Skip to content

Commit 8c9b3d5

Browse files
committed
Fix flaky tests with hashed prefix path type snapshots (opensearch-project#15560)
Signed-off-by: Ashish Singh <[email protected]>
1 parent dfea54b commit 8c9b3d5

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

server/src/internalClusterTest/java/org/opensearch/snapshots/CorruptedBlobStoreRepositoryIT.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,11 @@
4343
import org.opensearch.cluster.ClusterState;
4444
import org.opensearch.cluster.metadata.Metadata;
4545
import org.opensearch.cluster.metadata.RepositoriesMetadata;
46-
import org.opensearch.common.blobstore.BlobPath;
4746
import org.opensearch.common.settings.Settings;
4847
import org.opensearch.common.util.io.IOUtils;
4948
import org.opensearch.core.common.bytes.BytesReference;
5049
import org.opensearch.core.common.unit.ByteSizeUnit;
5150
import org.opensearch.core.xcontent.MediaTypeRegistry;
52-
import org.opensearch.index.remote.RemoteStoreEnums.PathHashAlgorithm;
53-
import org.opensearch.index.remote.RemoteStoreEnums.PathType;
54-
import org.opensearch.index.remote.RemoteStorePathStrategy;
5551
import org.opensearch.repositories.IndexId;
5652
import org.opensearch.repositories.IndexMetaDataGenerations;
5753
import org.opensearch.repositories.RepositoriesService;
@@ -76,7 +72,7 @@
7672
import java.util.stream.Collectors;
7773
import java.util.stream.Stream;
7874

79-
import static org.opensearch.index.remote.RemoteStoreEnums.PathHashAlgorithm.FNV_1A_COMPOSITE_1;
75+
import static org.opensearch.test.OpenSearchIntegTestCase.resolvePath;
8076
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
8177
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertFileExists;
8278
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertRequestBuilderThrows;
@@ -874,16 +870,4 @@ private void assertRepositoryBlocked(Client client, String repo, String existing
874870
containsString("Could not read repository data because the contents of the repository do not match its expected state.")
875871
);
876872
}
877-
878-
private static String resolvePath(IndexId indexId, String shardId) {
879-
PathType pathType = PathType.fromCode(indexId.getShardPathType());
880-
RemoteStorePathStrategy.SnapshotShardPathInput shardPathInput = new RemoteStorePathStrategy.SnapshotShardPathInput.Builder()
881-
.basePath(BlobPath.cleanPath())
882-
.indexUUID(indexId.getId())
883-
.shardId(shardId)
884-
.build();
885-
PathHashAlgorithm pathHashAlgorithm = pathType != PathType.FIXED ? FNV_1A_COMPOSITE_1 : null;
886-
BlobPath blobPath = pathType.path(shardPathInput, pathHashAlgorithm);
887-
return blobPath.buildAsString();
888-
}
889873
}

