reduce mutex lock usage time
This commit is contained in:
parent
ca2e761a86
commit
96c59cc746
|
@ -176,11 +176,11 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define TAOS_CHECK_RETURN_WITH_MUTEX(CMD, MUTEX) \
|
#define TAOS_CHECK_RETURN_WITH_FREE(CMD, PTR) \
|
||||||
do { \
|
do { \
|
||||||
int32_t __c = (CMD); \
|
int32_t __c = (CMD); \
|
||||||
if (__c != TSDB_CODE_SUCCESS) { \
|
if (__c != TSDB_CODE_SUCCESS) { \
|
||||||
taosThreadMutexUnlock(MUTEX); \
|
taosMemoryFree(PTR); \
|
||||||
TAOS_RETURN(__c); \
|
TAOS_RETURN(__c); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
|
@ -202,22 +202,28 @@ static int32_t walReadSeekVerImpl(SWalReader *pReader, int64_t ver) {
|
||||||
SWalFileInfo tmpInfo;
|
SWalFileInfo tmpInfo;
|
||||||
tmpInfo.firstVer = ver;
|
tmpInfo.firstVer = ver;
|
||||||
taosThreadMutexLock(&pWal->mutex);
|
taosThreadMutexLock(&pWal->mutex);
|
||||||
SWalFileInfo *pRet = taosArraySearch(pWal->fileInfoSet, &tmpInfo, compareWalFileInfo, TD_LE);
|
SWalFileInfo *gloablPRet = taosArraySearch(pWal->fileInfoSet, &tmpInfo, compareWalFileInfo, TD_LE);
|
||||||
if (pRet == NULL) {
|
if (gloablPRet == NULL) {
|
||||||
wError("failed to find WAL log file with ver:%" PRId64, ver);
|
wError("failed to find WAL log file with ver:%" PRId64, ver);
|
||||||
taosThreadMutexUnlock(&pWal->mutex);
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
TAOS_RETURN(TSDB_CODE_WAL_INVALID_VER);
|
TAOS_RETURN(TSDB_CODE_WAL_INVALID_VER);
|
||||||
}
|
}
|
||||||
|
SWalFileInfo *pRet = taosMemoryMalloc(sizeof(SWalFileInfo));
|
||||||
|
if (pRet == NULL) {
|
||||||
|
wError("failed to allocate memory for localRet");
|
||||||
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
|
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
}
|
||||||
|
TAOS_MEMCPY(pRet, gloablPRet, sizeof(SWalFileInfo));
|
||||||
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
if (pReader->curFileFirstVer != pRet->firstVer) {
|
if (pReader->curFileFirstVer != pRet->firstVer) {
|
||||||
// error code was set inner
|
// error code was set inner
|
||||||
TAOS_CHECK_RETURN_WITH_MUTEX(walReadChangeFile(pReader, pRet->firstVer), &pWal->mutex);
|
TAOS_CHECK_RETURN_WITH_FREE(walReadChangeFile(pReader, pRet->firstVer), pRet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// error code was set inner
|
// error code was set inner
|
||||||
TAOS_CHECK_RETURN_WITH_MUTEX(walReadSeekFilePos(pReader, pRet->firstVer, ver), &pWal->mutex);
|
TAOS_CHECK_RETURN_WITH_FREE(walReadSeekFilePos(pReader, pRet->firstVer, ver), pRet);
|
||||||
|
taosMemoryFree(pRet);
|
||||||
taosThreadMutexUnlock(&pWal->mutex);
|
|
||||||
wDebug("vgId:%d, wal version reset from %" PRId64 " to %" PRId64, pReader->pWal->cfg.vgId, pReader->curVersion, ver);
|
wDebug("vgId:%d, wal version reset from %" PRId64 " to %" PRId64, pReader->pWal->cfg.vgId, pReader->curVersion, ver);
|
||||||
|
|
||||||
pReader->curVersion = ver;
|
pReader->curVersion = ver;
|
||||||
|
|
Loading…
Reference in New Issue