-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Avoid sending duplicate remote failed shard requests #31313
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
99562c0
TEST: getCapturedRequestsAndClear should be atomic
dnhatn 251d44c
Avoid sending duplicate remote failed shard requests
dnhatn 71a2db4
Merge branch 'master' into cache-remote-shards-failed
dnhatn 6a704c7
Simplify report
dnhatn 7601a13
Remove identity map
dnhatn 19baf31
Revert "TEST: getCapturedRequestsAndClear should be atomic"
dnhatn dcdaba7
Merge branch 'master' into cache-remote-shards-failed
dnhatn a102531
Address Yannick’s comments
dnhatn 56da910
Merge branch 'master' into cache-remote-shards-failed
dnhatn 496a6bd
Randomize primary term
dnhatn 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,11 @@ | |
import com.carrotsearch.hppc.cursors.ObjectCursor; | ||
import org.apache.lucene.index.CorruptIndexException; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.action.shard.ShardStateAction.FailedShardEntry; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.ClusterStateTaskExecutor; | ||
import org.elasticsearch.cluster.ESAllocationTestCase; | ||
import org.elasticsearch.cluster.action.shard.ShardStateAction.FailedShardEntry; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
|
@@ -43,6 +43,7 @@ | |
import org.elasticsearch.cluster.routing.allocation.StaleShard; | ||
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider; | ||
import org.elasticsearch.common.UUIDs; | ||
import org.elasticsearch.common.collect.Tuple; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.set.Sets; | ||
import org.elasticsearch.index.Index; | ||
|
@@ -53,9 +54,7 @@ | |
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
|
@@ -131,9 +130,14 @@ ClusterState applyFailedShards(ClusterState currentState, List<FailedShard> fail | |
tasks.addAll(failingTasks); | ||
tasks.addAll(nonExistentTasks); | ||
ClusterStateTaskExecutor.ClusterTasksResult<FailedShardEntry> result = failingExecutor.execute(currentState, tasks); | ||
Map<FailedShardEntry, ClusterStateTaskExecutor.TaskResult> taskResultMap = | ||
failingTasks.stream().collect(Collectors.toMap(Function.identity(), task -> ClusterStateTaskExecutor.TaskResult.failure(new RuntimeException("simulated applyFailedShards failure")))); | ||
taskResultMap.putAll(nonExistentTasks.stream().collect(Collectors.toMap(Function.identity(), task -> ClusterStateTaskExecutor.TaskResult.success()))); | ||
List<Tuple<FailedShardEntry, ClusterStateTaskExecutor.TaskResult>> taskResultMap = new ArrayList<>(); | ||
for (FailedShardEntry failingTask : failingTasks) { | ||
taskResultMap.add(Tuple.tuple(failingTask, | ||
ClusterStateTaskExecutor.TaskResult.failure(new RuntimeException("simulated applyFailedShards failure")))); | ||
} | ||
for (FailedShardEntry nonExistentTask : nonExistentTasks) { | ||
taskResultMap.add(Tuple.tuple(nonExistentTask, ClusterStateTaskExecutor.TaskResult.success())); | ||
} | ||
assertTaskResults(taskResultMap, result, currentState, false); | ||
} | ||
|
||
|
@@ -147,12 +151,12 @@ public void testIllegalShardFailureRequests() throws Exception { | |
tasks.add(new FailedShardEntry(failingTask.shardId, failingTask.allocationId, | ||
randomIntBetween(1, (int) primaryTerm - 1), failingTask.message, failingTask.failure, randomBoolean())); | ||
} | ||
Map<FailedShardEntry, ClusterStateTaskExecutor.TaskResult> taskResultMap = | ||
tasks.stream().collect(Collectors.toMap( | ||
Function.identity(), | ||
task -> ClusterStateTaskExecutor.TaskResult.failure(new ShardStateAction.NoLongerPrimaryShardException(task.shardId, | ||
"primary term [" + task.primaryTerm + "] did not match current primary term [" + | ||
currentState.metaData().index(task.shardId.getIndex()).primaryTerm(task.shardId.id()) + "]")))); | ||
List<Tuple<FailedShardEntry, ClusterStateTaskExecutor.TaskResult>> taskResultMap = tasks.stream() | ||
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. same here (taskResultList) |
||
.map(task -> Tuple.tuple(task, ClusterStateTaskExecutor.TaskResult.failure( | ||
new ShardStateAction.NoLongerPrimaryShardException(task.shardId, "primary term [" | ||
+ task.primaryTerm + "] did not match current primary term [" | ||
+ currentState.metaData().index(task.shardId.getIndex()).primaryTerm(task.shardId.id()) + "]")))) | ||
.collect(Collectors.toList()); | ||
ClusterStateTaskExecutor.ClusterTasksResult<FailedShardEntry> result = executor.execute(currentState, tasks); | ||
assertTaskResults(taskResultMap, result, currentState, false); | ||
} | ||
|
@@ -251,44 +255,44 @@ private static void assertTasksSuccessful( | |
ClusterState clusterState, | ||
boolean clusterStateChanged | ||
) { | ||
Map<ShardStateAction.FailedShardEntry, ClusterStateTaskExecutor.TaskResult> taskResultMap = | ||
tasks.stream().collect(Collectors.toMap(Function.identity(), task -> ClusterStateTaskExecutor.TaskResult.success())); | ||
List<Tuple<FailedShardEntry, ClusterStateTaskExecutor.TaskResult>> taskResultMap = tasks.stream() | ||
.map(t -> Tuple.tuple(t, ClusterStateTaskExecutor.TaskResult.success())).collect(Collectors.toList()); | ||
assertTaskResults(taskResultMap, result, clusterState, clusterStateChanged); | ||
} | ||
|
||
private static void assertTaskResults( | ||
Map<ShardStateAction.FailedShardEntry, ClusterStateTaskExecutor.TaskResult> taskResultMap, | ||
List<Tuple<ShardStateAction.FailedShardEntry, ClusterStateTaskExecutor.TaskResult>> taskResultMap, | ||
ClusterStateTaskExecutor.ClusterTasksResult<ShardStateAction.FailedShardEntry> result, | ||
ClusterState clusterState, | ||
boolean clusterStateChanged | ||
) { | ||
// there should be as many task results as tasks | ||
assertEquals(taskResultMap.size(), result.executionResults.size()); | ||
|
||
for (Map.Entry<ShardStateAction.FailedShardEntry, ClusterStateTaskExecutor.TaskResult> entry : taskResultMap.entrySet()) { | ||
for (Tuple<FailedShardEntry, ClusterStateTaskExecutor.TaskResult> entry : taskResultMap) { | ||
// every task should have a corresponding task result | ||
assertTrue(result.executionResults.containsKey(entry.getKey())); | ||
assertTrue(result.executionResults.containsKey(entry.v1())); | ||
|
||
// the task results are as expected | ||
assertEquals(entry.getKey().toString(), entry.getValue().isSuccess(), result.executionResults.get(entry.getKey()).isSuccess()); | ||
assertEquals(entry.v1().toString(), entry.v2().isSuccess(), result.executionResults.get(entry.v1()).isSuccess()); | ||
} | ||
|
||
List<ShardRouting> shards = clusterState.getRoutingTable().allShards(); | ||
for (Map.Entry<ShardStateAction.FailedShardEntry, ClusterStateTaskExecutor.TaskResult> entry : taskResultMap.entrySet()) { | ||
if (entry.getValue().isSuccess()) { | ||
for (Tuple<FailedShardEntry, ClusterStateTaskExecutor.TaskResult> entry : taskResultMap) { | ||
if (entry.v2().isSuccess()) { | ||
// the shard was successfully failed and so should not be in the routing table | ||
for (ShardRouting shard : shards) { | ||
if (shard.assignedToNode()) { | ||
assertFalse("entry key " + entry.getKey() + ", shard routing " + shard, | ||
entry.getKey().getShardId().equals(shard.shardId()) && | ||
entry.getKey().getAllocationId().equals(shard.allocationId().getId())); | ||
assertFalse("entry key " + entry.v1() + ", shard routing " + shard, | ||
entry.v1().getShardId().equals(shard.shardId()) && | ||
entry.v1().getAllocationId().equals(shard.allocationId().getId())); | ||
} | ||
} | ||
} else { | ||
// check we saw the expected failure | ||
ClusterStateTaskExecutor.TaskResult actualResult = result.executionResults.get(entry.getKey()); | ||
assertThat(actualResult.getFailure(), instanceOf(entry.getValue().getFailure().getClass())); | ||
assertThat(actualResult.getFailure().getMessage(), equalTo(entry.getValue().getFailure().getMessage())); | ||
ClusterStateTaskExecutor.TaskResult actualResult = result.executionResults.get(entry.v1()); | ||
assertThat(actualResult.getFailure(), instanceOf(entry.v2().getFailure().getClass())); | ||
assertThat(actualResult.getFailure().getMessage(), equalTo(entry.v2().getFailure().getMessage())); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
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.
rename to taskResultList?