MID File Cleaner - deletes old Export Set files, errored ECC Queue payloads, and LogsDetails Table of Contents IntroductionFunctionalityLoggingTroubleshooting Potential errorsListing the Last Accessed time of files Disabling the MID File Cleaner Introduction Since the Tokyo release, a new monitor thread runs in the MID Server to clean up old files, to keep the size and quantity of files within the install folder manageable, to prevent performance issues with the MID Servers. This wider change was done in relation to the fix for this specific problem that had caused MID Server outage support cases:PRB1507153 / KB0965745 Export Sets have no data cleanup for attachments saved to MID Server, eventually causing performance problems for the MID Server Functionality Files and empty folders within the following folders may be deleted by this MID File Cleaner. Files last accessed more than 30 days ago are deleted. It runs on startup, and then every 24 hours after that. You can force the File Cleaner to run by restarting the MID Server service. Folders/files cleaned (as of Utah)L \agent\import\agent\export - including sub-folders. Used by the Export Set feature. \agent\work\monitors\ECCSender\output_error - Used since San Diego for ECC input payloads that cannot be inserted for any reason (see PRB1521761/KB0995569).\agent\work\monitors\ECCSender\output_oversize - Used since Eureka/Fuji for saving copies of payloads that are not sent to the instance because they are larger than the limit set by mid.eccq.max_payload_size, which defaults to 20000000 bytes (see PRB598334)\agent\logs - Specifically JFR Dumps (Utah release) Logging The MID Server agent log will show this monitor starting and shutting down with the MID Server. 2022-10-21T13:08:58.330+0200 INFO (MIDServer) [Main:265] Initializing MID Server 2022-10-21T13:10:36.527+0200 INFO (StartupSequencer) [Monitors:307] Enabling monitor: FileCleanerMonitor ... 2022-10-24T09:29:35.193+0200 INFO (MIDServer) [MIDServerState:160] MID Server stopping 2022-10-24T09:29:38.591+0200 INFO (MIDServer) [Instance:928] interrupting thread FileCleanerMonitor.21600 To see exactly when it runs, you will need to enable debug with parameter mid.log.level=debug 2022-11-17T02:49:13.201-0800 DEBUG (FileCleanerMonitor.21600) [AFileCleaner:103] Scanning directory to delete files: C:\...\agent\import2022-11-17T02:49:13.201-0800 DEBUG (FileCleanerMonitor.21600) [AFileCleaner:103] Scanning directory to delete files: C:\...\agent\export2022-11-17T02:49:13.201-0800 DEBUG (FileCleanerMonitor.21600) [AFileCleaner:103] Scanning directory to delete files: C:\...\agent\work\monitors\ECCSender\output_error2022-11-17T02:49:13.201-0800 DEBUG (FileCleanerMonitor.21600) [AFileCleaner:103] Scanning directory to delete files: C:\...\agent\work\monitors\ECCSender\output_oversize2022-11-17T02:49:13.201-0800 DEBUG (FileCleanerMonitor.21600) [AFileCleaner:103] Scanning directory to delete files: C:\...\agent\logs There is no logging for individual file/folder deletes. Troubleshooting Potential errors "Error occurred while collecting files for deletion""Error occurred while checking the file attributes in: " + path 2022-05-11 15:28:11 (428) FileCleanerMonitor.21600 SEVERE *** ERROR *** Error occurred while checking the file attributes in: C:\...\agent\exportjava.nio.file.NoSuchFileException: C:\...\agent\export2022-05-11 15:28:11 (428) FileCleanerMonitor.21600 SEVERE *** ERROR *** Error occurred while checking the file attributes in: C:\...\agent\work\monitors\ECCSender\output_oversizejava.nio.file.NoSuchFileException: C:\...\agent\work\monitors\ECCSender\output_oversize2022-05-11 15:28:11 (428) FileCleanerMonitor.21600 SEVERE *** ERROR *** Error occurred while checking the file attributes in: C:\...\agent\work\monitors\ECCSender\output_errorjava.nio.file.NoSuchFileException: C:\...\agent\work\monitors\ECCSender\output_error2022-05-11 15:28:11 (428) FileCleanerMonitor.21600 SEVERE *** ERROR *** Error occurred while checking the file attributes in: C:\...\agent\importjava.nio.file.NoSuchFileException: C:\...\agent\import "Error occurred while trying to delete file: " + filePath2022-10-20T07:55:03.088-0600 ERROR (FileCleanerMonitor.21600) [AFileCleaner:122] Error occurred while trying to delete file: C:\...\agent\export\XXXjava.nio.file.AccessDeniedException: C:\...\agent\export\XXXat java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:274)at java.base/sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:105)at java.base/java.nio.file.Files.delete(Files.java:1142)at com.service_now.monitor.AFileCleaner.removePath(AFileCleaner.java:120)at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)at com.service_now.monitor.AFileCleaner.deleteFiles(AFileCleaner.java:108)at com.service_now.monitor.FileCleanerMonitor.run(FileCleanerMonitor.java:48)at com.service_now.monitor.AMonitor.runit(AMonitor.java:154)at com.service_now.monitor.AMonitor.access$200(AMonitor.java:43)at com.service_now.monitor.AMonitor$MonitorTask.execute(AMonitor.java:147)at com.service_now.monitor.base.AMonitorTask.run(AMonitorTask.java:29)at java.base/java.util.TimerThread.mainLoop(Timer.java:556)at java.base/java.util.TimerThread.run(Timer.java:506) Listing the Last Accessed time of files This Powershell script can be used to list the Last Accessed timestamps of files in the export folder that are older than 30 days. This can be used to confirm that the File Cleaner has deleted all it should have. $Folder = 'C:\MID_SERVERS\empdpiper_1\agent\export\*.*'$lastAccessDate = (Get-Date).AddDays(30) Get-ChildItem $Folder -Recurse | Where-Object { $_.LastAccessTime -lt $lastAccessDate} | Select-Object -Property Name, LastAccessTime Disabling the MID File Cleaner Export Sets will write files to the MID Server agent\export folders. The idea is then that a custom implementation on the customer side takes those files and moves them elsewhere, so that these files only need to remain in the MID Server application's install directory for a short time. The MID File Cleaner can be disabled completely for all folders, by adding the MID Server Configuration Parameter mid.file_cleaner.disabled=true. When the parameter is not present, which is the out-of-box state, it defaults to false, and file cleaner will run. On the MID Server form, click New on the "Configuration Parameters" related list, select mid.file_cleaner.disabled, and enter the value "true". This can also be manually added to the config.xml file: <parameter name="mid.file_cleaner.disabled" value="true"/> Adding the parameter before upgrading to Tokyo would prevent this deleting any files when you do upgrade to Tokyo. Restart the MID Server service, and confirm the config.xml file loaded with the corresponding setting. That will confirm it is truly disabled. Note: Individual folders cannot be disabled. Turning this off stops all of these folders being cleaned. WARNING: MID Server performance issues have been caused by these folders being allowed to grow too large, with too many files. If you disable this, you will need to regularly check that you are not going to cause disk space problems, or delay the startup of MID Servers while it checks permissions on all the files.