private static LocalCache CreateLocalCacheWithSingleCas(Config config, DisposeLogger logger)
        {
            LocalCacheConfiguration localCacheConfiguration;

            if (config.EnableContentServer)
            {
                localCacheConfiguration = LocalCacheConfiguration.CreateServerEnabled(
                    config.GrpcPort,
                    config.CacheName,
                    config.ScenarioName,
                    config.RetryIntervalSeconds,
                    config.RetryCount);
            }
            else
            {
                localCacheConfiguration = LocalCacheConfiguration.CreateServerDisabled();
            }

            var configCore         = GetCasConfig(config);
            var configurationModel = CreateConfigurationModel(configCore);
            var cacheRoot          = new AbsolutePath(config.CacheRootPath);
            var memoConfig         = GetMemoizationStoreConfiguration(cacheRoot, config, configCore);

            return(new LocalCache(
                       logger,
                       cacheRoot,
                       memoConfig,
                       localCacheConfiguration,
                       configurationModel: configurationModel,
                       clock: null,
                       checkLocalFiles: config.CheckLocalFiles,
                       emptyFileHashShortcutEnabled: config.EmptyFileHashShortcutEnabled));
        }
Пример #2
0
        private static LocalCache CreateLocalCacheWithSingleCas(Config config, DisposeLogger logger)
        {
            var configCore         = GetCasConfig(config);
            var configurationModel = CreateConfigurationModel(configCore);

            var cacheRoot  = new AbsolutePath(config.CacheRootPath);
            var memoConfig = GetMemoConfig(cacheRoot, config, configCore);

            return(new LocalCache(
                       logger,
                       cacheRoot,
                       memoConfig,
                       configurationModel));
        }
        private static LocalCache CreateLocalCacheWithStreamPathCas(Config config, DisposeLogger logger)
        {
            Contract.Requires(config.UseStreamCAS);

            SetDefaultsForStreamCas(config);
            var configCoreForPath = GetCasConfig(config);

            return(LocalCache.CreateStreamPathContentStoreInProcMemoizationStoreCache(
                       logger,
                       new AbsolutePath(config.StreamCAS.CacheRootPath),
                       new AbsolutePath(configCoreForPath.CacheRootPath),
                       GetInProcMemoizationStoreConfiguration(new AbsolutePath(config.CacheRootPath), config, configCoreForPath),
                       CreateConfigurationModel(config.StreamCAS),
                       CreateConfigurationModel(configCoreForPath)));
        }
        private static LocalCache CreateLocalCacheWithStreamPathCas(Config config, DisposeLogger logger)
        {
            Contract.Requires(config.UseStreamCAS);

            SetDefaultsForStreamCas(config);

            var configCoreForPath            = GetCasConfig(config);
            var configurationModelForPath    = CreateConfigurationModel(configCoreForPath);
            var configurationModelForStreams = CreateConfigurationModel(config.StreamCAS);

            var memoConfig = GetMemoConfig(new AbsolutePath(config.CacheRootPath), config, configCoreForPath);

            return(new LocalCache(
                       logger,
                       new AbsolutePath(config.StreamCAS.CacheRootPath),
                       new AbsolutePath(configCoreForPath.CacheRootPath),
                       memoConfig,
                       configurationModelForStreams,
                       configurationModelForPath));
        }
        /// <inheritdoc />
        public async Task <Possible <ICache, Failure> > InitializeCacheAsync(ICacheConfigData cacheData, Guid activityId, ICacheConfiguration cacheConfiguration = null)
        {
            Contract.Requires(cacheData != null);

            var possibleCacheConfig = cacheData.Create <Config>();

            if (!possibleCacheConfig.Succeeded)
            {
                return(possibleCacheConfig.Failure);
            }

            Config cacheConfig = possibleCacheConfig.Result;

            try
            {
                Contract.Assert(cacheConfig.CacheName != null);
                var logPath = new AbsolutePath(cacheConfig.MetadataLogPath);
                var logger  = new DisposeLogger(() => new EtwFileLog(logPath.Path, cacheConfig.CacheId), cacheConfig.LogFlushIntervalSeconds);

                logger.Debug($"Creating CASaaS backed LocalCache using cache name: {cacheConfig.CacheName}");

                var cache = CreateCache(cacheConfig, logPath, logger);

                var startupResult = await cache.StartupAsync();

                if (!startupResult.Succeeded)
                {
                    logger.Error($"Error while initializing the cache [{cacheConfig.CacheId}]. Failure: {startupResult.Failure}");
                    cache.Dispose();

                    return(startupResult.Failure);
                }

                logger.Debug("Successfully started CloudStoreLocalCacheService client.");
                return(cache);
            }
            catch (Exception e)
            {
                return(new CacheConstructionFailure(cacheConfig.CacheId, e));
            }
        }
