Skip to content

Commit 9851830

Browse files
jltoblergitster
authored andcommitted
bulk-checkin: introduce object database transaction structure
Object database transaction state is stored across several global variables in the bulk-checkin subsystem. Consolidate this state into a single `struct odb_transaction` global. In a subsequent commit, the transactional interfaces will be updated to wire this structure instead of relying on a global variable. Signed-off-by: Justin Tobler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c44beea commit 9851830

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

bulk-checkin.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919
#include "object-file.h"
2020
#include "odb.h"
2121

22-
static int odb_transaction_nesting;
23-
24-
static struct tmp_objdir *bulk_fsync_objdir;
25-
26-
static struct bulk_checkin_packfile {
22+
struct bulk_checkin_packfile {
2723
char *pack_tmp_name;
2824
struct hashfile *f;
2925
off_t offset;
@@ -32,7 +28,13 @@ static struct bulk_checkin_packfile {
3228
struct pack_idx_entry **written;
3329
uint32_t alloc_written;
3430
uint32_t nr_written;
35-
} bulk_checkin_packfile;
31+
};
32+
33+
static struct odb_transaction {
34+
int nesting;
35+
struct tmp_objdir *objdir;
36+
struct bulk_checkin_packfile packfile;
37+
} transaction;
3638

3739
static void finish_tmp_packfile(struct strbuf *basename,
3840
const char *pack_tmp_name,
@@ -101,7 +103,7 @@ static void flush_batch_fsync(void)
101103
struct strbuf temp_path = STRBUF_INIT;
102104
struct tempfile *temp;
103105

104-
if (!bulk_fsync_objdir)
106+
if (!transaction.objdir)
105107
return;
106108

107109
/*
@@ -123,8 +125,8 @@ static void flush_batch_fsync(void)
123125
* Make the object files visible in the primary ODB after their data is
124126
* fully durable.
125127
*/
126-
tmp_objdir_migrate(bulk_fsync_objdir);
127-
bulk_fsync_objdir = NULL;
128+
tmp_objdir_migrate(transaction.objdir);
129+
transaction.objdir = NULL;
128130
}
129131

130132
static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
@@ -331,12 +333,12 @@ void prepare_loose_object_bulk_checkin(void)
331333
* callers may not know whether any objects will be
332334
* added at the time they call begin_odb_transaction.
333335
*/
334-
if (!odb_transaction_nesting || bulk_fsync_objdir)
336+
if (!transaction.nesting || transaction.objdir)
335337
return;
336338

337-
bulk_fsync_objdir = tmp_objdir_create(the_repository, "bulk-fsync");
338-
if (bulk_fsync_objdir)
339-
tmp_objdir_replace_primary_odb(bulk_fsync_objdir, 0);
339+
transaction.objdir = tmp_objdir_create(the_repository, "bulk-fsync");
340+
if (transaction.objdir)
341+
tmp_objdir_replace_primary_odb(transaction.objdir, 0);
340342
}
341343

342344
void fsync_loose_object_bulk_checkin(int fd, const char *filename)
@@ -348,7 +350,7 @@ void fsync_loose_object_bulk_checkin(int fd, const char *filename)
348350
* before renaming the objects to their final names as part of
349351
* flush_batch_fsync.
350352
*/
351-
if (!bulk_fsync_objdir ||
353+
if (!transaction.objdir ||
352354
git_fsync(fd, FSYNC_WRITEOUT_ONLY) < 0) {
353355
if (errno == ENOSYS)
354356
warning(_("core.fsyncMethod = batch is unsupported on this platform"));
@@ -360,31 +362,31 @@ int index_blob_bulk_checkin(struct object_id *oid,
360362
int fd, size_t size,
361363
const char *path, unsigned flags)
362364
{
363-
int status = deflate_blob_to_pack(&bulk_checkin_packfile, oid, fd, size,
365+
int status = deflate_blob_to_pack(&transaction.packfile, oid, fd, size,
364366
path, flags);
365-
if (!odb_transaction_nesting)
366-
flush_bulk_checkin_packfile(&bulk_checkin_packfile);
367+
if (!transaction.nesting)
368+
flush_bulk_checkin_packfile(&transaction.packfile);
367369
return status;
368370
}
369371

370372
void begin_odb_transaction(void)
371373
{
372-
odb_transaction_nesting += 1;
374+
transaction.nesting += 1;
373375
}
374376

375377
void flush_odb_transaction(void)
376378
{
377379
flush_batch_fsync();
378-
flush_bulk_checkin_packfile(&bulk_checkin_packfile);
380+
flush_bulk_checkin_packfile(&transaction.packfile);
379381
}
380382

381383
void end_odb_transaction(void)
382384
{
383-
odb_transaction_nesting -= 1;
384-
if (odb_transaction_nesting < 0)
385+
transaction.nesting -= 1;
386+
if (transaction.nesting < 0)
385387
BUG("Unbalanced ODB transaction nesting");
386388

387-
if (odb_transaction_nesting)
389+
if (transaction.nesting)
388390
return;
389391

390392
flush_odb_transaction();

0 commit comments

Comments
 (0)