A simple write ahead log implements of go.
wal-go is an implementation of write ahead log. It provides the log persistence, recovery capabilities. wal-go is thread-safe and supports concurrent calls.
wal-go support logs are split at 64 Mb and support recovery from specified log points. wal-go Pre-allocate 64MB of space, the use of batch submission, to reduce disk sync costs.
Create a new Wal and give it from that log point:
log, _ := wal.Create("/tmp/wal", 0)
defer log.Close()
log.Write(1, []byte{ 0x1, 0x2, 0x3}) // will block until bytes has been written.
log.Write(....)
log.Sync() // will block until bytes has been written.
Or after a crash, resume from a checkpoint:
checkpoint = ....
log, _ := wal.Open("/tmp/wal", checkpoint, func(idx uint64, data []byte) {
// consume record data.
})
defer log.Close()
log.Write(1, []byte{ 0x1, 0x2, 0x3}) // will block until bytes has been written.
log.Write(....)
log.Sync() // will block until bytes has been written.