diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2021-10-22 14:34:23 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2021-11-10 12:20:48 +0300 |
commit | c90ed8b02c660e16a5cf4137d6183fee5418ae03 (patch) | |
tree | 32ccac2e8c30a0ab9d2662fbcd999a33303cc090 /internal/praefect/router_per_repository.go | |
parent | e4199889b4b0cb28d6ac0de374aafdd85faaaabb (diff) |
praefect: Return replica path for additional repository from Router
ObjectPoolService operates on multiple repositories in its mutators.
One of these repositories is the repository itself and the second one
is always the object pool. Depending on the operation, either one is
the target repo and the other one is called the additional repository.
As ObjectPool's are not handled in a special manner by Praefect, they
will also get unique relative paths generated for them by Praefect. The
proxied requests need to be then rewritten to use this generated path
instead of the client provided relative path. Prafect is already rewriting
the relative paths of the target repository but not the relative path of
the additional repository. This commit extends the Router to returns the
replica path of the additional repository if one is included in the request.
Diffstat (limited to 'internal/praefect/router_per_repository.go')
-rw-r--r-- | internal/praefect/router_per_repository.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/internal/praefect/router_per_repository.go b/internal/praefect/router_per_repository.go index 84c0097a2..a41c0938e 100644 --- a/internal/praefect/router_per_repository.go +++ b/internal/praefect/router_per_repository.go @@ -189,7 +189,7 @@ func (r *PerRepositoryRouter) RouteRepositoryAccessor(ctx context.Context, virtu }, nil } -func (r *PerRepositoryRouter) RouteRepositoryMutator(ctx context.Context, virtualStorage, relativePath string) (RepositoryMutatorRoute, error) { +func (r *PerRepositoryRouter) RouteRepositoryMutator(ctx context.Context, virtualStorage, relativePath, additionalRelativePath string) (RepositoryMutatorRoute, error) { healthyNodes, err := r.healthyNodes(virtualStorage) if err != nil { return RepositoryMutatorRoute{}, err @@ -200,6 +200,19 @@ func (r *PerRepositoryRouter) RouteRepositoryMutator(ctx context.Context, virtua return RepositoryMutatorRoute{}, fmt.Errorf("get repository id: %w", err) } + var additionalReplicaPath string + if additionalRelativePath != "" { + additionalRepositoryID, err := r.rs.GetRepositoryID(ctx, virtualStorage, additionalRelativePath) + if err != nil { + return RepositoryMutatorRoute{}, fmt.Errorf("get additional repository id: %w", err) + } + + additionalReplicaPath, err = r.rs.GetReplicaPath(ctx, additionalRepositoryID) + if err != nil { + return RepositoryMutatorRoute{}, fmt.Errorf("get additional repository replica path: %w", err) + } + } + primary, err := r.pg.GetPrimary(ctx, virtualStorage, repositoryID) if err != nil { return RepositoryMutatorRoute{}, fmt.Errorf("get primary: %w", err) @@ -228,7 +241,11 @@ func (r *PerRepositoryRouter) RouteRepositoryMutator(ctx context.Context, virtua return RepositoryMutatorRoute{}, fmt.Errorf("get host assignments: %w", err) } - route := RepositoryMutatorRoute{RepositoryID: repositoryID, ReplicaPath: replicaPath} + route := RepositoryMutatorRoute{ + RepositoryID: repositoryID, + ReplicaPath: replicaPath, + AdditionalReplicaPath: additionalReplicaPath, + } for _, assigned := range assignedStorages { node, healthy := healthySet[assigned] if assigned == primary { |