Esempio n. 1
0
        /// <inheritdoc />
        public async Task <Possible <CasEntries, Failure> > GetCacheEntryAsync(StrongFingerprint strong, UrgencyHint urgencyHint, Guid activityId)
        {
            var hashListResult = await ReadOnlyCacheSession.GetContentHashListAsync(
                new Context(Logger),
                new BuildXL.Cache.MemoizationStore.Interfaces.Sessions.StrongFingerprint(
                    strong.WeakFingerprint.ToMemoization(),
                    new Selector(strong.CasElement.ToMemoization(), strong.HashElement.RawHash.ToByteArray())),
                CancellationToken.None);

            if (hashListResult.Succeeded)
            {
                if (hashListResult.ContentHashListWithDeterminism.ContentHashList == null)
                {
                    return(new NoMatchingFingerprintFailure(strong));
                }

                SessionEntries?.TryAdd(strong, 1);

                return(hashListResult.ContentHashListWithDeterminism.FromMemoization());
            }
            else
            {
                return(new CacheFailure(hashListResult.ErrorMessage));
            }
        }
Esempio n. 2
0
        public void StrongFingerprintFromMemoization()
        {
            MemoizationStrongFingerprint memoizationStrongFingerprint = new MemoizationStrongFingerprint(
                Fingerprint.Random(WeakFingerprintHash.Length),
                Selector.Random(HashingType, WeakFingerprintHash.Length));
            BuildXLStrongFingerprint buildXLStrongFingerprint = memoizationStrongFingerprint.FromMemoization(CacheId);

            Assert.Equal(memoizationStrongFingerprint.WeakFingerprint.ToByteArray(), buildXLStrongFingerprint.WeakFingerprint.ToArray());
            Assert.Equal(memoizationStrongFingerprint.Selector.ContentHash.FromMemoization(), buildXLStrongFingerprint.CasElement);
            Assert.Equal(memoizationStrongFingerprint.Selector.Output, buildXLStrongFingerprint.HashElement.ToArray());
            Assert.Equal(CacheId, buildXLStrongFingerprint.CacheId);
        }
        public async Task <Possible <FullCacheRecordWithDeterminism, Failure> > AddOrGetAsync(WeakFingerprintHash weak, CasHash casElement, Hash hashElement, CasEntries hashes, UrgencyHint urgencyHint, Guid activityId)
        {
            var addResult = await CacheSession.AddOrGetContentHashListAsync(
                new Context(Logger),
                new BuildXL.Cache.MemoizationStore.Interfaces.Sessions.StrongFingerprint(
                    weak.ToMemoization(),
                    new Selector(casElement.ToMemoization(), hashElement.RawHash.ToByteArray())),
                hashes.ToMemoization(),
                CancellationToken.None,
                urgencyHint.ToMemoization());

            var strong = new StrongFingerprint(weak, casElement, hashElement, CacheId);

            switch (addResult.Code)
            {
            case AddOrGetContentHashListResult.ResultCode.Success:
                SessionEntries?.TryAdd(strong, 1);

                return(addResult.ContentHashListWithDeterminism.ContentHashList == null
                        ? new FullCacheRecordWithDeterminism(addResult.ContentHashListWithDeterminism.Determinism.FromMemoization())
                        : new FullCacheRecordWithDeterminism(new FullCacheRecord(strong, addResult.ContentHashListWithDeterminism.FromMemoization())));

            case AddOrGetContentHashListResult.ResultCode.SinglePhaseMixingError:
                return(new SinglePhaseMixingFailure(CacheId));

            case AddOrGetContentHashListResult.ResultCode.InvalidToolDeterminismError:
                return(new NotDeterministicFailure(
                           CacheId,
                           new FullCacheRecord(strong, addResult.ContentHashListWithDeterminism.FromMemoization()),
                           new FullCacheRecord(strong, hashes)));

            case AddOrGetContentHashListResult.ResultCode.Error:
                return(new CacheFailure(addResult.ErrorMessage));

            default:
                return(new CacheFailure("Unrecognized AddOrGetContentHashListAsync result code: " + addResult.Code + ", error message: " + (addResult.ErrorMessage ?? string.Empty)));
            }
        }