|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * The OpenSearch Contributors require contributions made to |
| 5 | + * this file be licensed under the Apache-2.0 license or a |
| 6 | + * compatible open source license. |
| 7 | + */ |
| 8 | + |
| 9 | +package org.opensearch.remotestore; |
| 10 | + |
| 11 | +import org.opensearch.action.admin.cluster.remotestore.stats.RemoteStoreStatsRequest; |
| 12 | +import org.opensearch.action.admin.cluster.remotestore.stats.RemoteStoreStatsResponse; |
| 13 | +import org.opensearch.common.settings.Settings; |
| 14 | +import org.opensearch.common.unit.TimeValue; |
| 15 | +import org.opensearch.indices.RemoteStoreSettings; |
| 16 | +import org.opensearch.plugins.Plugin; |
| 17 | +import org.opensearch.remotestore.multipart.mocks.MockFsRepositoryPlugin; |
| 18 | +import org.opensearch.test.OpenSearchIntegTestCase; |
| 19 | + |
| 20 | +import java.nio.file.Path; |
| 21 | +import java.util.Arrays; |
| 22 | +import java.util.Collection; |
| 23 | +import java.util.Locale; |
| 24 | +import java.util.concurrent.TimeUnit; |
| 25 | + |
| 26 | +import static org.opensearch.index.remote.RemoteStorePressureSettings.REMOTE_REFRESH_SEGMENT_PRESSURE_ENABLED; |
| 27 | +import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT; |
| 28 | + |
| 29 | +@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) |
| 30 | +public class RemoteStoreRefreshListenerMultipartIT extends AbstractRemoteStoreMockRepositoryIntegTestCase { |
| 31 | + |
| 32 | + protected Collection<Class<? extends Plugin>> nodePlugins() { |
| 33 | + return Arrays.asList(MockFsRepositoryPlugin.class); |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + public Settings buildRemoteStoreNodeAttributes(Path repoLocation, double ioFailureRate, String skipExceptionBlobList, long maxFailure) { |
| 38 | + Settings settings = super.buildRemoteStoreNodeAttributes(repoLocation, ioFailureRate, skipExceptionBlobList, maxFailure); |
| 39 | + String segmentRepoTypeAttributeKey = String.format( |
| 40 | + Locale.getDefault(), |
| 41 | + "node.attr." + REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT, |
| 42 | + REPOSITORY_NAME |
| 43 | + ); |
| 44 | + String translogRepoTypeAttributeKey = String.format( |
| 45 | + Locale.getDefault(), |
| 46 | + "node.attr." + REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT, |
| 47 | + TRANSLOG_REPOSITORY_NAME |
| 48 | + ); |
| 49 | + |
| 50 | + String stateRepoTypeAttributeKey = String.format( |
| 51 | + Locale.getDefault(), |
| 52 | + "node.attr." + REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT, |
| 53 | + REPOSITORY_NAME |
| 54 | + ); |
| 55 | + |
| 56 | + return Settings.builder() |
| 57 | + .put(settings) |
| 58 | + .put(segmentRepoTypeAttributeKey, MockFsRepositoryPlugin.TYPE) |
| 59 | + .put(translogRepoTypeAttributeKey, MockFsRepositoryPlugin.TYPE) |
| 60 | + .put(stateRepoTypeAttributeKey, MockFsRepositoryPlugin.TYPE) |
| 61 | + .build(); |
| 62 | + } |
| 63 | + |
| 64 | + public void testRemoteRefreshSegmentUploadTimeout() throws Exception { |
| 65 | + Path location = randomRepoPath().toAbsolutePath(); |
| 66 | + setup(location, randomDoubleBetween(0.1, 0.15, true), "metadata", 10L); |
| 67 | + |
| 68 | + client().admin() |
| 69 | + .cluster() |
| 70 | + .prepareUpdateSettings() |
| 71 | + .setPersistentSettings(Settings.builder().put(REMOTE_REFRESH_SEGMENT_PRESSURE_ENABLED.getKey(), false)) |
| 72 | + .setPersistentSettings( |
| 73 | + Settings.builder() |
| 74 | + .put(RemoteStoreSettings.CLUSTER_REMOTE_SEGMENT_TRANSFER_TIMEOUT_SETTING.getKey(), TimeValue.timeValueMillis(1)) |
| 75 | + ) |
| 76 | + .get(); |
| 77 | + |
| 78 | + // Here we are having flush/refresh after each iteration of indexing. However, the refresh will not always succeed |
| 79 | + // due to IOExceptions that are thrown while doing uploadBlobs. |
| 80 | + indexData(randomIntBetween(5, 10), randomBoolean()); |
| 81 | + logger.info("--> Indexed data"); |
| 82 | + logger.info("--> Verify that the segment upload fails"); |
| 83 | + try { |
| 84 | + assertBusy(() -> { |
| 85 | + RemoteStoreStatsResponse remoteStoreStatsResponse = client().admin() |
| 86 | + .cluster() |
| 87 | + .remoteStoreStats(new RemoteStoreStatsRequest()) |
| 88 | + .get(); |
| 89 | + Arrays.asList(remoteStoreStatsResponse.getRemoteStoreStats()).forEach(remoteStoreStats -> { |
| 90 | + assertTrue(remoteStoreStats.getSegmentStats().totalUploadsFailed > 10); |
| 91 | + }); |
| 92 | + }, 10, TimeUnit.SECONDS); |
| 93 | + } catch (Exception e) { |
| 94 | + throw new RuntimeException(e); |
| 95 | + } |
| 96 | + cleanupRepo(); |
| 97 | + } |
| 98 | +} |
0 commit comments