himanshug commented on a change in pull request #10961:
URL: https://github.com/apache/druid/pull/10961#discussion_r589977445
##########
File path:
extensions-core/kubernetes-extensions/src/main/java/org/apache/druid/k8s/discovery/K8sDruidNodeAnnouncer.java
##########
@@ -237,30 +236,14 @@ private String getPodDefAnnocationPath(String annotation)
return StringUtils.format("%s/%s", POD_ANNOTATIONS_PATH_PREFIX,
annotation);
}
- private static String encodeHostPort(String hostPort)
+ // a valid label must be an empty string or consist of alphanumeric
characters, '-', '_' or '.', and
+ // must start and end with an alphanumeric character
+ private static String hashEncodeStringForLabelValue(String str)
{
- //K8S requires that label values must match regex
(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?
- //So, it is essential to replace ':' with '-'
-
- // it is assumed that hostname does not have ':' in it except for
separating host and port
- Preconditions.checkState(
- hostPort.indexOf(':') == hostPort.lastIndexOf(':'),
- "hostname in host:port[%s] has ':' in it", hostPort
- );
-
- return hostPort.replace(':', '-');
- }
-
- private String replaceLast(String str, char oldChar, char newChar)
- {
- char[] chars = str.toCharArray();
- for (int i = chars.length - 1; i >= 0; i--) {
- if (chars[i] == oldChar) {
- chars[i] = newChar;
- break;
- }
+ int hash = str.hashCode();
+ if (hash < 0) {
+ hash = -1 * hash;
Review comment:
hash collision here has no impact on correctness , this is only used to
get a suitable list of candidates. and, this is only used for finding a
specific node by host:port for the health check.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]