X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=cleaner%2Fcleaner;h=7b50c73e7a1113317f822b963739b66ca254f2de;hb=8ff0fd08d6e1cc97cdb7e94b7cd97dc28c29e674;hp=4cda7c7f95ec70dd2742d3442625cb2a52f19954;hpb=0f7d13b7c5329e3aebe1bfa82fc859f16f2e09e5;p=bluesky.git diff --git a/cleaner/cleaner b/cleaner/cleaner index 4cda7c7..7b50c73 100755 --- a/cleaner/cleaner +++ b/cleaner/cleaner @@ -7,6 +7,30 @@ # # Copyright (C) 2010 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. import base64, os, re, struct, sys, time import boto @@ -21,6 +45,15 @@ HEADER_SIZE = struct.calcsize(HEADER_FORMAT) CHECKPOINT_MAGIC = struct.pack('>sys.stderr, "S3 operation failed, retrying..." + print >>sys.stderr, " %s %s %s" % (method, args, kwargs) self.connect() time.sleep(1.0) return method(self, *args, **kwargs) @@ -94,7 +130,12 @@ class S3Backend(Backend): self.path = path self.cachedir = cachedir self.cache = {} + for f in os.listdir(cachedir): + self.cache[f] = True + #print "Initial cache contents:", list(self.cache.keys()) self.connect() + self.stats_get = [0, 0] + self.stats_put = [0, 0] def connect(self): self.conn = boto.connect_s3(is_secure=False) @@ -125,6 +166,8 @@ class S3Backend(Backend): fp.write(data) fp.close() self.cache[filename] = True + self.stats_get[0] += 1 + self.stats_get[1] += len(data) if offset > 0: data = data[offset:] if length is not None: @@ -136,6 +179,8 @@ class S3Backend(Backend): k = Key(self.bucket) k.key = self.path + filename k.set_contents_from_string(data) + self.stats_put[0] += 1 + self.stats_put[1] += len(data) if filename in self.cache: del self.cache[filename] @@ -147,6 +192,13 @@ class S3Backend(Backend): if filename in self.cache: del self.cache[filename] + def dump_stats(self): + print "S3 statistics:" + print "GET: %d ops / %d bytes" % tuple(self.stats_get) + print "PUT: %d ops / %d bytes" % tuple(self.stats_put) + benchlog_write("s3_get: %d", self.stats_get[1]) + benchlog_write("s3_put: %d", self.stats_put[1]) + class SimpleBackend(Backend): """An interface to the simple BlueSky test network server.""" @@ -268,7 +320,7 @@ class LogDirectory: self.dir_num = dir self.seq_num = 0 for logname in backend.list(dir): - print "Old log file:", logname + #print "Old log file:", logname loc = backend.name_to_loc(logname[0]) if loc is not None and loc[0] == dir: self.seq_num = max(self.seq_num, loc[1] + 1) @@ -427,12 +479,12 @@ class InodeMap: data = data[self.vvsize:] - print "Inode map:" + #print "Inode map:" for i in range(len(data) // 16): (start, end) = struct.unpack_from("