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_node_manager.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_node_manager.go')
-rw-r--r-- | internal/praefect/router_node_manager.go | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/internal/praefect/router_node_manager.go b/internal/praefect/router_node_manager.go index 90275e4fa..6bc850ca6 100644 --- a/internal/praefect/router_node_manager.go +++ b/internal/praefect/router_node_manager.go @@ -69,23 +69,25 @@ func (r *nodeManagerRouter) RouteRepositoryMutator(ctx context.Context, virtualS return RepositoryMutatorRoute{}, fmt.Errorf("get shard: %w", err) } - consistentStorages, err := r.rs.GetConsistentStorages(ctx, virtualStorage, relativePath) - if err != nil { - return RepositoryMutatorRoute{}, fmt.Errorf("consistent storages: %w", err) - } - - if _, ok := consistentStorages[shard.Primary.GetStorage()]; !ok { + if latest, err := r.rs.IsLatestGeneration(ctx, virtualStorage, relativePath, shard.Primary.GetStorage()); err != nil { + return RepositoryMutatorRoute{}, fmt.Errorf("check generation: %w", err) + } else if !latest { return RepositoryMutatorRoute{}, ErrRepositoryReadOnly } + // Only healthy secondaries which are consistent with the primary are allowed to take + // part in the transaction. Unhealthy nodes would block the transaction until they come back. // Inconsistent nodes will anyway need repair so including them doesn't make sense. They // also might vote to abort which might unnecessarily fail the transaction. + consistentSecondaries, err := r.rs.GetConsistentSecondaries(ctx, virtualStorage, relativePath, shard.Primary.GetStorage()) + if err != nil { + return RepositoryMutatorRoute{}, fmt.Errorf("consistent secondaries: %w", err) + } + var replicationTargets []string - // Only healthy secondaries which are consistent with the primary are allowed to take - // part in the transaction. Unhealthy nodes would block the transaction until they come back. - participatingSecondaries := make([]nodes.Node, 0, len(consistentStorages)) + participatingSecondaries := make([]nodes.Node, 0, len(consistentSecondaries)) for _, secondary := range shard.Secondaries { - if _, ok := consistentStorages[secondary.GetStorage()]; ok && secondary.IsHealthy() { + if _, ok := consistentSecondaries[secondary.GetStorage()]; ok && secondary.IsHealthy() { participatingSecondaries = append(participatingSecondaries, secondary) continue } |