Skip to content
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
33 changes: 23 additions & 10 deletions server/src/main/java/org/opensearch/snapshots/RestoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ static Set<String> getUserUnremovableSettings() {
return USER_UNREMOVABLE_SETTINGS;
}

/**
* Returns the internal index settings to be ignored (stripped) when restoring a snapshot
* onto a cluster that does not store index data remotely.
* <p>
* The remote data attribute check (segment/translog repositories) is used rather than the
* broader remote store attribute check, because clusters with only remote cluster state or
* routing table publication enabled do not store index data remotely and must still have
* {@code index.remote_store.*} settings stripped on restore.
*
* @param nodeSettings the node settings of the cluster performing the restore
* @return array of index setting patterns to ignore during restore
*/
static String[] getIgnoreSettingsInternal(Settings nodeSettings) {
String[] indexSettingsToBeIgnored = new String[] {};
if (false == RemoteStoreNodeAttribute.isRemoteDataAttributePresent(nodeSettings)) {
indexSettingsToBeIgnored = ArrayUtils.concat(indexSettingsToBeIgnored, new String[] { REMOTE_STORE_INDEX_SETTINGS_REGEX });
}
return indexSettingsToBeIgnored;
}

private final ClusterService clusterService;

private final RepositoriesService repositoriesService;
Expand Down Expand Up @@ -762,16 +782,9 @@ private void applyAliasesWithRename(
}

private String[] getIgnoreSettingsInternal() {
// for non-remote store enabled domain, we will remove all the remote store
// related index settings present in the snapshot.
String[] indexSettingsToBeIgnored = new String[] {};
if (false == RemoteStoreNodeAttribute.isRemoteStoreAttributePresent(clusterService.getSettings())) {
indexSettingsToBeIgnored = ArrayUtils.concat(
indexSettingsToBeIgnored,
new String[] { REMOTE_STORE_INDEX_SETTINGS_REGEX }
);
}
return indexSettingsToBeIgnored;
// for a domain that does not store index data remotely, we will remove all the
// remote store related index settings present in the snapshot.
return RestoreService.getIgnoreSettingsInternal(clusterService.getSettings());
}

private Settings getOverrideSettingsInternal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,33 @@ public void testUserIgnoreWorksForNonProtected() {
// User can filter non-protected settings
assertFalse(filter.test("index.custom.setting"));
}

// Tests for internal ignore settings gating on remote data attributes

public void testIgnoreSettingsInternalOnClusterWithoutRemoteAttributes() {
// A cluster with no remote store attributes must strip remote store index settings on restore
String[] ignoreSettings = RestoreService.getIgnoreSettingsInternal(Settings.EMPTY);
assertArrayEquals(new String[] { "index.remote_store.*" }, ignoreSettings);
}

public void testIgnoreSettingsInternalOnRemotePublicationOnlyCluster() {
// A cluster with only remote cluster state/routing table publication enabled does not
// store index data remotely, so remote store index settings must still be stripped
Settings nodeSettings = Settings.builder()
.put("node.attr.remote_publication.state.repository", "cluster-state-repo")
.put("node.attr.remote_publication.routing_table.repository", "routing-table-repo")
.build();
String[] ignoreSettings = RestoreService.getIgnoreSettingsInternal(nodeSettings);
assertArrayEquals(new String[] { "index.remote_store.*" }, ignoreSettings);
}

public void testIgnoreSettingsInternalOnRemoteDataCluster() {
// A cluster that stores index data remotely must preserve remote store index settings
Settings nodeSettings = Settings.builder()
.put("node.attr.remote_store.segment.repository", "segment-repo")
.put("node.attr.remote_store.translog.repository", "translog-repo")
.build();
String[] ignoreSettings = RestoreService.getIgnoreSettingsInternal(nodeSettings);
assertEquals(0, ignoreSettings.length);
}
}
Loading