Skip to content

Commit 30d6fb8

Browse files
committed
Merge branch 'tb/incremental-midx-part-2' into jch
Incrementally updating multi-pack index files. * tb/incremental-midx-part-2: midx: implement writing incremental MIDX bitmaps pack-bitmap.c: use `ewah_or_iterator` for type bitmap iterators pack-bitmap.c: keep track of each layer's type bitmaps ewah: implement `struct ewah_or_iterator` pack-bitmap.c: apply pseudo-merge commits with incremental MIDXs pack-bitmap.c: compute disk-usage with incremental MIDXs pack-bitmap.c: teach `rev-list --test-bitmap` about incremental MIDXs pack-bitmap.c: support bitmap pack-reuse with incremental MIDXs pack-bitmap.c: teach `show_objects_for_type()` about incremental MIDXs pack-bitmap.c: teach `bitmap_for_commit()` about incremental MIDXs pack-bitmap.c: open and store incremental bitmap layers pack-revindex: prepare for incremental MIDX bitmaps Documentation: describe incremental MIDX bitmaps
2 parents d076d20 + 668e8c8 commit 30d6fb8

File tree

10 files changed

+559
-116
lines changed

10 files changed

+559
-116
lines changed

Documentation/technical/multi-pack-index.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,70 @@ objects_nr($H2) + objects_nr($H1) + i
164164
(in the C implementation, this is often computed as `i +
165165
m->num_objects_in_base`).
166166

167+
=== Pseudo-pack order for incremental MIDXs
168+
169+
The original implementation of multi-pack reachability bitmaps defined
170+
the pseudo-pack order in linkgit:gitformat-pack[5] (see the section
171+
titled "multi-pack-index reverse indexes") roughly as follows:
172+
173+
____
174+
In short, a MIDX's pseudo-pack is the de-duplicated concatenation of
175+
objects in packs stored by the MIDX, laid out in pack order, and the
176+
packs arranged in MIDX order (with the preferred pack coming first).
177+
____
178+
179+
In the incremental MIDX design, we extend this definition to include
180+
objects from multiple layers of the MIDX chain. The pseudo-pack order
181+
for incremental MIDXs is determined by concatenating the pseudo-pack
182+
ordering for each layer of the MIDX chain in order. Formally two objects
183+
`o1` and `o2` are compared as follows:
184+
185+
1. If `o1` appears in an earlier layer of the MIDX chain than `o2`, then
186+
`o1` is considered less than `o2`.
187+
2. Otherwise, if `o1` and `o2` appear in the same MIDX layer, and that
188+
MIDX layer has no base, then If one of `pack(o1)` and `pack(o2)` is
189+
preferred and the other is not, then the preferred one sorts first. If
190+
there is a base layer (i.e. the MIDX layer is not the first layer in
191+
the chain), then if `pack(o1)` appears earlier in that MIDX layer's
192+
pack order, than `o1` is less than `o2`. Likewise if `pack(o2)`
193+
appears earlier, than the opposite is true.
194+
3. Otherwise, `o1` and `o2` appear in the same pack, and thus in the
195+
same MIDX layer. Sort `o1` and `o2` by their offset within their
196+
containing packfile.
197+
198+
=== Reachability bitmaps and incremental MIDXs
199+
200+
Each layer of an incremental MIDX chain may have its objects (and the
201+
objects from any previous layer in the same MIDX chain) represented in
202+
its own `*.bitmap` file.
203+
204+
The structure of a `*.bitmap` file belonging to an incremental MIDX
205+
chain is identical to that of a non-incremental MIDX bitmap, or a
206+
classic single-pack bitmap. Since objects are added to the end of the
207+
incremental MIDX's pseudo-pack order (see: above), it is possible to
208+
extend a bitmap when appending to the end of a MIDX chain.
209+
210+
(Note: it is possible likewise to compress a contiguous sequence of MIDX
211+
incremental layers, and their `*.bitmap`(s) into a single layer and
212+
`*.bitmap`, but this is not yet implemented.)
213+
214+
The object positions used are global within the pseudo-pack order, so
215+
subsequent layers will have, for example, `m->num_objects_in_base`
216+
number of `0` bits in each of their four type bitmaps. This follows from
217+
the fact that we only write type bitmap entries for objects present in
218+
the layer immediately corresponding to the bitmap).
219+
220+
Note also that only the bitmap pertaining to the most recent layer in an
221+
incremental MIDX chain is used to store reachability information about
222+
the interesting and uninteresting objects in a reachability query.
223+
Earlier bitmap layers are only used to look up commit and pseudo-merge
224+
bitmaps from that layer, as well as the type-level bitmaps for objects
225+
in that layer.
226+
227+
To simplify the implementation, type-level bitmaps are iterated
228+
simultaneously, and their results are OR'd together to avoid recursively
229+
calling internal bitmap functions.
230+
167231
Future Work
168232
-----------
169233

