/// <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();
            }
        }
 /// <summary>
 /// The retry policy to use when executing commands against sql databases
 /// </summary>
 /// <param name="retryPolicyPerShard">An instance of the <see cref="RetryPolicy"/> class</param>
 /// <param name="retryBehavior">Behavior to use for detecting transient faults.</param>
 /// <returns>An instance of the <see cref="RetryPolicy"/> class</returns>
 internal static TransientFaultHandling.RetryPolicy GetSqlCommandRetryPolicy(RetryPolicy retryPolicyPerShard, RetryBehavior retryBehavior)
 {
     return new TransientFaultHandling.RetryPolicy(
         new MultiShardQueryTransientErrorDetectionStrategy(retryBehavior),
         retryPolicyPerShard.GetRetryStrategy());
 }
Esempio n. 3
0
 /// <summary>
 /// The retry policy to use when executing commands against sql databases
 /// </summary>
 /// <param name="retryPolicyPerShard">An instance of the <see cref="RetryPolicy"/> class</param>
 /// <param name="retryBehavior">Behavior to use for detecting transient faults.</param>
 /// <returns>An instance of the <see cref="RetryPolicy"/> class</returns>
 internal static TransientFaultHandling.RetryPolicy GetSqlCommandRetryPolicy(RetryPolicy retryPolicyPerShard, RetryBehavior retryBehavior)
 {
     return(new TransientFaultHandling.RetryPolicy(
                new MultiShardQueryTransientErrorDetectionStrategy(retryBehavior),
                retryPolicyPerShard.GetRetryStrategy()));
 }