Skip to content

Commit

Permalink
mvcc: allow large concurrent reads under light write workload
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang90 committed Feb 8, 2018
1 parent fe94f8f commit e50aacb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/mvcc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ func (b *backend) run() {
b.batchTx.CommitAndStop()
return
}
b.batchTx.Commit()
b.batchTx.Lock()
pending := b.batchTx.pending
b.batchTx.Unlock()
if pending != 0 {
b.batchTx.Commit()
}
t.Reset(b.batchInterval)
}
}
Expand Down Expand Up @@ -302,11 +307,7 @@ func (b *backend) defrag() error {
b.mu.Lock()
defer b.mu.Unlock()

// block concurrent read requests while resetting tx
b.readTx.mu.Lock()
defer b.readTx.mu.Unlock()

b.batchTx.unsafeCommit(true)
b.batchTx.commit(true)
b.batchTx.tx = nil

tmpdb, err := bolt.Open(b.db.Path()+".tmp", 0600, boltOpenOptions)
Expand Down
1 change: 1 addition & 0 deletions internal/mvcc/backend/batch_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func unsafeRange(c *bolt.Cursor, key, endKey []byte, limit int64) (keys [][]byte
isMatch = func(b []byte) bool { return bytes.Equal(b, key) }
limit = 1
}

for ck, cv := c.Seek(key); ck != nil && isMatch(ck); ck, cv = c.Next() {
vs = append(vs, cv)
keys = append(keys, ck)
Expand Down

0 comments on commit e50aacb

Please sign in to comment.