Skip to content

Commit

Permalink
Block readiness on bad initial file settings (#107775)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rjernst committed Apr 26, 2024
1 parent 3ed42f3 commit 658c014
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
Expand Up @@ -251,7 +251,6 @@ private void writeFileSettings(String json) throws Exception {
logger.info("--> New file settings: [{}]", Strings.format(json, version));
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/107744")
public void testNotReadyOnBadFileSettings() throws Exception {
internalCluster().setBootstrapMasterNodeIndex(0);
logger.info("--> start data node / non master node");
Expand Down
Expand Up @@ -46,6 +46,8 @@ public record ReservedStateMetadata(
ReservedStateErrorMetadata errorMetadata
) implements SimpleDiffable<ReservedStateMetadata>, ToXContentFragment {

public static final Long NO_VERSION = Long.MIN_VALUE; // use min long as sentinel for uninitialized version

private static final ParseField VERSION = new ParseField("version");
private static final ParseField HANDLERS = new ParseField("handlers");
private static final ParseField ERRORS_METADATA = new ParseField("errors");
Expand Down Expand Up @@ -209,7 +211,7 @@ public static class Builder {
*/
public Builder(String namespace) {
this.namespace = namespace;
this.version = -1L;
this.version = NO_VERSION;
this.handlers = new HashMap<>();
this.errorMetadata = null;
}
Expand Down
Expand Up @@ -254,7 +254,7 @@ public void clusterChanged(ClusterChangedEvent event) {
// protected to allow mock service to override
protected boolean areFileSettingsApplied(ClusterState clusterState) {
ReservedStateMetadata fileSettingsMetadata = clusterState.metadata().reservedStateMetadata().get(FileSettingsService.NAMESPACE);
return fileSettingsMetadata != null;
return fileSettingsMetadata != null && fileSettingsMetadata.version().equals(ReservedStateMetadata.NO_VERSION) == false;
}

private void setReady(boolean ready) {
Expand Down
Expand Up @@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;

import static org.elasticsearch.cluster.metadata.ReservedStateMetadata.NO_VERSION;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;

Expand Down Expand Up @@ -78,7 +79,7 @@ public void testXContent() throws IOException {

public void testReservedStateVersionWithError() {
final ReservedStateMetadata meta = createRandom(false, true);
assertEquals(-1L, meta.version().longValue());
assertEquals(NO_VERSION.longValue(), meta.version().longValue());
}

private static ReservedStateMetadata createRandom(boolean addHandlers, boolean addErrors) {
Expand Down
Expand Up @@ -776,7 +776,7 @@ public void testToXContentAPIReservedMetadata() throws IOException {
},
"reserved_state" : {
"namespace_one" : {
"version" : -1,
"version" : -9223372036854775808,
"handlers" : {
"one" : {
"keys" : [
Expand All @@ -801,7 +801,7 @@ public void testToXContentAPIReservedMetadata() throws IOException {
}
},
"namespace_two" : {
"version" : -1,
"version" : -9223372036854775808,
"handlers" : {
"three" : {
"keys" : [
Expand Down

0 comments on commit 658c014

Please sign in to comment.