0

After going through Cosmos db documentation I am a bit confused about the change feed processor library.

  1. Lease document exists for each physical partition or logical partition?
  2. If I only have one host with multiple logical partition and a single physical partition. Will the change feed processor utilize multiple threads for each logical partition. I have cosmos change feed processor library implemented like this.
        var changeFeedProcessorInstance = new ChangeFeedProcessorBuilder()
          .options(cfOptions)
          .hostName(hostName)
          .feedContainer(container)
          .leaseContainer(leaseContainer)
          .handleChanges((List<JsonNode> docs) -> {
          for (JsonNode document : docs) {
            // Doing some processing
            }
          })
        .buildChangeFeedProcessor();
        changeFeedProcessorInstance.start()
          .subscribeOn(Schedulers.elastic())
          .doOnSuccess(aVoid -> {
           })
          .subscribe();

My assumption is due to Scheduler.elastic a new thread can be utilized per logical partition basis.

4

1 回答 1

2

当前的实现对每个物理分区使用 1 个租赁文档。

并行化基于租约。如果租用存储有 10 个租约,则最多可以分配 10 个主机,因为在任何给定时间点,1 个租约只能由单个主机拥有(您可以使用更少的主机,并且租约将平均分配)。

如果您的租约存储包含 1 个租约(因为该集合有 1 个物理分区),那么您最多可以监听 1 个主机中的更改。添加更多主机只会让多余的主机闲置。例如,如果由于使用了更多存储而导致集合增长,并且动态添加了新的物理分区,则将动态添加新的租约,并且额外的实例可以开始自动获取它们(如果可用的实例多于租约)。当两个维度发生变化时,该库会自动在主机上动态分配租约。

于 2020-08-07T00:05:16.503 回答