不能让Xandra与Cassandra 3一起运行

时间:2018-05-29 15:29:01

标签: cassandra elixir

我尝试使用Elixir / Xandra库(https://github.com/lexhide/xandra

我在设置问题时遇到了问题。这是我的iex shell会话:

defmodule MyApp.CassandraAuth do
  @behaviour Xandra.Authenticator

  def response_body(options) do
    ["user:", "cassandra", "_password:", "cassandra"]
  end
end

{:ok, conn} = Xandra.start_link(
  nodes: ["127.0.0.1:9042", "127.0.0.1:9043"],
  authentication: {MyApp.CassandraAuth, user: "cassandra", password: "cassandra"},
  name: :xandra_pool,
  pool: Xandra.Cluster,
  after_connect: fn(conn) -> Xandra.execute(conn, "USE ks_test") end
)

{:ok, prepared} = Xandra.prepare(
  conn,
  "SELECT * FROM ts WHERE datapoint_id = ? ORDER BY time ASC LIMIT 10"
)

最后一次通话会导致以下错误:

17:09:24.134 [error] GenServer :xandra_pool terminating
** (FunctionClauseError) no function clause matching in Xandra.Cluster.handle_call/3
(xandra) lib/xandra/cluster.ex:162: Xandra.Cluster.handle_call({:checkout, #Reference<0.1872713690.1148452865.108070>, true, 15000}, {#PID<0.299.0>, #Reference<0.1872713690.1148452865.108071>}, %Xandra.Cluster{load_balancing: :random, node_refs: [{#Reference<0.1872713690.1148452865.107855>, nil}, {#Reference<0.1872713690.1148452865.107860>, nil}], options: [prepared_cache: #Reference<0.1872713690.1148583937.107852>, idle_timeout: 30000, authentication: {MyApp.CassizerAuth, [user: "cassandra", password: "cassandra"]}, after_connect: #Function<6.99386804/1 in :erl_eval.expr/5>], pool_module: DBConnection.Connection, pool_supervisor: #PID<0.302.0>, pools: %{}})
(stdlib) gen_server.erl:636: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:665: :gen_server.handle_msg/6
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.299.0>): {:checkout, #Reference<0.1872713690.1148452865.108070>, true, 15000}
State: %Xandra.Cluster{load_balancing: :random, node_refs: [{#Reference<0.1872713690.1148452865.107855>, nil}, {#Reference<0.1872713690.1148452865.107860>, nil}], options: [prepared_cache: #Reference<0.1872713690.1148583937.107852>, idle_timeout: 30000, authentication: {MyApp.CassandraAuth, [user: "cassandra", password: "cassandra"]}, after_connect: #Function<6.99386804/1 in :erl_eval.expr/5>], pool_module: DBConnection.Connection, pool_supervisor: #PID<0.302.0>, pools: %{}}
Client #PID<0.299.0> is alive
(stdlib) gen.erl:169: :gen.do_call/4
(stdlib) gen_server.erl:210: :gen_server.call/3
(db_connection) lib/db_connection/connection.ex:50:   DBConnection.Connection.checkout/2
(db_connection) lib/db_connection.ex:928: DBConnection.checkout/2
(db_connection) lib/db_connection.ex:750: DBConnection.run/3
(db_connection) lib/db_connection.ex:1141: DBConnection.run_meter/3
(db_connection) lib/db_connection.ex:538: DBConnection.prepare/3
(xandra) lib/xandra.ex:382: Xandra.prepare!/3

其次是

17:09:24.135 [error] GenServer #PID<0.302.0> terminating
** (FunctionClauseError) no function clause matching in Xandra.Cluster.handle_call/3
(xandra) lib/xandra/cluster.ex:162: Xandra.Cluster.handle_call({:checkout, #Reference<0.1872713690.1148452865.108070>, true, 15000}, {#PID<0.299.0>, #Reference<0.1872713690.1148452865.108071>}, %Xandra.Cluster{load_balancing: :random, node_refs: [{#Reference<0.1872713690.1148452865.107855>, nil}, {#Reference<0.1872713690.1148452865.107860>, nil}], options: [prepared_cache: #Reference<0.1872713690.1148583937.107852>, idle_timeout: 30000, authentication: {PortalTimeseries.CassizerAuth, [user: "cassandra", password: "cassandra"]}, after_connect: #Function<6.99386804/1 in :erl_eval.expr/5>], pool_module: DBConnection.Connection, pool_supervisor: #PID<0.302.0>, pools: %{}})
(stdlib) gen_server.erl:636: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:665: :gen_server.handle_msg/6
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: {:EXIT, #PID<0.301.0>, {:function_clause, [{Xandra.Cluster, :handle_call, [{:checkout, #Reference<0.1872713690.1148452865.108070>, true, 15000}, {#PID<0.299.0>, #Reference<0.1872713690.1148452865.108071>}, %Xandra.Cluster{load_balancing: :random, node_refs: [{#Reference<0.1872713690.1148452865.107855>, nil}, {#Reference<0.1872713690.1148452865.107860>, nil}], options: [prepared_cache: #Reference<0.1872713690.1148583937.107852>, idle_timeout: 30000, authentication: {MyApp.CassandraAuth, [user: "cassandra", password: "cassandra"]}, after_connect: #Function<6.99386804/1 in :erl_eval.expr/5>], pool_module: DBConnection.Connection, pool_supervisor: #PID<0.302.0>, pools: %{}}], [file: 'lib/xandra/cluster.ex', line: 162]}, {:gen_server, :try_handle_call, 4, [file: 'gen_server.erl', line: 636]}, {:gen_server, :handle_msg, 6, [file: 'gen_server.erl', line: 665]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]}}
State: {:state, {#PID<0.302.0>, Supervisor.Default}, :one_for_one, [], :undefined, 0, 5, [], 0, Supervisor.Default, {:ok, {%{intensity: 0, period: 5, strategy: :one_for_one}, []}}}

我做错了什么?

1 个答案:

答案 0 :(得分:0)

当您使用与创建集群不同的 pool 选项执行查询时会发生这种情况。

https://github.com/lexhide/xandra/issues/96#issuecomment-315735601

在本例中,您使用 pool:Xandra.Cluster 选项启动 Xandra。

执行查询时:

after_connect: fn(conn) -> Xandra.execute(conn, "USE ks_test")

您没有指定 pool 选项。要修复您可以使用的电话:

after_connect: fn(conn) -> Xandra.execute(conn, "USE ks_test", [], pool: Xandra.Cluster)

如果您使用 Xandra.Cluster 启动集群,但使用 Xandra 而不是 Xandra.Cluster 执行查询,我看到了相同或至少非常相似的问题:

   # cassandra_config includes "name: :cassandra"
   # children here will be used as part of starting a supervisor
   children = {
      .... other children here ...
      {Xandra.Cluster, cassandra_config}
   }

   # ... start the supervisor which starts the Xandra.Cluster instance named :cassandra

   # will error out
   Xandra.execute(:cassandra, "USE my_namespace")

   # work fine
   Xandra.Cluster.execute(:cassandra, "USE my_namespace")