Commit 735ab157 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e9a36412
...@@ -20,21 +20,44 @@ ...@@ -20,21 +20,44 @@
"""Zodbpack - Pack a ZODB database""" """Zodbpack - Pack a ZODB database"""
from __future__ import print_function from __future__ import print_function
from zodbtools.util import storageFromURL from zodbtools.util import storageFromURL, parse_tid, ashex
import ZODB.serialize import ZODB.serialize
from ZODB.utils import u64
from persistent.TimeStamp import TimeStamp
import sys import sys, time
import time from golang import func, defer, panic
from golang import func, defer
# XXX try to avoid
import numpy as np
# XXX # XXX
# XXX +packtime def zodbpack(stor, packat, gc):
def zodbpack(stor, gc):
t = time.time()
kw = {} kw = {}
if gc is not None: if gc is not None:
kw['gc'] = gc kw['gc'] = gc
# packat(tid) -> t(float) (IStorage.pack requres float packtime)
# the conversion is not exact due to potential rounding.
# we are ok to go a bit before, but not after - so that if packat specifies
# transaction exactly, this transaction is not pruned and stays in [packat range.
t = TimeStamp(packat).timeTime()
while 1:
packat_ = TimeStamp(*time.gmtime(t)[:5]+(t%60,)).raw()
d = u64(packat_) - u64(packat)
if abs(d) > 1E2:
panic("too much divergence due to rounding:"
"\npackat: %s\npackat_: %s\nδ: %d" % (ashex(packat), ashex(packat_), d))
print("\npackat: %s\npackat_: %s\nδ: %d" % (ashex(packat), ashex(packat_), d))
if d <= 0:
break
t = np.nextafter(t, -np.inf)
stor.pack(t, ZODB.serialize.referencesf, **kw) stor.pack(t, ZODB.serialize.referencesf, **kw)
...@@ -45,7 +68,7 @@ summary = "pack a ZODB database" ...@@ -45,7 +68,7 @@ summary = "pack a ZODB database"
def usage(out): def usage(out):
print("""\ print("""\
Usage: zodb pack [OPTIONS] <storage> Usage: zodb pack [OPTIONS] <storage> <packat>
Pack a ZODB database. Pack a ZODB database.
<storage> is an URL (see 'zodb help zurl') of a ZODB-storage. <storage> is an URL (see 'zodb help zurl') of a ZODB-storage.
...@@ -63,7 +86,7 @@ def main(argv): ...@@ -63,7 +86,7 @@ def main(argv):
gc = False gc = False
try: try:
optv, argv = getopt.getopt(argv[1:], "h", ["help"]) optv, argv = getopt.getopt(argv[1:], "h", ["gc", "help"])
except getopt.GetoptError as e: except getopt.GetoptError as e:
print(e, file=sys.stderr) print(e, file=sys.stderr)
usage(sys.stderr) usage(sys.stderr)
...@@ -76,13 +99,15 @@ def main(argv): ...@@ -76,13 +99,15 @@ def main(argv):
if opt in ("--gc"): if opt in ("--gc"):
gc = True gc = True
try: if len(argv) != 2:
storurl = argv[0]
except IndexError:
usage(sys.stderr) usage(sys.stderr)
sys.exit(2) sys.exit(2)
storurl = argv[0]
packat = parse_tid(argv[1])
print(`packat`)
stor = storageFromURL(storurl) stor = storageFromURL(storurl)
defer(stor.close) defer(stor.close)
zodbpack(stor, gc) zodbpack(stor, packat, gc)
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