Skip to content

Commit

Permalink
Refactred the way historical connections work to work with RelStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Fulton committed Jun 15, 2016
1 parent fad84bd commit ad25595
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/ZODB/Connection.py
Expand Up @@ -49,6 +49,8 @@
from ZODB import utils
import six

from .mvccadapter import HistoricalStorageAdapter

global_reset_counter = 0

noop = lambda : None
Expand Down Expand Up @@ -101,11 +103,10 @@ def __init__(self, db, cache_size=400, before=None, cache_size_bytes=0):
# Multi-database support
self.connections = {self._db.database_name: self}

storage = db._mvcc_storage
if before:
storage = storage.before_instance(before)
storage = HistoricalStorageAdapter(db.storage, before)
else:
storage = storage.new_instance()
storage = db._mvcc_storage.new_instance()

self._normal_storage = self._storage = storage
self.new_oid = db.new_oid
Expand Down Expand Up @@ -308,7 +309,7 @@ def isReadOnly(self):
"""Returns True if this connection is read only."""
if self.opened is None:
raise ConnectionStateError("The database connection is closed")
return self.before is not None or self._storage.isReadOnly()
return self._storage.isReadOnly()

@property
def root(self):
Expand Down
8 changes: 5 additions & 3 deletions src/ZODB/mvccadapter.py
Expand Up @@ -177,15 +177,17 @@ def invalidate_finish(tid):
def read_only_writer(self, *a, **kw):
raise POSException.ReadOnlyError

class BeforeAdapterInstance(Base):
class HistoricalStorageAdapter(Base):
"""Adapt a storage to a historical storage
"""

_copy_methods = Base._copy_methods + (
'loadSerial', 'tpc_begin', 'tpc_finish', 'tpc_abort', 'tpc_vote',
'checkCurrentSerialInTransaction',
)

def __init__(self, base, before=None):
Base.__init__(self, base._storage)
def __init__(self, storage, before=None):
Base.__init__(self, storage)
self._before = before

def isReadOnly(self):
Expand Down

0 comments on commit ad25595

Please sign in to comment.