From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.156 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796367204; b=L4keUH38USA49PoJd3LvpVwAZlmfTgFO+mJfZH1Pt2gV0BcQoL75p38bnn0ftDFWSqzd kBMB8eX5lmzb6Z1x54v4CGUvREL7RvvraC++rdWJXpcyrH61OrL0sg6FWbRstReCiaqZI Fnp3mk2tNOad5VsAUXu6kXDdWA4gLKHZTePC7IdrOSOmuHA+IHsncY9TRHaOpcxciQlvn F6XQkT07po3/9HT6WUDDG06e2C4SYSBj2eUJNi2pfv/xSvLSaccQQrhoIpVa8za49BAej lBr2yN15C71iUbtUcH7cMCx+vNcYnIpnOvkRT8W0XIkPXYWrDAretfE4ZeKc6lMfTKQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796367204; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=yb//O7dIuzp7UbpEmg9nf7IlefoU+R/qJozzeRYNPgE=; b=yd3IgNFcCEZkZOgLWiIPyKh45KSpyE8vX6zTru5vufSOeqdi0t71vwQqDFw6KWUzHsx+ Yw7n0h79hfz9mWbD+uBACwvDryPw0GGB0aNi/9EPwM4b+UtNB9CkZINx4A75hZZWThe8r FqBCiTO/auFNANrulFyhMZmaSCxyWFAm7luK6HYY3kYt7y9bHWuBA38LIWM+t9pKAA90h 3SBzGq/JpmHxRaxe8Mpj7I24j9/wWJVL84FLuWsFF2QmhaxuACRmDTArG/vHCQZ7jKogT tRFshZfuxo8lkUvQZBL9RLWPJsz4NwFuVs4Ru9dbVweUR70RacdRMkWL2WLje1VR3Pw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass header.d=pks.im header.i=@pks.im header.a=rsa-sha256 header.s=fm3 header.b=hpFg5hQl; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=aABVH0SS; arc=none smtp.remote-ip=202.12.124.156 Received: from fhigh-b5-smtp.messagingengine.com (fhigh-b5-smtp.messagingengine.com [202.12.124.156]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F41E3606A32C for ; Fri, 4 Dec 2026 06:53:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F41E3606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=pks.im header.i=@pks.im header.a=rsa-sha256 header.s=fm3 header.b=hpFg5hQl; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=aABVH0SS Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfhigh.stl.internal (Postfix) with ESMTP id 2AE017A0190 for ; Fri, 4 Dec 2026 01:53:23 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Fri, 04 Dec 2026 01:53:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1796367203; x=1796453603; bh=yb//O7dIuz p7UbpEmg9nf7IlefoU+R/qJozzeRYNPgE=; b=hpFg5hQl7Bbce4K8mhUhtiEx4Y InIv3W/RO/mf6d759BLkHt8ND3uUvupkxUPBkKw8EWomYadkL5uhmmoWm2Xuxqbp h4p/QXnN+eZwNG6S0ZBCys7wrLZFOgSfQVS5YUhJn9qrloQR+Him0ud3daJMiFGI eG9RRReFltZchIyfZm/75dwfOZQ0JvmNMP7s2WzAtIEqAWL2f7gJ2Z9n5/46lzlN 49nbYO4vTixRn0dXqFSWHtIhNur7F1L84HhFoxibGtIQdr4uybqtOXYJqN2yjPuN YumywgsnLaznCoK3HyR1OBHXnArJF5JmCKNrAzp8E8v9a5EAKLqEqy9l/CFQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1796367203; x=1796453603; bh=yb//O7dIuzp7UbpEmg9nf7IlefoU+R/qJoz zeRYNPgE=; b=aABVH0SS0sX3oBC/TTEZGd1u9Mf74bNFJcBKtdR0ugXHnze+HmH tPBOmF1kr7K9cldAXl1mBG4v9y0I0mJ/MgVMgHSiwitB1IaZ9qXMc7FxIAzegph9 CyLHiubVz3xve9tRIDRSIfNYy83MTSI/TVUoNbYXLTnaPVaY0faFOGyHqmhPKcsx FKQwY8ktGGoyXBLFvPQoCYrNN7pwmbPZbeqNktkkxxhIPYj/RaUeQr/5drUHFNrG IsYoLdw9fWJzTyzhp5xGD3z55ixzT6yvJ+lxvVXLTREoGaNTo3ASJNfx/mMBuNfF GFLDGYsYQlJ231VKmgjxeLpwvtJ3ETE62jA== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=pks.im a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796367203; d=pks.im; mf=PHBzQHBrcy5pbT4=; rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:Gyj0z8/sM4eTyTtyuSzzJ8dMr3aLY44JpzNTBJmZPqTRtlC oFpQLsHQTSwoj30DzhXppqvJNtLRjeyAQM9ppZI0Q0OCz1rkBxJzn+Ys9BjIFa6C +DZDeCAbdU52N7u3Evo1epnUrsMZJMhsngRjXgnTGkv2Q0SB4tAhBMpJBUX5TXff Tu+4FTH7CSDPw/jLrp5rlG61UzA8pjHDa/S0E0hIUN8/DAODiWy+Hwv832zmUeyE tWvlmmLeDzqjjez+N9XhvrN3ipSoIzjUWfVOEQLUptF79gF+ROMSimMBf6v9g6sh Fm9Rdfnvc3krwRflhDRWVuCdO2QqYp9XoiScRCA==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-disposition,content-type,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:FCA3lT6bDIEgYwOI/5X6D1f2IxJhNxEmBuIscMQZGJs=:7s80WL8+gfglXswaYjEZbIAcdJz6NudsVbYeIXmqq3I=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFUXJGjwa2xtzenG7xU5rN4i5zhww/qpwen77iypswIWnSstZiHfMEItejltUq5RV hC8o6mCXPL3f4zr/qJ6vpXhn852KBz6l+9CkoRsyaOEw/jTwdv0BjzEVqJiBGfd08201Lw +CHnESRW456RaHNQoOn+2Y2/tg9KkZS96fpy8uydLEUP46wmJ6xX93ulpAkb9lfcp/cDk1 nfkAg7ei8guV5gFEYVL+e5ckb7cgJL0IUWcP43vJjEWJQaRFFFKWqXflvT38PgtqEj3t5F LPu1hS90DQoAboFpJt2GPIaisTn7/Q3CqbU2/DBy7791mo7FcGXQbLDeuaU2J1y3CvgKKj YEiJAYVIgxgFEp/7YmBEhvp0aQsJkxMRqf+YrorulCknDlWUkJvsAe68wCZzGFSlEm1rvF S5M73UpmB+Jcdnrk2WUsRB1wuSZN4+6GUNP5ii/BqUXnqmbEOw6dFMOksC5iUEDtLgBb13 Lku+RvKhqGBWl71+6uewMkfV5cStdY+zQaEJHBUwHf7G9bQoTUor5nJ8uQZTu/Ot1bPmYF HhgVMKSZ682dCsl/6LedH0mFambwv+MS8OTSI50TycX5tXzFZnNOIV1/2siDY3s5oCNwuC 0rF2/56pMaYXFEfvqxTwF5qMuCn5TekxD7jFlh5/RZeHfcq/l3vjPv7jRWKg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 4 Dec 2026 01:53:21 -0500 (EST) Received: by mail (OpenSMTPD) with ESMTPSA id 01b4f7ce (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 4 Dec 2026 06:53:19 +0000 (UTC) Date: Fri, 4 Dec 2026 07:53:15 +0100 From: Patrick Steinhardt To: Aman Ganapathy Cc: git@vger.kernel.org, John Cai Subject: Re: [PATCH] reftable/writer: fsync table after writing its footer Message-ID: References: <20261204022550.17883-1-amanganapathy@gmail.com> X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261204022550.17883-1-amanganapathy@gmail.com> On Thu, Dec 03, 2026 at 06:25:50PM -0800, Aman Ganapathy wrote: > When adding a table to the stack, we write it to a temporary file, fsync > it, rename it into place and then update "tables.list" to refer to it. > The fsync is there so that the table is on disk before "tables.list" > points to it. But reftable_writer_close() calls the flush callback > before writing the footer, so the footer is not covered by the fsync. > > After a crash, the new table can thus end up without its footer while > "tables.list" already refers to it. Reading the stack then fails and git > acts as if there were no refs at all, not just the ones in the new > table: "git for-each-ref" prints nothing, and "git gc --prune=now" > deletes every object. This can be reproduced with core.fsync=reference > by shutting down the filesystem with "xfs_io -x -c shutdown" right after > "git update-ref" returns. This failure mode is quite surprising. I would have expected that we die with a lot of noise and refuse to do anything in case the reftable stack is corrupt. Did you by any chance also investigate why that's the case? > diff --git a/reftable/writer.c b/reftable/writer.c > index 073b9bbd89..1ba54398a2 100644 > --- a/reftable/writer.c > +++ b/reftable/writer.c > @@ -775,16 +775,16 @@ int reftable_writer_close(struct reftable_writer *w) > reftable_put_be32(p, crc32(0, footer, p - footer)); > p += 4; > > + err = padded_write(w, footer, footer_size(writer_version(w)), 0); > + if (err < 0) > + goto done; > + > err = w->flush(w->write_arg); > if (err < 0) { > err = REFTABLE_IO_ERROR; > goto done; > } > > - err = padded_write(w, footer, footer_size(writer_version(w)), 0); > - if (err < 0) > - goto done; > - > if (empty_table) { > err = REFTABLE_EMPTY_TABLE_ERROR; > goto done; The diff looks obviously good to me. In theory we could even move the flush after the check for the empty table, because we won't commit such a table to disk anyway. But I don't think that necessitates a reroll. > diff --git a/t/unit-tests/u-reftable-readwrite.c b/t/unit-tests/u-reftable-readwrite.c > index 5794b460c6..ead2e80987 100644 > --- a/t/unit-tests/u-reftable-readwrite.c > +++ b/t/unit-tests/u-reftable-readwrite.c > @@ -662,6 +662,47 @@ void test_reftable_readwrite__write_empty_table(void) > reftable_buf_release(&buf); > } > > +struct flush_check { > + struct reftable_buf buf; > + size_t len_at_flush; > +}; > + > +static ssize_t flush_check_write(void *arg, const void *data, size_t sz) > +{ > + struct flush_check *check = arg; > + cl_assert(!reftable_buf_add(&check->buf, data, sz)); > + return sz; > +} > + > +static int flush_check_flush(void *arg) > +{ > + struct flush_check *check = arg; > + check->len_at_flush = check->buf.len; > + return 0; > +} > + > +void test_reftable_readwrite__write_flush_after_footer(void) > +{ > + struct reftable_write_options opts = { 0 }; > + struct flush_check check = { .buf = REFTABLE_BUF_INIT }; > + struct reftable_ref_record ref = { > + .refname = (char *) "refs/heads/main", > + .update_index = 1, > + .value_type = REFTABLE_REF_VAL1, > + }; > + struct reftable_writer *w; > + > + cl_assert(!reftable_writer_new(&w, flush_check_write, flush_check_flush, > + &check, REFTABLE_HASH_SHA1, &opts)); > + reftable_writer_set_limits(w, 1, 1); > + cl_assert(!reftable_writer_add_ref(w, &ref)); > + cl_assert(!reftable_writer_close(w)); > + cl_assert_equal_i(check.len_at_flush, check.buf.len); > + > + reftable_writer_free(w); > + reftable_buf_release(&check.buf); > +} Clever. It's nice to see how easy it is with our unit tests to exercise even small details of the system. Overall I think this patch is already in a good state. Thanks for the fix! Patrick