private async Task <IEnumerable <CacheError> > CheckCache(Task <IEnumerable <CacheError> > remoteCacheChecker) { // Check remote cache var remoteCacheErrors = await remoteCacheChecker; // Check local cache var localCacheErrors = await m_localChecker.CheckCache(m_remoteChecker.GetStrongFingerprints()); IEnumerable <CacheError> errors = remoteCacheErrors.Concat(localCacheErrors); IEnumerable <CacheError> determinismErrors = CheckDeterminism(); errors = errors.Concat(determinismErrors); return(errors); }
/// <summary> /// Performs a consistency check of the specified cache. /// If the cache is a VerticalCacheAggregator, a two level /// check will be performed. Otherwise, a single level /// check will be performed. /// </summary> /// <returns>Status code. 0 => success, non-zero => failure</returns> private int DoConsistencyCheck() { Console.Error.WriteLine("\nStarting consistency check"); // Start timing Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); IEnumerable <CacheError> cacheErrors; VerticalCacheAggregator verticalCacheAggregator = m_cache as VerticalCacheAggregator; if (verticalCacheAggregator != null) { ICache localCache = verticalCacheAggregator.LocalCache; ICache remoteCache = verticalCacheAggregator.RemoteCache; TwoLevelCacheChecker cacheChecker = new TwoLevelCacheChecker(localCache, remoteCache, m_rehashCASContent); if (m_inputWeakFingerprints.Count > 0) { Console.Error.WriteLine("\nChecking through the " + m_inputWeakFingerprints.Count + " provided weak fingerprints"); cacheErrors = cacheChecker.CheckCache(m_inputWeakFingerprints, m_weakFingerprintsFound).Result; } else { try { Console.Error.WriteLine("\nChecking through the sessions using the following regex: " + m_sessionRegex.ToString()); cacheErrors = cacheChecker.CheckCache(m_sessionRegex, m_weakFingerprintsFound).Result; Console.Error.WriteLine(string.Format(CultureInfo.InvariantCulture, "\nSessions checked/Total sessions: {0}/{1}", cacheChecker.NumSessionsChecked, cacheChecker.NumSessions)); } catch (NotImplementedException e) { // Not all cache implementations implement all of the interface methods WriteError("Exception caught: " + e.Message); WriteError("The implementation of the specified cache does not implement all required methods for this tool to be able to perform a check."); return(1); } } Console.Error.WriteLine("\nNumber of FullCacheRecords checked: " + cacheChecker.NumFullCacheRecords); } else { SingleCacheChecker cacheChecker = new SingleCacheChecker(m_jsonString, m_rehashCASContent); if (m_inputWeakFingerprints.Count > 0) { Console.Error.WriteLine("\nChecking through the " + m_inputWeakFingerprints.Count + " provided weak fingerprints"); cacheErrors = cacheChecker.CheckCache(m_inputWeakFingerprints, m_weakFingerprintsFound).Result; } else { try { Console.Error.WriteLine("\nChecking through the sessions using the following regex: " + m_sessionRegex.ToString()); cacheErrors = cacheChecker.CheckCache(m_sessionRegex, m_weakFingerprintsFound).Result; Console.Error.WriteLine(string.Format(CultureInfo.InvariantCulture, "\nSessions checked/Total sessions: {0}/{1}", cacheChecker.NumSessionsChecked, cacheChecker.NumSessions)); } catch (NotImplementedException e) { // Not all cache implementations implement all of the interface methods WriteError("Exception caught: " + e.Message); WriteError("The implementation of the specified cache does not implement all required methods for this tool to be able to perform a check."); return(1); } } Console.Error.WriteLine("\nNumber of FullCacheRecords checked: " + cacheChecker.AllFullCacheRecords.Count); } // Output cache errors found during check OutputCacheErrors(cacheErrors); // Stop timing stopwatch.Stop(); Console.Error.WriteLine("\nTotal time to check cache: " + stopwatch.Elapsed.TotalSeconds.ToString("F", CultureInfo.CurrentCulture) + " seconds"); return(0); }
/// <summary> /// First individually checks the remote and local caches for /// consistency errors, then checks both for determinism errors /// </summary> /// <remarks>The remote cache must support sessions but the local does /// not have to</remarks> /// <param name="sessionRegex">Filters which sessions are used</param> /// <param name="weakFingerprintsFound">If specified, all weak /// fingerprints found will be added to this collection</param> /// <returns>All the errors found</returns> public Task <IEnumerable <CacheError> > CheckCache(Regex sessionRegex, ConcurrentDictionary <WeakFingerprintHash, byte> weakFingerprintsFound = null) { return(CheckCache(m_remoteChecker.CheckCache(sessionRegex, weakFingerprintsFound))); }