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

Save patches to temporary files #9296

Closed
wants to merge 6 commits into from

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented Dec 8, 2019

This PR saves patches directly to a temporary file rather than read these directly into memory - this fixes a number of issues but not the issue that spurred me to look at this.

This could be backported to 1.10 as it doesn't make any significant changes to the code structure.

@zeripath zeripath added this to the 1.11.0 milestone Dec 8, 2019
os.Rename cannot rename across disk boundaries
models/pull.go Show resolved Hide resolved
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 9, 2019
@codecov-io
Copy link

codecov-io commented Dec 9, 2019

Codecov Report

Merging #9296 into master will decrease coverage by <.01%.
The diff coverage is 35.13%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9296      +/-   ##
==========================================
- Coverage   41.19%   41.18%   -0.01%     
==========================================
  Files         559      559              
  Lines       73073    73126      +53     
==========================================
+ Hits        30099    30114      +15     
- Misses      39205    39240      +35     
- Partials     3769     3772       +3
Impacted Files Coverage Δ
modules/git/repo_compare.go 68.18% <100%> (ø) ⬆️
models/pull.go 53.51% <22.22%> (-0.9%) ⬇️
routers/api/v1/repo/pull.go 35.14% <35.29%> (-0.05%) ⬇️
models/repo.go 47.89% <35.29%> (-0.04%) ⬇️
routers/repo/pull.go 30.26% <38.88%> (+0.13%) ⬆️
services/pull/pull.go 39.43% <50%> (ø) ⬆️
modules/indexer/indexer.go 44.73% <0%> (-10.53%) ⬇️
models/gpg_key.go 55.59% <0%> (+0.55%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update baae90e...810898f. Read the comment docs.

models/pull.go Show resolved Hide resolved
routers/repo/pull.go Outdated Show resolved Hide resolved
routers/api/v1/repo/pull.go Outdated Show resolved Hide resolved
routers/repo/pull.go Outdated Show resolved Hide resolved
routers/api/v1/repo/pull.go Outdated Show resolved Hide resolved
@zeripath zeripath changed the title WIP: Save patches to temporary files Save patches to temporary files Dec 9, 2019
_ = os.Remove(tmpPatchFile.Name())
}()

if err := headGitRepo.GetPatch(pr.MergeBase, pr.HeadBranch, tmpPatchFile); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if err := headGitRepo.GetPatch(pr.MergeBase, pr.HeadBranch, tmpPatchFile); err != nil {
err = headGitRepo.GetPatch(pr.MergeBase, pr.HeadBranch, tmpPatchFile)
tmpPatchFile.Close()
if err != nil {

}()

if err := headGitRepo.GetPatch(pr.MergeBase, pr.HeadBranch, tmpPatchFile); err != nil {
tmpPatchFile.Close()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tmpPatchFile.Close()

}()

if err := headGitRepo.GetPatch(prInfo.MergeBase, headBranch, tmpPatchFile); err != nil {
tmpPatchFile.Close()
Copy link
Member

Choose a reason for hiding this comment

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

same with tmpPatchFile.Close()

Copy link
Member

@6543 6543 left a comment

Choose a reason for hiding this comment

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

looks good but reduce code by remove tmpPatchFile.Close() redundancy ?

@guillep2k
Copy link
Member

So is this obsolete or complementary regarding #9302 ?

@zeripath
Copy link
Contributor Author

zeripath commented Dec 9, 2019

This one is simpler, the other is more of a refactor but also likely fixes the issue that spurred me to look at this.

We could probably backport this one - if we think the efficiency is worth it.

Copy link
Member

@guillep2k guillep2k left a comment

Choose a reason for hiding this comment

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

There are several issues with the patch file approach; I like #9302 better, but I understand it's not easy to backport.

if len(patch) > 0 {
if err = repo.savePatch(sess, pr.Index, patch); err != nil {
if patchFileSize > 0 {
if err = repo.savePatch(sess, pr.Index, patchFileName); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I think the patch should be saved even if it's got 0 bytes. The reason is that a previous PR creation attempt (from a different PR, with patch data) could have failed between this step and the commit, so a left-over patch file (named after this same index number) might still be lingering in the directory. I hope that makes sense.

In fact, there are scenarios where that patch could be broken anyway with this retry mechanism. Mmm.... we should be locking that path, at the very least? Sorry, I wasn't aware that there were destinations other than the database when I wrote the retry code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would make it simpler if we dropped that file size test.

Tbh I'm not certain that the patch files are ever actually cleaned up. I don't remember seeing any code looking at deleting them. I actually forgot to look explicitly - that's not like me!!

You're also right about the lack of file locking. This might be because we have generally migrated from the repoworkingcopy lock mechanism to rely on git locking but obviously this doesn't use that mechanism. #9302 obviously isn't affected by this.

I guess the question is how important is it provide a backport?

If we're not going to backport - then I'm happy to close this and move to the more radical refactor.

(It's not like this is the only place we still read in potentially huge amounts of data - diff and blame are both still doing that, and a change to streaming there will require huge refactoring.)

Copy link
Member

Choose a reason for hiding this comment

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

Well, backporting is not my call, but I'm OK with not backporting this as long as #9302 makes it in time for 1.11.

@zeripath
Copy link
Contributor Author

I'm gonna close this. We can re-examine this technique if 1.10 has lots of problems with its current structure.

@zeripath zeripath closed this Dec 11, 2019
@zeripath zeripath deleted the SavePatch-must-go branch December 26, 2019 12:36
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants