未验证 提交 028496a1 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #10254 from taosdata/feature/privilege

serialize request
...@@ -275,6 +275,7 @@ typedef struct { ...@@ -275,6 +275,7 @@ typedef struct {
int32_t tSerializeSMCreateStbReq(void** buf, SMCreateStbReq* pReq); int32_t tSerializeSMCreateStbReq(void** buf, SMCreateStbReq* pReq);
void* tDeserializeSMCreateStbReq(void* buf, SMCreateStbReq* pReq); void* tDeserializeSMCreateStbReq(void* buf, SMCreateStbReq* pReq);
void tFreeSMCreateStbReq(SMCreateStbReq* pReq);
typedef struct { typedef struct {
char name[TSDB_TABLE_FNAME_LEN]; char name[TSDB_TABLE_FNAME_LEN];
...@@ -328,6 +329,26 @@ static FORCE_INLINE void* taosDecodeSEpSet(void* buf, SEpSet* pEp) { ...@@ -328,6 +329,26 @@ static FORCE_INLINE void* taosDecodeSEpSet(void* buf, SEpSet* pEp) {
return buf; return buf;
} }
static FORCE_INLINE int32_t tEncodeSEpSet(SCoder* pEncoder, const SEpSet* pEp) {
if (tEncodeI8(pEncoder, pEp->inUse) < 0) return -1;
if (tEncodeI8(pEncoder, pEp->numOfEps) < 0) return -1;
for (int i = 0; i < TSDB_MAX_REPLICA; i++) {
if (tEncodeU16(pEncoder, pEp->eps[i].port) < 0) return -1;
if (tEncodeCStr(pEncoder, pEp->eps[i].fqdn) < 0) return -1;
}
return 0;
}
static FORCE_INLINE int32_t tDecodeSEpSet(SCoder* pDecoder, SEpSet* pEp) {
if (tDecodeI8(pDecoder, &pEp->inUse) < 0) return -1;
if (tDecodeI8(pDecoder, &pEp->numOfEps) < 0) return -1;
for (int i = 0; i < TSDB_MAX_REPLICA; i++) {
if (tDecodeU16(pDecoder, &pEp->eps[i].port) < 0) return -1;
if (tDecodeCStrTo(pDecoder, pEp->eps[i].fqdn) < 0) return -1;
}
return 0;
}
typedef struct { typedef struct {
int32_t acctId; int32_t acctId;
int64_t clusterId; int64_t clusterId;
...@@ -525,28 +546,6 @@ typedef struct { ...@@ -525,28 +546,6 @@ typedef struct {
int32_t code; int32_t code;
} SQueryTableRsp; } SQueryTableRsp;
// todo: the show handle should be replaced with id
typedef struct {
SMsgHead header;
union {
int64_t showId;
int64_t qhandle;
int64_t qId;
}; // query handle
int8_t free;
} SRetrieveTableReq;
typedef struct {
int64_t useconds;
int8_t completed; // all results are returned to client
int8_t precision;
int8_t compressed;
int32_t compLen;
int32_t numOfRows;
char data[];
} SRetrieveTableRsp;
typedef struct { typedef struct {
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
int32_t numOfVgroups; int32_t numOfVgroups;
...@@ -612,6 +611,27 @@ typedef struct { ...@@ -612,6 +611,27 @@ typedef struct {
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq); int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq); int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
typedef struct {
char db[TSDB_DB_FNAME_LEN];
uint64_t uid;
int32_t vgVersion;
int32_t vgNum;
int8_t hashMethod;
SArray* pVgroupInfos; // Array of SVgroupInfo
} SUseDbRsp;
int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
int32_t tDeserializeSUseDbRsp(void* buf, int32_t bufLen, SUseDbRsp* pRsp);
void tFreeSUsedbRsp(SUseDbRsp* pRsp);
typedef struct {
SArray* pArray; // Array of SUseDbRsp
} SUseDbBatchRsp;
int32_t tSerializeSUseDbBatchRsp(void* buf, int32_t bufLen, SUseDbBatchRsp* pRsp);
int32_t tDeserializeSUseDbBatchRsp(void* buf, int32_t bufLen, SUseDbBatchRsp* pRsp);
void tFreeSUseDbBatchRsp(SUseDbBatchRsp* pRsp);
typedef struct { typedef struct {
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
} SSyncDbReq, SCompactDbReq; } SSyncDbReq, SCompactDbReq;
...@@ -841,27 +861,22 @@ typedef struct { ...@@ -841,27 +861,22 @@ typedef struct {
char* data; char* data;
} STagData; } STagData;
typedef struct {
char db[TSDB_DB_FNAME_LEN];
uint64_t uid;
int32_t vgVersion;
int32_t vgNum;
int8_t hashMethod;
SVgroupInfo vgroupInfo[];
} SUseDbRsp;
/* /*
* sql: show tables like '%a_%' * sql: show tables like '%a_%'
* payload is the query condition, e.g., '%a_%' * payload is the query condition, e.g., '%a_%'
* payloadLen is the length of payload * payloadLen is the length of payload
*/ */
typedef struct { typedef struct {
int8_t type; int32_t type;
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
int16_t payloadLen; int32_t payloadLen;
char payload[]; char* payload;
} SShowReq; } SShowReq;
int32_t tSerializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
int32_t tDeserializeSShowReq(void* buf, int32_t bufLen, SShowReq* pReq);
void tFreeSShowReq(SShowReq* pReq);
typedef struct { typedef struct {
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
int32_t numOfVgroup; int32_t numOfVgroup;
...@@ -873,6 +888,26 @@ typedef struct { ...@@ -873,6 +888,26 @@ typedef struct {
STableMetaRsp tableMeta; STableMetaRsp tableMeta;
} SShowRsp; } SShowRsp;
// todo: the show handle should be replaced with id
typedef struct {
int64_t showId;
int8_t free;
} SRetrieveTableReq;
int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq);
typedef struct {
int64_t useconds;
int8_t completed; // all results are returned to client
int8_t precision;
int8_t compressed;
int32_t compLen;
int32_t numOfRows;
char data[];
} SRetrieveTableRsp;
typedef struct { typedef struct {
char fqdn[TSDB_FQDN_LEN]; // end point, hostname:port char fqdn[TSDB_FQDN_LEN]; // end point, hostname:port
int32_t port; int32_t port;
...@@ -1535,43 +1570,30 @@ typedef struct { ...@@ -1535,43 +1570,30 @@ typedef struct {
SArray* rsps; // SArray<SClientHbRsp> SArray* rsps; // SArray<SClientHbRsp>
} SClientHbBatchRsp; } SClientHbBatchRsp;
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); }
return taosIntHash_64(key, keyLen);
}
int tSerializeSClientHbReq(void** buf, const SClientHbReq* pReq);
void* tDeserializeSClientHbReq(void* buf, SClientHbReq* pReq);
int tSerializeSClientHbRsp(void** buf, const SClientHbRsp* pRsp);
void* tDeserializeSClientHbRsp(void* buf, SClientHbRsp* pRsp);
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) {
static FORCE_INLINE void tFreeReqKvHash(SHashObj* info) { void* pIter = taosHashIterate(info, NULL);
void *pIter = taosHashIterate(info, NULL);
while (pIter != NULL) { while (pIter != NULL) {
SKv* kv = (SKv*)pIter; SKv* kv = (SKv*)pIter;
tfree(kv->value); tfree(kv->value);
pIter = taosHashIterate(info, pIter); pIter = taosHashIterate(info, pIter);
} }
} }
static FORCE_INLINE void tFreeClientHbReq(void* pReq) {
static FORCE_INLINE void tFreeClientHbReq(void *pReq) {
SClientHbReq* req = (SClientHbReq*)pReq; SClientHbReq* req = (SClientHbReq*)pReq;
if (req->info) { if (req->info) {
tFreeReqKvHash(req->info); tFreeReqKvHash(req->info);
taosHashCleanup(req->info); taosHashCleanup(req->info);
} }
} }
int tSerializeSClientHbBatchReq(void** buf, const SClientHbBatchReq* pReq); int32_t tSerializeSClientHbBatchReq(void* buf, int32_t bufLen, const SClientHbBatchReq* pReq);
void* tDeserializeSClientHbBatchReq(void* buf, SClientHbBatchReq* pReq); int32_t tDeserializeSClientHbBatchReq(void* buf, int32_t bufLen, SClientHbBatchReq* pReq);
static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq, bool deep) { static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq, bool deep) {
SClientHbBatchReq *req = (SClientHbBatchReq*)pReq; SClientHbBatchReq* req = (SClientHbBatchReq*)pReq;
if (deep) { if (deep) {
taosArrayDestroyEx(req->reqs, tFreeClientHbReq); taosArrayDestroyEx(req->reqs, tFreeClientHbReq);
} else { } else {
...@@ -1580,54 +1602,52 @@ static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq, bool deep) { ...@@ -1580,54 +1602,52 @@ static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq, bool deep) {
free(pReq); free(pReq);
} }
static FORCE_INLINE void tFreeClientKv(void *pKv) { static FORCE_INLINE void tFreeClientKv(void* pKv) {
SKv *kv = (SKv *)pKv; SKv* kv = (SKv*)pKv;
if (kv) { if (kv) {
tfree(kv->value); tfree(kv->value);
} }
} }
static FORCE_INLINE void tFreeClientHbRsp(void *pRsp) { static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) {
SClientHbRsp* rsp = (SClientHbRsp*)pRsp; SClientHbRsp* rsp = (SClientHbRsp*)pRsp;
if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv); if (rsp->info) taosArrayDestroyEx(rsp->info, tFreeClientKv);
} }
static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) { static FORCE_INLINE void tFreeClientHbBatchRsp(void* pRsp) {
SClientHbBatchRsp *rsp = (SClientHbBatchRsp*)pRsp; SClientHbBatchRsp* rsp = (SClientHbBatchRsp*)pRsp;
taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp); taosArrayDestroyEx(rsp->rsps, tFreeClientHbRsp);
} }
int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
int tSerializeSClientHbBatchRsp(void** buf, const SClientHbBatchRsp* pBatchRsp); static FORCE_INLINE int32_t tEncodeSKv(SCoder* pEncoder, const SKv* pKv) {
void* tDeserializeSClientHbBatchRsp(void* buf, SClientHbBatchRsp* pBatchRsp); if (tEncodeI32(pEncoder, pKv->key) < 0) return -1;
if (tEncodeI32(pEncoder, pKv->valueLen) < 0) return -1;
static FORCE_INLINE int taosEncodeSKv(void** buf, const SKv* pKv) { if (tEncodeCStrWithLen(pEncoder, (const char*)pKv->value, pKv->valueLen) < 0) return -1;
int tlen = 0; return 0;
tlen += taosEncodeFixedI32(buf, pKv->key);
tlen += taosEncodeFixedI32(buf, pKv->valueLen);
tlen += taosEncodeBinary(buf, pKv->value, pKv->valueLen);
return tlen;
} }
static FORCE_INLINE void* taosDecodeSKv(void* buf, SKv* pKv) { static FORCE_INLINE int32_t tDecodeSKv(SCoder* pDecoder, SKv* pKv) {
buf = taosDecodeFixedI32(buf, &pKv->key); if (tDecodeI32(pDecoder, &pKv->key) < 0) return -1;
buf = taosDecodeFixedI32(buf, &pKv->valueLen); if (tDecodeI32(pDecoder, &pKv->valueLen) < 0) return -1;
buf = taosDecodeBinary(buf, &pKv->value, pKv->valueLen); pKv->value = malloc(pKv->valueLen + 1);
return buf; if (pKv->value == NULL) return -1;
if (tDecodeCStrTo(pDecoder, (char*)pKv->value) < 0) return -1;
return 0;
} }
static FORCE_INLINE int taosEncodeSClientHbKey(void** buf, const SClientHbKey* pKey) { static FORCE_INLINE int32_t tEncodeSClientHbKey(SCoder* pEncoder, const SClientHbKey* pKey) {
int tlen = 0; if (tEncodeI32(pEncoder, pKey->connId) < 0) return -1;
tlen += taosEncodeFixedI32(buf, pKey->connId); if (tEncodeI32(pEncoder, pKey->hbType) < 0) return -1;
tlen += taosEncodeFixedI32(buf, pKey->hbType); return 0;
return tlen;
} }
static FORCE_INLINE void* taosDecodeSClientHbKey(void* buf, SClientHbKey* pKey) { static FORCE_INLINE int32_t tDecodeSClientHbKey(SCoder* pDecoder, SClientHbKey* pKey) {
buf = taosDecodeFixedI32(buf, &pKey->connId); if (tDecodeI32(pDecoder, &pKey->connId) < 0) return -1;
buf = taosDecodeFixedI32(buf, &pKey->hbType); if (tDecodeI32(pDecoder, &pKey->hbType) < 0) return -1;
return buf; return 0;
} }
typedef struct SMqHbVgInfo { typedef struct SMqHbVgInfo {
......
...@@ -28,16 +28,17 @@ static int32_t hbMqHbRspHandle(struct SAppHbMgr *pAppHbMgr, SClientHbRsp* pRsp) ...@@ -28,16 +28,17 @@ static int32_t hbMqHbRspHandle(struct SAppHbMgr *pAppHbMgr, SClientHbRsp* pRsp)
} }
static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) { static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
int32_t msgLen = 0;
int32_t code = 0; int32_t code = 0;
while (msgLen < valueLen) {
SUseDbRsp *rsp = (SUseDbRsp *)((char *)value + msgLen);
rsp->vgVersion = ntohl(rsp->vgVersion); SUseDbBatchRsp batchUseRsp = {0};
rsp->vgNum = ntohl(rsp->vgNum); if (tDeserializeSUseDbBatchRsp(value, valueLen, &batchUseRsp) != 0) {
rsp->uid = be64toh(rsp->uid); terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
int32_t numOfBatchs = taosArrayGetSize(batchUseRsp.pArray);
for (int32_t i = 0; i < numOfBatchs; ++i) {
SUseDbRsp *rsp = taosArrayGet(batchUseRsp.pArray, i);
tscDebug("hb db rsp, db:%s, vgVersion:%d, uid:%"PRIx64, rsp->db, rsp->vgVersion, rsp->uid); tscDebug("hb db rsp, db:%s, vgVersion:%d, uid:%"PRIx64, rsp->db, rsp->vgVersion, rsp->uid);
if (rsp->vgVersion < 0) { if (rsp->vgVersion < 0) {
...@@ -52,16 +53,9 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog ...@@ -52,16 +53,9 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
for (int32_t i = 0; i < rsp->vgNum; ++i) { for (int32_t j = 0; j < rsp->vgNum; ++j) {
rsp->vgroupInfo[i].vgId = ntohl(rsp->vgroupInfo[i].vgId); SVgroupInfo *pInfo = taosArrayGet(rsp->pVgroupInfos, j);
rsp->vgroupInfo[i].hashBegin = ntohl(rsp->vgroupInfo[i].hashBegin); if (taosHashPut(vgInfo.vgHash, &pInfo->vgId, sizeof(int32_t), pInfo, sizeof(SVgroupInfo)) != 0) {
rsp->vgroupInfo[i].hashEnd = ntohl(rsp->vgroupInfo[i].hashEnd);
for (int32_t n = 0; n < rsp->vgroupInfo[i].epset.numOfEps; ++n) {
rsp->vgroupInfo[i].epset.eps[n].port = ntohs(rsp->vgroupInfo[i].epset.eps[n].port);
}
if (0 != taosHashPut(vgInfo.vgHash, &rsp->vgroupInfo[i].vgId, sizeof(rsp->vgroupInfo[i].vgId), &rsp->vgroupInfo[i], sizeof(rsp->vgroupInfo[i]))) {
tscError("hash push failed, errno:%d", errno); tscError("hash push failed, errno:%d", errno);
taosHashCleanup(vgInfo.vgHash); taosHashCleanup(vgInfo.vgHash);
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
...@@ -74,8 +68,6 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog ...@@ -74,8 +68,6 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog
if (code) { if (code) {
return code; return code;
} }
msgLen += sizeof(SUseDbRsp) + rsp->vgNum * sizeof(SVgroupInfo);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -199,9 +191,10 @@ static int32_t hbMqAsyncCallBack(void* param, const SDataBuf* pMsg, int32_t code ...@@ -199,9 +191,10 @@ static int32_t hbMqAsyncCallBack(void* param, const SDataBuf* pMsg, int32_t code
tfree(param); tfree(param);
return -1; return -1;
} }
char *key = (char *)param; char *key = (char *)param;
SClientHbBatchRsp pRsp = {0}; SClientHbBatchRsp pRsp = {0};
tDeserializeSClientHbBatchRsp(pMsg->pData, &pRsp); tDeserializeSClientHbBatchRsp(pMsg->pData, pMsg->len, &pRsp);
int32_t rspNum = taosArrayGetSize(pRsp.rsps); int32_t rspNum = taosArrayGetSize(pRsp.rsps);
...@@ -414,7 +407,7 @@ static void* hbThreadFunc(void* param) { ...@@ -414,7 +407,7 @@ static void* hbThreadFunc(void* param) {
if (pReq == NULL) { if (pReq == NULL) {
continue; continue;
} }
int tlen = tSerializeSClientHbBatchReq(NULL, pReq); int tlen = tSerializeSClientHbBatchReq(NULL, 0, pReq);
void *buf = malloc(tlen); void *buf = malloc(tlen);
if (buf == NULL) { if (buf == NULL) {
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
...@@ -422,8 +415,7 @@ static void* hbThreadFunc(void* param) { ...@@ -422,8 +415,7 @@ static void* hbThreadFunc(void* param) {
hbClearReqInfo(pAppHbMgr); hbClearReqInfo(pAppHbMgr);
break; break;
} }
void *abuf = buf; tSerializeSClientHbBatchReq(buf, tlen, pReq);
tSerializeSClientHbBatchReq(&abuf, pReq);
SMsgSendInfo *pInfo = malloc(sizeof(SMsgSendInfo)); SMsgSendInfo *pInfo = malloc(sizeof(SMsgSendInfo));
if (pInfo == NULL) { if (pInfo == NULL) {
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
......
...@@ -97,14 +97,15 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) { ...@@ -97,14 +97,15 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) {
if (pRequest->type == TDMT_MND_SHOW_RETRIEVE || pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) { if (pRequest->type == TDMT_MND_SHOW_RETRIEVE || pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) {
if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) { if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) {
SRetrieveTableReq* pRetrieveMsg = calloc(1, sizeof(SRetrieveTableReq)); SRetrieveTableReq retrieveReq = {0};
if (pRetrieveMsg == NULL) { retrieveReq.showId = pRequest->body.showInfo.execId;
return NULL;
} int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &retrieveReq);
void* pReq = malloc(contLen);
tSerializeSRetrieveTableReq(pReq, contLen, &retrieveReq);
pRetrieveMsg->showId = htobe64(pRequest->body.showInfo.execId); pMsgSendInfo->msgInfo.pData = pReq;
pMsgSendInfo->msgInfo.pData = pRetrieveMsg; pMsgSendInfo->msgInfo.len = contLen;
pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableReq);
} else { } else {
SVShowTablesFetchReq* pFetchMsg = calloc(1, sizeof(SVShowTablesFetchReq)); SVShowTablesFetchReq* pFetchMsg = calloc(1, sizeof(SVShowTablesFetchReq));
if (pFetchMsg == NULL) { if (pFetchMsg == NULL) {
...@@ -264,9 +265,13 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { ...@@ -264,9 +265,13 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
return code; return code;
} }
SUseDbRsp* pUseDbRsp = (SUseDbRsp*) pMsg->pData; SUseDbRsp usedbRsp = {0};
tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp);
SName name = {0}; SName name = {0};
tNameFromString(&name, pUseDbRsp->db, T_NAME_ACCT|T_NAME_DB); tNameFromString(&name, usedbRsp.db, T_NAME_ACCT|T_NAME_DB);
tFreeSUsedbRsp(&usedbRsp);
char db[TSDB_DB_NAME_LEN] = {0}; char db[TSDB_DB_NAME_LEN] = {0};
tNameGetDbName(&name, db); tNameGetDbName(&name, db);
...@@ -300,14 +305,12 @@ int32_t processDropDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { ...@@ -300,14 +305,12 @@ int32_t processDropDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
return code; return code;
} }
SDropDbRsp *rsp = (SDropDbRsp *)pMsg->pData; SDropDbRsp dropdbRsp = {0};
tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp);
struct SCatalog *pCatalog = NULL;
rsp->uid = be64toh(rsp->uid);
struct SCatalog* pCatalog = NULL;
catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid);
catalogRemoveDB(pCatalog, rsp->db, rsp->uid);
tsem_post(&pRequest->body.rspSem); tsem_post(&pRequest->body.rspSem);
return code; return code;
......
...@@ -85,118 +85,156 @@ STSRow *tGetSubmitBlkNext(SSubmitBlkIter *pIter) { ...@@ -85,118 +85,156 @@ STSRow *tGetSubmitBlkNext(SSubmitBlkIter *pIter) {
} }
} }
int32_t tSerializeSClientHbReq(void **buf, const SClientHbReq *pReq) { static int32_t tSerializeSClientHbReq(SCoder *pEncoder, const SClientHbReq *pReq) {
int32_t tlen = 0; if (tEncodeSClientHbKey(pEncoder, &pReq->connKey) < 0) return -1;
tlen += taosEncodeSClientHbKey(buf, &pReq->connKey);
int32_t kvNum = taosHashGetSize(pReq->info); int32_t kvNum = taosHashGetSize(pReq->info);
tlen += taosEncodeFixedI32(buf, kvNum); if (tEncodeI32(pEncoder, kvNum) < 0) return -1;
SKv *kv;
void *pIter = taosHashIterate(pReq->info, NULL); void *pIter = taosHashIterate(pReq->info, NULL);
while (pIter != NULL) { while (pIter != NULL) {
kv = pIter; SKv *kv = pIter;
tlen += taosEncodeSKv(buf, kv); if (tEncodeSKv(pEncoder, kv) < 0) return -1;
pIter = taosHashIterate(pReq->info, pIter); pIter = taosHashIterate(pReq->info, pIter);
} }
return tlen;
return 0;
} }
void *tDeserializeSClientHbReq(void *buf, SClientHbReq *pReq) { static int32_t tDeserializeSClientHbReq(SCoder *pDecoder, SClientHbReq *pReq) {
buf = taosDecodeSClientHbKey(buf, &pReq->connKey); if (tDecodeSClientHbKey(pDecoder, &pReq->connKey) < 0) return -1;
// TODO: error handling int32_t kvNum = 0;
int32_t kvNum; if (tDecodeI32(pDecoder, &kvNum) < 0) return -1;
buf = taosDecodeFixedI32(buf, &kvNum);
if (pReq->info == NULL) { if (pReq->info == NULL) {
pReq->info = taosHashInit(kvNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); pReq->info = taosHashInit(kvNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
} }
if (pReq->info == NULL) return -1;
for (int32_t i = 0; i < kvNum; i++) { for (int32_t i = 0; i < kvNum; i++) {
SKv kv; SKv kv = {0};
buf = taosDecodeSKv(buf, &kv); if (tDecodeSKv(pDecoder, &kv) < 0) return -1;
taosHashPut(pReq->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv)); taosHashPut(pReq->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
} }
return buf; return 0;
} }
int32_t tSerializeSClientHbRsp(void **buf, const SClientHbRsp *pRsp) { static int32_t tSerializeSClientHbRsp(SCoder *pEncoder, const SClientHbRsp *pRsp) {
int32_t tlen = 0; if (tEncodeSClientHbKey(pEncoder, &pRsp->connKey) < 0) return -1;
if (tEncodeI32(pEncoder, pRsp->status) < 0) return -1;
int32_t kvNum = taosArrayGetSize(pRsp->info); int32_t kvNum = taosArrayGetSize(pRsp->info);
tlen += taosEncodeSClientHbKey(buf, &pRsp->connKey); if (tEncodeI32(pEncoder, kvNum) < 0) return -1;
tlen += taosEncodeFixedI32(buf, pRsp->status);
tlen += taosEncodeFixedI32(buf, kvNum);
for (int32_t i = 0; i < kvNum; i++) { for (int32_t i = 0; i < kvNum; i++) {
SKv *kv = (SKv *)taosArrayGet(pRsp->info, i); SKv *kv = taosArrayGet(pRsp->info, i);
tlen += taosEncodeSKv(buf, kv); if (tEncodeSKv(pEncoder, kv) < 0) return -1;
} }
return tlen;
return 0;
} }
void *tDeserializeSClientHbRsp(void *buf, SClientHbRsp *pRsp) { static int32_t tDeserializeSClientHbRsp(SCoder *pDecoder, SClientHbRsp *pRsp) {
if (tDecodeSClientHbKey(pDecoder, &pRsp->connKey) < 0) return -1;
if (tDecodeI32(pDecoder, &pRsp->status) < 0) return -1;
int32_t kvNum = 0; int32_t kvNum = 0;
buf = taosDecodeSClientHbKey(buf, &pRsp->connKey); if (tDecodeI32(pDecoder, &kvNum) < 0) return -1;
buf = taosDecodeFixedI32(buf, &pRsp->status);
buf = taosDecodeFixedI32(buf, &kvNum);
pRsp->info = taosArrayInit(kvNum, sizeof(SKv)); pRsp->info = taosArrayInit(kvNum, sizeof(SKv));
if (pRsp->info == NULL) return -1;
for (int32_t i = 0; i < kvNum; i++) { for (int32_t i = 0; i < kvNum; i++) {
SKv kv = {0}; SKv kv = {0};
buf = taosDecodeSKv(buf, &kv); tDecodeSKv(pDecoder, &kv);
taosArrayPush(pRsp->info, &kv); taosArrayPush(pRsp->info, &kv);
} }
return buf; return 0;
} }
int32_t tSerializeSClientHbBatchReq(void **buf, const SClientHbBatchReq *pBatchReq) { int32_t tSerializeSClientHbBatchReq(void *buf, int32_t bufLen, const SClientHbBatchReq *pBatchReq) {
int32_t tlen = 0; SCoder encoder = {0};
tlen += taosEncodeFixedI64(buf, pBatchReq->reqId); tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
if (tStartEncode(&encoder) < 0) return -1;
if (tEncodeI64(&encoder, pBatchReq->reqId) < 0) return -1;
int32_t reqNum = taosArrayGetSize(pBatchReq->reqs); int32_t reqNum = taosArrayGetSize(pBatchReq->reqs);
tlen += taosEncodeFixedI32(buf, reqNum); if (tEncodeI32(&encoder, reqNum) < 0) return -1;
for (int32_t i = 0; i < reqNum; i++) { for (int32_t i = 0; i < reqNum; i++) {
SClientHbReq *pReq = taosArrayGet(pBatchReq->reqs, i); SClientHbReq *pReq = taosArrayGet(pBatchReq->reqs, i);
tlen += tSerializeSClientHbReq(buf, pReq); if (tSerializeSClientHbReq(&encoder, pReq) < 0) return -1;
} }
tEndEncode(&encoder);
int32_t tlen = encoder.pos;
tCoderClear(&encoder);
return tlen; return tlen;
} }
void *tDeserializeSClientHbBatchReq(void *buf, SClientHbBatchReq *pBatchReq) { int32_t tDeserializeSClientHbBatchReq(void *buf, int32_t bufLen, SClientHbBatchReq *pBatchReq) {
buf = taosDecodeFixedI64(buf, &pBatchReq->reqId); SCoder decoder = {0};
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
if (tStartDecode(&decoder) < 0) return -1;
if (tDecodeI64(&decoder, &pBatchReq->reqId) < 0) return -1;
int32_t reqNum = 0;
if (tDecodeI32(&decoder, &reqNum) < 0) return -1;
if (pBatchReq->reqs == NULL) { if (pBatchReq->reqs == NULL) {
pBatchReq->reqs = taosArrayInit(0, sizeof(SClientHbReq)); pBatchReq->reqs = taosArrayInit(reqNum, sizeof(SClientHbReq));
} }
int32_t reqNum;
buf = taosDecodeFixedI32(buf, &reqNum);
for (int32_t i = 0; i < reqNum; i++) { for (int32_t i = 0; i < reqNum; i++) {
SClientHbReq req = {0}; SClientHbReq req = {0};
buf = tDeserializeSClientHbReq(buf, &req); tDeserializeSClientHbReq(&decoder, &req);
taosArrayPush(pBatchReq->reqs, &req); taosArrayPush(pBatchReq->reqs, &req);
} }
return buf;
tEndDecode(&decoder);
tCoderClear(&decoder);
return 0;
} }
int32_t tSerializeSClientHbBatchRsp(void **buf, const SClientHbBatchRsp *pBatchRsp) { int32_t tSerializeSClientHbBatchRsp(void *buf, int32_t bufLen, const SClientHbBatchRsp *pBatchRsp) {
int32_t tlen = 0; SCoder encoder = {0};
int32_t sz = taosArrayGetSize(pBatchRsp->rsps); tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
tlen += taosEncodeFixedI32(buf, sz);
for (int32_t i = 0; i < sz; i++) { if (tStartEncode(&encoder) < 0) return -1;
if (tEncodeI64(&encoder, pBatchRsp->reqId) < 0) return -1;
if (tEncodeI64(&encoder, pBatchRsp->rspId) < 0) return -1;
int32_t rspNum = taosArrayGetSize(pBatchRsp->rsps);
if (tEncodeI32(&encoder, rspNum) < 0) return -1;
for (int32_t i = 0; i < rspNum; i++) {
SClientHbRsp *pRsp = taosArrayGet(pBatchRsp->rsps, i); SClientHbRsp *pRsp = taosArrayGet(pBatchRsp->rsps, i);
tlen += tSerializeSClientHbRsp(buf, pRsp); if (tSerializeSClientHbRsp(&encoder, pRsp) < 0) return -1;
} }
tEndEncode(&encoder);
int32_t tlen = encoder.pos;
tCoderClear(&encoder);
return tlen; return tlen;
} }
void *tDeserializeSClientHbBatchRsp(void *buf, SClientHbBatchRsp *pBatchRsp) { int32_t tDeserializeSClientHbBatchRsp(void *buf, int32_t bufLen, SClientHbBatchRsp *pBatchRsp) {
int32_t sz; SCoder decoder = {0};
buf = taosDecodeFixedI32(buf, &sz); tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
pBatchRsp->rsps = taosArrayInit(sz, sizeof(SClientHbRsp));
for (int32_t i = 0; i < sz; i++) { if (tStartDecode(&decoder) < 0) return -1;
if (tDecodeI64(&decoder, &pBatchRsp->reqId) < 0) return -1;
if (tDecodeI64(&decoder, &pBatchRsp->rspId) < 0) return -1;
int32_t rspNum = 0;
if (tDecodeI32(&decoder, &rspNum) < 0) return -1;
if (pBatchRsp->rsps == NULL) {
pBatchRsp->rsps = taosArrayInit(rspNum, sizeof(SClientHbReq));
}
for (int32_t i = 0; i < rspNum; i++) {
SClientHbRsp rsp = {0}; SClientHbRsp rsp = {0};
buf = tDeserializeSClientHbRsp(buf, &rsp); tDeserializeSClientHbRsp(&decoder, &rsp);
taosArrayPush(pBatchRsp->rsps, &rsp); taosArrayPush(pBatchRsp->rsps, &rsp);
} }
return buf;
tEndDecode(&decoder);
tCoderClear(&decoder);
return 0;
} }
int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
...@@ -402,6 +440,11 @@ void *tDeserializeSMCreateStbReq(void *buf, SMCreateStbReq *pReq) { ...@@ -402,6 +440,11 @@ void *tDeserializeSMCreateStbReq(void *buf, SMCreateStbReq *pReq) {
return buf; return buf;
} }
void tFreeSMCreateStbReq(SMCreateStbReq *pReq) {
taosArrayDestroy(pReq->pColumns);
taosArrayDestroy(pReq->pTags);
}
int32_t tSerializeSMDropStbReq(void **buf, SMDropStbReq *pReq) { int32_t tSerializeSMDropStbReq(void **buf, SMDropStbReq *pReq) {
int32_t tlen = 0; int32_t tlen = 0;
...@@ -1306,4 +1349,195 @@ int32_t tDeserializeSSyncDbReq(void *buf, int32_t bufLen, SSyncDbReq *pReq) { ...@@ -1306,4 +1349,195 @@ int32_t tDeserializeSSyncDbReq(void *buf, int32_t bufLen, SSyncDbReq *pReq) {
tCoderClear(&decoder); tCoderClear(&decoder);
return 0; return 0;
} }
\ No newline at end of file
static int32_t tSerializeSUseDbRspImp(SCoder *pEncoder, SUseDbRsp *pRsp) {
if (tEncodeCStr(pEncoder, pRsp->db) < 0) return -1;
if (tEncodeU64(pEncoder, pRsp->uid) < 0) return -1;
if (tEncodeI32(pEncoder, pRsp->vgVersion) < 0) return -1;
if (tEncodeI32(pEncoder, pRsp->vgNum) < 0) return -1;
if (tEncodeI8(pEncoder, pRsp->hashMethod) < 0) return -1;
for (int32_t i = 0; i < pRsp->vgNum; ++i) {
SVgroupInfo *pVgInfo = taosArrayGet(pRsp->pVgroupInfos, i);
if (tEncodeI32(pEncoder, pVgInfo->vgId) < 0) return -1;
if (tEncodeU32(pEncoder, pVgInfo->hashBegin) < 0) return -1;
if (tEncodeU32(pEncoder, pVgInfo->hashEnd) < 0) return -1;
if (tEncodeSEpSet(pEncoder, &pVgInfo->epset) < 0) return -1;
}
return 0;
}
int32_t tSerializeSUseDbRsp(void *buf, int32_t bufLen, SUseDbRsp *pRsp) {
SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
if (tStartEncode(&encoder) < 0) return -1;
if (tSerializeSUseDbRspImp(&encoder, pRsp) < 0) return -1;
tEndEncode(&encoder);
int32_t tlen = encoder.pos;
tCoderClear(&encoder);
return tlen;
}
int32_t tSerializeSUseDbBatchRsp(void *buf, int32_t bufLen, SUseDbBatchRsp *pRsp) {
SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
if (tStartEncode(&encoder) < 0) return -1;
int32_t numOfBatch = taosArrayGetSize(pRsp->pArray);
if (tEncodeI32(&encoder, numOfBatch) < 0) return -1;
for (int32_t i = 0; i < numOfBatch; ++i) {
SUseDbRsp *pUsedbRsp = taosArrayGet(pRsp->pArray, i);
if (tSerializeSUseDbRspImp(&encoder, pUsedbRsp) < 0) return -1;
}
tEndEncode(&encoder);
int32_t tlen = encoder.pos;
tCoderClear(&encoder);
return tlen;
}
int32_t tDeserializeSUseDbRspImp(SCoder *pDecoder, SUseDbRsp *pRsp) {
if (tDecodeCStrTo(pDecoder, pRsp->db) < 0) return -1;
if (tDecodeU64(pDecoder, &pRsp->uid) < 0) return -1;
if (tDecodeI32(pDecoder, &pRsp->vgVersion) < 0) return -1;
if (tDecodeI32(pDecoder, &pRsp->vgNum) < 0) return -1;
if (tDecodeI8(pDecoder, &pRsp->hashMethod) < 0) return -1;
pRsp->pVgroupInfos = taosArrayInit(pRsp->vgNum, sizeof(SVgroupInfo));
if (pRsp->pVgroupInfos == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
for (int32_t i = 0; i < pRsp->vgNum; ++i) {
SVgroupInfo vgInfo = {0};
if (tDecodeI32(pDecoder, &vgInfo.vgId) < 0) return -1;
if (tDecodeU32(pDecoder, &vgInfo.hashBegin) < 0) return -1;
if (tDecodeU32(pDecoder, &vgInfo.hashEnd) < 0) return -1;
if (tDecodeSEpSet(pDecoder, &vgInfo.epset) < 0) return -1;
taosArrayPush(pRsp->pVgroupInfos, &vgInfo);
}
return 0;
}
int32_t tDeserializeSUseDbRsp(void *buf, int32_t bufLen, SUseDbRsp *pRsp) {
SCoder decoder = {0};
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
if (tStartDecode(&decoder) < 0) return -1;
if (tDeserializeSUseDbRspImp(&decoder, pRsp) < 0) return -1;
tEndDecode(&decoder);
tCoderClear(&decoder);
return 0;
}
int32_t tDeserializeSUseDbBatchRsp(void *buf, int32_t bufLen, SUseDbBatchRsp *pRsp) {
SCoder decoder = {0};
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
if (tStartDecode(&decoder) < 0) return -1;
int32_t numOfBatch = taosArrayGetSize(pRsp->pArray);
if (tDecodeI32(&decoder, &numOfBatch) < 0) return -1;
pRsp->pArray = taosArrayInit(numOfBatch, sizeof(SUseDbBatchRsp));
if (pRsp->pArray == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
for (int32_t i = 0; i < numOfBatch; ++i) {
SUseDbRsp usedbRsp = {0};
if (tDeserializeSUseDbRspImp(&decoder, &usedbRsp) < 0) return -1;
taosArrayPush(pRsp->pArray, &usedbRsp);
}
tEndDecode(&decoder);
tCoderClear(&decoder);
return 0;
}
void tFreeSUsedbRsp(SUseDbRsp *pRsp) { taosArrayDestroy(pRsp->pVgroupInfos); }
void tFreeSUseDbBatchRsp(SUseDbBatchRsp *pRsp) {
int32_t numOfBatch = taosArrayGetSize(pRsp->pArray);
for (int32_t i = 0; i < numOfBatch; ++i) {
SUseDbRsp *pUsedbRsp = taosArrayGet(pRsp->pArray, i);
tFreeSUsedbRsp(pUsedbRsp);
}
taosArrayDestroy(pRsp->pArray);
}
int32_t tSerializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) {
SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
if (tStartEncode(&encoder) < 0) return -1;
if (tEncodeI32(&encoder, pReq->type) < 0) return -1;
if (tEncodeCStr(&encoder, pReq->db) < 0) return -1;
if (tEncodeI32(&encoder, pReq->payloadLen) < 0) return -1;
if (pReq->payloadLen > 0) {
if (tEncodeCStr(&encoder, pReq->payload) < 0) return -1;
}
tEndEncode(&encoder);
int32_t tlen = encoder.pos;
tCoderClear(&encoder);
return tlen;
}
int32_t tDeserializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) {
SCoder decoder = {0};
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
if (tStartDecode(&decoder) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->type) < 0) return -1;
if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1;
if (tDecodeI32(&decoder, &pReq->payloadLen) < 0) return -1;
if (pReq->payloadLen > 0) {
pReq->payload = malloc(pReq->payloadLen);
if (pReq->payload == NULL) return -1;
if (tDecodeCStrTo(&decoder, pReq->payload) < 0) return -1;
}
tEndDecode(&decoder);
tCoderClear(&decoder);
return 0;
}
void tFreeSShowReq(SShowReq *pReq) { free(pReq->payload); }
int32_t tSerializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableReq *pReq) {
SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
if (tStartEncode(&encoder) < 0) return -1;
if (tEncodeI64(&encoder, pReq->showId) < 0) return -1;
if (tEncodeI8(&encoder, pReq->free) < 0) return -1;
tEndEncode(&encoder);
int32_t tlen = encoder.pos;
tCoderClear(&encoder);
return tlen;
}
int32_t tDeserializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableReq *pReq) {
SCoder decoder = {0};
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
if (tStartDecode(&decoder) < 0) return -1;
if (tDecodeI64(&decoder, &pReq->showId) < 0) return -1;
if (tDecodeI8(&decoder, &pReq->free) < 0) return -1;
tEndDecode(&decoder);
tCoderClear(&decoder);
return 0;
}
...@@ -80,12 +80,16 @@ SRpcMsg* Testbase::SendReq(tmsg_t msgType, void* pCont, int32_t contLen) { ...@@ -80,12 +80,16 @@ SRpcMsg* Testbase::SendReq(tmsg_t msgType, void* pCont, int32_t contLen) {
} }
void Testbase::SendShowMetaReq(int8_t showType, const char* db) { void Testbase::SendShowMetaReq(int8_t showType, const char* db) {
int32_t contLen = sizeof(SShowReq); SShowReq showReq = {0};
SShowReq* pShow = (SShowReq*)rpcMallocCont(contLen); showReq.type = showType;
pShow->type = showType; strcpy(showReq.db, db);
strcpy(pShow->db, db);
SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW, pShow, contLen); int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
char* pReq = (char*)rpcMallocCont(contLen);
tSerializeSShowReq(pReq, contLen, &showReq);
tFreeSShowReq(&showReq);
SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW, pReq, contLen);
SShowRsp* pShowRsp = (SShowRsp*)pRsp->pCont; SShowRsp* pShowRsp = (SShowRsp*)pRsp->pCont;
ASSERT(pShowRsp != nullptr); ASSERT(pShowRsp != nullptr);
...@@ -128,13 +132,15 @@ int32_t Testbase::GetMetaNum() { return pMeta->numOfColumns; } ...@@ -128,13 +132,15 @@ int32_t Testbase::GetMetaNum() { return pMeta->numOfColumns; }
const char* Testbase::GetMetaTbName() { return pMeta->tbName; } const char* Testbase::GetMetaTbName() { return pMeta->tbName; }
void Testbase::SendShowRetrieveReq() { void Testbase::SendShowRetrieveReq() {
int32_t contLen = sizeof(SRetrieveTableReq); SRetrieveTableReq retrieveReq = {0};
retrieveReq.showId = showId;
retrieveReq.free = 0;
SRetrieveTableReq* pRetrieve = (SRetrieveTableReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &retrieveReq);
pRetrieve->showId = htobe64(showId); void* pReq = rpcMallocCont(contLen);
pRetrieve->free = 0; tSerializeSRetrieveTableReq(pReq, contLen, &retrieveReq);
SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen); SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW_RETRIEVE, pReq, contLen);
pRetrieveRsp = (SRetrieveTableRsp*)pRsp->pCont; pRetrieveRsp = (SRetrieveTableRsp*)pRsp->pCont;
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
......
...@@ -26,7 +26,7 @@ int32_t mndInitDb(SMnode *pMnode); ...@@ -26,7 +26,7 @@ int32_t mndInitDb(SMnode *pMnode);
void mndCleanupDb(SMnode *pMnode); void mndCleanupDb(SMnode *pMnode);
SDbObj *mndAcquireDb(SMnode *pMnode, char *db); SDbObj *mndAcquireDb(SMnode *pMnode, char *db);
void mndReleaseDb(SMnode *pMnode, SDbObj *pDb); void mndReleaseDb(SMnode *pMnode, SDbObj *pDb);
int32_t mndValidateDBInfo(SMnode *pMnode, SDbVgVersion *dbs, int32_t num, void **rsp, int32_t *rspLen); int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs, void **ppRsp, int32_t *pRspLen);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "mndDb.h" #include "mndDb.h"
#include "mndAuth.h"
#include "mndDnode.h" #include "mndDnode.h"
#include "mndShow.h" #include "mndShow.h"
#include "mndTrans.h" #include "mndTrans.h"
...@@ -369,7 +370,7 @@ static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj ...@@ -369,7 +370,7 @@ static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
action.pCont = pReq; action.pCont = pReq;
action.contLen = sizeof(SDropVnodeReq); action.contLen = sizeof(SDropVnodeReq);
action.msgType = TDMT_DND_DROP_VNODE; action.msgType = TDMT_DND_DROP_VNODE;
action.acceptableCode = TSDB_CODE_DND_VNODE_NOT_DEPLOYED; action.acceptableCode = TSDB_CODE_DND_VNODE_NOT_DEPLOYED;
if (mndTransAppendUndoAction(pTrans, &action) != 0) { if (mndTransAppendUndoAction(pTrans, &action) != 0) {
free(pReq); free(pReq);
return -1; return -1;
...@@ -451,54 +452,54 @@ CREATE_DB_OVER: ...@@ -451,54 +452,54 @@ CREATE_DB_OVER:
} }
static int32_t mndProcessCreateDbReq(SMnodeMsg *pReq) { static int32_t mndProcessCreateDbReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SCreateDbReq *pCreate = pReq->rpcMsg.pCont; int32_t code = -1;
SDbObj *pDb = NULL;
pCreate->numOfVgroups = htonl(pCreate->numOfVgroups); SUserObj *pUser = NULL;
pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize); SCreateDbReq createReq = {0};
pCreate->totalBlocks = htonl(pCreate->totalBlocks);
pCreate->daysPerFile = htonl(pCreate->daysPerFile); if (tDeserializeSCreateDbReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &createReq) != 0) {
pCreate->daysToKeep0 = htonl(pCreate->daysToKeep0); terrno = TSDB_CODE_INVALID_MSG;
pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1); goto CREATE_DB_OVER;
pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2); }
pCreate->minRows = htonl(pCreate->minRows);
pCreate->maxRows = htonl(pCreate->maxRows); mDebug("db:%s, start to create, vgroups:%d", createReq.db, createReq.numOfVgroups);
pCreate->commitTime = htonl(pCreate->commitTime);
pCreate->fsyncPeriod = htonl(pCreate->fsyncPeriod); pDb = mndAcquireDb(pMnode, createReq.db);
mDebug("db:%s, start to create, vgroups:%d", pCreate->db, pCreate->numOfVgroups);
SDbObj *pDb = mndAcquireDb(pMnode, pCreate->db);
if (pDb != NULL) { if (pDb != NULL) {
mndReleaseDb(pMnode, pDb); if (createReq.ignoreExist) {
if (pCreate->ignoreExist) { mDebug("db:%s, already exist, ignore exist is set", createReq.db);
mDebug("db:%s, already exist, ignore exist is set", pCreate->db); code = 0;
return 0; goto CREATE_DB_OVER;
} else { } else {
terrno = TSDB_CODE_MND_DB_ALREADY_EXIST; terrno = TSDB_CODE_MND_DB_ALREADY_EXIST;
mError("db:%s, failed to create since %s", pCreate->db, terrstr()); goto CREATE_DB_OVER;
return -1;
} }
} else if (terrno != TSDB_CODE_MND_DB_NOT_EXIST) { } else if (terrno != TSDB_CODE_MND_DB_NOT_EXIST) {
mError("db:%s, failed to create since %s", pCreate->db, terrstr()); goto CREATE_DB_OVER;
return -1;
} }
SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user); pUser = mndAcquireUser(pMnode, pReq->user);
if (pOperUser == NULL) { if (pUser == NULL) {
mError("db:%s, failed to create since %s", pCreate->db, terrstr()); goto CREATE_DB_OVER;
return -1;
} }
int32_t code = mndCreateDb(pMnode, pReq, pCreate, pOperUser); if (mndCheckCreateDbAuth(pUser) != 0) {
mndReleaseUser(pMnode, pOperUser); goto CREATE_DB_OVER;
}
if (code != 0) { code = mndCreateDb(pMnode, pReq, &createReq, pUser);
mError("db:%s, failed to create since %s", pCreate->db, terrstr()); if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
return -1;
CREATE_DB_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("db:%s, failed to create since %s", createReq.db, terrstr());
} }
return TSDB_CODE_MND_ACTION_IN_PROGRESS; mndReleaseDb(pMnode, pDb);
mndReleaseUser(pMnode, pUser);
return code;
} }
static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) { static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) {
...@@ -633,43 +634,56 @@ UPDATE_DB_OVER: ...@@ -633,43 +634,56 @@ UPDATE_DB_OVER:
} }
static int32_t mndProcessAlterDbReq(SMnodeMsg *pReq) { static int32_t mndProcessAlterDbReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SAlterDbReq *pAlter = pReq->rpcMsg.pCont; int32_t code = -1;
pAlter->totalBlocks = htonl(pAlter->totalBlocks); SDbObj *pDb = NULL;
pAlter->daysToKeep0 = htonl(pAlter->daysToKeep0); SUserObj *pUser = NULL;
pAlter->daysToKeep1 = htonl(pAlter->daysToKeep1); SAlterDbReq alterReq = {0};
pAlter->daysToKeep2 = htonl(pAlter->daysToKeep2);
pAlter->fsyncPeriod = htonl(pAlter->fsyncPeriod); if (tDeserializeSAlterDbReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &alterReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto ALTER_DB_OVER;
}
mDebug("db:%s, start to alter", pAlter->db); mDebug("db:%s, start to alter", alterReq.db);
SDbObj *pDb = mndAcquireDb(pMnode, pAlter->db); pDb = mndAcquireDb(pMnode, alterReq.db);
if (pDb == NULL) { if (pDb == NULL) {
mError("db:%s, failed to alter since %s", pAlter->db, terrstr()); terrno = TSDB_CODE_MND_DB_NOT_EXIST;
return TSDB_CODE_MND_DB_NOT_EXIST; goto ALTER_DB_OVER;
}
pUser = mndAcquireUser(pMnode, pReq->user);
if (pUser == NULL) {
goto ALTER_DB_OVER;
}
if (mndCheckAlterDropCompactSyncDbAuth(pUser, pDb) != 0) {
goto ALTER_DB_OVER;
} }
SDbObj dbObj = {0}; SDbObj dbObj = {0};
memcpy(&dbObj, pDb, sizeof(SDbObj)); memcpy(&dbObj, pDb, sizeof(SDbObj));
int32_t code = mndSetDbCfgFromAlterDbReq(&dbObj, pAlter); code = mndSetDbCfgFromAlterDbReq(&dbObj, &alterReq);
if (code != 0) { if (code != 0) {
mndReleaseDb(pMnode, pDb); goto ALTER_DB_OVER;
mError("db:%s, failed to alter since %s", pAlter->db, tstrerror(code));
return code;
} }
dbObj.cfgVersion++; dbObj.cfgVersion++;
dbObj.updateTime = taosGetTimestampMs(); dbObj.updateTime = taosGetTimestampMs();
code = mndUpdateDb(pMnode, pReq, pDb, &dbObj); code = mndUpdateDb(pMnode, pReq, pDb, &dbObj);
mndReleaseDb(pMnode, pDb); if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
if (code != 0) { ALTER_DB_OVER:
mError("db:%s, failed to alter since %s", pAlter->db, tstrerror(code)); if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
return code; mError("db:%s, failed to alter since %s", alterReq.db, terrstr());
} }
return TSDB_CODE_MND_ACTION_IN_PROGRESS; mndReleaseDb(pMnode, pDb);
mndReleaseUser(pMnode, pUser);
return code;
} }
static int32_t mndSetDropDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { static int32_t mndSetDropDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
...@@ -771,11 +785,18 @@ static int32_t mndDropDb(SMnode *pMnode, SMnodeMsg *pReq, SDbObj *pDb) { ...@@ -771,11 +785,18 @@ static int32_t mndDropDb(SMnode *pMnode, SMnodeMsg *pReq, SDbObj *pDb) {
if (mndSetDropDbCommitLogs(pMnode, pTrans, pDb) != 0) goto DROP_DB_OVER; if (mndSetDropDbCommitLogs(pMnode, pTrans, pDb) != 0) goto DROP_DB_OVER;
if (mndSetDropDbRedoActions(pMnode, pTrans, pDb) != 0) goto DROP_DB_OVER; if (mndSetDropDbRedoActions(pMnode, pTrans, pDb) != 0) goto DROP_DB_OVER;
int32_t rspLen = sizeof(SDropDbRsp); SDropDbRsp dropRsp = {0};
SDropDbRsp *pRsp = rpcMallocCont(rspLen); memcpy(dropRsp.db, pDb->name, TSDB_DB_FNAME_LEN);
if (pRsp == NULL) goto DROP_DB_OVER; dropRsp.uid = pDb->uid;
memcpy(pRsp->db, pDb->name, TSDB_DB_FNAME_LEN);
pRsp->uid = htobe64(pDb->uid); int32_t rspLen = tSerializeSDropDbRsp(NULL, 0, &dropRsp);
void *pRsp = malloc(rspLen);
if (pRsp == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto DROP_DB_OVER;
}
tSerializeSDropDbRsp(pRsp, rspLen, &dropRsp);
mndTransSetRpcRsp(pTrans, pRsp, rspLen); mndTransSetRpcRsp(pTrans, pRsp, rspLen);
if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_DB_OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_DB_OVER;
...@@ -788,37 +809,56 @@ DROP_DB_OVER: ...@@ -788,37 +809,56 @@ DROP_DB_OVER:
} }
static int32_t mndProcessDropDbReq(SMnodeMsg *pReq) { static int32_t mndProcessDropDbReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SDropDbReq *pDrop = pReq->rpcMsg.pCont; int32_t code = -1;
SDbObj *pDb = NULL;
SUserObj *pUser = NULL;
SDropDbReq dropReq = {0};
if (tDeserializeSDropDbReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &dropReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto DROP_DB_OVER;
}
mDebug("db:%s, start to drop", pDrop->db); mDebug("db:%s, start to drop", dropReq.db);
SDbObj *pDb = mndAcquireDb(pMnode, pDrop->db); pDb = mndAcquireDb(pMnode, dropReq.db);
if (pDb == NULL) { if (pDb == NULL) {
if (pDrop->ignoreNotExists) { if (dropReq.ignoreNotExists) {
mDebug("db:%s, not exist, ignore not exist is set", pDrop->db); code = 0;
return TSDB_CODE_SUCCESS; goto DROP_DB_OVER;
} else { } else {
terrno = TSDB_CODE_MND_DB_NOT_EXIST; terrno = TSDB_CODE_MND_DB_NOT_EXIST;
mError("db:%s, failed to drop since %s", pDrop->db, terrstr()); goto DROP_DB_OVER;
return -1;
} }
} }
int32_t code = mndDropDb(pMnode, pReq, pDb); pUser = mndAcquireUser(pMnode, pReq->user);
mndReleaseDb(pMnode, pDb); if (pUser == NULL) {
goto DROP_DB_OVER;
}
if (code != 0) { if (mndCheckAlterDropCompactSyncDbAuth(pUser, pDb) != 0) {
mError("db:%s, failed to drop since %s", pDrop->db, terrstr()); goto DROP_DB_OVER;
return code; }
code = mndDropDb(pMnode, pReq, pDb);
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
DROP_DB_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("db:%s, failed to drop since %s", dropReq.db, terrstr());
} }
return TSDB_CODE_MND_ACTION_IN_PROGRESS; mndReleaseDb(pMnode, pDb);
mndReleaseUser(pMnode, pUser);
return code;
} }
static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SVgroupInfo *vgList, int32_t *vgNum) { static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) {
int32_t vindex = 0; int32_t vindex = 0;
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL; void *pIter = NULL;
while (vindex < pDb->cfg.numOfVgroups) { while (vindex < pDb->cfg.numOfVgroups) {
...@@ -827,168 +867,243 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SVgroupInfo *vgLis ...@@ -827,168 +867,243 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SVgroupInfo *vgLis
if (pIter == NULL) break; if (pIter == NULL) break;
if (pVgroup->dbUid == pDb->uid) { if (pVgroup->dbUid == pDb->uid) {
SVgroupInfo *pInfo = &vgList[vindex]; SVgroupInfo vgInfo = {0};
pInfo->vgId = htonl(pVgroup->vgId); vgInfo.vgId = pVgroup->vgId;
pInfo->hashBegin = htonl(pVgroup->hashBegin); vgInfo.hashBegin = pVgroup->hashBegin;
pInfo->hashEnd = htonl(pVgroup->hashEnd); vgInfo.hashEnd = pVgroup->hashEnd;
pInfo->epset.numOfEps = pVgroup->replica; vgInfo.epset.numOfEps = pVgroup->replica;
for (int32_t gid = 0; gid < pVgroup->replica; ++gid) { for (int32_t gid = 0; gid < pVgroup->replica; ++gid) {
SVnodeGid *pVgid = &pVgroup->vnodeGid[gid]; SVnodeGid *pVgid = &pVgroup->vnodeGid[gid];
SEp * pEp = &pInfo->epset.eps[gid]; SEp *pEp = &vgInfo.epset.eps[gid];
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId); SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
if (pDnode != NULL) { if (pDnode != NULL) {
memcpy(pEp->fqdn, pDnode->fqdn, TSDB_FQDN_LEN); memcpy(pEp->fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
pEp->port = htons(pDnode->port); pEp->port = pDnode->port;
} }
mndReleaseDnode(pMnode, pDnode); mndReleaseDnode(pMnode, pDnode);
if (pVgid->role == TAOS_SYNC_STATE_LEADER) { if (pVgid->role == TAOS_SYNC_STATE_LEADER) {
pInfo->epset.inUse = gid; vgInfo.epset.inUse = gid;
} }
} }
vindex++; vindex++;
taosArrayPush(pVgList, &vgInfo);
} }
sdbRelease(pSdb, pVgroup); sdbRelease(pSdb, pVgroup);
} }
*vgNum = vindex;
} }
static int32_t mndProcessUseDbReq(SMnodeMsg *pReq) { static int32_t mndProcessUseDbReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SSdb *pSdb = pMnode->pSdb; int32_t code = -1;
SUseDbReq *pUse = pReq->rpcMsg.pCont; SDbObj *pDb = NULL;
pUse->vgVersion = htonl(pUse->vgVersion); SUserObj *pUser = NULL;
SUseDbReq usedbReq = {0};
SUseDbRsp usedbRsp = {0};
if (tDeserializeSUseDbReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &usedbReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto USE_DB_OVER;
}
SDbObj *pDb = mndAcquireDb(pMnode, pUse->db); pDb = mndAcquireDb(pMnode, usedbReq.db);
if (pDb == NULL) { if (pDb == NULL) {
terrno = TSDB_CODE_MND_DB_NOT_EXIST; terrno = TSDB_CODE_MND_DB_NOT_EXIST;
mError("db:%s, failed to process use db req since %s", pUse->db, terrstr()); goto USE_DB_OVER;
return -1;
} }
int32_t contLen = sizeof(SUseDbRsp) + pDb->cfg.numOfVgroups * sizeof(SVgroupInfo); pUser = mndAcquireUser(pMnode, pReq->user);
SUseDbRsp *pRsp = rpcMallocCont(contLen); if (pUser == NULL) {
if (pRsp == NULL) { goto USE_DB_OVER;
mndReleaseDb(pMnode, pDb); }
if (mndCheckUseDbAuth(pUser, pDb) != 0) {
goto USE_DB_OVER;
}
usedbRsp.pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo));
if (usedbRsp.pVgroupInfos == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1; goto USE_DB_OVER;
} }
int32_t vgNum = 0; if (usedbReq.vgVersion < pDb->vgVersion) {
mndBuildDBVgroupInfo(pDb, pMnode, usedbRsp.pVgroupInfos);
}
if (pUse->vgVersion < pDb->vgVersion) { memcpy(usedbRsp.db, pDb->name, TSDB_DB_FNAME_LEN);
mndBuildDBVgroupInfo(pDb, pMnode, pRsp->vgroupInfo, &vgNum); usedbRsp.uid = pDb->uid;
usedbRsp.vgVersion = pDb->vgVersion;
usedbRsp.vgNum = taosArrayGetSize(usedbRsp.pVgroupInfos);
usedbRsp.hashMethod = pDb->hashMethod;
int32_t contLen = tSerializeSUseDbRsp(NULL, 0, &usedbRsp);
void *pRsp = rpcMallocCont(contLen);
if (pRsp == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto USE_DB_OVER;
} }
memcpy(pRsp->db, pDb->name, TSDB_DB_FNAME_LEN); tSerializeSUseDbRsp(pRsp, contLen, &usedbRsp);
pRsp->uid = htobe64(pDb->uid);
pRsp->vgVersion = htonl(pDb->vgVersion);
pRsp->vgNum = htonl(vgNum);
pRsp->hashMethod = pDb->hashMethod;
pReq->pCont = pRsp; pReq->pCont = pRsp;
pReq->contLen = contLen; pReq->contLen = contLen;
code = 0;
USE_DB_OVER:
if (code != 0) {
mError("db:%s, failed to process use db req since %s", usedbReq.db, terrstr());
}
mndReleaseDb(pMnode, pDb); mndReleaseDb(pMnode, pDb);
mndReleaseUser(pMnode, pUser);
tFreeSUsedbRsp(&usedbRsp);
return 0; return code;
} }
int32_t mndValidateDBInfo(SMnode *pMnode, SDbVgVersion *dbs, int32_t num, void **rsp, int32_t *rspLen) { int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs, void **ppRsp, int32_t *pRspLen) {
SSdb *pSdb = pMnode->pSdb; SUseDbBatchRsp batchUseRsp = {0};
int32_t bufSize = num * (sizeof(SUseDbRsp) + TSDB_DEFAULT_VN_PER_DB * sizeof(SVgroupInfo)); batchUseRsp.pArray = taosArrayInit(numOfDbs, sizeof(SUseDbRsp));
void *buf = malloc(bufSize); if (batchUseRsp.pArray == NULL) {
int32_t len = 0; terrno = TSDB_CODE_OUT_OF_MEMORY;
int32_t contLen = 0; return -1;
int32_t bufOffset = 0; }
SUseDbRsp *pRsp = NULL;
for (int32_t i = 0; i < num; ++i) {
SDbVgVersion *db = &dbs[i];
db->dbId = be64toh(db->dbId);
db->vgVersion = ntohl(db->vgVersion);
len = 0;
SDbObj *pDb = mndAcquireDb(pMnode, db->dbFName);
if (pDb == NULL) {
mInfo("db %s not exist", db->dbFName);
len = sizeof(SUseDbRsp);
} else if (pDb->uid != db->dbId || db->vgVersion < pDb->vgVersion) {
len = sizeof(SUseDbRsp) + pDb->cfg.numOfVgroups * sizeof(SVgroupInfo);
}
if (0 == len) { for (int32_t i = 0; i < numOfDbs; ++i) {
SDbVgVersion *pDbVgVersion = &pDbs[i];
pDbVgVersion->dbId = htobe64(pDbVgVersion->dbId);
pDbVgVersion->vgVersion = htonl(pDbVgVersion->vgVersion);
SUseDbRsp usedbRsp = {0};
SDbObj *pDb = mndAcquireDb(pMnode, pDbVgVersion->dbFName);
if (pDb == NULL) {
mDebug("db:%s, no exist", pDbVgVersion->dbFName);
memcpy(usedbRsp.db, pDbVgVersion->dbFName, TSDB_DB_FNAME_LEN);
usedbRsp.uid = pDbVgVersion->dbId;
usedbRsp.vgVersion = -1;
taosArrayPush(batchUseRsp.pArray, &usedbRsp);
} else if (pDbVgVersion->vgVersion >= pDb->vgVersion) {
mDebug("db:%s, version not changed", pDbVgVersion->dbFName);
mndReleaseDb(pMnode, pDb); mndReleaseDb(pMnode, pDb);
continue; continue;
}
contLen += len;
if (contLen > bufSize) {
buf = realloc(buf, contLen);
}
pRsp = (SUseDbRsp *)((char *)buf + bufOffset);
memcpy(pRsp->db, db->dbFName, TSDB_DB_FNAME_LEN);
if (pDb) {
int32_t vgNum = 0;
mndBuildDBVgroupInfo(pDb, pMnode, pRsp->vgroupInfo, &vgNum);
pRsp->uid = htobe64(pDb->uid);
pRsp->vgVersion = htonl(pDb->vgVersion);
pRsp->vgNum = htonl(vgNum);
pRsp->hashMethod = pDb->hashMethod;
} else { } else {
pRsp->uid = htobe64(db->dbId); usedbRsp.pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo));
pRsp->vgNum = htonl(0); if (usedbRsp.pVgroupInfos == NULL) {
pRsp->hashMethod = 0; mndReleaseDb(pMnode, pDb);
pRsp->vgVersion = htonl(-1); mError("db:%s, failed to malloc usedb response", pDb->name);
} continue;
}
mndBuildDBVgroupInfo(pDb, pMnode, usedbRsp.pVgroupInfos);
memcpy(usedbRsp.db, pDb->name, TSDB_DB_FNAME_LEN);
usedbRsp.uid = pDb->uid;
usedbRsp.vgVersion = pDb->vgVersion;
usedbRsp.vgNum = (int32_t)taosArrayGetSize(usedbRsp.pVgroupInfos);
usedbRsp.hashMethod = pDb->hashMethod;
bufOffset += len; taosArrayPush(batchUseRsp.pArray, &usedbRsp);
mndReleaseDb(pMnode, pDb);
mndReleaseDb(pMnode, pDb); }
} }
if (contLen > 0) { int32_t rspLen = tSerializeSUseDbBatchRsp(NULL, 0, &batchUseRsp);
*rsp = buf; void *pRsp = malloc(rspLen);
*rspLen = contLen; if (pRsp == NULL) {
} else { terrno = TSDB_CODE_OUT_OF_MEMORY;
*rsp = NULL; tFreeSUseDbBatchRsp(&batchUseRsp);
tfree(buf); return -1;
*rspLen = 0;
} }
tSerializeSUseDbBatchRsp(pRsp, rspLen, &batchUseRsp);
*ppRsp = pRsp;
*pRspLen = rspLen;
tFreeSUseDbBatchRsp(&batchUseRsp);
return 0; return 0;
} }
static int32_t mndProcessSyncDbReq(SMnodeMsg *pReq) { static int32_t mndProcessSyncDbReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SSyncDbReq *pSync = pReq->rpcMsg.pCont; int32_t code = -1;
SDbObj *pDb = mndAcquireDb(pMnode, pSync->db); SDbObj *pDb = NULL;
SUserObj *pUser = NULL;
SSyncDbReq syncReq = {0};
if (tDeserializeSSyncDbReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &syncReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto SYNC_DB_OVER;
}
mDebug("db:%s, start to sync", syncReq.db);
pDb = mndAcquireDb(pMnode, syncReq.db);
if (pDb == NULL) { if (pDb == NULL) {
mError("db:%s, failed to process sync db req since %s", pSync->db, terrstr()); goto SYNC_DB_OVER;
return -1; }
pUser = mndAcquireUser(pMnode, pReq->user);
if (pUser == NULL) {
goto SYNC_DB_OVER;
}
if (mndCheckAlterDropCompactSyncDbAuth(pUser, pDb) != 0) {
goto SYNC_DB_OVER;
}
// code = mndSyncDb();
SYNC_DB_OVER:
if (code != 0) {
mError("db:%s, failed to process sync db req since %s", syncReq.db, terrstr());
} }
mndReleaseDb(pMnode, pDb); mndReleaseDb(pMnode, pDb);
return 0; mndReleaseUser(pMnode, pUser);
return code;
} }
static int32_t mndProcessCompactDbReq(SMnodeMsg *pReq) { static int32_t mndProcessCompactDbReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SCompactDbReq *pCompact = pReq->rpcMsg.pCont; int32_t code = -1;
SDbObj *pDb = mndAcquireDb(pMnode, pCompact->db); SDbObj *pDb = NULL;
SUserObj *pUser = NULL;
SCompactDbReq compactReq = {0};
if (tDeserializeSSyncDbReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &compactReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto SYNC_DB_OVER;
}
mDebug("db:%s, start to sync", compactReq.db);
pDb = mndAcquireDb(pMnode, compactReq.db);
if (pDb == NULL) { if (pDb == NULL) {
mError("db:%s, failed to process compact db req since %s", pCompact->db, terrstr()); goto SYNC_DB_OVER;
return -1; }
pUser = mndAcquireUser(pMnode, pReq->user);
if (pUser == NULL) {
goto SYNC_DB_OVER;
}
if (mndCheckAlterDropCompactSyncDbAuth(pUser, pDb) != 0) {
goto SYNC_DB_OVER;
}
// code = mndSyncDb();
SYNC_DB_OVER:
if (code != 0) {
mError("db:%s, failed to process compact db req since %s", compactReq.db, terrstr());
} }
mndReleaseDb(pMnode, pDb); mndReleaseDb(pMnode, pDb);
return 0; mndReleaseUser(pMnode, pUser);
return code;
} }
static int32_t mndGetDbMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { static int32_t mndGetDbMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) {
......
...@@ -343,17 +343,21 @@ static SClientHbRsp* mndMqHbBuildRsp(SMnode* pMnode, SClientHbReq* pReq) { ...@@ -343,17 +343,21 @@ static SClientHbRsp* mndMqHbBuildRsp(SMnode* pMnode, SClientHbReq* pReq) {
static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) { static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
char *batchReqStr = pReq->rpcMsg.pCont;
SClientHbBatchReq batchReq = {0}; SClientHbBatchReq batchReq = {0};
tDeserializeSClientHbBatchReq(batchReqStr, &batchReq); if (tDeserializeSClientHbBatchReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &batchReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
SArray *pArray = batchReq.reqs; SArray *pArray = batchReq.reqs;
int sz = taosArrayGetSize(pArray); int32_t sz = taosArrayGetSize(pArray);
SClientHbBatchRsp batchRsp = {0}; SClientHbBatchRsp batchRsp = {0};
batchRsp.rsps = taosArrayInit(0, sizeof(SClientHbRsp)); batchRsp.rsps = taosArrayInit(0, sizeof(SClientHbRsp));
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
SClientHbReq* pHbReq = taosArrayGet(pArray, i); SClientHbReq *pHbReq = taosArrayGet(pArray, i);
if (pHbReq->connKey.hbType == HEARTBEAT_TYPE_QUERY) { if (pHbReq->connKey.hbType == HEARTBEAT_TYPE_QUERY) {
int32_t kvNum = taosHashGetSize(pHbReq->info); int32_t kvNum = taosHashGetSize(pHbReq->info);
if (NULL == pHbReq->info || kvNum <= 0) { if (NULL == pHbReq->info || kvNum <= 0) {
...@@ -364,13 +368,13 @@ static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) { ...@@ -364,13 +368,13 @@ static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) {
void *pIter = taosHashIterate(pHbReq->info, NULL); void *pIter = taosHashIterate(pHbReq->info, NULL);
while (pIter != NULL) { while (pIter != NULL) {
SKv* kv = pIter; SKv *kv = pIter;
switch (kv->key) { switch (kv->key) {
case HEARTBEAT_KEY_DBINFO: { case HEARTBEAT_KEY_DBINFO: {
void *rspMsg = NULL; void *rspMsg = NULL;
int32_t rspLen = 0; int32_t rspLen = 0;
mndValidateDBInfo(pMnode, (SDbVgVersion *)kv->value, kv->valueLen/sizeof(SDbVgVersion), &rspMsg, &rspLen); mndValidateDbInfo(pMnode, kv->value, kv->valueLen / sizeof(SDbVgVersion), &rspMsg, &rspLen);
if (rspMsg && rspLen > 0) { if (rspMsg && rspLen > 0) {
SKv kv = {.key = HEARTBEAT_KEY_DBINFO, .valueLen = rspLen, .value = rspMsg}; SKv kv = {.key = HEARTBEAT_KEY_DBINFO, .valueLen = rspLen, .value = rspMsg};
taosArrayPush(hbRsp.info, &kv); taosArrayPush(hbRsp.info, &kv);
...@@ -378,9 +382,9 @@ static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) { ...@@ -378,9 +382,9 @@ static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) {
break; break;
} }
case HEARTBEAT_KEY_STBINFO: { case HEARTBEAT_KEY_STBINFO: {
void *rspMsg = NULL; void *rspMsg = NULL;
int32_t rspLen = 0; int32_t rspLen = 0;
mndValidateStbInfo(pMnode, (SSTableMetaVersion *)kv->value, kv->valueLen/sizeof(SSTableMetaVersion), &rspMsg, &rspLen); mndValidateStbInfo(pMnode, kv->value, kv->valueLen / sizeof(SSTableMetaVersion), &rspMsg, &rspLen);
if (rspMsg && rspLen > 0) { if (rspMsg && rspLen > 0) {
SKv kv = {.key = HEARTBEAT_KEY_STBINFO, .valueLen = rspLen, .value = rspMsg}; SKv kv = {.key = HEARTBEAT_KEY_STBINFO, .valueLen = rspLen, .value = rspMsg};
taosArrayPush(hbRsp.info, &kv); taosArrayPush(hbRsp.info, &kv);
...@@ -392,7 +396,7 @@ static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) { ...@@ -392,7 +396,7 @@ static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) {
hbRsp.status = TSDB_CODE_MND_APP_ERROR; hbRsp.status = TSDB_CODE_MND_APP_ERROR;
break; break;
} }
pIter = taosHashIterate(pHbReq->info, pIter); pIter = taosHashIterate(pHbReq->info, pIter);
} }
...@@ -407,15 +411,14 @@ static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) { ...@@ -407,15 +411,14 @@ static int32_t mndProcessHeartBeatReq(SMnodeMsg *pReq) {
} }
taosArrayDestroyEx(pArray, tFreeClientHbReq); taosArrayDestroyEx(pArray, tFreeClientHbReq);
int32_t tlen = tSerializeSClientHbBatchRsp(NULL, &batchRsp); int32_t tlen = tSerializeSClientHbBatchRsp(NULL, 0, &batchRsp);
void* buf = rpcMallocCont(tlen); void *buf = rpcMallocCont(tlen);
void* abuf = buf; tSerializeSClientHbBatchRsp(buf, tlen, &batchRsp);
tSerializeSClientHbBatchRsp(&abuf, &batchRsp);
int32_t rspNum = (int32_t)taosArrayGetSize(batchRsp.rsps); int32_t rspNum = (int32_t)taosArrayGetSize(batchRsp.rsps);
for (int32_t i = 0; i < rspNum; ++i) { for (int32_t i = 0; i < rspNum; ++i) {
SClientHbRsp *rsp = taosArrayGet(batchRsp.rsps, i); SClientHbRsp *rsp = taosArrayGet(batchRsp.rsps, i);
int32_t kvNum = (rsp->info) ? taosArrayGetSize(rsp->info): 0; int32_t kvNum = (rsp->info) ? taosArrayGetSize(rsp->info) : 0;
for (int32_t n = 0; n < kvNum; ++n) { for (int32_t n = 0; n < kvNum; ++n) {
SKv *kv = taosArrayGet(rsp->info, n); SKv *kv = taosArrayGet(rsp->info, n);
tfree(kv->value); tfree(kv->value);
......
...@@ -118,27 +118,28 @@ static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) { ...@@ -118,27 +118,28 @@ static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
static int32_t mndProcessShowReq(SMnodeMsg *pReq) { static int32_t mndProcessShowReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SShowMgmt *pMgmt = &pMnode->showMgmt; SShowMgmt *pMgmt = &pMnode->showMgmt;
SShowReq *pShowReq = pReq->rpcMsg.pCont; int32_t code = -1;
int8_t type = pShowReq->type; SShowReq showReq = {0};
int16_t payloadLen = htonl(pShowReq->payloadLen);
if (type <= TSDB_MGMT_TABLE_START || type >= TSDB_MGMT_TABLE_MAX) { if (tDeserializeSShowReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &showReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto SHOW_OVER;
}
if (showReq.type <= TSDB_MGMT_TABLE_START || showReq.type >= TSDB_MGMT_TABLE_MAX) {
terrno = TSDB_CODE_MND_INVALID_MSG_TYPE; terrno = TSDB_CODE_MND_INVALID_MSG_TYPE;
mError("failed to process show-meta req since %s", terrstr()); goto SHOW_OVER;
return -1;
} }
ShowMetaFp metaFp = pMgmt->metaFps[type]; ShowMetaFp metaFp = pMgmt->metaFps[showReq.type];
if (metaFp == NULL) { if (metaFp == NULL) {
terrno = TSDB_CODE_MND_INVALID_MSG_TYPE; terrno = TSDB_CODE_MND_INVALID_MSG_TYPE;
mError("failed to process show-meta req:%s since %s", mndShowStr(type), terrstr()); goto SHOW_OVER;
return -1;
} }
SShowObj *pShow = mndCreateShowObj(pMnode, pShowReq); SShowObj *pShow = mndCreateShowObj(pMnode, &showReq);
if (pShow == NULL) { if (pShow == NULL) {
mError("failed to process show-meta req:%s since %s", mndShowStr(type), terrstr()); goto SHOW_OVER;
return -1;
} }
int32_t size = sizeof(SShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE; int32_t size = sizeof(SShowRsp) + sizeof(SSchema) * TSDB_MAX_COLUMNS + TSDB_EXTRA_PAYLOAD_SIZE;
...@@ -146,26 +147,30 @@ static int32_t mndProcessShowReq(SMnodeMsg *pReq) { ...@@ -146,26 +147,30 @@ static int32_t mndProcessShowReq(SMnodeMsg *pReq) {
if (pRsp == NULL) { if (pRsp == NULL) {
mndReleaseShowObj(pShow, true); mndReleaseShowObj(pShow, true);
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
mError("show:0x%" PRIx64 ", failed to process show-meta req:%s since malloc rsp error", pShow->id, goto SHOW_OVER;
mndShowStr(type));
return -1;
} }
int32_t code = (*metaFp)(pReq, pShow, &pRsp->tableMeta); code = (*metaFp)(pReq, pShow, &pRsp->tableMeta);
mDebug("show:0x%" PRIx64 ", get meta finished, numOfRows:%d cols:%d type:%s, result:%s", pShow->id, pShow->numOfRows, mDebug("show:0x%" PRIx64 ", get meta finished, numOfRows:%d cols:%d showReq.type:%s, result:%s", pShow->id,
pShow->numOfColumns, mndShowStr(type), tstrerror(code)); pShow->numOfRows, pShow->numOfColumns, mndShowStr(showReq.type), tstrerror(code));
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
pReq->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns; pReq->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns;
pReq->pCont = pRsp; pReq->pCont = pRsp;
pRsp->showId = htobe64(pShow->id); pRsp->showId = htobe64(pShow->id);
mndReleaseShowObj(pShow, false); mndReleaseShowObj(pShow, false);
return TSDB_CODE_SUCCESS;
} else { } else {
rpcFreeCont(pRsp); rpcFreeCont(pRsp);
mndReleaseShowObj(pShow, true); mndReleaseShowObj(pShow, true);
return code;
} }
SHOW_OVER:
if (code != 0) {
mError("failed to process show-meta req since %s", terrstr());
}
tFreeSShowReq(&showReq);
return code;
} }
static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) { static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) {
...@@ -175,10 +180,13 @@ static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) { ...@@ -175,10 +180,13 @@ static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) {
int32_t size = 0; int32_t size = 0;
int32_t rowsRead = 0; int32_t rowsRead = 0;
SRetrieveTableReq *pRetrieve = pReq->rpcMsg.pCont; SRetrieveTableReq retrieveReq = {0};
int64_t showId = htobe64(pRetrieve->showId); if (tDeserializeSRetrieveTableReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &retrieveReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
SShowObj *pShow = mndAcquireShowObj(pMnode, showId); SShowObj *pShow = mndAcquireShowObj(pMnode, retrieveReq.showId);
if (pShow == NULL) { if (pShow == NULL) {
terrno = TSDB_CODE_MND_INVALID_SHOWOBJ; terrno = TSDB_CODE_MND_INVALID_SHOWOBJ;
mError("failed to process show-retrieve req:%p since %s", pShow, terrstr()); mError("failed to process show-retrieve req:%p since %s", pShow, terrstr());
...@@ -202,7 +210,7 @@ static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) { ...@@ -202,7 +210,7 @@ static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) {
pShow->numOfReads = pShow->numOfRows; pShow->numOfReads = pShow->numOfRows;
} }
if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { if ((retrieveReq.free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) {
rowsToRead = pShow->numOfRows - pShow->numOfReads; rowsToRead = pShow->numOfRows - pShow->numOfReads;
} }
...@@ -226,7 +234,7 @@ static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) { ...@@ -226,7 +234,7 @@ static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) {
} }
// if free flag is set, client wants to clean the resources // if free flag is set, client wants to clean the resources
if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { if ((retrieveReq.free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) {
rowsRead = (*retrieveFp)(pReq, pShow, pRsp->data, rowsToRead); rowsRead = (*retrieveFp)(pReq, pShow, pRsp->data, rowsToRead);
} }
......
...@@ -542,12 +542,18 @@ static void mndTransSendRpcRsp(STrans *pTrans) { ...@@ -542,12 +542,18 @@ static void mndTransSendRpcRsp(STrans *pTrans) {
} }
if (sendRsp && pTrans->rpcHandle != NULL) { if (sendRsp && pTrans->rpcHandle != NULL) {
void *rpcCont = rpcMallocCont(pTrans->rpcRspLen);
if (rpcCont != NULL) {
memcpy(rpcCont, pTrans->rpcRsp, pTrans->rpcRspLen);
}
free(pTrans->rpcRsp);
mDebug("trans:%d, send rsp, code:0x%x stage:%d app:%p", pTrans->id, pTrans->code & 0xFFFF, pTrans->stage, mDebug("trans:%d, send rsp, code:0x%x stage:%d app:%p", pTrans->id, pTrans->code & 0xFFFF, pTrans->stage,
pTrans->rpcAHandle); pTrans->rpcAHandle);
SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, SRpcMsg rspMsg = {.handle = pTrans->rpcHandle,
.code = pTrans->code, .code = pTrans->code,
.ahandle = pTrans->rpcAHandle, .ahandle = pTrans->rpcAHandle,
.pCont = pTrans->rpcRsp, .pCont = rpcCont,
.contLen = pTrans->rpcRspLen}; .contLen = pTrans->rpcRspLen};
rpcSendResponse(&rspMsg); rpcSendResponse(&rspMsg);
pTrans->rpcHandle = NULL; pTrans->rpcHandle = NULL;
......
...@@ -56,10 +56,13 @@ TEST_F(MndTestAcct, 03_Drop_Acct) { ...@@ -56,10 +56,13 @@ TEST_F(MndTestAcct, 03_Drop_Acct) {
} }
TEST_F(MndTestAcct, 04_Show_Acct) { TEST_F(MndTestAcct, 04_Show_Acct) {
int32_t contLen = sizeof(SShowReq); SShowReq showReq = {0};
showReq.type = TSDB_MGMT_TABLE_ACCT;
SShowReq* pReq = (SShowReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
pReq->type = TSDB_MGMT_TABLE_ACCT; void* pReq = rpcMallocCont(contLen);
tSerializeSShowReq(pReq, contLen, &showReq);
tFreeSShowReq(&showReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
......
...@@ -53,29 +53,31 @@ TEST_F(MndTestDb, 01_ShowDb) { ...@@ -53,29 +53,31 @@ TEST_F(MndTestDb, 01_ShowDb) {
TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) { TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
{ {
int32_t contLen = sizeof(SCreateDbReq); SCreateDbReq createReq = {0};
strcpy(createReq.db, "1.d1");
SCreateDbReq* pReq = (SCreateDbReq*)rpcMallocCont(contLen); createReq.numOfVgroups = 2;
strcpy(pReq->db, "1.d1"); createReq.cacheBlockSize = 16;
pReq->numOfVgroups = htonl(2); createReq.totalBlocks = 10;
pReq->cacheBlockSize = htonl(16); createReq.daysPerFile = 10;
pReq->totalBlocks = htonl(10); createReq.daysToKeep0 = 3650;
pReq->daysPerFile = htonl(10); createReq.daysToKeep1 = 3650;
pReq->daysToKeep0 = htonl(3650); createReq.daysToKeep2 = 3650;
pReq->daysToKeep1 = htonl(3650); createReq.minRows = 100;
pReq->daysToKeep2 = htonl(3650); createReq.maxRows = 4096;
pReq->minRows = htonl(100); createReq.commitTime = 3600;
pReq->maxRows = htonl(4096); createReq.fsyncPeriod = 3000;
pReq->commitTime = htonl(3600); createReq.walLevel = 1;
pReq->fsyncPeriod = htonl(3000); createReq.precision = 0;
pReq->walLevel = 1; createReq.compression = 2;
pReq->precision = 0; createReq.replications = 1;
pReq->compression = 2; createReq.quorum = 1;
pReq->replications = 1; createReq.update = 0;
pReq->quorum = 1; createReq.cacheLastRow = 0;
pReq->update = 0; createReq.ignoreExist = 1;
pReq->cacheLastRow = 0;
pReq->ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDbReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -125,18 +127,20 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) { ...@@ -125,18 +127,20 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
CheckBinary("master", 9); CheckBinary("master", 9);
{ {
int32_t contLen = sizeof(SAlterDbReq); SAlterDbReq alterdbReq = {0};
strcpy(alterdbReq.db, "1.d1");
SAlterDbReq* pReq = (SAlterDbReq*)rpcMallocCont(contLen); alterdbReq.totalBlocks = 12;
strcpy(pReq->db, "1.d1"); alterdbReq.daysToKeep0 = 300;
pReq->totalBlocks = htonl(12); alterdbReq.daysToKeep1 = 400;
pReq->daysToKeep0 = htonl(300); alterdbReq.daysToKeep2 = 500;
pReq->daysToKeep1 = htonl(400); alterdbReq.fsyncPeriod = 4000;
pReq->daysToKeep2 = htonl(500); alterdbReq.walLevel = 2;
pReq->fsyncPeriod = htonl(4000); alterdbReq.quorum = 2;
pReq->walLevel = 2; alterdbReq.cacheLastRow = 1;
pReq->quorum = 2;
pReq->cacheLastRow = 1; int32_t contLen = tSerializeSAlterDbReq(NULL, 0, &alterdbReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSAlterDbReq(pReq, contLen, &alterdbReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -194,18 +198,20 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) { ...@@ -194,18 +198,20 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
CheckInt8(0); // update CheckInt8(0); // update
{ {
int32_t contLen = sizeof(SDropDbReq); SDropDbReq dropdbReq = {0};
strcpy(dropdbReq.db, "1.d1");
SDropDbReq* pReq = (SDropDbReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSDropDbReq(NULL, 0, &dropdbReq);
strcpy(pReq->db, "1.d1"); void* pReq = rpcMallocCont(contLen);
tSerializeSDropDbReq(pReq, contLen, &dropdbReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0); ASSERT_EQ(pRsp->code, 0);
SDropDbRsp* pDrop = (SDropDbRsp*)pRsp->pCont; SDropDbRsp dropdbRsp = {0};
pDrop->uid = htobe64(pDrop->uid); tDeserializeSDropDbRsp(pRsp->pCont, pRsp->contLen, &dropdbRsp);
EXPECT_STREQ(pDrop->db, "1.d1"); EXPECT_STREQ(dropdbRsp.db, "1.d1");
} }
test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
...@@ -217,29 +223,31 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) { ...@@ -217,29 +223,31 @@ TEST_F(MndTestDb, 02_Create_Alter_Drop_Db) {
TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) { TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) {
{ {
int32_t contLen = sizeof(SCreateDbReq); SCreateDbReq createReq = {0};
strcpy(createReq.db, "1.d2");
SCreateDbReq* pReq = (SCreateDbReq*)rpcMallocCont(contLen); createReq.numOfVgroups = 2;
strcpy(pReq->db, "1.d2"); createReq.cacheBlockSize = 16;
pReq->numOfVgroups = htonl(2); createReq.totalBlocks = 10;
pReq->cacheBlockSize = htonl(16); createReq.daysPerFile = 10;
pReq->totalBlocks = htonl(10); createReq.daysToKeep0 = 3650;
pReq->daysPerFile = htonl(10); createReq.daysToKeep1 = 3650;
pReq->daysToKeep0 = htonl(3650); createReq.daysToKeep2 = 3650;
pReq->daysToKeep1 = htonl(3650); createReq.minRows = 100;
pReq->daysToKeep2 = htonl(3650); createReq.maxRows = 4096;
pReq->minRows = htonl(100); createReq.commitTime = 3600;
pReq->maxRows = htonl(4096); createReq.fsyncPeriod = 3000;
pReq->commitTime = htonl(3600); createReq.walLevel = 1;
pReq->fsyncPeriod = htonl(3000); createReq.precision = 0;
pReq->walLevel = 1; createReq.compression = 2;
pReq->precision = 0; createReq.replications = 1;
pReq->compression = 2; createReq.quorum = 1;
pReq->replications = 1; createReq.update = 0;
pReq->quorum = 1; createReq.cacheLastRow = 0;
pReq->update = 0; createReq.ignoreExist = 1;
pReq->cacheLastRow = 0;
pReq->ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDbReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -256,73 +264,74 @@ TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) { ...@@ -256,73 +264,74 @@ TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) {
uint64_t d2_uid = 0; uint64_t d2_uid = 0;
{ {
int32_t contLen = sizeof(SUseDbReq); SUseDbReq usedbReq = {0};
strcpy(usedbReq.db, "1.d2");
usedbReq.vgVersion = -1;
SUseDbReq* pReq = (SUseDbReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
strcpy(pReq->db, "1.d2"); void* pReq = rpcMallocCont(contLen);
pReq->vgVersion = htonl(-1); tSerializeSUseDbReq(pReq, contLen, &usedbReq);
SRpcMsg* pMsg = test.SendReq(TDMT_MND_USE_DB, pReq, contLen); SRpcMsg* pMsg = test.SendReq(TDMT_MND_USE_DB, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->code, 0);
SUseDbRsp* pRsp = (SUseDbRsp*)pMsg->pCont; SUseDbRsp usedbRsp = {0};
EXPECT_STREQ(pRsp->db, "1.d2"); tDeserializeSUseDbRsp(pMsg->pCont, pMsg->contLen, &usedbRsp);
pRsp->uid = htobe64(pRsp->uid); EXPECT_STREQ(usedbRsp.db, "1.d2");
d2_uid = pRsp->uid; EXPECT_EQ(usedbRsp.vgVersion, 1);
pRsp->vgVersion = htonl(pRsp->vgVersion); EXPECT_EQ(usedbRsp.vgNum, 2);
pRsp->vgNum = htonl(pRsp->vgNum); EXPECT_EQ(usedbRsp.hashMethod, 1);
pRsp->hashMethod = pRsp->hashMethod; d2_uid = usedbRsp.uid;
EXPECT_EQ(pRsp->vgVersion, 1);
EXPECT_EQ(pRsp->vgNum, 2);
EXPECT_EQ(pRsp->hashMethod, 1);
{ {
SVgroupInfo* pInfo = &pRsp->vgroupInfo[0]; SVgroupInfo* pInfo = (SVgroupInfo*)taosArrayGet(usedbRsp.pVgroupInfos, 0);
pInfo->vgId = htonl(pInfo->vgId); pInfo->vgId = pInfo->vgId;
pInfo->hashBegin = htonl(pInfo->hashBegin); pInfo->hashBegin = pInfo->hashBegin;
pInfo->hashEnd = htonl(pInfo->hashEnd); pInfo->hashEnd = pInfo->hashEnd;
EXPECT_GT(pInfo->vgId, 0); EXPECT_GT(pInfo->vgId, 0);
EXPECT_EQ(pInfo->hashBegin, 0); EXPECT_EQ(pInfo->hashBegin, 0);
EXPECT_EQ(pInfo->hashEnd, UINT32_MAX / 2 - 1); EXPECT_EQ(pInfo->hashEnd, UINT32_MAX / 2 - 1);
EXPECT_EQ(pInfo->epset.inUse, 0); EXPECT_EQ(pInfo->epset.inUse, 0);
EXPECT_EQ(pInfo->epset.numOfEps, 1); EXPECT_EQ(pInfo->epset.numOfEps, 1);
SEp* pAddr = &pInfo->epset.eps[0]; SEp* pAddr = &pInfo->epset.eps[0];
pAddr->port = htons(pAddr->port);
EXPECT_EQ(pAddr->port, 9030); EXPECT_EQ(pAddr->port, 9030);
EXPECT_STREQ(pAddr->fqdn, "localhost"); EXPECT_STREQ(pAddr->fqdn, "localhost");
} }
{ {
SVgroupInfo* pInfo = &pRsp->vgroupInfo[1]; SVgroupInfo* pInfo = (SVgroupInfo*)taosArrayGet(usedbRsp.pVgroupInfos, 1);
pInfo->vgId = htonl(pInfo->vgId); pInfo->vgId = pInfo->vgId;
pInfo->hashBegin = htonl(pInfo->hashBegin); pInfo->hashBegin = pInfo->hashBegin;
pInfo->hashEnd = htonl(pInfo->hashEnd); pInfo->hashEnd = pInfo->hashEnd;
EXPECT_GT(pInfo->vgId, 0); EXPECT_GT(pInfo->vgId, 0);
EXPECT_EQ(pInfo->hashBegin, UINT32_MAX / 2); EXPECT_EQ(pInfo->hashBegin, UINT32_MAX / 2);
EXPECT_EQ(pInfo->hashEnd, UINT32_MAX); EXPECT_EQ(pInfo->hashEnd, UINT32_MAX);
EXPECT_EQ(pInfo->epset.inUse, 0); EXPECT_EQ(pInfo->epset.inUse, 0);
EXPECT_EQ(pInfo->epset.numOfEps, 1); EXPECT_EQ(pInfo->epset.numOfEps, 1);
SEp* pAddr = &pInfo->epset.eps[0]; SEp* pAddr = &pInfo->epset.eps[0];
pAddr->port = htons(pAddr->port);
EXPECT_EQ(pAddr->port, 9030); EXPECT_EQ(pAddr->port, 9030);
EXPECT_STREQ(pAddr->fqdn, "localhost"); EXPECT_STREQ(pAddr->fqdn, "localhost");
} }
tFreeSUsedbRsp(&usedbRsp);
} }
{ {
int32_t contLen = sizeof(SDropDbReq); SDropDbReq dropdbReq = {0};
strcpy(dropdbReq.db, "1.d2");
SDropDbReq* pReq = (SDropDbReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSDropDbReq(NULL, 0, &dropdbReq);
strcpy(pReq->db, "1.d2"); void* pReq = rpcMallocCont(contLen);
tSerializeSDropDbReq(pReq, contLen, &dropdbReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0); ASSERT_EQ(pRsp->code, 0);
SDropDbRsp* pDrop = (SDropDbRsp*)pRsp->pCont; SDropDbRsp dropdbRsp = {0};
pDrop->uid = htobe64(pDrop->uid); tDeserializeSDropDbRsp(pRsp->pCont, pRsp->contLen, &dropdbRsp);
EXPECT_STREQ(pDrop->db, "1.d2"); EXPECT_STREQ(dropdbRsp.db, "1.d2");
EXPECT_EQ(pDrop->uid, d2_uid); EXPECT_EQ(dropdbRsp.uid, d2_uid);
} }
} }
...@@ -96,35 +96,35 @@ TEST_F(MndTestProfile, 03_ConnectMsg_Show) { ...@@ -96,35 +96,35 @@ TEST_F(MndTestProfile, 03_ConnectMsg_Show) {
} }
TEST_F(MndTestProfile, 04_HeartBeatMsg) { TEST_F(MndTestProfile, 04_HeartBeatMsg) {
SClientHbBatchReq batchReq; SClientHbBatchReq batchReq = {0};
batchReq.reqs = taosArrayInit(0, sizeof(SClientHbReq)); batchReq.reqs = taosArrayInit(0, sizeof(SClientHbReq));
SClientHbReq req = {0}; SClientHbReq req = {0};
req.connKey = {.connId = 123, .hbType = HEARTBEAT_TYPE_MQ}; req.connKey = {.connId = 123, .hbType = HEARTBEAT_TYPE_MQ};
req.info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK); req.info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
SKv kv; SKv kv = {0};
kv.key = 123; kv.key = 123;
kv.value = (void*)"bcd"; kv.value = (void*)"bcd";
kv.valueLen = 4; kv.valueLen = 4;
taosHashPut(req.info, &kv.key, sizeof(kv.key), &kv, sizeof(kv)); taosHashPut(req.info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
taosArrayPush(batchReq.reqs, &req); taosArrayPush(batchReq.reqs, &req);
int32_t tlen = tSerializeSClientHbBatchReq(NULL, &batchReq); int32_t tlen = tSerializeSClientHbBatchReq(NULL, 0, &batchReq);
void* buf = (SClientHbBatchReq*)rpcMallocCont(tlen);
void* buf = (SClientHbBatchReq*)rpcMallocCont(tlen); tSerializeSClientHbBatchReq(buf, tlen, &batchReq);
void* bufCopy = buf;
tSerializeSClientHbBatchReq(&bufCopy, &batchReq);
SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, buf, tlen); SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, buf, tlen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->code, 0);
char* pRspChar = (char*)pMsg->pCont;
SClientHbBatchRsp rsp = {0}; SClientHbBatchRsp rsp = {0};
tDeserializeSClientHbBatchRsp(pRspChar, &rsp); tDeserializeSClientHbBatchRsp(pMsg->pCont, pMsg->contLen, &rsp);
int sz = taosArrayGetSize(rsp.rsps); int sz = taosArrayGetSize(rsp.rsps);
ASSERT_EQ(sz, 0); ASSERT_EQ(sz, 0);
//SClientHbRsp* pRsp = (SClientHbRsp*) taosArrayGet(rsp.rsps, 0);
//EXPECT_EQ(pRsp->connKey.connId, 123); // SClientHbRsp* pRsp = (SClientHbRsp*) taosArrayGet(rsp.rsps, 0);
//EXPECT_EQ(pRsp->connKey.hbType, HEARTBEAT_TYPE_MQ); // EXPECT_EQ(pRsp->connKey.connId, 123);
//EXPECT_EQ(pRsp->status, 0); // EXPECT_EQ(pRsp->connKey.hbType, HEARTBEAT_TYPE_MQ);
// EXPECT_EQ(pRsp->status, 0);
#if 0 #if 0
int32_t contLen = sizeof(SHeartBeatReq); int32_t contLen = sizeof(SHeartBeatReq);
......
...@@ -26,11 +26,13 @@ class MndTestShow : public ::testing::Test { ...@@ -26,11 +26,13 @@ class MndTestShow : public ::testing::Test {
Testbase MndTestShow::test; Testbase MndTestShow::test;
TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) { TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) {
int32_t contLen = sizeof(SShowReq); SShowReq showReq = {0};
showReq.type = TSDB_MGMT_TABLE_MAX;
SShowReq* pReq = (SShowReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
pReq->type = TSDB_MGMT_TABLE_MAX; void* pReq = rpcMallocCont(contLen);
strcpy(pReq->db, ""); tSerializeSShowReq(pReq, contLen, &showReq);
tFreeSShowReq(&showReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -38,11 +40,13 @@ TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) { ...@@ -38,11 +40,13 @@ TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) {
} }
TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) { TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) {
int32_t contLen = sizeof(SShowReq); SShowReq showReq = {0};
showReq.type = TSDB_MGMT_TABLE_START;
SShowReq* pReq = (SShowReq*)rpcMallocCont(sizeof(SShowReq)); int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq);
pReq->type = TSDB_MGMT_TABLE_START; void* pReq = rpcMallocCont(contLen);
strcpy(pReq->db, ""); tSerializeSShowReq(pReq, contLen, &showReq);
tFreeSShowReq(&showReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
......
...@@ -38,39 +38,43 @@ class MndTestStb : public ::testing::Test { ...@@ -38,39 +38,43 @@ class MndTestStb : public ::testing::Test {
Testbase MndTestStb::test; Testbase MndTestStb::test;
void* MndTestStb::BuildCreateDbReq(const char* dbname, int32_t* pContLen) { void* MndTestStb::BuildCreateDbReq(const char* dbname, int32_t* pContLen) {
int32_t contLen = sizeof(SCreateDbReq); SCreateDbReq createReq = {0};
strcpy(createReq.db, dbname);
SCreateDbReq* pReq = (SCreateDbReq*)rpcMallocCont(contLen); createReq.numOfVgroups = 2;
strcpy(pReq->db, dbname); createReq.cacheBlockSize = 16;
pReq->numOfVgroups = htonl(2); createReq.totalBlocks = 10;
pReq->cacheBlockSize = htonl(16); createReq.daysPerFile = 10;
pReq->totalBlocks = htonl(10); createReq.daysToKeep0 = 3650;
pReq->daysPerFile = htonl(10); createReq.daysToKeep1 = 3650;
pReq->daysToKeep0 = htonl(3650); createReq.daysToKeep2 = 3650;
pReq->daysToKeep1 = htonl(3650); createReq.minRows = 100;
pReq->daysToKeep2 = htonl(3650); createReq.maxRows = 4096;
pReq->minRows = htonl(100); createReq.commitTime = 3600;
pReq->maxRows = htonl(4096); createReq.fsyncPeriod = 3000;
pReq->commitTime = htonl(3600); createReq.walLevel = 1;
pReq->fsyncPeriod = htonl(3000); createReq.precision = 0;
pReq->walLevel = 1; createReq.compression = 2;
pReq->precision = 0; createReq.replications = 1;
pReq->compression = 2; createReq.quorum = 1;
pReq->replications = 1; createReq.update = 0;
pReq->quorum = 1; createReq.cacheLastRow = 0;
pReq->update = 0; createReq.ignoreExist = 1;
pReq->cacheLastRow = 0;
pReq->ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDbReq(pReq, contLen, &createReq);
*pContLen = contLen; *pContLen = contLen;
return pReq; return pReq;
} }
void* MndTestStb::BuildDropDbReq(const char* dbname, int32_t* pContLen) { void* MndTestStb::BuildDropDbReq(const char* dbname, int32_t* pContLen) {
int32_t contLen = sizeof(SDropDbReq); SDropDbReq dropdbReq = {0};
strcpy(dropdbReq.db, dbname);
SDropDbReq* pReq = (SDropDbReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSDropDbReq(NULL, 0, &dropdbReq);
strcpy(pReq->db, dbname); void* pReq = rpcMallocCont(contLen);
tSerializeSDropDbReq(pReq, contLen, &dropdbReq);
*pContLen = contLen; *pContLen = contLen;
return pReq; return pReq;
......
...@@ -319,29 +319,31 @@ TEST_F(MndTestUser, 03_Alter_User) { ...@@ -319,29 +319,31 @@ TEST_F(MndTestUser, 03_Alter_User) {
} }
{ {
int32_t contLen = sizeof(SCreateDbReq); SCreateDbReq createReq = {0};
strcpy(createReq.db, "1.d2");
SCreateDbReq* pReq = (SCreateDbReq*)rpcMallocCont(contLen); createReq.numOfVgroups = 2;
strcpy(pReq->db, "1.d2"); createReq.cacheBlockSize = 16;
pReq->numOfVgroups = htonl(2); createReq.totalBlocks = 10;
pReq->cacheBlockSize = htonl(16); createReq.daysPerFile = 10;
pReq->totalBlocks = htonl(10); createReq.daysToKeep0 = 3650;
pReq->daysPerFile = htonl(10); createReq.daysToKeep1 = 3650;
pReq->daysToKeep0 = htonl(3650); createReq.daysToKeep2 = 3650;
pReq->daysToKeep1 = htonl(3650); createReq.minRows = 100;
pReq->daysToKeep2 = htonl(3650); createReq.maxRows = 4096;
pReq->minRows = htonl(100); createReq.commitTime = 3600;
pReq->maxRows = htonl(4096); createReq.fsyncPeriod = 3000;
pReq->commitTime = htonl(3600); createReq.walLevel = 1;
pReq->fsyncPeriod = htonl(3000); createReq.precision = 0;
pReq->walLevel = 1; createReq.compression = 2;
pReq->precision = 0; createReq.replications = 1;
pReq->compression = 2; createReq.quorum = 1;
pReq->replications = 1; createReq.update = 0;
pReq->quorum = 1; createReq.cacheLastRow = 0;
pReq->update = 0; createReq.ignoreExist = 1;
pReq->cacheLastRow = 0;
pReq->ignoreExist = 1; int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDbReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
......
...@@ -65,14 +65,14 @@ bool ctgTestDeadLoop = false; ...@@ -65,14 +65,14 @@ bool ctgTestDeadLoop = false;
int32_t ctgTestPrintNum = 200000; int32_t ctgTestPrintNum = 200000;
int32_t ctgTestMTRunSec = 5; int32_t ctgTestMTRunSec = 5;
int32_t ctgTestCurrentVgVersion = 0; int32_t ctgTestCurrentVgVersion = 0;
int32_t ctgTestVgVersion = 1; int32_t ctgTestVgVersion = 1;
int32_t ctgTestVgNum = 10; int32_t ctgTestVgNum = 10;
int32_t ctgTestColNum = 2; int32_t ctgTestColNum = 2;
int32_t ctgTestTagNum = 1; int32_t ctgTestTagNum = 1;
int32_t ctgTestSVersion = 1; int32_t ctgTestSVersion = 1;
int32_t ctgTestTVersion = 1; int32_t ctgTestTVersion = 1;
int32_t ctgTestSuid = 2; int32_t ctgTestSuid = 2;
uint64_t ctgTestDbId = 33; uint64_t ctgTestDbId = 33;
uint64_t ctgTestClusterId = 0x1; uint64_t ctgTestClusterId = 0x1;
...@@ -85,35 +85,38 @@ int32_t ctgTestRspFunc[10] = {0}; ...@@ -85,35 +85,38 @@ int32_t ctgTestRspFunc[10] = {0};
int32_t ctgTestRspIdx = 0; int32_t ctgTestRspIdx = 0;
void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) { void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
SCreateDbReq *pReq = (SCreateDbReq *)rpcMallocCont(sizeof(SCreateDbReq)); SCreateDbReq createReq = {0};
strcpy(pReq->db, "1.db1"); strcpy(createReq.db, "1.db1");
pReq->numOfVgroups = htonl(2); createReq.numOfVgroups = 2;
pReq->cacheBlockSize = htonl(16); createReq.cacheBlockSize = 16;
pReq->totalBlocks = htonl(10); createReq.totalBlocks = 10;
pReq->daysPerFile = htonl(10); createReq.daysPerFile = 10;
pReq->daysToKeep0 = htonl(3650); createReq.daysToKeep0 = 3650;
pReq->daysToKeep1 = htonl(3650); createReq.daysToKeep1 = 3650;
pReq->daysToKeep2 = htonl(3650); createReq.daysToKeep2 = 3650;
pReq->minRows = htonl(100); createReq.minRows = 100;
pReq->maxRows = htonl(4096); createReq.maxRows = 4096;
pReq->commitTime = htonl(3600); createReq.commitTime = 3600;
pReq->fsyncPeriod = htonl(3000); createReq.fsyncPeriod = 3000;
pReq->walLevel = 1; createReq.walLevel = 1;
pReq->precision = 0; createReq.precision = 0;
pReq->compression = 2; createReq.compression = 2;
pReq->replications = 1; createReq.replications = 1;
pReq->quorum = 1; createReq.quorum = 1;
pReq->update = 0; createReq.update = 0;
pReq->cacheLastRow = 0; createReq.cacheLastRow = 0;
pReq->ignoreExist = 1; createReq.ignoreExist = 1;
int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
void *pReq = rpcMallocCont(contLen);
tSerializeSCreateDbReq(pReq, contLen, &createReq);
SRpcMsg rpcMsg = {0}; SRpcMsg rpcMsg = {0};
rpcMsg.pCont = pReq; rpcMsg.pCont = pReq;
rpcMsg.contLen = sizeof(SCreateDbReq); rpcMsg.contLen = contLen;
rpcMsg.msgType = TDMT_MND_CREATE_DB; rpcMsg.msgType = TDMT_MND_CREATE_DB;
SRpcMsg rpcRsp = {0}; SRpcMsg rpcRsp = {0};
rpcSendRecv(shandle, pEpSet, &rpcMsg, &rpcRsp); rpcSendRecv(shandle, pEpSet, &rpcMsg, &rpcRsp);
ASSERT_EQ(rpcRsp.code, 0); ASSERT_EQ(rpcRsp.code, 0);
...@@ -228,7 +231,6 @@ void ctgTestBuildDBVgroup(SDBVgInfo **pdbVgroup) { ...@@ -228,7 +231,6 @@ void ctgTestBuildDBVgroup(SDBVgInfo **pdbVgroup) {
*pdbVgroup = dbVgroup; *pdbVgroup = dbVgroup;
} }
void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) { void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) {
strcpy(rspMsg->dbFName, ctgTestDbname); strcpy(rspMsg->dbFName, ctgTestDbname);
sprintf(rspMsg->tbName, "%s", ctgTestSTablename); sprintf(rspMsg->tbName, "%s", ctgTestSTablename);
...@@ -266,41 +268,44 @@ void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) { ...@@ -266,41 +268,44 @@ void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) {
return; return;
} }
void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
SUseDbRsp *rspMsg = NULL; // todo SUseDbRsp usedbRsp = {0};
strcpy(usedbRsp.db, ctgTestDbname);
pRsp->code = 0; usedbRsp.vgVersion = ctgTestVgVersion;
pRsp->contLen = sizeof(SUseDbRsp) + ctgTestVgNum * sizeof(SVgroupInfo);
pRsp->pCont = calloc(1, pRsp->contLen);
rspMsg = (SUseDbRsp *)pRsp->pCont;
strcpy(rspMsg->db, ctgTestDbname);
rspMsg->vgVersion = htonl(ctgTestVgVersion);
ctgTestCurrentVgVersion = ctgTestVgVersion; ctgTestCurrentVgVersion = ctgTestVgVersion;
rspMsg->vgNum = htonl(ctgTestVgNum); usedbRsp.vgNum = ctgTestVgNum;
rspMsg->hashMethod = 0; usedbRsp.hashMethod = 0;
rspMsg->uid = htobe64(ctgTestDbId); usedbRsp.uid = ctgTestDbId;
usedbRsp.pVgroupInfos = taosArrayInit(usedbRsp.vgNum, sizeof(SVgroupInfo));
SVgroupInfo *vg = NULL; uint32_t hashUnit = UINT32_MAX / ctgTestVgNum;
uint32_t hashUnit = UINT32_MAX / ctgTestVgNum;
for (int32_t i = 0; i < ctgTestVgNum; ++i) { for (int32_t i = 0; i < ctgTestVgNum; ++i) {
vg = &rspMsg->vgroupInfo[i]; SVgroupInfo vg = {0};
vg.vgId = i + 1;
vg->vgId = htonl(i + 1); vg.hashBegin = i * hashUnit;
vg->hashBegin = htonl(i * hashUnit); vg.hashEnd = hashUnit * (i + 1) - 1;
vg->hashEnd = htonl(hashUnit * (i + 1) - 1); if (i == ctgTestVgNum - 1) {
vg->epset.numOfEps = i % TSDB_MAX_REPLICA + 1; vg.hashEnd = htonl(UINT32_MAX);
vg->epset.inUse = i % vg->epset.numOfEps; }
for (int32_t n = 0; n < vg->epset.numOfEps; ++n) {
SEp *addr = &vg->epset.eps[n]; vg.epset.numOfEps = i % TSDB_MAX_REPLICA + 1;
vg.epset.inUse = i % vg.epset.numOfEps;
for (int32_t n = 0; n < vg.epset.numOfEps; ++n) {
SEp *addr = &vg.epset.eps[n];
strcpy(addr->fqdn, "a0"); strcpy(addr->fqdn, "a0");
addr->port = htons(n + 22); addr->port = n + 22;
} }
taosArrayPush(usedbRsp.pVgroupInfos, &vg);
} }
vg->hashEnd = htonl(UINT32_MAX); int32_t contLen = tSerializeSUseDbRsp(NULL, 0, &usedbRsp);
void *pReq = rpcMallocCont(contLen);
tSerializeSUseDbRsp(pReq, contLen, &usedbRsp);
return; pRsp->code = 0;
pRsp->contLen = contLen;
pRsp->pCont = pReq;
} }
void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
...@@ -390,8 +395,8 @@ void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg ...@@ -390,8 +395,8 @@ void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg
pRsp->pCont = calloc(1, pRsp->contLen); pRsp->pCont = calloc(1, pRsp->contLen);
rspMsg = (STableMetaRsp *)pRsp->pCont; rspMsg = (STableMetaRsp *)pRsp->pCont;
strcpy(rspMsg->dbFName, ctgTestDbname); strcpy(rspMsg->dbFName, ctgTestDbname);
strcpy(rspMsg->tbName, ctgTestSTablename); strcpy(rspMsg->tbName, ctgTestSTablename);
strcpy(rspMsg->stbName, ctgTestSTablename); strcpy(rspMsg->stbName, ctgTestSTablename);
rspMsg->numOfTags = htonl(ctgTestTagNum); rspMsg->numOfTags = htonl(ctgTestTagNum);
rspMsg->numOfColumns = htonl(ctgTestColNum); rspMsg->numOfColumns = htonl(ctgTestColNum);
rspMsg->precision = 1; rspMsg->precision = 1;
...@@ -716,7 +721,6 @@ void *ctgTestSetSameDbVgroupThread(void *param) { ...@@ -716,7 +721,6 @@ void *ctgTestSetSameDbVgroupThread(void *param) {
return NULL; return NULL;
} }
void *ctgTestSetDiffDbVgroupThread(void *param) { void *ctgTestSetDiffDbVgroupThread(void *param) {
struct SCatalog *pCtg = (struct SCatalog *)param; struct SCatalog *pCtg = (struct SCatalog *)param;
int32_t code = 0; int32_t code = 0;
...@@ -741,7 +745,6 @@ void *ctgTestSetDiffDbVgroupThread(void *param) { ...@@ -741,7 +745,6 @@ void *ctgTestSetDiffDbVgroupThread(void *param) {
return NULL; return NULL;
} }
void *ctgTestGetCtableMetaThread(void *param) { void *ctgTestGetCtableMetaThread(void *param) {
struct SCatalog *pCtg = (struct SCatalog *)param; struct SCatalog *pCtg = (struct SCatalog *)param;
int32_t code = 0; int32_t code = 0;
...@@ -1008,7 +1011,7 @@ TEST(tableMeta, childTableCase) { ...@@ -1008,7 +1011,7 @@ TEST(tableMeta, childTableCase) {
} }
if (stbNum) { if (stbNum) {
printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName); printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
free(stb); free(stb);
stb = NULL; stb = NULL;
} else { } else {
...@@ -1131,7 +1134,7 @@ TEST(tableMeta, superTableCase) { ...@@ -1131,7 +1134,7 @@ TEST(tableMeta, superTableCase) {
if (stbNum) { if (stbNum) {
printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName); printf("got expired stb,suid:%" PRId64 ",dbFName:%s, stbName:%s\n", stb->suid, stb->dbFName, stb->stbName);
free(stb); free(stb);
stb = NULL; stb = NULL;
} else { } else {
...@@ -1215,7 +1218,7 @@ TEST(tableMeta, rmStbMeta) { ...@@ -1215,7 +1218,7 @@ TEST(tableMeta, rmStbMeta) {
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 0); ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), 0);
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1); ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), 1);
ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 0); ASSERT_EQ(ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 0);
catalogDestroy(); catalogDestroy();
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
} }
...@@ -1304,13 +1307,11 @@ TEST(tableMeta, updateStbMeta) { ...@@ -1304,13 +1307,11 @@ TEST(tableMeta, updateStbMeta) {
ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12);
tfree(tableMeta); tfree(tableMeta);
catalogDestroy(); catalogDestroy();
memset(&gCtgMgmt.stat, 0, sizeof(gCtgMgmt.stat)); memset(&gCtgMgmt.stat, 0, sizeof(gCtgMgmt.stat));
} }
TEST(tableDistVgroup, normalTable) { TEST(tableDistVgroup, normalTable) {
struct SCatalog *pCtg = NULL; struct SCatalog *pCtg = NULL;
void *mockPointer = (void *)0x1; void *mockPointer = (void *)0x1;
...@@ -1448,7 +1449,7 @@ TEST(dbVgroup, getSetDbVgroupCase) { ...@@ -1448,7 +1449,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
void *mockPointer = (void *)0x1; void *mockPointer = (void *)0x1;
SVgroupInfo vgInfo = {0}; SVgroupInfo vgInfo = {0};
SVgroupInfo *pvgInfo = NULL; SVgroupInfo *pvgInfo = NULL;
SDBVgInfo *dbVgroup = NULL; SDBVgInfo *dbVgroup = NULL;
SArray *vgList = NULL; SArray *vgList = NULL;
ctgTestInitLogFile(); ctgTestInitLogFile();
...@@ -1634,8 +1635,6 @@ TEST(multiThread, getSetRmDiffDbVgroup) { ...@@ -1634,8 +1635,6 @@ TEST(multiThread, getSetRmDiffDbVgroup) {
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
} }
TEST(multiThread, ctableMeta) { TEST(multiThread, ctableMeta) {
struct SCatalog *pCtg = NULL; struct SCatalog *pCtg = NULL;
void *mockPointer = (void *)0x1; void *mockPointer = (void *)0x1;
...@@ -1687,8 +1686,6 @@ TEST(multiThread, ctableMeta) { ...@@ -1687,8 +1686,6 @@ TEST(multiThread, ctableMeta) {
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
} }
TEST(rentTest, allRent) { TEST(rentTest, allRent) {
struct SCatalog *pCtg = NULL; struct SCatalog *pCtg = NULL;
void *mockPointer = (void *)0x1; void *mockPointer = (void *)0x1;
...@@ -1751,7 +1748,8 @@ TEST(rentTest, allRent) { ...@@ -1751,7 +1748,8 @@ TEST(rentTest, allRent) {
printf("%d - expired stableNum:%d\n", i, num); printf("%d - expired stableNum:%d\n", i, num);
if (stable) { if (stable) {
for (int32_t n = 0; n < num; ++n) { for (int32_t n = 0; n < num; ++n) {
printf("suid:%" PRId64 ", dbFName:%s, stbName:%s, sversion:%d, tversion:%d\n", stable[n].suid, stable[n].dbFName, stable[n].stbName, stable[n].sversion, stable[n].tversion); printf("suid:%" PRId64 ", dbFName:%s, stbName:%s, sversion:%d, tversion:%d\n", stable[n].suid,
stable[n].dbFName, stable[n].stbName, stable[n].sversion, stable[n].tversion);
} }
free(stable); free(stable);
stable = NULL; stable = NULL;
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_ASTTOMSG_H #ifndef TDENGINE_ASTTOMSG_H
#define TDENGINE_ASTTOMSG_H #define TDENGINE_ASTTOMSG_H
#include "parserInt.h" #include "parserInt.h"
#include "tmsg.h" #include "tmsg.h"
char* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); char* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen);
SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseContext* pParseCtx, SMsgBuf* pMsgBuf); char* buildShowMsg(SShowInfo* pShowInfo, int32_t* outputLen, SParseContext* pParseCtx, SMsgBuf* pMsgBuf);
SCreateDbReq* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseContext *pCtx, SMsgBuf* pMsgBuf); char* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, int32_t* outputLen, SParseContext* pCtx, SMsgBuf* pMsgBuf);
char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf); char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* outputLen, SParseContext* pParseCtx, SMsgBuf* pMsgBuf);
char* buildDropStableReq(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf); char* buildDropStableReq(SSqlInfo* pInfo, int32_t* outputLen, SParseContext* pParseCtx, SMsgBuf* pMsgBuf);
char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* outputLen, SMsgBuf* pMsgBuf);
char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* outputLen, SMsgBuf* pMsgBuf);
#endif // TDENGINE_ASTTOMSG_H #endif // TDENGINE_ASTTOMSG_H
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "astGenerator.h" #include "astGenerator.h"
#include "parserInt.h" #include "parserInt.h"
#include "parserUtil.h" #include "parserUtil.h"
...@@ -11,7 +26,7 @@ char* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, ...@@ -11,7 +26,7 @@ char* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id,
createReq.superUser = (int8_t)pUser->type; createReq.superUser = (int8_t)pUser->type;
if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) {
// pMsg->privilege = (char)pCmd->count; // pMsg->privilege = (char)pCmd->count;
} else { } else {
strncpy(createReq.pass, pUser->passwd.z, pUser->passwd.n); strncpy(createReq.pass, pUser->passwd.z, pUser->passwd.n);
} }
...@@ -39,14 +54,11 @@ char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, ...@@ -39,14 +54,11 @@ char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id,
SCreateAcctInfo* pAcctOpt = &pInfo->pMiscInfo->acctOpt; SCreateAcctInfo* pAcctOpt = &pInfo->pMiscInfo->acctOpt;
createReq.maxUsers = htonl(pAcctOpt->maxUsers); createReq.maxUsers = pAcctOpt->maxUsers;
createReq.maxDbs = htonl(pAcctOpt->maxDbs); createReq.maxDbs = pAcctOpt->maxDbs;
createReq.maxTimeSeries = htonl(pAcctOpt->maxTimeSeries); createReq.maxTimeSeries = pAcctOpt->maxTimeSeries;
createReq.maxStreams = htonl(pAcctOpt->maxStreams); createReq.maxStreams = pAcctOpt->maxStreams;
// createReq.maxPointsPerSecond = htonl(pAcctOpt->maxPointsPerSecond); createReq.maxStorage = pAcctOpt->maxStorage;
createReq.maxStorage = htobe64(pAcctOpt->maxStorage);
// createReq.maxQueryTime = htobe64(pAcctOpt->maxQueryTime);
// createReq.maxConnections = htonl(pAcctOpt->maxConnections);
if (pAcctOpt->stat.n == 0) { if (pAcctOpt->stat.n == 0) {
createReq.accessState = -1; createReq.accessState = -1;
...@@ -74,7 +86,7 @@ char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, ...@@ -74,7 +86,7 @@ char* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id,
return pReq; return pReq;
} }
char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* msgLen, int64_t id, char* msgBuf, int32_t msgBufLen) { char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgBufLen) {
SDropUserReq dropReq = {0}; SDropUserReq dropReq = {0};
SToken* pName = taosArrayGet(pInfo->pMiscInfo->a, 0); SToken* pName = taosArrayGet(pInfo->pMiscInfo->a, 0);
...@@ -92,30 +104,26 @@ char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* msgLen, int64_t id, char* msgBu ...@@ -92,30 +104,26 @@ char* buildDropUserMsg(SSqlInfo* pInfo, int32_t* msgLen, int64_t id, char* msgBu
} }
tSerializeSDropUserReq(pReq, tlen, &dropReq); tSerializeSDropUserReq(pReq, tlen, &dropReq);
*msgLen = tlen; *outputLen = tlen;
return pReq; return pReq;
} }
SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseContext* pCtx, SMsgBuf* pMsgBuf) { char* buildShowMsg(SShowInfo* pShowInfo, int32_t* outputLen, SParseContext* pCtx, SMsgBuf* pMsgBuf) {
SShowReq* pShowMsg = calloc(1, sizeof(SShowReq)); SShowReq showReq = {.type = pShowInfo->showType};
if (pShowMsg == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return pShowMsg;
}
pShowMsg->type = pShowInfo->showType;
if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) { if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) {
SToken* pPattern = &pShowInfo->pattern; SToken* pPattern = &pShowInfo->pattern;
if (pPattern->type > 0) { // only show tables support wildcard query if (pPattern->type > 0) { // only show tables support wildcard query
strncpy(pShowMsg->payload, pPattern->z, pPattern->n); showReq.payloadLen = pPattern->n;
pShowMsg->payloadLen = htons(pPattern->n); showReq.payload = malloc(showReq.payloadLen);
strncpy(showReq.payload, pPattern->z, pPattern->n);
} }
} else { } else {
SToken* pEpAddr = &pShowInfo->prefix; SToken* pEpAddr = &pShowInfo->prefix;
assert(pEpAddr->n > 0 && pEpAddr->type > 0); assert(pEpAddr->n > 0 && pEpAddr->type > 0);
showReq.payloadLen = pEpAddr->n;
strncpy(pShowMsg->payload, pEpAddr->z, pEpAddr->n); showReq.payload = malloc(showReq.payloadLen);
pShowMsg->payloadLen = htons(pEpAddr->n); strncpy(showReq.payload, pEpAddr->z, pEpAddr->n);
} }
if (pShowInfo->showType == TSDB_MGMT_TABLE_STB || pShowInfo->showType == TSDB_MGMT_TABLE_VGROUP) { if (pShowInfo->showType == TSDB_MGMT_TABLE_STB || pShowInfo->showType == TSDB_MGMT_TABLE_VGROUP) {
...@@ -124,22 +132,32 @@ SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseContext* pCtx, SMsgBuf* pMsgB ...@@ -124,22 +132,32 @@ SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseContext* pCtx, SMsgBuf* pMsgB
if (pShowInfo->prefix.n > 0) { if (pShowInfo->prefix.n > 0) {
if (pShowInfo->prefix.n >= TSDB_DB_FNAME_LEN) { if (pShowInfo->prefix.n >= TSDB_DB_FNAME_LEN) {
terrno = buildInvalidOperationMsg(pMsgBuf, "prefix name is too long"); terrno = buildInvalidOperationMsg(pMsgBuf, "prefix name is too long");
tfree(pShowMsg); tFreeSShowReq(&showReq);
return NULL; return NULL;
} }
tNameSetDbName(&n, pCtx->acctId, pShowInfo->prefix.z, pShowInfo->prefix.n); tNameSetDbName(&n, pCtx->acctId, pShowInfo->prefix.z, pShowInfo->prefix.n);
} else if (pCtx->db == NULL || strlen(pCtx->db) == 0) { } else if (pCtx->db == NULL || strlen(pCtx->db) == 0) {
terrno = buildInvalidOperationMsg(pMsgBuf, "database is not specified"); terrno = buildInvalidOperationMsg(pMsgBuf, "database is not specified");
tfree(pShowMsg); tFreeSShowReq(&showReq);
return NULL; return NULL;
} else { } else {
tNameSetDbName(&n, pCtx->acctId, pCtx->db, strlen(pCtx->db)); tNameSetDbName(&n, pCtx->acctId, pCtx->db, strlen(pCtx->db));
} }
tNameGetFullDbName(&n, pShowMsg->db); tNameGetFullDbName(&n, showReq.db);
}
int32_t tlen = tSerializeSShowReq(NULL, 0, &showReq);
void* pReq = malloc(tlen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
} }
return pShowMsg; tSerializeSShowReq(pReq, tlen, &showReq);
tFreeSShowReq(&showReq);
*outputLen = tlen;
return pReq;
} }
static int32_t setKeepOption(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDb, SMsgBuf* pMsgBuf) { static int32_t setKeepOption(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDb, SMsgBuf* pMsgBuf) {
...@@ -147,9 +165,9 @@ static int32_t setKeepOption(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDb, ...@@ -147,9 +165,9 @@ static int32_t setKeepOption(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDb,
const char* msg2 = "invalid keep value"; const char* msg2 = "invalid keep value";
const char* msg3 = "invalid keep value, should be keep0 <= keep1 <= keep2"; const char* msg3 = "invalid keep value, should be keep0 <= keep1 <= keep2";
pMsg->daysToKeep0 = htonl(-1); pMsg->daysToKeep0 = -1;
pMsg->daysToKeep1 = htonl(-1); pMsg->daysToKeep1 = -1;
pMsg->daysToKeep2 = htonl(-1); pMsg->daysToKeep2 = -1;
SArray* pKeep = pCreateDb->keep; SArray* pKeep = pCreateDb->keep;
if (pKeep != NULL) { if (pKeep != NULL) {
...@@ -209,13 +227,13 @@ static int32_t setTimePrecision(SCreateDbReq* pMsg, const SCreateDbInfo* pCreate ...@@ -209,13 +227,13 @@ static int32_t setTimePrecision(SCreateDbReq* pMsg, const SCreateDbInfo* pCreate
} }
static void doSetDbOptions(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDb) { static void doSetDbOptions(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDb) {
pMsg->cacheBlockSize = htonl(pCreateDb->cacheBlockSize); pMsg->cacheBlockSize = pCreateDb->cacheBlockSize;
pMsg->totalBlocks = htonl(pCreateDb->numOfBlocks); pMsg->totalBlocks = pCreateDb->numOfBlocks;
pMsg->daysPerFile = htonl(pCreateDb->daysPerFile); pMsg->daysPerFile = pCreateDb->daysPerFile;
pMsg->commitTime = htonl((int32_t)pCreateDb->commitTime); pMsg->commitTime = (int32_t)pCreateDb->commitTime;
pMsg->minRows = htonl(pCreateDb->minRowsPerBlock); pMsg->minRows = pCreateDb->minRowsPerBlock;
pMsg->maxRows = htonl(pCreateDb->maxRowsPerBlock); pMsg->maxRows = pCreateDb->maxRowsPerBlock;
pMsg->fsyncPeriod = htonl(pCreateDb->fsyncPeriod); pMsg->fsyncPeriod = pCreateDb->fsyncPeriod;
pMsg->compression = (int8_t)pCreateDb->compressionLevel; pMsg->compression = (int8_t)pCreateDb->compressionLevel;
pMsg->walLevel = (char)pCreateDb->walLevel; pMsg->walLevel = (char)pCreateDb->walLevel;
pMsg->replications = pCreateDb->replica; pMsg->replications = pCreateDb->replica;
...@@ -223,7 +241,7 @@ static void doSetDbOptions(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDb) { ...@@ -223,7 +241,7 @@ static void doSetDbOptions(SCreateDbReq* pMsg, const SCreateDbInfo* pCreateDb) {
pMsg->ignoreExist = pCreateDb->ignoreExists; pMsg->ignoreExist = pCreateDb->ignoreExists;
pMsg->update = pCreateDb->update; pMsg->update = pCreateDb->update;
pMsg->cacheLastRow = pCreateDb->cachelast; pMsg->cacheLastRow = pCreateDb->cachelast;
pMsg->numOfVgroups = htonl(pCreateDb->numOfVgroups); pMsg->numOfVgroups = pCreateDb->numOfVgroups;
} }
int32_t setDbOptions(SCreateDbReq* pCreateDbMsg, const SCreateDbInfo* pCreateDbSql, SMsgBuf* pMsgBuf) { int32_t setDbOptions(SCreateDbReq* pCreateDbMsg, const SCreateDbInfo* pCreateDbSql, SMsgBuf* pMsgBuf) {
...@@ -240,12 +258,104 @@ int32_t setDbOptions(SCreateDbReq* pCreateDbMsg, const SCreateDbInfo* pCreateDbS ...@@ -240,12 +258,104 @@ int32_t setDbOptions(SCreateDbReq* pCreateDbMsg, const SCreateDbInfo* pCreateDbS
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
SCreateDbReq* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseContext* pCtx, SMsgBuf* pMsgBuf) { // can only perform the parameters based on the macro definitation
SCreateDbReq* pCreateMsg = calloc(1, sizeof(SCreateDbReq)); static int32_t doCheckDbOptions(SCreateDbReq* pCreate, SMsgBuf* pMsgBuf) {
if (setDbOptions(pCreateMsg, pCreateDbInfo, pMsgBuf) != TSDB_CODE_SUCCESS) { char msg[512] = {0};
tfree(pCreateMsg);
terrno = TSDB_CODE_TSC_INVALID_OPERATION; if (pCreate->walLevel != -1 && (pCreate->walLevel < TSDB_MIN_WAL_LEVEL || pCreate->walLevel > TSDB_MAX_WAL_LEVEL)) {
snprintf(msg, tListLen(msg), "invalid db option walLevel: %d, only 1-2 allowed", pCreate->walLevel);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
if (pCreate->replications != -1 &&
(pCreate->replications < TSDB_MIN_DB_REPLICA_OPTION || pCreate->replications > TSDB_MAX_DB_REPLICA_OPTION)) {
snprintf(msg, tListLen(msg), "invalid db option replications: %d valid range: [%d, %d]", pCreate->replications,
TSDB_MIN_DB_REPLICA_OPTION, TSDB_MAX_DB_REPLICA_OPTION);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
int32_t blocks = pCreate->totalBlocks;
if (blocks != -1 && (blocks < TSDB_MIN_TOTAL_BLOCKS || blocks > TSDB_MAX_TOTAL_BLOCKS)) {
snprintf(msg, tListLen(msg), "invalid db option totalBlocks: %d valid range: [%d, %d]", blocks,
TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
if (pCreate->quorum != -1 &&
(pCreate->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCreate->quorum > TSDB_MAX_DB_QUORUM_OPTION)) {
snprintf(msg, tListLen(msg), "invalid db option quorum: %d valid range: [%d, %d]", pCreate->quorum,
TSDB_MIN_DB_QUORUM_OPTION, TSDB_MAX_DB_QUORUM_OPTION);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
int32_t val = pCreate->daysPerFile;
if (val != -1 && (val < TSDB_MIN_DAYS_PER_FILE || val > TSDB_MAX_DAYS_PER_FILE)) {
snprintf(msg, tListLen(msg), "invalid db option daysPerFile: %d valid range: [%d, %d]", val, TSDB_MIN_DAYS_PER_FILE,
TSDB_MAX_DAYS_PER_FILE);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
val = pCreate->cacheBlockSize;
if (val != -1 && (val < TSDB_MIN_CACHE_BLOCK_SIZE || val > TSDB_MAX_CACHE_BLOCK_SIZE)) {
snprintf(msg, tListLen(msg), "invalid db option cacheBlockSize: %d valid range: [%d, %d]", val,
TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO &&
pCreate->precision != TSDB_TIME_PRECISION_NANO) {
snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d, %d]", pCreate->precision,
TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO, TSDB_TIME_PRECISION_NANO);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
val = pCreate->commitTime;
if (val != -1 && (val < TSDB_MIN_COMMIT_TIME || val > TSDB_MAX_COMMIT_TIME)) {
snprintf(msg, tListLen(msg), "invalid db option commitTime: %d valid range: [%d, %d]", val, TSDB_MIN_COMMIT_TIME,
TSDB_MAX_COMMIT_TIME);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
val = pCreate->fsyncPeriod;
if (val != -1 && (val < TSDB_MIN_FSYNC_PERIOD || val > TSDB_MAX_FSYNC_PERIOD)) {
snprintf(msg, tListLen(msg), "invalid db option fsyncPeriod: %d valid range: [%d, %d]", val, TSDB_MIN_FSYNC_PERIOD,
TSDB_MAX_FSYNC_PERIOD);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
if (pCreate->compression != -1 &&
(pCreate->compression < TSDB_MIN_COMP_LEVEL || pCreate->compression > TSDB_MAX_COMP_LEVEL)) {
snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression,
TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
val = pCreate->numOfVgroups;
if (val < TSDB_MIN_VNODES_PER_DB || val > TSDB_MAX_VNODES_PER_DB) {
snprintf(msg, tListLen(msg), "invalid number of vgroups for DB:%d valid range: [%d, %d]", val,
TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB);
}
val = pCreate->maxRows;
if (val < TSDB_MIN_MAX_ROW_FBLOCK || val > TSDB_MAX_MAX_ROW_FBLOCK) {
snprintf(msg, tListLen(msg), "invalid number of max rows in file block for DB:%d valid range: [%d, %d]", val,
TSDB_MIN_MAX_ROW_FBLOCK, TSDB_MAX_MAX_ROW_FBLOCK);
}
val = pCreate->minRows;
if (val < TSDB_MIN_MIN_ROW_FBLOCK || val > TSDB_MAX_MIN_ROW_FBLOCK) {
snprintf(msg, tListLen(msg), "invalid number of min rows in file block for DB:%d valid range: [%d, %d]", val,
TSDB_MIN_MIN_ROW_FBLOCK, TSDB_MAX_MIN_ROW_FBLOCK);
}
return TSDB_CODE_SUCCESS;
}
char* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, int32_t* outputLen, SParseContext* pCtx, SMsgBuf* pMsgBuf) {
SCreateDbReq createReq = {0};
if (setDbOptions(&createReq, pCreateDbInfo, pMsgBuf) != TSDB_CODE_SUCCESS) {
terrno = TSDB_CODE_TSC_INVALID_OPERATION;
return NULL; return NULL;
} }
...@@ -256,11 +366,27 @@ SCreateDbReq* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseContext* pCtx ...@@ -256,11 +366,27 @@ SCreateDbReq* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseContext* pCtx
return NULL; return NULL;
} }
tNameGetFullDbName(&name, pCreateMsg->db); tNameGetFullDbName(&name, createReq.db);
return pCreateMsg;
if (doCheckDbOptions(&createReq, pMsgBuf) != TSDB_CODE_SUCCESS) {
terrno = TSDB_CODE_TSC_INVALID_OPERATION;
return NULL;
}
int32_t tlen = tSerializeSCreateDbReq(NULL, 0, &createReq);
void* pReq = malloc(tlen);
if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
tSerializeSCreateDbReq(pReq, tlen, &createReq);
*outputLen = tlen;
return pReq;
} }
char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf) { char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* outputLen, SParseContext* pParseCtx,
SMsgBuf* pMsgBuf) {
SMCreateStbReq createReq = {0}; SMCreateStbReq createReq = {0};
createReq.igExists = pCreateTableSql->existCheck ? 1 : 0; createReq.igExists = pCreateTableSql->existCheck ? 1 : 0;
createReq.pColumns = pCreateTableSql->colInfo.pColumns; createReq.pColumns = pCreateTableSql->colInfo.pColumns;
...@@ -287,11 +413,11 @@ char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* len, SParseCo ...@@ -287,11 +413,11 @@ char* buildCreateStbReq(SCreateTableSql* pCreateTableSql, int32_t* len, SParseCo
void* pBuf = pReq; void* pBuf = pReq;
tSerializeSMCreateStbReq(&pBuf, &createReq); tSerializeSMCreateStbReq(&pBuf, &createReq);
*len = tlen; *outputLen = tlen;
return pReq; return pReq;
} }
char* buildDropStableReq(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx, SMsgBuf* pMsgBuf) { char* buildDropStableReq(SSqlInfo* pInfo, int32_t* outputLen, SParseContext* pParseCtx, SMsgBuf* pMsgBuf) {
SToken* tableName = taosArrayGet(pInfo->pMiscInfo->a, 0); SToken* tableName = taosArrayGet(pInfo->pMiscInfo->a, 0);
SName name = {0}; SName name = {0};
...@@ -316,11 +442,11 @@ char* buildDropStableReq(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx ...@@ -316,11 +442,11 @@ char* buildDropStableReq(SSqlInfo* pInfo, int32_t* len, SParseContext* pParseCtx
void* pBuf = pReq; void* pBuf = pReq;
tSerializeSMDropStbReq(&pBuf, &dropReq); tSerializeSMDropStbReq(&pBuf, &dropReq);
*len = tlen; *outputLen = tlen;
return pReq; return pReq;
} }
char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) { char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* outputLen, SMsgBuf* pMsgBuf) {
const char* msg1 = "invalid host name (name too long, maximum length 128)"; const char* msg1 = "invalid host name (name too long, maximum length 128)";
const char* msg2 = "dnode name can not be string"; const char* msg2 = "dnode name can not be string";
const char* msg3 = "port should be an integer that is less than 65535 and greater than 0"; const char* msg3 = "port should be an integer that is less than 65535 and greater than 0";
...@@ -365,11 +491,11 @@ char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) { ...@@ -365,11 +491,11 @@ char* buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) {
} }
tSerializeSCreateDnodeReq(pReq, tlen, &createReq); tSerializeSCreateDnodeReq(pReq, tlen, &createReq);
*len = tlen; *outputLen = tlen;
return pReq; return pReq;
} }
char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) { char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* outputLen, SMsgBuf* pMsgBuf) {
SDropDnodeReq dropReq = {0}; SDropDnodeReq dropReq = {0};
SToken* pzName = taosArrayGet(pInfo->pMiscInfo->a, 0); SToken* pzName = taosArrayGet(pInfo->pMiscInfo->a, 0);
...@@ -390,6 +516,6 @@ char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) { ...@@ -390,6 +516,6 @@ char* buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf) {
} }
tSerializeSDropDnodeReq(pReq, tlen, &dropReq); tSerializeSDropDnodeReq(pReq, tlen, &dropReq);
*len = tlen; *outputLen = tlen;
return pReq; return pReq;
} }
\ No newline at end of file
...@@ -114,105 +114,10 @@ static int32_t setShowInfo(SShowInfo* pShowInfo, SParseContext* pCtx, void** out ...@@ -114,105 +114,10 @@ static int32_t setShowInfo(SShowInfo* pShowInfo, SParseContext* pCtx, void** out
} }
*pEpSet = pCtx->mgmtEpSet; *pEpSet = pCtx->mgmtEpSet;
*output = buildShowMsg(pShowInfo, pCtx, pMsgBuf); *output = buildShowMsg(pShowInfo, outputLen, pCtx, pMsgBuf);
if (*output == NULL) { if (*output == NULL) {
return terrno; return terrno;
} }
*outputLen = sizeof(SShowReq) /* + htons(pShowMsg->payloadLen)*/;
}
return TSDB_CODE_SUCCESS;
}
// can only perform the parameters based on the macro definitation
static int32_t doCheckDbOptions(SCreateDbReq* pCreate, SMsgBuf* pMsgBuf) {
char msg[512] = {0};
if (pCreate->walLevel != -1 && (pCreate->walLevel < TSDB_MIN_WAL_LEVEL || pCreate->walLevel > TSDB_MAX_WAL_LEVEL)) {
snprintf(msg, tListLen(msg), "invalid db option walLevel: %d, only 1-2 allowed", pCreate->walLevel);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
if (pCreate->replications != -1 &&
(pCreate->replications < TSDB_MIN_DB_REPLICA_OPTION || pCreate->replications > TSDB_MAX_DB_REPLICA_OPTION)) {
snprintf(msg, tListLen(msg), "invalid db option replications: %d valid range: [%d, %d]", pCreate->replications,
TSDB_MIN_DB_REPLICA_OPTION, TSDB_MAX_DB_REPLICA_OPTION);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
int32_t blocks = ntohl(pCreate->totalBlocks);
if (blocks != -1 && (blocks < TSDB_MIN_TOTAL_BLOCKS || blocks > TSDB_MAX_TOTAL_BLOCKS)) {
snprintf(msg, tListLen(msg), "invalid db option totalBlocks: %d valid range: [%d, %d]", blocks,
TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
if (pCreate->quorum != -1 &&
(pCreate->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCreate->quorum > TSDB_MAX_DB_QUORUM_OPTION)) {
snprintf(msg, tListLen(msg), "invalid db option quorum: %d valid range: [%d, %d]", pCreate->quorum,
TSDB_MIN_DB_QUORUM_OPTION, TSDB_MAX_DB_QUORUM_OPTION);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
int32_t val = htonl(pCreate->daysPerFile);
if (val != -1 && (val < TSDB_MIN_DAYS_PER_FILE || val > TSDB_MAX_DAYS_PER_FILE)) {
snprintf(msg, tListLen(msg), "invalid db option daysPerFile: %d valid range: [%d, %d]", val, TSDB_MIN_DAYS_PER_FILE,
TSDB_MAX_DAYS_PER_FILE);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
val = htonl(pCreate->cacheBlockSize);
if (val != -1 && (val < TSDB_MIN_CACHE_BLOCK_SIZE || val > TSDB_MAX_CACHE_BLOCK_SIZE)) {
snprintf(msg, tListLen(msg), "invalid db option cacheBlockSize: %d valid range: [%d, %d]", val,
TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO &&
pCreate->precision != TSDB_TIME_PRECISION_NANO) {
snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d, %d]", pCreate->precision,
TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO, TSDB_TIME_PRECISION_NANO);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
val = htonl(pCreate->commitTime);
if (val != -1 && (val < TSDB_MIN_COMMIT_TIME || val > TSDB_MAX_COMMIT_TIME)) {
snprintf(msg, tListLen(msg), "invalid db option commitTime: %d valid range: [%d, %d]", val, TSDB_MIN_COMMIT_TIME,
TSDB_MAX_COMMIT_TIME);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
val = htonl(pCreate->fsyncPeriod);
if (val != -1 && (val < TSDB_MIN_FSYNC_PERIOD || val > TSDB_MAX_FSYNC_PERIOD)) {
snprintf(msg, tListLen(msg), "invalid db option fsyncPeriod: %d valid range: [%d, %d]", val, TSDB_MIN_FSYNC_PERIOD,
TSDB_MAX_FSYNC_PERIOD);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
if (pCreate->compression != -1 &&
(pCreate->compression < TSDB_MIN_COMP_LEVEL || pCreate->compression > TSDB_MAX_COMP_LEVEL)) {
snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression,
TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
val = htonl(pCreate->numOfVgroups);
if (val < TSDB_MIN_VNODES_PER_DB || val > TSDB_MAX_VNODES_PER_DB) {
snprintf(msg, tListLen(msg), "invalid number of vgroups for DB:%d valid range: [%d, %d]", val,
TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB);
}
val = htonl(pCreate->maxRows);
if (val < TSDB_MIN_MAX_ROW_FBLOCK || val > TSDB_MAX_MAX_ROW_FBLOCK) {
snprintf(msg, tListLen(msg), "invalid number of max rows in file block for DB:%d valid range: [%d, %d]", val,
TSDB_MIN_MAX_ROW_FBLOCK, TSDB_MAX_MAX_ROW_FBLOCK);
}
val = htonl(pCreate->minRows);
if (val < TSDB_MIN_MIN_ROW_FBLOCK || val > TSDB_MAX_MIN_ROW_FBLOCK) {
snprintf(msg, tListLen(msg), "invalid number of min rows in file block for DB:%d valid range: [%d, %d]", val,
TSDB_MIN_MIN_ROW_FBLOCK, TSDB_MAX_MIN_ROW_FBLOCK);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -852,11 +757,15 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseContext* pCtx, ch ...@@ -852,11 +757,15 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseContext* pCtx, ch
goto _error; goto _error;
} }
SUseDbReq* pUseDbMsg = (SUseDbReq*)calloc(1, sizeof(SUseDbReq)); SUseDbReq usedbReq = {0};
tNameExtractFullName(&n, pUseDbMsg->db); tNameExtractFullName(&n, usedbReq.db);
pDcl->pMsg = (char*)pUseDbMsg; int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
pDcl->msgLen = sizeof(SUseDbReq); void* pBuf = malloc(bufLen);
tSerializeSUseDbReq(pBuf, bufLen, &usedbReq);
pDcl->pMsg = pBuf;
pDcl->msgLen = bufLen;
pDcl->msgType = TDMT_MND_USE_DB; pDcl->msgType = TDMT_MND_USE_DB;
break; break;
} }
...@@ -880,14 +789,11 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseContext* pCtx, ch ...@@ -880,14 +789,11 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseContext* pCtx, ch
goto _error; goto _error;
} }
SCreateDbReq* pCreateMsg = buildCreateDbMsg(pCreateDB, pCtx, pMsgBuf); int32_t bufLen = 0;
if (doCheckDbOptions(pCreateMsg, pMsgBuf) != TSDB_CODE_SUCCESS) { char* pBuf = buildCreateDbMsg(pCreateDB, &bufLen, pCtx, pMsgBuf);
code = TSDB_CODE_TSC_INVALID_OPERATION;
goto _error;
}
pDcl->pMsg = (char*)pCreateMsg; pDcl->pMsg = pBuf;
pDcl->msgLen = sizeof(SCreateDbReq); pDcl->msgLen = bufLen;
pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_DB) ? TDMT_MND_CREATE_DB : TDMT_MND_ALTER_DB; pDcl->msgType = (pInfo->type == TSDB_SQL_CREATE_DB) ? TDMT_MND_CREATE_DB : TDMT_MND_ALTER_DB;
break; break;
} }
...@@ -905,15 +811,18 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseContext* pCtx, ch ...@@ -905,15 +811,18 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseContext* pCtx, ch
goto _error; goto _error;
} }
SDropDbReq* pDropDbMsg = (SDropDbReq*)calloc(1, sizeof(SDropDbReq)); SDropDbReq dropdbReq = {0};
code = tNameExtractFullName(&name, dropdbReq.db);
code = tNameExtractFullName(&name, pDropDbMsg->db); dropdbReq.ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0;
pDropDbMsg->ignoreNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0;
assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_DB_NAME_T); assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_DB_NAME_T);
int32_t bufLen = tSerializeSDropDbReq(NULL, 0, &dropdbReq);
void* pBuf = malloc(bufLen);
tSerializeSDropDbReq(pBuf, bufLen, &dropdbReq);
pDcl->msgType = TDMT_MND_DROP_DB; pDcl->msgType = TDMT_MND_DROP_DB;
pDcl->msgLen = sizeof(SDropDbReq); pDcl->msgLen = bufLen;
pDcl->pMsg = (char*)pDropDbMsg; pDcl->pMsg = pBuf;
break; break;
} }
......
...@@ -55,106 +55,85 @@ int32_t queryBuildTableMetaReqMsg(void* input, char **msg, int32_t msgSize, int3 ...@@ -55,106 +55,85 @@ int32_t queryBuildTableMetaReqMsg(void* input, char **msg, int32_t msgSize, int3
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t queryBuildUseDbMsg(void* input, char **msg, int32_t msgSize, int32_t *msgLen) { int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen) {
if (NULL == input || NULL == msg || NULL == msgLen) { if (NULL == input || NULL == msg || NULL == msgLen) {
return TSDB_CODE_TSC_INVALID_INPUT; return TSDB_CODE_TSC_INVALID_INPUT;
} }
SBuildUseDBInput* bInput = (SBuildUseDBInput *)input; SBuildUseDBInput *bInput = input;
int32_t estimateSize = sizeof(SUseDbReq); SUseDbReq usedbReq = {0};
if (NULL == *msg || msgSize < estimateSize) { strncpy(usedbReq.db, bInput->db, sizeof(usedbReq.db));
tfree(*msg); usedbReq.db[sizeof(usedbReq.db) - 1] = 0;
*msg = rpcMallocCont(estimateSize); usedbReq.vgVersion = bInput->vgVersion;
if (NULL == *msg) {
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
}
SUseDbReq *bMsg = (SUseDbReq *)*msg;
strncpy(bMsg->db, bInput->db, sizeof(bMsg->db)); int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
bMsg->db[sizeof(bMsg->db) - 1] = 0; void *pBuf = rpcMallocCont(bufLen);
tSerializeSUseDbReq(pBuf, bufLen, &usedbReq);
bMsg->vgVersion = bInput->vgVersion; *msg = pBuf;
*msgLen = bufLen;
*msgLen = (int32_t)sizeof(*bMsg);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) {
int32_t queryProcessUseDBRsp(void* output, char *msg, int32_t msgSize) {
if (NULL == output || NULL == msg || msgSize <= 0) { if (NULL == output || NULL == msg || msgSize <= 0) {
return TSDB_CODE_TSC_INVALID_INPUT; return TSDB_CODE_TSC_INVALID_INPUT;
} }
SUseDbRsp *pRsp = (SUseDbRsp *)msg;
SUseDbOutput *pOut = (SUseDbOutput *)output; SUseDbOutput *pOut = (SUseDbOutput *)output;
int32_t code = 0; int32_t code = 0;
if (msgSize <= sizeof(*pRsp)) { SUseDbRsp usedbRsp = {0};
qError("invalid use db rsp msg size, msgSize:%d", msgSize); if (tDeserializeSUseDbRsp(msg, msgSize, &usedbRsp) != 0) {
return TSDB_CODE_TSC_VALUE_OUT_OF_RANGE; qError("invalid use db rsp msg, msgSize:%d", msgSize);
return TSDB_CODE_INVALID_MSG;
} }
pRsp->vgVersion = ntohl(pRsp->vgVersion);
pRsp->vgNum = ntohl(pRsp->vgNum);
pRsp->uid = be64toh(pRsp->uid);
if (pRsp->vgNum < 0) { if (usedbRsp.vgNum < 0) {
qError("invalid db[%s] vgroup number[%d]", pRsp->db, pRsp->vgNum); qError("invalid db[%s] vgroup number[%d]", usedbRsp.db, usedbRsp.vgNum);
return TSDB_CODE_TSC_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
int32_t expectSize = pRsp->vgNum * sizeof(pRsp->vgroupInfo[0]) + sizeof(*pRsp);
if (msgSize != expectSize) {
qError("use db rsp size mis-match, msgSize:%d, expected:%d, vgnumber:%d", msgSize, expectSize, pRsp->vgNum);
return TSDB_CODE_TSC_VALUE_OUT_OF_RANGE;
}
pOut->dbVgroup = calloc(1, sizeof(SDBVgInfo)); pOut->dbVgroup = calloc(1, sizeof(SDBVgInfo));
if (NULL == pOut->dbVgroup) { if (NULL == pOut->dbVgroup) {
qError("calloc %d failed", (int32_t)sizeof(SDBVgInfo)); qError("calloc %d failed", (int32_t)sizeof(SDBVgInfo));
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
pOut->dbId = pRsp->uid; pOut->dbId = usedbRsp.uid;
pOut->dbVgroup->vgVersion = pRsp->vgVersion; pOut->dbVgroup->vgVersion = usedbRsp.vgVersion;
pOut->dbVgroup->hashMethod = pRsp->hashMethod; pOut->dbVgroup->hashMethod = usedbRsp.hashMethod;
pOut->dbVgroup->vgHash = taosHashInit(pRsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); pOut->dbVgroup->vgHash =
taosHashInit(usedbRsp.vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
if (NULL == pOut->dbVgroup->vgHash) { if (NULL == pOut->dbVgroup->vgHash) {
qError("taosHashInit %d failed", pRsp->vgNum); qError("taosHashInit %d failed", usedbRsp.vgNum);
tfree(pOut->dbVgroup); tfree(pOut->dbVgroup);
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
for (int32_t i = 0; i < pRsp->vgNum; ++i) { for (int32_t i = 0; i < usedbRsp.vgNum; ++i) {
pRsp->vgroupInfo[i].vgId = ntohl(pRsp->vgroupInfo[i].vgId); SVgroupInfo *pVgInfo = taosArrayGet(usedbRsp.pVgroupInfos, i);
pRsp->vgroupInfo[i].hashBegin = ntohl(pRsp->vgroupInfo[i].hashBegin);
pRsp->vgroupInfo[i].hashEnd = ntohl(pRsp->vgroupInfo[i].hashEnd);
for (int32_t n = 0; n < pRsp->vgroupInfo[i].epset.numOfEps; ++n) { if (0 != taosHashPut(pOut->dbVgroup->vgHash, &pVgInfo->vgId, sizeof(int32_t), pVgInfo, sizeof(SVgroupInfo))) {
pRsp->vgroupInfo[i].epset.eps[n].port = ntohs(pRsp->vgroupInfo[i].epset.eps[n].port);
}
if (0 != taosHashPut(pOut->dbVgroup->vgHash, &pRsp->vgroupInfo[i].vgId, sizeof(pRsp->vgroupInfo[i].vgId), &pRsp->vgroupInfo[i], sizeof(pRsp->vgroupInfo[i]))) {
qError("taosHashPut failed"); qError("taosHashPut failed");
goto _return; goto _return;
} }
} }
memcpy(pOut->db, pRsp->db, sizeof(pOut->db)); memcpy(pOut->db, usedbRsp.db, TSDB_DB_FNAME_LEN);
return code; return code;
_return: _return:
tFreeSUsedbRsp(&usedbRsp);
if (pOut) { if (pOut) {
taosHashCleanup(pOut->dbVgroup->vgHash); taosHashCleanup(pOut->dbVgroup->vgHash);
tfree(pOut->dbVgroup); tfree(pOut->dbVgroup);
} }
return code; return code;
} }
......
...@@ -77,7 +77,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PTR, "Invalid pointer") ...@@ -77,7 +77,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PTR, "Invalid pointer")
TAOS_DEFINE_ERROR(TSDB_CODE_MEMORY_CORRUPTED, "Memory corrupted") TAOS_DEFINE_ERROR(TSDB_CODE_MEMORY_CORRUPTED, "Memory corrupted")
TAOS_DEFINE_ERROR(TSDB_CODE_FILE_CORRUPTED, "Data file corrupted") TAOS_DEFINE_ERROR(TSDB_CODE_FILE_CORRUPTED, "Data file corrupted")
TAOS_DEFINE_ERROR(TSDB_CODE_CHECKSUM_ERROR, "Checksum error") TAOS_DEFINE_ERROR(TSDB_CODE_CHECKSUM_ERROR, "Checksum error")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG, "Invalid config message") TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_MSG, "Invalid message")
TAOS_DEFINE_ERROR(TSDB_CODE_MSG_NOT_PROCESSED, "Message not processed") TAOS_DEFINE_ERROR(TSDB_CODE_MSG_NOT_PROCESSED, "Message not processed")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PARA, "Invalid parameters") TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PARA, "Invalid parameters")
TAOS_DEFINE_ERROR(TSDB_CODE_REPEAT_INIT, "Repeat initialization") TAOS_DEFINE_ERROR(TSDB_CODE_REPEAT_INIT, "Repeat initialization")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册