Example #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;
        }
Example #2
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);
        }
Example #3
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;
 }
 /// <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 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));
 }
 /// <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));
 }
Example #8
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()))
            {
                Tracer.TraceInfo(
                    TraceSourceConstants.ComponentNames.ShardMapManagerFactory,
                    "CreateSqlShardMapManager",
                    "Start; ");

                Stopwatch stopwatch = Stopwatch.StartNew();

                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();
                    }

                    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));
            }
        }
        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;
        }
        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);
            }
        }
Example #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>
 internal GetShardMapManagerGlobalOperation(SqlShardMapManagerCredentials credentials, TransientFaultHandling.RetryPolicy retryPolicy, string operationName, bool throwOnFailure) :
     base(credentials, retryPolicy, operationName)
 {
     _throwOnFailure = throwOnFailure;
 }
 /// <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;
 }
        public static void ShardMapManagerLoadTestsInitialize(TestContext testContext)
        {
            // Clear all connection pools.
            SqlConnection.ClearAllPools();

            using (SqlConnection conn = new SqlConnection(Globals.ShardMapManagerTestConnectionString))
            {
                conn.Open();

                // Create ShardMapManager database
                using (SqlCommand cmd = new SqlCommand(
                           string.Format(Globals.CreateDatabaseQuery, Globals.ShardMapManagerDatabaseName),
                           conn))
                {
                    cmd.ExecuteNonQuery();
                }

                // Create shard databases
                for (int i = 0; i < ShardMapManagerLoadTests.s_shardedDBs.Length; i++)
                {
                    using (SqlCommand cmd = new SqlCommand(
                               string.Format(Globals.CreateDatabaseQuery, ShardMapManagerLoadTests.s_shardedDBs[i]),
                               conn))
                    {
                        cmd.ExecuteNonQuery();
                    }
                }

                // cleanup for deadlock monitoring
                foreach (string q in s_deadlockDetectionCleanupQueries)
                {
                    using (SqlCommand cmd = new SqlCommand(q, conn))
                    {
                        try
                        {
                            cmd.ExecuteNonQuery();
                        }
                        catch (SqlException)
                        {
                        }
                    }
                }

                // setup for deadlock monitoring
                foreach (string q in s_deadlockDetectionSetupQueries)
                {
                    using (SqlCommand cmd = new SqlCommand(q, conn))
                    {
                        try
                        {
                            cmd.ExecuteNonQuery();
                        }
                        catch (SqlException)
                        {
                        }
                    }
                }
            }

            // Create shard map manager.
            ShardMapManagerFactory.CreateSqlShardMapManager(
                Globals.ShardMapManagerConnectionString,
                ShardMapManagerCreateMode.ReplaceExisting);

            // Create list shard map.
            ShardMapManager smm = ShardMapManagerFactory.GetSqlShardMapManager(
                Globals.ShardMapManagerConnectionString,
                ShardMapManagerLoadPolicy.Lazy);

            ListShardMap <int> lsm = smm.CreateListShardMap <int>(ShardMapManagerLoadTests.s_listShardMapName);

            Assert.IsNotNull(lsm);

            // Create range shard map.
            RangeShardMap <int> rsm = smm.CreateRangeShardMap <int>(ShardMapManagerLoadTests.s_rangeShardMapName);

            Assert.IsNotNull(rsm);

            // Add 'InitialShardCount' shards to list and range shard map.

            for (int i = 0; i < ShardMapManagerLoadTests.InitialShardCount; i++)
            {
                ShardCreationInfo si = new ShardCreationInfo(
                    new ShardLocation(Globals.ShardMapManagerTestsDatasourceName, ShardMapManagerLoadTests.s_shardedDBs[i]),
                    ShardStatus.Online);

                Shard sList = lsm.CreateShard(si);
                Assert.IsNotNull(sList);

                Shard sRange = rsm.CreateShard(si);
                Assert.IsNotNull(sRange);
            }

            // Initialize retry policy
            s_retryPolicy = new TransientFaultHandling.RetryPolicy <TransientFaultHandling.SqlDatabaseTransientErrorDetectionStrategy>(
                new TransientFaultHandling.ExponentialBackoff(5, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(5), TimeSpan.FromMilliseconds(100)));
        }