| 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 <[email protected]> |
| 7 |
*/ |
| 8 |
#ifndef MEMCACHED_DEFAULT_ENGINE_H |
| 9 |
#define MEMCACHED_DEFAULT_ENGINE_H |
| 10 |
|
| 11 |
#include "config.h" |
| 12 |
|
| 13 |
#include <pthread.h> |
| 14 |
#include <stdbool.h> |
| 15 |
|
| 16 |
#include <memcached/engine.h> |
| 17 |
#include <memcached/util.h> |
| 18 |
#include <memcached/visibility.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 */ |
| 33 |
struct default_engine; |
| 34 |
|
| 35 |
#include "trace.h" |
| 36 |
#include "items.h" |
| 37 |
#include "assoc.h" |
| 38 |
#include "slabs.h" |
| 39 |
|
| 40 |
#ifdef __cplusplus |
| 41 |
extern "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 |
|
| 52 |
struct 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 |
}; |
| 65 |
|
| 66 |
MEMCACHED_PUBLIC_API |
| 67 |
ENGINE_ERROR_CODE create_instance(uint64_t interface, |
| 68 |
GET_SERVER_API get_server_api, |
| 69 |
ENGINE_HANDLE **handle); |
| 70 |
|
| 71 |
/** |
| 72 |
* Statistic information collected by the default engine |
| 73 |
*/ |
| 74 |
struct engine_stats { |
| 75 |
pthread_mutex_t lock; |
| 76 |
uint64_t evictions; |
| 77 |
uint64_t reclaimed; |
| 78 |
uint64_t curr_bytes; |
| 79 |
uint64_t curr_items; |
| 80 |
uint64_t total_items; |
| 81 |
}; |
| 82 |
|
| 83 |
struct engine_scrubber { |
| 84 |
pthread_mutex_t lock; |
| 85 |
bool running; |
| 86 |
uint64_t visited; |
| 87 |
uint64_t cleaned; |
| 88 |
time_t started; |
| 89 |
time_t stopped; |
| 90 |
}; |
| 91 |
|
| 92 |
struct tap_connections { |
| 93 |
pthread_mutex_t lock; |
| 94 |
size_t size; |
| 95 |
const void* *clients; |
| 96 |
}; |
| 97 |
|
| 98 |
struct vbucket_info { |
| 99 |
int state : 2; |
| 100 |
}; |
| 101 |
|
| 102 |
#define NUM_VBUCKETS 65536 |
| 103 |
|
| 104 |
/** |
| 105 |
* Definition of the private instance data used by the default engine. |
| 106 |
* |
| 107 |
* This is currently "work in progress" so it is not as clean as it should be. |
| 108 |
*/ |
| 109 |
struct default_engine { |
| 110 |
ENGINE_HANDLE_V1 engine; |
| 111 |
SERVER_HANDLE_V1 server; |
| 112 |
GET_SERVER_API get_server_api; |
| 113 |
|
| 114 |
/** |
| 115 |
* Is the engine initalized or not |
| 116 |
*/ |
| 117 |
bool initialized; |
| 118 |
|
| 119 |
struct assoc assoc; |
| 120 |
struct slabs slabs; |
| 121 |
struct items items; |
| 122 |
|
| 123 |
/** |
| 124 |
* The cache layer (item_* and assoc_*) is currently protected by |
| 125 |
* this single mutex |
| 126 |
*/ |
| 127 |
pthread_mutex_t cache_lock; |
| 128 |
|
| 129 |
struct config config; |
| 130 |
struct engine_stats stats; |
| 131 |
struct engine_scrubber scrubber; |
| 132 |
struct tap_connections tap_connections; |
| 133 |
|
| 134 |
union { |
| 135 |
engine_info engine_info; |
| 136 |
char buffer[sizeof(engine_info) + |
| 137 |
(sizeof(feature_info) * LAST_REGISTERED_ENGINE_FEATURE)]; |
| 138 |
} info; |
| 139 |
|
| 140 |
char vbucket_infos[NUM_VBUCKETS]; |
| 141 |
}; |
| 142 |
|
| 143 |
char* item_get_data(const hash_item* item); |
| 144 |
const void* item_get_key(const hash_item* item); |
| 145 |
void item_set_cas(ENGINE_HANDLE *handle, const void *cookie, |
| 146 |
item* item, uint64_t val); |
| 147 |
uint64_t item_get_cas(const hash_item* item); |
| 148 |
uint8_t item_get_clsid(const hash_item* item); |
| 149 |
#endif |