-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not fail replica shard due to primary closure #4133
Merged
+205
−18
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
server/src/main/java/org/opensearch/index/shard/PrimaryShardClosedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.index.shard; | ||
|
||
import java.io.IOException; | ||
|
||
import org.opensearch.common.io.stream.StreamInput; | ||
|
||
/** | ||
* Exception to indicate failures are caused due to the closure of the primary | ||
* shard. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class PrimaryShardClosedException extends IndexShardClosedException { | ||
public PrimaryShardClosedException(ShardId shardId) { | ||
super(shardId, "Primary closed"); | ||
} | ||
|
||
public PrimaryShardClosedException(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
|
||
package org.opensearch.action.support.replication; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.opensearch.OpenSearchException; | ||
import org.opensearch.action.ActionListener; | ||
import org.opensearch.action.support.ActionFilters; | ||
|
@@ -57,6 +58,7 @@ | |
import org.opensearch.index.IndexService; | ||
import org.opensearch.index.IndexingPressureService; | ||
import org.opensearch.index.shard.IndexShard; | ||
import org.opensearch.index.shard.PrimaryShardClosedException; | ||
import org.opensearch.index.shard.ShardId; | ||
import org.opensearch.index.shard.ShardNotFoundException; | ||
import org.opensearch.index.translog.Translog; | ||
|
@@ -91,6 +93,7 @@ | |
import java.util.stream.Collectors; | ||
|
||
import static java.util.Collections.emptyMap; | ||
import static org.hamcrest.Matchers.emptyArray; | ||
import static org.opensearch.test.ClusterServiceUtils.createClusterService; | ||
import static org.hamcrest.Matchers.arrayWithSize; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
@@ -395,6 +398,48 @@ public void testReplicaProxy() throws InterruptedException, ExecutionException { | |
} | ||
} | ||
|
||
public void testPrimaryClosedDoesNotFailShard() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not add a test in corruptionIT as well and ensure that the cluster is green after some time? |
||
final CapturingTransport transport = new CapturingTransport(); | ||
final TransportService transportService = transport.createTransportService( | ||
clusterService.getSettings(), | ||
threadPool, | ||
TransportService.NOOP_TRANSPORT_INTERCEPTOR, | ||
x -> clusterService.localNode(), | ||
null, | ||
Collections.emptySet() | ||
); | ||
transportService.start(); | ||
transportService.acceptIncomingRequests(); | ||
final ShardStateAction shardStateAction = new ShardStateAction(clusterService, transportService, null, null, threadPool); | ||
final TestAction action = new TestAction( | ||
Settings.EMPTY, | ||
"internal:testAction", | ||
transportService, | ||
clusterService, | ||
shardStateAction, | ||
threadPool | ||
); | ||
final String index = "test"; | ||
final ShardId shardId = new ShardId(index, "_na_", 0); | ||
final ClusterState state = ClusterStateCreationUtils.stateWithActivePrimary(index, true, 1, 0); | ||
ClusterServiceUtils.setState(clusterService, state); | ||
final long primaryTerm = state.metadata().index(index).primaryTerm(0); | ||
final ShardRouting shardRouting = state.routingTable().shardRoutingTable(shardId).replicaShards().get(0); | ||
|
||
// Assert that failShardIfNeeded is a no-op for the PrimaryShardClosedException failure | ||
final AtomicInteger callbackCount = new AtomicInteger(0); | ||
action.newReplicasProxy() | ||
.failShardIfNeeded( | ||
shardRouting, | ||
primaryTerm, | ||
"test", | ||
new PrimaryShardClosedException(shardId), | ||
ActionListener.wrap(callbackCount::incrementAndGet) | ||
); | ||
MatcherAssert.assertThat(transport.getCapturedRequestsAndClear(), emptyArray()); | ||
MatcherAssert.assertThat(callbackCount.get(), equalTo(0)); | ||
} | ||
|
||
private class TestAction extends TransportWriteAction<TestRequest, TestRequest, TestResponse> { | ||
|
||
private final boolean withDocumentFailureOnPrimary; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my understanding, I am guessing we would not successfully ack back request to the client and eventually the replica copy would get promoted to primary and the request subsequently retried on the newly promoted copy.
Can we add an integration test in ClusterDisruptionIT to verify this behaviour?