Skip to content

Commit

Permalink
Fix repeated error save loops in File Settings Service (#90271)
Browse files Browse the repository at this point in the history
  • Loading branch information
grcevski committed Sep 23, 2022
1 parent 1acc278 commit 6af2b5c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/90271.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 90271
summary: Fix repeated error save loops in File Settings Service
area: Infra/Core
type: bug
issues:
- 90222
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import static java.lang.invoke.MethodType.methodType;
import static org.elasticsearch.bootstrap.FilePermissionUtils.addDirectoryPath;
import static org.elasticsearch.bootstrap.FilePermissionUtils.addSingleFilePath;
import static org.elasticsearch.reservedstate.service.FileSettingsService.OPERATOR_DIRECTORY;
import static org.elasticsearch.reservedstate.service.FileSettingsService.SETTINGS_FILE_NAME;

/**
* Initializes SecurityManager with necessary permissions.
Expand Down Expand Up @@ -253,6 +255,8 @@ static void addFilePermissions(Permissions policy, Environment environment, Path
// we just need permission to remove the file if its elsewhere.
addSingleFilePath(policy, pidFile, "delete");
}
// we need to touch the operator/settings.json file when restoring from snapshots, on some OSs it needs file write permission
addSingleFilePath(policy, environment.configFile().resolve(OPERATOR_DIRECTORY).resolve(SETTINGS_FILE_NAME), "read,readlink,write");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static class Builder {
*/
public Builder(String namespace) {
this.namespace = namespace;
this.version = 0L;
this.version = -1L;
this.handlers = new HashMap<>();
this.errorMetadata = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
public class FileSettingsService extends AbstractLifecycleComponent implements ClusterStateListener {
private static final Logger logger = LogManager.getLogger(FileSettingsService.class);

private static final String SETTINGS_FILE_NAME = "settings.json";
public static final String SETTINGS_FILE_NAME = "settings.json";
public static final String NAMESPACE = "file_settings";

private final ClusterService clusterService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public void testXContent() throws IOException {
xContentTest(false, false);
}

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

private static ReservedStateMetadata createRandom(boolean addHandlers, boolean addErrors) {
List<ReservedStateHandlerMetadata> handlers = randomList(
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ public void testToXContentAPIReservedMetadata() throws IOException {
},
"reserved_state" : {
"namespace_one" : {
"version" : 0,
"version" : -1,
"handlers" : {
"one" : {
"keys" : [
Expand All @@ -807,7 +807,7 @@ public void testToXContentAPIReservedMetadata() throws IOException {
}
},
"namespace_two" : {
"version" : 0,
"version" : -1,
"handlers" : {
"three" : {
"keys" : [
Expand Down

0 comments on commit 6af2b5c

Please sign in to comment.