[FEAT MERGE] incremental direct load phase I

Co-authored-by: Monk-Liu <1152761042@qq.com>
Co-authored-by: suz-yang <suz.yang@foxmail.com>
Co-authored-by: ZenoWang <wzybuaasoft@163.com>
This commit is contained in:
coolfishchen
2024-04-22 09:23:47 +00:00
committed by ob-robot
parent 4d7b31b518
commit 9de65fb1d7
278 changed files with 13417 additions and 6679 deletions

View File

@ -1,69 +0,0 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#ifndef MOCK_OB_PARTITION_COMPONENT_FACTORY_H_
#define MOCK_OB_PARTITION_COMPONENT_FACTORY_H_
namespace oceanbase
{
namespace storage
{
class MockObIPartitionComponentFactory : public ObIPartitionComponentFactory
{
public:
MOCK_METHOD1(get_ls,
ObLS * (const uint64_t tenant_id));
MOCK_METHOD1(get_partition,
ObIPartitionGroup * (const uint64_t tenant_id));
MOCK_METHOD0(get_ssstore,
ObSSStore * ());
MOCK_METHOD0(get_trans_service,
transaction::ObTransService * ());
MOCK_METHOD0(get_clog_mgr,
clog::ObICLogMgr * ());
MOCK_METHOD0(get_partition_service,
ObPartitionService * ());
MOCK_METHOD0(get_election_mgr,
election::ObElectionMgr * ());
MOCK_METHOD1(get_log_service,
clog::ObIPartitionLogService * (const uint64_t tenant_id));
MOCK_METHOD0(get_replay_engine_wrapper,
clog::ObLogReplayEngineWrapper * ());
MOCK_METHOD1(free,
void(ObIPartitionGroup *partition));
MOCK_METHOD1(free,
void(ObReplayStatus *status));
MOCK_METHOD1(free,
void(ObSSStore *store));
MOCK_METHOD1(free,
void(transaction::ObTransService *txs));
MOCK_METHOD1(free,
void(clog::ObICLogMgr *clog_mgr));
MOCK_METHOD1(free,
void(ObPartitionService *ptt_service));
MOCK_METHOD1(free,
void(replayengine::ObILogReplayEngine *rp_eg));
MOCK_METHOD1(free,
void(oceanbase::election::ObIElectionMgr *election_mgr));
MOCK_METHOD1(free,
void(clog::ObIPartitionLogService *log_service));
MOCK_METHOD1(free,
void(clog::ObLogReplayEngineWrapper *rp_eg));
};
} // namespace storage
} // namespace oceanbase
#endif

View File

