-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathcmd_resolve_intent_range.go
74 lines (62 loc) · 2.31 KB
/
cmd_resolve_intent_range.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
// 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"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/storage/batcheval/result"
"github.com/cockroachdb/cockroach/pkg/storage/engine"
"github.com/cockroachdb/cockroach/pkg/storage/spanset"
)
func init() {
RegisterReadWriteCommand(roachpb.ResolveIntentRange, declareKeysResolveIntentRange, ResolveIntentRange)
}
func declareKeysResolveIntentRange(
desc *roachpb.RangeDescriptor, header roachpb.Header, req roachpb.Request, spans *spanset.SpanSet,
) {
declareKeysResolveIntentCombined(desc, header, req, spans)
}
// ResolveIntentRange resolves write intents in the specified
// key range according to the status of the transaction which created it.
func ResolveIntentRange(
ctx context.Context, readWriter engine.ReadWriter, cArgs CommandArgs, resp roachpb.Response,
) (result.Result, error) {
args := cArgs.Args.(*roachpb.ResolveIntentRangeRequest)
h := cArgs.Header
ms := cArgs.Stats
if h.Txn != nil {
return result.Result{}, ErrTransactionUnsupported
}
update := args.AsLockUpdate()
iterAndBuf := engine.GetIterAndBuf(readWriter, engine.IterOptions{UpperBound: args.EndKey})
defer iterAndBuf.Cleanup()
numKeys, resumeSpan, err := engine.MVCCResolveWriteIntentRangeUsingIter(
ctx, readWriter, iterAndBuf, ms, update, h.MaxSpanRequestKeys,
)
if err != nil {
return result.Result{}, err
}
reply := resp.(*roachpb.ResolveIntentRangeResponse)
reply.NumKeys = numKeys
if resumeSpan != nil {
update.EndKey = resumeSpan.Key
reply.ResumeSpan = resumeSpan
reply.ResumeReason = roachpb.RESUME_KEY_LIMIT
}
var res result.Result
res.Local.ResolvedIntents = []roachpb.LockUpdate{update}
res.Local.Metrics = resolveToMetricType(args.Status, args.Poison)
if WriteAbortSpanOnResolve(args.Status, args.Poison, numKeys > 0) {
if err := UpdateAbortSpan(ctx, cArgs.EvalCtx, readWriter, ms, args.IntentTxn, args.Poison); err != nil {
return result.Result{}, err
}
}
return res, nil
}