Git development
 help / color / mirror / Atom feed
From: Justin Tobler <jltobler@gmail.com>
To: git@vger.kernel.org
Cc: ps@pks.im, karthik.188@gmail.com, Justin Tobler <jltobler@gmail.com>
Subject: [PATCH v2 2/2] object-file: flush transaction packfile before migrating objects
Date: Wed, 23 Sep 2026 17:03:15 -0500	[thread overview]
Message-ID: <20260923220315.569424-3-jltobler@gmail.com> (raw)
In-Reply-To: <20260923220315.569424-1-jltobler@gmail.com>

A "files" ODB transaction creates a temporary directory to stage newly
written objects in when configured to batch fsync loose objects. Once
the temporary directory is created, it is configured as the primary ODB
and all object are written to it accordingly. This also includes
packfiles containing blobs that exceed `core.bigFileThreshold` written
via `odb_transaction_files_write_object_stream()`.

If a "large" blob packfile is written to the ODB transaction temporary
directory after other loose objects, the ODB transaction fails to commit
as a result of the temporary directory being migrated prior to the
packfile being flushed. Fix this bug by always flushing the packfile
transaction before objects are migrated to the main ODB.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
 object-file.c    |  4 ++--
 t/t1050-large.sh | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/object-file.c b/object-file.c
index 0f123b79fa..210984f825 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1262,6 +1262,8 @@ static int odb_transaction_files_commit(struct odb_transaction *base)
 		container_of(base, struct odb_transaction_files, base);
 	int have_packfile = !!transaction->packfile.f;
 
+	flush_packfile_transaction(transaction);
+
 	if (transaction->objdir) {
 		struct strbuf temp_path = STRBUF_INIT;
 		struct tempfile *temp;
@@ -1292,8 +1294,6 @@ static int odb_transaction_files_commit(struct odb_transaction *base)
 		transaction->objdir = NULL;
 	}
 
-	flush_packfile_transaction(transaction);
-
 	if (have_packfile)
 		odb_reprepare(transaction->base.source->odb);
 
diff --git a/t/t1050-large.sh b/t/t1050-large.sh
index d295c265c7..95233458b4 100755
--- a/t/t1050-large.sh
+++ b/t/t1050-large.sh
@@ -87,6 +87,23 @@ test_expect_success 'add a large file or two' '
 	test $count = 1
 '
 
+test_expect_success 'add large file with loose object in batch fsync' '
+	test_when_finished "rm -rf batch" &&
+	git init batch &&
+	(
+		cd batch &&
+		git config core.bigFileThreshold 5 &&
+		echo foo >1-small &&
+		echo foobar >2-large &&
+
+		git -c core.fsync=loose-object -c core.fsyncMethod=batch \
+			add 1-small 2-large &&
+
+		git cat-file -e :1-small &&
+		git cat-file -e :2-large
+	)
+'
+
 test_expect_success 'checkout a large file' '
 	large1=$(git rev-parse :large1) &&
 	git update-index --add --cacheinfo 100644 $large1 another &&
-- 
2.55.0.424.g13c7afec21


  parent reply	other threads:[~2026-09-23 22:03 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-13 20:26 [PATCH 0/2] object-file: fix packfile flush during transaction commit Justin Tobler
2026-09-13 20:26 ` [PATCH 1/2] object-file: lift ODB reprepare out of packfile flush Justin Tobler
2026-09-15  4:40   ` Karthik Nayak
2026-09-15  8:54     ` Justin Tobler
2026-09-23 13:16   ` Patrick Steinhardt
2026-09-23 21:04     ` Justin Tobler
2026-09-24  5:58       ` Patrick Steinhardt
2026-09-24  6:00         ` Patrick Steinhardt
2026-09-13 20:26 ` [PATCH 2/2] object-file: flush transaction packfile before migrating objects Justin Tobler
2026-09-15  4:46   ` Karthik Nayak
2026-09-15  8:59     ` Justin Tobler
2026-09-23 13:16   ` Patrick Steinhardt
2026-09-23 21:17     ` Justin Tobler
2026-09-23 22:03 ` [PATCH v2 0/2] object-file: fix packfile flush during transaction commit Justin Tobler
2026-09-23 22:03   ` [PATCH v2 1/2] object-file: lift ODB reprepare out of packfile flush Justin Tobler
2026-09-24  6:13     ` Patrick Steinhardt
2026-09-23 22:03   ` Justin Tobler [this message]
2026-09-24  6:01   ` [PATCH v2 0/2] object-file: fix packfile flush during transaction commit Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260923220315.569424-3-jltobler@gmail.com \
    --to=jltobler@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox