forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate a correct consistent downsample target name in downsample il…
…m action. Bring back generate downsample step that is used to prepare the lifecycle state and sets the name of the target downsample index to be used. A number of steps will use this to execute various downsample related operations. The generate downsample index name step produces a consistent name. And also takes into account whether the source index was already downsampled, so a logical name is generated.
- Loading branch information
Showing
5 changed files
with
162 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
68 changes: 68 additions & 0 deletions
68
...e/src/main/java/org/elasticsearch/xpack/core/ilm/DownsamplePrepareLifeCycleStateStep.java
This file contains 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,68 @@ | ||
/* | ||
* 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.core.ilm; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.metadata.LifecycleExecutionState; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; | ||
|
||
import static org.elasticsearch.xpack.core.ilm.DownsampleAction.DOWNSAMPLED_INDEX_PREFIX; | ||
|
||
public class DownsamplePrepareLifeCycleStateStep extends ClusterStateActionStep { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(DownsamplePrepareLifeCycleStateStep.class); | ||
public static final String NAME = "generate-downsampled-index-name"; | ||
private final DateHistogramInterval fixedInterval; | ||
|
||
public DownsamplePrepareLifeCycleStateStep(StepKey key, StepKey nextStepKey, DateHistogramInterval fixedInterval) { | ||
super(key, nextStepKey); | ||
this.fixedInterval = fixedInterval; | ||
} | ||
|
||
@Override | ||
public ClusterState performAction(Index index, ClusterState clusterState) { | ||
IndexMetadata indexMetadata = clusterState.metadata().index(index); | ||
if (indexMetadata == null) { | ||
// Index must have been since deleted, ignore it | ||
LOGGER.debug("[{}] lifecycle action for index [{}] executed but index no longer exists", getKey().action(), index.getName()); | ||
return clusterState; | ||
} | ||
|
||
LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState(); | ||
|
||
LifecycleExecutionState.Builder newLifecycleState = LifecycleExecutionState.builder(lifecycleState); | ||
final String downsampleIndexName = generateDownsampleIndexName(indexMetadata, fixedInterval); | ||
newLifecycleState.setDownsampleIndexName(downsampleIndexName); | ||
|
||
return LifecycleExecutionStateUtils.newClusterStateWithLifecycleState( | ||
clusterState, | ||
indexMetadata.getIndex(), | ||
newLifecycleState.build() | ||
); | ||
} | ||
|
||
@Override | ||
public boolean isRetryable() { | ||
return true; | ||
} | ||
|
||
static String generateDownsampleIndexName(IndexMetadata sourceIndexMetadata, DateHistogramInterval fixedInterval) { | ||
String downsampleSourceName = sourceIndexMetadata.getSettings().get(IndexMetadata.INDEX_DOWNSAMPLE_SOURCE_NAME_KEY); | ||
String sourceIndexName; | ||
if (downsampleSourceName != null) { | ||
sourceIndexName = downsampleSourceName; | ||
} else { | ||
sourceIndexName = sourceIndexMetadata.getIndex().getName(); | ||
} | ||
return DOWNSAMPLED_INDEX_PREFIX + sourceIndexName + "-" + fixedInterval; | ||
} | ||
} |
This file contains 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 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 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