GAE 的锁定机制
我正在使用一个具有在线数据存储(GAE)和离线数据存储(HTML5 websql)的应用程序。因此,为了解决同步问题,我正在尝试实现锁定机制。 它应该像信号量一样工作,或者作为主从机制。用户可以获得锁,如果不可用,可以请求它。 (虽然饥饿是可能的,但它是由用户策略处理的)
那么App Engine中是否提供了任何设施来实现这种锁定机制。
提前致谢...
I'm working with a app that has both online datastore(GAE) and an offline datastore(HTML5 websql). So to resolve synchronizing problems, i'm trying to implement a locking mechanism.
It should work like a semaphore, or as master-slave mechanism. User can get the lock, and if not available, can request for it. (although starvation is possible, it is handled by an user-policy)
So is there any facilities provided in App Engine to implementing this locking mechanism.
thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GAE 数据存储中没有明确的锁定机制。
但是,Datastore 支持事务,因此您可以创建(例如)一个
SyncLock
实体,并在事务内将属性locked
设置为true
。请注意,创建 SyncLock 不包含在事务中,但更新现有的同步锁包含在事务中。因此,不同的会话应该尝试访问相同的 SyncLock 实体,并且只有当实体具有相同的 ID 时才能实现这一点。因此您应该使用 userID 作为 SyncLock 的 ID。
There is no explicit mechanism for locking in GAE Datastore.
However, Datastore supports transactions, so you could create (for example) a
SyncLock
entity and set a propertylocked
totrue
inside a transaction.Note that creating a
SyncLock
is not covered by transaction, but updating an existing one is. So different sessions should try to access the sameSyncLock
entity and this can only be achieved if entities have the same ID. So you should use userID as ID forSyncLock
.