[CP] reset macro info after writing linked block

This commit is contained in:
obdev 2023-12-07 11:17:19 +00:00 committed by ob-robot
parent a084a7ae38
commit 655c8c0790
8 changed files with 177 additions and 97 deletions

View File

@ -128,10 +128,6 @@ TEST_F(TestBlockIdList, test_id_list)
ASSERT_EQ(OB_SUCCESS, init_info_set(allocator, TEST_LINKED_NUM, info_set));
ASSERT_EQ(OB_SUCCESS, macro_info.init(allocator, info_set, linked_writer));
ASSERT_EQ(false, IS_EMPTY_BLOCK_LIST(macro_info.entry_block_));
ASSERT_EQ(TEST_LINKED_NUM, macro_info.shared_data_block_info_arr_.cnt_);
ASSERT_EQ(TEST_LINKED_NUM, macro_info.shared_meta_block_info_arr_.cnt_);
ASSERT_EQ(TEST_LINKED_NUM, macro_info.data_block_info_arr_.cnt_);
ASSERT_EQ(TEST_LINKED_NUM, macro_info.meta_block_info_arr_.cnt_);
meta_block_arr.reset();
data_block_arr.reset();
shared_meta_block_arr.reset();
@ -179,6 +175,92 @@ TEST_F(TestBlockIdList, test_id_list)
ASSERT_EQ(linked_ref_cnt + 2, block_info.ref_cnt_);
}
TEST_F(TestBlockIdList, test_serialize_deep_copy)
{
ObArenaAllocator allocator;
ObLinkedMacroBlockItemWriter linked_writer;
// linked macro info without meta_block_id and shared_meta_block_id
linked_writer.reset();
ObBlockInfoSet info_set;
ObTabletMacroInfo macro_info;
ASSERT_EQ(OB_SUCCESS, info_set.init());
for (int64_t i = 0; i < ObTabletMacroInfo::ID_COUNT_THRESHOLD; i++) {
MacroBlockId tmp_macro_id(i + 1, i + 1, 0);
ASSERT_EQ(OB_SUCCESS, info_set.data_block_info_set_.set_refactored(tmp_macro_id));
ASSERT_EQ(OB_SUCCESS, info_set.shared_data_block_info_map_.set_refactored(tmp_macro_id, i + 5));
}
ASSERT_EQ(OB_SUCCESS, macro_info.init(allocator, info_set, linked_writer));
ASSERT_EQ(0, macro_info.data_block_info_arr_.cnt_);
ASSERT_EQ(0, macro_info.shared_data_block_info_arr_.cnt_);
ASSERT_EQ(0, macro_info.shared_meta_block_info_arr_.cnt_);
ASSERT_EQ(0, macro_info.meta_block_info_arr_.cnt_);
int64_t serialize_size = macro_info.get_serialize_size();
char *buf = (char *)allocator.alloc(serialize_size);
int64_t pos = 0;
ASSERT_EQ(OB_SUCCESS, macro_info.serialize(buf, serialize_size, pos));
ObTabletMacroInfo deserialize_info;
pos = 0;
ASSERT_EQ(OB_SUCCESS, deserialize_info.deserialize(allocator, buf, serialize_size, pos));
ASSERT_EQ(deserialize_info.entry_block_, macro_info.entry_block_);
ASSERT_EQ(0, deserialize_info.data_block_info_arr_.cnt_);
ASSERT_EQ(0, deserialize_info.shared_data_block_info_arr_.cnt_);
ASSERT_EQ(0, deserialize_info.shared_meta_block_info_arr_.cnt_);
ASSERT_EQ(0, deserialize_info.meta_block_info_arr_.cnt_);
int64_t deep_copy_size = macro_info.get_deep_copy_size();
buf = (char *)allocator.alloc(deep_copy_size);
ObTabletMacroInfo *deep_copy_info = nullptr;
ASSERT_EQ(OB_SUCCESS, macro_info.deep_copy(buf, deep_copy_size, deep_copy_info));
ASSERT_EQ(deep_copy_info->entry_block_, macro_info.entry_block_);
ASSERT_EQ(0, deep_copy_info->data_block_info_arr_.cnt_);
ASSERT_EQ(0, deep_copy_info->shared_data_block_info_arr_.cnt_);
ASSERT_EQ(0, deep_copy_info->shared_meta_block_info_arr_.cnt_);
ASSERT_EQ(0, deep_copy_info->meta_block_info_arr_.cnt_);
// memory macro info without meta_block_id and shared_meta_block_id
linked_writer.reset();
ObBlockInfoSet info_set_2;
ObTabletMacroInfo macro_info_2;
static const int64_t MEMORY_ID_CNT = 100;
ASSERT_EQ(OB_SUCCESS, info_set_2.init());
for (int64_t i = 0; i < MEMORY_ID_CNT; i++) {
MacroBlockId tmp_macro_id(i + 1, i + 1, 0);
ASSERT_EQ(OB_SUCCESS, info_set_2.data_block_info_set_.set_refactored(tmp_macro_id));
ASSERT_EQ(OB_SUCCESS, info_set_2.shared_data_block_info_map_.set_refactored(tmp_macro_id, i + 5));
}
ASSERT_EQ(OB_SUCCESS, macro_info_2.init(allocator, info_set_2, linked_writer));
ASSERT_EQ(true, IS_EMPTY_BLOCK_LIST(macro_info_2.entry_block_));
ASSERT_EQ(MEMORY_ID_CNT, macro_info_2.data_block_info_arr_.cnt_);
ASSERT_EQ(MEMORY_ID_CNT, macro_info_2.shared_data_block_info_arr_.cnt_);
ASSERT_EQ(0, macro_info_2.shared_meta_block_info_arr_.cnt_);
ASSERT_EQ(0, macro_info_2.meta_block_info_arr_.cnt_);
serialize_size = macro_info_2.get_serialize_size();
buf = (char *)allocator.alloc(serialize_size);
pos = 0;
ASSERT_EQ(OB_SUCCESS, macro_info_2.serialize(buf, serialize_size, pos));
deserialize_info.reset();
pos = 0;
ASSERT_EQ(OB_SUCCESS, deserialize_info.deserialize(allocator, buf, serialize_size, pos));
ASSERT_EQ(true, IS_EMPTY_BLOCK_LIST(deserialize_info.entry_block_));
ASSERT_EQ(MEMORY_ID_CNT, deserialize_info.data_block_info_arr_.cnt_);
ASSERT_EQ(MEMORY_ID_CNT, deserialize_info.shared_data_block_info_arr_.cnt_);
ASSERT_EQ(0, deserialize_info.shared_meta_block_info_arr_.cnt_);
ASSERT_EQ(0, deserialize_info.meta_block_info_arr_.cnt_);
deep_copy_size = macro_info_2.get_deep_copy_size();
buf = (char *)allocator.alloc(deep_copy_size);
deep_copy_info = nullptr;
ASSERT_EQ(OB_SUCCESS, macro_info_2.deep_copy(buf, deep_copy_size, deep_copy_info));
ASSERT_EQ(deep_copy_info->entry_block_, macro_info_2.entry_block_);
ASSERT_EQ(MEMORY_ID_CNT, deep_copy_info->data_block_info_arr_.cnt_);
ASSERT_EQ(MEMORY_ID_CNT, deep_copy_info->shared_data_block_info_arr_.cnt_);
ASSERT_EQ(0, deep_copy_info->shared_meta_block_info_arr_.cnt_);
ASSERT_EQ(0, deep_copy_info->meta_block_info_arr_.cnt_);
}
TEST_F(TestBlockIdList, test_meta_macro_ref_cnt)
{
ObTabletID tablet_id(TestIndexBlockDataPrepare::tablet_id_);

View File

@ -709,11 +709,12 @@ TEST_F(TestTenantMetaMemMgr, test_wash_tablet)
ASSERT_EQ(common::OB_SUCCESS, ret);
ASSERT_EQ(1, tablet->get_ref());
ObTabletPersister persister;
ObSArray<MacroBlockId> shared_meta_id_arr;
ObTabletHandle new_handle;
ASSERT_EQ(common::OB_SUCCESS, t3m_.acquire_tablet_from_pool(ObTabletPoolType::TP_NORMAL, WashTabletPriority::WTP_HIGH, key, new_handle));
ASSERT_EQ(common::OB_SUCCESS, persister.persist_and_fill_tablet(
*tablet, linked_writer, total_write_ctxs, new_handle, space_usage, tablet_macro_info));
*tablet, linked_writer, total_write_ctxs, new_handle, space_usage, tablet_macro_info, shared_meta_id_arr));
ASSERT_EQ(common::OB_SUCCESS, persister.persist_aggregated_meta(tablet_macro_info, new_handle, space_usage));
ObMetaDiskAddr addr = new_handle.get_obj()->get_tablet_addr();
@ -805,9 +806,10 @@ TEST_F(TestTenantMetaMemMgr, test_wash_inner_tablet)
ObTabletHandle new_handle;
ObTabletPersister persister;
ObSArray<MacroBlockId> shared_meta_id_arr;
ASSERT_EQ(common::OB_SUCCESS, t3m_.acquire_tablet_from_pool(ObTabletPoolType::TP_NORMAL, WashTabletPriority::WTP_HIGH, key, new_handle));
ASSERT_EQ(common::OB_SUCCESS, persister.persist_and_fill_tablet(
*tablet, linked_writer, total_write_ctxs, new_handle, space_usage, tablet_macro_info));
*tablet, linked_writer, total_write_ctxs, new_handle, space_usage, tablet_macro_info, shared_meta_id_arr));
ASSERT_EQ(common::OB_SUCCESS, persister.persist_aggregated_meta(tablet_macro_info, new_handle, space_usage));
ObMetaDiskAddr addr = new_handle.get_obj()->get_tablet_addr();
@ -911,9 +913,10 @@ TEST_F(TestTenantMetaMemMgr, test_wash_no_sstable_tablet)
ObTabletHandle new_handle;
ObTabletPersister persister;
ObSArray<MacroBlockId> shared_meta_id_arr;
ASSERT_EQ(common::OB_SUCCESS, t3m_.acquire_tablet_from_pool(ObTabletPoolType::TP_NORMAL, WashTabletPriority::WTP_HIGH, key, new_handle));
ASSERT_EQ(common::OB_SUCCESS, persister.persist_and_fill_tablet(
*tablet, linked_writer, total_write_ctxs, new_handle, space_usage, tablet_macro_info));
*tablet, linked_writer, total_write_ctxs, new_handle, space_usage, tablet_macro_info, shared_meta_id_arr));
ASSERT_EQ(common::OB_SUCCESS, persister.persist_aggregated_meta(tablet_macro_info, new_handle, space_usage));
ret = t3m_.compare_and_swap_tablet(key, new_handle, new_handle);
@ -1003,9 +1006,10 @@ TEST_F(TestTenantMetaMemMgr, test_get_tablet_with_allocator)
ObTabletHandle new_handle;
ObTabletPersister persister;
ObSArray<MacroBlockId> shared_meta_id_arr;
ASSERT_EQ(common::OB_SUCCESS, t3m_.acquire_tablet_from_pool(ObTabletPoolType::TP_NORMAL, WashTabletPriority::WTP_HIGH, key, new_handle));
ASSERT_EQ(common::OB_SUCCESS, persister.persist_and_fill_tablet(
*tablet, linked_writer, total_write_ctxs, new_handle, space_usage, tablet_macro_info));
*tablet, linked_writer, total_write_ctxs, new_handle, space_usage, tablet_macro_info, shared_meta_id_arr));
ASSERT_EQ(common::OB_SUCCESS, persister.persist_aggregated_meta(tablet_macro_info, new_handle, space_usage));
ret = t3m_.compare_and_swap_tablet(key, new_handle, new_handle);

