fixed restart failed because of the defense of ObServerLogBlockMgr

This commit is contained in:
HaHaJeff 2023-02-20 04:44:22 +00:00 committed by ob-robot
parent d3ea779bdc
commit 0aa17c1e8e
2 changed files with 36 additions and 7 deletions

View File

@ -109,6 +109,7 @@ TEST_F(TestObSimpleLogClusterBasicFunc, restart_and_clear_tmp_files)
int ret = OB_SUCCESS;
guard.click("mkdir");
EXPECT_EQ(OB_ERR_UNEXPECTED, restart_paxos_groups());
CLOG_LOG(INFO, "after restart_paxos_groups after exist tmp dir");
guard.click("restart");
const std::string rm_dir_2 = "rm -rf " + dir_2;
system(rm_dir_2.c_str());
@ -117,6 +118,7 @@ TEST_F(TestObSimpleLogClusterBasicFunc, restart_and_clear_tmp_files)
PALF_LOG(ERROR, "restart_paxos_groups failed", K(ret));
} else {
{
CLOG_LOG(INFO, "after restart_paxos_groups after remove tmp dir");
guard.click("restart");
bool result = false;
EXPECT_EQ(OB_SUCCESS,
@ -137,6 +139,34 @@ TEST_F(TestObSimpleLogClusterBasicFunc, restart_and_clear_tmp_files)
EXPECT_EQ(OB_ITER_END, read_log(leader1));
guard.click("read_log");
}
// 验证tenant下有临时文件的场景,该临时文件需要归还给log_pool
{
PalfHandleImplGuard leader1;
int64_t leader_idx1 = 0;
EXPECT_EQ(OB_SUCCESS, get_leader(id, leader1, leader_idx1));
std::string palf_log_dir = leader1.palf_handle_impl_->log_engine_.log_storage_.block_mgr_.log_dir_;
ObISimpleLogServer *i_server = get_cluster()[0];
ObSimpleLogServer *server = dynamic_cast<ObSimpleLogServer*>(i_server);
std::string log_pool = server->log_block_pool_.log_pool_path_;
const block_id_t min_block_id = server->log_block_pool_.min_block_id_;
char src[1024] = {'\0'};
char dest[1024] = {'\0'};
block_id_to_tmp_string(10000, dest, 1024);
block_id_to_string(min_block_id, src, 1024);
std::string src_str = log_pool + "/" + src;
std::string dest_str = palf_log_dir + "/" + dest;
std::string mv_system = "mv " + src_str + " " + dest_str;
system(mv_system.c_str());
bool result1 = false;
EXPECT_EQ(OB_SUCCESS,
common::FileDirectoryUtils::is_exists(dest_str.c_str(), result1));
EXPECT_EQ(true, result1);
leader1.reset();
EXPECT_EQ(OB_SUCCESS, restart_paxos_groups());
EXPECT_EQ(OB_SUCCESS,
common::FileDirectoryUtils::is_exists(dest_str.c_str(), result1));
EXPECT_EQ(false, result1);
}
EXPECT_EQ(OB_SUCCESS, remove_dir());
EXPECT_EQ(OB_SUCCESS, restart_paxos_groups());
}

View File

@ -99,8 +99,6 @@ int ObServerLogBlockMgr::init(const char *log_disk_base_path)
CLOG_LOG(ERROR, "Invalid argument", K(ret), KPC(this), KP(log_disk_base_path));
} else if (OB_FAIL(do_init_(log_disk_base_path))) {
CLOG_LOG(ERROR, "do_init_ failed", K(ret), KPC(this), K(log_disk_base_path));
} else if (OB_FAIL(FileDirectoryUtils::delete_tmp_file_or_directory_at(log_disk_base_path))) {
CLOG_LOG(ERROR, "delete_tmp_file_or_directory_at failed", K(ret), KPC(this));
} else if (OB_FAIL(do_load_(log_disk_base_path))) {
CLOG_LOG(ERROR, "do_load_ failed", K(ret), KPC(this), K(log_disk_base_path));
} else {
@ -464,15 +462,16 @@ int ObServerLogBlockMgr::do_load_(const char *log_disk_path)
int ret = OB_SUCCESS;
int64_t has_allocated_block_cnt = 0;
ObTimeGuard time_guard("RestartServerBlockMgr", 1 * 1000 * 1000);
if (OB_FAIL(scan_log_disk_dir_(log_disk_path, has_allocated_block_cnt))) {
if (OB_FAIL(remove_tmp_file_or_directory_for_tenant_(log_disk_path))) {
CLOG_LOG(ERROR, "remove_tmp_file_or_directory_at failed", K(ret), K(log_disk_path));
} else if (OB_FAIL(scan_log_disk_dir_(log_disk_path, has_allocated_block_cnt))) {
CLOG_LOG(ERROR, "scan_log_disk_dir_ failed", K(ret), KPC(this), K(log_disk_path),
K(has_allocated_block_cnt));
} else if (FALSE_IT(time_guard.click("scan_log_disk_dir_"))
} else if (FALSE_IT(time_guard.click("scan_log_disk_"))
|| OB_FAIL(scan_log_pool_dir_and_do_trim_())) {
CLOG_LOG(ERROR, "scan_log_pool_dir_ failed", K(ret), KPC(this), K(log_disk_path));
} else if (OB_FAIL(remove_tmp_file_or_directory_for_tenant_(log_disk_path))) {
CLOG_LOG(ERROR, "remove_tmp_file_or_directory_at failed", K(ret), K(log_disk_path));
} else if (FALSE_IT(time_guard.click("scan_log_pool_dir_")) || OB_FAIL(load_meta_())) {
} else if (FALSE_IT(time_guard.click("scan_log_pool_dir_and_do_trim_"))
|| OB_FAIL(load_meta_())) {
CLOG_LOG(ERROR, "load_meta_ failed", K(ret), KPC(this), K(log_disk_path));
} else if (FALSE_IT(time_guard.click("load_meta_"))
|| OB_FAIL(try_continous_to_resize_(has_allocated_block_cnt * BLOCK_SIZE))) {