Documentation ¶
Overview ¶
Package wal This Module is in so many aspects inspired by etcd's WAL.
Index ¶
- Variables
- func BytesToUint64(p []byte) uint64
- func Exist(dir string) bool
- func OpenDir(path string) (*os.File, error)
- func Uint64ToBytes(i uint64) []byte
- func ZeroToEnd(f *os.File) error
- type Entry
- type Log
- func (log *Log) Check(crc uint64) error
- func (*Log) Descriptor() ([]byte, []int)deprecated
- func (x *Log) GetChecksum() uint64
- func (x *Log) GetData() []byte
- func (x *Log) GetType() LogType
- func (*Log) ProtoMessage()
- func (x *Log) ProtoReflect() protoreflect.Message
- func (x *Log) Reset()
- func (x *Log) String() string
- type LogType
- type PageWriter
- type StreamFile
- type WAL
- func (w *WAL) CleanDir() error
- func (w *WAL) Close() error
- func (w *WAL) HasDecoder() bool
- func (w *WAL) ReadAll() (metadata []byte, ents []*Entry, err error)
- func (w *WAL) ReleaseLockTo(index uint64) error
- func (w *WAL) RemoveFiles(index uint64) error
- func (w *WAL) RemoveFilesBefore(index uint64) error
- func (w *WAL) Save(ents []*Entry) (uint64, error)
- func (w *WAL) SaveSingle(ent *Entry) (uint64, error)
- func (w *WAL) Size() uint64
Constants ¶
This section is empty.
Variables ¶
var ( LogType_name = map[int32]string{ 0: "crcType", 2: "metaDataType", 3: "entryType", } LogType_value = map[string]int32{ "crcType": 0, "metaDataType": 2, "entryType": 3, } )
Enum value maps for LogType.
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 = 8 * 1000 * 1000 // 8MB // ErrMetadataConflict metadata not consist ErrMetadataConflict = errors.New("wal: conflicting metadata found") // ErrFileNotFound file not found ErrFileNotFound = errors.New("wal: file not found") // ErrCRCMismatch crc miss match ErrCRCMismatch = errors.New("wal: crc mismatch") )
var File_db_wal_log_proto protoreflect.FileDescriptor
Functions ¶
Types ¶
type Entry ¶
type Entry struct { Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` ExtraMeta []byte `protobuf:"bytes,2,opt,name=ExtraMeta,proto3" json:"ExtraMeta,omitempty"` Index uint64 `protobuf:"varint,3,opt,name=index,proto3" json:"index,omitempty"` // contains filtered or unexported fields }
func (*Entry) Descriptor
deprecated
func (*Entry) GetExtraMeta ¶
func (*Entry) ProtoMessage ¶
func (*Entry) ProtoMessage()
func (*Entry) ProtoReflect ¶
func (x *Entry) ProtoReflect() protoreflect.Message
type Log ¶
type Log struct { Type LogType `protobuf:"varint,1,opt,name=type,proto3,enum=wal.LogType" json:"type,omitempty"` Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` Checksum uint64 `protobuf:"varint,3,opt,name=checksum,proto3" json:"checksum,omitempty"` // contains filtered or unexported fields }
func (*Log) Descriptor
deprecated
func (*Log) GetChecksum ¶
func (*Log) ProtoMessage ¶
func (*Log) ProtoMessage()
func (*Log) ProtoReflect ¶
func (x *Log) ProtoReflect() protoreflect.Message
type LogType ¶
type LogType int32
func (LogType) Descriptor ¶
func (LogType) Descriptor() protoreflect.EnumDescriptor
func (LogType) EnumDescriptor
deprecated
func (LogType) Number ¶
func (x LogType) Number() protoreflect.EnumNumber
func (LogType) Type ¶
func (LogType) Type() protoreflect.EnumType
type PageWriter ¶
type PageWriter struct {
// contains filtered or unexported fields
}
PageWriter implements the io.Writer interface so that writes will either be in page chunks or from flushing.
func NewPageWriter ¶
func NewPageWriter(w io.Writer, pageBytes, pageOffset int) *PageWriter
NewPageWriter creates a new PageWriter. pageBytes is the number of bytes to write per page. pageOffset is the starting offset of io.Writer.
type StreamFile ¶
type StreamFile struct {
// contains filtered or unexported fields
}
StreamFile generate files like a endless stream
func (*StreamFile) GetNewFile ¶
func (st *StreamFile) GetNewFile() (f *os.File, err error)
GetNewFile get a new generated file
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 ¶
Create creates a WAL ready for appending records. The given metadata is recorded at the head of each WAL file, and can be retrieved with ReadAll. If there already are some wal files, it will try to recover from them.
func Open ¶
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 OpenForRead ¶
OpenForRead only opens the wal files for read. Write on a read only wal panics.
func (*WAL) HasDecoder ¶
HasDecoder check whether wal has decoder, has decoder means there already are some wal files.
func (*WAL) ReadAll ¶
nolint ReadAll reads out records of the current WAL. After ReadAll, the WAL will be ready for appending new records.
func (*WAL) ReleaseLockTo ¶
ReleaseLockTo releases the files, which has smaller index than the given index except the largest one among them. For example, if WAL is holding lock 1,2,3,4,5,6, ReleaseLockTo(4) will release lock 1,2 but keep 3. ReleaseLockTo(5) will release 1,2,3 but keep 4.
func (*WAL) RemoveFiles ¶
RemoveFiles remove files less than or equal to index
func (*WAL) RemoveFilesBefore ¶
RemoveFilesBefore remove files less than index
func (*WAL) SaveSingle ¶
SaveSingle save single entry, Return entry index and error