rosedblabs / rosedb

Lightweight, fast and reliable key/value storage engine based on Bitcask.

Home Page:https://rosedblabs.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: Is it a bug in *Batch.Put?

Orlion opened this issue · comments

We have the following code:

var key = []byte("key")
var value1 = []byte("v1")
var value2 = []byte("v2")
db.Put(key, value1)
duration, _ := db.TTL(key)
fmt.Printf("before expire: %d\n", duration)

batch := db.NewBatch(BatchOptions{})
err = batch.Expire(key, time.Second*10)
err = batch.Put(key, value2)
err = batch.Commit()
duration, _ = db.TTL(key)
fmt.Printf("after expire: %d\n", duration)

Its output is

before expire: -1
after expire: -1

We expected to add an expiration time of 10 seconds to the key through batch.Expire(key, time.Second*10), but batch.Put(key, value2) removed the expiration time incorrectly.

I found this line in the code:

rosedb/batch.go

Line 131 in a89ea82

record.Type, record.Expire = LogRecordNormal, 0

So, is it a bug?

First, you set the expiration time of the key in batch,
The key is then immediately set to a new value, so any previous information will be overwritten,
I think this is correct.

First, you set the expiration time of the key in batch, The key is then immediately set to a new value, so any previous information will be overwritten, I think this is correct.

I got it.