From df1ce4d2db74ed98a9db50bb0b85e99b595a01f6 Mon Sep 17 00:00:00 2001 From: Tanzeel Khan <140405735+tanscorpio7@users.noreply.github.com> Date: Mon, 30 Dec 2024 23:21:21 +0530 Subject: [PATCH] Fix sys.dm_exec_sessions having rows for backends which are already terminated (#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 tzlkhan@amazon.com --- contrib/babelfishpg_tds/src/backend/tds/tds.c | 12 ++++++++++-- test/JDBC/upgrade/13_6/schedule | 2 +- test/JDBC/upgrade/13_9/schedule | 2 +- test/JDBC/upgrade/14_12/schedule | 4 ++-- test/JDBC/upgrade/14_15/schedule | 4 ++-- test/JDBC/upgrade/14_16/schedule | 4 ++-- test/JDBC/upgrade/14_3/schedule | 2 +- test/JDBC/upgrade/14_5/schedule | 4 ++-- test/JDBC/upgrade/14_6/schedule | 4 ++-- test/JDBC/upgrade/15_2/schedule | 4 ++-- 10 files changed, 25 insertions(+), 17 deletions(-) diff --git a/contrib/babelfishpg_tds/src/backend/tds/tds.c b/contrib/babelfishpg_tds/src/backend/tds/tds.c index c00a694048..653011ae8d 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tds.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tds.c @@ -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; @@ -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; } diff --git a/test/JDBC/upgrade/13_6/schedule b/test/JDBC/upgrade/13_6/schedule index 5229e86699..630f602183 100644 --- a/test/JDBC/upgrade/13_6/schedule +++ b/test/JDBC/upgrade/13_6/schedule @@ -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 diff --git a/test/JDBC/upgrade/13_9/schedule b/test/JDBC/upgrade/13_9/schedule index e5cfec582b..23c12873f4 100644 --- a/test/JDBC/upgrade/13_9/schedule +++ b/test/JDBC/upgrade/13_9/schedule @@ -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 diff --git a/test/JDBC/upgrade/14_12/schedule b/test/JDBC/upgrade/14_12/schedule index b45b85fa19..9a8a0592b8 100644 --- a/test/JDBC/upgrade/14_12/schedule +++ b/test/JDBC/upgrade/14_12/schedule @@ -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 @@ -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 diff --git a/test/JDBC/upgrade/14_15/schedule b/test/JDBC/upgrade/14_15/schedule index f02bb2cf3b..23483d79a2 100644 --- a/test/JDBC/upgrade/14_15/schedule +++ b/test/JDBC/upgrade/14_15/schedule @@ -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 @@ -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 diff --git a/test/JDBC/upgrade/14_16/schedule b/test/JDBC/upgrade/14_16/schedule index c79822746b..132b4e6796 100644 --- a/test/JDBC/upgrade/14_16/schedule +++ b/test/JDBC/upgrade/14_16/schedule @@ -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 @@ -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 diff --git a/test/JDBC/upgrade/14_3/schedule b/test/JDBC/upgrade/14_3/schedule index 47352124e2..39ca14015b 100644 --- a/test/JDBC/upgrade/14_3/schedule +++ b/test/JDBC/upgrade/14_3/schedule @@ -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 diff --git a/test/JDBC/upgrade/14_5/schedule b/test/JDBC/upgrade/14_5/schedule index 86ba828975..3f176f7b99 100644 --- a/test/JDBC/upgrade/14_5/schedule +++ b/test/JDBC/upgrade/14_5/schedule @@ -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 @@ -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 diff --git a/test/JDBC/upgrade/14_6/schedule b/test/JDBC/upgrade/14_6/schedule index 8df42f7943..82edbaa3a8 100644 --- a/test/JDBC/upgrade/14_6/schedule +++ b/test/JDBC/upgrade/14_6/schedule @@ -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 @@ -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 diff --git a/test/JDBC/upgrade/15_2/schedule b/test/JDBC/upgrade/15_2/schedule index e68a0870f5..e164028edf 100644 --- a/test/JDBC/upgrade/15_2/schedule +++ b/test/JDBC/upgrade/15_2/schedule @@ -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 @@ -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