-
Notifications
You must be signed in to change notification settings - Fork 325
Expand file tree
/
Copy pathAzureStorageOrchestrationServiceSettings.cs
More file actions
327 lines (274 loc) · 16.1 KB
/
AzureStorageOrchestrationServiceSettings.cs
File metadata and controls
327 lines (274 loc) · 16.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
// ----------------------------------------------------------------------------------
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------
namespace DurableTask.AzureStorage
{
using System;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using DurableTask.AzureStorage.Logging;
using DurableTask.AzureStorage.Partitioning;
using DurableTask.Core;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Queue;
using Microsoft.WindowsAzure.Storage.Table;
/// <summary>
/// Settings that impact the runtime behavior of the <see cref="AzureStorageOrchestrationService"/>.
/// </summary>
public class AzureStorageOrchestrationServiceSettings
{
internal const int DefaultPartitionCount = 4;
internal static readonly TimeSpan DefaultMaxQueuePollingInterval = TimeSpan.FromSeconds(30);
LogHelper logHelper;
/// <summary>
/// Gets or sets the name of the app.
/// </summary>
public string AppName { get; set; } = Utils.AppName;
/// <summary>
/// Gets or sets the number of messages to pull from the control queue at a time. The default is 32.
/// The maximum batch size supported by Azure Storage Queues is 32.
/// </summary>
public int ControlQueueBatchSize { get; set; } = 32;
/// <summary>
/// Gets or sets the number of control queue messages that can be buffered in memory at a time, at which
/// point the dispatcher will wait before dequeuing any additional messages. The default is 64.
/// </summary>
public int ControlQueueBufferThreshold { get; set; } = 64;
/// <summary>
/// Gets or sets the visibility timeout of dequeued control queue messages. The default is 5 minutes.
/// </summary>
public TimeSpan ControlQueueVisibilityTimeout { get; set; } = TimeSpan.FromMinutes(5);
/// <summary>
/// Gets or sets the <see cref="QueueRequestOptions"/> that are provided to all internal
/// usage of <see cref="CloudQueue"/> APIs for the control queue.
/// </summary>
[Obsolete("ControlQueueRequestOptions is deprecated. If you still need to configure QueueRequestOptions please open an issue at https://github.com/Azure/durabletask with the specific configurations options you need.")]
public QueueRequestOptions ControlQueueRequestOptions { get; set; }
/// <summary>
/// Gets or sets the visibility timeout of dequeued work item queue messages. The default is 5 minutes.
/// </summary>
public TimeSpan WorkItemQueueVisibilityTimeout { get; set; } = TimeSpan.FromMinutes(5);
/// <summary>
/// Gets or sets the <see cref="QueueRequestOptions"/> that are provided to all internal
/// usage of <see cref="CloudQueue"/> APIs for the work item queue.
/// </summary>
[Obsolete("WorkItemQueueRequestOptions is deprecated. If you still need to configure QueueRequestOptions please open an issue at https://github.com/Azure/durabletask with the specific configurations options you need.")]
public QueueRequestOptions WorkItemQueueRequestOptions { get; set; }
/// <summary>
/// Gets or sets the <see cref="TableRequestOptions"/> that are provided to all internal
/// usage of the <see cref="CloudTable"/> APIs for the history table.
/// </summary>
[Obsolete("HistoryTableRequestOptions is deprecated. If you still need to configure TableRequestOptions please open an issue at https://github.com/Azure/durabletask with the specific configurations options you need.")]
public TableRequestOptions HistoryTableRequestOptions { get; set; }
/// <summary>
/// Gets or sets the Azure Storage connection string.
/// </summary>
public string StorageConnectionString { get; set; }
/// <summary>
/// Gets or sets the prefix of the TrackingStore table name.
/// This property is only used when we have TrackingStoreStorageAccountDetails.
/// The default is "DurableTask"
/// </summary>
public string TrackingStoreNamePrefix { get; set; } = "DurableTask";
/// <summary>
/// Gets or sets the name of the task hub. This value is used to group related storage resources.
/// </summary>
public string TaskHubName { get; set; } = "Default";
/// <summary>
/// Gets or sets the maximum number of work items that can be processed concurrently on a single node.
/// The default value is 10.
/// </summary>
public int MaxConcurrentTaskActivityWorkItems { get; set; } = 10;
/// <summary>
/// Gets or sets the maximum number of orchestrations that can be processed concurrently on a single node.
/// The default value is 100.
/// </summary>
public int MaxConcurrentTaskOrchestrationWorkItems { get; set; } = 100;
/// <summary>
/// Gets or sets the maximum number of entity operation batches that can be processed concurrently on a single node.
/// The default value is 100.
/// </summary>
public int MaxConcurrentTaskEntityWorkItems { get; set; } = 100;
/// <summary>
/// Gets or sets the maximum dequeue count of any message before it is flagged as a "poison message".
/// The default value is 20.
/// </summary>
public int PoisonMessageDeuqueCountThreshold { get; set; } = 20;
/// <summary>
/// Gets or sets the maximum number of concurrent storage operations that can be executed in the context
/// of a single orchestration instance.
/// </summary>
public int MaxStorageOperationConcurrency { get; set; } = Environment.ProcessorCount * 25;
/// <summary>
/// Gets the maximum number of orchestrator actions to checkpoint at a time.
/// </summary>
public int MaxCheckpointBatchSize { get; set; }
/// <summary>
/// Gets or sets the identifier for the current worker.
/// </summary>
public string WorkerId { get; set; } = Environment.MachineName;
/// <summary>
/// Gets or sets the maximum number of orchestration partitions.
/// </summary>
public int PartitionCount { get; set; } = DefaultPartitionCount;
/// <summary>
/// Gets or sets a flag indicating whether to enable extended sessions.
/// </summary>
public bool ExtendedSessionsEnabled { get; set; }
/// <summary>
/// Gets or sets a flag indicating whether to automatically fetch large orchestration input and outputs
/// when it is stored in a compressed blob when retrieving orchestration state.
/// </summary>
public bool FetchLargeMessageDataEnabled { get; set; } = true;
/// <summary>
/// Gets or sets the number of seconds before an idle session times out.
/// </summary>
public TimeSpan ExtendedSessionIdleTimeout { get; set; } = TimeSpan.FromSeconds(30);
/// <summary>
/// Renew interval for all leases for partitions currently held.
/// </summary>
public TimeSpan LeaseRenewInterval { get; set; } = TimeSpan.FromSeconds(10);
/// <summary>
/// Interval when the current worker instance kicks off a task to compute if partitions are distributed evenly.
/// among known host instances.
/// </summary>
public TimeSpan LeaseAcquireInterval { get; set; } = TimeSpan.FromSeconds(10);
/// <summary>
/// Interval for which the lease is taken on Azure Blob representing a task hub partition in partition manager V1 (legacy partition manager) and V2 (safe partition manager).
/// The amount of time that a lease expiration deadline is extended on a renewal in partition manager V3 (table partition manager).
/// If the lease is not renewed within this within this timespan, it will expire and ownership of the partition may move to another worker.
/// </summary>
public TimeSpan LeaseInterval { get; set; } = TimeSpan.FromSeconds(30);
/// <summary>
/// Maximum interval for polling control and work-item queues.
/// </summary>
public TimeSpan MaxQueuePollingInterval { get; set; } = DefaultMaxQueuePollingInterval;
/// <summary>
/// If true, takes a lease on the task hub container, allowing for only one app to process messages in a task hub at a time.
/// </summary>
public bool UseAppLease { get; set; } = true;
/// <summary>
/// If UseAppLease is true, gets or sets the AppLeaaseOptions used for acquiring the lease to start the application.
/// </summary>
public AppLeaseOptions AppLeaseOptions { get; set; } = AppLeaseOptions.DefaultOptions;
/// <summary>
/// Gets or sets the Azure Storage Account details
/// If provided, this is used to connect to Azure Storage
/// </summary>
public StorageAccountDetails StorageAccountDetails { get; set; }
/// <summary>
/// Gets or sets the Storage Account Details for Tracking Store.
/// In case of null, StorageAccountDetails is applied.
/// </summary>
public StorageAccountDetails TrackingStoreStorageAccountDetails { get; set; }
/// <summary>
/// Should we carry over unexecuted raised events to the next iteration of an orchestration on ContinueAsNew
/// </summary>
public BehaviorOnContinueAsNew EventBehaviourForContinueAsNew { get; set; } = BehaviorOnContinueAsNew.Carryover;
/// <summary>
/// When true, will throw an exception when attempting to create an orchestration with an existing dedupe status.
/// </summary>
public bool ThrowExceptionOnInvalidDedupeStatus { get; set; } = false;
/// <summary>
/// Use the legacy partition management strategy, which improves performance at the cost of being less resiliant
/// to split brain.
/// </summary>
public bool UseLegacyPartitionManagement { get; set; } = false;
/// <summary>
/// Use the newer Azure Tables-based partition manager instead of the older Azure Blobs-based partition manager. The default value is <c>false</c>.
/// </summary>
public bool UseTablePartitionManagement { get; set; } = false;
/// <summary>
/// User serialization that will respect <see cref="IExtensibleDataObject"/>. Default is false.
/// </summary>
public bool UseDataContractSerialization { get; set; }
/// <summary>
/// Gets or sets the optional <see cref="ILoggerFactory"/> to use for diagnostic logging.
/// </summary>
public ILoggerFactory LoggerFactory { get; set; } = NoOpLoggerFactory.Instance;
/// <summary>
/// Gets or sets a value indicating whether to disable the ExecutionStarted de-duplication logic.
/// </summary>
public bool DisableExecutionStartedDeduplication { get; set; }
/// <summary>
/// Gets or sets an optional function to be executed before the app is recycled. Reason for shutdown is passed as a string parameter.
/// This can be used to perform any pending cleanup tasks or just do a graceful shutdown.
/// The function returns a <see cref="bool"/>. If 'true' is returned <see cref="Environment.FailFast(string)"/> is executed, if 'false' is returned,
/// process kill is skipped.
/// A wait time of 35 seconds will be given for the task to finish, if the task does not finish in required time, <see cref="Environment.FailFast(string)"/> will be executed.
/// </summary>
/// <remarks>Skipping process kill by returning false might have negative consequences if since Storage SDK might be in deadlock. Ensure if you return
/// false a process shutdown is executed by you.</remarks>
public Func<string, Task<bool>> OnImminentFailFast { get; set; } = (message) => Task.FromResult(true);
/// <summary>
/// Gets or sets the number of times we allow the timeout to be hit before recycling the app. We set this
/// to a fixed value to prevent building up an infinite number of deadlocked tasks and leak resources.
/// </summary>
public int MaxNumberOfTimeoutsBeforeRecycle { get; set; } = 5;
/// <summary>
/// Gets or sets the number of seconds before a request to Azure Storage is considered as timed out.
/// </summary>
public TimeSpan StorageRequestsTimeout { get; set; } = TimeSpan.FromMinutes(2);
/// <summary>
/// Gets or sets the window duration (in seconds) in which we count the number of timed out request before recycling the app.
/// </summary>
public TimeSpan StorageRequestsTimeoutCooldown { get; set; } = TimeSpan.FromMinutes(5);
/// <summary>
/// Gets or Sets an optional custom type binder used when trying to deserialize queued messages
/// </summary>
public ICustomTypeBinder CustomMessageTypeBinder { get; set; }
/// <summary>
/// Returns bool indicating is the TrackingStoreStorageAccount has been set.
/// </summary>
public bool HasTrackingStoreStorageAccount => this.TrackingStoreStorageAccountDetails != null;
internal string HistoryTableName => this.HasTrackingStoreStorageAccount ? $"{this.TrackingStoreNamePrefix}History" : $"{this.TaskHubName}History";
internal string InstanceTableName => this.HasTrackingStoreStorageAccount ? $"{this.TrackingStoreNamePrefix}Instances" : $"{this.TaskHubName}Instances";
internal string PartitionTableName => $"{this.TaskHubName}Partitions";
/// <summary>
/// Gets an instance of <see cref="LogHelper"/> that can be used for writing structured logs.
/// </summary>
internal LogHelper Logger
{
get
{
if (this.logHelper == null)
{
this.logHelper = new LogHelper(this.LoggerFactory.CreateLogger("DurableTask.AzureStorage"));
}
return this.logHelper;
}
}
/// <summary>
/// Gets or sets the limit on the number of entity operations that should be processed as a single batch.
/// A null value indicates that no particular limit should be enforced.
/// </summary>
/// <remarks>
/// Limiting the batch size can help to avoid timeouts in execution environments that impose time limitations on work items.
/// If set to 1, batching is disabled, and each operation executes as a separate work item.
/// </remarks>
/// <value>
/// A positive integer, or null.
/// </value>
public int? MaxEntityOperationBatchSize { get; set; } = null;
/// <summary>
/// Gets or sets the time window within which entity messages get deduplicated and reordered.
/// If set to zero, there is no sorting or deduplication, and all messages are just passed through.
/// </summary>
public int EntityMessageReorderWindowInMinutes { get; set; } = 30;
/// <summary>
/// Whether to use separate work item queues for entities and orchestrators.
/// This defaults to false, to avoid issues when using this provider from code that does not support separate dispatch.
/// Consumers that require separate dispatch (such as the new out-of-proc v2 SDKs) must set this to true.
/// </summary>
public bool UseSeparateQueueForEntityWorkItems { get; set; } = false;
}
}