MySQL  8.0.16
Source Code Documentation
memcached.c File Reference
#include "config.h"
#include "config_static.h"
#include "memcached.h"
#include "memcached/extension_loggers.h"
#include "utilities/engine_loader.h"
#include <signal.h>
#include <getopt.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>
#include <stdarg.h>
#include <stddef.h>
#include <dlfcn.h>
#include "memcached_mysql.h"

Classes

struct  sasl_tmp
 
struct  tap_cmd_stats
 Tap stats (these are only used by the tap thread, so they don't need to be in the threadlocal struct right now... More...
 
struct  tap_stats
 
struct  eng_config_info
 InnoDB Memcached engine configuration info. More...
 

Macros

#define INNODB_MEMCACHED
 
#define SLAB_GUTS(conn, thread_stats, slab_op, thread_op)   thread_stats->slab_stats[info.clsid].slab_op++;
 
#define THREAD_GUTS(conn, thread_stats, slab_op, thread_op)   thread_stats->thread_op++;
 
#define THREAD_GUTS2(conn, thread_stats, slab_op, thread_op)
 
#define SLAB_THREAD_GUTS(conn, thread_stats, slab_op, thread_op)
 
#define STATS_INCR1(GUTS, conn, slab_op, thread_op, key, nkey)
 
#define STATS_INCR(conn, op, key, nkey)   STATS_INCR1(THREAD_GUTS, conn, op, op, key, nkey)
 
#define SLAB_INCR(conn, op, key, nkey)   STATS_INCR1(SLAB_GUTS, conn, op, op, key, nkey)
 
#define STATS_TWO(conn, slab_op, thread_op, key, nkey)   STATS_INCR1(THREAD_GUTS2, conn, slab_op, thread_op, key, nkey)
 
#define SLAB_TWO(conn, slab_op, thread_op, key, nkey)   STATS_INCR1(SLAB_THREAD_GUTS, conn, slab_op, thread_op, key, nkey)
 
#define STATS_HIT(conn, op, key, nkey)   SLAB_TWO(conn, op##_hits, cmd_##op, key, nkey)
 
#define STATS_MISS(conn, op, key, nkey)   STATS_TWO(conn, op##_misses, cmd_##op, key, nkey)
 
#define STATS_NOKEY(conn, op)
 
#define STATS_NOKEY2(conn, op1, op2)
 
#define STATS_ADD(conn, op, amt)
 
#define MEMCACHED_ATOMIC_MSG   "InnoDB Memcached: Memcached DOES NOT use atomic increment"
 
#define REALTIME_MAXDELTA   60*60*24*30
 
#define COMMAND_TOKEN   0
 
#define SUBCOMMAND_TOKEN   1
 
#define KEY_TOKEN   1
 
#define MAX_TOKENS   30
 

Typedefs

typedef void(* RESPONSE_HANDLER) (conn *)
 
typedef struct eng_config_info eng_config_info_t
 

Enumerations

enum  try_read_result { READ_DATA_RECEIVED, READ_NO_DATA_RECEIVED, READ_ERROR, READ_MEMORY_ERROR }
 
enum  transmit_result { TRANSMIT_COMPLETE, TRANSMIT_INCOMPLETE, TRANSMIT_SOFT_ERROR, TRANSMIT_HARD_ERROR }
 

Functions

void my_thread_init ()
 Allocate thread specific memory for the thread, used by mysys and dbug. More...
 
void my_thread_end ()
 Deallocate memory used by the thread for book-keeping. More...
 
static void item_set_cas (const void *cookie, item *it, uint64_t cas)
 
static SOCKET new_socket (struct addrinfo *ai)
 
static int try_read_command (conn *c)
 
static struct independent_statsget_independent_stats (conn *c)
 
static struct thread_statsget_thread_stats (conn *c)
 
static void register_callback (ENGINE_HANDLE *eh, ENGINE_EVENT_TYPE type, EVENT_CALLBACK cb, const void *cb_data)
 
static enum try_read_result try_read_network (conn *c)
 
static enum try_read_result try_read_udp (conn *c)
 
static void stats_init (void)
 
static void server_stats (ADD_STAT add_stats, conn *c, bool aggregate)
 
static void process_stat_settings (ADD_STAT add_stats, void *c)
 
static void settings_init (void)
 
static void event_handler (const int fd, const short which, void *arg)
 
static void complete_nread (conn *c)
 
static char * process_command (conn *c, char *command)
 
static void write_and_free (conn *c, char *buf, int bytes)
 
static int ensure_iov_space (conn *c)
 
static int add_iov (conn *c, const void *buf, int len)
 
static int add_msghdr (conn *c)
 
static void set_current_time (void)
 
static enum transmit_result transmit (conn *c)
 
static void perform_callbacks (ENGINE_EVENT_TYPE type, const void *data, const void *c)
 
static rel_time_t realtime (const time_t exptime)
 
static time_t abstime (const rel_time_t exptime)
 Convert the relative time to an absolute time (relative to EPOC ;) ) More...
 
static void stats_reset (const void *cookie)
 
static const char * prot_text (enum protocol prot)
 
static bool is_listen_disabled (void)
 
static uint64_t get_listen_disabled_num (void)
 
static void disable_listen (void)
 
void safe_close (SOCKET sfd)
 
static bool conn_reset_buffersize (conn *c)
 Reset all of the dynamic buffers used by a connection back to their default sizes. More...
 
static int conn_constructor (void *buffer, void *unused1, int unused2)
 Constructor for all memory allocations of connection objects. More...
 
