项目作者: PatrickNicholas

项目描述 :
A simple write ahead log implements of go.
高级语言: Go
项目地址: git://github.com/PatrickNicholas/wal-go.git
创建时间: 2018-02-11T05:38:01Z
项目社区:https://github.com/PatrickNicholas/wal-go

开源协议:

下载


Wal-go

Build Status
Coverage Status

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.

Usage

Create a new Wal and give it from that log point:

  1. log, _ := wal.Create("/tmp/wal", 0)
  2. defer log.Close()
  3. log.Write(1, []byte{ 0x1, 0x2, 0x3}) // will block until bytes has been written.
  4. log.Write(....)
  5. log.Sync() // will block until bytes has been written.

Or after a crash, resume from a checkpoint:

  1. checkpoint = ....
  2. log, _ := wal.Open("/tmp/wal", checkpoint, func(idx uint64, data []byte) {
  3. // consume record data.
  4. })
  5. defer log.Close()
  6. log.Write(1, []byte{ 0x1, 0x2, 0x3}) // will block until bytes has been written.
  7. log.Write(....)
  8. log.Sync() // will block until bytes has been written.