diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2020-12-10 17:00:12 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2020-12-10 17:00:12 +0300 |
commit | 971d49dccdd578fa09cc0747ff35b679d0e1c302 (patch) | |
tree | c87c83a2e9eb6d309913a0f59389f808024a58f9 /internal/praefect/router_per_repository.go | |
parent | 09c6d25de370446ac855a8241d8f821ed3f1ceec (diff) |
Revert "On each read/write operation praefect requires to know which"
This reverts commit 09c6d25de370446ac855a8241d8f821ed3f1ceec
Diffstat (limited to 'internal/praefect/router_per_repository.go')
-rw-r--r-- | internal/praefect/router_per_repository.go | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/internal/praefect/router_per_repository.go b/internal/praefect/router_per_repository.go index d5e42a717..d2174c9bb 100644 --- a/internal/praefect/router_per_repository.go +++ b/internal/praefect/router_per_repository.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/praefect/datastore" "gitlab.com/gitlab-org/gitaly/internal/praefect/nodes" "google.golang.org/grpc" @@ -129,14 +130,22 @@ func (r *PerRepositoryRouter) RouteRepositoryAccessor(ctx context.Context, virtu return RouterNode{}, err } - consistentStorages, err := r.rs.GetConsistentStorages(ctx, virtualStorage, relativePath) + primary, err := r.pg.GetPrimary(ctx, virtualStorage, relativePath) if err != nil { - return RouterNode{}, fmt.Errorf("consistent storages: %w", err) + return RouterNode{}, fmt.Errorf("get primary: %w", err) } + consistentSecondaries, err := r.rs.GetConsistentSecondaries(ctx, virtualStorage, relativePath, primary) + if err != nil { + // this is recoverable error - proceed with primary node + ctxlogrus.Extract(ctx).WithError(err).Warn("get up to date secondaries") + } + + consistentSecondaries[primary] = struct{}{} + healthyConsistentNodes := make([]RouterNode, 0, len(healthyNodes)) for _, node := range healthyNodes { - if _, ok := consistentStorages[node.Storage]; !ok { + if _, ok := consistentSecondaries[node.Storage]; !ok { continue } @@ -166,13 +175,15 @@ func (r *PerRepositoryRouter) RouteRepositoryMutator(ctx context.Context, virtua return RepositoryMutatorRoute{}, nodes.ErrPrimaryNotHealthy } - consistentStorages, err := r.rs.GetConsistentStorages(ctx, virtualStorage, relativePath) - if err != nil { - return RepositoryMutatorRoute{}, fmt.Errorf("consistent storages: %w", err) + if latest, err := r.rs.IsLatestGeneration(ctx, virtualStorage, relativePath, primary); err != nil { + return RepositoryMutatorRoute{}, fmt.Errorf("is latest generation: %w", err) + } else if !latest { + return RepositoryMutatorRoute{}, ErrRepositoryReadOnly } - if _, ok := consistentStorages[primary]; !ok { - return RepositoryMutatorRoute{}, ErrRepositoryReadOnly + consistentSecondaries, err := r.rs.GetConsistentSecondaries(ctx, virtualStorage, relativePath, primary) + if err != nil { + return RepositoryMutatorRoute{}, fmt.Errorf("consistent secondaries: %w", err) } assignedStorages, err := r.ag.GetHostAssignments(ctx, virtualStorage, relativePath) @@ -188,7 +199,7 @@ func (r *PerRepositoryRouter) RouteRepositoryMutator(ctx context.Context, virtua continue } - if _, consistent := consistentStorages[node.Storage]; !consistent || !healthy { + if _, consistent := consistentSecondaries[node.Storage]; !consistent || !healthy { route.ReplicationTargets = append(route.ReplicationTargets, assigned) continue } |