GAE 的锁定机制

发布于 2025-01-07 06:22:41 字数 201 浏览 3 评论 0原文

我正在使用一个具有在线数据存储(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情未る 2025-01-14 06:22:41

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 property locked to true 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 same SyncLock entity and this can only be achieved if entities have the same ID. So you should use userID as ID for SyncLock.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文