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-03-30 21:32:39 +0300
committerJohn Cai <jcai@gitlab.com>2022-03-30 21:32:39 +0300
commit131adc858a199fec86ad128d41b10340e0e9fabc (patch)
treeeddbbdbb1526a799dd26d34475f8ed5b0dec5a80 /internal/gitaly/service
parent53ed969077dbd1611492fd67109dc1ef5e80aee5 (diff)
parente842c0b37ca67125383faf7f3f24b15d01f224ab (diff)
Merge branch 'jc-repo-cleaner-grace-period' into 'master'
repocleaner: Only log repositories that have a mod time older than 24 hours and are not in the Praefect DB See merge request gitlab-org/gitaly!4449
Diffstat (limited to 'internal/gitaly/service')
-rw-r--r--internal/gitaly/service/internalgitaly/walkrepos.go9
-rw-r--r--internal/gitaly/service/internalgitaly/walkrepos_test.go29
2 files changed, 28 insertions, 10 deletions
diff --git a/internal/gitaly/service/internalgitaly/walkrepos.go b/internal/gitaly/service/internalgitaly/walkrepos.go
index 08979f92b..71a023fdd 100644
--- a/internal/gitaly/service/internalgitaly/walkrepos.go
+++ b/internal/gitaly/service/internalgitaly/walkrepos.go
@@ -9,6 +9,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
+ "google.golang.org/protobuf/types/known/timestamppb"
)
func (s *server) WalkRepos(req *gitalypb.WalkReposRequest, stream gitalypb.InternalGitaly_WalkReposServer) error {
@@ -55,8 +56,14 @@ func walkStorage(ctx context.Context, storagePath string, stream gitalypb.Intern
return err
}
+ gitDirInfo, err := os.Stat(path)
+ if err != nil {
+ return err
+ }
+
if err := stream.Send(&gitalypb.WalkReposResponse{
- RelativePath: relPath,
+ RelativePath: relPath,
+ ModificationTime: timestamppb.New(gitDirInfo.ModTime()),
}); err != nil {
return err
}
diff --git a/internal/gitaly/service/internalgitaly/walkrepos_test.go b/internal/gitaly/service/internalgitaly/walkrepos_test.go
index c4aad9fcd..23a3aaec4 100644
--- a/internal/gitaly/service/internalgitaly/walkrepos_test.go
+++ b/internal/gitaly/service/internalgitaly/walkrepos_test.go
@@ -6,6 +6,7 @@ import (
"path/filepath"
"sync"
"testing"
+ "time"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest"
@@ -42,16 +43,26 @@ func TestWalkRepos(t *testing.T) {
// file walk happens lexicographically, so we delete repository in the middle
// of the seqeuence to ensure the walk proceeds normally
- testRepo1, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
+ testRepo1, testRepo1Path := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
RelativePath: "a",
})
deletedRepo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
RelativePath: "b",
})
- testRepo2, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
+ testRepo2, testRepo2Path := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{
RelativePath: "c",
})
+ modifiedDate := time.Now().Add(-1 * time.Hour)
+ require.NoError(
+ t,
+ os.Chtimes(testRepo1Path, time.Now(), modifiedDate),
+ )
+ require.NoError(
+ t,
+ os.Chtimes(testRepo2Path, time.Now(), modifiedDate),
+ )
+
// to test a directory being deleted during a walk, we must delete a directory after
// the file walk has started. To achieve that, we wrap the server to pass down a wrapped
// stream that allows us to hook in to stream responses. We then delete 'b' when
@@ -93,14 +104,14 @@ func TestWalkRepos(t *testing.T) {
require.NoError(t, err)
actualRepos := consumeWalkReposStream(t, stream)
- require.Equal(t, []string{
- testRepo1.GetRelativePath(),
- testRepo2.GetRelativePath(),
- }, actualRepos)
+ require.Equal(t, testRepo1.GetRelativePath(), actualRepos[0].GetRelativePath())
+ require.Equal(t, modifiedDate.UTC(), actualRepos[0].GetModificationTime().AsTime())
+ require.Equal(t, testRepo2.GetRelativePath(), actualRepos[1].GetRelativePath())
+ require.Equal(t, modifiedDate.UTC(), actualRepos[1].GetModificationTime().AsTime())
}
-func consumeWalkReposStream(t *testing.T, stream gitalypb.InternalGitaly_WalkReposClient) []string {
- var repos []string
+func consumeWalkReposStream(t *testing.T, stream gitalypb.InternalGitaly_WalkReposClient) []*gitalypb.WalkReposResponse {
+ var repos []*gitalypb.WalkReposResponse
for {
resp, err := stream.Recv()
if err == io.EOF {
@@ -108,7 +119,7 @@ func consumeWalkReposStream(t *testing.T, stream gitalypb.InternalGitaly_WalkRep
} else {
require.NoError(t, err)
}
- repos = append(repos, resp.RelativePath)
+ repos = append(repos, resp)
}
return repos
}