drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
filtered_replicator.h
Go to the documentation of this file.
1/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2009 Sun Microsystems, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
29
30#pragma once
31
32#include <drizzled/atomics.h>
33#include <drizzled/plugin/transaction_replicator.h>
34
35#include <drizzled/pcre.h>
36
37#include <vector>
38#include <string>
39
40namespace drizzle_plugin
41{
42
43class FilteredReplicator :
45{
46public:
47 FilteredReplicator(std::string name_arg,
48 const std::string &sch_filter,
49 const std::string &tab_filter,
50 const std::string &sch_regex,
51 const std::string &tab_regex);
52
55
73 drizzled::plugin::ReplicationReturnCode
75 drizzled::Session &in_session,
76 drizzled::message::Transaction &to_replicate);
77
85 void setSchemaFilter(const std::string &input);
86
90 const std::string &getSchemaFilter() const
91 {
92 return _sch_filter;
93 }
94
102 void setTableFilter(const std::string &input);
103
107 const std::string &getTableFilter() const
108 {
109 return _tab_filter;
110 }
111
118 void updateTableSysvar(const char **var_ptr)
119 {
120 *var_ptr= _tab_filter.c_str();
121 pthread_mutex_unlock(&sysvar_tab_lock);
122 }
123
130 void updateSchemaSysvar(const char **var_ptr)
131 {
132 *var_ptr= _sch_filter.c_str();
133 pthread_mutex_unlock(&sysvar_sch_lock);
134 }
135
136private:
137
146 void populateFilter(std::string input,
147 std::vector<std::string> &filter);
148
157 bool isSchemaFiltered(const std::string &schema_name);
158
167 bool isTableFiltered(const std::string &table_name);
168
178 void parseStatementTableMetadata(const drizzled::message::Statement &in_statement,
179 std::string &in_schema_name,
180 std::string &in_table_name) const;
181
193 void parseQuery(const std::string &sql,
194 std::string &schema_name,
195 std::string &table_name);
196
197 /*
198 * Vectors of the tables and schemas to filter.
199 */
200 std::vector<std::string> schemas_to_filter;
201 std::vector<std::string> tables_to_filter;
202
203 /*
204 * Variables to contain the string representation of the
205 * comma-separated lists of schemas and tables to filter.
206 */
207 std::string _sch_filter;
208 std::string _tab_filter;
209
210 const std::string _sch_regex;
211 const std::string _tab_regex;
212
213 /*
214 * We need locks to protect the vectors when they are
215 * being updated and accessed. It would be nice to use
216 * r/w locks here since the vectors will mostly be
217 * accessed in a read-only fashion and will be only updated
218 * rarely.
219 */
220 pthread_mutex_t sch_vector_lock;
221 pthread_mutex_t tab_vector_lock;
222
223 /*
224 * We need a lock to protect the system variables
225 * that can be updated. We have a lock for each
226 * system variable.
227 */
228 pthread_mutex_t sysvar_sch_lock;
229 pthread_mutex_t sysvar_tab_lock;
230
231 pcre2_code *sch_re;
232 pcre2_code *tab_re;
233};
234
235} /* namespace drizzle_plugin */
void populateFilter(std::string input, std::vector< std::string > &filter)
void updateTableSysvar(const char **var_ptr)
bool isTableFiltered(const std::string &table_name)
void setTableFilter(const std::string &input)
void parseStatementTableMetadata(const drizzled::message::Statement &in_statement, std::string &in_schema_name, std::string &in_table_name) const
drizzled::plugin::ReplicationReturnCode replicate(drizzled::plugin::TransactionApplier *in_applier, drizzled::Session &in_session, drizzled::message::Transaction &to_replicate)
void parseQuery(const std::string &sql, std::string &schema_name, std::string &table_name)
bool isSchemaFiltered(const std::string &schema_name)
void updateSchemaSysvar(const char **var_ptr)
const std::string & getTableFilter() const
void setSchemaFilter(const std::string &input)
const std::string & getSchemaFilter() const