diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-07 12:57:04 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-15 16:15:09 +0300 |
commit | 219ce8a325bb722e13ab70539dc1bc70a44c37e6 (patch) | |
tree | 3d70be7c4ea4048ad4f0076f9dd4f8ea0b75e866 | |
parent | 925e65cdc845c78ed4467d83fb905b5be8ef0825 (diff) |
housekeeping: Split commit-graph writing out of object repacks
Writing commit-graphs and repacking objects is currently both done in
`RepackObjects()`. Back when the code was introduced this was done to
keep required code changes at bay by continuing to always rewrite the
commit-graph when we repack objects. We're about to iterate on the
strategy we use to write commit-graphs though, which requires us to
start doing so independently of whether we did or didn't repack objects.
Pull out the logic to write commit-graphs from `RepackObjects()` and
adjust all callsites of the latter to manually write commit-graphs. This
has merit on its own given that we can now properly report metrics for
writing the commit-graph on its own.
-rw-r--r-- | internal/git/housekeeping/objects.go | 4 | ||||
-rw-r--r-- | internal/git/housekeeping/optimize_repository.go | 10 | ||||
-rw-r--r-- | internal/git/housekeeping/optimize_repository_ext_test.go | 5 | ||||
-rw-r--r-- | internal/git/housekeeping/optimize_repository_test.go | 6 | ||||
-rw-r--r-- | internal/gitaly/service/repository/repack.go | 8 |
5 files changed, 27 insertions, 6 deletions
diff --git a/internal/git/housekeeping/objects.go b/internal/git/housekeeping/objects.go index 7ce675c6e..232fec629 100644 --- a/internal/git/housekeeping/objects.go +++ b/internal/git/housekeeping/objects.go @@ -52,10 +52,6 @@ func RepackObjects(ctx context.Context, repo *localrepo.Repo, cfg RepackObjectsC return err } - if err := WriteCommitGraph(ctx, repo); err != nil { - return err - } - stats.LogObjectsInfo(ctx, repo) return nil diff --git a/internal/git/housekeeping/optimize_repository.go b/internal/git/housekeeping/optimize_repository.go index 2837cd065..a6ec186f9 100644 --- a/internal/git/housekeeping/optimize_repository.go +++ b/internal/git/housekeeping/optimize_repository.go @@ -85,7 +85,17 @@ func optimizeRepository(ctx context.Context, m *RepositoryManager, repo *localre optimizations["written_bitmap"] = "success" } } + timer.ObserveDuration() + timer = prometheus.NewTimer(m.tasksLatency.WithLabelValues("commit-graph")) + if didRepack { + if err := WriteCommitGraph(ctx, repo); err != nil { + optimizations["written_commit_graph"] = "failure" + return fmt.Errorf("could not write commit-graph: %w", err) + } + + optimizations["written_commit_graph"] = "success" + } timer.ObserveDuration() timer = prometheus.NewTimer(m.tasksLatency.WithLabelValues("prune")) diff --git a/internal/git/housekeeping/optimize_repository_ext_test.go b/internal/git/housekeeping/optimize_repository_ext_test.go index 13940b9b6..7eae05993 100644 --- a/internal/git/housekeeping/optimize_repository_ext_test.go +++ b/internal/git/housekeeping/optimize_repository_ext_test.go @@ -120,8 +120,9 @@ func TestPruneIfNeeded(t *testing.T) { require.NoError(t, housekeeping.NewManager(cfg.Prometheus, nil).OptimizeRepository(ctx, repo)) expectedLogEntry := map[string]string{ - "packed_objects_full": "success", - "written_bitmap": "success", + "packed_objects_full": "success", + "written_commit_graph": "success", + "written_bitmap": "success", } if tc.expectedPrune { diff --git a/internal/git/housekeeping/optimize_repository_test.go b/internal/git/housekeeping/optimize_repository_test.go index 939dab9b1..453dd4ca7 100644 --- a/internal/git/housekeeping/optimize_repository_test.go +++ b/internal/git/housekeeping/optimize_repository_test.go @@ -546,6 +546,7 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 expectedMetrics: `# HELP gitaly_housekeeping_tasks_total Total number of housekeeping tasks performed in the repository # TYPE gitaly_housekeeping_tasks_total counter gitaly_housekeeping_tasks_total{housekeeping_task="packed_objects_full", status="success"} 1 +gitaly_housekeeping_tasks_total{housekeeping_task="written_commit_graph", status="success"} 1 gitaly_housekeeping_tasks_total{housekeeping_task="written_bitmap", status="success"} 1 gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 `, @@ -562,6 +563,7 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 expectedMetrics: `# HELP gitaly_housekeeping_tasks_total Total number of housekeeping tasks performed in the repository # TYPE gitaly_housekeeping_tasks_total counter gitaly_housekeeping_tasks_total{housekeeping_task="packed_objects_full", status="success"} 1 +gitaly_housekeeping_tasks_total{housekeeping_task="written_commit_graph", status="success"} 1 gitaly_housekeeping_tasks_total{housekeeping_task="written_bitmap", status="success"} 1 gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 `, @@ -588,6 +590,7 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 # TYPE gitaly_housekeeping_tasks_total counter gitaly_housekeeping_tasks_total{housekeeping_task="packed_objects_full", status="success"} 1 gitaly_housekeeping_tasks_total{housekeeping_task="written_bitmap", status="success"} 1 +gitaly_housekeeping_tasks_total{housekeeping_task="written_commit_graph", status="success"} 1 gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 `, }, @@ -635,6 +638,7 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 expectedMetrics: `# HELP gitaly_housekeeping_tasks_total Total number of housekeeping tasks performed in the repository # TYPE gitaly_housekeeping_tasks_total counter gitaly_housekeeping_tasks_total{housekeeping_task="packed_objects_incremental", status="success"} 1 +gitaly_housekeeping_tasks_total{housekeeping_task="written_commit_graph", status="success"} 1 gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 `, }, @@ -664,6 +668,7 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 expectedMetrics: `# HELP gitaly_housekeeping_tasks_total Total number of housekeeping tasks performed in the repository # TYPE gitaly_housekeeping_tasks_total counter gitaly_housekeeping_tasks_total{housekeeping_task="packed_objects_incremental", status="success"} 1 +gitaly_housekeeping_tasks_total{housekeeping_task="written_commit_graph", status="success"} 1 gitaly_housekeeping_tasks_total{housekeeping_task="pruned_objects",status="success"} 1 gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 `, @@ -671,6 +676,7 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 expectedMetricsForPool: `# HELP gitaly_housekeeping_tasks_total Total number of housekeeping tasks performed in the repository # TYPE gitaly_housekeeping_tasks_total counter gitaly_housekeeping_tasks_total{housekeeping_task="packed_objects_incremental", status="success"} 1 +gitaly_housekeeping_tasks_total{housekeeping_task="written_commit_graph", status="success"} 1 gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 `, }, diff --git a/internal/gitaly/service/repository/repack.go b/internal/gitaly/service/repository/repack.go index 66184ef1b..752e3c4c3 100644 --- a/internal/gitaly/service/repository/repack.go +++ b/internal/gitaly/service/repository/repack.go @@ -40,6 +40,10 @@ func (s *server) RepackFull(ctx context.Context, in *gitalypb.RepackFullRequest) return nil, helper.ErrInternalf("repacking objects: %w", err) } + if err := housekeeping.WriteCommitGraph(ctx, repo); err != nil { + return nil, helper.ErrInternalf("writing commit-graph: %w", err) + } + return &gitalypb.RepackFullResponse{}, nil } @@ -60,5 +64,9 @@ func (s *server) RepackIncremental(ctx context.Context, in *gitalypb.RepackIncre return nil, helper.ErrInternalf("repacking objects: %w", err) } + if err := housekeeping.WriteCommitGraph(ctx, repo); err != nil { + return nil, helper.ErrInternalf("writing commit-graph: %w", err) + } + return &gitalypb.RepackIncrementalResponse{}, nil } |