View File

@ -2324,7 +2324,7 @@ int ObTablet::inc_macro_ref_with_macro_info(const ObTabletMacroInfo &tablet_macr
K(auto_inc_seq_addr.addr_), K(storage_schema_addr_.addr_), K(medium_info_list_addr.addr_),
K(tablet_status_uncommitted_kv_addr.addr_), K(tablet_status_committed_kv_addr.addr_),
K(aux_tablet_info_uncommitted_kv_addr.addr_), K(aux_tablet_info_committed_kv_addr.addr_),
K(tablet_addr_), KP(this), K(lbt()));
K(tablet_addr_), KP(this), K(tablet_macro_info), K(lbt()));
return ret;
}
@ -2361,7 +2361,7 @@ int ObTablet::inner_inc_macro_ref_cnt()
K(auto_inc_seq_addr.addr_), K(storage_schema_addr_.addr_), K(medium_info_list_addr.addr_),
K(tablet_status_uncommitted_kv_addr.addr_), K(tablet_status_committed_kv_addr.addr_),
K(aux_tablet_info_uncommitted_kv_addr.addr_), K(aux_tablet_info_committed_kv_addr.addr_),
K(tablet_addr_), KP(this), K(lbt()));
K(tablet_addr_), KP(this), KPC(macro_info_addr_.ptr_), K(lbt()));
return ret;
}
@ -2441,12 +2441,6 @@ int ObTablet::inc_ref_without_aggregated_info()
} else if (OB_FAIL(inc_table_store_ref_cnt(inc_table_store_member_ref))) {
LOG_WARN("fail to increase macro blocks' ref cnt for sstable meta", K(ret));
}
FLOG_INFO("the tablet that inner increases ref cnt is", K(ret),
K(is_inited_), K(tablet_meta_.ls_id_), K(tablet_meta_.tablet_id_), K(table_store_addr_.addr_),
K(auto_inc_seq_addr.addr_), K(storage_schema_addr_.addr_), K(medium_info_list_addr.addr_),
K(tablet_status_uncommitted_kv_addr.addr_), K(tablet_status_committed_kv_addr.addr_),
K(aux_tablet_info_uncommitted_kv_addr.addr_), K(aux_tablet_info_committed_kv_addr.addr_),
K(tablet_addr_), KP(this), K(lbt()));
if (OB_FAIL(ret)) {
if (inc_medium_info_list_ref) {
@ -2515,7 +2509,7 @@ void ObTablet::dec_macro_ref_cnt()
K(auto_inc_seq_addr.addr_), K(storage_schema_addr_.addr_), K(medium_info_list_addr.addr_),
K(tablet_status_uncommitted_kv_addr.addr_), K(tablet_status_committed_kv_addr.addr_),
K(aux_tablet_info_uncommitted_kv_addr.addr_), K(aux_tablet_info_committed_kv_addr.addr_),
K(tablet_addr_), KP(this), K(lbt()));
K(tablet_addr_), KP(this), KPC(macro_info_addr_.ptr_), K(lbt()));
}
void ObTablet::dec_ref_without_aggregated_info()

