Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 440 lines (371 sloc) 15.551 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
70960eb Add ifdefs around config.h so we can get the windows port working soon
Paul Lindner authored
3 #ifdef HAVE_CONFIG_H
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
4 #include "config.h"
70960eb Add ifdefs around config.h so we can get the windows port working soon
Paul Lindner authored
5 #endif
6
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
7 #include <sys/types.h>
b65aa2a fix for freebsd 6.x (and perhaps others)
Paul Lindner authored
8 #include <sys/socket.h>
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
9 #include <sys/time.h>
10 #include <netinet/in.h>
11 #include <event.h>
a61a690 @BrianAker IPv6 support patch by Brian Aker <brian@tangent.org>
BrianAker authored
12 #include <netdb.h>
718047f Remove #ifdef checks for header files in C99
Trond Norbye authored
13 #include <stdbool.h>
14 #include <stdint.h>
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
15 #include <pthread.h>
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
16
a85a6e1 Binary protocol updates from the fourth hackathon.
Trond Norbye authored
17 #include "protocol_binary.h"
18
ecdb011 @dustin Fix memory corruption error in stats cachedump.
dustin authored
19 /* Maximum length of a key. */
20 #define KEY_MAX_LENGTH 250
21
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
22 #define DATA_BUFFER_SIZE 2048
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
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)
420aa2d @bradfitz start of the incr fix, rearranges a bunch, adds util, tests, etc
bradfitz authored
27 /* 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
28 * Plus a few for spaces, \r\n, \0 */
29 #define SUFFIX_SIZE 24
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
30
516e7dc Minimal doxygen configuration
Paul Lindner authored
31 /** 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
32 #define ITEM_LIST_INITIAL 200
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
33
e61c0a8 @dormando Dynamic suffix buffer work.
dormando authored
34 /** Initial size of list of CAS suffixes appended to "gets" lines. */
35 #define SUFFIX_LIST_INITIAL 20
36
516e7dc Minimal doxygen configuration
Paul Lindner authored
37 /** Initial size of the sendmsg() scatter/gather array. */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
38 #define IOV_LIST_INITIAL 400
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
39
516e7dc Minimal doxygen configuration
Paul Lindner authored
40 /** Initial number of sendmsg() argument structures to allocate. */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
41 #define MSG_LIST_INITIAL 10
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
42
516e7dc Minimal doxygen configuration
Paul Lindner authored
43 /** High water marks for buffer shrinking */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
44 #define READ_BUFFER_HIGHWAT 8192
45 #define ITEM_LIST_HIGHWAT 400
46 #define IOV_LIST_HIGHWAT 600
47 #define MSG_LIST_HIGHWAT 100
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
48
6aafe58 @dustin Initial binary server implementation.
dustin authored
49 /* Binary protocol stuff */
7cfd343 @dustin Updates for the new binary protocol (draft-stone-memcache-binary-01).…
dustin authored
50 #define MIN_BIN_PKT_LENGTH 16
6aafe58 @dustin Initial binary server implementation.
dustin authored
51 #define BIN_PKT_HDR_WORDS (MIN_BIN_PKT_LENGTH/sizeof(uint32_t))
52
d9b97d8 cleanup unistd.h, better spec file, remove warnings from threads.c
Paul Lindner authored
53 /* unistd.h is here */
54 #if HAVE_UNISTD_H
55 # include <unistd.h>
56 #endif
57
067102a @dustin Moved slab sizing definitions from slabs.c to memcached.h
dustin authored
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
7173856 @dustin Create a more sensible definition for the maximum number of slab clas…
dustin authored
64 #define MAX_NUMBER_OF_SLAB_CLASSES (POWER_LARGEST + 1)
067102a @dustin Moved slab sizing definitions from slabs.c to memcached.h
dustin authored
65
b8d997e @dustin Define TAIL_REPAIR_TIME as a constant.
dustin authored
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
516e7dc Minimal doxygen configuration
Paul Lindner authored
70 /** 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
71 typedef unsigned int rel_time_t;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
72
25b5189 @dustin Push hit and set stats down into per-slab stats.
dustin authored
73 /* Stats stored per slab (and per thread). */
74 struct slab_stats {
75 uint64_t set_cmds;
76 uint64_t get_hits;
a77d12b @dustin Added stats for delete commands.
dustin authored
77 uint64_t delete_hits;
15e6462 @dustin Added CAS stats.
dustin authored
78 uint64_t cas_hits;
79 uint64_t cas_badval;
3e03078 @dustin incr/decr stats
dustin authored
80 uint64_t incr_hits;
81 uint64_t decr_hits;
25b5189 @dustin Push hit and set stats down into per-slab stats.
dustin authored
82 };
83
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
84 struct thread_stats {
25b5189 @dustin Push hit and set stats down into per-slab stats.
dustin authored
85 pthread_mutex_t mutex;
86 uint64_t get_cmds;
87 uint64_t get_misses;
a77d12b @dustin Added stats for delete commands.
dustin authored
88 uint64_t delete_misses;
3e03078 @dustin incr/decr stats
dustin authored
89 uint64_t incr_misses;
90 uint64_t decr_misses;
15e6462 @dustin Added CAS stats.
dustin authored
91 uint64_t cas_misses;
25b5189 @dustin Push hit and set stats down into per-slab stats.
dustin authored
92 uint64_t bytes_read;
93 uint64_t bytes_written;
534466e @dormando add a cmd_flush stat
dormando authored
94 uint64_t flush_cmds;
25b5189 @dustin Push hit and set stats down into per-slab stats.
dustin authored
95 struct slab_stats slab_stats[MAX_NUMBER_OF_SLAB_CLASSES];
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
96 };
97
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
98 struct stats {
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
99 pthread_mutex_t mutex;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
100 unsigned int curr_items;
101 unsigned int total_items;
c6975ef Part 1 of the Windows compatibility patch
Paul Lindner authored
102 uint64_t curr_bytes;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
103 unsigned int curr_conns;
104 unsigned int total_conns;
105 unsigned int conn_structs;
534466e @dormando add a cmd_flush stat
dormando authored
106 uint64_t get_cmds;
107 uint64_t set_cmds;
108 uint64_t get_hits;
109 uint64_t get_misses;
c6975ef Part 1 of the Windows compatibility patch
Paul Lindner authored
110 uint64_t evictions;
3d540bd @dormando two new troubleshooting stats
dormando authored
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;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
114 };
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
115
eca55c9 Add patch for changable verbosity levels
Paul Lindner authored
116 #define MAX_VERBOSITY_LEVEL 2
117
5277879 @dustin Added stats settings.
dustin authored
118 /* When adding a setting, be sure to update process_stat_settings */
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
119 struct settings {
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
120 size_t maxbytes;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
121 int maxconns;
122 int port;
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
123 int udpport;
a61a690 @BrianAker IPv6 support patch by Brian Aker <brian@tangent.org>
BrianAker authored
124 char *inter;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
125 int verbose;
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
126 rel_time_t oldest_live; /* ignore existing items older than this */
841811e From: Jason Titus <jtitus@postini.com>
Jason Titus authored
127 int evict_to_free;
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
128 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
129 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
130 double factor; /* chunk size growth factor */
131 int chunk_size;
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
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 */
ca90710 @dormando Prevent starvation by busy threads. This gives a configurable limit t…
dormando authored
135 int reqs_per_event; /* Maximum number of io to process on each
136 io-event. */
eda68b7 Added -C to remove the cas_id from the data structures to save space
Trond Norbye authored
137 bool use_cas;
7d010a8 @lenn0x Added support for setting backlog queue on command line
lenn0x authored
138 int backlog;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
139 };
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
140
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
141 extern struct stats stats;
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
142 extern time_t process_started;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
143 extern struct settings settings;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
144
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
145 #define ITEM_LINKED 1
eda68b7 Added -C to remove the cas_id from the data structures to save space
Trond Norbye authored
146 #define ITEM_CAS 2
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
147
54326f4 @bradfitz more debug
bradfitz authored
148 /* temp */
149 #define ITEM_SLABBED 4
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
150
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
151 typedef struct _stritem {
152 struct _stritem *next;
153 struct _stritem *prev;
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
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 */
1ea89bd @bradfitz remove all trailing whitespace, not just first occurrence. :)
bradfitz authored
158 unsigned short refcount;
77dde9f multiple cleanups/refactoring, see ChangeLog
Paul Lindner authored
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 */
61f543a Solaris portability fixes from Trond Norbye
Paul Lindner authored
163 void * end[];
eda68b7 Added -C to remove the cas_id from the data structures to save space
Trond Norbye authored
164 /* 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
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!) */
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
168 } item;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
169
f6d334e @bradfitz 2003-06-10
bradfitz authored
170 /* warning: don't use these macros with a function, as it evals its arg twice */
eda68b7 Added -C to remove the cas_id from the data structures to save space
Trond Norbye authored
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
e5260b9 Add the size of the cas (if present) to the ITEM_ntotal
Trond Norbye authored
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))
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
189
37369b0 @dustin Make APPEND_STAT globally available.
dustin authored
190 /* Append a simple stat with a stat name, value format and value */
dd71386 @dustin Added append_stat function to contain the common stat append stuff.
dustin authored
191 #define APPEND_STAT(name, fmt, val) \
192 pos = append_stat(name, pos, add_stats, c, allocated, buflen, \
193 fmt, val);
fc85484 @dustin Added APPEND_STAT2
dustin authored
194
b89f7c7 @dustin Use stat macros for item stats.
dustin authored
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; \
29345c0 @dustin Use stat macros for stats slabs.
dustin authored
203 assert(*buflen < allocated);
37369b0 @dustin Make APPEND_STAT globally available.
dustin authored
204
b89f7c7 @dustin Use stat macros for item stats.
dustin authored
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
f1351f9 Syscall optimizations.
Trond Norbye authored
209 /**
210 * NOTE: If you modify this table you _MUST_ update the function state_text
211 */
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
212 enum conn_states {
516e7dc Minimal doxygen configuration
Paul Lindner authored
213 conn_listening, /** the socket which listens for connections */
f1351f9 Syscall optimizations.
Trond Norbye authored
214 conn_new_cmd, /** Prepare connection for next command */
215 conn_waiting, /** waiting for a readable socket */
516e7dc Minimal doxygen configuration
Paul Lindner authored
216 conn_read, /** reading in a command line */
f1351f9 Syscall optimizations.
Trond Norbye authored
217 conn_parse_cmd, /** try to parse a command from the input buffer */
516e7dc Minimal doxygen configuration
Paul Lindner authored
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 */
e61c0a8 @dormando Dynamic suffix buffer work.
dormando authored
222 conn_mwrite, /** writing out many items sequentially */
dfc5130 @dustin Get build working under ICC.
dustin authored
223 conn_max_state /** Max state value (used for assertion) */
6aafe58 @dustin Initial binary server implementation.
dustin authored
224 };
225
226 enum bin_substates {
227 bin_no_state,
228 bin_reading_set_header,
1379edf @dustin Binary server CAS implementation
dustin authored
229 bin_reading_cas_header,
6aafe58 @dustin Initial binary server implementation.
dustin authored
230 bin_read_set_value,
231 bin_reading_get_key,
4c77f59 Initial attempt of supporting stats in binary protocol.
Toru Maesaka authored
232 bin_reading_stat,
6aafe58 @dustin Initial binary server implementation.
dustin authored
233 bin_reading_del_header,
234 bin_reading_incr_header,
a85a6e1 Binary protocol updates from the fourth hackathon.
Trond Norbye authored
235 bin_read_flush_exptime
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
236 };
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
237
e1407b2 @dustin Handle protocol enums more correctly.
dustin authored
238 enum protocol {
2cdde3e @dustin Added protocol flag to connection for multi-protocol support.
dustin authored
239 ascii_prot = 3, /* arbitrary value. */
6aafe58 @dustin Initial binary server implementation.
dustin authored
240 ascii_udp_prot,
cba691f @dustin Auto-discover the protocol being spoken on a per-connection basis.
dustin authored
241 binary_prot,
dfc5130 @dustin Get build working under ICC.
dustin authored
242 negotiating_prot /* Discovering the protocol */
2cdde3e @dustin Added protocol flag to connection for multi-protocol support.
dustin authored
243 };
244
245 #define IS_UDP(x) (x == ascii_udp_prot)
246
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
247 #define NREAD_ADD 1
248 #define NREAD_SET 2
249 #define NREAD_REPLACE 3
7283d85 @Desi-Planet Add append command support written by Filipe Laborde. Tests/protocol …
Desi-Planet authored
250 #define NREAD_APPEND 4
6091c6d update for prepend operation, thread safe version from Maxim replacin…
Paul Lindner authored
251 #define NREAD_PREPEND 5
e4a4596 @dustin CAS fix from Christ Goffinet and Dustin Sallings. Use a global increm…
dustin authored
252 #define NREAD_CAS 6
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
253
e5d053c @dustin Magic number cleanup in do_store_item.
dustin authored
254 enum store_item_type {
255 NOT_STORED=0, STORED, EXISTS, NOT_FOUND
256 };
257
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
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
9150c85 @BrianAker Support multiple interfaces returned by IPv6 interfaces. By Brian Ake…
BrianAker authored
268 typedef struct conn conn;
269 struct conn {
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
270 int sfd;
3ed60cd @dustin Ensure all connection states are expressed as enums.
dustin authored
271 enum conn_states state;
d86881e @dustin Use the bin substate enum as well
dustin authored
272 enum bin_substates substate;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
273 struct event event;
274 short ev_flags;
516e7dc Minimal doxygen configuration
Paul Lindner authored
275 short which; /** which events were just triggered */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
276
516e7dc Minimal doxygen configuration
Paul Lindner authored
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 */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
281
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
282 char *wbuf;
283 char *wcurr;
284 int wsize;
1ea89bd @bradfitz remove all trailing whitespace, not just first occurrence. :)
bradfitz authored
285 int wbytes;
a564b42 @dustin Fix type of write_and_go
dustin authored
286 /** which state to go into after finishing current write */
287 enum conn_states write_and_go;
516e7dc Minimal doxygen configuration
Paul Lindner authored
288 void *write_and_free; /** free this memory after finishing writing */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
289
516e7dc Minimal doxygen configuration
Paul Lindner authored
290 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
291 int rlbytes;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
292
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
293 /* data for the nread state */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
294
516e7dc Minimal doxygen configuration
Paul Lindner authored
295 /**
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
296 * 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
297 * 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
298 * 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
299 */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
300
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
301 void *item; /* for commands set/add/replace */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
302
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
303 /* data for the swallow state */
304 int sbytes; /* how many bytes to swallow */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
305
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
306 /* data for the mwrite state */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
307 struct iovec *iov;
308 int iovsize; /* number of elements allocated in iov[] */
309 int iovused; /* number of elements used in iov[] */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
310
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
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 */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
316
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
317 item **ilist; /* list of items to write out */
318 int isize;
319 item **icurr;
320 int ileft;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
321
e61c0a8 @dormando Dynamic suffix buffer work.
dormando authored
322 char **suffixlist;
323 int suffixsize;
324 char **suffixcurr;
325 int suffixleft;
326
e1407b2 @dustin Handle protocol enums more correctly.
dustin authored
327 enum protocol protocol; /* which protocol this connection speaks */
2cdde3e @dustin Added protocol flag to connection for multi-protocol support.
dustin authored
328
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
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 */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
335
d9ece78 @kroki Implement 'noreply' option for update commands. (Tomash Brechko <toma…
kroki authored
336 bool noreply; /* True if the reply should not be sent. */
6aafe58 @dustin Initial binary server implementation.
dustin authored
337 /* Binary protocol stuff */
338 /* This is where the binary header goes */
a85a6e1 Binary protocol updates from the fourth hackathon.
Trond Norbye authored
339 protocol_binary_request_header binary_header;
340 uint64_t cas; /* the cas to return */
0a77fdf @dustin Have just one field for a connection's current cmd.
dustin authored
341 short cmd; /* current command being processed */
6aafe58 @dustin Initial binary server implementation.
dustin authored
342 int opaque;
343 int keylen;
9150c85 @BrianAker Support multiple interfaces returned by IPv6 interfaces. By Brian Ake…
BrianAker authored
344 conn *next; /* Used for generating a list of conn structures */
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
345 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
346 };
6aafe58 @dustin Initial binary server implementation.
dustin authored
347
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
348
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
349 /* current time of day (updated periodically) */
350 extern volatile rel_time_t current_time;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
351
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
352 /*
353 * Functions
354 */
6895721 Add DTrace probes for Solaris/etc.
Trond Norbye authored
355 char *do_add_delta(conn *c, item *item, const bool incr, const int64_t delta,
356 char *buf);
e5d053c @dustin Magic number cleanup in do_store_item.
dustin authored
357 enum store_item_type do_store_item(item *item, int comm, conn* c);
3ed60cd @dustin Ensure all connection states are expressed as enums.
dustin authored
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);
df1b7e4 Removed compiler warnings and increased warning level
Trond Norbye authored
359 uint32_t append_bin_stats(char *buf, const char *key, const uint16_t klen,
3bdfd46 Fix for stats opaque issue pointed out at the hackathon and removed s…
Toru Maesaka authored
360 const char *val, const uint32_t vlen, void *cookie);
df1b7e4 Removed compiler warnings and increased warning level
Trond Norbye authored
361 uint32_t append_ascii_stats(char *buf, const char *key, const uint16_t klen,
3bdfd46 Fix for stats opaque issue pointed out at the hackathon and removed s…
Toru Maesaka authored
362 const char *val, const uint32_t vlen, void *cookie);
08c14e4 Always use bundled daemonize function, fixed warnings on MacOSX
Trond Norbye authored
363 extern int daemonize(int nochdir, int noclose);
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
364
365
366 #include "stats.h"
77dde9f multiple cleanups/refactoring, see ChangeLog
Paul Lindner authored
367 #include "slabs.h"
368 #include "assoc.h"
369 #include "items.h"
e440813 dtrace on macosx does not support -G
Trond Norbye authored
370 #include "trace.h"
1a07065 Refactor: moved the hash function from assoc.c to hash.c
Trond Norbye authored
371 #include "hash.h"
420aa2d @bradfitz start of the incr fix, rearranges a bunch, adds util, tests, etc
bradfitz authored
372 #include "util.h"
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
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);
3ed60cd @dustin Ensure all connection states are expressed as enums.
dustin authored
383 void dispatch_conn_new(int sfd, enum conn_states init_state, int event_flags, int read_buffer_size, enum protocol prot);
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
384
385 /* Lock wrappers for cache functions that are called from main loop. */
6895721 Add DTrace probes for Solaris/etc.
Trond Norbye authored
386 char *add_delta(conn *c, item *item, const int incr, const int64_t delta,
387 char *buf);
a9dcd9a Code modified to only build and run under multi-threaded mode.
Toru Maesaka authored
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);
5da8dba Merged Trond Norbye's protocol patch.
Trond Norbye authored
396 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
397 int item_link(item *it);
398 void item_remove(item *it);
399 int item_replace(item *it, item *new_it);
3e47e81 The slabber no longer needs a is_binary like flag for stats due to ab…
Toru Maesaka authored
400 char *item_stats(uint32_t (*add_stats)(char *buf, const char *key,
401 const uint16_t klen, const char *val,
3bdfd46 Fix for stats opaque issue pointed out at the hackathon and removed s…
Toru Maesaka authored
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);
a9dcd9a Code modified to only build and run under multi-threaded mode.
Toru Maesaka authored
406 void item_unlink(item *it);
407 void item_update(item *it);
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
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);
25b5189 @dustin Push hit and set stats down into per-slab stats.
dustin authored
413 void slab_stats_aggregate(struct thread_stats *stats, struct slab_stats *out);
1fdfb7e Use threadlocal stats to count the commands
Trond Norbye authored
414
dd71386 @dustin Added append_stat function to contain the common stat append stuff.
dustin authored
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
e5d053c @dustin Magic number cleanup in do_store_item.
dustin authored
425 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
426
69aa542 Drop privileges when running on Solaris
Trond Norbye authored
427 #if HAVE_DROP_PRIVILEGES
428 extern void drop_privileges();
429 #else
430 #define drop_privileges()
431 #endif
432
c12ebb2 @BrianAker Make likely() and unlikely() available (Brian Aker)
BrianAker authored
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
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
437
c12ebb2 @BrianAker Make likely() and unlikely() available (Brian Aker)
BrianAker authored
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.