Skip to content

Commit 74d01b1

Browse files
rajiv-kvakolarkunnu
authored andcommitted
introduce a setting to disable full cluster state from remote on term mismatch (opensearch-project#16798)
Signed-off-by: Rajiv Kumar Vaidyanathan <rajivkv@amazon.com>
1 parent d51236c commit 74d01b1

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2323
- Add stats for remote publication failure and move download failure stats to remote methods([#16682](https://github.com/opensearch-project/OpenSearch/pull/16682/))
2424
- Added a precaution to handle extreme date values during sorting to prevent `arithmetic_exception: long overflow` ([#16812](https://github.com/opensearch-project/OpenSearch/pull/16812)).
2525
- Add search replica stats to segment replication stats API ([#16678](https://github.com/opensearch-project/OpenSearch/pull/16678))
26+
- Introduce a setting to disable download of full cluster state from remote on term mismatch([#16798](https://github.com/opensearch-project/OpenSearch/pull/16798/))
2627

2728
### Dependencies
2829
- Bump `com.google.cloud:google-cloud-core-http` from 2.23.0 to 2.47.0 ([#16504](https://github.com/opensearch-project/OpenSearch/pull/16504))

server/src/main/java/org/opensearch/action/support/clustermanager/term/TransportGetTermVersionAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private GetTermVersionResponse buildResponse(GetTermVersionRequest request, Clus
9898
ClusterStateTermVersion termVersion = new ClusterStateTermVersion(state);
9999
if (discovery instanceof Coordinator) {
100100
Coordinator coordinator = (Coordinator) discovery;
101-
if (coordinator.isRemotePublicationEnabled()) {
101+
if (coordinator.canDownloadFullStateFromRemote()) {
102102
return new GetTermVersionResponse(termVersion, coordinator.isRemotePublicationEnabled());
103103
}
104104
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,4 +1906,12 @@ public boolean isRemotePublicationEnabled() {
19061906
}
19071907
return false;
19081908
}
1909+
1910+
public boolean canDownloadFullStateFromRemote() {
1911+
if (remoteClusterStateService != null) {
1912+
return remoteClusterStateService.isRemotePublicationEnabled() && remoteClusterStateService.canDownloadFromRemoteForReadAPI();
1913+
}
1914+
return false;
1915+
}
1916+
19091917
}

server/src/main/java/org/opensearch/common/settings/ClusterSettings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ public void apply(Settings value, Settings current, Settings previous) {
738738
RemoteClusterStateCleanupManager.REMOTE_CLUSTER_STATE_CLEANUP_INTERVAL_SETTING,
739739
RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING,
740740
RemoteClusterStateService.REMOTE_PUBLICATION_SETTING,
741+
RemoteClusterStateService.REMOTE_STATE_DOWNLOAD_TO_SERVE_READ_API,
742+
741743
INDEX_METADATA_UPLOAD_TIMEOUT_SETTING,
742744
GLOBAL_METADATA_UPLOAD_TIMEOUT_SETTING,
743745
METADATA_MANIFEST_UPLOAD_TIMEOUT_SETTING,

server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public class RemoteClusterStateService implements Closeable {
129129
* Gates the functionality of remote publication.
130130
*/
131131
public static final String REMOTE_PUBLICATION_SETTING_KEY = "cluster.remote_store.publication.enabled";
132+
public static final String REMOTE_STATE_DOWNLOAD_TO_SERVE_READ_API_KEY = "cluster.remote_state.download.serve_read_api.enabled";
132133

133134
public static final Setting<Boolean> REMOTE_PUBLICATION_SETTING = Setting.boolSetting(
134135
REMOTE_PUBLICATION_SETTING_KEY,
@@ -137,6 +138,13 @@ public class RemoteClusterStateService implements Closeable {
137138
Property.Dynamic
138139
);
139140

141+
public static final Setting<Boolean> REMOTE_STATE_DOWNLOAD_TO_SERVE_READ_API = Setting.boolSetting(
142+
REMOTE_STATE_DOWNLOAD_TO_SERVE_READ_API_KEY,
143+
true,
144+
Property.NodeScope,
145+
Property.Dynamic
146+
);
147+
140148
/**
141149
* Used to specify if cluster state metadata should be published to remote store
142150
*/
@@ -235,6 +243,9 @@ public static RemoteClusterStateValidationMode parseString(String mode) {
235243
+ "indices, coordination metadata updated : [{}], settings metadata updated : [{}], templates metadata "
236244
+ "updated : [{}], custom metadata updated : [{}], indices routing updated : [{}]";
237245
private volatile AtomicBoolean isPublicationEnabled;
246+
247+
private volatile AtomicBoolean downloadFromRemoteForReadAPI;
248+
238249
private final String remotePathPrefix;
239250

240251
private final RemoteClusterStateCache remoteClusterStateCache;
@@ -281,6 +292,8 @@ public RemoteClusterStateService(
281292
&& RemoteStoreNodeAttribute.isRemoteRoutingTableConfigured(settings)
282293
);
283294
clusterSettings.addSettingsUpdateConsumer(REMOTE_PUBLICATION_SETTING, this::setRemotePublicationSetting);
295+
this.downloadFromRemoteForReadAPI = new AtomicBoolean(clusterSettings.get(REMOTE_STATE_DOWNLOAD_TO_SERVE_READ_API));
296+
clusterSettings.addSettingsUpdateConsumer(REMOTE_STATE_DOWNLOAD_TO_SERVE_READ_API, this::setRemoteDownloadForReadAPISetting);
284297
this.remotePathPrefix = CLUSTER_REMOTE_STORE_STATE_PATH_PREFIX.get(settings);
285298
this.remoteRoutingTableService = RemoteRoutingTableServiceFactory.getService(
286299
repositoriesService,
@@ -1124,6 +1137,14 @@ private void setRemotePublicationSetting(boolean remotePublicationSetting) {
11241137
}
11251138
}
11261139

1140+
private void setRemoteDownloadForReadAPISetting(boolean remoteDownloadForReadAPISetting) {
1141+
this.downloadFromRemoteForReadAPI.set(remoteDownloadForReadAPISetting);
1142+
}
1143+
1144+
public boolean canDownloadFromRemoteForReadAPI() {
1145+
return this.downloadFromRemoteForReadAPI.get();
1146+
}
1147+
11271148
// Package private for unit test
11281149
RemoteRoutingTableService getRemoteRoutingTableService() {
11291150
return this.remoteRoutingTableService;

0 commit comments

Comments
 (0)