Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Fix custom metadata not getting stored for remote store not supporting async write #10828

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -233,8 +234,7 @@ public void testFullClusterRestoreGlobalMetadata() throws Exception {
String prevClusterUUID = clusterService().state().metadata().clusterUUID();

// Create global metadata - register a custom repo
// TODO - uncomment after all customs is also uploaded for all repos - https://github.com/opensearch-project/OpenSearch/issues/10691
// registerCustomRepository();
Path repoPath = registerCustomRepository();

// Create global metadata - persistent settings
updatePersistentSettings(Settings.builder().put(SETTING_CLUSTER_MAX_SHARDS_PER_NODE.getKey(), 34).build());
Expand Down Expand Up @@ -263,30 +263,36 @@ public void testFullClusterRestoreGlobalMetadata() throws Exception {
verifyRedIndicesAndTriggerRestore(indexStats, INDEX_NAME, false);

// validate global metadata restored
verifyRestoredRepositories();
verifyRestoredRepositories(repoPath);
verifyRestoredIndexTemplate();
}

private void registerCustomRepository() {
private Path registerCustomRepository() {
Path path = randomRepoPath();
assertAcked(
client().admin()
.cluster()
.preparePutRepository("custom-repo")
.setType("fs")
.setSettings(Settings.builder().put("location", randomRepoPath()).put("compress", false))
.setSettings(Settings.builder().put("location", path).put("compress", false))
.get()
);
return path;
}

private void verifyRestoredRepositories() {
private void verifyRestoredRepositories(Path repoPath) {
RepositoriesMetadata repositoriesMetadata = clusterService().state().metadata().custom(RepositoriesMetadata.TYPE);
assertEquals(2, repositoriesMetadata.repositories().size()); // includes remote store repo as well
assertEquals(3, repositoriesMetadata.repositories().size()); // includes remote store repo as well
assertTrue(SYSTEM_REPOSITORY_SETTING.get(repositoriesMetadata.repository(REPOSITORY_NAME).settings()));
assertTrue(SYSTEM_REPOSITORY_SETTING.get(repositoriesMetadata.repository(REPOSITORY_2_NAME).settings()));
// TODO - uncomment after all customs is also uploaded for all repos - https://github.com/opensearch-project/OpenSearch/issues/10691
// assertEquals("fs", repositoriesMetadata.repository("custom-repo").type());
// assertEquals(Settings.builder().put("location", randomRepoPath()).put("compress", false).build(),
// repositoriesMetadata.repository("custom-repo").settings());
assertEquals("fs", repositoriesMetadata.repository("custom-repo").type());
assertEquals(
Settings.builder().put("location", repoPath).put("compress", false).build(),
repositoriesMetadata.repository("custom-repo").settings()
);

// repo cleanup post verification
clusterAdmin().prepareDeleteRepository("custom-repo").get();
}

private void addClusterLevelReadOnlyBlock() throws InterruptedException, ExecutionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,13 @@ private ClusterMetadataManifest uploadManifest(
private void writeMetadataManifest(String clusterName, String clusterUUID, ClusterMetadataManifest uploadManifest, String fileName)
throws IOException {
final BlobContainer metadataManifestContainer = manifestContainer(clusterName, clusterUUID);
CLUSTER_METADATA_MANIFEST_FORMAT.write(uploadManifest, metadataManifestContainer, fileName, blobStoreRepository.getCompressor());
CLUSTER_METADATA_MANIFEST_FORMAT.write(
uploadManifest,
metadataManifestContainer,
fileName,
blobStoreRepository.getCompressor(),
FORMAT_PARAMS
);
}

private String fetchPreviousClusterUUID(String clusterName, String clusterUUID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,29 @@ public T deserialize(String blobName, NamedXContentRegistry namedXContentRegistr
* @param compressor whether to use compression
*/
public void write(final T obj, final BlobContainer blobContainer, final String name, final Compressor compressor) throws IOException {
write(obj, blobContainer, name, compressor, SNAPSHOT_ONLY_FORMAT_PARAMS);
}

/**
* Writes blob with resolving the blob name using {@link #blobName} method.
* <p>
* The blob will optionally by compressed.
*
* @param obj object to be serialized
* @param blobContainer blob container
* @param name blob name
* @param compressor whether to use compression
* @param params ToXContent params
*/
public void write(
final T obj,
final BlobContainer blobContainer,
final String name,
final Compressor compressor,
final ToXContent.Params params
) throws IOException {
final String blobName = blobName(name);
final BytesReference bytes = serialize(obj, blobName, compressor, SNAPSHOT_ONLY_FORMAT_PARAMS);
final BytesReference bytes = serialize(obj, blobName, compressor, params);
blobContainer.writeBlob(blobName, bytes.streamInput(), bytes.length(), false);
}

Expand All @@ -195,7 +216,7 @@ public void writeAsync(
final ToXContent.Params params
) throws IOException {
if (blobContainer instanceof AsyncMultiStreamBlobContainer == false) {
write(obj, blobContainer, name, compressor);
write(obj, blobContainer, name, compressor, params);
listener.onResponse(null);
return;
}
Expand Down
Loading