-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Add new DLM Frozen Tier Transition execution plugin and service #144595
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
lukewhiting
merged 17 commits into
elastic:main
from
lukewhiting:est-2433-frozen-task-executor-service
Mar 26, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5fbd1a6
Add new DLM Frozen Tier Transition executioplugin and service
lukewhiting 0d1c2d8
Revert inspection profile change
lukewhiting 62c9eed
Update x-pack/plugin/dlm-frozen-transition/src/test/java/org/elastics…
lukewhiting 74f0747
PR changes
lukewhiting f59379a
Fix flaky test
lukewhiting 5d095a3
Merge branch 'main' of github.com:elastic/elasticsearch into est-2433…
lukewhiting 1279f1c
Move new tests to correct plugin
lukewhiting aae1e77
Fix plugin errors on startup
lukewhiting dda6ae7
Improve thread pool termination and ensure proper clean-up during close
lukewhiting 5e03490
PR Changes
lukewhiting 272e4e8
Merge branch 'main' of github.com:elastic/elasticsearch into est-2433…
lukewhiting 9aec2ce
Update x-pack/plugin/dlm-frozen-transition/src/main/java/org/elastics…
lukewhiting 656ee40
Merge branch 'main' into est-2433-frozen-task-executor-service
lukewhiting c64045e
Merge branch 'main' into est-2433-frozen-task-executor-service
dakrone 206b292
Merge branch 'main' into est-2433-frozen-task-executor-service
lukewhiting d9eb533
Merge branch 'main' into est-2433-frozen-task-executor-service
dakrone ff13f48
Merge branch 'main' into est-2433-frozen-task-executor-service
lukewhiting 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
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 |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| apply plugin: 'elasticsearch.internal-es-plugin' | ||
| apply plugin: 'elasticsearch.internal-cluster-test' | ||
| esplugin { | ||
| name = 'dlm-frozen-transition' | ||
| description = 'A plugin for the frozen tier functionality of DLM' | ||
| classname = 'org.elasticsearch.xpack.dlm.frozen.DlmFrozenTransitionPlugin' | ||
| extendedPlugins = ['data-streams', 'x-pack-core'] | ||
| } | ||
| base { | ||
| archivesName = 'x-pack-dlm-frozen-transition' | ||
| } | ||
|
|
||
| dependencies { | ||
| compileOnly project(path: xpackModule('core')) | ||
| compileOnly project(':modules:data-streams') | ||
| testImplementation(testArtifact(project(xpackModule('core')))) | ||
| testImplementation project(':modules:data-streams') | ||
| } |
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
104 changes: 104 additions & 0 deletions
104
...nsition/src/main/java/org/elasticsearch/xpack/dlm/frozen/DlmFrozenTransitionExecutor.java
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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.dlm.frozen; | ||
|
|
||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.concurrent.EsExecutors; | ||
| import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
| import org.elasticsearch.core.Strings; | ||
| import org.elasticsearch.logging.Logger; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
|
|
||
| import java.io.Closeable; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Future; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static org.elasticsearch.logging.LogManager.getLogger; | ||
|
|
||
| /** | ||
| * DlmFrozenTransitionExecutor is responsible for managing and executing tasks related to | ||
| * frozen transitions in the distributed lifecycle management (DLM) feature. | ||
| * <br> | ||
| * This executor limits the number of concurrent transition tasks based on a configurable capacity | ||
| * and prevents transitions being executed concurrently for the same index. | ||
| * It also ensures that tasks are tracked and cleaned up upon completion or failure. | ||
| */ | ||
| class DlmFrozenTransitionExecutor implements Closeable { | ||
|
|
||
| private static final Logger logger = getLogger(DlmFrozenTransitionExecutor.class); | ||
|
|
||
| private static final String EXECUTOR_NAME = "dlm-frozen-transition"; | ||
|
|
||
| private final Set<String> runningTransitions; | ||
| private final int maxConcurrency; | ||
| private final ExecutorService executor; | ||
|
|
||
| DlmFrozenTransitionExecutor(int maxConcurrency, Settings settings) { | ||
| this.runningTransitions = ConcurrentHashMap.newKeySet(maxConcurrency); | ||
| this.maxConcurrency = maxConcurrency; | ||
| this.executor = EsExecutors.newFixed( | ||
| EXECUTOR_NAME, | ||
| maxConcurrency, | ||
| -1, | ||
| EsExecutors.daemonThreadFactory(settings, EXECUTOR_NAME), | ||
| new ThreadContext(settings), | ||
| EsExecutors.TaskTrackingConfig.DEFAULT | ||
| ); | ||
| } | ||
|
|
||
| public boolean isTransitionRunning(String indexName) { | ||
| return runningTransitions.contains(indexName); | ||
| } | ||
|
|
||
| public boolean hasCapacity() { | ||
| return runningTransitions.size() < maxConcurrency; | ||
| } | ||
|
|
||
| public List<Runnable> shutdownNow() { | ||
| return executor.shutdownNow(); | ||
| } | ||
|
|
||
| public Future<?> submit(DlmFrozenTransitionRunnable task) { | ||
| final String indexName = task.getIndexName(); | ||
| runningTransitions.add(indexName); | ||
| try { | ||
| return executor.submit(wrapRunnable(task)); | ||
| } catch (Exception e) { | ||
| runningTransitions.remove(indexName); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Wraps the task with index tracking and error handling. Ensures the index name is always removed from | ||
| * {@link #runningTransitions} when the thread completes, whether successfully or with an error. | ||
| */ | ||
| private Runnable wrapRunnable(DlmFrozenTransitionRunnable task) { | ||
| return () -> { | ||
| final String indexName = task.getIndexName(); | ||
| try { | ||
| logger.debug("Starting transition for index [{}]", indexName); | ||
| task.run(); | ||
lukewhiting marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| logger.debug("Transition completed for index [{}]", indexName); | ||
| } catch (Exception ex) { | ||
| logger.error(() -> Strings.format("Error executing transition for index [%s]", indexName), ex); | ||
| } finally { | ||
| runningTransitions.remove(indexName); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| ThreadPool.terminate(executor, 10, TimeUnit.SECONDS); | ||
| } | ||
| } | ||
46 changes: 46 additions & 0 deletions
46
...ransition/src/main/java/org/elasticsearch/xpack/dlm/frozen/DlmFrozenTransitionPlugin.java
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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| package org.elasticsearch.xpack.dlm.frozen; | ||
|
|
||
| import org.elasticsearch.cluster.metadata.DataStreamLifecycle; | ||
| import org.elasticsearch.common.settings.Setting; | ||
| import org.elasticsearch.license.XPackLicenseState; | ||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.xpack.core.XPackPlugin; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Plugin that registers the {@link DlmFrozenTransitionService} for converting data stream backing indices to the frozen tier as part of | ||
| * the data stream lifecycle. Only active when the searchable snapshots feature flag is enabled. | ||
| */ | ||
| public class DlmFrozenTransitionPlugin extends Plugin { | ||
|
|
||
| @Override | ||
| public Collection<?> createComponents(PluginServices services) { | ||
| Set<Object> components = new HashSet<>(super.createComponents(services)); | ||
| if (DataStreamLifecycle.DLM_SEARCHABLE_SNAPSHOTS_FEATURE_FLAG.isEnabled()) { | ||
| XPackLicenseState licenseState = XPackPlugin.getSharedLicenseState(); | ||
| var service = new DlmFrozenTransitionService(services.clusterService(), services.client(), licenseState); | ||
| service.init(); | ||
| components.add(service); | ||
| } | ||
| return components; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Setting<?>> getSettings() { | ||
| if (DataStreamLifecycle.DLM_SEARCHABLE_SNAPSHOTS_FEATURE_FLAG.isEnabled()) { | ||
| return List.of(DlmFrozenTransitionService.POLL_INTERVAL_SETTING, DlmFrozenTransitionService.MAX_CONCURRENCY_SETTING); | ||
| } else { | ||
| return List.of(); | ||
| } | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
...nsition/src/main/java/org/elasticsearch/xpack/dlm/frozen/DlmFrozenTransitionRunnable.java
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.dlm.frozen; | ||
|
|
||
| /** | ||
| * A runnable task associated with a specific index transition. | ||
| */ | ||
| interface DlmFrozenTransitionRunnable extends Runnable { | ||
| String getIndexName(); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.