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_INTERNAL_H 9#define MEMCACHED_DEFAULT_ENGINE_INTERNAL_H 10 11#include "config.h" 12 13#include <stdbool.h> 14#include <atomic> 15 16#include <memcached/engine.h> 17#include <memcached/util.h> 18#include <memcached/visibility.h> 19#include <platform/platform.h> 20 21/* Slab sizing definitions. */ 22#define POWER_SMALLEST 1 23#define POWER_LARGEST 200 24#define CHUNK_ALIGN_BYTES 8 25#define DONT_PREALLOC_SLABS 26#define MAX_NUMBER_OF_SLAB_CLASSES (POWER_LARGEST + 1) 27 28/** How long an object can reasonably be assumed to be locked before 29 harvesting it on a low memory condition. */ 30#define TAIL_REPAIR_TIME (3 * 3600) 31 32 33/* Forward decl */ 34struct default_engine; 35 36#include "trace.h" 37#include "items.h" 38#include "assoc.h" 39#include "slabs.h" 40 41 /* Flags */ 42#define ITEM_LINKED (1) 43 44/* temp */ 45#define ITEM_SLABBED (2) 46 47/** The item is deleted (may only be accessed if explicitly asked for) */ 48#define ITEM_ZOMBIE (4) 49 50struct config { 51 size_t verbose; 52 rel_time_t oldest_live; 53 bool evict_to_free; 54 size_t maxbytes; 55 bool preallocate; 56 float factor; 57 size_t chunk_size; 58 size_t item_size_max; 59 bool ignore_vbucket; 60 bool vb0; 61 char *uuid; 62 bool keep_deleted; 63 std::atomic<bool> xattr_enabled; 64 std::atomic<BucketCompressionMode> compression_mode; 65 std::atomic<float> min_compression_ratio; 66}; 67 68/** 69 * Statistic information collected by the default engine 70 */ 71struct engine_stats { 72 cb_mutex_t lock; 73 uint64_t evictions; 74 uint64_t reclaimed; 75 uint64_t curr_bytes; 76 uint64_t curr_items; 77 uint64_t total_items; 78}; 79 80struct engine_scrubber { 81 cb_mutex_t lock; 82 uint64_t visited; 83 uint64_t cleaned; 84 time_t started; 85 time_t stopped; 86 bool running; 87 bool force_delete; 88}; 89 90struct vbucket_info { 91 int state : 2; 92}; 93 94#define NUM_VBUCKETS 65536 95 96/** 97 * Definition of the private instance data used by the default engine. 98 * 99 * This is currently "work in progress" so it is not as clean as it should be. 100 */ 101struct default_engine { 102 ENGINE_HANDLE_V1 engine; 103 SERVER_HANDLE_V1 server; 104 GET_SERVER_API get_server_api; 105 106 /** 107 * Is the engine initalized or not 108 */ 109 bool initialized; 110 111 struct slabs slabs; 112 struct items items; 113 114 struct config config; 115 struct engine_stats stats; 116 struct engine_scrubber scrubber; 117 118 char vbucket_infos[NUM_VBUCKETS]; 119 120 /* a unique bucket index, note this is not cluster wide and dies with the process */ 121 bucket_id_t bucket_id; 122}; 123 124char* item_get_data(const hash_item* item); 125hash_key* item_get_key(const hash_item* item); 126void item_set_cas(gsl::not_null<ENGINE_HANDLE*> handle, 127 gsl::not_null<item*> item, 128 uint64_t val); 129#ifdef __cplusplus 130extern "C" { 131#endif 132 133MEMCACHED_PUBLIC_API 134void destroy_engine(void); 135 136void default_engine_constructor(struct default_engine* engine, bucket_id_t id); 137void destroy_engine_instance(struct default_engine* engine); 138 139#ifdef __cplusplus 140} 141#endif 142 143 144#endif 145