#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <event.h>
#include <netdb.h>
#include <stdbool.h>
#include <stdint.h>
#include <pthread.h>
#include "protocol_binary.h"
#include "cache.h"
#include "stats.h"
#include "slabs.h"
#include "assoc.h"
#include "items.h"
#include "trace.h"
#include "hash.h"
#include "util.h"
Go to the source code of this file.
Classes | |
struct | slab_stats |
Stats stored per slab (and per thread). More... | |
struct | thread_stats |
Stats stored per-thread. More... | |
struct | stats |
Global stats. More... | |
struct | settings |
Globally accessible settings as derived from the commandline. More... | |
struct | _stritem |
Structure for storing items within memcached. More... | |
struct | LIBEVENT_THREAD |
struct | conn |
Defines | |
#define | KEY_MAX_LENGTH 250 |
Maximum length of a key. | |
#define | DATA_BUFFER_SIZE 2048 |
#define | UDP_READ_BUFFER_SIZE 65536 |
#define | UDP_MAX_PAYLOAD_SIZE 1400 |
#define | UDP_HEADER_SIZE 8 |
#define | MAX_SENDBUF_SIZE (256 * 1024 * 1024) |
#define | SUFFIX_SIZE 24 |
#define | ITEM_LIST_INITIAL 200 |
Initial size of list of items being returned by "get". | |
#define | SUFFIX_LIST_INITIAL 20 |
Initial size of list of CAS suffixes appended to "gets" lines. | |
#define | IOV_LIST_INITIAL 400 |
Initial size of the sendmsg() scatter/gather array. | |
#define | MSG_LIST_INITIAL 10 |
Initial number of sendmsg() argument structures to allocate. | |
#define | READ_BUFFER_HIGHWAT 8192 |
High water marks for buffer shrinking. | |
#define | ITEM_LIST_HIGHWAT 400 |
#define | IOV_LIST_HIGHWAT 600 |
#define | MSG_LIST_HIGHWAT 100 |
#define | MIN_BIN_PKT_LENGTH 16 |
#define | BIN_PKT_HDR_WORDS (MIN_BIN_PKT_LENGTH/sizeof(uint32_t)) |
#define | POWER_SMALLEST 1 |
#define | POWER_LARGEST 200 |
#define | POWER_BLOCK 1048576 |
#define | CHUNK_ALIGN_BYTES 8 |
#define | DONT_PREALLOC_SLABS |
#define | MAX_NUMBER_OF_SLAB_CLASSES (POWER_LARGEST + 1) |
#define | TAIL_REPAIR_TIME (3 * 3600) |
How long an object can reasonably be assumed to be locked before harvesting it on a low memory condition. | |
#define | MAX_VERBOSITY_LEVEL 2 |
#define | ITEM_LINKED 1 |
#define | ITEM_CAS 2 |
#define | ITEM_SLABBED 4 |
#define | ITEM_get_cas(i) |
#define | ITEM_set_cas(i, v) |
#define | ITEM_key(item) |
#define | ITEM_suffix(item) |
#define | ITEM_data(item) |
#define | ITEM_ntotal(item) |
#define | APPEND_STAT(name, fmt, val) append_stat(name, add_stats, c, fmt, val); |
Append a simple stat with a stat name, value format and value. | |
#define | APPEND_NUM_FMT_STAT(name_fmt, num, name, fmt, val) |
Append an indexed stat with a stat name (with format), value format and value. | |
#define | APPEND_NUM_STAT(num, name, fmt, val) APPEND_NUM_FMT_STAT("%d:%s", num, name, fmt, val) |
Common APPEND_NUM_FMT_STAT format. | |
#define | IS_UDP(x) (x == ascii_udp_prot) |
#define | NREAD_ADD 1 |
#define | NREAD_SET 2 |
#define | NREAD_REPLACE 3 |
#define | NREAD_APPEND 4 |
#define | NREAD_PREPEND 5 |
#define | NREAD_CAS 6 |
#define | drop_privileges() |
#define | __builtin_expect(x, expected_value) (x) |
#define | likely(x) __builtin_expect((x),1) |
#define | unlikely(x) __builtin_expect((x),0) |
Typedefs | |
typedef unsigned int | rel_time_t |
Time relative to server start. | |
typedef struct _stritem | item |
Structure for storing items within memcached. | |
typedef void(* | ADD_STAT )(const char *key, const uint16_t klen, const char *val, const uint32_t vlen, const void *cookie) |
Callback for any function producing stats. | |
typedef struct conn | conn |
The structure representing a connection into memcached. | |
Enumerations | |
enum | conn_states { conn_listening, conn_new_cmd, conn_waiting, conn_read, conn_parse_cmd, conn_write, conn_nread, conn_swallow, conn_closing, conn_mwrite, conn_max_state } |
Possible states of a connection. More... | |
enum | bin_substates { bin_no_state, bin_reading_set_header, bin_reading_cas_header, bin_read_set_value, bin_reading_get_key, bin_reading_stat, bin_reading_del_header, bin_reading_incr_header, bin_read_flush_exptime } |
enum | protocol { ascii_prot = 3, ascii_udp_prot, binary_prot, negotiating_prot } |
enum | store_item_type { NOT_STORED = 0, STORED, EXISTS, NOT_FOUND } |
Functions | |
void | do_accept_new_conns (const bool do_accept) |
char * | do_add_delta (conn *c, item *item, const bool incr, const int64_t delta, char *buf) |
enum store_item_type | do_store_item (item *item, int comm, conn *c) |
conn * | conn_new (const int sfd, const enum conn_states init_state, const int event_flags, const int read_buffer_size, enum protocol prot, struct event_base *base) |
int | daemonize (int nochdir, int noclose) |
void | thread_init (int nthreads, struct event_base *main_base) |
int | dispatch_event_add (int thread, conn *c) |
void | dispatch_conn_new (int sfd, enum conn_states init_state, int event_flags, int read_buffer_size, enum protocol prot) |
char * | add_delta (conn *c, item *item, const int incr, const int64_t delta, char *buf) |
void | accept_new_conns (const bool do_accept) |
conn * | conn_from_freelist (void) |
bool | conn_add_to_freelist (conn *c) |
int | is_listen_thread (void) |
item * | item_alloc (char *key, size_t nkey, int flags, rel_time_t exptime, int nbytes) |
char * | item_cachedump (const unsigned int slabs_clsid, const unsigned int limit, unsigned int *bytes) |
void | item_flush_expired (void) |
item * | item_get (const char *key, const size_t nkey) |
int | item_link (item *it) |
void | item_remove (item *it) |
int | item_replace (item *it, item *new_it) |
void | item_stats (ADD_STAT add_stats, void *c) |
void | item_stats_sizes (ADD_STAT add_stats, void *c) |
void | item_unlink (item *it) |
void | item_update (item *it) |
void | STATS_LOCK (void) |
void | STATS_UNLOCK (void) |
void | threadlocal_stats_reset (void) |
void | threadlocal_stats_aggregate (struct thread_stats *stats) |
void | slab_stats_aggregate (struct thread_stats *stats, struct slab_stats *out) |
void | append_stat (const char *name, ADD_STAT add_stats, conn *c, const char *fmt,...) |
enum store_item_type | store_item (item *item, int comm, conn *c) |
Variables | |
struct stats | stats |
exported globals | |
time_t | process_started |
struct settings | settings |
volatile rel_time_t | current_time |
#define __builtin_expect | ( | x, | |||
expected_value | ) | (x) |
#define APPEND_NUM_FMT_STAT | ( | name_fmt, | |||
num, | |||||
name, | |||||
fmt, | |||||
val | ) |
Value:
klen = sprintf(key_str, name_fmt, num, name); \ vlen = sprintf(val_str, fmt, val); \ add_stats(key_str, klen, val_str, vlen, c);
#define APPEND_NUM_STAT | ( | num, | |||
name, | |||||
fmt, | |||||
val | ) | APPEND_NUM_FMT_STAT("%d:%s", num, name, fmt, val) |
Common APPEND_NUM_FMT_STAT format.
#define APPEND_STAT | ( | name, | |||
fmt, | |||||
val | ) | append_stat(name, add_stats, c, fmt, val); |
Append a simple stat with a stat name, value format and value.
#define BIN_PKT_HDR_WORDS (MIN_BIN_PKT_LENGTH/sizeof(uint32_t)) |
#define CHUNK_ALIGN_BYTES 8 |
#define DATA_BUFFER_SIZE 2048 |
#define DONT_PREALLOC_SLABS |
#define drop_privileges | ( | ) |
#define IOV_LIST_HIGHWAT 600 |
#define IOV_LIST_INITIAL 400 |
Initial size of the sendmsg() scatter/gather array.
#define IS_UDP | ( | x | ) | (x == ascii_udp_prot) |
#define ITEM_CAS 2 |
#define ITEM_data | ( | item | ) |
#define ITEM_get_cas | ( | i | ) |
Value:
((uint64_t)(((i)->it_flags & ITEM_CAS) ? \ *(uint64_t*)&((i)->end[0]) : 0x0))
#define ITEM_key | ( | item | ) |
#define ITEM_LINKED 1 |
#define ITEM_LIST_HIGHWAT 400 |
#define ITEM_LIST_INITIAL 200 |
Initial size of list of items being returned by "get".
#define ITEM_ntotal | ( | item | ) |
#define ITEM_set_cas | ( | i, | |||
v | ) |
#define ITEM_SLABBED 4 |
#define ITEM_suffix | ( | item | ) |
#define KEY_MAX_LENGTH 250 |
Maximum length of a key.
#define likely | ( | x | ) | __builtin_expect((x),1) |
#define MAX_NUMBER_OF_SLAB_CLASSES (POWER_LARGEST + 1) |
#define MAX_SENDBUF_SIZE (256 * 1024 * 1024) |
#define MAX_VERBOSITY_LEVEL 2 |
#define MIN_BIN_PKT_LENGTH 16 |
#define MSG_LIST_HIGHWAT 100 |
#define MSG_LIST_INITIAL 10 |
Initial number of sendmsg() argument structures to allocate.
#define NREAD_ADD 1 |
#define NREAD_APPEND 4 |
#define NREAD_CAS 6 |
#define NREAD_PREPEND 5 |
#define NREAD_REPLACE 3 |
#define NREAD_SET 2 |
#define POWER_BLOCK 1048576 |
#define POWER_LARGEST 200 |
#define POWER_SMALLEST 1 |
#define READ_BUFFER_HIGHWAT 8192 |
High water marks for buffer shrinking.
#define SUFFIX_LIST_INITIAL 20 |
Initial size of list of CAS suffixes appended to "gets" lines.
#define SUFFIX_SIZE 24 |
#define TAIL_REPAIR_TIME (3 * 3600) |
How long an object can reasonably be assumed to be locked before harvesting it on a low memory condition.
#define UDP_HEADER_SIZE 8 |
#define UDP_MAX_PAYLOAD_SIZE 1400 |
#define UDP_READ_BUFFER_SIZE 65536 |
#define unlikely | ( | x | ) | __builtin_expect((x),0) |
typedef void(* ADD_STAT)(const char *key, const uint16_t klen, const char *val, const uint32_t vlen, const void *cookie) |
Callback for any function producing stats.
key | the stat's key | |
klen | length of the key | |
val | the stat's value in an ascii form (e.g. text form of a number) | |
vlen | length of the value cookie magic callback cookie |
typedef unsigned int rel_time_t |
Time relative to server start.
Smaller than time_t on 64-bit systems.
enum bin_substates |
enum conn_states |
Possible states of a connection.
enum protocol |
enum store_item_type |
void accept_new_conns | ( | const bool | do_accept | ) |
bool conn_add_to_freelist | ( | conn * | c | ) |
conn* conn_from_freelist | ( | void | ) |
conn* conn_new | ( | const int | sfd, | |
const enum conn_states | init_state, | |||
const int | event_flags, | |||
const int | read_buffer_size, | |||
enum protocol | prot, | |||
struct event_base * | base | |||
) |
int daemonize | ( | int | nochdir, | |
int | noclose | |||
) |
void dispatch_conn_new | ( | int | sfd, | |
enum conn_states | init_state, | |||
int | event_flags, | |||
int | read_buffer_size, | |||
enum protocol | prot | |||
) |
int dispatch_event_add | ( | int | thread, | |
conn * | c | |||
) |
void do_accept_new_conns | ( | const bool | do_accept | ) |
enum store_item_type do_store_item | ( | item * | item, | |
int | comm, | |||
conn * | c | |||
) |
int is_listen_thread | ( | void | ) |
item* item_alloc | ( | char * | key, | |
size_t | nkey, | |||
int | flags, | |||
rel_time_t | exptime, | |||
int | nbytes | |||
) |
char* item_cachedump | ( | const unsigned int | slabs_clsid, | |
const unsigned int | limit, | |||
unsigned int * | bytes | |||
) |
void item_flush_expired | ( | void | ) |
item* item_get | ( | const char * | key, | |
const size_t | nkey | |||
) |
int item_link | ( | item * | it | ) |
void item_remove | ( | item * | it | ) |
void item_stats | ( | ADD_STAT | add_stats, | |
void * | c | |||
) |
void item_stats_sizes | ( | ADD_STAT | add_stats, | |
void * | c | |||
) |
void item_unlink | ( | item * | it | ) |
void item_update | ( | item * | it | ) |
void slab_stats_aggregate | ( | struct thread_stats * | stats, | |
struct slab_stats * | out | |||
) |
void STATS_LOCK | ( | void | ) |
void STATS_UNLOCK | ( | void | ) |
enum store_item_type store_item | ( | item * | item, | |
int | comm, | |||
conn * | c | |||
) |
void thread_init | ( | int | nthreads, | |
struct event_base * | main_base | |||
) |
void threadlocal_stats_aggregate | ( | struct thread_stats * | stats | ) |
void threadlocal_stats_reset | ( | void | ) |
volatile rel_time_t current_time |
time_t process_started |