Skip to content

Commit 1292597

Browse files
committed
SNAPSHOT - Shell of functionality, ready to slot in read only check
1 parent 61e9a22 commit 1292597

File tree

7 files changed

+75
-19
lines changed

7 files changed

+75
-19
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,18 @@ public class DeprecatedIndexPredicate {
2626
*
2727
* It ignores searchable snapshots as they are not writable.
2828
*/
29-
public static Predicate<Index> getReindexRequiredPredicate(Metadata metadata) {
29+
public static Predicate<Index> getReindexRequiredPredicate(Metadata metadata, boolean filterToBlockedStatus) {
3030
return index -> {
3131
IndexMetadata indexMetadata = metadata.index(index);
32-
return reindexRequired(indexMetadata);
32+
return reindexRequired(indexMetadata, filterToBlockedStatus);
3333
};
3434
}
3535

36-
public static boolean reindexRequired(IndexMetadata indexMetadata) {
36+
public static boolean reindexRequired(IndexMetadata indexMetadata, boolean filterToBlockedStatus) {
3737
return creationVersionBeforeMinimumWritableVersion(indexMetadata)
3838
&& isNotSearchableSnapshot(indexMetadata)
3939
&& isNotClosed(indexMetadata)
40-
&& isNotVerifiedReadOnly(indexMetadata);
41-
}
42-
43-
private static boolean isNotVerifiedReadOnly(IndexMetadata indexMetadata) {
44-
// no need to check blocks.
45-
return MetadataIndexStateService.VERIFIED_READ_ONLY_SETTING.get(indexMetadata.getSettings()) == false;
40+
&& matchBlockedStatus(indexMetadata, filterToBlockedStatus);
4641
}
4742

4843
private static boolean isNotSearchableSnapshot(IndexMetadata indexMetadata) {
@@ -57,4 +52,7 @@ private static boolean isNotClosed(IndexMetadata indexMetadata) {
5752
return indexMetadata.getState().equals(IndexMetadata.State.CLOSE) == false;
5853
}
5954

55+
private static boolean matchBlockedStatus(IndexMetadata indexMetadata, boolean filterToBlockedStatus) {
56+
return MetadataIndexStateService.VERIFIED_READ_ONLY_SETTING.get(indexMetadata.getSettings()) == filterToBlockedStatus;
57+
}
6058
}

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
@@ -94,6 +94,7 @@ private DeprecationChecks() {}
9494

9595
static List<BiFunction<IndexMetadata, ClusterState, DeprecationIssue>> INDEX_SETTINGS_CHECKS = List.of(
9696
IndexDeprecationChecks::oldIndicesCheck,
97+
IndexDeprecationChecks::ignoredOldIndicesCheck,
9798
IndexDeprecationChecks::translogRetentionSettingCheck,
9899
IndexDeprecationChecks::checkIndexDataPath,
99100
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
@@ -36,7 +36,8 @@ static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterStat
3636
// TODO: this check needs to be revised. It's trivially true right now.
3737
IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
3838
// We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
39-
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata) && isNotDataStreamIndex(indexMetadata, clusterState)) {
39+
if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, false)
40+
&& isNotDataStreamIndex(indexMetadata, clusterState)) {
4041
return new DeprecationIssue(
4142
DeprecationIssue.Level.CRITICAL,
4243
"Old index with a compatibility version < 9.0",
@@ -49,6 +50,26 @@ static DeprecationIssue oldIndicesCheck(IndexMetadata indexMetadata, ClusterStat
4950
return null;
5051
}
5152

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

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)