diff --git a/lib/supavisor/db_handler.ex b/lib/supavisor/db_handler.ex index b6a3de96..d9ca4846 100644 --- a/lib/supavisor/db_handler.ex +++ b/lib/supavisor/db_handler.ex @@ -245,6 +245,7 @@ defmodule Supavisor.DbHandler do end def handle_event(:info, {_proto, _, bin}, _, %{replica_type: :read} = data) do + Logger.debug("Got read replica message #{inspect(bin)}") pkts = Server.decode(bin) resp = @@ -277,6 +278,7 @@ defmodule Supavisor.DbHandler do end def handle_event(:info, {_proto, _, bin}, _, %{caller: caller} = data) when is_pid(caller) do + Logger.debug("Got write replica message #{inspect(bin)}") # check if the response ends with "ready for query" {ready, data} = if String.ends_with?(bin, Server.ready_for_query()) do diff --git a/lib/supavisor/tenants.ex b/lib/supavisor/tenants.ex index 62b58223..b575e28f 100644 --- a/lib/supavisor/tenants.ex +++ b/lib/supavisor/tenants.ex @@ -140,7 +140,7 @@ defmodule Supavisor.Tenants do ) end - @spec get_cluster_config(String.t(), String.t()) :: [ClusterTenants.t()] | nil + @spec get_cluster_config(String.t(), String.t()) :: [ClusterTenants.t()] | {:error, any()} def get_cluster_config(external_id, user) do case Repo.all(ClusterTenants, cluster_alias: external_id) do [%{cluster_alias: cluster_alias, active: true} | _] -> @@ -161,9 +161,16 @@ defmodule Supavisor.Tenants do ) Repo.all(query) + |> Enum.reduce_while([], fn cluster, acc -> + if cluster.tenant.require_user do + {:cont, [cluster | acc]} + else + {:halt, {:error, {:config, cluster.tenant.external_id}}} + end + end) _ -> - nil + {:error, :not_found} end end