未验证 提交 ac54faad 编写于 作者: T Teng Zhang 提交者: GitHub

Fix pg_stat_activity show wrong session id after session reset bug (#5757)

* Fix pg_stat_activity show wrong session id after session reset bug

Currently if a session is reset because of some error such as OOM,
after call CheckForResetSession, gp_session_id will bump to a new one,
but sess_id in pg_stat_activity remains unchanged and show the wrong number.
This commit changes sess_id in pg_stat_activity, once a session is reset.

* Refactor test using gp_execute_on_server to trigger session reset
上级 fcadfe88
......@@ -20,6 +20,7 @@
#include "libpq-fe.h"
#include "miscadmin.h" /* MyDatabaseId */
#include "pgstat.h" /* pgstat_report_sessionid() */
#include "storage/proc.h" /* MyProc */
#include "storage/ipc.h"
#include "utils/memutils.h"
......@@ -1421,6 +1422,7 @@ CheckForResetSession(void)
gp_session_id = newSessionId;
gp_command_count = 0;
pgstat_report_sessionid(newSessionId);
/* Update the slotid for our singleton reader. */
if (SharedLocalSnapshotSlot != NULL)
......
......@@ -2763,6 +2763,27 @@ gpstat_report_waiting(char reason)
beentry->st_waiting = reason;
}
/* ----------
* pgstat_report_sessionid() -
*
* Called from cdbgang to report a session is reset.
*
* ----------
*/
void
pgstat_report_sessionid(int new_sessionid)
{
volatile PgBackendStatus *beentry = MyBEEntry;
if (!beentry)
return;
beentry->st_changecount++;
beentry->st_session_id = new_sessionid;
beentry->st_changecount++;
Assert((beentry->st_changecount & 1) == 0);
}
/* ----------
* pgstat_read_current_status() -
*
......
......@@ -862,6 +862,7 @@ extern void pgstat_report_txn_timestamp(TimestampTz tstamp);
extern void pgstat_report_waiting(bool waiting);
#endif
extern void gpstat_report_waiting(char reason);
extern void pgstat_report_sessionid(int new_sessionid);
extern void pgstat_report_activity(BackendState state, const char *cmd_str);
extern void pgstat_report_tempfile(size_t filesize);
......
......@@ -209,6 +209,7 @@ test: vacuum_full_heap_bitmapindex
test: ao_checksum_corruption AOCO_Compression2 table_statistics fts_error
test: metadata_track
test: workfile_mgr_test
test: session_reset
test: psql_gp_commands pg_resetxlog
......
set log_min_messages to ERROR;
CREATE FUNCTION gp_execute_on_server(content smallint, query cstring) returns boolean
language C as '@abs_builddir@/regress@DLSUFFIX@', 'gp_execute_on_server';
-- terminate backend process for this session on segment with content ID = 0
select gp_execute_on_server(0::smallint, 'select pg_terminate_backend(pg_backend_pid())'::cstring);
-- session is reset and gp_session_id value changes
-- sess_id in pg_stat_activity should be consistent with gp_session_id
select session_id AS session_not_in_stat_activity from (select paramvalue AS session_id from gp_toolkit.gp_param_settings() where paramname='gp_session_id' and paramsegment = 0) right_id where right_id.session_id not in (select sess_id::text from pg_stat_activity);
set log_min_messages to default;
set log_min_messages to ERROR;
CREATE FUNCTION gp_execute_on_server(content smallint, query cstring) returns boolean
language C as '@abs_builddir@/regress@DLSUFFIX@', 'gp_execute_on_server';
-- terminate backend process for this session on segment with content ID = 0
select gp_execute_on_server(0::smallint, 'select pg_terminate_backend(pg_backend_pid())'::cstring);
ERROR: terminating connection due to administrator command (seg0 10.152.10.149:25432 pid=32665)
-- session is reset and gp_session_id value changes
-- sess_id in pg_stat_activity should be consistent with gp_session_id
select session_id AS session_not_in_stat_activity from (select paramvalue AS session_id from gp_toolkit.gp_param_settings() where paramname='gp_session_id' and paramsegment = 0) right_id where right_id.session_id not in (select sess_id::text from pg_stat_activity);
session_not_in_stat_activity
------------------------------
(0 rows)
set log_min_messages to default;
......@@ -43,3 +43,4 @@ gp_tablespace.sql
partition_ddl.sql
autovacuum-template0.sql
rpt_tpch.sql
session_reset.sql
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册