fix/TD-32863-add-lock-for-allocate-primary
This commit is contained in:
parent
1031a3487d
commit
3c34ce6e96
|
@ -38,6 +38,7 @@ typedef struct SVnodeMgmt {
|
||||||
SHashObj *hash;
|
SHashObj *hash;
|
||||||
SHashObj *closedHash;
|
SHashObj *closedHash;
|
||||||
TdThreadRwlock lock;
|
TdThreadRwlock lock;
|
||||||
|
TdThreadMutex mutex;
|
||||||
SVnodesStat state;
|
SVnodesStat state;
|
||||||
STfs *pTfs;
|
STfs *pTfs;
|
||||||
TdThread thread;
|
TdThread thread;
|
||||||
|
|
|
@ -66,6 +66,12 @@ int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code = taosThreadMutexLock(&pMgmt->mutex);
|
||||||
|
if (code != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t v = 0; v < numOfVnodes; v++) {
|
for (int32_t v = 0; v < numOfVnodes; v++) {
|
||||||
SVnodeObj *pVnode = ppVnodes[v];
|
SVnodeObj *pVnode = ppVnodes[v];
|
||||||
disks[pVnode->diskPrimary] += 1;
|
disks[pVnode->diskPrimary] += 1;
|
||||||
|
@ -81,6 +87,13 @@ int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code = taosThreadMutexUnlock(&pMgmt->mutex);
|
||||||
|
if (code != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||||
if (ppVnodes == NULL || ppVnodes[i] == NULL) continue;
|
if (ppVnodes == NULL || ppVnodes[i] == NULL) continue;
|
||||||
vmReleaseVnode(pMgmt, ppVnodes[i]);
|
vmReleaseVnode(pMgmt, ppVnodes[i]);
|
||||||
|
@ -89,8 +102,13 @@ int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
||||||
taosMemoryFree(ppVnodes);
|
taosMemoryFree(ppVnodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
dError("vgId:%d, failed to alloc disk since %s", vgId, tstrerror(code));
|
||||||
|
return code;
|
||||||
|
} else {
|
||||||
dInfo("vgId:%d, alloc disk:%d of level 0. ndisk:%d, vnodes: %d", vgId, diskId, ndisk, numOfVnodes);
|
dInfo("vgId:%d, alloc disk:%d of level 0. ndisk:%d, vnodes: %d", vgId, diskId, ndisk, numOfVnodes);
|
||||||
return diskId;
|
return diskId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SVnodeObj *vmAcquireVnodeImpl(SVnodeMgmt *pMgmt, int32_t vgId, bool strict) {
|
SVnodeObj *vmAcquireVnodeImpl(SVnodeMgmt *pMgmt, int32_t vgId, bool strict) {
|
||||||
|
@ -622,6 +640,7 @@ static void vmCleanup(SVnodeMgmt *pMgmt) {
|
||||||
vmStopWorker(pMgmt);
|
vmStopWorker(pMgmt);
|
||||||
vnodeCleanup();
|
vnodeCleanup();
|
||||||
(void)taosThreadRwlockDestroy(&pMgmt->lock);
|
(void)taosThreadRwlockDestroy(&pMgmt->lock);
|
||||||
|
(void)taosThreadMutexDestroy(&pMgmt->mutex);
|
||||||
(void)taosThreadMutexDestroy(&pMgmt->fileLock);
|
(void)taosThreadMutexDestroy(&pMgmt->fileLock);
|
||||||
taosMemoryFree(pMgmt);
|
taosMemoryFree(pMgmt);
|
||||||
}
|
}
|
||||||
|
@ -714,6 +733,12 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code = taosThreadMutexInit(&pMgmt->mutex, NULL);
|
||||||
|
if (code != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
code = taosThreadMutexInit(&pMgmt->fileLock, NULL);
|
code = taosThreadMutexInit(&pMgmt->fileLock, NULL);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
|
Loading…
Reference in New Issue