@ -27,7 +27,6 @@
#include "common/storage/ob_freeze_define.h"
#include "storage/tx/ob_trans_define.h"
#include "storage/tx/ob_trans_service.h"
#include "storage/ob_i_partition_component_factory.h"
#include "sql/ob_end_trans_callback.h"
namespace oceanbase
@ -56,9 +55,8 @@ public:
MOCK_METHOD0(force_refresh_locality_info, int());
MOCK_METHOD6(init,
MOCK_METHOD5(init,
int(const blocksstable::ObStorageEnv &env, const common::ObAddr &self_addr,
ObIPartitionComponentFactory *cp_fty,
share::schema::ObMultiVersionSchemaService *schema_service,
share::ObRsMgr *rs_mgr, rpc::frame::ObReqTransport *req_transport));

View File

@ -19,7 +19,6 @@
#include "share/ob_rs_mgr.h"
#include "share/ob_srv_rpc_proxy.h"
#include "storage/blocksstable/ob_block_sstable_struct.h"
#include "storage/ob_partition_component_factory.h"
#include "storage/tx/ob_gts_rpc.h"
#include "sql/session/ob_sql_session_mgr.h"
#include "observer/ob_srv_network_frame.h"
@ -105,7 +104,6 @@ public:
protected:
bool is_inited_;
protected:
ObPartitionComponentFactory partition_cfy_;
//MockObSchemaService schema_service_;
ObRestoreSchema restore_schema_;
MockSchemaService *schema_service_;

View File

@ -15,7 +15,6 @@
#include "storage/blocksstable/ob_sstable.h"
#include "storage/ob_partition_scheduler.h"
#include "storage/ob_partition_component_factory.h"
#include "storage/blocksstable/ob_macro_block_writer.h"
#include "storage/ob_store_row_comparer.h"
#include "storage/ob_parallel_external_sort.h"

View File

@ -63,10 +63,10 @@ void MdsAllocator::free(void *ptr) {
}
}
}
namespace memtable
namespace storage
{
bool ObMemtable::can_be_minor_merged()
bool ObITabletMemtable::can_be_minor_merged()
{
return is_tablet_freeze_;
}
@ -346,7 +346,7 @@ int TestCompactionPolicy::mock_memtable(
}
ObTabletMemtableMgr *mt_mgr = static_cast<ObTabletMemtableMgr *>(protected_handle->memtable_mgr_handle_.get_memtable_mgr());
if (OB_FAIL(ret)) {
} else if (OB_FAIL(t3m->acquire_memtable(table_handle))) {
} else if (OB_FAIL(t3m->acquire_data_memtable(table_handle))) {
LOG_WARN("failed to acquire memtable", K(ret));
} else if (OB_ISNULL(memtable = static_cast<ObMemtable*>(table_handle.get_table()))) {
ret = OB_ERR_UNEXPECTED;

View File

@ -1,794 +0,0 @@
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#include <gtest/gtest.h>
#define private public
#include "storage/ob_multi_version_sorted_stores.h"
#include "storage/ob_ss_store.h"
namespace oceanbase
{
using namespace common;
using namespace storage;
using namespace memtable;
namespace unittest
{
TEST(ObStoresHandle, simple)
{
int ret = OB_SUCCESS;
ObStoresHandle stores_handle;
ObPartitionComponentFactory cp_fty;
ObSSStore *store = NULL;
//Invalid argument
ret = stores_handle.add_store(NULL);
ASSERT_NE(OB_SUCCESS, ret);
//without init
store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_EQ(1L, store->ref_cnt_);
ret = stores_handle.add_store(store);
ASSERT_NE(OB_SUCCESS, ret);
//normal
stores_handle.init(&cp_fty);
ret = stores_handle.add_store(store);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(2L, store->ref_cnt_);
ASSERT_EQ(1L, stores_handle.get_stores().count());
ASSERT_EQ(2L, store->ref_cnt_);
stores_handle.reset();
//allow repeate reset
stores_handle.reset();
ASSERT_EQ(1L, store->ref_cnt_);
cp_fty.free(store);
}
TEST(ObSortedStores, simple)
{
int ret = OB_SUCCESS;
ObSortedStores stores;
ObStoresHandle stores_handle;
ObPartitionComponentFactory cp_fty;
ObSSStore *ss_store = NULL;
ObVersion version;
bool merge;
//invalid use without init
ret = stores.add_store(ss_store);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.remove_store(version);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_write_store(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_base_ssstore(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_last_ssstore(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_store(version, stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_read_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_merge_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_minor_merge_stores(stores_handle, merge);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_ssstores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
//empty
ASSERT_EQ(OB_SUCCESS, stores.init(&cp_fty));
ret = stores.add_store(ss_store);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.remove_store(version);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_write_store(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_base_ssstore(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_last_ssstore(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_store(version, stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_read_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_merge_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_minor_merge_stores(stores_handle, merge);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_ssstores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
//repeatedly add
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
version.major_ = 1;
ss_store->set_version(version);
ret = stores.add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = stores.add_store(ss_store);
ASSERT_NE(OB_SUCCESS, ret);
ASSERT_EQ(2L, ss_store->ref_cnt_);
//invalid handle
ret = stores.get_write_store(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_base_ssstore(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_last_ssstore(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_store(version, stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_read_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_merge_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_ssstores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
//remove
ret = stores.remove_store(version);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1L, ss_store->ref_cnt_);
cp_fty.free(ss_store);
}
TEST(ObSortedStores, normal)
{
int ret = OB_SUCCESS;
ObSortedStores stores;
ObStoresHandle stores_handle;
ObPartitionComponentFactory cp_fty;
ObSSStore *ss_store = NULL;
ObIMemtable *mem_store = NULL;
ASSERT_EQ(OB_SUCCESS, stores.init(&cp_fty));
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(1, 0));
ret = stores.add_store(ss_store);
if (0 == ss_store->dec_ref()) {
cp_fty.free(ss_store);
}
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(2, 0));
mem_store->minor_freeze(ObVersion(2, 0));
ret = stores.add_store(mem_store);
if (0 == mem_store->dec_ref()) {
cp_fty.free(mem_store);
}
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(2, 1));
mem_store->major_freeze(ObVersion(2, 1));
ret = stores.add_store(mem_store);
if (0 == mem_store->dec_ref()) {
cp_fty.free(mem_store);
}
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(3, 0));
ret = stores.add_store(mem_store);
if (0 == mem_store->dec_ref()) {
cp_fty.free(mem_store);
}
ASSERT_EQ(OB_SUCCESS, ret);
stores_handle.reset();
stores_handle.init(&cp_fty);
ret = stores.get_write_store(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores_handle.get_stores().count());
ASSERT_EQ(ObVersion(3, 0), stores_handle.get_stores().at(0)->get_version());
stores_handle.reset();
stores_handle.init(&cp_fty);
ret = stores.get_base_ssstore(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores_handle.get_stores().count());
ASSERT_EQ(ObVersion(1, 0), stores_handle.get_stores().at(0)->get_version());
stores_handle.reset();
stores_handle.init(&cp_fty);
ret = stores.get_last_ssstore(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores_handle.get_stores().count());
ASSERT_EQ(ObVersion(1, 0), stores_handle.get_stores().at(0)->get_version());
stores_handle.reset();
stores_handle.init(&cp_fty);
ret = stores.get_store(ObVersion(2, 1), stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores_handle.get_stores().count());
ASSERT_EQ(ObVersion(2, 1), stores_handle.get_stores().at(0)->get_version());
stores_handle.reset();
stores_handle.init(&cp_fty);
ret = stores.get_read_stores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(4, stores_handle.get_stores().count());
stores_handle.reset();
stores_handle.init(&cp_fty);
ret = stores.get_merge_stores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(3, stores_handle.get_stores().count());
stores_handle.reset();
stores_handle.init(&cp_fty);
bool merge = false;
ret = stores.get_minor_merge_stores(stores_handle, merge);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(2, stores_handle.get_stores().count());
ASSERT_EQ(ObVersion(2, 0), stores_handle.get_stores().at(0)->get_version());
ASSERT_EQ(true, merge);
stores_handle.reset();
stores_handle.init(&cp_fty);
ret = stores.get_all_stores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(4, stores_handle.get_stores().count());
ASSERT_EQ(ObVersion(1, 0), stores_handle.get_stores().at(0)->get_version());
stores_handle.reset();
stores_handle.init(&cp_fty);
ret = stores.get_all_ssstores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores_handle.get_stores().count());
ASSERT_EQ(ObVersion(1, 0), stores_handle.get_stores().at(0)->get_version());
}
TEST(ObMultiVersionSortedStores, simple)
{
int ret = OB_SUCCESS;
ObMultiVersionSortedStores stores;
ObStoresHandle stores_handle;
ObPartitionComponentFactory cp_fty;
ObSSStore *ss_store = NULL;
ObVersion version;
bool merge;
//invalid use without init
ret = stores.add_store(ss_store);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.remove_store(version);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_write_store(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_base_ssstore(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_last_ssstore(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_store(version, stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_read_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_merge_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_minor_merge_stores(stores_handle, merge);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_ssstores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_version_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_version_ssstores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
//empty
stores.init(&cp_fty);
ret = stores.add_store(ss_store);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.remove_store(version);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_write_store(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_base_ssstore(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_last_ssstore(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_store(version, stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_read_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_merge_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_minor_merge_stores(stores_handle, merge);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_version_stores(stores_handle);
ASSERT_NE(OB_SUCCESS, ret);
ret = stores.get_all_ssstores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ret = stores.get_all_version_ssstores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(0, stores_handle.get_stores().count());
}
TEST(ObMultiVersionSortedStores, get_minor_store_major_freeze)
{
int ret = OB_SUCCESS;
ObMultiVersionSortedStores stores;
ObStoresHandle stores_handle;
ObPartitionComponentFactory cp_fty;
ObSSStore *ss_store = NULL;
ObIMemtable *mem_store = NULL;
ObIStore *store = NULL;
bool merge;
ASSERT_EQ(OB_SUCCESS, stores.init(&cp_fty));
// only ssstore
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(1, 0));
ret = stores.add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(2, 0));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
// ssstore + major frozen memstore + active memstore
mem_store->major_freeze(ObVersion(2, 0));
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(3, 0));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = stores.get_minor_merge_stores(stores_handle, merge);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores_handle.get_stores_count());
ASSERT_EQ(OB_SUCCESS, stores_handle.get_last_store(store));
ASSERT_EQ(ObVersion(2, 0), store->get_version());
ASSERT_EQ(true, merge);
}
TEST(ObMultiVersionSortedStores, get_minor_store)
{
int ret = OB_SUCCESS;
ObMultiVersionSortedStores stores;
ObStoresHandle stores_handle;
ObPartitionComponentFactory cp_fty;
ObSSStore *ss_store = NULL;
ObIMemtable *mem_store = NULL;
ObIStore *store = NULL;
bool merge;
ASSERT_EQ(OB_SUCCESS, stores.init(&cp_fty));
// only ssstore
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(1, 0));
ret = stores.add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = stores.get_minor_merge_stores(stores_handle, merge);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(0, stores_handle.get_stores_count());
ASSERT_EQ(false, merge);
// ssstore + active memstore
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(2, 0));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = stores.get_minor_merge_stores(stores_handle, merge);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(0, stores_handle.get_stores_count());
ASSERT_EQ(false, merge);
// ssstore + minor frozen memstore + active memstore
mem_store->minor_freeze(ObVersion(2, 0));
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(2, 1));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = stores.get_minor_merge_stores(stores_handle, merge);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores_handle.get_stores_count());
ASSERT_EQ(OB_SUCCESS, stores_handle.get_last_store(store));
ASSERT_EQ(ObVersion(2, 0), store->get_version());
ASSERT_EQ(false, merge);
// ssstore + minor frozen memstore + major frozen memstore + active memstore
mem_store->major_freeze(ObVersion(2, 1));
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(3, 0));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = stores.get_minor_merge_stores(stores_handle, merge);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(2, stores_handle.get_stores_count());
ASSERT_EQ(OB_SUCCESS, stores_handle.get_last_store(store));
ASSERT_TRUE(NULL != store);
ASSERT_EQ(ObVersion(2, 1), store->get_version());
ASSERT_EQ(true, merge);
}
TEST(ObMultiVersionSortedStores, get_minor_store_merged)
{
int ret = OB_SUCCESS;
ObMultiVersionSortedStores stores;
ObStoresHandle stores_handle;
ObPartitionComponentFactory cp_fty;
ObSSStore *ss_store = NULL;
ObIMemtable *mem_store = NULL;
ObIStore *store = NULL;
bool merge;
ASSERT_EQ(OB_SUCCESS, stores.init(&cp_fty));
// ssstore + minor merged sstore(major frozen memstore) + minor frozen memstore * 2 + active memstore
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(1, 0));
ret = stores.add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(2, 0));
ret = stores.add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(3, 0));
mem_store->minor_freeze(ObVersion(3, 0));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(3, 1));
mem_store->minor_freeze(ObVersion(3, 1));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(3, 2));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = stores.get_minor_merge_stores(stores_handle, merge);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(2, stores_handle.get_stores_count());
ASSERT_EQ(OB_SUCCESS, stores_handle.get_last_store(store));
ASSERT_TRUE(NULL != store);
ASSERT_EQ(ObVersion(3, 1), store->get_version());
ASSERT_EQ(false, merge);
}
TEST(ObMultiVersionSortedStores, get_minor_store_not_across_memstore)
{
int ret = OB_SUCCESS;
ObMultiVersionSortedStores stores;
ObStoresHandle stores_handle;
ObPartitionComponentFactory cp_fty;
ObSSStore *ss_store = NULL;
ObIMemtable *mem_store = NULL;
bool merge;
ASSERT_EQ(OB_SUCCESS, stores.init(&cp_fty));
// ssstore + minor merged sstore + major frozen memstore + minor frozen memstore + active memstore
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(1, 0));
ret = stores.add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(2, 0));
ret = stores.add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(3, 0));
ret = stores.add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(3, 1));
mem_store->major_freeze(ObVersion(3, 1));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(4, 0));
mem_store->minor_freeze(ObVersion(4, 0));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(4, 1));
mem_store->minor_freeze(ObVersion(4, 1));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = stores.get_minor_merge_stores(stores_handle, merge);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(0, stores_handle.get_stores_count());
ASSERT_EQ(false, merge);
}
TEST(ObMultiVersionSortedStores, prewarm_major_merge)
{
int ret = OB_SUCCESS;
ObMultiVersionSortedStores stores;
ObStoresHandle stores_handle;
ObSortedStores *new_stores = NULL;
ObPartitionComponentFactory cp_fty;
ObSSStore *ss_store = NULL;
ObIMemtable *mem_store = NULL;
ASSERT_EQ(OB_SUCCESS, stores.init(&cp_fty));
ASSERT_TRUE(NULL != (new_stores = cp_fty.get_sorted_stores()));
ASSERT_EQ(OB_SUCCESS, new_stores->init(&cp_fty));
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(1, 0));
ret = stores.add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(2, 0));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(2, 0));
ret = new_stores->add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(3, 0));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = new_stores->add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores.tail_ - stores.head_);
ret = stores.get_all_version_ssstores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores_handle.get_stores_count());
ret = stores.update(new_stores, MAJOR_MERGE);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores.tail_ - stores.head_);
ret = stores.get_all_version_ssstores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(2, stores_handle.get_stores_count());
}
TEST(ObMultiVersionSortedStores, prewarm_minor_merge)
{
int ret = OB_SUCCESS;
ObMultiVersionSortedStores stores;
ObStoresHandle stores_handle;
ObSortedStores *new_stores = NULL;
ObSortedStores *new_stores2 = NULL;
ObPartitionComponentFactory cp_fty;
ObSSStore *ss_store = NULL;
ObIMemtable *mem_store = NULL;
ASSERT_EQ(OB_SUCCESS, stores.init(&cp_fty));
ASSERT_TRUE(NULL != (new_stores = cp_fty.get_sorted_stores()));
ASSERT_EQ(OB_SUCCESS, new_stores->init(&cp_fty));
ASSERT_TRUE(NULL != (new_stores2 = cp_fty.get_sorted_stores()));
ASSERT_EQ(OB_SUCCESS, new_stores2->init(&cp_fty));
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(1, 0));
ret = stores.add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = new_stores->add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = new_stores2->add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(2, 0));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(2, 0));
ret = new_stores->add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(2, 1));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = new_stores->add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores.tail_ - stores.head_);
ret = stores.get_all_version_ssstores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores_handle.get_stores_count());
ret = stores.update(new_stores, MINOR_MERGE);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(2, stores.tail_ - stores.head_);
ret = stores.get_all_version_ssstores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(2, stores_handle.get_stores_count());
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(2, 1));
ret = new_stores2->add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(2, 2));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = new_stores2->add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = stores.update(new_stores2, MINOR_MERGE);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(2, stores.tail_ - stores.head_);
ret = stores.get_all_version_ssstores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(3, stores_handle.get_stores_count());
}
TEST(ObMultiVersionSortedStores, prewarm_major_minor_merge)
{
int ret = OB_SUCCESS;
ObMultiVersionSortedStores stores;
ObStoresHandle stores_handle;
ObSortedStores *new_stores = NULL;
ObSortedStores *new_stores2 = NULL;
ObPartitionComponentFactory cp_fty;
ObSSStore *ss_store = NULL;
ObIMemtable *mem_store = NULL;
ASSERT_EQ(OB_SUCCESS, stores.init(&cp_fty));
ASSERT_TRUE(NULL != (new_stores = cp_fty.get_sorted_stores()));
ASSERT_EQ(OB_SUCCESS, new_stores->init(&cp_fty));
ASSERT_TRUE(NULL != (new_stores2 = cp_fty.get_sorted_stores()));
ASSERT_EQ(OB_SUCCESS, new_stores2->init(&cp_fty));
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(1, 0));
ret = stores.add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = new_stores->add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = new_stores2->add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(2, 0));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(2, 0));
ret = new_stores->add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = new_stores2->add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(2, 1));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = new_stores->add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = new_stores2->add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores.tail_ - stores.head_);
ret = stores.get_all_version_ssstores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(1, stores_handle.get_stores_count());
ret = stores.update(new_stores, MINOR_MERGE);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(2, stores.tail_ - stores.head_);
ret = stores.get_all_version_ssstores(stores_handle);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(2, stores_handle.get_stores_count());
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(3, 0));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ss_store = cp_fty.get_ssstore(OB_SERVER_TENANT_ID);
ASSERT_TRUE(NULL != ss_store);
ss_store->set_version(ObVersion(3, 0));
ret = new_stores2->add_store(ss_store);
ASSERT_EQ(OB_SUCCESS, ret);
mem_store = cp_fty.get_memtable(500);
ASSERT_TRUE(NULL != mem_store);
mem_store->set_version(ObVersion(3, 1));
ret = stores.add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = new_stores2->add_store(mem_store);
ASSERT_EQ(OB_SUCCESS, ret);
ret = stores.update(new_stores2, MINOR_MERGE);
ASSERT_EQ(OB_SUCCESS, ret);
ASSERT_EQ(3, stores.tail_ - stores.head_);
}
}
}
int main(int argc, char **argv)
{
OB_LOGGER.set_log_level("INFO");
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -18,7 +18,6 @@
#include "lib/container/ob_array_array.h"
#include "storage/compaction/ob_partition_merger.h"
#include "storage/memtable/ob_memtable_interface.h"
#include "storage/ob_partition_component_factory.h"
#include "blocksstable/ob_data_file_prepare.h"
#include "blocksstable/ob_row_generate.h"
#include "observer/ob_service.h"

View File

@ -78,8 +78,8 @@ TEST_F(TestTabletMemtableMgr, tablet_memtable_mgr) {
ASSERT_EQ(0, pool->count_);
// create memtable
ASSERT_EQ(OB_SUCCESS, tablet_handle.get_obj()->create_memtable(1, scn1));
ASSERT_EQ(OB_SUCCESS, tablet_handle.get_obj()->create_memtable(2, scn2));
ASSERT_EQ(OB_SUCCESS, tablet_handle.get_obj()->create_memtable(1, scn1, false, false));
ASSERT_EQ(OB_SUCCESS, tablet_handle.get_obj()->create_memtable(2, scn2, false, false));
ObSEArray<ObTableHandleV2, 64> handles;
ASSERT_EQ(OB_SUCCESS, tablet_handle.get_obj()->get_all_memtables(handles));
@ -106,7 +106,7 @@ TEST_F(TestTabletMemtableMgr, tablet_memtable_mgr) {
// remove memtable mgr reference from memtable
ASSERT_EQ(1, handles.count());
for (int i = 0; i < handles.count(); i++) {
memtable::ObIMemtable *i_mt = nullptr;
ObIMemtable *i_mt = nullptr;
EXPECT_EQ(OB_SUCCESS, handles[i].get_memtable(i_mt));
memtable::ObMemtable *mt = (memtable::ObMemtable *)(i_mt);
mt->memtable_mgr_handle_.reset();

View File

@ -129,7 +129,6 @@ ObTxNode::ObTxNode(const int64_t ls_id,
lock_memtable_handle.set_table(&lock_memtable_, &t3m_, ObITable::LOCK_MEMTABLE);
lock_memtable_.key_.table_type_ = ObITable::LOCK_MEMTABLE;
fake_ls_.ls_tablet_svr_.lock_memtable_mgr_.t3m_ = &t3m_;
fake_ls_.ls_tablet_svr_.lock_memtable_mgr_.table_type_ = ObITable::TableType::LOCK_MEMTABLE;
fake_ls_.ls_tablet_svr_.lock_memtable_mgr_.add_memtable_(lock_memtable_handle);
fake_lock_table_.is_inited_ = true;
fake_lock_table_.parent_ = &fake_ls_;

View File

@ -201,9 +201,7 @@ int64_t TestTxCtxTable::ref_count_;
TEST_F(TestTxCtxTable, test_tx_ctx_memtable_mgr)
{
EXPECT_EQ(0, TestTxCtxTable::ref_count_);
EXPECT_EQ(OB_SUCCESS, mt_mgr_->create_memtable(SCN::min_scn(), /*last_replay_log_ts*/
0 /*schema_version*/,
SCN::min_scn()));
EXPECT_EQ(OB_SUCCESS, mt_mgr_->create_memtable(CreateMemtableArg(0, SCN::min_scn(), SCN::min_scn(), false, false)));
EXPECT_EQ(1, TestTxCtxTable::ref_count_);