Skip to content

Commit

Permalink
Assign index.downsample.interval setting when downsample index gets c…
Browse files Browse the repository at this point in the history
…reated. (elastic#105241)

This avoids keeping downsamplingInterval field around. Additionally, the
downsample interval is known when downsample interval is invoked and
doesn't change.
  • Loading branch information
martijnvg authored Feb 7, 2024
1 parent 6489101 commit cc67205
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,7 @@ public String toString() {
INDEX_DOWNSAMPLE_INTERVAL_KEY,
"",
Property.IndexScope,
Property.InternalIndex,
Property.PrivateIndex
Property.InternalIndex
);

// LIFECYCLE_NAME is here an as optimization, see LifecycleSettings.LIFECYCLE_NAME and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public class TransportDownsampleAction extends AcknowledgedTransportMasterNodeAc
private final IndexScopedSettings indexScopedSettings;
private final ThreadContext threadContext;
private final PersistentTasksService persistentTasksService;
private String downsamplingInterval;

private static final Set<String> FORBIDDEN_SETTINGS = Set.of(
IndexSettings.DEFAULT_PIPELINE.getKey(),
Expand Down Expand Up @@ -184,7 +183,6 @@ protected void masterOperation(
ActionListener<AcknowledgedResponse> listener
) {
String sourceIndexName = request.getSourceIndex();
downsamplingInterval = request.getDownsampleConfig().getInterval().toString();

final IndicesAccessControl indicesAccessControl = threadContext.getTransient(AuthorizationServiceField.INDICES_PERMISSIONS_KEY);
if (indicesAccessControl != null) {
Expand Down Expand Up @@ -775,12 +773,14 @@ private void createDownsampleIndex(
* case downsample will fail.
*/
int numberOfReplicas = settings.getAsInt(Downsample.DOWNSAMPLE_MIN_NUMBER_OF_REPLICAS_NAME, 0);
var downsampleInterval = request.getDownsampleConfig().getInterval().toString();
Settings.Builder builder = Settings.builder()
.put(IndexMetadata.SETTING_INDEX_HIDDEN, true)
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, sourceIndexMetadata.getNumberOfShards())
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, String.valueOf(numberOfReplicas))
.put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), "-1")
.put(IndexMetadata.INDEX_DOWNSAMPLE_STATUS.getKey(), DownsampleTaskStatus.STARTED);
.put(IndexMetadata.INDEX_DOWNSAMPLE_STATUS.getKey(), DownsampleTaskStatus.STARTED)
.put(IndexMetadata.INDEX_DOWNSAMPLE_INTERVAL.getKey(), downsampleInterval);
if (sourceIndexMetadata.getSettings().hasValue(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey())) {
builder.put(
MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(),
Expand Down Expand Up @@ -910,7 +910,6 @@ public ClusterState execute(ClusterState currentState) {
Settings.builder()
.put(downsampleIndex.getSettings())
.put(IndexMetadata.INDEX_DOWNSAMPLE_STATUS.getKey(), DownsampleTaskStatus.SUCCESS)
.put(IndexMetadata.INDEX_DOWNSAMPLE_INTERVAL.getKey(), downsamplingInterval)
.build(),
downsampleIndexName
);
Expand Down

0 comments on commit cc67205

Please sign in to comment.