From 461f9464579f244230b585a9d8df298e1a234ae8 Mon Sep 17 00:00:00 2001
From: david-sarah <david-sarah@jacaranda.org>
Date: Sun, 18 Jul 2010 21:46:55 -0700
Subject: [PATCH] upload.py: fix #1118 by aborting newly-homeless buckets when
 reassignment runs. This makes a previously failing assert correct. This
 version refactors 'abort' into two methods, rather than using a default
 argument.

---
 src/allmydata/immutable/upload.py | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/allmydata/immutable/upload.py b/src/allmydata/immutable/upload.py
index 60e1078f..dc468004 100644
--- a/src/allmydata/immutable/upload.py
+++ b/src/allmydata/immutable/upload.py
@@ -137,11 +137,19 @@ class PeerTracker:
 
     def abort(self):
         """
-        I abort the remote bucket writers for the share numbers in
-        sharenums. This is a good idea to conserve space on the storage
-        server.
+        I abort the remote bucket writers for all shares. This is a good idea
+        to conserve space on the storage server.
         """
-        for writer in self.buckets.itervalues(): writer.abort()
+        self.abort_some_buckets(self.buckets.keys())
+
+    def abort_some_buckets(self, sharenums):
+        """
+        I abort the remote bucket writers for the share numbers in sharenums.
+        """
+        for sharenum in sharenums:
+            if sharenum in self.buckets:
+                self.buckets[sharenum].abort()
+                del self.buckets[sharenum]
 
 
 class Tahoe2PeerSelector:
@@ -356,6 +364,8 @@ class Tahoe2PeerSelector:
                             if not self.preexisting_shares[share]:
                                 del self.preexisting_shares[share]
                             items.append((server, sharelist))
+                        for writer in self.use_peers:
+                            writer.abort_some_buckets(self.homeless_shares)
                     return self._loop()
                 else:
                     # Redistribution won't help us; fail.
@@ -364,6 +374,8 @@ class Tahoe2PeerSelector:
                                           self.needed_shares,
                                           self.servers_of_happiness,
                                           effective_happiness)
+                    log.msg("server selection unsuccessful for %r: %s (%s), merged=%r"
+                            % (self, msg, self._get_progress_message(), merged), level=log.INFREQUENT)
                     return self._failed("%s (%s)" % (msg, self._get_progress_message()))
 
         if self.uncontacted_peers:
-- 
2.45.2