Ejemplo n.º 1
0
        public void LockMapping(PointMapping <TKey> mapping, MappingLockToken mappingLockToken)
        {
            ExceptionUtils.DisallowNullArgument(mapping, "mapping");
            ExceptionUtils.DisallowNullArgument(mappingLockToken, "mappingLockToken");

            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                // Generate a lock owner id
                Guid lockOwnerId = mappingLockToken.LockOwnerId;

                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.ListShardMap,
                    "Lock", "Start; LockOwnerId: {0}", lockOwnerId);

                Stopwatch stopwatch = Stopwatch.StartNew();

                _lsm.LockOrUnlockMappings(mapping, lockOwnerId, LockOwnerIdOpType.Lock);

                stopwatch.Stop();

                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.ListShardMap,
                    "Lock", "Complete; Duration: {0}; StoreLockOwnerId: {1}",
                    stopwatch.Elapsed, lockOwnerId);
            }
        }
Ejemplo n.º 2
0
        public RangeMapping <TKey> MergeMappings(RangeMapping <TKey> left, RangeMapping <TKey> right,
                                                 MappingLockToken leftMappingLockToken, MappingLockToken rightMappingLockToken)
        {
            ExceptionUtils.DisallowNullArgument(left, "left");
            ExceptionUtils.DisallowNullArgument(right, "right");
            ExceptionUtils.DisallowNullArgument(leftMappingLockToken, "leftMappingLockToken");
            ExceptionUtils.DisallowNullArgument(rightMappingLockToken, "rightMappingLockToken");

            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.RangeShardMap,
                                 "SplitMapping", "Start; Left Shard: {0}; Right Shard: {1}",
                                 left.Shard.Location, right.Shard.Location);

                Stopwatch stopwatch = Stopwatch.StartNew();

                RangeMapping <TKey> rangeMapping = this.rsm.Merge(left, right, leftMappingLockToken.LockOwnerId, rightMappingLockToken.LockOwnerId);

                stopwatch.Stop();

                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.RangeShardMap,
                                 "SplitMapping", "Complete; Duration: {0}", stopwatch.Elapsed);

                return(rangeMapping);
            }
        }
Ejemplo n.º 3
0
        public PointMapping <TKey> UpdateMapping(PointMapping <TKey> currentMapping, PointMappingUpdate update,
                                                 MappingLockToken mappingLockToken)
        {
            ExceptionUtils.DisallowNullArgument(currentMapping, "currentMapping");
            ExceptionUtils.DisallowNullArgument(update, "update");
            ExceptionUtils.DisallowNullArgument(mappingLockToken, "mappingLockToken");

            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                string mappingKey = BitConverter.ToString(currentMapping.Key.RawValue);
                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.ListShardMap,
                                 "UpdatePointMapping", "Start; ShardMap name: {0}; Current Point Mapping: {1}",
                                 this.Name, mappingKey);

                Stopwatch stopwatch = Stopwatch.StartNew();

                PointMapping <TKey> pointMapping = _lsm.Update(currentMapping, update, mappingLockToken.LockOwnerId);

                stopwatch.Stop();

                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.ListShardMap,
                                 "UpdatePointMapping", "Complete; ShardMap name: {0}; Current Point Mapping: {1}; Duration: {2}",
                                 this.Name, mappingKey, stopwatch.Elapsed);

                return(pointMapping);
            }
        }
Ejemplo n.º 4
0
        public RangeMapping <TKey> UpdateMapping(RangeMapping <TKey> currentMapping, RangeMappingUpdate update,
                                                 MappingLockToken mappingLockToken)
        {
            ExceptionUtils.DisallowNullArgument(currentMapping, "currentMapping");
            ExceptionUtils.DisallowNullArgument(update, "update");
            ExceptionUtils.DisallowNullArgument(mappingLockToken, "mappingLockToken");

            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.RangeShardMap,
                                 "UpdateMapping", "Start; Current mapping shard: {0}",
                                 currentMapping.Shard.Location);

                Stopwatch stopwatch = Stopwatch.StartNew();

                RangeMapping <TKey> rangeMapping = this.rsm.Update(currentMapping, update, mappingLockToken.LockOwnerId, MappingOptions.Validate);

                stopwatch.Stop();

                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.RangeShardMap,
                                 "UpdateMapping", "Complete; Current mapping shard: {0}; Duration: {1}",
                                 currentMapping.Shard.Location, stopwatch.Elapsed);

                return(rangeMapping);
            }
        }
