同一文档上同时服务器端事务的Firestore行为 [英] Firestore behavior of simultaneous server-side Transactions on the same document

查看:52
本文介绍了同一文档上同时服务器端事务的Firestore行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,Cloud Firestore的admin SDK文档指出,一个事务持有对其内部正在读取的所有文档的悲观锁.这意味着在此锁定期间(从获取文档到执行事务的那一刻),在事务本身之外对锁定文档进行的任何 update 都会被拒绝,而不是重试事务.

So the cloud firestore's admin SDK documentation states that a transaction holds a pessimistic lock on all documents being read inside it. Which means that during this locked period (moment from when the document was fetched to when the transaction is committed), any updates to the locked documents outside of the transaction itself will get rejected instead of the transaction being retried.

现在,当事务t1在时间t1读取(并锁定)文档d1,而在稍后的时间t2,另一个事务T2尝试在第一个事务T1仍在运行时读取同一文档d1时,会发生什么情况?还没有提交?

Now what happens when let's say at time t1 a transaction T1 reads (and thus locks) a document d1, while at a later time t2 another transaction T2 tries to read the same document d1 while the first transaction T1 is still running and is not yet committed?

  • 第二笔交易T2会完全失败吗?
  • 文档建议在锁定期间对文档的更新将被拒绝,但不会被 reads 拒绝.因此,在这种情况下,T2不会直立失败,但是当它尝试对文档d1执行 write 操作时,由于此 update 操作不在事务中,因此它会失败T1?
  • 如果我的第二个假设是正确的,那么有可能同时在同一文档d1上同时运行事务T1和T2,前提是T2甚至不修改文档d1(这只是d1的已读事务),或者当它在d2上执行写操作时,事务T1已经被提交了吗?
  • Will the second transaction T2 will just fail upright?
  • The documentation suggests that during the locked period updates to the document will get rejected but not reads. So will that be a case that T2 does not fails upright, but when it tries to perform a write operation on the document d1 it fails as this update operation is outside the transaction T1?
  • If my 2nd assumption is correct, then is it possible to run both transactions T1 and T2 simultaneously on the same document d1 successfully, providing that either T2 does not even modify document d1 (it is only a read transaction for d1) or when it performs write operations on d2, the transaction T1 has already been committed?

推荐答案

我试图找到一些信息,并询问很少的人.根据所有读物,正如所提到的,当然是可能的.

I have tried to find some information and ask few people as well. According to all reads are of course possible as it was mentioned.

所以 T2 不会失败,只要它能读取.如果它将尝试更新锁定的文档,它将失败,然后退出.

So T2 will not fail, if it only reads. It should fail if it will try to update locked document, and than will be retied.

这两个事务都应该成功完成,但是我认为要提到的重要一点是,在 T1 完成更改之前, T2 将以旧格式获取数据.

Both transaction should finish successfully, however I think that important thing to mention is that T2 will get data in old form, before changes done by T1.

我试图找到与Firestore直接相关的任何文档,但是似乎没有,所以我认为这与您提供的Wiki页面完全相同(

I tried to find any documentation regarding directly Firestore, however it seems there is no, so I think this is exactly as in Wiki page you have provided (here)

您可以在SO和Internet上找到很多类似的考虑因素.我只提到 this

You can find a lot of similar consideration here on SO and over internet. I only mention this and this for me are quite good.

我希望它会有所帮助!

这篇关于同一文档上同时服务器端事务的Firestore行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