static void conn_destructor (void *buffer, void *unused)
 Destructor for all connection objects. More...
 
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)
 
static void conn_cleanup (conn *c)
 
void conn_close (conn *c)
 
static void conn_shrink (conn *c)
 
const char * state_text (STATE_FUNC state)
 Convert a state name to a human readable form. More...
 
void conn_set_state (conn *c, STATE_FUNC state)
 
static int build_udp_headers (conn *c)
 
static void out_string (conn *c, const char *str)
 
static void complete_update_ascii (conn *c)
 
static void * binary_get_request (conn *c)
 get a pointer to the start of the request struct for the current command More...
 
static char * binary_get_key (conn *c)
 get a pointer to the key in this request More...
 
static ssize_t key_to_printable_buffer (char *dest, size_t destsz, int client, bool from_client, const char *prefix, const char *key, size_t nkey)
 Insert a key into a buffer, but replace all non-printable characters with a '. More...
 
static ssize_t bytes_to_output_string (char *dest, size_t destsz, int client, bool from_client, const char *prefix, const char *data, size_t size)
 Convert a byte array to a text string. More...
 
static void add_bin_header (conn *c, uint16_t err, uint8_t hdr_len, uint16_t key_len, uint32_t body_len)
 
static protocol_binary_response_status engine_error_2_protocol_error (ENGINE_ERROR_CODE e)
 Convert an error code generated from the storage engine to the corresponding error code used by the protocol layer. More...
 
static void write_bin_packet (conn *c, protocol_binary_response_status err, int swallow)
 
static void write_bin_response (conn *c, void *d, int hlen, int keylen, int dlen)
 
static void complete_incr_bin (conn *c)
 
static void complete_update_bin (conn *c)
 
static void process_bin_get (conn *c)
 
static void append_bin_stats (const char *key, const uint16_t klen, const char *val, const uint32_t vlen, conn *c)
 
static void append_ascii_stats (const char *key, const uint16_t klen, const char *val, const uint32_t vlen, conn *c)
 Append a key-value pair to the stats output buffer. More...
 
static bool grow_dynamic_buffer (conn *c, size_t needed)
 
static void append_stats (const char *key, const uint16_t klen, const char *val, const uint32_t vlen, const void *cookie)
 
static void process_bin_stat (conn *c)
 
static void bin_read_chunk (conn *c, enum bin_substates next_substate, uint32_t chunk)
 
static void bin_read_key (conn *c, enum bin_substates next_substate, int extra)
 
static void handle_binary_protocol_error (conn *c)
 
static void init_sasl_conn (conn *c)
 
static void get_auth_data (const void *cookie, auth_data_t *data)
 
static void process_bin_sasl_auth (conn *c)
 
static void process_bin_complete_sasl_auth (conn *c)
 
static bool authenticated (conn *c)
 
static bool binary_response_handler (const void *key, uint16_t keylen, const void *ext, uint8_t extlen, const void *body, uint32_t bodylen, uint8_t datatype, uint16_t status, uint64_t cas, const void *cookie)
 
static void ship_tap_log (conn *c)
 
static void process_bin_unknown_packet (conn *c)
 
static void process_bin_tap_connect (conn *c)
 
static void process_bin_tap_packet (tap_event_t event, conn *c)
 
static void process_bin_tap_ack (conn *c)
 
static void process_bin_noop_response (conn *c)
 We received a noop response. More...
 
static void process_bin_verbosity (conn *c)
 
static void process_bin_packet (conn *c)
 
static void dispatch_bin_command (conn *c)
 
static void process_bin_update (conn *c)
 
static void process_bin_append_prepend (conn *c)
 
static void process_bin_flush (conn *c)
 
static void process_bin_delete (conn *c)
 
static void complete_nread_binary (conn *c)
 
static void reset_cmd_handler (conn *c)
 
static ENGINE_ERROR_CODE ascii_response_handler (const void *cookie, int nbytes, const char *dta)
 
static void complete_nread_ascii (conn *c)
 
static size_t tokenize_command (char *command, token_t *tokens, const size_t max_tokens)
 
static void detokenize (token_t *tokens, size_t ntokens, char **out, int *nbytes)
 
static bool set_noreply_maybe (conn *c, token_t *tokens, size_t ntokens)
 
void append_stat (const char *name, ADD_STAT add_stats, conn *c, const char *fmt,...)
 
static void process_stats_detail (conn *c, const char *command)
 
static void aggregate_callback (void *in, void *out)
 
static char * process_stat (conn *c, token_t *tokens, const size_t ntokens)
 
static char * get_suffix_buffer (conn *c)
 Get a suffix buffer and insert it into the list of used suffix buffers. More...
 
static char * process_get_command (conn *c, token_t *tokens, size_t ntokens, bool return_cas)
 
static void process_update_command (conn *c, token_t *tokens, const size_t ntokens, ENGINE_STORE_OPERATION store_op, bool handle_cas)
 
static char * process_arithmetic_command (conn *c, token_t *tokens, const size_t ntokens, const bool incr)
 
static char * process_delete_command (conn *c, token_t *tokens, const size_t ntokens)
 
static char * process_bind_command (conn *c, token_t *tokens, const size_t ntokens)
 
static void process_verbosity_command (conn *c, token_t *tokens, const size_t ntokens)
 
bool register_event (conn *c, struct timeval *timeout)
 
bool unregister_event (conn *c)
 
bool update_event (conn *c, const int new_flags)
 
