private static MemoizationStoreAdapterCache CreateCache(Config cacheConfig, AbsolutePath logPath, ILogger logger) { ServiceClientRpcConfiguration rpcConfiguration; if (cacheConfig.GrpcPort != 0) { rpcConfiguration = new ServiceClientRpcConfiguration((int)cacheConfig.GrpcPort); } else { var factory = new MemoryMappedFileGrpcPortSharingFactory(logger, cacheConfig.GrpcPortFileName); var portReader = factory.GetPortReader(); var port = portReader.ReadPort(); rpcConfiguration = new ServiceClientRpcConfiguration(port); } var serviceClientConfiguration = new ServiceClientContentStoreConfiguration(cacheConfig.CacheName, rpcConfiguration, cacheConfig.ScenarioName) { RetryCount = cacheConfig.ConnectionRetryCount, RetryIntervalSeconds = cacheConfig.ConnectionRetryIntervalSeconds, TraceOperationStarted = cacheConfig.GrpcTraceOperationStarted, }; MemoizationStore.Interfaces.Caches.ICache localCache; if (cacheConfig.EnableMetadataServer) { localCache = LocalCache.CreateRpcCache(logger, serviceClientConfiguration); } else { var metadataRootPath = new AbsolutePath(cacheConfig.MetadataRootPath); localCache = LocalCache.CreateRpcContentStoreInProcMemoizationStoreCache(logger, metadataRootPath, serviceClientConfiguration, CreateInProcMemoizationStoreConfiguration(cacheConfig, metadataRootPath)); } var statsFilePath = new AbsolutePath(logPath.Path + ".stats"); if (!string.IsNullOrEmpty(cacheConfig.VfsCasRoot)) { logger.Debug($"Creating virtualized cache"); localCache = new VirtualizedContentCache(localCache, new ContentStore.Vfs.VfsCasConfiguration.Builder() { RootPath = new AbsolutePath(cacheConfig.VfsCasRoot), UseSymlinks = cacheConfig.UseVfsSymlinks }.Build()); } var cache = new MemoizationStoreAdapterCache(cacheConfig.CacheId, localCache, logger, statsFilePath, cacheConfig.ReplaceExistingOnPlaceFile); return(cache); }
/// <summary> /// Create cache using configuration /// </summary> public async Task <Possible <ICache, Failure> > InitializeCacheAsync(Config cacheConfig, Guid activityId) { Contract.Requires(cacheConfig != null); try { var logPath = new AbsolutePath(cacheConfig.CacheLogPath); var logger = new DisposeLogger(() => new EtwFileLog(logPath.Path, cacheConfig.CacheId), cacheConfig.LogFlushIntervalSeconds); var localCache = cacheConfig.UseStreamCAS ? CreateLocalCacheWithStreamPathCas(cacheConfig, logger) : CreateLocalCacheWithSingleCas(cacheConfig, logger); var statsFilePath = new AbsolutePath(logPath.Path + ".stats"); if (!string.IsNullOrEmpty(cacheConfig.VfsCasRoot)) { localCache = new VirtualizedContentCache(localCache, new ContentStore.Vfs.VfsCasConfiguration.Builder() { RootPath = new AbsolutePath(cacheConfig.VfsCasRoot), UseSymlinks = cacheConfig.UseVfsSymlinks }.Build()); } var cache = new MemoizationStoreAdapterCache(cacheConfig.CacheId, localCache, logger, statsFilePath, cacheConfig.ReplaceExistingOnPlaceFile); var startupResult = await cache.StartupAsync(); if (!startupResult.Succeeded) { return(startupResult.Failure); } return(cache); } catch (Exception e) { return(new CacheConstructionFailure(cacheConfig.CacheId, e)); } }
private static MemoizationStoreAdapterCache CreateCache(Config cacheConfig, AbsolutePath logPath, ILogger logger) { var serviceClientContentStoreConfiguration = CreateGrpcServiceConfiguration(cacheConfig, logger); MemoizationStore.Interfaces.Caches.ICache localCache; if (cacheConfig.EnableMetadataServer) { // CaChaaS path. localCache = LocalCache.CreateRpcCache(logger, serviceClientContentStoreConfiguration); } else { // CASaaS path. We construct an in-proc memoization store in this case. var metadataRootPath = new AbsolutePath(cacheConfig.MetadataRootPath); localCache = LocalCache.CreateRpcContentStoreInProcMemoizationStoreCache(logger, metadataRootPath, serviceClientContentStoreConfiguration, CreateInProcMemoizationStoreConfiguration(cacheConfig, metadataRootPath)); } var statsFilePath = new AbsolutePath(logPath.Path + ".stats"); if (!string.IsNullOrEmpty(cacheConfig.VfsCasRoot)) { // Vfs path. Vfs wraps around whatever cache we are using to virtualize logger.Debug($"Creating virtualized cache"); localCache = new VirtualizedContentCache(localCache, new ContentStore.Vfs.VfsCasConfiguration.Builder() { RootPath = new AbsolutePath(cacheConfig.VfsCasRoot), UseSymlinks = cacheConfig.VfsUseSymlinks }.Build()); } return(new MemoizationStoreAdapterCache(cacheConfig.CacheId, localCache, logger, statsFilePath, cacheConfig.ReplaceExistingOnPlaceFile)); }