Documentation ¶
Index ¶
- Variables
- type BootstrapSession
- type Bootstrapper
- type Chunker
- type Snapshot
- type SnapshotFileInfo
- type SnapshotMetadata
- type SnapshotStore
- func (s *SnapshotStore) CreateSnapshot(height uint64) error
- func (s *SnapshotStore) IsSnapshotDue(height uint64) bool
- func (s *SnapshotStore) ListSnapshots() ([]Snapshot, error)
- func (s *SnapshotStore) LoadSnapshotChunk(height uint64, format uint32, chunkID uint32) []byte
- func (s *SnapshotStore) NumSnapshots() uint64
- type SnapshotStoreOpts
- type Snapshotter
- func (s *Snapshotter) CreateChunkFile(chunkID uint32) (*os.File, error)
- func (s *Snapshotter) CreateSnapshot() error
- func (s *Snapshotter) DeleteOldestSnapshot() error
- func (s *Snapshotter) EndSnapshotSession() error
- func (s *Snapshotter) ListSnapshots() ([]Snapshot, error)
- func (s *Snapshotter) LoadSnapshotChunk(height uint64, format uint32, chunkID uint32) ([]byte, error)
- func (s *Snapshotter) ReadSnapshotFile(filePath string) (*Snapshot, error)
- func (s *Snapshotter) StartSnapshotSession(height uint64) error
- type Status
Constants ¶
This section is empty.
Variables ¶
var BeginLen = len(ChunkBegin)
var BoundaryLen = BeginLen + EndLen
var ChunkBegin = []byte("CK_BEGIN")
var ChunkEnd = []byte("CK_END")
var EndLen = len(ChunkEnd)
Functions ¶
This section is empty.
Types ¶
type BootstrapSession ¶
type BootstrapSession struct {
// contains filtered or unexported fields
}
Placeholder for managing the Bootstrap session
type Bootstrapper ¶
type Bootstrapper struct {
// contains filtered or unexported fields
}
Receives snapshot chunks from the network and writes them to disk & restore the DB from the snapshot chunks
func NewBootstrapper ¶
func NewBootstrapper(dbDir string, rcvdSnapsDir string) (*Bootstrapper, error)
func (*Bootstrapper) ApplySnapshotChunk ¶
This has 2 functions: - Validate Chunks received and keep track of chunks - Start the DB restoration process once all the chunks are received > If failures occur during the chunk validation, it probably due to data corruption in which case, we would reject this chunk and request to refetch the chunk > If any failures occur during the db restoration phase, the snapshot is rejected and cometbft has to find another snapshot and startover the db restoration process
func (*Bootstrapper) IsDBRestored ¶
func (b *Bootstrapper) IsDBRestored() bool
func (*Bootstrapper) OfferSnapshot ¶
func (b *Bootstrapper) OfferSnapshot(snapshot *Snapshot) error
Receives snapshot metadata and validates and decides if the snapshot to be applied If snapshot is accepted, it starts the bootstrap session
type Snapshot ¶
type Snapshot struct { Height uint64 `json:"height"` Format uint32 `json:"format"` ChunkCount uint32 `json:"chunk_count"` Hash []byte `json:"hash"` Metadata SnapshotMetadata }
func (*Snapshot) GetChunkHash ¶
func (*Snapshot) SnapshotFileInfo ¶
func (s *Snapshot) SnapshotFileInfo(file string) SnapshotFileInfo
func (*Snapshot) SnapshotMetadata ¶
func (s *Snapshot) SnapshotMetadata() SnapshotMetadata
type SnapshotFileInfo ¶
type SnapshotMetadata ¶
type SnapshotMetadata struct { ChunkHashes map[uint32][]byte `json:"chunk_hashes"` FileInfo map[string]SnapshotFileInfo `json:"file_info"` }
type SnapshotStore ¶
type SnapshotStore struct {
// contains filtered or unexported fields
}
SnapshotStore handles the creation/deletion/loading snapshots
func NewSnapshotStore ¶
func NewSnapshotStore(databaseDir string, snapshotDir string, height uint64, maxSnapshots uint64, opts ...SnapshotStoreOpts) *SnapshotStore
func (*SnapshotStore) CreateSnapshot ¶
func (s *SnapshotStore) CreateSnapshot(height uint64) error
CreateSnapshot creates a snapshot at the given height & deletes the oldest snapshot if the max limit on snapshots has been reached
func (*SnapshotStore) IsSnapshotDue ¶
func (s *SnapshotStore) IsSnapshotDue(height uint64) bool
func (*SnapshotStore) ListSnapshots ¶
func (s *SnapshotStore) ListSnapshots() ([]Snapshot, error)
Lists the snapshot metadata of all the existing snapshots
func (*SnapshotStore) LoadSnapshotChunk ¶
func (s *SnapshotStore) LoadSnapshotChunk(height uint64, format uint32, chunkID uint32) []byte
Loads snapshotChunk of snapshot at given height and chunkIndex
func (*SnapshotStore) NumSnapshots ¶
func (s *SnapshotStore) NumSnapshots() uint64
type SnapshotStoreOpts ¶
type SnapshotStoreOpts func(*SnapshotStore)
func WithChunkSize ¶
func WithChunkSize(chunkSize uint64) SnapshotStoreOpts
func WithLogger ¶
func WithLogger(logger log.Logger) SnapshotStoreOpts
type Snapshotter ¶
type Snapshotter struct { SnapshotDir string // Directory to store snapshots DatabaseDir string // Directory to be snapshotted ChunkSize uint64 // Chunk sizes of snapshots SnapshotFailed bool SnapshotError error Snapshot *Snapshot // Current snapshot info // contains filtered or unexported fields }
func NewSnapshotter ¶
func NewSnapshotter(snapshotDir string, databaseDir string, chunkSz uint64) *Snapshotter
func (*Snapshotter) CreateChunkFile ¶
func (s *Snapshotter) CreateChunkFile(chunkID uint32) (*os.File, error)
func (*Snapshotter) CreateSnapshot ¶
func (s *Snapshotter) CreateSnapshot() error
List all the sqlite files in the database directory in sorted order (for ordering chunks) Divide each file into chunks of 16 MB max Hash each chunk and the entire file Store chunk mapping to file in the snapshot metadata for restoring the DB from chunks
func (*Snapshotter) DeleteOldestSnapshot ¶
func (s *Snapshotter) DeleteOldestSnapshot() error
func (*Snapshotter) EndSnapshotSession ¶
func (s *Snapshotter) EndSnapshotSession() error
Writes Snapshot metadata to disk
func (*Snapshotter) ListSnapshots ¶
func (s *Snapshotter) ListSnapshots() ([]Snapshot, error)
Returns the list of snapshot metadata of all snapshots stored in the snapshot store
func (*Snapshotter) LoadSnapshotChunk ¶
func (s *Snapshotter) LoadSnapshotChunk(height uint64, format uint32, chunkID uint32) ([]byte, error)
Returns the chunk of index chunkID from snapshot at given height
func (*Snapshotter) ReadSnapshotFile ¶
func (s *Snapshotter) ReadSnapshotFile(filePath string) (*Snapshot, error)
func (*Snapshotter) StartSnapshotSession ¶
func (s *Snapshotter) StartSnapshotSession(height uint64) error
Creates /snapshots/<height>/chunks directory & initializes snapshot metadata