Skip to content

Commit 332c922

Browse files
authored
onProcessFileChangesException (#115038)
1 parent c7f53ff commit 332c922

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
@@ -313,12 +313,20 @@ void processSettingsOnServiceStartAndNotifyListeners() throws InterruptedExcepti
313313
void processSettingsAndNotifyListeners() throws InterruptedException {
314314
try {
315315
processFileChanges();
316-
for (var listener : eventListeners) {
317-
listener.watchedFileChanged();
318-
}
319316
} catch (IOException | ExecutionException e) {
320-
logger.error(() -> "Error processing watched file: " + watchedFile(), e);
317+
onProcessFileChangesException(e);
318+
return;
321319
}
320+
for (var listener : eventListeners) {
321+
listener.watchedFileChanged();
322+
}
323+
}
324+
325+
/**
326+
* Called for checked exceptions only.
327+
*/
328+
protected void onProcessFileChangesException(Exception e) {
329+
logger.error(() -> "Error processing watched file: " + watchedFile(), e);
322330
}
323331

324332
// 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;
@@ -144,7 +145,16 @@ private void processFileChanges(ReservedStateVersionCheck versionCheck) throws I
144145
}
145146

146147
@Override
147-
protected void processInitialFileMissing() throws ExecutionException, InterruptedException {
148+
protected void onProcessFileChangesException(Exception e) {
149+
if (e instanceof ExecutionException && e.getCause() instanceof FailedToCommitClusterStateException f) {
150+
logger.error("Unable to commit cluster state", e);
151+
} else {
152+
super.onProcessFileChangesException(e);
153+
}
154+
}
155+
156+
@Override
157+
protected void processInitialFileMissing() throws ExecutionException, InterruptedException, IOException {
148158
PlainActionFuture<ActionResponse.Empty> completion = new PlainActionFuture<>();
149159
logger.info("setting file [{}] not found, initializing [{}] as empty", watchedFile(), NAMESPACE);
150160
stateService.initEmpty(NAMESPACE, completion);

0 commit comments

Comments
 (0)