使用 rocksdb::Iterator 和列族不起作用
Using rocksdb::Iterator and Column Family is not working
我有如下一段代码:
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);
我有如下一段代码:
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);