bizstation / transactd

The high-speed and advanced NoSQL interface plugin for MySQL / MariaDB.
GNU General Public License v2.0
18 stars 1 forks source link

Snapshot can use read-only transaction optimization of InnoDB after 5.6 #17

Closed kinoyasu closed 9 years ago

kinoyasu commented 9 years ago

If the transactd doesn't set session variables of THD by users, snapshot (readonly transaction?) of the transactd can use read only transacion explicitly. InnoDB can optimize (skip useless processes for read-only transaction) for the snapshot.

--- transactd_orig_2.2.0/source/bzs/db/engine/mysql/database.cpp        2015-01-18 00:05:52.000000000 +0900
+++ mysql-5.6.23_td_test/plugin/transactd/source/bzs/db/engine/mysql/database.cpp       2015-02-18 19:25:05.133893783 +0900
@@ -304,14 +304,15 @@ void database::use() const

 void database::prebuildIsoratinMode()
 {
-    cp_thd_set_read_only(m_thd);
     if (m_inTransaction)
     {
+       cp_thd_set_read_only(m_thd, false);
         m_thd->tx_isolation = m_iso;
         m_thd->in_lock_tables = 1;// WITH LOCK
     }
     else if(m_inSnapshot)
     {
+       cp_thd_set_read_only(m_thd, true);
         if (m_iso)
         {
             m_thd->in_lock_tables = 1;// WITH LOCK
@@ -320,7 +321,10 @@ void database::prebuildIsoratinMode()
             m_thd->tx_isolation = ISO_REPEATABLE_READ;
     }
     else
+    {
+        cp_thd_set_read_only(m_thd, false);
         m_thd->tx_isolation = (enum_tx_isolation)m_thd->variables.tx_isolation;
+    }
 }

 void database::prebuildExclusieLockMode(table* tb)
--- transactd_orig_2.2.0/source/bzs/db/engine/mysql/mysqlInternal.h     2015-01-13 20:42:52.000000000 +0900
+++ mysql-5.6.23_td_test/plugin/transactd/source/bzs/db/engine/mysql/mysqlInternal.h    2015-02-18 19:24:17.364897009 +0900
@@ -173,7 +173,7 @@ inline void cp_restore_globals(THD* thd)
     my_pthread_setspecific_ptr(THR_MALLOC, 0);
 }

-inline void cp_thd_set_read_only(THD* thd)
+inline void cp_thd_set_read_only(THD* thd, bool read_only)
 {
     ;
 }
@@ -216,14 +216,14 @@ inline void cp_restore_globals(THD* thd)
     thd->restore_globals();
 }

-inline void cp_thd_set_read_only(THD* thd)
+inline void cp_thd_set_read_only(THD* thd, bool read_only)
 {
-    thd->tx_read_only = (thd->variables.tx_read_only != 0);
+    thd->tx_read_only = read_only;
 }

 inline bool cp_thd_get_read_only(THD* thd)
 {
-    return (thd->variables.tx_read_only != 0);
+    return (thd->tx_read_only);
 }

 inline bool cp_open_table(THD* thd, TABLE_LIST* tables,
bizstation commented 9 years ago

We have confirmed that a part of current source code is useless because thd->variables.tx_read_only does not change. I fixed it almost according to your patch.

Thank you for your advice.