Skip to content

Commit 2c23d1b

Browse files
neerajsi-msftgitster
authored andcommitted
bulk-checkin: rebrand plug/unplug APIs as 'odb transactions'
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]>
1 parent 897c9e2 commit 2c23d1b

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

builtin/add.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
670670
string_list_clear(&only_match_skip_worktree, 0);
671671
}
672672

673-
plug_bulk_checkin();
673+
begin_odb_transaction();
674674

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

683683
if (chmod_arg && pathspec.nr)
684684
exit_status |= chmod_pathspec(&pathspec, chmod_arg[0], show_only);
685-
unplug_bulk_checkin();
685+
end_odb_transaction();
686686

687687
finish:
688688
if (write_locked_index(&the_index, &lock_file,

bulk-checkin.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "packfile.h"
1111
#include "object-store.h"
1212

13-
static int bulk_checkin_plugged;
13+
static int odb_transaction_nesting;
1414

1515
static struct bulk_checkin_packfile {
1616
char *pack_tmp_name;
@@ -280,20 +280,29 @@ int index_bulk_checkin(struct object_id *oid,
280280
{
281281
int status = deflate_to_pack(&bulk_checkin_packfile, oid, fd, size, type,
282282
path, flags);
283-
if (!bulk_checkin_plugged)
283+
if (!odb_transaction_nesting)
284284
flush_bulk_checkin_packfile(&bulk_checkin_packfile);
285285
return status;
286286
}
287287

288-
void plug_bulk_checkin(void)
288+
void begin_odb_transaction(void)
289289
{
290-
assert(!bulk_checkin_plugged);
291-
bulk_checkin_plugged = 1;
290+
odb_transaction_nesting += 1;
292291
}
293292

294-
void unplug_bulk_checkin(void)
293+
void flush_odb_transaction(void)
295294
{
296-
assert(bulk_checkin_plugged);
297-
bulk_checkin_plugged = 0;
298295
flush_bulk_checkin_packfile(&bulk_checkin_packfile);
299296
}
297+
298+
void end_odb_transaction(void)
299+
{
300+
odb_transaction_nesting -= 1;
301+
if (odb_transaction_nesting < 0)
302+
BUG("Unbalanced ODB transaction nesting");
303+
304+
if (odb_transaction_nesting)
305+
return;
306+
307+
flush_odb_transaction();
308+
}

bulk-checkin.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,27 @@ int index_bulk_checkin(struct object_id *oid,
1010
int fd, size_t size, enum object_type type,
1111
const char *path, unsigned flags);
1212

13-
void plug_bulk_checkin(void);
14-
void unplug_bulk_checkin(void);
13+
/*
14+
* Tell the object database to optimize for adding
15+
* multiple objects. end_odb_transaction must be called
16+
* to make new objects visible. Transactions can be nested,
17+
* and objects are only visible after the outermost transaction
18+
* is complete or the transaction is flushed.
19+
*/
20+
void begin_odb_transaction(void);
21+
22+
/*
23+
* Make any objects that are currently part of a pending object
24+
* database transaction visible. It is valid to call this function
25+
* even if no transaction is active.
26+
*/
27+
void flush_odb_transaction(void);
28+
29+
/*
30+
* Tell the object database to make any objects from the
31+
* current transaction visible if this is the final nested
32+
* transaction.
33+
*/
34+
void end_odb_transaction(void);
1535

1636
#endif

0 commit comments

Comments
 (0)