Skip to content
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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,14 @@ Generally speaking, it will be put into application start.

## Change log

- [v1.0.1] Fixed bug when put with ttl and remove `delete_object/1`. [pull request](https://github.com/ArcBlock/mcc/pull/6)
- [v1.0.1]
- Fixed bug when put with ttl and remove `delete_object/1`


[pull request](https://github.com/ArcBlock/mcc/pull/6)

- [v1.0.2]
- try to connect kernel optional nodes before join cluster
- added log after joined in cluster and create/copy table

[pull request](https://github.com/ArcBlock/mcc/pull/7)
20 changes: 17 additions & 3 deletions lib/mcc/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ defmodule Mcc.Application do
@moduledoc false

use Application

require Logger
alias Mcc.Expiration.Supervisor, as: ExpSup
alias Mcc.Lib

# alias Mcc.

Expand All @@ -20,19 +21,23 @@ defmodule Mcc.Application do
defp join_cluster do
:kernel
|> Application.get_env(:sync_nodes_optional, [])
|> try_connect_nodes()
|> intersection(Node.list())
|> case do
[] ->
Logger.warn("[mcc] #{node()} can't find any other nodes")
:ok

node_list ->
[target_node | _] = Enum.sort(node_list)
true = ensure_target_running?(target_node)

case Mcc.join(target_node) do
:ok -> :ok
{:error, {:already_clustered, _}} -> :ok
:ok -> Logger.info("[mcc] #{node()} joined in target node #{target_node}")
{:error, {:already_clustered, _}} -> nil
end

Logger.info("[mcc] current cluster node list: #{inspect(Lib.status())}")
end
end

Expand All @@ -54,5 +59,14 @@ defmodule Mcc.Application do
end
end

@doc false
defp try_connect_nodes(node_list) do
node_list
|> Enum.map(fn node ->
_ = Node.connect(node)
node
end)
end

# __end_of_module__
end
6 changes: 5 additions & 1 deletion lib/mcc/expiration/worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ defmodule Mcc.Expiration.Worker do

use GenServer

require Logger

def start_link(worker_name, worker_opts) do
GenServer.start_link(__MODULE__, worker_opts, name: worker_name)
end

def init(worker_opts) do
check_interval = Keyword.get(worker_opts, :check_interval, 1_000)
scheduler(check_interval)
main_tab = Keyword.fetch!(worker_opts, :main_table)
Logger.info("[mcc] the expiration process for #{main_tab} started")

{:ok,
%{
main_tab: Keyword.fetch!(worker_opts, :main_table),
main_tab: main_tab,
exp_tab: Keyword.fetch!(worker_opts, :expiration_table),
size_limit: Keyword.get(worker_opts, :size_limit, 1_000_000),
memory_limit: Keyword.get(worker_opts, :memory_limit, 100),
Expand Down
28 changes: 18 additions & 10 deletions lib/mcc/model.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,34 @@ defmodule Mcc.Model do
quote do
use Mcc.Model.Repo

require Logger

alias Mcc.Expiration.Supervisor, as: ExpSup
alias Mcc.Model

@spec boot_tables() :: :ok
def boot_tables do
Enum.each(tables(), fn {table, attr} -> Model.create_table(table, attr) end)
Enum.each(tables(), fn {table, attr} ->
Model.create_table(table, attr)
Logger.info("[mcc] mnesia table #{table} created")
end)
end

@spec copy_tables() :: :ok
def copy_tables do
Enum.each(tables(), fn {table, attr} ->
case {
Keyword.has_key?(attr, :ram_copies),
Keyword.has_key?(attr, :disc_copies),
Keyword.has_key?(attr, :disc_only_copies)
} do
{true, false, false} -> Model.copy_table(table, :ram_copies)
{false, true, false} -> Model.copy_table(table, :disc_copies)
{false, false, true} -> Model.copy_table(table, :disc_only_copies)
end
copy_res =
case {
Keyword.has_key?(attr, :ram_copies),
Keyword.has_key?(attr, :disc_copies),
Keyword.has_key?(attr, :disc_only_copies)
} do
{true, false, false} -> Model.copy_table(table, :ram_copies)
{false, true, false} -> Model.copy_table(table, :disc_copies)
{false, false, true} -> Model.copy_table(table, :disc_only_copies)
end

Logger.info("[mcc] mnesia table #{table} copied, result: #{inspect(copy_res)}")
end)

:ok
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Mcc.MixProject do
def project do
[
app: :mcc,
version: "1.0.1",
version: "1.0.2",
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
elixirc_paths: elixirc_paths(Mix.env()),
Expand Down
1 change: 1 addition & 0 deletions test/support/node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule MccTest.Support.Node do
node_pid = start_node_pid(:"#{name}", node_name)
:ok = block_until_nodeup(node_pid)
{:ok, _} = :rpc.call(node(), Application, :ensure_all_started, [:elixir])
{:ok, _} = :rpc.call(node_name, Application, :ensure_all_started, [:logger])
{:ok, node_name, node_pid}
end

Expand Down