示例#1
0
 /// <summary>
 /// Backward-compat constructor.
 /// </summary>
 public FileSystemContentStore(
     IAbsFileSystem fileSystem,
     IClock clock,
     AbsolutePath rootPath,
     ConfigurationModel configurationModel = null,
     NagleQueue <ContentHash> nagleQueue   = null,
     DistributedEvictionSettings distributedEvictionSettings = null,
     TrimBulkAsync trimBulkAsync   = null,
     ContentStoreSettings settings = null)
     : this(fileSystem, clock, rootPath, configurationModel, distributedEvictionSettings?.DistributedStore, settings)
 {
 }
示例#2
0
 public Purger(
     Context context,
     QuotaKeeper quotaKeeper,
     DistributedEvictionSettings distributedEvictionSettings,
     IReadOnlyList <ContentHashWithLastAccessTimeAndReplicaCount> contentHashesWithInfo,
     PurgeResult purgeResult,
     CancellationToken token)
 {
     _distributedEvictionSettings = distributedEvictionSettings;
     _context               = context;
     _quotaKeeper           = quotaKeeper;
     _contentHashesWithInfo = contentHashesWithInfo;
     _purgeResult           = purgeResult;
     _token = token;
 }
示例#3
0
        /// <nodoc />
        public LegacyQuotaKeeper(
            IAbsFileSystem fileSystem,
            ContentStoreInternalTracer tracer,
            ContentStoreConfiguration configuration,
            long startSize,
            CancellationToken token,
            IContentStoreInternal store,
            DistributedEvictionSettings distributedEvictionSettings = null)
        {
            _tracer       = tracer;
            _size         = startSize;
            _token        = token;
            _store        = store;
            _reserveQueue = new BlockingCollection <Request <QuotaKeeperRequest, string> >();

            _rules = CreateRules(fileSystem, configuration, store, distributedEvictionSettings);
        }
示例#4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="DiskFreePercentRule"/> class.
        /// </summary>
        public DiskFreePercentRule(
            DiskFreePercentQuota quota,
            EvictAsync evictAsync,
            IAbsFileSystem fileSystem,
            AbsolutePath rootPath,
            DistributedEvictionSettings distributedEvictionSettings = null)
            : base(evictAsync, OnlyUnlinkedValue, distributedEvictionSettings)
        {
            Contract.Requires(quota != null);
            Contract.Requires(evictAsync != null);
            Contract.Requires(fileSystem != null);
            Contract.Requires(rootPath != null);

            _quota      = quota;
            _fileSystem = fileSystem;
            _rootPath   = rootPath;
        }
示例#5
0
        /// <nodoc />
        public static QuotaKeeperConfiguration Create(
            ContentStoreConfiguration configuration,
            DistributedEvictionSettings evictionSettings,
            long contentDirectorySize)
        {
            Contract.Requires(configuration != null);

            return(new QuotaKeeperConfiguration()
            {
                EnableElasticity = configuration.EnableElasticity,
                MaxSizeQuota = configuration.MaxSizeQuota,
                DiskFreePercentQuota = configuration.DiskFreePercentQuota,
                InitialElasticSize = configuration.InitialElasticSize,
                HistoryWindowSize = configuration.HistoryWindowSize,
                DistributedEvictionSettings = evictionSettings,
                ContentDirectorySize = contentDirectorySize,
            });
        }
示例#6
0
 public QuotaKeeper(
     IAbsFileSystem fileSystem,
     ContentStoreInternalTracer tracer,
     QuotaKeeperConfiguration configuration,
     CancellationToken token,
     IContentStoreInternal store)
 {
     _contentStoreTracer = tracer;
     _tracer             = new Tracer(name: Component);
     _allContentSize     = configuration.ContentDirectorySize;
     _token         = token;
     _store         = store;
     _reserveQueue  = new BlockingCollection <QuotaRequest>();
     _evictionQueue = new ConcurrentQueue <ReserveSpaceRequest>();
     _distributedEvictionSettings = configuration.DistributedEvictionSettings;
     _rules   = CreateRules(fileSystem, configuration, store);
     Counters = new CounterCollection <QuotaKeeperCounters>();
 }
示例#7
0
        /// <nodoc />
        protected List <IQuotaRule> CreateRules(
            IAbsFileSystem fileSystem,
            ContentStoreConfiguration configuration,
            IContentStoreInternal store,
            DistributedEvictionSettings distributedEvictionSettings)
        {
            var rules = new List <IQuotaRule>();

            if (configuration.EnableElasticity)
            {
                var elasticSizeRule = new ElasticSizeRule(
                    configuration.HistoryWindowSize,
                    configuration.InitialElasticSize,
                    EvictContentAsync,
                    () => CurrentSize,
                    store.ReadPinSizeHistory,
                    fileSystem,
                    store.RootPath,
                    distributedEvictionSettings: distributedEvictionSettings);
                rules.Add(elasticSizeRule);
            }
            else
            {
                if (configuration.MaxSizeQuota != null)
                {
                    rules.Add(new MaxSizeRule(configuration.MaxSizeQuota, EvictContentAsync, () => CurrentSize, distributedEvictionSettings));
                }

                if (configuration.DiskFreePercentQuota != null)
                {
                    rules.Add(new DiskFreePercentRule(configuration.DiskFreePercentQuota, EvictContentAsync, fileSystem, store.RootPath, distributedEvictionSettings));
                }
            }

            if (!rules.Any())
            {
                throw new CacheException("At least one quota rule must be defined");
            }

            return(rules);
        }
