Skip to content

Commit

Permalink
server: introduce a hook for short-running migrations
Browse files Browse the repository at this point in the history
TODO: see if this migration is actually "short-running". That is,
in a sufficiently large cluster, does this cause significant load?

----

This is a baby version of cockroachdb#39182 that handles only short-running
migrations but is useful in itself because it allows us to migrate us
fully into the following two KV below-Raft migrations:

1. use the RangeAppliedState on all ranges
2. use the unreplicated TruncatedState on all ranges

These two migrations have been around for a while and it has been
getting in the way of things. While ideally we introduce cockroachdb#39182 in the
near future and use it to address a larger class of migration concerns,
this PR serves as a starting point and work done on cockroachdb#39182 should be
able to absorb this PR with relative ease.

With this PR, legacy code related to 1) and 2) above can be removed from
`master` once the 20.1 branch is cut, i.e. roughly in April 2020.

The main ingredients in this PR are

a) introduce a hook that is called during `SET CLUSTER SETTING version`,
   after the change has been validated but before it is made.
b) introduce a KV-level `Migrate` ranged write command that triggers
   the migrations for 1) and 2) above. It is called from the hook for
   all of the keyspace.
c) before returning to the client, `Migrate` waits for the command to
   be durably applied on all followers.

Trying to get this 100% correct has proven tricky, perhaps foreshadowing
similar issues that expect us once we try cockroachdb#39182 in earnest. For one,
the mechanism only reaches replicas that members of the raft group, that
is, it won't touch replicas which are gc'able. For the migrations at
hand this means that in 20.2 there may - in theory - still be replicas
that have a replicated truncated state. I believe that our recent
efforts around not re-using replicas across replicaIDs has made sure
that this isn't an issue for this particular migration, but in general
it will have to remain on the radar. Similarly, it seems hard to prove
conclusively that no snapshot is in-flight that would set up a new
follower with a state predating the explicit migration, though it would
be exceptionally rare in practice.

Release note (general change): version upgrades now perform maintenance
duties that may slightly delay the `SET CLUSTER SETTING version` command
and may cause a small amount of additional load on the cluster while an
upgrade is being finalized.
  • Loading branch information
tbg committed Dec 2, 2019
1 parent 6901e65 commit 23ef7bb
Show file tree
Hide file tree
Showing 34 changed files with 3,092 additions and 1,049 deletions.
597 changes: 589 additions & 8 deletions c-deps/libroach/protos/roachpb/api.pb.cc

Large diffs are not rendered by default.

559 changes: 537 additions & 22 deletions c-deps/libroach/protos/roachpb/api.pb.h

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions pkg/roachpb/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@ func (*ImportRequest) Method() Method { return Import }
// Method implements the Request interface.
func (*AdminScatterRequest) Method() Method { return AdminScatter }

func (*MigrateRequest) Method() Method { return Migrate }

// Method implements the Request interface.
func (*AddSSTableRequest) Method() Method { return AddSSTable }

Expand Down Expand Up @@ -828,6 +830,11 @@ func (r *AdminScatterRequest) ShallowCopy() Request {
return &shallowCopy
}

func (r *MigrateRequest) ShallowCopy() Request {
shallowCopy := *r
return &shallowCopy
}

// ShallowCopy implements the Request interface.
func (r *AddSSTableRequest) ShallowCopy() Request {
shallowCopy := *r
Expand Down Expand Up @@ -1126,6 +1133,7 @@ func (*WriteBatchRequest) flags() int { return isWrite | isRange }
func (*ExportRequest) flags() int { return isRead | isRange | updatesReadTSCache }
func (*ImportRequest) flags() int { return isAdmin | isAlone }
func (*AdminScatterRequest) flags() int { return isAdmin | isRange | isAlone }
func (*MigrateRequest) flags() int { return isWrite | isRange | isAlone }
func (*AddSSTableRequest) flags() int {
return isWrite | isRange | isAlone | isUnsplittable | canBackpressure
}
Expand Down
2,327 changes: 1,445 additions & 882 deletions pkg/roachpb/api.pb.go

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions pkg/roachpb/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,23 @@ message AdminScatterResponse {
repeated Range ranges = 2 [(gogoproto.nullable) = false];
}

// MigrateRequest forces all ranges overlapping it to proactively move out of
// any legacy modes that they are currently in. When this command returns, the
// ranges are ready to run with the most up to date cluster version supported
// by this binary.
message MigrateRequest {
option (gogoproto.equal) = true;

RequestHeader header = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true];
// The new version that will become active next.
Version NewVersion = 2 [(gogoproto.nullable) = false];
}

// MigrateResponse is the response to an Migrate operation.
message MigrateResponse {
ResponseHeader header = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true];
}

// AddSSTableRequest is arguments to the AddSSTable() method, to link a file
// into the RocksDB log-structured merge-tree.
message AddSSTableRequest {
Expand Down Expand Up @@ -1684,6 +1701,7 @@ message RequestUnion {
RefreshRangeRequest refresh_range = 41;
SubsumeRequest subsume = 43;
RangeStatsRequest range_stats = 44;
MigrateRequest migrate = 49;
}
reserved 15, 23, 25, 27;
}
Expand Down Expand Up @@ -1735,6 +1753,7 @@ message ResponseUnion {
RefreshRangeResponse refresh_range = 41;
SubsumeResponse subsume = 43;
RangeStatsResponse range_stats = 44;
MigrateResponse migrate = 49;
}
reserved 15, 23, 25, 27, 28;
}
Expand Down
25 changes: 24 additions & 1 deletion pkg/roachpb/batch_generated.go

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

Loading

0 comments on commit 23ef7bb

Please sign in to comment.