more code
This commit is contained in:
parent
75cd1fc9bf
commit
d7ec7ed936
|
@ -62,6 +62,8 @@ struct SVBufPoolNode {
|
||||||
|
|
||||||
struct SVBufPool {
|
struct SVBufPool {
|
||||||
SVBufPool* freeNext;
|
SVBufPool* freeNext;
|
||||||
|
SVBufPool* recycleNext;
|
||||||
|
SVBufPool* recyclePrev;
|
||||||
SVnode* pVnode;
|
SVnode* pVnode;
|
||||||
TdThreadSpinlock* lock;
|
TdThreadSpinlock* lock;
|
||||||
volatile int32_t nRef;
|
volatile int32_t nRef;
|
||||||
|
|
|
@ -69,8 +69,6 @@ static int vnodeBufPoolDestroy(SVBufPool *pPool) {
|
||||||
int vnodeOpenBufPool(SVnode *pVnode) {
|
int vnodeOpenBufPool(SVnode *pVnode) {
|
||||||
int64_t size = pVnode->config.szBuf / VNODE_BUFPOOL_SEGMENTS;
|
int64_t size = pVnode->config.szBuf / VNODE_BUFPOOL_SEGMENTS;
|
||||||
|
|
||||||
ASSERT(pVnode->freeList == NULL);
|
|
||||||
|
|
||||||
for (int i = 0; i < VNODE_BUFPOOL_SEGMENTS; i++) {
|
for (int i = 0; i < VNODE_BUFPOOL_SEGMENTS; i++) {
|
||||||
// create pool
|
// create pool
|
||||||
if (vnodeBufPoolCreate(pVnode, size, &pVnode->aBufPool[i])) {
|
if (vnodeBufPoolCreate(pVnode, size, &pVnode->aBufPool[i])) {
|
||||||
|
|
|
@ -21,18 +21,48 @@
|
||||||
static int vnodeEncodeInfo(const SVnodeInfo *pInfo, char **ppData);
|
static int vnodeEncodeInfo(const SVnodeInfo *pInfo, char **ppData);
|
||||||
static int vnodeCommitImpl(SCommitInfo *pInfo);
|
static int vnodeCommitImpl(SCommitInfo *pInfo);
|
||||||
|
|
||||||
|
#define WAIT_TIME_MILI_SEC 10 // miliseconds
|
||||||
|
|
||||||
int vnodeBegin(SVnode *pVnode) {
|
int vnodeBegin(SVnode *pVnode) {
|
||||||
// alloc buffer pool
|
// alloc buffer pool
|
||||||
taosThreadMutexLock(&pVnode->mutex);
|
taosThreadMutexLock(&pVnode->mutex);
|
||||||
|
|
||||||
while (pVnode->freeList == NULL) {
|
int32_t nTry = 0;
|
||||||
taosThreadCondWait(&pVnode->poolNotEmpty, &pVnode->mutex);
|
for (;;) {
|
||||||
}
|
while (pVnode->freeList == NULL) {
|
||||||
|
vDebug("vgId:%d no free buffer pool, try to wait %d...", TD_VID(pVnode), ++nTry);
|
||||||
|
|
||||||
pVnode->inUse = pVnode->freeList;
|
struct timeval tv;
|
||||||
pVnode->inUse->nRef = 1;
|
struct timespec ts;
|
||||||
pVnode->freeList = pVnode->inUse->freeNext;
|
|
||||||
pVnode->inUse->freeNext = NULL;
|
taosGetTimeOfDay(&tv);
|
||||||
|
ts.tv_sec = tv.tv_sec;
|
||||||
|
ts.tv_nsec = tv.tv_usec * 1000 + WAIT_TIME_MILI_SEC * 1000000;
|
||||||
|
|
||||||
|
int32_t rc = taosThreadCondTimedWait(&pVnode->poolNotEmpty, &pVnode->mutex, &ts);
|
||||||
|
if (rc == ETIMEDOUT) { // time out, break
|
||||||
|
break;
|
||||||
|
} else if (rc != 0) { // error occurred
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(rc);
|
||||||
|
vError("vgId:%d %s failed since %s", TD_VID(pVnode), __func__, tstrerror(terrno));
|
||||||
|
taosThreadMutexUnlock(&pVnode->mutex);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pVnode->freeList) {
|
||||||
|
// allocate from free list
|
||||||
|
pVnode->inUse = pVnode->freeList;
|
||||||
|
pVnode->inUse->nRef = 1;
|
||||||
|
pVnode->freeList = pVnode->inUse->freeNext;
|
||||||
|
pVnode->inUse->freeNext = NULL;
|
||||||
|
break;
|
||||||
|
} else if (nTry == 1) {
|
||||||
|
// try to recycle a buffer pool
|
||||||
|
vInfo("vgId:%d no free buffer pool, try to recycle...", TD_VID(pVnode));
|
||||||
|
ASSERT(false); // TODO: condition of nTry == 1 may not be reasonable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
taosThreadMutexUnlock(&pVnode->mutex);
|
taosThreadMutexUnlock(&pVnode->mutex);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue