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); }
private static MemoizationStore.Interfaces.Caches.ICache CreateGrpcCache(Config config, DisposeLogger logger) { Contract.Requires(config.RetryIntervalSeconds >= 0); Contract.Requires(config.RetryCount >= 0); var serviceClientRpcConfiguration = new ServiceClientRpcConfiguration() { GrpcCoreClientOptions = config.GrpcCoreClientOptions, }; if (config.GrpcPort > 0) { serviceClientRpcConfiguration.GrpcPort = config.GrpcPort; } ServiceClientContentStoreConfiguration serviceClientContentStoreConfiguration = null; if (config.EnableContentServer) { new ServiceClientContentStoreConfiguration(config.CacheName, serviceClientRpcConfiguration, config.ScenarioName) { RetryIntervalSeconds = (uint)config.RetryIntervalSeconds, RetryCount = (uint)config.RetryCount, GrpcEnvironmentOptions = config.GrpcEnvironmentOptions, }; } if (config.EnableContentServer && config.EnableMetadataServer) { return(LocalCache.CreateRpcCache(logger, serviceClientContentStoreConfiguration)); } else { Contract.Assert(!config.EnableMetadataServer, "It is not supported to use a Metadata server without a Content server"); var memoizationStoreConfiguration = GetInProcMemoizationStoreConfiguration(new AbsolutePath(config.CacheRootPath), config, GetCasConfig(config)); return(LocalCache.CreateUnknownContentStoreInProcMemoizationStoreCache(logger, new AbsolutePath(config.CacheRootPath), memoizationStoreConfiguration, new LocalCacheConfiguration(serviceClientContentStoreConfiguration), configurationModel: CreateConfigurationModel(GetCasConfig(config)), clock: null, checkLocalFiles: config.CheckLocalFiles)); } }
private static MemoizationStore.Interfaces.Caches.ICache CreateLocalCacheWithSingleCas(Config config, DisposeLogger logger) { if (config.EnableContentServer && config.EnableMetadataServer) { Contract.Assert(config.RetryIntervalSeconds >= 0); Contract.Assert(config.RetryCount >= 0); var rpcConfiguration = new ServiceClientRpcConfiguration(config.GrpcPort); var serviceClientConfiguration = new ServiceClientContentStoreConfiguration(config.CacheName, rpcConfiguration, config.ScenarioName) { RetryIntervalSeconds = (uint)config.RetryIntervalSeconds, RetryCount = (uint)config.RetryCount, }; return(LocalCache.CreateRpcCache(logger, serviceClientConfiguration)); } else { Contract.Assert(!config.EnableMetadataServer, "It is not supported to use a Metadata server without a Content server"); LocalCacheConfiguration localCacheConfiguration; if (config.EnableContentServer) { localCacheConfiguration = LocalCacheConfiguration.CreateServerEnabled( config.GrpcPort, config.CacheName, config.ScenarioName, config.RetryIntervalSeconds, config.RetryCount); } else { localCacheConfiguration = LocalCacheConfiguration.CreateServerDisabled(); } return(LocalCache.CreateUnknownContentStoreInProcMemoizationStoreCache(logger, new AbsolutePath(config.CacheRootPath), GetInProcMemoizationStoreConfiguration(new AbsolutePath(config.CacheRootPath), config, GetCasConfig(config)), localCacheConfiguration, configurationModel: CreateConfigurationModel(GetCasConfig(config)), clock: null, checkLocalFiles: config.CheckLocalFiles, emptyFileHashShortcutEnabled: config.EmptyFileHashShortcutEnabled)); } }
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, }; 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"); var cache = new MemoizationStoreAdapterCache(cacheConfig.CacheId, localCache, logger, statsFilePath, cacheConfig.ReplaceExistingOnPlaceFile); return(cache); }
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)); }