Skip to content

Conversation

@voidzcy
Copy link
Contributor

@voidzcy voidzcy commented Sep 29, 2020

No description provided.

@voidzcy voidzcy force-pushed the impl/migrate_xds_resolver_to_use_watch_lds_rds_individually branch from 45c2e0c to f95e61c Compare September 30, 2020 23:11
@voidzcy voidzcy marked this pull request as ready for review October 1, 2020 01:20
@voidzcy voidzcy marked this pull request as draft October 1, 2020 01:26
@voidzcy voidzcy marked this pull request as ready for review October 2, 2020 22:56
…xds_resolver_to_use_watch_lds_rds_individually
@voidzcy voidzcy requested a review from dapengzhang0 October 5, 2020 17:49
.setServiceConfig(emptyServiceConfig)
// let channel take action for no config selector
.build();
private boolean started;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this flag is necessary. It's immediately true once instantiated.

Copy link
Contributor Author

@voidzcy voidzcy Oct 6, 2020

Choose a reason for hiding this comment

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

Ah, this was for the same reason as the rdsWatcher != this check for RDS watcher. When there is multi-threading involved, it is possible that a callback was scheduled (to be executed later) while this resolver is being shut down. Then when the callback is invoked, it should be ignored.

Without this flag, it would do the similar check resolveState != this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend add the checks when you are really implementing the race handling, and review them together. This is really based on assumptions of future implementation which I cannot see the whole picture.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, eliminated flags used for racing cases for now.

}

private void start() {
if (started) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe start() is only called right after instantiation and won't be called twice.

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 for not using start()/stop() is that the LdsResourceWatcher implementation class will not be self-contained. It would be something like

class XdsNameResolver {
  private LdsResourceWatcher ldsWatcher;

  @Override
  public void start(Listener2 listener) {
    ...
    ldsWatcher = new LdsResourceWatcherImpl();
    xdsClient.watchLdsResource(authority, ldsWatcher);
  }


  @Override
  public void shutdown() {
    ...
    if (xdsClient != null) {
      if (ldsWatcher != null) {
        xdsClient.cancelLdsResourceWatch(authority, ldsWatcher);
      }
      ...
    }
    ...
  }
}

I prefer the existing approach as it encapsulate things better. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was not saying not to use start()/stop(). It was about checking the started flag.


@Override
public void onChanged(RdsUpdate update) {
if (this != rdsWatcher) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not do this now based on assumptions on future XdsClient implementation. It's not clear how race is handled by XdsClient yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eliminated. Will reconsider in next steps.

Comment on lines 470 to 471
xdsClient.cancelLdsResourceWatch(authority, this);
cleanUpRdsWatcher();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should they be cleaned up in a FILO order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't matter. But sure, swapped.

}

// https://github.com/google/error-prone/issues/1767
@SuppressWarnings("ModifyCollectionInEnhancedForLoop")
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder where the error-prone warning was coming from in the old code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's for modifying ConcurrentMap clusterRefs in the loop. Not sure how that was triggered. But now, seems it doesn't trigger.

@voidzcy voidzcy merged commit 460ca75 into grpc:master Oct 8, 2020
dfawley pushed a commit to dfawley/grpc-java that referenced this pull request Jan 15, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants