data_basedistributed_lock

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.

Redis Documentation

Zookeeper

Centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services.

Zookeeper Documentation

File

Fasteners file-based locking.

InterProcessLockNoWritePermission and Fasteners Documentation

If no such file exists, or the environment variable is not set, a default configuration is used, which uses (in order of decreasing precedence):

  1. A redis server running on spock at port 8885

  2. A redis server running on localhost at port 6379

  3. 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

InterProcessLockNoWritePermission

Check if the target file or directory has write access, and only lock it if so.

Functions

get_locking_server_client()

Get the file locking client object, depending on the file locking configuration.

get_locking_client()

Get the locking client

get_locking_server()

Get the locking server

update_config(c)

Update the global configuration variables with the provided configuration.

get_lock(name)

Fetch the correct lock, depending on global locking server configuration.

get_read_lock(name)

Fetch the correct read lock, depending on global locking server configuration.

get_write_lock(name)

Fetch the correct write lock, depending on global locking server configuration.