MySQL  8.0.18
Source Code Documentation
memcached.h File Reference

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

#include <pthread.h>
#include <config_static.h>
#include <memcached/protocol_binary.h>
#include <memcached/engine.h>
#include <memcached/extension.h>
#include "cache.h"
#include "topkeys.h"
#include "sasl_defs.h"
#include "stats.h"
#include "trace.h"
#include "hash.h"
#include <memcached/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  independent_stats
 The stats structure the engine keeps track of. More...
 
struct  stats
 Global stats. More...
 
struct  settings
 Globally accessible settings as derived from the commandline. More...
 
struct  engine_event_handler
 
struct  LIBEVENT_THREAD
 
struct  conn
 The structure representing a connection into memcached. More...
 

Macros

#define KEY_MAX_LENGTH   250
 Maximum length of a key. More...
 
#define INCR_MAX_STORAGE_LEN   24
 Size of an incr buf. More...
 
#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". More...
 
#define SUFFIX_LIST_INITIAL   20
 Initial size of list of CAS suffixes appended to "gets" lines. More...
 
#define IOV_LIST_INITIAL   400
 Initial size of the sendmsg() scatter/gather array. More...
 
#define MSG_LIST_INITIAL   10
 Initial number of sendmsg() argument structures to allocate. More...
 
#define READ_BUFFER_HIGHWAT   8192
 High water marks for buffer shrinking. More...
 
#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 CHUNK_ALIGN_BYTES   8
 
#define DONT_PREALLOC_SLABS
 
#define MAX_NUMBER_OF_SLAB_CLASSES   (POWER_LARGEST + 1)
 
#define STAT_KEY_LEN   128
 
#define STAT_VAL_LEN   128
 
#define DEFAULT_REQS_PER_EVENT   20
 
#define DEFAULT_REQS_PER_TAP_EVENT   50
 
#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. More...
 
#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. More...
 
#define APPEND_NUM_STAT(num, name, fmt, val)   APPEND_NUM_FMT_STAT("%d:%s", num, name, fmt, val)
 Common APPEND_NUM_FMT_STAT format. More...
 
#define IS_UDP(x)   (x == udp_transport)
 
#define MAX_VERBOSITY_LEVEL   2
 
#define LOCK_THREAD(t)
 
#define UNLOCK_THREAD(t)
 
#define LIST_STATE_PROCESSING   1
 
#define LIST_STATE_REQ_PENDING_IO   2
 
#define LIST_STATE_REQ_PENDING_CLOSE   4
 
#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 struct conn conn
 
typedef bool(* STATE_FUNC) (conn *)
 

Enumerations

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, bin_reading_sasl_auth, bin_reading_sasl_auth_data, bin_reading_packet
}
 
enum  protocol { ascii_prot = 3, binary_prot, negotiating_prot }
 
enum  network_transport { local_transport, tcp_transport, udp_transport }
 
enum  thread_type { GENERAL = 11, TAP = 13, DISPATCHER = 15 }
 

Functions

void notify_thread (LIBEVENT_THREAD *thread)
 
void notify_dispatcher (void)
 
bool create_notification_pipe (LIBEVENT_THREAD *me)
 
connconn_new (const SOCKET sfd, STATE_FUNC init_state, const int event_flags, const int read_buffer_size, enum network_transport transport, struct event_base *base, struct timeval *timeout)
 
int daemonize (int nochdir, int noclose)
 
bool register_event (conn *c, struct timeval *timeout)
 
bool unregister_event (conn *c)
 
bool update_event (conn *c, const int new_flags)
 
void thread_init (int nthreads, struct event_base *main_base, void(*dispatcher_callback)(int, short, void *))
 
void threads_shutdown (void)
 
int dispatch_event_add (int thread, conn *c)
 
void dispatch_conn_new (SOCKET sfd, STATE_FUNC init_state, int event_flags, int read_buffer_size, enum network_transport transport)
 
void accept_new_conns (const bool do_accept)
 
connconn_from_freelist (void)
 
bool conn_add_to_freelist (conn *c)
 
int is_listen_thread (void)
 
void STATS_LOCK (void)
 
void STATS_UNLOCK (void)
 
void threadlocal_stats_clear (struct thread_stats *stats)
 
