github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/batcheval/result/intent.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 result 12 13 import ( 14 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/lock" 15 "github.com/cockroachdb/cockroach/pkg/roachpb" 16 ) 17 18 // FromEncounteredIntents creates a Result communicating that the intents were 19 // encountered and should be handled. 20 func FromEncounteredIntents(intents []roachpb.Intent) Result { 21 var pd Result 22 if len(intents) == 0 { 23 return pd 24 } 25 pd.Local.EncounteredIntents = intents 26 return pd 27 } 28 29 // FromAcquiredLocks creates a Result communicating that the locks were 30 // acquired or re-acquired by the given transaction and should be handled. 31 func FromAcquiredLocks(txn *roachpb.Transaction, keys ...roachpb.Key) Result { 32 var pd Result 33 if txn == nil { 34 return pd 35 } 36 pd.Local.AcquiredLocks = make([]roachpb.LockAcquisition, len(keys)) 37 for i := range pd.Local.AcquiredLocks { 38 pd.Local.AcquiredLocks[i] = roachpb.MakeLockAcquisition(txn, keys[i], lock.Replicated) 39 } 40 return pd 41 } 42 43 // EndTxnIntents contains a finished transaction and a bool (Always), 44 // which indicates whether the intents should be resolved whether or 45 // not the command succeeds through Raft. 46 type EndTxnIntents struct { 47 Txn *roachpb.Transaction 48 Always bool 49 Poison bool 50 } 51 52 // FromEndTxn creates a Result communicating that a transaction was 53 // completed and its locks should be resolved. 54 func FromEndTxn(txn *roachpb.Transaction, alwaysReturn, poison bool) Result { 55 var pd Result 56 if len(txn.LockSpans) == 0 { 57 return pd 58 } 59 pd.Local.EndTxns = []EndTxnIntents{{Txn: txn, Always: alwaysReturn, Poison: poison}} 60 return pd 61 }