Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: ekexium <[email protected]>
  • Loading branch information
ekexium committed Nov 18, 2024
1 parent 5461693 commit fa81972
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
6 changes: 0 additions & 6 deletions tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,12 +951,6 @@ func WithPipelinedMemDB() TxnOption {
}
}

func WithPrewriteEncounterLockPolicy(policy transaction.PrewriteEncounterLockPolicy) TxnOption {
return func(st *transaction.TxnOptions) {
st.PrewriteEncounterLockPolicy = policy
}
}

// TODO: remove once tidb and br are ready

// KVTxn contains methods to interact with a TiKV transaction.
Expand Down
2 changes: 1 addition & 1 deletion txnkv/transaction/prewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func (action actionPrewrite) handleSingleBatch(
// TiKV will return a PessimisticLockNotFound error directly if it encounters a different lock. Otherwise,
// TiKV returns lock.TTL = 0, and we still need to resolve the lock.
if (lock.TxnID > c.startTS && !c.isPessimistic) ||
c.txn.prewriteEncounterLockPolicy == TryResolvePolicy {
c.txn.prewriteEncounterLockPolicy == NoResolvePolicy {
return tikverr.NewErrWriteConflictWithArgs(
c.startTS,
lock.TxnID,
Expand Down
7 changes: 6 additions & 1 deletion txnkv/transaction/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ type TxnOptions struct {
TxnScope string
StartTS *uint64
PipelinedMemDB bool
PrewriteEncounterLockPolicy PrewriteEncounterLockPolicy
}

// PrewriteEncounterLockPolicy specifies the policy when prewrite encounters locks.
type PrewriteEncounterLockPolicy int

const (
// TryResolvePolicy is the default one: try to resolve those locks with smaller startTS.
TryResolvePolicy PrewriteEncounterLockPolicy = iota
Expand Down Expand Up @@ -496,6 +496,11 @@ func (txn *KVTxn) SetAssertionLevel(assertionLevel kvrpcpb.AssertionLevel) {
txn.assertionLevel = assertionLevel
}

// SetPrewriteEncounterLockPolicy specifies the behavior when prewrite encounters locks.
func (txn *KVTxn) SetPrewriteEncounterLockPolicy(policy PrewriteEncounterLockPolicy) {
txn.prewriteEncounterLockPolicy = policy
}

// IsPessimistic returns true if it is pessimistic.
func (txn *KVTxn) IsPessimistic() bool {
return txn.isPessimistic
Expand Down

0 comments on commit fa81972

Please sign in to comment.