Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

what is used for about ttl in session? #6736

Closed
xiaoyulei opened this issue Oct 26, 2016 · 7 comments
Closed

what is used for about ttl in session? #6736

xiaoyulei opened this issue Oct 26, 2016 · 7 comments

Comments

@xiaoyulei
Copy link
Contributor

What is ttl in session used for? I thought it is the timeout for lock.
But I create a locker by concurrency.NewLocker with concurrency.WithTTL, and Lock, sleep for some time over the ttl, and create another locker locked on the same key, but it blocked.
Do I understand not correct?

@heyitsanthony
Copy link
Contributor

It's a lease wrapper that refreshes a lease until it is closed. It is blocking because the session that holds the lock is still alive and refreshing the underlying lease.

@xiaoyulei
Copy link
Contributor Author

xiaoyulei commented Oct 26, 2016

@heyitsanthony ok, it looks like I understand not correct. But is there anything to make session release the lock when timeout?

@xiaoyulei
Copy link
Contributor Author

xiaoyulei commented Oct 26, 2016

@heyitsanthony
I do not get why we need a session ttl in lock if it is not timeout for release lock?
What is the scene to use it?

@heyitsanthony
Copy link
Contributor

It's a distributed lock-- if there's no TTL / an infinite TTL and the lock holder crashes, the system can't make forward progress because the lock will never be released.

@xiaoyulei
Copy link
Contributor Author

@heyitsanthony Sorry, I am confused now.
You mean if I set TTL 1s, the lock will be released after 1s?

@heyitsanthony
Copy link
Contributor

No. It's for liveness checking. If the lock owner does not refresh its session lease within 1s (e.g., the process crashed), etcd will revoke the lease and the next waiter can claim the lock. If the lock owner keeps refreshing its session lease, it will not lose the lock.

@xiaoyulei
Copy link
Contributor Author

ok, understand it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants