- 
                Notifications
    
You must be signed in to change notification settings  - Fork 25.6k
 
Avoid restarting data stream reindex when cluster is upgraded #125587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            masseyke
  merged 16 commits into
  elastic:main
from
masseyke:data-stream-reindex-no-restart-on-upgrade
  
      
      
   
  Mar 25, 2025 
      
    
  
     Merged
                    Changes from 14 commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      87fc468
              
                Avoid restarting data stream reindex when cluster is upgraded
              
              
                masseyke 5f61f74
              
                fixing a compilation error
              
              
                masseyke 231de38
              
                killing task if it is already complete on a fresh node
              
              
                masseyke 12919f4
              
                [CI] Auto commit changes from spotless
              
              
                 9b3ec98
              
                scheduling task for future removal
              
              
                masseyke b0fce5c
              
                Merge branch 'data-stream-reindex-no-restart-on-upgrade' of github.co…
              
              
                masseyke 1b5184c
              
                using state we already have to determine isComplete
              
              
                masseyke d785813
              
                Merge branch 'main' into data-stream-reindex-no-restart-on-upgrade
              
              
                masseyke 69f1ef8
              
                minor fix to DataStreamsUpgradeIT
              
              
                masseyke e091420
              
                making sure that we cancel tasks
              
              
                masseyke 744870a
              
                Merge branch 'data-stream-reindex-no-restart-on-upgrade' of github.co…
              
              
                masseyke deba319
              
                avoiding forbidden method
              
              
                masseyke 1a7a56e
              
                Merge branch 'main' into data-stream-reindex-no-restart-on-upgrade
              
              
                masseyke e1ff8a0
              
                making sure time is not negative
              
              
                masseyke 02a1e64
              
                fixing getTimeToLive
              
              
                masseyke 1c215ee
              
                removing unnecessary null check
              
              
                masseyke File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -108,6 +108,11 @@ protected void nodeOperation( | |
| ReindexDataStreamTaskParams params, | ||
| PersistentTaskState persistentTaskState | ||
| ) { | ||
| Long completionTime = getCompletionTime(persistentTaskState); | ||
| if (completionTime != null && task instanceof ReindexDataStreamTask reindexDataStreamTask) { | ||
| reindexDataStreamTask.allReindexesCompleted(threadPool, getTimeToLive(completionTime)); | ||
| return; | ||
| } | ||
| ReindexDataStreamPersistentTaskState state = (ReindexDataStreamPersistentTaskState) persistentTaskState; | ||
| String sourceDataStream = params.getSourceDataStream(); | ||
| TaskId taskId = new TaskId(clusterService.localNode().getId(), task.getId()); | ||
| 
          
            
          
           | 
    @@ -316,6 +321,18 @@ private void completeFailedPersistentTask( | |
| persistentTask.taskFailed(threadPool, updateCompletionTimeAndGetTimeToLive(persistentTask, state), e); | ||
| } | ||
| 
     | 
||
| private Long getCompletionTime(PersistentTaskState persistentTaskState) { | ||
| if (persistentTaskState == null) { | ||
| return null; | ||
| } else { | ||
| if (persistentTaskState instanceof ReindexDataStreamPersistentTaskState state) { | ||
| return state.completionTime(); | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
| 
     | 
||
| private TimeValue updateCompletionTimeAndGetTimeToLive( | ||
| ReindexDataStreamTask reindexDataStreamTask, | ||
| @Nullable ReindexDataStreamPersistentTaskState state | ||
| 
          
            
          
           | 
    @@ -345,6 +362,15 @@ private TimeValue updateCompletionTimeAndGetTimeToLive( | |
| completionTime = state.completionTime(); | ||
| } | ||
| } | ||
| return TimeValue.timeValueMillis(TASK_KEEP_ALIVE_TIME.millis() - (threadPool.absoluteTimeInMillis() - completionTime)); | ||
| return getTimeToLive(completionTime); | ||
| } | ||
| 
     | 
||
| private TimeValue getTimeToLive(long completionTimeInMillis) { | ||
| return TimeValue.timeValueMillis( | ||
| TASK_KEEP_ALIVE_TIME.millis() - Math.max( | ||
                
       | 
||
| TASK_KEEP_ALIVE_TIME.millis(), | ||
| threadPool.absoluteTimeInMillis() - completionTimeInMillis | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I don't think you need a null check prior to calling
instanceof