Пример #1
0
        internal static async Task <T> WithErrorTranslationAndProfiling <T>(Func <Task <T> > t, string name, Logger logger)
        {
            SpannerException translatedException;

            try
            {
                Stopwatch sw = null;
                if (logger.LogPerformanceTraces)
                {
                    sw = Stopwatch.StartNew();
                }

                var result = await t().ConfigureAwait(false);

                if (sw != null)
                {
                    logger.LogPerformanceCounterFn($"{name}.Duration", x => sw.ElapsedMilliseconds);
                }

                return(result);
            }
            catch (Exception e) when((translatedException = SpannerException.TryTranslateRpcException(e)) != null)
            {
                throw translatedException;
            }
        }
Пример #2
0
        /// <summary>
        /// Returns true if the exception represents a transient error in Spanner.
        /// This indicates that the operation may succeed if it is attempted again.
        /// Common errors that can cause this include temporary network interruption
        /// or the service being temporarily unavailable.
        /// </summary>
        /// <returns>True if the exception represents an error that may succeed on a retry.</returns>
        public static bool IsTransientSpannerFault(this Exception exception)
        {
            var spannerException = exception as SpannerException
                                   ?? SpannerException.TryTranslateRpcException(exception);

            return(spannerException != null && spannerException.IsRetryable);
        }
Пример #3
0
        internal static void WithErrorTranslationAndProfiling(Action t, string name, Logger logger)
        {
            SpannerException translatedException;

            try
            {
                Stopwatch sw = null;
                if (logger.LogPerformanceTraces)
                {
                    sw = Stopwatch.StartNew();
                }

                t();
                if (sw != null)
                {
                    logger.LogPerformanceCounterFn($"{name}.Duration", x => sw.ElapsedMilliseconds);
                }
            }
            catch (Exception e) when((translatedException = SpannerException.TryTranslateRpcException(e)) != null)
            {
                throw translatedException;
            }
        }