- Notifications
You must be signed in to change notification settings - Fork 25.6k
Reduce WaitForNoFollowersStep requests indices shard stats #94510
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
Changes from 2 commits
38653fa 712e5aa 2f5df59 391e8cf d3c5f99 7c04207 4d4c235 77c26aa 96d80c4 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -17,10 +17,14 @@ | |
| import org.elasticsearch.cluster.metadata.Metadata; | ||
| import org.elasticsearch.core.TimeValue; | ||
| import org.elasticsearch.index.Index; | ||
| import org.elasticsearch.protocol.xpack.XPackInfoRequest; | ||
| import org.elasticsearch.protocol.xpack.XPackInfoResponse; | ||
| import org.elasticsearch.xpack.core.action.XPackInfoAction; | ||
| import org.elasticsearch.xpack.core.ilm.step.info.SingleMessageFieldInfo; | ||
| | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.EnumSet; | ||
| import java.util.Optional; | ||
| | ||
| /** | ||
| | @@ -49,10 +53,31 @@ public boolean isRetryable() { | |
| | ||
| @Override | ||
| public void evaluateCondition(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout) { | ||
| XPackInfoRequest xPackInfoRequest = new XPackInfoRequest(); | ||
| xPackInfoRequest.setCategories(EnumSet.of(XPackInfoRequest.Category.FEATURES)); | ||
| getClient().execute( | ||
| XPackInfoAction.INSTANCE, | ||
| xPackInfoRequest, | ||
| ActionListener.wrap((xPackInfoResponse) -> { | ||
| XPackInfoResponse.FeatureSetsInfo featureSetsInfo = xPackInfoResponse.getFeatureSetsInfo(); | ||
| if (featureSetsInfo != null) { | ||
| XPackInfoResponse.FeatureSetsInfo.FeatureSet featureSet = featureSetsInfo.getFeatureSets().get(CCR_LEASE_KEY); | ||
| if (featureSet != null && (featureSet.available() == false || featureSet.enabled() == false)){ | ||
| ||
| listener.onResponse(true, null); | ||
| return; | ||
| } | ||
| } | ||
| leaderIndexCheck(metadata, index, listener, masterTimeout); | ||
| }, listener::onFailure) | ||
| ); | ||
| } | ||
| | ||
| private void leaderIndexCheck(Metadata metadata, Index index, Listener listener, TimeValue masterTimeout) { | ||
| IndicesStatsRequest request = new IndicesStatsRequest(); | ||
| request.clear(); | ||
| String indexName = index.getName(); | ||
| request.indices(indexName); | ||
| | ||
| getClient().admin().indices().stats(request, ActionListener.wrap((response) -> { | ||
| IndexStats indexStats = response.getIndex(indexName); | ||
| if (indexStats == null) { | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -23,11 +23,15 @@ | |
| import org.elasticsearch.index.seqno.RetentionLeases; | ||
| import org.elasticsearch.index.shard.ShardId; | ||
| import org.elasticsearch.index.shard.ShardPath; | ||
| import org.elasticsearch.protocol.xpack.XPackInfoResponse; | ||
| import org.elasticsearch.xcontent.ToXContentObject; | ||
| import org.elasticsearch.xpack.core.action.XPackInfoAction; | ||
| import org.mockito.Mockito; | ||
| | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
| | ||
| import static org.elasticsearch.xpack.core.ilm.WaitForNoFollowersStep.CCR_LEASE_KEY; | ||
| import static org.hamcrest.Matchers.containsString; | ||
| | @@ -64,7 +68,7 @@ protected WaitForNoFollowersStep copyInstance(WaitForNoFollowersStep instance) { | |
| return new WaitForNoFollowersStep(instance.getKey(), instance.getNextStepKey(), instance.getClient()); | ||
| } | ||
| | ||
| public void testConditionMet() { | ||
| public void testConditionMetWhenEnable() { | ||
| ||
| WaitForNoFollowersStep step = createRandomInstance(); | ||
| | ||
| String indexName = randomAlphaOfLengthBetween(5, 10); | ||
| | @@ -76,6 +80,41 @@ public void testConditionMet() { | |
| .numberOfReplicas(randomIntBetween(1, 10)) | ||
| .build(); | ||
| | ||
| mockXPackInfo(true, true); | ||
| mockIndexStatsCall(indexName, randomIndexStats(false, numberOfShards)); | ||
| | ||
| final SetOnce<Boolean> conditionMetHolder = new SetOnce<>(); | ||
| final SetOnce<ToXContentObject> stepInfoHolder = new SetOnce<>(); | ||
| step.evaluateCondition(Metadata.builder().put(indexMetadata, true).build(), indexMetadata.getIndex(), new AsyncWaitStep.Listener() { | ||
| @Override | ||
| public void onResponse(boolean conditionMet, ToXContentObject infomationContext) { | ||
| conditionMetHolder.set(conditionMet); | ||
| stepInfoHolder.set(infomationContext); | ||
| } | ||
| | ||
| @Override | ||
| public void onFailure(Exception e) { | ||
| fail("onFailure should not be called in this test, called with exception: " + e.getMessage()); | ||
| } | ||
| }, MASTER_TIMEOUT); | ||
| | ||
| assertTrue(conditionMetHolder.get()); | ||
| assertNull(stepInfoHolder.get()); | ||
| } | ||
| | ||
| public void testConditionMetWhenDisabled() { | ||
| ||
| WaitForNoFollowersStep step = createRandomInstance(); | ||
| | ||
| String indexName = randomAlphaOfLengthBetween(5, 10); | ||
| | ||
| int numberOfShards = randomIntBetween(1, 100); | ||
| final IndexMetadata indexMetadata = IndexMetadata.builder(indexName) | ||
| .settings(settings(Version.CURRENT)) | ||
| .numberOfShards(numberOfShards) | ||
| .numberOfReplicas(randomIntBetween(1, 10)) | ||
| .build(); | ||
| | ||
| mockXPackInfo(false, false); | ||
| mockIndexStatsCall(indexName, randomIndexStats(false, numberOfShards)); | ||
| | ||
| final SetOnce<Boolean> conditionMetHolder = new SetOnce<>(); | ||
| | @@ -109,6 +148,7 @@ public void testConditionNotMet() { | |
| .numberOfReplicas(randomIntBetween(1, 10)) | ||
| .build(); | ||
| | ||
| mockXPackInfo(true, true); | ||
| mockIndexStatsCall(indexName, randomIndexStats(true, numberOfShards)); | ||
| | ||
| final SetOnce<Boolean> conditionMetHolder = new SetOnce<>(); | ||
| | @@ -148,6 +188,8 @@ public void testNoShardStats() { | |
| ShardStats sStats = new ShardStats(null, mockShardPath(), null, null, null, null); | ||
| ShardStats[] shardStats = new ShardStats[1]; | ||
| shardStats[0] = sStats; | ||
| | ||
| mockXPackInfo(true, true); | ||
| mockIndexStatsCall(indexName, new IndexStats(indexName, "uuid", ClusterHealthStatus.GREEN, IndexMetadata.State.OPEN, shardStats)); | ||
| | ||
| final SetOnce<Boolean> conditionMetHolder = new SetOnce<>(); | ||
| | @@ -183,6 +225,7 @@ public void testFailure() { | |
| | ||
| final Exception expectedException = new RuntimeException(randomAlphaOfLength(5)); | ||
| | ||
| mockXPackInfo(true, true); | ||
| Mockito.doAnswer(invocationOnMock -> { | ||
| @SuppressWarnings("unchecked") | ||
| ActionListener<IndicesStatsResponse> listener = (ActionListener<IndicesStatsResponse>) invocationOnMock.getArguments()[1]; | ||
| | @@ -211,6 +254,22 @@ public void onFailure(Exception e) { | |
| assertThat(exceptionHolder.get(), equalTo(expectedException)); | ||
| } | ||
| | ||
| private void mockXPackInfo(boolean available, boolean enabled) { | ||
| Mockito.doAnswer(invocationOnMock -> { | ||
| | ||
| @SuppressWarnings("unchecked") | ||
| ActionListener<XPackInfoResponse> listener = (ActionListener<XPackInfoResponse>) invocationOnMock.getArguments()[2]; | ||
| | ||
| Set<XPackInfoResponse.FeatureSetsInfo.FeatureSet> featureSets = new HashSet<>(); | ||
| featureSets.add(new XPackInfoResponse.FeatureSetsInfo.FeatureSet("ccr", available, enabled)); | ||
| XPackInfoResponse.FeatureSetsInfo featureInfos = new XPackInfoResponse.FeatureSetsInfo(featureSets); | ||
| XPackInfoResponse xpackInfo = new XPackInfoResponse(null, null, featureInfos); | ||
| | ||
| listener.onResponse(xpackInfo); | ||
| return null; | ||
| }).when(client).execute(Mockito.same(XPackInfoAction.INSTANCE), Mockito.any(), Mockito.any()); | ||
| } | ||
| | ||
| private void mockIndexStatsCall(String expectedIndexName, IndexStats indexStats) { | ||
| Mockito.doAnswer(invocationOnMock -> { | ||
| IndicesStatsRequest request = (IndicesStatsRequest) invocationOnMock.getArguments()[0]; | ||
| | ||
Uh oh!
There was an error while loading. Please reload this page.