dlmarion commented on code in PR #6041:
URL: https://github.com/apache/accumulo/pull/6041#discussion_r2672323169
##########
server/tserver/src/main/java/org/apache/accumulo/tserver/TabletClientHandler.java:
##########
@@ -447,15 +449,15 @@ private void flush(UpdateSession us) {
us.totalUpdates += mutationCount;
}
- private void updateAverageLockTime(long time, TimeUnit unit, int size) {
+ private void updateAverageLockTime(Duration duration, int size) {
if (size > 0) {
- server.updateMetrics.addLockTime((long) (time / (double) size), unit);
+ server.updateMetrics.addLockTime(duration.dividedBy(size));
Review Comment:
If you reverted the changes to `TabletServerUpdateMetrics`, then you could
do something like the following here:
```
server.updateMetrics.addLockTime(duration.toNanos() / size,
TimeUnit.NANOSECONDS);
```
##########
test/src/main/java/org/apache/accumulo/test/util/Wait.java:
##########
@@ -103,14 +106,14 @@ public static void waitFor(final Condition condition,
final long duration, final
final String failMessage) {
final int timeoutFactor = getTimeoutFactor(e -> 1); // default to factor
of 1
- final long scaledDurationNanos = MILLISECONDS.toNanos(duration) *
timeoutFactor;
+ final Duration scaledDuration =
Duration.ofMillis(duration).multipliedBy(timeoutFactor);
Review Comment:
Might be able to get rid of the call to `multipliedBy` here and just
multiply `duration` and `timeoutFactor`.
##########
minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java:
##########
@@ -804,9 +805,9 @@ public Configuration getConfiguration(TableId tableId) {
// wait up to 10 seconds for the process to start
private static void waitForProcessStart(Process p, String name) throws
InterruptedException {
- long start = System.nanoTime();
+ Timer waitTimer = Timer.startNew();
while (p.info().startInstant().isEmpty()) {
- if (NANOSECONDS.toSeconds(System.nanoTime() - start) > 10) {
+ if (waitTimer.hasElapsed(Duration.ofSeconds(10))) {
Review Comment:
`Duration.ofSeconds` can probably be moved up and out of the loop.
##########
core/src/main/java/org/apache/accumulo/core/clientImpl/ThriftTransportPool.java:
##########
@@ -84,18 +86,21 @@ private ThriftTransportPool(LongSupplier maxAgeMillis,
boolean shouldHalt) {
private Runnable thriftConnectionPoolChecker() {
return () -> {
try {
- final long minNanos = MILLISECONDS.toNanos(250);
- final long maxNanos = MINUTES.toNanos(1);
- long lastRun = System.nanoTime();
+ final Duration minInterval = Duration.ofMillis(250);
+ final Duration maxInterval = Duration.ofMinutes(1);
+ Timer lastRunTimer = Timer.startNew();
// loop often, to detect shutdowns quickly
while (!connectionPool.awaitShutdown(250)) {
// don't close on every loop; instead, check based on configured max
age, within bounds
- var threshold = Math.min(maxNanos,
- Math.max(minNanos,
MILLISECONDS.toNanos(maxAgeMillis.getAsLong()) / 2));
- long currentNanos = System.nanoTime();
- if ((currentNanos - lastRun) >= threshold) {
+ Duration threshold =
Duration.ofMillis(maxAgeMillis.getAsLong()).dividedBy(2);
Review Comment:
```suggestion
Duration threshold = Duration.ofMillis(maxAgeMillis.getAsLong() /
2);
```
If you look into the source of
[Duration.dividedBy](https://github.com/openjdk/jdk/blob/jdk-11%2B28/src/java.base/share/classes/java/time/Duration.java#L989)
it's doing validation and creating BigDecimal objects. We know the divisor
value here, it's static and not zero. I think we should just do the simple math
here instead of calling `dividedBy`.
--
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]