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

.

parent e9a36412
......@@ -20,21 +20,44 @@
"""Zodbpack - Pack a ZODB database"""
from __future__ import print_function
from zodbtools.util import storageFromURL
from zodbtools.util import storageFromURL, parse_tid, ashex
import ZODB.serialize
from ZODB.utils import u64
from persistent.TimeStamp import TimeStamp
import sys
import time
from golang import func, defer
import sys, time
from golang import func, defer, panic
# XXX try to avoid
import numpy as np
# XXX
# XXX +packtime
def zodbpack(stor, gc):
t = time.time()
def zodbpack(stor, packat, gc):
kw = {}
if gc is not None:
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)
......@@ -45,7 +68,7 @@ summary = "pack a ZODB database"
def usage(out):
print("""\
Usage: zodb pack [OPTIONS] <storage>
Usage: zodb pack [OPTIONS] <storage> <packat>
Pack a ZODB database.
<storage> is an URL (see 'zodb help zurl') of a ZODB-storage.
......@@ -63,7 +86,7 @@ def main(argv):
gc = False
try:
optv, argv = getopt.getopt(argv[1:], "h", ["help"])
optv, argv = getopt.getopt(argv[1:], "h", ["gc", "help"])
except getopt.GetoptError as e:
print(e, file=sys.stderr)
usage(sys.stderr)
......@@ -76,13 +99,15 @@ def main(argv):
if opt in ("--gc"):
gc = True
try:
storurl = argv[0]
except IndexError:
if len(argv) != 2:
usage(sys.stderr)
sys.exit(2)
storurl = argv[0]
packat = parse_tid(argv[1])
print(`packat`)
stor = storageFromURL(storurl)
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