builtin/pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,8 @@ static void write_pack_file(void)
13561356

13571357
if (write_bitmap_index) {
13581358
bitmap_writer_init(&bitmap_writer,
1359-
the_repository, &to_pack);
1359+
the_repository, &to_pack,
1360+
NULL);
13601361
bitmap_writer_set_checksum(&bitmap_writer, hash);
13611362
bitmap_writer_build_type_index(&bitmap_writer,
13621363
written_list);

ewah/ewah_bitmap.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,39 @@ void ewah_iterator_init(struct ewah_iterator *it, struct ewah_bitmap *parent)
372372
read_new_rlw(it);
373373
}
374374

375+
void ewah_or_iterator_init(struct ewah_or_iterator *it,
376+
struct ewah_bitmap **parents, size_t nr)
377+
{
378+
size_t i;
379+
380+
memset(it, 0, sizeof(*it));
381+
382+
ALLOC_ARRAY(it->its, nr);
383+
for (i = 0; i < nr; i++)
384+
ewah_iterator_init(&it->its[it->nr++], parents[i]);
385+
}
386+
387+
int ewah_or_iterator_next(eword_t *next, struct ewah_or_iterator *it)
388+
{
389+
eword_t buf, out = 0;
390+
size_t i;
391+
int ret = 0;
392+
393+
for (i = 0; i < it->nr; i++)
394+
if (ewah_iterator_next(&buf, &it->its[i])) {
395+
out |= buf;
396+
ret = 1;
397+
}
398+
399+
*next = out;
400+
return ret;
401+
}
402+
403+
void ewah_or_iterator_free(struct ewah_or_iterator *it)
404+
{
405+
free(it->its);
406+
}
407+
375408
void ewah_xor(
376409
struct ewah_bitmap *ewah_i,
377410
struct ewah_bitmap *ewah_j,

ewah/ewok.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ void ewah_iterator_init(struct ewah_iterator *it, struct ewah_bitmap *parent);
148148
*/
149149
int ewah_iterator_next(eword_t *next, struct ewah_iterator *it);
150150

151+
struct ewah_or_iterator {
152+
struct ewah_iterator *its;
153+
size_t nr;
154+
};
155+
156+
void ewah_or_iterator_init(struct ewah_or_iterator *it,
157+
struct ewah_bitmap **parents, size_t nr);
158+
159+
int ewah_or_iterator_next(eword_t *next, struct ewah_or_iterator *it);
160+
161+
void ewah_or_iterator_free(struct ewah_or_iterator *it);
162+
151163
void ewah_xor(
152164
struct ewah_bitmap *ewah_i,
153165
struct ewah_bitmap *ewah_j,

midx-write.c

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -645,15 +645,21 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)
645645
return pack_order;
646646
}
647647

648-
static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,
649-
struct write_midx_context *ctx)
648+
static void write_midx_reverse_index(struct write_midx_context *ctx,
649+
const char *object_dir,
650+
unsigned char *midx_hash)
650651
{
651652
struct strbuf buf = STRBUF_INIT;
652653
char *tmp_file;
653654

654655
trace2_region_enter("midx", "write_midx_reverse_index", the_repository);
655656

656-
strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex(midx_hash));
657+
if (ctx->incremental)
658+
get_split_midx_filename_ext(&buf, object_dir, midx_hash,
659+
MIDX_EXT_REV);
660+
else
661+
get_midx_filename_ext(&buf, object_dir, midx_hash,
662+
MIDX_EXT_REV);
657663

658664
tmp_file = write_rev_file_order(NULL, ctx->pack_order, ctx->entries_nr,
659665
midx_hash, WRITE_REV);
@@ -827,20 +833,26 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr
827833
return cb.commits;
828834
}
829835

