-
Notifications
You must be signed in to change notification settings - Fork 14
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
SLING-10107 [Refactoring] improve resourceresolver handling #63
base: master
Are you sure you want to change the base?
SLING-10107 [Refactoring] improve resourceresolver handling #63
Conversation
Use a Supplier so the LocalStore does not need to know about the creation of the ResourceResolver and its parameters.
Whenever a resourceResolver for the bookkeeper subservice is required, a single central supplier is used. This supplier also exposes a gauge metric so it can be observed how often it is invoked.
Kudos, SonarCloud Quality Gate passed! |
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.
I like the idea of externalising the ResourceResolver creation with a Supplier. We should not leak this into the load methods though.
As a further improvement I think we could have a factory class for the resource resolver outside of BookKeeper. The factory could be a DS component that gets the ResourceResolverFactory injected and could provide a supplier via the create method.
return resolverFactory.getServiceResourceResolver(singletonMap(SUBSERVICE, SUBSERVICE_BOOKKEEPER)); | ||
} catch (LoginException e) { | ||
log.error("Cannot open ResourceResolver", e); | ||
return null; |
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.
I think returning null is dangerous here as it later leads to a NPE. How about throwing an exception instead?
} | ||
|
||
public ValueMap load() { | ||
public ValueMap load(Supplier<ResourceResolver> supplier) { |
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.
When using a LocalStore I think it is a bad idea to provide a ResourceResolver supplier. Why do you think this is necessary?
this.resolverFactory = resolverFactory; | ||
this.distributionMetricsService = distributionMetricsService; | ||
// Error queues are enabled when the number | ||
// of retry attempts is limited ; disabled otherwise | ||
this.errorQueueEnabled = (config.getMaxRetries() >= 0); | ||
this.statusStore = new LocalStore(resolverFactory, STORE_TYPE_STATUS, config.getSubAgentName()); | ||
this.processedOffsets = new LocalStore(resolverFactory, STORE_TYPE_PACKAGE, config.getSubAgentName()); | ||
this.statusStore = new LocalStore(bookKeeperResolver, STORE_TYPE_STATUS, config.getSubAgentName()); |
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's the lifetime of a bookkeeper object? If it's a long-living object, these ResourceResolver
s are also long-living, which is a anti-pattern in Sling/JCR.
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.
BookKeeper is long lived. We are only passing resolverFactory there though. The ResourceResolvers should be short lived.
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.
BookKeeper is long lived, but the resources resolvers it builds inside the LocalStore are short lived and kept private. I think the current implementation is good and simple.
I like the idea of having a metric of resourceResolvers. How about putting the metric inside the standard ResourceResolverFactory in sling? |
@cschneider you mean a metric into the ResourceResolverFactory? For Oak-based setups we have a metric already there. |
Would this metric already help to diagnose if we open too many resource resolvers? |
I refactored the creation of ResourceResolvers (for the bookkeeper subservice) and moved it into a central supplier, which allows also a better monitoring how often ResourceResolvers are actually opened here.
If necessary, further optimizations can be done from here regarding a more efficient use of ResourceResolvers.