83
83
import java .util .concurrent .ConcurrentHashMap ;
84
84
import java .util .concurrent .CountDownLatch ;
85
85
import java .util .concurrent .TimeUnit ;
86
+ import java .util .concurrent .atomic .AtomicBoolean ;
86
87
import java .util .concurrent .atomic .AtomicReference ;
87
88
import java .util .function .Function ;
88
89
import java .util .function .LongSupplier ;
112
113
import static org .opensearch .gateway .remote .model .RemoteTransientSettingsMetadata .TRANSIENT_SETTING_METADATA ;
113
114
import static org .opensearch .gateway .remote .routingtable .RemoteIndexRoutingTable .INDEX_ROUTING_METADATA_PREFIX ;
114
115
import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .isRemoteClusterStateConfigured ;
116
+ import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .isRemoteRoutingTableConfigured ;
117
+ import static org .opensearch .node .remotestore .RemoteStoreNodeAttribute .isRemoteStoreClusterStateEnabled ;
115
118
116
119
/**
117
120
* A Service which provides APIs to upload and download cluster metadata from remote store.
@@ -132,7 +135,7 @@ public class RemoteClusterStateService implements Closeable {
132
135
REMOTE_PUBLICATION_SETTING_KEY ,
133
136
false ,
134
137
Property .NodeScope ,
135
- Property .Final
138
+ Property .Dynamic
136
139
);
137
140
138
141
/**
@@ -232,7 +235,7 @@ public static RemoteClusterStateValidationMode parseString(String mode) {
232
235
private final String METADATA_UPDATE_LOG_STRING = "wrote metadata for [{}] indices and skipped [{}] unchanged "
233
236
+ "indices, coordination metadata updated : [{}], settings metadata updated : [{}], templates metadata "
234
237
+ "updated : [{}], custom metadata updated : [{}], indices routing updated : [{}]" ;
235
- private final boolean isPublicationEnabled ;
238
+ private volatile AtomicBoolean isPublicationEnabled ;
236
239
private final String remotePathPrefix ;
237
240
238
241
private final RemoteClusterStateCache remoteClusterStateCache ;
@@ -273,9 +276,12 @@ public RemoteClusterStateService(
273
276
this .remoteStateStats = new RemotePersistenceStats ();
274
277
this .namedWriteableRegistry = namedWriteableRegistry ;
275
278
this .indexMetadataUploadListeners = indexMetadataUploadListeners ;
276
- this .isPublicationEnabled = REMOTE_PUBLICATION_SETTING .get (settings )
277
- && RemoteStoreNodeAttribute .isRemoteStoreClusterStateEnabled (settings )
278
- && RemoteStoreNodeAttribute .isRemoteRoutingTableEnabled (settings );
279
+ this .isPublicationEnabled = new AtomicBoolean (
280
+ clusterSettings .get (REMOTE_PUBLICATION_SETTING )
281
+ && RemoteStoreNodeAttribute .isRemoteStoreClusterStateEnabled (settings )
282
+ && RemoteStoreNodeAttribute .isRemoteRoutingTableConfigured (settings )
283
+ );
284
+ clusterSettings .addSettingsUpdateConsumer (REMOTE_PUBLICATION_SETTING , this ::setRemotePublicationSetting );
279
285
this .remotePathPrefix = CLUSTER_REMOTE_STORE_STATE_PATH_PREFIX .get (settings );
280
286
this .remoteRoutingTableService = RemoteRoutingTableServiceFactory .getService (
281
287
repositoriesService ,
@@ -303,19 +309,20 @@ public RemoteClusterStateManifestInfo writeFullMetadata(ClusterState clusterStat
303
309
return null ;
304
310
}
305
311
312
+ boolean publicationEnabled = isPublicationEnabled .get ();
306
313
UploadedMetadataResults uploadedMetadataResults = writeMetadataInParallel (
307
314
clusterState ,
308
315
new ArrayList <>(clusterState .metadata ().indices ().values ()),
309
316
emptyMap (),
310
- RemoteGlobalMetadataManager .filterCustoms (clusterState .metadata ().customs (), isPublicationEnabled ),
317
+ RemoteGlobalMetadataManager .filterCustoms (clusterState .metadata ().customs (), publicationEnabled ),
311
318
true ,
312
319
true ,
313
320
true ,
314
- isPublicationEnabled ,
315
- isPublicationEnabled ,
316
- isPublicationEnabled ,
317
- isPublicationEnabled ? clusterState .customs () : Collections .emptyMap (),
318
- isPublicationEnabled ,
321
+ publicationEnabled ,
322
+ publicationEnabled ,
323
+ publicationEnabled ,
324
+ publicationEnabled ? clusterState .customs () : Collections .emptyMap (),
325
+ publicationEnabled ,
319
326
remoteRoutingTableService .getIndicesRouting (clusterState .getRoutingTable ()),
320
327
null
321
328
);
@@ -394,9 +401,9 @@ public RemoteClusterStateManifestInfo writeIncrementalMetadata(
394
401
boolean firstUploadForSplitGlobalMetadata = !previousManifest .hasMetadataAttributesFiles ();
395
402
396
403
final DiffableUtils .MapDiff <String , Metadata .Custom , Map <String , Metadata .Custom >> customsDiff = remoteGlobalMetadataManager
397
- .getCustomsDiff (clusterState , previousClusterState , firstUploadForSplitGlobalMetadata , isPublicationEnabled );
404
+ .getCustomsDiff (clusterState , previousClusterState , firstUploadForSplitGlobalMetadata , isPublicationEnabled . get () );
398
405
final DiffableUtils .MapDiff <String , ClusterState .Custom , Map <String , ClusterState .Custom >> clusterStateCustomsDiff =
399
- remoteClusterStateAttributesManager .getUpdatedCustoms (clusterState , previousClusterState , isPublicationEnabled , false );
406
+ remoteClusterStateAttributesManager .getUpdatedCustoms (clusterState , previousClusterState , isPublicationEnabled . get () , false );
400
407
final Map <String , UploadedMetadataAttribute > allUploadedCustomMap = new HashMap <>(previousManifest .getCustomMetadataMap ());
401
408
final Map <String , UploadedMetadataAttribute > allUploadedClusterStateCustomsMap = new HashMap <>(
402
409
previousManifest .getClusterStateCustomMap ()
@@ -461,10 +468,10 @@ public RemoteClusterStateManifestInfo writeIncrementalMetadata(
461
468
boolean updateTemplatesMetadata = firstUploadForSplitGlobalMetadata
462
469
|| Metadata .isTemplatesMetadataEqual (previousClusterState .metadata (), clusterState .metadata ()) == false ;
463
470
464
- final boolean updateDiscoveryNodes = isPublicationEnabled
471
+ final boolean updateDiscoveryNodes = isPublicationEnabled . get ()
465
472
&& clusterState .getNodes ().delta (previousClusterState .getNodes ()).hasChanges ();
466
- final boolean updateClusterBlocks = isPublicationEnabled && !clusterState .blocks ().equals (previousClusterState .blocks ());
467
- final boolean updateHashesOfConsistentSettings = isPublicationEnabled
473
+ final boolean updateClusterBlocks = isPublicationEnabled . get () && !clusterState .blocks ().equals (previousClusterState .blocks ());
474
+ final boolean updateHashesOfConsistentSettings = isPublicationEnabled . get ()
468
475
&& Metadata .isHashesOfConsistentSettingsEqual (previousClusterState .metadata (), clusterState .metadata ()) == false ;
469
476
470
477
uploadedMetadataResults = writeMetadataInParallel (
@@ -1115,6 +1122,14 @@ private void setChecksumValidationMode(RemoteClusterStateValidationMode remoteCl
1115
1122
this .remoteClusterStateValidationMode = remoteClusterStateValidationMode ;
1116
1123
}
1117
1124
1125
+ private void setRemotePublicationSetting (boolean remotePublicationSetting ) {
1126
+ if (remotePublicationSetting == false ) {
1127
+ this .isPublicationEnabled .set (false );
1128
+ } else {
1129
+ this .isPublicationEnabled .set (isRemoteStoreClusterStateEnabled (settings ) && isRemoteRoutingTableConfigured (settings ));
1130
+ }
1131
+ }
1132
+
1118
1133
// Package private for unit test
1119
1134
RemoteRoutingTableService getRemoteRoutingTableService () {
1120
1135
return this .remoteRoutingTableService ;
@@ -1830,7 +1845,7 @@ public String getLastKnownUUIDFromRemote(String clusterName) {
1830
1845
}
1831
1846
1832
1847
public boolean isRemotePublicationEnabled () {
1833
- return this .isPublicationEnabled ;
1848
+ return this .isPublicationEnabled . get () ;
1834
1849
}
1835
1850
1836
1851
public void setRemoteStateReadTimeout (TimeValue remoteStateReadTimeout ) {
0 commit comments