Skip to content

Commit 29ade02

Browse files
committed
Merge branch 'tb/incremental-midx-part-2' into seen
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 777a5e2 + 99b4db3 commit 29ade02

File tree

10 files changed

+583
-122
lines changed

10 files changed

+583
-122
lines changed

Documentation/technical/multi-pack-index.adoc

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,77 @@ 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+
188+
2. Otherwise, if `o1` and `o2` appear in the same MIDX layer, and that
189+
MIDX layer has no base, then if one of `pack(o1)` and `pack(o2)` is
190+
preferred and the other is not, then the preferred one sorts first. If
191+
there is a base layer (i.e. the MIDX layer is not the first layer in
192+
the chain), then if `pack(o1)` appears earlier in that MIDX layer's
193+
pack order, than `o1` is less than `o2`. Likewise if `pack(o2)`
194+
appears earlier, than the opposite is true.
195+
196+
3. Otherwise, `o1` and `o2` appear in the same pack, and thus in the
197+
same MIDX layer. Sort `o1` and `o2` by their offset within their
198+
containing packfile.
199+
200+
Note that the preferred pack is a property of the MIDX chain, not the
201+
individual layers themselves. Fundamentally we could introduce a
202+
per-layer preferred pack, but this is less relevant now that we can
203+
perform multi-pack reuse across the set of packs in a MIDX.
204+
205+
=== Reachability bitmaps and incremental MIDXs
206+
207+
Each layer of an incremental MIDX chain may have its objects (and the
208+
objects from any previous layer in the same MIDX chain) represented in
209+
its own `*.bitmap` file.
210+
211+
The structure of a `*.bitmap` file belonging to an incremental MIDX
212+
chain is identical to that of a non-incremental MIDX bitmap, or a
213+
classic single-pack bitmap. Since objects are added to the end of the
214+
incremental MIDX's pseudo-pack order (see: above), it is possible to
215+
extend a bitmap when appending to the end of a MIDX chain.
216+
217+
(Note: it is possible likewise to compress a contiguous sequence of MIDX
218+
incremental layers, and their `*.bitmap`(s) into a single layer and
219+
`*.bitmap`, but this is not yet implemented.)
220+
221+
The object positions used are global within the pseudo-pack order, so
222+
subsequent layers will have, for example, `m->num_objects_in_base`
223+
number of `0` bits in each of their four type bitmaps. This follows from
224+
the fact that we only write type bitmap entries for objects present in
225+
the layer immediately corresponding to the bitmap).
226+
227+
Note also that only the bitmap pertaining to the most recent layer in an
228+
incremental MIDX chain is used to store reachability information about
229+
the interesting and uninteresting objects in a reachability query.
230+
Earlier bitmap layers are only used to look up commit and pseudo-merge
231+
bitmaps from that layer, as well as the type-level bitmaps for objects
232+
in that layer.
233+
234+
To simplify the implementation, type-level bitmaps are iterated
235+
simultaneously, and their results are OR'd together to avoid recursively
236+
calling internal bitmap functions.
237+
167238
Future Work
168239
-----------
169240

builtin/pack-objects.c

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

14121412
if (write_bitmap_index) {
14131413
bitmap_writer_init(&bitmap_writer,
1414-
the_repository, &to_pack);
1414+
the_repository, &to_pack,
1415+
NULL);
14151416
bitmap_writer_set_checksum(&bitmap_writer, hash);
14161417
bitmap_writer_build_type_index(&bitmap_writer,
14171418
written_list);

ewah/ewah_bitmap.c

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

374+
void ewah_or_iterator_init(struct ewah_or_iterator *it,
375+
struct ewah_bitmap **parents, size_t nr)
376+
{
377+
size_t i;
378+
379+
memset(it, 0, sizeof(*it));
380+
381+
ALLOC_ARRAY(it->its, nr);
382+
for (i = 0; i < nr; i++)
383+
ewah_iterator_init(&it->its[it->nr++], parents[i]);
384+
}
385+
386+
int ewah_or_iterator_next(eword_t *next, struct ewah_or_iterator *it)
387+
{
388+
eword_t buf, out = 0;
389+
size_t i;
390+
int ret = 0;
391+
392+
for (i = 0; i < it->nr; i++)
393+
if (ewah_iterator_next(&buf, &it->its[i])) {
394+
out |= buf;
395+
ret = 1;
396+
}
397+
398+
*next = out;
399+
return ret;
400+
}
401+
402+
void ewah_or_iterator_release(struct ewah_or_iterator *it)
403+
{
404+
free(it->its);
405+
}
406+
374407
void ewah_xor(
375408
struct ewah_bitmap *ewah_i,
376409
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_release(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: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -647,16 +647,22 @@ static uint32_t *midx_pack_order(struct write_midx_context *ctx)
647647
return pack_order;
648648
}
649649

650-
static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,
651-
struct write_midx_context *ctx)
650+
static void write_midx_reverse_index(struct write_midx_context *ctx,
651+
const char *object_dir,
652+
unsigned char *midx_hash)
652653
{
653654
struct strbuf buf = STRBUF_INIT;
654655
char *tmp_file;
655656

656657
trace2_region_enter("midx", "write_midx_reverse_index", ctx->repo);
657658

658-
strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex_algop(midx_hash,
659-
ctx->repo->hash_algo));
659+
if (ctx->incremental)
660+
get_split_midx_filename_ext(ctx->repo->hash_algo, &buf,
661+
object_dir, midx_hash,
662+
MIDX_EXT_REV);
663+
else
664+
get_midx_filename_ext(ctx->repo->hash_algo, &buf, object_dir,
665+
midx_hash, MIDX_EXT_REV);
660666

