~drizzle-trunk/drizzle/development

1643.6.2 by Djellel E. Difallah
Added the Query Cache Plugin for Memcached
1
/* 
2
 * Copyright (c) 2010, Djellel Eddine Difallah
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 *   * Redistributions of source code must retain the above copyright notice,
9
 *     this list of conditions and the following disclaimer.
10
 *   * Redistributions in binary form must reproduce the above copyright notice,
11
 *     this list of conditions and the following disclaimer in the documentation
12
 *     and/or other materials provided with the distribution.
1643.6.11 by Djellel E. Difallah
trunk merge
13
 *   * Neither the name of Djellel Eddine Difallah nor the names of its contributors
1643.6.2 by Djellel E. Difallah
Added the Query Cache Plugin for Memcached
14
 *     may be used to endorse or promote products derived from this software
15
 *     without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27
 * THE POSSIBILITY OF SUCH DAMAGE.
28
 */
1643.6.17 by Djellel E. Difallah
fix the header guards
29
#ifndef PLUGIN_MEMCACHED_QUERY_CACHE_MEMCACHED_QC_H
30
#define PLUGIN_MEMCACHED_QUERY_CACHE_MEMCACHED_QC_H
1643.6.2 by Djellel E. Difallah
Added the Query Cache Plugin for Memcached
31
32
#include "drizzled/plugin/query_cache.h"
1643.6.3 by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query
33
#include "query_cache_service.h"
34
#include "drizzled/atomics.h"
1643.6.2 by Djellel E. Difallah
Added the Query Cache Plugin for Memcached
35
#include <libmemcached/memcached.hpp>
36
37
namespace drizzled 
38
{
39
  class Session;
40
  class select_result;
41
  class String;
1643.6.13 by Djellel E. Difallah
adding tests
42
  class TableList;
1643.6.2 by Djellel E. Difallah
Added the Query Cache Plugin for Memcached
43
}
1643.6.10 by Djellel E. Difallah
plugin options
44
class MemcachedQueryCache : public drizzled::plugin::QueryCache
1643.6.2 by Djellel E. Difallah
Added the Query Cache Plugin for Memcached
45
{
1643.6.3 by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query
46
private:
47
  pthread_mutex_t mutex;  
48
  drizzled::QueryCacheService queryCacheService;
1643.6.10 by Djellel E. Difallah
plugin options
49
  static memcache::Memcache* client;
1643.6.11 by Djellel E. Difallah
trunk merge
50
  static std::string memcached_servers;
1643.7.1 by Monty Taylor
First stab at reworking memcached_servers.
51
1643.6.2 by Djellel E. Difallah
Added the Query Cache Plugin for Memcached
52
public:
1643.6.10 by Djellel E. Difallah
plugin options
53
  
1643.6.17 by Djellel E. Difallah
fix the header guards
54
  explicit MemcachedQueryCache(std::string name_arg, const std::string &servers_arg): drizzled::plugin::QueryCache(name_arg)
1643.6.2 by Djellel E. Difallah
Added the Query Cache Plugin for Memcached
55
  {
1643.6.10 by Djellel E. Difallah
plugin options
56
    client= new memcache::Memcache(servers_arg);
1643.6.16 by Djellel E. Difallah
Fixing memory leaks
57
    pthread_mutex_init(&mutex, NULL);
1643.6.3 by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query
58
    queryCacheService= drizzled::QueryCacheService::singleton();
1643.6.2 by Djellel E. Difallah
Added the Query Cache Plugin for Memcached
59
  }
1643.6.14 by Djellel E. Difallah
Added the Table Based Invalidation and its test suite
60
  ~MemcachedQueryCache()
61
  {
1643.6.16 by Djellel E. Difallah
Fixing memory leaks
62
    delete client;
63
    pthread_mutex_destroy(&mutex);
1643.6.14 by Djellel E. Difallah
Added the Table Based Invalidation and its test suite
64
  };
1643.6.3 by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query
65
  bool doIsCached(drizzled::Session *session);
66
  bool doSendCachedResultset(drizzled::Session *session);
67
  bool doPrepareResultset(drizzled::Session *session);
68
  bool doInsertRecord(drizzled::Session *session, drizzled::List<drizzled::Item> &item);
69
  bool doSetResultset(drizzled::Session *session);
1643.6.2 by Djellel E. Difallah
Added the Query Cache Plugin for Memcached
70
  char* md5_key(const char* str);
1643.6.14 by Djellel E. Difallah
Added the Table Based Invalidation and its test suite
71
  void checkTables(drizzled::Session *session, drizzled::TableList* in_table);
1643.6.3 by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query
72
  bool isSelect(std::string query);
1643.6.10 by Djellel E. Difallah
plugin options
73
  static memcache::Memcache* getClient()
74
  {
75
    return client;
76
  }
1643.7.1 by Monty Taylor
First stab at reworking memcached_servers.
77
  static const char *getServers()
78
  {
79
    return memcached_servers.c_str();
80
  }
1643.6.17 by Djellel E. Difallah
fix the header guards
81
  static void setServers(const std::string &server_list)
1643.7.1 by Monty Taylor
First stab at reworking memcached_servers.
82
  {
83
    memcached_servers.assign(server_list);
1643.6.17 by Djellel E. Difallah
fix the header guards
84
    //getClient()->setServers(server_list);
1643.7.1 by Monty Taylor
First stab at reworking memcached_servers.
85
  }
86
1643.6.2 by Djellel E. Difallah
Added the Query Cache Plugin for Memcached
87
};
1643.6.17 by Djellel E. Difallah
fix the header guards
88
#endif /* PLUGIN_MEMCACHED_QUERY_CACHE_MEMCACHED_QC_H */