~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/plugin/query_cache.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *  Copyright (C) 2010 Djellel Eddine Difallah
5
6
 *
6
7
 *  This program is free software; you can redistribute it and/or modify
7
8
 *  it under the terms of the GNU General Public License as published by
19
20
 
20
21
#include "config.h"
21
22
#include "drizzled/plugin/query_cache.h"
22
 
#include "drizzled/plugin/registry.h"
 
23
#include "drizzled/errmsg_print.h"
23
24
 
24
25
#include "drizzled/gettext.h"
25
26
 
 
27
#include <algorithm>
26
28
#include <vector>
27
29
 
28
30
class Session;
31
33
 
32
34
namespace drizzled
33
35
{
34
 
 
35
 
vector<plugin::QueryCache *> all_query_cache;
 
36
typedef vector<plugin::QueryCache *> QueryCaches;
 
37
QueryCaches all_query_cache;
36
38
 
37
39
/* Namespaces are here to prevent global symbol clashes with these classes */
38
40
 
39
 
class TryFetchAndSendIterate
40
 
 : public unary_function<plugin::QueryCache *, bool>
41
 
{
42
 
  Session *session;
43
 
  bool is_transactional;
44
 
public:
45
 
  TryFetchAndSendIterate(Session *session_arg, bool is_transactional_arg) :
46
 
    unary_function<plugin::QueryCache *, bool>(),
47
 
    session(session_arg), is_transactional(is_transactional_arg) { }
48
 
 
49
 
  inline result_type operator()(argument_type handler)
50
 
  {
51
 
    if (handler->tryFetchAndSend(session, is_transactional))
52
 
    {
53
 
      errmsg_printf(ERRMSG_LVL_ERROR,
54
 
                    _("qcache plugin '%s' try_fetch_and_send() failed"),
55
 
                    handler->getName().c_str());
56
 
      return true;
57
 
    }
58
 
    return false;
59
 
  }
60
 
};
61
 
 
62
 
class SetIterate
63
 
 : public unary_function<plugin::QueryCache *, bool>
64
 
{
65
 
  Session *session;
66
 
  bool is_transactional;
67
 
public:
68
 
  SetIterate(Session *session_arg, bool is_transactional_arg) :
69
 
    unary_function<plugin::QueryCache *, bool>(),
70
 
    session(session_arg), is_transactional(is_transactional_arg) { }
71
 
 
72
 
  inline result_type operator()(argument_type handler)
73
 
  {
74
 
 
75
 
    if (handler->set(session, is_transactional))
76
 
    {
77
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' set() failed"),
78
 
                    handler->getName().c_str());
79
 
      return true;
80
 
    }
81
 
    return false;
82
 
  }
83
 
};
84
 
 
85
 
class InvalidateTableIterate
86
 
 : public unary_function<plugin::QueryCache *, bool>
87
 
{
88
 
  Session *session;
89
 
  bool is_transactional;
90
 
public:
91
 
  InvalidateTableIterate(Session *session_arg, bool is_transactional_arg) :
92
 
    unary_function<plugin::QueryCache *, bool>(),
93
 
    session(session_arg), is_transactional(is_transactional_arg) { }
94
 
 
95
 
  inline result_type operator()(argument_type handler)
96
 
  {
97
 
 
98
 
    if (handler->invalidateTable(session, is_transactional))
99
 
    {
100
 
      errmsg_printf(ERRMSG_LVL_ERROR,
101
 
                    _("qcache plugin '%s' invalidateTable() failed"),
102
 
                    handler->getName().c_str());
103
 
      return true;
104
 
    }
105
 
    return false;
106
 
  }
107
 
};
108
 
 
109
 
 
110
 
class InvalidateDbIterate
111
 
 : public unary_function<plugin::QueryCache *, bool>
112
 
{
113
 
  Session *session;
114
 
  const char *dbname;
115
 
  bool is_transactional;
116
 
public:
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) { }
122
 
 
123
 
  inline result_type operator()(argument_type handler)
124
 
  {
125
 
    if (handler->invalidateDb(session, dbname, is_transactional))
126
 
    {
127
 
      errmsg_printf(ERRMSG_LVL_ERROR,
128
 
                    _("qcache plugin '%s' invalidateDb() failed"),
129
 
                    handler->getName().c_str());
130
 
      return true;
131
 
    }
132
 
    return false;
133
 
  }
134
 
};
135
 
 
136
 
class FlushIterate
137
 
 : public unary_function<plugin::QueryCache *, bool>
138
 
{
139
 
  Session *session;
140
 
public:
141
 
  FlushIterate(Session *session_arg) :
 
41
class IsCachedIterate
 
42
 : public unary_function<plugin::QueryCache *, bool>
 
43
{
 
44
  Session *session;
 
45
public:
 
46
  IsCachedIterate(Session* session_arg) :
 
47
    unary_function<plugin::QueryCache *, bool>(),
 
48
    session(session_arg) { }
 
49
 
 
50
  inline result_type operator()(argument_type handler)
 
51
  {
 
52
    return handler->doIsCached(session);
 
53
  }
 
54
};
 
55
 
 
56
bool plugin::QueryCache::isCached(Session *session)
 
57
{
 
58
  /* Use find_if instead of foreach so that we can collect return codes */
 
59
  QueryCaches::iterator iter=
 
60
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
61
            IsCachedIterate(session));
 
62
  /* If iter is == end() here, that means that all of the plugins returned
 
63
   * false, which in this case means they all succeeded. Since we want to 
 
64
   * return false on success, we return the value of the two being != 
 
65
   */
 
66
  return iter != all_query_cache.end();
 
67
}
 
