ndb: release LOCK_open during mysqld schema sync and mysqld sync with binlog...

ndb: release LOCK_open during mysqld schema sync and mysqld sync with binlog (create/drop/rename table)
+ increase timeout for sync... which now should never occur
parent faff1b37
...@@ -4649,7 +4649,7 @@ int ha_ndbcluster::create(const char *name, ...@@ -4649,7 +4649,7 @@ int ha_ndbcluster::create(const char *name,
share->db, share->table_name, share->db, share->table_name,
m_table->getObjectId(), m_table->getObjectId(),
m_table->getObjectVersion(), m_table->getObjectVersion(),
SOT_CREATE_TABLE); SOT_CREATE_TABLE, 0, 0, 1);
break; break;
} }
} }
...@@ -5031,7 +5031,7 @@ int ha_ndbcluster::rename_table(const char *from, const char *to) ...@@ -5031,7 +5031,7 @@ int ha_ndbcluster::rename_table(const char *from, const char *to)
old_dbname, m_tabname, old_dbname, m_tabname,
ndb_table_id, ndb_table_version, ndb_table_id, ndb_table_version,
SOT_RENAME_TABLE, SOT_RENAME_TABLE,
m_dbname, new_tabname); m_dbname, new_tabname, 1);
} }
if (share) if (share)
free_share(&share); free_share(&share);
...@@ -5155,7 +5155,7 @@ ha_ndbcluster::delete_table(ha_ndbcluster *h, Ndb *ndb, ...@@ -5155,7 +5155,7 @@ ha_ndbcluster::delete_table(ha_ndbcluster *h, Ndb *ndb,
current_thd->query, current_thd->query_length, current_thd->query, current_thd->query_length,
share->db, share->table_name, share->db, share->table_name,
ndb_table_id, ndb_table_version, ndb_table_id, ndb_table_version,
SOT_DROP_TABLE); SOT_DROP_TABLE, 0, 0, 1);
} }
else if (table_dropped && share && share->op) /* ndbcluster_log_schema_op else if (table_dropped && share && share->op) /* ndbcluster_log_schema_op
will do a force GCP */ will do a force GCP */
...@@ -5752,7 +5752,7 @@ static void ndbcluster_drop_database(char *path) ...@@ -5752,7 +5752,7 @@ static void ndbcluster_drop_database(char *path)
ha_ndbcluster::set_dbname(path, db); ha_ndbcluster::set_dbname(path, db);
ndbcluster_log_schema_op(current_thd, 0, ndbcluster_log_schema_op(current_thd, 0,
current_thd->query, current_thd->query_length, current_thd->query, current_thd->query_length,
db, "", 0, 0, SOT_DROP_DB); db, "", 0, 0, SOT_DROP_DB, 0, 0, 0);
#endif #endif
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -9941,13 +9941,13 @@ int ndbcluster_alter_tablespace(THD* thd, st_alter_tablespace *info) ...@@ -9941,13 +9941,13 @@ int ndbcluster_alter_tablespace(THD* thd, st_alter_tablespace *info)
thd->query, thd->query_length, thd->query, thd->query_length,
"", info->tablespace_name, "", info->tablespace_name,
0, 0, 0, 0,
SOT_TABLESPACE); SOT_TABLESPACE, 0, 0, 0);
else else
ndbcluster_log_schema_op(thd, 0, ndbcluster_log_schema_op(thd, 0,
thd->query, thd->query_length, thd->query, thd->query_length,
"", info->logfile_group_name, "", info->logfile_group_name,
0, 0, 0, 0,
SOT_LOGFILE_GROUP); SOT_LOGFILE_GROUP, 0, 0, 0);
#endif #endif
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
......
...@@ -39,6 +39,12 @@ ...@@ -39,6 +39,12 @@
#define NDB_APPLY_TABLE_FILE "./" NDB_REP_DB "/" NDB_APPLY_TABLE #define NDB_APPLY_TABLE_FILE "./" NDB_REP_DB "/" NDB_APPLY_TABLE
#define NDB_SCHEMA_TABLE_FILE "./" NDB_REP_DB "/" NDB_SCHEMA_TABLE #define NDB_SCHEMA_TABLE_FILE "./" NDB_REP_DB "/" NDB_SCHEMA_TABLE
/*
Timeout for syncing schema events between
mysql servers, and between mysql server and the binlog
*/
const int opt_ndb_sync_timeout= 120;
/* /*
Flag showing if the ndb injector thread is running, if so == 1 Flag showing if the ndb injector thread is running, if so == 1
-1 if it was started but later stopped for some reason -1 if it was started but later stopped for some reason
...@@ -498,6 +504,7 @@ ndbcluster_binlog_log_query(THD *thd, enum_binlog_command binlog_command, ...@@ -498,6 +504,7 @@ ndbcluster_binlog_log_query(THD *thd, enum_binlog_command binlog_command,
{ {
case LOGCOM_CREATE_TABLE: case LOGCOM_CREATE_TABLE:
type= SOT_CREATE_TABLE; type= SOT_CREATE_TABLE;
DBUG_ASSERT(FALSE);
break; break;
case LOGCOM_ALTER_TABLE: case LOGCOM_ALTER_TABLE:
type= SOT_ALTER_TABLE; type= SOT_ALTER_TABLE;
...@@ -505,9 +512,11 @@ ndbcluster_binlog_log_query(THD *thd, enum_binlog_command binlog_command, ...@@ -505,9 +512,11 @@ ndbcluster_binlog_log_query(THD *thd, enum_binlog_command binlog_command,
break; break;
case LOGCOM_RENAME_TABLE: case LOGCOM_RENAME_TABLE:
type= SOT_RENAME_TABLE; type= SOT_RENAME_TABLE;
DBUG_ASSERT(FALSE);
break; break;
case LOGCOM_DROP_TABLE: case LOGCOM_DROP_TABLE:
type= SOT_DROP_TABLE; type= SOT_DROP_TABLE;
DBUG_ASSERT(FALSE);
break; break;
case LOGCOM_CREATE_DB: case LOGCOM_CREATE_DB:
type= SOT_CREATE_DB; type= SOT_CREATE_DB;
...@@ -519,12 +528,14 @@ ndbcluster_binlog_log_query(THD *thd, enum_binlog_command binlog_command, ...@@ -519,12 +528,14 @@ ndbcluster_binlog_log_query(THD *thd, enum_binlog_command binlog_command,
break; break;
case LOGCOM_DROP_DB: case LOGCOM_DROP_DB:
type= SOT_DROP_DB; type= SOT_DROP_DB;
DBUG_ASSERT(FALSE);
break; break;
} }
if (log) if (log)
{ {
ndbcluster_log_schema_op(thd, 0, query, query_length, ndbcluster_log_schema_op(thd, 0, query, query_length,
db, table_name, 0, 0, type); db, table_name, 0, 0, type,
0, 0, 0);
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -995,7 +1006,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, ...@@ -995,7 +1006,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share,
uint32 ndb_table_id, uint32 ndb_table_id,
uint32 ndb_table_version, uint32 ndb_table_version,
enum SCHEMA_OP_TYPE type, enum SCHEMA_OP_TYPE type,
const char *new_db, const char *new_table_name) const char *new_db, const char *new_table_name,
int have_lock_open)
{ {
DBUG_ENTER("ndbcluster_log_schema_op"); DBUG_ENTER("ndbcluster_log_schema_op");
Thd_ndb *thd_ndb= get_thd_ndb(thd); Thd_ndb *thd_ndb= get_thd_ndb(thd);
...@@ -1254,8 +1266,13 @@ end: ...@@ -1254,8 +1266,13 @@ end:
if (ndb_error == 0 && if (ndb_error == 0 &&
!bitmap_is_clear_all(&schema_subscribers)) !bitmap_is_clear_all(&schema_subscribers))
{ {
int max_timeout= 10; int max_timeout= opt_ndb_sync_timeout;
(void) pthread_mutex_lock(&ndb_schema_object->mutex); (void) pthread_mutex_lock(&ndb_schema_object->mutex);
if (have_lock_open)
{
safe_mutex_assert_owner(&LOCK_open);
(void) pthread_mutex_unlock(&LOCK_open);
}
while (1) while (1)
{ {
struct timespec abstime; struct timespec abstime;
...@@ -1300,6 +1317,10 @@ end: ...@@ -1300,6 +1317,10 @@ end:
"distributing", ndb_schema_object->key); "distributing", ndb_schema_object->key);
} }
} }
if (have_lock_open)
{
(void) pthread_mutex_lock(&LOCK_open);
}
(void) pthread_mutex_unlock(&ndb_schema_object->mutex); (void) pthread_mutex_unlock(&ndb_schema_object->mutex);
} }
...@@ -2698,6 +2719,7 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, ...@@ -2698,6 +2719,7 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name,
NDB_SHARE *share, const char *type_str) NDB_SHARE *share, const char *type_str)
{ {
DBUG_ENTER("ndbcluster_handle_drop_table"); DBUG_ENTER("ndbcluster_handle_drop_table");
THD *thd= current_thd;
NDBDICT *dict= ndb->getDictionary(); NDBDICT *dict= ndb->getDictionary();
if (event_name && dict->dropEvent(event_name)) if (event_name && dict->dropEvent(event_name))
...@@ -2743,10 +2765,14 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, ...@@ -2743,10 +2765,14 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name,
these out of order, thus we are keeping the SYNC_DROP_ defined these out of order, thus we are keeping the SYNC_DROP_ defined
for now. for now.
*/ */
const char *save_proc_info= thd->proc_info;
#define SYNC_DROP_ #define SYNC_DROP_
#ifdef SYNC_DROP_ #ifdef SYNC_DROP_
thd->proc_info= "Syncing ndb table schema operation and binlog";
(void) pthread_mutex_lock(&share->mutex); (void) pthread_mutex_lock(&share->mutex);
int max_timeout= 10; safe_mutex_assert_owner(&LOCK_open);
(void) pthread_mutex_unlock(&LOCK_open);
int max_timeout= opt_ndb_sync_timeout;
while (share->op) while (share->op)
{ {
struct timespec abstime; struct timespec abstime;
...@@ -2770,6 +2796,7 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, ...@@ -2770,6 +2796,7 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name,
type_str, share->key); type_str, share->key);
} }
} }
(void) pthread_mutex_lock(&LOCK_open);
(void) pthread_mutex_unlock(&share->mutex); (void) pthread_mutex_unlock(&share->mutex);
#else #else
(void) pthread_mutex_lock(&share->mutex); (void) pthread_mutex_lock(&share->mutex);
...@@ -2777,6 +2804,7 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, ...@@ -2777,6 +2804,7 @@ ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name,
share->op= 0; share->op= 0;
(void) pthread_mutex_unlock(&share->mutex); (void) pthread_mutex_unlock(&share->mutex);
#endif #endif
thd->proc_info= save_proc_info;
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
...@@ -138,8 +138,9 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share, ...@@ -138,8 +138,9 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share,
uint32 ndb_table_id, uint32 ndb_table_id,
uint32 ndb_table_version, uint32 ndb_table_version,
enum SCHEMA_OP_TYPE type, enum SCHEMA_OP_TYPE type,
const char *new_db= 0, const char *new_db,
const char *new_table_name= 0); const char *new_table_name,
int have_lock_open);
int ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name, int ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name,
NDB_SHARE *share, NDB_SHARE *share,
const char *type_str); const char *type_str);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment