Skip to content

Commit

Permalink
[CP] Fix circular wait between row lock and tenant rpc thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongqin-Li authored and ob-robot committed Nov 8, 2023
1 parent 5198a80 commit cd1eea4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/rootserver/ddl_task/ob_ddl_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3253,7 +3253,7 @@ int ObDDLTaskRecordOperator::select_for_update(
} else {
SMART_VAR(ObMySQLProxy::MySQLResult, res) {
sqlclient::ObMySQLResult *result = NULL;
if (OB_FAIL(sql_string.assign_fmt("SELECT status, execution_id FROM %s WHERE task_id = %lu FOR UPDATE",
if (OB_FAIL(sql_string.assign_fmt("SELECT status, execution_id FROM %s WHERE task_id = %lu FOR UPDATE NOWAIT",
OB_ALL_DDL_TASK_STATUS_TNAME, task_id))) {
LOG_WARN("assign sql string failed", K(ret), K(task_id), K(tenant_id));
} else if (OB_FAIL(trans.read(res, tenant_id, sql_string.ptr()))) {
Expand Down
16 changes: 12 additions & 4 deletions src/share/ob_global_stat_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,27 +483,35 @@ int ObGlobalStatProxy::get(
return ret;
}

int ObGlobalStatProxy::select_snapshot_gc_scn_for_update_nowait(
common::ObISQLClient &sql_client,
const uint64_t tenant_id,
SCN &snapshot_gc_scn)
{
return inner_get_snapshot_gc_scn_(sql_client, tenant_id, snapshot_gc_scn, "FOR UPDATE NOWAIT");
}

int ObGlobalStatProxy::select_snapshot_gc_scn_for_update(
common::ObISQLClient &sql_client,
const uint64_t tenant_id,
SCN &snapshot_gc_scn)
{
return inner_get_snapshot_gc_scn_(sql_client, tenant_id, snapshot_gc_scn, true);
return inner_get_snapshot_gc_scn_(sql_client, tenant_id, snapshot_gc_scn, "FOR UPDATE");
}

int ObGlobalStatProxy::get_snapshot_gc_scn(
common::ObISQLClient &sql_client,
const uint64_t tenant_id,
SCN &snapshot_gc_scn)
{
return inner_get_snapshot_gc_scn_(sql_client, tenant_id, snapshot_gc_scn, false);
return inner_get_snapshot_gc_scn_(sql_client, tenant_id, snapshot_gc_scn, "");
}

int ObGlobalStatProxy::inner_get_snapshot_gc_scn_(
common::ObISQLClient &sql_client,
const uint64_t tenant_id,
SCN &snapshot_gc_scn,
const bool is_for_update)
const char *for_update_str)
{
int ret = OB_SUCCESS;
uint64_t snapshot_gc_scn_val = 0;
Expand All @@ -512,7 +520,7 @@ int ObGlobalStatProxy::inner_get_snapshot_gc_scn_(
ObSqlString sql;
if (OB_FAIL(sql.assign_fmt(
"SELECT column_value FROM %s WHERE TABLE_NAME = '__all_global_stat' AND COLUMN_NAME"
" = 'snapshot_gc_scn' %s", OB_ALL_CORE_TABLE_TNAME, (is_for_update ? "FOR UPDATE" : "")))) {
" = 'snapshot_gc_scn' %s", OB_ALL_CORE_TABLE_TNAME, for_update_str))) {
LOG_WARN("assign sql failed", K(ret));
} else if (OB_FAIL(sql_client.read(res, tenant_id, sql.ptr()))) {
LOG_WARN("execute sql failed", K(ret), K(sql));
Expand Down
5 changes: 4 additions & 1 deletion src/share/ob_global_stat_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class ObGlobalStatProxy

virtual int get_snapshot_info(int64_t &snapshot_gc_scn,
int64_t &gc_schema_version);
static int select_snapshot_gc_scn_for_update_nowait(common::ObISQLClient &sql_client,
const uint64_t tenant_id,
SCN &snapshot_gc_scn);
static int select_snapshot_gc_scn_for_update(common::ObISQLClient &sql_client,
const uint64_t tenant_id,
SCN &snapshot_gc_scn);
Expand All @@ -107,7 +110,7 @@ class ObGlobalStatProxy
static int inner_get_snapshot_gc_scn_(common::ObISQLClient &sql_client,
const uint64_t tenant_id,
SCN &snapshot_gc_scn,
const bool is_for_update);
const char *for_update_str);
int update(const ObGlobalStatItem::ItemList &list, const bool is_incremental = false);
int get(ObGlobalStatItem::ItemList &list, bool for_update = false);

Expand Down
2 changes: 1 addition & 1 deletion src/share/ob_snapshot_table_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ int ObSnapshotTableProxy::batch_add_snapshot(
info.snapshot_scn_ = snapshot_scn;
info.schema_version_ = schema_version;
info.comment_ = comment;
if (OB_FAIL(ObGlobalStatProxy::select_snapshot_gc_scn_for_update(trans, tenant_id, snapshot_gc_scn))) {
if (OB_FAIL(ObGlobalStatProxy::select_snapshot_gc_scn_for_update_nowait(trans, tenant_id, snapshot_gc_scn))) {
LOG_WARN("fail to select gc timstamp for update", KR(ret), K(info), K(tenant_id));
}
while (OB_SUCC(ret) && report_idx < tablet_id_array.count()) {
Expand Down

0 comments on commit cd1eea4

Please sign in to comment.