[tablelock] do not throw deadlock error code when the timeout parameter of LOCK TABLE statment is larger than 1 min

This commit is contained in:
YangEfei
2023-05-16 02:11:33 +00:00
committed by ob-robot
parent 88b861540e
commit da78951e6d
7 changed files with 19 additions and 7 deletions

View File

@ -1141,6 +1141,7 @@ int ObSqlTransControl::lock_table(ObExecContext &exec_ctx,
arg.lock_mode_ = lock_mode;
arg.op_type_ = ObTableLockOpType::IN_TRANS_COMMON_LOCK;
arg.timeout_us_ = lock_timeout_us;
arg.is_from_sql_ = true;
OZ (lock_service->lock_table(*session->get_tx_desc(),
tx_param,
@ -1153,6 +1154,8 @@ int ObSqlTransControl::lock_table(ObExecContext &exec_ctx,
arg.lock_mode_ = lock_mode;
arg.op_type_ = ObTableLockOpType::IN_TRANS_COMMON_LOCK;
arg.timeout_us_ = lock_timeout_us;
arg.is_from_sql_ = true;
for (int64_t i = 0; i < part_ids.count() && OB_SUCC(ret); ++i) {
arg.part_object_id_ = part_ids.at(i);
OZ(lock_service->lock_partition_or_subpartition(*session->get_tx_desc(),

View File

@ -28,9 +28,9 @@ namespace tablelock
constexpr const char ObSimpleIteratorModIds::OB_OBJ_LOCK[];
constexpr const char ObSimpleIteratorModIds::OB_OBJ_LOCK_MAP[];
bool is_deadlock_avoid_enabled(const int64_t timeout_us)
bool is_deadlock_avoid_enabled(const bool is_from_sql, const int64_t timeout_us)
{
return (timeout_us >= MIN_DEADLOCK_AVOID_TIMEOUT_US);
return (!is_from_sql && timeout_us >= MIN_DEADLOCK_AVOID_TIMEOUT_US);
}
OB_SERIALIZE_MEMBER(ObTableLockOp, lock_id_,

View File

@ -472,7 +472,7 @@ typedef common::ObSimpleIterator<ObTableLockOp, ObSimpleIteratorModIds::OB_OBJ_L
// the threshold of timeout interval which will enable the deadlock avoid.
static const int64_t MIN_DEADLOCK_AVOID_TIMEOUT_US = 60 * 1000 * 1000; // 1 min
bool is_deadlock_avoid_enabled(const int64_t expire_time);
bool is_deadlock_avoid_enabled(const bool is_from_sql, const int64_t expire_time);
} // tablelock
} // transaction

View File

@ -37,7 +37,8 @@ OB_SERIALIZE_MEMBER(ObLockRequest,
owner_id_,
lock_mode_,
op_type_,
timeout_us_);
timeout_us_,
is_from_sql_);
OB_SERIALIZE_MEMBER_INHERIT(ObLockObjRequest, ObLockRequest,
obj_type_,

View File

@ -115,7 +115,8 @@ public:
owner_id_(0),
lock_mode_(NO_LOCK),
op_type_(UNKNOWN_TYPE),
timeout_us_(0)
timeout_us_(0),
is_from_sql_(false)
{ type_ = ObLockMsgType::UNKNOWN_MSG_TYPE; }
virtual ~ObLockRequest() { reset(); }
virtual void reset();
@ -127,6 +128,7 @@ public:
ObTableLockMode lock_mode_;
ObTableLockOpType op_type_;
int64_t timeout_us_;
bool is_from_sql_;
};
struct ObLockObjRequest : public ObLockRequest

View File

@ -54,6 +54,7 @@ ObTableLockService::ObTableLockCtx::ObTableLockCtx(const ObTableLockTaskType tas
tablet_list_(),
schema_version_(-1),
tx_is_killed_(false),
is_from_sql_(false),
stmt_savepoint_(-1)
{
abs_timeout_ts_ = (0 == timeout_us)
@ -274,7 +275,7 @@ void ObTableLockService::ObTableLockCtx::clean_touched_ls()
bool ObTableLockService::ObTableLockCtx::is_deadlock_avoid_enabled() const
{
return tablelock::is_deadlock_avoid_enabled(origin_timeout_us_);
return tablelock::is_deadlock_avoid_enabled(is_from_sql_, origin_timeout_us_);
}
int ObTableLockService::mtl_init(ObTableLockService* &lock_service)
@ -507,6 +508,7 @@ int ObTableLockService::lock_table(ObTxDesc &tx_desc,
ctx.tx_desc_ = &tx_desc;
ctx.tx_param_ = tx_param;
ctx.lock_op_type_ = arg.op_type_;
ctx.is_from_sql_ = arg.is_from_sql_;
ret = process_lock_task_(ctx, arg.lock_mode_, arg.owner_id_);
}
return ret;
@ -653,6 +655,7 @@ int ObTableLockService::lock_partition(ObTxDesc &tx_desc,
ctx.tx_desc_ = &tx_desc;
ctx.tx_param_ = tx_param;
ctx.lock_op_type_ = arg.op_type_;
ctx.is_from_sql_ = arg.is_from_sql_;
ret = process_lock_task_(ctx, arg.lock_mode_, arg.owner_id_);
}
return ret;
@ -708,6 +711,7 @@ int ObTableLockService::lock_subpartition(ObTxDesc &tx_desc,
ctx.tx_desc_ = &tx_desc;
ctx.tx_param_ = tx_param;
ctx.lock_op_type_ = arg.op_type_;
ctx.is_from_sql_ = arg.is_from_sql_;
ret = process_lock_task_(ctx, arg.lock_mode_, arg.owner_id_);
}
return ret;

View File

@ -129,6 +129,7 @@ private:
// share::ObLSArray ls_list_; // related ls list
int64_t schema_version_; // the schema version of the table to be locked
bool tx_is_killed_; // used to kill a trans.
bool is_from_sql_;
// use to kill the whole lock table stmt.
int64_t stmt_savepoint_;
@ -138,7 +139,8 @@ private:
K(origin_timeout_us_), K(timeout_us_),
K(abs_timeout_ts_), KPC(tx_desc_), K(tx_param_),
K(current_savepoint_), K(need_rollback_ls_),
K(tablet_list_), K(schema_version_), K(tx_is_killed_), K(stmt_savepoint_));
K(tablet_list_), K(schema_version_), K(tx_is_killed_),
K(is_from_sql_), K(stmt_savepoint_));
};
public:
class ObOBJLockGarbageCollector