コード例 #1
0
        /// <summary>
        /// Constructs an instance of SqlOperationGlobal.
        /// </summary>
        /// <param name="credentials">Credentials for connecting to SMM GSM database.</param>
        /// <param name="retryPolicy">Retry policy for requests.</param>
        /// <param name="operationName">Operation name, useful for diagnostics.</param>
        internal StoreOperationGlobal(SqlShardMapManagerCredentials credentials, TransientFaultHandling.RetryPolicy retryPolicy, string operationName)
        {
            this.OperationName = operationName;

            _credentials = credentials;
            _retryPolicy = retryPolicy;
        }
コード例 #2
0
ファイル: ShardMap.cs プロジェクト: stuartpa/elastic-db-tools
        /// <summary>
        /// Ensures that the provided connection string is valid and builds the connection string
        /// to be used for DDR connection to the given shard provider.
        /// </summary>
        /// <param name="shardProvider">Shard provider containing shard to be connected to.</param>
        /// <param name="connectionString">Input connection string.</param>
        /// <returns>Connection string for DDR connection.</returns>
        private string ValidateAndPrepareConnectionString(IShardProvider shardProvider, string connectionString)
        {
            Debug.Assert(shardProvider != null);
            Debug.Assert(connectionString != null);

            // Devnote: If connection string specifies Active Directory authentication and runtime is not
            // .NET 4.6 or higher, then below call will throw.
            SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder(connectionString);

            // DataSource must not be set.
            if (!string.IsNullOrEmpty(connectionStringBuilder.DataSource))
            {
                throw new ArgumentException(
                          StringUtils.FormatInvariant(
                              Errors._ShardMap_OpenConnection_ConnectionStringPropertyDisallowed,
                              "DataSource"),
                          "connectionString");
            }

            // InitialCatalog must not be set.
            if (!string.IsNullOrEmpty(connectionStringBuilder.InitialCatalog))
            {
                throw new ArgumentException(
                          StringUtils.FormatInvariant(
                              Errors._ShardMap_OpenConnection_ConnectionStringPropertyDisallowed,
                              "Initial Catalog"),
                          "connectionString");
            }

            // ConnectRetryCount must not be set (default value is 1)
            if (ShardMapUtils.IsConnectionResiliencySupported && (int)connectionStringBuilder[ShardMapUtils.ConnectRetryCount] > 1)
            {
                throw new ArgumentException(
                          StringUtils.FormatInvariant(
                              Errors._ShardMap_OpenConnection_ConnectionStringPropertyDisallowed,
                              ShardMapUtils.ConnectRetryCount),
                          "connectionString");
            }

            // Verify that either UserID/Password or provided or integrated authentication is enabled.
            SqlShardMapManagerCredentials.EnsureCredentials(connectionStringBuilder, "connectionString");

            Shard s = shardProvider.ShardInfo;

            connectionStringBuilder.DataSource     = s.Location.DataSource;
            connectionStringBuilder.InitialCatalog = s.Location.Database;

            // Append the proper post-fix for ApplicationName
            connectionStringBuilder.ApplicationName = ApplicationNameHelper.AddApplicationNameSuffix(
                connectionStringBuilder.ApplicationName,
                this.ApplicationNameSuffix);

            // Disable connection resiliency if necessary
            if (ShardMapUtils.IsConnectionResiliencySupported)
            {
                connectionStringBuilder[ShardMapUtils.ConnectRetryCount] = 0;
            }

            return(connectionStringBuilder.ConnectionString);
        }
