Skip to content

Commit cd8d2c4

Browse files
committed
Merge branch 'tb/incremental-midx-part-2' into ps/cat-file-filter-batch
* 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 Documentation: remove a "future work" item from the MIDX docs
2 parents 683c54c + 27afc27 commit cd8d2c4

File tree

10 files changed

+589
-132
lines changed

10 files changed

+589
-132
lines changed

Documentation/technical/multi-pack-index.adoc

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,81 @@ 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` sorts ahead of `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 ahead of
191+
the non-preferred one. If there is a base layer (i.e. the MIDX layer
192+
is not the first layer in the chain), then if `pack(o1)` appears
193+
earlier in that MIDX layer's pack order, then `o1` sorts ahead of
194+
`o2`. Likewise if `pack(o2)` appears earlier, then the opposite is
195+
true.
196+
197+
3. Otherwise, `o1` and `o2` appear in the same pack, and thus in the
198+
same MIDX layer. Sort `o1` and `o2` by their offset within their
199+
containing packfile.
200+
201+
Note that the preferred pack is a property of the MIDX chain, not the
202+
individual layers themselves. Fundamentally we could introduce a
203+
per-layer preferred pack, but this is less relevant now that we can
204+
perform multi-pack reuse across the set of packs in a MIDX.
205+
206+
=== Reachability bitmaps and incremental MIDXs
207+
208+
Each layer of an incremental MIDX chain may have its objects (and the
209+
objects from any previous layer in the same MIDX chain) represented in
210+
its own `*.bitmap` file.
211+
212+
The structure of a `*.bitmap` file belonging to an incremental MIDX
213+
chain is identical to that of a non-incremental MIDX bitmap, or a
214+
classic single-pack bitmap. Since objects are added to the end of the
215+
incremental MIDX's pseudo-pack order (see above), it is possible to
216+
extend a bitmap when appending to the end of a MIDX chain.
217+
218+
(Note: it is possible likewise to compress a contiguous sequence of MIDX
219+
incremental layers, and their `*.bitmap` files into a single layer and
220+
`*.bitmap`, but this is not yet implemented.)
221+
222+
The object positions used are global within the pseudo-pack order, so
223+
subsequent layers will have, for example, `m->num_objects_in_base`
224+
number of `0` bits in each of their four type bitmaps. This follows from
225+
the fact that we only write type bitmap entries for objects present in
226+
the layer immediately corresponding to the bitmap).
227+
228+
Note also that only the bitmap pertaining to the most recent layer in an
229+
incremental MIDX chain is used to store reachability information about
230+
the interesting and uninteresting objects in a reachability query.
231+
Earlier bitmap layers are only used to look up commit and pseudo-merge
232+
bitmaps from that layer, as well as the type-level bitmaps for objects
233+
in that layer.
234+
235+
To simplify the implementation, type-level bitmaps are iterated
236+
simultaneously, and their results are OR'd together to avoid recursively
237+
calling internal bitmap functions.
238+
167239
Future Work
168240
-----------
169241
170-
- The multi-pack-index allows many packfiles, especially in a context
171-
where repacking is expensive (such as a very large repo), or
172-
unexpected maintenance time is unacceptable (such as a high-demand
173-
build machine). However, the multi-pack-index needs to be rewritten
174-
in full every time. We can extend the format to be incremental, so
175-
writes are fast. By storing a small "tip" multi-pack-index that
176-
points to large "base" MIDX files, we can keep writes fast while
177-
still reducing the number of binary searches required for object
178-
lookups.
179-
180242
- If the multi-pack-index is extended to store a "stable object order"
181243
(a function Order(hash) = integer that is constant for a given hash,
182244
even as the multi-pack-index is updated) then MIDX bitmaps could be

builtin/pack-objects.c

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

13981398
if (write_bitmap_index) {
13991399
bitmap_writer_init(&bitmap_writer,
1400-
the_repository, &to_pack);
1400+
the_repository, &to_pack,
1401+
NULL);
14011402
bitmap_writer_set_checksum(&bitmap_writer, hash);
14021403
bitmap_writer_build_type_index(&bitmap_writer,
14031404
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->hash_algo, 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
}
@@ -1387,7 +1406,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
13871406

13881407
if (flags & MIDX_WRITE_REV_INDEX &&
13891408
git_env_bool("GIT_TEST_MIDX_WRITE_REV", 0))
1390-
write_midx_reverse_index(midx_name.buf, midx_hash, &ctx);
1409+
write_midx_reverse_index(&ctx, object_dir, midx_hash);
13911410

13921411
if (flags & MIDX_WRITE_BITMAP) {
13931412
struct packing_data pdata;
@@ -1410,8 +1429,8 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
14101429
FREE_AND_NULL(ctx.entries);
14111430
ctx.entries_nr = 0;
14121431

1413-
if (write_midx_bitmap(r, midx_name.buf, midx_hash, &pdata,
1414-
commits, commits_nr, ctx.pack_order,
1432+
if (write_midx_bitmap(&ctx, object_dir,
1433+
midx_hash, &pdata, commits, commits_nr,
14151434
flags) < 0) {
14161435
error(_("could not write multi-pack bitmap"));
14171436
result = 1;

0 commit comments

Comments
 (0)