datahike

Andrew Huggins 2024-06-07T13:14:09.050589Z

I have been developing with datahike on Linux without issue, but when I run on Windows 10 I get the error below. I have full read/write permissions on the directory as well. I have run the process with User and Admin privileges and get the same error. Has anyone else come across this error when running on Windows 10?

Caused by: java.nio.file.AccessDeniedException: C:\Users\ahuggins\Downloads\arena-db-win-release-2024.06.05.2\windows-jre\bin\.arena_db_data\1643fed1-9f2d-514e-b007-53bbb8682214.ksv.new -> C:\Users\ahuggins\Downloads\arena-db-win-release-2024.06.05.2\windows-jre\bin\.arena_db_data\1643fed1-9f2d-514e-b007-53bbb8682214.ksv
        at java.base/sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
        at java.base/sun.nio.fs.WindowsFileCopy.move(Unknown Source)
        at java.base/sun.nio.fs.WindowsFileSystemProvider.move(Unknown Source)
        at java.base/java.nio.file.Files.move(Unknown Source)
        at konserve.filestore.BackingFilestore._atomic_move(filestore.clj:150)
        at konserve.impl.defaults$update_blob.invokeStatic(defaults.cljc:56)
        at konserve.impl.defaults$update_blob.invoke(defaults.cljc:50)
        at konserve.impl.defaults$io_operation.invokeStatic(defaults.cljc:237)
        at konserve.impl.defaults$io_operation.invoke(defaults.cljc:233)
        at konserve.impl.defaults.DefaultStore._assoc_in(defaults.cljc:356)
        at konserve.core$assoc_in.invokeStatic(core.cljc:146)
        at konserve.core$assoc_in.invoke(core.cljc:139)
        at konserve.core$assoc.invokeStatic(core.cljc:159)
        at konserve.core$assoc.invoke(core.cljc:152)
        at datahike.writing$fn__33694.invokeStatic(writing.cljc:236)
        at datahike.writing$fn__33694.doInvoke(writing.cljc:177)
        at clojure.lang.RestFn.invoke(RestFn.java:423)
        at datahike.writing$fn__33662$G__33642__33669.invoke(writing.cljc:172)
        at datahike.writing$create_database.invokeStatic(writing.cljc:260)
        at datahike.writing$create_database.doInvoke(writing.cljc:256)
        at clojure.lang.RestFn.invoke(RestFn.java:410)
        at clojure.lang.AFn.applyToHelper(AFn.java:154)
        at clojure.lang.RestFn.applyTo(RestFn.java:132)
        at clojure.core$apply.invokeStatic(core.clj:667)
        at clojure.core$apply.invoke(core.clj:662)
        at datahike.writer$fn__34618.invokeStatic(writer.cljc:160)
        at datahike.writer$fn__34618.doInvoke(writer.cljc:158)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.lang.MultiFn.invoke(MultiFn.java:229)
        at clojure.lang.AFn.applyToHelper(AFn.java:154)
        at clojure.lang.AFn.applyTo(AFn.java:144)
        at clojure.core$apply.invokeStatic(core.clj:667)
        at clojure.core$apply.invoke(core.clj:662)
        at datahike.api.impl$create_database.invokeStatic(impl.cljc:42)
        at datahike.api.impl$create_database.doInvoke(impl.cljc:41)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at arena.db$initialize_db.invokeStatic(db.clj:14)
        at arena.db$initialize_db.invoke(db.clj:11)
        at arena.core$fn__55857.invokeStatic(core.clj:44)
        at arena.core$fn__55857.invoke(core.clj:44)
        at donut.system$apply_stage_fn.invokeStatic(system.cljc:612)
        at donut.system$apply_stage_fn.invoke(system.cljc:609)
        at donut.system$handler_stage_fn$fn__55644.invoke(system.cljc:693)
        at donut.system$apply_signal_stage$fn__55657.invoke(system.cljc:746)
        ... 14 more

Andrew Huggins 2024-06-09T17:50:16.310679Z

I think you are right. I will try a test with the konserve library next.

whilo 2024-06-09T20:03:40.455159Z

That is very helpful, thanks! It would be cool if we can make sure it runs smoothly on Windows, there is no reason why it shouldn't.

