【问题标题】:Using rocksdb::Iterator and Column Family is not working使用rocksdb::Iterator 和Column Family 不起作用
【发布时间】:2016-08-17 08:16:46
【问题描述】:

我有以下代码:

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

【问题讨论】:

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


    【解决方案1】:

    确实缺少的 API 调用是:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 2017-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多