github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/batcheval/cmd_resolve_intent_range.go (about) 1 // Copyright 2014 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package batcheval 12 13 import ( 14 "context" 15 16 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval/result" 17 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/spanset" 18 "github.com/cockroachdb/cockroach/pkg/roachpb" 19 "github.com/cockroachdb/cockroach/pkg/storage" 20 ) 21 22 func init() { 23 RegisterReadWriteCommand(roachpb.ResolveIntentRange, declareKeysResolveIntentRange, ResolveIntentRange) 24 } 25 26 func declareKeysResolveIntentRange( 27 _ *roachpb.RangeDescriptor, 28 header roachpb.Header, 29 req roachpb.Request, 30 latchSpans, _ *spanset.SpanSet, 31 ) { 32 declareKeysResolveIntentCombined(header, req, latchSpans) 33 } 34 35 // ResolveIntentRange resolves write intents in the specified 36 // key range according to the status of the transaction which created it. 37 func ResolveIntentRange( 38 ctx context.Context, readWriter storage.ReadWriter, cArgs CommandArgs, resp roachpb.Response, 39 ) (result.Result, error) { 40 args := cArgs.Args.(*roachpb.ResolveIntentRangeRequest) 41 h := cArgs.Header 42 ms := cArgs.Stats 43 44 if h.Txn != nil { 45 return result.Result{}, ErrTransactionUnsupported 46 } 47 48 update := args.AsLockUpdate() 49 50 iterAndBuf := storage.GetIterAndBuf(readWriter, storage.IterOptions{UpperBound: args.EndKey}) 51 defer iterAndBuf.Cleanup() 52 53 numKeys, resumeSpan, err := storage.MVCCResolveWriteIntentRangeUsingIter( 54 ctx, readWriter, iterAndBuf, ms, update, h.MaxSpanRequestKeys, 55 ) 56 if err != nil { 57 return result.Result{}, err 58 } 59 reply := resp.(*roachpb.ResolveIntentRangeResponse) 60 reply.NumKeys = numKeys 61 if resumeSpan != nil { 62 update.EndKey = resumeSpan.Key 63 reply.ResumeSpan = resumeSpan 64 reply.ResumeReason = roachpb.RESUME_KEY_LIMIT 65 } 66 67 var res result.Result 68 res.Local.ResolvedLocks = []roachpb.LockUpdate{update} 69 res.Local.Metrics = resolveToMetricType(args.Status, args.Poison) 70 71 if WriteAbortSpanOnResolve(args.Status, args.Poison, numKeys > 0) { 72 if err := UpdateAbortSpan(ctx, cArgs.EvalCtx, readWriter, ms, args.IntentTxn, args.Poison); err != nil { 73 return result.Result{}, err 74 } 75 } 76 return res, nil 77 }