transactions on pharo objects
Hi, is there some library or approach how to do transactions in pharo? And I don't mean database transactions, but directly in memory on Pharo objects... e.g. p := Person new. transaction do: [ p name: 'Nobody'. p age: 70. ] on: Error do: [ transaction rollback. ]. self assert: p name equals: 'Nobody'. self assert: p age equals: 70. transaction do: [ p name: 'Somebody'. p age: 1 / 0. ] on: Error do: [ transaction rollback. ]. self assert: p name equals: 'Nobody'. self assert: p age equals: 70. Any pointers appreciated. Thanks, Peter
I think it is a tricky thing to do "in memory transactions", even without thinking about databases. You have to define what to keep and where to place the "original" values (inst. vars.) of the object. As a general purpose solution if you can do that, you end up implementing a mini gemstone in Pharo :) But what's sure is that you should have a mini object-table of the "touched" objects or do "explicit" registration of these objects like GLORP allows you to do. e.g. | p | p := Person new. System transaction: [:tx | tx register: p. p name: 'Nobody'. p age: 70. ]. self assert: p name equals: 'Nobody'. self assert: p age equals: 70. I'm using System here, to make it compatible with GemStone. #transaction: could be implemented in terms of #beginTransaction, #commitTransaction and internally use #abortTransaction if an unhandled Error is signalled. Regards! Esteban A. Maringolo El lun., 30 jul. 2018 a las 10:17, Peter Uhnák (<i.uhnak@gmail.com>) escribió:
Hi,
is there some library or approach how to do transactions in pharo? And I don't mean database transactions, but directly in memory on Pharo objects... e.g.
p := Person new.
transaction do: [ p name: 'Nobody'. p age: 70. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
transaction do: [ p name: 'Somebody'. p age: 1 / 0. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
Any pointers appreciated.
Thanks, Peter
Esteban A. Maringolo wrote
I think it is a tricky thing to do "in memory transactions", even without thinking about databases. You have to define what to keep and where to place the "original" values (inst. vars.) of the object.
As a general purpose solution if you can do that, you end up implementing a mini gemstone in Pharo :)
But what's sure is that you should have a mini object-table of the "touched" objects or do "explicit" registration of these objects like GLORP allows you to do.
e.g.
| p | p := Person new. System transaction: [:tx | tx register: p. p name: 'Nobody'. p age: 70. ].
It seems to me that the fundamental problem with the idea of registering each object with the transaction (or anything else) is that it requires white-box knowledge of what every invoked behaviour will do and touch. The above example is so minimal, it looks easy. I think if you really want transactional Smalltalk, you need to use one designed expressly for that purpose. (And fortunately, there is one.)
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
I'm using System here, to make it compatible with GemStone. #transaction: could be implemented in terms of #beginTransaction, #commitTransaction and internally use #abortTransaction if an unhandled Error is signalled.
Regards!
Esteban A. Maringolo El lun., 30 jul. 2018 a las 10:17, Peter Uhnák (<
i.uhnak@
>) escribió:
Hi,
is there some library or approach how to do transactions in pharo? And I don't mean database transactions, but directly in memory on Pharo objects... e.g.
p := Person new.
transaction do: [ p name: 'Nobody'. p age: 70. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
transaction do: [ p name: 'Somebody'. p age: 1 / 0. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
Any pointers appreciated.
Thanks, Peter
-- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
El mié., 1 de ago. de 2018 20:52, Richard Sargent < richard.sargent@gemtalksystems.com> escribió:
Esteban A. Maringolo wrote
As a general purpose solution if you can do that, you end up implementing a mini gemstone in Pharo :)
But what's sure is that you should have a mini object-table of the "touched" objects or do "explicit" registration of these objects like GLORP allows you to do.
It seems to me that the fundamental problem with the idea of registering each object with the transaction (or anything else) is that it requires white-box knowledge of what every invoked behaviour will do and touch. The above example is so minimal, it looks easy.
I agree with that. Deciding when to what to copy and what to preserve is always tricky unless yo decide to copy the whole object graph which would be terrible. Very much like what to proxy and what to forward in GemBuilder. I think if you really want transactional Smalltalk, you need to use one
designed expressly for that purpose. (And fortunately, there is one.)
That's why I say this is tricky and you'll probably end up implementing a mini-GemStone. I don't know what it means in terms of programming, but having a transactional object memory would be a useful thing to work with. Regards, Esteban.
Maybe you can have a look to this paper : https://www.sciencedirect.com/science/article/pii/S1477842408000237 On Mon, Jul 30, 2018 at 2:17 PM Peter Uhnák <i.uhnak@gmail.com> wrote:
Hi,
is there some library or approach how to do transactions in pharo? And I don't mean database transactions, but directly in memory on Pharo objects... e.g.
p := Person new.
transaction do: [ p name: 'Nobody'. p age: 70. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
transaction do: [ p name: 'Somebody'. p age: 1 / 0. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
Any pointers appreciated.
Thanks, Peter
-- Serge Stinckwich UMI UMMISCO 209 (SU/IRD/UY1) "Programs must be written for people to read, and only incidentally for machines to execute."http://www.doesnotunderstand.org/
Peter Uhnák wrote
is there some library or approach how to do transactions⦠directly in memory on Pharo objects
Magritte? It uses the Memento pattern to verify all changes before committing to real object. ----- Cheers, Sean -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
El lun., 30 jul. 2018 a las 11:03, Sean P. DeNigris (<sean@clipperadams.com>) escribió:
Peter Uhnák wrote
is there some library or approach how to do transactions⦠directly in memory on Pharo objects
Magritte? It uses the Memento pattern to verify all changes before committing to real object.
But you need Magritte, and define descriptions, and references, and access the objects via Magritte Accessors, etc. I think that works for an UI of a somehow limited form, but not as a general purpose (as I guess Peter is looking for). Also for forms, but without metadata, Dolphin used a "BufferedModel" object, which means that if you have an MVP/MVC, instead of using your original model, you work on this "buffer", which internally has the original and a copy, and all messages are sent to the copy and once you "apply" the changes they are applied back to the original model, and if you don't apply, the copy is discarded and the original model left unmodified. But again, I guess Peter is looking for something else. Regards!
Am 30.07.2018 um 16:02 schrieb Sean P. DeNigris <sean@clipperadams.com>:
Peter Uhnák wrote
is there some library or approach how to do transactions⦠directly in memory on Pharo objects
Magritte? It uses the Memento pattern to verify all changes before committing to real object.
This only works for simple use cases where there is one flow that creates the memento and keeps it like in a web form. The problem with the memento is that it is hard to make all objects give a memento when they are aquired. Norbert
----- Cheers, Sean -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Basically, what you are talking about is Software Transactional Memory. According to https://en.wikipedia.org/wiki/Software_transactional_memory#Smalltalk there *is* STM support for Pharo at http://source.lukas-renggli.ch/transactional/ although the last version there is from 2012, and there have been major changes to Pharo since then, so it probably doesn't work any longer. You could probably make a TransactionalObject class with a 'lastTransaction' instance variable, and a noteChange method that checks if lastTransaction == Transaction current, and if not, pushes self -> self shallowCopy onto a stack inside Transaction and sets lastTransaction to Transaction current. Then to roll back a transaction, peel back original -> backup records from the stack and do original copyFrom: backup for each of them. Please don't ask me to think about combining this with concurrency. On 31 July 2018 at 01:16, Peter Uhnák <i.uhnak@gmail.com> wrote:
Hi,
is there some library or approach how to do transactions in pharo? And I don't mean database transactions, but directly in memory on Pharo objects... e.g.
p := Person new.
transaction do: [ p name: 'Nobody'. p age: 70. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
transaction do: [ p name: 'Somebody'. p age: 1 / 0. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
Any pointers appreciated.
Thanks, Peter
Am 31.07.2018 um 06:57 schrieb Richard O'Keefe <raoknz@gmail.com>:
Basically, what you are talking about is Software Transactional Memory. According to https://en.wikipedia.org/wiki/Software_transactional_memory#Smalltalk there *is* STM support for Pharo at http://source.lukas-renggli.ch/transactional/ although the last version there is from 2012, and there have been major changes to Pharo since then, so it probably doesn't work any longer.
You could probably make a TransactionalObject class with a 'lastTransaction' instance variable, and a noteChange method that checks if lastTransaction == Transaction current, and if not, pushes self -> self shallowCopy onto a stack inside Transaction and sets lastTransaction to Transaction current. Then to roll back a transaction, peel back original -> backup records from the stack and do original copyFrom: backup for each of them.
Please don't ask me to think about combining this with concurrency.
You could delegate the transaction list and other objects to a process specific variable. But the biggest problem with a copy approach is that all identity checks fail with the copied objects Norbert
On 31 July 2018 at 01:16, Peter Uhnák <i.uhnak@gmail.com> wrote: Hi,
is there some library or approach how to do transactions in pharo? And I don't mean database transactions, but directly in memory on Pharo objects... e.g.
p := Person new.
transaction do: [ p name: 'Nobody'. p age: 70. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
transaction do: [ p name: 'Somebody'. p age: 1 / 0. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
Any pointers appreciated.
Thanks, Peter
Hello, A lot of time ago, we have implemented a basic support for STM in Java (it is written in Scala... dark dark dark ages). We have used aspect oriented programming to intercept the reading and writing of the instance variables of the classes that support the transactions. We kept a dictionary with the values for the transactions in course and a version, and the original object has the "commited" values. On a commit you can apply the changes to the object iff there is no conflict version. I think a similar implementation could be done in Pharo using Slots in a couple of hours. Also, you should use process specific values to detect and handle in witch transaction you are. Depending how much you want to guarantee ACID properties, you will have simpler or complex implementation. In those days, we only wanted only isolation. Sadly, the details of the implementation are in a Master Thesis in Spanish, I doubt they will be useful, but still I can point you to the source code of the solution. By the way, this is still in use as a part of a tool to teach UI design. https://github.com/uqbar-project/arena/tree/master/arena-pot Cheers, Pablo On Tue, Jul 31, 2018 at 8:48 AM Norbert Hartl <norbert@hartl.name> wrote:
Am 31.07.2018 um 06:57 schrieb Richard O'Keefe <raoknz@gmail.com>:
Basically, what you are talking about is Software Transactional Memory. According to https://en.wikipedia.org/wiki/Software_transactional_memory#Smalltalk there *is* STM support for Pharo at http://source.lukas-renggli.ch/transactional/ although the last version there is from 2012, and there have been major changes to Pharo since then, so it probably doesn't work any longer.
You could probably make a TransactionalObject class with a 'lastTransaction' instance variable, and a noteChange method that checks if lastTransaction == Transaction current, and if not, pushes self -> self shallowCopy onto a stack inside Transaction and sets lastTransaction to Transaction current. Then to roll back a transaction, peel back original -> backup records from the stack and do original copyFrom: backup for each of them.
Please don't ask me to think about combining this with concurrency.
You could delegate the transaction list and other objects to a process specific variable. But the biggest problem with a copy approach is that all identity checks fail with the copied objects
Norbert
On 31 July 2018 at 01:16, Peter Uhnák <i.uhnak@gmail.com> wrote:
Hi,
is there some library or approach how to do transactions in pharo? And I don't mean database transactions, but directly in memory on Pharo objects... e.g.
p := Person new.
transaction do: [ p name: 'Nobody'. p age: 70. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
transaction do: [ p name: 'Somebody'. p age: 1 / 0. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
Any pointers appreciated.
Thanks, Peter
-- Pablo Tesone. tesonep@gmail.com
Norbert Hartl wrote:
the biggest problem with a copy approach is that all identity checks fail with the copied objects
The scheme I proposed *hides* the (shallow) copies. The only thing ever done with them is to copy their contents back into the original objects. There are therefore no "identity checks ... with the copied objects" for anyone to care about. On 31 July 2018 at 18:47, Norbert Hartl <norbert@hartl.name> wrote:
Am 31.07.2018 um 06:57 schrieb Richard O'Keefe <raoknz@gmail.com>:
Basically, what you are talking about is Software Transactional Memory. According to https://en.wikipedia.org/wiki/Software_transactional_ memory#Smalltalk there *is* STM support for Pharo at http://source.lukas-renggli.ch/transactional/ although the last version there is from 2012, and there have been major changes to Pharo since then, so it probably doesn't work any longer.
You could probably make a TransactionalObject class with a 'lastTransaction' instance variable, and a noteChange method that checks if lastTransaction == Transaction current, and if not, pushes self -> self shallowCopy onto a stack inside Transaction and sets lastTransaction to Transaction current. Then to roll back a transaction, peel back original -> backup records from the stack and do original copyFrom: backup for each of them.
Please don't ask me to think about combining this with concurrency.
You could delegate the transaction list and other objects to a process specific variable. But the biggest problem with a copy approach is that all identity checks fail with the copied objects
Norbert
On 31 July 2018 at 01:16, Peter Uhnák <i.uhnak@gmail.com> wrote:
Hi,
is there some library or approach how to do transactions in pharo? And I don't mean database transactions, but directly in memory on Pharo objects... e.g.
p := Person new.
transaction do: [ p name: 'Nobody'. p age: 70. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
transaction do: [ p name: 'Somebody'. p age: 1 / 0. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
Any pointers appreciated.
Thanks, Peter
Am 30.07.2018 um 15:16 schrieb Peter Uhnák <i.uhnak@gmail.com>:
Hi,
is there some library or approach how to do transactions in pharo? And I don't mean database transactions, but directly in memory on Pharo objects... e.g.
p := Person new.
transaction do: [ p name: 'Nobody'. p age: 70. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
transaction do: [ p name: 'Somebody'. p age: 1 / 0. ] on: Error do: [ transaction rollback. ].
self assert: p name equals: 'Nobody'. self assert: p age equals: 70.
Any pointers appreciated.
Should this work image wide or per process? Norbert
participants (8)
-
Esteban A. Maringolo -
Norbert Hartl -
Peter Uhnák -
Richard O'Keefe -
Richard Sargent -
Sean P. DeNigris -
Serge Stinckwich -
tesonep@gmail.com