68
 
 
69
 
 
70
class SendCachedResultsetIterate
 
71
 : public unary_function<plugin::QueryCache *, bool>
 
72
{
 
73
  Session *session;
 
74
public:
 
75
  SendCachedResultsetIterate(Session *session_arg) :
 
76
    unary_function<plugin::QueryCache *, bool>(),
 
77
    session(session_arg) { }
 
78
 
 
79
  inline result_type operator()(argument_type handler)
 
80
  {
 
81
    return handler->doSendCachedResultset(session);
 
82
  }
 
83
};
 
84
bool plugin::QueryCache::sendCachedResultset(Session *session)
 
85
{
 
86
  /* Use find_if instead of foreach so that we can collect return codes */
 
87
  QueryCaches::iterator iter=
 
88
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
89
            SendCachedResultsetIterate(session));
 
90
  /* If iter is == end() here, that means that all of the plugins returned
 
91
   * false, which in this case means they all succeeded. Since we want to 
 
92
   * return false on success, we return the value of the two being != 
 
93
   */
 
94
  return iter != all_query_cache.end();
 
95
}
 
96
 
 
97
class PrepareResultsetIterate
 
98
 : public unary_function<plugin::QueryCache *, bool>
 
99
{
 
100
  Session *session;
 
101
public:
 
102
  PrepareResultsetIterate(Session *session_arg) :
142
103
    unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
143
104
 
144
105
  inline result_type operator()(argument_type handler)
145
106
  {
146
 
    if (handler->flush(session))
147
 
    {
148
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' flush() failed"),
149
 
                    handler->getName().c_str());
150
 
      return true;
151
 
    }
152
 
    return false;
153
 
  }
154
 
};
 
107
    return handler->doPrepareResultset(session);
 
108
  }
 
109
};
 
110
bool plugin::QueryCache::prepareResultset(Session *session)
 
111
{
 
112
  /* Use find_if instead of foreach so that we can collect return codes */
 
113
  QueryCaches::iterator iter=
 
114
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
115
            PrepareResultsetIterate(session));
 
116
  /* If iter is == end() here, that means that all of the plugins returned
 
117
   * false, which in this case means they all succeeded. Since we want to 
 
118
   * return false on success, we return the value of the two being != 
 
119
   */
 
120
  return iter != all_query_cache.end();
 
121
}
 
122
 
 
123
class SetResultsetIterate
 
124
 : public unary_function<plugin::QueryCache *, bool>
 
125
{
 
126
  Session *session;
 
127
public:
 
128
  SetResultsetIterate(Session *session_arg) :
 
129
    unary_function<plugin::QueryCache *, bool>(),
 
130
    session(session_arg) { }
 
131
 
 
132
  inline result_type operator()(argument_type handler)
 
133
  {
 
134
    return handler->doSetResultset(session);
 
135
  }
 
136
};
 
137
 
 
138
bool plugin::QueryCache::setResultset(Session *session)
 
139
{
 
140
  /* Use find_if instead of foreach so that we can collect return codes */
 
141
  QueryCaches::iterator iter=
 
142
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
143
            SetResultsetIterate(session));
 
144
  /* If iter is == end() here, that means that all of the plugins returned
 
145
   * false, which in this case means they all succeeded. Since we want to 
 
146
   * return false on success, we return the value of the two being != 
 
147
   */
 
148
  return iter != all_query_cache.end();
 
149
}
 
150
 
 
151
class InsertRecordIterate
 
152
 : public unary_function<plugin::QueryCache *, bool>
 
153
{
 
154
  Session *session;
 
155
  List<Item> &item;
 
156
public:
 
157
  InsertRecordIterate(Session *session_arg, List<Item> &item_arg) :
 
158
    unary_function<plugin::QueryCache *, bool>(),
 
159
    session(session_arg), item(item_arg) { }
 
160
 
 
161
  inline result_type operator()(argument_type handler)
 
162
  {
 
163
    return handler->doInsertRecord(session, item);
 
164
  }
 
165
};
 
166
bool plugin::QueryCache::insertRecord(Session *session, List<Item> &items)
 
167
{
 
168
  /* Use find_if instead of foreach so that we can collect return codes */
 
169
  QueryCaches::iterator iter=
 
170
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
171
            InsertRecordIterate(session, items));
 
172
  /* If iter is == end() here, that means that all of the plugins returned
 
173
   * false, which in this case means they all succeeded. Since we want to 
 
174
   * return false on success, we return the value of the two being != 
 
175
   */
 
176
  return iter != all_query_cache.end();
 
177
}
 
178
 
 
179
 
155
180
 
156
181
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
157
182
{
165
190
                        handler));
166
191
}
167
192
 
168
 
 
169
 
bool plugin::QueryCache::tryFetchAndSendDo(Session *session,
170
 
                                           bool transactional)
171
 
{
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 != 
179
 
   */
180
 
  return iter != all_query_cache.end();
181
 
}
182
 
 
183
 
bool plugin::QueryCache::setDo(Session *session, bool transactional)
184
 
{
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 != 
192
 
   */
193
 
  return iter != all_query_cache.end();
194
 
}
195
 
 
196
 
bool plugin::QueryCache::invalidateTableDo(Session *session,
197
 
                                         bool transactional)
198
 
{
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 != 
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=
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 != 
220
 
   */
221
 
  return iter != all_query_cache.end();
222
 
}
223
 
 
224
 
bool plugin::QueryCache::flushDo(Session *session)
225
 
{
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 != 
233
 
   */
234
 
  return iter != all_query_cache.end();
235
 
}
236
 
 
237
193
} /* namespace drizzled */