HDFS-15094. RBF: Reuse ugi string in ConnectionPoolID. Contributed by Ayush Saxena.

This commit is contained in:
Ayush Saxena 2020-01-09 09:02:38 +05:30
parent fd30f4c52b
commit 8fe01db34a
1 changed files with 9 additions and 2 deletions

View File

@ -44,6 +44,12 @@ public class ConnectionPoolId implements Comparable<ConnectionPoolId> {
private final UserGroupInformation ugi; private final UserGroupInformation ugi;
/** Protocol for the connection. */ /** Protocol for the connection. */
private final Class<?> protocol; 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. * New connection pool identifier.
@ -57,13 +63,14 @@ public class ConnectionPoolId implements Comparable<ConnectionPoolId> {
this.nnId = nnId; this.nnId = nnId;
this.ugi = ugi; this.ugi = ugi;
this.protocol = proto; this.protocol = proto;
this.ugiString = ugi.toString();
} }
@Override @Override
public int hashCode() { public int hashCode() {
int hash = new HashCodeBuilder(17, 31) int hash = new HashCodeBuilder(17, 31)
.append(this.nnId) .append(this.nnId)
.append(this.ugi.toString()) .append(this.ugiString)
.append(this.getTokenIds()) .append(this.getTokenIds())
.append(this.protocol) .append(this.protocol)
.toHashCode(); .toHashCode();
@ -77,7 +84,7 @@ public class ConnectionPoolId implements Comparable<ConnectionPoolId> {
if (!this.nnId.equals(other.nnId)) { if (!this.nnId.equals(other.nnId)) {
return false; return false;
} }
if (!this.ugi.toString().equals(other.ugi.toString())) { if (!this.ugiString.equals(other.ugiString)) {
return false; return false;
} }
String thisTokens = this.getTokenIds().toString(); String thisTokens = this.getTokenIds().toString();