fix switching leader gets stuck

This commit is contained in:
BinChenn
2023-02-08 11:50:34 +08:00
committed by ob-robot
parent c071b904f9
commit 2f125a5aad

View File

@ -80,49 +80,53 @@ int PriorityV1::compare(const AbstractPriority &rhs, int &result, ObStringHolder
#undef PRINT_WRAPPER
}
// | Leader | Follower
// ----------|----------------|-----------------
// APPEND | max_scn | max_replayed_scn
// ----------|----------------|-----------------
// RAW_WRITE | replayable_scn | max_replayed_scn
// ----------|----------------|-----------------
// OTHER | like RAW_WRITE
int PriorityV1::get_scn_(const share::ObLSID &ls_id, SCN &scn)
{
LC_TIME_GUARD(100_ms);
#define PRINT_WRAPPER KR(ret), K(MTL_ID()), K(ls_id), K(*this)
int ret = OB_SUCCESS;
palf::PalfHandleGuard palf_handle_guard;
// palf::AccessMode access_mode = palf::AccessMode::INVALID_ACCESS_MODE;
if (OB_ISNULL(MTL(ObLogService*))) {
palf::AccessMode access_mode = palf::AccessMode::INVALID_ACCESS_MODE;
ObLogService* log_service = MTL(ObLogService*);
common::ObRole role;
int64_t unused_pid = -1;
if (OB_ISNULL(log_service)) {
COORDINATOR_LOG_(ERROR, "ObLogService is nullptr");
} else if (CLICK_FAIL(MTL(ObLogService*)->open_palf(ls_id, palf_handle_guard))) {
} else if (CLICK_FAIL(log_service->open_palf(ls_id, palf_handle_guard))) {
COORDINATOR_LOG_(WARN, "open_palf failed");
// } else if (CLICK_FAIL(palf_handle_guard.get_palf_handle()->get_access_mode(access_mode))) {
// COORDINATOR_LOG_(WARN, "get_access_mode failed");
// } else if (palf::AccessMode::APPEND != access_mode) {
// // Set log_ts to 0 when current access mode is not APPEND.
// log_ts = 0;
} else {
common::ObRole role;
int64_t unused_pid = -1;
SCN max_replayed_scn;
if (CLICK_FAIL(palf_handle_guard.get_role(role, unused_pid))) {
COORDINATOR_LOG_(WARN, "get_role failed");
} else if (CLICK_FAIL(palf_handle_guard.get_max_scn(scn))) {
} else if (CLICK_FAIL(palf_handle_guard.get_role(role, unused_pid))) {
COORDINATOR_LOG_(WARN, "get_role failed");
} else if (FOLLOWER == role) {
if (CLICK_FAIL(log_service->get_log_replay_service()->get_max_replayed_scn(ls_id, scn))) {
COORDINATOR_LOG_(WARN, "failed to get_max_replayed_scn");
ret = OB_SUCCESS;
}
} else if (CLICK_FAIL(palf_handle_guard.get_palf_handle()->get_access_mode(access_mode))) {
COORDINATOR_LOG_(WARN, "get_access_mode failed");
} else if (palf::AccessMode::APPEND == access_mode) {
if (CLICK_FAIL(palf_handle_guard.get_max_scn(scn))) {
COORDINATOR_LOG_(WARN, "get_max_scn failed");
} else if (FOLLOWER == role) {
if (CLICK_FAIL(MTL(ObLogService*)->get_log_replay_service()->get_max_replayed_scn(ls_id, max_replayed_scn))) {
COORDINATOR_LOG_(WARN, "failed to get_max_replayed_scnn");
ret = OB_SUCCESS;
} else if (max_replayed_scn < scn) {
// For restore case, min_unreplay_scn may be larger than max_ts.
scn = max_replayed_scn;
} else {}
} else {}
// log_ts may fallback because palf's role may be different with apply_service.
// So we need check it here to keep inc update semantic.
if (scn < scn_) {
COORDINATOR_LOG_(TRACE, "new scn is smaller than current, no need update", K(role), K(max_replayed_scn), K(scn));
scn = scn_;
}
COORDINATOR_LOG_(TRACE, "get_scn_ finished", K(role), K(max_replayed_scn), K(scn));
if (OB_SUCC(ret) && !scn.is_valid()) {
scn.set_min();
}
} else if (CLICK_FAIL(log_service->get_log_replay_service()->get_replayable_point(scn))) {
COORDINATOR_LOG_(WARN, "failed to get_replayable_point");
ret = OB_SUCCESS;
}
// scn may fallback because palf's role may be different with apply_service.
// So we need check it here to keep inc update semantic.
if (scn < scn_) {
COORDINATOR_LOG_(TRACE, "new scn is smaller than current, no need update", K(role), K(access_mode), K(scn));
scn = scn_;
}
COORDINATOR_LOG_(TRACE, "get_scn_ finished", K(role), K(access_mode), K(scn));
if (OB_SUCC(ret) && !scn.is_valid()) {
scn.set_min();
}
return ret;
#undef PRINT_WRAPPER