Skip to content
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

HBASE-23373 Log RetriesExhaustedException context with full time precision (#903) #918

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
package org.apache.hadoop.hbase.client;

import java.io.IOException;
import java.util.Date;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.StringJoiner;

import org.apache.commons.lang3.StringUtils;
import org.apache.yetus.audience.InterfaceAudience;

/**
Expand All @@ -41,24 +44,34 @@ public RetriesExhaustedException(final String msg, final IOException e) {
}

/**
* Datastructure that allows adding more info around Throwable incident.
* Data structure that allows adding more info around Throwable incident.
*/
@InterfaceAudience.Private
public static class ThrowableWithExtraContext {
private final Throwable t;
private final long when;
private final Throwable throwable;
private final long whenAsEpochMilli;
private final String extras;

public ThrowableWithExtraContext(final Throwable t, final long when,
public ThrowableWithExtraContext(final Throwable throwable, final long whenAsEpochMilli,
final String extras) {
this.t = t;
this.when = when;
this.throwable = throwable;
this.whenAsEpochMilli = whenAsEpochMilli;
this.extras = extras;
}

@Override
public String toString() {
return new Date(this.when).toString() + ", " + extras + ", " + t.toString();
final StringJoiner joiner = new StringJoiner(", ");
if (whenAsEpochMilli != 0) {
joiner.add(DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(whenAsEpochMilli)));
}
if (StringUtils.isNotEmpty(extras)) {
joiner.add(extras);
}
if (throwable != null) {
joiner.add(throwable.toString());
}
return joiner.toString();
}
}

Expand All @@ -83,7 +96,7 @@ public RetriesExhaustedException(final String callableVitals, int numTries,
public RetriesExhaustedException(final int numRetries,
final List<ThrowableWithExtraContext> exceptions) {
super(getMessage(numRetries, exceptions),
exceptions.isEmpty()? null: exceptions.get(exceptions.size() - 1).t);
exceptions.isEmpty()? null: exceptions.get(exceptions.size() - 1).throwable);
}

private static String getMessage(String callableVitals, int numTries,
Expand Down