public
Fork of dustin/memcached
Description: This is where my memcached work lives before svn munges the changes.
Homepage: http://www.danga.com/memcached/
Clone URL: git://github.com/tmaesaka/memcached.git
memcached / engine.h
100644 240 lines (215 sloc) 9.101 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
* Copyright (c) <2008>, Sun Microsystems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY SUN MICROSYSTEMS, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/*
* Summary: Specification of the storage engine interface.
*
* Copy: See Copyright for the status of this software.
*
* Author: Trond Norbye <trond.norbye@sun.com>
*/
#ifndef ENGINE_H
#define ENGINE_H
 
#include <sys/types.h>
#include <stdbool.h>
 
#ifdef __cplusplus
extern "C" {
#endif
 
   typedef enum {
      ENGINE_SUCCESS = 0x00,
      ENGINE_KEY_ENOENT = 0x01,
      ENGINE_KEY_EEXISTS = 0x02,
      ENGINE_ENOMEM = 0x03,
      ENGINE_NOT_STORED = 0x04,
      ENGINE_EINVAL = 0x05,
      ENGINE_ENOTSUP = 0x06,
   } ENGINE_ERROR_CODE;
 
   typedef struct engine_handle {
      /**
* In order to allow future modifications to the interface, we need to
* store the interface version in the structure to allow the core server
* to work with multiple versions of the interface at the same time.
*/
      uint32_t interface_level;
 
      /**
* Get information about this storage engine (to use in the version
* command)
*
* @param handle Pointer to the instance.
* @return A preformatted string with the name and version of the engine
* (NOTE: Do NOT try to release this pointer).
*/
      const char* (*get_info)(struct engine_handle* handle);
 
      /**
* Initialize the instance.
* @param handle Pointer to the instance
* @param config_str pointer to a string containing configuration data
* @return 0 success, TODO specify different error codes..
*/
      ENGINE_ERROR_CODE (*initialize)(struct engine_handle* handle,
                                      const char* config_str);
 
      /**
* Destroy the instance.
*
* @param handle Pointer to the instance
*/
      void (*destroy)(struct engine_handle* handle);
 
      /**
* Test to see if this item size if allowed by the engine
*
* @param handle pointer to the instance
* @param nkey Length of the key
* @param flags The flags for the object
* @param nbytes Size of userdata
* @return true if ok, false otherwise
*/
      bool (*item_size_ok)(struct engine_handle* handle, const size_t nkey,
                           const int flags, const size_t nbytes);
 
 
      /**
* Allocate an item structure
*
* @param handle Pointer to the instance
* @param key Pointer to the key
* @param nkey Length of key
* @param flags The flags for the object
* @param exptime expiry time
* @param nbytes Total size of userdata
* @return pointer to an item or null if out of memory
*/
      item* (*item_allocate)(struct engine_handle* handle, const void* key,
                             const size_t nkey, const int flags,
                             const rel_time_t exptime, const int nbytes);
 
      /**
* Delete an item. Note that this function will release your
* handle to the item)
*
* @param handle Pointer to the instance
* @param item Pointer to the item to be deleted
* @param exptime When the item should be deleted
*/
      ENGINE_ERROR_CODE (*item_delete)(struct engine_handle* handle,
                                       item* item,
                                       const rel_time_t exptime);
 
      /**
* Release the the "refcount" to an object (so that the engine may modify
* the object)
*
* @param handle Pointer to the instance
* @param item Pointer to the item to be released
*/
      void (*item_release)(struct engine_handle* handle, item* item);
 
      /**
* Get an object from the storage.
* @param handle Pointer to the instance
* @param key Pointer to the key
* @param nkey Number of bytes in the key
* @return Pointer to the object if found, null otherwise
*/
      item* (*get)(struct engine_handle* handle, const void* key,
                   const int nkey);
 
      /**
* Get an object from the storage.
*
* @param handle Pointer to the instance
* @param key Pointer to the key
* @param nkey Number of bytes in the key
* @param delete_locked Is this set to returned as true if the item is
* locked by a delete
* @return Pointer to the object if found, null otherwise
*/
      item* (*get_not_deleted)(struct engine_handle* handle, const void* key,
                               const int nkey, bool* delete_locked);
 
      /**
* Get statistics from the engine
*
* @param handle Pointer to the instance
* @param what_to_fetch The statistics information to get
* @return a pointer to a string with the data (or null if not supported).
* Caller must free.
*/
      char* (*get_stats)(struct engine_handle* handle,
                         const char* what_to_fetch);
 
      /**
* Store an item in the cache.
*
* @param handle Pointer to the instance
* @param item the item to store in the cache
* @param operation the operation to do with the item (add, set, replace)
* @return an error code specifying the result of the operation.
*/
      ENGINE_ERROR_CODE (*store)(struct engine_handle* handle, item* item,
                                 enum operation operation);
 
      /**
* Arithmetic operation on the value for a key (incr or decr)
*
* @param handle Pointer to the instance
* @param key Pointer to the key
* @param nkey Length of the key
* @param increment true if increment, false otherwise
* @param create true if the item should be created if nonexisting
* @param delta the amount to increment
* @param initial Initial value (if key don't exist)
* @param exptime When the key should expire
* @param cas The requested CAS on entry, the resulting CAS on return
* @param result The result after the operation (return)
* @return an error code specifying the result of the operation.
*/
      ENGINE_ERROR_CODE (*arithmetic)(struct engine_handle* handle,
                                      const void* key,
                                      const int nkey,
                                      const bool increment,
                                      const bool create,
                                      const uint64_t delta,
                                      const uint64_t initial,
                                      const rel_time_t exptime,
                                      uint64_t *cas,
                                      uint64_t *result);
 
 
      /**
* Flush the cache!
*
* @param handle Pointer to the instance
* @param when When to flush the cache (see the protocol spec)
*/
      void (*flush)(struct engine_handle* handle, time_t when);
 
      /**
* Set the LRU time for an item
*
* @param handle Pointer to the instance
* @param item The item to set the LRU item on
* @param newtime The new time for the object
*/
      void (*update_lru_time)(struct engine_handle* handle, item *item,
                              const rel_time_t newtime);
   } ENGINE_HANDLE;
 
   /**
* The signature for the "create_instance" function exported from the module
*/
   typedef ENGINE_HANDLE* (*CREATE_INSTANCE)(int version,
                                             ENGINE_ERROR_CODE* error);
 
#ifdef __cplusplus
}
#endif
 
#endif