【问题标题】:Azure Change Feed and Querying based on PartitionAzure 更改源和基于分区的查询
【发布时间】:2017-06-29 15:50:57
【问题描述】:

当我们从更改提要中的 Document Db 获取数据时,我们只希望每个分区都得到它,并尝试将 PatitionKey 添加到代码中。

do
        {
            FeedResponse<PartitionKeyRange> pkRangesResponse = await client.ReadPartitionKeyRangeFeedAsync(
                collectionUri,
                new FeedOptions
                {
                    RequestContinuation = pkRangesResponseContinuation,
                    PartitionKey = new PartitionKey("KEY"),
                });

            partitionKeyRanges.AddRange(pkRangesResponse);
            pkRangesResponseContinuation = pkRangesResponse.ResponseContinuation;
        }
        while (pkRangesResponseContinuation != null);

它返回单个范围,当我们去执行第二个查询时

IDocumentQuery<Document> query = client.CreateDocumentChangeFeedQuery(
                collectionUri,
                new ChangeFeedOptions
                {
                    PartitionKeyRangeId = pkRange.Id,
                    StartFromBeginning = true,
                    RequestContinuation = continuation,
                    MaxItemCount = -1,
                });

它返回所有分区的所有结果。有没有办法只限制单个分区的结果?

【问题讨论】:

  • 根据artilce,CreateDocumentChangeFeedQuery 方法会从一个分区范围内获取结果,我们不能只限制单个分区的结果。
  • 那么根据该建议,更改提要只能通过中间服务器支持,而不能直接由客户端支持?由于客户端可能无法访问其他分区数据?
  • 在我看来,中间服务器也是客户端。更改源用于存储对 Azure Cosmos DB 数据所做的更改。 azure documentdb 服务器只支持分区范围跟踪。所以我们只能使用分区范围。

标签: azure azure-cosmosdb


【解决方案1】:

Changefeed 在 PartitionKey Range 级别工作。

什么是分区键范围?

Document Db 目前有 10 GB 的物理分区。 您指定的分区键是逻辑分区键。 Document Db 在内部使用散列将此逻辑分区键映射到物理分区。 所以有可能一堆逻辑分区共享同一个物理分区。 因此,为这些哈希范围分配了一个物理分区。

允许从 changefeed 读取的最小粒度是分区键范围。 因此,您必须查询您感兴趣的分区的分区键范围 ID。然后在 Changefeed 中查询该范围 ID 并过滤掉与分区 ID 无关的数据。

注意:如果特定分区已满,Document db 会透明地创建新的物理分区。因此,给定逻辑分区的分区键范围 ID 可能会随着时间而改变。

此链接详细解释了这一点: https://docs.microsoft.com/en-us/azure/cosmos-db/partition-data#partitioning-in-azure-cosmos-db

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    • 2020-02-11
    • 1970-01-01
    • 2019-06-03
    相关资源
    最近更新 更多