Skip to content

Commit 9a6bfee

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 96e3d2c + 668e8c8 commit 9a6bfee

File tree

10 files changed

+577
-124
lines changed

10 files changed

+577
-124
lines changed

Documentation/technical/multi-pack-index.adoc

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
@@ -1398,7 +1398,8 @@ static void write_pack_file(void)
13981398

13991399
if (write_bitmap_index) {
14001400
bitmap_writer_init(&bitmap_writer,
1401-
the_repository, &to_pack);
1401+
the_repository, &to_pack,
1402+
NULL);
14021403
bitmap_writer_set_checksum(&bitmap_writer, hash);
14031404
bitmap_writer_build_type_index(&bitmap_writer,
14041405
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_free(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_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: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -647,16 +647,23 @@ 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,
661+
&buf, object_dir, midx_hash,
662+
MIDX_EXT_REV);
663+
else
664+
get_midx_filename_ext(ctx->repo->hash_algo,
665+
&buf, object_dir, midx_hash,
666+
MIDX_EXT_REV);
660667

661668
tmp_file = write_rev_file_order(ctx->repo->hash_algo, NULL, ctx->pack_order,
662669
ctx->entries_nr, midx_hash, WRITE_REV);
@@ -829,22 +836,30 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr
829836
return cb.commits;
830837
}
831838

832-
static int write_midx_bitmap(struct repository *r, const char *midx_name,
839+
static int write_midx_bitmap(struct write_midx_context *ctx,
840+
const char *object_dir,
833841
const unsigned char *midx_hash,
834842
struct packing_data *pdata,
835843
struct commit **commits,
836844
uint32_t commits_nr,
837-
uint32_t *pack_order,
838845
unsigned flags)
839846
{
840847
int ret, i;
841848
uint16_t options = 0;
842849
struct bitmap_writer writer;
843850
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));
851+
struct strbuf bitmap_name = STRBUF_INIT;
852+
853+
if (ctx->incremental)
854+
get_split_midx_filename_ext(ctx->repo->hash_algo,
855+
&bitmap_name, object_dir, midx_hash,
856+
MIDX_EXT_BITMAP);
857+
else
858+
get_midx_filename_ext(ctx->repo->hash_algo,
859+
&bitmap_name, object_dir, midx_hash,
860+
MIDX_EXT_BITMAP);
846861

847-
trace2_region_enter("midx", "write_midx_bitmap", r);
862+
trace2_region_enter("midx", "write_midx_bitmap", ctx->repo);
848863

849864
if (flags & MIDX_WRITE_BITMAP_HASH_CACHE)
850865
options |= BITMAP_OPT_HASH_CACHE;
@@ -861,7 +876,8 @@ static int write_midx_bitmap(struct repository *r, const char *midx_name,
861876
for (i = 0; i < pdata->nr_objects; i++)
862877
index[i] = &pdata->objects[i].idx;
863878

864-
bitmap_writer_init(&writer, r, pdata);
879+
bitmap_writer_init(&writer, ctx->repo, pdata,
880+
ctx->incremental ? ctx->base_midx : NULL);
865881
bitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS);
866882
bitmap_writer_build_type_index(&writer, index);
867883

@@ -879,22 +895,22 @@ static int write_midx_bitmap(struct repository *r, const char *midx_name,
879895
* bitmap_writer_finish().
880896
*/
881897
for (i = 0; i < pdata->nr_objects; i++)
882-
index[pack_order[i]] = &pdata->objects[i].idx;
898+
index[ctx->pack_order[i]] = &pdata->objects[i].idx;
883899

884900
bitmap_writer_select_commits(&writer, commits, commits_nr);
885901
ret = bitmap_writer_build(&writer);
886902
if (ret < 0)
887903
goto cleanup;
888904

889905
bitmap_writer_set_checksum(&writer, midx_hash);
890-
bitmap_writer_finish(&writer, index, bitmap_name, options);
906+
bitmap_writer_finish(&writer, index, bitmap_name.buf, options);
891907

892908
cleanup:
893909
free(index);
894-
free(bitmap_name);
910+
strbuf_release(&bitmap_name);
895911
bitmap_writer_free(&writer);
896912

897-
trace2_region_leave("midx", "write_midx_bitmap", r);
913+
trace2_region_leave("midx", "write_midx_bitmap", ctx->repo);
898914

899915
return ret;
900916
}
@@ -1077,8 +1093,6 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
10771093
ctx.repo = r;
10781094

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

10831097
if (ctx.incremental)
10841098
strbuf_addf(&midx_name,
@@ -1119,6 +1133,13 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
11191133
if (ctx.incremental) {
11201134
struct multi_pack_index *m = ctx.base_midx;
11211135
while (m) {
1136+
if (flags & MIDX_WRITE_BITMAP && load_midx_revindex(m)) {
1137+
error(_("could not load reverse index for MIDX %s"),
1138+
hash_to_hex_algop(get_midx_checksum(m),
1139+
r->hash_algo));
1140+
result = 1;
1141+
goto cleanup;
1142+
}
11221143
ctx.num_multi_pack_indexes_before++;
11231144
m = m->base_midx;
11241145
}
@@ -1387,7 +1408,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
13871408

13881409
if (flags & MIDX_WRITE_REV_INDEX &&
13891410
git_env_bool("GIT_TEST_MIDX_WRITE_REV", 0))
1390-
write_midx_reverse_index(midx_name.buf, midx_hash, &ctx);
1411+
write_midx_reverse_index(&ctx, object_dir, midx_hash);
13911412

13921413
if (flags & MIDX_WRITE_BITMAP) {
13931414
struct packing_data pdata;
@@ -1410,8 +1431,8 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
14101431
FREE_AND_NULL(ctx.entries);
14111432
ctx.entries_nr = 0;
14121433

1413-
if (write_midx_bitmap(r, midx_name.buf, midx_hash, &pdata,
1414-
commits, commits_nr, ctx.pack_order,
1434+
if (write_midx_bitmap(&ctx, object_dir,
1435+
midx_hash, &pdata, commits, commits_nr,
14151436
flags) < 0) {
14161437
error(_("could not write multi-pack bitmap"));
14171438
result = 1;

0 commit comments

Comments
 (0)