From: Jonas Oreland Date: August 17 2011 12:23pm Subject: bzr push into mysql-5.5-cluster branch (jonas.oreland:3436 to 3437) List-Archive: http://lists.mysql.com/commits/140673 Message-Id: <20110817122314.B9B919E8756@perch.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3437 Jonas Oreland 2011-08-17 ndb - The last crusade of the trailing share - remove dependency on LOCK_open in ndbcluster_create_binlog_setup, allow it to be used from anywhere. Use share->mutex to serialize the actual binlog setup. Patch for 5.5, plan to backport after test results modified: sql/ha_ndbcluster.cc sql/ha_ndbcluster_binlog.cc sql/ha_ndbcluster_binlog.h 3436 Jonas Oreland 2011-08-17 [merge] ndb - merge 71 into 5.5-cluster removed: mysql-test/suite/ndb/r/ndb_statistics.result mysql-test/suite/ndb/t/ndb_statistics.test added: mysql-test/suite/ndb/r/ndb_index_stat.result mysql-test/suite/ndb/r/ndb_statistics0.result mysql-test/suite/ndb/r/ndb_statistics1.result mysql-test/suite/ndb/t/ndb_index_stat.test mysql-test/suite/ndb/t/ndb_index_stat_enable.inc mysql-test/suite/ndb/t/ndb_statistics.inc mysql-test/suite/ndb/t/ndb_statistics0.test mysql-test/suite/ndb/t/ndb_statistics1.test modified: mysql-test/r/group_by.result mysql-test/suite/ndb/r/ndb_restore_misc.result mysql-test/suite/ndb/t/ndb_restore_misc.test mysql-test/t/group_by.test sql/ha_ndb_index_stat.cc sql/ha_ndb_index_stat.h sql/ha_ndbcluster.cc sql/ha_ndbcluster.h sql/sql_select.cc storage/ndb/clusterj/clusterj-core/src/main/java/com/mysql/clusterj/core/SessionFactoryImpl.java storage/ndb/clusterj/clusterj-jdbc/src/main/antlr3/com/mysql/clusterj/jdbc/antlr/MySQL51Lexer.g storage/ndb/clusterj/clusterj-openjpa/src/main/java/com/mysql/clusterj/openjpa/NdbOpenJPABrokerFactory.java storage/ndb/clusterj/clusterj-openjpa/src/main/java/com/mysql/clusterj/openjpa/NdbOpenJPAConfigurationImpl.java storage/ndb/clusterj/clusterj-openjpa/src/main/java/com/mysql/clusterj/openjpa/NdbOpenJPADomainFieldHandlerImpl.java storage/ndb/clusterj/clusterj-openjpa/src/main/java/com/mysql/clusterj/openjpa/NdbOpenJPADomainTypeHandlerImpl.java storage/ndb/clusterj/clusterj-openjpa/src/main/java/com/mysql/clusterj/openjpa/NdbOpenJPAStoreManager.java storage/ndb/include/ndb_constants.h storage/ndb/include/ndbapi/NdbIndexStat.hpp storage/ndb/include/util/NdbPack.hpp storage/ndb/src/common/util/NdbPack.cpp storage/ndb/src/kernel/blocks/dbtux/DbtuxNode.cpp storage/ndb/src/kernel/vm/ndbd_malloc_impl.cpp storage/ndb/src/kernel/vm/ndbd_malloc_impl.hpp storage/ndb/src/ndbapi/NdbIndexStat.cpp storage/ndb/src/ndbapi/NdbIndexStatImpl.cpp storage/ndb/src/ndbapi/NdbIndexStatImpl.hpp storage/ndb/src/ndbapi/NdbQueryOperation.cpp storage/ndb/src/ndbapi/NdbQueryOperationImpl.hpp storage/ndb/test/ndbapi/testIndexStat.cpp storage/ndb/tools/ndb_index_stat.cpp === modified file 'sql/ha_ndbcluster.cc' --- a/sql/ha_ndbcluster.cc 2011-08-17 10:36:01 +0000 +++ b/sql/ha_ndbcluster.cc 2011-08-17 12:22:49 +0000 @@ -9130,8 +9130,9 @@ int ha_ndbcluster::create(const char *na */ if ((my_errno= write_ndb_file(name))) DBUG_RETURN(my_errno); + ndbcluster_create_binlog_setup(thd, ndb, name, strlen(name), - m_dbname, m_tabname, FALSE); + m_dbname, m_tabname, form); DBUG_RETURN(my_errno); } @@ -10686,7 +10687,7 @@ int ha_ndbcluster::open(const char *name } Ndb* ndb= check_ndb_in_thd(thd); ndbcluster_create_binlog_setup(thd, ndb, name, strlen(name), - m_dbname, m_tabname, FALSE); + m_dbname, m_tabname, table); if ((m_share=get_share(name, table, FALSE)) == 0) { local_close(thd, FALSE); @@ -11402,7 +11403,7 @@ int ndbcluster_find_all_files(THD *thd) /* set up replication for this table */ ndbcluster_create_binlog_setup(thd, ndb, key, end-key, elmt.database, elmt.name, - TRUE); + 0); } } } @@ -11570,7 +11571,7 @@ ndbcluster_find_files(handlerton *hton, end= end1 + tablename_to_filename(file_name_str, end1, sizeof(name) - (end1 - name)); ndbcluster_create_binlog_setup(thd, ndb, name, end-name, - db, file_name_str, TRUE); + db, file_name_str, 0); } } @@ -13033,6 +13034,7 @@ NDB_SHARE *ndbcluster_get_share(const ch MEM_ROOT *old_root= *root_ptr; init_sql_alloc(&share->mem_root, 1024, 0); *root_ptr= &share->mem_root; // remember to reset before return + share->flags= 0; share->state= NSS_INITIAL; /* enough space for key, db, and table_name */ share->key= (char*) alloc_root(*root_ptr, 2 * (length + 1)); === modified file 'sql/ha_ndbcluster_binlog.cc' --- a/sql/ha_ndbcluster_binlog.cc 2011-07-08 15:05:28 +0000 +++ b/sql/ha_ndbcluster_binlog.cc 2011-08-17 12:22:49 +0000 @@ -4683,66 +4683,33 @@ int ndbcluster_create_binlog_setup(THD * uint key_len, const char *db, const char *table_name, - my_bool share_may_exist) + TABLE * table) { int do_event_op= ndb_binlog_running; DBUG_ENTER("ndbcluster_create_binlog_setup"); - DBUG_PRINT("enter",("key: %s key_len: %d %s.%s share_may_exist: %d", - key, key_len, db, table_name, share_may_exist)); + DBUG_PRINT("enter",("key: %s key_len: %d %s.%s", + key, key_len, db, table_name)); DBUG_ASSERT(! IS_NDB_BLOB_PREFIX(table_name)); DBUG_ASSERT(strlen(key) == key_len); pthread_mutex_lock(&ndbcluster_mutex); - - /* Handle any trailing share */ - NDB_SHARE *share= (NDB_SHARE*) my_hash_search(&ndbcluster_open_tables, - (const uchar*) key, key_len); - - if (share && share_may_exist) - { - if (get_binlog_nologging(share) || - share->op != 0 || - share->new_op != 0) - { - pthread_mutex_unlock(&ndbcluster_mutex); - DBUG_RETURN(0); // replication already setup, or should not - } - } - - if (share) + NDB_SHARE * share = get_share(key, table, TRUE, TRUE); + if (share == 0) { - if (share->op || share->new_op) - { - my_errno= HA_ERR_TABLE_EXIST; - pthread_mutex_unlock(&ndbcluster_mutex); - DBUG_RETURN(1); - } - if (!share_may_exist || share->connect_count != - g_ndb_cluster_connection->get_connect_count()) - { - handle_trailing_share(thd, share); - share= NULL; - } + /** + * Failed to create share + */ + pthread_mutex_unlock(&ndbcluster_mutex); + DBUG_RETURN(-1); } + pthread_mutex_unlock(&ndbcluster_mutex); - /* Create share which is needed to hold replication information */ - if (share) - { - /* ndb_share reference create */ - ++share->use_count; - DBUG_PRINT("NDB_SHARE", ("%s create use_count: %u", - share->key, share->use_count)); - } - /* ndb_share reference create */ - else if (!(share= get_share(key, 0, TRUE, TRUE))) - { - sql_print_error("NDB Binlog: " - "allocating table share for %s failed", key); - } - else + pthread_mutex_lock(&share->mutex); + if (get_binlog_nologging(share) || share->op != 0 || share->new_op != 0) { - DBUG_PRINT("NDB_SHARE", ("%s create use_count: %u", - share->key, share->use_count)); + pthread_mutex_unlock(&share->mutex); + free_share(&share); + DBUG_RETURN(0); // replication already setup, or should not } if (!ndb_schema_share && @@ -4757,10 +4724,9 @@ int ndbcluster_create_binlog_setup(THD * if (!do_event_op) { set_binlog_nologging(share); - pthread_mutex_unlock(&ndbcluster_mutex); + pthread_mutex_unlock(&share->mutex); DBUG_RETURN(0); } - pthread_mutex_unlock(&ndbcluster_mutex); while (share && !IS_TMP_PREFIX(table_name)) { @@ -4798,6 +4764,7 @@ int ndbcluster_create_binlog_setup(THD * { if (opt_ndb_extra_logging) sql_print_information("NDB Binlog: NOT logging %s", share->key); + pthread_mutex_unlock(&share->mutex); DBUG_RETURN(0); } @@ -4842,13 +4809,12 @@ int ndbcluster_create_binlog_setup(THD * /* a warning has been issued to the client */ break; } + pthread_mutex_unlock(&share->mutex); DBUG_RETURN(0); } - if (share) - { - free_share(&share); - } + pthread_mutex_unlock(&share->mutex); + free_share(&share); DBUG_RETURN(-1); } === modified file 'sql/ha_ndbcluster_binlog.h' --- a/sql/ha_ndbcluster_binlog.h 2011-07-05 12:46:07 +0000 +++ b/sql/ha_ndbcluster_binlog.h 2011-08-17 12:22:49 +0000 @@ -138,7 +138,7 @@ int ndbcluster_create_binlog_setup(THD * uint key_len, const char *db, const char *table_name, - my_bool share_may_exist); + TABLE * table); int ndbcluster_create_event(THD *thd, Ndb *ndb, const NDBTAB *table, const char *event_name, NDB_SHARE *share, int push_warning= 0); No bundle (reason: useless for push emails).