From 80a802b4be52c92612a4d20bb246c00a78625937 Mon Sep 17 00:00:00 2001 From: sanmiguel Date: Wed, 11 Dec 2013 17:30:10 +0000 Subject: [PATCH 1/2] s/erlcassa/erlcql/ erlcassa's thrift implementation clashes with casbench's. erlcassa is nominally used as a cql client but was set up using thrift (which casbench does already) it was clearly labelled as alpha, and remains untouched in 2 years. erlcql is a real cql client, under active development and does not clash with casbench --- examples/cassandra_cql.config | 22 ++++-- rebar.config | 4 +- src/basho_bench_driver_cassandra_cql.erl | 88 ++++++++++++++---------- 3 files changed, 71 insertions(+), 43 deletions(-) diff --git a/examples/cassandra_cql.config b/examples/cassandra_cql.config index cd01e0b56..dc508076b 100644 --- a/examples/cassandra_cql.config +++ b/examples/cassandra_cql.config @@ -3,11 +3,18 @@ %% Run the following queries in a cqlsh session: %% CREATE KEYSPACE DEMO WITH strategy_class = SimpleStrategy AND strategy_options:replication_factor = 1; %% CREATE COLUMNFAMILY test (KEY varchar PRIMARY KEY, val blob); + +%% Cassandra v2.0.1 +%% DROP KEYSPACE DEMO; +%% CREATE KEYSPACE DEMO WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1' }; +%% USE DEMO; +%% CREATE COLUMNFAMILY test (KEY varchar PRIMARY KEY, val blob); + {mode, max}. -{duration, 10}. +{duration, 1}. -{concurrent, 1}. +{concurrent, 5}. {driver, basho_bench_driver_cassandra_cql}. @@ -19,13 +26,16 @@ {value_generator, {fixed_bin, 100}}. {cassandra_host, "localhost"}. -{cassandra_port, 9160}. +{cassandra_port, 9042}. {cassandra_keyspace, "DEMO"}. {cassandra_columnfamily, "test"}. {cassandra_column, "val"}. -%% {operations, [{insert, 1},{put, 1},{get, 1},{delete, 1}]}. -{operations, [{insert, 1}]}. +{operations, [{insert, 1},{put, 1},{get, 1},{delete, 1}]}. +%%{operations, [{insert, 1}]}. +%%{operations, [{put, 1}]}. +%%{operations, [{get, 1}]}. +%%{operations, [{delete, 1}]}. -{code_paths, ["./deps/erlcassa/ebin", "./deps/thrift/ebin"]}. \ No newline at end of file +{code_paths, ["./deps/erlcql/ebin"]}. diff --git a/rebar.config b/rebar.config index df5b0a8b4..c53c206a3 100644 --- a/rebar.config +++ b/rebar.config @@ -17,8 +17,8 @@ {git, "git://github.com/basho/casbench", "95ed55b494551577870984aeb1e0f683631a326f"}}, {thrift, ".*", {git, "git://github.com/lpgauth/thrift-erlang.git", {branch, "master"}}}, - {erlcassa, ".*", - {git, "git://github.com/ostinelli/erlcassa.git", + {erlcql, ".*", + {git, "git://github.com/rpt/erlcql.git", {branch, "master"}}}, {riakc, ".*", {git, "git://github.com/basho/riak-erlang-client", {tag, "1.4.1"}}}, diff --git a/src/basho_bench_driver_cassandra_cql.erl b/src/basho_bench_driver_cassandra_cql.erl index 6001a6563..679bea7e5 100644 --- a/src/basho_bench_driver_cassandra_cql.erl +++ b/src/basho_bench_driver_cassandra_cql.erl @@ -24,8 +24,7 @@ -export([new/1, run/4]). --include("basho_bench.hrl"). --include_lib("erlcassa/include/erlcassa.hrl"). +-include_lib("basho_bench/include/basho_bench.hrl"). -record(state, { client, keyspace, @@ -40,34 +39,48 @@ new(Id) -> Host = basho_bench_config:get(cassandra_host, "localhost"), - Port = basho_bench_config:get(cassandra_port, 9160), + Port = basho_bench_config:get(cassandra_port, 9042), Keyspace = basho_bench_config:get(cassandra_keyspace, "Keyspace1"), ColumnFamily = basho_bench_config:get(cassandra_columnfamily, "ColumnFamily1"), Column = basho_bench_config:get(cassandra_column, "Column"), % connect to client - {ok, C} = erlcassa_client:connect(Host, Port), - ?INFO("Id: ~p, Connected to Cassandra at Host ~p and Port ~p\n", [Id, Host, Port]), - - % use keyspace - {result, ok} = erlcassa_client:cql_execute(C, lists:concat(["USE ", Keyspace, ";"])), - - case erlcassa_client:cql_execute(C, lists:concat(["USE ", Keyspace, ";"])) of - {result, ok} -> + {ok, C} = erlcql:start_link(Host, [{port, Port}]), + error_logger:info_msg("Id: ~p, " + "Connected to Cassandra at Host ~p and Port ~p\n", [Id, Host, Port]), + + + case ksbarrier(C, Keyspace) of + ok -> {ok, #state { client = C, keyspace = Keyspace, columnfamily = ColumnFamily, column = Column}}; - {error, Reason} -> - ?FAIL_MSG("Failed to get a thrift_client for ~p: ~p\n", [Host, Reason]) + {error, Reason} -> + error_logger:error_msg("Failed to get a erlcql client for ~p: ~p\n", + [Host, Reason]) + end. + + +ksbarrier(C, Keyspace) -> + case erlcql:q(C, lists:concat(["USE ", Keyspace, ";"])) of + {ok, _KSBin} -> ok; + {error, not_ready} -> + %% Not ready yet, try again + timer:sleep(100), + ksbarrier(C, Keyspace); + {error, _} = Error -> + Error end. -run(get, KeyGen, _ValueGen, +run(get, KeyGen, _ValueGen, #state{client=C, columnfamily=ColumnFamily, column=Column}=State) -> Key = KeyGen(), - Query = lists:concat(["SELECT ", Column ," FROM ", ColumnFamily ," where KEY = '", Key ,"';"]), - case erlcassa_client:cql_execute(C, Query, proplist) of - {result, {rows, _Rows}} -> + Query = ["SELECT ", Column ," FROM ", ColumnFamily ," where KEY = '", Key ,"';"], + case erlcql:q(C, Query, one) of + {ok,void} -> + {ok, State}; + {ok, {_Rows, _Cols}} -> %% [Row|_] = Rows, %% KeyColumn = erlcassa_client:get_column("KEY", Row), {ok, State}; @@ -78,9 +91,14 @@ run(insert, KeyGen, ValueGen, #state{client=C, columnfamily=ColumnFamily, column=Column}=State) -> Key = KeyGen(), Val = ValueGen(), - Query = lists:concat(["INSERT INTO ", ColumnFamily , " (KEY, ", Column, ") VALUES ('", Key ,"', ", bin_to_hexstr(Val) ,");"]), - case erlcassa_client:cql_execute(C, Query) of - {result, ok} -> + Query = ["INSERT INTO ", ColumnFamily , + " (KEY, ", Column, ") VALUES " + "('", Key ,"', ", bin_to_hexstr(Val) ,");"], + + case erlcql:q(C, Query, any) of + {ok,void} -> + {ok, State}; + {ok, {_Rows, _Cols}} -> {ok, State}; Error -> {error, Error, State} @@ -89,9 +107,14 @@ run(put, KeyGen, ValueGen, #state{client=C, columnfamily=ColumnFamily, column=Column}=State) -> Key = KeyGen(), Val = ValueGen(), - Query = lists:concat(["UPDATE ", ColumnFamily, " SET '", Column, "' = ", bin_to_hexstr(Val), " WHERE KEY = '", Key, "';"]), - case erlcassa_client:cql_execute(C, Query, proplist) of - {result,ok} -> + Query = ["UPDATE ", ColumnFamily, + " SET ", Column, " = ", bin_to_hexstr(Val), + " WHERE KEY = '", Key, "';"], + + case erlcql:q(C, Query, any) of + {ok,void} -> + {ok, State}; + {ok, {_Rows, _Cols}} -> {ok, State}; Error -> {error, Error, State} @@ -99,9 +122,11 @@ run(put, KeyGen, ValueGen, run(delete, KeyGen, _ValueGen, #state{client=C, columnfamily=ColumnFamily}=State) -> Key = KeyGen(), - Query = lists:concat(["DELETE FROM ", ColumnFamily ," where KEY = '", Key ,"';"]), - case erlcassa_client:cql_execute(C, Query) of - {result, ok} -> + Query = ["DELETE FROM ", ColumnFamily ," WHERE KEY = '", Key ,"';"], + case erlcql:q(C, Query, any) of + {ok,void} -> + {ok, State}; + {ok, {_Rows, _Cols}} -> {ok, State}; Error -> {error, Error, State} @@ -113,14 +138,7 @@ hex(N) when N < 10 -> $0+N; hex(N) when N >= 10, N < 16 -> $a+(N-10). - -to_hex(N) when N < 256 -> - [hex(N div 16), hex(N rem 16)]. - -list_to_hexstr([]) -> - []; -list_to_hexstr([H|T]) -> - to_hex(H) ++ list_to_hexstr(T). bin_to_hexstr(Bin) -> - lists:concat(["abcdef0123",list_to_hexstr(binary_to_list(Bin))]). \ No newline at end of file + List = binary_to_list(Bin), + ["0x", [ [hex(N div 16), hex(N rem 16)] || N <- List, N < 256 ] ]. From b2d1ca5515d9a7413a145184137fe82dcbc2a023 Mon Sep 17 00:00:00 2001 From: sanmiguel Date: Fri, 13 Dec 2013 16:21:40 +0000 Subject: [PATCH 2/2] Remove outdated reference to erlcassa --- src/basho_bench_driver_cassandra_cql.erl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/basho_bench_driver_cassandra_cql.erl b/src/basho_bench_driver_cassandra_cql.erl index 679bea7e5..b293a9508 100644 --- a/src/basho_bench_driver_cassandra_cql.erl +++ b/src/basho_bench_driver_cassandra_cql.erl @@ -81,8 +81,6 @@ run(get, KeyGen, _ValueGen, {ok,void} -> {ok, State}; {ok, {_Rows, _Cols}} -> - %% [Row|_] = Rows, - %% KeyColumn = erlcassa_client:get_column("KEY", Row), {ok, State}; Error -> {error, Error, State}