Skip to content

Commit 689cfca

Browse files
authored
[Remote State] Disable remote publication if remote state disabled (opensearch-project#15219)
* Disable remote publication if remote state disabled Signed-off-by: Shivansh Arora <[email protected]>
1 parent 6152afe commit 689cfca

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

server/src/internalClusterTest/java/org/opensearch/gateway/remote/RemoteStatePublicationIT.java

+21-3
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,22 @@
5050
public class RemoteStatePublicationIT extends RemoteStoreBaseIntegTestCase {
5151

5252
private static String INDEX_NAME = "test-index";
53+
private boolean isRemoteStateEnabled = true;
54+
private String isRemotePublicationEnabled = "true";
5355

5456
@Before
5557
public void setup() {
5658
asyncUploadMockFsRepo = false;
59+
isRemoteStateEnabled = true;
60+
isRemotePublicationEnabled = "true";
5761
}
5862

5963
@Override
6064
protected Settings featureFlagSettings() {
61-
return Settings.builder().put(super.featureFlagSettings()).put(FeatureFlags.REMOTE_PUBLICATION_EXPERIMENTAL, "true").build();
65+
return Settings.builder()
66+
.put(super.featureFlagSettings())
67+
.put(FeatureFlags.REMOTE_PUBLICATION_EXPERIMENTAL, isRemotePublicationEnabled)
68+
.build();
6269
}
6370

6471
@Override
@@ -76,7 +83,7 @@ protected Settings nodeSettings(int nodeOrdinal) {
7683
);
7784
return Settings.builder()
7885
.put(super.nodeSettings(nodeOrdinal))
79-
.put(REMOTE_CLUSTER_STATE_ENABLED_SETTING.getKey(), true)
86+
.put(REMOTE_CLUSTER_STATE_ENABLED_SETTING.getKey(), isRemoteStateEnabled)
8087
.put("node.attr." + REMOTE_STORE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEY, routingTableRepoName)
8188
.put(routingTableRepoTypeAttributeKey, ReloadableFsRepository.TYPE)
8289
.put(routingTableRepoSettingsAttributeKeyPrefix + "location", segmentRepoPath)
@@ -136,6 +143,18 @@ public void testPublication() throws Exception {
136143
}
137144
}
138145

146+
public void testRemotePublicationDisableIfRemoteStateDisabled() {
147+
// only disable remote state
148+
isRemoteStateEnabled = false;
149+
// create cluster with multi node with in-consistent settings
150+
prepareCluster(3, 2, INDEX_NAME, 1, 2);
151+
// assert cluster is stable, ensuring publication falls back to legacy transport with inconsistent settings
152+
ensureStableCluster(5);
153+
ensureGreen(INDEX_NAME);
154+
155+
assertNull(internalCluster().getCurrentClusterManagerNodeInstance(RemoteClusterStateService.class));
156+
}
157+
139158
private Map<String, Integer> getMetadataFiles(BlobStoreRepository repository, String subDirectory) throws IOException {
140159
BlobPath metadataPath = repository.basePath()
141160
.add(
@@ -151,5 +170,4 @@ private Map<String, Integer> getMetadataFiles(BlobStoreRepository repository, St
151170
return fileName.split(DELIMITER)[0];
152171
}).collect(Collectors.toMap(Function.identity(), key -> 1, Integer::sum));
153172
}
154-
155173
}

server/src/main/java/org/opensearch/cluster/coordination/CoordinationState.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public CoordinationState(
105105
.getLastAcceptedConfiguration();
106106
this.publishVotes = new VoteCollection();
107107
this.isRemoteStateEnabled = isRemoteStoreClusterStateEnabled(settings);
108-
this.isRemotePublicationEnabled = FeatureFlags.isEnabled(REMOTE_PUBLICATION_EXPERIMENTAL)
108+
this.isRemotePublicationEnabled = isRemoteStateEnabled
109+
&& FeatureFlags.isEnabled(REMOTE_PUBLICATION_EXPERIMENTAL)
109110
&& localNode.isRemoteStatePublicationEnabled();
110111
}
111112

server/src/test/java/org/opensearch/cluster/coordination/CoordinationStateTests.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666

6767
import static java.util.Collections.emptyMap;
6868
import static java.util.Collections.emptySet;
69+
import static org.opensearch.common.util.FeatureFlags.REMOTE_PUBLICATION_EXPERIMENTAL;
70+
import static org.opensearch.gateway.remote.RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING;
6971
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY;
7072
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_SETTINGS_ATTRIBUTE_KEY_PREFIX;
7173
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_REPOSITORY_TYPE_ATTRIBUTE_KEY_FORMAT;
@@ -971,7 +973,7 @@ public void testHandlePrePublishAndCommitWhenRemoteStateEnabled() throws IOExcep
971973
.put("node.attr." + REMOTE_STORE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEY, randomRepoName)
972974
.put(stateRepoTypeAttributeKey, FsRepository.TYPE)
973975
.put(stateRepoSettingsAttributeKeyPrefix + "location", "randomRepoPath")
974-
.put(RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING.getKey(), true)
976+
.put(REMOTE_CLUSTER_STATE_ENABLED_SETTING.getKey(), true)
975977
.build();
976978

977979
final CoordinationState coordinationState = createCoordinationState(persistedStateRegistry, node1, settings);
@@ -1002,6 +1004,16 @@ public void testHandlePrePublishAndCommitWhenRemoteStateEnabled() throws IOExcep
10021004
);
10031005
}
10041006

1007+
public void testIsRemotePublicationEnabled_WithInconsistentSettings() {
1008+
// create settings with remote state disabled but publication enabled
1009+
Settings settings = Settings.builder()
1010+
.put(REMOTE_CLUSTER_STATE_ENABLED_SETTING.getKey(), false)
1011+
.put(REMOTE_PUBLICATION_EXPERIMENTAL, true)
1012+
.build();
1013+
CoordinationState coordinationState = createCoordinationState(psr1, node1, settings);
1014+
assertFalse(coordinationState.isRemotePublicationEnabled());
1015+
}
1016+
10051017
public static CoordinationState createCoordinationState(
10061018
PersistedStateRegistry persistedStateRegistry,
10071019
DiscoveryNode localNode,

0 commit comments

Comments
 (0)