Map data do not flush to disk on regular autosave
Expected behavior
map data do not flush to disk with autosave
Observed/Actual behavior
Playerdata and chunk data are saved properly to disk with autosave, but map data only save to disk on proper shutdown. Map data can be saved with autosave on Paper. If the folia server crashes, all the map data will be lost.
Steps/models to reproduce
It can be reproduce everytime as server crash or unexpected power off
Plugin and Datapack List
None
Folia version
Folia version 1.21.4-DEV-dev/hard-fork@cd49d65 (1970-01-01T00:00:00Z) (Implementing API version 1.21.4-R0.1-SNAPSHOT)
Other
No response
This bug is incredibly frustrating on servers that utilize map-based artwork. I'm really hoping that it can be addressed or some workaround can be suggested.
https://github.com/PaperMC/Folia/blob/ver/1.21.8/folia-server/minecraft-patches/features/0001-Region-Threading-Base.patch#L8697-L8698
Maybe because this change causes the auto save to no longer work
Found that running the following caused maps to save. Tried to be as unobtrusive to the overall logic as possible, hence why I'm targeting the DimensionDataStorage instead of the ServerLevel as a whole.
I am quite new to working with Folia so this may have unforseen implications regarding multithreading. It will probably be safer to run them inside the .globalRegionScheduler()
1.20 and below
Kotlin
(Bukkit.getServer() as CraftServer).server.overworld().dataStorage.save(true)
Java
((CraftServer) Bukkit.getServer()).getServer().overworld().getDataStorage().save(true);
1.21 and above
Kotlin
(Bukkit.getServer() as CraftServer).server.overworld().dataStorage.saveAndJoin()
Java
((CraftServer) Bukkit.getServer()).getServer().overworld().getDataStorage().saveAndJoin();
Likely to be caused by the mentioned patch file, although the original reason for disabling incremental saving in this circumstance seems to have been lost to time as the file has been renamed numerous times.
https://github.com/PaperMC/Folia/blob/ver/1.21.8/folia-server/minecraft-patches/features/0001-Region-Threading-Base.patch#L8697-L8698
Maybe because this change causes the auto save to no longer work
My temporary solution is to revert the line change mentioned above and add the following to the top of saveIncrementally()
if (doFull) {
this.getChunkSource().getDataStorage().scheduleSave();
return;
}
Similarly, only save DimensionDataStorage to avoid some unexpected problems
Also, if you get ConcurrentModificationException, you can add sync lock in collectDirtyTagsToSave() when looping this.cache
It has been running on my server for a few weeks, and the map data is auto saved normally. I haven't encountered any problems yet, but as mentioned above this is just my temporary solution