1/* 2 * Summary: Specification of the storage engine interface. 3 * 4 * Copy: See Copyright for the status of this software. 5 * 6 * Author: Trond Norbye <trond.norbye@sun.com> 7 */ 8#ifndef MEMCACHED_DEFAULT_ENGINE_H 9#define MEMCACHED_DEFAULT_ENGINE_H 10 11#include "config.h" 12 13#include <stdbool.h> 14 15#include <memcached/engine.h> 16#include <memcached/util.h> 17#include <memcached/visibility.h> 18#include <platform/platform.h> 19 20/* Slab sizing definitions. */ 21#define POWER_SMALLEST 1 22#define POWER_LARGEST 200 23#define CHUNK_ALIGN_BYTES 8 24#define DONT_PREALLOC_SLABS 25#define MAX_NUMBER_OF_SLAB_CLASSES (POWER_LARGEST + 1) 26 27/** How long an object can reasonably be assumed to be locked before 28 harvesting it on a low memory condition. */ 29#define TAIL_REPAIR_TIME (3 * 3600) 30 31 32/* Forward decl */ 33struct default_engine; 34 35#include "trace.h" 36#include "items.h" 37#include "assoc.h" 38#include "slabs.h" 39 40#ifdef __cplusplus 41extern "C" { 42#endif 43 44 /* Flags */ 45#define ITEM_WITH_CAS 1 46 47#define ITEM_LINKED (1<<8) 48 49/* temp */ 50#define ITEM_SLABBED (2<<8) 51 52struct config { 53 bool use_cas; 54 size_t verbose; 55 rel_time_t oldest_live; 56 bool evict_to_free; 57 size_t maxbytes; 58 bool preallocate; 59 float factor; 60 size_t chunk_size; 61 size_t item_size_max; 62 bool ignore_vbucket; 63 bool vb0; 64 char *uuid; 65}; 66 67MEMCACHED_PUBLIC_API 68ENGINE_ERROR_CODE create_instance(uint64_t interface, 69 GET_SERVER_API get_server_api, 70 ENGINE_HANDLE **handle); 71 72/** 73 * Statistic information collected by the default engine 74 */ 75struct engine_stats { 76 cb_mutex_t lock; 77 uint64_t evictions; 78 uint64_t reclaimed; 79 uint64_t curr_bytes; 80 uint64_t curr_items; 81 uint64_t total_items; 82}; 83 84struct engine_scrubber { 85 cb_mutex_t lock; 86 bool running; 87 uint64_t visited; 88 uint64_t cleaned; 89 time_t started; 90 time_t stopped; 91}; 92 93struct tap_connections { 94 cb_mutex_t lock; 95 size_t size; 96 const void* *clients; 97}; 98 99struct vbucket_info { 100 int state : 2; 101}; 102 103#define NUM_VBUCKETS 65536 104 105/** 106 * Definition of the private instance data used by the default engine. 107 * 108 * This is currently "work in progress" so it is not as clean as it should be. 109 */ 110struct default_engine { 111 ENGINE_HANDLE_V1 engine; 112 SERVER_HANDLE_V1 server; 113 GET_SERVER_API get_server_api; 114 115 /** 116 * Is the engine initalized or not 117 */ 118 bool initialized; 119 120 struct assoc assoc; 121 struct slabs slabs; 122 struct items items; 123 124 /** 125 * The cache layer (item_* and assoc_*) is currently protected by 126 * this single mutex 127 */ 128 cb_mutex_t cache_lock; 129 130 struct config config; 131 struct engine_stats stats; 132 struct engine_scrubber scrubber; 133 struct tap_connections tap_connections; 134 135 union { 136 engine_info engine_info; 137 char buffer[sizeof(engine_info) + 138 (sizeof(feature_info) * LAST_REGISTERED_ENGINE_FEATURE)]; 139 } info; 140 141 char vbucket_infos[NUM_VBUCKETS]; 142}; 143 144char* item_get_data(const hash_item* item); 145const void* item_get_key(const hash_item* item); 146void item_set_cas(ENGINE_HANDLE *handle, const void *cookie, 147 item* item, uint64_t val); 148uint64_t item_get_cas(const hash_item* item); 149uint8_t item_get_clsid(const hash_item* item); 150#endif 151