mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
support linearizable renew lease
When etcdserver receives a LeaseRenew request, it may be still in progress of processing the LeaseGrantRequest on exact the same leaseID. Accordingly it may return a TTL=0 to client due to the leaseID not found error. So the leader should wait for the appliedID to be available before processing client requests.
This commit is contained in:
@@ -1454,7 +1454,7 @@ func (c *ClusterV3) Client(i int) *clientv3.Client {
|
||||
|
||||
func (c *ClusterV3) ClusterClient() (client *clientv3.Client, err error) {
|
||||
if c.clusterClient == nil {
|
||||
endpoints := []string{}
|
||||
var endpoints []string
|
||||
for _, m := range c.Members {
|
||||
endpoints = append(endpoints, m.grpcURL)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ package integration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"testing"
|
||||
@@ -498,17 +499,31 @@ func TestV3LeaseLeases(t *testing.T) {
|
||||
// it was oberserved that the immediate lease renewal after granting a lease from follower resulted lease not found.
|
||||
// related issue https://github.com/etcd-io/etcd/issues/6978
|
||||
func TestV3LeaseRenewStress(t *testing.T) {
|
||||
testLeaseStress(t, stressLeaseRenew)
|
||||
testLeaseStress(t, stressLeaseRenew, false)
|
||||
}
|
||||
|
||||
// TestV3LeaseRenewStressWithClusterClient is similar to TestV3LeaseRenewStress,
|
||||
// but it uses a cluster client instead of a specific member's client.
|
||||
// The related issue is https://github.com/etcd-io/etcd/issues/13675.
|
||||
func TestV3LeaseRenewStressWithClusterClient(t *testing.T) {
|
||||
testLeaseStress(t, stressLeaseRenew, true)
|
||||
}
|
||||
|
||||
// TestV3LeaseTimeToLiveStress keeps creating lease and retrieving it immediately to ensure the lease can be retrieved.
|
||||
// it was oberserved that the immediate lease retrieval after granting a lease from follower resulted lease not found.
|
||||
// related issue https://github.com/etcd-io/etcd/issues/6978
|
||||
func TestV3LeaseTimeToLiveStress(t *testing.T) {
|
||||
testLeaseStress(t, stressLeaseTimeToLive)
|
||||
testLeaseStress(t, stressLeaseTimeToLive, false)
|
||||
}
|
||||
|
||||
func testLeaseStress(t *testing.T, stresser func(context.Context, pb.LeaseClient) error) {
|
||||
// TestV3LeaseTimeToLiveStressWithClusterClient is similar to TestV3LeaseTimeToLiveStress,
|
||||
// but it uses a cluster client instead of a specific member's client.
|
||||
// The related issue is https://github.com/etcd-io/etcd/issues/13675.
|
||||
func TestV3LeaseTimeToLiveStressWithClusterClient(t *testing.T) {
|
||||
testLeaseStress(t, stressLeaseTimeToLive, true)
|
||||
}
|
||||
|
||||
func testLeaseStress(t *testing.T, stresser func(context.Context, pb.LeaseClient) error, useClusterClient bool) {
|
||||
BeforeTest(t)
|
||||
clus := NewClusterV3(t, &ClusterConfig{Size: 3})
|
||||
defer clus.Terminate(t)
|
||||
@@ -517,13 +532,23 @@ func testLeaseStress(t *testing.T, stresser func(context.Context, pb.LeaseClient
|
||||
defer cancel()
|
||||
errc := make(chan error)
|
||||
|
||||
for i := 0; i < 30; i++ {
|
||||
for j := 0; j < 3; j++ {
|
||||
go func(i int) { errc <- stresser(ctx, toGRPC(clus.Client(i)).Lease) }(j)
|
||||
if useClusterClient {
|
||||
for i := 0; i < 300; i++ {
|
||||
clusterClient, err := clus.ClusterClient()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
go func(i int) { errc <- stresser(ctx, toGRPC(clusterClient).Lease) }(i)
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < 100; i++ {
|
||||
for j := 0; j < 3; j++ {
|
||||
go func(i int) { errc <- stresser(ctx, toGRPC(clus.Client(i)).Lease) }(j)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < 90; i++ {
|
||||
for i := 0; i < 300; i++ {
|
||||
if err := <-errc; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -554,7 +579,7 @@ func stressLeaseRenew(tctx context.Context, lc pb.LeaseClient) (reterr error) {
|
||||
continue
|
||||
}
|
||||
if rresp.TTL == 0 {
|
||||
return fmt.Errorf("TTL shouldn't be 0 so soon")
|
||||
return errors.New("TTL shouldn't be 0 so soon")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user