When a multi-pack bitmap is used to implement verbatim pack reuse (that is, when verbatim chunks from an on-disk packfile are copied directly[^1]), it does so by using its "preferred pack" as the source for pack-reuse. This allows repositories to pack the majority of their objects into a single (often large) pack, and then use it as the single source for verbatim pack reuse. This increases the amount of objects that are reused verbatim (and consequently, decrease the amount of time it takes to generate many packs). But this performance comes at a cost, which is that the preferred packfile must pace its growth with that of the entire repository in order to maintain the utility of verbatim pack reuse. As repositories grow beyond what we can reasonably store in a single packfile, the utility of verbatim pack reuse diminishes. Or, at the very least, it becomes increasingly more expensive to maintain as the pack grows larger and larger. It would be beneficial to be able to perform this same optimization over multiple packs, provided some modest constraints (most importantly, that the set of packs eligible for verbatim reuse are disjoint with respect to the subset of their objects being sent). If we assume that the packs which we treat as candidates for verbatim reuse are disjoint with respect to any of their objects we may output, we need to make only modest modifications to the verbatim pack-reuse code itself. Most notably, we need to remove the assumption that the bits in the reachability bitmap corresponding to objects from the single reuse pack begin at the first bit position. Future patches will unwind these assumptions and reimplement their existing functionality as special cases of the more general assumptions (e.g. that reuse bits can start anywhere within the bitset, but happen to start at 0 for all existing cases). This patch does not yet relax any of those assumptions. Instead, it implements a foundational data-structure, the "Bitampped Packs" (`BTMP`) chunk of the multi-pack index. The `BTMP` chunk's contents are described in detail here. Importantly, the `BTMP` chunk contains information to map regions of a multi-pack index's reachability bitmap to the packs whose objects they represent. For now, this chunk is only written, not read (outside of the test-tool used in this patch to test the new chunk's behavior). Future patches will begin to make use of this new chunk. [^1]: Modulo patching any `OFS_DELTA`'s that cross over a region of the pack that wasn't used verbatim. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
144 lines
3.1 KiB
C
144 lines
3.1 KiB
C
#include "test-tool.h"
|
|
#include "hex.h"
|
|
#include "midx.h"
|
|
#include "repository.h"
|
|
#include "object-store-ll.h"
|
|
#include "pack-bitmap.h"
|
|
#include "packfile.h"
|
|
#include "setup.h"
|
|
|
|
static int read_midx_file(const char *object_dir, int show_objects)
|
|
{
|
|
uint32_t i;
|
|
struct multi_pack_index *m;
|
|
|
|
setup_git_directory();
|
|
m = load_multi_pack_index(object_dir, 1);
|
|
|
|
if (!m)
|
|
return 1;
|
|
|
|
printf("header: %08x %d %d %d %d\n",
|
|
m->signature,
|
|
m->version,
|
|
m->hash_len,
|
|
m->num_chunks,
|
|
m->num_packs);
|
|
|
|
printf("chunks:");
|
|
|
|
if (m->chunk_pack_names)
|
|
printf(" pack-names");
|
|
if (m->chunk_oid_fanout)
|
|
printf(" oid-fanout");
|
|
if (m->chunk_oid_lookup)
|
|
printf(" oid-lookup");
|
|
if (m->chunk_object_offsets)
|
|
printf(" object-offsets");
|
|
if (m->chunk_large_offsets)
|
|
printf(" large-offsets");
|
|
|
|
printf("\nnum_objects: %d\n", m->num_objects);
|
|
|
|
printf("packs:\n");
|
|
for (i = 0; i < m->num_packs; i++)
|
|
printf("%s\n", m->pack_names[i]);
|
|
|
|
printf("object-dir: %s\n", m->object_dir);
|
|
|
|
if (show_objects) {
|
|
struct object_id oid;
|
|
struct pack_entry e;
|
|
|
|
for (i = 0; i < m->num_objects; i++) {
|
|
nth_midxed_object_oid(&oid, m, i);
|
|
fill_midx_entry(the_repository, &oid, &e, m);
|
|
|
|
printf("%s %"PRIu64"\t%s\n",
|
|
oid_to_hex(&oid), e.offset, e.p->pack_name);
|
|
}
|
|
}
|
|
|
|
close_midx(m);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int read_midx_checksum(const char *object_dir)
|
|
{
|
|
struct multi_pack_index *m;
|
|
|
|
setup_git_directory();
|
|
m = load_multi_pack_index(object_dir, 1);
|
|
if (!m)
|
|
return 1;
|
|
printf("%s\n", hash_to_hex(get_midx_checksum(m)));
|
|
return 0;
|
|
}
|
|
|
|
static int read_midx_preferred_pack(const char *object_dir)
|
|
{
|
|
struct multi_pack_index *midx = NULL;
|
|
struct bitmap_index *bitmap = NULL;
|
|
|
|
setup_git_directory();
|
|
|
|
midx = load_multi_pack_index(object_dir, 1);
|
|
if (!midx)
|
|
return 1;
|
|
|
|
bitmap = prepare_bitmap_git(the_repository);
|
|
if (!bitmap)
|
|
return 1;
|
|
if (!bitmap_is_midx(bitmap)) {
|
|
free_bitmap_index(bitmap);
|
|
return 1;
|
|
}
|
|
|
|
printf("%s\n", midx->pack_names[midx_preferred_pack(bitmap)]);
|
|
free_bitmap_index(bitmap);
|
|
return 0;
|
|
}
|
|
|
|
static int read_midx_bitmapped_packs(const char *object_dir)
|
|
{
|
|
struct multi_pack_index *midx = NULL;
|
|
struct bitmapped_pack pack;
|
|
uint32_t i;
|
|
|
|
setup_git_directory();
|
|
|
|
midx = load_multi_pack_index(object_dir, 1);
|
|
if (!midx)
|
|
return 1;
|
|
|
|
for (i = 0; i < midx->num_packs; i++) {
|
|
if (nth_bitmapped_pack(the_repository, midx, &pack, i) < 0)
|
|
return 1;
|
|
|
|
printf("%s\n", pack_basename(pack.p));
|
|
printf(" bitmap_pos: %"PRIuMAX"\n", (uintmax_t)pack.bitmap_pos);
|
|
printf(" bitmap_nr: %"PRIuMAX"\n", (uintmax_t)pack.bitmap_nr);
|
|
}
|
|
|
|
close_midx(midx);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int cmd__read_midx(int argc, const char **argv)
|
|
{
|
|
if (!(argc == 2 || argc == 3))
|
|
usage("read-midx [--show-objects|--checksum|--preferred-pack|--bitmap] <object-dir>");
|
|
|
|
if (!strcmp(argv[1], "--show-objects"))
|
|
return read_midx_file(argv[2], 1);
|
|
else if (!strcmp(argv[1], "--checksum"))
|
|
return read_midx_checksum(argv[2]);
|
|
else if (!strcmp(argv[1], "--preferred-pack"))
|
|
return read_midx_preferred_pack(argv[2]);
|
|
else if (!strcmp(argv[1], "--bitmap"))
|
|
return read_midx_bitmapped_packs(argv[2]);
|
|
return read_midx_file(argv[1], 0);
|
|
}
|