git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] bulk-checkin: introduce object database transaction structure

From
Justin Tobler <jltobler@gmail.com>
Date
Aug 20, 2025, 22:55 UTC
Message-ID
<20250820225531.1212935-2-jltobler@gmail.com>
In-Reply-To
<20250820225531.1212935-1-jltobler@gmail.com>

Object database transaction state is stored across several global variables in the bulk-checkin subsystem. Consolidate this state into a single `struct odb_transaction` global. In a subsequent commit, the transactional interfaces will be updated to wire this structure instead of relying on a global variable.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
 bulk-checkin.c | 46 ++++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)
diff --git a/bulk-checkin.c b/bulk-checkin.c
index b2809ab0398..82a73da79e8 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -19,11 +19,7 @@
 #include "object-file.h"
 #include "odb.h"
 
-static int odb_transaction_nesting;
-
-static struct tmp_objdir *bulk_fsync_objdir;
-
-static struct bulk_checkin_packfile {
+struct bulk_checkin_packfile {
 	char *pack_tmp_name;
 	struct hashfile *f;
 	off_t offset;
@@ -32,7 +28,13 @@ static struct bulk_checkin_packfile {
 	struct pack_idx_entry **written;
 	uint32_t alloc_written;
 	uint32_t nr_written;
-} bulk_checkin_packfile;
+};
+
+static struct odb_transaction {
+	int nesting;
+	struct tmp_objdir *objdir;
+	struct bulk_checkin_packfile packfile;
+} transaction;
 
 static void finish_tmp_packfile(struct strbuf *basename,
 				const char *pack_tmp_name,
@@ -101,7 +103,7 @@ static void flush_batch_fsync(void)
 	struct strbuf temp_path = STRBUF_INIT;
 	struct tempfile *temp;
 
-	if (!bulk_fsync_objdir)
+	if (!transaction.objdir)
 		return;
 
 	/*
@@ -123,8 +125,8 @@ static void flush_batch_fsync(void)
 	 * Make the object files visible in the primary ODB after their data is
 	 * fully durable.
 	 */
-	tmp_objdir_migrate(bulk_fsync_objdir);
-	bulk_fsync_objdir = NULL;
+	tmp_objdir_migrate(transaction.objdir);
+	transaction.objdir = NULL;
 }
 
 static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
@@ -331,12 +333,12 @@ void prepare_loose_object_bulk_checkin(void)
 	 * callers may not know whether any objects will be
 	 * added at the time they call begin_odb_transaction.
 	 */
-	if (!odb_transaction_nesting || bulk_fsync_objdir)
+	if (!transaction.nesting || transaction.objdir)
 		return;
 
-	bulk_fsync_objdir = tmp_objdir_create(the_repository, "bulk-fsync");
-	if (bulk_fsync_objdir)
-		tmp_objdir_replace_primary_odb(bulk_fsync_objdir, 0);
+	transaction.objdir = tmp_objdir_create(the_repository, "bulk-fsync");
+	if (transaction.objdir)
+		tmp_objdir_replace_primary_odb(transaction.objdir, 0);
 }
 
 void fsync_loose_object_bulk_checkin(int fd, const char *filename)
@@ -348,7 +350,7 @@ void fsync_loose_object_bulk_checkin(int fd, const char *filename)
 	 * before renaming the objects to their final names as part of
 	 * flush_batch_fsync.
 	 */
-	if (!bulk_fsync_objdir ||
+	if (!transaction.objdir ||
 	    git_fsync(fd, FSYNC_WRITEOUT_ONLY) < 0) {
 		if (errno == ENOSYS)
 			warning(_("core.fsyncMethod = batch is unsupported on this platform"));
@@ -360,31 +362,31 @@ int index_blob_bulk_checkin(struct object_id *oid,
 			    int fd, size_t size,
 			    const char *path, unsigned flags)
 {
-	int status = deflate_blob_to_pack(&bulk_checkin_packfile, oid, fd, size,
+	int status = deflate_blob_to_pack(&transaction.packfile, oid, fd, size,
 					  path, flags);
-	if (!odb_transaction_nesting)
-		flush_bulk_checkin_packfile(&bulk_checkin_packfile);
+	if (!transaction.nesting)
+		flush_bulk_checkin_packfile(&transaction.packfile);
 	return status;
 }
 
 void begin_odb_transaction(void)
 {
-	odb_transaction_nesting += 1;
+	transaction.nesting += 1;
 }
 
 void flush_odb_transaction(void)
 {
 	flush_batch_fsync();
-	flush_bulk_checkin_packfile(&bulk_checkin_packfile);
+	flush_bulk_checkin_packfile(&transaction.packfile);
 }
 
 void end_odb_transaction(void)
 {
-	odb_transaction_nesting -= 1;
-	if (odb_transaction_nesting < 0)
+	transaction.nesting -= 1;
+	if (transaction.nesting < 0)
 		BUG("Unbalanced ODB transaction nesting");
 
-	if (odb_transaction_nesting)
+	if (transaction.nesting)
 		return;
 
 	flush_odb_transaction();
-- 
2.51.0
Previous: Justin ToblerNext: Justin Tobler
Message 2 of 27 in “bulk-checkin: remove global transaction state”
  1. 0/3 bulk-checkin: remove global transaction stateJustin Tobler, Aug 20, 2025
  2. 1/3 bulk-checkin: introduce object database transaction structureJustin Tobler, Aug 20, 2025
  3. 2/3 bulk-checkin: remove global transaction stateJustin Tobler, Aug 20, 2025
  4. 3/3 bulk-checkin: wire repository variableJustin Tobler, Aug 20, 2025
  5. Junio C HamanoAug 21, 2025
  6. Justin ToblerAug 21, 2025
  7. Junio C HamanoAug 21, 2025
  8. Junio C HamanoAug 21, 2025
  9. 0/4 bulk-checkin: remove global transaction stateJustin Tobler, Aug 21, 2025
  10. 1/4 bulk-checkin: introduce object database transaction structureJustin Tobler, Aug 21, 2025
  11. 3/4 bulk-checkin: require transaction for index_blob_bulk_checkin()Justin Tobler, Aug 21, 2025
  12. Junio C HamanoAug 22, 2025
  13. Justin ToblerAug 22, 2025
  14. Junio C HamanoAug 22, 2025
  15. 2/4 bulk-checkin: remove global transaction stateJustin Tobler, Aug 21, 2025
  16. Junio C HamanoAug 22, 2025
  17. Justin ToblerAug 22, 2025
  18. Junio C HamanoAug 22, 2025
  19. 4/4 bulk-checkin: use repository variable from transactionJustin Tobler, Aug 21, 2025
  20. Junio C HamanoAug 22, 2025
  21. Justin ToblerAug 22, 2025
  22. 0/4 bulk-checkin: remove global transaction stateJustin Tobler, Aug 22, 2025
  23. 1/4 bulk-checkin: introduce object database transaction structureJustin Tobler, Aug 22, 2025
  24. 2/4 bulk-checkin: remove global transaction stateJustin Tobler, Aug 22, 2025
  25. 3/4 bulk-checkin: require transaction for index_blob_bulk_checkin()Justin Tobler, Aug 22, 2025
  26. 4/4 bulk-checkin: use repository variable from transactionJustin Tobler, Aug 22, 2025
  27. Junio C HamanoAug 25, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.