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