protected DefaultEntityStore(IStoreMapping storeMapping, StorageDialectSettings dialectSettings) { _storeMapping = storeMapping ?? throw new ArgumentNullException(nameof(storeMapping)); _dialectSettings = dialectSettings ?? throw new ArgumentNullException(nameof(dialectSettings)); //_classMap = ClassMapCached.Fetch<TKey, TEntity>(); this._classMap = ClassMapCached <TKey, TEntity> .ClassMap; }
/// <summary> /// Add or update a mapping in cache. /// </summary> /// <param name="sm">Storage mapping object.</param> /// <param name="policy">Policy to use for preexisting cache entries during update.</param> internal override void AddOrUpdate(IStoreMapping sm, CacheStoreMappingUpdatePolicy policy) { ShardKey min = ShardKey.FromRawValue(this.KeyType, sm.MinValue); // Make range out of mapping key ranges. ShardRange range = new ShardRange( min, ShardKey.FromRawValue(this.KeyType, sm.MaxValue)); CacheMapping cm; ICacheStoreMapping csm; IStoreMapping smDummy; // We need to update TTL and update entry if: // a) We are in update TTL mode // b) Mapping exists and same as the one we already have // c) Entry is beyond the TTL limit if (policy == CacheStoreMappingUpdatePolicy.UpdateTimeToLive && (csm = this.LookupByKey(min, out smDummy)) != null && csm.Mapping.Id == sm.Id /*&& * TimerUtils.ElapsedMillisecondsSince(csm.CreationTime) >= csm.TimeToLiveMilliseconds */) { cm = new CacheMapping(sm, CacheMapper.CalculateNewTimeToLiveMilliseconds(csm)); } else { cm = new CacheMapping(sm); } this.Remove(sm); // Add the entry to lookup table by Range. _mappingsByRange.Add(range, cm); }
/// <summary> /// Add or update a mapping in cache. /// </summary> /// <param name="sm">Storage mapping object.</param> /// <param name="policy">Policy to use for preexisting cache entries during update.</param> internal override void AddOrUpdate(IStoreMapping sm, CacheStoreMappingUpdatePolicy policy) { // Make key out of mapping key. ShardKey key = ShardKey.FromRawValue(this.KeyType, sm.MinValue); CacheMapping cm; // We need to update TTL and update entry if: // a) We are in update TTL mode // b) Mapping exists and same as the one we already have // c) Entry is beyond the TTL limit if (policy == CacheStoreMappingUpdatePolicy.UpdateTimeToLive && _mappingsByKey.TryGetValue(key, out cm) && cm.Mapping.Id == sm.Id /*&& TimerUtils.ElapsedMillisecondsSince(cm.CreationTime) >= cm.TimeToLiveMilliseconds */) { cm = new CacheMapping(sm, CacheMapper.CalculateNewTimeToLiveMilliseconds(cm)); } else { cm = new CacheMapping(sm); } // Remove existing entry. this.Remove(sm); // Add the entry to lookup table by Key. _mappingsByKey.Add(key, cm); }
/// <summary> /// Invoked for refreshing mapping in cache from store. /// </summary> /// <param name="mapping">Storage representation of mapping.</param> /// <param name="policy">Policy to use for preexisting cache entries during update.</param> public virtual void AddOrUpdateMapping(IStoreMapping mapping, CacheStoreMappingUpdatePolicy policy) { using (ReadLockScope rls = _cacheRoot.GetReadLockScope(false)) { CacheShardMap csm = _cacheRoot.LookupById(mapping.ShardMapId); if (csm != null) { using (WriteLockScope wlscsm = csm.GetWriteLockScope()) { csm.Mapper.AddOrUpdate(mapping, policy); // Update perf counters for add or update operation and mappings count. csm.IncrementPerformanceCounter(PerformanceCounterName.MappingsAddOrUpdatePerSec); csm.SetPerformanceCounter(PerformanceCounterName.MappingsCount, csm.Mapper.GetMappingsCount()); Tracer.TraceVerbose( TraceSourceConstants.ComponentNames.ShardMapManager, "OnAddOrUpdateMapping", "Cache Add/Update mapping complete. Mapping Id: {0}", mapping.Id); } } } }
/// <summary> /// Add or update a mapping in cache. /// </summary> /// <param name="sm">Storage mapping object.</param> /// <param name="policy">Policy to use for preexisting cache entries during update.</param> internal override void AddOrUpdate(IStoreMapping sm, CacheStoreMappingUpdatePolicy policy) { ShardKey min = ShardKey.FromRawValue(this.KeyType, sm.MinValue); // Make range out of mapping key ranges. ShardRange range = new ShardRange( min, ShardKey.FromRawValue(this.KeyType, sm.MaxValue)); CacheMapping cm; ICacheStoreMapping csm; IStoreMapping smDummy; // We need to update TTL and update entry if: // a) We are in update TTL mode // b) Mapping exists and same as the one we already have // c) Entry is beyond the TTL limit if (policy == CacheStoreMappingUpdatePolicy.UpdateTimeToLive && (csm = this.LookupByKey(min, out smDummy)) != null && csm.Mapping.Id == sm.Id /*&& TimerUtils.ElapsedMillisecondsSince(csm.CreationTime) >= csm.TimeToLiveMilliseconds */) { cm = new CacheMapping(sm, CacheMapper.CalculateNewTimeToLiveMilliseconds(csm)); } else { cm = new CacheMapping(sm); } this.Remove(sm); // Add the entry to lookup table by Range. _mappingsByRange.Add(range, cm); }
/// <summary> /// Invoked for deleting mapping in cache becase it no longer exists in store. /// </summary> /// <param name="mapping">Storage representation of mapping.</param> public virtual void DeleteMapping(IStoreMapping mapping) { using (ReadLockScope rls = _cacheRoot.GetReadLockScope(false)) { CacheShardMap csm = _cacheRoot.LookupById(mapping.ShardMapId); if (csm != null) { using (WriteLockScope wlscsm = csm.GetWriteLockScope()) { csm.Mapper.Remove(mapping); /* * // Update perf counters for remove mapping operation and mappings count. * csm.IncrementPerformanceCounter(PerformanceCounterName.MappingsRemovePerSec); * csm.SetPerformanceCounter(PerformanceCounterName.MappingsCount, csm.Mapper.GetMappingsCount()); */ Tracer.TraceVerbose( TraceSourceConstants.ComponentNames.ShardMapManager, "OnDeleteMapping", "Cache delete mapping complete. Mapping Id: {0}", mapping.Id); } } } }
/// <summary> /// Add or update a mapping in cache. /// </summary> /// <param name="sm">Storage mapping object.</param> /// <param name="policy">Policy to use for preexisting cache entries during update.</param> internal override void AddOrUpdate(IStoreMapping sm, CacheStoreMappingUpdatePolicy policy) { // Make key out of mapping key. ShardKey key = ShardKey.FromRawValue(this.KeyType, sm.MinValue); CacheMapping cm; // We need to update TTL and update entry if: // a) We are in update TTL mode // b) Mapping exists and same as the one we already have // c) Entry is beyond the TTL limit if (policy == CacheStoreMappingUpdatePolicy.UpdateTimeToLive && _mappingsByKey.TryGetValue(key, out cm) && cm.Mapping.Id == sm.Id /*&& * TimerUtils.ElapsedMillisecondsSince(cm.CreationTime) >= cm.TimeToLiveMilliseconds */) { cm = new CacheMapping(sm, CacheMapper.CalculateNewTimeToLiveMilliseconds(cm)); } else { cm = new CacheMapping(sm); } // Remove existing entry. this.Remove(sm); // Add the entry to lookup table by Key. _mappingsByKey.Add(key, cm); }
/// <summary> /// Looks up a mapping by key. /// </summary> /// <param name="key">Key value.</param> /// <param name="sm">Storage mapping object.</param> /// <returns>Mapping object which has the key value.</returns> internal override ICacheStoreMapping LookupByKey(ShardKey key, out IStoreMapping sm) { CacheMapping cm; // Performs a binary search in the ranges for key value and // then return the result. int rangeIndex = this.GetIndexOfMappingContainingShardKey(key); if (rangeIndex != -1) { ShardRange range = _mappingsByRange.Keys[rangeIndex]; cm = _mappingsByRange[range]; // DEVNOTE(wbasheer): We should clone the mapping. sm = cm.Mapping; } else { cm = null; sm = null; } return(cm); }
/// <summary> /// Constructs request for obtaining mapping from GSM based on given key. /// </summary> /// <param name="shardMapManager">Shard map manager.</param> /// <param name="operationName">Operation being executed.</param> /// <param name="shardMap">Local shard map.</param> /// <param name="mapping">Mapping whose Id will be used.</param> /// <param name="errorCategory">Error category.</param> internal FindMappingByIdGlobalOperation(ShardMapManager shardMapManager, string operationName, IStoreShardMap shardMap, IStoreMapping mapping, ShardManagementErrorCategory errorCategory) : base(shardMapManager.Credentials, shardMapManager.RetryPolicy, operationName) { _manager = shardMapManager; _shardMap = shardMap; _mapping = mapping; _errorCategory = errorCategory; }
internal SortClauseBuilder(ISortClause obj, IStoreMapping storeMapping, StorageDialectSettings dialectSettings) { _obj = obj ?? throw new ArgumentNullException(nameof(obj)); _storeMapping = storeMapping ?? throw new ArgumentNullException(nameof(storeMapping)); _dialectSettings = dialectSettings ?? throw new ArgumentNullException(nameof(dialectSettings)); _body = new Dictionary <string, Orderby>(); //_classMap = ClassMapCached.Fetch<TKey, TEntity>(); this._classMap = ClassMapCached <TKey, TEntity> .ClassMap; }
/// <summary> /// Remove a mapping object from cache. /// </summary> /// <param name="sm">Storage maping object.</param> internal override void Remove(IStoreMapping sm) { // Make key value out of mapping key. ShardKey key = ShardKey.FromRawValue(this.KeyType, sm.MinValue); // Remove existing entry. if (_mappingsByKey.ContainsKey(key)) { _mappingsByKey.Remove(key); } }
/// <summary> /// Constructs request to lock or unlock given mappings in GSM. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <param name="shardMap">Shard map to add.</param> /// <param name="mapping">Mapping to lock or unlock. Null means all mappings.</param> /// <param name="lockOwnerId">Lock owner.</param> /// <param name="lockOpType">Lock operation type.</param> /// <param name="errorCategory">Error category.</param> internal LockOrUnLockMappingsGlobalOperation(ShardMapManager shardMapManager, string operationName, IStoreShardMap shardMap, IStoreMapping mapping, Guid lockOwnerId, LockOwnerIdOpType lockOpType, ShardManagementErrorCategory errorCategory) : base(shardMapManager.Credentials, shardMapManager.RetryPolicy, operationName) { _shardMapManager = shardMapManager; _shardMap = shardMap; _mapping = mapping; _lockOwnerId = lockOwnerId; _lockOpType = lockOpType; _errorCategory = errorCategory; Debug.Assert(mapping != null || (lockOpType == LockOwnerIdOpType.UnlockAllMappingsForId || lockOpType == LockOwnerIdOpType.UnlockAllMappings)); }
/// <summary> /// Creates request to add shard to given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationCode">Store operation code.</param> /// <param name="shardMap">Shard map for which to add mapping.</param> /// <param name="mapping">Mapping to add.</param> /// <returns>The store operation.</returns> public virtual IStoreOperation CreateAddMappingOperation( ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mapping) { return(new AddMappingOperation( shardMapManager, operationCode, shardMap, mapping)); }
internal WhereClauseBuilder(IWhereClause obj, IStoreMapping storeMapping, StorageDialectSettings dialectSettings) { _obj = obj ?? throw new ArgumentNullException(nameof(obj)); _storeMapping = storeMapping ?? throw new ArgumentNullException(nameof(storeMapping)); _dialectSettings = dialectSettings ?? throw new ArgumentNullException(nameof(dialectSettings)); _builder = new StringBuilder(); _parameters = new Dictionary <string, object>(); _writeAnd = () => this.And(); _writeOr = () => this.Or(); // this._classMap = ClassMapCached.Fetch<TKey, TEntity>(); this._classMap = ClassMapCached <TKey, TEntity> .ClassMap; }
/// <summary> /// Instantiates a new instance of range mapping comparison result. /// </summary> /// <param name="ssm">Store representation of shard map.</param> /// <param name="range">Range being considered.</param> /// <param name="mappingLocation">Location of mapping.</param> /// <param name="gsmMapping">Storage representation of GSM mapping.</param> /// <param name="lsmMapping">Storange representation of LSM mapping.</param> internal MappingComparisonResult( IStoreShardMap ssm, ShardRange range, MappingLocation mappingLocation, IStoreMapping gsmMapping, IStoreMapping lsmMapping) { this.ShardMap = ssm; this.Range = range; this.MappingLocation = mappingLocation; this.ShardMapManagerMapping = gsmMapping; this.ShardMapping = lsmMapping; }
/// <summary> /// Helper function to advance mapping iterators. /// </summary> /// <param name="iterator">The iterator to advance.</param> /// <param name="keyType">The data type of the map key.</param> /// <param name="nextMapping">Output value that will contain next mapping.</param> /// <param name="nextRange">Output value that will contain next range.</param> /// <param name="nextMinKey">Output value that will contain next min key.</param> private static void MoveToNextMapping( IEnumerator <IStoreMapping> iterator, ShardKeyType keyType, out IStoreMapping nextMapping, out ShardRange nextRange, out ShardKey nextMinKey) { nextMapping = iterator.MoveNext() ? iterator.Current : null; nextRange = nextMapping != null ? new ShardRange( ShardKey.FromRawValue(keyType, nextMapping.MinValue), ShardKey.FromRawValue(keyType, nextMapping.MaxValue)) : null; nextMinKey = nextRange != null ? nextRange.Low : null; }
/// <summary> /// Serializes shard mapping to xml. /// </summary> /// <param name="name">Element name for shard mapping.</param> /// <param name="mapping">Shard mapping to serialize.</param> /// <returns>XElement representing shard mapping.</returns> internal static XElement WriteIStoreMapping(string name, IStoreMapping mapping) { Debug.Assert(mapping != null); return(new XElement(name, new XElement("Id", mapping.Id), new XElement("ShardMapId", mapping.ShardMapId), new XElement("MinValue", StringUtils.ByteArrayToString(mapping.MinValue)), new XElement("MaxValue", new XAttribute("Null", mapping.MaxValue == null ? 1 : 0), mapping.MaxValue == null ? null : StringUtils.ByteArrayToString(mapping.MaxValue)), new XElement("Status", mapping.Status), new XElement("LockOwnerId", mapping.LockOwnerId))); }
internal MappingDifference( MappingDifferenceType type, MappingLocation location, IStoreShardMap shardMap, IStoreMapping mappingForShardMap, IStoreMapping mappingForShard ) { this.Type = type; this.Location = location; this.ShardMap = shardMap; this.MappingForShardMap = mappingForShardMap; this.MappingForShard = mappingForShard; }
/// <summary> /// Constructs request for obtaining mapping from GSM based on given key. /// </summary> /// <param name="shardMapManager">Shard map manager.</param> /// <param name="operationName">Operation being executed.</param> /// <param name="shardMap">Local shard map.</param> /// <param name="mapping">Mapping whose Id will be used.</param> /// <param name="errorCategory">Error category.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateFindMappingByIdGlobalOperation( ShardMapManager shardMapManager, string operationName, IStoreShardMap shardMap, IStoreMapping mapping, ShardManagementErrorCategory errorCategory) { return(new FindMappingByIdGlobalOperation( shardMapManager, operationName, shardMap, mapping, errorCategory)); }
/// <summary> /// Creates request to add shard to given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationCode">Store operation code.</param> /// <param name="shardMap">Shard map from which to remove mapping.</param> /// <param name="mapping">Mapping to add.</param> /// <param name="lockOwnerId">Id of lock owner.</param> /// <returns>The store operation.</returns> public virtual IStoreOperation CreateRemoveMappingOperation( ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mapping, Guid lockOwnerId) { return(new RemoveMappingOperation( shardMapManager, operationCode, shardMap, mapping, lockOwnerId)); }
/// <summary> /// Creates request to add shard to given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationCode">Store operation code.</param> /// <param name="shardMap">Shard map for which to add mapping.</param> /// <param name="mapping">Mapping to add.</param> protected internal AddMappingOperation( ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mapping) : this( shardMapManager, Guid.NewGuid(), StoreOperationState.UndoBegin, operationCode, shardMap, mapping, default(Guid)) { }
/// <summary> /// Sets the stub of CacheStore.DeleteMapping(IStoreMapping mapping) /// </summary> public override void DeleteMapping(IStoreMapping mapping) { Action <IStoreMapping> action1 = this.DeleteMappingIStoreMapping; if (action1 != null) { action1(mapping); } else if (this.___callBase) { base.DeleteMapping(mapping); } else { this.InstanceBehavior.VoidResult <StubCacheStore>(this, "DeleteMapping"); } }
/// <summary> /// Looks up a mapping by key. /// </summary> /// <param name="key">Key value.</param> /// <param name="sm">Storage mapping object.</param> /// <returns>Mapping object which has the key value.</returns> internal override ICacheStoreMapping LookupByKey(ShardKey key, out IStoreMapping sm) { CacheMapping cm; _mappingsByKey.TryGetValue(key, out cm); if (cm != null) { sm = cm.Mapping; } else { sm = null; } return(cm); }
/// <summary> /// Sets the stub of CacheStore.AddOrUpdateMapping(IStoreMapping mapping, CacheStoreMappingUpdatePolicy policy) /// </summary> public override void AddOrUpdateMapping(IStoreMapping mapping, CacheStoreMappingUpdatePolicy policy) { Action <IStoreMapping, CacheStoreMappingUpdatePolicy> action1 = this.AddOrUpdateMappingIStoreMappingCacheStoreMappingUpdatePolicy; if (action1 != null) { action1(mapping, policy); } else if (this.___callBase) { base.AddOrUpdateMapping(mapping, policy); } else { this.InstanceBehavior.VoidResult <StubCacheStore>(this, "AddOrUpdateMapping"); } }
/// <summary> /// Constructs request to lock or unlock given mappings in GSM. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <param name="shardMap">Shard map to add.</param> /// <param name="mapping">Mapping to lock or unlock. Null means all mappings.</param> /// <param name="lockOwnerId">Lock owner.</param> /// <param name="lockOpType">Lock operation type.</param> /// <param name="errorCategory">Error category.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateLockOrUnLockMappingsGlobalOperation( ShardMapManager shardMapManager, string operationName, IStoreShardMap shardMap, IStoreMapping mapping, Guid lockOwnerId, LockOwnerIdOpType lockOpType, ShardManagementErrorCategory errorCategory) { return(new LockOrUnLockMappingsGlobalOperation( shardMapManager, operationName, shardMap, mapping, lockOwnerId, lockOpType, errorCategory)); }
/// <summary> /// Creates request to add shard to given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationCode">Store operation code.</param> /// <param name="shardMap">Shard map for which to update mapping.</param> /// <param name="mappingSource">Mapping to update.</param> /// <param name="mappingTarget">Updated mapping.</param> /// <param name="patternForKill">Pattern for kill commands.</param> /// <param name="lockOwnerId">Id of lock owner.</param> /// <returns>The store operation.</returns> public virtual IStoreOperation CreateUpdateMappingOperation( ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mappingSource, IStoreMapping mappingTarget, string patternForKill, Guid lockOwnerId) { return(new UpdateMappingOperation( shardMapManager, operationCode, shardMap, mappingSource, mappingTarget, patternForKill, lockOwnerId)); }
/// <summary> /// Internal constructor used for deserialization from store representation of /// the mapping object. /// </summary> /// <param name="manager">Owning ShardMapManager.</param> /// <param name="shardMap">Owning shard map.</param> /// <param name="mapping">Storage representation of the mapping.</param> internal PointMapping( ShardMapManager manager, ShardMap shardMap, IStoreMapping mapping) { Debug.Assert(manager != null); this.Manager = manager; Debug.Assert(mapping != null); Debug.Assert(mapping.ShardMapId != default(Guid)); Debug.Assert(mapping.StoreShard.ShardMapId != default(Guid)); this.StoreMapping = mapping; _shard = new Shard(this.Manager, shardMap, mapping.StoreShard); this.Key = ShardKey.FromRawValue(ShardKey.ShardKeyTypeFromType(typeof(TKey)), mapping.MinValue); this.Value = (TKey)this.Key.Value; }
/// <summary> /// Invoked for deleting mapping in cache becase it no longer exists in store. /// </summary> /// <param name="mapping">Storage representation of mapping.</param> public virtual void DeleteMapping(IStoreMapping mapping) { using (ReadLockScope rls = _cacheRoot.GetReadLockScope(false)) { CacheShardMap csm = _cacheRoot.LookupById(mapping.ShardMapId); if (csm != null) { using (WriteLockScope wlscsm = csm.GetWriteLockScope()) { csm.Mapper.Remove(mapping); Tracer.TraceVerbose( TraceSourceConstants.ComponentNames.ShardMapManager, "OnDeleteMapping", "Cache delete mapping complete. Mapping Id: {0}", mapping.Id); } } } }
/// <summary> /// Creates request to add shard to given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationId">Operation id.</param> /// <param name="undoStartState">State from which Undo operation starts.</param> /// <param name="operationCode">Store operation code.</param> /// <param name="shardMap">Shard map for which to update mapping.</param> /// <param name="mappingSource">Mapping to update.</param> /// <param name="mappingTarget">Updated mapping.</param> /// <param name="patternForKill">Pattern for kill commands.</param> /// <param name="lockOwnerId">Id of lock owner.</param> /// <param name="originalShardVersionRemoves">Original shard version for removes.</param> /// <param name="originalShardVersionAdds">Original shard version for adds.</param> /// <param name="killConnection">Whether to kill open connections.</param> internal UpdateMappingOperation( ShardMapManager shardMapManager, Guid operationId, StoreOperationState undoStartState, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mappingSource, IStoreMapping mappingTarget, string patternForKill, Guid lockOwnerId, Guid originalShardVersionRemoves, Guid originalShardVersionAdds, bool killConnection) : base( shardMapManager, operationId, undoStartState, operationCode, originalShardVersionRemoves, originalShardVersionAdds) { _shardMap = shardMap; _mappingSource = mappingSource; _mappingTarget = mappingTarget; _lockOwnerId = lockOwnerId; _errorCategory = (operationCode == StoreOperationCode.UpdateRangeMapping || operationCode == StoreOperationCode.UpdateRangeMappingWithOffline) ? ShardManagementErrorCategory.RangeShardMap : ShardManagementErrorCategory.ListShardMap; _updateLocation = _mappingSource.StoreShard.Id != _mappingTarget.StoreShard.Id; _fromOnlineToOffline = operationCode == StoreOperationCode.UpdatePointMappingWithOffline || operationCode == StoreOperationCode.UpdateRangeMappingWithOffline; _patternForKill = patternForKill; _killConnection = killConnection; }
/// <summary> /// Creates request to add shard to given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationCode">Store operation code.</param> /// <param name="shardMap">Shard map for which to update mapping.</param> /// <param name="mappingSource">Mapping to update.</param> /// <param name="mappingTarget">Updated mapping.</param> /// <param name="patternForKill">Pattern for kill commands.</param> /// <param name="lockOwnerId">Id of lock owner.</param> protected internal UpdateMappingOperation( ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mappingSource, IStoreMapping mappingTarget, string patternForKill, Guid lockOwnerId) : this( shardMapManager, Guid.NewGuid(), StoreOperationState.UndoBegin, operationCode, shardMap, mappingSource, mappingTarget, patternForKill, lockOwnerId, default(Guid), default(Guid)) { }
/// <summary> /// Creates request to add shard to given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationId">Operation id.</param> /// <param name="undoStartState">State from which Undo operation starts.</param> /// <param name="operationCode">Store operation code.</param> /// <param name="shardMap">Shard map for which to add mapping.</param> /// <param name="mapping">Mapping to add.</param> /// <param name="originalShardVersionAdds">Original shard version.</param> internal AddMappingOperation( ShardMapManager shardMapManager, Guid operationId, StoreOperationState undoStartState, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mapping, Guid originalShardVersionAdds) : base( shardMapManager, operationId, undoStartState, operationCode, default(Guid), originalShardVersionAdds) { _shardMap = shardMap; _mapping = mapping; _errorCategory = operationCode == StoreOperationCode.AddRangeMapping ? ShardManagementErrorCategory.RangeShardMap : ShardManagementErrorCategory.ListShardMap; }
/// <summary> /// Internal constructor used for deserialization from store representation of /// the mapping object. /// </summary> /// <param name="manager">Owning ShardMapManager.</param> /// <param name="shardMap">Owning shard map.</param> /// <param name="mapping">Storage representation of the mapping.</param> internal RangeMapping( ShardMapManager manager, ShardMap shardMap, IStoreMapping mapping) { Debug.Assert(manager != null); this.Manager = manager; Debug.Assert(mapping != null); Debug.Assert(mapping.ShardMapId != default(Guid)); Debug.Assert(mapping.StoreShard.ShardMapId != default(Guid)); this.StoreMapping = mapping; _shard = new Shard(this.Manager, shardMap, mapping.StoreShard); this.Range = new ShardRange( ShardKey.FromRawValue(ShardKey.ShardKeyTypeFromType(typeof(TKey)), mapping.MinValue), ShardKey.FromRawValue(ShardKey.ShardKeyTypeFromType(typeof(TKey)), mapping.MaxValue)); this.Value = this.Range.High.IsMax ? new Range <TKey>(this.Range.Low.GetValue <TKey>()) : new Range <TKey>(this.Range.Low.GetValue <TKey>(), this.Range.High.GetValue <TKey>()); }
/// <summary> /// Creates request to add shard to given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationId">Operation id.</param> /// <param name="undoStartState">State from which Undo operation starts.</param> /// <param name="operationCode">Store operation code.</param> /// <param name="shardMap">Shard map from which to remove mapping.</param> /// <param name="mapping">Mapping to add.</param> /// <param name="lockOwnerId">Id of lock owner.</param> /// <param name="originalShardVersionRemoves">Original shard version.</param> internal RemoveMappingOperation( ShardMapManager shardMapManager, Guid operationId, StoreOperationState undoStartState, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mapping, Guid lockOwnerId, Guid originalShardVersionRemoves) : base( shardMapManager, operationId, undoStartState, operationCode, originalShardVersionRemoves, default(Guid)) { _shardMap = shardMap; _mapping = mapping; _lockOwnerId = lockOwnerId; _errorCategory = operationCode == StoreOperationCode.RemoveRangeMapping ? ShardManagementErrorCategory.RangeShardMap : ShardManagementErrorCategory.ListShardMap; }
/// <summary> /// Constructs request for obtaining mapping from GSM based on given key. /// </summary> /// <param name="shardMapManager">Shard map manager.</param> /// <param name="operationName">Operation being executed.</param> /// <param name="shardMap">Local shard map.</param> /// <param name="mapping">Mapping whose Id will be used.</param> /// <param name="errorCategory">Error category.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateFindMappingByIdGlobalOperation( ShardMapManager shardMapManager, string operationName, IStoreShardMap shardMap, IStoreMapping mapping, ShardManagementErrorCategory errorCategory) { return new FindMappingByIdGlobalOperation( shardMapManager, operationName, shardMap, mapping, errorCategory); }
/// <summary> /// Constructs request to lock or unlock given mappings in GSM. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <param name="shardMap">Shard map to add.</param> /// <param name="mapping">Mapping to lock or unlock. Null means all mappings.</param> /// <param name="lockOwnerId">Lock owner.</param> /// <param name="lockOpType">Lock operation type.</param> /// <param name="errorCategory">Error category.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateLockOrUnLockMappingsGlobalOperation( ShardMapManager shardMapManager, string operationName, IStoreShardMap shardMap, IStoreMapping mapping, Guid lockOwnerId, LockOwnerIdOpType lockOpType, ShardManagementErrorCategory errorCategory) { return new LockOrUnLockMappingsGlobalOperation( shardMapManager, operationName, shardMap, mapping, lockOwnerId, lockOpType, errorCategory); }
/// <summary> /// Initializes a new instance /// </summary> public StubAddMappingOperation(ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mapping) : base(shardMapManager, operationCode, shardMap, mapping) { this.InitializeStub(); }
/// <summary> /// Request to add mapping to given shard map in LSM. /// </summary> /// <param name="operationId">Operation Id.</param> /// <param name="shardMap">Shard map for which operation is being requested.</param> /// <param name="mapping">Mapping to add.</param> /// <param name="undo">Whether this is undo request.</param> /// <returns>Xml formatted request.</returns> internal static XElement AddShardMappingLocal( Guid operationId, bool undo, IStoreShardMap shardMap, IStoreMapping mapping) { return new XElement( "BulkOperationShardMappingsLocal", StoreOperationRequestBuilder.OperationId(operationId), StoreOperationRequestBuilder.Undo(undo), StoreOperationRequestBuilder.StepsCount(1), StoreOperationRequestBuilder.s_lsmVersion, StoreObjectFormatterXml.WriteIStoreShardMap("ShardMap", shardMap), StoreObjectFormatterXml.WriteIStoreShard("Shard", mapping.StoreShard), new XElement("Steps", new XElement("Step", new XAttribute("Id", 1), StoreOperationRequestBuilder.StepKind(StoreOperationStepKind.Add), StoreObjectFormatterXml.WriteIStoreMapping("Mapping", mapping)))); }
internal UpdateMappingOperationFailAfterLocalTarget( ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mappingSource, IStoreMapping mappingTarget, string patternForKill, Guid lockOwnerId) : base(shardMapManager, operationCode, shardMap, mappingSource, mappingTarget, patternForKill, lockOwnerId) { }
/// <summary> /// Creates request to add shard to given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationCode">Store operation code.</param> /// <param name="shardMap">Shard map for which to update mapping.</param> /// <param name="mappingSource">Mapping to update.</param> /// <param name="mappingTarget">Updated mapping.</param> /// <param name="patternForKill">Pattern for kill commands.</param> /// <param name="lockOwnerId">Id of lock owner.</param> /// <returns>The store operation.</returns> public virtual IStoreOperation CreateUpdateMappingOperation( ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mappingSource, IStoreMapping mappingTarget, string patternForKill, Guid lockOwnerId) { return new UpdateMappingOperation( shardMapManager, operationCode, shardMap, mappingSource, mappingTarget, patternForKill, lockOwnerId); }
/// <summary> /// Constructs cached representation of a mapping object. /// </summary> /// <param name="storeMapping">Storage representation of mapping.</param> internal CacheMapping(IStoreMapping storeMapping) : this(storeMapping, 0) { }
/// <summary> /// Constructs cached representation of a mapping object. /// </summary> /// <param name="storeMapping">Storage representation of mapping.</param> /// <param name="timeToLiveMilliseconds">Mapping expiration time.</param> internal CacheMapping(IStoreMapping storeMapping, long timeToLiveMilliseconds) { this.Mapping = storeMapping; this.CreationTime = TimerUtils.GetTimestamp(); this.TimeToLiveMilliseconds = timeToLiveMilliseconds; }
public virtual void AddOrUpdateMapping(IStoreMapping mapping, CacheStoreMappingUpdatePolicy policy) { this.inner.AddOrUpdateMapping(mapping, policy); }
public virtual void DeleteMapping(IStoreMapping mapping) { this.inner.DeleteMapping(mapping); }
internal NTimeFailingAddMappingOperation( int failureCountMax, ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mapping) : base(shardMapManager, operationCode, shardMap, mapping) { _failureCountMax = failureCountMax; _currentFailureCount = 0; }
/// <summary> /// Asynchronously performs validation that the local representation is as up-to-date /// as the representation on the backing data store. /// </summary> /// <param name="conn">Connection used for validation.</param> /// <param name="manager">ShardMapManager reference.</param> /// <param name="shardMap">Shard map for the mapping.</param> /// <param name="storeMapping">Mapping to validate.</param> /// <returns>A task to await validation completion</returns> internal static async Task ValidateMappingAsync( SqlConnection conn, ShardMapManager manager, IStoreShardMap shardMap, IStoreMapping storeMapping) { DateTime validateStartTime = DateTime.UtcNow; SqlResults lsmResult = new SqlResults(); XElement xeValidate = StoreOperationRequestBuilder.ValidateShardMappingLocal(shardMap.Id, storeMapping.Id); using (SqlCommand cmd = conn.CreateCommand()) using (XmlReader input = xeValidate.CreateReader()) { cmd.CommandText = StoreOperationRequestBuilder.SpValidateShardMappingLocal; cmd.CommandType = CommandType.StoredProcedure; SqlUtils.AddCommandParameter( cmd, "@input", SqlDbType.Xml, ParameterDirection.Input, 0, new SqlXml(input)); SqlParameter resultParam = SqlUtils.AddCommandParameter( cmd, "@result", SqlDbType.Int, ParameterDirection.Output, 0, 0); using (SqlDataReader reader = await cmd.ExecuteReaderAsync()) { await lsmResult.FetchAsync(reader); } // Output parameter will be used to specify the outcome. lsmResult.Result = (StoreResult)resultParam.Value; } Tracer.TraceInfo( TraceSourceConstants.ComponentNames.Shard, "ValidateMappingAsync", "Complete; Shard: {0}; Connection: {1}; Result: {2}; Duration: {3}", storeMapping.StoreShard.Location, conn.ConnectionString, lsmResult.Result, DateTime.UtcNow - validateStartTime); if (lsmResult.Result != StoreResult.Success) { if (lsmResult.Result == StoreResult.ShardMapDoesNotExist) { manager.Cache.DeleteShardMap(shardMap); } else if (lsmResult.Result == StoreResult.MappingDoesNotExist || lsmResult.Result == StoreResult.MappingIsOffline) { manager.Cache.DeleteMapping(storeMapping); } // Possible errors are: // StoreResult.ShardMapDoesNotExist // StoreResult.MappingDoesNotExist // StoreResult.MappingIsOffline // StoreResult.ShardVersionMismatch // StoreResult.StoreVersionMismatch // StoreResult.MissingParametersForStoredProcedure throw StoreOperationErrorHandler.OnValidationErrorLocal( lsmResult, shardMap, storeMapping.StoreShard.Location, "ValidateMappingAsync", StoreOperationRequestBuilder.SpValidateShardLocal); } Debug.Assert(lsmResult.Result == StoreResult.Success); }
internal RemoveMappingOperationFailAfterLocalTarget( ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mapping, Guid lockOwnerId) : base(shardMapManager, operationCode, shardMap, mapping, lockOwnerId) { }
/// <summary> /// Performs validation that the local representation is as up-to-date /// as the representation on the backing data store. /// </summary> /// <param name="conn">Connection used for validation.</param> /// <param name="manager">ShardMapManager reference.</param> /// <param name="shardMap">Shard map for the mapping.</param> /// <param name="storeMapping">Mapping to validate.</param> internal static void ValidateMapping( SqlConnection conn, ShardMapManager manager, IStoreShardMap shardMap, IStoreMapping storeMapping) { Stopwatch stopwatch = Stopwatch.StartNew(); SqlResults lsmResult = new SqlResults(); XElement xeValidate = StoreOperationRequestBuilder.ValidateShardMappingLocal(shardMap.Id, storeMapping.Id); using (SqlCommand cmd = conn.CreateCommand()) using (XmlReader input = xeValidate.CreateReader()) { cmd.CommandText = StoreOperationRequestBuilder.SpValidateShardMappingLocal; cmd.CommandType = CommandType.StoredProcedure; SqlUtils.AddCommandParameter( cmd, "@input", SqlDbType.Xml, ParameterDirection.Input, 0, new SqlXml(input)); SqlParameter resultParam = SqlUtils.AddCommandParameter( cmd, "@result", SqlDbType.Int, ParameterDirection.Output, 0, 0); using (SqlDataReader reader = cmd.ExecuteReader()) { lsmResult.Fetch(reader); } // Output parameter will be used to specify the outcome. lsmResult.Result = (StoreResult)resultParam.Value; } stopwatch.Stop(); Tracer.TraceInfo( TraceSourceConstants.ComponentNames.Shard, "ValidateMapping", "Complete; Shard: {0}; Connection: {1}; Result: {2}; Duration: {3}", storeMapping.StoreShard.Location, conn.ConnectionString, lsmResult.Result, stopwatch.Elapsed); if (lsmResult.Result != StoreResult.Success) { if (lsmResult.Result == StoreResult.ShardMapDoesNotExist) { manager.Cache.DeleteShardMap(shardMap); } else if (lsmResult.Result == StoreResult.MappingDoesNotExist) { // Only evict from cache is mapping is no longer present, // for Offline mappings, we don't even retry, so same request // will continue to go to the LSM. manager.Cache.DeleteMapping(storeMapping); } // Possible errors are: // StoreResult.ShardMapDoesNotExist // StoreResult.MappingDoesNotExist // StoreResult.MappingIsOffline // StoreResult.ShardVersionMismatch // StoreResult.StoreVersionMismatch // StoreResult.MissingParametersForStoredProcedure throw StoreOperationErrorHandler.OnValidationErrorLocal( lsmResult, shardMap, storeMapping.StoreShard.Location, "ValidateMapping", StoreOperationRequestBuilder.SpValidateShardLocal); } Debug.Assert(lsmResult.Result == StoreResult.Success); }
internal AddMappingOperationFailAfterLocalTarget( ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mapping) : base(shardMapManager, operationCode, shardMap, mapping) { }
/// <summary> /// Creates request to add shard to given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationCode">Store operation code.</param> /// <param name="shardMap">Shard map from which to remove mapping.</param> /// <param name="mapping">Mapping to add.</param> /// <param name="lockOwnerId">Id of lock owner.</param> /// <returns>The store operation.</returns> public virtual IStoreOperation CreateRemoveMappingOperation( ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mapping, Guid lockOwnerId) { return new RemoveMappingOperation( shardMapManager, operationCode, shardMap, mapping, lockOwnerId); }
/// <summary> /// Creates request to add shard to given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationCode">Store operation code.</param> /// <param name="shardMap">Shard map for which to add mapping.</param> /// <param name="mapping">Mapping to add.</param> /// <returns>The store operation.</returns> public virtual IStoreOperation CreateAddMappingOperation( ShardMapManager shardMapManager, StoreOperationCode operationCode, IStoreShardMap shardMap, IStoreMapping mapping) { return new AddMappingOperation( shardMapManager, operationCode, shardMap, mapping); }