Skip to content

Commit

Permalink
server: expose GetLivenessesFromKV in node liveness interfaces
Browse files Browse the repository at this point in the history
Expose the GetLivenessesFromKV API we introduced earlier to pkg/sql.
We'll eventually use this to power long running migrations (cockroachdb#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]: cockroachdb#48795

Release note: None
  • Loading branch information
irfansharif committed Nov 3, 2020
1 parent ce4f607 commit e3401be
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/liveness/livenesspb"
Expand All @@ -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
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 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) {
Expand All @@ -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{}{}:
Expand All @@ -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")
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/liveness/livenesspb"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/util/errorutil"
Expand All @@ -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)
}

Expand Down

0 comments on commit e3401be

Please sign in to comment.