Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 439 lines (371 sloc) 15.551 kb
f6d334e0 » bradfitz
2003-06-20 2003-06-10
1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
c6975ef4 » Paul Lindner
2007-04-16 Part 1 of the Windows compatibility patch
2
70960eb3 » Paul Lindner
2007-07-29 Add ifdefs around config.h so we can get the windows port working soon
3 #ifdef HAVE_CONFIG_H
56b8339e » Steven Grimm
2007-04-16 Merge multithreaded into trunk, commit #2 (first commit only did the
4 #include "config.h"
70960eb3 » Paul Lindner
2007-07-29 Add ifdefs around config.h so we can get the windows port working soon
5 #endif
6
56b8339e » Steven Grimm
2007-04-16 Merge multithreaded into trunk, commit #2 (first commit only did the
7 #include <sys/types.h>
b65aa2ab » Paul Lindner
2007-05-07 fix for freebsd 6.x (and perhaps others)
8 #include <sys/socket.h>
56b8339e » Steven Grimm
2007-04-16 Merge multithreaded into trunk, commit #2 (first commit only did the
9 #include <sys/time.h>
10 #include <netinet/in.h>
11 #include <event.h>
a61a6900 » BrianAker
2008-02-18 IPv6 support patch by Brian Aker <brian@tangent.org>
12 #include <netdb.h>
718047f8 » Trond Norbye
2009-01-28 Remove #ifdef checks for header files in C99
13 #include <stdbool.h>
14 #include <stdint.h>
1fdfb7e9 » Trond Norbye
2009-03-04 Use threadlocal stats to count the commands
15 #include <pthread.h>
56b8339e » Steven Grimm
2007-04-16 Merge multithreaded into trunk, commit #2 (first commit only did the
16
a85a6e15 » Trond Norbye
2008-04-29 Binary protocol updates from the fourth hackathon.
17 #include "protocol_binary.h"
18
ecdb0114 » dustin
2009-02-12 Fix memory corruption error in stats cachedump.
19 /* Maximum length of a key. */
20 #define KEY_MAX_LENGTH 250
21
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
22 #define DATA_BUFFER_SIZE 2048
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
23 #define UDP_READ_BUFFER_SIZE 65536
24 #define UDP_MAX_PAYLOAD_SIZE 1400
25 #define UDP_HEADER_SIZE 8
26 #define MAX_SENDBUF_SIZE (256 * 1024 * 1024)
420aa2d9 » bradfitz
2008-10-14 start of the incr fix, rearranges a bunch, adds util, tests, etc
27 /* I'm told the max length of a 64-bit num converted to string is 20 bytes.
b17a0c8b » dormando
2007-11-21 Fix bugs reported by Tomash Brechko for the new cas patch.
28 * Plus a few for spaces, \r\n, \0 */
29 #define SUFFIX_SIZE 24
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
30
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
31 /** Initial size of list of items being returned by "get". */
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
32 #define ITEM_LIST_INITIAL 200
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
33
e61c0a86 » dormando
2007-11-20 Dynamic suffix buffer work.
34 /** Initial size of list of CAS suffixes appended to "gets" lines. */
35 #define SUFFIX_LIST_INITIAL 20
36
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
37 /** Initial size of the sendmsg() scatter/gather array. */
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
38 #define IOV_LIST_INITIAL 400
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
39
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
40 /** Initial number of sendmsg() argument structures to allocate. */
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
41 #define MSG_LIST_INITIAL 10
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
42
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
43 /** High water marks for buffer shrinking */
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
44 #define READ_BUFFER_HIGHWAT 8192
45 #define ITEM_LIST_HIGHWAT 400
46 #define IOV_LIST_HIGHWAT 600
47 #define MSG_LIST_HIGHWAT 100
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
48
6aafe58e » dustin
2007-12-11 Initial binary server implementation.
49 /* Binary protocol stuff */
7cfd3438 » dustin
2007-12-19 Updates for the new binary protocol (draft-stone-memcache-binary-01).…
50 #define MIN_BIN_PKT_LENGTH 16
6aafe58e » dustin
2007-12-11 Initial binary server implementation.
51 #define BIN_PKT_HDR_WORDS (MIN_BIN_PKT_LENGTH/sizeof(uint32_t))
52
d9b97d80 » Paul Lindner
2007-05-07 cleanup unistd.h, better spec file, remove warnings from threads.c
53 /* unistd.h is here */
54 #if HAVE_UNISTD_H
55 # include <unistd.h>
56 #endif
57
067102a4 » dustin
2009-03-06 Moved slab sizing definitions from slabs.c to memcached.h
58 /* Slab sizing definitions. */
59 #define POWER_SMALLEST 1
60 #define POWER_LARGEST 200
61 #define POWER_BLOCK 1048576
62 #define CHUNK_ALIGN_BYTES 8
63 #define DONT_PREALLOC_SLABS
7173856a » dustin
2009-03-06 Create a more sensible definition for the maximum number of slab clas…
64 #define MAX_NUMBER_OF_SLAB_CLASSES (POWER_LARGEST + 1)
067102a4 » dustin
2009-03-06 Moved slab sizing definitions from slabs.c to memcached.h
65
b8d997e5 » dustin
2009-03-29 Define TAIL_REPAIR_TIME as a constant.
66 /* How long an object can reasonably be assumed to be locked before
67 harvesting it on a low memory condition. */
68 #define TAIL_REPAIR_TIME (3 * 3600)
69
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
70 /** Time relative to server start. Smaller than time_t on 64-bit systems. */
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
71 typedef unsigned int rel_time_t;
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
72
25b5189c » dustin
2009-03-06 Push hit and set stats down into per-slab stats.
73 /* Stats stored per slab (and per thread). */
74 struct slab_stats {
75 uint64_t set_cmds;
76 uint64_t get_hits;
a77d12b0 » dustin
2009-03-06 Added stats for delete commands.
77 uint64_t delete_hits;
15e64625 » dustin
2009-03-07 Added CAS stats.
78 uint64_t cas_hits;
79 uint64_t cas_badval;
3e030782 » dustin
2009-03-07 incr/decr stats
80 uint64_t incr_hits;
81 uint64_t decr_hits;
25b5189c » dustin
2009-03-06 Push hit and set stats down into per-slab stats.
82 };
83
1fdfb7e9 » Trond Norbye
2009-03-04 Use threadlocal stats to count the commands
84 struct thread_stats {
25b5189c » dustin
2009-03-06 Push hit and set stats down into per-slab stats.
85 pthread_mutex_t mutex;
86 uint64_t get_cmds;
87 uint64_t get_misses;
a77d12b0 » dustin
2009-03-06 Added stats for delete commands.
88 uint64_t delete_misses;
3e030782 » dustin
2009-03-07 incr/decr stats
89 uint64_t incr_misses;
90 uint64_t decr_misses;
15e64625 » dustin
2009-03-07 Added CAS stats.
91 uint64_t cas_misses;
25b5189c » dustin
2009-03-06 Push hit and set stats down into per-slab stats.
92 uint64_t bytes_read;
93 uint64_t bytes_written;
534466e0 » dormando
2009-03-25 add a cmd_flush stat
94 uint64_t flush_cmds;
25b5189c » dustin
2009-03-06 Push hit and set stats down into per-slab stats.
95 struct slab_stats slab_stats[MAX_NUMBER_OF_SLAB_CLASSES];
1fdfb7e9 » Trond Norbye
2009-03-04 Use threadlocal stats to count the commands
96 };
97
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
98 struct stats {
1fdfb7e9 » Trond Norbye
2009-03-04 Use threadlocal stats to count the commands
99 pthread_mutex_t mutex;
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
100 unsigned int curr_items;
101 unsigned int total_items;
c6975ef4 » Paul Lindner
2007-04-16 Part 1 of the Windows compatibility patch
102 uint64_t curr_bytes;
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
103 unsigned int curr_conns;
104 unsigned int total_conns;
105 unsigned int conn_structs;
534466e0 » dormando
2009-03-25 add a cmd_flush stat
106 uint64_t get_cmds;
107 uint64_t set_cmds;
108 uint64_t get_hits;
109 uint64_t get_misses;
c6975ef4 » Paul Lindner
2007-04-16 Part 1 of the Windows compatibility patch
110 uint64_t evictions;
3d540bdb » dormando
2009-03-27 two new troubleshooting stats
111 time_t started; /* when the process was started */
112 unsigned int accepting_conns; /* whether we are currently accepting */
113 uint64_t listen_disabled_num;
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
114 };
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
115
eca55c9a » Paul Lindner
2007-04-12 Add patch for changable verbosity levels
116 #define MAX_VERBOSITY_LEVEL 2
117
52778791 » dustin
2009-03-17 Added stats settings.
118 /* When adding a setting, be sure to update process_stat_settings */
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
119 struct settings {
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
120 size_t maxbytes;
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
121 int maxconns;
122 int port;
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
123 int udpport;
a61a6900 » BrianAker
2008-02-18 IPv6 support patch by Brian Aker <brian@tangent.org>
124 char *inter;
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
125 int verbose;
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
126 rel_time_t oldest_live; /* ignore existing items older than this */
841811e9 » Jason Titus
2004-02-24 From: Jason Titus <jtitus@postini.com>
127 int evict_to_free;
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
128 char *socketpath; /* path to unix socket if using local socket */
40c76ced » bremner
2007-10-16 Patch from David Bremner <bremner@unb.ca> that implements a new optio…
129 int access; /* access mask (a la chmod) for unix domain socket */
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
130 double factor; /* chunk size growth factor */
131 int chunk_size;
56b8339e » Steven Grimm
2007-04-16 Merge multithreaded into trunk, commit #2 (first commit only did the
132 int num_threads; /* number of libevent threads to run */
133 char prefix_delimiter; /* character that marks a key prefix (for stats) */
134 int detail_enabled; /* nonzero if we're collecting detailed stats */
ca90710f » dormando
2008-09-29 Prevent starvation by busy threads. This gives a configurable limit t…
135 int reqs_per_event; /* Maximum number of io to process on each
136 io-event. */
eda68b70 » Trond Norbye
2008-11-25 Added -C to remove the cas_id from the data structures to save space
137 bool use_cas;
7d010a85 » lenn0x
2009-03-15 Added support for setting backlog queue on command line
138 int backlog;
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
139 };
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
140
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
141 extern struct stats stats;
1fdfb7e9 » Trond Norbye
2009-03-04 Use threadlocal stats to count the commands
142 extern time_t process_started;
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
143 extern struct settings settings;
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
144
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
145 #define ITEM_LINKED 1
eda68b70 » Trond Norbye
2008-11-25 Added -C to remove the cas_id from the data structures to save space
146 #define ITEM_CAS 2
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
147
54326f42 » bradfitz
2003-06-27 more debug
148 /* temp */
149 #define ITEM_SLABBED 4
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
150
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
151 typedef struct _stritem {
152 struct _stritem *next;
153 struct _stritem *prev;
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
154 struct _stritem *h_next; /* hash chain next */
155 rel_time_t time; /* least recent access */
156 rel_time_t exptime; /* expire time */
157 int nbytes; /* size of data */
1ea89bd5 » bradfitz
2006-09-04 remove all trailing whitespace, not just first occurrence. :)
158 unsigned short refcount;
77dde9f9 » Paul Lindner
2007-03-06 multiple cleanups/refactoring, see ChangeLog
159 uint8_t nsuffix; /* length of flags-and-length string */
160 uint8_t it_flags; /* ITEM_* above */
161 uint8_t slabs_clsid;/* which slab class we're in */
162 uint8_t nkey; /* key length, w/terminating null and padding */
61f543a5 » Paul Lindner
2007-06-20 Solaris portability fixes from Trond Norbye
163 void * end[];
eda68b70 » Trond Norbye
2008-11-25 Added -C to remove the cas_id from the data structures to save space
164 /* if it_flags & ITEM_CAS we have 8 bytes CAS */
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
165 /* then null-terminated key */
166 /* then " flags length\r\n" (no terminating null) */
167 /* then data with terminating \r\n (no terminating null; it's binary!) */
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
168 } item;
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
169
f6d334e0 » bradfitz
2003-06-20 2003-06-10
170 /* warning: don't use these macros with a function, as it evals its arg twice */
eda68b70 » Trond Norbye
2008-11-25 Added -C to remove the cas_id from the data structures to save space
171 #define ITEM_get_cas(i) ((uint64_t)(((i)->it_flags & ITEM_CAS) ? \
172 *(uint64_t*)&((i)->end[0]) : 0x0))
173 #define ITEM_set_cas(i,v) { if ((i)->it_flags & ITEM_CAS) { \
174 *(uint64_t*)&((i)->end[0]) = v; } }
175
176 #define ITEM_key(item) (((char*)&((item)->end[0])) \
177 + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))
178
179 #define ITEM_suffix(item) ((char*) &((item)->end[0]) + (item)->nkey + 1 \
180 + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))
181
182 #define ITEM_data(item) ((char*) &((item)->end[0]) + (item)->nkey + 1 \
183 + (item)->nsuffix \
184 + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))
185
e5260b91 » Trond Norbye
2008-11-26 Add the size of the cas (if present) to the ITEM_ntotal
186 #define ITEM_ntotal(item) (sizeof(struct _stritem) + (item)->nkey + 1 \
187 + (item)->nsuffix + (item)->nbytes \
188 + (((item)->it_flags & ITEM_CAS) ? sizeof(uint64_t) : 0))
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
189
37369b0d » dustin
2009-03-24 Make APPEND_STAT globally available.
190 /* Append a simple stat with a stat name, value format and value */
dd713869 » dustin
2009-03-24 Added append_stat function to contain the common stat append stuff.
191 #define APPEND_STAT(name, fmt, val) \
192 pos = append_stat(name, pos, add_stats, c, allocated, buflen, \
193 fmt, val);
fc854846 » dustin
2009-03-24 Added APPEND_STAT2
194
b89f7c7b » dustin
2009-03-24 Use stat macros for item stats.
195 /* Append an indexed stat with a stat name (with format), value format
196 and value */
197 #define APPEND_NUM_FMT_STAT(name_fmt, num, name, fmt, val) \
198 klen = sprintf(key_str, name_fmt, num, name); \
199 vlen = sprintf(val_str, fmt, val); \
200 size = add_stats(pos, key_str, klen, val_str, vlen, c); \
201 *buflen += size; \
202 pos += size; \
29345c04 » dustin
2009-03-24 Use stat macros for stats slabs.
203 assert(*buflen < allocated);
37369b0d » dustin
2009-03-24 Make APPEND_STAT globally available.
204
b89f7c7b » dustin
2009-03-24 Use stat macros for item stats.
205 /* Common APPEND_NUM_FMT_STAT format. */
206 #define APPEND_NUM_STAT(num, name, fmt, val) \
207 APPEND_NUM_FMT_STAT("%d:%s", num, name, fmt, val)
208
f1351f9b » Trond Norbye
2008-04-02 Syscall optimizations.
209 /**
210 * NOTE: If you modify this table you _MUST_ update the function state_text
211 */
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
212 enum conn_states {
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
213 conn_listening, /** the socket which listens for connections */
f1351f9b » Trond Norbye
2008-04-02 Syscall optimizations.
214 conn_new_cmd, /** Prepare connection for next command */
215 conn_waiting, /** waiting for a readable socket */
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
216 conn_read, /** reading in a command line */
f1351f9b » Trond Norbye
2008-04-02 Syscall optimizations.
217 conn_parse_cmd, /** try to parse a command from the input buffer */
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
218 conn_write, /** writing out a simple response */
219 conn_nread, /** reading in a fixed number of bytes */
220 conn_swallow, /** swallowing unnecessary bytes w/o storing */
221 conn_closing, /** closing this connection */
e61c0a86 » dormando
2007-11-20 Dynamic suffix buffer work.
222 conn_mwrite, /** writing out many items sequentially */
dfc5130e » dustin
2009-02-03 Get build working under ICC.
223 conn_max_state /** Max state value (used for assertion) */
6aafe58e » dustin
2007-12-11 Initial binary server implementation.
224 };
225
226 enum bin_substates {
227 bin_no_state,
228 bin_reading_set_header,
1379edf3 » dustin
2007-12-11 Binary server CAS implementation
229 bin_reading_cas_header,
6aafe58e » dustin
2007-12-11 Initial binary server implementation.
230 bin_read_set_value,
231 bin_reading_get_key,
4c77f591 » Toru Maesaka
2008-07-03 Initial attempt of supporting stats in binary protocol.
232 bin_reading_stat,
6aafe58e » dustin
2007-12-11 Initial binary server implementation.
233 bin_reading_del_header,
234 bin_reading_incr_header,
a85a6e15 » Trond Norbye
2008-04-29 Binary protocol updates from the fourth hackathon.
235 bin_read_flush_exptime
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
236 };
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
237
e1407b25 » dustin
2008-03-17 Handle protocol enums more correctly.
238 enum protocol {
2cdde3e4 » dustin
2007-12-11 Added protocol flag to connection for multi-protocol support.
239 ascii_prot = 3, /* arbitrary value. */
6aafe58e » dustin
2007-12-11 Initial binary server implementation.
240 ascii_udp_prot,
cba691f4 » dustin
2008-03-01 Auto-discover the protocol being spoken on a per-connection basis.
241 binary_prot,
dfc5130e » dustin
2009-02-03 Get build working under ICC.
242 negotiating_prot /* Discovering the protocol */
2cdde3e4 » dustin
2007-12-11 Added protocol flag to connection for multi-protocol support.
243 };
244
245 #define IS_UDP(x) (x == ascii_udp_prot)
246
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
247 #define NREAD_ADD 1
248 #define NREAD_SET 2
249 #define NREAD_REPLACE 3
7283d85b » Desi-Planet
2007-10-03 Add append command support written by Filipe Laborde. Tests/protocol …
250 #define NREAD_APPEND 4
6091c6de » Paul Lindner
2007-10-03 update for prepend operation, thread safe version from Maxim replacin…
251 #define NREAD_PREPEND 5
e4a45965 » dustin
2007-11-15 CAS fix from Christ Goffinet and Dustin Sallings. Use a global increm…
252 #define NREAD_CAS 6
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
253
e5d053c3 » dustin
2009-02-24 Magic number cleanup in do_store_item.
254 enum store_item_type {
255 NOT_STORED=0, STORED, EXISTS, NOT_FOUND
256 };
257
1fdfb7e9 » Trond Norbye
2009-03-04 Use threadlocal stats to count the commands
258 typedef struct {
259 pthread_t thread_id; /* unique ID of this thread */
260 struct event_base *base; /* libevent handle this thread uses */
261 struct event notify_event; /* listen event for notify pipe */
262 int notify_receive_fd; /* receiving end of notify pipe */
263 int notify_send_fd; /* sending end of notify pipe */
264 struct thread_stats stats; /* Stats generated by this thread */
265 struct conn_queue *new_conn_queue; /* queue of new connections to handle */
266 } LIBEVENT_THREAD;
267
9150c85b » BrianAker
2008-02-18 Support multiple interfaces returned by IPv6 interfaces. By Brian Ake…
268 typedef struct conn conn;
269 struct conn {
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
270 int sfd;
3ed60cdd » dustin
2008-03-18 Ensure all connection states are expressed as enums.
271 enum conn_states state;
d86881ea » dustin
2008-03-18 Use the bin substate enum as well
272 enum bin_substates substate;
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
273 struct event event;
274 short ev_flags;
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
275 short which; /** which events were just triggered */
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
276
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
277 char *rbuf; /** buffer to read commands into */
278 char *rcurr; /** but if we parsed some already, this is where we stopped */
279 int rsize; /** total allocated size of rbuf */
280 int rbytes; /** how much data, starting from rcur, do we have unparsed */
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
281
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
282 char *wbuf;
283 char *wcurr;
284 int wsize;
1ea89bd5 » bradfitz
2006-09-04 remove all trailing whitespace, not just first occurrence. :)
285 int wbytes;
a564b426 » dustin
2009-02-02 Fix type of write_and_go
286 /** which state to go into after finishing current write */
287 enum conn_states write_and_go;
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
288 void *write_and_free; /** free this memory after finishing writing */
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
289
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
290 char *ritem; /** when we read in an item's value, it goes here */
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
291 int rlbytes;
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
292
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
293 /* data for the nread state */
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
294
516e7dc2 » Paul Lindner
2007-07-10 Minimal doxygen configuration
295 /**
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
296 * item is used to hold an item structure created after reading the command
1ea89bd5 » bradfitz
2006-09-04 remove all trailing whitespace, not just first occurrence. :)
297 * line of set/add/replace commands, but before we finished reading the actual
7917af40 » bradfitz
2003-06-22 misc fixes as suggested by avva. lot of comment updates, mostly.
298 * data. The data is read into ITEM_data(item) to avoid extra copying.
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
299 */
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
300
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
301 void *item; /* for commands set/add/replace */
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
302
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
303 /* data for the swallow state */
304 int sbytes; /* how many bytes to swallow */
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
305
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
306 /* data for the mwrite state */
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
307 struct iovec *iov;
308 int iovsize; /* number of elements allocated in iov[] */
309 int iovused; /* number of elements used in iov[] */
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
310
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
311 struct msghdr *msglist;
312 int msgsize; /* number of elements allocated in msglist[] */
313 int msgused; /* number of elements used in msglist[] */
314 int msgcurr; /* element in msglist[] being transmitted now */
315 int msgbytes; /* number of bytes in current msg */
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
316
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
317 item **ilist; /* list of items to write out */
318 int isize;
319 item **icurr;
320 int ileft;
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
321
e61c0a86 » dormando
2007-11-20 Dynamic suffix buffer work.
322 char **suffixlist;
323 int suffixsize;
324 char **suffixcurr;
325 int suffixleft;
326
e1407b25 » dustin
2008-03-17 Handle protocol enums more correctly.
327 enum protocol protocol; /* which protocol this connection speaks */
2cdde3e4 » dustin
2007-12-11 Added protocol flag to connection for multi-protocol support.
328
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
329 /* data for UDP clients */
330 int request_id; /* Incoming UDP request ID, if this is a UDP "connection" */
331 struct sockaddr request_addr; /* Who sent the most recent request */
332 socklen_t request_addr_size;
333 unsigned char *hdrbuf; /* udp packet headers */
334 int hdrsize; /* number of headers' worth of space is allocated */
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
335
d9ece780 » kroki
2008-02-22 Implement 'noreply' option for update commands. (Tomash Brechko <toma…
336 bool noreply; /* True if the reply should not be sent. */
6aafe58e » dustin
2007-12-11 Initial binary server implementation.
337 /* Binary protocol stuff */
338 /* This is where the binary header goes */
a85a6e15 » Trond Norbye
2008-04-29 Binary protocol updates from the fourth hackathon.
339 protocol_binary_request_header binary_header;
340 uint64_t cas; /* the cas to return */
0a77fdfa » dustin
2009-03-10 Have just one field for a connection's current cmd.
341 short cmd; /* current command being processed */
6aafe58e » dustin
2007-12-11 Initial binary server implementation.
342 int opaque;
343 int keylen;
9150c85b » BrianAker
2008-02-18 Support multiple interfaces returned by IPv6 interfaces. By Brian Ake…
344 conn *next; /* Used for generating a list of conn structures */
1fdfb7e9 » Trond Norbye
2009-03-04 Use threadlocal stats to count the commands
345 LIBEVENT_THREAD *thread; /* Pointer to the thread object serving this connection */
9150c85b » BrianAker
2008-02-18 Support multiple interfaces returned by IPv6 interfaces. By Brian Ake…
346 };
6aafe58e » dustin
2007-12-11 Initial binary server implementation.
347
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
348
c9607c6d » bradfitz
2006-09-03 merge end of facebook branch into trunk, after copying the old trunk …
349 /* current time of day (updated periodically) */
350 extern volatile rel_time_t current_time;
86969ea4 » bradfitz
2006-09-04 restore blank lines I over-zealously destroyed earlier.
351
60d70942 » Anatoly Vorobey
2003-05-30 update from avva with new allocation policy: bunches of power-of-two
352 /*
353 * Functions
354 */
68957214 » Trond Norbye
2008-07-23 Add DTrace probes for Solaris/etc.
355 char *do_add_delta(conn *c, item *item, const bool incr, const int64_t delta,
356 char *buf);
e5d053c3 » dustin
2009-02-24 Magic number cleanup in do_store_item.
357 enum store_item_type do_store_item(item *item, int comm, conn* c);
3ed60cdd » dustin
2008-03-18 Ensure all connection states are expressed as enums.
358 conn *conn_new(const int sfd, const enum conn_states init_state, const int event_flags, const int read_buffer_size, enum protocol prot, struct event_base *base);
df1b7e42 » Trond Norbye
2008-10-06 Removed compiler warnings and increased warning level
359 uint32_t append_bin_stats(char *buf, const char *key, const uint16_t klen,
3bdfd463 » Toru Maesaka
2008-10-19 Fix for stats opaque issue pointed out at the hackathon and removed s…
360 const char *val, const uint32_t vlen, void *cookie);
df1b7e42 » Trond Norbye
2008-10-06 Removed compiler warnings and increased warning level
361 uint32_t append_ascii_stats(char *buf, const char *key, const uint16_t klen,
3bdfd463 » Toru Maesaka
2008-10-19 Fix for stats opaque issue pointed out at the hackathon and removed s…
362 const char *val, const uint32_t vlen, void *cookie);
08c14e4e » Trond Norbye
2008-10-06 Always use bundled daemonize function, fixed warnings on MacOSX
363 extern int daemonize(int nochdir, int noclose);
56b8339e » Steven Grimm
2007-04-16 Merge multithreaded into trunk, commit #2 (first commit only did the
364
365
366 #include "stats.h"
77dde9f9 » Paul Lindner
2007-03-06 multiple cleanups/refactoring, see ChangeLog
367 #include "slabs.h"
368 #include "assoc.h"
369 #include "items.h"
e440813d » Trond Norbye
2008-10-02 dtrace on macosx does not support -G
370 #include "trace.h"
1a070652 » Trond Norbye
2009-03-02 Refactor: moved the hash function from assoc.c to hash.c
371 #include "hash.h"
420aa2d9 » bradfitz
2008-10-14 start of the incr fix, rearranges a bunch, adds util, tests, etc
372 #include "util.h"
56b8339e » Steven Grimm
2007-04-16 Merge multithreaded into trunk, commit #2 (first commit only did the
373
374 /*
375 * Functions such as the libevent-related calls that need to do cross-thread
376 * communication in multithreaded mode (rather than actually doing the work
377 * in the current thread) are called via "dispatch_" frontends, which are
378 * also #define-d to directly call the underlying code in singlethreaded mode.
379 */
380
381 void thread_init(int nthreads, struct event_base *main_base);
382 int dispatch_event_add(int thread, conn *c);
3ed60cdd » dustin
2008-03-18 Ensure all connection states are expressed as enums.
383 void dispatch_conn_new(int sfd, enum conn_states init_state, int event_flags, int read_buffer_size, enum protocol prot);
56b8339e » Steven Grimm
2007-04-16 Merge multithreaded into trunk, commit #2 (first commit only did the
384
385 /* Lock wrappers for cache functions that are called from main loop. */
68957214 » Trond Norbye
2008-07-23 Add DTrace probes for Solaris/etc.
386 char *add_delta(conn *c, item *item, const int incr, const int64_t delta,
387 char *buf);
a9dcd9ac » Toru Maesaka
2008-04-28 Code modified to only build and run under multi-threaded mode.
388 conn *conn_from_freelist(void);
389 bool conn_add_to_freelist(conn *c);
390 char *suffix_from_freelist(void);
391 bool suffix_add_to_freelist(char *s);
392 int is_listen_thread(void);
393 item *item_alloc(char *key, size_t nkey, int flags, rel_time_t exptime, int nbytes);
394 char *item_cachedump(const unsigned int slabs_clsid, const unsigned int limit, unsigned int *bytes);
395 void item_flush_expired(void);
5da8dbab » Trond Norbye
2008-07-28 Merged Trond Norbye's protocol patch.
396 item *item_get(const char *key, const size_t nkey);
a9dcd9ac » Toru Maesaka
2008-04-28 Code modified to only build and run under multi-threaded mode.
397 int item_link(item *it);
398 void item_remove(item *it);
399 int item_replace(item *it, item *new_it);
3e47e810 » Toru Maesaka
2008-10-05 The slabber no longer needs a is_binary like flag for stats due to ab…
400 char *item_stats(uint32_t (*add_stats)(char *buf, const char *key,
401 const uint16_t klen, const char *val,
3bdfd463 » Toru Maesaka
2008-10-19 Fix for stats opaque issue pointed out at the hackathon and removed s…
402 const uint32_t vlen, void *cookie), void *c, int *bytes);
403 char *item_stats_sizes(uint32_t (*add_stats)(char *buf,
404 const char *key, const uint16_t klen, const char *val,
405 const uint32_t vlen, void *cookie), void *c, int *bytes);
a9dcd9ac » Toru Maesaka
2008-04-28 Code modified to only build and run under multi-threaded mode.
406 void item_unlink(item *it);
407 void item_update(item *it);
1fdfb7e9 » Trond Norbye
2009-03-04 Use threadlocal stats to count the commands
408
409 void STATS_LOCK(void);
410 void STATS_UNLOCK(void);
411 void threadlocal_stats_reset(void);
412 void threadlocal_stats_aggregate(struct thread_stats *stats);
25b5189c » dustin
2009-03-06 Push hit and set stats down into per-slab stats.
413 void slab_stats_aggregate(struct thread_stats *stats, struct slab_stats *out);
1fdfb7e9 » Trond Norbye
2009-03-04 Use threadlocal stats to count the commands
414
dd713869 » dustin
2009-03-24 Added append_stat function to contain the common stat append stuff.
415 /* Stat processing functions */
416 char *append_stat(const char *name, char *pos,
417 uint32_t (*add_stats)(char *buf, const char *key,
418 const uint16_t klen, const char *val,
419 const uint32_t vlen, void *cookie),
420 conn *c,
421 int allocated,
422 int *buflen,
423 const char *fmt, ...);
424
e5d053c3 » dustin
2009-02-24 Magic number cleanup in do_store_item.
425 enum store_item_type store_item(item *item, int comm, conn *c);
56b8339e » Steven Grimm
2007-04-16 Merge multithreaded into trunk, commit #2 (first commit only did the
426
69aa5427 » Trond Norbye
2009-03-03 Drop privileges when running on Solaris
427 #if HAVE_DROP_PRIVILEGES
428 extern void drop_privileges();
429 #else
430 #define drop_privileges()
431 #endif
432
c12ebb2b » BrianAker
2008-02-24 Make likely() and unlikely() available (Brian Aker)
433 /* If supported, give compiler hints for branch prediction. */
434 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
435 #define __builtin_expect(x, expected_value) (x)
436 #endif
56b8339e » Steven Grimm
2007-04-16 Merge multithreaded into trunk, commit #2 (first commit only did the
437
c12ebb2b » BrianAker
2008-02-24 Make likely() and unlikely() available (Brian Aker)
438 #define likely(x) __builtin_expect((x),1)
439 #define unlikely(x) __builtin_expect((x),0)
Something went wrong with that request. Please try again.