ZODB: more control over object deactivations
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
ZODB |
Confirmed
|
Wishlist
|
Unassigned | ||
Zope 2 |
Invalid
|
Wishlist
|
Unassigned |
Bug Description
Several parts of Zope use volatile variables ("_v_")
which must not disappear during a transaction.
Most prominent examples are Zope's database adapters
that use a volatile attribute to hold the connection
to the database.
The current ZODB implementation can deactivate objects
at sub-transactions and transaction boundaries.
Deactivating objects with "_v_" attributes at subtransaction
boundaries, can seriously affect transaction consistency
(when a connection in a Zope database adapter is dropped).
This has beend discussed on zodb-dev in Dec. 2003. Most
people favoured a way to control object deactivation during
a transaction.
On Feb. 7th, 2004, I posted the attached patch to zodb-dev
with the following description. It allows to easily fix
problems with premature loss of "_v_" variables.
Quote from a "zodb-dev" post from Feb 7th, 2004, titled:
More "cPickleCache.
(was: [Problem] "_v_" variables too volatile)
The attached patch against the Zope-Head CVS version
of 2004-02-07 provides more control as follows:
* Persistent objects get a new "_p_sticky" attribute which
can be read and written (from Python).
It is a boolean, but currently implemented (in "C") as a byte
(just because byte access is more efficient than bit access).
The "Sticky" state could not be used for this purpose
as it is reset at transaction boundaries while
our "_p_sticky" must remain until object deactivation
* "cPickleCache.
argument.
This optional argument now gets the interpretation
"mayFlushS
Its default is "True".
If true, "incrgc" is allowed to deactivate objects
with a true "_p_sticky". Otherwise, it must not deactivate
such objects.
* "ZODB.Connection" is changed such that it calls "cPickleCache.
with "mayFlushSticky" true only in
"setDB", "sync" and at boundaries of main transactions (and
not subtransactions).
As subtransaction handling is a bit convoluted :-(
"incrgc" may be called with "mayFlushSticky
even when a main transaction is aborted (as it is not
always clear whether a main or a subtransaction is aborted).
* "minimize" never flushes objects with "_p_sticky == True",
as it is usually called asynchronously.
The patch does not automatically prevent "_v_" attribute flushing at
subtransaction boundaries. Only if "_p_sticky" is explicitely set to a true
value, a flush at subtransaction boundaries is prevented.
A "self->sticky = 1" in the "_v_" attribute handling
of "cPersistence:
would make "_v_" protection automatic but
most discussion contributors said "explicit is better than implicit"
and saw use cases where "_v_" variables need no protection.
Changed in zodb: | |
status: | New → Confirmed |
Changed in zodb: | |
importance: | Undecided → Wishlist |
Thanks Dieter.
I'd like to apply this patch quickly (I'd rather Tim did it though :))
Is it acceptable on the 2.7 branch ?
Would it need modifications on ZODB 3.3 for Zope 2.8 ?