Skip to content

Commit

Permalink
Merge pull request #12916 from wpedrak/pass-mlock-during-defrag
Browse files Browse the repository at this point in the history
server: reapply `Mlock` flag after defrag
  • Loading branch information
gyuho authored May 3, 2021
2 parents c46e96d + 6623c00 commit eb128d2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions server/mvcc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type backend struct {
commits int64
// openReadTxN is the number of currently open read transactions in the backend
openReadTxN int64
// mlock prevents backend database file to be swapped
mlock bool

mu sync.RWMutex
db *bolt.DB
Expand Down Expand Up @@ -171,6 +173,7 @@ func newBackend(bcfg BackendConfig) *backend {

batchInterval: bcfg.BatchInterval,
batchLimit: bcfg.BatchLimit,
mlock: bcfg.Mlock,

readTx: &readTx{
baseReadTx: baseReadTx{
Expand Down Expand Up @@ -381,7 +384,7 @@ func (b *backend) defrag() error {
if boltOpenOptions != nil {
options = *boltOpenOptions
}
options.OpenFile = func(path string, i int, mode os.FileMode) (file *os.File, err error) {
options.OpenFile = func(_ string, _ int, _ os.FileMode) (file *os.File, err error) {
return temp, nil
}
// Don't load tmp db into memory regardless of opening options
Expand Down Expand Up @@ -428,7 +431,13 @@ func (b *backend) defrag() error {
b.lg.Fatal("failed to rename tmp database", zap.Error(err))
}

b.db, err = bolt.Open(dbp, 0600, boltOpenOptions)
defragmentedBoltOptions := bolt.Options{}
if boltOpenOptions != nil {
defragmentedBoltOptions = *boltOpenOptions
}
defragmentedBoltOptions.Mlock = b.mlock

b.db, err = bolt.Open(dbp, 0600, &defragmentedBoltOptions)
if err != nil {
b.lg.Fatal("failed to open database", zap.String("path", dbp), zap.Error(err))
}
Expand Down

0 comments on commit eb128d2

Please sign in to comment.