memcached.h File Reference

The main memcached header holding commonly used data structures and function prototypes. More...

#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"

Include dependency graph for memcached.h:

This graph shows which files directly or indirectly include this file:

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)
connconn_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)
connconn_from_freelist (void)
bool conn_add_to_freelist (conn *c)
int is_listen_thread (void)
itemitem_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)
itemitem_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


Detailed Description

The main memcached header holding commonly used data structures and function prototypes.


Define Documentation

#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);
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 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 == ascii_udp_prot)

#define ITEM_CAS   2

#define ITEM_data ( item   ) 

Value:

((char*) &((item)->end[0]) + (item)->nkey + 1 \
         + (item)->nsuffix \
         + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))

#define ITEM_get_cas (  ) 

Value:

((uint64_t)(((i)->it_flags & ITEM_CAS) ? \
                                    *(uint64_t*)&((i)->end[0]) : 0x0))

#define ITEM_key ( item   ) 

Value:

(((char*)&((item)->end[0])) \
         + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))

#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   ) 

Value:

(sizeof(struct _stritem) + (item)->nkey + 1 \
         + (item)->nsuffix + (item)->nbytes \
         + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))

#define ITEM_set_cas ( i,
 ) 

Value:

{ if ((i)->it_flags & ITEM_CAS) { \
                          *(uint64_t*)&((i)->end[0]) = v; } }

#define ITEM_SLABBED   4

#define ITEM_suffix ( item   ) 

Value:

((char*) &((item)->end[0]) + (item)->nkey + 1 \
         + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))

#define KEY_MAX_LENGTH   250

Maximum length of a key.

#define likely (  )     __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 (  )     __builtin_expect((x),0)


Typedef Documentation

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.

Parameters:
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 struct conn conn

The structure representing a connection into memcached.

typedef struct _stritem item

Structure for storing items within memcached.

typedef unsigned int rel_time_t

Time relative to server start.

Smaller than time_t on 64-bit systems.


Enumeration Type Documentation

Enumerator:
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 

Possible states of a connection.

Enumerator:
conn_listening  the socket which listens for connections
conn_new_cmd  Prepare connection for next command.
conn_waiting  waiting for a readable socket
conn_read  reading in a command line
conn_parse_cmd  try to parse a command from the input buffer
conn_write  writing out a simple response
conn_nread  reading in a fixed number of bytes
conn_swallow  swallowing unnecessary bytes w/o storing
conn_closing  closing this connection
conn_mwrite  writing out many items sequentially
conn_max_state  Max state value (used for assertion).

enum protocol

Enumerator:
ascii_prot 
ascii_udp_prot 
binary_prot 
negotiating_prot 

Enumerator:
NOT_STORED 
STORED 
EXISTS 
NOT_FOUND 


Function Documentation

void accept_new_conns ( const bool  do_accept  ) 

Here is the call graph for this function:

char* add_delta ( conn c,
item item,
const int  incr,
const int64_t  delta,
char *  buf 
)

Here is the call graph for this function:

void append_stat ( const char *  name,
ADD_STAT  add_stats,
conn c,
const char *  fmt,
  ... 
)

bool conn_add_to_freelist ( conn c  ) 

Here is the caller graph for this function:

conn* conn_from_freelist ( void   ) 

Here is the caller graph for this function:

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 
)

Here is the call graph for this function:

int daemonize ( int  nochdir,
int  noclose 
)

Here is the caller graph for this function:

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  ) 

Here is the call graph for this function:

Here is the caller graph for this function:

char* do_add_delta ( conn c,
item item,
const bool  incr,
const int64_t  delta,
char *  buf 
)

Here is the call graph for this function:

Here is the caller graph for this function:

enum store_item_type do_store_item ( item item,
int  comm,
conn c 
)

Here is the call graph for this function:

Here is the caller graph for this function:

int is_listen_thread ( void   ) 

item* item_alloc ( char *  key,
size_t  nkey,
int  flags,
rel_time_t  exptime,
int  nbytes 
)

Here is the call graph for this function:

char* item_cachedump ( const unsigned int  slabs_clsid,
const unsigned int  limit,
unsigned int *  bytes 
)

Here is the call graph for this function:

void item_flush_expired ( void   ) 

Here is the call graph for this function:

item* item_get ( const char *  key,
const size_t  nkey 
)

Here is the call graph for this function:

int item_link ( item it  ) 

Here is the call graph for this function:

void item_remove ( item it  ) 

Here is the call graph for this function:

int item_replace ( item it,
item new_it 
)

Here is the call graph for this function:

Here is the caller graph for this function:

void item_stats ( ADD_STAT  add_stats,
void *  c 
)

Here is the call graph for this function:

Here is the caller graph for this function:

void item_stats_sizes ( ADD_STAT  add_stats,
void *  c 
)

Here is the call graph for this function:

Here is the caller graph for this function:

void item_unlink ( item it  ) 

Here is the call graph for this function:

void item_update ( item it  ) 

Here is the call graph for this function:

void slab_stats_aggregate ( struct thread_stats stats,
struct slab_stats out 
)

void STATS_LOCK ( void   ) 

Here is the caller graph for this function:

void STATS_UNLOCK ( void   ) 

Here is the caller graph for this function:

enum store_item_type store_item ( item item,
int  comm,
conn c 
)

Here is the call graph for this function:

void thread_init ( int  nthreads,
struct event_base *  main_base 
)

Here is the caller graph for this function:

void threadlocal_stats_aggregate ( struct thread_stats stats  ) 

void threadlocal_stats_reset ( void   ) 


Variable Documentation

struct stats stats

exported globals


Generated on Fri Apr 17 16:28:22 2009 for memcached by  doxygen 1.5.8