adding configure code for --enable-benchmarks, --enable-expensive-tests, some clean up
[oweals/gnunet.git] / src / datastore / plugin_datastore_sqlite.c
index 3710b7eb7d0cc55d391486fb8728eace1a3fd617..3267869d5db79cdf8515623880be7616b0959b06 100644 (file)
@@ -475,7 +475,7 @@ sqlite_plugin_put (void *cls,
 #if DEBUG_SQLITE
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
                   "sqlite",
-                  "Storing in database block with type %u/key `%s'/priority %u/expiration %llu (%lld).\n",
+                  "Storing in database block with type %u/key `%s'/priority %u/expiration in %llu ms (%lld).\n",
                   type, 
                   GNUNET_h2s(key),
                   priority,
@@ -650,6 +650,12 @@ execute_get (struct Plugin *plugin,
          break;
        }
       expiration.abs_value = sqlite3_column_int64 (stmt, 3);
+#if DEBUG_SQLITE
+      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 
+                      "sqlite",
+                      "Found reply in database with expiration %llu\n",
+                      (unsigned long long) expiration.abs_value);
+#endif
       ret = proc (proc_cls,
                  sqlite3_column_blob (stmt, 4) /* key */,
                  size,
@@ -878,11 +884,6 @@ sqlite_plugin_get_key (void *cls,
 struct ReplCtx
 {
   
-  /**
-   * Plugin handle.
-   */
-  struct Plugin *plugin;
-  
   /**
    * Function to call for the result (or the NULL).
    */
@@ -892,6 +893,16 @@ struct ReplCtx
    * Closure for proc.
    */
   void *proc_cls;
+
+  /**
+   * UID to use.
+   */
+  uint64_t uid;
+
+  /**
+   * Yes if UID was set.
+   */
+  int have_uid;
 };
 
 
@@ -926,7 +937,6 @@ repl_proc (void *cls,
           uint64_t uid)
 {
   struct ReplCtx *rc = cls;
-  struct Plugin *plugin = rc->plugin;
   int ret;
 
   ret = rc->proc (rc->proc_cls,
@@ -934,24 +944,10 @@ repl_proc (void *cls,
                  size, data, 
                  type, priority, anonymity, expiration,
                  uid);
-  if (NULL != key)
+  if (key != NULL)
     {
-      sqlite3_bind_int64 (plugin->updRepl, 1, uid);
-      if (SQLITE_DONE != sqlite3_step (plugin->updRepl))
-       {
-         LOG_SQLITE (plugin, NULL,
-                     GNUNET_ERROR_TYPE_ERROR |
-                     GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
-         if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
-           LOG_SQLITE (plugin, NULL,
-                       GNUNET_ERROR_TYPE_ERROR |
-                       GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
-         return GNUNET_SYSERR;
-       }
-      if (SQLITE_OK != sqlite3_reset (plugin->delRow))
-       LOG_SQLITE (plugin, NULL,
-                   GNUNET_ERROR_TYPE_ERROR |
-                   GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+      rc->uid = uid;
+      rc->have_uid = GNUNET_YES;
     }
   return ret;
 }
@@ -979,10 +975,22 @@ sqlite_plugin_get_replication (void *cls,
                   "sqlite",
                   "Getting random block based on replication order.\n");
 #endif
-  rc.plugin = plugin;
+  rc.have_uid = GNUNET_NO;
   rc.proc = proc;
   rc.proc_cls = proc_cls;
-  execute_get (plugin, plugin->selRepl, &repl_proc, &rc);
+  execute_get (plugin, plugin->selRepl, &repl_proc, &rc); 
+  if (GNUNET_YES == rc.have_uid)
+    {
+      sqlite3_bind_int64 (plugin->updRepl, 1, rc.uid);
+      if (SQLITE_DONE != sqlite3_step (plugin->updRepl))       
+       LOG_SQLITE (plugin, NULL,
+                   GNUNET_ERROR_TYPE_ERROR |
+                   GNUNET_ERROR_TYPE_BULK, "sqlite3_step");
+      if (SQLITE_OK != sqlite3_reset (plugin->updRepl))
+       LOG_SQLITE (plugin, NULL,
+                   GNUNET_ERROR_TYPE_ERROR |
+                   GNUNET_ERROR_TYPE_BULK, "sqlite3_reset");
+    }
 }
 
 
@@ -1175,7 +1183,7 @@ libgnunet_plugin_datastore_sqlite_done (void *cls)
 #if DEBUG_SQLITE
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
                   "sqlite",
-                  "sqlite plugin is finished doneing\n");
+                  "sqlite plugin is finished\n");
 #endif
   return NULL;
 }