cockroachdb / pebble

RocksDB/LevelDB inspired key-value database in Go
BSD 3-Clause "New" or "Revised" License
4.76k stars 441 forks source link

err: Comparer.Split required for range key operations #2459

Open ericjing83 opened 1 year ago

ericjing83 commented 1 year ago

Dear sir,

I have a problem with batch.RangeKeySet. It shows an error: err: Comparer.Split required for range key operations

func pebbleDBBatch() error { var err error db, err = pebble.Open("./demo", o) if err != nil { fmt.Println(err) return err } batch := db.NewBatch() for i := 0; i < 10; i++ { err = batch.RangeKeySet([]byte("a"), []byte("z"), nil, []byte("myvalue"), nil) if err != nil { fmt.Println("i=", i) fmt.Println("RangeKeySet err:", err) return err } } err = batch.Commit(nil) if err != nil { fmt.Println(err) return err } db.Flush() //it := db.NewIter(&pebble.IterOptions{}) res, closer, err := db.Get([]byte("a")) if err != nil { fmt.Println(err) return err } fmt.Println("res=", string(res)) err = closer.Close() if err != nil { fmt.Println(err) return err } fmt.Println("closer success") return nil } func main() { pebbleDBBatch() } I don't know how to use Comparer.Split. Could you help me? Jira issue: PEBBLE-196
jbowens commented 1 year ago

Hi, please see this documentation on the Split type:

https://github.com/cockroachdb/pebble/blob/d54c3292241c3b670c8bbc9e140e01532ec42b88/internal/base/comparer.go#L86-L117

Note that range keys are an advanced feature, and so I don't recommend using them unless you have a good understanding of what they are and their limitations.

ericjing83 commented 1 year ago

So, before learning the details, what's the benifit of using range key? I've look through the code, and only found RangeKeySet, Is there a RangeKeyGet like function? How to get the key/value back after set? Thanks.

nicktrav commented 1 year ago

So, before learning the details, what's the benifit of using range key? I've look through the code, and only found RangeKeySet, Is there a RangeKeyGet like function? How to get the key/value back after set?

Take a look at the RFC for range keys, which has a good overview.