From b9de10a83f130b2c0a4513a1f713d778fbb4ecc1 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 7 Aug 2010 16:55:16 +0000 Subject: [PATCH] do not fail if datastore unavailable --- contrib/defaults.conf | 1 + src/datastore/datastore_api.c | 11 +++-- src/datastore/gnunet-service-datastore.c | 1 - src/datastore/perf_datastore_api.c | 41 ++++++++++++++++-- src/datastore/perf_plugin_datastore.c | 20 ++++++--- .../perf_plugin_datastore_data_mysql.conf | 1 + src/datastore/test_datastore_api.c | 42 ++++++++++++++++--- src/datastore/test_datastore_api_management.c | 41 +++++++++++++++--- src/include/gnunet_block_lib.h | 4 +- src/include/gnunet_fs_service.h | 17 +++++++- src/util/bio.c | 10 ++++- 11 files changed, 157 insertions(+), 32 deletions(-) diff --git a/contrib/defaults.conf b/contrib/defaults.conf index 016870466..74efa2260 100644 --- a/contrib/defaults.conf +++ b/contrib/defaults.conf @@ -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 diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index dcafeb839..aaad7118f 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c @@ -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) diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 34cb70906..40ea153de 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c @@ -1623,7 +1623,6 @@ run (void *cls, GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, NULL); - } diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 61724e964..741878309 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c @@ -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); + } } diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c index 660f256f9..17cd009bc 100644 --- a/src/datastore/perf_plugin_datastore.c +++ b/src/datastore/perf_plugin_datastore.c @@ -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); } diff --git a/src/datastore/perf_plugin_datastore_data_mysql.conf b/src/datastore/perf_plugin_datastore_data_mysql.conf index a9daec189..d436ea53d 100644 --- a/src/datastore/perf_plugin_datastore_data_mysql.conf +++ b/src/datastore/perf_plugin_datastore_data_mysql.conf @@ -21,6 +21,7 @@ DATABASE = mysql # REJECT_FROM6 = # PREFIX = + [dht] AUTOSTART = NO diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index 000601df3..0ea3c4c86 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c @@ -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 () { diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c index d0278094f..3de1544f3 100644 --- a/src/datastore/test_datastore_api_management.c +++ b/src/datastore/test_datastore_api_management.c @@ -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; + } } diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h index eebbb2f68..0bd9848d7 100644 --- a/src/include/gnunet_block_lib.h +++ b/src/include/gnunet_block_lib.h @@ -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 }; diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index 3f3b2b981..758a4895c 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h @@ -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); diff --git a/src/util/bio.c b/src/util/bio.c index 059638ff1..3fc7d05e6 100644 --- a/src/util/bio.c +++ b/src/util/bio.c @@ -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; } -- 2.25.1