mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
parent
3a6235ea03
commit
29e1cf648b
12
bitcask.go
12
bitcask.go
@ -125,6 +125,11 @@ func (b *Bitcask) close() error {
|
|||||||
func (b *Bitcask) Sync() error {
|
func (b *Bitcask) Sync() error {
|
||||||
b.mu.RLock()
|
b.mu.RLock()
|
||||||
defer b.mu.RUnlock()
|
defer b.mu.RUnlock()
|
||||||
|
|
||||||
|
if err := b.saveMetadata(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return b.curr.Sync()
|
return b.curr.Sync()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,12 +206,7 @@ func (b *Bitcask) Put(key, value []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// in case of successful `put`, IndexUpToDate will be always be false
|
// in case of successful `put`, IndexUpToDate will be always be false
|
||||||
if b.metadata.IndexUpToDate {
|
b.metadata.IndexUpToDate = false
|
||||||
b.metadata.IndexUpToDate = false
|
|
||||||
if err := b.saveMetadata(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if oldItem, found := b.trie.Search(key); found {
|
if oldItem, found := b.trie.Search(key); found {
|
||||||
b.metadata.ReclaimableSpace += oldItem.(internal.Item).Size
|
b.metadata.ReclaimableSpace += oldItem.(internal.Item).Size
|
||||||
|
@ -633,6 +633,11 @@ func TestSync(t *testing.T) {
|
|||||||
value := []byte("foobar")
|
value := []byte("foobar")
|
||||||
err = db.Put(key, value)
|
err = db.Put(key, value)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Put", func(t *testing.T) {
|
||||||
|
err = db.Put([]byte("hello"), []byte("world"))
|
||||||
|
assert.NoError(err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMaxKeySize(t *testing.T) {
|
func TestMaxKeySize(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user