Skip to content

Commit

Permalink
addressing comments
Browse files Browse the repository at this point in the history
Signed-off-by: Himshikha Gupta <himshikh@amazon.com>
  • Loading branch information
Himshikha Gupta committed Sep 24, 2024
1 parent 1b5edaa commit 542d709
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<BufferedChecksumStreamOutput, Void> checksumTask, Consumer<Long> checksumConsumer, ExecutorService executorService, CountDownLatch latch) {
private void executeChecksumTask(
Function<BufferedChecksumStreamOutput, Void> checksumTask,
Consumer<Long> 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);
}
});
Expand Down

0 comments on commit 542d709

Please sign in to comment.