Skip to content

Commit 4c16a14

Browse files
committed
fix initKeysAndMutations
Signed-off-by: ekexium <[email protected]>
1 parent c46d490 commit 4c16a14

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

internal/unionstore/art/art_iterator.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import (
1919
"fmt"
2020
"sort"
2121

22+
"github.com/tikv/client-go/v2/internal/logutil"
23+
"go.uber.org/zap"
24+
2225
"github.com/pkg/errors"
2326
"github.com/tikv/client-go/v2/internal/unionstore/arena"
2427
"github.com/tikv/client-go/v2/kv"
@@ -84,7 +87,21 @@ type Iterator struct {
8487
ignoreSeqNo bool
8588
}
8689

87-
func (it *Iterator) Valid() bool { return it.valid && (it.seqNo == it.tree.SeqNo || it.ignoreSeqNo) }
90+
func (it *Iterator) checkSeqNo() {
91+
if it.seqNo != it.tree.SeqNo && !it.ignoreSeqNo {
92+
logutil.BgLogger().Panic(
93+
"seqNo mismatch",
94+
zap.Int("it seqNo", it.seqNo),
95+
zap.Int("art seqNo", it.tree.SeqNo),
96+
zap.Stack("stack"),
97+
)
98+
}
99+
}
100+
101+
func (it *Iterator) Valid() bool {
102+
it.checkSeqNo()
103+
return it.valid
104+
}
88105
func (it *Iterator) Key() []byte { return it.currLeaf.GetKey() }
89106
func (it *Iterator) Flags() kv.KeyFlags { return it.currLeaf.GetKeyFlags() }
90107
func (it *Iterator) Value() []byte {
@@ -108,9 +125,7 @@ func (it *Iterator) Next() error {
108125
// iterate is finished
109126
return errors.New("Art: iterator is finished")
110127
}
111-
if !it.ignoreSeqNo && it.seqNo != it.tree.SeqNo {
112-
return errors.New(fmt.Sprintf("seqNo mismatch: iter=%d, art=%d", it.seqNo, it.tree.SeqNo))
113-
}
128+
it.checkSeqNo()
114129
if it.currAddr == it.endAddr {
115130
it.valid = false
116131
return nil

txnkv/transaction/2pc.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ func (c *twoPhaseCommitter) initKeysAndMutations(ctx context.Context) error {
559559

560560
var err error
561561
var assertionError error
562+
toUpdatePrewriteOnly := make([][]byte, 0)
562563
for it := memBuf.IterWithFlags(nil, nil); it.Valid(); err = it.Next() {
563564
_ = err
564565
key := it.Key()
@@ -607,7 +608,7 @@ func (c *twoPhaseCommitter) initKeysAndMutations(ctx context.Context) error {
607608
// due to `Op_CheckNotExists` doesn't prewrite lock, so mark those keys should not be used in commit-phase.
608609
op = kvrpcpb.Op_CheckNotExists
609610
checkCnt++
610-
memBuf.UpdateFlags(key, kv.SetPrewriteOnly)
611+
toUpdatePrewriteOnly = append(toUpdatePrewriteOnly, key)
611612
} else {
612613
if flags.HasNewlyInserted() {
613614
// The delete-your-write keys in pessimistic transactions, only lock needed keys and skip
@@ -682,6 +683,10 @@ func (c *twoPhaseCommitter) initKeysAndMutations(ctx context.Context) error {
682683
}
683684
}
684685

686+
for _, key := range toUpdatePrewriteOnly {
687+
memBuf.UpdateFlags(key, kv.SetPrewriteOnly)
688+
}
689+
685690
if c.mutations.Len() == 0 {
686691
return nil
687692
}

0 commit comments

Comments
 (0)