diff --git a/src/DurableTask.AzureStorage/EntityTrackingStoreQueries.cs b/src/DurableTask.AzureStorage/EntityTrackingStoreQueries.cs index 3ba243908..1bf9bfadb 100644 --- a/src/DurableTask.AzureStorage/EntityTrackingStoreQueries.cs +++ b/src/DurableTask.AzureStorage/EntityTrackingStoreQueries.cs @@ -21,6 +21,7 @@ namespace DurableTask.AzureStorage using System.Text; using System.Threading; using System.Threading.Tasks; + using Azure; using DurableTask.AzureStorage.Tracking; using DurableTask.Core; using DurableTask.Core.Entities; @@ -56,7 +57,7 @@ public EntityTrackingStoreQueries( CancellationToken cancellation = default(CancellationToken)) { await this.ensureTaskHub(); - OrchestrationState? state = (await this.trackingStore.GetStateAsync(id.ToString(), allExecutions: false, fetchInput: includeState)).FirstOrDefault(); + OrchestrationState? state = await this.trackingStore.GetStateAsync(id.ToString(), allExecutions: false, fetchInput: includeState).FirstOrDefaultAsync(); return await this.GetEntityMetadataAsync(state, includeStateless, includeState); } @@ -87,7 +88,10 @@ public async override Task QueryEntitiesAsync(EntityQuery fil do { - DurableStatusQueryResult result = await this.trackingStore.GetStateAsync(condition, filter.PageSize ?? 100, continuationToken, cancellation); + Page? page = await this.trackingStore.GetStateAsync(condition, cancellation).AsPages(continuationToken, filter.PageSize ?? 100).FirstOrDefaultAsync(); + DurableStatusQueryResult result = page != null + ? new DurableStatusQueryResult { ContinuationToken = page.ContinuationToken, OrchestrationState = page.Values } + : new DurableStatusQueryResult { OrchestrationState = Array.Empty() }; entityResult = await ConvertResultsAsync(result.OrchestrationState); continuationToken = result.ContinuationToken; } @@ -139,7 +143,10 @@ async ValueTask> ConvertResultsAsync(IEnumerable? states = await this.trackingStore.GetStateAsync(condition, cancellation).AsPages(continuationToken, 100).FirstOrDefaultAsync(); + DurableStatusQueryResult page = states != null + ? new DurableStatusQueryResult { ContinuationToken = states.ContinuationToken, OrchestrationState = states.Values } + : new DurableStatusQueryResult { OrchestrationState = Array.Empty() }; continuationToken = page.ContinuationToken; var tasks = new List(); @@ -174,8 +181,8 @@ async Task DeleteIdleOrchestrationEntity(OrchestrationState state) async Task CheckForOrphanedLockAndFixIt(OrchestrationState state, string lockOwner) { - OrchestrationState? ownerState - = (await this.trackingStore.GetStateAsync(lockOwner, allExecutions: false, fetchInput: false)).FirstOrDefault(); + OrchestrationState? ownerState + = await this.trackingStore.GetStateAsync(lockOwner, allExecutions: false, fetchInput: false).FirstOrDefaultAsync(); bool OrchestrationIsRunning(OrchestrationStatus? status) => status != null && (status == OrchestrationStatus.Running || status == OrchestrationStatus.Suspended); diff --git a/src/DurableTask.AzureStorage/Tracking/OrchestrationInstanceStatusQueryCondition.cs b/src/DurableTask.AzureStorage/Tracking/OrchestrationInstanceStatusQueryCondition.cs index 9ef2c20ca..0f47a3979 100644 --- a/src/DurableTask.AzureStorage/Tracking/OrchestrationInstanceStatusQueryCondition.cs +++ b/src/DurableTask.AzureStorage/Tracking/OrchestrationInstanceStatusQueryCondition.cs @@ -145,10 +145,7 @@ internal ODataCondition ToOData() } else if (this.ExcludeEntities) { - conditions.Add(TableQuery.CombineFilters( - TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThan, "@"), - TableOperators.Or, - TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, "A"))); + conditions.Add($"{nameof(OrchestrationInstanceStatus.PartitionKey)} lt '@' or {nameof(OrchestrationInstanceStatus.PartitionKey)} ge 'A'"); } if (this.InstanceId != null)