Update etcd Godeps to 3.0.17
This commit is contained in:
15
vendor/github.com/coreos/etcd/lease/leasehttp/http.go
generated
vendored
15
vendor/github.com/coreos/etcd/lease/leasehttp/http.go
generated
vendored
@@ -19,10 +19,10 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
|
||||
"github.com/coreos/etcd/lease"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// NewHandler returns an http Handler for lease renewals
|
||||
@@ -75,15 +75,22 @@ func (h *leaseHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// RenewHTTP renews a lease at a given primary server.
|
||||
// TODO: Batch request in future?
|
||||
func RenewHTTP(id lease.LeaseID, url string, rt http.RoundTripper, timeout time.Duration) (int64, error) {
|
||||
func RenewHTTP(ctx context.Context, id lease.LeaseID, url string, rt http.RoundTripper) (int64, error) {
|
||||
// will post lreq protobuf to leader
|
||||
lreq, err := (&pb.LeaseKeepAliveRequest{ID: int64(id)}).Marshal()
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
cc := &http.Client{Transport: rt, Timeout: timeout}
|
||||
resp, err := cc.Post(url, "application/protobuf", bytes.NewReader(lreq))
|
||||
cc := &http.Client{Transport: rt}
|
||||
req, err := http.NewRequest("POST", url, bytes.NewReader(lreq))
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/protobuf")
|
||||
req.Cancel = ctx.Done()
|
||||
|
||||
resp, err := cc.Do(req)
|
||||
if err != nil {
|
||||
// TODO detect if leader failed and retry?
|
||||
return -1, err
|
||||
|
||||
34
vendor/github.com/coreos/etcd/lease/lessor.go
generated
vendored
34
vendor/github.com/coreos/etcd/lease/lessor.go
generated
vendored
@@ -31,8 +31,6 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
minLeaseTTL = int64(5)
|
||||
|
||||
leaseBucketName = []byte("lease")
|
||||
// do not use maxInt64 since it can overflow time which will add
|
||||
// the offset of unix time (1970yr to seconds).
|
||||
@@ -143,6 +141,10 @@ type lessor struct {
|
||||
// The leased items can be recovered by iterating all the keys in kv.
|
||||
b backend.Backend
|
||||
|
||||
// minLeaseTTL is the minimum lease TTL that can be granted for a lease. Any
|
||||
// requests for shorter TTLs are extended to the minimum TTL.
|
||||
minLeaseTTL int64
|
||||
|
||||
expiredC chan []*Lease
|
||||
// stopC is a channel whose closure indicates that the lessor should be stopped.
|
||||
stopC chan struct{}
|
||||
@@ -150,14 +152,15 @@ type lessor struct {
|
||||
doneC chan struct{}
|
||||
}
|
||||
|
||||
func NewLessor(b backend.Backend) Lessor {
|
||||
return newLessor(b)
|
||||
func NewLessor(b backend.Backend, minLeaseTTL int64) Lessor {
|
||||
return newLessor(b, minLeaseTTL)
|
||||
}
|
||||
|
||||
func newLessor(b backend.Backend) *lessor {
|
||||
func newLessor(b backend.Backend, minLeaseTTL int64) *lessor {
|
||||
l := &lessor{
|
||||
leaseMap: make(map[LeaseID]*Lease),
|
||||
b: b,
|
||||
leaseMap: make(map[LeaseID]*Lease),
|
||||
b: b,
|
||||
minLeaseTTL: minLeaseTTL,
|
||||
// expiredC is a small buffered chan to avoid unnecessary blocking.
|
||||
expiredC: make(chan []*Lease, 16),
|
||||
stopC: make(chan struct{}),
|
||||
@@ -193,6 +196,10 @@ func (le *lessor) Grant(id LeaseID, ttl int64) (*Lease, error) {
|
||||
return nil, ErrLeaseExists
|
||||
}
|
||||
|
||||
if l.TTL < le.minLeaseTTL {
|
||||
l.TTL = le.minLeaseTTL
|
||||
}
|
||||
|
||||
if le.primary {
|
||||
l.refresh(0)
|
||||
} else {
|
||||
@@ -425,6 +432,9 @@ func (le *lessor) initAndRecover() {
|
||||
panic("failed to unmarshal lease proto item")
|
||||
}
|
||||
ID := LeaseID(lpb.ID)
|
||||
if lpb.TTL < le.minLeaseTTL {
|
||||
lpb.TTL = le.minLeaseTTL
|
||||
}
|
||||
le.leaseMap[ID] = &Lease{
|
||||
ID: ID,
|
||||
TTL: lpb.TTL,
|
||||
@@ -464,19 +474,11 @@ func (l Lease) persistTo(b backend.Backend) {
|
||||
|
||||
// refresh refreshes the expiry of the lease.
|
||||
func (l *Lease) refresh(extend time.Duration) {
|
||||
if l.TTL < minLeaseTTL {
|
||||
l.TTL = minLeaseTTL
|
||||
}
|
||||
l.expiry = time.Now().Add(extend + time.Second*time.Duration(l.TTL))
|
||||
}
|
||||
|
||||
// forever sets the expiry of lease to be forever.
|
||||
func (l *Lease) forever() {
|
||||
if l.TTL < minLeaseTTL {
|
||||
l.TTL = minLeaseTTL
|
||||
}
|
||||
l.expiry = forever
|
||||
}
|
||||
func (l *Lease) forever() { l.expiry = forever }
|
||||
|
||||
type LeaseItem struct {
|
||||
Key string
|
||||
|
||||
Reference in New Issue
Block a user