bbeaudreault commented on code in PR #5192:
URL: https://github.com/apache/hbase/pull/5192#discussion_r1178405138
##########
hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/RpcThrottlingException.java:
##########
@@ -130,29 +129,64 @@ 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;
+ if (hours != 0) {
+ buf.append(hours);
+ buf.append("hrs, ");
+ }
+ if (minutes != 0) {
+ buf.append(minutes);
+ buf.append("mins, ");
+ }
+ 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[] patterns = new Pattern[] { Pattern.compile("^(\\d+)ms"),
+ Pattern.compile("^(\\d+)sec, (\\d+)ms"), Pattern.compile("^(\\d+)mins,
(\\d+)sec, (\\d+)ms"),
Review Comment:
The last thing I'd say here is that the original approach here seems like
someone who doesn't know regex. It seems like we could make this use just one
pattern by just wrapping the individual components with `(?:)?`. I.e.
`(?:(\\d)sec, )?`
Thoughts? Probably would be faster than having to run up to 6 matches
--
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]