wal

package
v0.0.0-...-4eef59b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2018 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SegmentSizeBytes is the preallocated size of each wal segment file.
	// The actual size might be larger than this. In general, the default
	// value should be used, but this is defined as an exported variable
	// so that tests can set a different segment size.
	SegmentSizeBytes int64 = 64 * 1000 * 1000 // 64MB

	ErrFileNotFound = errors.New("wal: file not found")
	ErrCRCMismatch  = errors.New("wal: crc mismatch")
)

Functions

func Exist

func Exist(dirpath string) bool

Types

type WAL

type WAL struct {
	// contains filtered or unexported fields
}

WAL is a logical representation of the stable storage. WAL is either in read mode or append mode but not both. A newly created WAL is in append mode, and ready for appending records. A just opened WAL is in read mode, and ready for reading records. The WAL will be ready for appending after reading out all the previous records.

func Create

func Create(dirpath string) (*WAL, error)

Create creates a WAL ready for appending records.

func Open

func Open(dirpath string, snap walpb.Snapshot) (*WAL, error)

Open opens the WAL at the given snap. The snap SHOULD have been previously saved to the WAL, or the following ReadAll will fail. The returned WAL is ready to read and the first record will be the one after the given snap. The WAL cannot be appended to before reading out all of its previous records.

func OpenAtBeginning

func OpenAtBeginning(dirpath string) (*WAL, error)

OpenAtBeginning opens the WAL at the beginning. The WAL cannot be appended to before reading out all of its previous records.

func OpenForRead

func OpenForRead(dirpath string, snap walpb.Snapshot) (*WAL, error)

OpenForRead only opens the wal files for read. Write on a read only wal panics.

func (*WAL) Close

func (w *WAL) Close(clean bool) (err error)

func (*WAL) CompactAll

func (w *WAL) CompactAll() (err error)

CompactAll remove all entries.

func (*WAL) ReadAll

func (w *WAL) ReadAll() (ents []walpb.Entry, err error)

ReadAll reads out records of the current WAL. If opened in write mode, it must read out all records until EOF. Or an error will be returned. If opened in read mode, it will try to read all records if possible. If it cannot read out the expected snap, it will return ErrSnapshotNotFound. If loaded snap doesn't match with the expected one, it will return all the records and error ErrSnapshotMismatch. TODO: detect not-last-snap error. TODO: maybe loose the checking of match. After ReadAll, the WAL will be ready for appending new records.

func (*WAL) Save

func (w *WAL) Save(ents []walpb.Entry) (err error)

func (*WAL) SaveEntry

func (w *WAL) SaveEntry(e *walpb.Entry) (err error)

SaveEntry saves an entry, and always sync the wal

func (*WAL) Sync

func (w *WAL) Sync() error

Directories

Path Synopsis
Package walpb is a generated protocol buffer package.
Package walpb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL