提交 4276c2ce 编写于 作者: 小地鼠家的小松鼠's avatar 小地鼠家的小松鼠 提交者: heyuchen

fix: fix db is not nullptr when release_db (#594)

上级 a83343d4
......@@ -1813,7 +1813,16 @@ private:
if (remove_checkpoint && !::dsn::utils::filesystem::remove_path(checkpoint_dir)) {
derror_replica("remove checkpoint directory {} failed", checkpoint_dir);
}
release_db(snapshot_db, handles_opened);
if (snapshot_db) {
for (auto handle : handles_opened) {
if (handle) {
snapshot_db->DestroyColumnFamilyHandle(handle);
handle = nullptr;
}
}
delete snapshot_db;
snapshot_db = nullptr;
}
};
// Because of RocksDB's restriction, we have to to open default column family even though
......@@ -2716,19 +2725,16 @@ void pegasus_server_impl::set_partition_version(int32_t partition_version)
return ::dsn::ERR_OK;
}
void pegasus_server_impl::release_db() { release_db(_db, {_data_cf, _meta_cf}); }
void pegasus_server_impl::release_db(rocksdb::DB *db,
const std::vector<rocksdb::ColumnFamilyHandle *> &handles)
void pegasus_server_impl::release_db()
{
if (db) {
for (auto handle : handles) {
dassert_replica(handle != nullptr, "");
db->DestroyColumnFamilyHandle(handle);
handle = nullptr;
}
delete db;
db = nullptr;
if (_db) {
dassert_replica(_data_cf != nullptr && _meta_cf != nullptr, "");
_db->DestroyColumnFamilyHandle(_data_cf);
_data_cf = nullptr;
_db->DestroyColumnFamilyHandle(_meta_cf);
_meta_cf = nullptr;
delete _db;
_db = nullptr;
}
}
......
......@@ -168,6 +168,7 @@ private:
FRIEND_TEST(pegasus_server_impl_test, default_data_version);
FRIEND_TEST(pegasus_server_impl_test, test_open_db_with_latest_options);
FRIEND_TEST(pegasus_server_impl_test, test_open_db_with_app_envs);
FRIEND_TEST(pegasus_server_impl_test, test_stop_db_twice);
friend class pegasus_manual_compact_service;
friend class pegasus_write_service;
......@@ -314,7 +315,6 @@ private:
check_column_families(const std::string &path, bool *missing_meta_cf, bool *miss_data_cf);
void release_db();
void release_db(rocksdb::DB *db, const std::vector<rocksdb::ColumnFamilyHandle *> &handles);
::dsn::error_code flush_all_family_columns(bool wait);
......
......@@ -99,5 +99,21 @@ TEST_F(pegasus_server_impl_test, test_open_db_with_app_envs)
ASSERT_EQ(ROCKSDB_ENV_USAGE_SCENARIO_BULK_LOAD, _server->_usage_scenario);
}
TEST_F(pegasus_server_impl_test, test_stop_db_twice)
{
start();
ASSERT_TRUE(_server->_is_open);
ASSERT_TRUE(_server->_db != nullptr);
_server->stop(false);
ASSERT_FALSE(_server->_is_open);
ASSERT_TRUE(_server->_db == nullptr);
// stop again
_server->stop(false);
ASSERT_FALSE(_server->_is_open);
ASSERT_TRUE(_server->_db == nullptr);
}
} // namespace server
} // namespace pegasus
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册