bool conn_listening (conn *c)
 
bool conn_ship_log (conn *c)
 Ship tap log to the other end. More...
 
bool conn_waiting (conn *c)
 
bool conn_read (conn *c)
 
bool conn_parse_cmd (conn *c)
 
bool conn_new_cmd (conn *c)
 
bool conn_swallow (conn *c)
 
bool conn_nread (conn *c)
 
bool conn_write (conn *c)
 
bool conn_mwrite (conn *c)
 
bool conn_pending_close (conn *c)
 
bool conn_immediate_close (conn *c)
 
bool conn_closing (conn *c)
 
bool conn_add_tap_client (conn *c)
 
bool conn_setup_tap_stream (conn *c)
 
static void dispatch_event_handler (int fd, short which, void *arg)
 
static void maximize_sndbuf (const int sfd)
 
static int server_socket (const char *interface, int port, enum network_transport transport, FILE *portnumber_file)
 Create a socket and bind it to a specific port number. More...
 
static int server_sockets (int port, enum network_transport transport, FILE *portnumber_file)
 
static int new_socket_unix (void)
 
static int server_socket_unix (const char *path, int access_mask)
 
static void clock_handler (const int fd, const short which, void *arg)
 
static void usage (void)
 
static void usage_license (void)
 
static void save_pid (const char *pid_file)
 
static void remove_pidfile (const char *pid_file)
 
static int sigignore (int sig)
 
static void sigterm_handler (int sig)
 
static int install_sigterm_handler (void)
 
static int enable_large_pages (void)
 
static const char * get_server_version (void)
 
static void store_engine_specific (const void *cookie, void *engine_data)
 
static void * get_engine_specific (const void *cookie)
 
static int get_socket_fd (const void *cookie)
 
static void set_tap_nack_mode (const void *cookie, bool enable)
 
static void reserve_cookie (const void *cookie)
 
static void release_cookie (const void *cookie)
 
static int num_independent_stats (void)
 
static void * new_independent_stats (void)
 
static void release_independent_stats (void *stats)
 
static rel_time_t get_current_time (void)
 
static void count_eviction (const void *cookie, const void *key, const int nkey)
 
static ENGINE_ERROR_CODE internal_arithmetic (ENGINE_HANDLE *handle, const void *cookie, const void *key, const int nkey, const bool increment, const bool create, const uint64_t delta, const uint64_t initial, const rel_time_t exptime, uint64_t *cas, uint64_t *result, uint16_t vbucket)
 To make it easy for engine implementors that doesn't want to care about writing their own incr/decr code, they can just set the arithmetic function to NULL and use this implementation. More...
 
static bool register_extension (extension_type_t type, void *extension)
 Register an extension if it's not already registered. More...
 
static void unregister_extension (extension_type_t type, void *extension)
 Unregister an extension. More...
 
static void * get_extension (extension_type_t type)
 Get the named extension. More...
 
void shutdown_server (void)
 
bool shutdown_complete (void)
 
bool init_complete (void)
 
static EXTENSION_LOGGER_DESCRIPTOR * get_logger (void)
 
static EXTENSION_LOG_LEVEL get_log_level (void)
 
static void set_log_level (EXTENSION_LOG_LEVEL severity)
 
static void get_config_append_stats (const char *key, const uint16_t klen, const char *val, const uint32_t vlen, const void *cookie)
 
static bool get_config (struct config_item items[])
 
static SERVER_HANDLE_V1 * get_server_api (void)
 Callback the engines may call to get the public server interface. More...
 
static bool load_extension (const char *soname, const char *config)
 Load a shared object and initialize all the extensions in there. More...
 
static bool sanitycheck (void)
 Do basic sanity check of the runtime environment. More...
 
static char * my_strdupl (const char *str, int len)
 
static void daemon_memcached_make_option (char *option, int *option_argc, char ***option_argv)
 Function that messages MySQL config variable string to something that can be parsed by getopt() More...
 
void * daemon_memcached_main (void *p)
 

Variables

volatile sig_atomic_t memcached_shutdown
 
volatile sig_atomic_t memcached_initialized
 
volatile rel_time_t current_time
 
struct stats stats
 exported globals More...
 
struct settings settings
 
static time_t process_started
 
static connlisten_conn = NULL
 file scope variables More...
 
static int udp_socket [100]
 
static int num_udp_socket
 
static struct event_base * main_base
 
static struct independent_statsdefault_independent_stats
 
static struct engine_event_handlerengine_event_handlers [MAX_ENGINE_EVENT_TYPE+1]
 
struct {
   pthread_mutex_t   mutex
 
   bool   disabled
 
   ssize_t   count
 
   uint64_t   num_disable
 
listen_state
 
cache_tconn_cache
 
struct tap_stats tap_stats = { .mutex = PTHREAD_MUTEX_INITIALIZER }
 
static RESPONSE_HANDLER response_handlers [256]
 A map between the response packets op-code and the function to handle the response message. More...
 
static struct event clockevent
 

Macro Definition Documentation

◆ COMMAND_TOKEN

#define COMMAND_TOKEN   0

◆ INNODB_MEMCACHED

#define INNODB_MEMCACHED

◆ KEY_TOKEN

#define KEY_TOKEN   1

◆ MAX_TOKENS

#define MAX_TOKENS   30

◆ MEMCACHED_ATOMIC_MSG

#define MEMCACHED_ATOMIC_MSG   "InnoDB Memcached: Memcached DOES NOT use atomic increment"

◆ REALTIME_MAXDELTA

#define REALTIME_MAXDELTA   60*60*24*30

◆ SLAB_GUTS

#define SLAB_GUTS (   conn,
  thread_stats,
  slab_op,
  thread_op 
)    thread_stats->slab_stats[info.clsid].slab_op++;

