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

Implement --delete-generations + flag for keeping last N number of gens #767

Merged
merged 5 commits into from May 31, 2018

Conversation

mogorman
Copy link
Contributor

@mogorman mogorman commented Jan 7, 2016

I don't find keeping last X days of generations as useful to me as keeping the last X number of generations. so I implemented it.

@domenkozar
Copy link
Member

cc @edolstra

@@ -37,6 +37,8 @@ void deleteGeneration(const Path & profile, unsigned int gen);

void deleteGenerations(const Path & profile, const std::set<unsigned int> & gensToDelete, bool dryRun);

void deleteGenerationsGreaterThan(const Path & profile, const string & max, bool dryRun);
Copy link
Member

Choose a reason for hiding this comment

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

max should be an integer. (I.e. the conversion to int should be done in nix-env.cc where the argument parsing happens.)

@edolstra
Copy link
Member

Looks good apart from my two comments.

@mogorman
Copy link
Contributor Author

fixes what was brought up in comments

@domenkozar domenkozar added the feature Feature request or proposal label Jul 21, 2016
@Profpatsch
Copy link
Member

merge?

@mogorman
Copy link
Contributor Author

bump from mailinglist

@mogorman
Copy link
Contributor Author

@edolstra or @domenkozar could you take a look if you get the time?

Copy link

@jb55 jb55 left a comment

Choose a reason for hiding this comment

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

Looking forward to this! Just noticed a possible typo.

} else if (opArgs.size() == 1 && opArgs.front().find('+') != string::npos) {
if(opArgs.front().size() < 2)
throw Error(format("invalid number of generations ‘%1%’") % opArgs.front());
string str_max = string(opArgs.front() 1, opArgs.front().size());
Copy link

Choose a reason for hiding this comment

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

typo here? opArgs.front() 1

@mogorman
Copy link
Contributor Author

yup you were right i hadnt rerun it when i made that change

@@ -37,6 +37,8 @@ void deleteGeneration(const Path & profile, unsigned int gen);

void deleteGenerations(const Path & profile, const std::set<unsigned int> & gensToDelete, bool dryRun);

void deleteGenerationsGreaterThan(const Path & profile, const int max, bool dryRun);
Copy link
Member

Choose a reason for hiding this comment

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

Can deleteGenerations be removed? It looks like a special case of deleteGenerationsGreaterThan with max=1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, deleteGenerations can be given a list of specific generations where as mine will only keep x in chronological order, or the date one will only keep so many dates back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@edolstra any chance we can get this merged before 18.03 release?

Copy link
Member

Choose a reason for hiding this comment

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

I suppose we could unify the two functions by simply having deleteGenerationsOlderThan build the std::set and then pass it into deleteGenerations. I doubt the deduplication would be that valuable though.

Although I did notice that you don't check against curGen, but deleteGenerations does. Do you do anything to ensure you don't delete the current generation? If not, perhaps it'd pay to just call the existing function with the set you computed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copumpkin I could be mistaken but rereading the logic I wrote, it shouldn't be possible to delete the current generation, the list of gens checks to see if it hits the end of generations and bails out at that point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copumpkin you were correct that it would have been possible to have deleted the currentgeneration if you had done enough rollbacks. I have modified the code to make sure this is not possible

@dtzWill
Copy link
Member

dtzWill commented Mar 1, 2018

Is the last generation always the current one, even after rollback and such?

@mogorman
Copy link
Contributor Author

mogorman commented Mar 2, 2018

I am going to confirm the delete current generation issue now in a roll back situation now.

@mogorman mogorman force-pushed the garbage_collect_keep_last_few branch from 9057aa1 to 12fe224 Compare March 2, 2018 02:48
@mogorman
Copy link
Contributor Author

mogorman commented Mar 2, 2018

thanks @dtzWill i went back and changed the logic slightly. now it starts the count from the current generation rather than the beginning of the list. I also updated docs to explain this. I think this is more likely what people will want. I would say this is good to go again.

@jackjennings
Copy link

Any chance this is still on the table? This would help put immensely in a nixops managed server that consistently runs out of space unless cleaned up manually. Being able to only keep the last N generations would make keeping the disk relatively empty much easier.

I would be happy to contribute if some manual tasks need to be performed to update this pull request to work with the latest release…

@peti
Copy link
Member

peti commented May 31, 2018

This will do it:

$ cd /nix/var/nix/profiles
$ ls -1d system-*-link | head -n -5 | xargs --no-run-if-empty rm
# nix-collect-garbage

@peti peti merged commit 93aa3be into NixOS:master May 31, 2018
@mogorman
Copy link
Contributor Author

woohoo

@mogorman mogorman deleted the garbage_collect_keep_last_few branch May 31, 2018 08:06
@jackjennings
Copy link

Thank you @peti!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants