~vadim-tk/percona-server/flushing-algo

« back to all changes in this revision

Viewing changes to sql/rpl_filter.h

  • Committer: root
  • Date: 2011-10-29 01:34:40 UTC
  • Revision ID: root@hppro1.office.percona.com-20111029013440-qhnf4jk8kdjcf4e0
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  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;
 
32
} TABLE_RULE_ENT;
 
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
  /* Setters - add filtering rules */
 
58
 
 
59
  int add_do_table(const char* table_spec);
 
60
  int add_ignore_table(const char* table_spec);
 
61
 
 
62
  int add_wild_do_table(const char* table_spec);
 
63
  int add_wild_ignore_table(const char* table_spec);
 
64
 
 
65
  void add_do_db(const char* db_spec);
 
66
  void add_ignore_db(const char* db_spec);
 
67
 
 
68
  void add_db_rewrite(const char* from_db, const char* to_db);
 
69
 
 
70
  /* Getters - to get information about current rules */
 
71
 
 
72
  void get_do_table(String* str);
 
73
  void get_ignore_table(String* str);
 
74
 
 
75
  void get_wild_do_table(String* str);
 
76
  void get_wild_ignore_table(String* str);
 
77
 
 
78
  const char* get_rewrite_db(const char* db, size_t *new_len);
 
79
 
 
80
  I_List<i_string>* get_do_db();
 
81
  I_List<i_string>* get_ignore_db();
 
82
 
 
83
private:
 
84
  bool table_rules_on;
 
85
 
 
86
  void init_table_rule_hash(HASH* h, bool* h_inited);
 
87
  void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited);
 
88
 
 
89
  int add_table_rule(HASH* h, const char* table_spec);
 
90
  int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec);
 
91
 
 
92
  void free_string_array(DYNAMIC_ARRAY *a);
 
93
 
 
94
  void table_rule_ent_hash_to_str(String* s, HASH* h, bool inited);
 
95
  void table_rule_ent_dynamic_array_to_str(String* s, DYNAMIC_ARRAY* a,
 
96
                                           bool inited);
 
97
  TABLE_RULE_ENT* find_wild(DYNAMIC_ARRAY *a, const char* key, int len);
 
98
 
 
99
  /*
 
100
    Those 4 structures below are uninitialized memory unless the
 
101
    corresponding *_inited variables are "true".
 
102
  */
 
103
  HASH do_table;
 
104
  HASH ignore_table;
 
105
  DYNAMIC_ARRAY wild_do_table;
 
106
  DYNAMIC_ARRAY wild_ignore_table;
 
107
 
 
108
  bool do_table_inited;
 
109
  bool ignore_table_inited;
 
110
  bool wild_do_table_inited;
 
111
  bool wild_ignore_table_inited;
 
112
 
 
113
  I_List<i_string> do_db;
 
114
  I_List<i_string> ignore_db;
 
115
 
 
116
  I_List<i_string_pair> rewrite_db;
 
117
};
 
118
 
 
119
extern Rpl_filter *rpl_filter;
 
120
extern Rpl_filter *binlog_filter;
 
121
 
 
122
#endif // RPL_FILTER_H