我正在尝试使用 Microsoft在此处提供的示例应用程序。这适用于创建新数据库及其分片等。但是当我尝试使用单个分片将其连接到现有数据库时它会失败。
它有一个名为的类ShardManagementUtils
,它提供了以下RangeShardMap<T>
从分片 azure 数据库中检索的方法:
/// <summary>
/// Creates a new Range Shard Map with the specified name, or gets the Range Shard Map if it already exists.
/// </summary>
public static RangeShardMap<T> CreateOrGetRangeShardMap<T>(ShardMapManager shardMapManager, string shardMapName)
{
// Try to get a reference to the Shard Map.
RangeShardMap<T> shardMap;
bool shardMapExists = shardMapManager.TryGetRangeShardMap(shardMapName, out shardMap);
if (shardMapExists)
{
ConsoleUtils.WriteInfo("Shard Map {0} already exists", shardMap.Name);
}
else
{
// The Shard Map does not exist, so create it
shardMap = shardMapManager.CreateRangeShardMap<T>(shardMapName);
ConsoleUtils.WriteInfo("Created Shard Map {0}", shardMap.Name);
}
return shardMap;
}
我的数据库中有一个分片,分片数据保存在Global Shard Map (GSM)
. 当我通过传入正确的ShardMapManager
and调用此方法时shardMapName
,会发生以下情况:
//this return FALSE, it should not
bool shardMapExists = shardMapManager.TryGetRangeShardMap(shardMapName, out shardMap);
//Then this line throw exception that map with this name already exists
shardMap = shardMapManager.CreateRangeShardMap<T>(shardMapName);
抛出的异常如下:
An unhandled exception of type 'Microsoft.Azure.SqlDatabase.ElasticScale.ShardManagement.ShardManagementException' occurred in Microsoft.Azure.SqlDatabase.ElasticScale.Client.dll
Additional information: Shard map with name 'UserId' already exists in the store. Error occurred while executing stored procedure '__ShardManagement.spAddShardMapGlobal' for operation 'CreateRangeShardMap'.
所以我检查了__ShardManagement.ShardMapsGlobal
表格,其中包含分片映射信息。那么如果第一行RangShardMap
已经存在,为什么它不会检索呢?
我究竟做错了什么。非常感谢您的帮助。