LLFIO
v2.00
|
Scalable many entity shared/exclusive file system based lock. More...
#include "atomic_append.hpp"
Public Types | |
using | entity_type = shared_fs_mutex::entity_type |
The type of an entity id. | |
using | entities_type = shared_fs_mutex::entities_type |
The type of a sequence of entities. | |
Public Member Functions | |
atomic_append (const atomic_append &)=delete | |
No copy construction. | |
atomic_append & | operator= (const atomic_append &)=delete |
No copy assignment. | |
atomic_append (atomic_append &&o) noexcept | |
Move constructor. | |
atomic_append & | operator= (atomic_append &&o) noexcept |
Move assign. | |
const file_handle & | handle () const noexcept |
Return the handle to file being used for this lock. | |
virtual void | unlock (entities_type entities, unsigned long long hint) noexcept final |
Unlock a previously locked sequence of entities. | |
entity_type | entity_from_buffer (const char *buffer, size_t bytes, bool exclusive=true) noexcept |
Generates an entity id from a sequence of bytes. | |
template<typename T > | |
entity_type | entity_from_string (const std::basic_string< T > &str, bool exclusive=true) noexcept |
Generates an entity id from a string. | |
entity_type | random_entity (bool exclusive=true) noexcept |
Generates a cryptographically random entity id. | |
void | fill_random_entities (span< entity_type > seq, bool exclusive=true) noexcept |
Fills a sequence of entity ids with cryptographic randomness. Much faster than calling random_entity() individually. | |
result< entities_guard > | lock (entities_type entities, deadline d=deadline(), bool spin_not_sleep=false) noexcept |
Lock all of a sequence of entities for exclusive or shared access. | |
result< entities_guard > | lock (entity_type entity, deadline d=deadline(), bool spin_not_sleep=false) noexcept |
Lock a single entity for exclusive or shared access. | |
result< entities_guard > | try_lock (entities_type entities) noexcept |
Try to lock all of a sequence of entities for exclusive or shared access. | |
result< entities_guard > | try_lock (entity_type entity) noexcept |
Try to lock a single entity for exclusive or shared access. | |
Static Public Member Functions | |
static result< atomic_append > | fs_mutex_append (const path_handle &base, path_view lockfile, bool nfs_compatibility=false, bool skip_hashing=false) noexcept |
Protected Member Functions | |
virtual result< void > | _lock (entities_guard &out, deadline d, bool spin_not_sleep) noexcept final |
Scalable many entity shared/exclusive file system based lock.
Lock files and byte ranges scale poorly to the number of items being concurrently locked with typically an exponential drop off in performance as the number of items being concurrently locked rises. This file system algorithm solves this problem using IPC via a shared append-only lock file.
Caveats:
/tmp
if possible (file_handle::temp_file()
). If you really must use a non-extents based filing system, destroy and recreate the object instance periodically to force resetting the lock file's length to zero.If your OS doesn't have sane byte range locks (OS X, BSD, older Linuxes) and multiple objects in your process use the same lock file, misoperation will occur. Use lock_files instead.
Implement hole punching once I port that code from LLFIO v1.
Decide on some resolution mechanism for sudden process exit.
There is a 1 out of 2^64-2 chance of unique id collision. It would be nice if we actually formally checked that our chosen unique id is actually unique.
|
inlinefinalprotectedvirtualnoexcept |
Implements llfio_v2_xxx::algorithm::shared_fs_mutex::shared_fs_mutex.
|
inlinestaticnoexcept |
Initialises a shared filing system mutex using the file at lockfile
base | Optional base for the path to the file. |
lockfile | The path to the file to use for IPC. |
nfs_compatibility | Make this true if the lockfile could be accessed by NFS. |
skip_hashing | Some filing systems (typically the copy on write ones e.g. ZFS, btrfs) guarantee atomicity of updates and therefore torn writes are never observed by readers. For these, hashing can be safely disabled. |