[ZODB-Dev] Unique Object ID
Jeremy Hylton
jeremy at zope.com
Thu Jun 5 01:18:19 EDT 2003
On Wed, 4 Jun 2003 23:32:37 -0400
Casey Duncan <casey at zope.com> wrote:
> > 2) Using a counter, increase it for each object
> >
> > I believe this can create problems regarding to
> multiple connections and
> > conflict errors. Create an object in connection A,
> create another one in
> > connection B, commit A, commit B. *boom*
>
> This should work if you use a BTrees.Length.Length object
> which has automatic
> conflict resolution. Its a pretty clever and elegant
> piece of code too, give
> it a looksee. There are also tests in the BTree code that
> you can look at to
> see how to test your code for conflicts.
One disadvantage of a counter is that you tend to increase
the number of conflicts. If two different transactions
pick ids that are near enough to each other, the keys will
wind up in the same bucket. If the keys are chosen
randomly, it is less likely that concurrent transactions
will update the same bucket.
> Actually Catalog uses a combination of random and
> sequencial ids. That way if
> many objects are added at once, they tend to cluster in
> the BTree data
> structure minimizing the number of nodes and buckets that
> need to be touched.
> Have a look at the catalogObject method of Catalog.py in
> the Zope head.
That seems like a nice idea.
> Also, if use an integer rid, then you can use IOBTrees
> too, which are
> optimized for integer keys.
Good point!
Jeremy
More information about the ZODB-Dev
mailing list