MySQL  8.0.17
Source Code Documentation
items.h
Go to the documentation of this file.
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 {
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  */
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  */
66  const void *key, const size_t nkey);
67 
68 /**
69  * Reset the item statistics
70  * @param engine handle to the storage engine
71  */
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  */
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  */
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  */
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 
191  const void* cookie);
192 
193 
194 #endif
uint32_t flags
Flags associated with the item (in network byte order)
Definition: items.h:16
hash_item * tails[POWER_LARGEST]
Definition: items.h:36
hash_item * heads[POWER_LARGEST]
Definition: items.h:35
Definition: items.h:8
void item_stats_sizes(struct default_engine *engine, ADD_STAT add_stat, const void *cookie)
Get detaild item statitistics.
Definition: items.c:961
ENGINE_HANDLE * engine
Definition: mock_server.c:28
itemstats_t itemstats[POWER_LARGEST]
Definition: items.h:37
char * item_cachedump(struct default_engine *engine, const unsigned int slabs_clsid, const unsigned int limit, unsigned int *bytes)
Dump items from the cache.
Definition: items.c:940
unsigned int outofmemory
Definition: items.h:29
void * handle
Definition: engine_loader.c:19
void item_stats_reset(struct default_engine *engine)
Reset the item statistics.
Definition: items.c:44
void item_unlink(struct default_engine *engine, hash_item *it)
Unlink the item from the hash table (make it inaccessible)
Definition: items.c:786
uint16_t nkey
The total length of the key (in bytes)
Definition: items.h:17
hash_item * item_get(struct default_engine *engine, const void *key, const size_t nkey)
Get an item from the cache.
Definition: items.c:764
rel_time_t time
Definition: items.h:12
void item_flush_expired(struct default_engine *engine, time_t when)
Flush expired items from the cache.
Definition: items.c:900
Definition: items.h:25
unsigned int reclaimed
Definition: items.h:31
#define POWER_LARGEST
Definition: memcached.h:70
struct _hash_item hash_item
bool initialize_item_tap_walker(struct default_engine *engine, const void *cookie)
Definition: items.c:1184
bool item_start_scrub(struct default_engine *engine)
Start the item scrubber.
Definition: items.c:1086
uint16_t iflag
Intermal flags.
Definition: items.h:18
struct _hash_item * prev
Definition: items.h:10
hash_item * item_alloc(struct default_engine *engine, const void *key, size_t nkey, int flags, rel_time_t exptime, int nbytes, const void *cookie)
Allocate and initialize a new item structure.
Definition: items.c:750
rel_time_t evicted_time
Definition: items.h:28
ENGINE_ERROR_CODE store_item(struct default_engine *engine, hash_item *item, uint64_t *cas, ENGINE_STORE_OPERATION operation, const void *cookie)
Store an item in the cache.
Definition: items.c:860
unsigned int evicted
Definition: items.h:26
uint32_t nbytes
The total size of the data (in bytes)
Definition: items.h:15
ENGINE_ERROR_CODE arithmetic(struct default_engine *engine, const void *cookie, 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)
Definition: items.c:835
static const char * key
Definition: suite_stubs.c:14
hash_item * touch_item(struct default_engine *engine, const void *key, uint16_t nkey, uint32_t exptime)
Set the expiration time for an object.
Definition: items.c:884
unsigned short refcount
Definition: items.h:21
Definition of the private instance data used by the default engine.
Definition: default_engine.h:109
unsigned int evicted_nonzero
Definition: items.h:27
tap_event_t item_tap_walker(ENGINE_HANDLE *handle, const void *cookie, item **itm, void **es, uint16_t *nes, uint8_t *ttl, uint16_t *flags, uint32_t *seqno, uint16_t *vbucket)
The tap walker to walk the hashtables.
Definition: items.c:1169
unsigned int sizes[POWER_LARGEST]
Definition: items.h:38
rel_time_t exptime
When the item will expire (relative to process startup)
Definition: items.h:13
uint8_t slabs_clsid
Definition: items.h:22
static int flags[50]
Definition: hp_test1.cc:39
unsigned int tailrepairs
Definition: items.h:30
void item_stats(struct default_engine *engine, ADD_STAT add_stat, const void *cookie)
Get item statitistics.
Definition: items.c:952
struct _hash_item * h_next
Definition: items.h:11
unsigned int slabs_clsid(struct default_engine *engine, const size_t size)
Given object size, return id to use when allocating/freeing memory for object 0 means error: can&#39;t st...
Definition: slabs.c:48
void item_release(struct default_engine *engine, hash_item *it)
Release our reference to the current item.
Definition: items.c:777
Definition: items.h:34
struct _hash_item * next
Definition: items.h:9