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>2021-03-26 11:29:37 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2021-04-01 12:50:46 +0300
commit6f68e2cb582b272336963761181d1b0759fb5b22 (patch)
treee1c1d8037dc0a2161d6d7fdafc907590b17bde7e
parentc5786b09543e40acc6e05bd4d29f6d89106b8e8a (diff)
Add GetPrimary to NodeManager
This commit implements the praefect.PrimaryGetter interface on NodeManager. This allows for NodeManager to be used as a PrimaryGetter in code which has been written to support repository specific primaries.
-rw-r--r--internal/praefect/nodes/manager.go11
-rw-r--r--internal/praefect/nodes/manager_test.go7
2 files changed, 18 insertions, 0 deletions
diff --git a/internal/praefect/nodes/manager.go b/internal/praefect/nodes/manager.go
index bc1b382ff..393159668 100644
--- a/internal/praefect/nodes/manager.go
+++ b/internal/praefect/nodes/manager.go
@@ -275,6 +275,17 @@ func (n *Mgr) GetShard(ctx context.Context, virtualStorageName string) (Shard, e
return strategy.GetShard(ctx)
}
+// GetPrimary returns the current primary of a repository. This is an adapter so NodeManager can be used
+// as a praefect.PrimaryGetter in newer code which written to support repository specific primaries.
+func (n *Mgr) GetPrimary(ctx context.Context, virtualStorage, _ string) (string, error) {
+ shard, err := n.GetShard(ctx, virtualStorage)
+ if err != nil {
+ return "", err
+ }
+
+ return shard.Primary.GetStorage(), nil
+}
+
func (n *Mgr) GetSyncedNode(ctx context.Context, virtualStorageName, repoPath string) (Node, error) {
upToDateStorages, err := n.csg.GetConsistentStorages(ctx, virtualStorageName, repoPath)
if err != nil {
diff --git a/internal/praefect/nodes/manager_test.go b/internal/praefect/nodes/manager_test.go
index 8661adfe6..e715078ef 100644
--- a/internal/praefect/nodes/manager_test.go
+++ b/internal/praefect/nodes/manager_test.go
@@ -294,12 +294,19 @@ func TestNodeManager(t *testing.T) {
Secondaries: []nodeAssertion{{node2.Storage, node2.Address}},
}, shard)
+ primary, err := nm.GetPrimary(ctx, "virtual-storage-0", "")
+ require.NoError(t, err)
+ require.Equal(t, shard.Primary.GetStorage(), primary)
+
healthSrv0.SetServingStatus("", grpc_health_v1.HealthCheckResponse_UNKNOWN)
healthSrv1.SetServingStatus("", grpc_health_v1.HealthCheckResponse_UNKNOWN)
checkShards(unhealthyCheckCount)
_, err = nm.GetShard(ctx, "virtual-storage-0")
require.Error(t, err, "should return error since no nodes are healthy")
+
+ _, err = nm.GetPrimary(ctx, "virtual-storage-0", "")
+ require.Equal(t, ErrPrimaryNotHealthy, err)
}
func TestMgr_GetSyncedNode(t *testing.T) {