Skip to content

Commit 196ed6b

Browse files
Remove Mostly Redundant Deleting in FsBlobContainer (#60117) (#60195)
In almost all cases we write uuid named files via this method. Preemptively deleting just wastes IO ops, we can delete after a write failed and retry the write to cover the few cases where we actually do an overwrite.
1 parent 53fa52d commit 196ed6b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

server/src/main/java/org/elasticsearch/common/blobstore/fs/FsBlobContainer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,16 @@ public long readBlobPreferredLength() {
176176

177177
@Override
178178
public void writeBlob(String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists) throws IOException {
179-
if (failIfAlreadyExists == false) {
179+
final Path file = path.resolve(blobName);
180+
try {
181+
writeToPath(inputStream, file, blobSize);
182+
} catch (FileAlreadyExistsException faee) {
183+
if (failIfAlreadyExists) {
184+
throw faee;
185+
}
180186
deleteBlobsIgnoringIfNotExists(Collections.singletonList(blobName));
187+
writeToPath(inputStream, file, blobSize);
181188
}
182-
final Path file = path.resolve(blobName);
183-
writeToPath(inputStream, file, blobSize);
184189
IOUtils.fsync(path, true);
185190
}
186191

0 commit comments

Comments
 (0)