aboutsummaryrefslogtreecommitdiff
path: root/src/datacache/plugin_datacache_postgres.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-08-27 11:42:09 +0000
committerChristian Grothoff <christian@grothoff.org>2010-08-27 11:42:09 +0000
commitfb948e1e36718621b4dcc92b2a6f54c470812eb4 (patch)
tree96fe28cd7f139cdcd0ec5ae3c7ccc2ed56ad2919 /src/datacache/plugin_datacache_postgres.c
parent7222ddd36eb376fc2b1465a700d8ae496af006b7 (diff)
downloadgnunet-fb948e1e36718621b4dcc92b2a6f54c470812eb4.tar.gz
gnunet-fb948e1e36718621b4dcc92b2a6f54c470812eb4.zip
implementing delete
Diffstat (limited to 'src/datacache/plugin_datacache_postgres.c')
-rw-r--r--src/datacache/plugin_datacache_postgres.c71
1 files changed, 65 insertions, 6 deletions
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,
455static int 458static int
456postgres_plugin_del (void *cls) 459postgres_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;