mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
[ADDED] new tests for TTL expiration race condition, see #216 [REMOVED] removes cleanup / automatic expiration from get() function to resolve #216 Reviewed-on: https://git.mills.io/prologic/bitcask/pulls/227 Co-authored-by: Tai Groot <tai@taigrr.com> Co-committed-by: Tai Groot <tai@taigrr.com>
This commit is contained in:
parent
c4a7ad7a7f
commit
92535e654b
@ -386,8 +386,7 @@ func (b *Bitcask) get(key []byte) (internal.Entry, error) {
|
|||||||
if !found {
|
if !found {
|
||||||
return internal.Entry{}, ErrKeyNotFound
|
return internal.Entry{}, ErrKeyNotFound
|
||||||
}
|
}
|
||||||
if expired := b.isExpired(key); expired {
|
if b.isExpired(key) {
|
||||||
_ = b.delete(key) // we don't care if it doesnt succeed
|
|
||||||
return internal.Entry{}, ErrKeyExpired
|
return internal.Entry{}, ErrKeyExpired
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1750,6 +1750,43 @@ func TestLockingAfterMerge(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetExpiredInsideFold(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
testdir, err := ioutil.TempDir("", "bitcask")
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
db, err := Open(testdir)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer db.Close()
|
||||||
|
// Add a node to the tree that won't expire
|
||||||
|
db.Put([]byte("static"), []byte("static"))
|
||||||
|
// Add a node that expires almost immediately to the tree
|
||||||
|
db.PutWithTTL([]byte("shortLived"), []byte("shortLived"), 1*time.Millisecond)
|
||||||
|
db.Put([]byte("skipped"), []byte("skipped"))
|
||||||
|
db.Put([]byte("static2"), []byte("static2"))
|
||||||
|
time.Sleep(2 * time.Millisecond)
|
||||||
|
var arr []string
|
||||||
|
_ = db.Fold(func(key []byte) error {
|
||||||
|
val, err := db.Get(key)
|
||||||
|
switch string(key) {
|
||||||
|
case "skipped":
|
||||||
|
fallthrough
|
||||||
|
case "static2":
|
||||||
|
fallthrough
|
||||||
|
case "static":
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.Equal(string(val), string(key))
|
||||||
|
case "shortLived":
|
||||||
|
assert.Error(err)
|
||||||
|
}
|
||||||
|
arr = append(arr, string(val))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
assert.Contains(arr, "skipped")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
type benchmarkTestCase struct {
|
type benchmarkTestCase struct {
|
||||||
name string
|
name string
|
||||||
size int
|
size int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user