Skip to content

Commit

Permalink
ft: use RPC helper function everywhere (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauleth authored Jun 26, 2024
1 parent a76efaa commit 48dac52
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 106 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.65
1.1.66
11 changes: 1 addition & 10 deletions lib/supavisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,7 @@ defmodule Supavisor do
if node() == dest_node do
subscribe_local(pid, id)
else
try do
# TODO: tests for different cases
:erpc.call(dest_node, __MODULE__, :subscribe_local, [pid, id], 15_000)
|> case do
{:EXIT, _} = badrpc -> {:error, {:badrpc, badrpc}}
result -> result
end
catch
kind, reason -> {:error, {:badrpc, {kind, reason}}}
end
H.rpc(dest_node, __MODULE__, :subscribe_local, [pid, id], 15_000)
end
end

Expand Down
7 changes: 3 additions & 4 deletions lib/supavisor/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,11 @@ defmodule Supavisor.Helpers do
def rpc(node, module, function, args, timeout \\ 15_000) do
try do
:erpc.call(node, module, function, args, timeout)
|> case do
{:EXIT, _} = badrpc -> {:error, {:badrpc, badrpc}}
result -> result
end
catch
kind, reason -> {:error, {:badrpc, {kind, reason}}}
else
{:EXIT, _} = badrpc -> {:error, {:badrpc, badrpc}}
result -> result
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/supavisor_web/ws_proxy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ defmodule SupavisorWeb.WsProxy do
@spec connect_local() :: {:ok, port()} | {:error, term()}
defp connect_local() do
proxy_port = Application.fetch_env!(:supavisor, :proxy_port_transaction)
:gen_tcp.connect('localhost', proxy_port, [:binary, packet: :raw, active: true])
:gen_tcp.connect(~c"localhost", proxy_port, [:binary, packet: :raw, active: true])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ defmodule Supavisor.Repo.Migrations.AddTenantIpVersion do
constraint(
"tenants",
:ip_version_values,
check: "ip_version IN ('auto', 'v4', 'v6')"
check: "ip_version IN ('auto', 'v4', 'v6')",
prefix: "_supavisor"
)
)
end
Expand Down
12 changes: 9 additions & 3 deletions priv/repo/migrations/20230919100141_create_cluster_tenants.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ defmodule Supavisor.Repo.Migrations.CreateClusterTenants do

add(
:cluster_alias,
references(:clusters, on_delete: :delete_all, type: :string, column: :alias)
references(:clusters,
on_delete: :delete_all,
type: :string,
column: :alias,
prefix: "_supavisor"
)
)

add(
:tenant_external_id,
references(:tenants, type: :string, column: :external_id)
references(:tenants, type: :string, column: :external_id, prefix: "_supavisor")
)

timestamps()
Expand All @@ -24,7 +29,8 @@ defmodule Supavisor.Repo.Migrations.CreateClusterTenants do
constraint(
:cluster_tenants,
:type,
check: "type IN ('read', 'write')"
check: "type IN ('read', 'write')",
prefix: "_supavisor"
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ defmodule Supavisor.Repo.Migrations.AddDefaultPoolStrategy do
constraint(
"tenants",
:default_pool_strategy_values,
check: "default_pool_strategy IN ('fifo', 'lifo')"
check: "default_pool_strategy IN ('fifo', 'lifo')",
prefix: "_supavisor"
)
)
end
Expand Down
83 changes: 0 additions & 83 deletions priv/repo/migrations/mix.exs

This file was deleted.

4 changes: 2 additions & 2 deletions test/integration/proxy_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ defmodule Supavisor.Integration.ProxyTest do
"http://localhost:#{Application.get_env(:supavisor, :proxy_port_transaction)}"
) ==
{:ok,
{{'HTTP/1.1', 204, 'OK'}, [{'x-app-version', Application.spec(:supavisor, :vsn)}],
[]}}
{{~c"HTTP/1.1", 204, ~c"OK"},
[{~c"x-app-version", Application.spec(:supavisor, :vsn)}], []}}
end

test "checks that client_handler is idle and db_pid is nil for transaction mode" do
Expand Down

0 comments on commit 48dac52

Please sign in to comment.