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-27799: RpcThrottlingException wait interval message is misleading between 0-1s #5192

Merged
merged 11 commits into from
May 4, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,19 @@ public static void throwWriteCapacityUnitExceeded(final long waitInterval)

private static void throwThrottlingException(final Type type, final long waitInterval)
throws RpcThrottlingException {
String msg = MSG_TYPE[type.ordinal()] + MSG_WAIT + StringUtils.formatTime(waitInterval);
String msg = MSG_TYPE[type.ordinal()] + MSG_WAIT + stringFromMillis(waitInterval);
throw new RpcThrottlingException(type, waitInterval, msg);
}

private static String stringFromMillis(long millis) {
if (millis >= 1000) {
return StringUtils.formatTime(millis);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I realize this will continue to be misleading for values greater than 1s. For example 1.9s is almost double what would be shown by formatTime. It matters less for values in the 10s of seconds or higher, but I think it will be very common to have values mostly in the single digit seconds.

We could copy the impl of formatTime here and add ms, or use the existing formatTime and append a ms part, or look for a different "humanize" method/library (as long as it's already a dep)

} else {
// StringUtils#formatTime doesn't support millis
return millis + "ms";
}
}

private static long timeFromString(String timeDiff) {
Pattern[] patterns = new Pattern[] { Pattern.compile("^(\\d+\\.\\d\\d)sec"),
Pattern.compile("^(\\d+)mins, (\\d+\\.\\d\\d)sec"),
Expand Down