Skip to content

Commit

Permalink
storage: build SSTable from KV_BATCH snapshot
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
jeffrey-xiao committed Jul 23, 2019
1 parent 61f132c commit 107b8d1
Show file tree
Hide file tree
Showing 13 changed files with 714 additions and 72 deletions.
4 changes: 4 additions & 0 deletions pkg/keys/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ var (
// last verification timestamp (for checking integrity of on-disk data).
// Note: DEPRECATED.
LocalRangeLastVerificationTimestampSuffixDeprecated = []byte("rlvt")
// LocalRangeSSTSnapshotInProgress is the UUID of the snapshot in progress,
// if any. If this key is set, the replica must finish processing the
// snapshot by ingesting the SSTs of the snapshot on startup.
LocalRangeSSTSnapshotInProgressSuffix = []byte("rssp")
// LocalRangePrefix is the prefix identifying per-range data indexed
// by range key (either start key, or some key in the range). The
// key is appended to this prefix, encoded using EncodeBytes. The
Expand Down
6 changes: 6 additions & 0 deletions pkg/keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,3 +974,9 @@ func (b RangeIDPrefixBuf) RangeLastReplicaGCTimestampKey() roachpb.Key {
func (b RangeIDPrefixBuf) RangeLastVerificationTimestampKeyDeprecated() roachpb.Key {
return append(b.unreplicatedPrefix(), LocalRangeLastVerificationTimestampSuffixDeprecated...)
}

// RangeSSTSnapshotInProgress returns a range-local key for the snapshot in
// progress, in any.
func (b RangeIDPrefixBuf) RangeSSTSnapshotInProgress() roachpb.Key {
return append(b.unreplicatedPrefix(), LocalRangeSSTSnapshotInProgressSuffix...)
}
1 change: 1 addition & 0 deletions pkg/keys/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ var (
{name: "RaftTombstone", suffix: LocalRaftTombstoneSuffix},
{name: "RaftHardState", suffix: LocalRaftHardStateSuffix},
{name: "RangeAppliedState", suffix: LocalRangeAppliedStateSuffix},
{name: "RangeSSTSnapshotInProgress", suffix: LocalRangeSSTSnapshotInProgressSuffix},
{name: "RaftAppliedIndex", suffix: LocalRaftAppliedIndexLegacySuffix},
{name: "LeaseAppliedIndex", suffix: LocalLeaseAppliedIndexLegacySuffix},
{name: "RaftLog", suffix: LocalRaftLogSuffix,
Expand Down
233 changes: 197 additions & 36 deletions pkg/roachpb/internal_raft.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions pkg/roachpb/internal_raft.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ message RaftSnapshotData {
// roundtripping through memory.
repeated bytes log_entries = 3;
}

// SSTSnapshotInProgressData is the persisted record that a snapshot is in
// progess which is durably written to coordinate recovery from an untimely
// crash.
message SSTSnapshotInProgressData {
// The uuid of the in-progress snapshot.
optional bytes id = 1 [(gogoproto.nullable) = false,
(gogoproto.customtype) = "github.com/cockroachdb/cockroach/pkg/util/uuid.UUID",
(gogoproto.customname) = "ID"];
}
2 changes: 2 additions & 0 deletions pkg/storage/client_raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/cockroach/pkg/util/stop"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/cockroach/pkg/util/uuid"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -1070,6 +1071,7 @@ func TestFailedSnapshotFillsReservation(t *testing.T) {
RangeSize: 100,
State: storagepb.ReplicaState{Desc: rep.Desc()},
}
header.RaftMessageRequest.Message.Snapshot.Data = uuid.UUID{}.GetBytes()
// Cause this stream to return an error as soon as we ask it for something.
// This injects an error into HandleSnapshotStream when we try to send the
// "snapshot accepted" message.
Expand Down
Loading

0 comments on commit 107b8d1

Please sign in to comment.