MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rpl_filter.h
1 /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
16 #ifndef RPL_FILTER_H
17 #define RPL_FILTER_H
18 
19 #include "mysql.h"
20 #include "sql_list.h" /* I_List */
21 #include "hash.h" /* HASH */
22 
23 class String;
24 struct TABLE_LIST;
25 typedef struct st_dynamic_array DYNAMIC_ARRAY;
26 
27 typedef struct st_table_rule_ent
28 {
29  char* db;
30  char* tbl_name;
31  uint key_len;
33 
34 /*
35  Rpl_filter
36 
37  Inclusion and exclusion rules of tables and databases.
38  Also handles rewrites of db.
39  Used for replication and binlogging.
40  */
41 class Rpl_filter
42 {
43 public:
44  Rpl_filter();
45  ~Rpl_filter();
46  Rpl_filter(Rpl_filter const&);
47  Rpl_filter& operator=(Rpl_filter const&);
48 
49  /* Checks - returns true if ok to replicate/log */
50 
51  bool tables_ok(const char* db, TABLE_LIST* tables);
52  bool db_ok(const char* db);
53  bool db_ok_with_wild_table(const char *db);
54 
55  bool is_on();
56 
57  bool is_rewrite_empty();
58 
59  /* Setters - add filtering rules */
60  int build_do_table_hash();
61  int build_ignore_table_hash();
62 
63  int add_do_table_array(const char* table_spec);
64  int add_ignore_table_array(const char* table_spec);
65 
66  int add_wild_do_table(const char* table_spec);
67  int add_wild_ignore_table(const char* table_spec);
68 
69  void add_do_db(const char* db_spec);
70  void add_ignore_db(const char* db_spec);
71 
72  void add_db_rewrite(const char* from_db, const char* to_db);
73 
74  /* Getters - to get information about current rules */
75 
76  void get_do_table(String* str);
77  void get_ignore_table(String* str);
78 
79  void get_wild_do_table(String* str);
80  void get_wild_ignore_table(String* str);
81 
82  const char* get_rewrite_db(const char* db, size_t *new_len);
83 
84  I_List<i_string>* get_do_db();
85  I_List<i_string>* get_ignore_db();
86 
87 private:
88  bool table_rules_on;
89 
90  void init_table_rule_hash(HASH* h, bool* h_inited);
91  void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited);
92 
93  int add_table_rule_to_array(DYNAMIC_ARRAY* a, const char* table_spec);
94  int add_table_rule_to_hash(HASH* h, const char* table_spec, uint len);
95 
96  void free_string_array(DYNAMIC_ARRAY *a);
97 
98  void table_rule_ent_hash_to_str(String* s, HASH* h, bool inited);
99  void table_rule_ent_dynamic_array_to_str(String* s, DYNAMIC_ARRAY* a,
100  bool inited);
101  TABLE_RULE_ENT* find_wild(DYNAMIC_ARRAY *a, const char* key, int len);
102 
103  int build_table_hash_from_array(DYNAMIC_ARRAY *table_array, HASH *table_hash,
104  bool array_inited, bool *hash_inited);
105 
106  /*
107  Those 6 structures below are uninitialized memory unless the
108  corresponding *_inited variables are "true".
109  */
110  /* For quick search */
111  HASH do_table_hash;
112  HASH ignore_table_hash;
113 
114  DYNAMIC_ARRAY do_table_array;
115  DYNAMIC_ARRAY ignore_table_array;
116 
117  DYNAMIC_ARRAY wild_do_table;
118  DYNAMIC_ARRAY wild_ignore_table;
119 
120  bool do_table_hash_inited;
121  bool ignore_table_hash_inited;
122  bool do_table_array_inited;
123  bool ignore_table_array_inited;
124  bool wild_do_table_inited;
125  bool wild_ignore_table_inited;
126 
127  I_List<i_string> do_db;
128  I_List<i_string> ignore_db;
129 
130  I_List<i_string_pair> rewrite_db;
131 };
132 
133 extern Rpl_filter *rpl_filter;
134 extern Rpl_filter *binlog_filter;
135 
136 #endif // RPL_FILTER_H