1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Mark Atwood, Toru Maesaka
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; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
21
#include <drizzled/qcache.h>
22
#include <drizzled/gettext.h>
24
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
if (plugin->plugin->init)
36
if (plugin->plugin->init((void *)p))
38
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' init() failed"),
51
int qcache_finalizer(st_plugin_int *plugin)
53
qcache_t *p= (qcache_t *) plugin->data;
55
if (plugin->plugin->deinit)
57
if (plugin->plugin->deinit((void *)p))
59
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)
101
if (l->qcache_try_fetch_and_send(session, is_transactional))
103
errmsg_printf(ERRMSG_LVL_ERROR,
104
_("qcache plugin '%s' try_fetch_and_send() failed"),
105
(char *)plugin_name(plugin));
112
static bool qcache_set_iterate(Session *session, plugin_ref plugin, void *p)
114
qcache_t *l = plugin_data(plugin, qcache_t *);
115
bool transactional = (bool *)p;
117
if (l && l->qcache_set)
119
if (l->qcache_set(session, transactional))
121
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' set() failed"),
122
(char *)plugin_name(plugin));
129
static bool qcache_invalidate_table_iterate(Session *session,
130
plugin_ref plugin, void *p)
132
qcache_t *l = plugin_data(plugin, qcache_t *);
133
bool transactional = (bool *)p;
135
if (l && l->qcache_invalidate_table)
137
if (l->qcache_invalidate_table(session, transactional))
139
errmsg_printf(ERRMSG_LVL_ERROR,
140
_("qcache plugin '%s' invalidate_table() failed"),
141
(char *)plugin_name(plugin));
148
static bool qcache_invalidate_db_iterate(Session *session,
149
plugin_ref plugin, void *p)
151
qcache_t *l = plugin_data(plugin, qcache_t *);
152
db_invalidation_parms_t *parms = (db_invalidation_parms_t *)p;
154
if (l && l->qcache_invalidate_db)
156
if (l->qcache_invalidate_db(session, parms->dbname, parms->transactional))
158
errmsg_printf(ERRMSG_LVL_ERROR,
159
_("qcache plugin '%s' invalidate_db() failed"),
160
(char *)plugin_name(plugin));
167
static bool qcache_flush_iterate(Session *session, plugin_ref plugin, void *p)
169
qcache_t *l = plugin_data(plugin, qcache_t *);
171
if (p) return true; /* flush has no parameters, return failure */
173
if (l && l->qcache_flush)
175
if (l->qcache_flush(session))
177
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' flush() failed"),
178
(char *)plugin_name(plugin));
189
drizzle_qcache_try_fetch_and_send();
190
drizzle_qcache_set();
191
drizzle_qcache_invalidate_table();
192
drizzle_qcache_invalidate_db();
193
drizzle_qcache_flush();
195
are the entry points to the query cache plugin that is called by the
196
rest of the Drizzle server code.
199
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);
209
bool drizzle_qcache_set(Session *session, bool transactional)
212
foreach_rv= plugin_foreach(session,
214
DRIZZLE_QCACHE_PLUGIN,
215
(void *) &transactional);
219
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);
229
bool drizzle_qcache_invalidate_db(Session *session, const char *dbname,
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,
246
bool drizzle_qcache_flush(Session *session)
249
foreach_rv= plugin_foreach(session,
250
qcache_flush_iterate,
251
DRIZZLE_QCACHE_PLUGIN,