Skip to content

lightuponcloud/pydvv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Dotted Version Vector Sets

SWUbanner

This is an implementation of the Erlang's DVV on Python.

It is used in distributed systems, where UTC timestamp is unreliable value for object's version control.

Usage examples

  • Creating a new version
from dvvset import DVVSet
dvvset = DVVSet()
dot = dvvset.create(dvvset.new("something"), "user_id_1")
  • Incrementing version
context = dvvset.join(dot)
new_dot = dvvset.update(dvvset.new_with_history(context, "something else"), dot, "user_id_2")
dvvset.sync([dot, new_dot])
  • Detecting conflicts

Conflict is situation when two branches of the history exist. It could happen when someone updates old version ( casual history ).

merged_history = dvvset.sync([OldVersion, NewVersion])
if len(dvvset.values(merged_history)) > 1:
    print("Conflict detected")
else:
    print("Ok")

Example

  1. User 1 uploads file to the server, specifying version vector:
from dvvset import DVVSet
dvvset = DVVSet()
dot = dvvset.create(dvvset.new("something"), "user_id_1")
  1. Server checks version on a subject of conflict. Then it stores file with version information and provides it to User 2.
merged_history = dvvset.sync([ExistingVersion, UploadedVersion])
if len(dvvset.values(merged_history)) > 1:
    return "409 Conflict"
else:
    return "200 OK"  # Casual history is linear
  1. User 2 downloads file, edits it and increments its version, before uploading back to server.
context = dvvset.join(dot)  # ``dot`` is a downloaded version
new_dot = dvvset.update(dvvset.new_with_history(context, "something else"), dot, "user_id_2")
dvvset.sync([dot, new_dot])

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages