-
Notifications
You must be signed in to change notification settings - Fork 497
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
WIP: implement Ip::Address::asText() #1739
base: master
Are you sure you want to change the base?
Changes from 5 commits
c673207
b97f3ed
49b1423
8979a90
7e6b316
1ab9f10
5f2ee67
0a15787
95bd8d1
ba29475
1b46e26
6105648
468faa7
bf14fcc
a422967
06644aa
343f04b
6007f79
beee7cb
96489ce
899724a
794cad1
c8f7293
c73c17f
a38723a
4de23d0
abf7d4d
9a19f31
15ca319
e29fa69
ec14be4
88402b1
80dd4bf
8545ac0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -137,28 +137,25 @@ peerSourceHashRegisterWithCacheManager(void) | |||||
CachePeer * | ||||||
peerSourceHashSelectParent(PeerSelector *ps) | ||||||
{ | ||||||
const char *c; | ||||||
CachePeer *p = nullptr; | ||||||
unsigned int user_hash = 0; | ||||||
unsigned int combined_hash; | ||||||
double score; | ||||||
double high_score = 0; | ||||||
const char *key = nullptr; | ||||||
char ntoabuf[MAX_IPSTRLEN]; | ||||||
|
||||||
if (SourceHashPeers().empty()) | ||||||
return nullptr; | ||||||
|
||||||
assert(ps); | ||||||
HttpRequest *request = ps->request; | ||||||
|
||||||
key = request->client_addr.toStr(ntoabuf, sizeof(ntoabuf)); | ||||||
const auto key = request->client_addr.toStrAsSBuf(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This use-case does not need any new API. It can just:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to guarantee that two different Squid instances produce the same hash for the same request?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point. At the same time, I would keep this change as its own PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Adopted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is this hash computation (de facto) standardized across different products (including non-Squid-based caches) or can we assume that this is a Squid-specific concern? If it is a Squid-specific concern: The "we can change things across versions" logic is sound, but it does not work as well when dealing with distributed cache hierarchies where nodes may run different versions. I would not object to a breaking change like that if others are sure that it is warranted, but in that case, again, we should not covert the IP address to text to compute a hash. The non-obvious sensitivity of this code to address formatting warrants a C++ comment, especially if we migrate to something implicit like ToSBuf().
Thank you. I assume "this change" is "possible change of peer hash values". |
||||||
|
||||||
/* calculate hash key */ | ||||||
debugs(39, 2, "peerSourceHashSelectParent: Calculating hash for " << key); | ||||||
|
||||||
for (c = key; *c != 0; ++c) | ||||||
user_hash += ROTATE_LEFT(user_hash, 19) + *c; | ||||||
for (auto c : key) | ||||||
user_hash += ROTATE_LEFT(user_hash, 19) + c; | ||||||
|
||||||
/* select CachePeer */ | ||||||
for (const auto &tp: SourceHashPeers()) { | ||||||
|
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.
IMO the
AsSBuf
portion of the naming is more harm than good. We should just be deprecating thechar*
API and otherwise keeping the naming the same.[EDIT: ... assuming scope is kept at updating methods, not moving to the alternative API @rousskov proposed]
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 do agree that toStrAsSBuf() is a non-starter as far as spelling is concerned. However, FWIW, following the above renaming suggestion will not address my primary concerns and, hence, will not move this PR forward.
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.
It is now gone
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.
Still here and still used. I cannot provide requested feedback until this is gone.