Skip to content
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

chore: improve active_count #481

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions lib/supavisor/client_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@

key = {:secrets, tenant_or_alias, user}

case auth_secrets(info, user, key, :timer.hours(24)) do

Check warning on line 278 in lib/supavisor/client_handler.ex

View workflow job for this annotation

GitHub Actions / Code style

Function body is nested too deep (max depth is 2, was 3).
{:ok, auth_secrets} ->
Logger.debug("ClientHandler: Authentication method: #{inspect(auth_secrets)}")

Expand Down Expand Up @@ -334,7 +334,7 @@
Cachex.get(Supavisor.Cache, key) == {:ok, nil} do
case auth_secrets(info, data.user, key, 15_000) do
{:ok, {method2, secrets2}} = value ->
if method != method2 or Map.delete(secrets.(), :client_key) != secrets2.() do

Check warning on line 337 in lib/supavisor/client_handler.ex

View workflow job for this annotation

GitHub Actions / Code style

Function body is nested too deep (max depth is 2, was 4).
Logger.warning("ClientHandler: Update secrets and terminate pool")

Cachex.update(
Expand Down Expand Up @@ -529,6 +529,7 @@
{:keep_state, %{data | active_count: reset_active_count(data)}, handle_actions(data)}
end

# handle Flush message
def handle_event(:info, {proto, _, <<?H, 4::32, _::binary>> = msg}, _, data)
when proto in @proto do
Logger.debug("ClientHandler: Receive flush while not idle")
Expand Down Expand Up @@ -1125,11 +1126,7 @@

@spec reset_active_count(map()) :: 0
def reset_active_count(data) do
if data.active_count >= @switch_active_count do
Logger.debug("ClientHandler: Activate socket #{inspect(data.active_count)}")
HandlerHelpers.activate(data.sock)
end

HandlerHelpers.activate(data.sock)
0
end
end
5 changes: 2 additions & 3 deletions lib/supavisor/db_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
tenant = if data.proxy, do: Supavisor.tenant(data.id)
search_path = Supavisor.search_path(data.id)

case send_startup(sock, auth, tenant, search_path) do

Check warning on line 128 in lib/supavisor/db_handler.ex

View workflow job for this annotation

GitHub Actions / Code style

Function body is nested too deep (max depth is 2, was 3).
:ok ->
:ok = activate(sock)
{:next_state, :authentication, %{data | sock: sock}}
Expand Down Expand Up @@ -295,8 +295,7 @@
Logger.debug("DbHandler: Got write replica message #{inspect(bin)}")

if String.ends_with?(bin, Server.ready_for_query()) do
if data.active_count >= @switch_active_count,
do: HandlerHelpers.activate(data.sock)
HandlerHelpers.activate(data.sock)

{_, stats} = Telem.network_usage(:db, data.sock, data.id, data.stats)

Expand Down Expand Up @@ -363,7 +362,7 @@
end

if state == :busy or data.mode == :session do
sock_send(data.sock, <<?X, 4::32>>)
sock_send(data.sock, Server.terminate_message())
:gen_tcp.close(elem(data.sock, 1))
{:stop, {:client_handler_down, data.mode}}
else
Expand Down
4 changes: 4 additions & 0 deletions lib/supavisor/protocol/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@scram_request <<?R, 23::32, 10::32, "SCRAM-SHA-256", 0, 0>>
@msg_cancel_header <<16::32, 1234::16, 5678::16>>
@application_name <<?S, 31::32, "application_name", 0, "Supavisor", 0>>
@terminate_message <<?X, 4::32>>

defmodule Pkt do
@moduledoc "Representing a packet structure with tag, length, and payload fields."
Expand Down Expand Up @@ -470,4 +471,7 @@

@spec application_name() :: binary
def application_name, do: @application_name

@spec terminate_message() :: binary
def terminate_message(), do: @terminate_message

Check warning on line 476 in lib/supavisor/protocol/server.ex

View workflow job for this annotation

GitHub Actions / Code style

Do not use parentheses when defining a function which has no arguments.
end
Loading