Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2022-05-18 22:46:11 +0300
committerJohn Cai <jcai@gitlab.com>2022-06-15 19:32:12 +0300
commit3c68f28df307b2d417ec361fba947f2d5f03a380 (patch)
tree87e066c9eec822a398f23ecc35f8cc8990f9e723
parent7daa134a9c206ec381c271c5004a48d2ae4849ff (diff)
If a command's repo is nil, handle it gracefully by adding the command to a cgroup by using the command arguments as a key for the circular hash. While we're at it, fix a test that was doing the checksum incorrectly. This didn't make a difference in the test however, because we were using the groupID we calculated ourselves to check for the location of the cgroup file. Changelog: fixed
-rw-r--r--internal/cgroups/v1_linux.go10
-rw-r--r--internal/cgroups/v1_linux_test.go47
2 files changed, 44 insertions, 13 deletions
diff --git a/internal/cgroups/v1_linux.go b/internal/cgroups/v1_linux.go
index 49802bcb8..3e37c6205 100644
--- a/internal/cgroups/v1_linux.go
+++ b/internal/cgroups/v1_linux.go
@@ -103,9 +103,17 @@ func (cg *CGroupV1Manager) AddCommand(
cmd *command.Command,
repo repository.GitRepo,
) error {
+ var key string
+ if repo == nil {
+ key = strings.Join(cmd.Args(), "/")
+ } else {
+ key = repo.GetStorageName() + "/" + repo.GetRelativePath()
+ }
+
checksum := crc32.ChecksumIEEE(
- []byte(repo.GetStorageName() + "/" + repo.GetRelativePath()),
+ []byte(key),
)
+
groupID := uint(checksum) % cg.cfg.Repositories.Count
cgroupPath := cg.repoPath(int(groupID))
diff --git a/internal/cgroups/v1_linux_test.go b/internal/cgroups/v1_linux_test.go
index 347973374..03a498a11 100644
--- a/internal/cgroups/v1_linux_test.go
+++ b/internal/cgroups/v1_linux_test.go
@@ -69,7 +69,7 @@ func TestAddCommand(t *testing.T) {
}
config := defaultCgroupsConfig()
- config.Repositories.Count = 1
+ config.Repositories.Count = 10
config.Repositories.MemoryBytes = 1024
config.Repositories.CPUShares = 16
@@ -90,21 +90,44 @@ func TestAddCommand(t *testing.T) {
hierarchy: mock.hierarchy,
}
- require.NoError(t, v1Manager2.AddCommand(cmd2, repo))
+ t.Run("without a repository", func(t *testing.T) {
+ require.NoError(t, v1Manager2.AddCommand(cmd2, nil))
- checksum := crc32.ChecksumIEEE([]byte(strings.Join([]string{"default", "path/to/repo.git"}, "")))
- groupID := uint(checksum) % config.Repositories.Count
+ checksum := crc32.ChecksumIEEE([]byte(strings.Join(cmd2.Args(), "/")))
+ groupID := uint(checksum) % config.Repositories.Count
- for _, s := range mock.subsystems {
- path := filepath.Join(mock.root, string(s.Name()), "gitaly",
- fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("repos-%d", groupID), "cgroup.procs")
- content := readCgroupFile(t, path)
+ for _, s := range mock.subsystems {
+ path := filepath.Join(mock.root, string(s.Name()), "gitaly",
+ fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("repos-%d", groupID), "cgroup.procs")
+ content := readCgroupFile(t, path)
- pid, err := strconv.Atoi(string(content))
- require.NoError(t, err)
+ pid, err := strconv.Atoi(string(content))
+ require.NoError(t, err)
- require.Equal(t, cmd2.Pid(), pid)
- }
+ require.Equal(t, cmd2.Pid(), pid)
+ }
+ })
+
+ t.Run("with a repository", func(t *testing.T) {
+ require.NoError(t, v1Manager2.AddCommand(cmd2, repo))
+
+ checksum := crc32.ChecksumIEEE([]byte(strings.Join([]string{
+ "default",
+ "path/to/repo.git",
+ }, "/")))
+ groupID := uint(checksum) % config.Repositories.Count
+
+ for _, s := range mock.subsystems {
+ path := filepath.Join(mock.root, string(s.Name()), "gitaly",
+ fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("repos-%d", groupID), "cgroup.procs")
+ content := readCgroupFile(t, path)
+
+ pid, err := strconv.Atoi(string(content))
+ require.NoError(t, err)
+
+ require.Equal(t, cmd2.Pid(), pid)
+ }
+ })
}
func TestCleanup(t *testing.T) {