patch 4.0

This commit is contained in:
wangzelin.wzl
2022-10-24 10:34:53 +08:00
parent 4ad6e00ec3
commit 93a1074b0c
10533 changed files with 2588271 additions and 2299373 deletions

View File

@ -19,140 +19,138 @@
#include "rootserver/ob_server_manager.h"
#include "rootserver/ob_unit_manager.h"
namespace oceanbase {
namespace oceanbase
{
using namespace common;
using namespace share;
namespace rootserver {
ObVTableLocationGetter::ObVTableLocationGetter(ObServerManager& server_mgr, ObUnitManager& unit_mgr)
: server_mgr_(server_mgr), unit_mgr_(unit_mgr)
{}
namespace rootserver
{
ObVTableLocationGetter::ObVTableLocationGetter(ObServerManager &server_mgr,
ObUnitManager &unit_mgr)
: server_mgr_(server_mgr),
unit_mgr_(unit_mgr)
{
}
ObVTableLocationGetter::~ObVTableLocationGetter()
{}
{
}
int ObVTableLocationGetter::get(const uint64_t table_id, ObSArray<ObPartitionLocation>& locations)
int ObVTableLocationGetter::get(const ObVtableLocationType &vtable_type,
ObSArray<common::ObAddr> &servers)
{
int ret = OB_SUCCESS;
locations.reuse();
if (OB_INVALID_ID == table_id) {
servers.reuse();
if (OB_UNLIKELY(!vtable_type.is_valid()
|| vtable_type.is_only_local())) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("table_id is invalid", KT(table_id), K(ret));
} else if (!is_virtual_table(table_id)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("table is not virtual table", KT(table_id), K(ret));
} else if (is_only_rs_virtual_table(table_id)) {
if (OB_FAIL(get_only_rs_vtable_location(table_id, locations))) {
LOG_WARN("get_only_rs_vtable_location failed", KT(table_id), K(ret));
LOG_WARN("input is invalid", KR(ret), K(vtable_type));
} else if (vtable_type.is_only_rs()) {
if (OB_FAIL(get_only_rs_vtable_location_(vtable_type, servers))) {
LOG_WARN("get_only_rs_vtable_location failed", KR(ret), K(vtable_type));
}
} else if (is_global_virtual_table(table_id)) {
if (OB_FAIL(get_global_vtable_location(table_id, locations))) {
LOG_WARN("get_global_vtable_location failed", KT(table_id), K(ret));
} else if (vtable_type.is_cluster_distributed()) {
if (OB_FAIL(get_global_vtable_location_(vtable_type, servers))) {
LOG_WARN("get_global_vtable_location failed", KR(ret), K(vtable_type));
}
} else if (is_tenant_virtual_table(table_id)) {
if (OB_FAIL(get_tenant_vtable_location(table_id, locations))) {
LOG_WARN("get_tenant_vtable_location failed", KT(table_id), K(ret));
} else if (vtable_type.is_tenant_distributed()) {
if (OB_FAIL(get_tenant_vtable_location_(vtable_type, servers))) {
LOG_WARN("get_tenant_vtable_location failed", KR(ret), K(vtable_type));
}
} else {
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("expected not to run here", KT(table_id), K(ret));
LOG_ERROR("expected not to run here", KR(ret), K(vtable_type));
}
if (OB_SUCC(ret) && OB_UNLIKELY(servers.count() <= 0)) {
ret = OB_LOCATION_NOT_EXIST;
LOG_WARN("servers from server_mgr_ are empty", KR(ret), K(vtable_type), K(servers));
}
return ret;
}
int ObVTableLocationGetter::get_only_rs_vtable_location(
const uint64_t table_id, ObSArray<ObPartitionLocation>& locations)
int ObVTableLocationGetter::get_only_rs_vtable_location_(
const ObVtableLocationType &vtable_type,
ObSArray<ObAddr> &servers)
{
int ret = OB_SUCCESS;
locations.reuse();
ObArray<ObAddr> servers;
if (OB_INVALID_ID == table_id) {
servers.reuse();
if (OB_UNLIKELY(!vtable_type.is_only_rs())) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("table_id is invalid", KT(table_id), K(ret));
} else if (!is_only_rs_virtual_table(table_id)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("table is not only rs virtual table", KT(table_id), K(ret));
LOG_WARN("vtable_type is invalid", K(vtable_type), KR(ret));
} else if (OB_FAIL(servers.push_back(server_mgr_.get_rs_addr()))) {
LOG_WARN("push_back failed", K(ret));
} else if (OB_FAIL(build_location(table_id, servers, locations))) {
LOG_WARN("build_location failed", KT(table_id), K(servers), K(ret));
LOG_WARN("push_back failed", KR(ret));
}
return ret;
}
int ObVTableLocationGetter::get_global_vtable_location(
const uint64_t table_id, ObSArray<ObPartitionLocation>& locations)
int ObVTableLocationGetter::get_global_vtable_location_(
const ObVtableLocationType &vtable_type,
ObSArray<ObAddr> &servers)
{
int ret = OB_SUCCESS;
locations.reuse();
ObZone zone; // empty zone means all zones
ObArray<ObAddr> servers;
if (OB_INVALID_ID == table_id) {
servers.reuse();
ObZone zone; // empty zone means all zones
if (OB_UNLIKELY(!(vtable_type.is_cluster_distributed()))) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("table_id is invalid", KT(table_id), K(ret));
} else if (!is_global_virtual_table(table_id)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("table is not global virtual table", KT(table_id), K(ret));
LOG_WARN("vtable_type is invalid", K(vtable_type), KR(ret));
} else if (!server_mgr_.has_build()) {
ret = OB_SERVER_IS_INIT;
LOG_WARN("server manager hasn't built", "server_mgr built", server_mgr_.has_build(), K(ret));
LOG_WARN("server manager hasn't built",
"server_mgr built", server_mgr_.has_build(), KR(ret));
} else if (OB_FAIL(server_mgr_.get_alive_servers(zone, servers))) {
LOG_WARN("get_alive_servers failed", K(ret));
} else if (OB_FAIL(build_location(table_id, servers, locations))) {
LOG_WARN("build_location failed", KT(table_id), K(servers), K(ret));
LOG_WARN("get_alive_servers failed", KR(ret));
}
return ret;
}
int ObVTableLocationGetter::get_tenant_vtable_location(
const uint64_t table_id, ObSArray<ObPartitionLocation>& locations)
int ObVTableLocationGetter::get_tenant_vtable_location_(
const ObVtableLocationType &vtable_type,
ObSArray<ObAddr> &servers)
{
int ret = OB_SUCCESS;
locations.reuse();
const uint64_t tenant_id = extract_tenant_id(table_id);
servers.reuse();
ObArray<ObAddr> unit_servers;
ObArray<ObAddr> servers;
ObArray<uint64_t> pool_ids;
if (OB_INVALID_ID == table_id) {
if (OB_UNLIKELY(!vtable_type.is_valid()
|| !vtable_type.is_tenant_distributed()
|| is_sys_tenant(vtable_type.get_tenant_id()))) { // sys_tenant should get cluster location
ret = OB_INVALID_ARGUMENT;
LOG_WARN("table_id is invalid", KT(table_id), K(ret));
} else if (!is_tenant_virtual_table(table_id)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("table is not tenant virtual table", KT(table_id), K(ret));
LOG_WARN("vtable_type is invalid", KR(ret), K(vtable_type));
} else if (!server_mgr_.has_build() || !unit_mgr_.check_inner_stat()) {
ret = OB_SERVER_IS_INIT;
LOG_WARN("server manager or unit manager hasn't built",
"server_mgr built",
server_mgr_.has_build(),
"unit_mgr built",
unit_mgr_.check_inner_stat(),
K(ret));
} else if (OB_FAIL(unit_mgr_.get_pool_ids_of_tenant(tenant_id, pool_ids))) {
LOG_WARN("get_pool_ids_of_tenant failed", K(tenant_id), K(ret));
"server_mgr built", server_mgr_.has_build(),
"unit_mgr built", unit_mgr_.check_inner_stat(), KR(ret));
} else if (OB_FAIL(unit_mgr_.get_pool_ids_of_tenant(vtable_type.get_tenant_id(), pool_ids))) {
LOG_WARN("get_pool_ids_of_tenant failed", KR(ret), K(vtable_type));
} else {
ObArray<ObUnitInfo> unit_infos;
for (int64_t i = 0; OB_SUCC(ret) && i < pool_ids.count(); ++i) {
unit_infos.reuse();
if (OB_FAIL(unit_mgr_.get_unit_infos_of_pool(pool_ids.at(i), unit_infos))) {
LOG_WARN("get_unit_infos_of_pool failed", "pool_id", pool_ids.at(i), K(ret));
LOG_WARN("get_unit_infos_of_pool failed", "pool_id", pool_ids.at(i), KR(ret));
} else {
for (int64_t j = 0; OB_SUCC(ret) && j < unit_infos.count(); ++j) {
bool is_alive = false;
const ObUnit& unit = unit_infos.at(j).unit_;
const ObUnit &unit = unit_infos.at(j).unit_;
if (OB_FAIL(server_mgr_.check_server_alive(unit.server_, is_alive))) {
LOG_WARN("check_server_alive failed", "server", unit.server_, K(ret));
LOG_WARN("check_server_alive failed", "server", unit.server_, KR(ret));
} else if (is_alive) {
if (OB_FAIL(unit_servers.push_back(unit.server_))) {
LOG_WARN("push_back failed", K(ret));
LOG_WARN("push_back failed", KR(ret));
}
}
if (OB_SUCC(ret)) {
if (unit.migrate_from_server_.is_valid()) {
if (OB_FAIL(server_mgr_.check_server_alive(unit.migrate_from_server_, is_alive))) {
LOG_WARN("check_server_alive failed", "server", unit.migrate_from_server_, K(ret));
if (OB_FAIL(server_mgr_.check_server_alive(
unit.migrate_from_server_, is_alive))) {
LOG_WARN("check_server_alive failed", "server",
unit.migrate_from_server_, KR(ret));
} else if (is_alive) {
if (OB_FAIL(unit_servers.push_back(unit.migrate_from_server_))) {
LOG_WARN("push_back failed", K(ret));
LOG_WARN("push_back failed", KR(ret));
}
}
}
@ -169,57 +167,20 @@ int ObVTableLocationGetter::get_tenant_vtable_location(
for (int64_t i = 0; OB_SUCC(ret) && i < unit_servers.count(); ++i) {
if (!unit_servers.at(i).is_valid()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("server not expected to be invalid", "server", unit_servers.at(i), K(unit_servers), K(ret));
LOG_WARN("server not expected to be invalid",
"server", unit_servers.at(i), K(unit_servers), KR(ret));
} else {
if (pre_server != unit_servers.at(i)) {
if (OB_FAIL(servers.push_back(unit_servers.at(i)))) {
LOG_WARN("push_back failed", K(ret));
LOG_WARN("push_back failed", KR(ret));
}
}
pre_server = unit_servers.at(i);
}
}
}
if (OB_SUCC(ret)) {
if (OB_FAIL(build_location(table_id, servers, locations))) {
LOG_WARN("build_location failed", KT(table_id), K(servers), K(ret));
}
}
return ret;
}
int ObVTableLocationGetter::build_location(
const uint64_t table_id, const ObArray<ObAddr>& servers, ObSArray<ObPartitionLocation>& locations)
{
int ret = OB_SUCCESS;
ObServerManager::ObServerStatusArray statuses;
if (OB_INVALID_ID == table_id || servers.count() <= 0) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", KT(table_id), K(servers), K(ret));
} else if (OB_FAIL(server_mgr_.get_server_statuses(servers, statuses))) {
LOG_WARN("get_server_statuses failed", K(servers), K(ret));
} else {
ObPartitionLocation location;
ObReplicaLocation replica_location;
for (int64_t i = 0; OB_SUCC(ret) && i < statuses.count(); ++i) {
location.reset();
replica_location.reset();
location.set_table_id(table_id);
location.set_partition_id(i);
location.set_partition_cnt(statuses.count());
replica_location.role_ = LEADER;
replica_location.server_ = statuses.at(i).server_;
replica_location.sql_port_ = statuses.at(i).sql_port_;
if (OB_FAIL(location.add(replica_location))) {
LOG_WARN("location add failed", K(replica_location), K(ret));
} else if (OB_FAIL(locations.push_back(location))) {
LOG_WARN("push_back failed", K(location), K(ret));
}
}
}
return ret;
}
} // end namespace rootserver
} // end namespace oceanbase
}//end namespace rootserver
}//end namespace oceanbase