コード例 #3
0
        private static ShardMapManager GetSqlShardMapManager(
            string connectionString,
            SqlCredential secureCredential,
            ShardMapManagerLoadPolicy loadPolicy,
            RetryBehavior retryBehavior,
            EventHandler <RetryingEventArgs> retryEventHandler,
            bool throwOnFailure)
        {
            Debug.Assert(connectionString != null);
            Debug.Assert(retryBehavior != null);

            SqlShardMapManagerCredentials credentials = new SqlShardMapManagerCredentials(connectionString, secureCredential);

            StoreOperationFactory storeOperationFactory = new StoreOperationFactory();

            IStoreResults result;

            TransientFaultHandling.RetryPolicy retryPolicy = new TransientFaultHandling.RetryPolicy(
                new ShardManagementTransientErrorDetectionStrategy(retryBehavior),
                RetryPolicy.DefaultRetryPolicy.GetRetryStrategy());

            EventHandler <TransientFaultHandling.RetryingEventArgs> handler = (sender, args) =>
            {
                if (retryEventHandler != null)
                {
                    retryEventHandler(sender, new RetryingEventArgs(args));
                }
            };

            try
            {
                retryPolicy.Retrying += handler;

                using (IStoreOperationGlobal op = storeOperationFactory.CreateGetShardMapManagerGlobalOperation(
                           credentials,
                           retryPolicy,
                           throwOnFailure ? "GetSqlShardMapManager" : "TryGetSqlShardMapManager",
                           throwOnFailure))
                {
                    result = op.Do();
                }
            }
            finally
            {
                retryPolicy.Retrying -= handler;
            }

            return(result.Result == StoreResult.Success ?
                   new ShardMapManager(
                       credentials,
                       new SqlStoreConnectionFactory(),
                       storeOperationFactory,
                       new CacheStore(),
                       loadPolicy,
                       RetryPolicy.DefaultRetryPolicy,
                       retryBehavior,
                       retryEventHandler) :
                   null);
        }
コード例 #4
0
        /// <summary>
        /// Instantiates the object that holds the credentials for accessing SQL Servers
        /// containing the shard map manager data.
        /// </summary>
        /// <param name="connectionString">
        /// Connection string for shard map manager data source.
        /// </param>
        /// <param name="secureCredential">
        ///  Secure credential for shard map manager data source.
        /// </param>
        public SqlShardMapManagerCredentials(string connectionString, SqlCredential secureCredential)
        {
            ExceptionUtils.DisallowNullArgument(connectionString, "connectionString");

            this._secureCredential = secureCredential;

            // Devnote: If connection string specifies Active Directory authentication and runtime is not
            // .NET 4.6 or higher, then below call will throw.
            SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder(connectionString);

            #region GSM Validation

            // DataSource must be set.
            if (string.IsNullOrEmpty(connectionStringBuilder.DataSource))
            {
                throw new ArgumentException(
                          StringUtils.FormatInvariant(
                              Errors._SqlShardMapManagerCredentials_ConnectionStringPropertyRequired,
                              "DataSource"),
                          "connectionString");
            }

            // InitialCatalog must be set.
            if (string.IsNullOrEmpty(connectionStringBuilder.InitialCatalog))
            {
                throw new ArgumentException(
                          StringUtils.FormatInvariant(
                              Errors._SqlShardMapManagerCredentials_ConnectionStringPropertyRequired,
                              "Initial Catalog"),
                          "connectionString");
            }

            // Ensure credentials are specified for GSM connectivity.
            SqlShardMapManagerCredentials.EnsureCredentials(
                connectionStringBuilder,
                "connectionString",
                this._secureCredential);

            #endregion GSM Validation

            // Copy the input connection strings.
            _connectionStringShardMapManager = new SqlConnectionStringBuilder(connectionStringBuilder.ConnectionString);

            _connectionStringShardMapManager.ApplicationName = ApplicationNameHelper.AddApplicationNameSuffix(
                _connectionStringShardMapManager.ApplicationName,
                GlobalConstants.ShardMapManagerInternalConnectionSuffixGlobal);

            _connectionStringShard = new SqlConnectionStringBuilder(connectionStringBuilder.ConnectionString);

            _connectionStringShard.Remove("Data Source");
            _connectionStringShard.Remove("Initial Catalog");

            _connectionStringShard.ApplicationName = ApplicationNameHelper.AddApplicationNameSuffix(
                _connectionStringShard.ApplicationName,
                GlobalConstants.ShardMapManagerInternalConnectionSuffixLocal);
        }
