コード例 #1
0
        /// <summary>
        ///     Put a randomly-sized content from a file into the store.
        /// </summary>
        public static Task <PutResult> PutRandomFileAsync(
            this IContentSession session,
            Context context,
            IAbsFileSystem fileSystem,
            AbsolutePath path,
            HashType hashType,
            bool provideHash,
            long size,
            CancellationToken ct)
        {
            Contract.RequiresNotNull(session);
            Contract.RequiresNotNull(context);
            Contract.RequiresNotNull(fileSystem);

            var c = context.CreateNested(nameof(ContentSessionExtensions));

            // TODO: Fix this to work with size > int.Max (bug 1365340)
            var data = ThreadSafeRandom.GetBytes((int)size);

            fileSystem.WriteAllBytes(path, data);

            if (!provideHash)
            {
                return(session.PutFileAsync(c, hashType, path, FileRealizationMode.Any, ct));
            }

            var hash = HashInfoLookup.Find(hashType).CreateContentHasher().GetContentHash(data);

            return(session.PutFileAsync(c, hash, path, FileRealizationMode.Any, ct));
        }
コード例 #2
0
        public static async Task <IReadOnlyList <ContentHash> > PutRandomAsync(
            this IContentSession session,
            Context context,
            HashType hashType,
            bool provideHash,
            int fileCount,
            long fileSize,
            bool useExactSize)
        {
            var contentHashes = new List <ContentHash>(fileCount);

            for (long i = 0; i < fileCount / MaxBulkPageSize; i++)
            {
                var hashes = await PutRandomBulkAsync(
                    session, context, hashType, provideHash, MaxBulkPageSize, fileSize, useExactSize).ConfigureAwait(false);

                contentHashes.AddRange(hashes);
            }

            var remainder = fileCount % MaxBulkPageSize;

            if (remainder > 0)
            {
                var hashes = await PutRandomBulkAsync(
                    session, context, hashType, provideHash, remainder, fileSize, useExactSize).ConfigureAwait(false);

                contentHashes.AddRange(hashes);
            }

            return(contentHashes);
        }
コード例 #3
0
        public static async Task <PutResult> PutRandomAsync(
            this IContentSession session,
            Context context,
            HashType hashType,
            bool provideHash,
            long size,
            CancellationToken ct)
        {
            Contract.RequiresNotNull(session);
            Contract.RequiresNotNull(context);

            var c = context.CreateNested();

            // TODO: Fix this to work with size > int.Max (bug 1365340)
            var data = ThreadSafeRandom.GetBytes((int)size);

            using (var stream = new MemoryStream(data))
            {
                if (!provideHash)
                {
                    return(await session.PutStreamAsync(c, hashType, stream, ct).ConfigureAwait(false));
                }

                var hash = HashInfoLookup.Find(hashType).CreateContentHasher().GetContentHash(data);
                return(await session.PutStreamAsync(c, hash, stream, ct).ConfigureAwait(false));
            }
        }
コード例 #4
0
        public static async Task <PutResult> PutRandomFileAsync(
            this IContentSession session,
            Context context,
            IAbsFileSystem fileSystem,
            HashType hashType,
            bool provideHash,
            long size,
            CancellationToken ct)
        {
            Contract.RequiresNotNull(session);
            Contract.RequiresNotNull(context);
            Contract.RequiresNotNull(fileSystem);

            using (var directory = new DisposableDirectory(fileSystem))
            {
                var c = context.CreateNested();

                // TODO: Fix this to work with size > int.Max (bug 1365340)
                var data = ThreadSafeRandom.GetBytes((int)size);
                var path = directory.CreateRandomFileName();
                fileSystem.WriteAllBytes(path, data);

                if (!provideHash)
                {
                    return(await session.PutFileAsync(c, hashType, path, FileRealizationMode.Any, ct).ConfigureAwait(false));
                }

                var hash = HashInfoLookup.Find(hashType).CreateContentHasher().GetContentHash(data);
                return(await session.PutFileAsync(c, hash, path, FileRealizationMode.Any, ct).ConfigureAwait(false));
            }
        }
