Esempio n. 1
0
        /// <summary>
        /// Creates and adds a point mapping to ShardMap.
        /// </summary>
        /// <param name="point">Point for which to create the mapping.</param>
        /// <param name="shard">Shard associated with the point mapping.</param>
        /// <returns>Newly created mapping.</returns>
        public PointMapping <TKey> CreatePointMapping(TKey point, Shard shard)
        {
            ExceptionUtils.DisallowNullArgument(shard, "shard");

            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                PointMappingCreationInfo <TKey> args = new PointMappingCreationInfo <TKey>(point, shard, MappingStatus.Online);

                string mappingKey = BitConverter.ToString(args.Key.RawValue);
                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.ListShardMap,
                                 "CreatePointMapping", "Start; ShardMap name: {0}; Point Mapping: {1}",
                                 this.Name, mappingKey);

                Stopwatch stopwatch = Stopwatch.StartNew();

                PointMapping <TKey> pointMapping = _lsm.Add(new PointMapping <TKey>(this.Manager, args));

                stopwatch.Stop();

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

                return(pointMapping);
            }
        }
 internal void LockOrUnlockMappings(PointMapping <TKey> mapping, Guid lockOwnerId, LockOwnerIdOpType lockOwnerIdOpType)
 {
     this.LockOrUnlockMappings <PointMapping <TKey> >(
         mapping,
         lockOwnerId,
         lockOwnerIdOpType,
         ShardManagementErrorCategory.ListShardMap);
 }
Esempio n. 3
0
 /// <summary>
 /// Allows for update to a point mapping with the updates provided in
 /// the <paramref name="update"/> parameter.
 /// </summary>
 /// <param name="currentMapping">Mapping being updated.</param>
 /// <param name="update">Updated properties of the Shard.</param>
 /// <param name="lockOwnerId">Lock owner id of this mapping</param>
 /// <returns>New instance of mapping with updated information.</returns>
 internal PointMapping <TKey> Update(PointMapping <TKey> currentMapping, PointMappingUpdate update, Guid lockOwnerId = default(Guid))
 {
     return(this.Update <PointMapping <TKey>, PointMappingUpdate, MappingStatus>(
                currentMapping,
                update,
                (smm, sm, ssm) => new PointMapping <TKey>(smm, sm, ssm),
                pms => (int)pms,
                i => (MappingStatus)i,
                lockOwnerId));
 }
        /// <summary>
        /// Tries to looks up the key value and returns the corresponding mapping.
        /// </summary>
        /// <param name="key">Input key value.</param>
        /// <param name="useCache">Whether to use cache for lookups.</param>
        /// <param name="mapping">Mapping that contains the key value.</param>
        /// <returns><c>true</c> if mapping is found, <c>false</c> otherwise.</returns>
        public bool TryLookup(TKey key, bool useCache, out PointMapping <TKey> mapping)
        {
            PointMapping <TKey> p = this.Lookup <PointMapping <TKey>, TKey>(
                key,
                useCache,
                (smm, sm, ssm) => new PointMapping <TKey>(smm, sm, ssm),
                ShardManagementErrorCategory.ListShardMap);

            mapping = p;

            return(p != null);
        }
 /// <summary>
 /// Marks the given mapping online.
 /// </summary>
 /// <param name="mapping">Input point mapping.</param>
 /// <param name="lockOwnerId">Lock owner id of this mapping</param>
 /// <returns>An online mapping.</returns>
 public PointMapping <TKey> MarkMappingOnline(PointMapping <TKey> mapping, Guid lockOwnerId = default(Guid))
 {
     return(BaseShardMapper.SetStatus <PointMapping <TKey>, PointMappingUpdate, MappingStatus>(
                mapping,
                mapping.Status,
                s => MappingStatus.Online,
                s => new PointMappingUpdate()
     {
         Status = s
     },
                this.Update,
                lockOwnerId));
 }
 /// <summary>
 /// Marks the given mapping offline.
 /// </summary>
 /// <param name="mapping">Input point mapping.</param>
 /// <param name="lockOwnerId">Lock owner id of this mapping</param>
 /// <param name="options">Options for validation operations to perform on opened connection to affected shard.</param>
 /// <returns>An offline mapping.</returns>
 public PointMapping <TKey> MarkMappingOffline(PointMapping <TKey> mapping, Guid lockOwnerId = default(Guid), MappingOptions options = MappingOptions.Validate)
 {
     return(BaseShardMapper.SetStatus <PointMapping <TKey>, PointMappingUpdate, MappingStatus>(
                mapping,
                mapping.Status,
                s => MappingStatus.Offline,
                s => new PointMappingUpdate()
     {
         Status = s
     },
                this.Update,
                lockOwnerId,
                options));
 }
        /// <summary>
        /// Determines whether the specified object is equal to the current object.
        /// </summary>
        /// <param name="obj">The object to compare with the current object.</param>
        /// <returns>True if the specified object is equal to the current object; otherwise, false.</returns>
        public override bool Equals(object obj)
        {
            PointMapping <TKey> other = obj as PointMapping <TKey>;

            if (other == null)
            {
                return(false);
            }

            if (this.Id.Equals(other.Id))
            {
                Debug.Assert(this.Key == other.Key);
                return(true);
            }

            return(false);
        }