◆ SLAB_INCR

#define SLAB_INCR (   conn,
  op,
  key,
  nkey 
)    STATS_INCR1(SLAB_GUTS, conn, op, op, key, nkey)

◆ SLAB_THREAD_GUTS

#define SLAB_THREAD_GUTS (   conn,
  thread_stats,
  slab_op,
  thread_op 
)
Value:
SLAB_GUTS(conn, thread_stats, slab_op, thread_op) \
THREAD_GUTS(conn, thread_stats, slab_op, thread_op)
#define SLAB_GUTS(conn, thread_stats, slab_op, thread_op)
Definition: memcached.c:53
The structure representing a connection into memcached.
Definition: memcached.h:283
Stats stored per-thread.
Definition: memcached.h:138

◆ SLAB_TWO

#define SLAB_TWO (   conn,
  slab_op,
  thread_op,
  key,
  nkey 
)    STATS_INCR1(SLAB_THREAD_GUTS, conn, slab_op, thread_op, key, nkey)

◆ STATS_ADD

#define STATS_ADD (   conn,
  op,
  amt 
)
Value:
{ \
get_thread_stats(conn); \
pthread_mutex_lock(&thread_stats->mutex); \
thread_stats->op += amt; \
pthread_mutex_unlock(&thread_stats->mutex); \
}
The structure representing a connection into memcached.
Definition: memcached.h:283
pthread_mutex_t mutex
Definition: memcached.h:139
Stats stored per-thread.
Definition: memcached.h:138

◆ STATS_HIT

#define STATS_HIT (   conn,
  op,
  key,
  nkey 
)    SLAB_TWO(conn, op##_hits, cmd_##op, key, nkey)

◆ STATS_INCR

#define STATS_INCR (   conn,
  op,
  key,
  nkey 
)    STATS_INCR1(THREAD_GUTS, conn, op, op, key, nkey)

◆ STATS_INCR1

#define STATS_INCR1 (   GUTS,
  conn,
  slab_op,
  thread_op,
  key,
  nkey 
)
Value:
{ \
pthread_mutex_lock(&thread_stats->mutex); \
GUTS(conn, thread_stats, slab_op, thread_op); \
pthread_mutex_unlock(&thread_stats->mutex); \
TK(topkeys, slab_op, key, nkey, current_time); \
}
The stats structure the engine keeps track of.
Definition: memcached.h:161
The structure representing a connection into memcached.
Definition: memcached.h:283
struct thread_stats thread_stats[]
Definition: memcached.h:163
pthread_mutex_t mutex
Definition: memcached.h:139
LIBEVENT_THREAD * thread
Definition: memcached.h:385
Stats stored per-thread.
Definition: memcached.h:138
Definition: topkeys.h:43
static const char * key
Definition: suite_stubs.c:14
topkeys_t * topkeys
Definition: memcached.h:162
static struct independent_stats * get_independent_stats(conn *c)
Definition: memcached.c:6484
volatile rel_time_t current_time
Definition: memcached.c:162
int index
Definition: memcached.h:250

◆ STATS_MISS

#define STATS_MISS (   conn,
  op,
  key,
  nkey 
)    STATS_TWO(conn, op##_misses, cmd_##op, key, nkey)

◆ STATS_NOKEY

#define STATS_NOKEY (   conn,
  op 
)
Value:
{ \
get_thread_stats(conn); \
pthread_mutex_lock(&thread_stats->mutex); \
thread_stats->op++; \
pthread_mutex_unlock(&thread_stats->mutex); \
}
The structure representing a connection into memcached.
Definition: memcached.h:283
pthread_mutex_t mutex
Definition: memcached.h:139
Stats stored per-thread.
Definition: memcached.h:138

◆ STATS_NOKEY2

#define STATS_NOKEY2 (   conn,
  op1,
  op2 
)
Value:
{ \
get_thread_stats(conn); \
pthread_mutex_lock(&thread_stats->mutex); \
thread_stats->op1++; \
thread_stats->op2++; \
pthread_mutex_unlock(&thread_stats->mutex); \
}
The structure representing a connection into memcached.
Definition: memcached.h:283
pthread_mutex_t mutex
Definition: memcached.h:139
Stats stored per-thread.
Definition: memcached.h:138

◆ STATS_TWO

#define STATS_TWO (   conn,
  slab_op,
  thread_op,
  key,
  nkey 
)    STATS_INCR1(THREAD_GUTS2, conn, slab_op, thread_op, key, nkey)

◆ SUBCOMMAND_TOKEN

#define SUBCOMMAND_TOKEN   1

◆ THREAD_GUTS

#define THREAD_GUTS (   conn,
  thread_stats,
  slab_op,
  thread_op 
)    thread_stats->thread_op++;

◆ THREAD_GUTS2

#define THREAD_GUTS2 (   conn,
  thread_stats,
  slab_op,
  thread_op 
)
Value:
thread_stats->slab_op++; \
thread_stats->thread_op++;
Stats stored per-thread.
Definition: memcached.h:138

Typedef Documentation

◆ eng_config_info_t

◆ RESPONSE_HANDLER

typedef void(* RESPONSE_HANDLER) (conn *)

Enumeration Type Documentation

◆ transmit_result

