From f867f498456fefd23cadb7e8ae383fbe68aa891e Mon Sep 17 00:00:00 2001 From: ekexium Date: Tue, 6 Sep 2022 17:45:32 +0800 Subject: [PATCH] add a flag PreviousPresumeKNE (#581) Signed-off-by: ekexium --- kv/keyflags.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kv/keyflags.go b/kv/keyflags.go index d0c00d4b..5c8fb4cc 100644 --- a/kv/keyflags.go +++ b/kv/keyflags.go @@ -68,6 +68,15 @@ const ( // (a conflict check + a constraint check) in prewrite. flagNeedConstraintCheckInPrewrite + // A PresumeKNE that should not be unset. It's used by lazy uniqueness checks. So that PresumeKNE flags in previous + // statement should not be mistakenly unset. + // It's only set when a stmt that sets PresumeKNE finishes. + // It's only read together with PresumeKNE + // It doesn't have to be persistent, since the only place where it is used is in statement retry where it helps set + // the correct assert_not_exist option. The life of the flag begins after stmt which sets the PresumeKNE flag, and + // ends when the lock is acquired. + flagPreviousPresumeKNE + persistentFlags = flagKeyLocked | flagKeyLockedValExist | flagNeedConstraintCheckInPrewrite ) @@ -93,7 +102,7 @@ func (f KeyFlags) HasAssertionFlags() bool { // HasPresumeKeyNotExists returns whether the associated key use lazy check. func (f KeyFlags) HasPresumeKeyNotExists() bool { - return f&flagPresumeKNE != 0 + return f&(flagPresumeKNE|flagPreviousPresumeKNE) != 0 } // HasLocked returns whether the associated key has acquired pessimistic lock. @@ -194,6 +203,8 @@ func ApplyFlagsOps(origin KeyFlags, ops ...FlagsOp) KeyFlags { origin |= flagNeedConstraintCheckInPrewrite case DelNeedConstraintCheckInPrewrite: origin &= ^flagNeedConstraintCheckInPrewrite + case SetPreviousPresumeKNE: + origin |= flagPreviousPresumeKNE } } return origin @@ -243,4 +254,6 @@ const ( // DelNeedConstraintCheckInPrewrite reverts SetNeedConstraintCheckInPrewrite. This is required when we decide to // make up the pessimistic lock. DelNeedConstraintCheckInPrewrite + // SetPreviousPresumeKNE sets flagPreviousPresumeKNE. + SetPreviousPresumeKNE )