Commit 9dbe70f3 authored by Kirill Smelkov's avatar Kirill Smelkov

*: Don't forget to close opened ZODB storage

Storages need to be closed to indicate a clean access end. If a storage is
not closed cleanly it might require to spend time and resources on next
open. For example FileStorage might need to recompute the index.

/reviewed-on nexedi/zodbtools!6
parent 220d1121
......@@ -12,6 +12,7 @@ import shutil
from ZODB.FileStorage import FileIterator, FileStorage, packed_version
from ZODB.FileStorage.format import FileStorageFormatter
from ZODB.utils import get_pickle_metadata
from golang import func, defer
class DeltaFileStorage(
FileStorageFormatter,
......@@ -22,6 +23,9 @@ class DeltaFileStorage(
def iterator(self, start=None, stop=None):
return DeltaFileIterator(self._file_name, start, stop)
def close(self):
pass
class DeltaFileIterator(FileIterator):
def __init__(self, filename, start=None, stop=None, pos=0L):
assert isinstance(filename, str)
......@@ -157,11 +161,13 @@ def report(rep, csv=False):
rep.FBYTES * 100.0 / rep.DBYTES,
rep.FBYTES * 1.0 / rep.FOIDS)
@func
def analyze(path, use_dbm, delta_fs):
if delta_fs:
fs = DeltaFileStorage(path, read_only=1)
else:
fs = FileStorage(path, read_only=1)
defer(fs.close)
fsi = fs.iterator()
report = Report(use_dbm, delta_fs)
for txn in fsi:
......
......@@ -34,6 +34,7 @@ from __future__ import print_function
from zodbtools.util import ashex, inf, nextitem, txnobjv, parse_tidrange, TidRangeInvalid, \
storageFromURL
from time import time
from golang import func, defer
# compare two storage transactions
# 0 - equal, 1 - non-equal
......@@ -127,6 +128,7 @@ Options:
-h --help show this help
""", file=out)
@func
def main2(argv):
verbose = False
......@@ -159,8 +161,8 @@ def main2(argv):
print("E: invalid tidrange: %s" % e, file=sys.stderr)
sys.exit(2)
stor1 = storageFromURL(storurl1, read_only=True)
stor2 = storageFromURL(storurl2, read_only=True)
stor1 = storageFromURL(storurl1, read_only=True); defer(stor1.close)
stor2 = storageFromURL(storurl2, read_only=True); defer(stor2.close)
zcmp = storcmp(stor1, stor2, tidmin, tidmax, verbose)
sys.exit(1 if zcmp else 0)
......
......@@ -44,7 +44,7 @@ from zodbtools.util import ashex, storageFromURL
from ZODB.utils import p64, u64, z64
from ZODB.POSException import POSKeyError
from ZODB._compat import BytesIO
from golang import panic
from golang import func, defer, panic
# zodbcommit commits new transaction into ZODB storage with data specified by
......@@ -135,6 +135,7 @@ Options:
-h --help show this help
""", file=out)
@func
def main(argv):
try:
optv, argv = getopt.getopt(argv[1:], "h", ["help"])
......@@ -156,6 +157,7 @@ def main(argv):
at = argv[1].decode('hex')
stor = storageFromURL(storurl)
defer(stor.close)
zin = 'txn 0000000000000000 " "\n' # artificial transaction header
zin += sys.stdin.read()
......
......@@ -65,7 +65,7 @@ import sys
import logging
import re
from golang.gcompat import qq
from golang import strconv
from golang import func, defer, strconv
# txn_raw_extension returns raw extension from txn metadata
def txn_raw_extension(stor, txn):
......@@ -240,6 +240,7 @@ Options:
-h --help show this help
""", file=out)
@func
def main(argv):
hashonly = False
......@@ -273,6 +274,7 @@ def main(argv):
sys.exit(2)
stor = storageFromURL(storurl, read_only=True)
defer(stor.close)
zodbdump(stor, tidmin, tidmax, hashonly)
......
......@@ -22,6 +22,7 @@
from __future__ import print_function
from zodbtools.util import ashex, storageFromURL
from collections import OrderedDict
from golang import func, defer
import sys
# {} parameter_name -> get_parameter(stor)
......@@ -71,6 +72,7 @@ Options:
-h --help show this help
""", file=out)
@func
def main(argv):
try:
optv, argv = getopt.getopt(argv[1:], "h", ["help"])
......@@ -91,5 +93,6 @@ def main(argv):
sys.exit(2)
stor = storageFromURL(storurl, read_only=True)
defer(stor.close)
zodbinfo(stor, argv[1:])
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