Enumerator
TRANSMIT_COMPLETE 
TRANSMIT_INCOMPLETE 

All done writing.

TRANSMIT_SOFT_ERROR 

More data remaining to write.

TRANSMIT_HARD_ERROR 

Can't write any more right now.

Can't write (c->state is set to conn_closing)

◆ try_read_result

Enumerator
READ_DATA_RECEIVED 
READ_NO_DATA_RECEIVED 
READ_ERROR 
READ_MEMORY_ERROR 

an error occured (on the socket) (or client closed connection)

failed to allocate more memory

Function Documentation

◆ abstime()

static time_t abstime ( const rel_time_t  exptime)
static

Convert the relative time to an absolute time (relative to EPOC ;) )

◆ add_bin_header()

static void add_bin_header ( conn c,
uint16_t  err,
uint8_t  hdr_len,
uint16_t  key_len,
uint32_t  body_len 
)
static

◆ add_iov()

static int add_iov ( conn c,
const void *  buf,
int  len 
)
static

◆ add_msghdr()

static int add_msghdr ( conn c)
static

◆ aggregate_callback()

static void aggregate_callback ( void *  in,
void *  out 
)
static

◆ append_ascii_stats()

static void append_ascii_stats ( const char *  key,
const uint16_t  klen,
const char *  val,
const uint32_t  vlen,
conn c 
)
static

Append a key-value pair to the stats output buffer.

This function assumes that the output buffer is big enough (it will be if you call it through append_stats)

◆ append_bin_stats()

static void append_bin_stats ( const char *  key,
const uint16_t  klen,
const char *  val,
const uint32_t  vlen,
conn c 
)
static

◆ append_stat()

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

◆ append_stats()

static void append_stats ( const char *  key,
const uint16_t  klen,
const char *  val,
const uint32_t  vlen,
const void *  cookie 
)
static

◆ ascii_response_handler()

static ENGINE_ERROR_CODE ascii_response_handler ( const void *  cookie,
int  nbytes,
const char *  dta 
)
static

◆ authenticated()

static bool authenticated ( conn c)
static

◆ bin_read_chunk()

static void bin_read_chunk ( conn c,
enum bin_substates  next_substate,
uint32_t  chunk 
)
static

◆ bin_read_key()

static void bin_read_key ( conn c,
enum bin_substates  next_substate,
int  extra 
)
static

◆ binary_get_key()

static char* binary_get_key ( conn c)
static

get a pointer to the key in this request

◆ binary_get_request()

static void* binary_get_request ( conn c)
static

get a pointer to the start of the request struct for the current command

◆ binary_response_handler()

static bool binary_response_handler ( const void *  key,
uint16_t  keylen,
const void *  ext,
uint8_t  extlen,
const void *  body,
uint32_t  bodylen,
uint8_t  datatype,
uint16_t  status,
uint64_t  cas,
const void *  cookie 
)
static

◆ build_udp_headers()

static int build_udp_headers ( conn c)
static

◆ bytes_to_output_string()

static ssize_t bytes_to_output_string ( char *  dest,
size_t  destsz,
int  client,
bool  from_client,
const char *  prefix,
const char *  data,
size_t  size 
)
static

Convert a byte array to a text string.

Parameters
destwhere to store the output
destszsize of destination buffer
prefixstring to insert before the data
clientthe client we are serving
from_clientset to true if this data is from the client
datathe data to add to the buffer
sizethe number of bytes in data to print
Returns
number of bytes in dest if success, -1 otherwise

◆ clock_handler()

static void clock_handler ( const int  fd,
const short  which,
void *  arg 
)
static

◆ complete_incr_bin()

static void complete_incr_bin ( conn c)
static

◆ complete_nread()

static void complete_nread ( conn c)
static

◆ complete_nread_ascii()

static void complete_nread_ascii ( conn c)
static

◆ complete_nread_binary()

static void complete_nread_binary ( conn c)
static

◆ complete_update_ascii()

static void complete_update_ascii ( conn c)
static

◆ complete_update_bin()

static void complete_update_bin ( conn c)
static

◆ conn_add_tap_client()

bool conn_add_tap_client ( conn c)

◆ conn_cleanup()

static void conn_cleanup ( conn c)
static

◆ conn_close()

void conn_close ( conn c)

◆ conn_closing()

bool conn_closing ( conn c)

◆ conn_constructor()

static int conn_constructor ( void *  buffer,
void *  unused1,
int  unused2 
)
static

Constructor for all memory allocations of connection objects.

Initialize all members and allocate the transfer buffers.

Parameters
bufferThe memory allocated by the object cache
unused1not used
unused2not used
Returns
0 on success, 1 if we failed to allocate memory

◆ conn_destructor()

static void conn_destructor ( void *  buffer,
void *  unused 
)
static

Destructor for all connection objects.

Release all allocated resources.

Parameters
bufferThe memory allocated by the objec cache
unusednot used

◆ 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_reset_buffersize()

static bool conn_reset_buffersize ( conn c)
static

Reset all of the dynamic buffers used by a connection back to their default sizes.

The strategy for resizing the buffers is to allocate a new one of the correct size and free the old one if the allocation succeeds instead of using realloc to change the buffer size (because realloc may not shrink the buffers, and will also copy the memory). If the allocation fails the buffer will be unchanged.

Parameters
cthe connection to resize the buffers for
Returns
true if all allocations succeeded, false if one or more of the allocations failed.

◆ 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_shrink()

static void conn_shrink ( conn c)
static

