Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,16 @@ public IndexOutput createOutput(String name, IOContext context) throws IOExcepti
public void sync(Collection<String> names) throws IOException {
ensureOpen();
logger.trace("Composite Directory[{}]: sync() called {}", this::toString, () -> names);
Collection<String> remoteFiles = Arrays.asList(getRemoteFiles());
Collection<String> filesToSync = names.stream().filter(name -> remoteFiles.contains(name) == false).collect(Collectors.toList());
logger.trace("Composite Directory[{}]: Synced files : {}", this::toString, () -> filesToSync);
localDirectory.sync(filesToSync);
Set<String> remoteFiles = Set.of(getRemoteFiles());
Set<String> localFilesHavingBlocks = Arrays.stream(listLocalFiles())
.filter(FileTypeUtils::isBlockFile)
.map(file -> file.substring(0, file.indexOf(BLOCK_FILE_IDENTIFIER)))
.collect(Collectors.toSet());
Collection<String> fullFilesToSync = names.stream()
.filter(name -> (remoteFiles.contains(name) == false) && (localFilesHavingBlocks.contains(name) == false))
.collect(Collectors.toList());
logger.trace("Composite Directory[{}]: Synced files : {}", this::toString, () -> fullFilesToSync);
localDirectory.sync(fullFilesToSync);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ public void testSync() throws IOException {
// All the files in the below list are present either locally or on remote, so sync should work as expected
Collection<String> names = List.of("_0.cfe", "_0.cfs", "_0.si", "_1.cfe", "_2.cfe", "segments_1");
compositeDirectory.sync(names);
// Deleting file _1.cfe and then adding its blocks locally so that full file is not present but block files are present in local
// State of _1.cfe file after these operations - not present in remote, full file not present locally but blocks present in local
compositeDirectory.deleteFile("_1.cfe");
addFilesToDirectory(new String[] { "_1.cfe_block_0", "_1.cfe_block_2" });
// Sync should work as expected since blocks are present in local
compositeDirectory.sync(List.of("_1.cfe"));
// Below list contains a non-existent file, hence will throw an error
Collection<String> names1 = List.of("_0.cfe", "_0.cfs", "_0.si", "_1.cfe", "_2.cfe", "segments_1", "non_existent_file");
assertThrows(NoSuchFileException.class, () -> compositeDirectory.sync(names1));
Expand Down
Loading