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"),
43
plugin->state= PLUGIN_IS_READY;
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
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' deinit() failed"),
70
The plugin_foreach() iterator requires that we convert all the parameters
71
of a plugin API entry point into a single void pointer, plus the session.
72
So we need the following structure for qcache_invalidate_db() which requires
75
typedef struct db_invalidation_parms
79
} db_invalidation_parms_t;
85
qcache_try_fetch_and_send_iterate();
87
qcache_invalidate_table_iterate();
88
qcache_invalidate_db_iterate();
89
qcache_flush_iterate();
91
are called by plugin_foreach() _once_ for each Query Cache plugin.
94
static bool qcache_try_fetch_and_send_iterate(Session *session,
95
plugin_ref plugin, void *p)
97
qcache_t *l= plugin_data(plugin, qcache_t *);
98
bool is_transactional = (bool *)p;
100
if (l && l->qcache_try_fetch_and_send)
102
if (l->qcache_try_fetch_and_send(session, is_transactional))
104
errmsg_printf(ERRMSG_LVL_ERROR,
105
_("qcache plugin '%s' try_fetch_and_send() failed"),
106
(char *)plugin_name(plugin));
113
static bool qcache_set_iterate(Session *session, plugin_ref plugin, void *p)
115
qcache_t *l = plugin_data(plugin, qcache_t *);
116
bool transactional = (bool *)p;
118
if (l && l->qcache_set)
120
if (l->qcache_set(session, transactional))
122
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' set() failed"),
123
(char *)plugin_name(plugin));
130
static bool qcache_invalidate_table_iterate(Session *session,
131
plugin_ref plugin, void *p)
133
qcache_t *l = plugin_data(plugin, qcache_t *);
134
bool transactional = (bool *)p;
136
if (l && l->qcache_invalidate_table)
138
if (l->qcache_invalidate_table(session, transactional))
140
errmsg_printf(ERRMSG_LVL_ERROR,
141
_("qcache plugin '%s' invalidate_table() failed"),
142
(char *)plugin_name(plugin));
149
static bool qcache_invalidate_db_iterate(Session *session,
150
plugin_ref plugin, void *p)
152
qcache_t *l = plugin_data(plugin, qcache_t *);
153
db_invalidation_parms_t *parms = (db_invalidation_parms_t *)p;
155
if (l && l->qcache_invalidate_db)
157
if (l->qcache_invalidate_db(session, parms->dbname, parms->transactional))
159
errmsg_printf(ERRMSG_LVL_ERROR,
160
_("qcache plugin '%s' invalidate_db() failed"),
161
(char *)plugin_name(plugin));
168
static bool qcache_flush_iterate(Session *session, plugin_ref plugin, void *p)
170
qcache_t *l = plugin_data(plugin, qcache_t *);
172
if (p) return true; /* flush has no parameters, return failure */
174
if (l && l->qcache_flush)
176
if (l->qcache_flush(session))
178
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' flush() failed"),
179
(char *)plugin_name(plugin));
190
drizzle_qcache_try_fetch_and_send();
191
drizzle_qcache_set();
192
drizzle_qcache_invalidate_table();
193
drizzle_qcache_invalidate_db();
194
drizzle_qcache_flush();
196
are the entry points to the query cache plugin that is called by the
197
rest of the Drizzle server code.
200
bool drizzle_qcache_try_fetch_and_send(Session *session, bool transactional)
203
foreach_rv= plugin_foreach(session,
204
qcache_try_fetch_and_send_iterate,
205
DRIZZLE_QCACHE_PLUGIN,
206
(void *) &transactional);
210
bool drizzle_qcache_set(Session *session, bool transactional)
213
foreach_rv= plugin_foreach(session,
215
DRIZZLE_QCACHE_PLUGIN,
216
(void *) &transactional);
220
bool drizzle_qcache_invalidate_table(Session *session, bool transactional)
223
foreach_rv= plugin_foreach(session,
224
qcache_invalidate_table_iterate,
225
DRIZZLE_QCACHE_PLUGIN,
226
(void *) &transactional);
230
bool drizzle_qcache_invalidate_db(Session *session, const char *dbname,
234
db_invalidation_parms_t parms;
236
/* marshall the parameters */
237
parms.dbname = dbname;
238
parms.transactional = transactional;
240
foreach_rv= plugin_foreach(session,
241
qcache_invalidate_db_iterate,
242
DRIZZLE_QCACHE_PLUGIN,
247
bool drizzle_qcache_flush(Session *session)
250
foreach_rv= plugin_foreach(session,
251
qcache_flush_iterate,
252
DRIZZLE_QCACHE_PLUGIN,