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

Commit daaf9f7

Browse files
authored
gitserver: Remove effectively disabled debouncing of updates (#60584)
The only value we ever passed here was 1 second, which is effectively "don't debounce". So we can simplify here. Really, the client should make sure to go at a reasonable pace, and gitserver on the other end of the wire can have ultimate authority over if it's time for an update or not. All existing tests still pass, integration and E2E tests are passing.
1 parent fac966d commit daaf9f7

File tree

14 files changed

+435
-462
lines changed

14 files changed

+435
-462
lines changed

cmd/gitserver/internal/integration_tests/clone_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestClone(t *testing.T) {
8888

8989
// Requesting a repo update should figure out that the repo is not yet
9090
// cloned and call clone. We expect that clone to succeed.
91-
_, err := cli.RequestRepoUpdate(ctx, repo, 0)
91+
_, err := cli.RequestRepoUpdate(ctx, repo)
9292
require.NoError(t, err)
9393

9494
// Should have acquired a lock.
@@ -185,7 +185,7 @@ func TestClone_Fail(t *testing.T) {
185185
// Requesting a repo update should figure out that the repo is not yet
186186
// cloned and call clone. We expect that clone to fail, because vcssyncer.IsCloneable
187187
// fails here.
188-
resp, err := cli.RequestRepoUpdate(ctx, repo, 0)
188+
resp, err := cli.RequestRepoUpdate(ctx, repo)
189189
require.NoError(t, err)
190190
// Note that this error is from IsCloneable(), not from Clone().
191191
require.Contains(t, resp.Error, "error cloning repo: repo github.com/test/repo not cloneable:")
@@ -223,7 +223,7 @@ func TestClone_Fail(t *testing.T) {
223223
// Requesting another repo update should figure out that the repo is not yet
224224
// cloned and call clone. We expect that clone to fail, but in the vcssyncer.Clone
225225
// stage this time, not vcssyncer.IsCloneable.
226-
resp, err = cli.RequestRepoUpdate(ctx, repo, 0)
226+
resp, err = cli.RequestRepoUpdate(ctx, repo)
227227
require.NoError(t, err)
228228
require.Contains(t, resp.Error, "failed to clone github.com/test/repo: clone failed. Output: Creating bare repo\nCreated bare repo at")
229229

cmd/gitserver/internal/integration_tests/resolverevisions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func TestClient_ResolveRevision(t *testing.T) {
103103

104104
for _, test := range tests {
105105
t.Run("", func(t *testing.T) {
106-
_, err := cli.RequestRepoUpdate(ctx, api.RepoName(remote), 0)
106+
_, err := cli.RequestRepoUpdate(ctx, api.RepoName(remote))
107107
require.NoError(t, err)
108108

109109
got, err := cli.ResolveRevision(ctx, api.RepoName(remote), test.input, gitserver.ResolveRevisionOptions{NoEnsureRevision: true})

cmd/gitserver/internal/integration_tests/test_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func MakeGitRepository(t testing.TB, cmds ...string) api.RepoName {
117117
t.Helper()
118118
dir := InitGitRepository(t, cmds...)
119119
repo := api.RepoName(filepath.Base(dir))
120-
if resp, err := testGitserverClient.RequestRepoUpdate(context.Background(), repo, 0); err != nil {
120+
if resp, err := testGitserverClient.RequestRepoUpdate(context.Background(), repo); err != nil {
121121
t.Fatal(err)
122122
} else if resp.Error != "" {
123123
t.Fatal(resp.Error)

cmd/gitserver/internal/server.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,6 @@ import (
5757
// logs to stderr
5858
var traceLogs bool
5959

60-
var (
61-
lastCheckAt = make(map[api.RepoName]time.Time)
62-
lastCheckMutex sync.Mutex
63-
)
64-
65-
// debounce() provides some filtering to prevent spammy requests for the same
66-
// repository. If the last fetch of the repository was within the given
67-
// duration, returns false, otherwise returns true and updates the last
68-
// fetch stamp.
69-
func debounce(name api.RepoName, since time.Duration) bool {
70-
lastCheckMutex.Lock()
71-
defer lastCheckMutex.Unlock()
72-
if t, ok := lastCheckAt[name]; ok && time.Now().Before(t.Add(since)) {
73-
return false
74-
}
75-
lastCheckAt[name] = time.Now()
76-
return true
77-
}
78-
7960
func init() {
8061
traceLogs, _ = strconv.ParseBool(env.Get("SRC_GITSERVER_TRACE", "false", "Toggles trace logging to stderr"))
8162
}
@@ -539,14 +520,11 @@ func (s *Server) RepoUpdate(ctx context.Context, req *protocol.RepoUpdateRequest
539520
return resp
540521
}
541522

542-
var statusErr, updateErr error
543-
544-
if debounce(req.Repo, req.Since) {
545-
updateErr = s.doRepoUpdate(ctx, req.Repo, "")
546-
}
523+
updateErr := s.doRepoUpdate(ctx, req.Repo, "")
547524

548525
// attempts to acquire these values are not contingent on the success of
549526
// the update.
527+
var statusErr error
550528
lastFetched, err := repoLastFetched(dir)
551529
if err != nil {
552530
statusErr = err

cmd/repo-updater/internal/scheduler/scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (s *UpdateScheduler) runUpdateLoop(ctx context.Context) {
179179
// if it doesn't exist or update it if it does. The timeout of this request depends
180180
// on the value of conf.GitLongCommandTimeout() or if the passed context has a set
181181
// deadline shorter than the value of this config.
182-
resp, err := s.gitserverClient.RequestRepoUpdate(ctx, repo.Name, 1*time.Second)
182+
resp, err := s.gitserverClient.RequestRepoUpdate(ctx, repo.Name)
183183
if err != nil {
184184
schedError.WithLabelValues("requestRepoUpdate").Inc()
185185
subLogger.Error("error requesting repo update", log.Error(err), log.String("uri", string(repo.Name)))

cmd/repo-updater/internal/scheduler/scheduler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ func TestUpdateScheduler_runUpdateLoop(t *testing.T) {
14281428
contexts := make(chan context.Context, expectedRequestCount)
14291429
db := dbmocks.NewMockDB()
14301430
gs := gitserver.NewMockClient()
1431-
gs.RequestRepoUpdateFunc.SetDefaultHook(func(ctx context.Context, repo api.RepoName, d time.Duration) (*gitserverprotocol.RepoUpdateResponse, error) {
1431+
gs.RequestRepoUpdateFunc.SetDefaultHook(func(ctx context.Context, repo api.RepoName) (*gitserverprotocol.RepoUpdateResponse, error) {
14321432
select {
14331433
case mock := <-mockRequestRepoUpdates:
14341434
if !reflect.DeepEqual(mock.repo.Name, repo) {

internal/batches/sources/mocks_test.go

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

internal/gitserver/client.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,8 @@ type Client interface {
363363
// with more detailed responses. Do not use this if you are not repo-updater.
364364
//
365365
// Repo updates are not guaranteed to occur. If a repo has been updated
366-
// recently (within the Since duration specified in the request), the
367-
// update won't happen.
368-
RequestRepoUpdate(context.Context, api.RepoName, time.Duration) (*protocol.RepoUpdateResponse, error)
366+
// recently, the update won't happen.
367+
RequestRepoUpdate(context.Context, api.RepoName) (*protocol.RepoUpdateResponse, error)
369368

370369
// RequestRepoClone is an asynchronous request to clone a repository.
371370
RequestRepoClone(context.Context, api.RepoName) (*protocol.RepoCloneResponse, error)
@@ -707,19 +706,17 @@ func (c *clientImplementor) gitCommand(repo api.RepoName, arg ...string) GitComm
707706
}
708707
}
709708

710-
func (c *clientImplementor) RequestRepoUpdate(ctx context.Context, repo api.RepoName, since time.Duration) (_ *protocol.RepoUpdateResponse, err error) {
709+
func (c *clientImplementor) RequestRepoUpdate(ctx context.Context, repo api.RepoName) (_ *protocol.RepoUpdateResponse, err error) {
711710
ctx, _, endObservation := c.operations.requestRepoUpdate.With(ctx, &err, observation.Args{
712711
MetricLabelValues: []string{c.scope},
713712
Attrs: []attribute.KeyValue{
714713
repo.Attr(),
715-
attribute.Stringer("since", since),
716714
},
717715
})
718716
defer endObservation(1, observation.Args{})
719717

720718
req := &protocol.RepoUpdateRequest{
721-
Repo: repo,
722-
Since: since,
719+
Repo: repo,
723720
}
724721

725722
client, err := c.ClientForRepo(ctx, repo)

internal/gitserver/client_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ func TestClient_IsRepoCloneale_ProtoRoundTrip(t *testing.T) {
6666
func TestClient_RepoUpdateRequest_ProtoRoundTrip(t *testing.T) {
6767
var diff string
6868
t.Run("request", func(t *testing.T) {
69-
fn := func(repo api.RepoName, since int64) bool {
69+
fn := func(repo api.RepoName) bool {
7070
original := protocol.RepoUpdateRequest{
71-
Repo: repo,
72-
Since: time.Duration(since),
71+
Repo: repo,
7372
}
7473

7574
var converted protocol.RepoUpdateRequest

internal/gitserver/mocks_temp.go

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

0 commit comments

Comments
 (0)