aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/perf_plugin_datastore.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/datastore/perf_plugin_datastore.c
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/datastore/perf_plugin_datastore.c')
-rw-r--r--src/datastore/perf_plugin_datastore.c563
1 files changed, 283 insertions, 280 deletions
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c
index 564f8f37b..a051f27ca 100644
--- a/src/datastore/perf_plugin_datastore.c
+++ b/src/datastore/perf_plugin_datastore.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/* 20/*
21 * @file perf_plugin_datastore.c 21 * @file perf_plugin_datastore.c
22 * @brief Profile database plugin directly, focusing on iterators. 22 * @brief Profile database plugin directly, focusing on iterators.
@@ -59,8 +59,7 @@ static const char *plugin_name;
59 59
60static int ok; 60static int ok;
61 61
62enum RunPhase 62enum RunPhase {
63{
64 RP_ERROR = 0, 63 RP_ERROR = 0,
65 RP_PUT, 64 RP_PUT,
66 RP_REP_GET, 65 RP_REP_GET,
@@ -70,8 +69,7 @@ enum RunPhase
70}; 69};
71 70
72 71
73struct CpsRunContext 72struct CpsRunContext {
74{
75 unsigned int i; 73 unsigned int i;
76 struct GNUNET_TIME_Absolute start; 74 struct GNUNET_TIME_Absolute start;
77 struct GNUNET_TIME_Absolute end; 75 struct GNUNET_TIME_Absolute end;
@@ -93,13 +91,13 @@ struct CpsRunContext
93 * 0 for "reset to empty" 91 * 0 for "reset to empty"
94 */ 92 */
95static void 93static void
96disk_utilization_change_cb (void *cls, int delta) 94disk_utilization_change_cb(void *cls, int delta)
97{ 95{
98} 96}
99 97
100 98
101static void 99static void
102test (void *cls); 100test(void *cls);
103 101
104 102
105/** 103/**
@@ -112,30 +110,30 @@ test (void *cls);
112 * @param msg error message on error 110 * @param msg error message on error
113 */ 111 */
114static void 112static void
115put_continuation (void *cls, 113put_continuation(void *cls,
116 const struct GNUNET_HashCode *key, 114 const struct GNUNET_HashCode *key,
117 uint32_t size, 115 uint32_t size,
118 int status, 116 int status,
119 const char *msg) 117 const char *msg)
120{ 118{
121 struct CpsRunContext *crc = cls; 119 struct CpsRunContext *crc = cls;
122 120
123 if (GNUNET_OK != status) 121 if (GNUNET_OK != status)
124 { 122 {
125 fprintf (stderr, "ERROR: `%s'\n", msg); 123 fprintf(stderr, "ERROR: `%s'\n", msg);
126 } 124 }
127 else 125 else
128 { 126 {
129 stored_bytes += size; 127 stored_bytes += size;
130 stored_ops++; 128 stored_ops++;
131 stored_entries++; 129 stored_entries++;
132 } 130 }
133 GNUNET_SCHEDULER_add_now (&test, crc); 131 GNUNET_SCHEDULER_add_now(&test, crc);
134} 132}
135 133
136 134
137static void 135static void
138do_put (struct CpsRunContext *crc) 136do_put(struct CpsRunContext *crc)
139{ 137{
140 char value[65536]; 138 char value[65536];
141 size_t size; 139 size_t size;
@@ -144,66 +142,123 @@ do_put (struct CpsRunContext *crc)
144 unsigned int prio; 142 unsigned int prio;
145 143
146 if (0 == i) 144 if (0 == i)
147 crc->start = GNUNET_TIME_absolute_get (); 145 crc->start = GNUNET_TIME_absolute_get();
148 if (PUT_10 == i) 146 if (PUT_10 == i)
149 {
150 i = 0;
151 crc->end = GNUNET_TIME_absolute_get ();
152 { 147 {
153 printf ("%s took %s for %llu items\n", "Storing an item", 148 i = 0;
154 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (crc->start, 149 crc->end = GNUNET_TIME_absolute_get();
155 crc->end), 150 {
156 GNUNET_YES), 151 printf("%s took %s for %llu items\n", "Storing an item",
157 PUT_10); 152 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_difference(crc->start,
158 if (PUT_10 > 0) 153 crc->end),
159 GAUGER (category, "Storing an item", 154 GNUNET_YES),
160 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / PUT_10, 155 PUT_10);
161 "ms/item"); 156 if (PUT_10 > 0)
157 GAUGER(category, "Storing an item",
158 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / PUT_10,
159 "ms/item");
160 }
161 crc->i++;
162 crc->start = GNUNET_TIME_absolute_get();
163 crc->phase++;
164 GNUNET_SCHEDULER_add_now(&test, crc);
165 return;
162 } 166 }
163 crc->i++;
164 crc->start = GNUNET_TIME_absolute_get ();
165 crc->phase++;
166 GNUNET_SCHEDULER_add_now (&test, crc);
167 return;
168 }
169 /* most content is 32k */ 167 /* most content is 32k */
170 size = 32 * 1024; 168 size = 32 * 1024;
171 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ 169 if (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
172 size = 8 + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); 170 size = 8 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
173 size = size - (size & 7); /* always multiple of 8 */ 171 size = size - (size & 7); /* always multiple of 8 */
174 172
175 /* generate random key */ 173 /* generate random key */
176 key.bits[0] = (unsigned int) GNUNET_TIME_absolute_get ().abs_value_us; 174 key.bits[0] = (unsigned int)GNUNET_TIME_absolute_get().abs_value_us;
177 GNUNET_CRYPTO_hash (&key, sizeof (struct GNUNET_HashCode), &key); 175 GNUNET_CRYPTO_hash(&key, sizeof(struct GNUNET_HashCode), &key);
178 memset (value, i, size); 176 memset(value, i, size);
179 if (i > 255) 177 if (i > 255)
180 memset (value, i - 255, size / 2); 178 memset(value, i - 255, size / 2);
181 value[0] = crc->i; 179 value[0] = crc->i;
182 GNUNET_memcpy (&value[4], &i, sizeof (i)); 180 GNUNET_memcpy(&value[4], &i, sizeof(i));
183 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); 181 prio = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100);
184 crc->api->put (crc->api->cls, 182 crc->api->put(crc->api->cls,
185 &key, 183 &key,
186 false /* absent */, 184 false /* absent */,
187 size, 185 size,
188 value, 186 value,
189 1 + i % 4 /* type */ , 187 1 + i % 4 /* type */,
190 prio, 188 prio,
191 i % 4 /* anonymity */ , 189 i % 4 /* anonymity */,
192 0 /* replication */ , 190 0 /* replication */,
193 GNUNET_TIME_relative_to_absolute 191 GNUNET_TIME_relative_to_absolute
194 (GNUNET_TIME_relative_multiply 192 (GNUNET_TIME_relative_multiply
195 (GNUNET_TIME_UNIT_MILLISECONDS, 193 (GNUNET_TIME_UNIT_MILLISECONDS,
196 60 * 60 * 60 * 1000 + 194 60 * 60 * 60 * 1000 +
197 GNUNET_CRYPTO_random_u32 195 GNUNET_CRYPTO_random_u32
198 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), 196 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
199 put_continuation, 197 put_continuation,
200 crc); 198 crc);
201 i++; 199 i++;
202} 200}
203 201
204 202
205static int 203static int
206iterate_zeros (void *cls, 204iterate_zeros(void *cls,
205 const struct GNUNET_HashCode *key,
206 uint32_t size,
207 const void *data,
208 enum GNUNET_BLOCK_Type type,
209 uint32_t priority,
210 uint32_t anonymity,
211 uint32_t replication,
212 struct GNUNET_TIME_Absolute expiration,
213 uint64_t uid)
214{
215 struct CpsRunContext *crc = cls;
216 int i;
217 const char *cdata = data;
218
219 GNUNET_assert(key != NULL);
220 GNUNET_assert(size >= 8);
221 GNUNET_memcpy(&i, &cdata[4], sizeof(i));
222 hits[i / 8] |= (1 << (i % 8));
223
224 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
225 "Found result %d type=%u, priority=%u, size=%u, expire=%s\n",
226 i,
227 type, priority, size,
228 GNUNET_STRINGS_absolute_time_to_string(expiration));
229 crc->cnt++;
230 if (crc->cnt == PUT_10 / 4 - 1)
231 {
232 unsigned int bc;
233
234 bc = 0;
235 for (i = 0; i < PUT_10; i++)
236 if (0 != (hits[i / 8] & (1 << (i % 8))))
237 bc++;
238
239 crc->end = GNUNET_TIME_absolute_get();
240 printf("%s took %s yielding %u/%u items\n",
241 "Select random zero-anonymity item",
242 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_difference(crc->start,
243 crc->end),
244 GNUNET_YES),
245 bc, crc->cnt);
246 if (crc->cnt > 0)
247 GAUGER(category, "Select random zero-anonymity item",
248 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt,
249 "ms/item");
250 memset(hits, 0, sizeof(hits));
251 crc->phase++;
252 crc->cnt = 0;
253 crc->start = GNUNET_TIME_absolute_get();
254 }
255 GNUNET_SCHEDULER_add_now(&test, crc);
256 return GNUNET_OK;
257}
258
259
260static int
261expiration_get(void *cls,
207 const struct GNUNET_HashCode *key, 262 const struct GNUNET_HashCode *key,
208 uint32_t size, 263 uint32_t size,
209 const void *data, 264 const void *data,
@@ -218,49 +273,45 @@ iterate_zeros (void *cls,
218 int i; 273 int i;
219 const char *cdata = data; 274 const char *cdata = data;
220 275
221 GNUNET_assert (key != NULL); 276 GNUNET_assert(size >= 8);
222 GNUNET_assert (size >= 8); 277 GNUNET_memcpy(&i, &cdata[4], sizeof(i));
223 GNUNET_memcpy (&i, &cdata[4], sizeof (i));
224 hits[i / 8] |= (1 << (i % 8)); 278 hits[i / 8] |= (1 << (i % 8));
225
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
227 "Found result %d type=%u, priority=%u, size=%u, expire=%s\n",
228 i,
229 type, priority, size,
230 GNUNET_STRINGS_absolute_time_to_string (expiration));
231 crc->cnt++; 279 crc->cnt++;
232 if (crc->cnt == PUT_10 / 4 - 1) 280 if (PUT_10 <= crc->cnt)
233 { 281 {
234 unsigned int bc; 282 unsigned int bc;
235 283
236 bc = 0; 284 bc = 0;
237 for (i = 0; i < PUT_10; i++) 285 for (i = 0; i < PUT_10; i++)
238 if (0 != (hits[i / 8] & (1 << (i % 8)))) 286 if (0 != (hits[i / 8] & (1 << (i % 8))))
239 bc++; 287 bc++;
240 288
241 crc->end = GNUNET_TIME_absolute_get (); 289 crc->end = GNUNET_TIME_absolute_get();
242 printf ("%s took %s yielding %u/%u items\n", 290 printf("%s took %s yielding %u/%u items\n",
243 "Select random zero-anonymity item", 291 "Selecting and deleting by expiration",
244 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (crc->start, 292 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_difference(crc->start,
245 crc->end), 293 crc->end),
246 GNUNET_YES), 294 GNUNET_YES),
247 bc, crc->cnt); 295 bc, (unsigned int)PUT_10);
248 if (crc->cnt > 0) 296 if (crc->cnt > 0)
249 GAUGER (category, "Select random zero-anonymity item", 297 GAUGER(category, "Selecting and deleting by expiration",
250 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt, 298 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt,
251 "ms/item"); 299 "ms/item");
252 memset (hits, 0, sizeof (hits)); 300 memset(hits, 0, sizeof(hits));
253 crc->phase++; 301 if (++crc->iter == ITERATIONS)
254 crc->cnt = 0; 302 crc->phase++;
255 crc->start = GNUNET_TIME_absolute_get (); 303 else
256 } 304 crc->phase = RP_PUT;
257 GNUNET_SCHEDULER_add_now (&test, crc); 305 crc->cnt = 0;
258 return GNUNET_OK; 306 crc->start = GNUNET_TIME_absolute_get();
307 }
308 GNUNET_SCHEDULER_add_now(&test, crc);
309 return GNUNET_NO;
259} 310}
260 311
261 312
262static int 313static int
263expiration_get (void *cls, 314replication_get(void *cls,
264 const struct GNUNET_HashCode *key, 315 const struct GNUNET_HashCode *key,
265 uint32_t size, 316 uint32_t size,
266 const void *data, 317 const void *data,
@@ -275,92 +326,39 @@ expiration_get (void *cls,
275 int i; 326 int i;
276 const char *cdata = data; 327 const char *cdata = data;
277 328
278 GNUNET_assert (size >= 8); 329 GNUNET_assert(NULL != key);
279 GNUNET_memcpy (&i, &cdata[4], sizeof (i)); 330 GNUNET_assert(size >= 8);
331 GNUNET_memcpy(&i, &cdata[4], sizeof(i));
280 hits[i / 8] |= (1 << (i % 8)); 332 hits[i / 8] |= (1 << (i % 8));
281 crc->cnt++; 333 crc->cnt++;
282 if (PUT_10 <= crc->cnt) 334 if (PUT_10 <= crc->cnt)
283 { 335 {
284 unsigned int bc; 336 unsigned int bc;
285 337
286 bc = 0; 338 bc = 0;
287 for (i = 0; i < PUT_10; i++) 339 for (i = 0; i < PUT_10; i++)
288 if (0 != (hits[i / 8] & (1 << (i % 8)))) 340 if (0 != (hits[i / 8] & (1 << (i % 8))))
289 bc++; 341 bc++;
290 342
291 crc->end = GNUNET_TIME_absolute_get (); 343 crc->end = GNUNET_TIME_absolute_get();
292 printf ("%s took %s yielding %u/%u items\n", 344 printf("%s took %s yielding %u/%u items\n",
293 "Selecting and deleting by expiration", 345 "Selecting random item for replication",
294 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (crc->start, 346 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_difference(crc->start,
295 crc->end), 347 crc->end),
296 GNUNET_YES), 348 GNUNET_YES),
297 bc, (unsigned int) PUT_10); 349 bc, (unsigned int)PUT_10);
298 if (crc->cnt > 0) 350 if (crc->cnt > 0)
299 GAUGER (category, "Selecting and deleting by expiration", 351 GAUGER(category, "Selecting random item for replication",
300 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt, 352 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt,
301 "ms/item"); 353 "ms/item");
302 memset (hits, 0, sizeof (hits)); 354 memset(hits, 0, sizeof(hits));
303 if (++crc->iter == ITERATIONS)
304 crc->phase++; 355 crc->phase++;
305 else 356 crc->offset = 0;
306 crc->phase = RP_PUT; 357 crc->cnt = 0;
307 crc->cnt = 0; 358 crc->start = GNUNET_TIME_absolute_get();
308 crc->start = GNUNET_TIME_absolute_get (); 359 }
309 }
310 GNUNET_SCHEDULER_add_now (&test, crc);
311 return GNUNET_NO;
312}
313
314
315static int
316replication_get (void *cls,
317 const struct GNUNET_HashCode *key,
318 uint32_t size,
319 const void *data,
320 enum GNUNET_BLOCK_Type type,
321 uint32_t priority,
322 uint32_t anonymity,
323 uint32_t replication,
324 struct GNUNET_TIME_Absolute expiration,
325 uint64_t uid)
326{
327 struct CpsRunContext *crc = cls;
328 int i;
329 const char *cdata = data;
330 360
331 GNUNET_assert (NULL != key); 361 GNUNET_SCHEDULER_add_now(&test, crc);
332 GNUNET_assert (size >= 8);
333 GNUNET_memcpy (&i, &cdata[4], sizeof (i));
334 hits[i / 8] |= (1 << (i % 8));
335 crc->cnt++;
336 if (PUT_10 <= crc->cnt)
337 {
338 unsigned int bc;
339
340 bc = 0;
341 for (i = 0; i < PUT_10; i++)
342 if (0 != (hits[i / 8] & (1 << (i % 8))))
343 bc++;
344
345 crc->end = GNUNET_TIME_absolute_get ();
346 printf ("%s took %s yielding %u/%u items\n",
347 "Selecting random item for replication",
348 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (crc->start,
349 crc->end),
350 GNUNET_YES),
351 bc, (unsigned int) PUT_10);
352 if (crc->cnt > 0)
353 GAUGER (category, "Selecting random item for replication",
354 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / crc->cnt,
355 "ms/item");
356 memset (hits, 0, sizeof (hits));
357 crc->phase++;
358 crc->offset = 0;
359 crc->cnt = 0;
360 crc->start = GNUNET_TIME_absolute_get ();
361 }
362
363 GNUNET_SCHEDULER_add_now (&test, crc);
364 return GNUNET_OK; 362 return GNUNET_OK;
365} 363}
366 364
@@ -373,25 +371,25 @@ replication_get (void *cls,
373 * @param cfg configuration to use 371 * @param cfg configuration to use
374 */ 372 */
375static void 373static void
376unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api, 374unload_plugin(struct GNUNET_DATASTORE_PluginFunctions *api,
377 const struct GNUNET_CONFIGURATION_Handle *cfg) 375 const struct GNUNET_CONFIGURATION_Handle *cfg)
378{ 376{
379 char *name; 377 char *name;
380 char *libname; 378 char *libname;
381 379
382 if (GNUNET_OK != 380 if (GNUNET_OK !=
383 GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE", 381 GNUNET_CONFIGURATION_get_value_string(cfg, "DATASTORE", "DATABASE",
384 &name)) 382 &name))
385 { 383 {
386 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 384 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
387 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", 385 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE",
388 "DATASTORE"); 386 "DATASTORE");
389 return; 387 return;
390 } 388 }
391 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 389 GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", name);
392 GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); 390 GNUNET_break(NULL == GNUNET_PLUGIN_unload(libname, api));
393 GNUNET_free (libname); 391 GNUNET_free(libname);
394 GNUNET_free (name); 392 GNUNET_free(name);
395} 393}
396 394
397 395
@@ -401,51 +399,56 @@ unload_plugin (struct GNUNET_DATASTORE_PluginFunctions *api,
401 * the transport and core. 399 * the transport and core.
402 */ 400 */
403static void 401static void
404cleaning_task (void *cls) 402cleaning_task(void *cls)
405{ 403{
406 struct CpsRunContext *crc = cls; 404 struct CpsRunContext *crc = cls;
407 405
408 unload_plugin (crc->api, crc->cfg); 406 unload_plugin(crc->api, crc->cfg);
409 GNUNET_free (crc); 407 GNUNET_free(crc);
410} 408}
411 409
412 410
413static void 411static void
414test (void *cls) 412test(void *cls)
415{ 413{
416 struct CpsRunContext *crc = cls; 414 struct CpsRunContext *crc = cls;
417 415
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 416 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
419 "In phase %d, iteration %u\n", crc->phase, crc->cnt); 417 "In phase %d, iteration %u\n", crc->phase, crc->cnt);
420 switch (crc->phase) 418 switch (crc->phase)
421 { 419 {
422 case RP_ERROR: 420 case RP_ERROR:
423 GNUNET_break (0); 421 GNUNET_break(0);
424 crc->api->drop (crc->api->cls); 422 crc->api->drop(crc->api->cls);
425 ok = 1; 423 ok = 1;
426 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 424 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE,
427 &cleaning_task, crc); 425 &cleaning_task, crc);
428 break; 426 break;
429 case RP_PUT: 427
430 do_put (crc); 428 case RP_PUT:
431 break; 429 do_put(crc);
432 case RP_REP_GET: 430 break;
433 crc->api->get_replication (crc->api->cls, &replication_get, crc); 431
434 break; 432 case RP_REP_GET:
435 case RP_ZA_GET: 433 crc->api->get_replication(crc->api->cls, &replication_get, crc);
436 crc->api->get_zero_anonymity (crc->api->cls, crc->offset++, 1, 434 break;
437 &iterate_zeros, crc); 435
438 break; 436 case RP_ZA_GET:
439 case RP_EXP_GET: 437 crc->api->get_zero_anonymity(crc->api->cls, crc->offset++, 1,
440 crc->api->get_expiration (crc->api->cls, &expiration_get, crc); 438 &iterate_zeros, crc);
441 break; 439 break;
442 case RP_DONE: 440
443 crc->api->drop (crc->api->cls); 441 case RP_EXP_GET:
444 ok = 0; 442 crc->api->get_expiration(crc->api->cls, &expiration_get, crc);
445 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, 443 break;
446 &cleaning_task, crc); 444
447 break; 445 case RP_DONE:
448 } 446 crc->api->drop(crc->api->cls);
447 ok = 0;
448 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE,
449 &cleaning_task, crc);
450 break;
451 }
449} 452}
450 453
451 454
@@ -453,7 +456,7 @@ test (void *cls)
453 * Load the datastore plugin. 456 * Load the datastore plugin.
454 */ 457 */
455static struct GNUNET_DATASTORE_PluginFunctions * 458static struct GNUNET_DATASTORE_PluginFunctions *
456load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) 459load_plugin(const struct GNUNET_CONFIGURATION_Handle *cfg)
457{ 460{
458 static struct GNUNET_DATASTORE_PluginEnvironment env; 461 static struct GNUNET_DATASTORE_PluginEnvironment env;
459 struct GNUNET_DATASTORE_PluginFunctions *ret; 462 struct GNUNET_DATASTORE_PluginFunctions *ret;
@@ -461,63 +464,63 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg)
461 char *libname; 464 char *libname;
462 465
463 if (GNUNET_OK != 466 if (GNUNET_OK !=
464 GNUNET_CONFIGURATION_get_value_string (cfg, "DATASTORE", "DATABASE", 467 GNUNET_CONFIGURATION_get_value_string(cfg, "DATASTORE", "DATABASE",
465 &name)) 468 &name))
466 { 469 {
467 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 470 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
468 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE", 471 _("No `%s' specified for `%s' in configuration!\n"), "DATABASE",
469 "DATASTORE"); 472 "DATASTORE");
470 return NULL; 473 return NULL;
471 } 474 }
472 env.cfg = cfg; 475 env.cfg = cfg;
473 env.duc = &disk_utilization_change_cb; 476 env.duc = &disk_utilization_change_cb;
474 env.cls = NULL; 477 env.cls = NULL;
475 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"), 478 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Loading `%s' datastore plugin\n"),
476 name); 479 name);
477 GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name); 480 GNUNET_asprintf(&libname, "libgnunet_plugin_datastore_%s", name);
478 if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env))) 481 if (NULL == (ret = GNUNET_PLUGIN_load(libname, &env)))
479 { 482 {
480 fprintf (stderr, "Failed to load plugin `%s'!\n", name); 483 fprintf(stderr, "Failed to load plugin `%s'!\n", name);
481 GNUNET_free (name); 484 GNUNET_free(name);
482 GNUNET_free (libname); 485 GNUNET_free(libname);
483 return NULL; 486 return NULL;
484 } 487 }
485 GNUNET_free (libname); 488 GNUNET_free(libname);
486 GNUNET_free (name); 489 GNUNET_free(name);
487 return ret; 490 return ret;
488} 491}
489 492
490 493
491static void 494static void
492run (void *cls, char *const *args, const char *cfgfile, 495run(void *cls, char *const *args, const char *cfgfile,
493 const struct GNUNET_CONFIGURATION_Handle *c) 496 const struct GNUNET_CONFIGURATION_Handle *c)
494{ 497{
495 struct GNUNET_DATASTORE_PluginFunctions *api; 498 struct GNUNET_DATASTORE_PluginFunctions *api;
496 struct CpsRunContext *crc; 499 struct CpsRunContext *crc;
497 500
498 if (NULL == c) 501 if (NULL == c)
499 { 502 {
500 GNUNET_break (0); 503 GNUNET_break(0);
501 return; 504 return;
502 } 505 }
503 api = load_plugin (c); 506 api = load_plugin(c);
504 if (api == NULL) 507 if (api == NULL)
505 { 508 {
506 fprintf (stderr, 509 fprintf(stderr,
507 "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n"); 510 "%s", "Could not initialize plugin, assuming database not configured. Test not run!\n");
508 return; 511 return;
509 } 512 }
510 crc = GNUNET_new (struct CpsRunContext); 513 crc = GNUNET_new(struct CpsRunContext);
511 crc->api = api; 514 crc->api = api;
512 crc->cfg = c; 515 crc->cfg = c;
513 crc->phase = RP_PUT; 516 crc->phase = RP_PUT;
514 ok = 2; 517 ok = 2;
515 GNUNET_SCHEDULER_add_now (&test, crc); 518 GNUNET_SCHEDULER_add_now(&test, crc);
516} 519}
517 520
518 521
519int 522int
520main (int argc, char *argv[]) 523main(int argc, char *argv[])
521{ 524{
522 char dir_name[PATH_MAX]; 525 char dir_name[PATH_MAX];
523 char cfg_name[PATH_MAX]; 526 char cfg_name[PATH_MAX];
@@ -531,21 +534,21 @@ main (int argc, char *argv[])
531 GNUNET_GETOPT_OPTION_END 534 GNUNET_GETOPT_OPTION_END
532 }; 535 };
533 536
534 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); 537 plugin_name = GNUNET_TESTING_get_testname_from_underscore(argv[0]);
535 GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/perf-gnunet-datastore-%s", 538 GNUNET_snprintf(dir_name, sizeof(dir_name), "/tmp/perf-gnunet-datastore-%s",
536 plugin_name); 539 plugin_name);
537 GNUNET_DISK_directory_remove (dir_name); 540 GNUNET_DISK_directory_remove(dir_name);
538 GNUNET_log_setup ("perf-plugin-datastore", 541 GNUNET_log_setup("perf-plugin-datastore",
539 "WARNING", 542 "WARNING",
540 NULL); 543 NULL);
541 GNUNET_snprintf (category, sizeof (category), "DATASTORE-%s", plugin_name); 544 GNUNET_snprintf(category, sizeof(category), "DATASTORE-%s", plugin_name);
542 GNUNET_snprintf (cfg_name, sizeof (cfg_name), 545 GNUNET_snprintf(cfg_name, sizeof(cfg_name),
543 "perf_plugin_datastore_data_%s.conf", plugin_name); 546 "perf_plugin_datastore_data_%s.conf", plugin_name);
544 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, 547 GNUNET_PROGRAM_run((sizeof(xargv) / sizeof(char *)) - 1, xargv,
545 "perf-plugin-datastore", "nohelp", options, &run, NULL); 548 "perf-plugin-datastore", "nohelp", options, &run, NULL);
546 if (ok != 0) 549 if (ok != 0)
547 fprintf (stderr, "Missed some testcases: %u\n", ok); 550 fprintf(stderr, "Missed some testcases: %u\n", ok);
548 GNUNET_DISK_directory_remove (dir_name); 551 GNUNET_DISK_directory_remove(dir_name);
549 552
550 return ok; 553 return ok;
551} 554}