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

Add-DbaAgDatabase - Fix stale cache issue #9101

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests-repl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ jobs:
- name: Run replication tests part 3
run: |
Import-Module ./dbatools.psd1 -Force
Invoke-Pester ./tests/gh-actions-repl-3.ps1 -Output Detailed -PassThru -Verbose
# Invoke-Pester ./tests/gh-actions-repl-3.ps1 -Output Detailed -PassThru -Verbose
8 changes: 0 additions & 8 deletions public/Add-DbaAgDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,6 @@ function Add-DbaAgDatabase {

try {
$replicaAgDb = Get-DbaAgDatabase -SqlInstance $replicaServerSMO[$replicaName] -AvailabilityGroup $AvailabilityGroup -Database $db.Name -EnableException
if ($null -eq $replicaAgDb) {
# We know the database has to exist by now, so we refresh the AvailabilityGroup object to update the cache that claims it doesn't.
$replicaAgDb = Get-DbaAgDatabase -Refresh -SqlInstance $replicaServerSMO[$replicaName] -AvailabilityGroup $AvailabilityGroup -Database $db.Name -EnableException
if ($null -eq $replicaAgDb) {
# throws to a catch
throw [System.Management.Automation.ItemNotFoundException]::New()
}
}
} catch {
$failure = $true
Stop-Function -Message "Failed to get database $($db.Name) on replica $replicaName." -ErrorRecord $_ -Continue
Expand Down
8 changes: 0 additions & 8 deletions public/Get-DbaAgDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@ function Get-DbaAgDatabase {
$InputObject += Get-DbaAvailabilityGroup -SqlInstance $SqlInstance -SqlCredential $SqlCredential -AvailabilityGroup $AvailabilityGroup
}

foreach ($ag in $InputObject) {
$null = $ag.Refresh()
# Calling AvilabilityReplica.Refresh() has the side effct of updating AvailabilityDatabases.
# calling AvailabilityDatabases.Refresh() alone is not enough
$null = $ag.AvailabilityReplicas.Refresh()
$null = $ag.AvailabilityDatabases.Refresh()
}

foreach ($db in $InputObject.AvailabilityDatabases) {
if ($Database) {
if ($db.Name -notin $Database) { continue }
Expand Down
3 changes: 3 additions & 0 deletions public/Get-DbaAvailabilityGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ function Get-DbaAvailabilityGroup {
}

foreach ($ag in $ags) {
# Refresh list of databases to fix #9094
$ag.AvailabilityDatabases.Refresh()

Add-Member -Force -InputObject $ag -MemberType NoteProperty -Name ComputerName -value $server.ComputerName
Add-Member -Force -InputObject $ag -MemberType NoteProperty -Name InstanceName -value $server.ServiceName
Add-Member -Force -InputObject $ag -MemberType NoteProperty -Name SqlInstance -value $server.DomainInstanceName
Expand Down
Loading