From a48d1f32b638bea269b29203180bb4c363e90abd Mon Sep 17 00:00:00 2001 From: Marc Handalian Date: Thu, 17 Feb 2022 13:34:48 -0800 Subject: [PATCH] Remove explicit fsync when every file is copied. Signed-off-by: Marc Handalian --- .../org/opensearch/index/engine/InternalEngine.java | 3 --- .../opensearch/indices/recovery/MultiFileWriter.java | 4 +++- .../indices/replication/copy/ReplicationTarget.java | 10 +++++++++- 3 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 4076162f949c4..1fc998164ac12 100644 --- a/server/src/main/java/org/opensearch/index/engine/InternalEngine.java +++ b/server/src/main/java/org/opensearch/index/engine/InternalEngine.java @@ -352,9 +352,6 @@ 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/indices/recovery/MultiFileWriter.java b/server/src/main/java/org/opensearch/indices/recovery/MultiFileWriter.java index f10fc6e834703..d3ccef841b90b 100644 --- a/server/src/main/java/org/opensearch/indices/recovery/MultiFileWriter.java +++ b/server/src/main/java/org/opensearch/indices/recovery/MultiFileWriter.java @@ -151,7 +151,9 @@ private void innerWriteFileChunk(StoreFileMetadata fileMetadata, long position, + temporaryFileName + "] in " + Arrays.toString(store.directory().listAll()); - store.directory().sync(Collections.singleton(temporaryFileName)); + // TODO: Segrep - toggle this with a setting. With segrep we don't want this fsync we will only fsync + // when a new checkpoint is received. +// store.directory().sync(Collections.singleton(temporaryFileName)); IndexOutput remove = removeOpenIndexOutputs(name); assert remove == null || remove == indexOutput; // remove maybe null if we got finished } diff --git a/server/src/main/java/org/opensearch/indices/replication/copy/ReplicationTarget.java b/server/src/main/java/org/opensearch/indices/replication/copy/ReplicationTarget.java index ee253ebaa05aa..85ef63ce3023f 100644 --- a/server/src/main/java/org/opensearch/indices/replication/copy/ReplicationTarget.java +++ b/server/src/main/java/org/opensearch/indices/replication/copy/ReplicationTarget.java @@ -36,6 +36,7 @@ import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.IndexFormatTooNewException; import org.apache.lucene.index.IndexFormatTooOldException; +import org.apache.lucene.store.Directory; import org.opensearch.OpenSearchException; import org.opensearch.action.ActionListener; import org.opensearch.action.StepListener; @@ -59,6 +60,7 @@ import org.opensearch.indices.replication.checkpoint.TransportCheckpointInfoResponse; import java.io.IOException; +import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; @@ -187,7 +189,13 @@ public void finalizeReplication(TransportCheckpointInfoResponse checkpointInfo, } else { assert indexShard.assertRetentionLeasesPersisted(); } - indexShard.updateCurrentInfos(checkpointInfo.getCheckpoint().getSegmentsGen(), checkpointInfo.getInfosBytes()); + final long segmentsGen = checkpointInfo.getCheckpoint().getSegmentsGen(); + // force an fsync if we are receiving a new gen. + if (segmentsGen > indexShard.getLatestSegmentInfos().getGeneration()) { + final Directory directory = store().directory(); + directory.sync(Arrays.asList(directory.listAll())); + } + indexShard.updateCurrentInfos(segmentsGen, checkpointInfo.getInfosBytes()); } catch (CorruptIndexException | IndexFormatTooNewException | IndexFormatTooOldException ex) { // this is a fatal exception at this stage. // this means we transferred files from the remote that have not be checksummed and they are