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

Add lease read option #16669

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"go.etcd.io/etcd/pkg/v3/netutil"
"go.etcd.io/etcd/server/v3/etcdserver/api/v3discovery"
"go.etcd.io/etcd/server/v3/storage/datadir"
"go.etcd.io/raft/v3"
)

// ServerConfig holds the configuration of etcd as taken from the command line or discovery.
Expand Down Expand Up @@ -162,6 +163,8 @@ type ServerConfig struct {

ForceNewCluster bool

ReadOnlyOption raft.ReadOnlyOption `json:"read-only-option"`

// EnableLeaseCheckpoint enables leader to send regular checkpoints to other members to prevent reset of remaining TTL on leader change.
EnableLeaseCheckpoint bool
// LeaseCheckpointInterval time.Duration is the wait duration between lease checkpoints.
Expand Down
4 changes: 4 additions & 0 deletions server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ type Config struct {
// ForceNewCluster starts a new cluster even if previously started; unsafe.
ForceNewCluster bool `json:"force-new-cluster"`

// LeaseRead enables to read value from leader lease without communicating with quorum.
LeaseRead bool `json:"lease-read"`

EnablePprof bool `json:"enable-pprof"`
Metrics string `json:"metrics"`
ListenMetricsUrls []url.URL
Expand Down Expand Up @@ -642,6 +645,7 @@ func (cfg *Config) AddFlags(fs *flag.FlagSet) {
fs.BoolVar(&cfg.StrictReconfigCheck, "strict-reconfig-check", cfg.StrictReconfigCheck, "Reject reconfiguration requests that would cause quorum loss.")

fs.BoolVar(&cfg.PreVote, "pre-vote", cfg.PreVote, "Enable to run an additional Raft election phase.")
fs.BoolVar(&cfg.LeaseRead, "lease-read", false, "Enable to read value from leader lease without communicating with quorum.")

// security
fs.StringVar(&cfg.ClientTLSInfo.CertFile, "cert-file", "", "Path to the client server TLS cert file.")
Expand Down
7 changes: 7 additions & 0 deletions server/embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp"
"go.etcd.io/etcd/server/v3/storage"
"go.etcd.io/etcd/server/v3/verify"
"go.etcd.io/raft/v3"
)

const (
Expand Down Expand Up @@ -166,6 +167,11 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {

backendFreelistType := parseBackendFreelistType(cfg.BackendFreelistType)

readOnlyOption := raft.ReadOnlySafe
if cfg.LeaseRead {
readOnlyOption = raft.ReadOnlyLeaseBased
}

srvcfg := config.ServerConfig{
Name: cfg.Name,
ClientURLs: cfg.AdvertiseClientUrls,
Expand Down Expand Up @@ -211,6 +217,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
PreVote: cfg.PreVote,
Logger: cfg.logger,
ForceNewCluster: cfg.ForceNewCluster,
ReadOnlyOption: readOnlyOption,
EnableGRPCGateway: cfg.EnableGRPCGateway,
ExperimentalEnableDistributedTracing: cfg.ExperimentalEnableDistributedTracing,
UnsafeNoFsync: cfg.UnsafeNoFsync,
Expand Down
2 changes: 2 additions & 0 deletions server/etcdmain/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ Clustering:
Auto compaction retention length. 0 means disable auto compaction.
--auto-compaction-mode 'periodic'
Interpret 'auto-compaction-retention' one of: periodic|revision. 'periodic' for duration based retention, defaulting to hours if no time unit is provided (e.g. '5m'). 'revision' for revision number based retention.
--lease-read 'false'
Enable to read value from leader lease without communicating with quorum.
--v2-deprecation '` + string(cconfig.V2_DEPR_DEFAULT) + `'
Phase of v2store deprecation. Allows to opt-in for higher compatibility mode.
Supported values:
Expand Down
1 change: 1 addition & 0 deletions server/etcdserver/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ func raftConfig(cfg config.ServerConfig, id uint64, s *raft.MemoryStorage) *raft
CheckQuorum: true,
PreVote: cfg.PreVote,
Logger: NewRaftLoggerZap(cfg.Logger.Named("raft")),
ReadOnlyOption: cfg.ReadOnlyOption,
}
}

Expand Down