[ZODB-Dev] Re: [Zope] ZODB.POSException.ReadConflictError
Christopher N. Deckard
chris@globalfoo.net
Wed, 8 Jan 2003 08:09:14 -0500
On Wed, 8 Jan 2003 12:57:45 +0000, Toby Dickenson spoke forth:
> On Wednesday 08 January 2003 12:32 pm, Christopher N. Deckard
> wrote:
>
> > > > It'd be neat if the old copy of the object and catalog were
> > > > available until the update transaction was completed. Then
> > > > the new ones could be put in. I don't know the details in
> > > > how updates are handled in the ZODB though.
> > >
> > > That is planned for the future. For now you can fake it by
> > > touching every object you need at the start of your
> > > transaction. That moves a copy into memory, and every access
> > > for the rest of that transaction will be safe from
> > > ReadConflictErrors
> >
> > So how I do that? Just make a reference to it somewhere in my
> > code?
>
> Yes, just try to read an attribute from every persistent object
> that you will need in the computation, *then* perform the
> computation.
>
> That assumes that your method is slow because of a computation,
> rather than because it does something simple on many objects.
>
> The conflict-avoiding pattern looks like
>
> data1 = self.catalog_query('param 1')
> data2 = self.catalog_query('param 2')
> data3 = self.catalog_query('param 3')
> # ReadConflictErrors above here. Expensive stuff below.
> return presentation(computation(data1,data2,data3))
How's something like this:
query = {}
query['foo'] = 'bar'
results = catalog.searchResults(query)[]
# expensive stuff here
return results
I just added the "[]" to the end of the searchResults line. Will
that help?
Thanks,
-Chris
> rather than
>
> p = presentation(computation(self.catalog_query('param 1'))
> p += presentation(computation(self.catalog_query('param 1'))
> p += presentation(computation(self.catalog_query('param 1'))
> return p
>
> > I would assume that it should be doing that already since I do
> > "touch" things throughout the query. I only need to touch the
> > catalog, and I thought that I was doing that.
>
> The catalog is made up of many persistent objects that can be
> leaded into memory independantly. You need to touch the right
> ones.
>