From f040a3ba6226f0a4107b61ed6669be483fc2196b Mon Sep 17 00:00:00 2001 From: Cam Date: Fri, 17 May 2024 17:59:02 +0200 Subject: [PATCH] fix same rowkey error in batch --- Sync.cs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Sync.cs b/Sync.cs index 9397ec4..cc95160 100644 --- a/Sync.cs +++ b/Sync.cs @@ -167,6 +167,11 @@ await BatchQueueProcess(tableActionQueue_Users, private static async Task BatchQueueProcess(ConcurrentQueue Queue, TableClient tableClient, CancellationToken ct) { List BatchTransactions = new List(); + + // Used to re-queue transactions that cannot be put in this batch + // Such as transactions with a row key that is already present in the batch (cannot perform within the same batch) + + List RequeueTransactions = new List(); // Take items out of the queue until it's empty or the max batch size hit while (!Queue.IsEmpty && BatchTransactions.Count < _maxTableBatchSize) @@ -174,7 +179,24 @@ private static async Task BatchQueueProcess(ConcurrentQueue + x.Entity.PartitionKey == dequeued.Entity.PartitionKey && + x.Entity.RowKey == dequeued.Entity.RowKey)) + { + // Requeue the transaction for next batch as it is already existing in this batch + RequeueTransactions.Add(dequeued); + } + else + { + BatchTransactions.Add(dequeued); + } + + } + } if (BatchTransactions.Any()) @@ -200,6 +222,13 @@ private static async Task BatchQueueProcess(ConcurrentQueue