数据存储:失败的事务和回滚:如果回滚未被调用或失败会发生什么?

Datastore: Failed transactions and rollbacks: What happens if rollback is not called or fails?

如果事务失败,应用因为其他原因崩溃,事务没有回滚怎么办?

此外,发生什么情况以及应该如何处理 rollback 故障?

您不必担心应用程序崩溃对事务回滚(或任何其他有状态数据存储操作)的影响。

应用程序只是发送操作的 RPC 请求。实际操作 steps/sequence 执行发生在数据存储后端,而不是在您的应用程序内部。

From Life of a Datastore Write:

We'll dive into a bit more detail in terms of what new data is placed in the datastore as part of write operations such as inserts, deletions, updates, and transactions. The focus is on the backend work that is common to all of the runtimes.

...

When we call put or makePersistent, several things happen behind the scenes before the call returns and sets the entity's key:

  1. The my_todo object is converted into a protocol buffer.
  2. The appserver makes an RPC call to the datastore server, sending the entity data in a protocol buffer.
  3. If a key name is not provided, a unique ID is determined for this entity's key. The entity key is composed of app ID | ancestor keys | kind name | key name or ID.
  4. The datastore server processes the request in two phases that are executed in order: commit, then apply. In each phase, the datastore server identifies the Bigtable tablet servers that should receive the data.

现在,根据您使用的客户端库,事务回滚可以是完全自动的(例如,在 ndb python 客户端库中),也可以是您的应用程序的责任。但即使这是您的应用程序的责任,无论如何这也是尽力而为的尝试。在不请求回滚的情况下崩溃仅意味着后端侧的一些潜在挂起操作最终会超时,而不是被主动结束。另见相关