Skip to content

Commit 7f8bddf

Browse files
obdevfootka
authored andcommitted
[CP] add the fsync before read macro block during the construction of sstable
Co-authored-by: footka <672528926@qq.com>
1 parent 7d93de4 commit 7f8bddf

7 files changed

Lines changed: 50 additions & 1 deletion

File tree

mittest/mtlenv/storage/blocksstable/ob_index_block_data_prepare.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ void TestIndexBlockDataPrepare::SetUp()
321321
} else {
322322
prepare_data();
323323
}
324+
if (!GCTX.is_shared_storage_mode()) {
325+
ASSERT_EQ(OB_SUCCESS, LOCAL_DEVICE_INSTANCE.fsync_block());
326+
}
324327
}
325328
void TestIndexBlockDataPrepare::TearDown()
326329
{

src/storage/blocksstable/index_block/ob_index_block_builder.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "ob_index_block_builder.h"
2020
#include "storage/blocksstable/ob_shared_macro_block_manager.h"
21+
#include "share/ob_io_device_helper.h"
2122

2223
#ifdef OB_BUILD_SHARED_STORAGE
2324
#include "share/compaction/ob_shared_storage_compaction_util.h"
@@ -1579,6 +1580,22 @@ int64_t ObSSTableIndexBuilder::get_tablet_transfer_seq() const
15791580
return data_store_desc_.get_desc().get_tablet_transfer_seq();
15801581
}
15811582

1583+
int ObSSTableIndexBuilder::fsync_block()
1584+
{
1585+
int ret = OB_SUCCESS;
1586+
const bool in_array = roots_[0]->meta_block_info_.in_array();
1587+
bool all_in_mem = true;
1588+
for (int64_t i = 0; i < roots_.count(); ++i) {
1589+
all_in_mem &= !roots_[i]->meta_block_info_.in_disk();
1590+
}
1591+
if (in_array || all_in_mem) {
1592+
// do nothing
1593+
} else if (OB_FAIL(LOCAL_DEVICE_INSTANCE.fsync_block())) {
1594+
STORAGE_LOG(WARN, "fail to fsync_block", K(ret));
1595+
}
1596+
return ret;
1597+
}
1598+
15821599
int ObSSTableIndexBuilder::close(ObSSTableMergeRes &res,
15831600
const int64_t nested_size,
15841601
const int64_t nested_offset,
@@ -1679,6 +1696,8 @@ int ObSSTableIndexBuilder::close_with_macro_seq_inner(
16791696
}
16801697
if (OB_FAIL(ret) || roots_.empty() || is_closed_) {
16811698
// do nothing
1699+
} else if (!GCTX.is_shared_storage_mode() && OB_FAIL(fsync_block())) {
1700+
STORAGE_LOG(WARN, "fail to fsync_block", K(ret));
16821701
} else if (OB_FAIL(merge_index_tree(pre_warm_param, res, macro_seq, callback))) {
16831702
STORAGE_LOG(WARN, "fail to merge index tree", K(ret), KP(callback));
16841703
} else if (OB_FAIL(build_meta_tree(pre_warm_param, res, ++macro_seq, callback))) {
@@ -1810,6 +1829,8 @@ int ObSSTableIndexBuilder::rewrite_small_sstable(ObSSTableMergeRes &res)
18101829
container_store_desc_, roots_, macro_meta))) {
18111830
STORAGE_LOG(WARN, "fail to get single macro meta", K(ret));
18121831
} else if (FALSE_IT(read_info.macro_block_id_ = macro_meta.val_.macro_id_)) {
1832+
} else if (!GCTX.is_shared_storage_mode() && OB_FAIL(LOCAL_DEVICE_INSTANCE.fsync_block())) {
1833+
LOG_WARN("fail to fsync_block", K(ret));
18131834
} else if (OB_FAIL(ObObjectManager::async_read_object(read_info, read_handle))) {
18141835
STORAGE_LOG(WARN, "fail to async read macro block", K(ret), K(read_info), K(macro_meta), K(roots_[0]->last_macro_size_));
18151836
} else if (OB_FAIL(read_handle.wait())) {
@@ -1922,6 +1943,8 @@ int ObSSTableIndexBuilder::load_single_macro_block(
19221943
ret = OB_ALLOCATE_MEMORY_FAILED;
19231944
STORAGE_LOG(WARN, "failed to alloc macro read info buffer", K(ret),
19241945
K(read_info.size_));
1946+
} else if (!GCTX.is_shared_storage_mode() && OB_FAIL(LOCAL_DEVICE_INSTANCE.fsync_block())) {
1947+
LOG_WARN("fail to fsync_block", K(ret));
19251948
} else if (OB_FAIL(ObObjectManager::async_read_object(read_info, read_handle))) {
19261949
STORAGE_LOG(WARN, "fail to async read macro block", K(ret), K(read_info), K(macro_meta));
19271950
} else if (OB_FAIL(read_handle.wait())) {

src/storage/blocksstable/index_block/ob_index_block_builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ class ObSSTableIndexBuilder final
732732
int get_clustered_micro_info(const int64_t roots_idx,
733733
const int64_t macro_meta_idx,
734734
ObClusteredIndexBlockMicroInfos *&clustered_micro_info) const;
735+
int fsync_block();
735736
int merge_index_tree(const share::ObPreWarmerParam &pre_warm_param,
736737
ObSSTableMergeRes &res,
737738
int64_t &macro_seq,

src/storage/blocksstable/ob_macro_block_writer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "storage/blocksstable/cs_encoding/ob_micro_block_cs_encoder.h"
2222
#include "src/storage/ddl/ob_ddl_clog.h"
2323
#include "storage/backup/ob_backup_data_struct.h"
24+
#include "share/ob_io_device_helper.h"
2425
#ifdef OB_BUILD_SHARED_STORAGE
2526
#include "storage/compaction/ob_major_pre_warmer.h"
2627
#endif
@@ -2230,6 +2231,8 @@ int ObMacroBlockWriter::check_write_complete(const MacroBlockId &macro_block_id)
22302231
read_info.buf_ = io_buf_;
22312232
}
22322233
if (OB_FAIL(ret)) {
2234+
} else if (!GCTX.is_shared_storage_mode() && OB_FAIL(LOCAL_DEVICE_INSTANCE.fsync_block())) {
2235+
LOG_WARN("fail to fsync_block", K(ret));
22332236
} else if (OB_FAIL(ObObjectManager::async_read_object(read_info, read_handle))) {
22342237
STORAGE_LOG(WARN, "fail to async read macro block", K(ret), K(read_info));
22352238
} else if (OB_FAIL(read_handle.wait())) {

src/storage/blocksstable/ob_shared_macro_block_manager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ int ObSharedMacroBlockMgr::write_block(
284284
ret = OB_ALLOCATE_MEMORY_FAILED;
285285
STORAGE_LOG(WARN, "failed to alloc macro read info buffer", K(ret), K(read_info.size_));
286286
} else {
287-
if (OB_FAIL(ObBlockManager::async_read_block(read_info, read_handle))) {
287+
if (!GCTX.is_shared_storage_mode() && OB_FAIL(LOCAL_DEVICE_INSTANCE.fsync_block())) {
288+
LOG_WARN("fail to fsync_block", K(ret));
289+
} else if (OB_FAIL(ObBlockManager::async_read_block(read_info, read_handle))) {
288290
LOG_WARN("fail to async read macro block", K(ret), K(read_info));
289291
} else if (OB_FAIL(read_handle.wait())) {
290292
LOG_WARN("fail to wait io finish", K(ret), K(read_info));

src/storage/blocksstable/ob_sstable_meta.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "ob_sstable_meta.h"
2020
#include "storage/blocksstable/index_block/ob_index_block_builder.h"
2121
#include "storage/tablet/ob_tablet_create_sstable_param.h"
22+
#include "share/ob_io_device_helper.h"
2223

2324
using namespace oceanbase::common;
2425
using namespace oceanbase::storage;
@@ -706,6 +707,19 @@ bool ObSSTableMeta::check_meta() const
706707
&& macro_info_.is_valid();
707708
}
708709

710+
int ObSSTableMeta::fsync_block(const ObTabletCreateSSTableParam &param)
711+
{
712+
int ret = OB_SUCCESS;
713+
const bool root_block_in_disk = param.root_block_addr_.is_disked();
714+
const bool macro_meta_in_disk = param.data_block_macro_meta_addr_.is_disked();
715+
if (root_block_in_disk || macro_meta_in_disk) {
716+
if (OB_FAIL(LOCAL_DEVICE_INSTANCE.fsync_block())) {
717+
LOG_WARN("fail to fsync_block", K(ret));
718+
}
719+
}
720+
return ret;
721+
}
722+
709723
int ObSSTableMeta::init(
710724
const ObTabletCreateSSTableParam &param,
711725
common::ObArenaAllocator &allocator)
@@ -726,6 +740,8 @@ int ObSSTableMeta::init(
726740
LOG_WARN("sstable state is not match.", K(ret), K(basic_meta_.status_));
727741
} else if (OB_FAIL(macro_info_.init_macro_info(allocator, param))) {
728742
LOG_WARN("fail to init macro info", K(ret), K(param));
743+
} else if (!GCTX.is_shared_storage_mode() && OB_FAIL(fsync_block(param))) {
744+
LOG_WARN("fail to fsync block", K(ret));
729745
} else if (OB_FAIL(load_root_block_data(allocator))) {
730746
LOG_WARN("fail to load root block data", K(ret), K(param));
731747
} else if (OB_UNLIKELY(!check_meta())) {

src/storage/blocksstable/ob_sstable_meta.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ class ObSSTableMeta final
322322
bool is_shared_table() const;
323323
TO_STRING_KV(K_(basic_meta), K_(column_ckm_struct), K_(data_root_info), K_(macro_info), K_(cg_sstables), K_(tx_ctx), K_(is_inited));
324324
private:
325+
int fsync_block(const ObTabletCreateSSTableParam &param);
325326
bool check_meta() const;
326327
int init_base_meta(const ObTabletCreateSSTableParam &param, common::ObArenaAllocator &allocator);
327328
int init_data_index_tree_info(

0 commit comments

Comments
 (0)