public async Task <IEnumerable <Task <Indexed <PinResult> > > > PinAsync(Context context, IReadOnlyList <ContentHash> contentHashes, CancellationToken cts, UrgencyHint urgencyHint = UrgencyHint.Nominal) { Stopwatch sw = Stopwatch.StartNew(); try { Tracer.PinBulkStart(context, contentHashes); DateTime endDateTime = DateTime.UtcNow + TimeToKeepContent; return(await Workflows.RunWithFallback( contentHashes, hashes => CheckInMemoryCaches(hashes, endDateTime), hashes => UpdateBlobStoreAsync(context, hashes, endDateTime, cts), result => result.Succeeded)); } catch (Exception ex) { context.Warning($"Exception when querying pins against the VSTS services {ex}"); return(contentHashes.Select((_, index) => Task.FromResult(new PinResult(ex).WithIndex(index)))); } finally { Tracer.PinBulkStop(context, sw.Elapsed); } }
/// <inheritdoc /> public async Task <PinResult> PinAsync( Context context, ContentHash contentHash, CancellationToken cts, UrgencyHint urgencyHint = UrgencyHint.Nominal) { if (contentHash.HashType != RequiredHashType) { return(new PinResult($"DedupStore client requires {RequiredHashType}. Cannot take HashType '{contentHash.HashType}'.")); } Stopwatch sw = Stopwatch.StartNew(); try { Tracer.PinBulkStart(context, new[] { contentHash }); var pinResult = CheckPinInMemory(contentHash); if (pinResult.Succeeded) { return(pinResult); } var dedupId = ToVstsBlobIdentifier(contentHash.ToBlobIdentifier()).ToDedupIdentifier(); if (dedupId.AlgorithmId == Hashing.ChunkDedupIdentifier.ChunkAlgorithmId) { pinResult = await TryPinChunkAsync(context, dedupId, cts); } else { pinResult = await TryPinNodeAsync(context, dedupId, cts); } if (pinResult.Succeeded) { BackingContentStoreExpiryCache.Instance.AddExpiry(contentHash, EndDateTime); } return(pinResult); } catch (Exception ex) { return(new PinResult(ex)); } finally { Tracer.PinBulkStop(context, sw.Elapsed); } }