Skip to content

Fix S3DBService and LocalDBService file overwrite handling during downloads#5911

Merged
dlvenable merged 4 commits intoopensearch-project:mainfrom
KirtanKakadiya:main
Jul 31, 2025
Merged

Fix S3DBService and LocalDBService file overwrite handling during downloads#5911
dlvenable merged 4 commits intoopensearch-project:mainfrom
KirtanKakadiya:main

Conversation

@KirtanKakadiya
Copy link
Copy Markdown
Contributor

@KirtanKakadiya KirtanKakadiya commented Jul 28, 2025

Description

S3DBService

When downloading the databases from S3, the download will fail if the current file exists as it is not able to overwrite the file. The method which causes this issue is S3DBService.buildRequestAndDownloadFile. Currently this method uses Files.copy from the java.nio.file.Files package which does not allow overwrites.

The solution would be to use the ResponseTransformer.toFile(path) method like this:
S3Client.getObject((b) -> { b.bucket(bucketName).key(key);}, ResponseTransformer.toFile(destination));

LocalDBService

When downloading the databases locally, the download will fail if the current file exists as it is not able to overwrite the file. The method which causes this issue is LocalDBService.initiateDownload. Currently this method uses Files.copy from the java.nio.file.Files package which does not allow overwrites.

The solution would be to use enable the overwrite option using the StandardCopyOption.REPLACE_EXISTING like this:
Files.copy(sourceFile.toPath(), destinationFile.toPath(), StandardCopyOption.REPLACE_EXISTING);

Issues Resolved

Resolves #5898 , #5899

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@KirtanKakadiya KirtanKakadiya changed the title Fix S3DBService file overwrite handling during downloads Fix S3DBService and LocalDBService file overwrite handling during downloads Jul 28, 2025
Copy link
Copy Markdown
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks good, though I have one small comment.

S3DBService s3DBService = createObjectUnderTest();
s3DBService.initiateDownload();

String finalContent = Files.readString(destinationFile.toPath());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move these three lines out of the try block. They don't require the mocked static.

@dlvenable
Copy link
Copy Markdown
Member

Also, your DCO check is failing. You have the use the same email for sign-off as you use in the commits. See:

https://github.com/opensearch-project/data-prepper/pull/5911/checks?check_run_id=46964106373

kirtanhk added 3 commits July 29, 2025 16:11
Signed-off-by: kirtanhk <kirtanhk@amazon.com>
Signed-off-by: kirtanhk <kirtanhk@amazon.com>
Signed-off-by: kirtanhk <kirtanhk@amazon.com>
Signed-off-by: kirtanhk <kirtanhk@amazon.com>
@dlvenable dlvenable merged commit b87890a into opensearch-project:main Jul 31, 2025
50 of 53 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 31, 2025
…nloads (#5911)

Fix S3DBService/LocalDBService file overwrite handling during downloads

Signed-off-by: kirtanhk <kirtanhk@amazon.com>
Co-authored-by: kirtanhk <kirtanhk@amazon.com>
(cherry picked from commit b87890a)
dlvenable pushed a commit that referenced this pull request Jul 31, 2025
…nloads (#5911) (#5934)

Fix S3DBService/LocalDBService file overwrite handling during downloads



(cherry picked from commit b87890a)

Signed-off-by: kirtanhk <kirtanhk@amazon.com>
Co-authored-by: Kirtan Kakadiya <35823164+KirtanKakadiya@users.noreply.github.com>
Co-authored-by: kirtanhk <kirtanhk@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] S3DBService fails to handle existing files during download

3 participants