diff --git a/src/storage/compaction/ob_medium_compaction_func.cpp b/src/storage/compaction/ob_medium_compaction_func.cpp index 988b30ee16..4db5a24f26 100644 --- a/src/storage/compaction/ob_medium_compaction_func.cpp +++ b/src/storage/compaction/ob_medium_compaction_func.cpp @@ -155,6 +155,8 @@ int ObMediumCompactionScheduleFunc::choose_major_snapshot( } int ObMediumCompactionScheduleFunc::get_status_from_inner_table( + const ObLSID &ls_id, + const ObTabletID &tablet_id, ObTabletCompactionScnInfo &ret_info) { int ret = OB_SUCCESS; @@ -162,8 +164,8 @@ int ObMediumCompactionScheduleFunc::get_status_from_inner_table( ObTabletCompactionScnInfo snapshot_info( MTL_ID(), - ls_.get_ls_id(), - tablet_.get_tablet_meta().tablet_id_, + ls_id, + tablet_id, ObTabletReplica::SCN_STATUS_IDLE); if (OB_FAIL(ObTabletMetaTableCompactionOperator::get_status(snapshot_info, ret_info))) { if (OB_ENTRY_NOT_EXIST == ret) { @@ -251,7 +253,7 @@ int ObMediumCompactionScheduleFunc::schedule_next_medium_primary_cluster( } else if (ObMediumCompactionInfo::MAJOR_COMPACTION == medium_list.get_last_compaction_type()) { // for normal medium, checksum error happened, wait_check_medium_scn_ will never = 0 // for major, need select inner_table to check RS status - if (OB_FAIL(get_status_from_inner_table(ret_info))) { + if (OB_FAIL(get_status_from_inner_table(ls_.get_ls_id(), tablet_.get_tablet_meta().tablet_id_, ret_info))) { LOG_WARN("failed to get status from inner tablet", K(ret), KPC(this)); } else if (ret_info.could_schedule_next_round(last_major->get_snapshot_version())) { LOG_INFO("success to check RS major checksum validation finished", K(ret), KPC(this), K(ret_info)); @@ -802,12 +804,13 @@ int ObMediumCompactionScheduleFunc::check_medium_finish() return ret; } -// DO NOT visit inner table in this func +// scheduler_called = false : called in compaction, DO NOT visit inner table in this func +// scheduler_called = true : in scheduler loop, could visit inner table int ObMediumCompactionScheduleFunc::schedule_tablet_medium_merge( ObLS &ls, ObTablet &tablet, const int64_t input_major_snapshot, - const bool schedule_with_memtable) + const bool scheduler_called) { int ret = OB_SUCCESS; #ifdef ERRSIM @@ -817,26 +820,50 @@ int ObMediumCompactionScheduleFunc::schedule_tablet_medium_merge( return ret; } #endif + if (MTL(ObTenantTabletScheduler *)->could_major_merge_start()) { const ObMediumCompactionInfoList &medium_list = tablet.get_medium_compaction_info_list(); const ObTabletID &tablet_id = tablet.get_tablet_meta().tablet_id_; const ObLSID &ls_id = ls.get_ls_id(); - int64_t major_frozen_snapshot = 0 == input_major_snapshot ? MTL(ObTenantTabletScheduler *)->get_frozen_version() : input_major_snapshot; - ObMediumCompactionInfo::ObCompactionType compaction_type = ObMediumCompactionInfo::COMPACTION_TYPE_MAX; - int64_t schedule_scn = 0; - bool need_merge = false; + ObITable *last_major = tablet.get_table_store().get_major_sstables().get_boundary_table(true/*last*/); - (void)tablet.get_medium_compaction_info_list().get_schedule_scn(major_frozen_snapshot, schedule_scn, compaction_type); + bool schedule_flag = false; + if (OB_ISNULL(last_major)) { + // do nothing + } else if (ObMediumCompactionInfo::MAJOR_COMPACTION == medium_list.get_last_compaction_type() + && !MTL_IS_PRIMARY_TENANT()) { // for STANDBY/RESTORE TENANT + ObTabletCompactionScnInfo ret_info; + // for standby/restore tenant, need select inner_table to check RS status before schedule new round + if (!scheduler_called) { // should not visit inner table, wait for scheduler loop + } else if (OB_FAIL(get_status_from_inner_table(ls_id, tablet_id, ret_info))) { + LOG_WARN("failed to get status from inner tablet", K(ret), K(ls_id), K(tablet_id)); + } else if (ret_info.could_schedule_next_round(last_major->get_snapshot_version())) { + LOG_INFO("success to check RS major checksum validation finished", K(ret), K(ls_id), K(tablet_id)); + } else { + schedule_flag = true; + } + } else { + schedule_flag = true; + } - LOG_DEBUG("schedule_tablet_medium_merge", K(schedule_scn), K(major_frozen_snapshot), K(schedule_with_memtable), K(ls_id), K(tablet_id)); - if (0 == schedule_scn - && 0 == tablet.get_medium_compaction_info_list().size() // serialized medium list is empty - && schedule_with_memtable - && OB_FAIL(get_schedule_medium_from_memtable(tablet, major_frozen_snapshot, schedule_scn, compaction_type))) { - LOG_WARN("failed to get schedule medium scn from memtables", K(ret)); - } else if (schedule_scn > 0) { - if (OB_FAIL(check_need_merge_and_schedule(ls, tablet, schedule_scn, compaction_type))) { - LOG_WARN("failed to check medium merge", K(ret), K(ls_id), K(tablet_id), K(schedule_scn)); + if (OB_SUCC(ret) && schedule_flag) { + int64_t major_frozen_snapshot = 0 == input_major_snapshot ? MTL(ObTenantTabletScheduler *)->get_frozen_version() : input_major_snapshot; + ObMediumCompactionInfo::ObCompactionType compaction_type = ObMediumCompactionInfo::COMPACTION_TYPE_MAX; + int64_t schedule_scn = 0; + bool need_merge = false; + + (void)tablet.get_medium_compaction_info_list().get_schedule_scn(major_frozen_snapshot, schedule_scn, compaction_type); + + LOG_DEBUG("schedule_tablet_medium_merge", K(schedule_scn), K(major_frozen_snapshot), K(scheduler_called), K(ls_id), K(tablet_id)); + if (0 == schedule_scn + && 0 == tablet.get_medium_compaction_info_list().size() // serialized medium list is empty + && scheduler_called + && OB_FAIL(get_schedule_medium_from_memtable(tablet, major_frozen_snapshot, schedule_scn, compaction_type))) { + LOG_WARN("failed to get schedule medium scn from memtables", K(ret)); + } else if (schedule_scn > 0) { + if (OB_FAIL(check_need_merge_and_schedule(ls, tablet, schedule_scn, compaction_type))) { + LOG_WARN("failed to check medium merge", K(ret), K(ls_id), K(tablet_id), K(schedule_scn)); + } } } } diff --git a/src/storage/compaction/ob_medium_compaction_func.h b/src/storage/compaction/ob_medium_compaction_func.h index 7976b8b183..19141934c4 100644 --- a/src/storage/compaction/ob_medium_compaction_func.h +++ b/src/storage/compaction/ob_medium_compaction_func.h @@ -38,7 +38,7 @@ public: ObLS &ls, ObTablet &tablet, const int64_t major_frozen_scn = 0, - const bool schedule_with_memtable = false); + const bool scheduler_called = false); static int get_latest_storage_schema_from_memtable( ObIAllocator &allocator, const ObIArray &memtables, @@ -65,7 +65,10 @@ public: int64_t to_string(char* buf, const int64_t buf_len) const; protected: - int get_status_from_inner_table(share::ObTabletCompactionScnInfo &ret_info); + static int get_status_from_inner_table( + const ObLSID &ls_id, + const ObTabletID &tablet_id, + share::ObTabletCompactionScnInfo &ret_info); int prepare_medium_info(const ObGetMergeTablesResult &result, ObMediumCompactionInfo &medium_info); int init_parallel_range( const ObGetMergeTablesResult &result, diff --git a/src/storage/compaction/ob_tenant_tablet_scheduler.cpp b/src/storage/compaction/ob_tenant_tablet_scheduler.cpp index c163f00042..57291c6820 100755 --- a/src/storage/compaction/ob_tenant_tablet_scheduler.cpp +++ b/src/storage/compaction/ob_tenant_tablet_scheduler.cpp @@ -1017,7 +1017,7 @@ int ObTenantTabletScheduler::schedule_ls_medium_merge( ls, *tablet, major_frozen_scn, - true/*schedule_with_memtable*/))) { + true/*scheduler_called*/))) { if (OB_EAGAIN != ret) { LOG_WARN("failed to schedule medium", K(tmp_ret), K(ls_id), K(tablet_id)); }