Bug fixes for Orleans Bank Account sample.#7019
Conversation
Balance now updates after Deposit or Withdraw operations. Withdraw decrements now instead of incorrectly incrementing.
|
Removing the immutability of the Balance class sets a bad precedent for this sample. The idea of immutability is to prevent the class of bugs where grain A makes a change to a instance, then sends it to grain B -- on the same silo -- and then makes another change to the instance, which, because it's a reference/byref, will change the instance in grain B also. |
| } | ||
|
|
||
| return balance with { Value = balance.Value + amount }; | ||
| balance = balance.Value -= amount; |
There was a problem hiding this comment.
The balance = part here is unnecessary - the balance variable goes out of scope immediately after this statement
|
@oising I believe this is the correct change, due to how the transactions API works: The delegate passed to PerformUpdate receives a copy of state and it's expected to mutate it. |
Made Balance a class instead of a record as no benefit in using record here. Added Id attribute to Balance.Value so that it is serialized and to allow state to be persisted after a Withdrawal. Removed Reentrant attribute from AccountGrain as this could introduce race conditions when using Transactions.
07f28af to
7a91f98
Compare
|
I fixed a couple of build errors in the commit. Also, I fixed the sample to allow the bank balance to actually persist the balance after a Withdrawal. |
Balance now updates after Deposit or Withdraw operations.
Withdraw decrements now instead of incorrectly incrementing.