Documentation ¶
Index ¶
- Variables
- func MarshalEntry(entry *WAL_Entry) []byte
- func UnmarshalEntry(data []byte, entry *WAL_Entry)
- func VerifyCRC(entity *WAL_Entry) bool
- type WAL
- func (w *WAL) Close() error
- func (w *WAL) CreateCheckPoint(data []byte) error
- func (w *WAL) ReadAll(readFromCheckPoint bool) ([]*WAL_Entry, error)
- func (w *WAL) ReadAllEntriesFromFile(file *os.File, readFromCheckPoint bool) ([]*WAL_Entry, uint64, error)
- func (w *WAL) ReadAllFromOffset(offset int, readFromCheckPoint bool) ([]*WAL_Entry, error)
- func (w *WAL) Repair() ([]*WAL_Entry, error)
- func (w *WAL) Sync() error
- func (w *WAL) WriteEntity(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 ErrCRCMismatch = errors.New("CRC mismatch: data may be corrupted")
var File_types_proto protoreflect.FileDescriptor
Functions ¶
func MarshalEntry ¶
MarshalEntry marshals the WAL_Entry into a byte slice.
func UnmarshalEntry ¶
UnmarshalEntry unmarshal the byte slice into a WAL_Entry.
Types ¶
type WAL ¶
type WAL struct {
// contains filtered or unexported fields
}
WAL is a write-ahead log that is used to store the data before it is written to any storage It is used to ensure that the data is not lost in case of a crash. It is also used to recover the data in case of a crash using automatic recovery.
func OpenWAL ¶
OpenWAL creates a new WAL instance if the directory does not exist. If the directory exists, the last log segment is opened and the last sequence number is read from the segment file. 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) Close ¶
Close closes the WAL, also calls sync to sync the data from the buffer to the disk
func (*WAL) CreateCheckPoint ¶
CreateCheckPoint create a check point in the WAL. A check point is a special entry in the WAL that is used to restore the state of the system to a point where the check point was created.
func (*WAL) ReadAll ¶
ReadAll reads all the entries from the WAL. if readFromCheckPoint is true, it reads from the check point. it will return all the entries from last checkpoint (if no checkpoint is found) if readFromCheckPoint is false, it reads from the beginning of the WAL.
func (*WAL) ReadAllEntriesFromFile ¶
func (w *WAL) ReadAllEntriesFromFile(file *os.File, readFromCheckPoint bool) ([]*WAL_Entry, uint64, error)
ReadAllEntriesFromFile reads all the entries from the given file. returns all the entries from the file and the last checkpoint log sequence number.
func (*WAL) ReadAllFromOffset ¶
ReadAllFromOffset start reading all log segment files 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) WriteEntity ¶
WriteEntity writes the data to WAL
type WAL_Entry ¶
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 check pointing IsCheckPoint *bool `protobuf:"varint,4,opt,name=isCheckPoint,proto3,oneof" json:"isCheckPoint,omitempty"` // contains filtered or unexported fields }
func UnmarshalAndVerifyEntry ¶
UnmarshalAndVerifyEntry unmarshals the data into a WAL_Entry and verifies the CRC.
func (*WAL_Entry) Descriptor
deprecated
func (*WAL_Entry) GetIsCheckPoint ¶
func (*WAL_Entry) GetLogSequenceNumber ¶
func (*WAL_Entry) ProtoMessage ¶
func (*WAL_Entry) ProtoMessage()
func (*WAL_Entry) ProtoReflect ¶
func (x *WAL_Entry) ProtoReflect() protoreflect.Message