[Commits] 8c84489: Make memory counting system happy

Oleksandr Byelkin sanja at mariadb.com
Thu May 26 19:44:11 EEST 2016


revision-id: 8c84489bdb6330384ab20e562c803fa0e0f8ac53 (mariadb-10.2.0-46-g8c84489)
parent(s): 2722af43559d7d6b31dd7686dc92c80a8c23168e
committer: Oleksandr Byelkin
timestamp: 2016-05-26 18:44:11 +0200
message:

Make memory counting system happy

---
 sql/session_tracker.cc | 29 +++++++++++++++++++----------
 sql/session_tracker.h  | 13 ++++++++++++-
 sql/sql_class.cc       |  4 ++++
 3 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/sql/session_tracker.cc b/sql/session_tracker.cc
index 7d3b90e..36a1381 100644
--- a/sql/session_tracker.cc
+++ b/sql/session_tracker.cc
@@ -993,16 +993,8 @@ bool Session_state_change_tracker::is_state_changed(THD *)
 
 Session_tracker::Session_tracker()
 {
-  m_trackers[SESSION_SYSVARS_TRACKER]=
-    new (std::nothrow) Session_sysvars_tracker();
-  m_trackers[CURRENT_SCHEMA_TRACKER]=
-    new (std::nothrow) Current_schema_tracker;
-  m_trackers[SESSION_STATE_CHANGE_TRACKER]=
-    new (std::nothrow) Session_state_change_tracker;
-  m_trackers[SESSION_GTIDS_TRACKER]=
-    new (std::nothrow) Not_implemented_tracker;
-  m_trackers[TRANSACTION_INFO_TRACKER]=
-    new (std::nothrow) Not_implemented_tracker;
+  for (int i= 0; i <= SESSION_TRACKER_END; i ++)
+    m_trackers[i]= NULL;
 }
 
 
@@ -1016,6 +1008,23 @@ Session_tracker::Session_tracker()
 
 void Session_tracker::enable(THD *thd)
 {
+  /*
+    Originally and correctly this allocation was in the constructor and
+    deallocation in the destructor, but in this case memory counting
+    system works incorrectly (for example in INSERT DELAYED thread)
+  */
+  deinit();
+  m_trackers[SESSION_SYSVARS_TRACKER]=
+    new (std::nothrow) Session_sysvars_tracker();
+  m_trackers[CURRENT_SCHEMA_TRACKER]=
+    new (std::nothrow) Current_schema_tracker;
+  m_trackers[SESSION_STATE_CHANGE_TRACKER]=
+    new (std::nothrow) Session_state_change_tracker;
+  m_trackers[SESSION_GTIDS_TRACKER]=
+    new (std::nothrow) Not_implemented_tracker;
+  m_trackers[TRANSACTION_INFO_TRACKER]=
+    new (std::nothrow) Not_implemented_tracker;
+
   for (int i= 0; i <= SESSION_TRACKER_END; i ++)
     m_trackers[i]->enable(thd);
 }
diff --git a/sql/session_tracker.h b/sql/session_tracker.h
index f6a3f89..7025c34 100644
--- a/sql/session_tracker.h
+++ b/sql/session_tracker.h
@@ -140,9 +140,20 @@ class Session_tracker
   Session_tracker();
   ~Session_tracker()
   {
+    deinit();
+  }
+
+  /* trick to make happy memory accounting system */
+  void deinit()
+  {
     for (int i= 0; i <= SESSION_TRACKER_END; i ++)
-      delete m_trackers[i];
+    {
+      if (m_trackers[i])
+        delete m_trackers[i];
+      m_trackers[i]= NULL;
+    }
   }
+
   void enable(THD *thd);
   bool server_boot_verify(const CHARSET_INFO *char_set);
 
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 0b6388f..ff7e133 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -1710,6 +1710,10 @@ THD::~THD()
     lf_hash_put_pins(xid_hash_pins);
   /* Ensure everything is freed */
   status_var.local_memory_used-= sizeof(THD);
+
+  /* trick to make happy memory accounting system */
+  session_tracker.deinit();
+
   if (status_var.local_memory_used != 0)
   {
     DBUG_PRINT("error", ("memory_used: %lld", status_var.local_memory_used));


More information about the commits mailing list