~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/qcache.cc

  • Committer: Monty Taylor
  • Date: 2009-08-17 18:46:08 UTC
  • mto: (1182.1.1 staging)
  • mto: This revision was merged to the branch mainline in revision 1183.
  • Revision ID: mordred@inaugust.com-20090817184608-0b2emowpjr9m6le7
"Fixed" the deadlock test. I'd still like someone to look at what's going on here.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
#include "drizzled/plugin/query_cache.h"
22
 
#include "drizzled/plugin/registry.h"
23
 
 
24
 
#include "drizzled/gettext.h"
25
 
 
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/qcache.h>
 
22
#include <drizzled/gettext.h>
 
23
#include "drizzled/plugin_registry.h"
26
24
#include <vector>
27
25
 
28
 
class Session;
29
 
 
30
26
using namespace std;
31
27
 
32
 
namespace drizzled
33
 
{
34
 
 
35
 
vector<plugin::QueryCache *> all_query_cache;
 
28
static vector<QueryCache *> all_query_cache;
 
29
 
 
30
void add_query_cache(QueryCache *handler)
 
31
{
 
32
  all_query_cache.push_back(handler);
 
33
}
 
34
 
 
35
void remove_query_cache(QueryCache *handler)
 
36
{
 
37
  all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
 
38
                        handler));
 
39
}
 
40
 
 
41
 
36
42
 
37
43
/* Namespaces are here to prevent global symbol clashes with these classes */
38
44
 
 
45
namespace drizzled {
 
46
namespace query_cache {
 
47
 
39
48
class TryFetchAndSendIterate
40
 
