Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide loadBeforeEx #485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/relstorage/storage/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,30 @@ def loadSerial(self, oid, serial):

raise self.__pke(oid, tid_int=tid_int, state=state)

@stale_aware
@storage_method
@metricmethod_sampled
def loadBeforeEx(self, oid, tid): # -> (state, serial)
"""
Return most recent revision of oid before tid committed.
(see IStorageLoadBeforeEx)
"""
oid_int = bytes8_to_int64(oid)
cursor = self.load_connection.cursor
state, serial_tid = self._loadBeforeEx(cursor, oid_int, tid)
serial = int64_to_8bytes(serial_tid)
return state, serial

def _loadBeforeEx(self, cursor, oid_int, tid): # -> (state, serial_tid)
# serves loadBeforeEx and loadBefore
state, start_tid = self.adapter.mover.load_before(
cursor, oid_int, bytes8_to_int64(tid))

if start_tid is None:
assert state is None
start_tid = 0

return state, start_tid

@stale_aware
@storage_method
Expand All @@ -225,6 +249,8 @@ def loadBefore(self, oid, tid):

# TODO: This makes three separate queries, and also bypasses the cache.
# We should be able to fix at least the multiple queries.
# ( this is "fixed" on recent ZODB which calls loadBeforeEx instead of
# loadBefore after https://github.com/zopefoundation/ZODB/pull/323 )

# In the past, we would use the store connection (only if it was already open)
# to "allow leading dato from later transactions for conflict resolution".
Expand All @@ -242,10 +268,8 @@ def loadBefore(self, oid, tid):
if not self.adapter.mover.exists(cursor, oid_int):
raise self.__pke(oid, exists=False)

state, start_tid = self.adapter.mover.load_before(
cursor, oid_int, bytes8_to_int64(tid))

if start_tid is None:
state, start_tid = self._loadBeforeEx(cursor, oid_int, tid)
if start_tid == 0:
return None

if state is None:
Expand Down
1 change: 1 addition & 0 deletions src/relstorage/tests/reltestbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def func(*args, **kwargs):
return func

for name in (
'loadBeforeEx',
'loadBefore',
'load',
'store',
Expand Down