Skip to content

lightuponcloud/jdvv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

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
DVVSet dvvSet = new DVVSet();
Clock dot = dvvSet.create(dvvSet.newDvv("1611600920427"), "user_id_1");
  • Incrementing version
List context = dvvSet.join(dot);
Clock newDot = dvvSet.update(dvvSet.newWithHistory(context, "1616682865530"), dot, "user_id_2");
List mergedHistory = dvvSet.sync(new Clock(dot.asList(), newDot.asList()));
  • Detecting conflicts

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

List values = dvvSet.values(mergedHistory);
if (values.size() > 1) {
    System.out.println("CONFLICT");
} else {
    System.out.println("OK");
}

Example

  1. User 1 uploads file to the server, specifying version vector:
DVVSet dvvSet = new DVVSet();
Clock dot = dvvSet.create(dvvSet.newDvv("1611600920427"), "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.
List mergedHistory = dvvSet.sync(new Clock(existingVersion, uploadedVersion));
List values = dvvSet.values(mergedHistory);
if (values.size() > 1) {
    // return 409 Conflict
} else {
    // return 200 OK
}
  1. User 2 downloads file, edits it and increments its version, before uploading back to server.
List context = dvvSet.join(dot);
Clock newDot = dvvSet.update(dvvSet.newWithHistory(context, "1616682865530"), dot, "user_id_2");
dvvSet.sync(new Clock(dot.asList(), newDot.asList()));

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages