From b168766ff2ff4a3c4a3f17ff40a26cc49ffbc16f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 30 Mar 2022 20:32:01 +0800 Subject: [PATCH] shm --- include/util/taoserror.h | 1 + source/dnode/mgmt/main/src/dndFile.c | 2 +- source/dnode/mgmt/main/src/dndObj.c | 8 +++++--- source/os/src/osShm.c | 13 ++++++------- source/util/src/terror.c | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index d49e83b012..27145afc3d 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -78,6 +78,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_CFG_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x010C) #define TSDB_CODE_INVALID_CFG TAOS_DEF_ERROR_CODE(0, 0x010D) #define TSDB_CODE_OUT_OF_SHM_MEM TAOS_DEF_ERROR_CODE(0, 0x010E) +#define TSDB_CODE_INVALID_SHM_ID TAOS_DEF_ERROR_CODE(0, 0x010F) #define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0110) #define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0111) #define TSDB_CODE_REF_ID_REMOVED TAOS_DEF_ERROR_CODE(0, 0x0112) diff --git a/source/dnode/mgmt/main/src/dndFile.c b/source/dnode/mgmt/main/src/dndFile.c index bbd1cd3b92..edd5b75d97 100644 --- a/source/dnode/mgmt/main/src/dndFile.c +++ b/source/dnode/mgmt/main/src/dndFile.c @@ -191,7 +191,7 @@ int32_t dndReadShmFile(SDnode *pDnode) { SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; if (taosAttachShm(&pWrapper->shm) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("shmid:%d, failed to attach since %s", pWrapper->shm.id, terrstr()); + dError("shmid:%d, failed to attach shm since %s", pWrapper->shm.id, terrstr()); goto _OVER; } dDebug("shmid:%d, is attached, size:%d", pWrapper->shm.id, pWrapper->shm.size); diff --git a/source/dnode/mgmt/main/src/dndObj.c b/source/dnode/mgmt/main/src/dndObj.c index 387efca846..cd0ef4879b 100644 --- a/source/dnode/mgmt/main/src/dndObj.c +++ b/source/dnode/mgmt/main/src/dndObj.c @@ -35,9 +35,11 @@ static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { return -1; } - pDnode->lockfile = dndCheckRunning(pDnode->dataDir); - if (pDnode->lockfile == NULL) { - return -1; + if (!tsMultiProcess || pDnode->ntype == DNODE) { + pDnode->lockfile = dndCheckRunning(pDnode->dataDir); + if (pDnode->lockfile == NULL) { + return -1; + } } return 0; diff --git a/source/os/src/osShm.c b/source/os/src/osShm.c index 74717878a0..ba184c1f5d 100644 --- a/source/os/src/osShm.c +++ b/source/os/src/osShm.c @@ -49,12 +49,11 @@ void taosDropShm(SShm* pShm) { } int32_t taosAttachShm(SShm* pShm) { - if (pShm->id >= 0) { - pShm->ptr = shmat(pShm->id, NULL, 0); - if (pShm->ptr != NULL) { - return 0; - } - } + errno = 0; - return -1; + void* ptr = shmat(pShm->id, NULL, 0); + if (errno == 0) { + pShm->ptr = ptr; + } + return errno; } diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 005995c8e2..90fa624a8d 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -85,7 +85,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_REPEAT_INIT, "Repeat initialization TAOS_DEFINE_ERROR(TSDB_CODE_CFG_NOT_FOUND, "Config not found") TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CFG, "Invalid config option") TAOS_DEFINE_ERROR(TSDB_CODE_OUT_OF_SHM_MEM, "Out of Share memory") - +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_SHM_ID, "Invalid SHM ID") TAOS_DEFINE_ERROR(TSDB_CODE_REF_NO_MEMORY, "Ref out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_REF_FULL, "too many Ref Objs") TAOS_DEFINE_ERROR(TSDB_CODE_REF_ID_REMOVED, "Ref ID is removed")