-
Notifications
You must be signed in to change notification settings - Fork 64
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
Conversation
Signed-off-by: achmelo <[email protected]>
Signed-off-by: achmelo <[email protected]>
Signed-off-by: achmelo <[email protected]>
Signed-off-by: achmelo <[email protected]>
… rip/gh1982/infinspan_tweak
Kudos, SonarCloud Quality Gate passed! |
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
* update data model for infinispan Signed-off-by: achmelo <[email protected]> * client cert for profiling Signed-off-by: achmelo <[email protected]> * storage tests Signed-off-by: achmelo <[email protected]> * fix code smells Signed-off-by: achmelo <[email protected]>
* update data model for infinispan Signed-off-by: achmelo <[email protected]> * client cert for profiling Signed-off-by: achmelo <[email protected]> * storage tests Signed-off-by: achmelo <[email protected]> * fix code smells Signed-off-by: achmelo <[email protected]>
Signed-off-by: achmelo [email protected]
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.
Checklist:
For more details about how should the code look like read the Contributing guideline