-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathSqlServerScalabilityProvider.cs
More file actions
105 lines (95 loc) · 3.9 KB
/
SqlServerScalabilityProvider.cs
File metadata and controls
105 lines (95 loc) · 3.9 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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
using DurableTask.SqlServer;
using Microsoft.Azure.WebJobs.Host.Scale;
using Microsoft.Extensions.Logging;
namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.FunctionsScale.Sql
{
/// <summary>
/// The SQL Server implementation of ScalabilityProvider.
/// Provides scale monitoring and target-based scaling for SQL Server backend.
/// </summary>
public class SqlServerScalabilityProvider : ScalabilityProvider
{
private readonly SqlOrchestrationService service;
private readonly string connectionName;
private readonly ILogger logger;
private readonly object initLock = new object();
private SqlServerMetricsProvider singletonSqlMetricsProvider;
/// <summary>
/// Initializes a new instance of the <see cref="SqlServerScalabilityProvider"/> class.
/// for managing scaling operations using a SQL Server–based orchestration service.
/// </summary>
/// <param name="service">The SQL orchestration service instance.</param>
/// <param name="connectionName">The name of the SQL connection.</param>
/// <param name="logger">The logger used for diagnostic output.</param>
/// <exception cref="ArgumentNullException">
/// Thrown if <paramref name="service"/> is null.
/// </exception>
public SqlServerScalabilityProvider(
SqlOrchestrationService service,
string connectionName,
ILogger logger)
: base("mssql", connectionName)
{
this.service = service ?? throw new ArgumentNullException(nameof(service));
this.connectionName = connectionName;
this.logger = logger;
}
/// <summary>
/// Gets the app setting containing the SQL Server connection string.
/// </summary>
public override string ConnectionName => this.connectionName;
/// <inheritdoc/>
public override bool TryGetScaleMonitor(
string functionId,
string functionName,
string hubName,
string targetConnectionName,
out IScaleMonitor scaleMonitor)
{
lock (this.initLock)
{
if (this.singletonSqlMetricsProvider == null)
{
// This is only called by the ScaleController, it doesn't run in the Functions Host process.
this.singletonSqlMetricsProvider = this.GetMetricsProvider(
hubName,
this.service,
this.logger);
}
scaleMonitor = new SqlServerScaleMonitor(functionId, hubName, this.singletonSqlMetricsProvider);
return true;
}
}
/// <inheritdoc/>
public override bool TryGetTargetScaler(
string functionId,
string functionName,
string hubName,
string targetConnectionName,
out ITargetScaler targetScaler)
{
lock (this.initLock)
{
if (this.singletonSqlMetricsProvider == null)
{
this.singletonSqlMetricsProvider = this.GetMetricsProvider(
hubName,
this.service,
this.logger);
}
targetScaler = new SqlServerTargetScaler(functionId, this.singletonSqlMetricsProvider);
return true;
}
}
internal SqlServerMetricsProvider GetMetricsProvider(
string hubName,
SqlOrchestrationService sqlOrchestrationService,
ILogger logger)
{
return new SqlServerMetricsProvider(sqlOrchestrationService);
}
}
}