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.
Indeed the missing API call was:
rocksdb::Iterator* iterator = db->NewIterator(readOptions, cfHandle);