List:Commits« Previous MessageNext Message »
From:Magnus Blåudd Date:March 8 2011 10:29am
Subject:bzr commit into mysql-5.5-cluster branch (magnus.blaudd:3222)
View as plain text  
#At file:///C:/mysql/5.5-cluster/ based on revid:magnus.blaudd@stripped

 3222 Magnus Blåudd	2011-03-08
      ndb
       - move Thd_ndb into ndb_thd_ndb.h and add new ndb_thd_ndb.cc file for Thd_ndb
        implementation(not moving everything related to Thd_ndb since it still has many dependencies)
       - move Thd_ndb seize and release functions from ha_ndbcluster to Thd_ndb class

    added:
      sql/ndb_thd_ndb.cc
      sql/ndb_thd_ndb.h
    modified:
      sql/ha_ndbcluster.cc
      sql/ha_ndbcluster.h
      sql/ha_ndbcluster_binlog.cc
      storage/ndb/CMakeLists.txt
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2011-03-04 15:16:56 +0000
+++ b/sql/ha_ndbcluster.cc	2011-03-08 10:29:13 +0000
@@ -245,14 +245,6 @@ static MYSQL_THDVAR_UINT(
   UINT_MAX,                          /* max */
   0                                  /* block */
 );
-  
-
-/*
-  Default value for max number of transactions createable against NDB from
-  the handler. Should really be 2 but there is a transaction to much allocated
-  when lock table is used, and one extra to used for global schema lock.
-*/
-static const int max_transactions= 4;
 
 static int ndbcluster_end(handlerton *hton, ha_panic_function flag);
 static bool ndbcluster_show_status(handlerton *hton, THD*,
@@ -1066,13 +1058,6 @@ Thd_ndb::~Thd_ndb()
   free_root(&m_batch_mem_root, MYF(0));
 }
 
-void
-Thd_ndb::init_open_tables()
-{
-  count= 0;
-  m_error= FALSE;
-  my_hash_reset(&open_tables);
-}
 
 inline
 Ndb *ha_ndbcluster::get_ndb(THD *thd)
