private void ValidateLogFile(GranularLogCompleteMsg msg, string fullSourceFileName) { if (msg.ChecksumUsed != GranularLogCloseData.ChecksumAlgorithm.MD5) { GranularWriter.Tracer.TraceError((long)this.GetHashCode(), "only MD5 supported for now"); this.ThrowUnexpectedMessage("only MD5 supported for now"); } Exception ex = null; try { using (SafeFileHandle safeFileHandle = LogCopy.OpenLogForRead(fullSourceFileName)) { using (FileStream fileStream = LogCopy.OpenFileStream(safeFileHandle, true)) { FileInfo fileInfo = new FileInfo(fullSourceFileName); if (fileInfo.Length != 1048576L) { throw new IOException(string.Format("Unexpected log file size: '{0}' has 0x{1:X} bytes", fullSourceFileName, fileInfo.Length)); } byte[] buffer = new byte[1048576]; int num = fileStream.Read(buffer, 0, 1048576); if (num != 1048576) { GranularWriter.Tracer.TraceError <int, int, string>((long)this.GetHashCode(), "ValidateLogFile. Expected {0} but got {1} bytes from {2}", 1048576, num, fullSourceFileName); throw new IOException(ReplayStrings.UnexpectedEOF(fullSourceFileName)); } byte[] b; using (MessageDigestForNonCryptographicPurposes messageDigestForNonCryptographicPurposes = new MessageDigestForNonCryptographicPurposes()) { b = messageDigestForNonCryptographicPurposes.ComputeHash(buffer); } if (!GranularWriter.BytesAreIdentical(b, msg.ChecksumBytes)) { GranularWriter.Tracer.TraceError <string>((long)this.GetHashCode(), "ValidateLogFile: MD5 hash failure on '{0}'", fullSourceFileName); throw new GranularReplicationTerminatedException(string.Format("MD5 HASH fails on {0}", fullSourceFileName)); } } } } catch (IOException ex2) { ex = ex2; } catch (UnauthorizedAccessException ex3) { ex = ex3; } if (ex != null) { throw new GranularReplicationTerminatedException(string.Format("ValidateLogFile on {0} failed: {1}", fullSourceFileName, ex.Message), ex); } }
public void ProcessGranularLogCompleteMsg(GranularLogCompleteMsg msg) { if (this.m_lowestClosedGeneration == 0L || this.m_lowestClosedGeneration > msg.Generation) { GranularWriter.Tracer.TraceDebug <string, long>((long)this.GetHashCode(), "ProcessGranularLogCompleteMsg({0}): haven't found the completion of the first granule. Ignoring 0x{1:X}", this.DatabaseName, msg.Generation); return; } Exception ex = null; try { if (this.m_lowestClosedGeneration < msg.Generation) { GranularWriter.Tracer.TraceError <string, long, long>((long)this.GetHashCode(), "The server must have skipped verification.({0}): expecting 0x{1:X} got 0x{2:X}", this.DatabaseName, this.m_lowestClosedGeneration, msg.Generation); long num; long num2; this.ReleaseRangeOfClosedButUnfinalizedLogs(msg.Generation - 1L, out num, out num2); } string text = this.FormFullGranuleName(msg.Generation); ReplayStopwatch replayStopwatch = new ReplayStopwatch(); replayStopwatch.Start(); FileInfo fileInfo = new FileInfo(text); fileInfo.LastWriteTimeUtc = msg.LastWriteUtc; GranularWriter.Tracer.TracePerformance <string, long, ReplayStopwatch>((long)this.GetHashCode(), "GranularLogComplete({0},0x{1:X}) file timestamped at {2}", this.DatabaseName, msg.Generation, replayStopwatch); if (msg.ChecksumUsed == GranularLogCloseData.ChecksumAlgorithm.MD5) { this.ValidateLogFile(msg, text); GranularWriter.Tracer.TracePerformance <string, long, ReplayStopwatch>((long)this.GetHashCode(), "GranularLogComplete({0},0x{1:X}) validated at {2}", this.DatabaseName, msg.Generation, replayStopwatch); } string destFileName = this.FormInspectorLogfileName(msg.Generation); File.Move(text, destFileName); this.TrackInspectorGeneration(msg.Generation, msg.LastWriteUtc); GranularWriter.Tracer.TracePerformance <string, long, ReplayStopwatch>((long)this.GetHashCode(), "GranularLogComplete({0},0x{1:X}) moved at {2}", this.DatabaseName, msg.Generation, replayStopwatch); this.m_lowestClosedGeneration = msg.Generation + 1L; } catch (IOException ex2) { ex = ex2; } catch (UnauthorizedAccessException ex3) { ex = ex3; } if (ex != null) { throw new GranularReplicationTerminatedException(string.Format("ProcessGranularLogCompleteMsg on 0x{0:X} failed: {1}", msg.Generation, ex.Message), ex); } }