Skip to content

Improve storage.mkvs.checkpoint abstractions #6467

@martintomazic

Description

@martintomazic

Motivation:
checkpoint.Creator and fileProvider are awkward abstraction, especially when using it externally, e.g. new checkpoint create import cmd.

Problem:
Creator is responsible for storing checkpoints as well creating them (abstraction smell).

Proposed Solution:

I suggest to get rid of checkpoint.CreateRestorer entirely and instead define:

// Store manages checkpoint persistence.
type Store interface {
	ChunkProvider

	// 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

	// AddCheckpoint begins a new checkpoint write transaction.
	AddCheckpoint(ctx context.Context, root node.Root) (CheckpointWriter, error)
}

type CheckpointWriter interface {
	writerFactory

	Finalize(meta *Metadata) error

	Abort() error
}

Creating a checkpoint should be instead a package level function:

func CreateCheckpoint(ctx context.Context, ndb db.NodeDB, store Store, root node.Root, chunkSize uint64, chunkerThreads uint16) (*Metadata, error) {

and checkpoint.fileCreator becomes checkpoint.FileStore.

Finally the following change is made to the storage API:

-       // Checkpointer returns the checkpoint creator/restorer for this storage backend.
-       Checkpointer() checkpoint.CreateRestorer
+       // CheckpointStore returns the checkpoint store for this storage backend.
+       CheckpointStore() checkpoint.Store
+
+       // CheckpointRestorer returns the checkpoint restorer for this storage backend.
+       CheckpointRestorer() *checkpoint.Restorer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions