Transaction bug in functional db, the 'ts' field will be incorrect if execute more than one operations in a single transaction?
@yoavrubin
The functional db project is really cool, and I learned a lot from it. After reading it, I have a doubt about the Transaction section. I'm not familiar with Clojure, if I have a wrong understanding, please forgive me, thank you very much.
In the transact-on-db function, each operations will be executed on the initial-db and finally generated an updated database named transacted, and then the newest layer in transacted will be appended to the initial-db as the newest layer. I think there is a bug in the last process if more than one operations need to be executed in an transaction. Consider the following example:
- The
initial-dbhas two layers, the first layer is empty(tsis0), and the second one has only one entityewith an attribute nameda, anda's value isv1,tsis1. - Execute two update operations in a transaction: the first one will update
atov2and the second one will updateatov3. The first operation will generate a new layer, in whicha's value isv2andtsis2,prev-tsis1. The second operation will generate a new layer too, in whicha's value isv3,tsis3,prev-tsis2. - After above two operations,
transact-on-dbwill append the layer generated by second operation toinitial-db's layers, now theinitial-dbhas three layers, the first one'stsis0, the second one'stsis1, but the third one'stsis3, anda'sprev-tsis2in the third layer. At this time, if we invoke theevolution-offunction oninitial-db, we will fall into an infinite loop.
The above example is just one possible error, if we execute more than two update operations in a single transaction and then invoke evolution-of, we will fall into a 'layer not found' error.
Source: aosabook/500lines