From 9be8443ec990cb765aae606e64c7e7cd757c7201 Mon Sep 17 00:00:00 2001 From: Jingyi Hu Date: Tue, 4 Jun 2019 19:30:57 -0700 Subject: [PATCH] *: enable lease checkpoint via experimental flag Primary lessor persist lease remainingTTL only if experimental flag "--experimental-enable-lease-checkpoint" is set. --- embed/config.go | 2 ++ embed/etcd.go | 1 + etcdmain/config.go | 1 + etcdmain/help.go | 2 ++ etcdserver/config.go | 2 ++ etcdserver/server.go | 8 +++++--- integration/cluster.go | 4 ++++ integration/v3_lease_test.go | 6 +++++- 8 files changed, 22 insertions(+), 4 deletions(-) diff --git a/embed/config.go b/embed/config.go index 0480acae3a3e..616e46cce908 100644 --- a/embed/config.go +++ b/embed/config.go @@ -278,6 +278,8 @@ type Config struct { ExperimentalEnableV2V3 string `json:"experimental-enable-v2v3"` // ExperimentalBackendFreelistType specifies the type of freelist that boltdb backend uses (array and map are supported types). ExperimentalBackendFreelistType string `json:"experimental-backend-bbolt-freelist-type"` + // ExperimentalEnableLeaseCheckpoint enables primary lessor to persist lease remainingTTL to prevent indefinite auto-renewal of long lived leases. + ExperimentalEnableLeaseCheckpoint bool `json:"experimental-enable-lease-checkpoint"` // ForceNewCluster starts a new cluster even if previously started; unsafe. ForceNewCluster bool `json:"force-new-cluster"` diff --git a/embed/etcd.go b/embed/etcd.go index d32adbd1543c..8fa48f41d117 100644 --- a/embed/etcd.go +++ b/embed/etcd.go @@ -204,6 +204,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) { Debug: cfg.Debug, ForceNewCluster: cfg.ForceNewCluster, EnableGRPCGateway: cfg.EnableGRPCGateway, + EnableLeaseCheckpoint: cfg.ExperimentalEnableLeaseCheckpoint, } print(e.cfg.logger, *cfg, srvcfg, memberInitialized) if e.Server, err = etcdserver.NewServer(srvcfg); err != nil { diff --git a/etcdmain/config.go b/etcdmain/config.go index 37a23a56e294..1b5c992ea0e2 100644 --- a/etcdmain/config.go +++ b/etcdmain/config.go @@ -249,6 +249,7 @@ func newConfig() *config { fs.DurationVar(&cfg.ec.ExperimentalCorruptCheckTime, "experimental-corrupt-check-time", cfg.ec.ExperimentalCorruptCheckTime, "Duration of time between cluster corruption check passes.") fs.StringVar(&cfg.ec.ExperimentalEnableV2V3, "experimental-enable-v2v3", cfg.ec.ExperimentalEnableV2V3, "v3 prefix for serving emulated v2 state.") fs.StringVar(&cfg.ec.ExperimentalBackendFreelistType, "experimental-backend-bbolt-freelist-type", cfg.ec.ExperimentalBackendFreelistType, "ExperimentalBackendFreelistType specifies the type of freelist that boltdb backend uses(array and map are supported types)") + fs.BoolVar(&cfg.ec.ExperimentalEnableLeaseCheckpoint, "experimental-enable-lease-checkpoint", false, "Enable to persist lease remaining TTL to prevent indefinite auto-renewal of long lived leases.") // unsafe fs.BoolVar(&cfg.ec.ForceNewCluster, "force-new-cluster", false, "Force to create a new one member cluster.") diff --git a/etcdmain/help.go b/etcdmain/help.go index c8db7d34128b..7f022cda9003 100644 --- a/etcdmain/help.go +++ b/etcdmain/help.go @@ -202,6 +202,8 @@ Experimental feature: Serve v2 requests through the v3 backend under a given prefix. --experimental-backend-bbolt-freelist-type ExperimentalBackendFreelistType specifies the type of freelist that boltdb backend uses(array and map are supported types). + --experimental-enable-lease-checkpoint + ExperimentalEnableLeaseCheckpoint enables primary lessor to persist lease remainingTTL to prevent indefinite auto-renewal of long lived leases. Unsafe feature: --force-new-cluster 'false' diff --git a/etcdserver/config.go b/etcdserver/config.go index b0eaf18e7b91..9597c6cb8b21 100644 --- a/etcdserver/config.go +++ b/etcdserver/config.go @@ -150,6 +150,8 @@ type ServerConfig struct { ForceNewCluster bool + // EnableLeaseCheckpoint enables primary lessor to persist lease remainingTTL to prevent indefinite auto-renewal of long lived leases. + EnableLeaseCheckpoint bool // LeaseCheckpointInterval time.Duration is the wait duration between lease checkpoints. LeaseCheckpointInterval time.Duration diff --git a/etcdserver/server.go b/etcdserver/server.go index 722922eeff2d..13dd660315d1 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -595,9 +595,11 @@ func NewServer(cfg ServerConfig) (srv *EtcdServer, err error) { return nil, err } - srv.lessor.SetCheckpointer(func(ctx context.Context, cp *pb.LeaseCheckpointRequest) { - srv.raftRequestOnce(ctx, pb.InternalRaftRequest{LeaseCheckpoint: cp}) - }) + if srv.Cfg.EnableLeaseCheckpoint { + srv.lessor.SetCheckpointer(func(ctx context.Context, cp *pb.LeaseCheckpointRequest) { + srv.raftRequestOnce(ctx, pb.InternalRaftRequest{LeaseCheckpoint: cp}) + }) + } // TODO: move transport initialization near the definition of remote tr := &rafthttp.Transport{ diff --git a/integration/cluster.go b/integration/cluster.go index 73b32cae1cc7..7c3e07018911 100644 --- a/integration/cluster.go +++ b/integration/cluster.go @@ -150,6 +150,7 @@ type ClusterConfig struct { // UseIP is true to use only IP for gRPC requests. UseIP bool + EnableLeaseCheckpoint bool LeaseCheckpointInterval time.Duration } @@ -293,6 +294,7 @@ func (c *cluster) mustNewMember(t testing.TB) *member { clientMaxCallSendMsgSize: c.cfg.ClientMaxCallSendMsgSize, clientMaxCallRecvMsgSize: c.cfg.ClientMaxCallRecvMsgSize, useIP: c.cfg.UseIP, + enableLeaseCheckpoint: c.cfg.EnableLeaseCheckpoint, leaseCheckpointInterval: c.cfg.LeaseCheckpointInterval, }) m.DiscoveryURL = c.cfg.DiscoveryURL @@ -581,6 +583,7 @@ type memberConfig struct { clientMaxCallSendMsgSize int clientMaxCallRecvMsgSize int useIP bool + enableLeaseCheckpoint bool leaseCheckpointInterval time.Duration } @@ -672,6 +675,7 @@ func mustNewMember(t testing.TB, mcfg memberConfig) *member { m.clientMaxCallSendMsgSize = mcfg.clientMaxCallSendMsgSize m.clientMaxCallRecvMsgSize = mcfg.clientMaxCallRecvMsgSize m.useIP = mcfg.useIP + m.EnableLeaseCheckpoint = mcfg.enableLeaseCheckpoint m.LeaseCheckpointInterval = mcfg.leaseCheckpointInterval m.InitialCorruptCheck = true diff --git a/integration/v3_lease_test.go b/integration/v3_lease_test.go index 7b378f0c92f6..29e9d4c763b1 100644 --- a/integration/v3_lease_test.go +++ b/integration/v3_lease_test.go @@ -230,7 +230,11 @@ func TestV3LeaseCheckpoint(t *testing.T) { var ttl int64 = 300 leaseInterval := 2 * time.Second defer testutil.AfterTest(t) - clus := NewClusterV3(t, &ClusterConfig{Size: 3, LeaseCheckpointInterval: leaseInterval}) + clus := NewClusterV3(t, &ClusterConfig{ + Size: 3, + EnableLeaseCheckpoint: true, + LeaseCheckpointInterval: leaseInterval, + }) defer clus.Terminate(t) // create lease