@@ -178,6 +178,14 @@ public PublishClusterStateStats stats() {
178
178
);
179
179
}
180
180
181
+ public PersistedStateStats getFullDownloadStats () {
182
+ return remoteClusterStateService .getFullDownloadStats ();
183
+ }
184
+
185
+ public PersistedStateStats getDiffDownloadStats () {
186
+ return remoteClusterStateService .getDiffDownloadStats ();
187
+ }
188
+
181
189
private PublishWithJoinResponse handleIncomingPublishRequest (BytesTransportRequest request ) throws IOException {
182
190
try (StreamInput in = CompressedStreamUtils .decompressBytes (request , namedWriteableRegistry )) {
183
191
ClusterState incomingState ;
@@ -231,69 +239,78 @@ private PublishWithJoinResponse handleIncomingPublishRequest(BytesTransportReque
231
239
}
232
240
233
241
// package private for testing
234
- PublishWithJoinResponse handleIncomingRemotePublishRequest (RemotePublishRequest request ) throws IOException {
235
- if (transportService .getLocalNode ().equals (request .getSourceNode ())) {
236
- return acceptRemoteStateOnLocalNode (request );
237
- }
238
- // TODO Make cluster state download non-blocking: https://github.com/opensearch-project/OpenSearch/issues/14102
239
- ClusterMetadataManifest manifest = remoteClusterStateService .getClusterMetadataManifestByFileName (
240
- request .getClusterUUID (),
241
- request .getManifestFile ()
242
- );
243
- if (manifest == null ) {
244
- throw new IllegalStateException ("Publication failed as manifest was not found for " + request );
245
- }
242
+ PublishWithJoinResponse handleIncomingRemotePublishRequest (RemotePublishRequest request ) throws IOException , IllegalStateException {
246
243
boolean applyFullState = false ;
247
- final ClusterState lastSeen = lastSeenClusterState .get ();
248
- if (lastSeen == null ) {
249
- logger .debug (() -> "Diff cannot be applied as there is no last cluster state" );
250
- applyFullState = true ;
251
- } else if (manifest .getDiffManifest () == null ) {
252
- logger .trace (() -> "There is no diff in the manifest" );
253
- applyFullState = true ;
254
- } else if (manifest .getDiffManifest ().getFromStateUUID ().equals (lastSeen .stateUUID ()) == false ) {
255
- logger .debug (() -> "Last cluster state not compatible with the diff" );
256
- applyFullState = true ;
257
- }
258
-
259
- if (applyFullState == true ) {
260
- logger .debug (
261
- () -> new ParameterizedMessage (
262
- "Downloading full cluster state for term {}, version {}, stateUUID {}" ,
263
- manifest .getClusterTerm (),
264
- manifest .getStateVersion (),
265
- manifest .getStateUUID ()
266
- )
267
- );
268
- ClusterState clusterState = remoteClusterStateService .getClusterStateForManifest (
269
- request .getClusterName (),
270
- manifest ,
271
- transportService .getLocalNode ().getId (),
272
- true
273
- );
274
- fullClusterStateReceivedCount .incrementAndGet ();
275
- final PublishWithJoinResponse response = acceptState (clusterState );
276
- lastSeenClusterState .set (clusterState );
277
- return response ;
278
- } else {
279
- logger .debug (
280
- () -> new ParameterizedMessage (
281
- "Downloading diff cluster state for term {}, version {}, previousUUID {}, current UUID {}" ,
282
- manifest .getClusterTerm (),
283
- manifest .getStateVersion (),
284
- manifest .getDiffManifest ().getFromStateUUID (),
285
- manifest .getStateUUID ()
286
- )
287
- );
288
- ClusterState clusterState = remoteClusterStateService .getClusterStateUsingDiff (
289
- manifest ,
290
- lastSeen ,
291
- transportService .getLocalNode ().getId ()
244
+ try {
245
+ if (transportService .getLocalNode ().equals (request .getSourceNode ())) {
246
+ return acceptRemoteStateOnLocalNode (request );
247
+ }
248
+ // TODO Make cluster state download non-blocking: https://github.com/opensearch-project/OpenSearch/issues/14102
249
+ ClusterMetadataManifest manifest = remoteClusterStateService .getClusterMetadataManifestByFileName (
250
+ request .getClusterUUID (),
251
+ request .getManifestFile ()
292
252
);
293
- compatibleClusterStateDiffReceivedCount .incrementAndGet ();
294
- final PublishWithJoinResponse response = acceptState (clusterState );
295
- lastSeenClusterState .compareAndSet (lastSeen , clusterState );
296
- return response ;
253
+ if (manifest == null ) {
254
+ throw new IllegalStateException ("Publication failed as manifest was not found for " + request );
255
+ }
256
+ final ClusterState lastSeen = lastSeenClusterState .get ();
257
+ if (lastSeen == null ) {
258
+ logger .debug (() -> "Diff cannot be applied as there is no last cluster state" );
259
+ applyFullState = true ;
260
+ } else if (manifest .getDiffManifest () == null ) {
261
+ logger .debug (() -> "There is no diff in the manifest" );
262
+ applyFullState = true ;
263
+ } else if (manifest .getDiffManifest ().getFromStateUUID ().equals (lastSeen .stateUUID ()) == false ) {
264
+ logger .debug (() -> "Last cluster state not compatible with the diff" );
265
+ applyFullState = true ;
266
+ }
267
+
268
+ if (applyFullState == true ) {
269
+ logger .debug (
270
+ () -> new ParameterizedMessage (
271
+ "Downloading full cluster state for term {}, version {}, stateUUID {}" ,
272
+ manifest .getClusterTerm (),
273
+ manifest .getStateVersion (),
274
+ manifest .getStateUUID ()
275
+ )
276
+ );
277
+ ClusterState clusterState = remoteClusterStateService .getClusterStateForManifest (
278
+ request .getClusterName (),
279
+ manifest ,
280
+ transportService .getLocalNode ().getId (),
281
+ true
282
+ );
283
+ fullClusterStateReceivedCount .incrementAndGet ();
284
+ final PublishWithJoinResponse response = acceptState (clusterState );
285
+ lastSeenClusterState .set (clusterState );
286
+ return response ;
287
+ } else {
288
+ logger .debug (
289
+ () -> new ParameterizedMessage (
290
+ "Downloading diff cluster state for term {}, version {}, previousUUID {}, current UUID {}" ,
291
+ manifest .getClusterTerm (),
292
+ manifest .getStateVersion (),
293
+ manifest .getDiffManifest ().getFromStateUUID (),
294
+ manifest .getStateUUID ()
295
+ )
296
+ );
297
+ ClusterState clusterState = remoteClusterStateService .getClusterStateUsingDiff (
298
+ manifest ,
299
+ lastSeen ,
300
+ transportService .getLocalNode ().getId ()
301
+ );
302
+ compatibleClusterStateDiffReceivedCount .incrementAndGet ();
303
+ final PublishWithJoinResponse response = acceptState (clusterState );
304
+ lastSeenClusterState .compareAndSet (lastSeen , clusterState );
305
+ return response ;
306
+ }
307
+ } catch (Exception e ) {
308
+ if (applyFullState ) {
309
+ remoteClusterStateService .fullDownloadFailed ();
310
+ } else {
311
+ remoteClusterStateService .diffDownloadFailed ();
312
+ }
313
+ throw e ;
297
314
}
298
315
}
299
316
0 commit comments