Skip to content

Allow WriteClientMetrics To Be Final #51

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions src/main/java/com/uber/rss/clients/DataBlockSyncWriteClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class DataBlockSyncWriteClient extends com.uber.rss.clients.ClientBase {
private long totalWriteBytes = 0;
private long startUploadShuffleByteSnapshot = 0;

private WriteClientMetrics metrics = null;
private final WriteClientMetrics metrics;

public DataBlockSyncWriteClient(String host, int port, int timeoutMillis, String user, String appId, String appAttempt) {
this(host, port, timeoutMillis, true, user, appId, appAttempt);
Expand All @@ -66,7 +66,7 @@ public DataBlockSyncWriteClient(String host, int port, int timeoutMillis, boolea

this.metrics = new WriteClientMetrics(new WriteClientMetricsKey(
this.getClass().getSimpleName(), user));
metrics.getNumClients().inc(1);
this.metrics.getNumClients().inc(1);
}

public ConnectUploadResponse connect() {
Expand Down Expand Up @@ -171,22 +171,15 @@ public void finishUpload(long taskAttemptId) {
@Override
public void close() {
super.close();
closeMetrics();
}

public long getShuffleWriteBytes() {
return totalWriteBytes - startUploadShuffleByteSnapshot;
}

private void closeMetrics() {
try {
if (metrics != null) {
metrics.close();
metrics = null;
}
} catch (Throwable e) {
M3Stats.addException(e, this.getClass().getSimpleName());
logger.warn(String.format("Failed to close metrics: %s", connectionInfo), e);
logger.warn("Failed to close metrics: {}", connectionInfo, e);
}
}

public long getShuffleWriteBytes() {
return totalWriteBytes - startUploadShuffleByteSnapshot;
}
}