#At file:///C:/mysql/5.5-cluster/ based on revid:magnus.blaudd@stripped
3246 Magnus Blåudd 2011-03-24
ndb
- move the locking of GSL before taking the EXCLUSIVE local MDL lock for CREATE. ALTER and DROP DATABASE
- add testcase for attempting these three operations against a mysqld connected to stopped NDB nodes.
- add new method on ndb_global_schema_lock_guard which raise proper error message on THD if lock fails
added:
mysql-test/suite/ndb/r/ndb_global_schema_lock_error.result
mysql-test/suite/ndb/t/ndb_global_schema_lock_error.test
mysql-test/suite/ndb/t/ndb_mgm.inc
mysql-test/suite/ndb/t/ndb_restart_nostart.inc
mysql-test/suite/ndb/t/ndb_restart_start.inc
mysql-test/suite/ndb/t/ndb_wait_nostart.inc
mysql-test/suite/ndb/t/ndb_wait_started.inc
mysql-test/suite/ndb/t/ndb_waiter.inc
modified:
sql/ndb_global_schema_lock.cc
sql/ndb_global_schema_lock_guard.h
sql/sql_db.cc
=== added file 'mysql-test/suite/ndb/r/ndb_global_schema_lock_error.result'
--- a/mysql-test/suite/ndb/r/ndb_global_schema_lock_error.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/r/ndb_global_schema_lock_error.result 2011-03-24 09:06:36 +0000
@@ -0,0 +1,11 @@
+call mtr.add_suppression("Could not acquire global schema lock");
+Restarting all nodes "no start"
+Waiting for not started
+CREATE DATABASE test2;
+ERROR HY000: Got error 4009 'Failed to acquire global schema lock' from ndbcluster
+ALTER DATABASE test2 CHARACTER SET latin2;
+ERROR HY000: Got error 4009 'Failed to acquire global schema lock' from ndbcluster
+DROP DATABASE test2;
+ERROR HY000: Got error 4009 'Failed to acquire global schema lock' from ndbcluster
+Starting all nodes
+Waiting for started
=== added file 'mysql-test/suite/ndb/t/ndb_global_schema_lock_error.test'
--- a/mysql-test/suite/ndb/t/ndb_global_schema_lock_error.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_global_schema_lock_error.test 2011-03-24 09:06:36 +0000
@@ -0,0 +1,35 @@
+-- source include/have_ndb.inc
+
+# Test will produce this error in server log file -> ignore
+call mtr.add_suppression("Could not acquire global schema lock");
+
+#
+# Run all the commands which should take the global schema lock
+# against a mysqld "connected" to stopped NDB nodes
+#
+
+# Restart NDB nodes into "no start"
+--source ndb_restart_nostart.inc
+
+--error ER_GET_ERRMSG
+CREATE DATABASE test2;
+--error ER_GET_ERRMSG
+ALTER DATABASE test2 CHARACTER SET latin2;
+--error ER_GET_ERRMSG
+DROP DATABASE test2;
+
+# Start NDB nodes back up again
+--source ndb_restart_start.inc
+
+
+
+# NOTE! this is a workaround so that check-testcase after test
+# see the mysql.ndb_schema table(if not connected, 'find_files'
+# will hide the table)
+#
+# Wait until mysqld has connected properly to cluster
+--disable_result_log
+--disable_query_log
+source include/ndb_not_readonly.inc;
+--enable_query_log
+--enable_result_log
=== added file 'mysql-test/suite/ndb/t/ndb_mgm.inc'
--- a/mysql-test/suite/ndb/t/ndb_mgm.inc 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_mgm.inc 2011-03-24 09:06:36 +0000
@@ -0,0 +1,3 @@
+let $_mgm_cmd=$NDB_MGM --no-defaults;
+let $_mgm_cmd=$_mgm_cmd --ndb-connectstring="$NDB_CONNECTSTRING";
+#echo mgm_cmd: $_mgm_cmd;
=== added file 'mysql-test/suite/ndb/t/ndb_restart_nostart.inc'
--- a/mysql-test/suite/ndb/t/ndb_restart_nostart.inc 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_restart_nostart.inc 2011-03-24 09:06:36 +0000
@@ -0,0 +1,6 @@
+--source ndb_mgm.inc
+
+--echo Restarting all nodes "no start"
+--exec $_mgm_cmd -e "ALL RESTART -n" > /dev/null
+
+--source ndb_wait_nostart.inc
=== added file 'mysql-test/suite/ndb/t/ndb_restart_start.inc'
--- a/mysql-test/suite/ndb/t/ndb_restart_start.inc 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_restart_start.inc 2011-03-24 09:06:36 +0000
@@ -0,0 +1,6 @@
+--source ndb_mgm.inc
+
+--echo Starting all nodes
+--exec $_mgm_cmd -e "ALL START" > /dev/null
+
+--source ndb_wait_started.inc
=== added file 'mysql-test/suite/ndb/t/ndb_wait_nostart.inc'
--- a/mysql-test/suite/ndb/t/ndb_wait_nostart.inc 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_wait_nostart.inc 2011-03-24 09:06:36 +0000
@@ -0,0 +1,4 @@
+--source ndb_waiter.inc
+
+--echo Waiting for not started
+--exec $_waiter_cmd --not-started > /dev/null
=== added file 'mysql-test/suite/ndb/t/ndb_wait_started.inc'
--- a/mysql-test/suite/ndb/t/ndb_wait_started.inc 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_wait_started.inc 2011-03-24 09:06:36 +0000
@@ -0,0 +1,4 @@
+--source ndb_waiter.inc
+
+--echo Waiting for started
+--exec $_waiter_cmd > /dev/null
=== added file 'mysql-test/suite/ndb/t/ndb_waiter.inc'
--- a/mysql-test/suite/ndb/t/ndb_waiter.inc 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_waiter.inc 2011-03-24 09:06:36 +0000
@@ -0,0 +1,3 @@
+let $_waiter_cmd=$NDB_WAITER --no-defaults;
+let $_waiter_cmd=$_waiter_cmd --ndb-connectstring="$NDB_CONNECTSTRING";
+#echo waiter_cmd: $_waiter_cmd;
=== modified file 'sql/ndb_global_schema_lock.cc'
--- a/sql/ndb_global_schema_lock.cc 2011-03-09 13:09:55 +0000
+++ b/sql/ndb_global_schema_lock.cc 2011-03-24 09:06:36 +0000
@@ -433,3 +433,21 @@ int Ndb_global_schema_lock_guard::lock(b
return ndbcluster_global_schema_lock(m_thd, no_lock_queue,
report_cluster_disconnected);
}
+
+
+bool
+Ndb_global_schema_lock_guard::lock_raise_error(void)
+{
+ if (lock() != 0)
+ {
+ Thd_ndb *thd_ndb= thd_get_thd_ndb(m_thd);
+
+ my_error(ER_GET_ERRMSG, MYF(0),
+ thd_ndb->global_schema_lock_error,
+ "Failed to acquire global schema lock",
+ "ndbcluster");
+
+ return false; // Failed
+ }
+ return true; // OK
+}
=== modified file 'sql/ndb_global_schema_lock_guard.h'
--- a/sql/ndb_global_schema_lock_guard.h 2011-03-09 13:09:55 +0000
+++ b/sql/ndb_global_schema_lock_guard.h 2011-03-24 09:06:36 +0000
@@ -27,8 +27,12 @@ public:
~Ndb_global_schema_lock_guard();
int lock(bool no_lock_queue=false,
bool report_cluster_disconnected=true);
+
+ // Lock GSL, raise error in THD if failure occurs
+ bool lock_raise_error(void);
+
private:
- THD *m_thd;
+ THD* m_thd;
bool m_locked;
};
=== modified file 'sql/sql_db.cc'
--- a/sql/sql_db.cc 2011-03-08 15:18:22 +0000
+++ b/sql/sql_db.cc 2011-03-24 09:06:36 +0000
@@ -554,15 +554,16 @@ int mysql_create_db(THD *thd, char *db,
my_error(ER_DB_CREATE_EXISTS, MYF(0), db);
DBUG_RETURN(-1);
}
+
+#ifndef MCP_GLOBAL_SCHEMA_LOCK
+ Ndb_global_schema_lock_guard global_schema_lock_guard(thd);
+ if (!global_schema_lock_guard.lock_raise_error())
+ DBUG_RETURN(-1); // Same as failed lock_schema_name, see below
+ #endif
if (lock_schema_name(thd, db))
DBUG_RETURN(-1);
-#ifndef MCP_GLOBAL_SCHEMA_LOCK
- Ndb_global_schema_lock_guard global_schema_lock_guard(thd);
- global_schema_lock_guard.lock();
-#endif
-
/* Check directory */
path_len= build_table_filename(path, sizeof(path) - 1, db, "", "", 0);
path[path_len-1]= 0; // Remove last '/' from path
@@ -692,14 +693,15 @@ bool mysql_alter_db(THD *thd, const char
int error= 0;
DBUG_ENTER("mysql_alter_db");
- if (lock_schema_name(thd, db))
- DBUG_RETURN(TRUE);
-
#ifndef MCP_GLOBAL_SCHEMA_LOCK
Ndb_global_schema_lock_guard global_schema_lock_guard(thd);
- global_schema_lock_guard.lock();
+ if (!global_schema_lock_guard.lock_raise_error())
+ DBUG_RETURN(TRUE); // Same as failed lock_schema_name, se below
#endif
+ if (lock_schema_name(thd, db))
+ DBUG_RETURN(TRUE);
+
/*
Recreate db options file: /dbpath/.db.opt
We pass MY_DB_OPT_FILE as "extension" to avoid
@@ -778,15 +780,15 @@ bool mysql_rm_db(THD *thd,char *db,bool
Drop_table_error_handler err_handler;
DBUG_ENTER("mysql_rm_db");
+#ifndef MCP_GLOBAL_SCHEMA_LOCK
+ Ndb_global_schema_lock_guard global_schema_lock_guard(thd);
+ if (!global_schema_lock_guard.lock_raise_error())
+ DBUG_RETURN(true); // Same as failed lock_schema_name, see below
+ #endif
if (lock_schema_name(thd, db))
DBUG_RETURN(true);
-#ifndef MCP_GLOBAL_SCHEMA_LOCK
- Ndb_global_schema_lock_guard global_schema_lock_guard(thd);
- global_schema_lock_guard.lock();
-#endif
-
length= build_table_filename(path, sizeof(path) - 1, db, "", "", 0);
strmov(path+length, MY_DB_OPT_FILE); // Append db option file name
del_dbopt(path); // Remove dboption hash entry
Attachment: [text/bzr-bundle] bzr/magnus.blaudd@sun.com-20110324090636-m0gcs19qalpacb3a.bundle
| Thread |
|---|
| • bzr commit into mysql-5.5-cluster branch (magnus.blaudd:3246) | Magnus Blåudd | 24 Mar |