Closed konghaiya closed 2 years ago
Can you share a unit test of what you are trying to do causing this error?
#include <mutex>
#include <string>
#include <thread>
#include "rocksdb/compaction_filter.h"
#include "rocksdb/convenience.h"
#include "rocksdb/db.h"
#include "rocksdb/utilities/transaction_db.h"
#include "rocksdb/utilities/write_batch_with_index.h"
class KVStore final {
public:
void Init(); //Called at system startup
void UnInit(); //Called when the system is shut down
private:
rocksdb::BlockBasedTableOptions bbto_;
rocksdb::TransactionDB *rdb;
};
void KVStore::Init() {
rocksdb::TransactionDBOptions txn_db_options;
std::vector<std::string> cf_names;
std::vector<rocksdb::ColumnFamilyDescriptor> cf_descr;
std::vector<rocksdb::ColumnFamilyHandle *> cf_handles;
rocksdb::Options options;
options.create_if_missing = true;
bbto_.no_block_cache = false;
bbto_.cache_index_and_filter_blocks = true;
bbto_.block_cache = rocksdb::NewLRUCache(stonedb_sysvar_index_cache_size << 20);
options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(bbto_));
rocksdb::DBOptions db_option(options);
auto rocksdb_datadir = kv_data_dir / ".index";
int max_compact_threads = std::thread::hardware_concurrency() / 4;
max_compact_threads = (max_compact_threads > 1) ? max_compact_threads : 1;
db_option.max_background_compactions = max_compact_threads;
db_option.max_subcompactions = max_compact_threads;
db_option.env->SetBackgroundThreads(max_compact_threads, rocksdb::Env::Priority::LOW);
db_option.statistics = rocksdb::CreateDBStatistics();
// get column family names from manifest file
rocksdb::Status status = rocksdb::DB::ListColumnFamilies(db_option, rocksdb_datadir, &cf_names);
if (!status.ok() &&
((status.subcode() == rocksdb::Status::kNone) || (status.subcode() == rocksdb::Status::kPathNotFound))) {
STONEDB_LOG(LogCtl_Level::INFO, "First init rocksdb, create default column family");
cf_names.push_back(DEFAULT_CF_NAME);
}
rocksdb::ColumnFamilyOptions rs_cf_option(options);
rocksdb::ColumnFamilyOptions index_cf_option(options);
// Disable compactions to prevent compaction start before compaction filter is
// ready.
index_cf_option.disable_auto_compactions = true;
index_cf_option.compaction_filter_factory.reset(new IndexCompactFilterFactory);
for (auto &cfn : cf_names) {
if (IsRowStoreCF(cfn))
cf_descr.emplace_back(cfn, rs_cf_option);
else
cf_descr.emplace_back(cfn, index_cf_option);
}
// open db, get column family handles
status = rocksdb::TransactionDB::Open(options, txn_db_options, rocksdb_datadir, cf_descr, &cf_handles, &rdb);
if (!status.ok()) {
throw common::Exception("Error opening rocks instance. status msg: " + status.ToString());
}
cf_manager.init(cf_handles);
status = rdb->EnableAutoCompaction(cf_handles);
// Enable compaction, things needed for compaction filter are finished
// initializing
status = rdb->EnableAutoCompaction(cf_handles);
if (!status.ok()) {
throw common::Exception("RocksDB: Failed to enable compaction.");
}
}
void KVStore::UnInit() {
// Stop all rocksdb background work
rocksdb::CancelAllBackgroundWork(rdb->GetBaseDB(), true);
if (bbto_.block_cache) bbto_.block_cache->EraseUnRefEntries();
delete rdb;
rdb = nullptr;
}
Our actual calling process is like the above code, which calls "init()" when the system is started and "uninit()" when the system is shut down
Is this by any chance similar to #7183?
It's a similar situation. Do you conclude that this situation can be ignored?
Right, that's my understanding. You can also build the test with asan and see what the result is.
Well, thank you very much.
Expected behavior
Actual behavior
problem 1
problem 2
Steps to reproduce the behavior
We are using version 6.4.6