Skip to content

Commit d9d8556

Browse files
committed
deprecation info API: negative index.unassigned.node_left.delayed_timeout
This commit adds support to check for negative values for index setting `index.unassigned.node_left.delayed_timeout` for the deprecation info API. relates elastic#36024 relates elastic#26828
1 parent 27487c9 commit d9d8556

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ private DeprecationChecks() {
4848
Collections.unmodifiableList(Arrays.asList(
4949
IndexDeprecationChecks::oldIndicesCheck,
5050
IndexDeprecationChecks::delimitedPayloadFilterCheck,
51-
IndexDeprecationChecks::indexNameCheck
51+
IndexDeprecationChecks::indexNameCheck,
52+
IndexDeprecationChecks::nodeLeftDelayedTimeCheck
5253
));
5354

5455
/**

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import org.elasticsearch.Version;
1212
import org.elasticsearch.cluster.metadata.IndexMetaData;
1313
import org.elasticsearch.cluster.metadata.MappingMetaData;
14+
import org.elasticsearch.cluster.routing.UnassignedInfo;
15+
import org.elasticsearch.common.Strings;
1416
import org.elasticsearch.common.settings.Settings;
17+
import org.elasticsearch.common.unit.TimeValue;
1518
import org.elasticsearch.index.analysis.AnalysisRegistry;
1619
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
1720

@@ -116,4 +119,20 @@ static DeprecationIssue indexNameCheck(IndexMetaData indexMetaData) {
116119
}
117120
return null;
118121
}
122+
123+
static DeprecationIssue nodeLeftDelayedTimeCheck(IndexMetaData indexMetaData) {
124+
String setting = UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey();
125+
String value = indexMetaData.getSettings().get(setting);
126+
if (Strings.isNullOrEmpty(value) == false) {
127+
TimeValue parsedValue = TimeValue.parseTimeValue(value, setting);
128+
if (parsedValue.getNanos() < 0) {
129+
return new DeprecationIssue(DeprecationIssue.Level.WARNING,
130+
"Negative values for index.unassigned.node_left.delayed_timeout are deprecated and should be set to 0",
131+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
132+
"#_literal_index_unassigned_node_left_delayed_timeout_literal_may_no_longer_be_negative",
133+
"The index " + indexMetaData.getIndex().getName() + " is set to " + value);
134+
}
135+
}
136+
return null;
137+
}
119138
}

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.elasticsearch.Version;
99
import org.elasticsearch.cluster.metadata.IndexMetaData;
10+
import org.elasticsearch.cluster.routing.UnassignedInfo;
1011
import org.elasticsearch.common.settings.Settings;
1112
import org.elasticsearch.test.ESTestCase;
1213
import org.elasticsearch.test.VersionUtils;
@@ -76,4 +77,31 @@ public void testIndexNameCheck(){
7677
List<DeprecationIssue> noIssues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(goodIndex));
7778
assertTrue(noIssues.isEmpty());
7879
}
80+
81+
public void testNodeLeftDelayedTimeCheck() {
82+
String negativeTimeValue = "-" + randomPositiveTimeValue();
83+
String indexName = randomAlphaOfLengthBetween(0, 10);
84+
85+
final IndexMetaData badIndex = IndexMetaData.builder(indexName)
86+
.settings(settings(Version.CURRENT).put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), negativeTimeValue))
87+
.numberOfShards(randomIntBetween(1, 100))
88+
.numberOfReplicas(randomIntBetween(1, 15))
89+
.build();
90+
DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.WARNING,
91+
"Negative values for index.unassigned.node_left.delayed_timeout are deprecated and should be set to 0",
92+
"https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" +
93+
"#_literal_index_unassigned_node_left_delayed_timeout_literal_may_no_longer_be_negative",
94+
"The index " + indexName + " is set to " + negativeTimeValue);
95+
96+
List<DeprecationIssue> issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(badIndex));
97+
assertEquals(singletonList(expected), issues);
98+
99+
final IndexMetaData goodIndex = IndexMetaData.builder(indexName)
100+
.settings(settings(Version.CURRENT))
101+
.numberOfShards(randomIntBetween(1, 100))
102+
.numberOfReplicas(randomIntBetween(1, 15))
103+
.build();
104+
List<DeprecationIssue> noIssues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(goodIndex));
105+
assertTrue(noIssues.isEmpty());
106+
}
79107
}

0 commit comments

Comments
 (0)