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

[PATCH v2 6/6] refs: always try to do packed transactions for reftable

From
Han-Wen Nienhuys via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 20, 2023, 13:02 UTC
Message-ID
<2cf743031abbbd3de94d98dc883dfc01f327aadc.1695214969.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1574.v2.git.git.1695214968.gitgitgadget@gmail.com>
From: Han-Wen Nienhuys <hanwen@google.com>

Reftable updates are cheap (compared to packed-refs updates), so do them always. This also helps exercise this code more in tests.

This should commit should not be merged currently. It fails 55 tests when running with GIT_TEST_REFTABLE.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 refs/files-backend.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 2cd596bbeba..0d61a18b4ba 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2800,6 +2800,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
 	int head_type;
 	struct files_transaction_backend_data *backend_data;
 	struct ref_transaction *packed_transaction = NULL;
+	int is_reftable = !strcmp(refs->packed_ref_store->be->name, "reftable");
 
 	assert(err);
 
@@ -2809,6 +2810,16 @@ static int files_transaction_prepare(struct ref_store *ref_store,
 	CALLOC_ARRAY(backend_data, 1);
 	transaction->backend_data = backend_data;
 
+	if (is_reftable) {
+		packed_transaction = ref_store_transaction_begin(
+			refs->packed_ref_store, err);
+		if (!packed_transaction) {
+			ret = TRANSACTION_GENERIC_ERROR;
+			goto cleanup;
+		}
+		backend_data->packed_transaction = packed_transaction;
+	}
+
 	/*
 	 * Fail if a refname appears more than once in the
 	 * transaction. (If we end up splitting up any updates using
@@ -2881,9 +2892,9 @@ static int files_transaction_prepare(struct ref_store *ref_store,
 		if (ret)
 			goto cleanup;
 
-		if (update->flags & REF_DELETING &&
-		    !(update->flags & REF_LOG_ONLY) &&
-		    !(update->flags & REF_IS_PRUNING)) {
+		if (is_reftable || (update->flags & REF_DELETING &&
+				    !(update->flags & REF_LOG_ONLY) &&
+				    !(update->flags & REF_IS_PRUNING))) {
 			/*
 			 * This reference has to be deleted from
 			 * packed-refs if it exists there.
@@ -2909,8 +2920,9 @@ static int files_transaction_prepare(struct ref_store *ref_store,
 	}
 
 	if (packed_transaction) {
-		backend_data->packed_transaction_needed = is_packed_transaction_needed(refs->packed_ref_store,
-										       packed_transaction);
+		backend_data->packed_transaction_needed = is_reftable ||
+			is_packed_transaction_needed(refs->packed_ref_store,
+						     packed_transaction);
 		if (backend_data->packed_transaction_needed) {
 			ret = ref_transaction_prepare(packed_transaction, err);
 			/*
-- 
gitgitgadget
Previous: Han-Wen Nienhuys via GitGitGadgetNext: Han-Wen Nienhuys via GitGitGadget
Message 13 of 15 in “Simple reftable backend”
  1. 0/3 Simple reftable backendHan-Wen Nienhuys via GitGitGadget, Sep 18, 2023
  2. 1/3 refs: push lock management into packed backendHan-Wen Nienhuys via GitGitGadget, Sep 18, 2023
  3. Junio C HamanoSep 18, 2023
  4. Han-Wen NienhuysSep 19, 2023
  5. 2/3 refs: move is_packed_transaction_needed out of packed-backend.cHan-Wen Nienhuys via GitGitGadget, Sep 18, 2023
  6. 3/3 refs: alternate reftable ref backend implementationHan-Wen Nienhuys via GitGitGadget, Sep 18, 2023
  7. Junio C HamanoSep 18, 2023
  8. 0/6 RFC: simple reftable backendHan-Wen Nienhuys via GitGitGadget, Sep 20, 2023
  9. 1/6 refs: construct transaction using a _begin callbackHan-Wen Nienhuys via GitGitGadget, Sep 20, 2023
  10. 2/6 refs: wrap transaction in a debug-specific transactionHan-Wen Nienhuys via GitGitGadget, Sep 20, 2023
  11. 3/6 refs: push lock management into packed backendHan-Wen Nienhuys via GitGitGadget, Sep 20, 2023
  12. 4/6 refs: move is_packed_transaction_needed out of packed-backend.cHan-Wen Nienhuys via GitGitGadget, Sep 20, 2023
  13. 6/6 refs: always try to do packed transactions for reftableHan-Wen Nienhuys via GitGitGadget, Sep 20, 2023
  14. 5/6 refs: alternate reftable ref backend implementationHan-Wen Nienhuys via GitGitGadget, Sep 20, 2023
  15. Patrick SteinhardtSep 21, 2023

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.