我有一个使用多租户的应用程序,每个租户模型一个数据库。我使用 Shardmap 来跟踪租户数据库的位置。当我尝试创建一个弹性作业来运行迁移时,我将 AzSqlElasticJobTarget 设置为我的 shardmap db,一切运行良好并且作业被创建,但随后作业失败,我收到以下错误:
Failed to determine members of SqlShardMapTarget (server name '***', server location '***.database.windows.net', database '***', shard map '***'): Data structures for shard map manager persistence do not exist at the target location.
我已经去了数据库,上面有一个 __ShardManagement Scheme,其中包含所有分片的信息。
# Create TenantsPoolGroup target group
$TenantsGroup = $JobAgent | New-AzSqlElasticJobTargetGroup -Name 'TargetGroup'
$TenantsGroup | Add-AzSqlElasticJobTarget -ServerName $catalogServerName -ShardMapName $config.CatalogShardMapName -DatabaseName $config.CatalogDatabaseName -RefreshCredentialName $config.JobCredentialName
Write-Output "Creating a new job"
$timestamp = Get-Date -Format o | foreach {$_ -replace ":", "_"}
$timestamp = $timestamp | foreach {$_ -replace "\.", "_"}
$timestamp = $timestamp | foreach {$_ -replace "-", "_"}
$JobName = "Migration-$timestamp"
$Job = $JobAgent | New-AzSqlElasticJob -Name $JobName -RunOnce
Write-Output "Creating job steps"
$SqlText = Get-Content -Path "$PSScriptRoot\script-entities.sql" -Raw
$Job | Add-AzSqlElasticJobStep -Name "step1" -TargetGroupName 'TargetGroup' -CredentialName $config.JobCredentialName -CommandText $SqlText
Write-Output "Start a new execution of the job..."
$JobExecution = $Job | Start-AzSqlElasticJob