Skip to content

Commit

Permalink
storage: write min version file with checkpoint
Browse files Browse the repository at this point in the history
We now write out the min version file with checkpoints generated
through the storage layer. This allows checkpoints to be opened with
the cockroach storage layer (not just with the low level pebble tool).

Informs cockroachdb#97337

Release note: None
Epic: none
  • Loading branch information
RaduBerinde committed Feb 21, 2023
1 parent 577da11 commit 15351c0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
21 changes: 16 additions & 5 deletions pkg/storage/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,15 +1004,26 @@ func TestCreateCheckpoint(t *testing.T) {
assert.NoError(t, err)
defer db.Close()

dir = filepath.Join(dir, "checkpoint")
checkpointDir := filepath.Join(dir, "checkpoint")

assert.NoError(t, err)
assert.NoError(t, db.CreateCheckpoint(dir, nil))
assert.DirExists(t, dir)
m, err := filepath.Glob(dir + "/*")
assert.NoError(t, db.CreateCheckpoint(checkpointDir, nil))
assert.DirExists(t, checkpointDir)
m, err := filepath.Glob(checkpointDir + "/*")
assert.NoError(t, err)
assert.True(t, len(m) > 0)
if err := db.CreateCheckpoint(dir, nil); !testutils.IsError(err, "exists") {

// Verify that we can open the checkpoint.
db2, err := Open(
context.Background(),
Filesystem(checkpointDir),
cluster.MakeTestingClusterSettings(),
MustExist)
require.NoError(t, err)
db2.Close()

// Verify that creating another checkpoint in the same directory fails.
if err := db.CreateCheckpoint(checkpointDir, nil); !testutils.IsError(err, "exists") {
t.Fatal(err)
}
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/storage/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -1950,11 +1950,21 @@ func (p *Pebble) CreateCheckpoint(dir string, spans []roachpb.Span) error {
return err
}

// Write out the min version file.
if err := writeMinVersionFile(p.unencryptedFS, dir, p.MinVersion()); err != nil {
return errors.Wrapf(err, "writing min version file for checkpoint")
}

// TODO(#90543, cockroachdb/pebble#2285): move spans info to Pebble manifest.
if len(spans) > 0 {
return fs.SafeWriteToFile(p.fs, dir, p.fs.PathJoin(dir, "checkpoint.txt"),
checkpointSpansNote(spans))
if err := fs.SafeWriteToFile(
p.fs, dir, p.fs.PathJoin(dir, "checkpoint.txt"),
checkpointSpansNote(spans),
); err != nil {
return err
}
}

return nil
}

Expand Down

0 comments on commit 15351c0

Please sign in to comment.