From 89e8a63d49eeaec0e1809ca7e73548d4ed3b2dd6 Mon Sep 17 00:00:00 2001 From: Julong-Li <584147810@qq.com> Date: Fri, 26 Jan 2024 16:33:19 +0800 Subject: [PATCH] =?UTF-8?q?issue=E4=BF=AE=E6=94=B9=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E6=94=B9gsql=E5=91=BD=E4=BB=A4=E8=A1=8C=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=97=B6=EF=BC=8C=E9=83=A8=E5=88=86=E6=9A=82?= =?UTF-8?q?=E5=AD=98=E5=8C=BA=E7=9A=84=E8=AF=AD=E5=8F=A5=E8=A2=AB=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E6=B2=A1=E6=9C=89=E4=B8=8A=E4=BC=A0=E8=87=B3statement?= =?UTF-8?q?=5Fhistory=E4=B8=AD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbb/instruments/statement/instr_statement.cpp | 5 ++--- src/gausskernel/storage/ipc/ipc.cpp | 10 ++++++++++ src/include/instruments/instr_statement.h | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/gausskernel/cbb/instruments/statement/instr_statement.cpp b/src/gausskernel/cbb/instruments/statement/instr_statement.cpp index afccc4b6b..312665d50 100755 --- a/src/gausskernel/cbb/instruments/statement/instr_statement.cpp +++ b/src/gausskernel/cbb/instruments/statement/instr_statement.cpp @@ -887,7 +887,6 @@ static void FlushAllStatement() static void StatementFlush() { - const int flush_usleep_interval = 100000; int count = 0; bool is_readonly_log_needed = false; @@ -899,7 +898,7 @@ static void StatementFlush() ereport(WARNING, (errmodule(MOD_INSTR), errmsg("[Statement] cannot flush suspend list to statement_history in a read-only transaction"))); } - pg_usleep(flush_usleep_interval); + pg_usleep(FLUSH_USLEEP_INTERVAL); continue; } if (is_readonly_log_needed) { @@ -919,7 +918,7 @@ static void StatementFlush() /* report statement_history state to pgstat */ if (OidIsValid(u_sess->proc_cxt.MyDatabaseId)) pgstat_report_stat(true); - pg_usleep(flush_usleep_interval); + pg_usleep(FLUSH_USLEEP_INTERVAL); } } diff --git a/src/gausskernel/storage/ipc/ipc.cpp b/src/gausskernel/storage/ipc/ipc.cpp index b1e426dd0..b5e2c738a 100644 --- a/src/gausskernel/storage/ipc/ipc.cpp +++ b/src/gausskernel/storage/ipc/ipc.cpp @@ -51,6 +51,7 @@ #include "utils/plog.h" #include "threadpool/threadpool.h" #include "instruments/instr_user.h" +#include "instruments/instr_statement.h" #include "utils/postinit.h" #ifdef ENABLE_MOT #include "storage/mot/mot_fdw.h" @@ -167,6 +168,15 @@ void proc_exit(int code) } } + /* Wait for all statements that have not been flushed to complete flushing. + * The flush usleep wait interval is 100,000 microseconds, + * therefore we set it here to 300,000 microseconds for a safe margin. + */ + if (u_sess->statement_cxt.suspend_count != 0) { + int flushWaitInterval = 3 * FLUSH_USLEEP_INTERVAL; + pg_usleep(flushWaitInterval); + } + if (t_thrd.utils_cxt.backend_reserved) { ereport(DEBUG2, (errmodule(MOD_MEM), errmsg("[BackendReservedExit] current thread role is: %d, used memory is: %d MB\n", diff --git a/src/include/instruments/instr_statement.h b/src/include/instruments/instr_statement.h index 49161d897..2d35adda7 100644 --- a/src/include/instruments/instr_statement.h +++ b/src/include/instruments/instr_statement.h @@ -162,7 +162,7 @@ struct StatementDetail { #define STATEMENT_DETAIL_TYPE_PRETTY "pretty" #define Anum_statement_history_finish_time 12 - +#define FLUSH_USLEEP_INTERVAL 100000 /* entry for full/slow sql stat */ typedef struct StatementStatContext { void *next; /* next item if in free or suspend list */