diff options
author | Stan Hu <stanhu@gmail.com> | 2020-12-13 07:56:48 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2020-12-14 12:08:35 +0300 |
commit | 6f1ef4b49a87897668d40b7ba77e08973668162b (patch) | |
tree | 2e2cd604a5fdd7451de5661d6cb4049549763797 | |
parent | d5a9a458e393f3bccbec1a12e71d49179912457b (diff) |
Run housekeeping on pool repository
https://gitlab.com/gitlab-org/gitaly/-/merge_requests/2885 added
housekeeping on the origin repository during a FetchIntoObjectPool RPC,
but not on the pool repository itself.
We now remove housekeeping from origin repo and only clean up the pool
repository.
Relates to https://gitlab.com/gitlab-org/gitaly/-/issues/3305
-rw-r--r-- | changelogs/unreleased/sh-fix-issue-3305.yml | 5 | ||||
-rw-r--r-- | internal/git/objectpool/fetch.go | 7 | ||||
-rw-r--r-- | internal/gitaly/service/objectpool/fetch_into_object_pool_test.go | 19 |
3 files changed, 30 insertions, 1 deletions
diff --git a/changelogs/unreleased/sh-fix-issue-3305.yml b/changelogs/unreleased/sh-fix-issue-3305.yml new file mode 100644 index 000000000..a138574a2 --- /dev/null +++ b/changelogs/unreleased/sh-fix-issue-3305.yml @@ -0,0 +1,5 @@ +--- +title: Run housekeeping on pool repository +merge_request: 2916 +author: +type: fixed diff --git a/internal/git/objectpool/fetch.go b/internal/git/objectpool/fetch.go index 41967d029..d49b60043 100644 --- a/internal/git/objectpool/fetch.go +++ b/internal/git/objectpool/fetch.go @@ -38,7 +38,12 @@ func (o *ObjectPool) FetchFromOrigin(ctx context.Context, origin *gitalypb.Repos return err } - if err := housekeeping.Perform(ctx, originPath); err != nil { + poolPath, err := o.locator.GetPath(o) + if err != nil { + return err + } + + if err := housekeeping.Perform(ctx, poolPath); err != nil { return err } diff --git a/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go b/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go index 81c4a0d57..68e605001 100644 --- a/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go +++ b/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go @@ -3,9 +3,12 @@ package objectpool import ( "bytes" "encoding/json" + "io/ioutil" + "os" "path/filepath" "strings" "testing" + "time" "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "github.com/sirupsen/logrus" @@ -63,6 +66,22 @@ func TestFetchIntoObjectPool_Success(t *testing.T) { _, err = client.FetchIntoObjectPool(ctx, req) require.NoError(t, err, "calling FetchIntoObjectPool twice should be OK") require.True(t, pool.IsValid(), "ensure that pool is valid") + + // Simulate a broken ref + poolPath, err := locator.GetRepoPath(pool) + require.NoError(t, err) + brokenRef := filepath.Join(poolPath, "refs", "heads", "broken") + err = ioutil.WriteFile(brokenRef, []byte{}, 0777) + require.NoError(t, err) + + oldTime := time.Now().Add(-25 * time.Hour) + require.NoError(t, os.Chtimes(brokenRef, oldTime, oldTime)) + + _, err = client.FetchIntoObjectPool(ctx, req) + require.NoError(t, err) + + _, err = os.Stat(brokenRef) + require.Error(t, err, "Expected refs/heads/broken to be deleted") } func TestFetchIntoObjectPool_CollectLogStatistics(t *testing.T) { |