Have troubles with deleting shard from shard map in azure Elastic pool
var isMapKeyExists = shardMap.TryGetMappingForKey(tenantId, out PointMapping<int> pointMapping);
if(pointMapping.Status == MappingStatus.Online)
{
pointMapping = shardMap.MarkMappingOffline(pointMapping);
}
if (isMapKeyExists)
{
shardMap.DeleteMapping(pointMapping);
Thread.Sleep(TimeSpan.FromSeconds(30));
if (enableDedicatedDb)
{
shardMap.DeleteShard(shard);
}
}
So firstly i just deleted mappings from shardMap, but once i get to deleteShard from shardMap i get following:
Shard '[DataSource=*** Database=Test21]' belonging to shard map 'UserIdShardMap' has been updated in store. Error occurred while executing stored procedure '__ShardManagement.spBulkOperationShardsGlobalBegin' for operation 'DeleteShard'. This can occur if another concurrent user updates the shard. Perform a GetShard operation for the shard location to obtain the updated instance. Could anyone help me with it, please?
This is probably not relevant anymore, but for reference: the exception points to a kind of concurrency violation in the catalog. To get around it, you must change
to something like:
You can forget about the Thread.Sleep, this is effective immediately.