コード例 #5
0
 /// <summary>
 /// Constructs an instance of SqlOperationLocal.
 /// </summary>
 /// <param name="credentials">Credentials for connecting to SMM databases.</param>
 /// <param name="retryPolicy">Retry policy for requests.</param>
 /// <param name="location">Shard location where the operation is to be performed.</param>
 /// <param name="operationName">Operation name.</param>
 internal StoreOperationLocal(
     SqlShardMapManagerCredentials credentials,
     TransientFaultHandling.RetryPolicy retryPolicy,
     ShardLocation location,
     string operationName)
 {
     _credentials = credentials;
     _retryPolicy = retryPolicy;
     this.OperationName = operationName;
     this.Location = location;
 }
 /// <summary>
 /// Constructs request for deploying SMM storage objects to target GSM database.
 /// </summary>
 /// <param name="credentials">Credentials for connection.</param>
 /// <param name="retryPolicy">Retry policy.</param>
 /// <param name="operationName">Operation name, useful for diagnostics.</param>
 /// <param name="createMode">Creation mode.</param>
 /// <param name="targetVersion">target version of store to deploy</param>
 internal CreateShardMapManagerGlobalOperation(
     SqlShardMapManagerCredentials credentials,
     TransientFaultHandling.RetryPolicy retryPolicy,
     string operationName,
     ShardMapManagerCreateMode createMode,
     Version targetVersion) :
     base(credentials, retryPolicy, operationName)
 {
     _createMode    = createMode;
     _targetVersion = targetVersion;
 }
コード例 #7
0
 /// <summary>
 /// Given the connection string, opens up the corresponding data source and obtains the ShardMapManager.
 /// </summary>
 /// <param name="credentials">Credentials for performing ShardMapManager operations.</param>
 /// <param name="storeConnectionFactory">Factory for store connections.</param>
 /// <param name="storeOperationFactory">Factory for store operations.</param>
 /// <param name="cacheStore">Cache store.</param>
 /// <param name="loadPolicy">Initialization policy.</param>
 /// <param name="retryPolicy">Policy for performing retries on connections to shard map manager database.</param>
 /// <param name="retryBehavior">Policy for detecting transient errors.</param>
 internal ShardMapManager(
     SqlShardMapManagerCredentials credentials,
     IStoreConnectionFactory storeConnectionFactory,
     IStoreOperationFactory storeOperationFactory,
     ICacheStore cacheStore,
     ShardMapManagerLoadPolicy loadPolicy,
     RetryPolicy retryPolicy,
     RetryBehavior retryBehavior)
     : this(credentials, storeConnectionFactory, storeOperationFactory, cacheStore, loadPolicy, retryPolicy, retryBehavior, null)
 {
 }
コード例 #8
0
 /// <summary>
 /// Constructs request for deploying SMM storage objects to target GSM database.
 /// </summary>
 /// <param name="credentials">Credentials for connection.</param>
 /// <param name="retryPolicy">Retry policy.</param>
 /// <param name="operationName">Operation name, useful for diagnostics.</param>
 /// <param name="createMode">Creation mode.</param>
 /// <param name="targetVersion">target version of store to deploy</param>
 internal CreateShardMapManagerGlobalOperation(
     SqlShardMapManagerCredentials credentials,
     TransientFaultHandling.RetryPolicy retryPolicy,
     string operationName,
     ShardMapManagerCreateMode createMode,
     Version targetVersion) :
     base(credentials, retryPolicy, operationName)
 {
     _createMode = createMode;
     _targetVersion = targetVersion;
 }