コード例 #5
0
        /// <summary>
        ///     Ensure the existence of all related content by pinning it.
        /// </summary>
        public static async Task <bool> EnsureContentIsAvailableAsync(this IContentSession contentSession, Context context, string componentName, ContentHashList contentHashList, CancellationToken cts)
        {
            // If there is no contentSession in which to find content, then trivially no content is available.
            if (contentSession == null)
            {
                return(false);
            }

            // If the contentHashList does not exist, then trivially all content is pinned.
            if (contentHashList == null)
            {
                return(true);
            }

            IEnumerable <Task <Indexed <PinResult> > > pinResultEnumerable = await contentSession.PinAsync(context, contentHashList.Hashes, cts).ConfigureAwait(false);

            var pinSucceeded = true;

            foreach (var pinResultTask in pinResultEnumerable)
            {
                var pinResult = await pinResultTask.ConfigureAwait(false);

                if (!pinResult.Item.Succeeded)
                {
                    if (pinResult.Item.Code != PinResult.ResultCode.ContentNotFound)
                    {
                        context.Warning($"Pinning hash {contentHashList.Hashes[pinResult.Index]} failed with error {pinResult}", component: componentName);
                    }

                    pinSucceeded = false;
                }
            }

            return(pinSucceeded);
        }
コード例 #6
0
        public async Task <PlaceFileResult> CreateTempAndPutAsync(
            OperationContext context,
            ContentHash contentHash,
            IContentSession contentSession)
        {
            using (var disposableFile = new DisposableFile(context, _fileSystem, AbsolutePath.CreateRandomFileName(_rootPath / "temp")))
            {
                PlaceFileResult placeTempFileResult = await PlaceFileAsync(context, contentHash, disposableFile.Path, FileAccessMode.ReadOnly, FileReplacementMode.FailIfExists, FileRealizationMode.HardLink, context.Token);

                if (!placeTempFileResult.Succeeded)
                {
                    return(placeTempFileResult);
                }
                PutResult putFileResult = await contentSession.PutFileAsync(context, contentHash, disposableFile.Path, FileRealizationMode.Any, context.Token);

                if (!putFileResult)
                {
                    return(new PlaceFileResult(putFileResult));
                }
                else
                {
                    return(new PlaceFileResult(PlaceFileResult.ResultCode.PlacedWithCopy, putFileResult.ContentSize));
                }
            }
        }
コード例 #7
0
        private static async Task <IReadOnlyList <ContentHash> > PutRandomBulkAsync(
            this IContentSession session,
            Context context,
            HashType hashType,
            bool provideHash,
            int fileCount,
            long fileSize,
            bool useExactSize)
        {
            Contract.Requires(fileCount > 0);

            var c     = context.CreateNested();
            var tasks = Enumerable.Range(0, fileCount).Select(_ => Task.Run(async() => await session.PutRandomAsync(
                                                                                c,
                                                                                hashType,
                                                                                provideHash,
                                                                                useExactSize ? fileSize : ThreadSafeRandom.Generator.Next(1, (int)fileSize),
                                                                                CancellationToken.None)
                                                                            .ConfigureAwait(false))).ToList();

            var contentHashes = new List <ContentHash>(fileCount);

            foreach (var task in tasks.ToList())
            {
                var result = await task.ConfigureAwait(false);

                if (result.Succeeded)
                {
                    contentHashes.Add(result.ContentHash);
                }
            }

            return(contentHashes);
        }
コード例 #8
0
 public VirtualizedContentSession(VirtualizedContentStore store, IContentSession session, string name)
     : base(name)
 {
     // TODO: ImplicitPin?
     Store        = store;
     InnerSession = session;
 }
コード例 #9
0
 public VirtualizedContentSession(VirtualizedContentStore store, IContentSession session, VfsContentManager contentManager, string name)
     : base(name)
 {
     _store          = store;
     _innerSession   = session;
     _contentManager = contentManager;
     _fileSystem     = new PassThroughFileSystem();
 }
コード例 #10
0
        private static void DisableHeartbeat(IContentSession session)
        {
            var testSession = session as TestServiceClientContentSession;

            testSession.Should().NotBeNull();
            testSession?.StartupStarted.Should().BeFalse("Too late to disable heartbeat.");
            testSession?.DisableHeartbeat();
        }
