[Erp5-dev] reindex inside a transaction?

Bartek Gorny bartek at gorny.edu.pl
Sat Nov 6 14:11:16 CET 2010


Hi

I observed a very strange behaviour, which makes me rather worried.
Here is the use case:

There is a document (an invoice) and a workflow. Upon validation of
the document the workflow script does two things:
- generates a pdf version
- changes the title of the document (because validated invoices are
numbered sequentially)

Then the document is automatically reindexed. The problem is that
while every validated invoice has the new title when you look at the
object, the catalog sometimes contains the new value, and sometimes
the old value. Next time the doc is validated the values in ZODB and
in catalog become equal.

All this is very strange, especially that it appears to happen
randomly and is not reproduceable. How and why it may happen?

The only way I see is that a reindex is processed by activity tool
before the transaction is commited to the ZODB, so it uses old version
of the object. Is reindex wrote to the sql activity queue immediately,
or only after the transaction is committed? Because if it is written
immediately, then the following might happen:
- the workflow changes the object state, writes the object to ZODB
- activity tool writes the activity to the sql queue
- workflow triggers the after_scripts which begins to generate PDF,
which takes some time
- activity tool picks up the job and executes reindex
- the script returns and transaction is committed
and we have an inconsistency in data.

Am I right, or there might be some other reason?

Bartek


-- 
"CPU stepping is when you tile your front porch with extra CPU like
celeron 1ghz units.
typically you spread a thin layer of mortar the cpu's are laid and
then joints filled.
that's it cpu steps all done!"

(dragonsprayer at www.tomshardware.co.uk)



More information about the Erp5-dev mailing list