Example #1
0
        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 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));
        }