Ejemplo n.º 1
0
        public async Task TranAsync(IsolationLevel?isolationLevel, DeadlockRetryConfig?retryConfig, TransactionalTaskAsync task)
        {
            await EnsureOpenAsync();

            if (retryConfig == null)
            {
                retryConfig = this.DeadlockRetryConfig;
            }

            int numRetry = 0;

LABEL_RETRY:
            try
            {
                using (UsingTran u = this.UsingTran(isolationLevel))
                {
                    if (await task())
                    {
                        u.Commit();
                    }
                }
            }
            catch (SqlException sqlex)
            {
                //sqlex._Debug();
                if (sqlex.Number == 1205)
                {
                    // デッドロック発生
                    numRetry++;
                    if (numRetry <= retryConfig.RetryCount)
                    {
                        await Task.Delay(Util.RandSInt31() % retryConfig.RetryAverageInterval);

                        goto LABEL_RETRY;
                    }

                    throw;
                }
                else
                {
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public void Tran(IsolationLevel?isolationLevel, DeadlockRetryConfig?retryConfig, TransactionalTask task)
        {
            EnsureOpen();
            if (retryConfig == null)
            {
                retryConfig = this.DeadlockRetryConfig;
            }

            int numRetry = 0;

LABEL_RETRY:
            try
            {
                using (UsingTran u = this.UsingTran(isolationLevel))
                {
                    if (task())
                    {
                        u.Commit();
                    }
                }
            }
            catch (SqlException sqlex)
            {
                if (sqlex.Number == 1205)
                {
                    // デッドロック発生
                    numRetry++;
                    if (numRetry <= retryConfig.RetryCount)
                    {
                        Kernel.SleepThread(Util.RandSInt31() % retryConfig.RetryAverageInterval);

                        goto LABEL_RETRY;
                    }

                    throw;
                }
                else
                {
                    throw;
                }
            }
        }