distributed_lock¶
Configuration for locking servers
Checks the environment variable ISF_DISTRIBUTED_LOCK_CONFIG
for a path to a .yml
file providing file locking configuration.
The following locking servers/types are supported:
Locking Server |
Description |
Documentation |
---|---|---|
Redis |
In-memory data structure store used as a database, cache, and message broker. |
|
Zookeeper |
Centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services. |
|
File |
Fasteners file-based locking. |
|
If no such file exists, or the environment variable is not set, a default configuration is used, which uses (in order of decreasing precedence):
A redis server running on
spock
at port8885
A redis server running on
localhost
at port6379
File-based locking.
Example:
>>> os.environ["ISF_DISTRIBUTED_LOCK_CONFIG"] = config_path
>>> with open(config_path, "r" ) as f:
... config = yaml.load(f, Loader=YamlLoader)
>>> config
[{'type': 'zookeeper', 'config': {'hosts':'localhost', 'port': 8885'}}]
# or
>>> DEFUALT_CONFIG
[{'type': 'redis', 'config': {'host': 'spock', 'port': 8885, 'socket_timeout': 1}},
{'type': 'redis', 'config': {'host': 'localhost', 'port': 6379, 'socket_timeout': 1}},
{'type': 'file'}]
Classes¶
Check if the target file or directory has write access, and only lock it if so. |
Functions¶
Get the file locking client object, depending on the file locking configuration. |
|
Get the locking client |
|
Get the locking server |
|
Update the global configuration variables with the provided configuration. |
|
|
Fetch the correct lock, depending on global locking server configuration. |
|
Fetch the correct read lock, depending on global locking server configuration. |
|
Fetch the correct write lock, depending on global locking server configuration. |