diff --git a/server/src/main/java/org/opensearch/index/engine/InternalEngine.java b/server/src/main/java/org/opensearch/index/engine/InternalEngine.java index 1fc998164ac12..4076162f949c4 100644 --- a/server/src/main/java/org/opensearch/index/engine/InternalEngine.java +++ b/server/src/main/java/org/opensearch/index/engine/InternalEngine.java @@ -352,6 +352,9 @@ public void updateCurrentInfos(byte[] infosBytes, long gen) throws IOException { toIndexInput(infosBytes), gen); assert gen == infos.getGeneration(); + if (gen > getLatestSegmentInfos().getGeneration()) { + this.store.syncDirectory(); + } externalReaderManager.internalReaderManager.setCurrentInfos(infos); externalReaderManager.maybeRefresh(); } diff --git a/server/src/main/java/org/opensearch/index/store/Store.java b/server/src/main/java/org/opensearch/index/store/Store.java index 04825ea701fe9..6176e06e243a6 100644 --- a/server/src/main/java/org/opensearch/index/store/Store.java +++ b/server/src/main/java/org/opensearch/index/store/Store.java @@ -104,6 +104,7 @@ import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -208,6 +209,14 @@ public Directory directory() { return directory; } + /** + * Forces an fsync on the directory - to be called by replicas after receiving a new commit point. + * @throws IOException if we are unable to list current directory contents. + */ + public void syncDirectory() throws IOException { + this.directory.sync(Arrays.asList(this.directory.listAll())); + } + /** * Returns the last committed segments info for this store * @@ -785,11 +794,6 @@ public Set getPendingDeletions() throws IOException { // to be removed once fixed in FilterDirectory. return unwrap(this).getPendingDeletions(); } - - @Override - public void sync(Collection names) throws IOException { - // Do nothing. - } } /**