Documentation
¶
Index ¶
- Constants
- Variables
- func CloneEntry(org *proto.Entry) *proto.Entry
- func CurLogFileName(shardId uint64) string
- func CutEntriesMaxSize(entries []*proto.Entry, maxSize uint64) []*proto.Entry
- func HsFileName(shardId, seqId uint64) string
- func LogFileName(shardId, firstIndex, lastIndex uint64) string
- func LogFileNameByIndex(shardId, index uint64) string
- func LogFileNameByPos(shardId uint64, pos int) string
- func LogFilePrefix(shardId uint64) string
- func ParseLogFileName(fileName string) (shardId, firstIndex, lastIndex uint64, e error)
- type BlockBuffer
- type DiskRotateStorage
- func (ds *DiskRotateStorage) ApplySnapshot(meta proto.SnapshotMeta) (e error)
- func (ds *DiskRotateStorage) Clear() error
- func (ds *DiskRotateStorage) Close()
- func (ds *DiskRotateStorage) Entries(lo, hi uint64, maxSize uint64) (entries []*proto.Entry, isCompact bool, e error)
- func (ds *DiskRotateStorage) FirstIndex() (uint64, error)
- func (ds *DiskRotateStorage) InitialState() (hs proto.HardState, e error)
- func (ds *DiskRotateStorage) LastIndex() (uint64, error)
- func (ds *DiskRotateStorage) StoreEntries(entries []*proto.Entry) error
- func (ds *DiskRotateStorage) StoreHardState(hs proto.HardState) (e error)
- func (ds *DiskRotateStorage) Term(index uint64) (term uint64, isCompact bool, e error)
- func (ds *DiskRotateStorage) Truncate(index uint64) error
- type EntryMeta
- type HardStateFile
- type LogEntryCache
- type LogFile
- type LogFileCache
- type MemoryStorage
- func (ms *MemoryStorage) ApplySnapshot(meta proto.SnapshotMeta) error
- func (ms *MemoryStorage) Close()
- func (ms *MemoryStorage) Entries(lo, hi uint64, maxSize uint64) (entries []*proto.Entry, isCompact bool, err error)
- func (ms *MemoryStorage) FirstIndex() (uint64, error)
- func (ms *MemoryStorage) InitialState() (proto.HardState, error)
- func (ms *MemoryStorage) LastIndex() (uint64, error)
- func (ms *MemoryStorage) StoreEntries(entries []*proto.Entry) error
- func (ms *MemoryStorage) StoreHardState(st proto.HardState) error
- func (ms *MemoryStorage) Term(index uint64) (term uint64, isCompact bool, err error)
- func (ms *MemoryStorage) Truncate(index uint64) error
- type PersistStorage
- func (s *PersistStorage) ApplyIndex() (index uint64, err error)
- func (s *PersistStorage) ApplySnapshot(meta proto.SnapshotMeta) error
- func (s *PersistStorage) Close()
- func (s *PersistStorage) Entries(lo, hi uint64, maxSize uint64) ([]*proto.Entry, bool, error)
- func (s *PersistStorage) FirstIndex() (uint64, error)
- func (s *PersistStorage) InitialState() (hs proto.HardState, err error)
- func (s *PersistStorage) LastIndex() (uint64, error)
- func (s *PersistStorage) SnapshotApplyIndex(snap model.Snapshot) (index uint64, err error)
- func (s *PersistStorage) StoreApplyIndex(applyIndex uint64) error
- func (s *PersistStorage) StoreApplyIndexBatch(batch model.WriteBatch, applyIndex uint64) error
- func (s *PersistStorage) StoreEntries(entries []*proto.Entry) error
- func (s *PersistStorage) StoreHardState(st proto.HardState) error
- func (s *PersistStorage) Term(index uint64) (term uint64, isCompact bool, err error)
- func (s *PersistStorage) Truncate(index uint64) error
- type Storage
Constants ¶
View Source
const ( Log_Magic = 0x1EEE // uint32 Log_MaxEntryNum = 8192 Log_MetaHeadSize = (4 + 4 + 8 + 4 + 4) // magic + crc + shard id + cap + entry num Log_FileMetaEntrySize = (8 + 8 + 8) // index + term + offset Log_FileMetaSize = (Log_MetaHeadSize + Log_MaxEntryNum*Log_FileMetaEntrySize) Log_EntryHeadSize = (4 + 4 + 1 + 8 + 8) // crc + data size + type + term + index Log_HsHeadSize = (4 + 4 + 8 + 8 + 4 + 4) // magic + crc + shard id + seq id + data size + data size Log_EntryCacheNum = 128 Log_FileCacheNum = 5 Log_HardStateNum = 2 )
Variables ¶
View Source
var ( Err_BufferSizeNotEnough = errors.New("BufferSizeNotEnough") Err_LogFileFull = errors.New("LogFileFull") Err_LogFileEmpty = errors.New("LogFileEmpty") Err_LogEmpty = errors.New("LogFileEmpty") Err_LogDirNotExist = errors.New("Err_LogDirNotExist") Err_LogDirCannotAccess = errors.New("Err_LogDirCannotAccess") Err_InvalidFilePos = errors.New("InvalidFilePos") Err_IndexOutOfRange = errors.New("IndexOutOfRange") Err_IndexOutOfFileRange = errors.New("IndexOutOfFileRange") Err_LastIndexNotMatch = errors.New("LastIndexNotMatch") Err_FileLastIndexNotMatch = errors.New("FileLastIndexNotMatch") Err_LogFileIncomplete = errors.New("LogFileIncomplete") Err_LossLogFileInMiddle = errors.New("LossLogFileInMiddle") Err_NilInput = errors.New("NilInput") Err_EmptyHardState = errors.New("EmptyHardState") Err_EmptySnapshotMeta = errors.New("EmptySnapshotMeta") Err_NoHardStateFile = errors.New("NoHardStateFile") Err_CrcNotMatch = errors.New("CrcNotMatch") Err_BadMeta = errors.New("BadMeta") Err_FirstIndexNotMatch = errors.New("FirstIndexNotMatch") Err_BadMagic = errors.New("BadMagic") Err_FileNameNotMatch = errors.New("FileNameNotMatch") )
Functions ¶
func CurLogFileName ¶
func CutEntriesMaxSize ¶
func HsFileName ¶
func LogFileName ¶
func LogFileNameByIndex ¶
func LogFileNameByPos ¶
func LogFilePrefix ¶
func ParseLogFileName ¶
Types ¶
type BlockBuffer ¶
type BlockBuffer struct {
// contains filtered or unexported fields
}
func NewBlockBuffer ¶
func NewBlockBuffer(blockSize int) *BlockBuffer
func (*BlockBuffer) BlockSize ¶
func (bb *BlockBuffer) BlockSize() uint32
func (*BlockBuffer) GetBuffer ¶
func (bb *BlockBuffer) GetBuffer() []byte
func (*BlockBuffer) PutBuffer ¶
func (bb *BlockBuffer) PutBuffer(b []byte)
type DiskRotateStorage ¶
type DiskRotateStorage struct {
// contains filtered or unexported fields
}
func NewDiskRotateStorage ¶
func NewDiskRotateStorage(dir string, shardId uint64) (*DiskRotateStorage, error)
func (*DiskRotateStorage) ApplySnapshot ¶
func (ds *DiskRotateStorage) ApplySnapshot(meta proto.SnapshotMeta) (e error)
func (*DiskRotateStorage) Clear ¶
func (ds *DiskRotateStorage) Clear() error
func (*DiskRotateStorage) Close ¶
func (ds *DiskRotateStorage) Close()
func (*DiskRotateStorage) FirstIndex ¶
func (ds *DiskRotateStorage) FirstIndex() (uint64, error)
func (*DiskRotateStorage) InitialState ¶
func (ds *DiskRotateStorage) InitialState() (hs proto.HardState, e error)
func (*DiskRotateStorage) LastIndex ¶
func (ds *DiskRotateStorage) LastIndex() (uint64, error)
func (*DiskRotateStorage) StoreEntries ¶
func (ds *DiskRotateStorage) StoreEntries(entries []*proto.Entry) error
func (*DiskRotateStorage) StoreHardState ¶
func (ds *DiskRotateStorage) StoreHardState(hs proto.HardState) (e error)
func (*DiskRotateStorage) Term ¶
func (ds *DiskRotateStorage) Term(index uint64) (term uint64, isCompact bool, e error)
func (*DiskRotateStorage) Truncate ¶
func (ds *DiskRotateStorage) Truncate(index uint64) error
type HardStateFile ¶
type HardStateFile struct {
// contains filtered or unexported fields
}
func LoadHardStateFile ¶
func LoadHardStateFile(dir string, shardId uint64) (*HardStateFile, error)
func NewHardStateFile ¶
func NewHardStateFile(dir string, shardId uint64, hs *proto.HardState, snap *proto.SnapshotMeta) (hf *HardStateFile, e error)
type LogEntryCache ¶
type LogEntryCache struct {
// contains filtered or unexported fields
}
func NewLogEntryCache ¶
func NewLogEntryCache(maxSize int) *LogEntryCache
type LogFile ¶
type LogFile struct {
// contains filtered or unexported fields
}
func LoadLogFile ¶
func NewLogFile ¶
type LogFileCache ¶
type LogFileCache struct {
// contains filtered or unexported fields
}
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
This storage is circular storage in memory and truncate when over capacity, but keep it a high capacity.
func DefaultMemoryStorage ¶
func DefaultMemoryStorage() *MemoryStorage
func NewMemoryStorage ¶
func NewMemoryStorage(fsm fsm, id, capacity uint64) *MemoryStorage
func (*MemoryStorage) ApplySnapshot ¶
func (ms *MemoryStorage) ApplySnapshot(meta proto.SnapshotMeta) error
func (*MemoryStorage) Close ¶
func (ms *MemoryStorage) Close()
func (*MemoryStorage) FirstIndex ¶
func (ms *MemoryStorage) FirstIndex() (uint64, error)
func (*MemoryStorage) InitialState ¶
func (ms *MemoryStorage) InitialState() (proto.HardState, error)
func (*MemoryStorage) LastIndex ¶
func (ms *MemoryStorage) LastIndex() (uint64, error)
func (*MemoryStorage) StoreEntries ¶
func (ms *MemoryStorage) StoreEntries(entries []*proto.Entry) error
func (*MemoryStorage) StoreHardState ¶
func (ms *MemoryStorage) StoreHardState(st proto.HardState) error
func (*MemoryStorage) Term ¶
func (ms *MemoryStorage) Term(index uint64) (term uint64, isCompact bool, err error)
func (*MemoryStorage) Truncate ¶
func (ms *MemoryStorage) Truncate(index uint64) error
type PersistStorage ¶
type PersistStorage struct { RangeID uint64 // the rangeID // contains filtered or unexported fields }
func NewPersistStorage ¶
func NewPersistStorage(rangeID uint64, store model.KVStore) (*PersistStorage, error)
func (*PersistStorage) ApplyIndex ¶
func (s *PersistStorage) ApplyIndex() (index uint64, err error)
ApplyIndex
func (*PersistStorage) ApplySnapshot ¶
func (s *PersistStorage) ApplySnapshot(meta proto.SnapshotMeta) error
func (*PersistStorage) Close ¶
func (s *PersistStorage) Close()
func (*PersistStorage) FirstIndex ¶
func (s *PersistStorage) FirstIndex() (uint64, error)
func (*PersistStorage) InitialState ¶
func (s *PersistStorage) InitialState() (hs proto.HardState, err error)
func (*PersistStorage) LastIndex ¶
func (s *PersistStorage) LastIndex() (uint64, error)
func (*PersistStorage) SnapshotApplyIndex ¶
func (s *PersistStorage) SnapshotApplyIndex(snap model.Snapshot) (index uint64, err error)
func (*PersistStorage) StoreApplyIndex ¶
func (s *PersistStorage) StoreApplyIndex(applyIndex uint64) error
func (*PersistStorage) StoreApplyIndexBatch ¶
func (s *PersistStorage) StoreApplyIndexBatch(batch model.WriteBatch, applyIndex uint64) error
func (*PersistStorage) StoreEntries ¶
func (s *PersistStorage) StoreEntries(entries []*proto.Entry) error
func (*PersistStorage) StoreHardState ¶
func (s *PersistStorage) StoreHardState(st proto.HardState) error
func (*PersistStorage) Term ¶
func (s *PersistStorage) Term(index uint64) (term uint64, isCompact bool, err error)
func (*PersistStorage) Truncate ¶
func (s *PersistStorage) Truncate(index uint64) error
type Storage ¶
type Storage interface { // InitialState returns the saved HardState information to init the repl state. InitialState() (proto.HardState, error) // Entries returns a slice of log entries in the range [lo,hi), the hi is not inclusive. // MaxSize limits the total size of the log entries returned, but Entries returns at least one entry if any. // If lo <= CompactIndex,then return isCompact true. // If no entries,then return entries nil. // Note: math.MaxUint32 is no limit. Entries(lo, hi uint64, maxSize uint64) (entries []*proto.Entry, isCompact bool, err error) // Term returns the term of entry i, which must be in the range [FirstIndex()-1, LastIndex()]. // The term of the entry before FirstIndex is retained for matching purposes even though the // rest of that entry may not be available. // If lo <= CompactIndex,then return isCompact true. Term(i uint64) (term uint64, isCompact bool, err error) // FirstIndex returns the index of the first log entry that is possibly available via Entries (older entries have been incorporated // into the latest Snapshot; if storage only contains the dummy entry the first log entry is not available). FirstIndex() (uint64, error) // LastIndex returns the index of the last entry in the log. LastIndex() (uint64, error) // StoreEntries store the log entries to the repository. // If first index of entries > LastIndex,then append all entries, // Else write entries at first index and truncate the redundant log entries. StoreEntries(entries []*proto.Entry) error // StoreHardState store the raft state to the repository. StoreHardState(st proto.HardState) error // Truncate the log to index, The index is inclusive. Truncate(index uint64) error // Sync snapshot status. ApplySnapshot(meta proto.SnapshotMeta) error // Close the storage. Close() }
Storage is an interface that may be implemented by the application to retrieve log entries from storage. If any Storage method returns an error, the raft instance will become inoperable and refuse to participate in elections; the application is responsible for cleanup and recovery in this case.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.