Skip to content

Commit

Permalink
Fix system_repository setting is restored after cluster metadata reco…
Browse files Browse the repository at this point in the history
…very from local disk (#10556)

Signed-off-by: bansvaru <[email protected]>
  • Loading branch information
linuxpi authored Oct 12, 2023
1 parent 90c4297 commit 9c06228
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,31 @@

package org.opensearch.remotestore;

import org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesAction;
import org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest;
import org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse;
import org.opensearch.client.Client;
import org.opensearch.cluster.metadata.RepositoryMetadata;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.common.unit.ByteSizeValue;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.plugins.Plugin;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.disruption.NetworkDisruption;
import org.opensearch.test.transport.MockTransportService;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

import static org.opensearch.repositories.blobstore.BlobStoreRepository.SYSTEM_REPOSITORY_SETTING;

@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0)
public class RemoteStoreRepositoryRegistrationIT extends RemoteStoreBaseIntegTestCase {

Expand Down Expand Up @@ -162,4 +172,13 @@ public void testNodeRestartPostNonRestrictedSettingsUpdate() throws Exception {

ensureStableCluster(4);
}

public void testSystemRepositorySettingIsHiddenForGetRepositoriesRequest() throws IOException {
GetRepositoriesRequest request = new GetRepositoriesRequest(new String[] { REPOSITORY_NAME });
GetRepositoriesResponse repositoriesResponse = client().execute(GetRepositoriesAction.INSTANCE, request).actionGet();
XContentBuilder builder = MediaTypeRegistry.contentBuilder(randomFrom(XContentType.JSON));
XContentBuilder xContentBuilder = repositoriesResponse.toXContent(builder, ToXContent.EMPTY_PARAMS);
repositoriesResponse = GetRepositoriesResponse.fromXContent(createParser(xContentBuilder));
assertEquals(false, SYSTEM_REPOSITORY_SETTING.get(repositoriesResponse.repositories().get(0).settings()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
import org.opensearch.core.xcontent.XContentParser;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;

Expand Down Expand Up @@ -83,7 +83,10 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.startObject();
repositories.toXContent(
builder,
new DelegatingMapParams(Collections.singletonMap(RepositoriesMetadata.HIDE_GENERATIONS_PARAM, "true"), params)
new DelegatingMapParams(
Map.of(RepositoriesMetadata.HIDE_GENERATIONS_PARAM, "true", RepositoriesMetadata.HIDE_SYSTEM_REPOSITORY_SETTING, "true"),
params
)
);
builder.endObject();
return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class RepositoriesMetadata extends AbstractNamedDiffable<Custom> implemen
* in {@link org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse}.
*/
public static final String HIDE_GENERATIONS_PARAM = "hide_generations";
public static final String HIDE_SYSTEM_REPOSITORY_SETTING = "hide_system_repository_setting";

private final List<RepositoryMetadata> repositories;

Expand Down Expand Up @@ -291,7 +292,7 @@ public static void toXContent(RepositoryMetadata repository, XContentBuilder bui
repository.cryptoMetadata().toXContent(repository.cryptoMetadata(), builder, params);
}
Settings settings = repository.settings();
if (SYSTEM_REPOSITORY_SETTING.get(settings)) {
if (SYSTEM_REPOSITORY_SETTING.get(settings) && params.paramAsBoolean(HIDE_SYSTEM_REPOSITORY_SETTING, false)) {
settings = repository.settings().filter(s -> !s.equals(SYSTEM_REPOSITORY_SETTING.getKey()));
}
builder.startObject("settings");
Expand Down

0 comments on commit 9c06228

Please sign in to comment.