提交 a563fb8f 编写于 作者: S slguan

create database message

上级 156fa5d4
...@@ -4643,7 +4643,7 @@ static void setCreateDBOption(SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) { ...@@ -4643,7 +4643,7 @@ static void setCreateDBOption(SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
} }
int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) { int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) {
SCreateDbMsg* pMsg = (SCreateDbMsg*)(pCmd->payload + tsRpcHeadSize + sizeof(SMgmtHead)); SCreateDbMsg* pMsg = (SCreateDbMsg*)(pCmd->payload);
setCreateDBOption(pMsg, pCreateDbSql); setCreateDBOption(pMsg, pCreateDbSql);
if (setKeepOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) { if (setKeepOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) {
......
...@@ -40,7 +40,6 @@ SRpcIpSet tscDnodeIpSet; ...@@ -40,7 +40,6 @@ SRpcIpSet tscDnodeIpSet;
int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo) = {0}; int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo) = {0};
int (*tscProcessMsgRsp[TSDB_SQL_MAX])(SSqlObj *pSql); int (*tscProcessMsgRsp[TSDB_SQL_MAX])(SSqlObj *pSql);
char *doBuildMsgHeader(SSqlObj *pSql, char **pStart);
void (*tscUpdateVnodeMsg[TSDB_SQL_MAX])(SSqlObj *pSql, char *buf); void (*tscUpdateVnodeMsg[TSDB_SQL_MAX])(SSqlObj *pSql, char *buf);
void tscProcessActivityTimer(void *handle, void *tmrId); void tscProcessActivityTimer(void *handle, void *tmrId);
int tscKeepConn[TSDB_SQL_MAX] = {0}; int tscKeepConn[TSDB_SQL_MAX] = {0};
...@@ -1651,41 +1650,34 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1651,41 +1650,34 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
} }
int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildCreateDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCreateDbMsg *pCreateDbMsg;
char * pMsg, *pStart;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
pCmd->payloadLen = sizeof(SCreateDbMsg);
pCmd->msgType = TSDB_MSG_TYPE_CREATE_DB;
pMsg = doBuildMsgHeader(pSql, &pStart); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
pCreateDbMsg = (SCreateDbMsg *)pMsg; tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY;
}
SCreateDbMsg *pCreateDbMsg = (SCreateDbMsg*)pCmd->payload;
assert(pCmd->numOfClause == 1); assert(pCmd->numOfClause == 1);
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
strncpy(pCreateDbMsg->db, pMeterMetaInfo->name, tListLen(pCreateDbMsg->db)); strncpy(pCreateDbMsg->db, pMeterMetaInfo->name, tListLen(pCreateDbMsg->db));
pMsg += sizeof(SCreateDbMsg);
pCmd->payloadLen = pMsg - pStart;
pCmd->msgType = TSDB_MSG_TYPE_CREATE_DB;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCreateDnodeMsg *pCreate;
char *pMsg, *pStart;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
pCmd->payloadLen = sizeof(SCreateDnodeMsg);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY;
}
pMsg = doBuildMsgHeader(pSql, &pStart); SCreateDnodeMsg *pCreate = (SCreateDnodeMsg *)pCmd->payload;
pCreate = (SCreateDnodeMsg *)pMsg;
strncpy(pCreate->ip, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); strncpy(pCreate->ip, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n);
pMsg += sizeof(SCreateDnodeMsg);
pCmd->payloadLen = pMsg - pStart;
pCmd->msgType = TSDB_MSG_TYPE_CREATE_DNODE; pCmd->msgType = TSDB_MSG_TYPE_CREATE_DNODE;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -1737,7 +1729,6 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1737,7 +1729,6 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
} }
int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
STscObj *pObj = pSql->pTscObj;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
pCmd->payloadLen = sizeof(SCreateUserMsg); pCmd->payloadLen = sizeof(SCreateUserMsg);
...@@ -1770,107 +1761,71 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1770,107 +1761,71 @@ int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
} }
int32_t tscBuildCfgDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildCfgDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
char * pStart = NULL;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
pCmd->payloadLen = sizeof(SCfgDnodeMsg);
char *pMsg = doBuildMsgHeader(pSql, &pStart); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
pMsg += sizeof(SCfgDnodeMsg); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY;
}
pCmd->payloadLen = pMsg - pStart;
pCmd->msgType = TSDB_MSG_TYPE_DNODE_CFG; pCmd->msgType = TSDB_MSG_TYPE_DNODE_CFG;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
char *doBuildMsgHeader(SSqlObj *pSql, char **pStart) {
SSqlCmd *pCmd = &pSql->cmd;
STscObj *pObj = pSql->pTscObj;
char *pMsg = pCmd->payload + tsRpcHeadSize;
*pStart = pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg;
strcpy(pMgmt->db, pObj->db);
pMsg += sizeof(SMgmtHead);
return pMsg;
}
int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SDropDbMsg *pDropDbMsg;
char * pMsg, *pStart;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
pCmd->payloadLen = sizeof(SDropDbMsg);
pMsg = doBuildMsgHeader(pSql, &pStart); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
pDropDbMsg = (SDropDbMsg *)pMsg; tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY;
}
SDropDbMsg *pDropDbMsg = (SDropDbMsg*)pCmd->payload;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
strncpy(pDropDbMsg->db, pMeterMetaInfo->name, tListLen(pDropDbMsg->db)); strncpy(pDropDbMsg->db, pMeterMetaInfo->name, tListLen(pDropDbMsg->db));
pDropDbMsg->ignoreNotExists = pInfo->pDCLInfo->existsCheck ? 1 : 0; pDropDbMsg->ignoreNotExists = pInfo->pDCLInfo->existsCheck ? 1 : 0;
pMsg += sizeof(SDropDbMsg);
pCmd->payloadLen = pMsg - pStart;
pCmd->msgType = TSDB_MSG_TYPE_DROP_DB; pCmd->msgType = TSDB_MSG_TYPE_DROP_DB;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildDropTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SDropTableMsg *pDropTableMsg;
char * pMsg, *pStart;
int msgLen = 0;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
pCmd->payloadLen = sizeof(SDropTableMsg);
//pMsg = doBuildMsgHeader(pSql, &pStart); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0); tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY;
pMsg = pCmd->payload + tsRpcHeadSize; }
pStart = pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg;
tscGetDBInfoFromMeterId(pMeterMetaInfo->name, pMgmt->db);
pMsg += sizeof(SMgmtHead);
pDropTableMsg = (SDropTableMsg *)pMsg;
SDropTableMsg *pDropTableMsg = (SDropTableMsg*)pCmd->payload;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
strcpy(pDropTableMsg->tableId, pMeterMetaInfo->name); strcpy(pDropTableMsg->tableId, pMeterMetaInfo->name);
pDropTableMsg->igNotExists = pInfo->pDCLInfo->existsCheck ? 1 : 0;
pMsg += sizeof(SDropTableMsg);
msgLen = pMsg - pStart;
pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_DROP_TABLE; pCmd->msgType = TSDB_MSG_TYPE_DROP_TABLE;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildDropDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SDropDnodeMsg *pDrop; SSqlCmd *pCmd = &pSql->cmd;
char * pMsg, *pStart; pCmd->payloadLen = sizeof(SDropDnodeMsg);
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY;
}
SSqlCmd * pCmd = &pSql->cmd; SDropDnodeMsg *pDrop = (SDropDnodeMsg *)pCmd->payload;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
pMsg = doBuildMsgHeader(pSql, &pStart);
pDrop = (SDropDnodeMsg *)pMsg;
strcpy(pDrop->ip, pMeterMetaInfo->name); strcpy(pDrop->ip, pMeterMetaInfo->name);
pMsg += sizeof(SDropDnodeMsg);
pCmd->payloadLen = pMsg - pStart;
pCmd->msgType = TSDB_MSG_TYPE_DROP_DNODE; pCmd->msgType = TSDB_MSG_TYPE_DROP_DNODE;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
STscObj *pObj = pSql->pTscObj;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
pCmd->payloadLen = sizeof(SDropUserMsg); pCmd->payloadLen = sizeof(SDropUserMsg);
pCmd->msgType = TSDB_MSG_TYPE_DROP_USER; pCmd->msgType = TSDB_MSG_TYPE_DROP_USER;
...@@ -1888,20 +1843,17 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1888,20 +1843,17 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
} }
int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildUseDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SUseDbMsg *pUseDbMsg;
char * pMsg, *pStart;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
pCmd->payloadLen = sizeof(SUseDbMsg);
pMsg = doBuildMsgHeader(pSql, &pStart); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
pUseDbMsg = (SUseDbMsg *)pMsg; tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY;
}
SUseDbMsg *pUseDbMsg = (SUseDbMsg*)pCmd->payload;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
strcpy(pUseDbMsg->db, pMeterMetaInfo->name); strcpy(pUseDbMsg->db, pMeterMetaInfo->name);
pMsg += sizeof(SUseDbMsg);
pCmd->payloadLen = pMsg - pStart;
pCmd->msgType = TSDB_MSG_TYPE_USE_DB; pCmd->msgType = TSDB_MSG_TYPE_USE_DB;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -1950,20 +1902,16 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1950,20 +1902,16 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
} }
int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildKillMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SKillQueryMsg *pKill;
char * pMsg, *pStart;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
pCmd->payloadLen = sizeof(SKillQueryMsg);
pMsg = doBuildMsgHeader(pSql, &pStart); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
pKill = (SKillQueryMsg *)pMsg; tscError("%p failed to malloc for query msg", pSql);
return TSDB_CODE_CLI_OUT_OF_MEMORY;
}
SKillQueryMsg *pKill = (SKillQueryMsg*)pCmd->payload;
strncpy(pKill->queryId, pInfo->pDCLInfo->ip.z, pInfo->pDCLInfo->ip.n); strncpy(pKill->queryId, pInfo->pDCLInfo->ip.z, pInfo->pDCLInfo->ip.n);
pMsg += sizeof(SKillQueryMsg);
pCmd->payloadLen = pMsg - pStart;
switch (pCmd->command) { switch (pCmd->command) {
case TSDB_SQL_KILL_QUERY: case TSDB_SQL_KILL_QUERY:
pCmd->msgType = TSDB_MSG_TYPE_KILL_QUERY; pCmd->msgType = TSDB_MSG_TYPE_KILL_QUERY;
...@@ -1998,12 +1946,9 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1998,12 +1946,9 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
} }
int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCreateTableMsg *pCreateTableMsg;
char * pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
SSchema * pSchema; SSchema * pSchema;
int size = 0; int size = 0;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
...@@ -2016,18 +1961,12 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -2016,18 +1961,12 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return TSDB_CODE_CLI_OUT_OF_MEMORY; return TSDB_CODE_CLI_OUT_OF_MEMORY;
} }
pMsg = pCmd->payload + tsRpcHeadSize;
pStart = pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg; SCreateTableMsg *pCreateTableMsg = (SCreateTableMsg *)pCmd->payload;
strcpy(pCreateTableMsg->tableId, pMeterMetaInfo->name);
// use dbinfo from table id without modifying current db info // use dbinfo from table id without modifying current db info
tscGetDBInfoFromMeterId(pMeterMetaInfo->name, pMgmt->db); tscGetDBInfoFromMeterId(pMeterMetaInfo->name, pCreateTableMsg->db);
pMsg += sizeof(SMgmtHead);
pCreateTableMsg = (SCreateTableMsg *)pMsg;
strcpy(pCreateTableMsg->tableId, pMeterMetaInfo->name);
SCreateTableSQL *pCreateTable = pInfo->pCreateTableInfo; SCreateTableSQL *pCreateTable = pInfo->pCreateTableInfo;
...@@ -2037,7 +1976,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -2037,7 +1976,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pCreateTableMsg->numOfTags = htons(pCmd->count); pCreateTableMsg->numOfTags = htons(pCmd->count);
pCreateTableMsg->sqlLen = 0; pCreateTableMsg->sqlLen = 0;
pMsg = (char *)pCreateTableMsg->schema; char *pMsg = (char *)pCreateTableMsg->schema;
int8_t type = pInfo->pCreateTableInfo->type; int8_t type = pInfo->pCreateTableInfo->type;
if (type == TSQL_CREATE_TABLE_FROM_STABLE) { // create by using super table, tags value if (type == TSQL_CREATE_TABLE_FROM_STABLE) { // create by using super table, tags value
...@@ -2068,7 +2007,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -2068,7 +2007,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
tscClearFieldInfo(&pQueryInfo->fieldsInfo); tscClearFieldInfo(&pQueryInfo->fieldsInfo);
msgLen = pMsg - pStart; msgLen = pMsg - (char*)pCreateTableMsg;
pCmd->payloadLen = msgLen; pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_CREATE_TABLE; pCmd->msgType = TSDB_MSG_TYPE_CREATE_TABLE;
...@@ -2099,16 +2038,12 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -2099,16 +2038,12 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
return -1; return -1;
} }
pMsg = pCmd->payload + tsRpcHeadSize; pAlterTableMsg = (SAlterTableMsg *)pCmd->payload;
pStart = pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg; tscGetDBInfoFromMeterId(pMeterMetaInfo->name, pAlterTableMsg->db);
tscGetDBInfoFromMeterId(pMeterMetaInfo->name, pMgmt->db);
pMsg += sizeof(SMgmtHead);
SAlterTableSQL *pAlterInfo = pInfo->pAlterInfo; SAlterTableSQL *pAlterInfo = pInfo->pAlterInfo;
pAlterTableMsg = (SAlterTableMsg *)pMsg;
strcpy(pAlterTableMsg->tableId, pMeterMetaInfo->name); strcpy(pAlterTableMsg->tableId, pMeterMetaInfo->name);
pAlterTableMsg->type = htons(pAlterInfo->type); pAlterTableMsg->type = htons(pAlterInfo->type);
...@@ -2127,7 +2062,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -2127,7 +2062,7 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg = (char *)pSchema; pMsg = (char *)pSchema;
msgLen = pMsg - pStart; msgLen = pMsg - (char*)pAlterTableMsg;
pCmd->payloadLen = msgLen; pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_ALTER_TABLE; pCmd->msgType = TSDB_MSG_TYPE_ALTER_TABLE;
...@@ -2137,35 +2072,23 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -2137,35 +2072,23 @@ int tscBuildAlterTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
} }
int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscAlterDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SAlterDbMsg *pAlterDbMsg; SSqlCmd *pCmd = &pSql->cmd;
char * pMsg, *pStart; pCmd->payloadLen = sizeof(SAlterDbMsg);
int msgLen = 0; pCmd->msgType = TSDB_MSG_TYPE_ALTER_DB;
SSqlCmd * pCmd = &pSql->cmd;
STscObj * pObj = pSql->pTscObj;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
pStart = pCmd->payload + tsRpcHeadSize;
pMsg = pStart;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) {
strcpy(pMgmt->db, pObj->db); tscError("%p failed to malloc for query msg", pSql);
pMsg += sizeof(SMgmtHead); return TSDB_CODE_CLI_OUT_OF_MEMORY;
}
pAlterDbMsg = (SAlterDbMsg *)pMsg; SAlterDbMsg *pAlterDbMsg = (SAlterDbMsg*)pCmd->payload;
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
strcpy(pAlterDbMsg->db, pMeterMetaInfo->name); strcpy(pAlterDbMsg->db, pMeterMetaInfo->name);
pMsg += sizeof(SAlterDbMsg);
msgLen = pMsg - pStart;
pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_ALTER_DB;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
STscObj *pObj = pSql->pTscObj;
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
pCmd->msgType = TSDB_MSG_TYPE_RETRIEVE; pCmd->msgType = TSDB_MSG_TYPE_RETRIEVE;
pCmd->payloadLen = sizeof(SRetrieveTableMsg); pCmd->payloadLen = sizeof(SRetrieveTableMsg);
...@@ -2316,7 +2239,7 @@ int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -2316,7 +2239,7 @@ int tscBuildConnectMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int tscBuildMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
STableInfoMsg *pInfoMsg; STableInfoMsg *pInfoMsg;
char * pMsg, *pStart; char * pMsg;
int msgLen = 0; int msgLen = 0;
char *tmpData = 0; char *tmpData = 0;
...@@ -2335,25 +2258,18 @@ int tscBuildMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -2335,25 +2258,18 @@ int tscBuildMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
pMsg = pCmd->payload + tsRpcHeadSize; pInfoMsg = (STableInfoMsg *)pCmd->payload;
pStart = pMsg;
SMgmtHead *pMgmt = (SMgmtHead *)pMsg;
tscGetDBInfoFromMeterId(pMeterMetaInfo->name, pMgmt->db);
pMsg += sizeof(SMgmtHead);
pInfoMsg = (STableInfoMsg *)pMsg;
strcpy(pInfoMsg->tableId, pMeterMetaInfo->name); strcpy(pInfoMsg->tableId, pMeterMetaInfo->name);
pInfoMsg->createFlag = htons(pSql->cmd.createOnDemand ? 1 : 0); pInfoMsg->createFlag = htons(pSql->cmd.createOnDemand ? 1 : 0);
pMsg += sizeof(STableInfoMsg);
pMsg = (char*)pInfoMsg + sizeof(STableInfoMsg);
if (pSql->cmd.createOnDemand) { if (pSql->cmd.createOnDemand) {
memcpy(pInfoMsg->tags, tmpData, sizeof(STagData)); memcpy(pInfoMsg->tags, tmpData, sizeof(STagData));
pMsg += sizeof(STagData); pMsg += sizeof(STagData);
} }
msgLen = pMsg - pStart; msgLen = pMsg - (char*)pInfoMsg;
pCmd->payloadLen = msgLen; pCmd->payloadLen = msgLen;
pCmd->msgType = TSDB_MSG_TYPE_TABLE_META; pCmd->msgType = TSDB_MSG_TYPE_TABLE_META;
...@@ -3429,9 +3345,9 @@ int tscGetMetricMeta(SSqlObj *pSql, int32_t clauseIndex) { ...@@ -3429,9 +3345,9 @@ int tscGetMetricMeta(SSqlObj *pSql, int32_t clauseIndex) {
} }
void tscInitMsgs() { void tscInitMsgs() {
tscBuildMsg[TSDB_SQL_SELECT] = tscBuildQueryMsg; tscBuildMsg[TSDB_SQL_SELECT] = tscBuildQueryMsg;//
tscBuildMsg[TSDB_SQL_INSERT] = tscBuildSubmitMsg; tscBuildMsg[TSDB_SQL_INSERT] = tscBuildSubmitMsg;//
tscBuildMsg[TSDB_SQL_FETCH] = tscBuildRetrieveMsg; tscBuildMsg[TSDB_SQL_FETCH] = tscBuildRetrieveMsg;//
tscBuildMsg[TSDB_SQL_CREATE_DB] = tscBuildCreateDbMsg; tscBuildMsg[TSDB_SQL_CREATE_DB] = tscBuildCreateDbMsg;
tscBuildMsg[TSDB_SQL_CREATE_USER] = tscBuildUserMsg; tscBuildMsg[TSDB_SQL_CREATE_USER] = tscBuildUserMsg;
......
...@@ -801,6 +801,7 @@ int tscAllocPayload(SSqlCmd* pCmd, int size) { ...@@ -801,6 +801,7 @@ int tscAllocPayload(SSqlCmd* pCmd, int size) {
pCmd->payload = (char*)malloc(size); pCmd->payload = (char*)malloc(size);
if (pCmd->payload == NULL) return TSDB_CODE_CLI_OUT_OF_MEMORY; if (pCmd->payload == NULL) return TSDB_CODE_CLI_OUT_OF_MEMORY;
pCmd->allocSize = size; pCmd->allocSize = size;
memset(pCmd->payload, 0, pCmd->allocSize);
} else { } else {
if (pCmd->allocSize < size) { if (pCmd->allocSize < size) {
char* b = realloc(pCmd->payload, size); char* b = realloc(pCmd->payload, size);
...@@ -810,7 +811,7 @@ int tscAllocPayload(SSqlCmd* pCmd, int size) { ...@@ -810,7 +811,7 @@ int tscAllocPayload(SSqlCmd* pCmd, int size) {
} }
} }
memset(pCmd->payload, 0, pCmd->allocSize); //memset(pCmd->payload, 0, pCmd->allocSize);
assert(pCmd->allocSize >= size); assert(pCmd->allocSize >= size);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
......
...@@ -82,10 +82,11 @@ struct arguments args = { ...@@ -82,10 +82,11 @@ struct arguments args = {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
/*setlocale(LC_ALL, "en_US.UTF-8"); */ /*setlocale(LC_ALL, "en_US.UTF-8"); */
// //
if (argc != 1) { if (argc == 1)
{
printf("=== this a test for debug usage\n"); printf("=== this a test for debug usage\n");
void *taos = taos_connect(NULL, "root", "taosdata", NULL, 0); void *taos = taos_connect(NULL, "root", "taosdata", NULL, 0);
taos_query(taos, "drop user a"); taos_query(taos, "create database db");
while (1) { while (1) {
sleep(1000); sleep(1000);
} }
......
...@@ -67,7 +67,10 @@ int32_t mgmtInitDbs() { ...@@ -67,7 +67,10 @@ int32_t mgmtInitDbs() {
mgmtDbActionInit(); mgmtDbActionInit();
tsDbSdb = sdbOpenTable(tsMaxDbs, sizeof(SDbObj), "db", SDB_KEYTYPE_STRING, tsMgmtDirectory, mgmtDbAction); SDbObj tObj;
tsDbUpdateSize = tObj.updateEnd - (char *)&tObj;
tsDbSdb = sdbOpenTable(tsMaxDbs, tsDbUpdateSize, "db", SDB_KEYTYPE_STRING, tsMgmtDirectory, mgmtDbAction);
if (tsDbSdb == NULL) { if (tsDbSdb == NULL) {
mError("failed to init db data"); mError("failed to init db data");
return -1; return -1;
...@@ -94,9 +97,6 @@ int32_t mgmtInitDbs() { ...@@ -94,9 +97,6 @@ int32_t mgmtInitDbs() {
} }
} }
SDbObj tObj;
tsDbUpdateSize = tObj.updateEnd - (char *)&tObj;
mTrace("db data is initialized"); mTrace("db data is initialized");
return 0; return 0;
} }
...@@ -823,12 +823,11 @@ void *mgmtDbActionUpdate(void *row, char *str, int32_t size, int32_t *ssize) { ...@@ -823,12 +823,11 @@ void *mgmtDbActionUpdate(void *row, char *str, int32_t size, int32_t *ssize) {
void *mgmtDbActionEncode(void *row, char *str, int32_t size, int32_t *ssize) { void *mgmtDbActionEncode(void *row, char *str, int32_t size, int32_t *ssize) {
SDbObj *pDb = (SDbObj *) row; SDbObj *pDb = (SDbObj *) row;
int32_t tsize = pDb->updateEnd - (char *) pDb; if (size < tsDbUpdateSize) {
if (size < tsize) {
*ssize = -1; *ssize = -1;
} else { } else {
memcpy(str, pDb, tsize); memcpy(str, pDb, tsDbUpdateSize);
*ssize = tsize; *ssize = tsDbUpdateSize;
} }
return NULL; return NULL;
...@@ -838,16 +837,14 @@ void *mgmtDbActionDecode(void *row, char *str, int32_t size, int32_t *ssize) { ...@@ -838,16 +837,14 @@ void *mgmtDbActionDecode(void *row, char *str, int32_t size, int32_t *ssize) {
if (pDb == NULL) return NULL; if (pDb == NULL) return NULL;
memset(pDb, 0, sizeof(SDbObj)); memset(pDb, 0, sizeof(SDbObj));
int32_t tsize = pDb->updateEnd - (char *)pDb; memcpy(pDb, str, tsDbUpdateSize);
memcpy(pDb, str, tsize);
return (void *)pDb; return (void *)pDb;
} }
void *mgmtDbActionReset(void *row, char *str, int32_t size, int32_t *ssize) { void *mgmtDbActionReset(void *row, char *str, int32_t size, int32_t *ssize) {
SDbObj *pDb = (SDbObj *) row; SDbObj *pDb = (SDbObj *) row;
int32_t tsize = pDb->updateEnd - (char *) pDb; memcpy(pDb, str, tsDbUpdateSize);
memcpy(pDb, str, tsize);
return NULL; return NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册