Skip to content

Commit

Permalink
peapod: Do not commit idle batch transaction
Browse files Browse the repository at this point in the history
Previously, Peapod collects write batch within 10ms and then flushes
changes to physical drive. In the absence of operations during the
lifetime of the current batch transaction, the latter was committed in
any case and a new one was begun. This behavior could lead to idle
commit-begin ops.

Now each state-changing batch is marked. The flush cycle commits only
non-idle batches: if current batch is idle, Peapod keeps related
transaction for the time interval. When Peapod is closed, transaction
related to idle batch is rolled back.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Jul 31, 2023
1 parent a7318e7 commit af12bc4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/local_object_storage/peapod/peapod.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type batch struct {

tx *bbolt.Tx

nonIdle bool

commitErr error
chCommitted chan struct{}

Expand Down Expand Up @@ -97,6 +99,14 @@ func (x *Peapod) flushLoop() {
func (x *Peapod) flushCurrentBatch(beginNew bool) {
x.currentBatchMtx.Lock()

if !x.currentBatch.nonIdle {
if !beginNew {
_ = x.currentBatch.tx.Rollback()
}
x.currentBatchMtx.Unlock()
return
}

err := x.currentBatch.tx.Commit()
if err != nil {
err = fmt.Errorf("commit BoltDB batch transaction: %w", err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/local_object_storage/peapod/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func (x *Peapod) Put(ctx context.Context, addr oid.Address, data []byte) error {
return fmt.Errorf("put object into BoltDB bucket for container: %w", err)
}

currentBatch.nonIdle = true

x.currentBatchMtx.RUnlock()

select {
Expand Down

0 comments on commit af12bc4

Please sign in to comment.