Skip to content
1 change: 1 addition & 0 deletions modules/data-streams/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
exports org.elasticsearch.datastreams.lifecycle;
exports org.elasticsearch.datastreams.lifecycle.transitions.steps to org.elasticsearch.server;
exports org.elasticsearch.datastreams.options.action to org.elasticsearch.server;
exports org.elasticsearch.datastreams;

provides org.elasticsearch.features.FeatureSpecification with org.elasticsearch.datastreams.DataStreamFeatures;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
import org.elasticsearch.cluster.metadata.RepositoriesMetadata;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.datastreams.DataStreamsPlugin;
import org.elasticsearch.datastreams.lifecycle.DataStreamLifecycleService;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.license.LicenseUtils;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.repositories.RepositoriesService;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -200,7 +202,7 @@ boolean isEligibleForConvertToFrozen() {
return false;
}

String repositoryName = resolveRepositoryName(projectState);
final String repositoryName = getRepositoryForFrozen(projectMetadata, indexName);
if (Strings.hasText(repositoryName) == false) {
logger.debug("Default repository not configured, skipping convert-to-frozen steps for index [{}]", indexName);
throw new ElasticsearchException(
Expand Down Expand Up @@ -228,10 +230,14 @@ boolean isEligibleForConvertToFrozen() {
}

/**
* Resolves the repository name to use for the snapshot and searchable snapshot steps.
* Return the repository name to use for converting this index to a searchable snapshot, or else null if it is not set.
*/
private static String resolveRepositoryName(ProjectState projectState) {
return RepositoriesService.DEFAULT_REPOSITORY_SETTING.get(projectState.cluster().metadata().settings());
@Nullable
private static String getRepositoryForFrozen(ProjectMetadata projectMetadata, String indexName) {
return Optional.ofNullable(projectMetadata.index(indexName))
.map(im -> im.getCustomData(DataStreamsPlugin.LIFECYCLE_CUSTOM_INDEX_METADATA_KEY))
.map(custom -> custom.get(DataStreamLifecycleService.FROZEN_CANDIDATE_REPOSITORY_METADATA_KEY))
.orElse(null);
}

private ResizeRequest getCloneRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.elasticsearch.cluster.metadata.RepositoryMetadata;
import org.elasticsearch.cluster.project.TestProjectResolvers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.datastreams.DataStreamsPlugin;
import org.elasticsearch.datastreams.lifecycle.DataStreamLifecycleService;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.license.License;
Expand All @@ -42,6 +44,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import static org.elasticsearch.cluster.metadata.IndexMetadata.APIBlock.WRITE;
Expand Down Expand Up @@ -405,6 +408,10 @@ private ProjectState createProjectStateWithRepo(String repoName, boolean registe
.settings(Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()).build())
.numberOfShards(1)
.numberOfReplicas(0)
.putCustom(
DataStreamsPlugin.LIFECYCLE_CUSTOM_INDEX_METADATA_KEY,
Map.of(DataStreamLifecycleService.FROZEN_CANDIDATE_REPOSITORY_METADATA_KEY, repoName)
)
.build(),
false
);
Expand Down
Loading