Skip to content

Commit

Permalink
fix - Set slot_name_suffix to avoid conflicts on deploys (#709)
Browse files Browse the repository at this point in the history
Sets a default value for slot_name_suffix so we avoid issues during deployments

Plus sets the SynHandler as conflict resolution for :syn on the Application.ex level
  • Loading branch information
filipecabaco authored Oct 23, 2023
1 parent dd369e8 commit bab0992
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
5 changes: 5 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Config

version = Mix.Project.config()[:version] |> String.replace(".", "_") |> String.downcase()

config :logflare_logger_backend,
url: System.get_env("LOGFLARE_LOGGER_BACKEND_URL", "https://api.logflare.app")

Expand All @@ -9,6 +11,9 @@ username = System.get_env("DB_USER", "postgres")
password = System.get_env("DB_PASSWORD", "postgres")
database = System.get_env("DB_NAME", "postgres")
port = System.get_env("DB_PORT", "5432")
slot_name_suffix = System.get_env("SLOT_NAME_SUFFIX", version)

config :realtime, slot_name_suffix: slot_name_suffix

if config_env() == :prod do
secret_key_base =
Expand Down
10 changes: 2 additions & 8 deletions lib/extensions/postgres_cdc_rls/replication_poller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,8 @@ defmodule Extensions.PostgresCdcRls.ReplicationPoller do
end

def slot_name_suffix() do
case System.get_env("SLOT_NAME_SUFFIX") do
nil ->
""

value ->
Logger.debug("Using slot name suffix: " <> value)
"_" <> value
end
slot_name_suffix = Application.get_env(:realtime, :slot_name_suffix)
"_" <> slot_name_suffix
end

defp convert_errors([_ | _] = errors), do: errors
Expand Down
1 change: 0 additions & 1 deletion lib/extensions/postgres_cdc_rls/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ defmodule Extensions.PostgresCdcRls.Supervisor do
def init(_args) do
load_migrations_modules()

:syn.set_event_handler(Realtime.SynHandler)
:syn.add_node_to_scopes([PostgresCdcRls])

children = [
Expand Down
2 changes: 2 additions & 0 deletions lib/realtime/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ defmodule Realtime.Application do
name: Realtime.Registry.Unique
)

:syn.set_event_handler(Realtime.SynHandler)
:ok = :syn.add_node_to_scopes([Realtime.Tenants.Connect])
:ok = :syn.add_node_to_scopes([:users, RegionNodes])

region = Application.get_env(:realtime, :region)
:syn.join(RegionNodes, region, self(), node: node())

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 Realtime.MixProject do
def project do
[
app: :realtime,
version: "2.25.7",
version: "2.25.8",
elixir: "~> 1.14.0",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down
19 changes: 13 additions & 6 deletions test/realtime/extensions/cdc_rls/replication_poller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,21 @@ defmodule ReplicationPollerTest do
end

describe "slot_name_suffix" do
test "when no SLOT_NAME_SUFFIX" do
System.delete_env("SLOT_NAME_SUFFIX")
assert Poller.slot_name_suffix() == ""
setup do
slot_name_suffix = Application.get_env(:realtime, :slot_name_suffix)

on_exit(fn -> Application.put_env(:realtime, :slot_name_suffix, slot_name_suffix) end)
end

test "uses Application.get_env/2 with key :slot_name_suffix" do
slot_name_suffix = Generators.rand_string()
Application.put_env(:realtime, :slot_name_suffix, slot_name_suffix)
assert Poller.slot_name_suffix() == "_" <> slot_name_suffix
end

test "when SLOT_NAME_SUFFIX defined" do
System.put_env("SLOT_NAME_SUFFIX", "some_val")
assert Poller.slot_name_suffix() == "_some_val"
test "defaults to project version" do
version = Mix.Project.config()[:version] |> String.replace(".", "_")
assert Poller.slot_name_suffix() == "_" <> version
end
end
end

0 comments on commit bab0992

Please sign in to comment.