void threadlocal_stats_reset (struct thread_stats *thread_stats)
 
void threadlocal_stats_aggregate (struct thread_stats *thread_stats, 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,...)
 
void notify_io_complete (const void *cookie, ENGINE_ERROR_CODE status)
 
void conn_set_state (conn *c, STATE_FUNC state)
 
const char * state_text (STATE_FUNC state)
 Convert a state name to a human readable form. More...
 
void safe_close (SOCKET sfd)
 
int number_of_pending (conn *c, conn *pending)
 
bool has_cycle (conn *c)
 
bool list_contains (conn *h, conn *n)
 
connlist_remove (conn *h, conn *n)
 
size_t list_to_array (conn **dest, size_t max_items, conn **l)
 
void enlist_conn (conn *c, conn **list)
 
void finalize_list (conn **list, size_t items)
 
bool set_socket_nonblocking (SOCKET sfd)
 
void conn_close (conn *c)
 
bool conn_listening (conn *c)
 
bool conn_new_cmd (conn *c)
 
bool conn_waiting (conn *c)
 
bool conn_read (conn *c)
 
bool conn_parse_cmd (conn *c)
 
bool conn_write (conn *c)
 
bool conn_nread (conn *c)
 
bool conn_swallow (conn *c)
 
bool conn_pending_close (conn *c)
 
bool conn_immediate_close (conn *c)
 
bool conn_closing (conn *c)
 
bool conn_mwrite (conn *c)
 
bool conn_ship_log (conn *c)
 Ship tap log to the other end. More...
 
bool conn_add_tap_client (conn *c)
 
bool conn_setup_tap_stream (conn *c)
 

Variables

struct stats stats
 exported globals More...
 
struct settings settings
 
LIBEVENT_THREADtap_thread
 

Detailed Description

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

Macro Definition Documentation

◆ __builtin_expect

#define __builtin_expect (   x,
  expected_value 
)    (x)

◆ APPEND_NUM_FMT_STAT

#define APPEND_NUM_FMT_STAT (   name_fmt,
  num,
  name,
  fmt,
  val 
)
Value:
klen = snprintf(key_str, STAT_KEY_LEN, name_fmt, num, name); \
vlen = snprintf(val_str, STAT_VAL_LEN, fmt, val); \
add_stats(key_str, klen, val_str, vlen, c);
const string name("\ame\)
#define STAT_VAL_LEN
Definition: memcached.h:77
#define STAT_KEY_LEN
Definition: memcached.h:76

Append an indexed stat with a stat name (with format), value format and value.

◆ APPEND_NUM_STAT

#define APPEND_NUM_STAT (   num,
  name,
  fmt,
  val 
)    APPEND_NUM_FMT_STAT("%d:%s", num, name, fmt, val)

Common APPEND_NUM_FMT_STAT format.

◆ APPEND_STAT

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

◆ BIN_PKT_HDR_WORDS

#define BIN_PKT_HDR_WORDS   (MIN_BIN_PKT_LENGTH/sizeof(uint32_t))

◆ CHUNK_ALIGN_BYTES

#define CHUNK_ALIGN_BYTES   8

◆ DATA_BUFFER_SIZE

#define DATA_BUFFER_SIZE   2048

◆ DEFAULT_REQS_PER_EVENT

#define DEFAULT_REQS_PER_EVENT   20

◆ DEFAULT_REQS_PER_TAP_EVENT

#define DEFAULT_REQS_PER_TAP_EVENT   50

◆ DONT_PREALLOC_SLABS

#define DONT_PREALLOC_SLABS

◆ drop_privileges

#define drop_privileges (   void)

◆ INCR_MAX_STORAGE_LEN

#define INCR_MAX_STORAGE_LEN   24

Size of an incr buf.

◆ IOV_LIST_HIGHWAT

#define IOV_LIST_HIGHWAT   600

◆ IOV_LIST_INITIAL

#define IOV_LIST_INITIAL   400

Initial size of the sendmsg() scatter/gather array.

◆ IS_UDP

#define IS_UDP (   x)    (x == udp_transport)

◆ ITEM_LIST_HIGHWAT

#define ITEM_LIST_HIGHWAT   400

◆ ITEM_LIST_INITIAL

#define ITEM_LIST_INITIAL   200

Initial size of list of items being returned by "get".

