Exception in NativeSession.moveFile method

42 views
Skip to first unread message

mqca...@gmail.com

unread,
Feb 10, 2014, 9:58:33 AM2/10/14
to xad...@googlegroups.com
Hello,
As I said in title, I encountered a "java.util.ConcurrentModificationException" creating a file and moving the folder (two level up) containing it in the same transaction.

My file system before starting the transaction looks like:


/xa4test
   |-- input_folder
   |   `-- folder_1
   |       `-- folder_2   <--- empty folder
   |           
   |-- output_folder   <--- empty folder


What I would like to do in one transaction is:

1 - create a file (foo.bar) in folder_2:
/xa4test
   |-- input_folder
   |   `-- folder_1
   |       `-- folder_2  
   |           `-- foo.bar
   |
   |-- output_folder   <--- empty folder
2 - move folder_1 in output_folder:

/xa4test
   |-- input_folder     <--- empty folder
   |
   |-- output_folder  
   | `-- folder_1
   |       `-- folder_2  
   |           `-- foo.bar
3 - commit

This is the code:

1 - Session session = xaFileSystem.createSessionForLocalTransaction();
2 - session.createFile(new File("/xa4test/input_folder/folder_1/folder_2/foo.bar"), false);
3 - session.moveFile(new File("/xa4test/input_folder/folder_1"), new File("/xa4test/output_folder/folder_1"));
4 - session.commit();

... line 3 fails with this exception:

Exception in thread "main" java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:926)
at java.util.HashMap$KeyIterator.next(HashMap.java:960)
at org.xadisk.filesystem.virtual.TransactionVirtualView.updateDescendantVVDsWithPrefix(TransactionVirtualView.java:250)
at org.xadisk.filesystem.virtual.TransactionVirtualView.moveDirectory(TransactionVirtualView.java:237)
at org.xadisk.filesystem.NativeSession.moveFile(NativeSession.java:312)


Thank you,
Marco


Nitin Verma

unread,
Feb 10, 2014, 12:41:26 PM2/10/14
to xad...@googlegroups.com, mqca...@gmail.com
Hello Marco,

I have tested this code and can see the issue. This is a bug as there are modifications to the hashmap inside the loop which is iterating over the same map's keys (see TransactionVirtualView.java, for-loop in method updateDescendantVVDsWithPrefix, modification to virtualViewDirs map in call updateVVDWithPath).

I am creating a tracking bug for this: https://java.net/jira/browse/XADISK-160

You can create a local patch to fix this, just use an array to hold the keys of the virtualViewDirs and then iterate over the array, i.e.
replace:
        for (File dirName : virtualViewDirs.keySet()) {

with:
        File[] dirNames = virtualViewDirs.keySet().toArray(new File[0]);
        for (File dirName : dirNames) {


Please note that, once you fix it you will see another issue saying "direction changes could not be forced to disk". I have created a tracking bug for this too: https://java.net/jira/browse/XADISK-161. For the time being, you can use a work around by switching off directory synchronization through the method: https://xadisk.java.net/javadoc/1.2.2/org/xadisk/filesystem/FileSystemConfiguration.html#setSynchronizeDirectoryChanges%28java.lang.Boolean%29

Please let me know if you have any questions.

Thanks,
Nitin

mqca...@gmail.com

unread,
Feb 11, 2014, 10:21:38 AM2/11/14
to xad...@googlegroups.com, mqca...@gmail.com
Hello Nitin,
Thanks for answering (as usual) so quickly! 
Unfortunately I cannot turn off synchronization beacuse I need directory changes to be synchronized during transaction commit.
As temporary fix I will recursively move every folder in a loop.

Thank you
Marco
Reply all
Reply to author
Forward
0 new messages