~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/qcache.cc

Update from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Mark Atwood
 
4
 *  Copyright (C) 2008 Mark Atwood, Toru Maesaka
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
35
35
  {
36
36
    if (plugin->plugin->init((void *)p))
37
37
    {
38
 
      /* TRANSLATORS: The leading word "qcache" is the name
39
 
         of the plugin api, and so should not be translated. */
40
38
      errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' init() failed"),
41
 
                      plugin->name.str);
 
39
                    plugin->name.str);
42
40
      goto err;
43
41
    }
44
42
  }
57
55
  {
58
56
    if (plugin->plugin->deinit((void *)p))
59
57
    {
60
 
      /* TRANSLATORS: The leading word "qcache" is the name
61
 
         of the plugin api, and so should not be translated. */
62
58
      errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' deinit() failed"),
63
 
                      plugin->name.str);
 
59
                    plugin->name.str);
64
60
    }
65
61
  }
66
62
 
67
63
  if (p) delete p;
68
 
 
69
64
  return 0;
70
65
}
71
66
 
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.
78
 
*/
79
 
typedef struct qcache_do1_parms_st
80
 
{
81
 
  void *parm1;
82
 
  void *parm2;
83
 
} qcache_do1_parms_t;
84
 
 
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)
87
 
{
88
 
  qcache_t *l= plugin_data(plugin, qcache_t *);
89
 
  qcache_do1_parms_t *parms= (qcache_do1_parms_t *) p;
90
 
 
91
 
  /* call this loaded qcache plugin's qcache_func1 function pointer */
92
 
  if (l && l->qcache_func1)
93
 
  {
94
 
    if (l->qcache_func1(session, parms->parm1, parms->parm2))
95
 
    {
96
 
      /* TRANSLATORS: The leading word "qcache" is the name
97
 
         of the plugin api, and so should not be translated. */
98
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' do1() failed"),
99
 
                      (char *)plugin_name(plugin));
100
 
      return true;
101
 
    }
102
 
  }
103
 
  return false;
104
 
}
105
 
 
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)
109
 
{
110
 
  qcache_do1_parms_t parms;
111
 
  bool foreach_rv;
112
 
 
113
 
  /* marshall the parameters so they will fit into the foreach */
114
 
  parms.parm1= parm1;
115
 
  parms.parm2= parm2;
116
 
 
117
 
  /* call qcache_do1_iterate
118
 
     once for each loaded qcache plugin */
119
 
  foreach_rv= plugin_foreach(session,
120
 
                             qcache_do1_iterate,
121
 
                             DRIZZLE_QCACHE_PLUGIN,
122
 
                             (void *) &parms);
123
 
  return foreach_rv;
124
 
}
125
 
 
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.
132
 
*/
133
 
typedef struct qcache_do2_parms_st
134
 
{
135
 
  void *parm3;
136
 
  void *parm4;
137
 
} qcache_do2_parms_t;
138
 
 
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)
141
 
{
142
 
  qcache_t *l= plugin_data(plugin, qcache_t *);
143
 
  qcache_do2_parms_t *parms= (qcache_do2_parms_t *) p;
144
 
 
145
 
  /* call this loaded qcache plugin's qcache_func1 function pointer */
146
 
  if (l && l->qcache_func1)
147
 
  {
148
 
    if (l->qcache_func2(session, parms->parm3, parms->parm4))
149
 
    {
150
 
      /* TRANSLATORS: The leading word "qcache" is the name
151
 
         of the plugin api, and so should not be translated. */
152
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' qcache_func2() failed"),
153
 
                      (char *)plugin_name(plugin));
154
 
 
155
 
      return true;
156
 
    }
157
 
  }
158
 
  return false;
159
 
}
160
 
 
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)
164
 
