2006-01-12 19:51:02 +01:00
|
|
|
/* Copyright (C) 2000-2003 MySQL AB
|
|
|
|
|
|
|
|
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; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Typedefs for long names
|
|
|
|
typedef NdbDictionary::Object NDBOBJ;
|
|
|
|
typedef NdbDictionary::Column NDBCOL;
|
|
|
|
typedef NdbDictionary::Table NDBTAB;
|
|
|
|
typedef NdbDictionary::Index NDBINDEX;
|
|
|
|
typedef NdbDictionary::Dictionary NDBDICT;
|
|
|
|
typedef NdbDictionary::Event NDBEVENT;
|
|
|
|
|
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
The intermediate (not temporary) files of the new table
during ALTER TABLE was visible for SHOW TABLES. These
intermediate files are copies of the original table with
the changes done by ALTER TABLE. After all the data is
copied over from the original table, these files are renamed
to the original tables file names. So they are not temporary
files. They persist after ALTER TABLE, but just with another
name.
In 5.0 the intermediate files are invisible for SHOW TABLES
because all file names beginning with "#sql" were suppressed.
This failed since 5.1.6 because even temporary table names were
converted when making file names from them. The prefix became
converted to "@0023sql". Converting the prefix during SHOW TABLES
would suppress the listing of user tables that start with "#sql".
The solution of the problem is to continue the implementation of
the table name to file name conversion feature. One requirement
is to suppress the conversion for temporary table names.
This change is straightforward for real temporary tables as there
is a function that creates temporary file names.
But the generated path names are located in TMPDIR and have no
relation to the internal table name. This cannot be used for
ALTER TABLE. Its intermediate files need to be in the same
directory as the old table files. And it is necessary to be
able to deduce the same path from the same table name repeatedly.
Consequently the intermediate table files must be handled like normal
tables. Their internal names shall start with tmp_file_prefix
(#sql) and they shall not be converted like normal table names.
I added a flags parameter to all relevant functions that are
called from ALTER TABLE. It is used to suppress the conversion
for the intermediate table files.
The outcome is that the suppression of #sql in SHOW TABLES
works again. It does not suppress user tables as these are
converted to @0023sql on file level.
This patch does also fix ALTER TABLE ... RENAME, which could not
rename a table with non-ASCII characters in its name.
It does also fix the problem that a user could create a table like
`#sql-xxxx-yyyy`, where xxxx is mysqld's pid and yyyy is the thread
ID of some other thread, which prevented this thread from running
ALTER TABLE.
Some of the above problems are mentioned in Bug 1405, which can
be closed with this patch.
This patch does also contain some minor fixes for other forgotten
conversions. Still known problems are reported as bugs 21370,
21373, and 21387.
mysql-test/r/alter_table.result:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added test results.
mysql-test/r/backup.result:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added test results.
mysql-test/r/repair.result:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added test results.
mysql-test/t/alter_table.test:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added test cases.
mysql-test/t/backup.test:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added test cases.
mysql-test/t/repair.test:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added a test case.
sql/ha_myisam.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added missing table name mapping calls to backup() and restore().
sql/ha_myisammrg.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/ha_ndbcluster.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/ha_ndbcluster_binlog.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/ha_ndbcluster_binlog.h:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Removed unnecessary check for wrong temp file prefix.
sql/mysql_priv.h:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Extended quick_rm_table(), mysql_rename_table(), and
build_table_filename() by an flags argument, which can indicate
temporary table names that should not be converted.
Added symbolic flag values.
sql/sql_acl.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_base.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Fixed a comment.
Added DBUG calls.
sql/sql_db.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_delete.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_insert.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_partition.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_rename.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_show.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Reverted the former fix for this bug. tmp_file_prefix is now used
verbatim in the comparison of file names.
sql/sql_table.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added a check for a tmp_file_prefix file name to
filename_to_tablename(). These names are now accepted without
conversion.
Extended quick_rm_table(), mysql_rename_table(), and
build_table_filename() by an flags argument, which can indicate
temporary table names that should not be converted.
Removed the table to file name conversion from
build_tmptable_filename().
Disabled REPAIR TABLE ... USE_FRM for temporary tables.
Added the forgotten conversion to mysql_alter_table() for the case
of ALTER TABLE ... RENAME.
Added comments and DBUG calls.
sql/sql_trigger.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/sql_view.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Added an zero argument for the new 'flags' parameter.
sql/table.cc:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Replaced a literal ".frm" by reg_ext.
Added DBUG calls.
storage/innobase/row/row0mysql.c:
Bug#18775 - Temporary table from alter table visible to other threads
Continued implementation of WL#1324 (table name to filename encoding)
Changed back the encoded temp file prefix to #sql.
2006-08-02 17:57:06 +02:00
|
|
|
#define IS_TMP_PREFIX(A) (is_prefix(A, tmp_file_prefix))
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
extern ulong ndb_extra_logging;
|
|
|
|
|
|
|
|
#define INJECTOR_EVENT_LEN 200
|
|
|
|
|
2006-03-23 22:49:02 +01:00
|
|
|
#define NDB_INVALID_SCHEMA_OBJECT 241
|
|
|
|
|
2006-10-01 20:17:59 +02:00
|
|
|
extern handlerton *ndbcluster_hton;
|
|
|
|
|
2006-02-06 11:47:12 +01:00
|
|
|
/*
|
|
|
|
The numbers below must not change as they
|
|
|
|
are passed between mysql servers, and if changed
|
|
|
|
would break compatablility. Add new numbers to
|
|
|
|
the end.
|
|
|
|
*/
|
2006-01-12 19:51:02 +01:00
|
|
|
enum SCHEMA_OP_TYPE
|
|
|
|
{
|
2006-02-06 11:47:12 +01:00
|
|
|
SOT_DROP_TABLE= 0,
|
|
|
|
SOT_CREATE_TABLE= 1,
|
2006-05-04 13:58:17 +02:00
|
|
|
SOT_RENAME_TABLE_NEW= 2,
|
2006-02-06 11:47:12 +01:00
|
|
|
SOT_ALTER_TABLE= 3,
|
|
|
|
SOT_DROP_DB= 4,
|
|
|
|
SOT_CREATE_DB= 5,
|
|
|
|
SOT_ALTER_DB= 6,
|
|
|
|
SOT_CLEAR_SLOCK= 7,
|
|
|
|
SOT_TABLESPACE= 8,
|
2006-05-04 13:58:17 +02:00
|
|
|
SOT_LOGFILE_GROUP= 9,
|
2006-06-12 14:23:21 +02:00
|
|
|
SOT_RENAME_TABLE= 10,
|
|
|
|
SOT_TRUNCATE_TABLE= 11
|
2006-01-12 19:51:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const uint max_ndb_nodes= 64; /* multiple of 32 */
|
|
|
|
|
2006-01-20 12:55:07 +01:00
|
|
|
static const char *ha_ndb_ext=".ndb";
|
|
|
|
static const char share_prefix[]= "./";
|
|
|
|
|
2006-05-04 13:58:17 +02:00
|
|
|
class Ndb_table_guard
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Ndb_table_guard(NDBDICT *dict, const char *tabname)
|
|
|
|
: m_dict(dict)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Ndb_table_guard");
|
|
|
|
m_ndbtab= m_dict->getTableGlobal(tabname);
|
|
|
|
m_invalidate= 0;
|
|
|
|
DBUG_PRINT("info", ("m_ndbtab: %p", m_ndbtab));
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
~Ndb_table_guard()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("~Ndb_table_guard");
|
|
|
|
if (m_ndbtab)
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("m_ndbtab: %p m_invalidate: %d",
|
|
|
|
m_ndbtab, m_invalidate));
|
|
|
|
m_dict->removeTableGlobal(*m_ndbtab, m_invalidate);
|
|
|
|
}
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
const NDBTAB *get_table() { return m_ndbtab; }
|
|
|
|
void invalidate() { m_invalidate= 1; }
|
|
|
|
const NDBTAB *release()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("Ndb_table_guard::release");
|
|
|
|
const NDBTAB *tmp= m_ndbtab;
|
|
|
|
DBUG_PRINT("info", ("m_ndbtab: %p", m_ndbtab));
|
|
|
|
m_ndbtab = 0;
|
|
|
|
DBUG_RETURN(tmp);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
const NDBTAB *m_ndbtab;
|
|
|
|
NDBDICT *m_dict;
|
|
|
|
int m_invalidate;
|
|
|
|
};
|
|
|
|
|
2006-01-20 12:55:07 +01:00
|
|
|
#ifdef HAVE_NDB_BINLOG
|
2006-01-12 19:51:02 +01:00
|
|
|
extern pthread_t ndb_binlog_thread;
|
|
|
|
extern pthread_mutex_t injector_mutex;
|
|
|
|
extern pthread_cond_t injector_cond;
|
|
|
|
|
|
|
|
extern unsigned char g_node_id_map[max_ndb_nodes];
|
|
|
|
extern pthread_t ndb_util_thread;
|
|
|
|
extern pthread_mutex_t LOCK_ndb_util_thread;
|
|
|
|
extern pthread_cond_t COND_ndb_util_thread;
|
|
|
|
extern int ndbcluster_util_inited;
|
|
|
|
extern pthread_mutex_t ndbcluster_mutex;
|
|
|
|
extern HASH ndbcluster_open_tables;
|
|
|
|
extern Ndb_cluster_connection* g_ndb_cluster_connection;
|
|
|
|
extern long ndb_number_of_storage_nodes;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Initialize the binlog part of the ndb handlerton
|
|
|
|
*/
|
|
|
|
void ndbcluster_binlog_init_handlerton();
|
|
|
|
/*
|
|
|
|
Initialize the binlog part of the NDB_SHARE
|
|
|
|
*/
|
|
|
|
void ndbcluster_binlog_init_share(NDB_SHARE *share, TABLE *table);
|
|
|
|
|
2006-09-12 16:34:12 +02:00
|
|
|
bool ndbcluster_check_if_local_table(const char *dbname, const char *tabname);
|
2006-11-15 11:13:49 +01:00
|
|
|
bool ndbcluster_check_if_local_tables_in_db(THD *thd, const char *dbname);
|
2006-09-12 16:34:12 +02:00
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
int ndbcluster_create_binlog_setup(Ndb *ndb, const char *key,
|
2006-01-31 15:40:26 +01:00
|
|
|
uint key_len,
|
2006-01-12 19:51:02 +01:00
|
|
|
const char *db,
|
|
|
|
const char *table_name,
|
2006-01-31 15:40:26 +01:00
|
|
|
my_bool share_may_exist);
|
2006-01-12 19:51:02 +01:00
|
|
|
int ndbcluster_create_event(Ndb *ndb, const NDBTAB *table,
|
2006-02-20 12:36:10 +01:00
|
|
|
const char *event_name, NDB_SHARE *share,
|
|
|
|
int push_warning= 0);
|
2006-01-12 19:51:02 +01:00
|
|
|
int ndbcluster_create_event_ops(NDB_SHARE *share,
|
|
|
|
const NDBTAB *ndbtab,
|
|
|
|
const char *event_name);
|
|
|
|
int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share,
|
|
|
|
const char *query, int query_length,
|
|
|
|
const char *db, const char *table_name,
|
|
|
|
uint32 ndb_table_id,
|
|
|
|
uint32 ndb_table_version,
|
2006-03-01 18:23:00 +01:00
|
|
|
enum SCHEMA_OP_TYPE type,
|
2006-05-31 01:52:14 +02:00
|
|
|
const char *new_db,
|
|
|
|
const char *new_table_name,
|
|
|
|
int have_lock_open);
|
2006-01-12 19:51:02 +01:00
|
|
|
int ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name,
|
2006-04-10 16:08:40 +02:00
|
|
|
NDB_SHARE *share,
|
|
|
|
const char *type_str);
|
2006-01-12 19:51:02 +01:00
|
|
|
void ndb_rep_event_name(String *event_name,
|
|
|
|
const char *db, const char *tbl);
|
2006-01-31 01:37:48 +01:00
|
|
|
int ndb_create_table_from_engine(THD *thd, const char *db,
|
|
|
|
const char *table_name);
|
2006-01-12 19:51:02 +01:00
|
|
|
int ndbcluster_binlog_start();
|
|
|
|
pthread_handler_t ndb_binlog_thread_func(void *arg);
|
|
|
|
|
|
|
|
/*
|
2006-12-01 15:49:07 +01:00
|
|
|
table mysql.ndb_apply_status
|
2006-01-12 19:51:02 +01:00
|
|
|
*/
|
2006-04-10 16:08:40 +02:00
|
|
|
int ndbcluster_setup_binlog_table_shares(THD *thd);
|
2006-12-01 15:49:07 +01:00
|
|
|
extern NDB_SHARE *ndb_apply_status_share;
|
|
|
|
extern NDB_SHARE *ndb_schema_share;
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
extern THD *injector_thd;
|
2006-02-01 01:12:11 +01:00
|
|
|
extern my_bool ndb_binlog_running;
|
2006-04-10 16:08:40 +02:00
|
|
|
extern my_bool ndb_binlog_tables_inited;
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
ndbcluster_show_status_binlog(THD* thd, stat_print_fn *stat_print,
|
|
|
|
enum ha_stat_type stat_type);
|
|
|
|
|
|
|
|
/*
|
|
|
|
prototypes for ndb handler utility function also needed by
|
|
|
|
the ndb binlog code
|
|
|
|
*/
|
2006-02-13 11:23:13 +01:00
|
|
|
int cmp_frm(const NDBTAB *ndbtab, const void *pack_data,
|
|
|
|
uint pack_length);
|
2006-01-12 19:51:02 +01:00
|
|
|
int ndbcluster_find_all_files(THD *thd);
|
2006-01-20 12:55:07 +01:00
|
|
|
#endif /* HAVE_NDB_BINLOG */
|
|
|
|
|
2006-01-12 19:51:02 +01:00
|
|
|
void ndb_unpack_record(TABLE *table, NdbValue *value,
|
|
|
|
MY_BITMAP *defined, byte *buf);
|
|
|
|
|
|
|
|
NDB_SHARE *ndbcluster_get_share(const char *key,
|
|
|
|
TABLE *table,
|
|
|
|
bool create_if_not_exists,
|
|
|
|
bool have_lock);
|
|
|
|
NDB_SHARE *ndbcluster_get_share(NDB_SHARE *share);
|
|
|
|
void ndbcluster_free_share(NDB_SHARE **share, bool have_lock);
|
|
|
|
void ndbcluster_real_free_share(NDB_SHARE **share);
|
|
|
|
int handle_trailing_share(NDB_SHARE *share);
|
|
|
|
inline NDB_SHARE *get_share(const char *key,
|
|
|
|
TABLE *table,
|
|
|
|
bool create_if_not_exists= TRUE,
|
|
|
|
bool have_lock= FALSE)
|
|
|
|
{
|
|
|
|
return ndbcluster_get_share(key, table, create_if_not_exists, have_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline NDB_SHARE *get_share(NDB_SHARE *share)
|
|
|
|
{
|
|
|
|
return ndbcluster_get_share(share);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void free_share(NDB_SHARE **share, bool have_lock= FALSE)
|
|
|
|
{
|
|
|
|
ndbcluster_free_share(share, have_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void real_free_share(NDB_SHARE **share)
|
|
|
|
{
|
|
|
|
ndbcluster_real_free_share(share);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
Thd_ndb *
|
2006-09-15 19:28:00 +02:00
|
|
|
get_thd_ndb(THD *thd) { return (Thd_ndb *) thd->ha_data[ndbcluster_hton->slot]; }
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
inline
|
|
|
|
void
|
2006-09-15 19:28:00 +02:00
|
|
|
set_thd_ndb(THD *thd, Thd_ndb *thd_ndb) { thd->ha_data[ndbcluster_hton->slot]= thd_ndb; }
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
Ndb* check_ndb_in_thd(THD* thd);
|