830-
static int write_midx_bitmap(const char *midx_name,
836+
static int write_midx_bitmap(struct write_midx_context *ctx,
837+
const char *object_dir,
831838
const unsigned char *midx_hash,
832839
struct packing_data *pdata,
833840
struct commit **commits,
834841
uint32_t commits_nr,
835-
uint32_t *pack_order,
836842
unsigned flags)
837843
{
838844
int ret, i;
839845
uint16_t options = 0;
840846
struct bitmap_writer writer;
841847
struct pack_idx_entry **index;
842-
char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name,
843-
hash_to_hex(midx_hash));
848+
struct strbuf bitmap_name = STRBUF_INIT;
849+
850+
if (ctx->incremental)
851+
get_split_midx_filename_ext(&bitmap_name, object_dir, midx_hash,
852+
MIDX_EXT_BITMAP);
853+
else
854+
get_midx_filename_ext(&bitmap_name, object_dir, midx_hash,
855+
MIDX_EXT_BITMAP);
844856

845857
trace2_region_enter("midx", "write_midx_bitmap", the_repository);
846858

@@ -859,7 +871,8 @@ static int write_midx_bitmap(const char *midx_name,
859871
for (i = 0; i < pdata->nr_objects; i++)
860872
index[i] = &pdata->objects[i].idx;
861873

862-
bitmap_writer_init(&writer, the_repository, pdata);
874+
bitmap_writer_init(&writer, the_repository, pdata,
875+
ctx->incremental ? ctx->base_midx : NULL);
863876
bitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS);
864877
bitmap_writer_build_type_index(&writer, index);
865878

@@ -877,19 +890,19 @@ static int write_midx_bitmap(const char *midx_name,
877890
* bitmap_writer_finish().
878891
*/
879892
for (i = 0; i < pdata->nr_objects; i++)
880-
index[pack_order[i]] = &pdata->objects[i].idx;
893+
index[ctx->pack_order[i]] = &pdata->objects[i].idx;
881894

882895
bitmap_writer_select_commits(&writer, commits, commits_nr);
883896
ret = bitmap_writer_build(&writer);
884897
if (ret < 0)
885898
goto cleanup;
886899

887900
bitmap_writer_set_checksum(&writer, midx_hash);
888-
bitmap_writer_finish(&writer, index, bitmap_name, options);
901+
bitmap_writer_finish(&writer, index, bitmap_name.buf, options);
889902

890903
cleanup:
891904
free(index);
892-
free(bitmap_name);
905+
strbuf_release(&bitmap_name);
893906
bitmap_writer_free(&writer);
894907

895908
trace2_region_leave("midx", "write_midx_bitmap", the_repository);
@@ -1073,8 +1086,6 @@ static int write_midx_internal(const char *object_dir,
10731086
trace2_region_enter("midx", "write_midx_internal", the_repository);
10741087

10751088
ctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL);
1076-
if (ctx.incremental && (flags & MIDX_WRITE_BITMAP))
1077-
die(_("cannot write incremental MIDX with bitmap"));
10781089

10791090
if (ctx.incremental)
10801091
strbuf_addf(&midx_name,
@@ -1116,6 +1127,12 @@ static int write_midx_internal(const char *object_dir,
11161127
if (ctx.incremental) {
11171128
struct multi_pack_index *m = ctx.base_midx;
11181129
while (m) {
1130+
if (flags & MIDX_WRITE_BITMAP && load_midx_revindex(m)) {
1131+
error(_("could not load reverse index for MIDX %s"),
1132+
hash_to_hex(get_midx_checksum(m)));
1133+
result = 1;
1134+
goto cleanup;
1135+
}
11191136
ctx.num_multi_pack_indexes_before++;
11201137
m = m->base_midx;
11211138
}
@@ -1382,7 +1399,7 @@ static int write_midx_internal(const char *object_dir,
13821399

13831400
if (flags & MIDX_WRITE_REV_INDEX &&
13841401
git_env_bool("GIT_TEST_MIDX_WRITE_REV", 0))
1385-
write_midx_reverse_index(midx_name.buf, midx_hash, &ctx);
1402+
write_midx_reverse_index(&ctx, object_dir, midx_hash);
13861403

13871404
if (flags & MIDX_WRITE_BITMAP) {
13881405
struct packing_data pdata;
@@ -1405,8 +1422,8 @@ static int write_midx_internal(const char *object_dir,
14051422
FREE_AND_NULL(ctx.entries);
14061423
ctx.entries_nr = 0;
14071424

1408-
if (write_midx_bitmap(midx_name.buf, midx_hash, &pdata,
1409-
commits, commits_nr, ctx.pack_order,
1425+
if (write_midx_bitmap(&ctx, object_dir,
1426+
midx_hash, &pdata, commits, commits_nr,
14101427
flags) < 0) {
14111428
error(_("could not write multi-pack bitmap"));
14121429
result = 1;

0 commit comments

Comments
 (0)