bbeaudreault commented on code in PR #5192:
URL: https://github.com/apache/hbase/pull/5192#discussion_r1181563492
##########
hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/RpcThrottlingException.java:
##########
@@ -130,29 +129,55 @@ 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 long timeFromString(String timeDiff) {
- Pattern[] patterns = new Pattern[] {
Pattern.compile("^(\\d+\\.\\d\\d)sec"),
- Pattern.compile("^(\\d+)mins, (\\d+\\.\\d\\d)sec"),
- Pattern.compile("^(\\d+)hrs, (\\d+)mins, (\\d+\\.\\d\\d)sec") };
+ // Visible for TestRpcThrottlingException
+ protected static String stringFromMillis(long millis) {
+ StringBuilder buf = new StringBuilder();
+ long hours = millis / (60 * 60 * 1000);
+ long rem = (millis % (60 * 60 * 1000));
+ long minutes = rem / (60 * 1000);
+ rem = rem % (60 * 1000);
+ long seconds = rem / 1000;
+ long milliseconds = rem % 1000;
- for (int i = 0; i < patterns.length; ++i) {
- Matcher m = patterns[i].matcher(timeDiff);
- if (m.find()) {
- long time = Math.round(Float.parseFloat(m.group(1 + i)) * 1000);
- if (i > 0) {
- time += Long.parseLong(m.group(i)) * (60 * 1000);
- }
- if (i > 1) {
- time += Long.parseLong(m.group(i - 1)) * (60 * 60 * 1000);
+ if (hours != 0) {
+ buf.append(hours);
+ buf.append("hrs, ");
Review Comment:
Since we have our own formatted here now, can you appease my perfectionism
and only add the s to these if > 1? In terms of parsing you'll just add `?`
after each s in the regex.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]