Skip to main content

A vector clock

Project description

Introduction

A vector clock is a data structure used for determining the partial ordering of events in a distributed system and detecting causality violations.

See https://en.wikipedia.org/wiki/Vector_clock.

This implements a vector where each process has its own clock.

A typical description will have the counter start from 1 and increment by 1 every time there is a change.

However, this implementation allows the counter increase by whatever the client asks for. Our processes can set the counter to their own clock, hence allow us to resolve conflicts (unordered changes) by leaning towards later (more recent) object versions.

Using

>>> from vectorclock import VectorClock
>>> vca1 = VectorClock({"A":1})
>>> vca2 = VectorClock.from_string('{"A":2}')
>>> print(vca1 < vca2)
True
>>> print(vca1 != vca2)
True
>>> print(vca1 == vca2)
False
>>> print(vca1 > vca2)
False
>>> print(str(vca1))
{"A":1}

# these two clocks are not ordered
>>> vcb = VectorClock({"B": 1})
>>> print(vca1 == vcb)
False
>>> print(vca1 < vcb)
False
>>> print(vca1 > vcb)
False
# If tie-breaking is off, they are not ordered (but not equal!)
>>> print(vca1.compare(vcb, tiebreak=False))
0
# If tie-breaking is on, we pick an order (deterministically)
>>> print(vca1.compare(vcb, tiebreak=True))
-1

The rest of this README is for vectorclock developers.

Testing

python -m unittest discover -s tests

Building

python -m pip install --upgrade build
python -m build

See also https://packaging.python.org/en/latest/tutorials/packaging-projects/#generating-distribution-archives.

Uploading to pypi

python -m pip install twine
twine check dist/*
twine upload -r testpypi dist/*

Check that the distribution looks as expected. Now:

twine upload -r pypi dist/*

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

vectorclock-0.5.3.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vectorclock-0.5.3-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file vectorclock-0.5.3.tar.gz.

File metadata

  • Download URL: vectorclock-0.5.3.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.7

File hashes

Hashes for vectorclock-0.5.3.tar.gz
Algorithm Hash digest
SHA256 bd575cbd3dc3491116b6d9aafcd234958f2eb6e0bb7b36f6ceb9ca10888791ff
MD5 41576261d28122ec23d25890a9f5ae31
BLAKE2b-256 1b1edab269e183287389b47b51acb74b71eab4ade1f440d4bf2861d2d12a995b

See more details on using hashes here.

File details

Details for the file vectorclock-0.5.3-py3-none-any.whl.

File metadata

  • Download URL: vectorclock-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.7

File hashes

Hashes for vectorclock-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f82b91dc9fe62c0b26e93c35c50aec0550c04b6ad98ec880e2a3d8a9c3e0fe2e
MD5 6c5d271e5f7eedf559783f010cce95ce
BLAKE2b-256 519b3ef185a01d9048ddcab7ffaa574a8bff3a12d4bd06932928984cf20989f0

See more details on using hashes here.

Supported by

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