Documentation ¶
Index ¶
- Constants
- Variables
- func ChainRPCClient(server string) (*rpchttp.HTTP, error)
- func RestoreDB(ctx context.Context, snapshot io.Reader, ...) error
- func ToABCIApplySnapshotChunkResponse(err error) abciTypes.ResponseApplySnapshotChunk_Result
- func ToABCIOfferSnapshotResponse(err error) abciTypes.ResponseOfferSnapshot_Result
- type DBConfig
- type DBSnapshotter
- type Snapshot
- type SnapshotConfig
- type SnapshotStore
- func (s *SnapshotStore) CreateSnapshot(ctx context.Context, height uint64, snapshotID string, ...) error
- func (s *SnapshotStore) IsSnapshotDue(height uint64) bool
- func (s *SnapshotStore) ListSnapshots() []*Snapshot
- func (s *SnapshotStore) LoadSnapshotChunk(height uint64, format uint32, chunkIdx uint32) ([]byte, error)
- func (s *SnapshotStore) RegisterSnapshot(snapshot *Snapshot) error
- type Snapshotter
- type StateSyncer
- type Streamer
Constants ¶
const ( DefaultSnapshotFormat = 0 CreateSchema = "CREATE SCHEMA" CreateTable = "CREATE TABLE" CreateFunction = "CREATE FUNCTION" )
const ( ABCISnapshotQueryPath = "/snapshot/height" ABCILatestSnapshotHeightPath = "/snapshot/latest" )
const HashLen int = 32
Variables ¶
var ( ErrStateSyncInProgress = fmt.Errorf("statesync already in progress") ErrStateSyncNotInProgress = fmt.Errorf("statesync not in progress") ErrAbortSnapshot = fmt.Errorf("abort snapshot") ErrRejectSnapshot = fmt.Errorf("reject snapshot") ErrUnsupportedSnapshotFormat = fmt.Errorf("unsupported snapshot format") ErrInvalidSnapshot = fmt.Errorf("invalid snapshot") ErrAbortSnapshotChunk = fmt.Errorf("abort snapshot chunk") ErrRetrySnapshotChunk = fmt.Errorf("retry snapshot chunk") // retries without refetching the chunk ErrRefetchSnapshotChunk = fmt.Errorf("refetch snapshot chunk") // retries after refetching the chunk ErrRejectSnapshotChunk = fmt.Errorf("reject snapshot chunk") )
Functions ¶
func ChainRPCClient ¶
rpcClient sets up a new RPC client
func RestoreDB ¶
func RestoreDB(ctx context.Context, snapshot io.Reader, dbName, dbUser, dbPass, dbHost, dbPort string, snapshotHash []byte, logger log.Logger) error
RestoreDB restores the database from the logical sql dump using psql command It also validates the snapshot hash, before restoring the database
func ToABCIApplySnapshotChunkResponse ¶
func ToABCIApplySnapshotChunkResponse(err error) abciTypes.ResponseApplySnapshotChunk_Result
func ToABCIOfferSnapshotResponse ¶
func ToABCIOfferSnapshotResponse(err error) abciTypes.ResponseOfferSnapshot_Result
Types ¶
type DBSnapshotter ¶
type Snapshot ¶
type Snapshot struct { Height uint64 `json:"height"` Format uint32 `json:"format"` ChunkHashes [][HashLen]byte `json:"chunk_hashes"` ChunkCount uint32 `json:"chunk_count"` SnapshotHash []byte `json:"hash"` SnapshotSize uint64 `json:"size"` }
Snapshot is the header of a snapshot file representing the snapshot of the database at a certain height. It contains the height, format, chunk count, hash, size, and name of the snapshot. WARNING: This struct CAN NOT be changed without breaking functionality, since it is used for communication between nodes.
func GetLatestSnapshotInfo ¶ added in v0.9.0
func GetLatestSnapshotInfo(ctx context.Context, client cometClient.ABCIClient) (*Snapshot, error)
GetLatestSnapshotHeight queries the trusted snapshot providers to get the latest snapshot height.
func (*Snapshot) MarshalBinary ¶ added in v0.9.0
func (*Snapshot) UnmarshalBinary ¶ added in v0.9.0
type SnapshotConfig ¶
type SnapshotStore ¶
type SnapshotStore struct {
// contains filtered or unexported fields
}
func NewSnapshotStore ¶
func NewSnapshotStore(cfg *SnapshotConfig, dbCfg *DBConfig, logger log.Logger) (*SnapshotStore, error)
func (*SnapshotStore) CreateSnapshot ¶
func (s *SnapshotStore) CreateSnapshot(ctx context.Context, height uint64, snapshotID string, schemas, excludedTables []string, excludeTableData []string) error
CreateSnapshot creates a new snapshot at the given height and snapshot ID. SnapshotStore ensures that the number of snapshots does not exceed the maximum configured snapshots. If exceeds, it deletes the oldest snapshot. It takes a list of schemas, excludedTables and excludeTableData args to specify the contents of the snapshot. schemas: list of schemas to include in the snapshot excludedTables: list of tables to exclude from the snapshot excludeTableData: list of tables to include schema but exclude data from the snapshot
func (*SnapshotStore) IsSnapshotDue ¶
func (s *SnapshotStore) IsSnapshotDue(height uint64) bool
IsSnapshotDue checks if a snapshot is due at the given height.
func (*SnapshotStore) ListSnapshots ¶
func (s *SnapshotStore) ListSnapshots() []*Snapshot
List snapshots lists all the registered snapshots in the snapshot store.
func (*SnapshotStore) LoadSnapshotChunk ¶
func (s *SnapshotStore) LoadSnapshotChunk(height uint64, format uint32, chunkIdx uint32) ([]byte, error)
LoadSnapshotChunk loads a snapshot chunk at the given height and chunk index of given format. It returns the snapshot chunk as a byte slice of max size 16MB. errors if the chunk of chunkIndex corresponding to snapshot at given height and format does not exist.
func (*SnapshotStore) RegisterSnapshot ¶
func (s *SnapshotStore) RegisterSnapshot(snapshot *Snapshot) error
RegisterSnapshot registers the existing snapshot in the snapshot store. It ensures that the number of snapshots does not exceed the maximum configured snapshots. If exceeds, it deletes the oldest snapshot.
type Snapshotter ¶
type Snapshotter struct {
// contains filtered or unexported fields
}
func NewSnapshotter ¶
func NewSnapshotter(cfg *DBConfig, dir string, logger log.Logger) *Snapshotter
type StateSyncer ¶
type StateSyncer struct {
// contains filtered or unexported fields
}
func NewStateSyncer ¶
func NewStateSyncer(ctx context.Context, cfg *DBConfig, snapshotDir string, providers []string, db sql.ReadTxMaker, logger log.Logger) (*StateSyncer, error)
NewStateSyncer will initialize the state syncer that enables the node to receive and validate snapshots from the network and initialize the database state. It takes the database configuration, snapshot directory, and the trusted snapshot providers. Trusted snapshot providers are special nodes in the network trusted by the nodes and have snapshot creation enabled. These nodes are responsible for creating and validating snapshots.
func (*StateSyncer) ApplySnapshotChunk ¶
func (ss *StateSyncer) ApplySnapshotChunk(ctx context.Context, chunk []byte, index uint32) (bool, error)
ApplySnapshotChunk accepts a chunk and stores it on disk for later processing if valid If all chunks are received, it starts the process of restoring the database
func (*StateSyncer) OfferSnapshot ¶
func (ss *StateSyncer) OfferSnapshot(ctx context.Context, snapshot *Snapshot) error
OfferSnapshot checks if the snapshot is valid and kicks off the state sync process accepted snapshot is stored on disk for later processing