Skip to content
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

SqlAGReplica: Tries to modify AG properties that were not specified #1244

Closed
codykonior opened this issue Oct 18, 2018 · 3 comments · Fixed by #1302
Closed

SqlAGReplica: Tries to modify AG properties that were not specified #1244

codykonior opened this issue Oct 18, 2018 · 3 comments · Fixed by #1302
Labels
bug The issue is a bug.

Comments

@codykonior
Copy link
Contributor

codykonior commented Oct 18, 2018

Details of the scenario you tried and the problem that is occurring

I'm trying to use SQLAGReplica to modify a property (ReadOnlyRoutingConnectionUrl) on an AG after it has been created.

This fails because the SQLAGReplica resource sets two default properties:

  • AvailabilityMode = AsynchronousCommit
  • FailoverMode = Manual

This means it tries to set them every time you access the AG even though you may only want to modify one property.

Verbose logs showing the problem

VERBOSE: [SEC1N1]:                            [[SqlAGReplica]Blah] Connected to SQL instance 'DAC1N1'.
VERBOSE: [SEC1N1]:                            [[SqlAGReplica]Blah] The recommended account 'NT SERVICE\ClusSvc' is missing one or more of the following permissions: Trying with 'NT AUTHORITY\SYSTEM'.
VERBOSE: [SEC1N1]:                            [[SqlAGReplica]Blah] Getting the effective permissions for the login 'NT AUTHORITY\SYSTEM' on 'MSSQLSERVER'.
VERBOSE: [SEC1N1]:                            [[SqlAGReplica]Blah] Found PowerShell module SqlServer already imported in the session.
VERBOSE: [SEC1N1]:                            [[SqlAGReplica]Blah] Connected to SQL instance 'SEC1N1'.
VERBOSE: [SEC1N1]:                            [[SqlAGReplica]Blah] The cluster login 'NT AUTHORITY\SYSTEM' has the required permissions.
VERBOSE: [SEC1N1]: LCM:  [ End    Set      ]  [[SqlAGReplica]Blah]  in 3.0580 seconds.
PowerShell DSC resource MSFT_SqlAGReplica  failed to execute Set-TargetResource functionality with error message: System.InvalidOperationException: Failed to alter the availability group replica 'DAC1N1'. ---> 
System.Management.Automation.MethodInvocationException: Exception calling "Alter" with "0" argument(s): "Alter failed for Availability Replica 'DAC1N1'. " ---> Microsoft.SqlServer.Management.Smo.FailedOperationException: Alter 
failed for Availability Replica 'DAC1N1'.  ---> Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: 
The Alter operation is not allowed.  The operation attempted to change the configuration of availability replica 'DAC1N1' to the asynchronous-commit availability mode with automatic failover, which is an invalid configuration.  
Either change the failover mode to manual or the availability mode to synchronous commit, and retry the operation.
   at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
   at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)
   --- End of inner exception stack trace ---
   at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)
   at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType, Boolean retry)
   at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries, Boolean retry)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.AlterImplFinish(StringCollection alterQuery, ScriptingPreferences sp)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.AlterImpl()
   --- End of inner exception stack trace ---
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.AlterImpl()
   at Microsoft.SqlServer.Management.Smo.AvailabilityReplica.Alter()
   at CallSite.Target(Closure , CallSite , AvailabilityReplica )
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   --- End of inner exception stack trace --- 
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : localhost
 
VERBOSE: [SEC1N1]: LCM:  [ End    Set      ]
The SendConfigurationApply function did not succeed.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost
 
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 5.901 seconds

Suggested solution to the issue

The defaults on the parameters should be removed. If the resource detects it needs to add an AG Replica it can check for nulls in these properties and then set the same defaults. But if the replica is being modified, the existing settings won't be changed for these because there's no default set.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

$configurationData = @{
    AllNodes = @(
        @{
            NodeName = '*'
            PsDscAllowPlainTextPassword = $true
            PsDscAllowDomainUser = $true
        }
        @{
         NodeName = 'localhost'
        }
    )
}

configuration Blah {
    param(
        $Credential
    )
    Import-DscResource -Module SqlServerDsc

    Node $AllNodes.NodeName {    
        SqlAGReplica Blah {
            AvailabilityGroupName = 'AG1'
            ServerName = 'SEC1N1'
            InstanceName = 'MSSQLSERVER'
            Name = 'DAC1N1'
            ReadOnlyRoutingConnectionUrl = 'tcp://DAC1N1.lab.com:1433'
            # AvailabilityMode = 'SynchronousCommit'
            # FailoverMode = 'Automatic'
            PsDscRunAsCredential = $Credential
        }
    }
}

if (!$credential) { $credential = Get-Credential LAB\LocalAdministrator }
Blah -Credential $credential -ConfigurationData $configurationData
Start-DscConfiguration -Force -Wait -Verbose -Path Blah

SQL Server edition and version the target node is running

2012

SQL Server PowerShell modules present on the target node

Current

The operating system the target node is running

2012

Version and build of PowerShell the target node is running

WMF 5.1

Version of the DSC module that was used ('dev' if using current dev branch)

dev

@johlju
Copy link
Member

johlju commented Oct 25, 2018

Agree that is should be able to set these properties individually, labeling it as a bug.

@johlju johlju added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Oct 25, 2018
@fculpo
Copy link

fculpo commented Feb 27, 2019

Hi,

Any news on this ?
I have the smae issue, each time i replay the dsc module the Alter on AG fails

@codykonior
Copy link
Contributor Author

codykonior commented Mar 2, 2019

I have a PR in to fix database ownership; after that's merged I will resubmit my PR for read-only routing which fixes (at least some of) this as part of it. So not long now.

johlju pushed a commit that referenced this issue Mar 10, 2019
- Changes to SqlAG
  - Updated documentation on the behavior of defaults as they only apply when
    creating a group.
- Changes to SqlAGReplica
  - AvailabilityMode, BackupPriority, and FailoverMode defaults only apply when
    creating a replica not when making changes to an existing replica. Explicit
    parameters will still change existing replicas (issue #1244).
  - ReadOnlyRoutingList now gets updated without throwing an error on the first
    run (issue #518).
@johlju johlju removed the help wanted The issue is up for grabs for anyone in the community. label Apr 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants