提交 ded484b5 编写于 作者: H Hongze Cheng

Merge branch '2.0' of https://github.com/taosdata/TDengine into 2.0

...@@ -45,13 +45,15 @@ mkdir build && cd build ...@@ -45,13 +45,15 @@ mkdir build && cd build
cmake .. && cmake --build . cmake .. && cmake --build .
``` ```
if compiling on an ARM processor(aarch64 or aarch32), you need add one parameter: To compile on an ARM processor (aarch64 or aarch32), please add option CPUTYPE as below:
```cmd
aarch64: aarch64:
```cmd
cmake .. -DCPUTYPE=aarch64 && cmake --build . cmake .. -DCPUTYPE=aarch64 && cmake --build .
```
aarch32: aarch32:
```cmd
cmake .. -DCPUTYPE=aarch32 && cmake --build . cmake .. -DCPUTYPE=aarch32 && cmake --build .
``` ```
......
...@@ -73,7 +73,7 @@ sed -i "2c$debver" ${pkg_dir}/DEBIAN/control ...@@ -73,7 +73,7 @@ sed -i "2c$debver" ${pkg_dir}/DEBIAN/control
if [ "$verMode" == "cluster" ]; then if [ "$verMode" == "cluster" ]; then
debname="TDengine-server-"${tdengine_ver}-${osType}-${cpuType} debname="TDengine-server-"${tdengine_ver}-${osType}-${cpuType}
elif [ "$verMode" == "lite" ]; then elif [ "$verMode" == "lite" ]; then
debname="TDengine-server-edge"-${tdengine_ver}-${osType}-${cpuType} debname="TDengine-server"-${tdengine_ver}-${osType}-${cpuType}
else else
echo "unknow verMode, nor cluster or lite" echo "unknow verMode, nor cluster or lite"
exit 1 exit 1
......
...@@ -66,7 +66,7 @@ cp_rpm_package ${pkg_dir}/RPMS ...@@ -66,7 +66,7 @@ cp_rpm_package ${pkg_dir}/RPMS
if [ "$verMode" == "cluster" ]; then if [ "$verMode" == "cluster" ]; then
rpmname="TDengine-server-"${tdengine_ver}-${osType}-${cpuType} rpmname="TDengine-server-"${tdengine_ver}-${osType}-${cpuType}
elif [ "$verMode" == "lite" ]; then elif [ "$verMode" == "lite" ]; then
rpmname="TDengine-server-edge"-${tdengine_ver}-${osType}-${cpuType} rpmname="TDengine-server"-${tdengine_ver}-${osType}-${cpuType}
else else
echo "unknow verMode, nor cluster or lite" echo "unknow verMode, nor cluster or lite"
exit 1 exit 1
......
...@@ -111,7 +111,7 @@ cd ${release_dir} ...@@ -111,7 +111,7 @@ cd ${release_dir}
if [ "$verMode" == "cluster" ]; then if [ "$verMode" == "cluster" ]; then
pkg_name=${install_dir}-${version}-${osType}-${cpuType} pkg_name=${install_dir}-${version}-${osType}-${cpuType}
elif [ "$verMode" == "lite" ]; then elif [ "$verMode" == "lite" ]; then
pkg_name=${install_dir}-edge-${version}-${osType}-${cpuType} pkg_name=${install_dir}-${version}-${osType}-${cpuType}
else else
echo "unknow verMode, nor cluster or lite" echo "unknow verMode, nor cluster or lite"
exit 1 exit 1
......
...@@ -111,7 +111,7 @@ cd ${release_dir} ...@@ -111,7 +111,7 @@ cd ${release_dir}
if [ "$verMode" == "cluster" ]; then if [ "$verMode" == "cluster" ]; then
pkg_name=${install_dir}-${version}-${osType}-${cpuType} pkg_name=${install_dir}-${version}-${osType}-${cpuType}
elif [ "$verMode" == "lite" ]; then elif [ "$verMode" == "lite" ]; then
pkg_name=${install_dir}-edge-${version}-${osType}-${cpuType} pkg_name=${install_dir}-${version}-${osType}-${cpuType}
else else
echo "unknow verMode, nor cluster or lite" echo "unknow verMode, nor cluster or lite"
exit 1 exit 1
......
...@@ -30,10 +30,10 @@ extern "C" { ...@@ -30,10 +30,10 @@ extern "C" {
#include "tsdb.h" #include "tsdb.h"
#define UTIL_METER_IS_SUPERTABLE(metaInfo) \ #define UTIL_METER_IS_SUPERTABLE(metaInfo) \
(((metaInfo)->pMeterMeta != NULL) && ((metaInfo)->pMeterMeta->meterType == TSDB_METER_METRIC)) (((metaInfo)->pMeterMeta != NULL) && ((metaInfo)->pMeterMeta->tableType == TSDB_TABLE_TYPE_SUPER_TABLE))
#define UTIL_METER_IS_NOMRAL_METER(metaInfo) (!(UTIL_METER_IS_SUPERTABLE(metaInfo))) #define UTIL_METER_IS_NOMRAL_METER(metaInfo) (!(UTIL_METER_IS_SUPERTABLE(metaInfo)))
#define UTIL_METER_IS_CREATE_FROM_METRIC(metaInfo) \ #define UTIL_METER_IS_CREATE_FROM_METRIC(metaInfo) \
(((metaInfo)->pMeterMeta != NULL) && ((metaInfo)->pMeterMeta->meterType == TSDB_METER_MTABLE)) (((metaInfo)->pMeterMeta != NULL) && ((metaInfo)->pMeterMeta->tableType == TSDB_TABLE_TYPE_CREATE_FROM_STABLE))
#define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0) #define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0)
......
...@@ -54,7 +54,7 @@ typedef struct SMeterMetaInfo { ...@@ -54,7 +54,7 @@ typedef struct SMeterMetaInfo {
* 2. keep the vnode index for multi-vnode insertion * 2. keep the vnode index for multi-vnode insertion
*/ */
int32_t vnodeIndex; int32_t vnodeIndex;
char name[TSDB_METER_ID_LEN + 1]; // table(super table) name char name[TSDB_TABLE_ID_LEN + 1]; // table(super table) name
int16_t numOfTags; // total required tags in query, including groupby tags int16_t numOfTags; // total required tags in query, including groupby tags
int16_t tagColumnIndex[TSDB_MAX_TAGS]; // clause + tag projection int16_t tagColumnIndex[TSDB_MAX_TAGS]; // clause + tag projection
} SMeterMetaInfo; } SMeterMetaInfo;
...@@ -119,7 +119,7 @@ typedef struct SCond { ...@@ -119,7 +119,7 @@ typedef struct SCond {
} SCond; } SCond;
typedef struct SJoinNode { typedef struct SJoinNode {
char meterId[TSDB_METER_ID_LEN]; char meterId[TSDB_TABLE_ID_LEN];
uint64_t uid; uint64_t uid;
int16_t tagCol; int16_t tagCol;
} SJoinNode; } SJoinNode;
...@@ -154,7 +154,7 @@ typedef struct SParamInfo { ...@@ -154,7 +154,7 @@ typedef struct SParamInfo {
} SParamInfo; } SParamInfo;
typedef struct STableDataBlocks { typedef struct STableDataBlocks {
char meterId[TSDB_METER_ID_LEN]; char meterId[TSDB_TABLE_ID_LEN];
int8_t tsSource; // where does the UNIX timestamp come from, server or client int8_t tsSource; // where does the UNIX timestamp come from, server or client
bool ordered; // if current rows are ordered or not bool ordered; // if current rows are ordered or not
int64_t vgid; // virtual group id int64_t vgid; // virtual group id
...@@ -302,7 +302,7 @@ typedef struct _tsc_obj { ...@@ -302,7 +302,7 @@ typedef struct _tsc_obj {
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_KEY_LEN]; char pass[TSDB_KEY_LEN];
char acctId[TSDB_DB_NAME_LEN]; char acctId[TSDB_DB_NAME_LEN];
char db[TSDB_METER_ID_LEN]; char db[TSDB_TABLE_ID_LEN];
char sversion[TSDB_VERSION_LEN]; char sversion[TSDB_VERSION_LEN];
char writeAuth : 1; char writeAuth : 1;
char superAuth : 1; char superAuth : 1;
......
...@@ -24,8 +24,6 @@ taos_fetch_row_a ...@@ -24,8 +24,6 @@ taos_fetch_row_a
taos_subscribe taos_subscribe
taos_consume taos_consume
taos_unsubscribe taos_unsubscribe
taos_subfields_count
taos_fetch_subfields
taos_open_stream taos_open_stream
taos_close_stream taos_close_stream
taos_fetch_block taos_fetch_block
......
...@@ -3194,7 +3194,7 @@ static void diff_function(SQLFunctionCtx *pCtx) { ...@@ -3194,7 +3194,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
GET_RES_INFO(pCtx)->numOfRes += forwardStep; GET_RES_INFO(pCtx)->numOfRes += forwardStep;
pCtx->aOutputBuf += forwardStep * pCtx->outputBytes; pCtx->aOutputBuf += forwardStep * pCtx->outputBytes;
pCtx->ptsOutputBuf += forwardStep * TSDB_KEYSIZE; pCtx->ptsOutputBuf = (char*)pCtx->ptsOutputBuf + forwardStep * TSDB_KEYSIZE;
} }
} }
......
...@@ -79,8 +79,8 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type ...@@ -79,8 +79,8 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
static int32_t tscMaxLengthOfTagsFields(SSqlObj *pSql) { static int32_t tscMaxLengthOfTagsFields(SSqlObj *pSql) {
SMeterMeta *pMeta = tscGetMeterMetaInfo(&pSql->cmd, 0, 0)->pMeterMeta; SMeterMeta *pMeta = tscGetMeterMetaInfo(&pSql->cmd, 0, 0)->pMeterMeta;
if (pMeta->meterType == TSDB_METER_METRIC || pMeta->meterType == TSDB_METER_OTABLE || if (pMeta->tableType == TSDB_TABLE_TYPE_SUPER_TABLE || pMeta->tableType == TSDB_TABLE_TYPE_NORMAL_TABLE ||
pMeta->meterType == TSDB_METER_STABLE) { pMeta->tableType == TSDB_TABLE_TYPE_STREAM_TABLE) {
return 0; return 0;
} }
......
...@@ -776,7 +776,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { ...@@ -776,7 +776,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
SMeterMetaInfo *pSTableMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, STABLE_INDEX); SMeterMetaInfo *pSTableMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, STABLE_INDEX);
setMeterID(pSTableMeterMetaInfo, &sToken, pSql); setMeterID(pSTableMeterMetaInfo, &sToken, pSql);
strncpy(pTag->name, pSTableMeterMetaInfo->name, TSDB_METER_ID_LEN); strncpy(pTag->name, pSTableMeterMetaInfo->name, TSDB_TABLE_ID_LEN);
code = tscGetMeterMeta(pSql, pSTableMeterMetaInfo); code = tscGetMeterMeta(pSql, pSTableMeterMetaInfo);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
...@@ -950,7 +950,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) { ...@@ -950,7 +950,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
} }
int validateTableName(char *tblName, int len) { int validateTableName(char *tblName, int len) {
char buf[TSDB_METER_ID_LEN] = {0}; char buf[TSDB_TABLE_ID_LEN] = {0};
strncpy(buf, tblName, len); strncpy(buf, tblName, len);
SSQLToken token = {.n = len, .type = TK_ID, .z = buf}; SSQLToken token = {.n = len, .type = TK_ID, .z = buf};
...@@ -1544,7 +1544,7 @@ void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql) { ...@@ -1544,7 +1544,7 @@ void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql) {
continue; continue;
} }
strncpy(pMeterMetaInfo->name, pDataBlock->meterId, TSDB_METER_ID_LEN); strncpy(pMeterMetaInfo->name, pDataBlock->meterId, TSDB_TABLE_ID_LEN);
memset(pDataBlock->pData, 0, pDataBlock->nAllocSize); memset(pDataBlock->pData, 0, pDataBlock->nAllocSize);
int32_t ret = tscGetMeterMeta(pSql, pMeterMetaInfo); int32_t ret = tscGetMeterMeta(pSql, pMeterMetaInfo);
......
...@@ -1072,11 +1072,11 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL ...@@ -1072,11 +1072,11 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL
*xlen = totalLen; *xlen = totalLen;
} }
if (totalLen < TSDB_METER_ID_LEN) { if (totalLen < TSDB_TABLE_ID_LEN) {
fullName[totalLen] = 0; fullName[totalLen] = 0;
} }
return (totalLen <= TSDB_METER_ID_LEN) ? TSDB_CODE_SUCCESS : TSDB_CODE_INVALID_SQL; return (totalLen <= TSDB_TABLE_ID_LEN) ? TSDB_CODE_SUCCESS : TSDB_CODE_INVALID_SQL;
} }
static void extractColumnNameFromString(tSQLExprItem* pItem) { static void extractColumnNameFromString(tSQLExprItem* pItem) {
...@@ -1901,7 +1901,7 @@ int32_t getMeterIndex(SSQLToken* pTableToken, SQueryInfo* pQueryInfo, SColumnInd ...@@ -1901,7 +1901,7 @@ int32_t getMeterIndex(SSQLToken* pTableToken, SQueryInfo* pQueryInfo, SColumnInd
} }
pIndex->tableIndex = COLUMN_INDEX_INITIAL_VAL; pIndex->tableIndex = COLUMN_INDEX_INITIAL_VAL;
char tableName[TSDB_METER_ID_LEN + 1] = {0}; char tableName[TSDB_TABLE_ID_LEN + 1] = {0};
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, i); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, i);
...@@ -3365,7 +3365,7 @@ static int32_t setTableCondForMetricQuery(SQueryInfo* pQueryInfo, const char* ac ...@@ -3365,7 +3365,7 @@ static int32_t setTableCondForMetricQuery(SQueryInfo* pQueryInfo, const char* ac
SStringBuilder sb1 = {0}; SStringBuilder sb1 = {0};
taosStringBuilderAppendStringLen(&sb1, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN); taosStringBuilderAppendStringLen(&sb1, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN);
char db[TSDB_METER_ID_LEN] = {0}; char db[TSDB_TABLE_ID_LEN] = {0};
// remove the duplicated input table names // remove the duplicated input table names
int32_t num = 0; int32_t num = 0;
...@@ -3389,7 +3389,7 @@ static int32_t setTableCondForMetricQuery(SQueryInfo* pQueryInfo, const char* ac ...@@ -3389,7 +3389,7 @@ static int32_t setTableCondForMetricQuery(SQueryInfo* pQueryInfo, const char* ac
taosStringBuilderAppendStringLen(&sb1, TBNAME_LIST_SEP, 1); taosStringBuilderAppendStringLen(&sb1, TBNAME_LIST_SEP, 1);
} }
char idBuf[TSDB_METER_ID_LEN + 1] = {0}; char idBuf[TSDB_TABLE_ID_LEN + 1] = {0};
int32_t xlen = strlen(segments[i]); int32_t xlen = strlen(segments[i]);
SSQLToken t = {.z = segments[i], .n = xlen, .type = TK_STRING}; SSQLToken t = {.z = segments[i], .n = xlen, .type = TK_STRING};
...@@ -5300,7 +5300,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { ...@@ -5300,7 +5300,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
} }
// get meter meta from mnode // get meter meta from mnode
strncpy(pCreateTable->usingInfo.tagdata.name, pStableMeterMetaInfo->name, TSDB_METER_ID_LEN); strncpy(pCreateTable->usingInfo.tagdata.name, pStableMeterMetaInfo->name, TSDB_TABLE_ID_LEN);
tVariantList* pList = pInfo->pCreateTableInfo->usingInfo.pTagVals; tVariantList* pList = pInfo->pCreateTableInfo->usingInfo.pTagVals;
int32_t code = tscGetMeterMeta(pSql, pStableMeterMetaInfo); int32_t code = tscGetMeterMeta(pSql, pStableMeterMetaInfo);
......
...@@ -2685,7 +2685,7 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -2685,7 +2685,7 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
// fill head info // fill head info
SMgmtHead *pMgmt = (SMgmtHead *)(pCmd->payload + tsRpcHeadSize); SMgmtHead *pMgmt = (SMgmtHead *)(pCmd->payload + tsRpcHeadSize);
memset(pMgmt->db, 0, TSDB_METER_ID_LEN); // server don't need the db memset(pMgmt->db, 0, TSDB_TABLE_ID_LEN); // server don't need the db
SMultiMeterInfoMsg *pInfoMsg = (SMultiMeterInfoMsg *)(pCmd->payload + tsRpcHeadSize + sizeof(SMgmtHead)); SMultiMeterInfoMsg *pInfoMsg = (SMultiMeterInfoMsg *)(pCmd->payload + tsRpcHeadSize + sizeof(SMgmtHead));
pInfoMsg->numOfMeters = htonl((int32_t)pCmd->count); pInfoMsg->numOfMeters = htonl((int32_t)pCmd->count);
...@@ -2709,7 +2709,7 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -2709,7 +2709,7 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
static int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) { static int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) {
const int32_t defaultSize = const int32_t defaultSize =
minMsgSize() + sizeof(SMetricMetaMsg) + sizeof(SMgmtHead) + sizeof(int16_t) * TSDB_MAX_TAGS; minMsgSize() + sizeof(SSuperTableMetaMsg) + sizeof(SMgmtHead) + sizeof(int16_t) * TSDB_MAX_TAGS;
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0); SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
int32_t n = 0; int32_t n = 0;
...@@ -2722,7 +2722,7 @@ static int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) { ...@@ -2722,7 +2722,7 @@ static int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) {
tagLen += strlen(pQueryInfo->tagCond.tbnameCond.cond) * TSDB_NCHAR_SIZE; tagLen += strlen(pQueryInfo->tagCond.tbnameCond.cond) * TSDB_NCHAR_SIZE;
} }
int32_t joinCondLen = (TSDB_METER_ID_LEN + sizeof(int16_t)) * 2; int32_t joinCondLen = (TSDB_TABLE_ID_LEN + sizeof(int16_t)) * 2;
int32_t elemSize = sizeof(SMetricMetaElemMsg) * pQueryInfo->numOfTables; int32_t elemSize = sizeof(SMetricMetaElemMsg) * pQueryInfo->numOfTables;
int32_t len = tagLen + joinCondLen + elemSize + defaultSize; int32_t len = tagLen + joinCondLen + elemSize + defaultSize;
...@@ -2731,7 +2731,7 @@ static int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) { ...@@ -2731,7 +2731,7 @@ static int32_t tscEstimateMetricMetaMsgSize(SSqlCmd *pCmd) {
} }
int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SMetricMetaMsg *pMetaMsg; SSuperTableMetaMsg *pMetaMsg;
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
int tableIndex = 0; int tableIndex = 0;
...@@ -2757,25 +2757,25 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -2757,25 +2757,25 @@ int tscBuildMetricMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg += sizeof(SMgmtHead); pMsg += sizeof(SMgmtHead);
pMetaMsg = (SMetricMetaMsg *)pMsg; pMetaMsg = (SSuperTableMetaMsg *)pMsg;
pMetaMsg->numOfMeters = htonl(pQueryInfo->numOfTables); pMetaMsg->numOfMeters = htonl(pQueryInfo->numOfTables);
pMsg += sizeof(SMetricMetaMsg); pMsg += sizeof(SSuperTableMetaMsg);
int32_t offset = pMsg - (char *)pMetaMsg; int32_t offset = pMsg - (char *)pMetaMsg;
pMetaMsg->join = htonl(offset); pMetaMsg->join = htonl(offset);
// todo refactor // todo refactor
pMetaMsg->joinCondLen = htonl((TSDB_METER_ID_LEN + sizeof(int16_t)) * 2); pMetaMsg->joinCondLen = htonl((TSDB_TABLE_ID_LEN + sizeof(int16_t)) * 2);
memcpy(pMsg, pTagCond->joinInfo.left.meterId, TSDB_METER_ID_LEN); memcpy(pMsg, pTagCond->joinInfo.left.meterId, TSDB_TABLE_ID_LEN);
pMsg += TSDB_METER_ID_LEN; pMsg += TSDB_TABLE_ID_LEN;
*(int16_t *)pMsg = pTagCond->joinInfo.left.tagCol; *(int16_t *)pMsg = pTagCond->joinInfo.left.tagCol;
pMsg += sizeof(int16_t); pMsg += sizeof(int16_t);
memcpy(pMsg, pTagCond->joinInfo.right.meterId, TSDB_METER_ID_LEN); memcpy(pMsg, pTagCond->joinInfo.right.meterId, TSDB_TABLE_ID_LEN);
pMsg += TSDB_METER_ID_LEN; pMsg += TSDB_TABLE_ID_LEN;
*(int16_t *)pMsg = pTagCond->joinInfo.right.tagCol; *(int16_t *)pMsg = pTagCond->joinInfo.right.tagCol;
pMsg += sizeof(int16_t); pMsg += sizeof(int16_t);
...@@ -2991,7 +2991,7 @@ int tscProcessMeterMetaRsp(SSqlObj *pSql) { ...@@ -2991,7 +2991,7 @@ int tscProcessMeterMetaRsp(SSqlObj *pSql) {
int32_t tagLen = 0; int32_t tagLen = 0;
SSchema *pTagsSchema = tsGetTagSchema(pMeta); SSchema *pTagsSchema = tsGetTagSchema(pMeta);
if (pMeta->meterType == TSDB_METER_MTABLE) { if (pMeta->tableType == TSDB_TABLE_TYPE_CREATE_FROM_STABLE) {
for (int32_t i = 0; i < pMeta->numOfTags; ++i) { for (int32_t i = 0; i < pMeta->numOfTags; ++i) {
tagLen += pTagsSchema[i].bytes; tagLen += pTagsSchema[i].bytes;
} }
...@@ -3106,7 +3106,7 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) { ...@@ -3106,7 +3106,7 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) {
int32_t tagLen = 0; int32_t tagLen = 0;
SSchema *pTagsSchema = tsGetTagSchema(pMeta); SSchema *pTagsSchema = tsGetTagSchema(pMeta);
if (pMeta->meterType == TSDB_METER_MTABLE) { if (pMeta->tableType == TSDB_TABLE_TYPE_CREATE_FROM_STABLE) {
for (int32_t j = 0; j < pMeta->numOfTags; ++j) { for (int32_t j = 0; j < pMeta->numOfTags; ++j) {
tagLen += pTagsSchema[j].bytes; tagLen += pTagsSchema[j].bytes;
} }
...@@ -3304,7 +3304,7 @@ int tscProcessShowRsp(SSqlObj *pSql) { ...@@ -3304,7 +3304,7 @@ int tscProcessShowRsp(SSqlObj *pSql) {
} }
int tscProcessConnectRsp(SSqlObj *pSql) { int tscProcessConnectRsp(SSqlObj *pSql) {
char temp[TSDB_METER_ID_LEN * 2]; char temp[TSDB_TABLE_ID_LEN * 2];
SConnectRsp *pConnect; SConnectRsp *pConnect;
STscObj *pObj = pSql->pTscObj; STscObj *pObj = pSql->pTscObj;
......
...@@ -1047,7 +1047,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t ...@@ -1047,7 +1047,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
} }
char *nextStr; char *nextStr;
char tblName[TSDB_METER_ID_LEN]; char tblName[TSDB_TABLE_ID_LEN];
int payloadLen = 0; int payloadLen = 0;
char *pMsg = pCmd->payload; char *pMsg = pCmd->payload;
while (1) { while (1) {
......
...@@ -657,7 +657,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff ...@@ -657,7 +657,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
dataBuf->size = startOffset; dataBuf->size = startOffset;
dataBuf->tsSource = -1; dataBuf->tsSource = -1;
strncpy(dataBuf->meterId, name, TSDB_METER_ID_LEN); strncpy(dataBuf->meterId, name, TSDB_TABLE_ID_LEN);
/* /*
* The metermeta may be released since the metermeta cache are completed clean by other thread * The metermeta may be released since the metermeta cache are completed clean by other thread
...@@ -1810,7 +1810,7 @@ SMeterMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, SM ...@@ -1810,7 +1810,7 @@ SMeterMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, SM
assert(pMeterMetaInfo != NULL); assert(pMeterMetaInfo != NULL);
if (name != NULL) { if (name != NULL) {
assert(strlen(name) <= TSDB_METER_ID_LEN); assert(strlen(name) <= TSDB_TABLE_ID_LEN);
strcpy(pMeterMetaInfo->name, name); strcpy(pMeterMetaInfo->name, name);
} }
......
...@@ -312,7 +312,7 @@ int vnodeProcessCreateMeterMsg(char *pMsg, int msgLen) { ...@@ -312,7 +312,7 @@ int vnodeProcessCreateMeterMsg(char *pMsg, int msgLen) {
pObj->vnode = pCreate->vnode; pObj->vnode = pCreate->vnode;
pObj->sid = pCreate->sid; pObj->sid = pCreate->sid;
pObj->uid = pCreate->uid; pObj->uid = pCreate->uid;
memcpy(pObj->meterId, pCreate->meterId, TSDB_METER_ID_LEN); memcpy(pObj->meterId, pCreate->meterId, TSDB_TABLE_ID_LEN);
pObj->numOfColumns = pCreate->numOfColumns; pObj->numOfColumns = pCreate->numOfColumns;
pObj->timeStamp = pCreate->timeStamp; pObj->timeStamp = pCreate->timeStamp;
pObj->sversion = htonl(pCreate->sversion); pObj->sversion = htonl(pCreate->sversion);
...@@ -377,7 +377,7 @@ int vnodeProcessRemoveMeterRequest(char *pMsg, int msgLen, SMgmtObj *pMgmtObj) { ...@@ -377,7 +377,7 @@ int vnodeProcessRemoveMeterRequest(char *pMsg, int msgLen, SMgmtObj *pMgmtObj) {
pObj = vnodeList[pRemove->vnode].meterList[pRemove->sid]; pObj = vnodeList[pRemove->vnode].meterList[pRemove->sid];
if (pObj == NULL) goto _remove_over; if (pObj == NULL) goto _remove_over;
if (memcmp(pObj->meterId, pRemove->meterId, TSDB_METER_ID_LEN) != 0) { if (memcmp(pObj->meterId, pRemove->meterId, TSDB_TABLE_ID_LEN) != 0) {
dWarn("vid:%d sid:%d id:%s, remove ID:%s, meter ID not matched", pObj->vnode, pObj->sid, pObj->meterId, dWarn("vid:%d sid:%d id:%s, remove ID:%s, meter ID not matched", pObj->vnode, pObj->sid, pObj->meterId,
pRemove->meterId); pRemove->meterId);
goto _remove_over; goto _remove_over;
......
...@@ -95,7 +95,7 @@ typedef struct { ...@@ -95,7 +95,7 @@ typedef struct {
} SMeterGid; } SMeterGid;
typedef struct _tab_obj { typedef struct _tab_obj {
char meterId[TSDB_METER_ID_LEN + 1]; char meterId[TSDB_TABLE_ID_LEN + 1];
uint64_t uid; uint64_t uid;
SMeterGid gid; SMeterGid gid;
...@@ -106,7 +106,7 @@ typedef struct _tab_obj { ...@@ -106,7 +106,7 @@ typedef struct _tab_obj {
int32_t numOfColumns; int32_t numOfColumns;
int32_t schemaSize; int32_t schemaSize;
short nextColId; short nextColId;
char meterType : 4; char tableType : 4;
char status : 3; char status : 3;
char isDirty : 1; // if the table change tag column 1 value char isDirty : 1; // if the table change tag column 1 value
char reserved[15]; char reserved[15];
...@@ -116,7 +116,7 @@ typedef struct _tab_obj { ...@@ -116,7 +116,7 @@ typedef struct _tab_obj {
tSkipList * pSkipList; tSkipList * pSkipList;
struct _tab_obj *pHead; // for metric, a link list for all meters created struct _tab_obj *pHead; // for metric, a link list for all meters created
// according to this metric // according to this metric
char *pTagData; // TSDB_METER_ID_LEN(metric_name)+ char *pTagData; // TSDB_TABLE_ID_LEN(metric_name)+
// tags_value1/tags_value2/tags_value3 // tags_value1/tags_value2/tags_value3
struct _tab_obj *prev, *next; struct _tab_obj *prev, *next;
char * pSql; // pointer to SQL, for SC, null-terminated string char * pSql; // pointer to SQL, for SC, null-terminated string
...@@ -262,8 +262,8 @@ extern SDnodeObj dnodeObj; ...@@ -262,8 +262,8 @@ extern SDnodeObj dnodeObj;
// dnodeInt API // dnodeInt API
int mgmtInitDnodeInt(); int mgmtInitDnodeInt();
void mgmtCleanUpDnodeInt(); void mgmtCleanUpDnodeInt();
int mgmtSendCreateMsgToVgroup(STabObj *pMeter, SVgObj *pVgroup); int mgmtSendCreateMsgToVgroup(STabObj *pTable, SVgObj *pVgroup);
int mgmtSendRemoveMeterMsgToDnode(STabObj *pMeter, SVgObj *pVgroup); int mgmtSendRemoveMeterMsgToDnode(STabObj *pTable, SVgObj *pVgroup);
int mgmtSendVPeersMsg(SVgObj *pVgroup); int mgmtSendVPeersMsg(SVgObj *pVgroup);
int mgmtSendFreeVnodeMsg(SVgObj *pVgroup); int mgmtSendFreeVnodeMsg(SVgObj *pVgroup);
int mgmtSendOneFreeVnodeMsg(SVnodeGid *pVnodeGid); int mgmtSendOneFreeVnodeMsg(SVnodeGid *pVnodeGid);
...@@ -284,8 +284,8 @@ int mgmtRetrieveUsers(SShowObj *pShow, char *data, int rows, SConnObj *pConn); ...@@ -284,8 +284,8 @@ int mgmtRetrieveUsers(SShowObj *pShow, char *data, int rows, SConnObj *pConn);
void mgmtCleanUpUsers(); void mgmtCleanUpUsers();
// metric API // metric API
int mgmtAddMeterIntoMetric(STabObj *pMetric, STabObj *pMeter); int mgmtAddMeterIntoMetric(STabObj *pMetric, STabObj *pTable);
int mgmtRemoveMeterFromMetric(STabObj *pMetric, STabObj *pMeter); int mgmtRemoveMeterFromMetric(STabObj *pMetric, STabObj *pTable);
int mgmtGetMetricMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn); int mgmtGetMetricMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn);
int mgmtRetrieveMetrics(SShowObj *pShow, char *data, int rows, SConnObj *pConn); int mgmtRetrieveMetrics(SShowObj *pShow, char *data, int rows, SConnObj *pConn);
...@@ -324,20 +324,17 @@ void mgmtCleanUpVgroups(); ...@@ -324,20 +324,17 @@ void mgmtCleanUpVgroups();
// meter API // meter API
int mgmtInitMeters(); int mgmtInitMeters();
STabObj *mgmtGetMeter(char *meterId); STabObj *mgmtGetTable(char *meterId);
STabObj *mgmtGetMeterInfo(char *src, char *tags[]); STabObj *mgmtGetTableInfo(char *src, char *tags[]);
int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pInfo); int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SSuperTableMetaMsg *pInfo);
int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate); int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate);
int mgmtDropMeter(SDbObj *pDb, char *meterId, int ignore); int mgmtDropMeter(SDbObj *pDb, char *meterId, int ignore);
int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter); int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter);
int mgmtGetMeterMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn); int mgmtGetTableMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn);
int mgmtRetrieveMeters(SShowObj *pShow, char *data, int rows, SConnObj *pConn); int mgmtRetrieveMeters(SShowObj *pShow, char *data, int rows, SConnObj *pConn);
void mgmtCleanUpMeters(); void mgmtCleanUpMeters();
SSchema *mgmtGetMeterSchema(STabObj *pMeter); // get schema for a meter SSchema *mgmtGetTableSchema(STabObj *pTable); // get schema for a meter
bool mgmtMeterCreateFromMetric(STabObj *pMeterObj);
bool mgmtIsMetric(STabObj *pMeterObj);
bool mgmtIsNormalMeter(STabObj *pMeterObj);
// dnode API // dnode API
int mgmtInitDnodes(); int mgmtInitDnodes();
...@@ -376,16 +373,6 @@ int grantRetrieveGrants(SShowObj *pShow, char *data, int rows, SConnObj *pConn); ...@@ -376,16 +373,6 @@ int grantRetrieveGrants(SShowObj *pShow, char *data, int rows, SConnObj *pConn);
int mgmtGetVnodeMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn); int mgmtGetVnodeMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn);
int mgmtRetrieveVnodes(SShowObj *pShow, char *data, int rows, SConnObj *pConn); int mgmtRetrieveVnodes(SShowObj *pShow, char *data, int rows, SConnObj *pConn);
// dnode balance api
int mgmtInitBalance();
void mgmtCleanupBalance();
int mgmtAllocVnodes(SVgObj *pVgroup);
int mgmtSetDnodeShellRemoving(SDnodeObj *pDnode);
void mgmtSetDnodeUnRemove(SDnodeObj *pDnode);
void mgmtStartBalanceTimer(int64_t mseconds);
void mgmtSetDnodeOfflineOnSdbChanged();
void mgmtUpdateVgroupState(SVgObj *pVgroup, int lbStatus, int srcIp);
bool mgmtAddVnode(SVgObj *pVgroup, SDnodeObj *pSrcDnode, SDnodeObj *pDestDnode);
void mgmtSetModuleInDnode(SDnodeObj *pDnode, int moduleType); void mgmtSetModuleInDnode(SDnodeObj *pDnode, int moduleType);
int mgmtUnSetModuleInDnode(SDnodeObj *pDnode, int moduleType); int mgmtUnSetModuleInDnode(SDnodeObj *pDnode, int moduleType);
......
...@@ -181,11 +181,14 @@ enum _mgmt_table { ...@@ -181,11 +181,14 @@ enum _mgmt_table {
#define TSDB_KILL_MSG_LEN 30 #define TSDB_KILL_MSG_LEN 30
#define TSDB_METER_METRIC 0 // metric enum {
#define TSDB_METER_MTABLE 1 // table created from metric TSDB_TABLE_TYPE_SUPER_TABLE = 0, // super table
#define TSDB_METER_OTABLE 2 // ordinary table TSDB_TABLE_TYPE_CREATE_FROM_STABLE = 1, // table created from super table
#define TSDB_METER_STABLE 3 // table created from stream computing TSDB_TABLE_TYPE_NORMAL_TABLE = 2, // ordinary table
#define TSDB_MAX_METER_TYPES 4 TSDB_TABLE_TYPE_STREAM_TABLE = 3, // table created from stream computing
TSDB_TABLE_TYPE_MAX = 4
} ETableType;
#define TSDB_VN_READ_ACCCESS ((char)0x1) #define TSDB_VN_READ_ACCCESS ((char)0x1)
#define TSDB_VN_WRITE_ACCCESS ((char)0x2) #define TSDB_VN_WRITE_ACCCESS ((char)0x2)
...@@ -298,7 +301,7 @@ typedef struct { ...@@ -298,7 +301,7 @@ typedef struct {
uint64_t uid; uint64_t uid;
char spi; char spi;
char encrypt; char encrypt;
char meterId[TSDB_METER_ID_LEN]; char meterId[TSDB_TABLE_ID_LEN];
char secret[TSDB_KEY_LEN]; char secret[TSDB_KEY_LEN];
char cipheringKey[TSDB_KEY_LEN]; char cipheringKey[TSDB_KEY_LEN];
uint64_t timeStamp; uint64_t timeStamp;
...@@ -311,7 +314,7 @@ typedef struct { ...@@ -311,7 +314,7 @@ typedef struct {
} SCreateMsg; } SCreateMsg;
typedef struct { typedef struct {
char db[TSDB_METER_ID_LEN]; char db[TSDB_TABLE_ID_LEN];
uint8_t ignoreNotExists; uint8_t ignoreNotExists;
} SDropDbMsg, SUseDbMsg; } SDropDbMsg, SUseDbMsg;
...@@ -324,7 +327,7 @@ typedef struct { ...@@ -324,7 +327,7 @@ typedef struct {
} SShowTableMsg; } SShowTableMsg;
typedef struct { typedef struct {
char meterId[TSDB_METER_ID_LEN]; char meterId[TSDB_TABLE_ID_LEN];
char igExists; char igExists;
short numOfTags; short numOfTags;
...@@ -338,12 +341,12 @@ typedef struct { ...@@ -338,12 +341,12 @@ typedef struct {
} SCreateTableMsg; } SCreateTableMsg;
typedef struct { typedef struct {
char meterId[TSDB_METER_ID_LEN]; char meterId[TSDB_TABLE_ID_LEN];
char igNotExists; char igNotExists;
} SDropTableMsg; } SDropTableMsg;
typedef struct { typedef struct {
char meterId[TSDB_METER_ID_LEN]; char meterId[TSDB_TABLE_ID_LEN];
short type; /* operation type */ short type; /* operation type */
char tagVal[TSDB_MAX_BYTES_PER_ROW]; char tagVal[TSDB_MAX_BYTES_PER_ROW];
short numOfCols; /* number of schema */ short numOfCols; /* number of schema */
...@@ -352,7 +355,7 @@ typedef struct { ...@@ -352,7 +355,7 @@ typedef struct {
typedef struct { typedef struct {
char clientVersion[TSDB_VERSION_LEN]; char clientVersion[TSDB_VERSION_LEN];
char db[TSDB_METER_ID_LEN]; char db[TSDB_TABLE_ID_LEN];
} SConnectMsg; } SConnectMsg;
typedef struct { typedef struct {
...@@ -383,7 +386,7 @@ typedef struct { ...@@ -383,7 +386,7 @@ typedef struct {
} SCreateUserMsg, SAlterUserMsg; } SCreateUserMsg, SAlterUserMsg;
typedef struct { typedef struct {
char db[TSDB_METER_ID_LEN]; char db[TSDB_TABLE_ID_LEN];
} SMgmtHead; } SMgmtHead;
typedef struct { typedef struct {
...@@ -397,7 +400,7 @@ typedef struct { ...@@ -397,7 +400,7 @@ typedef struct {
short vnode; short vnode;
int32_t sid; int32_t sid;
uint64_t uid; uint64_t uid;
char meterId[TSDB_METER_ID_LEN]; char meterId[TSDB_TABLE_ID_LEN];
} SRemoveMeterMsg; } SRemoveMeterMsg;
typedef struct { typedef struct {
...@@ -601,7 +604,7 @@ typedef struct { ...@@ -601,7 +604,7 @@ typedef struct {
* the message is too large, so it may will overwrite the cfg information in meterobj.v* * the message is too large, so it may will overwrite the cfg information in meterobj.v*
* recover to origin codes * recover to origin codes
*/ */
//char db[TSDB_METER_ID_LEN+2]; // 8bytes align //char db[TSDB_TABLE_ID_LEN+2]; // 8bytes align
char db[TSDB_DB_NAME_LEN]; char db[TSDB_DB_NAME_LEN];
uint32_t vgId; uint32_t vgId;
int32_t maxSessions; int32_t maxSessions;
...@@ -692,7 +695,7 @@ typedef struct { ...@@ -692,7 +695,7 @@ typedef struct {
} SVPeersMsg; } SVPeersMsg;
typedef struct { typedef struct {
char meterId[TSDB_METER_ID_LEN]; char meterId[TSDB_TABLE_ID_LEN];
short createFlag; short createFlag;
char tags[]; char tags[];
} SMeterInfoMsg; } SMeterInfoMsg;
...@@ -705,7 +708,7 @@ typedef struct { ...@@ -705,7 +708,7 @@ typedef struct {
typedef struct { typedef struct {
int16_t elemLen; int16_t elemLen;
char meterId[TSDB_METER_ID_LEN]; char meterId[TSDB_TABLE_ID_LEN];
int16_t orderIndex; int16_t orderIndex;
int16_t orderType; // used in group by xx order by xxx int16_t orderType; // used in group by xx order by xxx
...@@ -729,7 +732,7 @@ typedef struct { ...@@ -729,7 +732,7 @@ typedef struct {
int32_t join; int32_t join;
int32_t joinCondLen; // for join condition int32_t joinCondLen; // for join condition
int32_t metaElem[TSDB_MAX_JOIN_TABLE_NUM]; int32_t metaElem[TSDB_MAX_JOIN_TABLE_NUM];
} SMetricMetaMsg; } SSuperTableMetaMsg;
typedef struct { typedef struct {
SVPeerDesc vpeerDesc[TSDB_VNODES_SUPPORT]; SVPeerDesc vpeerDesc[TSDB_VNODES_SUPPORT];
...@@ -748,7 +751,7 @@ typedef struct { ...@@ -748,7 +751,7 @@ typedef struct {
typedef struct SMeterMeta { typedef struct SMeterMeta {
uint8_t numOfTags : 6; uint8_t numOfTags : 6;
uint8_t precision : 2; uint8_t precision : 2;
uint8_t meterType : 4; uint8_t tableType : 4;
uint8_t index : 4; // used locally uint8_t index : 4; // used locally
int16_t numOfColumns; int16_t numOfColumns;
...@@ -764,12 +767,12 @@ typedef struct SMeterMeta { ...@@ -764,12 +767,12 @@ typedef struct SMeterMeta {
} SMeterMeta; } SMeterMeta;
typedef struct SMultiMeterMeta { typedef struct SMultiMeterMeta {
char meterId[TSDB_METER_ID_LEN]; // note: This field must be at the front char meterId[TSDB_TABLE_ID_LEN]; // note: This field must be at the front
SMeterMeta meta; SMeterMeta meta;
} SMultiMeterMeta; } SMultiMeterMeta;
typedef struct { typedef struct {
char name[TSDB_METER_ID_LEN]; char name[TSDB_TABLE_ID_LEN];
char data[TSDB_MAX_TAGS_LEN]; char data[TSDB_MAX_TAGS_LEN];
} STagData; } STagData;
......
...@@ -86,7 +86,7 @@ extern "C" { ...@@ -86,7 +86,7 @@ extern "C" {
#define TS_PATH_DELIMITER_LEN 1 #define TS_PATH_DELIMITER_LEN 1
#define TSDB_METER_ID_LEN_MARGIN 10 #define TSDB_METER_ID_LEN_MARGIN 10
#define TSDB_METER_ID_LEN (TSDB_DB_NAME_LEN+TSDB_METER_NAME_LEN+2*TS_PATH_DELIMITER_LEN+TSDB_USERID_LEN+TSDB_METER_ID_LEN_MARGIN) //TSDB_DB_NAME_LEN+TSDB_METER_NAME_LEN+2*strlen(TS_PATH_DELIMITER)+strlen(USERID) #define TSDB_TABLE_ID_LEN (TSDB_DB_NAME_LEN+TSDB_METER_NAME_LEN+2*TS_PATH_DELIMITER_LEN+TSDB_USERID_LEN+TSDB_METER_ID_LEN_MARGIN) //TSDB_DB_NAME_LEN+TSDB_METER_NAME_LEN+2*strlen(TS_PATH_DELIMITER)+strlen(USERID)
#define TSDB_UNI_LEN 24 #define TSDB_UNI_LEN 24
#define TSDB_USER_LEN TSDB_UNI_LEN #define TSDB_USER_LEN TSDB_UNI_LEN
#define TSDB_ACCT_LEN TSDB_UNI_LEN #define TSDB_ACCT_LEN TSDB_UNI_LEN
......
...@@ -2,22 +2,20 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) ...@@ -2,22 +2,20 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/dnode/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/mnode/detail/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/vnode/detail/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/dnode/inc)
INCLUDE_DIRECTORIES(inc) INCLUDE_DIRECTORIES(inc)
AUX_SOURCE_DIRECTORY(src SRC) AUX_SOURCE_DIRECTORY(src SRC)
ADD_LIBRARY(mnode ${SRC}) ADD_LIBRARY(mnode ${SRC})
TARGET_LINK_LIBRARIES(mnode trpc tutil sdb pthread) #TARGET_LINK_LIBRARIES(mnode trpc tutil sdb pthread)
IF (TD_CLUSTER) #IF (TD_CLUSTER)
TARGET_LINK_LIBRARIES(mnode mcluster) # TARGET_LINK_LIBRARIES(mnode mcluster)
ELSEIF (TD_LITE) #ENDIF ()
TARGET_LINK_LIBRARIES(mnode mlite)
ENDIF ()
ENDIF () ENDIF ()
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include "mgmt.h" #include "mnode.h"
int32_t mgmtCreateAcct(char *name, char *pass, SAcctCfg *pCfg); int32_t mgmtCreateAcct(char *name, char *pass, SAcctCfg *pCfg);
int32_t mgmtUpdateAcct(SAcctObj *pAcct); int32_t mgmtUpdateAcct(SAcctObj *pAcct);
......
...@@ -13,60 +13,32 @@ ...@@ -13,60 +13,32 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_MGMTBALANCE_H #ifndef TDENGINE_MGMT_BALANCE_H
#define TDENGINE_MGMTBALANCE_H #define TDENGINE_MGMT_BALANCE_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "os.h" #include "os.h"
#include "mnode.h"
#include "dnodeSystem.h"
#include "mgmt.h"
#include "tglobalcfg.h" #include "tglobalcfg.h"
#include "vnodeStatus.h" #include "vnodeStatus.h"
#include "ttime.h" #include "ttime.h"
void mgmtCreateDnodeOrderList(); extern void (*mgmtStartBalanceTimer)(int64_t mseconds);
extern int32_t (*mgmtInitBalance)();
void mgmtReleaseDnodeOrderList(); extern void (*mgmtCleanupBalance)();
extern int32_t (*mgmtAllocVnodes)(SVgObj *pVgroup);
void mgmtMakeDnodeOrderList(); extern bool (*mgmtCheckModuleInDnode)(SDnodeObj *pDnode, int moduleType);
extern char* (*mgmtGetVnodeStatus)(SVgObj *pVgroup, SVnodeGid *pVnode);
void mgmtCalcSystemScore(); extern bool (*mgmtCheckVnodeReady)(SDnodeObj *pDnode, SVgObj *pVgroup, SVnodeGid *pVnode);
extern void (*mgmtUpdateDnodeState)(SDnodeObj *pDnode, int lbStatus);
float mgmtTryCalcDnodeScore(SDnodeObj *pDnode, int extraVnode); extern void (*mgmtUpdateVgroupState)(SVgObj *pVgroup, int lbStatus, int srcIp);
extern bool (*mgmtAddVnode)(SVgObj *pVgroup, SDnodeObj *pSrcDnode, SDnodeObj *pDestDnode);
bool mgmtCheckDnodeInOfflineState(SDnodeObj *pDnode);
bool mgmtCheckDnodeInRemoveState(SDnodeObj *pDnode);
bool mgmtCheckModuleInDnode(SDnodeObj *pDnode, int moduleType);
void mgmtMonitorDnodeModule();
void mgmtSetModuleInDnode(SDnodeObj *pDnode, int moduleType);
int mgmtUnSetModuleInDnode(SDnodeObj *pDnode, int moduleType);
void mgmtMonitorVgroups();
void mgmtMonitorDnodes();
void mgmtCalcNumOfFreeVnodes(SDnodeObj *pDnode);
extern void * dnodeSdb;
extern void * vgSdb;
extern void * balanceTimer;
extern int mgmtOrderedDnodesSize;
extern int mgmtOrderedDnodesMallocSize;
extern SDnodeObj **mgmtOrderedDnodes;
extern uint32_t mgmtAccessSquence;
extern SMgmtIpList mgmtIpList;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // TDENGINE_MGMTBALANCE_H #endif
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include "mgmt.h" #include "mnode.h"
int mgmtGetQueryMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn); int mgmtGetQueryMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn);
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TBASE_MNODE_SUPER_TABLE_QUERY_H
#define TBASE_MNODE_SUPER_TABLE_QUERY_H
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "mnode.h"
int32_t mgmtRetrieveMetersFromSuperTable(SSuperTableMetaMsg* pInfo, int32_t tableIndex, tQueryResultset* pRes);
int32_t mgmtDoJoin(SSuperTableMetaMsg* pSuperTableMetaMsg, tQueryResultset* pRes);
void mgmtReorganizeMetersInMetricMeta(SSuperTableMetaMsg* pInfo, int32_t index, tQueryResultset* pRes);
#endif
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TBASE_MNODE_TABLE_H
#define TBASE_MNODE_TABLE_H
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "mnode.h"
int32_t mgmtFindTagCol(STabObj * pTable, const char * tagName);
#endif
...@@ -11,32 +11,22 @@ ...@@ -11,32 +11,22 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/#include <stdio.h> */
#include <stdlib.h>
#include <stdint.h>
#include "tast.h"
#ifndef TBASE_MGMTUTIL_H
#define TBASE_MGMTUTIL_H
typedef struct SSyntaxTreeFilterSupporter { #ifndef TBASE_MNODE_UTIL_H
SSchema* pTagSchema; #define TBASE_MNODE_UTIL_H
int32_t numOfTags;
int32_t optr;
} SSyntaxTreeFilterSupporter;
char* mgmtMeterGetTag(STabObj* pMeter, int32_t col, SSchema* pTagColSchema); #include <stdio.h>
int32_t mgmtFindTagCol(STabObj * pMetric, const char * tagName); #include <stdlib.h>
#include <stdint.h>
#include "mnode.h"
int32_t mgmtGetTagsLength(STabObj* pMetric, int32_t col); bool mgmtTableCreateFromSuperTable(STabObj *pTableObj);
bool mgmtIsSuperTable(STabObj *pTableObj);
bool mgmtIsNormalTable(STabObj *pTableObj);
char* mgmtTableGetTag(STabObj* pTable, int32_t col, SSchema* pTagColSchema);
int32_t mgmtGetTagsLength(STabObj* pSuperTable, int32_t col);
bool mgmtCheckIsMonitorDB(char *db, char *monitordb); bool mgmtCheckIsMonitorDB(char *db, char *monitordb);
int32_t mgmtCheckDBParams(SCreateDbMsg *pCreate); int32_t mgmtCheckDBParams(SCreateDbMsg *pCreate);
int32_t mgmtRetrieveMetersFromMetric(SMetricMetaMsg* pInfo, int32_t tableIndex, tQueryResultset* pRes); #endif
int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes);
void mgmtReorganizeMetersInMetricMeta(SMetricMetaMsg* pInfo, int32_t index, tQueryResultset* pRes);
bool tSkipListNodeFilterCallback(const void *pNode, void *param);
#endif //TBASE_MGMTUTIL_H
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "mgmt.h" #include "mnode.h"
#include "mgmtAcct.h" #include "mgmtAcct.h"
#include "tschemautil.h" #include "tschemautil.h"
......
...@@ -18,13 +18,16 @@ ...@@ -18,13 +18,16 @@
#include "vnodeStatus.h" #include "vnodeStatus.h"
#include "dnodeModule.h" #include "dnodeModule.h"
void mgmtStartBalanceTimer(int64_t mseconds) {} void mgmtStartBalanceTimerImp(int64_t mseconds) {}
void (*mgmtStartBalanceTimer)(int64_t mseconds) = mgmtStartBalanceTimerImp;
int mgmtInitBalance() { return 0; } int32_t mgmtInitBalanceImp() { return 0; }
int32_t (*mgmtInitBalance)() = mgmtInitBalanceImp;
void mgmtCleanupBalance() {} void mgmtCleanupBalanceImp() {}
void (*mgmtCleanupBalance)() = mgmtCleanupBalanceImp;
int mgmtAllocVnodes(SVgObj *pVgroup) { int32_t mgmtAllocVnodesImp(SVgObj *pVgroup) {
int selectedVnode = -1; int selectedVnode = -1;
SDnodeObj *pDnode = &dnodeObj; SDnodeObj *pDnode = &dnodeObj;
int lastAllocVode = pDnode->lastAllocVnode; int lastAllocVode = pDnode->lastAllocVnode;
...@@ -48,17 +51,26 @@ int mgmtAllocVnodes(SVgObj *pVgroup) { ...@@ -48,17 +51,26 @@ int mgmtAllocVnodes(SVgObj *pVgroup) {
return 0; return 0;
} }
} }
int32_t (*mgmtAllocVnodes)(SVgObj *pVgroup) = mgmtAllocVnodesImp;
bool mgmtCheckModuleInDnode(SDnodeObj *pDnode, int moduleType) { bool mgmtCheckModuleInDnodeImp(SDnodeObj *pDnode, int moduleType) {
return tsModule[moduleType].num != 0; return tsModule[moduleType].num != 0;
} }
bool (*mgmtCheckModuleInDnode)(SDnodeObj *pDnode, int moduleType) = mgmtCheckModuleInDnodeImp;
char *mgmtGetVnodeStatus(SVgObj *pVgroup, SVnodeGid *pVnode) { return "master"; } char *mgmtGetVnodeStatusImp(SVgObj *pVgroup, SVnodeGid *pVnode) { return "master"; }
char *(*mgmtGetVnodeStatus)(SVgObj *pVgroup, SVnodeGid *pVnode) = mgmtGetVnodeStatusImp;
bool mgmtCheckVnodeReady(SDnodeObj *pDnode, SVgObj *pVgroup, SVnodeGid *pVnode) { return true; } bool mgmtCheckVnodeReadyImp(SDnodeObj *pDnode, SVgObj *pVgroup, SVnodeGid *pVnode) { return true; }
bool (*mgmtCheckVnodeReady)(SDnodeObj *pDnode, SVgObj *pVgroup, SVnodeGid *pVnode) = mgmtCheckVnodeReadyImp;
void mgmtUpdateDnodeState(SDnodeObj *pDnode, int lbStatus) {}
void mgmtUpdateVgroupState(SVgObj *pVgroup, int lbStatus, int srcIp) {} void mgmtUpdateDnodeStateImp(SDnodeObj *pDnode, int lbStatus) {}
void (*mgmtUpdateDnodeState)(SDnodeObj *pDnode, int lbStatus) = mgmtUpdateDnodeStateImp;
void mgmtUpdateVgroupStateImp(SVgObj *pVgroup, int lbStatus, int srcIp) {}
void (*mgmtUpdateVgroupState)(SVgObj *pVgroup, int lbStatus, int srcIp) = mgmtUpdateVgroupStateImp;
bool mgmtAddVnodeImp(SVgObj *pVgroup, SDnodeObj *pSrcDnode, SDnodeObj *pDestDnode) { return false; }
bool (*mgmtAddVnode)(SVgObj *pVgroup, SDnodeObj *pSrcDnode, SDnodeObj *pDestDnode) = mgmtAddVnodeImp;
bool mgmtAddVnode(SVgObj *pVgroup, SDnodeObj *pSrcDnode, SDnodeObj *pDestDnode) { return false; }
\ No newline at end of file
...@@ -14,15 +14,13 @@ ...@@ -14,15 +14,13 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "mnode.h"
#include "mgmt.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tschemautil.h" #include "tschemautil.h"
typedef struct { typedef struct {
char user[TSDB_METER_ID_LEN]; char user[TSDB_TABLE_ID_LEN];
uint64_t stime; uint64_t stime;
uint32_t ip; uint32_t ip;
uint16_t port; uint16_t port;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "mgmt.h" #include "mnode.h"
#include "mgmtGrant.h" #include "mgmtGrant.h"
#include "mgmtBalance.h" #include "mgmtBalance.h"
#include "mgmtUtil.h" #include "mgmtUtil.h"
...@@ -116,7 +116,7 @@ int mgmtInitDbs() { ...@@ -116,7 +116,7 @@ int mgmtInitDbs() {
SDbObj *mgmtGetDb(char *db) { return (SDbObj *)sdbGetRow(dbSdb, db); } SDbObj *mgmtGetDb(char *db) { return (SDbObj *)sdbGetRow(dbSdb, db); }
SDbObj *mgmtGetDbByMeterId(char *meterId) { SDbObj *mgmtGetDbByMeterId(char *meterId) {
char db[TSDB_METER_ID_LEN], *pos; char db[TSDB_TABLE_ID_LEN], *pos;
pos = strstr(meterId, TS_PATH_DELIMITER); pos = strstr(meterId, TS_PATH_DELIMITER);
pos = strstr(pos + 1, TS_PATH_DELIMITER); pos = strstr(pos + 1, TS_PATH_DELIMITER);
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "os.h" #include "os.h"
#include "dnodeSystem.h" #include "dnodeSystem.h"
#include "mgmt.h" #include "mnode.h"
#include "tschemautil.h" #include "tschemautil.h"
#include "vnodeStatus.h" #include "vnodeStatus.h"
#include "dnodeModule.h" #include "dnodeModule.h"
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "mgmt.h" #include "mnode.h"
#include "vnodeStatus.h" #include "vnodeStatus.h"
#include "dnodeModule.h" #include "dnodeModule.h"
......
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
#include "os.h" #include "os.h"
#include "dnodeSystem.h" #include "dnodeSystem.h"
#include "mgmt.h" #include "mnode.h"
#include "mgmtBalance.h" #include "mgmtBalance.h"
#include "tutil.h" #include "tutil.h"
void mgmtProcessMsgFromDnode(char *content, int msgLen, int msgType, SDnodeObj *pObj); void mgmtProcessMsgFromDnode(char *content, int msgLen, int msgType, SDnodeObj *pObj);
int mgmtSendVPeersMsg(SVgObj *pVgroup); int mgmtSendVPeersMsg(SVgObj *pVgroup);
char *mgmtBuildVpeersIe(char *pMsg, SVgObj *pVgroup, int vnode); char *mgmtBuildVpeersIe(char *pMsg, SVgObj *pVgroup, int vnode);
char *mgmtBuildCreateMeterIe(STabObj *pMeter, char *pMsg, int vnode); char *mgmtBuildCreateMeterIe(STabObj *pTable, char *pMsg, int vnode);
/* /*
* functions for communicate between dnode and mnode * functions for communicate between dnode and mnode
...@@ -39,7 +39,7 @@ int taosSendMsgToDnode(SDnodeObj *pObj, char *msg, int msgLen); ...@@ -39,7 +39,7 @@ int taosSendMsgToDnode(SDnodeObj *pObj, char *msg, int msgLen);
int mgmtProcessMeterCfgMsg(char *cont, int contLen, SDnodeObj *pObj) { int mgmtProcessMeterCfgMsg(char *cont, int contLen, SDnodeObj *pObj) {
char * pMsg, *pStart; char * pMsg, *pStart;
int msgLen = 0; int msgLen = 0;
STabObj * pMeter = NULL; STabObj * pTable = NULL;
SMeterCfgMsg *pCfg = (SMeterCfgMsg *)cont; SMeterCfgMsg *pCfg = (SMeterCfgMsg *)cont;
SVgObj * pVgroup; SVgObj * pVgroup;
...@@ -63,13 +63,13 @@ int mgmtProcessMeterCfgMsg(char *cont, int contLen, SDnodeObj *pObj) { ...@@ -63,13 +63,13 @@ int mgmtProcessMeterCfgMsg(char *cont, int contLen, SDnodeObj *pObj) {
int vgId = pObj->vload[vnode].vgId; int vgId = pObj->vload[vnode].vgId;
pVgroup = mgmtGetVgroup(vgId); pVgroup = mgmtGetVgroup(vgId);
if (pVgroup) pMeter = pVgroup->meterList[sid]; if (pVgroup) pTable = pVgroup->meterList[sid];
} }
if (pMeter) { if (pTable) {
*pMsg = 0; // code *pMsg = 0; // code
pMsg++; pMsg++;
pMsg = mgmtBuildCreateMeterIe(pMeter, pMsg, vnode); pMsg = mgmtBuildCreateMeterIe(pTable, pMsg, vnode);
} else { } else {
mTrace("dnode:%s, vnode:%d sid:%d, meter not there", taosIpStr(pObj->privateIp), vnode, sid); mTrace("dnode:%s, vnode:%d sid:%d, meter not there", taosIpStr(pObj->privateIp), vnode, sid);
*pMsg = TSDB_CODE_INVALID_METER_ID; *pMsg = TSDB_CODE_INVALID_METER_ID;
...@@ -187,48 +187,48 @@ void mgmtProcessMsgFromDnode(char *content, int msgLen, int msgType, SDnodeObj * ...@@ -187,48 +187,48 @@ void mgmtProcessMsgFromDnode(char *content, int msgLen, int msgType, SDnodeObj *
} }
} }
char *mgmtBuildCreateMeterIe(STabObj *pMeter, char *pMsg, int vnode) { char *mgmtBuildCreateMeterIe(STabObj *pTable, char *pMsg, int vnode) {
SCreateMsg *pCreateMeter; SCreateMsg *pCreateMeter;
pCreateMeter = (SCreateMsg *)pMsg; pCreateMeter = (SCreateMsg *)pMsg;
pCreateMeter->vnode = htons(vnode); pCreateMeter->vnode = htons(vnode);
pCreateMeter->sid = htonl(pMeter->gid.sid); pCreateMeter->sid = htonl(pTable->gid.sid);
pCreateMeter->uid = pMeter->uid; pCreateMeter->uid = pTable->uid;
memcpy(pCreateMeter->meterId, pMeter->meterId, TSDB_METER_ID_LEN); memcpy(pCreateMeter->meterId, pTable->meterId, TSDB_TABLE_ID_LEN);
// pCreateMeter->lastCreate = htobe64(pVgroup->lastCreate); // pCreateMeter->lastCreate = htobe64(pVgroup->lastCreate);
pCreateMeter->timeStamp = htobe64(pMeter->createdTime); pCreateMeter->timeStamp = htobe64(pTable->createdTime);
/* /*
pCreateMeter->spi = pSec->spi; pCreateMeter->spi = pSec->spi;
pCreateMeter->encrypt = pSec->encrypt; pCreateMeter->encrypt = pSec->encrypt;
memcpy(pCreateMeter->cipheringKey, pSec->cipheringKey, TSDB_KEY_LEN); memcpy(pCreateMeter->cipheringKey, pSec->cipheringKey, TSDB_KEY_LEN);
memcpy(pCreateMeter->secret, pSec->secret, TSDB_KEY_LEN); memcpy(pCreateMeter->secret, pSec->secret, TSDB_KEY_LEN);
*/ */
pCreateMeter->sversion = htonl(pMeter->sversion); pCreateMeter->sversion = htonl(pTable->sversion);
pCreateMeter->numOfColumns = htons(pMeter->numOfColumns); pCreateMeter->numOfColumns = htons(pTable->numOfColumns);
SSchema *pSchema = mgmtGetMeterSchema(pMeter); SSchema *pSchema = mgmtGetTableSchema(pTable);
for (int i = 0; i < pMeter->numOfColumns; ++i) { for (int i = 0; i < pTable->numOfColumns; ++i) {
pCreateMeter->schema[i].type = pSchema[i].type; pCreateMeter->schema[i].type = pSchema[i].type;
/* strcpy(pCreateMeter->schema[i].name, pSchema[i].name); */ /* strcpy(pCreateMeter->schema[i].name, pSchema[i].name); */
pCreateMeter->schema[i].bytes = htons(pSchema[i].bytes); pCreateMeter->schema[i].bytes = htons(pSchema[i].bytes);
pCreateMeter->schema[i].colId = htons(pSchema[i].colId); pCreateMeter->schema[i].colId = htons(pSchema[i].colId);
} }
pMsg = ((char *)(pCreateMeter->schema)) + pMeter->numOfColumns * sizeof(SMColumn); pMsg = ((char *)(pCreateMeter->schema)) + pTable->numOfColumns * sizeof(SMColumn);
pCreateMeter->sqlLen = 0; pCreateMeter->sqlLen = 0;
if (pMeter->pSql) { if (pTable->pSql) {
int len = strlen(pMeter->pSql) + 1; int len = strlen(pTable->pSql) + 1;
pCreateMeter->sqlLen = htons(len); pCreateMeter->sqlLen = htons(len);
strcpy(pMsg, pMeter->pSql); strcpy(pMsg, pTable->pSql);
pMsg += len; pMsg += len;
} }
return pMsg; return pMsg;
} }
int mgmtSendCreateMsgToVgroup(STabObj *pMeter, SVgObj *pVgroup) { int mgmtSendCreateMsgToVgroup(STabObj *pTable, SVgObj *pVgroup) {
char * pMsg, *pStart; char * pMsg, *pStart;
int i, msgLen = 0; int i, msgLen = 0;
SDnodeObj *pObj; SDnodeObj *pObj;
...@@ -244,7 +244,7 @@ int mgmtSendCreateMsgToVgroup(STabObj *pMeter, SVgObj *pVgroup) { ...@@ -244,7 +244,7 @@ int mgmtSendCreateMsgToVgroup(STabObj *pMeter, SVgObj *pVgroup) {
pStart = taosBuildReqMsgToDnodeWithSize(pObj, TSDB_MSG_TYPE_CREATE, 64000); pStart = taosBuildReqMsgToDnodeWithSize(pObj, TSDB_MSG_TYPE_CREATE, 64000);
if (pStart == NULL) continue; if (pStart == NULL) continue;
pMsg = mgmtBuildCreateMeterIe(pMeter, pStart, pVgroup->vnodeGid[i].vnode); pMsg = mgmtBuildCreateMeterIe(pTable, pStart, pVgroup->vnodeGid[i].vnode);
msgLen = pMsg - pStart; msgLen = pMsg - pStart;
taosSendMsgToDnode(pObj, pStart, msgLen); taosSendMsgToDnode(pObj, pStart, msgLen);
...@@ -255,7 +255,7 @@ int mgmtSendCreateMsgToVgroup(STabObj *pMeter, SVgObj *pVgroup) { ...@@ -255,7 +255,7 @@ int mgmtSendCreateMsgToVgroup(STabObj *pMeter, SVgObj *pVgroup) {
return 0; return 0;
} }
int mgmtSendRemoveMeterMsgToDnode(STabObj *pMeter, SVgObj *pVgroup) { int mgmtSendRemoveMeterMsgToDnode(STabObj *pTable, SVgObj *pVgroup) {
SRemoveMeterMsg *pRemove; SRemoveMeterMsg *pRemove;
char * pMsg, *pStart; char * pMsg, *pStart;
int i, msgLen = 0; int i, msgLen = 0;
...@@ -277,8 +277,8 @@ int mgmtSendRemoveMeterMsgToDnode(STabObj *pMeter, SVgObj *pVgroup) { ...@@ -277,8 +277,8 @@ int mgmtSendRemoveMeterMsgToDnode(STabObj *pMeter, SVgObj *pVgroup) {
pRemove = (SRemoveMeterMsg *)pMsg; pRemove = (SRemoveMeterMsg *)pMsg;
pRemove->vnode = htons(pVgroup->vnodeGid[i].vnode); pRemove->vnode = htons(pVgroup->vnodeGid[i].vnode);
pRemove->sid = htonl(pMeter->gid.sid); pRemove->sid = htonl(pTable->gid.sid);
memcpy(pRemove->meterId, pMeter->meterId, TSDB_METER_ID_LEN); memcpy(pRemove->meterId, pTable->meterId, TSDB_TABLE_ID_LEN);
pMsg += sizeof(SRemoveMeterMsg); pMsg += sizeof(SRemoveMeterMsg);
msgLen = pMsg - pStart; msgLen = pMsg - pStart;
...@@ -287,7 +287,7 @@ int mgmtSendRemoveMeterMsgToDnode(STabObj *pMeter, SVgObj *pVgroup) { ...@@ -287,7 +287,7 @@ int mgmtSendRemoveMeterMsgToDnode(STabObj *pMeter, SVgObj *pVgroup) {
tinet_ntoa(ipstr, pVgroup->vnodeGid[i].ip); tinet_ntoa(ipstr, pVgroup->vnodeGid[i].ip);
mTrace("dnode:%s vid:%d, send remove meter msg, sid:%d status:%d", ipstr, pVgroup->vnodeGid[i].vnode, mTrace("dnode:%s vid:%d, send remove meter msg, sid:%d status:%d", ipstr, pVgroup->vnodeGid[i].vnode,
pMeter->gid.sid, pObj->status); pTable->gid.sid, pObj->status);
} }
pVgroup->lastRemove = timeStamp; pVgroup->lastRemove = timeStamp;
...@@ -295,7 +295,7 @@ int mgmtSendRemoveMeterMsgToDnode(STabObj *pMeter, SVgObj *pVgroup) { ...@@ -295,7 +295,7 @@ int mgmtSendRemoveMeterMsgToDnode(STabObj *pMeter, SVgObj *pVgroup) {
return 0; return 0;
} }
int mgmtSendAlterStreamMsgToDnode(STabObj *pMeter, SVgObj *pVgroup) { int mgmtSendAlterStreamMsgToDnode(STabObj *pTable, SVgObj *pVgroup) {
SAlterStreamMsg *pAlter; SAlterStreamMsg *pAlter;
char * pMsg, *pStart; char * pMsg, *pStart;
int i, msgLen = 0; int i, msgLen = 0;
...@@ -313,9 +313,9 @@ int mgmtSendAlterStreamMsgToDnode(STabObj *pMeter, SVgObj *pVgroup) { ...@@ -313,9 +313,9 @@ int mgmtSendAlterStreamMsgToDnode(STabObj *pMeter, SVgObj *pVgroup) {
pAlter = (SAlterStreamMsg *)pMsg; pAlter = (SAlterStreamMsg *)pMsg;
pAlter->vnode = htons(pVgroup->vnodeGid[i].vnode); pAlter->vnode = htons(pVgroup->vnodeGid[i].vnode);
pAlter->sid = htonl(pMeter->gid.sid); pAlter->sid = htonl(pTable->gid.sid);
pAlter->uid = pMeter->uid; pAlter->uid = pTable->uid;
pAlter->status = pMeter->status; pAlter->status = pTable->status;
pMsg += sizeof(SAlterStreamMsg); pMsg += sizeof(SAlterStreamMsg);
msgLen = pMsg - pStart; msgLen = pMsg - pStart;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <endian.h> #include <endian.h>
#include "dnodeSystem.h" #include "dnodeSystem.h"
#include "mgmt.h" #include "mnode.h"
#include "tsched.h" #include "tsched.h"
#include "tutil.h" #include "tutil.h"
#include "vnode.h" #include "vnode.h"
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "mgmt.h" #include "mnode.h"
#include "mgmtAcct.h" #include "mgmtAcct.h"
#include "mgmtGrant.h" #include "mgmtGrant.h"
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "mgmt.h" #include "mnode.h"
int mgmtGetMnodeMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { return TSDB_CODE_OPS_NOT_SUPPORT; } int mgmtGetMnodeMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { return TSDB_CODE_OPS_NOT_SUPPORT; }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "mgmt.h" #include "mnode.h"
#include "mgmtProfile.h" #include "mgmtProfile.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tschemautil.h" #include "tschemautil.h"
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
typedef struct { typedef struct {
uint32_t ip; uint32_t ip;
uint16_t port; uint16_t port;
char user[TSDB_METER_ID_LEN]; char user[TSDB_TABLE_ID_LEN];
} SCDesc; } SCDesc;
typedef struct { typedef struct {
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "os.h" #include "os.h"
#include "dnodeSystem.h" #include "dnodeSystem.h"
#include "mgmt.h" #include "mnode.h"
#include "mgmtGrant.h" #include "mgmtGrant.h"
#include "mgmtProfile.h" #include "mgmtProfile.h"
#include "taosmsg.h" #include "taosmsg.h"
...@@ -118,7 +118,7 @@ static void mgmtSetSchemaFromMeters(SSchema *pSchema, STabObj *pMeterObj, uint32 ...@@ -118,7 +118,7 @@ static void mgmtSetSchemaFromMeters(SSchema *pSchema, STabObj *pMeterObj, uint32
static uint32_t mgmtSetMeterTagValue(char *pTags, STabObj *pMetric, STabObj *pMeterObj) { static uint32_t mgmtSetMeterTagValue(char *pTags, STabObj *pMetric, STabObj *pMeterObj) {
SSchema *pTagSchema = (SSchema *)(pMetric->schema + pMetric->numOfColumns * sizeof(SSchema)); SSchema *pTagSchema = (SSchema *)(pMetric->schema + pMetric->numOfColumns * sizeof(SSchema));
char *tagVal = pMeterObj->pTagData + TSDB_METER_ID_LEN; // tag start position char *tagVal = pMeterObj->pTagData + TSDB_TABLE_ID_LEN; // tag start position
uint32_t tagsLen = 0; uint32_t tagsLen = 0;
for (int32_t i = 0; i < pMetric->numOfTags; ++i) { for (int32_t i = 0; i < pMetric->numOfTags; ++i) {
...@@ -157,7 +157,7 @@ bool mgmtCheckMeterMetaMsgType(char *pMsg) { ...@@ -157,7 +157,7 @@ bool mgmtCheckMeterMetaMsgType(char *pMsg) {
SMeterInfoMsg *pInfo = (SMeterInfoMsg *)pMsg; SMeterInfoMsg *pInfo = (SMeterInfoMsg *)pMsg;
int16_t autoCreate = htons(pInfo->createFlag); int16_t autoCreate = htons(pInfo->createFlag);
STabObj *pMeterObj = mgmtGetMeter(pInfo->meterId); STabObj *pMeterObj = mgmtGetTable(pInfo->meterId);
// If table does not exists and autoCreate flag is set, we add the handler into another task queue, namely tranQueue // If table does not exists and autoCreate flag is set, we add the handler into another task queue, namely tranQueue
bool addIntoTranQueue = (pMeterObj == NULL && autoCreate == 1); bool addIntoTranQueue = (pMeterObj == NULL && autoCreate == 1);
...@@ -199,7 +199,7 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -199,7 +199,7 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
goto _exit_code; goto _exit_code;
} }
pMeterObj = mgmtGetMeter(pInfo->meterId); pMeterObj = mgmtGetTable(pInfo->meterId);
// on demand create table from super table if meter does not exists // on demand create table from super table if meter does not exists
if (pMeterObj == NULL && pInfo->createFlag == 1) { if (pMeterObj == NULL && pInfo->createFlag == 1) {
...@@ -224,8 +224,8 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -224,8 +224,8 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
int32_t code = mgmtCreateMeter(pDb, pCreateMsg); int32_t code = mgmtCreateMeter(pDb, pCreateMsg);
char stableName[TSDB_METER_ID_LEN] = {0}; char stableName[TSDB_TABLE_ID_LEN] = {0};
strncpy(stableName, pInfo->tags, TSDB_METER_ID_LEN); strncpy(stableName, pInfo->tags, TSDB_TABLE_ID_LEN);
mTrace("meter:%s is automatically created by %s from %s, code:%d", pCreateMsg->meterId, pConn->pUser->user, mTrace("meter:%s is automatically created by %s from %s, code:%d", pCreateMsg->meterId, pConn->pUser->user,
stableName, code); stableName, code);
...@@ -243,7 +243,7 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -243,7 +243,7 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
goto _exit_code; goto _exit_code;
} }
pMeterObj = mgmtGetMeter(pInfo->meterId); pMeterObj = mgmtGetTable(pInfo->meterId);
} }
if ((pStart = mgmtAllocMsg(pConn, size, &pMsg, &pRsp)) == NULL) { if ((pStart = mgmtAllocMsg(pConn, size, &pMsg, &pRsp)) == NULL) {
...@@ -274,15 +274,15 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -274,15 +274,15 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
pMeta->numOfTags = pMeterObj->numOfTags; pMeta->numOfTags = pMeterObj->numOfTags;
pMeta->numOfColumns = htons(pMeterObj->numOfColumns); pMeta->numOfColumns = htons(pMeterObj->numOfColumns);
pMeta->meterType = pMeterObj->meterType; pMeta->tableType = pMeterObj->tableType;
pMsg += sizeof(SMeterMeta); pMsg += sizeof(SMeterMeta);
pSchema = (SSchema *)pMsg; // schema locates at the end of SMeterMeta struct pSchema = (SSchema *)pMsg; // schema locates at the end of SMeterMeta struct
if (mgmtMeterCreateFromMetric(pMeterObj)) { if (mgmtTableCreateFromSuperTable(pMeterObj)) {
assert(pMeterObj->numOfTags == 0); assert(pMeterObj->numOfTags == 0);
STabObj *pMetric = mgmtGetMeter(pMeterObj->pTagData); STabObj *pMetric = mgmtGetTable(pMeterObj->pTagData);
uint32_t numOfTotalCols = (uint32_t)pMetric->numOfTags + pMetric->numOfColumns; uint32_t numOfTotalCols = (uint32_t)pMetric->numOfTags + pMetric->numOfColumns;
pMeta->numOfTags = pMetric->numOfTags; // update the numOfTags info pMeta->numOfTags = pMetric->numOfTags; // update the numOfTags info
...@@ -302,7 +302,7 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -302,7 +302,7 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
pMsg += numOfTotalCols * sizeof(SSchema); pMsg += numOfTotalCols * sizeof(SSchema);
} }
if (mgmtIsNormalMeter(pMeterObj)) { if (mgmtIsNormalTable(pMeterObj)) {
pVgroup = mgmtGetVgroup(pMeterObj->gid.vgId); pVgroup = mgmtGetVgroup(pMeterObj->gid.vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
pRsp->code = TSDB_CODE_INVALID_TABLE; pRsp->code = TSDB_CODE_INVALID_TABLE;
...@@ -361,7 +361,7 @@ int mgmtProcessMultiMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -361,7 +361,7 @@ int mgmtProcessMultiMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
} }
int32_t totalNum = 0; int32_t totalNum = 0;
char tblName[TSDB_METER_ID_LEN]; char tblName[TSDB_TABLE_ID_LEN];
char* nextStr; char* nextStr;
char* pCurMeter = pStart + sizeof(STaosRsp) + sizeof(SMultiMeterInfoMsg) + 1; // 1: ie type byte char* pCurMeter = pStart + sizeof(STaosRsp) + sizeof(SMultiMeterInfoMsg) + 1; // 1: ie type byte
...@@ -397,7 +397,7 @@ int mgmtProcessMultiMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -397,7 +397,7 @@ int mgmtProcessMultiMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
} }
// get meter schema, and fill into resp payload // get meter schema, and fill into resp payload
pMeterObj = mgmtGetMeter(tblName); pMeterObj = mgmtGetTable(tblName);
pDbObj = mgmtGetDbByMeterId(tblName); pDbObj = mgmtGetDbByMeterId(tblName);
if (pMeterObj == NULL || (pDbObj == NULL)) { if (pMeterObj == NULL || (pDbObj == NULL)) {
...@@ -414,15 +414,15 @@ int mgmtProcessMultiMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -414,15 +414,15 @@ int mgmtProcessMultiMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
pMeta->meta.precision = pDbObj->cfg.precision; pMeta->meta.precision = pDbObj->cfg.precision;
pMeta->meta.numOfTags = pMeterObj->numOfTags; pMeta->meta.numOfTags = pMeterObj->numOfTags;
pMeta->meta.numOfColumns = htons(pMeterObj->numOfColumns); pMeta->meta.numOfColumns = htons(pMeterObj->numOfColumns);
pMeta->meta.meterType = pMeterObj->meterType; pMeta->meta.tableType = pMeterObj->tableType;
pCurMeter += sizeof(SMultiMeterMeta); pCurMeter += sizeof(SMultiMeterMeta);
pSchema = (SSchema *)pCurMeter; // schema locates at the end of SMeterMeta struct pSchema = (SSchema *)pCurMeter; // schema locates at the end of SMeterMeta struct
if (mgmtMeterCreateFromMetric(pMeterObj)) { if (mgmtTableCreateFromSuperTable(pMeterObj)) {
assert(pMeterObj->numOfTags == 0); assert(pMeterObj->numOfTags == 0);
STabObj *pMetric = mgmtGetMeter(pMeterObj->pTagData); STabObj *pMetric = mgmtGetTable(pMeterObj->pTagData);
uint32_t numOfTotalCols = (uint32_t)pMetric->numOfTags + pMetric->numOfColumns; uint32_t numOfTotalCols = (uint32_t)pMetric->numOfTags + pMetric->numOfColumns;
pMeta->meta.numOfTags = pMetric->numOfTags; // update the numOfTags info pMeta->meta.numOfTags = pMetric->numOfTags; // update the numOfTags info
...@@ -442,7 +442,7 @@ int mgmtProcessMultiMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -442,7 +442,7 @@ int mgmtProcessMultiMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
pCurMeter += numOfTotalCols * sizeof(SSchema); pCurMeter += numOfTotalCols * sizeof(SSchema);
} }
if (mgmtIsNormalMeter(pMeterObj)) { if (mgmtIsNormalTable(pMeterObj)) {
pVgroup = mgmtGetVgroup(pMeterObj->gid.vgId); pVgroup = mgmtGetVgroup(pMeterObj->gid.vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
pRsp->code = TSDB_CODE_INVALID_TABLE; pRsp->code = TSDB_CODE_INVALID_TABLE;
...@@ -494,22 +494,22 @@ _exit_code: ...@@ -494,22 +494,22 @@ _exit_code:
} }
int mgmtProcessMetricMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { int mgmtProcessMetricMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
SMetricMetaMsg *pMetricMetaMsg = (SMetricMetaMsg *)pMsg; SSuperTableMetaMsg *pSuperTableMetaMsg = (SSuperTableMetaMsg *)pMsg;
STabObj * pMetric; STabObj * pMetric;
STaosRsp * pRsp; STaosRsp * pRsp;
char * pStart; char * pStart;
pMetricMetaMsg->numOfMeters = htonl(pMetricMetaMsg->numOfMeters); pSuperTableMetaMsg->numOfMeters = htonl(pSuperTableMetaMsg->numOfMeters);
pMetricMetaMsg->join = htonl(pMetricMetaMsg->join); pSuperTableMetaMsg->join = htonl(pSuperTableMetaMsg->join);
pMetricMetaMsg->joinCondLen = htonl(pMetricMetaMsg->joinCondLen); pSuperTableMetaMsg->joinCondLen = htonl(pSuperTableMetaMsg->joinCondLen);
for (int32_t i = 0; i < pMetricMetaMsg->numOfMeters; ++i) { for (int32_t i = 0; i < pSuperTableMetaMsg->numOfMeters; ++i) {
pMetricMetaMsg->metaElem[i] = htonl(pMetricMetaMsg->metaElem[i]); pSuperTableMetaMsg->metaElem[i] = htonl(pSuperTableMetaMsg->metaElem[i]);
} }
SMetricMetaElemMsg *pElem = (SMetricMetaElemMsg *)(((char *)pMetricMetaMsg) + pMetricMetaMsg->metaElem[0]); SMetricMetaElemMsg *pElem = (SMetricMetaElemMsg *)(((char *)pSuperTableMetaMsg) + pSuperTableMetaMsg->metaElem[0]);
pMetric = mgmtGetMeter(pElem->meterId); pMetric = mgmtGetTable(pElem->meterId);
SDbObj *pDb = NULL; SDbObj *pDb = NULL;
if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name); if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name);
...@@ -531,7 +531,7 @@ int mgmtProcessMetricMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -531,7 +531,7 @@ int mgmtProcessMetricMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
msgLen = pMsg - pStart; msgLen = pMsg - pStart;
} else { } else {
msgLen = mgmtRetrieveMetricMeta(pConn, &pStart, pMetricMetaMsg); msgLen = mgmtRetrieveMetricMeta(pConn, &pStart, pSuperTableMetaMsg);
if (msgLen <= 0) { if (msgLen <= 0) {
taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_METRIC_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY); taosSendSimpleRsp(pConn->thandle, TSDB_MSG_TYPE_METRIC_META_RSP, TSDB_CODE_SERV_OUT_OF_MEMORY);
return 0; return 0;
...@@ -880,7 +880,7 @@ int mgmtProcessUseDbMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -880,7 +880,7 @@ int mgmtProcessUseDbMsg(char *pMsg, int msgLen, SConnObj *pConn) {
} }
int (*mgmtGetMetaFp[])(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) = { int (*mgmtGetMetaFp[])(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) = {
mgmtGetAcctMeta, mgmtGetUserMeta, mgmtGetDbMeta, mgmtGetMeterMeta, mgmtGetDnodeMeta, mgmtGetAcctMeta, mgmtGetUserMeta, mgmtGetDbMeta, mgmtGetTableMeta, mgmtGetDnodeMeta,
mgmtGetMnodeMeta, mgmtGetVgroupMeta, mgmtGetMetricMeta, mgmtGetModuleMeta, mgmtGetQueryMeta, mgmtGetMnodeMeta, mgmtGetVgroupMeta, mgmtGetMetricMeta, mgmtGetModuleMeta, mgmtGetQueryMeta,
mgmtGetStreamMeta, mgmtGetConfigMeta, mgmtGetConnsMeta, mgmtGetScoresMeta, grantGetGrantsMeta, mgmtGetStreamMeta, mgmtGetConfigMeta, mgmtGetConnsMeta, mgmtGetScoresMeta, grantGetGrantsMeta,
mgmtGetVnodeMeta, mgmtGetVnodeMeta,
...@@ -1076,11 +1076,11 @@ int mgmtProcessCreateTableMsg(char *pMsg, int msgLen, SConnObj *pConn) { ...@@ -1076,11 +1076,11 @@ int mgmtProcessCreateTableMsg(char *pMsg, int msgLen, SConnObj *pConn) {
} else if (code != TSDB_CODE_SUCCESS) { } else if (code != TSDB_CODE_SUCCESS) {
if (code == TSDB_CODE_TABLE_ALREADY_EXIST) { // table already created when the second attempt to create table if (code == TSDB_CODE_TABLE_ALREADY_EXIST) { // table already created when the second attempt to create table
STabObj* pMeter = mgmtGetMeter(pCreate->meterId); STabObj* pTable = mgmtGetTable(pCreate->meterId);
assert(pMeter != NULL); assert(pTable != NULL);
mWarn("table:%s, table already created, failed to create table, ts:%" PRId64 ", code:%d", pCreate->meterId, mWarn("table:%s, table already created, failed to create table, ts:%" PRId64 ", code:%d", pCreate->meterId,
pMeter->createdTime, code); pTable->createdTime, code);
} else { // other errors } else { // other errors
mError("table:%s, failed to create table, code:%d", pCreate->meterId, code); mError("table:%s, failed to create table, code:%d", pCreate->meterId, code);
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include <arpa/inet.h> #include <arpa/inet.h>
#include "mgmt.h" #include "mnode.h"
int mgmtCheckRedirectMsg(SConnObj *pConn, int msgType) { return 0; } int mgmtCheckRedirectMsg(SConnObj *pConn, int msgType) { return 0; }
......
...@@ -16,13 +16,19 @@ ...@@ -16,13 +16,19 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "mgmt.h" #include "mnode.h"
#include "mgmtUtil.h" #include "mgmtUtil.h"
#include "textbuffer.h" #include "textbuffer.h"
#include "tschemautil.h" #include "tschemautil.h"
#include "tsqlfunction.h" #include "tsqlfunction.h"
#include "vnodeTagMgmt.h" #include "vnodeTagMgmt.h"
typedef struct SSyntaxTreeFilterSupporter {
SSchema* pTagSchema;
int32_t numOfTags;
int32_t optr;
} SSyntaxTreeFilterSupporter;
typedef struct SJoinSupporter { typedef struct SJoinSupporter {
void** val; void** val;
void** pTabObjs; void** pTabObjs;
...@@ -41,6 +47,7 @@ typedef struct SMeterNameFilterSupporter { ...@@ -41,6 +47,7 @@ typedef struct SMeterNameFilterSupporter {
} SMeterNameFilterSupporter; } SMeterNameFilterSupporter;
static void tansformQueryResult(tQueryResultset* pRes); static void tansformQueryResult(tQueryResultset* pRes);
static bool tSkipListNodeFilterCallback(const void *pNode, void *param);
static int32_t tabObjVGIDComparator(const void* pLeft, const void* pRight) { static int32_t tabObjVGIDComparator(const void* pLeft, const void* pRight) {
STabObj* p1 = *(STabObj**)pLeft; STabObj* p1 = *(STabObj**)pLeft;
...@@ -82,10 +89,10 @@ static int32_t tabObjResultComparator(const void* p1, const void* p2, void* para ...@@ -82,10 +89,10 @@ static int32_t tabObjResultComparator(const void* p1, const void* p2, void* para
f1 = pNode1->meterId; f1 = pNode1->meterId;
f2 = pNode2->meterId; f2 = pNode2->meterId;
schema.type = TSDB_DATA_TYPE_BINARY; schema.type = TSDB_DATA_TYPE_BINARY;
schema.bytes = TSDB_METER_ID_LEN; schema.bytes = TSDB_TABLE_ID_LEN;
} else { } else {
f1 = mgmtMeterGetTag(pNode1, colIdx, NULL); f1 = mgmtTableGetTag(pNode1, colIdx, NULL);
f2 = mgmtMeterGetTag(pNode2, colIdx, &schema); f2 = mgmtTableGetTag(pNode2, colIdx, &schema);
assert(schema.type == pOrderDesc->pTagSchema->pSchema[colIdx].type); assert(schema.type == pOrderDesc->pTagSchema->pSchema[colIdx].type);
} }
...@@ -104,15 +111,15 @@ static int32_t tabObjResultComparator(const void* p1, const void* p2, void* para ...@@ -104,15 +111,15 @@ static int32_t tabObjResultComparator(const void* p1, const void* p2, void* para
* update the tag order index according to the tags column index. The tags column index needs to be checked one-by-one, * update the tag order index according to the tags column index. The tags column index needs to be checked one-by-one,
* since the normal columns may be passed to server for handling the group by on status column. * since the normal columns may be passed to server for handling the group by on status column.
* *
* @param pMetricMetaMsg * @param pSuperTableMetaMsg
* @param tableIndex * @param tableIndex
* @param pOrderIndexInfo * @param pOrderIndexInfo
* @param numOfTags * @param numOfTags
*/ */
static void mgmtUpdateOrderTagColIndex(SMetricMetaMsg* pMetricMetaMsg, int32_t tableIndex, tOrderIdx* pOrderIndexInfo, static void mgmtUpdateOrderTagColIndex(SSuperTableMetaMsg* pSuperTableMetaMsg, int32_t tableIndex, tOrderIdx* pOrderIndexInfo,
int32_t numOfTags) { int32_t numOfTags) {
SMetricMetaElemMsg* pElem = (SMetricMetaElemMsg*)((char*)pMetricMetaMsg + pMetricMetaMsg->metaElem[tableIndex]); SMetricMetaElemMsg* pElem = (SMetricMetaElemMsg*)((char*)pSuperTableMetaMsg + pSuperTableMetaMsg->metaElem[tableIndex]);
SColIndexEx* groupColumnList = (SColIndexEx*)((char*)pMetricMetaMsg + pElem->groupbyTagColumnList); SColIndexEx* groupColumnList = (SColIndexEx*)((char*)pSuperTableMetaMsg + pElem->groupbyTagColumnList);
int32_t numOfGroupbyTags = 0; int32_t numOfGroupbyTags = 0;
for (int32_t i = 0; i < pElem->numOfGroupCols; ++i) { for (int32_t i = 0; i < pElem->numOfGroupCols; ++i) {
...@@ -127,14 +134,14 @@ static void mgmtUpdateOrderTagColIndex(SMetricMetaMsg* pMetricMetaMsg, int32_t t ...@@ -127,14 +134,14 @@ static void mgmtUpdateOrderTagColIndex(SMetricMetaMsg* pMetricMetaMsg, int32_t t
} }
// todo merge sort function with losertree used // todo merge sort function with losertree used
void mgmtReorganizeMetersInMetricMeta(SMetricMetaMsg* pMetricMetaMsg, int32_t tableIndex, tQueryResultset* pRes) { void mgmtReorganizeMetersInMetricMeta(SSuperTableMetaMsg* pSuperTableMetaMsg, int32_t tableIndex, tQueryResultset* pRes) {
if (pRes->num <= 0) { // no result, no need to pagination if (pRes->num <= 0) { // no result, no need to pagination
return; return;
} }
SMetricMetaElemMsg* pElem = (SMetricMetaElemMsg*)((char*)pMetricMetaMsg + pMetricMetaMsg->metaElem[tableIndex]); SMetricMetaElemMsg* pElem = (SMetricMetaElemMsg*)((char*)pSuperTableMetaMsg + pSuperTableMetaMsg->metaElem[tableIndex]);
STabObj* pMetric = mgmtGetMeter(pElem->meterId); STabObj* pMetric = mgmtGetTable(pElem->meterId);
SSchema* pTagSchema = (SSchema*)(pMetric->schema + pMetric->numOfColumns * sizeof(SSchema)); SSchema* pTagSchema = (SSchema*)(pMetric->schema + pMetric->numOfColumns * sizeof(SSchema));
/* /*
...@@ -149,7 +156,7 @@ void mgmtReorganizeMetersInMetricMeta(SMetricMetaMsg* pMetricMetaMsg, int32_t ta ...@@ -149,7 +156,7 @@ void mgmtReorganizeMetersInMetricMeta(SMetricMetaMsg* pMetricMetaMsg, int32_t ta
int32_t* startPos = NULL; int32_t* startPos = NULL;
int32_t numOfSubset = 1; int32_t numOfSubset = 1;
mgmtUpdateOrderTagColIndex(pMetricMetaMsg, tableIndex, &descriptor->orderIdx, pMetric->numOfTags); mgmtUpdateOrderTagColIndex(pSuperTableMetaMsg, tableIndex, &descriptor->orderIdx, pMetric->numOfTags);
if (descriptor->orderIdx.numOfOrderedCols > 0) { if (descriptor->orderIdx.numOfOrderedCols > 0) {
tQSortEx(pRes->pRes, POINTER_BYTES, 0, pRes->num - 1, descriptor, tabObjResultComparator); tQSortEx(pRes->pRes, POINTER_BYTES, 0, pRes->num - 1, descriptor, tabObjResultComparator);
startPos = calculateSubGroup(pRes->pRes, pRes->num, &numOfSubset, descriptor, tabObjResultComparator); startPos = calculateSubGroup(pRes->pRes, pRes->num, &numOfSubset, descriptor, tabObjResultComparator);
...@@ -181,7 +188,7 @@ static void mgmtRetrieveByMeterName(tQueryResultset* pRes, char* str, STabObj* p ...@@ -181,7 +188,7 @@ static void mgmtRetrieveByMeterName(tQueryResultset* pRes, char* str, STabObj* p
pRes->num = 0; pRes->num = 0;
for (pToken = strsep(&str, sep); pToken != NULL; pToken = strsep(&str, sep)) { for (pToken = strsep(&str, sep); pToken != NULL; pToken = strsep(&str, sep)) {
STabObj* pMeterObj = mgmtGetMeter(pToken); STabObj* pMeterObj = mgmtGetTable(pToken);
if (pMeterObj == NULL) { if (pMeterObj == NULL) {
mWarn("metric:%s error in metric query expression, invalid meter id:%s", pMetric->meterId, pToken); mWarn("metric:%s error in metric query expression, invalid meter id:%s", pMetric->meterId, pToken);
continue; continue;
...@@ -193,7 +200,7 @@ static void mgmtRetrieveByMeterName(tQueryResultset* pRes, char* str, STabObj* p ...@@ -193,7 +200,7 @@ static void mgmtRetrieveByMeterName(tQueryResultset* pRes, char* str, STabObj* p
} }
/* not a table created from metric, ignore */ /* not a table created from metric, ignore */
if (pMeterObj->meterType != TSDB_METER_MTABLE) { if (pMeterObj->tableType != TSDB_TABLE_TYPE_CREATE_FROM_STABLE) {
continue; continue;
} }
...@@ -201,8 +208,8 @@ static void mgmtRetrieveByMeterName(tQueryResultset* pRes, char* str, STabObj* p ...@@ -201,8 +208,8 @@ static void mgmtRetrieveByMeterName(tQueryResultset* pRes, char* str, STabObj* p
* queried meter not belongs to this metric, ignore, metric does not have * queried meter not belongs to this metric, ignore, metric does not have
* uid, so compare according to meterid * uid, so compare according to meterid
*/ */
STabObj* parentMetric = mgmtGetMeter(pMeterObj->pTagData); STabObj* parentMetric = mgmtGetTable(pMeterObj->pTagData);
if (strncasecmp(parentMetric->meterId, pMetric->meterId, TSDB_METER_ID_LEN) != 0 || if (strncasecmp(parentMetric->meterId, pMetric->meterId, TSDB_TABLE_ID_LEN) != 0 ||
(parentMetric->uid != pMetric->uid)) { (parentMetric->uid != pMetric->uid)) {
continue; continue;
} }
...@@ -214,13 +221,13 @@ static void mgmtRetrieveByMeterName(tQueryResultset* pRes, char* str, STabObj* p ...@@ -214,13 +221,13 @@ static void mgmtRetrieveByMeterName(tQueryResultset* pRes, char* str, STabObj* p
static bool mgmtTablenameFilterCallback(tSkipListNode* pNode, void* param) { static bool mgmtTablenameFilterCallback(tSkipListNode* pNode, void* param) {
SMeterNameFilterSupporter* pSupporter = (SMeterNameFilterSupporter*)param; SMeterNameFilterSupporter* pSupporter = (SMeterNameFilterSupporter*)param;
char name[TSDB_METER_ID_LEN] = {0}; char name[TSDB_TABLE_ID_LEN] = {0};
// pattern compare for meter name // pattern compare for meter name
STabObj* pMeterObj = (STabObj*)pNode->pData; STabObj* pMeterObj = (STabObj*)pNode->pData;
extractTableName(pMeterObj->meterId, name); extractTableName(pMeterObj->meterId, name);
return patternMatch(pSupporter->pattern, name, TSDB_METER_ID_LEN, &pSupporter->info) == TSDB_PATTERN_MATCH; return patternMatch(pSupporter->pattern, name, TSDB_TABLE_ID_LEN, &pSupporter->info) == TSDB_PATTERN_MATCH;
} }
static void mgmtRetrieveFromLikeOptr(tQueryResultset* pRes, const char* str, STabObj* pMetric) { static void mgmtRetrieveFromLikeOptr(tQueryResultset* pRes, const char* str, STabObj* pMetric) {
...@@ -256,7 +263,7 @@ UNUSED_FUNC static bool mgmtJoinFilterCallback(tSkipListNode* pNode, void* param ...@@ -256,7 +263,7 @@ UNUSED_FUNC static bool mgmtJoinFilterCallback(tSkipListNode* pNode, void* param
SJoinSupporter* pSupporter = (SJoinSupporter*)param; SJoinSupporter* pSupporter = (SJoinSupporter*)param;
SSchema s = {0}; SSchema s = {0};
char* v = mgmtMeterGetTag((STabObj*)pNode->pData, pSupporter->colIndex, &s); char* v = mgmtTableGetTag((STabObj*)pNode->pData, pSupporter->colIndex, &s);
for (int32_t i = 0; i < pSupporter->size; ++i) { for (int32_t i = 0; i < pSupporter->size; ++i) {
int32_t ret = doCompare(v, pSupporter->val[i], pSupporter->type, s.bytes); int32_t ret = doCompare(v, pSupporter->val[i], pSupporter->type, s.bytes);
...@@ -282,13 +289,13 @@ UNUSED_FUNC static bool mgmtJoinFilterCallback(tSkipListNode* pNode, void* param ...@@ -282,13 +289,13 @@ UNUSED_FUNC static bool mgmtJoinFilterCallback(tSkipListNode* pNode, void* param
return false; return false;
} }
static void orderResult(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes, int16_t colIndex, int32_t tableIndex) { static void orderResult(SSuperTableMetaMsg* pSuperTableMetaMsg, tQueryResultset* pRes, int16_t colIndex, int32_t tableIndex) {
SMetricMetaElemMsg* pElem = (SMetricMetaElemMsg*)((char*)pMetricMetaMsg + pMetricMetaMsg->metaElem[tableIndex]); SMetricMetaElemMsg* pElem = (SMetricMetaElemMsg*)((char*)pSuperTableMetaMsg + pSuperTableMetaMsg->metaElem[tableIndex]);
tOrderDescriptor* descriptor = tOrderDescriptor* descriptor =
(tOrderDescriptor*)calloc(1, sizeof(tOrderDescriptor) + sizeof(int32_t) * 1); // only one column for join (tOrderDescriptor*)calloc(1, sizeof(tOrderDescriptor) + sizeof(int32_t) * 1); // only one column for join
STabObj* pMetric = mgmtGetMeter(pElem->meterId); STabObj* pMetric = mgmtGetTable(pElem->meterId);
SSchema* pTagSchema = (SSchema*)(pMetric->schema + pMetric->numOfColumns * sizeof(SSchema)); SSchema* pTagSchema = (SSchema*)(pMetric->schema + pMetric->numOfColumns * sizeof(SSchema));
descriptor->pTagSchema = tCreateTagSchema(pTagSchema, pMetric->numOfTags); descriptor->pTagSchema = tCreateTagSchema(pTagSchema, pMetric->numOfTags);
...@@ -311,8 +318,8 @@ static int32_t mgmtCheckForDuplicateTagValue(tQueryResultset* pRes, int32_t inde ...@@ -311,8 +318,8 @@ static int32_t mgmtCheckForDuplicateTagValue(tQueryResultset* pRes, int32_t inde
STabObj* pObj1 = pRes[index].pRes[k - 1]; STabObj* pObj1 = pRes[index].pRes[k - 1];
STabObj* pObj2 = pRes[index].pRes[k]; STabObj* pObj2 = pRes[index].pRes[k];
char* val1 = mgmtMeterGetTag(pObj1, tagCol, &s); char* val1 = mgmtTableGetTag(pObj1, tagCol, &s);
char* val2 = mgmtMeterGetTag(pObj2, tagCol, NULL); char* val2 = mgmtTableGetTag(pObj2, tagCol, NULL);
if (doCompare(val1, val2, s.type, s.bytes) == 0) { if (doCompare(val1, val2, s.type, s.bytes) == 0) {
return TSDB_CODE_DUPLICATE_TAGS; return TSDB_CODE_DUPLICATE_TAGS;
...@@ -322,13 +329,13 @@ static int32_t mgmtCheckForDuplicateTagValue(tQueryResultset* pRes, int32_t inde ...@@ -322,13 +329,13 @@ static int32_t mgmtCheckForDuplicateTagValue(tQueryResultset* pRes, int32_t inde
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes) { int32_t mgmtDoJoin(SSuperTableMetaMsg* pSuperTableMetaMsg, tQueryResultset* pRes) {
if (pMetricMetaMsg->numOfMeters == 1) { if (pSuperTableMetaMsg->numOfMeters == 1) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
bool allEmpty = false; bool allEmpty = false;
for (int32_t i = 0; i < pMetricMetaMsg->numOfMeters; ++i) { for (int32_t i = 0; i < pSuperTableMetaMsg->numOfMeters; ++i) {
if (pRes[i].num == 0) { // all results are empty if one of them is empty if (pRes[i].num == 0) { // all results are empty if one of them is empty
allEmpty = true; allEmpty = true;
break; break;
...@@ -336,7 +343,7 @@ int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes) { ...@@ -336,7 +343,7 @@ int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes) {
} }
if (allEmpty) { if (allEmpty) {
for (int32_t i = 0; i < pMetricMetaMsg->numOfMeters; ++i) { for (int32_t i = 0; i < pSuperTableMetaMsg->numOfMeters; ++i) {
pRes[i].num = 0; pRes[i].num = 0;
tfree(pRes[i].pRes); tfree(pRes[i].pRes);
} }
...@@ -344,26 +351,26 @@ int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes) { ...@@ -344,26 +351,26 @@ int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
char* cond = (char*)pMetricMetaMsg + pMetricMetaMsg->join; char* cond = (char*)pSuperTableMetaMsg + pSuperTableMetaMsg->join;
char left[TSDB_METER_ID_LEN + 1] = {0}; char left[TSDB_TABLE_ID_LEN + 1] = {0};
strcpy(left, cond); strcpy(left, cond);
int16_t leftTagColIndex = *(int16_t*)(cond + TSDB_METER_ID_LEN); int16_t leftTagColIndex = *(int16_t*)(cond + TSDB_TABLE_ID_LEN);
char right[TSDB_METER_ID_LEN + 1] = {0}; char right[TSDB_TABLE_ID_LEN + 1] = {0};
strcpy(right, cond + TSDB_METER_ID_LEN + sizeof(int16_t)); strcpy(right, cond + TSDB_TABLE_ID_LEN + sizeof(int16_t));
int16_t rightTagColIndex = *(int16_t*)(cond + TSDB_METER_ID_LEN * 2 + sizeof(int16_t)); int16_t rightTagColIndex = *(int16_t*)(cond + TSDB_TABLE_ID_LEN * 2 + sizeof(int16_t));
STabObj* pLeftMetric = mgmtGetMeter(left); STabObj* pLeftMetric = mgmtGetTable(left);
STabObj* pRightMetric = mgmtGetMeter(right); STabObj* pRightMetric = mgmtGetTable(right);
// decide the pRes belongs to // decide the pRes belongs to
int32_t leftIndex = 0; int32_t leftIndex = 0;
int32_t rightIndex = 0; int32_t rightIndex = 0;
for (int32_t i = 0; i < pMetricMetaMsg->numOfMeters; ++i) { for (int32_t i = 0; i < pSuperTableMetaMsg->numOfMeters; ++i) {
STabObj* pObj = (STabObj*)pRes[i].pRes[0]; STabObj* pObj = (STabObj*)pRes[i].pRes[0];
STabObj* pMetric1 = mgmtGetMeter(pObj->pTagData); STabObj* pMetric1 = mgmtGetTable(pObj->pTagData);
if (pMetric1 == pLeftMetric) { if (pMetric1 == pLeftMetric) {
leftIndex = i; leftIndex = i;
} else if (pMetric1 == pRightMetric) { } else if (pMetric1 == pRightMetric) {
...@@ -371,8 +378,8 @@ int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes) { ...@@ -371,8 +378,8 @@ int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes) {
} }
} }
orderResult(pMetricMetaMsg, &pRes[leftIndex], leftTagColIndex, leftIndex); orderResult(pSuperTableMetaMsg, &pRes[leftIndex], leftTagColIndex, leftIndex);
orderResult(pMetricMetaMsg, &pRes[rightIndex], rightTagColIndex, rightIndex); orderResult(pSuperTableMetaMsg, &pRes[rightIndex], rightTagColIndex, rightIndex);
int32_t i = 0; int32_t i = 0;
int32_t j = 0; int32_t j = 0;
...@@ -391,8 +398,8 @@ int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes) { ...@@ -391,8 +398,8 @@ int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes) {
STabObj* pLeftObj = pRes[leftIndex].pRes[i]; STabObj* pLeftObj = pRes[leftIndex].pRes[i];
STabObj* pRightObj = pRes[rightIndex].pRes[j]; STabObj* pRightObj = pRes[rightIndex].pRes[j];
char* v1 = mgmtMeterGetTag(pLeftObj, leftTagColIndex, &s); char* v1 = mgmtTableGetTag(pLeftObj, leftTagColIndex, &s);
char* v2 = mgmtMeterGetTag(pRightObj, rightTagColIndex, NULL); char* v2 = mgmtTableGetTag(pRightObj, rightTagColIndex, NULL);
int32_t ret = doCompare(v1, v2, s.type, s.bytes); int32_t ret = doCompare(v1, v2, s.type, s.bytes);
if (ret == 0) { // qualified if (ret == 0) { // qualified
...@@ -727,9 +734,9 @@ static int32_t mgmtFilterMeterByIndex(STabObj* pMetric, tQueryResultset* pRes, c ...@@ -727,9 +734,9 @@ static int32_t mgmtFilterMeterByIndex(STabObj* pMetric, tQueryResultset* pRes, c
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int mgmtRetrieveMetersFromMetric(SMetricMetaMsg* pMsg, int32_t tableIndex, tQueryResultset* pRes) { int32_t mgmtRetrieveMetersFromSuperTable(SSuperTableMetaMsg* pMsg, int32_t tableIndex, tQueryResultset* pRes) {
SMetricMetaElemMsg* pElem = (SMetricMetaElemMsg*)((char*)pMsg + pMsg->metaElem[tableIndex]); SMetricMetaElemMsg* pElem = (SMetricMetaElemMsg*)((char*)pMsg + pMsg->metaElem[tableIndex]);
STabObj* pMetric = mgmtGetMeter(pElem->meterId); STabObj* pMetric = mgmtGetTable(pElem->meterId);
char* pCond = NULL; char* pCond = NULL;
char* tmpTableNameCond = NULL; char* tmpTableNameCond = NULL;
...@@ -806,11 +813,11 @@ int mgmtRetrieveMetersFromMetric(SMetricMetaMsg* pMsg, int32_t tableIndex, tQuer ...@@ -806,11 +813,11 @@ int mgmtRetrieveMetersFromMetric(SMetricMetaMsg* pMsg, int32_t tableIndex, tQuer
} }
// todo refactor!!!!! // todo refactor!!!!!
static char* getTagValueFromMeter(STabObj* pMeter, int32_t offset, int32_t len, char* param) { static char* getTagValueFromMeter(STabObj* pTable, int32_t offset, int32_t len, char* param) {
if (offset == TSDB_TBNAME_COLUMN_INDEX) { if (offset == TSDB_TBNAME_COLUMN_INDEX) {
extractTableName(pMeter->meterId, param); extractTableName(pTable->meterId, param);
} else { } else {
char* tags = pMeter->pTagData + offset + TSDB_METER_ID_LEN; // tag start position char* tags = pTable->pTagData + offset + TSDB_TABLE_ID_LEN; // tag start position
memcpy(param, tags, len); // make sure the value is null-terminated string memcpy(param, tags, len); // make sure the value is null-terminated string
} }
...@@ -820,11 +827,11 @@ static char* getTagValueFromMeter(STabObj* pMeter, int32_t offset, int32_t len, ...@@ -820,11 +827,11 @@ static char* getTagValueFromMeter(STabObj* pMeter, int32_t offset, int32_t len,
bool tSkipListNodeFilterCallback(const void* pNode, void* param) { bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
tQueryInfo* pInfo = (tQueryInfo*)param; tQueryInfo* pInfo = (tQueryInfo*)param;
STabObj* pMeter = (STabObj*)(((tSkipListNode*)pNode)->pData); STabObj* pTable = (STabObj*)(((tSkipListNode*)pNode)->pData);
char buf[TSDB_MAX_TAGS_LEN] = {0}; char buf[TSDB_MAX_TAGS_LEN] = {0};
char* val = getTagValueFromMeter(pMeter, pInfo->offset, pInfo->sch.bytes, buf); char* val = getTagValueFromMeter(pTable, pInfo->offset, pInfo->sch.bytes, buf);
int8_t type = pInfo->sch.type; int8_t type = pInfo->sch.type;
int32_t ret = 0; int32_t ret = 0;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "os.h" #include "os.h"
#include "dnodeSystem.h" #include "dnodeSystem.h"
#include "mgmt.h" #include "mnode.h"
#include "tsdb.h" #include "tsdb.h"
#include "mgmtSystem.h" #include "mgmtSystem.h"
#include "dnodeModule.h" #include "dnodeModule.h"
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include "dnodeSystem.h" #include "dnodeSystem.h"
#include "mgmt.h" #include "mnode.h"
extern void *mgmtTmr; extern void *mgmtTmr;
extern void *mgmtStatusTimer; extern void *mgmtStatusTimer;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "mgmt.h" #include "mnode.h"
#include "mgmtAcct.h" #include "mgmtAcct.h"
#include "mgmtGrant.h" #include "mgmtGrant.h"
#include "mgmtUtil.h" #include "mgmtUtil.h"
...@@ -33,11 +33,11 @@ ...@@ -33,11 +33,11 @@
extern int64_t sdbVersion; extern int64_t sdbVersion;
#define mgmtDestroyMeter(pMeter) \ #define mgmtDestroyMeter(pTable) \
do { \ do { \
tfree(pMeter->schema); \ tfree(pTable->schema); \
pMeter->pSkipList = tSkipListDestroy((pMeter)->pSkipList); \ pTable->pSkipList = tSkipListDestroy((pTable)->pSkipList); \
tfree(pMeter); \ tfree(pTable); \
} while (0) } while (0)
enum _Meter_Update_Action { enum _Meter_Update_Action {
...@@ -55,14 +55,14 @@ typedef struct { ...@@ -55,14 +55,14 @@ typedef struct {
} SchemaUnit; } SchemaUnit;
typedef struct { typedef struct {
char meterId[TSDB_METER_ID_LEN + 1]; char meterId[TSDB_TABLE_ID_LEN + 1];
char type; char type;
uint32_t cols; uint32_t cols;
char data[]; char data[];
} SMeterBatchUpdateMsg; } SMeterBatchUpdateMsg;
typedef struct { typedef struct {
char meterId[TSDB_METER_ID_LEN + 1]; char meterId[TSDB_TABLE_ID_LEN + 1];
char action; char action;
int32_t dataSize; int32_t dataSize;
char data[]; char data[];
...@@ -83,14 +83,14 @@ void *mgmtMeterActionAfterBatchUpdate(void *row, char *str, int size, int *ssize ...@@ -83,14 +83,14 @@ void *mgmtMeterActionAfterBatchUpdate(void *row, char *str, int size, int *ssize
void *mgmtMeterActionReset(void *row, char *str, int size, int *ssize); void *mgmtMeterActionReset(void *row, char *str, int size, int *ssize);
void *mgmtMeterActionDestroy(void *row, char *str, int size, int *ssize); void *mgmtMeterActionDestroy(void *row, char *str, int size, int *ssize);
int32_t mgmtMeterAddTags(STabObj *pMetric, SSchema schema[], int ntags); int32_t mgmtMeterAddTags(STabObj *pMetric, SSchema schema[], int ntags);
static void removeMeterFromMetricIndex(STabObj *pMetric, STabObj *pMeter); static void removeMeterFromMetricIndex(STabObj *pMetric, STabObj *pTable);
static void addMeterIntoMetricIndex(STabObj *pMetric, STabObj *pMeter); static void addMeterIntoMetricIndex(STabObj *pMetric, STabObj *pTable);
int32_t mgmtMeterDropTagByName(STabObj *pMetric, char *name); int32_t mgmtMeterDropTagByName(STabObj *pMetric, char *name);
int32_t mgmtMeterModifyTagNameByName(STabObj *pMetric, const char *oname, const char *nname); int32_t mgmtMeterModifyTagNameByName(STabObj *pMetric, const char *oname, const char *nname);
int32_t mgmtMeterModifyTagValueByName(STabObj *pMeter, char *tagName, char *nContent); int32_t mgmtMeterModifyTagValueByName(STabObj *pTable, char *tagName, char *nContent);
int32_t mgmtMeterAddColumn(STabObj *pMeter, SSchema schema[], int ncols); int32_t mgmtMeterAddColumn(STabObj *pTable, SSchema schema[], int ncols);
int32_t mgmtMeterDropColumnByName(STabObj *pMeter, const char *name); int32_t mgmtMeterDropColumnByName(STabObj *pTable, const char *name);
static int dropMeterImp(SDbObj *pDb, STabObj * pMeter, SAcctObj *pAcct); static int dropMeterImp(SDbObj *pDb, STabObj * pTable, SAcctObj *pAcct);
static void dropAllMetersOfMetric(SDbObj *pDb, STabObj * pMetric, SAcctObj *pAcct); static void dropAllMetersOfMetric(SDbObj *pDb, STabObj * pMetric, SAcctObj *pAcct);
int mgmtCheckTableLimit(SAcctObj *pAcct, SCreateTableMsg *pCreate); int mgmtCheckTableLimit(SAcctObj *pAcct, SCreateTableMsg *pCreate);
...@@ -109,7 +109,7 @@ void mgmtMeterActionInit() { ...@@ -109,7 +109,7 @@ void mgmtMeterActionInit() {
} }
static int32_t mgmtGetReqTagsLength(STabObj *pMetric, int16_t *cols, int32_t numOfCols) { static int32_t mgmtGetReqTagsLength(STabObj *pMetric, int16_t *cols, int32_t numOfCols) {
assert(mgmtIsMetric(pMetric) && numOfCols >= 0 && numOfCols <= TSDB_MAX_TAGS + 1); assert(mgmtIsSuperTable(pMetric) && numOfCols >= 0 && numOfCols <= TSDB_MAX_TAGS + 1);
int32_t len = 0; int32_t len = 0;
for (int32_t i = 0; i < numOfCols; ++i) { for (int32_t i = 0; i < numOfCols; ++i) {
...@@ -136,38 +136,38 @@ static void mgmtVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_ ...@@ -136,38 +136,38 @@ static void mgmtVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_
} }
void *mgmtMeterActionReset(void *row, char *str, int size, int *ssize) { void *mgmtMeterActionReset(void *row, char *str, int size, int *ssize) {
STabObj *pMeter = (STabObj *)row; STabObj *pTable = (STabObj *)row;
int tsize = pMeter->updateEnd - (char *)pMeter; int tsize = pTable->updateEnd - (char *)pTable;
memcpy(pMeter, str, tsize); memcpy(pTable, str, tsize);
pMeter->schema = (char *)realloc(pMeter->schema, pMeter->schemaSize); pTable->schema = (char *)realloc(pTable->schema, pTable->schemaSize);
memcpy(pMeter->schema, str + tsize, pMeter->schemaSize); memcpy(pTable->schema, str + tsize, pTable->schemaSize);
if (mgmtMeterCreateFromMetric(pMeter)) { if (mgmtTableCreateFromSuperTable(pTable)) {
pMeter->pTagData = pMeter->schema; pTable->pTagData = pTable->schema;
} }
return NULL; return NULL;
} }
void *mgmtMeterActionDestroy(void *row, char *str, int size, int *ssize) { void *mgmtMeterActionDestroy(void *row, char *str, int size, int *ssize) {
STabObj *pMeter = (STabObj *)row; STabObj *pTable = (STabObj *)row;
mgmtDestroyMeter(pMeter); mgmtDestroyMeter(pTable);
return NULL; return NULL;
} }
void *mgmtMeterActionInsert(void *row, char *str, int size, int *ssize) { void *mgmtMeterActionInsert(void *row, char *str, int size, int *ssize) {
STabObj * pMeter = NULL; STabObj * pTable = NULL;
SVgObj * pVgroup = NULL; SVgObj * pVgroup = NULL;
SDbObj * pDb = NULL; SDbObj * pDb = NULL;
STabObj * pMetric = NULL; STabObj * pMetric = NULL;
SAcctObj *pAcct = NULL; SAcctObj *pAcct = NULL;
pMeter = (STabObj *)row; pTable = (STabObj *)row;
if (mgmtIsNormalMeter(pMeter)) { if (mgmtIsNormalTable(pTable)) {
pVgroup = mgmtGetVgroup(pMeter->gid.vgId); pVgroup = mgmtGetVgroup(pTable->gid.vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
mError("id:%s not in vgroup:%d", pMeter->meterId, pMeter->gid.vgId); mError("id:%s not in vgroup:%d", pTable->meterId, pTable->gid.vgId);
return NULL; return NULL;
} }
...@@ -185,40 +185,40 @@ void *mgmtMeterActionInsert(void *row, char *str, int size, int *ssize) { ...@@ -185,40 +185,40 @@ void *mgmtMeterActionInsert(void *row, char *str, int size, int *ssize) {
} }
} }
if (mgmtMeterCreateFromMetric(pMeter)) { if (mgmtTableCreateFromSuperTable(pTable)) {
pMeter->pTagData = (char *)pMeter->schema; pTable->pTagData = (char *)pTable->schema;
pMetric = mgmtGetMeter(pMeter->pTagData); pMetric = mgmtGetTable(pTable->pTagData);
assert(pMetric != NULL); assert(pMetric != NULL);
} }
if (pMeter->meterType == TSDB_METER_STABLE) { if (pTable->tableType == TSDB_TABLE_TYPE_STREAM_TABLE) {
pMeter->pSql = (char *)pMeter->schema + sizeof(SSchema) * pMeter->numOfColumns; pTable->pSql = (char *)pTable->schema + sizeof(SSchema) * pTable->numOfColumns;
} }
if (mgmtIsNormalMeter(pMeter)) { if (mgmtIsNormalTable(pTable)) {
if (pMetric) mgmtAddMeterIntoMetric(pMetric, pMeter); if (pMetric) mgmtAddMeterIntoMetric(pMetric, pTable);
if (!sdbMaster) { if (!sdbMaster) {
int sid = taosAllocateId(pVgroup->idPool); int sid = taosAllocateId(pVgroup->idPool);
if (sid != pMeter->gid.sid) { if (sid != pTable->gid.sid) {
mError("sid:%d is not matched from the master:%d", sid, pMeter->gid.sid); mError("sid:%d is not matched from the master:%d", sid, pTable->gid.sid);
return NULL; return NULL;
} }
} }
pAcct->acctInfo.numOfTimeSeries += (pMeter->numOfColumns - 1); pAcct->acctInfo.numOfTimeSeries += (pTable->numOfColumns - 1);
pVgroup->numOfMeters++; pVgroup->numOfMeters++;
pDb->numOfTables++; pDb->numOfTables++;
pVgroup->meterList[pMeter->gid.sid] = pMeter; pVgroup->meterList[pTable->gid.sid] = pTable;
if (pVgroup->numOfMeters >= pDb->cfg.maxSessions - 1 && pDb->numOfVgroups > 1) mgmtMoveVgroupToTail(pDb, pVgroup); if (pVgroup->numOfMeters >= pDb->cfg.maxSessions - 1 && pDb->numOfVgroups > 1) mgmtMoveVgroupToTail(pDb, pVgroup);
} else { } else {
// insert a metric // insert a metric
pMeter->pHead = NULL; pTable->pHead = NULL;
pMeter->pSkipList = NULL; pTable->pSkipList = NULL;
pDb = mgmtGetDbByMeterId(pMeter->meterId); pDb = mgmtGetDbByMeterId(pTable->meterId);
if (pDb) { if (pDb) {
mgmtAddMetricIntoDb(pDb, pMeter); mgmtAddMetricIntoDb(pDb, pTable);
} }
} }
...@@ -226,21 +226,21 @@ void *mgmtMeterActionInsert(void *row, char *str, int size, int *ssize) { ...@@ -226,21 +226,21 @@ void *mgmtMeterActionInsert(void *row, char *str, int size, int *ssize) {
} }
void *mgmtMeterActionDelete(void *row, char *str, int size, int *ssize) { void *mgmtMeterActionDelete(void *row, char *str, int size, int *ssize) {
STabObj *pMeter = NULL; STabObj *pTable = NULL;
SVgObj * pVgroup = NULL; SVgObj * pVgroup = NULL;
SDbObj * pDb = NULL; SDbObj * pDb = NULL;
STabObj *pMetric = NULL; STabObj *pMetric = NULL;
pMeter = (STabObj *)row; pTable = (STabObj *)row;
if (mgmtIsNormalMeter(pMeter)) { if (mgmtIsNormalTable(pTable)) {
if (pMeter->gid.vgId == 0) { if (pTable->gid.vgId == 0) {
return NULL; return NULL;
} }
pVgroup = mgmtGetVgroup(pMeter->gid.vgId); pVgroup = mgmtGetVgroup(pTable->gid.vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
mError("id:%s not in vgroup:%d", pMeter->meterId, pMeter->gid.vgId); mError("id:%s not in vgroup:%d", pTable->meterId, pTable->gid.vgId);
return NULL; return NULL;
} }
...@@ -251,48 +251,48 @@ void *mgmtMeterActionDelete(void *row, char *str, int size, int *ssize) { ...@@ -251,48 +251,48 @@ void *mgmtMeterActionDelete(void *row, char *str, int size, int *ssize) {
} }
} }
if (mgmtMeterCreateFromMetric(pMeter)) { if (mgmtTableCreateFromSuperTable(pTable)) {
pMeter->pTagData = (char *)pMeter->schema; pTable->pTagData = (char *)pTable->schema;
pMetric = mgmtGetMeter(pMeter->pTagData); pMetric = mgmtGetTable(pTable->pTagData);
assert(pMetric != NULL); assert(pMetric != NULL);
} }
if (mgmtIsNormalMeter(pMeter)) { if (mgmtIsNormalTable(pTable)) {
if (pMetric) mgmtRemoveMeterFromMetric(pMetric, pMeter); if (pMetric) mgmtRemoveMeterFromMetric(pMetric, pTable);
pVgroup->meterList[pMeter->gid.sid] = NULL; pVgroup->meterList[pTable->gid.sid] = NULL;
pVgroup->numOfMeters--; pVgroup->numOfMeters--;
pDb->numOfTables--; pDb->numOfTables--;
taosFreeId(pVgroup->idPool, pMeter->gid.sid); taosFreeId(pVgroup->idPool, pTable->gid.sid);
if (pVgroup->numOfMeters > 0) mgmtMoveVgroupToHead(pDb, pVgroup); if (pVgroup->numOfMeters > 0) mgmtMoveVgroupToHead(pDb, pVgroup);
} else { } else {
// remove a metric // remove a metric
// remove all the associated meters // remove all the associated meters
pDb = mgmtGetDbByMeterId(pMeter->meterId); pDb = mgmtGetDbByMeterId(pTable->meterId);
if (pDb) mgmtRemoveMetricFromDb(pDb, pMeter); if (pDb) mgmtRemoveMetricFromDb(pDb, pTable);
} }
return NULL; return NULL;
} }
void *mgmtMeterActionUpdate(void *row, char *str, int size, int *ssize) { void *mgmtMeterActionUpdate(void *row, char *str, int size, int *ssize) {
STabObj *pMeter = NULL; STabObj *pTable = NULL;
STabObj *pMetric = NULL; STabObj *pMetric = NULL;
pMeter = (STabObj *)row; pTable = (STabObj *)row;
STabObj *pNew = (STabObj *)str; STabObj *pNew = (STabObj *)str;
if (pNew->isDirty) { if (pNew->isDirty) {
pMetric = mgmtGetMeter(pMeter->pTagData); pMetric = mgmtGetTable(pTable->pTagData);
removeMeterFromMetricIndex(pMetric, pMeter); removeMeterFromMetricIndex(pMetric, pTable);
} }
mgmtMeterActionReset(pMeter, str, size, NULL); mgmtMeterActionReset(pTable, str, size, NULL);
pMeter->pTagData = pMeter->schema; pTable->pTagData = pTable->schema;
if (pNew->isDirty) { if (pNew->isDirty) {
addMeterIntoMetricIndex(pMetric, pMeter); addMeterIntoMetricIndex(pMetric, pTable);
pMeter->isDirty = 0; pTable->isDirty = 0;
} }
return NULL; return NULL;
...@@ -301,18 +301,18 @@ void *mgmtMeterActionUpdate(void *row, char *str, int size, int *ssize) { ...@@ -301,18 +301,18 @@ void *mgmtMeterActionUpdate(void *row, char *str, int size, int *ssize) {
void *mgmtMeterActionEncode(void *row, char *str, int size, int *ssize) { void *mgmtMeterActionEncode(void *row, char *str, int size, int *ssize) {
assert(row != NULL && str != NULL); assert(row != NULL && str != NULL);
STabObj *pMeter = (STabObj *)row; STabObj *pTable = (STabObj *)row;
int tsize = pMeter->updateEnd - (char *)pMeter; int tsize = pTable->updateEnd - (char *)pTable;
if (size < tsize + pMeter->schemaSize + 1) { if (size < tsize + pTable->schemaSize + 1) {
*ssize = -1; *ssize = -1;
return NULL; return NULL;
} }
memcpy(str, pMeter, tsize); memcpy(str, pTable, tsize);
memcpy(str + tsize, pMeter->schema, pMeter->schemaSize); memcpy(str + tsize, pTable->schema, pTable->schemaSize);
*ssize = tsize + pMeter->schemaSize; *ssize = tsize + pTable->schemaSize;
return NULL; return NULL;
} }
...@@ -320,25 +320,25 @@ void *mgmtMeterActionEncode(void *row, char *str, int size, int *ssize) { ...@@ -320,25 +320,25 @@ void *mgmtMeterActionEncode(void *row, char *str, int size, int *ssize) {
void *mgmtMeterActionDecode(void *row, char *str, int size, int *ssize) { void *mgmtMeterActionDecode(void *row, char *str, int size, int *ssize) {
assert(str != NULL); assert(str != NULL);
STabObj *pMeter = (STabObj *)malloc(sizeof(STabObj)); STabObj *pTable = (STabObj *)malloc(sizeof(STabObj));
if (pMeter == NULL) return NULL; if (pTable == NULL) return NULL;
memset(pMeter, 0, sizeof(STabObj)); memset(pTable, 0, sizeof(STabObj));
int tsize = pMeter->updateEnd - (char *)pMeter; int tsize = pTable->updateEnd - (char *)pTable;
if (size < tsize) { if (size < tsize) {
mgmtDestroyMeter(pMeter); mgmtDestroyMeter(pTable);
return NULL; return NULL;
} }
memcpy(pMeter, str, tsize); memcpy(pTable, str, tsize);
pMeter->schema = (char *)malloc(pMeter->schemaSize); pTable->schema = (char *)malloc(pTable->schemaSize);
if (pMeter->schema == NULL) { if (pTable->schema == NULL) {
mgmtDestroyMeter(pMeter); mgmtDestroyMeter(pTable);
return NULL; return NULL;
} }
memcpy(pMeter->schema, str + tsize, pMeter->schemaSize); memcpy(pTable->schema, str + tsize, pTable->schemaSize);
return (void *)pMeter; return (void *)pTable;
} }
void *mgmtMeterActionBeforeBatchUpdate(void *row, char *str, int size, int *ssize) { void *mgmtMeterActionBeforeBatchUpdate(void *row, char *str, int size, int *ssize) {
...@@ -350,61 +350,61 @@ void *mgmtMeterActionBeforeBatchUpdate(void *row, char *str, int size, int *ssiz ...@@ -350,61 +350,61 @@ void *mgmtMeterActionBeforeBatchUpdate(void *row, char *str, int size, int *ssiz
} }
void *mgmtMeterActionBatchUpdate(void *row, char *str, int size, int *ssize) { void *mgmtMeterActionBatchUpdate(void *row, char *str, int size, int *ssize) {
STabObj * pMeter = (STabObj *)row; STabObj * pTable = (STabObj *)row;
SMeterBatchUpdateMsg *msg = (SMeterBatchUpdateMsg *)str; SMeterBatchUpdateMsg *msg = (SMeterBatchUpdateMsg *)str;
if (mgmtIsMetric(pMeter)) { if (mgmtIsSuperTable(pTable)) {
if (msg->type == SDB_TYPE_INSERT) { // Insert schema if (msg->type == SDB_TYPE_INSERT) { // Insert schema
uint32_t total_cols = pMeter->numOfColumns + pMeter->numOfTags; uint32_t total_cols = pTable->numOfColumns + pTable->numOfTags;
pMeter->schema = realloc(pMeter->schema, (total_cols + msg->cols) * sizeof(SSchema)); pTable->schema = realloc(pTable->schema, (total_cols + msg->cols) * sizeof(SSchema));
pMeter->schemaSize = (total_cols + msg->cols) * sizeof(SSchema); pTable->schemaSize = (total_cols + msg->cols) * sizeof(SSchema);
pMeter->numOfTags += msg->cols; pTable->numOfTags += msg->cols;
memcpy(pMeter->schema + total_cols * sizeof(SSchema), msg->data, msg->cols * sizeof(SSchema)); memcpy(pTable->schema + total_cols * sizeof(SSchema), msg->data, msg->cols * sizeof(SSchema));
} else if (msg->type == SDB_TYPE_DELETE) { // Delete schema } else if (msg->type == SDB_TYPE_DELETE) { // Delete schema
// Make sure the order of tag columns // Make sure the order of tag columns
SchemaUnit *schemaUnit = (SchemaUnit *)(msg->data); SchemaUnit *schemaUnit = (SchemaUnit *)(msg->data);
int col = schemaUnit->col; int col = schemaUnit->col;
assert(col > 0 && col < pMeter->numOfTags); assert(col > 0 && col < pTable->numOfTags);
if (col < pMeter->numOfTags - 1) { if (col < pTable->numOfTags - 1) {
memmove(pMeter->schema + sizeof(SSchema) * (pMeter->numOfColumns + col), memmove(pTable->schema + sizeof(SSchema) * (pTable->numOfColumns + col),
pMeter->schema + sizeof(SSchema) * (pMeter->numOfColumns + col + 1), pTable->schema + sizeof(SSchema) * (pTable->numOfColumns + col + 1),
pMeter->schemaSize - (sizeof(SSchema) * (pMeter->numOfColumns + col + 1))); pTable->schemaSize - (sizeof(SSchema) * (pTable->numOfColumns + col + 1)));
} }
pMeter->schemaSize -= sizeof(SSchema); pTable->schemaSize -= sizeof(SSchema);
pMeter->numOfTags--; pTable->numOfTags--;
pMeter->schema = realloc(pMeter->schema, pMeter->schemaSize); pTable->schema = realloc(pTable->schema, pTable->schemaSize);
} }
return pMeter->pHead; return pTable->pHead;
} else if (mgmtMeterCreateFromMetric(pMeter)) { } else if (mgmtTableCreateFromSuperTable(pTable)) {
if (msg->type == SDB_TYPE_INSERT) { if (msg->type == SDB_TYPE_INSERT) {
SSchema *schemas = (SSchema *)msg->data; SSchema *schemas = (SSchema *)msg->data;
int total_size = 0; int total_size = 0;
for (int i = 0; i < msg->cols; i++) { for (int i = 0; i < msg->cols; i++) {
total_size += schemas[i].bytes; total_size += schemas[i].bytes;
} }
pMeter->schema = realloc(pMeter->schema, pMeter->schemaSize + total_size); pTable->schema = realloc(pTable->schema, pTable->schemaSize + total_size);
pMeter->pTagData = pMeter->schema; pTable->pTagData = pTable->schema;
memset(pMeter->schema + pMeter->schemaSize, 0, total_size); memset(pTable->schema + pTable->schemaSize, 0, total_size);
pMeter->schemaSize += total_size; pTable->schemaSize += total_size;
// TODO: set the data as default value // TODO: set the data as default value
} else if (msg->type == SDB_TYPE_DELETE) { // Delete values in MTABLEs } else if (msg->type == SDB_TYPE_DELETE) { // Delete values in MTABLEs
SchemaUnit *schemaUnit = (SchemaUnit *)(msg->data); SchemaUnit *schemaUnit = (SchemaUnit *)(msg->data);
int32_t pos = schemaUnit->pos; int32_t pos = schemaUnit->pos;
int32_t bytes = schemaUnit->schema.bytes; int32_t bytes = schemaUnit->schema.bytes;
assert(pos + bytes <= pMeter->schemaSize); assert(pos + bytes <= pTable->schemaSize);
if (pos + bytes != pMeter->schemaSize) { if (pos + bytes != pTable->schemaSize) {
memmove(pMeter->schema + pos, pMeter->schema + pos + bytes, pMeter->schemaSize - (pos + bytes)); memmove(pTable->schema + pos, pTable->schema + pos + bytes, pTable->schemaSize - (pos + bytes));
} }
pMeter->schemaSize -= bytes; pTable->schemaSize -= bytes;
pMeter->schema = realloc(pMeter->schema, pMeter->schemaSize); pTable->schema = realloc(pTable->schema, pTable->schemaSize);
} }
return pMeter->next; return pTable->next;
} }
return NULL; return NULL;
...@@ -425,15 +425,15 @@ void *mgmtMeterAction(char action, void *row, char *str, int size, int *ssize) { ...@@ -425,15 +425,15 @@ void *mgmtMeterAction(char action, void *row, char *str, int size, int *ssize) {
return NULL; return NULL;
} }
void mgmtAddMeterStatisticToAcct(STabObj *pMeter, SAcctObj *pAcct) { void mgmtAddMeterStatisticToAcct(STabObj *pTable, SAcctObj *pAcct) {
pAcct->acctInfo.numOfTimeSeries += (pMeter->numOfColumns - 1); pAcct->acctInfo.numOfTimeSeries += (pTable->numOfColumns - 1);
} }
int mgmtInitMeters() { int mgmtInitMeters() {
void * pNode = NULL; void * pNode = NULL;
void * pLastNode = NULL; void * pLastNode = NULL;
SVgObj * pVgroup = NULL; SVgObj * pVgroup = NULL;
STabObj * pMeter = NULL; STabObj * pTable = NULL;
STabObj * pMetric = NULL; STabObj * pMetric = NULL;
SDbObj * pDb = NULL; SDbObj * pDb = NULL;
SAcctObj *pAcct = NULL; SAcctObj *pAcct = NULL;
...@@ -450,71 +450,71 @@ int mgmtInitMeters() { ...@@ -450,71 +450,71 @@ int mgmtInitMeters() {
pNode = NULL; pNode = NULL;
while (1) { while (1) {
pNode = sdbFetchRow(meterSdb, pNode, (void **)&pMeter); pNode = sdbFetchRow(meterSdb, pNode, (void **)&pTable);
if (pMeter == NULL) break; if (pTable == NULL) break;
if (mgmtIsMetric(pMeter)) pMeter->numOfMeters = 0; if (mgmtIsSuperTable(pTable)) pTable->numOfMeters = 0;
} }
pNode = NULL; pNode = NULL;
while (1) { while (1) {
pLastNode = pNode; pLastNode = pNode;
pNode = sdbFetchRow(meterSdb, pNode, (void **)&pMeter); pNode = sdbFetchRow(meterSdb, pNode, (void **)&pTable);
if (pMeter == NULL) break; if (pTable == NULL) break;
pDb = mgmtGetDbByMeterId(pMeter->meterId); pDb = mgmtGetDbByMeterId(pTable->meterId);
if (pDb == NULL) { if (pDb == NULL) {
mError("meter:%s, failed to get db, discard it", pMeter->meterId, pMeter->gid.vgId, pMeter->gid.sid); mError("meter:%s, failed to get db, discard it", pTable->meterId, pTable->gid.vgId, pTable->gid.sid);
pMeter->gid.vgId = 0; pTable->gid.vgId = 0;
sdbDeleteRow(meterSdb, pMeter); sdbDeleteRow(meterSdb, pTable);
pNode = pLastNode; pNode = pLastNode;
continue; continue;
} }
if (mgmtIsNormalMeter(pMeter)) { if (mgmtIsNormalTable(pTable)) {
pVgroup = mgmtGetVgroup(pMeter->gid.vgId); pVgroup = mgmtGetVgroup(pTable->gid.vgId);
if (pVgroup == NULL) { if (pVgroup == NULL) {
mError("meter:%s, failed to get vgroup:%d sid:%d, discard it", pMeter->meterId, pMeter->gid.vgId, pMeter->gid.sid); mError("meter:%s, failed to get vgroup:%d sid:%d, discard it", pTable->meterId, pTable->gid.vgId, pTable->gid.sid);
pMeter->gid.vgId = 0; pTable->gid.vgId = 0;
sdbDeleteRow(meterSdb, pMeter); sdbDeleteRow(meterSdb, pTable);
pNode = pLastNode; pNode = pLastNode;
continue; continue;
} }
if (strcmp(pVgroup->dbName, pDb->name) != 0) { if (strcmp(pVgroup->dbName, pDb->name) != 0) {
mError("meter:%s, db:%s not match with vgroup:%d db:%s sid:%d, discard it", mError("meter:%s, db:%s not match with vgroup:%d db:%s sid:%d, discard it",
pMeter->meterId, pDb->name, pMeter->gid.vgId, pVgroup->dbName, pMeter->gid.sid); pTable->meterId, pDb->name, pTable->gid.vgId, pVgroup->dbName, pTable->gid.sid);
pMeter->gid.vgId = 0; pTable->gid.vgId = 0;
sdbDeleteRow(meterSdb, pMeter); sdbDeleteRow(meterSdb, pTable);
pNode = pLastNode; pNode = pLastNode;
continue; continue;
} }
if ( pVgroup->meterList == NULL) { if ( pVgroup->meterList == NULL) {
mError("meter:%s, vgroup:%d meterlist is null", pMeter->meterId, pMeter->gid.vgId); mError("meter:%s, vgroup:%d meterlist is null", pTable->meterId, pTable->gid.vgId);
pMeter->gid.vgId = 0; pTable->gid.vgId = 0;
sdbDeleteRow(meterSdb, pMeter); sdbDeleteRow(meterSdb, pTable);
pNode = pLastNode; pNode = pLastNode;
continue; continue;
} }
pVgroup->meterList[pMeter->gid.sid] = pMeter; pVgroup->meterList[pTable->gid.sid] = pTable;
taosIdPoolMarkStatus(pVgroup->idPool, pMeter->gid.sid, 1); taosIdPoolMarkStatus(pVgroup->idPool, pTable->gid.sid, 1);
if (pMeter->meterType == TSDB_METER_STABLE) { if (pTable->tableType == TSDB_TABLE_TYPE_STREAM_TABLE) {
pMeter->pSql = (char *)pMeter->schema + sizeof(SSchema) * pMeter->numOfColumns; pTable->pSql = (char *)pTable->schema + sizeof(SSchema) * pTable->numOfColumns;
} }
if (mgmtMeterCreateFromMetric(pMeter)) { if (mgmtTableCreateFromSuperTable(pTable)) {
pMeter->pTagData = (char *)pMeter->schema; // + sizeof(SSchema)*pMeter->numOfColumns; pTable->pTagData = (char *)pTable->schema; // + sizeof(SSchema)*pTable->numOfColumns;
pMetric = mgmtGetMeter(pMeter->pTagData); pMetric = mgmtGetTable(pTable->pTagData);
if (pMetric) mgmtAddMeterIntoMetric(pMetric, pMeter); if (pMetric) mgmtAddMeterIntoMetric(pMetric, pTable);
} }
pAcct = mgmtGetAcct(pDb->cfg.acct); pAcct = mgmtGetAcct(pDb->cfg.acct);
if (pAcct) mgmtAddMeterStatisticToAcct(pMeter, pAcct); if (pAcct) mgmtAddMeterStatisticToAcct(pTable, pAcct);
} else { } else {
if (pDb) mgmtAddMetricIntoDb(pDb, pMeter); if (pDb) mgmtAddMetricIntoDb(pDb, pTable);
} }
} }
...@@ -524,10 +524,10 @@ int mgmtInitMeters() { ...@@ -524,10 +524,10 @@ int mgmtInitMeters() {
return 0; return 0;
} }
STabObj *mgmtGetMeter(char *meterId) { return (STabObj *)sdbGetRow(meterSdb, meterId); } STabObj *mgmtGetTable(char *meterId) { return (STabObj *)sdbGetRow(meterSdb, meterId); }
int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) { int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) {
STabObj * pMeter = NULL; STabObj * pTable = NULL;
STabObj * pMetric = NULL; STabObj * pMetric = NULL;
SVgObj * pVgroup = NULL; SVgObj * pVgroup = NULL;
int size = 0; int size = 0;
...@@ -548,8 +548,8 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) { ...@@ -548,8 +548,8 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) {
} }
// does table exist? // does table exist?
pMeter = mgmtGetMeter(pCreate->meterId); pTable = mgmtGetTable(pCreate->meterId);
if (pMeter) { if (pTable) {
if (pCreate->igExists) { if (pCreate->igExists) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
...@@ -558,14 +558,14 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) { ...@@ -558,14 +558,14 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) {
} }
// Create the table object // Create the table object
pMeter = (STabObj *)malloc(sizeof(STabObj)); pTable = (STabObj *)malloc(sizeof(STabObj));
if (pMeter == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY; if (pTable == NULL) return TSDB_CODE_SERV_OUT_OF_MEMORY;
memset(pMeter, 0, sizeof(STabObj)); memset(pTable, 0, sizeof(STabObj));
if (pCreate->numOfColumns == 0 && pCreate->numOfTags == 0) { // MTABLE if (pCreate->numOfColumns == 0 && pCreate->numOfTags == 0) { // MTABLE
pMeter->meterType = TSDB_METER_MTABLE; pTable->tableType = TSDB_TABLE_TYPE_CREATE_FROM_STABLE;
char *pTagData = (char *)pCreate->schema; // it is a tag key char *pTagData = (char *)pCreate->schema; // it is a tag key
pMetric = mgmtGetMeter(pTagData); pMetric = mgmtGetTable(pTagData);
if (pMetric == NULL) { if (pMetric == NULL) {
mError("table:%s, corresponding super table does not exist", pCreate->meterId); mError("table:%s, corresponding super table does not exist", pCreate->meterId);
return TSDB_CODE_INVALID_TABLE; return TSDB_CODE_INVALID_TABLE;
...@@ -576,74 +576,74 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) { ...@@ -576,74 +576,74 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) {
* so, we don't allocate memory for it in order to save a huge amount of * so, we don't allocate memory for it in order to save a huge amount of
* memory when a large amount of meters are created according to this super table. * memory when a large amount of meters are created according to this super table.
*/ */
size = mgmtGetTagsLength(pMetric, INT_MAX) + (uint32_t)TSDB_METER_ID_LEN; size = mgmtGetTagsLength(pMetric, INT_MAX) + (uint32_t)TSDB_TABLE_ID_LEN;
pMeter->schema = (char *)malloc(size); pTable->schema = (char *)malloc(size);
if (pMeter->schema == NULL) { if (pTable->schema == NULL) {
mgmtDestroyMeter(pMeter); mgmtDestroyMeter(pTable);
mError("table:%s, corresponding super table schema is null", pCreate->meterId); mError("table:%s, corresponding super table schema is null", pCreate->meterId);
return TSDB_CODE_INVALID_TABLE; return TSDB_CODE_INVALID_TABLE;
} }
memset(pMeter->schema, 0, size); memset(pTable->schema, 0, size);
pMeter->schemaSize = size; pTable->schemaSize = size;
pMeter->numOfColumns = pMetric->numOfColumns; pTable->numOfColumns = pMetric->numOfColumns;
pMeter->sversion = pMetric->sversion; pTable->sversion = pMetric->sversion;
pMeter->pTagData = pMeter->schema; pTable->pTagData = pTable->schema;
pMeter->nextColId = pMetric->nextColId; pTable->nextColId = pMetric->nextColId;
memcpy(pMeter->pTagData, pTagData, size); memcpy(pTable->pTagData, pTagData, size);
} else { } else {
int numOfCols = pCreate->numOfColumns + pCreate->numOfTags; int numOfCols = pCreate->numOfColumns + pCreate->numOfTags;
size = numOfCols * sizeof(SSchema) + pCreate->sqlLen; size = numOfCols * sizeof(SSchema) + pCreate->sqlLen;
pMeter->schema = (char *)malloc(size); pTable->schema = (char *)malloc(size);
if (pMeter->schema == NULL) { if (pTable->schema == NULL) {
mgmtDestroyMeter(pMeter); mgmtDestroyMeter(pTable);
mError("table:%s, no schema input", pCreate->meterId); mError("table:%s, no schema input", pCreate->meterId);
return TSDB_CODE_SERV_OUT_OF_MEMORY; return TSDB_CODE_SERV_OUT_OF_MEMORY;
} }
memset(pMeter->schema, 0, size); memset(pTable->schema, 0, size);
pMeter->numOfColumns = pCreate->numOfColumns; pTable->numOfColumns = pCreate->numOfColumns;
pMeter->sversion = 0; pTable->sversion = 0;
pMeter->numOfTags = pCreate->numOfTags; pTable->numOfTags = pCreate->numOfTags;
pMeter->schemaSize = size; pTable->schemaSize = size;
memcpy(pMeter->schema, pCreate->schema, numOfCols * sizeof(SSchema)); memcpy(pTable->schema, pCreate->schema, numOfCols * sizeof(SSchema));
for (int k = 0; k < pCreate->numOfColumns; k++) { for (int k = 0; k < pCreate->numOfColumns; k++) {
SSchema *tschema = (SSchema *)pMeter->schema; SSchema *tschema = (SSchema *)pTable->schema;
tschema[k].colId = pMeter->nextColId++; tschema[k].colId = pTable->nextColId++;
} }
if (pCreate->sqlLen > 0) { if (pCreate->sqlLen > 0) {
pMeter->meterType = TSDB_METER_STABLE; pTable->tableType = TSDB_TABLE_TYPE_STREAM_TABLE;
pMeter->pSql = pMeter->schema + numOfCols * sizeof(SSchema); pTable->pSql = pTable->schema + numOfCols * sizeof(SSchema);
memcpy(pMeter->pSql, (char *)(pCreate->schema) + numOfCols * sizeof(SSchema), pCreate->sqlLen); memcpy(pTable->pSql, (char *)(pCreate->schema) + numOfCols * sizeof(SSchema), pCreate->sqlLen);
pMeter->pSql[pCreate->sqlLen - 1] = 0; pTable->pSql[pCreate->sqlLen - 1] = 0;
mTrace("table:%s, stream sql len:%d sql:%s", pCreate->meterId, pCreate->sqlLen, pMeter->pSql); mTrace("table:%s, stream sql len:%d sql:%s", pCreate->meterId, pCreate->sqlLen, pTable->pSql);
} else { } else {
if (pCreate->numOfTags > 0) { if (pCreate->numOfTags > 0) {
pMeter->meterType = TSDB_METER_METRIC; pTable->tableType = TSDB_TABLE_TYPE_SUPER_TABLE;
} else { } else {
pMeter->meterType = TSDB_METER_OTABLE; pTable->tableType = TSDB_TABLE_TYPE_NORMAL_TABLE;
} }
} }
} }
pMeter->createdTime = taosGetTimestampMs(); pTable->createdTime = taosGetTimestampMs();
strcpy(pMeter->meterId, pCreate->meterId); strcpy(pTable->meterId, pCreate->meterId);
if (pthread_rwlock_init(&pMeter->rwLock, NULL)) { if (pthread_rwlock_init(&pTable->rwLock, NULL)) {
mError("table:%s, failed to init meter lock", pCreate->meterId); mError("table:%s, failed to init meter lock", pCreate->meterId);
mgmtDestroyMeter(pMeter); mgmtDestroyMeter(pTable);
return TSDB_CODE_FAILED_TO_LOCK_RESOURCES; return TSDB_CODE_FAILED_TO_LOCK_RESOURCES;
} }
if (mgmtCheckExpired()) { if (mgmtCheckExpired()) {
mError("failed to create meter:%s, reason:grant expired", pMeter->meterId); mError("failed to create meter:%s, reason:grant expired", pTable->meterId);
return TSDB_CODE_GRANT_EXPIRED; return TSDB_CODE_GRANT_EXPIRED;
} }
if (pCreate->numOfTags == 0) { if (pCreate->numOfTags == 0) {
int grantCode = mgmtCheckTimeSeries(pMeter->numOfColumns); int grantCode = mgmtCheckTimeSeries(pTable->numOfColumns);
if (grantCode != 0) { if (grantCode != 0) {
mError("table:%s, grant expired", pCreate->meterId); mError("table:%s, grant expired", pCreate->meterId);
return grantCode; return grantCode;
...@@ -654,13 +654,13 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) { ...@@ -654,13 +654,13 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) {
pVgroup = pDb->pHead; pVgroup = pDb->pHead;
if (pDb->vgStatus == TSDB_VG_STATUS_IN_PROGRESS) { if (pDb->vgStatus == TSDB_VG_STATUS_IN_PROGRESS) {
mgmtDestroyMeter(pMeter); mgmtDestroyMeter(pTable);
//mTrace("table:%s, vgroup in creating progress", pCreate->meterId); //mTrace("table:%s, vgroup in creating progress", pCreate->meterId);
return TSDB_CODE_ACTION_IN_PROGRESS; return TSDB_CODE_ACTION_IN_PROGRESS;
} }
if (pDb->vgStatus == TSDB_VG_STATUS_FULL) { if (pDb->vgStatus == TSDB_VG_STATUS_FULL) {
mgmtDestroyMeter(pMeter); mgmtDestroyMeter(pTable);
mError("table:%s, vgroup is full", pCreate->meterId); mError("table:%s, vgroup is full", pCreate->meterId);
return TSDB_CODE_NO_ENOUGH_DNODES; return TSDB_CODE_NO_ENOUGH_DNODES;
} }
...@@ -669,7 +669,7 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) { ...@@ -669,7 +669,7 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) {
pDb->vgStatus == TSDB_VG_STATUS_SERVER_NO_PACE || pDb->vgStatus == TSDB_VG_STATUS_SERVER_NO_PACE ||
pDb->vgStatus == TSDB_VG_STATUS_SERV_OUT_OF_MEMORY || pDb->vgStatus == TSDB_VG_STATUS_SERV_OUT_OF_MEMORY ||
pDb->vgStatus == TSDB_VG_STATUS_INIT_FAILED ) { pDb->vgStatus == TSDB_VG_STATUS_INIT_FAILED ) {
mgmtDestroyMeter(pMeter); mgmtDestroyMeter(pTable);
mError("table:%s, vgroup init failed, reason:%d %s", pCreate->meterId, pDb->vgStatus, taosGetVgroupStatusStr(pDb->vgStatus)); mError("table:%s, vgroup init failed, reason:%d %s", pCreate->meterId, pDb->vgStatus, taosGetVgroupStatusStr(pDb->vgStatus));
return pDb->vgStatus; return pDb->vgStatus;
} }
...@@ -677,7 +677,7 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) { ...@@ -677,7 +677,7 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) {
if (pVgroup == NULL) { if (pVgroup == NULL) {
pDb->vgStatus = TSDB_VG_STATUS_IN_PROGRESS; pDb->vgStatus = TSDB_VG_STATUS_IN_PROGRESS;
mgmtCreateVgroup(pDb); mgmtCreateVgroup(pDb);
mgmtDestroyMeter(pMeter); mgmtDestroyMeter(pTable);
mTrace("table:%s, vgroup malloced, wait for create progress finished", pCreate->meterId); mTrace("table:%s, vgroup malloced, wait for create progress finished", pCreate->meterId);
return TSDB_CODE_ACTION_IN_PROGRESS; return TSDB_CODE_ACTION_IN_PROGRESS;
} }
...@@ -687,22 +687,22 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) { ...@@ -687,22 +687,22 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) {
mWarn("table:%s, vgroup:%d run out of ID, num:%d", pCreate->meterId, pVgroup->vgId, taosIdPoolNumOfUsed(pVgroup->idPool)); mWarn("table:%s, vgroup:%d run out of ID, num:%d", pCreate->meterId, pVgroup->vgId, taosIdPoolNumOfUsed(pVgroup->idPool));
pDb->vgStatus = TSDB_VG_STATUS_IN_PROGRESS; pDb->vgStatus = TSDB_VG_STATUS_IN_PROGRESS;
mgmtCreateVgroup(pDb); mgmtCreateVgroup(pDb);
mgmtDestroyMeter(pMeter); mgmtDestroyMeter(pTable);
return TSDB_CODE_ACTION_IN_PROGRESS; return TSDB_CODE_ACTION_IN_PROGRESS;
} }
pMeter->gid.sid = sid; pTable->gid.sid = sid;
pMeter->gid.vgId = pVgroup->vgId; pTable->gid.vgId = pVgroup->vgId;
pMeter->uid = (((uint64_t)pMeter->gid.vgId) << 40) + ((((uint64_t)pMeter->gid.sid) & ((1ul << 24) - 1ul)) << 16) + pTable->uid = (((uint64_t)pTable->gid.vgId) << 40) + ((((uint64_t)pTable->gid.sid) & ((1ul << 24) - 1ul)) << 16) +
((uint64_t)sdbVersion & ((1ul << 16) - 1ul)); ((uint64_t)sdbVersion & ((1ul << 16) - 1ul));
mTrace("table:%s, create table in vgroup, vgId:%d sid:%d vnode:%d uid:%" PRIu64 " db:%s", mTrace("table:%s, create table in vgroup, vgId:%d sid:%d vnode:%d uid:%" PRIu64 " db:%s",
pMeter->meterId, pVgroup->vgId, sid, pVgroup->vnodeGid[0].vnode, pMeter->uid, pDb->name); pTable->meterId, pVgroup->vgId, sid, pVgroup->vnodeGid[0].vnode, pTable->uid, pDb->name);
} else { } else {
pMeter->uid = (((uint64_t)pMeter->createdTime) << 16) + ((uint64_t)sdbVersion & ((1ul << 16) - 1ul)); pTable->uid = (((uint64_t)pTable->createdTime) << 16) + ((uint64_t)sdbVersion & ((1ul << 16) - 1ul));
} }
if (sdbInsertRow(meterSdb, pMeter, 0) < 0) { if (sdbInsertRow(meterSdb, pTable, 0) < 0) {
mError("table:%s, update sdb error", pCreate->meterId); mError("table:%s, update sdb error", pCreate->meterId);
return TSDB_CODE_SDB_ERROR; return TSDB_CODE_SDB_ERROR;
} }
...@@ -710,21 +710,21 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) { ...@@ -710,21 +710,21 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) {
// send create message to the selected vnode servers // send create message to the selected vnode servers
if (pCreate->numOfTags == 0) { if (pCreate->numOfTags == 0) {
mTrace("table:%s, send create table msg to dnode, vgId:%d, sid:%d, vnode:%d", mTrace("table:%s, send create table msg to dnode, vgId:%d, sid:%d, vnode:%d",
pMeter->meterId, pMeter->gid.vgId, pMeter->gid.sid, pVgroup->vnodeGid[0].vnode); pTable->meterId, pTable->gid.vgId, pTable->gid.sid, pVgroup->vnodeGid[0].vnode);
mgmtAddTimeSeries(pMeter->numOfColumns - 1); mgmtAddTimeSeries(pTable->numOfColumns - 1);
mgmtSendCreateMsgToVgroup(pMeter, pVgroup); mgmtSendCreateMsgToVgroup(pTable, pVgroup);
} }
return 0; return 0;
} }
int mgmtDropMeter(SDbObj *pDb, char *meterId, int ignore) { int mgmtDropMeter(SDbObj *pDb, char *meterId, int ignore) {
STabObj * pMeter; STabObj * pTable;
SAcctObj *pAcct; SAcctObj *pAcct;
pMeter = mgmtGetMeter(meterId); pTable = mgmtGetTable(meterId);
if (pMeter == NULL) { if (pTable == NULL) {
if (ignore) { if (ignore) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
...@@ -739,31 +739,31 @@ int mgmtDropMeter(SDbObj *pDb, char *meterId, int ignore) { ...@@ -739,31 +739,31 @@ int mgmtDropMeter(SDbObj *pDb, char *meterId, int ignore) {
return TSDB_CODE_MONITOR_DB_FORBEIDDEN; return TSDB_CODE_MONITOR_DB_FORBEIDDEN;
} }
if (mgmtIsNormalMeter(pMeter)) { if (mgmtIsNormalTable(pTable)) {
return dropMeterImp(pDb, pMeter, pAcct); return dropMeterImp(pDb, pTable, pAcct);
} else { } else {
// remove a metric // remove a metric
/* /*
if (pMeter->numOfMeters > 0) { if (pTable->numOfMeters > 0) {
assert(pMeter->pSkipList != NULL && pMeter->pSkipList->nSize > 0); assert(pTable->pSkipList != NULL && pTable->pSkipList->nSize > 0);
return TSDB_CODE_RELATED_TABLES_EXIST; return TSDB_CODE_RELATED_TABLES_EXIST;
} }
*/ */
// first delet all meters of metric // first delet all meters of metric
dropAllMetersOfMetric(pDb, pMeter, pAcct); dropAllMetersOfMetric(pDb, pTable, pAcct);
// finally delete metric // finally delete metric
sdbDeleteRow(meterSdb, pMeter); sdbDeleteRow(meterSdb, pTable);
} }
return 0; return 0;
} }
int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter) { int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter) {
STabObj *pMeter; STabObj *pTable;
pMeter = mgmtGetMeter(pAlter->meterId); pTable = mgmtGetTable(pAlter->meterId);
if (pMeter == NULL) { if (pTable == NULL) {
return TSDB_CODE_INVALID_TABLE; return TSDB_CODE_INVALID_TABLE;
} }
...@@ -771,7 +771,7 @@ int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter) { ...@@ -771,7 +771,7 @@ int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter) {
if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) return TSDB_CODE_MONITOR_DB_FORBEIDDEN; if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) return TSDB_CODE_MONITOR_DB_FORBEIDDEN;
if (pAlter->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) { if (pAlter->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) {
if (!mgmtIsNormalMeter(pMeter) || !mgmtMeterCreateFromMetric(pMeter)) { if (!mgmtIsNormalTable(pTable) || !mgmtTableCreateFromSuperTable(pTable)) {
return TSDB_CODE_OPS_NOT_SUPPORT; return TSDB_CODE_OPS_NOT_SUPPORT;
} }
} }
...@@ -779,25 +779,25 @@ int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter) { ...@@ -779,25 +779,25 @@ int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter) {
// todo add // todo add
/* mgmtMeterAddTags */ /* mgmtMeterAddTags */
if (pAlter->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) { if (pAlter->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) {
mTrace("alter table %s to add tag column:%s, type:%d", pMeter->meterId, pAlter->schema[0].name, mTrace("alter table %s to add tag column:%s, type:%d", pTable->meterId, pAlter->schema[0].name,
pAlter->schema[0].type); pAlter->schema[0].type);
return mgmtMeterAddTags(pMeter, pAlter->schema, 1); return mgmtMeterAddTags(pTable, pAlter->schema, 1);
} else if (pAlter->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN) {
mTrace("alter table %s to drop tag column:%s", pMeter->meterId, pAlter->schema[0].name); mTrace("alter table %s to drop tag column:%s", pTable->meterId, pAlter->schema[0].name);
return mgmtMeterDropTagByName(pMeter, pAlter->schema[0].name); return mgmtMeterDropTagByName(pTable, pAlter->schema[0].name);
} else if (pAlter->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) {
mTrace("alter table %s to change tag column name, old: %s, new: %s", pMeter->meterId, pAlter->schema[0].name, mTrace("alter table %s to change tag column name, old: %s, new: %s", pTable->meterId, pAlter->schema[0].name,
pAlter->schema[1].name); pAlter->schema[1].name);
return mgmtMeterModifyTagNameByName(pMeter, pAlter->schema[0].name, pAlter->schema[1].name); return mgmtMeterModifyTagNameByName(pTable, pAlter->schema[0].name, pAlter->schema[1].name);
} else if (pAlter->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) { } else if (pAlter->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) {
mTrace("alter table %s to modify tag value, tag name:%s", pMeter->meterId, pAlter->schema[0].name); mTrace("alter table %s to modify tag value, tag name:%s", pTable->meterId, pAlter->schema[0].name);
return mgmtMeterModifyTagValueByName(pMeter, pAlter->schema[0].name, pAlter->tagVal); return mgmtMeterModifyTagValueByName(pTable, pAlter->schema[0].name, pAlter->tagVal);
} else if (pAlter->type == TSDB_ALTER_TABLE_ADD_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_ADD_COLUMN) {
mTrace("alter table %s to add column:%s, type:%d", pMeter->meterId, pAlter->schema[0].name, pAlter->schema[0].type); mTrace("alter table %s to add column:%s, type:%d", pTable->meterId, pAlter->schema[0].name, pAlter->schema[0].type);
return mgmtMeterAddColumn(pMeter, pAlter->schema, 1); return mgmtMeterAddColumn(pTable, pAlter->schema, 1);
} else if (pAlter->type == TSDB_ALTER_TABLE_DROP_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_DROP_COLUMN) {
mTrace("alter table %s to drop column:%s", pMeter->meterId, pAlter->schema[0].name); mTrace("alter table %s to drop column:%s", pTable->meterId, pAlter->schema[0].name);
return mgmtMeterDropColumnByName(pMeter, pAlter->schema[0].name); return mgmtMeterDropColumnByName(pTable, pAlter->schema[0].name);
} else { } else {
return TSDB_CODE_INVALID_MSG_TYPE; return TSDB_CODE_INVALID_MSG_TYPE;
} }
...@@ -805,17 +805,17 @@ int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter) { ...@@ -805,17 +805,17 @@ int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int dropMeterImp(SDbObj *pDb, STabObj * pMeter, SAcctObj *pAcct) { static int dropMeterImp(SDbObj *pDb, STabObj * pTable, SAcctObj *pAcct) {
SVgObj * pVgroup; SVgObj * pVgroup;
if (pAcct != NULL) pAcct->acctInfo.numOfTimeSeries -= (pMeter->numOfColumns - 1); if (pAcct != NULL) pAcct->acctInfo.numOfTimeSeries -= (pTable->numOfColumns - 1);
pVgroup = mgmtGetVgroup(pMeter->gid.vgId); pVgroup = mgmtGetVgroup(pTable->gid.vgId);
if (pVgroup == NULL) return TSDB_CODE_OTHERS; if (pVgroup == NULL) return TSDB_CODE_OTHERS;
mgmtRestoreTimeSeries(pMeter->numOfColumns - 1); mgmtRestoreTimeSeries(pTable->numOfColumns - 1);
mgmtSendRemoveMeterMsgToDnode(pMeter, pVgroup); mgmtSendRemoveMeterMsgToDnode(pTable, pVgroup);
sdbDeleteRow(meterSdb, pMeter); sdbDeleteRow(meterSdb, pTable);
if (pVgroup->numOfMeters <= 0) mgmtDropVgroup(pDb, pVgroup); if (pVgroup->numOfMeters <= 0) mgmtDropVgroup(pDb, pVgroup);
...@@ -823,10 +823,10 @@ static int dropMeterImp(SDbObj *pDb, STabObj * pMeter, SAcctObj *pAcct) { ...@@ -823,10 +823,10 @@ static int dropMeterImp(SDbObj *pDb, STabObj * pMeter, SAcctObj *pAcct) {
} }
static void dropAllMetersOfMetric(SDbObj *pDb, STabObj * pMetric, SAcctObj *pAcct) { static void dropAllMetersOfMetric(SDbObj *pDb, STabObj * pMetric, SAcctObj *pAcct) {
STabObj * pMeter = NULL; STabObj * pTable = NULL;
while ((pMeter = pMetric->pHead) != NULL) { while ((pTable = pMetric->pHead) != NULL) {
(void)dropMeterImp(pDb, pMeter, pAcct); (void)dropMeterImp(pDb, pTable, pAcct);
} }
} }
...@@ -834,18 +834,18 @@ static void dropAllMetersOfMetric(SDbObj *pDb, STabObj * pMetric, SAcctObj *pAcc ...@@ -834,18 +834,18 @@ static void dropAllMetersOfMetric(SDbObj *pDb, STabObj * pMetric, SAcctObj *pAcc
* create key of each meter for skip list, which is generated from first tag * create key of each meter for skip list, which is generated from first tag
* column * column
*/ */
static void createKeyFromTagValue(STabObj *pMetric, STabObj *pMeter, tSkipListKey *pKey) { static void createKeyFromTagValue(STabObj *pMetric, STabObj *pTable, tSkipListKey *pKey) {
SSchema * pTagSchema = (SSchema *)(pMetric->schema + pMetric->numOfColumns * sizeof(SSchema)); SSchema * pTagSchema = (SSchema *)(pMetric->schema + pMetric->numOfColumns * sizeof(SSchema));
const int16_t KEY_COLUMN_OF_TAGS = 0; const int16_t KEY_COLUMN_OF_TAGS = 0;
char *tagVal = pMeter->pTagData + TSDB_METER_ID_LEN; // tag start position char *tagVal = pTable->pTagData + TSDB_TABLE_ID_LEN; // tag start position
*pKey = tSkipListCreateKey(pTagSchema[KEY_COLUMN_OF_TAGS].type, tagVal, pTagSchema[KEY_COLUMN_OF_TAGS].bytes); *pKey = tSkipListCreateKey(pTagSchema[KEY_COLUMN_OF_TAGS].type, tagVal, pTagSchema[KEY_COLUMN_OF_TAGS].bytes);
} }
/* /*
* add a meter into a metric's skip list * add a meter into a metric's skip list
*/ */
static void addMeterIntoMetricIndex(STabObj *pMetric, STabObj *pMeter) { static void addMeterIntoMetricIndex(STabObj *pMetric, STabObj *pTable) {
const int16_t KEY_COLUMN_OF_TAGS = 0; const int16_t KEY_COLUMN_OF_TAGS = 0;
SSchema * pTagSchema = (SSchema *)(pMetric->schema + pMetric->numOfColumns * sizeof(SSchema)); SSchema * pTagSchema = (SSchema *)(pMetric->schema + pMetric->numOfColumns * sizeof(SSchema));
...@@ -856,27 +856,27 @@ static void addMeterIntoMetricIndex(STabObj *pMetric, STabObj *pMeter) { ...@@ -856,27 +856,27 @@ static void addMeterIntoMetricIndex(STabObj *pMetric, STabObj *pMeter) {
if (pMetric->pSkipList) { if (pMetric->pSkipList) {
tSkipListKey key = {0}; tSkipListKey key = {0};
createKeyFromTagValue(pMetric, pMeter, &key); createKeyFromTagValue(pMetric, pTable, &key);
tSkipListPut(pMetric->pSkipList, pMeter, &key, 1); tSkipListPut(pMetric->pSkipList, pTable, &key, 1);
tSkipListDestroyKey(&key); tSkipListDestroyKey(&key);
} }
} }
static void removeMeterFromMetricIndex(STabObj *pMetric, STabObj *pMeter) { static void removeMeterFromMetricIndex(STabObj *pMetric, STabObj *pTable) {
if (pMetric->pSkipList == NULL) { if (pMetric->pSkipList == NULL) {
return; return;
} }
tSkipListKey key = {0}; tSkipListKey key = {0};
createKeyFromTagValue(pMetric, pMeter, &key); createKeyFromTagValue(pMetric, pTable, &key);
tSkipListNode **pRes = NULL; tSkipListNode **pRes = NULL;
int32_t num = tSkipListGets(pMetric->pSkipList, &key, &pRes); int32_t num = tSkipListGets(pMetric->pSkipList, &key, &pRes);
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
STabObj *pOneMeter = (STabObj *)pRes[i]->pData; STabObj *pOneMeter = (STabObj *)pRes[i]->pData;
if (pOneMeter->gid.sid == pMeter->gid.sid && pOneMeter->gid.vgId == pMeter->gid.vgId) { if (pOneMeter->gid.sid == pTable->gid.sid && pOneMeter->gid.vgId == pTable->gid.vgId) {
assert(pMeter == pOneMeter); assert(pTable == pOneMeter);
tSkipListRemoveNode(pMetric->pSkipList, pRes[i]); tSkipListRemoveNode(pMetric->pSkipList, pRes[i]);
} }
} }
...@@ -887,38 +887,38 @@ static void removeMeterFromMetricIndex(STabObj *pMetric, STabObj *pMeter) { ...@@ -887,38 +887,38 @@ static void removeMeterFromMetricIndex(STabObj *pMetric, STabObj *pMeter) {
} }
} }
int mgmtAddMeterIntoMetric(STabObj *pMetric, STabObj *pMeter) { int mgmtAddMeterIntoMetric(STabObj *pMetric, STabObj *pTable) {
if (pMeter == NULL || pMetric == NULL) return -1; if (pTable == NULL || pMetric == NULL) return -1;
pthread_rwlock_wrlock(&(pMetric->rwLock)); pthread_rwlock_wrlock(&(pMetric->rwLock));
// add meter into skip list // add meter into skip list
pMeter->next = pMetric->pHead; pTable->next = pMetric->pHead;
pMeter->prev = NULL; pTable->prev = NULL;
if (pMetric->pHead) pMetric->pHead->prev = pMeter; if (pMetric->pHead) pMetric->pHead->prev = pTable;
pMetric->pHead = pMeter; pMetric->pHead = pTable;
pMetric->numOfMeters++; pMetric->numOfMeters++;
addMeterIntoMetricIndex(pMetric, pMeter); addMeterIntoMetricIndex(pMetric, pTable);
pthread_rwlock_unlock(&(pMetric->rwLock)); pthread_rwlock_unlock(&(pMetric->rwLock));
return 0; return 0;
} }
int mgmtRemoveMeterFromMetric(STabObj *pMetric, STabObj *pMeter) { int mgmtRemoveMeterFromMetric(STabObj *pMetric, STabObj *pTable) {
pthread_rwlock_wrlock(&(pMetric->rwLock)); pthread_rwlock_wrlock(&(pMetric->rwLock));
if (pMeter->prev) pMeter->prev->next = pMeter->next; if (pTable->prev) pTable->prev->next = pTable->next;
if (pMeter->next) pMeter->next->prev = pMeter->prev; if (pTable->next) pTable->next->prev = pTable->prev;
if (pMeter->prev == NULL) pMetric->pHead = pMeter->next; if (pTable->prev == NULL) pMetric->pHead = pTable->next;
pMetric->numOfMeters--; pMetric->numOfMeters--;
removeMeterFromMetricIndex(pMetric, pMeter); removeMeterFromMetricIndex(pMetric, pTable);
pthread_rwlock_unlock(&(pMetric->rwLock)); pthread_rwlock_unlock(&(pMetric->rwLock));
...@@ -927,7 +927,7 @@ int mgmtRemoveMeterFromMetric(STabObj *pMetric, STabObj *pMeter) { ...@@ -927,7 +927,7 @@ int mgmtRemoveMeterFromMetric(STabObj *pMetric, STabObj *pMeter) {
void mgmtCleanUpMeters() { sdbCloseTable(meterSdb); } void mgmtCleanUpMeters() { sdbCloseTable(meterSdb); }
int mgmtGetMeterMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { int mgmtGetTableMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) {
int cols = 0; int cols = 0;
SDbObj *pDb = NULL; SDbObj *pDb = NULL;
...@@ -974,34 +974,34 @@ int mgmtGetMeterMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { ...@@ -974,34 +974,34 @@ int mgmtGetMeterMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) {
return 0; return 0;
} }
SSchema *mgmtGetMeterSchema(STabObj *pMeter) { SSchema *mgmtGetTableSchema(STabObj *pTable) {
if (pMeter == NULL) { if (pTable == NULL) {
return NULL; return NULL;
} }
if (!mgmtMeterCreateFromMetric(pMeter)) { if (!mgmtTableCreateFromSuperTable(pTable)) {
return (SSchema *)pMeter->schema; return (SSchema *)pTable->schema;
} }
STabObj *pMetric = mgmtGetMeter(pMeter->pTagData); STabObj *pMetric = mgmtGetTable(pTable->pTagData);
assert(pMetric != NULL); assert(pMetric != NULL);
return (SSchema *)pMetric->schema; return (SSchema *)pMetric->schema;
} }
static int32_t mgmtSerializeTagValue(char* pMsg, STabObj* pMeter, int16_t* tagsId, int32_t numOfTags) { static int32_t mgmtSerializeTagValue(char* pMsg, STabObj* pTable, int16_t* tagsId, int32_t numOfTags) {
int32_t offset = 0; int32_t offset = 0;
for (int32_t j = 0; j < numOfTags; ++j) { for (int32_t j = 0; j < numOfTags; ++j) {
if (tagsId[j] == TSDB_TBNAME_COLUMN_INDEX) { // handle the table name tags if (tagsId[j] == TSDB_TBNAME_COLUMN_INDEX) { // handle the table name tags
char name[TSDB_METER_NAME_LEN] = {0}; char name[TSDB_METER_NAME_LEN] = {0};
extractTableName(pMeter->meterId, name); extractTableName(pTable->meterId, name);
memcpy(pMsg + offset, name, TSDB_METER_NAME_LEN); memcpy(pMsg + offset, name, TSDB_METER_NAME_LEN);
offset += TSDB_METER_NAME_LEN; offset += TSDB_METER_NAME_LEN;
} else { } else {
SSchema s = {0}; SSchema s = {0};
char * tag = mgmtMeterGetTag(pMeter, tagsId[j], &s); char * tag = mgmtTableGetTag(pTable, tagsId[j], &s);
memcpy(pMsg + offset, tag, (size_t)s.bytes); memcpy(pMsg + offset, tag, (size_t)s.bytes);
offset += s.bytes; offset += s.bytes;
...@@ -1014,10 +1014,10 @@ static int32_t mgmtSerializeTagValue(char* pMsg, STabObj* pMeter, int16_t* tagsI ...@@ -1014,10 +1014,10 @@ static int32_t mgmtSerializeTagValue(char* pMsg, STabObj* pMeter, int16_t* tagsI
/* /*
* serialize SVnodeSidList to byte array * serialize SVnodeSidList to byte array
*/ */
static char *mgmtBuildMetricMetaMsg(SConnObj *pConn, STabObj *pMeter, int32_t *ovgId, SVnodeSidList **pList, SMetricMeta *pMeta, static char *mgmtBuildMetricMetaMsg(SConnObj *pConn, STabObj *pTable, int32_t *ovgId, SVnodeSidList **pList, SMetricMeta *pMeta,
int32_t tagLen, int16_t numOfTags, int16_t *tagsId, int32_t maxNumOfMeters, int32_t tagLen, int16_t numOfTags, int16_t *tagsId, int32_t maxNumOfMeters,
char *pMsg) { char *pMsg) {
if (pMeter->gid.vgId != *ovgId || ((*pList) != NULL && (*pList)->numOfSids >= maxNumOfMeters)) { if (pTable->gid.vgId != *ovgId || ((*pList) != NULL && (*pList)->numOfSids >= maxNumOfMeters)) {
/* /*
* here we construct a new vnode group for 2 reasons * here we construct a new vnode group for 2 reasons
* 1. the query msg may be larger than 64k, * 1. the query msg may be larger than 64k,
...@@ -1028,7 +1028,7 @@ static char *mgmtBuildMetricMetaMsg(SConnObj *pConn, STabObj *pMeter, int32_t *o ...@@ -1028,7 +1028,7 @@ static char *mgmtBuildMetricMetaMsg(SConnObj *pConn, STabObj *pMeter, int32_t *o
(*pList)->index = 0; (*pList)->index = 0;
pMeta->numOfVnodes++; pMeta->numOfVnodes++;
SVgObj *pVgroup = mgmtGetVgroup(pMeter->gid.vgId); SVgObj *pVgroup = mgmtGetVgroup(pTable->gid.vgId);
for (int i = 0; i < TSDB_VNODES_SUPPORT; ++i) { for (int i = 0; i < TSDB_VNODES_SUPPORT; ++i) {
if (pConn->usePublicIp) { if (pConn->usePublicIp) {
(*pList)->vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp; (*pList)->vpeerDesc[i].ip = pVgroup->vnodeGid[i].publicIp;
...@@ -1040,18 +1040,18 @@ static char *mgmtBuildMetricMetaMsg(SConnObj *pConn, STabObj *pMeter, int32_t *o ...@@ -1040,18 +1040,18 @@ static char *mgmtBuildMetricMetaMsg(SConnObj *pConn, STabObj *pMeter, int32_t *o
} }
pMsg += sizeof(SVnodeSidList); pMsg += sizeof(SVnodeSidList);
(*ovgId) = pMeter->gid.vgId; (*ovgId) = pTable->gid.vgId;
} }
pMeta->numOfMeters++; pMeta->numOfMeters++;
(*pList)->numOfSids++; (*pList)->numOfSids++;
SMeterSidExtInfo *pSMeterTagInfo = (SMeterSidExtInfo *)pMsg; SMeterSidExtInfo *pSMeterTagInfo = (SMeterSidExtInfo *)pMsg;
pSMeterTagInfo->sid = htonl(pMeter->gid.sid); pSMeterTagInfo->sid = htonl(pTable->gid.sid);
pSMeterTagInfo->uid = htobe64(pMeter->uid); pSMeterTagInfo->uid = htobe64(pTable->uid);
pMsg += sizeof(SMeterSidExtInfo); pMsg += sizeof(SMeterSidExtInfo);
int32_t offset = mgmtSerializeTagValue(pMsg, pMeter, tagsId, numOfTags); int32_t offset = mgmtSerializeTagValue(pMsg, pTable, tagsId, numOfTags);
assert(offset == tagLen); assert(offset == tagLen);
pMsg += offset; pMsg += offset;
...@@ -1064,12 +1064,12 @@ static int32_t mgmtGetNumOfVnodesInResult(tQueryResultset *pResult) { ...@@ -1064,12 +1064,12 @@ static int32_t mgmtGetNumOfVnodesInResult(tQueryResultset *pResult) {
int32_t prevGid = -1; int32_t prevGid = -1;
for (int32_t i = 0; i < pResult->num; ++i) { for (int32_t i = 0; i < pResult->num; ++i) {
STabObj *pMeter = pResult->pRes[i]; STabObj *pTable = pResult->pRes[i];
if (prevGid == -1) { if (prevGid == -1) {
prevGid = pMeter->gid.vgId; prevGid = pTable->gid.vgId;
numOfVnodes++; numOfVnodes++;
} else if (prevGid != pMeter->gid.vgId) { } else if (prevGid != pTable->gid.vgId) {
prevGid = pMeter->gid.vgId; prevGid = pTable->gid.vgId;
numOfVnodes++; numOfVnodes++;
} }
} }
...@@ -1087,8 +1087,8 @@ static int32_t mgmtGetMetricMetaMsgSize(tQueryResultset *pResult, int32_t tagLen ...@@ -1087,8 +1087,8 @@ static int32_t mgmtGetMetricMetaMsgSize(tQueryResultset *pResult, int32_t tagLen
return size; return size;
} }
static SMetricMetaElemMsg *doConvertMetricMetaMsg(SMetricMetaMsg *pMetricMetaMsg, int32_t tableIndex) { static SMetricMetaElemMsg *doConvertMetricMetaMsg(SSuperTableMetaMsg *pSuperTableMetaMsg, int32_t tableIndex) {
SMetricMetaElemMsg *pElem = (SMetricMetaElemMsg *)((char *)pMetricMetaMsg + pMetricMetaMsg->metaElem[tableIndex]); SMetricMetaElemMsg *pElem = (SMetricMetaElemMsg *)((char *)pSuperTableMetaMsg + pSuperTableMetaMsg->metaElem[tableIndex]);
pElem->orderIndex = htons(pElem->orderIndex); pElem->orderIndex = htons(pElem->orderIndex);
pElem->orderType = htons(pElem->orderType); pElem->orderType = htons(pElem->orderType);
...@@ -1111,7 +1111,7 @@ static SMetricMetaElemMsg *doConvertMetricMetaMsg(SMetricMetaMsg *pMetricMetaMsg ...@@ -1111,7 +1111,7 @@ static SMetricMetaElemMsg *doConvertMetricMetaMsg(SMetricMetaMsg *pMetricMetaMsg
pElem->groupbyTagColumnList = htonl(pElem->groupbyTagColumnList); pElem->groupbyTagColumnList = htonl(pElem->groupbyTagColumnList);
SColIndexEx *groupColIds = (SColIndexEx*) (((char *)pMetricMetaMsg) + pElem->groupbyTagColumnList); SColIndexEx *groupColIds = (SColIndexEx*) (((char *)pSuperTableMetaMsg) + pElem->groupbyTagColumnList);
for (int32_t i = 0; i < pElem->numOfGroupCols; ++i) { for (int32_t i = 0; i < pElem->numOfGroupCols; ++i) {
groupColIds[i].colId = htons(groupColIds[i].colId); groupColIds[i].colId = htons(groupColIds[i].colId);
groupColIds[i].colIdx = htons(groupColIds[i].colIdx); groupColIds[i].colIdx = htons(groupColIds[i].colIdx);
...@@ -1122,7 +1122,7 @@ static SMetricMetaElemMsg *doConvertMetricMetaMsg(SMetricMetaMsg *pMetricMetaMsg ...@@ -1122,7 +1122,7 @@ static SMetricMetaElemMsg *doConvertMetricMetaMsg(SMetricMetaMsg *pMetricMetaMsg
return pElem; return pElem;
} }
static int32_t mgmtBuildMetricMetaRspMsg(SConnObj *pConn, SMetricMetaMsg *pMetricMetaMsg, tQueryResultset *pResult, static int32_t mgmtBuildMetricMetaRspMsg(SConnObj *pConn, SSuperTableMetaMsg *pSuperTableMetaMsg, tQueryResultset *pResult,
char **pStart, int32_t *tagLen, int32_t rspMsgSize, int32_t maxTablePerVnode, char **pStart, int32_t *tagLen, int32_t rspMsgSize, int32_t maxTablePerVnode,
int32_t code) { int32_t code) {
*pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_METRIC_META_RSP, rspMsgSize); *pStart = taosBuildRspMsgWithSize(pConn->thandle, TSDB_MSG_TYPE_METRIC_META_RSP, rspMsgSize);
...@@ -1144,10 +1144,10 @@ static int32_t mgmtBuildMetricMetaRspMsg(SConnObj *pConn, SMetricMetaMsg *pMetri ...@@ -1144,10 +1144,10 @@ static int32_t mgmtBuildMetricMetaRspMsg(SConnObj *pConn, SMetricMetaMsg *pMetri
int32_t msgLen = 0; int32_t msgLen = 0;
*(int16_t *)pMsg = htons(pMetricMetaMsg->numOfMeters); *(int16_t *)pMsg = htons(pSuperTableMetaMsg->numOfMeters);
pMsg += sizeof(int16_t); pMsg += sizeof(int16_t);
for (int32_t j = 0; j < pMetricMetaMsg->numOfMeters; ++j) { for (int32_t j = 0; j < pSuperTableMetaMsg->numOfMeters; ++j) {
SVnodeSidList *pList = NULL; SVnodeSidList *pList = NULL;
int ovgId = -1; int ovgId = -1;
...@@ -1159,11 +1159,11 @@ static int32_t mgmtBuildMetricMetaRspMsg(SConnObj *pConn, SMetricMetaMsg *pMetri ...@@ -1159,11 +1159,11 @@ static int32_t mgmtBuildMetricMetaRspMsg(SConnObj *pConn, SMetricMetaMsg *pMetri
pMsg = (char *)pMeta + sizeof(SMetricMeta); pMsg = (char *)pMeta + sizeof(SMetricMeta);
SMetricMetaElemMsg *pElem = (SMetricMetaElemMsg *)((char *)pMetricMetaMsg + pMetricMetaMsg->metaElem[j]); SMetricMetaElemMsg *pElem = (SMetricMetaElemMsg *)((char *)pSuperTableMetaMsg + pSuperTableMetaMsg->metaElem[j]);
for (int32_t i = 0; i < pResult[j].num; ++i) { for (int32_t i = 0; i < pResult[j].num; ++i) {
STabObj *pMeter = pResult[j].pRes[i]; STabObj *pTable = pResult[j].pRes[i];
pMsg = mgmtBuildMetricMetaMsg(pConn, pMeter, &ovgId, &pList, pMeta, tagLen[j], pElem->numOfTags, pElem->tagCols, pMsg = mgmtBuildMetricMetaMsg(pConn, pTable, &ovgId, &pList, pMeta, tagLen[j], pElem->numOfTags, pElem->tagCols,
maxTablePerVnode, pMsg); maxTablePerVnode, pMsg);
} }
...@@ -1179,7 +1179,7 @@ static int32_t mgmtBuildMetricMetaRspMsg(SConnObj *pConn, SMetricMetaMsg *pMetri ...@@ -1179,7 +1179,7 @@ static int32_t mgmtBuildMetricMetaRspMsg(SConnObj *pConn, SMetricMetaMsg *pMetri
return msgLen; return msgLen;
} }
int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pMetricMetaMsg) { int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SSuperTableMetaMsg *pSuperTableMetaMsg) {
/* /*
* naive method: Do not limit the maximum number of meters in each * naive method: Do not limit the maximum number of meters in each
* vnode(subquery), split the result according to vnodes * vnode(subquery), split the result according to vnodes
...@@ -1190,8 +1190,8 @@ int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pMetr ...@@ -1190,8 +1190,8 @@ int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pMetr
int32_t maxMetersPerVNodeForQuery = INT32_MAX; int32_t maxMetersPerVNodeForQuery = INT32_MAX;
int msgLen = 0; int msgLen = 0;
int ret = TSDB_CODE_SUCCESS; int ret = TSDB_CODE_SUCCESS;
tQueryResultset *result = calloc(1, pMetricMetaMsg->numOfMeters * sizeof(tQueryResultset)); tQueryResultset *result = calloc(1, pSuperTableMetaMsg->numOfMeters * sizeof(tQueryResultset));
int32_t * tagLen = calloc(1, sizeof(int32_t) * pMetricMetaMsg->numOfMeters); int32_t * tagLen = calloc(1, sizeof(int32_t) * pSuperTableMetaMsg->numOfMeters);
if (result == NULL || tagLen == NULL) { if (result == NULL || tagLen == NULL) {
tfree(result); tfree(result);
...@@ -1199,11 +1199,11 @@ int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pMetr ...@@ -1199,11 +1199,11 @@ int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pMetr
return -1; return -1;
} }
for (int32_t i = 0; i < pMetricMetaMsg->numOfMeters; ++i) { for (int32_t i = 0; i < pSuperTableMetaMsg->numOfMeters; ++i) {
SMetricMetaElemMsg *pElem = doConvertMetricMetaMsg(pMetricMetaMsg, i); SMetricMetaElemMsg *pElem = doConvertMetricMetaMsg(pSuperTableMetaMsg, i);
STabObj * pMetric = mgmtGetMeter(pElem->meterId); STabObj * pMetric = mgmtGetTable(pElem->meterId);
if (!mgmtIsMetric(pMetric)) { if (!mgmtIsSuperTable(pMetric)) {
ret = TSDB_CODE_NOT_SUPER_TABLE; ret = TSDB_CODE_NOT_SUPER_TABLE;
break; break;
} }
...@@ -1216,9 +1216,9 @@ int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pMetr ...@@ -1216,9 +1216,9 @@ int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pMetr
int64_t num = 0; int64_t num = 0;
int32_t index = 0; int32_t index = 0;
for (int32_t i = 0; i < pMetricMetaMsg->numOfMeters; ++i) { for (int32_t i = 0; i < pSuperTableMetaMsg->numOfMeters; ++i) {
SMetricMetaElemMsg *pElem = (SMetricMetaElemMsg*) ((char *) pMetricMetaMsg + pMetricMetaMsg->metaElem[i]); SMetricMetaElemMsg *pElem = (SMetricMetaElemMsg*) ((char *) pSuperTableMetaMsg + pSuperTableMetaMsg->metaElem[i]);
STabObj *pMetric = mgmtGetMeter(pElem->meterId); STabObj *pMetric = mgmtGetTable(pElem->meterId);
if (pMetric->pSkipList->nSize > num) { if (pMetric->pSkipList->nSize > num) {
index = i; index = i;
...@@ -1229,32 +1229,32 @@ int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pMetr ...@@ -1229,32 +1229,32 @@ int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pMetr
if (ret == TSDB_CODE_SUCCESS) { if (ret == TSDB_CODE_SUCCESS) {
// todo opt performance // todo opt performance
for (int32_t i = 0; i < pMetricMetaMsg->numOfMeters; ++i) { for (int32_t i = 0; i < pSuperTableMetaMsg->numOfMeters; ++i) {
ret = mgmtRetrieveMetersFromMetric(pMetricMetaMsg, i, &result[i]); ret = mgmtRetrieveMetersFromSuperTable(pSuperTableMetaMsg, i, &result[i]);
} }
} }
if (ret == TSDB_CODE_SUCCESS) { if (ret == TSDB_CODE_SUCCESS) {
ret = mgmtDoJoin(pMetricMetaMsg, result); ret = mgmtDoJoin(pSuperTableMetaMsg, result);
} }
if (ret == TSDB_CODE_SUCCESS) { if (ret == TSDB_CODE_SUCCESS) {
for (int32_t i = 0; i < pMetricMetaMsg->numOfMeters; ++i) { for (int32_t i = 0; i < pSuperTableMetaMsg->numOfMeters; ++i) {
mgmtReorganizeMetersInMetricMeta(pMetricMetaMsg, i, &result[i]); mgmtReorganizeMetersInMetricMeta(pSuperTableMetaMsg, i, &result[i]);
} }
} }
if (ret == TSDB_CODE_SUCCESS) { if (ret == TSDB_CODE_SUCCESS) {
for (int32_t i = 0; i < pMetricMetaMsg->numOfMeters; ++i) { for (int32_t i = 0; i < pSuperTableMetaMsg->numOfMeters; ++i) {
msgLen += mgmtGetMetricMetaMsgSize(&result[i], tagLen[i], maxMetersPerVNodeForQuery); msgLen += mgmtGetMetricMetaMsgSize(&result[i], tagLen[i], maxMetersPerVNodeForQuery);
} }
} else { } else {
msgLen = 512; msgLen = 512;
} }
msgLen = mgmtBuildMetricMetaRspMsg(pConn, pMetricMetaMsg, result, pStart, tagLen, msgLen, maxMetersPerVNodeForQuery, ret); msgLen = mgmtBuildMetricMetaRspMsg(pConn, pSuperTableMetaMsg, result, pStart, tagLen, msgLen, maxMetersPerVNodeForQuery, ret);
for (int32_t i = 0; i < pMetricMetaMsg->numOfMeters; ++i) { for (int32_t i = 0; i < pSuperTableMetaMsg->numOfMeters; ++i) {
tQueryResultClean(&result[i]); tQueryResultClean(&result[i]);
} }
...@@ -1266,7 +1266,7 @@ int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pMetr ...@@ -1266,7 +1266,7 @@ int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SMetricMetaMsg *pMetr
int mgmtRetrieveMeters(SShowObj *pShow, char *data, int rows, SConnObj *pConn) { int mgmtRetrieveMeters(SShowObj *pShow, char *data, int rows, SConnObj *pConn) {
int numOfRows = 0; int numOfRows = 0;
STabObj *pMeter = NULL; STabObj *pTable = NULL;
char * pWrite; char * pWrite;
int cols = 0; int cols = 0;
int prefixLen; int prefixLen;
...@@ -1291,19 +1291,19 @@ int mgmtRetrieveMeters(SShowObj *pShow, char *data, int rows, SConnObj *pConn) { ...@@ -1291,19 +1291,19 @@ int mgmtRetrieveMeters(SShowObj *pShow, char *data, int rows, SConnObj *pConn) {
char meterName[TSDB_METER_NAME_LEN] = {0}; char meterName[TSDB_METER_NAME_LEN] = {0};
while (numOfRows < rows) { while (numOfRows < rows) {
pShow->pNode = sdbFetchRow(meterSdb, pShow->pNode, (void **)&pMeter); pShow->pNode = sdbFetchRow(meterSdb, pShow->pNode, (void **)&pTable);
if (pMeter == NULL) break; if (pTable == NULL) break;
if (mgmtIsMetric(pMeter)) continue; if (mgmtIsSuperTable(pTable)) continue;
// not belong to current db // not belong to current db
if (strncmp(pMeter->meterId, prefix, prefixLen)) continue; if (strncmp(pTable->meterId, prefix, prefixLen)) continue;
numOfRead++; numOfRead++;
memset(meterName, 0, tListLen(meterName)); memset(meterName, 0, tListLen(meterName));
// pattern compare for meter name // pattern compare for meter name
extractTableName(pMeter->meterId, meterName); extractTableName(pTable->meterId, meterName);
if (pShow->payloadLen > 0 && if (pShow->payloadLen > 0 &&
patternMatch(pShow->payload, meterName, TSDB_METER_NAME_LEN, &info) != TSDB_PATTERN_MATCH) patternMatch(pShow->payload, meterName, TSDB_METER_NAME_LEN, &info) != TSDB_PATTERN_MATCH)
...@@ -1316,16 +1316,16 @@ int mgmtRetrieveMeters(SShowObj *pShow, char *data, int rows, SConnObj *pConn) { ...@@ -1316,16 +1316,16 @@ int mgmtRetrieveMeters(SShowObj *pShow, char *data, int rows, SConnObj *pConn) {
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int64_t *)pWrite = pMeter->createdTime; *(int64_t *)pWrite = pTable->createdTime;
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int16_t *)pWrite = pMeter->numOfColumns; *(int16_t *)pWrite = pTable->numOfColumns;
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
if (pMeter->pTagData) { if (pTable->pTagData) {
extractTableName(pMeter->pTagData, pWrite); extractTableName(pTable->pTagData, pWrite);
} }
cols++; cols++;
...@@ -1455,7 +1455,7 @@ int mgmtRetrieveMetrics(SShowObj *pShow, char *data, int rows, SConnObj *pConn) ...@@ -1455,7 +1455,7 @@ int mgmtRetrieveMetrics(SShowObj *pShow, char *data, int rows, SConnObj *pConn)
} }
int32_t mgmtFindTagCol(STabObj *pMetric, const char *tagName) { int32_t mgmtFindTagCol(STabObj *pMetric, const char *tagName) {
if (!mgmtIsMetric(pMetric)) return -1; if (!mgmtIsSuperTable(pMetric)) return -1;
SSchema *schema = NULL; SSchema *schema = NULL;
...@@ -1474,7 +1474,7 @@ int32_t mgmtMeterModifyTagNameByCol(STabObj *pMetric, uint32_t col, const char * ...@@ -1474,7 +1474,7 @@ int32_t mgmtMeterModifyTagNameByCol(STabObj *pMetric, uint32_t col, const char *
uint32_t len = strlen(nname); uint32_t len = strlen(nname);
if (pMetric == NULL || (!mgmtIsMetric(pMetric)) || col >= pMetric->numOfTags || len >= TSDB_COL_NAME_LEN || if (pMetric == NULL || (!mgmtIsSuperTable(pMetric)) || col >= pMetric->numOfTags || len >= TSDB_COL_NAME_LEN ||
mgmtFindTagCol(pMetric, nname) >= 0) mgmtFindTagCol(pMetric, nname) >= 0)
return TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR;
...@@ -1503,7 +1503,7 @@ int32_t mgmtMeterModifyTagNameByCol(STabObj *pMetric, uint32_t col, const char * ...@@ -1503,7 +1503,7 @@ int32_t mgmtMeterModifyTagNameByCol(STabObj *pMetric, uint32_t col, const char *
} }
int32_t mgmtMeterModifyTagNameByName(STabObj *pMetric, const char *oname, const char *nname) { int32_t mgmtMeterModifyTagNameByName(STabObj *pMetric, const char *oname, const char *nname) {
if (pMetric == NULL || (!mgmtIsMetric(pMetric))) return TSDB_CODE_APP_ERROR; if (pMetric == NULL || (!mgmtIsSuperTable(pMetric))) return TSDB_CODE_APP_ERROR;
int index = mgmtFindTagCol(pMetric, oname); int index = mgmtFindTagCol(pMetric, oname);
if (index < 0) { if (index < 0) {
...@@ -1515,11 +1515,11 @@ int32_t mgmtMeterModifyTagNameByName(STabObj *pMetric, const char *oname, const ...@@ -1515,11 +1515,11 @@ int32_t mgmtMeterModifyTagNameByName(STabObj *pMetric, const char *oname, const
return mgmtMeterModifyTagNameByCol(pMetric, index, nname); return mgmtMeterModifyTagNameByCol(pMetric, index, nname);
} }
int32_t mgmtMeterModifyTagValueByCol(STabObj *pMeter, int col, const char *nContent) { int32_t mgmtMeterModifyTagValueByCol(STabObj *pTable, int col, const char *nContent) {
int rowSize = 0; int rowSize = 0;
if (pMeter == NULL || nContent == NULL || (!mgmtMeterCreateFromMetric(pMeter))) return TSDB_CODE_APP_ERROR; if (pTable == NULL || nContent == NULL || (!mgmtTableCreateFromSuperTable(pTable))) return TSDB_CODE_APP_ERROR;
STabObj *pMetric = mgmtGetMeter(pMeter->pTagData); STabObj *pMetric = mgmtGetTable(pTable->pTagData);
assert(pMetric != NULL); assert(pMetric != NULL);
if (col < 0 || col > pMetric->numOfTags) return TSDB_CODE_APP_ERROR; if (col < 0 || col > pMetric->numOfTags) return TSDB_CODE_APP_ERROR;
...@@ -1527,12 +1527,12 @@ int32_t mgmtMeterModifyTagValueByCol(STabObj *pMeter, int col, const char *nCont ...@@ -1527,12 +1527,12 @@ int32_t mgmtMeterModifyTagValueByCol(STabObj *pMeter, int col, const char *nCont
SSchema *schema = (SSchema *)(pMetric->schema + (pMetric->numOfColumns + col) * sizeof(SSchema)); SSchema *schema = (SSchema *)(pMetric->schema + (pMetric->numOfColumns + col) * sizeof(SSchema));
if (col == 0) { if (col == 0) {
pMeter->isDirty = 1; pTable->isDirty = 1;
removeMeterFromMetricIndex(pMetric, pMeter); removeMeterFromMetricIndex(pMetric, pTable);
} }
memcpy(pMeter->pTagData + mgmtGetTagsLength(pMetric, col) + TSDB_METER_ID_LEN, nContent, schema->bytes); memcpy(pTable->pTagData + mgmtGetTagsLength(pMetric, col) + TSDB_TABLE_ID_LEN, nContent, schema->bytes);
if (col == 0) { if (col == 0) {
addMeterIntoMetricIndex(pMetric, pMeter); addMeterIntoMetricIndex(pMetric, pTable);
} }
// Encode the string // Encode the string
...@@ -1544,37 +1544,37 @@ int32_t mgmtMeterModifyTagValueByCol(STabObj *pMeter, int col, const char *nCont ...@@ -1544,37 +1544,37 @@ int32_t mgmtMeterModifyTagValueByCol(STabObj *pMeter, int col, const char *nCont
} }
memset(msg, 0, size); memset(msg, 0, size);
mgmtMeterActionEncode(pMeter, msg, size, &rowSize); mgmtMeterActionEncode(pTable, msg, size, &rowSize);
int32_t ret = sdbUpdateRow(meterSdb, msg, rowSize, 1); // Need callback function int32_t ret = sdbUpdateRow(meterSdb, msg, rowSize, 1); // Need callback function
tfree(msg); tfree(msg);
if (pMeter->isDirty) pMeter->isDirty = 0; if (pTable->isDirty) pTable->isDirty = 0;
if (ret < 0) { if (ret < 0) {
mError("Failed to modify tag column %d of table %s", col, pMeter->meterId); mError("Failed to modify tag column %d of table %s", col, pTable->meterId);
return TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR;
} }
mTrace("Succeed to modify tag column %d of table %s", col, pMeter->meterId); mTrace("Succeed to modify tag column %d of table %s", col, pTable->meterId);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t mgmtMeterModifyTagValueByName(STabObj *pMeter, char *tagName, char *nContent) { int32_t mgmtMeterModifyTagValueByName(STabObj *pTable, char *tagName, char *nContent) {
if (pMeter == NULL || tagName == NULL || nContent == NULL || (!mgmtMeterCreateFromMetric(pMeter))) if (pTable == NULL || tagName == NULL || nContent == NULL || (!mgmtTableCreateFromSuperTable(pTable)))
return TSDB_CODE_INVALID_MSG_TYPE; return TSDB_CODE_INVALID_MSG_TYPE;
STabObj *pMetric = mgmtGetMeter(pMeter->pTagData); STabObj *pMetric = mgmtGetTable(pTable->pTagData);
if (pMetric == NULL) return TSDB_CODE_APP_ERROR; if (pMetric == NULL) return TSDB_CODE_APP_ERROR;
int col = mgmtFindTagCol(pMetric, tagName); int col = mgmtFindTagCol(pMetric, tagName);
if (col < 0) return TSDB_CODE_APP_ERROR; if (col < 0) return TSDB_CODE_APP_ERROR;
return mgmtMeterModifyTagValueByCol(pMeter, col, nContent); return mgmtMeterModifyTagValueByCol(pTable, col, nContent);
} }
int32_t mgmtMeterAddTags(STabObj *pMetric, SSchema schema[], int ntags) { int32_t mgmtMeterAddTags(STabObj *pMetric, SSchema schema[], int ntags) {
if (pMetric == NULL || (!mgmtIsMetric(pMetric))) return TSDB_CODE_INVALID_TABLE; if (pMetric == NULL || (!mgmtIsSuperTable(pMetric))) return TSDB_CODE_INVALID_TABLE;
if (pMetric->numOfTags + ntags > TSDB_MAX_TAGS) return TSDB_CODE_APP_ERROR; if (pMetric->numOfTags + ntags > TSDB_MAX_TAGS) return TSDB_CODE_APP_ERROR;
...@@ -1597,7 +1597,7 @@ int32_t mgmtMeterAddTags(STabObj *pMetric, SSchema schema[], int ntags) { ...@@ -1597,7 +1597,7 @@ int32_t mgmtMeterAddTags(STabObj *pMetric, SSchema schema[], int ntags) {
SMeterBatchUpdateMsg *msg = (SMeterBatchUpdateMsg *)malloc(size); SMeterBatchUpdateMsg *msg = (SMeterBatchUpdateMsg *)malloc(size);
memset(msg, 0, size); memset(msg, 0, size);
memcpy(msg->meterId, pMetric->meterId, TSDB_METER_ID_LEN); memcpy(msg->meterId, pMetric->meterId, TSDB_TABLE_ID_LEN);
msg->type = SDB_TYPE_INSERT; msg->type = SDB_TYPE_INSERT;
msg->cols = ntags; msg->cols = ntags;
memcpy(msg->data, schema, sizeof(SSchema) * ntags); memcpy(msg->data, schema, sizeof(SSchema) * ntags);
...@@ -1615,19 +1615,19 @@ int32_t mgmtMeterAddTags(STabObj *pMetric, SSchema schema[], int ntags) { ...@@ -1615,19 +1615,19 @@ int32_t mgmtMeterAddTags(STabObj *pMetric, SSchema schema[], int ntags) {
} }
int32_t mgmtMeterDropTagByCol(STabObj *pMetric, int col) { int32_t mgmtMeterDropTagByCol(STabObj *pMetric, int col) {
if (pMetric == NULL || (!mgmtIsMetric(pMetric)) || col <= 0 || col >= pMetric->numOfTags) return TSDB_CODE_APP_ERROR; if (pMetric == NULL || (!mgmtIsSuperTable(pMetric)) || col <= 0 || col >= pMetric->numOfTags) return TSDB_CODE_APP_ERROR;
// Pack message to do batch update // Pack message to do batch update
uint32_t size = sizeof(SMeterBatchUpdateMsg) + sizeof(SchemaUnit); uint32_t size = sizeof(SMeterBatchUpdateMsg) + sizeof(SchemaUnit);
SMeterBatchUpdateMsg *msg = (SMeterBatchUpdateMsg *)malloc(size); SMeterBatchUpdateMsg *msg = (SMeterBatchUpdateMsg *)malloc(size);
memset(msg, 0, size); memset(msg, 0, size);
memcpy(msg->meterId, pMetric->meterId, TSDB_METER_ID_LEN); memcpy(msg->meterId, pMetric->meterId, TSDB_TABLE_ID_LEN);
msg->type = SDB_TYPE_DELETE; // TODO: what should here be ? msg->type = SDB_TYPE_DELETE; // TODO: what should here be ?
msg->cols = 1; msg->cols = 1;
((SchemaUnit *)(msg->data))->col = col; ((SchemaUnit *)(msg->data))->col = col;
((SchemaUnit *)(msg->data))->pos = mgmtGetTagsLength(pMetric, col) + TSDB_METER_ID_LEN; ((SchemaUnit *)(msg->data))->pos = mgmtGetTagsLength(pMetric, col) + TSDB_TABLE_ID_LEN;
((SchemaUnit *)(msg->data))->schema = *(SSchema *)(pMetric->schema + sizeof(SSchema) * (pMetric->numOfColumns + col)); ((SchemaUnit *)(msg->data))->schema = *(SSchema *)(pMetric->schema + sizeof(SSchema) * (pMetric->numOfColumns + col));
int32_t ret = sdbBatchUpdateRow(meterSdb, msg, size); int32_t ret = sdbBatchUpdateRow(meterSdb, msg, size);
...@@ -1643,7 +1643,7 @@ int32_t mgmtMeterDropTagByCol(STabObj *pMetric, int col) { ...@@ -1643,7 +1643,7 @@ int32_t mgmtMeterDropTagByCol(STabObj *pMetric, int col) {
} }
int32_t mgmtMeterDropTagByName(STabObj *pMetric, char *name) { int32_t mgmtMeterDropTagByName(STabObj *pMetric, char *name) {
if (pMetric == NULL || (!mgmtIsMetric(pMetric))) { if (pMetric == NULL || (!mgmtIsSuperTable(pMetric))) {
mTrace("Failed to drop tag name: %s from table: %s", name, pMetric->meterId); mTrace("Failed to drop tag name: %s from table: %s", name, pMetric->meterId);
return TSDB_CODE_INVALID_TABLE; return TSDB_CODE_INVALID_TABLE;
} }
...@@ -1653,22 +1653,22 @@ int32_t mgmtMeterDropTagByName(STabObj *pMetric, char *name) { ...@@ -1653,22 +1653,22 @@ int32_t mgmtMeterDropTagByName(STabObj *pMetric, char *name) {
return mgmtMeterDropTagByCol(pMetric, col); return mgmtMeterDropTagByCol(pMetric, col);
} }
int32_t mgmtFindColumnIndex(STabObj *pMeter, const char *colName) { int32_t mgmtFindColumnIndex(STabObj *pTable, const char *colName) {
STabObj *pMetric = NULL; STabObj *pMetric = NULL;
SSchema *schema = NULL; SSchema *schema = NULL;
if (pMeter->meterType == TSDB_METER_OTABLE || pMeter->meterType == TSDB_METER_METRIC) { if (pTable->tableType == TSDB_TABLE_TYPE_NORMAL_TABLE || pTable->tableType == TSDB_TABLE_TYPE_SUPER_TABLE) {
schema = (SSchema *)pMeter->schema; schema = (SSchema *)pTable->schema;
for (int32_t i = 0; i < pMeter->numOfColumns; i++) { for (int32_t i = 0; i < pTable->numOfColumns; i++) {
if (strcasecmp(schema[i].name, colName) == 0) { if (strcasecmp(schema[i].name, colName) == 0) {
return i; return i;
} }
} }
} else if (pMeter->meterType == TSDB_METER_MTABLE) { } else if (pTable->tableType == TSDB_TABLE_TYPE_CREATE_FROM_STABLE) {
pMetric = mgmtGetMeter(pMeter->pTagData); pMetric = mgmtGetTable(pTable->pTagData);
if (pMetric == NULL) { if (pMetric == NULL) {
mError("MTable not belongs to any metric, meter: %s", pMeter->meterId); mError("MTable not belongs to any metric, meter: %s", pTable->meterId);
return -1; return -1;
} }
schema = (SSchema *)pMetric->schema; schema = (SSchema *)pMetric->schema;
...@@ -1682,20 +1682,20 @@ int32_t mgmtFindColumnIndex(STabObj *pMeter, const char *colName) { ...@@ -1682,20 +1682,20 @@ int32_t mgmtFindColumnIndex(STabObj *pMeter, const char *colName) {
return -1; return -1;
} }
int32_t mgmtMeterAddColumn(STabObj *pMeter, SSchema schema[], int ncols) { int32_t mgmtMeterAddColumn(STabObj *pTable, SSchema schema[], int ncols) {
SAcctObj *pAcct = NULL; SAcctObj *pAcct = NULL;
SDbObj * pDb = NULL; SDbObj * pDb = NULL;
if (pMeter == NULL || pMeter->meterType == TSDB_METER_MTABLE || pMeter->meterType == TSDB_METER_STABLE || ncols <= 0) if (pTable == NULL || pTable->tableType == TSDB_TABLE_TYPE_CREATE_FROM_STABLE || pTable->tableType == TSDB_TABLE_TYPE_STREAM_TABLE || ncols <= 0)
return TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR;
// ASSUMPTION: no two tags are the same // ASSUMPTION: no two tags are the same
for (int i = 0; i < ncols; i++) for (int i = 0; i < ncols; i++)
if (mgmtFindColumnIndex(pMeter, schema[i].name) > 0) return TSDB_CODE_APP_ERROR; if (mgmtFindColumnIndex(pTable, schema[i].name) > 0) return TSDB_CODE_APP_ERROR;
pDb = mgmtGetDbByMeterId(pMeter->meterId); pDb = mgmtGetDbByMeterId(pTable->meterId);
if (pDb == NULL) { if (pDb == NULL) {
mError("meter: %s not belongs to any database", pMeter->meterId); mError("meter: %s not belongs to any database", pTable->meterId);
return TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR;
} }
...@@ -1705,33 +1705,33 @@ int32_t mgmtMeterAddColumn(STabObj *pMeter, SSchema schema[], int ncols) { ...@@ -1705,33 +1705,33 @@ int32_t mgmtMeterAddColumn(STabObj *pMeter, SSchema schema[], int ncols) {
return TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR;
} }
pMeter->schema = realloc(pMeter->schema, pMeter->schemaSize + sizeof(SSchema) * ncols); pTable->schema = realloc(pTable->schema, pTable->schemaSize + sizeof(SSchema) * ncols);
if (pMeter->meterType == TSDB_METER_OTABLE) { if (pTable->tableType == TSDB_TABLE_TYPE_NORMAL_TABLE) {
memcpy(pMeter->schema + pMeter->schemaSize, schema, sizeof(SSchema) * ncols); memcpy(pTable->schema + pTable->schemaSize, schema, sizeof(SSchema) * ncols);
} else if (pMeter->meterType == TSDB_METER_METRIC) { } else if (pTable->tableType == TSDB_TABLE_TYPE_SUPER_TABLE) {
memmove(pMeter->schema + sizeof(SSchema) * (pMeter->numOfColumns + ncols), memmove(pTable->schema + sizeof(SSchema) * (pTable->numOfColumns + ncols),
pMeter->schema + sizeof(SSchema) * pMeter->numOfColumns, sizeof(SSchema) * pMeter->numOfTags); pTable->schema + sizeof(SSchema) * pTable->numOfColumns, sizeof(SSchema) * pTable->numOfTags);
memcpy(pMeter->schema + sizeof(SSchema) * pMeter->numOfColumns, schema, sizeof(SSchema) * ncols); memcpy(pTable->schema + sizeof(SSchema) * pTable->numOfColumns, schema, sizeof(SSchema) * ncols);
} }
SSchema *tschema = (SSchema *)(pMeter->schema + sizeof(SSchema) * pMeter->numOfColumns); SSchema *tschema = (SSchema *)(pTable->schema + sizeof(SSchema) * pTable->numOfColumns);
for (int i = 0; i < ncols; i++) tschema[i].colId = pMeter->nextColId++; for (int i = 0; i < ncols; i++) tschema[i].colId = pTable->nextColId++;
pMeter->schemaSize += sizeof(SSchema) * ncols; pTable->schemaSize += sizeof(SSchema) * ncols;
pMeter->numOfColumns += ncols; pTable->numOfColumns += ncols;
pMeter->sversion++; pTable->sversion++;
if (mgmtIsNormalMeter(pMeter)) if (mgmtIsNormalTable(pTable))
pAcct->acctInfo.numOfTimeSeries += ncols; pAcct->acctInfo.numOfTimeSeries += ncols;
else else
pAcct->acctInfo.numOfTimeSeries += (ncols * pMeter->numOfMeters); pAcct->acctInfo.numOfTimeSeries += (ncols * pTable->numOfMeters);
sdbUpdateRow(meterSdb, pMeter, 0, 1); sdbUpdateRow(meterSdb, pTable, 0, 1);
if (pMeter->meterType == TSDB_METER_METRIC) { if (pTable->tableType == TSDB_TABLE_TYPE_SUPER_TABLE) {
for (STabObj *pObj = pMeter->pHead; pObj != NULL; pObj = pObj->next) { for (STabObj *pObj = pTable->pHead; pObj != NULL; pObj = pObj->next) {
pObj->numOfColumns++; pObj->numOfColumns++;
pObj->nextColId = pMeter->nextColId; pObj->nextColId = pTable->nextColId;
pObj->sversion = pMeter->sversion; pObj->sversion = pTable->sversion;
sdbUpdateRow(meterSdb, pObj, 0, 1); sdbUpdateRow(meterSdb, pObj, 0, 1);
} }
} }
...@@ -1739,19 +1739,19 @@ int32_t mgmtMeterAddColumn(STabObj *pMeter, SSchema schema[], int ncols) { ...@@ -1739,19 +1739,19 @@ int32_t mgmtMeterAddColumn(STabObj *pMeter, SSchema schema[], int ncols) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t mgmtMeterDropColumnByName(STabObj *pMeter, const char *name) { int32_t mgmtMeterDropColumnByName(STabObj *pTable, const char *name) {
SAcctObj *pAcct = NULL; SAcctObj *pAcct = NULL;
SDbObj * pDb = NULL; SDbObj * pDb = NULL;
if (pMeter == NULL || pMeter->meterType == TSDB_METER_MTABLE || pMeter->meterType == TSDB_METER_STABLE) if (pTable == NULL || pTable->tableType == TSDB_TABLE_TYPE_CREATE_FROM_STABLE || pTable->tableType == TSDB_TABLE_TYPE_STREAM_TABLE)
return TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR;
int32_t index = mgmtFindColumnIndex(pMeter, name); int32_t index = mgmtFindColumnIndex(pTable, name);
if (index < 0) return TSDB_CODE_APP_ERROR; if (index < 0) return TSDB_CODE_APP_ERROR;
pDb = mgmtGetDbByMeterId(pMeter->meterId); pDb = mgmtGetDbByMeterId(pTable->meterId);
if (pDb == NULL) { if (pDb == NULL) {
mError("meter: %s not belongs to any database", pMeter->meterId); mError("meter: %s not belongs to any database", pTable->meterId);
return TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR;
} }
...@@ -1761,28 +1761,28 @@ int32_t mgmtMeterDropColumnByName(STabObj *pMeter, const char *name) { ...@@ -1761,28 +1761,28 @@ int32_t mgmtMeterDropColumnByName(STabObj *pMeter, const char *name) {
return TSDB_CODE_APP_ERROR; return TSDB_CODE_APP_ERROR;
} }
if (pMeter->meterType == TSDB_METER_OTABLE) { if (pTable->tableType == TSDB_TABLE_TYPE_NORMAL_TABLE) {
memmove(pMeter->schema + sizeof(SSchema) * index, pMeter->schema + sizeof(SSchema) * (index + 1), memmove(pTable->schema + sizeof(SSchema) * index, pTable->schema + sizeof(SSchema) * (index + 1),
sizeof(SSchema) * (pMeter->numOfColumns - index - 1)); sizeof(SSchema) * (pTable->numOfColumns - index - 1));
} else if (pMeter->meterType == TSDB_METER_METRIC) { } else if (pTable->tableType == TSDB_TABLE_TYPE_SUPER_TABLE) {
memmove(pMeter->schema + sizeof(SSchema) * index, pMeter->schema + sizeof(SSchema) * (index + 1), memmove(pTable->schema + sizeof(SSchema) * index, pTable->schema + sizeof(SSchema) * (index + 1),
sizeof(SSchema) * (pMeter->numOfColumns + pMeter->numOfTags - index - 1)); sizeof(SSchema) * (pTable->numOfColumns + pTable->numOfTags - index - 1));
} }
pMeter->schemaSize -= sizeof(SSchema); pTable->schemaSize -= sizeof(SSchema);
pMeter->numOfColumns--; pTable->numOfColumns--;
if (mgmtIsNormalMeter(pMeter)) if (mgmtIsNormalTable(pTable))
pAcct->acctInfo.numOfTimeSeries--; pAcct->acctInfo.numOfTimeSeries--;
else else
pAcct->acctInfo.numOfTimeSeries -= (pMeter->numOfMeters); pAcct->acctInfo.numOfTimeSeries -= (pTable->numOfMeters);
pMeter->schema = realloc(pMeter->schema, pMeter->schemaSize); pTable->schema = realloc(pTable->schema, pTable->schemaSize);
pMeter->sversion++; pTable->sversion++;
sdbUpdateRow(meterSdb, pMeter, 0, 1); sdbUpdateRow(meterSdb, pTable, 0, 1);
if (pMeter->meterType == TSDB_METER_METRIC) { if (pTable->tableType == TSDB_TABLE_TYPE_SUPER_TABLE) {
for (STabObj *pObj = pMeter->pHead; pObj != NULL; pObj = pObj->next) { for (STabObj *pObj = pTable->pHead; pObj != NULL; pObj = pObj->next) {
pObj->numOfColumns--; pObj->numOfColumns--;
pObj->sversion = pMeter->sversion; pObj->sversion = pTable->sversion;
sdbUpdateRow(meterSdb, pObj, 0, 1); sdbUpdateRow(meterSdb, pObj, 0, 1);
} }
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "mgmt.h" #include "mnode.h"
#include "mgmtGrant.h" #include "mgmtGrant.h"
#include "mgmtAcct.h" #include "mgmtAcct.h"
#include "tschemautil.h" #include "tschemautil.h"
......
...@@ -15,71 +15,54 @@ ...@@ -15,71 +15,54 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "mnode.h"
#include "mgmt.h"
#include "mgmtUtil.h" #include "mgmtUtil.h"
#include "textbuffer.h"
#include "tschemautil.h" #include "tschemautil.h"
#include "tsqlfunction.h"
#include "vnodeTagMgmt.h"
extern int cksumsize;
uint64_t mgmtGetCheckSum(FILE* fp, int offset) {
uint64_t checksum = 0;
uint64_t data;
int bytes;
while (1) {
data = 0;
bytes = fread(&data, sizeof(data), 1, fp);
if (bytes != sizeof(data)) break;
checksum += data; bool mgmtTableCreateFromSuperTable(STabObj* pTableObj) {
} return pTableObj->tableType == TSDB_TABLE_TYPE_CREATE_FROM_STABLE;
return checksum;
} }
bool mgmtMeterCreateFromMetric(STabObj* pMeterObj) { return pMeterObj->meterType == TSDB_METER_MTABLE; } bool mgmtIsSuperTable(STabObj* pTableObj) {
return pTableObj->tableType == TSDB_TABLE_TYPE_SUPER_TABLE;
bool mgmtIsMetric(STabObj* pMeterObj) { return pMeterObj->meterType == TSDB_METER_METRIC; } }
bool mgmtIsNormalMeter(STabObj* pMeterObj) { return !mgmtIsMetric(pMeterObj); } bool mgmtIsNormalTable(STabObj* pTableObj) {
return !mgmtIsSuperTable(pTableObj);
}
/** /**
* TODO: the tag offset value should be kept in memory to avoid dynamically calculating the value * TODO: the tag offset value should be kept in memory to avoid dynamically calculating the value
* *
* @param pMeter * @param pTable
* @param col * @param col
* @param pTagColSchema * @param pTagColSchema
* @return * @return
*/ */
char* mgmtMeterGetTag(STabObj* pMeter, int32_t col, SSchema* pTagColSchema) { char* mgmtTableGetTag(STabObj* pTable, int32_t col, SSchema* pTagColSchema) {
if (!mgmtMeterCreateFromMetric(pMeter)) { if (!mgmtTableCreateFromSuperTable(pTable)) {
return NULL; return NULL;
} }
STabObj* pMetric = mgmtGetMeter(pMeter->pTagData); STabObj* pSuperTable = mgmtGetTable(pTable->pTagData);
int32_t offset = mgmtGetTagsLength(pMetric, col) + TSDB_METER_ID_LEN; int32_t offset = mgmtGetTagsLength(pSuperTable, col) + TSDB_TABLE_ID_LEN;
assert(offset > 0); assert(offset > 0);
if (pTagColSchema != NULL) { if (pTagColSchema != NULL) {
*pTagColSchema = ((SSchema*)pMetric->schema)[pMetric->numOfColumns + col]; *pTagColSchema = ((SSchema*)pSuperTable->schema)[pSuperTable->numOfColumns + col];
} }
return (pMeter->pTagData + offset); return (pTable->pTagData + offset);
} }
int32_t mgmtGetTagsLength(STabObj* pMetric, int32_t col) { // length before column col int32_t mgmtGetTagsLength(STabObj* pSuperTable, int32_t col) { // length before column col
assert(mgmtIsMetric(pMetric) && col >= 0); assert(mgmtIsSuperTable(pSuperTable) && col >= 0);
int32_t len = 0; int32_t len = 0;
int32_t tagColumnIndexOffset = pMetric->numOfColumns; int32_t tagColumnIndexOffset = pSuperTable->numOfColumns;
for (int32_t i = 0; i < pMetric->numOfTags && i < col; ++i) { for (int32_t i = 0; i < pSuperTable->numOfTags && i < col; ++i) {
len += ((SSchema*)pMetric->schema)[tagColumnIndexOffset + i].bytes; len += ((SSchema*)pSuperTable->schema)[tagColumnIndexOffset + i].bytes;
} }
return len; return len;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "mgmt.h" #include "mnode.h"
#include "tschemautil.h" #include "tschemautil.h"
#include "tlog.h" #include "tlog.h"
#include "vnodeStatus.h" #include "vnodeStatus.h"
...@@ -168,13 +168,13 @@ SVgObj *mgmtCreateVgroup(SDbObj *pDb) { ...@@ -168,13 +168,13 @@ SVgObj *mgmtCreateVgroup(SDbObj *pDb) {
} }
int mgmtDropVgroup(SDbObj *pDb, SVgObj *pVgroup) { int mgmtDropVgroup(SDbObj *pDb, SVgObj *pVgroup) {
STabObj *pMeter; STabObj *pTable;
if (pVgroup->numOfMeters > 0) { if (pVgroup->numOfMeters > 0) {
for (int i = 0; i < pDb->cfg.maxSessions; ++i) { for (int i = 0; i < pDb->cfg.maxSessions; ++i) {
if (pVgroup->meterList != NULL) { if (pVgroup->meterList != NULL) {
pMeter = pVgroup->meterList[i]; pTable = pVgroup->meterList[i];
if (pMeter) mgmtDropMeter(pDb, pMeter->meterId, 0); if (pTable) mgmtDropMeter(pDb, pTable->meterId, 0);
} }
} }
} }
...@@ -239,14 +239,14 @@ int mgmtGetVgroupMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { ...@@ -239,14 +239,14 @@ int mgmtGetVgroupMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) {
int maxReplica = 0; int maxReplica = 0;
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
STabObj *pMeter = NULL; STabObj *pTable = NULL;
if (pShow->payloadLen > 0 ) { if (pShow->payloadLen > 0 ) {
pMeter = mgmtGetMeter(pShow->payload); pTable = mgmtGetTable(pShow->payload);
if (NULL == pMeter) { if (NULL == pTable) {
return TSDB_CODE_INVALID_METER_ID; return TSDB_CODE_INVALID_METER_ID;
} }
pVgroup = mgmtGetVgroup(pMeter->gid.vgId); pVgroup = mgmtGetVgroup(pTable->gid.vgId);
if (NULL == pVgroup) return TSDB_CODE_INVALID_METER_ID; if (NULL == pVgroup) return TSDB_CODE_INVALID_METER_ID;
maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica; maxReplica = pVgroup->numOfVnodes > maxReplica ? pVgroup->numOfVnodes : maxReplica;
...@@ -292,7 +292,7 @@ int mgmtGetVgroupMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { ...@@ -292,7 +292,7 @@ int mgmtGetVgroupMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) {
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
if (NULL == pMeter) { if (NULL == pTable) {
pShow->numOfRows = pDb->numOfVgroups; pShow->numOfRows = pDb->numOfVgroups;
pShow->pNode = pDb->pHead; pShow->pNode = pDb->pHead;
} else { } else {
......
...@@ -188,7 +188,7 @@ void dnodeBuildMonitorSql(char *sql, int cmd) { ...@@ -188,7 +188,7 @@ void dnodeBuildMonitorSql(char *sql, int cmd) {
snprintf(sql, SQL_LENGTH, snprintf(sql, SQL_LENGTH,
"create table if not exists %s.slowquery(ts timestamp, username " "create table if not exists %s.slowquery(ts timestamp, username "
"binary(%d), created_time timestamp, time bigint, sql binary(%d))", "binary(%d), created_time timestamp, time bigint, sql binary(%d))",
tsMonitorDbName, TSDB_METER_ID_LEN, TSDB_SHOW_SQL_LEN); tsMonitorDbName, TSDB_TABLE_ID_LEN, TSDB_SHOW_SQL_LEN);
} else if (cmd == MONITOR_CMD_CREATE_TB_LOG) { } else if (cmd == MONITOR_CMD_CREATE_TB_LOG) {
snprintf(sql, SQL_LENGTH, snprintf(sql, SQL_LENGTH,
"create table if not exists %s.log(ts timestamp, level tinyint, " "create table if not exists %s.log(ts timestamp, level tinyint, "
......
...@@ -722,7 +722,7 @@ int taosSetSecurityInfo(int chann, int sid, char *id, int spi, int encrypt, char ...@@ -722,7 +722,7 @@ int taosSetSecurityInfo(int chann, int sid, char *id, int spi, int encrypt, char
pConn->encrypt = encrypt; pConn->encrypt = encrypt;
memcpy(pConn->secret, pConn->secret, TSDB_KEY_LEN); memcpy(pConn->secret, pConn->secret, TSDB_KEY_LEN);
memcpy(pConn->cipheringKey, ckey, TSDB_KEY_LEN); memcpy(pConn->cipheringKey, ckey, TSDB_KEY_LEN);
memcpy(pConn->meterId, id, TSDB_METER_ID_LEN); memcpy(pConn->meterId, id, TSDB_TABLE_ID_LEN);
*/ */
return -1; return -1;
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#define MAX_STR_LEN 40 #define MAX_STR_LEN 40
typedef struct _str_node_t { typedef struct _str_node_t {
char string[TSDB_METER_ID_LEN]; char string[TSDB_TABLE_ID_LEN];
int hash; int hash;
struct _str_node_t *prev; struct _str_node_t *prev;
struct _str_node_t *next; struct _str_node_t *next;
......
CMAKE_MINIMUM_REQUIRED(VERSION 2.8) CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(TDengine) PROJECT(TDengine)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
AUX_SOURCE_DIRECTORY(src SRC) AUX_SOURCE_DIRECTORY(src SRC)
...@@ -34,6 +35,7 @@ ELSEIF (TD_WINDOWS_64) ...@@ -34,6 +35,7 @@ ELSEIF (TD_WINDOWS_64)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/iconv) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/iconv)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/regex) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/regex)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
LIST(APPEND SRC ./src/hash.c)
LIST(APPEND SRC ./src/ihash.c) LIST(APPEND SRC ./src/ihash.c)
LIST(APPEND SRC ./src/lz4.c) LIST(APPEND SRC ./src/lz4.c)
LIST(APPEND SRC ./src/shash.c) LIST(APPEND SRC ./src/shash.c)
...@@ -68,6 +70,7 @@ ELSEIF (TD_WINDOWS_64) ...@@ -68,6 +70,7 @@ ELSEIF (TD_WINDOWS_64)
TARGET_LINK_LIBRARIES(tutil iconv regex pthread os winmm IPHLPAPI ws2_32) TARGET_LINK_LIBRARIES(tutil iconv regex pthread os winmm IPHLPAPI ws2_32)
ELSEIF(TD_DARWIN_64) ELSEIF(TD_DARWIN_64)
ADD_DEFINITIONS(-DUSE_LIBICONV) ADD_DEFINITIONS(-DUSE_LIBICONV)
LIST(APPEND SRC ./src/hash.c)
LIST(APPEND SRC ./src/ihash.c) LIST(APPEND SRC ./src/ihash.c)
LIST(APPEND SRC ./src/lz4.c) LIST(APPEND SRC ./src/lz4.c)
LIST(APPEND SRC ./src/shash.c) LIST(APPEND SRC ./src/shash.c)
......
...@@ -16,12 +16,14 @@ ...@@ -16,12 +16,14 @@
#ifndef TDENGINE_TSTATUS_H #ifndef TDENGINE_TSTATUS_H
#define TDENGINE_TSTATUS_H #define TDENGINE_TSTATUS_H
#include "taoserror.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <stdint.h>
#include <stdbool.h>
#include "taoserror.h"
enum _TSDB_VG_STATUS { enum _TSDB_VG_STATUS {
TSDB_VG_STATUS_READY = TSDB_CODE_SUCCESS, TSDB_VG_STATUS_READY = TSDB_CODE_SUCCESS,
TSDB_VG_STATUS_IN_PROGRESS = TSDB_CODE_ACTION_IN_PROGRESS, TSDB_VG_STATUS_IN_PROGRESS = TSDB_CODE_ACTION_IN_PROGRESS,
......
...@@ -80,7 +80,12 @@ short tsNumOfVnodesPerCore = 8; ...@@ -80,7 +80,12 @@ short tsNumOfVnodesPerCore = 8;
short tsNumOfTotalVnodes = 0; short tsNumOfTotalVnodes = 0;
short tsCheckHeaderFile = 0; short tsCheckHeaderFile = 0;
#ifdef _TD_ARM_32_
int tsSessionsPerVnode = 100;
#else
int tsSessionsPerVnode = 1000; int tsSessionsPerVnode = 1000;
#endif
int tsCacheBlockSize = 16384; // 256 columns int tsCacheBlockSize = 16384; // 256 columns
int tsAverageCacheBlocks = TSDB_DEFAULT_AVG_BLOCKS; int tsAverageCacheBlocks = TSDB_DEFAULT_AVG_BLOCKS;
/** /**
......
...@@ -14,8 +14,7 @@ ...@@ -14,8 +14,7 @@
*/ */
#include "taosmsg.h" #include "taosmsg.h"
#include "tsdb.h" #include "tstatus.h"
#include "vnodeStatus.h"
const char* taosGetVgroupStatusStr(int32_t vgroupStatus) { const char* taosGetVgroupStatusStr(int32_t vgroupStatus) {
switch (vgroupStatus) { switch (vgroupStatus) {
......
...@@ -24,7 +24,43 @@ ...@@ -24,7 +24,43 @@
#include "ttime.h" #include "ttime.h"
#include "tutil.h" #include "tutil.h"
/*
* mktime64 - Converts date to seconds.
* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
* Assumes input in normal date format, i.e. 1980-12-31 23:59:59
* => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
*
* [For the Julian calendar (which was used in Russia before 1917,
* Britain & colonies before 1752, anywhere else before 1582,
* and is still in use by some communities) leave out the
* -year/100+year/400 terms, and add 10.]
*
* This algorithm was first published by Gauss (I think).
*
* A leap second can be indicated by calling this function with sec as
* 60 (allowable under ISO 8601). The leap second is treated the same
* as the following second since they don't exist in UNIX time.
*
* An encoding of midnight at the end of the day as 24:00:00 - ie. midnight
* tomorrow - (allowable under ISO 8601) is supported.
*/
int64_t user_mktime64(const unsigned int year0, const unsigned int mon0,
const unsigned int day, const unsigned int hour,
const unsigned int min, const unsigned int sec)
{
unsigned int mon = mon0, year = year0;
/* 1..12 -> 11,12,1..10 */
if (0 >= (int) (mon -= 2)) {
mon += 12; /* Puts Feb last since it has leap day */
year -= 1;
}
int64_t res = (((((int64_t) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
year*365 - 719499)*24 + hour)*60 + min)*60 + sec);
return (res + timezone);
}
// ==== mktime() kernel code =================// // ==== mktime() kernel code =================//
static int64_t m_deltaUtc = 0; static int64_t m_deltaUtc = 0;
void deltaToUtcInitOnce() { void deltaToUtcInitOnce() {
...@@ -293,7 +329,8 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) { ...@@ -293,7 +329,8 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) {
/* mktime will be affected by TZ, set by using taos_options */ /* mktime will be affected by TZ, set by using taos_options */
//int64_t seconds = mktime(&tm); //int64_t seconds = mktime(&tm);
int64_t seconds = (int64_t)user_mktime(&tm); //int64_t seconds = (int64_t)user_mktime(&tm);
int64_t seconds = user_mktime64(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
int64_t fraction = 0; int64_t fraction = 0;
......
...@@ -976,11 +976,21 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) { ...@@ -976,11 +976,21 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
break; break;
} }
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
#ifdef _TD_ARM_32_
float fv = GET_FLOAT_VAL(src);
SET_FLOAT_VAL_ALIGN(val, &fv);
#else
*((float *)val) = GET_FLOAT_VAL(src); *((float *)val) = GET_FLOAT_VAL(src);
#endif
break; break;
}; };
case TSDB_DATA_TYPE_DOUBLE: { case TSDB_DATA_TYPE_DOUBLE: {
#ifdef _TD_ARM_32_
double dv = GET_DOUBLE_VAL(src);
SET_DOUBLE_VAL_ALIGN(val, &dv);
#else
*((double *)val) = GET_DOUBLE_VAL(src); *((double *)val) = GET_DOUBLE_VAL(src);
#endif
break; break;
}; };
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
......
char version[64] = "1.6.5.3"; char version[64] = "1.6.5.4";
char compatible_version[64] = "1.6.1.0"; char compatible_version[64] = "1.6.1.0";
char gitinfo[128] = "700305490a82228ec1b0244afb838bdbb9de9793"; char gitinfo[128] = "3264067e97300c84caa61ac909d548c9ca56de6b";
char gitinfoOfInternal[128] = ""; char gitinfoOfInternal[128] = "da88f4a2474737d1f9c76adcf0ff7fd0975e7342";
char buildinfo[512] = "Built by at 2020-01-17 13:22"; char buildinfo[512] = "Built by root at 2020-02-05 14:38";
void libtaos_edge_1_6_5_1_Linux_x64() {}; void libtaos_1_6_5_4_Linux_x64() {};
...@@ -158,7 +158,7 @@ typedef struct SColumn { ...@@ -158,7 +158,7 @@ typedef struct SColumn {
typedef struct _meter_obj { typedef struct _meter_obj {
uint64_t uid; uint64_t uid;
char meterId[TSDB_METER_ID_LEN]; char meterId[TSDB_TABLE_ID_LEN];
int sid; int sid;
short vnode; short vnode;
short numOfColumns; short numOfColumns;
......
...@@ -253,7 +253,7 @@ typedef struct SMeterQuerySupportObj { ...@@ -253,7 +253,7 @@ typedef struct SMeterQuerySupportObj {
typedef struct _qinfo { typedef struct _qinfo {
uint64_t signature; uint64_t signature;
int32_t refCount; // QInfo reference count, when the value is 0, it can be released safely int32_t refCount; // QInfo reference count, when the value is 0, it can be released safely
char user[TSDB_METER_ID_LEN + 1]; char user[TSDB_TABLE_ID_LEN + 1];
char sql[TSDB_SHOW_SQL_LEN]; char sql[TSDB_SHOW_SQL_LEN];
uint8_t stream; uint8_t stream;
uint16_t port; uint16_t port;
......
...@@ -492,7 +492,7 @@ void *vnodeCommitMultiToFile(SVnodeObj *pVnode, int ssid, int esid) { ...@@ -492,7 +492,7 @@ void *vnodeCommitMultiToFile(SVnodeObj *pVnode, int ssid, int esid) {
SMeterObj * pObj = NULL; SMeterObj * pObj = NULL;
SCompInfo compInfo = {0}; SCompInfo compInfo = {0};
SCompHeader * pHeader; SCompHeader * pHeader;
SMeterInfo * meterInfo = NULL, *pMeter = NULL; SMeterInfo * meterInfo = NULL, *pTable = NULL;
SQuery query; SQuery query;
SColumnInfoEx colList[TSDB_MAX_COLUMNS] = {0}; SColumnInfoEx colList[TSDB_MAX_COLUMNS] = {0};
SSqlFunctionExpr pExprs[TSDB_MAX_COLUMNS] = {0}; SSqlFunctionExpr pExprs[TSDB_MAX_COLUMNS] = {0};
...@@ -617,7 +617,7 @@ _again: ...@@ -617,7 +617,7 @@ _again:
continue; continue;
} }
pMeter = meterInfo + sid; pTable = meterInfo + sid;
pHeader = ((SCompHeader *)tmem) + sid; pHeader = ((SCompHeader *)tmem) + sid;
if (pVnode->hfd > 0) { if (pVnode->hfd > 0) {
...@@ -633,18 +633,18 @@ _again: ...@@ -633,18 +633,18 @@ _again:
goto _over; goto _over;
} else { } else {
if (pObj->uid == compInfo.uid) { if (pObj->uid == compInfo.uid) {
pMeter->oldNumOfBlocks = compInfo.numOfBlocks; pTable->oldNumOfBlocks = compInfo.numOfBlocks;
pMeter->oldCompBlockOffset = pHeader->compInfoOffset + sizeof(SCompInfo); pTable->oldCompBlockOffset = pHeader->compInfoOffset + sizeof(SCompInfo);
pMeter->last = compInfo.last; pTable->last = compInfo.last;
if (compInfo.numOfBlocks > maxOldBlocks) maxOldBlocks = compInfo.numOfBlocks; if (compInfo.numOfBlocks > maxOldBlocks) maxOldBlocks = compInfo.numOfBlocks;
if (pMeter->last) { if (pTable->last) {
lseek(pVnode->hfd, sizeof(SCompBlock) * (compInfo.numOfBlocks - 1), SEEK_CUR); lseek(pVnode->hfd, sizeof(SCompBlock) * (compInfo.numOfBlocks - 1), SEEK_CUR);
read(pVnode->hfd, &pMeter->lastBlock, sizeof(SCompBlock)); read(pVnode->hfd, &pTable->lastBlock, sizeof(SCompBlock));
} }
} else { } else {
dTrace("vid:%d sid:%d id:%s, uid:%" PRIu64 " is not matched with old:%" PRIu64 ", old data will be thrown away", dTrace("vid:%d sid:%d id:%s, uid:%" PRIu64 " is not matched with old:%" PRIu64 ", old data will be thrown away",
vnode, sid, pObj->meterId, pObj->uid, compInfo.uid); vnode, sid, pObj->meterId, pObj->uid, compInfo.uid);
pMeter->oldNumOfBlocks = 0; pTable->oldNumOfBlocks = 0;
} }
} }
} else { } else {
...@@ -669,8 +669,8 @@ _again: ...@@ -669,8 +669,8 @@ _again:
pObj->pointsPerFileBlock * pObj->schema[col - 1].bytes + EXTRA_BYTES + sizeof(TSCKSUM)); pObj->pointsPerFileBlock * pObj->schema[col - 1].bytes + EXTRA_BYTES + sizeof(TSCKSUM));
} }
pMeter = meterInfo + sid; pTable = meterInfo + sid;
pMeter->tempHeadOffset = headLen; pTable->tempHeadOffset = headLen;
memset(&query, 0, sizeof(query)); memset(&query, 0, sizeof(query));
query.colList = colList; query.colList = colList;
...@@ -690,27 +690,27 @@ _again: ...@@ -690,27 +690,27 @@ _again:
pointsReadLast = 0; pointsReadLast = 0;
// last block is at last file // last block is at last file
if (pMeter->last) { if (pTable->last) {
if ((pMeter->lastBlock.sversion != pObj->sversion) || (query.over)) { if ((pTable->lastBlock.sversion != pObj->sversion) || (query.over)) {
// TODO : Check the correctness of this code. write the last block to // TODO : Check the correctness of this code. write the last block to
// .data file // .data file
pCompBlock = (SCompBlock *)(hmem + headLen); pCompBlock = (SCompBlock *)(hmem + headLen);
assert(dmem - (char *)pCompBlock >= sizeof(SCompBlock)); assert(dmem - (char *)pCompBlock >= sizeof(SCompBlock));
*pCompBlock = pMeter->lastBlock; *pCompBlock = pTable->lastBlock;
if (pMeter->lastBlock.sversion != pObj->sversion) { if (pTable->lastBlock.sversion != pObj->sversion) {
pCompBlock->last = 0; pCompBlock->last = 0;
pCompBlock->offset = lseek(pVnode->dfd, 0, SEEK_END); pCompBlock->offset = lseek(pVnode->dfd, 0, SEEK_END);
pMeter->last = 0; pTable->last = 0;
lseek(pVnode->lfd, pMeter->lastBlock.offset, SEEK_SET); lseek(pVnode->lfd, pTable->lastBlock.offset, SEEK_SET);
tsendfile(pVnode->dfd, pVnode->lfd, NULL, pMeter->lastBlock.len); tsendfile(pVnode->dfd, pVnode->lfd, NULL, pTable->lastBlock.len);
pVnode->dfSize = pCompBlock->offset + pMeter->lastBlock.len; pVnode->dfSize = pCompBlock->offset + pTable->lastBlock.len;
} else { } else {
if (ssid == 0) { if (ssid == 0) {
assert(pCompBlock->last && pVnode->tfd != -1); assert(pCompBlock->last && pVnode->tfd != -1);
pCompBlock->offset = lseek(pVnode->tfd, 0, SEEK_END); pCompBlock->offset = lseek(pVnode->tfd, 0, SEEK_END);
lseek(pVnode->lfd, pMeter->lastBlock.offset, SEEK_SET); lseek(pVnode->lfd, pTable->lastBlock.offset, SEEK_SET);
tsendfile(pVnode->tfd, pVnode->lfd, NULL, pMeter->lastBlock.len); tsendfile(pVnode->tfd, pVnode->lfd, NULL, pTable->lastBlock.len);
pVnode->lfSize = pCompBlock->offset + pMeter->lastBlock.len; pVnode->lfSize = pCompBlock->offset + pTable->lastBlock.len;
} else { } else {
assert(pVnode->tfd == -1); assert(pVnode->tfd == -1);
} }
...@@ -718,12 +718,12 @@ _again: ...@@ -718,12 +718,12 @@ _again:
} }
headLen += sizeof(SCompBlock); headLen += sizeof(SCompBlock);
pMeter->newNumOfBlocks++; pTable->newNumOfBlocks++;
} else { } else {
// read last block into memory // read last block into memory
if (vnodeReadLastBlockToMem(pObj, &pMeter->lastBlock, data) < 0) goto _over; if (vnodeReadLastBlockToMem(pObj, &pTable->lastBlock, data) < 0) goto _over;
pMeter->last = 0; pTable->last = 0;
pointsReadLast = pMeter->lastBlock.numOfPoints; pointsReadLast = pTable->lastBlock.numOfPoints;
query.over = 0; query.over = 0;
headInfo.totalStorage -= (pointsReadLast * pObj->bytesPerPoint); headInfo.totalStorage -= (pointsReadLast * pObj->bytesPerPoint);
...@@ -731,8 +731,8 @@ _again: ...@@ -731,8 +731,8 @@ _again:
pObj->vnode, pObj->sid, pObj->meterId, pointsReadLast); pObj->vnode, pObj->sid, pObj->meterId, pointsReadLast);
} }
pMeter->changed = 1; pTable->changed = 1;
pMeter->oldNumOfBlocks--; pTable->oldNumOfBlocks--;
} }
while (query.over == 0) { while (query.over == 0) {
...@@ -753,17 +753,17 @@ _again: ...@@ -753,17 +753,17 @@ _again:
pCompBlock->last = 1; pCompBlock->last = 1;
if (vnodeWriteBlockToFile(pObj, pCompBlock, data, cdata, pointsRead) < 0) goto _over; if (vnodeWriteBlockToFile(pObj, pCompBlock, data, cdata, pointsRead) < 0) goto _over;
if (pCompBlock->keyLast > pObj->lastKeyOnFile) pObj->lastKeyOnFile = pCompBlock->keyLast; if (pCompBlock->keyLast > pObj->lastKeyOnFile) pObj->lastKeyOnFile = pCompBlock->keyLast;
pMeter->last = pCompBlock->last; pTable->last = pCompBlock->last;
// write block info into header buffer // write block info into header buffer
headLen += sizeof(SCompBlock); headLen += sizeof(SCompBlock);
pMeter->newNumOfBlocks++; pTable->newNumOfBlocks++;
pMeter->committedPoints += (pointsRead - pointsReadLast); pTable->committedPoints += (pointsRead - pointsReadLast);
dTrace("vid:%d sid:%d id:%s, pointsRead:%d, pointsReadLast:%d lastKey:%" PRId64 ", " dTrace("vid:%d sid:%d id:%s, pointsRead:%d, pointsReadLast:%d lastKey:%" PRId64 ", "
"slot:%d pos:%d newNumOfBlocks:%d headLen:%d", "slot:%d pos:%d newNumOfBlocks:%d headLen:%d",
pObj->vnode, pObj->sid, pObj->meterId, pointsRead, pointsReadLast, pObj->lastKeyOnFile, query.slot, query.pos, pObj->vnode, pObj->sid, pObj->meterId, pointsRead, pointsReadLast, pObj->lastKeyOnFile, query.slot, query.pos,
pMeter->newNumOfBlocks, headLen); pTable->newNumOfBlocks, headLen);
if (pointsRead < pObj->pointsPerFileBlock || query.keyIsMet) break; if (pointsRead < pObj->pointsPerFileBlock || query.keyIsMet) break;
...@@ -772,12 +772,12 @@ _again: ...@@ -772,12 +772,12 @@ _again:
} }
dTrace("vid:%d sid:%d id:%s, %d points are committed, lastKey:%" PRId64 " slot:%d pos:%d newNumOfBlocks:%d", dTrace("vid:%d sid:%d id:%s, %d points are committed, lastKey:%" PRId64 " slot:%d pos:%d newNumOfBlocks:%d",
pObj->vnode, pObj->sid, pObj->meterId, pMeter->committedPoints, pObj->lastKeyOnFile, query.slot, query.pos, pObj->vnode, pObj->sid, pObj->meterId, pTable->committedPoints, pObj->lastKeyOnFile, query.slot, query.pos,
pMeter->newNumOfBlocks); pTable->newNumOfBlocks);
if (pMeter->committedPoints > 0) { if (pTable->committedPoints > 0) {
pMeter->commitSlot = query.slot; pTable->commitSlot = query.slot;
pMeter->commitPos = query.pos; pTable->commitPos = query.pos;
} }
TSKEY nextKey = 0; TSKEY nextKey = 0;
...@@ -805,19 +805,19 @@ _again: ...@@ -805,19 +805,19 @@ _again:
continue; continue;
} }
pMeter = meterInfo + sid; pTable = meterInfo + sid;
pMeter->compInfoOffset = compInfoOffset; pTable->compInfoOffset = compInfoOffset;
pMeter->finalNumOfBlocks = pMeter->oldNumOfBlocks + pMeter->newNumOfBlocks; pTable->finalNumOfBlocks = pTable->oldNumOfBlocks + pTable->newNumOfBlocks;
if (pMeter->finalNumOfBlocks > 0) { if (pTable->finalNumOfBlocks > 0) {
pHeader->compInfoOffset = pMeter->compInfoOffset; pHeader->compInfoOffset = pTable->compInfoOffset;
compInfoOffset += sizeof(SCompInfo) + pMeter->finalNumOfBlocks * sizeof(SCompBlock) + sizeof(TSCKSUM); compInfoOffset += sizeof(SCompInfo) + pTable->finalNumOfBlocks * sizeof(SCompBlock) + sizeof(TSCKSUM);
} else { } else {
pHeader->compInfoOffset = 0; pHeader->compInfoOffset = 0;
} }
dTrace("vid:%d sid:%d id:%s, oldBlocks:%d numOfBlocks:%d compInfoOffset:%d", pObj->vnode, pObj->sid, pObj->meterId, dTrace("vid:%d sid:%d id:%s, oldBlocks:%d numOfBlocks:%d compInfoOffset:%d", pObj->vnode, pObj->sid, pObj->meterId,
pMeter->oldNumOfBlocks, pMeter->finalNumOfBlocks, compInfoOffset); pTable->oldNumOfBlocks, pTable->finalNumOfBlocks, compInfoOffset);
} }
// write the comp header into new file // write the comp header into new file
...@@ -838,16 +838,16 @@ _again: ...@@ -838,16 +838,16 @@ _again:
pObj = (SMeterObj *)(pVnode->meterList[sid]); pObj = (SMeterObj *)(pVnode->meterList[sid]);
if (pObj == NULL) continue; if (pObj == NULL) continue;
pMeter = meterInfo + sid; pTable = meterInfo + sid;
if (pMeter->finalNumOfBlocks <= 0) continue; if (pTable->finalNumOfBlocks <= 0) continue;
compInfo.last = pMeter->last; compInfo.last = pTable->last;
compInfo.uid = pObj->uid; compInfo.uid = pObj->uid;
compInfo.numOfBlocks = pMeter->finalNumOfBlocks; compInfo.numOfBlocks = pTable->finalNumOfBlocks;
/* compInfo.compBlockLen = pMeter->finalCompBlockLen; */ /* compInfo.compBlockLen = pTable->finalCompBlockLen; */
compInfo.delimiter = TSDB_VNODE_DELIMITER; compInfo.delimiter = TSDB_VNODE_DELIMITER;
taosCalcChecksumAppend(0, (uint8_t *)(&compInfo), sizeof(SCompInfo)); taosCalcChecksumAppend(0, (uint8_t *)(&compInfo), sizeof(SCompInfo));
lseek(pVnode->nfd, pMeter->compInfoOffset, SEEK_SET); lseek(pVnode->nfd, pTable->compInfoOffset, SEEK_SET);
if (twrite(pVnode->nfd, &compInfo, sizeof(compInfo)) <= 0) { if (twrite(pVnode->nfd, &compInfo, sizeof(compInfo)) <= 0) {
dError("vid:%d sid:%d id:%s, failed to write:%s, reason:%s", vnode, sid, pObj->meterId, pVnode->nfn, dError("vid:%d sid:%d id:%s, failed to write:%s, reason:%s", vnode, sid, pObj->meterId, pVnode->nfn,
strerror(errno)); strerror(errno));
...@@ -857,23 +857,23 @@ _again: ...@@ -857,23 +857,23 @@ _again:
// write the old comp blocks // write the old comp blocks
chksum = 0; chksum = 0;
if (pVnode->hfd && pMeter->oldNumOfBlocks) { if (pVnode->hfd && pTable->oldNumOfBlocks) {
lseek(pVnode->hfd, pMeter->oldCompBlockOffset, SEEK_SET); lseek(pVnode->hfd, pTable->oldCompBlockOffset, SEEK_SET);
if (pMeter->changed) { if (pTable->changed) {
int compBlockLen = pMeter->oldNumOfBlocks * sizeof(SCompBlock); int compBlockLen = pTable->oldNumOfBlocks * sizeof(SCompBlock);
read(pVnode->hfd, pOldCompBlocks, compBlockLen); read(pVnode->hfd, pOldCompBlocks, compBlockLen);
twrite(pVnode->nfd, pOldCompBlocks, compBlockLen); twrite(pVnode->nfd, pOldCompBlocks, compBlockLen);
chksum = taosCalcChecksum(0, pOldCompBlocks, compBlockLen); chksum = taosCalcChecksum(0, pOldCompBlocks, compBlockLen);
} else { } else {
tsendfile(pVnode->nfd, pVnode->hfd, NULL, pMeter->oldNumOfBlocks * sizeof(SCompBlock)); tsendfile(pVnode->nfd, pVnode->hfd, NULL, pTable->oldNumOfBlocks * sizeof(SCompBlock));
read(pVnode->hfd, &chksum, sizeof(TSCKSUM)); read(pVnode->hfd, &chksum, sizeof(TSCKSUM));
} }
} }
if (pMeter->newNumOfBlocks) { if (pTable->newNumOfBlocks) {
chksum = taosCalcChecksum(chksum, (uint8_t *)(hmem + pMeter->tempHeadOffset), chksum = taosCalcChecksum(chksum, (uint8_t *)(hmem + pTable->tempHeadOffset),
pMeter->newNumOfBlocks * sizeof(SCompBlock)); pTable->newNumOfBlocks * sizeof(SCompBlock));
if (twrite(pVnode->nfd, hmem + pMeter->tempHeadOffset, pMeter->newNumOfBlocks * sizeof(SCompBlock)) <= 0) { if (twrite(pVnode->nfd, hmem + pTable->tempHeadOffset, pTable->newNumOfBlocks * sizeof(SCompBlock)) <= 0) {
dError("vid:%d sid:%d id:%s, failed to write:%s, reason:%s", vnode, sid, pObj->meterId, pVnode->nfn, dError("vid:%d sid:%d id:%s, failed to write:%s, reason:%s", vnode, sid, pObj->meterId, pVnode->nfn,
strerror(errno)); strerror(errno));
vnodeRecoverFromPeer(pVnode, pVnode->commitFileId); vnodeRecoverFromPeer(pVnode, pVnode->commitFileId);
...@@ -891,11 +891,11 @@ _again: ...@@ -891,11 +891,11 @@ _again:
pObj = (SMeterObj *)(pVnode->meterList[sid]); pObj = (SMeterObj *)(pVnode->meterList[sid]);
if (pObj == NULL) continue; if (pObj == NULL) continue;
pMeter = meterInfo + sid; pTable = meterInfo + sid;
if (pMeter->finalNumOfBlocks <= 0) continue; if (pTable->finalNumOfBlocks <= 0) continue;
if (pMeter->committedPoints > 0) { if (pTable->committedPoints > 0) {
vnodeUpdateCommitInfo(pObj, pMeter->commitSlot, pMeter->commitPos, pMeter->commitCount); vnodeUpdateCommitInfo(pObj, pTable->commitSlot, pTable->commitPos, pTable->commitCount);
} }
} }
......
...@@ -1236,12 +1236,12 @@ _error_merge: ...@@ -1236,12 +1236,12 @@ _error_merge:
} \ } \
} }
int isCacheEnd(SBlockIter iter, SMeterObj *pMeter) { int isCacheEnd(SBlockIter iter, SMeterObj *pTable) {
SCacheInfo *pInfo = (SCacheInfo *)(pMeter->pCache); SCacheInfo *pInfo = (SCacheInfo *)(pTable->pCache);
int slot = 0; int slot = 0;
int pos = 0; int pos = 0;
if (pInfo->cacheBlocks[pInfo->currentSlot]->numOfPoints == pMeter->pointsPerBlock) { if (pInfo->cacheBlocks[pInfo->currentSlot]->numOfPoints == pTable->pointsPerBlock) {
slot = (pInfo->currentSlot + 1) % (pInfo->maxBlocks); slot = (pInfo->currentSlot + 1) % (pInfo->maxBlocks);
pos = 0; pos = 0;
} else { } else {
......
...@@ -4506,7 +4506,7 @@ int32_t vnodeMultiMeterQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param) ...@@ -4506,7 +4506,7 @@ int32_t vnodeMultiMeterQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param)
} }
// get one queried meter // get one queried meter
SMeterObj *pMeter = getMeterObj(pSupporter->pMetersHashTable, pSupporter->pSidSet->pSids[0]->sid); SMeterObj *pTable = getMeterObj(pSupporter->pMetersHashTable, pSupporter->pSidSet->pSids[0]->sid);
pRuntimeEnv->pTSBuf = param; pRuntimeEnv->pTSBuf = param;
pRuntimeEnv->cur.vnodeIndex = -1; pRuntimeEnv->cur.vnodeIndex = -1;
...@@ -4517,18 +4517,18 @@ int32_t vnodeMultiMeterQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param) ...@@ -4517,18 +4517,18 @@ int32_t vnodeMultiMeterQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param)
tsBufSetTraverseOrder(pRuntimeEnv->pTSBuf, order); tsBufSetTraverseOrder(pRuntimeEnv->pTSBuf, order);
} }
int32_t ret = setupQueryRuntimeEnv(pMeter, pQuery, &pSupporter->runtimeEnv, pTagSchema, TSQL_SO_ASC, true); int32_t ret = setupQueryRuntimeEnv(pTable, pQuery, &pSupporter->runtimeEnv, pTagSchema, TSQL_SO_ASC, true);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
ret = allocateRuntimeEnvBuf(pRuntimeEnv, pMeter); ret = allocateRuntimeEnvBuf(pRuntimeEnv, pTable);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
tSidSetSort(pSupporter->pSidSet); tSidSetSort(pSupporter->pSidSet);
vnodeRecordAllFiles(pQInfo, pMeter->vnode); vnodeRecordAllFiles(pQInfo, pTable->vnode);
if ((ret = allocateOutputBufForGroup(pSupporter, pQuery, true)) != TSDB_CODE_SUCCESS) { if ((ret = allocateOutputBufForGroup(pSupporter, pQuery, true)) != TSDB_CODE_SUCCESS) {
return ret; return ret;
...@@ -4595,12 +4595,12 @@ void vnodeDecMeterRefcnt(SQInfo *pQInfo) { ...@@ -4595,12 +4595,12 @@ void vnodeDecMeterRefcnt(SQInfo *pQInfo) {
} else { } else {
int32_t num = 0; int32_t num = 0;
for (int32_t i = 0; i < pSupporter->numOfMeters; ++i) { for (int32_t i = 0; i < pSupporter->numOfMeters; ++i) {
SMeterObj *pMeter = getMeterObj(pSupporter->pMetersHashTable, pSupporter->pSidSet->pSids[i]->sid); SMeterObj *pTable = getMeterObj(pSupporter->pMetersHashTable, pSupporter->pSidSet->pSids[i]->sid);
atomic_fetch_sub_32(&(pMeter->numOfQueries), 1); atomic_fetch_sub_32(&(pTable->numOfQueries), 1);
if (pMeter->numOfQueries > 0) { if (pTable->numOfQueries > 0) {
dTrace("QInfo:%p vid:%d sid:%d meterId:%s, query is over, numOfQueries:%d", pQInfo, pMeter->vnode, pMeter->sid, dTrace("QInfo:%p vid:%d sid:%d meterId:%s, query is over, numOfQueries:%d", pQInfo, pTable->vnode, pTable->sid,
pMeter->meterId, pMeter->numOfQueries); pTable->meterId, pTable->numOfQueries);
num++; num++;
} }
} }
......
...@@ -186,15 +186,15 @@ void vnodeUpdateStreamRole(SVnodeObj *pVnode) { ...@@ -186,15 +186,15 @@ void vnodeUpdateStreamRole(SVnodeObj *pVnode) {
// Callback function called from client // Callback function called from client
void vnodeCloseStreamCallback(void *param) { void vnodeCloseStreamCallback(void *param) {
SMeterObj *pMeter = (SMeterObj *)param; SMeterObj *pTable = (SMeterObj *)param;
SVnodeObj *pVnode = NULL; SVnodeObj *pVnode = NULL;
if (pMeter == NULL || pMeter->sqlLen == 0) return; if (pTable == NULL || pTable->sqlLen == 0) return;
pVnode = vnodeList + pMeter->vnode; pVnode = vnodeList + pTable->vnode;
pMeter->sqlLen = 0; pTable->sqlLen = 0;
pMeter->pSql = NULL; pTable->pSql = NULL;
pMeter->pStream = NULL; pTable->pStream = NULL;
pVnode->numOfStreams--; pVnode->numOfStreams--;
...@@ -203,5 +203,5 @@ void vnodeCloseStreamCallback(void *param) { ...@@ -203,5 +203,5 @@ void vnodeCloseStreamCallback(void *param) {
pVnode->dbConn = NULL; pVnode->dbConn = NULL;
} }
vnodeSaveMeterObjToFile(pMeter); vnodeSaveMeterObjToFile(pTable);
} }
\ No newline at end of file
...@@ -527,7 +527,7 @@ bool vnodeIsProjectionQuery(SSqlFunctionExpr* pExpr, int32_t numOfOutput) { ...@@ -527,7 +527,7 @@ bool vnodeIsProjectionQuery(SSqlFunctionExpr* pExpr, int32_t numOfOutput) {
} }
/* /*
* the pMeter->state may be changed by vnodeIsSafeToDeleteMeter and import/update processor, the check of * the pTable->state may be changed by vnodeIsSafeToDeleteMeter and import/update processor, the check of
* the state will not always be correct. * the state will not always be correct.
* *
* The import/update/deleting is actually blocked by current query processing if the check of meter state is * The import/update/deleting is actually blocked by current query processing if the check of meter state is
...@@ -548,30 +548,30 @@ int32_t vnodeIncQueryRefCount(SQueryMeterMsg* pQueryMsg, SMeterSidExtInfo** pSid ...@@ -548,30 +548,30 @@ int32_t vnodeIncQueryRefCount(SQueryMeterMsg* pQueryMsg, SMeterSidExtInfo** pSid
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
for (int32_t i = 0; i < pQueryMsg->numOfSids; ++i) { for (int32_t i = 0; i < pQueryMsg->numOfSids; ++i) {
SMeterObj* pMeter = pVnode->meterList[pSids[i]->sid]; SMeterObj* pTable = pVnode->meterList[pSids[i]->sid];
/* /*
* If table is missing or is in dropping status, config it from management node, and ignore it * If table is missing or is in dropping status, config it from management node, and ignore it
* during query processing. The error code of TSDB_CODE_NOT_ACTIVE_TABLE will never return to client. * during query processing. The error code of TSDB_CODE_NOT_ACTIVE_TABLE will never return to client.
* The missing table needs to be removed from pSids list * The missing table needs to be removed from pSids list
*/ */
if (pMeter == NULL || vnodeIsMeterState(pMeter, TSDB_METER_STATE_DROPPING)) { if (pTable == NULL || vnodeIsMeterState(pTable, TSDB_METER_STATE_DROPPING)) {
dWarn("qmsg:%p, vid:%d sid:%d, not there or will be dropped, ignore this table in query", pQueryMsg, dWarn("qmsg:%p, vid:%d sid:%d, not there or will be dropped, ignore this table in query", pQueryMsg,
pQueryMsg->vnode, pSids[i]->sid); pQueryMsg->vnode, pSids[i]->sid);
vnodeSendMeterCfgMsg(pQueryMsg->vnode, pSids[i]->sid); vnodeSendMeterCfgMsg(pQueryMsg->vnode, pSids[i]->sid);
continue; continue;
} else if (pMeter->uid != pSids[i]->uid || pMeter->sid != pSids[i]->sid) { } else if (pTable->uid != pSids[i]->uid || pTable->sid != pSids[i]->sid) {
code = TSDB_CODE_TABLE_ID_MISMATCH; code = TSDB_CODE_TABLE_ID_MISMATCH;
dError("qmsg:%p, vid:%d sid:%d id:%s uid:%" PRIu64 ", id mismatch. sid:%d uid:%" PRId64 " in msg", pQueryMsg, dError("qmsg:%p, vid:%d sid:%d id:%s uid:%" PRIu64 ", id mismatch. sid:%d uid:%" PRId64 " in msg", pQueryMsg,
pQueryMsg->vnode, pMeter->sid, pMeter->meterId, pMeter->uid, pSids[i]->sid, pSids[i]->uid); pQueryMsg->vnode, pTable->sid, pTable->meterId, pTable->uid, pSids[i]->sid, pSids[i]->uid);
vnodeSendMeterCfgMsg(pQueryMsg->vnode, pSids[i]->sid); vnodeSendMeterCfgMsg(pQueryMsg->vnode, pSids[i]->sid);
continue; continue;
} else if (pMeter->state > TSDB_METER_STATE_INSERTING) { //update or import } else if (pTable->state > TSDB_METER_STATE_INSERTING) { //update or import
code = TSDB_CODE_ACTION_IN_PROGRESS; code = TSDB_CODE_ACTION_IN_PROGRESS;
dTrace("qmsg:%p, vid:%d sid:%d id:%s, it is in state:%s, wait!", pQueryMsg, pQueryMsg->vnode, pSids[i]->sid, dTrace("qmsg:%p, vid:%d sid:%d id:%s, it is in state:%s, wait!", pQueryMsg, pQueryMsg->vnode, pSids[i]->sid,
pMeter->meterId, taosGetTableStatusStr(pMeter->state)); pTable->meterId, taosGetTableStatusStr(pTable->state));
continue; continue;
} }
...@@ -579,15 +579,15 @@ int32_t vnodeIncQueryRefCount(SQueryMeterMsg* pQueryMsg, SMeterSidExtInfo** pSid ...@@ -579,15 +579,15 @@ int32_t vnodeIncQueryRefCount(SQueryMeterMsg* pQueryMsg, SMeterSidExtInfo** pSid
* vnodeIsSafeToDeleteMeter will wait for this function complete, and then it can * vnodeIsSafeToDeleteMeter will wait for this function complete, and then it can
* check if the numOfQueries is 0 or not. * check if the numOfQueries is 0 or not.
*/ */
pMeterObjList[(*numOfIncTables)++] = pMeter; pMeterObjList[(*numOfIncTables)++] = pTable;
atomic_fetch_add_32(&pMeter->numOfQueries, 1); atomic_fetch_add_32(&pTable->numOfQueries, 1);
pSids[index++] = pSids[i]; pSids[index++] = pSids[i];
// output for meter more than one query executed // output for meter more than one query executed
if (pMeter->numOfQueries > 1) { if (pTable->numOfQueries > 1) {
dTrace("qmsg:%p, vid:%d sid:%d id:%s, inc query ref, numOfQueries:%d", pQueryMsg, pMeter->vnode, pMeter->sid, dTrace("qmsg:%p, vid:%d sid:%d id:%s, inc query ref, numOfQueries:%d", pQueryMsg, pTable->vnode, pTable->sid,
pMeter->meterId, pMeter->numOfQueries); pTable->meterId, pTable->numOfQueries);
num++; num++;
} }
} }
...@@ -605,14 +605,14 @@ void vnodeDecQueryRefCount(SQueryMeterMsg* pQueryMsg, SMeterObj** pMeterObjList, ...@@ -605,14 +605,14 @@ void vnodeDecQueryRefCount(SQueryMeterMsg* pQueryMsg, SMeterObj** pMeterObjList,
int32_t num = 0; int32_t num = 0;
for (int32_t i = 0; i < numOfIncTables; ++i) { for (int32_t i = 0; i < numOfIncTables; ++i) {
SMeterObj* pMeter = pMeterObjList[i]; SMeterObj* pTable = pMeterObjList[i];
if (pMeter != NULL) { // here, do not need to lock to perform operations if (pTable != NULL) { // here, do not need to lock to perform operations
atomic_fetch_sub_32(&pMeter->numOfQueries, 1); atomic_fetch_sub_32(&pTable->numOfQueries, 1);
if (pMeter->numOfQueries > 0) { if (pTable->numOfQueries > 0) {
dTrace("qmsg:%p, vid:%d sid:%d id:%s dec query ref, numOfQueries:%d", pQueryMsg, pMeter->vnode, pMeter->sid, dTrace("qmsg:%p, vid:%d sid:%d id:%s dec query ref, numOfQueries:%d", pQueryMsg, pTable->vnode, pTable->sid,
pMeter->meterId, pMeter->numOfQueries); pTable->meterId, pTable->numOfQueries);
num++; num++;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册