Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: Refactor TableDescriptor lease acquisition to use singleflight #18989

Merged
merged 2 commits into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions pkg/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ const (
// with a value of 0.2 and a liveness duration of 10 seconds, each node's
// liveness record would be eagerly renewed after 2 seconds.
livenessRenewalFraction = 0.5

// DefaultTableDescriptorLeaseDuration is the default mean duration a
// lease will be acquired for. The actual duration is jittered using
// the jitter fraction. Jittering is done to prevent multiple leases
// from being renewed simultaneously if they were all acquired
// simultaneously.
DefaultTableDescriptorLeaseDuration = 5 * time.Minute

// DefaultTableDescriptorLeaseJitterFraction is the default factor
// that we use to randomly jitter the lease duration when acquiring a
// new lease and the lease renewal timeout.
DefaultTableDescriptorLeaseJitterFraction = 0.25
)

var defaultRaftElectionTimeoutTicks = envutil.EnvOrDefaultInt(
Expand Down Expand Up @@ -466,3 +478,23 @@ func TempStorageConfigFromEnv(
Mon: &monitor,
}
}

// LeaseManagerConfig holds table lease manager parameters.
type LeaseManagerConfig struct {
// TableDescriptorLeaseDuration is the mean duration a lease will be
// acquired for.
TableDescriptorLeaseDuration time.Duration

// TableDescriptorLeaseJitterFraction is the factor that we use to
// randomly jitter the lease duration when acquiring a new lease and
// the lease renewal timeout.
TableDescriptorLeaseJitterFraction float64
}

// NewLeaseManagerConfig initializes a LeaseManagerConfig with default values.
func NewLeaseManagerConfig() *LeaseManagerConfig {
return &LeaseManagerConfig{
TableDescriptorLeaseDuration: DefaultTableDescriptorLeaseDuration,
TableDescriptorLeaseJitterFraction: DefaultTableDescriptorLeaseJitterFraction,
}
}
3 changes: 3 additions & 0 deletions pkg/base/test_server_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type TestServerArgs struct {
*cluster.Settings
RaftConfig

// LeaseManagerConfig holds configuration values specific to the LeaseManager.
LeaseManagerConfig *LeaseManagerConfig

// PartOfCluster must be set if the TestServer is joining others in a cluster.
// If not set (and hence the server is the only one in the cluster), the
// default zone config will be overridden to disable all replication - so that
Expand Down
4 changes: 4 additions & 0 deletions pkg/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ type Config struct {

base.RaftConfig

// LeaseManagerConfig holds configuration values specific to the LeaseManager.
LeaseManagerConfig *base.LeaseManagerConfig

// Unix socket: for postgres only.
SocketFile string

Expand Down Expand Up @@ -369,6 +372,7 @@ func MakeConfig(ctx context.Context, st *cluster.Settings) Config {

cfg.Config.InitDefaults()
cfg.RaftConfig.SetDefaults()
cfg.LeaseManagerConfig = base.NewLeaseManagerConfig()
return cfg
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func NewServer(cfg Config, stopper *stop.Stopper) (*Server, error) {
lmKnobs = *leaseManagerTestingKnobs.(*sql.LeaseManagerTestingKnobs)
}
s.leaseMgr = sql.NewLeaseManager(&s.nodeIDContainer, *s.db, s.clock, lmKnobs,
s.stopper, &s.internalMemMetrics)
s.stopper, &s.internalMemMetrics, s.cfg.LeaseManagerConfig)
s.leaseMgr.RefreshLeases(s.stopper, s.db, s.gossip)

// We do not set memory monitors or a noteworthy limit because the children of
Expand Down
5 changes: 5 additions & 0 deletions pkg/server/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func makeTestConfigFromParams(params base.TestServerArgs) Config {
cfg.TestingKnobs = params.Knobs
cfg.RaftConfig = params.RaftConfig
cfg.RaftConfig.SetDefaults()
if params.LeaseManagerConfig != nil {
cfg.LeaseManagerConfig = params.LeaseManagerConfig
} else {
cfg.LeaseManagerConfig = base.NewLeaseManagerConfig()
}
if params.JoinAddr != "" {
cfg.JoinList = []string{params.JoinAddr}
}
Expand Down
Loading