コード例 #11
0
ファイル: VfsContentManager.cs プロジェクト: erikma/BuildXL
 public VfsContentManager(ILogger logger, VfsCasConfiguration configuration, VfsTree tree, IContentSession contentSession)
 {
     _logger         = logger;
     _configuration  = configuration;
     Tree            = tree;
     _contentSession = contentSession;
     _fileSystem     = new PassThroughFileSystem();
     _tempDirectory  = new DisposableDirectory(_fileSystem, configuration.DataRootPath / "temp");
 }
コード例 #12
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="StreamPathContentSession" /> class.
 /// </summary>
 public StreamPathContentSession(
     string name,
     IContentSession sessionForStream,
     IContentSession sessionForPath)
 {
     Name = name;
     _sessionForStream = sessionForStream;
     _sessionForPath   = sessionForPath;
 }
コード例 #13
0
 public BuildCachePublishingSession(BuildCacheServiceConfiguration config, string name, string pat, IContentSession sourceContentSession, IAbsFileSystem fileSystem, SemaphoreSlim publishGate)
 {
     _name                 = name;
     _config               = config;
     _publishingGate       = publishGate;
     _pat                  = pat;
     _fileSystem           = fileSystem;
     _sourceContentSession = sourceContentSession;
 }
コード例 #14
0
        public async Task PutStreamSucceedsWithNonSeekableStream()
        {
            using (var testDirectory = new DisposableDirectory(FileSystem))
            {
                var rootPath = testDirectory.Path;
                var config   = CreateStoreConfiguration();
                config.Write(FileSystem, rootPath);

                using (var store = CreateStore(testDirectory, config))
                {
                    try
                    {
                        var r = await store.StartupAsync(_context);

                        r.ShouldBeSuccess();

                        IContentSession session1 = null;

                        try
                        {
                            var createSessionResult1 = store.CreateSession(_context, "session1", ImplicitPin.None);
                            createSessionResult1.ShouldBeSuccess();

                            using (createSessionResult1.Session)
                            {
                                var r1 = await createSessionResult1.Session.StartupAsync(_context);

                                r1.ShouldBeSuccess();
                                session1 = createSessionResult1.Session;

                                using (var memoryStream = new RestrictedMemoryStream(ThreadSafeRandom.GetBytes(RandomContentByteCount)))
                                {
                                    var result = await session1.PutStreamAsync(_context, ContentHashType, memoryStream, Token);

                                    result.ShouldBeSuccess();
                                    result.ContentSize.Should().Be(RandomContentByteCount);
                                }
                            }
                        }
                        finally
                        {
                            if (session1 != null)
                            {
                                await session1.ShutdownAsync(_context).ShouldBeSuccess();
                            }
                        }
                    }
                    finally
                    {
                        var r = await store.ShutdownAsync(_context);

                        r.ShouldBeSuccess();
                    }
                }
            }
        }
コード例 #15
0
 public BuildCacheTestPublishingSession(
     BuildCacheServiceConfiguration config,
     string name,
     string pat,
     IContentSession contentSource,
     IAbsFileSystem fileSystem,
     SemaphoreSlim publishingGate)
     : base(config, name, pat, contentSource, fileSystem, publishingGate)
 {
 }
コード例 #16
0
        private async Task UploadContent(
            Context context, ContentHash contentHash, IContentSession fromSession, IContentSession toSession)
        {
            var openStreamResult = await fromSession.OpenStreamAsync(context, contentHash, Token).ConfigureAwait(false);

            openStreamResult.Succeeded.Should().BeTrue();
            var putResult = await toSession.PutStreamAsync(context, contentHash, openStreamResult.Stream, Token).ConfigureAwait(false);

            putResult.Succeeded.Should().BeTrue();
        }
コード例 #17
0
        /// <summary>
        /// Creates a contenthashlistadapter for a particular session.
        /// </summary>
        public IContentHashListAdapter Create(IContentSession contentSession)
        {
            ItemBuildCacheHttpClient itemBasedClient = BuildCacheHttpClient as ItemBuildCacheHttpClient;

            if (itemBasedClient != null)
            {
                return(new ItemBuildCacheContentHashListAdapter(itemBasedClient));
            }

            return(new BlobBuildCacheContentHashListAdapter((IBlobBuildCacheHttpClient)BuildCacheHttpClient, contentSession));
        }
