Count rows within partition in Azure table storage

后端 未结 5 997
余生分开走
余生分开走 2020-12-16 00:42

I\'ve seen various questions around SO about how to get the total row count of an Azure storage table, but I want to know how to get the number of rows with

5条回答
  •  余生分开走
    2020-12-16 00:58

    You could achieve this by leveraging atomic batch operation of azure table storage service pretty efficiently. For every partition have an additional entity with the same partition key and a specific row key like "PartitionCount" etc. That entity will have a single int (or long ) property Count.

    Every time you insert a new entity do an atomic batch operation to also increment the Count property of your partition counter entity. Your partition counter entity will have the same partition key with your data entity so that allows you to do an atomic batch operation with guaranteed consistency.

    Every time you delete an entity, go and decrement the Count property of the partition counter entity. Again in a batch execute operation so these 2 operations are consistent.

    If you want to just read the value of partition count then all you need to do is to make a single point query to the partition counter entity and its Count property will tell you the current count for that partition.

提交回复
热议问题