Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 349 lines (293 sloc) 12.051 kB
f6d334e @bradfitz 2003-06-10
bradfitz authored
1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
1422dff @bradfitz fixup makefile, add Id lines
bradfitz authored
2 /* $Id$ */
c6975ef Part 1 of the Windows compatibility patch
Paul Lindner authored
3
70960eb Add ifdefs around config.h so we can get the windows port working soon
Paul Lindner authored
4 #ifdef HAVE_CONFIG_H
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
5 #include "config.h"
70960eb Add ifdefs around config.h so we can get the windows port working soon
Paul Lindner authored
6 #endif
7
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
8 #include <sys/types.h>
b65aa2a fix for freebsd 6.x (and perhaps others)
Paul Lindner authored
9 #include <sys/socket.h>
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
10 #include <sys/time.h>
11 #include <netinet/in.h>
12 #include <event.h>
a61a690 @BrianAker IPv6 support patch by Brian Aker <brian@tangent.org>
BrianAker authored
13 #include <netdb.h>
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
14
a85a6e1 Binary protocol updates from the fourth hackathon.
Trond Norbye authored
15 #include "protocol_binary.h"
16
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
17 #define DATA_BUFFER_SIZE 2048
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
18 #define UDP_READ_BUFFER_SIZE 65536
19 #define UDP_MAX_PAYLOAD_SIZE 1400
20 #define UDP_HEADER_SIZE 8
21 #define MAX_SENDBUF_SIZE (256 * 1024 * 1024)
e61c0a8 @dormando Dynamic suffix buffer work.
dormando authored
22 /* I'm told the max legnth 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
23 * Plus a few for spaces, \r\n, \0 */
24 #define SUFFIX_SIZE 24
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
25
516e7dc Minimal doxygen configuration
Paul Lindner authored
26 /** 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
27 #define ITEM_LIST_INITIAL 200
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
28
e61c0a8 @dormando Dynamic suffix buffer work.
dormando authored
29 /** Initial size of list of CAS suffixes appended to "gets" lines. */
30 #define SUFFIX_LIST_INITIAL 20
31
516e7dc Minimal doxygen configuration
Paul Lindner authored
32 /** Initial size of the sendmsg() scatter/gather array. */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
33 #define IOV_LIST_INITIAL 400
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
34
516e7dc Minimal doxygen configuration
Paul Lindner authored
35 /** Initial number of sendmsg() argument structures to allocate. */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
36 #define MSG_LIST_INITIAL 10
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
37
516e7dc Minimal doxygen configuration
Paul Lindner authored
38 /** High water marks for buffer shrinking */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
39 #define READ_BUFFER_HIGHWAT 8192
40 #define ITEM_LIST_HIGHWAT 400
41 #define IOV_LIST_HIGHWAT 600
42 #define MSG_LIST_HIGHWAT 100
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
43
6aafe58 @dustin Initial binary server implementation.
dustin authored
44 /* Binary protocol stuff */
7cfd343 @dustin Updates for the new binary protocol (draft-stone-memcache-binary-01).…
dustin authored
45 #define MIN_BIN_PKT_LENGTH 16
6aafe58 @dustin Initial binary server implementation.
dustin authored
46 #define BIN_PKT_HDR_WORDS (MIN_BIN_PKT_LENGTH/sizeof(uint32_t))
47
77dde9f multiple cleanups/refactoring, see ChangeLog
Paul Lindner authored
48 /* Get a consistent bool type */
49 #if HAVE_STDBOOL_H
50 # include <stdbool.h>
51 #else
10862f6 * Remove unused parameter to item_size_ok()
Paul Lindner authored
52 typedef enum {false = 0, true = 1} bool;
77dde9f multiple cleanups/refactoring, see ChangeLog
Paul Lindner authored
53 #endif
54
55 #if HAVE_STDINT_H
56 # include <stdint.h>
57 #else
58 typedef unsigned char uint8_t;
59 #endif
60
d9b97d8 cleanup unistd.h, better spec file, remove warnings from threads.c
Paul Lindner authored
61 /* unistd.h is here */
62 #if HAVE_UNISTD_H
63 # include <unistd.h>
64 #endif
65
516e7dc Minimal doxygen configuration
Paul Lindner authored
66 /** 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
67 typedef unsigned int rel_time_t;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
68
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
69 struct stats {
70 unsigned int curr_items;
71 unsigned int total_items;
c6975ef Part 1 of the Windows compatibility patch
Paul Lindner authored
72 uint64_t curr_bytes;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
73 unsigned int curr_conns;
74 unsigned int total_conns;
75 unsigned int conn_structs;
c6975ef Part 1 of the Windows compatibility patch
Paul Lindner authored
76 uint64_t get_cmds;
77 uint64_t set_cmds;
78 uint64_t get_hits;
79 uint64_t get_misses;
80 uint64_t evictions;
6d74e13 @bradfitz -- remove the ages array since it's not needed. (you can just look
bradfitz authored
81 time_t started; /* when the process was started */
c6975ef Part 1 of the Windows compatibility patch
Paul Lindner authored
82 uint64_t bytes_read;
83 uint64_t bytes_written;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
84 };
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
85
eca55c9 Add patch for changable verbosity levels
Paul Lindner authored
86 #define MAX_VERBOSITY_LEVEL 2
87
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
88 struct settings {
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
89 size_t maxbytes;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
90 int maxconns;
91 int port;
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
92 int udpport;
a61a690 @BrianAker IPv6 support patch by Brian Aker <brian@tangent.org>
BrianAker authored
93 char *inter;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
94 int verbose;
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
95 rel_time_t oldest_live; /* ignore existing items older than this */
841811e From: Jason Titus <jtitus@postini.com>
Jason Titus authored
96 int evict_to_free;
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
97 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
98 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
99 double factor; /* chunk size growth factor */
100 int chunk_size;
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
101 int num_threads; /* number of libevent threads to run */
102 char prefix_delimiter; /* character that marks a key prefix (for stats) */
103 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
104 int reqs_per_event; /* Maximum number of io to process on each
105 io-event. */
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
106 };
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
107
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
108 extern struct stats stats;
109 extern struct settings settings;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
110
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
111 #define ITEM_LINKED 1
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
112
54326f4 @bradfitz more debug
bradfitz authored
113 /* temp */
114 #define ITEM_SLABBED 4
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
115
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
116 typedef struct _stritem {
117 struct _stritem *next;
118 struct _stritem *prev;
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
119 struct _stritem *h_next; /* hash chain next */
120 rel_time_t time; /* least recent access */
121 rel_time_t exptime; /* expire time */
122 int nbytes; /* size of data */
1ea89bd @bradfitz remove all trailing whitespace, not just first occurrence. :)
bradfitz authored
123 unsigned short refcount;
77dde9f multiple cleanups/refactoring, see ChangeLog
Paul Lindner authored
124 uint8_t nsuffix; /* length of flags-and-length string */
125 uint8_t it_flags; /* ITEM_* above */
126 uint8_t slabs_clsid;/* which slab class we're in */
127 uint8_t nkey; /* key length, w/terminating null and padding */
e4a4596 @dustin CAS fix from Christ Goffinet and Dustin Sallings. Use a global increm…
dustin authored
128 uint64_t cas_id; /* the CAS identifier */
61f543a Solaris portability fixes from Trond Norbye
Paul Lindner authored
129 void * end[];
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
130 /* then null-terminated key */
131 /* then " flags length\r\n" (no terminating null) */
132 /* 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
133 } item;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
134
f6d334e @bradfitz 2003-06-10
bradfitz authored
135 #define ITEM_key(item) ((char*)&((item)->end[0]))
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
136
f6d334e @bradfitz 2003-06-10
bradfitz authored
137 /* warning: don't use these macros with a function, as it evals its arg twice */
217dcce Incorporate changes from "performance" branch (revisions 414-419).
Steven Grimm authored
138 #define ITEM_suffix(item) ((char*) &((item)->end[0]) + (item)->nkey + 1)
139 #define ITEM_data(item) ((char*) &((item)->end[0]) + (item)->nkey + 1 + (item)->nsuffix)
140 #define ITEM_ntotal(item) (sizeof(struct _stritem) + (item)->nkey + 1 + (item)->nsuffix + (item)->nbytes)
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
141
f1351f9 Syscall optimizations.
Trond Norbye authored
142 /**
143 * NOTE: If you modify this table you _MUST_ update the function state_text
144 */
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
145 enum conn_states {
516e7dc Minimal doxygen configuration
Paul Lindner authored
146 conn_listening, /** the socket which listens for connections */
f1351f9 Syscall optimizations.
Trond Norbye authored
147 conn_new_cmd, /** Prepare connection for next command */
148 conn_waiting, /** waiting for a readable socket */
516e7dc Minimal doxygen configuration
Paul Lindner authored
149 conn_read, /** reading in a command line */
f1351f9 Syscall optimizations.
Trond Norbye authored
150 conn_parse_cmd, /** try to parse a command from the input buffer */
516e7dc Minimal doxygen configuration
Paul Lindner authored
151 conn_write, /** writing out a simple response */
152 conn_nread, /** reading in a fixed number of bytes */
153 conn_swallow, /** swallowing unnecessary bytes w/o storing */
154 conn_closing, /** closing this connection */
e61c0a8 @dormando Dynamic suffix buffer work.
dormando authored
155 conn_mwrite, /** writing out many items sequentially */
f1351f9 Syscall optimizations.
Trond Norbye authored
156 conn_max_state, /** Max state value (used for assertion) */
6aafe58 @dustin Initial binary server implementation.
dustin authored
157 };
158
159 enum bin_substates {
160 bin_no_state,
161 bin_reading_set_header,
1379edf @dustin Binary server CAS implementation
dustin authored
162 bin_reading_cas_header,
6aafe58 @dustin Initial binary server implementation.
dustin authored
163 bin_read_set_value,
164 bin_reading_get_key,
4c77f59 Initial attempt of supporting stats in binary protocol.
Toru Maesaka authored
165 bin_reading_stat,
6aafe58 @dustin Initial binary server implementation.
dustin authored
166 bin_reading_del_header,
167 bin_reading_incr_header,
a85a6e1 Binary protocol updates from the fourth hackathon.
Trond Norbye authored
168 bin_read_flush_exptime
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
169 };
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
170
e1407b2 @dustin Handle protocol enums more correctly.
dustin authored
171 enum protocol {
2cdde3e @dustin Added protocol flag to connection for multi-protocol support.
dustin authored
172 ascii_prot = 3, /* arbitrary value. */
6aafe58 @dustin Initial binary server implementation.
dustin authored
173 ascii_udp_prot,
cba691f @dustin Auto-discover the protocol being spoken on a per-connection basis.
dustin authored
174 binary_prot,
175 negotiating_prot, /* Discovering the protocol */
2cdde3e @dustin Added protocol flag to connection for multi-protocol support.
dustin authored
176 };
177
178 #define IS_UDP(x) (x == ascii_udp_prot)
179
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
180 #define NREAD_ADD 1
181 #define NREAD_SET 2
182 #define NREAD_REPLACE 3
7283d85 @Desi-Planet Add append command support written by Filipe Laborde. Tests/protocol …
Desi-Planet authored
183 #define NREAD_APPEND 4
6091c6d update for prepend operation, thread safe version from Maxim replacin…
Paul Lindner authored
184 #define NREAD_PREPEND 5
e4a4596 @dustin CAS fix from Christ Goffinet and Dustin Sallings. Use a global increm…
dustin authored
185 #define NREAD_CAS 6
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
186
9150c85 @BrianAker Support multiple interfaces returned by IPv6 interfaces. By Brian Ake…
BrianAker authored
187 typedef struct conn conn;
188 struct conn {
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
189 int sfd;
3ed60cd @dustin Ensure all connection states are expressed as enums.
dustin authored
190 enum conn_states state;
d86881e @dustin Use the bin substate enum as well
dustin authored
191 enum bin_substates substate;
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
192 struct event event;
193 short ev_flags;
516e7dc Minimal doxygen configuration
Paul Lindner authored
194 short which; /** which events were just triggered */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
195
516e7dc Minimal doxygen configuration
Paul Lindner authored
196 char *rbuf; /** buffer to read commands into */
197 char *rcurr; /** but if we parsed some already, this is where we stopped */
198 int rsize; /** total allocated size of rbuf */
199 int rbytes; /** how much data, starting from rcur, do we have unparsed */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
200
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
201 char *wbuf;
202 char *wcurr;
203 int wsize;
1ea89bd @bradfitz remove all trailing whitespace, not just first occurrence. :)
bradfitz authored
204 int wbytes;
516e7dc Minimal doxygen configuration
Paul Lindner authored
205 int write_and_go; /** which state to go into after finishing current write */
206 void *write_and_free; /** free this memory after finishing writing */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
207
516e7dc Minimal doxygen configuration
Paul Lindner authored
208 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
209 int rlbytes;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
210
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
211 /* data for the nread state */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
212
516e7dc Minimal doxygen configuration
Paul Lindner authored
213 /**
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
214 * 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
215 * 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
216 * 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
217 */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
218
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
219 void *item; /* for commands set/add/replace */
220 int item_comm; /* which one is it: set/add/replace */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
221
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
222 /* data for the swallow state */
223 int sbytes; /* how many bytes to swallow */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
224
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
225 /* data for the mwrite state */
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
226 struct iovec *iov;
227 int iovsize; /* number of elements allocated in iov[] */
228 int iovused; /* number of elements used in iov[] */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
229
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
230 struct msghdr *msglist;
231 int msgsize; /* number of elements allocated in msglist[] */
232 int msgused; /* number of elements used in msglist[] */
233 int msgcurr; /* element in msglist[] being transmitted now */
234 int msgbytes; /* number of bytes in current msg */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
235
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
236 item **ilist; /* list of items to write out */
237 int isize;
238 item **icurr;
239 int ileft;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
240
e61c0a8 @dormando Dynamic suffix buffer work.
dormando authored
241 char **suffixlist;
242 int suffixsize;
243 char **suffixcurr;
244 int suffixleft;
245
e1407b2 @dustin Handle protocol enums more correctly.
dustin authored
246 enum protocol protocol; /* which protocol this connection speaks */
2cdde3e @dustin Added protocol flag to connection for multi-protocol support.
dustin authored
247
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
248 /* data for UDP clients */
249 int request_id; /* Incoming UDP request ID, if this is a UDP "connection" */
250 struct sockaddr request_addr; /* Who sent the most recent request */
251 socklen_t request_addr_size;
252 unsigned char *hdrbuf; /* udp packet headers */
253 int hdrsize; /* number of headers' worth of space is allocated */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
254
1bb05fb @crucially r265@crucially-3: sky | 2006-03-29 17:02:15 +051800
crucially authored
255 int binary; /* are we in binary mode */
d9ece78 @kroki Implement 'noreply' option for update commands. (Tomash Brechko <toma…
kroki authored
256 bool noreply; /* True if the reply should not be sent. */
6aafe58 @dustin Initial binary server implementation.
dustin authored
257 /* Binary protocol stuff */
258 /* This is where the binary header goes */
a85a6e1 Binary protocol updates from the fourth hackathon.
Trond Norbye authored
259 protocol_binary_request_header binary_header;
260 uint64_t cas; /* the cas to return */
6aafe58 @dustin Initial binary server implementation.
dustin authored
261 short cmd;
262 int opaque;
263 int keylen;
9150c85 @BrianAker Support multiple interfaces returned by IPv6 interfaces. By Brian Ake…
BrianAker authored
264 conn *next; /* Used for generating a list of conn structures */
265 };
6aafe58 @dustin Initial binary server implementation.
dustin authored
266
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
267
c9607c6 @bradfitz merge end of facebook branch into trunk, after copying the old trunk …
bradfitz authored
268 /* current time of day (updated periodically) */
269 extern volatile rel_time_t current_time;
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
270
60d7094 update from avva with new allocation policy: bunches of power-of-two
Anatoly Vorobey authored
271 /*
272 * Functions
273 */
86969ea @bradfitz restore blank lines I over-zealously destroyed earlier.
bradfitz authored
274
df1b7e4 Removed compiler warnings and increased warning level
Trond Norbye authored
275 conn *do_conn_from_freelist(void);
bb3a4c9 conn_add_to_freelist returns bool
Paul Lindner authored
276 bool do_conn_add_to_freelist(conn *c);
df1b7e4 Removed compiler warnings and increased warning level
Trond Norbye authored
277 char *do_suffix_from_freelist(void);
e61c0a8 @dormando Dynamic suffix buffer work.
dormando authored
278 bool do_suffix_add_to_freelist(char *s);
6895721 Add DTrace probes for Solaris/etc.
Trond Norbye authored
279 char *do_add_delta(conn *c, item *item, const bool incr, const int64_t delta,
280 char *buf);
a85a6e1 Binary protocol updates from the fourth hackathon.
Trond Norbye authored
281 int do_store_item(item *item, int comm, conn* c);
3ed60cd @dustin Ensure all connection states are expressed as enums.
dustin authored
282 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
283 uint32_t append_bin_stats(char *buf, const char *key, const uint16_t klen,
284 const char *val, const uint32_t vlen);
285 uint32_t append_ascii_stats(char *buf, const char *key, const uint16_t klen,
286 const char *val, const uint32_t vlen);
08c14e4 Always use bundled daemonize function, fixed warnings on MacOSX
Trond Norbye authored
287 extern int daemonize(int nochdir, int noclose);
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
288
289
290 #include "stats.h"
77dde9f multiple cleanups/refactoring, see ChangeLog
Paul Lindner authored
291 #include "slabs.h"
292 #include "assoc.h"
293 #include "items.h"
e440813 dtrace on macosx does not support -G
Trond Norbye authored
294 #include "trace.h"
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
295
296
297 /*
298 * Functions such as the libevent-related calls that need to do cross-thread
299 * communication in multithreaded mode (rather than actually doing the work
300 * in the current thread) are called via "dispatch_" frontends, which are
301 * also #define-d to directly call the underlying code in singlethreaded mode.
302 */
303
304 void thread_init(int nthreads, struct event_base *main_base);
305 int dispatch_event_add(int thread, conn *c);
3ed60cd @dustin Ensure all connection states are expressed as enums.
dustin authored
306 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
307
308 /* Lock wrappers for cache functions that are called from main loop. */
6895721 Add DTrace probes for Solaris/etc.
Trond Norbye authored
309 char *add_delta(conn *c, item *item, const int incr, const int64_t delta,
310 char *buf);
a9dcd9a Code modified to only build and run under multi-threaded mode.
Toru Maesaka authored
311 void assoc_move_next_bucket(void);
312 conn *conn_from_freelist(void);
313 bool conn_add_to_freelist(conn *c);
314 char *suffix_from_freelist(void);
315 bool suffix_add_to_freelist(char *s);
316 int is_listen_thread(void);
317 item *item_alloc(char *key, size_t nkey, int flags, rel_time_t exptime, int nbytes);
318 char *item_cachedump(const unsigned int slabs_clsid, const unsigned int limit, unsigned int *bytes);
319 void item_flush_expired(void);
5da8dba Merged Trond Norbye's protocol patch.
Trond Norbye authored
320 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
321 int item_link(item *it);
322 void item_remove(item *it);
323 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
324 char *item_stats(uint32_t (*add_stats)(char *buf, const char *key,
325 const uint16_t klen, const char *val,
326 const uint32_t vlen), int *bytes);
327 char *item_stats_sizes(uint32_t (*add_stats)(char *buf, const char *key,
328 const uint16_t klen, const char *val,
329 const uint32_t vlen), int *bytes);
a9dcd9a Code modified to only build and run under multi-threaded mode.
Toru Maesaka authored
330 void item_unlink(item *it);
331 void item_update(item *it);
332 void *slabs_alloc(size_t size, unsigned int id);
333 void slabs_free(void *ptr, size_t size, unsigned int id);
334 int slabs_reassign(unsigned char srcid, unsigned char dstid);
3e47e81 The slabber no longer needs a is_binary like flag for stats due to ab…
Toru Maesaka authored
335 char *slabs_stats(uint32_t (*add_stats)(char *buf,
a91d357 Changed the argument ordering for stats callback to something more co…
Toru Maesaka authored
336 const char *key, const uint16_t klen, const char *val,
3e47e81 The slabber no longer needs a is_binary like flag for stats due to ab…
Toru Maesaka authored
337 const uint32_t vlen), int *buflen);
a9dcd9a Code modified to only build and run under multi-threaded mode.
Toru Maesaka authored
338 void STATS_LOCK(void);
339 void STATS_UNLOCK(void);
a85a6e1 Binary protocol updates from the fourth hackathon.
Trond Norbye authored
340 int store_item(item *item, int comm, conn *c);
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
341
c12ebb2 @BrianAker Make likely() and unlikely() available (Brian Aker)
BrianAker authored
342 /* If supported, give compiler hints for branch prediction. */
343 #if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
344 #define __builtin_expect(x, expected_value) (x)
345 #endif
56b8339 Merge multithreaded into trunk, commit #2 (first commit only did the
Steven Grimm authored
346
c12ebb2 @BrianAker Make likely() and unlikely() available (Brian Aker)
BrianAker authored
347 #define likely(x) __builtin_expect((x),1)
348 #define unlikely(x) __builtin_expect((x),0)
Something went wrong with that request. Please try again.