首页 文章

具有多个分区的DocumentDb分区计数

提问于
浏览
0

我在一个数据库中有几个由PartitionKey属性分区的不同实体的集合 . 我正在为每个实体存储库创建新的DocumentClient并将HashPartitionResolver绑定到它:

var hashResolver = new HashPartitionResolver(partitionKeyExtractor, partitionCollectionsSelfLinks, hashGenerator:new HashGenerator());
client.PartitionResolvers[db.SelfLink] = hashResolver;

但是当我试图插入实体时:

await _client.UpsertDocumentAsync(Database.SelfLink, entity);

一些实体经常进入错误的分区 . 我想这可能是因为一个数据库中每个实体的分区数不同 .

有谁知道什么会导致这个问题,我该如何解决?感谢帮助!

1 回答

  • 0

    最后我发现了问题 . 在反编译HashPartitionResolver和ConsistentHashRing的代码后,我发现ConsistentHashRing有这一行:

    byte[] hash = hashGenerator.ComputeHash(BitConverter.GetBytes(node.GetHashCode()));
    

    但在代码的另一部分,它有这一行:

    byte[] hash = hashGenerator.ComputeHash(Encoding.UTF8.GetBytes(node));
    

    所以当我改变第一个

    byte[] hash = hashGenerator.ComputeHash(Encoding.UTF8.GetBytes(node));
    

    一切正常 . 我认为这是因为硬件依赖BitConverter或GetHashCode方法 . GitHub中的相关问题:Different Partitioning Schemes in the same database

相关问题