server/src/internalClusterTest/java/org/opensearch/snapshots/RepositoriesIT.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,17 @@ public void testRepositoryCreation() throws Exception {
110110
assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-1"), notNullValue());
111111
assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-2"), notNullValue());
112112

113+
RepositoryMetadata testRepo1Md = findRepository(repositoriesResponse.repositories(), "test-repo-1");
114+
113115
logger.info("--> check that trying to create a repository with the same settings repeatedly does not update cluster state");
114116
String beforeStateUuid = clusterStateResponse.getState().stateUUID();
115117
createRepository("test-repo-1", "fs", Settings.builder().put("location", location));
116-
assertEquals(beforeStateUuid, client.admin().cluster().prepareState().clear().get().getState().stateUUID());
118+
repositoriesResponse = client.admin().cluster().prepareGetRepositories(randomFrom("_all", "*", "test-repo-*")).get();
119+
RepositoryMetadata testRepo1MdAfterUpdate = findRepository(repositoriesResponse.repositories(), "test-repo-1");
120+
121+
if (testRepo1Md.settings().equals(testRepo1MdAfterUpdate.settings())) {
122+
assertEquals(beforeStateUuid, client.admin().cluster().prepareState().clear().get().getState().stateUUID());
123+
}
117124

118125
logger.info("--> delete repository test-repo-1");
119126
client.admin().cluster().prepareDeleteRepository("test-repo-1").get();

server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.opensearch.common.util.io.IOUtils;
5050
import org.opensearch.core.common.Strings;
5151
import org.opensearch.core.common.unit.ByteSizeUnit;
52+
import org.opensearch.repositories.IndexId;
5253
import org.opensearch.repositories.blobstore.BlobStoreRepository;
5354
import org.opensearch.threadpool.ThreadPool;
5455

@@ -62,6 +63,7 @@
6263
import java.util.concurrent.TimeUnit;
6364
import java.util.stream.Collectors;
6465

66+
import static org.opensearch.test.OpenSearchIntegTestCase.resolvePath;
6567
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
6668
import static org.hamcrest.Matchers.equalTo;
6769
import static org.hamcrest.Matchers.greaterThan;
@@ -200,11 +202,9 @@ public void testExceptionOnMissingShardLevelSnapBlob() throws IOException {
200202
final SnapshotInfo snapshotInfo = createFullSnapshot("test-repo", "test-snap");
201203

202204
logger.info("--> delete shard-level snap-${uuid}.dat file for one shard in this snapshot to simulate concurrent delete");
203-
final String indexRepoId = getRepositoryData("test-repo").resolveIndexId(snapshotInfo.indices().get(0)).getId();
205+
IndexId indexId = getRepositoryData("test-repo").resolveIndexId(snapshotInfo.indices().get(0));
204206
IOUtils.rm(
205-
repoPath.resolve("indices")
206-
.resolve(indexRepoId)
207-
.resolve("0")
207+
repoPath.resolve(resolvePath(indexId, "0"))
208208
.resolve(BlobStoreRepository.SNAPSHOT_PREFIX + snapshotInfo.snapshotId().getUUID() + ".dat")
209209
);
210210

test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
import org.opensearch.cluster.service.applicationtemplates.TestSystemTemplatesRepositoryPlugin;
102102
import org.opensearch.common.Nullable;
103103
import org.opensearch.common.Priority;
104+
import org.opensearch.common.blobstore.BlobPath;
104105
import org.opensearch.common.collect.Tuple;
105106
import org.opensearch.common.concurrent.GatedCloseable;
106107
import org.opensearch.common.network.NetworkModule;
@@ -145,7 +146,9 @@
145146
import org.opensearch.index.engine.Segment;
146147
import org.opensearch.index.mapper.CompletionFieldMapper;
147148
import org.opensearch.index.mapper.MockFieldFilterPlugin;
149+
import org.opensearch.index.remote.RemoteStoreEnums;
148150
import org.opensearch.index.remote.RemoteStoreEnums.PathType;
151+
import org.opensearch.index.remote.RemoteStorePathStrategy;
149152
import org.opensearch.index.shard.IndexShard;
150153
import org.opensearch.index.store.Store;
151154
import org.opensearch.index.translog.Translog;
@@ -161,6 +164,7 @@
161164
import org.opensearch.node.remotestore.RemoteStoreNodeService;
162165
import org.opensearch.plugins.NetworkPlugin;
163166
import org.opensearch.plugins.Plugin;
167+
import org.opensearch.repositories.IndexId;
164168
import org.opensearch.repositories.blobstore.BlobStoreRepository;
165169
import org.opensearch.repositories.fs.FsRepository;
166170
import org.opensearch.repositories.fs.ReloadableFsRepository;
@@ -227,6 +231,7 @@
227231
import static org.opensearch.index.IndexSettings.INDEX_DOC_ID_FUZZY_SET_FALSE_POSITIVE_PROBABILITY_SETTING;
228232
import static org.opensearch.index.IndexSettings.INDEX_SOFT_DELETES_RETENTION_LEASE_PERIOD_SETTING;
229233
import static org.opensearch.index.query.QueryBuilders.matchAllQuery;
234+
import static org.opensearch.index.remote.RemoteStoreEnums.PathHashAlgorithm.FNV_1A_COMPOSITE_1;
230235
import static org.opensearch.indices.IndicesService.CLUSTER_REPLICATION_TYPE_SETTING;
231236
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY;
232237
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX;
@@ -2903,4 +2908,16 @@ private static Settings buildRemoteStoreNodeAttributes(
29032908
settings.put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_PINNED_TIMESTAMP_ENABLED.getKey(), false);
29042909
return settings.build();
29052910
}
2911+
2912+
public static String resolvePath(IndexId indexId, String shardId) {
2913+
PathType pathType = PathType.fromCode(indexId.getShardPathType());
2914+
RemoteStorePathStrategy.SnapshotShardPathInput shardPathInput = new RemoteStorePathStrategy.SnapshotShardPathInput.Builder()
2915+
.basePath(BlobPath.cleanPath())
2916+
.indexUUID(indexId.getId())
2917+
.shardId(shardId)
2918+
.build();
2919+
RemoteStoreEnums.PathHashAlgorithm pathHashAlgorithm = pathType != PathType.FIXED ? FNV_1A_COMPOSITE_1 : null;
2920+
BlobPath blobPath = pathType.path(shardPathInput, pathHashAlgorithm);
2921+
return blobPath.buildAsString();
2922+
}
29062923
}

0 commit comments

Comments
 (0)