Skip to content

Instantly share code, notes, and snippets.

@andytill
Last active July 27, 2016 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andytill/08ceb711063dfd9b5274468211fd0307 to your computer and use it in GitHub Desktop.
Save andytill/08ceb711063dfd9b5274468211fd0307 to your computer and use it in GitHub Desktop.
Quick Start for the Erlyberly EUG demo using Riak TS and Erlyberly

Riak TS commands

for node in {1..3}; do ~/riak_ts/dev/dev$node/bin/riak stop; done
for node in {1..3}; do ~/riak_ts/dev/dev$node/bin/riak start; done

Build the cluster

for node in {2..3}; do ~/riak_ts/dev/dev$node/bin/riak-admin cluster join 'dev1@127.0.0.1'; done

~/riak_ts/dev/dev1/bin/riak-admin cluster plan

~/riak_ts/dev/dev1/bin/riak-admin cluster commit

~/riak_ts/dev/dev1/bin/riak-admin member-status

Start the Riak TS Shell

All SQL examples can be executed through the Riak Shell.

~/riak_ts/dev/dev1/bin/riak-shell

Tracing Activities

Once the cluster is up, start erlyberly.

java -jar ~/erlyberly/target/*runnable.jar

erlyberly is a java process that connects to Riak TS just as if it is another erlang node. The cluster is configured with these node names and cookies.

Node Name Cookie
dev1@127.0.0.1 riak
dev2@127.0.0.1 riak
dev3@127.0.0.1 riak

Now choose one or more of the three debugging tracks, or do your own thing!

Create the Table

CREATE TABLE mytable (a SINT64 NOT NULL, b TIMESTAMP NOT NULL, PRIMARY KEY ((a,quantum(b,1,'s')),a,b));

The full allowed syntax is documented here. A table name can only be used once, and dropping tables is not supported. Use different tables names to create new tables.

Tracing Tail
  • riak_ql_parser:ql_parse/1 transforms string CREATE TABLE statements into an erlang record.
  • riak_kv_metadata_store_listener:handle_event/2 handles events where the ring metadata has changed, this is received by other nodes in the cluster.
  • riak_ql_ddl_compiler:compiler/1 compiles the erlang table records (ddl_v1{}) into erlang modules on each node. Reload the modules and filter on table name, try decompiling the source.

Write some data

First, create the table mytable above before writing data.

INSERT INTO mytable VALUES (1,1000);
INSERT INTO mytable VALUES (1,1100);
INSERT INTO mytable VALUES (1,1200);
INSERT INTO mytable VALUES (1,1300);
INSERT INTO mytable VALUES (1,1400);
INSERT INTO mytable VALUES (1,1500);
INSERT INTO mytable VALUES (1,1600);
INSERT INTO mytable VALUES (1,1700);
INSERT INTO mytable VALUES (1,1800);
INSERT INTO mytable VALUES (1,1900);
INSERT INTO mytable VALUES (1,2000);
INSERT INTO mytable VALUES (1,2100);
INSERT INTO mytable VALUES (1,2200);
INSERT INTO mytable VALUES (1,2300);
INSERT INTO mytable VALUES (1,2400);
INSERT INTO mytable VALUES (1,2500);
INSERT INTO mytable VALUES (1,2600);
INSERT INTO mytable VALUES (1,2700);
INSERT INTO mytable VALUES (1,2800);
INSERT INTO mytable VALUES (1,2900);
INSERT INTO mytable VALUES (1,3000);
Tracing Tail
  • riak_kv_w1c_worker:async_put/8 and riak_kv_w1c_worker:ts_batch_put/8.
  • riak_kv_vnode:handle_command/3
  • riak_kv_w1c_worker:handle_put_reply/3

Execute a query

First, create the table mytable and write some data before issuing a query.

SELECT * FROM mytable WHERE a = 1 AND b >= 1200 and b <= 4000;

Documentation on Riak TS queries is here.

Tracing Tail
  • riak_ql_parser:ql_parse/1 transforms string CREATE TABLE statements into an erlang record.
  • riak_kv_qry_compiler:compiler/3 splits the query into multiple sub queries to be executed around the cluster.
  • riak_kv_qry_coverage_plan:create_plan/5 and riak_kv_qry_coverage_plan:create_plan/6 decides which nodes execute the sub queries.
  • riak_kv_qry_worker:add_subquery_result/3 handles the results from the sub queries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment