Skip to content

Commit

Permalink
Fix sys.dm_exec_sessions having rows for backends which are already t…
Browse files Browse the repository at this point in the history
…erminated (#3329)

We initialize and keep a local status array which has the entries
for all TDS connections but we did not reset these entries during
connection abort or shmem exit of the backend, which means
future read of this local status array will see these entries as valid.

As a fix, mark the status entry as invalid during proc/shmem exit

Task: [BABEL-5414]

Signed-off-by: Tanzeel Khan [email protected]
  • Loading branch information
tanscorpio7 authored Dec 30, 2024
1 parent da9d1da commit df1ce4d
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 17 deletions.
12 changes: 10 additions & 2 deletions contrib/babelfishpg_tds/src/backend/tds/tds.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ typedef struct LocalTdsStatus
} LocalTdsStatus;

static TdsStatus *TdsStatusArray = NULL;
static TdsStatus *MyTdsStatusEntry;
static TdsStatus *MyTdsStatusEntry = NULL;
static LocalTdsStatus *localTdsStatusTable = NULL;

uint32_t MyTdsClientVersion = 0;
Expand Down Expand Up @@ -446,9 +446,17 @@ tds_stats_shmem_shutdown(int code, Datum arg)
return;

/* Safety check ... shouldn't get here unless shmem is set up. */
if (TdsStatusArray == NULL)
if (TdsStatusArray == NULL || MyTdsStatusEntry == NULL)
return;

PGSTAT_BEGIN_WRITE_ACTIVITY(MyTdsStatusEntry);

MyTdsStatusEntry->st_procpid = 0; /* mark invalid */

PGSTAT_END_WRITE_ACTIVITY(MyTdsStatusEntry);

MyTdsStatusEntry = NULL;

return;
}

