Open blagoev opened 3 years ago
➤ On 2022-03-25, bmunkholm commented:
[~yavor.georgiev] Do you know if this has been done?
➤ On 2022-03-25, fealebenpae commented:
No, this hasn’t been addressed yet.
➤ On 2022-03-25, bmunkholm commented:
Oh , that's interesting as the comment has been removed now :-)
➤ On 2022-03-25, fealebenpae commented:
It’s just in a different place now: https://github.com/realm/realm-core/blob/798335cf1cc054ae7abbe1d2c7e1efd2d7e982a5/src/realm/db.cpp#L1389
This is coming up in the context of the Kotlin SDK. How tricky would this be to fix?
It's somewhat tricky. There isn't a clear-cut API that promises atomicity on Windows without caveats, unless we want to start enforcing same-volume origin when renaming files, and even then there are other caveats from what I can tell. It's safer to use the shouldCompactOnLaunch
configuration option in any case, I believe.
Currently we have this comment that
compact
is not atomic and safe on Windows https://github.com/realm/realm-core/blob/0a4c622924018b434af293f9ec2bb9c6b2edbc01/src/realm/db.hpp#L283-L284 After a short discussion we have decided that sincecompact()
is already exposed in Realm JS on Windows https://github.com/realm/realm-js/blob/master/src/js_realm.hpp#L339 we could improve the compact operation and make it atomic by using MoveFileEx using MOVEFILE_REPLACE_EXISTING and possibly MOVEFILE_WRITE_THROUGH flags which should result in an atomic and safe move on NTFS on Windows