@@ -9839,97 +9824,6 @@ int ha_ndbcluster::close(void)
 
 
 /**
-  @todo
-  - Alt.1 If init fails because to many allocated Ndb 
-  wait on condition for a Ndb object to be released.
-  - Alt.2 Seize/release from pool, wait until next release 
-*/
-Thd_ndb* ha_ndbcluster::seize_thd_ndb()
-{
-  Thd_ndb *thd_ndb;
-  DBUG_ENTER("seize_thd_ndb");
-
-  thd_ndb= new Thd_ndb();
-  if (thd_ndb == NULL)
-  {
-    my_errno= HA_ERR_OUT_OF_MEM;
-    return NULL;
-  }
-  if (thd_ndb->ndb->init(max_transactions) != 0)
-  {
-    ERR_PRINT(thd_ndb->ndb->getNdbError());
-    /*
-      TODO 
-      Alt.1 If init fails because to many allocated Ndb 
-      wait on condition for a Ndb object to be released.
-      Alt.2 Seize/release from pool, wait until next release 
-    */
-    delete thd_ndb;
-    thd_ndb= NULL;
-  }
-  DBUG_RETURN(thd_ndb);
-}
-
-
-void ha_ndbcluster::release_thd_ndb(Thd_ndb* thd_ndb)
-{
-  DBUG_ENTER("release_thd_ndb");
-  delete thd_ndb;
-  DBUG_VOID_RETURN;
-}
-
-
-bool Thd_ndb::recycle_ndb(THD* thd)
-{
-  DBUG_ENTER("recycle_ndb");
-  DBUG_PRINT("enter", ("ndb: 0x%lx", (long)ndb));
-
-  DBUG_ASSERT(global_schema_lock_trans == NULL);
-  DBUG_ASSERT(trans == NULL);
-
-  delete ndb;
-  if ((ndb= new Ndb(connection, "")) == NULL)
-  {
-    DBUG_PRINT("error",("failed to allocate Ndb object"));
-    DBUG_RETURN(false);
-  }
-
-  if (ndb->init(max_transactions) != 0)
-  {
-    delete ndb;
-    ndb= NULL;
-    DBUG_PRINT("error", ("Ndb::init failed, %d  message: %s",
-                         ndb->getNdbError().code,
-                         ndb->getNdbError().message));
-    DBUG_RETURN(false);
-  }
-
-  DBUG_RETURN(true);
-}
-
-
-bool
-Thd_ndb::valid_ndb(void)
-{
-  // The ndb object should be valid as long as a
-  // global schema lock transaction is ongoing
-  if (global_schema_lock_trans)
-    return true;
-
-  // The ndb object should be valid as long as a
-  // transaction is ongoing
-  if (trans)
-    return true;
-
-  if (unlikely(m_connect_count != connection->get_connect_count()))
-    return false;
-
-  return true;
-}
-
-
-
-/**
   If this thread already has a Thd_ndb object allocated
   in current THD, reuse it. Otherwise
   seize a Thd_ndb object, assign it to current THD and use it.
@@ -9941,7 +9835,7 @@ Ndb* check_ndb_in_thd(THD* thd, bool val
   Thd_ndb *thd_ndb= get_thd_ndb(thd);
   if (!thd_ndb)
   {
-    if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb()))
+    if (!(thd_ndb= Thd_ndb::seize()))
       return NULL;
     set_thd_ndb(thd, thd_ndb);
   }
@@ -9978,7 +9872,7 @@ static int ndbcluster_close_connection(h
   DBUG_ENTER("ndbcluster_close_connection");
   if (thd_ndb)
   {
-    ha_ndbcluster::release_thd_ndb(thd_ndb);
+    Thd_ndb::release(thd_ndb);
     set_thd_ndb(thd, NULL); // not strictly required but does not hurt either
   }
   DBUG_RETURN(0);
@@ -13039,7 +12933,7 @@ pthread_handler_t ndb_util_thread_func(v
   pthread_mutex_unlock(&LOCK_ndb_util_thread);
 
   /* Get thd_ndb for this thread */
