Skip to content

Commit

Permalink
backend: set seq flag for each bucket buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mlmhl authored and ptabor committed May 25, 2021
1 parent dd22bd7 commit 261f8b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/mvcc/backend/batch_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,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 @@ -39,11 +39,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
}


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

Expand All @@ -56,6 +57,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 @@ -64,7 +77,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

0 comments on commit 261f8b1

Please sign in to comment.