diff --git a/src/storage/high_availability/ob_storage_ha_struct.cpp b/src/storage/high_availability/ob_storage_ha_struct.cpp index 243c291644..0645c2fb66 100644 --- a/src/storage/high_availability/ob_storage_ha_struct.cpp +++ b/src/storage/high_availability/ob_storage_ha_struct.cpp @@ -401,16 +401,15 @@ int ObMigrationStatusHelper::check_transfer_dest_ls_status_for_ls_gc( // and the destination can be restored through rebuilding. int ObMigrationStatusHelper::set_ls_migrate_gc_status_( ObLS &ls, - const ObMigrationStatus &migration_status) + bool &allow_gc) { int ret = OB_SUCCESS; - const ObMigrationStatus migrate_GC_status = ObMigrationStatus::OB_MIGRATION_STATUS_GC; - if (ObMigrationStatus::OB_MIGRATION_STATUS_NONE != migration_status) { - // do nothing + if (OB_FAIL(ls.set_ls_migration_gc(allow_gc))) { + LOG_WARN("failed to set migration status", K(ret)); + } else if (!allow_gc) { + LOG_INFO("ls is not allow gc", K(ret), K(ls)); } else if (OB_FAIL(ls.get_log_handler()->disable_sync())) { LOG_WARN("failed to disable replay", K(ret)); - } else if (OB_FAIL(ls.set_migration_status(migrate_GC_status, ls.get_ls_meta().get_rebuild_seq()))) { - LOG_WARN("failed to set migration status", K(ret)); } return ret; } @@ -444,7 +443,7 @@ int ObMigrationStatusHelper::check_ls_transfer_tablet_( } else if (FALSE_IT(ls_status = ls->get_persistent_state())) { } else if (ls_status.is_need_gc()) { allow_gc = true; - } else if (OB_FAIL(set_ls_migrate_gc_status_(*ls, migration_status))) { + } else if (OB_FAIL(set_ls_migrate_gc_status_(*ls, allow_gc))) { LOG_WARN("failed to set ls gc status", KR(ret)); } else if (OB_FAIL(ls->get_restore_status(restore_status))) { LOG_WARN("failed to get restore status", K(ret), KPC(ls)); diff --git a/src/storage/high_availability/ob_storage_ha_struct.h b/src/storage/high_availability/ob_storage_ha_struct.h index 5c35b640ea..7f335fd0ce 100644 --- a/src/storage/high_availability/ob_storage_ha_struct.h +++ b/src/storage/high_availability/ob_storage_ha_struct.h @@ -117,7 +117,7 @@ private: static bool check_migration_status_is_fail_(const ObMigrationStatus &cur_status); static int set_ls_migrate_gc_status_( ObLS &ls, - const ObMigrationStatus &migration_status); + bool &allow_gc); static int check_ls_with_transfer_task_( ObLS &ls, bool &need_check_allow_gc, diff --git a/src/storage/ls/ob_ls.cpp b/src/storage/ls/ob_ls.cpp index 29dfed30bc..7d178898cb 100644 --- a/src/storage/ls/ob_ls.cpp +++ b/src/storage/ls/ob_ls.cpp @@ -2467,5 +2467,42 @@ bool ObLS::is_in_gc() return bret; } +int ObLS::set_ls_migration_gc( + bool &allow_gc) +{ + int ret = OB_SUCCESS; + allow_gc = false; + const bool write_slog = true; + const ObMigrationStatus change_status = ObMigrationStatus::OB_MIGRATION_STATUS_GC; + ObMigrationStatus curr_status = ObMigrationStatus::OB_MIGRATION_STATUS_MAX; + ObLSRebuildInfo rebuild_info; + WRLockGuard guard(meta_rwlock_); + + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + STORAGE_LOG(WARN, "ls is not inited", K(ret), K(ls_meta_)); + } else if (!ls_meta_.get_persistent_state().can_update_ls_meta()) { + ret = OB_STATE_NOT_MATCH; + STORAGE_LOG(WARN, "state not match, cannot update ls meta", K(ret), K(ls_meta_)); + } else if (OB_FAIL(ls_meta_.get_rebuild_info(rebuild_info))) { + LOG_WARN("failed to get rebuild info", K(ret), K(ls_meta_)); + } else if (rebuild_info.is_in_rebuild()) { + allow_gc = false; + } else if (OB_FAIL(ls_meta_.get_migration_status(curr_status))) { + LOG_WARN("failed to get migration status", K(ret), K(ls_meta_)); + } else if (ObMigrationStatusHelper::check_allow_gc_abandoned_ls(curr_status)) { + allow_gc = true; + } else if (ObMigrationStatus::OB_MIGRATION_STATUS_NONE != curr_status) { + allow_gc = false; + } else if (OB_FAIL(ls_meta_.set_migration_status(change_status, write_slog))) { + LOG_WARN("failed to set migration status", K(ret), K(change_status)); + } else { + ls_tablet_svr_.disable_to_read(); + allow_gc = true; + } + return ret; +} + + } } diff --git a/src/storage/ls/ob_ls.h b/src/storage/ls/ob_ls.h index 23b8d334bc..649d4443b3 100644 --- a/src/storage/ls/ob_ls.h +++ b/src/storage/ls/ob_ls.h @@ -879,6 +879,8 @@ public: DELEGATE_WITH_RET(reserved_snapshot_mgr_, get_min_reserved_snapshot, int64_t); DELEGATE_WITH_RET(reserved_snapshot_mgr_, add_dependent_medium_tablet, int); DELEGATE_WITH_RET(reserved_snapshot_mgr_, del_dependent_medium_tablet, int); + int set_ls_migration_gc(bool &allow_gc); + private: // StorageBaseUtil // table manager: create, remove and guard get.