问题描述
亚马逊推荐的在生产DynamoDB中更改大表的模式的方式是什么?
What is the Amazon-recommended way of changing the schema of a large table in a production DynamoDB?
想象一个假设案例,我们有一个表Person,带有主哈希键SSN。该表可能包含1000万个项目。
Imagine a hypothetical case where we have a table Person, with primary hash key SSN. This table may contain 10 million items.
现在有消息传出,由于身份盗用的数量大增,这个假设国家的政府引入了另一个个人身份证明:唯一个人标识符或UPI。
Now the news comes that due to the critical volume of identity thefts, the government of this hypothetical country has introduced another personal identification: Unique Personal Identifier, or UPI.
我们必须添加一个UPI列并更改Person表的架构,因此现在的主要哈希键是UPI。 我们希望同时支持使用SSN的当前系统和使用UPI的新系统,因此我们需要将这两列同时存在于Person表中。
We have to add an UPI column and change the schema of the Person table, so that now the primary hash key is UPI. We want to support for some time both the current system, which uses SSN and the new system, which uses UPI, thus we need both these two columns to co-exist in the Person table.
执行此架构更改的亚马逊推荐方法是什么?
What is the Amazon-recommended way to do this schema change?
推荐答案
有两种方法,但是首先您必须了解您不能更改现有表的架构。要获得其他架构,必须创建一个新表。您也许可以重用现有的表,但是结果将与创建其他表相同。
There are a couple of approaches, but first you must understand that you cannot change the schema of an existing table. To get a different schema, you have to create a new table. You may be able to reuse your existing table, but the result would be the same as if you created a different table.
- 延迟迁移到相同的表格,没有流。每次修改Person表中的条目时,都使用UPI而不是SSN作为哈希键的值在Person表中创建一个新项目,并删除以SSN为键的旧项目。这假定UPI从与SSN不同的值范围中提取。如果SSN看起来像XXX-XX-XXXX,那么只要UPI的位数与SSN的位数不同,那么您就永远不会重叠。
- 向同一表格的懒惰迁移,使用流。当流普遍可用时,您将能够为个人表打开流。创建具有NEW_AND_OLD_IMAGES流视图类型的流,并且每当您检测到对将 UPI添加到人员表中现有人员的项目的更改时,请创建Lambda函数,该函数将删除以SSN键为键的人员,并添加具有相同名称的人员。以UPI键控的属性。这种方法具有竞争条件,可以通过向项目添加原子的反向版本属性并在version属性上限制DeleteItem调用来缓解竞争条件。
- 抢先(脚本)式迁移到其他表,使用流。运行一个脚本,该脚本扫描您的表并将唯一的UPI添加到Person表中的每个Person项。在具有NEW_AND_OLD_IMAGES流视图类型的Person表上创建流,并在该lambda函数检测到具有UPI的Person被更改时,或者向该流订阅一个lambda函数,该函数将所有新Person写入新的Person_UPI表中。 UPI已添加。基本表上的突变通常需要数百毫秒才能作为流记录出现在流中,因此您可以对应用程序中的新Person_UPI表进行热故障转移。拒绝请求几秒钟,在这段时间内将您的应用程序指向Person_UPI表,然后重新启用请求。
这篇关于更改DynamoDB表的架构:最佳/推荐方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!