[Zope-CVS] CVS: Products/ZopeVersionControl - Repository.py:1.13

Casey Duncan casey at zope.com
Wed Mar 24 16:00:01 EST 2004

Update of /cvs-repository/Products/ZopeVersionControl
In directory cvs.zope.org:/tmp/cvs-serv26112

Modified Files:
Log Message:
Use random rather than sequencial history ids. This solves two problems:

 - Computing the next history id in sequence was expensive since it used
   len(BTree). It would also cause conflicts when adding concurrently

 - Since no checking was done to see if the next chosen id was actually in use,
   it was possible to enter into a situation where *all* new object placed
   under version control got the *same* history id. This puts the version
   repository into an insane state

=== Products/ZopeVersionControl/Repository.py 1.12 => 1.13 ===
--- Products/ZopeVersionControl/Repository.py:1.12	Tue Feb 24 14:25:13 2004
+++ Products/ZopeVersionControl/Repository.py	Wed Mar 24 16:00:00 2004
@@ -14,6 +14,7 @@
 import time
+from random import randint
 from Acquisition import Implicit, aq_parent, aq_inner
 from ZopeVersionHistory import ZopeVersionHistory
@@ -52,7 +53,9 @@
         # When one creates the first version in a version history, neither
         # the version or version history yet have a _p_jar, which causes
         # copy operations to fail. To work around that, we share our _p_jar.
-        history_id = '%0.09d' % (len(self._histories) + 1)
+        history_id = None
+        while history_id is None or self._histories.has_key(history_id):
+            history_id = str(randint(1, 9999999999))
         history = ZopeVersionHistory(history_id, object)
         self._histories[history_id] = history
         return history.__of__(self)

More information about the Zope-CVS mailing list