Commit
cbcc8e8720202ad6022fb21f7bf8bc1468f3a85c
by md_5Make region files more reliable to write to
Previously we would write to header before writing our chunk data,
which opens a window for corruption (or we would overwrite entirely).
Now the saving process has been changed to follow this chain of events:
1. We always allocate a new space to write so we do not potentially
overwrite and corrupt the current data
2. Write the chunk data first (the order of the fields in
the chunk data isn't relevant though)
3. Flush to disk (if the launch flag is used)
4. Write to the region header last
5. Flush to disk (if the launch flag is used)
6. Then we free the previous space allocated
With this chain of events it is impossible for a chunk write to corrupt
a region file, unless the operating system has messed around with the order
of our writes or if it has lied about us flushing (if applicable).
However server administrators are still recommended to continue performing
regular backups.
If the spigot.flush-on-save startup flag is set to true, then the
steps 3 and 5 will make a call to sync() on the region file's fd,
effectively flushing to disk. For people running on harddrives this
is not recommended since you will incur a very significant performance
hit. As such the option is disabled by default.