Reputation: 53
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?
Upvotes: 0
Views: 225
Reputation: 1
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
shardMap.DeleteShard(shard);
to something like:
var shard = _shardMap.GetShard(pointMapping.Shard.Location);
_shardMap.DeleteShard(shard);
You can forget about the Thread.Sleep, this is effective immediately.
Upvotes: 0