more code
This commit is contained in:
parent
851dba5166
commit
f26f661f47
|
@ -83,6 +83,8 @@ struct SVBufPool {
|
||||||
int32_t vnodeOpenBufPool(SVnode* pVnode);
|
int32_t vnodeOpenBufPool(SVnode* pVnode);
|
||||||
int32_t vnodeCloseBufPool(SVnode* pVnode);
|
int32_t vnodeCloseBufPool(SVnode* pVnode);
|
||||||
void vnodeBufPoolReset(SVBufPool* pPool);
|
void vnodeBufPoolReset(SVBufPool* pPool);
|
||||||
|
void vnodeBufPoolAddToFreeList(SVBufPool* pPool);
|
||||||
|
int32_t vnodeBufPoolRecycle(SVBufPool* pPool);
|
||||||
|
|
||||||
// vnodeQuery.c
|
// vnodeQuery.c
|
||||||
int32_t vnodeQueryOpen(SVnode* pVnode);
|
int32_t vnodeQueryOpen(SVnode* pVnode);
|
||||||
|
|
|
@ -212,34 +212,9 @@ void vnodeBufPoolRef(SVBufPool *pPool) {
|
||||||
ASSERT(nRef > 0);
|
ASSERT(nRef > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeBufPoolUnRef(SVBufPool *pPool) {
|
void vnodeBufPoolAddToFreeList(SVBufPool *pPool) {
|
||||||
if (pPool == NULL) return;
|
|
||||||
|
|
||||||
SVnode *pVnode = pPool->pVnode;
|
SVnode *pVnode = pPool->pVnode;
|
||||||
|
|
||||||
taosThreadMutexLock(&pVnode->mutex);
|
|
||||||
|
|
||||||
if (atomic_sub_fetch_32(&pPool->nRef, 1) > 0) goto _exit;
|
|
||||||
|
|
||||||
// remove from recycle list or on-recycle position
|
|
||||||
if (pVnode->onRecycle == pPool) {
|
|
||||||
pVnode->onRecycle = NULL;
|
|
||||||
} else {
|
|
||||||
if (pPool->recyclePrev) {
|
|
||||||
pPool->recyclePrev->recycleNext = pPool->recycleNext;
|
|
||||||
} else {
|
|
||||||
pVnode->recycleHead = pPool->recycleNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pPool->recycleNext) {
|
|
||||||
pPool->recycleNext->recyclePrev = pPool->recyclePrev;
|
|
||||||
} else {
|
|
||||||
pVnode->recycleTail = pPool->recyclePrev;
|
|
||||||
}
|
|
||||||
pPool->recyclePrev = pPool->recycleNext = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// change the pool size if need
|
|
||||||
int64_t size = pVnode->config.szBuf / VNODE_BUFPOOL_SEGMENTS;
|
int64_t size = pVnode->config.szBuf / VNODE_BUFPOOL_SEGMENTS;
|
||||||
if (pPool->node.size != size) {
|
if (pPool->node.size != size) {
|
||||||
SVBufPool *pNewPool = NULL;
|
SVBufPool *pNewPool = NULL;
|
||||||
|
@ -257,10 +232,41 @@ void vnodeBufPoolUnRef(SVBufPool *pPool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to free list
|
// add to free list
|
||||||
|
vDebug("vgId:%d buffer pool %p of id %d is added to free list", TD_VID(pVnode), pPool, pPool->id);
|
||||||
vnodeBufPoolReset(pPool);
|
vnodeBufPoolReset(pPool);
|
||||||
pPool->freeNext = pVnode->freeList;
|
pPool->freeNext = pVnode->freeList;
|
||||||
pVnode->freeList = pPool;
|
pVnode->freeList = pPool;
|
||||||
taosThreadCondSignal(&pVnode->poolNotEmpty);
|
taosThreadCondSignal(&pVnode->poolNotEmpty);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vnodeBufPoolUnRef(SVBufPool *pPool) {
|
||||||
|
if (pPool == NULL) return;
|
||||||
|
|
||||||
|
SVnode *pVnode = pPool->pVnode;
|
||||||
|
|
||||||
|
taosThreadMutexLock(&pVnode->mutex);
|
||||||
|
|
||||||
|
if (atomic_sub_fetch_32(&pPool->nRef, 1) > 0) goto _exit;
|
||||||
|
|
||||||
|
// remove from recycle queue or on-recycle position
|
||||||
|
if (pVnode->onRecycle == pPool) {
|
||||||
|
pVnode->onRecycle = NULL;
|
||||||
|
} else {
|
||||||
|
if (pPool->recyclePrev) {
|
||||||
|
pPool->recyclePrev->recycleNext = pPool->recycleNext;
|
||||||
|
} else {
|
||||||
|
pVnode->recycleHead = pPool->recycleNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pPool->recycleNext) {
|
||||||
|
pPool->recycleNext->recyclePrev = pPool->recyclePrev;
|
||||||
|
} else {
|
||||||
|
pVnode->recycleTail = pPool->recyclePrev;
|
||||||
|
}
|
||||||
|
pPool->recyclePrev = pPool->recycleNext = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
vnodeBufPoolAddToFreeList(pPool);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
taosThreadMutexUnlock(&pVnode->mutex);
|
taosThreadMutexUnlock(&pVnode->mutex);
|
||||||
|
@ -298,3 +304,45 @@ int32_t vnodeBufPoolDeregisterQuery(SVBufPool *pPool, SQueryNode *pQNode) {
|
||||||
_exit:
|
_exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t vnodeBufPoolRecycle(SVBufPool *pPool) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
bool canRecycle;
|
||||||
|
SVnode *pVnode = pPool->pVnode;
|
||||||
|
|
||||||
|
vDebug("vgId:%d recycle buffer pool %p of id %d", TD_VID(pVnode), pPool, pPool->id);
|
||||||
|
|
||||||
|
taosThreadMutexLock(&pPool->mutex);
|
||||||
|
|
||||||
|
SQueryNode *pNode = pPool->qList.pNext;
|
||||||
|
while (pNode != &pPool->qList) {
|
||||||
|
int32_t rc = pNode->reseek(pNode->pQHandle);
|
||||||
|
if (rc == 0) {
|
||||||
|
SQueryNode *pTNode = pNode->pNext;
|
||||||
|
pNode->pNext->ppNext = pNode->ppNext;
|
||||||
|
*pNode->ppNext = pNode->pNext;
|
||||||
|
pPool->nQuery--;
|
||||||
|
pNode = pTNode;
|
||||||
|
} else if (rc == TSDB_CODE_VND_QUERY_BUSY) {
|
||||||
|
pNode = pNode->pNext;
|
||||||
|
} else {
|
||||||
|
taosThreadMutexUnlock(&pPool->mutex);
|
||||||
|
code = rc;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
canRecycle = (pPool->nQuery == 0);
|
||||||
|
|
||||||
|
taosThreadMutexUnlock(&pPool->mutex);
|
||||||
|
|
||||||
|
if (canRecycle) {
|
||||||
|
ASSERT(atomic_load_32(&pPool->nRef) == 0);
|
||||||
|
pVnode->onRecycle = NULL;
|
||||||
|
vnodeBufPoolAddToFreeList(pPool);
|
||||||
|
}
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
return code;
|
||||||
|
}
|
|
@ -31,7 +31,7 @@ static int32_t vnodeTryRecycleBufPool(SVnode *pVnode) {
|
||||||
vDebug("vgId:%d no recyclable buffer pool", TD_VID(pVnode));
|
vDebug("vgId:%d no recyclable buffer pool", TD_VID(pVnode));
|
||||||
goto _exit;
|
goto _exit;
|
||||||
} else {
|
} else {
|
||||||
vDebug("vgId:%d buffer pool %p of id %d on recycle list, try to recycle", TD_VID(pVnode), pVnode->recycleHead,
|
vDebug("vgId:%d buffer pool %p of id %d on recycle queue, try to recycle", TD_VID(pVnode), pVnode->recycleHead,
|
||||||
pVnode->recycleHead->id);
|
pVnode->recycleHead->id);
|
||||||
|
|
||||||
pVnode->onRecycle = pVnode->recycleHead;
|
pVnode->onRecycle = pVnode->recycleHead;
|
||||||
|
@ -45,33 +45,8 @@ static int32_t vnodeTryRecycleBufPool(SVnode *pVnode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// do recycle the buffer pool
|
code = vnodeBufPoolRecycle(pVnode->onRecycle);
|
||||||
SVBufPool *pPool = pVnode->onRecycle;
|
if (code) goto _exit;
|
||||||
vDebug("vgId:%d buffer pool %p of id %d on recycle", TD_VID(pVnode), pPool, pPool->id);
|
|
||||||
|
|
||||||
taosThreadMutexLock(&pPool->mutex);
|
|
||||||
|
|
||||||
SQueryNode *pNode = pPool->qList.pNext;
|
|
||||||
while (pNode != &pPool->qList) {
|
|
||||||
int32_t rc = pNode->reseek(pNode->pQHandle);
|
|
||||||
if (rc == 0) {
|
|
||||||
SQueryNode *pTNode = pNode->pNext;
|
|
||||||
pNode->pNext->ppNext = pNode->ppNext;
|
|
||||||
*pNode->ppNext = pNode->pNext;
|
|
||||||
pPool->nQuery--;
|
|
||||||
pNode = pTNode;
|
|
||||||
} else if (rc == TSDB_CODE_VND_QUERY_BUSY) {
|
|
||||||
pNode = pNode->pNext;
|
|
||||||
} else {
|
|
||||||
taosThreadMutexUnlock(&pPool->mutex);
|
|
||||||
code = rc;
|
|
||||||
goto _exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
taosThreadMutexUnlock(&pPool->mutex);
|
|
||||||
|
|
||||||
// TODO: if (pPool->nQuery == 0) add to free list
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
|
@ -360,17 +335,7 @@ _exit:
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
static int32_t vnodeCommitTask(void *arg) {
|
static void vnodeReturnBufPool(SVnode *pVnode) {
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
SCommitInfo *pInfo = (SCommitInfo *)arg;
|
|
||||||
SVnode *pVnode = pInfo->pVnode;
|
|
||||||
|
|
||||||
// commit
|
|
||||||
code = vnodeCommitImpl(pInfo);
|
|
||||||
if (code) goto _exit;
|
|
||||||
|
|
||||||
// recycle buffer pool
|
|
||||||
taosThreadMutexLock(&pVnode->mutex);
|
taosThreadMutexLock(&pVnode->mutex);
|
||||||
|
|
||||||
SVBufPool *pPool = pVnode->onCommit;
|
SVBufPool *pPool = pVnode->onCommit;
|
||||||
|
@ -378,16 +343,9 @@ static int32_t vnodeCommitTask(void *arg) {
|
||||||
|
|
||||||
pVnode->onCommit = NULL;
|
pVnode->onCommit = NULL;
|
||||||
if (nRef == 0) {
|
if (nRef == 0) {
|
||||||
// add to free list
|
vnodeBufPoolAddToFreeList(pPool);
|
||||||
vDebug("vgId:%d buffer pool %p of id %d is added to free list", TD_VID(pVnode), pPool, pPool->id);
|
|
||||||
|
|
||||||
vnodeBufPoolReset(pPool);
|
|
||||||
pPool->freeNext = pVnode->freeList;
|
|
||||||
pVnode->freeList = pPool;
|
|
||||||
taosThreadCondSignal(&pVnode->poolNotEmpty);
|
|
||||||
} else if (nRef > 0) {
|
} else if (nRef > 0) {
|
||||||
// add to recycle list
|
vDebug("vgId:%d buffer pool %p of id %d is added to recycle queue", TD_VID(pVnode), pPool, pPool->id);
|
||||||
vDebug("vgId:%d buffer pool %p of id %d is added to recycle list", TD_VID(pVnode), pPool, pPool->id);
|
|
||||||
|
|
||||||
if (pVnode->recycleTail == NULL) {
|
if (pVnode->recycleTail == NULL) {
|
||||||
pPool->recyclePrev = pPool->recycleNext = NULL;
|
pPool->recyclePrev = pPool->recycleNext = NULL;
|
||||||
|
@ -403,6 +361,18 @@ static int32_t vnodeCommitTask(void *arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadMutexUnlock(&pVnode->mutex);
|
taosThreadMutexUnlock(&pVnode->mutex);
|
||||||
|
}
|
||||||
|
static int32_t vnodeCommitTask(void *arg) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
SCommitInfo *pInfo = (SCommitInfo *)arg;
|
||||||
|
SVnode *pVnode = pInfo->pVnode;
|
||||||
|
|
||||||
|
// commit
|
||||||
|
code = vnodeCommitImpl(pInfo);
|
||||||
|
if (code) goto _exit;
|
||||||
|
|
||||||
|
vnodeReturnBufPool(pVnode);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
// end commit
|
// end commit
|
||||||
|
|
Loading…
Reference in New Issue