Skip to content

Commit

Permalink
kvsever: introduce some testing knobs for node liveness
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
andreimatei committed Oct 26, 2020
1 parent adee6bc commit be25a97
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/base/testing_knobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type TestingKnobs struct {
DistSQL ModuleTestingKnobs
SQLEvalContext ModuleTestingKnobs
RegistryLiveness ModuleTestingKnobs
NodeLiveness ModuleTestingKnobs
Server ModuleTestingKnobs
TenantTestingKnobs ModuleTestingKnobs
JobsTestingKnobs ModuleTestingKnobs
Expand Down
17 changes: 17 additions & 0 deletions pkg/kv/kvserver/testing_knobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package kvserver
import (
"time"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/tenantrate"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/txnwait"
Expand Down Expand Up @@ -250,3 +251,19 @@ type StoreTestingKnobs struct {

// ModuleTestingKnobs is part of the base.ModuleTestingKnobs interface.
func (*StoreTestingKnobs) ModuleTestingKnobs() {}

// NodeLivenessTestingKnobs allows tests to override some node liveness
// controls. When set, fields ultimately affect the NodeLivenessOptions used by
// the cluster.
type NodeLivenessTestingKnobs struct {
// LivenessDuration overrides a liveness record's life time.
LivenessDuration time.Duration
// RenewalDuration specifies how long before the expiration a record is
// heartbeated. If LivenessDuration is set, this should probably be set too.
RenewalDuration time.Duration
}

var _ base.ModuleTestingKnobs = NodeLivenessTestingKnobs{}

// ModuleTestingKnobs implements the base.ModuleTestingKnobs interface.
func (NodeLivenessTestingKnobs) ModuleTestingKnobs() {}
9 changes: 9 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,15 @@ func NewServer(cfg Config, stopper *stop.Stopper) (*Server, error) {
db := kv.NewDBWithContext(cfg.AmbientCtx, tcsFactory, clock, dbCtx)

nlActive, nlRenewal := cfg.NodeLivenessDurations()
if knobs := cfg.TestingKnobs.NodeLiveness; knobs != nil {
nlKnobs := knobs.(kvserver.NodeLivenessTestingKnobs)
if duration := nlKnobs.LivenessDuration; duration != 0 {
nlActive = duration
}
if duration := nlKnobs.RenewalDuration; duration != 0 {
nlRenewal = duration
}
}

nodeLiveness := kvserver.NewNodeLiveness(kvserver.NodeLivenessOptions{
AmbientCtx: cfg.AmbientCtx,
Expand Down

0 comments on commit be25a97

Please sign in to comment.