internal static IContentStore CreateLocalContentStore(
            DistributedContentSettings settings,
            DistributedCacheServiceArguments arguments,
            ResolvedNamedCacheSettings resolvedSettings,
            IDistributedLocationStore distributedStore = null)
        {
            settings = settings ?? DistributedContentSettings.CreateDisabled();
            var contentStoreSettings = FromDistributedSettings(settings);

            ConfigurationModel configurationModel
                = new ConfigurationModel(new ContentStoreConfiguration(new MaxSizeQuota(resolvedSettings.Settings.CacheSizeQuotaString)));

            var localStore = ContentStoreFactory.CreateContentStore(arguments.FileSystem, resolvedSettings.ResolvedCacheRootPath,
                                                                    contentStoreSettings: contentStoreSettings, distributedStore: distributedStore, configurationModel: configurationModel);

            if (settings.BackingGrpcPort != null)
            {
                var backingStore = new ServiceClientContentStore(
                    arguments.Logger,
                    arguments.FileSystem,
                    resolvedSettings.Name,
                    new ServiceClientRpcConfiguration(settings.BackingGrpcPort.Value),
                    arguments.Configuration.LocalCasSettings.CasClientSettings.RetryIntervalSecondsOnFailServiceCalls,
                    arguments.Configuration.LocalCasSettings.CasClientSettings.RetryCountOnFailServiceCalls,
                    scenario: settings.BackingScenario);

                return(new MultiLevelContentStore(localStore, backingStore));
            }

            return(localStore);
        }
Пример #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="FileSystemContentStore" /> class.
        /// </summary>
        public FileSystemContentStore(
            IAbsFileSystem fileSystem,
            IClock clock,
            AbsolutePath rootPath,
            ConfigurationModel configurationModel,
            IDistributedLocationStore distributedStore,
            ContentStoreSettings settings)
        {
            Contract.Requires(fileSystem != null);
            Contract.Requires(clock != null);
            Contract.Requires(rootPath != null);

            int singleInstanceTimeoutSeconds = ContentStoreConfiguration.DefaultSingleInstanceTimeoutSeconds;

            if (configurationModel?.InProcessConfiguration != null)
            {
                // TODO: Stop using the configurationModel's SingleInstanceTimeout (bug 1365340)
                // because FileSystemContentStore doesn't respect the config file's value
                singleInstanceTimeoutSeconds = configurationModel.InProcessConfiguration.SingleInstanceTimeoutSeconds;
            }

            // FileSystemContentStore implicitly uses a null component name for compatibility with older versions' directory locks.
            _directoryLock = new DirectoryLock(rootPath, fileSystem, TimeSpan.FromSeconds(singleInstanceTimeoutSeconds));

            Store = new FileSystemContentStoreInternal(
                fileSystem,
                clock,
                rootPath,
                configurationModel,
                settings,
                distributedStore);
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DistributedEvictionSettings"/> class.
        /// </summary>
        public DistributedEvictionSettings(
            TrimOrGetLastAccessTimeAsync trimOrGetLastAccessTimeAsync,
            int locationStoreBatchSize,
            int?replicaCreditInMinutes,
            IDistributedLocationStore distributedStore)
        {
            Contract.Assert(trimOrGetLastAccessTimeAsync != null);

            TrimOrGetLastAccessTimeAsync = trimOrGetLastAccessTimeAsync;
            LocationStoreBatchSize       = locationStoreBatchSize;
            ReplicaCreditInMinutes       = replicaCreditInMinutes ?? DefaultReplicaCreditInMinutes;
            IsInitialized    = false;
            DistributedStore = distributedStore;
        }
Пример #4
0
        private async Task <BoolResult> EvictDistributedWithDistributedStoreAsync(IDistributedLocationStore distributedStore)
        {
            var      evictedContent  = new List <ContentHash>();
            TimeSpan?minEffectiveAge = null;

            foreach (var contentHashInfo in distributedStore.GetHashesInEvictionOrder(_context, _contentHashesWithInfo))
            {
                if (StopPurging(out var stopReason, out var rule))
                {
                    _purgeResult.StopReason = stopReason;
                    break;
                }

                var contentHashWithLastAccessTimeAndReplicaCount = ToContentHashListWithLastAccessTimeAndReplicaCount(contentHashInfo);
                var evictionResult = await _quotaKeeper.EvictContentAsync(_context, contentHashWithLastAccessTimeAndReplicaCount, rule.GetOnlyUnlinked());

                if (!evictionResult)
                {
                    return(evictionResult);
                }

                if (evictionResult.SuccessfullyEvictedHash)
                {
                    evictedContent.Add(contentHashInfo.ContentHash);
                    minEffectiveAge = minEffectiveAge < contentHashInfo.EffectiveAge ? minEffectiveAge : contentHashInfo.EffectiveAge;
                }

                _purgeResult.Merge(evictionResult);
            }

            var unregisterResult = await distributedStore.UnregisterAsync(_context, evictedContent, _token, minEffectiveAge);

            if (!unregisterResult)
            {
                return(unregisterResult);
            }

            return(BoolResult.Success);
        }
        public TestFileSystemContentStoreInternal(
            IAbsFileSystem fileSystem,
            IClock clock,
            AbsolutePath rootPath,
            ContentStoreConfiguration configuration,
            Action <ContentHashWithSize> onContentAdded   = null,
            Action <ContentHashWithSize> onContentEvicted = null,
            ContentStoreSettings settings = null,
            IDistributedLocationStore distributedStore = null)
            : base(fileSystem, clock, rootPath, new ConfigurationModel(configuration), settings: settings, distributedStore: distributedStore)
        {
            Contract.Requires(fileSystem != null);
            Contract.Requires(clock != null);
            Contract.Requires(rootPath != null);
            Contract.Requires(configuration != null);

            _onContentAdded   = onContentAdded;
            _onContentEvicted = onContentEvicted;

            if (_onContentAdded != null || _onContentEvicted != null)
            {
                Announcer = this;
            }
        }
Пример #6
0
 public DistributedEvictionSettings(IDistributedLocationStore distributedStore)
 {
     DistributedStore = distributedStore;
 }
Пример #7
0
        public IContentStore CreateFileSystemContentStore(ResolvedNamedCacheSettings resolvedCacheSettings, IDistributedLocationStore distributedStore)
        {
            var contentStoreSettings = FromDistributedSettings(_distributedSettings);

            ConfigurationModel configurationModel
                = new ConfigurationModel(new ContentStoreConfiguration(new MaxSizeQuota(resolvedCacheSettings.Settings.CacheSizeQuotaString)));

            return(ContentStoreFactory.CreateContentStore(_fileSystem, resolvedCacheSettings.ResolvedCacheRootPath,
                                                          contentStoreSettings: contentStoreSettings, distributedStore: distributedStore, configurationModel: configurationModel));
        }
Пример #8
0
 private TestFileSystemContentStoreInternal CreateStore(DisposableDirectory testDirectory, ContentStoreSettings settings, IDistributedLocationStore distributedStore)
 {
     return(new TestFileSystemContentStoreInternal(FileSystem, Clock, testDirectory.Path, Config, distributedStore: distributedStore, settings: settings));
 }