Skip to content
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

Drop VirtualMap.getForModify() API #16784

Open
Tracked by #14395
artemananiev opened this issue Nov 25, 2024 · 0 comments
Open
Tracked by #14395

Drop VirtualMap.getForModify() API #16784

artemananiev opened this issue Nov 25, 2024 · 0 comments
Assignees
Labels
Platform Data Structures Platform Virtual Map Platform Tickets pertaining to the platform Tech Debt Reduced Issues which reduce technical debt.

Comments

@artemananiev
Copy link
Member

VirtualMap provides java.util.Map like API, but besides that - a weird method getForModify(). This method is similar to get(): it returns a value from the map, or null if the corresponding key is not in the map. The key difference between get() and getForModify() is that the value returned by the latter can be changed later, and these changes will be reflected in the map.

There are a few concerns about it:

  • This approach opens a possibility for un-intentional changes. It may not be clear that changing an object without an explicit put() to the map may still change the value in the map
  • All recent virtual maps used in Hedera services code are used to store immutable objects: HAPI-generated Java records. There is no way to mutate them. Typical pattern is getForModify(), followed by object copy, then the copy is modified, and put() back to the map explicitly
  • If virtual maps are changed to work with Bytes for both keys and values, getForModify() will still be impossible to implement, since Bytes objects are immutable, too

This ticket is to get rid of getForModify() in VirtualMap and all services code. This is already a part of #16699, but it can be done as a separate fix to reduce the scope of 16699 (which is huge even without this part).

@artemananiev artemananiev added Tech Debt Reduced Issues which reduce technical debt. Platform Virtual Map Platform Data Structures Platform Tickets pertaining to the platform labels Nov 25, 2024
@artemananiev artemananiev self-assigned this Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform Data Structures Platform Virtual Map Platform Tickets pertaining to the platform Tech Debt Reduced Issues which reduce technical debt.
Projects
None yet
Development

No branches or pull requests

3 participants