Skip to content

[AMQ-9856] Journal move fails on Windows#1654

Open
jeanouii wants to merge 3 commits intoapache:mainfrom
jeanouii:fix/exclude-JournalArchiveTest-from-windows-builds
Open

[AMQ-9856] Journal move fails on Windows#1654
jeanouii wants to merge 3 commits intoapache:mainfrom
jeanouii:fix/exclude-JournalArchiveTest-from-windows-builds

Conversation

@jeanouii
Copy link
Contributor

@jeanouii jeanouii commented Feb 5, 2026

To be discussed. On Github Actions for Windows nodes, it consistently fails.

On Windows, files cannot be renamed/moved while open by another process. The simplest and most appropriate fix is to skip this test on Windows where file locking makes it inherently unreliable.

@jeanouii
Copy link
Contributor Author

jeanouii commented Feb 5, 2026

FYI, here is the stack trace on Windows

java.io.IOException: Failed to move target\activemq-data\localhost\KahaDB\db-6.log to D:\a\activemq\activemq\activemq-kahadb-store\target\activemq-data\localhost\KahaDB\data-archive - target\activemq-data\localhost\KahaDB\db-6.log -> D:\a\activemq\activemq\activemq-kahadb-store\target\activemq-data\localhost\KahaDB\data-archive\db-6.log: The process cannot access the file because it is being used by another process
	at org.apache.activemq.util.IOHelper.moveFile(IOHelper.java:200)
	at org.apache.activemq.store.kahadb.disk.journal.DataFile.move(DataFile.java:107)
	at org.apache.activemq.store.kahadb.disk.journal.Journal.forceRemoveDataFile(Journal.java:833)
	at org.apache.activemq.store.kahadb.disk.journal.Journal.removeDataFiles(Journal.java:812)
	at org.apache.activemq.store.kahadb.MessageDatabase.checkpointUpdate(MessageDatabase.java:1701)
	at org.apache.activemq.store.kahadb.MessageDatabase.checkpointCleanup(MessageDatabase.java:1035)
	at org.apache.activemq.store.kahadb.KahaDBStore.checkpoint(KahaDBStore.java:1481)

@mattrpav
Copy link
Contributor

mattrpav commented Feb 5, 2026

A debug on macos confirmed that when the move is requested, the db-6.log file is not opened by the Java process.

Note: This may be a race condition if close is async.

@mattrpav
Copy link
Contributor

mattrpav commented Feb 5, 2026

The exception is wrapped and the original exception and stacktrace is lost-- I made a quick change to see if we can get the full stacktrace

ref: #1655

@jeanouii jeanouii changed the title [WIP] Exclude JournalArchiveTest from Windows builds to reduce test flakiness [AMQ-9856] Journal move fails on Windows Feb 5, 2026
@jeanouii
Copy link
Contributor Author

jeanouii commented Feb 9, 2026

@mattrpav Ok with you to merge?

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses Windows file locking issues (AMQ-9856) in journal operations by introducing non-blocking file operations with asynchronous cleanup mechanisms. The changes replace direct file system operations with IOHelper utility methods that gracefully handle Windows' exclusive file locking behavior, where files cannot be moved or deleted while open by another process.

Changes:

  • Introduced async file deletion mechanism with a background cleanup thread for Windows
  • Added renameFile and moveFile methods with fallback strategies (rename → NIO move → copy+delete)
  • Migrated DataFile, PageFile, and LockFile to use non-blocking IOHelper methods instead of direct File operations

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
activemq-broker/src/main/java/org/apache/activemq/util/IOHelper.java Added async cleanup infrastructure with ScheduledExecutorService, implemented deleteFileNonBlocking, renameFile, and enhanced moveFile with multi-strategy fallback approach
activemq-broker/src/test/java/org/apache/activemq/util/IOHelperTest.java New test suite covering moveFile, deleteFileNonBlocking, and isWindows utility method
activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/page/PageFile.java Updated delete and archive methods to use IOHelper utilities, fixing error message bug in archive
activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/disk/journal/DataFile.java Migrated delete method to use IOHelper.deleteFileNonBlocking
activemq-broker/src/main/java/org/apache/activemq/util/LockFile.java Updated unlock method to use non-blocking deletion
activemq-kahadb-store/pom.xml Whitespace cleanup (trailing space removal)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jeanouii jeanouii force-pushed the fix/exclude-JournalArchiveTest-from-windows-builds branch from 7d63f1e to 9e8410e Compare February 12, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants