项目作者: hachreak

项目描述 :
Riak Core Demo (KV store)
高级语言: Erlang
项目地址: git://github.com/hachreak/riak_core_demo.git
创建时间: 2017-04-26T17:28:31Z
项目社区:https://github.com/hachreak/riak_core_demo

开源协议:Other

下载


riak_core_demo

This is a riak demo application following the elixir tutorials by
Gpad and adapting them to erlang

(@GPad/create-a-riak-core-application-in-elixir-part-1-41354c1f26c3">Part 1,
@GPad/create-a-riak-core-application-in-elixir-part-2-88bdec73f368">Part 2,
@GPad/create-a-riak-core-application-in-elixir-part-3-8bac36632be0">Part 3,
@GPad/create-a-riak-core-application-in-elixir-part-4-728512ece224">Part 4)

Build

  1. $ rebar3 compile

Run demo

Start the first node:

  1. rebar3 shell --name test1@127.0.0.1 --config config/vars_dev1.config
  2. 1> application:ensure_all_started(riak_core_demo).

Start the second node:

  1. rebar3 shell --name test2@127.0.0.1 --config config/vars_dev2.config
  2. 1> application:ensure_all_started(riak_core_demo).

Join the two nodes together (run from the first node):

  1. 2> riak_core:join('test2@127.0.0.1').

Ping

Test the ping (you can run from both nodes):

  1. 3> riak_core_demo:ping().

You should see messages from console like:

{pong, ....}

and in one of the two nodes (it’s pseudo random) a message like:

[ping received] from ...

Get/Put values in the store

  1. riak_core_demo:put(a, 1).
  2. riak_core_demo:put(b, 2).
  3. ...
  4. riak_core_demo:get(a).
  5. riak_core_demo:get(b).

Handoff

After you insert many data in the store, just try to disconnect
the second node from the cluster:

  1. riak_core:leave().

In the console you should be able to see the different messages.
Automatically, all information stored in the second node will be transfered
to the first node.

To reconnect again the second node, simply:

  1. application:ensure_all_started(riak_core_demo).
  2. riak_core:join('test1@127.0.0.1').

Again, you will see the handoff of some process from the first node and
part of the data will be transfered to the second node.

Coverage commands: keys() and values()

After you insert many data in the store, try to get the list of keys stored in
all nodes or list of values:

  1. riak_core_demo:keys().
  2. riak_core_demo:values().

Cluster status

Show cluster status:

  1. riak_core_demo:status().