20
20
#include <drizzled/server_includes.h>
21
21
#include <drizzled/qcache.h>
22
22
#include <drizzled/gettext.h>
27
static vector<QueryCache *> all_query_cache;
29
static void add_query_cache(QueryCache *handler)
31
all_query_cache.push_back(handler);
34
static void remove_query_cache(QueryCache *handler)
36
all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
24
40
int qcache_initializer(st_plugin_int *plugin)
29
if (p == NULL) return 1;
30
memset(p, 0, sizeof(qcache_t));
32
plugin->data= (void *)p;
34
45
if (plugin->plugin->init)
36
if (plugin->plugin->init((void *)p))
47
if (plugin->plugin->init(&p))
38
49
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' init() failed"),
51
62
int qcache_finalizer(st_plugin_int *plugin)
53
qcache_t *p= (qcache_t *) plugin->data;
55
64
if (plugin->plugin->deinit)
57
if (plugin->plugin->deinit((void *)p))
66
if (plugin->plugin->deinit(plugin->data))
59
68
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' deinit() failed"),
69
The plugin_foreach() iterator requires that we convert all the parameters
70
of a plugin API entry point into a single void pointer, plus the session.
71
So we need the following structure for qcache_invalidate_db() which requires
74
typedef struct db_invalidation_parms
78
} db_invalidation_parms_t;
84
qcache_try_fetch_and_send_iterate();
86
qcache_invalidate_table_iterate();
87
qcache_invalidate_db_iterate();
88
qcache_flush_iterate();
90
are called by plugin_foreach() _once_ for each Query Cache plugin.
93
static bool qcache_try_fetch_and_send_iterate(Session *session,
94
plugin_ref plugin, void *p)
96
qcache_t *l= plugin_data(plugin, qcache_t *);
97
bool is_transactional = (bool *)p;
99
if (l && l->qcache_try_fetch_and_send)
76
/* Namespaces are here to prevent global symbol clashes with these classes */
79
namespace query_cache {
81
class TryFetchAndSendIterate
82
: public unary_function<QueryCache *, bool>
85
bool is_transactional;
87
TryFetchAndSendIterate(Session *session_arg, bool is_transactional_arg) :
88
unary_function<QueryCache *, bool>(),
89
session(session_arg), is_transactional(is_transactional_arg) { }
91
inline result_type operator()(argument_type handler)
101
if (l->qcache_try_fetch_and_send(session, is_transactional))
93
if (handler->try_fetch_and_send(session, is_transactional))
103
95
errmsg_printf(ERRMSG_LVL_ERROR,
104
96
_("qcache plugin '%s' try_fetch_and_send() failed"),
105
(char *)plugin_name(plugin));
97
handler->getName().c_str());
112
static bool qcache_set_iterate(Session *session, plugin_ref plugin, void *p)
105
: public unary_function<QueryCache *, bool>
114
qcache_t *l = plugin_data(plugin, qcache_t *);
115
bool transactional = (bool *)p;
108
bool is_transactional;
110
SetIterate(Session *session_arg, bool is_transactional_arg) :
111
unary_function<QueryCache *, bool>(),
112
session(session_arg), is_transactional(is_transactional_arg) { }
117
if (l && l->qcache_set)
114
inline result_type operator()(argument_type handler)
119
if (l->qcache_set(session, transactional))
117
if (handler->set(session, is_transactional))
121
119
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' set() failed"),
122
(char *)plugin_name(plugin));
120
handler->getName().c_str());
129
static bool qcache_invalidate_table_iterate(Session *session,
130
plugin_ref plugin, void *p)
127
class InvalidateTableIterate
128
: public unary_function<QueryCache *, bool>
132
qcache_t *l = plugin_data(plugin, qcache_t *);
133
bool transactional = (bool *)p;
131
bool is_transactional;
133
InvalidateTableIterate(Session *session_arg, bool is_transactional_arg) :
134
unary_function<QueryCache *, bool>(),
135
session(session_arg), is_transactional(is_transactional_arg) { }
135
if (l && l->qcache_invalidate_table)
137
inline result_type operator()(argument_type handler)
137
if (l->qcache_invalidate_table(session, transactional))
140
if (handler->invalidate_table(session, is_transactional))
139
142
errmsg_printf(ERRMSG_LVL_ERROR,
140
143
_("qcache plugin '%s' invalidate_table() failed"),
141
(char *)plugin_name(plugin));
144
handler->getName().c_str());
148
static bool qcache_invalidate_db_iterate(Session *session,
149
plugin_ref plugin, void *p)
152
class InvalidateDbIterate
153
: public unary_function<QueryCache *, bool>
151
qcache_t *l = plugin_data(plugin, qcache_t *);
152
db_invalidation_parms_t *parms = (db_invalidation_parms_t *)p;
157
bool is_transactional;
159
InvalidateDbIterate(Session *session_arg, const char *dbname_arg,
160
bool is_transactional_arg) :
161
unary_function<QueryCache *, bool>(),
162
session(session_arg), dbname(dbname_arg),
163
is_transactional(is_transactional_arg) { }
154
if (l && l->qcache_invalidate_db)
165
inline result_type operator()(argument_type handler)
156
if (l->qcache_invalidate_db(session, parms->dbname, parms->transactional))
167
if (handler->invalidate_db(session, dbname, is_transactional))
158
169
errmsg_printf(ERRMSG_LVL_ERROR,
159
170
_("qcache plugin '%s' invalidate_db() failed"),
160
(char *)plugin_name(plugin));
171
handler->getName().c_str());
167
static bool qcache_flush_iterate(Session *session, plugin_ref plugin, void *p)
179
: public unary_function<QueryCache *, bool>
169
qcache_t *l = plugin_data(plugin, qcache_t *);
171
if (p) return true; /* flush has no parameters, return failure */
183
FlushIterate(Session *session_arg) :
184
unary_function<QueryCache *, bool>(), session(session_arg) { }
173
if (l && l->qcache_flush)
186
inline result_type operator()(argument_type handler)
175
if (l->qcache_flush(session))
188
if (handler->flush(session))
177
190
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' flush() failed"),
178
(char *)plugin_name(plugin));
191
handler->getName().c_str());
198
} /* namespace query_cache */
199
} /* namespace drizzled */
201
using namespace drizzled::query_cache;
187
204
Following functions:
199
216
bool drizzle_qcache_try_fetch_and_send(Session *session, bool transactional)
202
foreach_rv= plugin_foreach(session,
203
qcache_try_fetch_and_send_iterate,
204
DRIZZLE_QCACHE_PLUGIN,
205
(void *) &transactional);
218
/* Use find_if instead of foreach so that we can collect return codes */
219
vector<QueryCache *>::iterator iter=
220
find_if(all_query_cache.begin(), all_query_cache.end(),
221
TryFetchAndSendIterate(session, transactional));
222
/* If iter is == end() here, that means that all of the plugins returned
223
* false, which in this case means they all succeeded. Since we want to
224
* return false on success, we return the value of the two being !=
226
return iter != all_query_cache.end();
209
229
bool drizzle_qcache_set(Session *session, bool transactional)
212
foreach_rv= plugin_foreach(session,
214
DRIZZLE_QCACHE_PLUGIN,
215
(void *) &transactional);
231
/* Use find_if instead of foreach so that we can collect return codes */
232
vector<QueryCache *>::iterator iter=
233
find_if(all_query_cache.begin(), all_query_cache.end(),
234
SetIterate(session, transactional));
235
/* If iter is == end() here, that means that all of the plugins returned
236
* false, which in this case means they all succeeded. Since we want to
237
* return false on success, we return the value of the two being !=
239
return iter != all_query_cache.end();
219
242
bool drizzle_qcache_invalidate_table(Session *session, bool transactional)
222
foreach_rv= plugin_foreach(session,
223
qcache_invalidate_table_iterate,
224
DRIZZLE_QCACHE_PLUGIN,
225
(void *) &transactional);
244
/* Use find_if instead of foreach so that we can collect return codes */
245
vector<QueryCache *>::iterator iter=
246
find_if(all_query_cache.begin(), all_query_cache.end(),
247
InvalidateTableIterate(session, transactional));
248
/* If iter is == end() here, that means that all of the plugins returned
249
* false, which in this case means they all succeeded. Since we want to
250
* return false on success, we return the value of the two being !=
252
return iter != all_query_cache.end();
229
255
bool drizzle_qcache_invalidate_db(Session *session, const char *dbname,
230
256
bool transactional)
233
db_invalidation_parms_t parms;
235
/* marshall the parameters */
236
parms.dbname = dbname;
237
parms.transactional = transactional;
239
foreach_rv= plugin_foreach(session,
240
qcache_invalidate_db_iterate,
241
DRIZZLE_QCACHE_PLUGIN,
258
/* Use find_if instead of foreach so that we can collect return codes */
259
vector<QueryCache *>::iterator iter=
260
find_if(all_query_cache.begin(), all_query_cache.end(),
261
InvalidateDbIterate(session, dbname, transactional));
262
/* If iter is == end() here, that means that all of the plugins returned
263
* false, which in this case means they all succeeded. Since we want to
264
* return false on success, we return the value of the two being !=
266
return iter != all_query_cache.end();
246
269
bool drizzle_qcache_flush(Session *session)
249
foreach_rv= plugin_foreach(session,
250
qcache_flush_iterate,
251
DRIZZLE_QCACHE_PLUGIN,
271
/* Use find_if instead of foreach so that we can collect return codes */
272
vector<QueryCache *>::iterator iter=
273
find_if(all_query_cache.begin(), all_query_cache.end(),
274
FlushIterate(session));
275
/* If iter is == end() here, that means that all of the plugins returned
276
* false, which in this case means they all succeeded. Since we want to
277
* return false on success, we return the value of the two being !=
279
return iter != all_query_cache.end();