コード例 #9
0
 /// <summary>
 /// Constructs an instance of SqlOperationLocal.
 /// </summary>
 /// <param name="credentials">Credentials for connecting to SMM databases.</param>
 /// <param name="retryPolicy">Retry policy for requests.</param>
 /// <param name="location">Shard location where the operation is to be performed.</param>
 /// <param name="operationName">Operation name.</param>
 internal StoreOperationLocal(
     SqlShardMapManagerCredentials credentials,
     TransientFaultHandling.RetryPolicy retryPolicy,
     ShardLocation location,
     string operationName)
 {
     _credentials       = credentials;
     _retryPolicy       = retryPolicy;
     this.OperationName = operationName;
     this.Location      = location;
 }
コード例 #10
0
 /// <summary>
 /// Constructs request for obtaining shard map manager object if the GSM has the SMM objects in it.
 /// </summary>
 /// <param name="credentials">Credentials for connection.</param>
 /// <param name="retryPolicy">Retry policy.</param>
 /// <param name="operationName">Operation name, useful for diagnostics.</param>
 /// <param name="throwOnFailure">Whether to throw exception on failure or return error code.</param>
 /// <returns>The store operation.</returns>
 public virtual IStoreOperationGlobal CreateGetShardMapManagerGlobalOperation(
     SqlShardMapManagerCredentials credentials,
     TransientFaultHandling.RetryPolicy retryPolicy,
     string operationName,
     bool throwOnFailure)
 {
     return(new GetShardMapManagerGlobalOperation(
                credentials,
                retryPolicy,
                operationName,
                throwOnFailure));
 }
コード例 #11
0
 /// <summary>
 /// Constructs request for obtaining shard map manager object if the GSM has the SMM objects in it.
 /// </summary>
 /// <param name="credentials">Credentials for connection.</param>
 /// <param name="retryPolicy">Retry policy.</param>
 /// <param name="operationName">Operation name, useful for diagnostics.</param>
 /// <param name="throwOnFailure">Whether to throw exception on failure or return error code.</param>
 /// <returns>The store operation.</returns>
 public virtual IStoreOperationGlobal CreateGetShardMapManagerGlobalOperation(
     SqlShardMapManagerCredentials credentials,
     TransientFaultHandling.RetryPolicy retryPolicy,
     string operationName,
     bool throwOnFailure)
 {
     return new GetShardMapManagerGlobalOperation(
         credentials,
         retryPolicy,
         operationName,
         throwOnFailure);
 }
コード例 #12
0
 /// <summary>
 /// Constructs request for deploying SMM storage objects to target GSM database.
 /// </summary>
 /// <param name="credentials">Credentials for connection.</param>
 /// <param name="retryPolicy">Retry policy.</param>
 /// <param name="operationName">Operation name, useful for diagnostics.</param>
 /// <param name="createMode">Creation mode.</param>
 /// <param name="targetVersion">target version of store to deploy, this will be used mainly for upgrade testing purposes.</param>
 /// <returns>The store operation.</returns>
 public virtual IStoreOperationGlobal CreateCreateShardMapManagerGlobalOperation(
     SqlShardMapManagerCredentials credentials,
     TransientFaultHandling.RetryPolicy retryPolicy,
     string operationName,
     ShardMapManagerCreateMode createMode,
     Version targetVersion)
 {
     return(new CreateShardMapManagerGlobalOperation(
                credentials,
                retryPolicy,
                operationName,
                createMode,
                targetVersion));
 }
コード例 #13
0
 /// <summary>
 /// Constructs request for deploying SMM storage objects to target GSM database.
 /// </summary>
 /// <param name="credentials">Credentials for connection.</param>
 /// <param name="retryPolicy">Retry policy.</param>
 /// <param name="operationName">Operation name, useful for diagnostics.</param>
 /// <param name="createMode">Creation mode.</param>
 /// <param name="targetVersion">target version of store to deploy, this will be used mainly for upgrade testing purposes.</param>
 /// <returns>The store operation.</returns>
 public virtual IStoreOperationGlobal CreateCreateShardMapManagerGlobalOperation(
     SqlShardMapManagerCredentials credentials,
     TransientFaultHandling.RetryPolicy retryPolicy,
     string operationName,
     ShardMapManagerCreateMode createMode,
     Version targetVersion)
 {
     return new CreateShardMapManagerGlobalOperation(
         credentials,
         retryPolicy,
         operationName,
         createMode,
         targetVersion);
 }
