Beispiel #1
0
 private void SealIfNecessaryAfterUnbackedAddOrGet(
     Context context,
     StrongFingerprint strongFingerprint,
     ContentHashListWithDeterminism addedValue,
     ContentHashListWithCacheMetadata cacheMetadata)
 {
     if (cacheMetadata == null)
     {
         // Our unbacked Add won the race, so the value is implicitly unbacked in VSTS
         // Seal the added value
         SealInTheBackground(context, strongFingerprint, addedValue);
     }
     else if (cacheMetadata.GetEffectiveExpirationTimeUtc() == null)
     {
         // Value is explicitly unbacked in VSTS
         if (cacheMetadata.ContentHashListWithDeterminism.ContentHashList != null)
         {
             // Our Add lost the race, so seal the existing value
             SealInTheBackground(context, strongFingerprint, cacheMetadata.ContentHashListWithDeterminism);
         }
         else
         {
             // Our Add won the race, so seal the added value
             var valueToSeal = new ContentHashListWithDeterminism(
                 addedValue.ContentHashList, cacheMetadata.ContentHashListWithDeterminism.Determinism);
             SealInTheBackground(
                 context,
                 strongFingerprint,
                 valueToSeal);
         }
     }
 }
Beispiel #2
0
 private async Task <bool> CheckNeedToUpdateExistingValueAsync(
     Context context,
     ContentHashListWithCacheMetadata cacheMetadata,
     ContentHashList contentHashListToReturn,
     CancellationToken cts,
     UrgencyHint urgencyHint)
 {
     return(cacheMetadata != null &&
            cacheMetadata.GetEffectiveExpirationTimeUtc() == null &&
            contentHashListToReturn != null &&
            (!await EnsureContentIsAvailableAsync(context, contentHashListToReturn.Hashes, cts, urgencyHint).ConfigureAwait(false)));
 }
        private void SealIfNecessaryAfterGet(Context context, StrongFingerprint strongFingerprint, ContentHashListWithCacheMetadata cacheMetadata)
        {
            if (WriteThroughContentSession == null)
            {
                return;
            }

            if (cacheMetadata != null && cacheMetadata.GetEffectiveExpirationTimeUtc() == null)
            {
                // Value is unbacked in VSTS
                SealInTheBackground(context, strongFingerprint, cacheMetadata.ContentHashListWithDeterminism);
            }
        }
        /// <summary>
        ///     Checks for inconsistencies in the metadata returned by the service, returning an appropriate error message (null if none).
        /// </summary>
        protected static string CheckForResponseInconsistency(ContentHashListWithCacheMetadata cacheMetadata)
        {
            if (cacheMetadata != null)
            {
                if (cacheMetadata.GetEffectiveExpirationTimeUtc() == null &&
                    cacheMetadata.ContentGuarantee != ContentAvailabilityGuarantee.NoContentBackedByCache)
                {
                    return
                        ("Inconsistent BuildCache service response. Null ContentHashListExpirationUtc should be iff ContentAvailabilityGuarantee.NoContentBackedByCache.");
                }
            }

            return(null);
        }
        /// <inheritdoc />
        public async Task <ObjectResult <ContentHashListWithCacheMetadata> > AddContentHashListAsync(
            Context context,
            string cacheNamespace,
            StrongFingerprint strongFingerprint,
            ContentHashListWithCacheMetadata valueToAdd)
        {
            try
            {
                ContentHashListResponse addResult = await ArtifactHttpClientErrorDetectionStrategy.ExecuteWithTimeoutAsync(
                    context,
                    "AddContentHashList",
                    innerCts => _buildCacheHttpClient.AddContentHashListAsync(
                        cacheNamespace,
                        strongFingerprint,
                        valueToAdd), CancellationToken.None).ConfigureAwait(false);

                DownloadUriCache.Instance.BulkAddDownloadUris(addResult.BlobDownloadUris);

                // add succeeded but returned an empty contenthashlistwith cache metadata. correct this.
                if (addResult.ContentHashListWithCacheMetadata == null)
                {
                    return
                        (new ObjectResult <ContentHashListWithCacheMetadata>(
                             new ContentHashListWithCacheMetadata(
                                 new ContentHashListWithDeterminism(null, valueToAdd.ContentHashListWithDeterminism.Determinism),
                                 valueToAdd.GetEffectiveExpirationTimeUtc(),
                                 valueToAdd.ContentGuarantee,
                                 valueToAdd.HashOfExistingContentHashList)));
                }
                else if (addResult.ContentHashListWithCacheMetadata.ContentHashListWithDeterminism.ContentHashList != null &&
                         addResult.ContentHashListWithCacheMetadata.HashOfExistingContentHashList == null)
                {
                    return(new ObjectResult <ContentHashListWithCacheMetadata>(
                               new ContentHashListWithCacheMetadata(
                                   addResult.ContentHashListWithCacheMetadata.ContentHashListWithDeterminism,
                                   addResult.ContentHashListWithCacheMetadata.GetEffectiveExpirationTimeUtc(),
                                   addResult.ContentHashListWithCacheMetadata.ContentGuarantee,
                                   addResult.ContentHashListWithCacheMetadata.ContentHashListWithDeterminism.ContentHashList.GetHashOfHashes())));
                }
                else
                {
                    return(new ObjectResult <ContentHashListWithCacheMetadata>(addResult.ContentHashListWithCacheMetadata));
                }
            }
            catch (Exception ex)
            {
                return(new ObjectResult <ContentHashListWithCacheMetadata>(ex));
            }
        }
        /// <summary>
        ///     Determine the Determinism to return.
        /// </summary>
        protected static CacheDeterminism UnpackDeterminism(ContentHashListWithCacheMetadata cacheMetadata, Guid cacheId)
        {
            Contract.Assert(cacheMetadata != null);

            if (cacheMetadata.ContentHashListWithDeterminism.Determinism.Guid == CacheDeterminism.Tool.Guid)
            {
                // Value is Tool-deterministic
                return(CacheDeterminism.Tool);
            }

            var expirationUtc = cacheMetadata.GetEffectiveExpirationTimeUtc();

            return(expirationUtc == null
                ? CacheDeterminism.None                                     // Value is unbacked in VSTS
                : CacheDeterminism.ViaCache(cacheId, expirationUtc.Value)); // Value is backed in VSTS
        }