fix unindex persistence
authorChristian Grothoff <christian@grothoff.org>
Thu, 6 May 2010 20:28:21 +0000 (20:28 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 6 May 2010 20:28:21 +0000 (20:28 +0000)
TODO
src/fs/Makefile.am
src/fs/fs.c
src/fs/fs.h
src/fs/fs_unindex.c
src/fs/test_fs_unindex_persistence.c

diff --git a/TODO b/TODO
index 0eb7fc6b2b70e1fb8b62cd9a612b5fcb0d02d439..bf30d665a86108ea09e28352f9602f3281d3f91a 100644 (file)
--- 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
   - [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]
index 2881ab4fa1afbae3685f6fb4931c694bf859da09..9c9fd7525f55a414ae9bbc7a772d876555713c39 100644 (file)
@@ -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
index 1968a8453d928089dd19cfd0231a396cf3867c87..1226db707c93bfb819c310e7836f69786b70c01f 100644 (file)
@@ -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;
index bca8fc6916ad4db9f76170aa848d58c90f7cba26..c0e2033358a730b7dcad5786de55e94e2ece29d7 100644 (file)
@@ -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
   };
 
 
index db054060779851ac411a97eb8ef5199153d46ce0..349cc42515293840b741ded2fb08ac71aeb8997e 100644 (file)
@@ -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);
index c964004c1d54e22af62ea1697979c49bb2d87588..2185be21d02952d18b543502a343c38eddac0c79 100644 (file)
@@ -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,