snapshots

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BeginLen = len(ChunkBegin)
View Source
var BoundaryLen = BeginLen + EndLen
View Source
var ChunkBegin = []byte("CK_BEGIN")
View Source
var ChunkEnd = []byte("CK_END")
View Source
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

func (b *Bootstrapper) ApplySnapshotChunk(chunk []byte, index uint32) ([]uint32, Status, error)
    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 Chunker

type Chunker struct {
	// contains filtered or unexported fields
}

func NewChunker

func NewChunker(reader io.Reader, writer io.Writer, chunkSize int64) *Chunker

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 (s *Snapshot) GetChunkHash(chunkID uint32) []byte

func (*Snapshot) SnapshotFileInfo

func (s *Snapshot) SnapshotFileInfo(file string) SnapshotFileInfo

func (*Snapshot) SnapshotMetadata

func (s *Snapshot) SnapshotMetadata() SnapshotMetadata

type SnapshotFileInfo

type SnapshotFileInfo struct {
	Size     uint64 `json:"size"`
	Hash     []byte `json:"hash"`
	BeginIdx uint32 `json:"begin_idx"`
	EndIdx   uint32 `json:"end_idx"`
}

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

type Status

type Status int
const (
	ACCEPT Status = iota
	REJECT
	RETRY
	UNKNOWN
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL