Пример #1
0
        private static void WriteContentStoreConfigFile(string cacheSizeQuotaString, AbsolutePath rootPath, IAbsFileSystem fileSystem)
        {
            fileSystem.CreateDirectory(rootPath);

            var maxSizeQuota = new MaxSizeQuota(cacheSizeQuotaString);
            var casConfig    = new ContentStoreConfiguration(maxSizeQuota);

            casConfig.Write(fileSystem, rootPath).GetAwaiter().GetResult();
        }
Пример #2
0
        protected virtual TestFileSystemContentStoreInternal CreateElastic(
            AbsolutePath rootPath,
            ITestClock clock,
            MaxSizeQuota initialQuota = null,
            int?windowSize            = default(int?))
        {
            var maxSizeQuota = initialQuota ?? new MaxSizeQuota(MaxSizeHard, MaxSizeSoft);

            // Some tests rely on maxSizeQuota being set in the configuration although it is ignored if elasticity is enabled.
            var config = new ContentStoreConfiguration(maxSizeQuota: maxSizeQuota, enableElasticity: true, initialElasticSize: maxSizeQuota, historyWindowSize: windowSize);

            return(new TestFileSystemContentStoreInternal(FileSystem, clock, rootPath, config, settings: ContentStoreSettings));
        }
Пример #3
0
        protected override IQuotaRule CreateRule(long currentSize, EvictResult evictResult = null)
        {
            var root = new DisposableDirectory(FileSystem);
            Func <IQuotaRule> ruleFactory = () =>
            {
                var initialQuota = new MaxSizeQuota(Hard);
                return(new ElasticSizeRule(
                           ElasticSizeRule.DefaultHistoryWindowSize,
                           initialQuota,
                           () => currentSize,
                           windowSize => new PinSizeHistory.ReadHistoryResult(new long[0], DateTime.UtcNow.Ticks),
                           FileSystem,
                           root.Path));
            };

            return(new ForwardingQuotaRule(ruleFactory, root));
        }
Пример #4
0
        private ElasticSizeRule CreateElasticRule(
            AbsolutePath root,
            long initialHardLimit,
            Func <long> currentSizeFunc,
            Func <int, PinSizeHistory.ReadHistoryResult> readHistoryFunc,
            int windowSize = ElasticSizeRule.DefaultHistoryWindowSize,
            double calibrateCoefficient = ElasticSizeRule.DefaultCalibrationCoefficient)
        {
            var initialQuota = new MaxSizeQuota(initialHardLimit);

            return(new ElasticSizeRule(
                       windowSize,
                       initialQuota,
                       currentSizeFunc,
                       readHistoryFunc,
                       FileSystem,
                       root,
                       calibrateCoefficient));
        }
Пример #5
0
        private ElasticSizeRule CreateElasticRule(
            AbsolutePath root,
            long initialHardLimit,
            Func <long> currentSizeFunc,
            Func <int, PinSizeHistory.ReadHistoryResult> readHistoryFunc,
            int windowSize = ElasticSizeRule.DefaultHistoryWindowSize,
            double calibrateCoefficient = ElasticSizeRule.DefaultCalibrationCoefficient)
        {
            var initialQuota = new MaxSizeQuota(initialHardLimit);

            return(new ElasticSizeRule(
                       windowSize,
                       initialQuota,
                       (context, contentHashInfo, onlyUnlinked) => Task.FromResult(new EvictResult("error")),
                       currentSizeFunc,
                       readHistoryFunc,
                       FileSystem,
                       root,
                       calibrateCoefficient));
        }
Пример #6
0
        [Trait("Category", "QTestSkip")] // Skipped
        public Task TestQuotaCalibration()
        {
            var context = new Context(Logger);

            return(TestStore(context, _clock, async store =>
            {
                int totalSize = 0;

                // Add big content should trigger calibration.
                using (var pinContext = store.CreatePinContext())
                {
                    int size = 60;
                    using (var dataStream1 = RandomStream(size))
                        using (var dataStream2 = RandomStream(size))
                        {
                            await store.PutStreamAsync(context, dataStream1, ContentHashType, new PinRequest(pinContext)).ShouldBeSuccess();
                            _clock.Increment();

                            await store.PutStreamAsync(context, dataStream2, ContentHashType, new PinRequest(pinContext)).ShouldBeSuccess();
                            _clock.Increment();
                        }

                    totalSize += 2 * size;
                }

                MaxSizeQuota currentQuota = null;

                // Initial max = 100, total size = 120. Calibrate up.
                await VerifyQuota(context, store, quota =>
                {
                    currentQuota = quota;
                    Assert.True(quota.Hard > totalSize);
                    Assert.True(quota.Soft > totalSize);
                });

                // Add small content does not change quota.
                using (var pinContext = store.CreatePinContext())
                {
                    int size = 1;
                    using (var dataStream = RandomStream(size))
                    {
                        await store.PutStreamAsync(context, dataStream, ContentHashType, new PinRequest(pinContext)).ShouldBeSuccess();
                        _clock.Increment();
                    }

                    totalSize += size;
                }

                await VerifyQuota(context, store, quota =>
                {
                    Assert.Equal(currentQuota.Hard, quota.Hard);
                    Assert.Equal(currentQuota.Soft, quota.Soft);
                });

                // Add small content, but window is small. Calibrate down such that in the next reservation purging can run.
                using (var pinContext = store.CreatePinContext())
                {
                    int size = 1;
                    using (var dataStream = RandomStream(size))
                    {
                        await store.PutStreamAsync(context, dataStream, ContentHashType, new PinRequest(pinContext)).ShouldBeSuccess();
                        _clock.Increment();
                    }

                    totalSize += size;
                }

                await VerifyQuota(context, store, quota =>
                {
                    Assert.True(currentQuota.Hard > quota.Hard);
                    Assert.True(currentQuota.Soft > quota.Soft);
                    Assert.True(totalSize > quota.Soft && totalSize < quota.Hard);
                });
            }));
        }