Skip to content

Change locality name to a class#19223

Merged
AspirinSJL merged 1 commit intogrpc:masterfrom
AspirinSJL:locality_key
Jun 6, 2019
Merged

Change locality name to a class#19223
AspirinSJL merged 1 commit intogrpc:masterfrom
AspirinSJL:locality_key

Conversation

@AspirinSJL
Copy link
Copy Markdown
Contributor

@AspirinSJL AspirinSJL commented Jun 4, 2019

To keep the original locality name information, we create a class to hold the locality name, instead of a plain string concatenating the fields.


This change is Reviewable

@AspirinSJL AspirinSJL requested a review from mhaidrygoog June 4, 2019 00:31
@AspirinSJL AspirinSJL added the release notes: no Indicates if PR should not be in release notes label Jun 4, 2019
Copy link
Copy Markdown
Member

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

This looks good. Just one comment to address.

Reviewed 2 of 2 files at r1.
Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @apolcyn, @AspirinSJL, @markdroth, and @mhaidrygoog)


src/core/lib/gprpp/map.h, line 44 at r1 (raw file):

struct RefCountedPtrLess {
  bool operator()(const RefCountedPtr<T>& p1, const RefCountedPtr<T>& p2) {
    return *p1 < *p2;

I don't think this is the right default behavior for RefCountedPtrLess<>, because not all ref-counted types will define operator<(). I think RefCountedPtrLess<> should compare only based on addresses. This is analogous to how std::less<> provides a default specialization for pointer types like std::shared_ptr<>, which compare only by address.

I think it's fine to implement a more specific comparison for LocalityName, but that should be a custom type defined in the xds code, not something implemented here in the map library.

Copy link
Copy Markdown
Contributor Author

@AspirinSJL AspirinSJL left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @apolcyn, @markdroth, and @mhaidrygoog)


src/core/lib/gprpp/map.h, line 44 at r1 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

I don't think this is the right default behavior for RefCountedPtrLess<>, because not all ref-counted types will define operator<(). I think RefCountedPtrLess<> should compare only based on addresses. This is analogous to how std::less<> provides a default specialization for pointer types like std::shared_ptr<>, which compare only by address.

I think it's fine to implement a more specific comparison for LocalityName, but that should be a custom type defined in the xds code, not something implemented here in the map library.

Done.

Copy link
Copy Markdown
Member

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

This looks good. Feel free to merge after addressing the remaining comment.

Reviewed 2 of 2 files at r3.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @apolcyn, @AspirinSJL, and @mhaidrygoog)


src/core/ext/filters/client_channel/lb_policy/xds/xds.cc, line 362 at r3 (raw file):

      bool operator()(const RefCountedPtr<LocalityName>& lhs,
                      const RefCountedPtr<LocalityName>& rhs) {
        int cmp_result = gpr_stricmp(lhs->region_.get(), rhs->region_.get());

Do we want all of these comparisons to be case-insensitive? Unless the XDS API specifically indicates that all of these names should be case-insensitive, this seems like the wrong thing to do.

Copy link
Copy Markdown
Contributor Author

@AspirinSJL AspirinSJL left a comment

Choose a reason for hiding this comment

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

Thanks!

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @apolcyn, @markdroth, and @mhaidrygoog)


src/core/ext/filters/client_channel/lb_policy/xds/xds.cc, line 362 at r3 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Do we want all of these comparisons to be case-insensitive? Unless the XDS API specifically indicates that all of these names should be case-insensitive, this seems like the wrong thing to do.

Done.

The spec doesn't say that. I was following the previous comparing code. But I agree it should be case sensitive.

@AspirinSJL AspirinSJL merged commit 10f7ab2 into grpc:master Jun 6, 2019
@AspirinSJL AspirinSJL deleted the locality_key branch June 6, 2019 14:25
@lock lock bot locked as resolved and limited conversation to collaborators Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release notes: no Indicates if PR should not be in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants