[Glass] Concurrency Pattern - Delete an object if a collction it contains is empty, how ?
James Foster
Smalltalk at JGFoster.net
Wed Feb 27 12:20:29 PST 2019
Marten,
Perhaps I’m getting confused by the reference to "an empty set” and then the instructions to “remove object”. Are there two collections? One in the object and one holding the object?
I believe you are describing a situation in which you have a collection of objects and you want a sub collection of objects that satisfy some criteria (in your case the criteria is “an object’s attribute slot is empty").
So, first, just apply a #select: message to the persistent collection. Would that be semantically the same? If so, are you eliminating that solution based on a measurable performance concern?
One way to think about concurrency is how the events would play out if they were not in parallel, but happened in series (e.g., with a lock on the persistent collection). If the object changed so that it satisfied the condition before the purge runs, then the object stays. If the purge runs first, how does the object get added back? Is a new object created? Or is it in another collection?
If the object would be persistent anyway (in another collection), then, again, why not a #select: on the main collection? If that has a measurable performance problem then look at creating an index on the attribute in question and use the index-based #select: method.
Again, I’m asking mostly to better understand the question, not to push a solution on you.
James
> On Feb 27, 2019, at 7:54 AM, Marten Feldtmann <m at feldtmann.online> wrote:
>
> I do not want to remove an empty set from an object, perhaps this makes it much clearer:
>
>
>
> Transaction A:
>
> +-------------------> check if set in object attribute slot is empty -> remove object -> ------------------------------------+
>
> Transaction B:
>
> + -----------------> add element to set in object attribute slot -> ------------ +
>
>
>
> I would not assume, that this results into a commit conflict ....
>
>
>
>> James Foster <Smalltalk at JGFoster.net> hat am 27. Februar 2019 um 15:59 geschrieben:
>>
>> In order to better understand the situation, I have two questions:
>> (1) Why do you want to remove an empty Set from an object?
>> (2) Why not use locks?
>>
>> James
>>
>>> On Feb 27, 2019, at 4:16 AM, Marten Feldtmann via Glass < glass at lists.gemtalksystems.com <mailto:glass at lists.gemtalksystems.com>> wrote:
>>>
>>> This seems to be a general concurrency handling pattern in Gemstone:
>>>
>>>
>>>
>>> Situation: I have an object, which holds a Set in one of its attributes (slots).
>>>
>>> Question: I want to remove this object, IF the set is empty. But what happens, if another task is just adding an item to this set ? How can Gemstone find a commit conflict ? I do not want to use locks on objects.
>>>
>>>
>>>
>>> Any other idea ?
>>>
>>> _______________________________________________
>>> Glass mailing list
>>> Glass at lists.gemtalksystems.com <mailto:Glass at lists.gemtalksystems.com>
>>> http://lists.gemtalksystems.com/mailman/listinfo/glass
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20190227/58c6a96f/attachment.html>
More information about the Glass
mailing list