Documentation ¶
Overview ¶
Package checkpoint provides methods for creating MKVS checkpoints.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCheckpointNotFound is the error when a checkpoint is not found. ErrCheckpointNotFound = errors.New(moduleName, 1, "checkpoint: not found") // ErrChunkNotFound is the error when a chunk is not found. ErrChunkNotFound = errors.New(moduleName, 2, "checkpoint: chunk not found") // ErrRestoreAlreadyInProgress is the error when a checkpoint restore is already in progress and // the caller wanted to start another restore. ErrRestoreAlreadyInProgress = errors.New(moduleName, 3, "checkpoint: restore already in progress") // ErrNoRestoreInProgress is the error when no checkpoint restore is currently in progress. ErrNoRestoreInProgress = errors.New(moduleName, 4, "checkpoint: no restore in progress") // ErrChunkAlreadyRestored is the error when a chunk has already been restored. ErrChunkAlreadyRestored = errors.New(moduleName, 5, "checkpoint: chunk already restored") // ErrChunkProofVerificationFailed is the error when a chunk fails proof verification. ErrChunkProofVerificationFailed = errors.New(moduleName, 6, "chunk: chunk proof verification failed") // ErrChunkCorrupted is the error when a chunk is corrupted. ErrChunkCorrupted = errors.New(moduleName, 7, "chunk: corrupted chunk") )
Functions ¶
This section is empty.
Types ¶
type Checkpointer ¶
type Checkpointer interface { // NotifyNewVersion notifies the checkpointer that a new version has been finalized. NotifyNewVersion(version uint64) }
Checkpointer is a checkpointer.
func NewCheckpointer ¶
func NewCheckpointer( ctx context.Context, ndb db.NodeDB, creator Creator, cfg CheckpointerConfig, ) (Checkpointer, error)
NewCheckpointer creates a new checkpointer that can be notified of new finalized versions and will automatically generate the configured number of checkpoints.
type CheckpointerConfig ¶
type CheckpointerConfig struct { // Name identifying this checkpointer in logs. Name string // Namespace is the storage namespace this checkpointer is for. Namespace common.Namespace // CheckInterval is the interval on which to check if any checkpointing is needed. CheckInterval time.Duration // RootsPerVersion is the number of roots per version. RootsPerVersion int // Parameters are the checkpoint creation parameters. Parameters *CreationParameters // GetParameters can be used instead of specifying Parameters to dynamically fetch the current // checkpoint parameters. In this case Parameters must be set to nil. GetParameters func(context.Context) (*CreationParameters, error) // GetRoots can be used to override which finalized roots should be checkpointed. If this is not // specified, all finalized roots will be checkpointed. // // This must return exactly RootsPerVersion roots. GetRoots func(context.Context, uint64) ([]hash.Hash, error) }
CheckpointerConfig is a checkpointer configuration.
type ChunkMetadata ¶
type ChunkMetadata struct { Version uint16 `json:"version"` Root node.Root `json:"root"` Index uint64 `json:"index"` Digest hash.Hash `json:"digest"` }
ChunkMetadata is chunk metadata.
type ChunkProvider ¶
type ChunkProvider interface { // GetCheckpoints returns a list of checkpoint metadata for all known checkpoints. GetCheckpoints(ctx context.Context, request *GetCheckpointsRequest) ([]*Metadata, error) // GetCheckpointChunk fetches a specific chunk from an existing chekpoint. GetCheckpointChunk(ctx context.Context, chunk *ChunkMetadata, w io.Writer) error }
ChunkProvider is a chunk provider.
type CreateRestorer ¶
CreateRestorer is an interface that combines the checkpoint creator and restorer.
func NewCreateRestorer ¶
func NewCreateRestorer(creator Creator, restorer Restorer) CreateRestorer
NewCreateRestorer combines a checkpoint creator and a restorer.
type CreationParameters ¶
type CreationParameters struct { // Interval is the expected runtime state checkpoint interval (in rounds). Interval uint64 // NumKept is the expected minimum number of checkpoints to keep. NumKept uint64 // ChunkSize is the chunk size parameter for checkpoint creation. ChunkSize uint64 }
CreationParameters are the checkpoint creation parameters used by the checkpointer.
type Creator ¶
type Creator interface { ChunkProvider // CreateCheckpoint creates a new checkpoint at the given root. CreateCheckpoint(ctx context.Context, root node.Root, chunkSize uint64) (*Metadata, error) // GetCheckpoint retrieves checkpoint metadata for a specific checkpoint. GetCheckpoint(ctx context.Context, version uint16, root node.Root) (*Metadata, error) // DeleteCheckpoint deletes a specific checkpoint. DeleteCheckpoint(ctx context.Context, version uint16, root node.Root) error }
Creator is a checkpoint creator.
type GetCheckpointsRequest ¶
type GetCheckpointsRequest struct { Version uint16 `json:"version"` Namespace common.Namespace `json:"namespace"` // RootVersion specifies an optional root version to limit the request to. If specified, only // checkpoints for roots with the specific version will be considered. RootVersion *uint64 `json:"root_version,omitempty"` }
GetCheckpointsRequest is a GetCheckpoints request.
type Metadata ¶
type Metadata struct { Version uint16 `json:"version"` Root node.Root `json:"root"` Chunks []hash.Hash `json:"chunks"` }
Metadata is checkpoint metadata.
func (*Metadata) EncodedHash ¶
EncodedHash returns the encoded cryptographic hash of the checkpoint metadata.
func (Metadata) GetChunkMetadata ¶
func (m Metadata) GetChunkMetadata(idx uint64) (*ChunkMetadata, error)
GetChunkMetadata returns the chunk metadata for the corresponding chunk.
type Restorer ¶
type Restorer interface { // StartRestore starts a checkpoint restoration process. StartRestore(ctx context.Context, checkpoint *Metadata) error // AbortRestore aborts a checkpoint restore in progress. // // It is not an error to call this method when no checkpoint restore is in progress. AbortRestore(ctx context.Context) error // GetCurrentCheckpoint returns the checkpoint that is being restored. If no restoration is in // progress, this method may return nil. GetCurrentCheckpoint() *Metadata // RestoreChunk restores the given chunk into the underlying node database. // // This method requires that a restoration is in progress. // // Returns true when the checkpoint has been fully restored. RestoreChunk(ctx context.Context, index uint64, r io.Reader) (bool, error) }
Restorer is a checkpoint restorer.