コード例 #18
0
        private async Task PutStreamAsync(
            IContentSession session, IReadOnlyCollection <Stream> streams, List <PutResult> results)
        {
            var tasks = streams.Select(s => Task.Run(async() =>
                                                     await session.PutStreamAsync(_context, ContentHashType, s, CancellationToken.None)));

            foreach (var task in tasks.ToList())
            {
                var result = await task;
                results.Add(result);
            }
        }
コード例 #19
0
        /// <inheritdoc />
        protected override async Task <BoolResult> StartupCoreAsync(OperationContext context)
        {
            await _innerStore.StartupAsync(context).ThrowIfFailure();

            // Create long-lived session to be used with overlay (ImplicitPin=None (i.e false) to avoid cache full errors)
            _backingContentSession = _innerStore.CreateSession(context, "VFSInner", ImplicitPin.None).ThrowIfFailure().Session;
            await _backingContentSession.StartupAsync(context).ThrowIfFailure();

            _contentManager = new VfsContentManager(_logger, Configuration, _backingContentSession);

            return(await _contentManager.StartupAsync(context));
        }
コード例 #20
0
        private async Task PutFileAsync(
            IContentSession session, IReadOnlyList <AbsolutePath> paths, List <PutResult> results)
        {
            var tasks = paths.Select(p => Task.Run(async() => await session.PutFileAsync(
                                                       _context, ContentHashType, p, FileRealizationMode.HardLink, CancellationToken.None)));

            foreach (var task in tasks.ToList())
            {
                var result = await task;
                results.Add(result);
            }
        }
コード例 #21
0
        public static async Task <IReadOnlyList <ContentHash> > PutRandomAsync
        (
            this IContentSession session,
            Context context,
            HashType hashType,
            bool provideHash,
            long maxSize,
            int percent,
            long fileSize,
            bool useExactSize
        )
        {
            long bytesToPopulate = (percent * maxSize) / 100;

            if (useExactSize)
            {
                return(await PutRandomAsync(
                           session, context, hashType, provideHash, (int)(bytesToPopulate / fileSize), fileSize, true).ConfigureAwait(false));
            }

            var  contentHashes = new List <ContentHash>();
            long populatedSize = 0;

            while (populatedSize < bytesToPopulate)
            {
                var contentSizes = new List <int>();
                while (populatedSize < bytesToPopulate && contentSizes.Count < MaxBulkPageSize)
                {
                    var numBytes = (int)Math.Min(ThreadSafeRandom.Generator.Next((int)fileSize), bytesToPopulate - populatedSize);
                    contentSizes.Add(numBytes);
                    populatedSize += numBytes;
                }

                var tasks = new List <Task <PutResult> >(contentSizes.Count);
                tasks.AddRange(
                    contentSizes.Select(
                        contentSize =>
                        session.PutRandomAsync(context.CreateNested(), hashType, provideHash, contentSize, CancellationToken.None)));

                foreach (var task in tasks)
                {
                    var result = await task.ConfigureAwait(false);

                    if (result.Succeeded)
                    {
                        contentHashes.Add(result.ContentHash);
                    }
                }
            }

            return(contentHashes);
        }