Expand Down
2 changes: 1 addition & 1 deletion test/JDBC/upgrade/13_6/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ sys-datefirst
sys-dm_exec_connections
sys-dm_exec_connections-dep
sys-dm_exec_sessions
#sys-dm_exec_sessions-dep TODO:BABEL-5414
sys-dm_exec_sessions-dep
sys-dm_hadr_cluster
sys-dm_hadr_database_replica_states
sys-dm_os_host_info
Expand Down
2 changes: 1 addition & 1 deletion test/JDBC/upgrade/13_9/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ sys-datefirst
sys-dm_exec_connections
sys-dm_exec_connections-dep
sys-dm_exec_sessions
#sys-dm_exec_sessions-dep TODO:BABEL-5414
sys-dm_exec_sessions-dep
sys-dm_hadr_cluster
sys-dm_hadr_database_replica_states
sys-dm_os_host_info
Expand Down
4 changes: 2 additions & 2 deletions test/JDBC/upgrade/14_12/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ column_domain_usage
constraint_column_usage
select-strip-parens-before-15_5
sp_describe_first_result_set
#sys-host_name-before-15_8-or-16_4 TODO:BABEL-5414
sys-host_name-before-15_8-or-16_4
SYSTEM_USER
indexproperty
sys-all_parameters
Expand Down Expand Up @@ -241,7 +241,7 @@ sys-index_columns-dep
sys-sp_databases-dep
sys-syscolumns-dep
sys-dm_exec_connections-dep
#sys-dm_exec_sessions-dep TODO:BABEL-5414
sys-dm_exec_sessions-dep
sys-table_types-before-dep
sys-all_sql_modules-dep_before_16_5
sys-sql_modules-dep_before_16_5
Expand Down
4 changes: 2 additions & 2 deletions test/JDBC/upgrade/14_15/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ column_domain_usage
constraint_column_usage
select-strip-parens-before-15_5
sp_describe_first_result_set
#sys-host_name-before-15_8-or-16_4 TODO:BABEL-5414
sys-host_name-before-15_8-or-16_4
SYSTEM_USER
indexproperty
sys-all_parameters
Expand Down Expand Up @@ -241,7 +241,7 @@ sys-index_columns-dep
sys-sp_databases-dep
sys-syscolumns-dep
sys-dm_exec_connections-dep
#sys-dm_exec_sessions-dep TODO:BABEL-5414
sys-dm_exec_sessions-dep
sys-table_types-before-dep
sys-all_sql_modules-dep_before_16_5
sys-sql_modules-dep_before_16_5
Expand Down
4 changes: 2 additions & 2 deletions test/JDBC/upgrade/14_16/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ column_domain_usage
constraint_column_usage
select-strip-parens-before-15_5
sp_describe_first_result_set
#sys-host_name-before-15_8-or-16_4 TODO:BABEL-5414
sys-host_name-before-15_8-or-16_4
SYSTEM_USER
indexproperty
sys-all_parameters
Expand Down Expand Up @@ -241,7 +241,7 @@ sys-index_columns-dep
sys-sp_databases-dep
sys-syscolumns-dep
sys-dm_exec_connections-dep
#sys-dm_exec_sessions-dep TODO:BABEL-5414
sys-dm_exec_sessions-dep
sys-table_types-before-dep
sys-all_sql_modules-dep_before_16_5
sys-sql_modules-dep_before_16_5
Expand Down
2 changes: 1 addition & 1 deletion test/JDBC/upgrade/14_3/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ sys-datefirst
sys-dm_exec_connections
sys-dm_exec_connections-dep
sys-dm_exec_sessions
#sys-dm_exec_sessions-dep TODO:BABEL-5414
sys-dm_exec_sessions-dep
sys-dm_hadr_cluster
sys-dm_hadr_database_replica_states
sys-dm_os_host_info
Expand Down
4 changes: 2 additions & 2 deletions test/JDBC/upgrade/14_5/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ sys-datefirst
sys-dm_exec_connections
sys-dm_exec_connections-dep
sys-dm_exec_sessions
#sys-dm_exec_sessions-dep TODO:BABEL-5414
sys-dm_exec_sessions-dep
sys-dm_hadr_cluster
sys-dm_hadr_database_replica_states
sys-dm_os_host_info
Expand All @@ -237,7 +237,7 @@ sys-fulltext_stoplists
sys-hash_indexes
sys-has_perms_by_name
sys-has_perms_by_name-dep
#sys-host_name-before-15_8-or-16_4 TODO:BABEL-5414
sys-host_name-before-15_8-or-16_4
sys-identity_columns
sys-identity_columns-dep
sys-index_columns
Expand Down
4 changes: 2 additions & 2 deletions test/JDBC/upgrade/14_6/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ sys-default_constraints-dep
sys-dm_exec_connections
sys-dm_exec_connections-dep
sys-dm_exec_sessions
#sys-dm_exec_sessions-dep TODO:BABEL-5414
sys-dm_exec_sessions-dep
sys-dm_hadr_cluster
sys-dm_hadr_database_replica_states
sys-dm_os_host_info
Expand All @@ -270,7 +270,7 @@ sys-fulltext_stoplists
sys-hash_indexes
sys-has_perms_by_name
sys-has_perms_by_name-dep
#sys-host_name-before-15_8-or-16_4 TODO:BABEL-5414
sys-host_name-before-15_8-or-16_4
sys-identity_columns
sys-identity_columns-dep
sys-index_columns
Expand Down
4 changes: 2 additions & 2 deletions test/JDBC/upgrade/15_2/schedule
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ sys-default_constraints-dep
sys-dm_exec_connections
sys-dm_exec_connections-dep
sys-dm_exec_sessions
#sys-dm_exec_sessions-dep TODO:BABEL-5414
sys-dm_exec_sessions-dep
sys-dm_hadr_cluster
sys-dm_hadr_database_replica_states
sys-dm_os_host_info
Expand All @@ -293,7 +293,7 @@ sys-fulltext_stoplists
sys-hash_indexes
sys-has_perms_by_name
sys-has_perms_by_name-dep
#sys-host_name-before-15_8-or-16_4 TODO:BABEL-5414
sys-host_name-before-15_8-or-16_4
sys-identity_columns
sys-identity_columns-dep
sys-index_columns
Expand Down

0 comments on commit df1ce4d

Please sign in to comment.