Exemple #1
0
        public void RebuildMappingsOnShard(RecoveryToken token, IEnumerable <ShardRange> ranges)
        {
            ExceptionUtils.DisallowNullArgument(token, "token");
            ExceptionUtils.DisallowNullArgument(ranges, "ranges");

            ShardLocation location = this.GetShardLocation(token);

            if (!this.Inconsistencies.ContainsKey(token))
            {
                throw new ArgumentException(
                          StringUtils.FormatInvariant(
                              Errors._Recovery_InvalidRecoveryToken,
                              token),
                          "token");
            }

            IStoreShardMap ssmLocal;

            DefaultStoreShard dss = this.GetStoreShardFromToken("RebuildMappingsOnShard", token, out ssmLocal);

            IList <IStoreMapping> mappingsToAdd = new List <IStoreMapping>();

            // Determine the ranges we want to keep based on input keeps list.
            foreach (ShardRange range in ranges)
            {
                MappingDifference difference;

                if (!this.Inconsistencies[token].TryGetValue(range, out difference))
                {
                    throw new ArgumentException(
                              StringUtils.FormatInvariant(
                                  Errors._Recovery_InvalidRebuildShardSpecification,
                                  range,
                                  location),
                              "ranges");
                }

                // The storeMapping we will use as a template.
                IStoreMapping storeMappingTemplate = difference.Location == MappingLocation.MappingInShardMapOnly ?
                                                     difference.MappingForShardMap :
                                                     difference.MappingForShard;

                IStoreMapping storeMappingToAdd = new DefaultStoreMapping(
                    Guid.NewGuid(),
                    storeMappingTemplate.ShardMapId,
                    dss,
                    range.Low.RawValue,
                    range.High.RawValue,
                    storeMappingTemplate.Status,
                    default(Guid)
                    );

                mappingsToAdd.Add(storeMappingToAdd);
            }

            using (IStoreOperationLocal op = this.Manager.StoreOperationFactory.CreateReplaceMappingsLocalOperation(
                       this.Manager,
                       location,
                       "RebuildMappingsOnShard",
                       ssmLocal,
                       dss,
                       this.Inconsistencies[token].Keys,
                       mappingsToAdd))
            {
                op.Do();
            }

            this.StoreShardMaps.Remove(token);
            this.Locations.Remove(token);
            this.Inconsistencies.Remove(token);
        }
        public void RebuildMappingsOnShard(RecoveryToken token, IEnumerable<ShardRange> ranges)
        {
            ExceptionUtils.DisallowNullArgument(token, "token");
            ExceptionUtils.DisallowNullArgument(ranges, "ranges");

            ShardLocation location = this.GetShardLocation(token);

            if (!this.Inconsistencies.ContainsKey(token))
            {
                throw new ArgumentException(
                    StringUtils.FormatInvariant(
                        Errors._Recovery_InvalidRecoveryToken,
                        token),
                    "token");
            }

            IStoreShardMap ssmLocal;

            DefaultStoreShard dss = this.GetStoreShardFromToken("RebuildMappingsOnShard", token, out ssmLocal);

            IList<IStoreMapping> mappingsToAdd = new List<IStoreMapping>();

            // Determine the ranges we want to keep based on input keeps list.
            foreach (ShardRange range in ranges)
            {
                MappingDifference difference;

                if (!this.Inconsistencies[token].TryGetValue(range, out difference))
                {
                    throw new ArgumentException(
                        StringUtils.FormatInvariant(
                            Errors._Recovery_InvalidRebuildShardSpecification,
                            range,
                            location),
                        "ranges");
                }

                // The storeMapping we will use as a template.
                IStoreMapping storeMappingTemplate = difference.Location == MappingLocation.MappingInShardMapOnly ?
                    difference.MappingForShardMap :
                    difference.MappingForShard;

                IStoreMapping storeMappingToAdd = new DefaultStoreMapping(
                    Guid.NewGuid(),
                    storeMappingTemplate.ShardMapId,
                    dss,
                    range.Low.RawValue,
                    range.High.RawValue,
                    storeMappingTemplate.Status,
                    default(Guid)
                    );

                mappingsToAdd.Add(storeMappingToAdd);
            }

            using (IStoreOperationLocal op = this.Manager.StoreOperationFactory.CreateReplaceMappingsLocalOperation(
                this.Manager,
                location,
                "RebuildMappingsOnShard",
                ssmLocal,
                dss,
                this.Inconsistencies[token].Keys,
                mappingsToAdd))
            {
                op.Do();
            }

            this.StoreShardMaps.Remove(token);
            this.Locations.Remove(token);
            this.Inconsistencies.Remove(token);
        }