{
165
 
  qcache_do2_parms_t parms;
166
 
  bool foreach_rv;
167
 
 
168
 
  /* marshall the parameters so they will fit into the foreach */
169
 
  parms.parm3= parm3;
170
 
  parms.parm4= parm4;
171
 
 
172
 
  /* call qcache_do2_iterate
173
 
     once for each loaded qcache plugin */
174
 
  foreach_rv= plugin_foreach(session,
175
 
                             qcache_do2_iterate,
176
 
                             DRIZZLE_QCACHE_PLUGIN,
177
 
                             (void *) &parms);
 
67
/*
 
68
  The plugin_foreach() iterator requires that we convert all the parameters
 
69
  of a plugin API entry point into a single void pointer, plus the session.
 
70
  So we need the following structure for qcache_invalidate_db() which requires
 
71
  multiple arguments.
 
72
*/
 
73
typedef struct db_invalidation_parms
 
74
{
 
75
  const char *dbname;
 
76
  bool transactional;
 
77
} db_invalidation_parms_t;
 
78
 
 
79
 
 
80
/*
 
81
  Following functions:
 
82
 
 
83
    qcache_try_fetch_and_send_iterate();
 
84
    qcache_set_iterate();
 
85
    qcache_invalidate_table_iterate();
 
86
    qcache_invalidate_db_iterate();
 
87
    qcache_flush_iterate();
 
88
 
 
89
  are called by plugin_foreach() _once_ for each Query Cache plugin.
 
90
*/
 
91
 
 
92
static bool qcache_try_fetch_and_send_iterate(Session *session, 
 
93
                                              plugin_ref plugin, void *p)
 
94
{
 
95
  qcache_t *l= plugin_data(plugin, qcache_t *);
 
96
  bool is_transactional = (bool *)p;
 
97
 
 
98
  if (l && l->qcache_try_fetch_and_send)
 
99
  {
 
100
    if (l->qcache_try_fetch_and_send(session, is_transactional))
 
101
    {
 
102
      errmsg_printf(ERRMSG_LVL_ERROR,
 
103
                    _("qcache plugin '%s' try_fetch_and_send() failed"),
 
104
                    (char *)plugin_name(plugin));
 
105
      return true;
 
106
    }
 
107
  }
 
108
  return false;
 
109
}
 
110
 
 
111
static bool qcache_set_iterate(Session *session, plugin_ref plugin, void *p)
 
112
{
 
113
  qcache_t *l = plugin_data(plugin, qcache_t *);
 
114
  bool transactional = (bool *)p;
 
115
 
 
116
  if (l && l->qcache_set)
 
117
  {
 
118
    if (l->qcache_set(session, transactional))
 
119
    {
 
120
      errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' set() failed"),
 
121
                    (char *)plugin_name(plugin));
 
122
      return true;
 
123
    }
 
124
  }
 
125
  return false;
 
126
}
 
127
 
 
128
static bool qcache_invalidate_table_iterate(Session *session,
 
129
                                            plugin_ref plugin, void *p)
 
130
{
 
131
  qcache_t *l = plugin_data(plugin, qcache_t *);
 
132
  bool transactional = (bool *)p;
 
133
 
 
134
  if (l && l->qcache_invalidate_table)
 
135
  {
 
136
    if (l->qcache_invalidate_table(session, transactional))
 
137
    {
 
138
      errmsg_printf(ERRMSG_LVL_ERROR,
 
139
                    _("qcache plugin '%s' invalidate_table() failed"),
 
140
                    (char *)plugin_name(plugin));
 
141
      return true;
 
142
    }
 
143
  }
 
144
  return false;
 
145
}
 
146
 
 
147
static bool qcache_invalidate_db_iterate(Session *session,
 
148
                                         plugin_ref plugin, void *p)
 
