Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

cleanup tmp files #570

Merged

Conversation

zhulongcheng
Copy link
Contributor

Closes #565

@zhulongcheng zhulongcheng changed the title WIP: cleanup tmp file Cleanup tmp file Mar 26, 2019
@zhulongcheng zhulongcheng changed the title Cleanup tmp file WIP: cleanup tmp file Mar 26, 2019
@krasi-georgiev
Copy link
Contributor

krasi-georgiev commented Mar 27, 2019

Here is another related bug which we should fix here or in a separate PR
prometheus/prometheus#4058 (comment)

ping me when ready for a review.

@krasi-georgiev
Copy link
Contributor

how is it going with this one?

I received you ping on IRC and replied, but maybe you were offline. I suggest using Riot to never miss IRC messaged.

@zhulongcheng
Copy link
Contributor Author

I suggest using Riot to never miss IRC messaged.

Thanks Krasi

@zhulongcheng zhulongcheng changed the title WIP: cleanup tmp file cleanup tmp meta file Apr 4, 2019
@zhulongcheng zhulongcheng marked this pull request as ready for review April 4, 2019 13:29
block.go Outdated Show resolved Hide resolved
Copy link
Contributor

@krasi-georgiev krasi-georgiev left a comment

Choose a reason for hiding this comment

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

did you test that

if err := os.RemoveAll(to); err != nil {
		return err
	}

is not needed?

block.go Outdated Show resolved Hide resolved
@zhulongcheng zhulongcheng changed the title cleanup tmp meta file cleanup tmp files Apr 8, 2019
@krasi-georgiev
Copy link
Contributor

btw @zhulongcheng don't forget that tomorrow the 9th is the last day for the GSOC proposal submissions. Feel free to ping me on IRC with yours so I can give some feedback before submitting.

@krasi-georgiev
Copy link
Contributor

krasi-georgiev commented Apr 10, 2019

a file conflict and did you test that

if err := os.RemoveAll(to); err != nil {
		return err
	}

is not needed?

@zhulongcheng
Copy link
Contributor Author

Will rebase ASAP.

About test:
For replacing files, os.RemoveAll is not needed.
For replacing dirs, os.RemoveAll is required to ensure the dest dir not exists.

@krasi-georgiev
Copy link
Contributor

so IIUC we do need it since fileutil.Rename should also handle dirs.

@zhulongcheng
Copy link
Contributor Author

so IIUC we do need it since fileutil.Rename should also handle dirs.

How about fileutil.Replace?
https://github.com/prometheus/tsdb/blob/4b3a5ac5d36e5262d2656c8d149e137c2d1fab12/fileutil/fileutil.go#L128-L149

@krasi-georgiev
Copy link
Contributor

do you mean to use Rename only for files and Replace for files or dirs?

is there no way to combine these into a single func?

@krasi-georgiev
Copy link
Contributor

actually maybe best to keep separate, this way when Rename will fail if the destination exists and Replace will delete destination and rename source to destination.

compact.go Show resolved Hide resolved
repair.go Outdated Show resolved Hide resolved
wal.go Outdated Show resolved Hide resolved
@zhulongcheng zhulongcheng force-pushed the clr-tmp-file branch 2 times, most recently from 7912b39 to 5b47f49 Compare April 11, 2019 13:14
block.go Outdated Show resolved Hide resolved
tombstones.go Outdated Show resolved Hide resolved
@zhulongcheng
Copy link
Contributor Author

Maybe we need to reconsider whether we still need the fileutil.Rename function?

If the destination file/dir exists, should use fileutil.Replace.
If the destination file/dir not exists, use fileutil.Replace, and os.RemoveAll (in fileutil.Replace func) just does nothing.

@krasi-georgiev
Copy link
Contributor

I am concerned that this might lead to unexpected data loss. For example if the generated destination ULID of a block collapses with an existing block Replace will just delete the destination without us even knowing about this leading to data loss.

@zhulongcheng
Copy link
Contributor Author

I want to simplify this pr.
just do two things:

  1. replace renameFile with fileutil.Replace, and remove the renameFile func.
  2. cleanup tmp files.

because the implementation of renameFile is identical to fileutil.Replace, the replace operation is safe.

this will make this pr clear and be reviewed friendly.

@zhulongcheng
Copy link
Contributor Author

new a separate issue to discuss implementations and usages of Rename and Replace.

@krasi-georgiev
Copy link
Contributor

ok

@zhulongcheng zhulongcheng force-pushed the clr-tmp-file branch 2 times, most recently from 34f13c2 to 0e2749c Compare April 12, 2019 07:50
@krasi-georgiev
Copy link
Contributor

if #583 turns out to be a good solution to inject FS errors can use it to write a test for this PR.

@krasi-georgiev
Copy link
Contributor

LGTM
no need to wait for #583 as it would probably take a while and we can write that test later.

ping @gouthamve , @codesome , @bwplotka

@krasi-georgiev
Copy link
Contributor

since it is a low risk PR , will merge and if anymore changes are needed will open a new one.

@krasi-georgiev krasi-georgiev merged commit 19d402d into prometheus-junkyard:master Apr 26, 2019
@zhulongcheng zhulongcheng deleted the clr-tmp-file branch April 27, 2019 07:37
Copy link
Contributor

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup temp file if rename/replace failed
3 participants