Google App Engine:在数据存储之间迁移数据

Google App Engine: Migrate data between Data Stores

我们目前正计划合并我们的两个 App Engine 项目,并希望将所有数据从欧盟数据存储移动到美国数据存储。

将使用 Google 的导出/导入工具 (https://cloud.google.com/datastore/docs/export-import-entities) 移动数据。但我们不确定现有数据存储如何处理插入具有自动生成 ID 的实体。我们能否确保之后存储的实体不会使用现有 ID 并因此覆盖现有实体? (数据存储接收器中尚不存在所有复制的实体)

文档中指出:

"Imports do not assign new IDs to entities. Imports use the IDs that existed at the time of the export and overwrite any existing entity with the same ID. During an import, the IDs are reserved during the time that the entities are being imported. This feature prevents ID collisions with new entities if writes are enabled while an import is running."

"the IDs are reserved during the time that the entities are being imported" 这是否意味着它们也被阻止用于将来分配新的自动生成的 ID?

例子

在 Datastore1(来源,EU)中,我有一个具有自动生成的 Long-Id 的实体。假设我保存了 10,000 个这样的实体,然后我删除了其中的 1,000 个实体。我可以肯定的是,如果我在 datastore1 中保存一个新实体(即到目前为止没有设置 Id),那么它将获得一个以前从未使用过的 Id。因此,该 Id 将不同于 9,000 个现有实体,也不同于 1,000 个已删除实体。

现在我将所有实体导出到 Cloudstorage(gcloud 数据存储导出),然后将它们从 Cloudstorage 导入到另一个数据存储 Datastore2(gcloud 数据存储导入)。这当然会在 Datastore2 中创建 9,000 个给定种类的实体(之前 Datastore2 中不存在该种类)。

我现在的问题是:当我在 Datastore2 中存储 1 个(或多个)新的 Entity/ies 时,它会始终获得一个新的 ID 还是会发生冲突?

身份冲突有两种方式

类型 A:新实体覆盖现有 9,000 个复制实体之一。 类型 B:一个新实体获得一个 ID,它等于 Datastore1 中 1,000 个已删除实体之一的 ID(显然,在 Datastore2 中从来没有一个实体具有这些 ID 之一,但我想知道 export/import也阻止这些 ID)

有人知道 A 类或 B 类是否会在某个时候发生吗?

当您执行从数据库 1 到数据库 2 的导入时,在将实体放入新数据库之前,所有 ID 都会被保留(有关保留 ID 的更多信息,请参阅 REST documentation)。

这意味着数据库 2 不会分配从数据库 1 导入的 ID(类型 A 不会发生)。

但是,导入将不会保留它不知道的实体(即删除的实体)的 ID。这些 ID 可能 在数据库 2 中重复使用。(类型 B 会发生)。