From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <guix-patches-bounces+larch=yhetil.org@gnu.org>
Received: from mp2 ([2001:41d0:8:6d80::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by ms0.migadu.com with LMTPS
	id qIZPGC8Cf2HnFQAAgWs5BA
	(envelope-from <guix-patches-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Sun, 31 Oct 2021 21:53:03 +0100
Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	by mp2 with LMTPS
	id wBb8Ey8Cf2H+bwAAB5/wlQ
	(envelope-from <guix-patches-bounces+larch=yhetil.org@gnu.org>)
	for <larch@yhetil.org>; Sun, 31 Oct 2021 20:53:03 +0000
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by aspmx1.migadu.com (Postfix) with ESMTPS id E730910654
	for <larch@yhetil.org>; Sun, 31 Oct 2021 21:53:02 +0100 (CET)
Received: from localhost ([::1]:51476 helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <guix-patches-bounces+larch=yhetil.org@gnu.org>)
	id 1mhHp8-0006Qn-2y
	for larch@yhetil.org; Sun, 31 Oct 2021 16:53:02 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:59326)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1mhHoA-0004iA-Ar
 for guix-patches@gnu.org; Sun, 31 Oct 2021 16:52:02 -0400
Received: from debbugs.gnu.org ([209.51.188.43]:49862)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1mhHoA-0007tS-29
 for guix-patches@gnu.org; Sun, 31 Oct 2021 16:52:02 -0400
Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1mhHo9-0003YT-Ri
 for guix-patches@gnu.org; Sun, 31 Oct 2021 16:52:01 -0400
X-Loop: help-debbugs@gnu.org
Subject: [bug#51427] [PATCH] nix: libstore: Do not remove unused links when
 deleting specific items.
Resent-From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: guix-patches@gnu.org
Resent-Date: Sun, 31 Oct 2021 20:52:01 +0000
Resent-Message-ID: <handler.51427.B51427.163571350513640@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 51427
X-GNU-PR-Package: guix-patches
X-GNU-PR-Keywords: patch
To: Ludovic =?UTF-8?Q?Court=C3=A8s?= <ludo@gnu.org>
Cc: 51427@debbugs.gnu.org, Liliana Marie Prikler <liliana.prikler@gmail.com>
Received: via spool by 51427-submit@debbugs.gnu.org id=B51427.163571350513640
 (code B ref 51427); Sun, 31 Oct 2021 20:52:01 +0000
Received: (at 51427) by debbugs.gnu.org; 31 Oct 2021 20:51:45 +0000
Received: from localhost ([127.0.0.1]:33175 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1mhHnt-0003Xw-H4
 for submit@debbugs.gnu.org; Sun, 31 Oct 2021 16:51:45 -0400
Received: from mail-qk1-f170.google.com ([209.85.222.170]:33313)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <maxim.cournoyer@gmail.com>) id 1mhHnr-0003Xh-CH
 for 51427@debbugs.gnu.org; Sun, 31 Oct 2021 16:51:43 -0400
Received: by mail-qk1-f170.google.com with SMTP id a132so13747627qkg.0
 for <51427@debbugs.gnu.org>; Sun, 31 Oct 2021 13:51:43 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 
 h=from:to:cc:subject:references:date:in-reply-to:message-id
 :user-agent:mime-version:content-transfer-encoding;
 bh=Ko6H/BV6WE/WlkVC1GO1AiW9LXIPfe5A07BwQ9NXRIE=;
 b=QATU9+qXOR/E20yiHOkIn0t3QCv2cUfYpiRmTr4WAjd+fyhgebK6MRi2x90ycNOeGE
 GvVzOjrT/hivkjEth4UJbqOnIZbmBwjq2SrugHngF0xgI32UNaN4p9Pf8PByHPn1GN7L
 E13rpqiqSEeHDlo7P50mFMaGydgJcCut58Xw69jjaTOz2GXLWwQmTX8prGchXGGZHuzk
 m3p/VfhAkR2wlb2hxoNTKIuaOWUx7SFAXcr2xChHtHVPL+9C/D8J9chrzsnVtjIRdqp5
 VamVl4A0fShRDkFv2N8qD3laBp+q4sa4GJ0Hk+B6NDDZ6baqGoFm1UwwtORQUESLCmxM
 R8dw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to
 :message-id:user-agent:mime-version:content-transfer-encoding;
 bh=Ko6H/BV6WE/WlkVC1GO1AiW9LXIPfe5A07BwQ9NXRIE=;
 b=er9eHTwmhwgr7Ln6Rz6aRyHocCZ+uMfuPa5kr6ZEzY3bRH7IoS1YPl22aEJcyDkMfV
 v9oGAXkBRAWxsV7aB8F6pQwEyZGRfSd6bJz3Np/pxisrUpb7JL+Xaw7mI+1vP5zUz4xj
 OGthbmz9YR9ZsmcxmbDL67L39uQf/Z6xT9cONG+ReYTmPDUENecWYyKPn1ib8DSRUJgE
 /me3qSKhg6oIgmut53eTR+nCB5juyTy/R8RZ6ZSuF+XwlbhUw/FziTLy2VY8Fd+1AuFN
 mXEoAE/Yc/pm5JkpWtjQtmwALKBgWMI71HtbF0GGpD6GFBniByKPmGBhD9o/BSWfSN4O
 HKnw==
X-Gm-Message-State: AOAM531QKBJkc7ZZuwE0vMmbsOlaeHylo50MS3wpBsTNWMVVtN6VA2m7
 rP6TRmVicm4/JNQA7iValDU2PN+XM6k=
X-Google-Smtp-Source: ABdhPJxb5+AXAuk/CspT199mBdNuTTl2Sh4pIu578vkUnE2uI+oOEDxUgWO9YyD2dMnm8lniO3QbBg==
X-Received: by 2002:a05:620a:178b:: with SMTP id
 ay11mr20500299qkb.287.1635713497455; 
 Sun, 31 Oct 2021 13:51:37 -0700 (PDT)
Received: from hurd (dsl-153-210.b2b2c.ca. [66.158.153.210])
 by smtp.gmail.com with ESMTPSA id e18sm6132720qtw.12.2021.10.31.13.51.36
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 31 Oct 2021 13:51:37 -0700 (PDT)
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
References: <20211027034918.4591-1-maxim.cournoyer@gmail.com>
 <87o8795j61.fsf@gnu.org>
 <5c2dd60acfaa7d74b7554babb3e223bc855bac8a.camel@gmail.com>
 <87h7cxp9tl.fsf@gnu.org>
Date: Sun, 31 Oct 2021 16:51:36 -0400
In-Reply-To: <87h7cxp9tl.fsf@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s
 message of "Sun, 31 Oct 2021 15:07:02 +0100")
Message-ID: <87sfwg7w9z.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-BeenThere: guix-patches@gnu.org
List-Id: <guix-patches.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/guix-patches>,
 <mailto:guix-patches-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/guix-patches>
List-Post: <mailto:guix-patches@gnu.org>
List-Help: <mailto:guix-patches-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/guix-patches>,
 <mailto:guix-patches-request@gnu.org?subject=subscribe>
Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org
Sender: "Guix-patches" <guix-patches-bounces+larch=yhetil.org@gnu.org>
X-Migadu-Flow: FLOW_IN
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org;
	s=key1; t=1635713583;
	h=from:from:sender:sender:reply-to:subject:subject:date:date:
	 message-id:message-id:to:to:cc:cc:mime-version:mime-version:
	 content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:resent-cc:
	 resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to:
	 references:references:list-id:list-help:list-unsubscribe:
	 list-subscribe:list-post:dkim-signature;
	bh=Ko6H/BV6WE/WlkVC1GO1AiW9LXIPfe5A07BwQ9NXRIE=;
	b=SBayDf8xS5ltaEPAHsl4OO+ufspO66Yn1RTX7cAfW2ifdmlou/czU+oBZU1AqNlVZ9OPyF
	LvWNnKWN05KyjQy9tLfK3J+k3127ZmkYUY/4x5WZjdIIDWEvqp8dFohg5dVvHrUQja5aM6
	zzv2vpaDxssCOe+IfHOmTSO1CqpNfEyuv3jqxM3rUwWG7fxinz6molVMfIQUuRCIzSHwD3
	Sv8HLYGVibSA710/CC8Kwpr1K281rB8G77JX/3ca+n1olCqVLOB4Hy75CF0/1Gg92+CG6h
	GjKimi8MXeyaSojYJ0y46DS7hQGYLr8FqUYdctsEptBtXhb73sFDH1AEx4x+9g==
ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635713583; a=rsa-sha256; cv=none;
	b=dVc31fIAM6kkRmGDEIPPSPxeMLCGslLAVrXM11v4VNp48LWI0YEuEg0ri/4zcxSXfOzxwG
	v6PnPg6h2+2T+47zOLMo/x+kDCi6HrcKmzr1YXzlk6X+vebO/sbN/K1ggdyfmUKeikFvPk
	jAmL1y+vll61mTpr8RvYwrhB+li4/gvzGXMzdTuLJz56D/ng6Ia+ZBKvQCNE6N2EVEOJER
	L6n11qYvJDduYG/Td4KcfEEq1gyJ3Dt8NEfZUTLNxU8ZI0rLtf7JgfXSmcwrLihsrPC46N
	VrceKQeRub6/yt0tQIG8fm/D42ZqcNaAd6UXiYtD2wARWUEprmpW2wmMi98VsA==
ARC-Authentication-Results: i=1;
	aspmx1.migadu.com;
	dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=QATU9+qX;
	dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none);
	spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org
X-Migadu-Spam-Score: 0.18
Authentication-Results: aspmx1.migadu.com;
	dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=QATU9+qX;
	dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none);
	spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org
