Exemplo n.º 1
0
 /// <inheritdoc />
 public Task <BoolResult> ShutdownAsync(Context context)
 {
     ShutdownStarted = true;
     return(ShutdownCall <ContentSessionTracer> .RunAsync(_tracer, context, () =>
     {
         ShutdownCompleted = true;
         return Task.FromResult(BoolResult.Success);
     }));
 }
Exemplo n.º 2
0
        /// <inheritdoc />
        public Task <BoolResult> ShutdownAsync(Context context)
        {
            ShutdownStarted = true;
            return(ShutdownCall <BuildCacheCacheTracer> .RunAsync(_tracer, context, async() =>
            {
                var statsResult = await GetStatsInternalAsync(context).ConfigureAwait(false);
                if (statsResult.Succeeded)
                {
                    context.Debug("BuildCacheCache Stats:");
                    statsResult.CounterSet.LogOrderedNameValuePairs(s => _tracer.Debug(context, s));
                }
                else
                {
                    context.Debug($"Getting stats failed: [{statsResult}]");
                }

                var backingContentStoreTask = Task.Run(async() => await _backingContentStore.ShutdownAsync(context).ConfigureAwait(false));
                var writeThroughContentStoreResult = _writeThroughContentStore != null
                    ? await _writeThroughContentStore.ShutdownAsync(context)
                    : BoolResult.Success;
                var backingContentStoreResult = await backingContentStoreTask.ConfigureAwait(false);

                BoolResult result;
                if (backingContentStoreResult.Succeeded && writeThroughContentStoreResult.Succeeded)
                {
                    result = BoolResult.Success;
                }
                else
                {
                    var sb = new StringBuilder();
                    if (!backingContentStoreResult.Succeeded)
                    {
                        sb.Append($"Backing content store shutdown failed, error=[{backingContentStoreResult}]");
                    }

                    if (!writeThroughContentStoreResult.Succeeded)
                    {
                        sb.Append($"Write-through content store shutdown failed, error=[{writeThroughContentStoreResult}]");
                    }

                    result = new BoolResult(sb.ToString());
                }

                ShutdownCompleted = true;
                return result;
            }));
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public Task <BoolResult> ShutdownAsync(Context context)
        {
            ShutdownStarted = true;

            return(ShutdownCall <CacheTracer> .RunAsync(_tracer, context, async() =>
            {
                var statsResult = await StatsAsync(context).ConfigureAwait(false);

                var contentStoreTask = Task.Run(() => ContentStore.ShutdownAsync(context));
                var memoizationStoreResult = await MemoizationStore.ShutdownAsync(context).ConfigureAwait(false);
                var contentStoreResult = await contentStoreTask.ConfigureAwait(false);

                BoolResult result;
                if (contentStoreResult.Succeeded && memoizationStoreResult.Succeeded)
                {
                    result = BoolResult.Success;
                }
                else
                {
                    var sb = new StringBuilder();
                    if (!contentStoreResult.Succeeded)
                    {
                        sb.AppendFormat($"Content store shutdown failed, error=[{contentStoreResult}]");
                    }

                    if (!memoizationStoreResult.Succeeded)
                    {
                        sb.Append(sb.Length > 0 ? ", " : string.Empty);
                        sb.AppendFormat($"Memoization store shutdown failed, error=[{memoizationStoreResult}]");
                    }

                    result = new BoolResult(sb.ToString());
                }

                if (statsResult.Succeeded)
                {
#if !FEATURE_CORECLR
                    LocalCacheStatsEventSource.Instance.Stats(statsResult.CounterSet);
#endif
                    statsResult.CounterSet.LogOrderedNameValuePairs(s => _tracer.Debug(context, s));
                }

                ShutdownCompleted = true;
                return result;
            }));
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public virtual Task <BoolResult> ShutdownAsync(Context context)
        {
            ShutdownStarted = true;

            return(ShutdownCall <TTracer> .RunAsync(Tracer, context, async() =>
            {
                await PreShutdownAsync(context);

                Messages.Add(ShutdownMessage.Instance);
                _backgroundThread?.Join();

                DeleteMarkerFile(context);

                await PostShutdownAsync(context).ThrowIfFailure();
                ShutdownCompleted = true;
                return BoolResult.Success;
            }));
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public Task <BoolResult> ShutdownAsync(Context context)
        {
            return(ShutdownCall <ContentSessionTracer> .RunAsync(
                       Tracer,
                       context,
                       async() =>
            {
                ShutdownStarted = true;
                var finalResult = BoolResult.Success;

                foreach (var session in SessionsByCacheRoot.Values)
                {
                    var result = await session.ShutdownAsync(context).ConfigureAwait(false);
                    if (!result.Succeeded)
                    {
                        finalResult = new BoolResult(finalResult, result.ErrorMessage);
                    }
                }

                ShutdownCompleted = true;
                return finalResult;
            }));
        }
Exemplo n.º 6
0
        /// <inheritdoc />
        public Task <BoolResult> ShutdownAsync(Context context)
        {
            ShutdownStarted = true;

            return(ShutdownCall <ContentSessionTracer> .RunAsync(_tracer, context, async() =>
            {
                var shutdownResults =
                    await
                    Task.WhenAll(_sessionForStream.ShutdownAsync(context), _sessionForPath.ShutdownAsync(context));
                Contract.Assert(shutdownResults.Length == 2);

                var shutdownResultForStream = shutdownResults[0];
                var shutdownResultForPath = shutdownResults[1];

                var result = shutdownResultForStream & shutdownResultForPath;

                if (!result.Succeeded)
                {
                    var sb = new StringBuilder();
                    if (!shutdownResultForStream.Succeeded)
                    {
                        sb.Concat($"{SessionForStreamText} shutdown failed, error=[{shutdownResultForStream}]", "; ");
                    }

                    if (!shutdownResultForPath.Succeeded)
                    {
                        sb.Concat($"{SessionForPathText} shutdown failed, error=[{shutdownResultForPath}]", "; ");
                    }

                    result = new BoolResult(sb.ToString());
                }

                ShutdownCompleted = true;

                return result;
            }));
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        public Task <BoolResult> ShutdownAsync(Context context)
        {
            ShutdownStarted = true;
            return(ShutdownCall <MemoizationStoreTracer> .RunAsync(_tracer, context, async() =>
            {
                GetStatsResult stats = GetStatsInternal();
                if (!stats)
                {
                    context.Debug($"Get stats failed with error {stats.ErrorMessage}; Diagnostics {stats.Diagnostics}");
                }
                else
                {
                    context.Debug("DistributedCache Stats:");
                    stats.CounterSet.LogOrderedNameValuePairs(s => _tracer.Debug(context, s));
                }

                var innerCacheShutdown = await _innerICache.ShutdownAsync(context);
                var metadataCacheShutdown = await _metadataCache.ShutdownAsync(context);

                if (!innerCacheShutdown)
                {
                    // TODO: should print errors as well.
                    context.Error("Shutdown call on inner cache failed.");
                    return new BoolResult(innerCacheShutdown);
                }

                if (!metadataCacheShutdown)
                {
                    context.Error("Shutdown call on metadata cache failed.");
                    return new BoolResult(metadataCacheShutdown);
                }

                ShutdownCompleted = true;

                return BoolResult.Success;
            }));
        }
Exemplo n.º 8
0
        /// <inheritdoc />
        public Task <BoolResult> ShutdownAsync(Context context)
        {
            return(ShutdownCall <ContentStoreTracer> .RunAsync(Tracer, context, async() =>
            {
                ShutdownStarted = true;
                var finalResult = BoolResult.Success;

                foreach (var store in _drivesWithContentStore.Values)
                {
                    if (store.StartupCompleted && !store.ShutdownCompleted)
                    {
                        // Shutdown is available only when the store started up successfully and wasn't shut down yet.
                        var result = await store.ShutdownAsync(context).ConfigureAwait(false);
                        if (!result)
                        {
                            finalResult = new BoolResult(finalResult, result.ErrorMessage);
                        }
                    }
                }

                ShutdownCompleted = true;
                return finalResult;
            }));
        }
        /// <inheritdoc />
        public Task <BoolResult> ShutdownAsync(Context context)
        {
            ShutdownStarted = true;
            return(ShutdownCall <MemoizationStoreTracer> .RunAsync(Tracer.MemoizationStoreTracer, context, async() =>
            {
                Tracer.Debug(context, "IncorporateOnShutdown start");
                Tracer.Debug(context, $"Incorporate fingerprints feature enabled:[{_fingerprintIncorporationEnabled}]");
                Tracer.Debug(context, $"Total fingerprints to be incorporated:[{FingerprintTracker.Count}]");
                Tracer.Debug(context, $"Max fingerprints per incorporate request(=chunk size):[{_maxFingerprintsPerIncorporateRequest}]");
                Tracer.Debug(context, $"Max incorporate requests allowed in parallel:[{_maxDegreeOfParallelismForIncorporateRequests}]");
                if (_fingerprintIncorporationEnabled)
                {
                    // Incorporating all of the fingerprints for a build, in one request, to a single endpoint causes pain. Incorporation involves
                    // extending the lifetime of all fingerprints *and* content/s mapped to each fingerprint. Processing a large request payload
                    // results in, potentially, fanning out a massive number of "lifetime extend" requests to itemstore and blobstore, which can
                    // bring down the endpoint. Break this down into chunks so that multiple, load-balanced endpoints can share the burden.
                    List <StrongFingerprint> fingerprintsToBump = FingerprintTracker.StaleFingerprints.ToList();
                    Tracer.Debug(context, $"Total fingerprints to be sent in incorporation requeststo the service: {fingerprintsToBump.Count}");

                    List <List <StrongFingerprintAndExpiration> > chunks = fingerprintsToBump.Select(
                        strongFingerprint => new StrongFingerprintAndExpiration(strongFingerprint, FingerprintTracker.GenerateNewExpiration())
                        ).GetPages(_maxFingerprintsPerIncorporateRequest).ToList();
                    Tracer.Debug(context, $"Total fingerprint incorporation requests to be issued(=number of fingerprint chunks):[{chunks.Count}]");

                    var incorporateBlock = new ActionBlock <IEnumerable <StrongFingerprintAndExpiration> >(
                        async chunk =>
                    {
                        await ContentHashListAdapter.IncorporateStrongFingerprints(
                            context,
                            CacheNamespace,
                            new IncorporateStrongFingerprintsRequest(chunk.ToList().AsReadOnly())
                            ).ConfigureAwait(false);
                    },
                        new ExecutionDataflowBlockOptions {
                        MaxDegreeOfParallelism = _maxDegreeOfParallelismForIncorporateRequests
                    });

                    foreach (var chunk in chunks)
                    {
                        await incorporateBlock.SendAsync(chunk);
                    }

                    incorporateBlock.Complete();
                    await incorporateBlock.Completion.ConfigureAwait(false); // TODO: Gracefully handle exceptions so that the rest of shutdown can happen (bug 1365340)
                    Tracer.Debug(context, "IncorporateOnShutdown stop");
                }

                if (_taskTracker != null)
                {
                    await _taskTracker.Synchronize().ConfigureAwait(false);
                    await _taskTracker.ShutdownAsync(context).ConfigureAwait(false);
                }

                var backingContentSessionTask = Task.Run(async() => await BackingContentSession.ShutdownAsync(context).ConfigureAwait(false));
                var writeThroughContentSessionResult = WriteThroughContentSession != null
                    ? await WriteThroughContentSession.ShutdownAsync(context).ConfigureAwait(false)
                    : BoolResult.Success;
                var backingContentSessionResult = await backingContentSessionTask.ConfigureAwait(false);

                BoolResult result;
                if (backingContentSessionResult.Succeeded && writeThroughContentSessionResult.Succeeded)
                {
                    if (_sealingErrorsToPrintOnShutdown.Any())
                    {
                        var sb = new StringBuilder();
                        sb.AppendLine("Error(s) during background sealing:");
                        foreach (var sealingError in _sealingErrorsToPrintOnShutdown)
                        {
                            sb.AppendLine($"[{sealingError}]");
                        }

                        if (_sealingErrorCount > MaxSealingErrorsToPrintOnShutdown)
                        {
                            sb.AppendLine($"See log for the other {MaxSealingErrorsToPrintOnShutdown - _sealingErrorCount} error(s).");
                        }

                        result = new BoolResult(sb.ToString());
                    }
                    else
                    {
                        result = BoolResult.Success;
                    }
                }
                else
                {
                    var sb = new StringBuilder();
                    if (!backingContentSessionResult.Succeeded)
                    {
                        sb.Append($"Backing content session shutdown failed, error=[{backingContentSessionResult}]");
                    }

                    if (!writeThroughContentSessionResult.Succeeded)
                    {
                        sb.Append(sb.Length > 0 ? ", " : string.Empty);
                        sb.Append($"Write-through content session shutdown failed, error=[{writeThroughContentSessionResult}]");
                    }

                    result = new BoolResult(sb.ToString());
                }

                ShutdownCompleted = true;
                return result;
            }));
        }