Code Monkey home page Code Monkey logo

riak_preflists's Introduction

Riak Preflists

This app is a distilled example of an approach used in a couple of riak-based applicaitons I've seen. As you may know Riak allows to contact any node with any request. Although client is greatly simplified this way, there are cases when you want to contact "the right" node for a key. This simple application on being injected into Riak node exposes routing information through a simple HTTP API.

API

All API endpoints piggybacks on Riak's HTTP interface, so host and port are the same.

Ring status

GET /riak_preflists/ringstatus Returns a json hash table of hosts and what part of the continuum they own.

For example:
curl http://localhost:8881/riak_preflists/ringstatus
returns something like:

{"0":"[email protected]",
 "22835963083295358096932575511191922182123945984":"[email protected]",
 "45671926166590716193865151022383844364247891968":"[email protected]",
   ...
  "1415829711164312202009819681693899175291684651008":"[email protected]",
  "1438665674247607560106752257205091097473808596992":"[email protected]"
}

Nodelists

GET /riak_preflists/nodelists/buckets/Bucket/keys/Key Returns a list of hostnames for the Bucket and key Key in the form of JSON array.

For example:
curl http://localhost:8881/riak_preflists/nodelists/buckets/foo/keys/bar
returns ["sumerman-mbpr.local"] on my machine :)

Ring update notifications

Having to ask nodelist for every request may defeat the purpose of exposing it. But if one wants to cache it, (s)he needs a way to invalidate the cache. So this endpoint provides such a way.

GET /riak_preflists/notifications[?ping=N] Returns an endless chunked stream of either ping\n or update\n. Pings are there as a means of health-check while an update is a sign to invalidate a cache of nodelists. The optional parameter allows to specify an interval in seconds between pings (1 sec by default).

Build

  • To build for injection just issue make.
  • If you want to play with it in a standalone mode issue make standalone. But beware, it will download and compile almost whole riak :)

Run standalone

Open the first console and cd into the app's directory, then$ ./start.sh, wait a bit until everything starts up, then (in the erlang console) issue node()

Open the second one and do the$ ./start.sh 2, wait a bit again, then type riak_core:join('first_node@name') where first_node@name is the thing returned by node() in the first console.

You can join up to 9 nodes in the same way.

API ports for the nodes are 8881, 8882, ... respectively.

Inject into Riak

Just add

-pa /path/too/riak_preflists/ebin
-s riak_preflists_app

to your vm.args file

You should see in the log something like

Application riak_preflists started on node '[email protected]'

When running into Riak, the REST API will be available under the same port as Riak's one, so 8098 by default.

riak_preflists's People

Contributors

sumerman avatar dams avatar

Watchers

 avatar 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.