DynamoDB 中 UUID 的 "internal hash function" 是什么?

What is the "internal hash function" for UUIDs in DynamoDB?

Amazon 的 DynamoDB 文档似乎故意对如何为行选择分区保持谨慎。这是关于分区键的discussion(重点是我的):

Partition key – A simple primary key, composed of one attribute known as the partition key.

DynamoDB uses the partition key's value as input to an internal hash function. The output from the hash function determines the partition (physical storage internal to DynamoDB) in which the item will be stored.

In a table that has only a partition key, no two items can have the same partition key value.

The People table described in Tables, Items, and Attributes is an example of a table with a simple primary key (PersonID). You can access any item in the People table immediately by providing the PersonId value for that item.

所以给出的示例将 PersonID 作为一个数字,对于散列来说可以是大的也可以是小的 - 取决于内部散列函数。

在我的项目中,我们使用随机的 v4 UUID 作为主键,目前我们以 String/S 形式(包括破折号)保留该 UUID。我突然想到,与整数类似,这个 UUID 字符串可以根据内部散列函数进行漂亮或糟糕的散列。

将 UUID 保留为字符串对我们来说很方便(尽管很浪费 space-wise),因为我们可以 view/query Dynamo 控制台中的 UUID 采用与应用程序日志中显示的相同 v4 格式。但是,如果以 String/S 形式而不是 Binary/B 形式保留我们的 UUID 将导致我们的行可怕地别名到一个或两个分区,因为内部哈希函数对于转换是天真的我们的 UUID 字符串到字节,然后该死的方便和 Binary/B 形式最适合 UUID。

所以,我想了解更多关于内部哈希函数的信息(最好是从 Dynamo 开发人员那里了解。)请向我们提供有关该内部哈希函数的智能水平的详细信息。它如何处理 String/S、Number/N 和 Binary/B 类型?

内部哈希函数是否识别出我们传递的是 v4 UUID 格式的字符串并自动对该 UUID 的二进制形式进行哈希处理?或者,它是按字典顺序哈希吗?

如果 String/S 密钥散列算法默认情况下是天真的,是否有任何编程方式可以用来向 Dynamo 提示我的 String 密钥是 UUID 并将其散列为二进制形式这样的?我将 Java 的 DynamoSDK 与 DynamoDBMapper 一起使用来访问我的 table,并且我可以在您指示的任何地方在我的实体上添加额外的注释。我也通过 DynamoDB 架构 json 配置控制自己的 table 定义,并可以根据需要进行更改。

我不是这里 DynamoDB 团队的开发人员,但我仍然会尽力回答。

  • 无法提示 DynamoDB 它应该如何在内部散列您的分区键。另外,DynamoDBMapper 没有这样的注解。
  • 由于 DynamoDB 不公开其哈希方案的内部结构,因此您不应在系统中使用任何此类假设。这是因为 DynamoDB 可以随时随意更改前者,无论这种情况多么罕见。
  • DynamoDB 实际上在内部散列两次,因此我认为您不必太担心:
    • 它首先进行散列以避免连续的键落在一起。检查 this 个论坛条目。
    • 它对上面的内容进行哈希处理,以决定记录应该转到哪个分区。