Skip to content

Commit

Permalink
Add support for isolated entities (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianburckhardt authored Apr 26, 2024
1 parent 7ca60ba commit 24efd54
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.DurableTask.Core" Version="2.15.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.12.0" />
<PackageReference Include="Microsoft.Azure.DurableTask.Core" Version="2.16.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.13.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp2.2' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class NetheriteProviderFactory : IDurabilityProviderFactory
readonly IServiceProvider serviceProvider;
readonly DurableTask.Netherite.ConnectionResolver connectionResolver;

readonly bool usesNewPassthroughMiddlewareForEntities;
readonly bool inConsumption;

// the following are boolean options that can be specified in host.json,
Expand Down Expand Up @@ -96,6 +97,14 @@ bool ReadBooleanSetting(string name) => this.options.StorageProvider.TryGetValue

this.TraceToConsole = ReadBooleanSetting(nameof(this.TraceToConsole));
this.TraceToBlob = ReadBooleanSetting(nameof(this.TraceToBlob));

WorkerRuntimeType runtimeType = platformInfo.GetWorkerRuntimeType();
if (runtimeType == WorkerRuntimeType.DotNetIsolated ||
runtimeType == WorkerRuntimeType.Java ||
runtimeType == WorkerRuntimeType.Custom)
{
this.usesNewPassthroughMiddlewareForEntities = true;
}
}

NetheriteOrchestrationServiceSettings GetNetheriteOrchestrationServiceSettings(string taskHubNameOverride = null, string connectionName = null)
Expand All @@ -109,12 +118,19 @@ NetheriteOrchestrationServiceSettings GetNetheriteOrchestrationServiceSettings(s
// different defaults for key configuration values.
int maxConcurrentOrchestratorsDefault = this.inConsumption ? 5 : 10 * Environment.ProcessorCount;
int maxConcurrentActivitiesDefault = this.inConsumption ? 20 : 25 * Environment.ProcessorCount;
int maxConcurrentEntitiesDefault = this.inConsumption ? 20 : 25 * Environment.ProcessorCount;
int maxEntityOperationBatchSizeDefault = this.inConsumption ? 50 : 5000;

// The following defaults are only applied if the customer did not explicitely set them on `host.json`
this.options.MaxConcurrentOrchestratorFunctions = this.options.MaxConcurrentOrchestratorFunctions ?? maxConcurrentOrchestratorsDefault;
this.options.MaxConcurrentActivityFunctions = this.options.MaxConcurrentActivityFunctions ?? maxConcurrentActivitiesDefault;
this.options.MaxEntityOperationBatchSize = this.options.MaxEntityOperationBatchSize ?? maxEntityOperationBatchSizeDefault;
this.options.MaxConcurrentOrchestratorFunctions ??= maxConcurrentOrchestratorsDefault;
this.options.MaxConcurrentActivityFunctions ??= maxConcurrentActivitiesDefault;
this.options.MaxConcurrentEntityFunctions ??= maxConcurrentEntitiesDefault;
this.options.MaxEntityOperationBatchSize ??= maxEntityOperationBatchSizeDefault;

if (this.usesNewPassthroughMiddlewareForEntities)
{
netheriteSettings.UseSeparateQueueForEntityWorkItems = true;
}

// copy all applicable fields from both the options and the storageProvider options
JsonConvert.PopulateObject(JsonConvert.SerializeObject(this.options), netheriteSettings);
Expand Down
2 changes: 1 addition & 1 deletion src/DurableTask.Netherite/DurableTask.Netherite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<PackageReference Include="Microsoft.Azure.EventHubs.Processor" Version="4.3.2" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.2.3" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.16.0" />
<PackageReference Include="Microsoft.Azure.DurableTask.Core" Version="2.15.1" />
<PackageReference Include="Microsoft.Azure.DurableTask.Core" Version="2.16.1" />
<PackageReference Include="Microsoft.FASTER.Core" Version="2.6.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
Expand Down
11 changes: 7 additions & 4 deletions src/DurableTask.Netherite/OrchestrationService/InstanceQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public class InstanceQuery
[DataMember]
internal bool PrefetchHistory { get; set; }

/// <summary>
/// Whether to exclude entities from the results.
/// </summary>
[DataMember]
internal bool ExcludeEntities { get; set; }

/// <summary>
/// Construct an instance query with the given parameters.
Expand All @@ -77,9 +82,6 @@ public InstanceQuery(

internal bool HasRuntimeStatus => this.RuntimeStatus != null && this.RuntimeStatus.Length > 0;

internal bool IsSet => this.HasRuntimeStatus || !string.IsNullOrWhiteSpace(this.InstanceIdPrefix)
|| !(this.CreatedTimeFrom is null) || !(this.CreatedTimeTo is null);

internal bool Matches(OrchestrationState targetState)
{
if (targetState == null)
Expand All @@ -88,7 +90,8 @@ internal bool Matches(OrchestrationState targetState)
return (!this.HasRuntimeStatus || this.RuntimeStatus.Contains(targetState.OrchestrationStatus))
&& (string.IsNullOrWhiteSpace(this.InstanceIdPrefix) || targetState.OrchestrationInstance.InstanceId.StartsWith(this.InstanceIdPrefix))
&& (!this.CreatedTimeFrom.HasValue || targetState.CreatedTime >= this.CreatedTimeFrom.Value)
&& (!this.CreatedTimeTo.HasValue || targetState.CreatedTime <= this.CreatedTimeTo.Value);
&& (!this.CreatedTimeTo.HasValue || targetState.CreatedTime <= this.CreatedTimeTo.Value)
&& (!this.ExcludeEntities || !DurableTask.Core.Common.Entities.IsEntityInstance(targetState.OrchestrationInstance.InstanceId));
}
}
}
Loading

0 comments on commit 24efd54

Please sign in to comment.