mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
Fix a race condition around .Close() and .Sync()
This commit is contained in:
parent
e900e2fa77
commit
720f03c6c2
@ -87,7 +87,10 @@ func (b *Bitcask) Stats() (stats Stats, err error) {
|
|||||||
// Close() as this is the only way to cleanup the lock held by the open
|
// Close() as this is the only way to cleanup the lock held by the open
|
||||||
// database.
|
// database.
|
||||||
func (b *Bitcask) Close() error {
|
func (b *Bitcask) Close() error {
|
||||||
|
b.mu.RLock()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
b.mu.RUnlock()
|
||||||
b.Flock.Unlock()
|
b.Flock.Unlock()
|
||||||
os.Remove(b.Flock.Path())
|
os.Remove(b.Flock.Path())
|
||||||
}()
|
}()
|
||||||
@ -107,6 +110,8 @@ func (b *Bitcask) Close() error {
|
|||||||
|
|
||||||
// Sync flushes all buffers to disk ensuring all data is written
|
// Sync flushes all buffers to disk ensuring all data is written
|
||||||
func (b *Bitcask) Sync() error {
|
func (b *Bitcask) Sync() error {
|
||||||
|
b.mu.RLock()
|
||||||
|
defer b.mu.RUnlock()
|
||||||
return b.curr.Sync()
|
return b.curr.Sync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user