Scripting a Distributed Availability Group throws ArgumentException: Unexpected value for enumeration type AvailabilityGroupAutomatedBackupPreference
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 78/100
調査の方向性
src/Microsoft/SqlServer/Management/Smo/AvailabilityGroupBase.cs から開始し、特に ScriptGroupOption、ScriptCreateGroupOptions、GetAutomatedBackupPreferenceScript を確認します。その後、src/Microsoft/SqlServer/Management/SqlEnum/xml/AvailabilityGroup.xml の sentinel マッピングを調べます。分散可用性グループのスクリプト生成を再現し、生成された CREATE ステートメントで sentinel に対応する3つのオプションが省略され、正常に実行できることを検証します。
索引モデルが issue の本文から書いたものです。
説明
AvailabilityGroup.Script() / Scripter.EnumScript() has an explicit code path for Distributed Availability Groups (ScriptCreate scripts AVAILABILITY GROUP ON ... LISTENER_URL ...), but scripting a DAG fetched from a live server always throws before that path is reached:
System.ArgumentException: Unexpected value for enumeration type AvailabilityGroupAutomatedBackupPreference.
at Microsoft.SqlServer.Management.Smo.AvailabilityGroup.GetAutomatedBackupPreferenceScript(AvailabilityGroupAutomatedBackupPreference preference)
at Microsoft.SqlServer.Management.Smo.AvailabilityGroup.ScriptGroupOption(Boolean scriptAll, String propertyName, SqlServerVersionInternal targetServerVersion)
at Microsoft.SqlServer.Management.Smo.AvailabilityGroup.<>c__DisplayClass83_0.<ScriptCreateGroupOptions>b__1(String propertyName)
...
at Microsoft.SqlServer.Management.Smo.AvailabilityGroup.ScriptCreate(StringCollection query, ScriptingPreferences sp)
Repro
# On the primary of any distributed availability group:
$server = New-Object Microsoft.SqlServer.Management.Smo.Server("<instance>")
$dag = $server.AvailabilityGroups["<dag name>"]
$dag.Script() # or: (New-Object Microsoft.SqlServer.Management.Smo.Scripter($server)).EnumScript($dag)
Originally reported against dbatools (Export-DbaScript calls EnumScript): dataplat/dbatools#9220 has a full stack trace from a user's environment. dbatools now works around it by hand-building the DAG DDL from the AvailabilityReplicas properties (dataplat/dbatools#10216).
Mechanism
For a distributed availability group, sys.availability_groups returns NULL for automated_backup_preference, failure_condition_level and health_check_timeout — those options do not apply to DAGs. The enumerator metadata maps each NULL to a sentinel (AvailabilityGroup.xml#L53-L55):
<property name="AutomatedBackupPreference" ...>ISNULL(AG.automated_backup_preference, 4)</property>
<property name="FailureConditionLevel" ...>ISNULL(AG.failure_condition_level, 6)</property>
<property name="HealthCheckTimeout" ...>ISNULL(AG.health_check_timeout, -1)</property>
4 is AvailabilityGroupAutomatedBackupPreference.Unknown and 6 is AvailabilityGroupFailureConditionLevel.Unknown — both defined, [Browsable(false)], documented as "the replica may not be able to communicate with the cluster".
ScriptCreateGroupOptions iterates all creatable group options with scriptAll: true, and ScriptGroupOption only skips a property when prop.IsNull — a sentinel value is not null, so it is scripted. For AutomatedBackupPreference that reaches GetAutomatedBackupPreferenceScript, whose switch has no case for Unknown and throws in default.
The throw is only the first of three problems. If it were bypassed, the same ScriptGroupOption would emit the other two sentinels verbatim into the CREATE statement:
FAILURE_CONDITION_LEVEL = 6(script.Append((int)FailureConditionLevel); valid server range is 1–5)HEALTH_CHECK_TIMEOUT = -1(minimum accepted value is 15000)
so the generated DDL would fail on the server even without the exception.
The same applies to any regular AG queried from a node where WSFC state is unavailable, since that is what the sentinels were originally introduced for — the DAG case just makes it deterministic.
Suggested fix
Treat the three sentinel values like prop.IsNull in ScriptGroupOption and skip the clause: AutomatedBackupPreference == Unknown, FailureConditionLevel == Unknown, HealthCheckTimeout < 0. ScriptCreateGroupOptions already tolerates empty per-option scripts, and the options are all optional in the DDL, so omitting them is correct for both the DAG case and the cluster-state-unavailable case.
Happy to submit a PR along those lines if that helps.
This was created by Claude and reviewed by Andreas Jordan.
- 主要言語
- C#
- スター
- 143
- フォーク
- 28
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/sqlmanagementobjects のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 74/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
microsoft/sqlmanagementobjects の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
dotnet/AspNetCore.Docs#37699 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
SubtitleEdit/subtitleedit#15108 · コメント 1 件 ·
-
area/docs-content Bug pulumi/docs
難易度 1/5 1〜3時間 初心者へのやさしさ 94/100
-
agentic-workflows untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100