Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Bug fixes for Orleans Bank Account sample. #7019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2025

Conversation

Rossimac
Copy link
Contributor

Balance now updates after Deposit or Withdraw operations.

Withdraw decrements now instead of incorrectly incrementing.

Balance now updates after Deposit or Withdraw operations.

Withdraw decrements now instead of incorrectly incrementing.
@oising
Copy link

oising commented May 8, 2025

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.

@@ -34,7 +34,7 @@ public Task Withdraw(int amount) =>
$" This account has {balance.Value} credits.");
}

return balance with { Value = balance.Value + amount };
balance = balance.Value -= amount;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The balance = part here is unnecessary - the balance variable goes out of scope immediately after this statement

@ReubenBond
Copy link
Member

@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.
@Rossimac Rossimac force-pushed the fix-orleans-bank-account-sample branch from 07f28af to 7a91f98 Compare June 8, 2025 19:02
@Rossimac
Copy link
Contributor Author

Rossimac commented Jun 8, 2025

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.

@ReubenBond ReubenBond merged commit 4d316c2 into dotnet:main Jun 9, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.