# README
wal
Package wal provides a simple write-ahead log implementation inspired by Indeed's BasicRecordFile implementation. Each record in the file is stored using the following format:
[length - varint][record content][checksum]
Unlike the reference implementation, the record length is written as a varint to help conserve space. The checksum is a simple CRC32 checksum. Reference: https://github.com/indeedeng/lsmtree/blob/master/recordlog/src/main/java/com/indeed/lsmtree/recordlog/BasicRecordFile.java
import go.pitz.tech/lib/wal
Usage
type Reader
type Reader struct {
}
Reader implements the logic for reading information from the write-ahead log. The underlying file is wrapped with a buffered reader to help improve performance.
func OpenReader
func OpenReader(ctx context.Context, filepath string) (*Reader, error)
OpenReader opens a new read-only handle to the target file.
func (*Reader) Close
func (r *Reader) Close() error
func (*Reader) Position
func (r *Reader) Position() uint64
Position returns the current position of the reader.
func (*Reader) Read
func (r *Reader) Read(p []byte) (n int, err error)
func (*Reader) Seek
func (r *Reader) Seek(offset int64, whence int) (int64, error)
type Writer
type Writer struct {
}
Writer implements the logic for writing information to the write-ahead log. The underlying file is wrapped with a buffered writer to help improve durability of writes.
func OpenWriter
func OpenWriter(ctx context.Context, filepath string) (*Writer, error)
OpenWriter opens a new append-only handle that writes data to the target file.
func (*Writer) Close
func (w *Writer) Close() error
func (*Writer) Flush
func (w *Writer) Flush() error
func (*Writer) Sync
func (w *Writer) Sync() error
func (*Writer) Write
func (w *Writer) Write(p []byte) (int, error)