https://github.com/ajermakovics/crdts
Simple Conflict-free Replicated Data Types (CRDTs) for Java
https://github.com/ajermakovics/crdts
Last synced: about 1 year ago
JSON representation
Simple Conflict-free Replicated Data Types (CRDTs) for Java
- Host: GitHub
- URL: https://github.com/ajermakovics/crdts
- Owner: ajermakovics
- License: mit
- Created: 2014-12-07T12:41:14.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-01-29T07:43:32.000Z (over 9 years ago)
- Last Synced: 2025-03-27T10:51:16.454Z (about 1 year ago)
- Language: Java
- Homepage:
- Size: 19.5 KB
- Stars: 35
- Watchers: 3
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-java - CRDTs
README
CRDTs
================
Simple [Conflict-free Replicated Data Types](http://en.wikipedia.org/wiki/Conflict-free_replicated_data_type) (CRDTs) for distributed systems. CRDTs on different replicas can diverge from one another but at the end they can be safely merged providing an eventually consistent value. In other words, CRDTs have a **merge** method that is *idempotent*, *commutative* and *associative*.
The following CRDTs are currently implemented:
- G-Counter - Grow only counter
- PN-Counter - Increment/decrement counter
- G-Set - Grow only set. Allows only adds
- 2P-Set - Two Phase Set. Allows adds and removes but an item can be removed only once
- OR-Set- Ovserved-Removed Set. Allows multiple adds and removes. Adds win in case of a conflict during merge.
Examples
===========
PN-Counter:
```java
PNCounter replica1 = new PNCounter<>();
replica1.increment("hostname1");
PNCounter replica2 = replica1.copy();
replica1.increment("hostname2");
replica2.decrement("hostname2");
replica1.merge( replica2 );
replica1.get(); // counter is 1
```
2-P Set:
```java
TwoPSet replica1 = new TwoPSet<>();
replica1.add("a");
replica1.add("b");
TwoPSet replica2 = replica1.copy();
replica2.remove("b");
replica2.add("c");
replica1.merge(replica2);
replica1.get(); // set is {"a", "c"}
```
Download
========
Maven/Gradle dependency: https://jitpack.io/#ajermakovics/crdts
Serialization
===========
All CRDT classes implement Java Serializable but you should be able to use any other library.
Requirements
============
Java 1.6
The only dependency is Google Guava
More info
=========
- http://book.mixu.net/distsys/eventual.html
- [A comprehensive study of
Convergent and Commutative Replicated Data Types](http://hal.upmc.fr/file/index/docid/555588/filename/techreport.pdf)
License
=======
MIT