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_QUERY_CACHE_SERVICE_H
|
30 |
#define PLUGIN_MEMCACHED_QUERY_CACHE_QUERY_CACHE_SERVICE_H
|
|
1643.6.2
by Djellel E. Difallah
Added the Query Cache Plugin for Memcached |
31 |
|
32 |
#include "drizzled/message/resultset.pb.h" |
|
33 |
#include <drizzled/sql_list.h> |
|
34 |
#include <map> |
|
1643.6.14
by Djellel E. Difallah
Added the Table Based Invalidation and its test suite |
35 |
#include <vector> |
1643.6.2
by Djellel E. Difallah
Added the Query Cache Plugin for Memcached |
36 |
|
37 |
namespace drizzled |
|
38 |
{
|
|
1643.6.4
by Djellel E. Difallah
Added data dictionary view 'Query_cache_entries' to list current cached queries. Added a UDF print_query_cache_meta(key) to display a text representation of the metadata |
39 |
class TableList; |
40 |
class Item; |
|
41 |
||
1643.6.2
by Djellel E. Difallah
Added the Query Cache Plugin for Memcached |
42 |
namespace message |
43 |
{
|
|
1643.6.4
by Djellel E. Difallah
Added data dictionary view 'Query_cache_entries' to list current cached queries. Added a UDF print_query_cache_meta(key) to display a text representation of the metadata |
44 |
class Resultset; |
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 |
|
1643.6.2
by Djellel E. Difallah
Added the Query Cache Plugin for Memcached |
47 |
class QueryCacheService |
48 |
{
|
|
49 |
public: |
|
1643.6.14
by Djellel E. Difallah
Added the Table Based Invalidation and its test suite |
50 |
|
51 |
typedef std::map<std::string, drizzled::message::Resultset> CacheEntries; |
|
52 |
typedef std::pair<const std::string, drizzled::message::Resultset> CacheEntry; |
|
53 |
typedef std::map<std::string, std::vector<std::string>> CachedTablesEntries; |
|
54 |
typedef std::pair<const std::string, std::vector<std::string>> CachedTablesEntry; |
|
55 |
||
1643.6.2
by Djellel E. Difallah
Added the Query Cache Plugin for Memcached |
56 |
static const size_t DEFAULT_RECORD_SIZE= 100; |
1643.6.14
by Djellel E. Difallah
Added the Table Based Invalidation and its test suite |
57 |
static CacheEntries cache; |
58 |
static CachedTablesEntries cachedTables; |
|
1643.6.2
by Djellel E. Difallah
Added the Query Cache Plugin for Memcached |
59 |
|
60 |
/**
|
|
61 |
* Singleton method
|
|
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 |
62 |
* Returns the singleton instance of QueryCacheService
|
1643.6.2
by Djellel E. Difallah
Added the Query Cache Plugin for Memcached |
63 |
*/
|
64 |
static inline QueryCacheService &singleton() |
|
65 |
{
|
|
66 |
static QueryCacheService query_cache_service; |
|
67 |
return query_cache_service; |
|
68 |
};
|
|
69 |
||
70 |
/**
|
|
71 |
* Method which returns the active Resultset message
|
|
72 |
* for the supplied Session. If one is not found, a new Resultset
|
|
73 |
* message is allocated, initialized, and returned.
|
|
74 |
*
|
|
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 |
75 |
* @param The session processing the Select
|
1643.6.2
by Djellel E. Difallah
Added the Query Cache Plugin for Memcached |
76 |
*/
|
1643.6.16
by Djellel E. Difallah
Fixing memory leaks |
77 |
drizzled::message::Resultset *setCurrentResultsetMessage(drizzled::Session *in_session); |
1643.6.2
by Djellel E. Difallah
Added the Query Cache Plugin for Memcached |
78 |
|
79 |
/**
|
|
80 |
* Helper method which initializes the header message for
|
|
81 |
* a Resultset.
|
|
82 |
*
|
|
83 |
* @param[inout] Resultset message container to modify
|
|
84 |
* @param[in] Pointer to the Session doing the processing
|
|
85 |
* @param[in] Pointer to the Table being inserted into
|
|
86 |
*/
|
|
87 |
void setResultsetHeader(drizzled::message::Resultset &resultset, |
|
88 |
drizzled::Session *in_session, |
|
89 |
drizzled::TableList *in_table); |
|
90 |
/**
|
|
91 |
* Creates a new SelectRecord GPB message and pushes it to
|
|
92 |
* currrent Resultset.
|
|
93 |
*
|
|
94 |
* @param Pointer to the Session which has inserted a record
|
|
95 |
* @param Pointer to the List<Items> to add
|
|
96 |
*/
|
|
97 |
bool addRecord(drizzled::Session *in_session, drizzled::List<drizzled::Item> &list); |
|
98 |
||
99 |
/* cache fetching */
|
|
100 |
static bool isCached(std::string query); |
|
101 |
||
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 |
102 |
};
|
103 |
} /* namespace drizzled */ |
|
1643.6.17
by Djellel E. Difallah
fix the header guards |
104 |
#endif /* PLUGIN_MEMCACHED_QUERY_CACHE_QUERY_CACHE_SERVICE_H */ |