[Commits] be34f4c: MDEV-4018 : Feature Request: microseconds in GET_LOCK()

nirbhay at mariadb.com nirbhay at mariadb.com
Fri Nov 28 18:43:42 EET 2014


revision-id: be34f4c82dc951f97864faff0726efbbcdd3858c
parent(s): 7b55b67de5fdfe91283357fe6c7ccc3f9e355925
committer: Nirbhay Choubey
branch nick: b4018
timestamp: 2014-11-28 11:42:42 -0500
message:

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

Updated MDL_context's lock methods to accept double precision
lock_wait_timeout.

MariaDB [(none)]> select get_lock('test', 0.5);
+-----------------------+
| get_lock('test', 0.5) |
+-----------------------+
|                     0 |
+-----------------------+
1 row in set (0.50 sec)

---
 mysql-test/r/func_misc.result | 40 ++++++++++++++++++++++++++++++++++++++++
 mysql-test/t/func_misc.test   | 27 +++++++++++++++++++++++++++
 sql/item_func.cc              |  2 +-
 sql/mdl.cc                    |  8 ++++----
 sql/mdl.h                     |  6 +++---
 5 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result
index 5ae9ae1..7c01c8a 100644
--- a/mysql-test/r/func_misc.result
+++ b/mysql-test/r/func_misc.result
@@ -1169,6 +1169,46 @@ INET6_NTOA(ip)	HEX(ip)	LENGTH(ip)
 
 DROP TABLE t1;
 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.
 
diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test
index 8b1f0ca..5236987 100644
--- a/mysql-test/t/func_misc.test
+++ b/mysql-test/t/func_misc.test
@@ -863,6 +863,33 @@ SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2;
 DROP TABLE t1;
 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 # -- Done.
 --echo
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 25c0197..30a9aa9 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -4257,7 +4257,7 @@ longlong Item_func_get_lock::val_int()
 {
   DBUG_ASSERT(fixed == 1);
   String *res= args[0]->val_str(&value);
-  ulonglong timeout= args[1]->val_int();
+  double timeout= args[1]->val_real();
   THD *thd= current_thd;
   User_level_lock *ull;
   DBUG_ENTER("Item_func_get_lock::val_int");
diff --git a/sql/mdl.cc b/sql/mdl.cc
index 42f12a4..09c26cf 100644
--- a/sql/mdl.cc
+++ b/sql/mdl.cc
@@ -2388,7 +2388,7 @@ void MDL_scoped_lock::notify_conflicting_locks(MDL_context *ctx)
 */
 
 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_ticket *ticket;
@@ -2550,7 +2550,7 @@ void MDL_scoped_lock::notify_conflicting_locks(MDL_context *ctx)
 */
 
 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 **sort_buf, **p_req;
@@ -2623,13 +2623,13 @@ bool MDL_context::acquire_locks(MDL_request_list *mdl_requests,
 bool
 MDL_context::upgrade_shared_lock(MDL_ticket *mdl_ticket,
                                  enum_mdl_type new_type,
-                                 ulong lock_wait_timeout)
+                                 double lock_wait_timeout)
 {
   MDL_request mdl_xlock_request;
   MDL_savepoint mdl_svp= mdl_savepoint();
   bool is_new_ticket;
   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));
   DEBUG_SYNC(get_thd(), "mdl_upgrade_lock");
 
diff --git a/sql/mdl.h b/sql/mdl.h
index 27289e6..44e692b 100644
--- a/sql/mdl.h
+++ b/sql/mdl.h
@@ -752,11 +752,11 @@ class MDL_context
   void destroy();
 
   bool try_acquire_lock(MDL_request *mdl_request);
-  bool acquire_lock(MDL_request *mdl_request, ulong lock_wait_timeout);
-  bool acquire_locks(MDL_request_list *requests, ulong lock_wait_timeout);
+  bool acquire_lock(MDL_request *mdl_request, double lock_wait_timeout);
+  bool acquire_locks(MDL_request_list *requests, double lock_wait_timeout);
   bool upgrade_shared_lock(MDL_ticket *mdl_ticket,
                            enum_mdl_type new_type,
-                           ulong lock_wait_timeout);
+                           double lock_wait_timeout);
 
   bool clone_ticket(MDL_request *mdl_request);
 


More information about the commits mailing list