Documentation
¶
Index ¶
- Constants
- Variables
- func IsValidSnapshot(snapshot raftpb.Snapshot) bool
- type DataType
- type DataWrapper
- type FileWrap
- func (fw *FileWrap) Close() error
- func (fw *FileWrap) Delete() error
- func (fw *FileWrap) GetEntryData(slotIdx int, start, end int, isMeta bool) []byte
- func (fw *FileWrap) Instance() *FileWrap
- func (fw *FileWrap) MemSize() int
- func (fw *FileWrap) Name() string
- func (fw *FileWrap) ReadSlice(slotIdx int, offset int64, isMeta bool) []byte
- func (fw *FileWrap) Size() int
- func (fw *FileWrap) SliceSize(slotIdx int, offset int) int
- func (fw *FileWrap) Truncate(size int64) error
- func (fw *FileWrap) TrySync() error
- func (fw *FileWrap) Write(dat []byte) (int, error)
- func (fw *FileWrap) WriteAt(slotIdx int, offset int64, dat []byte, isMeta bool) (int, error)
- func (fw *FileWrap) WriteSlice(slotIdx int, endSlotIdx int, offset int64, dat []byte, isMeta bool, ...) error
- type FileWrapCache
- type FileWrapV2
- func (fw *FileWrapV2) Close() error
- func (fw *FileWrapV2) Delete() error
- func (fw *FileWrapV2) GetEntryData(slotIdx int, start, end int, isMeta bool) []byte
- func (fw *FileWrapV2) Name() string
- func (fw *FileWrapV2) ReadSlice(slotIdx int, offset int64, isMeta bool) []byte
- func (fw *FileWrapV2) Size() int
- func (fw *FileWrapV2) SliceSize(slotIdx int, offset int) int
- func (fw *FileWrapV2) Truncate(size int64) error
- func (fw *FileWrapV2) TrySync() error
- func (fw *FileWrapV2) Write(dat []byte) (int, error)
- func (fw *FileWrapV2) WriteAt(slotIdx int, offset int64, dat []byte, isMeta bool) (int, error)
- func (fw *FileWrapV2) WriteSlice(slotIdx int, endSlotIdx int, offset int64, dat []byte, isMeta bool, ...) error
- type FileWrapper
- type MetaInfo
- type RaftDiskStorage
- func (rds *RaftDiskStorage) AllValidEntries(lo, hi, first, last, maxSize uint64) ([]raftpb.Entry, error)
- func (rds *RaftDiskStorage) Close() error
- func (rds *RaftDiskStorage) CreateSnapshot(i uint64, cs *raftpb.ConfState, data []byte) error
- func (rds *RaftDiskStorage) DeleteBefore(index uint64) error
- func (rds *RaftDiskStorage) Entries(lo, hi, maxSize uint64) ([]raftpb.Entry, error)
- func (rds *RaftDiskStorage) EntrySize() int
- func (rds *RaftDiskStorage) Exist() bool
- func (rds *RaftDiskStorage) FirstIndex() (uint64, error)
- func (rds *RaftDiskStorage) FirstIndexWithSnap() (uint64, error)
- func (rds *RaftDiskStorage) GetDir() string
- func (rds *RaftDiskStorage) GetFirstLast() (uint64, uint64)
- func (rds *RaftDiskStorage) GetRaftEntryLog() *entryLog
- func (rds *RaftDiskStorage) HardState() (raftpb.HardState, error)
- func (rds *RaftDiskStorage) InitialState() (hs raftpb.HardState, cs raftpb.ConfState, err error)
- func (rds *RaftDiskStorage) LastIndex() (uint64, error)
- func (rds *RaftDiskStorage) Lock()
- func (rds *RaftDiskStorage) NumEntries() int
- func (rds *RaftDiskStorage) Save(h *raftpb.HardState, entries []raftpb.Entry, snap *raftpb.Snapshot) error
- func (rds *RaftDiskStorage) SaveEntries(h *raftpb.HardState, entries []raftpb.Entry, snap *raftpb.Snapshot) error
- func (rds *RaftDiskStorage) SetUint(info MetaInfo, id uint64)
- func (rds *RaftDiskStorage) SlotGe(index uint64) (int, int)
- func (rds *RaftDiskStorage) Snapshot() (raftpb.Snapshot, error)
- func (rds *RaftDiskStorage) Term(idx uint64) (uint64, error)
- func (rds *RaftDiskStorage) TrySync() error
- func (rds *RaftDiskStorage) Uint(info MetaInfo) uint64
- func (rds *RaftDiskStorage) UnLock()
- type SnapShotter
Constants ¶
const ( RaftIdOffset = 0 GroupIdOffset = 8 CheckpointIndexOffset = 16 )
const (
RaftEntriesDir = "__raft_entries__"
)
Variables ¶
var NewFile = errors.New("Create a new file")
Functions ¶
func IsValidSnapshot ¶
Types ¶
type DataWrapper ¶
type DataWrapper struct {
Data []byte
DataType DataType
Identity string // raftNode identity
ProposeId uint64 // propose seq id
}
func Unmarshal ¶
func Unmarshal(dst []byte) (*DataWrapper, error)
func (*DataWrapper) GetData ¶
func (d *DataWrapper) GetData() []byte
func (*DataWrapper) GetDataType ¶
func (d *DataWrapper) GetDataType() DataType
func (*DataWrapper) Marshal ¶
func (d *DataWrapper) Marshal() []byte
type FileWrap ¶
type FileWrap struct {
// contains filtered or unexported fields
}
FileWrap represents a file and includes both the buffer to the data and the file descriptor.
func NewFileWrap ¶ added in v1.4.0
func NewNilFileWrap ¶ added in v1.4.0
func NewNilFileWrap() *FileWrap
func (*FileWrap) GetEntryData ¶
GetEntryData returns entry data
func (*FileWrap) Size ¶
todo: don't need getContent, clear by size will be slow when fileNum is big, which read from disk mostly
type FileWrapCache ¶ added in v1.4.0
type FileWrapCache struct {
// contains filtered or unexported fields
}
func NewCache ¶ added in v1.4.0
func NewCache() *FileWrapCache
type FileWrapV2 ¶ added in v1.5.0
type FileWrapV2 struct {
// contains filtered or unexported fields
}
FileWrapV2 represents a file and includes fileSlotCaches, current data cache, metaCache and the file descriptor.
func NewFileWrapV2 ¶ added in v1.5.0
func NewFileWrapV2(fd fileops.File) *FileWrapV2
func (*FileWrapV2) Close ¶ added in v1.5.0
func (fw *FileWrapV2) Close() error
func (*FileWrapV2) Delete ¶ added in v1.5.0
func (fw *FileWrapV2) Delete() error
func (*FileWrapV2) GetEntryData ¶ added in v1.5.0
func (fw *FileWrapV2) GetEntryData(slotIdx int, start, end int, isMeta bool) []byte
GetEntryData returns entry data
func (*FileWrapV2) Name ¶ added in v1.5.0
func (fw *FileWrapV2) Name() string
func (*FileWrapV2) ReadSlice ¶ added in v1.5.0
func (fw *FileWrapV2) ReadSlice(slotIdx int, offset int64, isMeta bool) []byte
func (*FileWrapV2) Size ¶ added in v1.5.0
func (fw *FileWrapV2) Size() int
func (*FileWrapV2) SliceSize ¶ added in v1.5.0
func (fw *FileWrapV2) SliceSize(slotIdx int, offset int) int
func (*FileWrapV2) Truncate ¶ added in v1.5.0
func (fw *FileWrapV2) Truncate(size int64) error
func (*FileWrapV2) TrySync ¶ added in v1.5.0
func (fw *FileWrapV2) TrySync() error
func (*FileWrapV2) WriteSlice ¶ added in v1.5.0
type FileWrapper ¶
type FileWrapper interface {
Name() string
Size() int
GetEntryData(slotIdx int, start, end int, isMeta bool) []byte
Write(dat []byte) (int, error)
WriteAt(slotIdx int, offset int64, dat []byte, isMeta bool) (int, error)
WriteSlice(slotIdx int, endSlotIdx int, offset int64, dat []byte, isMeta bool, clearSlots bool) error
ReadSlice(slotIdx int, offset int64, isMeta bool) []byte
SliceSize(slotIdx int, offset int) int
Truncate(size int64) error
TrySync() error
Delete() error
Close() error
// contains filtered or unexported methods
}
func OpenFile ¶
func OpenFile(fpath string, flag int, maxSz int) (FileWrapper, error)
OpenFile opens an existing file or creates a new file. If the file is created, it would truncate the file to maxSz. In case the file is created, z.NewFile is returned.
func OpenFileV2 ¶ added in v1.5.0
func OpenFileV2(fpath string, flag int, maxSz int) (FileWrapper, error)
OpenFile opens an existing file or creates a new file. If the file is created, it would truncate the file to maxSz. In case the file is created, z.NewFile is returned.
type RaftDiskStorage ¶
type RaftDiskStorage struct {
SyncInterval time.Duration
// contains filtered or unexported fields
}
RaftDiskStorage handles disk access and writing for the RAFT write-ahead log. Dir contains wal.meta file and <start idx zero padded>.entry files.
func Init ¶
func Init(dir string, SyncInterval time.Duration) (*RaftDiskStorage, error)
Init initializes an instance of DiskStorage.
func (*RaftDiskStorage) AllValidEntries ¶ added in v1.5.0
func (rds *RaftDiskStorage) AllValidEntries(lo, hi, first, last, maxSize uint64) ([]raftpb.Entry, error)
func (*RaftDiskStorage) Close ¶
func (rds *RaftDiskStorage) Close() error
Close closes the DiskStorage.
func (*RaftDiskStorage) CreateSnapshot ¶
CreateSnapshot generates a snapshot with the given ConfState and data and writes it to disk.
func (*RaftDiskStorage) DeleteBefore ¶
func (rds *RaftDiskStorage) DeleteBefore(index uint64) error
func (*RaftDiskStorage) Entries ¶
func (rds *RaftDiskStorage) Entries(lo, hi, maxSize uint64) ([]raftpb.Entry, error)
Entries returns a slice of log entries in the range [lo,hi). MaxSize limits the total size of the log entries returned, but Entries returns at least one entry if any.
func (*RaftDiskStorage) EntrySize ¶ added in v1.4.0
func (rds *RaftDiskStorage) EntrySize() int
func (*RaftDiskStorage) Exist ¶
func (rds *RaftDiskStorage) Exist() bool
func (*RaftDiskStorage) FirstIndex ¶
func (rds *RaftDiskStorage) FirstIndex() (uint64, error)
FirstIndex implements the Storage interface.
func (*RaftDiskStorage) FirstIndexWithSnap ¶
func (rds *RaftDiskStorage) FirstIndexWithSnap() (uint64, error)
FirstIndex implements the Storage interface.
func (*RaftDiskStorage) GetDir ¶ added in v1.5.1
func (rds *RaftDiskStorage) GetDir() string
func (*RaftDiskStorage) GetFirstLast ¶
func (rds *RaftDiskStorage) GetFirstLast() (uint64, uint64)
func (*RaftDiskStorage) GetRaftEntryLog ¶ added in v1.5.2
func (rds *RaftDiskStorage) GetRaftEntryLog() *entryLog
func (*RaftDiskStorage) HardState ¶
func (rds *RaftDiskStorage) HardState() (raftpb.HardState, error)
func (*RaftDiskStorage) InitialState ¶
InitialState returns the saved HardState and ConfState information.
func (*RaftDiskStorage) LastIndex ¶
func (rds *RaftDiskStorage) LastIndex() (uint64, error)
func (*RaftDiskStorage) Lock ¶ added in v1.5.2
func (rds *RaftDiskStorage) Lock()
func (*RaftDiskStorage) NumEntries ¶
func (rds *RaftDiskStorage) NumEntries() int
func (*RaftDiskStorage) Save ¶
func (rds *RaftDiskStorage) Save(h *raftpb.HardState, entries []raftpb.Entry, snap *raftpb.Snapshot) error
Save would write Entries, HardState and Snapshot to persistent storage in order, i.e. Entries first, then HardState and Snapshot if they are not empty. If persistent storage supports atomic writes then all of them can be written together. Note that when writing an Entry with Index i, any previously-persisted entries with Index >= i must be discarded.
func (*RaftDiskStorage) SaveEntries ¶
func (*RaftDiskStorage) SetUint ¶
func (rds *RaftDiskStorage) SetUint(info MetaInfo, id uint64)
func (*RaftDiskStorage) Snapshot ¶
func (rds *RaftDiskStorage) Snapshot() (raftpb.Snapshot, error)
Snapshot returns the most recent snapshot. If snapshot is temporarily unavailable, it should return ErrSnapshotTemporarilyUnavailable, so raft state machine could know that Storage needs some time to prepare snapshot and call Snapshot later.
func (*RaftDiskStorage) TrySync ¶
func (rds *RaftDiskStorage) TrySync() error
TrySync trys to write all the contents to disk.
func (*RaftDiskStorage) Uint ¶
func (rds *RaftDiskStorage) Uint(info MetaInfo) uint64
func (*RaftDiskStorage) UnLock ¶ added in v1.5.2
func (rds *RaftDiskStorage) UnLock()
type SnapShotter ¶
type SnapShotter struct {
RaftFlag uint32 // 1 represents advancing committedIndex , other num represents suspending committedIndex
RaftFlushC chan bool
CommittedIndex uint64
// contains filtered or unexported fields
}
func (*SnapShotter) TryToUpdateCommittedIndex ¶
func (s *SnapShotter) TryToUpdateCommittedIndex(index uint64)