From 4a99186c901f026d04eeb69ed56d899913bfe92f Mon Sep 17 00:00:00 2001 From: Arpit Bandejiya Date: Thu, 14 Mar 2024 15:41:39 +0530 Subject: [PATCH] Address review comments Signed-off-by: Arpit Bandejiya --- .../admin/cluster/node/stats/NodeStats.java | 2 +- .../cluster/stats/ClusterStatsNodes.java | 49 +++++++++--------- .../recovery/PeerRecoverySourceService.java | 1 + .../indices/recovery/PeerRecoveryStats.java | 27 ++++++---- .../recovery/PeerRecoveryStatsTracker.java | 50 +++++++++---------- .../StatsAwareReplicationCollection.java | 10 ++-- 6 files changed, 73 insertions(+), 66 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/node/stats/NodeStats.java b/server/src/main/java/org/opensearch/action/admin/cluster/node/stats/NodeStats.java index 078010b7d93d0..27f7bee2c9e0e 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/node/stats/NodeStats.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/node/stats/NodeStats.java @@ -239,7 +239,7 @@ public NodeStats(StreamInput in) throws IOException { admissionControlStats = null; } - if (in.getVersion().onOrAfter(Version.V_2_13_0)) { + if (in.getVersion().onOrAfter(Version.CURRENT)) { peerRecoveryStats = in.readOptionalWriteable(PeerRecoveryStats::new); } else { peerRecoveryStats = null; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsNodes.java b/server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsNodes.java index a8b7181f20566..8565074534b12 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsNodes.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsNodes.java @@ -49,7 +49,6 @@ import org.opensearch.core.xcontent.ToXContentFragment; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.discovery.DiscoveryModule; -import org.opensearch.indices.recovery.PeerRecoveryStats; import org.opensearch.monitor.fs.FsInfo; import org.opensearch.monitor.jvm.JvmInfo; import org.opensearch.monitor.os.OsInfo; @@ -861,40 +860,42 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa static class PeerRecoveryStats implements ToXContentFragment { - private long total_started_recoveries; - private long total_failed_recoveries; - private long total_completed_recoveries; - private long total_retried_recoveries; - private long total_cancelled_recoveries; - - private static final String TotalStartedRecoveries = "total_started_recoveries"; - private static final String TotalFailedRecoveries = "total_failed_recoveries"; - private static final String TotalCompletedRecoveries = "total_completed_recoveries"; - private static final String TotalRetriedRecoveries = "total_retried_recoveries"; - private static final String TotalCancelledRecoveries = "total_cancelled_recoveries"; + private long totalStartedRecoveries; + private long totalFailedRecoveries; + private long totalCompletedRecoveries; + private long totalRetriedRecoveries; + private long totalCancelledRecoveries; PeerRecoveryStats(List nodeStats) { for (NodeStats nodeStat : nodeStats) { if (nodeStat.getPeerRecoveryStats() != null) { - total_started_recoveries += nodeStat.getPeerRecoveryStats().getTotalStartedRecoveries(); - total_failed_recoveries += nodeStat.getPeerRecoveryStats().getTotalFailedRecoveries(); - total_completed_recoveries += nodeStat.getPeerRecoveryStats().getTotalCompletedRecoveries(); - total_retried_recoveries += nodeStat.getPeerRecoveryStats().getTotalRetriedRecoveries(); - total_cancelled_recoveries += nodeStat.getPeerRecoveryStats().getTotalCancelledRecoveries(); + totalStartedRecoveries += nodeStat.getPeerRecoveryStats().getTotalStartedRecoveries(); + totalFailedRecoveries += nodeStat.getPeerRecoveryStats().getTotalFailedRecoveries(); + totalCompletedRecoveries += nodeStat.getPeerRecoveryStats().getTotalCompletedRecoveries(); + totalRetriedRecoveries += nodeStat.getPeerRecoveryStats().getTotalRetriedRecoveries(); + totalCancelledRecoveries += nodeStat.getPeerRecoveryStats().getTotalCancelledRecoveries(); } } } + public static final class Fields { + static final String PEER_RECOVERY_STATS = "peer_recovery_stats"; + static final String TOTAL_STARTED_RECOVERIES = "total_started_recoveries"; + static final String TOTAL_FAILED_RECOVERIES = "total_failed_recoveries"; + static final String TOTAL_COMPLETED_RECOVERIES = "total_completed_recoveries"; + static final String TOTAL_RETRIED_RECOVERIES = "total_retried_recoveries"; + static final String TOTAL_CANCELLED_RECOVERIES = "total_cancelled_recoveries"; + } + @Override public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { - builder.startObject("peer_recovery_stats"); + builder.startObject(Fields.PEER_RECOVERY_STATS); { - builder.field(TotalStartedRecoveries, total_started_recoveries); - builder.field(TotalFailedRecoveries, total_failed_recoveries); - builder.field(TotalCompletedRecoveries, total_completed_recoveries); - builder.field(TotalRetriedRecoveries, total_retried_recoveries); - builder.field(TotalCancelledRecoveries, total_cancelled_recoveries); - + builder.field(Fields.TOTAL_STARTED_RECOVERIES, totalStartedRecoveries); + builder.field(Fields.TOTAL_FAILED_RECOVERIES, totalFailedRecoveries); + builder.field(Fields.TOTAL_COMPLETED_RECOVERIES, totalCompletedRecoveries); + builder.field(Fields.TOTAL_RETRIED_RECOVERIES, totalRetriedRecoveries); + builder.field(Fields.TOTAL_CANCELLED_RECOVERIES, totalCancelledRecoveries); } builder.endObject(); return builder; diff --git a/server/src/main/java/org/opensearch/indices/recovery/PeerRecoverySourceService.java b/server/src/main/java/org/opensearch/indices/recovery/PeerRecoverySourceService.java index 43af8485e2631..cb2bedf00de99 100644 --- a/server/src/main/java/org/opensearch/indices/recovery/PeerRecoverySourceService.java +++ b/server/src/main/java/org/opensearch/indices/recovery/PeerRecoverySourceService.java @@ -165,6 +165,7 @@ private void recover(StartRecoveryRequest request, ActionListener