/// <summary> /// Creates request to update a mapping in given shard map. /// </summary> /// <param name="operationCode">Operation code.</param> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationId">Operation Id.</param> /// <param name="undoStartState">Undo start state.</param> /// <param name="root">Xml representation of the object.</param> /// <param name="originalShardVersionRemoves">Original shard version for removes.</param> /// <param name="originalShardVersionAdds">Original shard version for adds.</param> /// <returns>The store operation.</returns> public virtual IStoreOperation CreateUpdateMappingOperation( StoreOperationCode operationCode, ShardMapManager shardMapManager, Guid operationId, StoreOperationState undoStartState, XElement root, Guid originalShardVersionRemoves, Guid originalShardVersionAdds) { return(new UpdateMappingOperation( shardMapManager, operationId, undoStartState, operationCode, StoreObjectFormatterXml.ReadIStoreShardMap(root.Element("ShardMap")), StoreObjectFormatterXml.ReadIStoreMapping( root.Element("Steps").Element("Step").Element("Mapping"), root.Element("Removes").Element("Shard")), StoreObjectFormatterXml.ReadIStoreMapping( root.Element("Steps").Element("Step").Element("Update").Element("Mapping"), root.Element("Adds").Element("Shard")), root.Element("PatternForKill").Value, StoreObjectFormatterXml.ReadLock(root.Element("Steps").Element("Step").Element("Lock")), originalShardVersionRemoves, originalShardVersionAdds)); }
/// <summary> /// Constructs request for obtaining all the shard maps and shards from an LSM. /// </summary> /// <param name="operationName">Operation name.</param> /// <param name="shardMapManager">Shard map manager.</param> /// <param name="location">Location of the LSM.</param> internal CheckShardLocalOperation( string operationName, ShardMapManager shardMapManager, ShardLocation location) : base(shardMapManager.Credentials, shardMapManager.RetryPolicy, location, operationName) { }
/// <summary> /// Ensures that the shard map and shard map manager information for given /// shard matches the one for current shard map. /// </summary> /// <param name="currentShardMapManager">Current shard map manager.</param> /// <param name="currentShardMap">Current shard map.</param> /// <param name="shard">Input shard.</param> /// <param name="operation">Operation being performed.</param> /// <param name="mappingType">Type of mapping.</param> internal static void EnsureShardBelongsToShardMap( ShardMapManager currentShardMapManager, ShardMap currentShardMap, Shard shard, string operation, string mappingType) { // Ensure that shard is associated with current shard map. if (shard.ShardMapId != currentShardMap.Id) { throw new InvalidOperationException( StringUtils.FormatInvariant( Errors._Shard_DifferentShardMap, shard.Location, mappingType, currentShardMap.Name, operation)); } // Ensure that shard is associated with current shard map manager instance. if (shard.Manager != currentShardMapManager) { throw new InvalidOperationException( StringUtils.FormatInvariant( Errors._Shard_DifferentShardMapManager, shard.Location, mappingType, currentShardMapManager.Credentials.ShardMapManagerLocation, operation)); } }
/// <summary> /// Converts IStoreShardMap to ShardMap. /// </summary> /// <param name="manager">Reference to shard map manager.</param> /// <param name="ssm">Storage representation for ShardMap.</param> /// <returns>ShardMap object corresponding to storange representation.</returns> internal static ShardMap CreateShardMapFromStoreShardMap( ShardMapManager manager, IStoreShardMap ssm) { switch (ssm.MapType) { case ShardMapType.List: // Create ListShardMap<TKey> return((ShardMap)Activator.CreateInstance( typeof(ListShardMap <>).MakeGenericType( ShardKey.TypeFromShardKeyType(ssm.KeyType)), BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { manager, ssm }, CultureInfo.InvariantCulture)); default: Debug.Assert(ssm.MapType == ShardMapType.Range); // Create RangeShardMap<TKey> return((ShardMap)Activator.CreateInstance( typeof(RangeShardMap <>).MakeGenericType( ShardKey.TypeFromShardKeyType(ssm.KeyType)), BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { manager, ssm }, CultureInfo.InvariantCulture)); } }
/// <summary> /// Constructs request to get shard with specific location for given shard map from GSM. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <param name="shardMap">Shard map for which shard is being requested.</param> /// <param name="location">Location of shard being searched.</param> internal FindShardByLocationGlobalOperation(ShardMapManager shardMapManager, string operationName, IStoreShardMap shardMap, ShardLocation location) : base(shardMapManager.Credentials, shardMapManager.RetryPolicy, operationName) { _shardMapManager = shardMapManager; _shardMap = shardMap; _location = location; }
/// <summary> /// Tries to obtains a <see cref="RangeShardMap{TKey}"/> given the name. /// </summary> /// <typeparam name="TKey">Key type.</typeparam> /// <param name="shardMapName">Name of shard map.</param> /// <param name="shardMap">Shard map with the specified name.</param> /// <returns><c>true</c> if shard map with the specified name was found, <c>false</c> otherwise.</returns> public bool TryGetRangeShardMap <TKey>(string shardMapName, out RangeShardMap <TKey> shardMap) { ShardMapManager.ValidateShardMapName(shardMapName); using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid())) { Tracer.TraceVerbose( TraceSourceConstants.ComponentNames.ShardMapManager, "TryGetRangeShardMap", "Start; ShardMap: {0}", shardMapName); shardMap = this.LookupAndConvertShardMapHelper <RangeShardMap <TKey> >( "TryGetRangeShardMap", shardMapName, ShardMapExtensions.AsRangeShardMap <TKey>, false); Tracer.TraceInfo( TraceSourceConstants.ComponentNames.ShardMapManager, "TryGetRangeShardMap", "Complete; ShardMap: {0}", shardMapName); return(shardMap != null); } }
/// <summary> /// Constructs request for attaching the given shard map and shard information to the GSM database. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="shard">Shard to attach</param> /// <param name="shardMap">Shard map to attach specified shard</param> /// <returns>The store operation.</returns> public virtual IStoreOperation CreateAttachShardOperation( ShardMapManager shardMapManager, IStoreShardMap shardMap, IStoreShard shard) { return(new AttachShardOperation(shardMapManager, shardMap, shard)); }
/// <summary> /// Obtains a <see cref="ListShardMap{TKey}"/> given the name. /// </summary> /// <typeparam name="TKey">Key type.</typeparam> /// <param name="shardMapName">Name of shard map.</param> /// <returns>Resulting ShardMap.</returns> public ListShardMap <TKey> GetListShardMap <TKey>(string shardMapName) { ShardMapManager.ValidateShardMapName(shardMapName); using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid())) { Tracer.TraceVerbose( TraceSourceConstants.ComponentNames.ShardMapManager, "GetListShardMap", "Start; ShardMap: {0}", shardMapName); ListShardMap <TKey> shardMap = this.LookupAndConvertShardMapHelper <ListShardMap <TKey> >( "GetListShardMap", shardMapName, ShardMapExtensions.AsListShardMap <TKey>, true); Debug.Assert(shardMap != null); Tracer.TraceInfo( TraceSourceConstants.ComponentNames.ShardMapManager, "GetListShardMap", "Complete; ShardMap: {0}", shardMapName); return(shardMap); } }
/// <summary> /// Obtains a <see cref="ShardMap"/> given the name. /// </summary> /// <param name="shardMapName">Name of shard map.</param> /// <returns>Shardmap with the specificed name.</returns> public ShardMap GetShardMap(string shardMapName) { ShardMapManager.ValidateShardMapName(shardMapName); using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid())) { Tracer.TraceVerbose( TraceSourceConstants.ComponentNames.ShardMapManager, "GetShardMap", "Start; ShardMap: {0}", shardMapName); ShardMap shardMap = this.LookupAndConvertShardMapHelper <ShardMap>( "GetShardMap", shardMapName, (sm, t) => sm, true); Debug.Assert(shardMap != null); Tracer.TraceInfo( TraceSourceConstants.ComponentNames.ShardMapManager, "GetShardMap", "Complete; ShardMap: {0}", shardMapName); return(shardMap); } }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="manager">Reference to ShardMapManager.</param> /// <param name="ssm">Storage representation.</param> internal ListShardMap(ShardMapManager manager, IStoreShardMap ssm) : base(manager, ssm) { Debug.Assert(manager != null); Debug.Assert(ssm != null); _lsm = new ListShardMapper <TKey>(this.Manager, this); }
/// <summary> /// Creates request to attach shard to given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="shardMap">Shard map for which to attach shard.</param> /// <param name="shard">Shard to attach.</param> protected internal AttachShardOperation( ShardMapManager shardMapManager, IStoreShardMap shardMap, IStoreShard shard) : this(shardMapManager, Guid.NewGuid(), StoreOperationState.UndoBegin, shardMap, shard) { }
/// <summary> /// Creates request to update shard in given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="shardMap">Shard map for which to remove shard.</param> /// <param name="shardOld">Shard to update.</param> /// <param name="shardNew">Updated shard.</param> protected internal UpdateShardOperation( ShardMapManager shardMapManager, IStoreShardMap shardMap, IStoreShard shardOld, IStoreShard shardNew) : this(shardMapManager, Guid.NewGuid(), StoreOperationState.UndoBegin, shardMap, shardOld, shardNew) { }
/// <summary> /// Constructs request to upgrade store hosting GSM. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <param name="targetVersion">Target version to upgrade.</param> internal UpgradeStoreGlobalOperation( ShardMapManager shardMapManager, string operationName, Version targetVersion) : base(shardMapManager.Credentials, shardMapManager.RetryPolicy, operationName) { _targetVersion = targetVersion; }
/// <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; }
/// <summary> /// Base shard mapper, which is just a holder of some fields. /// </summary> /// <param name="manager">Reference to ShardMapManager.</param> /// <param name="sm">Containing shard map.</param> protected BaseShardMapper(ShardMapManager manager, ShardMap sm) { Debug.Assert(manager != null); Debug.Assert(sm != null); this.Manager = manager; this.ShardMap = sm; }
/// <summary> /// Constructs a request to get all schema info objects from GSM. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateGetShardingSchemaInfosGlobalOperation( ShardMapManager shardMapManager, string operationName) { return(new GetShardingSchemaInfosGlobalOperation( shardMapManager, operationName)); }
/// <summary> /// Constructs request for replacing the GSM mappings for given shard map with the input mappings. /// </summary> /// <param name="shardMapManager">Shard map manager.</param> /// <param name="operationName">Operation name.</param> /// <param name="shardMap">GSM Shard map.</param> /// <param name="shard">GSM Shard.</param> /// <param name="mappingsToRemove">Optional list of mappings to remove.</param> /// <param name="mappingsToAdd">List of mappings to add.</param> internal ReplaceMappingsGlobalOperation(ShardMapManager shardMapManager, string operationName, IStoreShardMap shardMap, IStoreShard shard, IEnumerable <IStoreMapping> mappingsToRemove, IEnumerable <IStoreMapping> mappingsToAdd) : base(shardMapManager.Credentials, shardMapManager.RetryPolicy, operationName) { _shardMap = shardMap; _shard = shard; _mappingsToRemove = mappingsToRemove; _mappingsToAdd = mappingsToAdd; }
/// <summary> /// Creates request to update shard in given shard map. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="shardMap">Shard map for which to remove shard.</param> /// <param name="shardOld">Shard to update.</param> /// <param name="shardNew">Updated shard.</param> /// <returns>The store operation.</returns> public virtual IStoreOperation CreateUpdateShardOperation( ShardMapManager shardMapManager, IStoreShardMap shardMap, IStoreShard shardOld, IStoreShard shardNew) { return(new UpdateShardOperation(shardMapManager, shardMap, shardOld, shardNew)); }
/// <summary> /// Constructs request to get all shard maps from GSM. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateLoadShardMapManagerGlobalOperation( ShardMapManager shardMapManager, string operationName) { return(new LoadShardMapManagerGlobalOperation( shardMapManager, operationName)); }
/// <summary> /// Constructs request to get distinct shard locations from GSM. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateGetDistinctShardLocationsGlobalOperation( ShardMapManager shardMapManager, string operationName) { return(new GetDistinctShardLocationsGlobalOperation( shardMapManager, operationName)); }
/// <summary> /// Constructs request to get all shards for given shard map from GSM. /// </summary> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="shardMap">Shard map for which shards are being requested.</param> internal GetShardsGlobalOperation( string operationName, ShardMapManager shardMapManager, IStoreShardMap shardMap) : base(shardMapManager.Credentials, shardMapManager.RetryPolicy, operationName) { _shardMapManager = shardMapManager; _shardMap = shardMap; }
/// <summary> /// Constructs request for obtaining all the shard maps and shards from an LSM. /// </summary> /// <param name="shardMapManager">Shard map manager.</param> /// <param name="location">Location of the LSM.</param> /// <param name="operationName">Operatio name.</param> public virtual IStoreOperationLocal CreateGetShardsLocalOperation( ShardMapManager shardMapManager, ShardLocation location, string operationName) { return(new GetShardsLocalOperation( shardMapManager, location, operationName)); }
/// <summary> /// Constructs request for obtaining all the shard maps and shards from an LSM. /// </summary> /// <param name="operationName">Operation name.</param> /// <param name="shardMapManager">Shard map manager.</param> /// <param name="location">Location of the LSM.</param> public virtual IStoreOperationLocal CreateCheckShardLocalOperation( string operationName, ShardMapManager shardMapManager, ShardLocation location) { return(new CheckShardLocalOperation( operationName, shardMapManager, location)); }
/// <summary> /// Constructs a request to upgrade global store. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <param name="targetVersion">Target version of store to deploy.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateUpgradeStoreGlobalOperation( ShardMapManager shardMapManager, string operationName, Version targetVersion) { return(new UpgradeStoreGlobalOperation( shardMapManager, operationName, targetVersion)); }
/// <summary> /// Constructs request to remove given shard map from 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 remove.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateRemoveShardMapGlobalOperation( ShardMapManager shardMapManager, string operationName, IStoreShardMap shardMap) { return(new RemoveShardMapGlobalOperation( shardMapManager, operationName, shardMap)); }
/// <summary> /// Constructs request to find shard map with given name from GSM. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <param name="shardMapName">Name of the shard map being searched.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateFindShardMapByNameGlobalOperation( ShardMapManager shardMapManager, string operationName, string shardMapName) { return(new FindShardMapByNameGlobalOperation( shardMapManager, operationName, shardMapName)); }
/// <summary> /// Constructs request to get all shards for given shard map from GSM. /// </summary> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="shardMap">Shard map for which shards are being requested.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateGetShardsGlobalOperation( string operationName, ShardMapManager shardMapManager, IStoreShardMap shardMap) { return(new GetShardsGlobalOperation( operationName, shardMapManager, shardMap)); }
/// <summary> /// Constructs a request to update schema info to GSM. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <param name="schemaInfo">Schema info to update.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateUpdateShardingSchemaInfoGlobalOperation( ShardMapManager shardMapManager, string operationName, IStoreSchemaInfo schemaInfo) { return(new UpdateShardingSchemaInfoGlobalOperation( shardMapManager, operationName, schemaInfo)); }
/// <summary> /// Constructs a request to delete schema info from GSM. /// </summary> /// <param name="shardMapManager">Shard map manager object.</param> /// <param name="operationName">Operation name, useful for diagnostics.</param> /// <param name="schemaInfoName">Name of schema info to delete.</param> /// <returns>The store operation.</returns> public virtual IStoreOperationGlobal CreateRemoveShardingSchemaInfoGlobalOperation( ShardMapManager shardMapManager, string operationName, string schemaInfoName) { return(new RemoveShardingSchemaInfoGlobalOperation( shardMapManager, operationName, schemaInfoName)); }
public static bool TryGetSqlShardMapManager( string connectionString, ShardMapManagerLoadPolicy loadPolicy, out ShardMapManager shardMapManager) { return(TryGetSqlShardMapManager( connectionString, loadPolicy, RetryBehavior.DefaultRetryBehavior, out shardMapManager)); }