Skip to content

Commit 658c014

Browse files
authored
Block readiness on bad initial file settings (#107775)
If file settings have an update that fails, existing applied file settings continue to work. But if the initial file settings fail to process, readiness should be blocked. This commit adjusts readiness to look for this special initialization case. relates #107738
1 parent 3ed42f3 commit 658c014

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

server/src/internalClusterTest/java/org/elasticsearch/readiness/ReadinessClusterIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ private void writeFileSettings(String json) throws Exception {
251251
logger.info("--> New file settings: [{}]", Strings.format(json, version));
252252
}
253253

254-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/107744")
255254
public void testNotReadyOnBadFileSettings() throws Exception {
256255
internalCluster().setBootstrapMasterNodeIndex(0);
257256
logger.info("--> start data node / non master node");

server/src/main/java/org/elasticsearch/cluster/metadata/ReservedStateMetadata.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public record ReservedStateMetadata(
4646
ReservedStateErrorMetadata errorMetadata
4747
) implements SimpleDiffable<ReservedStateMetadata>, ToXContentFragment {
4848

49+
public static final Long NO_VERSION = Long.MIN_VALUE; // use min long as sentinel for uninitialized version
50+
4951
private static final ParseField VERSION = new ParseField("version");
5052
private static final ParseField HANDLERS = new ParseField("handlers");
5153
private static final ParseField ERRORS_METADATA = new ParseField("errors");
@@ -209,7 +211,7 @@ public static class Builder {
209211
*/
210212
public Builder(String namespace) {
211213
this.namespace = namespace;
212-
this.version = -1L;
214+
this.version = NO_VERSION;
213215
this.handlers = new HashMap<>();
214216
this.errorMetadata = null;
215217
}

server/src/main/java/org/elasticsearch/readiness/ReadinessService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void clusterChanged(ClusterChangedEvent event) {
254254
// protected to allow mock service to override
255255
protected boolean areFileSettingsApplied(ClusterState clusterState) {
256256
ReservedStateMetadata fileSettingsMetadata = clusterState.metadata().reservedStateMetadata().get(FileSettingsService.NAMESPACE);
257-
return fileSettingsMetadata != null;
257+
return fileSettingsMetadata != null && fileSettingsMetadata.version().equals(ReservedStateMetadata.NO_VERSION) == false;
258258
}
259259

260260
private void setReady(boolean ready) {

server/src/test/java/org/elasticsearch/cluster/metadata/ReservedStateMetadataTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Collections;
2121
import java.util.List;
2222

23+
import static org.elasticsearch.cluster.metadata.ReservedStateMetadata.NO_VERSION;
2324
import static org.hamcrest.Matchers.equalTo;
2425
import static org.hamcrest.Matchers.not;
2526

@@ -78,7 +79,7 @@ public void testXContent() throws IOException {
7879

7980
public void testReservedStateVersionWithError() {
8081
final ReservedStateMetadata meta = createRandom(false, true);
81-
assertEquals(-1L, meta.version().longValue());
82+
assertEquals(NO_VERSION.longValue(), meta.version().longValue());
8283
}
8384

8485
private static ReservedStateMetadata createRandom(boolean addHandlers, boolean addErrors) {

server/src/test/java/org/elasticsearch/cluster/metadata/ToAndFromJsonMetadataTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ public void testToXContentAPIReservedMetadata() throws IOException {
776776
},
777777
"reserved_state" : {
778778
"namespace_one" : {
779-
"version" : -1,
779+
"version" : -9223372036854775808,
780780
"handlers" : {
781781
"one" : {
782782
"keys" : [
@@ -801,7 +801,7 @@ public void testToXContentAPIReservedMetadata() throws IOException {
801801
}
802802
},
803803
"namespace_two" : {
804-
"version" : -1,
804+
"version" : -9223372036854775808,
805805
"handlers" : {
806806
"three" : {
807807
"keys" : [

0 commit comments

Comments
 (0)