patch backup &migrate code to open source

This commit is contained in:
mw0
2021-09-27 20:48:34 +08:00
committed by wangzelin.wzl
parent a2c22b06aa
commit 64b53b6a17
41 changed files with 4944 additions and 4232 deletions

View File

@ -19,10 +19,10 @@
#include "share/backup/ob_backup_path.h"
#include "share/backup/ob_log_archive_backup_info_mgr.h"
#include "share/backup/ob_backup_struct.h"
#include "rootserver/ob_backup_data_clean.h"
#undef private
#include <algorithm>
#include "lib/hash/ob_hashmap.h"
using namespace oceanbase;
using namespace common;
using namespace share;
@ -451,6 +451,101 @@ TEST(ObLogArchiveBackupInfoMgr, log_archive_info_cmp)
}
TEST(ObLogArchiveBackupInfoMgr, log_archive_info_cmp2)
{
int ret = OB_SUCCESS;
ObArray<ObLogArchiveBackupInfo> log_infos;
ObLogArchiveBackupInfo log_info;
log_info.status_.start_ts_ = 1;
log_info.status_.checkpoint_ts_ = 0;
log_info.status_.round_ = 1;
ret = log_infos.push_back(log_info);
ASSERT_EQ(OB_SUCCESS, ret);
log_info.reset();
log_info.status_.start_ts_ = 1;
log_info.status_.checkpoint_ts_ = 0;
log_info.status_.round_ = 2;
ret = log_infos.push_back(log_info);
ASSERT_EQ(OB_SUCCESS, ret);
log_info.reset();
log_info.status_.start_ts_ = 1;
log_info.status_.checkpoint_ts_ = 0;
log_info.status_.round_ = 3;
ret = log_infos.push_back(log_info);
ASSERT_EQ(OB_SUCCESS, ret);
typedef ObArray<ObLogArchiveBackupInfo>::iterator ArrayIter;
rootserver::ObBackupDataClean::CompareLogArchiveSnapshotVersion cmp;
ArrayIter iter = std::lower_bound(log_infos.begin(),
log_infos.end(),
1,
cmp);
if (iter == log_infos.end()) {
--iter;
} else if (iter != log_infos.begin()
&& iter->status_.start_ts_ > 1) {
--iter;
}
log_info = *iter;
LOG_INFO("log info", K(log_info));
}
TEST(ObBackupDataClean, duplicate_task)
{
int ret = OB_SUCCESS;
ObTenantBackupTaskInfo task_info;
ObArray<ObTenantBackupTaskInfo> task_infos;
//mock task info
//array backup set id is : 1, 2, 1, 2
task_info.tenant_id_ = OB_SYS_TENANT_ID;
task_info.incarnation_ = 1;
task_info.backup_set_id_ = 1;
task_info.copy_id_ = 0;
task_info.status_ = ObTenantBackupTaskInfo::FINISH;
ret = task_infos.push_back(task_info);
ASSERT_EQ(OB_SUCCESS, ret);
task_info.reset();
task_info.tenant_id_ = OB_SYS_TENANT_ID;
task_info.incarnation_ = 1;
task_info.backup_set_id_ = 2;
ret = task_infos.push_back(task_info);
task_info.copy_id_ = 0;
task_info.status_ = ObTenantBackupTaskInfo::FINISH;
ASSERT_EQ(OB_SUCCESS, ret);
task_info.reset();
task_info.tenant_id_ = OB_SYS_TENANT_ID;
task_info.incarnation_ = 1;
task_info.backup_set_id_ = 1;
task_info.copy_id_ = 0;
task_info.status_ = ObTenantBackupTaskInfo::DOING;
ret = task_infos.push_back(task_info);
ASSERT_EQ(OB_SUCCESS, ret);
task_info.reset();
task_info.tenant_id_ = OB_SYS_TENANT_ID;
task_info.incarnation_ = 1;
task_info.backup_set_id_ = 2;
task_info.copy_id_ = 0;
task_info.status_ = ObTenantBackupTaskInfo::DOING;
ret = task_infos.push_back(task_info);
ASSERT_EQ(OB_SUCCESS, ret);
rootserver::ObBackupDataClean data_clean;
data_clean.is_inited_ = true;
ret = data_clean.duplicate_task_info(task_infos);
ASSERT_EQ(2, task_infos.count());
ASSERT_EQ(1, task_infos.at(0).backup_set_id_);
ASSERT_EQ(ObTenantBackupTaskInfo::DOING, task_infos.at(0).status_);
ASSERT_EQ(2, task_infos.at(1).backup_set_id_);
ASSERT_EQ(ObTenantBackupTaskInfo::DOING, task_infos.at(1).status_);
}
int main(int argc, char **argv)
{
OB_LOGGER.set_log_level("INFO");

View File

@ -43,16 +43,16 @@ public:
{
destory();
}
int init(const char* test_name, const int64_t macro_block_size = 64 * 1024, const int64_t macro_block_count = 100,
int init(const char *test_name, const int64_t macro_block_size = 64 * 1024, const int64_t macro_block_count = 100,
const int64_t disk_num = 0);
virtual int open();
virtual int restart();
virtual void destory();
ObStorageEnv& get_storage_env()
ObStorageEnv &get_storage_env()
{
return storage_env_;
}
ObStoreFileSystem& get_file_system()
ObStoreFileSystem &get_file_system()
{
return OB_FILE_SYSTEM;
}
@ -78,33 +78,33 @@ private:
class TestDataFilePrepare : public ::testing::Test {
public:
TestDataFilePrepare(
const char* test_name, const int64_t macro_block_size = 64 * 1024, const int64_t macro_block_count = 100);
const char *test_name, const int64_t macro_block_size = 64 * 1024, const int64_t macro_block_count = 100);
virtual ~TestDataFilePrepare();
virtual void SetUp();
virtual void TearDown();
virtual void fake_freeze_mgr();
const ObStorageEnv& get_storage_env()
const ObStorageEnv &get_storage_env()
{
return util_.get_storage_env();
}
ObStoreFileSystem& get_file_system()
ObStoreFileSystem &get_file_system()
{
return util_.get_file_system();
}
const ObStorageFileHandle& get_storage_file_handle();
const ObStorageFileHandle &get_storage_file_handle();
protected:
static const int64_t TENANT_ID = 1;
static const int64_t TABLE_ID = 3001;
TestDataFilePrepareUtil util_;
ObArenaAllocator allocator_;
const char* test_name_;
const char *test_name_;
const int64_t macro_block_size_;
const int64_t macro_block_count_;
};
TestDataFilePrepare::TestDataFilePrepare(
const char* test_name, const int64_t macro_block_size, const int64_t macro_block_count)
const char *test_name, const int64_t macro_block_size, const int64_t macro_block_count)
: util_(),
allocator_(ObModIds::TEST),
test_name_(test_name),
@ -133,14 +133,12 @@ void TestDataFilePrepare::fake_freeze_mgr()
common::ObArray<ObFreezeInfoSnapshotMgr::SchemaPair> gc_schema_version;
common::ObArray<share::ObSnapshotInfo> snapshots;
common::ObMySQLProxy sql_proxy;
ObFreezeInfoSnapshotMgr* freeze_mgr;
ObFreezeInfoSnapshotMgr *freeze_mgr;
freeze_mgr = &ObFreezeInfoMgrWrapper::get_instance();
if (!freeze_mgr->is_inited()) {
ASSERT_EQ(OB_SUCCESS, freeze_mgr->init(sql_proxy, false));
const int64_t snapshot_gc_ts = 500;
const int64_t backup_snapshot_version = snapshot_gc_ts - 100;
const int64_t delay_delete_snapshot_version = backup_snapshot_version;
bool changed = false;
ASSERT_EQ(OB_SUCCESS, gc_schema_version.push_back(ObFreezeInfoSnapshotMgr::SchemaPair(1, 210)));
@ -150,18 +148,11 @@ void TestDataFilePrepare::fake_freeze_mgr()
ASSERT_EQ(OB_SUCCESS, freeze_info.push_back(ObFreezeInfoSnapshotMgr::FreezeInfoLite(4, 400, 0)));
ASSERT_EQ(OB_SUCCESS,
freeze_mgr->update_info(snapshot_gc_ts,
gc_schema_version,
freeze_info,
snapshots,
backup_snapshot_version,
delay_delete_snapshot_version,
INT64_MAX,
changed));
freeze_mgr->update_info(snapshot_gc_ts, gc_schema_version, freeze_info, snapshots, INT64_MAX, changed));
}
}
const ObStorageFileHandle& TestDataFilePrepare::get_storage_file_handle()
const ObStorageFileHandle &TestDataFilePrepare::get_storage_file_handle()
{
ObPGKey pg_key(combine_id(1, 1001), 1, 0);
ObIPartitionGroupGuard pg_guard;
@ -174,7 +165,7 @@ TestDataFilePrepareUtil::TestDataFilePrepareUtil()
{}
int TestDataFilePrepareUtil::init(
const char* test_name, const int64_t macro_block_size, const int64_t macro_block_count, const int64_t disk_num)
const char *test_name, const int64_t macro_block_size, const int64_t macro_block_count, const int64_t disk_num)
{
int ret = OB_SUCCESS;
char cur_dir[OB_MAX_FILE_NAME_LENGTH];

View File

@ -31,7 +31,7 @@ class MockSchemaCache : public ObFreezeInfoSnapshotMgr::SchemaCache {
public:
MockSchemaCache() : SchemaCache(schema_query_set_), schema_query_set_(*this)
{}
virtual int fetch_freeze_schema(const uint64_t, const int64_t, int64_t& schema_version) override
virtual int fetch_freeze_schema(const uint64_t, const int64_t, int64_t &schema_version) override
{
int ret = OB_SUCCESS;
if (rand() % 4 == 0) {
@ -43,8 +43,8 @@ public:
return ret;
}
virtual int fetch_freeze_schema(const uint64_t tenant_id, const int64_t, int64_t& schema_version,
common::ObIArray<ObFreezeInfoSnapshotMgr::SchemaPair>& freeze_schema) override
virtual int fetch_freeze_schema(const uint64_t tenant_id, const int64_t, int64_t &schema_version,
common::ObIArray<ObFreezeInfoSnapshotMgr::SchemaPair> &freeze_schema) override
{
int ret = OB_SUCCESS;
for (int64_t i = 0; i < TEST_ALL_TENANT_NUM; i++) {
@ -78,8 +78,6 @@ public:
ObArray<ObFreezeInfoSnapshotMgr::SchemaPair> schemas;
ObArray<ObFreezeInfoSnapshotMgr::FreezeInfoLite> infos;
ObArray<share::ObSnapshotInfo> snapshots;
const int64_t backup_snapshot_version = 0;
const int64_t delay_delete_snapshot_version = 0;
for (int i = 0; i < TEST_NUM; i++) {
schemas.reset();
@ -100,14 +98,7 @@ public:
}
bool changed;
mgr.update_info((i + 1) * 10,
schemas,
infos,
snapshots,
backup_snapshot_version,
INT64_MAX,
delay_delete_snapshot_version,
changed);
mgr.update_info((i + 1) * 10, schemas, infos, snapshots, INT64_MAX, changed);
usleep(100000);
}
@ -125,7 +116,7 @@ TEST_F(TestFreezeInfoSnapshotMgr, test_rs_return_minus_one_for_gc_snapshot_info)
for (int i = 0; i < TEST_NUM; i++) {
for (int j = 0; j < TEST_TENANT_NUM; j++) {
ObFreezeInfoSnapshotMgr::NeighbourFreezeInfo& info_item = info[i][j];
ObFreezeInfoSnapshotMgr::NeighbourFreezeInfo &info_item = info[i][j];
EXPECT_EQ(
OB_SUCCESS, mgr.get_neighbour_major_freeze(((((int64_t)j + 1001) << 40) + 50001), i * 10 + 5, info[i][j]));
STORAGE_LOG(WARN, "get neighbour major freeze", K(j + 1001), K(i * 10 + 5), K(info_item));
@ -143,9 +134,9 @@ TEST_F(TestFreezeInfoSnapshotMgr, test_rs_return_minus_one_for_gc_snapshot_info)
TEST_F(TestFreezeInfoSnapshotMgr, test_rs_return_minus_one_for_get_freeze_schema_evrsion)
{
MockSchemaCache cache;
MockSchemaCache::schema_node* p = NULL;
MockSchemaCache::schema_node *p = NULL;
p = (MockSchemaCache::schema_node*)cache.allocator_.alloc();
p = (MockSchemaCache::schema_node *)cache.allocator_.alloc();
cache.head_ = cache.tail_ = p;
cache.inited_ = true;
@ -182,7 +173,7 @@ TEST_F(TestFreezeInfoSnapshotMgr, test_rs_return_minus_one_for_get_freeze_schema
}
}
MockSchemaCache::schema_node* curr = cache.head_->next;
MockSchemaCache::schema_node *curr = cache.head_->next;
STORAGE_LOG(INFO, "start finding -1 in list");
while (curr) {
EXPECT_TRUE(curr->schema_version != -1);
@ -193,7 +184,7 @@ TEST_F(TestFreezeInfoSnapshotMgr, test_rs_return_minus_one_for_get_freeze_schema
} // namespace unittest
} // namespace oceanbase
int main(int argc, char** argv)
int main(int argc, char **argv)
{
OB_LOGGER.set_file_name("test_ob_freeze_info_snapshot_mgr.log");
OB_LOGGER.set_log_level("INFO");