|
108 | 108 | import org.elasticsearch.cluster.service.ClusterApplierService;
|
109 | 109 | import org.elasticsearch.cluster.service.ClusterService;
|
110 | 110 | import org.elasticsearch.cluster.service.MasterService;
|
| 111 | +import org.elasticsearch.common.Nullable; |
111 | 112 | import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
112 | 113 | import org.elasticsearch.common.network.NetworkModule;
|
113 | 114 | import org.elasticsearch.common.settings.ClusterSettings;
|
|
152 | 153 | import org.elasticsearch.search.SearchService;
|
153 | 154 | import org.elasticsearch.search.builder.SearchSourceBuilder;
|
154 | 155 | import org.elasticsearch.search.fetch.FetchPhase;
|
| 156 | +import org.elasticsearch.snapshots.mockstore.MockEventuallyConsistentRepository; |
155 | 157 | import org.elasticsearch.test.ESTestCase;
|
156 | 158 | import org.elasticsearch.test.disruption.DisruptableMockTransport;
|
157 | 159 | import org.elasticsearch.test.disruption.NetworkDisruption;
|
@@ -203,16 +205,28 @@ public class SnapshotResiliencyTests extends ESTestCase {
|
203 | 205 |
|
204 | 206 | private Path tempDir;
|
205 | 207 |
|
| 208 | + /** |
| 209 | + * Context shared by all the node's {@link Repository} instances if the eventually consistent blobstore is to be used. |
| 210 | + * {@code null} if not using the eventually consistent blobstore. |
| 211 | + */ |
| 212 | + @Nullable private MockEventuallyConsistentRepository.Context blobStoreContext; |
| 213 | + |
206 | 214 | @Before
|
207 | 215 | public void createServices() {
|
208 | 216 | tempDir = createTempDir();
|
| 217 | + if (randomBoolean()) { |
| 218 | + blobStoreContext = new MockEventuallyConsistentRepository.Context(); |
| 219 | + } |
209 | 220 | deterministicTaskQueue =
|
210 | 221 | new DeterministicTaskQueue(Settings.builder().put(NODE_NAME_SETTING.getKey(), "shared").build(), random());
|
211 | 222 | }
|
212 | 223 |
|
213 | 224 | @After
|
214 | 225 | public void verifyReposThenStopServices() {
|
215 | 226 | try {
|
| 227 | + if (blobStoreContext != null) { |
| 228 | + blobStoreContext.forceConsistent(); |
| 229 | + } |
216 | 230 | BlobStoreTestUtil.assertConsistency(
|
217 | 231 | (BlobStoreRepository) testClusterNodes.randomMasterNodeSafe().repositoriesService.repository("repo"),
|
218 | 232 | Runnable::run);
|
@@ -900,19 +914,7 @@ public void onFailure(final Exception e) {
|
900 | 914 | final IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver();
|
901 | 915 | repositoriesService = new RepositoriesService(
|
902 | 916 | settings, clusterService, transportService,
|
903 |
| - Collections.singletonMap(FsRepository.TYPE, metaData -> { |
904 |
| - final Repository repository = new FsRepository(metaData, environment, xContentRegistry(), threadPool) { |
905 |
| - @Override |
906 |
| - protected void assertSnapshotOrGenericThread() { |
907 |
| - // eliminate thread name check as we create repo in the test thread |
908 |
| - } |
909 |
| - }; |
910 |
| - repository.start(); |
911 |
| - return repository; |
912 |
| - } |
913 |
| - ), |
914 |
| - emptyMap(), |
915 |
| - threadPool |
| 917 | + Collections.singletonMap(FsRepository.TYPE, getRepoFactory(environment)), emptyMap(), threadPool |
916 | 918 | );
|
917 | 919 | snapshotsService =
|
918 | 920 | new SnapshotsService(settings, clusterService, indexNameExpressionResolver, repositoriesService, threadPool);
|
@@ -1093,6 +1095,28 @@ searchTransportService, new SearchPhaseController(searchService::createReduceCon
|
1093 | 1095 | client.initialize(actions, () -> clusterService.localNode().getId(), transportService.getRemoteClusterService());
|
1094 | 1096 | }
|
1095 | 1097 |
|
| 1098 | + private Repository.Factory getRepoFactory(Environment environment) { |
| 1099 | + // Run half the tests with the eventually consistent repository |
| 1100 | + if (blobStoreContext == null) { |
| 1101 | + return metaData -> { |
| 1102 | + final Repository repository = new FsRepository(metaData, environment, xContentRegistry(), threadPool) { |
| 1103 | + @Override |
| 1104 | + protected void assertSnapshotOrGenericThread() { |
| 1105 | + // eliminate thread name check as we create repo in the test thread |
| 1106 | + } |
| 1107 | + }; |
| 1108 | + repository.start(); |
| 1109 | + return repository; |
| 1110 | + }; |
| 1111 | + } else { |
| 1112 | + return metaData -> { |
| 1113 | + final Repository repository = new MockEventuallyConsistentRepository( |
| 1114 | + metaData, environment, xContentRegistry(), deterministicTaskQueue.getThreadPool(), blobStoreContext); |
| 1115 | + repository.start(); |
| 1116 | + return repository; |
| 1117 | + }; |
| 1118 | + } |
| 1119 | + } |
1096 | 1120 | public void restart() {
|
1097 | 1121 | testClusterNodes.disconnectNode(this);
|
1098 | 1122 | final ClusterState oldState = this.clusterService.state();
|
|
0 commit comments