[MDS] if read mds data meet ls state changed: 1. retry if still online. 2.OB_LS_OFFLINE if offline.
This commit is contained in:
@ -35,7 +35,7 @@ int ObLSSwitchChecker::check_online(ObLS *ls)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObLSSwitchChecker::check_ls_switch_state(ObLS *ls, bool &online_state)
|
||||
int ObLSSwitchChecker::check_ls_switch_state(ObLS *ls, bool &is_online)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ls_ = ls;
|
||||
@ -44,21 +44,24 @@ int ObLSSwitchChecker::check_ls_switch_state(ObLS *ls, bool &online_state)
|
||||
} else {
|
||||
record_switch_epoch_ = ATOMIC_LOAD(&(ls_->switch_epoch_));
|
||||
if (!(record_switch_epoch_ & 1)) {
|
||||
online_state = false;
|
||||
is_online = false;
|
||||
} else {
|
||||
online_state = true;
|
||||
is_online = true;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObLSSwitchChecker::double_check_epoch() const
|
||||
int ObLSSwitchChecker::double_check_epoch(bool &is_online) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t switch_state = 0;
|
||||
if (OB_ISNULL(ls_)) {
|
||||
ret = OB_NOT_INIT;
|
||||
} else if (record_switch_epoch_ != ATOMIC_LOAD(&(ls_->switch_epoch_))) {
|
||||
} else if (FALSE_IT(switch_state = ATOMIC_LOAD(&(ls_->switch_epoch_)))) {
|
||||
} else if (OB_UNLIKELY(record_switch_epoch_ != switch_state)) {
|
||||
ret = OB_VERSION_NOT_MATCH;
|
||||
is_online = (switch_state & 1) ? false : true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ class ObLSSwitchChecker
|
||||
public:
|
||||
ObLSSwitchChecker() : ls_(nullptr), record_switch_epoch_(UINT64_MAX) {}
|
||||
int check_online(ObLS *ls);
|
||||
int check_ls_switch_state(ObLS *ls, bool &online_state);
|
||||
int double_check_epoch() const;
|
||||
int check_ls_switch_state(ObLS *ls, bool &is_online);
|
||||
int double_check_epoch(bool &is_online) const;
|
||||
private:
|
||||
ObLS *ls_;
|
||||
uint64_t record_switch_epoch_;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef INCLUDE_OB_TABLET_MDS_PART_IPP
|
||||
#define INCLUDE_OB_TABLET_MDS_PART_IPP
|
||||
#include "ob_i_tablet_mds_interface.h"
|
||||
#include "share/ob_errno.h"
|
||||
#endif
|
||||
namespace oceanbase
|
||||
{
|
||||
@ -353,7 +354,6 @@ int ObITabletMdsInterface::remove(const Key &key, mds::MdsCtx &ctx, const int64_
|
||||
MDS_TG(10_ms);
|
||||
int ret = OB_SUCCESS;
|
||||
mds::MdsTableHandle handle;
|
||||
ObLSSwitchChecker ls_switch_checker;
|
||||
if (CLICK_FAIL(get_mds_table_handle_(handle, true))) {
|
||||
MDS_LOG_SET(WARN, "failed to get_mds_table");
|
||||
} else if (!handle.is_valid()) {
|
||||
@ -382,7 +382,6 @@ int ObITabletMdsInterface::replay_remove(const Key &key, mds::MdsCtx &ctx, const
|
||||
MDS_TG(10_ms);
|
||||
int ret = OB_SUCCESS;
|
||||
mds::MdsTableHandle handle;
|
||||
ObLSSwitchChecker ls_switch_checker;
|
||||
if (CLICK_FAIL(get_mds_table_handle_(handle, true))) {
|
||||
MDS_LOG_SET(WARN, "failed to get_mds_table");
|
||||
} else if (!handle.is_valid()) {
|
||||
@ -407,9 +406,10 @@ int ObITabletMdsInterface::is_locked_by_others(bool &is_locked, const mds::MdsWr
|
||||
#define PRINT_WRAPPER KR(ret), K(*this), K(is_locked), K(self)
|
||||
MDS_TG(10_ms);
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_online = false;
|
||||
do {
|
||||
mds::MdsTableHandle handle;
|
||||
ObLSSwitchChecker ls_switch_checker;
|
||||
bool is_online = false;
|
||||
if (CLICK_FAIL(get_mds_table_handle_(handle, false))) {
|
||||
if (OB_ENTRY_NOT_EXIST != ret) {
|
||||
MDS_LOG_GET(WARN, "failed to get_mds_table");
|
||||
@ -436,12 +436,16 @@ int ObITabletMdsInterface::is_locked_by_others(bool &is_locked, const mds::MdsWr
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (is_online && MDS_FAIL(ls_switch_checker.double_check_epoch())) {
|
||||
if (is_online && MDS_FAIL(ls_switch_checker.double_check_epoch(is_online))) {
|
||||
if (!is_online) {
|
||||
ret = OB_LS_OFFLINE;
|
||||
}
|
||||
MDS_LOG_GET(WARN, "failed to double check ls online");
|
||||
} else {
|
||||
MDS_LOG_GET(TRACE, "success to get is locked by others state");
|
||||
}
|
||||
}
|
||||
} while (ret == OB_VERSION_NOT_MATCH && is_online);
|
||||
return ret;
|
||||
#undef PRINT_WRAPPER
|
||||
}
|
||||
@ -452,9 +456,10 @@ int ObITabletMdsInterface::get_latest(OP &&read_op, bool &is_committed, const in
|
||||
#define PRINT_WRAPPER KR(ret), K(*this), K(read_seq), K(typeid(OP).name())
|
||||
MDS_TG(10_ms);
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_online = false;
|
||||
do {
|
||||
mds::MdsTableHandle handle;
|
||||
ObLSSwitchChecker ls_switch_checker;
|
||||
bool is_online = false;
|
||||
if (CLICK_FAIL(get_mds_table_handle_(handle, false))) {
|
||||
if (OB_ENTRY_NOT_EXIST != ret) {
|
||||
MDS_LOG_GET(WARN, "failed to get_mds_table");
|
||||
@ -488,12 +493,16 @@ int ObITabletMdsInterface::get_latest(OP &&read_op, bool &is_committed, const in
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (is_online && MDS_FAIL(ls_switch_checker.double_check_epoch())) {
|
||||
if (is_online && MDS_FAIL(ls_switch_checker.double_check_epoch(is_online))) {
|
||||
if (!is_online) {
|
||||
ret = OB_LS_OFFLINE;
|
||||
}
|
||||
MDS_LOG_GET(WARN, "failed to double check ls online");
|
||||
} else {
|
||||
MDS_LOG_GET(TRACE, "success to get_latest");
|
||||
}
|
||||
}
|
||||
} while (ret == OB_VERSION_NOT_MATCH && is_online);
|
||||
return ret;
|
||||
#undef PRINT_WRAPPER
|
||||
}
|
||||
@ -507,9 +516,10 @@ int ObITabletMdsInterface::get_snapshot(OP &&read_op,
|
||||
#define PRINT_WRAPPER KR(ret), K(*this), K(snapshot), K(read_seq), K(typeid(OP).name())
|
||||
MDS_TG(10_ms);
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_online = false;
|
||||
do {
|
||||
mds::MdsTableHandle handle;
|
||||
ObLSSwitchChecker ls_switch_checker;
|
||||
bool is_online = false;
|
||||
if (CLICK_FAIL(get_mds_table_handle_(handle, false))) {
|
||||
if (OB_ENTRY_NOT_EXIST != ret) {
|
||||
MDS_LOG_GET(WARN, "failed to get_mds_table");
|
||||
@ -546,12 +556,16 @@ int ObITabletMdsInterface::get_snapshot(OP &&read_op,
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (is_online && MDS_FAIL(ls_switch_checker.double_check_epoch())) {
|
||||
if (is_online && MDS_FAIL(ls_switch_checker.double_check_epoch(is_online))) {
|
||||
if (!is_online) {
|
||||
ret = OB_LS_OFFLINE;
|
||||
}
|
||||
MDS_LOG_GET(WARN, "failed to double check ls online");
|
||||
} else {
|
||||
MDS_LOG_GET(TRACE, "success to get_snapshot");
|
||||
}
|
||||
}
|
||||
} while (ret == OB_VERSION_NOT_MATCH && is_online);
|
||||
return ret;
|
||||
#undef PRINT_WRAPPER
|
||||
}
|
||||
@ -566,9 +580,10 @@ int ObITabletMdsInterface::get_snapshot(const Key &key,
|
||||
#define PRINT_WRAPPER KR(ret), K(*this), K(key), K(snapshot), K(read_seq), K(typeid(OP).name())
|
||||
MDS_TG(10_ms);
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_online = false;
|
||||
do {
|
||||
mds::MdsTableHandle handle;
|
||||
ObLSSwitchChecker ls_switch_checker;
|
||||
bool is_online = false;
|
||||
if (CLICK_FAIL(get_mds_table_handle_(handle, false))) {
|
||||
if (OB_ENTRY_NOT_EXIST != ret) {
|
||||
MDS_LOG_GET(WARN, "failed to get_mds_table");
|
||||
@ -605,12 +620,16 @@ int ObITabletMdsInterface::get_snapshot(const Key &key,
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (is_online && MDS_FAIL(ls_switch_checker.double_check_epoch())) {
|
||||
if (is_online && MDS_FAIL(ls_switch_checker.double_check_epoch(is_online))) {
|
||||
if (!is_online) {
|
||||
ret = OB_LS_OFFLINE;
|
||||
}
|
||||
MDS_LOG_GET(WARN, "failed to double check ls online");
|
||||
} else {
|
||||
MDS_LOG_GET(TRACE, "success to get_snapshot");
|
||||
}
|
||||
}
|
||||
} while (ret == OB_VERSION_NOT_MATCH && is_online);
|
||||
return ret;
|
||||
#undef PRINT_WRAPPER
|
||||
}
|
||||
|
Reference in New Issue
Block a user