提交 b07a9cb2 编写于 作者: C cpwu

Merge branch '3.0' into cpwu/3.0

...@@ -70,11 +70,7 @@ typedef uint16_t tmsg_t; ...@@ -70,11 +70,7 @@ typedef uint16_t tmsg_t;
#define TSDB_IE_TYPE_DNODE_EXT 6 #define TSDB_IE_TYPE_DNODE_EXT 6
#define TSDB_IE_TYPE_DNODE_STATE 7 #define TSDB_IE_TYPE_DNODE_STATE 7
enum { enum { CONN_TYPE__QUERY = 1, CONN_TYPE__TMQ, CONN_TYPE__MAX };
CONN_TYPE__QUERY = 1,
CONN_TYPE__TMQ,
CONN_TYPE__MAX
};
enum { enum {
HEARTBEAT_KEY_DBINFO = 1, HEARTBEAT_KEY_DBINFO = 1,
...@@ -342,13 +338,13 @@ int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq); ...@@ -342,13 +338,13 @@ int32_t tSerializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq); int32_t tDeserializeSConnectReq(void* buf, int32_t bufLen, SConnectReq* pReq);
typedef struct { typedef struct {
int32_t acctId; int32_t acctId;
int64_t clusterId; int64_t clusterId;
uint32_t connId; uint32_t connId;
int8_t superUser; int8_t superUser;
int8_t connType; int8_t connType;
SEpSet epSet; SEpSet epSet;
char sVersion[128]; char sVersion[128];
} SConnectRsp; } SConnectRsp;
int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp); int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp);
...@@ -663,14 +659,13 @@ typedef struct { ...@@ -663,14 +659,13 @@ typedef struct {
int32_t outputLen; int32_t outputLen;
int32_t bufSize; int32_t bufSize;
int64_t signature; int64_t signature;
int32_t commentSize; char* pComment;
int32_t codeSize; char* pCode;
char pComment[TSDB_FUNC_COMMENT_LEN];
char pCode[TSDB_FUNC_CODE_LEN];
} SCreateFuncReq; } SCreateFuncReq;
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq); int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq); int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
void tFreeSCreateFuncReq(SCreateFuncReq* pReq);
typedef struct { typedef struct {
char name[TSDB_FUNC_NAME_LEN]; char name[TSDB_FUNC_NAME_LEN];
...@@ -687,6 +682,7 @@ typedef struct { ...@@ -687,6 +682,7 @@ typedef struct {
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq); int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq); int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
void tFreeSRetrieveFuncReq(SRetrieveFuncReq* pReq);
typedef struct { typedef struct {
char name[TSDB_FUNC_NAME_LEN]; char name[TSDB_FUNC_NAME_LEN];
...@@ -698,8 +694,8 @@ typedef struct { ...@@ -698,8 +694,8 @@ typedef struct {
int64_t signature; int64_t signature;
int32_t commentSize; int32_t commentSize;
int32_t codeSize; int32_t codeSize;
char pComment[TSDB_FUNC_COMMENT_LEN]; char* pComment;
char pCode[TSDB_FUNC_CODE_LEN]; char* pCode;
} SFuncInfo; } SFuncInfo;
typedef struct { typedef struct {
...@@ -709,6 +705,7 @@ typedef struct { ...@@ -709,6 +705,7 @@ typedef struct {
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp); int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp); int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
void tFreeSRetrieveFuncRsp(SRetrieveFuncRsp* pRsp);
typedef struct { typedef struct {
int32_t statusInterval; int32_t statusInterval;
...@@ -1213,12 +1210,12 @@ typedef struct { ...@@ -1213,12 +1210,12 @@ typedef struct {
#define STREAM_TRIGGER_WINDOW_CLOSE 2 #define STREAM_TRIGGER_WINDOW_CLOSE 2
typedef struct { typedef struct {
char name[TSDB_TOPIC_FNAME_LEN]; char name[TSDB_TOPIC_FNAME_LEN];
char outputSTbName[TSDB_TABLE_FNAME_LEN]; char outputSTbName[TSDB_TABLE_FNAME_LEN];
int8_t igExists; int8_t igExists;
char* sql; char* sql;
char* ast; char* ast;
int8_t triggerType; int8_t triggerType;
int64_t watermark; int64_t watermark;
} SCMCreateStreamReq; } SCMCreateStreamReq;
...@@ -1671,14 +1668,14 @@ typedef struct { ...@@ -1671,14 +1668,14 @@ typedef struct {
int32_t pid; int32_t pid;
char fqdn[TSDB_FQDN_LEN]; char fqdn[TSDB_FQDN_LEN];
int32_t subPlanNum; int32_t subPlanNum;
SArray* subDesc; // SArray<SQuerySubDesc> SArray* subDesc; // SArray<SQuerySubDesc>
} SQueryDesc; } SQueryDesc;
typedef struct { typedef struct {
uint32_t connId; uint32_t connId;
int32_t pid; int32_t pid;
char app[TSDB_APP_NAME_LEN]; char app[TSDB_APP_NAME_LEN];
SArray* queryDesc; // SArray<SQueryDesc> SArray* queryDesc; // SArray<SQueryDesc>
} SQueryHbReqBasic; } SQueryHbReqBasic;
typedef struct { typedef struct {
...@@ -1742,7 +1739,7 @@ static FORCE_INLINE void tFreeClientHbReq(void* pReq) { ...@@ -1742,7 +1739,7 @@ static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
} }
taosMemoryFreeClear(req->query); taosMemoryFreeClear(req->query);
} }
if (req->info) { if (req->info) {
tFreeReqKvHash(req->info); tFreeReqKvHash(req->info);
taosHashCleanup(req->info); taosHashCleanup(req->info);
......
...@@ -128,17 +128,17 @@ extern const int32_t TYPE_BYTES[15]; ...@@ -128,17 +128,17 @@ extern const int32_t TYPE_BYTES[15];
#define TSDB_INS_TABLE_QUERIES "queries" #define TSDB_INS_TABLE_QUERIES "queries"
#define TSDB_INS_TABLE_VNODES "vnodes" #define TSDB_INS_TABLE_VNODES "vnodes"
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema" #define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
#define TSDB_PERFS_TABLE_CONNECTIONS "connections" #define TSDB_PERFS_TABLE_CONNECTIONS "connections"
#define TSDB_PERFS_TABLE_QUERIES "queries" #define TSDB_PERFS_TABLE_QUERIES "queries"
#define TSDB_PERFS_TABLE_TOPICS "topics" #define TSDB_PERFS_TABLE_TOPICS "topics"
#define TSDB_PERFS_TABLE_CONSUMERS "consumers" #define TSDB_PERFS_TABLE_CONSUMERS "consumers"
#define TSDB_PERFS_TABLE_SUBSCRIBES "subscribes" #define TSDB_PERFS_TABLE_SUBSCRIBES "subscribes"
#define TSDB_INDEX_TYPE_SMA "SMA" #define TSDB_INDEX_TYPE_SMA "SMA"
#define TSDB_INDEX_TYPE_FULLTEXT "FULLTEXT" #define TSDB_INDEX_TYPE_FULLTEXT "FULLTEXT"
#define TSDB_INS_USER_STABLES_DBNAME_COLID 2 #define TSDB_INS_USER_STABLES_DBNAME_COLID 2
#define TSDB_TICK_PER_SECOND(precision) \ #define TSDB_TICK_PER_SECOND(precision) \
((int64_t)((precision) == TSDB_TIME_PRECISION_MILLI ? 1e3L \ ((int64_t)((precision) == TSDB_TIME_PRECISION_MILLI ? 1e3L \
...@@ -234,8 +234,8 @@ typedef enum ELogicConditionType { ...@@ -234,8 +234,8 @@ typedef enum ELogicConditionType {
#define TSDB_DB_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN) #define TSDB_DB_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
#define TSDB_FUNC_NAME_LEN 65 #define TSDB_FUNC_NAME_LEN 65
#define TSDB_FUNC_COMMENT_LEN 4096 #define TSDB_FUNC_COMMENT_LEN 1024 * 1024
#define TSDB_FUNC_CODE_LEN (65535 - 512) #define TSDB_FUNC_CODE_LEN 10 * 1024 * 1024
#define TSDB_FUNC_BUF_SIZE 512 #define TSDB_FUNC_BUF_SIZE 512
#define TSDB_FUNC_TYPE_SCALAR 1 #define TSDB_FUNC_TYPE_SCALAR 1
#define TSDB_FUNC_TYPE_AGGREGATE 2 #define TSDB_FUNC_TYPE_AGGREGATE 2
...@@ -339,12 +339,12 @@ typedef enum ELogicConditionType { ...@@ -339,12 +339,12 @@ typedef enum ELogicConditionType {
#define TSDB_MAX_TOTAL_BLOCKS 10000 #define TSDB_MAX_TOTAL_BLOCKS 10000
#define TSDB_DEFAULT_TOTAL_BLOCKS 6 #define TSDB_DEFAULT_TOTAL_BLOCKS 6
#define TSDB_MIN_DAYS_PER_FILE 60 // unit minute #define TSDB_MIN_DAYS_PER_FILE 60 // unit minute
#define TSDB_MAX_DAYS_PER_FILE (3650 * 1440) #define TSDB_MAX_DAYS_PER_FILE (3650 * 1440)
#define TSDB_DEFAULT_DAYS_PER_FILE (10 * 1440) #define TSDB_DEFAULT_DAYS_PER_FILE (10 * 1440)
#define TSDB_MIN_KEEP (1 * 1440) // data in db to be reserved. unit minute #define TSDB_MIN_KEEP (1 * 1440) // data in db to be reserved. unit minute
#define TSDB_MAX_KEEP (365000 * 1440) // data in db to be reserved. #define TSDB_MAX_KEEP (365000 * 1440) // data in db to be reserved.
#define TSDB_DEFAULT_KEEP (3650 * 1440) // ten years #define TSDB_DEFAULT_KEEP (3650 * 1440) // ten years
#define TSDB_MIN_MIN_ROW_FBLOCK 10 #define TSDB_MIN_MIN_ROW_FBLOCK 10
...@@ -419,11 +419,11 @@ typedef enum ELogicConditionType { ...@@ -419,11 +419,11 @@ typedef enum ELogicConditionType {
#define TSDB_DEFAULT_EXPLAIN_VERBOSE false #define TSDB_DEFAULT_EXPLAIN_VERBOSE false
#define TSDB_MIN_EXPLAIN_RATIO 0 #define TSDB_MIN_EXPLAIN_RATIO 0
#define TSDB_MAX_EXPLAIN_RATIO 1 #define TSDB_MAX_EXPLAIN_RATIO 1
#define TSDB_DEFAULT_EXPLAIN_RATIO 0.001 #define TSDB_DEFAULT_EXPLAIN_RATIO 0.001
#define TSDB_EXPLAIN_RESULT_ROW_SIZE 1024 #define TSDB_EXPLAIN_RESULT_ROW_SIZE 1024
#define TSDB_EXPLAIN_RESULT_COLUMN_NAME "QUERY PLAN" #define TSDB_EXPLAIN_RESULT_COLUMN_NAME "QUERY PLAN"
#define TSDB_MAX_JOIN_TABLE_NUM 10 #define TSDB_MAX_JOIN_TABLE_NUM 10
...@@ -509,13 +509,13 @@ enum { ...@@ -509,13 +509,13 @@ enum {
SND_WORKER_TYPE__UNIQUE, SND_WORKER_TYPE__UNIQUE,
}; };
#define MNODE_HANDLE -1 #define MNODE_HANDLE -1
#define QNODE_HANDLE 1 #define QNODE_HANDLE 1
#define DEFAULT_HANDLE 0 #define DEFAULT_HANDLE 0
#define TSDB_CONFIG_OPTION_LEN 16 #define TSDB_CONFIG_OPTION_LEN 16
#define TSDB_CONIIG_VALUE_LEN 48 #define TSDB_CONIIG_VALUE_LEN 48
#define TSDB_CONFIG_NUMBER 8 #define TSDB_CONFIG_NUMBER 8
#define QUERY_ID_SIZE 20 #define QUERY_ID_SIZE 20
#define QUERY_OBJ_ID_SIZE 18 #define QUERY_OBJ_ID_SIZE 18
...@@ -524,7 +524,6 @@ enum { ...@@ -524,7 +524,6 @@ enum {
#define MAX_NUM_STR_SIZE 40 #define MAX_NUM_STR_SIZE 40
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -142,10 +142,10 @@ static int32_t tSerializeSClientHbReq(SCoder *pEncoder, const SClientHbReq *pReq ...@@ -142,10 +142,10 @@ static int32_t tSerializeSClientHbReq(SCoder *pEncoder, const SClientHbReq *pReq
if (tEncodeU32(pEncoder, pReq->query->connId) < 0) return -1; if (tEncodeU32(pEncoder, pReq->query->connId) < 0) return -1;
if (tEncodeI32(pEncoder, pReq->query->pid) < 0) return -1; if (tEncodeI32(pEncoder, pReq->query->pid) < 0) return -1;
if (tEncodeCStr(pEncoder, pReq->query->app) < 0) return -1; if (tEncodeCStr(pEncoder, pReq->query->app) < 0) return -1;
int32_t num = taosArrayGetSize(pReq->query->queryDesc); int32_t num = taosArrayGetSize(pReq->query->queryDesc);
if (tEncodeI32(pEncoder, num) < 0) return -1; if (tEncodeI32(pEncoder, num) < 0) return -1;
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
SQueryDesc *desc = taosArrayGet(pReq->query->queryDesc, i); SQueryDesc *desc = taosArrayGet(pReq->query->queryDesc, i);
if (tEncodeCStr(pEncoder, desc->sql) < 0) return -1; if (tEncodeCStr(pEncoder, desc->sql) < 0) return -1;
...@@ -169,7 +169,7 @@ static int32_t tSerializeSClientHbReq(SCoder *pEncoder, const SClientHbReq *pReq ...@@ -169,7 +169,7 @@ static int32_t tSerializeSClientHbReq(SCoder *pEncoder, const SClientHbReq *pReq
if (tEncodeI32(pEncoder, queryNum) < 0) return -1; if (tEncodeI32(pEncoder, queryNum) < 0) return -1;
} }
} }
int32_t kvNum = taosHashGetSize(pReq->info); int32_t kvNum = taosHashGetSize(pReq->info);
if (tEncodeI32(pEncoder, kvNum) < 0) return -1; if (tEncodeI32(pEncoder, kvNum) < 0) return -1;
void *pIter = taosHashIterate(pReq->info, NULL); void *pIter = taosHashIterate(pReq->info, NULL);
...@@ -200,7 +200,7 @@ static int32_t tDeserializeSClientHbReq(SCoder *pDecoder, SClientHbReq *pReq) { ...@@ -200,7 +200,7 @@ static int32_t tDeserializeSClientHbReq(SCoder *pDecoder, SClientHbReq *pReq) {
if (num > 0) { if (num > 0) {
pReq->query->queryDesc = taosArrayInit(num, sizeof(SQueryDesc)); pReq->query->queryDesc = taosArrayInit(num, sizeof(SQueryDesc));
if (NULL == pReq->query->queryDesc) return -1; if (NULL == pReq->query->queryDesc) return -1;
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
SQueryDesc desc = {0}; SQueryDesc desc = {0};
if (tDecodeCStrTo(pDecoder, desc.sql) < 0) return -1; if (tDecodeCStrTo(pDecoder, desc.sql) < 0) return -1;
...@@ -217,7 +217,7 @@ static int32_t tDeserializeSClientHbReq(SCoder *pDecoder, SClientHbReq *pReq) { ...@@ -217,7 +217,7 @@ static int32_t tDeserializeSClientHbReq(SCoder *pDecoder, SClientHbReq *pReq) {
if (snum > 0) { if (snum > 0) {
desc.subDesc = taosArrayInit(snum, sizeof(SQuerySubDesc)); desc.subDesc = taosArrayInit(snum, sizeof(SQuerySubDesc));
if (NULL == desc.subDesc) return -1; if (NULL == desc.subDesc) return -1;
for (int32_t m = 0; m < snum; ++m) { for (int32_t m = 0; m < snum; ++m) {
SQuerySubDesc sDesc = {0}; SQuerySubDesc sDesc = {0};
if (tDecodeI64(pDecoder, &sDesc.tid) < 0) return -1; if (tDecodeI64(pDecoder, &sDesc.tid) < 0) return -1;
...@@ -254,7 +254,7 @@ static int32_t tSerializeSClientHbRsp(SCoder *pEncoder, const SClientHbRsp *pRsp ...@@ -254,7 +254,7 @@ static int32_t tSerializeSClientHbRsp(SCoder *pEncoder, const SClientHbRsp *pRsp
int32_t queryNum = 0; int32_t queryNum = 0;
if (pRsp->query) { if (pRsp->query) {
queryNum = 1; queryNum = 1;
if (tEncodeI32(pEncoder, queryNum) < 0) return -1; if (tEncodeI32(pEncoder, queryNum) < 0) return -1;
if (tEncodeU32(pEncoder, pRsp->query->connId) < 0) return -1; if (tEncodeU32(pEncoder, pRsp->query->connId) < 0) return -1;
if (tEncodeU64(pEncoder, pRsp->query->killRid) < 0) return -1; if (tEncodeU64(pEncoder, pRsp->query->killRid) < 0) return -1;
if (tEncodeI32(pEncoder, pRsp->query->totalDnodes) < 0) return -1; if (tEncodeI32(pEncoder, pRsp->query->totalDnodes) < 0) return -1;
...@@ -262,9 +262,9 @@ static int32_t tSerializeSClientHbRsp(SCoder *pEncoder, const SClientHbRsp *pRsp ...@@ -262,9 +262,9 @@ static int32_t tSerializeSClientHbRsp(SCoder *pEncoder, const SClientHbRsp *pRsp
if (tEncodeI8(pEncoder, pRsp->query->killConnection) < 0) return -1; if (tEncodeI8(pEncoder, pRsp->query->killConnection) < 0) return -1;
if (tEncodeSEpSet(pEncoder, &pRsp->query->epSet) < 0) return -1; if (tEncodeSEpSet(pEncoder, &pRsp->query->epSet) < 0) return -1;
} else { } else {
if (tEncodeI32(pEncoder, queryNum) < 0) return -1; if (tEncodeI32(pEncoder, queryNum) < 0) return -1;
} }
int32_t kvNum = taosArrayGetSize(pRsp->info); int32_t kvNum = taosArrayGetSize(pRsp->info);
if (tEncodeI32(pEncoder, kvNum) < 0) return -1; if (tEncodeI32(pEncoder, kvNum) < 0) return -1;
for (int32_t i = 0; i < kvNum; i++) { for (int32_t i = 0; i < kvNum; i++) {
...@@ -1492,10 +1492,25 @@ int32_t tSerializeSCreateFuncReq(void *buf, int32_t bufLen, SCreateFuncReq *pReq ...@@ -1492,10 +1492,25 @@ int32_t tSerializeSCreateFuncReq(void *buf, int32_t bufLen, SCreateFuncReq *pReq
if (tEncodeI32(&encoder, pReq->outputLen) < 0) return -1; if (tEncodeI32(&encoder, pReq->outputLen) < 0) return -1;
if (tEncodeI32(&encoder, pReq->bufSize) < 0) return -1; if (tEncodeI32(&encoder, pReq->bufSize) < 0) return -1;
if (tEncodeI64(&encoder, pReq->signature) < 0) return -1; if (tEncodeI64(&encoder, pReq->signature) < 0) return -1;
if (tEncodeI32(&encoder, pReq->commentSize) < 0) return -1;
if (tEncodeI32(&encoder, pReq->codeSize) < 0) return -1; int32_t codeSize = 0;
if (tEncodeCStr(&encoder, pReq->pComment) < 0) return -1; if (pReq->pCode != NULL) {
if (tEncodeCStr(&encoder, pReq->pCode) < 0) return -1; codeSize = strlen(pReq->pCode) + 1;
}
if (tEncodeI32(&encoder, codeSize) < 0) return -1;
if (pReq->pCode != NULL) {
if (tEncodeCStr(&encoder, pReq->pCode) < 0) return -1;
}
int32_t commentSize = 0;
if (pReq->pComment != NULL) {
commentSize = strlen(pReq->pComment) + 1;
}
if (tEncodeI32(&encoder, commentSize) < 0) return -1;
if (pReq->pComment != NULL) {
if (tEncodeCStr(&encoder, pReq->pComment) < 0) return -1;
}
tEndEncode(&encoder); tEndEncode(&encoder);
int32_t tlen = encoder.pos; int32_t tlen = encoder.pos;
...@@ -1516,16 +1531,40 @@ int32_t tDeserializeSCreateFuncReq(void *buf, int32_t bufLen, SCreateFuncReq *pR ...@@ -1516,16 +1531,40 @@ int32_t tDeserializeSCreateFuncReq(void *buf, int32_t bufLen, SCreateFuncReq *pR
if (tDecodeI32(&decoder, &pReq->outputLen) < 0) return -1; if (tDecodeI32(&decoder, &pReq->outputLen) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->bufSize) < 0) return -1; if (tDecodeI32(&decoder, &pReq->bufSize) < 0) return -1;
if (tDecodeI64(&decoder, &pReq->signature) < 0) return -1; if (tDecodeI64(&decoder, &pReq->signature) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->commentSize) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->codeSize) < 0) return -1; int32_t codeSize = 0;
if (tDecodeCStrTo(&decoder, pReq->pComment) < 0) return -1; if (tDecodeI32(&decoder, &codeSize) < 0) return -1;
if (tDecodeCStrTo(&decoder, pReq->pCode) < 0) return -1; if (codeSize > 0) {
pReq->pCode = taosMemoryCalloc(1, codeSize);
if (pReq->pCode == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
if (tDecodeCStrTo(&decoder, pReq->pCode) < 0) return -1;
}
int32_t commentSize = 0;
if (tDecodeI32(&decoder, &commentSize) < 0) return -1;
if (commentSize > 0) {
pReq->pComment = taosMemoryCalloc(1, commentSize);
if (pReq->pComment == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
if (tDecodeCStrTo(&decoder, pReq->pComment) < 0) return -1;
}
tEndDecode(&decoder); tEndDecode(&decoder);
tCoderClear(&decoder); tCoderClear(&decoder);
return 0; return 0;
} }
void tFreeSCreateFuncReq(SCreateFuncReq *pReq) {
taosMemoryFree(pReq->pCode);
taosMemoryFree(pReq->pComment);
}
int32_t tSerializeSDropFuncReq(void *buf, int32_t bufLen, SDropFuncReq *pReq) { int32_t tSerializeSDropFuncReq(void *buf, int32_t bufLen, SDropFuncReq *pReq) {
SCoder encoder = {0}; SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
...@@ -1594,6 +1633,8 @@ int32_t tDeserializeSRetrieveFuncReq(void *buf, int32_t bufLen, SRetrieveFuncReq ...@@ -1594,6 +1633,8 @@ int32_t tDeserializeSRetrieveFuncReq(void *buf, int32_t bufLen, SRetrieveFuncReq
return 0; return 0;
} }
void tFreeSRetrieveFuncReq(SRetrieveFuncReq *pReq) { taosArrayDestroy(pReq->pFuncNames); }
int32_t tSerializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp *pRsp) { int32_t tSerializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp *pRsp) {
SCoder encoder = {0}; SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
...@@ -1612,10 +1653,10 @@ int32_t tSerializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp * ...@@ -1612,10 +1653,10 @@ int32_t tSerializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp *
if (tEncodeI32(&encoder, pInfo->outputLen) < 0) return -1; if (tEncodeI32(&encoder, pInfo->outputLen) < 0) return -1;
if (tEncodeI32(&encoder, pInfo->bufSize) < 0) return -1; if (tEncodeI32(&encoder, pInfo->bufSize) < 0) return -1;
if (tEncodeI64(&encoder, pInfo->signature) < 0) return -1; if (tEncodeI64(&encoder, pInfo->signature) < 0) return -1;
if (tEncodeI32(&encoder, pInfo->commentSize) < 0) return -1;
if (tEncodeI32(&encoder, pInfo->codeSize) < 0) return -1; if (tEncodeI32(&encoder, pInfo->codeSize) < 0) return -1;
if (tEncodeCStr(&encoder, pInfo->pComment) < 0) return -1; if (tEncodeI32(&encoder, pInfo->commentSize) < 0) return -1;
if (tEncodeCStr(&encoder, pInfo->pCode) < 0) return -1; if (tEncodeCStr(&encoder, pInfo->pCode) < 0) return -1;
if (tEncodeCStr(&encoder, pInfo->pComment) < 0) return -1;
} }
tEndEncode(&encoder); tEndEncode(&encoder);
...@@ -1644,10 +1685,17 @@ int32_t tDeserializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp ...@@ -1644,10 +1685,17 @@ int32_t tDeserializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp
if (tDecodeI32(&decoder, &fInfo.outputLen) < 0) return -1; if (tDecodeI32(&decoder, &fInfo.outputLen) < 0) return -1;
if (tDecodeI32(&decoder, &fInfo.bufSize) < 0) return -1; if (tDecodeI32(&decoder, &fInfo.bufSize) < 0) return -1;
if (tDecodeI64(&decoder, &fInfo.signature) < 0) return -1; if (tDecodeI64(&decoder, &fInfo.signature) < 0) return -1;
if (tDecodeI32(&decoder, &fInfo.commentSize) < 0) return -1;
if (tDecodeI32(&decoder, &fInfo.codeSize) < 0) return -1; if (tDecodeI32(&decoder, &fInfo.codeSize) < 0) return -1;
if (tDecodeCStrTo(&decoder, fInfo.pComment) < 0) return -1; if (tDecodeI32(&decoder, &fInfo.commentSize) < 0) return -1;
fInfo.pCode = taosMemoryCalloc(1, fInfo.codeSize);
fInfo.pComment = taosMemoryCalloc(1, fInfo.commentSize);
if (fInfo.pCode == NULL || fInfo.pComment == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
if (tDecodeCStrTo(&decoder, fInfo.pCode) < 0) return -1; if (tDecodeCStrTo(&decoder, fInfo.pCode) < 0) return -1;
if (tDecodeCStrTo(&decoder, fInfo.pComment) < 0) return -1;
taosArrayPush(pRsp->pFuncInfos, &fInfo); taosArrayPush(pRsp->pFuncInfos, &fInfo);
} }
tEndDecode(&decoder); tEndDecode(&decoder);
...@@ -1656,6 +1704,16 @@ int32_t tDeserializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp ...@@ -1656,6 +1704,16 @@ int32_t tDeserializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp
return 0; return 0;
} }
void tFreeSRetrieveFuncRsp(SRetrieveFuncRsp *pRsp) {
int32_t size = taosArrayGetSize(pRsp->pFuncInfos);
for (int32_t i = 0; i < size; ++i) {
SFuncInfo *pInfo = taosArrayGet(pRsp->pFuncInfos, i);
taosMemoryFree(pInfo->pCode);
taosMemoryFree(pInfo->pComment);
}
taosArrayDestroy(pRsp->pFuncInfos);
}
int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) { int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) {
SCoder encoder = {0}; SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
......
...@@ -121,7 +121,7 @@ int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deploye ...@@ -121,7 +121,7 @@ int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deploye
int32_t len = 0; int32_t len = 0;
int32_t maxLen = 4096; int32_t maxLen = 4096;
char *content = taosMemoryCalloc(1, maxLen + 1); char *content = taosMemoryCalloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, "{\n");
len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n"); len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n");
......
...@@ -275,16 +275,17 @@ typedef struct { ...@@ -275,16 +275,17 @@ typedef struct {
} SDbCfg; } SDbCfg;
typedef struct { typedef struct {
char name[TSDB_DB_FNAME_LEN]; char name[TSDB_DB_FNAME_LEN];
char acct[TSDB_USER_LEN]; char acct[TSDB_USER_LEN];
char createUser[TSDB_USER_LEN]; char createUser[TSDB_USER_LEN];
int64_t createdTime; int64_t createdTime;
int64_t updateTime; int64_t updateTime;
int64_t uid; int64_t uid;
int32_t cfgVersion; int32_t cfgVersion;
int32_t vgVersion; int32_t vgVersion;
int8_t hashMethod; // default is 1 int8_t hashMethod; // default is 1
SDbCfg cfg; SDbCfg cfg;
SRWLatch lock;
} SDbObj; } SDbObj;
typedef struct { typedef struct {
......
...@@ -33,7 +33,7 @@ static int32_t mndProcessCreateBnodeReq(SNodeMsg *pReq); ...@@ -33,7 +33,7 @@ static int32_t mndProcessCreateBnodeReq(SNodeMsg *pReq);
static int32_t mndProcessCreateBnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessCreateBnodeRsp(SNodeMsg *pRsp);
static int32_t mndProcessDropBnodeReq(SNodeMsg *pReq); static int32_t mndProcessDropBnodeReq(SNodeMsg *pReq);
static int32_t mndProcessDropBnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessDropBnodeRsp(SNodeMsg *pRsp);
static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter); static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter);
int32_t mndInitBnode(SMnode *pMnode) { int32_t mndInitBnode(SMnode *pMnode) {
...@@ -437,7 +437,7 @@ static int32_t mndProcessDropBnodeRsp(SNodeMsg *pRsp) { ...@@ -437,7 +437,7 @@ static int32_t mndProcessDropBnodeRsp(SNodeMsg *pRsp) {
return 0; return 0;
} }
static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
SMnode *pMnode = pReq->pNode; SMnode *pMnode = pReq->pNode;
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
int32_t numOfRows = 0; int32_t numOfRows = 0;
...@@ -449,8 +449,8 @@ static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* p ...@@ -449,8 +449,8 @@ static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* p
if (pShow->pIter == NULL) break; if (pShow->pIter == NULL) break;
cols = 0; cols = 0;
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*) &pObj->id, false); colDataAppend(pColInfo, numOfRows, (const char *)&pObj->id, false);
char buf[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; char buf[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(buf, pObj->pDnode->ep, pShow->bytes[cols]); STR_WITH_MAXSIZE_TO_VARSTR(buf, pObj->pDnode->ep, pShow->bytes[cols]);
...@@ -459,7 +459,7 @@ static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* p ...@@ -459,7 +459,7 @@ static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* p
colDataAppend(pColInfo, numOfRows, buf, false); colDataAppend(pColInfo, numOfRows, buf, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*) &pObj->createdTime, false); colDataAppend(pColInfo, numOfRows, (const char *)&pObj->createdTime, false);
numOfRows++; numOfRows++;
sdbRelease(pSdb, pObj); sdbRelease(pSdb, pObj);
......
...@@ -219,10 +219,14 @@ static int32_t mndDbActionDelete(SSdb *pSdb, SDbObj *pDb) { ...@@ -219,10 +219,14 @@ static int32_t mndDbActionDelete(SSdb *pSdb, SDbObj *pDb) {
static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) { static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) {
mTrace("db:%s, perform update action, old row:%p new row:%p", pOld->name, pOld, pNew); mTrace("db:%s, perform update action, old row:%p new row:%p", pOld->name, pOld, pNew);
taosWLockLatch(&pOld->lock);
SArray *pOldRetensions = pOld->cfg.pRetensions;
pOld->updateTime = pNew->updateTime; pOld->updateTime = pNew->updateTime;
pOld->cfgVersion = pNew->cfgVersion; pOld->cfgVersion = pNew->cfgVersion;
pOld->vgVersion = pNew->vgVersion; pOld->vgVersion = pNew->vgVersion;
memcpy(&pOld->cfg, &pNew->cfg, sizeof(SDbCfg)); memcpy(&pOld->cfg, &pNew->cfg, sizeof(SDbCfg));
pNew->cfg.pRetensions = pOldRetensions;
taosWUnLockLatch(&pOld->lock);
return 0; return 0;
} }
......
...@@ -34,7 +34,7 @@ static int32_t mndDropFunc(SMnode *pMnode, SNodeMsg *pReq, SFuncObj *pFunc); ...@@ -34,7 +34,7 @@ static int32_t mndDropFunc(SMnode *pMnode, SNodeMsg *pReq, SFuncObj *pFunc);
static int32_t mndProcessCreateFuncReq(SNodeMsg *pReq); static int32_t mndProcessCreateFuncReq(SNodeMsg *pReq);
static int32_t mndProcessDropFuncReq(SNodeMsg *pReq); static int32_t mndProcessDropFuncReq(SNodeMsg *pReq);
static int32_t mndProcessRetrieveFuncReq(SNodeMsg *pReq); static int32_t mndProcessRetrieveFuncReq(SNodeMsg *pReq);
static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
static void mndCancelGetNextFunc(SMnode *pMnode, void *pIter); static void mndCancelGetNextFunc(SMnode *pMnode, void *pIter);
int32_t mndInitFunc(SMnode *pMnode) { int32_t mndInitFunc(SMnode *pMnode) {
...@@ -63,28 +63,28 @@ static SSdbRaw *mndFuncActionEncode(SFuncObj *pFunc) { ...@@ -63,28 +63,28 @@ static SSdbRaw *mndFuncActionEncode(SFuncObj *pFunc) {
int32_t size = pFunc->commentSize + pFunc->codeSize + sizeof(SFuncObj) + SDB_FUNC_RESERVE_SIZE; int32_t size = pFunc->commentSize + pFunc->codeSize + sizeof(SFuncObj) + SDB_FUNC_RESERVE_SIZE;
SSdbRaw *pRaw = sdbAllocRaw(SDB_FUNC, SDB_FUNC_VER, size); SSdbRaw *pRaw = sdbAllocRaw(SDB_FUNC, SDB_FUNC_VER, size);
if (pRaw == NULL) goto FUNC_ENCODE_OVER; if (pRaw == NULL) goto _OVER;
int32_t dataPos = 0; int32_t dataPos = 0;
SDB_SET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN, FUNC_ENCODE_OVER) SDB_SET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN, _OVER)
SDB_SET_INT64(pRaw, dataPos, pFunc->createdTime, FUNC_ENCODE_OVER) SDB_SET_INT64(pRaw, dataPos, pFunc->createdTime, _OVER)
SDB_SET_INT8(pRaw, dataPos, pFunc->funcType, FUNC_ENCODE_OVER) SDB_SET_INT8(pRaw, dataPos, pFunc->funcType, _OVER)
SDB_SET_INT8(pRaw, dataPos, pFunc->scriptType, FUNC_ENCODE_OVER) SDB_SET_INT8(pRaw, dataPos, pFunc->scriptType, _OVER)
SDB_SET_INT8(pRaw, dataPos, pFunc->align, FUNC_ENCODE_OVER) SDB_SET_INT8(pRaw, dataPos, pFunc->align, _OVER)
SDB_SET_INT8(pRaw, dataPos, pFunc->outputType, FUNC_ENCODE_OVER) SDB_SET_INT8(pRaw, dataPos, pFunc->outputType, _OVER)
SDB_SET_INT32(pRaw, dataPos, pFunc->outputLen, FUNC_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pFunc->outputLen, _OVER)
SDB_SET_INT32(pRaw, dataPos, pFunc->bufSize, FUNC_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pFunc->bufSize, _OVER)
SDB_SET_INT64(pRaw, dataPos, pFunc->signature, FUNC_ENCODE_OVER) SDB_SET_INT64(pRaw, dataPos, pFunc->signature, _OVER)
SDB_SET_INT32(pRaw, dataPos, pFunc->commentSize, FUNC_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pFunc->commentSize, _OVER)
SDB_SET_INT32(pRaw, dataPos, pFunc->codeSize, FUNC_ENCODE_OVER) SDB_SET_INT32(pRaw, dataPos, pFunc->codeSize, _OVER)
SDB_SET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, FUNC_ENCODE_OVER) SDB_SET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, _OVER)
SDB_SET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize, FUNC_ENCODE_OVER) SDB_SET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize, _OVER)
SDB_SET_RESERVE(pRaw, dataPos, SDB_FUNC_RESERVE_SIZE, FUNC_ENCODE_OVER) SDB_SET_RESERVE(pRaw, dataPos, SDB_FUNC_RESERVE_SIZE, _OVER)
SDB_SET_DATALEN(pRaw, dataPos, FUNC_ENCODE_OVER); SDB_SET_DATALEN(pRaw, dataPos, _OVER);
terrno = 0; terrno = 0;
FUNC_ENCODE_OVER: _OVER:
if (terrno != 0) { if (terrno != 0) {
mError("func:%s, failed to encode to raw:%p since %s", pFunc->name, pRaw, terrstr()); mError("func:%s, failed to encode to raw:%p since %s", pFunc->name, pRaw, terrstr());
sdbFreeRaw(pRaw); sdbFreeRaw(pRaw);
...@@ -99,45 +99,45 @@ static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) { ...@@ -99,45 +99,45 @@ static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
int8_t sver = 0; int8_t sver = 0;
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto FUNC_DECODE_OVER; if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
if (sver != SDB_FUNC_VER) { if (sver != SDB_FUNC_VER) {
terrno = TSDB_CODE_SDB_INVALID_DATA_VER; terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
goto FUNC_DECODE_OVER; goto _OVER;
} }
SSdbRow *pRow = sdbAllocRow(sizeof(SFuncObj)); SSdbRow *pRow = sdbAllocRow(sizeof(SFuncObj));
if (pRow == NULL) goto FUNC_DECODE_OVER; if (pRow == NULL) goto _OVER;
SFuncObj *pFunc = sdbGetRowObj(pRow); SFuncObj *pFunc = sdbGetRowObj(pRow);
if (pFunc == NULL) goto FUNC_DECODE_OVER; if (pFunc == NULL) goto _OVER;
int32_t dataPos = 0; int32_t dataPos = 0;
SDB_GET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN, FUNC_DECODE_OVER) SDB_GET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN, _OVER)
SDB_GET_INT64(pRaw, dataPos, &pFunc->createdTime, FUNC_DECODE_OVER) SDB_GET_INT64(pRaw, dataPos, &pFunc->createdTime, _OVER)
SDB_GET_INT8(pRaw, dataPos, &pFunc->funcType, FUNC_DECODE_OVER) SDB_GET_INT8(pRaw, dataPos, &pFunc->funcType, _OVER)
SDB_GET_INT8(pRaw, dataPos, &pFunc->scriptType, FUNC_DECODE_OVER) SDB_GET_INT8(pRaw, dataPos, &pFunc->scriptType, _OVER)
SDB_GET_INT8(pRaw, dataPos, &pFunc->align, FUNC_DECODE_OVER) SDB_GET_INT8(pRaw, dataPos, &pFunc->align, _OVER)
SDB_GET_INT8(pRaw, dataPos, &pFunc->outputType, FUNC_DECODE_OVER) SDB_GET_INT8(pRaw, dataPos, &pFunc->outputType, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pFunc->outputLen, FUNC_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pFunc->outputLen, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pFunc->bufSize, FUNC_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pFunc->bufSize, _OVER)
SDB_GET_INT64(pRaw, dataPos, &pFunc->signature, FUNC_DECODE_OVER) SDB_GET_INT64(pRaw, dataPos, &pFunc->signature, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pFunc->commentSize, FUNC_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pFunc->commentSize, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pFunc->codeSize, FUNC_DECODE_OVER) SDB_GET_INT32(pRaw, dataPos, &pFunc->codeSize, _OVER)
pFunc->pComment = taosMemoryCalloc(1, pFunc->commentSize); pFunc->pComment = taosMemoryCalloc(1, pFunc->commentSize);
pFunc->pCode = taosMemoryCalloc(1, pFunc->codeSize); pFunc->pCode = taosMemoryCalloc(1, pFunc->codeSize);
if (pFunc->pComment == NULL || pFunc->pCode == NULL) { if (pFunc->pComment == NULL || pFunc->pCode == NULL) {
goto FUNC_DECODE_OVER; goto _OVER;
} }
SDB_GET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, FUNC_DECODE_OVER) SDB_GET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, _OVER)
SDB_GET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize, FUNC_DECODE_OVER) SDB_GET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize, _OVER)
SDB_GET_RESERVE(pRaw, dataPos, SDB_FUNC_RESERVE_SIZE, FUNC_DECODE_OVER) SDB_GET_RESERVE(pRaw, dataPos, SDB_FUNC_RESERVE_SIZE, _OVER)
terrno = 0; terrno = 0;
FUNC_DECODE_OVER: _OVER:
if (terrno != 0) { if (terrno != 0) {
mError("func:%s, failed to decode from raw:%p since %s", pFunc->name, pRaw, terrstr()); mError("func:%s, failed to decode from raw:%p since %s", pFunc->name, pRaw, terrstr());
taosMemoryFreeClear(pRow); taosMemoryFreeClear(pRow);
...@@ -192,40 +192,40 @@ static int32_t mndCreateFunc(SMnode *pMnode, SNodeMsg *pReq, SCreateFuncReq *pCr ...@@ -192,40 +192,40 @@ static int32_t mndCreateFunc(SMnode *pMnode, SNodeMsg *pReq, SCreateFuncReq *pCr
func.outputLen = pCreate->outputLen; func.outputLen = pCreate->outputLen;
func.bufSize = pCreate->bufSize; func.bufSize = pCreate->bufSize;
func.signature = pCreate->signature; func.signature = pCreate->signature;
func.commentSize = pCreate->commentSize; func.commentSize = strlen(pCreate->pComment) + 1;
func.codeSize = pCreate->codeSize; func.codeSize = strlen(pCreate->pCode) + 1;
func.pComment = taosMemoryMalloc(func.commentSize); func.pComment = taosMemoryMalloc(func.commentSize);
func.pCode = taosMemoryMalloc(func.codeSize); func.pCode = taosMemoryMalloc(func.codeSize);
if (func.pCode == NULL || func.pCode == NULL) { if (func.pCode == NULL || func.pCode == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
goto CREATE_FUNC_OVER; goto _OVER;
} }
memcpy(func.pComment, pCreate->pComment, pCreate->commentSize); memcpy(func.pComment, pCreate->pComment, func.commentSize);
memcpy(func.pCode, pCreate->pCode, func.codeSize); memcpy(func.pCode, pCreate->pCode, func.codeSize);
pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_FUNC, &pReq->rpcMsg); pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_FUNC, &pReq->rpcMsg);
if (pTrans == NULL) goto CREATE_FUNC_OVER; if (pTrans == NULL) goto _OVER;
mDebug("trans:%d, used to create func:%s", pTrans->id, pCreate->name); mDebug("trans:%d, used to create func:%s", pTrans->id, pCreate->name);
SSdbRaw *pRedoRaw = mndFuncActionEncode(&func); SSdbRaw *pRedoRaw = mndFuncActionEncode(&func);
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) goto CREATE_FUNC_OVER; if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) goto _OVER;
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) goto CREATE_FUNC_OVER; if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) goto _OVER;
SSdbRaw *pUndoRaw = mndFuncActionEncode(&func); SSdbRaw *pUndoRaw = mndFuncActionEncode(&func);
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) goto CREATE_FUNC_OVER; if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) goto _OVER;
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) goto CREATE_FUNC_OVER; if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) goto _OVER;
SSdbRaw *pCommitRaw = mndFuncActionEncode(&func); SSdbRaw *pCommitRaw = mndFuncActionEncode(&func);
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) goto CREATE_FUNC_OVER; if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) goto _OVER;
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) goto CREATE_FUNC_OVER; if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) goto _OVER;
if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_FUNC_OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
code = 0; code = 0;
CREATE_FUNC_OVER: _OVER:
taosMemoryFree(func.pCode); taosMemoryFree(func.pCode);
taosMemoryFree(func.pComment); taosMemoryFree(func.pComment);
mndTransDrop(pTrans); mndTransDrop(pTrans);
...@@ -235,27 +235,27 @@ CREATE_FUNC_OVER: ...@@ -235,27 +235,27 @@ CREATE_FUNC_OVER:
static int32_t mndDropFunc(SMnode *pMnode, SNodeMsg *pReq, SFuncObj *pFunc) { static int32_t mndDropFunc(SMnode *pMnode, SNodeMsg *pReq, SFuncObj *pFunc) {
int32_t code = -1; int32_t code = -1;
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_DROP_FUNC, &pReq->rpcMsg); STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_DROP_FUNC, &pReq->rpcMsg);
if (pTrans == NULL) goto DROP_FUNC_OVER; if (pTrans == NULL) goto _OVER;
mDebug("trans:%d, used to drop user:%s", pTrans->id, pFunc->name); mDebug("trans:%d, used to drop user:%s", pTrans->id, pFunc->name);
SSdbRaw *pRedoRaw = mndFuncActionEncode(pFunc); SSdbRaw *pRedoRaw = mndFuncActionEncode(pFunc);
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) goto DROP_FUNC_OVER; if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) goto _OVER;
sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING); sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING);
SSdbRaw *pUndoRaw = mndFuncActionEncode(pFunc); SSdbRaw *pUndoRaw = mndFuncActionEncode(pFunc);
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) goto DROP_FUNC_OVER; if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) goto _OVER;
sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY); sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY);
SSdbRaw *pCommitRaw = mndFuncActionEncode(pFunc); SSdbRaw *pCommitRaw = mndFuncActionEncode(pFunc);
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) goto DROP_FUNC_OVER; if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) goto _OVER;
sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED); sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_FUNC_OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
code = 0; code = 0;
DROP_FUNC_OVER: _OVER:
mndTransDrop(pTrans); mndTransDrop(pTrans);
return code; return code;
} }
...@@ -269,7 +269,7 @@ static int32_t mndProcessCreateFuncReq(SNodeMsg *pReq) { ...@@ -269,7 +269,7 @@ static int32_t mndProcessCreateFuncReq(SNodeMsg *pReq) {
if (tDeserializeSCreateFuncReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &createReq) != 0) { if (tDeserializeSCreateFuncReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &createReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG; terrno = TSDB_CODE_INVALID_MSG;
goto CREATE_FUNC_OVER; goto _OVER;
} }
mDebug("func:%s, start to create", createReq.name); mDebug("func:%s, start to create", createReq.name);
...@@ -279,60 +279,66 @@ static int32_t mndProcessCreateFuncReq(SNodeMsg *pReq) { ...@@ -279,60 +279,66 @@ static int32_t mndProcessCreateFuncReq(SNodeMsg *pReq) {
if (createReq.igExists) { if (createReq.igExists) {
mDebug("func:%s, already exist, ignore exist is set", createReq.name); mDebug("func:%s, already exist, ignore exist is set", createReq.name);
code = 0; code = 0;
goto CREATE_FUNC_OVER; goto _OVER;
} else { } else {
terrno = TSDB_CODE_MND_FUNC_ALREADY_EXIST; terrno = TSDB_CODE_MND_FUNC_ALREADY_EXIST;
goto CREATE_FUNC_OVER; goto _OVER;
} }
} else if (terrno == TSDB_CODE_MND_FUNC_ALREADY_EXIST) { } else if (terrno == TSDB_CODE_MND_FUNC_ALREADY_EXIST) {
goto CREATE_FUNC_OVER; goto _OVER;
} }
if (createReq.name[0] == 0) { if (createReq.name[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_FUNC_NAME; terrno = TSDB_CODE_MND_INVALID_FUNC_NAME;
goto CREATE_FUNC_OVER; goto _OVER;
} }
if (createReq.commentSize <= 0 || createReq.commentSize > TSDB_FUNC_COMMENT_LEN) { if (createReq.pComment == NULL) {
terrno = TSDB_CODE_MND_INVALID_FUNC_COMMENT; terrno = TSDB_CODE_MND_INVALID_FUNC_COMMENT;
goto CREATE_FUNC_OVER; goto _OVER;
} }
if (createReq.codeSize <= 0 || createReq.codeSize > TSDB_FUNC_CODE_LEN) { if (createReq.pComment[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_FUNC_COMMENT;
goto _OVER;
}
if (createReq.pCode == NULL) {
terrno = TSDB_CODE_MND_INVALID_FUNC_CODE; terrno = TSDB_CODE_MND_INVALID_FUNC_CODE;
goto CREATE_FUNC_OVER; goto _OVER;
} }
if (createReq.pCode[0] == 0) { if (createReq.pCode[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_FUNC_CODE; terrno = TSDB_CODE_MND_INVALID_FUNC_CODE;
goto CREATE_FUNC_OVER; goto _OVER;
} }
if (createReq.bufSize <= 0 || createReq.bufSize > TSDB_FUNC_BUF_SIZE) { if (createReq.bufSize <= 0 || createReq.bufSize > TSDB_FUNC_BUF_SIZE) {
terrno = TSDB_CODE_MND_INVALID_FUNC_BUFSIZE; terrno = TSDB_CODE_MND_INVALID_FUNC_BUFSIZE;
goto CREATE_FUNC_OVER; goto _OVER;
} }
pUser = mndAcquireUser(pMnode, pReq->user); pUser = mndAcquireUser(pMnode, pReq->user);
if (pUser == NULL) { if (pUser == NULL) {
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
goto CREATE_FUNC_OVER; goto _OVER;
} }
if (mndCheckFuncAuth(pUser)) { if (mndCheckFuncAuth(pUser)) {
goto CREATE_FUNC_OVER; goto _OVER;
} }
code = mndCreateFunc(pMnode, pReq, &createReq); code = mndCreateFunc(pMnode, pReq, &createReq);
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
CREATE_FUNC_OVER: _OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("func:%s, failed to create since %s", createReq.name, terrstr()); mError("func:%s, failed to create since %s", createReq.name, terrstr());
} }
mndReleaseFunc(pMnode, pFunc); mndReleaseFunc(pMnode, pFunc);
mndReleaseUser(pMnode, pUser); mndReleaseUser(pMnode, pUser);
tFreeSCreateFuncReq(&createReq);
return code; return code;
} }
...@@ -346,14 +352,14 @@ static int32_t mndProcessDropFuncReq(SNodeMsg *pReq) { ...@@ -346,14 +352,14 @@ static int32_t mndProcessDropFuncReq(SNodeMsg *pReq) {
if (tDeserializeSDropFuncReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &dropReq) != 0) { if (tDeserializeSDropFuncReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &dropReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG; terrno = TSDB_CODE_INVALID_MSG;
goto DROP_FUNC_OVER; goto _OVER;
} }
mDebug("func:%s, start to drop", dropReq.name); mDebug("func:%s, start to drop", dropReq.name);
if (dropReq.name[0] == 0) { if (dropReq.name[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_FUNC_NAME; terrno = TSDB_CODE_MND_INVALID_FUNC_NAME;
goto DROP_FUNC_OVER; goto _OVER;
} }
pFunc = mndAcquireFunc(pMnode, dropReq.name); pFunc = mndAcquireFunc(pMnode, dropReq.name);
...@@ -361,27 +367,27 @@ static int32_t mndProcessDropFuncReq(SNodeMsg *pReq) { ...@@ -361,27 +367,27 @@ static int32_t mndProcessDropFuncReq(SNodeMsg *pReq) {
if (dropReq.igNotExists) { if (dropReq.igNotExists) {
mDebug("func:%s, not exist, ignore not exist is set", dropReq.name); mDebug("func:%s, not exist, ignore not exist is set", dropReq.name);
code = 0; code = 0;
goto DROP_FUNC_OVER; goto _OVER;
} else { } else {
terrno = TSDB_CODE_MND_FUNC_NOT_EXIST; terrno = TSDB_CODE_MND_FUNC_NOT_EXIST;
goto DROP_FUNC_OVER; goto _OVER;
} }
} }
pUser = mndAcquireUser(pMnode, pReq->user); pUser = mndAcquireUser(pMnode, pReq->user);
if (pUser == NULL) { if (pUser == NULL) {
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
goto DROP_FUNC_OVER; goto _OVER;
} }
if (mndCheckFuncAuth(pUser)) { if (mndCheckFuncAuth(pUser)) {
goto DROP_FUNC_OVER; goto _OVER;
} }
code = mndDropFunc(pMnode, pReq, pFunc); code = mndDropFunc(pMnode, pReq, pFunc);
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS; if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
DROP_FUNC_OVER: _OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("func:%s, failed to drop since %s", dropReq.name, terrstr()); mError("func:%s, failed to drop since %s", dropReq.name, terrstr());
} }
...@@ -434,6 +440,12 @@ static int32_t mndProcessRetrieveFuncReq(SNodeMsg *pReq) { ...@@ -434,6 +440,12 @@ static int32_t mndProcessRetrieveFuncReq(SNodeMsg *pReq) {
funcInfo.signature = pFunc->signature; funcInfo.signature = pFunc->signature;
funcInfo.commentSize = pFunc->commentSize; funcInfo.commentSize = pFunc->commentSize;
funcInfo.codeSize = pFunc->codeSize; funcInfo.codeSize = pFunc->codeSize;
funcInfo.pCode = taosMemoryCalloc(1, sizeof(funcInfo.codeSize));
funcInfo.pComment = taosMemoryCalloc(1, sizeof(funcInfo.commentSize));
if (funcInfo.pCode == NULL || funcInfo.pComment == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto RETRIEVE_FUNC_OVER;
}
memcpy(funcInfo.pComment, pFunc->pComment, pFunc->commentSize); memcpy(funcInfo.pComment, pFunc->pComment, pFunc->commentSize);
memcpy(funcInfo.pCode, pFunc->pCode, pFunc->codeSize); memcpy(funcInfo.pCode, pFunc->pCode, pFunc->codeSize);
taosArrayPush(retrieveRsp.pFuncInfos, &funcInfo); taosArrayPush(retrieveRsp.pFuncInfos, &funcInfo);
...@@ -455,8 +467,8 @@ static int32_t mndProcessRetrieveFuncReq(SNodeMsg *pReq) { ...@@ -455,8 +467,8 @@ static int32_t mndProcessRetrieveFuncReq(SNodeMsg *pReq) {
code = 0; code = 0;
RETRIEVE_FUNC_OVER: RETRIEVE_FUNC_OVER:
taosArrayDestroy(retrieveReq.pFuncNames); tFreeSRetrieveFuncReq(&retrieveReq);
taosArrayDestroy(retrieveRsp.pFuncInfos); tFreeSRetrieveFuncRsp(&retrieveRsp);
return code; return code;
} }
...@@ -479,7 +491,7 @@ static void *mnodeGenTypeStr(char *buf, int32_t buflen, uint8_t type, int16_t le ...@@ -479,7 +491,7 @@ static void *mnodeGenTypeStr(char *buf, int32_t buflen, uint8_t type, int16_t le
return tDataTypes[type].name; return tDataTypes[type].name;
} }
static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
SMnode *pMnode = pReq->pNode; SMnode *pMnode = pReq->pNode;
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
int32_t numOfRows = 0; int32_t numOfRows = 0;
...@@ -496,34 +508,35 @@ static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pB ...@@ -496,34 +508,35 @@ static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pB
char b1[tListLen(pFunc->name) + VARSTR_HEADER_SIZE] = {0}; char b1[tListLen(pFunc->name) + VARSTR_HEADER_SIZE] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(b1, pFunc->name, pShow->bytes[cols]); STR_WITH_MAXSIZE_TO_VARSTR(b1, pFunc->name, pShow->bytes[cols]);
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*) b1, false); colDataAppend(pColInfo, numOfRows, (const char *)b1, false);
char* b2 = taosMemoryCalloc(1, pShow->bytes[cols]); char *b2 = taosMemoryCalloc(1, pShow->bytes[cols]);
STR_WITH_MAXSIZE_TO_VARSTR(b2, pFunc->pComment, pShow->bytes[cols]); STR_WITH_MAXSIZE_TO_VARSTR(b2, pFunc->pComment, pShow->bytes[cols]);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*) b2, false); colDataAppend(pColInfo, numOfRows, (const char *)b2, false);
int32_t isAgg = (pFunc->funcType == TSDB_FUNC_TYPE_AGGREGATE) ? 1 : 0; int32_t isAgg = (pFunc->funcType == TSDB_FUNC_TYPE_AGGREGATE) ? 1 : 0;
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*) &isAgg, false); colDataAppend(pColInfo, numOfRows, (const char *)&isAgg, false);
char b3[TSDB_TYPE_STR_MAX_LEN] = {0}; char b3[TSDB_TYPE_STR_MAX_LEN] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(b3, mnodeGenTypeStr(buf, TSDB_TYPE_STR_MAX_LEN, pFunc->outputType, pFunc->outputLen), pShow->bytes[cols]); STR_WITH_MAXSIZE_TO_VARSTR(b3, mnodeGenTypeStr(buf, TSDB_TYPE_STR_MAX_LEN, pFunc->outputType, pFunc->outputLen),
pShow->bytes[cols]);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*) b3, false); colDataAppend(pColInfo, numOfRows, (const char *)b3, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*) &pFunc->createdTime, false); colDataAppend(pColInfo, numOfRows, (const char *)&pFunc->createdTime, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*) &pFunc->codeSize, false); colDataAppend(pColInfo, numOfRows, (const char *)&pFunc->codeSize, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*) &pFunc->bufSize, false); colDataAppend(pColInfo, numOfRows, (const char *)&pFunc->bufSize, false);
numOfRows++; numOfRows++;
sdbRelease(pSdb, pFunc); sdbRelease(pSdb, pFunc);
......
...@@ -78,13 +78,13 @@ void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pObj) { ...@@ -78,13 +78,13 @@ void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pObj) {
const char *mndGetRoleStr(int32_t showType) { const char *mndGetRoleStr(int32_t showType) {
switch (showType) { switch (showType) {
case TAOS_SYNC_STATE_FOLLOWER: case TAOS_SYNC_STATE_FOLLOWER:
return "unsynced"; return "FOLLOWER";
case TAOS_SYNC_STATE_CANDIDATE: case TAOS_SYNC_STATE_CANDIDATE:
return "slave"; return "CANDIDATE";
case TAOS_SYNC_STATE_LEADER: case TAOS_SYNC_STATE_LEADER:
return "master"; return "LEADER";
default: default:
return "undefined"; return "ERROR";
} }
} }
...@@ -615,7 +615,7 @@ static int32_t mndProcessDropMnodeRsp(SNodeMsg *pRsp) { ...@@ -615,7 +615,7 @@ static int32_t mndProcessDropMnodeRsp(SNodeMsg *pRsp) {
return 0; return 0;
} }
static int32_t mndRetrieveMnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { static int32_t mndRetrieveMnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
SMnode *pMnode = pReq->pNode; SMnode *pMnode = pReq->pNode;
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
int32_t numOfRows = 0; int32_t numOfRows = 0;
...@@ -628,8 +628,8 @@ static int32_t mndRetrieveMnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* p ...@@ -628,8 +628,8 @@ static int32_t mndRetrieveMnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* p
if (pShow->pIter == NULL) break; if (pShow->pIter == NULL) break;
cols = 0; cols = 0;
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*) &pObj->id, false); colDataAppend(pColInfo, numOfRows, (const char *)&pObj->id, false);
char b1[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; char b1[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(b1, pObj->pDnode->ep, pShow->bytes[cols]); STR_WITH_MAXSIZE_TO_VARSTR(b1, pObj->pDnode->ep, pShow->bytes[cols]);
...@@ -638,11 +638,11 @@ static int32_t mndRetrieveMnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* p ...@@ -638,11 +638,11 @@ static int32_t mndRetrieveMnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* p
colDataAppend(pColInfo, numOfRows, b1, false); colDataAppend(pColInfo, numOfRows, b1, false);
const char *roles = mndGetRoleStr(pObj->role); const char *roles = mndGetRoleStr(pObj->role);
char* b2 = taosMemoryCalloc(1, strlen(roles) + VARSTR_HEADER_SIZE); char *b2 = taosMemoryCalloc(1, strlen(roles) + VARSTR_HEADER_SIZE);
STR_WITH_MAXSIZE_TO_VARSTR(b2, roles, pShow->bytes[cols]); STR_WITH_MAXSIZE_TO_VARSTR(b2, roles, pShow->bytes[cols]);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*) b2, false); colDataAppend(pColInfo, numOfRows, (const char *)b2, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char *)&pObj->roleTime, false); colDataAppend(pColInfo, numOfRows, (const char *)&pObj->roleTime, false);
......
...@@ -34,7 +34,7 @@ static int32_t mndProcessCreateQnodeRsp(SNodeMsg *pRsp); ...@@ -34,7 +34,7 @@ static int32_t mndProcessCreateQnodeRsp(SNodeMsg *pRsp);
static int32_t mndProcessDropQnodeReq(SNodeMsg *pReq); static int32_t mndProcessDropQnodeReq(SNodeMsg *pReq);
static int32_t mndProcessDropQnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessDropQnodeRsp(SNodeMsg *pRsp);
static int32_t mndProcessQnodeListReq(SNodeMsg *pReq); static int32_t mndProcessQnodeListReq(SNodeMsg *pReq);
static int32_t mndRetrieveQnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static int32_t mndRetrieveQnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
static void mndCancelGetNextQnode(SMnode *pMnode, void *pIter); static void mndCancelGetNextQnode(SMnode *pMnode, void *pIter);
int32_t mndInitQnode(SMnode *pMnode) { int32_t mndInitQnode(SMnode *pMnode) {
...@@ -497,7 +497,7 @@ static int32_t mndProcessDropQnodeRsp(SNodeMsg *pRsp) { ...@@ -497,7 +497,7 @@ static int32_t mndProcessDropQnodeRsp(SNodeMsg *pRsp) {
return 0; return 0;
} }
static int32_t mndRetrieveQnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { static int32_t mndRetrieveQnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
SMnode *pMnode = pReq->pNode; SMnode *pMnode = pReq->pNode;
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
int32_t numOfRows = 0; int32_t numOfRows = 0;
...@@ -510,8 +510,8 @@ static int32_t mndRetrieveQnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* p ...@@ -510,8 +510,8 @@ static int32_t mndRetrieveQnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* p
if (pShow->pIter == NULL) break; if (pShow->pIter == NULL) break;
cols = 0; cols = 0;
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*)&pObj->id, false); colDataAppend(pColInfo, numOfRows, (const char *)&pObj->id, false);
char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->bytes[cols]); STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->bytes[cols]);
......
...@@ -33,7 +33,7 @@ static int32_t mndProcessCreateSnodeReq(SNodeMsg *pReq); ...@@ -33,7 +33,7 @@ static int32_t mndProcessCreateSnodeReq(SNodeMsg *pReq);
static int32_t mndProcessCreateSnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessCreateSnodeRsp(SNodeMsg *pRsp);
static int32_t mndProcessDropSnodeReq(SNodeMsg *pReq); static int32_t mndProcessDropSnodeReq(SNodeMsg *pReq);
static int32_t mndProcessDropSnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessDropSnodeRsp(SNodeMsg *pRsp);
static int32_t mndRetrieveSnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static int32_t mndRetrieveSnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
static void mndCancelGetNextSnode(SMnode *pMnode, void *pIter); static void mndCancelGetNextSnode(SMnode *pMnode, void *pIter);
int32_t mndInitSnode(SMnode *pMnode) { int32_t mndInitSnode(SMnode *pMnode) {
...@@ -447,7 +447,7 @@ static int32_t mndProcessDropSnodeRsp(SNodeMsg *pRsp) { ...@@ -447,7 +447,7 @@ static int32_t mndProcessDropSnodeRsp(SNodeMsg *pRsp) {
return 0; return 0;
} }
static int32_t mndRetrieveSnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { static int32_t mndRetrieveSnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
SMnode *pMnode = pReq->pNode; SMnode *pMnode = pReq->pNode;
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
int32_t numOfRows = 0; int32_t numOfRows = 0;
...@@ -459,8 +459,8 @@ static int32_t mndRetrieveSnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* p ...@@ -459,8 +459,8 @@ static int32_t mndRetrieveSnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* p
if (pShow->pIter == NULL) break; if (pShow->pIter == NULL) break;
cols = 0; cols = 0;
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataAppend(pColInfo, numOfRows, (const char*)&pObj->id, false); colDataAppend(pColInfo, numOfRows, (const char *)&pObj->id, false);
char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->bytes[cols]); STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->bytes[cols]);
......
...@@ -21,10 +21,25 @@ class MndTestFunc : public ::testing::Test { ...@@ -21,10 +21,25 @@ class MndTestFunc : public ::testing::Test {
public: public:
void SetUp() override {} void SetUp() override {}
void TearDown() override {} void TearDown() override {}
void SetCode(SCreateFuncReq* pReq, const char* pCode);
void SetComment(SCreateFuncReq* pReq, const char* pComment);
}; };
Testbase MndTestFunc::test; Testbase MndTestFunc::test;
void MndTestFunc::SetCode(SCreateFuncReq* pReq, const char* pCode) {
int32_t len = strlen(pCode);
pReq->pCode = (char*)taosMemoryCalloc(1, len + 1);
strcpy(pReq->pCode, pCode);
}
void MndTestFunc::SetComment(SCreateFuncReq* pReq, const char* pComment) {
int32_t len = strlen(pComment);
pReq->pComment = (char*)taosMemoryCalloc(1, len + 1);
strcpy(pReq->pComment, pComment);
}
TEST_F(MndTestFunc, 01_Show_Func) { TEST_F(MndTestFunc, 01_Show_Func) {
test.SendShowReq(TSDB_MGMT_TABLE_FUNC, "user_functions", ""); test.SendShowReq(TSDB_MGMT_TABLE_FUNC, "user_functions", "");
EXPECT_EQ(test.GetShowRows(), 0); EXPECT_EQ(test.GetShowRows(), 0);
...@@ -38,6 +53,7 @@ TEST_F(MndTestFunc, 02_Create_Func) { ...@@ -38,6 +53,7 @@ TEST_F(MndTestFunc, 02_Create_Func) {
int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSCreateFuncReq(pReq, contLen, &createReq); tSerializeSCreateFuncReq(pReq, contLen, &createReq);
tFreeSCreateFuncReq(&createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -47,10 +63,12 @@ TEST_F(MndTestFunc, 02_Create_Func) { ...@@ -47,10 +63,12 @@ TEST_F(MndTestFunc, 02_Create_Func) {
{ {
SCreateFuncReq createReq = {0}; SCreateFuncReq createReq = {0};
strcpy(createReq.name, "f1"); strcpy(createReq.name, "f1");
SetCode(&createReq, "code1");
int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSCreateFuncReq(pReq, contLen, &createReq); tSerializeSCreateFuncReq(pReq, contLen, &createReq);
tFreeSCreateFuncReq(&createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -60,25 +78,12 @@ TEST_F(MndTestFunc, 02_Create_Func) { ...@@ -60,25 +78,12 @@ TEST_F(MndTestFunc, 02_Create_Func) {
{ {
SCreateFuncReq createReq = {0}; SCreateFuncReq createReq = {0};
strcpy(createReq.name, "f1"); strcpy(createReq.name, "f1");
createReq.commentSize = TSDB_FUNC_COMMENT_LEN + 1; SetComment(&createReq, "comment1");
int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateFuncReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_COMMENT);
}
{
SCreateFuncReq createReq = {0};
strcpy(createReq.name, "f1");
createReq.commentSize = TSDB_FUNC_COMMENT_LEN;
int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSCreateFuncReq(pReq, contLen, &createReq); tSerializeSCreateFuncReq(pReq, contLen, &createReq);
tFreeSCreateFuncReq(&createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -88,27 +93,29 @@ TEST_F(MndTestFunc, 02_Create_Func) { ...@@ -88,27 +93,29 @@ TEST_F(MndTestFunc, 02_Create_Func) {
{ {
SCreateFuncReq createReq = {0}; SCreateFuncReq createReq = {0};
strcpy(createReq.name, "f1"); strcpy(createReq.name, "f1");
createReq.commentSize = TSDB_FUNC_COMMENT_LEN; SetCode(&createReq, "code1");
createReq.codeSize = TSDB_FUNC_CODE_LEN + 1; SetComment(&createReq, "");
int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSCreateFuncReq(pReq, contLen, &createReq); tSerializeSCreateFuncReq(pReq, contLen, &createReq);
tFreeSCreateFuncReq(&createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_CODE); ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_COMMENT);
} }
{ {
SCreateFuncReq createReq = {0}; SCreateFuncReq createReq = {0};
strcpy(createReq.name, "f1"); strcpy(createReq.name, "f1");
createReq.commentSize = TSDB_FUNC_COMMENT_LEN; SetCode(&createReq, "");
createReq.codeSize = TSDB_FUNC_CODE_LEN; SetComment(&createReq, "comment1");
int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSCreateFuncReq(pReq, contLen, &createReq); tSerializeSCreateFuncReq(pReq, contLen, &createReq);
tFreeSCreateFuncReq(&createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -118,13 +125,13 @@ TEST_F(MndTestFunc, 02_Create_Func) { ...@@ -118,13 +125,13 @@ TEST_F(MndTestFunc, 02_Create_Func) {
{ {
SCreateFuncReq createReq = {0}; SCreateFuncReq createReq = {0};
strcpy(createReq.name, "f1"); strcpy(createReq.name, "f1");
createReq.commentSize = TSDB_FUNC_COMMENT_LEN; SetCode(&createReq, "code1");
createReq.codeSize = TSDB_FUNC_CODE_LEN; SetComment(&createReq, "comment1");
createReq.pCode[0] = 'a';
int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSCreateFuncReq(pReq, contLen, &createReq); tSerializeSCreateFuncReq(pReq, contLen, &createReq);
tFreeSCreateFuncReq(&createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -134,14 +141,14 @@ TEST_F(MndTestFunc, 02_Create_Func) { ...@@ -134,14 +141,14 @@ TEST_F(MndTestFunc, 02_Create_Func) {
{ {
SCreateFuncReq createReq = {0}; SCreateFuncReq createReq = {0};
strcpy(createReq.name, "f1"); strcpy(createReq.name, "f1");
createReq.commentSize = TSDB_FUNC_COMMENT_LEN; SetCode(&createReq, "code1");
createReq.codeSize = TSDB_FUNC_CODE_LEN; SetComment(&createReq, "comment1");
createReq.pCode[0] = 'a';
createReq.bufSize = TSDB_FUNC_BUF_SIZE + 1; createReq.bufSize = TSDB_FUNC_BUF_SIZE + 1;
int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSCreateFuncReq(pReq, contLen, &createReq); tSerializeSCreateFuncReq(pReq, contLen, &createReq);
tFreeSCreateFuncReq(&createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -151,9 +158,8 @@ TEST_F(MndTestFunc, 02_Create_Func) { ...@@ -151,9 +158,8 @@ TEST_F(MndTestFunc, 02_Create_Func) {
for (int32_t i = 0; i < 3; ++i) { for (int32_t i = 0; i < 3; ++i) {
SCreateFuncReq createReq = {0}; SCreateFuncReq createReq = {0};
strcpy(createReq.name, "f1"); strcpy(createReq.name, "f1");
createReq.commentSize = TSDB_FUNC_COMMENT_LEN; SetCode(&createReq, "code1");
createReq.codeSize = TSDB_FUNC_CODE_LEN; SetComment(&createReq, "comment1");
createReq.pCode[0] = 'a';
createReq.bufSize = TSDB_FUNC_BUF_SIZE + 1; createReq.bufSize = TSDB_FUNC_BUF_SIZE + 1;
createReq.igExists = 0; createReq.igExists = 0;
if (i == 2) createReq.igExists = 1; if (i == 2) createReq.igExists = 1;
...@@ -163,16 +169,11 @@ TEST_F(MndTestFunc, 02_Create_Func) { ...@@ -163,16 +169,11 @@ TEST_F(MndTestFunc, 02_Create_Func) {
createReq.outputLen = 12; createReq.outputLen = 12;
createReq.bufSize = 4; createReq.bufSize = 4;
createReq.signature = 5; createReq.signature = 5;
for (int32_t i = 0; i < createReq.commentSize - 1; ++i) {
createReq.pComment[i] = 'm';
}
for (int32_t i = 0; i < createReq.codeSize - 1; ++i) {
createReq.pCode[i] = 'd';
}
int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSCreateFuncReq(pReq, contLen, &createReq); tSerializeSCreateFuncReq(pReq, contLen, &createReq);
tFreeSCreateFuncReq(&createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -197,7 +198,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -197,7 +198,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq); int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq); tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
taosArrayDestroy(retrieveReq.pFuncNames); tFreeSRetrieveFuncReq(&retrieveReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -217,20 +218,10 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -217,20 +218,10 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
EXPECT_EQ(pFuncInfo->outputLen, 12); EXPECT_EQ(pFuncInfo->outputLen, 12);
EXPECT_EQ(pFuncInfo->bufSize, 4); EXPECT_EQ(pFuncInfo->bufSize, 4);
EXPECT_EQ(pFuncInfo->signature, 5); EXPECT_EQ(pFuncInfo->signature, 5);
EXPECT_EQ(pFuncInfo->commentSize, TSDB_FUNC_COMMENT_LEN); EXPECT_STREQ("comment1", pFuncInfo->pComment);
EXPECT_EQ(pFuncInfo->codeSize, TSDB_FUNC_CODE_LEN); EXPECT_STREQ("code1", pFuncInfo->pCode);
char comments[TSDB_FUNC_COMMENT_LEN] = {0}; tFreeSRetrieveFuncRsp(&retrieveRsp);
for (int32_t i = 0; i < TSDB_FUNC_COMMENT_LEN - 1; ++i) {
comments[i] = 'm';
}
char codes[TSDB_FUNC_CODE_LEN] = {0};
for (int32_t i = 0; i < TSDB_FUNC_CODE_LEN - 1; ++i) {
codes[i] = 'd';
}
EXPECT_STREQ(comments, pFuncInfo->pComment);
EXPECT_STREQ(codes, pFuncInfo->pCode);
taosArrayDestroy(retrieveRsp.pFuncInfos);
} }
{ {
...@@ -241,7 +232,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -241,7 +232,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq); int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq); tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
taosArrayDestroy(retrieveReq.pFuncNames); tFreeSRetrieveFuncReq(&retrieveReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -259,7 +250,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -259,7 +250,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq); int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq); tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
taosArrayDestroy(retrieveReq.pFuncNames); tFreeSRetrieveFuncReq(&retrieveReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -275,7 +266,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -275,7 +266,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq); int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq); tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
taosArrayDestroy(retrieveReq.pFuncNames); tFreeSRetrieveFuncReq(&retrieveReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -285,8 +276,6 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -285,8 +276,6 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
{ {
SCreateFuncReq createReq = {0}; SCreateFuncReq createReq = {0};
strcpy(createReq.name, "f2"); strcpy(createReq.name, "f2");
createReq.commentSize = 1024;
createReq.codeSize = 9527;
createReq.igExists = 1; createReq.igExists = 1;
createReq.funcType = 2; createReq.funcType = 2;
createReq.scriptType = 3; createReq.scriptType = 3;
...@@ -294,16 +283,13 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -294,16 +283,13 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
createReq.outputLen = 24; createReq.outputLen = 24;
createReq.bufSize = 6; createReq.bufSize = 6;
createReq.signature = 18; createReq.signature = 18;
for (int32_t i = 0; i < createReq.commentSize - 1; ++i) { SetCode(&createReq, "code2");
createReq.pComment[i] = 'p'; SetComment(&createReq, "comment2");
}
for (int32_t i = 0; i < createReq.codeSize - 1; ++i) {
createReq.pCode[i] = 'q';
}
int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSCreateFuncReq(pReq, contLen, &createReq); tSerializeSCreateFuncReq(pReq, contLen, &createReq);
tFreeSCreateFuncReq(&createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -322,7 +308,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -322,7 +308,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq); int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq); tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
taosArrayDestroy(retrieveReq.pFuncNames); tFreeSRetrieveFuncReq(&retrieveReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -342,21 +328,13 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -342,21 +328,13 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
EXPECT_EQ(pFuncInfo->outputLen, 24); EXPECT_EQ(pFuncInfo->outputLen, 24);
EXPECT_EQ(pFuncInfo->bufSize, 6); EXPECT_EQ(pFuncInfo->bufSize, 6);
EXPECT_EQ(pFuncInfo->signature, 18); EXPECT_EQ(pFuncInfo->signature, 18);
EXPECT_EQ(pFuncInfo->commentSize, 1024); EXPECT_EQ(pFuncInfo->commentSize, strlen("comment2") + 1);
EXPECT_EQ(pFuncInfo->codeSize, 9527); EXPECT_EQ(pFuncInfo->codeSize, strlen("code2") + 1);
char comments[TSDB_FUNC_COMMENT_LEN] = {0}; EXPECT_STREQ("comment2", pFuncInfo->pComment);
for (int32_t i = 0; i < 1024 - 1; ++i) { EXPECT_STREQ("code2", pFuncInfo->pCode);
comments[i] = 'p';
}
char codes[TSDB_FUNC_CODE_LEN] = {0};
for (int32_t i = 0; i < 9527 - 1; ++i) {
codes[i] = 'q';
}
EXPECT_STREQ(comments, pFuncInfo->pComment); tFreeSRetrieveFuncRsp(&retrieveRsp);
EXPECT_STREQ(codes, pFuncInfo->pCode);
taosArrayDestroy(retrieveRsp.pFuncInfos);
} }
{ {
...@@ -369,7 +347,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -369,7 +347,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq); int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq); tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
taosArrayDestroy(retrieveReq.pFuncNames); tFreeSRetrieveFuncReq(&retrieveReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -389,20 +367,10 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -389,20 +367,10 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
EXPECT_EQ(pFuncInfo->outputLen, 24); EXPECT_EQ(pFuncInfo->outputLen, 24);
EXPECT_EQ(pFuncInfo->bufSize, 6); EXPECT_EQ(pFuncInfo->bufSize, 6);
EXPECT_EQ(pFuncInfo->signature, 18); EXPECT_EQ(pFuncInfo->signature, 18);
EXPECT_EQ(pFuncInfo->commentSize, 1024); EXPECT_EQ(pFuncInfo->commentSize, strlen("comment2") + 1);
EXPECT_EQ(pFuncInfo->codeSize, 9527); EXPECT_EQ(pFuncInfo->codeSize, strlen("code2") + 1);
EXPECT_STREQ("comment2", pFuncInfo->pComment);
char comments[TSDB_FUNC_COMMENT_LEN] = {0}; EXPECT_STREQ("code2", pFuncInfo->pCode);
for (int32_t i = 0; i < 1024 - 1; ++i) {
comments[i] = 'p';
}
char codes[TSDB_FUNC_CODE_LEN] = {0};
for (int32_t i = 0; i < 9527 - 1; ++i) {
codes[i] = 'q';
}
EXPECT_STREQ(comments, pFuncInfo->pComment);
EXPECT_STREQ(codes, pFuncInfo->pCode);
} }
{ {
...@@ -414,21 +382,11 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -414,21 +382,11 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
EXPECT_EQ(pFuncInfo->outputLen, 12); EXPECT_EQ(pFuncInfo->outputLen, 12);
EXPECT_EQ(pFuncInfo->bufSize, 4); EXPECT_EQ(pFuncInfo->bufSize, 4);
EXPECT_EQ(pFuncInfo->signature, 5); EXPECT_EQ(pFuncInfo->signature, 5);
EXPECT_EQ(pFuncInfo->commentSize, TSDB_FUNC_COMMENT_LEN); EXPECT_STREQ("comment1", pFuncInfo->pComment);
EXPECT_EQ(pFuncInfo->codeSize, TSDB_FUNC_CODE_LEN); EXPECT_STREQ("code1", pFuncInfo->pCode);
char comments[TSDB_FUNC_COMMENT_LEN] = {0};
for (int32_t i = 0; i < TSDB_FUNC_COMMENT_LEN - 1; ++i) {
comments[i] = 'm';
}
char codes[TSDB_FUNC_CODE_LEN] = {0};
for (int32_t i = 0; i < TSDB_FUNC_CODE_LEN - 1; ++i) {
codes[i] = 'd';
}
EXPECT_STREQ(comments, pFuncInfo->pComment);
EXPECT_STREQ(codes, pFuncInfo->pCode);
} }
taosArrayDestroy(retrieveRsp.pFuncInfos);
tFreeSRetrieveFuncRsp(&retrieveRsp);
} }
{ {
...@@ -441,7 +399,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -441,7 +399,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq); int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
void* pReq = rpcMallocCont(contLen); void* pReq = rpcMallocCont(contLen);
tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq); tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
taosArrayDestroy(retrieveReq.pFuncNames); tFreeSRetrieveFuncReq(&retrieveReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
......
...@@ -772,6 +772,9 @@ int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) { ...@@ -772,6 +772,9 @@ int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) {
if (pFile == NULL) { if (pFile == NULL) {
return -1; return -1;
} }
if (*ptrBuf != NULL) {
taosMemoryFreeClear(*ptrBuf);
}
assert(pFile->fp != NULL); assert(pFile->fp != NULL);
size_t len = 0; size_t len = 0;
......
...@@ -24,7 +24,7 @@ if $data00 != 1 then ...@@ -24,7 +24,7 @@ if $data00 != 1 then
return -1 return -1
endi endi
if $data02 != master then if $data02 != LEADER then
return -1 return -1
endi endi
...@@ -71,7 +71,7 @@ if $data00 != 1 then ...@@ -71,7 +71,7 @@ if $data00 != 1 then
return -1 return -1
endi endi
if $data02 != master then if $data02 != LEADER then
return -1 return -1
endi endi
......
...@@ -72,7 +72,7 @@ print rows: $rows ...@@ -72,7 +72,7 @@ print rows: $rows
print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ====> dataX_db print ====> dataX_db
print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db print $data(db)[0] $data(db)[1] $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db
if $rows != 3 then if $rows != 3 then
return -1 return -1
......
...@@ -17,7 +17,6 @@ print =============== step1 ...@@ -17,7 +17,6 @@ print =============== step1
# quorum presicion # quorum presicion
sql create database $db vgroups 8 replica 1 days 2880 keep 3650 cache 32 blocks 12 minrows 80 maxrows 10000 wal 2 fsync 1000 comp 0 cachelast 2 precision 'us' sql create database $db vgroups 8 replica 1 days 2880 keep 3650 cache 32 blocks 12 minrows 80 maxrows 10000 wal 2 fsync 1000 comp 0 cachelast 2 precision 'us'
sql show databases sql show databases
print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1
print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
if $rows != 3 then if $rows != 3 then
......
...@@ -29,7 +29,7 @@ if $data00 != 1 then ...@@ -29,7 +29,7 @@ if $data00 != 1 then
return -1 return -1
endi endi
if $data02 != master then if $data02 != LEADER then
return -1 return -1
endi endi
...@@ -76,7 +76,7 @@ if $data00 != 1 then ...@@ -76,7 +76,7 @@ if $data00 != 1 then
return -1 return -1
endi endi
if $data02 != master then if $data02 != LEADER then
return -1 return -1
endi endi
......
...@@ -24,7 +24,7 @@ if $data00 != 1 then ...@@ -24,7 +24,7 @@ if $data00 != 1 then
return -1 return -1
endi endi
if $data02 != master then if $data02 != LEADER then
return -1 return -1
endi endi
...@@ -71,7 +71,7 @@ if $data00 != 1 then ...@@ -71,7 +71,7 @@ if $data00 != 1 then
return -1 return -1
endi endi
if $data02 != master then if $data02 != LEADER then
return -1 return -1
endi endi
......
...@@ -24,7 +24,7 @@ if $data00 != 1 then ...@@ -24,7 +24,7 @@ if $data00 != 1 then
return -1 return -1
endi endi
if $data02 != master then if $data02 != LEADER then
return -1 return -1
endi endi
...@@ -71,7 +71,7 @@ if $data00 != 1 then ...@@ -71,7 +71,7 @@ if $data00 != 1 then
return -1 return -1
endi endi
if $data02 != master then if $data02 != LEADER then
return -1 return -1
endi endi
......
...@@ -4,7 +4,7 @@ system sh/deploy.sh -n dnode1 -i 1 ...@@ -4,7 +4,7 @@ system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c wallevel -v 2 system sh/cfg.sh -n dnode1 -c wallevel -v 2
system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1
print ========= start dnode1 as master print ========= start dnode1 as LEADER
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start
sleep 2000 sleep 2000
sql connect sql connect
......
...@@ -26,14 +26,6 @@ sql connect ...@@ -26,14 +26,6 @@ sql connect
$vgroups = 4 $vgroups = 4
$dbNamme = d0 $dbNamme = d0
print ====> create database d1 precision 'us'
sql create database d1 precision 'us'
sql use d1
sql create table dev_001 (ts timestamp ,i timestamp ,j int)
sql insert into dev_001 values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4)
sql create table secondts(ts timestamp,t2 timestamp,i int)
sql insert into secondts values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4)
print ====> create database $dbNamme vgroups $vgroups print ====> create database $dbNamme vgroups $vgroups
sql create database $dbNamme vgroups $vgroups sql create database $dbNamme vgroups $vgroups
sql show databases sql show databases
...@@ -296,11 +288,14 @@ sql_error select count(*) from dev_001 session(i,1y) ...@@ -296,11 +288,14 @@ sql_error select count(*) from dev_001 session(i,1y)
sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0' sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0'
# vnode does not return the precision of the table # vnode does not return the precision of the table
#print ====> create database d1 precision 'us' print ====> create database d1 precision 'us'
#sql create database d1 precision 'us' sql create database d1 precision 'us'
#sql use d1 sql use d1
#sql create table dev_001 (ts timestamp ,i timestamp ,j int) sql create table dev_001 (ts timestamp ,i timestamp ,j int)
#sql insert into dev_001 values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4) sql insert into dev_001 values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4)
sql create table secondts(ts timestamp,t2 timestamp,i int)
sql insert into secondts values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4)
#print ====> select count(*) from dev_001 session(ts,1u) #print ====> select count(*) from dev_001 session(ts,1u)
#sql select _wstartts, count(*) from dev_001 session(ts,1u) #sql select _wstartts, count(*) from dev_001 session(ts,1u)
#print rows: $rows #print rows: $rows
...@@ -312,14 +307,12 @@ sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0: ...@@ -312,14 +307,12 @@ sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:
# print expect 2, actual: $rows # print expect 2, actual: $rows
# return -1 # return -1
#endi #endi
#
#if $data01 != 1 then #if $data01 != 1 then
# return -1 # return -1
#endi #endi
#sql_error select count(*) from dev_001 session(i,1s) sql_error select count(*) from dev_001 session(i,1s)
sql create table secondts(ts timestamp,t2 timestamp,i int) sql_error select count(*) from secondts session(t2,2s)
#sql_error select count(*) from secondts session(t2,2s)
if $loop_test == 0 then if $loop_test == 0 then
print =============== stop and restart taosd print =============== stop and restart taosd
......
...@@ -24,7 +24,7 @@ if $data00 != 1 then ...@@ -24,7 +24,7 @@ if $data00 != 1 then
return -1 return -1
endi endi
if $data02 != master then if $data02 != LEADER then
return -1 return -1
endi endi
...@@ -71,7 +71,7 @@ if $data00 != 1 then ...@@ -71,7 +71,7 @@ if $data00 != 1 then
return -1 return -1
endi endi
if $data02 != master then if $data02 != LEADER then
return -1 return -1
endi endi
......
...@@ -9,9 +9,9 @@ if $rows != 1 then ...@@ -9,9 +9,9 @@ if $rows != 1 then
return -1 return -1
endi endi
print $data00 $data01 $data02 print $data[0][0] $data[0][1] $data[0][2]
print $data10 $data11 $data22 print $data[1][0] $data[1][1] $data[1][2]
print $data20 $data11 $data22 print $data[2][0] $data[1][2] $data[2][2]
sql_error show accounts; sql_error show accounts;
sql_error create account a pass "a" sql_error create account a pass "a"
...@@ -25,10 +25,10 @@ if $rows != 2 then ...@@ -25,10 +25,10 @@ if $rows != 2 then
return -1 return -1
endi endi
print $data00 $data01 $data02 print $data[0][0] $data[0][1] $data[0][2]
print $data10 $data11 $data12 print $data[1][0] $data[1][1] $data[1][2]
print $data20 $data11 $data22 print $data[2][0] $data[1][2] $data[2][2]
print $data30 $data31 $data32 print $data[3][0] $data[3][1] $data[3][2]
print =============== create user2 print =============== create user2
sql create user user2 PASS 'user2' sql create user user2 PASS 'user2'
...@@ -37,10 +37,10 @@ if $rows != 3 then ...@@ -37,10 +37,10 @@ if $rows != 3 then
return -1 return -1
endi endi
print $data00 $data01 $data02 print $data[0][0] $data[0][1] $data[0][2]
print $data10 $data11 $data12 print $data[1][0] $data[1][1] $data[1][2]
print $data20 $data11 $data22 print $data[2][0] $data[1][2] $data[2][2]
print $data30 $data31 $data32 print $data[3][0] $data[3][1] $data[3][2]
print $data40 $data41 $data42 print $data40 $data41 $data42
print =============== drop user1 print =============== drop user1
...@@ -50,10 +50,10 @@ if $rows != 2 then ...@@ -50,10 +50,10 @@ if $rows != 2 then
return -1 return -1
endi endi
print $data00 $data01 $data02 print $data[0][0] $data[0][1] $data[0][2]
print $data10 $data11 $data22 print $data[1][0] $data[1][1] $data[1][2]
print $data20 $data11 $data22 print $data[2][0] $data[1][2] $data[2][2]
print $data30 $data31 $data32 print $data[3][0] $data[3][1] $data[3][2]
print =============== restart taosd print =============== restart taosd
system sh/exec.sh -n dnode1 -s stop system sh/exec.sh -n dnode1 -s stop
...@@ -66,9 +66,9 @@ if $rows != 2 then ...@@ -66,9 +66,9 @@ if $rows != 2 then
return -1 return -1
endi endi
print $data00 $data01 $data02 print $data[0][0] $data[0][1] $data[0][2]
print $data10 $data11 $data22 print $data[1][0] $data[1][1] $data[1][2]
print $data20 $data11 $data22 print $data[2][0] $data[1][2] $data[2][2]
print $data30 $data31 $data32 print $data[3][0] $data[3][1] $data[3][2]
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s stop -x SIGINT
...@@ -33,9 +33,9 @@ ...@@ -33,9 +33,9 @@
#define MAX_BACKGROUND_SCRIPT_NUM 10 #define MAX_BACKGROUND_SCRIPT_NUM 10
#define MAX_FILE_NAME_LEN 256 #define MAX_FILE_NAME_LEN 256
#define MAX_ERROR_LEN 1024 #define MAX_ERROR_LEN 1024
#define MAX_QUERY_VALUE_LEN 10240 #define MAX_QUERY_VALUE_LEN 1024
#define MAX_QUERY_COL_NUM 20 #define MAX_QUERY_COL_NUM 100
#define MAX_QUERY_ROW_NUM 20 #define MAX_QUERY_ROW_NUM 100
#define MAX_SYSTEM_RESULT_LEN 2048 #define MAX_SYSTEM_RESULT_LEN 2048
#define MAX_VAR_LEN 100 #define MAX_VAR_LEN 100
#define MAX_VAR_NAME_LEN 32 #define MAX_VAR_NAME_LEN 32
......
...@@ -49,6 +49,41 @@ char *simParseHostName(char *varName) { ...@@ -49,6 +49,41 @@ char *simParseHostName(char *varName) {
return hostName; return hostName;
} }
static void simFindFirstNum(const char *begin, int32_t beginLen, int32_t *num) {
if (beginLen <= 5) {
*num = 0;
} else {
*num = atoi(begin + 5);
}
}
static void simFindSecondNum(const char *begin, int32_t beginLen, int32_t *num) {
const char *number = strstr(begin, "][");
if (number == NULL) {
*num = 0;
} else {
*num = atoi(number + 2);
}
}
static void simFindFirstKeyVal(const char *begin, int32_t beginLen, char *key, int32_t keyLen) {
key[0] = 0;
for (int32_t i = 5; i < beginLen && i - 5 < keyLen; ++i) {
if (begin[i] != 0 && begin[i] != ']' && begin[i] != ')') {
key[i - 5] = begin[i];
}
}
}
static void simFindSecondKeyNum(const char *begin, int32_t beginLen, int32_t *num) {
const char *number = strstr(begin, ")[");
if (number == NULL) {
*num = 0;
} else {
*num = atoi(number + 2);
}
}
char *simGetVariable(SScript *script, char *varName, int32_t varLen) { char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
if (strncmp(varName, "hostname", 8) == 0) { if (strncmp(varName, "hostname", 8) == 0) {
return simParseHostName(varName); return simParseHostName(varName);
...@@ -66,13 +101,40 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -66,13 +101,40 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
if (strncmp(varName, "system_content", varLen) == 0) return script->system_ret_content; if (strncmp(varName, "system_content", varLen) == 0) return script->system_ret_content;
// variable like data2_192.168.0.1
if (strncmp(varName, "data", 4) == 0) { if (strncmp(varName, "data", 4) == 0) {
if (varLen < 6) { if (varLen < 6) {
return "null"; return "null";
} }
if (varName[5] == '_') { int32_t row = 0;
int32_t col = 0;
char keyVal[1024] = {0};
int32_t keyLen = 1024;
if (varName[4] == '[') {
// $data[0][1]
simFindFirstNum(varName, varLen, &row);
simFindSecondNum(varName, varLen, &col);
if (row < 0 || row >= MAX_QUERY_ROW_NUM) {
return "null";
}
if (col < 0 || col >= MAX_QUERY_COL_NUM) {
return "null";
}
simDebug("script:%s, data[%d][%d]=%s", script->fileName, row, col, script->data[row][col]);
return script->data[row][col];
} else if (varName[4] == '(') {
// $data(db)[0]
simFindFirstKeyVal(varName, varLen, keyVal, keyLen);
simFindSecondKeyNum(varName, varLen, &col);
for (int32_t i = 0; i < MAX_QUERY_ROW_NUM; ++i) {
if (strncmp(keyVal, script->data[i][0], keyLen) == 0) {
simDebug("script:%s, keyName:%s, keyValue:%s", script->fileName, script->data[i][0], script->data[i][col]);
return script->data[i][col];
}
}
} else if (varName[5] == '_') {
// data2_db
int32_t col = varName[4] - '0'; int32_t col = varName[4] - '0';
if (col < 0 || col >= MAX_QUERY_COL_NUM) { if (col < 0 || col >= MAX_QUERY_COL_NUM) {
return "null"; return "null";
...@@ -90,6 +152,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -90,6 +152,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
} }
return "null"; return "null";
} else if (varName[6] == '_') { } else if (varName[6] == '_') {
// data21_db
int32_t col = (varName[4] - '0') * 10 + (varName[5] - '0'); int32_t col = (varName[4] - '0') * 10 + (varName[5] - '0');
if (col < 0 || col >= MAX_QUERY_COL_NUM) { if (col < 0 || col >= MAX_QUERY_COL_NUM) {
return "null"; return "null";
...@@ -107,6 +170,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -107,6 +170,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
} }
return "null"; return "null";
} else { } else {
// $data00
int32_t row = varName[4] - '0'; int32_t row = varName[4] - '0';
int32_t col = varName[5] - '0'; int32_t col = varName[5] - '0';
if (row < 0 || row >= MAX_QUERY_ROW_NUM) { if (row < 0 || row >= MAX_QUERY_ROW_NUM) {
...@@ -119,6 +183,8 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -119,6 +183,8 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
simDebug("script:%s, data[%d][%d]=%s", script->fileName, row, col, script->data[row][col]); simDebug("script:%s, data[%d][%d]=%s", script->fileName, row, col, script->data[row][col]);
return script->data[row][col]; return script->data[row][col];
} }
return "null";
} }
for (int32_t i = 0; i < script->varLen; ++i) { for (int32_t i = 0; i < script->varLen; ++i) {
...@@ -127,9 +193,6 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -127,9 +193,6 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
continue; continue;
} }
if (strncmp(varName, var->varName, varLen) == 0) { if (strncmp(varName, var->varName, varLen) == 0) {
// if (strlen(var->varValue) != 0)
// simDebug("script:%s, var:%s, value:%s", script->fileName,
// var->varName, var->varValue);
return var->varValue; return var->varValue;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册