Commit e5fb6e7c authored by Kirill Smelkov's avatar Kirill Smelkov

zodbcommit: Prepare to compute current serial of an oid lazily

This current serial will not be needed on new codepaths to be added to
zodbcommit in the next patch.

-> Move the computation to function to trigger it only from places where
knowing current serial is actually needed.
parent 1844c7db
...@@ -55,11 +55,11 @@ from golang import func, defer, panic ...@@ -55,11 +55,11 @@ from golang import func, defer, panic
def zodbcommit(stor, at, txn): def zodbcommit(stor, at, txn):
assert isinstance(txn, zodbdump.Transaction) assert isinstance(txn, zodbdump.Transaction)
before = p64(u64(at)+1)
stor.tpc_begin(txn) stor.tpc_begin(txn)
def _(): def _():
def current_serial(oid):
return _serial_at(stor, oid, at)
for obj in txn.objv: for obj in txn.objv:
data = None # data do be committed - setup vvv data = None # data do be committed - setup vvv
if isinstance(obj, zodbdump.ObjectCopy): if isinstance(obj, zodbdump.ObjectCopy):
...@@ -82,25 +82,12 @@ def zodbcommit(stor, at, txn): ...@@ -82,25 +82,12 @@ def zodbcommit(stor, at, txn):
else: else:
panic('invalid object record: %r' % (obj,)) panic('invalid object record: %r' % (obj,))
# we have the data -> store the object.
# now we have the data.
# find out what is oid's serial as of <before state
try:
xdata = stor.loadBefore(obj.oid, before)
except POSKeyError:
serial_prev = z64
else:
if xdata is None:
serial_prev = z64
else:
_, serial_prev, _ = xdata
# store the object.
# if it will be ConflictError - we just fail and let the caller retry. # if it will be ConflictError - we just fail and let the caller retry.
if data is None: if data is None:
stor.deleteObject(obj.oid, serial_prev, txn) stor.deleteObject(obj.oid, current_serial(obj.oid), txn)
else: else:
stor.store(obj.oid, serial_prev, data, '', txn) stor.store(obj.oid, current_serial(obj.oid), data, '', txn)
try: try:
_() _()
...@@ -118,6 +105,20 @@ def zodbcommit(stor, at, txn): ...@@ -118,6 +105,20 @@ def zodbcommit(stor, at, txn):
tid = _[0] tid = _[0]
return tid return tid
# _serial_at returns oid's serial as of @at database state.
def _serial_at(stor, oid, at):
before = p64(u64(at)+1)
try:
xdata = stor.loadBefore(oid, before)
except POSKeyError:
serial = z64
else:
if xdata is None:
serial = z64
else:
_, serial, _ = xdata
return serial
# ---------------------------------------- # ----------------------------------------
import sys, getopt import sys, getopt
......
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