0

I have the following piece of code:

rocksdb::DBWithTTL* db = ...
rocksdb::WriteOptions writeOptions;
rocksdb::ColumnFamilyHandle cfHandle = ...

std::string keyPrefix = "prefix";
std::string key = keyPrefix + "_key";
std::string value = "value";
rocksdb::Status s = db->Put(writeOptions, cfHandle, key, value);

rocksdb::ReadOptions readOptions;
readOptions.prefix_same_as_start;
readOptions.snapshot = db->GetSnapshot();
rocksdb::Iterator* iterator = db->NewIterator(readOptions);

rocksdb::Sliced start = rocksdb::Slice(keyPrefix);
for (iterator->Seek(start); iterator->Valid(); iterator->Next()) {
  printf("hello");
}

The printf is never hit.

However, if I change the Put line to:

rocksdb::Status s = db->Put(writeOptions, key, value);

Meaning, removing the column family handle, I'm getting the line printed fine.

I'm guessing the iterator API should take the column family into account, but I couldn't find any documentation.

4

1 回答 1

1

事实上,缺少的 API 调用是:

rocksdb::Iterator* iterator = db->NewIterator(readOptions, cfHandle);
于 2016-08-17T10:21:06.620 回答