Ejemplo n.º 5
0
        public RangeMapping <TKey> MarkMappingOnline(RangeMapping <TKey> mapping, MappingLockToken mappingLockToken)
        {
            ExceptionUtils.DisallowNullArgument(mapping, "mapping");
            ExceptionUtils.DisallowNullArgument(mappingLockToken, "mappingLockToken");

            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.RangeShardMap,
                    "MarkMappingOnline", "Start; ");

                Stopwatch stopwatch = Stopwatch.StartNew();

                RangeMapping <TKey> result = this.rsm.MarkMappingOnline(mapping, mappingLockToken.LockOwnerId);

                stopwatch.Stop();

                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.RangeShardMap,
                    "MarkMappingOnline", "Complete; Duration: {0}",
                    stopwatch.Elapsed);

                return(result);
            }
        }
Ejemplo n.º 6
0
        public void DeleteMapping(RangeMapping <TKey> mapping, MappingLockToken mappingLockToken)
        {
            ExceptionUtils.DisallowNullArgument(mapping, "mapping");
            ExceptionUtils.DisallowNullArgument(mappingLockToken, "mappingLockToken");

            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.RangeShardMap,
                                 "DeleteMapping", "Start; Shard: {0}", mapping.Shard.Location);

                Stopwatch stopwatch = Stopwatch.StartNew();

                this.rsm.Remove(mapping, mappingLockToken.LockOwnerId);

                stopwatch.Stop();

                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.RangeShardMap,
                                 "DeleteMapping", "Complete; Shard: {0}; Duration: {1}",
                                 mapping.Shard.Location, stopwatch.Elapsed);
            }
        }
Ejemplo n.º 7
0
        public void UnlockMapping(MappingLockToken mappingLockToken)
        {
            ExceptionUtils.DisallowNullArgument(mappingLockToken, "mappingLockToken");

            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                Guid lockOwnerId = mappingLockToken.LockOwnerId;
                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.ListShardMap,
                    "UnlockAllMappingsWithLockOwnerId", "Start; LockOwnerId: {0}", lockOwnerId);

                Stopwatch stopwatch = Stopwatch.StartNew();

                _lsm.LockOrUnlockMappings(null, lockOwnerId, LockOwnerIdOpType.UnlockAllMappingsForId);

                stopwatch.Stop();

                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.ListShardMap,
                    "UnlockAllMappingsWithLockOwnerId", "Complete; Duration: {0}",
                    stopwatch.Elapsed);
            }
        }
Ejemplo n.º 8
0
        public IReadOnlyList <RangeMapping <TKey> > SplitMapping(RangeMapping <TKey> existingMapping, TKey splitAt,
                                                                 MappingLockToken mappingLockToken)
        {
            ExceptionUtils.DisallowNullArgument(existingMapping, "existingMapping");
            ExceptionUtils.DisallowNullArgument(mappingLockToken, "mappingLockToken");

            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.RangeShardMap,
                                 "SplitMapping", "Start; Shard: {0}", existingMapping.Shard.Location);

                Stopwatch stopwatch = Stopwatch.StartNew();

                IReadOnlyList <RangeMapping <TKey> > rangeMapping = this.rsm.Split(existingMapping, splitAt, mappingLockToken.LockOwnerId);

                stopwatch.Stop();

                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.RangeShardMap,
                                 "SplitMapping", "Complete; Shard: {0}; Duration: {1}",
                                 existingMapping.Shard.Location, stopwatch.Elapsed);

                return(rangeMapping);
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Marks the specified mapping offline.
 /// </summary>
 /// <param name="mapping">Input range mapping.</param>
 /// <param name="mappingLockToken">An instance of <see cref="MappingLockToken"/></param>
 /// <returns>An offline mapping.</returns>
 public RangeMapping <TKey> MarkMappingOffline(RangeMapping <TKey> mapping, MappingLockToken mappingLockToken)
 {
     return(this.MarkMappingOffline(mapping, mappingLockToken, MappingOptions.Validate));
 }