Documentation ¶
Index ¶
- Variables
- func MustMarshal(entry *WAL_Entry) []byte
- func MustUnmarshal(data []byte, entry *WAL_Entry)
- type WAL
- func (wal *WAL) Close() error
- func (wal *WAL) CreateCheckpoint(data []byte) error
- func (wal *WAL) ReadAll(readFromCheckpoint bool) ([]*WAL_Entry, error)
- func (wal *WAL) ReadAllFromOffset(offset int, readFromCheckpoint bool) ([]*WAL_Entry, error)
- func (wal *WAL) Repair() ([]*WAL_Entry, error)
- func (wal *WAL) Sync() error
- func (wal *WAL) WriteEntry(data []byte) error
- type WAL_Entry
- func (*WAL_Entry) Descriptor() ([]byte, []int)deprecated
- func (x *WAL_Entry) GetCRC() uint32
- func (x *WAL_Entry) GetData() []byte
- func (x *WAL_Entry) GetIsCheckpoint() bool
- func (x *WAL_Entry) GetLogSequenceNumber() uint64
- func (*WAL_Entry) ProtoMessage()
- func (x *WAL_Entry) ProtoReflect() protoreflect.Message
- func (x *WAL_Entry) Reset()
- func (x *WAL_Entry) String() string
Constants ¶
This section is empty.
Variables ¶
var File_types_proto protoreflect.FileDescriptor
Functions ¶
func MustUnmarshal ¶
Types ¶
type WAL ¶
type WAL struct {
// contains filtered or unexported fields
}
WAL structure
func OpenWAL ¶
Initialize a new WAL. If the directory does not exist, it will be created. If the directory exists, the last log segment will be opened and the last sequence number will be read from it. enableFsync enables fsync on the log segment file every time the log flushes. maxFileSize is the maximum size of a log segment file in bytes. maxSegments is the maximum number of log segment files to keep.
func (*WAL) CreateCheckpoint ¶
CreateCheckpoint creates a checkpoint entry in the WAL. A checkpoint entry is a special entry that can be used to restore the state of the system to the point when the checkpoint was created.
func (*WAL) ReadAll ¶
Read all entries from the WAL. If readFromCheckpoint is true, it will return all the entries from the last checkpoint (if no checkpoint is found, it will return an empty slice.)
func (*WAL) ReadAllFromOffset ¶
Starts reading from log segment files starting from the given offset (Segment Index) and returns all the entries. If readFromCheckpoint is true, it will return all the entries from the last checkpoint (if no checkpoint is found, it will return an empty slice.)
func (*WAL) Repair ¶
Repairs a corrupted WAL by scanning the WAL from the start and reading all entries until a corrupted entry is encountered, at which point the file is truncated. The function returns the entries that were read before the corruption and overwrites the existing WAL file with the repaired entries. It checks the CRC of each entry to verify if it is corrupted, and if the CRC is invalid, the file is truncated at that point.
func (*WAL) Sync ¶
Writes out any data in the WAL's in-memory buffer to the segment file. If fsync is enabled, it also calls fsync on the segment file. It also resets the synchronization timer.
func (*WAL) WriteEntry ¶
WriteEntry writes an entry to the WAL.
type WAL_Entry ¶ added in v1.2.0
type WAL_Entry struct { LogSequenceNumber uint64 `protobuf:"varint,1,opt,name=logSequenceNumber,proto3" json:"logSequenceNumber,omitempty"` Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` CRC uint32 `protobuf:"varint,3,opt,name=CRC,proto3" json:"CRC,omitempty"` // Optional field for checkpointing. IsCheckpoint *bool `protobuf:"varint,4,opt,name=isCheckpoint,proto3,oneof" json:"isCheckpoint,omitempty"` // contains filtered or unexported fields }
func (*WAL_Entry) Descriptor
deprecated
added in
v1.2.0
func (*WAL_Entry) GetIsCheckpoint ¶ added in v1.2.0
func (*WAL_Entry) GetLogSequenceNumber ¶ added in v1.2.0
func (*WAL_Entry) ProtoMessage ¶ added in v1.2.0
func (*WAL_Entry) ProtoMessage()
func (*WAL_Entry) ProtoReflect ¶ added in v1.2.0
func (x *WAL_Entry) ProtoReflect() protoreflect.Message