Esempio n. 8
0
        /// <summary>
        /// Tries to looks up the key value and place the corresponding mapping in <paramref name="pointMapping"/>.
        /// </summary>
        /// <param name="key">Input key value.</param>
        /// <param name="pointMapping">Mapping that contains the key value.</param>
        /// <returns><c>true</c> if mapping is found, <c>false</c> otherwise.</returns>
        public bool TryGetMappingForKey(TKey key, out PointMapping <TKey> pointMapping)
        {
            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.ListShardMap,
                                 "TryLookupPointMapping", "Start; ShardMap name: {0}; Point Mapping Key Type: {1}",
                                 this.Name, typeof(TKey));

                Stopwatch stopwatch = Stopwatch.StartNew();

                bool result = _lsm.TryLookup(key, false, out pointMapping);

                stopwatch.Stop();

                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.ListShardMap,
                                 "TryLookupPointMapping", "Complete; ShardMap name: {0}; Point Mapping Key Type: {1}; Duration: {2}",
                                 this.Name, typeof(TKey), stopwatch.Elapsed);

                return(result);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Looks up the key value and returns the corresponding mapping.
        /// </summary>
        /// <param name="key">Input key value.</param>
        /// <param name="lookupOptions">Whether to search in the cache and/or store.</param>
        /// <returns>Mapping that contains the key value.</returns>
        public PointMapping <TKey> GetMappingForKey(TKey key, LookupOptions lookupOptions)
        {
            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.ListShardMap,
                                 "LookupPointMapping", "Start; ShardMap name: {0}; Point Mapping Key Type: {1}; Lookup Options: {2}",
                                 this.Name, typeof(TKey), lookupOptions);

                Stopwatch stopwatch = Stopwatch.StartNew();

                PointMapping <TKey> pointMapping = _lsm.Lookup(key, lookupOptions);

                stopwatch.Stop();

                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.ListShardMap,
                                 "LookupPointMapping", "Complete; ShardMap name: {0}; Point Mapping Key Type: {1}; Lookup Options: {2}; Duration: {3}",
                                 this.Name, typeof(TKey), lookupOptions, stopwatch.Elapsed);

                return(pointMapping);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Looks up the key value and returns the corresponding mapping.
        /// </summary>
        /// <param name="key">Input key value.</param>
        /// <param name="useCache">Whether to use cache for lookups.</param>
        /// <returns>Mapping that contains the key value.</returns>
        public PointMapping <TKey> Lookup(TKey key, bool useCache)
        {
            PointMapping <TKey> p = this.Lookup <PointMapping <TKey>, TKey>(
                key,
                useCache,
                (smm, sm, ssm) => new PointMapping <TKey>(smm, sm, ssm),
                ShardManagementErrorCategory.ListShardMap);

            if (p == null)
            {
                throw new ShardManagementException(
                          ShardManagementErrorCategory.ListShardMap,
                          ShardManagementErrorCode.MappingNotFoundForKey,
                          Errors._Store_ShardMapper_MappingNotFoundForKeyGlobal,
                          this.ShardMap.Name,
                          StoreOperationRequestBuilder.SpFindShardMappingByKeyGlobal,
                          "Lookup");
            }

            return(p);
        }
Esempio n. 11
0
        public void DeleteMapping(PointMapping <TKey> mapping)
        {
            ExceptionUtils.DisallowNullArgument(mapping, "mapping");

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

                Stopwatch stopwatch = Stopwatch.StartNew();

                _lsm.Remove(mapping);

                stopwatch.Stop();

                Tracer.TraceInfo(TraceSourceConstants.ComponentNames.ListShardMap,
                                 "DeletePointMapping", "Completed; ShardMap name: {0}; Point Mapping: {1}; Duration: {2}",
                                 this.Name, mappingKey, stopwatch.Elapsed);
            }
        }
