fix get table schema

This commit is contained in:
yongshige 2023-08-04 06:42:19 +00:00 committed by ob-robot
parent ec768b2565
commit fe86d54fad

View File

@ -68,13 +68,35 @@ int ObTableLoadSchema::get_table_schema(uint64_t tenant_id, uint64_t table_id,
{
int ret = OB_SUCCESS;
table_schema = nullptr;
if (OB_FAIL(get_schema_guard(tenant_id, schema_guard))) {
LOG_WARN("fail to get schema guard", KR(ret), K(tenant_id));
} else if (OB_FAIL(schema_guard.get_table_schema(tenant_id, table_id, table_schema))) {
LOG_WARN("fail to get table schema", KR(ret), K(tenant_id), K(table_id));
} else if (OB_ISNULL(table_schema)) {
bool get_table_schema_succ = false;
const int64_t MAX_RETRY_COUNT = 10;
for (int64_t i = 0; OB_SUCC(ret) && (!get_table_schema_succ) && (i < MAX_RETRY_COUNT); ++i) {
if (OB_FAIL(get_schema_guard(tenant_id, schema_guard))) {
LOG_WARN("fail to get schema guard", KR(ret), K(tenant_id));
} else if (OB_FAIL(schema_guard.get_table_schema(tenant_id, table_id, table_schema))) {
LOG_WARN("fail to get table schema", KR(ret), K(tenant_id), K(table_id));
} else if (OB_ISNULL(table_schema)) {
const int64_t RESERVED_TIME_US = 600 * 1000; // 600 ms
const int64_t timeout_remain_us = THIS_WORKER.get_timeout_remain();
const int64_t idle_time_us = 200 * 1000 * (i + 1);
if (timeout_remain_us - idle_time_us > RESERVED_TIME_US) {
LOG_WARN("fail to get table schema, will retry", KR(ret), K(i), K(tenant_id), K(table_id),
K(timeout_remain_us), K(idle_time_us), K(RESERVED_TIME_US));
USLEEP(idle_time_us);
ret = OB_SUCCESS;
} else {
ret = OB_TIMEOUT;
LOG_WARN("fail to get table schema, will not retry cuz timeout_remain is not enough",
KR(ret), K(i), K(tenant_id), K(table_id), K(timeout_remain_us), K(idle_time_us),
K(RESERVED_TIME_US));
}
} else {
get_table_schema_succ = true;
}
}
if (OB_SUCC(ret) && !get_table_schema_succ) {
ret = OB_TABLE_NOT_EXIST;
LOG_WARN("table not exist", KR(ret), K(tenant_id), K(table_id));
LOG_WARN("fail to get table schema", KR(ret), K(tenant_id));
}
return ret;
}