提交 5651bde6 编写于 作者: C Cary Xu

enh: use lock in buf pool only for rsma vnode

上级 13680e2e
...@@ -65,6 +65,7 @@ struct SVBufPool { ...@@ -65,6 +65,7 @@ struct SVBufPool {
SVnode* pVnode; SVnode* pVnode;
volatile int32_t nRef; volatile int32_t nRef;
TdThreadSpinlock lock; TdThreadSpinlock lock;
bool isLock;
int64_t size; int64_t size;
uint8_t* ptr; uint8_t* ptr;
SVBufPoolNode* pTail; SVBufPoolNode* pTail;
......
...@@ -27,10 +27,15 @@ static int vnodeBufPoolCreate(SVnode *pVnode, int64_t size, SVBufPool **ppPool) ...@@ -27,10 +27,15 @@ 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;
}
pPool->isLock = true;
} else {
pPool->isLock = false;
} }
pPool->next = NULL; pPool->next = NULL;
...@@ -49,7 +54,9 @@ static int vnodeBufPoolCreate(SVnode *pVnode, int64_t size, SVBufPool **ppPool) ...@@ -49,7 +54,9 @@ 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->isLock) {
taosThreadSpinDestroy(&pPool->lock);
}
taosMemoryFree(pPool); taosMemoryFree(pPool);
return 0; return 0;
} }
...@@ -114,7 +121,10 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) { ...@@ -114,7 +121,10 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) {
void *p = NULL; void *p = NULL;
ASSERT(pPool != NULL); ASSERT(pPool != NULL);
taosThreadSpinLock(&pPool->lock); if (pPool->isLock) {
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 +135,9 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) { ...@@ -125,7 +135,9 @@ 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->isLock) {
taosThreadSpinUnlock(&pPool->lock);
}
return NULL; return NULL;
} }
...@@ -138,7 +150,9 @@ void *vnodeBufPoolMalloc(SVBufPool *pPool, int size) { ...@@ -138,7 +150,9 @@ 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->isLock) {
taosThreadSpinUnlock(&pPool->lock);
}
return p; return p;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册