コード例 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BuildCacheSession"/> class.
 /// </summary>
 /// <param name="fileSystem">Filesystem used to read/write files.</param>
 /// <param name="name">Session name.</param>
 /// <param name="implicitPin">Policy determining whether or not content should be automatically pinned on adds or gets.</param>
 /// <param name="cacheNamespace">The namespace of the cache being communicated with.</param>
 /// <param name="cacheId">The id of the cache being communicated with.</param>
 /// <param name="contentHashListAdapter">Backing BuildCache http client.</param>
 /// <param name="backingContentSession">Backing BlobStore content session.</param>
 /// <param name="maxFingerprintSelectorsToFetch">Maximum number of selectors to enumerate for a GetSelectors call.</param>
 /// <param name="minimumTimeToKeepContentHashLists">Minimum time-to-live for created or referenced ContentHashLists.</param>
 /// <param name="rangeOfTimeToKeepContentHashLists">Range of time beyond the minimum for the time-to-live of created or referenced ContentHashLists.</param>
 /// <param name="fingerprintIncorporationEnabled">Feature flag to enable fingerprints incorporation</param>
 /// <param name="maxDegreeOfParallelismForIncorporateRequests">Throttle the number of fingerprints chunks sent in parallel</param>
 /// <param name="maxFingerprintsPerIncorporateRequest">Max fingerprints allowed per chunk</param>
 /// <param name="writeThroughContentSession">Optional write-through session to allow writing-behind to BlobStore</param>
 /// <param name="sealUnbackedContentHashLists">If true, the client will attempt to seal any unbacked ContentHashLists that it sees.</param>
 /// <param name="overrideUnixFileAccessMode">If true, overrides default Unix file access modes when placing files.</param>
 /// <param name="tracer">A tracer for logging calls</param>
 /// <param name="enableEagerFingerprintIncorporation"><see cref="BuildCacheServiceConfiguration.EnableEagerFingerprintIncorporation"/></param>
 /// <param name="inlineFingerprintIncorporationExpiry"><see cref="BuildCacheServiceConfiguration.InlineFingerprintIncorporationExpiryHours"/></param>
 /// <param name="eagerFingerprintIncorporationInterval"><see cref="BuildCacheServiceConfiguration.EagerFingerprintIncorporationNagleIntervalMinutes"/></param>
 /// <param name="eagerFingerprintIncorporationBatchSize"><see cref="BuildCacheServiceConfiguration.EagerFingerprintIncorporationNagleBatchSize"/></param>
 /// <param name="manuallyExtendContentLifetime">Whether to manually extend content lifetime when doing incorporate calls</param>
 /// <param name="forceUpdateOnAddContentHashList">Whether to force an update and ignore existing CHLs when adding.</param>
 public BuildCacheSession(
     IAbsFileSystem fileSystem,
     string name,
     ImplicitPin implicitPin,
     string cacheNamespace,
     Guid cacheId,
     IContentHashListAdapter contentHashListAdapter,
     IBackingContentSession backingContentSession,
     int maxFingerprintSelectorsToFetch,
     TimeSpan minimumTimeToKeepContentHashLists,
     TimeSpan rangeOfTimeToKeepContentHashLists,
     bool fingerprintIncorporationEnabled,
     int maxDegreeOfParallelismForIncorporateRequests,
     int maxFingerprintsPerIncorporateRequest,
     IContentSession writeThroughContentSession,
     bool sealUnbackedContentHashLists,
     bool overrideUnixFileAccessMode,
     BuildCacheCacheTracer tracer,
     bool enableEagerFingerprintIncorporation,
     TimeSpan inlineFingerprintIncorporationExpiry,
     TimeSpan eagerFingerprintIncorporationInterval,
     int eagerFingerprintIncorporationBatchSize,
     bool manuallyExtendContentLifetime,
     bool forceUpdateOnAddContentHashList)
     : base(
         fileSystem,
         name,
         implicitPin,
         cacheNamespace,
         cacheId,
         contentHashListAdapter,
         backingContentSession,
         maxFingerprintSelectorsToFetch,
         minimumTimeToKeepContentHashLists,
         rangeOfTimeToKeepContentHashLists,
         fingerprintIncorporationEnabled,
         maxDegreeOfParallelismForIncorporateRequests,
         maxFingerprintsPerIncorporateRequest,
         writeThroughContentSession,
         sealUnbackedContentHashLists,
         overrideUnixFileAccessMode,
         tracer,
         enableEagerFingerprintIncorporation,
         inlineFingerprintIncorporationExpiry,
         eagerFingerprintIncorporationInterval,
         eagerFingerprintIncorporationBatchSize,
         manuallyExtendContentLifetime,
         forceUpdateOnAddContentHashList)
 {
 }
コード例 #23
0
        private async Task UploadContent(
            Context context,
            StrongFingerprint strongFingerprint,
            ContentHashList contentHashList,
            IContentSession fromSession,
            IContentSession toSession)
        {
            await UploadContent(context, strongFingerprint.Selector.ContentHash, fromSession, toSession).ConfigureAwait(false);

            foreach (var contentHash in contentHashList.Hashes)
            {
                await UploadContent(context, contentHash, fromSession, toSession).ConfigureAwait(false);
            }
        }
コード例 #24
0
            private static IContentSession UnwrapSession(IContentSession session, bool primary)
            {
                if (session is MultiplexedContentSession multiplexSession)
                {
                    var primarySession = multiplexSession.PreferredContentSession;
                    session = (IContentSession)(primary ? primarySession : multiplexSession.SessionsByCacheRoot.Values.Where(s => s != primarySession).First());
                }
                else if (session is DistributedContentSession distributedSession)
                {
                    session = distributedSession.Inner;
                }

                return(session);
            }
