126 Commits

Author SHA1 Message Date
tangcong
b0bdaaa449 lease: fix memory leak in LeaseGrant when node is follower 2020-03-29 12:47:14 -07:00
Xiang Li
f6a9ebe579
Merge pull request #10710 from j2gg0s/refactor-lease-bench-test
lease: refactor lease's benchmark.
2019-06-07 21:32:04 -07:00
Gyuho Lee
1caaa9ed4a test: test update for Go 1.12.5 and related changes
Update to Go 1.12.5 testing. Remove deprecated unused and gosimple
pacakges, and mask staticcheck 1006. Also, fix unconvert errors related
to unnecessary type conversions and following staticcheck errors:
- remove redundant return statements
- use for range instead of for select
- use time.Since instead of time.Now().Sub
- omit comparison to bool constant
- replace T.Fatal and T.Fatalf in tests with T.Error and T.Fatalf respectively because the goroutine calls T.Fatal must be called in the same goroutine as the test
- fix error strings that should not be capitalized
- use sort.Strings(...) instead of sort.Sort(sort.StringSlice(...))
- use he status code of Canceled instead of grpc.ErrClientConnClosing which is deprecated
- use use status.Errorf instead of grpc.Errorf which is deprecated

Related #10528 #10438
2019-06-05 17:02:05 -04:00
yanjie.wyj
6a7ee7063c lease: refactor benchmark. 2019-06-05 10:01:01 +08:00
nolouch
dc8a31eaf0 lease/lessor: recheck if exprired lease is revoked
Signed-off-by: nolouch <nolouch@gmail.com>
2019-05-29 14:27:19 +08:00
johncming
e46af034df bugfix: adjust or add close request body.
affected modules:
- lease/leasehttp
- contrib/raftexample
2019-03-12 22:41:55 +08:00
nolouch
e20b9d9e16 lease: fix deadlock with renew lease when the checkpointor is set
Signed-off-by: nolouch <nolouch@gmail.com>
2019-02-24 19:53:09 +08:00
Gyuho Lee
d37f1521b7 *: update import paths to "go.etcd.io/etcd"
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
2018-08-28 17:47:55 -07:00
Joe Betz
d1de41efe1
lease: Add unit and integration tests for lease checkpointing 2018-07-23 16:12:42 -07:00
Joe Betz
2edb954bce
lease: Checkpoint lease TTLs to prevent indefinite auto-renewal of long lived leases 2018-07-23 16:12:34 -07:00
Joe Betz
bbe2d777b1
lease: Add LessorConfig and wire zap logger into Lessor 2018-07-17 13:10:34 -07:00
Joe Betz
75ac18cd2d
lease: Add and lease checkpoint protobuf types 2018-07-17 11:54:51 -07:00
Micah Gates
aa02ceb2e5 leases: Move lease sorting outside of lock
Because the leases were sorted inside UnsafeLeases() the lessor mutex
ended up being locked while the whole map was sorted. This pulls the
soring outside of the lock, per feedback on
https://github.com/coreos/etcd/pull/9699
2018-06-06 15:05:23 +00:00
Isaac Diamond
0369298b21
leases: Add metrics to etcd leases
This patch adds four metrics to the `leases` package for easier
debugging.
2018-05-25 12:57:28 -07:00
Gyuho Lee
200401248a
Merge pull request #9665 from gyuho/unconvert
test: integrate github.com/mdempsky/unconvert
2018-05-01 09:52:44 -07:00
Gyuho Lee
561fab1650 lease: fix "unconvert" warnings
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2018-04-30 15:32:16 -07:00
Gyuho Lee
48f28b9d27 lease/leasehttp: remove "strings.Compare != 0"
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2018-04-30 15:11:26 -07:00
Brian Cosgrove
13ed9f3197 lease: Clean-up old TODO around lease map and priority queue
This TODO was addressed in #9418.
2018-04-27 10:08:15 -05:00
Gyuho Lee
9c62d7b2d1 leaes: remove unnecessary O(log N) operation when nothing is expiry
Since heap is already sorted, we can just check first element
to see if anything is expiry, rather than popping and pushing
it back. If nothing is expiry, pop operation is unnecessary.

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2018-04-02 16:34:34 -07:00
Gyuho Lee
a6984c53de lease: add "expireExists"
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2018-04-02 16:34:34 -07:00
Gyuho Lee
f9b7a012b5 lease: add "TestLeaseQueue"
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2018-04-02 16:34:30 -07:00
Gyuho Lee
51b8d68a7f lease: godoc "LeaseWithTime", change field name to "id"
No need to have "lease" in field name.

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2018-04-02 14:58:34 -07:00
Gyuho Lee
472f309411 lease: fix gofmt
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2018-04-02 13:00:33 -07:00
micah
3f85ae70e0 lease: add lease benchmarks 2018-04-02 11:52:58 -07:00
micah
6f271d8bf1 lease: Add a heap to optimize lease expiration checks
This adds a heap acting as a priority queue to keep track of lease
exiprations. Previously the whole lease map had to be iterated through
each time.

