// Token: 0x06002221 RID: 8737 RVA: 0x0009F690 File Offset: 0x0009D890 public static SafeFileHandle OpenFile(string filename, bool openForRead, out int lastError, bool cachedIo) { FileMode fileMode; FileShare fileShare; FileAccess fileAccess; if (openForRead) { fileMode = FileMode.Open; fileShare = FileShare.Read; fileAccess = FileAccess.Read; } else { fileMode = FileMode.Create; fileShare = FileShare.None; fileAccess = FileAccess.Write; } FileFlags fileFlags; if (cachedIo) { fileFlags = FileFlags.FILE_ATTRIBUTE_NORMAL; } else { fileFlags = FileFlags.FILE_FLAG_NO_BUFFERING; } if (RegistryParameters.LogCopyBufferedIo != 0) { fileFlags = FileFlags.FILE_ATTRIBUTE_NORMAL; } return(LogCopy.LogCopyCreateFile(filename, fileAccess, fileShare, fileMode, fileFlags, out lastError)); }
internal static void TruncateFile(string fileName, long fileSize) { int num; using (SafeFileHandle safeFileHandle = LogCopy.LogCopyCreateFile(fileName, FileAccess.Write, FileShare.None, FileMode.Open, FileFlags.FILE_ATTRIBUTE_NORMAL, out num)) { long num2; NativeMethods.SetFilePointerEx(safeFileHandle, fileSize, out num2, 0U); NativeMethods.SetEndOfFile(safeFileHandle); } }
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); } }
// Token: 0x06002223 RID: 8739 RVA: 0x0009F760 File Offset: 0x0009D960 public static SafeFileHandle OpenLogForRead(string filename) { int num = 0; int num2 = 300; Exception ex = null; ExDateTime?exDateTime = null; FileFlags fileFlags = FileFlags.FILE_FLAG_NO_BUFFERING; if (RegistryParameters.LogCopyBufferedIo != 0) { fileFlags = FileFlags.FILE_ATTRIBUTE_NORMAL; } for (;;) { int num3 = 0; try { return(LogCopy.LogCopyCreateFile(filename, FileAccess.Read, FileShare.Read, FileMode.Open, fileFlags, out num3)); } catch (IOException ex2) { ex = ex2; if (num3 == 32) { if (num++ == 0) { exDateTime = new ExDateTime?(ExDateTime.Now.AddSeconds((double)RegistryParameters.FileInUseRetryLimitInSecs)); } else { if (exDateTime.Value <= ExDateTime.Now) { break; } num2 = 1000; } ExTraceGlobals.LogCopyTracer.TraceError <string, int>(0L, "OpenLogForRead({0}) caught sharing violation. Will retry in {1}ms", filename, num2); Thread.Sleep(num2); continue; } } break; } ExTraceGlobals.LogCopyTracer.TraceError <string, Exception>(0L, "OpenLogForRead({0}) failed: {1}", filename, ex); throw ex; }
// Token: 0x06001AB0 RID: 6832 RVA: 0x0007240F File Offset: 0x0007060F private static FileStream OpenFileStream(SafeFileHandle fileHandle, bool openForRead) { return(LogCopy.OpenFileStream(fileHandle, openForRead)); }
private LogCopyServerContext.SendLogStatus SendE00() { string text = this.Database.BuildLogFileName(0L); long num = 0L; FileIOonSourceException ex; if (this.m_dismountWorker == null) { ex = this.Database.GetE00Generation(out num, text); } else { ex = this.m_dismountWorker.LastE00ReadException; } if (ex != null) { bool flag = true; Exception innerException = ex.InnerException; if (innerException != null && innerException is EsentFileAccessDeniedException && !AmStoreServiceMonitor.WasKillTriggered()) { if (this.m_dismountWorker == null) { LogCopyServerContext.Tracer.TraceDebug((long)this.GetHashCode(), "SendE00(): E00 still in use so starting a DismountDatabaseOrKillStore() in background..."); this.m_dismountWorker = new DismountBackgroundWorker(new DismountBackgroundWorker.DismountDelegate(this.DismountDatabaseOrKillStore)); this.m_dismountWorker.LastE00ReadException = ex; this.m_dismountWorker.Start(); } if (this.m_dismountWorker.CompletedEvent.WaitOne(1000)) { if (this.m_dismountWorker.DismountException == null) { flag = false; LogCopyServerContext.Tracer.TraceDebug((long)this.GetHashCode(), "SendE00(): DismountDatabaseOrKillStore() operation completed successfully"); } else { LogCopyServerContext.Tracer.TraceError <Exception>((long)this.GetHashCode(), "SendE00(): DismountDatabaseOrKillStore() operation completed but encountered an exception: {0}", this.m_dismountWorker.DismountException); } this.m_dismountWorker.Dispose(); this.m_dismountWorker = null; } else if ((ExDateTime.Now - this.m_dismountWorker.StartTime).TotalMilliseconds < (double)(RegistryParameters.AcllDismountOrKillTimeoutInSec2 * 1000)) { return(LogCopyServerContext.SendLogStatus.KeepChannelAlive); } } if (!flag) { this.Database.ProbeForMoreLogs(this.m_currentLogGeneration); return(LogCopyServerContext.SendLogStatus.KeepTrying); } this.HandleSourceReadError(ex); return(LogCopyServerContext.SendLogStatus.StopForException); } else if (num != this.m_currentLogGeneration) { LogCopyServerContext.Tracer.TraceDebug <long, long>((long)this.GetHashCode(), "SendE00 finds e00 at 0x{0:X} but expected 0x{1:X}", num, this.m_currentLogGeneration); if (num > this.m_currentLogGeneration) { this.Database.SyncWithE00(num); return(LogCopyServerContext.SendLogStatus.KeepTrying); } AcllFailedException e = new AcllFailedException(ReplayStrings.LogCopierE00InconsistentError(num, this.m_currentLogGeneration)); this.SendException(e); return(LogCopyServerContext.SendLogStatus.StopForException); } else { Exception ex2 = null; try { using (SafeFileHandle safeFileHandle = LogCopy.OpenLogForRead(text)) { CopyLogReply copyLogReply = new CopyLogReply(this.Channel); copyLogReply.ThisLogGeneration = 0L; copyLogReply.EndOfLogGeneration = num; copyLogReply.EndOfLogUtc = DateTime.UtcNow; CheckSummer summer = null; if (this.Channel.ChecksumDataTransfer) { summer = new CheckSummer(); } this.Channel.SendLogFileTransferReply(copyLogReply, text, safeFileHandle, this.SourceDatabasePerfCounters, summer); } } catch (IOException ex3) { ex2 = new FileIOonSourceException(Environment.MachineName, text, ex3.Message, ex3); } catch (UnauthorizedAccessException ex4) { ex2 = new FileIOonSourceException(Environment.MachineName, text, ex4.Message, ex4); } catch (FileIOonSourceException ex5) { ex2 = ex5; } if (ex2 != null) { this.HandleSourceReadError(ex2); return(LogCopyServerContext.SendLogStatus.StopForException); } return(LogCopyServerContext.SendLogStatus.SentE00); } }
// Token: 0x06001D67 RID: 7527 RVA: 0x00084D0C File Offset: 0x00082F0C private Exception VerifyLog(string fullLocalFileName, long expectedGen) { Exception ex = null; try { ReplayStopwatch replayStopwatch = new ReplayStopwatch(); replayStopwatch.Start(); using (SafeFileHandle safeFileHandle = LogCopy.OpenLogForRead(fullLocalFileName)) { long arg = replayStopwatch.ElapsedMilliseconds; LogRepair.Tracer.TracePerformance <string, long>((long)this.GetHashCode(), "VerifyLog({0}): Open took: {1} ms", fullLocalFileName, arg); using (FileStream fileStream = LogCopy.OpenFileStream(safeFileHandle, true)) { FileInfo fileInfo = new FileInfo(fullLocalFileName); long elapsedMilliseconds; try { if (fileInfo.Length != 1048576L) { throw new IOException(string.Format("Unexpected log file size: '{0}' has 0x{1:X} bytes.", fullLocalFileName, fileInfo.Length)); } elapsedMilliseconds = replayStopwatch.ElapsedMilliseconds; int num = fileStream.Read(this.m_verifierLogDataBuf, 0, 1048576); if (num != 1048576) { LogRepair.Tracer.TraceError <int, int, string>((long)this.GetHashCode(), "VerifyLog. Expected {0} but got {1} bytes from {2}", 1048576, num, fullLocalFileName); throw new IOException(ReplayStrings.UnexpectedEOF(fullLocalFileName)); } arg = replayStopwatch.ElapsedMilliseconds - elapsedMilliseconds; LogRepair.Tracer.TracePerformance <string, long>((long)this.GetHashCode(), "VerifyLog({0}): Read took: {1} ms", fullLocalFileName, arg); } catch (IOException ex2) { throw new CorruptLogDetectedException(fullLocalFileName, ex2.Message, ex2); } elapsedMilliseconds = replayStopwatch.ElapsedMilliseconds; EsentErrorException ex3 = this.EseLogVerifier.Verify(fullLocalFileName, this.m_verifierLogDataBuf); if (ex3 != null) { LogRepair.Tracer.TraceError <string, EsentErrorException>((long)this.GetHashCode(), "ESELogVerifier({0}) failed: {1}", fullLocalFileName, ex3); if (ex3 is EsentLogFileCorruptException) { throw new CorruptLogDetectedException(fullLocalFileName, ex3.Message, ex3); } throw ex3; } else { JET_LOGINFOMISC jet_LOGINFOMISC; UnpublishedApi.JetGetLogFileInfo(fullLocalFileName, out jet_LOGINFOMISC, JET_LogInfo.Misc2); if ((long)jet_LOGINFOMISC.ulGeneration != expectedGen) { throw new FileCheckLogfileGenerationException(fullLocalFileName, (long)jet_LOGINFOMISC.ulGeneration, expectedGen); } if (this.m_logfileSignature == null) { this.m_logfileSignature = new JET_SIGNATURE?(jet_LOGINFOMISC.signLog); } if (!jet_LOGINFOMISC.signLog.Equals(this.m_logfileSignature)) { throw new FileCheckLogfileSignatureException(fullLocalFileName, jet_LOGINFOMISC.signLog.ToString(), this.m_logfileSignature.ToString()); } arg = replayStopwatch.ElapsedMilliseconds - elapsedMilliseconds; LogRepair.Tracer.TracePerformance <string, long>((long)this.GetHashCode(), "VerifyLog({0}): Verify took: {1} ms", fullLocalFileName, arg); return(null); } } } } catch (IOException ex4) { ex = ex4; } catch (UnauthorizedAccessException ex5) { ex = ex5; } catch (EsentErrorException ex6) { ex = ex6; } catch (CorruptLogDetectedException ex7) { ex = ex7; } catch (FileCheckException ex8) { ex = ex8; } if (ex != null) { LogRepair.Tracer.TraceError <string, Exception>((long)this.GetHashCode(), "VerifyLog({0}): failed with {1}", fullLocalFileName, ex); } return(ex); }
// Token: 0x06002220 RID: 8736 RVA: 0x0009F682 File Offset: 0x0009D882 public static SafeFileHandle OpenFile(string filename, bool openForRead, out int lastError) { return(LogCopy.OpenFile(filename, openForRead, out lastError, false)); }
internal void SendLog(long logGen, NetworkChannel channel, SourceDatabasePerformanceCountersInstance perfCounters) { ReplayStopwatch replayStopwatch = new ReplayStopwatch(); replayStopwatch.Start(); string text = this.BuildLogFileName(logGen); Exception ex = null; try { using (SafeFileHandle safeFileHandle = LogCopy.OpenLogForRead(text)) { try { JET_LOGINFOMISC jet_LOGINFOMISC; UnpublishedApi.JetGetLogFileInfo(text, out jet_LOGINFOMISC, JET_LogInfo.Misc2); if (logGen != 0L && (long)jet_LOGINFOMISC.ulGeneration != logGen) { FileCheckLogfileGenerationException ex2 = new FileCheckLogfileGenerationException(text, (long)jet_LOGINFOMISC.ulGeneration, logGen); CorruptLogDetectedException ex3 = new CorruptLogDetectedException(text, ex2.Message, ex2); throw new FileIOonSourceException(Environment.MachineName, text, ex3.Message, ex3); } JET_SIGNATURE?jet_SIGNATURE = null; lock (this.m_sigLock) { if (this.m_logfileSignature == null) { this.m_logfileSignature = new JET_SIGNATURE?(jet_LOGINFOMISC.signLog); } jet_SIGNATURE = this.m_logfileSignature; } if (!jet_LOGINFOMISC.signLog.Equals(jet_SIGNATURE)) { FileCheckLogfileSignatureException ex4 = new FileCheckLogfileSignatureException(text, jet_LOGINFOMISC.signLog.ToString(), jet_SIGNATURE.Value.ToString()); CorruptLogDetectedException ex5 = new CorruptLogDetectedException(text, ex4.Message, ex4); throw new FileIOonSourceException(Environment.MachineName, text, ex5.Message, ex5); } } catch (EsentLogFileCorruptException ex6) { CorruptLogDetectedException ex7 = new CorruptLogDetectedException(text, ex6.Message, ex6); throw new FileIOonSourceException(Environment.MachineName, text, ex7.Message, ex7); } EndOfLog currentEndOfLog = this.CurrentEndOfLog; CopyLogReply copyLogReply = new CopyLogReply(channel); copyLogReply.ThisLogGeneration = logGen; copyLogReply.EndOfLogGeneration = currentEndOfLog.Generation; copyLogReply.EndOfLogUtc = currentEndOfLog.Utc; CheckSummer summer = null; if (channel.ChecksumDataTransfer) { summer = new CheckSummer(); } channel.SetupLogChecksummer(this.Config.LogFilePrefix); channel.SendLogFileTransferReply(copyLogReply, text, safeFileHandle, perfCounters, summer); MonitoredDatabase.Tracer.TracePerformance <long>((long)this.GetHashCode(), "CopyLogFile finished streaming after {0}ms.", replayStopwatch.ElapsedMilliseconds); } } catch (IOException ex8) { ex = ex8; } catch (UnauthorizedAccessException ex9) { ex = ex9; } catch (EsentErrorException ex10) { ex = ex10; } if (ex != null) { ExTraceGlobals.MonitoredDatabaseTracer.TraceError <string, Exception>((long)this.GetHashCode(), "SendLog({0}) failed: {1}", text, ex); throw new FileIOonSourceException(Environment.MachineName, text, ex.Message, ex); } }