コード例 #25
0
        /// <inheritdoc />
        public Task <PlaceFileResult> PlaceFileAsync(
            Context context,
            ContentHash contentHash,
            AbsolutePath path,
            FileAccessMode accessMode,
            FileReplacementMode replacementMode,
            FileRealizationMode realizationMode,
            CancellationToken cts,
            UrgencyHint urgencyHint = UrgencyHint.Nominal)
        {
            IContentSession hardlinkSession = null;

            if (realizationMode == FileRealizationMode.HardLink)
            {
                var drive = path.GetPathRoot();
                if (SessionsByCacheRoot.TryGetValue(drive, out var session) && session is IContentSession writeableSession)
                {
                    hardlinkSession = writeableSession;
                }
                else
                {
                    return(Task.FromResult(new PlaceFileResult("Requested hardlink but there is no session on the same drive as destination path.")));
                }
            }

            return(PerformAggregateSessionOperationAsync <IReadOnlyContentSession, PlaceFileResult>(
                       context,
                       executeAsync: placeFileCore,
                       (r1, r2) => r1.Succeeded ? r1 : r2,
                       shouldBreak: r => r.Succeeded,
                       pathHint: path));

            async Task <PlaceFileResult> placeFileCore(IReadOnlyContentSession session)
            {
                // If we exclusively want a hardlink, we should make sure that we can copy from other drives to satisfy the request.
                if (realizationMode != FileRealizationMode.HardLink || session == hardlinkSession)
                {
                    return(await session.PlaceFileAsync(context, contentHash, path, accessMode, replacementMode, realizationMode, cts, urgencyHint));
                }

                // See if session has the content.
                var streamResult = await session.OpenStreamAsync(context, contentHash, cts, urgencyHint).ThrowIfFailure();

                // Put it into correct store
                var putResult = await hardlinkSession.PutStreamAsync(context, contentHash, streamResult.Stream, cts, urgencyHint).ThrowIfFailure();

                // Try the hardlink on the correct drive.
                return(await hardlinkSession.PlaceFileAsync(context, contentHash, path, accessMode, replacementMode, realizationMode, cts, urgencyHint));
            }
        }
コード例 #26
0
        public static async Task <PutResult> PutContentAsync(
            this IContentSession session, Context context, string content)
        {
            var c = context.CreateNested();

            var data     = Encoding.UTF8.GetBytes(content);
            var hashType = HashType.SHA256;

            using (var stream = new MemoryStream(data))
            {
                var hash = HashInfoLookup.Find(hashType).CreateContentHasher().GetContentHash(data);
                return(await session.PutStreamAsync(c, hash, stream, CancellationToken.None).ConfigureAwait(false));
            }
        }
コード例 #27
0
        public Task TestColdStorageWithBulkFunction()
        {
            return(RunTestAsync(async(context, store, directory) =>
            {
                var originalPath = directory.Path / "original.txt";
                var fileContents = GetRandomFileContents();

                // Build destination IContentSession
                DisposableDirectory sessionDirectory = new DisposableDirectory(FileSystem);
                ConfigurationModel configurationModel = new ConfigurationModel(new ContentStoreConfiguration(new MaxSizeQuota("10MB")));
                FileSystemContentStore destination = new FileSystemContentStore(FileSystem, SystemClock.Instance, sessionDirectory.Path, configurationModel);
                _ = await destination.StartupAsync(context);
                IContentSession contentSession = destination.CreateSession(context, "test_session", BuildXL.Cache.ContentStore.Interfaces.Stores.ImplicitPin.None).Session;
                _ = await contentSession.StartupAsync(context);

                // Create the file and hardlink it into the cache.
                FileSystem.WriteAllText(originalPath, fileContents);

                var contentHasher = HashInfoLookup.GetContentHasher(HashType.MD5);
                var contentHash = contentHasher.GetContentHash(Encoding.UTF8.GetBytes(fileContents));

                await store.PutFileAsync(context, contentHash, new DisposableFile(context, FileSystem, originalPath), context.Token).ShouldBeSuccess();

                FileSystem.DeleteFile(originalPath);
                FileSystem.FileExists(originalPath).Should().Be(false);

                ContentHashWithPath contentHashWithPath = new ContentHashWithPath(contentHash, originalPath);
                List <ContentHashWithPath> listFile = new List <ContentHashWithPath>();
                listFile.Add(contentHashWithPath);

                // Hardlink back to original location trying to replace existing.
                var copyTask = await store.FetchThenPutBulkAsync(
                    context,
                    listFile,
                    contentSession);

                await copyTask.ToLookupAwait(r => { return r.Item.Succeeded; });

                FileSystem.FileExists(originalPath).Should().Be(false);

                // The file is in the destination.
                await contentSession.PlaceFileAsync(context, contentHash, originalPath, FileAccessMode.Write, FileReplacementMode.FailIfExists, FileRealizationMode.Copy, CancellationToken.None).ShouldBeSuccess();
                FileSystem.FileExists(originalPath).Should().Be(true);
                FileSystem.ReadAllText(originalPath).Should().Be(fileContents);

                _ = await contentSession.ShutdownAsync(context);
                _ = await destination.ShutdownAsync(context);
            }));
        }
