add buffer recycle
This commit is contained in:
parent
1d54f14c3b
commit
df35435416
|
@ -27,6 +27,8 @@ typedef struct SVBufPool SVBufPool;
|
||||||
|
|
||||||
int vnodeOpenBufPool(SVnode *pVnode);
|
int vnodeOpenBufPool(SVnode *pVnode);
|
||||||
void vnodeCloseBufPool(SVnode *pVnode);
|
void vnodeCloseBufPool(SVnode *pVnode);
|
||||||
|
int vnodeBufPoolSwitch(SVnode *pVnode);
|
||||||
|
int vnodeBufPoolRecycle(SVnode *pVnode);
|
||||||
void *vnodeMalloc(SVnode *pVnode, uint64_t size);
|
void *vnodeMalloc(SVnode *pVnode, uint64_t size);
|
||||||
bool vnodeBufPoolIsFull(SVnode *pVnode);
|
bool vnodeBufPoolIsFull(SVnode *pVnode);
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ extern "C" {
|
||||||
|
|
||||||
#define vnodeShouldCommit vnodeBufPoolIsFull
|
#define vnodeShouldCommit vnodeBufPoolIsFull
|
||||||
int vnodeAsyncCommit(SVnode *pVnode);
|
int vnodeAsyncCommit(SVnode *pVnode);
|
||||||
|
int vnodeCommit(void *arg);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,27 @@ void vnodeCloseBufPool(SVnode *pVnode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vnodeBufPoolSwitch(SVnode *pVnode) {
|
||||||
|
SVMemAllocator *pvma = pVnode->pBufPool->inuse;
|
||||||
|
|
||||||
|
pVnode->pBufPool->inuse = NULL;
|
||||||
|
|
||||||
|
tDListAppend(&(pVnode->pBufPool->incycle), pvma);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int vnodeBufPoolRecycle(SVnode *pVnode) {
|
||||||
|
SVBufPool * pBufPool = pVnode->pBufPool;
|
||||||
|
SVMemAllocator *pvma = TD_DLIST_HEAD(&(pBufPool->incycle));
|
||||||
|
ASSERT(pvma != NULL);
|
||||||
|
|
||||||
|
tDListPop(&(pBufPool->incycle), pvma);
|
||||||
|
vmaReset(pvma);
|
||||||
|
tDListAppend(&(pBufPool->free), pvma);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void *vnodeMalloc(SVnode *pVnode, uint64_t size) {
|
void *vnodeMalloc(SVnode *pVnode, uint64_t size) {
|
||||||
SVBufPool *pBufPool = pVnode->pBufPool;
|
SVBufPool *pBufPool = pVnode->pBufPool;
|
||||||
|
|
||||||
|
|
|
@ -19,28 +19,21 @@ static int vnodeStartCommit(SVnode *pVnode);
|
||||||
static int vnodeEndCommit(SVnode *pVnode);
|
static int vnodeEndCommit(SVnode *pVnode);
|
||||||
|
|
||||||
int vnodeAsyncCommit(SVnode *pVnode) {
|
int vnodeAsyncCommit(SVnode *pVnode) {
|
||||||
#if 0
|
vnodeBufPoolSwitch(pVnode);
|
||||||
if (vnodeStartCommit(pVnode) < 0) {
|
SVnodeTask *pTask = (SVnodeTask *)malloc(sizeof(*pTask));
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tqCommit(pVnode->pTQ) < 0) {
|
pTask->execute = vnodeCommit; // TODO
|
||||||
// TODO
|
pTask->arg = pVnode; // TODO
|
||||||
}
|
|
||||||
|
|
||||||
if (metaCommit(pVnode->pMeta) < 0) {
|
vnodeScheduleTask(pTask);
|
||||||
// TODO
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tsdbCommit(pVnode->pTsdb) < 0) {
|
int vnodeCommit(void *arg) {
|
||||||
// TODO
|
SVnode *pVnode = (SVnode *)arg;
|
||||||
}
|
|
||||||
|
|
||||||
if (vnodeEndCommit(pVnode) < 0) {
|
vnodeBufPoolRecycle(pVnode);
|
||||||
// TODO
|
// TODO
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,19 @@ void vnodeClear() {
|
||||||
pthread_mutex_destroy(&(vnodeMgr.mutex));
|
pthread_mutex_destroy(&(vnodeMgr.mutex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vnodeScheduleTask(SVnodeTask* pTask) {
|
||||||
|
pthread_mutex_lock(&(vnodeMgr.mutex));
|
||||||
|
|
||||||
|
tDListAppend(&(vnodeMgr.queue), pTask);
|
||||||
|
|
||||||
|
pthread_cond_signal(&(vnodeMgr.hasTask));
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&(vnodeMgr.mutex));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------ STATIC METHODS ------------------------ */
|
||||||
static void* loop(void* arg) {
|
static void* loop(void* arg) {
|
||||||
SVnodeTask* pTask;
|
SVnodeTask* pTask;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
Loading…
Reference in New Issue