為什麼使用 DFSR 複製後文件最終完全被空字節填充?
我們使用 Microsoft 的分佈式文件系統進行複制。在我們的場景中,我們有一個創建/覆蓋/刪除文件的寫入器和幾個分佈式讀取器。編寫器執行 Windows Server 2008 R2 Enterprise x64 SP 1,閱讀器執行 Windows Server 2003 R2 Standard Edition x86 SP 2。一些閱讀器執行 DFSR 版本為 5.2.3790.4656,另一些閱讀器執行更新檔版本 5.2.3790.4799。
文件是使用
System.IO.File.WriteAllText
寫入的,並且可以在同一個文件上快速連續地進行寫入。大多數情況下,複製工作正常,但有時文件在複製後最終完全被空字節填充。我們檢查了所有相關機器上的 DFSR 日誌,在閱讀器上發現了以下類型的 usn 日記條目報告:
20150302 11:05:00.498 2512 USNC 2202 UsnConsumer::UpdateIdRecord ID record updated from USN_RECORD: + USN_RECORD: + RecordLength: 80 + MajorVersion: 2 + MinorVersion: 0 + FileRefNumber: 0x800000000f7c8 + ParentFileRefNumber: 0x31000000152806 + USN: 0x872e876720 + TimeStamp: 20150302 11:05:00.498 CET + Reason: Basic Info Change Close Rename New Name + SourceInfo: 0x4 + SecurityId: 0xebe + FileAttributes: 0x2220 + FileNameLength: 18 + FileNameOffset: 60 + FileName: xyz.txt
讓我們感到疑惑的是,根本就存在 usn 日記帳分錄報告(讀者只是應該閱讀而不是修改任何內容)以及設置了 sparse 屬性的事實。
為了找出是否有一些程序執行意外寫入或做一些可疑的事情,我們使用Process Monitor監控文件系統活動。閱讀器上下一次出現的空字節文件為我們提供了以下資訊:
10:59:55,2311121 Dfsr.exe 1584 760 IRP_MJ_CREATE path\to\xyz.txt-{GUID}-vVERSION SUCCESS Desired Access: Generic Read/Write/Execute, Write DAC, Write Owner, Access System Security, Disposition: Create, Options: Sequential Access, Synchronous IO Non-Alert, Complete If Oplocked, Open For Backup, Open No Recall, Attributes: N, ShareMode: Read, Write, Delete, AllocationSize: 0, OpenResult: Created 10:59:55,2312485 Dfsr.exe 1584 760 IRP_MJ_CLEANUP path\to\xyz.txt-{GUID}-vVERSION SUCCESS 10:59:55,2313007 Dfsr.exe 1584 760 IRP_MJ_CLOSE path\to\xyz.txt-{GUID}-vVERSION SUCCESS 10:59:55,2314394 Dfsr.exe 1584 760 IRP_MJ_CREATE path\to\xyz.txt-{GUID}-vVERSION SUCCESS Desired Access: Read Attributes, Write Attributes, Synchronize, Disposition: Open, Options: Sequential Access, Synchronous IO Non-Alert, Open For Backup, Open Reparse Point, Open No Recall, Attributes: N, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened 10:59:55,2314626 Dfsr.exe 1584 760 IRP_MJ_FILE_SYSTEM_CONTROL path\to\xyz.txt-{GUID}-vVERSION SUCCESS Control: FSCTL_MARK_HANDLE 10:59:55,2314780 Dfsr.exe 1584 760 IRP_MJ_QUERY_INFORMATION path\to\xyz.txt-{GUID}-vVERSION SUCCESS Type: QueryNameInformationFile, Name: path\to\xyz.txt-{GUID}-vVERSION 10:59:55,2314996 Dfsr.exe 1584 760 FASTIO_QUERY_INFORMATION path\to\xyz.txt-{GUID}-vVERSION SUCCESS Type: QueryBasicInformationFile, CreationTime: 10.03.2015 10:59:55, LastAccessTime: 10.03.2015 10:59:55, LastWriteTime: 10.03.2015 10:59:55, ChangeTime: 10.03.2015 10:59:55, FileAttributes: ANCI 10:59:55,2315081 Dfsr.exe 1584 760 IRP_MJ_QUERY_INFORMATION path\to\xyz.txt-{GUID}-vVERSION SUCCESS Type: QueryAttributeTagFile, Attributes: ANCI, ReparseTag: 0x0 10:59:55,2315194 Dfsr.exe 1584 760 IRP_MJ_QUERY_INFORMATION path\to\xyz.txt-{GUID}-vVERSION SUCCESS Type: QueryCompressionInformationFile 10:59:55,2315391 Dfsr.exe 1584 760 IRP_MJ_QUERY_VOLUME_INFORMATION path\to\xyz.txt-{GUID}-vVERSION BUFFER OVERFLOW Type: QueryInformationVolume, VolumeCreationTime: 14.07.2014 14:59:54, VolumeSerialNumber: 88F0-15DC, SupportsObjects: True, VolumeLabel: uvw 10:59:55,2315481 Dfsr.exe 1584 760 IRP_MJ_QUERY_INFORMATION path\to\xyz.txt-{GUID}-vVERSION BUFFER OVERFLOW Type: QueryAllInformationFile, CreationTime: 10.03.2015 10:59:55, LastAccessTime: 10.03.2015 10:59:55, LastWriteTime: 10.03.2015 10:59:55, ChangeTime: 10.03.2015 10:59:55, FileAttributes: ANCI, AllocationSize: 0, EndOfFile: 0, NumberOfLinks: 1, DeletePending: False, Directory: False, IndexNumber: 0xe00000001589e, EaSize: 0, Access: Read Attributes, Write Attributes, Synchronize, Position: 0, Mode: Sequential Access, Synchronous IO Non-Alert, AlignmentRequirement: Long 10:59:55,2316459 Dfsr.exe 1584 760 IRP_MJ_CREATE path\to\xyz.txt-{GUID}-vVERSION SUCCESS Desired Access: Generic Read/Write/Execute, Write DAC, Write Owner, Access System Security, Disposition: Open, Options: Sequential Access, Synchronous IO Non-Alert, Complete If Oplocked, Open For Backup, Open No Recall, Attributes: N, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened 10:59:55,2316691 Dfsr.exe 1584 760 IRP_MJ_FILE_SYSTEM_CONTROL path\to\xyz.txt-{GUID}-vVERSION SUCCESS Control: FSCTL_MARK_HANDLE 10:59:55,2316796 Dfsr.exe 1584 760 IRP_MJ_CLEANUP path\to\xyz.txt-{GUID}-vVERSION SUCCESS 10:59:55,2316876 Dfsr.exe 1584 760 IRP_MJ_CLOSE path\to\xyz.txt-{GUID}-vVERSION SUCCESS 10:59:55,2317891 Dfsr.exe 1584 760 IRP_MJ_SET_SECURITY path\to\xyz.txt-{GUID}-vVERSION SUCCESS Information: Owner, Group, DACL 10:59:55,2318748 Dfsr.exe 1584 760 IRP_MJ_FILE_SYSTEM_CONTROL path\to\xyz.txt-{GUID}-vVERSION SUCCESS Control: FSCTL_SET_SPARSE 10:59:55,2319307 Dfsr.exe 1584 760 IRP_MJ_WRITE path\to\xyz.txt-{GUID}-vVERSION SUCCESS Offset: 0, Length: 0 10:59:55,2319442 Dfsr.exe 1584 760 IRP_MJ_SET_INFORMATION path\to\xyz.txt-{GUID}-vVERSION SUCCESS Type: SetEndOfFileInformationFile, EndOfFile: 240 10:59:55,2320066 Dfsr.exe 1584 760 IRP_MJ_SET_INFORMATION path\to\xyz.txt-{GUID}-vVERSION SUCCESS Type: SetAllocationInformationFile, AllocationSize: 240 10:59:55,2320382 Dfsr.exe 1584 760 IRP_MJ_WRITE path\to\xyz.txt-{GUID}-vVERSION SUCCESS Offset: 240, Length: 0 10:59:55,2320505 Dfsr.exe 1584 760 IRP_MJ_SET_INFORMATION path\to\xyz.txt-{GUID}-vVERSION SUCCESS Type: SetBasicInformationFile, CreationTime: 16.12.2013 10:57:23, LastAccessTime: 19.02.2015 11:00:25, LastWriteTime: 10.03.2015 10:59:55, ChangeTime: 10.03.2015 10:59:55, FileAttributes: ANCI 10:59:55,2320688 Dfsr.exe 1584 760 IRP_MJ_FILE_SYSTEM_CONTROL path\to\xyz.txt-{GUID}-vVERSION SUCCESS Control: FSCTL_WRITE_USN_CLOSE_RECORD 10:59:55,2321256 Dfsr.exe 1584 760 IRP_MJ_CLEANUP path\to\xyz.txt-{GUID}-vVERSION SUCCESS 10:59:55,2321506 Dfsr.exe 1584 760 IRP_MJ_CLOSE path\to\xyz.txt-{GUID}-vVERSION SUCCESS
通過這種觀察,看起來 DFSR 是產生它們的人。為什麼這樣做?另外,為什麼它將文件標記為稀疏?除了使用上述技術編寫文件之外,作者不會弄亂文件。請注意,EOF 標記移動到的偏移量與作者創建的文件大小相匹配。
到目前為止,我們無法可靠地重現該問題。有誰知道是什麼原因造成的,更重要的是,如何解決它?
將閱讀器升級到最新版本的DFSR 2008 R2只是減少了問題的發生,但並沒有完全解決。在另外將閱讀器配置為防寫後,沒有再次觀察到該問題(距上次升級半年)。
您的 DFS-R 暫存區是否與 DFS-R 文件夾位於同一卷上?出於性能原因,它應該是。如果不是,則 DFS-R 必須將文件從暫存卷複製到目標卷,而不是直接移動。
這是推測開始的地方。可能是在此複製操作期間,DFS-R 正在創建一個稀疏文件,然後填充塊,並在完成時“解壓縮”它。如果某些東西中斷了這個過程(如防病毒、Undelete 或其他掃描 DfsrPrivate 文件夾的文件過濾驅動程序),那麼您最終可能會得到一個臨時的稀疏文件,該文件沒有被其內容填充。
您可以通過在正確複製的文件上使用程序監視器來測試此行為,並查看它們是否在程序中的任何點被標記/取消標記為稀疏。
當談到 DFS-R 時,我不喜歡混合 2008 年和 2003 年。我很高興將最後一台 2003 年的機器從我們的 DFS 樹中取出。