示例#8
0
 /// <summary>
 /// Backward-compat constructor.
 /// </summary>
 public FileSystemContentStore(
     IAbsFileSystem fileSystem,
     IClock clock,
     AbsolutePath rootPath,
     ConfigurationModel configurationModel,
     NagleQueue <ContentHash> nagleQueue,
     RefCountdown sensitiveSessionCount,
     DistributedEvictionSettings distributedEvictionSettings,
     bool checkFiles,
     TrimBulkAsync trimBulkAsync)
     : this(
         fileSystem,
         clock,
         rootPath,
         configurationModel,
         nagleQueue,
         distributedEvictionSettings,
         trimBulkAsync,
         settings : new ContentStoreSettings() { CheckFiles = checkFiles })
 {
 }
示例#9
0
        /// <nodoc />
        public static QuotaKeeper Create(
            IAbsFileSystem fileSystem,
            ContentStoreInternalTracer tracer,
            ContentStoreConfiguration configuration,
            long startSize,
            CancellationToken token,
            IContentStoreInternal store,
            DistributedEvictionSettings distributedEvictionSettings = null,
            bool useLegacyQuotaKeeper = false)
        {
            Contract.Requires(fileSystem != null);
            Contract.Requires(tracer != null);
            Contract.Requires(configuration != null);

            if (useLegacyQuotaKeeper)
            {
                return(new LegacyQuotaKeeper(fileSystem, tracer, configuration, startSize, token, store, distributedEvictionSettings));
            }

            return(new QuotaKeeperV2(fileSystem, tracer, configuration, startSize, token, store, distributedEvictionSettings));
        }
示例#10
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ElasticSizeRule" /> class.
        /// </summary>
        public ElasticSizeRule(
            int?historyWindowSize,
            MaxSizeQuota initialElasticSize,
            EvictAsync evictAsync,
            Func <long> getCurrentSizeFunc,
            Func <int, PinSizeHistory.ReadHistoryResult> getPinnedSizeHistoryFunc,
            IAbsFileSystem fileSystem,
            AbsolutePath rootPath,
            double?calibrationCoefficient = default(double?),
            DistributedEvictionSettings distributedEvictionSettings = null)
            : base(evictAsync, OnlyUnlinkedValue, distributedEvictionSettings)
        {
            Contract.Requires(!historyWindowSize.HasValue || historyWindowSize.Value >= 0);
            Contract.Requires(evictAsync != null);
            Contract.Requires(getCurrentSizeFunc != null);
            Contract.Requires(getPinnedSizeHistoryFunc != null);
            Contract.Requires(fileSystem != null);
            Contract.Requires(rootPath != null);
            Contract.Requires(!calibrationCoefficient.HasValue || calibrationCoefficient.Value > 1.0);

            _historyWindowSize        = historyWindowSize ?? DefaultHistoryWindowSize;
            _calibrationCoefficient   = calibrationCoefficient ?? DefaultCalibrationCoefficient;
            _getPinnedSizeHistoryFunc = getPinnedSizeHistoryFunc;
            _getCurrentSizeFunc       = getCurrentSizeFunc;
            _fileSystem   = fileSystem;
            _rootPath     = rootPath;
            _initialQuota = initialElasticSize ?? SmallQuota;

            var loadQuotaResult = LoadOrCreateNewAsync(_fileSystem, _initialQuota, _rootPath).GetAwaiter().GetResult();

            _quota = loadQuotaResult.Quota;
            _historyTimestampInTick = loadQuotaResult.HistoryTimestampInTick;

            // TODO: CalibrateAsync method fails in tests all the time. Bug #1331905
            CalibrateAsync().GetAwaiter().GetResult().IgnoreFailure();
            Contract.Assert(IsInsideHardLimit(0, checkIfQuotaEnabled: false).Succeeded);
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="FileSystemContentStore" /> class.
        /// </summary>
        public FileSystemContentStore(
            IAbsFileSystem fileSystem,
            IClock clock,
            AbsolutePath rootPath,
            ConfigurationModel configurationModel = null,
            NagleQueue <ContentHash> nagleQueue   = null,
            DistributedEvictionSettings distributedEvictionSettings = null,
            TrimBulkAsync trimBulkAsync   = null,
            ContentStoreSettings settings = null)
        {
            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,
                nagleQueue,
                distributedEvictionSettings,
                settings);

            _trimBulkAsync = trimBulkAsync;
        }
示例#12
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="MaxSizeRule"/> class.
        /// </summary>
        public MaxSizeRule(MaxSizeQuota quota, EvictAsync evictAsync, Func <long> getCurrentSizeFunc, DistributedEvictionSettings distributedEvictionSettings = null)
            : base(evictAsync, OnlyUnlinkedValue, distributedEvictionSettings)
        {
            Contract.Requires(quota != null);
            Contract.Requires(evictAsync != null);
            Contract.Requires(getCurrentSizeFunc != null);

            _quota = quota;
            _getCurrentSizeFunc = getCurrentSizeFunc;
        }
示例#13
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="QuotaRule" /> class.
 /// </summary>
 protected QuotaRule(EvictAsync evictAsync, bool onlyUnlinked, DistributedEvictionSettings distributedEvictionSettings = null)
 {
     _distributedEvictionSettings = distributedEvictionSettings;
     _evictAsync  = evictAsync;
     OnlyUnlinked = onlyUnlinked;
 }