提交 1d1a027d 编写于 作者: S Steven Li

Merge branch 'develop' into feature/python-test-no-sudo

...@@ -32,15 +32,15 @@ matrix: ...@@ -32,15 +32,15 @@ matrix:
- cd debug - cd debug
script: script:
- cmake .. - cmake .. > /dev/null
- make - make > /dev/null
after_success: after_success:
- |- - |-
case $TRAVIS_OS_NAME in case $TRAVIS_OS_NAME in
linux) linux)
cd ${TRAVIS_BUILD_DIR}/debug cd ${TRAVIS_BUILD_DIR}/debug
make install || travis_terminate $? make install > /dev/null || travis_terminate $?
pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/ pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/
pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/ pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/
...@@ -98,11 +98,11 @@ matrix: ...@@ -98,11 +98,11 @@ matrix:
# Commands to prepare for build_command # Commands to prepare for build_command
# ** likely specific to your build ** # ** likely specific to your build **
build_command_prepend: cmake . build_command_prepend: cmake . > /dev/null
# The command that will be added as an argument to "cov-build" to compile your project for analysis, # The command that will be added as an argument to "cov-build" to compile your project for analysis,
# ** likely specific to your build ** # ** likely specific to your build **
build_command: make build_command: make > /dev/null
# Pattern to match selecting branches that will run analysis. We recommend leaving this set to 'coverity_scan'. # Pattern to match selecting branches that will run analysis. We recommend leaving this set to 'coverity_scan'.
# Take care in resource usage, and consider the build frequency allowances per # Take care in resource usage, and consider the build frequency allowances per
...@@ -135,15 +135,15 @@ matrix: ...@@ -135,15 +135,15 @@ matrix:
- cd debug - cd debug
script: script:
- cmake -DCOVER=true .. - cmake -DCOVER=true .. > /dev/null
- make - make > /dev/null
after_success: after_success:
- |- - |-
case $TRAVIS_OS_NAME in case $TRAVIS_OS_NAME in
linux) linux)
cd ${TRAVIS_BUILD_DIR}/debug cd ${TRAVIS_BUILD_DIR}/debug
make install || travis_terminate $? make install > /dev/null || travis_terminate $?
pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/ pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/
pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/ pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/
...@@ -208,8 +208,8 @@ matrix: ...@@ -208,8 +208,8 @@ matrix:
- cd debug - cd debug
script: script:
- cmake .. - cmake .. > /dev/null
- make - make > /dev/null
# - os: osx # - os: osx
# language: c # language: c
...@@ -225,5 +225,5 @@ matrix: ...@@ -225,5 +225,5 @@ matrix:
# - cd ${TRAVIS_BUILD_DIR} # - cd ${TRAVIS_BUILD_DIR}
# - mkdir debug # - mkdir debug
# - cd debug # - cd debug
# - cmake .. # - cmake .. > /dev/null
# - make # - make > /dev/null
...@@ -304,10 +304,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -304,10 +304,11 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
SSQLToken* pIpAddr = &pInfo->pDCLInfo->a[0]; SSQLToken* pIpAddr = &pInfo->pDCLInfo->a[0];
if (!validateIpAddress(pIpAddr->z, pIpAddr->n)) { // if (!validateIpAddress(pIpAddr->z, pIpAddr->n)) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg); // return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
} // }
pIpAddr->n = strdequote(pIpAddr->z);
break; break;
} }
...@@ -385,7 +386,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -385,7 +386,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
pMsg += sizeof(SMgmtHead); pMsg += sizeof(SMgmtHead);
SCMCfgDnodeMsg* pCfg = (SCMCfgDnodeMsg*)pMsg; SCMCfgDnodeMsg* pCfg = (SCMCfgDnodeMsg*)pMsg;
strncpy(pCfg->ip, pDCL->a[0].z, pDCL->a[0].n); strncpy(pCfg->ep, pDCL->a[0].z, pDCL->a[0].n);
strncpy(pCfg->config, pDCL->a[1].z, pDCL->a[1].n); strncpy(pCfg->config, pDCL->a[1].z, pDCL->a[1].n);
......
...@@ -49,11 +49,11 @@ static void tscSetDnodeIpList(SSqlObj* pSql, STableMeta* pTableMeta) { ...@@ -49,11 +49,11 @@ static void tscSetDnodeIpList(SSqlObj* pSql, STableMeta* pTableMeta) {
SRpcIpSet* pIpList = &pSql->ipList; SRpcIpSet* pIpList = &pSql->ipList;
pIpList->numOfIps = pTableMeta->vgroupInfo.numOfIps; pIpList->numOfIps = pTableMeta->vgroupInfo.numOfIps;
pIpList->port = tsDnodeShellPort;
pIpList->inUse = 0; pIpList->inUse = 0;
for(int32_t i = 0; i < pTableMeta->vgroupInfo.numOfIps; ++i) { for(int32_t i = 0; i < pTableMeta->vgroupInfo.numOfIps; ++i) {
pIpList->ip[i] = pTableMeta->vgroupInfo.ipAddr[i].ip; strcpy(pIpList->fqdn[i], pTableMeta->vgroupInfo.ipAddr[i].fqdn);
pIpList->port[i] = pTableMeta->vgroupInfo.ipAddr[i].port;
} }
} }
...@@ -62,7 +62,7 @@ void tscPrintMgmtIp() { ...@@ -62,7 +62,7 @@ void tscPrintMgmtIp() {
tscError("invalid mgmt IP list:%d", tscMgmtIpSet.numOfIps); tscError("invalid mgmt IP list:%d", tscMgmtIpSet.numOfIps);
} else { } else {
for (int i = 0; i < tscMgmtIpSet.numOfIps; ++i) { for (int i = 0; i < tscMgmtIpSet.numOfIps; ++i) {
tscTrace("mgmt index:%d ip:%d", i, tscMgmtIpSet.ip[i]); tscTrace("mgmt index:%d %s:%d", i, tscMgmtIpSet.fqdn[i], tscMgmtIpSet.port[i]);
} }
} }
} }
...@@ -70,9 +70,8 @@ void tscPrintMgmtIp() { ...@@ -70,9 +70,8 @@ void tscPrintMgmtIp() {
void tscSetMgmtIpListFromCluster(SRpcIpSet *pIpList) { void tscSetMgmtIpListFromCluster(SRpcIpSet *pIpList) {
tscMgmtIpSet.numOfIps = pIpList->numOfIps; tscMgmtIpSet.numOfIps = pIpList->numOfIps;
tscMgmtIpSet.inUse = pIpList->inUse; tscMgmtIpSet.inUse = pIpList->inUse;
tscMgmtIpSet.port = htons(pIpList->port);
for (int32_t i = 0; i < tscMgmtIpSet.numOfIps; ++i) { for (int32_t i = 0; i < tscMgmtIpSet.numOfIps; ++i) {
tscMgmtIpSet.ip[i] = htonl(pIpList->ip[i]); tscMgmtIpSet.port[i] = htons(pIpList->port[i]);
} }
} }
...@@ -80,8 +79,7 @@ void tscSetMgmtIpListFromEdge() { ...@@ -80,8 +79,7 @@ void tscSetMgmtIpListFromEdge() {
if (tscMgmtIpSet.numOfIps != 1) { if (tscMgmtIpSet.numOfIps != 1) {
tscMgmtIpSet.numOfIps = 1; tscMgmtIpSet.numOfIps = 1;
tscMgmtIpSet.inUse = 0; tscMgmtIpSet.inUse = 0;
tscMgmtIpSet.port = tsMnodeShellPort; taosGetFqdnPortFromEp(tsFirst, tscMgmtIpSet.fqdn[0], &tscMgmtIpSet.port[0]);
tscMgmtIpSet.ip[0] = inet_addr(tsMasterIp);
tscTrace("edge mgmt IP list:"); tscTrace("edge mgmt IP list:");
tscPrintMgmtIp(); tscPrintMgmtIp();
} }
...@@ -213,9 +211,6 @@ int tscSendMsgToServer(SSqlObj *pSql) { ...@@ -213,9 +211,6 @@ int tscSendMsgToServer(SSqlObj *pSql) {
rpcSendRequest(pVnodeConn, &pSql->ipList, &rpcMsg); rpcSendRequest(pVnodeConn, &pSql->ipList, &rpcMsg);
} else { } else {
pSql->ipList = tscMgmtIpSet; pSql->ipList = tscMgmtIpSet;
pSql->ipList.port = tsMnodeShellPort;
tscTrace("%p msg:%s is sent to server %d", pSql, taosMsg[pSql->cmd.msgType], pSql->ipList.port);
memcpy(pMsg, pSql->cmd.payload, pSql->cmd.payloadLen); memcpy(pMsg, pSql->cmd.payload, pSql->cmd.payloadLen);
SRpcMsg rpcMsg = { SRpcMsg rpcMsg = {
.msgType = pSql->cmd.msgType, .msgType = pSql->cmd.msgType,
...@@ -224,6 +219,7 @@ int tscSendMsgToServer(SSqlObj *pSql) { ...@@ -224,6 +219,7 @@ int tscSendMsgToServer(SSqlObj *pSql) {
.handle = pSql, .handle = pSql,
.code = 0 .code = 0
}; };
tscTrace("%p msg:%s is sent to server", pSql, taosMsg[pSql->cmd.msgType]);
rpcSendRequest(pObj->pMgmtConn, &pSql->ipList, &rpcMsg); rpcSendRequest(pObj->pMgmtConn, &pSql->ipList, &rpcMsg);
} }
...@@ -295,11 +291,6 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) { ...@@ -295,11 +291,6 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
} }
} }
if (pRes->code == TSDB_CODE_SUCCESS) {
tscTrace("%p reset retry counter to be 0 due to success rsp, old:%d", pSql, pSql->retry);
pSql->retry = 0;
}
pRes->rspLen = 0; pRes->rspLen = 0;
if (pRes->code != TSDB_CODE_QUERY_CANCELLED) { if (pRes->code != TSDB_CODE_QUERY_CANCELLED) {
...@@ -308,6 +299,11 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) { ...@@ -308,6 +299,11 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
tscTrace("%p query is cancelled, code:%d", pSql, tstrerror(pRes->code)); tscTrace("%p query is cancelled, code:%d", pSql, tstrerror(pRes->code));
} }
if (pRes->code == TSDB_CODE_SUCCESS) {
tscTrace("%p reset retry counter to be 0 due to success rsp, old:%d", pSql, pSql->retry);
pSql->retry = 0;
}
if (pRes->code != TSDB_CODE_QUERY_CANCELLED) { if (pRes->code != TSDB_CODE_QUERY_CANCELLED) {
assert(rpcMsg->msgType == pCmd->msgType + 1); assert(rpcMsg->msgType == pCmd->msgType + 1);
pRes->code = rpcMsg->code; pRes->code = rpcMsg->code;
...@@ -569,7 +565,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -569,7 +565,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pSql->cmd.msgType = TSDB_MSG_TYPE_SUBMIT; pSql->cmd.msgType = TSDB_MSG_TYPE_SUBMIT;
tscSetDnodeIpList(pSql, pTableMeta); tscSetDnodeIpList(pSql, pTableMeta);
tscTrace("%p build submit msg, vgId:%d numOfVgroup:%d", pSql, vgId, htonl(pMsgDesc->numOfVnodes)); tscTrace("%p build submit msg, vgId:%d numOfVgroup:%d numberOfIP:%d", pSql, vgId, htonl(pMsgDesc->numOfVnodes), pSql->ipList.numOfIps);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -664,11 +660,11 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -664,11 +660,11 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCMVgroupInfo* pVgroupInfo = &pTableMetaInfo->vgroupList->vgroups[index]; SCMVgroupInfo* pVgroupInfo = &pTableMetaInfo->vgroupList->vgroups[index];
pSql->ipList.numOfIps = pVgroupInfo->numOfIps; // todo fix me pSql->ipList.numOfIps = pVgroupInfo->numOfIps; // todo fix me
pSql->ipList.port = tsDnodeShellPort;
pSql->ipList.inUse = 0; pSql->ipList.inUse = 0;
for(int32_t i = 0; i < pVgroupInfo->numOfIps; ++i) { for(int32_t i = 0; i < pVgroupInfo->numOfIps; ++i) {
pSql->ipList.ip[i] = pVgroupInfo->ipAddr[i].ip; strcpy(pSql->ipList.fqdn[i], pVgroupInfo->ipAddr[i].fqdn);
pSql->ipList.port[i] = pVgroupInfo->ipAddr[i].port;
} }
tscTrace("%p query on super table, numOfVgroup:%d, vgroupIndex:%d", pSql, pTableMetaInfo->vgroupList->numOfVgroups, index); tscTrace("%p query on super table, numOfVgroup:%d, vgroupIndex:%d", pSql, pTableMetaInfo->vgroupList->numOfVgroups, index);
...@@ -935,7 +931,8 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -935,7 +931,8 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
} }
SCMCreateDnodeMsg *pCreate = (SCMCreateDnodeMsg *)pCmd->payload; SCMCreateDnodeMsg *pCreate = (SCMCreateDnodeMsg *)pCmd->payload;
strncpy(pCreate->ip, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); strncpy(pCreate->ep, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n);
pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_DNODE; pCmd->msgType = TSDB_MSG_TYPE_CM_CREATE_DNODE;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -1078,7 +1075,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1078,7 +1075,7 @@ int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCMDropDnodeMsg *pDrop = (SCMDropDnodeMsg *)pCmd->payload; SCMDropDnodeMsg *pDrop = (SCMDropDnodeMsg *)pCmd->payload;
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
strcpy(pDrop->ip, pTableMetaInfo->name); strcpy(pDrop->ep, pTableMetaInfo->name);
pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_DNODE; pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_DNODE;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -1857,10 +1854,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { ...@@ -1857,10 +1854,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
} }
for (int i = 0; i < pMetaMsg->vgroup.numOfIps; ++i) { for (int i = 0; i < pMetaMsg->vgroup.numOfIps; ++i) {
pMetaMsg->vgroup.ipAddr[i].ip = htonl(pMetaMsg->vgroup.ipAddr[i].ip);
pMetaMsg->vgroup.ipAddr[i].port = htons(pMetaMsg->vgroup.ipAddr[i].port); pMetaMsg->vgroup.ipAddr[i].port = htons(pMetaMsg->vgroup.ipAddr[i].port);
assert(pMetaMsg->vgroup.ipAddr[i].ip != 0);
} }
SSchema* pSchema = pMetaMsg->schema; SSchema* pSchema = pMetaMsg->schema;
...@@ -2144,7 +2138,6 @@ _error_clean: ...@@ -2144,7 +2138,6 @@ _error_clean:
assert(pVgroups->numOfIps >= 1); assert(pVgroups->numOfIps >= 1);
for(int32_t j = 0; j < pVgroups->numOfIps; ++j) { for(int32_t j = 0; j < pVgroups->numOfIps; ++j) {
pVgroups->ipAddr[j].ip = htonl(pVgroups->ipAddr[j].ip);
pVgroups->ipAddr[j].port = htons(pVgroups->ipAddr[j].port); pVgroups->ipAddr[j].port = htons(pVgroups->ipAddr[j].port);
} }
} }
......
...@@ -72,25 +72,25 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con ...@@ -72,25 +72,25 @@ STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, con
return NULL; return NULL;
} }
tscMgmtIpSet.numOfIps = 0;
if (ip && ip[0]) { if (ip && ip[0]) {
tscMgmtIpSet.inUse = 0; tscMgmtIpSet.inUse = 0;
tscMgmtIpSet.port = tsMnodeShellPort;
tscMgmtIpSet.numOfIps = 1; tscMgmtIpSet.numOfIps = 1;
tscMgmtIpSet.ip[0] = inet_addr(ip); strcpy(tscMgmtIpSet.fqdn[0], ip);
tscMgmtIpSet.port[0] = port? port: tsMnodeShellPort;
if (tsMasterIp[0] && strcmp(ip, tsMasterIp) != 0) { } else {
tscMgmtIpSet.numOfIps = 2; if (tsFirst[0] != 0) {
tscMgmtIpSet.ip[1] = inet_addr(tsMasterIp); taosGetFqdnPortFromEp(tsFirst, tscMgmtIpSet.fqdn[tscMgmtIpSet.numOfIps], &tscMgmtIpSet.port[tscMgmtIpSet.numOfIps]);
tscMgmtIpSet.numOfIps++;
} }
if (tsSecondIp[0] && strcmp(tsSecondIp, tsMasterIp) != 0) { if (tsSecond[0] != 0) {
tscMgmtIpSet.numOfIps = 3; taosGetFqdnPortFromEp(tsSecond, tscMgmtIpSet.fqdn[tscMgmtIpSet.numOfIps], &tscMgmtIpSet.port[tscMgmtIpSet.numOfIps]);
tscMgmtIpSet.ip[2] = inet_addr(tsSecondIp); tscMgmtIpSet.numOfIps++;
} }
} }
tscMgmtIpSet.port = port ? port : tsMnodeShellPort;
STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj)); STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj));
if (NULL == pObj) { if (NULL == pObj) {
terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; terrno = TSDB_CODE_CLI_OUT_OF_MEMORY;
...@@ -167,10 +167,6 @@ static void syncConnCallback(void *param, TAOS_RES *tres, int code) { ...@@ -167,10 +167,6 @@ static void syncConnCallback(void *param, TAOS_RES *tres, int code) {
} }
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) { TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
if (ip == NULL || (ip != NULL && (strcmp("127.0.0.1", ip) == 0 || strcasecmp("localhost", ip) == 0))) {
ip = tsMasterIp;
}
tscTrace("try to create a connection to %s", ip); tscTrace("try to create a connection to %s", ip);
STscObj *pObj = taosConnectImpl(ip, user, pass, db, port, NULL, NULL, NULL); STscObj *pObj = taosConnectImpl(ip, user, pass, db, port, NULL, NULL, NULL);
...@@ -939,7 +935,7 @@ char *taos_errstr(TAOS *taos) { ...@@ -939,7 +935,7 @@ char *taos_errstr(TAOS *taos) {
void taos_config(int debug, char *log_path) { void taos_config(int debug, char *log_path) {
uDebugFlag = debug; uDebugFlag = debug;
strcpy(logDir, log_path); strcpy(tsLogDir, log_path);
} }
char *taos_get_server_info(TAOS *taos) { char *taos_get_server_info(TAOS *taos) {
......
...@@ -220,7 +220,7 @@ int tscUpdateSubscription(STscObj* pObj, SSub* pSub) { ...@@ -220,7 +220,7 @@ int tscUpdateSubscription(STscObj* pObj, SSub* pSub) {
static int tscLoadSubscriptionProgress(SSub* pSub) { static int tscLoadSubscriptionProgress(SSub* pSub) {
char buf[TSDB_MAX_SQL_LEN]; char buf[TSDB_MAX_SQL_LEN];
sprintf(buf, "%s/subscribe/%s", dataDir, pSub->topic); sprintf(buf, "%s/subscribe/%s", tsDataDir, pSub->topic);
FILE* fp = fopen(buf, "r"); FILE* fp = fopen(buf, "r");
if (fp == NULL) { if (fp == NULL) {
...@@ -281,12 +281,12 @@ void tscSaveSubscriptionProgress(void* sub) { ...@@ -281,12 +281,12 @@ void tscSaveSubscriptionProgress(void* sub) {
SSub* pSub = (SSub*)sub; SSub* pSub = (SSub*)sub;
char path[256]; char path[256];
sprintf(path, "%s/subscribe", dataDir); sprintf(path, "%s/subscribe", tsDataDir);
if (access(path, 0) != 0) { if (access(path, 0) != 0) {
mkdir(path, 0777); mkdir(path, 0777);
} }
sprintf(path, "%s/subscribe/%s", dataDir, pSub->topic); sprintf(path, "%s/subscribe/%s", tsDataDir, pSub->topic);
FILE* fp = fopen(path, "w+"); FILE* fp = fopen(path, "w+");
if (fp == NULL) { if (fp == NULL) {
tscError("failed to create progress file for subscription: %s", pSub->topic); tscError("failed to create progress file for subscription: %s", pSub->topic);
...@@ -416,7 +416,7 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) { ...@@ -416,7 +416,7 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) {
tscSaveSubscriptionProgress(pSub); tscSaveSubscriptionProgress(pSub);
} else { } else {
char path[256]; char path[256];
sprintf(path, "%s/subscribe/%s", dataDir, pSub->topic); sprintf(path, "%s/subscribe/%s", tsDataDir, pSub->topic);
remove(path); remove(path);
} }
......
...@@ -1245,7 +1245,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p ...@@ -1245,7 +1245,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
// data in from current vnode is stored in cache and disk // data in from current vnode is stored in cache and disk
uint32_t numOfRowsFromSubquery = trsupport->pExtMemBuffer[idx]->numOfTotalElems + trsupport->localBuffer->numOfElems; uint32_t numOfRowsFromSubquery = trsupport->pExtMemBuffer[idx]->numOfTotalElems + trsupport->localBuffer->numOfElems;
tscTrace("%p sub:%p all data retrieved from ip:%u,vgId:%d, numOfRows:%d, orderOfSub:%d", pPObj, pSql, tscTrace("%p sub:%p all data retrieved from ip:%u,vgId:%d, numOfRows:%d, orderOfSub:%d", pPObj, pSql,
pTableMetaInfo->vgroupList->vgroups[0].ipAddr[0].ip, pTableMetaInfo->vgroupList->vgroups[0].vgId, pTableMetaInfo->vgroupList->vgroups[0].ipAddr[0].fqdn, pTableMetaInfo->vgroupList->vgroups[0].vgId,
numOfRowsFromSubquery, idx); numOfRowsFromSubquery, idx);
tColModelCompact(pDesc->pColumnModel, trsupport->localBuffer, pDesc->pColumnModel->capacity); tColModelCompact(pDesc->pColumnModel, trsupport->localBuffer, pDesc->pColumnModel->capacity);
...@@ -1473,12 +1473,12 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { ...@@ -1473,12 +1473,12 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
if (pState->code != TSDB_CODE_SUCCESS) { // at least one peer subquery failed, abort current query if (pState->code != TSDB_CODE_SUCCESS) { // at least one peer subquery failed, abort current query
tscTrace("%p sub:%p query failed,ip:%u,vgId:%d,orderOfSub:%d,global code:%d", pParentSql, pSql, tscTrace("%p sub:%p query failed,ip:%u,vgId:%d,orderOfSub:%d,global code:%d", pParentSql, pSql,
pVgroup->ipAddr[0].ip, pVgroup->vgId, trsupport->subqueryIndex, pState->code); pVgroup->ipAddr[0].fqdn, pVgroup->vgId, trsupport->subqueryIndex, pState->code);
tscHandleSubqueryError(param, tres, pState->code); tscHandleSubqueryError(param, tres, pState->code);
} else { // success, proceed to retrieve data from dnode } else { // success, proceed to retrieve data from dnode
tscTrace("%p sub:%p query complete, ip:%u, vgId:%d, orderOfSub:%d, retrieve data", trsupport->pParentSqlObj, pSql, tscTrace("%p sub:%p query complete, ip:%u, vgId:%d, orderOfSub:%d, retrieve data", trsupport->pParentSqlObj, pSql,
pVgroup->ipAddr[0].ip, pVgroup->vgId, trsupport->subqueryIndex); pVgroup->ipAddr[0].fqdn, pVgroup->vgId, trsupport->subqueryIndex);
if (pSql->res.qhandle == 0) { // qhandle is NULL, code is TSDB_CODE_SUCCESS means no results generated from this vnode if (pSql->res.qhandle == 0) { // qhandle is NULL, code is TSDB_CODE_SUCCESS means no results generated from this vnode
tscRetrieveFromDnodeCallBack(param, pSql, 0); tscRetrieveFromDnodeCallBack(param, pSql, 0);
......
...@@ -55,7 +55,6 @@ int32_t tscInitRpc(const char *user, const char *secret, void** pMgmtConn) { ...@@ -55,7 +55,6 @@ int32_t tscInitRpc(const char *user, const char *secret, void** pMgmtConn) {
if (pVnodeConn == NULL) { if (pVnodeConn == NULL) {
memset(&rpcInit, 0, sizeof(rpcInit)); memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localIp = tsLocalIp;
rpcInit.localPort = 0; rpcInit.localPort = 0;
rpcInit.label = "TSC-vnode"; rpcInit.label = "TSC-vnode";
rpcInit.numOfThreads = tscNumOfThreads; rpcInit.numOfThreads = tscNumOfThreads;
...@@ -76,7 +75,6 @@ int32_t tscInitRpc(const char *user, const char *secret, void** pMgmtConn) { ...@@ -76,7 +75,6 @@ int32_t tscInitRpc(const char *user, const char *secret, void** pMgmtConn) {
if (*pMgmtConn == NULL) { if (*pMgmtConn == NULL) {
memset(&rpcInit, 0, sizeof(rpcInit)); memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localIp = tsLocalIp;
rpcInit.localPort = 0; rpcInit.localPort = 0;
rpcInit.label = "TSC-mgmt"; rpcInit.label = "TSC-mgmt";
rpcInit.numOfThreads = 1; rpcInit.numOfThreads = 1;
...@@ -109,23 +107,17 @@ void taos_init_imp() { ...@@ -109,23 +107,17 @@ void taos_init_imp() {
deltaToUtcInitOnce(); deltaToUtcInitOnce();
if (tscEmbedded == 0) { if (tscEmbedded == 0) {
/*
* set localIp = 0
* means unset tsLocalIp in client
* except read from config file
*/
strcpy(tsLocalIp, "0.0.0.0");
// Read global configuration. // Read global configuration.
taosInitGlobalCfg(); taosInitGlobalCfg();
taosReadGlobalLogCfg(); taosReadGlobalLogCfg();
// For log directory // For log directory
if (stat(logDir, &dirstat) < 0) mkdir(logDir, 0755); if (stat(tsLogDir, &dirstat) < 0) mkdir(tsLogDir, 0755);
sprintf(temp, "%s/taoslog", logDir); sprintf(temp, "%s/taoslog", tsLogDir);
if (taosInitLog(temp, tsNumOfLogLines, 10) < 0) { if (taosInitLog(temp, tsNumOfLogLines, 10) < 0) {
printf("failed to open log file in directory:%s\n", logDir); printf("failed to open log file in directory:%s\n", tsLogDir);
} }
taosReadGlobalCfg(); taosReadGlobalCfg();
...@@ -133,7 +125,7 @@ void taos_init_imp() { ...@@ -133,7 +125,7 @@ void taos_init_imp() {
taosPrintGlobalCfg(); taosPrintGlobalCfg();
tscTrace("starting to initialize TAOS client ..."); tscTrace("starting to initialize TAOS client ...");
tscTrace("Local IP address is:%s", tsLocalIp); tscTrace("Local End Point is:%s", tsLocalEp);
} }
taosSetCoreDump(); taosSetCoreDump();
...@@ -143,13 +135,12 @@ void taos_init_imp() { ...@@ -143,13 +135,12 @@ void taos_init_imp() {
} }
tscMgmtIpSet.inUse = 0; tscMgmtIpSet.inUse = 0;
tscMgmtIpSet.port = tsMnodeShellPort;
tscMgmtIpSet.numOfIps = 1; tscMgmtIpSet.numOfIps = 1;
tscMgmtIpSet.ip[0] = inet_addr(tsMasterIp); taosGetFqdnPortFromEp(tsFirst, tscMgmtIpSet.fqdn[0], &tscMgmtIpSet.port[0]);
if (tsSecondIp[0] && strcmp(tsSecondIp, tsMasterIp) != 0) { if (tsSecond[0] && strcmp(tsSecond, tsFirst) != 0) {
tscMgmtIpSet.numOfIps = 2; tscMgmtIpSet.numOfIps = 2;
tscMgmtIpSet.ip[1] = inet_addr(tsSecondIp); taosGetFqdnPortFromEp(tsSecond, tscMgmtIpSet.fqdn[1], &tscMgmtIpSet.port[1]);
} }
tscInitMsgsFp(); tscInitMsgsFp();
......
...@@ -631,47 +631,44 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, ...@@ -631,47 +631,44 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList,
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static void trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock) { static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock) {
int32_t firstPartLen = 0; // TODO: optimize this function
int len = 0;
STableMeta* pTableMeta = pTableDataBlock->pTableMeta; STableMeta* pTableMeta = pTableDataBlock->pTableMeta;
STableComInfo tinfo = tscGetTableInfo(pTableMeta); STableComInfo tinfo = tscGetTableInfo(pTableMeta);
SSchema* pSchema = tscGetTableSchema(pTableMeta); SSchema* pSchema = tscGetTableSchema(pTableMeta);
SSubmitBlk* pBlock = pDataBlock;
memcpy(pDataBlock, pTableDataBlock->pData, sizeof(SSubmitBlk)); memcpy(pDataBlock, pTableDataBlock->pData, sizeof(SSubmitBlk));
pDataBlock += sizeof(SSubmitBlk); pDataBlock += sizeof(SSubmitBlk);
int32_t total = sizeof(int32_t)*2; int32_t flen = 0;
for(int32_t i = 0; i < tinfo.numOfColumns; ++i) { for (int32_t i = 0; i < tinfo.numOfColumns; ++i) {
switch (pSchema[i].type) { flen += TYPE_BYTES[pSchema[i].type];
case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_BINARY: {
assert(0); // not support binary yet
firstPartLen += sizeof(int32_t);break;
}
default:
firstPartLen += tDataTypeDesc[pSchema[i].type].nSize;
total += tDataTypeDesc[pSchema[i].type].nSize;
}
} }
char* p = pTableDataBlock->pData + sizeof(SSubmitBlk); char* p = pTableDataBlock->pData + sizeof(SSubmitBlk);
pBlock->len = 0;
for (int32_t i = 0; i < htons(pBlock->numOfRows); ++i) {
SDataRow trow = (SDataRow)pDataBlock;
dataRowSetLen(trow, TD_DATA_ROW_HEAD_SIZE + flen);
SSubmitBlk* pBlock = (SSubmitBlk*) pTableDataBlock->pData; int toffset = 0;
int32_t rows = htons(pBlock->numOfRows); for (int32_t j = 0; j < tinfo.numOfColumns; j++) {
tdAppendColVal(trow, p, pSchema[j].type, pSchema[j].bytes, toffset);
for(int32_t i = 0; i < rows; ++i) { toffset += TYPE_BYTES[pSchema[j].type];
*(int32_t*) pDataBlock = total; p += pSchema[j].bytes;
pDataBlock += sizeof(int32_t); }
*(int32_t*) pDataBlock = firstPartLen;
pDataBlock += sizeof(int32_t);
memcpy(pDataBlock, p, pTableDataBlock->rowSize);
p += pTableDataBlock->rowSize; // p += pTableDataBlock->rowSize;
pDataBlock += pTableDataBlock->rowSize; pDataBlock += dataRowLen(trow);
pBlock->len += dataRowLen(trow);
} }
len = pBlock->len;
pBlock->len = htonl(pBlock->len);
return len;
} }
int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockList) { int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockList) {
...@@ -734,7 +731,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi ...@@ -734,7 +731,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi
pBlocks->len = htonl(len); pBlocks->len = htonl(len);
// erase the empty space reserved for binary data // erase the empty space reserved for binary data
trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock); len = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock);
dataBuf->size += (len + sizeof(SSubmitBlk)); dataBuf->size += (len + sizeof(SSubmitBlk));
dataBuf->numOfTables += 1; dataBuf->numOfTables += 1;
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <string.h> #include <string.h>
#include "taosdef.h" #include "taosdef.h"
#include "tutil.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -30,7 +31,7 @@ typedef struct { ...@@ -30,7 +31,7 @@ typedef struct {
int8_t type; // Column type int8_t type; // Column type
int16_t colId; // column ID int16_t colId; // column ID
int32_t bytes; // column bytes int32_t bytes; // column bytes
int32_t offset; // point offset in a row data int32_t offset; // point offset in SDataRow after the header part
} STColumn; } STColumn;
#define colType(col) ((col)->type) #define colType(col) ((col)->type)
...@@ -43,26 +44,25 @@ typedef struct { ...@@ -43,26 +44,25 @@ typedef struct {
#define colSetBytes(col, b) (colBytes(col) = (b)) #define colSetBytes(col, b) (colBytes(col) = (b))
#define colSetOffset(col, o) (colOffset(col) = (o)) #define colSetOffset(col, o) (colOffset(col) = (o))
STColumn *tdNewCol(int8_t type, int16_t colId, int16_t bytes);
void tdFreeCol(STColumn *pCol);
void tdColCpy(STColumn *dst, STColumn *src);
void tdSetCol(STColumn *pCol, int8_t type, int16_t colId, int32_t bytes);
// ----------------- TSDB SCHEMA DEFINITION // ----------------- TSDB SCHEMA DEFINITION
typedef struct { typedef struct {
int totalCols; // Total columns allocated
int numOfCols; // Number of columns appended int numOfCols; // Number of columns appended
int padding; // Total columns allocated int tlen; // maximum length of a SDataRow without the header part
int flen; // First part length in a SDataRow after the header part
STColumn columns[]; STColumn columns[];
} STSchema; } STSchema;
#define schemaNCols(s) ((s)->numOfCols) #define schemaNCols(s) ((s)->numOfCols)
#define schemaTotalCols(s) ((s)->totalCols)
#define schemaTLen(s) ((s)->tlen)
#define schemaFLen(s) ((s)->flen)
#define schemaColAt(s, i) ((s)->columns + i) #define schemaColAt(s, i) ((s)->columns + i)
STSchema *tdNewSchema(int32_t nCols); STSchema *tdNewSchema(int32_t nCols);
int tdSchemaAppendCol(STSchema *pSchema, int8_t type, int16_t colId, int32_t bytes); #define tdFreeSchema(s) tfree((s))
int tdSchemaAddCol(STSchema *pSchema, int8_t type, int16_t colId, int32_t bytes);
STSchema *tdDupSchema(STSchema *pSchema); STSchema *tdDupSchema(STSchema *pSchema);
void tdFreeSchema(STSchema *pSchema);
void tdUpdateSchema(STSchema *pSchema);
int tdGetSchemaEncodeSize(STSchema *pSchema); int tdGetSchemaEncodeSize(STSchema *pSchema);
void * tdEncodeSchema(void *dst, STSchema *pSchema); void * tdEncodeSchema(void *dst, STSchema *pSchema);
STSchema *tdDecodeSchema(void **psrc); STSchema *tdDecodeSchema(void **psrc);
...@@ -70,53 +70,100 @@ STSchema *tdDecodeSchema(void **psrc); ...@@ -70,53 +70,100 @@ STSchema *tdDecodeSchema(void **psrc);
// ----------------- Data row structure // ----------------- Data row structure
/* A data row, the format is like below: /* A data row, the format is like below:
* +----------+---------+---------------------------------+---------------------------------+ * |<------------------------------------- len ---------------------------------->|
* | int32_t | int32_t | | | * |<--Head ->|<--------- flen -------------->| |
* +----------+---------+---------------------------------+---------------------------------+ * +----------+---------------------------------+---------------------------------+
* | len | flen | First part | Second part | * | int32_t | | |
* +----------+---------+---------------------------------+---------------------------------+ * +----------+---------------------------------+---------------------------------+
* plen: first part length * | len | First part | Second part |
* len: the length including sizeof(row) + sizeof(len) * +----------+---------------------------------+---------------------------------+
* row: actual row data encoding
*/ */
typedef void *SDataRow; typedef void *SDataRow;
#define TD_DATA_ROW_HEAD_SIZE sizeof(int32_t)
#define TD_DATA_ROW_HEAD_SIZE (2 * sizeof(int32_t))
#define dataRowLen(r) (*(int32_t *)(r)) #define dataRowLen(r) (*(int32_t *)(r))
#define dataRowFLen(r) (*(int32_t *)((char *)(r) + sizeof(int32_t))) #define dataRowTuple(r) POINTER_DRIFT(r, TD_DATA_ROW_HEAD_SIZE)
#define dataRowTuple(r) ((char *)(r) + TD_DATA_ROW_HEAD_SIZE)
#define dataRowKey(r) (*(TSKEY *)(dataRowTuple(r))) #define dataRowKey(r) (*(TSKEY *)(dataRowTuple(r)))
#define dataRowSetLen(r, l) (dataRowLen(r) = (l)) #define dataRowSetLen(r, l) (dataRowLen(r) = (l))
#define dataRowSetFLen(r, l) (dataRowFLen(r) = (l))
#define dataRowIdx(r, i) ((char *)(r) + i)
#define dataRowCpy(dst, r) memcpy((dst), (r), dataRowLen(r)) #define dataRowCpy(dst, r) memcpy((dst), (r), dataRowLen(r))
#define dataRowAt(r, idx) ((char *)(r) + (idx)) #define dataRowMaxBytesFromSchema(s) (schemaTLen(s) + TD_DATA_ROW_HEAD_SIZE)
void tdInitDataRow(SDataRow row, STSchema *pSchema);
int tdMaxRowBytesFromSchema(STSchema *pSchema);
SDataRow tdNewDataRow(int32_t bytes, STSchema *pSchema);
SDataRow tdNewDataRowFromSchema(STSchema *pSchema); SDataRow tdNewDataRowFromSchema(STSchema *pSchema);
void tdFreeDataRow(SDataRow row); void tdFreeDataRow(SDataRow row);
int tdAppendColVal(SDataRow row, void *value, STColumn *pCol); void tdInitDataRow(SDataRow row, STSchema *pSchema);
void tdDataRowReset(SDataRow row, STSchema *pSchema); int tdAppendColVal(SDataRow row, void *value, int8_t type, int32_t bytes, int32_t offset);
SDataRow tdDataRowDup(SDataRow row); SDataRow tdDataRowDup(SDataRow row);
// NOTE: offset here including the header size
static FORCE_INLINE void *tdGetRowDataOfCol(SDataRow row, int8_t type, int32_t offset) {
switch (type) {
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR:
return POINTER_DRIFT(row, *(VarDataOffsetT *)POINTER_DRIFT(row, offset));
break;
default:
return POINTER_DRIFT(row, offset);
break;
}
}
// ----------------- Data column structure // ----------------- Data column structure
typedef struct SDataCol { typedef struct SDataCol {
int8_t type; int8_t type; // column type
int16_t colId; int16_t colId; // column ID
int bytes; int bytes; // column data bytes defined
int len; int offset; // data offset in a SDataRow (including the header size)
int offset; int spaceSize; // Total space size for this column
void * pData; // Original data int len; // column data length
VarDataOffsetT *dataOff; // For binary and nchar data, the offset in the data column
void * pData; // Actual data pointer
} SDataCol; } SDataCol;
static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; }
void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints);
void dataColAppendVal(SDataCol *pCol, void *value, int numOfPoints, int maxPoints);
void dataColPopPoints(SDataCol *pCol, int pointsToPop, int numOfPoints);
void dataColSetOffset(SDataCol *pCol, int nEle);
bool isNEleNull(SDataCol *pCol, int nEle);
void dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints);
// Get the data pointer from a column-wised data
static FORCE_INLINE void *tdGetColDataOfRow(SDataCol *pCol, int row) {
switch (pCol->type) {
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR:
return POINTER_DRIFT(pCol->pData, pCol->dataOff[row]);
break;
default:
return POINTER_DRIFT(pCol->pData, TYPE_BYTES[pCol->type] * row);
break;
}
}
static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int rows) {
ASSERT(rows > 0);
switch (pDataCol->type) {
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR:
return pDataCol->dataOff[rows - 1] + varDataTLen(tdGetColDataOfRow(pDataCol, rows - 1));
break;
default:
return TYPE_BYTES[pDataCol->type] * rows;
}
}
typedef struct { typedef struct {
int maxRowSize; int maxRowSize;
int maxCols; // max number of columns int maxCols; // max number of columns
int maxPoints; // max number of points int maxPoints; // max number of points
int bufSize;
int numOfPoints; int numOfPoints;
int numOfCols; // Total number of cols int numOfCols; // Total number of cols
int sversion; // TODO: set sversion int sversion; // TODO: set sversion
...@@ -125,7 +172,7 @@ typedef struct { ...@@ -125,7 +172,7 @@ typedef struct {
} SDataCols; } SDataCols;
#define keyCol(pCols) (&((pCols)->cols[0])) // Key column #define keyCol(pCols) (&((pCols)->cols[0])) // Key column
#define dataColsKeyAt(pCols, idx) ((int64_t *)(keyCol(pCols)->pData))[(idx)] #define dataColsKeyAt(pCols, idx) ((TSKEY *)(keyCol(pCols)->pData))[(idx)]
#define dataColsKeyFirst(pCols) dataColsKeyAt(pCols, 0) #define dataColsKeyFirst(pCols) dataColsKeyAt(pCols, 0)
#define dataColsKeyLast(pCols) dataColsKeyAt(pCols, (pCols)->numOfPoints - 1) #define dataColsKeyLast(pCols) dataColsKeyAt(pCols, (pCols)->numOfPoints - 1)
......
...@@ -24,10 +24,10 @@ extern char configDir[]; ...@@ -24,10 +24,10 @@ extern char configDir[];
extern char tsVnodeDir[]; extern char tsVnodeDir[];
extern char tsDnodeDir[]; extern char tsDnodeDir[];
extern char tsMnodeDir[]; extern char tsMnodeDir[];
extern char dataDir[]; extern char tsDataDir[];
extern char logDir[]; extern char tsLogDir[];
extern char scriptDir[]; extern char tsScriptDir[];
extern char osName[]; extern char tsOsName[];
// system info // system info
extern int64_t tsPageSize; extern int64_t tsPageSize;
...@@ -51,8 +51,10 @@ extern int32_t tsVersion; ...@@ -51,8 +51,10 @@ extern int32_t tsVersion;
extern int32_t tscEmbedded; extern int32_t tscEmbedded;
extern int64_t tsMsPerDay[2]; extern int64_t tsMsPerDay[2];
extern char tsMasterIp[]; extern char tsFirst[];
extern char tsSecondIp[]; extern char tsSecond[];
extern char tsLocalEp[];
extern uint16_t tsServerPort;
extern uint16_t tsMnodeDnodePort; extern uint16_t tsMnodeDnodePort;
extern uint16_t tsMnodeShellPort; extern uint16_t tsMnodeShellPort;
extern uint16_t tsDnodeShellPort; extern uint16_t tsDnodeShellPort;
...@@ -178,6 +180,7 @@ void taosInitGlobalCfg(); ...@@ -178,6 +180,7 @@ void taosInitGlobalCfg();
bool taosCheckGlobalCfg(); bool taosCheckGlobalCfg();
void taosSetAllDebugFlag(); void taosSetAllDebugFlag();
bool taosCfgDynamicOptions(char *msg); bool taosCfgDynamicOptions(char *msg);
int taosGetFqdnPortFromEp(char *ep, char *fqdn, uint16_t *port);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
此差异已折叠。
...@@ -25,14 +25,15 @@ ...@@ -25,14 +25,15 @@
#include "tutil.h" #include "tutil.h"
#include "tlocale.h" #include "tlocale.h"
#include "ttimezone.h" #include "ttimezone.h"
#include "tsync.h"
char configDir[TSDB_FILENAME_LEN] = "/etc/taos"; char configDir[TSDB_FILENAME_LEN] = "/etc/taos";
char tsVnodeDir[TSDB_FILENAME_LEN] = {0}; char tsVnodeDir[TSDB_FILENAME_LEN] = {0};
char tsDnodeDir[TSDB_FILENAME_LEN] = {0}; char tsDnodeDir[TSDB_FILENAME_LEN] = {0};
char tsMnodeDir[TSDB_FILENAME_LEN] = {0}; char tsMnodeDir[TSDB_FILENAME_LEN] = {0};
char dataDir[TSDB_FILENAME_LEN] = "/var/lib/taos"; char tsDataDir[TSDB_FILENAME_LEN] = "/var/lib/taos";
char scriptDir[TSDB_FILENAME_LEN] = "/etc/taos"; char tsScriptDir[TSDB_FILENAME_LEN] = "/etc/taos";
char osName[10] = "Linux"; char tsOsName[10] = "Linux";
// system info, not configurable // system info, not configurable
int64_t tsPageSize; int64_t tsPageSize;
...@@ -60,8 +61,11 @@ int32_t tscEmbedded = 0; ...@@ -60,8 +61,11 @@ int32_t tscEmbedded = 0;
*/ */
int64_t tsMsPerDay[] = {86400000L, 86400000000L}; int64_t tsMsPerDay[] = {86400000L, 86400000000L};
char tsMasterIp[TSDB_IPv4ADDR_LEN] = {0}; char tsFirst[TSDB_FQDN_LEN] = {0};
char tsSecondIp[TSDB_IPv4ADDR_LEN] = {0}; char tsSecond[TSDB_FQDN_LEN] = {0};
char tsArbitrator[TSDB_FQDN_LEN] = {0};
char tsLocalEp[TSDB_FQDN_LEN] = {0}; // Local End Point, hostname:port
uint16_t tsServerPort = 6030;
uint16_t tsMnodeShellPort = 6030; // udp[6030-6034] tcp[6030] uint16_t tsMnodeShellPort = 6030; // udp[6030-6034] tcp[6030]
uint16_t tsDnodeShellPort = 6035; // udp[6035-6039] tcp[6035] uint16_t tsDnodeShellPort = 6035; // udp[6035-6039] tcp[6035]
uint16_t tsMnodeDnodePort = 6040; // udp/tcp uint16_t tsMnodeDnodePort = 6040; // udp/tcp
...@@ -70,8 +74,6 @@ uint16_t tsSyncPort = 6050; ...@@ -70,8 +74,6 @@ uint16_t tsSyncPort = 6050;
int32_t tsStatusInterval = 1; // second int32_t tsStatusInterval = 1; // second
int32_t tsShellActivityTimer = 3; // second int32_t tsShellActivityTimer = 3; // second
int32_t tsVnodePeerHBTimer = 1; // second
int32_t tsMgmtPeerHBTimer = 1; // second
int32_t tsMeterMetaKeepTimer = 7200; // second int32_t tsMeterMetaKeepTimer = 7200; // second
int32_t tsMetricMetaKeepTimer = 600; // second int32_t tsMetricMetaKeepTimer = 600; // second
int32_t tsRpcTimer = 300; int32_t tsRpcTimer = 300;
...@@ -79,8 +81,6 @@ int32_t tsRpcMaxTime = 600; // seconds; ...@@ -79,8 +81,6 @@ int32_t tsRpcMaxTime = 600; // seconds;
float tsNumOfThreadsPerCore = 1.0; float tsNumOfThreadsPerCore = 1.0;
float tsRatioOfQueryThreads = 0.5; float tsRatioOfQueryThreads = 0.5;
char tsPublicIp[TSDB_IPv4ADDR_LEN] = {0};
char tsPrivateIp[TSDB_IPv4ADDR_LEN] = {0};
int16_t tsNumOfVnodesPerCore = 8; int16_t tsNumOfVnodesPerCore = 8;
int16_t tsNumOfTotalVnodes = TSDB_INVALID_VNODE_NUM; int16_t tsNumOfTotalVnodes = TSDB_INVALID_VNODE_NUM;
...@@ -112,7 +112,6 @@ int32_t tsNumOfMPeers = 3; ...@@ -112,7 +112,6 @@ int32_t tsNumOfMPeers = 3;
int32_t tsMaxShellConns = 2000; int32_t tsMaxShellConns = 2000;
int32_t tsMaxTables = 100000; int32_t tsMaxTables = 100000;
char tsLocalIp[TSDB_IPv4ADDR_LEN] = {0};
char tsDefaultDB[TSDB_DB_NAME_LEN] = {0}; char tsDefaultDB[TSDB_DB_NAME_LEN] = {0};
char tsDefaultUser[64] = "root"; char tsDefaultUser[64] = "root";
char tsDefaultPass[64] = "taosdata"; char tsDefaultPass[64] = "taosdata";
...@@ -144,6 +143,7 @@ int32_t qdebugFlag = 131; ...@@ -144,6 +143,7 @@ int32_t qdebugFlag = 131;
int32_t rpcDebugFlag = 131; int32_t rpcDebugFlag = 131;
int32_t uDebugFlag = 131; int32_t uDebugFlag = 131;
int32_t debugFlag = 131; int32_t debugFlag = 131;
int32_t sDebugFlag = 131;
// the maximum number of results for projection query on super table that are returned from // the maximum number of results for projection query on super table that are returned from
// one virtual node, to order according to timestamp // one virtual node, to order according to timestamp
...@@ -183,7 +183,6 @@ float tsStreamComputDelayRatio = 0.1; ...@@ -183,7 +183,6 @@ float tsStreamComputDelayRatio = 0.1;
int32_t tsProjectExecInterval = 10000; // every 10sec, the projection will be executed once int32_t tsProjectExecInterval = 10000; // every 10sec, the projection will be executed once
int64_t tsMaxRetentWindow = 24 * 3600L; // maximum time window tolerance int64_t tsMaxRetentWindow = 24 * 3600L; // maximum time window tolerance
char tsHttpIp[TSDB_IPv4ADDR_LEN] = "0.0.0.0";
uint16_t tsHttpPort = 6020; // only tcp, range tcp[6020] uint16_t tsHttpPort = 6020; // only tcp, range tcp[6020]
// uint16_t tsNginxPort = 6060; //only tcp, range tcp[6060] // uint16_t tsNginxPort = 6060; //only tcp, range tcp[6060]
int32_t tsHttpCacheSessions = 100; int32_t tsHttpCacheSessions = 100;
...@@ -194,7 +193,6 @@ int32_t tsHttpEnableRecordSql = 0; ...@@ -194,7 +193,6 @@ int32_t tsHttpEnableRecordSql = 0;
int32_t tsTelegrafUseFieldNum = 0; int32_t tsTelegrafUseFieldNum = 0;
int32_t tsTscEnableRecordSql = 0; int32_t tsTscEnableRecordSql = 0;
int32_t tsAnyIp = 1;
uint32_t tsPublicIpInt = 0; uint32_t tsPublicIpInt = 0;
char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log"; char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log";
...@@ -274,69 +272,29 @@ static void doInitGlobalConfig() { ...@@ -274,69 +272,29 @@ static void doInitGlobalConfig() {
SGlobalCfg cfg = {0}; SGlobalCfg cfg = {0};
// ip address // ip address
cfg.option = "masterIp"; cfg.option = "first";
cfg.ptr = tsMasterIp; cfg.ptr = tsFirst;
cfg.valType = TAOS_CFG_VTYPE_IPSTR; cfg.valType = TAOS_CFG_VTYPE_STRING;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
cfg.minValue = 0;
cfg.maxValue = 0;
cfg.ptrLength = TSDB_IPv4ADDR_LEN;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "secondIp";
cfg.ptr = tsSecondIp;
cfg.valType = TAOS_CFG_VTYPE_IPSTR;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
cfg.minValue = 0; cfg.minValue = 0;
cfg.maxValue = 0; cfg.maxValue = 0;
cfg.ptrLength = TSDB_IPv4ADDR_LEN; cfg.ptrLength = TSDB_FQDN_LEN;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "publicIp";
cfg.ptr = tsPublicIp;
cfg.valType = TAOS_CFG_VTYPE_IPSTR;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
cfg.minValue = 0;
cfg.maxValue = 0;
cfg.ptrLength = TSDB_IPv4ADDR_LEN;
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
cfg.option = "privateIp"; cfg.option = "second";
cfg.ptr = tsPrivateIp; cfg.ptr = tsSecond;
cfg.valType = TAOS_CFG_VTYPE_IPSTR; cfg.valType = TAOS_CFG_VTYPE_STRING;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
cfg.minValue = 0;
cfg.maxValue = 0;
cfg.ptrLength = TSDB_IPv4ADDR_LEN;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "localIp";
cfg.ptr = tsLocalIp;
cfg.valType = TAOS_CFG_VTYPE_IPSTR;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
cfg.minValue = 0; cfg.minValue = 0;
cfg.maxValue = 0; cfg.maxValue = 0;
cfg.ptrLength = TSDB_IPv4ADDR_LEN; cfg.ptrLength = TSDB_FQDN_LEN;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "httpIp";
cfg.ptr = tsHttpIp;
cfg.valType = TAOS_CFG_VTYPE_IPSTR;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
cfg.minValue = 0;
cfg.maxValue = 0;
cfg.ptrLength = TSDB_IPv4ADDR_LEN;
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
// port // port
cfg.option = "mnodeShellPort"; cfg.option = "serverPort";
cfg.ptr = &tsMnodeShellPort; cfg.ptr = &tsServerPort;
cfg.valType = TAOS_CFG_VTYPE_INT16; cfg.valType = TAOS_CFG_VTYPE_INT16;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
cfg.minValue = 1; cfg.minValue = 1;
...@@ -345,56 +303,6 @@ static void doInitGlobalConfig() { ...@@ -345,56 +303,6 @@ static void doInitGlobalConfig() {
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
cfg.option = "dnodeShellPort";
cfg.ptr = &tsDnodeShellPort;
cfg.valType = TAOS_CFG_VTYPE_INT16;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT;
cfg.minValue = 1;
cfg.maxValue = 65535;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "mnodeDnodePort";
cfg.ptr = &tsMnodeDnodePort;
cfg.valType = TAOS_CFG_VTYPE_INT16;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
cfg.minValue = 1;
cfg.maxValue = 65535;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "dnodeMnodePort";
cfg.ptr = &tsDnodeMnodePort;
cfg.valType = TAOS_CFG_VTYPE_INT16;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
cfg.minValue = 1;
cfg.maxValue = 65535;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
// cfg.option = "syncPort";
// cfg.ptr = &syncPort;
// cfg.valType = TAOS_CFG_VTYPE_INT16;
// cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
// cfg.minValue = 1;
// cfg.maxValue = 65535;
// cfg.ptrLength = 0;
// cfg.unitType = TAOS_CFG_UTYPE_NONE;
// taosInitConfigOption(cfg);
cfg.option = "httpPort";
cfg.ptr = &tsHttpPort;
cfg.valType = TAOS_CFG_VTYPE_INT16;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW;
cfg.minValue = 1;
cfg.maxValue = 65535;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
// directory // directory
cfg.option = "configDir"; cfg.option = "configDir";
cfg.ptr = configDir; cfg.ptr = configDir;
...@@ -407,7 +315,7 @@ static void doInitGlobalConfig() { ...@@ -407,7 +315,7 @@ static void doInitGlobalConfig() {
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
cfg.option = "logDir"; cfg.option = "logDir";
cfg.ptr = logDir; cfg.ptr = tsLogDir;
cfg.valType = TAOS_CFG_VTYPE_DIRECTORY; cfg.valType = TAOS_CFG_VTYPE_DIRECTORY;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_LOG; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_LOG;
cfg.minValue = 0; cfg.minValue = 0;
...@@ -417,7 +325,7 @@ static void doInitGlobalConfig() { ...@@ -417,7 +325,7 @@ static void doInitGlobalConfig() {
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
cfg.option = "scriptDir"; cfg.option = "scriptDir";
cfg.ptr = scriptDir; cfg.ptr = tsScriptDir;
cfg.valType = TAOS_CFG_VTYPE_DIRECTORY; cfg.valType = TAOS_CFG_VTYPE_DIRECTORY;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
cfg.minValue = 0; cfg.minValue = 0;
...@@ -427,7 +335,7 @@ static void doInitGlobalConfig() { ...@@ -427,7 +335,7 @@ static void doInitGlobalConfig() {
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
cfg.option = "dataDir"; cfg.option = "dataDir";
cfg.ptr = dataDir; cfg.ptr = tsDataDir;
cfg.valType = TAOS_CFG_VTYPE_DIRECTORY; cfg.valType = TAOS_CFG_VTYPE_DIRECTORY;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
cfg.minValue = 0; cfg.minValue = 0;
...@@ -436,6 +344,16 @@ static void doInitGlobalConfig() { ...@@ -436,6 +344,16 @@ static void doInitGlobalConfig() {
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
cfg.option = "arbitrator";
cfg.ptr = tsArbitrator;
cfg.valType = TAOS_CFG_VTYPE_STRING;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT;
cfg.minValue = 0;
cfg.maxValue = 0;
cfg.ptrLength = TSDB_FQDN_LEN;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
// dnode configs // dnode configs
cfg.option = "numOfThreadsPerCore"; cfg.option = "numOfThreadsPerCore";
cfg.ptr = &tsNumOfThreadsPerCore; cfg.ptr = &tsNumOfThreadsPerCore;
...@@ -1107,6 +1025,16 @@ static void doInitGlobalConfig() { ...@@ -1107,6 +1025,16 @@ static void doInitGlobalConfig() {
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
cfg.option = "sDebugFlag";
cfg.ptr = &sDebugFlag;
cfg.valType = TAOS_CFG_VTYPE_INT32;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG;
cfg.minValue = 0;
cfg.maxValue = 255;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "sdbDebugFlag"; cfg.option = "sdbDebugFlag";
cfg.ptr = &sdbDebugFlag; cfg.ptr = &sdbDebugFlag;
cfg.valType = TAOS_CFG_VTYPE_INT32; cfg.valType = TAOS_CFG_VTYPE_INT32;
...@@ -1227,16 +1155,6 @@ static void doInitGlobalConfig() { ...@@ -1227,16 +1155,6 @@ static void doInitGlobalConfig() {
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
cfg.option = "anyIp";
cfg.ptr = &tsAnyIp;
cfg.valType = TAOS_CFG_VTYPE_INT32;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
cfg.minValue = 0;
cfg.maxValue = 1;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
// version info // version info
cfg.option = "gitinfo"; cfg.option = "gitinfo";
cfg.ptr = gitinfo; cfg.ptr = gitinfo;
...@@ -1284,25 +1202,16 @@ void taosInitGlobalCfg() { ...@@ -1284,25 +1202,16 @@ void taosInitGlobalCfg() {
} }
bool taosCheckGlobalCfg() { bool taosCheckGlobalCfg() {
if (tsPrivateIp[0] == 0) { taosGetFqdn(tsLocalEp);
taosGetPrivateIp(tsPrivateIp); sprintf(tsLocalEp + strlen(tsLocalEp), ":%d", tsServerPort);
} uPrint("localEp is %s", tsLocalEp);
if (tsPublicIp[0] == 0) {
strcpy(tsPublicIp, tsPrivateIp);
}
tsPublicIpInt = inet_addr(tsPublicIp);
if (tsLocalIp[0] == 0) {
strcpy(tsLocalIp, tsPrivateIp);
}
if (tsMasterIp[0] == 0) { if (tsFirst[0] == 0) {
strcpy(tsMasterIp, tsPrivateIp); strcpy(tsFirst, tsLocalEp);
} }
if (tsSecondIp[0] == 0) { if (tsSecond[0] == 0) {
strcpy(tsSecondIp, tsMasterIp); strcpy(tsSecond, tsLocalEp);
} }
taosGetSystemInfo(); taosGetSystemInfo();
...@@ -1324,15 +1233,6 @@ bool taosCheckGlobalCfg() { ...@@ -1324,15 +1233,6 @@ bool taosCheckGlobalCfg() {
tsNumOfTotalVnodes = tsNumOfTotalVnodes < TSDB_MIN_VNODES ? TSDB_MIN_VNODES : tsNumOfTotalVnodes; tsNumOfTotalVnodes = tsNumOfTotalVnodes < TSDB_MIN_VNODES ? TSDB_MIN_VNODES : tsNumOfTotalVnodes;
} }
if (strlen(tsPrivateIp) == 0) {
uError("privateIp is null");
return false;
}
if (tscEmbedded) {
strcpy(tsLocalIp, tsPrivateIp);
}
// todo refactor // todo refactor
tsVersion = 0; tsVersion = 0;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
...@@ -1345,5 +1245,26 @@ bool taosCheckGlobalCfg() { ...@@ -1345,5 +1245,26 @@ bool taosCheckGlobalCfg() {
tsVersion = 10 * tsVersion; tsVersion = 10 * tsVersion;
tsMnodeShellPort = tsServerPort + TSDB_PORT_MNODESHELL; // udp[6030-6034] tcp[6030]
tsDnodeShellPort = tsServerPort + TSDB_PORT_DNODESHELL; // udp[6035-6039] tcp[6035]
tsMnodeDnodePort = tsServerPort + TSDB_PORT_MNODEDNODE; // udp/tcp
tsDnodeMnodePort = tsServerPort + TSDB_PORT_DNODEMNODE; // udp/tcp
tsSyncPort = tsServerPort + TSDB_PORT_SYNC;
return true; return true;
} }
int taosGetFqdnPortFromEp(char *ep, char *fqdn, uint16_t *port) {
*port = 0;
strcpy(fqdn, ep);
char *temp = strchr(fqdn, ':');
if (temp) {
*temp = 0;
*port = atoi(temp+1);
}
if (*port == 0) *port = tsServerPort;
return 0;
}
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "taosdef.h" #include "taosdef.h"
#include "ttokendef.h" #include "ttokendef.h"
#include "tscompression.h"
const int32_t TYPE_BYTES[11] = { const int32_t TYPE_BYTES[11] = {
-1, // TSDB_DATA_TYPE_NULL -1, // TSDB_DATA_TYPE_NULL
...@@ -26,23 +27,23 @@ const int32_t TYPE_BYTES[11] = { ...@@ -26,23 +27,23 @@ const int32_t TYPE_BYTES[11] = {
sizeof(int64_t), // TSDB_DATA_TYPE_BIGINT sizeof(int64_t), // TSDB_DATA_TYPE_BIGINT
sizeof(float), // TSDB_DATA_TYPE_FLOAT sizeof(float), // TSDB_DATA_TYPE_FLOAT
sizeof(double), // TSDB_DATA_TYPE_DOUBLE sizeof(double), // TSDB_DATA_TYPE_DOUBLE
sizeof(int32_t), // TSDB_DATA_TYPE_BINARY sizeof(VarDataOffsetT), // TSDB_DATA_TYPE_BINARY
sizeof(TSKEY), // TSDB_DATA_TYPE_TIMESTAMP sizeof(TSKEY), // TSDB_DATA_TYPE_TIMESTAMP
sizeof(int32_t) // TSDB_DATA_TYPE_NCHAR sizeof(VarDataOffsetT) // TSDB_DATA_TYPE_NCHAR
}; };
tDataTypeDescriptor tDataTypeDesc[11] = { tDataTypeDescriptor tDataTypeDesc[11] = {
{TSDB_DATA_TYPE_NULL, 6, 1, "NOTYPE"}, {TSDB_DATA_TYPE_NULL, 6, 1, "NOTYPE", NULL, NULL},
{TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL"}, {TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL", tsCompressBool, tsDecompressBool},
{TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT"}, {TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT", tsCompressTinyint, tsDecompressTinyint},
{TSDB_DATA_TYPE_SMALLINT, 8, SHORT_BYTES, "SMALLINT"}, {TSDB_DATA_TYPE_SMALLINT, 8, SHORT_BYTES, "SMALLINT", tsCompressSmallint, tsDecompressSmallint},
{TSDB_DATA_TYPE_INT, 3, INT_BYTES, "INT"}, {TSDB_DATA_TYPE_INT, 3, INT_BYTES, "INT", tsCompressInt, tsDecompressInt},
{TSDB_DATA_TYPE_BIGINT, 6, LONG_BYTES, "BIGINT"}, {TSDB_DATA_TYPE_BIGINT, 6, LONG_BYTES, "BIGINT", tsCompressBigint, tsDecompressBigint},
{TSDB_DATA_TYPE_FLOAT, 5, FLOAT_BYTES, "FLOAT"}, {TSDB_DATA_TYPE_FLOAT, 5, FLOAT_BYTES, "FLOAT", tsCompressFloat, tsDecompressFloat},
{TSDB_DATA_TYPE_DOUBLE, 6, DOUBLE_BYTES, "DOUBLE"}, {TSDB_DATA_TYPE_DOUBLE, 6, DOUBLE_BYTES, "DOUBLE", tsCompressDouble, tsDecompressDouble},
{TSDB_DATA_TYPE_BINARY, 6, 0, "BINARY"}, {TSDB_DATA_TYPE_BINARY, 6, 0, "BINARY", tsCompressString, tsDecompressString},
{TSDB_DATA_TYPE_TIMESTAMP, 9, LONG_BYTES, "TIMESTAMP"}, {TSDB_DATA_TYPE_TIMESTAMP, 9, LONG_BYTES, "TIMESTAMP", tsCompressTimestamp, tsDecompressTimestamp},
{TSDB_DATA_TYPE_NCHAR, 5, 8, "NCHAR"}, {TSDB_DATA_TYPE_NCHAR, 5, 8, "NCHAR", tsCompressString, tsDecompressString},
}; };
char tTokenTypeSwitcher[13] = { char tTokenTypeSwitcher[13] = {
......
...@@ -59,16 +59,13 @@ void dnodeUpdateIpSet(void *ahandle, SRpcIpSet *pIpSet) { ...@@ -59,16 +59,13 @@ void dnodeUpdateIpSet(void *ahandle, SRpcIpSet *pIpSet) {
tsMnodeIpSet = *pIpSet; tsMnodeIpSet = *pIpSet;
} }
void dnodeGetMnodeIpSet(void *ipSetRaw, bool usePublicIp) { void dnodeGetMnodeDnodeIpSet(void *ipSetRaw) {
SRpcIpSet *ipSet = ipSetRaw; SRpcIpSet *ipSet = ipSetRaw;
ipSet->numOfIps = tsMnodeInfos.nodeNum; ipSet->numOfIps = tsMnodeInfos.nodeNum;
ipSet->inUse = tsMnodeInfos.inUse; ipSet->inUse = tsMnodeInfos.inUse;
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; ++i) { for (int32_t i = 0; i < tsMnodeInfos.nodeNum; ++i) {
if (usePublicIp) { taosGetFqdnPortFromEp(tsMnodeInfos.nodeInfos[i].nodeEp, ipSet->fqdn[i], &ipSet->port[i]);
ipSet->ip[i] = tsMnodeInfos.nodeInfos[i].nodeIp; ipSet->port[i] += TSDB_PORT_MNODEDNODE;
} else {
ipSet->ip[i] = tsMnodeInfos.nodeInfos[i].nodeIp;
}
} }
} }
...@@ -85,26 +82,25 @@ int32_t dnodeInitMClient() { ...@@ -85,26 +82,25 @@ int32_t dnodeInitMClient() {
if (!dnodeReadMnodeInfos()) { if (!dnodeReadMnodeInfos()) {
memset(&tsMnodeIpSet, 0, sizeof(SRpcIpSet)); memset(&tsMnodeIpSet, 0, sizeof(SRpcIpSet));
memset(&tsMnodeInfos, 0, sizeof(SDMMnodeInfos)); memset(&tsMnodeInfos, 0, sizeof(SDMMnodeInfos));
tsMnodeIpSet.port = tsMnodeDnodePort;
tsMnodeIpSet.numOfIps = 1; tsMnodeIpSet.numOfIps = 1;
tsMnodeIpSet.ip[0] = inet_addr(tsMasterIp); taosGetFqdnPortFromEp(tsFirst, tsMnodeIpSet.fqdn[0], &tsMnodeIpSet.port[0]);
if (strcmp(tsSecondIp, tsMasterIp) != 0) { tsMnodeIpSet.port[0] += TSDB_PORT_MNODEDNODE;
if (strcmp(tsSecond, tsFirst) != 0) {
tsMnodeIpSet.numOfIps = 2; tsMnodeIpSet.numOfIps = 2;
tsMnodeIpSet.ip[1] = inet_addr(tsSecondIp); taosGetFqdnPortFromEp(tsSecond, tsMnodeIpSet.fqdn[1], &tsMnodeIpSet.port[1]);
tsMnodeIpSet.port[1] += TSDB_PORT_MNODEDNODE;
} }
} else { } else {
tsMnodeIpSet.inUse = tsMnodeInfos.inUse; tsMnodeIpSet.inUse = tsMnodeInfos.inUse;
tsMnodeIpSet.numOfIps = tsMnodeInfos.nodeNum; tsMnodeIpSet.numOfIps = tsMnodeInfos.nodeNum;
tsMnodeIpSet.port = tsMnodeInfos.nodeInfos[0].nodePort;
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) { for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) {
tsMnodeIpSet.ip[i] = tsMnodeInfos.nodeInfos[i].nodeIp; taosGetFqdnPortFromEp(tsMnodeInfos.nodeInfos[i].nodeEp, tsMnodeIpSet.fqdn[i], &tsMnodeIpSet.port[i]);
tsMnodeIpSet.port[i] += TSDB_PORT_MNODEDNODE;
} }
} }
SRpcInit rpcInit; SRpcInit rpcInit;
memset(&rpcInit, 0, sizeof(rpcInit)); memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localIp = tsAnyIp ? "0.0.0.0" : tsPrivateIp;
rpcInit.localPort = 0;
rpcInit.label = "DND-MC"; rpcInit.label = "DND-MC";
rpcInit.numOfThreads = 1; rpcInit.numOfThreads = 1;
rpcInit.cfp = dnodeProcessRspFromMnode; rpcInit.cfp = dnodeProcessRspFromMnode;
...@@ -182,9 +178,6 @@ static void dnodeProcessStatusRsp(SRpcMsg *pMsg) { ...@@ -182,9 +178,6 @@ static void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
for (int32_t i = 0; i < pMnodes->nodeNum; ++i) { for (int32_t i = 0; i < pMnodes->nodeNum; ++i) {
SDMMnodeInfo *pMnodeInfo = &pMnodes->nodeInfos[i]; SDMMnodeInfo *pMnodeInfo = &pMnodes->nodeInfos[i];
pMnodeInfo->nodeId = htonl(pMnodeInfo->nodeId); pMnodeInfo->nodeId = htonl(pMnodeInfo->nodeId);
pMnodeInfo->nodeIp = htonl(pMnodeInfo->nodeIp);
pMnodeInfo->nodePort = htons(pMnodeInfo->nodePort);
pMnodeInfo->syncPort = htons(pMnodeInfo->syncPort);
} }
SDMVgroupAccess *pVgAcccess = pStatusRsp->vgAccess; SDMVgroupAccess *pVgAcccess = pStatusRsp->vgAccess;
...@@ -207,15 +200,14 @@ static void dnodeUpdateMnodeInfos(SDMMnodeInfos *pMnodes) { ...@@ -207,15 +200,14 @@ static void dnodeUpdateMnodeInfos(SDMMnodeInfos *pMnodes) {
tsMnodeIpSet.inUse = tsMnodeInfos.inUse; tsMnodeIpSet.inUse = tsMnodeInfos.inUse;
tsMnodeIpSet.numOfIps = tsMnodeInfos.nodeNum; tsMnodeIpSet.numOfIps = tsMnodeInfos.nodeNum;
tsMnodeIpSet.port = tsMnodeInfos.nodeInfos[0].nodePort;
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) { for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) {
tsMnodeIpSet.ip[i] = tsMnodeInfos.nodeInfos[i].nodeIp; taosGetFqdnPortFromEp(tsMnodeInfos.nodeInfos[i].nodeEp, tsMnodeIpSet.fqdn[i], &tsMnodeIpSet.port[i]);
tsMnodeIpSet.port[i] += TSDB_PORT_MNODEDNODE;
} }
dPrint("mnodes is changed, nodeNum:%d inUse:%d", tsMnodeInfos.nodeNum, tsMnodeInfos.inUse); dPrint("mnodes is changed, nodeNum:%d inUse:%d", tsMnodeInfos.nodeNum, tsMnodeInfos.inUse);
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) { for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) {
dPrint("mnode:%d, ip:%s:%u name:%s", tsMnodeInfos.nodeInfos[i].nodeId, taosIpStr(tsMnodeInfos.nodeInfos[i].nodeIp), dPrint("mnode:%d, %s", tsMnodeInfos.nodeInfos[i].nodeId, tsMnodeInfos.nodeInfos[i].nodeEp);
tsMnodeInfos.nodeInfos[i].nodePort, tsMnodeInfos.nodeInfos[i].nodeName);
} }
dnodeSaveMnodeInfos(); dnodeSaveMnodeInfos();
...@@ -291,42 +283,19 @@ static bool dnodeReadMnodeInfos() { ...@@ -291,42 +283,19 @@ static bool dnodeReadMnodeInfos() {
} }
tsMnodeInfos.nodeInfos[i].nodeId = nodeId->valueint; tsMnodeInfos.nodeInfos[i].nodeId = nodeId->valueint;
cJSON *nodeIp = cJSON_GetObjectItem(nodeInfo, "nodeIp"); cJSON *nodeEp = cJSON_GetObjectItem(nodeInfo, "nodeEp");
if (!nodeIp || nodeIp->type != cJSON_String || nodeIp->valuestring == NULL) { if (!nodeEp || nodeEp->type != cJSON_String || nodeEp->valuestring == NULL) {
dError("failed to read mnode mgmtIpList.json, nodeIp not found");
goto PARSE_OVER;
}
tsMnodeInfos.nodeInfos[i].nodeIp = inet_addr(nodeIp->valuestring);
cJSON *nodePort = cJSON_GetObjectItem(nodeInfo, "nodePort");
if (!nodePort || nodePort->type != cJSON_Number) {
dError("failed to read mnode mgmtIpList.json, nodePort not found");
goto PARSE_OVER;
}
tsMnodeInfos.nodeInfos[i].nodePort = (uint16_t)nodePort->valueint;
cJSON *syncPort = cJSON_GetObjectItem(nodeInfo, "syncPort");
if (!syncPort || syncPort->type != cJSON_Number) {
dError("failed to read mnode mgmtIpList.json, syncPort not found");
goto PARSE_OVER;
}
tsMnodeInfos.nodeInfos[i].syncPort = (uint16_t)syncPort->valueint;
cJSON *nodeName = cJSON_GetObjectItem(nodeInfo, "nodeName");
if (!nodeName || nodeName->type != cJSON_String || nodeName->valuestring == NULL) {
dError("failed to read mnode mgmtIpList.json, nodeName not found"); dError("failed to read mnode mgmtIpList.json, nodeName not found");
goto PARSE_OVER; goto PARSE_OVER;
} }
strncpy(tsMnodeInfos.nodeInfos[i].nodeName, nodeName->valuestring, TSDB_NODE_NAME_LEN); strncpy(tsMnodeInfos.nodeInfos[i].nodeEp, nodeEp->valuestring, TSDB_FQDN_LEN);
} }
ret = true; ret = true;
dPrint("read mnode iplist successed, numOfIps:%d inUse:%d", tsMnodeInfos.nodeNum, tsMnodeInfos.inUse); dPrint("read mnode iplist successed, numOfIps:%d inUse:%d", tsMnodeInfos.nodeNum, tsMnodeInfos.inUse);
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) { for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) {
dPrint("mnode:%d, ip:%s:%u name:%s", tsMnodeInfos.nodeInfos[i].nodeId, dPrint("mnode:%d, %s", tsMnodeInfos.nodeInfos[i].nodeId, tsMnodeInfos.nodeInfos[i].nodeEp);
taosIpStr(tsMnodeInfos.nodeInfos[i].nodeIp), tsMnodeInfos.nodeInfos[i].nodePort,
tsMnodeInfos.nodeInfos[i].nodeName);
} }
PARSE_OVER: PARSE_OVER:
...@@ -352,10 +321,7 @@ static void dnodeSaveMnodeInfos() { ...@@ -352,10 +321,7 @@ static void dnodeSaveMnodeInfos() {
len += snprintf(content + len, maxLen - len, " \"nodeInfos\": [{\n"); len += snprintf(content + len, maxLen - len, " \"nodeInfos\": [{\n");
for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) { for (int32_t i = 0; i < tsMnodeInfos.nodeNum; i++) {
len += snprintf(content + len, maxLen - len, " \"nodeId\": %d,\n", tsMnodeInfos.nodeInfos[i].nodeId); len += snprintf(content + len, maxLen - len, " \"nodeId\": %d,\n", tsMnodeInfos.nodeInfos[i].nodeId);
len += snprintf(content + len, maxLen - len, " \"nodeIp\": \"%s\",\n", taosIpStr(tsMnodeInfos.nodeInfos[i].nodeIp)); len += snprintf(content + len, maxLen - len, " \"nodeEp\": \"%s\"\n", tsMnodeInfos.nodeInfos[i].nodeEp);
len += snprintf(content + len, maxLen - len, " \"nodePort\": %u,\n", tsMnodeInfos.nodeInfos[i].nodePort);
len += snprintf(content + len, maxLen - len, " \"syncPort\": %u,\n", tsMnodeInfos.nodeInfos[i].syncPort);
len += snprintf(content + len, maxLen - len, " \"nodeName\": \"%s\"\n", tsMnodeInfos.nodeInfos[i].nodeName);
if (i < tsMnodeInfos.nodeNum -1) { if (i < tsMnodeInfos.nodeNum -1) {
len += snprintf(content + len, maxLen - len, " },{\n"); len += snprintf(content + len, maxLen - len, " },{\n");
} else { } else {
...@@ -371,8 +337,8 @@ static void dnodeSaveMnodeInfos() { ...@@ -371,8 +337,8 @@ static void dnodeSaveMnodeInfos() {
dPrint("save mnode iplist successed"); dPrint("save mnode iplist successed");
} }
uint32_t dnodeGetMnodeMasteIp() { char *dnodeGetMnodeMasterEp() {
return tsMnodeIpSet.ip[tsMnodeIpSet.inUse]; return tsMnodeInfos.nodeInfos[tsMnodeIpSet.inUse].nodeEp;
} }
void* dnodeGetMnodeInfos() { void* dnodeGetMnodeInfos() {
...@@ -402,8 +368,7 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) { ...@@ -402,8 +368,7 @@ static void dnodeSendStatusMsg(void *handle, void *tmrId) {
//strcpy(pStatus->dnodeName, tsDnodeName); //strcpy(pStatus->dnodeName, tsDnodeName);
pStatus->version = htonl(tsVersion); pStatus->version = htonl(tsVersion);
pStatus->dnodeId = htonl(tsDnodeCfg.dnodeId); pStatus->dnodeId = htonl(tsDnodeCfg.dnodeId);
pStatus->privateIp = htonl(inet_addr(tsPrivateIp)); strcpy(pStatus->dnodeEp, tsLocalEp);
pStatus->publicIp = htonl(inet_addr(tsPublicIp));
pStatus->lastReboot = htonl(tsRebootTime); pStatus->lastReboot = htonl(tsRebootTime);
pStatus->numOfTotalVnodes = htons((uint16_t) tsNumOfTotalVnodes); pStatus->numOfTotalVnodes = htons((uint16_t) tsNumOfTotalVnodes);
pStatus->numOfCores = htons((uint16_t) tsNumOfCores); pStatus->numOfCores = htons((uint16_t) tsNumOfCores);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taos.h"
#include "tglobal.h" #include "tglobal.h"
#include "trpc.h" #include "trpc.h"
#include "tutil.h" #include "tutil.h"
...@@ -144,12 +145,12 @@ static int32_t dnodeInitSystem() { ...@@ -144,12 +145,12 @@ static int32_t dnodeInitSystem() {
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
struct stat dirstat; struct stat dirstat;
if (stat(logDir, &dirstat) < 0) { if (stat(tsLogDir, &dirstat) < 0) {
mkdir(logDir, 0755); mkdir(tsLogDir, 0755);
} }
char temp[TSDB_FILENAME_LEN]; char temp[TSDB_FILENAME_LEN];
sprintf(temp, "%s/taosdlog", logDir); sprintf(temp, "%s/taosdlog", tsLogDir);
if (taosInitLog(temp, tsNumOfLogLines, 1) < 0) { if (taosInitLog(temp, tsNumOfLogLines, 1) < 0) {
printf("failed to init log file\n"); printf("failed to init log file\n");
} }
...@@ -161,8 +162,7 @@ static int32_t dnodeInitSystem() { ...@@ -161,8 +162,7 @@ static int32_t dnodeInitSystem() {
} }
taosPrintGlobalCfg(); taosPrintGlobalCfg();
dPrint("Server IP address is:%s", tsPrivateIp); dPrint("start to initialize TDengine on %s", tsLocalEp);
dPrint("starting to initialize TDengine ...");
if (dnodeInitStorage() != 0) return -1; if (dnodeInitStorage() != 0) return -1;
if (dnodeInitRead() != 0) return -1; if (dnodeInitRead() != 0) return -1;
...@@ -191,6 +191,7 @@ static void dnodeCleanUpSystem() { ...@@ -191,6 +191,7 @@ static void dnodeCleanUpSystem() {
dnodeCleanupWrite(); dnodeCleanupWrite();
dnodeCleanupRead(); dnodeCleanupRead();
dnodeCleanUpModules(); dnodeCleanUpModules();
taos_cleanup();
dnodeCleanupStorage(); dnodeCleanupStorage();
taosCloseLog(); taosCloseLog();
} }
...@@ -218,13 +219,13 @@ static void dnodeCheckDataDirOpenned(char *dir) { ...@@ -218,13 +219,13 @@ static void dnodeCheckDataDirOpenned(char *dir) {
static int32_t dnodeInitStorage() { static int32_t dnodeInitStorage() {
struct stat dirstat; struct stat dirstat;
if (stat(dataDir, &dirstat) < 0) { if (stat(tsDataDir, &dirstat) < 0) {
mkdir(dataDir, 0755); mkdir(tsDataDir, 0755);
} }
sprintf(tsMnodeDir, "%s/mnode", dataDir); sprintf(tsMnodeDir, "%s/mnode", tsDataDir);
sprintf(tsVnodeDir, "%s/vnode", dataDir); sprintf(tsVnodeDir, "%s/vnode", tsDataDir);
sprintf(tsDnodeDir, "%s/dnode", dataDir); sprintf(tsDnodeDir, "%s/dnode", tsDataDir);
mkdir(tsVnodeDir, 0755); mkdir(tsVnodeDir, 0755);
mkdir(tsDnodeDir, 0755); mkdir(tsDnodeDir, 0755);
...@@ -237,5 +238,5 @@ static int32_t dnodeInitStorage() { ...@@ -237,5 +238,5 @@ static int32_t dnodeInitStorage() {
static void dnodeCleanupStorage() {} static void dnodeCleanupStorage() {}
bool dnodeIsFirstDeploy() { bool dnodeIsFirstDeploy() {
return strcmp(tsMasterIp, tsPrivateIp) == 0; return strcmp(tsFirst, tsLocalEp) == 0;
} }
...@@ -139,11 +139,9 @@ static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) { ...@@ -139,11 +139,9 @@ static int32_t dnodeProcessCreateVnodeMsg(SRpcMsg *rpcMsg) {
pCreate->cfg.minRowsPerFileBlock = htonl(pCreate->cfg.minRowsPerFileBlock); pCreate->cfg.minRowsPerFileBlock = htonl(pCreate->cfg.minRowsPerFileBlock);
pCreate->cfg.maxRowsPerFileBlock = htonl(pCreate->cfg.maxRowsPerFileBlock); pCreate->cfg.maxRowsPerFileBlock = htonl(pCreate->cfg.maxRowsPerFileBlock);
pCreate->cfg.commitTime = htonl(pCreate->cfg.commitTime); pCreate->cfg.commitTime = htonl(pCreate->cfg.commitTime);
pCreate->cfg.arbitratorIp = htonl(pCreate->cfg.arbitratorIp);
for (int32_t j = 0; j < pCreate->cfg.replications; ++j) { for (int32_t j = 0; j < pCreate->cfg.replications; ++j) {
pCreate->nodes[j].nodeId = htonl(pCreate->nodes[j].nodeId); pCreate->nodes[j].nodeId = htonl(pCreate->nodes[j].nodeId);
pCreate->nodes[j].nodeIp = htonl(pCreate->nodes[j].nodeIp);
} }
void *pVnode = vnodeAccquireVnode(pCreate->cfg.vgId); void *pVnode = vnodeAccquireVnode(pCreate->cfg.vgId);
......
...@@ -38,7 +38,6 @@ int32_t dnodeInitMnode() { ...@@ -38,7 +38,6 @@ int32_t dnodeInitMnode() {
SRpcInit rpcInit; SRpcInit rpcInit;
memset(&rpcInit, 0, sizeof(rpcInit)); memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localIp = tsAnyIp ? "0.0.0.0" : tsPrivateIp;
rpcInit.localPort = tsDnodeMnodePort; rpcInit.localPort = tsDnodeMnodePort;
rpcInit.label = "DND-MS"; rpcInit.label = "DND-MS";
rpcInit.numOfThreads = 1; rpcInit.numOfThreads = 1;
......
...@@ -47,7 +47,6 @@ int32_t dnodeInitShell() { ...@@ -47,7 +47,6 @@ int32_t dnodeInitShell() {
SRpcInit rpcInit; SRpcInit rpcInit;
memset(&rpcInit, 0, sizeof(rpcInit)); memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localIp = tsAnyIp ? "0.0.0.0" : tsPrivateIp;
rpcInit.localPort = tsDnodeShellPort; rpcInit.localPort = tsDnodeShellPort;
rpcInit.label = "DND-shell"; rpcInit.label = "DND-shell";
rpcInit.numOfThreads = numOfThreads; rpcInit.numOfThreads = numOfThreads;
......
...@@ -42,8 +42,8 @@ void dnodeFreeRqueue(void *rqueue); ...@@ -42,8 +42,8 @@ void dnodeFreeRqueue(void *rqueue);
void dnodeSendRpcWriteRsp(void *pVnode, void *param, int32_t code); void dnodeSendRpcWriteRsp(void *pVnode, void *param, int32_t code);
bool dnodeIsFirstDeploy(); bool dnodeIsFirstDeploy();
uint32_t dnodeGetMnodeMasteIp(); char *dnodeGetMnodeMasterEp();
void dnodeGetMnodeIpSet(void *ipSet, bool usePublicIp); void dnodeGetMnodeDnodeIpSet(void *ipSet);
void * dnodeGetMnodeInfos(); void * dnodeGetMnodeInfos();
int32_t dnodeGetDnodeId(); int32_t dnodeGetDnodeId();
......
...@@ -32,6 +32,13 @@ extern "C" { ...@@ -32,6 +32,13 @@ extern "C" {
#define TSKEY int64_t #define TSKEY int64_t
#endif #endif
// ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR
typedef int32_t VarDataOffsetT;
typedef int16_t VarDataLenT;
#define varDataLen(v) ((VarDataLenT *)(v))[0]
#define varDataTLen(v) (sizeof(VarDataLenT) + varDataLen(v))
#define varDataVal(v) ((void *)((char *)v + sizeof(VarDataLenT)))
// this data type is internally used only in 'in' query to hold the values // this data type is internally used only in 'in' query to hold the values
#define TSDB_DATA_TYPE_ARRAY (TSDB_DATA_TYPE_NCHAR + 1) #define TSDB_DATA_TYPE_ARRAY (TSDB_DATA_TYPE_NCHAR + 1)
...@@ -121,6 +128,10 @@ typedef struct tDataTypeDescriptor { ...@@ -121,6 +128,10 @@ typedef struct tDataTypeDescriptor {
int16_t nameLen; int16_t nameLen;
int32_t nSize; int32_t nSize;
char * aName; char * aName;
int (*compFunc)(const char *const input, int inputSize, const int nelements, char *const output, int outputSize,
char algorithm, char *const buffer, int bufferSize);
int (*decompFunc)(const char *const input, int compressedSize, const int nelements, char *const output,
int outputSize, char algorithm, char *const buffer, int bufferSize);
} tDataTypeDescriptor; } tDataTypeDescriptor;
extern tDataTypeDescriptor tDataTypeDesc[11]; extern tDataTypeDescriptor tDataTypeDesc[11];
...@@ -187,11 +198,10 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); ...@@ -187,11 +198,10 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
#define TSDB_CITY_LEN 20 #define TSDB_CITY_LEN 20
#define TSDB_STATE_LEN 20 #define TSDB_STATE_LEN 20
#define TSDB_COUNTRY_LEN 20 #define TSDB_COUNTRY_LEN 20
#define TSDB_VNODES_SUPPORT 6
#define TSDB_MGMT_SUPPORT 4
#define TSDB_LOCALE_LEN 64 #define TSDB_LOCALE_LEN 64
#define TSDB_TIMEZONE_LEN 64 #define TSDB_TIMEZONE_LEN 64
#define TSDB_FQDN_LEN 72
#define TSDB_IPv4ADDR_LEN 16 #define TSDB_IPv4ADDR_LEN 16
#define TSDB_FILENAME_LEN 128 #define TSDB_FILENAME_LEN 128
#define TSDB_METER_VNODE_BITS 20 #define TSDB_METER_VNODE_BITS 20
...@@ -218,8 +228,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); ...@@ -218,8 +228,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
#define TSDB_DNODE_ROLE_MGMT 1 #define TSDB_DNODE_ROLE_MGMT 1
#define TSDB_DNODE_ROLE_VNODE 2 #define TSDB_DNODE_ROLE_VNODE 2
#define TSDB_MAX_MPEERS 5 #define TSDB_MAX_REPLICA 5
#define TSDB_MAX_MGMT_IPS (TSDB_MAX_MPEERS+1)
#define TSDB_TBNAME_COLUMN_INDEX (-1) #define TSDB_TBNAME_COLUMN_INDEX (-1)
#define TSDB_MULTI_METERMETA_MAX_NUM 100000 // maximum batch size allowed to load metermeta #define TSDB_MULTI_METERMETA_MAX_NUM 100000 // maximum batch size allowed to load metermeta
...@@ -320,6 +329,12 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); ...@@ -320,6 +329,12 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
#define TSDB_MAX_NORMAL_TABLES 1000 #define TSDB_MAX_NORMAL_TABLES 1000
#define TSDB_MAX_CHILD_TABLES 100000 #define TSDB_MAX_CHILD_TABLES 100000
#define TSDB_PORT_MNODESHELL 0
#define TSDB_PORT_DNODESHELL 5
#define TSDB_PORT_DNODEMNODE 10
#define TSDB_PORT_MNODEDNODE 15
#define TSDB_PORT_SYNC 20
typedef enum { typedef enum {
TSDB_PRECISION_MILLI, TSDB_PRECISION_MILLI,
TSDB_PRECISION_MICRO, TSDB_PRECISION_MICRO,
......
...@@ -187,7 +187,7 @@ extern char *taosMsg[]; ...@@ -187,7 +187,7 @@ extern char *taosMsg[];
#pragma pack(push, 1) #pragma pack(push, 1)
typedef struct { typedef struct {
uint32_t ip; char fqdn[TSDB_FQDN_LEN];
uint16_t port; uint16_t port;
} SIpAddr; } SIpAddr;
...@@ -265,6 +265,7 @@ typedef struct { ...@@ -265,6 +265,7 @@ typedef struct {
char tableId[TSDB_TABLE_ID_LEN + 1]; char tableId[TSDB_TABLE_ID_LEN + 1];
char db[TSDB_DB_NAME_LEN + 1]; char db[TSDB_DB_NAME_LEN + 1];
int8_t igExists; int8_t igExists;
int8_t getMeta;
int16_t numOfTags; int16_t numOfTags;
int16_t numOfColumns; int16_t numOfColumns;
int16_t sqlLen; // the length of SQL, it starts after schema , sql is a null-terminated string int16_t sqlLen; // the length of SQL, it starts after schema , sql is a null-terminated string
...@@ -549,24 +550,19 @@ typedef struct { ...@@ -549,24 +550,19 @@ typedef struct {
typedef struct { typedef struct {
int32_t nodeId; int32_t nodeId;
uint32_t nodeIp; char nodeEp[TSDB_FQDN_LEN];
uint16_t nodePort;
uint16_t syncPort;
char nodeName[TSDB_NODE_NAME_LEN + 1];
} SDMMnodeInfo; } SDMMnodeInfo;
typedef struct { typedef struct {
int8_t inUse; int8_t inUse;
int8_t nodeNum; int8_t nodeNum;
SDMMnodeInfo nodeInfos[TSDB_MAX_MPEERS]; SDMMnodeInfo nodeInfos[TSDB_MAX_REPLICA];
} SDMMnodeInfos; } SDMMnodeInfos;
typedef struct { typedef struct {
uint32_t version; uint32_t version;
int32_t dnodeId; int32_t dnodeId;
char dnodeName[TSDB_NODE_NAME_LEN + 1]; char dnodeEp[TSDB_FQDN_LEN];
uint32_t privateIp;
uint32_t publicIp;
uint32_t moduleStatus; uint32_t moduleStatus;
uint32_t lastReboot; // time stamp for last reboot uint32_t lastReboot; // time stamp for last reboot
uint16_t numOfTotalVnodes; // from config file uint16_t numOfTotalVnodes; // from config file
...@@ -603,19 +599,17 @@ typedef struct { ...@@ -603,19 +599,17 @@ typedef struct {
int8_t replications; int8_t replications;
int8_t wals; int8_t wals;
int8_t quorum; int8_t quorum;
uint32_t arbitratorIp;
int8_t reserved[16]; int8_t reserved[16];
} SMDVnodeCfg; } SMDVnodeCfg;
typedef struct { typedef struct {
int32_t nodeId; int32_t nodeId;
uint32_t nodeIp; char nodeEp[TSDB_FQDN_LEN];
char nodeName[TSDB_NODE_NAME_LEN + 1];
} SMDVnodeDesc; } SMDVnodeDesc;
typedef struct { typedef struct {
SMDVnodeCfg cfg; SMDVnodeCfg cfg;
SMDVnodeDesc nodes[TSDB_MAX_MPEERS]; SMDVnodeDesc nodes[TSDB_MAX_REPLICA];
} SMDCreateVnodeMsg; } SMDCreateVnodeMsg;
typedef struct { typedef struct {
...@@ -738,7 +732,7 @@ typedef struct SCMShowRsp { ...@@ -738,7 +732,7 @@ typedef struct SCMShowRsp {
} SCMShowRsp; } SCMShowRsp;
typedef struct { typedef struct {
char ip[32]; char ep[TSDB_FQDN_LEN]; // end point, hostname:port
} SCMCreateDnodeMsg, SCMDropDnodeMsg; } SCMCreateDnodeMsg, SCMDropDnodeMsg;
typedef struct { typedef struct {
...@@ -753,7 +747,7 @@ typedef struct { ...@@ -753,7 +747,7 @@ typedef struct {
} SDMConfigVnodeMsg; } SDMConfigVnodeMsg;
typedef struct { typedef struct {
char ip[32]; char ep[TSDB_FQDN_LEN]; // end point, hostname:port
char config[64]; char config[64];
} SMDCfgDnodeMsg, SCMCfgDnodeMsg; } SMDCfgDnodeMsg, SCMCfgDnodeMsg;
......
...@@ -31,8 +31,8 @@ extern int tsRpcHeadSize; ...@@ -31,8 +31,8 @@ extern int tsRpcHeadSize;
typedef struct { typedef struct {
int8_t inUse; int8_t inUse;
int8_t numOfIps; int8_t numOfIps;
uint16_t port; uint16_t port[TSDB_MAX_REPLICA];
uint32_t ip[TSDB_MAX_MPEERS]; char fqdn[TSDB_MAX_REPLICA][TSDB_FQDN_LEN];
} SRpcIpSet; } SRpcIpSet;
typedef struct { typedef struct {
...@@ -51,7 +51,6 @@ typedef struct { ...@@ -51,7 +51,6 @@ typedef struct {
} SRpcMsg; } SRpcMsg;
typedef struct { typedef struct {
char *localIp; // local IP used
uint16_t localPort; // local port uint16_t localPort; // local port
char *label; // for debug purpose char *label; // for debug purpose
int numOfThreads; // number of threads to handle connections int numOfThreads; // number of threads to handle connections
......
...@@ -107,6 +107,7 @@ int32_t tsdbTableGetName(TsdbRepoT *repo, STableId id, char** name); ...@@ -107,6 +107,7 @@ int32_t tsdbTableGetName(TsdbRepoT *repo, STableId id, char** name);
int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg); int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg);
int tsdbDropTable(TsdbRepoT *pRepo, STableId tableId); int tsdbDropTable(TsdbRepoT *pRepo, STableId tableId);
int tsdbAlterTable(TsdbRepoT *repo, STableCfg *pCfg); int tsdbAlterTable(TsdbRepoT *repo, STableCfg *pCfg);
TSKEY tsdbGetTableLastKey(TsdbRepoT *repo, int64_t uid);
// the TSDB repository info // the TSDB repository info
typedef struct STsdbRepoInfo { typedef struct STsdbRepoInfo {
......
...@@ -38,12 +38,11 @@ typedef enum _TAOS_SYNC_STATUS { ...@@ -38,12 +38,11 @@ typedef enum _TAOS_SYNC_STATUS {
typedef struct { typedef struct {
uint32_t nodeId; // node ID assigned by TDengine uint32_t nodeId; // node ID assigned by TDengine
uint32_t nodeIp; // node IP address uint16_t nodePort; // node sync Port
char name[TSDB_FILENAME_LEN]; // external node name char nodeFqdn[TSDB_FQDN_LEN]; // node FQDN
} SNodeInfo; } SNodeInfo;
typedef struct { typedef struct {
uint32_t arbitratorIp; // arbitrator IP address
int8_t quorum; // number of confirms required, >=1 int8_t quorum; // number of confirms required, >=1
int8_t replica; // number of replications, >=1 int8_t replica; // number of replications, >=1
SNodeInfo nodeInfo[TAOS_SYNC_MAX_REPLICA]; SNodeInfo nodeInfo[TAOS_SYNC_MAX_REPLICA];
...@@ -107,6 +106,7 @@ extern int tsMaxWatchFiles; ...@@ -107,6 +106,7 @@ extern int tsMaxWatchFiles;
extern int tsSyncTimer; extern int tsSyncTimer;
extern int tsMaxFwdInfo; extern int tsMaxFwdInfo;
extern int sDebugFlag; extern int sDebugFlag;
extern char tsArbitrator[];
extern uint16_t tsSyncPort; extern uint16_t tsSyncPort;
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -40,7 +40,7 @@ History history; ...@@ -40,7 +40,7 @@ History history;
*/ */
TAOS *shellInit(struct arguments *args) { TAOS *shellInit(struct arguments *args) {
printf("\n"); printf("\n");
printf(CLIENT_VERSION, osName, taos_get_client_info()); printf(CLIENT_VERSION, tsOsName, taos_get_client_info());
fflush(stdout); fflush(stdout);
// set options before initializing // set options before initializing
......
...@@ -32,6 +32,7 @@ int32_t mgmtInitDbs(); ...@@ -32,6 +32,7 @@ int32_t mgmtInitDbs();
void mgmtCleanUpDbs(); void mgmtCleanUpDbs();
SDbObj *mgmtGetDb(char *db); SDbObj *mgmtGetDb(char *db);
SDbObj *mgmtGetDbByTableId(char *db); SDbObj *mgmtGetDbByTableId(char *db);
void * mgmtGetNextDb(void *pNode, SDbObj **pDb);
void mgmtIncDbRef(SDbObj *pDb); void mgmtIncDbRef(SDbObj *pDb);
void mgmtDecDbRef(SDbObj *pDb); void mgmtDecDbRef(SDbObj *pDb);
bool mgmtCheckIsMonitorDB(char *db, char *monitordb); bool mgmtCheckIsMonitorDB(char *db, char *monitordb);
......
...@@ -31,13 +31,9 @@ struct SMnodeObj; ...@@ -31,13 +31,9 @@ struct SMnodeObj;
typedef struct SDnodeObj { typedef struct SDnodeObj {
int32_t dnodeId; int32_t dnodeId;
uint32_t privateIp; uint16_t dnodePort;
uint32_t publicIp; char dnodeFqdn[TSDB_FQDN_LEN];
uint16_t mnodeShellPort; char dnodeEp[TSDB_FQDN_LEN];
uint16_t mnodeDnodePort;
uint16_t dnodeShellPort;
uint16_t dnodeMnodePort;
uint16_t syncPort;
int64_t createdTime; int64_t createdTime;
uint32_t lastAccess; uint32_t lastAccess;
int32_t openVnodes; int32_t openVnodes;
...@@ -47,7 +43,6 @@ typedef struct SDnodeObj { ...@@ -47,7 +43,6 @@ typedef struct SDnodeObj {
int8_t alternativeRole; // from dnode status msg, 0-any, 1-mgmt, 2-dnode int8_t alternativeRole; // from dnode status msg, 0-any, 1-mgmt, 2-dnode
int8_t status; // set in balance function int8_t status; // set in balance function
int8_t isMgmt; int8_t isMgmt;
char dnodeName[TSDB_NODE_NAME_LEN + 1];
int8_t reserved[15]; int8_t reserved[15];
int8_t updateEnd[1]; int8_t updateEnd[1];
int32_t refCount; int32_t refCount;
...@@ -123,7 +118,7 @@ typedef struct SVgObj { ...@@ -123,7 +118,7 @@ typedef struct SVgObj {
uint32_t vgId; uint32_t vgId;
char dbName[TSDB_DB_NAME_LEN + 1]; char dbName[TSDB_DB_NAME_LEN + 1];
int64_t createdTime; int64_t createdTime;
SVnodeGid vnodeGid[TSDB_VNODES_SUPPORT]; SVnodeGid vnodeGid[TSDB_MAX_REPLICA];
int32_t numOfVnodes; int32_t numOfVnodes;
int32_t lbDnodeId; int32_t lbDnodeId;
int32_t lbTime; int32_t lbTime;
...@@ -242,7 +237,6 @@ typedef struct { ...@@ -242,7 +237,6 @@ typedef struct {
typedef struct { typedef struct {
uint8_t msgType; uint8_t msgType;
int8_t usePublicIp;
int8_t received; int8_t received;
int8_t successed; int8_t successed;
int8_t expected; int8_t expected;
......
...@@ -38,7 +38,7 @@ void * mgmtGetNextDnode(void *pNode, SDnodeObj **pDnode); ...@@ -38,7 +38,7 @@ void * mgmtGetNextDnode(void *pNode, SDnodeObj **pDnode);
void mgmtIncDnodeRef(SDnodeObj *pDnode); void mgmtIncDnodeRef(SDnodeObj *pDnode);
void mgmtDecDnodeRef(SDnodeObj *pDnode); void mgmtDecDnodeRef(SDnodeObj *pDnode);
void * mgmtGetDnode(int32_t dnodeId); void * mgmtGetDnode(int32_t dnodeId);
void * mgmtGetDnodeByIp(uint32_t ip); void * mgmtGetDnodeByIp(char *ep);
void mgmtUpdateDnode(SDnodeObj *pDnode); void mgmtUpdateDnode(SDnodeObj *pDnode);
int32_t mgmtDropDnode(SDnodeObj *pDnode); int32_t mgmtDropDnode(SDnodeObj *pDnode);
......
...@@ -33,16 +33,19 @@ void mgmtCleanupMnodes(); ...@@ -33,16 +33,19 @@ void mgmtCleanupMnodes();
int32_t mgmtAddMnode(int32_t dnodeId); int32_t mgmtAddMnode(int32_t dnodeId);
int32_t mgmtDropMnode(int32_t dnodeId); int32_t mgmtDropMnode(int32_t dnodeId);
void mgmtDropMnodeLocal(int32_t dnodeId);
void * mgmtGetMnode(int32_t mnodeId); void * mgmtGetMnode(int32_t mnodeId);
int32_t mgmtGetMnodesNum(); int32_t mgmtGetMnodesNum();
void * mgmtGetNextMnode(void *pNode, struct SMnodeObj **pMnode); void * mgmtGetNextMnode(void *pNode, struct SMnodeObj **pMnode);
void mgmtReleaseMnode(struct SMnodeObj *pMnode); void mgmtIncMnodeRef(struct SMnodeObj *pMnode);
void mgmtDecMnodeRef(struct SMnodeObj *pMnode);
char * mgmtGetMnodeRoleStr(); char * mgmtGetMnodeRoleStr();
void mgmtGetMnodeIpSet(SRpcIpSet *ipSet, bool usePublicIp); void mgmtGetMnodeIpSet(SRpcIpSet *ipSet);
void mgmtGetMnodeInfos(void *mnodes); void mgmtGetMnodeInfos(void *mnodes);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -24,14 +24,6 @@ extern "C" { ...@@ -24,14 +24,6 @@ extern "C" {
int32_t mgmtInitProfile(); int32_t mgmtInitProfile();
void mgmtCleanUpProfile(); void mgmtCleanUpProfile();
bool mgmtCheckQhandle(uint64_t qhandle);
void mgmtSaveQhandle(void *qhandle);
void mgmtFreeQhandle(void *qhandle);
void * mgmtMallocQueuedMsg(SRpcMsg *rpcMsg);
void * mgmtCloneQueuedMsg(SQueuedMsg *pSrcMsg);
void mgmtFreeQueuedMsg(SQueuedMsg *pMsg);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -72,6 +72,7 @@ void sdbCleanUp(); ...@@ -72,6 +72,7 @@ void sdbCleanUp();
void * sdbOpenTable(SSdbTableDesc *desc); void * sdbOpenTable(SSdbTableDesc *desc);
void sdbCloseTable(void *handle); void sdbCloseTable(void *handle);
bool sdbIsMaster(); bool sdbIsMaster();
bool sdbIsServing();
void sdbUpdateMnodeRoles(); void sdbUpdateMnodeRoles();
int32_t sdbInsertRow(SSdbOper *pOper); int32_t sdbInsertRow(SSdbOper *pOper);
......
...@@ -34,6 +34,14 @@ void mgmtAddToShellQueue(SQueuedMsg *queuedMsg); ...@@ -34,6 +34,14 @@ void mgmtAddToShellQueue(SQueuedMsg *queuedMsg);
void mgmtDealyedAddToShellQueue(SQueuedMsg *queuedMsg); void mgmtDealyedAddToShellQueue(SQueuedMsg *queuedMsg);
void mgmtSendSimpleResp(void *thandle, int32_t code); void mgmtSendSimpleResp(void *thandle, int32_t code);
bool mgmtCheckQhandle(uint64_t qhandle);
void *mgmtSaveQhandle(void *qhandle, int32_t size);
void mgmtFreeQhandle(void *qhandle, bool forceRemove);
void *mgmtMallocQueuedMsg(SRpcMsg *rpcMsg);
void *mgmtCloneQueuedMsg(SQueuedMsg *pSrcMsg);
void mgmtFreeQueuedMsg(SQueuedMsg *pMsg);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -24,9 +24,11 @@ extern "C" { ...@@ -24,9 +24,11 @@ extern "C" {
int32_t mgmtInitTables(); int32_t mgmtInitTables();
void mgmtCleanUpTables(); void mgmtCleanUpTables();
STableObj* mgmtGetTable(char* tableId); void * mgmtGetTable(char *tableId);
void mgmtIncTableRef(void *pTable); void mgmtIncTableRef(void *pTable);
void mgmtDecTableRef(void *pTable); void mgmtDecTableRef(void *pTable);
void * mgmtGetNextChildTable(void *pNode, SChildTableObj **pTable);
void * mgmtGetNextSuperTable(void *pNode, SSuperTableObj **pTable);
void mgmtDropAllChildTables(SDbObj *pDropDb); void mgmtDropAllChildTables(SDbObj *pDropDb);
void mgmtDropAllSuperTables(SDbObj *pDropDb); void mgmtDropAllSuperTables(SDbObj *pDropDb);
......
...@@ -27,7 +27,7 @@ SUserObj *mgmtGetUser(char *name); ...@@ -27,7 +27,7 @@ SUserObj *mgmtGetUser(char *name);
void * mgmtGetNextUser(void *pNode, SUserObj **pUser); void * mgmtGetNextUser(void *pNode, SUserObj **pUser);
void mgmtIncUserRef(SUserObj *pUser); void mgmtIncUserRef(SUserObj *pUser);
void mgmtDecUserRef(SUserObj *pUser); void mgmtDecUserRef(SUserObj *pUser);
SUserObj *mgmtGetUserFromConn(void *pConn, bool *usePublicIp); SUserObj *mgmtGetUserFromConn(void *pConn);
int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass); int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass);
void mgmtDropAllUsers(SAcctObj *pAcct); void mgmtDropAllUsers(SAcctObj *pAcct);
......
...@@ -32,7 +32,8 @@ void mgmtCleanUpVgroups(); ...@@ -32,7 +32,8 @@ void mgmtCleanUpVgroups();
SVgObj *mgmtGetVgroup(int32_t vgId); SVgObj *mgmtGetVgroup(int32_t vgId);
void mgmtIncVgroupRef(SVgObj *pVgroup); void mgmtIncVgroupRef(SVgObj *pVgroup);
void mgmtDecVgroupRef(SVgObj *pVgroup); void mgmtDecVgroupRef(SVgObj *pVgroup);
void mgmtDropAllVgroups(SDbObj *pDropDb); void mgmtDropAllDbVgroups(SDbObj *pDropDb);
void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode);
void * mgmtGetNextVgroup(void *pNode, SVgObj **pVgroup); void * mgmtGetNextVgroup(void *pNode, SVgObj **pVgroup);
void mgmtUpdateVgroup(SVgObj *pVgroup); void mgmtUpdateVgroup(SVgObj *pVgroup);
...@@ -50,7 +51,7 @@ void mgmtSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle); ...@@ -50,7 +51,7 @@ void mgmtSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle);
void mgmtSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle); void mgmtSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle);
SRpcIpSet mgmtGetIpSetFromVgroup(SVgObj *pVgroup); SRpcIpSet mgmtGetIpSetFromVgroup(SVgObj *pVgroup);
SRpcIpSet mgmtGetIpSetFromIp(uint32_t ip); SRpcIpSet mgmtGetIpSetFromIp(char *ep);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "mgmtUser.h" #include "mgmtUser.h"
void * tsAcctSdb = NULL; void * tsAcctSdb = NULL;
int32_t tsAcctUpdateSize; static int32_t tsAcctUpdateSize;
static void mgmtCreateRootAcct(); static void mgmtCreateRootAcct();
static int32_t mgmtActionAcctDestroy(SSdbOper *pOper) { static int32_t mgmtActionAcctDestroy(SSdbOper *pOper) {
......
...@@ -35,7 +35,7 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) { ...@@ -35,7 +35,7 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
void * pNode = NULL; void * pNode = NULL;
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
SDnodeObj *pSelDnode = NULL; SDnodeObj *pSelDnode = NULL;
float vnodeUsage = 1.0; float vnodeUsage = 1000.0;
while (1) { while (1) {
pNode = mgmtGetNextDnode(pNode, &pDnode); pNode = mgmtGetNextDnode(pNode, &pDnode);
......
...@@ -38,7 +38,6 @@ static void *tsMgmtDClientRpc = NULL; ...@@ -38,7 +38,6 @@ static void *tsMgmtDClientRpc = NULL;
int32_t mgmtInitDClient() { int32_t mgmtInitDClient() {
SRpcInit rpcInit = {0}; SRpcInit rpcInit = {0};
rpcInit.localIp = tsAnyIp ? "0.0.0.0" : tsPrivateIp;
rpcInit.localPort = 0; rpcInit.localPort = 0;
rpcInit.label = "MND-DC"; rpcInit.label = "MND-DC";
rpcInit.numOfThreads = 1; rpcInit.numOfThreads = 1;
......
...@@ -43,7 +43,6 @@ static void *tsMgmtDServerQhandle = NULL; ...@@ -43,7 +43,6 @@ static void *tsMgmtDServerQhandle = NULL;
int32_t mgmtInitDServer() { int32_t mgmtInitDServer() {
SRpcInit rpcInit = {0}; SRpcInit rpcInit = {0};
rpcInit.localIp = tsAnyIp ? "0.0.0.0" : tsPrivateIp;;
rpcInit.localPort = tsMnodeDnodePort; rpcInit.localPort = tsMnodeDnodePort;
rpcInit.label = "MND-DS"; rpcInit.label = "MND-DS";
rpcInit.numOfThreads = 1; rpcInit.numOfThreads = 1;
...@@ -105,14 +104,13 @@ static void mgmtProcessMsgFromDnode(SRpcMsg *rpcMsg) { ...@@ -105,14 +104,13 @@ static void mgmtProcessMsgFromDnode(SRpcMsg *rpcMsg) {
if (!sdbIsMaster()) { if (!sdbIsMaster()) {
SRpcConnInfo connInfo; SRpcConnInfo connInfo;
rpcGetConnInfo(rpcMsg->handle, &connInfo); rpcGetConnInfo(rpcMsg->handle, &connInfo);
bool usePublicIp = false;
SRpcIpSet ipSet = {0}; SRpcIpSet ipSet = {0};
ipSet.port = tsMnodeDnodePort; dnodeGetMnodeDnodeIpSet(&ipSet);
dnodeGetMnodeIpSet(&ipSet, usePublicIp);
mTrace("conn from dnode ip:%s user:%s redirect msg, inUse:%d", taosIpStr(connInfo.clientIp), connInfo.user, ipSet.inUse); mTrace("conn from dnode ip:%s user:%s redirect msg, inUse:%d", taosIpStr(connInfo.clientIp), connInfo.user, ipSet.inUse);
for (int32_t i = 0; i < ipSet.numOfIps; ++i) { for (int32_t i = 0; i < ipSet.numOfIps; ++i) {
mTrace("index:%d ip:%s", i, taosIpStr(ipSet.ip[i])); mTrace("index:%d %s:%d", i, ipSet.fqdn[i], ipSet.port[i]);
} }
rpcSendRedirectRsp(rpcMsg->handle, &ipSet); rpcSendRedirectRsp(rpcMsg->handle, &ipSet);
return; return;
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include "mgmtUser.h" #include "mgmtUser.h"
#include "mgmtVgroup.h" #include "mgmtVgroup.h"
void * tsDbSdb = NULL; static void * tsDbSdb = NULL;
static int32_t tsDbUpdateSize; static int32_t tsDbUpdateSize;
static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate); static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate);
...@@ -82,7 +82,7 @@ static int32_t mgmtDbActionDelete(SSdbOper *pOper) { ...@@ -82,7 +82,7 @@ static int32_t mgmtDbActionDelete(SSdbOper *pOper) {
mgmtDropDbFromAcct(pAcct, pDb); mgmtDropDbFromAcct(pAcct, pDb);
mgmtDropAllChildTables(pDb); mgmtDropAllChildTables(pDb);
mgmtDropAllSuperTables(pDb); mgmtDropAllSuperTables(pDb);
mgmtDropAllVgroups(pDb); mgmtDropAllDbVgroups(pDb);
mgmtDecAcctRef(pAcct); mgmtDecAcctRef(pAcct);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -95,6 +95,7 @@ static int32_t mgmtDbActionUpdate(SSdbOper *pOper) { ...@@ -95,6 +95,7 @@ static int32_t mgmtDbActionUpdate(SSdbOper *pOper) {
memcpy(pSaved, pDb, pOper->rowSize); memcpy(pSaved, pDb, pOper->rowSize);
free(pDb); free(pDb);
} }
mgmtDecDbRef(pSaved);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -154,6 +155,10 @@ int32_t mgmtInitDbs() { ...@@ -154,6 +155,10 @@ int32_t mgmtInitDbs() {
return 0; return 0;
} }
void *mgmtGetNextDb(void *pNode, SDbObj **pDb) {
return sdbFetchRow(tsDbSdb, pNode, (void **)pDb);
}
SDbObj *mgmtGetDb(char *db) { SDbObj *mgmtGetDb(char *db) {
return (SDbObj *)sdbGetRow(tsDbSdb, db); return (SDbObj *)sdbGetRow(tsDbSdb, db);
} }
...@@ -174,7 +179,7 @@ SDbObj *mgmtGetDbByTableId(char *tableId) { ...@@ -174,7 +179,7 @@ SDbObj *mgmtGetDbByTableId(char *tableId) {
memset(db, 0, sizeof(db)); memset(db, 0, sizeof(db));
strncpy(db, tableId, pos - tableId); strncpy(db, tableId, pos - tableId);
return (SDbObj *)sdbGetRow(tsDbSdb, db); return mgmtGetDb(db);
} }
static int32_t mgmtCheckDbCfg(SDbCfg *pCfg) { static int32_t mgmtCheckDbCfg(SDbCfg *pCfg) {
...@@ -346,8 +351,27 @@ bool mgmtCheckIsMonitorDB(char *db, char *monitordb) { ...@@ -346,8 +351,27 @@ bool mgmtCheckIsMonitorDB(char *db, char *monitordb) {
return (strncasecmp(dbName, monitordb, len) == 0 && len == strlen(monitordb)); return (strncasecmp(dbName, monitordb, len) == 0 && len == strlen(monitordb));
} }
#if 0
void mgmtPrintVgroups(SDbObj *pDb, char *oper) {
mPrint("db:%s, vgroup link from head, oper:%s", pDb->name, oper);
SVgObj *pVgroup = pDb->pHead;
while (pVgroup != NULL) {
mPrint("vgId:%d", pVgroup->vgId);
pVgroup = pVgroup->next;
}
mPrint("db:%s, vgroup link from tail", pDb->name, pDb->numOfVgroups);
pVgroup = pDb->pTail;
while (pVgroup != NULL) {
mPrint("vgId:%d", pVgroup->vgId);
pVgroup = pVgroup->prev;
}
}
#endif
void mgmtAddVgroupIntoDb(SVgObj *pVgroup) { void mgmtAddVgroupIntoDb(SVgObj *pVgroup) {
SDbObj *pDb = pVgroup->pDb; SDbObj *pDb = pVgroup->pDb;
pVgroup->next = pDb->pHead; pVgroup->next = pDb->pHead;
pVgroup->prev = NULL; pVgroup->prev = NULL;
...@@ -397,7 +421,7 @@ static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) ...@@ -397,7 +421,7 @@ static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn)
int32_t cols = 0; int32_t cols = 0;
SSchema *pSchema = pMeta->schema; SSchema *pSchema = pMeta->schema;
SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); SUserObj *pUser = mgmtGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
pShow->bytes[cols] = TSDB_DB_NAME_LEN; pShow->bytes[cols] = TSDB_DB_NAME_LEN;
...@@ -545,11 +569,11 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void * ...@@ -545,11 +569,11 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *
SDbObj *pDb = NULL; SDbObj *pDb = NULL;
char * pWrite; char * pWrite;
int32_t cols = 0; int32_t cols = 0;
SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); SUserObj *pUser = mgmtGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
while (numOfRows < rows) { while (numOfRows < rows) {
pShow->pNode = sdbFetchRow(tsDbSdb, pShow->pNode, (void **) &pDb); pShow->pNode = mgmtGetNextDb(pShow->pNode, &pDb);
if (pDb == NULL) break; if (pDb == NULL) break;
cols = 0; cols = 0;
...@@ -674,8 +698,7 @@ static int32_t mgmtSetDbDropping(SDbObj *pDb) { ...@@ -674,8 +698,7 @@ static int32_t mgmtSetDbDropping(SDbObj *pDb) {
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
.table = tsDbSdb, .table = tsDbSdb,
.pObj = pDb, .pObj = pDb
.rowSize = tsDbUpdateSize
}; };
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
...@@ -770,11 +793,17 @@ static SDbCfg mgmtGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { ...@@ -770,11 +793,17 @@ static SDbCfg mgmtGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
mTrace("db:%s, replications:%d change to %d", pDb->name, pDb->cfg.replications, replications); mTrace("db:%s, replications:%d change to %d", pDb->name, pDb->cfg.replications, replications);
newCfg.replications = replications; newCfg.replications = replications;
} }
if (replications > mgmtGetDnodesNum()) { if (replications > mgmtGetDnodesNum()) {
mError("db:%s, no enough dnode to change replica:%d", pDb->name, replications); mError("db:%s, no enough dnode to change replica:%d", pDb->name, replications);
terrno = TSDB_CODE_NO_ENOUGH_DNODES; terrno = TSDB_CODE_NO_ENOUGH_DNODES;
} }
if (pDb->cfg.replications - replications >= 2) {
mError("db:%s, replica number can't change from 3 to 1", pDb->name, replications);
terrno = TSDB_CODE_INVALID_OPTION;
}
return newCfg; return newCfg;
} }
...@@ -797,8 +826,7 @@ static int32_t mgmtAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) { ...@@ -797,8 +826,7 @@ static int32_t mgmtAlterDb(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
.table = tsDbSdb, .table = tsDbSdb,
.pObj = pDb, .pObj = pDb
.rowSize = tsDbUpdateSize
}; };
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
...@@ -833,21 +861,21 @@ static void mgmtProcessAlterDbMsg(SQueuedMsg *pMsg) { ...@@ -833,21 +861,21 @@ static void mgmtProcessAlterDbMsg(SQueuedMsg *pMsg) {
return; return;
} }
SDbObj *pDb = pMsg->pDb = mgmtGetDb(pAlter->db); if (pMsg->pDb == NULL) pMsg->pDb = mgmtGetDb(pAlter->db);
if (pDb == NULL) { if (pMsg->pDb == NULL) {
mError("db:%s, failed to alter, invalid db", pAlter->db); mError("db:%s, failed to alter, invalid db", pAlter->db);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_DB); mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_INVALID_DB);
return; return;
} }
int32_t code = mgmtAlterDb(pDb, pAlter); int32_t code = mgmtAlterDb(pMsg->pDb, pAlter);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
mError("db:%s, failed to alter, invalid db option", pAlter->db); mError("db:%s, failed to alter, invalid db option", pAlter->db);
mgmtSendSimpleResp(pMsg->thandle, code); mgmtSendSimpleResp(pMsg->thandle, code);
return; return;
} }
mTrace("db:%s, all vgroups is altered", pDb->name); mTrace("db:%s, all vgroups is altered", pMsg->pDb->name);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SUCCESS); mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SUCCESS);
} }
...@@ -878,8 +906,8 @@ static void mgmtProcessDropDbMsg(SQueuedMsg *pMsg) { ...@@ -878,8 +906,8 @@ static void mgmtProcessDropDbMsg(SQueuedMsg *pMsg) {
return; return;
} }
SDbObj *pDb = pMsg->pDb = mgmtGetDb(pDrop->db); if (pMsg->pDb == NULL) pMsg->pDb = mgmtGetDb(pDrop->db);
if (pDb == NULL) { if (pMsg->pDb == NULL) {
if (pDrop->ignoreNotExists) { if (pDrop->ignoreNotExists) {
mTrace("db:%s, db is not exist, think drop success", pDrop->db); mTrace("db:%s, db is not exist, think drop success", pDrop->db);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SUCCESS); mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_SUCCESS);
...@@ -891,30 +919,32 @@ static void mgmtProcessDropDbMsg(SQueuedMsg *pMsg) { ...@@ -891,30 +919,32 @@ static void mgmtProcessDropDbMsg(SQueuedMsg *pMsg) {
} }
} }
if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) { if (mgmtCheckIsMonitorDB(pMsg->pDb->name, tsMonitorDbName)) {
mError("db:%s, can't drop monitor database", pDrop->db); mError("db:%s, can't drop monitor database", pDrop->db);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_MONITOR_DB_FORBIDDEN); mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_MONITOR_DB_FORBIDDEN);
return; return;
} }
int32_t code = mgmtSetDbDropping(pDb); int32_t code = mgmtSetDbDropping(pMsg->pDb);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
mError("db:%s, failed to drop, reason:%s", pDrop->db, tstrerror(code)); mError("db:%s, failed to drop, reason:%s", pDrop->db, tstrerror(code));
mgmtSendSimpleResp(pMsg->thandle, code); mgmtSendSimpleResp(pMsg->thandle, code);
return; return;
} }
SVgObj *pVgroup = pDb->pHead; #if 0
SVgObj *pVgroup = pMsg->pDb->pHead;
if (pVgroup != NULL) { if (pVgroup != NULL) {
mPrint("vgroup:%d, will be dropped", pVgroup->vgId); mPrint("vgId:%d, will be dropped", pVgroup->vgId);
SQueuedMsg *newMsg = mgmtCloneQueuedMsg(pMsg); SQueuedMsg *newMsg = mgmtCloneQueuedMsg(pMsg);
newMsg->ahandle = pVgroup; newMsg->ahandle = pVgroup;
newMsg->expected = pVgroup->numOfVnodes; newMsg->expected = pVgroup->numOfVnodes;
mgmtDropVgroup(pVgroup, newMsg); mgmtDropVgroup(pVgroup, newMsg);
return; return;
} }
#endif
mTrace("db:%s, all vgroups is dropped", pDb->name); mTrace("db:%s, all vgroups is dropped", pMsg->pDb->name);
mgmtDropDb(pMsg); mgmtDropDb(pMsg);
} }
...@@ -926,7 +956,7 @@ void mgmtDropAllDbs(SAcctObj *pAcct) { ...@@ -926,7 +956,7 @@ void mgmtDropAllDbs(SAcctObj *pAcct) {
mPrint("acct:%s, all dbs will be dropped from sdb", pAcct->user); mPrint("acct:%s, all dbs will be dropped from sdb", pAcct->user);
while (1) { while (1) {
pNode = sdbFetchRow(tsDbSdb, pNode, (void **)&pDb); pNode = mgmtGetNextDb(pNode, &pDb);
if (pDb == NULL) break; if (pDb == NULL) break;
if (pDb->pAcct == pAcct) { if (pDb->pAcct == pAcct) {
......
...@@ -36,13 +36,13 @@ ...@@ -36,13 +36,13 @@
#include "mgmtUser.h" #include "mgmtUser.h"
#include "mgmtVgroup.h" #include "mgmtVgroup.h"
void *tsDnodeSdb = NULL;
int32_t tsDnodeUpdateSize = 0;
int32_t tsAccessSquence = 0; int32_t tsAccessSquence = 0;
static void *tsDnodeSdb = NULL;
static int32_t tsDnodeUpdateSize = 0;
extern void * tsMnodeSdb; extern void * tsMnodeSdb;
extern void * tsVgroupSdb; extern void * tsVgroupSdb;
static int32_t mgmtCreateDnode(uint32_t ip); static int32_t mgmtCreateDnode(char *ep);
static void mgmtProcessCreateDnodeMsg(SQueuedMsg *pMsg); static void mgmtProcessCreateDnodeMsg(SQueuedMsg *pMsg);
static void mgmtProcessDropDnodeMsg(SQueuedMsg *pMsg); static void mgmtProcessDropDnodeMsg(SQueuedMsg *pMsg);
static void mgmtProcessCfgDnodeMsg(SQueuedMsg *pMsg); static void mgmtProcessCfgDnodeMsg(SQueuedMsg *pMsg);
...@@ -68,50 +68,17 @@ static int32_t mgmtDnodeActionInsert(SSdbOper *pOper) { ...@@ -68,50 +68,17 @@ static int32_t mgmtDnodeActionInsert(SSdbOper *pOper) {
pDnode->status = TAOS_DN_STATUS_OFFLINE; pDnode->status = TAOS_DN_STATUS_OFFLINE;
} }
pDnode->mnodeShellPort = tsMnodeShellPort;
pDnode->mnodeDnodePort = tsMnodeDnodePort;
pDnode->dnodeShellPort = tsDnodeShellPort;
pDnode->dnodeMnodePort = tsDnodeMnodePort;
pDnode->syncPort = tsSyncPort;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t mgmtDnodeActionDelete(SSdbOper *pOper) { static int32_t mgmtDnodeActionDelete(SSdbOper *pOper) {
SDnodeObj *pDnode = pOper->pObj; SDnodeObj *pDnode = pOper->pObj;
void * pNode = NULL;
void * pLastNode = NULL;
SVgObj * pVgroup = NULL;
int32_t numOfVgroups = 0;
while (1) {
pLastNode = pNode;
pNode = sdbFetchRow(tsVgroupSdb, pNode, (void **)&pVgroup);
if (pVgroup == NULL) break;
if (pVgroup->vnodeGid[0].dnodeId == pDnode->dnodeId) {
SSdbOper oper = {
.type = SDB_OPER_LOCAL,
.table = tsVgroupSdb,
.pObj = pVgroup,
};
sdbDeleteRow(&oper);
pNode = pLastNode;
numOfVgroups++;
continue;
}
}
SMnodeObj *pMnode = mgmtGetMnode(pDnode->dnodeId);
if (pMnode != NULL) {
SSdbOper oper = {.type = SDB_OPER_LOCAL, .table = tsMnodeSdb, .pObj = pMnode};
sdbDeleteRow(&oper);
mgmtReleaseMnode(pMnode);
}
mgmtDropAllDnodeVgroups(pDnode);
mgmtDropMnodeLocal(pDnode->dnodeId);
balanceNotify(); balanceNotify();
mTrace("dnode:%d, all vgroups:%d is dropped from sdb", pDnode->dnodeId, numOfVgroups); mTrace("dnode:%d, all vgroups is dropped from sdb", pDnode->dnodeId);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -122,6 +89,7 @@ static int32_t mgmtDnodeActionUpdate(SSdbOper *pOper) { ...@@ -122,6 +89,7 @@ static int32_t mgmtDnodeActionUpdate(SSdbOper *pOper) {
memcpy(pSaved, pDnode, pOper->rowSize); memcpy(pSaved, pDnode, pOper->rowSize);
free(pDnode); free(pDnode);
} }
mgmtDecDnodeRef(pSaved);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -144,9 +112,8 @@ static int32_t mgmtDnodeActionDecode(SSdbOper *pOper) { ...@@ -144,9 +112,8 @@ static int32_t mgmtDnodeActionDecode(SSdbOper *pOper) {
static int32_t mgmtDnodeActionRestored() { static int32_t mgmtDnodeActionRestored() {
int32_t numOfRows = sdbGetNumOfRows(tsDnodeSdb); int32_t numOfRows = sdbGetNumOfRows(tsDnodeSdb);
if (numOfRows <= 0 && dnodeIsFirstDeploy()) { if (numOfRows <= 0 && dnodeIsFirstDeploy()) {
uint32_t ip = inet_addr(tsPrivateIp); mgmtCreateDnode(tsLocalEp);
mgmtCreateDnode(ip); SDnodeObj *pDnode = mgmtGetDnodeByIp(tsLocalEp);
SDnodeObj *pDnode = mgmtGetDnodeByIp(ip);
mgmtAddMnode(pDnode->dnodeId); mgmtAddMnode(pDnode->dnodeId);
mgmtDecDnodeRef(pDnode); mgmtDecDnodeRef(pDnode);
} }
...@@ -214,14 +181,14 @@ void *mgmtGetDnode(int32_t dnodeId) { ...@@ -214,14 +181,14 @@ void *mgmtGetDnode(int32_t dnodeId) {
return sdbGetRow(tsDnodeSdb, &dnodeId); return sdbGetRow(tsDnodeSdb, &dnodeId);
} }
void *mgmtGetDnodeByIp(uint32_t ip) { void *mgmtGetDnodeByIp(char *ep) {
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
void * pNode = NULL; void * pNode = NULL;
while (1) { while (1) {
pNode = sdbFetchRow(tsDnodeSdb, pNode, (void**)&pDnode); pNode = mgmtGetNextDnode(pNode, &pDnode);
if (pDnode == NULL) break; if (pDnode == NULL) break;
if (ip == pDnode->privateIp) { if (strcmp(ep, pDnode->dnodeEp) == 0) {
return pDnode; return pDnode;
} }
mgmtDecDnodeRef(pDnode); mgmtDecDnodeRef(pDnode);
...@@ -242,8 +209,7 @@ void mgmtUpdateDnode(SDnodeObj *pDnode) { ...@@ -242,8 +209,7 @@ void mgmtUpdateDnode(SDnodeObj *pDnode) {
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
.table = tsDnodeSdb, .table = tsDnodeSdb,
.pObj = pDnode, .pObj = pDnode
.rowSize = tsDnodeUpdateSize
}; };
sdbUpdateRow(&oper); sdbUpdateRow(&oper);
...@@ -253,19 +219,18 @@ void mgmtProcessCfgDnodeMsg(SQueuedMsg *pMsg) { ...@@ -253,19 +219,18 @@ void mgmtProcessCfgDnodeMsg(SQueuedMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0}; SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SCMCfgDnodeMsg *pCmCfgDnode = pMsg->pCont; SCMCfgDnodeMsg *pCmCfgDnode = pMsg->pCont;
if (pCmCfgDnode->ip[0] == 0) { if (pCmCfgDnode->ep[0] == 0) {
strcpy(pCmCfgDnode->ip, tsPrivateIp); strcpy(pCmCfgDnode->ep, tsLocalEp);
} else { } else {
strcpy(pCmCfgDnode->ip, pCmCfgDnode->ip); strcpy(pCmCfgDnode->ep, pCmCfgDnode->ep);
} }
uint32_t dnodeIp = inet_addr(pCmCfgDnode->ip);
if (strcmp(pMsg->pUser->user, "root") != 0) { if (strcmp(pMsg->pUser->user, "root") != 0) {
rpcRsp.code = TSDB_CODE_NO_RIGHTS; rpcRsp.code = TSDB_CODE_NO_RIGHTS;
} else { } else {
SRpcIpSet ipSet = mgmtGetIpSetFromIp(dnodeIp); SRpcIpSet ipSet = mgmtGetIpSetFromIp(pCmCfgDnode->ep);
SMDCfgDnodeMsg *pMdCfgDnode = rpcMallocCont(sizeof(SMDCfgDnodeMsg)); SMDCfgDnodeMsg *pMdCfgDnode = rpcMallocCont(sizeof(SMDCfgDnodeMsg));
strcpy(pMdCfgDnode->ip, pCmCfgDnode->ip); strcpy(pMdCfgDnode->ep, pCmCfgDnode->ep);
strcpy(pMdCfgDnode->config, pCmCfgDnode->config); strcpy(pMdCfgDnode->config, pCmCfgDnode->config);
SRpcMsg rpcMdCfgDnodeMsg = { SRpcMsg rpcMdCfgDnodeMsg = {
.handle = 0, .handle = 0,
...@@ -279,7 +244,7 @@ void mgmtProcessCfgDnodeMsg(SQueuedMsg *pMsg) { ...@@ -279,7 +244,7 @@ void mgmtProcessCfgDnodeMsg(SQueuedMsg *pMsg) {
} }
if (rpcRsp.code == TSDB_CODE_SUCCESS) { if (rpcRsp.code == TSDB_CODE_SUCCESS) {
mPrint("dnode:%s, is configured by %s", pCmCfgDnode->ip, pMsg->pUser->user); mPrint("dnode:%s, is configured by %s", pCmCfgDnode->ep, pMsg->pUser->user);
} }
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
...@@ -292,8 +257,6 @@ static void mgmtProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) { ...@@ -292,8 +257,6 @@ static void mgmtProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) {
void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) { void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
SDMStatusMsg *pStatus = rpcMsg->pCont; SDMStatusMsg *pStatus = rpcMsg->pCont;
pStatus->dnodeId = htonl(pStatus->dnodeId); pStatus->dnodeId = htonl(pStatus->dnodeId);
pStatus->privateIp = htonl(pStatus->privateIp);
pStatus->publicIp = htonl(pStatus->publicIp);
pStatus->moduleStatus = htonl(pStatus->moduleStatus); pStatus->moduleStatus = htonl(pStatus->moduleStatus);
pStatus->lastReboot = htonl(pStatus->lastReboot); pStatus->lastReboot = htonl(pStatus->lastReboot);
pStatus->numOfCores = htons(pStatus->numOfCores); pStatus->numOfCores = htons(pStatus->numOfCores);
...@@ -308,23 +271,21 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) { ...@@ -308,23 +271,21 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
if (pStatus->dnodeId == 0) { if (pStatus->dnodeId == 0) {
pDnode = mgmtGetDnodeByIp(pStatus->privateIp); pDnode = mgmtGetDnodeByIp(pStatus->dnodeEp);
if (pDnode == NULL) { if (pDnode == NULL) {
mTrace("dnode not created, privateIp:%s", taosIpStr(pStatus->privateIp)); mTrace("dnode %s not created", pStatus->dnodeEp);
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_DNODE_NOT_EXIST); mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_DNODE_NOT_EXIST);
return; return;
} }
} else { } else {
pDnode = mgmtGetDnode(pStatus->dnodeId); pDnode = mgmtGetDnode(pStatus->dnodeId);
if (pDnode == NULL) { if (pDnode == NULL) {
mError("dnode:%d, not exist, privateIp:%s", pStatus->dnodeId, taosIpStr(pStatus->privateIp)); mError("dnode id:%d, %s not exist", pStatus->dnodeId, pStatus->dnodeEp);
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_DNODE_NOT_EXIST); mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_DNODE_NOT_EXIST);
return; return;
} }
} }
pDnode->privateIp = pStatus->privateIp;
pDnode->publicIp = pStatus->publicIp;
pDnode->lastReboot = pStatus->lastReboot; pDnode->lastReboot = pStatus->lastReboot;
pDnode->numOfCores = pStatus->numOfCores; pDnode->numOfCores = pStatus->numOfCores;
pDnode->diskAvailable = pStatus->diskAvailable; pDnode->diskAvailable = pStatus->diskAvailable;
...@@ -334,7 +295,7 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) { ...@@ -334,7 +295,7 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
pDnode->lastAccess = tsAccessSquence; pDnode->lastAccess = tsAccessSquence;
if (pStatus->dnodeId == 0) { if (pStatus->dnodeId == 0) {
mTrace("dnode:%d, first access, privateIp:%s, name:%s", pDnode->dnodeId, taosIpStr(pDnode->privateIp), pDnode->dnodeName); mTrace("dnode:%d %s, first access", pDnode->dnodeId, pDnode->dnodeEp);
} else { } else {
//mTrace("dnode:%d, status received, access times %d", pDnode->dnodeId, pDnode->lastAccess); //mTrace("dnode:%d, status received, access times %d", pDnode->dnodeId, pDnode->lastAccess);
} }
...@@ -347,8 +308,8 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) { ...@@ -347,8 +308,8 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
SVgObj *pVgroup = mgmtGetVgroup(pVload->vgId); SVgObj *pVgroup = mgmtGetVgroup(pVload->vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
SRpcIpSet ipSet = mgmtGetIpSetFromIp(pDnode->privateIp); SRpcIpSet ipSet = mgmtGetIpSetFromIp(pDnode->dnodeEp);
mPrint("dnode:%d, vgroup:%d not exist in mnode, drop it", pDnode->dnodeId, pVload->vgId); mPrint("dnode:%d, vgId:%d not exist in mnode, drop it", pDnode->dnodeId, pVload->vgId);
mgmtSendDropVnodeMsg(pVload->vgId, &ipSet, NULL); mgmtSendDropVnodeMsg(pVload->vgId, &ipSet, NULL);
} else { } else {
mgmtUpdateVgroupStatus(pVgroup, pDnode, pVload); mgmtUpdateVgroupStatus(pVgroup, pDnode, pVload);
...@@ -391,25 +352,25 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) { ...@@ -391,25 +352,25 @@ void mgmtProcessDnodeStatusMsg(SRpcMsg *rpcMsg) {
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
} }
static int32_t mgmtCreateDnode(uint32_t ip) { static int32_t mgmtCreateDnode(char *ep) {
int32_t grantCode = grantCheck(TSDB_GRANT_DNODE); int32_t grantCode = grantCheck(TSDB_GRANT_DNODE);
if (grantCode != TSDB_CODE_SUCCESS) { if (grantCode != TSDB_CODE_SUCCESS) {
return grantCode; return grantCode;
} }
SDnodeObj *pDnode = mgmtGetDnodeByIp(ip); SDnodeObj *pDnode = mgmtGetDnodeByIp(ep);
if (pDnode != NULL) { if (pDnode != NULL) {
mError("dnode:%d is alredy exist, ip:%s", pDnode->dnodeId, taosIpStr(pDnode->privateIp)); mgmtDecDnodeRef(pDnode);
mError("dnode:%d is alredy exist, %s:%d", pDnode->dnodeId, pDnode->dnodeFqdn, pDnode->dnodePort);
return TSDB_CODE_DNODE_ALREADY_EXIST; return TSDB_CODE_DNODE_ALREADY_EXIST;
} }
pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj)); pDnode = (SDnodeObj *) calloc(1, sizeof(SDnodeObj));
pDnode->privateIp = ip;
pDnode->publicIp = ip;
pDnode->createdTime = taosGetTimestampMs(); pDnode->createdTime = taosGetTimestampMs();
pDnode->status = TAOS_DN_STATUS_OFFLINE; pDnode->status = TAOS_DN_STATUS_OFFLINE;
pDnode->totalVnodes = TSDB_INVALID_VNODE_NUM; pDnode->totalVnodes = TSDB_INVALID_VNODE_NUM;
sprintf(pDnode->dnodeName, "n%d", sdbGetId(tsDnodeSdb) + 1); strcpy(pDnode->dnodeEp, ep);
taosGetFqdnPortFromEp(ep, pDnode->dnodeFqdn, &pDnode->dnodePort);
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
...@@ -446,15 +407,16 @@ int32_t mgmtDropDnode(SDnodeObj *pDnode) { ...@@ -446,15 +407,16 @@ int32_t mgmtDropDnode(SDnodeObj *pDnode) {
return code; return code;
} }
static int32_t mgmtDropDnodeByIp(uint32_t ip) { static int32_t mgmtDropDnodeByIp(char *ep) {
SDnodeObj *pDnode = mgmtGetDnodeByIp(ip); SDnodeObj *pDnode = mgmtGetDnodeByIp(ep);
if (pDnode == NULL) { if (pDnode == NULL) {
mError("dnode:%s, is not exist", taosIpStr(ip)); mError("dnode:%s, is not exist", ep);
return TSDB_CODE_DNODE_NOT_EXIST; return TSDB_CODE_DNODE_NOT_EXIST;
} }
if (pDnode->privateIp == dnodeGetMnodeMasteIp()) { mgmtDecDnodeRef(pDnode);
mError("dnode:%d, can't drop dnode which is master", pDnode->dnodeId); if (strcmp(pDnode->dnodeEp, dnodeGetMnodeMasterEp()) == 0) {
mError("dnode:%d, can't drop dnode:%s which is master", pDnode->dnodeId, ep);
return TSDB_CODE_NO_REMOVE_MASTER; return TSDB_CODE_NO_REMOVE_MASTER;
} }
...@@ -473,13 +435,13 @@ static void mgmtProcessCreateDnodeMsg(SQueuedMsg *pMsg) { ...@@ -473,13 +435,13 @@ static void mgmtProcessCreateDnodeMsg(SQueuedMsg *pMsg) {
if (strcmp(pMsg->pUser->user, "root") != 0) { if (strcmp(pMsg->pUser->user, "root") != 0) {
rpcRsp.code = TSDB_CODE_NO_RIGHTS; rpcRsp.code = TSDB_CODE_NO_RIGHTS;
} else { } else {
uint32_t ip = inet_addr(pCreate->ip); rpcRsp.code = mgmtCreateDnode(pCreate->ep);
rpcRsp.code = mgmtCreateDnode(ip);
if (rpcRsp.code == TSDB_CODE_SUCCESS) { if (rpcRsp.code == TSDB_CODE_SUCCESS) {
SDnodeObj *pDnode = mgmtGetDnodeByIp(ip); SDnodeObj *pDnode = mgmtGetDnodeByIp(pCreate->ep);
mLPrint("dnode:%d, ip:%s is created by %s", pDnode->dnodeId, pCreate->ip, pMsg->pUser->user); mLPrint("dnode:%d, %s is created by %s", pDnode->dnodeId, pCreate->ep, pMsg->pUser->user);
mgmtDecDnodeRef(pDnode);
} else { } else {
mError("failed to create dnode:%s, reason:%s", pCreate->ip, tstrerror(rpcRsp.code)); mError("failed to create dnode:%s, reason:%s", pCreate->ep, tstrerror(rpcRsp.code));
} }
} }
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
...@@ -490,15 +452,15 @@ static void mgmtProcessDropDnodeMsg(SQueuedMsg *pMsg) { ...@@ -490,15 +452,15 @@ static void mgmtProcessDropDnodeMsg(SQueuedMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0}; SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SCMDropDnodeMsg *pDrop = pMsg->pCont; SCMDropDnodeMsg *pDrop = pMsg->pCont;
if (strcmp(pMsg->pUser->user, "root") != 0) { if (strcmp(pMsg->pUser->user, "root") != 0) {
rpcRsp.code = TSDB_CODE_NO_RIGHTS; rpcRsp.code = TSDB_CODE_NO_RIGHTS;
} else { } else {
uint32_t ip = inet_addr(pDrop->ip); rpcRsp.code = mgmtDropDnodeByIp(pDrop->ep);
rpcRsp.code = mgmtDropDnodeByIp(ip);
if (rpcRsp.code == TSDB_CODE_SUCCESS) { if (rpcRsp.code == TSDB_CODE_SUCCESS) {
mLPrint("dnode:%s is dropped by %s", pDrop->ip, pMsg->pUser->user); mLPrint("dnode:%s is dropped by %s", pDrop->ep, pMsg->pUser->user);
} else { } else {
mError("failed to drop dnode:%s, reason:%s", pDrop->ip, tstrerror(rpcRsp.code)); mError("failed to drop dnode:%s, reason:%s", pDrop->ep, tstrerror(rpcRsp.code));
} }
} }
...@@ -506,7 +468,7 @@ static void mgmtProcessDropDnodeMsg(SQueuedMsg *pMsg) { ...@@ -506,7 +468,7 @@ static void mgmtProcessDropDnodeMsg(SQueuedMsg *pMsg) {
} }
static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); SUserObj *pUser = mgmtGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->pAcct->user, "root") != 0) { if (strcmp(pUser->pAcct->user, "root") != 0) {
...@@ -523,15 +485,9 @@ static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo ...@@ -523,15 +485,9 @@ static int32_t mgmtGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 16; pShow->bytes[cols] = 40;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "private ip");
pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++;
pShow->bytes[cols] = 16;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "public ip"); strcpy(pSchema[cols].name, "end point");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
...@@ -581,7 +537,6 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -581,7 +537,6 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi
int32_t cols = 0; int32_t cols = 0;
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
char *pWrite; char *pWrite;
char ipstr[32];
while (numOfRows < rows) { while (numOfRows < rows) {
pShow->pNode = mgmtGetNextDnode(pShow->pNode, &pDnode); pShow->pNode = mgmtGetNextDnode(pShow->pNode, &pDnode);
...@@ -593,14 +548,8 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -593,14 +548,8 @@ static int32_t mgmtRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, voi
*(int16_t *)pWrite = pDnode->dnodeId; *(int16_t *)pWrite = pDnode->dnodeId;
cols++; cols++;
tinet_ntoa(ipstr, pDnode->privateIp);
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, ipstr);
cols++;
tinet_ntoa(ipstr, pDnode->publicIp);
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, ipstr); strncpy(pWrite, pDnode->dnodeEp, pShow->bytes[cols]-1);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
...@@ -636,7 +585,7 @@ static bool mgmtCheckModuleInDnode(SDnodeObj *pDnode, int32_t moduleType) { ...@@ -636,7 +585,7 @@ static bool mgmtCheckModuleInDnode(SDnodeObj *pDnode, int32_t moduleType) {
static int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
int32_t cols = 0; int32_t cols = 0;
SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); SUserObj *pUser = mgmtGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->user, "root") != 0) { if (strcmp(pUser->user, "root") != 0) {
...@@ -652,9 +601,9 @@ static int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC ...@@ -652,9 +601,9 @@ static int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 16; pShow->bytes[cols] = 40;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "ip"); strcpy(pSchema[cols].name, "end point");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
...@@ -702,10 +651,8 @@ int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pCo ...@@ -702,10 +651,8 @@ int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pCo
*(int16_t *)pWrite = pDnode->dnodeId; *(int16_t *)pWrite = pDnode->dnodeId;
cols++; cols++;
char ipstr[20];
tinet_ntoa(ipstr, pDnode->privateIp);
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, ipstr); strncpy(pWrite, pDnode->dnodeEp, pShow->bytes[cols]-1);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
...@@ -748,7 +695,7 @@ static bool mgmtCheckConfigShow(SGlobalCfg *cfg) { ...@@ -748,7 +695,7 @@ static bool mgmtCheckConfigShow(SGlobalCfg *cfg) {
static int32_t mgmtGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mgmtGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
int32_t cols = 0; int32_t cols = 0;
SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); SUserObj *pUser = mgmtGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->user, "root") != 0) { if (strcmp(pUser->user, "root") != 0) {
...@@ -835,7 +782,7 @@ static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, vo ...@@ -835,7 +782,7 @@ static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, vo
static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
int32_t cols = 0; int32_t cols = 0;
SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); SUserObj *pUser = mgmtGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->user, "root") != 0) { if (strcmp(pUser->user, "root") != 0) {
...@@ -865,8 +812,7 @@ static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo ...@@ -865,8 +812,7 @@ static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
if (pShow->payloadLen > 0 ) { if (pShow->payloadLen > 0 ) {
uint32_t ip = ip2uint(pShow->payload); pDnode = mgmtGetDnodeByIp(pShow->payload);
pDnode = mgmtGetDnodeByIp(ip);
} else { } else {
mgmtGetNextDnode(NULL, (SDnodeObj **)&pDnode); mgmtGetNextDnode(NULL, (SDnodeObj **)&pDnode);
} }
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include "mgmtTable.h" #include "mgmtTable.h"
#include "mgmtShell.h" #include "mgmtShell.h"
void *tsMgmtTmr = NULL; extern void *tsMgmtTmr;
static bool tsMgmtIsRunning = false; static bool tsMgmtIsRunning = false;
int32_t mgmtStartSystem() { int32_t mgmtStartSystem() {
...@@ -51,12 +51,6 @@ int32_t mgmtStartSystem() { ...@@ -51,12 +51,6 @@ int32_t mgmtStartSystem() {
mkdir(tsMnodeDir, 0755); mkdir(tsMnodeDir, 0755);
} }
tsMgmtTmr = taosTmrInit((tsMaxShellConns) * 3, 200, 3600000, "MND");
if (tsMgmtTmr == NULL) {
mError("failed to init timer");
return -1;
}
if (mgmtInitAccts() < 0) { if (mgmtInitAccts() < 0) {
mError("failed to init accts"); mError("failed to init accts");
return -1; return -1;
...@@ -130,7 +124,7 @@ int32_t mgmtInitSystem() { ...@@ -130,7 +124,7 @@ int32_t mgmtInitSystem() {
struct stat dirstat; struct stat dirstat;
bool fileExist = (stat(tsMnodeDir, &dirstat) == 0); bool fileExist = (stat(tsMnodeDir, &dirstat) == 0);
bool asMaster = (strcmp(tsMasterIp, tsPrivateIp) == 0); bool asMaster = (strcmp(tsFirst, tsLocalEp) == 0);
if (asMaster || fileExist) { if (asMaster || fileExist) {
if (mgmtStartSystem() != 0) { if (mgmtStartSystem() != 0) {
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "mgmtShell.h" #include "mgmtShell.h"
#include "mgmtUser.h" #include "mgmtUser.h"
void * tsMnodeSdb = NULL; static void * tsMnodeSdb = NULL;
static int32_t tsMnodeUpdateSize = 0; static int32_t tsMnodeUpdateSize = 0;
static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn);
...@@ -71,7 +71,7 @@ static int32_t mgmtMnodeActionUpdate(SSdbOper *pOper) { ...@@ -71,7 +71,7 @@ static int32_t mgmtMnodeActionUpdate(SSdbOper *pOper) {
memcpy(pSaved, pMnode, pOper->rowSize); memcpy(pSaved, pMnode, pOper->rowSize);
free(pMnode); free(pMnode);
} }
mgmtDecMnodeRef(pSaved);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -97,7 +97,7 @@ static int32_t mgmtMnodeActionRestored() { ...@@ -97,7 +97,7 @@ static int32_t mgmtMnodeActionRestored() {
mgmtGetNextMnode(NULL, &pMnode); mgmtGetNextMnode(NULL, &pMnode);
if (pMnode != NULL) { if (pMnode != NULL) {
pMnode->role = TAOS_SYNC_ROLE_MASTER; pMnode->role = TAOS_SYNC_ROLE_MASTER;
mgmtReleaseMnode(pMnode); mgmtDecMnodeRef(pMnode);
} }
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -148,7 +148,11 @@ void *mgmtGetMnode(int32_t mnodeId) { ...@@ -148,7 +148,11 @@ void *mgmtGetMnode(int32_t mnodeId) {
return sdbGetRow(tsMnodeSdb, &mnodeId); return sdbGetRow(tsMnodeSdb, &mnodeId);
} }
void mgmtReleaseMnode(SMnodeObj *pMnode) { void mgmtIncMnodeRef(SMnodeObj *pMnode) {
sdbIncRef(tsMnodeSdb, pMnode);
}
void mgmtDecMnodeRef(SMnodeObj *pMnode) {
sdbDecRef(tsMnodeSdb, pMnode); sdbDecRef(tsMnodeSdb, pMnode);
} }
...@@ -171,27 +175,23 @@ char *mgmtGetMnodeRoleStr(int32_t role) { ...@@ -171,27 +175,23 @@ char *mgmtGetMnodeRoleStr(int32_t role) {
} }
} }
void mgmtGetMnodeIpSet(SRpcIpSet *ipSet, bool usePublicIp) { void mgmtGetMnodeIpSet(SRpcIpSet *ipSet) {
void *pNode = NULL; void *pNode = NULL;
while (1) { while (1) {
SMnodeObj *pMnode = NULL; SMnodeObj *pMnode = NULL;
pNode = mgmtGetNextMnode(pNode, &pMnode); pNode = mgmtGetNextMnode(pNode, &pMnode);
if (pMnode == NULL) break; if (pMnode == NULL) break;
if (usePublicIp) { strcpy(ipSet->fqdn[ipSet->numOfIps], pMnode->pDnode->dnodeFqdn);
ipSet->ip[ipSet->numOfIps] = htonl(pMnode->pDnode->publicIp); ipSet->port[ipSet->numOfIps] = htons(pMnode->pDnode->dnodePort);
} else {
ipSet->ip[ipSet->numOfIps] = htonl(pMnode->pDnode->privateIp);
}
if (pMnode->role == TAOS_SYNC_ROLE_MASTER) { if (pMnode->role == TAOS_SYNC_ROLE_MASTER) {
ipSet->inUse = ipSet->numOfIps; ipSet->inUse = ipSet->numOfIps;
} }
ipSet->numOfIps++; ipSet->numOfIps++;
ipSet->port = htons(pMnode->pDnode->mnodeShellPort);
mgmtReleaseMnode(pMnode); mgmtDecMnodeRef(pMnode);
} }
} }
...@@ -207,16 +207,13 @@ void mgmtGetMnodeInfos(void *param) { ...@@ -207,16 +207,13 @@ void mgmtGetMnodeInfos(void *param) {
if (pMnode == NULL) break; if (pMnode == NULL) break;
mnodes->nodeInfos[index].nodeId = htonl(pMnode->mnodeId); mnodes->nodeInfos[index].nodeId = htonl(pMnode->mnodeId);
mnodes->nodeInfos[index].nodeIp = htonl(pMnode->pDnode->privateIp); strcpy(mnodes->nodeInfos[index].nodeEp, pMnode->pDnode->dnodeEp);
mnodes->nodeInfos[index].nodePort = htons(pMnode->pDnode->mnodeDnodePort);
mnodes->nodeInfos[index].syncPort = htons(pMnode->pDnode->syncPort);
strcpy(mnodes->nodeInfos[index].nodeName, pMnode->pDnode->dnodeName);
if (pMnode->role == TAOS_SYNC_ROLE_MASTER) { if (pMnode->role == TAOS_SYNC_ROLE_MASTER) {
mnodes->inUse = index; mnodes->inUse = index;
} }
index++; index++;
mgmtReleaseMnode(pMnode); mgmtDecMnodeRef(pMnode);
} }
mnodes->nodeNum = index; mnodes->nodeNum = index;
...@@ -242,8 +239,17 @@ int32_t mgmtAddMnode(int32_t dnodeId) { ...@@ -242,8 +239,17 @@ int32_t mgmtAddMnode(int32_t dnodeId) {
return code; return code;
} }
void mgmtDropMnodeLocal(int32_t dnodeId) {
SMnodeObj *pMnode = mgmtGetMnode(dnodeId);
if (pMnode != NULL) {
SSdbOper oper = {.type = SDB_OPER_LOCAL, .table = tsMnodeSdb, .pObj = pMnode};
sdbDeleteRow(&oper);
mgmtDecMnodeRef(pMnode);
}
}
int32_t mgmtDropMnode(int32_t dnodeId) { int32_t mgmtDropMnode(int32_t dnodeId) {
SMnodeObj *pMnode = sdbGetRow(tsMnodeSdb, &dnodeId); SMnodeObj *pMnode = mgmtGetMnode(dnodeId);
if (pMnode == NULL) { if (pMnode == NULL) {
return TSDB_CODE_DNODE_NOT_EXIST; return TSDB_CODE_DNODE_NOT_EXIST;
} }
...@@ -265,7 +271,7 @@ int32_t mgmtDropMnode(int32_t dnodeId) { ...@@ -265,7 +271,7 @@ int32_t mgmtDropMnode(int32_t dnodeId) {
static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
sdbUpdateMnodeRoles(); sdbUpdateMnodeRoles();
SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); SUserObj *pUser = mgmtGetUserFromConn(pConn);
if (pUser == NULL) return 0; if (pUser == NULL) return 0;
if (strcmp(pUser->pAcct->user, "root") != 0) { if (strcmp(pUser->pAcct->user, "root") != 0) {
...@@ -282,15 +288,9 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo ...@@ -282,15 +288,9 @@ static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCo
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 16; pShow->bytes[cols] = 40;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "private ip"); strcpy(pSchema[cols].name, "end point");
pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++;
pShow->bytes[cols] = 16;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "public ip");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
...@@ -327,7 +327,6 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -327,7 +327,6 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi
int32_t cols = 0; int32_t cols = 0;
SMnodeObj *pMnode = NULL; SMnodeObj *pMnode = NULL;
char *pWrite; char *pWrite;
char ipstr[32];
while (numOfRows < rows) { while (numOfRows < rows) {
pShow->pNode = mgmtGetNextMnode(pShow->pNode, &pMnode); pShow->pNode = mgmtGetNextMnode(pShow->pNode, &pMnode);
...@@ -339,14 +338,8 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -339,14 +338,8 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi
*(int16_t *)pWrite = pMnode->mnodeId; *(int16_t *)pWrite = pMnode->mnodeId;
cols++; cols++;
tinet_ntoa(ipstr, pMnode->pDnode->privateIp);
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, ipstr);
cols++;
tinet_ntoa(ipstr, pMnode->pDnode->publicIp);
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, ipstr); strncpy(pWrite, pMnode->pDnode->dnodeEp, pShow->bytes[cols]-1);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
...@@ -359,7 +352,7 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi ...@@ -359,7 +352,7 @@ static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, voi
numOfRows++; numOfRows++;
mgmtReleaseMnode(pMnode); mgmtDecMnodeRef(pMnode);
} }
pShow->numOfReads += numOfRows; pShow->numOfReads += numOfRows;
......
...@@ -561,17 +561,6 @@ int32_t mgmtKillConnection(char *qidstr, void *pConn) { ...@@ -561,17 +561,6 @@ int32_t mgmtKillConnection(char *qidstr, void *pConn) {
return TSDB_CODE_INVALID_CONNECTION; return TSDB_CODE_INVALID_CONNECTION;
} }
bool mgmtCheckQhandle(uint64_t qhandle) {
return true;
}
void mgmtSaveQhandle(void *qhandle) {
mTrace("qhandle:%p is allocated", qhandle);
}
void mgmtFreeQhandle(void *qhandle) {
mTrace("qhandle:%p is freed", qhandle);
}
int mgmtGetConns(SShowObj *pShow, void *pConn) { int mgmtGetConns(SShowObj *pShow, void *pConn) {
// SAcctObj * pAcct = pConn->pAcct; // SAcctObj * pAcct = pConn->pAcct;
...@@ -686,7 +675,7 @@ int32_t mgmtRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn ...@@ -686,7 +675,7 @@ int32_t mgmtRetrieveConns(SShowObj *pShow, char *data, int32_t rows, void *pConn
void mgmtProcessKillQueryMsg(SQueuedMsg *pMsg) { void mgmtProcessKillQueryMsg(SQueuedMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0}; SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SUserObj *pUser = mgmtGetUserFromConn(pMsg->thandle, NULL); SUserObj *pUser = mgmtGetUserFromConn(pMsg->thandle);
if (pUser == NULL) { if (pUser == NULL) {
rpcRsp.code = TSDB_CODE_INVALID_USER; rpcRsp.code = TSDB_CODE_INVALID_USER;
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
...@@ -710,7 +699,7 @@ void mgmtProcessKillQueryMsg(SQueuedMsg *pMsg) { ...@@ -710,7 +699,7 @@ void mgmtProcessKillQueryMsg(SQueuedMsg *pMsg) {
void mgmtProcessKillStreamMsg(SQueuedMsg *pMsg) { void mgmtProcessKillStreamMsg(SQueuedMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0}; SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SUserObj *pUser = mgmtGetUserFromConn(pMsg->thandle, NULL); SUserObj *pUser = mgmtGetUserFromConn(pMsg->thandle);
if (pUser == NULL) { if (pUser == NULL) {
rpcRsp.code = TSDB_CODE_INVALID_USER; rpcRsp.code = TSDB_CODE_INVALID_USER;
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
...@@ -734,7 +723,7 @@ void mgmtProcessKillStreamMsg(SQueuedMsg *pMsg) { ...@@ -734,7 +723,7 @@ void mgmtProcessKillStreamMsg(SQueuedMsg *pMsg) {
void mgmtProcessKillConnectionMsg(SQueuedMsg *pMsg) { void mgmtProcessKillConnectionMsg(SQueuedMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0}; SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SUserObj *pUser = mgmtGetUserFromConn(pMsg->thandle, NULL); SUserObj *pUser = mgmtGetUserFromConn(pMsg->thandle);
if (pUser == NULL) { if (pUser == NULL) {
rpcRsp.code = TSDB_CODE_INVALID_USER; rpcRsp.code = TSDB_CODE_INVALID_USER;
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
...@@ -771,52 +760,3 @@ int32_t mgmtInitProfile() { ...@@ -771,52 +760,3 @@ int32_t mgmtInitProfile() {
void mgmtCleanUpProfile() { void mgmtCleanUpProfile() {
} }
void *mgmtMallocQueuedMsg(SRpcMsg *rpcMsg) {
bool usePublicIp = false;
SUserObj *pUser = mgmtGetUserFromConn(rpcMsg->handle, &usePublicIp);
if (pUser == NULL) {
return NULL;
}
SQueuedMsg *pMsg = calloc(1, sizeof(SQueuedMsg));
pMsg->thandle = rpcMsg->handle;
pMsg->msgType = rpcMsg->msgType;
pMsg->contLen = rpcMsg->contLen;
pMsg->pCont = rpcMsg->pCont;
pMsg->pUser = pUser;
pMsg->usePublicIp = usePublicIp;
return pMsg;
}
void mgmtFreeQueuedMsg(SQueuedMsg *pMsg) {
if (pMsg != NULL) {
rpcFreeCont(pMsg->pCont);
if (pMsg->pUser) mgmtDecUserRef(pMsg->pUser);
if (pMsg->pDb) mgmtDecDbRef(pMsg->pDb);
if (pMsg->pVgroup) mgmtDecVgroupRef(pMsg->pVgroup);
if (pMsg->pTable) mgmtDecTableRef(pMsg->pTable);
if (pMsg->pAcct) mgmtDecAcctRef(pMsg->pAcct);
if (pMsg->pDnode) mgmtDecDnodeRef(pMsg->pDnode);
free(pMsg);
}
}
void* mgmtCloneQueuedMsg(SQueuedMsg *pSrcMsg) {
SQueuedMsg *pDestMsg = calloc(1, sizeof(SQueuedMsg));
pDestMsg->thandle = pSrcMsg->thandle;
pDestMsg->msgType = pSrcMsg->msgType;
pDestMsg->pCont = pSrcMsg->pCont;
pDestMsg->contLen = pSrcMsg->contLen;
pDestMsg->retry = pSrcMsg->retry;
pDestMsg->maxRetry= pSrcMsg->maxRetry;
pDestMsg->pUser = pSrcMsg->pUser;
pDestMsg->usePublicIp = pSrcMsg->usePublicIp;
pSrcMsg->pCont = NULL;
pSrcMsg->pUser = NULL;
return pDestMsg;
}
\ No newline at end of file
...@@ -40,7 +40,7 @@ typedef enum { ...@@ -40,7 +40,7 @@ typedef enum {
typedef enum { typedef enum {
SDB_STATUS_OFFLINE, SDB_STATUS_OFFLINE,
SDB_STATUS_SERVING, SDB_STATUS_SERVING,
SDB_ACTION_CLOSING SDB_STATUS_CLOSING
} ESdbStatus; } ESdbStatus;
typedef struct _SSdbTable { typedef struct _SSdbTable {
...@@ -107,6 +107,10 @@ bool sdbIsMaster() { ...@@ -107,6 +107,10 @@ bool sdbIsMaster() {
return tsSdbObj.role == TAOS_SYNC_ROLE_MASTER; return tsSdbObj.role == TAOS_SYNC_ROLE_MASTER;
} }
bool sdbIsServing() {
return tsSdbObj.status == SDB_STATUS_SERVING;
}
static char *sdbGetActionStr(int32_t action) { static char *sdbGetActionStr(int32_t action) {
switch (action) { switch (action) {
case SDB_ACTION_INSERT: case SDB_ACTION_INSERT:
...@@ -180,7 +184,7 @@ void sdbUpdateMnodeRoles() { ...@@ -180,7 +184,7 @@ void sdbUpdateMnodeRoles() {
if (pMnode != NULL) { if (pMnode != NULL) {
pMnode->role = roles.role[i]; pMnode->role = roles.role[i];
sdbPrint("mnode:%d, role:%s", pMnode->mnodeId, mgmtGetMnodeRoleStr(pMnode->role)); sdbPrint("mnode:%d, role:%s", pMnode->mnodeId, mgmtGetMnodeRoleStr(pMnode->role));
mgmtReleaseMnode(pMnode); mgmtDecMnodeRef(pMnode);
} }
} }
} }
...@@ -231,8 +235,8 @@ void sdbUpdateSync() { ...@@ -231,8 +235,8 @@ void sdbUpdateSync() {
for (int32_t i = 0; i < mnodes->nodeNum; ++i) { for (int32_t i = 0; i < mnodes->nodeNum; ++i) {
SDMMnodeInfo *node = &mnodes->nodeInfos[i]; SDMMnodeInfo *node = &mnodes->nodeInfos[i];
syncCfg.nodeInfo[i].nodeId = node->nodeId; syncCfg.nodeInfo[i].nodeId = node->nodeId;
syncCfg.nodeInfo[i].nodeIp = node->nodeIp; taosGetFqdnPortFromEp(node->nodeEp, syncCfg.nodeInfo[i].nodeFqdn, &syncCfg.nodeInfo[i].nodePort);
strcpy(syncCfg.nodeInfo[i].name, node->nodeName); syncCfg.nodeInfo[i].nodePort += TSDB_PORT_SYNC;
index++; index++;
} }
...@@ -244,21 +248,16 @@ void sdbUpdateSync() { ...@@ -244,21 +248,16 @@ void sdbUpdateSync() {
if (pMnode == NULL) break; if (pMnode == NULL) break;
syncCfg.nodeInfo[index].nodeId = pMnode->mnodeId; syncCfg.nodeInfo[index].nodeId = pMnode->mnodeId;
syncCfg.nodeInfo[index].nodeIp = pMnode->pDnode->privateIp; syncCfg.nodeInfo[index].nodePort = pMnode->pDnode->dnodePort + TSDB_PORT_SYNC;
strcpy(syncCfg.nodeInfo[index].name, pMnode->pDnode->dnodeName); strcpy(syncCfg.nodeInfo[index].nodeFqdn, pMnode->pDnode->dnodeEp);
index++; index++;
mgmtReleaseMnode(pMnode); mgmtDecMnodeRef(pMnode);
} }
} }
syncCfg.replica = index; syncCfg.replica = index;
syncCfg.arbitratorIp = syncCfg.nodeInfo[0].nodeIp; syncCfg.quorum = (syncCfg.replica == 1) ? 1:2;
if (syncCfg.replica == 1) {
syncCfg.quorum = 1;
} else {
syncCfg.quorum = 2;
}
bool hasThisDnode = false; bool hasThisDnode = false;
for (int32_t i = 0; i < syncCfg.replica; ++i) { for (int32_t i = 0; i < syncCfg.replica; ++i) {
...@@ -271,10 +270,9 @@ void sdbUpdateSync() { ...@@ -271,10 +270,9 @@ void sdbUpdateSync() {
if (!hasThisDnode) return; if (!hasThisDnode) return;
if (memcmp(&syncCfg, &tsSdbObj.cfg, sizeof(SSyncCfg)) == 0) return; if (memcmp(&syncCfg, &tsSdbObj.cfg, sizeof(SSyncCfg)) == 0) return;
sdbPrint("work as mnode, replica:%d arbitratorIp:%s", syncCfg.replica, taosIpStr(syncCfg.arbitratorIp)); sdbPrint("work as mnode, replica:%d", syncCfg.replica);
for (int32_t i = 0; i < syncCfg.replica; ++i) { for (int32_t i = 0; i < syncCfg.replica; ++i) {
sdbPrint("mnode:%d, ip:%s name:%s", syncCfg.nodeInfo[i].nodeId, taosIpStr(syncCfg.nodeInfo[i].nodeIp), sdbPrint("mnode:%d, %s:%d", syncCfg.nodeInfo[i].nodeId, syncCfg.nodeInfo[i].nodeFqdn, syncCfg.nodeInfo[i].nodePort);
syncCfg.nodeInfo[i].name);
} }
SSyncInfo syncInfo; SSyncInfo syncInfo;
...@@ -320,6 +318,7 @@ int32_t sdbInit() { ...@@ -320,6 +318,7 @@ int32_t sdbInit() {
void sdbCleanUp() { void sdbCleanUp() {
if (tsSdbObj.status != SDB_STATUS_SERVING) return; if (tsSdbObj.status != SDB_STATUS_SERVING) return;
tsSdbObj.status = SDB_STATUS_CLOSING;
syncStop(tsSdbObj.sync); syncStop(tsSdbObj.sync);
free(tsSdbObj.sync); free(tsSdbObj.sync);
walClose(tsSdbObj.wal); walClose(tsSdbObj.wal);
...@@ -333,7 +332,7 @@ void sdbIncRef(void *handle, void *pRow) { ...@@ -333,7 +332,7 @@ void sdbIncRef(void *handle, void *pRow) {
SSdbTable *pTable = handle; SSdbTable *pTable = handle;
int32_t * pRefCount = (int32_t *)(pRow + pTable->refCountPos); int32_t * pRefCount = (int32_t *)(pRow + pTable->refCountPos);
atomic_add_fetch_32(pRefCount, 1); atomic_add_fetch_32(pRefCount, 1);
if (0 && strcmp(pTable->tableName, "accounts") == 0) { if (0 && pTable->tableId == SDB_TABLE_CTABLE) {
sdbTrace("table:%s, add ref to record:%s:%s:%d", pTable->tableName, pTable->tableName, sdbGetkeyStr(pTable, pRow), sdbTrace("table:%s, add ref to record:%s:%s:%d", pTable->tableName, pTable->tableName, sdbGetkeyStr(pTable, pRow),
*pRefCount); *pRefCount);
} }
...@@ -345,7 +344,7 @@ void sdbDecRef(void *handle, void *pRow) { ...@@ -345,7 +344,7 @@ void sdbDecRef(void *handle, void *pRow) {
SSdbTable *pTable = handle; SSdbTable *pTable = handle;
int32_t * pRefCount = (int32_t *)(pRow + pTable->refCountPos); int32_t * pRefCount = (int32_t *)(pRow + pTable->refCountPos);
int32_t refCount = atomic_sub_fetch_32(pRefCount, 1); int32_t refCount = atomic_sub_fetch_32(pRefCount, 1);
if (0 && strcmp(pTable->tableName, "accounts") == 0) { if (0 && pTable->tableId == SDB_TABLE_CTABLE) {
sdbTrace("table:%s, def ref of record:%s:%s:%d", pTable->tableName, pTable->tableName, sdbGetkeyStr(pTable, pRow), sdbTrace("table:%s, def ref of record:%s:%s:%d", pTable->tableName, pTable->tableName, sdbGetkeyStr(pTable, pRow),
*pRefCount); *pRefCount);
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "ttimer.h" #include "ttimer.h"
#include "tgrant.h" #include "tgrant.h"
#include "tglobal.h" #include "tglobal.h"
#include "tcache.h"
#include "dnode.h" #include "dnode.h"
#include "mgmtDef.h" #include "mgmtDef.h"
#include "mgmtLog.h" #include "mgmtLog.h"
...@@ -50,10 +51,11 @@ static void mgmtProcessHeartBeatMsg(SQueuedMsg *queuedMsg); ...@@ -50,10 +51,11 @@ static void mgmtProcessHeartBeatMsg(SQueuedMsg *queuedMsg);
static void mgmtProcessConnectMsg(SQueuedMsg *queuedMsg); static void mgmtProcessConnectMsg(SQueuedMsg *queuedMsg);
static void mgmtProcessUseMsg(SQueuedMsg *queuedMsg); static void mgmtProcessUseMsg(SQueuedMsg *queuedMsg);
extern void *tsMgmtTmr; void *tsMgmtTmr;
static void *tsMgmtShellRpc = NULL; static void *tsMgmtShellRpc = NULL;
static void *tsMgmtTranQhandle = NULL; static void *tsMgmtTranQhandle = NULL;
static void (*tsMgmtProcessShellMsgFp[TSDB_MSG_TYPE_MAX])(SQueuedMsg *) = {0}; static void (*tsMgmtProcessShellMsgFp[TSDB_MSG_TYPE_MAX])(SQueuedMsg *) = {0};
static void *tsQhandleCache = NULL;
static SShowMetaFp tsMgmtShowMetaFp[TSDB_MGMT_TABLE_MAX] = {0}; static SShowMetaFp tsMgmtShowMetaFp[TSDB_MGMT_TABLE_MAX] = {0};
static SShowRetrieveFp tsMgmtShowRetrieveFp[TSDB_MGMT_TABLE_MAX] = {0}; static SShowRetrieveFp tsMgmtShowRetrieveFp[TSDB_MGMT_TABLE_MAX] = {0};
...@@ -64,7 +66,9 @@ int32_t mgmtInitShell() { ...@@ -64,7 +66,9 @@ int32_t mgmtInitShell() {
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_CONNECT, mgmtProcessConnectMsg); mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_CONNECT, mgmtProcessConnectMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_USE_DB, mgmtProcessUseMsg); mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_USE_DB, mgmtProcessUseMsg);
tsMgmtTmr = taosTmrInit((tsMaxShellConns) * 3, 200, 3600000, "MND");
tsMgmtTranQhandle = taosInitScheduler(tsMaxShellConns, 1, "mnodeT"); tsMgmtTranQhandle = taosInitScheduler(tsMaxShellConns, 1, "mnodeT");
tsQhandleCache = taosCacheInit(tsMgmtTmr, 2);
int32_t numOfThreads = tsNumOfCores * tsNumOfThreadsPerCore / 4.0; int32_t numOfThreads = tsNumOfCores * tsNumOfThreadsPerCore / 4.0;
if (numOfThreads < 1) { if (numOfThreads < 1) {
...@@ -72,7 +76,6 @@ int32_t mgmtInitShell() { ...@@ -72,7 +76,6 @@ int32_t mgmtInitShell() {
} }
SRpcInit rpcInit = {0}; SRpcInit rpcInit = {0};
rpcInit.localIp = tsAnyIp ? "0.0.0.0" : tsPrivateIp;
rpcInit.localPort = tsMnodeShellPort; rpcInit.localPort = tsMnodeShellPort;
rpcInit.label = "MND-shell"; rpcInit.label = "MND-shell";
rpcInit.numOfThreads = numOfThreads; rpcInit.numOfThreads = numOfThreads;
...@@ -103,6 +106,12 @@ void mgmtCleanUpShell() { ...@@ -103,6 +106,12 @@ void mgmtCleanUpShell() {
tsMgmtShellRpc = NULL; tsMgmtShellRpc = NULL;
mPrint("server connection to shell is closed"); mPrint("server connection to shell is closed");
} }
if (tsQhandleCache) {
taosCacheEmpty(tsQhandleCache);
taosCacheCleanup(tsQhandleCache);
tsQhandleCache = NULL;
}
} }
void mgmtAddShellMsgHandle(uint8_t showType, void (*fp)(SQueuedMsg *queuedMsg)) { void mgmtAddShellMsgHandle(uint8_t showType, void (*fp)(SQueuedMsg *queuedMsg)) {
...@@ -148,14 +157,12 @@ static void mgmtProcessMsgFromShell(SRpcMsg *rpcMsg) { ...@@ -148,14 +157,12 @@ static void mgmtProcessMsgFromShell(SRpcMsg *rpcMsg) {
if (!sdbIsMaster()) { if (!sdbIsMaster()) {
SRpcConnInfo connInfo; SRpcConnInfo connInfo;
rpcGetConnInfo(rpcMsg->handle, &connInfo); rpcGetConnInfo(rpcMsg->handle, &connInfo);
bool usePublicIp = (connInfo.serverIp == tsPublicIpInt);
SRpcIpSet ipSet = {0}; SRpcIpSet ipSet = {0};
ipSet.port = tsMnodeShellPort; mgmtGetMnodeIpSet(&ipSet);
dnodeGetMnodeIpSet(&ipSet, usePublicIp);
mTrace("conn from shell ip:%s user:%s redirect msg, inUse:%d", taosIpStr(connInfo.clientIp), connInfo.user, ipSet.inUse); mTrace("conn from shell ip:%s user:%s redirect msg, inUse:%d", taosIpStr(connInfo.clientIp), connInfo.user, ipSet.inUse);
for (int32_t i = 0; i < ipSet.numOfIps; ++i) { for (int32_t i = 0; i < ipSet.numOfIps; ++i) {
mTrace("index:%d ip:%s", i, taosIpStr(ipSet.ip[i])); mTrace("index:%d ip:%s:%d", i, ipSet.fqdn[i], ipSet.port[i]);
} }
rpcSendRedirectRsp(rpcMsg->handle, &ipSet); rpcSendRedirectRsp(rpcMsg->handle, &ipSet);
...@@ -236,14 +243,15 @@ static void mgmtProcessShowMsg(SQueuedMsg *pMsg) { ...@@ -236,14 +243,15 @@ static void mgmtProcessShowMsg(SQueuedMsg *pMsg) {
return; return;
} }
SShowObj *pShow = (SShowObj *) calloc(1, sizeof(SShowObj) + htons(pShowMsg->payloadLen)); int32_t showObjSize = sizeof(SShowObj) + htons(pShowMsg->payloadLen);
SShowObj *pShow = (SShowObj *) calloc(1, showObjSize);
pShow->signature = pShow; pShow->signature = pShow;
pShow->type = pShowMsg->type; pShow->type = pShowMsg->type;
pShow->payloadLen = htons(pShowMsg->payloadLen); pShow->payloadLen = htons(pShowMsg->payloadLen);
strcpy(pShow->db, pShowMsg->db); strcpy(pShow->db, pShowMsg->db);
memcpy(pShow->payload, pShowMsg->payload, pShow->payloadLen); memcpy(pShow->payload, pShowMsg->payload, pShow->payloadLen);
mgmtSaveQhandle(pShow); pShow = mgmtSaveQhandle(pShow, showObjSize);
pShowRsp->qhandle = htobe64((uint64_t) pShow); pShowRsp->qhandle = htobe64((uint64_t) pShow);
mTrace("show:%p, type:%s, start to get meta", pShow, mgmtGetShowTypeStr(pShowMsg->type)); mTrace("show:%p, type:%s, start to get meta", pShow, mgmtGetShowTypeStr(pShowMsg->type));
...@@ -258,7 +266,7 @@ static void mgmtProcessShowMsg(SQueuedMsg *pMsg) { ...@@ -258,7 +266,7 @@ static void mgmtProcessShowMsg(SQueuedMsg *pMsg) {
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
} else { } else {
mError("show:%p, type:%s, failed to get meta, reason:%s", pShow, mgmtGetShowTypeStr(pShowMsg->type), tstrerror(code)); mError("show:%p, type:%s, failed to get meta, reason:%s", pShow, mgmtGetShowTypeStr(pShowMsg->type), tstrerror(code));
mgmtFreeQhandle(pShow); mgmtFreeQhandle(pShow, false);
SRpcMsg rpcRsp = { SRpcMsg rpcRsp = {
.handle = pMsg->thandle, .handle = pMsg->thandle,
.code = code .code = code
...@@ -287,11 +295,6 @@ static void mgmtProcessRetrieveMsg(SQueuedMsg *pMsg) { ...@@ -287,11 +295,6 @@ static void mgmtProcessRetrieveMsg(SQueuedMsg *pMsg) {
SShowObj *pShow = (SShowObj *)pRetrieve->qhandle; SShowObj *pShow = (SShowObj *)pRetrieve->qhandle;
mTrace("show:%p, type:%s, retrieve data", pShow, mgmtGetShowTypeStr(pShow->type)); mTrace("show:%p, type:%s, retrieve data", pShow, mgmtGetShowTypeStr(pShow->type));
if (!mgmtCheckQhandle(pRetrieve->qhandle)) {
mError("pShow:%p, query memory is corrupted", pShow);
mgmtSendSimpleResp(pMsg->thandle, TSDB_CODE_MEMORY_CORRUPTED);
return;
} else {
if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) {
rowsToRead = pShow->numOfRows - pShow->numOfReads; rowsToRead = pShow->numOfRows - pShow->numOfReads;
} }
...@@ -305,7 +308,6 @@ static void mgmtProcessRetrieveMsg(SQueuedMsg *pMsg) { ...@@ -305,7 +308,6 @@ static void mgmtProcessRetrieveMsg(SQueuedMsg *pMsg) {
*/ */
if (rowsToRead < 0) rowsToRead = 0; if (rowsToRead < 0) rowsToRead = 0;
size = pShow->rowSize * rowsToRead; size = pShow->rowSize * rowsToRead;
}
size += 100; size += 100;
SRetrieveTableRsp *pRsp = rpcMallocCont(size); SRetrieveTableRsp *pRsp = rpcMallocCont(size);
...@@ -316,6 +318,7 @@ static void mgmtProcessRetrieveMsg(SQueuedMsg *pMsg) { ...@@ -316,6 +318,7 @@ static void mgmtProcessRetrieveMsg(SQueuedMsg *pMsg) {
if (rowsRead < 0) { // TSDB_CODE_ACTION_IN_PROGRESS; if (rowsRead < 0) { // TSDB_CODE_ACTION_IN_PROGRESS;
rpcFreeCont(pRsp); rpcFreeCont(pRsp);
mgmtFreeQhandle(pShow, false);
return; return;
} }
...@@ -332,7 +335,9 @@ static void mgmtProcessRetrieveMsg(SQueuedMsg *pMsg) { ...@@ -332,7 +335,9 @@ static void mgmtProcessRetrieveMsg(SQueuedMsg *pMsg) {
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
if (rowsToRead == 0) { if (rowsToRead == 0) {
mgmtFreeQhandle(pShow); mgmtFreeQhandle(pShow, true);
} else {
mgmtFreeQhandle(pShow, false);
} }
} }
...@@ -343,7 +348,7 @@ static void mgmtProcessHeartBeatMsg(SQueuedMsg *pMsg) { ...@@ -343,7 +348,7 @@ static void mgmtProcessHeartBeatMsg(SQueuedMsg *pMsg) {
return; return;
} }
mgmtGetMnodeIpSet(&pHBRsp->ipList, pMsg->usePublicIp); mgmtGetMnodeIpSet(&pHBRsp->ipList);
/* /*
* TODO * TODO
...@@ -416,6 +421,7 @@ static void mgmtProcessConnectMsg(SQueuedMsg *pMsg) { ...@@ -416,6 +421,7 @@ static void mgmtProcessConnectMsg(SQueuedMsg *pMsg) {
code = TSDB_CODE_INVALID_DB; code = TSDB_CODE_INVALID_DB;
goto connect_over; goto connect_over;
} }
mgmtDecDbRef(pDb);
} }
SCMConnectRsp *pConnectRsp = rpcMallocCont(sizeof(SCMConnectRsp)); SCMConnectRsp *pConnectRsp = rpcMallocCont(sizeof(SCMConnectRsp));
...@@ -429,7 +435,7 @@ static void mgmtProcessConnectMsg(SQueuedMsg *pMsg) { ...@@ -429,7 +435,7 @@ static void mgmtProcessConnectMsg(SQueuedMsg *pMsg) {
pConnectRsp->writeAuth = pUser->writeAuth; pConnectRsp->writeAuth = pUser->writeAuth;
pConnectRsp->superAuth = pUser->superAuth; pConnectRsp->superAuth = pUser->superAuth;
mgmtGetMnodeIpSet(&pConnectRsp->ipList, pMsg->usePublicIp); mgmtGetMnodeIpSet(&pConnectRsp->ipList);
connect_over: connect_over:
rpcRsp.code = code; rpcRsp.code = code;
...@@ -449,9 +455,8 @@ static void mgmtProcessUseMsg(SQueuedMsg *pMsg) { ...@@ -449,9 +455,8 @@ static void mgmtProcessUseMsg(SQueuedMsg *pMsg) {
SCMUseDbMsg *pUseDbMsg = pMsg->pCont; SCMUseDbMsg *pUseDbMsg = pMsg->pCont;
// todo check for priority of current user // todo check for priority of current user
pMsg->pDb = mgmtGetDb(pUseDbMsg->db);
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
if (pMsg->pDb == NULL) pMsg->pDb = mgmtGetDb(pUseDbMsg->db);
if (pMsg->pDb == NULL) { if (pMsg->pDb == NULL) {
code = TSDB_CODE_INVALID_DB; code = TSDB_CODE_INVALID_DB;
} }
...@@ -465,7 +470,7 @@ static void mgmtProcessUseMsg(SQueuedMsg *pMsg) { ...@@ -465,7 +470,7 @@ static void mgmtProcessUseMsg(SQueuedMsg *pMsg) {
*/ */
static bool mgmtCheckTableMetaMsgReadOnly(SQueuedMsg *pMsg) { static bool mgmtCheckTableMetaMsgReadOnly(SQueuedMsg *pMsg) {
SCMTableInfoMsg *pInfo = pMsg->pCont; SCMTableInfoMsg *pInfo = pMsg->pCont;
pMsg->pTable = mgmtGetTable(pInfo->tableId); if (pMsg->pTable == NULL) pMsg->pTable = mgmtGetTable(pInfo->tableId);
if (pMsg->pTable != NULL) return true; if (pMsg->pTable != NULL) return true;
// If table does not exists and autoCreate flag is set, we add the handler into task queue // If table does not exists and autoCreate flag is set, we add the handler into task queue
...@@ -514,3 +519,79 @@ void mgmtSendSimpleResp(void *thandle, int32_t code) { ...@@ -514,3 +519,79 @@ void mgmtSendSimpleResp(void *thandle, int32_t code) {
}; };
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
} }
bool mgmtCheckQhandle(uint64_t qhandle) {
void *pSaved = taosCacheAcquireByData(tsQhandleCache, (void *)qhandle);
if (pSaved == (void *)qhandle) {
mTrace("qhandle:%p is retrived", qhandle);
return true;
} else {
mTrace("qhandle:%p is already freed", qhandle);
return false;
}
}
void* mgmtSaveQhandle(void *qhandle, int32_t size) {
if (tsQhandleCache != NULL) {
char key[24];
sprintf(key, "show:%p", qhandle);
void *newQhandle = taosCachePut(tsQhandleCache, key, qhandle, size, 60);
free(qhandle);
mTrace("qhandle:%p is saved", newQhandle);
return newQhandle;
}
return NULL;
}
void mgmtFreeQhandle(void *qhandle, bool forceRemove) {
mTrace("qhandle:%p is freed", qhandle);
taosCacheRelease(tsQhandleCache, &qhandle, forceRemove);
}
void *mgmtMallocQueuedMsg(SRpcMsg *rpcMsg) {
SUserObj *pUser = mgmtGetUserFromConn(rpcMsg->handle);
if (pUser == NULL) {
return NULL;
}
SQueuedMsg *pMsg = calloc(1, sizeof(SQueuedMsg));
pMsg->thandle = rpcMsg->handle;
pMsg->msgType = rpcMsg->msgType;
pMsg->contLen = rpcMsg->contLen;
pMsg->pCont = rpcMsg->pCont;
pMsg->pUser = pUser;
return pMsg;
}
void mgmtFreeQueuedMsg(SQueuedMsg *pMsg) {
if (pMsg != NULL) {
rpcFreeCont(pMsg->pCont);
if (pMsg->pUser) mgmtDecUserRef(pMsg->pUser);
if (pMsg->pDb) mgmtDecDbRef(pMsg->pDb);
if (pMsg->pVgroup) mgmtDecVgroupRef(pMsg->pVgroup);
if (pMsg->pTable) mgmtDecTableRef(pMsg->pTable);
if (pMsg->pAcct) mgmtDecAcctRef(pMsg->pAcct);
if (pMsg->pDnode) mgmtDecDnodeRef(pMsg->pDnode);
free(pMsg);
}
}
void* mgmtCloneQueuedMsg(SQueuedMsg *pSrcMsg) {
SQueuedMsg *pDestMsg = calloc(1, sizeof(SQueuedMsg));
pDestMsg->thandle = pSrcMsg->thandle;
pDestMsg->msgType = pSrcMsg->msgType;
pDestMsg->pCont = pSrcMsg->pCont;
pDestMsg->contLen = pSrcMsg->contLen;
pDestMsg->retry = pSrcMsg->retry;
pDestMsg->maxRetry= pSrcMsg->maxRetry;
pDestMsg->pUser = pSrcMsg->pUser;
pSrcMsg->pCont = NULL;
pSrcMsg->pUser = NULL;
return pDestMsg;
}
\ No newline at end of file
此差异已折叠。
...@@ -168,8 +168,7 @@ static int32_t mgmtUpdateUser(SUserObj *pUser) { ...@@ -168,8 +168,7 @@ static int32_t mgmtUpdateUser(SUserObj *pUser) {
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
.table = tsUserSdb, .table = tsUserSdb,
.pObj = pUser, .pObj = pUser
.rowSize = tsUserUpdateSize
}; };
int32_t code = sdbUpdateRow(&oper); int32_t code = sdbUpdateRow(&oper);
...@@ -249,7 +248,7 @@ static int32_t mgmtDropUser(SUserObj *pUser) { ...@@ -249,7 +248,7 @@ static int32_t mgmtDropUser(SUserObj *pUser) {
} }
static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
SUserObj *pUser = mgmtGetUserFromConn(pConn, NULL); SUserObj *pUser = mgmtGetUserFromConn(pConn);
if (pUser == NULL) { if (pUser == NULL) {
return TSDB_CODE_NO_USER_FROM_CONN; return TSDB_CODE_NO_USER_FROM_CONN;
} }
...@@ -298,7 +297,7 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void ...@@ -298,7 +297,7 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void
char *pWrite; char *pWrite;
while (numOfRows < rows) { while (numOfRows < rows) {
pShow->pNode = sdbFetchRow(tsUserSdb, pShow->pNode, (void **) &pUser); pShow->pNode = mgmtGetNextUser(pShow->pNode, &pUser);
if (pUser == NULL) break; if (pUser == NULL) break;
cols = 0; cols = 0;
...@@ -329,12 +328,9 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void ...@@ -329,12 +328,9 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void
return numOfRows; return numOfRows;
} }
SUserObj *mgmtGetUserFromConn(void *pConn, bool *usePublicIp) { SUserObj *mgmtGetUserFromConn(void *pConn) {
SRpcConnInfo connInfo; SRpcConnInfo connInfo;
if (rpcGetConnInfo(pConn, &connInfo) == 0) { if (rpcGetConnInfo(pConn, &connInfo) == 0) {
if (usePublicIp) {
*usePublicIp = (connInfo.serverIp == tsPublicIpInt);
}
return mgmtGetUser(connInfo.user); return mgmtGetUser(connInfo.user);
} else { } else {
mError("can not get user from conn:%p", pConn); mError("can not get user from conn:%p", pConn);
...@@ -510,7 +506,7 @@ void mgmtDropAllUsers(SAcctObj *pAcct) { ...@@ -510,7 +506,7 @@ void mgmtDropAllUsers(SAcctObj *pAcct) {
while (1) { while (1) {
pLastNode = pNode; pLastNode = pNode;
pNode = sdbFetchRow(tsUserSdb, pNode, (void **)&pUser); pNode = mgmtGetNextUser(pNode, &pUser);
if (pUser == NULL) break; if (pUser == NULL) break;
if (strncmp(pUser->acct, pAcct->user, acctNameLen) == 0) { if (strncmp(pUser->acct, pAcct->user, acctNameLen) == 0) {
......
...@@ -36,8 +36,8 @@ ...@@ -36,8 +36,8 @@
#include "mgmtTable.h" #include "mgmtTable.h"
#include "mgmtVgroup.h" #include "mgmtVgroup.h"
void *tsVgroupSdb = NULL; static void *tsVgroupSdb = NULL;
int32_t tsVgUpdateSize = 0; static int32_t tsVgUpdateSize = 0;
static int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
static int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn);
...@@ -62,6 +62,8 @@ static int32_t mgmtVgroupActionDestroy(SSdbOper *pOper) { ...@@ -62,6 +62,8 @@ static int32_t mgmtVgroupActionDestroy(SSdbOper *pOper) {
static int32_t mgmtVgroupActionInsert(SSdbOper *pOper) { static int32_t mgmtVgroupActionInsert(SSdbOper *pOper) {
SVgObj *pVgroup = pOper->pObj; SVgObj *pVgroup = pOper->pObj;
// refer to db
SDbObj *pDb = mgmtGetDb(pVgroup->dbName); SDbObj *pDb = mgmtGetDb(pVgroup->dbName);
if (pDb == NULL) { if (pDb == NULL) {
return TSDB_CODE_INVALID_DB; return TSDB_CODE_INVALID_DB;
...@@ -74,13 +76,13 @@ static int32_t mgmtVgroupActionInsert(SSdbOper *pOper) { ...@@ -74,13 +76,13 @@ static int32_t mgmtVgroupActionInsert(SSdbOper *pOper) {
int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables; int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables;
pVgroup->tableList = calloc(pDb->cfg.maxTables, sizeof(SChildTableObj *)); pVgroup->tableList = calloc(pDb->cfg.maxTables, sizeof(SChildTableObj *));
if (pVgroup->tableList == NULL) { if (pVgroup->tableList == NULL) {
mError("vgroup:%d, failed to malloc(size:%d) for the tableList of vgroups", pVgroup->vgId, size); mError("vgId:%d, failed to malloc(size:%d) for the tableList of vgroups", pVgroup->vgId, size);
return -1; return -1;
} }
pVgroup->idPool = taosInitIdPool(pDb->cfg.maxTables); pVgroup->idPool = taosInitIdPool(pDb->cfg.maxTables);
if (pVgroup->idPool == NULL) { if (pVgroup->idPool == NULL) {
mError("vgroup:%d, failed to taosInitIdPool for vgroups", pVgroup->vgId); mError("vgId:%d, failed to taosInitIdPool for vgroups", pVgroup->vgId);
tfree(pVgroup->tableList); tfree(pVgroup->tableList);
return -1; return -1;
} }
...@@ -140,6 +142,7 @@ static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) { ...@@ -140,6 +142,7 @@ static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) {
if (pDnode != NULL) { if (pDnode != NULL) {
atomic_add_fetch_32(&pDnode->openVnodes, 1); atomic_add_fetch_32(&pDnode->openVnodes, 1);
} }
mgmtDecDnodeRef(pDnode);
} }
} }
...@@ -147,14 +150,15 @@ static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) { ...@@ -147,14 +150,15 @@ static int32_t mgmtVgroupActionUpdate(SSdbOper *pOper) {
SDbObj *pDb = pVgroup->pDb; SDbObj *pDb = pVgroup->pDb;
if (pDb != NULL) { if (pDb != NULL) {
if (pDb->cfg.maxTables != oldTables) { if (pDb->cfg.maxTables != oldTables) {
mPrint("vgroup:%d tables change from %d to %d", pVgroup->vgId, oldTables, pDb->cfg.maxTables); mPrint("vgId:%d tables change from %d to %d", pVgroup->vgId, oldTables, pDb->cfg.maxTables);
taosUpdateIdPool(pVgroup->idPool, pDb->cfg.maxTables); taosUpdateIdPool(pVgroup->idPool, pDb->cfg.maxTables);
int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables; int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables;
pVgroup->tableList = (SChildTableObj **)realloc(pVgroup->tableList, size); pVgroup->tableList = (SChildTableObj **)realloc(pVgroup->tableList, size);
} }
} }
mTrace("vgroup:%d, is updated, tables:%d numOfVnode:%d", pVgroup->vgId, pDb->cfg.maxTables, pVgroup->numOfVnodes); mgmtDecVgroupRef(pVgroup);
mTrace("vgId:%d, is updated, tables:%d numOfVnode:%d", pVgroup->vgId, pDb->cfg.maxTables, pVgroup->numOfVnodes);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -162,7 +166,7 @@ static int32_t mgmtVgroupActionEncode(SSdbOper *pOper) { ...@@ -162,7 +166,7 @@ static int32_t mgmtVgroupActionEncode(SSdbOper *pOper) {
SVgObj *pVgroup = pOper->pObj; SVgObj *pVgroup = pOper->pObj;
memcpy(pOper->rowData, pVgroup, tsVgUpdateSize); memcpy(pOper->rowData, pVgroup, tsVgUpdateSize);
SVgObj *pTmpVgroup = pOper->rowData; SVgObj *pTmpVgroup = pOper->rowData;
for (int32_t i = 0; i < TSDB_VNODES_SUPPORT; ++i) { for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
pTmpVgroup->vnodeGid[i].pDnode = NULL; pTmpVgroup->vnodeGid[i].pDnode = NULL;
pTmpVgroup->vnodeGid[i].role = 0; pTmpVgroup->vnodeGid[i].role = 0;
} }
...@@ -237,8 +241,7 @@ void mgmtUpdateVgroup(SVgObj *pVgroup) { ...@@ -237,8 +241,7 @@ void mgmtUpdateVgroup(SVgObj *pVgroup) {
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
.table = tsVgroupSdb, .table = tsVgroupSdb,
.pObj = pVgroup, .pObj = pVgroup
.rowSize = tsVgUpdateSize
}; };
sdbUpdateRow(&oper); sdbUpdateRow(&oper);
...@@ -260,8 +263,8 @@ void mgmtUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVlo ...@@ -260,8 +263,8 @@ void mgmtUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVlo
} }
if (!dnodeExist) { if (!dnodeExist) {
SRpcIpSet ipSet = mgmtGetIpSetFromIp(pDnode->privateIp); SRpcIpSet ipSet = mgmtGetIpSetFromIp(pDnode->dnodeEp);
mError("vgroup:%d, dnode:%d not exist in mnode, drop it", pVload->vgId, pDnode->dnodeId); mError("vgId:%d, dnode:%d not exist in mnode, drop it", pVload->vgId, pDnode->dnodeId);
mgmtSendDropVnodeMsg(pVload->vgId, &ipSet, NULL); mgmtSendDropVnodeMsg(pVload->vgId, &ipSet, NULL);
return; return;
} }
...@@ -273,7 +276,7 @@ void mgmtUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVlo ...@@ -273,7 +276,7 @@ void mgmtUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVlo
} }
if (pVload->cfgVersion != pVgroup->pDb->cfgVersion || pVload->replica != pVgroup->numOfVnodes) { if (pVload->cfgVersion != pVgroup->pDb->cfgVersion || pVload->replica != pVgroup->numOfVnodes) {
mError("dnode:%d, vgroup:%d, vnode cfgVersion:%d repica:%d not match with mgmt cfgVersion:%d replica:%d", mError("dnode:%d, vgId:%d, vnode cfgVersion:%d repica:%d not match with mgmt cfgVersion:%d replica:%d",
pDnode->dnodeId, pVload->vgId, pVload->cfgVersion, pVload->replica, pVgroup->pDb->cfgVersion, pDnode->dnodeId, pVload->vgId, pVload->cfgVersion, pVload->replica, pVgroup->pDb->cfgVersion,
pVgroup->numOfVnodes); pVgroup->numOfVnodes);
mgmtSendCreateVgroupMsg(pVgroup, NULL); mgmtSendCreateVgroupMsg(pVgroup, NULL);
...@@ -317,9 +320,9 @@ void mgmtCreateVgroup(SQueuedMsg *pMsg, SDbObj *pDb) { ...@@ -317,9 +320,9 @@ void mgmtCreateVgroup(SQueuedMsg *pMsg, SDbObj *pDb) {
return; return;
} }
mPrint("vgroup:%d, is created in mnode, db:%s replica:%d", pVgroup->vgId, pDb->name, pVgroup->numOfVnodes); mPrint("vgId:%d, is created in mnode, db:%s replica:%d", pVgroup->vgId, pDb->name, pVgroup->numOfVnodes);
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
mPrint("vgroup:%d, index:%d, dnode:%d", pVgroup->vgId, i, pVgroup->vnodeGid[i].dnodeId); mPrint("vgId:%d, index:%d, dnode:%d", pVgroup->vgId, i, pVgroup->vnodeGid[i].dnodeId);
} }
pMsg->ahandle = pVgroup; pMsg->ahandle = pVgroup;
...@@ -331,7 +334,7 @@ void mgmtDropVgroup(SVgObj *pVgroup, void *ahandle) { ...@@ -331,7 +334,7 @@ void mgmtDropVgroup(SVgObj *pVgroup, void *ahandle) {
if (ahandle != NULL) { if (ahandle != NULL) {
mgmtSendDropVgroupMsg(pVgroup, ahandle); mgmtSendDropVgroupMsg(pVgroup, ahandle);
} else { } else {
mTrace("vgroup:%d, replica:%d is deleting from sdb", pVgroup->vgId, pVgroup->numOfVnodes); mTrace("vgId:%d, replica:%d is deleting from sdb", pVgroup->vgId, pVgroup->numOfVnodes);
mgmtSendDropVgroupMsg(pVgroup, NULL); mgmtSendDropVgroupMsg(pVgroup, NULL);
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_GLOBAL, .type = SDB_OPER_GLOBAL,
...@@ -379,6 +382,7 @@ int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { ...@@ -379,6 +382,7 @@ int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
if (pShow->payloadLen > 0 ) { if (pShow->payloadLen > 0 ) {
pTable = mgmtGetTable(pShow->payload); pTable = mgmtGetTable(pShow->payload);
if (NULL == pTable || pTable->type == TSDB_SUPER_TABLE) { if (NULL == pTable || pTable->type == TSDB_SUPER_TABLE) {
mgmtDecTableRef(pTable);
return TSDB_CODE_INVALID_TABLE_ID; return TSDB_CODE_INVALID_TABLE_ID;
} }
mgmtDecTableRef(pTable); mgmtDecTableRef(pTable);
...@@ -401,9 +405,9 @@ int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { ...@@ -401,9 +405,9 @@ int32_t mgmtGetVgroupMeta(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] = 16; pShow->bytes[cols] = 40;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "ip"); strcpy(pSchema[cols].name, "end point");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htons(pShow->bytes[cols]);
cols++; cols++;
...@@ -440,7 +444,6 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo ...@@ -440,7 +444,6 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
int32_t maxReplica = 0; int32_t maxReplica = 0;
int32_t cols = 0; int32_t cols = 0;
char ipstr[20];
char * pWrite; char * pWrite;
SDbObj *pDb = mgmtGetDb(pShow->db); SDbObj *pDb = mgmtGetDb(pShow->db);
...@@ -479,10 +482,10 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo ...@@ -479,10 +482,10 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo
SDnodeObj *pDnode = pVgroup->vnodeGid[i].pDnode; SDnodeObj *pDnode = pVgroup->vnodeGid[i].pDnode;
if (pDnode != NULL) { if (pDnode != NULL) {
tinet_ntoa(ipstr, pDnode->privateIp);
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, ipstr); strncpy(pWrite, pDnode->dnodeEp, pShow->bytes[cols]-1);
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
strcpy(pWrite, mgmtGetMnodeRoleStr(pVgroup->vnodeGid[i].role)); strcpy(pWrite, mgmtGetMnodeRoleStr(pVgroup->vnodeGid[i].role));
cols++; cols++;
...@@ -506,25 +509,28 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo ...@@ -506,25 +509,28 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo
} }
void mgmtAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable) { void mgmtAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable) {
if (pTable->sid >= 0 && pVgroup->tableList[pTable->sid] == NULL) { if (pTable->sid >= 1 && pVgroup->tableList[pTable->sid - 1] == NULL) {
pVgroup->tableList[pTable->sid] = pTable; pVgroup->tableList[pTable->sid - 1] = pTable;
taosIdPoolMarkStatus(pVgroup->idPool, pTable->sid); taosIdPoolMarkStatus(pVgroup->idPool, pTable->sid);
pVgroup->numOfTables++; pVgroup->numOfTables++;
} }
if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxTables) if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxTables) {
mgmtAddVgroupIntoDbTail(pVgroup); mgmtMoveVgroupToTail(pVgroup);
}
mgmtIncVgroupRef(pVgroup);
} }
void mgmtRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable) { void mgmtRemoveTableFromVgroup(SVgObj *pVgroup, SChildTableObj *pTable) {
if (pTable->sid >= 0 && pVgroup->tableList[pTable->sid] != NULL) { if (pTable->sid >= 1 && pVgroup->tableList[pTable->sid - 1] != NULL) {
pVgroup->tableList[pTable->sid] = NULL; pVgroup->tableList[pTable->sid - 1] = NULL;
taosFreeId(pVgroup->idPool, pTable->sid); taosFreeId(pVgroup->idPool, pTable->sid);
pVgroup->numOfTables--; pVgroup->numOfTables--;
} }
if (pVgroup->numOfTables >= pVgroup->pDb->cfg.maxTables) mgmtMoveVgroupToHead(pVgroup);
mgmtAddVgroupIntoDbTail(pVgroup); mgmtDecVgroupRef(pVgroup);
} }
SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) { SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) {
...@@ -559,11 +565,7 @@ SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) { ...@@ -559,11 +565,7 @@ SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) {
SDnodeObj *pDnode = pVgroup->vnodeGid[j].pDnode; SDnodeObj *pDnode = pVgroup->vnodeGid[j].pDnode;
if (pDnode != NULL) { if (pDnode != NULL) {
pNodes[j].nodeId = htonl(pDnode->dnodeId); pNodes[j].nodeId = htonl(pDnode->dnodeId);
pNodes[j].nodeIp = htonl(pDnode->privateIp); strcpy(pNodes[j].nodeEp, pDnode->dnodeEp);
strcpy(pNodes[j].nodeName, pDnode->dnodeName);
if (j == 0) {
pCfg->arbitratorIp = htonl(pDnode->privateIp);
}
} }
} }
...@@ -574,26 +576,26 @@ SRpcIpSet mgmtGetIpSetFromVgroup(SVgObj *pVgroup) { ...@@ -574,26 +576,26 @@ SRpcIpSet mgmtGetIpSetFromVgroup(SVgObj *pVgroup) {
SRpcIpSet ipSet = { SRpcIpSet ipSet = {
.numOfIps = pVgroup->numOfVnodes, .numOfIps = pVgroup->numOfVnodes,
.inUse = 0, .inUse = 0,
.port = tsDnodeMnodePort
}; };
for (int i = 0; i < pVgroup->numOfVnodes; ++i) { for (int i = 0; i < pVgroup->numOfVnodes; ++i) {
ipSet.ip[i] = pVgroup->vnodeGid[i].pDnode->privateIp; strcpy(ipSet.fqdn[i], pVgroup->vnodeGid[i].pDnode->dnodeFqdn);
ipSet.port[i] = pVgroup->vnodeGid[i].pDnode->dnodePort + TSDB_PORT_DNODEMNODE;
} }
return ipSet; return ipSet;
} }
SRpcIpSet mgmtGetIpSetFromIp(uint32_t ip) { SRpcIpSet mgmtGetIpSetFromIp(char *ep) {
SRpcIpSet ipSet = { SRpcIpSet ipSet;
.ip[0] = ip,
.numOfIps = 1, ipSet.numOfIps = 1;
.inUse = 0, ipSet.inUse = 0;
.port = tsDnodeMnodePort taosGetFqdnPortFromEp(ep, ipSet.fqdn[0], &ipSet.port[0]);
}; ipSet.port[0] += TSDB_PORT_DNODEMNODE;
return ipSet; return ipSet;
} }
void mgmtSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle) { void mgmtSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle) {
mTrace("vgroup:%d, send create vnode:%d msg, ahandle:%p", pVgroup->vgId, pVgroup->vgId, ahandle); mTrace("vgId:%d, send create vnode:%d msg, ahandle:%p", pVgroup->vgId, pVgroup->vgId, ahandle);
SMDCreateVnodeMsg *pCreate = mgmtBuildCreateVnodeMsg(pVgroup); SMDCreateVnodeMsg *pCreate = mgmtBuildCreateVnodeMsg(pVgroup);
SRpcMsg rpcMsg = { SRpcMsg rpcMsg = {
.handle = ahandle, .handle = ahandle,
...@@ -606,9 +608,9 @@ void mgmtSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle) { ...@@ -606,9 +608,9 @@ void mgmtSendCreateVnodeMsg(SVgObj *pVgroup, SRpcIpSet *ipSet, void *ahandle) {
} }
void mgmtSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle) { void mgmtSendCreateVgroupMsg(SVgObj *pVgroup, void *ahandle) {
mTrace("vgroup:%d, send create all vnodes msg, ahandle:%p", pVgroup->vgId, ahandle); mTrace("vgId:%d, send create all vnodes msg, ahandle:%p", pVgroup->vgId, ahandle);
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
SRpcIpSet ipSet = mgmtGetIpSetFromIp(pVgroup->vnodeGid[i].pDnode->privateIp); SRpcIpSet ipSet = mgmtGetIpSetFromIp(pVgroup->vnodeGid[i].pDnode->dnodeEp);
mgmtSendCreateVnodeMsg(pVgroup, &ipSet, ahandle); mgmtSendCreateVnodeMsg(pVgroup, &ipSet, ahandle);
} }
} }
...@@ -624,7 +626,7 @@ static void mgmtProcessCreateVnodeRsp(SRpcMsg *rpcMsg) { ...@@ -624,7 +626,7 @@ static void mgmtProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
} }
SVgObj *pVgroup = queueMsg->ahandle; SVgObj *pVgroup = queueMsg->ahandle;
mTrace("vgroup:%d, create vnode rsp received, result:%s received:%d successed:%d expected:%d, thandle:%p ahandle:%p", mTrace("vgId:%d, create vnode rsp received, result:%s received:%d successed:%d expected:%d, thandle:%p ahandle:%p",
pVgroup->vgId, tstrerror(rpcMsg->code), queueMsg->received, queueMsg->successed, queueMsg->expected, pVgroup->vgId, tstrerror(rpcMsg->code), queueMsg->received, queueMsg->successed, queueMsg->expected,
queueMsg->thandle, rpcMsg->handle); queueMsg->thandle, rpcMsg->handle);
...@@ -659,7 +661,7 @@ static SMDDropVnodeMsg *mgmtBuildDropVnodeMsg(int32_t vgId) { ...@@ -659,7 +661,7 @@ static SMDDropVnodeMsg *mgmtBuildDropVnodeMsg(int32_t vgId) {
} }
void mgmtSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle) { void mgmtSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle) {
mTrace("vgroup:%d, send drop vnode msg, ahandle:%p", vgId, ahandle); mTrace("vgId:%d, send drop vnode msg, ahandle:%p", vgId, ahandle);
SMDDropVnodeMsg *pDrop = mgmtBuildDropVnodeMsg(vgId); SMDDropVnodeMsg *pDrop = mgmtBuildDropVnodeMsg(vgId);
SRpcMsg rpcMsg = { SRpcMsg rpcMsg = {
.handle = ahandle, .handle = ahandle,
...@@ -672,15 +674,15 @@ void mgmtSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle) { ...@@ -672,15 +674,15 @@ void mgmtSendDropVnodeMsg(int32_t vgId, SRpcIpSet *ipSet, void *ahandle) {
} }
static void mgmtSendDropVgroupMsg(SVgObj *pVgroup, void *ahandle) { static void mgmtSendDropVgroupMsg(SVgObj *pVgroup, void *ahandle) {
mTrace("vgroup:%d, send drop all vnodes msg, ahandle:%p", pVgroup->vgId, ahandle); mTrace("vgId:%d, send drop all vnodes msg, ahandle:%p", pVgroup->vgId, ahandle);
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) { for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
SRpcIpSet ipSet = mgmtGetIpSetFromIp(pVgroup->vnodeGid[i].pDnode->privateIp); SRpcIpSet ipSet = mgmtGetIpSetFromIp(pVgroup->vnodeGid[i].pDnode->dnodeEp);
mgmtSendDropVnodeMsg(pVgroup->vgId, &ipSet, ahandle); mgmtSendDropVnodeMsg(pVgroup->vgId, &ipSet, ahandle);
} }
} }
static void mgmtProcessDropVnodeRsp(SRpcMsg *rpcMsg) { static void mgmtProcessDropVnodeRsp(SRpcMsg *rpcMsg) {
mTrace("drop vnode rsp is received"); mTrace("drop vnode rsp is received, handle:%p", rpcMsg->handle);
if (rpcMsg->handle == NULL) return; if (rpcMsg->handle == NULL) return;
SQueuedMsg *queueMsg = rpcMsg->handle; SQueuedMsg *queueMsg = rpcMsg->handle;
...@@ -691,7 +693,7 @@ static void mgmtProcessDropVnodeRsp(SRpcMsg *rpcMsg) { ...@@ -691,7 +693,7 @@ static void mgmtProcessDropVnodeRsp(SRpcMsg *rpcMsg) {
} }
SVgObj *pVgroup = queueMsg->ahandle; SVgObj *pVgroup = queueMsg->ahandle;
mTrace("vgroup:%d, drop vnode rsp received, result:%s received:%d successed:%d expected:%d, thandle:%p ahandle:%p", mTrace("vgId:%d, drop vnode rsp received, result:%s received:%d successed:%d expected:%d, thandle:%p ahandle:%p",
pVgroup->vgId, tstrerror(rpcMsg->code), queueMsg->received, queueMsg->successed, queueMsg->expected, pVgroup->vgId, tstrerror(rpcMsg->code), queueMsg->received, queueMsg->successed, queueMsg->expected,
queueMsg->thandle, rpcMsg->handle); queueMsg->thandle, rpcMsg->handle);
...@@ -737,24 +739,49 @@ static void mgmtProcessVnodeCfgMsg(SRpcMsg *rpcMsg) { ...@@ -737,24 +739,49 @@ static void mgmtProcessVnodeCfgMsg(SRpcMsg *rpcMsg) {
mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_SUCCESS); mgmtSendSimpleResp(rpcMsg->handle, TSDB_CODE_SUCCESS);
SRpcIpSet ipSet = mgmtGetIpSetFromIp(pDnode->privateIp); SRpcIpSet ipSet = mgmtGetIpSetFromIp(pDnode->dnodeEp);
mgmtSendCreateVnodeMsg(pVgroup, &ipSet, NULL); mgmtSendCreateVnodeMsg(pVgroup, &ipSet, NULL);
} }
void mgmtDropAllVgroups(SDbObj *pDropDb) { void mgmtDropAllDnodeVgroups(SDnodeObj *pDropDnode) {
void * pNode = NULL;
void * pLastNode = NULL;
SVgObj *pVgroup = NULL;
int32_t numOfVgroups = 0;
while (1) {
pLastNode = pNode;
pNode = mgmtGetNextVgroup(pNode, &pVgroup);
if (pVgroup == NULL) break;
if (pVgroup->vnodeGid[0].dnodeId == pDropDnode->dnodeId) {
SSdbOper oper = {
.type = SDB_OPER_LOCAL,
.table = tsVgroupSdb,
.pObj = pVgroup,
};
sdbDeleteRow(&oper);
pNode = pLastNode;
numOfVgroups++;
continue;
}
mgmtDecVgroupRef(pVgroup);
}
}
void mgmtDropAllDbVgroups(SDbObj *pDropDb) {
void *pNode = NULL; void *pNode = NULL;
void *pLastNode = NULL; void *pLastNode = NULL;
int32_t numOfVgroups = 0; int32_t numOfVgroups = 0;
int32_t dbNameLen = strlen(pDropDb->name);
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
mPrint("db:%s, all vgroups will be dropped from sdb", pDropDb->name); mPrint("db:%s, all vgroups will be dropped from sdb", pDropDb->name);
while (1) { while (1) {
pNode = sdbFetchRow(tsVgroupSdb, pNode, (void **)&pVgroup); pLastNode = pNode;
pNode = mgmtGetNextVgroup(pNode, &pVgroup);
if (pVgroup == NULL) break; if (pVgroup == NULL) break;
if (strncmp(pDropDb->name, pVgroup->dbName, dbNameLen) == 0) { if (pVgroup->pDb == pDropDb) {
SSdbOper oper = { SSdbOper oper = {
.type = SDB_OPER_LOCAL, .type = SDB_OPER_LOCAL,
.table = tsVgroupSdb, .table = tsVgroupSdb,
...@@ -763,9 +790,9 @@ void mgmtDropAllVgroups(SDbObj *pDropDb) { ...@@ -763,9 +790,9 @@ void mgmtDropAllVgroups(SDbObj *pDropDb) {
sdbDeleteRow(&oper); sdbDeleteRow(&oper);
pNode = pLastNode; pNode = pLastNode;
numOfVgroups++; numOfVgroups++;
mgmtSendDropVgroupMsg(pVgroup, NULL);
} }
mgmtSendDropVgroupMsg(pVgroup, NULL);
mgmtDecVgroupRef(pVgroup); mgmtDecVgroupRef(pVgroup);
} }
......
...@@ -23,8 +23,8 @@ void osInit() { ...@@ -23,8 +23,8 @@ void osInit() {
strcpy(tsVnodeDir, ""); strcpy(tsVnodeDir, "");
strcpy(tsDnodeDir, ""); strcpy(tsDnodeDir, "");
strcpy(tsMnodeDir, ""); strcpy(tsMnodeDir, "");
strcpy(dataDir, "/var/lib/taos"); strcpy(tsDataDir, "/var/lib/taos");
strcpy(logDir, "~/TDengineLog"); strcpy(tsLogDir, "~/TDengineLog");
strcpy(scriptDir, "/etc/taos"); strcpy(tsScriptDir, "/etc/taos");
strcpy(osName, "Darwin"); strcpy(tsOsName, "Darwin");
} }
...@@ -151,67 +151,6 @@ int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optle ...@@ -151,67 +151,6 @@ int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optle
return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen); return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen);
} }
int taosOpenUDClientSocket(char *ip, uint16_t port) {
int sockFd = 0;
struct sockaddr_un serverAddr;
int ret;
char name[128];
sprintf(name, "%s.%hu", ip, port);
sockFd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sockFd < 0) {
uError("failed to open the UD socket:%s, reason:%s", name, strerror(errno));
return -1;
}
memset((char *)&serverAddr, 0, sizeof(serverAddr));
serverAddr.sun_family = AF_UNIX;
strcpy(serverAddr.sun_path + 1, name);
ret = connect(sockFd, (struct sockaddr *)&serverAddr, sizeof(serverAddr));
if (ret != 0) {
uError("failed to connect UD socket, name:%d, reason: %s", name, strerror(errno));
sockFd = -1;
}
return sockFd;
}
int taosOpenUDServerSocket(char *ip, uint16_t port) {
struct sockaddr_un serverAdd;
int sockFd;
char name[128];
uTrace("open ud socket:%s", name);
sprintf(name, "%s.%hu", ip, port);
bzero((char *)&serverAdd, sizeof(serverAdd));
serverAdd.sun_family = AF_UNIX;
strcpy(serverAdd.sun_path + 1, name);
unlink(name);
if ((sockFd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
uError("failed to open UD socket:%s, reason:%s", name, strerror(errno));
return -1;
}
/* bind socket to server address */
if (bind(sockFd, (struct sockaddr *)&serverAdd, sizeof(serverAdd)) < 0) {
uError("bind socket:%s failed, reason:%s", name, strerror(errno));
tclose(sockFd);
return -1;
}
if (listen(sockFd, 10) < 0) {
uError("listen socket:%s failed, reason:%s", name, strerror(errno));
return -1;
}
return sockFd;
}
int taosInitTimer(void (*callback)(int), int ms) { int taosInitTimer(void (*callback)(int), int ms) {
signal(SIGALRM, callback); signal(SIGALRM, callback);
......
...@@ -23,8 +23,8 @@ void osInit() { ...@@ -23,8 +23,8 @@ void osInit() {
strcpy(tsVnodeDir, ""); strcpy(tsVnodeDir, "");
strcpy(tsDnodeDir, ""); strcpy(tsDnodeDir, "");
strcpy(tsMnodeDir, ""); strcpy(tsMnodeDir, "");
strcpy(dataDir, "/var/lib/taos"); strcpy(tsDataDir, "/var/lib/taos");
strcpy(logDir, "/var/log/taos"); strcpy(tsLogDir, "/var/log/taos");
strcpy(scriptDir, "/etc/taos"); strcpy(tsScriptDir, "/etc/taos");
strcpy(osName, "Linux"); strcpy(tsOsName, "Linux");
} }
\ No newline at end of file
...@@ -143,68 +143,6 @@ int taosSetNonblocking(int sock, int on) { ...@@ -143,68 +143,6 @@ int taosSetNonblocking(int sock, int on) {
int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) { int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen) {
return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen); return setsockopt(socketfd, level, optname, optval, (socklen_t)optlen);
} }
int taosOpenUDClientSocket(char *ip, uint16_t port) {
int sockFd = 0;
struct sockaddr_un serverAddr;
int ret;
char name[128];
sprintf(name, "%s.%hu", ip, port);
sockFd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sockFd < 0) {
uError("failed to open the UD socket:%s, reason:%s", name, strerror(errno));
return -1;
}
memset((char *)&serverAddr, 0, sizeof(serverAddr));
serverAddr.sun_family = AF_UNIX;
strcpy(serverAddr.sun_path + 1, name);
ret = connect(sockFd, (struct sockaddr *)&serverAddr, sizeof(serverAddr));
if (ret != 0) {
uError("failed to connect UD socket, name:%d, reason: %s", name, strerror(errno));
sockFd = -1;
}
return sockFd;
}
int taosOpenUDServerSocket(char *ip, uint16_t port) {
struct sockaddr_un serverAdd;
int sockFd;
char name[128];
uTrace("open ud socket:%s", name);
sprintf(name, "%s.%hu", ip, port);
bzero((char *)&serverAdd, sizeof(serverAdd));
serverAdd.sun_family = AF_UNIX;
strcpy(serverAdd.sun_path + 1, name);
unlink(name);
if ((sockFd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
uError("failed to open UD socket:%s, reason:%s", name, strerror(errno));
return -1;
}
/* bind socket to server address */
if (bind(sockFd, (struct sockaddr *)&serverAdd, sizeof(serverAdd)) < 0) {
uError("bind socket:%s failed, reason:%s", name, strerror(errno));
tclose(sockFd);
return -1;
}
if (listen(sockFd, 10) < 0) {
uError("listen socket:%s failed, reason:%s", name, strerror(errno));
return -1;
}
return sockFd;
}
static void taosDeleteTimer(void *tharg) { static void taosDeleteTimer(void *tharg) {
timer_t *pTimer = tharg; timer_t *pTimer = tharg;
timer_delete(*pTimer); timer_delete(*pTimer);
......
...@@ -292,9 +292,10 @@ bool taosGetDisk() { ...@@ -292,9 +292,10 @@ bool taosGetDisk() {
const double unit = 1024 * 1024 * 1024; const double unit = 1024 * 1024 * 1024;
if (tscEmbedded) { if (tscEmbedded) {
if (statvfs(dataDir, &info)) { if (statvfs(tsDataDir, &info)) {
tsTotalDataDirGB = 0; //tsTotalDataDirGB = 0;
tsAvailDataDirGB = 0; //tsAvailDataDirGB = 0;
uError("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
return false; return false;
} else { } else {
tsTotalDataDirGB = (float)((double)info.f_blocks * (double)info.f_frsize / unit); tsTotalDataDirGB = (float)((double)info.f_blocks * (double)info.f_frsize / unit);
...@@ -302,9 +303,10 @@ bool taosGetDisk() { ...@@ -302,9 +303,10 @@ bool taosGetDisk() {
} }
} }
if (statvfs(logDir, &info)) { if (statvfs(tsLogDir, &info)) {
tsTotalLogDirGB = 0; //tsTotalLogDirGB = 0;
tsAvailLogDirGB = 0; //tsAvailLogDirGB = 0;
uError("failed to get disk size, logDir:%s errno:%s", tsLogDir, strerror(errno));
return false; return false;
} else { } else {
tsTotalLogDirGB = (float)((double)info.f_blocks * (double)info.f_frsize / unit); tsTotalLogDirGB = (float)((double)info.f_blocks * (double)info.f_frsize / unit);
...@@ -312,8 +314,9 @@ bool taosGetDisk() { ...@@ -312,8 +314,9 @@ bool taosGetDisk() {
} }
if (statvfs("/tmp", &info)) { if (statvfs("/tmp", &info)) {
tsTotalTmpDirGB = 0; //tsTotalTmpDirGB = 0;
tsAvailTmpDirGB = 0; //tsAvailTmpDirGB = 0;
uError("failed to get disk size, tmpDir:/tmp errno:%s", strerror(errno));
return false; return false;
} else { } else {
tsTotalTmpDirGB = (float)((double)info.f_blocks * (double)info.f_frsize / unit); tsTotalTmpDirGB = (float)((double)info.f_blocks * (double)info.f_frsize / unit);
...@@ -361,6 +364,8 @@ static bool taosGetCardName(char *ip, char *name) { ...@@ -361,6 +364,8 @@ static bool taosGetCardName(char *ip, char *name) {
static bool taosGetCardInfo(int64_t *bytes) { static bool taosGetCardInfo(int64_t *bytes) {
static char tsPublicCard[1000] = {0}; static char tsPublicCard[1000] = {0};
static char tsPrivateIp[40];
if (tsPublicCard[0] == 0) { if (tsPublicCard[0] == 0) {
if (!taosGetCardName(tsPrivateIp, tsPublicCard)) { if (!taosGetCardName(tsPrivateIp, tsPublicCard)) {
uError("can't get card name from ip:%s", tsPrivateIp); uError("can't get card name from ip:%s", tsPrivateIp);
......
...@@ -23,8 +23,8 @@ void osInit() { ...@@ -23,8 +23,8 @@ void osInit() {
strcpy(tsVnodeDir, "C:/TDengine/data"); strcpy(tsVnodeDir, "C:/TDengine/data");
strcpy(tsDnodeDir, ""); strcpy(tsDnodeDir, "");
strcpy(tsMnodeDir, ""); strcpy(tsMnodeDir, "");
strcpy(dataDir, "C:/TDengine/data"); strcpy(tsDataDir, "C:/TDengine/data");
strcpy(logDir, "C:/TDengine/log"); strcpy(tsLogDir, "C:/TDengine/log");
strcpy(scriptDir, "C:/TDengine/script"); strcpy(tsScriptDir, "C:/TDengine/script");
strcpy(osName, "Windows"); strcpy(tsOsName, "Windows");
} }
\ No newline at end of file
...@@ -210,7 +210,7 @@ typedef struct HttpThread { ...@@ -210,7 +210,7 @@ typedef struct HttpThread {
typedef struct HttpServer { typedef struct HttpServer {
char label[HTTP_LABEL_SIZE]; char label[HTTP_LABEL_SIZE];
char serverIp[16]; uint32_t serverIp;
uint16_t serverPort; uint16_t serverPort;
int cacheContext; int cacheContext;
int sessionExpire; int sessionExpire;
......
...@@ -48,7 +48,7 @@ int httpInitSystem() { ...@@ -48,7 +48,7 @@ int httpInitSystem() {
memset(httpServer, 0, sizeof(HttpServer)); memset(httpServer, 0, sizeof(HttpServer));
strcpy(httpServer->label, "rest"); strcpy(httpServer->label, "rest");
strcpy(httpServer->serverIp, tsHttpIp); httpServer->serverIp = 0;
httpServer->serverPort = tsHttpPort; httpServer->serverPort = tsHttpPort;
httpServer->cacheContext = tsHttpCacheSessions; httpServer->cacheContext = tsHttpCacheSessions;
httpServer->sessionExpire = tsHttpSessionExpire; httpServer->sessionExpire = tsHttpSessionExpire;
...@@ -117,7 +117,7 @@ void httpCleanUpSystem() { ...@@ -117,7 +117,7 @@ void httpCleanUpSystem() {
httpPrint("http service cleanup"); httpPrint("http service cleanup");
httpStopSystem(); httpStopSystem();
#if 1 #if 0
if (httpServer == NULL) { if (httpServer == NULL) {
return; return;
} }
......
...@@ -68,7 +68,7 @@ typedef enum { ...@@ -68,7 +68,7 @@ typedef enum {
typedef struct { typedef struct {
void * conn; void * conn;
void * timer; void * timer;
char privateIpStr[TSDB_IPv4ADDR_LEN]; char ep[TSDB_FQDN_LEN];
int8_t cmdIndex; int8_t cmdIndex;
int8_t state; int8_t state;
char sql[SQL_LENGTH]; char sql[SQL_LENGTH];
...@@ -112,14 +112,8 @@ static void monitorInitConn(void *para, void *unused) { ...@@ -112,14 +112,8 @@ static void monitorInitConn(void *para, void *unused) {
monitorPrint("starting to initialize monitor service .."); monitorPrint("starting to initialize monitor service ..");
tsMonitorConn.state = MONITOR_STATE_INITIALIZING; tsMonitorConn.state = MONITOR_STATE_INITIALIZING;
if (tsMonitorConn.privateIpStr[0] == 0) { if (tsMonitorConn.ep[0] == 0)
strcpy(tsMonitorConn.privateIpStr, tsPrivateIp); strcpy(tsMonitorConn.ep, tsLocalEp);
for (int32_t i = 0; i < TSDB_IPv4ADDR_LEN; ++i) {
if (tsMonitorConn.privateIpStr[i] == '.') {
tsMonitorConn.privateIpStr[i] = '_';
}
}
}
if (tsMonitorConn.conn == NULL) { if (tsMonitorConn.conn == NULL) {
taos_connect_a(NULL, "monitor", tsInternalPass, "", 0, monitorInitConnCb, &tsMonitorConn, &(tsMonitorConn.conn)); taos_connect_a(NULL, "monitor", tsInternalPass, "", 0, monitorInitConnCb, &tsMonitorConn, &(tsMonitorConn.conn));
...@@ -163,7 +157,7 @@ static void dnodeBuildMonitorSql(char *sql, int32_t cmd) { ...@@ -163,7 +157,7 @@ static void dnodeBuildMonitorSql(char *sql, int32_t cmd) {
tsMonitorDbName, IP_LEN_STR + 1); tsMonitorDbName, IP_LEN_STR + 1);
} else if (cmd == MONITOR_CMD_CREATE_TB_DN) { } else if (cmd == MONITOR_CMD_CREATE_TB_DN) {
snprintf(sql, SQL_LENGTH, "create table if not exists %s.dn_%s using %s.dn tags('%s')", tsMonitorDbName, snprintf(sql, SQL_LENGTH, "create table if not exists %s.dn_%s using %s.dn tags('%s')", tsMonitorDbName,
tsMonitorConn.privateIpStr, tsMonitorDbName, tsPrivateIp); tsMonitorConn.ep, tsMonitorDbName, tsLocalEp);
} else if (cmd == MONITOR_CMD_CREATE_MT_ACCT) { } else if (cmd == MONITOR_CMD_CREATE_MT_ACCT) {
snprintf(sql, SQL_LENGTH, snprintf(sql, SQL_LENGTH,
"create table if not exists %s.acct(ts timestamp " "create table if not exists %s.acct(ts timestamp "
...@@ -214,7 +208,7 @@ static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) { ...@@ -214,7 +208,7 @@ static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) {
if (-code == TSDB_CODE_TABLE_ALREADY_EXIST || -code == TSDB_CODE_DB_ALREADY_EXIST || code >= 0) { if (-code == TSDB_CODE_TABLE_ALREADY_EXIST || -code == TSDB_CODE_DB_ALREADY_EXIST || code >= 0) {
monitorTrace("monitor:%p, sql success, reason:%d, %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql); monitorTrace("monitor:%p, sql success, reason:%d, %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql);
if (tsMonitorConn.cmdIndex == MONITOR_CMD_CREATE_TB_LOG) { if (tsMonitorConn.cmdIndex == MONITOR_CMD_CREATE_TB_LOG) {
monitorPrint("dnode:%s is started", tsPrivateIp); monitorPrint("dnode:%s is started", tsLocalEp);
} }
tsMonitorConn.cmdIndex++; tsMonitorConn.cmdIndex++;
monitorInitDatabase(); monitorInitDatabase();
...@@ -346,7 +340,7 @@ static void monitorSaveSystemInfo() { ...@@ -346,7 +340,7 @@ static void monitorSaveSystemInfo() {
int64_t ts = taosGetTimestampUs(); int64_t ts = taosGetTimestampUs();
char * sql = tsMonitorConn.sql; char * sql = tsMonitorConn.sql;
int32_t pos = snprintf(sql, SQL_LENGTH, "insert into %s.dn_%s values(%" PRId64, tsMonitorDbName, tsMonitorConn.privateIpStr, ts); int32_t pos = snprintf(sql, SQL_LENGTH, "insert into %s.dn_%s values(%" PRId64, tsMonitorDbName, tsMonitorConn.ep, ts);
pos += monitorBuildCpuSql(sql + pos); pos += monitorBuildCpuSql(sql + pos);
pos += monitorBuildMemorySql(sql + pos); pos += monitorBuildMemorySql(sql + pos);
...@@ -414,7 +408,7 @@ void monitorSaveLog(int32_t level, const char *const format, ...) { ...@@ -414,7 +408,7 @@ void monitorSaveLog(int32_t level, const char *const format, ...) {
va_end(argpointer); va_end(argpointer);
if (len > max_length) len = max_length; if (len > max_length) len = max_length;
len += sprintf(sql + len, "', '%s')", tsPrivateIp); len += sprintf(sql + len, "', '%s')", tsLocalEp);
sql[len++] = 0; sql[len++] = 0;
monitorTrace("monitor:%p, save log, sql: %s", tsMonitorConn.conn, sql); monitorTrace("monitor:%p, save log, sql: %s", tsMonitorConn.conn, sql);
......
此差异已折叠。
...@@ -582,7 +582,7 @@ void exprSerializeTest1() { ...@@ -582,7 +582,7 @@ void exprSerializeTest1() {
tExprTreeDestroy(&p1, nullptr); tExprTreeDestroy(&p1, nullptr);
tExprTreeDestroy(&p2, nullptr); tExprTreeDestroy(&p2, nullptr);
tbufClose(&bw); // tbufClose(&bw);
} }
void exprSerializeTest2() { void exprSerializeTest2() {
...@@ -627,7 +627,7 @@ void exprSerializeTest2() { ...@@ -627,7 +627,7 @@ void exprSerializeTest2() {
tExprTreeDestroy(&p1, nullptr); tExprTreeDestroy(&p1, nullptr);
tExprTreeDestroy(&p2, nullptr); tExprTreeDestroy(&p2, nullptr);
tbufClose(&bw); // tbufClose(&bw);
} }
} // namespace } // namespace
TEST(testCase, astTest) { TEST(testCase, astTest) {
......
...@@ -22,8 +22,8 @@ extern "C" { ...@@ -22,8 +22,8 @@ extern "C" {
void *rpcOpenConnCache(int maxSessions, void (*cleanFp)(void *), void *tmrCtrl, int64_t keepTimer); void *rpcOpenConnCache(int maxSessions, void (*cleanFp)(void *), void *tmrCtrl, int64_t keepTimer);
void rpcCloseConnCache(void *handle); void rpcCloseConnCache(void *handle);
void rpcAddConnIntoCache(void *handle, void *data, uint32_t ip, uint16_t port, int8_t connType); void rpcAddConnIntoCache(void *handle, void *data, char *fqdn, uint16_t port, int8_t connType);
void *rpcGetConnFromCache(void *handle, uint32_t ip, uint16_t port, int8_t connType); void *rpcGetConnFromCache(void *handle, char *fqdn, uint16_t port, int8_t connType);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -20,12 +20,12 @@ ...@@ -20,12 +20,12 @@
extern "C" { extern "C" {
#endif #endif
void *taosInitTcpServer(char *ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle); void *taosInitTcpServer(uint32_t ip, uint16_t port, char *label, int numOfThreads, void *fp, void *shandle);
void taosCleanUpTcpServer(void *param); void taosCleanUpTcpServer(void *param);
void *taosInitTcpClient(char *ip, uint16_t port, char *label, int num, void *fp, void *shandle); void *taosInitTcpClient(uint32_t ip, uint16_t port, char *label, int num, void *fp, void *shandle);
void taosCleanUpTcpClient(void *chandle); void taosCleanUpTcpClient(void *chandle);
void *taosOpenTcpClientConnection(void *shandle, void *thandle, char *ip, uint16_t port); void *taosOpenTcpClientConnection(void *shandle, void *thandle, uint32_t ip, uint16_t port);
void taosCloseTcpConnection(void *chandle); void taosCloseTcpConnection(void *chandle);
int taosSendTcpData(uint32_t ip, uint16_t port, void *data, int len, void *chandle); int taosSendTcpData(uint32_t ip, uint16_t port, void *data, int len, void *chandle);
......
...@@ -22,10 +22,10 @@ extern "C" { ...@@ -22,10 +22,10 @@ extern "C" {
#include "taosdef.h" #include "taosdef.h"
void *taosInitUdpConnection(char *ip, uint16_t port, char *label, int, void *fp, void *shandle); void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int, void *fp, void *shandle);
void taosCleanUpUdpConnection(void *handle); void taosCleanUpUdpConnection(void *handle);
int taosSendUdpData(uint32_t ip, uint16_t port, void *data, int dataLen, void *chandle); int taosSendUdpData(uint32_t ip, uint16_t port, void *data, int dataLen, void *chandle);
void *taosOpenUdpConnection(void *shandle, void *thandle, char *ip, uint16_t port); void *taosOpenUdpConnection(void *shandle, void *thandle, uint32_t ip, uint16_t port);
void taosFreeMsgHdr(void *hdr); void taosFreeMsgHdr(void *hdr);
int taosMsgHdrSize(void *hdr); int taosMsgHdrSize(void *hdr);
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
...@@ -51,7 +51,7 @@ typedef struct { ...@@ -51,7 +51,7 @@ typedef struct {
typedef struct { typedef struct {
int index; int index;
int server; int server;
char ip[16]; // local IP uint32_t ip; // local IP
uint16_t port; // local Port uint16_t port; // local Port
void *shandle; // handle passed by upper layer during server initialization void *shandle; // handle passed by upper layer during server initialization
int threads; int threads;
...@@ -77,7 +77,7 @@ static void *taosRecvUdpData(void *param); ...@@ -77,7 +77,7 @@ static void *taosRecvUdpData(void *param);
static SUdpBuf *taosCreateUdpBuf(SUdpConn *pConn, uint32_t ip, uint16_t port); static SUdpBuf *taosCreateUdpBuf(SUdpConn *pConn, uint32_t ip, uint16_t port);
static void taosProcessUdpBufTimer(void *param, void *tmrId); static void taosProcessUdpBufTimer(void *param, void *tmrId);
void *taosInitUdpConnection(char *ip, uint16_t port, char *label, int threads, void *fp, void *shandle) { void *taosInitUdpConnection(uint32_t ip, uint16_t port, char *label, int threads, void *fp, void *shandle) {
SUdpConn *pConn; SUdpConn *pConn;
SUdpConnSet *pSet; SUdpConnSet *pSet;
...@@ -89,7 +89,7 @@ void *taosInitUdpConnection(char *ip, uint16_t port, char *label, int threads, v ...@@ -89,7 +89,7 @@ void *taosInitUdpConnection(char *ip, uint16_t port, char *label, int threads, v
} }
memset(pSet, 0, (size_t)size); memset(pSet, 0, (size_t)size);
strcpy(pSet->ip, ip); pSet->ip = ip;
pSet->port = port; pSet->port = port;
pSet->shandle = shandle; pSet->shandle = shandle;
pSet->fp = fp; pSet->fp = fp;
...@@ -111,7 +111,7 @@ void *taosInitUdpConnection(char *ip, uint16_t port, char *label, int threads, v ...@@ -111,7 +111,7 @@ void *taosInitUdpConnection(char *ip, uint16_t port, char *label, int threads, v
ownPort = (port ? port + i : 0); ownPort = (port ? port + i : 0);
pConn->fd = taosOpenUdpSocket(ip, ownPort); pConn->fd = taosOpenUdpSocket(ip, ownPort);
if (pConn->fd < 0) { if (pConn->fd < 0) {
tError("%s failed to open UDP socket %s:%hu", label, ip, port); tError("%s failed to open UDP socket %x:%hu", label, ip, port);
taosCleanUpUdpConnection(pSet); taosCleanUpUdpConnection(pSet);
return NULL; return NULL;
} }
...@@ -157,7 +157,7 @@ void *taosInitUdpConnection(char *ip, uint16_t port, char *label, int threads, v ...@@ -157,7 +157,7 @@ void *taosInitUdpConnection(char *ip, uint16_t port, char *label, int threads, v
++pSet->threads; ++pSet->threads;
} }
tTrace("%s UDP connection is initialized, ip:%s port:%hu threads:%d", label, ip, port, threads); tTrace("%s UDP connection is initialized, ip:%x port:%hu threads:%d", label, ip, port, threads);
return pSet; return pSet;
} }
...@@ -190,7 +190,7 @@ void taosCleanUpUdpConnection(void *handle) { ...@@ -190,7 +190,7 @@ void taosCleanUpUdpConnection(void *handle) {
tfree(pSet); tfree(pSet);
} }
void *taosOpenUdpConnection(void *shandle, void *thandle, char *ip, uint16_t port) { void *taosOpenUdpConnection(void *shandle, void *thandle, uint32_t ip, uint16_t port) {
SUdpConnSet *pSet = (SUdpConnSet *)shandle; SUdpConnSet *pSet = (SUdpConnSet *)shandle;
pSet->index = (pSet->index + 1) % pSet->threads; pSet->index = (pSet->index + 1) % pSet->threads;
...@@ -198,7 +198,7 @@ void *taosOpenUdpConnection(void *shandle, void *thandle, char *ip, uint16_t por ...@@ -198,7 +198,7 @@ void *taosOpenUdpConnection(void *shandle, void *thandle, char *ip, uint16_t por
SUdpConn *pConn = pSet->udpConn + pSet->index; SUdpConn *pConn = pSet->udpConn + pSet->index;
pConn->port = port; pConn->port = port;
tTrace("%s UDP connection is setup, ip: %s:%hu, local: %s:%d", pConn->label, ip, port, pSet->ip, tTrace("%s UDP connection is setup, ip:%x:%hu, local:%x:%d", pConn->label, ip, port, pSet->ip,
ntohs((uint16_t)pConn->localPort)); ntohs((uint16_t)pConn->localPort));
return pConn; return pConn;
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
...@@ -44,7 +44,10 @@ extern "C" { ...@@ -44,7 +44,10 @@ extern "C" {
#define tclose(x) taosCloseSocket(x) #define tclose(x) taosCloseSocket(x)
#ifdef ASSERTION // Pointer p drift right by b bytes
#define POINTER_DRIFT(p, b) ((void *)((char *)(p) + (b)))
#ifndef NDEBUG
#define ASSERT(x) assert(x) #define ASSERT(x) assert(x)
#else #else
#define ASSERT(x) #define ASSERT(x)
......
此差异已折叠。
此差异已折叠。
...@@ -249,7 +249,7 @@ void taosReadGlobalLogCfg() { ...@@ -249,7 +249,7 @@ void taosReadGlobalLogCfg() {
} }
wordfree(&full_path); wordfree(&full_path);
taosReadLogOption("logDir", logDir); taosReadLogOption("tsLogDir", tsLogDir);
sprintf(fileName, "%s/taos.cfg", configDir); sprintf(fileName, "%s/taos.cfg", configDir);
fp = fopen(fileName, "r"); fp = fopen(fileName, "r");
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册