gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r16924 - gnunet/src/datacache
Date: Sun, 18 Sep 2011 12:42:00 +0200

Author: grothoff
Date: 2011-09-18 12:42:00 +0200 (Sun, 18 Sep 2011)
New Revision: 16924

Modified:
   gnunet/src/datacache/datacache.c
   gnunet/src/datacache/plugin_datacache_sqlite.c
Log:
more efficient implementation, maybe helping with 1777

Modified: gnunet/src/datacache/datacache.c
===================================================================
--- gnunet/src/datacache/datacache.c    2011-09-18 09:47:16 UTC (rev 16923)
+++ gnunet/src/datacache/datacache.c    2011-09-18 10:42:00 UTC (rev 16924)
@@ -237,7 +237,7 @@
                             GNUNET_NO);
   GNUNET_CONTAINER_bloomfilter_add (h->filter, key);
   while (h->utilization + used > h->env.quota)
-    GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
+    GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));    
   h->utilization += used;
   return GNUNET_OK;
 }

Modified: gnunet/src/datacache/plugin_datacache_sqlite.c
===================================================================
--- gnunet/src/datacache/plugin_datacache_sqlite.c      2011-09-18 09:47:16 UTC 
(rev 16923)
+++ gnunet/src/datacache/plugin_datacache_sqlite.c      2011-09-18 10:42:00 UTC 
(rev 16924)
@@ -115,7 +115,7 @@
     dval = INT64_MAX;
   if (sq_prepare
       (plugin->dbh,
-       "INSERT INTO ds090 " "(type, expire, key, value) " "VALUES (?, ?, ?, 
?)",
+       "INSERT INTO ds090 (type, expire, key, value) VALUES (?, ?, ?, ?)",
        &stmt) != SQLITE_OK)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
@@ -275,11 +275,10 @@
 sqlite_plugin_del (void *cls)
 {
   struct Plugin *plugin = cls;
+  unsigned long long rowid;
   unsigned int dsize;
-  unsigned int dtype;
   sqlite3_stmt *stmt;
   sqlite3_stmt *dstmt;
-  char blob[65536];
   GNUNET_HashCode hc;
 
 #if DEBUG_DATACACHE_SQLITE
@@ -289,7 +288,7 @@
   dstmt = NULL;
   if (sq_prepare
       (plugin->dbh,
-       "SELECT type, key, value FROM ds090 ORDER BY expire ASC LIMIT 1",
+       "SELECT _ROWID_,key,value FROM ds090 ORDER BY expire ASC LIMIT 1",
        &stmt) != SQLITE_OK)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
@@ -307,18 +306,16 @@
     (void) sqlite3_finalize (stmt);
     return GNUNET_SYSERR;
   }
-  dtype = sqlite3_column_int (stmt, 0);
-  GNUNET_break (sqlite3_column_bytes (stmt, 1) == sizeof (GNUNET_HashCode));
-  dsize = sqlite3_column_bytes (stmt, 2);
-  GNUNET_assert (dsize <= sizeof (blob));
-  memcpy (blob, sqlite3_column_blob (stmt, 2), dsize);
+  rowid = sqlite3_column_int64 (stmt, 0);
+  GNUNET_assert (sqlite3_column_bytes (stmt, 1) == sizeof (GNUNET_HashCode));
   memcpy (&hc, sqlite3_column_blob (stmt, 1), sizeof (GNUNET_HashCode));
+  dsize = sqlite3_column_bytes (stmt, 2);
   if (SQLITE_OK != sqlite3_finalize (stmt))
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
                 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_step",
                 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
   if (sq_prepare
-      (plugin->dbh, "DELETE FROM ds090 " "WHERE key=? AND value=? AND type=?",
+      (plugin->dbh, "DELETE FROM ds090 WHERE _ROWID_=?",
        &dstmt) != SQLITE_OK)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
@@ -328,15 +325,12 @@
       (void) sqlite3_finalize (stmt);
     return GNUNET_SYSERR;
   }
-  if ((SQLITE_OK !=
-       sqlite3_bind_blob (dstmt, 1, &hc, sizeof (GNUNET_HashCode),
-                          SQLITE_TRANSIENT)) ||
-      (SQLITE_OK != sqlite3_bind_blob (dstmt, 2, blob, dsize, 
SQLITE_TRANSIENT))
-      || (SQLITE_OK != sqlite3_bind_int (dstmt, 3, dtype)))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
-                _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_bind",
-                __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
+  if (SQLITE_OK !=
+      sqlite3_bind_int64 (dstmt, 1, rowid))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
+                 _("`%s' failed at %s:%d with error: %s\n"), "sqlite3_bind",
+                 __FILE__, __LINE__, sqlite3_errmsg (plugin->dbh));
     (void) sqlite3_finalize (dstmt);
     return GNUNET_SYSERR;
   }
@@ -420,9 +414,7 @@
   return api;
 }
 
-// explain SELECT type FROM gn090 WHERE NOT EXISTS (SELECT 1 from gn090 WHERE 
expire < 42 LIMIT 1) OR expire < 42 ORDER BY repl DESC, Random() LIMIT 1;
 
-
 /**
  * Exit point from the plugin.
  *




reply via email to

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