From 8fe01db34afd681baa7f8d8d4a45bd080278f0f3 Mon Sep 17 00:00:00 2001 From: Ayush Saxena Date: Thu, 9 Jan 2020 09:02:38 +0530 Subject: [PATCH] HDFS-15094. RBF: Reuse ugi string in ConnectionPoolID. Contributed by Ayush Saxena. --- .../server/federation/router/ConnectionPoolId.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPoolId.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPoolId.java index 868476a826..7cb343b1d5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPoolId.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPoolId.java @@ -44,6 +44,12 @@ public class ConnectionPoolId implements Comparable { private final UserGroupInformation ugi; /** Protocol for the connection. */ private final Class protocol; + /** + * Caching ugi.toString() to save the redundant calculation effort, + * since it is a costly operation and is used as part of both hash calculation + * and equals method. + */ + private final String ugiString; /** * New connection pool identifier. @@ -57,13 +63,14 @@ public ConnectionPoolId(final UserGroupInformation ugi, final String nnId, this.nnId = nnId; this.ugi = ugi; this.protocol = proto; + this.ugiString = ugi.toString(); } @Override public int hashCode() { int hash = new HashCodeBuilder(17, 31) .append(this.nnId) - .append(this.ugi.toString()) + .append(this.ugiString) .append(this.getTokenIds()) .append(this.protocol) .toHashCode(); @@ -77,7 +84,7 @@ public boolean equals(Object o) { if (!this.nnId.equals(other.nnId)) { return false; } - if (!this.ugi.toString().equals(other.ugi.toString())) { + if (!this.ugiString.equals(other.ugiString)) { return false; } String thisTokens = this.getTokenIds().toString();