X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=cleaner%2Fazure.py;h=57c4d058214476d19b769b436b3ff9aa47114292;hb=HEAD;hp=89b4f23fbc52c8ce4521cb75f2878370386354b1;hpb=ad358c4ee8d8a34ec17caed417301e773de7a098;p=bluesky.git diff --git a/cleaner/azure.py b/cleaner/azure.py index 89b4f23..57c4d05 100644 --- a/cleaner/azure.py +++ b/cleaner/azure.py @@ -1,3 +1,32 @@ +# Blue Sky: File Systems in the Cloud +# +# Copyright (C) 2011 The Regents of the University of California +# Written by Michael Vrable +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the University nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + """A simple Python library for accessing the Windows Azure blob service.""" import base64, hashlib, hmac, httplib, os, time, urllib @@ -148,6 +177,34 @@ class AzureConnection: path = "/%s/%s" % (container, key) r = self._make_request(path, method='DELETE') +def parallel_delete(container, keys): + import Queue + from threading import Lock, Thread + + keys = list(iter(keys)) + + q = Queue.Queue(16384) + l = Lock() + + def deletion_task(): + conn = AzureConnection() + while True: + k = q.get() + l.acquire() + print k + l.release() + conn.delete(container, k) + q.task_done() + + for i in range(128): + t = Thread(target=deletion_task) + t.setDaemon(True) + t.start() + + for k in keys: + q.put(k) + q.join() + if __name__ == '__main__': container = 'bluesky' conn = AzureConnection() @@ -155,6 +212,4 @@ if __name__ == '__main__': conn.put(container, "testkey", "A" * 40) print "Fetch result:", conn.get(container, "testkey") - for k in list(iter(conn.list(container))): - print "Deleting", k - conn.delete(container, k) + parallel_delete(container, conn.list(container))