Can't Delete shard from Azure Elastic Pool

221 views Asked by At

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?

1

There are 1 answers

0
Nick Verschueren On

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.