◆ conn_swallow()

bool conn_swallow ( conn c)

◆ conn_waiting()

bool conn_waiting ( conn c)

◆ conn_write()

bool conn_write ( conn c)

◆ count_eviction()

static void count_eviction ( const void *  cookie,
const void *  key,
const int  nkey 
)
static

◆ daemon_memcached_main()

void* daemon_memcached_main ( void *  p)

◆ daemon_memcached_make_option()

static void daemon_memcached_make_option ( char *  option,
int *  option_argc,
char ***  option_argv 
)
static

Function that messages MySQL config variable string to something that can be parsed by getopt()

◆ detokenize()

static void detokenize ( token_t *  tokens,
size_t  ntokens,
char **  out,
int *  nbytes 
)
static

◆ disable_listen()

static void disable_listen ( void  )
static

◆ dispatch_bin_command()

static void dispatch_bin_command ( conn c)
static

◆ dispatch_event_handler()

static void dispatch_event_handler ( int  fd,
short  which,
void *  arg 
)
static

◆ enable_large_pages()

static int enable_large_pages ( void  )
static

◆ engine_error_2_protocol_error()

static protocol_binary_response_status engine_error_2_protocol_error ( ENGINE_ERROR_CODE  e)
static

Convert an error code generated from the storage engine to the corresponding error code used by the protocol layer.

Parameters
ethe error code as used in the engine
Returns
the error code as used by the protocol layer

◆ ensure_iov_space()

static int ensure_iov_space ( conn c)
static

◆ event_handler()

void event_handler ( const int  fd,
const short  which,
void *  arg 
)
static

◆ get_auth_data()

static void get_auth_data ( const void *  cookie,
auth_data_t *  data 
)
static

◆ get_config()

static bool get_config ( struct config_item  items[])
static

◆ get_config_append_stats()

static void get_config_append_stats ( const char *  key,
const uint16_t  klen,
const char *  val,
const uint32_t  vlen,
const void *  cookie 
)
static

◆ get_current_time()

static rel_time_t get_current_time ( void  )
static

◆ get_engine_specific()

static void* get_engine_specific ( const void *  cookie)
static

◆ get_extension()

static void* get_extension ( extension_type_t  type)
static

Get the named extension.

◆ get_independent_stats()

static struct independent_stats * get_independent_stats ( conn c)
inlinestatic

◆ get_listen_disabled_num()

static uint64_t get_listen_disabled_num ( void  )
static

◆ get_log_level()

static EXTENSION_LOG_LEVEL get_log_level ( void  )
static

◆ get_logger()

static EXTENSION_LOGGER_DESCRIPTOR* get_logger ( void  )
static

◆ get_server_api()

static SERVER_HANDLE_V1* get_server_api ( void  )
static

Callback the engines may call to get the public server interface.

Returns
pointer to a structure containing the interface. The client should know the layout and perform the proper casts.

◆ get_server_version()

static const char* get_server_version ( void  )
static

◆ get_socket_fd()

static int get_socket_fd ( const void *  cookie)
static

◆ get_suffix_buffer()

static char* get_suffix_buffer ( conn c)
static

Get a suffix buffer and insert it into the list of used suffix buffers.

Parameters
cthe connection object
Returns
a pointer to a new suffix buffer or NULL if allocation failed

◆ get_thread_stats()

static struct thread_stats * get_thread_stats ( conn c)
inlinestatic

◆ grow_dynamic_buffer()

static bool grow_dynamic_buffer ( conn c,
size_t  needed 
)
static

◆ handle_binary_protocol_error()

static void handle_binary_protocol_error ( conn c)
static

◆ init_complete()

bool init_complete ( void  )

◆ init_sasl_conn()

static void init_sasl_conn ( conn c)
static

◆ install_sigterm_handler()

static int install_sigterm_handler ( void  )
static

◆ internal_arithmetic()

static ENGINE_ERROR_CODE internal_arithmetic ( ENGINE_HANDLE *  handle,
const void *  cookie,
const void *  key,
const int  nkey,
const bool  increment,
const bool  create,
const uint64_t  delta,
const uint64_t  initial,
const rel_time_t  exptime,
uint64_t *  cas,
uint64_t *  result,
uint16_t  vbucket 
)
static

To make it easy for engine implementors that doesn't want to care about writing their own incr/decr code, they can just set the arithmetic function to NULL and use this implementation.

It is not efficient, due to the fact that it does multiple calls through the interface (get and then cas store). If you don't care, feel free to use it..

◆ is_listen_disabled()

static bool is_listen_disabled ( void  )
static

◆ item_set_cas()

static void item_set_cas ( const void *  cookie,
item *  it,
uint64_t  cas 
)
inlinestatic

◆ key_to_printable_buffer()

static ssize_t key_to_printable_buffer ( char *  dest,
size_t  destsz,
int  client,
bool  from_client,
const char *  prefix,
const char *  key,
size_t  nkey 
)
static

Insert a key into a buffer, but replace all non-printable characters with a '.

'.

Parameters
destwhere to store the output
destszsize of destination buffer
prefixstring to insert before the data
clientthe client we are serving
from_clientset to true if this data is from the client
keythe key to add to the buffer
nkeythe number of bytes in the key
Returns
number of bytes in dest if success, -1 otherwise

◆ load_extension()

static bool load_extension ( const char *  soname,
const char *  config 
)
static

Load a shared object and initialize all the extensions in there.

Parameters
sonamethe name of the shared object (may not be NULL)
configoptional configuration parameters
Returns
true if success, false otherwise

