Skip to content

Commit

Permalink
bulk-checkin: rebrand plug/unplug APIs as 'odb transactions'
Browse files Browse the repository at this point in the history
Make it clearer in the naming and documentation of the plug_bulk_checkin
and unplug_bulk_checkin APIs that they can be thought of as
a "transaction" to optimize operations on the object database. These
transactions may be nested so that subsystems like the cache-tree
writing code can optimize their operations without caring whether the
top-level code has a transaction active.

Add a flush_odb_transaction API that will be used in update-index to
make objects visible even if a transaction is active. The flush call may
also be useful in future cases if we hold a transaction active around
calling hooks.

Signed-off-by: Neeraj Singh <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
neerajsi-msft authored and gitster committed Apr 6, 2022
1 parent 897c9e2 commit 2c23d1b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
4 changes: 2 additions & 2 deletions builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
string_list_clear(&only_match_skip_worktree, 0);
}

plug_bulk_checkin();
begin_odb_transaction();

if (add_renormalize)
exit_status |= renormalize_tracked_files(&pathspec, flags);
Expand All @@ -682,7 +682,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)

if (chmod_arg && pathspec.nr)
exit_status |= chmod_pathspec(&pathspec, chmod_arg[0], show_only);
unplug_bulk_checkin();
end_odb_transaction();

finish:
if (write_locked_index(&the_index, &lock_file,
Expand Down
25 changes: 17 additions & 8 deletions bulk-checkin.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "packfile.h"
#include "object-store.h"

static int bulk_checkin_plugged;
static int odb_transaction_nesting;

static struct bulk_checkin_packfile {
char *pack_tmp_name;
Expand Down Expand Up @@ -280,20 +280,29 @@ int index_bulk_checkin(struct object_id *oid,
{
int status = deflate_to_pack(&bulk_checkin_packfile, oid, fd, size, type,
path, flags);
if (!bulk_checkin_plugged)
if (!odb_transaction_nesting)
flush_bulk_checkin_packfile(&bulk_checkin_packfile);
return status;
}

void plug_bulk_checkin(void)
void begin_odb_transaction(void)
{
assert(!bulk_checkin_plugged);
bulk_checkin_plugged = 1;
odb_transaction_nesting += 1;
}

void unplug_bulk_checkin(void)
void flush_odb_transaction(void)
{
assert(bulk_checkin_plugged);
bulk_checkin_plugged = 0;
flush_bulk_checkin_packfile(&bulk_checkin_packfile);
}

void end_odb_transaction(void)
{
odb_transaction_nesting -= 1;
if (odb_transaction_nesting < 0)
BUG("Unbalanced ODB transaction nesting");

if (odb_transaction_nesting)
return;

flush_odb_transaction();
}
24 changes: 22 additions & 2 deletions bulk-checkin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,27 @@ int index_bulk_checkin(struct object_id *oid,
int fd, size_t size, enum object_type type,
const char *path, unsigned flags);

void plug_bulk_checkin(void);
void unplug_bulk_checkin(void);
/*
* Tell the object database to optimize for adding
* multiple objects. end_odb_transaction must be called
* to make new objects visible. Transactions can be nested,
* and objects are only visible after the outermost transaction
* is complete or the transaction is flushed.
*/
void begin_odb_transaction(void);

/*
* Make any objects that are currently part of a pending object
* database transaction visible. It is valid to call this function
* even if no transaction is active.
*/
void flush_odb_transaction(void);

/*
* Tell the object database to make any objects from the
* current transaction visible if this is the final nested
* transaction.
*/
void end_odb_transaction(void);

#endif

0 comments on commit 2c23d1b

Please sign in to comment.