@@ -301,16 +301,7 @@ protected void masterOperation(
301301 final TaskId parentTask = new TaskId (clusterService .localNode ().getId (), task .getId ());
302302 // Short circuit if target index has been downsampled:
303303 final String downsampleIndexName = request .getTargetIndex ();
304- if (canShortCircuit (
305- sourceIndexName ,
306- downsampleIndexName ,
307- parentTask ,
308- request .masterNodeTimeout (),
309- request .getWaitTimeout (),
310- startTime ,
311- projectMetadata ,
312- listener
313- )) {
304+ if (canShortCircuit (downsampleIndexName , parentTask , request .getWaitTimeout (), startTime , true , projectMetadata , listener )) {
314305 logger .info ("Skipping downsampling, because a previous execution already completed downsampling" );
315306 return ;
316307 }
@@ -479,73 +470,6 @@ private boolean isForceMergeEnabled(Map<String, Object> sourceIndexMappings) {
479470 return true ;
480471 }
481472
482- /**
483- * Shortcircuit when another downsample api invocation already completed successfully.
484- */
485- private boolean canShortCircuit (
486- String sourceIndexName ,
487- String targetIndexName ,
488- TaskId parentTask ,
489- TimeValue masterNodeTimeout ,
490- TimeValue waitTimeout ,
491- long startTime ,
492- ProjectMetadata projectMetadata ,
493- ActionListener <AcknowledgedResponse > listener
494- ) {
495- IndexMetadata targetIndexMetadata = projectMetadata .index (targetIndexName );
496- if (targetIndexMetadata == null ) {
497- return false ;
498- }
499-
500- var downsampleStatus = IndexMetadata .INDEX_DOWNSAMPLE_STATUS .get (targetIndexMetadata .getSettings ());
501- if (downsampleStatus == DownsampleTaskStatus .UNKNOWN ) {
502- // This isn't a downsample index, so fail:
503- listener .onFailure (new ResourceAlreadyExistsException (targetIndexMetadata .getIndex ()));
504- return true ;
505- } else if (downsampleStatus == DownsampleTaskStatus .SUCCESS ) {
506- listener .onResponse (AcknowledgedResponse .TRUE );
507- return true ;
508- }
509- // In case the write block has been set on the target index means that the shard level downsampling itself was successful,
510- // but the previous invocation failed later performing settings update, refresh or force merge.
511- // The write block is used a signal to resume from the refresh part of the downsample api invocation.
512- if (targetIndexMetadata .getSettings ().get (IndexMetadata .SETTING_BLOCKS_WRITE ) != null ) {
513- // 1. Extract source index mappings
514- final GetMappingsRequest getMappingsRequest = new GetMappingsRequest (masterNodeTimeout ).indices (sourceIndexName );
515- getMappingsRequest .setParentTask (parentTask );
516- client .admin ().indices ().getMappings (getMappingsRequest , listener .delegateFailureAndWrap ((delegate , getMappingsResponse ) -> {
517- final Map <String , Object > sourceIndexMappings = getMappingsResponse .mappings ()
518- .entrySet ()
519- .stream ()
520- .filter (entry -> sourceIndexName .equals (entry .getKey ()))
521- .findFirst ()
522- .map (mappingMetadata -> mappingMetadata .getValue ().sourceAsMap ())
523- .orElseThrow (
524- () -> new IllegalArgumentException ("No mapping found for downsample source index [" + sourceIndexName + "]" )
525- );
526- var forceMergeEnabled = isForceMergeEnabled (sourceIndexMappings );
527- var refreshRequest = new RefreshRequest (targetIndexMetadata .getIndex ().getName ());
528- refreshRequest .setParentTask (parentTask );
529- client .admin ()
530- .indices ()
531- .refresh (
532- refreshRequest ,
533- new RefreshDownsampleIndexActionListener (
534- projectMetadata .id (),
535- delegate ,
536- parentTask ,
537- targetIndexMetadata .getIndex ().getName (),
538- waitTimeout ,
539- startTime ,
540- forceMergeEnabled
541- )
542- );
543- }));
544- return true ;
545- }
546- return false ;
547- }
548-
549473 /**
550474 * Shortcircuit when another downsample api invocation already completed successfully.
551475 */
0 commit comments