-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add new transaction handler #402
base: v2
Are you sure you want to change the base?
Conversation
8c88398
to
4402c5c
Compare
lib/supavisor.ex
Outdated
opts = | ||
%{ | ||
max_connections: args.max_clients, | ||
num_acceptors: if(acceptors < 10, do: 10, else: acceptors), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
num_acceptors: if(acceptors < 10, do: 10, else: acceptors), | |
num_acceptors: max(acceptors, 10), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh, cool, didn't know that
alias Supavisor.Helpers, as: H | ||
alias Supavisor.HandlerHelpers, as: HH | ||
|
||
alias Supavisor.{ | ||
alias S.{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alias S.{ | |
alias Supavisor.{ |
I am not a fan of alias Supavisor, as: S
, and this make it even worse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, let's make it more readable
with {:ok, sup} <- | ||
Supavisor.start_dist(data.id, data.auth_secrets, log_level: data.log_level), | ||
true <- if(node(sup) == node(), do: true, else: :proxy), | ||
{:ok, opts} <- Supavisor.subscribe(sup, data.id) do | ||
Process.monitor(opts.workers.manager) | ||
data = Map.merge(data, opts.workers) | ||
data = %{data | idle_timeout: opts.idle_timeout} | ||
|
||
next = | ||
if opts.ps == [] do | ||
{:timeout, 10_000, :wait_ps} | ||
else | ||
{:next_event, :internal, {:client, {:greetings, opts.ps}}} | ||
end | ||
|
||
{:keep_state, data, next} | ||
else | ||
{:error, :max_clients_reached} -> | ||
msg = "Max client connections reached" | ||
Logger.error("ClientHandler: #{msg}") | ||
:ok = HH.send_error(data.sock, "XX000", msg) | ||
Telem.client_join(:fail, data.id) | ||
{:stop, {:shutdown, :max_clients_reached}} | ||
|
||
:proxy -> | ||
{:ok, %{port: port, host: host}} = S.get_pool_ranch(data.id) | ||
|
||
auth = | ||
Map.merge(data.auth, %{ | ||
port: port, | ||
host: host, | ||
ip_version: :v4, | ||
upstream_ssl: false, | ||
upstream_tls_ca: nil, | ||
upstream_verify: nil | ||
}) | ||
|
||
data = Map.merge(data, %{auth: auth, mode: :session, proxy: true}) | ||
{:keep_state, data, {:next_event, :internal, {:client, :connect_db}}} | ||
|
||
error -> | ||
Logger.error("ClientHandler: Subscribe error: #{inspect(error)}") | ||
{:keep_state_and_data, {:timeout, 1000, :subscribe}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That with
looks super heavy, but I do not have immediate plan how to make it cleaner.
case ProxyDb.send_startup(sock, auth) do | ||
tenant = if(data.proxy, do: S.tenant(data.id)) | ||
|
||
case Db.send_startup(sock, auth, tenant) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deep case
nesting.
clients when clients == [{self(), []}] or clients == [] -> PromEx.remove_metrics(data.id) | ||
_ -> :ok | ||
if data.id != nil do | ||
with clients <- Registry.lookup(Supavisor.Registry.TenantClients, data.id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use with
for this clause? It cannot fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦
No description provided.