Commit fdc76cf4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 5fb60c76
...@@ -178,7 +178,7 @@ will be our future approach after we teach NEO about object deduplication. ...@@ -178,7 +178,7 @@ will be our future approach after we teach NEO about object deduplication.
from wendelin.bigfile import BigFile, WRITEOUT_STORE, WRITEOUT_MARKSTORED from wendelin.bigfile import BigFile, WRITEOUT_STORE, WRITEOUT_MARKSTORED
from wendelin import wcfs from wendelin import wcfs
from wendelin.lib.mem import bzero, memcpy from wendelin.lib.mem import bzero, memcpy
from wendelin.lib.zodb import deactivate_btree from wendelin.lib.zodb import deactivate_btree, zconn_at
from transaction.interfaces import IDataManager, ISynchronizer from transaction.interfaces import IDataManager, ISynchronizer
from persistent import Persistent, PickleCache, GHOST from persistent import Persistent, PickleCache, GHOST
...@@ -666,7 +666,7 @@ class ZBigFile(LivePersistent): ...@@ -666,7 +666,7 @@ class ZBigFile(LivePersistent):
zstor = zconn.db().storage zstor = zconn.db().storage
zurl = wcfs.zstor_2zurl(zstor) zurl = wcfs.zstor_2zurl(zstor)
wc = wcfs.join(zurl) wc = wcfs.join(zurl)
wconn = wc.connect(zconn.at()) wconn = wc.connect(zconn_at(zconn))
wcfileh = wconn.open(self._p_oid) wcfileh = wconn.open(self._p_oid)
fileh = _ZBigFileH(self, wcfileh) fileh = _ZBigFileH(self, wcfileh)
......
# Wendelin.bigfile | common ZODB-related helpers # Wendelin.bigfile | common ZODB-related helpers
# Copyright (C) 2014-2015 Nexedi SA and Contributors. # Copyright (C) 2014-2019 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -17,12 +17,17 @@ ...@@ -17,12 +17,17 @@
# #
# See COPYING file for full licensing terms. # See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
"""Package wendelin.lib.zodb provides ZODB-related utilitiy functions."""
import ZODB
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from ZODB import DB from ZODB import DB
from ZODB.utils import p64, u64
from persistent import Persistent from persistent import Persistent
import gc import gc
import pkg_resources
# open db storage by uri # open db storage by uri
def dbstoropen(uri): def dbstoropen(uri):
...@@ -105,3 +110,54 @@ def _deactivate_bucket(bucket): ...@@ -105,3 +110,54 @@ def _deactivate_bucket(bucket):
obj._p_deactivate() obj._p_deactivate()
bucket._p_deactivate() bucket._p_deactivate()
# zconn_at returns tid as of which ZODB connection is viewing the database.
def zconn_at(zconn): # -> tid
assert isinstance(zconn, ZODB.Connection.Connection)
# ZODB5 uses MVCC uniformly
if zmajor >= 5:
zstor = zconn._storage
if isinstance(zstor, ZODB.mvccadapter.MVCCAdapterInstance):
# XXX there is race in ZODB itself that leads to data corruption:
# https://github.com/zopefoundation/ZODB/issues/290
return before2at(zstor._start)
if isinstance(zstor, ZODB.mvccadapter.HistoricalStorageAdapter):
return before2at(zstor._before)
raise AssertionError("zconn_at: TODO: add support for zstor %r" % zstor)
raise AssertionError("zconn_at: TODO: add support for ZODB34")
# before2at converts tid that specifies database state as "before" into tid that
# specifies database state as "at".
def before2at(before): # -> at
return p64(u64(before) - 1)
# _zversion returns ZODB version object
def _zversion():
dzodb3 = pkg_resources.working_set.find(pkg_resources.Requirement.parse('ZODB3'))
dzodb = pkg_resources.working_set.find(pkg_resources.Requirement.parse('ZODB'))
v311 = pkg_resources.parse_version('3.11dev')
vzodb3 = dzodb3.parsed_version
if dzodb3 is not None and vzodb3 >= v311:
vzodb = dzodb.parsed_version # ZODB 3.11 just requires latest ZODB & ZEO
else:
vzodb = vzodb3
assert vzodb is not None
return vzodb
# _zmajor returns major ZODB version.
def _zmajor():
vzodb = _zversion()
# XXX hack - packaging.version.Version provides no way to extract major?
return int(vzodb.public.split('.')[0]) # 3.11.dev0 -> 3
# zmajor is set to major ZODB version.
zmajor = _zmajor()
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