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(); }
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)); }
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)); }
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)); }
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)); }
[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); }); })); }