Skip to content

Commit

Permalink
Remove bypass of fsync on primaries and force fsync on replicas.
Browse files Browse the repository at this point in the history
This change will force an fsync on replicas when a new commit point is received.

Signed-off-by: Marc Handalian <[email protected]>
  • Loading branch information
mch2 committed Feb 15, 2022
1 parent 507bdab commit 12bf217
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
14 changes: 9 additions & 5 deletions server/src/main/java/org/opensearch/index/store/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -785,11 +794,6 @@ public Set<String> getPendingDeletions() throws IOException {
// to be removed once fixed in FilterDirectory.
return unwrap(this).getPendingDeletions();
}

@Override
public void sync(Collection<String> names) throws IOException {
// Do nothing.
}
}

/**
Expand Down

0 comments on commit 12bf217

Please sign in to comment.