-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqlServerDsc: Resources work with automatic seeding #1915
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1915 +/- ##
====================================
- Coverage 92% 91% -1%
====================================
Files 91 91
Lines 7761 7788 +27
====================================
+ Hits 7149 7164 +15
- Misses 612 624 +12
|
Hi @johlju, can you please look at PR? Can you please also rerun the verification pipeline because two agents stopped to respond, and the whole pipeline is marked as failed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just made.a quick review and found some thing you can start with. Need to do more review. I only commented on the first code file, but the same comments are for the other as well.
Reviewed 1 of 5 files at r1, all commit messages.
Reviewable status: 1 of 6 files reviewed, 5 unresolved discussions (waiting on @Sidoran)
CHANGELOG.md
line 54 at r3 (raw file):
(tested v21.0.17099). The parameter will be ignored if SQLPS module will be used. >>>>>>> upstream/main
This seems to have been leftover.
Code quote:
>>>>>>> upstream/main
source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1
line 99 at r3 (raw file):
$alwaysOnAvailabilityGroupResource.Add('DatabaseHealthTrigger', $availabilityGroup.DatabaseHealthTrigger) $alwaysOnAvailabilityGroupResource.Add('DtcSupportEnabled', $availabilityGroup.DtcSupportEnabled) if ( $sqlModuleName -eq 'SQLServer' )
We should always return this property, either with a value or $null.
Code quote:
if ( $sqlModuleName -eq 'SQLServer' )
{
$alwaysOnAvailabilityGroupResource.Add('SeedingMode', $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode)
}
source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1
line 359 at r3 (raw file):
} if ( ( $sqlMajorVersion -ge 13 ) -and ( $sqlModuleName -eq 'SQLServer' ) )
If there is a chance that the command not always has the parameter then it would be better to check if the actual command supports the parameter. So here we can do this instead:
(Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode')
Code quote:
if ( ( $sqlMajorVersion -ge 13 ) -and ( $sqlModuleName -eq 'SQLServer' ) )
source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1
line 524 at r3 (raw file):
} if ( ( $submittedParameters -contains 'SeedingMode' ) -and ( $sqlMajorVersion -ge 13 ) -and ( $SeedingMode -ne $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode ) -and ( $sqlModuleName -eq 'SQLServer' ) )
Could we split the if-statement into at least two to make it easier to read? For example first check if seeding mode should be enforce, then if it is correct version and the property exist.
Code quote:
if ( ( $submittedParameters -contains 'SeedingMode' ) -and ( $sqlMajorVersion -ge 13 ) -and ( $SeedingMode -ne $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode ) -and ( $sqlModuleName -eq 'SQLServer' ) )
source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1
line 524 at r3 (raw file):
} if ( ( $submittedParameters -contains 'SeedingMode' ) -and ( $sqlMajorVersion -ge 13 ) -and ( $SeedingMode -ne $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode ) -and ( $sqlModuleName -eq 'SQLServer' ) )
If there is a chance that the type does not contain the property, we should check for that instead of looking for the module name. Like:
($availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName] | Get-Member -MemberType Property).Name -contains 'SeedingMode'
Code quote:
$sqlModuleName -eq 'SQLServer'
@johlju, I made the changes according to your comments. |
Only way is to connect to the replica (e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 5 files at r1, 1 of 1 files at r3, 3 of 3 files at r4, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @Sidoran)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 5 of 6 files reviewed, 1 unresolved discussion (waiting on @Sidoran)
source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1
line 359 at r5 (raw file):
} if ( ( $sqlMajorVersion -ge 13 ) -and (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') )
Instead of having this check, I thing we should have this check one time at the beginning of the Set-method. If the user passes SeedingMode and version is lower than 13 then it should throw an exception saying that "using SeedingMode for verison lower than 13 is not supported".
Code quote:
$sqlMajorVersion -ge 13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 5 of 6 files reviewed, 2 unresolved discussions (waiting on @Sidoran)
a discussion (no related file):
Is it possible for you to add unit tests to cover the changed (added) code paths?
Previously, johlju (Johan Ljunggren) wrote…
The Major version check at the beginning will break the current behavior for the BasicAvailabilityGroup, DatabaseHealthTrigger and DtcSupportEnabled availability group options. Previously, johlju (Johan Ljunggren) wrote…> Is it possible for you to add unit tests to cover the changed (added) code paths?I've already made some unit test modifications for the SqlAGReplica resource. The SqlAg, as I see, is uncovered by pester because of migration to Pester 5.x Previously, johlju (Johan Ljunggren) wrote…> Only way is to connect to the replica (e.g. `Connect-SqlDscDatabaseEngine` to get the `Server` object. The set the `SeedingMode` property on the right object. But that might be a bigger (too big?) change?Sorry, I didn't get your Idea. The |
I haven’t look at the code so not sure, but I meant: “if major version is less than 13 and PSBoundParameters contain SeedingMode then throw an exception telling the user to not specify SeedingMode as it is not supported”. I might be wrong but I thought you had that check because it was supported in lower major versions? |
I meant set all the settings using the SMO objects directly (if possible) and not use any commands from either module. It was the only way I could see around that the Microsoft SQL Server Team has not added the parameter to the command in the module SQLPS. But I’m good with the current way of checking for the parameter you added. Though maybe we should have outputted a warning message telling the user that they should use the module SqlServer if they pass the parameter SeedingMode. 🤔 |
Yes, no need to add unit tests for SqlAg if it hasn’t been converted. It probably need to be heavily refactored then anyway. |
Auto seeding was introduced in SQL 2016. When I did changes, I was based on existing behavior in a code, as you may see here SqlServerDsc/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 Lines 367 to 372 in a86039c
|
Ah, I see. Then we continue on the same path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r5, 1 of 1 files at r6, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @Sidoran)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r8, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @Sidoran)
Pull Request (PR) description
SeedingMode
that will set the SeedingMode for the SQLServer 2016 and higher. This parameter can only be used together with the
module SqlServer installed (tested v21.0.17099). The parameter will be
ignored if SQLPS module will be used.
SeedingMode
that will set the SeedingMode for the SQLServer 2016 and higher. This parameter can only be used together with the
module SqlServer installed (tested v21.0.17099). The parameter will be
ignored if SQLPS module will be used.
This Pull Request (PR) fixes the following issues
Task list
file CHANGELOG.md. Entry should say what was changed and how that
affects users (if applicable), and reference the issue being resolved
(if applicable).
This change is