Пример #6
0
        /// <inheritdoc />
        public async Task <Possible <ICache, Failure> > InitializeCacheAsync(ICacheConfigData cacheData, Guid activityId)
        {
            Contract.Requires(cacheData != null);

            var possibleCacheConfig = cacheData.Create <Config>();

            if (!possibleCacheConfig.Succeeded)
            {
                return(possibleCacheConfig.Failure);
            }

            Config cacheConfig = possibleCacheConfig.Result;

            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");
                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));
            }
        }
        /// <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 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));
            }
        }
Пример #9
0
        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));
            }
        }
Пример #10
0
        /// <inheritdoc />
        public async Task <Possible <ICache, Failure> > InitializeCacheAsync(ICacheConfigData cacheData, Guid activityId)
        {
            Contract.Requires(cacheData != null);

            var possibleCacheConfig = cacheData.Create <Config>();

            if (!possibleCacheConfig.Succeeded)
            {
                return(possibleCacheConfig.Failure);
            }

            Config cacheConfig = possibleCacheConfig.Result;

            try
            {
                Contract.Assert(cacheConfig.CacheName != null);
                var logPath = new AbsolutePath(cacheConfig.MetadataLogPath);
                var logger  = new DisposeLogger(() => new EtwFileLog(logPath.Path, cacheConfig.CacheId), cacheConfig.LogFlushIntervalSeconds);

                logger.Debug($"Creating CASaaS backed LocalCache using cache name: {cacheConfig.CacheName}");

                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 rootPath   = new AbsolutePath(cacheConfig.MetadataRootPath);
                var memoConfig = new SQLiteMemoizationStoreConfiguration(rootPath)
                {
                    MaxRowCount                  = cacheConfig.MaxStrongFingerprints,
                    BackupDatabase               = cacheConfig.BackupLKGCache,
                    VerifyIntegrityOnStartup     = cacheConfig.CheckCacheIntegrityOnStartup,
                    SingleInstanceTimeoutSeconds = (int)cacheConfig.SingleInstanceTimeoutInSeconds
                };

                if (!string.IsNullOrEmpty(cacheConfig.SynchronizationMode))
                {
                    memoConfig.SyncMode = (SynchronizationMode)Enum.Parse(typeof(SynchronizationMode), cacheConfig.SynchronizationMode, ignoreCase: true);
                }

                var localCache = new LocalCache(
                    logger,
                    cacheConfig.CacheName,
                    rootPath,
                    rpcConfiguration,
                    cacheConfig.ConnectionRetryIntervalSeconds,
                    cacheConfig.ConnectionRetryCount,
                    memoConfig,
                    scenarioName: cacheConfig.ScenarioName);

                var statsFilePath = new AbsolutePath(logPath.Path + ".stats");
                var cache         = new MemoizationStoreAdapterCache(cacheConfig.CacheId, localCache, logger, statsFilePath, cacheConfig.ReplaceExistingOnPlaceFile);

                var startupResult = await cache.StartupAsync();

                if (!startupResult.Succeeded)
                {
                    logger.Error($"Error while initializing the cache [{cacheConfig.CacheId}]. Failure: {startupResult.Failure}");
                    return(startupResult.Failure);
                }

                logger.Debug("Successfully started CloudStoreLocalCacheService client.");
                return(cache);
            }
            catch (Exception e)
            {
                return(new CacheConstructionFailure(cacheConfig.CacheId, e));
            }
        }