/// <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));
            }
        }
Example #2
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));
            }
        }
Example #3
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));
            }
        }