-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some obvious bugs in lease renewal
- Loading branch information
Showing
2 changed files
with
19 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,27 +285,32 @@ func (c *NamenodeConnection) renewLeases() { | |
ticker := time.NewTicker(leaseRenewInterval) | ||
defer ticker.Stop() | ||
|
||
select { | ||
case <-ticker.C: | ||
req := &hdfs.RenewLeaseRequestProto{ClientName: proto.String(c.ClientName)} | ||
resp := &hdfs.RenewLeaseResponseProto{} | ||
|
||
// Ignore any errors. | ||
c.Execute("renewLease", req, resp) | ||
case <-c.done: | ||
return | ||
for { | ||
select { | ||
case <-ticker.C: | ||
req := &hdfs.RenewLeaseRequestProto{ClientName: proto.String(c.ClientName)} | ||
resp := &hdfs.RenewLeaseResponseProto{} | ||
|
||
// Ignore any errors. | ||
c.Execute("renewLease", req, resp) | ||
case <-c.done: | ||
return | ||
} | ||
} | ||
} | ||
|
||
// Close terminates all underlying socket connections to remote server. | ||
func (c *NamenodeConnection) Close() error { | ||
close(c.done) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
colinmarc
Author
Owner
|
||
|
||
// Ensure that we're not concurrently renewing leases. | ||
c.reqLock.Lock() | ||
defer c.reqLock.Unlock() | ||
|
||
if c.conn != nil { | ||
return c.conn.Close() | ||
} | ||
|
||
close(c.done) | ||
return nil | ||
} | ||
|
||
|
Thanks for fixing. This part still looks weird for me. Why instead of sending done signal like that:
done<-struct{}{}
, you just close channel? This way renewLeases() will never reach return in for loop (Look here https://play.golang.org/p/PrF-l1sCWVy). Also this code looks more error prone and possibly contains race conditions (as pointed here 574b0ba#r36128585). We merged leaseRenew() realization by @efirs and that's been working pretty fine for a couple of month in production.