/wal

simple/small Write Ahead Log

Primary LanguageGoMIT LicenseMIT

wal

MIT License GoDoc Go Report Card Releases

simple/small write ahead log.

Installation

$ go get github.com/octu0/wal

Example

import "github.com/octu0/wal"

func main() {
	log, err := Open("/path/to/dir", wal.WithSync(true))
	if err != nil {
		panic(err)
	}
	defer log.Close()

	i1, err := log.Write([]byte("data1"))
	i2, err := log.Write([]byte("data2"))
	err := log.WriteAt(Index(100), []byte("data3"))

	data1, _ := log.Read(i1)
	println(string(data1)) // => "data1"

	data3, _ := log.Read(Index(100))
	println(string(data3)) // => "data3"

	// delete logs on memory
	if err := log.Delete(i1, i2); err != nil {
		panic(err)
	}

	// compaction of deleted logs to free disk space
	if err := log.Compact(); err != nil {
		panic(err)
	}
}

License

MIT, see LICENSE file for details.