static async Task HideTimeoutsOfCurrentSegment(CloudTable endpointTimeoutTable, IEnumerable <TimeoutDataEntity> timeoutsOfSegment, string uniqueHiddenEndpointName) { // with batching we can at least efficiently insert long hideByPartitionKeyBatchSize = 0; var hideByPartitionBatch = new TableBatchOperation(); var hideTasks = new List <Task>(); foreach (var entitiesInTheSamePartition in timeoutsOfSegment.GroupBy(x => x.PartitionKey)) { foreach (var timeoutDataEntity in entitiesInTheSamePartition) { // entries with Guid as partition key should never be modified. We are only interested in the query entities if (Guid.TryParse(timeoutDataEntity.PartitionKey.AsSpan(), out _)) { continue; } // we don't want to preserve the etag and we always want to win timeoutDataEntity.ETag = "*"; // Fix the hiding part timeoutDataEntity.OwningTimeoutManager = uniqueHiddenEndpointName; var entitySize = timeoutDataEntity.CalculateSize(); // the batch can have max 100 items and max 4 MB of data // the partition key for all operations in the batch has to be the same if (hideByPartitionKeyBatchSize + entitySize > MaxPayloadPerBatchOperation || hideByPartitionBatch.Count == MaxOperationsPerBatchOperation) { hideTasks.Add(endpointTimeoutTable.ExecuteBatchAsync(hideByPartitionBatch.Clone())); hideByPartitionKeyBatchSize = 0; hideByPartitionBatch.Clear(); } hideByPartitionKeyBatchSize += entitySize; var tableOperation = TableOperation.Merge(timeoutDataEntity); SetEchoContentTo(tableOperation, false); hideByPartitionBatch.Add(tableOperation); } if (hideByPartitionBatch.Count > 0) { hideTasks.Add(endpointTimeoutTable.ExecuteBatchAsync(hideByPartitionBatch.Clone())); } hideByPartitionBatch.Clear(); hideByPartitionKeyBatchSize = 0; } if (hideTasks.Count > 0) { await Task.WhenAll(hideTasks); } }