Skip to content

Instantly share code, notes, and snippets.

@ukazap
Last active September 27, 2022 06:28
Show Gist options
  • Save ukazap/eeb89b989e62909086e276c7c47bdf3b to your computer and use it in GitHub Desktop.
Save ukazap/eeb89b989e62909086e276c7c47bdf3b to your computer and use it in GitHub Desktop.

Revisions

  1. 阿謙 revised this gist Sep 27, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion riak_core_cluster_formation.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    ## Set up libcluster

    Use libcluster to set up cluster automatically.
    Use [libcluster](https://github.com/bitwalker/libcluster) to set up cluster automatically.

    Add dependency in mix.exs and run `mix deps.get`:

  2. 阿謙 renamed this gist Sep 27, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. 阿謙 created this gist Sep 27, 2022.
    81 changes: 81 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,81 @@
    # riak_core cluster formation

    ## Set up libcluster

    Use libcluster to set up cluster automatically.

    Add dependency in mix.exs and run `mix deps.get`:

    ```elixir
    defp deps do
    [
    # ...
    {:libcluster, "~> 3.3"}
    # ...
    ]
    end
    ```

    Add Cluster.Supervisor process in the supervision tree of the app (usually in lib/appname/application.ex):

    ```elixir
    defmodule MyApp.App do
    use Application

    def start(_type, _args) do
    topologies = [
    local_udp_gossip_aja: [
    strategy: Cluster.Strategy.Gossip,
    config: [
    secret: "this_is_a_shared_secret"
    ]
    ]
    ]

    children = [
    {Cluster.Supervisor, [topologies, [name: MyApp.ClusterSupervisor]]},
    # ..other children..
    ]
    Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
    end
    end
    ```

    ## Running

    Run 3 nodes:

    ```shell
    MIX_ENV=node1 iex --name [email protected] --cookie this_is_a_shared_secret -S mix
    MIX_ENV=node2 iex --name [email protected] --cookie this_is_a_shared_secret -S mix
    MIX_ENV=node3 iex --name [email protected] --cookie this_is_a_shared_secret -S mix
    ```

    On node2 and node3 run:

    ```elixir
    :riak_core.join('[email protected]')
    ```

    On node1 run:

    ```elixir
    # To see the planned changes in the ring:
    :riak_core_claimant.plan()

    # Now we can commit the plan:
    :riak_core_claimant.commit()

    # Periodically run some of these:

    :riak_core_console.member_status([])

    :riak_core_handoff_manager.status()

    :riak_core_console.transfers([])

    {:ok, ring} = :riak_core_ring_manager.get_my_ring()
    :riak_core_ring.pretty_print(ring, [:legend])

    :riak_core_status.ringready()
    ```