Giter VIP home page Giter VIP logo

Comments (2)

stulzq avatar stulzq commented on July 16, 2024

想了一下设计的几个点,目前的 api 比较简单 TryLock UnLock 还有个 expire 机制,
以下的 k 表示 ResourceId,v 表示 LockOwner
expire: 使用租约机制(不续约,如果租约到期表示超时释放锁)
TryLock: 首先创建租约,然后使用 etcd clientv3 txn,compare key revision=0, then put k/v and lease, else get key. txn commit 成功则表示抢到锁
UnLock: 同样使用 txn, compare v=req.LockOwner, then del key ,else get key, txn commit 成功表示删除锁成功,如果失败可以根据 txn responsee 来得到是什么原因 LOCK_UNEXIST or LOCK_BELONG_TO_OTHERS

from layotto.

seeflood avatar seeflood commented on July 16, 2024

想了一下设计的几个点,目前的 api 比较简单 TryLock UnLock 还有个 expire 机制,
以下的 k 表示 ResourceId,v 表示 LockOwner
expire: 使用租约机制(不续约,如果租约到期表示超时释放锁)
TryLock: 首先创建租约,然后使用 etcd clientv3 txn,compare key revision=0, then put k/v and lease, else get key. txn commit 成功则表示抢到锁
UnLock: 同样使用 txn, compare v=req.LockOwner, then del key ,else get key, txn commit 成功表示删除锁成功,如果失败可以根据 txn responsee 来得到是什么原因 LOCK_UNEXIST or LOCK_BELONG_TO_OTHERS

感谢您对Layotto的支持,已assign!
etcd支持服务端到时间自动删除节点,这点比zookeeper方便多了(zookeeper的ttl node特性默认是关闭的,我和@ZLBer 同学纠结了好长时间) :(

from layotto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.