[TD-468] deadlock while create tb
This commit is contained in:
parent
0e6c01c03b
commit
4929a943df
|
@ -388,7 +388,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, void *pMs
|
||||||
|
|
||||||
code = sdbInsertRow(&oper);
|
code = sdbInsertRow(&oper);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
tfree(pDb);
|
mnodeDestroyDb(pDb);
|
||||||
mLInfo("db:%s, failed to create, reason:%s", pDb->name, tstrerror(code));
|
mLInfo("db:%s, failed to create, reason:%s", pDb->name, tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
} else {
|
} else {
|
||||||
|
@ -434,7 +434,7 @@ void mnodeAddVgroupIntoDb(SVgObj *pVgroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pDb->vgList[vgPos] = pVgroup;
|
pDb->vgList[vgPos] = pVgroup;
|
||||||
pthread_mutex_lock(&pDb->mutex);
|
pthread_mutex_unlock(&pDb->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeRemoveVgroupFromDb(SVgObj *pVgroup) {
|
void mnodeRemoveVgroupFromDb(SVgObj *pVgroup) {
|
||||||
|
@ -451,7 +451,7 @@ void mnodeRemoveVgroupFromDb(SVgObj *pVgroup) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&pDb->mutex);
|
pthread_mutex_unlock(&pDb->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mnodeCleanupDbs() {
|
void mnodeCleanupDbs() {
|
||||||
|
|
|
@ -49,14 +49,17 @@ static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg);
|
||||||
static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) ;
|
static int32_t mnodeProcessVnodeCfgMsg(SMnodeMsg *pMsg) ;
|
||||||
static void mnodeSendDropVgroupMsg(SVgObj *pVgroup, void *ahandle);
|
static void mnodeSendDropVgroupMsg(SVgObj *pVgroup, void *ahandle);
|
||||||
|
|
||||||
static int32_t mnodeVgroupActionDestroy(SSdbOper *pOper) {
|
static void mnodeDestroyVgroup(SVgObj *pVgroup) {
|
||||||
SVgObj *pVgroup = pOper->pObj;
|
|
||||||
if (pVgroup->idPool) {
|
if (pVgroup->idPool) {
|
||||||
taosIdPoolCleanUp(pVgroup->idPool);
|
taosIdPoolCleanUp(pVgroup->idPool);
|
||||||
pVgroup->idPool = NULL;
|
pVgroup->idPool = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
tfree(pOper->pObj);
|
tfree(pVgroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mnodeVgroupActionDestroy(SSdbOper *pOper) {
|
||||||
|
mnodeDestroyVgroup(pOper->pObj);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,39 +302,45 @@ static int32_t mnodeAllocVgroupIdPool(SVgObj *pInputVgroup) {
|
||||||
SDbObj *pDb = pInputVgroup->pDb;
|
SDbObj *pDb = pInputVgroup->pDb;
|
||||||
if (pDb == NULL) return TSDB_CODE_MND_APP_ERROR;
|
if (pDb == NULL) return TSDB_CODE_MND_APP_ERROR;
|
||||||
|
|
||||||
int32_t currIdPoolSize = TSDB_MIN_TABLES;
|
int32_t minIdPoolSize = TSDB_MAX_TABLES;
|
||||||
|
int32_t maxIdPoolSize = TSDB_MIN_TABLES;
|
||||||
for (int32_t v = 0; v < pDb->numOfVgroups; ++v) {
|
for (int32_t v = 0; v < pDb->numOfVgroups; ++v) {
|
||||||
SVgObj *pVgroup = pDb->vgList[v];
|
SVgObj *pVgroup = pDb->vgList[v];
|
||||||
if (pVgroup == NULL) continue;
|
if (pVgroup == NULL) continue;
|
||||||
|
|
||||||
int32_t idPoolSize = taosIdPoolMaxSize(pVgroup->idPool);
|
int32_t idPoolSize = taosIdPoolMaxSize(pVgroup->idPool);
|
||||||
currIdPoolSize = MAX(currIdPoolSize, idPoolSize);
|
minIdPoolSize = MIN(minIdPoolSize, idPoolSize);
|
||||||
|
maxIdPoolSize = MAX(maxIdPoolSize, idPoolSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// new vgroup
|
// new vgroup
|
||||||
if (pInputVgroup->idPool == NULL) {
|
if (pInputVgroup->idPool == NULL) {
|
||||||
pInputVgroup->idPool = taosInitIdPool(currIdPoolSize);
|
pInputVgroup->idPool = taosInitIdPool(maxIdPoolSize);
|
||||||
if (pInputVgroup->idPool == NULL) {
|
if (pInputVgroup->idPool == NULL) {
|
||||||
mError("vgId:%d, failed to init idPool for vgroup, size:%d", pInputVgroup->vgId, currIdPoolSize);
|
mError("vgId:%d, failed to init idPool for vgroup, size:%d", pInputVgroup->vgId, maxIdPoolSize);
|
||||||
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
return TSDB_CODE_MND_OUT_OF_MEMORY;
|
||||||
} else {
|
} else {
|
||||||
mDebug("vgId:%d, init idPool for vgroup, size:%d", pInputVgroup->vgId, currIdPoolSize);
|
mDebug("vgId:%d, init idPool for vgroup, size:%d", pInputVgroup->vgId, maxIdPoolSize);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// realloc all vgroups in db
|
// realloc all vgroups in db
|
||||||
int32_t newIdPoolSize;
|
int32_t newIdPoolSize;
|
||||||
if (currIdPoolSize < TSDB_TABLES_STEP) {
|
if (minIdPoolSize < TSDB_TABLES_STEP) {
|
||||||
newIdPoolSize = currIdPoolSize * 2;
|
newIdPoolSize = minIdPoolSize * 2;
|
||||||
} else {
|
} else {
|
||||||
newIdPoolSize = ((currIdPoolSize / TSDB_TABLES_STEP) + 1) * TSDB_TABLES_STEP;
|
newIdPoolSize = ((minIdPoolSize / TSDB_TABLES_STEP) + 1) * TSDB_TABLES_STEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newIdPoolSize > tsMaxTablePerVnode) {
|
if (newIdPoolSize > tsMaxTablePerVnode) {
|
||||||
mDebug("db:%s, currIdPoolSize:%d newIdPoolSize%d larger than %d", pDb->name, currIdPoolSize, newIdPoolSize,
|
if (minIdPoolSize >= tsMaxTablePerVnode) {
|
||||||
tsMaxTablePerVnode);
|
mError("db:%s, minIdPoolSize:%d newIdPoolSize:%d larger than maxTablesPerVnode:%d", pDb->name, minIdPoolSize, newIdPoolSize,
|
||||||
return TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
tsMaxTablePerVnode);
|
||||||
|
return TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||||
|
} else {
|
||||||
|
newIdPoolSize = tsMaxTablePerVnode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t v = 0; v < pDb->numOfVgroups; ++v) {
|
for (int32_t v = 0; v < pDb->numOfVgroups; ++v) {
|
||||||
|
@ -339,6 +348,7 @@ static int32_t mnodeAllocVgroupIdPool(SVgObj *pInputVgroup) {
|
||||||
if (pVgroup == NULL) continue;
|
if (pVgroup == NULL) continue;
|
||||||
|
|
||||||
int32_t oldIdPoolSize = taosIdPoolMaxSize(pVgroup->idPool);
|
int32_t oldIdPoolSize = taosIdPoolMaxSize(pVgroup->idPool);
|
||||||
|
if (newIdPoolSize == oldIdPoolSize) continue;
|
||||||
|
|
||||||
if (taosUpdateIdPool(pVgroup->idPool, newIdPoolSize) < 0) {
|
if (taosUpdateIdPool(pVgroup->idPool, newIdPoolSize) < 0) {
|
||||||
mError("vgId:%d, failed to update idPoolSize from %d to %d", pVgroup->vgId, oldIdPoolSize, newIdPoolSize);
|
mError("vgId:%d, failed to update idPoolSize from %d to %d", pVgroup->vgId, oldIdPoolSize, newIdPoolSize);
|
||||||
|
@ -381,7 +391,7 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi
|
||||||
int maxVgroupsPerDb = tsMaxVgroupsPerDb;
|
int maxVgroupsPerDb = tsMaxVgroupsPerDb;
|
||||||
if (maxVgroupsPerDb <= 0) {
|
if (maxVgroupsPerDb <= 0) {
|
||||||
maxVgroupsPerDb = mnodeGetOnlinDnodesCpuCoreNum();
|
maxVgroupsPerDb = mnodeGetOnlinDnodesCpuCoreNum();
|
||||||
maxVgroupsPerDb = MIN(maxVgroupsPerDb, 2);
|
maxVgroupsPerDb = MAX(maxVgroupsPerDb, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pDb->numOfVgroups < maxVgroupsPerDb) {
|
if (pDb->numOfVgroups < maxVgroupsPerDb) {
|
||||||
|
@ -467,7 +477,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) {
|
||||||
int32_t code = sdbInsertRow(&oper);
|
int32_t code = sdbInsertRow(&oper);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
pMsg->pVgroup = NULL;
|
pMsg->pVgroup = NULL;
|
||||||
tfree(pVgroup);
|
mnodeDestroyVgroup(pVgroup);
|
||||||
} else {
|
} else {
|
||||||
code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||||
}
|
}
|
||||||
|
@ -515,6 +525,12 @@ int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
pShow->bytes[cols] = 4;
|
||||||
|
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||||
|
strcpy(pSchema[cols].name, "poolSize");
|
||||||
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
|
cols++;
|
||||||
|
|
||||||
pShow->bytes[cols] = 4;
|
pShow->bytes[cols] = 4;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||||
strcpy(pSchema[cols].name, "maxTables");
|
strcpy(pSchema[cols].name, "maxTables");
|
||||||
|
@ -607,7 +623,11 @@ int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pC
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
*(int32_t *) pWrite = tsMaxTablePerVnode;
|
*(int32_t *)pWrite = taosIdPoolMaxSize(pVgroup->idPool);
|
||||||
|
cols++;
|
||||||
|
|
||||||
|
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||||
|
*(int32_t *)pWrite = tsMaxTablePerVnode;
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pShow->maxReplica; ++i) {
|
for (int32_t i = 0; i < pShow->maxReplica; ++i) {
|
||||||
|
@ -679,6 +699,8 @@ SMDCreateVnodeMsg *mnodeBuildCreateVnodeMsg(SVgObj *pVgroup) {
|
||||||
|
|
||||||
strcpy(pVnode->db, pVgroup->dbName);
|
strcpy(pVnode->db, pVgroup->dbName);
|
||||||
int32_t maxTables = taosIdPoolMaxSize(pVgroup->idPool);
|
int32_t maxTables = taosIdPoolMaxSize(pVgroup->idPool);
|
||||||
|
//TODO: dynamic alloc tables in tsdb
|
||||||
|
maxTables = 10000;
|
||||||
|
|
||||||
SMDVnodeCfg *pCfg = &pVnode->cfg;
|
SMDVnodeCfg *pCfg = &pVnode->cfg;
|
||||||
pCfg->vgId = htonl(pVgroup->vgId);
|
pCfg->vgId = htonl(pVgroup->vgId);
|
||||||
|
|
|
@ -123,7 +123,7 @@ void taosIdPoolMarkStatus(void *handle, int id) {
|
||||||
int taosUpdateIdPool(id_pool_t *handle, int maxId) {
|
int taosUpdateIdPool(id_pool_t *handle, int maxId) {
|
||||||
id_pool_t *pIdPool = (id_pool_t*)handle;
|
id_pool_t *pIdPool = (id_pool_t*)handle;
|
||||||
if (maxId <= pIdPool->maxId) {
|
if (maxId <= pIdPool->maxId) {
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool *idList = calloc(maxId, sizeof(bool));
|
bool *idList = calloc(maxId, sizeof(bool));
|
||||||
|
|
Loading…
Reference in New Issue