/// <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> /// Creates two SingleCacheChecker instances, one for the local cache and one for the remote cache /// </summary> /// <param name="localCache">Local cache to check</param> /// <param name="remoteCache">Remote cache to check</param> /// <param name="checkCASContent">If true, each CAS content file will be downloaded and rehashed to ensure that the content has not been corrupted since initially being put in cache</param> public TwoLevelCacheChecker(ICache localCache, ICache remoteCache, bool checkCASContent) { m_localChecker = new SingleCacheChecker(localCache, checkCASContent, true); m_remoteChecker = new SingleCacheChecker(remoteCache, checkCASContent, false); m_remoteGuid = remoteCache.CacheGuid; }