Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
ignore cluster wal data
Browse files Browse the repository at this point in the history
  • Loading branch information
hailelagi committed Oct 29, 2023
1 parent 563da20 commit f4a0d32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ wave-*.tar
./postgres-two

./postgres-three

/wave-one@127.0.0.1
19 changes: 10 additions & 9 deletions lib/wave/state_machine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@ defmodule Wave.StateMachine do

# Cluster Management
def start do
:ra.start()
members = get_active_nodes()
machine_config = [:module, __MODULE__, %{}]
machine_config = {__MODULE__, %{}}

:ra.start_cluster(:wave_ledger, machine_config, members)
end

def replace_member do
:ra.start_cluster(:default, "wave_ledger", machine_config, members)
end

# State Machine
def init(_config) do
%{}
end

def apply(_command_meta_data, {:get, key}, state) do
def apply(_command_meta_data, {:get, key}, state) do
result = Map.get(state, key, :not_found)

{state, result}
Expand All @@ -38,9 +36,12 @@ defmodule Wave.StateMachine do
{Map.put(state, key, value), :inserted}
end

defp get_active_nodes do
def get_active_nodes do
true = Node.connect(:"wave-two@127.0.0.1")
true = Node.connect(:"wave-three@127.0.0.1")

Node.list()
|> Enum.zip([1, 2, 3])
|> Enum.map(fn {n, hostname} -> {:"ledger#{n}", hostname} end)
|> Enum.zip([1, 2])
|> Enum.map(fn {hostname, n} -> {:"ledger#{n}", hostname} end)
end
end

0 comments on commit f4a0d32

Please sign in to comment.