My Project
ha_ndbcluster_binlog.h
00001 /*
00002    Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; version 2 of the License.
00007 
00008    This program is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011    GNU General Public License for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; if not, write to the Free Software
00015    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
00016 */
00017 
00018 // Typedefs for long names
00019 typedef NdbDictionary::Object NDBOBJ;
00020 typedef NdbDictionary::Column NDBCOL;
00021 typedef NdbDictionary::Table NDBTAB;
00022 typedef NdbDictionary::Index  NDBINDEX;
00023 typedef NdbDictionary::Dictionary  NDBDICT;
00024 typedef NdbDictionary::Event  NDBEVENT;
00025 
00026 #define IS_TMP_PREFIX(A) (is_prefix(A, tmp_file_prefix))
00027 
00028 #define INJECTOR_EVENT_LEN 200
00029 
00030 #define NDB_INVALID_SCHEMA_OBJECT 241
00031 
00032 extern handlerton *ndbcluster_hton;
00033 
00034 class Ndb_event_data
00035 {
00036 public:
00037   Ndb_event_data(NDB_SHARE *the_share) :
00038     shadow_table(0),
00039     share(the_share)
00040   {
00041     ndb_value[0]= 0;
00042     ndb_value[1]= 0;
00043   }
00044   ~Ndb_event_data()
00045   {
00046     if (shadow_table)
00047       closefrm(shadow_table, 1);
00048     shadow_table= 0;
00049     free_root(&mem_root, MYF(0));
00050     share= 0;
00051     /*
00052        ndbvalue[] allocated with my_multi_malloc
00053        so only first pointer should be freed  
00054     */
00055     my_free(ndb_value[0], MYF(MY_WME|MY_ALLOW_ZERO_PTR));
00056   }
00057   MEM_ROOT mem_root;
00058   TABLE *shadow_table;
00059   NDB_SHARE *share;
00060   NdbValue *ndb_value[2];
00061 };
00062 
00063 /*
00064   The numbers below must not change as they
00065   are passed between mysql servers, and if changed
00066   would break compatablility.  Add new numbers to
00067   the end.
00068 */
00069 enum SCHEMA_OP_TYPE
00070 {
00071   SOT_DROP_TABLE= 0,
00072   SOT_CREATE_TABLE= 1,
00073   SOT_RENAME_TABLE_NEW= 2,
00074   SOT_ALTER_TABLE_COMMIT= 3,
00075   SOT_DROP_DB= 4,
00076   SOT_CREATE_DB= 5,
00077   SOT_ALTER_DB= 6,
00078   SOT_CLEAR_SLOCK= 7,
00079   SOT_TABLESPACE= 8,
00080   SOT_LOGFILE_GROUP= 9,
00081   SOT_RENAME_TABLE= 10,
00082   SOT_TRUNCATE_TABLE= 11,
00083   SOT_RENAME_TABLE_PREPARE= 12,
00084   SOT_ONLINE_ALTER_TABLE_PREPARE= 13,
00085   SOT_ONLINE_ALTER_TABLE_COMMIT= 14,
00086   SOT_CREATE_USER= 15,
00087   SOT_DROP_USER= 16,
00088   SOT_RENAME_USER= 17,
00089   SOT_GRANT= 18,
00090   SOT_REVOKE= 19
00091 };
00092 
00093 const uint max_ndb_nodes= 256; /* multiple of 32 */
00094 
00095 static const char *ha_ndb_ext=".ndb";
00096 
00097 #ifdef HAVE_NDB_BINLOG
00098 #define NDB_EXCEPTIONS_TABLE_SUFFIX "$EX"
00099 #define NDB_EXCEPTIONS_TABLE_SUFFIX_LOWER "$ex"
00100 
00101 const uint error_conflict_fn_violation= 9999;
00102 #endif /* HAVE_NDB_BINLOG */
00103 
00104 
00105 class Mutex_guard
00106 {
00107 public:
00108   Mutex_guard(pthread_mutex_t &mutex) : m_mutex(mutex)
00109   {
00110     pthread_mutex_lock(&m_mutex);
00111   };
00112   ~Mutex_guard()
00113   {
00114     pthread_mutex_unlock(&m_mutex);
00115   };
00116 private:
00117   pthread_mutex_t &m_mutex;
00118 };
00119 
00120 
00121 extern Ndb_cluster_connection* g_ndb_cluster_connection;
00122 
00123 extern unsigned char g_node_id_map[max_ndb_nodes];
00124 extern pthread_mutex_t LOCK_ndb_util_thread;
00125 extern pthread_cond_t COND_ndb_util_thread;
00126 extern pthread_mutex_t LOCK_ndb_index_stat_thread;
00127 extern pthread_cond_t COND_ndb_index_stat_thread;
00128 extern pthread_mutex_t ndbcluster_mutex;
00129 extern HASH ndbcluster_open_tables;
00130 
00131 /*
00132   Initialize the binlog part of the ndb handlerton
00133 */
00134 void ndbcluster_binlog_init_handlerton();
00135 /*
00136   Initialize the binlog part of the NDB_SHARE
00137 */
00138 int ndbcluster_binlog_init_share(THD *thd, NDB_SHARE *share, TABLE *table);
00139 int ndbcluster_create_binlog_setup(THD *thd, Ndb *ndb, const char *key,
00140                                    uint key_len,
00141                                    const char *db,
00142                                    const char *table_name,
00143                                    TABLE * table);
00144 int ndbcluster_create_event(THD *thd, Ndb *ndb, const NDBTAB *table,
00145                             const char *event_name, NDB_SHARE *share,
00146                             int push_warning= 0);
00147 int ndbcluster_create_event_ops(THD *thd,
00148                                 NDB_SHARE *share,
00149                                 const NDBTAB *ndbtab,
00150                                 const char *event_name);
00151 int ndbcluster_log_schema_op(THD *thd,
00152                              const char *query, int query_length,
00153                              const char *db, const char *table_name,
00154                              uint32 ndb_table_id,
00155                              uint32 ndb_table_version,
00156                              enum SCHEMA_OP_TYPE type,
00157                              const char *new_db,
00158                              const char *new_table_name);
00159 int ndbcluster_drop_event(THD *thd, Ndb *ndb, NDB_SHARE *share,
00160                           const char *type_str,
00161                           const char * dbname, const char * tabname);
00162 int ndbcluster_handle_drop_table(THD *thd, Ndb *ndb, NDB_SHARE *share,
00163                                  const char *type_str,
00164                                  const char * db, const char * tabname);
00165 void ndb_rep_event_name(String *event_name,
00166                         const char *db, const char *tbl, my_bool full);
00167 #ifdef HAVE_NDB_BINLOG
00168 int
00169 ndbcluster_get_binlog_replication_info(THD *thd, Ndb *ndb,
00170                                        const char* db,
00171                                        const char* table_name,
00172                                        uint server_id,
00173                                        const TABLE *table,
00174                                        Uint32* binlog_flags,
00175                                        const st_conflict_fn_def** conflict_fn,
00176                                        st_conflict_fn_arg* args,
00177                                        Uint32* num_args);
00178 int
00179 ndbcluster_apply_binlog_replication_info(THD *thd,
00180                                          NDB_SHARE *share,
00181                                          const NDBTAB* ndbtab,
00182                                          TABLE* table,
00183                                          const st_conflict_fn_def* conflict_fn,
00184                                          const st_conflict_fn_arg* args,
00185                                          Uint32 num_args,
00186                                          bool do_set_binlog_flags,
00187                                          Uint32 binlog_flags);
00188 int
00189 ndbcluster_read_binlog_replication(THD *thd, Ndb *ndb,
00190                                    NDB_SHARE *share,
00191                                    const NDBTAB *ndbtab,
00192                                    uint server_id,
00193                                    TABLE *table,
00194                                    bool do_set_binlog_flags);
00195 #endif
00196 int ndb_create_table_from_engine(THD *thd, const char *db,
00197                                  const char *table_name);
00198 int ndbcluster_binlog_start();
00199 
00200 
00201 /*
00202   Setup function for the ndb binlog component. The function should be
00203   called on startup until it succeeds(to allow initial setup) and with
00204   regular intervals afterwards to reconnect after a lost cluster
00205   connection
00206 */
00207 bool ndb_binlog_setup(THD *thd);
00208 
00209 /*
00210   Will return true when the ndb binlog component is properly setup
00211   and ready to receive events from the cluster. As long as function
00212   returns false, all tables in this MySQL Server are opened in read only
00213   mode to avoid writes before the binlog is ready to record them.
00214  */
00215 bool ndb_binlog_is_read_only(void);
00216 
00217 extern NDB_SHARE *ndb_apply_status_share;
00218 extern NDB_SHARE *ndb_schema_share;
00219 
00220 extern my_bool ndb_binlog_running;
00221 
00222 bool
00223 ndbcluster_show_status_binlog(THD* thd, stat_print_fn *stat_print,
00224                               enum ha_stat_type stat_type);
00225 
00226 /*
00227   prototypes for ndb handler utility function also needed by
00228   the ndb binlog code
00229 */
00230 int cmp_frm(const NDBTAB *ndbtab, const void *pack_data,
00231             uint pack_length);
00232 int ndbcluster_find_all_files(THD *thd);
00233 
00234 char *ndb_pack_varchar(const NDBCOL *col, char *buf,
00235                        const char *str, int sz);
00236 
00237 NDB_SHARE *ndbcluster_get_share(const char *key,
00238                                 TABLE *table,
00239                                 bool create_if_not_exists,
00240                                 bool have_lock);
00241 NDB_SHARE *ndbcluster_get_share(NDB_SHARE *share);
00242 void ndbcluster_free_share(NDB_SHARE **share, bool have_lock);
00243 void ndbcluster_real_free_share(NDB_SHARE **share);
00244 int handle_trailing_share(THD *thd, NDB_SHARE *share);
00245 int ndbcluster_prepare_rename_share(NDB_SHARE *share, const char *new_key);
00246 int ndbcluster_rename_share(THD *thd, NDB_SHARE *share);
00247 int ndbcluster_undo_rename_share(THD *thd, NDB_SHARE *share);
00248 inline NDB_SHARE *get_share(const char *key,
00249                             TABLE *table,
00250                             bool create_if_not_exists= TRUE,
00251                             bool have_lock= FALSE)
00252 {
00253   return ndbcluster_get_share(key, table, create_if_not_exists, have_lock);
00254 }
00255 
00256 inline NDB_SHARE *get_share(NDB_SHARE *share)
00257 {
00258   return ndbcluster_get_share(share);
00259 }
00260 
00261 inline void free_share(NDB_SHARE **share, bool have_lock= FALSE)
00262 {
00263   ndbcluster_free_share(share, have_lock);
00264 }
00265 
00266 void set_binlog_flags(NDB_SHARE *share);
00267 
00268 /*
00269   Helper functions
00270 */
00271 bool
00272 ndbcluster_check_if_local_table(const char *dbname, const char *tabname);
00273 bool
00274 ndbcluster_check_if_local_tables_in_db(THD *thd, const char *dbname);
00275 
00276 bool ndbcluster_anyvalue_is_reserved(Uint32 anyValue);
00277 bool ndbcluster_anyvalue_is_nologging(Uint32 anyValue);
00278 void ndbcluster_anyvalue_set_nologging(Uint32& anyValue);
00279 bool ndbcluster_anyvalue_is_serverid_in_range(Uint32 serverId);
00280 void ndbcluster_anyvalue_set_normal(Uint32& anyValue);
00281 Uint32 ndbcluster_anyvalue_get_serverid(Uint32 anyValue);
00282 void ndbcluster_anyvalue_set_serverid(Uint32& anyValue, Uint32 serverId);
00283 
00284 #ifndef DBUG_OFF
00285 void dbug_ndbcluster_anyvalue_set_userbits(Uint32& anyValue);
00286 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines