Debian Codegraph @

plugin/innodb_memcached/daemon_memcached/engines/default_engine/items.h

raw
1 #ifndef ITEMS_H
2 #define ITEMS_H
3
4 /*
5 * You should not try to aquire any of the item locks before calling these
6 * functions.
7 */
8 typedef struct _hash_item {
9 struct _hash_item *next;
10 struct _hash_item *prev;
11 struct _hash_item *h_next; /* hash chain next */
12 rel_time_t time; /* least recent access */
13 rel_time_t exptime; /**< When the item will expire (relative to process
14 * startup) */
15 uint32_t nbytes; /**< The total size of the data (in bytes) */
16 uint32_t flags; /**< Flags associated with the item (in network byte order)*/
17 uint16_t nkey; /**< The total length of the key (in bytes) */
18 uint16_t iflag; /**< Intermal flags. lower 8 bit is reserved for the core
19 * server, the upper 8 bits is reserved for engine
20 * implementation. */
21 unsigned short refcount;
22 uint8_t slabs_clsid;/* which slab class we're in */
23 } hash_item;
24
25 typedef struct {
26 unsigned int evicted;
27 unsigned int evicted_nonzero;
28 rel_time_t evicted_time;
29 unsigned int outofmemory;
30 unsigned int tailrepairs;
31 unsigned int reclaimed;
32 } itemstats_t;
33
34 struct items {
35 hash_item *heads[POWER_LARGEST];
36 hash_item *tails[POWER_LARGEST];
37 itemstats_t itemstats[POWER_LARGEST];
38 unsigned int sizes[POWER_LARGEST];
39 };
40
41
42 /**
43 * Allocate and initialize a new item structure
44 * @param engine handle to the storage engine
45 * @param key the key for the new item
46 * @param nkey the number of bytes in the key
47 * @param flags the flags in the new item
48 * @param exptime when the object should expire
49 * @param nbytes the number of bytes in the body for the item
50 * @param cookie cookie provided by the core to identify the client
51 * @return a pointer to an item on success NULL otherwise
52 */
53 hash_item *item_alloc(struct default_engine *engine,
54 const void *key, size_t nkey, int flags,
55 rel_time_t exptime, int nbytes, const void *cookie);
56
57 /**
58 * Get an item from the cache
59 *
60 * @param engine handle to the storage engine
61 * @param key the key for the item to get
62 * @param nkey the number of bytes in the key
63 * @return pointer to the item if it exists or NULL otherwise
64 */
65 hash_item *item_get(struct default_engine *engine,
66 const void *key, const size_t nkey);
67
68 /**
69 * Reset the item statistics
70 * @param engine handle to the storage engine
71 */
72 void item_stats_reset(struct default_engine *engine);
73
74 /**
75 * Get item statitistics
76 * @param engine handle to the storage engine
77 * @param add_stat callback provided by the core used to
78 * push statistics into the response
79 * @param cookie cookie provided by the core to identify the client
80 */
81 void item_stats(struct default_engine *engine,
82 ADD_STAT add_stat,
83 const void *cookie);
84
85 /**
86 * Get detaild item statitistics
87 * @param engine handle to the storage engine
88 * @param add_stat callback provided by the core used to
89 * push statistics into the response
90 * @param cookie cookie provided by the core to identify the client
91 */
92 void item_stats_sizes(struct default_engine *engine,
93 ADD_STAT add_stat, const void *cookie);
94
95 /**
96 * Dump items from the cache
97 * @param engine handle to the storage engine
98 * @param slabs_clsid the slab class to get items from
99 * @param limit the maximum number of items to receive
100 * @param bytes the number of bytes in the return message (OUT)
101 * @return pointer to a string containint the data
102 *
103 * @todo we need to rewrite this to use callbacks!!!! currently disabled
104 */
105 char *item_cachedump(struct default_engine *engine,
106 const unsigned int slabs_clsid,
107 const unsigned int limit,
108 unsigned int *bytes);
109
110 /**
111 * Flush expired items from the cache
112 * @param engine handle to the storage engine
113 * @param when when the items should be flushed
114 */
115 void item_flush_expired(struct default_engine *engine, time_t when);
116
117 /**
118 * Release our reference to the current item
119 * @param engine handle to the storage engine
120 * @param it the item to release
121 */
122 void item_release(struct default_engine *engine, hash_item *it);
123
124 /**
125 * Unlink the item from the hash table (make it inaccessible)
126 * @param engine handle to the storage engine
127 * @param it the item to unlink
128 */
129 void item_unlink(struct default_engine *engine, hash_item *it);
130
131 /**
132 * Set the expiration time for an object
133 * @param engine handle to the storage engine
134 * @param key the key to set
135 * @param nkey the number of characters in key..
136 * @param exptime the expiration time
137 * @return The (updated) item if it exists
138 */
139 hash_item *touch_item(struct default_engine *engine,
140 const void *key,
141 uint16_t nkey,
142 uint32_t exptime);
143
144 /**
145 * Store an item in the cache
146 * @param engine handle to the storage engine
147 * @param item the item to store
148 * @param cas the cas value (OUT)
149 * @param operation what kind of store operation is this (ADD/SET etc)
150 * @param cookie cookie provided by the core to identify the client
151 * @return ENGINE_SUCCESS on success
152 *
153 * @todo should we refactor this into hash_item ** and remove the cas
154 * there so that we can get it from the item instead?
155 */
156 ENGINE_ERROR_CODE store_item(struct default_engine *engine,
157 hash_item *item,
158 uint64_t *cas,
159 ENGINE_STORE_OPERATION operation,
160 const void *cookie);
161
162 ENGINE_ERROR_CODE arithmetic(struct default_engine *engine,
163 const void* cookie,
164 const void* key,
165 const int nkey,
166 const bool increment,
167 const bool create,
168 const uint64_t delta,
169 const uint64_t initial,
170 const rel_time_t exptime,
171 uint64_t *cas,
172 uint64_t *result);
173
174
175 /**
176 * Start the item scrubber
177 * @param engine handle to the storage engine
178 */
179 bool item_start_scrub(struct default_engine *engine);
180
181 /**
182 * The tap walker to walk the hashtables
183 */
184 tap_event_t item_tap_walker(ENGINE_HANDLE* handle,
185 const void *cookie, item **itm,
186 void **es, uint16_t *nes, uint8_t *ttl,
187 uint16_t *flags, uint32_t *seqno,
188 uint16_t *vbucket);
189
190 bool initialize_item_tap_walker(struct default_engine *engine,
191 const void* cookie);
192
193
194 #endif