-  if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb()))
+  if (!(thd_ndb= Thd_ndb::seize()))
   {
     sql_print_error("Could not allocate Thd_ndb object");
     pthread_mutex_lock(&LOCK_ndb_util_thread);
@@ -13223,7 +13117,7 @@ ndb_util_thread_fail:
     delete [] share_list;
   if (thd_ndb)
   {
-    ha_ndbcluster::release_thd_ndb(thd_ndb);
+    Thd_ndb::release(thd_ndb);
     set_thd_ndb(thd, NULL);
   }
   thd->cleanup();

=== modified file 'sql/ha_ndbcluster.h'
--- a/sql/ha_ndbcluster.h	2011-03-08 09:04:24 +0000
+++ b/sql/ha_ndbcluster.h	2011-03-08 10:29:13 +0000
@@ -184,97 +184,13 @@ typedef enum ndb_query_state_bits {
   NDB_QUERY_MULTI_READ_RANGE = 1
 } NDB_QUERY_STATE_BITS;
 
-/*
-  Place holder for ha_ndbcluster thread specific data
-*/
-
-enum THD_NDB_OPTIONS
-{
-  TNO_NO_LOG_SCHEMA_OP=  1 << 0,
-  /*
-    In participating mysqld, do not try to acquire global schema
-    lock, as one other mysqld already has the lock.
-  */
-  TNO_NO_LOCK_SCHEMA_OP= 1 << 1
-  /*
-    Skip drop of ndb table in delete_table.  Used when calling
-    mysql_rm_table_part2 in "show tables", as we do not want to
-    remove ndb tables "by mistake".  The table should not exist
-    in ndb in the first place.
-  */
-  ,TNO_NO_NDB_DROP_TABLE=    1 << 2
-};
-
-enum THD_NDB_TRANS_OPTIONS
-{
-  TNTO_INJECTED_APPLY_STATUS= 1 << 0
-  ,TNTO_NO_LOGGING=           1 << 1
-  ,TNTO_TRANSACTIONS_OFF=     1 << 2
-};
-
 struct Ndb_local_table_statistics {
   int no_uncommitted_rows_count;
   ulong last_count;
   ha_rows records;
 };
 
-class Thd_ndb 
-{
- public:
-  Thd_ndb();
-  ~Thd_ndb();
-
-  void init_open_tables();
-
-  Ndb_cluster_connection *connection;
-  Ndb *ndb;
-  /* this */
-  class ha_ndbcluster *m_handler;
-  ulong count;
-  uint lock_count;
-  uint start_stmt_count;
-  uint save_point_count;
-  NdbTransaction *trans;
-  bool m_error;
-  bool m_slow_path;
-  bool m_force_send;
-
-  uint32 options;
-  uint32 trans_options;
-  List<NDB_SHARE> changed_tables;
-  uint query_state;
-  HASH open_tables;
-  /*
-    This is a memroot used to buffer rows for batched execution.
-    It is reset after every execute().
-  */
-  MEM_ROOT m_batch_mem_root;
-  /*
-    Estimated pending batched execution bytes, once this is > BATCH_FLUSH_SIZE
-    we execute() to flush the rows buffered in m_batch_mem_root.
-  */
-  uint m_unsent_bytes;
-  uint m_batch_size;
-
-  uint m_execute_count;
-  uint m_max_violation_count;
-  uint m_old_violation_count;
-  uint m_conflict_fn_usage_count;
-
-  uint m_scan_count;
-  uint m_pruned_scan_count;
-  
-  uint m_transaction_no_hint_count[MAX_NDB_NODES];
-  uint m_transaction_hint_count[MAX_NDB_NODES];
-
-  NdbTransaction *global_schema_lock_trans;
-  uint global_schema_lock_count;
-  uint global_schema_lock_error;
-
-  unsigned m_connect_count;
-  bool valid_ndb(void);
-  bool recycle_ndb(THD* thd);
-};
+#include "ndb_thd_ndb.h"
 
 int ndbcluster_commit(handlerton *hton, THD *thd, bool all);
 class ha_ndbcluster: public handler
@@ -404,9 +320,6 @@ class ha_ndbcluster: public handler
   int ndb_update_row(const uchar *old_data, uchar *new_data,
                      int is_bulk_update);
 
-  static Thd_ndb* seize_thd_ndb();
-  static void release_thd_ndb(Thd_ndb* thd_ndb);
- 
 static void set_dbname(const char *pathname, char *dbname);
 static void set_tabname(const char *pathname, char *tabname);
 

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2011-03-04 10:35:37 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2011-03-08 10:29:13 +0000
@@ -1924,7 +1924,7 @@ int ndbcluster_log_schema_op(THD *thd,
   Thd_ndb *thd_ndb= get_thd_ndb(thd);
   if (!thd_ndb)
   {
-    if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb()))
+    if (!(thd_ndb= Thd_ndb::seize()))
     {
       sql_print_error("Could not allocate Thd_ndb object");
       DBUG_RETURN(1);
@@ -5887,7 +5887,7 @@ restart_cluster_failure:
   int have_injector_mutex_lock= 0;
   do_ndbcluster_binlog_close_connection= BCCC_exit;
 
-  if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb()))
+  if (!(thd_ndb= Thd_ndb::seize()))
   {
     sql_print_error("Could not allocate Thd_ndb object");
     ndb_binlog_thread_running= -1;
@@ -6733,7 +6733,7 @@ restart_cluster_failure:
 
   if (thd_ndb)
   {
-    ha_ndbcluster::release_thd_ndb(thd_ndb);
+    Thd_ndb::release(thd_ndb);
     set_thd_ndb(thd, NULL);
     thd_ndb= NULL;
   }

=== added file 'sql/ndb_thd_ndb.cc'
--- a/sql/ndb_thd_ndb.cc	1970-01-01 00:00:00 +0000
+++ b/sql/ndb_thd_ndb.cc	2011-03-08 10:29:13 +0000
@@ -0,0 +1,114 @@
+/*
+   Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+*/
+
+#include "ndb_thd_ndb.h"
+
+/*
+  Default value for max number of transactions createable against NDB from
+  the handler. Should really be 2 but there is a transaction to much allocated
+  when lock table is used, and one extra to used for global schema lock.
+*/
+static const int MAX_TRANSACTIONS= 4;
+
+
+Thd_ndb*
+Thd_ndb::seize(void)
+{
+  DBUG_ENTER("seize_thd_ndb");
+
+  Thd_ndb* thd_ndb= new Thd_ndb();
+  if (thd_ndb == NULL)
+    return NULL;
+
+  if (thd_ndb->ndb->init(MAX_TRANSACTIONS) != 0)
+  {
+    DBUG_PRINT("error", ("Ndb::init failed, eror: %d  message: %s",
+                         thd_ndb->ndb->getNdbError().code,
+                         thd_ndb->ndb->getNdbError().message));
+    
+    delete thd_ndb;
+    thd_ndb= NULL;
+  }
+  DBUG_RETURN(thd_ndb);
+}
+
+
+void
+Thd_ndb::release(Thd_ndb* thd_ndb)
+{
+  DBUG_ENTER("release_thd_ndb");
+  delete thd_ndb;
+  DBUG_VOID_RETURN;
+}
+
+
+bool
+Thd_ndb::recycle_ndb(THD* thd)
+{
+  DBUG_ENTER("recycle_ndb");
+  DBUG_PRINT("enter", ("ndb: 0x%lx", (long)ndb));
+
+  DBUG_ASSERT(global_schema_lock_trans == NULL);
+  DBUG_ASSERT(trans == NULL);
+
+  delete ndb;
+  if ((ndb= new Ndb(connection, "")) == NULL)
+  {
+    DBUG_PRINT("error",("failed to allocate Ndb object"));
+    DBUG_RETURN(false);
+  }
+
+  if (ndb->init(MAX_TRANSACTIONS) != 0)
+  {
+    delete ndb;
+    ndb= NULL;
+    DBUG_PRINT("error", ("Ndb::init failed, %d  message: %s",
+                         ndb->getNdbError().code,
+                         ndb->getNdbError().message));
+    DBUG_RETURN(false);
+  }
+  DBUG_RETURN(true);
+}
+
+
+bool
+Thd_ndb::valid_ndb(void)
+{
+  // The ndb object should be valid as long as a
+  // global schema lock transaction is ongoing
+  if (global_schema_lock_trans)
+    return true;
+
+  // The ndb object should be valid as long as a
+  // transaction is ongoing
+  if (trans)
+    return true;
+
+  if (unlikely(m_connect_count != connection->get_connect_count()))
+    return false;
+
+  return true;
+}
+
+
+void
+Thd_ndb::init_open_tables()
+{
+  count= 0;
+  m_error= FALSE;
+  my_hash_reset(&open_tables);
+}

=== added file 'sql/ndb_thd_ndb.h'
--- a/sql/ndb_thd_ndb.h	1970-01-01 00:00:00 +0000
+++ b/sql/ndb_thd_ndb.h	2011-03-08 10:29:13 +0000
@@ -0,0 +1,117 @@
+/*
+   Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+*/
+
+#ifndef NDB_THD_NDB_H
+#define NDB_THD_NDB_H
+
+#include <my_global.h>
+#include <my_base.h>          // ha_rows
+#include <sql_list.h>         // List<>
+#include <hash.h>             // HASH
+
+#include "ndb_share.h"
+
+#include <kernel/ndb_limits.h> // MAX_NDB_NODES
+
+/*
+  Place holder for ha_ndbcluster thread specific data
+*/
+
+enum THD_NDB_OPTIONS
+{
+  TNO_NO_LOG_SCHEMA_OP=  1 << 0,
+  /*
+    In participating mysqld, do not try to acquire global schema
+    lock, as one other mysqld already has the lock.
+  */
+  TNO_NO_LOCK_SCHEMA_OP= 1 << 1
+  /*
+    Skip drop of ndb table in delete_table.  Used when calling
+    mysql_rm_table_part2 in "show tables", as we do not want to
+    remove ndb tables "by mistake".  The table should not exist
+    in ndb in the first place.
+  */
+  ,TNO_NO_NDB_DROP_TABLE=    1 << 2
+};
+
+enum THD_NDB_TRANS_OPTIONS
+{
+  TNTO_INJECTED_APPLY_STATUS= 1 << 0
+  ,TNTO_NO_LOGGING=           1 << 1
+  ,TNTO_TRANSACTIONS_OFF=     1 << 2
+};
+
+class Thd_ndb 
+{
+  Thd_ndb();
+  ~Thd_ndb();
+public:
+  static Thd_ndb* seize(void);
+  static void release(Thd_ndb* thd_ndb);
+
+  void init_open_tables();
+
+  class Ndb_cluster_connection *connection;
+  class Ndb *ndb;
+  class ha_ndbcluster *m_handler;
+  ulong count;
+  uint lock_count;
+  uint start_stmt_count;
+  uint save_point_count;
+  class NdbTransaction *trans;
+  bool m_error;
+  bool m_slow_path;
+  bool m_force_send;
+
+  uint32 options;
+  uint32 trans_options;
+  List<NDB_SHARE> changed_tables;
+  uint query_state;
+  HASH open_tables;
+  /*
+    This is a memroot used to buffer rows for batched execution.
+    It is reset after every execute().
+  */
+  MEM_ROOT m_batch_mem_root;
+  /*
+    Estimated pending batched execution bytes, once this is > BATCH_FLUSH_SIZE
+    we execute() to flush the rows buffered in m_batch_mem_root.
+  */
+  uint m_unsent_bytes;
+  uint m_batch_size;
+
+  uint m_execute_count;
+  uint m_max_violation_count;
+  uint m_old_violation_count;
+  uint m_conflict_fn_usage_count;
+
+  uint m_scan_count;
+  uint m_pruned_scan_count;
+  
+  uint m_transaction_no_hint_count[MAX_NDB_NODES];
+  uint m_transaction_hint_count[MAX_NDB_NODES];
+
+  NdbTransaction *global_schema_lock_trans;
+  uint global_schema_lock_count;
+  uint global_schema_lock_error;
+
+  unsigned m_connect_count;
+  bool valid_ndb(void);
+  bool recycle_ndb(THD* thd);
+};
+
+#endif

=== modified file 'storage/ndb/CMakeLists.txt'
--- a/storage/ndb/CMakeLists.txt	2011-03-08 09:04:24 +0000
+++ b/storage/ndb/CMakeLists.txt	2011-03-08 10:29:13 +0000
@@ -104,6 +104,7 @@ SET(NDBCLUSTER_SOURCES
   ../../sql/ha_ndbinfo.cc
   ../../sql/ndb_local_connection.cc
   ../../sql/ndb_share.cc
+  ../../sql/ndb_thd_ndb.cc
 )
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/storage/ndb/include)
 

Attachment: [text/bzr-bundle] bzr/magnus.blaudd@sun.com-20110308102913-tt61npplayq67pku.bundle
Thread
bzr commit into mysql-5.5-cluster branch (magnus.blaudd:3222) Magnus Blåudd8 Mar