Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit b64422d

Browse files
authored
gitserver: Extract repository service in gRPC (#61807)
This PR moves the Fetch and Delete operations onto a separate service. With that, we also disallow consumers of the internal/gitserver.Client interface to use these methods. Repo-updaters scheduler has authority over this and it should not be interfered with. If a caller wants to make a scheduling _suggestion_, it will be able to talk to repo-updater. This prepares for a better scheduler that has full control of the operations running. Test plan: E2E and integration tests will verify that repos are still cloned properly.
1 parent 66724c7 commit b64422d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3376
-3757
lines changed

cmd/frontend/backend/mocks_temp.go

Lines changed: 37 additions & 163 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/frontend/backend/repos.go

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ type ReposService interface {
3434
List(ctx context.Context, opt database.ReposListOptions) ([]*types.Repo, error)
3535
ListIndexable(ctx context.Context) ([]types.MinimalRepo, error)
3636
GetInventory(ctx context.Context, repoName api.RepoName, commitID api.CommitID, forceEnhancedLanguageDetection bool) (*inventory.Inventory, error)
37-
DeleteRepositoryFromDisk(ctx context.Context, repoID api.RepoID) error
38-
RequestRepositoryUpdate(ctx context.Context, repoID api.RepoID) error
37+
RecloneRepository(ctx context.Context, repoID api.RepoID) error
3938
ResolveRev(ctx context.Context, repo api.RepoName, rev string) (api.CommitID, error)
4039
}
4140

@@ -283,41 +282,20 @@ func (s *repos) GetInventory(ctx context.Context, repo api.RepoName, commitID ap
283282
return &inv, nil
284283
}
285284

286-
func (s *repos) DeleteRepositoryFromDisk(ctx context.Context, repoID api.RepoID) (err error) {
287-
if Mocks.Repos.DeleteRepositoryFromDisk != nil {
288-
return Mocks.Repos.DeleteRepositoryFromDisk(ctx, repoID)
285+
func (s *repos) RecloneRepository(ctx context.Context, repoID api.RepoID) (err error) {
286+
if Mocks.Repos.RecloneRepository != nil {
287+
return Mocks.Repos.RecloneRepository(ctx, repoID)
289288
}
290289

291290
repo, err := s.Get(ctx, repoID)
292291
if err != nil {
293292
return errors.Wrap(err, fmt.Sprintf("error while fetching repo with ID %d", repoID))
294293
}
295294

296-
ctx, done := startTrace(ctx, "DeleteRepositoryFromDisk", repoID, &err)
295+
ctx, done := startTrace(ctx, "RecloneRepository", repoID, &err)
297296
defer done()
298297

299-
err = s.gitserverClient.Remove(ctx, repo.Name)
300-
return err
301-
}
302-
303-
func (s *repos) RequestRepositoryUpdate(ctx context.Context, repoID api.RepoID) (err error) {
304-
repo, err := s.Get(ctx, repoID)
305-
if err != nil {
306-
return errors.Wrap(err, fmt.Sprintf("error while fetching repo with ID %d", repoID))
307-
}
308-
309-
ctx, done := startTrace(ctx, "RequestRepositoryUpdate", repoID, &err)
310-
defer done()
311-
312-
resp, err := s.gitserverClient.RequestRepoUpdate(ctx, repo.Name)
313-
if err != nil {
314-
return err
315-
}
316-
if resp.Error != "" {
317-
return errors.Newf("requesting update for repo ID %d failed: %s", repoID, resp.Error)
318-
}
319-
320-
return nil
298+
return repoupdater.DefaultClient.RecloneRepository(ctx, repo.Name)
321299
}
322300

323301
// ResolveRev will return the absolute commit for a commit-ish spec in a repo.

0 commit comments

Comments
 (0)