コード例 #28
0
        public CreateSessionResult <ICacheSession> CreateSession(Context context, string name, ImplicitPin implicitPin)
        {
            return(Tracing.CreateSessionCall.Run(_tracer, context, name, () =>
            {
                var backingContentSessionResult = _backingContentStore.CreateSession(context, name, implicitPin);
                if (!backingContentSessionResult.Succeeded)
                {
                    return new CreateSessionResult <ICacheSession>(backingContentSessionResult);
                }

                IContentSession writeThroughContentSession = null;
                if (_writeThroughContentStore != null)
                {
                    var writeThroughContentSessionResult = _writeThroughContentStore.CreateSession(context, name, implicitPin);
                    if (!writeThroughContentSessionResult.Succeeded)
                    {
                        return new CreateSessionResult <ICacheSession>(writeThroughContentSessionResult);
                    }

                    writeThroughContentSession = writeThroughContentSessionResult.Session;
                }

                return new CreateSessionResult <ICacheSession>(
                    new BuildCacheSession(
                        _fileSystem,
                        name,
                        implicitPin,
                        _cacheNamespace,
                        Id,
                        _contentHashListAdapterFactory.Create(backingContentSessionResult.Session),
                        backingContentSessionResult.Session,
                        _maxFingerprintSelectorsToFetch,
                        _minimumTimeToKeepContentHashLists,
                        _rangeOfTimeToKeepContentHashLists,
                        _fingerprintIncorporationEnabled,
                        _maxDegreeOfParallelismForIncorporateRequests,
                        _maxFingerprintsPerIncorporateRequest,
                        writeThroughContentSession,
                        _sealUnbackedContentHashLists,
                        _overrideUnixFileAccessMode,
                        _tracer,
                        _enableEagerFingerprintIncorporation,
                        _inlineFingerprintIncorporationExpiry,
                        _eagerFingerprintIncorporationNagleInterval,
                        _eagerFingerprintIncorporationNagleBatchSize,
                        _manuallyExtendContentLifetime,
                        _forceUpdateOnAddContentHashList));
            }));
        }
コード例 #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MultiLevelReadOnlyContentSession{TSession}"/> class.
        /// </summary>
        public MultiLevelReadOnlyContentSession(
            string name,
            TSession localSession,
            TSession backingSession,
            bool isLocalWritable)
            : base(name)
        {
            Contract.Requires(name != null);
            Contract.Requires(localSession != null);
            Contract.Requires(backingSession != null);

            LocalSession         = localSession;
            BackingSession       = backingSession;
            WritableLocalSession = isLocalWritable ? (IContentSession)localSession : null;
        }
コード例 #30
0
 /// <nodoc />
 public DistributedContentSession(
     string name,
     IContentSession inner,
     IContentLocationStore contentLocationStore,
     DistributedContentCopier contentCopier,
     IDistributedContentCopierHost copierHost,
     MachineLocation localMachineLocation,
     DistributedContentStoreSettings settings = default)
     : base(
         name,
         inner,
         contentLocationStore,
         contentCopier,
         copierHost,
         localMachineLocation,
         settings)
 {
 }