Skip to content

Commit e696c3d

Browse files
authored
Remove expiration_interval from grpclb message (#1477)
1 parent 4112717 commit e696c3d

File tree

4 files changed

+60
-166
lines changed

4 files changed

+60
-166
lines changed

grpclb.go

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,18 @@ type grpclbAddrInfo struct {
9797
}
9898

9999
type balancer struct {
100-
r naming.Resolver
101-
target string
102-
mu sync.Mutex
103-
seq int // a sequence number to make sure addrCh does not get stale addresses.
104-
w naming.Watcher
105-
addrCh chan []Address
106-
rbs []remoteBalancerInfo
107-
addrs []*grpclbAddrInfo
108-
next int
109-
waitCh chan struct{}
110-
done bool
111-
expTimer *time.Timer
112-
rand *rand.Rand
100+
r naming.Resolver
101+
target string
102+
mu sync.Mutex
103+
seq int // a sequence number to make sure addrCh does not get stale addresses.
104+
w naming.Watcher
105+
addrCh chan []Address
106+
rbs []remoteBalancerInfo
107+
addrs []*grpclbAddrInfo
108+
next int
109+
waitCh chan struct{}
110+
done bool
111+
rand *rand.Rand
113112

114113
clientStats lbmpb.ClientStats
115114
}
@@ -181,21 +180,6 @@ func (b *balancer) watchAddrUpdates(w naming.Watcher, ch chan []remoteBalancerIn
181180
return nil
182181
}
183182

184-
func (b *balancer) serverListExpire(seq int) {
185-
b.mu.Lock()
186-
defer b.mu.Unlock()
187-
// TODO: gRPC interanls do not clear the connections when the server list is stale.
188-
// This means RPCs will keep using the existing server list until b receives new
189-
// server list even though the list is expired. Revisit this behavior later.
190-
if b.done || seq < b.seq {
191-
return
192-
}
193-
b.next = 0
194-
b.addrs = nil
195-
// Ask grpc internals to close all the corresponding connections.
196-
b.addrCh <- nil
197-
}
198-
199183
func convertDuration(d *lbmpb.Duration) time.Duration {
200184
if d == nil {
201185
return 0
@@ -208,7 +192,6 @@ func (b *balancer) processServerList(l *lbmpb.ServerList, seq int) {
208192
return
209193
}
210194
servers := l.GetServers()
211-
expiration := convertDuration(l.GetExpirationInterval())
212195
var (
213196
sl []*grpclbAddrInfo
214197
addrs []Address
@@ -243,15 +226,6 @@ func (b *balancer) processServerList(l *lbmpb.ServerList, seq int) {
243226
b.next = 0
244227
b.addrs = sl
245228
b.addrCh <- addrs
246-
if b.expTimer != nil {
247-
b.expTimer.Stop()
248-
b.expTimer = nil
249-
}
250-
if expiration > 0 {
251-
b.expTimer = time.AfterFunc(expiration, func() {
252-
b.serverListExpire(seq)
253-
})
254-
}
255229
}
256230
return
257231
}
@@ -721,9 +695,6 @@ func (b *balancer) Close() error {
721695
return errBalancerClosed
722696
}
723697
b.done = true
724-
if b.expTimer != nil {
725-
b.expTimer.Stop()
726-
}
727698
if b.waitCh != nil {
728699
close(b.waitCh)
729700
}

grpclb/grpc_lb_v1/messages/messages.pb.go

Lines changed: 46 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grpclb/grpc_lb_v1/messages/messages.proto

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ message Duration {
3232
}
3333

3434
message Timestamp {
35-
3635
// Represents seconds of UTC time since Unix epoch
3736
// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
3837
// 9999-12-31T23:59:59Z inclusive.
@@ -122,11 +121,8 @@ message ServerList {
122121
// unless instructed otherwise via the client_config.
123122
repeated Server servers = 1;
124123

125-
// Indicates the amount of time that the client should consider this server
126-
// list as valid. It may be considered stale after waiting this interval of
127-
// time after receiving the list. If the interval is not positive, the
128-
// client can assume the list is valid until the next list is received.
129-
Duration expiration_interval = 3;
124+
// Was google.protobuf.Duration expiration_interval.
125+
reserved 3;
130126
}
131127

132128
// Contains server information. When none of the [drop_for_*] fields are true,

grpclb/grpclb_test.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -501,66 +501,6 @@ func TestDropRequestFailedNonFailFast(t *testing.T) {
501501
cc.Close()
502502
}
503503

504-
func TestServerExpiration(t *testing.T) {
505-
tss, cleanup, err := newLoadBalancer(1)
506-
if err != nil {
507-
t.Fatalf("failed to create new load balancer: %v", err)
508-
}
509-
defer cleanup()
510-
be := &lbmpb.Server{
511-
IpAddress: tss.beIPs[0],
512-
Port: int32(tss.bePorts[0]),
513-
LoadBalanceToken: lbToken,
514-
}
515-
var bes []*lbmpb.Server
516-
bes = append(bes, be)
517-
exp := &lbmpb.Duration{
518-
Seconds: 0,
519-
Nanos: 100000000, // 100ms
520-
}
521-
var sls []*lbmpb.ServerList
522-
sl := &lbmpb.ServerList{
523-
Servers: bes,
524-
ExpirationInterval: exp,
525-
}
526-
sls = append(sls, sl)
527-
sl = &lbmpb.ServerList{
528-
Servers: bes,
529-
}
530-
sls = append(sls, sl)
531-
var intervals []time.Duration
532-
intervals = append(intervals, 0)
533-
intervals = append(intervals, 500*time.Millisecond)
534-
tss.ls.sls = sls
535-
tss.ls.intervals = intervals
536-
creds := serverNameCheckCreds{
537-
expected: besn,
538-
}
539-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
540-
defer cancel()
541-
cc, err := grpc.DialContext(ctx, besn,
542-
grpc.WithBalancer(grpc.NewGRPCLBBalancer(&testNameResolver{addrs: []string{tss.lbAddr}})),
543-
grpc.WithBlock(), grpc.WithTransportCredentials(&creds), grpc.WithDialer(fakeNameDialer))
544-
if err != nil {
545-
t.Fatalf("Failed to dial to the backend %v", err)
546-
}
547-
testC := testpb.NewTestServiceClient(cc)
548-
if _, err := testC.EmptyCall(context.Background(), &testpb.Empty{}); err != nil {
549-
t.Fatalf("%v.EmptyCall(_, _) = _, %v, want _, <nil>", testC, err)
550-
}
551-
// Sleep and wake up when the first server list gets expired.
552-
time.Sleep(150 * time.Millisecond)
553-
if _, err := testC.EmptyCall(context.Background(), &testpb.Empty{}); grpc.Code(err) != codes.Unavailable {
554-
t.Fatalf("%v.EmptyCall(_, _) = _, %v, want _, %s", testC, err, codes.Unavailable)
555-
}
556-
// A non-failfast rpc should be succeeded after the second server list is received from
557-
// the remote load balancer.
558-
if _, err := testC.EmptyCall(context.Background(), &testpb.Empty{}, grpc.FailFast(false)); err != nil {
559-
t.Fatalf("%v.EmptyCall(_, _) = _, %v, want _, <nil>", testC, err)
560-
}
561-
cc.Close()
562-
}
563-
564504
// When the balancer in use disconnects, grpclb should connect to the next address from resolved balancer address list.
565505
func TestBalancerDisconnects(t *testing.T) {
566506
var (

0 commit comments

Comments
 (0)