Change locality name to a class#19223
Conversation
markdroth
left a comment
There was a problem hiding this comment.
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.
AspirinSJL
left a comment
There was a problem hiding this comment.
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 defineoperator<(). I thinkRefCountedPtrLess<>should compare only based on addresses. This is analogous to howstd::less<>provides a default specialization for pointer types likestd::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.
markdroth
left a comment
There was a problem hiding this comment.
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.
AspirinSJL
left a comment
There was a problem hiding this comment.
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.
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