From c87458e229281a050ecca11a0b99fa55c07ad29c Mon Sep 17 00:00:00 2001
From: Darrell Bishop <darrell@swiftstack.com>
Date: Fri, 3 Aug 2012 19:27:07 -0700
Subject: [PATCH] Fix container delete throughput and 409 retries.

Fix race condition in _delete_container() where all elements of
object_queue have been removed, but the last one (per thread) may not
have actually been deleted yet when the container deletion thread calls
conn.delete_container(container).  Fixes bug 1032879.

Improves container deletion throughput by immediately deleting
containers with no objects instead of waiting for all pending object
deletes to complete.  Fixes bug 1032878.

Change-Id: I404229a4c608995294e0ada77724ac8afe8d6f3c
---
 bin/swift | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/bin/swift b/bin/swift
index 7cfbf161..11f9553a 100755
--- a/bin/swift
+++ b/bin/swift
@@ -215,16 +215,20 @@ def st_delete(parser, args, print_queue, error_queue):
     def _delete_container(container, conn):
         try:
             marker = ''
+            had_objects = False
             while True:
                 objects = [o['name'] for o in
                            conn.get_container(container, marker=marker)[1]]
                 if not objects:
                     break
+                had_objects = True
                 for obj in objects:
                     object_queue.put((container, obj))
                 marker = objects[-1]
-            while not object_queue.empty():
-                sleep(0.01)
+            if had_objects:
+                # By using join() instead of empty() we should avoid most
+                # occurrences of 409 below.
+                object_queue.join()
             attempts = 1
             while True:
                 try: