From b84c184853609b88a2d5f5a95a236425f5104426 Mon Sep 17 00:00:00 2001 From: Poojita Raj Date: Tue, 17 May 2022 11:11:03 -0700 Subject: [PATCH] review changes Signed-off-by: Poojita Raj --- .../cluster/IndicesClusterStateService.java | 18 ++++++------------ .../indices/recovery/RecoveriesCollection.java | 2 +- .../indices/recovery/RecoveryListener.java | 9 +-------- .../replication/common/ReplicationTarget.java | 4 +++- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/server/src/main/java/org/opensearch/indices/cluster/IndicesClusterStateService.java b/server/src/main/java/org/opensearch/indices/cluster/IndicesClusterStateService.java index b2a4d93636ab1..d1623df156593 100644 --- a/server/src/main/java/org/opensearch/indices/cluster/IndicesClusterStateService.java +++ b/server/src/main/java/org/opensearch/indices/cluster/IndicesClusterStateService.java @@ -80,6 +80,7 @@ import org.opensearch.indices.recovery.PeerRecoveryTargetService; import org.opensearch.indices.recovery.RecoveryListener; import org.opensearch.indices.recovery.RecoveryState; +import org.opensearch.indices.replication.common.ReplicationState; import org.opensearch.repositories.RepositoriesService; import org.opensearch.search.SearchService; import org.opensearch.snapshots.SnapshotShardsService; @@ -204,18 +205,6 @@ public IndicesClusterStateService( this.sendRefreshMapping = settings.getAsBoolean("indices.cluster.send_refresh_mapping", true); } - public ShardStateAction getShardStateAction() { - return shardStateAction; - } - - public ClusterService getClusterService() { - return clusterService; - } - - public ActionListener getShardStateActionListener() { - return SHARD_STATE_ACTION_LISTENER; - } - @Override protected void doStart() { // Doesn't make sense to manage shards on non-master and non-data nodes @@ -756,6 +745,11 @@ public synchronized void handleRecoveryFailure(ShardRouting shardRouting, boolea failAndRemoveShard(shardRouting, sendShardFailure, "failed recovery", failure, clusterService.state()); } + public void handleRecoveryDone(ReplicationState state, ShardRouting shardRouting, long primaryTerm) { + RecoveryState RecState = (RecoveryState) state; + shardStateAction.shardStarted(shardRouting, primaryTerm, "after " + RecState.getRecoverySource(), SHARD_STATE_ACTION_LISTENER); + } + private void failAndRemoveShard( ShardRouting shardRouting, boolean sendShardFailure, diff --git a/server/src/main/java/org/opensearch/indices/recovery/RecoveriesCollection.java b/server/src/main/java/org/opensearch/indices/recovery/RecoveriesCollection.java index 3e5ab94c317da..26e9edb842614 100644 --- a/server/src/main/java/org/opensearch/indices/recovery/RecoveriesCollection.java +++ b/server/src/main/java/org/opensearch/indices/recovery/RecoveriesCollection.java @@ -85,7 +85,7 @@ public long startRecovery(IndexShard indexShard, DiscoveryNode sourceNode, Repli private void startRecoveryInternal(RecoveryTarget recoveryTarget, TimeValue activityTimeout) { RecoveryTarget existingTarget = onGoingRecoveries.putIfAbsent(recoveryTarget.getId(), recoveryTarget); - assert existingTarget == null : "found two RecoveryStatus instances with the same id"; + assert existingTarget == null : "found two RecoveryTarget instances with the same id"; logger.trace( "{} started recovery from {}, id [{}]", recoveryTarget.indexShard().shardId(), diff --git a/server/src/main/java/org/opensearch/indices/recovery/RecoveryListener.java b/server/src/main/java/org/opensearch/indices/recovery/RecoveryListener.java index bc2fb8eec0050..b93c054ffa4bf 100644 --- a/server/src/main/java/org/opensearch/indices/recovery/RecoveryListener.java +++ b/server/src/main/java/org/opensearch/indices/recovery/RecoveryListener.java @@ -45,14 +45,7 @@ public RecoveryListener( @Override public void onDone(ReplicationState state) { - RecoveryState RecState = (RecoveryState) state; - indicesClusterStateService.getShardStateAction() - .shardStarted( - shardRouting, - primaryTerm, - "after " + RecState.getRecoverySource(), - indicesClusterStateService.getShardStateActionListener() - ); + indicesClusterStateService.handleRecoveryDone(state, shardRouting, primaryTerm); } @Override diff --git a/server/src/main/java/org/opensearch/indices/replication/common/ReplicationTarget.java b/server/src/main/java/org/opensearch/indices/replication/common/ReplicationTarget.java index 5e0ce9f10a1a4..1accfc0a2b6f9 100644 --- a/server/src/main/java/org/opensearch/indices/replication/common/ReplicationTarget.java +++ b/server/src/main/java/org/opensearch/indices/replication/common/ReplicationTarget.java @@ -171,7 +171,9 @@ public void fail(OpenSearchException e, boolean sendShardFailure) { protected void ensureRefCount() { if (refCount() <= 0) { - throw new OpenSearchException("RecoveryStatus is used but it's refcount is 0. Probably a mismatch between incRef/decRef calls"); + throw new OpenSearchException( + "ReplicationTarget is used but it's refcount is 0. Probably a mismatch between incRef/decRef calls" + ); } }