◆ KEY_MAX_LENGTH

#define KEY_MAX_LENGTH   250

Maximum length of a key.

◆ likely

#define likely (   x)    __builtin_expect((x),1)

◆ LIST_STATE_PROCESSING

#define LIST_STATE_PROCESSING   1

◆ LIST_STATE_REQ_PENDING_CLOSE

#define LIST_STATE_REQ_PENDING_CLOSE   4

◆ LIST_STATE_REQ_PENDING_IO

#define LIST_STATE_REQ_PENDING_IO   2

◆ LOCK_THREAD

#define LOCK_THREAD (   t)
Value:
if (pthread_mutex_lock(&t->mutex) != 0) { \
abort(); \
} \
assert(t->is_locked == false); \
t->is_locked = true;

◆ MAX_NUMBER_OF_SLAB_CLASSES

#define MAX_NUMBER_OF_SLAB_CLASSES   (POWER_LARGEST + 1)

◆ MAX_SENDBUF_SIZE

#define MAX_SENDBUF_SIZE   (256 * 1024 * 1024)

◆ MAX_VERBOSITY_LEVEL

#define MAX_VERBOSITY_LEVEL   2

◆ MIN_BIN_PKT_LENGTH

#define MIN_BIN_PKT_LENGTH   16

◆ MSG_LIST_HIGHWAT

#define MSG_LIST_HIGHWAT   100

◆ MSG_LIST_INITIAL

#define MSG_LIST_INITIAL   10

Initial number of sendmsg() argument structures to allocate.

◆ POWER_LARGEST

#define POWER_LARGEST   200

◆ POWER_SMALLEST

#define POWER_SMALLEST   1

◆ READ_BUFFER_HIGHWAT

#define READ_BUFFER_HIGHWAT   8192

High water marks for buffer shrinking.

◆ STAT_KEY_LEN

#define STAT_KEY_LEN   128

◆ STAT_VAL_LEN

#define STAT_VAL_LEN   128

◆ SUFFIX_LIST_INITIAL

#define SUFFIX_LIST_INITIAL   20

Initial size of list of CAS suffixes appended to "gets" lines.

◆ SUFFIX_SIZE

#define SUFFIX_SIZE   24

◆ UDP_HEADER_SIZE

#define UDP_HEADER_SIZE   8

◆ UDP_MAX_PAYLOAD_SIZE

#define UDP_MAX_PAYLOAD_SIZE   1400

◆ UDP_READ_BUFFER_SIZE

#define UDP_READ_BUFFER_SIZE   65536

◆ unlikely

#define unlikely (   x)    __builtin_expect((x),0)

◆ UNLOCK_THREAD

#define UNLOCK_THREAD (   t)
Value:
assert(t->is_locked == true); \
t->is_locked = false; \
if (pthread_mutex_unlock(&t->mutex) != 0) { \
abort(); \
}

Typedef Documentation

◆ conn

typedef struct conn conn

◆ STATE_FUNC

typedef bool(* STATE_FUNC) (conn *)

Enumeration Type Documentation

◆ bin_substates

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 
bin_reading_sasl_auth 
bin_reading_sasl_auth_data 
bin_reading_packet 

◆ network_transport

Enumerator
local_transport 
tcp_transport 
udp_transport 

◆ protocol

enum protocol
Enumerator
ascii_prot 
binary_prot 
negotiating_prot 

◆ thread_type

Enumerator
GENERAL 
TAP 
DISPATCHER 

Function Documentation

◆ accept_new_conns()

void accept_new_conns ( const bool  do_accept)

◆ append_stat()

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

◆ conn_add_tap_client()

bool conn_add_tap_client ( conn c)

◆ conn_add_to_freelist()

bool conn_add_to_freelist ( conn c)

◆ conn_close()

void conn_close ( conn c)

◆ conn_closing()

bool conn_closing ( conn c)

◆ conn_from_freelist()

conn* conn_from_freelist ( void  )

◆ conn_immediate_close()

bool conn_immediate_close ( conn c)

◆ conn_listening()

bool conn_listening ( conn c)

◆ conn_mwrite()

bool conn_mwrite ( conn c)

◆ conn_new()

