@matheusbsbs / matheus-bagliano / commits / e841a79a13
Fork 0

maintenance: add incremental-repack auto condition

The incremental-repack task updates the multi-pack-index by deleting pack- files that have been replaced with new packs, then repacking a batch of small pack-files into a larger pack-file. This incremental repack is faster than rewriting all object data, but is slower than some other maintenance activities. The 'maintenance.incremental-repack.auto' config option specifies how many pack-files should exist outside of the multi-pack-index before running the step. These pack-files could be created by 'git fetch' commands or by the loose-objects task. The default value is 10. Setting the option to zero disables the task with the '--auto' option, and a negative value makes the task run every time. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Sep 25, 2020 at 12:33 UTC e841a79a131d8ce491cf04d0ca3e24f139a10b82
3 files changed +68
Documentation/config/maintenance.txt
+9
@@ -23,3 +23,12 @@ maintenance.loose-objects.auto::
23 positive value implies the command should run when the number of
24 loose objects is at least the value of `maintenance.loose-objects.auto`.
25 The default value is 100.
26 +
27 +maintenance.incremental-repack.auto::
28 + This integer config option controls how often the `incremental-repack`
29 + task should be run as part of `git maintenance run --auto`. If zero,
30 + then the `incremental-repack` task will not run with the `--auto`
31 + option. A negative value will force the task to run every time.
32 + Otherwise, a positive value implies the command should run when the
33 + number of pack-files not in the multi-pack-index is at least the value
34 + of `maintenance.incremental-repack.auto`. The default value is 10.
builtin/gc.c
+31
@@ -30,6 +30,7 @@
30 #include "promisor-remote.h"
31 #include "refs.h"
32 #include "remote.h"
33 +#include "object-store.h"
34
35 #define FAILED_RUN "failed to run %s"
36
@@ -1001,6 +1002,35 @@ static int maintenance_task_loose_objects(struct maintenance_run_opts *opts)
1002 return prune_packed(opts) || pack_loose(opts);
1003 }
1004
1005 +static int incremental_repack_auto_condition(void)
1006 +{
1007 + struct packed_git *p;
1008 + int enabled;
1009 + int incremental_repack_auto_limit = 10;
1010 + int count = 0;
1011 +
1012 + if (git_config_get_bool("core.multiPackIndex", &enabled) ||
1013 + !enabled)
1014 + return 0;
1015 +
1016 + git_config_get_int("maintenance.incremental-repack.auto",
1017 + &incremental_repack_auto_limit);
1018 +
1019 + if (!incremental_repack_auto_limit)
1020 + return 0;
1021 + if (incremental_repack_auto_limit < 0)
1022 + return 1;
1023 +
1024 + for (p = get_packed_git(the_repository);
1025 + count < incremental_repack_auto_limit && p;
1026 + p = p->next) {
1027 + if (!p->multi_pack_index)
1028 + count++;
1029 + }
1030 +
1031 + return count >= incremental_repack_auto_limit;
1032 +}
1033 +
1034 static int multi_pack_index_write(struct maintenance_run_opts *opts)
1035 {
1036 struct child_process child = CHILD_PROCESS_INIT;
@@ -1156,6 +1186,7 @@ static struct maintenance_task tasks[] = {
1186 [TASK_INCREMENTAL_REPACK] = {
1187 "incremental-repack",
1188 maintenance_task_incremental_repack,
1189 + incremental_repack_auto_condition,
1190 },
1191 [TASK_GC] = {
1192 "gc",
t/t7900-maintenance.sh
+28
@@ -219,4 +219,32 @@ test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
219 --no-progress --batch-size=2147483647 <run-2g.txt
220 '
221
222 +test_expect_success 'maintenance.incremental-repack.auto' '
223 + git repack -adk &&
224 + git config core.multiPackIndex true &&
225 + git multi-pack-index write &&
226 + GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \
227 + -c maintenance.incremental-repack.auto=1 \
228 + maintenance run --auto --task=incremental-repack 2>/dev/null &&
229 + test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt &&
230 + test_commit A &&
231 + git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
232 + HEAD
233 + ^HEAD~1
234 + EOF
235 + GIT_TRACE2_EVENT=$(pwd)/trace-A git \
236 + -c maintenance.incremental-repack.auto=2 \
237 + maintenance run --auto --task=incremental-repack 2>/dev/null &&
238 + test_subcommand ! git multi-pack-index write --no-progress <trace-A &&
239 + test_commit B &&
240 + git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
241 + HEAD
242 + ^HEAD~1
243 + EOF
244 + GIT_TRACE2_EVENT=$(pwd)/trace-B git \
245 + -c maintenance.incremental-repack.auto=2 \
246 + maintenance run --auto --task=incremental-repack 2>/dev/null &&
247 + test_subcommand git multi-pack-index write --no-progress <trace-B
248 +'
249 +
250 test_done