Commit 3e792e6c authored by Nirbhay Choubey's avatar Nirbhay Choubey

MDEV-4018 : Feature Request: microseconds in GET_LOCK()

Updated MDL_context's lock methods to accept double precision
lock_wait_timeout.
parent 5298e21c
...@@ -1169,6 +1169,46 @@ INET6_NTOA(ip) HEX(ip) LENGTH(ip) ...@@ -1169,6 +1169,46 @@ INET6_NTOA(ip) HEX(ip) LENGTH(ip)
DROP TABLE t1; DROP TABLE t1;
DROP TABLE t2; DROP TABLE t2;
#
# MDEV-4018 : Microseconds in GET_LOCK()
#
# -> Switching to connection 'default'
select is_used_lock('test') = connection_id();
is_used_lock('test') = connection_id()
NULL
# GET_LOCK returns 1 if it manages to acquire a lock
select get_lock('test', 0);
get_lock('test', 0)
1
# -> Switching to connection 'con1'
select is_used_lock('test') = connection_id();
is_used_lock('test') = connection_id()
0
select get_lock('test', 0);
get_lock('test', 0)
0
select get_lock('test', 1.0);
get_lock('test', 1.0)
0
select get_lock('test', 1.5);
get_lock('test', 1.5)
0
select get_lock('test', 0.1);
get_lock('test', 0.1)
0
select get_lock('test', 0.000001);
get_lock('test', 0.000001)
0
select get_lock('test', 0.0000000000000001);
get_lock('test', 0.0000000000000001)
0
# -> Switching to connection 'default'
select is_used_lock('test') = connection_id();
is_used_lock('test') = connection_id()
1
select release_lock('test');
release_lock('test')
1
# -- Done. # -- Done.
...@@ -863,6 +863,33 @@ SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2; ...@@ -863,6 +863,33 @@ SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2;
DROP TABLE t1; DROP TABLE t1;
DROP TABLE t2; DROP TABLE t2;
--echo #
--echo # MDEV-4018 : Microseconds in GET_LOCK()
--echo #
--echo # -> Switching to connection 'default'
connection default;
select is_used_lock('test') = connection_id();
--echo # GET_LOCK returns 1 if it manages to acquire a lock
select get_lock('test', 0);
connect (con1,localhost,root,,);
--echo # -> Switching to connection 'con1'
connection con1;
select is_used_lock('test') = connection_id();
select get_lock('test', 0);
select get_lock('test', 1.0);
select get_lock('test', 1.5);
select get_lock('test', 0.1);
select get_lock('test', 0.000001);
select get_lock('test', 0.0000000000000001);
--echo # -> Switching to connection 'default'
connection default;
select is_used_lock('test') = connection_id();
select release_lock('test');
--echo --echo
--echo # -- Done. --echo # -- Done.
--echo --echo
...@@ -4257,7 +4257,7 @@ longlong Item_func_get_lock::val_int() ...@@ -4257,7 +4257,7 @@ longlong Item_func_get_lock::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
String *res= args[0]->val_str(&value); String *res= args[0]->val_str(&value);
ulonglong timeout= args[1]->val_int(); double timeout= args[1]->val_real();
THD *thd= current_thd; THD *thd= current_thd;
User_level_lock *ull; User_level_lock *ull;
DBUG_ENTER("Item_func_get_lock::val_int"); DBUG_ENTER("Item_func_get_lock::val_int");
......
...@@ -2388,7 +2388,7 @@ void MDL_scoped_lock::notify_conflicting_locks(MDL_context *ctx) ...@@ -2388,7 +2388,7 @@ void MDL_scoped_lock::notify_conflicting_locks(MDL_context *ctx)
*/ */
bool bool
MDL_context::acquire_lock(MDL_request *mdl_request, ulong lock_wait_timeout) MDL_context::acquire_lock(MDL_request *mdl_request, double lock_wait_timeout)
{ {
MDL_lock *lock; MDL_lock *lock;
MDL_ticket *ticket; MDL_ticket *ticket;
...@@ -2550,7 +2550,7 @@ extern "C" int mdl_request_ptr_cmp(const void* ptr1, const void* ptr2) ...@@ -2550,7 +2550,7 @@ extern "C" int mdl_request_ptr_cmp(const void* ptr1, const void* ptr2)
*/ */
bool MDL_context::acquire_locks(MDL_request_list *mdl_requests, bool MDL_context::acquire_locks(MDL_request_list *mdl_requests,
ulong lock_wait_timeout) double lock_wait_timeout)
{ {
MDL_request_list::Iterator it(*mdl_requests); MDL_request_list::Iterator it(*mdl_requests);
MDL_request **sort_buf, **p_req; MDL_request **sort_buf, **p_req;
...@@ -2623,13 +2623,13 @@ err: ...@@ -2623,13 +2623,13 @@ err:
bool bool
MDL_context::upgrade_shared_lock(MDL_ticket *mdl_ticket, MDL_context::upgrade_shared_lock(MDL_ticket *mdl_ticket,
enum_mdl_type new_type, enum_mdl_type new_type,
ulong lock_wait_timeout) double lock_wait_timeout)
{ {
MDL_request mdl_xlock_request; MDL_request mdl_xlock_request;
MDL_savepoint mdl_svp= mdl_savepoint(); MDL_savepoint mdl_svp= mdl_savepoint();
bool is_new_ticket; bool is_new_ticket;
DBUG_ENTER("MDL_context::upgrade_shared_lock"); DBUG_ENTER("MDL_context::upgrade_shared_lock");
DBUG_PRINT("enter",("new_type: %d lock_wait_timeout: %lu", new_type, DBUG_PRINT("enter",("new_type: %d lock_wait_timeout: %f", new_type,
lock_wait_timeout)); lock_wait_timeout));
DEBUG_SYNC(get_thd(), "mdl_upgrade_lock"); DEBUG_SYNC(get_thd(), "mdl_upgrade_lock");
......
...@@ -752,11 +752,11 @@ public: ...@@ -752,11 +752,11 @@ public:
void destroy(); void destroy();
bool try_acquire_lock(MDL_request *mdl_request); bool try_acquire_lock(MDL_request *mdl_request);
bool acquire_lock(MDL_request *mdl_request, ulong lock_wait_timeout); bool acquire_lock(MDL_request *mdl_request, double lock_wait_timeout);
bool acquire_locks(MDL_request_list *requests, ulong lock_wait_timeout); bool acquire_locks(MDL_request_list *requests, double lock_wait_timeout);
bool upgrade_shared_lock(MDL_ticket *mdl_ticket, bool upgrade_shared_lock(MDL_ticket *mdl_ticket,
enum_mdl_type new_type, enum_mdl_type new_type,
ulong lock_wait_timeout); double lock_wait_timeout);
bool clone_ticket(MDL_request *mdl_request); bool clone_ticket(MDL_request *mdl_request);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment