Fix/thread locking - #195
Conversation
|
@tpietzsch I added logic to handle cleanup of references, including stale references that were not released. I'll try and describe a bit here. FileKeyLockManager is a package-private singleton instance now, with static fields for the backing map. when a path is requested with |
|
One caveat to the current implementation; we only Again, all of this is only to handle the case where a declared |
* multiple read locks can be held across threads * only a single write lock can be held * still to do: holding a read lock does not prevent writing see #141
refactor: FileKeyLockManager is a static singleton now, and more KeyLockState logic is package-private Signed-off-by: Caleb Hulbert <cmhulbert@gmail.com>
Locks are not tied to the locking thread anymore. (A LockedChannel can be created by one thread and then be released by another thread). This required to replace ReentrantReadWriteLock with manual reader/writer counting guarded by Semaphores. LockedFileChannel is now created by KeyLockState (instead of FileKeyLockManager) because for releasing we need to distinguish between read and write locks. I revised clean-up of stale KeyLockStates by putting WeakReferences in the ConcurrentHashMap and adding a ReferenceQueue to remove entries whose KeyLockState has been GCed. I put no special logic to handle leaked LockedFileChannels (that are abandoned without being properly closed). Surprisingly, this still works. When the KeyLockState is GCed, its associated ChannelLock along with the existing FileChannel and FileLock is also GCed. At least on MacOS, this causes the JVM to release the system-level lock, and everything works out fine.
2bab2c3 to
5fac740
Compare
|
I revised locking so that locks are not tied to the locking thread. (A I revised clean-up of stale I put no special logic to handle leaked |
2d3b26b to
8a8975d
Compare
…nnel This fixes behaviour on Windows, where the we cannot open another FileChannel on the write-locked path. We have to use the channel that we locked.
8a8975d to
1724dc5
Compare
This PR introduced a ReentrantReadWriteLock based per-thread locking mechanism, backed by a single per-JVM FileLock, to support parallel reads while maintaining exlusive writes through the FileSystemKeyValueAccess
closes #141