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
- func (*Entry) Descriptor() ([]byte, []int)
- func (m *Entry) GetData() []byte
- func (m *Entry) GetExtraMeta() []byte
- func (m *Entry) GetIndex() uint64
- func (*Entry) ProtoMessage()
- func (m *Entry) Reset()
- func (m *Entry) String() string
- func (m *Entry) XXX_DiscardUnknown()
- func (m *Entry) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *Entry) XXX_Merge(src proto.Message)
- func (m *Entry) XXX_Size() int
- func (m *Entry) XXX_Unmarshal(b []byte) error
- type Log
- func (log *Log) Check(crc uint64) error
- func (*Log) Descriptor() ([]byte, []int)
- func (m *Log) GetChecksum() uint64
- func (m *Log) GetData() []byte
- func (m *Log) GetType() LogType
- func (*Log) ProtoMessage()
- func (m *Log) Reset()
- func (m *Log) String() string
- func (m *Log) XXX_DiscardUnknown()
- func (m *Log) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *Log) XXX_Merge(src proto.Message)
- func (m *Log) XXX_Size() int
- func (m *Log) XXX_Unmarshal(b []byte) error
- 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) Save(ents []Entry) (uint64, error)
- func (w *WAL) SaveSingle(ent Entry) (uint64, error)
Constants ¶
This section is empty.
Variables ¶
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 LogType_name = map[int32]string{
0: "crcType",
2: "metaDataType",
3: "entryType",
}
var LogType_value = map[string]int32{
"crcType": 0,
"metaDataType": 2,
"entryType": 3,
}
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"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Entry) Descriptor ¶
func (*Entry) GetExtraMeta ¶
func (*Entry) ProtoMessage ¶
func (*Entry) ProtoMessage()
func (*Entry) XXX_DiscardUnknown ¶
func (m *Entry) XXX_DiscardUnknown()
func (*Entry) XXX_Marshal ¶
func (*Entry) XXX_Unmarshal ¶
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"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Log) Descriptor ¶
func (*Log) GetChecksum ¶
func (*Log) ProtoMessage ¶
func (*Log) ProtoMessage()
func (*Log) XXX_DiscardUnknown ¶
func (m *Log) XXX_DiscardUnknown()
func (*Log) XXX_Unmarshal ¶
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.
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) 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 index