diff --git a/internal/git/gitcmd/command_description.go b/internal/git/gitcmd/command_description.go index e3384e98c405d42f07470415aa44cff047d17074..1473d4deff1ebd2a5c644a49447137ccbc7c95a4 100644 --- a/internal/git/gitcmd/command_description.go +++ b/internal/git/gitcmd/command_description.go @@ -8,6 +8,7 @@ import ( "strings" "gitlab.com/gitlab-org/gitaly/v16/internal/git" + "gitlab.com/gitlab-org/gitaly/v16/internal/helper/env" "gitlab.com/gitlab-org/gitaly/v16/internal/structerr" ) @@ -529,11 +530,19 @@ func templateFsckConfiguration(_ context.Context, prefix string) []GlobalOption } func packConfiguration(context.Context) []GlobalOption { - return []GlobalOption{ + opts := []GlobalOption{ ConfigPair{Key: "pack.windowMemory", Value: "100m"}, ConfigPair{Key: "pack.writeReverseIndex", Value: "true"}, ConfigPair{Key: "pack.threads", Value: threadsConfigValue(runtime.NumCPU())}, } + + // Experimental configuration for https://gitlab.com/gitlab-org/charts/gitlab/-/issues/5795 + // To documented properly at a later stage. + if packedGitLimit := env.GetString("GITALY_PACKED_GIT_LIMIT", ""); packedGitLimit != "" { + opts = append(opts, ConfigPair{Key: "core.packedGitLimit", Value: packedGitLimit}) + } + + return opts } // threadsConfigValue returns the log-2 number of threads based on the number of provided CPUs. This diff --git a/internal/git/gitcmd/command_description_test.go b/internal/git/gitcmd/command_description_test.go index 686701eda4bea40a866f292cdfea10f6ad5bf664..fe303f9fe46e53385461d301f2ae4ac3779ee512 100644 --- a/internal/git/gitcmd/command_description_test.go +++ b/internal/git/gitcmd/command_description_test.go @@ -2,6 +2,7 @@ package gitcmd import ( "fmt" + "runtime" "testing" "github.com/stretchr/testify/require" @@ -148,3 +149,43 @@ func TestFsckConfiguration_prefix(t *testing.T) { }) } } + +func TestPackConfiguration(t *testing.T) { + ctx := testhelper.Context(t) + + for _, tc := range []struct { + name string + env map[string]string + expected []ConfigPair + }{ + { + name: "with GITALY_PACKED_GIT_LIMIT", + env: map[string]string{ + "GITALY_PACKED_GIT_LIMIT": "1g", + }, + expected: []ConfigPair{ + {Key: "pack.windowMemory", Value: "100m"}, + {Key: "pack.writeReverseIndex", Value: "true"}, + {Key: "pack.threads", Value: threadsConfigValue(runtime.NumCPU())}, + {Key: "core.packedGitLimit", Value: "1g"}, + }, + }, + { + name: "without GITALY_PACKED_GIT_LIMIT", + expected: []ConfigPair{ + {Key: "pack.windowMemory", Value: "100m"}, + {Key: "pack.writeReverseIndex", Value: "true"}, + {Key: "pack.threads", Value: threadsConfigValue(runtime.NumCPU())}, + }, + }, + } { + t.Run(tc.name, func(t *testing.T) { + for k, v := range tc.env { + t.Setenv(k, v) + } + + opts := packConfiguration(ctx) + require.ElementsMatch(t, tc.expected, opts) + }) + } +}