Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite implementation of Xandra.Cluster #318

Merged
merged 8 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,74 +182,3 @@ jobs:
- name: Dump Docker logs on failure
uses: jwalton/gh-docker-logs@v1
if: failure()

test_clustering:
name: Test C* Clustering (Elixir ${{ matrix.elixir }}, OTP ${{ matrix.otp }}, C* ${{ matrix.cassandra_version }}, Native protocol ${{ matrix.cassandra_native_protocol }})
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- otp: "24.2"
elixir: "1.13"
cassandra_version: "4.1"
cassandra_native_protocol: "v5"
- otp: "24.2"
elixir: "1.13"
cassandra_version: "4.1"
cassandra_native_protocol: "v4"
- otp: "24.2"
elixir: "1.13"
cassandra_version: "3"
cassandra_native_protocol: "v3"
- otp: "24.2"
elixir: "1.13"
cassandra_version: "3"
cassandra_native_protocol: "v4"
# Oldest supported Elixir/OTP matrix. We support down to Erlang 21, but
# rustler_precompiled (which we use for nimble_lz4, which we use for testing)
# requires OTP 23+.
- otp: "23.3"
elixir: "1.11"
cassandra_version: "3"
cassandra_native_protocol: "v3"
env:
CASSANDRA_VERSION: ${{ matrix.cassandra_version }}
CASSANDRA_NATIVE_PROTOCOL: ${{ matrix.cassandra_native_protocol }}

steps:
- name: Clone the repository
uses: actions/checkout@v2

- name: Start Docker and wait for it to be up
run: |
docker-compose up --detach --build
./test/docker/health-check-services.sh

- name: Install OTP and Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}

- name: Cache dependencies
id: cache-deps
uses: actions/cache@v2
with:
path: |
deps
_build
key: ${{ runner.os }}-otp${{ matrix.otp }}-elixir${{ matrix.elixir }}-${{ hashFiles('**/mix.lock') }}

- name: Install and compile dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: |
mix deps.get --only test
mix deps.compile

- name: Run clustering end-to-end tests
run: mix test.clustering

- name: Dump Docker logs on failure
uses: jwalton/gh-docker-logs@v1
if: failure()
7 changes: 2 additions & 5 deletions lib/xandra.ex
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,8 @@ defmodule Xandra do
"""
],

# Internal, used by Xandra.Cluster.
registry: [
doc: false,
type: :atom
]
# Internal options, used by Xandra.Cluster.
cluster_pid: [doc: false, type: :pid]
]

@start_link_opts_keys Keyword.keys(@start_link_opts_schema)
Expand Down
18 changes: 13 additions & 5 deletions lib/xandra/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ defmodule Xandra.Cluster do

"""

alias Xandra.{Batch, ConnectionError, Prepared, RetryStrategy}
alias Xandra.Cluster.{ControlConnection, Pool}
alias Xandra.{Batch, ConnectionError, OptionsValidators, Prepared, RetryStrategy}
alias Xandra.Cluster.{ControlConnection, Host, Pool}

@typedoc """
A Xandra cluster.
Expand Down Expand Up @@ -268,7 +268,7 @@ defmodule Xandra.Cluster do
"""
],
name: [
type: :any,
type: {:custom, OptionsValidators, :validate_genstatem_name, []},
doc: """
The name to register this cluster under. Follows the name registration rules of `GenServer`.
"""
Expand Down Expand Up @@ -308,8 +308,7 @@ defmodule Xandra.Cluster do
# Internal for testing, not exposed.
xandra_module: [type: :atom, default: Xandra, doc: false],
control_connection_module: [type: :atom, default: ControlConnection, doc: false],
test_discovered_hosts: [type: :any, default: [], doc: false],
registry_listeners: [type: :any, default: [], doc: false]
test_discovered_hosts: [type: :any, default: [], doc: false]
]

@start_link_opts_schema_keys Keyword.keys(@start_link_opts_schema)
Expand Down Expand Up @@ -546,6 +545,15 @@ defmodule Xandra.Cluster do
Pool.stop(cluster, reason, timeout)
end

@doc """
Returns a list of hosts that the cluster has outgoing connections to.
"""
@doc since: "0.18.0"
@spec connected_hosts(cluster) :: [Host.t()]
def connected_hosts(cluster) do
Pool.connected_hosts(cluster)
end

defp with_conn_and_retrying(cluster, options, fun) do
RetryStrategy.run_with_retrying(options, fn -> with_conn(cluster, fun) end)
end
Expand Down
Loading
Loading