odb: support ODB source specific transaction handling
cover odb: support ODB source specific transaction handling
Greetings,
ODB transactions provide a mechanism for writing new objects in the repository that are in a pending state until they are committed. With pluggable ODBs, each source will likely need to handle transactions differently. This patch series prepares ODB transaction handling to be defined for each ODB source by creating a generic odb_transaction structure that stores a callback for committing the transaction.
For now, struct odb_transaction_loose is the only transaction implementation and what is always returned when creating a transaction. Additionally, this series lifts transaction logic that is common to all backends out of the implementation layer into odb_transaction_{begin,commit}() layer.
Thanks,
-Justin
Justin Tobler (4):
odb: store ODB source in struct odb_transaction
object-file: rename transaction functions
odb: prepare struct odb_transaction to support more sources
odb: transparently handle common transaction behavior
object-file.c | 77 +++++++++++++++++++++++++-------------------------- object-file.h | 10 ++----- odb.c | 22 +++++++++++++-- odb.h | 17 ++++++++++++ 4 files changed, 77 insertions(+), 49 deletions(-)
base-commit: ea717645d199f6f1b66058886475db3e8c9330e9
Signature · 1 line
2.52.0.373.g68cb7f9e92
PATCH 1/4 odb: store ODB source in `struct odb_transaction`
Each struct odb_transaction currently stores a reference to the struct object_database. Since transactions are handled per object source, instead store a reference to the source.
--- object-file.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
object-file.c +11 -11
@@ -711,7 +711,7 @@ struct transaction_packfile { };struct odb_transaction { -struct object_database *odb; +struct odb_source *source;struct tmp_objdir *objdir;struct transaction_packfile packfile;
@@ -728,7 +728,7 @@ static void prepare_loose_object_transaction(struct odb_transaction *transactionif (!transaction || transaction->objdir)return ; - transaction->objdir =tmp_objdir_create (transaction->odb->repo,"bulk-fsync" ); + transaction->objdir =tmp_objdir_create (transaction->source->odb->repo,"bulk-fsync" );if (transaction->objdir)tmp_objdir_replace_primary_odb (transaction->objdir,0 ); }
@@ -772,7 +772,7 @@ static void flush_loose_object_transaction(struct odb_transaction *transaction)* the final name is visible. */ strbuf_addf (&temp_path,"%s/bulk_fsync_XXXXXX" , -repo_get_object_directory (transaction->odb->repo)); +repo_get_object_directory (transaction->source->odb->repo)); temp =xmks_tempfile (temp_path.buf);fsync_or_die (get_tempfile_fd (temp),get_tempfile_path (temp));delete_tempfile (&temp);
@@ -1344,7 +1344,7 @@ static int already_written(struct odb_transaction *transaction, struct object_id *oid) {/* The object may already exist in the repository */ -if (odb_has_object (transaction->odb, oid, +if (odb_has_object (transaction->source->odb, oid,HAS_OBJECT_RECHECK_PACKED |HAS_OBJECT_FETCH_PROMISOR ))return 1 ;
@@ -1365,7 +1365,7 @@ static void prepare_packfile_transaction(struct odb_transaction *transaction,if (!(flags &INDEX_WRITE_OBJECT ) || state->f)return ; - state->f =create_tmp_packfile (transaction->odb->repo, + state->f =create_tmp_packfile (transaction->source->odb->repo, &state->pack_tmp_name);reset_pack_idx_option (&state->pack_idx_opts);
@@ -1469,7 +1469,7 @@ static int stream_blob_to_pack(struct transaction_packfile *state,static void flush_packfile_transaction (struct odb_transaction *transaction) {struct transaction_packfile *state = &transaction->packfile; -struct repository *repo = transaction->odb->repo; +struct repository *repo = transaction->source->odb->repo;unsigned char hash[GIT_MAX_RAWSZ ];struct strbuf packname =STRBUF_INIT ;char *idx_tmp_name =NULL ;
@@ -1494,7 +1494,7 @@ static void flush_packfile_transaction(struct odb_transaction *transaction) }strbuf_addf (&packname,"%s/pack/pack-%s." , -repo_get_object_directory (transaction->odb->repo), +repo_get_object_directory (transaction->source->odb->repo),hash_to_hex_algop (hash, repo->hash_algo)); stage_tmp_packfiles(repo, &packname, state->pack_tmp_name,
@@ -1553,7 +1553,7 @@ static int index_blob_packfile_transaction(struct odb_transaction *transaction, header_len =format_object_header ((char *)obuf,sizeof (obuf),OBJ_BLOB , size); - transaction->odb->repo->hash_algo->init_fn (&ctx); + transaction->source->odb->repo->hash_algo->init_fn (&ctx);git_hash_update (&ctx, obuf, header_len);/* Note: idx is non-NULL when we are writing */
@@ -1993,7 +1993,7 @@ struct odb_transaction *object_file_transaction_begin(struct odb_source *source)return NULL ;CALLOC_ARRAY (odb->transaction,1 ); - odb->transaction->odb = odb; + odb->transaction->source = source;return odb->transaction; }
@@ -2006,11 +2006,11 @@ void object_file_transaction_commit(struct odb_transaction *transaction)/* * Ensure the transaction ending matches the pending transaction. */ -ASSERT (transaction == transaction->odb->transaction); +ASSERT (transaction == transaction->source->odb->transaction);flush_loose_object_transaction (transaction);flush_packfile_transaction (transaction); - transaction->odb->transaction =NULL ; + transaction->source->odb->transaction =NULL ;free (transaction); }
Signature · 1 line
2.52.0.373.g68cb7f9e92
Re: [PATCH 1/4] odb: store ODB source in `struct odb_transaction`
Quoted 3 lines · Justin Tobler
Each
struct odb_transactioncurrently stores a reference to thestruct object_database. Since transactions are handled per object source, instead store a reference to the source.
Makes sense.
object-file.c static void prepare_loose_object_transaction(struct odb_transaction *transaction · line 734
Quoted 13 lines
object-file.c +1
-1@@ -728,7 +728,7 @@ static void prepare_loose_object_transaction(struct odb_transaction *transactionif (!transaction || transaction->objdir)return ; - transaction->objdir =tmp_objdir_create (transaction->odb->repo,"bulk-fsync" ); + transaction->objdir =tmp_objdir_create (transaction->source->odb->repo,"bulk-fsync" );if (transaction->objdir)tmp_objdir_replace_primary_odb (transaction->objdir,0 ); }
This makes me wonder whether we should first refactor the tmp_objdir subsystem to receive a source instead of a repository as input. Otherwise we "pretend" that the transaction is on the source level, but we ultimately still end up creating the temporary directory in the repository's object directory unconditionally.
It wouldn't really change anything right now as we only ever write objects via the primary object source anyway, so the end result would be the same. But it just feels like a good first step to me to fix this conceptual inconsistency, and it shouldn't be too involved either as tmp_objdir_create() only has three callsites.
Patrick
Re: [PATCH 1/4] odb: store ODB source in `struct odb_transaction`
Quoted 27 lines · Patrick Steinhardt
Quoted 3 lines · Justin Tobler
Each
struct odb_transactioncurrently stores a reference to thestruct object_database. Since transactions are handled per object source, instead store a reference to the source.Makes sense.
object-file.c static void prepare_loose_object_transaction(struct odb_transaction *transaction · line 734
Quoted 13 lines
object-file.c +1
-1@@ -728,7 +728,7 @@ static void prepare_loose_object_transaction(struct odb_transaction *transactionif (!transaction || transaction->objdir)return ; - transaction->objdir =tmp_objdir_create (transaction->odb->repo,"bulk-fsync" ); + transaction->objdir =tmp_objdir_create (transaction->source->odb->repo,"bulk-fsync" );if (transaction->objdir)tmp_objdir_replace_primary_odb (transaction->objdir,0 ); }This makes me wonder whether we should first refactor the
tmp_objdirsubsystem to receive a source instead of a repository as input. Otherwise we "pretend" that the transaction is on the source level, but we ultimately still end up creating the temporary directory in the repository's object directory unconditionally.
Quoted 5 lines
It wouldn't really change anything right now as we only ever write objects via the primary object source anyway, so the end result would be the same. But it just feels like a good first step to me to fix this conceptual inconsistency, and it shouldn't be too involved either as
tmp_objdir_create()only has three callsites.
I agree with your "not really change anything right now" comment, but a new odb source that will be invented in the future may not even be file based, and a generic-sounding tmp_objdir_create() that creates a temporary directory on the filesystem may not even be an appropriate abstraction.
If we have two or more odb sources both are filesystem based, on the other hand, I do not think it is particulary bad if these two odb sources belonging to the same repository took a temporary directory out of that repository. As long as one temporary object directory taken by one odb source is not used to commit the transaction into the other odb source, it would be fine, no?
Thanks.
Re: [PATCH 1/4] odb: store ODB source in `struct odb_transaction`
Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Patrick Steinhardt
This makes me wonder whether we should first refactor the
tmp_objdirsubsystem to receive a source instead of a repository as input. Otherwise we "pretend" that the transaction is on the source level, but we ultimately still end up creating the temporary directory in the repository's object directory unconditionally.It wouldn't really change anything right now as we only ever write objects via the primary object source anyway, so the end result would be the same. But it just feels like a good first step to me to fix this conceptual inconsistency, and it shouldn't be too involved either as
tmp_objdir_create()only has three callsites.
Quoted 5 lines
I agree with your "not really change anything right now" comment, but a new odb source that will be invented in the future may not even be file based, and a generic-sounding
tmp_objdir_create()that creates a temporary directory on the filesystem may not even be an appropriate abstraction.
Yup, the tmp-objdir system is really only useful in the context of file based ODB sources. I figure future ODB sources will have to have a different mechanism to temporarly store objects.
Interestingly, it looks like there are only three users of odb-tmpdir:
remerge-diffs, git-recieve-pack, and ODB transactions. All of these use-cases seems like a reasonble fit to create an ODB transaction instead of managing the tmpdir directly. In the case of remerge-diffs the transaction would need to always be aborted. If this is done, then a tmpdir could become an internal detail of the ODB transaction for the files backend.
Quoted 6 lines
If we have two or more odb sources both are filesystem based, on the other hand, I do not think it is particulary bad if these two odb sources belonging to the same repository took a temporary directory out of that repository. As long as one temporary object directory taken by one odb source is not used to commit the transaction into the other odb source, it would be fine, no?
I believe that we only support having a single tmpdir per Git process via the_tmp_objdir global anyway. So maybe on second thought configuring per source doesn't make much sense especially if only the "files" ODB source would make use of it. If we do go down the route of merging the tmpdir with the "files" ODB transaction implementation, we could probably just pass the concrete "files" ODB source to it instead.
-Justin
Re: [PATCH 1/4] odb: store ODB source in `struct odb_transaction`
Quoted 7 lines · Justin Tobler
Interestingly, it looks like there are only three users of odb-tmpdir:
remerge-diffs, git-recieve-pack, and ODB transactions. All of these use-cases seems like a reasonble fit to create an ODB transaction instead of managing the tmpdir directly. In the case of remerge-diffs the transaction would need to always be aborted. If this is done, then a tmpdir could become an internal detail of the ODB transaction for the files backend.
;-) I agree 100%.
"Prepare to create objects that may be undone in the end", "Now make these objects we created so far as parmanent part of the object store", "Reject those objects we created so far as the transaction created them is being aborted" are requests at the right abstraction level. "Give me a temporary object directory" is not.
Re: [PATCH 1/4] odb: store ODB source in `struct odb_transaction`
Quoted 10 lines · Junio C Hamano
Quoted 7 lines · Justin Tobler
Interestingly, it looks like there are only three users of odb-tmpdir:
remerge-diffs, git-recieve-pack, and ODB transactions. All of these use-cases seems like a reasonble fit to create an ODB transaction instead of managing the tmpdir directly. In the case of remerge-diffs the transaction would need to always be aborted. If this is done, then a tmpdir could become an internal detail of the ODB transaction for the files backend.
Quoted 7 lines
;-) I agree 100%.
"Prepare to create objects that may be undone in the end", "Now make these objects we created so far as parmanent part of the object store", "Reject those objects we created so far as the transaction created them is being aborted" are requests at the right abstraction level. "Give me a temporary object directory" is not.
Ok, I'll go ahead and leave the tmp-objdir stuff alone in this patch series and look into extending the ODB transaction usage to replace existing tmpdir callsites in a followup series.
Thanks,
-Justin
Re: [PATCH 1/4] odb: store ODB source in `struct odb_transaction`
In reply to Patrick SteinhardtQuoted 21 lines · Patrick Steinhardt
object-file.c static void prepare_loose_object_transaction(struct odb_transaction *transaction · line 734
Quoted 13 lines · Justin Tobler
object-file.c +1
-1@@ -728,7 +728,7 @@ static void prepare_loose_object_transaction(struct odb_transaction *transactionif (!transaction || transaction->objdir)return ; - transaction->objdir =tmp_objdir_create (transaction->odb->repo,"bulk-fsync" ); + transaction->objdir =tmp_objdir_create (transaction->source->odb->repo,"bulk-fsync" );if (transaction->objdir)tmp_objdir_replace_primary_odb (transaction->objdir,0 ); }This makes me wonder whether we should first refactor the
tmp_objdirsubsystem to receive a source instead of a repository as input. Otherwise we "pretend" that the transaction is on the source level, but we ultimately still end up creating the temporary directory in the repository's object directory unconditionally.
Quoted 5 lines
It wouldn't really change anything right now as we only ever write objects via the primary object source anyway, so the end result would be the same. But it just feels like a good first step to me to fix this conceptual inconsistency, and it shouldn't be too involved either as
tmp_objdir_create()only has three callsites.
Ya this seems reasonable and I agree that it makes sense to do as a first step. In the next version I'll make this change in a prepatory commit.
-Justin
PATCH 2/4 object-file: rename transaction functions
In reply to Justin ToblerIn a subsequent commit, ODB transactions are made more generic to facilitate each ODB source providing its own transaction handling. Rename object_file_transaction_{begin,commit}() to odb_transaction_loose_{begin,commit}() to better match the future source specific transaction implementation.
--- object-file.c | 6 +++--- object-file.h | 6 +++--- odb.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-)
object-file.c +3 -3
@@ -723,7 +723,7 @@ static void prepare_loose_object_transaction(struct odb_transaction *transaction* We lazily create the temporary object directory * the first time an object might be added, since * callers may not know whether any objects will be -* added at the time they call object_file_transaction_begin. +* added at the time they call odb_transaction_loose_begin. */ if (!transaction || transaction->objdir)return ;
@@ -1985,7 +1985,7 @@ int read_loose_object(struct repository *repo,return ret; } -struct odb_transaction *object_file_transaction_begin (struct odb_source *source) +struct odb_transaction *odb_transaction_loose_begin (struct odb_source *source) {struct object_database *odb = source->odb;
@@ -1998,7 +1998,7 @@ struct odb_transaction *object_file_transaction_begin(struct odb_source *source)return odb->transaction; } -void object_file_transaction_commit (struct odb_transaction *transaction) +void odb_transaction_loose_commit (struct odb_transaction *transaction) {if (!transaction)return ;
object-file.h +3 -3
@@ -202,16 +202,16 @@ struct odb_transaction;/* * Tell the object database to optimize for adding -* multiple objects. object_file_transaction_commit must be called +* multiple objects. odb_transaction_loose_commit must be called * to make new objects visible. If a transaction is already * pending, NULL is returned. */ -struct odb_transaction *object_file_transaction_begin (struct odb_source *source); +struct odb_transaction *odb_transaction_loose_begin (struct odb_source *source);/* * Tell the object database to make any objects from the * current transaction visible. */ -void object_file_transaction_commit (struct odb_transaction *transaction); +void odb_transaction_loose_commit (struct odb_transaction *transaction);#endif /* OBJECT_FILE_H */
odb.c +2 -2
@@ -1153,10 +1153,10 @@ void odb_reprepare(struct object_database *o)struct odb_transaction *odb_transaction_begin (struct object_database *odb) { -return object_file_transaction_begin (odb->sources); +return odb_transaction_loose_begin (odb->sources); }void odb_transaction_commit (struct odb_transaction *transaction) { -object_file_transaction_commit (transaction); +odb_transaction_loose_commit (transaction); }
Signature · 1 line
2.52.0.373.g68cb7f9e92
PATCH 3/4 odb: prepare `struct odb_transaction` to support more sources
In reply to Justin ToblerEach ODB transaction should be specific to the ODB source it pertains to. Update struct odb_transaction to store a commit callback specific to its object source type. For now struct odb_transaction_loose is the only transaction type and what is always returned when starting a transaction.
--- object-file.c | 80 ++++++++++++++++++++++++++++----------------------- object-file.h | 6 ---- odb.c | 5 +++- odb.h | 17 +++++++++++ 4 files changed, 65 insertions(+), 43 deletions(-)
object-file.c +44 -36
@@ -710,15 +710,17 @@ struct transaction_packfile {uint32_t nr_written; }; -struct odb_transaction { -struct odb_source *source; +struct odb_transaction_loose { +struct odb_transaction base;struct tmp_objdir *objdir;struct transaction_packfile packfile; }; -static void prepare_loose_object_transaction (struct odb_transaction *transaction) +static void prepare_loose_object_transaction (struct odb_transaction *base) { +struct odb_transaction_loose *transaction = (struct odb_transaction_loose *)base; +/* * We lazily create the temporary object directory * the first time an object might be added, since
@@ -728,14 +730,16 @@ static void prepare_loose_object_transaction(struct odb_transaction *transactionif (!transaction || transaction->objdir)return ; - transaction->objdir =tmp_objdir_create (transaction->source->odb->repo,"bulk-fsync" ); + transaction->objdir =tmp_objdir_create (base->source->odb->repo,"bulk-fsync" );if (transaction->objdir)tmp_objdir_replace_primary_odb (transaction->objdir,0 ); } -static void fsync_loose_object_transaction (struct odb_transaction *transaction, +static void fsync_loose_object_transaction (struct odb_transaction *base,int fd,const char *filename) { +struct odb_transaction_loose *transaction = (struct odb_transaction_loose *)base; +/* * If we have an active ODB transaction, we issue a call that * cleans the filesystem page cache but avoids a hardware flush
@@ -754,7 +758,7 @@ static void fsync_loose_object_transaction(struct odb_transaction *transaction,/* * Cleanup after batch-mode fsync_object_files. */ -static void flush_loose_object_transaction (struct odb_transaction *transaction) +static void flush_loose_object_transaction (struct odb_transaction_loose *transaction) {struct strbuf temp_path =STRBUF_INIT ;struct tempfile *temp;
@@ -772,7 +776,7 @@ static void flush_loose_object_transaction(struct odb_transaction *transaction)* the final name is visible. */ strbuf_addf (&temp_path,"%s/bulk_fsync_XXXXXX" , -repo_get_object_directory (transaction->source->odb->repo)); +repo_get_object_directory (transaction->base.source->odb->repo)); temp =xmks_tempfile (temp_path.buf);fsync_or_die (get_tempfile_fd (temp),get_tempfile_path (temp));delete_tempfile (&temp);
@@ -1340,11 +1344,11 @@ static int index_core(struct index_state *istate,return ret; } -static int already_written (struct odb_transaction *transaction, +static int already_written (struct odb_transaction_loose *transaction,struct object_id *oid) {/* The object may already exist in the repository */ -if (odb_has_object (transaction->source->odb, oid, +if (odb_has_object (transaction->base.source->odb, oid,HAS_OBJECT_RECHECK_PACKED |HAS_OBJECT_FETCH_PROMISOR ))return 1 ;
@@ -1358,14 +1362,14 @@ static int already_written(struct odb_transaction *transaction, }/* Lazily create backing packfile for the state */ -static void prepare_packfile_transaction (struct odb_transaction *transaction, +static void prepare_packfile_transaction (struct odb_transaction_loose *transaction,unsigned flags) {struct transaction_packfile *state = &transaction->packfile;if (!(flags &INDEX_WRITE_OBJECT ) || state->f)return ; - state->f =create_tmp_packfile (transaction->source->odb->repo, + state->f =create_tmp_packfile (transaction->base.source->odb->repo, &state->pack_tmp_name);reset_pack_idx_option (&state->pack_idx_opts);
@@ -1466,10 +1470,10 @@ static int stream_blob_to_pack(struct transaction_packfile *state,return 0 ; } -static void flush_packfile_transaction (struct odb_transaction *transaction) +static void flush_packfile_transaction (struct odb_transaction_loose *transaction) {struct transaction_packfile *state = &transaction->packfile; -struct repository *repo = transaction->source->odb->repo; +struct repository *repo = transaction->base.source->odb->repo;unsigned char hash[GIT_MAX_RAWSZ ];struct strbuf packname =STRBUF_INIT ;char *idx_tmp_name =NULL ;
@@ -1494,7 +1498,7 @@ static void flush_packfile_transaction(struct odb_transaction *transaction) }strbuf_addf (&packname,"%s/pack/pack-%s." , -repo_get_object_directory (transaction->source->odb->repo), +repo_get_object_directory (transaction->base.source->odb->repo),hash_to_hex_algop (hash, repo->hash_algo)); stage_tmp_packfiles(repo, &packname, state->pack_tmp_name,
@@ -1534,7 +1538,7 @@ static void flush_packfile_transaction(struct odb_transaction *transaction)* binary blobs, they generally do not want to get any conversion, and * callers should avoid this code path when filters are requested. */ -static int index_blob_packfile_transaction (struct odb_transaction *transaction, +static int index_blob_packfile_transaction (struct odb_transaction_loose *transaction,struct object_id *result_oid,int fd,size_t size,const char *path,unsigned flags)
@@ -1553,7 +1557,7 @@ static int index_blob_packfile_transaction(struct odb_transaction *transaction, header_len =format_object_header ((char *)obuf,sizeof (obuf),OBJ_BLOB , size); - transaction->source->odb->repo->hash_algo->init_fn (&ctx); + transaction->base.source->odb->repo->hash_algo->init_fn (&ctx);git_hash_update (&ctx, obuf, header_len);/* Note: idx is non-NULL when we are writing */
@@ -1629,10 +1633,11 @@ int index_fd(struct index_state *istate, struct object_id *oid, ret =index_core (istate, oid, fd,xsize_t (st->st_size), type, path, flags); }else { +struct object_database *odb = the_repository->objects;struct odb_transaction *transaction; - transaction =odb_transaction_begin (the_repository->objects); - ret =index_blob_packfile_transaction (the_repository->objects->transaction, + transaction =odb_transaction_begin (odb); + ret =index_blob_packfile_transaction ((struct odb_transaction_loose *)odb->transaction, oid, fd,xsize_t (st->st_size), path, flags);
@@ -1985,35 +1990,38 @@ int read_loose_object(struct repository *repo,return ret; } -struct odb_transaction *odb_transaction_loose_begin (struct odb_source *source) +static void odb_transaction_loose_commit (struct odb_transaction *base) { -struct object_database *odb = source->odb; - -if (odb->transaction) -return NULL ; - -CALLOC_ARRAY (odb->transaction,1 ); - odb->transaction->source = source; - -return odb->transaction; -} - -void odb_transaction_loose_commit (struct odb_transaction *transaction) -{ -if (!transaction) -return ; +struct odb_transaction_loose *transaction = (struct odb_transaction_loose *)base;/* * Ensure the transaction ending matches the pending transaction. */ -ASSERT (transaction == transaction->source->odb->transaction); +ASSERT (base == base->source->odb->transaction);flush_loose_object_transaction (transaction);flush_packfile_transaction (transaction); - transaction->source->odb->transaction =NULL ; + base->source->odb->transaction =NULL ;free (transaction); } +struct odb_transaction *odb_transaction_loose_begin (struct odb_source *source) +{ +struct odb_transaction_loose *transaction; +struct object_database *odb = source->odb; + +if (odb->transaction) +return NULL ; + + transaction =xcalloc (1 ,sizeof (*transaction)); + transaction->base.source = source; + transaction->base.commit = odb_transaction_loose_commit; + + odb->transaction = &transaction->base; + +return &transaction->base; +} +struct odb_source_loose *odb_source_loose_new (struct odb_source *source) {struct odb_source_loose *loose;
object-file.h +0 -6
@@ -208,10 +208,4 @@ struct odb_transaction;*/ struct odb_transaction *odb_transaction_loose_begin (struct odb_source *source); -/* -* Tell the object database to make any objects from the -* current transaction visible. -*/ -void odb_transaction_loose_commit (struct odb_transaction *transaction); -#endif /* OBJECT_FILE_H */
odb.c +4 -1
@@ -1158,5 +1158,8 @@ struct odb_transaction *odb_transaction_begin(struct object_database *odb)void odb_transaction_commit (struct odb_transaction *transaction) { -odb_transaction_loose_commit (transaction); +if (!transaction) +return ; + + transaction->commit (transaction); }
odb.h +17 -0
@@ -77,7 +77,24 @@ struct odb_source {struct packed_git ;struct packfile_store ;struct cached_object_entry ; + +/* +* A transaction may be started for an object database prior to writing new +* objects via odb_transaction_begin(). These objects are not committed until +* odb_transaction_commit() is invoked. Only a single transaction may be pending +* at a time. +* +* Each ODB source is expected to implement its own transaction handling. +*/ struct odb_transaction ; +typedef void (*odb_transaction_commit_fn )(struct odb_transaction *transaction); +struct odb_transaction { +/* The ODB source the transaction is opened against. */ +struct odb_source *source; + +/* The ODB source specific callback invoked to commit a transaction. */ +odb_transaction_commit_fn commit; +};/* * The object database encapsulates access to objects in a repository. It
Signature · 1 line
2.52.0.373.g68cb7f9e92
Re: [PATCH 3/4] odb: prepare `struct odb_transaction` to support more sources
On Wed, Jan 28, 2026 at 05:45:18PM -0600, Justin Tobler wrote:
The bit about supporting "more sources" in the subject reads a bit weird to me. We still only handle a single source in a transaction, not multiple ones. I guess what you rather want to say is that we handle "generic" sources? How about:
odb: prepare struct odb_source to become generic
Quoted 2 lines
Each ODB transaction should be specific to the ODB source it pertains to.
This is a claim that should probably be backed up a bit. I myself obviously agree with it, but I think it should be noted _why_ we want to have this in the first place.
The patch itself looks as expected to me, as we split up struct odb_transaction into two structures:
- struct odb_transaction continues to exist, but is now the generic part that simply contains the source and a function pointer.
- struct odb_transaction_loose is the backend-specific implementation.
One question though: is this tansaction really specific to loose objects? We also seem to be handling packfiles there in prepare_packfile_transaction(), so it rather feels like this is specific to the whole "files" backend. I might be misunderstanding though.
object-file.h struct odb_transaction; · line 209
Quoted 5 lines
object-file.h +0
-0@@ -208,10 +208,4 @@ struct odb_transaction;*/ struct odb_transaction *odb_transaction_loose_begin (struct odb_source *source);
Right, we still need this function to be public right now. But eventually it'll be converted into a function pointer part of the struct odb_source.
object-file.h struct odb_transaction; · line 215
Quoted 5 lines
object-file.h +0
-5-/* -* Tell the object database to make any objects from the -* current transaction visible. -*/ -void odb_transaction_loose_commit (struct odb_transaction *transaction);
But this doesn't have to be public anymore as we have it available to us via tranasction->commit(). Makes sense.
Patrick
Re: [PATCH 3/4] odb: prepare `struct odb_transaction` to support more sources
Quoted 8 lines · Patrick Steinhardt
On Wed, Jan 28, 2026 at 05:45:18PM -0600, Justin Tobler wrote:
The bit about supporting "more sources" in the subject reads a bit weird to me. We still only handle a single source in a transaction, not multiple ones. I guess what you rather want to say is that we handle "generic" sources? How about:
odb: prepare
struct odb_sourceto become generic
The intent was that with generic transactions we it becomes possible to support additional ODB sources each with their own transaction implementation, but I agree the current wording is not great. I'll update in the next version.
Quoted 6 lines
Quoted 2 lines
Each ODB transaction should be specific to the ODB source it pertains to.
This is a claim that should probably be backed up a bit. I myself obviously agree with it, but I think it should be noted _why_ we want to have this in the first place.
Ya that's fair. I'll update the commit message in the next version to properly explain the intent here.
Quoted 6 lines
The patch itself looks as expected to me, as we split up
struct odb_transactioninto two structures:-
struct odb_transactioncontinues to exist, but is now the generic part that simply contains the source and a function pointer.
Quoted 8 lines
-
struct odb_transaction_looseis the backend-specific implementation.One question though: is this tansaction really specific to loose objects? We also seem to be handling packfiles there in
prepare_packfile_transaction(), so it rather feels like this is specific to the whole "files" backend. I might be misunderstanding though.
The current transaction backend is primarily used to facilitate bulk writing of what would otherwise be loose objects into a packfile. I would like to eventually expand the use of ODB transactions though to cover areas like git-recieve-pack(1) which currently uses tmp-objdir directly. So it probably makes sense to call this odb_transaction_files. Will update in the next version.
-Justin
PATCH 4/4 odb: transparently handle common transaction behavior
In reply to Justin ToblerA new ODB transaction is created and returned via odb_transaction_begin() and stored in the ODB. Only a single transaction may be pending at a time. If the ODB already has a transaction, the function is expected to return NULL. Similarly, when committing a transaction via odb_transaction_commit() the transaction being committed must match the pending transaction and upon commit reset the ODB transaction to NULL.
These behaviors apply regardless of the ODB transaction implementation. Move the corresponding logic into odb_transaction_{begin,commit}() accordingly.
--- object-file.c | 9 --------- odb.c | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 10 deletions(-)
object-file.c +0 -9
@@ -1994,15 +1994,8 @@ static void odb_transaction_loose_commit(struct odb_transaction *base) {struct odb_transaction_loose *transaction = (struct odb_transaction_loose *)base; -/* -* Ensure the transaction ending matches the pending transaction. -*/ -ASSERT (base == base->source->odb->transaction); -flush_loose_object_transaction (transaction);flush_packfile_transaction (transaction); - base->source->odb->transaction =NULL ; -free (transaction); }struct odb_transaction *odb_transaction_loose_begin (struct odb_source *source)
@@ -2017,8 +2010,6 @@ struct odb_transaction *odb_transaction_loose_begin(struct odb_source *source) transaction->base.source = source; transaction->base.commit = odb_transaction_loose_commit; - odb->transaction = &transaction->base; -return &transaction->base; }
odb.c +16 -1
@@ -1153,7 +1153,15 @@ void odb_reprepare(struct object_database *o)struct odb_transaction *odb_transaction_begin (struct object_database *odb) { -return odb_transaction_loose_begin (odb->sources); +struct odb_transaction *transaction; + +if (odb->transaction) +return NULL ; + + transaction =odb_transaction_loose_begin (odb->sources); + odb->transaction = transaction; + +return transaction; }void odb_transaction_commit (struct odb_transaction *transaction)
@@ -1161,5 +1169,12 @@ void odb_transaction_commit(struct odb_transaction *transaction)if (!transaction)return ; +/* +* Ensure the transaction ending matches the pending transaction. +*/ +ASSERT (transaction == transaction->source->odb->transaction); + transaction->commit (transaction); + transaction->source->odb->transaction =NULL ; +free (transaction); }
Signature · 1 line
2.52.0.373.g68cb7f9e92
Re: [PATCH 4/4] odb: transparently handle common transaction behavior
Quoted 11 lines · Justin Tobler
A new ODB transaction is created and returned via
odb_transaction_begin()and stored in the ODB. Only a single transaction may be pending at a time. If the ODB already has a transaction, the function is expected to return NULL. Similarly, when committing a transaction viaodb_transaction_commit()the transaction being committed must match the pending transaction and upon commit reset the ODB transaction to NULL.These behaviors apply regardless of the ODB transaction implementation. Move the corresponding logic into
odb_transaction_{begin,commit}()accordingly.
Besides deduplicating the logic, it also makes the ODB source only care about itself, whereas the ODB is responsible for managing the transaction's lifecycle. Which I think is a good thing.
Quoted 11 lines
odb.c +2
-1@@ -1153,7 +1153,15 @@ void odb_reprepare(struct object_database *o)struct odb_transaction *odb_transaction_begin (struct object_database *odb) { -return odb_transaction_loose_begin (odb->sources); +struct odb_transaction *transaction; +
odb.c void odb_reprepare(struct object_database *o) · line 1167
Quoted 10 lines
odb.c +7
-0+if (odb->transaction) +return NULL ; + + transaction =odb_transaction_loose_begin (odb->sources); + odb->transaction = transaction; + +return transaction; }void odb_transaction_commit (struct odb_transaction *transaction)
Nit: the transaction variable seems somewhat pointless to me.
Patrick
v2 cover odb: support ODB source specific transaction handling
In reply to Justin ToblerGreetings,
ODB transactions provide a mechanism for writing new objects in the repository that are in a pending state until they are committed. With pluggable ODBs, each source will likely need to handle transactions differently. This patch series prepares ODB transaction handling to be defined for each ODB source by creating a generic odb_transaction structure that stores a callback for committing the transaction.
For now, struct odb_transaction_files is the only transaction implementation and what is always returned when creating a transaction. Additionally, this series lifts transaction logic that is common to all backends out of the implementation layer into odb_transaction_{begin,commit}() layer.
Changes since V1:
- Renamed the files transaction type to be odb_transaction_files. Associated functions were also renamed accordingly.
- Updated commit messages.
- The tmp_objdir subsystem has been left unchange in the version. In a followup series, I plan to couple tmpdirs directly to ODB files transactions.
Thanks,
-Justin
Justin Tobler (4):
odb: store ODB source in struct odb_transaction
object-file: rename transaction functions
odb: prepare struct odb_transaction to become generic
odb: transparently handle common transaction behavior
object-file.c | 77 +++++++++++++++++++++++++-------------------------- object-file.h | 10 ++----- odb.c | 19 +++++++++++-- odb.h | 17 ++++++++++++ 4 files changed, 74 insertions(+), 49 deletions(-)
Range-diff against v1:
1: 525c96f5f2 = 1: 525c96f5f2 odb: store ODB source in `struct odb_transaction` 2: 5ee1085453 ! 2: 02528f49fb object-file: rename transaction functions
@@ Commit message
In a subsequent commit, ODB transactions are made more generic to facilitate each ODB source providing its own transaction handling. Rename object_file_transaction_{begin,commit}() to
- odb_transaction_loose_{begin,commit}() to better match the future
+ odb_transaction_files_{begin,commit}() to better match the future
source specific transaction implementation.
@@ object-file.c: static void prepare_loose_object_transaction(struct odb_transacti
* the first time an object might be added, since
* callers may not know whether any objects will be
- * added at the time they call object_file_transaction_begin.
-+ * added at the time they call odb_transaction_loose_begin.
++ * added at the time they call odb_transaction_files_begin.
*/
if (!transaction || transaction->objdir)
return;
@@ object-file.c: int read_loose_object(struct repository *repo,
}
-struct odb_transaction *object_file_transaction_begin(struct odb_source *source)
-+struct odb_transaction *odb_transaction_loose_begin(struct odb_source *source) ++struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
{
struct object_database *odb = source->odb;
@@ object-file.c: struct odb_transaction *object_file_transaction_begin(struct odb_
}
-void object_file_transaction_commit(struct odb_transaction *transaction)
-+void odb_transaction_loose_commit(struct odb_transaction *transaction) ++void odb_transaction_files_commit(struct odb_transaction *transaction)
{
if (!transaction)
return;
@@ object-file.h: struct odb_transaction;
/*
* Tell the object database to optimize for adding
- * multiple objects. object_file_transaction_commit must be called
-+ * multiple objects. odb_transaction_loose_commit must be called
++ * multiple objects. odb_transaction_files_commit must be called
* to make new objects visible. If a transaction is already
* pending, NULL is returned.
*/
-struct odb_transaction *object_file_transaction_begin(struct odb_source *source);
-+struct odb_transaction *odb_transaction_loose_begin(struct odb_source *source); ++struct odb_transaction *odb_transaction_files_begin(struct odb_source *source);
/*
* Tell the object database to make any objects from the
* current transaction visible.
*/
-void object_file_transaction_commit(struct odb_transaction *transaction);
-+void odb_transaction_loose_commit(struct odb_transaction *transaction); ++void odb_transaction_files_commit(struct odb_transaction *transaction);
#endif /* OBJECT_FILE_H */
@@ odb.c: void odb_reprepare(struct object_database *o)
struct odb_transaction *odb_transaction_begin(struct object_database *odb) {
- return object_file_transaction_begin(odb->sources);
-+ return odb_transaction_loose_begin(odb->sources);
++ return odb_transaction_files_begin(odb->sources);
}
void odb_transaction_commit(struct odb_transaction *transaction)
{
- object_file_transaction_commit(transaction);
-+ odb_transaction_loose_commit(transaction);
++ odb_transaction_files_commit(transaction);
}
3: a06bfd8c55 ! 3: 081c82428b odb: prepare struct odb_transaction to support more sources
@@ Metadata
Author: Justin Tobler <[email protected]>
## Commit message ##
- odb: prepare `struct odb_transaction` to support more sources
+ odb: prepare `struct odb_transaction` to become generic
- Each ODB transaction should be specific to the ODB source it pertains
- to. Update `struct odb_transaction` to store a commit callback specific
- to its object source type. For now `struct odb_transaction_loose` is the
+ An ODB transaction handles how objects are stored temporarily and
+ eventually committed. Due to object storage being implemented
+ differently for a given ODB source, the ODB transactions must be
+ implemented in a manner specific to the source the objects are being
+ written to. To provide generic transactions, `struct odb_transaction` is
+ updated to store a commit callback that can be configured to support a
+ specific ODB source. For now `struct odb_transaction_files` is the
only transaction type and what is always returned when starting a
transaction.
@@ object-file.c: struct transaction_packfile {
-struct odb_transaction {
- struct odb_source *source;
-+struct odb_transaction_loose {
++struct odb_transaction_files {
+ struct odb_transaction base;
struct tmp_objdir *objdir;
@@ object-file.c: struct transaction_packfile {
-static void prepare_loose_object_transaction(struct odb_transaction *transaction)
+static void prepare_loose_object_transaction(struct odb_transaction *base)
{
-+ struct odb_transaction_loose *transaction = (struct odb_transaction_loose *)base;
++ struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;
+
/*
* We lazily create the temporary object directory
@@ object-file.c: static void prepare_loose_object_transaction(struct odb_transacti
+static void fsync_loose_object_transaction(struct odb_transaction *base,
int fd, const char *filename)
{
-+ struct odb_transaction_loose *transaction = (struct odb_transaction_loose *)base;
++ struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;
+
/*
* If we have an active ODB transaction, we issue a call that
@@ object-file.c: static void fsync_loose_object_transaction(struct odb_transaction
* Cleanup after batch-mode fsync_object_files.
*/
-static void flush_loose_object_transaction(struct odb_transaction *transaction)
-+static void flush_loose_object_transaction(struct odb_transaction_loose *transaction)
++static void flush_loose_object_transaction(struct odb_transaction_files *transaction)
{
struct strbuf temp_path = STRBUF_INIT;
struct tempfile *temp;
@@ object-file.c: static int index_core(struct index_state *istate,
}
-static int already_written(struct odb_transaction *transaction,
-+static int already_written(struct odb_transaction_loose *transaction,
++static int already_written(struct odb_transaction_files *transaction,
struct object_id *oid)
{
/* The object may already exist in the repository */
@@ object-file.c: static int already_written(struct odb_transaction *transaction,
/* Lazily create backing packfile for the state */
-static void prepare_packfile_transaction(struct odb_transaction *transaction,
-+static void prepare_packfile_transaction(struct odb_transaction_loose *transaction,
++static void prepare_packfile_transaction(struct odb_transaction_files *transaction,
unsigned flags)
{
struct transaction_packfile *state = &transaction->packfile;
@@ object-file.c: static int stream_blob_to_pack(struct transaction_packfile *state
}
-static void flush_packfile_transaction(struct odb_transaction *transaction)
-+static void flush_packfile_transaction(struct odb_transaction_loose *transaction)
++static void flush_packfile_transaction(struct odb_transaction_files *transaction)
{
struct transaction_packfile *state = &transaction->packfile;
- struct repository *repo = transaction->source->odb->repo;
@@ object-file.c: static void flush_packfile_transaction(struct odb_transaction *tr
* callers should avoid this code path when filters are requested.
*/
-static int index_blob_packfile_transaction(struct odb_transaction *transaction,
-+static int index_blob_packfile_transaction(struct odb_transaction_loose *transaction,
++static int index_blob_packfile_transaction(struct odb_transaction_files *transaction,
struct object_id *result_oid, int fd,
size_t size, const char *path,
unsigned flags)
@@ object-file.c: int index_fd(struct index_state *istate, struct object_id *oid,
- transaction = odb_transaction_begin(the_repository->objects);
- ret = index_blob_packfile_transaction(the_repository->objects->transaction,
+ transaction = odb_transaction_begin(odb);
-+ ret = index_blob_packfile_transaction((struct odb_transaction_loose *)odb->transaction,
++ ret = index_blob_packfile_transaction((struct odb_transaction_files *)odb->transaction,
oid, fd,
xsize_t(st->st_size),
path, flags);
@@ object-file.c: int read_loose_object(struct repository *repo,
return ret;
}
--struct odb_transaction *odb_transaction_loose_begin(struct odb_source *source)
-+static void odb_transaction_loose_commit(struct odb_transaction *base)
+-struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
++static void odb_transaction_files_commit(struct odb_transaction *base)
{
- struct object_database *odb = source->odb;
-
@@ object-file.c: int read_loose_object(struct repository *repo,
- return odb->transaction;
-}
-
--void odb_transaction_loose_commit(struct odb_transaction *transaction)
+-void odb_transaction_files_commit(struct odb_transaction *transaction)
-{
- if (!transaction)
- return;
-+ struct odb_transaction_loose *transaction = (struct odb_transaction_loose *)base;
++ struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;
/*
* Ensure the transaction ending matches the pending transaction.
@@ object-file.c: int read_loose_object(struct repository *repo,
free(transaction);
}
-+struct odb_transaction *odb_transaction_loose_begin(struct odb_source *source)
++struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
+{
-+ struct odb_transaction_loose *transaction;
++ struct odb_transaction_files *transaction;
+ struct object_database *odb = source->odb;
+
+ if (odb->transaction)
@@ object-file.c: int read_loose_object(struct repository *repo,
+
+ transaction = xcalloc(1, sizeof(*transaction));
+ transaction->base.source = source;
-+ transaction->base.commit = odb_transaction_loose_commit;
++ transaction->base.commit = odb_transaction_files_commit;
+
+ odb->transaction = &transaction->base;
+
@@ object-file.c: int read_loose_object(struct repository *repo,
## object-file.h ##
@@ object-file.h: struct odb_transaction;
*/
- struct odb_transaction *odb_transaction_loose_begin(struct odb_source *source);
+ struct odb_transaction *odb_transaction_files_begin(struct odb_source *source);
-/*
- * Tell the object database to make any objects from the
- * current transaction visible.
- */
--void odb_transaction_loose_commit(struct odb_transaction *transaction);
+-void odb_transaction_files_commit(struct odb_transaction *transaction);
-
#endif /* OBJECT_FILE_H */
@@ odb.c: struct odb_transaction *odb_transaction_begin(struct object_database *odb
void odb_transaction_commit(struct odb_transaction *transaction)
{
-- odb_transaction_loose_commit(transaction);
+- odb_transaction_files_commit(transaction);
+ if (!transaction)
+ return;
+
4: 476ed1235c ! 4: ed8164a3a3 odb: transparently handle common transaction behavior
@@ Commit message
Signed-off-by: Justin Tobler <[email protected]>
## object-file.c ##
-@@ object-file.c: static void odb_transaction_loose_commit(struct odb_transaction *base)
+@@ object-file.c: static void odb_transaction_files_commit(struct odb_transaction *base)
{
- struct odb_transaction_loose *transaction = (struct odb_transaction_loose *)base;
+ struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;
- /*
- * Ensure the transaction ending matches the pending transaction.
@@ object-file.c: static void odb_transaction_loose_commit(struct odb_transaction *
- free(transaction);
}
- struct odb_transaction *odb_transaction_loose_begin(struct odb_source *source)
-@@ object-file.c: struct odb_transaction *odb_transaction_loose_begin(struct odb_source *source)
+ struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
+@@ object-file.c: struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
transaction->base.source = source;
- transaction->base.commit = odb_transaction_loose_commit;
+ transaction->base.commit = odb_transaction_files_commit;
- odb->transaction = &transaction->base;
-
@@ odb.c: void odb_reprepare(struct object_database *o)
struct odb_transaction *odb_transaction_begin(struct object_database *odb)
{
-- return odb_transaction_loose_begin(odb->sources);
-+ struct odb_transaction *transaction;
-+
+- return odb_transaction_files_begin(odb->sources);
+ if (odb->transaction)
+ return NULL;
+
-+ transaction = odb_transaction_loose_begin(odb->sources);
-+ odb->transaction = transaction;
++ odb->transaction = odb_transaction_files_begin(odb->sources);
+
-+ return transaction;
++ return odb->transaction;
}
void odb_transaction_commit(struct odb_transaction *transaction)base-commit: ea717645d199f6f1b66058886475db3e8c9330e9
Signature · 1 line
2.52.0.373.g68cb7f9e92
PATCH v2 1/4 odb: store ODB source in `struct odb_transaction`
Each struct odb_transaction currently stores a reference to the struct object_database. Since transactions are handled per object source, instead store a reference to the source.
--- object-file.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
object-file.c +11 -11
@@ -711,7 +711,7 @@ struct transaction_packfile { };struct odb_transaction { -struct object_database *odb; +struct odb_source *source;struct tmp_objdir *objdir;struct transaction_packfile packfile;
@@ -728,7 +728,7 @@ static void prepare_loose_object_transaction(struct odb_transaction *transactionif (!transaction || transaction->objdir)return ; - transaction->objdir =tmp_objdir_create (transaction->odb->repo,"bulk-fsync" ); + transaction->objdir =tmp_objdir_create (transaction->source->odb->repo,"bulk-fsync" );if (transaction->objdir)tmp_objdir_replace_primary_odb (transaction->objdir,0 ); }
@@ -772,7 +772,7 @@ static void flush_loose_object_transaction(struct odb_transaction *transaction)* the final name is visible. */ strbuf_addf (&temp_path,"%s/bulk_fsync_XXXXXX" , -repo_get_object_directory (transaction->odb->repo)); +repo_get_object_directory (transaction->source->odb->repo)); temp =xmks_tempfile (temp_path.buf);fsync_or_die (get_tempfile_fd (temp),get_tempfile_path (temp));delete_tempfile (&temp);
@@ -1344,7 +1344,7 @@ static int already_written(struct odb_transaction *transaction, struct object_id *oid) {/* The object may already exist in the repository */ -if (odb_has_object (transaction->odb, oid, +if (odb_has_object (transaction->source->odb, oid,HAS_OBJECT_RECHECK_PACKED |HAS_OBJECT_FETCH_PROMISOR ))return 1 ;
@@ -1365,7 +1365,7 @@ static void prepare_packfile_transaction(struct odb_transaction *transaction,if (!(flags &INDEX_WRITE_OBJECT ) || state->f)return ; - state->f =create_tmp_packfile (transaction->odb->repo, + state->f =create_tmp_packfile (transaction->source->odb->repo, &state->pack_tmp_name);reset_pack_idx_option (&state->pack_idx_opts);
@@ -1469,7 +1469,7 @@ static int stream_blob_to_pack(struct transaction_packfile *state,static void flush_packfile_transaction (struct odb_transaction *transaction) {struct transaction_packfile *state = &transaction->packfile; -struct repository *repo = transaction->odb->repo; +struct repository *repo = transaction->source->odb->repo;unsigned char hash[GIT_MAX_RAWSZ ];struct strbuf packname =STRBUF_INIT ;char *idx_tmp_name =NULL ;
@@ -1494,7 +1494,7 @@ static void flush_packfile_transaction(struct odb_transaction *transaction) }strbuf_addf (&packname,"%s/pack/pack-%s." , -repo_get_object_directory (transaction->odb->repo), +repo_get_object_directory (transaction->source->odb->repo),hash_to_hex_algop (hash, repo->hash_algo)); stage_tmp_packfiles(repo, &packname, state->pack_tmp_name,
@@ -1553,7 +1553,7 @@ static int index_blob_packfile_transaction(struct odb_transaction *transaction, header_len =format_object_header ((char *)obuf,sizeof (obuf),OBJ_BLOB , size); - transaction->odb->repo->hash_algo->init_fn (&ctx); + transaction->source->odb->repo->hash_algo->init_fn (&ctx);git_hash_update (&ctx, obuf, header_len);/* Note: idx is non-NULL when we are writing */
@@ -1993,7 +1993,7 @@ struct odb_transaction *object_file_transaction_begin(struct odb_source *source)return NULL ;CALLOC_ARRAY (odb->transaction,1 ); - odb->transaction->odb = odb; + odb->transaction->source = source;return odb->transaction; }
@@ -2006,11 +2006,11 @@ void object_file_transaction_commit(struct odb_transaction *transaction)/* * Ensure the transaction ending matches the pending transaction. */ -ASSERT (transaction == transaction->odb->transaction); +ASSERT (transaction == transaction->source->odb->transaction);flush_loose_object_transaction (transaction);flush_packfile_transaction (transaction); - transaction->odb->transaction =NULL ; + transaction->source->odb->transaction =NULL ;free (transaction); }
Signature · 1 line
2.52.0.373.g68cb7f9e92
PATCH v2 2/4 object-file: rename transaction functions
In reply to Justin ToblerIn a subsequent commit, ODB transactions are made more generic to facilitate each ODB source providing its own transaction handling. Rename object_file_transaction_{begin,commit}() to odb_transaction_files_{begin,commit}() to better match the future source specific transaction implementation.
--- object-file.c | 6 +++--- object-file.h | 6 +++--- odb.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-)
object-file.c +3 -3
@@ -723,7 +723,7 @@ static void prepare_loose_object_transaction(struct odb_transaction *transaction* We lazily create the temporary object directory * the first time an object might be added, since * callers may not know whether any objects will be -* added at the time they call object_file_transaction_begin. +* added at the time they call odb_transaction_files_begin. */ if (!transaction || transaction->objdir)return ;
@@ -1985,7 +1985,7 @@ int read_loose_object(struct repository *repo,return ret; } -struct odb_transaction *object_file_transaction_begin (struct odb_source *source) +struct odb_transaction *odb_transaction_files_begin (struct odb_source *source) {struct object_database *odb = source->odb;
@@ -1998,7 +1998,7 @@ struct odb_transaction *object_file_transaction_begin(struct odb_source *source)return odb->transaction; } -void object_file_transaction_commit (struct odb_transaction *transaction) +void odb_transaction_files_commit (struct odb_transaction *transaction) {if (!transaction)return ;
object-file.h +3 -3
@@ -202,16 +202,16 @@ struct odb_transaction;/* * Tell the object database to optimize for adding -* multiple objects. object_file_transaction_commit must be called +* multiple objects. odb_transaction_files_commit must be called * to make new objects visible. If a transaction is already * pending, NULL is returned. */ -struct odb_transaction *object_file_transaction_begin (struct odb_source *source); +struct odb_transaction *odb_transaction_files_begin (struct odb_source *source);/* * Tell the object database to make any objects from the * current transaction visible. */ -void object_file_transaction_commit (struct odb_transaction *transaction); +void odb_transaction_files_commit (struct odb_transaction *transaction);#endif /* OBJECT_FILE_H */
odb.c +2 -2
@@ -1153,10 +1153,10 @@ void odb_reprepare(struct object_database *o)struct odb_transaction *odb_transaction_begin (struct object_database *odb) { -return object_file_transaction_begin (odb->sources); +return odb_transaction_files_begin (odb->sources); }void odb_transaction_commit (struct odb_transaction *transaction) { -object_file_transaction_commit (transaction); +odb_transaction_files_commit (transaction); }
Signature · 1 line
2.52.0.373.g68cb7f9e92
PATCH v2 3/4 odb: prepare `struct odb_transaction` to become generic
In reply to Justin ToblerAn ODB transaction handles how objects are stored temporarily and eventually committed. Due to object storage being implemented differently for a given ODB source, the ODB transactions must be implemented in a manner specific to the source the objects are being written to. To provide generic transactions, struct odb_transaction is updated to store a commit callback that can be configured to support a specific ODB source. For now struct odb_transaction_files is the only transaction type and what is always returned when starting a transaction.
--- object-file.c | 80 ++++++++++++++++++++++++++++----------------------- object-file.h | 6 ---- odb.c | 5 +++- odb.h | 17 +++++++++++ 4 files changed, 65 insertions(+), 43 deletions(-)
object-file.c +44 -36
@@ -710,15 +710,17 @@ struct transaction_packfile {uint32_t nr_written; }; -struct odb_transaction { -struct odb_source *source; +struct odb_transaction_files { +struct odb_transaction base;struct tmp_objdir *objdir;struct transaction_packfile packfile; }; -static void prepare_loose_object_transaction (struct odb_transaction *transaction) +static void prepare_loose_object_transaction (struct odb_transaction *base) { +struct odb_transaction_files *transaction = (struct odb_transaction_files *)base; +/* * We lazily create the temporary object directory * the first time an object might be added, since
@@ -728,14 +730,16 @@ static void prepare_loose_object_transaction(struct odb_transaction *transactionif (!transaction || transaction->objdir)return ; - transaction->objdir =tmp_objdir_create (transaction->source->odb->repo,"bulk-fsync" ); + transaction->objdir =tmp_objdir_create (base->source->odb->repo,"bulk-fsync" );if (transaction->objdir)tmp_objdir_replace_primary_odb (transaction->objdir,0 ); } -static void fsync_loose_object_transaction (struct odb_transaction *transaction, +static void fsync_loose_object_transaction (struct odb_transaction *base,int fd,const char *filename) { +struct odb_transaction_files *transaction = (struct odb_transaction_files *)base; +/* * If we have an active ODB transaction, we issue a call that * cleans the filesystem page cache but avoids a hardware flush
@@ -754,7 +758,7 @@ static void fsync_loose_object_transaction(struct odb_transaction *transaction,/* * Cleanup after batch-mode fsync_object_files. */ -static void flush_loose_object_transaction (struct odb_transaction *transaction) +static void flush_loose_object_transaction (struct odb_transaction_files *transaction) {struct strbuf temp_path =STRBUF_INIT ;struct tempfile *temp;
@@ -772,7 +776,7 @@ static void flush_loose_object_transaction(struct odb_transaction *transaction)* the final name is visible. */ strbuf_addf (&temp_path,"%s/bulk_fsync_XXXXXX" , -repo_get_object_directory (transaction->source->odb->repo)); +repo_get_object_directory (transaction->base.source->odb->repo)); temp =xmks_tempfile (temp_path.buf);fsync_or_die (get_tempfile_fd (temp),get_tempfile_path (temp));delete_tempfile (&temp);
@@ -1340,11 +1344,11 @@ static int index_core(struct index_state *istate,return ret; } -static int already_written (struct odb_transaction *transaction, +static int already_written (struct odb_transaction_files *transaction,struct object_id *oid) {/* The object may already exist in the repository */ -if (odb_has_object (transaction->source->odb, oid, +if (odb_has_object (transaction->base.source->odb, oid,HAS_OBJECT_RECHECK_PACKED |HAS_OBJECT_FETCH_PROMISOR ))return 1 ;
@@ -1358,14 +1362,14 @@ static int already_written(struct odb_transaction *transaction, }/* Lazily create backing packfile for the state */ -static void prepare_packfile_transaction (struct odb_transaction *transaction, +static void prepare_packfile_transaction (struct odb_transaction_files *transaction,unsigned flags) {struct transaction_packfile *state = &transaction->packfile;if (!(flags &INDEX_WRITE_OBJECT ) || state->f)return ; - state->f =create_tmp_packfile (transaction->source->odb->repo, + state->f =create_tmp_packfile (transaction->base.source->odb->repo, &state->pack_tmp_name);reset_pack_idx_option (&state->pack_idx_opts);
@@ -1466,10 +1470,10 @@ static int stream_blob_to_pack(struct transaction_packfile *state,return 0 ; } -static void flush_packfile_transaction (struct odb_transaction *transaction) +static void flush_packfile_transaction (struct odb_transaction_files *transaction) {struct transaction_packfile *state = &transaction->packfile; -struct repository *repo = transaction->source->odb->repo; +struct repository *repo = transaction->base.source->odb->repo;unsigned char hash[GIT_MAX_RAWSZ ];struct strbuf packname =STRBUF_INIT ;char *idx_tmp_name =NULL ;
@@ -1494,7 +1498,7 @@ static void flush_packfile_transaction(struct odb_transaction *transaction) }strbuf_addf (&packname,"%s/pack/pack-%s." , -repo_get_object_directory (transaction->source->odb->repo), +repo_get_object_directory (transaction->base.source->odb->repo),hash_to_hex_algop (hash, repo->hash_algo)); stage_tmp_packfiles(repo, &packname, state->pack_tmp_name,
@@ -1534,7 +1538,7 @@ static void flush_packfile_transaction(struct odb_transaction *transaction)* binary blobs, they generally do not want to get any conversion, and * callers should avoid this code path when filters are requested. */ -static int index_blob_packfile_transaction (struct odb_transaction *transaction, +static int index_blob_packfile_transaction (struct odb_transaction_files *transaction,struct object_id *result_oid,int fd,size_t size,const char *path,unsigned flags)
@@ -1553,7 +1557,7 @@ static int index_blob_packfile_transaction(struct odb_transaction *transaction, header_len =format_object_header ((char *)obuf,sizeof (obuf),OBJ_BLOB , size); - transaction->source->odb->repo->hash_algo->init_fn (&ctx); + transaction->base.source->odb->repo->hash_algo->init_fn (&ctx);git_hash_update (&ctx, obuf, header_len);/* Note: idx is non-NULL when we are writing */
@@ -1629,10 +1633,11 @@ int index_fd(struct index_state *istate, struct object_id *oid, ret =index_core (istate, oid, fd,xsize_t (st->st_size), type, path, flags); }else { +struct object_database *odb = the_repository->objects;struct odb_transaction *transaction; - transaction =odb_transaction_begin (the_repository->objects); - ret =index_blob_packfile_transaction (the_repository->objects->transaction, + transaction =odb_transaction_begin (odb); + ret =index_blob_packfile_transaction ((struct odb_transaction_files *)odb->transaction, oid, fd,xsize_t (st->st_size), path, flags);
@@ -1985,35 +1990,38 @@ int read_loose_object(struct repository *repo,return ret; } -struct odb_transaction *odb_transaction_files_begin (struct odb_source *source) +static void odb_transaction_files_commit (struct odb_transaction *base) { -struct object_database *odb = source->odb; - -if (odb->transaction) -return NULL ; - -CALLOC_ARRAY (odb->transaction,1 ); - odb->transaction->source = source; - -return odb->transaction; -} - -void odb_transaction_files_commit (struct odb_transaction *transaction) -{ -if (!transaction) -return ; +struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;/* * Ensure the transaction ending matches the pending transaction. */ -ASSERT (transaction == transaction->source->odb->transaction); +ASSERT (base == base->source->odb->transaction);flush_loose_object_transaction (transaction);flush_packfile_transaction (transaction); - transaction->source->odb->transaction =NULL ; + base->source->odb->transaction =NULL ;free (transaction); } +struct odb_transaction *odb_transaction_files_begin (struct odb_source *source) +{ +struct odb_transaction_files *transaction; +struct object_database *odb = source->odb; + +if (odb->transaction) +return NULL ; + + transaction =xcalloc (1 ,sizeof (*transaction)); + transaction->base.source = source; + transaction->base.commit = odb_transaction_files_commit; + + odb->transaction = &transaction->base; + +return &transaction->base; +} +struct odb_source_loose *odb_source_loose_new (struct odb_source *source) {struct odb_source_loose *loose;
object-file.h +0 -6
@@ -208,10 +208,4 @@ struct odb_transaction;*/ struct odb_transaction *odb_transaction_files_begin (struct odb_source *source); -/* -* Tell the object database to make any objects from the -* current transaction visible. -*/ -void odb_transaction_files_commit (struct odb_transaction *transaction); -#endif /* OBJECT_FILE_H */
odb.c +4 -1
@@ -1158,5 +1158,8 @@ struct odb_transaction *odb_transaction_begin(struct object_database *odb)void odb_transaction_commit (struct odb_transaction *transaction) { -odb_transaction_files_commit (transaction); +if (!transaction) +return ; + + transaction->commit (transaction); }
odb.h +17 -0
@@ -77,7 +77,24 @@ struct odb_source {struct packed_git ;struct packfile_store ;struct cached_object_entry ; + +/* +* A transaction may be started for an object database prior to writing new +* objects via odb_transaction_begin(). These objects are not committed until +* odb_transaction_commit() is invoked. Only a single transaction may be pending +* at a time. +* +* Each ODB source is expected to implement its own transaction handling. +*/ struct odb_transaction ; +typedef void (*odb_transaction_commit_fn )(struct odb_transaction *transaction); +struct odb_transaction { +/* The ODB source the transaction is opened against. */ +struct odb_source *source; + +/* The ODB source specific callback invoked to commit a transaction. */ +odb_transaction_commit_fn commit; +};/* * The object database encapsulates access to objects in a repository. It
Signature · 1 line
2.52.0.373.g68cb7f9e92
Re: [PATCH v2 3/4] odb: prepare `struct odb_transaction` to become generic
Quoted 29 lines · Justin Tobler
An ODB transaction handles how objects are stored temporarily and eventually committed. Due to object storage being implemented differently for a given ODB source, the ODB transactions must be implemented in a manner specific to the source the objects are being written to. To provide generic transactions,
struct odb_transactionis updated to store a commit callback that can be configured to support a specific ODB source. For nowstruct odb_transaction_filesis the only transaction type and what is always returned when starting a transaction.Signed-off-by Justin Tobler <[email protected]>--- object-file.c | 80 ++++++++++++++++++++++++++++----------------------- object-file.h | 6 ---- odb.c | 5 +++- odb.h | 17 +++++++++++ 4 files changed, 65 insertions(+), 43 deletions(-)object-file.c +1
-2@@ -710,15 +710,17 @@ struct transaction_packfile {uint32_t nr_written; }; -struct odb_transaction { -struct odb_source *source; +struct odb_transaction_files {
object-file.c struct transaction_packfile { · line 722
Quoted 10 lines
object-file.c +3
-1+struct odb_transaction base;struct tmp_objdir *objdir;struct transaction_packfile packfile; }; -static void prepare_loose_object_transaction (struct odb_transaction *transaction) +static void prepare_loose_object_transaction (struct odb_transaction *base) { +struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;
So you're assuming struct odb_transaction is the first field in struct odb_transaction_files?
I think it would be safer to do this instead:
+ struct odb_transaction_files *transaction =
+ container_of(base, struct odb_transaction_files, base);
(this also can be applied in a few other places in this patch)
Signature · 2 lines
Cheers, Toon
Re: [PATCH v2 3/4] odb: prepare `struct odb_transaction` to become generic
Quoted 8 lines · Toon Claes
object-file.c struct transaction_packfile { · line 722
Quoted 4 lines · Justin Tobler
object-file.c +2
-1-static void prepare_loose_object_transaction (struct odb_transaction *transaction) +static void prepare_loose_object_transaction (struct odb_transaction *base) { +struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;So you're assuming
struct odb_transactionis the first field instruct odb_transaction_files?
Yes, struct odb_transaction_files contains a reference to struct odb_transaction as its first member which is the "base" transaction type. This way we can easily cast to the containing "concrete" type.
Quoted 6 lines
I think it would be safer to do this instead:
(quoted diff) +2
-0+ struct odb_transaction_files *transaction = + container_of(base, struct odb_transaction_files, base);(this also can be applied in a few other places in this patch)
So long as struct odb_transaction remains the first member of struct odb_transaction_files, using container_of() is functionally the same thing as casting. This is also how we do things for odb_read_stream and odb_loose_read_stream so I don't think it is too big of a deal either way.
I've made the change locally, but will hold off from sending another version unless folks feel strongly about this change or there is other feedback.
Thanks,
-Justin
Re: [PATCH v2 3/4] odb: prepare `struct odb_transaction` to become generic
Quoted 5 lines · Justin Tobler
So long as
struct odb_transactionremains the first member ofstruct odb_transaction_files, usingcontainer_of()is functionally the same thing as casting. This is also how we do things forodb_read_streamandodb_loose_read_streamso I don't think it is too big of a deal either way.
It would be a good theme to clean them all up, together with existing ones, in a separate topic. Code hygiene matters.
Re: [PATCH v2 3/4] odb: prepare `struct odb_transaction` to become generic
Quoted 10 lines · Junio C Hamano
Quoted 5 lines · Justin Tobler
So long as
struct odb_transactionremains the first member ofstruct odb_transaction_files, usingcontainer_of()is functionally the same thing as casting. This is also how we do things forodb_read_streamandodb_loose_read_streamso I don't think it is too big of a deal either way.It would be a good theme to clean them all up, together with existing ones, in a separate topic. Code hygiene matters.
Fair indeed. Justin, will you handle this cleanup once this topic here is merged or shall I do it?
Patrick
Re: [PATCH v2 3/4] odb: prepare `struct odb_transaction` to become generic
Quoted 9 lines · Patrick Steinhardt
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Justin Tobler
So long as
struct odb_transactionremains the first member ofstruct odb_transaction_files, usingcontainer_of()is functionally the same thing as casting. This is also how we do things forodb_read_streamandodb_loose_read_streamso I don't think it is too big of a deal either way.
Quoted 5 lines
Quoted 2 lines
It would be a good theme to clean them all up, together with existing ones, in a separate topic. Code hygiene matters.
Fair indeed. Justin, will you handle this cleanup once this topic here is merged or shall I do it?
I've already have a patch that addresses odb_transaction_files and odb_loose_read_stream. I'll check to see if there are any others I notice and send a followup series after this one gets merged.
-Justin
Re: [PATCH v2 3/4] odb: prepare `struct odb_transaction` to become generic
In reply to Justin ToblerJustin Tobler <[email protected]> writes:
[snip]
odb.h struct odb_source { · line 89
Quoted 10 lines
odb.h +9
-0+ +/* +* A transaction may be started for an object database prior to writing new +* objects via odb_transaction_begin(). These objects are not committed until +* odb_transaction_commit() is invoked. Only a single transaction may be pending +* at a time. +* +* Each ODB source is expected to implement its own transaction handling. +*/ struct odb_transaction ;
Nit: Wouldn't it be nicer to just the below struct odb_transaction here and drop this line?
Quoted 12 lines
odb.h +8
-1+typedef void (*odb_transaction_commit_fn )(struct odb_transaction *transaction); +struct odb_transaction { +/* The ODB source the transaction is opened against. */ +struct odb_source *source; + +/* The ODB source specific callback invoked to commit a transaction. */ +odb_transaction_commit_fn commit; +};/* * The object database encapsulates access to objects in a repository. It --
Quoted 1 line
2.52.0.373.g68cb7f9e92
Just a question in general, is the idea to eventually also add support for {prepare, rollback} within odb transactions?
Re: [PATCH v2 3/4] odb: prepare `struct odb_transaction` to become generic
Quoted 4 lines · Karthik Nayak
Justin Tobler <[email protected]> writes:
[snip]
Quoted 13 lines
odb.h struct odb_source { · line 89
Quoted 10 lines
odb.h +9
-0+ +/* +* A transaction may be started for an object database prior to writing new +* objects via odb_transaction_begin(). These objects are not committed until +* odb_transaction_commit() is invoked. Only a single transaction may be pending +* at a time. +* +* Each ODB source is expected to implement its own transaction handling. +*/ struct odb_transaction ;Nit: Wouldn't it be nicer to just the below
struct odb_transactionhere and drop this line?
I assume you mean drop the typedef in favor of defining it directly in the struct and thus removing the need for the forward declation. I kind of like having a typedef for the function callback, but I don't feel too strongly either way. I've ammended locally, but will hold off from sending another version unless there is other feedback.
Quoted 9 lines
Quoted 9 lines
odb.h +8
-0+typedef void (*odb_transaction_commit_fn )(struct odb_transaction *transaction); +struct odb_transaction { +/* The ODB source the transaction is opened against. */ +struct odb_source *source; + +/* The ODB source specific callback invoked to commit a transaction. */ +odb_transaction_commit_fn commit; +};
Quoted 7 lines
Quoted 4 lines
/*
* The object database encapsulates access to objects in a repository. It
--
2.52.0.373.g68cb7f9e92Just a question in general, is the idea to eventually also add support for {prepare, rollback} within odb transactions?
I'm not quite sure yet about "prepare", but certainly an "abort" or "rollback" will be introduced in a followup series. This will be useful as we expand ODB transaction usage to other operations that require the ability to remove temporary objects such as remerge-diffs.
Thanks,
-Justin
Re: [PATCH v2 3/4] odb: prepare `struct odb_transaction` to become generic
Quoted 19 lines · Justin Tobler
Quoted 4 lines · Karthik Nayak
Justin Tobler <[email protected]> writes:
[snip]
Quoted 13 lines
odb.h struct odb_source { · line 89
Quoted 10 lines
odb.h +9
-0+ +/* +* A transaction may be started for an object database prior to writing new +* objects via odb_transaction_begin(). These objects are not committed until +* odb_transaction_commit() is invoked. Only a single transaction may be pending +* at a time. +* +* Each ODB source is expected to implement its own transaction handling. +*/ struct odb_transaction ;Nit: Wouldn't it be nicer to just the below
struct odb_transactionhere and drop this line?
Quoted 6 lines
I assume you mean drop the typedef in favor of defining it directly in the struct and thus removing the need for the forward declation. I kind of like having a typedef for the function callback, but I don't feel too strongly either way. I've ammended locally, but will hold off from sending another version unless there is other feedback.
All good.
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
odb.h +8
-0+typedef void (*odb_transaction_commit_fn )(struct odb_transaction *transaction); +struct odb_transaction { +/* The ODB source the transaction is opened against. */ +struct odb_source *source; + +/* The ODB source specific callback invoked to commit a transaction. */ +odb_transaction_commit_fn commit; +};Quoted 7 lines
Quoted 4 lines
/*
* The object database encapsulates access to objects in a repository. It
--
2.52.0.373.g68cb7f9e92Just a question in general, is the idea to eventually also add support for {prepare, rollback} within odb transactions?
Quoted 5 lines
I'm not quite sure yet about "prepare", but certainly an "abort" or "rollback" will be introduced in a followup series. This will be useful as we expand ODB transaction usage to other operations that require the ability to remove temporary objects such as remerge-diffs.
Alright.
PATCH v2 4/4 odb: transparently handle common transaction behavior
In reply to Justin ToblerA new ODB transaction is created and returned via odb_transaction_begin() and stored in the ODB. Only a single transaction may be pending at a time. If the ODB already has a transaction, the function is expected to return NULL. Similarly, when committing a transaction via odb_transaction_commit() the transaction being committed must match the pending transaction and upon commit reset the ODB transaction to NULL.
These behaviors apply regardless of the ODB transaction implementation. Move the corresponding logic into odb_transaction_{begin,commit}() accordingly.
--- object-file.c | 9 --------- odb.c | 14 +++++++++++++- 2 files changed, 13 insertions(+), 10 deletions(-)
object-file.c +0 -9
@@ -1994,15 +1994,8 @@ static void odb_transaction_files_commit(struct odb_transaction *base) {struct odb_transaction_files *transaction = (struct odb_transaction_files *)base; -/* -* Ensure the transaction ending matches the pending transaction. -*/ -ASSERT (base == base->source->odb->transaction); -flush_loose_object_transaction (transaction);flush_packfile_transaction (transaction); - base->source->odb->transaction =NULL ; -free (transaction); }struct odb_transaction *odb_transaction_files_begin (struct odb_source *source)
@@ -2017,8 +2010,6 @@ struct odb_transaction *odb_transaction_files_begin(struct odb_source *source) transaction->base.source = source; transaction->base.commit = odb_transaction_files_commit; - odb->transaction = &transaction->base; -return &transaction->base; }
odb.c +13 -1
@@ -1153,7 +1153,12 @@ void odb_reprepare(struct object_database *o)struct odb_transaction *odb_transaction_begin (struct object_database *odb) { -return odb_transaction_files_begin (odb->sources); +if (odb->transaction) +return NULL ; + + odb->transaction =odb_transaction_files_begin (odb->sources); + +return odb->transaction; }void odb_transaction_commit (struct odb_transaction *transaction)
@@ -1161,5 +1166,12 @@ void odb_transaction_commit(struct odb_transaction *transaction)if (!transaction)return ; +/* +* Ensure the transaction ending matches the pending transaction. +*/ +ASSERT (transaction == transaction->source->odb->transaction); + transaction->commit (transaction); + transaction->source->odb->transaction =NULL ; +free (transaction); }
Signature · 1 line
2.52.0.373.g68cb7f9e92
Re: [PATCH v2 4/4] odb: transparently handle common transaction behavior
Quoted 8 lines · Justin Tobler
A new ODB transaction is created and returned via
odb_transaction_begin()and stored in the ODB. Only a single transaction may be pending at a time. If the ODB already has a transaction, the function is expected to return NULL. Similarly, when committing a transaction viaodb_transaction_commit()the transaction being committed must match the pending transaction and upon commit reset the ODB transaction to NULL.
But isn't this merely a limitation of the current implementation of the files transactions? Couldn't a potential ODB source support parallel transactions where this might no longer hold?
Quoted 4 lines
These behaviors apply regardless of the ODB transaction implementation. Move the corresponding logic into
odb_transaction_{begin,commit}()accordingly.
[snip]
Re: [PATCH v2 4/4] odb: transparently handle common transaction behavior
Quoted 10 lines · Karthik Nayak
Quoted 7 lines · Justin Tobler
A new ODB transaction is created and returned via
odb_transaction_begin()and stored in the ODB. Only a single transaction may be pending at a time. If the ODB already has a transaction, the function is expected to return NULL. Similarly, when committing a transaction viaodb_transaction_commit()the transaction being committed must match the pending transaction and upon commit reset the ODB transaction to NULL.
Quoted 3 lines
But isn't this merely a limitation of the current implementation of the files transactions? Couldn't a potential ODB source support parallel transactions where this might no longer hold?
Just to clarify, this limitation exists per Git process. For the time being, we only support writing objects to a single ODB source so a single transaction for object writes seems reasonable for now. Furthermore, the current "files" transaction backend relies on the tmp_odjdir subsystem which means only a single temp odjdir may exist for a Git process to write objects to.
-Justin
Re: [PATCH v2 4/4] odb: transparently handle common transaction behavior
Quoted 11 lines · Justin Tobler
Quoted 10 lines · Karthik Nayak
Quoted 7 lines · Justin Tobler
A new ODB transaction is created and returned via
odb_transaction_begin()and stored in the ODB. Only a single transaction may be pending at a time. If the ODB already has a transaction, the function is expected to return NULL. Similarly, when committing a transaction viaodb_transaction_commit()the transaction being committed must match the pending transaction and upon commit reset the ODB transaction to NULL.
Quoted 5 lines
Quoted 3 lines
But isn't this merely a limitation of the current implementation of the files transactions? Couldn't a potential ODB source support parallel transactions where this might no longer hold?
Just to clarify, this limitation exists per Git process.
I missed this, makes sense now.
Quoted 8 lines
For the time
being, we only support writing objects to a single ODB source so a single transaction for object writes seems reasonable for now. Furthermore, the current "files" transaction backend relies on thetmp_odjdirsubsystem which means only a single temp odjdir may exist for a Git process to write objects to.-Justin
Thanks
Quoted 8 lines · Justin Tobler
Changes since V1:
- Renamed the files transaction type to be
odb_transaction_files. Associated functions were also renamed accordingly.
- Updated commit messages.
- Thetmp_objdirsubsystem has been left unchange in the version. In a followup series, I plan to couple tmpdirs directly to ODB files transactions.
Ah, I was wondering why the changes are so small (it looked essentially s/loose/files/ and nothing else to me), but if we are leaving the tmp_objdir stuff out of the scope (which is sensible), then there aren't much left to do relative to the previous iteration.
Looking good. Will replace.
Thanks.
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Justin Tobler
Changes since V1:
- Renamed the files transaction type to be
odb_transaction_files. Associated functions were also renamed accordingly.
- Updated commit messages.
- Thetmp_objdirsubsystem has been left unchange in the version. In a followup series, I plan to couple tmpdirs directly to ODB files transactions.
Quoted 5 lines
Ah, I was wondering why the changes are so small (it looked essentially s/loose/files/ and nothing else to me), but if we are leaving the
tmp_objdirstuff out of the scope (which is sensible), then there aren't much left to do relative to the previous iteration.
Yeah, agreed. As long as there is a subsequent patch series that fixes the tmp_objdir thing I'm happy. It'd be a no-op refactoring for now anyway given that we always write via the temporary object directory, but it's a good cleanup to do on top.
Anyway, I'm happy with the status quo of this patch series, thanks!
Patrick