rmdmattingly commented on code in PR #5192:
URL: https://github.com/apache/hbase/pull/5192#discussion_r1184463609
##########
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(hours > 1 ? "hrs, " : "hr, ");
+ }
+ if (minutes != 0) {
+ buf.append(minutes);
+ buf.append(minutes > 1 ? "mins, " : "min, ");
+ }
+ if (seconds != 0) {
+ buf.append(seconds);
+ buf.append("sec, ");
+ }
+ buf.append(milliseconds);
+ buf.append("ms");
+ return buf.toString();
+ }
+
+ // Visible for TestRpcThrottlingException
+ protected static long timeFromString(String timeDiff) {
+ Pattern pattern =
+ Pattern.compile("^(?:(\\d+)hrs?, )?(?:(\\d+)mins?, )?(?:(\\d+)sec[,
]{0,2})?(?:(\\d+)ms)?");
Review Comment:
Discussed offline, the existing regex is actually suitable and we added some
more test cases to enforce that
--
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]