Merge lp://qastaging/~trond-norbye/libmemcached/mget_memslap into lp://qastaging/~tangent-org/libmemcached/trunk

Proposed by Trond Norbye
Status: Merged
Merged at revision: not available
Proposed branch: lp://qastaging/~trond-norbye/libmemcached/mget_memslap
Merge into: lp://qastaging/~tangent-org/libmemcached/trunk
Diff against target: 327 lines (+128/-20)
6 files modified
clients/execute.c (+60/-2)
clients/execute.h (+6/-0)
clients/memslap.c (+41/-10)
example/interface_v0.c (+2/-2)
example/interface_v1.c (+1/-1)
libmemcached/protocol/callback.h (+18/-5)
To merge this branch: bzr merge lp://qastaging/~trond-norbye/libmemcached/mget_memslap
Reviewer Review Type Date Requested Status
Libmemcached-developers Pending
Review via email: mp+14540@code.qastaging.launchpad.net
To post a comment you must log in.
Revision history for this message
Trond Norbye (trond-norbye) wrote :

* added a mget test to memslap: ( ./memslap --servers=localhost --test=mget --binary )
* the interface number should be an enum

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'clients/execute.c'
2--- clients/execute.c 2009-09-22 08:09:29 +0000
3+++ clients/execute.c 2009-11-06 11:05:21 +0000
4@@ -19,7 +19,7 @@
5 pairs[x].value, pairs[x].value_length,
6 0, 0);
7 if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_BUFFERED)
8- fprintf(stderr, "Failured on insert of %.*s\n",
9+ fprintf(stderr, "Failured on insert of %.*s\n",
10 (unsigned int)pairs[x].key_length, pairs[x].key);
11 else
12 pairs_sent++;
13@@ -52,7 +52,7 @@
14 &value_length, &flags, &rc);
15
16 if (rc != MEMCACHED_SUCCESS)
17- fprintf(stderr, "Failured on read of %.*s\n",
18+ fprintf(stderr, "Failured on read of %.*s\n",
19 (unsigned int)pairs[fetch_key].key_length, pairs[fetch_key].key);
20 else
21 retrieved++;
22@@ -62,3 +62,61 @@
23
24 return retrieved;
25 }
26+
27+/**
28+ * Callback function to count the number of results
29+ */
30+static memcached_return callback_counter(memcached_st *ptr,
31+ memcached_result_st *result,
32+ void *context)
33+{
34+ (void)ptr;
35+ (void)result;
36+ unsigned int *counter= (unsigned int *)context;
37+ *counter= *counter + 1;
38+
39+ return MEMCACHED_SUCCESS;
40+}
41+
42+/**
43+ * Try to run a large mget to get all of the keys
44+ * @param memc memcached handle
45+ * @param keys the keys to get
46+ * @param key_length the length of the keys
47+ * @param number_of the number of keys to try to get
48+ * @return the number of keys received
49+ */
50+unsigned int execute_mget(memcached_st *memc,
51+ const char * const *keys,
52+ size_t *key_length,
53+ unsigned int number_of)
54+{
55+ unsigned int retrieved= 0;
56+ memcached_execute_function callbacks[1]= { [0]= &callback_counter };
57+ memcached_return rc;
58+ rc= memcached_mget_execute(memc, keys, key_length,
59+ (size_t)number_of, callbacks, &retrieved, 1);
60+
61+ likely (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_NOTFOUND ||
62+ rc == MEMCACHED_BUFFERED || rc == MEMCACHED_END)
63+ {
64+ rc= memcached_fetch_execute(memc, callbacks, (void *)&retrieved, 1);
65+ unlikely (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_NOTFOUND &&
66+ rc != MEMCACHED_END)
67+ {
68+ fprintf(stderr, "Failed to execute mget: %s\n",
69+ memcached_strerror(memc, rc));
70+ memcached_quit(memc);
71+ return 0;
72+ }
73+ }
74+ else
75+ {
76+ fprintf(stderr, "Failed to execute mget: %s\n",
77+ memcached_strerror(memc, rc));
78+ memcached_quit(memc);
79+ return 0;
80+ }
81+
82+ return retrieved;
83+}
84
85=== modified file 'clients/execute.h'
86--- clients/execute.h 2009-05-13 19:04:53 +0000
87+++ clients/execute.h 2009-11-06 11:05:21 +0000
88@@ -1,5 +1,11 @@
89+#ifndef CLIENTS_EXECUTE_H
90+#define CLIENTS_EXECUTE_H
91 #include "libmemcached/memcached.h"
92 #include "generator.h"
93
94 unsigned int execute_set(memcached_st *memc, pairs_st *pairs, unsigned int number_of);
95 unsigned int execute_get(memcached_st *memc, pairs_st *pairs, unsigned int number_of);
96+unsigned int execute_mget(memcached_st *memc, const char * const *keys, size_t *key_length,
97+ unsigned int number_of);
98+#endif
99+
100
101=== modified file 'clients/memslap.c'
102--- clients/memslap.c 2009-08-11 18:56:12 +0000
103+++ clients/memslap.c 2009-11-06 11:05:21 +0000
104@@ -42,6 +42,7 @@
105 typedef enum {
106 SET_TEST,
107 GET_TEST,
108+ MGET_TEST
109 } test_type;
110
111 struct thread_context_st {
112@@ -50,6 +51,8 @@
113 unsigned int initial_number;
114 pairs_st *execute_pairs;
115 unsigned int execute_number;
116+ char **keys;
117+ size_t *key_lengths;
118 test_type test;
119 memcached_st *memc;
120 };
121@@ -65,7 +68,7 @@
122 void options_parse(int argc, char *argv[]);
123 void conclusions_print(conclusions_st *conclusion);
124 void scheduler(memcached_server_st *servers, conclusions_st *conclusion);
125-pairs_st *load_create_data(memcached_st *memc, unsigned int number_of,
126+pairs_st *load_create_data(memcached_st *memc, unsigned int number_of,
127 unsigned int *actual_loaded);
128 void flush_all(memcached_st *memc);
129
130@@ -155,12 +158,29 @@
131
132 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
133 (uint64_t)opt_binary);
134-
135+
136 if (opt_flush)
137 flush_all(memc);
138 if (opt_createial_load)
139 pairs= load_create_data(memc, opt_createial_load, &actual_loaded);
140
141+ char **keys= calloc(actual_loaded, sizeof(char*));
142+ size_t *key_lengths= calloc(actual_loaded, sizeof(size_t));
143+
144+ if (keys == NULL || key_lengths == NULL)
145+ {
146+ free(keys);
147+ free(key_lengths);
148+ keys= NULL;
149+ key_lengths= NULL;
150+ } else {
151+ for (x= 0; x < actual_loaded; ++x)
152+ {
153+ keys[x]= pairs[x].key;
154+ key_lengths[x]= pairs[x].key_length;
155+ }
156+ }
157+
158 /* We set this after we have loaded */
159 {
160 if (opt_non_blocking_io)
161@@ -169,7 +189,6 @@
162 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1);
163 }
164
165-
166 pthread_mutex_lock(&counter_mutex);
167 thread_counter= 0;
168
169@@ -187,6 +206,8 @@
170
171 context->initial_pairs= pairs;
172 context->initial_number= actual_loaded;
173+ context->keys= keys;
174+ context->key_lengths= key_lengths;
175
176 if (opt_test == SET_TEST)
177 {
178@@ -225,6 +246,8 @@
179
180 conclusion->load_time= timedif(end_time, start_time);
181 conclusion->read_time= timedif(end_time, start_time);
182+ free(keys);
183+ free(key_lengths);
184 pairs_free(pairs);
185 memcached_free(memc);
186 }
187@@ -259,7 +282,7 @@
188 int option_index= 0;
189 int option_rv;
190
191- while (1)
192+ while (1)
193 {
194 option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
195 if (option_rv == -1) break;
196@@ -307,7 +330,11 @@
197 }
198 else if (!strcmp(optarg, "set"))
199 opt_test= SET_TEST;
200- else
201+ else if (!strcmp(optarg, "mget"))
202+ {
203+ opt_test= MGET_TEST;
204+ }
205+ else
206 {
207 fprintf(stderr, "Your test, %s, is not a known test\n", optarg);
208 exit(1);
209@@ -330,7 +357,7 @@
210 }
211 }
212
213- if (opt_test == GET_TEST && opt_createial_load == 0)
214+ if ((opt_test == GET_TEST || opt_test == MGET_TEST) && opt_createial_load == 0)
215 opt_createial_load= DEFAULT_INITIAL_LOAD;
216
217 if (opt_execute_number == 0)
218@@ -348,10 +375,10 @@
219 printf("\tRead %u rows\n", conclusion->rows_read);
220 #endif
221 if (opt_test == SET_TEST)
222- printf("\tTook %ld.%03ld seconds to load data\n", conclusion->load_time / 1000,
223+ printf("\tTook %ld.%03ld seconds to load data\n", conclusion->load_time / 1000,
224 conclusion->load_time % 1000);
225 else
226- printf("\tTook %ld.%03ld seconds to read data\n", conclusion->read_time / 1000,
227+ printf("\tTook %ld.%03ld seconds to read data\n", conclusion->read_time / 1000,
228 conclusion->read_time % 1000);
229 }
230
231@@ -366,7 +393,7 @@
232 while (master_wakeup)
233 {
234 pthread_cond_wait(&sleep_threshhold, &sleeper_mutex);
235- }
236+ }
237 pthread_mutex_unlock(&sleeper_mutex);
238
239 /* Do Stuff */
240@@ -379,6 +406,10 @@
241 case GET_TEST:
242 execute_get(memc, context->initial_pairs, context->initial_number);
243 break;
244+ case MGET_TEST:
245+ execute_mget(memc, (const char*const*)context->keys, context->key_lengths,
246+ context->initial_number);
247+ break;
248 default:
249 WATCHPOINT_ASSERT(context->test);
250 break;
251@@ -404,7 +435,7 @@
252 memcached_flush(memc, 0);
253 }
254
255-pairs_st *load_create_data(memcached_st *memc, unsigned int number_of,
256+pairs_st *load_create_data(memcached_st *memc, unsigned int number_of,
257 unsigned int *actual_loaded)
258 {
259 memcached_st *memc_clone;
260
261=== modified file 'example/interface_v0.c'
262--- example/interface_v0.c 2009-10-16 15:01:26 +0000
263+++ example/interface_v0.c 2009-11-06 11:05:21 +0000
264@@ -521,10 +521,10 @@
265 }
266
267 memcached_binary_protocol_callback_st interface_v0_impl= {
268- .interface_version= 0,
269+ .interface_version= MEMCACHED_PROTOCOL_HANDLER_V0,
270 #ifdef FUTURE
271 /*
272- ** There is a number of bugs in the extra options for gcc causing
273+ ** There is a number of bugs in the extra options for gcc causing
274 ** warning on these struct initializers. It hurts my heart to remove
275 ** it so I'll just leave it in here so that we can enable it when
276 ** we can drop support for the broken compilers
277
278=== modified file 'example/interface_v1.c'
279--- example/interface_v1.c 2009-10-05 21:00:48 +0000
280+++ example/interface_v1.c 2009-11-06 11:05:21 +0000
281@@ -393,7 +393,7 @@
282 }
283
284 memcached_binary_protocol_callback_st interface_v1_impl= {
285- .interface_version= 1,
286+ .interface_version= MEMCACHED_PROTOCOL_HANDLER_V1,
287 .interface.v1= {
288 .add= add_handler,
289 .append= append_handler,
290
291=== modified file 'libmemcached/protocol/callback.h'
292--- libmemcached/protocol/callback.h 2009-10-05 21:00:48 +0000
293+++ libmemcached/protocol/callback.h 2009-11-06 11:05:21 +0000
294@@ -338,15 +338,28 @@
295 memcached_binary_protocol_version_response_handler response_handler);
296 } memcached_binary_protocol_callback_v1_st;
297
298-/**
299- *
300+
301+/**
302+ * The version numbers for the different callback structures.
303+ */
304+typedef enum {
305+ /** Version 0 is a lowlevel interface that tries to maximize your freedom */
306+ MEMCACHED_PROTOCOL_HANDLER_V0= 0,
307+ /**
308+ * Version 1 abstracts more of the protocol details, and let you work at
309+ * a logical level
310+ */
311+ MEMCACHED_PROTOCOL_HANDLER_V1= 1,
312+} memcached_protocol_interface_version_t;
313+
314+/**
315+ * Definition of the protocol callback structure.
316 */
317 typedef struct {
318 /**
319- * The interface version used (set to 0 if you don't have any specialized
320- * command handlers).
321+ * The interface version you provide callbacks for.
322 */
323- uint64_t interface_version;
324+ memcached_protocol_interface_version_t interface_version;
325
326 /**
327 * Callback fired just before the command will be executed.

Subscribers

People subscribed via source and target branches

to all changes: