コード例 #1
0
        public void LoadTestRemoveShardFromListShardMap()
        {
            try
            {
                ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager(
                    Globals.ShardMapManagerConnectionString,
                    ShardMapManagerLoadPolicy.Lazy);

                ListShardMap <int> lsm = smm.GetListShardMap <int>(ShardMapManagerLoadTests.s_listShardMapName);
                Assert.IsNotNull(lsm);

                List <Shard> existingShards = lsm.GetShards().ToList();

                if (existingShards.Count == 0)
                {
                    return;
                }

                // If there is already a shard marked as offline, chose that one to delete.
                // This can happend if earlier remove operation was terminated for some reason - ex. killing connections.
                Shard offlineShard = existingShards.Find(e => e.Status == ShardStatus.Offline);

                if (offlineShard == null)
                {
                    offlineShard = existingShards[_r.Next(existingShards.Count)];

                    // First mark shard as offline so that other test threads will not add new mappings to it.
                    offlineShard = lsm.UpdateShard(offlineShard,
                                                   new ShardUpdate
                    {
                        Status = ShardStatus.Offline
                    });
                }

                Debug.WriteLine("Trying to remove shard at location {0}", offlineShard.Location);

                PointMappingUpdate pu = new PointMappingUpdate();
                pu.Status = MappingStatus.Offline;

                // Remove all mappings from this shard for given shard map.
                foreach (PointMapping <int> p in lsm.GetMappings(offlineShard))
                {
                    PointMapping <int> mappingToDelete = lsm.UpdateMapping(p, pu);
                    lsm.DeleteMapping(mappingToDelete);
                }

                // Shard object is changed as mappings are removed, get it again.
                Shard deleteShard = lsm.GetShard(offlineShard.Location);

                // now remove shard.
                lsm.DeleteShard(deleteShard);

                Debug.WriteLine("Removed shard at location {0} from shard map {1}", deleteShard.Location, lsm);
            }
            catch (ShardManagementException sme)
            {
                Debug.WriteLine("Exception caught: {0}", sme.Message);
            }
        }
コード例 #2
0
        public bool DeleteShardListMap()
        {
            try
            {
                if (ShardMapManager == null)
                {
                    return(false);
                }
                Shard tempShard = null;
                PointMapping <long> tempMapping = null;

                if (ShardMapManager.TryGetListShardMap(mapManagerName, out lsm))
                {
                    foreach (Shard shard in lsm.GetShards())
                    {
                        // delete all mappings
                        var allMappings = lsm.GetMappings(shard);
                        for (int i = 0; i < allMappings.Count; i++)
                        {
                            lsm.MarkMappingOffline(allMappings[i]);
                            if (lsm.TryGetMappingForKey(allMappings[i].Value, out tempMapping))
                            {
                                lsm.DeleteMapping(tempMapping);
                            }
                        }
                        // delete shard
                        if (lsm.TryGetShard(shard.Location, out tempShard))
                        {
                            lsm.DeleteShard(tempShard);
                        }
                    }
                }
                // clear shard map manager
                if (ShardMapManager.TryGetListShardMap(mapManagerName, out lsm))
                {
                    ShardMapManager.DeleteShardMap(lsm);
                }

                return(true);
            }
            catch { return(false); }
        }