Example #1
0
        public static QuotaKeeper Create(
            IAbsFileSystem fileSystem,
            ContentStoreInternalTracer tracer,
            CancellationToken token,
            IContentStoreInternal store,
            QuotaKeeperConfiguration configuration)
        {
            Contract.RequiresNotNull(fileSystem);
            Contract.RequiresNotNull(tracer);
            Contract.RequiresNotNull(configuration);

            return(new QuotaKeeper(fileSystem, tracer, configuration, token, store));
        }
Example #2
0
        /// <nodoc />
        public LegacyQuotaKeeper(
            IAbsFileSystem fileSystem,
            ContentStoreInternalTracer tracer,
            QuotaKeeperConfiguration configuration,
            CancellationToken token,
            IContentStoreInternal store)
            : base(configuration)
        {
            _tracer       = tracer;
            _size         = configuration.ContentDirectorySize;
            _token        = token;
            _store        = store;
            _reserveQueue = new BlockingCollection <Request <QuotaKeeperRequest, string> >();

            _rules = CreateRules(fileSystem, configuration, store);
        }
Example #3
0
        /// <nodoc />
        public static QuotaKeeper Create(
            IAbsFileSystem fileSystem,
            ContentStoreInternalTracer tracer,
            CancellationToken token,
            IContentStoreInternal store,
            QuotaKeeperConfiguration configuration)
        {
            Contract.Requires(fileSystem != null);
            Contract.Requires(tracer != null);
            Contract.Requires(configuration != null);

            if (configuration.UseLegacyQuotaKeeper)
            {
                return(new LegacyQuotaKeeper(fileSystem, tracer, configuration, token, store));
            }

            return(new QuotaKeeperV2(fileSystem, tracer, configuration, token, store));
        }
Example #4
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>();
 }
Example #5
0
 public QuotaKeeper(
     IAbsFileSystem fileSystem,
     ContentStoreInternalTracer tracer,
     QuotaKeeperConfiguration configuration,
     CancellationToken token,
     FileSystemContentStoreInternal store,
     IDistributedLocationStore?distributedStore)
 {
     _contentStoreTracer = tracer;
     Tracer            = new Tracer(name: $"{Component}({store.RootPath})");
     _allContentSize   = configuration.ContentDirectorySize;
     _token            = token;
     _store            = store;
     _distributedStore = distributedStore;
     _reserveQueue     = new BlockingCollection <QuotaRequest>();
     _evictionQueue    = new ConcurrentQueue <ReserveSpaceRequest>();
     _rules            = CreateRules(fileSystem, configuration, store);
     Counters          = new CounterCollection <QuotaKeeperCounters>();
 }
Example #6
0
        /// <nodoc />
        protected List <IQuotaRule> CreateRules(
            IAbsFileSystem fileSystem,
            QuotaKeeperConfiguration configuration,
            IContentStoreInternal store)
        {
            var rules = new List <IQuotaRule>();
            var distributedEvictionSettings = configuration.DistributedEvictionSettings;

            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);
        }
Example #7
0
 /// <nodoc />
 protected QuotaKeeper(QuotaKeeperConfiguration configuration)
 {
     PurgeAtStartup = configuration.StartPurgingAtStartup;
 }