[Glass] Concurrency Pattern - Delete an object if a collction it contains is empty, how ?
martin.mcclure at gemtalksystems.com
Wed Feb 27 14:57:32 PST 2019
It sounds like you're describing a condition where there is a semantic
conflict, even when the conflicting sessions do not commit changes to
the same object.
In order for GemStone to report a transaction conflict in cases like
that, you need to have both sessions modify the same object. I will
refer to this object as the "conflict object." This could be one of the
objects you already have, or you might have to create it just for that
purpose, depending on the situation.
If I understand what you've described correctly, you have an overall
collection holding objects. Each object holds a set of attributes.
You want a transaction removing the object from the overall collection
to conflict with a transaction adding an attribute.
If this is an accurate description of your situation, one choice would
be to use the object itself as the "conflict object." If you modify the
object every time you add an attribute to it, and also modify the object
when it's removed from the collection, then concurrent transactions
doing those operations will conflict.
IIRC, modifying an object by assigning an instvar to itself like
someInstVar := someInstVar.
is sufficient for the object to be considered written for the purposes
of transaction conflict detection.
By using this kind of pattern, these cases *can* be handled. But when
you run into these cases, it's worthwhile to examine your overall
architecture to see whether there's a change that would avoid needing
this kind of complexity, since code acquires a certain amount of
fragility when it's required to use these patterns.
More information about the Glass