The queue allows us to check only those leases which might be expired.
When the expiration changes, we add an additional entry. If we check an
entry that isn't expired, it means that the lease got extended.
If we find a entry in the heap that doesn't have a corresponding entry in
the map, we know that the lease has already been expired or revoked.
2018-04-02 11:52:55 -07:00
Iwasaki Yudai
db21941d1d *: enforce max lease TTL with 9,000,000,000 seconds
math.MaxInt64 / time.Second is 9,223,372,036. 9,000,000,000 is easier to
remember/document.
2018-03-08 10:17:12 -08:00
Gyuho Lee
659224b385
Merge pull request #9229 from ximenzaoshi/lease-fix
lease: Change lease Mutex to RWMutex
2018-02-26 17:21:09 -08:00
Gyuho Lee
8a518b01c4 *: revert "internal/mvcc" change
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2018-02-26 17:11:40 -08:00
Gyuho Lee
dd2f3b0de8 *: revert "internal/lease" change
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2018-02-26 17:11:40 -08:00
Gyuho Lee
349a377a67 *: move "lease" to "internal/lease"
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2018-01-26 11:09:29 -08:00
Manjunath A Kumatagi
f705c1be9b lease: fix govet errors 2018-01-25 04:51:13 -05:00
saiwl
4822116698 lease: Change lease Mutex to RWMutex 2018-01-25 16:19:28 +08:00
Gyuho Lee
bcd5390b35 *: regenerate protobuf, grpc-gateway
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2017-12-07 21:31:13 -08:00
Gyuho Lee
21d4307982 lease: use sort.Strings instead of StringSlice
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2017-12-04 14:10:14 -08:00
Gyu-Ho Lee
0048df6faf lease/leasehttp: use keyed fields in composite literals
Was complaining leasepb.LeaseInternalRequest composite literal uses unkeyed fields

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
2017-11-03 09:58:03 -07:00
lorneli
28a22075ca lease: test minLeaseTTL limit
Test whether lease's ttl is set to minLeaseTTL when passing a ttl
smaller than minLeaseTTL to Grant function.
2017-09-12 20:24:27 +08:00
Gyu-Ho Lee
0e0d9e492f lease: use time.Until in 'Remaining'
Fix 'gosimple' warnings.

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
2017-09-07 18:41:36 -07:00
Gyu-Ho Lee
6e39a39e3a Merge pull request #8511 from gyuho/ctx
*: deprecate 'golang.org/x/net/context'
2017-09-07 18:07:57 -07:00
Anthony Romano
eb55917ef6 Merge pull request #8507 from lorneli/lease_monotime
lease: use monotime in time.Time for Go 1.9
2017-09-07 15:43:24 -07:00
Gyu-Ho Lee
f65aee0759 *: replace 'golang.org/x/net/context' with 'context'
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
2017-09-07 13:39:42 -07:00
lorneli
63aa64d240 lease: use monotime in time.Time for Go 1.9
The golang/time package tracks monotonic time in each time.Time
returned by time.Now function for Go 1.9.

Use time.Time to measure whether a lease is expired and remove
previous pkg/monotime. Use zero time.Time to mean forever. No
expiration when expiry.IsZero() is true.
2017-09-07 14:18:19 +08:00
lorneli
7063a5e5cc lease: add limit in lessor.findExpiredLeases function
Function findExpiredLeases finds expired leases in the leaseMap until
reaching expired limit.
2017-09-07 02:34:56 +08:00
lorneli
77a19cd9d4 lease: fix typos
a. fix typo in godoc
b. make receiver of FakeLessor's function identical
2017-09-07 02:34:15 +08:00
Gyu-Ho Lee
099fbde809 lease: add 'Leases' method
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
2017-08-14 14:18:53 -07:00
Gyu-Ho Lee
8d41820741 lease: stop lessors after tests
Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
2017-06-30 10:13:36 -07:00
Anthony Romano
c38c00f7c3 lessor: extend leases on promote if expires will be rate limited
Instead of unconditionally randomizing, extend leases on promotion
if too many leases expire within the same time span. If the server
has few leases or spread out expires, there will be no extension.
2017-06-22 11:25:34 -07:00
Gyu-Ho Lee
5bba05703c lease: randomize expiry on initial refresh call
Randomize the very first expiry on lease recovery
to prevent recovered leases from expiring all at
the same time.

Address https://github.com/coreos/etcd/issues/8096.

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
2017-06-15 12:57:49 -07:00
Gyu-Ho Lee
0011b78bd5 lease: rate limit revoke runLoop
Fix https://github.com/coreos/etcd/issues/8097.

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
2017-06-14 14:22:16 -07:00
Anthony Romano
78a5eb79b5 *: add swagger and grpc-gateway assets for v3lock and v3election 2017-04-10 15:21:07 -07:00
Anthony Romano
42d56d5ef7 lease: acquire BatchTx lock in fakeDeleter
Revoke expects the BatchTx lock to be held when holding the TxnDeleter
because it updates the lease bucket. The tests don't hold the lock so
it may race with the backend commit loop.

Fixes #7662
2017-04-04 20:52:23 -07:00