使用rocksdb :: Iterator和Column Family不起作用

时间:2016-08-17 08:16:46

标签: c++ iterator key-value-store column-family rocksdb

我有以下代码:

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应考虑列系列,但我找不到任何文档。

1 个答案:

答案 0 :(得分:1)

确实缺少的API调用是:

rocksdb::Iterator* iterator = db->NewIterator(readOptions, cfHandle);