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 * @return a pointer to an item on success NULL otherwise 51 */ 52 hash_item *item_alloc(struct default_engine *engine, 53 const void *key, size_t nkey, int flags, 54 rel_time_t exptime, int nbytes, const void *cookie); 55 56 /** 57 * Get an item from the cache 58 * 59 * @param engine handle to the storage engine 60 * @param key the key for the item to get 61 * @param nkey the number of bytes in the key 62 * @return pointer to the item if it exists or NULL otherwise 63 */ 64 hash_item *item_get(struct default_engine *engine, 65 const void *key, const size_t nkey); 66 67 /** 68 * Reset the item statistics 69 * @param engine handle to the storage engine 70 */ 71 void item_stats_reset(struct default_engine *engine); 72 73 /** 74 * Get item statitistics 75 * @param engine handle to the storage engine 76 * @param add_stat callback provided by the core used to 77 * push statistics into the response 78 * @param cookie cookie provided by the core to identify the client 79 */ 80 void item_stats(struct default_engine *engine, 81 ADD_STAT add_stat, 82 const void *cookie); 83 84 /** 85 * Get detaild item statitistics 86 * @param engine handle to the storage engine 87 * @param add_stat callback provided by the core used to 88 * push statistics into the response 89 * @param cookie cookie provided by the core to identify the client 90 */ 91 void item_stats_sizes(struct default_engine *engine, 92 ADD_STAT add_stat, const void *cookie); 93 94 /** 95 * Dump items from the cache 96 * @param engine handle to the storage engine 97 * @param slabs_clsid the slab class to get items from 98 * @param limit the maximum number of items to receive 99 * @param bytes the number of bytes in the return message (OUT) 100 * @return pointer to a string containint the data 101 * 102 * @todo we need to rewrite this to use callbacks!!!! currently disabled 103 */ 104 char *item_cachedump(struct default_engine *engine, 105 const unsigned int slabs_clsid, 106 const unsigned int limit, 107 unsigned int *bytes); 108 109 /** 110 * Flush expired items from the cache 111 * @param engine handle to the storage engine 112 * @param when when the items should be flushed 113 */ 114 void item_flush_expired(struct default_engine *engine, time_t when); 115 116 /** 117 * Release our reference to the current item 118 * @param engine handle to the storage engine 119 * @param it the item to release 120 */ 121 void item_release(struct default_engine *engine, hash_item *it); 122 123 /** 124 * Unlink the item from the hash table (make it inaccessible) 125 * @param engine handle to the storage engine 126 * @param it the item to unlink 127 */ 128 void item_unlink(struct default_engine *engine, hash_item *it); 129 130 /** 131 * Store an item in the cache 132 * @param engine handle to the storage engine 133 * @param item the item to store 134 * @param cas the cas value (OUT) 135 * @param operation what kind of store operation is this (ADD/SET etc) 136 * @return ENGINE_SUCCESS on success 137 * 138 * @todo should we refactor this into hash_item ** and remove the cas 139 * there so that we can get it from the item instead? 140 */ 141 ENGINE_ERROR_CODE store_item(struct default_engine *engine, 142 hash_item *item, 143 uint64_t *cas, 144 ENGINE_STORE_OPERATION operation, 145 const void *cookie); 146 147 ENGINE_ERROR_CODE arithmetic(struct default_engine *engine, 148 const void* cookie, 149 const void* key, 150 const int nkey, 151 const bool increment, 152 const bool create, 153 const uint64_t delta, 154 const uint64_t initial, 155 const rel_time_t exptime, 156 uint64_t *cas, 157 uint64_t *result); 158 159 160 /** 161 * Start the item scrubber 162 * @param engine handle to the storage engine 163 */ 164 bool item_start_scrub(struct default_engine *engine); 165 166 #endif 167