facebook / facebook/rocksdb

Unable to get all records while traversing database

Open
#10,508 7 comments 0 reactions 0 assignees View on GitHub
question up-for-grabs
Dominant language
C++
Stars
32.1k
Forks
6.9k
Avg merge
32m
Merged PRs (30d)
1

Description

> Note: Please use Issues only for bug reports. For questions, discussions, feature requests, etc. post to dev group: https://groups.google.com/forum/#!forum/rocksdb or https://www.facebook.com/groups/rocksdb.dev

### Expected behavior
We have written millions of records into the database, and these records are prefixed with 'xxx' or 'yyy', such as: 'xxx0', 'xxx1', 'yyy0', 'yyy1', etc. In addition, we have customized the comparator to ensure that the records prefixed with 'xxx' are ranked before 'yyy'. In the case of the same prefix, the smaller number is ranked first.

When we iterate in the following way, we should be able to get all the records prefixed with 'xxx':

```
rocksdb::Iterator* iter = db->NewIterator(rocksdb::ReadOptions());
for (iter->Seek("xxx"); iter->Valid() && iter->key().starts_with("xxx"); iter->Next()) {
// print key and value
}
```
### Actual behavior
In fact, the records between 'xxx100' and 'xxx1001' are missing from the result of the traversal. But if we specify access to 'xxx105' in the following way, we can get the corresponding value:
```
std::string value;
rocksdb::Status s = db->Get(rocksdb::ReadOptions(), "xxx105", &value);
```
### Steps to reproduce the behavior
1. Define the comparator, and write the data starting with prefix, we wrote about four million records.
2. Traverse the database by seeking prefix.

The above anomalies are occasional.

In addition, is there an easy way to replace the comparator in the ldb tool. Currently, I cannot directly view the database written by myself using ldb. The error message I get is as follows: **Failed: Invalid argument: leveldb.BytewiseComparator: does not match existing comparator**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.