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