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:
authorSami Hiltunen <shiltunen@gitlab.com>2022-03-04 11:37:55 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2022-03-04 11:37:55 +0300
commit5027219a5131b9980f7eed618fa625df1d5cb6e7 (patch)
tree43d32e19b45fe2141ad5a99ff54bf609b313e33d
parent8c549118a56c59c3e9645c923f6c869a4904515d (diff)
Rewrite relative path in RepositoryReplicas conditionally
Rails is failing on RepositoryReplicas tests as it now checks the replica path. However, the Rails tests do not configure a database so Praefect can't get the replica path from there. It's not possible to mock out the function with the interface provided either. To fix the problem, this commit adds a config check which enables the relative path rewriting only if repository-specific primaries are enabled, which also indicates that a database must be configured.
-rw-r--r--internal/praefect/info_service_test.go2
-rw-r--r--internal/praefect/service/info/repositories.go10
2 files changed, 8 insertions, 4 deletions
diff --git a/internal/praefect/info_service_test.go b/internal/praefect/info_service_test.go
index f7a24610e..c89654f6a 100644
--- a/internal/praefect/info_service_test.go
+++ b/internal/praefect/info_service_test.go
@@ -58,7 +58,7 @@ func TestInfoService_RepositoryReplicas(t *testing.T) {
const virtualStorage = "default"
conf := config.Config{
VirtualStorages: []*config.VirtualStorage{{Name: virtualStorage, Nodes: cfgNodes}},
- Failover: config.Failover{Enabled: true},
+ Failover: config.Failover{ElectionStrategy: config.ElectionStrategyPerRepository},
}
ctx := testhelper.Context(t)
diff --git a/internal/praefect/service/info/repositories.go b/internal/praefect/service/info/repositories.go
index ec6bb1a4b..6b00a4f03 100644
--- a/internal/praefect/service/info/repositories.go
+++ b/internal/praefect/service/info/repositories.go
@@ -5,6 +5,7 @@ import (
"fmt"
"gitlab.com/gitlab-org/gitaly/v14/internal/helper"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"golang.org/x/sync/errgroup"
)
@@ -29,9 +30,12 @@ func (s *Server) RepositoryReplicas(ctx context.Context, in *gitalypb.Repository
return nil, fmt.Errorf("get host assignments: %w", err)
}
- replicaPath, err := s.rs.GetReplicaPath(ctx, repositoryID)
- if err != nil {
- return nil, fmt.Errorf("get replica path: %w", err)
+ replicaPath := relativePath
+ if s.conf.Failover.ElectionStrategy == config.ElectionStrategyPerRepository {
+ replicaPath, err = s.rs.GetReplicaPath(ctx, repositoryID)
+ if err != nil {
+ return nil, fmt.Errorf("get replica path: %w", err)
+ }
}
secondaries := make([]string, 0, len(assignments)-1)