 : public unary_function<plugin::QueryCache *, bool>
 
49
 : public unary_function<QueryCache *, bool>
41
50
{
42
51
  Session *session;
43
52
  bool is_transactional;
44
53
public:
45
54
  TryFetchAndSendIterate(Session *session_arg, bool is_transactional_arg) :
46
 
    unary_function<plugin::QueryCache *, bool>(),
 
55
    unary_function<QueryCache *, bool>(),
47
56
    session(session_arg), is_transactional(is_transactional_arg) { }
48
57
 
49
58
  inline result_type operator()(argument_type handler)
50
59
  {
51
 
    if (handler->tryFetchAndSend(session, is_transactional))
 
60
    if (handler->try_fetch_and_send(session, is_transactional))
52
61
    {
53
62
      errmsg_printf(ERRMSG_LVL_ERROR,
54
63
                    _("qcache plugin '%s' try_fetch_and_send() failed"),
60
69
};
61
70
 
62
71
class SetIterate
63
 
 : public unary_function<plugin::QueryCache *, bool>
 
72
 : public unary_function<QueryCache *, bool>
64
73
{
65
74
  Session *session;
66
75
  bool is_transactional;
67
76
public:
68
77
  SetIterate(Session *session_arg, bool is_transactional_arg) :
69
 
    unary_function<plugin::QueryCache *, bool>(),
 
78
    unary_function<QueryCache *, bool>(),
70
79
    session(session_arg), is_transactional(is_transactional_arg) { }
71
80
 
72
81
  inline result_type operator()(argument_type handler)
83
92
};
84
93
 
85
94
class InvalidateTableIterate
86
 
 : public unary_function<plugin::QueryCache *, bool>
 
95
 : public unary_function<QueryCache *, bool>
87
96
{
88
97
  Session *session;
89
98
  bool is_transactional;
90
99
public:
91
100
  InvalidateTableIterate(Session *session_arg, bool is_transactional_arg) :
92
 
    unary_function<plugin::QueryCache *, bool>(),
 
101
    unary_function<QueryCache *, bool>(),
93
102
    session(session_arg), is_transactional(is_transactional_arg) { }
94
103
 
95
104
  inline result_type operator()(argument_type handler)
96
105
  {
97
106
 
98
 
    if (handler->invalidateTable(session, is_transactional))
 
107
    if (handler->invalidate_table(session, is_transactional))
99
108
    {
100
109
      errmsg_printf(ERRMSG_LVL_ERROR,
101
 
                    _("qcache plugin '%s' invalidateTable() failed"),
 
110
                    _("qcache plugin '%s' invalidate_table() failed"),
102
111
                    handler->getName().c_str());
103
112
      return true;
104
113
    }
108
117
 
109
118
 
110
119
class InvalidateDbIterate
111
 
 : public unary_function<plugin::QueryCache *, bool>
 
120
 : public unary_function<QueryCache *, bool>
112
121
{
113
122
  Session *session;
114
123
  const char *dbname;
116
125
public:
117
126
  InvalidateDbIterate(Session *session_arg, const char *dbname_arg,
118
127
                      bool is_transactional_arg) :
119
 
    unary_function<plugin::QueryCache *, bool>(),
 
128
    unary_function<QueryCache *, bool>(),
120
129
    session(session_arg), dbname(dbname_arg),
121
130
    is_transactional(is_transactional_arg) { }
122
131
 
123
132
  inline result_type operator()(argument_type handler)
124
133
  {
125
 
    if (handler->invalidateDb(session, dbname, is_transactional))
 
134
    if (handler->invalidate_db(session, dbname, is_transactional))
126
135
    {
127
136
      errmsg_printf(ERRMSG_LVL_ERROR,
128
 
                    _("qcache plugin '%s' invalidateDb() failed"),
 
137
                    _("qcache plugin '%s' invalidate_db() failed"),
129
138
                    handler->getName().c_str());
130
139
      return true;
131
140
    }
134
143
};
135
144
 
136
145
class FlushIterate
137
 
 : public unary_function<plugin::QueryCache *, bool>
 
146
 : public unary_function<QueryCache *, bool>
138
147
{
139
148
  Session *session;
140
149
public:
141
150
  FlushIterate(Session *session_arg) :
142
 
    unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
 
151
    unary_function<QueryCache *, bool>(), session(session_arg) { }
143
152
 
144
153
  inline result_type operator()(argument_type handler)
145
154
  {
153
162
  }
154
163
};
155
164
 
156
 
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
157
 
{
158
 
  all_query_cache.push_back(handler);
159
 
  return false;
160
 
}
161
 
 
162
 
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
163
 
{
164
 
  all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
165
 
                        handler));
166
 
}
167
 
 
168
 
 
169
 
bool plugin::QueryCache::tryFetchAndSendDo(Session *session,
170
 
                                           bool transactional)
 
165
/*
 
166
  Following functions:
 
167
 
 
168
    try_fetch_and_send();
 
169
    set();
 
170
    invalidate_table();
 
171
    invalidate_db();
 
172
    flush();
 
173
 
 
174
  are the entry points to the query cache plugin that is called by the
 
175
  rest of the Drizzle server code.
 
176
*/
 
177
 
 
178
bool try_fetch_and_send(Session *session, bool transactional)
171
179
{
172
180
  /* Use find_if instead of foreach so that we can collect return codes */
173
 
  vector<plugin::QueryCache *>::iterator iter=
 
181
  vector<QueryCache *>::iterator iter=
174
182
    find_if(all_query_cache.begin(), all_query_cache.end(),
175
183
            TryFetchAndSendIterate(session, transactional));
176
184
  /* If iter is == end() here, that means that all of the plugins returned
180
188
  return iter != all_query_cache.end();
181
189
}
182
190
 
183
 
bool plugin::QueryCache::setDo(Session *session, bool transactional)
 
191
bool set(Session *session, bool transactional)
184
192
{
185
193
  /* Use find_if instead of foreach so that we can collect return codes */
186
 
  vector<plugin::QueryCache *>::iterator iter=
 
194
  vector<QueryCache *>::iterator iter=
187
195
    find_if(all_query_cache.begin(), all_query_cache.end(),
188
196
            SetIterate(session, transactional));
189
197
  /* If iter is == end() here, that means that all of the plugins returned
193
201
  return iter != all_query_cache.end();
194
202
}
195
203
 
196
 
bool plugin::QueryCache::invalidateTableDo(Session *session,
 
204
bool invalidate_table(Session *session, bool transactional)
 
205
{
 
206
  /* Use find_if instead of foreach so that we can collect return codes */
 
207
  vector<QueryCache *>::iterator iter=
 
208
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
209
            InvalidateTableIterate(session, transactional));
 
210
  /* If iter is == end() here, that means that all of the plugins returned
 
211
   * false, which in this case means they all succeeded. Since we want to 
 
212
   * return false on success, we return the value of the two being != 
 
213
   */
 
214
  return iter != all_query_cache.end();
 
215
}
 
216
 
 
217
bool invalidate_db(Session *session, const char *dbname,
197
218
                                         bool transactional)
198
219
{
199
220
  /* 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 != 
206
 
   */
207
 
  return iter != all_query_cache.end();
208
 
}
209
 
 
210
 
bool plugin::QueryCache::invalidateDbDo(Session *session, const char *dbname,
211
 
                                        bool transactional)
212
 
{
213
 
  /* Use find_if instead of foreach so that we can collect return codes */
214
 
  vector<plugin::QueryCache *>::iterator iter=
 
221
  vector<QueryCache *>::iterator iter=
215
222
    find_if(all_query_cache.begin(), all_query_cache.end(),
216
223
            InvalidateDbIterate(session, dbname, transactional));
217
224
  /* If iter is == end() here, that means that all of the plugins returned
221
228
  return iter != all_query_cache.end();
222
229
}
223
230
 
224
 
bool plugin::QueryCache::flushDo(Session *session)
 
231
bool flush(Session *session)
225
232
{
226
233
  /* Use find_if instead of foreach so that we can collect return codes */
227
 
  vector<plugin::QueryCache *>::iterator iter=
 
234
  vector<QueryCache *>::iterator iter=
228
235
    find_if(all_query_cache.begin(), all_query_cache.end(),
229
236
            FlushIterate(session));
230
237
  /* If iter is == end() here, that means that all of the plugins returned
234
241
  return iter != all_query_cache.end();
235
242
}
236
243
 
 
244
} /* namespace query_cache */
237
245
} /* namespace drizzled */
 
246