Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: delete staging and load files post successful sync #5428

Merged
merged 5 commits into from
Jan 23, 2025

Conversation

shekhar-rudder
Copy link
Member

@shekhar-rudder shekhar-rudder commented Jan 13, 2025

Description

This PR introduces support for cleaning up staging and load files from object storage based on the user preference (cleanupObjectStorageFiles). If file deletion fails, the job will be marked as failed. The cleanup process occurs just before marking the job as complete.

Implementation Details
The UploadJob struct already includes stagingFiles. Using their ids, the corresponding load files are retrieved. Keys are then computed from the locations of both file types, and the files are deleted.

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@shekhar-rudder shekhar-rudder force-pushed the war-134-delete-files branch 2 times, most recently from b07c7f6 to f333dfc Compare January 21, 2025 02:49
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 68.57143% with 11 lines in your changes missing coverage. Please review.

Project coverage is 74.76%. Comparing base (2541b1c) to head (25d59cb).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
warehouse/router/upload.go 68.57% 7 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5428      +/-   ##
==========================================
- Coverage   74.82%   74.76%   -0.07%     
==========================================
  Files         440      440              
  Lines       61668    61705      +37     
==========================================
- Hits        46145    46134      -11     
- Misses      12987    13021      +34     
- Partials     2536     2550      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shekhar-rudder shekhar-rudder marked this pull request as ready for review January 21, 2025 04:22
warehouse/router/upload.go Outdated Show resolved Hide resolved
warehouse/router/upload.go Outdated Show resolved Hide resolved
warehouse/router/upload.go Outdated Show resolved Hide resolved
warehouse/router/upload.go Outdated Show resolved Hide resolved
Comment on lines +367 to +369
if err = job.cleanupObjectStorageFiles(); err != nil {
break
}

Choose a reason for hiding this comment

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

@shekhar-rudder Say if this fails. Would the job be retried? If yes, in next retry would it continue from just cleanupObjectStorageFiles?

Choose a reason for hiding this comment

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

@shekhar-rudder @achettyiitr Also from PRD doc, did we close on failing the job or considering metric and internal alert for now?

Copy link
Member Author

Choose a reason for hiding this comment

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

@RanjeetMishra If the cleanup fails, the job will be marked as failed. On the next retry, I would assume it will proceed as it would for any other error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since now it is config based deletion, I think its fine to mark the job as failed. If customer doesn't want the syncs to error out, they can always turn it off.

Choose a reason for hiding this comment

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

Seems fine if we are aligning with marking sync jobs as failed. Regarding destination config for old and new destinations lets finalize tomorrow. This PR is good to go in that case.

Comment on lines 457 to 463
filesToDelete := make([]string, len(job.stagingFiles)+len(loadingFiles))
for i, file := range job.stagingFiles {
filesToDelete[i] = fm.GetDownloadKeyFromFileLocation(file.Location)
}
for i, file := range loadingFiles {
filesToDelete[i+len(job.stagingFiles)] = fm.GetDownloadKeyFromFileLocation(file.Location)
}

Choose a reason for hiding this comment

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

minor: Can see if you like lo map here.

fileKeysToDel := lo.Map(job.stagingFiles, func(file FileType, _ int) string {
	return fm.GetDownloadKeyFromFileLocation(file.Location)
})
loadingFilesKeys := lo.Map(loadingFiles, func(file FileType, _ int) string {
	return fm.GetDownloadKeyFromFileLocation(file.Location)
})

fileKeysToDel = append(fileKeysToDel, loadingFilesKeys...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced with lo

@RanjeetMishra RanjeetMishra self-requested a review January 22, 2025 11:42
@shekhar-rudder shekhar-rudder merged commit 134fbc0 into master Jan 23, 2025
58 checks passed
@shekhar-rudder shekhar-rudder deleted the war-134-delete-files branch January 23, 2025 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants