-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathcmd_compute_checksum.go
77 lines (68 loc) · 2.71 KB
/
cmd_compute_checksum.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2014 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package batcheval
import (
"context"
"time"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval/result"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/spanset"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/storage"
"github.com/cockroachdb/cockroach/pkg/util/uuid"
)
func init() {
RegisterReadOnlyCommand(roachpb.ComputeChecksum, declareKeysComputeChecksum, ComputeChecksum)
}
func declareKeysComputeChecksum(
desc *roachpb.RangeDescriptor,
_ roachpb.Header,
_ roachpb.Request,
latchSpans, _ *spanset.SpanSet,
) {
// The correctness of range merges depends on the lease applied index of a
// range not being bumped while the RHS is subsumed. ComputeChecksum bumps a
// range's LAI and thus needs to be serialized with Subsume requests, in order
// prevent a rare a closed timestamp violation due to writes on the
// post-merged range that violate a closed timestamp spuriously reported by
// the pre-merged range. This can, in turn, lead to a serializability
// violation. See comment at the end of Subsume() in cmd_subsume.go for
// details. Thus, it must declare access over at least one key. We choose to
// declare read-only access to the range descriptor key.
rdKey := keys.RangeDescriptorKey(desc.StartKey)
latchSpans.AddNonMVCC(spanset.SpanReadOnly, roachpb.Span{Key: rdKey})
}
// Version numbers for Replica checksum computation. Requests silently no-op
// unless the versions are compatible.
const (
ReplicaChecksumVersion = 4
ReplicaChecksumGCInterval = time.Hour
)
// ComputeChecksum starts the process of computing a checksum on the replica at
// a particular snapshot. The checksum is later verified through a
// CollectChecksumRequest.
func ComputeChecksum(
_ context.Context, _ storage.Reader, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error) {
args := cArgs.Args.(*roachpb.ComputeChecksumRequest)
reply := resp.(*roachpb.ComputeChecksumResponse)
reply.ChecksumID = uuid.MakeV4()
var pd result.Result
pd.Replicated.ComputeChecksum = &kvserverpb.ComputeChecksum{
Version: args.Version,
ChecksumID: reply.ChecksumID,
SaveSnapshot: args.Snapshot,
Mode: args.Mode,
Checkpoint: args.Checkpoint,
Terminate: args.Terminate,
}
return pd, nil
}