diff --git a/server/src/main/java/org/opensearch/snapshots/RestoreService.java b/server/src/main/java/org/opensearch/snapshots/RestoreService.java index 2cb3576b41871..d216f368c1e3d 100644 --- a/server/src/main/java/org/opensearch/snapshots/RestoreService.java +++ b/server/src/main/java/org/opensearch/snapshots/RestoreService.java @@ -246,6 +246,26 @@ static Set 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. + *

+ * 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; @@ -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() { diff --git a/server/src/test/java/org/opensearch/snapshots/RestoreServiceTests.java b/server/src/test/java/org/opensearch/snapshots/RestoreServiceTests.java index f97ce2abc4d87..6705632c4f30f 100644 --- a/server/src/test/java/org/opensearch/snapshots/RestoreServiceTests.java +++ b/server/src/test/java/org/opensearch/snapshots/RestoreServiceTests.java @@ -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); + } }