diff --git a/src/logservice/ob_garbage_collector.cpp b/src/logservice/ob_garbage_collector.cpp index 3a705c0c26..25d3f17792 100644 --- a/src/logservice/ob_garbage_collector.cpp +++ b/src/logservice/ob_garbage_collector.cpp @@ -633,16 +633,16 @@ bool ObGCHandler::is_valid_ls_gc_state(const LSGCState &state) && LSGCState::INVALID_LS_GC_STATE < state; } +bool ObGCHandler::is_ls_offline_gc_state(const LSGCState &state) +{ + return LSGCState::LS_OFFLINE == state; +} + bool ObGCHandler::is_ls_blocked_state_(const LSGCState &state) { return LSGCState::LS_BLOCKED == state; } -bool ObGCHandler::is_ls_offline_state_(const LSGCState &state) -{ - return LSGCState::LS_OFFLINE == state; -} - bool ObGCHandler::is_ls_wait_gc_state_(const LSGCState &state) { return LSGCState::WAIT_GC == state; @@ -987,7 +987,6 @@ void ObGCHandler::block_ls_transfer_in_(const SCN &block_scn) CLOG_LOG(WARN, "ls check gc state invalid", K(ls_id), K(gc_state)); } else if (is_ls_blocked_finished_(gc_state)) { CLOG_LOG(INFO, "ls already blocked, ignore", K(ls_id), K(gc_state), K(block_scn)); - //TODO: @keqing.llt transfer功能完成之前,先用杀事务代替transfer out } else if (OB_FAIL(ls_->block_tx_start())) { CLOG_LOG(WARN, "block_tx_start failed", K(ls_id), K(ret)); } else if (FALSE_IT(block_tx_ts_ = ObClockGenerator::getClock())) { @@ -1015,12 +1014,8 @@ void ObGCHandler::offline_ls_(const SCN &offline_scn) } else { CLOG_LOG(INFO, "ls already offline, ignore", K(ls_id), K(offline_scn), K(gc_state), K(pre_offline_scn)); } - } else if (OB_FAIL(ls_->set_gc_state(LSGCState::LS_OFFLINE))) { - //TODO: @yanyuan 需要调用ObLS的offline_ls_接口 - //offline_scn依赖gc_state写slog, 顺序必须为先设置offline_scn再设置gc状态 - CLOG_LOG(WARN, "set_gc_state failed", K(ls_->get_ls_id()), K(ret)); - } else if (OB_FAIL(ls_->set_offline_scn(offline_scn))) { - CLOG_LOG(WARN, "set_gc_state failed", K(ls_->get_ls_id()), K(ret)); + } else if (OB_FAIL(ls_->set_gc_state(LSGCState::LS_OFFLINE, offline_scn))) { + CLOG_LOG(WARN, "set_gc_state failed", K(ls_->get_ls_id()), K(offline_scn)); } else { CLOG_LOG(INFO, "offline_ls success", K(ls_->get_ls_id()), K(offline_scn)); } } @@ -1119,7 +1114,7 @@ void ObGCHandler::handle_gc_ls_offline_(ObGarbageCollector::LSStatus &ls_status) } else if (is_ls_wait_gc_state_(gc_state)) { ls_status = ObGarbageCollector::LSStatus::LS_NEED_DELETE_ENTRY; CLOG_LOG(INFO, "handle_gc_ls_offline need delete entry", K(ls_id), K(gc_state)); - } else if (is_ls_offline_state_(gc_state)) { + } else if (is_ls_offline_gc_state(gc_state)) { (void)try_check_and_set_wait_gc_(ls_status); } else { if (OB_FAIL(submit_log_(ObGCLSLOGType::OFFLINE_LS, is_success))) { diff --git a/src/logservice/ob_garbage_collector.h b/src/logservice/ob_garbage_collector.h index 52c6adea0d..91afebf4e9 100644 --- a/src/logservice/ob_garbage_collector.h +++ b/src/logservice/ob_garbage_collector.h @@ -251,6 +251,7 @@ public: int check_ls_can_offline(const share::ObLSStatus &ls_status); int gc_check_invalid_member_seq(const int64_t gc_seq, bool &need_gc); static bool is_valid_ls_gc_state(const LSGCState &state); + static bool is_ls_offline_gc_state(const LSGCState &state); int diagnose(GCDiagnoseInfo &diagnose_info) const; @@ -314,10 +315,10 @@ private: const int64_t GET_GTS_TIMEOUT_US = 10L * 1000 * 1000; //10s int get_gts_(const int64_t timeout_us, share::SCN >s_scn); bool is_ls_blocked_state_(const LSGCState &state); - bool is_ls_offline_state_(const LSGCState &state); bool is_ls_wait_gc_state_(const LSGCState &state); bool is_ls_blocked_finished_(const LSGCState &state); bool is_ls_offline_finished_(const LSGCState &state); + bool is_tablet_clear_(const ObGarbageCollector::LSStatus &ls_status); void try_check_and_set_wait_gc_(ObGarbageCollector::LSStatus &ls_status); int try_check_and_set_wait_gc_when_log_archive_is_off_( diff --git a/src/storage/ls/ob_ls.cpp b/src/storage/ls/ob_ls.cpp index a69a967acc..84593e75e0 100755 --- a/src/storage/ls/ob_ls.cpp +++ b/src/storage/ls/ob_ls.cpp @@ -2301,6 +2301,24 @@ int ObLS::set_restore_status( return ret; } +int ObLS::set_gc_state(const logservice::LSGCState &gc_state) +{ + SCN invalid_scn; + return set_gc_state(gc_state, invalid_scn); +} + +int ObLS::set_gc_state(const logservice::LSGCState &gc_state, const share::SCN &offline_scn) +{ + int ret = OB_SUCCESS; + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + LOG_WARN("ls is not inited", K(ret), K(ls_meta_)); + } else { + ret = ls_meta_.set_gc_state(gc_state, offline_scn); + } + return ret; +} + int ObLS::set_ls_rebuild() { int ret = OB_SUCCESS; diff --git a/src/storage/ls/ob_ls.h b/src/storage/ls/ob_ls.h index 3dfd872e05..5aa5aee9ec 100755 --- a/src/storage/ls/ob_ls.h +++ b/src/storage/ls/ob_ls.h @@ -380,7 +380,8 @@ public: int set_ls_rebuild(); // protect in ls lock // int set_gc_state(const logservice::LSGCState &gc_state); - DELEGATE_WITH_RET(ls_meta_, set_gc_state, int); + int set_gc_state(const logservice::LSGCState &gc_state); + int set_gc_state(const logservice::LSGCState &gc_state, const share::SCN &offline_scn); // int set_clog_checkpoint(const palf::LSN &clog_checkpoint_lsn, // const share::SCN &clog_checkpoint_scn, // const bool write_slog = true); @@ -414,10 +415,6 @@ public: // @param [in] gc state. // int get_gc_state(LSGCState &status); DELEGATE_WITH_RET(ls_meta_, get_gc_state, int); - // set offline ts - // @param [in] offline ts. - // int set_offline_scn(const int64_t offline_scn); - DELEGATE_WITH_RET(ls_meta_, set_offline_scn, int); // get offline ts // @param [in] offline ts. // int get_offline_scn(const share::SCN &offline_scn); diff --git a/src/storage/ls/ob_ls_meta.cpp b/src/storage/ls/ob_ls_meta.cpp index f9a5f218cc..b813948668 100644 --- a/src/storage/ls/ob_ls_meta.cpp +++ b/src/storage/ls/ob_ls_meta.cpp @@ -304,22 +304,26 @@ int ObLSMeta::get_migration_status(ObMigrationStatus &migration_status) const return ret; } -int ObLSMeta::set_gc_state(const logservice::LSGCState &gc_state) +int ObLSMeta::set_gc_state(const logservice::LSGCState &gc_state, const SCN &scn) { int ret = OB_SUCCESS; ObSpinLockTimeGuard guard(lock_); if (OB_FAIL(check_can_update_())) { LOG_WARN("ls meta cannot update", K(ret), K(*this)); - } else if (!ObGCHandler::is_valid_ls_gc_state(gc_state)) { + } else if (!ObGCHandler::is_valid_ls_gc_state(gc_state) + || (ObGCHandler::is_ls_offline_gc_state(gc_state) && !scn.is_valid()) + || (!ObGCHandler::is_ls_offline_gc_state(gc_state) && scn.is_valid())) { ret = OB_ERR_UNEXPECTED; LOG_WARN("gc_state invalid", K(ret), K(gc_state)); } else { ObLSMeta tmp(*this); tmp.gc_state_ = gc_state; + tmp.offline_scn_ = scn; if (OB_FAIL(write_slog_(tmp))) { LOG_WARN("gc_state write slog failed", K(ret)); } else { gc_state_ = gc_state; + offline_scn_ = scn; } } return ret; @@ -338,19 +342,6 @@ int ObLSMeta::get_gc_state(logservice::LSGCState &gc_state) return ret; } -int ObLSMeta::set_offline_scn(const SCN &offline_scn) -{ - // 不主动写slog - int ret = OB_SUCCESS; - ObSpinLockTimeGuard guard(lock_); - if (OB_FAIL(check_can_update_())) { - LOG_WARN("ls meta cannot update", K(ret), K(*this)); - } else { - offline_scn_ = offline_scn; - } - return ret; -} - int ObLSMeta::get_offline_scn(SCN &offline_scn) { int ret = OB_SUCCESS; diff --git a/src/storage/ls/ob_ls_meta.h b/src/storage/ls/ob_ls_meta.h index 7a50508f7a..e3e1d4a5fe 100644 --- a/src/storage/ls/ob_ls_meta.h +++ b/src/storage/ls/ob_ls_meta.h @@ -60,9 +60,8 @@ public: int set_migration_status(const ObMigrationStatus &migration_status, const bool write_slog = true); int get_migration_status (ObMigrationStatus &migration_status) const; - int set_gc_state(const logservice::LSGCState &gc_state); + int set_gc_state(const logservice::LSGCState &gc_state, const share::SCN &offline_scn); int get_gc_state(logservice::LSGCState &gc_state); - int set_offline_scn(const share::SCN &offline_scn); int get_offline_scn(share::SCN &offline_scn); int set_restore_status(const share::ObLSRestoreStatus &restore_status);