Skip to content

Commit

Permalink
Fix flaky test RemoteIndexRecoveryIT.testRerouteRecovery (opensearch-…
Browse files Browse the repository at this point in the history
…project#17228)

Signed-off-by: Sachin Kale <[email protected]>
  • Loading branch information
sachinpkale authored Mar 4, 2025
1 parent 218f353 commit f6d6aa6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private void assertOnGoingRecoveryState(
assertThat(state.getStage(), not(equalTo(Stage.DONE)));
}

private void slowDownRecovery(ByteSizeValue shardSize) {
public void slowDownRecovery(ByteSizeValue shardSize) {
long chunkSize = Math.max(1, shardSize.getBytes() / 10);
assertTrue(
client().admin()
Expand Down Expand Up @@ -528,7 +528,7 @@ public void testRerouteRecovery() throws Exception {
assertThat(indicesService.indexServiceSafe(index).getShard(0).recoveryStats().currentAsSource(), equalTo(1));
indicesService = internalCluster().getInstance(IndicesService.class, nodeB);
assertThat(indicesService.indexServiceSafe(index).getShard(0).recoveryStats().currentAsTarget(), equalTo(1));
}, TimeValue.timeValueSeconds(10), TimeValue.timeValueMillis(500));
}, TimeValue.timeValueSeconds(60), TimeValue.timeValueMillis(500));

logger.info("--> request recoveries");
RecoveryResponse response = client().admin().indices().prepareRecoveries(INDEX_NAME).execute().actionGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.common.unit.ByteSizeUnit;
import org.opensearch.core.common.unit.ByteSizeValue;
import org.opensearch.index.IndexModule;
import org.opensearch.index.IndexSettings;
import org.opensearch.indices.recovery.IndexRecoveryIT;
import org.opensearch.indices.recovery.RecoverySettings;
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.hamcrest.Matcher;
Expand All @@ -22,6 +25,7 @@

import java.nio.file.Path;

import static org.opensearch.indices.recovery.RecoverySettings.INDICES_RECOVERY_CHUNK_SIZE_SETTING;
import static org.opensearch.remotestore.RemoteStoreBaseIntegTestCase.remoteStoreClusterSettings;

@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0)
Expand Down Expand Up @@ -54,6 +58,26 @@ public Settings indexSettings() {
.build();
}

@Override
public void slowDownRecovery(ByteSizeValue shardSize) {
logger.info("--> shardSize: " + shardSize);
long chunkSize = Math.max(1, shardSize.getBytes() / 50);
assertTrue(
client().admin()
.cluster()
.prepareUpdateSettings()
.setTransientSettings(
Settings.builder()
// one chunk per sec..
.put(RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(), chunkSize, ByteSizeUnit.BYTES)
// small chunks
.put(INDICES_RECOVERY_CHUNK_SIZE_SETTING.getKey(), new ByteSizeValue(chunkSize, ByteSizeUnit.BYTES))
)
.get()
.isAcknowledged()
);
}

@After
public void teardown() {
clusterAdmin().prepareCleanupRepository(REPOSITORY_NAME).get();
Expand Down

0 comments on commit f6d6aa6

Please sign in to comment.