示例#1
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);
        }
        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);
            }
        }
示例#4
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));
            }
        }