Skip to content

Commit 9c45896

Browse files
craig[bot]beneschRaduBerinde
committed
29067: storage: protect ComputeChecksum commands from replaying r=tschottdorf a=benesch Previously, a ComputeChecksum command could apply twice with the same ID. Consider the following sequence of events: 1. DistSender sends a ComputeChecksum request to a replica. 2. The request is succesfully evaluated and proposed, but a connection error occurs. 3. DistSender retries the request, leaving the checksum ID unchanged! This would result in two ComputeChecksum commands with the same checksum ID in the Raft log. Somewhat amazingly, this typically wasn't problematic. If all replicas were online and reasonably up-to-date, they'd see the first ComputeChecksum command, compute its checksum, and store it in the checksums map. When they saw the duplicated ComputeChecksum command, they'd see that a checksum with that ID already existed and ignore it. In effect, only the first ComputeChecksum command for a given checksum ID mattered. The problem occured when one replica saw one ComputeChecksum command but not the other. There were two ways this could occur. A replica could go offline after computing the checksum the first time; when it came back online, it would have an empty checksum map, and the checksum computed for the second ComputeChecksum command would be recorded instead. Or a replica could receive a snapshot that advanced it past one ComputeChecksum but not the other. In both cases, the replicas could spuriously fail a consistency check. A very similar problem occured with range merges because ComputeChecksum requests are incorrectly ranged (see #29002). That means DistSender might split a ComputeChecksum request in two. Consider what happens when a consistency check occurs immediately after a merge: the ComputeChecksum request is generated using the up-to-date, post-merge descriptor, but DistSender might have the pre-merge descriptors cached, and so it splits the batch in two. Both halves of the batch would get routed to the same range, and both halves would have the same command ID, resulting in the same duplicated ComputeChecksum command problem. The fix for these problems is to assign the checksum ID when the ComputeChecksum request is evaluated. If the request is retried, it will be properly assigned a new checksum ID. Note that we don't need to worry about reproposals causing duplicate commands, as the MaxLeaseIndex prevents proposals from replay. The version compatibility story here is straightforward. The ReplicaChecksumVersion is bumped, so v2.0 nodes will turn ComputeChecksum requests proposed by v2.1 nodes into a no-op, and vice-versa. The consistency queue will spam some complaints into the log about this--it will time out while collecting checksums--but this will stop as soon as all nodes have been upgraded to the new version.† Note that this commit takes the opportunity to migrate storagebase.ReplicatedEvalResult.ComputeChecksum from roachpb.ComputeChecksumRequest to a dedicated storagebase.ComputeChecksum message. Separate types are more in line with how the merge/split/change replicas triggers work and avoid shipping unnecessary fields through Raft. Note that even though this migration changes logic downstream of Raft, it's safe. v2.1 nodes will turn any ComputeChecksum commands that were commited by v2.0 nodes into no-ops, and vice-versa, but the only effect of this will be some temporary consistency queue spam. As an added bonus, because we're guaranteed that we'll never see duplicate v2.1-style ComputeChecksum commands, we can properly fatal if we ever see a ComputeChecksum request with a checksum ID that we've already computed. † It would be possible to put the late-ID allocation behind a cluster version to avoid the log spam, but that amounts to allowing v2.1 to initiate known-buggy consistency checks. A bit of log spam seems preferable. Fix #28995. 29083: storage: fix raft snapshots that span merges and splits r=tschottdorf a=benesch The code that handles Raft snapshots that span merges did not account for snapshots that spanned merges AND splits. Handle this case by allowing snapshot subsumption even when the snapshot's end key does not exactly match the end of an existing replica. See the commits within the patch for details. Fix #29080. Release note: None 29117: opt: fix LookupJoinDef interning, add tests r=RaduBerinde a=RaduBerinde Fixing an omission I noticed in internLookupJoinDef and adding missing tests for interning defs. Release note: None Co-authored-by: Nikhil Benesch <[email protected]> Co-authored-by: Radu Berinde <[email protected]>
4 parents 403ca04 + c952cb3 + 736822a + 2545589 commit 9c45896

15 files changed

+1318
-633
lines changed

pkg/roachpb/api.pb.go

+412-415
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/roachpb/api.proto

+7-5
Original file line numberDiff line numberDiff line change
@@ -991,11 +991,7 @@ message ComputeChecksumRequest {
991991
// The version used to pick the checksum method. It allows us to use a
992992
// consistent checksumming method across replicas.
993993
uint32 version = 2;
994-
// A unique identifier to match a future storage.CollectChecksumRequest with
995-
// this request.
996-
bytes checksum_id = 3 [(gogoproto.nullable) = false,
997-
(gogoproto.customname) = "ChecksumID",
998-
(gogoproto.customtype) = "github.com/cockroachdb/cockroach/pkg/util/uuid.UUID"];
994+
reserved 3;
999995
// Compute a checksum along with a snapshot of the entire range, that will be
1000996
// used in logging a diff during checksum verification.
1001997
bool snapshot = 4;
@@ -1004,6 +1000,12 @@ message ComputeChecksumRequest {
10041000
// A ComputeChecksumResponse is the response to a ComputeChecksum() operation.
10051001
message ComputeChecksumResponse {
10061002
ResponseHeader header = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true];
1003+
1004+
// ChecksumID is the unique identifier that can be used to get the computed
1005+
// checksum in a future storage.CollectChecksumRequest.
1006+
bytes checksum_id = 2 [(gogoproto.nullable) = false,
1007+
(gogoproto.customname) = "ChecksumID",
1008+
(gogoproto.customtype) = "github.com/cockroachdb/cockroach/pkg/util/uuid.UUID"];
10071009
}
10081010

10091011
enum ExportStorageProvider {

pkg/roachpb/batch.go

+10
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,16 @@ func (ba *BatchRequest) IsSingleSubsumeRequest() bool {
188188
return false
189189
}
190190

191+
// IsSingleComputeChecksumRequest returns true iff the batch contains a single
192+
// request, and that request is a ComputeChecksumRequest.
193+
func (ba *BatchRequest) IsSingleComputeChecksumRequest() bool {
194+
if ba.IsSingleRequest() {
195+
_, ok := ba.Requests[0].GetInner().(*ComputeChecksumRequest)
196+
return ok
197+
}
198+
return false
199+
}
200+
191201
// GetPrevLeaseForLeaseRequest returns the previous lease, at the time
192202
// of proposal, for a request lease or transfer lease request. If the
193203
// batch does not contain a single lease request, this method will panic.

pkg/sql/opt/memo/private_storage.go

+2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ func (ps *privateStorage) internLookupJoinDef(def *LookupJoinDef) PrivateID {
315315
// The below code is carefully constructed to not allocate in the case where
316316
// the value is already in the map. Be careful when modifying.
317317
ps.keyBuf.Reset()
318+
ps.keyBuf.writeUvarint(uint64(def.JoinType))
318319
ps.keyBuf.writeUvarint(uint64(def.Table))
320+
ps.keyBuf.writeUvarint(uint64(def.Index))
319321
ps.keyBuf.writeColList(def.KeyCols)
320322
// Add a separator between the list and the set. Note that the column IDs
321323
// cannot be 0.

0 commit comments

Comments
 (0)