!4554 修复build进程hang住的问题

Merge pull request !4554 from chenxiaobin/fixBuildHang
This commit is contained in:
opengauss_bot
2023-12-06 08:08:35 +00:00
committed by Gitee
4 changed files with 30 additions and 10 deletions

View File

@ -31,6 +31,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/prctl.h>
#include "tool_common.h"
#include "getopt_long.h"
@ -503,7 +504,11 @@ static void StartLogStreamer(const char *startpos, uint32 timeline, char *syside
#ifndef WIN32
bgchild = fork();
if (bgchild == 0) {
/* in child process */
/*
* In child process.
* Receive SIGKILL when main process exits.
*/
prctl(PR_SET_PDEATHSIG, SIGKILL);
exit(LogStreamerMain(g_childParam));
} else if (bgchild < 0) {
fprintf(stderr, _("%s: could not create background process: %s\n"), progname, strerror(errno));

View File

@ -53,6 +53,10 @@ static XLogRecPtr lastFlushPosition = InvalidXLogRecPtr;
extern char* basedir;
extern int standby_message_timeout;
#define HEART_BEAT_INIT 0
#define HEART_BEAT_RUN 1
#define HEART_BEAT_STOP 2
/*
* The max size for single data file. copy from custorage.cpp.
*/
@ -64,7 +68,7 @@ const int HEART_BEAT = 5;
PGconn* xlogconn = NULL;
pthread_t hearbeatTimerId;
volatile uint32 timerFlag = 0;
volatile uint32 heartbeatRunning = 0;
volatile uint32 heartbeatRunning = HEART_BEAT_INIT;
pthread_mutex_t heartbeatMutex;
pthread_mutex_t heartbeatQuitMutex;
pthread_cond_t heartbeatQuitCV;
@ -235,8 +239,9 @@ void* heartbeatTimerHandler(void* data)
if (xlogconn == NULL) {
return NULL;
}
heartbeatRunning = 1;
while (heartbeatRunning) {
uint32 expected = HEART_BEAT_INIT;
(void)pg_atomic_compare_exchange_u32(&heartbeatRunning, &expected, HEART_BEAT_RUN);
while (pg_atomic_read_u32(&heartbeatRunning) == HEART_BEAT_RUN) {
pthread_mutex_lock(&heartbeatMutex);
(void)checkForReceiveTimeout(xlogconn);
ping_sent = false;
@ -280,7 +285,7 @@ void suspendHeartBeatTimer(void)
void closeHearBeatTimer(void)
{
heartbeatRunning = 0;
pg_atomic_write_u32(&heartbeatRunning, HEART_BEAT_STOP);
pthread_mutex_unlock(&heartbeatMutex);
pthread_mutex_lock(&heartbeatQuitMutex);
pthread_cond_signal(&heartbeatQuitCV);

View File

@ -26,6 +26,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/prctl.h>
#ifdef HAVE_LIBZ
#include "zlib.h"
@ -568,7 +569,11 @@ bool StartLogStreamer(
fflush(stderr);
bgchild = fork();
if (bgchild == 0) {
/* in child process */
/*
* In child process.
* Receive SIGKILL when main process exits.
*/
prctl(PR_SET_PDEATHSIG, SIGKILL);
exit(LogStreamerMain(param));
} else if (bgchild < 0) {
pg_log(PG_WARNING, _(" could not create background process: %s.\n"), strerror(errno));

View File

@ -51,6 +51,10 @@ static bool reportFlushPosition = false;
static XLogRecPtr lastFlushPosition = InvalidXLogRecPtr;
extern char* basedir;
#define HEART_BEAT_INIT 0
#define HEART_BEAT_RUN 1
#define HEART_BEAT_STOP 2
/*
* The max size for single data file. copy from custorage.cpp.
*/
@ -62,7 +66,7 @@ const int HEART_BEAT = 5;
PGconn* xlogconn = NULL;
pthread_t hearbeatTimerId;
volatile uint32 timerFlag = 0;
volatile uint32 heartbeatRunning = 0;
volatile uint32 heartbeatRunning = HEART_BEAT_INIT;
pthread_mutex_t heartbeatMutex;
typedef enum { DO_WAL_DATA_WRITE_DONE, DO_WAL_DATA_WRITE_STOP, DO_WAL_DATA_WRITE_ERROR } DoWalDataWriteResult;
@ -211,8 +215,9 @@ void* heartbeatTimerHandler(void* data)
if (xlogconn == NULL) {
return NULL;
}
heartbeatRunning = 1;
while (heartbeatRunning) {
uint32 expected = HEART_BEAT_INIT;
(void)pg_atomic_compare_exchange_u32(&heartbeatRunning, &expected, HEART_BEAT_RUN);
while (pg_atomic_read_u32(&heartbeatRunning) == HEART_BEAT_RUN) {
pthread_mutex_lock(&heartbeatMutex);
(void)checkForReceiveTimeout(xlogconn);
ping_sent = false;
@ -256,7 +261,7 @@ void suspendHeartBeatTimer(void)
void closeHearBeatTimer(void)
{
heartbeatRunning = 0;
pg_atomic_write_u32(&heartbeatRunning, HEART_BEAT_STOP);
pthread_mutex_unlock(&heartbeatMutex);
(void)pthread_join(hearbeatTimerId, NULL);
return;