Skip to content

Commit 5deec04

Browse files
authored
onProcessFileChangesException (elastic#115038) (elastic#134909)
1 parent dc02a07 commit 5deec04

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

server/src/main/java/org/elasticsearch/common/file/AbstractFileWatchingService.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,20 @@ void processSettingsOnServiceStartAndNotifyListeners() throws InterruptedExcepti
315315
void processSettingsAndNotifyListeners() throws InterruptedException {
316316
try {
317317
processFileChanges();
318-
for (var listener : eventListeners) {
319-
listener.watchedFileChanged();
320-
}
321318
} catch (IOException | ExecutionException e) {
322-
logger.error(() -> "Error processing watched file: " + watchedFile(), e);
319+
onProcessFileChangesException(e);
320+
return;
323321
}
322+
for (var listener : eventListeners) {
323+
listener.watchedFileChanged();
324+
}
325+
}
326+
327+
/**
328+
* Called for checked exceptions only.
329+
*/
330+
protected void onProcessFileChangesException(Exception e) {
331+
logger.error(() -> "Error processing watched file: " + watchedFile(), e);
324332
}
325333

326334
// package private for testing

server/src/main/java/org/elasticsearch/reservedstate/service/FileSettingsService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.action.support.PlainActionFuture;
1616
import org.elasticsearch.cluster.ClusterState;
1717
import org.elasticsearch.cluster.ClusterStateListener;
18+
import org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException;
1819
import org.elasticsearch.cluster.metadata.Metadata;
1920
import org.elasticsearch.cluster.metadata.ReservedStateMetadata;
2021
import org.elasticsearch.cluster.service.ClusterService;
@@ -149,7 +150,16 @@ private void processFileChanges(ReservedStateVersionCheck versionCheck) throws I
149150
}
150151

151152
@Override
152-
protected void processInitialFileMissing() throws ExecutionException, InterruptedException {
153+
protected void onProcessFileChangesException(Exception e) {
154+
if (e instanceof ExecutionException && e.getCause() instanceof FailedToCommitClusterStateException f) {
155+
logger.error("Unable to commit cluster state", e);
156+
} else {
157+
super.onProcessFileChangesException(e);
158+
}
159+
}
160+
161+
@Override
162+
protected void processInitialFileMissing() throws ExecutionException, InterruptedException, IOException {
153163
PlainActionFuture<ActionResponse.Empty> completion = new PlainActionFuture<>();
154164
logger.info("setting file [{}] not found, initializing [{}] as empty", watchedFile(), NAMESPACE);
155165
stateService.initEmpty(NAMESPACE, completion);

0 commit comments

Comments
 (0)