wal

package module
Version: v0.0.0-...-16b87a0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

WAL

Write-Ahead Logging based on etcd-wal

Storage API

type Storage interface {
	// Save function saves ents and state to the underlying stable storage.
	// Save MUST block until st and ents are on stable storage.
	Save(st log.HardState, ents []log.LogEntry) error
	// SaveState function saves state to the underlying stable storage.
	SaveState(st log.HardState) error
	// SaveState function saves ents to the underlying stable storage.
	SaveEntry(ents []log.LogEntry) error
	// SaveSnap function saves snapshot to the underlying stable storage.
	SaveSnap(snap log.Snapshot) error
	// Close closes the Storage and performs finalization.
	Close() error
	// Release releases the locked wal files older than the provided snapshot.
	Release(snap log.Snapshot) error
	// Sync WAL
	Sync() error
}

Record Type

const (
	MetadataType RecordType = iota + 1
	EntryType
	StateType
	CrcType
	SnapshotType
)
Record API
// LogEntry implement custom entry data struct with entry index
type LogEntry interface {
	RecordData
	// index of the entry saved to the wal
	GetIndex() uint64
	// size of entry alloc memory
	Size() (n int)
}

// HardState implement custom state data struct for save the system latest state to wal
type HardState interface {
	RecordData
	// The latest index that has been committed
	GetCommitted() uint64
	// Reset set state initial default value
	Reset()
}

// Snapshot implement custom snapshot struct with entry index
type Snapshot interface {
	RecordData
	// index of the entry saved to the wal
	GetIndex() uint64
}

type RecordData interface {
	Marshal() (data []byte, err error)
	Unmarshal(data []byte) error
}
Define Custom Record
type CustomEntry struct {
	Index uint64
	Value string
}

func (m *CustomEntry) Marshal() (data []byte, err error) {
	return json.Marshal(m)
}

func (m *CustomEntry) Unmarshal(data []byte) error {
	return json.Unmarshal(data, m)
}
func (m *CustomEntry) GetIndex() uint64 {
	return m.Index
}

log.RegisterRecord(log.EntryType, log.LogEntry(&CustomEntry{}))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadWAL

func ReadWAL(lg *zap.Logger, waldir string, snap log.Snapshot, unsafeNoFsync bool) (w *log.WAL,
	wmetadata []byte, st log.HardState, ents []log.LogEntry)

ReadWAL reads the WAL at the given snap and returns the wal, its latest HardState and all entries that appear after the position of the given snap in the WAL. The snap must have been previously saved to the WAL, or this call will panic.

Types

type Storage

type Storage interface {
	log.WALAPI
	snap.SnapshotAPI

	SaveSnap(snap snappb.ShotData, s log.Snapshot) error
	Release(snap snappb.ShotData, s log.Snapshot) error
}

func NewStorage

func NewStorage(w *log.WAL, s *snap.Snapshotter) Storage

Source Files

Directories

Path Synopsis
log

Jump to

Keyboard shortcuts

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