Skip to content

tylerztl/wal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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{}))

About

Write-Ahead Logging based on etcd-wal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages