-
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
Wait for prewarm when relocating searchable snapshot shards #65531
Merged
original-brownbear
merged 24 commits into
elastic:master
from
original-brownbear:wait-for-prewarm
Dec 9, 2020
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
74eae5c
Wait for Prewarm when Relocating Searchable Snapshot Shards
original-brownbear e688e74
Merge remote-tracking branch 'elastic/master' into wait-for-prewarm
original-brownbear e57db07
Merge remote-tracking branch 'elastic/master' into wait-for-prewarm
original-brownbear f489058
add test
original-brownbear 95dadb2
better test
original-brownbear d5ee3f3
way better test
original-brownbear fa8dea6
reformat nicer
original-brownbear eccb1b4
Merge remote-tracking branch 'elastic/master' into wait-for-prewarm
original-brownbear a428a8b
start
original-brownbear 472fa1e
Merge remote-tracking branch 'elastic/master' into wait-for-prewarm-o…
original-brownbear fc01ad4
Merge remote-tracking branch 'elastic/master' into wait-for-prewarm-o…
original-brownbear 48c55f5
bck
original-brownbear 40e18cd
works nicely
original-brownbear 9427179
Merge remote-tracking branch 'elastic/master' into wait-for-prewarm-o…
original-brownbear ed4e8c9
fixes
original-brownbear 59ab566
fix liveness check disabling
original-brownbear 566884e
fix comment
original-brownbear 3b41f93
much simpler
original-brownbear 43816f5
cs
original-brownbear 714e6c1
Merge remote-tracking branch 'elastic/master' into wait-for-prewarm
original-brownbear 86e9ebb
adjust broken test
original-brownbear d44b120
shorter
original-brownbear ef5032e
Merge remote-tracking branch 'elastic/master' into wait-for-prewarm
original-brownbear b9063b5
adjust tests
original-brownbear 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
125 changes: 125 additions & 0 deletions
125
.../org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsRelocationIntegTests.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,125 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.searchablesnapshots; | ||
|
||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.common.Priority; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.indices.IndicesService; | ||
import org.elasticsearch.indices.recovery.RecoveryState; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.snapshots.mockstore.MockRepository; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.hamcrest.Matchers; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.CyclicBarrier; | ||
import java.util.concurrent.Executor; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
|
||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0) | ||
public class SearchableSnapshotsRelocationIntegTests extends BaseSearchableSnapshotsIntegTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return List.of(LocalStateSearchableSnapshots.class, MockRepository.Plugin.class); | ||
} | ||
|
||
public void testRelocationWaitsForPreWarm() throws Exception { | ||
internalCluster().startMasterOnlyNode(); | ||
final String firstDataNode = internalCluster().startDataOnlyNode(); | ||
final String index = "test-idx"; | ||
createIndexWithContent(index, indexSettingsNoReplicas(1).build()); | ||
final String repoName = "test-repo"; | ||
createRepository(repoName, "mock"); | ||
final String snapshotName = "test-snapshot"; | ||
createSnapshot(repoName, snapshotName, List.of(index)); | ||
assertAcked(client().admin().indices().prepareDelete(index)); | ||
final String restoredIndex = mountSnapshot(repoName, snapshotName, index, Settings.EMPTY); | ||
ensureGreen(restoredIndex); | ||
final String secondDataNode = internalCluster().startDataOnlyNode(); | ||
|
||
final ThreadPool threadPool = internalCluster().getInstance(ThreadPool.class, secondDataNode); | ||
final int preWarmThreads = threadPool.info(SearchableSnapshotsConstants.CACHE_PREWARMING_THREAD_POOL_NAME).getMax(); | ||
final Executor executor = threadPool.executor(SearchableSnapshotsConstants.CACHE_PREWARMING_THREAD_POOL_NAME); | ||
final CyclicBarrier barrier = new CyclicBarrier(preWarmThreads + 1); | ||
final CountDownLatch latch = new CountDownLatch(1); | ||
for (int i = 0; i < preWarmThreads; i++) { | ||
executor.execute(() -> { | ||
try { | ||
barrier.await(); | ||
latch.await(); | ||
} catch (Exception e) { | ||
throw new AssertionError(e); | ||
} | ||
}); | ||
} | ||
logger.info("--> waiting for prewarm threads to all become blocked"); | ||
barrier.await(); | ||
|
||
logger.info("--> force index [{}] to relocate to [{}]", index, secondDataNode); | ||
assertAcked( | ||
client().admin() | ||
.indices() | ||
.prepareUpdateSettings(restoredIndex) | ||
.setSettings( | ||
Settings.builder() | ||
.put( | ||
IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getConcreteSettingForNamespace("_name").getKey(), | ||
secondDataNode | ||
) | ||
) | ||
); | ||
assertBusy(() -> { | ||
final List<RecoveryState> recoveryStates = getActiveRestores(restoredIndex); | ||
assertThat(recoveryStates, Matchers.hasSize(1)); | ||
final RecoveryState shardRecoveryState = recoveryStates.get(0); | ||
assertEquals(firstDataNode, shardRecoveryState.getSourceNode().getName()); | ||
assertEquals(secondDataNode, shardRecoveryState.getTargetNode().getName()); | ||
}); | ||
|
||
assertBusy(() -> assertSame(RecoveryState.Stage.TRANSLOG, getActiveRestores(restoredIndex).get(0).getStage())); | ||
final Index restoredIdx = clusterAdmin().prepareState().get().getState().metadata().index(restoredIndex).getIndex(); | ||
final IndicesService indicesService = internalCluster().getInstance(IndicesService.class, secondDataNode); | ||
assertEquals(1, indicesService.indexService(restoredIdx).getShard(0).outstandingCleanFilesConditions()); | ||
final ClusterState state = client().admin().cluster().prepareState().get().getState(); | ||
final String primaryNodeId = state.routingTable().index(restoredIndex).shard(0).primaryShard().currentNodeId(); | ||
final DiscoveryNode primaryNode = state.nodes().resolveNode(primaryNodeId); | ||
assertEquals(firstDataNode, primaryNode.getName()); | ||
|
||
logger.info("--> unblocking prewarm threads"); | ||
latch.countDown(); | ||
|
||
assertFalse( | ||
client().admin() | ||
.cluster() | ||
.prepareHealth(restoredIndex) | ||
.setWaitForNoRelocatingShards(true) | ||
.setWaitForEvents(Priority.LANGUID) | ||
.get() | ||
.isTimedOut() | ||
); | ||
assertBusy(() -> assertThat(getActiveRestores(restoredIndex), Matchers.empty())); | ||
} | ||
|
||
private static List<RecoveryState> getActiveRestores(String restoredIndex) { | ||
return client().admin() | ||
.indices() | ||
.prepareRecoveries(restoredIndex) | ||
.setDetailed(true) | ||
.setActiveOnly(true) | ||
.get() | ||
.shardRecoveryStates() | ||
.get(restoredIndex); | ||
} | ||
} |
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.
This is a little low-tech relative to the tricky ref-counting in the
IndexShard
. I figured this was ok here since the hand-off request only comes in once (at least judging by the assertions we have inIndexShard
) while the other API has a more "feel" to it and there are no hard guarantees on the index shard state listener only being invoked once (though the "loaded" flag on the directory effectively guarantees we only add one condition for now) and it wasn't that much extra effort since the API was supposed to be non-blocking anyway.