We have an entity in our system called an "identification program." This is also our boundary, each identification program is stored in its own fragment, so the fragment identifier is the identification program identifier.
We are in the process of realizing the possibility of physically removing the identification program. As part of this process, we want to clear the fragment map. For this, I wrote the following:
var shardKey = new Guid("E03F1DC0-5CA9-45AE-B6EC-0C90529C0062"); var connectionString = @"shard-catalog-connection-string"; var shardMapManager = ShardMapManagerFactory.GetSqlShardMapManager(connectionString, ShardMapManagerLoadPolicy.Lazy); var shardMap = shardMapManager.GetListShardMap<Guid>("IdentityProgramIdListShardMap"); if (shardMap.TryGetMappingForKey(shardKey, out PointMapping<Guid> mapping)) { if (mapping.Status == MappingStatus.Online) { shardMap.MarkMappingOffline(mapping); } shardMap.DeleteMapping(mapping); }
The problem is that when it gets into the DeleteMapping call, it gets an exception:
ShardManagementException: shard binding mapping '[shard-connection-string]' in the 'IdentityProgramIdListShardMap' shard map does not exist. An error occurred while executing the stored procedure "__ShardManagement.spBulkOperationShardMappingsGlobalBegin" for the operation "RemovePointMapping". This can happen if another simultaneous user has already deleted the display.
But the mapping was not removed, because right after that I do:
mappings = shardMap.GetMappings(); foreach(var mapping in mappings) { Console.WriteLine(mapping.Value); }
And I see that the shardmap entry still exists and is marked as "Offline".
If I delete the MarkMappingOffline call, I get an exception indicating that the display of the fragments cannot be removed because it is online.
So, I seem to have caught 22. If I tag it offline, he believes that the display of the fragments has disappeared and will not allow me to delete it. If I do not mark it as offline, it tells me that it should be offline.