Skip to content

Commit 00e1577

Browse files
committed
Add fix
1 parent 79fcbe0 commit 00e1577

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

server/src/internalClusterTest/java/org/elasticsearch/reservedstate/service/FileSettingsServiceIT.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,28 +522,30 @@ public void testSymlinkUpdateTriggerReload() throws Exception {
522522
assertBusy(() -> assertTrue(masterFileSettingsService.watching()));
523523
assertFalse(dataFileSettingsService.watching());
524524

525-
createK8sLikeMount(masterNode);
525+
// Create the settings.json as a symlink to simulate k8 setup
526+
// settings.json -> ..data/settings.json
527+
// ..data -> ..TIMESTAMP_TEMP_FOLDER_1
528+
createK8sLikeSymlinks(masterNode);
526529
assertClusterStateSaveOK(savedClusterState.v1(), savedClusterState.v2(), "50mb");
527530
}
528531
{
529532
var savedClusterState = setupClusterStateListener(masterNode);
530-
updateSymbolicLink(masterNode, testJSON43mb);
533+
// Update ..data symlink to ..data -> ..TIMESTAMP_TEMP_FOLDER_2 to simulate kubernetes secret update
534+
updateSymlinks(masterNode, testJSON43mb);
531535
assertClusterStateSaveOK(savedClusterState.v1(), savedClusterState.v2(), "43mb");
532536
}
533537
}
534538

535-
public Path createK8sLikeMount(String node) throws Exception {
539+
public Path createK8sLikeSymlinks(String node) throws Exception {
536540
FileSettingsService fileSettingsService = internalCluster().getInstance(FileSettingsService.class, node);
537541
Path baseDir = fileSettingsService.watchedFileDir();
538542
var fileDir = Files.createDirectories(baseDir.resolve("..TIMESTAMP_TEMP_FOLDER_1"));
539543
writeJSONFile(node, testJSON, logger, versionCounter.incrementAndGet(), fileDir.resolve("settings.json"));
540-
541544
var dataDir = Files.createSymbolicLink(baseDir.resolve("..data"), fileDir.getFileName());
542-
543545
return Files.createSymbolicLink(baseDir.resolve("settings.json"), dataDir.getFileName().resolve("settings.json"));
544546
}
545547

546-
public void updateSymbolicLink(String node, String json) throws Exception {
548+
public void updateSymlinks(String node, String json) throws Exception {
547549
FileSettingsService fileSettingsService = internalCluster().getInstance(FileSettingsService.class, node);
548550
Path baseDir = fileSettingsService.watchedFileDir();
549551
var fileDir = Files.createDirectories(baseDir.resolve("..TIMESTAMP_TEMP_FOLDER_2"));

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.IOException;
1919
import java.io.InputStream;
2020
import java.nio.file.ClosedWatchServiceException;
21+
import java.nio.file.Files;
2122
import java.nio.file.NoSuchFileException;
2223
import java.nio.file.Path;
2324
import java.nio.file.StandardWatchEventKinds;
@@ -241,7 +242,9 @@ protected final void watcherThread() {
241242
Set<Path> processedFiles = new HashSet<>();
242243
for (WatchEvent<?> e : events) {
243244
Path fullFile = settingsDir.resolve(e.context().toString());
244-
if (processedFiles.add(fullFile)) {
245+
if (Files.isSymbolicLink(fullFile)) {
246+
reprocessAllChangedFilesInSettingsDir();
247+
} else if (processedFiles.add(fullFile)) {
245248
if (fileChanged(fullFile)) {
246249
process(fullFile);
247250
}
@@ -257,14 +260,7 @@ protected final void watcherThread() {
257260
settingsDirWatchKey = enableDirectoryWatcher(settingsDirWatchKey, settingsDir);
258261

259262
// re-read the settings directory, and ping for any changes
260-
try (Stream<Path> files = filesList(settingsDir)) {
261-
for (var f = files.iterator(); f.hasNext();) {
262-
Path file = f.next();
263-
if (fileChanged(file)) {
264-
process(file);
265-
}
266-
}
267-
}
263+
reprocessAllChangedFilesInSettingsDir();
268264
} else if (settingsDirWatchKey != null) {
269265
settingsDirWatchKey.cancel();
270266
}
@@ -279,6 +275,17 @@ protected final void watcherThread() {
279275
}
280276
}
281277

278+
private void reprocessAllChangedFilesInSettingsDir() throws IOException, InterruptedException {
279+
try (Stream<Path> files = filesList(settingsDir)) {
280+
for (var f = files.iterator(); f.hasNext();) {
281+
Path file = f.next();
282+
if (fileChanged(file)) {
283+
process(file);
284+
}
285+
}
286+
}
287+
}
288+
282289
protected final synchronized void stopWatcher() {
283290
if (watching()) {
284291
logger.debug("stopping watcher ...");

0 commit comments

Comments
 (0)