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
|
#ifndef ITEMS_H
#define ITEMS_H
/*
* You should not try to aquire any of the item locks before calling these
* functions.
*/
typedef struct _hash_item {
struct _hash_item *next;
struct _hash_item *prev;
struct _hash_item *h_next; /* hash chain next */
rel_time_t time; /* least recent access */
rel_time_t exptime; /**< When the item will expire (relative to process
* startup) */
uint32_t nbytes; /**< The total size of the data (in bytes) */
uint32_t flags; /**< Flags associated with the item (in network byte order)*/
uint16_t nkey; /**< The total length of the key (in bytes) */
uint16_t iflag; /**< Intermal flags. lower 8 bit is reserved for the core
* server, the upper 8 bits is reserved for engine
* implementation. */
unsigned short refcount;
uint8_t slabs_clsid;/* which slab class we're in */
} hash_item;
typedef struct {
unsigned int evicted;
unsigned int evicted_nonzero;
rel_time_t evicted_time;
unsigned int outofmemory;
unsigned int tailrepairs;
unsigned int reclaimed;
} itemstats_t;
struct items {
hash_item *heads[POWER_LARGEST];
hash_item *tails[POWER_LARGEST];
itemstats_t itemstats[POWER_LARGEST];
unsigned int sizes[POWER_LARGEST];
};
/**
* Allocate and initialize a new item structure
* @param engine handle to the storage engine
* @param key the key for the new item
* @param nkey the number of bytes in the key
* @param flags the flags in the new item
* @param exptime when the object should expire
* @param nbytes the number of bytes in the body for the item
* @param cookie cookie provided by the core to identify the client
* @return a pointer to an item on success NULL otherwise
*/
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);
/**
* Get an item from the cache
*
* @param engine handle to the storage engine
* @param key the key for the item to get
* @param nkey the number of bytes in the key
* @return pointer to the item if it exists or NULL otherwise
*/
hash_item *item_get(struct default_engine *engine,
const void *key, const size_t nkey);
/**
* Reset the item statistics
* @param engine handle to the storage engine
*/
void item_stats_reset(struct default_engine *engine);
/**
* Get item statitistics
* @param engine handle to the storage engine
* @param add_stat callback provided by the core used to
* push statistics into the response
* @param cookie cookie provided by the core to identify the client
*/
void item_stats(struct default_engine *engine,
ADD_STAT add_stat,
const void *cookie);
/**
* Get detaild item statitistics
* @param engine handle to the storage engine
* @param add_stat callback provided by the core used to
* push statistics into the response
* @param cookie cookie provided by the core to identify the client
*/
void item_stats_sizes(struct default_engine *engine,
ADD_STAT add_stat, const void *cookie);
/**
* Dump items from the cache
* @param engine handle to the storage engine
* @param slabs_clsid the slab class to get items from
* @param limit the maximum number of items to receive
* @param bytes the number of bytes in the return message (OUT)
* @return pointer to a string containint the data
*
* @todo we need to rewrite this to use callbacks!!!! currently disabled
*/
char *item_cachedump(struct default_engine *engine,
const unsigned int slabs_clsid,
const unsigned int limit,
unsigned int *bytes);
/**
* Flush expired items from the cache
* @param engine handle to the storage engine
* @param when when the items should be flushed
*/
void item_flush_expired(struct default_engine *engine, time_t when);
/**
* Release our reference to the current item
* @param engine handle to the storage engine
* @param it the item to release
*/
void item_release(struct default_engine *engine, hash_item *it);
/**
* Unlink the item from the hash table (make it inaccessible)
* @param engine handle to the storage engine
* @param it the item to unlink
*/
void item_unlink(struct default_engine *engine, hash_item *it);
/**
* Set the expiration time for an object
* @param engine handle to the storage engine
* @param key the key to set
* @param nkey the number of characters in key..
* @param exptime the expiration time
* @return The (updated) item if it exists
*/
hash_item *touch_item(struct default_engine *engine,
const void *key,
uint16_t nkey,
uint32_t exptime);
/**
* Store an item in the cache
* @param engine handle to the storage engine
* @param item the item to store
* @param cas the cas value (OUT)
* @param operation what kind of store operation is this (ADD/SET etc)
* @param cookie cookie provided by the core to identify the client
* @return ENGINE_SUCCESS on success
*
* @todo should we refactor this into hash_item ** and remove the cas
* there so that we can get it from the item instead?
*/
ENGINE_ERROR_CODE store_item(struct default_engine *engine,
hash_item *item,
uint64_t *cas,
ENGINE_STORE_OPERATION operation,
const void *cookie);
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);
/**
* Start the item scrubber
* @param engine handle to the storage engine
*/
bool item_start_scrub(struct default_engine *engine);
/**
* The tap walker to walk the hashtables
*/
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);
bool initialize_item_tap_walker(struct default_engine *engine,
const void* cookie);
#endif
|