Esempio n. 12
0
        public void UnlockMapping(PointMapping <TKey> mapping, MappingLockToken mappingLockToken)
        {
            ExceptionUtils.DisallowNullArgument(mapping, "mapping");
            ExceptionUtils.DisallowNullArgument(mappingLockToken, "mappingLockToken");

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

                Stopwatch stopwatch = Stopwatch.StartNew();

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

                stopwatch.Stop();

                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.ListShardMap,
                    "UnLock", "Complete; Duration: {0}; StoreLockOwnerId: {1}",
                    stopwatch.Elapsed, lockOwnerId);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Gets the lock owner id of the specified mapping.
        /// </summary>
        /// <param name="mapping">Input range mapping.</param>
        /// <returns>An instance of <see cref="MappingLockToken"/></returns>
        public MappingLockToken GetMappingLockOwner(PointMapping <TKey> mapping)
        {
            ExceptionUtils.DisallowNullArgument(mapping, "mapping");

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

                Stopwatch stopwatch = Stopwatch.StartNew();

                Guid storeLockOwnerId = _lsm.GetLockOwnerForMapping(mapping);

                stopwatch.Stop();

                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.ListShardMap,
                    "LookupLockOwner", "Complete; Duration: {0}; StoreLockOwnerId: {1}",
                    stopwatch.Elapsed, storeLockOwnerId);

                return(new MappingLockToken(storeLockOwnerId));
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Marks the specified mapping online.
        /// </summary>
        /// <param name="mapping">Input point mapping.</param>
        /// <returns>An online mapping.</returns>
        public PointMapping <TKey> MarkMappingOnline(PointMapping <TKey> mapping)
        {
            ExceptionUtils.DisallowNullArgument(mapping, "mapping");

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

                Stopwatch stopwatch = Stopwatch.StartNew();

                PointMapping <TKey> result = _lsm.MarkMappingOnline(mapping);

                stopwatch.Stop();

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

                return(result);
            }
        }
Esempio n. 15
0
 public PointMapping <TKey> UpdateMapping(PointMapping <TKey> currentMapping, PointMappingUpdate update)
 {
     return(this.UpdateMapping(currentMapping, update, MappingLockToken.NoLock));
 }
Esempio n. 16
0
 /// <summary>
 /// Marks the specified mapping offline.
 /// </summary>
 /// <param name="mapping">Input point mapping.</param>
 /// <returns>An offline mapping.</returns>
 public PointMapping <TKey> MarkMappingOffline(PointMapping <TKey> mapping)
 {
     return(MarkMappingOffline(mapping, MappingOptions.Validate));
 }
Esempio n. 17
0
 /// <summary>
 /// Gets the lock owner of a mapping.
 /// </summary>
 /// <param name="mapping">The mapping</param>
 /// <returns>Lock owner for the mapping.</returns>
 internal Guid GetLockOwnerForMapping(PointMapping <TKey> mapping)
 {
     return(this.GetLockOwnerForMapping <PointMapping <TKey> >(mapping, ShardManagementErrorCategory.ListShardMap));
 }
Esempio n. 18
0
 /// <summary>
 /// Adds a point mapping.
 /// </summary>
 /// <param name="mapping">Mapping being added.</param>
 /// <returns>The added mapping object.</returns>
 public PointMapping <TKey> Add(PointMapping <TKey> mapping)
 {
     return(this.Add <PointMapping <TKey> >(
                mapping,
                (smm, sm, ssm) => new PointMapping <TKey>(smm, sm, ssm)));
 }
Esempio n. 19
0
 /// <summary>
 /// Tries to looks up the key value and place the corresponding mapping in <paramref name="pointMapping"/>.
 /// Only the global shard map store is searched, not the local cache.
 /// </summary>
 /// <remarks>
 /// This is equivalent to <c>TryGetMappingForKey(key, LookupOptions.LookupInStore, out pointMapping)</c>.
 /// </remarks>
 /// <param name="key">Input key value.</param>
 /// <param name="pointMapping">Mapping that contains the key value.</param>
 /// <returns><c>true</c> if mapping is found, <c>false</c> otherwise.</returns>
 public bool TryGetMappingForKey(TKey key, out PointMapping <TKey> pointMapping)
 {
     return(TryGetMappingForKey(key, LookupOptions.LookupInStore, out pointMapping));
 }