do not fail if datastore unavailable
authorChristian Grothoff <christian@grothoff.org>
Sat, 7 Aug 2010 16:55:16 +0000 (16:55 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 7 Aug 2010 16:55:16 +0000 (16:55 +0000)
contrib/defaults.conf
src/datastore/datastore_api.c
src/datastore/gnunet-service-datastore.c
src/datastore/perf_datastore_api.c
src/datastore/perf_plugin_datastore.c
src/datastore/perf_plugin_datastore_data_mysql.conf
src/datastore/test_datastore_api.c
src/datastore/test_datastore_api_management.c
src/include/gnunet_block_lib.h
src/include/gnunet_fs_service.h
src/util/bio.c

index 0168704667ccc79782e72ee2ea66deca216a1bbc..74efa2260ed6265d11250731fc6af16b1e01a1c0 100644 (file)
@@ -211,6 +211,7 @@ INDEXDB = $SERVICEHOME/idxinfo.lst
 TRUST = $SERVICEHOME/data/credit/
 IDENTITY_DIR = $SERVICEHOME/identities/
 STATE_DIR = $SERVICEHOME/persistence/
+UPDATE_DIR = $SERVICEHOME/updates/
 PORT = 2094
 HOSTNAME = localhost
 HOME = $SERVICEHOME
index dcafeb839d659ab6461edcddbae7775e538438ab..aaad7118fca5a00a6ec781b4d800a370e5a7e5e2 100644 (file)
@@ -682,14 +682,13 @@ process_status_message (void *cls,
   if (msg == NULL)
     {      
       free_queue_entry (qe);
+      rc.cont (rc.cont_cls, 
+              GNUNET_SYSERR,
+              _("Failed to receive response from database."));
       if (NULL == h->client)
        return; /* forced disconnect */
       if (was_transmitted == GNUNET_YES)
-       {
-         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                     _("Failed to receive response from database.\n"));
-         do_disconnect (h);
-       }
+       do_disconnect (h);
       return;
     }
   GNUNET_assert (GNUNET_YES == qe->was_transmitted);
@@ -1079,7 +1078,7 @@ process_result_message (void *cls,
 
   h->in_receive = GNUNET_NO;
   if (msg == NULL)
-    {
+   {
       was_transmitted = qe->was_transmitted;
       free_queue_entry (qe);
       if (was_transmitted == GNUNET_YES)
index 34cb70906caecc99aa50018862f85ecfafd04d84..40ea153de0ab3efb64e9a79ebb5b7952c3e412c2 100644 (file)
@@ -1623,7 +1623,6 @@ run (void *cls,
   GNUNET_SCHEDULER_add_delayed (sched,
                                 GNUNET_TIME_UNIT_FOREVER_REL,
                                 &cleaning_task, NULL);
-  
 }
 
 
index 61724e9643d896c9c4f178f40eafe6494beda388..741878309cd7b9df2998d2f97626f42ec0e9fb71 100644 (file)
@@ -314,6 +314,29 @@ run_continuation (void *cls,
 }
 
 
+
+static void
+run_tests (void *cls,
+          int success,
+          const char *msg)
+{
+  struct CpsRunContext *crc = cls;
+
+  if (success != GNUNET_YES)
+    {
+      fprintf (stderr,
+              "Test 'put' operation failed with error `%s' database likely not setup, skipping test.",
+              msg);
+      GNUNET_free (crc);
+      return;
+    }
+  GNUNET_SCHEDULER_add_continuation (crc->sched,
+                                    &run_continuation,
+                                    crc,
+                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+}
+
+
 static void
 run (void *cls,
      struct GNUNET_SCHEDULER_Handle *sched,
@@ -322,6 +345,7 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct CpsRunContext *crc;
+  static GNUNET_HashCode zkey;
 
   datastore = GNUNET_DATASTORE_connect (cfg, sched);
   start_time = GNUNET_TIME_absolute_get ();
@@ -329,10 +353,19 @@ run (void *cls,
   crc->sched = sched;
   crc->cfg = cfg;
   crc->phase = RP_PUT;
-  GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                    &run_continuation,
-                                    crc,
-                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+  if (NULL ==
+      GNUNET_DATASTORE_put (datastore, 0,
+                           &zkey, 4, "TEST",
+                           GNUNET_BLOCK_TYPE_TEST,
+                           0, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS),
+                           0, 1, GNUNET_TIME_UNIT_MINUTES,
+                           &run_tests, crc))
+    {
+      fprintf (stderr,
+              "Test 'put' operation failed.\n");
+      ok = 1;
+      GNUNET_free (crc);
+    }
 }
 
 
index 660f256f9b327f7fe084116c12ace0675e951655..17cd009bcd4e304f9a37f72646b6fe61ff2420ca 100644 (file)
@@ -334,7 +334,13 @@ load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg,
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               _("Loading `%s' datastore plugin\n"), name);
   GNUNET_asprintf (&libname, "libgnunet_plugin_datastore_%s", name);
-  GNUNET_assert (NULL != (ret = GNUNET_PLUGIN_load (libname, &env)));
+  if (NULL == (ret = GNUNET_PLUGIN_load (libname, &env)))
+    {
+      fprintf (stderr,
+              "Failed to load plugin `%s'!\n",
+              name);
+      return NULL;
+    }
   GNUNET_free (libname);
   GNUNET_free (name);
   return ret;
@@ -352,15 +358,19 @@ run (void *cls,
   struct CpsRunContext *crc;
 
   api = load_plugin (c, s);
-  GNUNET_assert (api != NULL);
+  if (api == NULL)
+    {
+      fprintf (stderr, 
+              "Could not initialize plugin, assuming database not configured. Test not run!\n");
+      return;
+    }
   crc = GNUNET_malloc(sizeof(struct CpsRunContext));
   crc->api = api;
   crc->sched = s;
   crc->cfg = c;
   crc->phase = RP_PUT;
-  GNUNET_SCHEDULER_add_after (s,
-                             GNUNET_SCHEDULER_NO_TASK,
-                             &test, crc);
+  GNUNET_SCHEDULER_add_now (crc->sched,
+                           &test, crc);
 }
 
 
index a9daec189a298157b13d15b3eca82212c5ba15ee..d436ea53de9e69df73fd99c9368c1667d6ba4f5e 100644 (file)
@@ -21,6 +21,7 @@ DATABASE = mysql
 # REJECT_FROM6 =
 # PREFIX =
 
+
 [dht]
 AUTOSTART = NO
 
index 000601df34e5212d24aae0b143ef49126c22eb19..0ea3c4c86cee653ca365e26cb903ca1420fed52c 100644 (file)
@@ -582,6 +582,28 @@ run_continuation (void *cls,
 }
 
 
+static void
+run_tests (void *cls,
+          int success,
+          const char *msg)
+{
+  struct CpsRunContext *crc = cls;
+
+  if (success != GNUNET_YES)
+    {
+      fprintf (stderr,
+              "Test 'put' operation failed with error `%s' database likely not setup, skipping test.",
+              msg);
+      GNUNET_free (crc);
+      return;
+    }
+  GNUNET_SCHEDULER_add_continuation (crc->sched,
+                                    &run_continuation,
+                                    crc,
+                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+}
+
+
 static void
 run (void *cls,
      struct GNUNET_SCHEDULER_Handle *sched,
@@ -590,6 +612,7 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct CpsRunContext *crc;
+  static GNUNET_HashCode zkey;
 
   crc = GNUNET_malloc(sizeof(struct CpsRunContext));
   crc->sched = sched;
@@ -597,15 +620,22 @@ run (void *cls,
   crc->phase = RP_PUT;
   now = GNUNET_TIME_absolute_get ();
   datastore = GNUNET_DATASTORE_connect (cfg, sched);
-  GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                    &run_continuation,
-                                    crc,
-                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-
+  if (NULL ==
+      GNUNET_DATASTORE_put (datastore, 0,
+                           &zkey, 4, "TEST",
+                           GNUNET_BLOCK_TYPE_TEST,
+                           0, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS),
+                           0, 1, GNUNET_TIME_UNIT_MINUTES,
+                           &run_tests, crc))
+    {
+      fprintf (stderr,
+              "Test 'put' operation failed.\n");
+      ok = 1;
+      GNUNET_free (crc);
+    }
 }
 
 
-
 static int
 check ()
 {
index d0278094f8a32a9fbdd81604a13df04c550178ca..3de1544f3277e6cb43400d2a2c02ba08e52fa60f 100644 (file)
@@ -292,6 +292,28 @@ run_continuation (void *cls,
 }
 
 
+static void
+run_tests (void *cls,
+          int success,
+          const char *msg)
+{
+  struct CpsRunContext *crc = cls;
+
+  if (success != GNUNET_YES)
+    {
+      fprintf (stderr,
+              "Test 'put' operation failed with error `%s' database likely not setup, skipping test.",
+              msg);
+      GNUNET_free (crc);
+      return;
+    }
+  GNUNET_SCHEDULER_add_continuation (crc->sched,
+                                    &run_continuation,
+                                    crc,
+                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+}
+
+
 static void
 run (void *cls,
      struct GNUNET_SCHEDULER_Handle *sched,
@@ -300,6 +322,7 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct CpsRunContext *crc;
+  static GNUNET_HashCode zkey;
 
   crc = GNUNET_malloc(sizeof(struct CpsRunContext));
   crc->sched = sched;
@@ -307,11 +330,19 @@ run (void *cls,
   crc->phase = RP_PUT;
   now = GNUNET_TIME_absolute_get ();
   datastore = GNUNET_DATASTORE_connect (cfg, sched);
-  GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                    &run_continuation,
-                                    crc,
-                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-
+  if (NULL ==
+      GNUNET_DATASTORE_put (datastore, 0,
+                           &zkey, 4, "TEST",
+                           GNUNET_BLOCK_TYPE_TEST,
+                           0, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS),
+                           0, 1, GNUNET_TIME_UNIT_MINUTES,
+                           &run_tests, crc))
+    {
+      fprintf (stderr,
+              "Test 'put' operation failed.\n");
+      GNUNET_free (crc);
+      ok = 1;
+    }
 }
 
 
index eebbb2f68df70231e2d126f640a933e347f2e96b..0bd9848d7c8fb7e8f71a14a5b27f6389c2d95972 100644 (file)
@@ -75,7 +75,9 @@ enum GNUNET_BLOCK_Type
     /**
      * Type of a block that is used to advertise a namespace.  
      */
-    GNUNET_BLOCK_TYPE_NBLOCK = 6
+    GNUNET_BLOCK_TYPE_NBLOCK = 6,
+
+    GNUNET_BLOCK_TYPE_TEST = 9999
 
   };
 
index 3f3b2b981ccbbc748856acc7659b4599d8869e02..758a4895c04e1b46f6a107e5ed5bc7796aca871a 100644 (file)
@@ -2243,15 +2243,28 @@ typedef void
 
 
 /**
- * List all of the identifiers in the namespace for 
- * which we could produce an update.
+ * List all of the identifiers in the namespace for which we could
+ * produce an update.  Namespace updates form a graph where each node
+ * has a name.  Each node can have any number of URI/meta-data entries
+ * which can each be linked to other nodes.  Cycles are possible.
+ * 
+ * Calling this function with "next_id" NULL will cause the library to
+ * call "ip" with a root for each strongly connected component of the
+ * graph (a root being a node from which all other nodes in the Scc
+ * are reachable).
+ * 
+ * Calling this function with "next_id" being the name of a node will
+ * cause the library to call "ip" with all children of the node.  Note
+ * that cycles within an SCC are possible (including self-loops).
  *
  * @param namespace namespace to inspect for updateable content
+ * @param next_id ID to look for; use NULL to look for SCC roots
  * @param ip function to call on each updateable identifier
  * @param ip_cls closure for ip
  */
 void
 GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace,
+                                    const char *next_id,
                                     GNUNET_FS_IdentifierProcessor ip, 
                                     void *ip_cls);
 
index 059638ff1f492414c25a1ac1db9abe65dbe7aab9..3fc7d05e620b2341a1c8adbc25cf2b43999dd29b 100644 (file)
@@ -79,10 +79,16 @@ GNUNET_BIO_read_open (const char *fn)
 int
 GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
 {
-  *emsg = h->emsg;
+  int err;
+
+  err = (NULL == h->emsg) ? GNUNET_OK : GNUNET_SYSERR;
+  if (emsg != NULL)
+    *emsg = h->emsg;
+  else
+    GNUNET_free_non_null (h->emsg);
   GNUNET_DISK_file_close (h->fd);
   GNUNET_free (h);
-  return (NULL == *emsg) ? GNUNET_OK : GNUNET_SYSERR;
+  return err;
 }