From 542d70941e69922e40f9a8883aa25da06a23d41b Mon Sep 17 00:00:00 2001 From: Himshikha Gupta Date: Tue, 24 Sep 2024 15:15:54 +0530 Subject: [PATCH] addressing comments Signed-off-by: Himshikha Gupta --- .../gateway/remote/ClusterStateChecksum.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/org/opensearch/gateway/remote/ClusterStateChecksum.java b/server/src/main/java/org/opensearch/gateway/remote/ClusterStateChecksum.java index 62e8ba7944f3a..7f97dd7ee1a3d 100644 --- a/server/src/main/java/org/opensearch/gateway/remote/ClusterStateChecksum.java +++ b/server/src/main/java/org/opensearch/gateway/remote/ClusterStateChecksum.java @@ -14,6 +14,7 @@ import org.opensearch.cluster.metadata.DiffableStringMap; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.settings.Settings; +import org.opensearch.common.unit.TimeValue; import org.opensearch.core.common.io.stream.BufferedChecksumStreamOutput; import org.opensearch.core.common.io.stream.StreamInput; import org.opensearch.core.common.io.stream.StreamOutput; @@ -30,7 +31,6 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.function.Function; @@ -73,7 +73,7 @@ public class ClusterStateChecksum implements ToXContentFragment, Writeable { long clusterStateChecksum; public ClusterStateChecksum(ClusterState clusterState) { - long start = System.currentTimeMillis(); + long start = System.nanoTime(); // keeping thread pool size to number of components. ExecutorService executorService = Executors.newFixedThreadPool(COMPONENT_SIZE); CountDownLatch latch = new CountDownLatch(COMPONENT_SIZE); @@ -187,16 +187,21 @@ public ClusterStateChecksum(ClusterState clusterState) { throw new RemoteStateTransferException("Failed to create checksum for cluster state.", e); } createClusterStateChecksum(); - logger.debug("Checksum execution time {}", System.currentTimeMillis() - start); + logger.debug("Checksum execution time {}", TimeValue.nsecToMSec(System.nanoTime() - start)); } - private void executeChecksumTask(Function checksumTask, Consumer checksumConsumer, ExecutorService executorService, CountDownLatch latch) { + private void executeChecksumTask( + Function checksumTask, + Consumer checksumConsumer, + ExecutorService executorService, + CountDownLatch latch + ) { executorService.execute(() -> { try { long checksum = createChecksum(checksumTask); checksumConsumer.accept(checksum); latch.countDown(); - } catch (IOException e) { + } catch (IOException e) { throw new RemoteStateTransferException("Failed to execute checksum task", e); } });