From 2ce6142cdcfd69810cdf4324cf5ad8ec1d988439 Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Sun, 5 Apr 2020 19:24:19 +0800 Subject: [PATCH 1/2] a wrong pointer in vnodeWriteToQueue refCount shall be increased by one --- src/util/src/tqueue.c | 6 +++--- src/vnode/main/src/vnodeMain.c | 5 ++++- src/vnode/main/src/vnodeWrite.c | 3 ++- src/vnode/wal/src/walMain.c | 2 ++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/util/src/tqueue.c b/src/util/src/tqueue.c index 6d75776ac8..2cf94267f8 100644 --- a/src/util/src/tqueue.c +++ b/src/util/src/tqueue.c @@ -92,7 +92,7 @@ void *taosAllocateQitem(int size) { void taosFreeQitem(void *param) { if (param == NULL) return; - //pTrace("item:%p is freed", param); + pTrace("item:%p is freed", param); char *temp = (char *)param; temp -= sizeof(STaosQnode); @@ -117,7 +117,7 @@ int taosWriteQitem(taos_queue param, int type, void *item) { queue->numOfItems++; if (queue->qset) atomic_add_fetch_32(&queue->qset->numOfItems, 1); - //pTrace("item:%p is put into queue, type:%d items:%d", item, type, queue->numOfItems); + pTrace("item:%p is put into queue, type:%d items:%d", item, type, queue->numOfItems); pthread_mutex_unlock(&queue->mutex); @@ -197,7 +197,7 @@ int taosGetQitem(taos_qall param, int *type, void **pitem) { *pitem = pNode->item; *type = pNode->type; num = 1; - // pTrace("item:%p is fetched, type:%d", *pitem, *type); + pTrace("item:%p is fetched, type:%d", *pitem, *type); } return num; diff --git a/src/vnode/main/src/vnodeMain.c b/src/vnode/main/src/vnodeMain.c index 8f4ce802e7..4ca5a2f7a3 100644 --- a/src/vnode/main/src/vnodeMain.c +++ b/src/vnode/main/src/vnodeMain.c @@ -165,7 +165,10 @@ void vnodeRelease(void *pVnodeRaw) { int32_t refCount = atomic_sub_fetch_32(&pVnode->refCount, 1); - if (refCount > 0) return; + if (refCount > 0) { + dTrace("pVnode:%p vgId:%d, release vnode, refCount:%d", pVnode, pVnode->vgId, refCount); + return; + } // remove read queue dnodeFreeRqueue(pVnode->rqueue); diff --git a/src/vnode/main/src/vnodeWrite.c b/src/vnode/main/src/vnodeWrite.c index 2c31f2243b..c6699bd62c 100644 --- a/src/vnode/main/src/vnodeWrite.c +++ b/src/vnode/main/src/vnodeWrite.c @@ -255,7 +255,8 @@ int vnodeWriteToQueue(void *param, SWalHead *pHead, int type) { SWalHead *pWal = (SWalHead *)taosAllocateQitem(size); memcpy(pWal, pHead, size); - taosWriteQitem(pVnode->wqueue, type, pHead); + atomic_add_fetch_32(&pVnode->refCount, 1); + taosWriteQitem(pVnode->wqueue, type, pWal); return 0; } diff --git a/src/vnode/wal/src/walMain.c b/src/vnode/wal/src/walMain.c index e192e91e8a..9708b0d9dc 100644 --- a/src/vnode/wal/src/walMain.c +++ b/src/vnode/wal/src/walMain.c @@ -287,6 +287,8 @@ static int walRestoreWalFile(char *name, void *pVnode, int (*writeFp)(void *, SW (*writeFp)(pVnode, pHead, TAOS_QTYPE_WAL); } + free(buffer); + return code; } From a1f675c8d1214ef386e4139bed3bcb61007eb2c2 Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Sun, 5 Apr 2020 20:03:18 +0800 Subject: [PATCH 2/2] rename a structure to remove the duplication --- src/dnode/src/dnodeWrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dnode/src/dnodeWrite.c b/src/dnode/src/dnodeWrite.c index 2348cf62a4..aee14ed484 100644 --- a/src/dnode/src/dnodeWrite.c +++ b/src/dnode/src/dnodeWrite.c @@ -40,7 +40,7 @@ typedef struct { SRpcMsg rpcMsg; } SWriteMsg; -typedef struct _thread_obj { +typedef struct _wworker_pool { int32_t max; // max number of workers int32_t nextId; // from 0 to max-1, cyclic SWriteWorker *writeWorker;