Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 498 lines (420 sloc) 16.557 kB
f6d334e @bradfitz 2003-06-10
bradfitz authored
1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
c6975ef Part 1 of the Windows compatibility patch
Paul Lindner authored
2
cf1b755 @dustin More docs.
dustin authored
3 /** \file
4 * The main memcached header holding commonly used data
5 * structures and function prototypes.
6 */
7
70960eb Add ifdefs around config.h so we can get the windows port working soon
Paul Lindner authored
8 #ifdef HAVE_CONFIG_H
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
9 #include "config.h"
70960eb Add ifdefs around config.h so we can get the windows port working soon
Paul Lindner authored
10 #endif
11
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
12 #include <sys/types.h>
b65aa2a fix for freebsd 6.x (and perhaps others)
Paul Lindner authored
13 #include <sys/socket.h>
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
14 #include <sys/time.h>
15 #include <netinet/in.h>
16 #include <event.h>
a61a690 @BrianAker IPv6 support patch by Brian Aker <brian@tangent.org>
BrianAker authored
17 #include <netdb.h>
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
18 #include <pthread.h>
f1307c4 @dustin SASL auth support.
dustin authored
19 #include <unistd.h>
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
20
a85a6e1 Binary protocol updates from the fourth hackathon.
Trond Norbye authored
21 #include "protocol_binary.h"
4c86fa5 Create a generic cache for objects of same size
Trond Norbye authored
22 #include "cache.h"
a85a6e1 Binary protocol updates from the fourth hackathon.
Trond Norbye authored
23
f1307c4 @dustin SASL auth support.
dustin authored
24 #include "sasl_defs.h"
25
cf1b755 @dustin More docs.
dustin authored
26 /** Maximum length of a key. */
ecdb011 @dustin Fix memory corruption error in stats cachedump.
dustin authored
27 #define KEY_MAX_LENGTH 250
28
7b7bc24 @dustin Enforce limits of add_delta buffer size.
dustin authored
29 /** Size of an incr buf. */
30 #define INCR_MAX_STORAGE_LEN 24
31
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
32 #define DATA_BUFFER_SIZE 2048
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
33 #define UDP_READ_BUFFER_SIZE 65536
34 #define UDP_MAX_PAYLOAD_SIZE 1400
35 #define UDP_HEADER_SIZE 8
36 #define MAX_SENDBUF_SIZE (256 * 1024 * 1024)
420aa2d @bradfitz start of the incr fix, rearranges a bunch, adds util, tests, etc
bradfitz authored
37 /* I'm told the max length of a 64-bit num converted to string is 20 bytes.
b17a0c8 @dormando Fix bugs reported by Tomash Brechko for the new cas patch.
dormando authored
38 * Plus a few for spaces, \r\n, \0 */
39 #define SUFFIX_SIZE 24
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
40
516e7dc Minimal doxygen configuration
Paul Lindner authored
41 /** Initial size of list of items being returned by "get". */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
42 #define ITEM_LIST_INITIAL 200
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
43
e61c0a8 @dormando Dynamic suffix buffer work.
dormando authored
44 /** Initial size of list of CAS suffixes appended to "gets" lines. */
45 #define SUFFIX_LIST_INITIAL 20
46
516e7dc Minimal doxygen configuration
Paul Lindner authored
47 /** Initial size of the sendmsg() scatter/gather array. */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
48 #define IOV_LIST_INITIAL 400
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
49
516e7dc Minimal doxygen configuration
Paul Lindner authored
50 /** Initial number of sendmsg() argument structures to allocate. */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
51 #define MSG_LIST_INITIAL 10
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
52
516e7dc Minimal doxygen configuration
Paul Lindner authored
53 /** High water marks for buffer shrinking */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
54 #define READ_BUFFER_HIGHWAT 8192
55 #define ITEM_LIST_HIGHWAT 400
56 #define IOV_LIST_HIGHWAT 600
57 #define MSG_LIST_HIGHWAT 100
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
58
6aafe58 @dustin Initial binary server implementation.
dustin authored
59 /* Binary protocol stuff */
7cfd343 @dustin Updates for the new binary protocol (draft-stone-memcache-binary-01).…
dustin authored
60 #define MIN_BIN_PKT_LENGTH 16
6aafe58 @dustin Initial binary server implementation.
dustin authored
61 #define BIN_PKT_HDR_WORDS (MIN_BIN_PKT_LENGTH/sizeof(uint32_t))
62
d9b97d8 cleanup unistd.h, better spec file, remove warnings from threads.c
Paul Lindner authored
63 /* unistd.h is here */
64 #if HAVE_UNISTD_H
65 # include <unistd.h>
66 #endif
67
067102a @dustin Moved slab sizing definitions from slabs.c to memcached.h
dustin authored
68 /* Slab sizing definitions. */
69 #define POWER_SMALLEST 1
70 #define POWER_LARGEST 200
71 #define CHUNK_ALIGN_BYTES 8
72 #define DONT_PREALLOC_SLABS
7173856 @dustin Create a more sensible definition for the maximum number of slab clas…
dustin authored
73 #define MAX_NUMBER_OF_SLAB_CLASSES (POWER_LARGEST + 1)
067102a @dustin Moved slab sizing definitions from slabs.c to memcached.h
dustin authored
74
cf1b755 @dustin More docs.
dustin authored
75 /** How long an object can reasonably be assumed to be locked before
76 harvesting it on a low memory condition. */
b8d997e @dustin Define TAIL_REPAIR_TIME as a constant.
dustin authored
77 #define TAIL_REPAIR_TIME (3 * 3600)
78
fcc2c98 @dustin Moved struct definitions below enum declarations.
dustin authored
79 /* warning: don't use these macros with a function, as it evals its arg twice */
80 #define ITEM_get_cas(i) ((uint64_t)(((i)->it_flags & ITEM_CAS) ? \
81 *(uint64_t*)&((i)->end[0]) : 0x0))
82 #define ITEM_set_cas(i,v) { if ((i)->it_flags & ITEM_CAS) { \
83 *(uint64_t*)&((i)->end[0]) = v; } }
84
85 #define ITEM_key(item) (((char*)&((item)->end[0])) \
86 + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))
87
88 #define ITEM_suffix(item) ((char*) &((item)->end[0]) + (item)->nkey + 1 \
89 + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))
90
91 #define ITEM_data(item) ((char*) &((item)->end[0]) + (item)->nkey + 1 \
92 + (item)->nsuffix \
93 + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))
94
95 #define ITEM_ntotal(item) (sizeof(struct _stritem) + (item)->nkey + 1 \
96 + (item)->nsuffix + (item)->nbytes \
97 + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))
98
88a6868 @dustin Clean up some assumed buffer sizes with stats (issue 64).
dustin authored
99 #define STAT_KEY_LEN 128
100 #define STAT_VAL_LEN 128
101
fcc2c98 @dustin Moved struct definitions below enum declarations.
dustin authored
102 /** Append a simple stat with a stat name, value format and value */
103 #define APPEND_STAT(name, fmt, val) \
104 append_stat(name, add_stats, c, fmt, val);
105
106 /** Append an indexed stat with a stat name (with format), value format
107 and value */
88a6868 @dustin Clean up some assumed buffer sizes with stats (issue 64).
dustin authored
108 #define APPEND_NUM_FMT_STAT(name_fmt, num, name, fmt, val) \
109 klen = snprintf(key_str, STAT_KEY_LEN, name_fmt, num, name); \
110 vlen = snprintf(val_str, STAT_VAL_LEN, fmt, val); \
fcc2c98 @dustin Moved struct definitions below enum declarations.
dustin authored
111 add_stats(key_str, klen, val_str, vlen, c);
112
113 /** Common APPEND_NUM_FMT_STAT format. */
114 #define APPEND_NUM_STAT(num, name, fmt, val) \
115 APPEND_NUM_FMT_STAT("%d:%s", num, name, fmt, val)
116
117 /**
118 * Callback for any function producing stats.
119 *
120 * @param key the stat's key
121 * @param klen length of the key
122 * @param val the stat's value in an ascii form (e.g. text form of a number)
123 * @param vlen length of the value
124 * @parm cookie magic callback cookie
125 */
126 typedef void (*ADD_STAT)(const char *key, const uint16_t klen,
127 const char *val, const uint32_t vlen,
128 const void *cookie);
129
130 /*
131 * NOTE: If you modify this table you _MUST_ update the function state_text
132 */
133 /**
134 * Possible states of a connection.
135 */
136 enum conn_states {
137 conn_listening, /**< the socket which listens for connections */
138 conn_new_cmd, /**< Prepare connection for next command */
139 conn_waiting, /**< waiting for a readable socket */
140 conn_read, /**< reading in a command line */
141 conn_parse_cmd, /**< try to parse a command from the input buffer */
142 conn_write, /**< writing out a simple response */
143 conn_nread, /**< reading in a fixed number of bytes */
144 conn_swallow, /**< swallowing unnecessary bytes w/o storing */
145 conn_closing, /**< closing this connection */
146 conn_mwrite, /**< writing out many items sequentially */
147 conn_max_state /**< Max state value (used for assertion) */
148 };
149
150 enum bin_substates {
151 bin_no_state,
152 bin_reading_set_header,
153 bin_reading_cas_header,
154 bin_read_set_value,
155 bin_reading_get_key,
156 bin_reading_stat,
157 bin_reading_del_header,
158 bin_reading_incr_header,
f1307c4 @dustin SASL auth support.
dustin authored
159 bin_read_flush_exptime,
160 bin_reading_sasl_auth,
161 bin_reading_sasl_auth_data
fcc2c98 @dustin Moved struct definitions below enum declarations.
dustin authored
162 };
163
164 enum protocol {
165 ascii_prot = 3, /* arbitrary value. */
166 binary_prot,
167 negotiating_prot /* Discovering the protocol */
168 };
169
170 enum network_transport {
171 local_transport, /* Unix sockets*/
172 tcp_transport,
173 udp_transport
174 };
175
176 #define IS_UDP(x) (x == udp_transport)
177
178 #define NREAD_ADD 1
179 #define NREAD_SET 2
180 #define NREAD_REPLACE 3
181 #define NREAD_APPEND 4
182 #define NREAD_PREPEND 5
183 #define NREAD_CAS 6
184
185 enum store_item_type {
186 NOT_STORED=0, STORED, EXISTS, NOT_FOUND
187 };
188
d044acb @dustin add_delta should return a proper status indicator.
dustin authored
189 enum delta_result_type {
190 OK, NON_NUMERIC, EOM
191 };
fcc2c98 @dustin Moved struct definitions below enum declarations.
dustin authored
192
516e7dc Minimal doxygen configuration
Paul Lindner authored
193 /** Time relative to server start. Smaller than time_t on 64-bit systems. */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
194 typedef unsigned int rel_time_t;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
195
cf1b755 @dustin More docs.
dustin authored
196 /** Stats stored per slab (and per thread). */
25b5189 @dustin Push hit and set stats down into per-slab stats.
dustin authored
197 struct slab_stats {
198 uint64_t set_cmds;
199 uint64_t get_hits;
a77d12b @dustin Added stats for delete commands.
dustin authored
200 uint64_t delete_hits;
15e6462 @dustin Added CAS stats.
dustin authored
201 uint64_t cas_hits;
202 uint64_t cas_badval;
3e03078 @dustin incr/decr stats
dustin authored
203 uint64_t incr_hits;
204 uint64_t decr_hits;
25b5189 @dustin Push hit and set stats down into per-slab stats.
dustin authored
205 };
206
cf1b755 @dustin More docs.
dustin authored
207 /**
208 * Stats stored per-thread.
209 */
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
210 struct thread_stats {
25b5189 @dustin Push hit and set stats down into per-slab stats.
dustin authored
211 pthread_mutex_t mutex;
212 uint64_t get_cmds;
213 uint64_t get_misses;
a77d12b @dustin Added stats for delete commands.
dustin authored
214 uint64_t delete_misses;
3e03078 @dustin incr/decr stats
dustin authored
215 uint64_t incr_misses;
216 uint64_t decr_misses;
15e6462 @dustin Added CAS stats.
dustin authored
217 uint64_t cas_misses;
25b5189 @dustin Push hit and set stats down into per-slab stats.
dustin authored
218 uint64_t bytes_read;
219 uint64_t bytes_written;
534466e @dormando add a cmd_flush stat
dormando authored
220 uint64_t flush_cmds;
a21f819 Issue 61: reqs_per_event handling (-R) is incorrect leading to client…
Trond Norbye authored
221 uint64_t conn_yields; /* # of yields for connections (-R option)*/
5100e7a @ingenthr Added new stats to track sasl authentication.
ingenthr authored
222 uint64_t auth_cmds;
223 uint64_t auth_errors;
25b5189 @dustin Push hit and set stats down into per-slab stats.
dustin authored
224 struct slab_stats slab_stats[MAX_NUMBER_OF_SLAB_CLASSES];
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
225 };
226
cf1b755 @dustin More docs.
dustin authored
227 /**
228 * Global stats.
229 */
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
230 struct stats {
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
231 pthread_mutex_t mutex;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
232 unsigned int curr_items;
233 unsigned int total_items;
c6975ef Part 1 of the Windows compatibility patch
Paul Lindner authored
234 uint64_t curr_bytes;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
235 unsigned int curr_conns;
236 unsigned int total_conns;
237 unsigned int conn_structs;
534466e @dormando add a cmd_flush stat
dormando authored
238 uint64_t get_cmds;
239 uint64_t set_cmds;
240 uint64_t get_hits;
241 uint64_t get_misses;
c6975ef Part 1 of the Windows compatibility patch
Paul Lindner authored
242 uint64_t evictions;
bc340cd @trondn Added reclaimed statistics.
trondn authored
243 uint64_t reclaimed;
3d540bd @dormando two new troubleshooting stats
dormando authored
244 time_t started; /* when the process was started */
0bdda0d @dustin Use a bool for the accepting_conns stat.
dustin authored
245 bool accepting_conns; /* whether we are currently accepting */
3d540bd @dormando two new troubleshooting stats
dormando authored
246 uint64_t listen_disabled_num;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
247 };
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
248
eca55c9 Add patch for changable verbosity levels
Paul Lindner authored
249 #define MAX_VERBOSITY_LEVEL 2
250
5277879 @dustin Added stats settings.
dustin authored
251 /* When adding a setting, be sure to update process_stat_settings */
cf1b755 @dustin More docs.
dustin authored
252 /**
253 * Globally accessible settings as derived from the commandline.
254 */
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
255 struct settings {
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
256 size_t maxbytes;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
257 int maxconns;
258 int port;
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
259 int udpport;
a61a690 @BrianAker IPv6 support patch by Brian Aker <brian@tangent.org>
BrianAker authored
260 char *inter;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
261 int verbose;
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
262 rel_time_t oldest_live; /* ignore existing items older than this */
841811e From: Jason Titus <jtitus@postini.com>
Jason Titus authored
263 int evict_to_free;
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
264 char *socketpath; /* path to unix socket if using local socket */
40c76ce @bremner Patch from David Bremner <bremner@unb.ca> that implements a new optio…
bremner authored
265 int access; /* access mask (a la chmod) for unix domain socket */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
266 double factor; /* chunk size growth factor */
267 int chunk_size;
2fe44f1 Cleanup of number of threads declarations (issue 91)
Dmitry Isaykin authored
268 int num_threads; /* number of worker (without dispatcher) libevent threads to run */
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
269 char prefix_delimiter; /* character that marks a key prefix (for stats) */
270 int detail_enabled; /* nonzero if we're collecting detailed stats */
ca90710 @dormando Prevent starvation by busy threads. This gives a configurable limit t…
dormando authored
271 int reqs_per_event; /* Maximum number of io to process on each
272 io-event. */
eda68b7 Added -C to remove the cas_id from the data structures to save space
Trond Norbye authored
273 bool use_cas;
a155b04 @dustin Allow the binding protocol to be specified.
dustin authored
274 enum protocol binding_protocol;
7d010a8 @lenn0x Added support for setting backlog queue on command line
lenn0x authored
275 int backlog;
bed5f9b @dormando Make item size max start time configurable.
dormando authored
276 int item_size_max; /* Maximum item size, and upper end for slabs */
f1307c4 @dustin SASL auth support.
dustin authored
277 bool sasl; /* SASL on/off */
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
278 };
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
279
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
280 extern struct stats stats;
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
281 extern time_t process_started;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
282 extern struct settings settings;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
283
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
284 #define ITEM_LINKED 1
eda68b7 Added -C to remove the cas_id from the data structures to save space
Trond Norbye authored
285 #define ITEM_CAS 2
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
286
54326f4 @bradfitz more debug
bradfitz authored
287 /* temp */
288 #define ITEM_SLABBED 4
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
289
cf1b755 @dustin More docs.
dustin authored
290 /**
291 * Structure for storing items within memcached.
292 */
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
293 typedef struct _stritem {
294 struct _stritem *next;
295 struct _stritem *prev;
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
296 struct _stritem *h_next; /* hash chain next */
297 rel_time_t time; /* least recent access */
298 rel_time_t exptime; /* expire time */
299 int nbytes; /* size of data */
1ea89bd @bradfitz remove all trailing whitespace, not just first occurrence. :)
bradfitz authored
300 unsigned short refcount;
77dde9f multiple cleanups/refactoring, see ChangeLog
Paul Lindner authored
301 uint8_t nsuffix; /* length of flags-and-length string */
302 uint8_t it_flags; /* ITEM_* above */
303 uint8_t slabs_clsid;/* which slab class we're in */
304 uint8_t nkey; /* key length, w/terminating null and padding */
61f543a Solaris portability fixes from Trond Norbye
Paul Lindner authored
305 void * end[];
eda68b7 Added -C to remove the cas_id from the data structures to save space
Trond Norbye authored
306 /* if it_flags & ITEM_CAS we have 8 bytes CAS */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
307 /* then null-terminated key */
308 /* then " flags length\r\n" (no terminating null) */
309 /* then data with terminating \r\n (no terminating null; it's binary!) */
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
310 } item;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
311
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
312 typedef struct {
313 pthread_t thread_id; /* unique ID of this thread */
314 struct event_base *base; /* libevent handle this thread uses */
315 struct event notify_event; /* listen event for notify pipe */
316 int notify_receive_fd; /* receiving end of notify pipe */
317 int notify_send_fd; /* sending end of notify pipe */
318 struct thread_stats stats; /* Stats generated by this thread */
319 struct conn_queue *new_conn_queue; /* queue of new connections to handle */
4c86fa5 Create a generic cache for objects of same size
Trond Norbye authored
320 cache_t *suffix_cache; /* suffix cache */
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
321 } LIBEVENT_THREAD;
322
2fe44f1 Cleanup of number of threads declarations (issue 91)
Dmitry Isaykin authored
323 typedef struct {
324 pthread_t thread_id; /* unique ID of this thread */
325 struct event_base *base; /* libevent handle this thread uses */
326 } LIBEVENT_DISPATCHER_THREAD;
327
cf1b755 @dustin More docs.
dustin authored
328 /**
329 * The structure representing a connection into memcached.
330 */
9150c85 @BrianAker Support multiple interfaces returned by IPv6 interfaces. By Brian Ake…
BrianAker authored
331 typedef struct conn conn;
332 struct conn {
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
333 int sfd;
f1307c4 @dustin SASL auth support.
dustin authored
334 sasl_conn_t *sasl_conn;
3ed60cd @dustin Ensure all connection states are expressed as enums.
dustin authored
335 enum conn_states state;
d86881e @dustin Use the bin substate enum as well
dustin authored
336 enum bin_substates substate;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
337 struct event event;
338 short ev_flags;
516e7dc Minimal doxygen configuration
Paul Lindner authored
339 short which; /** which events were just triggered */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
340
516e7dc Minimal doxygen configuration
Paul Lindner authored
341 char *rbuf; /** buffer to read commands into */
342 char *rcurr; /** but if we parsed some already, this is where we stopped */
343 int rsize; /** total allocated size of rbuf */
344 int rbytes; /** how much data, starting from rcur, do we have unparsed */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
345
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
346 char *wbuf;
347 char *wcurr;
348 int wsize;
1ea89bd @bradfitz remove all trailing whitespace, not just first occurrence. :)
bradfitz authored
349 int wbytes;
a564b42 @dustin Fix type of write_and_go
dustin authored
350 /** which state to go into after finishing current write */
351 enum conn_states write_and_go;
516e7dc Minimal doxygen configuration
Paul Lindner authored
352 void *write_and_free; /** free this memory after finishing writing */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
353
516e7dc Minimal doxygen configuration
Paul Lindner authored
354 char *ritem; /** when we read in an item's value, it goes here */
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
355 int rlbytes;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
356
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
357 /* data for the nread state */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
358
516e7dc Minimal doxygen configuration
Paul Lindner authored
359 /**
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
360 * item is used to hold an item structure created after reading the command
1ea89bd @bradfitz remove all trailing whitespace, not just first occurrence. :)
bradfitz authored
361 * line of set/add/replace commands, but before we finished reading the actual
7917af4 @bradfitz misc fixes as suggested by avva. lot of comment updates, mostly.
bradfitz authored
362 * data. The data is read into ITEM_data(item) to avoid extra copying.
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
363 */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
364
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
365 void *item; /* for commands set/add/replace */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
366
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
367 /* data for the swallow state */
368 int sbytes; /* how many bytes to swallow */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
369
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
370 /* data for the mwrite state */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
371 struct iovec *iov;
372 int iovsize; /* number of elements allocated in iov[] */
373 int iovused; /* number of elements used in iov[] */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
374
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
375 struct msghdr *msglist;
376 int msgsize; /* number of elements allocated in msglist[] */
377 int msgused; /* number of elements used in msglist[] */
378 int msgcurr; /* element in msglist[] being transmitted now */
379 int msgbytes; /* number of bytes in current msg */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
380
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
381 item **ilist; /* list of items to write out */
382 int isize;
383 item **icurr;
384 int ileft;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
385
e61c0a8 @dormando Dynamic suffix buffer work.
dormando authored
386 char **suffixlist;
387 int suffixsize;
388 char **suffixcurr;
389 int suffixleft;
390
e1407b2 @dustin Handle protocol enums more correctly.
dustin authored
391 enum protocol protocol; /* which protocol this connection speaks */
15ace4b fix and test for issue 38 (server does not respond to binary requests)
Eric Lambert authored
392 enum network_transport transport; /* what transport is used by this connection */
2cdde3e @dustin Added protocol flag to connection for multi-protocol support.
dustin authored
393
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
394 /* data for UDP clients */
395 int request_id; /* Incoming UDP request ID, if this is a UDP "connection" */
396 struct sockaddr request_addr; /* Who sent the most recent request */
397 socklen_t request_addr_size;
398 unsigned char *hdrbuf; /* udp packet headers */
399 int hdrsize; /* number of headers' worth of space is allocated */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
400
d9ece78 @kroki Implement 'noreply' option for update commands. (Tomash Brechko <toma…
kroki authored
401 bool noreply; /* True if the reply should not be sent. */
17df5c0 Don't expose the protocol used to the client api of the stats
Trond Norbye authored
402 /* current stats command */
403 struct {
404 char *buffer;
405 size_t size;
406 size_t offset;
407 } stats;
408
6aafe58 @dustin Initial binary server implementation.
dustin authored
409 /* Binary protocol stuff */
410 /* This is where the binary header goes */
a85a6e1 Binary protocol updates from the fourth hackathon.
Trond Norbye authored
411 protocol_binary_request_header binary_header;
412 uint64_t cas; /* the cas to return */
0a77fdf @dustin Have just one field for a connection's current cmd.
dustin authored
413 short cmd; /* current command being processed */
6aafe58 @dustin Initial binary server implementation.
dustin authored
414 int opaque;
415 int keylen;
9150c85 @BrianAker Support multiple interfaces returned by IPv6 interfaces. By Brian Ake…
BrianAker authored
416 conn *next; /* Used for generating a list of conn structures */
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
417 LIBEVENT_THREAD *thread; /* Pointer to the thread object serving this connection */
9150c85 @BrianAker Support multiple interfaces returned by IPv6 interfaces. By Brian Ake…
BrianAker authored
418 };
6aafe58 @dustin Initial binary server implementation.
dustin authored
419
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
420
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
421 /* current time of day (updated periodically) */
422 extern volatile rel_time_t current_time;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
423
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
424 /*
425 * Functions
426 */
a0e4a75 @dormando fix resumption of accept loop under multithread
dormando authored
427 void do_accept_new_conns(const bool do_accept);
d044acb @dustin add_delta should return a proper status indicator.
dustin authored
428 enum delta_result_type do_add_delta(conn *c, item *item, const bool incr,
429 const int64_t delta, char *buf);
e5d053c @dustin Magic number cleanup in do_store_item.
dustin authored
430 enum store_item_type do_store_item(item *item, int comm, conn* c);
15ace4b fix and test for issue 38 (server does not respond to binary requests)
Eric Lambert authored
431 conn *conn_new(const int sfd, const enum conn_states init_state, const int event_flags, const int read_buffer_size, enum network_transport transport, struct event_base *base);
08c14e4 Always use bundled daemonize function, fixed warnings on MacOSX
Trond Norbye authored
432 extern int daemonize(int nochdir, int noclose);
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
433
434
435 #include "stats.h"
77dde9f multiple cleanups/refactoring, see ChangeLog
Paul Lindner authored
436 #include "slabs.h"
437 #include "assoc.h"
438 #include "items.h"
e440813 dtrace on macosx does not support -G
Trond Norbye authored
439 #include "trace.h"
1a07065 Refactor: moved the hash function from assoc.c to hash.c
Trond Norbye authored
440 #include "hash.h"
420aa2d @bradfitz start of the incr fix, rearranges a bunch, adds util, tests, etc
bradfitz authored
441 #include "util.h"
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
442
443 /*
444 * Functions such as the libevent-related calls that need to do cross-thread
445 * communication in multithreaded mode (rather than actually doing the work
446 * in the current thread) are called via "dispatch_" frontends, which are
447 * also #define-d to directly call the underlying code in singlethreaded mode.
448 */
449
450 void thread_init(int nthreads, struct event_base *main_base);
451 int dispatch_event_add(int thread, conn *c);
15ace4b fix and test for issue 38 (server does not respond to binary requests)
Eric Lambert authored
452 void dispatch_conn_new(int sfd, enum conn_states init_state, int event_flags, int read_buffer_size, enum network_transport transport);
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
453
454 /* Lock wrappers for cache functions that are called from main loop. */
d044acb @dustin add_delta should return a proper status indicator.
dustin authored
455 enum delta_result_type add_delta(conn *c, item *item, const int incr,
456 const int64_t delta, char *buf);
a0e4a75 @dormando fix resumption of accept loop under multithread
dormando authored
457 void accept_new_conns(const bool do_accept);
a9dcd9a Code modified to only build and run under multi-threaded mode.
Toru Maesaka authored
458 conn *conn_from_freelist(void);
459 bool conn_add_to_freelist(conn *c);
460 int is_listen_thread(void);
461 item *item_alloc(char *key, size_t nkey, int flags, rel_time_t exptime, int nbytes);
462 char *item_cachedump(const unsigned int slabs_clsid, const unsigned int limit, unsigned int *bytes);
463 void item_flush_expired(void);
5da8dba Merged Trond Norbye's protocol patch.
Trond Norbye authored
464 item *item_get(const char *key, const size_t nkey);
a9dcd9a Code modified to only build and run under multi-threaded mode.
Toru Maesaka authored
465 int item_link(item *it);
466 void item_remove(item *it);
467 int item_replace(item *it, item *new_it);
17df5c0 Don't expose the protocol used to the client api of the stats
Trond Norbye authored
468 void item_stats(ADD_STAT add_stats, void *c);
469 void item_stats_sizes(ADD_STAT add_stats, void *c);
a9dcd9a Code modified to only build and run under multi-threaded mode.
Toru Maesaka authored
470 void item_unlink(item *it);
471 void item_update(item *it);
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
472
473 void STATS_LOCK(void);
474 void STATS_UNLOCK(void);
475 void threadlocal_stats_reset(void);
476 void threadlocal_stats_aggregate(struct thread_stats *stats);
25b5189 @dustin Push hit and set stats down into per-slab stats.
dustin authored
477 void slab_stats_aggregate(struct thread_stats *stats, struct slab_stats *out);
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
478
dd71386 @dustin Added append_stat function to contain the common stat append stuff.
dustin authored
479 /* Stat processing functions */
17df5c0 Don't expose the protocol used to the client api of the stats
Trond Norbye authored
480 void append_stat(const char *name, ADD_STAT add_stats, conn *c,
481 const char *fmt, ...);
dd71386 @dustin Added append_stat function to contain the common stat append stuff.
dustin authored
482
e5d053c @dustin Magic number cleanup in do_store_item.
dustin authored
483 enum store_item_type store_item(item *item, int comm, conn *c);
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
484
69aa542 Drop privileges when running on Solaris
Trond Norbye authored
485 #if HAVE_DROP_PRIVILEGES
3fa3137 Remove compilation errors from gcc on Solaris
Trond Norbye authored
486 extern void drop_privileges(void);
69aa542 Drop privileges when running on Solaris
Trond Norbye authored
487 #else
488 #define drop_privileges()
489 #endif
490
c12ebb2 @BrianAker Make likely() and unlikely() available (Brian Aker)
BrianAker authored
491 /* If supported, give compiler hints for branch prediction. */
492 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
493 #define __builtin_expect(x, expected_value) (x)
494 #endif
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
495
c12ebb2 @BrianAker Make likely() and unlikely() available (Brian Aker)
BrianAker authored
496 #define likely(x) __builtin_expect((x),1)
497 #define unlikely(x) __builtin_expect((x),0)
Something went wrong with that request. Please try again.