149
{
 
150
  qcache_t *l = plugin_data(plugin, qcache_t *);
 
151
  db_invalidation_parms_t *parms = (db_invalidation_parms_t *)p;
 
152
 
 
153
  if (l && l->qcache_invalidate_db)
 
154
  {
 
155
    if (l->qcache_invalidate_db(session, parms->dbname, parms->transactional))
 
156
    {
 
157
      errmsg_printf(ERRMSG_LVL_ERROR,
 
158
                    _("qcache plugin '%s' invalidate_db() failed"),
 
159
                    (char *)plugin_name(plugin));
 
160
      return true;
 
161
    }
 
162
  }
 
163
  return false;
 
164
}
 
165
 
 
166
static bool qcache_flush_iterate(Session *session, plugin_ref plugin, void *p)
 
167
{
 
168
  qcache_t *l = plugin_data(plugin, qcache_t *);
 
169
  
 
170
  if (p) return true; /* flush has no parameters, return failure */
 
171
 
 
172
  if (l && l->qcache_flush)
 
173
  {
 
174
    if (l->qcache_flush(session))
 
175
    {
 
176
      errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' flush() failed"),
 
177
                    (char *)plugin_name(plugin));
 
178
      return true;
 
179
    }
 
180
  }
 
181
  return false;
 
182
}
 
183
 
 
184
 
 
185
/*
 
186
  Following functions:
 
187
 
 
188
    drizzle_qcache_try_fetch_and_send();
 
189
    drizzle_qcache_set();
 
190
    drizzle_qcache_invalidate_table();
 
191
    drizzle_qcache_invalidate_db();
 
192
    drizzle_qcache_flush();
 
193
 
 
194
  are the entry points to the query cache plugin that is called by the
 
195
  rest of the Drizzle server code.
 
196
*/
 
197
 
 
198
bool drizzle_qcache_try_fetch_and_send(Session *session, bool transactional)
 
199
{
 
200
  bool foreach_rv;
 
201
  foreach_rv= plugin_foreach(session,
 
202
                             qcache_try_fetch_and_send_iterate,
 
203
                             DRIZZLE_QCACHE_PLUGIN,
 
204
                             (void *) &transactional);
 
205
  return foreach_rv;
 
206
}
 
207
 
 
208
bool drizzle_qcache_set(Session *session, bool transactional)
 
209
{
 
210
  bool foreach_rv;
 
211
  foreach_rv= plugin_foreach(session,
 
212
                             qcache_set_iterate,
 
213
                             DRIZZLE_QCACHE_PLUGIN,
 
214
                             (void *) &transactional);
 
215
  return foreach_rv;
 
216
}
 
217
 
 
218
bool drizzle_qcache_invalidate_table(Session *session, bool transactional)
 
219
{
 
220
  bool foreach_rv;
 
221
  foreach_rv= plugin_foreach(session,
 
222
                             qcache_invalidate_table_iterate,
 
223
                             DRIZZLE_QCACHE_PLUGIN,
 
224
                             (void *) &transactional);
 
225
  return foreach_rv;
 
226
}
 
227
 
 
228
bool drizzle_qcache_invalidate_db(Session *session, const char *dbname,
 
229
                                  bool transactional)
 
230
{
 
231
  bool foreach_rv;
 
232
  db_invalidation_parms_t parms;
 
233
 
 
234
  /* marshall the parameters */
 
235
  parms.dbname = dbname;
 
236
  parms.transactional = transactional;
 
237
 
 
238
  foreach_rv= plugin_foreach(session,
 
239
                             qcache_invalidate_db_iterate,
 
240
                             DRIZZLE_QCACHE_PLUGIN,
 
241
                             (void *) &parms);
 
242
  return foreach_rv;
 
243
}
 
244
 
 
245
bool drizzle_qcache_flush(Session *session)
 
246
{
 
247
  bool foreach_rv;
 
248
  foreach_rv= plugin_foreach(session,
 
249
                             qcache_flush_iterate,
 
250
                             DRIZZLE_QCACHE_PLUGIN,
 
251
                             NULL);
178
252
  return foreach_rv;
179
253
}