gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r12749 - gnunet/src/datacache


From: gnunet
Subject: [GNUnet-SVN] r12749 - gnunet/src/datacache
Date: Fri, 27 Aug 2010 13:42:09 +0200

Author: grothoff
Date: 2010-08-27 13:42:09 +0200 (Fri, 27 Aug 2010)
New Revision: 12749

Modified:
   gnunet/src/datacache/datacache.c
   gnunet/src/datacache/plugin_datacache_postgres.c
   gnunet/src/datacache/test_datacache_quota.c
Log:
implementing delete

Modified: gnunet/src/datacache/datacache.c
===================================================================
--- gnunet/src/datacache/datacache.c    2010-08-27 11:19:27 UTC (rev 12748)
+++ gnunet/src/datacache/datacache.c    2010-08-27 11:42:09 UTC (rev 12749)
@@ -191,6 +191,7 @@
       GNUNET_DATACACHE_destroy (ret);
       return NULL;
     }
+  GNUNET_assert (ret->api->get != NULL);
   return ret;
 }
 
@@ -244,6 +245,7 @@
 {
   uint32_t used;
 
+  GNUNET_assert (h->api->get != NULL);
   used = h->api->put (h->api->cls,
                      key,
                      size,
@@ -251,7 +253,10 @@
                      type,
                      discard_time);
   if (used == 0)
-    return GNUNET_SYSERR;
+    {
+      GNUNET_break (0);
+      return GNUNET_SYSERR;
+    }
   GNUNET_STATISTICS_update (h->stats,
                            gettext_noop ("# bytes stored"),
                            size,
@@ -282,6 +287,7 @@
                      GNUNET_DATACACHE_Iterator iter,
                      void *iter_cls)
 {
+  GNUNET_assert (h->api->get != NULL);
   GNUNET_STATISTICS_update (h->stats,
                            gettext_noop ("# requests received"),
                            1,
@@ -295,6 +301,7 @@
                                GNUNET_NO);
       return 0; /* can not be present */
     } 
+  GNUNET_assert (h->api->get != NULL);
   return h->api->get (h->api->cls,
                      key,
                      type,

Modified: gnunet/src/datacache/plugin_datacache_postgres.c
===================================================================
--- gnunet/src/datacache/plugin_datacache_postgres.c    2010-08-27 11:19:27 UTC 
(rev 12748)
+++ gnunet/src/datacache/plugin_datacache_postgres.c    2010-08-27 11:42:09 UTC 
(rev 12749)
@@ -30,8 +30,11 @@
 
 #define DEBUG_POSTGRES GNUNET_NO
 
+/**
+ * Per-entry overhead estimate
+ */
+#define OVERHEAD (sizeof(GNUNET_HashCode) + 24)
 
-
 /**
  * Context for all functions in this plugin.
  */
@@ -230,7 +233,7 @@
       (GNUNET_OK !=
        pq_prepare (plugin,
                   "getm",
-                   "SELECT length(value),oid FROM gn090dc "
+                   "SELECT length(value),oid,key FROM gn090dc "
                    "ORDER BY discard_time ASC LIMIT 1",
                    0,
                    __LINE__)) ||
@@ -330,7 +333,7 @@
                                  "PQexecPrepared", "put", __LINE__))
     return GNUNET_SYSERR;
   PQclear (ret);
-  return size;
+  return size + OVERHEAD;
 }
 
 
@@ -455,9 +458,62 @@
 static int 
 postgres_plugin_del (void *cls)
 {
-  
-  GNUNET_break (0);
-  return GNUNET_SYSERR;
+  struct Plugin *plugin = cls;
+  uint32_t size;
+  uint32_t oid;
+  GNUNET_HashCode key;
+  PGresult *res;
+
+  res = PQexecPrepared (plugin->dbh,
+                       "getm",
+                       0, NULL, NULL, NULL,
+                       1);
+  if (GNUNET_OK != check_result (plugin,
+                                res,
+                                PGRES_TUPLES_OK,
+                                "PQexecPrepared",
+                                "getm",
+                                __LINE__))
+    {
+#if DEBUG_POSTGRES
+      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+                      "datacache-postgres",
+                      "Ending iteration (postgres error)\n");
+#endif
+      return 0;
+    }
+  if (0 == PQntuples (res))
+    {
+      /* no result */
+#if DEBUG_POSTGRES
+      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+                      "datacache-postgres",
+                      "Ending iteration (no more results)\n");
+#endif
+      PQclear (res);
+      return GNUNET_SYSERR; 
+    }
+  if ( (3 != PQnfields (res)) ||
+       (sizeof (uint32_t) != PQfsize (res, 0)) ||
+       (sizeof (uint32_t) != PQfsize (res, 1)) ||
+       (sizeof (GNUNET_HashCode) != PQfsize (res, 2)) )
+    {
+      GNUNET_break (0);
+      PQclear (res);
+      return 0;
+    }  
+  size = ntohl (*(uint32_t *) PQgetvalue (res, 0, 0));
+  oid = ntohl (*(uint32_t *) PQgetvalue (res, 0, 1));
+  memcpy (&key,
+         PQgetvalue (res, 0, 2),
+         sizeof (GNUNET_HashCode));
+  PQclear (res);
+  if (GNUNET_OK != delete_by_rowid (plugin, oid))
+    return GNUNET_SYSERR;
+  plugin->env->delete_notify (plugin->env->cls,
+                             &key,
+                             size);  
+  return GNUNET_OK;
 }
 
 
@@ -508,6 +564,9 @@
   struct GNUNET_DATACACHE_PluginFunctions *api = cls;
   struct Plugin *plugin = api->cls;
 
+  fprintf (stderr,
+          "Unloading postgres plugin\n");
+  PQfinish (plugin->dbh);
   GNUNET_free (plugin);
   GNUNET_free (api);
   return NULL;

Modified: gnunet/src/datacache/test_datacache_quota.c
===================================================================
--- gnunet/src/datacache/test_datacache_quota.c 2010-08-27 11:19:27 UTC (rev 
12748)
+++ gnunet/src/datacache/test_datacache_quota.c 2010-08-27 11:42:09 UTC (rev 
12749)
@@ -88,6 +88,7 @@
                                        buf,
                                        1+i,
                                        exp));
+         fprintf (stderr, "G");
           ASSERT (0 < GNUNET_DATACACHE_get (h, 
                                            &k, 1+i, 
                                            NULL, NULL));




reply via email to

[Prev in Thread] Current Thread [Next in Thread]