コード例 #1
0
        /// <summary>
        /// Retrieves the content locations for a given set of content hashes from local and global stores.
        /// </summary>
        public static IEnumerable <Task <GetBulkLocationsResult> > MultiLevelGetLocations(
            this IContentLocationStore store,
            Context context,
            IReadOnlyList <ContentHash> contentHashes,
            CancellationToken cts,
            UrgencyHint urgencyHint,
            bool subtractLocalResults)
        {
            var localResultsTask = store.GetBulkAsync(context, contentHashes, cts, urgencyHint, GetBulkOrigin.Local);

            yield return(localResultsTask);

            yield return(getBulkGlobal());

            // Local function: Get global results optionally subtracting local results
            async Task <GetBulkLocationsResult> getBulkGlobal()
            {
                var globalResults = await store.GetBulkAsync(context, contentHashes, cts, urgencyHint, GetBulkOrigin.Global);

                if (subtractLocalResults)
                {
                    globalResults = globalResults.Subtract(await localResultsTask);
                }

                return(globalResults);
            }
        }
コード例 #2
0
 public static Task <GetBulkLocationsResult> GetBulkAsync(
     this IContentLocationStore store,
     Context context,
     ContentHash contentHash,
     GetBulkOrigin origin)
 {
     return(store.GetBulkAsync(context, new ContentHash[] { contentHash }, CancellationToken.None, UrgencyHint.Nominal, origin));
 }
コード例 #3
0
 /// <summary>
 /// Retrieves the content locations for a given set of content hashes.
 /// </summary>
 public static Task <GetBulkLocationsResult> GetBulkAsync(
     this IContentLocationStore store,
     Context context,
     IReadOnlyList <ContentHash> contentHashes,
     CancellationToken cts,
     UrgencyHint urgencyHint)
 {
     return(store.GetBulkAsync(context, contentHashes, cts, urgencyHint, GetBulkOrigin.Global));
 }
コード例 #4
0
        /// <summary>
        /// Retrieves the content locations for a given set of content hashes where Global origin returns merged global and local content locations.
        /// </summary>
        public static async Task <GetBulkLocationsResult> GetBulkStackedAsync(
            this IContentLocationStore store,
            Context context,
            IReadOnlyList <ContentHash> contentHashes,
            CancellationToken cts,
            UrgencyHint urgencyHint,
            GetBulkOrigin origin)
        {
            var localResults = await store.GetBulkAsync(context, contentHashes, cts, urgencyHint, GetBulkOrigin.Local);

            if (origin == GetBulkOrigin.Local)
            {
                return(localResults);
            }

            var globalResults = await store.GetBulkAsync(context, contentHashes, cts, urgencyHint, GetBulkOrigin.Global);

            return(localResults.Merge(globalResults));
        }
コード例 #5
0
        /// <inheritdoc />
        public Task <DeleteResult> DeleteAsync(Context context, ContentHash contentHash, DeleteContentOptions deleteOptions)
        {
            var operationContext = OperationContext(context);

            deleteOptions ??= new DeleteContentOptions()
            {
                DeleteLocalOnly = true
            };

            return(operationContext.PerformOperationAsync(Tracer,
                                                          async() =>
            {
                var deleteResult = await InnerContentStore.DeleteAsync(context, contentHash, deleteOptions);
                var contentHashes = new ContentHash[] { contentHash };
                if (!deleteResult)
                {
                    return deleteResult;
                }

                // Tell the event hub that this machine has removed the content locally
                var unRegisterResult = await UnregisterAsync(context, contentHashes, operationContext.Token).ThrowIfFailure();
                if (!unRegisterResult)
                {
                    return new DeleteResult(unRegisterResult, unRegisterResult.ToString());
                }

                if (deleteOptions.DeleteLocalOnly)
                {
                    return deleteResult;
                }

                var result = await _contentLocationStore.GetBulkAsync(context, contentHashes, operationContext.Token, UrgencyHint.Nominal, GetBulkOrigin.Local);
                if (!result)
                {
                    return new DeleteResult(result, result.ToString());
                }

                // Go through each machine that has this content, and delete async locally on each machine.
                if (result.ContentHashesInfo.Count == 1 && result.ContentHashesInfo.ElementAt(0).Locations != null)
                {
                    var machineLocations = result.ContentHashesInfo[0].Locations;
                    return await _distributedCopier.DeleteAsync(operationContext, contentHash, machineLocations);
                }

                return deleteResult;
            }));
        }