-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1919 from hashicorp/llb-session-connection-deadlocks
chore: Merge session connection deadlock branch to main
- Loading branch information
Showing
37 changed files
with
2,444 additions
and
1,196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
internal/db/schema/migrations/oss/postgres/27/01_disable_terminate_session.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
begin; | ||
-- Replaces function from 0/51_connection.up.sql | ||
-- Remove call to terminate_session_if_possible | ||
drop trigger update_connection_state_on_closed_reason on session_connection; | ||
drop function update_connection_state_on_closed_reason(); | ||
create function | ||
update_connection_state_on_closed_reason() | ||
returns trigger | ||
as $$ | ||
begin | ||
if new.closed_reason is not null then | ||
-- check to see if there's a closed state already, before inserting a new one. | ||
perform from | ||
session_connection_state cs | ||
where | ||
cs.connection_id = new.public_id and | ||
cs.state = 'closed'; | ||
if not found then | ||
insert into session_connection_state (connection_id, state) | ||
values | ||
(new.public_id, 'closed'); | ||
end if; | ||
end if; | ||
return new; | ||
end; | ||
$$ language plpgsql; | ||
|
||
create trigger | ||
update_connection_state_on_closed_reason | ||
after update of closed_reason on session_connection | ||
for each row execute procedure update_connection_state_on_closed_reason(); | ||
|
||
-- Remove function, defined in 0/51_connection.up.sql | ||
drop function terminate_session_if_possible; | ||
|
||
commit; |
114 changes: 114 additions & 0 deletions
114
internal/db/schema/migrations/oss/postgres/27/02_wh_session_facts.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
begin; | ||
-- Updating definition from 16/05_wh_credential_dimension.up.sql | ||
-- Remove call to wh_rollup_connections(new.session_id) from function | ||
drop trigger wh_insert_session_connection on session_connection; | ||
drop function wh_insert_session_connection(); | ||
create function wh_insert_session_connection() | ||
returns trigger | ||
as $$ | ||
declare | ||
new_row wh_session_connection_accumulating_fact%rowtype; | ||
begin | ||
with | ||
authorized_timestamp (date_dim_key, time_dim_key, ts) as ( | ||
select wh_date_key(start_time), wh_time_key(start_time), start_time | ||
from session_connection_state | ||
where connection_id = new.public_id | ||
and state = 'authorized' | ||
), | ||
session_dimension (host_dim_key, user_dim_key, credential_group_dim_key) as ( | ||
select host_key, user_key, credential_group_key | ||
from wh_session_accumulating_fact | ||
where session_id = new.session_id | ||
) | ||
insert into wh_session_connection_accumulating_fact ( | ||
connection_id, | ||
session_id, | ||
host_key, | ||
user_key, | ||
credential_group_key, | ||
connection_authorized_date_key, | ||
connection_authorized_time_key, | ||
connection_authorized_time, | ||
client_tcp_address, | ||
client_tcp_port_number, | ||
endpoint_tcp_address, | ||
endpoint_tcp_port_number, | ||
bytes_up, | ||
bytes_down | ||
) | ||
select new.public_id, | ||
new.session_id, | ||
session_dimension.host_dim_key, | ||
session_dimension.user_dim_key, | ||
session_dimension.credential_group_dim_key, | ||
authorized_timestamp.date_dim_key, | ||
authorized_timestamp.time_dim_key, | ||
authorized_timestamp.ts, | ||
new.client_tcp_address, | ||
new.client_tcp_port, | ||
new.endpoint_tcp_address, | ||
new.endpoint_tcp_port, | ||
new.bytes_up, | ||
new.bytes_down | ||
from authorized_timestamp, | ||
session_dimension | ||
returning * into strict new_row; | ||
return null; | ||
end; | ||
$$ language plpgsql; | ||
|
||
create trigger wh_insert_session_connection | ||
after insert on session_connection | ||
for each row | ||
execute function wh_insert_session_connection(); | ||
|
||
-- Updating definition from 0/69_wh_session_facts.up.sql | ||
-- Remove call to wh_rollup_connections(new.session_id) from function | ||
drop trigger wh_update_session_connection on session_connection; | ||
drop function wh_update_session_connection; | ||
create function wh_update_session_connection() | ||
returns trigger | ||
as $$ | ||
declare | ||
updated_row wh_session_connection_accumulating_fact%rowtype; | ||
begin | ||
update wh_session_connection_accumulating_fact | ||
set client_tcp_address = new.client_tcp_address, | ||
client_tcp_port_number = new.client_tcp_port, | ||
endpoint_tcp_address = new.endpoint_tcp_address, | ||
endpoint_tcp_port_number = new.endpoint_tcp_port, | ||
bytes_up = new.bytes_up, | ||
bytes_down = new.bytes_down | ||
where connection_id = new.public_id | ||
returning * into strict updated_row; | ||
return null; | ||
end; | ||
$$ language plpgsql; | ||
|
||
create trigger wh_update_session_connection | ||
after update on session_connection | ||
for each row | ||
execute function wh_update_session_connection(); | ||
|
||
create function | ||
wh_session_rollup() | ||
returns trigger | ||
as $$ | ||
begin | ||
if new.termination_reason is not null then | ||
-- Rollup will fail if no connections were made for a session | ||
if exists (select from session_connection where session_id = new.public_id) then | ||
perform wh_rollup_connections(new.public_id); | ||
end if; | ||
end if; | ||
return null; | ||
end; | ||
$$ language plpgsql; | ||
|
||
create trigger | ||
wh_rollup_connections_on_session_termination | ||
after update of termination_reason on session | ||
for each row execute procedure wh_session_rollup(); | ||
|
||
commit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.