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

Non-blocking garbage collector #5149

Merged
merged 26 commits into from
Oct 28, 2021
Merged

Conversation

edolstra
Copy link
Member

@edolstra edolstra commented Aug 17, 2021

This makes it possible to run builds when the garbage collector is running. So the message waiting for the big garbage collector lock... is a thing of the past.

Processes that start while the GC is running inform the GC process by connecting to the latter via a Unix domain socket (/nix/var/nix/gc-socket/socket). They write a path to the socket and then read a single-byte response to synchronize. After receiving the response, the GC process knows about the new root and won't delete it.

Note: nix-store --delete <path> will no longer delete the referrers of <path>. That was probably not expected behaviour anyway.

@edolstra edolstra marked this pull request as draft August 17, 2021 18:23
@edolstra edolstra changed the title Non blocking gc Non-blocking garbage collector Aug 17, 2021
@edolstra edolstra force-pushed the non-blocking-gc branch 2 times, most recently from 02fccb3 to 71d2a14 Compare August 19, 2021 20:46
@Mic92
Copy link
Member

Mic92 commented Aug 20, 2021

cc @domenkozar maybe relevant for cachix watch-store?

@domenkozar
Copy link
Member

Will Nix then consider referrers paths a valid?

@Ericson2314
Copy link
Member

I hope referrers to a path will still prevent deletions!

@edolstra
Copy link
Member Author

Yes, if a path has any refererrs, then deletion will fail. Previously it would recursively delete unreachable referrers (especially dangerous in combination with --ignore-liveness).

src/libutil/util.cc Outdated Show resolved Hide resolved
src/libutil/util.cc Outdated Show resolved Hide resolved
src/libutil/util.cc Outdated Show resolved Hide resolved
src/libutil/util.cc Outdated Show resolved Hide resolved
src/libutil/util.cc Outdated Show resolved Hide resolved
@edolstra edolstra force-pushed the non-blocking-gc branch 2 times, most recently from 7a06d24 to c63af2f Compare October 8, 2021 12:25
edolstra and others added 10 commits October 13, 2021 12:12
The garbage collector no longer blocks other processes from
adding/building store paths or adding GC roots. To prevent the
collector from deleting store paths just added by another process,
processes need to connect to the garbage collector via a Unix domain
socket to register new temporary roots.
Co-authored-by: Jörg Thalheim <Mic92@users.noreply.github.com>
This test broke the assumption that the hash parts of store paths are
unique.
(where "referrers" includes the reverse of derivation outputs and
derivers). Now we do a full traversal to look if we can reach any
root. If not, all paths reached can be deleted.
This fixes a bug in the garbage collector where if a path
/nix/store/abcd-foo is valid, but we do a
isValidPath("/nix/store/abcd-foo.lock") first, then a negative entry
for /nix/store/abcd is added to pathInfoCache, so /nix/store/abcd-foo
is subsequently considered invalid and deleted.
@edolstra edolstra marked this pull request as ready for review October 15, 2021 13:51
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tweag-nix-dev-update-20/15727/1

@edolstra edolstra merged commit 0d00dd6 into NixOS:master Oct 28, 2021
@edolstra edolstra deleted the non-blocking-gc branch October 28, 2021 21:55
edolstra added a commit that referenced this pull request Dec 13, 2021
Comment on lines +139 to +146
} catch (SysError & e) {
/* The garbage collector may have exited, so we need to
restart. */
if (e.errNo == EPIPE) {
debug("GC socket disconnected");
state->fdRootsSocket.close();
goto restart;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is missing a rethrow for other error codes (#6648).

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.

8 participants