コード例 #14
0
        /// <summary>
        /// Given the connection string, opens up the corresponding data source and obtains the ShardMapManager.
        /// </summary>
        /// <param name="credentials">Credentials for performing ShardMapManager operations.</param>
        /// <param name="storeConnectionFactory">Factory for store connections.</param>
        /// <param name="storeOperationFactory">Factory for store operations.</param>
        /// <param name="cacheStore">Cache store.</param>
        /// <param name="loadPolicy">Initialization policy.</param>
        /// <param name="retryPolicy">Policy for performing retries on connections to shard map manager database.</param>
        /// <param name="retryBehavior">Policy for detecting transient errors.</param>
        /// <param name="retryEventHandler">Event handler for store operation retry events.</param>
        internal ShardMapManager(
            SqlShardMapManagerCredentials credentials,
            IStoreConnectionFactory storeConnectionFactory,
            IStoreOperationFactory storeOperationFactory,
            ICacheStore cacheStore,
            ShardMapManagerLoadPolicy loadPolicy,
            RetryPolicy retryPolicy,
            RetryBehavior retryBehavior,
            EventHandler <RetryingEventArgs> retryEventHandler)
        {
            Debug.Assert(credentials != null);

            this.Credentials            = credentials;
            this.StoreConnectionFactory = storeConnectionFactory;
            this.StoreOperationFactory  = storeOperationFactory;
            this.Cache = cacheStore;

            this.RetryPolicy = new TransientFaultHandling.RetryPolicy(
                new ShardManagementTransientErrorDetectionStrategy(retryBehavior),
                retryPolicy.GetRetryStrategy());

            // Register for TfhImpl.RetryPolicy.Retrying event.
            this.RetryPolicy.Retrying += this.ShardMapManagerRetryingEventHandler;

            // Add user specified event handler.
            if (retryEventHandler != null)
            {
                this.ShardMapManagerRetrying += retryEventHandler;
            }

            if (loadPolicy == ShardMapManagerLoadPolicy.Eager)
            {
                // We eagerly load everything from ShardMapManager. In case of lazy
                // loading policy, we will add things to local caches based on cache
                // misses on lookups.
                this.LoadFromStore();
            }
        }
コード例 #15
0
        private static ShardMapManager GetSqlShardMapManager(
            string connectionString,
            ShardMapManagerLoadPolicy loadPolicy,
            RetryBehavior retryBehavior,
            EventHandler<RetryingEventArgs> retryEventHandler,
            bool throwOnFailure)
        {
            Debug.Assert(connectionString != null);
            Debug.Assert(retryBehavior != null);

            SqlShardMapManagerCredentials credentials = new SqlShardMapManagerCredentials(connectionString);

            StoreOperationFactory storeOperationFactory = new StoreOperationFactory();

            IStoreResults result;

            TransientFaultHandling.RetryPolicy retryPolicy = new TransientFaultHandling.RetryPolicy(
                    new ShardManagementTransientErrorDetectionStrategy(retryBehavior),
                    RetryPolicy.DefaultRetryPolicy.GetRetryStrategy());

            EventHandler<TransientFaultHandling.RetryingEventArgs> handler = (sender, args) =>
            {
                if (retryEventHandler != null)
                {
                    retryEventHandler(sender, new RetryingEventArgs(args));
                }
            };

            try
            {
                retryPolicy.Retrying += handler;

                using (IStoreOperationGlobal op = storeOperationFactory.CreateGetShardMapManagerGlobalOperation(
                    credentials,
                    retryPolicy,
                    throwOnFailure ? "GetSqlShardMapManager" : "TryGetSqlShardMapManager",
                    throwOnFailure))
                {
                    result = op.Do();
                }
            }
            finally
            {
                retryPolicy.Retrying -= handler;
            }

            return result.Result == StoreResult.Success ?
                new ShardMapManager(
                    credentials,
                    new SqlStoreConnectionFactory(),
                    storeOperationFactory,
                    new CacheStore(),
                    loadPolicy,
                    RetryPolicy.DefaultRetryPolicy,
                    retryBehavior,
                    retryEventHandler) :
                null;
        }
コード例 #16
0
        private static ShardMapManager CreateSqlShardMapManagerImpl(
            string connectionString,
            ShardMapManagerCreateMode createMode,
            RetryBehavior retryBehavior,
            EventHandler<RetryingEventArgs> retryEventHandler,
            Version targetVersion)
        {
            ExceptionUtils.DisallowNullArgument(connectionString, "connectionString");
            ExceptionUtils.DisallowNullArgument(retryBehavior, "retryBehavior");

            if (createMode != ShardMapManagerCreateMode.KeepExisting &&
                createMode != ShardMapManagerCreateMode.ReplaceExisting)
            {
                throw new ArgumentException(
                    StringUtils.FormatInvariant(
                        Errors._General_InvalidArgumentValue,
                        createMode,
                        "createMode"),
                    "createMode");
            }

            using (ActivityIdScope activityIdScope = new ActivityIdScope(Guid.NewGuid()))
            {
                DateTime getStartTime = DateTime.UtcNow;
                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.ShardMapManagerFactory,
                    "CreateSqlShardMapManager",
                    "Start; ");

                SqlShardMapManagerCredentials credentials = new SqlShardMapManagerCredentials(connectionString);

                TransientFaultHandling.RetryPolicy retryPolicy = new TransientFaultHandling.RetryPolicy(
                        new ShardManagementTransientErrorDetectionStrategy(retryBehavior),
                        RetryPolicy.DefaultRetryPolicy.GetRetryStrategy());

                EventHandler<TransientFaultHandling.RetryingEventArgs> handler = (sender, args) =>
                {
                    if (retryEventHandler != null)
                    {
                        retryEventHandler(sender, new RetryingEventArgs(args));
                    }
                };

                try
                {
                    retryPolicy.Retrying += handler;

                    // specifying targetVersion as GlobalConstants.GsmVersionClient to deploy latest store by default.
                    using (IStoreOperationGlobal op = new StoreOperationFactory().CreateCreateShardMapManagerGlobalOperation(
                        credentials,
                        retryPolicy,
                        "CreateSqlShardMapManager",
                        createMode,
                        targetVersion))
                    {
                        op.Do();
                    }

                    Tracer.TraceInfo(
                        TraceSourceConstants.ComponentNames.ShardMapManagerFactory,
                        "CreateSqlShardMapManager",
                        "Complete; Duration: {0}",
                        DateTime.UtcNow - getStartTime);
                }
                finally
                {
                    retryPolicy.Retrying -= handler;
                }

                return new ShardMapManager(
                    credentials,
                    new SqlStoreConnectionFactory(),
                    new StoreOperationFactory(),
                    new CacheStore(),
                    ShardMapManagerLoadPolicy.Lazy,
                    RetryPolicy.DefaultRetryPolicy,
                    retryBehavior,
                    retryEventHandler);
            }
        }
コード例 #17
0
        private static ShardMapManager CreateSqlShardMapManagerImpl(
            SqlConnectionInfo connectionInfo,
            ShardMapManagerCreateMode createMode,
            RetryBehavior retryBehavior,
            EventHandler <RetryingEventArgs> retryEventHandler,
            Version targetVersion)
        {
            ExceptionUtils.DisallowNullArgument(connectionInfo, "connectionInfo");
            ExceptionUtils.DisallowNullArgument(retryBehavior, "retryBehavior");

            if (createMode != ShardMapManagerCreateMode.KeepExisting &&
                createMode != ShardMapManagerCreateMode.ReplaceExisting)
            {
                throw new ArgumentException(
                          StringUtils.FormatInvariant(
                              Errors._General_InvalidArgumentValue,
                              createMode,
                              "createMode"),
                          "createMode");
            }

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

                Stopwatch stopwatch = Stopwatch.StartNew();

                SqlShardMapManagerCredentials credentials = new SqlShardMapManagerCredentials(connectionInfo);

                TransientFaultHandling.RetryPolicy retryPolicy = new TransientFaultHandling.RetryPolicy(
                    new ShardManagementTransientErrorDetectionStrategy(retryBehavior),
                    RetryPolicy.DefaultRetryPolicy.GetRetryStrategy());

                EventHandler <TransientFaultHandling.RetryingEventArgs> handler = (sender, args) =>
                {
                    if (retryEventHandler != null)
                    {
                        retryEventHandler(sender, new RetryingEventArgs(args));
                    }
                };

                try
                {
                    retryPolicy.Retrying += handler;

                    // specifying targetVersion as GlobalConstants.GsmVersionClient to deploy latest store by default.
                    using (IStoreOperationGlobal op = new StoreOperationFactory().CreateCreateShardMapManagerGlobalOperation(
                               credentials,
                               retryPolicy,
                               "CreateSqlShardMapManager",
                               createMode,
                               targetVersion))
                    {
                        op.Do();
                    }

                    stopwatch.Stop();

                    Tracer.TraceInfo(
                        TraceSourceConstants.ComponentNames.ShardMapManagerFactory,
                        "CreateSqlShardMapManager",
                        "Complete; Duration: {0}",
                        stopwatch.Elapsed);
                }
                finally
                {
                    retryPolicy.Retrying -= handler;
                }

                return(new ShardMapManager(
                           credentials,
                           new SqlStoreConnectionFactory(),
                           new StoreOperationFactory(),
                           new CacheStore(),
                           ShardMapManagerLoadPolicy.Lazy,
                           RetryPolicy.DefaultRetryPolicy,
                           retryBehavior,
                           retryEventHandler));
            }
        }
 /// <summary>
 /// Constructs request for obtaining shard map manager object if the GSM has the SMM objects in it.
 /// </summary>
 /// <param name="credentials">Credentials for connection.</param>
 /// <param name="retryPolicy">Retry policy.</param>
 /// <param name="operationName">Operation name, useful for diagnostics.</param>
 /// <param name="throwOnFailure">Whether to throw exception on failure or return error code.</param>
 internal GetShardMapManagerGlobalOperation(SqlShardMapManagerCredentials credentials, TransientFaultHandling.RetryPolicy retryPolicy, string operationName, bool throwOnFailure) :
     base(credentials, retryPolicy, operationName)
 {
     _throwOnFailure = throwOnFailure;
 }
コード例 #19
0
 /// <summary>
 /// Instantiates a store object using the credentials provided by the user.
 /// </summary>
 /// <param name="credentials">Credentials for store operations.</param>
 protected internal SqlStore(SqlShardMapManagerCredentials credentials)
 {
     Debug.Assert(credentials != null);
     this.credentials = credentials;
 }
コード例 #20
0
        /// <summary>
        /// Instantiates the object that holds the credentials for accessing SQL Servers
        /// containing the shard map manager data.
        /// </summary>
        /// <param name="connectionInfo">
        /// Connection info for shard map manager data source.
        /// </param>
        public SqlShardMapManagerCredentials(SqlConnectionInfo connectionInfo)
        {
            ExceptionUtils.DisallowNullArgument(connectionInfo, "connectionInfo");

            // Devnote: If connection string specifies Active Directory authentication and runtime is not
            // .NET 4.6 or higher, then below call will throw.
            SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder(connectionInfo.ConnectionString);

            #region GSM Validation

            // DataSource must be set.
            if (string.IsNullOrEmpty(connectionStringBuilder.DataSource))
            {
                throw new ArgumentException(
                          StringUtils.FormatInvariant(
                              Errors._SqlShardMapManagerCredentials_ConnectionStringPropertyRequired,
                              "DataSource"),
                          "connectionString");
            }

            // InitialCatalog must be set.
            if (string.IsNullOrEmpty(connectionStringBuilder.InitialCatalog))
            {
                throw new ArgumentException(
                          StringUtils.FormatInvariant(
                              Errors._SqlShardMapManagerCredentials_ConnectionStringPropertyRequired,
                              "Initial Catalog"),
                          "connectionString");
            }

            // Ensure credentials are specified for GSM connectivity.
            SqlShardMapManagerCredentials.EnsureCredentials(
                connectionStringBuilder,
                "connectionString",
                connectionInfo.Credential,
                connectionInfo.AccessTokenFactory);

            #endregion GSM Validation

            // Generate connectionInfoShardMapManager
            SqlConnectionStringBuilder connectionStringShardMapManager = new SqlConnectionStringBuilder(connectionStringBuilder.ConnectionString);

            connectionStringShardMapManager.ApplicationName = ApplicationNameHelper.AddApplicationNameSuffix(
                connectionStringShardMapManager.ApplicationName,
                GlobalConstants.ShardMapManagerInternalConnectionSuffixGlobal);

            _smmDataSource     = connectionStringShardMapManager.DataSource;
            _smmInitialCatalog = connectionStringShardMapManager.InitialCatalog;

            this.ConnectionInfoShardMapManager =
                connectionInfo.CloneWithUpdatedConnectionString(connectionStringShardMapManager.ConnectionString);

            // Generate connectionInfoShard
            SqlConnectionStringBuilder connectionStringShard = new SqlConnectionStringBuilder(connectionStringBuilder.ConnectionString);

            connectionStringShard.Remove("Data Source");
            connectionStringShard.Remove("Initial Catalog");

            connectionStringShard.ApplicationName = ApplicationNameHelper.AddApplicationNameSuffix(
                connectionStringShard.ApplicationName,
                GlobalConstants.ShardMapManagerInternalConnectionSuffixLocal);

            this.ConnectionInfoShard =
                connectionInfo.CloneWithUpdatedConnectionString(connectionStringShard.ConnectionString);
        }
コード例 #21
0
 /// <summary>
 /// Constructs request for obtaining shard map manager object if the GSM has the SMM objects in it.
 /// </summary>
 /// <param name="credentials">Credentials for connection.</param>
 /// <param name="retryPolicy">Retry policy.</param>
 /// <param name="operationName">Operation name, useful for diagnostics.</param>
 /// <param name="throwOnFailure">Whether to throw exception on failure or return error code.</param>
 internal GetShardMapManagerGlobalOperation(SqlShardMapManagerCredentials credentials, TransientFaultHandling.RetryPolicy retryPolicy, string operationName, bool throwOnFailure) :
     base(credentials, retryPolicy, operationName)
 {
     _throwOnFailure = throwOnFailure;
 }
コード例 #22
0
 /// <summary>
 /// Constructs an instance of SqlOperationGlobal.
 /// </summary>
 /// <param name="credentials">Credentials for connecting to SMM GSM database.</param>
 /// <param name="retryPolicy">Retry policy for requests.</param>
 /// <param name="operationName">Operation name, useful for diagnostics.</param>
 internal StoreOperationGlobal(SqlShardMapManagerCredentials credentials, TransientFaultHandling.RetryPolicy retryPolicy, string operationName)
 {
     this.OperationName = operationName;
     _credentials = credentials;
     _retryPolicy = retryPolicy;
 }