提交 6163e240 编写于 作者: dengyihao's avatar dengyihao

refor code

上级 dd45e955
...@@ -70,15 +70,10 @@ bool tscIpSetIsEqual(SRpcIpSet *s1, SRpcIpSet *s2) { ...@@ -70,15 +70,10 @@ bool tscIpSetIsEqual(SRpcIpSet *s1, SRpcIpSet *s2) {
} }
return true; return true;
} }
void tscSetMgmtIpList(SRpcIpSet *pIpSet) { void tscUpdateMgmtIpList(SRpcIpSet *pIpSet) {
// no need to update if equal // no need to update if equal
SRpcIpSet dump;
tscDumpMgmtIpSet(&dump);
if (tscIpSetIsEqual(&dump, pIpSet)) {
return;
}
taosCorBeginWrite(&tscMgmtIpSet.version); taosCorBeginWrite(&tscMgmtIpSet.version);
// or copy directly, tscMgmtIpSet.ipSet = *pIpSet
SRpcIpSet *mgmtIpSet = &tscMgmtIpSet.ipSet; SRpcIpSet *mgmtIpSet = &tscMgmtIpSet.ipSet;
tscIpSetCopy(mgmtIpSet, pIpSet); tscIpSetCopy(mgmtIpSet, pIpSet);
taosCorEndWrite(&tscMgmtIpSet.version); taosCorEndWrite(&tscMgmtIpSet.version);
...@@ -97,7 +92,12 @@ static void tscDumpIpSetFromVgroupInfo(SCMVgroupInfo *pVgroupInfo, SRpcIpSet *pI ...@@ -97,7 +92,12 @@ static void tscDumpIpSetFromVgroupInfo(SCMVgroupInfo *pVgroupInfo, SRpcIpSet *pI
} }
taosCorEndRead(&pVgroupInfo->version); taosCorEndRead(&pVgroupInfo->version);
} }
static void tscSetVgroupInfoWithIpSet(SCMVgroupInfo *pVgroupInfo, SRpcIpSet *pIpSet) {
static void tscUpdateVgroupInfo(SSqlObj *pObj, SRpcIpSet *pIpSet) {
SSqlCmd *pCmd = &pObj->cmd;
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
SCMVgroupInfo *pVgroupInfo = &pTableMetaInfo->pTableMeta->vgroupInfo;
taosCorBeginWrite(&pVgroupInfo->version); taosCorBeginWrite(&pVgroupInfo->version);
//TODO(dengyihao), dont care vgid //TODO(dengyihao), dont care vgid
pVgroupInfo->numOfIps = pIpSet->numOfIps; pVgroupInfo->numOfIps = pIpSet->numOfIps;
...@@ -107,14 +107,6 @@ static void tscSetVgroupInfoWithIpSet(SCMVgroupInfo *pVgroupInfo, SRpcIpSet *pIp ...@@ -107,14 +107,6 @@ static void tscSetVgroupInfoWithIpSet(SCMVgroupInfo *pVgroupInfo, SRpcIpSet *pIp
} }
taosCorEndWrite(&pVgroupInfo->version); taosCorEndWrite(&pVgroupInfo->version);
} }
static void tscSetVgroupInfo(SSqlObj *pObj, SRpcIpSet *pIpSet) {
if (tscIpSetIsEqual(&pObj->ipList, pIpSet)) {
return;
}
SSqlCmd *pCmd = &pObj->cmd;
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
tscSetVgroupInfoWithIpSet(&pTableMetaInfo->pTableMeta->vgroupInfo, pIpSet);
}
void tscPrintMgmtIp() { void tscPrintMgmtIp() {
SRpcIpSet dump; SRpcIpSet dump;
tscDumpMgmtIpSet(&dump); tscDumpMgmtIpSet(&dump);
...@@ -157,7 +149,7 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) { ...@@ -157,7 +149,7 @@ void tscProcessHeartBeatRsp(void *param, TAOS_RES *tres, int code) {
SCMHeartBeatRsp *pRsp = (SCMHeartBeatRsp *)pRes->pRsp; SCMHeartBeatRsp *pRsp = (SCMHeartBeatRsp *)pRes->pRsp;
SRpcIpSet * pIpList = &pRsp->ipList; SRpcIpSet * pIpList = &pRsp->ipList;
if (pIpList->numOfIps > 0) if (pIpList->numOfIps > 0)
tscSetMgmtIpList(pIpList); tscUpdateMgmtIpList(pIpList);
pSql->pTscObj->connId = htonl(pRsp->connId); pSql->pTscObj->connId = htonl(pRsp->connId);
...@@ -231,6 +223,7 @@ int tscSendMsgToServer(SSqlObj *pSql) { ...@@ -231,6 +223,7 @@ int tscSendMsgToServer(SSqlObj *pSql) {
if (pSql->cmd.command >= TSDB_SQL_MGMT) { if (pSql->cmd.command >= TSDB_SQL_MGMT) {
SRpcIpSet dump; SRpcIpSet dump;
tscDumpMgmtIpSet(&dump); tscDumpMgmtIpSet(&dump);
// no need to update pSql->ipList
tscIpSetCopy(&pSql->ipList, &dump); tscIpSetCopy(&pSql->ipList, &dump);
} }
...@@ -282,10 +275,14 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) { ...@@ -282,10 +275,14 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcIpSet *pIpSet) {
return; return;
} }
if (pCmd->command < TSDB_SQL_MGMT) { if (pIpSet) {
if (pIpSet) tscSetVgroupInfo(pSql, pIpSet); if (!tscIpSetIsEqual(&pSql->ipList, pIpSet)) {
} else { if (pCmd->command < TSDB_SQL_MGMT) {
if (pIpSet) tscSetMgmtIpList(pIpSet); tscUpdateVgroupInfo(pSql, pIpSet);
} else {
tscUpdateMgmtIpList(pIpSet);
}
}
} }
if (rpcMsg->pCont == NULL) { if (rpcMsg->pCont == NULL) {
...@@ -1994,7 +1991,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) { ...@@ -1994,7 +1991,7 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
tstrncpy(pObj->db, temp, sizeof(pObj->db)); tstrncpy(pObj->db, temp, sizeof(pObj->db));
if (pConnect->ipList.numOfIps > 0) if (pConnect->ipList.numOfIps > 0)
tscSetMgmtIpList(&pConnect->ipList); tscUpdateMgmtIpList(&pConnect->ipList);
strcpy(pObj->sversion, pConnect->serverVersion); strcpy(pObj->sversion, pConnect->serverVersion);
pObj->writeAuth = pConnect->writeAuth; pObj->writeAuth = pConnect->writeAuth;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册