Skip to content

Commit

Permalink
Check older source-only repos are supported (elastic#82213)
Browse files Browse the repository at this point in the history
Checks that archive functionality works with source-only repositories.

Relates elastic#80160
  • Loading branch information
ywelsch authored and astefan committed Jan 7, 2022
1 parent e7864f7 commit 2f41736
Showing 1 changed file with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.core.internal.io.IOUtils;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
Expand Down Expand Up @@ -71,10 +72,22 @@ protected static RestHighLevelClient highLevelClient(RestClient client) {
};
}

@SuppressWarnings("removal")
public void testOldRepoAccess() throws IOException {
runTest(false);
}

public void testOldSourceOnlyRepoAccess() throws IOException {
runTest(true);
}

@SuppressWarnings("removal")
public void runTest(boolean sourceOnlyRepository) throws IOException {
String repoLocation = System.getProperty("tests.repo.location");
Version oldVersion = Version.fromString(System.getProperty("tests.es.version"));
assumeTrue(
"source only repositories only supported since ES 6.5.0",
sourceOnlyRepository == false || oldVersion.onOrAfter(Version.fromString("6.5.0"))
);

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

for (int i = 0; i < numDocs; i++) {
String id = "testdoc" + i;
expectedIds.add(id);
Request doc = new Request("PUT", "/test/doc/" + id);
doc.addParameter("refresh", "true");
doc.setJsonEntity(sourceForDoc(i));
oldEs.performRequest(doc);
assertOK(oldEs.performRequest(doc));
}

// register repo on old ES and take snapshot
Request createRepoRequest = new Request("PUT", "/_snapshot/testrepo");
createRepoRequest.setJsonEntity("""
createRepoRequest.setJsonEntity(sourceOnlyRepository ? """
{"type":"source","settings":{"location":"%s","delegate_type":"fs"}}
""".formatted(repoLocation) : """
{"type":"fs","settings":{"location":"%s"}}
""".formatted(repoLocation));
oldEs.performRequest(createRepoRequest);
assertOK(oldEs.performRequest(createRepoRequest));

Request createSnapshotRequest = new Request("PUT", "/_snapshot/testrepo/snap1");
createSnapshotRequest.addParameter("wait_for_completion", "true");
createSnapshotRequest.setJsonEntity("{\"indices\":\"test\"}");
oldEs.performRequest(createSnapshotRequest);
assertOK(oldEs.performRequest(createSnapshotRequest));

// register repo on new ES
Settings.Builder repoSettingsBuilder = Settings.builder().put("location", repoLocation);
if (sourceOnlyRepository) {
repoSettingsBuilder.put("delegate_type", "fs");
}
if (Build.CURRENT.isSnapshot()) {
repoSettingsBuilder.put("allow_bwc_indices", true);
}
ElasticsearchAssertions.assertAcked(
client.snapshot()
.createRepository(
new PutRepositoryRequest("testrepo").type("fs").settings(repoSettingsBuilder),
new PutRepositoryRequest("testrepo").type(sourceOnlyRepository ? "source" : "fs").settings(repoSettingsBuilder),
RequestOptions.DEFAULT
)
);
Expand Down Expand Up @@ -193,7 +211,19 @@ public void testOldRepoAccess() throws IOException {
restoreMountAndVerify(numDocs, expectedIds, client, numberOfShards);
}
} finally {
oldEs.performRequest(new Request("DELETE", "/test"));
IOUtils.closeWhileHandlingException(
() -> oldEs.performRequest(new Request("DELETE", "/test")),
() -> oldEs.performRequest(new Request("DELETE", "/_snapshot/testrepo/snap1")),
() -> oldEs.performRequest(new Request("DELETE", "/_snapshot/testrepo"))
);
if (Build.CURRENT.isSnapshot()) {
IOUtils.closeWhileHandlingException(
() -> client().performRequest(new Request("DELETE", "/restored_test")),
() -> client().performRequest(new Request("DELETE", "/mounted_full_copy_test")),
() -> client().performRequest(new Request("DELETE", "/mounted_shared_cache_test"))
);
}
IOUtils.closeWhileHandlingException(() -> client().performRequest(new Request("DELETE", "/_snapshot/testrepo")));
}
}
}
Expand Down

0 comments on commit 2f41736

Please sign in to comment.