My Project
rpl_filter.h
00001 /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software Foundation,
00014    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
00015 
00016 #ifndef RPL_FILTER_H
00017 #define RPL_FILTER_H
00018 
00019 #include "mysql.h"
00020 #include "sql_list.h"                           /* I_List */
00021 #include "hash.h"                               /* HASH */
00022 
00023 class String;
00024 struct TABLE_LIST;
00025 typedef struct st_dynamic_array DYNAMIC_ARRAY;
00026 
00027 typedef struct st_table_rule_ent
00028 {
00029   char* db;
00030   char* tbl_name;
00031   uint key_len;
00032 } TABLE_RULE_ENT;
00033 
00034 /*
00035   Rpl_filter
00036 
00037   Inclusion and exclusion rules of tables and databases.
00038   Also handles rewrites of db.
00039   Used for replication and binlogging.
00040  */
00041 class Rpl_filter 
00042 {
00043 public:
00044   Rpl_filter();
00045   ~Rpl_filter();
00046   Rpl_filter(Rpl_filter const&);
00047   Rpl_filter& operator=(Rpl_filter const&);
00048  
00049   /* Checks - returns true if ok to replicate/log */
00050 
00051   bool tables_ok(const char* db, TABLE_LIST* tables);
00052   bool db_ok(const char* db);
00053   bool db_ok_with_wild_table(const char *db);
00054 
00055   bool is_on();
00056 
00057   bool is_rewrite_empty();
00058 
00059   /* Setters - add filtering rules */
00060   int build_do_table_hash();
00061   int build_ignore_table_hash();
00062 
00063   int add_do_table_array(const char* table_spec);
00064   int add_ignore_table_array(const char* table_spec);
00065 
00066   int add_wild_do_table(const char* table_spec);
00067   int add_wild_ignore_table(const char* table_spec);
00068 
00069   void add_do_db(const char* db_spec);
00070   void add_ignore_db(const char* db_spec);
00071 
00072   void add_db_rewrite(const char* from_db, const char* to_db);
00073 
00074   /* Getters - to get information about current rules */
00075 
00076   void get_do_table(String* str);
00077   void get_ignore_table(String* str);
00078 
00079   void get_wild_do_table(String* str);
00080   void get_wild_ignore_table(String* str);
00081 
00082   const char* get_rewrite_db(const char* db, size_t *new_len);
00083 
00084   I_List<i_string>* get_do_db();
00085   I_List<i_string>* get_ignore_db();
00086 
00087 private:
00088   bool table_rules_on;
00089 
00090   void init_table_rule_hash(HASH* h, bool* h_inited);
00091   void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited);
00092 
00093   int add_table_rule_to_array(DYNAMIC_ARRAY* a, const char* table_spec);
00094   int add_table_rule_to_hash(HASH* h, const char* table_spec, uint len);
00095 
00096   void free_string_array(DYNAMIC_ARRAY *a);
00097 
00098   void table_rule_ent_hash_to_str(String* s, HASH* h, bool inited);
00099   void table_rule_ent_dynamic_array_to_str(String* s, DYNAMIC_ARRAY* a,
00100                                            bool inited);
00101   TABLE_RULE_ENT* find_wild(DYNAMIC_ARRAY *a, const char* key, int len);
00102 
00103   int build_table_hash_from_array(DYNAMIC_ARRAY *table_array, HASH *table_hash,
00104                                   bool array_inited, bool *hash_inited);
00105 
00106   /*
00107     Those 6 structures below are uninitialized memory unless the
00108     corresponding *_inited variables are "true".
00109   */
00110   /* For quick search */
00111   HASH do_table_hash;
00112   HASH ignore_table_hash;
00113 
00114   DYNAMIC_ARRAY do_table_array;
00115   DYNAMIC_ARRAY ignore_table_array;
00116 
00117   DYNAMIC_ARRAY wild_do_table;
00118   DYNAMIC_ARRAY wild_ignore_table;
00119 
00120   bool do_table_hash_inited;
00121   bool ignore_table_hash_inited;
00122   bool do_table_array_inited;
00123   bool ignore_table_array_inited;
00124   bool wild_do_table_inited;
00125   bool wild_ignore_table_inited;
00126 
00127   I_List<i_string> do_db;
00128   I_List<i_string> ignore_db;
00129 
00130   I_List<i_string_pair> rewrite_db;
00131 };
00132 
00133 extern Rpl_filter *rpl_filter;
00134 extern Rpl_filter *binlog_filter;
00135 
00136 #endif // RPL_FILTER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines