Commit 27b6b5c7 authored by Barry Warsaw's avatar Barry Warsaw

Committing some old changes.

New `catdel' command which deletes the entire catalog in one
transaction.

Add a new global VERBOSE flag instead of passing around the printstat
argument everywhere.  This also lets us use getopt for proper option
parsing, and add a -v/--verbose flag for setting that global.

Added a usage() function.
parent 0376cebf
...@@ -90,6 +90,11 @@ Commands: ...@@ -90,6 +90,11 @@ Commands:
as described above. as described above.
catdel
Delete the entire catalog in one transaction. This is a fun one for
storages that do reference counting garbage collection.
pdebug command args pdebug command args
Run one of the other commands in the Python debugger. Run one of the other commands in the Python debugger.
...@@ -102,10 +107,12 @@ sample suite of tests:: ...@@ -102,10 +107,12 @@ sample suite of tests::
python Products/ZCatalog/regressiontests/loadmail.py \ python Products/ZCatalog/regressiontests/loadmail.py \
inc ~/python-dev.mbox 0 10 2 inc ~/python-dev.mbox 0 10 2
python Products/ZCatalog/regressiontests/loadmail.py edit 10 10 10 2 python Products/ZCatalog/regressiontests/loadmail.py edit 10 10 10 2
python Products/ZCatalog/regressiontests/loadmail.py catdel
""" """
import getopt
import mailbox, time, sys, os, string import mailbox, time, sys, os, string
sys.path.insert(0, '.') sys.path.insert(0, '.')
...@@ -115,6 +122,8 @@ whrandom.seed(1,2,3) ...@@ -115,6 +122,8 @@ whrandom.seed(1,2,3)
from string import strip, find, split, lower, atoi from string import strip, find, split, lower, atoi
from urllib import quote from urllib import quote
VERBOSE = 0
def do(db, f, args, returnf=None): def do(db, f, args, returnf=None):
"""Do something and measure it's impact""" """Do something and measure it's impact"""
t = c = size = mem = r = None t = c = size = mem = r = None
...@@ -159,7 +168,7 @@ def loadmessage(dest, message, i, body=None, headers=None): ...@@ -159,7 +168,7 @@ def loadmessage(dest, message, i, body=None, headers=None):
try: doc.manage_addProperty(name, v, type) try: doc.manage_addProperty(name, v, type)
except: pass except: pass
def loadmail(dest, name, mbox, printstat=0, max=-1): def loadmail(dest, name, mbox, max=-1):
try: try:
import Products.BTreeFolder.BTreeFolder import Products.BTreeFolder.BTreeFolder
...@@ -176,7 +185,7 @@ def loadmail(dest, name, mbox, printstat=0, max=-1): ...@@ -176,7 +185,7 @@ def loadmail(dest, name, mbox, printstat=0, max=-1):
while message: while message:
if max >= 0 and i > max: if max >= 0 and i > max:
break break
if i%100 == 0 and printstat: if i%100 == 0 and VERBOSE:
fmt = "\t%s\t%s\t\r" fmt = "\t%s\t%s\t\r"
if os.environ.get('TERM') in ('dumb', 'emacs'): if os.environ.get('TERM') in ('dumb', 'emacs'):
fmt = "\t%s\t%s\t\n" fmt = "\t%s\t%s\t\n"
...@@ -194,7 +203,7 @@ def loadmail(dest, name, mbox, printstat=0, max=-1): ...@@ -194,7 +203,7 @@ def loadmail(dest, name, mbox, printstat=0, max=-1):
print print
get_transaction().commit() get_transaction().commit()
def loadinc(name, mb, f, printstat=0, max=99999999, wait=1): def loadinc(name, mb, f, max=99999999, wait=1):
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from time import sleep from time import sleep
from whrandom import uniform from whrandom import uniform
...@@ -212,7 +221,7 @@ def loadinc(name, mb, f, printstat=0, max=99999999, wait=1): ...@@ -212,7 +221,7 @@ def loadinc(name, mb, f, printstat=0, max=99999999, wait=1):
jar=Zope.DB.open() jar=Zope.DB.open()
app=jar.root()['Application'] app=jar.root()['Application']
mdest=getattr(app, name) mdest=getattr(app, name)
if i%100 == 0 and printstat: if i%100 == 0 and VERBOSE:
fmt = "\t%s\t%s\t\r" fmt = "\t%s\t%s\t\r"
if os.environ.get('TERM') in ('dumb', 'emacs'): if os.environ.get('TERM') in ('dumb', 'emacs'):
fmt = "\t%s\t%s\t\n" fmt = "\t%s\t%s\t\n"
...@@ -243,7 +252,8 @@ def loadinc(name, mb, f, printstat=0, max=99999999, wait=1): ...@@ -243,7 +252,8 @@ def loadinc(name, mb, f, printstat=0, max=99999999, wait=1):
jar.close() jar.close()
if printstat: sys.stdout.write("\t%s\t%s\t\n" % (i, f.tell())) if VERBOSE:
sys.stdout.write("\t%s\t%s\t\n" % (i, f.tell()))
sys.stdout.flush() sys.stdout.flush()
return rconflicts, wconflicts return rconflicts, wconflicts
...@@ -256,7 +266,7 @@ def base(): ...@@ -256,7 +266,7 @@ def base():
max = atoi(sys.argv[3]) max = atoi(sys.argv[3])
else: else:
max = -1 max = -1
print do(Zope.DB, loadmail, (app, 'mail', sys.argv[2], 1, max)) print do(Zope.DB, loadmail, (app, 'mail', sys.argv[2], max))
Zope.DB.close() Zope.DB.close()
class RE: class RE:
...@@ -370,7 +380,7 @@ def inc(): ...@@ -370,7 +380,7 @@ def inc():
def returnf(t, c, size, mem, r, lock=lock): def returnf(t, c, size, mem, r, lock=lock):
print c, r print c, r
lock.release() lock.release()
argss.append((lock, (dest, mb, f, 1, count, wait), returnf)) argss.append((lock, (dest, mb, f, count, wait), returnf))
for lock, args, returnf in argss: for lock, args, returnf in argss:
thread.start_new_thread(do, (Zope.DB, loadinc, args, returnf)) thread.start_new_thread(do, (Zope.DB, loadinc, args, returnf))
...@@ -389,6 +399,25 @@ def inc(): ...@@ -389,6 +399,25 @@ def inc():
Zope.DB.close() Zope.DB.close()
def catdel():
import Zope
app = Zope.app()
db = Zope.DB
t = time.time()
c = time.clock()
size = db.getSize()
mem = VmSize()
del app.cat
get_transaction().commit()
t = time.time() - t
c = time.clock() - c
size = db.getSize() - size
mem = VmSize() - mem
print t, c, size, mem
words=['banishment', 'indirectly', 'imprecise', 'peeks', words=['banishment', 'indirectly', 'imprecise', 'peeks',
'opportunely', 'bribe', 'sufficiently', 'Occidentalized', 'elapsing', 'opportunely', 'bribe', 'sufficiently', 'Occidentalized', 'elapsing',
'fermenting', 'listen', 'orphanage', 'younger', 'draperies', 'Ida', 'fermenting', 'listen', 'orphanage', 'younger', 'draperies', 'Ida',
...@@ -698,9 +727,28 @@ def pdebug(): ...@@ -698,9 +727,28 @@ def pdebug():
del sys.argv[1] del sys.argv[1]
pdb.run('globals()[sys.argv[1]]()') pdb.run('globals()[sys.argv[1]]()')
def usage(code, msg=''):
print >> sys.stderr, __doc__
if msg:
print >> sys.stderr, msg
sys.exit(code)
if __name__=='__main__': if __name__=='__main__':
try: f=globals()[sys.argv[1]] try:
opts, args = getopt.getopt(sys.argv[1:], 'hv', ['help', 'verbose'])
except getopt.error, msg:
usage(1, msg)
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-v', '--verbose'):
VERBOSE = 1
try:
f=globals()[sys.argv[1]]
except: except:
print __doc__ print __doc__
sys.exit(1) sys.exit(1)
else: f() else:
f()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment