patch 4.0
This commit is contained in:
@ -21,45 +21,32 @@
|
||||
#include "rootserver/ob_root_utils.h"
|
||||
#include "observer/ob_server_struct.h"
|
||||
|
||||
namespace oceanbase {
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace common;
|
||||
using namespace common::sqlclient;
|
||||
namespace share {
|
||||
const char* ObGlobalStatProxy::OB_ALL_GC_SCHEMA_VERSION_TNAME = "__all_gc_schema_version";
|
||||
const char* ObGlobalStatProxy::TENANT_ID_CNAME = "tenant_id";
|
||||
const char* ObGlobalStatProxy::GC_SCHEMA_VERSION_CNAME = "gc_schema_version";
|
||||
int ObGlobalStatProxy::set_init_value(const int64_t core_schema_version, const int64_t baseline_schema_version,
|
||||
const int64_t frozen_version, const int64_t rootservice_epoch, const int64_t split_schema_verion,
|
||||
const int64_t split_schema_verion_v2, const int64_t snapshot_gc_ts, const int64_t gc_schema_version,
|
||||
const int64_t next_schema_version)
|
||||
namespace share
|
||||
{
|
||||
const char *ObGlobalStatProxy::TENANT_ID_CNAME = "tenant_id";
|
||||
int ObGlobalStatProxy::set_init_value(const int64_t core_schema_version,
|
||||
const int64_t baseline_schema_version,
|
||||
const int64_t rootservice_epoch,
|
||||
const int64_t snapshot_gc_scn,
|
||||
const int64_t gc_schema_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
// FIXME: split schema not yet enable, it is not need to check whether valid of split_schema_version
|
||||
if (!is_valid() || core_schema_version <= 0 || baseline_schema_version < -1 || snapshot_gc_ts < 0 ||
|
||||
frozen_version <= 0 || OB_INVALID_ID == rootservice_epoch || gc_schema_version < 0) {
|
||||
if (!is_valid() || core_schema_version <= 0 || baseline_schema_version < -1
|
||||
|| snapshot_gc_scn < 0 || OB_INVALID_ID == rootservice_epoch || gc_schema_version < 0) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument",
|
||||
K(ret),
|
||||
"self valid",
|
||||
is_valid(),
|
||||
K(rootservice_epoch),
|
||||
K(core_schema_version),
|
||||
K(baseline_schema_version),
|
||||
K(snapshot_gc_ts),
|
||||
K(frozen_version),
|
||||
K(gc_schema_version),
|
||||
K(next_schema_version));
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid(), K(rootservice_epoch),
|
||||
K(core_schema_version), K(baseline_schema_version), K(snapshot_gc_scn), K(gc_schema_version));
|
||||
} else {
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem core_schema_version_item(list, "core_schema_version", core_schema_version);
|
||||
ObGlobalStatItem baseline_schema_version_item(list, "baseline_schema_version", baseline_schema_version);
|
||||
ObGlobalStatItem frozen_version_item(list, "frozen_version", frozen_version);
|
||||
ObGlobalStatItem rootservice_epoch_item(list, "rootservice_epoch", rootservice_epoch);
|
||||
ObGlobalStatItem split_schema_version_item(list, "split_schema_version", split_schema_verion);
|
||||
ObGlobalStatItem split_schema_version_v2_item(list, "split_schema_version_v2", split_schema_verion_v2);
|
||||
ObGlobalStatItem snapshot_gc_ts_item(list, "snapshot_gc_ts", snapshot_gc_ts);
|
||||
ObGlobalStatItem snapshot_gc_scn_item(list, "snapshot_gc_scn", snapshot_gc_scn);
|
||||
ObGlobalStatItem gc_schema_version_item(list, "gc_schema_version", gc_schema_version);
|
||||
ObGlobalStatItem next_schema_version_item(list, "next_schema_version", next_schema_version);
|
||||
|
||||
if (OB_FAIL(update(list))) {
|
||||
LOG_WARN("update failed", K(list), K(ret));
|
||||
@ -68,13 +55,38 @@ int ObGlobalStatProxy::set_init_value(const int64_t core_schema_version, const i
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define SET_ITEM(name, value, is_incremental) \
|
||||
do { \
|
||||
ObGlobalStatItem::ItemList list; \
|
||||
ObGlobalStatItem item(list, name, value); \
|
||||
if (OB_FAIL(update(list, is_incremental))) { \
|
||||
int ObGlobalStatProxy::set_tenant_init_global_stat(
|
||||
const int64_t core_schema_version,
|
||||
const int64_t baseline_schema_version,
|
||||
const int64_t snapshot_gc_scn)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!is_valid() || core_schema_version <= 0 || baseline_schema_version < OB_INVALID_VERSION
|
||||
|| (snapshot_gc_scn < OB_INVALID_TIMESTAMP)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", KR(ret), "self valid", is_valid(),
|
||||
K(core_schema_version), K(baseline_schema_version),
|
||||
K(snapshot_gc_scn));
|
||||
} else {
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem core_schema_version_item(list, "core_schema_version", core_schema_version);
|
||||
ObGlobalStatItem baseline_schema_version_item(list, "baseline_schema_version", baseline_schema_version);
|
||||
// only Normal state tenant can refresh snapshot_gc_scn
|
||||
ObGlobalStatItem snapshot_gc_scn_item(list, "snapshot_gc_scn", snapshot_gc_scn);
|
||||
if (OB_FAIL(update(list))) {
|
||||
LOG_WARN("update failed", KR(ret), K(list));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define SET_ITEM(name, value, is_incremental) \
|
||||
do { \
|
||||
ObGlobalStatItem::ItemList list; \
|
||||
ObGlobalStatItem item(list, name, value); \
|
||||
if (OB_FAIL(update(list, is_incremental))) { \
|
||||
LOG_WARN("update failed", K(list), K(ret)); \
|
||||
} \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
int ObGlobalStatProxy::set_core_schema_version(const int64_t core_schema_version)
|
||||
@ -103,27 +115,15 @@ int ObGlobalStatProxy::set_baseline_schema_version(const int64_t baseline_schema
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::set_frozen_version(const int64_t frozen_version, const bool is_incremental)
|
||||
int ObGlobalStatProxy::set_snapshot_gc_scn(const int64_t snapshot_gc_scn)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!is_valid() || frozen_version <= 0) {
|
||||
if (!is_valid() || snapshot_gc_scn <= 0) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid(), K(frozen_version));
|
||||
} else {
|
||||
SET_ITEM("frozen_version", frozen_version, is_incremental);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::set_snapshot_gc_ts(const int64_t snapshot_gc_ts)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!is_valid() || snapshot_gc_ts <= 0) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(snapshot_gc_ts), "self valid", is_valid());
|
||||
LOG_WARN("invalid argument", K(ret), K(snapshot_gc_scn), "self valid", is_valid());
|
||||
} else {
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem snapshot_gc_ts_item(list, "snapshot_gc_ts", snapshot_gc_ts);
|
||||
ObGlobalStatItem snapshot_gc_scn_item(list, "snapshot_gc_scn", snapshot_gc_scn);
|
||||
if (OB_FAIL(update(list))) {
|
||||
LOG_WARN("update failed", K(list), K(ret));
|
||||
}
|
||||
@ -131,48 +131,16 @@ int ObGlobalStatProxy::set_snapshot_gc_ts(const int64_t snapshot_gc_ts)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::set_gc_schema_versions(
|
||||
common::ObISQLClient& sql_client, const ObIArray<TenantIdAndSchemaVersion>& gc_schema_versions)
|
||||
int ObGlobalStatProxy::set_snapshot_info(const int64_t snapshot_gc_scn,
|
||||
const int64_t gc_schema_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObDMLSqlSplicer dml(ObDMLSqlSplicer::NAKED_VALUE_MODE);
|
||||
int64_t affected_rows = 0;
|
||||
ObArray<ObCoreTableProxy::UpdateCell> cells;
|
||||
ObCoreTableProxy kv(OB_ALL_GC_SCHEMA_VERSION_TNAME, sql_client);
|
||||
if (gc_schema_versions.count() <= 0) {
|
||||
if (!is_valid() || snapshot_gc_scn <= 0 || gc_schema_version <= 0) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", KR(ret), K(gc_schema_versions));
|
||||
} else if (OB_FAIL(kv.load_for_update())) {
|
||||
LOG_WARN("fail to load for update", KR(ret));
|
||||
}
|
||||
for (int64_t i = 0; i < gc_schema_versions.count() && OB_SUCC(ret); i++) {
|
||||
const TenantIdAndSchemaVersion& schema_info = gc_schema_versions.at(i);
|
||||
cells.reset();
|
||||
dml.reset();
|
||||
if (OB_FAIL(dml.add_pk_column(TENANT_ID_CNAME, schema_info.tenant_id_)) ||
|
||||
OB_FAIL(dml.add_column(GC_SCHEMA_VERSION_CNAME, schema_info.schema_version_))) {
|
||||
LOG_WARN("fail to add column", KR(ret));
|
||||
} else if (OB_FAIL(dml.splice_core_cells(kv, cells))) {
|
||||
LOG_WARN("fail to splice core cells", KR(ret));
|
||||
} else if (OB_FAIL(kv.replace_row(cells, affected_rows))) {
|
||||
LOG_WARN("replace_row failed", K(ret));
|
||||
} else if (!is_single_row(affected_rows) && !is_zero_row(affected_rows)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("affected_rows expected to be one", K(ret), K(affected_rows), K(kv));
|
||||
}
|
||||
} // end for
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::set_snapshot_info(const int64_t snapshot_gc_ts, const int64_t gc_schema_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!is_valid() || snapshot_gc_ts <= 0 || gc_schema_version <= 0) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(snapshot_gc_ts), K(gc_schema_version), "self valid", is_valid());
|
||||
LOG_WARN("invalid argument", K(ret), K(snapshot_gc_scn), K(gc_schema_version), "self valid", is_valid());
|
||||
} else {
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem snapshot_gc_ts_item(list, "snapshot_gc_ts", snapshot_gc_ts);
|
||||
ObGlobalStatItem snapshot_gc_scn_item(list, "snapshot_gc_scn", snapshot_gc_scn);
|
||||
ObGlobalStatItem gc_schema_version_item(list, "gc_schema_version", gc_schema_version);
|
||||
bool is_incremental = true;
|
||||
if (OB_FAIL(update(list, is_incremental))) {
|
||||
@ -182,194 +150,21 @@ int ObGlobalStatProxy::set_snapshot_info(const int64_t snapshot_gc_ts, const int
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::set_snapshot_info_v2(common::ObISQLClient& sql_proxy, const int64_t snapshot_gc_ts,
|
||||
const common::ObIArray<TenantIdAndSchemaVersion>& tenant_schema_versions, const bool set_gc_schema_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObDMLSqlSplicer dml(ObDMLSqlSplicer::NAKED_VALUE_MODE);
|
||||
int64_t affected_rows = 0;
|
||||
ObArray<ObCoreTableProxy::UpdateCell> cells;
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem snapshot_gc_ts_item(list, "snapshot_gc_ts", snapshot_gc_ts);
|
||||
ObMySQLTransaction trans;
|
||||
ObCoreTableProxy kv(OB_ALL_GLOBAL_STAT_TNAME, trans);
|
||||
const ObGlobalStatItem* it = list.get_first();
|
||||
if (!is_valid() || snapshot_gc_ts <= 0 || (set_gc_schema_version && tenant_schema_versions.count() <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(snapshot_gc_ts), K(tenant_schema_versions), "self valid", is_valid());
|
||||
} else if (OB_ISNULL(it)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("error unexpected", KR(ret), K(it));
|
||||
} else if (OB_FAIL(trans.start(&sql_proxy))) {
|
||||
LOG_WARN("fail to start transaction", KR(ret));
|
||||
} else {
|
||||
if (OB_FAIL(kv.load_for_update())) {
|
||||
LOG_WARN("fail to load for update", KR(ret));
|
||||
} else if (OB_FAIL(dml.add_column(it->name_, it->value_))) {
|
||||
LOG_WARN("fail to add column", KR(ret));
|
||||
} else if (OB_FAIL(dml.splice_core_cells(kv, cells))) {
|
||||
LOG_WARN("fail to splice core cells", KR(ret));
|
||||
} else if (OB_FAIL(kv.replace_row(cells, affected_rows))) {
|
||||
LOG_WARN("replace_row failed", K(ret));
|
||||
} else if (!is_single_row(affected_rows)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("affected_rows expected to be one", K(ret), K(affected_rows), K(kv));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret) && set_gc_schema_version) {
|
||||
ObCoreTableProxy kv2(OB_ALL_GC_SCHEMA_VERSION_TNAME, trans);
|
||||
if (OB_FAIL(ret)) {
|
||||
// nothing todo
|
||||
} else if (OB_FAIL(kv2.load_for_update())) {
|
||||
LOG_WARN("fail to load for update", KR(ret));
|
||||
}
|
||||
for (int64_t i = 0; i < tenant_schema_versions.count() && OB_SUCC(ret); i++) {
|
||||
const TenantIdAndSchemaVersion& schema_info = tenant_schema_versions.at(i);
|
||||
cells.reset();
|
||||
dml.reset();
|
||||
if (OB_FAIL(dml.add_pk_column(TENANT_ID_CNAME, schema_info.tenant_id_)) ||
|
||||
OB_FAIL(dml.add_column(GC_SCHEMA_VERSION_CNAME, schema_info.schema_version_))) {
|
||||
LOG_WARN("fail to add column", KR(ret));
|
||||
} else if (dml.splice_core_cells(kv2, cells)) {
|
||||
LOG_WARN("fail to splice core cells", KR(ret));
|
||||
} else if (OB_FAIL(kv2.incremental_replace_row(cells, affected_rows))) {
|
||||
LOG_WARN("replace_row failed", K(ret));
|
||||
} else if (!is_single_row(affected_rows) && !is_zero_row(affected_rows)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("affected_rows expected to be one", K(ret), K(affected_rows), K(kv));
|
||||
}
|
||||
} // end for
|
||||
}
|
||||
if (trans.is_started()) {
|
||||
bool is_commit = (OB_SUCCESS == ret);
|
||||
int tmp_ret = trans.end(is_commit);
|
||||
if (OB_SUCCESS != tmp_ret) {
|
||||
LOG_WARN("fail to commit transaction", K(ret), K(is_commit));
|
||||
if (OB_SUCC(ret)) {
|
||||
ret = tmp_ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::get_snapshot_gc_ts(int64_t& snapshot_gc_ts)
|
||||
int ObGlobalStatProxy::get_snapshot_gc_scn(int64_t &snapshot_gc_scn)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem snapshot_gc_ts_item(list, "snapshot_gc_ts", snapshot_gc_ts);
|
||||
ObGlobalStatItem snapshot_gc_scn_item(list, "snapshot_gc_scn", snapshot_gc_scn);
|
||||
ObTimeoutCtx ctx;
|
||||
if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid());
|
||||
} else if (OB_FAIL(rootserver::ObRootUtils::get_rs_default_timeout_ctx(ctx))) {
|
||||
LOG_WARN("fail to get timeout ctx", K(ret), K(ctx));
|
||||
} else if (OB_FAIL(get(list))) {
|
||||
LOG_WARN("get failed", K(ret));
|
||||
} else {
|
||||
snapshot_gc_ts = snapshot_gc_ts_item.value_;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
// tenant_id = 0 represent getting all tenants`s schema_version of gc
|
||||
int ObGlobalStatProxy::get_snapshot_info_v2(common::ObISQLClient& sql_proxy, const uint64_t tenant_id,
|
||||
const bool need_gc_schema_version, int64_t& snapshot_gc_ts, ObIArray<TenantIdAndSchemaVersion>& gc_schema_versions)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
gc_schema_versions.reset();
|
||||
ObMySQLTransaction trans;
|
||||
ObTimeoutCtx ctx;
|
||||
if (!is_valid()) {
|
||||
ret = OB_INNER_STAT_ERROR;
|
||||
LOG_WARN("inner error", KR(ret));
|
||||
} else if (OB_FAIL(rootserver::ObRootUtils::get_rs_default_timeout_ctx(ctx))) {
|
||||
LOG_WARN("fail to get timeout ctx", K(ret), K(ctx));
|
||||
} else {
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem snapshot_gc_ts_item(list, "snapshot_gc_ts", snapshot_gc_ts);
|
||||
if (OB_FAIL(get(list))) {
|
||||
LOG_WARN("fail to get", KR(ret));
|
||||
} else {
|
||||
snapshot_gc_ts = snapshot_gc_ts_item.value_;
|
||||
}
|
||||
ObCoreTableProxy kv(OB_ALL_GC_SCHEMA_VERSION_TNAME, sql_proxy);
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (!need_gc_schema_version) {
|
||||
// nothing todo
|
||||
} else if (OB_FAIL(kv.load())) {
|
||||
LOG_WARN("fail to load", KR(ret));
|
||||
} else {
|
||||
const ObCoreTableProxy::Row* row = NULL;
|
||||
int64_t tmp_tenant_id = OB_INVALID_TENANT_ID;
|
||||
int64_t gc_schema_version = 0;
|
||||
while (OB_SUCC(ret)) {
|
||||
tmp_tenant_id = OB_INVALID_TENANT_ID;
|
||||
if (OB_FAIL(kv.next())) {
|
||||
if (OB_ITER_END == ret) {
|
||||
ret = OB_SUCCESS;
|
||||
break;
|
||||
} else {
|
||||
LOG_WARN("fail to get next", KR(ret));
|
||||
}
|
||||
} else if (OB_FAIL(kv.get_cur_row(row))) {
|
||||
LOG_WARN("fail to get cur row", K(ret));
|
||||
} else if (OB_ISNULL(row)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("NULL row", K(ret));
|
||||
} else if (OB_FAIL(row->get_int(TENANT_ID_CNAME, tmp_tenant_id))) {
|
||||
LOG_WARN("fail to get int", KR(ret));
|
||||
} else if (tenant_id != tmp_tenant_id && tenant_id != 0) {
|
||||
// nothing todo
|
||||
} else if (OB_FAIL(row->get_int(GC_SCHEMA_VERSION_CNAME, gc_schema_version))) {
|
||||
LOG_WARN("fail to get int", KR(ret), K(tenant_id), K(tmp_tenant_id));
|
||||
} else if (OB_FAIL(gc_schema_versions.push_back(TenantIdAndSchemaVersion(tmp_tenant_id, gc_schema_version)))) {
|
||||
LOG_WARN("fail to push back", KR(ret), K(tmp_tenant_id), K(gc_schema_version));
|
||||
}
|
||||
} // end while
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret) || !need_gc_schema_version) {
|
||||
} else if (gc_schema_versions.count() <= 0) {
|
||||
ret = OB_ENTRY_NOT_EXIST;
|
||||
LOG_WARN("entry not exist", KR(ret), K(tenant_id));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::set_split_schema_version(const int64_t split_schema_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!is_valid() || split_schema_version <= 0) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid(), K(split_schema_version));
|
||||
} else {
|
||||
bool is_incremental = true;
|
||||
SET_ITEM("split_schema_version", split_schema_version, is_incremental);
|
||||
LOG_INFO("[UPGRADE] set split schema_version", K(ret), K(split_schema_version));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::set_split_schema_version_v2(const int64_t split_schema_version_v2)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!is_valid() || split_schema_version_v2 <= 0) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid(), K(split_schema_version_v2));
|
||||
} else {
|
||||
bool is_incremental = true;
|
||||
SET_ITEM("split_schema_version_v2", split_schema_version_v2, is_incremental);
|
||||
LOG_INFO("[UPGRADE] set split schema_version_v2", K(ret), K(split_schema_version_v2));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::set_next_schema_version(const int64_t next_schema_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!is_valid() || next_schema_version <= 0) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid(), K(next_schema_version));
|
||||
} else {
|
||||
bool is_incremental = true;
|
||||
SET_ITEM("next_schema_version", next_schema_version, is_incremental);
|
||||
snapshot_gc_scn = snapshot_gc_scn_item.value_;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -395,11 +190,12 @@ int ObGlobalStatProxy::inc_rootservice_epoch()
|
||||
}
|
||||
|
||||
#undef SET_ITEM
|
||||
int ObGlobalStatProxy::get_snapshot_info(int64_t& snapshot_gc_ts, int64_t& gc_schema_version)
|
||||
int ObGlobalStatProxy::get_snapshot_info(int64_t &snapshot_gc_scn,
|
||||
int64_t &gc_schema_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem snapshot_gc_ts_item(list, "snapshot_gc_ts", snapshot_gc_ts);
|
||||
ObGlobalStatItem snapshot_gc_scn_item(list, "snapshot_gc_scn", snapshot_gc_scn);
|
||||
ObGlobalStatItem gc_schema_version_item(list, "gc_schema_version", gc_schema_version);
|
||||
if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
@ -407,13 +203,15 @@ int ObGlobalStatProxy::get_snapshot_info(int64_t& snapshot_gc_ts, int64_t& gc_sc
|
||||
} else if (OB_FAIL(get(list))) {
|
||||
LOG_WARN("get failed", K(ret));
|
||||
} else {
|
||||
snapshot_gc_ts = snapshot_gc_ts_item.value_;
|
||||
snapshot_gc_scn = snapshot_gc_scn_item.value_;
|
||||
gc_schema_version = gc_schema_version_item.value_;
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::update(const ObGlobalStatItem::ItemList& list, const bool is_incremental)
|
||||
int ObGlobalStatProxy::update(const ObGlobalStatItem::ItemList &list,
|
||||
const bool is_incremental)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t affected_rows = 0;
|
||||
@ -421,11 +219,12 @@ int ObGlobalStatProxy::update(const ObGlobalStatItem::ItemList& list, const bool
|
||||
ObArray<ObCoreTableProxy::UpdateCell> cells;
|
||||
if (!is_valid() || list.is_empty()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid(), "list size", list.get_size());
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid(),
|
||||
"list size", list.get_size());
|
||||
} else if (OB_FAIL(core_table_.load_for_update())) {
|
||||
LOG_WARN("core_table_load_for_update failed", K(ret));
|
||||
} else {
|
||||
const ObGlobalStatItem* it = list.get_first();
|
||||
const ObGlobalStatItem *it = list.get_first();
|
||||
if (NULL == it) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("NULL iterator", K(ret));
|
||||
@ -451,7 +250,8 @@ int ObGlobalStatProxy::update(const ObGlobalStatItem::ItemList& list, const bool
|
||||
LOG_WARN("replace_row failed", K(ret));
|
||||
} else if (!is_incremental && !is_single_row(affected_rows)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("affected_rows expected to be one", K(ret), K(affected_rows), K_(core_table));
|
||||
LOG_WARN("affected_rows expected to be one", K(ret), K(affected_rows),
|
||||
K_(core_table));
|
||||
} else if (is_incremental && affected_rows >= 2) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("affected row should less than 2", K(ret), K(affected_rows));
|
||||
@ -459,16 +259,15 @@ int ObGlobalStatProxy::update(const ObGlobalStatItem::ItemList& list, const bool
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::get_core_schema_version(const int64_t frozen_version, int64_t& core_schema_version)
|
||||
int ObGlobalStatProxy::get_core_schema_version(int64_t &core_schema_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem core_schema_version_item(list, "core_schema_version", core_schema_version);
|
||||
// frozen_version can be invalid for read the newest value
|
||||
if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid());
|
||||
} else if (OB_FAIL(get(list, frozen_version))) {
|
||||
} else if (OB_FAIL(get(list))) {
|
||||
LOG_WARN("get failed", K(ret));
|
||||
} else {
|
||||
core_schema_version = core_schema_version_item.value_;
|
||||
@ -476,16 +275,15 @@ int ObGlobalStatProxy::get_core_schema_version(const int64_t frozen_version, int
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::get_baseline_schema_version(const int64_t frozen_version, int64_t& baseline_schema_version)
|
||||
int ObGlobalStatProxy::get_baseline_schema_version(int64_t &baseline_schema_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem baseline_schema_version_item(list, "baseline_schema_version", baseline_schema_version);
|
||||
// frozen_version can be invalid for read the newest value
|
||||
if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid());
|
||||
} else if (OB_FAIL(get(list, frozen_version))) {
|
||||
} else if (OB_FAIL(get(list))) {
|
||||
LOG_WARN("get failed", K(ret));
|
||||
} else {
|
||||
baseline_schema_version = baseline_schema_version_item.value_;
|
||||
@ -493,60 +291,7 @@ int ObGlobalStatProxy::get_baseline_schema_version(const int64_t frozen_version,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::get_frozen_info(int64_t& frozen_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem frozen_version_item(list, "frozen_version", frozen_version);
|
||||
if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid());
|
||||
} else if (OB_FAIL(get(list))) {
|
||||
LOG_WARN("get failed", K(ret));
|
||||
} else {
|
||||
frozen_version = frozen_version_item.value_;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::get_split_schema_version(int64_t& split_schema_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem split_schema_version_item(list, "split_schema_version", split_schema_version);
|
||||
if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid());
|
||||
} else if (OB_FAIL(get(list))) {
|
||||
LOG_WARN("get failed", K(ret));
|
||||
} else {
|
||||
split_schema_version = split_schema_version_item.value_;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::get_split_schema_version_v2(int64_t& split_schema_version_v2)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem split_schema_version_v2_item(list, "split_schema_version_v2", split_schema_version_v2);
|
||||
if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid());
|
||||
} else if (OB_FAIL(get(list))) {
|
||||
if (OB_ERR_NULL_VALUE != ret) {
|
||||
LOG_WARN("get int value failed", K(ret));
|
||||
} else {
|
||||
ret = OB_SUCCESS; // for compatible
|
||||
split_schema_version_v2 = OB_INVALID_VERSION;
|
||||
}
|
||||
} else {
|
||||
split_schema_version_v2 = split_schema_version_v2_item.value_;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::get_rootservice_epoch(int64_t& rootservice_epoch)
|
||||
int ObGlobalStatProxy::get_rootservice_epoch(int64_t &rootservice_epoch)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObGlobalStatItem::ItemList list;
|
||||
@ -561,39 +306,18 @@ int ObGlobalStatProxy::get_rootservice_epoch(int64_t& rootservice_epoch)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int ObGlobalStatProxy::get_next_schema_version(int64_t& next_schema_version)
|
||||
|
||||
int ObGlobalStatProxy::get(ObGlobalStatItem::ItemList &list)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
next_schema_version = OB_INVALID_VERSION;
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem next_schema_version_item(list, "next_schema_version", next_schema_version);
|
||||
if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid());
|
||||
} else if (OB_FAIL(get(list))) {
|
||||
if (OB_EMPTY_RESULT == ret) {
|
||||
next_schema_version = OB_INVALID_VERSION;
|
||||
ret = OB_SUCCESS;
|
||||
LOG_INFO("maybe in bootstrap phase", K(ret));
|
||||
} else {
|
||||
LOG_WARN("get failed", K(ret));
|
||||
}
|
||||
} else {
|
||||
next_schema_version = next_schema_version_item.value_;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int ObGlobalStatProxy::get(ObGlobalStatItem::ItemList& list, const int64_t frozen_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
// frozen_version can be invalid for read the newest value
|
||||
ObTimeoutCtx ctx;
|
||||
if (!is_valid() || list.is_empty()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid(), "list size", list.get_size());
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid(),
|
||||
"list size", list.get_size());
|
||||
} else if (OB_FAIL(rootserver::ObRootUtils::get_rs_default_timeout_ctx(ctx))) {
|
||||
LOG_WARN("fail to get timeout ctx", K(ret), K(ctx));
|
||||
} else if (OB_FAIL(core_table_.load(frozen_version))) {
|
||||
} else if (OB_FAIL(core_table_.load())) {
|
||||
LOG_WARN("core_table load failed", K(ret));
|
||||
} else {
|
||||
if (OB_FAIL(core_table_.next())) {
|
||||
@ -604,7 +328,7 @@ int ObGlobalStatProxy::get(ObGlobalStatItem::ItemList& list, const int64_t froze
|
||||
LOG_WARN("next failed", K(ret));
|
||||
}
|
||||
} else {
|
||||
ObGlobalStatItem* it = list.get_first();
|
||||
ObGlobalStatItem *it = list.get_first();
|
||||
if (NULL == it) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("NULL iterator", K(ret));
|
||||
@ -636,19 +360,21 @@ int ObGlobalStatProxy::get(ObGlobalStatItem::ItemList& list, const int64_t froze
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::select_gc_timestamp_for_update(common::ObISQLClient& sql_client, int64_t& gc_timestamp)
|
||||
int ObGlobalStatProxy::select_snapshot_gc_scn_for_update(
|
||||
common::ObISQLClient &sql_client,
|
||||
const uint64_t tenant_id,
|
||||
int64_t &snapshot_gc_scn)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
gc_timestamp = 0;
|
||||
SMART_VAR(ObMySQLProxy::MySQLResult, res)
|
||||
{
|
||||
ObMySQLResult* result = NULL;
|
||||
snapshot_gc_scn = 0;
|
||||
SMART_VAR(ObMySQLProxy::MySQLResult, res) {
|
||||
ObMySQLResult *result = NULL;
|
||||
ObSqlString sql;
|
||||
if (OB_FAIL(sql.assign_fmt("SELECT column_value FROM %s WHERE TABLE_NAME = '__all_global_stat' AND COLUMN_NAME = "
|
||||
"'snapshot_gc_ts' FOR UPDATE",
|
||||
OB_ALL_CORE_TABLE_TNAME))) {
|
||||
if (OB_FAIL(sql.assign_fmt(
|
||||
"SELECT column_value FROM %s WHERE TABLE_NAME = '__all_global_stat' AND COLUMN_NAME"
|
||||
" = 'snapshot_gc_scn' FOR UPDATE", OB_ALL_CORE_TABLE_TNAME))) {
|
||||
LOG_WARN("assign sql failed", K(ret));
|
||||
} else if (OB_FAIL(sql_client.read(res, sql.ptr()))) {
|
||||
} else if (OB_FAIL(sql_client.read(res, tenant_id, sql.ptr()))) {
|
||||
LOG_WARN("execute sql failed", K(ret), K(sql));
|
||||
} else if (NULL == (result = res.get_result())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
@ -656,32 +382,40 @@ int ObGlobalStatProxy::select_gc_timestamp_for_update(common::ObISQLClient& sql_
|
||||
} else if (OB_FAIL(result->next())) {
|
||||
LOG_WARN("fail to get next row", K(ret));
|
||||
} else {
|
||||
ObString gc_timestamp_str;
|
||||
char* endptr = NULL;
|
||||
EXTRACT_VARCHAR_FIELD_MYSQL(*result, "column_value", gc_timestamp_str);
|
||||
ObString snapshot_gc_scn_str;
|
||||
EXTRACT_VARCHAR_FIELD_MYSQL(*result, "column_value", snapshot_gc_scn_str);
|
||||
|
||||
char *endptr = NULL;
|
||||
char buf[common::MAX_ZONE_INFO_LENGTH];
|
||||
MEMCPY(buf, gc_timestamp_str.ptr(), gc_timestamp_str.length());
|
||||
buf[gc_timestamp_str.length()] = '\0';
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (gc_timestamp_str.empty()) {
|
||||
ret = OB_INVALID_DATA;
|
||||
LOG_WARN("get invalid gc timestamp str", K(ret));
|
||||
} else {
|
||||
gc_timestamp = strtoll(buf, &endptr, 0);
|
||||
if ('\0' != *endptr) {
|
||||
if (OB_SUCC(ret)) {
|
||||
const int64_t str_len = snapshot_gc_scn_str.length();
|
||||
const int64_t buf_len = sizeof(buf);
|
||||
if ((str_len <= 0) || snapshot_gc_scn_str.empty()) {
|
||||
ret = OB_INVALID_DATA;
|
||||
LOG_WARN("invalid data, is not int value",
|
||||
K(ret),
|
||||
K(gc_timestamp_str),
|
||||
K(gc_timestamp_str.ptr()),
|
||||
K(strlen(gc_timestamp_str.ptr())));
|
||||
LOG_WARN("get invalid gc timestamp str", KR(ret), K(str_len), K(snapshot_gc_scn_str));
|
||||
} else if (str_len >= buf_len) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("buf is not enough to hold snapshot_gc_scn_str", KR(ret), K(str_len), K(buf_len));
|
||||
} else {
|
||||
MEMCPY(buf, snapshot_gc_scn_str.ptr(), str_len);
|
||||
buf[str_len] = '\0';
|
||||
//TODO:SCN strtolu
|
||||
snapshot_gc_scn = strtoll(buf, &endptr, 0);
|
||||
if ('\0' != *endptr) {
|
||||
ret = OB_INVALID_DATA;
|
||||
LOG_WARN("invalid data, is not int value", KR(ret), K(snapshot_gc_scn_str),
|
||||
K(snapshot_gc_scn_str.ptr()), K(strlen(snapshot_gc_scn_str.ptr())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int tmp_ret = OB_SUCCESS;
|
||||
if (OB_FAIL(ret)) {
|
||||
// nothing todo
|
||||
} else if (OB_ITER_END != result->next()) {
|
||||
LOG_WARN("get more row than one", K(ret));
|
||||
//nothing todo
|
||||
} else if (OB_ITER_END != (tmp_ret = result->next())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get more row than one", KR(ret), KR(tmp_ret));
|
||||
} else {
|
||||
ret = OB_SUCCESS;
|
||||
}
|
||||
@ -689,39 +423,29 @@ int ObGlobalStatProxy::select_gc_timestamp_for_update(common::ObISQLClient& sql_
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::set_schema_snapshot_version(const int64_t schema_snapshot_version, const int64_t frozen_version)
|
||||
int ObGlobalStatProxy::update_snapshot_gc_scn(
|
||||
common::ObISQLClient &sql_client,
|
||||
const uint64_t tenant_id,
|
||||
const int64_t snapshot_gc_scn,
|
||||
int64_t &affected_rows)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!is_valid()) {
|
||||
affected_rows = 0;
|
||||
if (!is_valid_tenant_id(tenant_id)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(schema_snapshot_version), "self valid", is_valid());
|
||||
LOG_WARN("invalid argument", KR(ret), K(tenant_id));
|
||||
} else {
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem schema_version_item(list, "standby_snapshot_schema_version", schema_snapshot_version);
|
||||
ObGlobalStatItem frozen_version_item(list, "standby_snapshot_frozen_version", frozen_version);
|
||||
if (OB_FAIL(update(list))) {
|
||||
LOG_WARN("update failed", K(list), K(ret));
|
||||
ObSqlString sql;
|
||||
if (OB_FAIL(sql.assign_fmt("UPDATE %s SET column_value = %ld WHERE table_name = '%s' AND "
|
||||
"column_name = '%s' AND column_value < %ld", OB_ALL_CORE_TABLE_TNAME, snapshot_gc_scn,
|
||||
"__all_global_stat", "snapshot_gc_scn", snapshot_gc_scn))) {
|
||||
LOG_WARN("fail to append sql", KR(ret), K(tenant_id), K(snapshot_gc_scn));
|
||||
} else if (OB_FAIL(sql_client.write(tenant_id, sql.ptr(), affected_rows))) {
|
||||
LOG_WARN("fail to execute sql", KR(ret), K(tenant_id), K(sql));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObGlobalStatProxy::get_schema_snapshot_version(int64_t& schema_snapshot_version, int64_t& frozen_version)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObGlobalStatItem::ItemList list;
|
||||
ObGlobalStatItem schema_version_item(list, "standby_snapshot_schema_version", schema_snapshot_version);
|
||||
ObGlobalStatItem frozen_version_item(list, "standby_snapshot_frozen_version", frozen_version);
|
||||
if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), "self valid", is_valid());
|
||||
} else if (OB_FAIL(get(list))) {
|
||||
LOG_WARN("get failed", K(ret));
|
||||
} else {
|
||||
schema_snapshot_version = schema_version_item.value_;
|
||||
frozen_version = frozen_version_item.value_;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // end namespace share
|
||||
} // end namespace oceanbase
|
||||
}//end namespace share
|
||||
}//end namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user