◆ maximize_sndbuf()

static void maximize_sndbuf ( const int  sfd)
static

◆ my_strdupl()

static char* my_strdupl ( const char *  str,
int  len 
)
static

◆ my_thread_end()

void my_thread_end ( )

Deallocate memory used by the thread for book-keeping.

Note
This may be called multiple times for a thread. This happens for example when one calls 'mysql_server_init()' mysql_server_end() and then ends with a mysql_end().

◆ my_thread_init()

void my_thread_init ( )

Allocate thread specific memory for the thread, used by mysys and dbug.

Note
This function may called multiple times for a thread, for example if one uses my_init() followed by mysql_server_init().
Return values
falseok
trueFatal error; mysys/dbug functions can't be used

◆ new_independent_stats()

static void* new_independent_stats ( void  )
static

◆ new_socket()

static SOCKET new_socket ( struct addrinfo *  ai)
static

◆ new_socket_unix()

static int new_socket_unix ( void  )
static

◆ num_independent_stats()

static int num_independent_stats ( void  )
static

◆ out_string()

static void out_string ( conn c,
const char *  str 
)
static

◆ perform_callbacks()

static void perform_callbacks ( ENGINE_EVENT_TYPE  type,
const void *  data,
const void *  c 
)
static

◆ process_arithmetic_command()

static char* process_arithmetic_command ( conn c,
token_t *  tokens,
const size_t  ntokens,
const bool  incr 
)
static

◆ process_bin_append_prepend()

static void process_bin_append_prepend ( conn c)
static

◆ process_bin_complete_sasl_auth()

static void process_bin_complete_sasl_auth ( conn c)
static

◆ process_bin_delete()

static void process_bin_delete ( conn c)
static

◆ process_bin_flush()

static void process_bin_flush ( conn c)
static

◆ process_bin_get()

static void process_bin_get ( conn c)
static

◆ process_bin_noop_response()

static void process_bin_noop_response ( conn c)
static

We received a noop response.

. just ignore it

◆ process_bin_packet()

static void process_bin_packet ( conn c)
static

◆ process_bin_sasl_auth()

static void process_bin_sasl_auth ( conn c)
static

◆ process_bin_stat()

static void process_bin_stat ( conn c)
static

◆ process_bin_tap_ack()

static void process_bin_tap_ack ( conn c)
static

◆ process_bin_tap_connect()

static void process_bin_tap_connect ( conn c)
static

◆ process_bin_tap_packet()

static void process_bin_tap_packet ( tap_event_t  event,
conn c 
)
static

◆ process_bin_unknown_packet()

static void process_bin_unknown_packet ( conn c)
static

◆ process_bin_update()

static void process_bin_update ( conn c)
static

◆ process_bin_verbosity()

static void process_bin_verbosity ( conn c)
static

◆ process_bind_command()

static char* process_bind_command ( conn c,
token_t *  tokens,
const size_t  ntokens 
)
static

◆ process_command()

static char * process_command ( conn c,
char *  command 
)
static

◆ process_delete_command()

static char* process_delete_command ( conn c,
token_t *  tokens,
const size_t  ntokens 
)
static

◆ process_get_command()

static char* process_get_command ( conn c,
token_t *  tokens,
size_t  ntokens,
bool  return_cas 
)
inlinestatic

◆ process_stat()

static char* process_stat ( conn c,
token_t *  tokens,
const size_t  ntokens 
)
static

◆ process_stat_settings()

static void process_stat_settings ( ADD_STAT  add_stats,
void *  c 
)
static

◆ process_stats_detail()

static void process_stats_detail ( conn c,
const char *  command 
)
inlinestatic

◆ process_update_command()

static void process_update_command ( conn c,
token_t *  tokens,
const size_t  ntokens,
ENGINE_STORE_OPERATION  store_op,
bool  handle_cas 
)
static

◆ process_verbosity_command()

static void process_verbosity_command ( conn c,
token_t *  tokens,
const size_t  ntokens 
)
static

◆ prot_text()

static const char* prot_text ( enum protocol  prot)
static

◆ realtime()

static rel_time_t realtime ( const time_t  exptime)
static

◆ register_callback()

static void register_callback ( ENGINE_HANDLE *  eh,
ENGINE_EVENT_TYPE  type,
EVENT_CALLBACK  cb,
const void *  cb_data 
)
static

◆ register_event()

bool register_event ( conn c,
struct timeval *  timeout 
)

◆ register_extension()

static bool register_extension ( extension_type_t  type,
void *  extension 
)
static

Register an extension if it's not already registered.

Parameters
typethe type of the extension to register
extensionthe extension to register
Returns
true if success, false otherwise

◆ release_cookie()

static void release_cookie ( const void *  cookie)
static

◆ release_independent_stats()

static void release_independent_stats ( void *  stats)
static

◆ remove_pidfile()

static void remove_pidfile ( const char *  pid_file)
static

◆ reserve_cookie()

static void reserve_cookie ( const void *  cookie)
static

◆ reset_cmd_handler()

static void reset_cmd_handler ( conn c)
static

◆ safe_close()

void safe_close ( SOCKET  sfd)

◆ sanitycheck()

static bool sanitycheck ( void  )
static

Do basic sanity check of the runtime environment.

Returns
true if no errors found, false if we can't use this env

◆ save_pid()

static void save_pid ( const char *  pid_file)
static

◆ server_socket()

static int server_socket ( const char *  interface,
int  port,
enum network_transport  transport,
FILE *  portnumber_file 
)
static

