enh: lock buf pool only for rsma vnode
This commit is contained in:
parent
5f97ea3ce1
commit
d9faec5e9f
|
@ -61,14 +61,14 @@ struct SVBufPoolNode {
|
|||
};
|
||||
|
||||
struct SVBufPool {
|
||||
SVBufPool* next;
|
||||
SVnode* pVnode;
|
||||
volatile int32_t nRef;
|
||||
TdThreadSpinlock lock;
|
||||
int64_t size;
|
||||
uint8_t* ptr;
|
||||
SVBufPoolNode* pTail;
|
||||
SVBufPoolNode node;
|
||||
SVBufPool* next;
|
||||
SVnode* pVnode;
|
||||
TdThreadSpinlock* lock;
|
||||
volatile int32_t nRef;
|
||||
int64_t size;
|
||||
uint8_t* ptr;
|
||||
SVBufPoolNode* pTail;
|
||||
SVBufPoolNode node;
|
||||
};
|
||||
|
||||
int32_t vnodeOpenBufPool(SVnode* pVnode);
|
||||
|
|
|
@ -27,10 +27,14 @@ static int vnodeBufPoolCreate(SVnode *pVnode, int64_t size, SVBufPool **ppPool)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (taosThreadSpinInit(&pPool->lock, 0) != 0) {
|
||||
taosMemoryFree(pPool);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
if (VND_IS_RSMA(pVnode)) {
|
||||
if (taosThreadSpinInit(pPool->lock, 0) != 0) {
|
||||
taosMemoryFree(pPool);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
pPool->lock = NULL;
|
||||
}
|
||||
|
||||
pPool->next = NULL;
|
||||
|
@ -49,7 +53,7 @@ static int vnodeBufPoolCreate(SVnode *pVnode, int64_t size, SVBufPool **ppPool)
|
|||
|
||||
static int vnodeBufPoolDestroy(SVBufPool *pPool) {
|
||||
vnodeBufPoolReset(pPool);
|
||||
taosThreadSpinDestroy(&pPool->lock);
|
||||
if (pPool->lock) taosThreadSpinDestroy(pPool->lock);
|
||||
taosMemoryFree(pPool);
|
||||
return 0;
|
||||
}
|
||||
|
@ -114,7 +118,7 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
|
|||
void *p = NULL;
|
||||
ASSERT(pPool != NULL);
|
||||
|
||||
taosThreadSpinLock(&pPool->lock);
|
||||
if(pPool->lock) taosThreadSpinLock(pPool->lock);
|
||||
if (pPool->node.size >= pPool->ptr - pPool->node.data + size) {
|
||||
// allocate from the anchor node
|
||||
p = pPool->ptr;
|
||||
|
@ -125,7 +129,7 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
|
|||
pNode = taosMemoryMalloc(sizeof(*pNode) + size);
|
||||
if (pNode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosThreadSpinUnlock(&pPool->lock);
|
||||
if (pPool->lock) taosThreadSpinUnlock(pPool->lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -138,7 +142,7 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
|
|||
|
||||
pPool->size = pPool->size + sizeof(*pNode) + size;
|
||||
}
|
||||
taosThreadSpinUnlock(&pPool->lock);
|
||||
if(pPool->lock) taosThreadSpinUnlock(pPool->lock);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue