我有以下代码:
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");
}
printf
永远不会被点击。但是,如果将
Put
行更改为:rocksdb::Status s = db->Put(writeOptions, key, value);
意思是,删除
column family handle
,我将行打印得很好。我猜迭代器API应该考虑到列族,但是我找不到任何文档。
最佳答案
实际上,缺少的API调用是:
rocksdb::Iterator* iterator = db->NewIterator(readOptions, cfHandle);