[BugFix] fix sanity core when freeze_stat is invalid

This commit is contained in:
obdev 2023-02-15 12:41:58 +00:00 committed by ob-robot
parent 0b0d502655
commit 4ca42f308e
3 changed files with 96 additions and 37 deletions

View File

@ -106,8 +106,6 @@ int ObAllVirtualMinorFreezeInfo::get_next_ls(ObLS *&ls)
int ObAllVirtualMinorFreezeInfo::process_curr_tenant(ObNewRow *&row)
{
int ret = OB_SUCCESS;
ObLS *ls = nullptr;
ObFreezer *freezer = nullptr;
ObFreezerStat freeze_stat;
if (NULL == allocator_) {
ret = OB_NOT_INIT;
@ -115,17 +113,10 @@ int ObAllVirtualMinorFreezeInfo::process_curr_tenant(ObNewRow *&row)
} else if (FALSE_IT(start_to_read_ = true)) {
} else if (ls_iter_guard_.get_ptr() == nullptr && OB_FAIL(MTL(ObLSService*)->get_ls_iter(ls_iter_guard_, ObLSGetMod::OBSERVER_MOD))) {
SERVER_LOG(WARN, "get_ls_iter fail", K(ret));
} else if (OB_FAIL(get_next_ls(ls))) {
} else if (OB_FAIL(get_next_freeze_stat(freeze_stat))) {
if (OB_ITER_END != ret) {
SERVER_LOG(WARN, "get_next_ls failed", K(ret));
SERVER_LOG(WARN, "get_next_freeze_stat failed", K(ret));
}
} else if (NULL == ls) {
ret = OB_ERR_UNEXPECTED;
SERVER_LOG(WARN, "ls shouldn't NULL here", K(ret));
} else if (FALSE_IT(freezer = ls->get_freezer())) {
} else if (!(freezer->get_stat().is_valid())) {
} else if (OB_FAIL(freezer->get_stat().deep_copy_to(freeze_stat))) {
SERVER_LOG(WARN, "fail to deep copy", K(ret));
} else {
int64_t freeze_clock = 0;
const int64_t col_count = output_column_ids_.count();
@ -240,40 +231,94 @@ int ObAllVirtualMinorFreezeInfo::process_curr_tenant(ObNewRow *&row)
return ret;
}
int ObAllVirtualMinorFreezeInfo::generate_memtables_info()
int ObAllVirtualMinorFreezeInfo::get_next_freeze_stat(ObFreezerStat &freeze_stat)
{
int ret = OB_SUCCESS;
ObLS *ls = nullptr;
ObFreezer *freezer = nullptr;
memset(memtables_info_string_, 0, OB_MAX_CHAR_LENGTH);
for (int i = 0; i < memtables_info_.count(); ++i) {
if (memtables_info_[i].is_valid()) {
// tablet_id
strcat(memtables_info_string_, "tablet_id:");
strcat(memtables_info_string_, to_cstring(memtables_info_[i].tablet_id_.id()));
// start_scn
strcat(memtables_info_string_, ", start_scn:");
strcat(memtables_info_string_, to_cstring(memtables_info_[i].start_scn_));
// end_scn
strcat(memtables_info_string_, ", end_scn:");
strcat(memtables_info_string_, to_cstring(memtables_info_[i].end_scn_));
// write_ref_cnt
strcat(memtables_info_string_, ", write_ref_cnt:");
strcat(memtables_info_string_, to_cstring(memtables_info_[i].write_ref_cnt_));
// unsubmitted_cnt
strcat(memtables_info_string_, ", unsubmitted_cnt:");
strcat(memtables_info_string_, to_cstring(memtables_info_[i].unsubmitted_cnt_));
// unsynced_cnt
strcat(memtables_info_string_, ", unsynced_cnt:");
strcat(memtables_info_string_, to_cstring(memtables_info_[i].unsynced_cnt_));
// current_right_boundary
strcat(memtables_info_string_, ", current_right_boundary:");
strcat(memtables_info_string_, to_cstring(memtables_info_[i].current_right_boundary_));
strcat(memtables_info_string_, "; ");
while (OB_SUCC(ret)) {
if (OB_FAIL(get_next_ls(ls))) {
if (OB_ITER_END != ret) {
SERVER_LOG(WARN, "get_next_ls failed", K(ret));
}
} else if (OB_ISNULL(ls)) {
ret = OB_ERR_UNEXPECTED;
SERVER_LOG(WARN, "ls shouldn't NULL here", K(ret));
} else if (FALSE_IT(freezer = ls->get_freezer())) {
} else if (OB_ISNULL(freezer)) {
ret = OB_ERR_UNEXPECTED;
SERVER_LOG(WARN, "ls shouldn't NULL here", K(ret));
} else if (OB_FAIL(freezer->get_stat().deep_copy_to(freeze_stat))) {
SERVER_LOG(WARN, "fail to deep copy", K(ret));
} else if (!(freeze_stat.is_valid())) {
SERVER_LOG(WARN, "freeze_stat is invalid", KP(ls), KP(freezer));
} else {
// freeze_stat is valid
break;
}
}
return ret;
}
int ObAllVirtualMinorFreezeInfo::generate_memtables_info()
{
int ret = OB_SUCCESS;
memset(memtables_info_string_, 0, OB_MAX_CHAR_LENGTH);
int memtable_info_count = memtables_info_.count();
// leave space for '\0'
int64_t size = OB_MAX_CHAR_LENGTH - 1;
for (int i = 0; i < memtable_info_count && size > 0; ++i) {
if (memtables_info_[i].is_valid()) {
// tablet_id
append_memtable_info_string(MEMTABLE_INFO_MEMBER[0], to_cstring(memtables_info_[i].tablet_id_.id()), size);
// start_scn
append_memtable_info_string(MEMTABLE_INFO_MEMBER[1], to_cstring(memtables_info_[i].start_scn_), size);
// end_scn
append_memtable_info_string(MEMTABLE_INFO_MEMBER[2], to_cstring(memtables_info_[i].end_scn_), size);
// write_ref_cnt
append_memtable_info_string(MEMTABLE_INFO_MEMBER[3], to_cstring(memtables_info_[i].write_ref_cnt_), size);
// unsubmitted_cnt
append_memtable_info_string(MEMTABLE_INFO_MEMBER[4], to_cstring(memtables_info_[i].unsubmitted_cnt_), size);
// unsynced_cnt
append_memtable_info_string(MEMTABLE_INFO_MEMBER[5], to_cstring(memtables_info_[i].unsynced_cnt_), size);
// current_right_boundary
append_memtable_info_string(MEMTABLE_INFO_MEMBER[6], to_cstring(memtables_info_[i].current_right_boundary_), size);
// end of the memtable_info
if (size >= 2) {
strcat(memtables_info_string_, "; ");
size = size - 2;
} else if (size < 0) {
SERVER_LOG(WARN, "size is invalid", K(size), K(memtable_info_count), K(memtables_info_string_));
}
}
}
return ret;
}
void ObAllVirtualMinorFreezeInfo::append_memtable_info_string(const char *name, const char *str, int64_t &size)
{
if (size > 0) {
int64_t name_len = MIN(size, strlen(name));
strncat(memtables_info_string_, name, name_len);
size = size - name_len;
int64_t mark_len = MIN(size, 1);
strncat(memtables_info_string_, ":", mark_len);
size = size - mark_len;
int64_t str_len = MIN(size, strlen(str));
strncat(memtables_info_string_, str, str_len);
size = size - str_len;
mark_len = MIN(size, 1);
strncat(memtables_info_string_, " ", mark_len);
size = size - mark_len;
}
}
}/* ns observer*/
}/* ns oceanbase */

View File

@ -46,6 +46,8 @@ private:
virtual void release_last_tenant() override;
int get_next_ls(ObLS *&ls);
int generate_memtables_info();
int get_next_freeze_stat(ObFreezerStat &freeze_stat);
void append_memtable_info_string(const char *name, const char *str, int64_t &size);
private:
common::ObAddr addr_;
int64_t ls_id_;
@ -54,6 +56,17 @@ private:
ObStringHolder diagnose_info_;
common::ObSArray<ObFrozenMemtableInfo> memtables_info_;
char memtables_info_string_[OB_MAX_CHAR_LENGTH];
private:
// dont forget update this if add more member of memtable_info
static constexpr const char *const MEMTABLE_INFO_MEMBER[] = {
"tablet_id",
"start_scn",
"end_scn",
"write_ref_cnt",
"unsubmitted_cnt",
"unsynced_cnt",
"current_right_boundary"
};
private:
DISALLOW_COPY_AND_ASSIGN(ObAllVirtualMinorFreezeInfo);
};

View File

@ -324,6 +324,7 @@ share::SCN ObFreezerStat::get_freeze_snapshot_version()
int ObFreezerStat::deep_copy_to(ObFreezerStat &other)
{
int ret = OB_SUCCESS;
other.reset();
ObSpinLockGuard guard(lock_);
other.set_tablet_id(tablet_id_);
other.set_is_force(is_force_);