oasisprotocol / oasisprotocol/oasis-core

Improve `storage.mkvs.checkpoint` abstractions

Open
#6,467 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
369
Forks
151
Avg merge
1d 3h
Merged PRs (30d)
6

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing checkpoint.CreateRestorer, fileProvider, fileCreator, and the storage API's Checkpointer references across the checkpoint and storage packages. Compare their responsibilities with the proposed Store, CheckpointWriter, CreateCheckpoint, and FileStore abstractions. Done means the API split is implemented across its consumers and the old abstraction is removed.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.