protected async Task RunTestAsync(Func <OperationContext, ColdStorage, DisposableDirectory, Task> funcAsync) { var context = new OperationContext(new Context(Logger)); var directory = new DisposableDirectory(FileSystem); ColdStorageSettings coldStorageSettings = new ColdStorageSettings(directory.Path.Path, "1MB"); TestDistributedContentCopier copier = DistributedContentCopierTests.CreateMocks( new MemoryFileSystem(TestSystemClock.Instance), directory.CreateRandomFileName(), TimeSpan.FromSeconds(1)).Item1; var store = new ColdStorage(FileSystem, coldStorageSettings, copier); try { Assert.False(store.StartupStarted); Assert.False(store.StartupCompleted); Assert.False(store.ShutdownStarted); Assert.False(store.ShutdownCompleted); await store.StartupAsync(context).ShouldBeSuccess(); await funcAsync(context, store, directory); } finally { await store.ShutdownAsync(context).ShouldBeSuccess(); } Assert.True(store.StartupStarted); Assert.True(store.StartupCompleted); Assert.True(store.ShutdownStarted); Assert.True(store.ShutdownCompleted); }
public ColdStorage(IAbsFileSystem fileSystem, ColdStorageSettings coldStorageSettings, DistributedContentCopier distributedContentCopier) { _fileSystem = fileSystem; _copier = distributedContentCopier; _rootPath = coldStorageSettings.GetAbsoulutePath(); ConfigurationModel configurationModel = new ConfigurationModel(new ContentStoreConfiguration(new MaxSizeQuota(coldStorageSettings.CacheSizeQuotaString !))); ContentStoreSettings contentStoreSettings = FromColdStorageSettings(coldStorageSettings); _store = new FileSystemContentStore(fileSystem, SystemClock.Instance, _rootPath, configurationModel, null, contentStoreSettings, null); HashType hashType; if (!Enum.TryParse <HashType>(coldStorageSettings.ConsistentHashingHashType, true, out hashType)) { hashType = HashType.SHA256; } _contentHasher = HashInfoLookup.GetContentHasher(hashType); _copiesQuantity = coldStorageSettings.ConsistentHashingCopiesQuantity; _maxParallelPlaces = coldStorageSettings.MaxParallelPlaces; // Starts empty and is created during the first update _ring = new RingNode[0]; }
private static SelfCheckSettings CreateSelfCheckSettings(ColdStorageSettings settings) { var selfCheckSettings = new SelfCheckSettings() { Epoch = settings.SelfCheckEpoch, StartSelfCheckInStartup = settings.StartSelfCheckAtStartup, Frequency = TimeSpan.FromMinutes(settings.SelfCheckFrequencyInMinutes), }; ApplyIfNotNull(settings.SelfCheckProgressReportingIntervalInMinutes, minutes => selfCheckSettings.ProgressReportingInterval = TimeSpan.FromMinutes(minutes)); ApplyIfNotNull(settings.SelfCheckDelayInMilliseconds, milliseconds => selfCheckSettings.HashAnalysisDelay = TimeSpan.FromMilliseconds(milliseconds)); ApplyIfNotNull(settings.SelfCheckDefaultHddDelayInMilliseconds, milliseconds => selfCheckSettings.DefaultHddHashAnalysisDelay = TimeSpan.FromMilliseconds(milliseconds)); return(selfCheckSettings); }
private static ContentStoreSettings FromColdStorageSettings(ColdStorageSettings settings) { var result = new ContentStoreSettings() { CheckFiles = settings.CheckLocalFiles, SelfCheckSettings = CreateSelfCheckSettings(settings), OverrideUnixFileAccessMode = settings.OverrideUnixFileAccessMode, UseRedundantPutFileShortcut = settings.UseRedundantPutFileShortcut, TraceFileSystemContentStoreDiagnosticMessages = settings.TraceFileSystemContentStoreDiagnosticMessages, SkipTouchAndLockAcquisitionWhenPinningFromHibernation = settings.UseFastHibernationPin, }; ApplyIfNotNull(settings.SilentOperationDurationThreshold, v => result.SilentOperationDurationThreshold = TimeSpan.FromSeconds(v)); ApplyIfNotNull(settings.SilentOperationDurationThreshold, v => DefaultTracingConfiguration.DefaultSilentOperationDurationThreshold = TimeSpan.FromSeconds(v)); ApplyIfNotNull(settings.DefaultPendingOperationTracingIntervalInMinutes, v => DefaultTracingConfiguration.DefaultPendingOperationTracingInterval = TimeSpan.FromMinutes(v)); ApplyIfNotNull(settings.ReserveSpaceTimeoutInMinutes, v => result.ReserveTimeout = TimeSpan.FromMinutes(v)); ApplyIfNotNull(settings.UseAsynchronousFileStreamOptionByDefault, v => FileSystemDefaults.UseAsynchronousFileStreamOptionByDefault = v); ApplyIfNotNull(settings.UseHierarchicalTraceIds, v => Context.UseHierarchicalIds = v); return(result); }