/// <summary> /// Trace that the service is starting. /// </summary> public static void ServiceStarting( Context context, TimeSpan?serviceRunningLogInterval, AbsolutePath logFilePath, string?serviceName = null, IClock?clock = null, DateTime?processStartupTime = null) { var operationContext = new OperationContext(context); ServiceRunningTrackerResult = ServiceOfflineDurationTracker.Create( operationContext, SystemClock.Instance, new PassThroughFileSystem(), serviceRunningLogInterval, logFilePath, serviceName); var offlineTime = ServiceRunningTrackerResult.Then(r => r.GetLastServiceHeartbeatTime(operationContext)); LifetimeTrackerHelper = Tracing.LifetimeTrackerHelper.Starting(clock.GetUtcNow(), processStartupTime ?? GetProcessStartupTimeUtc(), offlineTime.Then(v => Result.Success(v.lastServiceHeartbeatTime))); var runtime = OperatingSystemHelper.GetRuntimeFrameworkNameAndVersion(); Trace(context, $"Starting CaSaaS instance. Runtime={runtime}{offlineTime.ToStringSelect(r => $". LastHeartBeatTime={r.lastServiceHeartbeatTime}, ShutdownCorrectly={r.shutdownCorrectly}")}"); }
protected override BoolResult SaveCheckpointCore(OperationContext context, AbsolutePath checkpointDirectory) { try { if (IsStoredEpochInvalid(out var storedEpoch)) { SetGlobalEntry(nameof(GlobalKeys.StoredEpoch), _configuration.Epoch); Tracer.Info(context.TracingContext, $"Updated stored epoch from '{storedEpoch}' to '{_configuration.Epoch}'."); } var targetDirectory = checkpointDirectory.ToString(); Tracer.Info(context.TracingContext, $"Saving content location database checkpoint to '{targetDirectory}'."); if (Directory.Exists(targetDirectory)) { FileUtilities.DeleteDirectoryContents(targetDirectory, deleteRootDirectory: true); } return(_keyValueStore.Use(store => store.SaveCheckpoint(targetDirectory)).ToBoolResult()); } catch (Exception ex) when(ex.IsRecoverableIoException()) { return(new BoolResult(ex, "Save checkpoint failed.")); } }
private static LocalCache CreateLocalCacheWithSingleCas(Config config, DisposeLogger logger) { LocalCacheConfiguration localCacheConfiguration; if (config.EnableContentServer) { localCacheConfiguration = LocalCacheConfiguration.CreateServerEnabled( config.GrpcPort, config.CacheName, config.ScenarioName, config.RetryIntervalSeconds, config.RetryCount); } else { localCacheConfiguration = LocalCacheConfiguration.CreateServerDisabled(); } var configCore = GetCasConfig(config); var configurationModel = CreateConfigurationModel(configCore); var cacheRoot = new AbsolutePath(config.CacheRootPath); var memoConfig = GetMemoizationStoreConfiguration(cacheRoot, config, configCore); return(new LocalCache( logger, cacheRoot, memoConfig, localCacheConfiguration, configurationModel: configurationModel, clock: null, checkLocalFiles: config.CheckLocalFiles, emptyFileHashShortcutEnabled: config.EmptyFileHashShortcutEnabled)); }
private static MemoizationStoreAdapterCache CreateCache(Config cacheConfig, AbsolutePath logPath, ILogger logger) { ServiceClientRpcConfiguration rpcConfiguration; if (cacheConfig.GrpcPort != 0) { rpcConfiguration = new ServiceClientRpcConfiguration((int)cacheConfig.GrpcPort); } else { var factory = new MemoryMappedFileGrpcPortSharingFactory(logger, cacheConfig.GrpcPortFileName); var portReader = factory.GetPortReader(); var port = portReader.ReadPort(); rpcConfiguration = new ServiceClientRpcConfiguration(port); } var serviceClientConfiguration = new ServiceClientContentStoreConfiguration(cacheConfig.CacheName, rpcConfiguration, cacheConfig.ScenarioName) { RetryCount = cacheConfig.ConnectionRetryCount, RetryIntervalSeconds = cacheConfig.ConnectionRetryIntervalSeconds, TraceOperationStarted = cacheConfig.GrpcTraceOperationStarted, }; MemoizationStore.Interfaces.Caches.ICache localCache; if (cacheConfig.EnableMetadataServer) { localCache = LocalCache.CreateRpcCache(logger, serviceClientConfiguration); } else { var metadataRootPath = new AbsolutePath(cacheConfig.MetadataRootPath); localCache = LocalCache.CreateRpcContentStoreInProcMemoizationStoreCache(logger, metadataRootPath, serviceClientConfiguration, CreateInProcMemoizationStoreConfiguration(cacheConfig, metadataRootPath)); } var statsFilePath = new AbsolutePath(logPath.Path + ".stats"); if (!string.IsNullOrEmpty(cacheConfig.VfsCasRoot)) { logger.Debug($"Creating virtualized cache"); localCache = new VirtualizedContentCache(localCache, new ContentStore.Vfs.VfsCasConfiguration.Builder() { RootPath = new AbsolutePath(cacheConfig.VfsCasRoot), UseSymlinks = cacheConfig.UseVfsSymlinks }.Build()); } var cache = new MemoizationStoreAdapterCache(cacheConfig.CacheId, localCache, logger, statsFilePath, cacheConfig.ReplaceExistingOnPlaceFile); return(cache); }
private static LocalCache CreateLocalCacheWithSingleCas(Config config, DisposeLogger logger) { var configCore = GetCasConfig(config); var configurationModel = CreateConfigurationModel(configCore); var cacheRoot = new AbsolutePath(config.CacheRootPath); var memoConfig = GetMemoConfig(cacheRoot, config, configCore); return(new LocalCache( logger, cacheRoot, memoConfig, configurationModel)); }
private static SQLiteMemoizationStoreConfiguration GetMemoConfig(AbsolutePath cacheRoot, Config config, CasConfig configCore) { var memoConfig = new SQLiteMemoizationStoreConfiguration(cacheRoot) { MaxRowCount = config.MaxStrongFingerprints, BackupDatabase = config.BackupLKGCache, VerifyIntegrityOnStartup = config.CheckCacheIntegrityOnStartup, SingleInstanceTimeoutSeconds = (int)configCore.SingleInstanceTimeoutInSeconds, WaitForLruOnShutdown = WaitForLruOnShutdown }; if (!string.IsNullOrEmpty(config.SynchronizationMode)) { memoConfig.SyncMode = (SynchronizationMode)Enum.Parse(typeof(SynchronizationMode), config.SynchronizationMode, ignoreCase: true); } return(memoConfig); }
private static MemoizationStoreAdapterCache CreateCache(Config cacheConfig, AbsolutePath logPath, ILogger logger) { ServiceClientRpcConfiguration rpcConfiguration; if (cacheConfig.GrpcPort != 0) { rpcConfiguration = new ServiceClientRpcConfiguration((int)cacheConfig.GrpcPort); } else { var factory = new MemoryMappedFileGrpcPortSharingFactory(logger, cacheConfig.GrpcPortFileName); var portReader = factory.GetPortReader(); var port = portReader.ReadPort(); rpcConfiguration = new ServiceClientRpcConfiguration(port); } var serviceClientConfiguration = new ServiceClientContentStoreConfiguration(cacheConfig.CacheName, rpcConfiguration, cacheConfig.ScenarioName) { RetryCount = cacheConfig.ConnectionRetryCount, RetryIntervalSeconds = cacheConfig.ConnectionRetryIntervalSeconds, }; MemoizationStore.Interfaces.Caches.ICache localCache; if (cacheConfig.EnableMetadataServer) { localCache = LocalCache.CreateRpcCache(logger, serviceClientConfiguration); } else { var metadataRootPath = new AbsolutePath(cacheConfig.MetadataRootPath); localCache = LocalCache.CreateRpcContentStoreInProcMemoizationStoreCache(logger, metadataRootPath, serviceClientConfiguration, CreateInProcMemoizationStoreConfiguration(cacheConfig, metadataRootPath)); } var statsFilePath = new AbsolutePath(logPath.Path + ".stats"); var cache = new MemoizationStoreAdapterCache(cacheConfig.CacheId, localCache, logger, statsFilePath, cacheConfig.ReplaceExistingOnPlaceFile); return(cache); }
/// <inheritdoc /> protected override BoolResult SaveCheckpointCore(OperationContext context, AbsolutePath checkpointDirectory) { try { var targetDirectory = checkpointDirectory.ToString(); Tracer.Info(context.TracingContext, $"Saving content location database checkpoint to '{targetDirectory}'."); if (Directory.Exists(targetDirectory)) { FileUtilities.DeleteDirectoryContents(targetDirectory, deleteRootDirectory: true); } return(_keyValueStore.Use(store => store.SaveCheckpoint(targetDirectory)).ToBoolResult()); } catch (Exception ex) when(ex.IsRecoverableIoException()) { return(new BoolResult(ex, "Save checkpoint failed.")); } }
/// <inheritdoc /> public async Task <Possible <ICache, Failure> > InitializeCacheAsync(ICacheConfigData cacheData, Guid activityId, ICacheConfiguration cacheConfiguration = null) { Contract.Requires(cacheData != null); var possibleCacheConfig = cacheData.Create <Config>(); if (!possibleCacheConfig.Succeeded) { return(possibleCacheConfig.Failure); } Config cacheConfig = possibleCacheConfig.Result; try { var logPath = new AbsolutePath(cacheConfig.CacheLogPath); var logger = new DisposeLogger(() => new EtwFileLog(logPath.Path, cacheConfig.CacheId), cacheConfig.LogFlushIntervalSeconds); var distributedCache = CreateDistributedCache(logger, cacheConfig); logger.Debug($"Distributed cache created successfully."); var statsFilePath = new AbsolutePath(logPath.Path + ".stats"); var cache = new MemoizationStoreAdapterCache(cacheConfig.CacheId, distributedCache, logger, statsFilePath, implicitPin: cacheConfig.ImplicitPin); logger.Diagnostic($"Initializing the cache [{cacheConfig.CacheId}]"); var startupResult = await cache.StartupAsync(); if (!startupResult.Succeeded) { logger.Error($"Error while initializing the cache [{cacheConfig.CacheId}]. Failure: {startupResult.Failure}"); cache.Dispose(); return(startupResult.Failure); } return(cache); } catch (Exception e) { return(new CacheConstructionFailure(cacheConfig.CacheId, e)); } }
/// <inheritdoc /> public async Task <Possible <ICache, Failure> > InitializeCacheAsync(ICacheConfigData cacheData, Guid activityId, ICacheConfiguration cacheConfiguration = null) { Contract.Requires(cacheData != null); var possibleCacheConfig = cacheData.Create <Config>(); if (!possibleCacheConfig.Succeeded) { return(possibleCacheConfig.Failure); } Config cacheConfig = possibleCacheConfig.Result; try { Contract.Assert(cacheConfig.CacheName != null); var logPath = new AbsolutePath(cacheConfig.MetadataLogPath); var logger = new DisposeLogger(() => new EtwFileLog(logPath.Path, cacheConfig.CacheId), cacheConfig.LogFlushIntervalSeconds); logger.Debug($"Creating CASaaS backed LocalCache using cache name: {cacheConfig.CacheName}"); var cache = CreateCache(cacheConfig, logPath, logger); var startupResult = await cache.StartupAsync(); if (!startupResult.Succeeded) { logger.Error($"Error while initializing the cache [{cacheConfig.CacheId}]. Failure: {startupResult.Failure}"); cache.Dispose(); return(startupResult.Failure); } logger.Debug("Successfully started CloudStoreLocalCacheService client."); return(cache); } catch (Exception e) { return(new CacheConstructionFailure(cacheConfig.CacheId, e)); } }
/// <inheritdoc /> public async Task <Possible <ICache, Failure> > InitializeCacheAsync(ICacheConfigData cacheData, Guid activityId, ICacheConfiguration cacheConfiguration = null) { Contract.Requires(cacheData != null); var possibleCacheConfig = cacheData.Create <Config>(); if (!possibleCacheConfig.Succeeded) { return(possibleCacheConfig.Failure); } Config cacheConfig = possibleCacheConfig.Result; try { var logPath = new AbsolutePath(cacheConfig.CacheLogPath); var logger = new DisposeLogger(() => new EtwFileLog(logPath.Path, cacheConfig.CacheId), cacheConfig.LogFlushIntervalSeconds); var vstsCache = BuildCacheUtils.CreateBuildCacheCache(cacheConfig, logger, Environment.GetEnvironmentVariable("VSTSPERSONALACCESSTOKEN")); var statsFilePath = new AbsolutePath(logPath.Path + ".stats"); var cache = new MemoizationStoreAdapterCache(cacheConfig.CacheId, vstsCache, logger, statsFilePath); logger.Diagnostic($"Initializing the cache [{cacheConfig.CacheId}]"); var startupResult = await cache.StartupAsync(); if (!startupResult.Succeeded) { logger.Error($"Error while initializing the cache [{cacheConfig.CacheId}]. Failure: {startupResult.Failure}"); cache.Dispose(); return(startupResult.Failure); } return(cache); } catch (Exception e) { return(new CacheConstructionFailure(cacheConfig.CacheId, e)); } }
/// <inheritdoc /> public async Task <Possible <ICache, Failure> > InitializeCacheAsync(ICacheConfigData cacheData, Guid activityId) { Contract.Requires(cacheData != null); var possibleCacheConfig = cacheData.Create <Config>(); if (!possibleCacheConfig.Succeeded) { return(possibleCacheConfig.Failure); } Config cacheConfig = possibleCacheConfig.Result; try { var logPath = new AbsolutePath(cacheConfig.CacheLogPath); var logger = new DisposeLogger(() => new EtwFileLog(logPath.Path, cacheConfig.CacheId), cacheConfig.LogFlushIntervalSeconds); var localCache = cacheConfig.UseStreamCAS ? CreateLocalCacheWithStreamPathCas(cacheConfig, logger) : CreateLocalCacheWithSingleCas(cacheConfig, logger); var statsFilePath = new AbsolutePath(logPath.Path + ".stats"); var cache = new MemoizationStoreAdapterCache(cacheConfig.CacheId, localCache, logger, statsFilePath, cacheConfig.ReplaceExistingOnPlaceFile); var startupResult = await cache.StartupAsync(); if (!startupResult.Succeeded) { return(startupResult.Failure); } return(cache); } catch (Exception e) { return(new CacheConstructionFailure(cacheConfig.CacheId, e)); } }
/// <summary> /// Create cache using configuration /// </summary> public async Task <Possible <ICache, Failure> > InitializeCacheAsync(Config cacheConfig, Guid activityId) { Contract.Requires(cacheConfig != null); try { var logPath = new AbsolutePath(cacheConfig.CacheLogPath); var logger = new DisposeLogger(() => new EtwFileLog(logPath.Path, cacheConfig.CacheId), cacheConfig.LogFlushIntervalSeconds); var localCache = cacheConfig.UseStreamCAS ? CreateLocalCacheWithStreamPathCas(cacheConfig, logger) : CreateLocalCacheWithSingleCas(cacheConfig, logger); var statsFilePath = new AbsolutePath(logPath.Path + ".stats"); if (!string.IsNullOrEmpty(cacheConfig.VfsCasRoot)) { localCache = new VirtualizedContentCache(localCache, new ContentStore.Vfs.VfsCasConfiguration.Builder() { RootPath = new AbsolutePath(cacheConfig.VfsCasRoot), UseSymlinks = cacheConfig.UseVfsSymlinks }.Build()); } var cache = new MemoizationStoreAdapterCache(cacheConfig.CacheId, localCache, logger, statsFilePath, cacheConfig.ReplaceExistingOnPlaceFile); var startupResult = await cache.StartupAsync(); if (!startupResult.Succeeded) { return(startupResult.Failure); } return(cache); } catch (Exception e) { return(new CacheConstructionFailure(cacheConfig.CacheId, e)); } }
private static MemoizationStoreAdapterCache CreateCache(Config cacheConfig, AbsolutePath logPath, ILogger logger) { var serviceClientContentStoreConfiguration = CreateGrpcServiceConfiguration(cacheConfig, logger); MemoizationStore.Interfaces.Caches.ICache localCache; if (cacheConfig.EnableMetadataServer) { // CaChaaS path. localCache = LocalCache.CreateRpcCache(logger, serviceClientContentStoreConfiguration); } else { // CASaaS path. We construct an in-proc memoization store in this case. var metadataRootPath = new AbsolutePath(cacheConfig.MetadataRootPath); localCache = LocalCache.CreateRpcContentStoreInProcMemoizationStoreCache(logger, metadataRootPath, serviceClientContentStoreConfiguration, CreateInProcMemoizationStoreConfiguration(cacheConfig, metadataRootPath)); } var statsFilePath = new AbsolutePath(logPath.Path + ".stats"); if (!string.IsNullOrEmpty(cacheConfig.VfsCasRoot)) { // Vfs path. Vfs wraps around whatever cache we are using to virtualize logger.Debug($"Creating virtualized cache"); localCache = new VirtualizedContentCache(localCache, new ContentStore.Vfs.VfsCasConfiguration.Builder() { RootPath = new AbsolutePath(cacheConfig.VfsCasRoot), UseSymlinks = cacheConfig.VfsUseSymlinks }.Build()); } return(new MemoizationStoreAdapterCache(cacheConfig.CacheId, localCache, logger, statsFilePath, cacheConfig.ReplaceExistingOnPlaceFile)); }
/// <inheritdoc /> public override bool IsImmutable(AbsolutePath dbFile) { return(dbFile.Path.EndsWith(".sst", StringComparison.OrdinalIgnoreCase)); }
private static MemoizationStoreConfiguration GetInProcMemoizationStoreConfiguration(AbsolutePath cacheRoot, Config config, CasConfig configCore) { if (config.RoxisEnabled) { var roxisClientConfiguration = new RoxisClientConfiguration(); if (!string.IsNullOrEmpty(config.RoxisMetadataStoreHost)) { roxisClientConfiguration.GrpcHost = config.RoxisMetadataStoreHost; } if (config.RoxisMetadataStorePort > 0) { roxisClientConfiguration.GrpcPort = config.RoxisMetadataStorePort; } return(new RoxisMemoizationDatabaseConfiguration() { MetadataClientConfiguration = roxisClientConfiguration, }); } else { return(new RocksDbMemoizationStoreConfiguration() { Database = new RocksDbContentLocationDatabaseConfiguration(cacheRoot / "RocksDbMemoizationStore") { CleanOnInitialize = false, GarbageCollectionInterval = TimeSpan.FromSeconds(config.RocksDbMemoizationStoreGarbageCollectionIntervalInSeconds), MetadataGarbageCollectionEnabled = true, MetadataGarbageCollectionMaximumNumberOfEntriesToKeep = config.RocksDbMemoizationStoreGarbageCollectionMaximumNumberOfEntriesToKeep, OnFailureDeleteExistingStoreAndRetry = true, LogsKeepLongTerm = false, }, }); } }
private static MemoizationStoreConfiguration CreateInProcMemoizationStoreConfiguration(Config cacheConfig, AbsolutePath cacheRootPath) { return(new RocksDbMemoizationStoreConfiguration() { Database = new RocksDbContentLocationDatabaseConfiguration(cacheRootPath / "RocksDbMemoizationStore") { CleanOnInitialize = false, GarbageCollectionInterval = TimeSpan.FromSeconds(cacheConfig.RocksDbMemoizationStoreGarbageCollectionIntervalInSeconds), MetadataGarbageCollectionEnabled = true, MetadataGarbageCollectionMaximumNumberOfEntriesToKeep = cacheConfig.RocksDbMemoizationStoreGarbageCollectionMaximumNumberOfEntriesToKeep, OnFailureDeleteExistingStoreAndRetry = true, LogsKeepLongTerm = true, }, }); }
/// <inheritdoc /> protected override BoolResult RestoreCheckpointCore(OperationContext context, AbsolutePath checkpointDirectory) { try { var nextActiveSlot = GetNextSlot(_activeSlot); var newStoreLocation = GetStoreLocation(nextActiveSlot); Tracer.Info(context.TracingContext, $"Loading content location database checkpoint from '{checkpointDirectory}' into '{newStoreLocation}'."); if (Directory.Exists(newStoreLocation)) { FileUtilities.DeleteDirectoryContents(newStoreLocation, deleteRootDirectory: true); } Directory.Move(checkpointDirectory.ToString(), newStoreLocation); var possiblyLoaded = Load(context, nextActiveSlot); if (possiblyLoaded.Succeeded) { SaveActiveSlot(context.TracingContext); } return(possiblyLoaded); } catch (Exception ex) when(ex.IsRecoverableIoException()) { return(new BoolResult(ex, "Restore checkpoint failed.")); } }
public Task <PlaceFileResult> PlaceFileAsync(Context context, ContentHash contentHash, AbsolutePath path, FileAccessMode accessMode, FileReplacementMode replacementMode, FileRealizationMode realizationMode, CancellationToken cts, UrgencyHint urgencyHint = UrgencyHint.Nominal) { FilePlacedParams.Add(new Tuple <ContentHash, AbsolutePath, FileAccessMode, FileReplacementMode, FileRealizationMode>(contentHash, path, accessMode, replacementMode, realizationMode)); return(Task.FromResult(new PlaceFileResult(PinResult.Success))); }
public Task <PutResult> PutFileAsync(Context context, ContentHash contentHash, AbsolutePath path, FileRealizationMode realizationMode, CancellationToken cts, UrgencyHint urgencyHint = UrgencyHint.Nominal) { PutFileHashParams.Add(new Tuple <ContentHash, AbsolutePath, FileRealizationMode>(contentHash, path, realizationMode)); return(Task.FromResult(new PutResult(contentHash, 200))); }
private static MemoizationStoreConfiguration GetInProcMemoizationStoreConfiguration(AbsolutePath cacheRoot, Config config, CasConfig configCore) { if (config.UseRocksDbMemoizationStore) { return(new RocksDbMemoizationStoreConfiguration() { Database = new RocksDbContentLocationDatabaseConfiguration(cacheRoot / "RocksDbMemoizationStore") { CleanOnInitialize = false, GarbageCollectionInterval = TimeSpan.FromSeconds(config.RocksDbMemoizationStoreGarbageCollectionIntervalInSeconds), MetadataGarbageCollectionEnabled = true, MetadataGarbageCollectionMaximumNumberOfEntriesToKeep = config.RocksDbMemoizationStoreGarbageCollectionMaximumNumberOfEntriesToKeep, OnFailureDeleteExistingStoreAndRetry = true, LogsKeepLongTerm = false, }, }); } else { var memoConfig = new SQLiteMemoizationStoreConfiguration(cacheRoot) { MaxRowCount = config.MaxStrongFingerprints, SingleInstanceTimeoutSeconds = (int)configCore.SingleInstanceTimeoutInSeconds, WaitForLruOnShutdown = WaitForLruOnShutdown }; memoConfig.Database.BackupDatabase = config.BackupLKGCache; memoConfig.Database.VerifyIntegrityOnStartup = config.CheckCacheIntegrityOnStartup; if (!string.IsNullOrEmpty(config.SynchronizationMode)) { memoConfig.Database.SyncMode = (SynchronizationMode)Enum.Parse(typeof(SynchronizationMode), config.SynchronizationMode, ignoreCase: true); } return(memoConfig); } }
private static MemoizationStoreConfiguration GetMemoizationStoreConfiguration(AbsolutePath cacheRoot, Config config, CasConfig configCore) { if (config.UseRocksDbMemoizationStore) { return(new RocksDbMemoizationStoreConfiguration() { Database = new RocksDbContentLocationDatabaseConfiguration(cacheRoot / "RocksDbMemoizationStore") { CleanOnInitialize = false, }, }); } else { var memoConfig = new SQLiteMemoizationStoreConfiguration(cacheRoot) { MaxRowCount = config.MaxStrongFingerprints, SingleInstanceTimeoutSeconds = (int)configCore.SingleInstanceTimeoutInSeconds, WaitForLruOnShutdown = WaitForLruOnShutdown }; memoConfig.Database.BackupDatabase = config.BackupLKGCache; memoConfig.Database.VerifyIntegrityOnStartup = config.CheckCacheIntegrityOnStartup; if (!string.IsNullOrEmpty(config.SynchronizationMode)) { memoConfig.Database.SyncMode = (SynchronizationMode)Enum.Parse(typeof(SynchronizationMode), config.SynchronizationMode, ignoreCase: true); } return(memoConfig); } }
private static MemoizationStoreConfiguration CreateInProcMemoizationStoreConfiguration(Config cacheConfig, AbsolutePath cacheRootPath) { if (cacheConfig.UseRocksDbMemoizationStore) { var memoConfig = new RocksDbMemoizationStoreConfiguration() { Database = new RocksDbContentLocationDatabaseConfiguration(cacheRootPath / "RocksDbMemoizationStore") { CleanOnInitialize = false, GarbageCollectionInterval = TimeSpan.FromSeconds(cacheConfig.RocksDbMemoizationStoreGarbageCollectionIntervalInSeconds), MetadataGarbageCollectionEnabled = true, MetadataGarbageCollectionMaximumNumberOfEntriesToKeep = cacheConfig.RocksDbMemoizationStoreGarbageCollectionMaximumNumberOfEntriesToKeep, }, }; return(memoConfig); } else { var memoConfig = new SQLiteMemoizationStoreConfiguration(cacheRootPath) { MaxRowCount = cacheConfig.MaxStrongFingerprints, SingleInstanceTimeoutSeconds = (int)cacheConfig.SingleInstanceTimeoutInSeconds }; memoConfig.Database.BackupDatabase = cacheConfig.BackupLKGCache; memoConfig.Database.VerifyIntegrityOnStartup = cacheConfig.CheckCacheIntegrityOnStartup; if (!string.IsNullOrEmpty(cacheConfig.SynchronizationMode)) { memoConfig.Database.SyncMode = (SynchronizationMode)Enum.Parse(typeof(SynchronizationMode), cacheConfig.SynchronizationMode, ignoreCase: true); } return(memoConfig); } }
/// <inheritdoc /> public async Task <Possible <ICache, Failure> > InitializeCacheAsync(ICacheConfigData cacheData, Guid activityId) { Contract.Requires(cacheData != null); var possibleCacheConfig = cacheData.Create <Config>(); if (!possibleCacheConfig.Succeeded) { return(possibleCacheConfig.Failure); } Config cacheConfig = possibleCacheConfig.Result; try { Contract.Assert(cacheConfig.CacheName != null); var logPath = new AbsolutePath(cacheConfig.MetadataLogPath); var logger = new DisposeLogger(() => new EtwFileLog(logPath.Path, cacheConfig.CacheId), cacheConfig.LogFlushIntervalSeconds); logger.Debug($"Creating CASaaS backed LocalCache using cache name: {cacheConfig.CacheName}"); ServiceClientRpcConfiguration rpcConfiguration; if (cacheConfig.GrpcPort != 0) { rpcConfiguration = new ServiceClientRpcConfiguration((int)cacheConfig.GrpcPort); } else { var factory = new MemoryMappedFileGrpcPortSharingFactory(logger, cacheConfig.GrpcPortFileName); var portReader = factory.GetPortReader(); var port = portReader.ReadPort(); rpcConfiguration = new ServiceClientRpcConfiguration(port); } var rootPath = new AbsolutePath(cacheConfig.MetadataRootPath); var memoConfig = new SQLiteMemoizationStoreConfiguration(rootPath) { MaxRowCount = cacheConfig.MaxStrongFingerprints, BackupDatabase = cacheConfig.BackupLKGCache, VerifyIntegrityOnStartup = cacheConfig.CheckCacheIntegrityOnStartup, SingleInstanceTimeoutSeconds = (int)cacheConfig.SingleInstanceTimeoutInSeconds }; if (!string.IsNullOrEmpty(cacheConfig.SynchronizationMode)) { memoConfig.SyncMode = (SynchronizationMode)Enum.Parse(typeof(SynchronizationMode), cacheConfig.SynchronizationMode, ignoreCase: true); } var localCache = new LocalCache( logger, cacheConfig.CacheName, rootPath, rpcConfiguration, cacheConfig.ConnectionRetryIntervalSeconds, cacheConfig.ConnectionRetryCount, memoConfig, scenarioName: cacheConfig.ScenarioName); var statsFilePath = new AbsolutePath(logPath.Path + ".stats"); var cache = new MemoizationStoreAdapterCache(cacheConfig.CacheId, localCache, logger, statsFilePath, cacheConfig.ReplaceExistingOnPlaceFile); var startupResult = await cache.StartupAsync(); if (!startupResult.Succeeded) { logger.Error($"Error while initializing the cache [{cacheConfig.CacheId}]. Failure: {startupResult.Failure}"); return(startupResult.Failure); } logger.Debug("Successfully started CloudStoreLocalCacheService client."); return(cache); } catch (Exception e) { return(new CacheConstructionFailure(cacheConfig.CacheId, e)); } }
protected override BoolResult RestoreCheckpointCore(OperationContext context, AbsolutePath checkpointDirectory) { try { var activeSlot = _activeSlot; var newActiveSlot = GetNextSlot(activeSlot); var newStoreLocation = GetStoreLocation(newActiveSlot); Tracer.Info(context.TracingContext, $"Loading content location database checkpoint from '{checkpointDirectory}' into '{newStoreLocation}'."); if (Directory.Exists(newStoreLocation)) { FileUtilities.DeleteDirectoryContents(newStoreLocation, deleteRootDirectory: true); } Directory.Move(checkpointDirectory.ToString(), newStoreLocation); var possiblyLoaded = Load(context, newActiveSlot, clean: false); if (possiblyLoaded.Succeeded) { SaveActiveSlot(context.TracingContext); } // At this point in time, we have unloaded the old database and loaded the new one. This means we're // free to backup the old one's logs. var oldStoreLocation = GetStoreLocation(activeSlot); return(possiblyLoaded); } catch (Exception ex) when(ex.IsRecoverableIoException()) { return(new BoolResult(ex, "Restore checkpoint failed.")); } }