Fix migration cut sstable left scn but new tablet table store init failed bug.

This commit is contained in:
godyangfight
2022-12-29 14:41:54 +00:00
committed by ob-robot
parent 4f6f8b11f3
commit 94e0e5067a
4 changed files with 157 additions and 45 deletions

View File

@ -21,12 +21,16 @@
#include "storage/ob_i_table.h"
#include "storage/ob_storage_struct.h"
#include "share/scn.h"
#include "share/rc/ob_tenant_base.h"
#include "storage/meta_mem/ob_tenant_meta_mem_mgr.h"
namespace oceanbase
{
using namespace common;
using namespace blocksstable;
using namespace storage;
using namespace omt;
using namespace share;
namespace unittest
{
@ -42,17 +46,55 @@ public:
sstable.key_.tablet_id_ = 1;
sstable.key_.scn_range_.start_scn_.convert_for_gts(start_log_ts);
sstable.key_.scn_range_.end_scn_.convert_for_gts(end_log_ts);
sstable.meta_.basic_meta_.row_store_type_ = ObRowStoreType::FLAT_ROW_STORE;
sstable.valid_for_reading_ = true;
sstable.meta_.basic_meta_.status_ = SSTABLE_WRITE_BUILDING;
sstable.meta_.data_root_info_.addr_.set_none_addr();
sstable.meta_.macro_info_.macro_meta_info_.addr_.set_none_addr();
sstable.meta_.basic_meta_.compressor_type_ = ObCompressorType::NONE_COMPRESSOR;
}
};
class TestSSTableScnRangeCut : public ::testing::Test
{
public:
TestSSTableScnRangeCut()
: tenant_id_(1001),
t3m_(nullptr),
tenant_base_(1001)
{ }
~TestSSTableScnRangeCut() {}
void SetUp()
{
t3m_ = OB_NEW(ObTenantMetaMemMgr, ObModIds::TEST, 1001);
t3m_->init();
tenant_base_.set(t3m_);
ObTenantEnv::set_tenant(&tenant_base_);
ASSERT_EQ(OB_SUCCESS, tenant_base_.init());
}
void TearDown()
{
t3m_->~ObTenantMetaMemMgr();
t3m_ = nullptr;
tenant_base_.destroy();
ObTenantEnv::set_tenant(nullptr);
}
private:
const uint64_t tenant_id_;
ObTenantMetaMemMgr *t3m_;
ObTenantBase tenant_base_;
ObTabletTableStore tablet_table_store_;
DISALLOW_COPY_AND_ASSIGN(TestSSTableScnRangeCut);
};
//normal condition
//sstable1 log_ts: [0,100)
//sstable2 log_ts: [100, 200)
//sstable3 log_ts: [200,300)
TEST(ObTabletTableStore, sstable_scn_range_no_cross_and_continue)
TEST_F(TestSSTableScnRangeCut, sstable_scn_range_no_cross_and_continue)
{
int ret = OB_SUCCESS;
ObTabletTableStore tablet_table_store;
@ -65,25 +107,26 @@ TEST(ObTabletTableStore, sstable_scn_range_no_cross_and_continue)
ObSSTable sstable3;
TestMockSSTable::generate_mock_sstable(200, 300, sstable3);
ObArray<ObITable *> minor_sstables;
ObTablesHandleArray tables_handle;
ret = minor_sstables.push_back(&sstable1);
ASSERT_EQ(OB_SUCCESS, ret);
ret = minor_sstables.push_back(&sstable2);
ASSERT_EQ(OB_SUCCESS, ret);
ret = minor_sstables.push_back(&sstable3);
ASSERT_EQ(OB_SUCCESS, ret);
ret = tablet_table_store.cut_ha_sstable_scn_range_(minor_sstables);
ret = tablet_table_store.cut_ha_sstable_scn_range_(minor_sstables, tables_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(0, sstable1.key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(100, sstable1.key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(0, tables_handle.get_table(0)->key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(100, tables_handle.get_table(0)->key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(100, sstable2.key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(200, sstable2.key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(100, tables_handle.get_table(1)->key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(200, tables_handle.get_table(1)->key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(200, sstable3.key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(300, sstable3.key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(200, tables_handle.get_table(2)->key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(300, tables_handle.get_table(2)->key_.scn_range_.end_scn_.get_val_for_inner_table_field());
}
@ -92,7 +135,7 @@ TEST(ObTabletTableStore, sstable_scn_range_no_cross_and_continue)
//sstable2 log_ts: [200, 300)
//sstable3 log_ts: [300,500)
TEST(ObTabletTableStore, sstable_scn_range_is_not_continue)
TEST_F(TestSSTableScnRangeCut, sstable_scn_range_is_not_continue)
{
int ret = OB_SUCCESS;
ObTabletTableStore tablet_table_store;
@ -107,13 +150,15 @@ TEST(ObTabletTableStore, sstable_scn_range_is_not_continue)
TestMockSSTable::generate_mock_sstable(300, 500, sstable3);
ObArray<ObITable *> minor_sstables;
ObTablesHandleArray tables_handle;
ret = minor_sstables.push_back(&sstable1);
ASSERT_EQ(OB_SUCCESS, ret);
ret = minor_sstables.push_back(&sstable2);
ASSERT_EQ(OB_SUCCESS, ret);
ret = minor_sstables.push_back(&sstable3);
ASSERT_EQ(OB_SUCCESS, ret);
ret = tablet_table_store.cut_ha_sstable_scn_range_(minor_sstables);
ret = tablet_table_store.cut_ha_sstable_scn_range_(minor_sstables, tables_handle);
ASSERT_EQ(OB_ERR_UNEXPECTED, ret);
}
@ -123,7 +168,7 @@ TEST(ObTabletTableStore, sstable_scn_range_is_not_continue)
//sstable2 log_ts: [0, 200)
//sstable3 log_ts: [200,500)
TEST(ObTabletTableStore, sstable_scn_range_contain)
TEST_F(TestSSTableScnRangeCut, sstable_scn_range_contain)
{
int ret = OB_SUCCESS;
ObTabletTableStore tablet_table_store;
@ -138,23 +183,25 @@ TEST(ObTabletTableStore, sstable_scn_range_contain)
TestMockSSTable::generate_mock_sstable(200, 500, sstable3);
ObArray<ObITable *> minor_sstables;
ObTablesHandleArray tables_handle;
ret = minor_sstables.push_back(&sstable1);
ASSERT_EQ(OB_SUCCESS, ret);
ret = minor_sstables.push_back(&sstable2);
ASSERT_EQ(OB_SUCCESS, ret);
ret = minor_sstables.push_back(&sstable3);
ASSERT_EQ(OB_SUCCESS, ret);
ret = tablet_table_store.cut_ha_sstable_scn_range_(minor_sstables);
ret = tablet_table_store.cut_ha_sstable_scn_range_(minor_sstables, tables_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(0, sstable1.key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(100, sstable1.key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(0, tables_handle.get_table(0)->key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(100, tables_handle.get_table(0)->key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(100, sstable2.key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(200, sstable2.key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(100, tables_handle.get_table(1)->key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(200, tables_handle.get_table(1)->key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(200, sstable3.key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(500, sstable3.key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(200, tables_handle.get_table(2)->key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(500, tables_handle.get_table(2)->key_.scn_range_.end_scn_.get_val_for_inner_table_field());
}
@ -163,7 +210,7 @@ TEST(ObTabletTableStore, sstable_scn_range_contain)
//sstable2 log_ts: [50, 200)
//sstable3 log_ts: [200,500)
TEST(ObTabletTableStore, sstable_scn_range_has_overlap)
TEST_F(TestSSTableScnRangeCut, sstable_scn_range_has_overlap)
{
int ret = OB_SUCCESS;
ObTabletTableStore tablet_table_store;
@ -178,23 +225,25 @@ TEST(ObTabletTableStore, sstable_scn_range_has_overlap)
TestMockSSTable::generate_mock_sstable(200, 500, sstable3);
ObArray<ObITable *> minor_sstables;
ObTablesHandleArray tables_handle;
ret = minor_sstables.push_back(&sstable1);
ASSERT_EQ(OB_SUCCESS, ret);
ret = minor_sstables.push_back(&sstable2);
ASSERT_EQ(OB_SUCCESS, ret);
ret = minor_sstables.push_back(&sstable3);
ASSERT_EQ(OB_SUCCESS, ret);
ret = tablet_table_store.cut_ha_sstable_scn_range_(minor_sstables);
ret = tablet_table_store.cut_ha_sstable_scn_range_(minor_sstables, tables_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(0, sstable1.key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(100, sstable1.key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(0, tables_handle.get_table(0)->key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(100, tables_handle.get_table(0)->key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(100, sstable2.key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(200, sstable2.key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(100, tables_handle.get_table(1)->key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(200, tables_handle.get_table(1)->key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(200, sstable3.key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(500, sstable3.key_.scn_range_.end_scn_.get_val_for_inner_table_field());
ASSERT_EQ(200, tables_handle.get_table(2)->key_.scn_range_.start_scn_.get_val_for_inner_table_field());
ASSERT_EQ(500, tables_handle.get_table(2)->key_.scn_range_.end_scn_.get_val_for_inner_table_field());
}