80 Commits

Author SHA1 Message Date
Lucas Rodriguez
06216228c3 Backport TestLessorRenewExtendPileup race condition fix for release-3.4
Signed-off-by: Lucas Rodriguez <lucas.rodriguez9616@gmail.com>
2024-09-09 12:40:10 -05:00
Wei Fu
acc5325889 *: LeaseTimeToLive returns error if leader changed
The old leader demotes lessor and all the leases' expire time will be
updated. Instead of returning incorrect remaining TTL, we should return
errors to force client retry.

Cherry-pick: d3bb6f688b4643155b4a9924cec726bdc76a1306

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2024-04-04 22:32:23 +08:00
Ivan Valdes
bf04c67408
Backport ignore old leader's leases revoking request
Backport of PR #16822, commits f7e488dc9262685d6624755e0d3bb0a655863248,
67f17166bf2ba337dafb8e0ea8eea5f74a990767,
and f7ff898fd6c2d6dbb54278343073aa4fa5f46a03.

Co-authored-by: Benjamin Wang <benjamin.wang@broadcom.com>
Signed-off-by: Ivan Valdes <ivan@vald.es>
2024-02-20 11:31:29 -08:00
Thomas Jungblut
afa0167538 Add first unit test for authApplierV3
This contains a slight refactoring to expose enough information
to write meaningful tests for auth applier v3.

Signed-off-by: Thomas Jungblut <tjungblu@redhat.com>
2023-06-16 10:08:47 +02:00
Marek Siarkowicz
8f4735dfd4 server: Require either cluster version v3.6 or --experimental-enable-lease-checkpoint-persist to persist lease remainingTTL
To avoid inconsistant behavior during cluster upgrade we are feature
gating persistance behind cluster version. This should ensure that
all cluster members are upgraded to v3.6 before changing behavior.

To allow backporting this fix to v3.5 we are also introducing flag
--experimental-enable-lease-checkpoint-persist that will allow for
smooth upgrade in v3.5 clusters with this feature enabled.

Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
2022-07-22 10:28:29 +02:00
Michał Jasionowski
8d83691d53 etcdserver,integration: Store remaining TTL on checkpoint
To extend lease checkpointing mechanism to cases when the whole etcd
cluster is restarted.

Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
2022-07-21 17:35:21 +02:00
Michał Jasionowski
a30aba8fc2 lease,integration: add checkpoint scheduling after leader change
Current checkpointing mechanism is buggy. New checkpoints for any lease
are scheduled only until the first leader change. Added fix for that
and a test that will check it.

Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
2022-07-21 17:35:15 +02:00
Chao Chen
fd51434b54 backport 3.5: #13676 load all leases from backend
Signed-off-by: Chao Chen <chaochn@amazon.com>
2022-07-19 16:08:01 -07:00
Benjamin Wang
f036529b5d Backport two lease related bug fixes to 3.4
The first bug fix is to resolve the race condition between goroutine
and channel on the same leases to be revoked. It's a classic mistake
in using Golang channel + goroutine. Please refer to
https://go.dev/doc/effective_go#channels

The second bug fix is to resolve the issue that etcd lessor may
continue to schedule checkpoint after stepping down the leader role.

Signed-off-by: Benjamin Wang <wachao@vmware.com>
2022-06-24 09:09:40 +08:00
tangcong
b0bdaaa449 lease: fix memory leak in LeaseGrant when node is follower 2020-03-29 12:47:14 -07: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
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
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
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
561fab1650 lease: fix "unconvert" warnings
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
2018-04-30 15:32:16 -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
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
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
saiwl
4822116698 lease: Change lease Mutex to RWMutex 2018-01-25 16:19:28 +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
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
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
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
f0c184b3a2 lease: support mvcc txn 2017-03-08 20:54:15 -08:00
Gyu-Ho Lee
6f0723f23f lease: guard 'Lease.itemSet' from concurrent writes
Fix https://github.com/coreos/etcd/issues/7448.

Affected if etcd builds with Go 1.8+.

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
2017-03-08 11:01:42 -08:00
Anthony Romano
b5cde6b321 lease: use atomics for accessing lease expiry
Demote was racing on expiry when LeaseTimeToLive called Remaining. Replace
with intrinsics since the ordering isn't important, but torn writes are
bad.
2016-12-28 15:44:14 -08:00
fanmin shi
e7f4010cca lease: Use monotonic time in lease
lease uses monotimer to calculate its expiration. In this way, changing system time won't affect in lease expiration.

FIX #6700
2016-11-29 12:31:00 -08:00
Nikita Vetoshkin
064e02f4b3 mvcc: Optimize updating key by storing lease in lessor 2016-10-12 09:37:09 +05:00
Gyu-Ho Lee
5adca4a720 lease, leasehttp: add TTL() method
Fix https://github.com/coreos/etcd/issues/6595.
2016-10-06 11:24:09 -07:00
Xiang Li
f0469f7f25 Merge pull request #6570 from xiang90/lease_expire
Fix lease expire
2016-10-05 15:49:45 -07:00
Xiang Li
279c103517 lease: fix lease expire and add a test 2016-10-05 14:41:47 -07:00
Anthony Romano
4f9be94643 lessor: delete keys in deterministic order on revoke
Fixes #6558
2016-09-30 16:45:52 -07:00
Gyu-Ho Lee
4871a4a5f3 lease: remove redundant get method 2016-09-30 10:27:27 -07:00
Gyu-Ho Lee
617d2d5b98 lease/*: add lease handler for 'LeaseTimeToLive' 2016-09-09 08:11:46 +09:00
Xiang Li
d69d438289 *: minor cleanup for lease 2016-08-04 20:39:32 -07:00
Xiang Li
75c06cacae lease: do lease delection in the kv txn 2016-08-04 10:06:47 -07:00
Xiang Li
4d59b6f52c lease: delete kvs in a txn 2016-08-04 10:06:46 -07:00
Anthony Romano
bf71497537 etcdserver, lease: tie lease min ttl to election timeout 2016-08-02 13:06:57 -07:00