提交 84d49718 编写于 作者: S Shengliang Guan

[TD-374] update code while alter database maxTables

上级 d79aff09
...@@ -29,6 +29,7 @@ void mgmtIncVgroupRef(SVgObj *pVgroup); ...@@ -29,6 +29,7 @@ void mgmtIncVgroupRef(SVgObj *pVgroup);
void mgmtDecVgroupRef(SVgObj *pVgroup); void mgmtDecVgroupRef(SVgObj *pVgroup);
void mgmtDropAllDbVgroups(SDbObj *pDropDb, bool sendMsg); void mgmtDropAllDbVgroups(SDbObj *pDropDb, bool sendMsg);
void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode); void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode);
void mgmtUpdateAllDbVgroups(SDbObj *pAlterDb);
void * mgmtGetNextVgroup(void *pIter, SVgObj **pVgroup); void * mgmtGetNextVgroup(void *pIter, SVgObj **pVgroup);
void mgmtUpdateVgroup(SVgObj *pVgroup); void mgmtUpdateVgroup(SVgObj *pVgroup);
......
...@@ -96,6 +96,7 @@ static int32_t mgmtDbActionUpdate(SSdbOper *pOper) { ...@@ -96,6 +96,7 @@ static int32_t mgmtDbActionUpdate(SSdbOper *pOper) {
memcpy(pSaved, pDb, pOper->rowSize); memcpy(pSaved, pDb, pOper->rowSize);
free(pDb); free(pDb);
} }
mgmtUpdateAllDbVgroups(pSaved);
mgmtDecDbRef(pSaved); mgmtDecDbRef(pSaved);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
...@@ -121,6 +121,19 @@ static int32_t mgmtVgroupActionDelete(SSdbOper *pOper) { ...@@ -121,6 +121,19 @@ static int32_t mgmtVgroupActionDelete(SSdbOper *pOper) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static void mgmtVgroupUpdateIdPool(SVgObj *pVgroup) {
int32_t oldTables = taosIdPoolMaxSize(pVgroup->idPool);
SDbObj *pDb = pVgroup->pDb;
if (pDb != NULL) {
if (pDb->cfg.maxTables != oldTables) {
mPrint("vgId:%d tables change from %d to %d", pVgroup->vgId, oldTables, pDb->cfg.maxTables);
taosUpdateIdPool(pVgroup->idPool, pDb->cfg.maxTables);
int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables;
pVgroup->tableList = (SChildTableObj **)realloc(pVgroup->tableList, size);
}
}
}
static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) { static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) {
SVgObj *pNew = pOper->pObj; SVgObj *pNew = pOper->pObj;
SVgObj *pVgroup = mgmtGetVgroup(pNew->vgId); SVgObj *pVgroup = mgmtGetVgroup(pNew->vgId);
...@@ -146,20 +159,11 @@ static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) { ...@@ -146,20 +159,11 @@ static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) {
} }
} }
int32_t oldTables = taosIdPoolMaxSize(pVgroup->idPool); mgmtVgroupUpdateIdPool(pVgroup);
SDbObj *pDb = pVgroup->pDb;
if (pDb != NULL) {
if (pDb->cfg.maxTables != oldTables) {
mPrint("vgId:%d tables change from %d to %d", pVgroup->vgId, oldTables, pDb->cfg.maxTables);
taosUpdateIdPool(pVgroup->idPool, pDb->cfg.maxTables);
int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables;
pVgroup->tableList = (SChildTableObj **)realloc(pVgroup->tableList, size);
}
}
mgmtDecVgroupRef(pVgroup); mgmtDecVgroupRef(pVgroup);
mTrace("vgId:%d, is updated, numOfVnode:%d tables:%d", pVgroup->vgId, pVgroup->numOfVnodes, pDb == NULL ? 0 : pDb->cfg.maxTables); mTrace("vgId:%d, is updated, numOfVnode:%d", pVgroup->vgId, pVgroup->numOfVnodes);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -762,6 +766,28 @@ void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) { ...@@ -762,6 +766,28 @@ void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) {
sdbFreeIter(pIter); sdbFreeIter(pIter);
} }
void mgmtUpdateAllDbVgroups(SDbObj *pAlterDb) {
void * pIter = NULL;
SVgObj *pVgroup = NULL;
mPrint("db:%s, all vgroups will be update in sdb", pAlterDb->name);
while (1) {
pIter = mgmtGetNextVgroup(pIter, &pVgroup);
if (pVgroup == NULL) break;
if (pVgroup->pDb == pAlterDb) {
mgmtVgroupUpdateIdPool(pVgroup);
}
mgmtDecVgroupRef(pVgroup);
}
sdbFreeIter(pIter);
mPrint("db:%s, all vgroups is updated in sdb", pAlterDb->name);
}
void mgmtDropAllDbVgroups(SDbObj *pDropDb, bool sendMsg) { void mgmtDropAllDbVgroups(SDbObj *pDropDb, bool sendMsg) {
void * pIter = NULL; void * pIter = NULL;
int32_t numOfVgroups = 0; int32_t numOfVgroups = 0;
......
...@@ -49,7 +49,7 @@ endi ...@@ -49,7 +49,7 @@ endi
print ============================ step3 print ============================ step3
sql create database db maxTables 20 sql alter database db maxTables 20
sleep 1000 sleep 1000
sql create table db.t10 using db.st tags(0) sql create table db.t10 using db.st tags(0)
...@@ -87,7 +87,7 @@ endi ...@@ -87,7 +87,7 @@ endi
print ============================ step5 print ============================ step5
sql create database db maxTables 30 sql alter database db maxTables 30
sleep 1000 sleep 1000
sql create table db.t20 using db.st tags(0) sql create table db.t20 using db.st tags(0)
...@@ -185,7 +185,7 @@ endi ...@@ -185,7 +185,7 @@ endi
print ============================ step9 print ============================ step9
sql create database db maxTables 40 sql alter database db maxTables 40
sleep 1000 sleep 1000
sql create table db.t30 using db.st tags(0) sql create table db.t30 using db.st tags(0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册