View File

@ -88,7 +88,7 @@ int ObBlockInfoSet::init(
*/
template <typename T>
ObBlockInfoArray<T>::ObBlockInfoArray()
: cnt_(0), arr_(nullptr), capacity_(0), is_inited_(false)
: cnt_(0), arr_(nullptr), capacity_(0)
{
}
@ -104,17 +104,13 @@ void ObBlockInfoArray<T>::reset()
cnt_ = 0;
capacity_ = 0;
arr_ = nullptr;
is_inited_ = false;
}
template <typename T>
int ObBlockInfoArray<T>::init(const int64_t cnt, ObArenaAllocator &allocator)
int ObBlockInfoArray<T>::reserve(const int64_t cnt, ObArenaAllocator &allocator)
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(is_inited_)) {
ret = OB_INIT_TWICE;
LOG_WARN("ObBlockInfoArray has been inited", K(ret));
} else if (0 == cnt) {
if (0 == cnt) {
// no macro id
arr_ = nullptr;
} else if (OB_ISNULL(arr_ = reinterpret_cast<T *>(allocator.alloc(sizeof(T) * cnt)))) {
@ -124,7 +120,6 @@ int ObBlockInfoArray<T>::init(const int64_t cnt, ObArenaAllocator &allocator)
if (OB_SUCC(ret)) {
cnt_ = cnt;
capacity_ = cnt;
is_inited_ = true;
}
return ret;
}
@ -133,10 +128,7 @@ template <typename T>
int ObBlockInfoArray<T>::serialize(char *buf, const int64_t buf_len, int64_t &pos) const
{
int ret = OB_SUCCESS;
if (IS_NOT_INIT) {
ret = OB_NOT_INIT;
LOG_WARN("ObBlockInfoArray hasn't been inited", K(ret));
} else if (OB_ISNULL(buf) || OB_UNLIKELY(buf_len <= 0 || pos < 0)) {
if (OB_ISNULL(buf) || OB_UNLIKELY(buf_len <= 0 || pos < 0)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid arguments", K(ret), KP(buf), K(buf_len), K(pos));
} else if (OB_FAIL(serialization::encode_i64(buf, buf_len, pos, cnt_))) {
@ -157,16 +149,14 @@ template <typename T>
int ObBlockInfoArray<T>::deserialize(ObArenaAllocator &allocator, const char *buf, const int64_t data_len, int64_t &pos)
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(is_inited_)) {
ret = OB_INIT_TWICE;
LOG_WARN("ObBlockInfoArray has been inited", K(ret));
} else if (OB_ISNULL(buf) || OB_UNLIKELY(pos < 0 || data_len <= 0)) {
if (OB_ISNULL(buf) || OB_UNLIKELY(pos < 0 || data_len <= 0)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid arguments", K(ret), KP(buf), K(data_len), K(pos));
} else if (OB_FAIL(serialization::decode_i64(buf, data_len, pos, &cnt_))) {
LOG_WARN("fail to decode count", K(ret), K(data_len), K(pos));
} else if (0 == cnt_) {
// no macro id
arr_ = nullptr;
} else if (OB_UNLIKELY(cnt_ < 0)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("array count shouldn't be less than 0", K(ret), K_(cnt));
@ -187,7 +177,6 @@ int ObBlockInfoArray<T>::deserialize(ObArenaAllocator &allocator, const char *bu
allocator.free(arr_);
reset();
} else if (OB_SUCC(ret)) {
is_inited_ = true;
capacity_ = cnt_;
}
return ret;
@ -211,10 +200,7 @@ int ObBlockInfoArray<T>::deep_copy(char *buf, const int64_t buf_len, int64_t &po
{
int ret = OB_SUCCESS;
const int64_t memory_size = get_deep_copy_size();
if (IS_NOT_INIT) {
ret = OB_NOT_INIT;
LOG_WARN("ObBlockInfoArray hasn't been inited", K(ret));
} else if (OB_ISNULL(buf) || OB_UNLIKELY(buf_len <= 0 || pos < 0 || buf_len - pos < memory_size)) {
if (OB_ISNULL(buf) || OB_UNLIKELY(buf_len <= 0 || pos < 0 || buf_len - pos < memory_size)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", K(ret), KP(buf), K(buf_len), K(pos), K(memory_size));
} else if (OB_NOT_NULL(arr_) && 0 != cnt_) {
@ -227,7 +213,6 @@ int ObBlockInfoArray<T>::deep_copy(char *buf, const int64_t buf_len, int64_t &po
dest_obj.cnt_ = cnt_;
dest_obj.capacity_ = capacity_;
pos += memory_size;
dest_obj.is_inited_ = is_inited_;
}
return ret;
}
@ -259,15 +244,15 @@ void ObTabletMacroInfo::reset()
int ObTabletMacroInfo::init(
ObArenaAllocator &allocator,
ObBlockInfoSet &info_set,
const ObBlockInfoSet &info_set,
ObLinkedMacroBlockItemWriter &linked_writer)
{
int ret = OB_SUCCESS;
ObBlockInfoSet::TabletMacroSet &meta_block_info_set = info_set.meta_block_info_set_;
ObBlockInfoSet::TabletMacroSet &data_block_info_set = info_set.data_block_info_set_;
ObBlockInfoSet::TabletMacroSet &shared_meta_block_info_set = info_set.shared_meta_block_info_set_;
ObBlockInfoSet::TabletMacroMap &shared_data_block_info_map = info_set.shared_data_block_info_map_;
int64_t total_macro_cnt = meta_block_info_set.size()
const ObBlockInfoSet::TabletMacroSet &meta_block_info_set = info_set.meta_block_info_set_;
const ObBlockInfoSet::TabletMacroSet &data_block_info_set = info_set.data_block_info_set_;
const ObBlockInfoSet::TabletMacroSet &shared_meta_block_info_set = info_set.shared_meta_block_info_set_;
const ObBlockInfoSet::TabletMacroMap &shared_data_block_info_map = info_set.shared_data_block_info_map_;
const int64_t total_macro_cnt = meta_block_info_set.size()
+ data_block_info_set.size()
+ shared_meta_block_info_set.size()
+ shared_data_block_info_map.size();
@ -275,13 +260,13 @@ int ObTabletMacroInfo::init(
if (OB_UNLIKELY(is_inited_)) {
ret = OB_INIT_TWICE;
LOG_WARN("ObTabletMacroInfo has been inited", K(ret));
} else if (OB_FAIL(meta_block_info_arr_.init(meta_block_info_set.size(), allocator))) {
} else if (OB_FAIL(meta_block_info_arr_.reserve(meta_block_info_set.size(), allocator))) {
LOG_WARN("fail to init meta block id arr", K(ret));
} else if (OB_FAIL(data_block_info_arr_.init(data_block_info_set.size(), allocator))) {
} else if (OB_FAIL(data_block_info_arr_.reserve(data_block_info_set.size(), allocator))) {
LOG_WARN("fail to init data block id arr", K(ret));
} else if (OB_FAIL(shared_meta_block_info_arr_.init(shared_meta_block_info_set.size(), allocator))) {
} else if (OB_FAIL(shared_meta_block_info_arr_.reserve(shared_meta_block_info_set.size(), allocator))) {
LOG_WARN("fail to init shared meta block info arr", K(ret));
} else if (OB_FAIL(shared_data_block_info_arr_.init(shared_data_block_info_map.size(), allocator))) {
} else if (OB_FAIL(shared_data_block_info_arr_.reserve(shared_data_block_info_map.size(), allocator))) {
LOG_WARN("fail to init shared data block info arr", K(ret));
} else if (OB_FAIL(construct_block_id_arr(meta_block_info_set, meta_block_info_arr_))) {
LOG_WARN("fail to construct meta block id arr", K(ret));
@ -303,7 +288,7 @@ int ObTabletMacroInfo::init(
}
int ObTabletMacroInfo::construct_block_id_arr(
ObBlockInfoSet::TabletMacroSet &id_set,
const ObBlockInfoSet::TabletMacroSet &id_set,
ObBlockInfoArray<MacroBlockId> &block_id_arr)
{
int ret = OB_SUCCESS;
@ -322,7 +307,7 @@ int ObTabletMacroInfo::construct_block_id_arr(
}
int ObTabletMacroInfo::construct_block_info_arr(
ObBlockInfoSet::TabletMacroMap &block_info_map,
const ObBlockInfoSet::TabletMacroMap &block_info_map,
ObBlockInfoArray<ObSharedBlockInfo> &block_info_arr)
{
int ret = OB_SUCCESS;
@ -360,6 +345,11 @@ int ObTabletMacroInfo::persist_macro_ids(
LOG_WARN("fail to close linked writer", K(ret));
} else if (OB_FAIL(linked_writer.get_entry_block(entry_block_))) {
LOG_WARN("fail to get entry block", K(ret));
} else {
meta_block_info_arr_.reset();
data_block_info_arr_.reset();
shared_meta_block_info_arr_.reset();
shared_data_block_info_arr_.reset();
}
return ret;
}
@ -564,13 +554,13 @@ int ObTabletMacroInfo::deep_copy(char *buf, const int64_t buf_len, ObTabletMacro
}
} else {
ObArenaAllocator dummy_allocator;
if (OB_FAIL(tablet_macro_info->meta_block_info_arr_.init(0, dummy_allocator))) {
if (OB_FAIL(tablet_macro_info->meta_block_info_arr_.reserve(0, dummy_allocator))) {
LOG_WARN("fail to init empty meta block info arr", K(ret));
} else if (OB_FAIL(tablet_macro_info->data_block_info_arr_.init(0, dummy_allocator))) {
} else if (OB_FAIL(tablet_macro_info->data_block_info_arr_.reserve(0, dummy_allocator))) {
LOG_WARN("fail to init empty data block info arr", K(ret));
} else if (OB_FAIL(tablet_macro_info->shared_meta_block_info_arr_.init(0, dummy_allocator))) {
} else if (OB_FAIL(tablet_macro_info->shared_meta_block_info_arr_.reserve(0, dummy_allocator))) {
LOG_WARN("fail to init empty shared meta block info arr", K(ret));
} else if (OB_FAIL(tablet_macro_info->shared_data_block_info_arr_.init(0, dummy_allocator))) {
} else if (OB_FAIL(tablet_macro_info->shared_data_block_info_arr_.reserve(0, dummy_allocator))) {
LOG_WARN("fail to init empty shared data block info arr", K(ret));
}
}
@ -801,25 +791,26 @@ void ObTabletMacroInfo::dec_macro_ref_with_io() const
block_reader.reset();
if (OB_FAIL(block_reader.init(entry_block_))) {
LOG_WARN("fail to init linked block item reader", K(ret), K(entry_block_));
} else if (OB_FAIL(block_reader.get_next_item(meta_id_buf, meta_id_len, addr))) {
LOG_WARN("fail to get next item", K(ret));
} else if (OB_FAIL(block_reader.get_next_item(data_id_buf, data_id_len, addr))) {
LOG_WARN("fail to get next item", K(ret));
} else if (OB_FAIL(block_reader.get_next_item(shared_meta_id_buf, shared_meta_id_len, addr))) {
LOG_WARN("fail to get next item", K(ret));
} else if (OB_FAIL(block_reader.get_next_item(shared_data_info_buf, shared_data_info_len, addr))) {
LOG_WARN("fail to get next item", K(ret));
}
} while(ignore_ret(ret));
if (OB_FAIL(ret)) {
LOG_ERROR("fail to read macro id from disk, macro blocks may leak", K(ret));
} else {
deserialize_and_dec_macro_ref(meta_id_buf, meta_id_len);
deserialize_and_dec_macro_ref(data_id_buf, data_id_len);
deserialize_and_dec_macro_ref(shared_meta_id_buf, shared_meta_id_len);
deserialize_and_dec_shared_macro_ref(shared_data_info_buf, shared_data_info_len);
dec_linked_block_ref_cnt(block_reader.get_meta_block_list());
}
} while (ignore_ret(ret));
}
if (OB_FAIL(ret)) {
// do nothing
} else if (OB_FAIL(block_reader.get_next_item(meta_id_buf, meta_id_len, addr))) {
LOG_WARN("fail to get next item", K(ret));
} else if (FALSE_IT(deserialize_and_dec_macro_ref(meta_id_buf, meta_id_len))) {
} else if (OB_FAIL(block_reader.get_next_item(data_id_buf, data_id_len, addr))) {
LOG_WARN("fail to get next item", K(ret));
} else if (FALSE_IT(deserialize_and_dec_macro_ref(data_id_buf, data_id_len))) {
} else if (OB_FAIL(block_reader.get_next_item(shared_meta_id_buf, shared_meta_id_len, addr))) {
LOG_WARN("fail to get next item", K(ret));
} else if (FALSE_IT(deserialize_and_dec_macro_ref(shared_meta_id_buf, shared_meta_id_len))) {
} else if (OB_FAIL(block_reader.get_next_item(shared_data_info_buf, shared_data_info_len, addr))) {
LOG_WARN("fail to get next item", K(ret));
} else {
deserialize_and_dec_shared_macro_ref(shared_data_info_buf, shared_data_info_len);
dec_linked_block_ref_cnt(block_reader.get_meta_block_list());
}
}

View File

@ -95,8 +95,8 @@ public:
common::hash::NormalPointer,
oceanbase::common::ObMalloc,
MAP_EXTEND_RATIO> TabletMacroMap;
typedef typename TabletMacroSet::iterator SetIterator;
typedef typename TabletMacroMap::iterator MapIterator;
typedef typename TabletMacroSet::const_iterator SetIterator;
typedef typename TabletMacroMap::const_iterator MapIterator;
public:
ObBlockInfoSet()
: meta_block_info_set_(), data_block_info_set_(), shared_meta_block_info_set_(), shared_data_block_info_map_()
@ -129,7 +129,7 @@ public:
ObBlockInfoArray();
~ObBlockInfoArray();
void reset();
int init(const int64_t cnt, ObArenaAllocator &allocator);
int reserve(const int64_t cnt, ObArenaAllocator &allocator);
int serialize(char *buf, const int64_t buf_len, int64_t &pos) const;
int deserialize(ObArenaAllocator &allocator, const char *buf, const int64_t data_len, int64_t &pos);
int64_t get_serialize_size() const;
@ -139,15 +139,14 @@ public:
{
return (0 == cnt_ && nullptr == arr_) || (0 < cnt_ && nullptr != arr_);
}
TO_STRING_KV(K_(cnt), KP_(arr), K_(capacity), K_(is_inited));
TO_STRING_KV(K_(cnt), KP_(arr), K_(capacity));
public:
int64_t cnt_;
T *arr_;
// no need to be persisted
// no need to be persisted and only used by iterator
int64_t capacity_;
bool is_inited_;
};
class ObTabletMacroInfo final
@ -156,7 +155,7 @@ public:
ObTabletMacroInfo();
~ObTabletMacroInfo();
void reset();
int init(ObArenaAllocator &allocator, ObBlockInfoSet &id_set, ObLinkedMacroBlockItemWriter &linked_writer);
int init(ObArenaAllocator &allocator, const ObBlockInfoSet &id_set, ObLinkedMacroBlockItemWriter &linked_writer);
int serialize(char *buf, const int64_t buf_len, int64_t &pos) const;
int deserialize(ObArenaAllocator &allocator, const char *buf, const int64_t data_len, int64_t &pos);
int64_t get_serialize_size() const;
@ -209,8 +208,8 @@ private:
const ObIArray<blocksstable::MacroBlockId> &linked_block_list,
bool &inc_macro_id_success) const;
void dec_linked_block_ref_cnt(const ObIArray<blocksstable::MacroBlockId> &linked_block_list) const;
int construct_block_id_arr(ObBlockInfoSet::TabletMacroSet &id_set, ObBlockInfoArray<blocksstable::MacroBlockId> &block_id_arr);
int construct_block_info_arr(ObBlockInfoSet::TabletMacroMap &block_info_map, ObBlockInfoArray<ObSharedBlockInfo> &block_info_arr);
int construct_block_id_arr(const ObBlockInfoSet::TabletMacroSet &id_set, ObBlockInfoArray<blocksstable::MacroBlockId> &block_id_arr);
int construct_block_info_arr(const ObBlockInfoSet::TabletMacroMap &block_info_map, ObBlockInfoArray<ObSharedBlockInfo> &block_info_arr);
int persist_macro_ids(ObArenaAllocator &allocator, ObLinkedMacroBlockItemWriter &linked_writer);
int do_flush_ids(
const ObTabletMacroType macro_type,

View File

@ -313,7 +313,7 @@ int ObMacroInfoIterator::reuse_info_arr(const int64_t cnt)
} else {
block_info_arr_.reset();
allocator_.reuse();
if (OB_FAIL(block_info_arr_.init(cnt, allocator_))) {
if (OB_FAIL(block_info_arr_.reserve(cnt, allocator_))) {
LOG_WARN("fail to init block_info_arr_", K(ret), K(cnt));
}
}

View File

@ -303,6 +303,7 @@ int ObTabletPersister::persist_and_transform_tablet(
int64_t total_tablet_meta_size = 0;
ObTabletMacroInfo tablet_macro_info;
total_write_ctxs.set_attr(lib::ObMemAttr(MTL_ID(), "TblMetaWriCtx", ctx_id));
ObSArray<MacroBlockId> shared_meta_id_arr;
if (OB_UNLIKELY(!old_tablet.is_valid())) {
ret = OB_INVALID_ARGUMENT;
@ -310,12 +311,11 @@ int ObTabletPersister::persist_and_transform_tablet(
} else if (OB_FAIL(persister.multi_stats_.acquire_stats("persist_and_transform_tablet", time_stats))) {
LOG_WARN("fail to acquire time stats", K(ret));
} else if (OB_FAIL(persister.persist_and_fill_tablet(
old_tablet, linked_writer, total_write_ctxs, new_handle, space_usage, tablet_macro_info))) {
old_tablet, linked_writer, total_write_ctxs, new_handle, space_usage, tablet_macro_info, shared_meta_id_arr))) {
LOG_WARN("fail to persist and fill tablet", K(ret), K(old_tablet));
} else if (FALSE_IT(time_stats->click("persist_and_fill_tablet"))) {
} else if (OB_FAIL(check_tablet_meta_ids(tablet_macro_info.shared_meta_block_info_arr_, *(new_handle.get_obj())))) {
LOG_WARN("fail to check whether tablet meta's macro ids match",
K(ret), K(tablet_macro_info.shared_meta_block_info_arr_), KPC(new_handle.get_obj()));
} else if (OB_FAIL(check_tablet_meta_ids(shared_meta_id_arr, *(new_handle.get_obj())))) {
LOG_WARN("fail to check whether tablet meta's macro ids match", K(ret), K(shared_meta_id_arr), KPC(new_handle.get_obj()));
} else if (FALSE_IT(time_stats->click("check_tablet_meta_ids"))) {
} else if (OB_FAIL(persister.persist_aggregated_meta(tablet_macro_info, new_handle, space_usage))) {
LOG_WARN("fail to persist aggregated tablet", K(ret), K(new_handle), KPC(new_handle.get_obj()));
@ -587,7 +587,8 @@ int ObTabletPersister::persist_and_fill_tablet(
common::ObIArray<ObSharedBlocksWriteCtx> &total_write_ctxs,
ObTabletHandle &new_handle,
ObTabletSpaceUsage &space_usage,
ObTabletMacroInfo &tablet_macro_info)
ObTabletMacroInfo &tablet_macro_info,
ObIArray<MacroBlockId> &shared_meta_id_arr)
{
int ret = OB_SUCCESS;
ObTabletTransformArg arg;
@ -640,10 +641,17 @@ int ObTabletPersister::persist_and_fill_tablet(
space_usage.meta_size_ = block_info_set.meta_block_info_set_.size() * DEFAULT_MACRO_BLOCK_SIZE;
int64_t shared_data_size = 0;
for (ObBlockInfoSet::MapIterator iter = block_info_set.shared_data_block_info_map_.begin();
OB_SUCC(ret) && iter != block_info_set.shared_data_block_info_map_.end();
iter != block_info_set.shared_data_block_info_map_.end();
++iter) {
shared_data_size += iter->second;
}
for (ObBlockInfoSet::SetIterator iter = block_info_set.shared_meta_block_info_set_.begin();
OB_SUCC(ret) && iter != block_info_set.shared_meta_block_info_set_.end();
++iter) {
if (OB_FAIL(shared_meta_id_arr.push_back(iter->first))) {
LOG_WARN("fail to push back macro id", K(ret), K(iter->first));
}
}
space_usage.shared_data_size_ = shared_data_size;
}
@ -659,12 +667,13 @@ int ObTabletPersister::transform_empty_shell(const ObTablet &old_tablet, ObTable
ObTabletSpaceUsage space_usage;
ObTabletMacroInfo tablet_macro_info;
ObTabletPersister persister;
ObSArray<MacroBlockId> shared_meta_id_arr;
if (OB_UNLIKELY(!old_tablet.is_empty_shell())) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("only support transform empty shell", K(ret), K(old_tablet));
} else if (OB_FAIL(persister.persist_and_fill_tablet(old_tablet, linked_writer,
total_write_ctxs, new_handle, space_usage, tablet_macro_info))) {
total_write_ctxs, new_handle, space_usage, tablet_macro_info, shared_meta_id_arr))) {
LOG_WARN("fail to persist old empty shell", K(ret), K(old_tablet));
}
@ -672,21 +681,21 @@ int ObTabletPersister::transform_empty_shell(const ObTablet &old_tablet, ObTable
}
int ObTabletPersister::check_tablet_meta_ids(
const ObBlockInfoArray<MacroBlockId> &meta_id_arr,
const ObIArray<blocksstable::MacroBlockId> &shared_meta_id_arr,
const ObTablet &tablet)
{
int ret = OB_SUCCESS;
ObSArray<MacroBlockId> meta_ids;
if (OB_FAIL(tablet.get_tablet_first_second_level_meta_ids(meta_ids))) {
LOG_WARN("fail to get tablet meta ids", K(ret), K(tablet));
} else if (OB_UNLIKELY(meta_ids.count() > meta_id_arr.cnt_)) {
} else if (OB_UNLIKELY(meta_ids.count() > shared_meta_id_arr.count())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("num of macro blocks doesn't match", K(ret), K(meta_ids.count()), K(meta_id_arr.cnt_));
LOG_WARN("num of macro blocks doesn't match", K(ret), K(meta_ids.count()), K(shared_meta_id_arr));
} else {
bool found = false;
for (int64_t i = 0; OB_SUCC(ret) && i < meta_ids.count(); i++) {
for (int64_t j = 0; !found && j < meta_id_arr.cnt_; j++) {
if (meta_ids.at(i) == meta_id_arr.arr_[j]) {
for (int64_t j = 0; !found && j < shared_meta_id_arr.count(); j++) {
if (meta_ids.at(i) == shared_meta_id_arr.at(j)) {
found = true;
}
}

View File

@ -230,7 +230,7 @@ private:
blocksstable::ObMacroIdIterator &iter,
ObBlockInfoSet::TabletMacroSet &id_set);
static int check_tablet_meta_ids(
const ObBlockInfoArray<blocksstable::MacroBlockId> &meta_id_arr,
const ObIArray<blocksstable::MacroBlockId> &shared_meta_id_arr,
const ObTablet &tablet);
static int acquire_tablet(
const ObTabletPoolType &type,
@ -261,7 +261,8 @@ private:
common::ObIArray<ObSharedBlocksWriteCtx> &total_write_ctxs,
ObTabletHandle &new_handle,
ObTabletSpaceUsage &space_usage,
ObTabletMacroInfo &macro_info);
ObTabletMacroInfo &macro_info,
ObIArray<blocksstable::MacroBlockId> &shared_meta_id_arr);
int modify_and_fill_tablet(
const ObTablet &old_tablet,
ObITabletMetaModifier &modifier,