Skip to content

Commit

Permalink
Merge pull request #140 from zopefoundation/issue-139
Browse files Browse the repository at this point in the history
Connection.new_oid delegates to its storage, not the DB.
  • Loading branch information
jimfulton committed Jan 28, 2017
2 parents 93baff5 + 177cfab commit 42532c5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -8,5 +8,6 @@ omit =
[report]
exclude_lines =
pragma: nocover
pragma: no cover
if __name__ == ['"]__main__['"]:
assert False
7 changes: 7 additions & 0 deletions CHANGES.rst
Expand Up @@ -2,6 +2,13 @@
Change History
================

5.1.2 (unreleased)
==================

- ``Connection.new_oid`` delegates to its storage, not the DB. This is
helpful for improving concurrency in MVCC storages like RelStorage.
See `issue 139 <https://github.com/zopefoundation/ZODB/issues/139`_.

5.1.1 (2016-11-18)
==================

Expand Down
4 changes: 3 additions & 1 deletion src/ZODB/Connection.py
Expand Up @@ -126,7 +126,6 @@ def before_instance(before):
storage = storage.new_instance()

self._normal_storage = self._storage = storage
self.new_oid = db.new_oid
self._savepoint_storage = None

# Do we need to join a txn manager?
Expand Down Expand Up @@ -200,6 +199,9 @@ def before_instance(before):

self._reader = ObjectReader(self, self._cache, self._db.classFactory)

def new_oid(self):
return self._storage.new_oid()

def add(self, obj):
"""Add a new object 'obj' to the database and assign it an oid."""
if self.opened is None:
Expand Down
8 changes: 7 additions & 1 deletion src/ZODB/DB.py
Expand Up @@ -987,7 +987,13 @@ def transaction(self, note=None):
return ContextManager(self, note)

def new_oid(self):
return self.storage.new_oid()
"""
Return a new oid from the storage.
Kept for backwards compatibility only. New oids should be
allocated in a transaction using an open Connection.
"""
return self.storage.new_oid() # pragma: no cover

def open_then_close_db_when_connection_closes(self):
"""Create and return a connection.
Expand Down

0 comments on commit 42532c5

Please sign in to comment.