more code
This commit is contained in:
parent
fef8976836
commit
e710802f1f
|
@ -61,7 +61,7 @@ struct SVBufPoolNode {
|
|||
};
|
||||
|
||||
struct SVBufPool {
|
||||
SVBufPool* next;
|
||||
SVBufPool* freeNext;
|
||||
SVnode* pVnode;
|
||||
TdThreadSpinlock* lock;
|
||||
volatile int32_t nRef;
|
||||
|
|
|
@ -87,6 +87,8 @@ typedef struct SCommitInfo SCommitInfo;
|
|||
#define VNODE_RSMA1_DIR "rsma1"
|
||||
#define VNODE_RSMA2_DIR "rsma2"
|
||||
|
||||
#define VNODE_BUFPOOL_SEGMENTS 3
|
||||
|
||||
#define VND_INFO_FNAME "vnode.json"
|
||||
|
||||
// vnd.h
|
||||
|
@ -326,16 +328,21 @@ struct STsdbKeepCfg {
|
|||
};
|
||||
|
||||
struct SVnode {
|
||||
char* path;
|
||||
SVnodeCfg config;
|
||||
SVState state;
|
||||
SVStatis statis;
|
||||
STfs* pTfs;
|
||||
SMsgCb msgCb;
|
||||
char* path;
|
||||
SVnodeCfg config;
|
||||
SVState state;
|
||||
SVStatis statis;
|
||||
STfs* pTfs;
|
||||
SMsgCb msgCb;
|
||||
|
||||
// Buffer Pool
|
||||
TdThreadMutex mutex;
|
||||
TdThreadCond poolNotEmpty;
|
||||
SVBufPool* pPool;
|
||||
SVBufPool* aBufPool[VNODE_BUFPOOL_SEGMENTS];
|
||||
SVBufPool* freeList;
|
||||
SVBufPool* inUse;
|
||||
SVBufPool* recycling;
|
||||
|
||||
SMeta* pMeta;
|
||||
SSma* pSma;
|
||||
STsdb* pTsdb;
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
#include "vnd.h"
|
||||
|
||||
/* ------------------------ STRUCTURES ------------------------ */
|
||||
#define VNODE_BUFPOOL_SEGMENTS 3
|
||||
|
||||
static int vnodeBufPoolCreate(SVnode *pVnode, int64_t size, SVBufPool **ppPool) {
|
||||
SVBufPool *pPool;
|
||||
|
||||
|
@ -44,7 +42,7 @@ static int vnodeBufPoolCreate(SVnode *pVnode, int64_t size, SVBufPool **ppPool)
|
|||
pPool->lock = NULL;
|
||||
}
|
||||
|
||||
pPool->next = NULL;
|
||||
pPool->freeNext = NULL;
|
||||
pPool->pVnode = pVnode;
|
||||
pPool->nRef = 0;
|
||||
pPool->size = 0;
|
||||
|
@ -69,22 +67,21 @@ static int vnodeBufPoolDestroy(SVBufPool *pPool) {
|
|||
}
|
||||
|
||||
int vnodeOpenBufPool(SVnode *pVnode) {
|
||||
SVBufPool *pPool = NULL;
|
||||
int64_t size = pVnode->config.szBuf / VNODE_BUFPOOL_SEGMENTS;
|
||||
int64_t size = pVnode->config.szBuf / VNODE_BUFPOOL_SEGMENTS;
|
||||
|
||||
ASSERT(pVnode->pPool == NULL);
|
||||
ASSERT(pVnode->freeList == NULL);
|
||||
|
||||
for (int i = 0; i < VNODE_BUFPOOL_SEGMENTS; i++) {
|
||||
// create pool
|
||||
if (vnodeBufPoolCreate(pVnode, size, &pPool)) {
|
||||
if (vnodeBufPoolCreate(pVnode, size, &pVnode->aBufPool[i])) {
|
||||
vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
vnodeCloseBufPool(pVnode);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// add pool to vnode
|
||||
pPool->next = pVnode->pPool;
|
||||
pVnode->pPool = pPool;
|
||||
// add to free list
|
||||
pVnode->aBufPool[i]->freeNext = pVnode->freeList;
|
||||
pVnode->freeList = pVnode->aBufPool[i];
|
||||
}
|
||||
|
||||
vDebug("vgId:%d, vnode buffer pool is opened, size:%" PRId64, TD_VID(pVnode), size);
|
||||
|
@ -92,19 +89,18 @@ int vnodeOpenBufPool(SVnode *pVnode) {
|
|||
}
|
||||
|
||||
int vnodeCloseBufPool(SVnode *pVnode) {
|
||||
SVBufPool *pPool;
|
||||
|
||||
for (pPool = pVnode->pPool; pPool; pPool = pVnode->pPool) {
|
||||
pVnode->pPool = pPool->next;
|
||||
vnodeBufPoolDestroy(pPool);
|
||||
for (int32_t i = 0; i < VNODE_BUFPOOL_SEGMENTS; i++) {
|
||||
if (pVnode->aBufPool[i]) {
|
||||
vnodeBufPoolDestroy(pVnode->aBufPool[i]);
|
||||
pVnode->aBufPool[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (pVnode->inUse) {
|
||||
vnodeBufPoolDestroy(pVnode->inUse);
|
||||
pVnode->inUse = NULL;
|
||||
}
|
||||
pVnode->freeList = NULL;
|
||||
ASSERT(pVnode->inUse == NULL);
|
||||
ASSERT(pVnode->recycling == NULL);
|
||||
|
||||
vDebug("vgId:%d, vnode buffer pool is closed", TD_VID(pVnode));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -240,8 +236,8 @@ void vnodeBufPoolUnRef(SVBufPool *pPool) {
|
|||
}
|
||||
}
|
||||
|
||||
pPool->next = pVnode->pPool;
|
||||
pVnode->pPool = pPool;
|
||||
pPool->freeNext = pVnode->freeList;
|
||||
pVnode->freeList = pPool;
|
||||
taosThreadCondSignal(&pVnode->poolNotEmpty);
|
||||
|
||||
taosThreadMutexUnlock(&pVnode->mutex);
|
||||
|
|
|
@ -25,14 +25,14 @@ int vnodeBegin(SVnode *pVnode) {
|
|||
// alloc buffer pool
|
||||
taosThreadMutexLock(&pVnode->mutex);
|
||||
|
||||
while (pVnode->pPool == NULL) {
|
||||
while (pVnode->freeList == NULL) {
|
||||
taosThreadCondWait(&pVnode->poolNotEmpty, &pVnode->mutex);
|
||||
}
|
||||
|
||||
pVnode->inUse = pVnode->pPool;
|
||||
pVnode->inUse = pVnode->freeList;
|
||||
pVnode->inUse->nRef = 1;
|
||||
pVnode->pPool = pVnode->inUse->next;
|
||||
pVnode->inUse->next = NULL;
|
||||
pVnode->freeList = pVnode->inUse->freeNext;
|
||||
pVnode->inUse->freeNext = NULL;
|
||||
|
||||
taosThreadMutexUnlock(&pVnode->mutex);
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ _err:
|
|||
if (pVnode->pTsdb) tsdbClose(&pVnode->pTsdb);
|
||||
if (pVnode->pSma) smaClose(pVnode->pSma);
|
||||
if (pVnode->pMeta) metaClose(pVnode->pMeta);
|
||||
if (pVnode->pPool) vnodeCloseBufPool(pVnode);
|
||||
if (pVnode->freeList) vnodeCloseBufPool(pVnode);
|
||||
|
||||
tsem_destroy(&(pVnode->canCommit));
|
||||
taosMemoryFree(pVnode);
|
||||
|
|
Loading…
Reference in New Issue