From 095f8719839c1d0e47eb781200fa38384f0f5fa8 Mon Sep 17 00:00:00 2001 From: Tom Taylor Date: Mon, 13 Jan 2025 15:53:06 +0000 Subject: [PATCH] Revert "Implement Process Namespace for Process Ancestors" --- lib/snap/namespace.ex | 27 +++------------------------ test/namespace_test.exs | 7 ------- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/lib/snap/namespace.ex b/lib/snap/namespace.ex index d3ecf14..95f4917 100644 --- a/lib/snap/namespace.ex +++ b/lib/snap/namespace.ex @@ -152,7 +152,9 @@ defmodule Snap.Cluster.Namespace do @doc false def handle_call({:get, pid}, _from, state) do - {:reply, get_namespace_recursive(state, pid), state} + namespace = Map.get(state, pid) + + {:reply, namespace, state} end @doc false @@ -164,29 +166,6 @@ defmodule Snap.Cluster.Namespace do {:noreply, state} end - @spec get_namespace_recursive(state :: %{pid() => String.t()}, process :: pid()) :: - String.t() | nil - defp get_namespace_recursive(state, process) do - case Map.fetch(state, process) do - {:ok, namespace} -> - namespace - - :error -> - case Process.info(process, {:dictionary, :"$ancestors"}) do - {{:dictionary, :"$ancestors"}, :undefined} -> - nil - - {{:dictionary, :"$ancestors"}, ancestors} -> - ancestors - |> Enum.map(&GenServer.whereis/1) - |> Enum.find_value(&get_namespace_recursive(state, &1)) - - nil -> - nil - end - end - end - defp config_namespace(cluster) do config = cluster.config() Keyword.get(config, :index_namespace) diff --git a/test/namespace_test.exs b/test/namespace_test.exs index 763912c..e1a1218 100644 --- a/test/namespace_test.exs +++ b/test/namespace_test.exs @@ -65,13 +65,6 @@ defmodule Snap.Cluster.NamespaceTest do assert "cluster-process-index" == Namespace.add_namespace_to_index("index", NamespaceCluster) - task = - Task.async(fn -> - Namespace.add_namespace_to_index("index", NamespaceCluster) - end) - - assert "cluster-process-index" == Task.await(task) - Namespace.clear_process_namespace(NamespaceCluster, self()) assert "cluster-index" == Namespace.add_namespace_to_index("index", NamespaceCluster) end