Skip to main content

Python library that emulates the java-based dynamo-db-client from awslabs

Project description

Python DynamoDB Lock

https://img.shields.io/pypi/v/python_dynamodb_lock.svg https://img.shields.io/travis/mohankishore/python_dynamodb_lock.svg Documentation Status

This is a general purpose distributed locking library built on top of DynamoDB. It is heavily “inspired” by the java-based AmazonDynamoDBLockClient library, and supports both coarse-grained and fine-grained locking.

Features

  • Acquire named locks - with configurable retry semantics

  • Periodic heartbeat/update for the locks to keep them alive

  • Auto-release the locks if there is no heartbeat for a configurable lease-duration

  • Notify an app-callback function if the lock is stolen, or gets too close to lease expiry

  • Store arbitrary application data along with the locks

  • Uses monotonically increasing clock to avoid issues due to clock skew and/or DST etc.

  • Auto-delete the database entries after a configurable expiry-period

Consistency Notes

Note that while the lock itself can offer fairly strong consistency guarantees, it does NOT participate in any kind of distributed transaction.

For example, you may wish to acquire a lock for some customer-id “xyz”, and then make some changes to the corresponding database entry for this customer-id, and then release the lock - thereby guaranteeing that only one process changes any given customer-id at a time.

While the happy path looks okay, consider a case where the application changes take a long time, and some errors/gc-pauses prevent the heartbeat from updating the lock. Then, some other client can assume the lock to be abandoned, and start processing the same customer in parallel. The original lock-client will recognize that its lock has been “stolen” and will let the app know through a callback event, but the app may have already committed its changes to the database. This can only be solved by having the application changes and the lock-release be part of a single distributed transaction - which, as indicated earlier, is NOT supported.

That said, in most cases, where the heartbeat is not expected to get delayed beyond the lock’s lease duration, the implementation should work just fine.

Refer to an excellent post by Martin Kleppmann on this subject: https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html

Credits

History

0.9.0 (2018-10-28)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_dynamodb_lock-0.9.1.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

python_dynamodb_lock-0.9.1-py2.py3-none-any.whl (14.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file python_dynamodb_lock-0.9.1.tar.gz.

File metadata

  • Download URL: python_dynamodb_lock-0.9.1.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for python_dynamodb_lock-0.9.1.tar.gz
Algorithm Hash digest
SHA256 87b3659293cee4b023342b881ff9e4c9435ffec0c12e935a36ddca6829ffda07
MD5 e4f85f1297fcb7874b2f3e5bc39697ce
BLAKE2b-256 ac944aca685482ddba53e9c7b2eaf9b8e8f18012c0fd36ad67ca31e9b4699f07

See more details on using hashes here.

File details

Details for the file python_dynamodb_lock-0.9.1-py2.py3-none-any.whl.

File metadata

  • Download URL: python_dynamodb_lock-0.9.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for python_dynamodb_lock-0.9.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5a5c66d9bdbfdc37c53db38064dc8dd7a246e84bae09d5edb530befa5a347215
MD5 e3b23c8172a9c75a9b5fb0a2e8c7fc8f
BLAKE2b-256 d113dd519670814a5b7cb1f82e3db20bd41e1ad52eeaeb1ef49e0732ba80b0fe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page