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 <neerajsi@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Neeraj Singh committed
Apr 4, 2022 at 22:20 UTC
2c23d1b4776ec7b089943edb234f5de4312a6e30
3 files changed
+41
-12
builtin/add.c
+2
-2
@@ -670,7 +670,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
670
string_list_clear(&only_match_skip_worktree, 0);
671
}
672
673
- plug_bulk_checkin();
673
+ begin_odb_transaction();
674
675
if (add_renormalize)
676
exit_status |= renormalize_tracked_files(&pathspec, flags);
@@ -682,7 +682,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
682
683
if (chmod_arg && pathspec.nr)
684
exit_status |= chmod_pathspec(&pathspec, chmod_arg[0], show_only);
685
- unplug_bulk_checkin();
685
+ end_odb_transaction();
686
687
finish:
688
if (write_locked_index(&the_index, &lock_file,
bulk-checkin.c
+17
-8
@@ -10,7 +10,7 @@
10
#include "packfile.h"
11
#include "object-store.h"
12
13
-static int bulk_checkin_plugged;
13
+static int odb_transaction_nesting;
14
15
static struct bulk_checkin_packfile {
16
char *pack_tmp_name;
@@ -280,20 +280,29 @@ int index_bulk_checkin(struct object_id *oid,
280
{
281
int status = deflate_to_pack(&bulk_checkin_packfile, oid, fd, size, type,
282
path, flags);
283
- if (!bulk_checkin_plugged)
283
+ if (!odb_transaction_nesting)
284
flush_bulk_checkin_packfile(&bulk_checkin_packfile);
285
return status;
286
}
287
288
-void plug_bulk_checkin(void)
288
+void begin_odb_transaction(void)
289
{
290
- assert(!bulk_checkin_plugged);
291
- bulk_checkin_plugged = 1;
290
+ odb_transaction_nesting += 1;
291
}
292
294
-void unplug_bulk_checkin(void)
293
+void flush_odb_transaction(void)
294
{
296
- assert(bulk_checkin_plugged);
297
- bulk_checkin_plugged = 0;
295
flush_bulk_checkin_packfile(&bulk_checkin_packfile);
296
}
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
+22
-2
@@ -10,7 +10,27 @@ int index_bulk_checkin(struct object_id *oid,
10
int fd, size_t size, enum object_type type,
11
const char *path, unsigned flags);
12
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);
35
36
#endif