Skip to content

Commit e948894

Browse files
committed
SNAPSHOT - Shell of functionality, ready to slot in read only check
1 parent 9c0709f commit e948894

File tree

7 files changed

+78
-14
lines changed

7 files changed

+78
-14
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/deprecation/DeprecatedIndexPredicate.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.elasticsearch.cluster.metadata.IndexMetadata;
1111
import org.elasticsearch.cluster.metadata.Metadata;
12+
import org.elasticsearch.cluster.metadata.MetadataIndexStateService;
1213
import org.elasticsearch.index.Index;
1314
import org.elasticsearch.index.IndexVersion;
1415
import org.elasticsearch.index.IndexVersions;
@@ -25,15 +26,17 @@ public class DeprecatedIndexPredicate {
2526
*
2627
* It ignores searchable snapshots as they are not writable.
2728
*/
28-
public static Predicate<Index> getReindexRequiredPredicate(Metadata metadata) {
29+
public static Predicate<Index> getReindexRequiredPredicate(Metadata metadata, boolean filterToBlockedStatus) {
2930
return index -> {
3031
IndexMetadata indexMetadata = metadata.index(index);
31-
return reindexRequired(indexMetadata);
32+
return reindexRequired(indexMetadata, filterToBlockedStatus);
3233
};
3334
}
3435

35-
public static boolean reindexRequired(IndexMetadata indexMetadata) {
36-
return creationVersionBeforeMinimumWritableVersion(indexMetadata) && isNotSearchableSnapshot(indexMetadata);
36+
public static boolean reindexRequired(IndexMetadata indexMetadata, boolean filterToBlockedStatus) {
37+
return creationVersionBeforeMinimumWritableVersion(indexMetadata)
38+
&& isNotSearchableSnapshot(indexMetadata)
39+
&& matchBlockedStatus(indexMetadata, filterToBlockedStatus);
3740
}
3841

3942
private static boolean isNotSearchableSnapshot(IndexMetadata indexMetadata) {
@@ -44,4 +47,7 @@ private static boolean creationVersionBeforeMinimumWritableVersion(IndexMetadata
4447
return metadata.getCreationVersion().before(MINIMUM_WRITEABLE_VERSION_AFTER_UPGRADE);
4548
}
4649

50+
private static boolean matchBlockedStatus(IndexMetadata indexMetadata, boolean filterToBlockedStatus) {
51+
return MetadataIndexStateService.VERIFIED_READ_ONLY_SETTING.get(indexMetadata.getSettings()) == filterToBlockedStatus;
52+
}
4753
}

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationChecks.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ public class DataStreamDeprecationChecks {
2424
static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
2525
List<Index> backingIndices = dataStream.getIndices();
2626

27-
Set<String> indicesNeedingUpgrade = backingIndices.stream()
28-
.filter(DeprecatedIndexPredicate.getReindexRequiredPredicate(clusterState.metadata()))
29-
.map(Index::getName)
30-
.collect(Collectors.toUnmodifiableSet());
27+
Set<String> indicesNeedingUpgrade = getReIndexRequiredIndices(backingIndices, clusterState, false);
3128

3229
if (indicesNeedingUpgrade.isEmpty() == false) {
3330
return new DeprecationIssue(
@@ -47,4 +44,40 @@ static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clus
4744

4845
return null;
4946
}
47+
48+
static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
49+
List<Index> backingIndices = dataStream.getIndices();
50+
51+
Set<String> ignoredIndices = getReIndexRequiredIndices(backingIndices, clusterState, false);
52+
53+
if (ignoredIndices.isEmpty() == false) {
54+
return new DeprecationIssue(
55+
DeprecationIssue.Level.WARNING,
56+
"Old data stream with a compatibility version < 9.0 Have Been Ignored",
57+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
58+
"This data stream has backing indices that were created before Elasticsearch 9.0.0 and have been marked as OK to"
59+
+ "become read-only after upgrade",
60+
false,
61+
ofEntries(
62+
entry("reindex_required", true),
63+
entry("total_backing_indices", backingIndices.size()),
64+
entry("ignored_indices_requiring_upgrade_count", ignoredIndices.size()),
65+
entry("ignored_indices_requiring_upgrade", ignoredIndices)
66+
)
67+
);
68+
}
69+
70+
return null;
71+
}
72+
73+
private static Set<String> getReIndexRequiredIndices(
74+
List<Index> backingIndices,
75+
ClusterState clusterState,
76+
boolean filterToBlockedStatus
77+
) {
78+
return backingIndices.stream()
79+
.filter(DeprecatedIndexPredicate.getReindexRequiredPredicate(clusterState.metadata(), filterToBlockedStatus))
80+
.map(Index::getName)
81+
.collect(Collectors.toUnmodifiableSet());
82+
}
5083
}

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ private DeprecationChecks() {}
9393

9494
static List<BiFunction<IndexMetadata, ClusterState, DeprecationIssue>> INDEX_SETTINGS_CHECKS = List.of(
9595
IndexDeprecationChecks::oldIndicesCheck,
96+
IndexDeprecationChecks::ignoredOldIndicesCheck,
9697
IndexDeprecationChecks::translogRetentionSettingCheck,
9798
IndexDeprecationChecks::checkIndexDataPath,
9899
IndexDeprecationChecks::storeTypeSettingCheck,
@@ -102,7 +103,8 @@ private DeprecationChecks() {}
102103
);
103104

104105
static List<BiFunction<DataStream, ClusterState, DeprecationIssue>> DATA_STREAM_CHECKS = List.of(
105-
DataStreamDeprecationChecks::oldIndicesCheck
106+
DataStreamDeprecationChecks::oldIndicesCheck,
107+
DataStreamDeprecationChecks::ignoredOldIndicesCheck
106108
);
107109

108110
/**

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterStat
3737
// TODO: this check needs to be revised. It's trivially true right now.
3838
IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
3939
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
40-
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata) && isNotDataStreamIndex(indexMetadata, clusterState)) {
40+
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, false)
41+
&& isNotDataStreamIndex(indexMetadata, clusterState)) {
4142
return new DeprecationIssue(
4243
DeprecationIssue.Level.CRITICAL,
4344
"Old index with a compatibility version < 9.0",
@@ -50,6 +51,26 @@ static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterStat
5051
return null;
5152
}
5253

54+
static DeprecationIssue ignoredOldIndicesCheck(IndexMetadata indexMetadata, ClusterState clusterState) {
55+
// TODO: this check needs to be revised. It's trivially true right now.
56+
IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
57+
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
58+
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, true)
59+
&& isNotDataStreamIndex(indexMetadata, clusterState)) {
60+
return new DeprecationIssue(
61+
DeprecationIssue.Level.WARNING,
62+
"Old index with a compatibility version < 9.0 Has Been Ignored",
63+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-9.0.html",
64+
"This index has version: "
65+
+ currentCompatibilityVersion.toReleaseVersion()
66+
+ " and has been marked as OK to become read-only after upgrade",
67+
false,
68+
Collections.singletonMap("reindex_required", true)
69+
);
70+
}
71+
return null;
72+
}
73+
5374
private static boolean isNotDataStreamIndex(IndexMetadata indexMetadata, ClusterState clusterState) {
5475
return clusterState.metadata().findDataStreams(indexMetadata.getIndex().getName()).isEmpty();
5576
}

x-pack/plugin/migrate/src/main/java/org/elasticsearch/xpack/migrate/action/ReindexDataStreamIndexTransportAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ protected void doExecute(
118118
IndexMetadata sourceIndex = clusterService.state().getMetadata().index(sourceIndexName);
119119
Settings settingsBefore = sourceIndex.getSettings();
120120

121-
var hasOldVersion = DeprecatedIndexPredicate.getReindexRequiredPredicate(clusterService.state().metadata());
121+
var hasOldVersion = DeprecatedIndexPredicate.getReindexRequiredPredicate(clusterService.state().metadata(), false);
122122
if (hasOldVersion.test(sourceIndex.getIndex()) == false) {
123123
logger.warn(
124124
"Migrating index [{}] with version [{}] is unnecessary as its version is not before [{}]",

x-pack/plugin/migrate/src/main/java/org/elasticsearch/xpack/migrate/action/ReindexDataStreamTransportAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected void doExecute(Task task, ReindexDataStreamRequest request, ActionList
6868
return;
6969
}
7070
int totalIndices = dataStream.getIndices().size();
71-
int totalIndicesToBeUpgraded = (int) dataStream.getIndices().stream().filter(getReindexRequiredPredicate(metadata)).count();
71+
int totalIndicesToBeUpgraded = (int) dataStream.getIndices().stream().filter(getReindexRequiredPredicate(metadata, false)).count();
7272
ReindexDataStreamTaskParams params = new ReindexDataStreamTaskParams(
7373
sourceDataStreamName,
7474
transportService.getThreadPool().absoluteTimeInMillis(),

x-pack/plugin/migrate/src/main/java/org/elasticsearch/xpack/migrate/task/ReindexDataStreamPersistentTaskExecutor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected void nodeOperation(
112112
List<GetDataStreamAction.Response.DataStreamInfo> dataStreamInfos = response.getDataStreams();
113113
if (dataStreamInfos.size() == 1) {
114114
DataStream dataStream = dataStreamInfos.getFirst().getDataStream();
115-
if (getReindexRequiredPredicate(clusterService.state().metadata()).test(dataStream.getWriteIndex())) {
115+
if (getReindexRequiredPredicate(clusterService.state().metadata(), false).test(dataStream.getWriteIndex())) {
116116
RolloverRequest rolloverRequest = new RolloverRequest(sourceDataStream, null);
117117
rolloverRequest.setParentTask(taskId);
118118
reindexClient.execute(
@@ -161,7 +161,9 @@ private void reindexIndices(
161161
TaskId parentTaskId
162162
) {
163163
List<Index> indices = dataStream.getIndices();
164-
List<Index> indicesToBeReindexed = indices.stream().filter(getReindexRequiredPredicate(clusterService.state().metadata())).toList();
164+
List<Index> indicesToBeReindexed = indices.stream()
165+
.filter(getReindexRequiredPredicate(clusterService.state().metadata(), false))
166+
.toList();
165167
final ReindexDataStreamPersistentTaskState updatedState;
166168
if (params.totalIndices() != totalIndicesInDataStream
167169
|| params.totalIndicesToBeUpgraded() != indicesToBeReindexed.size()

0 commit comments

Comments
 (0)