Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend: set seq flag for each bucket buffer #12568

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/mvcc/backend/batch_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func newBatchTxBuffered(backend *backend) *batchTxBuffered {
batchTx: batchTx{backend: backend},
buf: txWriteBuffer{
txBuffer: txBuffer{make(map[string]*bucketBuffer)},
seq: true,
seq: make(map[string]bool),
},
}
tx.Commit()
Expand Down
19 changes: 16 additions & 3 deletions server/mvcc/backend/tx_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ func (txb *txBuffer) reset() {
// txWriteBuffer buffers writes of pending updates that have not yet committed.
type txWriteBuffer struct {
txBuffer
seq bool
seq map[string]bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please comment about semantic of this field (what's the key and what the value represents).

}


func (txw *txWriteBuffer) put(bucket, k, v []byte) {
txw.seq = false
txw.seq[string(bucket)] = false
txw.putSeq(bucket, k, v)
}

Expand All @@ -54,6 +55,18 @@ func (txw *txWriteBuffer) putSeq(bucket, k, v []byte) {
b.add(k, v)
}

func (txw *txWriteBuffer) reset() {
txw.txBuffer.reset()
for k := range txw.seq {
v, ok := txw.buckets[k]
if !ok {
delete(txw.seq, k)
} else if v.used == 0 {
txw.seq[k] = true
}
}
}

func (txw *txWriteBuffer) writeback(txr *txReadBuffer) {
for k, wb := range txw.buckets {
rb, ok := txr.buckets[k]
Expand All @@ -62,7 +75,7 @@ func (txw *txWriteBuffer) writeback(txr *txReadBuffer) {
txr.buckets[k] = wb
continue
}
if !txw.seq && wb.used > 1 {
if seq, ok := txw.seq[k]; ok && !seq && wb.used > 1 {
// assume no duplicate keys
sort.Sort(wb)
}
Expand Down