Skip to content

Commit 2f41736

Browse files
ywelschastefan
authored andcommitted
Check older source-only repos are supported (elastic#82213)
Checks that archive functionality works with source-only repositories. Relates elastic#80160
1 parent e7864f7 commit 2f41736

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

x-pack/qa/repository-old-versions/src/test/java/org/elasticsearch/oldrepos/OldRepositoryAccessIT.java

+38-8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.common.settings.Settings;
3434
import org.elasticsearch.common.util.concurrent.ThreadContext;
3535
import org.elasticsearch.common.util.set.Sets;
36+
import org.elasticsearch.core.internal.io.IOUtils;
3637
import org.elasticsearch.index.query.QueryBuilders;
3738
import org.elasticsearch.search.SearchHit;
3839
import org.elasticsearch.search.builder.SearchSourceBuilder;
@@ -71,10 +72,22 @@ protected static RestHighLevelClient highLevelClient(RestClient client) {
7172
};
7273
}
7374

74-
@SuppressWarnings("removal")
7575
public void testOldRepoAccess() throws IOException {
76+
runTest(false);
77+
}
78+
79+
public void testOldSourceOnlyRepoAccess() throws IOException {
80+
runTest(true);
81+
}
82+
83+
@SuppressWarnings("removal")
84+
public void runTest(boolean sourceOnlyRepository) throws IOException {
7685
String repoLocation = System.getProperty("tests.repo.location");
7786
Version oldVersion = Version.fromString(System.getProperty("tests.es.version"));
87+
assumeTrue(
88+
"source only repositories only supported since ES 6.5.0",
89+
sourceOnlyRepository == false || oldVersion.onOrAfter(Version.fromString("6.5.0"))
90+
);
7891

7992
int oldEsPort = Integer.parseInt(System.getProperty("tests.es.port"));
8093
int numDocs = 5;
@@ -89,38 +102,43 @@ public void testOldRepoAccess() throws IOException {
89102
createIndex.setJsonEntity("""
90103
{"settings":{"number_of_shards": %s}}
91104
""".formatted(numberOfShards));
92-
oldEs.performRequest(createIndex);
105+
assertOK(oldEs.performRequest(createIndex));
93106

94107
for (int i = 0; i < numDocs; i++) {
95108
String id = "testdoc" + i;
96109
expectedIds.add(id);
97110
Request doc = new Request("PUT", "/test/doc/" + id);
98111
doc.addParameter("refresh", "true");
99112
doc.setJsonEntity(sourceForDoc(i));
100-
oldEs.performRequest(doc);
113+
assertOK(oldEs.performRequest(doc));
101114
}
102115

103116
// register repo on old ES and take snapshot
104117
Request createRepoRequest = new Request("PUT", "/_snapshot/testrepo");
105-
createRepoRequest.setJsonEntity("""
118+
createRepoRequest.setJsonEntity(sourceOnlyRepository ? """
119+
{"type":"source","settings":{"location":"%s","delegate_type":"fs"}}
120+
""".formatted(repoLocation) : """
106121
{"type":"fs","settings":{"location":"%s"}}
107122
""".formatted(repoLocation));
108-
oldEs.performRequest(createRepoRequest);
123+
assertOK(oldEs.performRequest(createRepoRequest));
109124

110125
Request createSnapshotRequest = new Request("PUT", "/_snapshot/testrepo/snap1");
111126
createSnapshotRequest.addParameter("wait_for_completion", "true");
112127
createSnapshotRequest.setJsonEntity("{\"indices\":\"test\"}");
113-
oldEs.performRequest(createSnapshotRequest);
128+
assertOK(oldEs.performRequest(createSnapshotRequest));
114129

115130
// register repo on new ES
116131
Settings.Builder repoSettingsBuilder = Settings.builder().put("location", repoLocation);
132+
if (sourceOnlyRepository) {
133+
repoSettingsBuilder.put("delegate_type", "fs");
134+
}
117135
if (Build.CURRENT.isSnapshot()) {
118136
repoSettingsBuilder.put("allow_bwc_indices", true);
119137
}
120138
ElasticsearchAssertions.assertAcked(
121139
client.snapshot()
122140
.createRepository(
123-
new PutRepositoryRequest("testrepo").type("fs").settings(repoSettingsBuilder),
141+
new PutRepositoryRequest("testrepo").type(sourceOnlyRepository ? "source" : "fs").settings(repoSettingsBuilder),
124142
RequestOptions.DEFAULT
125143
)
126144
);
@@ -193,7 +211,19 @@ public void testOldRepoAccess() throws IOException {
193211
restoreMountAndVerify(numDocs, expectedIds, client, numberOfShards);
194212
}
195213
} finally {
196-
oldEs.performRequest(new Request("DELETE", "/test"));
214+
IOUtils.closeWhileHandlingException(
215+
() -> oldEs.performRequest(new Request("DELETE", "/test")),
216+
() -> oldEs.performRequest(new Request("DELETE", "/_snapshot/testrepo/snap1")),
217+
() -> oldEs.performRequest(new Request("DELETE", "/_snapshot/testrepo"))
218+
);
219+
if (Build.CURRENT.isSnapshot()) {
220+
IOUtils.closeWhileHandlingException(
221+
() -> client().performRequest(new Request("DELETE", "/restored_test")),
222+
() -> client().performRequest(new Request("DELETE", "/mounted_full_copy_test")),
223+
() -> client().performRequest(new Request("DELETE", "/mounted_shared_cache_test"))
224+
);
225+
}
226+
IOUtils.closeWhileHandlingException(() -> client().performRequest(new Request("DELETE", "/_snapshot/testrepo")));
197227
}
198228
}
199229
}

0 commit comments

Comments
 (0)