refine stop processing

This commit is contained in:
slzhou 2022-04-22 16:52:50 +08:00
parent 0307010861
commit 8ce6f55a9d
2 changed files with 6 additions and 7 deletions

View File

@ -221,8 +221,8 @@ static int32_t dmSpawnUdfd(SDnode *pDnode);
void dmUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) { void dmUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) {
dInfo("udfd process exited with status %" PRId64 ", signal %d", exitStatus, termSignal); dInfo("udfd process exited with status %" PRId64 ", signal %d", exitStatus, termSignal);
SDnode *pDnode = process->data; SDnode *pDnode = process->data;
if (exitStatus == 0 && termSignal == 0) { if (exitStatus == 0 && termSignal == 0 || atomic_load_32(&pDnode->udfdData.stopCalled)) {
dInfo("udfd process exit due to SIGINT"); dInfo("udfd process exit due to SIGINT or dnode-mgmt called stop");
} else { } else {
dInfo("udfd process restart"); dInfo("udfd process restart");
dmSpawnUdfd(pDnode); dmSpawnUdfd(pDnode);
@ -327,14 +327,12 @@ static int32_t dmStopUdfd(SDnode *pDnode) {
dInfo("dnode-mgmt to stop udfd. need cleanup: %d, spawn err: %d", dInfo("dnode-mgmt to stop udfd. need cleanup: %d, spawn err: %d",
pDnode->udfdData.needCleanUp, pDnode->udfdData.spawnErr); pDnode->udfdData.needCleanUp, pDnode->udfdData.spawnErr);
SUdfdData *pData = &pDnode->udfdData; SUdfdData *pData = &pDnode->udfdData;
if (!pData->needCleanUp) { if (!pData->needCleanUp || atomic_load_32(&pData->stopCalled)) {
return 0; return 0;
} }
atomic_store_32(&pData->stopCalled, 1);
pData->needCleanUp = false;
uv_barrier_destroy(&pData->barrier); uv_barrier_destroy(&pData->barrier);
if (pData->spawnErr == 0) {
uv_process_kill(&pData->process, SIGINT);
}
uv_async_send(&pData->stopAsync); uv_async_send(&pData->stopAsync);
uv_thread_join(&pData->thread); uv_thread_join(&pData->thread);

View File

@ -153,6 +153,7 @@ typedef struct SUdfdData {
int spawnErr; int spawnErr;
uv_pipe_t ctrlPipe; uv_pipe_t ctrlPipe;
uv_async_t stopAsync; uv_async_t stopAsync;
int32_t stopCalled;
} SUdfdData; } SUdfdData;
typedef struct SDnode { typedef struct SDnode {