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

Rely on TopologyEvent only instead of refering to DiscoveryService which c… #2651

Merged
merged 2 commits into from
Jul 22, 2021

Conversation

stefan-egli
Copy link
Contributor

…auses circular reference (#2650)

@stefan-egli
Copy link
Contributor Author

@kwin , could you please have a look at this PR? It avoids a circular reference error that can be avoided: the DiscoveryServiceHelper can rely on the TopologyEvent (which it is guaranteed to get as per discovery API) - instead of also having a reference to DiscoveryService (which causes osgi to issue the circular reference log.error). Thx!

@@ -64,9 +59,6 @@ public void handleTopologyEvent(TopologyEvent event) {
@Activate
public void activate(BundleContext bundleContext) {
this.bundleContext = bundleContext;
if (discoveryService.getTopology().getLocalInstance().isLeader()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How often are relevant topology events send out? How much does this change potentially defer the ClusterLeader service from becoming active on a leader...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are sent as soon as a topology change is detected and has settled.
There is no difference between getting the event vs asking the DiscoveryService - the underlying state is the same.

The problem with this activate method in addition btw is that the topology might not be defined yet - in which case TopologyView.isCurrent() would return false - ie the leader flag would be based on stale/not current information. If you rely on TopologyEventHandler this would not happen.

Copy link
Contributor

@kwin kwin Jul 21, 2021

Choose a reason for hiding this comment

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

I am not following here: In case TopologyView.isCurrent() would return false no ClusterLeader service is registered so I don't think there is a problem here.

They are sent as soon as a topology change is detected and has settled.

The problem is rather that this service (DiscoveryServiceHelper) might start after a stable topology has been established already. In that case the ClusterLeader service would only be registered once a new topology change event is received. You still haven't answered how long it might take to receive an event in the worst case.

The whole idea of registering the service eagerly in activate() is that otherwise it might take too long until this service figured out whether it runs on the leader or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was mentioning TopologyView.isCurrent() not InstanceDescription.isLeader()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is rather that this service might start after a stable topology has been established already. In that case the ClusterLeader service would only be registered once a new topology change event is received.

Just to make sure we're talking about the same thing: there's both TOPOLOGY_CHANGED - but there's also TOPOLOGY_INIT. TOPOLOGY_INIT is for exactly this purpose: it sends the very first state of the topology (once it is defined) to the listener right/soon-after the listener was registered. Ie the listener doesn't have to wait for a topology change.

The whole idea of registering the service eagerly in activate() is that otherwise it might take too long until this service figured out whether it runs on the leader or not.

Ideally we're talking a few millis

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, but that could be easily fixed by adding another condition. Your change affects functionality in a bad way as it defers registering ClusterLeader, I am just not sure by how much...

Copy link
Contributor

Choose a reason for hiding this comment

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

TOPOLOGY_INIT is for exactly this purpose: it sends the very first state of the topology (once it is defined) to the listener right/soon-after the listener was registered. Ie the listener doesn't have to wait for a topology change.

Thanks, indeed that was the missing part. Then the change looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok great. I was gonna add that the difference is miniscule. In case of a standalone instance it would be merely one
thread-switch (as TopologyEvents are always sent asynchronously to avoid blocking) - and in case of a cluster it is likely that at activation time the topology hasn't even settled, so no time would be lost at all.

@kwin kwin changed the title Rely on TopologyEvent instead of refering to DiscoveryService which c… Rely on TopologyEvent only instead of refering to DiscoveryService which c… Jul 21, 2021
@kwin
Copy link
Contributor

kwin commented Jul 21, 2021

@stefan-egli Can you add a changelog entry?

@stefan-egli
Copy link
Contributor Author

sure, let me find out where that is

@codecov
Copy link

codecov bot commented Jul 21, 2021

Codecov Report

Merging #2651 (9555c5e) into master (7c358e8) will decrease coverage by 0.00%.
The diff coverage is n/a.

❗ Current head 9555c5e differs from pull request most recent head 8ee1785. Consider uploading reports for the commit 8ee1785 to get more accurate results
Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2651      +/-   ##
============================================
- Coverage     52.49%   52.49%   -0.01%     
+ Complexity     5301     5300       -1     
============================================
  Files           751      751              
  Lines         30081    30079       -2     
  Branches       3881     3880       -1     
============================================
- Hits          15792    15790       -2     
  Misses        12823    12823              
  Partials       1466     1466              
Impacted Files Coverage Δ
.../acs/commons/util/impl/DiscoveryServiceHelper.java 88.88% <ø> (-1.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7c358e8...8ee1785. Read the comment docs.

@stefan-egli
Copy link
Contributor Author

done : 8ee1785

@stefan-egli
Copy link
Contributor Author

@kwin , is that code coverage -0.01% a worry?

@kwin
Copy link
Contributor

kwin commented Jul 21, 2021

is that code coverage -0.01% a worry?

That is no problem, we still need to tweak a bit the required checks after migrating from Travis to GitHub actions.

@kwin kwin merged commit 3933803 into Adobe-Consulting-Services:master Jul 22, 2021
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.

2 participants