Files
maven-mvnd/common
Stefan Oehme bb1191e4c6 Make DaemonRegistry concurrency-safe (#1281)
The previous implementation had two issues:

The memmory-mapped file was created in the constructor and ignored file expansions by other
threads or processes. It would then overwrite the file with its own, smaller size buffer.
Replaced the memory mapping with a regular InputStream/OutputStream approach. Memory mapping
is not very useful in this scenario anyway, since the file is small and infrequently read and
we always read/write the entire file.

The tryLock method was broken and only tried locking once. If the lock could not be acquired,
it returned null and the subsequent code then ignored that fact and proceeded without locking.
I've moved the retry loop and failure handling into the lock method, which gives it the intended
behavior of waiting for a lock for 20s and then failing.

The test expectation for the "big registry" test has changed, since we no longer
manually increase the file size to multiples of two, but instead simply write out
exactly the bytes we need.

I droped the String size requirement, since DataInputStream handles arbitrarly
long Strings. I also changed the exception handling to consistently do recovery
on any kind of exception while reading/writing, since it is reasonable to assume
that any such exception indicates a broken registry file. I've also adjusted the
user-facing message to only tell them to delete the file if recovery fails.
2025-03-07 18:34:44 +01:00
..