conn* conn_new ( const SOCKET  sfd,
STATE_FUNC  init_state,
const int  event_flags,
const int  read_buffer_size,
enum network_transport  transport,
struct event_base *  base,
struct timeval *  timeout 
)

◆ conn_new_cmd()

bool conn_new_cmd ( conn c)

◆ conn_nread()

bool conn_nread ( conn c)

◆ conn_parse_cmd()

bool conn_parse_cmd ( conn c)

◆ conn_pending_close()

bool conn_pending_close ( conn c)

◆ conn_read()

bool conn_read ( conn c)

◆ conn_set_state()

void conn_set_state ( conn c,
STATE_FUNC  state 
)

◆ conn_setup_tap_stream()

bool conn_setup_tap_stream ( conn c)

◆ conn_ship_log()

bool conn_ship_log ( conn c)

Ship tap log to the other end.

This state differs with all other states in the way that it support full duplex dialog. We're listening to both read and write events from libevent most of the time. If a read event occurs we switch to the conn_read state to read and execute the input message (that would be an ack message from the other side). If a write event occurs we continue to send tap log to the other end.

Parameters
cthe tap connection to drive
Returns
true if we should continue to process work for this connection, false if we should start processing events for other connections.

◆ conn_swallow()

bool conn_swallow ( conn c)

◆ conn_waiting()

bool conn_waiting ( conn c)

◆ conn_write()

bool conn_write ( conn c)

◆ create_notification_pipe()

bool create_notification_pipe ( LIBEVENT_THREAD me)

◆ daemonize()

int daemonize ( int  nochdir,
int  noclose 
)

◆ dispatch_conn_new()

void dispatch_conn_new ( SOCKET  sfd,
STATE_FUNC  init_state,
int  event_flags,
int  read_buffer_size,
enum network_transport  transport 
)

◆ dispatch_event_add()

int dispatch_event_add ( int  thread,
conn c 
)

◆ enlist_conn()

void enlist_conn ( conn c,
conn **  list 
)

◆ finalize_list()

void finalize_list ( conn **  list,
size_t  items 
)

◆ has_cycle()

bool has_cycle ( conn c)

◆ is_listen_thread()

int is_listen_thread ( void  )

◆ list_contains()

bool list_contains ( conn h,
conn n 
)

◆ list_remove()

conn* list_remove ( conn h,
conn n 
)

◆ list_to_array()

size_t list_to_array ( conn **  dest,
size_t  max_items,
conn **  l 
)

◆ notify_dispatcher()

void notify_dispatcher ( void  )

◆ notify_io_complete()

void notify_io_complete ( const void *  cookie,
ENGINE_ERROR_CODE  status 
)

◆ notify_thread()

void notify_thread ( LIBEVENT_THREAD thread)

◆ number_of_pending()

int number_of_pending ( conn c,
conn pending 
)

◆ register_event()

bool register_event ( conn c,
struct timeval *  timeout 
)

◆ safe_close()

void safe_close ( SOCKET  sfd)

◆ set_socket_nonblocking()

bool set_socket_nonblocking ( SOCKET  sfd)

◆ slab_stats_aggregate()

void slab_stats_aggregate ( struct thread_stats stats,
struct slab_stats out 
)

◆ state_text()

const char* state_text ( STATE_FUNC  state)

Convert a state name to a human readable form.

◆ STATS_LOCK()

void STATS_LOCK ( void  )

◆ STATS_UNLOCK()

void STATS_UNLOCK ( void  )

◆ thread_init()

void thread_init ( int  nthreads,
struct event_base *  main_base,
void(*)(int, short, void *)  dispatcher_callback 
)

◆ threadlocal_stats_aggregate()

void threadlocal_stats_aggregate ( struct thread_stats thread_stats,
struct thread_stats stats 
)

◆ threadlocal_stats_clear()

void threadlocal_stats_clear ( struct thread_stats stats)

◆ threadlocal_stats_reset()

void threadlocal_stats_reset ( struct thread_stats thread_stats)

◆ threads_shutdown()

void threads_shutdown ( void  )

◆ unregister_event()

bool unregister_event ( conn c)

◆ update_event()

bool update_event ( conn c,
const int  new_flags 
)

Variable Documentation

◆ settings

◆ stats

struct stats stats

exported globals

◆ tap_thread

LIBEVENT_THREAD* tap_thread