[Checkins] SVN: zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/ Make more than one transaction, close storage at the end.
Sylvain Viollon
sylvain at infrae.com
Thu Nov 5 09:00:02 EST 2009
Log message for revision 105496:
Make more than one transaction, close storage at the end.
Changed:
U zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/main.py
U zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/update.py
-=-
Modified: zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/main.py
===================================================================
--- zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/main.py 2009-11-05 13:00:55 UTC (rev 105495)
+++ zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/main.py 2009-11-05 14:00:01 UTC (rev 105496)
@@ -91,4 +91,5 @@
logging.debug('An error occured', exc_info=True)
logging.error('Stopped processing, due to: %s' % e)
raise SystemExit()
+ storage.close()
Modified: zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/update.py
===================================================================
--- zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/update.py 2009-11-05 13:00:55 UTC (rev 105495)
+++ zodbupdate/branches/sylvain-persistent-load/src/zodbupdate/update.py 2009-11-05 14:00:01 UTC (rev 105496)
@@ -25,7 +25,9 @@
logger = logging.getLogger('zodbupdate')
+TRANSACTION_COUNT = 100000
+
class Updater(object):
"""Update class references for all current objects in a storage."""
@@ -34,26 +36,41 @@
self.storage = storage
self.update = zodbupdate.serialize.ObjectRenamer(renames or {})
- def __call__(self):
+ def _new_transaction(self):
t = transaction.Transaction()
self.storage.tpc_begin(t)
t.note('Updated factory references using `zodbupdate`.')
+ return t
+ def _commit_transaction(self, t, changed):
+ if self.dry or not changed:
+ logger.info('Dry run selected or no changes, aborting transaction.')
+ self.storage.tpc_abort(t)
+ else:
+ logger.info('Committing changes.')
+ self.storage.tpc_vote(t)
+ self.storage.tpc_finish(t)
+
+ def __call__(self):
+ count = 0
+ t = self._new_transaction()
+
for oid, serial, current in self.records:
new = self.update.rename(current)
if new is None:
continue
logger.debug('Updated %s' % ZODB.utils.oid_repr(oid))
self.storage.store(oid, serial, new.getvalue(), '', t)
+ count += 1
- if self.dry:
- logger.info('Dry run selected, aborting transaction.')
- self.storage.tpc_abort(t)
- else:
- logger.info('Committing changes.')
- self.storage.tpc_vote(t)
- self.storage.tpc_finish(t)
+ if count > TRANSACTION_COUNT:
+ count = 0
+ self._commit_transaction(t, True)
+ t = self._new_transaction()
+ self._commit_transaction(t, count != 0)
+
+
@property
def records(self):
next = None
More information about the checkins
mailing list