Create a socket and bind it to a specific port number.

Parameters
interfacethe interface to bind to
portthe port number to bind to
transportthe transport protocol (TCP / UDP)
portnumber_fileA filepointer to write the port numbers to when they are successfully added to the list of ports we listen on.

◆ server_socket_unix()

static int server_socket_unix ( const char *  path,
int  access_mask 
)
static

◆ server_sockets()

static int server_sockets ( int  port,
enum network_transport  transport,
FILE *  portnumber_file 
)
static

◆ server_stats()

static void server_stats ( ADD_STAT  add_stats,
conn c,
bool  aggregate 
)
static

◆ set_current_time()

static void set_current_time ( void  )
static

◆ set_log_level()

static void set_log_level ( EXTENSION_LOG_LEVEL  severity)
static

◆ set_noreply_maybe()

static bool set_noreply_maybe ( conn c,
token_t *  tokens,
size_t  ntokens 
)
inlinestatic

◆ set_tap_nack_mode()

static void set_tap_nack_mode ( const void *  cookie,
bool  enable 
)
static

◆ settings_init()

static void settings_init ( void  )
static

◆ ship_tap_log()

static void ship_tap_log ( conn c)
static

◆ shutdown_complete()

bool shutdown_complete ( void  )

◆ shutdown_server()

void shutdown_server ( void  )

◆ sigignore()

static int sigignore ( int  sig)
static

◆ sigterm_handler()

static void sigterm_handler ( int  sig)
static

◆ state_text()

const char* state_text ( STATE_FUNC  state)

Convert a state name to a human readable form.

◆ stats_init()

static void stats_init ( void  )
static

◆ stats_reset()

static void stats_reset ( const void *  cookie)
static

◆ store_engine_specific()

static void store_engine_specific ( const void *  cookie,
void *  engine_data 
)
static

◆ tokenize_command()

static size_t tokenize_command ( char *  command,
token_t *  tokens,
const size_t  max_tokens 
)
static

◆ transmit()

static enum transmit_result transmit ( conn c)
static

◆ try_read_command()

static int try_read_command ( conn c)
static

◆ try_read_network()

static enum try_read_result try_read_network ( conn c)
static

◆ try_read_udp()

static enum try_read_result try_read_udp ( conn c)
static

◆ unregister_event()

bool unregister_event ( conn c)

◆ unregister_extension()

static void unregister_extension ( extension_type_t  type,
void *  extension 
)
static

Unregister an extension.

Parameters
typethe type of the extension to remove
extensionthe extension to remove

◆ update_event()

bool update_event ( conn c,
const int  new_flags 
)

◆ usage()

static void usage ( void  )
static

◆ usage_license()

static void usage_license ( void  )
static

◆ write_and_free()

static void write_and_free ( conn c,
char *  buf,
int  bytes 
)
static

◆ write_bin_packet()

static void write_bin_packet ( conn c,
protocol_binary_response_status  err,
int  swallow 
)
static

◆ write_bin_response()

static void write_bin_response ( conn c,
void *  d,
int  hlen,
int  keylen,
int  dlen 
)
static

Variable Documentation

◆ clockevent

struct event clockevent
static

◆ conn_cache

cache_t* conn_cache

◆ count

ssize_t count

◆ current_time

volatile rel_time_t current_time

◆ default_independent_stats

struct independent_stats* default_independent_stats
static

◆ disabled

bool disabled

◆ engine_event_handlers

struct engine_event_handler* engine_event_handlers[MAX_ENGINE_EVENT_TYPE+1]
static

◆ listen_conn

conn* listen_conn = NULL
static

file scope variables

◆ listen_state

struct { ... } listen_state

◆ main_base

struct event_base* main_base
static

◆ memcached_initialized

volatile sig_atomic_t memcached_initialized

◆ memcached_shutdown

volatile sig_atomic_t memcached_shutdown

◆ mutex

pthread_mutex_t mutex

◆ num_disable

uint64_t num_disable

◆ num_udp_socket

int num_udp_socket
static

◆ process_started

time_t process_started
static

◆ response_handlers

RESPONSE_HANDLER response_handlers[256]
static
Initial value:
= {
[PROTOCOL_BINARY_CMD_NOOP] = process_bin_noop_response,
[PROTOCOL_BINARY_CMD_TAP_MUTATION] = process_bin_tap_ack,
[PROTOCOL_BINARY_CMD_TAP_DELETE] = process_bin_tap_ack,
[PROTOCOL_BINARY_CMD_TAP_FLUSH] = process_bin_tap_ack,
[PROTOCOL_BINARY_CMD_TAP_OPAQUE] = process_bin_tap_ack,
[PROTOCOL_BINARY_CMD_TAP_VBUCKET_SET] = process_bin_tap_ack,
[PROTOCOL_BINARY_CMD_TAP_CHECKPOINT_START] = process_bin_tap_ack,
[PROTOCOL_BINARY_CMD_TAP_CHECKPOINT_END] = process_bin_tap_ack
}
static void process_bin_noop_response(conn *c)
We received a noop response.
Definition: memcached.c:2813
static void process_bin_tap_ack(conn *c)
Definition: memcached.c:2786

A map between the response packets op-code and the function to handle the response message.

◆ settings

◆ stats

struct stats stats

exported globals

◆ tap_stats

struct tap_stats tap_stats = { .mutex = PTHREAD_MUTEX_INITIALIZER }

◆ udp_socket

int udp_socket[100]
static