public DistributedContentStore <AbsolutePath> CreateContentStore(ResolvedNamedCacheSettings resolvedSettings) { var contentStoreSettings = FromDistributedSettings(_distributedSettings); ConfigurationModel configurationModel = configurationModel = new ConfigurationModel(new ContentStoreConfiguration(new MaxSizeQuota(resolvedSettings.Settings.CacheSizeQuotaString))); _logger.Debug("Creating a distributed content store"); var contentStore = new DistributedContentStore <AbsolutePath>( resolvedSettings.MachineLocation, resolvedSettings.ResolvedCacheRootPath, (checkLocal, distributedStore) => ContentStoreFactory.CreateContentStore(_fileSystem, resolvedSettings.ResolvedCacheRootPath, contentStoreSettings: contentStoreSettings, distributedStore: distributedStore, configurationModel: configurationModel), _redisMemoizationStoreFactory.Value, _distributedContentStoreSettings, distributedCopier: _copier, clock: _arguments.Overrides.Clock, contentStoreSettings: contentStoreSettings); _logger.Debug("Created Distributed content store."); return(contentStore); }
public DistributedContentStore CreateDistributedContentStore( ResolvedNamedCacheSettings resolvedSettings, Func <IDistributedLocationStore, IContentStore> innerStoreFactory) { _logger.Debug("Creating a distributed content store"); var contentStore = new DistributedContentStore( resolvedSettings.MachineLocation, resolvedSettings.ResolvedCacheRootPath, distributedStore => innerStoreFactory(distributedStore), _redisMemoizationStoreFactory.Value, _distributedContentStoreSettings, distributedCopier: _copier, clock: _arguments.Overrides.Clock); _logger.Debug("Created Distributed content store."); return(contentStore); }
public DistributedContentStore <AbsolutePath> CreateContentStore(ResolvedNamedCacheSettings resolvedSettings) { var contentStoreSettings = FromDistributedSettings(_distributedSettings); _logger.Debug("Creating a distributed content store"); var contentStore = new DistributedContentStore <AbsolutePath>( resolvedSettings.MachineLocation, resolvedSettings.ResolvedCacheRootPath, (checkLocal, distributedStore) => CreateLocalContentStore(_distributedSettings, _arguments, resolvedSettings, distributedStore), _redisMemoizationStoreFactory.Value, _distributedContentStoreSettings, distributedCopier: _copier, clock: _arguments.Overrides.Clock, contentStoreSettings: contentStoreSettings); _logger.Debug("Created Distributed content store."); return(contentStore); }
/// <nodoc /> public DistributedContentSession( string name, IContentSession inner, IContentLocationStore contentLocationStore, DistributedContentCopier contentCopier, DistributedContentStore distributedStore, MachineLocation localMachineLocation, ColdStorage coldStorage, DistributedContentStoreSettings settings = default) : base( name, inner, contentLocationStore, contentCopier, distributedStore, localMachineLocation, coldStorage, settings) { }
public IContentStore CreateContentStore(AbsolutePath localCacheRoot) { var redisContentLocationStoreFactory = CreateRedisCacheFactory(localCacheRoot, out var redisContentLocationStoreConfiguration); var localMachineLocation = _arguments.PathTransformer.GetLocalMachineLocation(localCacheRoot); ReadOnlyDistributedContentSession <AbsolutePath> .ContentAvailabilityGuarantee contentAvailabilityGuarantee; if (string.IsNullOrEmpty(_distributedSettings.ContentAvailabilityGuarantee)) { contentAvailabilityGuarantee = ReadOnlyDistributedContentSession <AbsolutePath> .ContentAvailabilityGuarantee .FileRecordsExist; } else if (!Enum.TryParse(_distributedSettings.ContentAvailabilityGuarantee, true, out contentAvailabilityGuarantee)) { throw new ArgumentException($"Unable to parse {nameof(_distributedSettings.ContentAvailabilityGuarantee)}: [{_distributedSettings.ContentAvailabilityGuarantee}]"); } PinConfiguration pinConfiguration = null; if (_distributedSettings.IsPinBetterEnabled) { pinConfiguration = new PinConfiguration(); if (_distributedSettings.PinRisk.HasValue) { pinConfiguration.PinRisk = _distributedSettings.PinRisk.Value; } if (_distributedSettings.MachineRisk.HasValue) { pinConfiguration.MachineRisk = _distributedSettings.MachineRisk.Value; } if (_distributedSettings.FileRisk.HasValue) { pinConfiguration.FileRisk = _distributedSettings.FileRisk.Value; } if (_distributedSettings.MaxIOOperations.HasValue) { pinConfiguration.MaxIOOperations = _distributedSettings.MaxIOOperations.Value; } pinConfiguration.UsePinCache = _distributedSettings.IsPinCachingEnabled; if (_distributedSettings.PinCacheReplicaCreditRetentionMinutes.HasValue) { pinConfiguration.PinCacheReplicaCreditRetentionMinutes = _distributedSettings.PinCacheReplicaCreditRetentionMinutes.Value; } if (_distributedSettings.PinCacheReplicaCreditRetentionDecay.HasValue) { pinConfiguration.PinCacheReplicaCreditRetentionDecay = _distributedSettings.PinCacheReplicaCreditRetentionDecay.Value; } } var contentHashBumpTime = TimeSpan.FromMinutes(_distributedSettings.ContentHashBumpTimeMinutes); var lazyTouchContentHashBumpTime = _distributedSettings.IsTouchEnabled ? (TimeSpan?)contentHashBumpTime : null; if (redisContentLocationStoreConfiguration.ReadMode == ContentLocationMode.LocalLocationStore) { // LocalLocationStore has its own internal notion of lazy touch/registration. We disable the lazy touch in distributed content store // because it can conflict with behavior of the local location store. lazyTouchContentHashBumpTime = null; } var contentStoreSettings = FromDistributedSettings(_distributedSettings); ConfigurationModel configurationModel = null; if (_arguments.Configuration.LocalCasSettings.CacheSettingsByCacheName.TryGetValue(_arguments.Configuration.LocalCasSettings.CasClientSettings.DefaultCacheName, out var namedCacheSettings)) { configurationModel = new ConfigurationModel(new ContentStoreConfiguration(new MaxSizeQuota(namedCacheSettings.CacheSizeQuotaString))); } var bandwidthCheckedCopier = new BandwidthCheckedCopier(_arguments.Copier, BandwidthChecker.Configuration.FromDistributedContentSettings(_distributedSettings), _logger); _logger.Debug("Creating a distributed content store for Autopilot"); var contentStore = new DistributedContentStore <AbsolutePath>( localMachineLocation, (announcer, evictionSettings, checkLocal, trimBulk) => ContentStoreFactory.CreateContentStore(_fileSystem, localCacheRoot, announcer, distributedEvictionSettings: evictionSettings, contentStoreSettings: contentStoreSettings, trimBulkAsync: trimBulk, configurationModel: configurationModel), redisContentLocationStoreFactory, _arguments.Copier, bandwidthCheckedCopier, _arguments.PathTransformer, _arguments.CopyRequester, contentAvailabilityGuarantee, localCacheRoot, _fileSystem, _distributedSettings.RedisBatchPageSize, new DistributedContentStoreSettings() { UseTrustedHash = _distributedSettings.UseTrustedHash, CleanRandomFilesAtRoot = _distributedSettings.CleanRandomFilesAtRoot, TrustedHashFileSizeBoundary = _distributedSettings.TrustedHashFileSizeBoundary, ParallelHashingFileSizeBoundary = _distributedSettings.ParallelHashingFileSizeBoundary, MaxConcurrentCopyOperations = _distributedSettings.MaxConcurrentCopyOperations, PinConfiguration = pinConfiguration, EmptyFileHashShortcutEnabled = _distributedSettings.EmptyFileHashShortcutEnabled, RetryIntervalForCopies = _distributedSettings.RetryIntervalForCopies, MaxRetryCount = _distributedSettings.MaxRetryCount, TimeoutForProactiveCopies = TimeSpan.FromMinutes(_distributedSettings.TimeoutForProactiveCopiesMinutes), ProactiveCopyMode = (ProactiveCopyMode)Enum.Parse(typeof(ProactiveCopyMode), _distributedSettings.ProactiveCopyMode), MaxConcurrentProactiveCopyOperations = _distributedSettings.MaxConcurrentProactiveCopyOperations, ProactiveCopyLocationsThreshold = _distributedSettings.ProactiveCopyLocationsThreshold, MaximumConcurrentPutFileOperations = _distributedSettings.MaximumConcurrentPutFileOperations, }, replicaCreditInMinutes: _distributedSettings.IsDistributedEvictionEnabled?_distributedSettings.ReplicaCreditInMinutes: null, enableRepairHandling: _distributedSettings.IsRepairHandlingEnabled, contentHashBumpTime: lazyTouchContentHashBumpTime, contentStoreSettings: contentStoreSettings); _logger.Debug("Created Distributed content store."); return(contentStore); }
public IContentStore CreateContentStore( AbsolutePath localCacheRoot, NagleQueue <ContentHash> evictionAnnouncer = null, ProactiveReplicationArgs replicationSettings = null, DistributedEvictionSettings distributedEvictionSettings = null, bool checkLocalFiles = true, TrimBulkAsync trimBulkAsync = null) { var redisContentLocationStoreConfiguration = new RedisContentLocationStoreConfiguration { RedisBatchPageSize = _distributedSettings.RedisBatchPageSize, BlobExpiryTimeMinutes = _distributedSettings.BlobExpiryTimeMinutes, MaxBlobCapacity = _distributedSettings.MaxBlobCapacity, MaxBlobSize = _distributedSettings.MaxBlobSize, EvictionWindowSize = _distributedSettings.EvictionWindowSize }; ApplyIfNotNull(_distributedSettings.ReplicaCreditInMinutes, v => redisContentLocationStoreConfiguration.ContentLifetime = TimeSpan.FromMinutes(v)); ApplyIfNotNull(_distributedSettings.MachineRisk, v => redisContentLocationStoreConfiguration.MachineRisk = v); ApplyIfNotNull(_distributedSettings.LocationEntryExpiryMinutes, v => redisContentLocationStoreConfiguration.LocationEntryExpiry = TimeSpan.FromMinutes(v)); ApplyIfNotNull(_distributedSettings.MachineExpiryMinutes, v => redisContentLocationStoreConfiguration.MachineExpiry = TimeSpan.FromMinutes(v)); redisContentLocationStoreConfiguration.ReputationTrackerConfiguration.Enabled = _distributedSettings.IsMachineReputationEnabled; if (_distributedSettings.IsContentLocationDatabaseEnabled) { var dbConfig = new RocksDbContentLocationDatabaseConfiguration(localCacheRoot / "LocationDb") { StoreClusterState = _distributedSettings.StoreClusterStateInDatabase }; redisContentLocationStoreConfiguration.Database = dbConfig; if (_distributedSettings.ContentLocationDatabaseGcIntervalMinutes != null) { dbConfig.LocalDatabaseGarbageCollectionInterval = TimeSpan.FromMinutes(_distributedSettings.ContentLocationDatabaseGcIntervalMinutes.Value); } ApplyIfNotNull(_distributedSettings.ContentLocationDatabaseCacheEnabled, v => dbConfig.CacheEnabled = v); ApplyIfNotNull(_distributedSettings.ContentLocationDatabaseFlushDegreeOfParallelism, v => dbConfig.FlushDegreeOfParallelism = v); ApplyIfNotNull(_distributedSettings.ContentLocationDatabaseFlushSingleTransaction, v => dbConfig.FlushSingleTransaction = v); ApplyIfNotNull(_distributedSettings.ContentLocationDatabaseFlushPreservePercentInMemory, v => dbConfig.FlushPreservePercentInMemory = v); ApplyIfNotNull(_distributedSettings.ContentLocationDatabaseCacheMaximumUpdatesPerFlush, v => dbConfig.CacheMaximumUpdatesPerFlush = v); ApplyIfNotNull(_distributedSettings.ContentLocationDatabaseCacheFlushingMaximumInterval, v => dbConfig.CacheFlushingMaximumInterval = v); ApplySecretSettingsForLlsAsync(redisContentLocationStoreConfiguration, localCacheRoot).GetAwaiter().GetResult(); } if (_distributedSettings.IsRedisGarbageCollectionEnabled) { redisContentLocationStoreConfiguration.GarbageCollectionConfiguration = new RedisGarbageCollectionConfiguration() { MaximumEntryLastAccessTime = TimeSpan.FromMinutes(30) }; } else { redisContentLocationStoreConfiguration.GarbageCollectionConfiguration = null; } var localMachineLocation = _arguments.PathTransformer.GetLocalMachineLocation(localCacheRoot); var contentHashBumpTime = TimeSpan.FromMinutes(_distributedSettings.ContentHashBumpTimeMinutes); // RedisContentSecretName and RedisMachineLocationsSecretName can be null. HostConnectionStringProvider won't fail in this case. IConnectionStringProvider contentConnectionStringProvider = TryCreateRedisConnectionStringProvider(_redisContentSecretNames.RedisContentSecretName); IConnectionStringProvider machineLocationsConnectionStringProvider = TryCreateRedisConnectionStringProvider(_redisContentSecretNames.RedisMachineLocationsSecretName); var redisContentLocationStoreFactory = new RedisContentLocationStoreFactory( contentConnectionStringProvider, machineLocationsConnectionStringProvider, SystemClock.Instance, contentHashBumpTime, _keySpace, localMachineLocation, configuration: redisContentLocationStoreConfiguration ); ReadOnlyDistributedContentSession <AbsolutePath> .ContentAvailabilityGuarantee contentAvailabilityGuarantee; if (string.IsNullOrEmpty(_distributedSettings.ContentAvailabilityGuarantee)) { contentAvailabilityGuarantee = ReadOnlyDistributedContentSession <AbsolutePath> .ContentAvailabilityGuarantee .FileRecordsExist; } else if (!Enum.TryParse(_distributedSettings.ContentAvailabilityGuarantee, true, out contentAvailabilityGuarantee)) { throw new ArgumentException($"Unable to parse {nameof(_distributedSettings.ContentAvailabilityGuarantee)}: [{_distributedSettings.ContentAvailabilityGuarantee}]"); } PinConfiguration pinConfiguration = null; if (_distributedSettings.IsPinBetterEnabled) { pinConfiguration = new PinConfiguration(); if (_distributedSettings.PinRisk.HasValue) { pinConfiguration.PinRisk = _distributedSettings.PinRisk.Value; } if (_distributedSettings.MachineRisk.HasValue) { pinConfiguration.MachineRisk = _distributedSettings.MachineRisk.Value; } if (_distributedSettings.FileRisk.HasValue) { pinConfiguration.FileRisk = _distributedSettings.FileRisk.Value; } if (_distributedSettings.MaxIOOperations.HasValue) { pinConfiguration.MaxIOOperations = _distributedSettings.MaxIOOperations.Value; } pinConfiguration.UsePinCache = _distributedSettings.IsPinCachingEnabled; if (_distributedSettings.PinCacheReplicaCreditRetentionMinutes.HasValue) { pinConfiguration.PinCacheReplicaCreditRetentionMinutes = _distributedSettings.PinCacheReplicaCreditRetentionMinutes.Value; } if (_distributedSettings.PinCacheReplicaCreditRetentionDecay.HasValue) { pinConfiguration.PinCacheReplicaCreditRetentionDecay = _distributedSettings.PinCacheReplicaCreditRetentionDecay.Value; } } var lazyTouchContentHashBumpTime = _distributedSettings.IsTouchEnabled ? (TimeSpan?)contentHashBumpTime : null; if (redisContentLocationStoreConfiguration.ReadMode == ContentLocationMode.LocalLocationStore) { // LocalLocationStore has its own internal notion of lazy touch/registration. We disable the lazy touch in distributed content store // because it can conflict with behavior of the local location store. lazyTouchContentHashBumpTime = null; } var contentStoreSettings = FromDistributedSettings(_distributedSettings); ConfigurationModel configurationModel = null; if (_arguments.Configuration.LocalCasSettings.CacheSettingsByCacheName.TryGetValue(_arguments.Configuration.LocalCasSettings.CasClientSettings.DefaultCacheName, out var namedCacheSettings)) { configurationModel = new ConfigurationModel(new ContentStoreConfiguration(new MaxSizeQuota(namedCacheSettings.CacheSizeQuotaString))); } _logger.Debug("Creating a distributed content store for Autopilot"); var contentStore = new DistributedContentStore <AbsolutePath>( localMachineLocation, (announcer, evictionSettings, checkLocal, trimBulk) => ContentStoreFactory.CreateContentStore(_fileSystem, localCacheRoot, announcer, distributedEvictionSettings: evictionSettings, contentStoreSettings: contentStoreSettings, trimBulkAsync: trimBulk, configurationModel: configurationModel), redisContentLocationStoreFactory, _arguments.Copier, _arguments.Copier, _arguments.PathTransformer, contentAvailabilityGuarantee, localCacheRoot, _fileSystem, _distributedSettings.RedisBatchPageSize, new DistributedContentStoreSettings() { UseTrustedHash = _distributedSettings.UseTrustedHash, CleanRandomFilesAtRoot = _distributedSettings.CleanRandomFilesAtRoot, TrustedHashFileSizeBoundary = _distributedSettings.TrustedHashFileSizeBoundary, ParallelHashingFileSizeBoundary = _distributedSettings.ParallelHashingFileSizeBoundary, MaxConcurrentCopyOperations = _distributedSettings.MaxConcurrentCopyOperations, PinConfiguration = pinConfiguration, EmptyFileHashShortcutEnabled = _distributedSettings.EmptyFileHashShortcutEnabled, RetryIntervalForCopies = _distributedSettings.RetryIntervalForCopies, }, replicaCreditInMinutes: _distributedSettings.IsDistributedEvictionEnabled?_distributedSettings.ReplicaCreditInMinutes: null, enableRepairHandling: _distributedSettings.IsRepairHandlingEnabled, contentHashBumpTime: lazyTouchContentHashBumpTime, contentStoreSettings: contentStoreSettings); _logger.Debug("Created Distributed content store."); return(contentStore); }
/// <nodoc /> public DistributedOneLevelCache(IContentStore contentStore, DistributedContentStore <AbsolutePath> distributedContentStore, Guid id, bool passContentToMemoization = true) : base(id, passContentToMemoization) { ContentStore = contentStore; _distributedContentStore = distributedContentStore; }
protected override IContentStore CreateStore( Context context, TestFileCopier fileCopier, DisposableDirectory testDirectory, int index, bool enableDistributedEviction, int?replicaCreditInMinutes, bool enableRepairHandling, object additionalArgs) { var rootPath = testDirectory.Path / "Root"; var tempPath = testDirectory.Path / "Temp"; var configurationModel = new ConfigurationModel(Config); var pathTransformer = new TestPathTransformer(); var localMachineData = pathTransformer.GetLocalMachineLocation(rootPath); if (!_localDatabases.TryGetValue(context.Id, out var localDatabase)) { localDatabase = LocalRedisProcessDatabase.CreateAndStartEmpty(_redis, TestGlobal.Logger, SystemClock.Instance); _localDatabases.TryAdd(context.Id, localDatabase); } if (!_localMachineDatabases.TryGetValue(context.Id, out var localMachineDatabase)) { localMachineDatabase = LocalRedisProcessDatabase.CreateAndStartEmpty(_redis, TestGlobal.Logger, SystemClock.Instance); _localMachineDatabases.TryAdd(context.Id, localMachineDatabase); } if (enableDistributedEviction && replicaCreditInMinutes == null) { // Apparently, replicaCreditInMinutes != null enables distributed eviction, // so make sure replicaCreditInMinutes is set when enableDistributedEviction is // true replicaCreditInMinutes = 0; } _configuration = CreateContentLocationStoreConfiguration?.Invoke(rootPath, index) ?? new RedisContentLocationStoreConfiguration(); _configuration.BlobExpiryTimeMinutes = 10; PostProcessConfiguration(_configuration, index); var storeFactory = new MockRedisContentLocationStoreFactory( localDatabase, localMachineDatabase, rootPath, mockClock: TestClock, _configuration); var distributedContentStore = new DistributedContentStore <AbsolutePath>( localMachineData, (nagleBlock, distributedEvictionSettings, contentStoreSettings, trimBulkAsync) => new FileSystemContentStore( FileSystem, TestClock, rootPath, configurationModel, nagleQueue: nagleBlock, distributedEvictionSettings: distributedEvictionSettings, settings: contentStoreSettings, trimBulkAsync: trimBulkAsync), storeFactory, fileCopier, fileCopier, pathTransformer, fileCopier, ContentAvailabilityGuarantee, tempPath, FileSystem, RedisContentLocationStoreConstants.DefaultBatchSize, settings: new DistributedContentStoreSettings { RetryIntervalForCopies = DistributedContentSessionTests.DefaultRetryIntervalsForTest, PinConfiguration = PinConfiguration, ShouldInlinePutBlob = true, }, replicaCreditInMinutes: replicaCreditInMinutes, clock: TestClock, enableRepairHandling: enableRepairHandling, contentStoreSettings: new ContentStoreSettings() { CheckFiles = true, }, setPostInitializationCompletionAfterStartup: true); distributedContentStore.DisposeContentStoreFactory = false; return(distributedContentStore); }