X-Migadu-Queue-Id: E730910654
X-Spam-Score: 0.18
X-Migadu-Scanner: scn0.migadu.com
X-TUID: Xd+p6RSyHHhq

Hi,

Ludovic Court=C3=A8s <ludo@gnu.org> writes:

> Hi,
>
> Liliana Marie Prikler <liliana.prikler@gmail.com> skribis:
>
>> Am Donnerstag, den 28.10.2021, 16:16 +0200 schrieb Ludovic Court=C3=A8s:
>>> Hi,
>>>=20
>>> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>>>=20
>>> > Deleting unused links can be a very costly operation, especially on
>>> > rotative hard drives.  As removing single store items is often used
>>> > for experimentation rather than for cleaning purposes, this change
>>> > allows it to run without the links cleanup.
>>> >=20
>>> > * nix/libstore/gc.cc (LocalStore::collectGarbage): Do not clean up
>>> > links when
>>> > the specified action is GCOptions::gcDeleteSpecific.
>>> > ---
>>> >  nix/libstore/gc.cc | 2 +-
>>> >  1 file changed, 1 insertion(+), 1 deletion(-)
>>> >=20
>>> > diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc
>>> > index e1d0765154..7d872d8cc1 100644
>>> > --- a/nix/libstore/gc.cc
>>> > +++ b/nix/libstore/gc.cc
>>> > @@ -771,7 +771,7 @@ void LocalStore::collectGarbage(const GCOptions
>>> > & options, GCResults & results)
>>> >      deleteGarbage(state, state.trashDir);
>>> >=20=20
>>> >      /* Clean up the links directory. */
>>> > -    if (options.action =3D=3D GCOptions::gcDeleteDead ||
>>> > options.action =3D=3D GCOptions::gcDeleteSpecific) {
>>> > +    if (options.action =3D=3D GCOptions::gcDeleteDead) {
>>>=20
>>> I believe the effect is that =E2=80=98guix gc -D /gnu/store/=E2=80=A6-d=
isk-image=E2=80=99
>>> would remove nothing: /gnu/store/.links would still contain a copy of
>>> that big disk image, so as a result, you=E2=80=99ve freed zero bytes.
>>>=20
>>> Am I right?
>> I think that might be the point.  As Maxim said, single items are
>> (likely) not removed for cleaning purposes, so freeing the disk image
>> has little effect.
>
> What do you mean?  When doing VM testing, I regularly do =E2=80=98guix gc=
 -D
> /gnu/store/=E2=80=A6-disk-image=E2=80=99 precisely to save space.  Fortun=
ately it does
> have the intended effect of freeing a bunch of GiBs.
>
>> Plus, you could invoke it like
>>
>>   guix gc -D dead-item dead-item live-item dead-item
>>
>> It would fail at live-item and then not continue to free the links of
>> the two dead items prior.
>
> Yes, and that=E2=80=99s annoying, but it=E2=80=99s unrelated.  :-)
>
>> So there's a few things we could do here:
>>
>> 1. simply fail and have the user deal with it (including the option of
>> doing a normal `guix gc' or `guix gc -C 1')
>> 2. remember which paths were live and dead and always clean up the
>> links, only reporting errors afterwards
>> 3. add an option to explicitly check the .links directory (which
>> defaults to true for the current things, but could also be used to
>> clean links after a liveness check or after a do-nothing `guix gc -F').
>> 4. ...
>
> You seem to be proposing to remove =E2=80=98-D=E2=80=99 altogether.  I ag=
ree it has the
> shortcomings you write, but I think it=E2=80=99s occasionally useful
> nonetheless.
>
> My proposal would be either the status quo, or removing just the one
> link that matters from /gnu/store/.links upon =E2=80=98-D=E2=80=99.

The second proposal makes sense.  I didn't care about freeing space, as
my use case was getting around corrupting an item in my store due to
https://issues.guix.gnu.org/51400, which the patch proposed here allowed
me to do without wasting hours of cleaning up links (nearly 1 GiB of
store on spinning drives).

Thanks,

Maxim