Giter VIP home page Giter VIP logo

monotone's Introduction

monotone

A 64 bit monotonically increasing Id generator for distributed databases.

Build Status

Purpose

As soon as you make a departure from an RDBMS for record based storage, you find yourself needing to generate Id's for those records as it's no longer afforded to you in most No-Sql stores.

We wanted to provide a simple solution to this that reused popular infrastructure that companies likely already have running.

Design

  • Monotone is a very simple wrapper around popular storage enginges capable of generating monotonically increasing id's that are not vulnerable to the challenges surrounding coorindated system clocks.

  • Underyling storage engine maven depdencies are scoped to provided so as to not pollute your depdendency tree for unused storage engine implementations.

  • A clean interface with fluent style builders and no checked exceptions is exposed to your codebase.

  • Monotone stores local ranges after it reserves them by incrementing a counter in the underlying storage engine implemtnation via atomic supported operations. This permits fast increments via a local AtomicLong in your application and only making a network hop when you have exhausted the local range.

ZooKeeper Support

Details

You may want to tune the setMaxIdsToFetch coniguration to your needs as this will dictate how frequent you have to do a write to ZK.

This implementation has an upper bound to its performance, even with a higher limit on setMaxIdsToFetch configured. This is mainly because the implementation does not use sharded counters. This is under consideration for future development.

If setMaxAttempts is reached, a RuntimeException is thrown.

Dead Simple Example

IdGenerator gen = ZKGenerator.newBuilder(zkClient).build();             
long nextId = gen.nextId();

Configuration Example

IdGenerator gen = ZKGenerator.newBuilder(zkClient)
                             .setCounterName("orders")
                             .setMaxIdsToFetch(1000)
                             .setRootPath("/id_gen/my_app")
                             .build();
                             
long nextId = gen.nextId();

Configuration

Setting Default Value Description
setCounterName "default" The name of your counter that will be stored in ZK. Cannot be null.
setMaxIdsToFetch 1000 The number of Id's to reserve for a given local range. Needs to be greater than 0.
setRootPath "/monotone/id_gen" The root path in ZK where the counter should live. Cannot be null.
setMaxAttempts 5 The number of times an incr operation will occur if a failure response is given by ZK. Needs to be greater than 0.

Redis Support

License

Free as in beer

monotone's People

Contributors

mgreene avatar atironati avatar

Watchers

James Cloos 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.