rmdmattingly commented on code in PR #5192:
URL: https://github.com/apache/hbase/pull/5192#discussion_r1178264992
##########
hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/RpcThrottlingException.java:
##########
@@ -159,20 +160,33 @@ private static String stringFromMillis(long millis) {
return buf.toString();
}
- 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 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"),
+ Pattern.compile("^(\\d+)hrs, (\\d+)mins, (\\d+)sec, (\\d+)ms"), };
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 == 0) {
+ return Math.round(Float.parseFloat(m.group(1))); // ms
}
- if (i > 1) {
- time += Long.parseLong(m.group(i - 1)) * (60 * 60 * 1000);
+ long time = 0;
+ if (i == 1) {
+ time += Math.round(Float.parseFloat(m.group(1)) * 1000); // sec
+ time += Math.round(Float.parseFloat(m.group(2))); // ms
+ }
+ if (i == 2) {
+ time += Math.round(Float.parseFloat(m.group(1)) * 60 * 1000); // mins
+ time += Math.round(Float.parseFloat(m.group(2)) * 1000); // sec
+ time += Math.round(Float.parseFloat(m.group(3))); // ms
+ }
+ if (i == 3) {
+ time += Math.round(Float.parseFloat(m.group(1)) * 60 * 60 * 1000);
// hrs
+ time += Math.round(Float.parseFloat(m.group(2)) * 60 * 1000); // mins
+ time += Math.round(Float.parseFloat(m.group(3)) * 1000); // sec
+ time += Math.round(Float.parseFloat(m.group(4))); // ms
}
Review Comment:
admittedly we could clean this up a bit via some sort of loop, but I think
the initial implementation suffered from trying to be a little too clever and
this both works and is straightforward imo
--
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]