patch 4.0
This commit is contained in:
@ -22,25 +22,30 @@
|
||||
#include "rootserver/ob_zone_manager.h"
|
||||
#include "observer/ob_server_struct.h"
|
||||
|
||||
namespace oceanbase {
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace oceanbase;
|
||||
using namespace oceanbase::common;
|
||||
namespace share {
|
||||
namespace share
|
||||
{
|
||||
using namespace schema;
|
||||
|
||||
// when invoked by DDL, zone_region_list_ shall not be NULL
|
||||
int ObPrimaryZoneUtil::init(const common::ObIArray<common::ObString>& zone_list)
|
||||
int ObPrimaryZoneUtil::init(
|
||||
const common::ObIArray<common::ObString> &zone_list)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(is_inited_)) {
|
||||
ret = OB_INIT_TWICE;
|
||||
LOG_WARN("init twice", K(ret));
|
||||
} else if (OB_UNLIKELY(no_need_to_check_primary_zone(primary_zone_)) || OB_UNLIKELY(zone_list.count() <= 0) ||
|
||||
OB_UNLIKELY(NULL == zone_region_list_)) {
|
||||
} else if (OB_UNLIKELY(no_need_to_check_primary_zone(primary_zone_))
|
||||
|| OB_UNLIKELY(zone_list.count() <= 0)
|
||||
|| OB_UNLIKELY(NULL == zone_region_list_)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(primary_zone_), "zone list count", zone_list.count(), KP(zone_region_list_));
|
||||
LOG_WARN("invalid argument", K(ret), K(primary_zone_),
|
||||
"zone list count", zone_list.count(), KP(zone_region_list_));
|
||||
} else {
|
||||
int64_t len = primary_zone_.length();
|
||||
int64_t len = strlen(primary_zone_.ptr());
|
||||
if (common::MAX_ZONE_LENGTH < len) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("primary_zone length overflowed", KR(ret), K(len), "max_zone_length", MAX_ZONE_LENGTH);
|
||||
@ -54,8 +59,7 @@ int ObPrimaryZoneUtil::init(const common::ObIArray<common::ObString>& zone_list)
|
||||
LOG_WARN("fail to assign zone", K(ret));
|
||||
} else if (OB_FAIL(zone_list_.push_back(zone))) {
|
||||
LOG_WARN("fail to push back", K(ret));
|
||||
} else {
|
||||
} // no more to do
|
||||
} else {} // no more to do
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
@ -66,18 +70,21 @@ int ObPrimaryZoneUtil::init(const common::ObIArray<common::ObString>& zone_list)
|
||||
}
|
||||
|
||||
// when invoked by DDL, zone_region_list_ shall not be NULL
|
||||
int ObPrimaryZoneUtil::init(const common::ObIArray<common::ObZone>& zone_list)
|
||||
int ObPrimaryZoneUtil::init(
|
||||
const common::ObIArray<common::ObZone> &zone_list)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(is_inited_)) {
|
||||
ret = OB_INIT_TWICE;
|
||||
LOG_WARN("init twice", K(ret));
|
||||
} else if (OB_UNLIKELY(no_need_to_check_primary_zone(primary_zone_)) || OB_UNLIKELY(zone_list.count() <= 0) ||
|
||||
OB_UNLIKELY(NULL == zone_region_list_)) {
|
||||
} else if (OB_UNLIKELY(no_need_to_check_primary_zone(primary_zone_))
|
||||
|| OB_UNLIKELY(zone_list.count() <= 0)
|
||||
|| OB_UNLIKELY(NULL == zone_region_list_)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(primary_zone_), "zone list count", zone_list.count(), KP(zone_region_list_));
|
||||
LOG_WARN("invalid argument", K(ret), K(primary_zone_),
|
||||
"zone list count", zone_list.count(), KP(zone_region_list_));
|
||||
} else {
|
||||
int64_t len = primary_zone_.length();
|
||||
int64_t len = strlen(primary_zone_.ptr());
|
||||
if (common::MAX_ZONE_LENGTH < len) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("primary_zone length overflowed", KR(ret), K(len), "max_zone_length", MAX_ZONE_LENGTH);
|
||||
@ -87,8 +94,7 @@ int ObPrimaryZoneUtil::init(const common::ObIArray<common::ObZone>& zone_list)
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < zone_list.count(); ++i) {
|
||||
if (OB_FAIL(zone_list_.push_back(zone_list.at(i)))) {
|
||||
LOG_WARN("fail to push back", K(ret));
|
||||
} else {
|
||||
} // no more to do
|
||||
} else {} // no more to do
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
@ -105,11 +111,12 @@ int ObPrimaryZoneUtil::init()
|
||||
if (OB_UNLIKELY(is_inited_)) {
|
||||
ret = OB_INIT_TWICE;
|
||||
LOG_WARN("init twice", K(ret));
|
||||
} else if (OB_UNLIKELY(no_need_to_check_primary_zone(primary_zone_)) || OB_UNLIKELY(NULL != zone_region_list_)) {
|
||||
} else if (OB_UNLIKELY(no_need_to_check_primary_zone(primary_zone_))
|
||||
|| OB_UNLIKELY(NULL != zone_region_list_)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(primary_zone_), KP(zone_region_list_));
|
||||
} else {
|
||||
int64_t len = primary_zone_.length();
|
||||
int64_t len = strlen(primary_zone_.ptr());
|
||||
if (common::MAX_ZONE_LENGTH < len) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("primary_zone length overflowed", KR(ret), K(len), "max_zone_length", MAX_ZONE_LENGTH);
|
||||
@ -150,7 +157,8 @@ int ObPrimaryZoneUtil::construct_zone_array()
|
||||
const int64_t end = strlen(primary_zone_str_);
|
||||
share::schema::ObZoneScore zone_score;
|
||||
zone_array_.reset();
|
||||
while (OB_SUCC(ret) && OB_SUCC(get_next_zone_score(cursor, end, zone_score))) {
|
||||
while (OB_SUCC(ret)
|
||||
&& OB_SUCC(get_next_zone_score(cursor, end, zone_score))) {
|
||||
bool zone_exist = false;
|
||||
if (OB_FAIL(check_zone_exist(zone_score.zone_, zone_exist))) {
|
||||
LOG_WARN("fail to check zone exist", K(ret));
|
||||
@ -159,8 +167,7 @@ int ObPrimaryZoneUtil::construct_zone_array()
|
||||
LOG_WARN("zone not exist", K(ret), K(zone_score), K(primary_zone_str_), K(zone_list_));
|
||||
} else if (OB_FAIL(zone_array_.push_back(zone_score))) {
|
||||
LOG_WARN("fail to push back zone str", K(ret));
|
||||
} else {
|
||||
} // ok
|
||||
} else {} // ok
|
||||
}
|
||||
if (OB_ITER_END == ret) {
|
||||
ret = OB_SUCCESS;
|
||||
@ -170,8 +177,7 @@ int ObPrimaryZoneUtil::construct_zone_array()
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < zone_array_.count(); ++i) {
|
||||
if (OB_FAIL(tmp_zone_array.push_back(zone_array_.at(i).zone_))) {
|
||||
LOG_WARN("fail to push back", K(ret));
|
||||
} else {
|
||||
} // no more
|
||||
} else {} // no more
|
||||
}
|
||||
std::sort(tmp_zone_array.begin(), tmp_zone_array.end());
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < tmp_zone_array.count() - 1; ++i) {
|
||||
@ -191,13 +197,11 @@ int ObPrimaryZoneUtil::construct_normalized_zone_array()
|
||||
if (NULL == zone_region_list_) {
|
||||
if (OB_FAIL(assign_zone_array_to_normalized())) {
|
||||
LOG_WARN("fail to assign zone array to normalized", K(ret));
|
||||
} else {
|
||||
} // no more to do
|
||||
} else {} // no more to do
|
||||
} else {
|
||||
if (OB_FAIL(construct_normalized_with_zone_region_list())) {
|
||||
LOG_WARN("fail to construct normalized with zon region list", K(ret));
|
||||
} else {
|
||||
} // no more to do
|
||||
} else {} // no more to do
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -209,16 +213,15 @@ int ObPrimaryZoneUtil::assign_zone_array_to_normalized()
|
||||
int ret = OB_SUCCESS;
|
||||
ZoneRegionScore zone_region_score;
|
||||
for (int i = 0; i < zone_array_.count() && OB_SUCC(ret); ++i) {
|
||||
const share::schema::ObZoneScore& zone_score = zone_array_.at(i);
|
||||
const common::ObZone& this_zone = zone_score.zone_;
|
||||
const share::schema::ObZoneScore &zone_score = zone_array_.at(i);
|
||||
const common::ObZone &this_zone = zone_score.zone_;
|
||||
int64_t this_score = zone_score.score_;
|
||||
zone_region_score.reset();
|
||||
zone_region_score.zone_score_ = this_score;
|
||||
zone_region_score.zone_region_.zone_ = this_zone;
|
||||
if (OB_FAIL(normalized_zone_array_.push_back(zone_region_score))) {
|
||||
LOG_WARN("fail to push back", K(ret));
|
||||
} else {
|
||||
} // no more to do
|
||||
} else {} // no more to do
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -233,12 +236,13 @@ int ObPrimaryZoneUtil::construct_normalized_with_zone_region_list()
|
||||
LOG_WARN("fail to construct basic normalized zone array", K(ret));
|
||||
} else if (OB_FAIL(do_construct_normalized_zone_array())) {
|
||||
LOG_WARN("fail to do construct normalized_zone_array", K(ret));
|
||||
} else {
|
||||
} // do nothing
|
||||
} else {} // do nothing
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPrimaryZoneUtil::check_zone_exist(const common::ObString& zone, bool& zone_exist)
|
||||
int ObPrimaryZoneUtil::check_zone_exist(
|
||||
const common::ObString &zone,
|
||||
bool &zone_exist)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(!is_inited_)) {
|
||||
@ -254,47 +258,48 @@ int ObPrimaryZoneUtil::check_zone_exist(const common::ObString& zone, bool& zone
|
||||
// invoked by DDL
|
||||
zone_exist = false;
|
||||
for (int64_t i = 0; i < zone_list_.count() && !zone_exist; ++i) {
|
||||
const ObZone& this_zone = zone_list_.at(i);
|
||||
const ObZone &this_zone = zone_list_.at(i);
|
||||
zone_exist = (ObString(this_zone.size(), this_zone.ptr()) == zone);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPrimaryZoneUtil::output_normalized_primary_zone(char* buf, int64_t buf_len, int64_t& pos)
|
||||
int ObPrimaryZoneUtil::output_normalized_primary_zone(
|
||||
char *buf,
|
||||
int64_t buf_len,
|
||||
int64_t &pos)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(!is_inited_)) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("not init", K(ret));
|
||||
} else if (OB_UNLIKELY(!check_and_parse_finished_) || OB_UNLIKELY(normalized_zone_array_.count() <= 0)) {
|
||||
} else if (OB_UNLIKELY(!check_and_parse_finished_)
|
||||
|| OB_UNLIKELY(normalized_zone_array_.count() <= 0)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("cannot output normalized primary zone",
|
||||
K(ret),
|
||||
K(check_and_parse_finished_),
|
||||
" normalized zone array count",
|
||||
normalized_zone_array_.count());
|
||||
K(ret), K(check_and_parse_finished_),
|
||||
" normalized zone array count", normalized_zone_array_.count());
|
||||
} else {
|
||||
bool start_format = false;
|
||||
int64_t prev_zone_score = normalized_zone_array_.at(0).zone_score_;
|
||||
int64_t prev_region_score = normalized_zone_array_.at(0).region_score_;
|
||||
const char* separator_token = NULL;
|
||||
const char *separator_token = NULL;
|
||||
for (int64_t i = 0; i < normalized_zone_array_.count() && OB_SUCC(ret); ++i) {
|
||||
ZoneRegionScore& cur_zone_region_score = normalized_zone_array_.at(i);
|
||||
if (INT64_MAX == cur_zone_region_score.region_score_ && INT64_MAX == cur_zone_region_score.zone_score_) {
|
||||
ZoneRegionScore &cur_zone_region_score = normalized_zone_array_.at(i);
|
||||
if (INT64_MAX == cur_zone_region_score.region_score_
|
||||
&& INT64_MAX == cur_zone_region_score.zone_score_) {
|
||||
// ignore this zone
|
||||
} else {
|
||||
const bool same_p = (cur_zone_region_score.zone_score_ == prev_zone_score &&
|
||||
cur_zone_region_score.region_score_ == prev_region_score);
|
||||
const bool same_p = (cur_zone_region_score.zone_score_ == prev_zone_score
|
||||
&& cur_zone_region_score.region_score_ == prev_region_score);
|
||||
separator_token = (same_p ? "," : ";");
|
||||
if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%s", (!start_format ? "" : separator_token)))) {
|
||||
if (OB_FAIL(databuff_printf(buf, buf_len, pos,
|
||||
"%s", (!start_format ? "" : separator_token)))) {
|
||||
LOG_WARN("fail to format separator", K(ret));
|
||||
} else if (OB_FAIL(databuff_printf(buf,
|
||||
buf_len,
|
||||
pos,
|
||||
"%.*s",
|
||||
static_cast<int32_t>(cur_zone_region_score.zone_region_.zone_.size()),
|
||||
cur_zone_region_score.zone_region_.zone_.ptr()))) {
|
||||
} else if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%.*s",
|
||||
static_cast<int32_t>(cur_zone_region_score.zone_region_.zone_.size()),
|
||||
cur_zone_region_score.zone_region_.zone_.ptr()))) {
|
||||
LOG_WARN("fail to format zone", K(ret));
|
||||
} else {
|
||||
start_format = true;
|
||||
@ -302,19 +307,25 @@ int ObPrimaryZoneUtil::output_normalized_primary_zone(char* buf, int64_t buf_len
|
||||
prev_region_score = cur_zone_region_score.region_score_;
|
||||
}
|
||||
}
|
||||
} // for
|
||||
} // for
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ObPrimaryZoneUtil::jump_over_blanks(int64_t& cursor, const int64_t end)
|
||||
void ObPrimaryZoneUtil::jump_over_blanks(
|
||||
int64_t &cursor,
|
||||
const int64_t end)
|
||||
{
|
||||
while (cursor < end && primary_zone_str_[cursor] == BLANK_TOKEN) {
|
||||
while (cursor < end
|
||||
&& primary_zone_str_[cursor] == BLANK_TOKEN) {
|
||||
++cursor;
|
||||
}
|
||||
}
|
||||
|
||||
int ObPrimaryZoneUtil::get_next_zone_score(int64_t& cursor, const int64_t end, share::schema::ObZoneScore& zone_score)
|
||||
int ObPrimaryZoneUtil::get_next_zone_score(
|
||||
int64_t &cursor,
|
||||
const int64_t end,
|
||||
share::schema::ObZoneScore &zone_score)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
jump_over_blanks(cursor, end);
|
||||
@ -326,8 +337,10 @@ int ObPrimaryZoneUtil::get_next_zone_score(int64_t& cursor, const int64_t end, s
|
||||
} else {
|
||||
zone_score.reset();
|
||||
int64_t tmp_cursor = cursor;
|
||||
while (tmp_cursor < end && primary_zone_str_[tmp_cursor] != BLANK_TOKEN &&
|
||||
primary_zone_str_[tmp_cursor] != COMMA_TOKEN && primary_zone_str_[tmp_cursor] != SEMI_COLON_TOKEN) {
|
||||
while (tmp_cursor < end
|
||||
&& primary_zone_str_[tmp_cursor] != BLANK_TOKEN
|
||||
&& primary_zone_str_[tmp_cursor] != COMMA_TOKEN
|
||||
&& primary_zone_str_[tmp_cursor] != SEMI_COLON_TOKEN) {
|
||||
++tmp_cursor;
|
||||
}
|
||||
int64_t len = tmp_cursor - cursor;
|
||||
@ -342,12 +355,12 @@ int ObPrimaryZoneUtil::get_next_zone_score(int64_t& cursor, const int64_t end, s
|
||||
if (OB_SUCC(ret)) {
|
||||
cursor = tmp_cursor;
|
||||
jump_over_blanks(cursor, end);
|
||||
if (cursor >= end) { // reach end
|
||||
if (cursor >= end) { // reach end
|
||||
} else if (COMMA_TOKEN == primary_zone_str_[cursor]) {
|
||||
++cursor; // no need to update zone_score_, just inc cursor and pass COMMA TOKEN
|
||||
++cursor; // no need to update zone_score_, just inc cursor and pass COMMA TOKEN
|
||||
} else if (SEMI_COLON_TOKEN == primary_zone_str_[cursor]) {
|
||||
++cursor; // inc cursor and pass SEMI COLON TOKEN
|
||||
++zone_score_; // come across SEMI COLON TOKEN, need to update zone_score_
|
||||
++cursor; // inc cursor and pass SEMI COLON TOKEN
|
||||
++zone_score_; // come across SEMI COLON TOKEN, need to update zone_score_
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid primary zone", K(ret));
|
||||
@ -367,18 +380,17 @@ int ObPrimaryZoneUtil::construct_basic_normalized_zone_array()
|
||||
LOG_WARN("zone region list null", K(ret), KP(zone_region_list_));
|
||||
} else {
|
||||
for (int64_t i = 0; i < zone_region_list_->count() && OB_SUCC(ret); ++i) {
|
||||
const common::ObZone& zone = zone_region_list_->at(i).zone_;
|
||||
const common::ObZone &zone = zone_region_list_->at(i).zone_;
|
||||
const common::ObString zone_str(zone.size(), zone.ptr());
|
||||
bool zone_exist = false;
|
||||
if (OB_FAIL(check_zone_exist(zone_str, zone_exist))) {
|
||||
LOG_WARN("fail to check zone exist", K(ret));
|
||||
} else if (zone_exist) {
|
||||
if (OB_FAIL(normalized_zone_array_.push_back(ZoneRegionScore(zone_region_list_->at(i))))) {
|
||||
if (OB_FAIL(normalized_zone_array_.push_back(
|
||||
ZoneRegionScore(zone_region_list_->at(i))))) {
|
||||
LOG_WARN("fail to push back", K(ret));
|
||||
} else {
|
||||
} // no more to do
|
||||
} else {
|
||||
} // do not exist in zone list, do nothing
|
||||
} else {} // no more to do
|
||||
} else {} // do not exist in zone list, do nothing
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -387,15 +399,14 @@ int ObPrimaryZoneUtil::construct_basic_normalized_zone_array()
|
||||
int ObPrimaryZoneUtil::do_construct_normalized_zone_array()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(NULL == zone_region_list_)) { // defensive check
|
||||
if (OB_UNLIKELY(NULL == zone_region_list_)) { // defensive check
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("zone region list null", K(ret), KP(zone_region_list_));
|
||||
} else if (OB_FAIL(prefill_zone_region_score())) {
|
||||
LOG_WARN("fail to prefill zone region score", K(ret));
|
||||
} else if (OB_FAIL(update_region_score())) {
|
||||
LOG_WARN("fail to update region score", K(ret));
|
||||
} else {
|
||||
} // no more to do
|
||||
} else {} // no more to do
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -404,20 +415,19 @@ int ObPrimaryZoneUtil::prefill_zone_region_score()
|
||||
// prefill the zone score in zone_array_ to normalized_zone_array_,
|
||||
// set region_score_ to zone_score_ temporarily, region_score_ needs to by modified afterwards
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(NULL == zone_region_list_)) { // defensive check
|
||||
if (OB_UNLIKELY(NULL == zone_region_list_)) { // defensive check
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("zone region list null", K(ret), KP(zone_region_list_));
|
||||
} else {
|
||||
for (int64_t i = 0; i < zone_array_.count() && OB_SUCC(ret); ++i) {
|
||||
const share::schema::ObZoneScore& zone_score = zone_array_.at(i);
|
||||
const common::ObZone& this_zone = zone_score.zone_;
|
||||
const share::schema::ObZoneScore &zone_score = zone_array_.at(i);
|
||||
const common::ObZone &this_zone = zone_score.zone_;
|
||||
for (int64_t j = 0; j < normalized_zone_array_.count(); ++j) {
|
||||
if (this_zone == normalized_zone_array_.at(j).zone_region_.zone_.ptr()) {
|
||||
normalized_zone_array_.at(j).zone_score_ = zone_score.score_;
|
||||
normalized_zone_array_.at(j).region_score_ = zone_score.score_;
|
||||
break;
|
||||
} else {
|
||||
} // go on find
|
||||
} else {} // go on find
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -458,20 +468,22 @@ int ObPrimaryZoneUtil::construct_full_zone_array()
|
||||
std::sort(normalized_zone_array_.begin(), normalized_zone_array_.end(), final_cmp);
|
||||
if (OB_UNLIKELY(normalized_zone_array_.count() <= 0)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("cannot construct full zone array", K(ret), "normalized zone array count", normalized_zone_array_.count());
|
||||
LOG_WARN("cannot construct full zone array", K(ret),
|
||||
"normalized zone array count", normalized_zone_array_.count());
|
||||
} else {
|
||||
int64_t zone_p_score = 0;
|
||||
int64_t prev_zone_score = normalized_zone_array_.at(0).zone_score_;
|
||||
int64_t prev_region_score = normalized_zone_array_.at(0).region_score_;
|
||||
for (int64_t i = 0; i < normalized_zone_array_.count() && OB_SUCC(ret); ++i) {
|
||||
const ZoneRegionScore& cur_zone_region_score = normalized_zone_array_.at(i);
|
||||
const ObZone& zone = cur_zone_region_score.zone_region_.zone_;
|
||||
if (INT64_MAX == cur_zone_region_score.region_score_ && INT64_MAX == cur_zone_region_score.zone_score_) {
|
||||
const ZoneRegionScore &cur_zone_region_score = normalized_zone_array_.at(i);
|
||||
const ObZone &zone = cur_zone_region_score.zone_region_.zone_;
|
||||
if (INT64_MAX == cur_zone_region_score.region_score_
|
||||
&& INT64_MAX == cur_zone_region_score.zone_score_) {
|
||||
// ignore this zone
|
||||
} else {
|
||||
ObString zone_str;
|
||||
if (cur_zone_region_score.zone_score_ != prev_zone_score ||
|
||||
cur_zone_region_score.region_score_ != prev_region_score) {
|
||||
if (cur_zone_region_score.zone_score_ != prev_zone_score
|
||||
|| cur_zone_region_score.region_score_ != prev_region_score) {
|
||||
++zone_p_score;
|
||||
}
|
||||
if (OB_FAIL(ob_write_string(allocator_, ObString(zone.size(), zone.ptr()), zone_str))) {
|
||||
@ -488,7 +500,9 @@ int ObPrimaryZoneUtil::construct_full_zone_array()
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ObPrimaryZoneUtil::RegionScoreCmp::operator()(const ZoneRegionScore& left, const ZoneRegionScore& right)
|
||||
bool ObPrimaryZoneUtil::RegionScoreCmp::operator()(
|
||||
const ZoneRegionScore &left,
|
||||
const ZoneRegionScore &right)
|
||||
{
|
||||
bool bool_ret = false;
|
||||
if (left.zone_region_.region_ < right.zone_region_.region_) {
|
||||
@ -505,7 +519,9 @@ bool ObPrimaryZoneUtil::RegionScoreCmp::operator()(const ZoneRegionScore& left,
|
||||
return bool_ret;
|
||||
}
|
||||
|
||||
bool ObPrimaryZoneUtil::FinalCmp::operator()(const ZoneRegionScore& left, const ZoneRegionScore& right)
|
||||
bool ObPrimaryZoneUtil::FinalCmp::operator()(
|
||||
const ZoneRegionScore &left,
|
||||
const ZoneRegionScore &right)
|
||||
{
|
||||
bool bool_ret = false;
|
||||
if (left.region_score_ < right.region_score_) {
|
||||
@ -529,11 +545,12 @@ bool ObPrimaryZoneUtil::FinalCmp::operator()(const ZoneRegionScore& left, const
|
||||
}
|
||||
|
||||
bool ObPrimaryZoneUtil::check_primary_zone_equal(
|
||||
const share::schema::ObPrimaryZone& left, const share::schema::ObPrimaryZone& right)
|
||||
const share::schema::ObPrimaryZone &left,
|
||||
const share::schema::ObPrimaryZone &right)
|
||||
{
|
||||
bool is_equal = true;
|
||||
const common::ObIArray<ObZoneScore>& left_primary_zone_array = left.get_primary_zone_array();
|
||||
const common::ObIArray<ObZoneScore>& right_primary_zone_array = right.get_primary_zone_array();
|
||||
const common::ObIArray<ObZoneScore> &left_primary_zone_array = left.get_primary_zone_array();
|
||||
const common::ObIArray<ObZoneScore> &right_primary_zone_array = right.get_primary_zone_array();
|
||||
if (left_primary_zone_array.count() != right_primary_zone_array.count()) {
|
||||
is_equal = false;
|
||||
} else if (0 == left_primary_zone_array.count()) {
|
||||
@ -542,8 +559,8 @@ bool ObPrimaryZoneUtil::check_primary_zone_equal(
|
||||
for (int i = 0; is_equal && i < left_primary_zone_array.count(); ++i) {
|
||||
is_equal = false;
|
||||
for (int j = 0; !is_equal && j < right_primary_zone_array.count(); ++j) {
|
||||
if (left_primary_zone_array.at(i).zone_ == right_primary_zone_array.at(j).zone_ &&
|
||||
left_primary_zone_array.at(i).score_ == right_primary_zone_array.at(j).score_) {
|
||||
if (left_primary_zone_array.at(i).zone_ == right_primary_zone_array.at(j).zone_
|
||||
&& left_primary_zone_array.at(i).score_ == right_primary_zone_array.at(j).score_) {
|
||||
is_equal = true;
|
||||
}
|
||||
}
|
||||
@ -552,15 +569,17 @@ bool ObPrimaryZoneUtil::check_primary_zone_equal(
|
||||
return is_equal;
|
||||
}
|
||||
|
||||
int ObPrimaryZoneUtil::check_primary_zone_equal(share::schema::ObSchemaGetterGuard& schema_guard,
|
||||
const share::schema::ObPartitionSchema& left, const share::schema::ObPartitionSchema& right, bool& is_match)
|
||||
int ObPrimaryZoneUtil::check_primary_zone_equal(
|
||||
share::schema::ObSchemaGetterGuard &schema_guard,
|
||||
const share::schema::ObPartitionSchema &left,
|
||||
const share::schema::ObPartitionSchema &right,
|
||||
bool &is_match)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
is_match = false;
|
||||
ObSchema left_schema;
|
||||
ObSchema right_schema;
|
||||
ObPrimaryZone left_primary_zone(&left_schema);
|
||||
ObPrimaryZone right_primary_zone(&right_schema);
|
||||
ObArenaAllocator allocator("PrimaryZone");
|
||||
ObPrimaryZone left_primary_zone(allocator);
|
||||
ObPrimaryZone right_primary_zone(allocator);
|
||||
ObArray<share::ObZoneReplicaNumSet> left_zone_locality;
|
||||
ObArray<share::ObZoneReplicaNumSet> right_zone_locality;
|
||||
// some primary_zone_str in __all_table originated from an old cluster
|
||||
@ -576,84 +595,167 @@ int ObPrimaryZoneUtil::check_primary_zone_equal(share::schema::ObSchemaGetterGua
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPrimaryZoneUtil::get_pg_integrated_primary_zone(share::schema::ObSchemaGetterGuard& schema_guard,
|
||||
const share::schema::ObPartitionSchema& partition_schema, common::ObZone& primary_zone_str)
|
||||
int ObPrimaryZoneUtil::get_tenant_primary_zone_array(
|
||||
const share::schema::ObTenantSchema &tenant_schema,
|
||||
common::ObIArray<common::ObZone> &primary_zone_array)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
uint64_t tenant_id = extract_tenant_id(partition_schema.get_table_id());
|
||||
bool small_tenant = false;
|
||||
ObSchema tmp_schema;
|
||||
ObPrimaryZone primary_zone_schema(&tmp_schema);
|
||||
primary_zone_str.reset();
|
||||
if (OB_FAIL(rootserver::ObTenantUtils::check_small_tenant(tenant_id, small_tenant))) {
|
||||
LOG_WARN("fail to check small tenant", K(ret));
|
||||
} else if (small_tenant) {
|
||||
const ObTenantSchema* tenant_schema = NULL;
|
||||
if (OB_FAIL(schema_guard.get_tenant_info(tenant_id, tenant_schema))) {
|
||||
LOG_WARN("fail to get tenant scehma", K(ret));
|
||||
} else if (OB_UNLIKELY(NULL == tenant_schema)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("tenant not exist", K(ret));
|
||||
} else if (OB_FAIL(tenant_schema->get_primary_zone_inherit(schema_guard, primary_zone_schema))) {
|
||||
LOG_WARN("fail to get primary zone inherit", K(ret), K(tenant_id));
|
||||
}
|
||||
common::ObSEArray<share::schema::ObZoneScore, DEFAULT_ZONE_COUNT> zone_score_list;
|
||||
ObArenaAllocator allocator("PrimaryZone");
|
||||
ObPrimaryZone primary_zone_schema(allocator);
|
||||
ObArray<share::ObZoneReplicaAttrSet> zone_locality;
|
||||
|
||||
if (OB_UNLIKELY(!tenant_schema.is_valid())) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("tenant schema is invalid", KR(ret), K(tenant_schema));
|
||||
} else if (OB_FAIL(get_tenant_primary_zone_score(tenant_schema,
|
||||
primary_zone_schema, zone_locality, zone_score_list))) {
|
||||
LOG_WARN("failed to get tenant primary zone score", KR(ret), K(tenant_schema));
|
||||
} else {
|
||||
if (OB_FAIL(partition_schema.get_primary_zone_inherit(schema_guard, primary_zone_schema))) {
|
||||
LOG_WARN(
|
||||
"fail to get table primary_zone inherit", K(ret), "partition_entity_id", partition_schema.get_table_id());
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
const int64_t DEFAULT_ZONE_NUM = 7;
|
||||
common::ObSEArray<common::ObZone, DEFAULT_ZONE_NUM> zone_list;
|
||||
common::ObSEArray<share::ObZoneReplicaNumSet, DEFAULT_ZONE_NUM> zone_locality;
|
||||
if (OB_FAIL(partition_schema.get_zone_list(schema_guard, zone_list))) {
|
||||
LOG_WARN("fail to get zone list", K(ret));
|
||||
} else if (OB_UNLIKELY(zone_list.count() <= 0)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("zone list count unexpected", K(ret));
|
||||
} else if (OB_FAIL(partition_schema.get_zone_replica_attr_array_inherit(schema_guard, zone_locality))) {
|
||||
LOG_WARN("fail to get zone replica num array inherit", K(ret));
|
||||
} else if (OB_FAIL(generate_integrated_primary_zone_str(
|
||||
primary_zone_schema, zone_list, zone_locality, primary_zone_str))) {
|
||||
LOG_WARN("fail to generate integrated primary zone str", K(ret));
|
||||
int64_t first_score = -1;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < zone_score_list.count(); ++i) {
|
||||
const share::schema::ObZoneScore &zone_score = zone_score_list.at(i);
|
||||
if (-1 == first_score) {
|
||||
first_score = zone_score.score_;
|
||||
}
|
||||
if (zone_score.score_ == first_score) {
|
||||
ObZone zone(zone_score.zone_);
|
||||
if (OB_FAIL(primary_zone_array.push_back(zone))) {
|
||||
LOG_WARN("failed to pushback primary zone", KR(ret), K(zone_score), K(zone));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPrimaryZoneUtil::get_pg_integrated_primary_zone(share::schema::ObSchemaGetterGuard& schema_guard,
|
||||
const uint64_t partition_entity_id, common::ObZone& primary_zone_str)
|
||||
int ObPrimaryZoneUtil::get_tenant_primary_zone_score(
|
||||
const share::schema::ObTenantSchema &tenant_schema,
|
||||
share::schema::ObPrimaryZone &primary_zone_schema,
|
||||
common::ObIArray<share::ObZoneReplicaNumSet> &zone_locality,
|
||||
common::ObIArray<share::schema::ObZoneScore> &zone_score_list)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const share::schema::ObSchemaType schema_type =
|
||||
(is_new_tablegroup_id(partition_entity_id) ? share::schema::ObSchemaType::TABLEGROUP_SCHEMA
|
||||
: share::schema::ObSchemaType::TABLE_SCHEMA);
|
||||
const share::schema::ObPartitionSchema* partition_schema = nullptr;
|
||||
if (OB_FAIL(share::schema::ObPartMgrUtils::get_partition_schema(
|
||||
schema_guard, partition_entity_id, schema_type, partition_schema))) {
|
||||
LOG_WARN("fail to get partition schema", K(ret), K(partition_entity_id));
|
||||
} else if (OB_UNLIKELY(nullptr == partition_schema)) {
|
||||
zone_score_list.reset();
|
||||
share::schema::ObSchemaGetterGuard guard;
|
||||
ObArray<share::schema::ObZoneRegion> zone_region_list;
|
||||
common::ObSEArray<common::ObZone, DEFAULT_ZONE_COUNT> zone_list;
|
||||
ObZone primary_zone_str;
|
||||
if (OB_UNLIKELY(!tenant_schema.is_valid())) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("tenant schema is invalid", KR(ret), K(tenant_schema));
|
||||
} else if (OB_FAIL(tenant_schema.get_primary_zone_inherit(
|
||||
guard, primary_zone_schema))) {
|
||||
LOG_WARN("failed to get primary zone", KR(ret));
|
||||
} else if (OB_FAIL(tenant_schema.get_zone_list(zone_list))) {
|
||||
LOG_WARN("fail to get zone list", K(ret));
|
||||
} else if (OB_UNLIKELY(zone_list.count() <= 0)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("partition schema ptr is null", K(ret), K(partition_entity_id));
|
||||
} else if (OB_FAIL(get_pg_integrated_primary_zone(schema_guard, *partition_schema, primary_zone_str))) {
|
||||
LOG_WARN("fail to get pg integrated primary zone", K(ret), K(partition_entity_id));
|
||||
LOG_WARN("zone list count unexpected", K(ret));
|
||||
} else if (OB_FAIL(tenant_schema.get_zone_replica_attr_array(
|
||||
zone_locality))) {
|
||||
LOG_WARN("fail to get zone replica num array inherit", K(ret));
|
||||
} else if (OB_FAIL(generate_integrated_primary_zone_str(
|
||||
primary_zone_schema, zone_list, zone_locality,
|
||||
zone_score_list,
|
||||
primary_zone_str))) {
|
||||
LOG_WARN("fail to generate integrated primary zone str", K(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPrimaryZoneUtil::convert_random_primary_zone_into_integrated(const common::ObIArray<common::ObZone>& zone_list,
|
||||
const common::ObIArray<share::ObZoneReplicaAttrSet>& zone_locality, common::ObZone& primary_zone_str)
|
||||
|
||||
int ObPrimaryZoneUtil::get_ls_primary_zone_priority(
|
||||
const ObZone &ls_primary_zone,
|
||||
const share::schema::ObTenantSchema &tenant_schema,
|
||||
ObSqlString &zone_priority)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
zone_priority.reset();
|
||||
|
||||
if (OB_UNLIKELY(ls_primary_zone.is_empty() || !tenant_schema.is_valid())) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("primary zone is empty", KR(ret), K(ls_primary_zone), K(tenant_schema));
|
||||
} else if (OB_FAIL(zone_priority.assign(ls_primary_zone.ptr()))) {
|
||||
LOG_WARN("failed to assign ls primary zone", KR(ret), K(ls_primary_zone));
|
||||
} else {
|
||||
const char *separator_token = ";";
|
||||
common::ObSEArray<share::schema::ObZoneScore, DEFAULT_ZONE_COUNT> zone_score_array;
|
||||
ObArenaAllocator allocator("PrimaryZone");
|
||||
ObPrimaryZone primary_zone_schema(allocator);
|
||||
ObArray<share::ObZoneReplicaAttrSet> zone_locality;
|
||||
|
||||
if (OB_FAIL(get_tenant_primary_zone_score(tenant_schema,
|
||||
primary_zone_schema, zone_locality, zone_score_array))) {
|
||||
LOG_WARN("failed to get zone score list", KR(ret), K(tenant_schema));
|
||||
} else if (1 == zone_score_array.count()) {
|
||||
} else if (OB_FAIL(zone_priority.append_fmt("%s", separator_token))) {
|
||||
LOG_WARN("failed to append", KR(ret), K(separator_token));
|
||||
} else {
|
||||
int64_t prev_zone_score = zone_score_array.at(0).score_;
|
||||
bool first = true;
|
||||
for (int64_t i = 0; i < zone_score_array.count() && OB_SUCC(ret); ++i) {
|
||||
const ObZoneScore &cur_zone_score = zone_score_array.at(i);
|
||||
const bool same_p = (cur_zone_score.score_ == prev_zone_score);
|
||||
separator_token = (same_p ? "," : ";");
|
||||
if (cur_zone_score.zone_ == ls_primary_zone.str()) {
|
||||
//nothing todo
|
||||
//already in zone priority
|
||||
} else if (!first && OB_FAIL(zone_priority.append_fmt("%s", separator_token))) {
|
||||
LOG_WARN("failed to append", KR(ret), K(separator_token));
|
||||
} else if (OB_FAIL(zone_priority.append_fmt("%.*s",
|
||||
cur_zone_score.zone_.length(), cur_zone_score.zone_.ptr()))) {
|
||||
LOG_WARN("failed to append", KR(ret), K(separator_token), K(cur_zone_score));
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
prev_zone_score = cur_zone_score.score_;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ObPrimaryZoneUtil::get_tenant_zone_priority(
|
||||
const share::schema::ObTenantSchema &tenant_schema,
|
||||
common::ObSqlString &zone_priority)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
common::ObSEArray<share::schema::ObZoneScore, DEFAULT_ZONE_COUNT> zone_score_array;
|
||||
ObZone primary_zone_str;
|
||||
ObArenaAllocator allocator("PrimaryZone");
|
||||
ObPrimaryZone primary_zone_schema(allocator);
|
||||
ObArray<share::ObZoneReplicaAttrSet> zone_locality;
|
||||
if (OB_UNLIKELY(!tenant_schema.is_valid())) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("tenant schema is invalid", KR(ret), K(tenant_schema));
|
||||
} else if (OB_FAIL(get_tenant_primary_zone_score(tenant_schema,
|
||||
primary_zone_schema, zone_locality, zone_score_array))) {
|
||||
LOG_WARN("failed to get zone score list", KR(ret), K(tenant_schema));
|
||||
} else if (OB_FAIL(do_generate_integrated_primary_zone_str(zone_score_array, primary_zone_str))) {
|
||||
LOG_WARN("failed to generate_integrated primary zone", KR(ret), K(zone_score_array));
|
||||
} else if (OB_FAIL(zone_priority.assign(primary_zone_str.str()))) {
|
||||
LOG_WARN("failed to assign zone priority", KR(ret), K(primary_zone_str));
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int ObPrimaryZoneUtil::convert_random_primary_zone_into_integrated(
|
||||
const common::ObIArray<common::ObZone> &zone_list,
|
||||
const common::ObIArray<share::ObZoneReplicaAttrSet> &zone_locality,
|
||||
common::ObIArray<share::schema::ObZoneScore> &zone_score_list,
|
||||
common::ObZone &primary_zone_str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
primary_zone_str.reset();
|
||||
common::ObSEArray<share::schema::ObZoneScore, MAX_ZONE_NUM> zone_score_list;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < zone_locality.count(); ++i) {
|
||||
const share::ObZoneReplicaAttrSet& this_set = zone_locality.at(i);
|
||||
const share::ObZoneReplicaAttrSet &this_set = zone_locality.at(i);
|
||||
if (this_set.get_full_replica_num() >= 1) {
|
||||
for (int64_t j = 0; OB_SUCC(ret) && j < this_set.get_zone_set().count(); ++j) {
|
||||
const common::ObZone& this_zone = this_set.get_zone_set().at(j);
|
||||
const char* zone_ptr = this_zone.ptr();
|
||||
const common::ObZone &this_zone = this_set.get_zone_set().at(j);
|
||||
const char *zone_ptr = this_zone.ptr();
|
||||
ObString zone_str(zone_ptr);
|
||||
ObZoneScore zone_score(zone_str, 0);
|
||||
if (!has_exist_in_array(zone_list, this_zone)) {
|
||||
@ -663,8 +765,7 @@ int ObPrimaryZoneUtil::convert_random_primary_zone_into_integrated(const common:
|
||||
LOG_WARN("fail to push back", K(ret));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} // has no full replica, cannot be leader
|
||||
} else {} // has no full replica, cannot be leader
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (OB_FAIL(do_generate_integrated_primary_zone_str(zone_score_list, primary_zone_str))) {
|
||||
@ -674,7 +775,8 @@ int ObPrimaryZoneUtil::convert_random_primary_zone_into_integrated(const common:
|
||||
}
|
||||
|
||||
int ObPrimaryZoneUtil::do_generate_integrated_primary_zone_str(
|
||||
const common::ObIArray<share::schema::ObZoneScore>& zone_score_array, common::ObZone& primary_zone_str)
|
||||
const common::ObIArray<share::schema::ObZoneScore> &zone_score_array,
|
||||
common::ObZone &primary_zone_str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
char zone_str[MAX_ZONE_LENGTH];
|
||||
@ -686,25 +788,23 @@ int ObPrimaryZoneUtil::do_generate_integrated_primary_zone_str(
|
||||
int64_t pos = 0;
|
||||
bool start_format = false;
|
||||
int64_t prev_zone_score = zone_score_array.at(0).score_;
|
||||
const char* separator_token = NULL;
|
||||
const char *separator_token = NULL;
|
||||
for (int64_t i = 0; i < zone_score_array.count() && OB_SUCC(ret); ++i) {
|
||||
const ObZoneScore& cur_zone_score = zone_score_array.at(i);
|
||||
const ObZoneScore &cur_zone_score = zone_score_array.at(i);
|
||||
const bool same_p = (cur_zone_score.score_ == prev_zone_score);
|
||||
separator_token = (same_p ? "," : ";");
|
||||
if (OB_FAIL(databuff_printf(zone_str, MAX_ZONE_LENGTH, pos, "%s", (!start_format ? "" : separator_token)))) {
|
||||
if (OB_FAIL(databuff_printf(zone_str, MAX_ZONE_LENGTH, pos,
|
||||
"%s", (!start_format ? "" : separator_token)))) {
|
||||
LOG_WARN("fail to format separator", K(ret));
|
||||
} else if (OB_FAIL(databuff_printf(zone_str,
|
||||
MAX_ZONE_LENGTH,
|
||||
pos,
|
||||
"%.*s",
|
||||
static_cast<int32_t>(cur_zone_score.zone_.length()),
|
||||
cur_zone_score.zone_.ptr()))) {
|
||||
} else if (OB_FAIL(databuff_printf(zone_str, MAX_ZONE_LENGTH, pos, "%.*s",
|
||||
static_cast<int32_t>(cur_zone_score.zone_.length()),
|
||||
cur_zone_score.zone_.ptr()))) {
|
||||
LOG_WARN("fail to format zone", K(ret));
|
||||
} else {
|
||||
start_format = true;
|
||||
prev_zone_score = cur_zone_score.score_;
|
||||
}
|
||||
} // for
|
||||
} // for
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(primary_zone_str.assign(zone_str))) {
|
||||
LOG_WARN("fail to assign primary zone", K(ret));
|
||||
@ -715,19 +815,20 @@ int ObPrimaryZoneUtil::do_generate_integrated_primary_zone_str(
|
||||
}
|
||||
|
||||
int ObPrimaryZoneUtil::convert_normal_primary_zone_into_integrated(
|
||||
const common::ObIArray<share::schema::ObZoneScore>& primary_zone_array,
|
||||
const common::ObIArray<common::ObZone>& zone_list,
|
||||
const common::ObIArray<share::ObZoneReplicaAttrSet>& zone_locality, common::ObZone& primary_zone_str)
|
||||
const common::ObIArray<share::schema::ObZoneScore> &primary_zone_array,
|
||||
const common::ObIArray<common::ObZone> &zone_list,
|
||||
const common::ObIArray<share::ObZoneReplicaAttrSet> &zone_locality,
|
||||
common::ObIArray<share::schema::ObZoneScore> &zone_score_list,
|
||||
common::ObZone &primary_zone_str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
primary_zone_str.reset();
|
||||
common::ObSEArray<common::ObZone, MAX_ZONE_NUM> full_replica_zone_list;
|
||||
common::ObSEArray<share::schema::ObZoneScore, MAX_ZONE_NUM> zone_score_list;
|
||||
common::ObArray<common::ObZone> full_replica_zone_list;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < zone_locality.count(); ++i) {
|
||||
const share::ObZoneReplicaAttrSet& this_set = zone_locality.at(i);
|
||||
const share::ObZoneReplicaAttrSet &this_set = zone_locality.at(i);
|
||||
if (this_set.get_full_replica_num() >= 1) {
|
||||
for (int64_t j = 0; OB_SUCC(ret) && j < this_set.get_zone_set().count(); ++j) {
|
||||
const common::ObZone& this_zone = this_set.get_zone_set().at(j);
|
||||
const common::ObZone &this_zone = this_set.get_zone_set().at(j);
|
||||
if (!has_exist_in_array(zone_list, this_zone)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("this zone is not in zone list", K(ret));
|
||||
@ -738,8 +839,8 @@ int ObPrimaryZoneUtil::convert_normal_primary_zone_into_integrated(
|
||||
}
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < primary_zone_array.count(); ++i) {
|
||||
const share::schema::ObZoneScore& this_score = primary_zone_array.at(i);
|
||||
const common::ObZone& this_zone = this_score.zone_.ptr();
|
||||
const share::schema::ObZoneScore &this_score = primary_zone_array.at(i);
|
||||
const common::ObZone &this_zone = this_score.zone_.ptr();
|
||||
if (has_exist_in_array(full_replica_zone_list, this_zone)) {
|
||||
ObZoneScore zone_score = this_score;
|
||||
if (OB_FAIL(zone_score_list.push_back(zone_score))) {
|
||||
@ -754,28 +855,34 @@ int ObPrimaryZoneUtil::convert_normal_primary_zone_into_integrated(
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPrimaryZoneUtil::generate_integrated_primary_zone_str(const share::schema::ObPrimaryZone& primary_zone,
|
||||
const common::ObIArray<common::ObZone>& zone_list,
|
||||
const common::ObIArray<share::ObZoneReplicaNumSet>& zone_locality, common::ObZone& primary_zone_str)
|
||||
int ObPrimaryZoneUtil::generate_integrated_primary_zone_str(
|
||||
const share::schema::ObPrimaryZone &primary_zone,
|
||||
const common::ObIArray<common::ObZone> &zone_list,
|
||||
const common::ObIArray<share::ObZoneReplicaNumSet> &zone_locality,
|
||||
common::ObIArray<share::schema::ObZoneScore> &zone_score_list,
|
||||
common::ObZone &primary_zone_str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
primary_zone_str.reset();
|
||||
const ObString& raw_primary_zone = primary_zone.get_primary_zone();
|
||||
const ObString &raw_primary_zone = primary_zone.get_primary_zone();
|
||||
if (raw_primary_zone.empty() || raw_primary_zone == OB_RANDOM_PRIMARY_ZONE) {
|
||||
if (OB_FAIL(convert_random_primary_zone_into_integrated(zone_list, zone_locality, primary_zone_str))) {
|
||||
if (OB_FAIL(convert_random_primary_zone_into_integrated(
|
||||
zone_list, zone_locality, zone_score_list, primary_zone_str))) {
|
||||
LOG_WARN("fail to convert random primary zone", K(ret));
|
||||
}
|
||||
} else {
|
||||
if (OB_FAIL(convert_normal_primary_zone_into_integrated(
|
||||
primary_zone.get_primary_zone_array(), zone_list, zone_locality, primary_zone_str))) {
|
||||
primary_zone.get_primary_zone_array(), zone_list, zone_locality, zone_score_list, primary_zone_str))) {
|
||||
LOG_WARN("fail to convert normal primary zone", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRawPrimaryZoneUtil::build(const ObZone& primary_zone, common::ObIArray<ZoneScore>& zone_score_array,
|
||||
common::ObIArray<RegionScore>& region_score_array)
|
||||
int ObRawPrimaryZoneUtil::build(
|
||||
const ObZone &primary_zone,
|
||||
common::ObIArray<ZoneScore> &zone_score_array,
|
||||
common::ObIArray<RegionScore> ®ion_score_array)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
// when upgrade from 1.4.x to 2.0, primary_zone may be empty string, the empty primary zone
|
||||
@ -786,22 +893,21 @@ int ObRawPrimaryZoneUtil::build(const ObZone& primary_zone, common::ObIArray<Zon
|
||||
region_score_array.reset();
|
||||
int64_t cursor = 0;
|
||||
const int64_t len = primary_zone.size();
|
||||
const char* zone_ptr = primary_zone.ptr();
|
||||
const char *zone_ptr = primary_zone.ptr();
|
||||
ZoneScore zone_score;
|
||||
while (OB_SUCC(ret) && OB_SUCC(get_next_zone_score(zone_ptr, cursor, len, zone_score))) {
|
||||
while (OB_SUCC(ret)
|
||||
&& OB_SUCC(get_next_zone_score(zone_ptr, cursor, len, zone_score))) {
|
||||
if (OB_FAIL(zone_score_array.push_back(ZoneScore(zone_score)))) {
|
||||
LOG_WARN("fail to push back", K(ret), K(zone_score));
|
||||
} else {
|
||||
} // ok
|
||||
} else {} // ok
|
||||
}
|
||||
if (OB_ITER_END == ret) {
|
||||
ret = OB_SUCCESS;
|
||||
}
|
||||
for (int64_t i = 0; i < zone_score_array.count() && OB_SUCC(ret); ++i) {
|
||||
ObRegion region;
|
||||
const ZoneScore& zone_score = zone_score_array.at(i);
|
||||
HEAP_VAR(share::ObZoneInfo, zone_info)
|
||||
{
|
||||
const ZoneScore &zone_score = zone_score_array.at(i);
|
||||
HEAP_VAR(share::ObZoneInfo, zone_info) {
|
||||
zone_info.zone_ = zone_score.zone_;
|
||||
if (OB_FAIL(zone_mgr_.get_zone(zone_info))) {
|
||||
LOG_WARN("fail to get zone", K(ret));
|
||||
@ -812,14 +918,14 @@ int ObRawPrimaryZoneUtil::build(const ObZone& primary_zone, common::ObIArray<Zon
|
||||
for (int64_t j = 0; j < region_score_array.count() && !is_region_exist; ++j) {
|
||||
if (region == region_score_array.at(j).region_) {
|
||||
is_region_exist = true;
|
||||
} else {
|
||||
} // go on
|
||||
} else {} // go on
|
||||
}
|
||||
if (is_region_exist) {
|
||||
} else if (OB_FAIL(region_score_array.push_back(RegionScore(region, zone_score.zone_score_)))) {
|
||||
LOG_WARN("fail to push back", K(ret), K(region), "score", zone_score.zone_score_);
|
||||
} else {
|
||||
} // ok
|
||||
} else if (OB_FAIL(region_score_array.push_back(
|
||||
RegionScore(region, zone_score.zone_score_)))) {
|
||||
LOG_WARN("fail to push back", K(ret), K(region),
|
||||
"score", zone_score.zone_score_);
|
||||
} else {} // ok
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -827,15 +933,22 @@ int ObRawPrimaryZoneUtil::build(const ObZone& primary_zone, common::ObIArray<Zon
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ObRawPrimaryZoneUtil::jump_over_blanks(const char* ptr, int64_t& cursor, const int64_t end)
|
||||
void ObRawPrimaryZoneUtil::jump_over_blanks(
|
||||
const char *ptr,
|
||||
int64_t &cursor,
|
||||
const int64_t end)
|
||||
{
|
||||
while (cursor < end && ptr[cursor] == BLANK_TOKEN) {
|
||||
while (cursor < end
|
||||
&& ptr[cursor] == BLANK_TOKEN) {
|
||||
++cursor;
|
||||
}
|
||||
}
|
||||
|
||||
int ObRawPrimaryZoneUtil::get_next_zone_score(
|
||||
const char* ptr, int64_t& cursor, const int64_t end, ZoneScore& zone_score)
|
||||
const char *ptr,
|
||||
int64_t &cursor,
|
||||
const int64_t end,
|
||||
ZoneScore &zone_score)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
common::ObZone zone;
|
||||
@ -845,8 +958,10 @@ int ObRawPrimaryZoneUtil::get_next_zone_score(
|
||||
ret = OB_ITER_END;
|
||||
} else {
|
||||
int64_t tmp_cursor = cursor;
|
||||
while (tmp_cursor < end && ptr[tmp_cursor] != BLANK_TOKEN && ptr[tmp_cursor] != COMMA_TOKEN &&
|
||||
ptr[tmp_cursor] != SEMI_COLON_TOKEN) {
|
||||
while (tmp_cursor < end
|
||||
&& ptr[tmp_cursor] != BLANK_TOKEN
|
||||
&& ptr[tmp_cursor] != COMMA_TOKEN
|
||||
&& ptr[tmp_cursor] != SEMI_COLON_TOKEN) {
|
||||
++tmp_cursor;
|
||||
}
|
||||
int64_t len = tmp_cursor - cursor;
|
||||
@ -863,17 +978,17 @@ int ObRawPrimaryZoneUtil::get_next_zone_score(
|
||||
LOG_WARN("zone do not exist", K(ret), K(zone));
|
||||
} else {
|
||||
zone_score.zone_ = zone;
|
||||
zone_score.zone_score_ = current_score_;
|
||||
zone_score.zone_score_= current_score_;
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
cursor = tmp_cursor;
|
||||
jump_over_blanks(ptr, cursor, end);
|
||||
if (cursor >= end) {
|
||||
} else if (COMMA_TOKEN == ptr[cursor]) {
|
||||
++cursor; // no need to inc current_score
|
||||
++cursor; // no need to inc current_score
|
||||
} else if (SEMI_COLON_TOKEN == ptr[cursor]) {
|
||||
++cursor; // inc cursor and pass SEMI COLON TOKEN
|
||||
++current_score_; // come across SEMI COLON TOKEN, inc current_score_
|
||||
++cursor; // inc cursor and pass SEMI COLON TOKEN
|
||||
++current_score_; // come across SEMI COLON TOKEN, inc current_score_
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid zone", K(ret));
|
||||
@ -884,7 +999,8 @@ int ObRawPrimaryZoneUtil::get_next_zone_score(
|
||||
}
|
||||
|
||||
int ObRawPrimaryZoneUtil::generate_high_priority_zone_array(
|
||||
const common::ObIArray<ZoneScore>& zone_score_array, common::ObIArray<common::ObZone>& high_priority_zone_array)
|
||||
const common::ObIArray<ZoneScore> &zone_score_array,
|
||||
common::ObIArray<common::ObZone> &high_priority_zone_array)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(zone_score_array.count() <= 0)) {
|
||||
@ -895,7 +1011,7 @@ int ObRawPrimaryZoneUtil::generate_high_priority_zone_array(
|
||||
const int64_t sample_score = zone_score_array.at(0).zone_score_;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < zone_score_array.count(); ++i) {
|
||||
const int64_t this_score = zone_score_array.at(i).zone_score_;
|
||||
const common::ObZone& this_zone = zone_score_array.at(i).zone_;
|
||||
const common::ObZone &this_zone = zone_score_array.at(i).zone_;
|
||||
if (sample_score == this_score) {
|
||||
if (OB_FAIL(high_priority_zone_array.push_back(this_zone))) {
|
||||
LOG_WARN("fail to push back", K(ret));
|
||||
@ -908,5 +1024,6 @@ int ObRawPrimaryZoneUtil::generate_high_priority_zone_array(
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // end namespace share
|
||||
} // end namespace oceanbase
|
||||
} // end namespace share
|
||||
} // end namespace oceanbase
|
||||
|
||||
|
||||
Reference in New Issue
Block a user