facebook / facebook/rocksdb

db->Get() can't find some keys, but Iterator can list them.

Open
#5,558 16 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
32.1k
Forks
6.9k
Avg merge
32m
Merged PRs (30d)
1

Description

We are using rocksdb in ceph to store monitor data, but we found there is a strange state in rocksdb in our cluster: we can get some keys in Iterator but rocksdb return NoEntry when we call db->Get() for these keys.

### Expected behavior
We can get values by db->Get() with the key get from iterator.

### Actual behavior
db->Get() return NoEnt with some keys get from iterator.

### Steps to reproduce the behavior
There is a simple test file to access my db file to reproduce this scenario:
```
#include
#include
#include

#include "rocksdb/db.h"
#include "rocksdb/slice.h"
#include "rocksdb/options.h"

using namespace rocksdb;

std::string kDBPath = "/data/ceph0705/node-2/ceph/ceph/mon/mon/ceph-node-2/store.db/";

int main() {
DB* db;
Options options;
// Optimize RocksDB. This is the easiest way to get RocksDB to perform well
options.IncreaseParallelism();

// open DB
Status s = DB::Open(options, kDBPath, &db);
assert(s.ok());

std::string value;
std::string prefix("auth");
std::string key("10851");
std::string combined_key = prefix;
combined_key.push_back(0);
combined_key.append(key);
Status st = db->Get(rocksdb::ReadOptions(), db->DefaultColumnFamily(), rocksdb::Slice(combined_key), &value);
fprintf(stdout, "Result of Get() with key(auth10851) is: %d\n", st.code());

rocksdb::Iterator* it = db->NewIterator(rocksdb::ReadOptions());
for (it->SeekToFirst(); it->Valid(); it->Next()) {
if (combined_key == it->key().ToString())
std::cout << "But we can find this key in iterator: " << it->key().ToString() << std::endl;
}
assert(it->status().ok()); // Check for any errors found during the scan
delete it;

delete db;
return 0;
}
```

result as below:
```
[root@atest-guest examples]# ./simple_example
Result of Get() with key(auth10851) is: 1
But we can find this key in iterator: auth10851
[root@atest-guest examples]#
```

In addition, we can get the value in iterator by iter->value(), but that's not printable, So I did not show it in my example.

I found the all releted keys as below, they are in a range:
```
auth 10851
auth 10852
auth 10853
auth 10854
auth 10855
auth 10856
auth 10857
auth 10858
```

db file attached:
[store.db.tar.gz](https://github.com/facebook/rocksdb/files/3377413/store.db.tar.gz)

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.