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

fix: update data model for infinispan #2156

Merged
merged 7 commits into from Mar 9, 2022
Merged

Conversation

achmelo
Copy link
Member

@achmelo achmelo commented Mar 4, 2022

Signed-off-by: achmelo a.chmelo@gmail.com

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Linked to #1982

Type of change

Please delete options that are not relevant.

  • (fix) Bug fix (non-breaking change which fixes an issue)
  • (feat) New feature (non-breaking change which adds functionality)
  • (docs) Change in a documentation
  • (refactor) Refactor the code
  • (chore) Chore, repository cleanup, updates the dependencies.
  • (BREAKING CHANGE or !) Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

For more details about how should the code look like read the Contributing guideline

Signed-off-by: achmelo <a.chmelo@gmail.com>
achmelo and others added 6 commits March 8, 2022 10:08
Signed-off-by: achmelo <a.chmelo@gmail.com>
Signed-off-by: achmelo <a.chmelo@gmail.com>
Signed-off-by: achmelo <a.chmelo@gmail.com>
@sonarcloud
Copy link

sonarcloud bot commented Mar 8, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

94.3% 94.3% Coverage
0.0% 0.0% Duplication

Comment on lines +34 to +37
toCreate.setServiceId(serviceId);
log.info("Writing record: {}|{}|{}", serviceId, toCreate.getKey(), toCreate.getValue());

Map<String, KeyValue> serviceCache = cache.computeIfAbsent(serviceId, k -> new HashMap<>());
KeyValue serviceCache = cache.putIfAbsent(serviceId + toCreate.getKey(), toCreate);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for using serviceId + toCreate.getKey() as the key, rather than a nested map structure like the in memory implementation? This seems to add complexity to the code in the read/delete all for service endpoints, and creates unintuitive coupling between the CRUD operations to calculate the correct key.

I think a comment explaining this might be useful in this file.

Copy link
Member Author

@achmelo achmelo Mar 9, 2022

Choose a reason for hiding this comment

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

Nested map structure was used in the original implementation of Infinispan storage and it turned out to be slow and error-prone in HA setup. Cache object can be mutated by another instance of Caching service when it is not directly used, e.g.

Map<String, KeyValue> serviceCache = cache.computeIfAbsent(serviceId, k -> new HashMap<>());
KeyValue entry = serviceCache.put(toCreate.getKey(), toCreate);
        cache.put(serviceId, serviceCache);

after conputeIfAbsent is returned, the cache lock is released and can be acquired by another instance. When cache.put() is called, the object could not be the same. It could be also an issue for services with too many entries. Each call for serviceId will return a large object that will not be necessarily useful.
There is a trade-off for read/delete all methods but I think that those will not be used extensively. If this will not be the case, we can adjust them.

@achmelo achmelo merged commit 38a1348 into master Mar 9, 2022
@delete-merged-branch delete-merged-branch bot deleted the rip/gh1982/infinspan_tweak branch March 9, 2022 13:46
balhar-jakub pushed a commit that referenced this pull request Apr 7, 2022
* update data model for infinispan

Signed-off-by: achmelo <a.chmelo@gmail.com>

* client cert for profiling

Signed-off-by: achmelo <a.chmelo@gmail.com>

* storage tests

Signed-off-by: achmelo <a.chmelo@gmail.com>

* fix code smells

Signed-off-by: achmelo <a.chmelo@gmail.com>
balhar-jakub pushed a commit that referenced this pull request Apr 8, 2022
* update data model for infinispan

Signed-off-by: achmelo <a.chmelo@gmail.com>

* client cert for profiling

Signed-off-by: achmelo <a.chmelo@gmail.com>

* storage tests

Signed-off-by: achmelo <a.chmelo@gmail.com>

* fix code smells

Signed-off-by: achmelo <a.chmelo@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants