Skip to content

Commit

Permalink
server: expose GetLivenessesFromKV in node liveness interfaces
Browse files Browse the repository at this point in the history
To flesh out the migrations infrastructure (in future commits), we'll
need a handle on all the nodes present in the system. Now that we always
create a liveness record on start up (cockroachdb#53805), we can simply fetch all
liveness records from KV. We add a helper to do so.

It's a bit unfortunate that we're further adding on to the NodeLiveness
API without changing the caching structure, but the methods fetching
records from KV is the world we're hoping to move towards going forward.

This does mean that we're introducing a direct dependency on
NodeLiveness in the sql layer, and there's improvements to be made here
around interfaces delineating between "system tenant only" sql code and
everything else. Only system tenants have the privilege to set cluster
settings (or at least the version setting specifically), which is what
this API will look to power.

Release note: None
  • Loading branch information
irfansharif committed Oct 27, 2020
1 parent 67ecba4 commit f6682d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/jobs/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/kvserverpb"
Expand All @@ -28,7 +30,7 @@ var FakeNodeID = func() *base.NodeIDContainer {
}()

// FakeNodeLiveness allows simulating liveness failures without the full
// storage.NodeLiveness machinery.
// kvserver.NodeLiveness machinery.
type FakeNodeLiveness struct {
mu struct {
syncutil.Mutex
Expand Down Expand Up @@ -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 kvserver.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() (kvserverpb.Liveness, bool) {
Expand All @@ -75,7 +77,7 @@ func (nl *FakeNodeLiveness) Self() (kvserverpb.Liveness, bool) {
return *nl.mu.livenessMap[FakeNodeID.Get()], true
}

// GetLivenesses implements the implicit storage.NodeLiveness interface.
// GetLivenesses implements the implicit kvserver.NodeLiveness interface.
func (nl *FakeNodeLiveness) GetLivenesses() (out []kvserverpb.Liveness) {
select {
case nl.GetLivenessesCalledCh <- struct{}{}:
Expand All @@ -89,6 +91,11 @@ func (nl *FakeNodeLiveness) GetLivenesses() (out []kvserverpb.Liveness) {
return out
}

// GetLivenessesFromKV implements the implicit kvserver.NodeLiveness interface.
func (nl *FakeNodeLiveness) GetLivenessesFromKV(context.Context) ([]kvserverpb.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")
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/optionalnodeliveness/node_liveness.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
package optionalnodeliveness

import (
"context"

"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverpb"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/util/errorutil"
Expand All @@ -20,6 +22,7 @@ import (
type Interface interface {
Self() (kvserverpb.Liveness, bool)
GetLivenesses() []kvserverpb.Liveness
GetLivenessesFromKV(ctx context.Context) ([]kvserverpb.Liveness, error)
IsLive(roachpb.NodeID) (bool, error)
}

Expand Down

0 comments on commit f6682d1

Please sign in to comment.