提交 f0e9656b 编写于 作者: M Minglei Jin

Merge branch 'fix/long_query' of https://github.com/taosdata/TDengine into fix/long_query

...@@ -79,12 +79,16 @@ _exit: ...@@ -79,12 +79,16 @@ _exit:
} }
return code; return code;
} }
int vnodeBegin(SVnode *pVnode) { static int32_t vnodeGetBufPoolToUse(SVnode *pVnode) {
// alloc buffer pool int32_t code = 0;
int32_t lino = 0;
taosThreadMutexLock(&pVnode->mutex); taosThreadMutexLock(&pVnode->mutex);
int32_t nTry = 0; int32_t nTry = 0;
while (++nTry) { for (;;) {
++nTry;
if (pVnode->freeList) { if (pVnode->freeList) {
vDebug("vgId:%d allocate free buffer pool on %d try, pPool:%p id:%d", TD_VID(pVnode), nTry, pVnode->freeList, vDebug("vgId:%d allocate free buffer pool on %d try, pPool:%p id:%d", TD_VID(pVnode), nTry, pVnode->freeList,
pVnode->freeList->id); pVnode->freeList->id);
...@@ -97,12 +101,8 @@ int vnodeBegin(SVnode *pVnode) { ...@@ -97,12 +101,8 @@ int vnodeBegin(SVnode *pVnode) {
} else { } else {
vInfo("vgId:%d no free buffer pool on %d try, try to recycle...", TD_VID(pVnode), nTry); vInfo("vgId:%d no free buffer pool on %d try, try to recycle...", TD_VID(pVnode), nTry);
terrno = vnodeTryRecycleBufPool(pVnode); code = vnodeTryRecycleBufPool(pVnode);
if (terrno != TSDB_CODE_SUCCESS) { TSDB_CHECK_CODE(code, lino, _exit);
vError("vgId:%d %s failed since %s", TD_VID(pVnode), __func__, tstrerror(terrno));
taosThreadMutexUnlock(&pVnode->mutex);
return -1;
}
if (pVnode->freeList == NULL) { if (pVnode->freeList == NULL) {
vDebug("vgId:%d no free buffer pool on %d try, wait %d ms...", TD_VID(pVnode), nTry, WAIT_TIME_MILI_SEC); vDebug("vgId:%d no free buffer pool on %d try, wait %d ms...", TD_VID(pVnode), nTry, WAIT_TIME_MILI_SEC);
...@@ -115,37 +115,53 @@ int vnodeBegin(SVnode *pVnode) { ...@@ -115,37 +115,53 @@ int vnodeBegin(SVnode *pVnode) {
int32_t rc = taosThreadCondTimedWait(&pVnode->poolNotEmpty, &pVnode->mutex, &ts); int32_t rc = taosThreadCondTimedWait(&pVnode->poolNotEmpty, &pVnode->mutex, &ts);
if (rc && rc != ETIMEDOUT) { if (rc && rc != ETIMEDOUT) {
terrno = TAOS_SYSTEM_ERROR(rc); code = TAOS_SYSTEM_ERROR(rc);
vError("vgId:%d %s failed since %s", TD_VID(pVnode), __func__, tstrerror(terrno)); TSDB_CHECK_CODE(code, lino, _exit);
taosThreadMutexUnlock(&pVnode->mutex);
return -1;
} }
} }
} }
} }
_exit:
taosThreadMutexUnlock(&pVnode->mutex); taosThreadMutexUnlock(&pVnode->mutex);
if (code) {
vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
}
return code;
}
int vnodeBegin(SVnode *pVnode) {
int32_t code = 0;
int32_t lino = 0;
pVnode->state.commitID++; pVnode->state.commitID++;
// alloc buffer pool
code = vnodeGetBufPoolToUse(pVnode);
TSDB_CHECK_CODE(code, lino, _exit);
// begin meta // begin meta
if (metaBegin(pVnode->pMeta, META_BEGIN_HEAP_BUFFERPOOL) < 0) { if (metaBegin(pVnode->pMeta, META_BEGIN_HEAP_BUFFERPOOL) < 0) {
vError("vgId:%d, failed to begin meta since %s", TD_VID(pVnode), tstrerror(terrno)); code = terrno;
return -1; TSDB_CHECK_CODE(code, lino, _exit);
} }
// begin tsdb // begin tsdb
if (tsdbBegin(pVnode->pTsdb) < 0) { if (tsdbBegin(pVnode->pTsdb) < 0) {
vError("vgId:%d, failed to begin tsdb since %s", TD_VID(pVnode), tstrerror(terrno)); code = terrno;
return -1; TSDB_CHECK_CODE(code, lino, _exit);
} }
// begin sma // begin sma
if (VND_IS_RSMA(pVnode) && smaBegin(pVnode->pSma) < 0) { if (VND_IS_RSMA(pVnode) && smaBegin(pVnode->pSma) < 0) {
vError("vgId:%d, failed to begin sma since %s", TD_VID(pVnode), tstrerror(terrno)); code = terrno;
return -1; TSDB_CHECK_CODE(code, lino, _exit);
} }
return 0; _exit:
if (code) {
vError("vgId:%d %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
}
return code;
} }
void vnodeUpdCommitSched(SVnode *pVnode) { void vnodeUpdCommitSched(SVnode *pVnode) {
...@@ -160,7 +176,7 @@ int vnodeShouldCommit(SVnode *pVnode) { ...@@ -160,7 +176,7 @@ int vnodeShouldCommit(SVnode *pVnode) {
} }
SVCommitSched *pSched = &pVnode->commitSched; SVCommitSched *pSched = &pVnode->commitSched;
int64_t nowMs = taosGetMonoTimestampMs(); int64_t nowMs = taosGetMonoTimestampMs();
return (((pVnode->inUse->size > pVnode->inUse->node.size) && (pSched->commitMs + SYNC_VND_COMMIT_MIN_MS < nowMs)) || return (((pVnode->inUse->size > pVnode->inUse->node.size) && (pSched->commitMs + SYNC_VND_COMMIT_MIN_MS < nowMs)) ||
(pVnode->inUse->size > 0 && pSched->commitMs + pSched->maxWaitMs < nowMs)); (pVnode->inUse->size > 0 && pSched->commitMs + pSched->maxWaitMs < nowMs));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册