From 1e94a424f360666f438064901fa9a800aa6e383e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 6 May 2010 20:28:21 +0000 Subject: [PATCH] fix unindex persistence --- TODO | 21 ++++------ src/fs/Makefile.am | 1 + src/fs/fs.c | 5 --- src/fs/fs.h | 7 +--- src/fs/fs_unindex.c | 62 +++++++++++++++++++++++----- src/fs/test_fs_unindex_persistence.c | 21 +++++++++- 6 files changed, 81 insertions(+), 36 deletions(-) diff --git a/TODO b/TODO index 0eb7fc6b2..bf30d665a 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,14 @@ 0.9.0pre1: +* MIGRATION [CG] + - on-demand encoding => move logic to block-library!? + - peer selection => how to consider latency/bw/etc? + - content transmission => how often the same block? + - how to select delay before next migration? + - migration to us + - testing + - integrate with FS or not? (peer list, index/on-demand encoding, block code, + inbound priority assignment; all would be easier with tight integration!) * FS: [CG] - - persistence testing (unindex, search): - * unindex: - + need to clean up state on stop/suspend (including file-hashing => util API change!) - gnunet-service-fs (hot-path routing, load-based routing, nitpicks) - [gnunet-service-fs.c:208]: member 'LocalGetContext::results_bf_size' is never used - [gnunet-service-fs.c:501]: member 'PendingRequest::used_pids_size' is never used @@ -14,15 +20,6 @@ - [gnunet-service-fs.c:700]: member 'ConnectedPeer::last_client_replies_woff' is never used - GAP improvements: + active reply route caching design & implementation of service; gap extension! -* MIGRATION [CG] - - on-demand encoding => move logic to block-library!? - - peer selection => how to consider latency/bw/etc? - - content transmission => how often the same block? - - how to select delay before next migration? - - migration to us - - testing - - integrate with FS or not? (peer list, index/on-demand encoding, block code, - inbound priority assignment; all would be easier with tight integration!) * TBENCH: [MW] - good to have for transport/DV evaluation! * DV: [Nate] diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index 2881ab4fa..9c9fd7525 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am @@ -157,6 +157,7 @@ TESTS = $(check_SCRIPTS) \ test_fs_search_persistence \ test_fs_start_stop \ test_fs_unindex \ + test_fs_unindex_persistence \ test_fs_uri \ test_fs_test_lib \ test_gnunet_service_fs_p2p diff --git a/src/fs/fs.c b/src/fs/fs.c index 1968a8453..1226db707 100644 --- a/src/fs/fs.c +++ b/src/fs/fs.c @@ -1571,8 +1571,6 @@ GNUNET_FS_unindex_sync_ (struct GNUNET_FS_UnindexContext *uc) { struct GNUNET_BIO_WriteHandle *wh; - if (UNINDEX_STATE_ABORTED == uc->state) - return; if (NULL == uc->serialization) uc->serialization = make_serialization_file_name (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX); @@ -2038,9 +2036,6 @@ deserialize_unindex_file (void *cls, goto cleanup; } break; - case UNINDEX_STATE_ABORTED: - GNUNET_break (0); - goto cleanup; default: GNUNET_break (0); goto cleanup; diff --git a/src/fs/fs.h b/src/fs/fs.h index bca8fc691..c0e203335 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h @@ -1339,13 +1339,8 @@ enum UnindexState /** * We've encountered a fatal error. */ - UNINDEX_STATE_ERROR = 4, + UNINDEX_STATE_ERROR = 4 - /** - * We've been aborted. The next callback should clean up the - * struct. - */ - UNINDEX_STATE_ABORTED = 5 }; diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index db0540607..349cc4251 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c @@ -243,6 +243,7 @@ unindex_finish (void *cls, GNUNET_FS_tree_encoder_finish (uc->tc, &uri, &emsg); + uc->tc = NULL; if (uri != NULL) GNUNET_FS_uri_destroy (uri); GNUNET_DISK_file_close (uc->fh); @@ -251,11 +252,13 @@ unindex_finish (void *cls, uc->dsh = NULL; if (emsg != NULL) { + uc->state = UNINDEX_STATE_ERROR; uc->emsg = emsg; signal_unindex_error (uc); } - else + else { + uc->state = UNINDEX_STATE_COMPLETE; pi.status = GNUNET_FS_STATUS_UNINDEX_COMPLETED; pi.value.unindex.eta = GNUNET_TIME_UNIT_ZERO; GNUNET_FS_unindex_make_status_ (&pi, uc, uc->file_size); @@ -284,7 +287,10 @@ process_fs_response (void *cls, } if (uc->state != UNINDEX_STATE_FS_NOTIFY) { - GNUNET_FS_unindex_stop (uc); + uc->state = UNINDEX_STATE_ERROR; + uc->emsg = GNUNET_strdup (_("Unexpected time for a response from `fs' service.")); + GNUNET_FS_unindex_sync_ (uc); + signal_unindex_error (uc); return; } if (NULL == msg) @@ -416,6 +422,28 @@ GNUNET_FS_unindex_signal_suspend_ (void *cls) GNUNET_CRYPTO_hash_file_cancel (uc->fhc); uc->fhc = NULL; } + if (uc->client != NULL) + { + GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO); + uc->client = NULL; + } + if (NULL != uc->dsh) + { + GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); + uc->dsh = NULL; + } + if (NULL != uc->tc) + { + GNUNET_FS_tree_encoder_finish (uc->tc, + NULL, + NULL); + uc->tc = NULL; + } + if (uc->fh != NULL) + { + GNUNET_DISK_file_close (uc->fh); + uc->fh = NULL; + } GNUNET_FS_end_top (uc->h, uc->top); pi.status = GNUNET_FS_STATUS_UNINDEX_SUSPEND; GNUNET_FS_unindex_make_status_ (&pi, uc, @@ -488,17 +516,29 @@ GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc) GNUNET_CRYPTO_hash_file_cancel (uc->fhc); uc->fhc = NULL; } - /* FIXME: disconnect uc->client (if still connected) */ - /* FIXME: disconnect from datastore (if still connected) */ - /* FIXME: other termination operations? */ - /* FIXME: must do same cleanup in 'unindex_signal_suspend'! */ - GNUNET_FS_end_top (uc->h, uc->top); - if ( (uc->state != UNINDEX_STATE_COMPLETE) && - (uc->state != UNINDEX_STATE_ERROR) ) + if (uc->client != NULL) { - uc->state = UNINDEX_STATE_ABORTED; - return; + GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO); + uc->client = NULL; + } + if (NULL != uc->dsh) + { + GNUNET_DATASTORE_disconnect (uc->dsh, GNUNET_NO); + uc->dsh = NULL; + } + if (NULL != uc->tc) + { + GNUNET_FS_tree_encoder_finish (uc->tc, + NULL, + NULL); + uc->tc = NULL; + } + if (uc->fh != NULL) + { + GNUNET_DISK_file_close (uc->fh); + uc->fh = NULL; } + GNUNET_FS_end_top (uc->h, uc->top); if (uc->serialization != NULL) { GNUNET_FS_remove_sync_file_ (uc->h, GNUNET_FS_SYNC_PATH_MASTER_UNINDEX, uc->serialization); diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c index c964004c1..2185be21d 100644 --- a/src/fs/test_fs_unindex_persistence.c +++ b/src/fs/test_fs_unindex_persistence.c @@ -161,7 +161,6 @@ progress_cb (void *cls, GNUNET_assert (unindex != NULL); break; case GNUNET_FS_STATUS_UNINDEX_COMPLETED: - consider_restart (event->status); printf ("Unindex complete, %llu kbps.\n", (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024)); GNUNET_SCHEDULER_add_continuation (sched, @@ -180,6 +179,25 @@ progress_cb (void *cls, (unsigned long long) event->value.unindex.specifics.progress.offset); #endif break; + case GNUNET_FS_STATUS_PUBLISH_SUSPEND: + if (event->value.publish.sc == publish) + publish = NULL; + break; + case GNUNET_FS_STATUS_PUBLISH_RESUME: + if (NULL == publish) + { + publish = event->value.publish.sc; + return "publish-context"; + } + break; + case GNUNET_FS_STATUS_UNINDEX_SUSPEND: + GNUNET_assert (event->value.unindex.uc == unindex); + unindex = NULL; + break; + case GNUNET_FS_STATUS_UNINDEX_RESUME: + GNUNET_assert (NULL == unindex); + unindex = event->value.unindex.uc; + return "unindex"; case GNUNET_FS_STATUS_PUBLISH_ERROR: fprintf (stderr, "Error publishing file: %s\n", @@ -222,7 +240,6 @@ progress_cb (void *cls, GNUNET_assert (0 == event->value.unindex.completed); break; case GNUNET_FS_STATUS_UNINDEX_STOPPED: - consider_restart (event->status); GNUNET_assert (unindex == event->value.unindex.uc); GNUNET_SCHEDULER_add_continuation (sched, &abort_publish_task, -- 2.25.1