Andrew Huggins 2024-06-08T19:32:15.402009Z

Andrew Huggins 2024-06-08T19:33:29.344989Z

Thanks for the reply! The small test I made works just fine. Here's the code for the small test. Also a screen grab of the error when initializing datahike and the directory contents.

whilo 2024-06-08T20:55:14.569479Z

Weird. I assume you ran your script in the same folder the db lives in.

Andrew Huggins 2024-06-08T21:25:15.445749Z

Is this what you mean?

whilo 2024-06-08T21:25:44.421859Z

yes

Andrew Huggins 2024-06-08T21:27:13.749899Z

It was able to run inside there and replace the file contents without error.

whilo 2024-06-08T21:28:02.499329Z

That is super weird.

whilo 2024-06-08T21:28:56.790339Z

What happens if you use the same absolute paths as in the Exception?

Andrew Huggins 2024-06-08T21:41:19.044769Z

Andrew Huggins 2024-06-08T21:41:22.632749Z

I changed the function to use the absolute path as shown in the snippet. It ran without error.

whilo 2024-06-08T21:43:39.706909Z

Ok, thanks! The only other thing I can think of is different file access rights for the files created by datahike/konserve. Could you compare those against the files you created manually?

Andrew Huggins 2024-06-08T21:53:37.884449Z

These are screenshots of permissions for the test, ksv, and ksv.new files respectively.

whilo 2024-06-08T21:55:35.154979Z

They look the same, right?

Andrew Huggins 2024-06-08T21:57:56.504119Z

Sorry, yes the are the same.

whilo 2024-06-08T22:13:56.230599Z

This is the konserve code used https://github.com/replikativ/konserve/blob/main/src/konserve/filestore.clj#L152, it looks the same as what you have.

whilo 2024-06-08T22:34:04.312599Z

The only thing I could imagine being a problem would be something weird with the path construction, but it looks ok. I don't have access to a Windows machine right now, can you open an issue to keep track of this? Also if you have ideas feel free to bring them up as well.

Andrew Huggins 2024-06-09T02:05:02.358509Z

I agree. It has baffled me for the past few days. I will open an issue so that there is record of what I am seeing. Thank you for your help!

whilo 2024-06-09T02:51:29.839789Z

It would be reasonable to git clone a local konserve copy and put it into your deps and then instrument these lines to see a bit more clearly what is exactly invoked and how it compares to your code snippet.

Andrew Huggins 2024-06-14T12:17:56.393729Z

Sorry, I failed to give my conclusion. The goal of the example code was to reproduce the same symptoms that I am experiencing with konserve and datahike on Windows. It suggests that, in konserve, a file might still be locked for some reason while being moved to/from resulting in an AcessDenied error. I have not read enough of the konserve code base to have confirmed that hypothesis yet. Also note that the example code runs just fine on Linux. As for possible workarounds, maybe a slight delay added between closing the file and calling move. I plan to read more into the konserve code for assoc-in soon and test some ideas.

whilo 2024-06-14T20:48:27.019059Z

Yes, that makes sense.

whilo 2024-06-13T23:46:16.418739Z

Did you get any further insights?

Andrew Huggins 2024-06-14T00:17:37.170709Z

Andrew Huggins 2024-06-14T00:17:44.995579Z

I have. I was able to reproduce the error with a minimal example that held a target path open for sometime and then try to move to it. Here's the code and a screenshot of the error.

Andrew Huggins 2024-06-14T00:18:55.439349Z

The error also occurs with konserve when calling the assoc-in fn. From what I have read, it seems that the move function doesn't have a good history with windows.

whilo 2024-06-14T03:31:00.808569Z

oh no 🤨

whilo 2024-06-14T03:31:11.754899Z

Any suggestions for workarounds?

whilo 2024-06-14T03:32:52.331809Z

In your example the file is still open for writing when it is moved. Maybe we can change that. We could also have a special implementation for Windows.

whilo 2024-06-08T01:21:11.577269Z

Strange, we use this call https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#move-java.nio.file.Path-java.nio.file.Path-java.nio.file.CopyOption...- with ATOMIC_MOVE option. Can you try that manually independently of Datahike?