示例#1
0
        /// <summary>
        /// Creates and adds many point mappings to ShardMap.
        /// </summary>
        /// <param name="argsList">List of objects containing information about mappings to be added.</param>
        public IEnumerable <PointMapping <TKey> > CreateFromPointMappings(IEnumerable <PointMappingCreationArgs <TKey> > argsList)
        {
            ExceptionUtils.DisallowNullArgument(argsList, "argsList");

            // Partition the mappings by shardlocation.
            IDictionary <ShardLocation, IList <PointMapping <TKey> > > pointMappings = new Dictionary <ShardLocation, IList <PointMapping <TKey> > >();

            foreach (PointMappingCreationArgs <TKey> args in argsList)
            {
                ExceptionUtils.DisallowNullArgument(args, "args");
                if (!pointMappings.ContainsKey(args.Shard.Location))
                {
                    pointMappings[args.Shard.Location] = new List <PointMapping <TKey> >();
                }
                pointMappings[args.Shard.Location].Add(new PointMapping <TKey>(this.Manager, this.Id, args));
            }

            // For each shardlocation bulk add all the mappings to local only.
            ConcurrentQueue <Exception> exceptions = new ConcurrentQueue <Exception>();

            Parallel.ForEach(pointMappings, (kvp) =>
            {
                try
                {
                    this.lsm.AddLocals(kvp.Value, kvp.Key);
                }
                catch (Exception e)
                {
                    exceptions.Enqueue(e);
                }
            });

            if (exceptions.Count > 0)
            {
                throw new AggregateException(exceptions);
            }

            // Rebuild the global from locals.
            RecoveryManager recoveryManager = this.Manager.GetRecoveryManager();

            recoveryManager.RebuildShardMapManager(pointMappings.Keys);
            return(pointMappings.Values.SelectMany(x => x.AsEnumerable()));
        }