GithubHelp home page GithubHelp logo

cinterloper / crdts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ajermakovics/crdts

0.0 1.0 0.0 456 KB

Simple Conflict-free Replicated Data Types (CRDTs) for Java

License: MIT License

Java 100.00%

crdts's Introduction

CRDTs

Simple Conflict-free Replicated Data Types (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:

        PNCounter<String> replica1 = new PNCounter<>();
        replica1.increment("hostname1");
        
        PNCounter<String> replica2 = replica1.copy();

        replica1.increment("hostname2");
        replica2.decrement("hostname2");
        
        replica1.merge( replica2 ); 
        replica1.get(); // counter is 1

2-P Set:

	TwoPSet<String> replica1 = new TwoPSet<>();

	replica1.add("a");
	replica1.add("b");
        
	TwoPSet<String> replica2 = replica1.copy();
	replica2.remove("b");
	replica2.add("c");

	replica1.merge(replica2); 
	replica1.get(); // set is {"a", "c"}

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

License

MIT

crdts's People

Contributors

ajermakovics avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.