[ZODB-Dev] _p_resolveConflicts

Jim Fulton jim@zope.com
Thu, 02 Aug 2001 18:25:35 -0400


"John D. Heintz" wrote:
> 
> That's what _p_independent does!
> 
> How does this prevent two threads (i.e. Connections) from generating the same
> number?

No, but it prevents them from committing the
same number. Note that this trick can *only* be used
if nothing else depends on the number.

> For example:
> class Factory(Persistent):
>         def build(self):
>                 o = Part()
>                 o.setId( generator.nextId() )
>                 self.addPart(o)
>                 return o
> 
> In this example the Factory instance should raise a ConflictError, but not
> the generator, right?

You couldn't use this to generate ids.  Look again at the comment
in the code snippet I provided.
 
> How would we do this without generating any ConflictErrors?  I thought this
> was the thrust of Randall's email, and it is a question I had a long time ago.

If you implement the hook, then the database will not enforce consistency
between the counter and other objects. If consistency is important, then
the trick won't work for you,
 
> Additionally: how would we provide ConflictError free indexing of newly
> created things?  This might already be answered in the conflictResolution of
> BTrees and I missed it, but what if two connections both:
>         ...
>         newId = generator.getNext()
>         part = Part( newId )
>         index[newId] = part
>         ...
> 
> Is there any way to make this free of ConflictErrors?

You probably would get a conflict in the index itself, 
since two threads might use the same id. If you didn't
get a conmflict error, then you'd get an application
error since you are relying on the generator generating 
unique ids consistently with other changes.

Jim
 
> Sorry if this is already answered, but I think it should be in an easy to
> find FAQ.
> 
> John
> 
> 
> On Thursday 02 August 2001 15:20, Jim Fulton wrote:
> > "Randall F. Kern" wrote:
> > > OH!  That would be it then :(
> > >
> > > So is there any way (other than using an external storage medium) to
> > > write a counter that will never cause a retry?  It's a major hotspot in
> > > my system.
> >
> > Hm, now that you mention it, there's a hook that
> > will let you do this::
> >
> >     def _p_independent(self):
> >         # My state doesn't depend on or materially effect the state of
> >         # other objects.
> >         return 1
> >
> > See BTrees/Length.py.  This disables the consistency check for
> > the object that implements the hook.
> >
> > Jim
> >
> > > -Randy
> > >
> > > > -----Original Message-----
> > > > From: Jim Fulton [mailto:jim@digicool.com]
> > > > Sent: Thursday, August 02, 2001 12:51 PM
> > > > To: Randall F. Kern
> > > > Cc: zodb-dev@zope.org
> > > > Subject: Re: [ZODB-Dev] _p_resolveConflicts
> > > >
> > > > "Randall F. Kern" wrote:
> > > > > Although my hook (_p_resolveConflicts) is called and is
> > > >
> > > > returning the
> > > >
> > > > > proper state, the transactions are still being retried :(
> > > > >
> > > > > Does the default FileStorage in Zope 2.4.0 support conflict
> > > >
> > > > resolution
> > > >
> > > > > or not?
> > > >
> > > > It does.
> > > >
> > > > Note that conflict errors can be detected when reading data.
> > > > Conflict resolution cannot resolve conflicts detected when
> > > > reading.  :(
> > > >
> > > > We need to add full support for "multi-version concurrency
> > > > control", which will allow us to avoid read conflicts by
> > > > reading non-current but consistent data.
> > > >
> > > > Jim
> > > >
> > > > --
> > > > Jim Fulton           mailto:jim@digicool.com   Python Powered!
> > > > Technical Director   (888) 344-4332            http://www.python.org
> > > > Digital Creations    http://www.digicool.com   http://www.zope.org
> > >
> > > _______________________________________________
> > > For more information about ZODB, see the ZODB Wiki:
> > > http://www.zope.org/Wikis/ZODB/
> > >
> > > ZODB-Dev mailing list  -  ZODB-Dev@zope.org
> > > http://lists.zope.org/mailman/listinfo/zodb-dev
> >
> > --
> > Jim Fulton           mailto:jim@digicool.com   Python Powered!
> > Technical Director   (888) 344-4332            http://www.python.org
> > Digital Creations    http://www.digicool.com   http://www.zope.org
> >
> > _______________________________________________
> > For more information about ZODB, see the ZODB Wiki:
> > http://www.zope.org/Wikis/ZODB/
> >
> > ZODB-Dev mailing list  -  ZODB-Dev@zope.org
> > http://lists.zope.org/mailman/listinfo/zodb-dev
> 
> --
> . . . . . . . . . . . . . . . . . . . . . . . .
> 
> John D. Heintz | Senior Engineer
> 
> 1016 La Posada Dr. | Suite 240 | Austin TX 78752
> T 512.633.1198 | jheintz@isogen.com
> 
> w w w . d a t a c h a n n e l . c o m
> 
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
> 
> ZODB-Dev mailing list  -  ZODB-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zodb-dev

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Zope Corporation     http://www.zope.com       http://www.zope.org