|
32 | 32 |
|
33 | 33 | package org.opensearch.repositories;
|
34 | 34 |
|
| 35 | +import org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest; |
35 | 36 | import org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse;
|
| 37 | +import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; |
36 | 38 | import org.opensearch.cluster.metadata.RepositoryMetadata;
|
37 | 39 | import org.opensearch.common.settings.Settings;
|
38 | 40 | import org.opensearch.plugins.Plugin;
|
|
42 | 44 | import org.opensearch.test.OpenSearchIntegTestCase;
|
43 | 45 | import org.opensearch.transport.client.Client;
|
44 | 46 |
|
| 47 | +import java.io.IOException; |
45 | 48 | import java.util.Collection;
|
46 | 49 | import java.util.Collections;
|
47 | 50 |
|
| 51 | +import static org.hamcrest.Matchers.containsString; |
| 52 | +import static org.hamcrest.Matchers.hasToString; |
| 53 | +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS; |
| 54 | +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS; |
48 | 55 | import static org.hamcrest.Matchers.equalTo;
|
49 | 56 | import static org.hamcrest.Matchers.hasSize;
|
50 | 57 | import static org.hamcrest.Matchers.instanceOf;
|
@@ -122,4 +129,66 @@ public void testSystemRepositoryCantBeCreated() {
|
122 | 129 |
|
123 | 130 | assertThrows(RepositoryException.class, () -> createRepository(repositoryName, FsRepository.TYPE, repoSettings));
|
124 | 131 | }
|
| 132 | + |
| 133 | + public void testCreatSnapAndUpdateReposityCauseInfiniteLoop() throws InterruptedException { |
| 134 | + // create index |
| 135 | + internalCluster(); |
| 136 | + String indexName = "test-index"; |
| 137 | + createIndex(indexName, Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, 0).put(SETTING_NUMBER_OF_SHARDS, 1).build()); |
| 138 | + index(indexName, "_doc", "1", Collections.singletonMap("user", generateRandomStringArray(1, 10, false, false))); |
| 139 | + flush(indexName); |
| 140 | + |
| 141 | + // create repository |
| 142 | + final String repositoryName = "test-repo"; |
| 143 | + Settings.Builder repoSettings = Settings.builder() |
| 144 | + .put("location", randomRepoPath()) |
| 145 | + .put("max_snapshot_bytes_per_sec", "10mb") |
| 146 | + .put("max_restore_bytes_per_sec", "10mb"); |
| 147 | + OpenSearchIntegTestCase.putRepositoryWithNoSettingOverrides( |
| 148 | + client().admin().cluster(), |
| 149 | + repositoryName, |
| 150 | + FsRepository.TYPE, |
| 151 | + true, |
| 152 | + repoSettings |
| 153 | + ); |
| 154 | + |
| 155 | + String snapshotName = "test-snapshot"; |
| 156 | + Runnable createSnapshot = () -> { |
| 157 | + logger.info("--> begining snapshot"); |
| 158 | + client().admin() |
| 159 | + .cluster() |
| 160 | + .prepareCreateSnapshot(repositoryName, snapshotName) |
| 161 | + .setWaitForCompletion(true) |
| 162 | + .setIndices(indexName) |
| 163 | + .get(); |
| 164 | + logger.info("--> finishing snapshot"); |
| 165 | + }; |
| 166 | + |
| 167 | + // snapshot mab be failed when updating repository |
| 168 | + Thread thread = new Thread(() -> { |
| 169 | + try { |
| 170 | + createSnapshot.run(); |
| 171 | + } catch (Exception e) { |
| 172 | + assertThat(e, instanceOf(RepositoryException.class)); |
| 173 | + assertThat(e, hasToString(containsString(("the repository is closed")))); |
| 174 | + } |
| 175 | + }); |
| 176 | + thread.start(); |
| 177 | + |
| 178 | + logger.info("--> begin to reset repository"); |
| 179 | + repoSettings = Settings.builder().put("location", randomRepoPath()).put("max_snapshot_bytes_per_sec", "300mb"); |
| 180 | + OpenSearchIntegTestCase.putRepositoryWithNoSettingOverrides( |
| 181 | + client().admin().cluster(), |
| 182 | + repositoryName, |
| 183 | + FsRepository.TYPE, |
| 184 | + true, |
| 185 | + repoSettings |
| 186 | + ); |
| 187 | + logger.info("--> finish to reset repository"); |
| 188 | + |
| 189 | + // after updating repository, snapshot should be success |
| 190 | + createSnapshot.run(); |
| 191 | + |
| 192 | + thread.join(); |
| 193 | + } |
125 | 194 | }
|
0 commit comments