[CP] [CP] Remove multi logical tenant files

This commit is contained in:
JiahuaChen
2022-08-12 17:10:46 +08:00
committed by wangzelin.wzl
parent 331db3f523
commit c6ce32929d
4 changed files with 28 additions and 32 deletions

View File

@ -63,7 +63,7 @@ int ObTenantFileMgr::alloc_file(const bool is_sys_table, ObStorageFileHandle& fi
LOG_WARN("ObTenantFileMgr has not been inited", K(ret)); LOG_WARN("ObTenantFileMgr has not been inited", K(ret));
} else { } else {
ObTenantFileValue* value = nullptr; ObTenantFileValue* value = nullptr;
if (OB_FAIL(choose_tenant_file(is_sys_table, true /*need create new file*/, tenant_file_map_, value))) { if (OB_FAIL(choose_tenant_file(true /*need create new file*/, tenant_file_map_, value))) {
LOG_WARN("fail to choose tenant file", K(ret)); LOG_WARN("fail to choose tenant file", K(ret));
} }
@ -72,8 +72,7 @@ int ObTenantFileMgr::alloc_file(const bool is_sys_table, ObStorageFileHandle& fi
const int64_t create_file_cnt = 1L; const int64_t create_file_cnt = 1L;
if (OB_FAIL(create_new_tenant_file(write_slog, is_sys_table, create_file_cnt))) { if (OB_FAIL(create_new_tenant_file(write_slog, is_sys_table, create_file_cnt))) {
LOG_WARN("fail to create new files", K(ret)); LOG_WARN("fail to create new files", K(ret));
} else if (OB_FAIL(choose_tenant_file( } else if (OB_FAIL(choose_tenant_file(false /*do not need create new file*/, tenant_file_map_, value))) {
is_sys_table, false /*do not need create new file*/, tenant_file_map_, value))) {
LOG_WARN("fail to choose tenant file", K(ret)); LOG_WARN("fail to choose tenant file", K(ret));
} else if (nullptr == value) { } else if (nullptr == value) {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
@ -186,24 +185,23 @@ int ObTenantFileMgr::alloc_exist_file(const ObTenantFileInfo& file_info, const b
} }
int ObTenantFileMgr::choose_tenant_file( int ObTenantFileMgr::choose_tenant_file(
const bool is_sys_table, const bool need_create_file, TENANT_FILE_MAP& tenant_file_map, ObTenantFileValue*& value) const bool need_create_file, TENANT_FILE_MAP& tenant_file_map, ObTenantFileValue*& value)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
value = nullptr; value = nullptr;
if (OB_UNLIKELY(!is_inited_)) { if (OB_UNLIKELY(!is_inited_)) {
ret = OB_NOT_INIT; ret = OB_NOT_INIT;
LOG_WARN("ObTenantFileMgr has not been inited", K(ret)); LOG_WARN("ObTenantFileMgr has not been inited", K(ret));
} else if (!is_sys_table && tenant_file_map.size() < TENANT_MIN_FILE_CNT && need_create_file) { } else if (0 == tenant_file_map.size() && need_create_file) {
// alloc one more file // alloc one more file
} else { } else {
for (TENANT_FILE_MAP::const_iterator iter = tenant_file_map.begin(); OB_SUCC(ret) && iter != tenant_file_map.end(); for (TENANT_FILE_MAP::const_iterator iter = tenant_file_map.begin(); OB_SUCC(ret) && iter != tenant_file_map.end();
++iter) { ++iter) {
ObTenantFileValue* tmp_value = iter->second; ObTenantFileValue* tmp_value = iter->second;
if (tmp_value->file_info_.tenant_file_super_block_.is_sys_table_file_ != is_sys_table) { if (OB_UNLIKELY(!tmp_value->is_owner_)) {
// do nothing ret = OB_ERR_UNEXPECTED;
} else if ((tmp_value->file_info_.get_pg_cnt() < ObTenantFileValue::MAX_REF_CNT_PER_FILE || is_sys_table) && LOG_WARN("file value is not owner", K(ret), K(*tmp_value));
TENANT_FILE_NORMAL == tmp_value->file_info_.tenant_file_super_block_.status_ && } else if (TENANT_FILE_NORMAL == tmp_value->file_info_.tenant_file_super_block_.status_) {
tmp_value->storage_file_.file_->get_mark_and_sweep_status()) {
if (nullptr == value) { if (nullptr == value) {
value = iter->second; value = iter->second;
} else { } else {
@ -215,13 +213,6 @@ int ObTenantFileMgr::choose_tenant_file(
return ret; return ret;
} }
int ObTenantFileMgr::generate_unique_file_id(int64_t& file_id)
{
int ret = OB_SUCCESS;
file_id = ObTimeUtility::current_time();
return ret;
}
int ObTenantFileMgr::create_new_tenant_file(const bool write_slog, const bool create_sys_table, const int64_t file_cnt) int ObTenantFileMgr::create_new_tenant_file(const bool write_slog, const bool create_sys_table, const int64_t file_cnt)
{ {
int ret = OB_SUCCESS; int ret = OB_SUCCESS;
@ -244,10 +235,8 @@ int ObTenantFileMgr::create_new_tenant_file(const bool write_slog, const bool cr
for (int64_t i = 0; OB_SUCC(ret) && i < file_cnt; ++i) { for (int64_t i = 0; OB_SUCC(ret) && i < file_cnt; ++i) {
void* buf = nullptr; void* buf = nullptr;
ObTenantFileValue* value = nullptr; ObTenantFileValue* value = nullptr;
int64_t file_id = -1; const int64_t file_id = ObTimeUtility::current_time();
if (OB_FAIL(generate_unique_file_id(file_id))) { if (OB_ISNULL(buf = allocator_->alloc(sizeof(ObTenantFileValue)))) {
LOG_WARN("fail to generate unique file id", K(file_id));
} else if (OB_ISNULL(buf = allocator_->alloc(sizeof(ObTenantFileValue)))) {
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to allocate memory for tenant file value", K(ret)); LOG_WARN("fail to allocate memory for tenant file value", K(ret));
} else { } else {

View File

@ -21,7 +21,6 @@
namespace oceanbase { namespace oceanbase {
namespace storage { namespace storage {
class ObTenantFileMgr final { class ObTenantFileMgr final {
public: public:
ObTenantFileMgr(); ObTenantFileMgr();
@ -64,11 +63,9 @@ public:
private: private:
static const int64_t TENANT_MAX_FILE_CNT = 1000; static const int64_t TENANT_MAX_FILE_CNT = 1000;
static const int64_t TENANT_MIN_FILE_CNT = 10;
typedef common::hash::ObHashMap<ObTenantFileKey, ObTenantFileValue*> TENANT_FILE_MAP; typedef common::hash::ObHashMap<ObTenantFileKey, ObTenantFileValue*> TENANT_FILE_MAP;
int create_new_tenant_file(const bool write_slog, const bool create_sys_table, const int64_t file_cnt); int create_new_tenant_file(const bool write_slog, const bool create_sys_table, const int64_t file_cnt);
int choose_tenant_file(const bool is_sys_table, const bool need_create_file, TENANT_FILE_MAP& tenant_file_map, int choose_tenant_file(const bool need_create_file, TENANT_FILE_MAP& tenant_file_map, ObTenantFileValue*& value);
ObTenantFileValue*& value);
int alloc_exist_file(const ObTenantFileInfo& tenant_file_info, const bool write_slog, const bool open_file, int alloc_exist_file(const ObTenantFileInfo& tenant_file_info, const bool write_slog, const bool open_file,
const bool is_owner, const bool from_svr_ckpt); const bool is_owner, const bool from_svr_ckpt);
int write_update_slog(const ObTenantFileKey& tenant_key, const bool in_slog_trans, int write_update_slog(const ObTenantFileKey& tenant_key, const bool in_slog_trans,
@ -77,7 +74,6 @@ private:
int write_update_file_info_slog(const ObTenantFileKey& file_key, const ObTenantFileSuperBlock& super_block); int write_update_file_info_slog(const ObTenantFileKey& file_key, const ObTenantFileSuperBlock& super_block);
int update_tenant_file_super_block_in_map( int update_tenant_file_super_block_in_map(
const ObTenantFileKey& tenant_key, const ObTenantFileSuperBlock& tenant_file_super_block); const ObTenantFileKey& tenant_key, const ObTenantFileSuperBlock& tenant_file_super_block);
int generate_unique_file_id(int64_t& file_id);
int update_tenant_file_meta_blocks_impl( int update_tenant_file_meta_blocks_impl(
const ObTenantFileKey& file_key, const common::ObIArray<blocksstable::MacroBlockId>& meta_block_list); const ObTenantFileKey& file_key, const common::ObIArray<blocksstable::MacroBlockId>& meta_block_list);

View File

@ -13,6 +13,7 @@
#define USING_LOG_PREFIX STORAGE #define USING_LOG_PREFIX STORAGE
#include "ob_tenant_file_super_block_checkpoint_writer.h" #include "ob_tenant_file_super_block_checkpoint_writer.h"
#include "share/schema/ob_multi_version_schema_service.h"
#include "storage/ob_tenant_file_mgr.h" #include "storage/ob_tenant_file_mgr.h"
using namespace oceanbase::common; using namespace oceanbase::common;
@ -98,11 +99,21 @@ int ObTenantFileSuperBlockCheckpointWriter::write_checkpoint(blocksstable::ObSto
LOG_INFO("get all tenant file infos", K(tenant_file_infos)); LOG_INFO("get all tenant file infos", K(tenant_file_infos));
ObTenantFileSuperBlockItem item; ObTenantFileSuperBlockItem item;
for (int64_t i = 0; OB_SUCC(ret) && i < tenant_file_infos.count(); ++i) { for (int64_t i = 0; OB_SUCC(ret) && i < tenant_file_infos.count(); ++i) {
bool tenant_has_been_dropped = false;
ObTenantFileInfo& file_info = *tenant_file_infos.at(i); ObTenantFileInfo& file_info = *tenant_file_infos.at(i);
ObTenantFileCheckpointEntry file_checkpoint_entry; ObTenantFileCheckpointEntry file_checkpoint_entry;
if (OB_FAIL(file_checkpoint_map.get_refactored(file_info.tenant_key_, file_checkpoint_entry))) { if (OB_FAIL(file_checkpoint_map.get_refactored(file_info.tenant_key_, file_checkpoint_entry))) {
if (OB_HASH_NOT_EXIST == ret) { if (OB_HASH_NOT_EXIST == ret) {
ret = OB_SUCCESS; // in case any deleted tenant file info is leaked, check schema for sure
share::schema::ObSchemaGetterGuard schema_guard;
if (OB_FAIL(share::schema::ObMultiVersionSchemaService::get_instance().get_schema_guard(schema_guard))) {
LOG_ERROR("fail to get schema guard", K(ret));
} else if (OB_FAIL(schema_guard.check_formal_guard())) {
LOG_WARN("fail to check formal schema guard", K(ret));
} else if (OB_FAIL(schema_guard.check_if_tenant_has_been_dropped(
file_info.tenant_key_.tenant_id_, tenant_has_been_dropped))) {
LOG_ERROR("fail to check if tenant has been dropped", K(ret), K(file_info));
}
} else { } else {
LOG_WARN("fail to get from file checkpoint map", K(ret)); LOG_WARN("fail to get from file checkpoint map", K(ret));
} }
@ -112,7 +123,7 @@ int ObTenantFileSuperBlockCheckpointWriter::write_checkpoint(blocksstable::ObSto
file_info.tenant_file_super_block_.pg_meta_entry_ = file_checkpoint_entry.super_block_.pg_meta_entry_; file_info.tenant_file_super_block_.pg_meta_entry_ = file_checkpoint_entry.super_block_.pg_meta_entry_;
} }
if (OB_SUCC(ret)) { if (OB_SUCC(ret) && !tenant_has_been_dropped) {
ObTenantFileSuperBlockCheckpointEntry entry(*tenant_file_infos.at(i)); ObTenantFileSuperBlockCheckpointEntry entry(*tenant_file_infos.at(i));
item.set_tenant_file_entry(entry); item.set_tenant_file_entry(entry);
if (OB_FAIL(writer_.write_item(&item))) { if (OB_FAIL(writer_.write_item(&item))) {

View File

@ -81,9 +81,9 @@ TEST_F(TestTenantFileMgr, test_file_op)
OB_SERVER_FILE_MGR.add_pg( OB_SERVER_FILE_MGR.add_pg(
ObTenantFileKey(handle2.get_storage_file()->get_tenant_id(), handle2.get_storage_file()->get_file_id()), ObTenantFileKey(handle2.get_storage_file()->get_tenant_id(), handle2.get_storage_file()->get_file_id()),
pg_key2)); pg_key2));
ASSERT_NE(handle1.get_storage_file(), handle2.get_storage_file()); ASSERT_EQ(handle1.get_storage_file(), handle2.get_storage_file());
ASSERT_EQ(OB_SUCCESS, OB_SERVER_FILE_MGR.get_all_tenant_file_infos(allocator, tenant_file_infos)); ASSERT_EQ(OB_SUCCESS, OB_SERVER_FILE_MGR.get_all_tenant_file_infos(allocator, tenant_file_infos));
ASSERT_EQ(2, tenant_file_infos.count()); ASSERT_EQ(1, tenant_file_infos.count());
// alloc less than 10000 files // alloc less than 10000 files
for (int64_t i = 0; OB_SUCC(ret) && i < 9998; ++i) { for (int64_t i = 0; OB_SUCC(ret) && i < 9998; ++i) {
@ -96,7 +96,7 @@ TEST_F(TestTenantFileMgr, test_file_op)
pg_key)); pg_key));
} }
ASSERT_EQ(OB_SUCCESS, OB_SERVER_FILE_MGR.get_all_tenant_file_infos(allocator, tenant_file_infos)); ASSERT_EQ(OB_SUCCESS, OB_SERVER_FILE_MGR.get_all_tenant_file_infos(allocator, tenant_file_infos));
ASSERT_EQ(10, tenant_file_infos.count()); ASSERT_EQ(1, tenant_file_infos.count());
// alloc more than 10000 files // alloc more than 10000 files
for (int64_t i = 0; OB_SUCC(ret) && i < 3; ++i) { for (int64_t i = 0; OB_SUCC(ret) && i < 3; ++i) {
@ -109,7 +109,7 @@ TEST_F(TestTenantFileMgr, test_file_op)
pg_key)); pg_key));
} }
ASSERT_EQ(OB_SUCCESS, OB_SERVER_FILE_MGR.get_all_tenant_file_infos(allocator, tenant_file_infos)); ASSERT_EQ(OB_SUCCESS, OB_SERVER_FILE_MGR.get_all_tenant_file_infos(allocator, tenant_file_infos));
ASSERT_EQ(11, tenant_file_infos.count()); ASSERT_EQ(1, tenant_file_infos.count());
} }
TEST_F(TestTenantFileMgr, test_update_tenant_file_super_block) TEST_F(TestTenantFileMgr, test_update_tenant_file_super_block)