diff options
author | Ahmad Sherif <me@ahmadsherif.com> | 2020-12-11 20:31:47 +0300 |
---|---|---|
committer | Ahmad Sherif <me@ahmadsherif.com> | 2020-12-14 16:59:46 +0300 |
commit | f78ba65051c1744332cb73422431ff871ef2a6b3 (patch) | |
tree | 951b0f51c78d51e1a8bf238565c351560b417d5f /internal/cgroups | |
parent | d902bf04434196af8a4a4b00b3420e9a2868e7fb (diff) |
Fix missing cgroups after upgrading Gitaly
Diffstat (limited to 'internal/cgroups')
-rw-r--r-- | internal/cgroups/v1_linux.go | 30 | ||||
-rw-r--r-- | internal/cgroups/v1_linux_test.go | 10 |
2 files changed, 17 insertions, 23 deletions
diff --git a/internal/cgroups/v1_linux.go b/internal/cgroups/v1_linux.go index 436b4d97a..6c41a8d7f 100644 --- a/internal/cgroups/v1_linux.go +++ b/internal/cgroups/v1_linux.go @@ -3,6 +3,7 @@ package cgroups import ( "fmt" "hash/crc32" + "os" "strings" "github.com/containerd/cgroups" @@ -74,33 +75,26 @@ func (cg *CGroupV1Manager) AddCommand(cmd *command.Command) error { } func (cg *CGroupV1Manager) Cleanup() error { - var failures []string + processCgroupPath := cg.currentProcessCgroup() - for i := 0; i < int(cg.cfg.Count); i++ { - cgroupPath := cg.cgroupPath(i) - control, err := cgroups.Load(cg.hierarchy, cgroups.StaticPath(cgroupPath)) - if err != nil { - failure := fmt.Sprintf("%s: %v", cgroupPath, err) - failures = append(failures, failure) - continue - } - - if err := control.Delete(); err != nil { - failure := fmt.Sprintf("%s: %v", cgroupPath, err) - failures = append(failures, failure) - continue - } + control, err := cgroups.Load(cg.hierarchy, cgroups.StaticPath(processCgroupPath)) + if err != nil { + return fmt.Errorf("failed loading cgroup %s: %w", processCgroupPath, err) } - if len(failures) > 0 { - return fmt.Errorf("failed cleaning up cgroups: %s", strings.Join(failures, ",")) + if err := control.Delete(); err != nil { + return fmt.Errorf("failed cleaning up cgroup %s: %w", processCgroupPath, err) } return nil } func (cg *CGroupV1Manager) cgroupPath(groupID int) string { - return fmt.Sprintf("/%s/gitaly-%d", cg.cfg.HierarchyRoot, groupID) + return fmt.Sprintf("/%s/shard-%d", cg.currentProcessCgroup(), groupID) +} + +func (cg *CGroupV1Manager) currentProcessCgroup() string { + return fmt.Sprintf("/%s/gitaly-%d", cg.cfg.HierarchyRoot, os.Getpid()) } func defaultSubsystems(root string) ([]cgroups.Subsystem, error) { diff --git a/internal/cgroups/v1_linux_test.go b/internal/cgroups/v1_linux_test.go index da0039a2b..c2bbd04bd 100644 --- a/internal/cgroups/v1_linux_test.go +++ b/internal/cgroups/v1_linux_test.go @@ -44,14 +44,14 @@ func TestSetup(t *testing.T) { for i := 0; i < 3; i++ { memoryPath := filepath.Join( - mock.root, "memory", "gitaly", fmt.Sprintf("gitaly-%d", i), "memory.limit_in_bytes", + mock.root, "memory", "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("shard-%d", i), "memory.limit_in_bytes", ) memoryContent := readCgroupFile(t, memoryPath) require.Equal(t, string(memoryContent), "1024000") cpuPath := filepath.Join( - mock.root, "cpu", "gitaly", fmt.Sprintf("gitaly-%d", i), "cpu.shares", + mock.root, "cpu", "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("shard-%d", i), "cpu.shares", ) cpuContent := readCgroupFile(t, cpuPath) @@ -88,7 +88,7 @@ func TestAddCommand(t *testing.T) { groupID := uint(checksum) % config.Count for _, s := range mock.subsystems { - path := filepath.Join(mock.root, string(s.Name()), "gitaly", fmt.Sprintf("gitaly-%d", groupID), "cgroup.procs") + path := filepath.Join(mock.root, string(s.Name()), "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("shard-%d", groupID), "cgroup.procs") content := readCgroupFile(t, path) pid, err := strconv.Atoi(string(content)) @@ -110,8 +110,8 @@ func TestCleanup(t *testing.T) { require.NoError(t, v1Manager.Cleanup()) for i := 0; i < 3; i++ { - memoryPath := filepath.Join(mock.root, "memory", "gitaly", fmt.Sprintf("gitaly-%d", i)) - cpuPath := filepath.Join(mock.root, "cpu", "gitaly", fmt.Sprintf("gitaly-%d", i)) + memoryPath := filepath.Join(mock.root, "memory", "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("shard-%d", i)) + cpuPath := filepath.Join(mock.root, "cpu", "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("shard-%d", i)) require.NoDirExists(t, memoryPath) require.NoDirExists(t, cpuPath) |