diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-08-27 11:42:09 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-08-27 11:42:09 +0000 |
commit | fb948e1e36718621b4dcc92b2a6f54c470812eb4 (patch) | |
tree | 96fe28cd7f139cdcd0ec5ae3c7ccc2ed56ad2919 /src/datacache | |
parent | 7222ddd36eb376fc2b1465a700d8ae496af006b7 (diff) | |
download | gnunet-fb948e1e36718621b4dcc92b2a6f54c470812eb4.tar.gz gnunet-fb948e1e36718621b4dcc92b2a6f54c470812eb4.zip |
implementing delete
Diffstat (limited to 'src/datacache')
-rw-r--r-- | src/datacache/datacache.c | 9 | ||||
-rw-r--r-- | src/datacache/plugin_datacache_postgres.c | 71 | ||||
-rw-r--r-- | src/datacache/test_datacache_quota.c | 1 |
3 files changed, 74 insertions, 7 deletions
diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c index 0ad9b9df4..6e9b07708 100644 --- a/src/datacache/datacache.c +++ b/src/datacache/datacache.c | |||
@@ -191,6 +191,7 @@ GNUNET_DATACACHE_create (struct GNUNET_SCHEDULER_Handle *sched, | |||
191 | GNUNET_DATACACHE_destroy (ret); | 191 | GNUNET_DATACACHE_destroy (ret); |
192 | return NULL; | 192 | return NULL; |
193 | } | 193 | } |
194 | GNUNET_assert (ret->api->get != NULL); | ||
194 | return ret; | 195 | return ret; |
195 | } | 196 | } |
196 | 197 | ||
@@ -244,6 +245,7 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, | |||
244 | { | 245 | { |
245 | uint32_t used; | 246 | uint32_t used; |
246 | 247 | ||
248 | GNUNET_assert (h->api->get != NULL); | ||
247 | used = h->api->put (h->api->cls, | 249 | used = h->api->put (h->api->cls, |
248 | key, | 250 | key, |
249 | size, | 251 | size, |
@@ -251,7 +253,10 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, | |||
251 | type, | 253 | type, |
252 | discard_time); | 254 | discard_time); |
253 | if (used == 0) | 255 | if (used == 0) |
254 | return GNUNET_SYSERR; | 256 | { |
257 | GNUNET_break (0); | ||
258 | return GNUNET_SYSERR; | ||
259 | } | ||
255 | GNUNET_STATISTICS_update (h->stats, | 260 | GNUNET_STATISTICS_update (h->stats, |
256 | gettext_noop ("# bytes stored"), | 261 | gettext_noop ("# bytes stored"), |
257 | size, | 262 | size, |
@@ -282,6 +287,7 @@ GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, | |||
282 | GNUNET_DATACACHE_Iterator iter, | 287 | GNUNET_DATACACHE_Iterator iter, |
283 | void *iter_cls) | 288 | void *iter_cls) |
284 | { | 289 | { |
290 | GNUNET_assert (h->api->get != NULL); | ||
285 | GNUNET_STATISTICS_update (h->stats, | 291 | GNUNET_STATISTICS_update (h->stats, |
286 | gettext_noop ("# requests received"), | 292 | gettext_noop ("# requests received"), |
287 | 1, | 293 | 1, |
@@ -295,6 +301,7 @@ GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, | |||
295 | GNUNET_NO); | 301 | GNUNET_NO); |
296 | return 0; /* can not be present */ | 302 | return 0; /* can not be present */ |
297 | } | 303 | } |
304 | GNUNET_assert (h->api->get != NULL); | ||
298 | return h->api->get (h->api->cls, | 305 | return h->api->get (h->api->cls, |
299 | key, | 306 | key, |
300 | type, | 307 | type, |
diff --git a/src/datacache/plugin_datacache_postgres.c b/src/datacache/plugin_datacache_postgres.c index 53118e6bf..6bf3c7011 100644 --- a/src/datacache/plugin_datacache_postgres.c +++ b/src/datacache/plugin_datacache_postgres.c | |||
@@ -30,7 +30,10 @@ | |||
30 | 30 | ||
31 | #define DEBUG_POSTGRES GNUNET_NO | 31 | #define DEBUG_POSTGRES GNUNET_NO |
32 | 32 | ||
33 | 33 | /** | |
34 | * Per-entry overhead estimate | ||
35 | */ | ||
36 | #define OVERHEAD (sizeof(GNUNET_HashCode) + 24) | ||
34 | 37 | ||
35 | /** | 38 | /** |
36 | * Context for all functions in this plugin. | 39 | * Context for all functions in this plugin. |
@@ -230,7 +233,7 @@ init_connection (struct Plugin *plugin) | |||
230 | (GNUNET_OK != | 233 | (GNUNET_OK != |
231 | pq_prepare (plugin, | 234 | pq_prepare (plugin, |
232 | "getm", | 235 | "getm", |
233 | "SELECT length(value),oid FROM gn090dc " | 236 | "SELECT length(value),oid,key FROM gn090dc " |
234 | "ORDER BY discard_time ASC LIMIT 1", | 237 | "ORDER BY discard_time ASC LIMIT 1", |
235 | 0, | 238 | 0, |
236 | __LINE__)) || | 239 | __LINE__)) || |
@@ -330,7 +333,7 @@ postgres_plugin_put (void *cls, | |||
330 | "PQexecPrepared", "put", __LINE__)) | 333 | "PQexecPrepared", "put", __LINE__)) |
331 | return GNUNET_SYSERR; | 334 | return GNUNET_SYSERR; |
332 | PQclear (ret); | 335 | PQclear (ret); |
333 | return size; | 336 | return size + OVERHEAD; |
334 | } | 337 | } |
335 | 338 | ||
336 | 339 | ||
@@ -455,9 +458,62 @@ postgres_plugin_get (void *cls, | |||
455 | static int | 458 | static int |
456 | postgres_plugin_del (void *cls) | 459 | postgres_plugin_del (void *cls) |
457 | { | 460 | { |
458 | 461 | struct Plugin *plugin = cls; | |
459 | GNUNET_break (0); | 462 | uint32_t size; |
460 | return GNUNET_SYSERR; | 463 | uint32_t oid; |
464 | GNUNET_HashCode key; | ||
465 | PGresult *res; | ||
466 | |||
467 | res = PQexecPrepared (plugin->dbh, | ||
468 | "getm", | ||
469 | 0, NULL, NULL, NULL, | ||
470 | 1); | ||
471 | if (GNUNET_OK != check_result (plugin, | ||
472 | res, | ||
473 | PGRES_TUPLES_OK, | ||
474 | "PQexecPrepared", | ||
475 | "getm", | ||
476 | __LINE__)) | ||
477 | { | ||
478 | #if DEBUG_POSTGRES | ||
479 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
480 | "datacache-postgres", | ||
481 | "Ending iteration (postgres error)\n"); | ||
482 | #endif | ||
483 | return 0; | ||
484 | } | ||
485 | if (0 == PQntuples (res)) | ||
486 | { | ||
487 | /* no result */ | ||
488 | #if DEBUG_POSTGRES | ||
489 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
490 | "datacache-postgres", | ||
491 | "Ending iteration (no more results)\n"); | ||
492 | #endif | ||
493 | PQclear (res); | ||
494 | return GNUNET_SYSERR; | ||
495 | } | ||
496 | if ( (3 != PQnfields (res)) || | ||
497 | (sizeof (uint32_t) != PQfsize (res, 0)) || | ||
498 | (sizeof (uint32_t) != PQfsize (res, 1)) || | ||
499 | (sizeof (GNUNET_HashCode) != PQfsize (res, 2)) ) | ||
500 | { | ||
501 | GNUNET_break (0); | ||
502 | PQclear (res); | ||
503 | return 0; | ||
504 | } | ||
505 | size = ntohl (*(uint32_t *) PQgetvalue (res, 0, 0)); | ||
506 | oid = ntohl (*(uint32_t *) PQgetvalue (res, 0, 1)); | ||
507 | memcpy (&key, | ||
508 | PQgetvalue (res, 0, 2), | ||
509 | sizeof (GNUNET_HashCode)); | ||
510 | PQclear (res); | ||
511 | if (GNUNET_OK != delete_by_rowid (plugin, oid)) | ||
512 | return GNUNET_SYSERR; | ||
513 | plugin->env->delete_notify (plugin->env->cls, | ||
514 | &key, | ||
515 | size); | ||
516 | return GNUNET_OK; | ||
461 | } | 517 | } |
462 | 518 | ||
463 | 519 | ||
@@ -508,6 +564,9 @@ libgnunet_plugin_datacache_postgres_done (void *cls) | |||
508 | struct GNUNET_DATACACHE_PluginFunctions *api = cls; | 564 | struct GNUNET_DATACACHE_PluginFunctions *api = cls; |
509 | struct Plugin *plugin = api->cls; | 565 | struct Plugin *plugin = api->cls; |
510 | 566 | ||
567 | fprintf (stderr, | ||
568 | "Unloading postgres plugin\n"); | ||
569 | PQfinish (plugin->dbh); | ||
511 | GNUNET_free (plugin); | 570 | GNUNET_free (plugin); |
512 | GNUNET_free (api); | 571 | GNUNET_free (api); |
513 | return NULL; | 572 | return NULL; |
diff --git a/src/datacache/test_datacache_quota.c b/src/datacache/test_datacache_quota.c index ada5ae171..9e1881bd8 100644 --- a/src/datacache/test_datacache_quota.c +++ b/src/datacache/test_datacache_quota.c | |||
@@ -88,6 +88,7 @@ run (void *cls, | |||
88 | buf, | 88 | buf, |
89 | 1+i, | 89 | 1+i, |
90 | exp)); | 90 | exp)); |
91 | fprintf (stderr, "G"); | ||
91 | ASSERT (0 < GNUNET_DATACACHE_get (h, | 92 | ASSERT (0 < GNUNET_DATACACHE_get (h, |
92 | &k, 1+i, | 93 | &k, 1+i, |
93 | NULL, NULL)); | 94 | NULL, NULL)); |