661667
tmp_file = write_rev_file_order(ctx->repo, NULL, ctx->pack_order,
662668
ctx->entries_nr, midx_hash, WRITE_REV);
@@ -829,22 +835,29 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr
829835
return cb.commits;
830836
}
831837

832-
static int write_midx_bitmap(struct repository *r, const char *midx_name,
838+
static int write_midx_bitmap(struct write_midx_context *ctx,
839+
const char *object_dir,
833840
const unsigned char *midx_hash,
834841
struct packing_data *pdata,
835842
struct commit **commits,
836843
uint32_t commits_nr,
837-
uint32_t *pack_order,
838844
unsigned flags)
839845
{
840846
int ret, i;
841847
uint16_t options = 0;
842848
struct bitmap_writer writer;
843849
struct pack_idx_entry **index;
844-
char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name,
845-
hash_to_hex_algop(midx_hash, r->hash_algo));
850+
struct strbuf bitmap_name = STRBUF_INIT;
851+
852+
trace2_region_enter("midx", "write_midx_bitmap", ctx->repo);
846853

847-
trace2_region_enter("midx", "write_midx_bitmap", r);
854+
if (ctx->incremental)
855+
get_split_midx_filename_ext(ctx->repo->hash_algo, &bitmap_name,
856+
object_dir, midx_hash,
857+
MIDX_EXT_BITMAP);
858+
else
859+
get_midx_filename_ext(ctx->repo->hash_algo, &bitmap_name,
860+
object_dir, midx_hash, MIDX_EXT_BITMAP);
848861

849862
if (flags & MIDX_WRITE_BITMAP_HASH_CACHE)
850863
options |= BITMAP_OPT_HASH_CACHE;
@@ -861,7 +874,8 @@ static int write_midx_bitmap(struct repository *r, const char *midx_name,
861874
for (i = 0; i < pdata->nr_objects; i++)
862875
index[i] = &pdata->objects[i].idx;
863876

864-
bitmap_writer_init(&writer, r, pdata);
877+
bitmap_writer_init(&writer, ctx->repo, pdata,
878+
ctx->incremental ? ctx->base_midx : NULL);
865879
bitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS);
866880
bitmap_writer_build_type_index(&writer, index);
867881

@@ -879,22 +893,22 @@ static int write_midx_bitmap(struct repository *r, const char *midx_name,
879893
* bitmap_writer_finish().
880894
*/
881895
for (i = 0; i < pdata->nr_objects; i++)
882-
index[pack_order[i]] = &pdata->objects[i].idx;
896+
index[ctx->pack_order[i]] = &pdata->objects[i].idx;
883897

884898
bitmap_writer_select_commits(&writer, commits, commits_nr);
885899
ret = bitmap_writer_build(&writer);
886900
if (ret < 0)
887901
goto cleanup;
888902

889903
bitmap_writer_set_checksum(&writer, midx_hash);
890-
bitmap_writer_finish(&writer, index, bitmap_name, options);
904+
bitmap_writer_finish(&writer, index, bitmap_name.buf, options);
891905

892906
cleanup:
893907
free(index);
894-
free(bitmap_name);
908+
strbuf_release(&bitmap_name);
895909
bitmap_writer_free(&writer);
896910

897-
trace2_region_leave("midx", "write_midx_bitmap", r);
911+
trace2_region_leave("midx", "write_midx_bitmap", ctx->repo);
898912

899913
return ret;
900914
}
@@ -1077,8 +1091,6 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
10771091
ctx.repo = r;
10781092

10791093
ctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL);
1080-
if (ctx.incremental && (flags & MIDX_WRITE_BITMAP))
1081-
die(_("cannot write incremental MIDX with bitmap"));
10821094

10831095
if (ctx.incremental)
10841096
strbuf_addf(&midx_name,
@@ -1119,6 +1131,13 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
11191131
if (ctx.incremental) {
11201132
struct multi_pack_index *m = ctx.base_midx;
11211133
while (m) {
1134+
if (flags & MIDX_WRITE_BITMAP && load_midx_revindex(m)) {
1135+
error(_("could not load reverse index for MIDX %s"),
1136+
hash_to_hex_algop(get_midx_checksum(m),
1137+
m->repo->hash_algo));
1138+
result = 1;
1139+
goto cleanup;
1140+
}
11221141
ctx.num_multi_pack_indexes_before++;
11231142
m = m->base_midx;
11241143
}
@@ -1389,7 +1408,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
13891408

13901409
if (flags & MIDX_WRITE_REV_INDEX &&
13911410
git_env_bool("GIT_TEST_MIDX_WRITE_REV", 0))
1392-
write_midx_reverse_index(midx_name.buf, midx_hash, &ctx);
1411+
write_midx_reverse_index(&ctx, object_dir, midx_hash);
13931412

13941413
if (flags & MIDX_WRITE_BITMAP) {
13951414
struct packing_data pdata;
@@ -1412,8 +1431,8 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
14121431
FREE_AND_NULL(ctx.entries);
14131432
ctx.entries_nr = 0;
14141433

1415-
if (write_midx_bitmap(r, midx_name.buf, midx_hash, &pdata,
1416-
commits, commits_nr, ctx.pack_order,
1434+
if (write_midx_bitmap(&ctx, object_dir,
1435+
midx_hash, &pdata, commits, commits_nr,
14171436
flags) < 0) {
14181437
error(_("could not write multi-pack bitmap"));
14191438
result = 1;

0 commit comments

Comments
 (0)