diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2020-11-23 14:07:27 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2020-11-23 18:02:26 +0300 |
commit | f199447088d78940c11bf4c964d702def6fb69bb (patch) | |
tree | dcd99f060455319f6dc960e67264f97a24528c69 /internal/praefect/replicator.go | |
parent | 00c6936a8257638733ea810f8438638cce960768 (diff) |
remove records of invalid repositories
Praefect's database contains records of invalid repositories. They'll
always fail a replication as the repository's record does not point to
a valid git repository. Praefect's automatic reconciler keeps reattempting
replication based on the invalid database records. This commit removes
database records of source repositories which do not point to a valid git
repository.
Diffstat (limited to 'internal/praefect/replicator.go')
-rw-r--r-- | internal/praefect/replicator.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/internal/praefect/replicator.go b/internal/praefect/replicator.go index e2fb8651a..dbabb899e 100644 --- a/internal/praefect/replicator.go +++ b/internal/praefect/replicator.go @@ -8,6 +8,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/repository" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/middleware/metadatahandler" "gitlab.com/gitlab-org/gitaly/internal/praefect/config" @@ -53,9 +54,10 @@ func (dr defaultReplicator) Replicate(ctx context.Context, event datastore.Repli } logger := dr.log.WithFields(logrus.Fields{ - logWithVirtualStorage: event.Job.VirtualStorage, - logWithReplTarget: event.Job.TargetNodeStorage, - logWithCorrID: correlation.ExtractFromContext(ctx), + logWithVirtualStorage: event.Job.VirtualStorage, + logWithReplTarget: event.Job.TargetNodeStorage, + "replication_job_source": event.Job.SourceNodeStorage, + logWithCorrID: correlation.ExtractFromContext(ctx), }) generation, err := dr.rs.GetReplicatedGeneration(ctx, event.Job.VirtualStorage, event.Job.RelativePath, event.Job.SourceNodeStorage, event.Job.TargetNodeStorage) @@ -82,6 +84,19 @@ func (dr defaultReplicator) Replicate(ctx context.Context, event datastore.Repli Source: sourceRepository, Repository: targetRepository, }); err != nil { + if errors.Is(err, repository.ErrInvalidSourceRepository) { + if err := dr.rs.DeleteInvalidRepository(ctx, + event.Job.VirtualStorage, + event.Job.RelativePath, + event.Job.SourceNodeStorage, + ); err != nil { + return fmt.Errorf("delete invalid repository: %w", err) + } + + logger.Info("invalid repository record removed") + return nil + } + return fmt.Errorf("failed to create repository: %w", err) } |