From 12bf217970917ca1c600dc49db2073468b9bb598 Mon Sep 17 00:00:00 2001 From: Marc Handalian Date: Tue, 15 Feb 2022 10:27:29 -0800 Subject: [PATCH] Remove bypass of fsync on primaries and force fsync on replicas. This change will force an fsync on replicas when a new commit point is received. Signed-off-by: Marc Handalian --- .../opensearch/index/engine/InternalEngine.java | 3 +++ .../java/org/opensearch/index/store/Store.java | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) 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. - } } /**