/// <inheritdoc /> public Task <BoolResult> StartupAsync(Context context) { StartupStarted = true; return(StartupCall <MemoizationStoreTracer> .RunAsync(Tracer.MemoizationStoreTracer, context, async() => { BoolResult result; var backingContentSessionTask = Task.Run(async() => await BackingContentSession.StartupAsync(context).ConfigureAwait(false)); var writeThroughContentSessionResult = WriteThroughContentSession != null ? await WriteThroughContentSession.StartupAsync(context).ConfigureAwait(false) : BoolResult.Success; var backingContentSessionResult = await backingContentSessionTask.ConfigureAwait(false); if (backingContentSessionResult.Succeeded && writeThroughContentSessionResult.Succeeded) { _taskTracker = new BackgroundTaskTracker(Component, new Context(context)); result = BoolResult.Success; } else { var sb = new StringBuilder(); if (backingContentSessionResult.Succeeded) { var r = await BackingContentSession.ShutdownAsync(context).ConfigureAwait(false); if (!r.Succeeded) { sb.Append($"Backing content session shutdown failed, error=[{r}]"); } } else { sb.Append($"Backing content session startup failed, error=[{backingContentSessionResult}]"); } if (writeThroughContentSessionResult.Succeeded) { var r = WriteThroughContentSession != null ? await WriteThroughContentSession.ShutdownAsync(context).ConfigureAwait(false) : BoolResult.Success; if (!r.Succeeded) { sb.Append(sb.Length > 0 ? ", " : string.Empty); sb.Append($"Write-through content session shutdown failed, error=[{r}]"); } } else { sb.Append(sb.Length > 0 ? ", " : string.Empty); sb.Append($"Write-through content session startup failed, error=[{writeThroughContentSessionResult}]"); } result = new BoolResult(sb.ToString()); } StartupCompleted = true; return result; })); }
/// <inheritdoc /> public Task <BoolResult> StartupAsync(Context context) { StartupStarted = true; return(StartupCall <ContentSessionTracer> .RunAsync(_tracer, context, async() => { var startupResults = await Task.WhenAll(_sessionForStream.StartupAsync(context), _sessionForPath.StartupAsync(context)); Contract.Assert(startupResults.Length == 2); var startupResultForStream = startupResults[0]; var startupResultForPath = startupResults[1]; var result = startupResultForStream & startupResultForPath; if (!result.Succeeded) { var sb = new StringBuilder(); if (!startupResultForStream.Succeeded) { sb.Concat($"{SessionForStreamText} startup failed, error=[{startupResultForStream}]", "; "); } if (!startupResultForPath.Succeeded) { sb.Concat($"{SessionForPathText} startup failed, error=[{startupResultForPath}]", "; "); } if (startupResultForStream.Succeeded) { var shutdownResult = await _sessionForStream.ShutdownAsync(context); if (!shutdownResult.Succeeded) { sb.Concat($"{SessionForStreamText} shutdown failed, error=[{shutdownResult}]", "; "); } } if (startupResultForPath.Succeeded) { var shutdownResult = await _sessionForPath.ShutdownAsync(context); if (!shutdownResult.Succeeded) { sb.Concat($"{SessionForPathText} shutdown failed, error=[{shutdownResult}]", "; "); } } result = new BoolResult(sb.ToString()); } StartupCompleted = true; return result; })); }
/// <inheritdoc /> protected override async Task <BoolResult> ShutdownCoreAsync(OperationContext context) { var result = await base.ShutdownCoreAsync(context); result &= await _innerSession.ShutdownAsync(context); return(result); }
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(); } } } }
/// <inheritdoc /> protected override async Task <BoolResult> ShutdownCoreAsync(OperationContext context) { // Close all sessions? var result = await base.ShutdownCoreAsync(context); result &= await _vfsContentSession.ShutdownAsync(context); result &= await _innerStore.ShutdownAsync(context); return(result); }
protected override async Task <BoolResult> ShutdownCoreAsync(OperationContext context) { var publisherResult = BoolResult.Success; if (_publisher != null) { publisherResult = await _publisher.ShutdownAsync(context).ThrowIfFailure(); } var contentSessionResult = await _sourceContentSession.ShutdownAsync(context); return(publisherResult & contentSessionResult); }
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); })); }
/// <inheritdoc /> protected override async Task <BoolResult> ShutdownCoreAsync(OperationContext context) { BoolResult result = BoolResult.Success; if (_contentManager != null) { result = await _contentManager.ShutdownAsync(context); } result &= await _backingContentSession.ShutdownAsync(context); result &= await _innerStore.ShutdownAsync(context); return(result); }
public async Task MultipleClients() { 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; IContentSession session2 = null; try { var createSessionResult1 = store.CreateSession(_context, "session1", ImplicitPin.None); createSessionResult1.ShouldBeSuccess(); var createSessionResult2 = store.CreateSession(_context, "session2", ImplicitPin.None); createSessionResult2.ShouldBeSuccess(); using (createSessionResult1.Session) using (createSessionResult2.Session) { var r1 = await createSessionResult1.Session.StartupAsync(_context); r1.ShouldBeSuccess(); session1 = createSessionResult1.Session; var startupSessionResult2 = await createSessionResult2.Session.StartupAsync(_context); startupSessionResult2.ShouldBeSuccess(); session2 = createSessionResult2.Session; var putResult = await session1.PutRandomAsync( _context, ContentHashType, false, RandomContentByteCount, Token); var tasks1 = Enumerable.Range(0, (int)ConnectionsPerSession) .Select(_ => Task.Run(async() => await session1.PinAsync(_context, putResult.ContentHash, Token))) .ToList(); var tasks2 = Enumerable.Range(0, (int)ConnectionsPerSession) .Select(_ => Task.Run(async() => await session2.PinAsync(_context, putResult.ContentHash, Token))) .ToList(); foreach (var task in tasks1.Union(tasks2)) { var result = await task; result.ShouldBeSuccess(); } } } finally { if (session2 != null) { await session2.ShutdownAsync(_context).ShouldBeSuccess(); } if (session1 != null) { await session1.ShutdownAsync(_context).ShouldBeSuccess(); } } } finally { var r = await store.ShutdownAsync(_context); r.ShouldBeSuccess(); } } } }
public async Task MultipleCaches() { const string CacheName1 = "test1"; const string CacheName2 = "test2"; using (var testDirectory0 = new DisposableDirectory(FileSystem)) using (var testDirectory1 = new DisposableDirectory(FileSystem)) using (var testDirectory2 = new DisposableDirectory(FileSystem)) { var config = CreateStoreConfiguration(); var rootPath1 = testDirectory1.Path; config.Write(FileSystem, rootPath1); var rootPath2 = testDirectory2.Path; config.Write(FileSystem, rootPath2); var grpcPort = PortExtensions.GetNextAvailablePort(); var grpcPortFileName = Guid.NewGuid().ToString(); var serviceConfiguration = new ServiceConfiguration( new Dictionary <string, AbsolutePath> { { CacheName1, rootPath1 }, { CacheName2, rootPath2 } }, testDirectory0.Path, ServiceConfiguration.DefaultGracefulShutdownSeconds, grpcPort, grpcPortFileName); using (var server = CreateServer(serviceConfiguration)) { var factory = new MemoryMappedFileGrpcPortSharingFactory(Logger, grpcPortFileName); var reader = factory.GetPortReader(); var port = reader.ReadPort(); var rpcConfig = new ServiceClientRpcConfiguration(port); using (var store1 = new ServiceClientContentStore( Logger, FileSystem, new ServiceClientContentStoreConfiguration(CacheName1, rpcConfig, Scenario))) using (var store2 = new ServiceClientContentStore( Logger, FileSystem, new ServiceClientContentStoreConfiguration(CacheName2, rpcConfig, Scenario))) { try { var rs = await server.StartupAsync(_context); rs.ShouldBeSuccess(); var storeBoolResult1 = await store1.StartupAsync(_context); storeBoolResult1.ShouldBeSuccess(); var storeBoolResult2 = await store2.StartupAsync(_context); storeBoolResult2.ShouldBeSuccess(); IContentSession session1 = null; IContentSession session2 = null; try { var createSessionResult1 = store1.CreateSession(_context, "session1", ImplicitPin.None); createSessionResult1.ShouldBeSuccess(); var createSessionResult2 = store2.CreateSession(_context, "session2", ImplicitPin.None); createSessionResult2.ShouldBeSuccess(); using (createSessionResult1.Session) using (createSessionResult2.Session) { var r1 = await createSessionResult1.Session.StartupAsync(_context); r1.ShouldBeSuccess(); session1 = createSessionResult1.Session; var r2 = await createSessionResult2.Session.StartupAsync(_context); r2.ShouldBeSuccess(); session2 = createSessionResult2.Session; var r3 = await session1.PutRandomAsync( _context, ContentHashType, false, RandomContentByteCount, Token); var pinResult = await session1.PinAsync(_context, r3.ContentHash, Token); pinResult.ShouldBeSuccess(); r3 = await session2.PutRandomAsync( _context, ContentHashType, false, RandomContentByteCount, Token); pinResult = await session2.PinAsync(_context, r3.ContentHash, Token); pinResult.ShouldBeSuccess(); } } finally { if (session2 != null) { await session2.ShutdownAsync(_context).ShouldBeSuccess(); } if (session1 != null) { await session1.ShutdownAsync(_context).ShouldBeSuccess(); } } } finally { BoolResult r1 = null; BoolResult r2 = null; if (store1.StartupCompleted) { r1 = await store1.ShutdownAsync(_context); } if (store2.StartupCompleted) { r2 = await store2.ShutdownAsync(_context); } var r3 = await server.ShutdownAsync(_context); r1?.ShouldBeSuccess(); r2?.ShouldBeSuccess(); r3?.ShouldBeSuccess(); } } } } }