From e3401be80b8a823a8f417fe4e0a27aafd7e4eee3 Mon Sep 17 00:00:00 2001 From: irfan sharif Date: Sun, 25 Oct 2020 01:56:55 -0400 Subject: [PATCH] server: expose GetLivenessesFromKV in node liveness interfaces Expose the GetLivenessesFromKV API we introduced earlier to pkg/sql. We'll eventually use this to power long running migrations (#56107), plumbing the liveness instance into the migration manager process. It should be noted that this will be a relatively meatier form of a dependency on node liveness from pkg/sql than we have currently. Today the only uses are in DistSQL planning and in jobs[1]. As it relates to our multi-tenancy work, the real use of this API will happen only on the system tenant. System tenants alone have the privilege to set cluster settings (or at least the version setting specifically), which is what the migration manager will be wired into. [1]: https://github.com/cockroachdb/cockroach/pull/48795 Release note: None --- pkg/jobs/helpers.go | 13 ++++++++++--- pkg/sql/optionalnodeliveness/node_liveness.go | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/jobs/helpers.go b/pkg/jobs/helpers.go index e5b3b9a1e072..42f13f9fb7c5 100644 --- a/pkg/jobs/helpers.go +++ b/pkg/jobs/helpers.go @@ -11,6 +11,8 @@ package jobs import ( + "context" + "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/jobs/jobspb" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" @@ -28,7 +30,7 @@ var FakeNodeID = func() *base.NodeIDContainer { }() // FakeNodeLiveness allows simulating liveness failures without the full -// storage.NodeLiveness machinery. +// liveness.NodeLiveness machinery. type FakeNodeLiveness struct { mu struct { syncutil.Mutex @@ -62,7 +64,7 @@ func NewFakeNodeLiveness(nodeCount int) *FakeNodeLiveness { // ModuleTestingKnobs implements base.ModuleTestingKnobs. func (*FakeNodeLiveness) ModuleTestingKnobs() {} -// Self implements the implicit storage.NodeLiveness interface. It uses NodeID +// Self implements the implicit liveness.NodeLiveness interface. It uses NodeID // as the node ID. On every call, a nonblocking send is performed over nl.ch to // allow tests to execute a callback. func (nl *FakeNodeLiveness) Self() (livenesspb.Liveness, bool) { @@ -75,7 +77,7 @@ func (nl *FakeNodeLiveness) Self() (livenesspb.Liveness, bool) { return *nl.mu.livenessMap[FakeNodeID.Get()], true } -// GetLivenesses implements the implicit storage.NodeLiveness interface. +// GetLivenesses implements the implicit liveness.NodeLiveness interface. func (nl *FakeNodeLiveness) GetLivenesses() (out []livenesspb.Liveness) { select { case nl.GetLivenessesCalledCh <- struct{}{}: @@ -89,6 +91,11 @@ func (nl *FakeNodeLiveness) GetLivenesses() (out []livenesspb.Liveness) { return out } +// GetLivenessesFromKV implements the implicit liveness.NodeLiveness interface. +func (nl *FakeNodeLiveness) GetLivenessesFromKV(context.Context) ([]livenesspb.Liveness, error) { + return nil, errors.New("FakeNodeLiveness.GetLivenessesFromKV is unimplemented") +} + // IsLive is unimplemented. func (nl *FakeNodeLiveness) IsLive(roachpb.NodeID) (bool, error) { return false, errors.New("FakeNodeLiveness.IsLive is unimplemented") diff --git a/pkg/sql/optionalnodeliveness/node_liveness.go b/pkg/sql/optionalnodeliveness/node_liveness.go index db89e171909c..cf6ce630d824 100644 --- a/pkg/sql/optionalnodeliveness/node_liveness.go +++ b/pkg/sql/optionalnodeliveness/node_liveness.go @@ -11,6 +11,8 @@ package optionalnodeliveness import ( + "context" + "github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb" "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/util/errorutil" @@ -20,6 +22,7 @@ import ( type Interface interface { Self() (livenesspb.Liveness, bool) GetLivenesses() []livenesspb.Liveness + GetLivenessesFromKV(ctx context.Context) ([]livenesspb.Liveness, error) IsLive(roachpb.NodeID) (bool, error) }