17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "drizzled/plugin/query_cache.h"
22
#include "drizzled/plugin/registry.h"
24
#include "drizzled/gettext.h"
35
vector<plugin::QueryCache *> all_query_cache;
37
/* Namespaces are here to prevent global symbol clashes with these classes */
39
class TryFetchAndSendIterate
40
: public unary_function<plugin::QueryCache *, bool>
43
bool is_transactional;
45
TryFetchAndSendIterate(Session *session_arg, bool is_transactional_arg) :
46
unary_function<plugin::QueryCache *, bool>(),
47
session(session_arg), is_transactional(is_transactional_arg) { }
49
inline result_type operator()(argument_type handler)
51
if (handler->tryFetchAndSend(session, is_transactional))
53
errmsg_printf(ERRMSG_LVL_ERROR,
54
_("qcache plugin '%s' try_fetch_and_send() failed"),
55
handler->getName().c_str());
63
: public unary_function<plugin::QueryCache *, bool>
66
bool is_transactional;
68
SetIterate(Session *session_arg, bool is_transactional_arg) :
69
unary_function<plugin::QueryCache *, bool>(),
70
session(session_arg), is_transactional(is_transactional_arg) { }
72
inline result_type operator()(argument_type handler)
75
if (handler->set(session, is_transactional))
77
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' set() failed"),
78
handler->getName().c_str());
85
class InvalidateTableIterate
86
: public unary_function<plugin::QueryCache *, bool>
89
bool is_transactional;
91
InvalidateTableIterate(Session *session_arg, bool is_transactional_arg) :
92
unary_function<plugin::QueryCache *, bool>(),
93
session(session_arg), is_transactional(is_transactional_arg) { }
95
inline result_type operator()(argument_type handler)
98
if (handler->invalidateTable(session, is_transactional))
100
errmsg_printf(ERRMSG_LVL_ERROR,
101
_("qcache plugin '%s' invalidateTable() failed"),
102
handler->getName().c_str());
110
class InvalidateDbIterate
111
: public unary_function<plugin::QueryCache *, bool>
115
bool is_transactional;
117
InvalidateDbIterate(Session *session_arg, const char *dbname_arg,
118
bool is_transactional_arg) :
119
unary_function<plugin::QueryCache *, bool>(),
120
session(session_arg), dbname(dbname_arg),
121
is_transactional(is_transactional_arg) { }
123
inline result_type operator()(argument_type handler)
125
if (handler->invalidateDb(session, dbname, is_transactional))
127
errmsg_printf(ERRMSG_LVL_ERROR,
128
_("qcache plugin '%s' invalidateDb() failed"),
129
handler->getName().c_str());
137
: public unary_function<plugin::QueryCache *, bool>
141
FlushIterate(Session *session_arg) :
142
unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
144
inline result_type operator()(argument_type handler)
146
if (handler->flush(session))
148
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' flush() failed"),
149
handler->getName().c_str());
156
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
158
all_query_cache.push_back(handler);
162
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
164
all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
169
bool plugin::QueryCache::tryFetchAndSendDo(Session *session,
172
/* Use find_if instead of foreach so that we can collect return codes */
173
vector<plugin::QueryCache *>::iterator iter=
174
find_if(all_query_cache.begin(), all_query_cache.end(),
175
TryFetchAndSendIterate(session, transactional));
176
/* If iter is == end() here, that means that all of the plugins returned
177
* false, which in this case means they all succeeded. Since we want to
178
* return false on success, we return the value of the two being !=
180
return iter != all_query_cache.end();
183
bool plugin::QueryCache::setDo(Session *session, bool transactional)
185
/* Use find_if instead of foreach so that we can collect return codes */
186
vector<plugin::QueryCache *>::iterator iter=
187
find_if(all_query_cache.begin(), all_query_cache.end(),
188
SetIterate(session, transactional));
189
/* If iter is == end() here, that means that all of the plugins returned
190
* false, which in this case means they all succeeded. Since we want to
191
* return false on success, we return the value of the two being !=
193
return iter != all_query_cache.end();
196
bool plugin::QueryCache::invalidateTableDo(Session *session,
199
/* Use find_if instead of foreach so that we can collect return codes */
200
vector<plugin::QueryCache *>::iterator iter=
201
find_if(all_query_cache.begin(), all_query_cache.end(),
202
InvalidateTableIterate(session, transactional));
203
/* If iter is == end() here, that means that all of the plugins returned
204
* false, which in this case means they all succeeded. Since we want to
205
* return false on success, we return the value of the two being !=
207
return iter != all_query_cache.end();
210
bool plugin::QueryCache::invalidateDbDo(Session *session, const char *dbname,
213
/* Use find_if instead of foreach so that we can collect return codes */
214
vector<plugin::QueryCache *>::iterator iter=
215
find_if(all_query_cache.begin(), all_query_cache.end(),
216
InvalidateDbIterate(session, dbname, transactional));
217
/* If iter is == end() here, that means that all of the plugins returned
218
* false, which in this case means they all succeeded. Since we want to
219
* return false on success, we return the value of the two being !=
221
return iter != all_query_cache.end();
224
bool plugin::QueryCache::flushDo(Session *session)
226
/* Use find_if instead of foreach so that we can collect return codes */
227
vector<plugin::QueryCache *>::iterator iter=
228
find_if(all_query_cache.begin(), all_query_cache.end(),
229
FlushIterate(session));
230
/* If iter is == end() here, that means that all of the plugins returned
231
* false, which in this case means they all succeeded. Since we want to
232
* return false on success, we return the value of the two being !=
234
return iter != all_query_cache.end();
237
} /* namespace drizzled */
20
#include <drizzled/server_includes.h>
21
#include <drizzled/qcache.h>
22
#include <drizzled/gettext.h>
24
int qcache_initializer(st_plugin_int *plugin)
28
p= (qcache_t *) malloc(sizeof(qcache_t));
29
if (p == NULL) return 1;
30
memset(p, 0, sizeof(qcache_t));
32
plugin->data= (void *)p;
34
if (plugin->plugin->init)
36
if (plugin->plugin->init((void *)p))
38
/* TRANSLATORS: The leading word "qcache" is the name
39
of the plugin api, and so should not be translated. */
40
sql_print_error(_("qcache plugin '%s' init() failed"),
52
int qcache_finalizer(st_plugin_int *plugin)
54
qcache_t *p= (qcache_t *) plugin->data;
56
if (plugin->plugin->deinit)
58
if (plugin->plugin->deinit((void *)p))
60
/* TRANSLATORS: The leading word "qcache" is the name
61
of the plugin api, and so should not be translated. */
62
sql_print_error(_("qcache plugin '%s' deinit() failed"),
72
/* The plugin_foreach() iterator requires that we
73
convert all the parameters of a plugin api entry point
74
into just one single void ptr, plus the session.
75
So we will take all the additional paramters of qcache_do1,
76
and marshall them into a struct of this type, and
77
then just pass in a pointer to it.
79
typedef struct qcache_do1_parms_st
85
/* This gets called by plugin_foreach once for each loaded qcache plugin */
86
static bool qcache_do1_iterate (Session *session, plugin_ref plugin, void *p)
88
qcache_t *l= plugin_data(plugin, qcache_t *);
89
qcache_do1_parms_t *parms= (qcache_do1_parms_t *) p;
91
/* call this loaded qcache plugin's qcache_func1 function pointer */
92
if (l && l->qcache_func1)
94
if (l->qcache_func1(session, parms->parm1, parms->parm2))
96
/* TRANSLATORS: The leading word "qcache" is the name
97
of the plugin api, and so should not be translated. */
98
sql_print_error(_("qcache plugin '%s' do1() failed"),
99
(char *)plugin_name(plugin));
106
/* This is the qcache_do1 entry point.
107
This gets called by the rest of the Drizzle server code */
108
bool qcache_do1 (Session *session, void *parm1, void *parm2)
110
qcache_do1_parms_t parms;
113
/* marshall the parameters so they will fit into the foreach */
117
/* call qcache_do1_iterate
118
once for each loaded qcache plugin */
119
foreach_rv= plugin_foreach(session,
121
DRIZZLE_QCACHE_PLUGIN,
126
/* The plugin_foreach() iterator requires that we
127
convert all the parameters of a plugin api entry point
128
into just one single void ptr, plus the session.
129
So we will take all the additional paramters of qcache_do2,
130
and marshall them into a struct of this type, and
131
then just pass in a pointer to it.
133
typedef struct qcache_do2_parms_st
137
} qcache_do2_parms_t;
139
/* This gets called by plugin_foreach once for each loaded qcache plugin */
140
static bool qcache_do2_iterate (Session *session, plugin_ref plugin, void *p)
142
qcache_t *l= plugin_data(plugin, qcache_t *);
143
qcache_do2_parms_t *parms= (qcache_do2_parms_t *) p;
145
/* call this loaded qcache plugin's qcache_func1 function pointer */
146
if (l && l->qcache_func1)
148
if (l->qcache_func2(session, parms->parm3, parms->parm4))
150
/* TRANSLATORS: The leading word "qcache" is the name
151
of the plugin api, and so should not be translated. */
152
sql_print_error(_("qcache plugin '%s' qcache_func2() failed"),
153
(char *)plugin_name(plugin));
161
/* This is the qcache_do2 entry point.
162
This gets called by the rest of the Drizzle server code */
163
bool qcache_do2 (Session *session, void *parm3, void *parm4)
165
qcache_do2_parms_t parms;
168
/* marshall the parameters so they will fit into the foreach */
172
/* call qcache_do2_iterate
173
once for each loaded qcache plugin */
174
foreach_rv= plugin_foreach(session,
176
DRIZZLE_QCACHE_PLUGIN,