2009-09-23 23:32:31 +02:00
|
|
|
#ifndef HA_NDBCLUSTER_BINLOG_INCLUDED
|
|
|
|
#define HA_NDBCLUSTER_BINLOG_INCLUDED
|
|
|
|
|
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
|
2006-12-27 02:23:51 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
|
|
|
#define INJECTOR_EVENT_LEN 200
|
|
|
|
|
2006-03-23 22:49:02 +01:00
|
|
|
#define NDB_INVALID_SCHEMA_OBJECT 241
|
|
|
|
|
2007-04-18 16:02:20 +02:00
|
|
|
/* server id's with high bit set is reservered */
|
|
|
|
#define NDB_ANYVALUE_FOR_NOLOGGING 0xFFFFFFFF
|
|
|
|
#define NDB_ANYVALUE_RESERVED 0x80000000
|
|
|
|
|
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
|
|
|
|
*/
|
2007-08-30 11:46:30 +02:00
|
|
|
int ndbcluster_binlog_init_share(NDB_SHARE *share, TABLE *table);
|
2006-01-12 19:51:02 +01:00
|
|
|
|
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,
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
MY_BITMAP *defined, uchar *buf);
|
2007-04-03 07:20:55 +02:00
|
|
|
char *ndb_pack_varchar(const NDBCOL *col, char *buf,
|
|
|
|
const char *str, int sz);
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
Thd_ndb *
|
2007-08-31 08:19:52 +02:00
|
|
|
get_thd_ndb(THD *thd)
|
|
|
|
{ return (Thd_ndb *) thd_get_ha_data(thd, ndbcluster_hton); }
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
inline
|
|
|
|
void
|
2007-08-31 08:19:52 +02:00
|
|
|
set_thd_ndb(THD *thd, Thd_ndb *thd_ndb)
|
|
|
|
{ thd_set_ha_data(thd, ndbcluster_hton, thd_ndb); }
|
2006-01-12 19:51:02 +01:00
|
|
|
|
|
|
|
Ndb* check_ndb_in_thd(THD* thd);
|
2009-09-23 23:32:31 +02:00
|
|
|
|
|
|
|
#endif /* HA_NDBCLUSTER_BINLOG_INCLUDED */
|