Skip to content

Commit

Permalink
introduce a setting to disable full cluster state from remote on term…
Browse files Browse the repository at this point in the history
… mismatch

Signed-off-by: Rajiv Kumar Vaidyanathan <[email protected]>
  • Loading branch information
rajiv-kv committed Dec 12, 2024
1 parent 2b402ec commit bada1f7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add new configuration setting `synonym_analyzer`, to the `synonym` and `synonym_graph` filters, enabling the specification of a custom analyzer for reading the synonym file ([#16488](https://github.com/opensearch-project/OpenSearch/pull/16488)).
- Add stats for remote publication failure and move download failure stats to remote methods([#16682](https://github.com/opensearch-project/OpenSearch/pull/16682/))
- 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)).
- Introduce a setting to disable download of full cluster state from remote on term mismatch([#16798](https://github.com/opensearch-project/OpenSearch/pull/16798/))

### Dependencies
- 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private GetTermVersionResponse buildResponse(GetTermVersionRequest request, Clus
ClusterStateTermVersion termVersion = new ClusterStateTermVersion(state);
if (discovery instanceof Coordinator) {
Coordinator coordinator = (Coordinator) discovery;
if (coordinator.isRemotePublicationEnabled()) {
if (coordinator.canDownloadFullStateFromRemote()) {
return new GetTermVersionResponse(termVersion, coordinator.isRemotePublicationEnabled());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1906,4 +1906,12 @@ public boolean isRemotePublicationEnabled() {
}
return false;
}

public boolean canDownloadFullStateFromRemote() {
if (remoteClusterStateService != null) {
return remoteClusterStateService.isRemotePublicationEnabled() && remoteClusterStateService.canDownloadFromRemoteForReadAPI();
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ public void apply(Settings value, Settings current, Settings previous) {
RemoteClusterStateCleanupManager.REMOTE_CLUSTER_STATE_CLEANUP_INTERVAL_SETTING,
RemoteClusterStateService.REMOTE_CLUSTER_STATE_ENABLED_SETTING,
RemoteClusterStateService.REMOTE_PUBLICATION_SETTING,
RemoteClusterStateService.REMOTE_STATE_DOWNLOAD_TO_SERVE_READ_API,

INDEX_METADATA_UPLOAD_TIMEOUT_SETTING,
GLOBAL_METADATA_UPLOAD_TIMEOUT_SETTING,
METADATA_MANIFEST_UPLOAD_TIMEOUT_SETTING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public class RemoteClusterStateService implements Closeable {
* Gates the functionality of remote publication.
*/
public static final String REMOTE_PUBLICATION_SETTING_KEY = "cluster.remote_store.publication.enabled";
public static final String REMOTE_STATE_DOWNLOAD_TO_SERVE_READ_API_KEY = "cluster.remote_state.download.serve_read_api.enabled";

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

public static final Setting<Boolean> REMOTE_STATE_DOWNLOAD_TO_SERVE_READ_API = Setting.boolSetting(
REMOTE_STATE_DOWNLOAD_TO_SERVE_READ_API_KEY,
true,
Property.NodeScope,
Property.Dynamic
);

/**
* Used to specify if cluster state metadata should be published to remote store
*/
Expand Down Expand Up @@ -235,6 +243,9 @@ public static RemoteClusterStateValidationMode parseString(String mode) {
+ "indices, coordination metadata updated : [{}], settings metadata updated : [{}], templates metadata "
+ "updated : [{}], custom metadata updated : [{}], indices routing updated : [{}]";
private volatile AtomicBoolean isPublicationEnabled;

private volatile AtomicBoolean downloadFromRemoteForReadAPI;

private final String remotePathPrefix;

private final RemoteClusterStateCache remoteClusterStateCache;
Expand Down Expand Up @@ -281,6 +292,8 @@ public RemoteClusterStateService(
&& RemoteStoreNodeAttribute.isRemoteRoutingTableConfigured(settings)
);
clusterSettings.addSettingsUpdateConsumer(REMOTE_PUBLICATION_SETTING, this::setRemotePublicationSetting);
this.downloadFromRemoteForReadAPI = new AtomicBoolean(clusterSettings.get(REMOTE_STATE_DOWNLOAD_TO_SERVE_READ_API));
clusterSettings.addSettingsUpdateConsumer(REMOTE_STATE_DOWNLOAD_TO_SERVE_READ_API, this::setRemoteDownloadForReadAPISetting);
this.remotePathPrefix = CLUSTER_REMOTE_STORE_STATE_PATH_PREFIX.get(settings);
this.remoteRoutingTableService = RemoteRoutingTableServiceFactory.getService(
repositoriesService,
Expand Down Expand Up @@ -1124,6 +1137,14 @@ private void setRemotePublicationSetting(boolean remotePublicationSetting) {
}
}

private void setRemoteDownloadForReadAPISetting(boolean remoteDownloadForReadAPISetting) {
this.downloadFromRemoteForReadAPI.set(remoteDownloadForReadAPISetting);
}

Check warning on line 1142 in server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java#L1141-L1142

Added lines #L1141 - L1142 were not covered by tests

public boolean canDownloadFromRemoteForReadAPI() {
return this.downloadFromRemoteForReadAPI.get();

Check warning on line 1145 in server/src/main/java/org/opensearch/gateway/remote/RemoteClusterStateService.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1145 was not covered by tests
}

// Package private for unit test
RemoteRoutingTableService getRemoteRoutingTableService() {
return this.remoteRoutingTableService;
Expand Down

0 comments on commit bada1f7

Please sign in to comment.