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.
This commit is contained in:
Armin Braun 2020-07-27 14:05:41 +02:00 committed by GitHub
parent 53fa52d618
commit 196ed6b90e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -176,11 +176,16 @@ public class FsBlobContainer extends AbstractBlobContainer {
@Override @Override
public void writeBlob(String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists) throws IOException { public void writeBlob(String blobName, InputStream inputStream, long blobSize, boolean failIfAlreadyExists) throws IOException {
if (failIfAlreadyExists == false) {
deleteBlobsIgnoringIfNotExists(Collections.singletonList(blobName));
}
final Path file = path.resolve(blobName); final Path file = path.resolve(blobName);
writeToPath(inputStream, file, blobSize); try {
writeToPath(inputStream, file, blobSize);
} catch (FileAlreadyExistsException faee) {
if (failIfAlreadyExists) {
throw faee;
}
deleteBlobsIgnoringIfNotExists(Collections.singletonList(blobName));
writeToPath(inputStream, file, blobSize);
}
IOUtils.fsync(path, true); IOUtils.fsync(path, true);
} }