|
32 | 32 |
|
33 | 33 | package org.opensearch.snapshots;
|
34 | 34 |
|
| 35 | +import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; |
35 | 36 | import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
|
36 | 37 | import org.opensearch.action.admin.cluster.snapshots.status.SnapshotIndexShardStage;
|
37 | 38 | import org.opensearch.action.admin.cluster.snapshots.status.SnapshotIndexShardStatus;
|
| 39 | +import org.opensearch.action.admin.cluster.snapshots.status.SnapshotIndexStatus; |
38 | 40 | import org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus;
|
39 | 41 | import org.opensearch.cluster.SnapshotsInProgress;
|
40 | 42 | import org.opensearch.common.action.ActionFuture;
|
41 | 43 | import org.opensearch.common.settings.Settings;
|
| 44 | +import org.opensearch.indices.RemoteStoreSettings; |
| 45 | +import org.opensearch.repositories.blobstore.BlobStoreRepository; |
42 | 46 | import org.opensearch.test.OpenSearchIntegTestCase;
|
43 | 47 | import org.opensearch.threadpool.ThreadPool;
|
44 | 48 | import org.junit.Before;
|
45 | 49 |
|
46 | 50 | import java.nio.file.Path;
|
| 51 | +import java.util.Map; |
| 52 | +import java.util.concurrent.TimeUnit; |
47 | 53 |
|
48 | 54 | import static org.opensearch.remotestore.RemoteStoreBaseIntegTestCase.remoteStoreClusterSettings;
|
| 55 | +import static org.opensearch.snapshots.SnapshotsService.MAX_SHARDS_ALLOWED_IN_STATUS_API; |
| 56 | +import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; |
49 | 57 | import static org.hamcrest.Matchers.equalTo;
|
50 | 58 | import static org.hamcrest.Matchers.greaterThan;
|
51 | 59 | import static org.hamcrest.Matchers.is;
|
@@ -192,6 +200,110 @@ public void testStatusAPICallInProgressShallowSnapshot() throws Exception {
|
192 | 200 | createSnapshotResponseActionFuture.actionGet();
|
193 | 201 | }
|
194 | 202 |
|
| 203 | + public void testStatusAPICallForShallowV2Snapshot() throws Exception { |
| 204 | + disableRepoConsistencyCheck("Remote store repository is being used for the test"); |
| 205 | + Settings pinnedTimestampSettings = Settings.builder() |
| 206 | + .put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_PINNED_TIMESTAMP_ENABLED.getKey(), true) |
| 207 | + .build(); |
| 208 | + internalCluster().startClusterManagerOnlyNode(pinnedTimestampSettings); |
| 209 | + internalCluster().startDataOnlyNodes(2, pinnedTimestampSettings); |
| 210 | + |
| 211 | + final String index1 = "remote-index-1"; |
| 212 | + final String index2 = "remote-index-2"; |
| 213 | + final String index3 = "remote-index-3"; |
| 214 | + final String snapshotRepoName = "snapshot-repo-name"; |
| 215 | + final String snapshot = "snapshot"; |
| 216 | + |
| 217 | + logger.info("Create repository for shallow V2 snapshots"); |
| 218 | + Settings.Builder snapshotV2RepoSettings = snapshotRepoSettingsForShallowCopy().put( |
| 219 | + BlobStoreRepository.SHALLOW_SNAPSHOT_V2.getKey(), |
| 220 | + Boolean.TRUE |
| 221 | + ); |
| 222 | + createRepository(snapshotRepoName, "fs", snapshotV2RepoSettings); |
| 223 | + |
| 224 | + final Settings remoteStoreEnabledIndexSettings = getRemoteStoreBackedIndexSettings(); |
| 225 | + createIndex(index1, remoteStoreEnabledIndexSettings); |
| 226 | + createIndex(index2, remoteStoreEnabledIndexSettings); |
| 227 | + createIndex(index3, remoteStoreEnabledIndexSettings); |
| 228 | + ensureGreen(); |
| 229 | + |
| 230 | + logger.info("Indexing some data"); |
| 231 | + for (int i = 0; i < 50; i++) { |
| 232 | + index(index1, "_doc", Integer.toString(i), "foo", "bar" + i); |
| 233 | + index(index2, "_doc", Integer.toString(i), "foo", "bar" + i); |
| 234 | + index(index3, "_doc", Integer.toString(i), "foo", "bar" + i); |
| 235 | + } |
| 236 | + refresh(); |
| 237 | + |
| 238 | + SnapshotInfo snapshotInfo = createFullSnapshot(snapshotRepoName, snapshot); |
| 239 | + assertTrue(snapshotInfo.getPinnedTimestamp() > 0); // to assert creation of a shallow v2 snapshot |
| 240 | + |
| 241 | + logger.info("Set MAX_SHARDS_ALLOWED_IN_STATUS_API to a low value"); |
| 242 | + ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(); |
| 243 | + updateSettingsRequest.persistentSettings(Settings.builder().put(MAX_SHARDS_ALLOWED_IN_STATUS_API.getKey(), 2)); |
| 244 | + assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet()); |
| 245 | + |
| 246 | + assertBusy(() -> { |
| 247 | + // without index filter |
| 248 | + // although no. of shards in snapshot (3) is greater than the max value allowed in a status api call, the request does not fail |
| 249 | + SnapshotStatus snapshotStatusWithoutIndexFilter = client().admin() |
| 250 | + .cluster() |
| 251 | + .prepareSnapshotStatus(snapshotRepoName) |
| 252 | + .setSnapshots(snapshot) |
| 253 | + .execute() |
| 254 | + .actionGet() |
| 255 | + .getSnapshots() |
| 256 | + .get(0); |
| 257 | + |
| 258 | + assertShallowV2SnapshotStatus(snapshotStatusWithoutIndexFilter, false); |
| 259 | + |
| 260 | + // with index filter |
| 261 | + SnapshotStatus snapshotStatusWithIndexFilter = client().admin() |
| 262 | + .cluster() |
| 263 | + .prepareSnapshotStatus(snapshotRepoName) |
| 264 | + .setSnapshots(snapshot) |
| 265 | + .setIndices(index1, index2) |
| 266 | + .execute() |
| 267 | + .actionGet() |
| 268 | + .getSnapshots() |
| 269 | + .get(0); |
| 270 | + |
| 271 | + assertShallowV2SnapshotStatus(snapshotStatusWithIndexFilter, true); |
| 272 | + |
| 273 | + }, 1, TimeUnit.MINUTES); |
| 274 | + |
| 275 | + } |
| 276 | + |
| 277 | + private void assertShallowV2SnapshotStatus(SnapshotStatus snapshotStatus, boolean hasIndexFilter) { |
| 278 | + if (hasIndexFilter) { |
| 279 | + assertEquals(0, snapshotStatus.getStats().getTotalSize()); |
| 280 | + } else { |
| 281 | + // TODO: after adding primary store size at the snapshot level, total size here should be > 0 |
| 282 | + } |
| 283 | + // assert that total and incremental values of file count and size_in_bytes are 0 at index and shard levels |
| 284 | + assertEquals(0, snapshotStatus.getStats().getTotalFileCount()); |
| 285 | + assertEquals(0, snapshotStatus.getStats().getIncrementalSize()); |
| 286 | + assertEquals(0, snapshotStatus.getStats().getIncrementalFileCount()); |
| 287 | + |
| 288 | + for (Map.Entry<String, SnapshotIndexStatus> entry : snapshotStatus.getIndices().entrySet()) { |
| 289 | + // index level |
| 290 | + SnapshotIndexStatus snapshotIndexStatus = entry.getValue(); |
| 291 | + assertEquals(0, snapshotIndexStatus.getStats().getTotalSize()); |
| 292 | + assertEquals(0, snapshotIndexStatus.getStats().getTotalFileCount()); |
| 293 | + assertEquals(0, snapshotIndexStatus.getStats().getIncrementalSize()); |
| 294 | + assertEquals(0, snapshotIndexStatus.getStats().getIncrementalFileCount()); |
| 295 | + |
| 296 | + for (SnapshotIndexShardStatus snapshotIndexShardStatus : snapshotStatus.getShards()) { |
| 297 | + // shard level |
| 298 | + assertEquals(0, snapshotIndexShardStatus.getStats().getTotalSize()); |
| 299 | + assertEquals(0, snapshotIndexShardStatus.getStats().getTotalFileCount()); |
| 300 | + assertEquals(0, snapshotIndexShardStatus.getStats().getIncrementalSize()); |
| 301 | + assertEquals(0, snapshotIndexShardStatus.getStats().getIncrementalFileCount()); |
| 302 | + assertEquals(SnapshotIndexShardStage.DONE, snapshotIndexShardStatus.getStage()); |
| 303 | + } |
| 304 | + } |
| 305 | + } |
| 306 | + |
195 | 307 | private static SnapshotIndexShardStatus stateFirstShard(SnapshotStatus snapshotStatus, String indexName) {
|
196 | 308 | return snapshotStatus.getIndices().get(indexName).getShards().get(0);
|
197 | 309 | }
|
|
0 commit comments