Skip to content

Commit 8fe01db

Browse files
committed
HDFS-15094. RBF: Reuse ugi string in ConnectionPoolID. Contributed by Ayush Saxena.
1 parent fd30f4c commit 8fe01db

File tree

1 file changed

+9
-2
lines changed
  • hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router

1 file changed

+9
-2
lines changed

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPoolId.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public class ConnectionPoolId implements Comparable<ConnectionPoolId> {
4444
private final UserGroupInformation ugi;
4545
/** Protocol for the connection. */
4646
private final Class<?> protocol;
47+
/**
48+
* Caching ugi.toString() to save the redundant calculation effort,
49+
* since it is a costly operation and is used as part of both hash calculation
50+
* and equals method.
51+
*/
52+
private final String ugiString;
4753

4854
/**
4955
* New connection pool identifier.
@@ -57,13 +63,14 @@ public ConnectionPoolId(final UserGroupInformation ugi, final String nnId,
5763
this.nnId = nnId;
5864
this.ugi = ugi;
5965
this.protocol = proto;
66+
this.ugiString = ugi.toString();
6067
}
6168

6269
@Override
6370
public int hashCode() {
6471
int hash = new HashCodeBuilder(17, 31)
6572
.append(this.nnId)
66-
.append(this.ugi.toString())
73+
.append(this.ugiString)
6774
.append(this.getTokenIds())
6875
.append(this.protocol)
6976
.toHashCode();
@@ -77,7 +84,7 @@ public boolean equals(Object o) {
7784
if (!this.nnId.equals(other.nnId)) {
7885
return false;
7986
}
80-
if (!this.ugi.toString().equals(other.ugi.toString())) {
87+
if (!this.ugiString.equals(other.ugiString)) {
8188
return false;
8289
}
8390
String thisTokens = this.getTokenIds().toString();

0 commit comments

Comments
 (0)