提交 22ae82ac 编写于 作者: L Liu Jicong

merge from 3.0

...@@ -82,6 +82,7 @@ enum { ...@@ -82,6 +82,7 @@ enum {
HEARTBEAT_KEY_MQ_TMP, HEARTBEAT_KEY_MQ_TMP,
}; };
typedef enum _mgmt_table { typedef enum _mgmt_table {
TSDB_MGMT_TABLE_START, TSDB_MGMT_TABLE_START,
TSDB_MGMT_TABLE_ACCT, TSDB_MGMT_TABLE_ACCT,
...@@ -274,6 +275,7 @@ typedef struct { ...@@ -274,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];
...@@ -393,8 +395,8 @@ typedef struct { ...@@ -393,8 +395,8 @@ typedef struct {
SHashObj* writeDbs; SHashObj* writeDbs;
} SGetUserAuthRsp; } SGetUserAuthRsp;
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pReq); int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pReq); int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
typedef struct { typedef struct {
int16_t colId; // column id int16_t colId; // column id
...@@ -524,28 +526,6 @@ typedef struct { ...@@ -524,28 +526,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;
...@@ -569,6 +549,9 @@ typedef struct { ...@@ -569,6 +549,9 @@ typedef struct {
int8_t ignoreExist; int8_t ignoreExist;
} SCreateDbReq; } SCreateDbReq;
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
int32_t tDeserializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
typedef struct { typedef struct {
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
int32_t totalBlocks; int32_t totalBlocks;
...@@ -581,28 +564,60 @@ typedef struct { ...@@ -581,28 +564,60 @@ typedef struct {
int8_t cacheLastRow; int8_t cacheLastRow;
} SAlterDbReq; } SAlterDbReq;
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
typedef struct { typedef struct {
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
int8_t ignoreNotExists; int8_t ignoreNotExists;
} SDropDbReq; } SDropDbReq;
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
int32_t tDeserializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
typedef struct { typedef struct {
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
uint64_t uid; uint64_t uid;
} SDropDbRsp; } SDropDbRsp;
int32_t tSerializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
int32_t tDeserializeSDropDbRsp(void* buf, int32_t bufLen, SDropDbRsp* pRsp);
typedef struct { typedef struct {
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
int32_t vgVersion; int32_t vgVersion;
} SUseDbReq; } SUseDbReq;
int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
int32_t tDeserializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq);
typedef struct { typedef struct {
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
} SSyncDbReq; 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];
} SCompactDbReq; } SSyncDbReq, SCompactDbReq;
int32_t tSerializeSSyncDbReq(void* buf, int32_t bufLen, SSyncDbReq* pReq);
int32_t tDeserializeSSyncDbReq(void* buf, int32_t bufLen, SSyncDbReq* pReq);
typedef struct { typedef struct {
char name[TSDB_FUNC_NAME_LEN]; char name[TSDB_FUNC_NAME_LEN];
...@@ -615,22 +630,31 @@ typedef struct { ...@@ -615,22 +630,31 @@ typedef struct {
int64_t signature; int64_t signature;
int32_t commentSize; int32_t commentSize;
int32_t codeSize; int32_t codeSize;
char pCont[]; char pComment[TSDB_FUNC_COMMENT_LEN];
char pCode[TSDB_FUNC_CODE_LEN];
} SCreateFuncReq; } SCreateFuncReq;
int32_t tSerializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
int32_t tDeserializeSCreateFuncReq(void* buf, int32_t bufLen, SCreateFuncReq* pReq);
typedef struct { typedef struct {
char name[TSDB_FUNC_NAME_LEN]; char name[TSDB_FUNC_NAME_LEN];
int8_t igNotExists; int8_t igNotExists;
} SDropFuncReq; } SDropFuncReq;
int32_t tSerializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
int32_t tDeserializeSDropFuncReq(void* buf, int32_t bufLen, SDropFuncReq* pReq);
typedef struct { typedef struct {
int32_t numOfFuncs; int32_t numOfFuncs;
char pFuncNames[]; SArray* pFuncNames;
} SRetrieveFuncReq; } SRetrieveFuncReq;
int32_t tSerializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
int32_t tDeserializeSRetrieveFuncReq(void* buf, int32_t bufLen, SRetrieveFuncReq* pReq);
typedef struct { typedef struct {
char name[TSDB_FUNC_NAME_LEN]; char name[TSDB_FUNC_NAME_LEN];
int8_t align;
int8_t funcType; int8_t funcType;
int8_t scriptType; int8_t scriptType;
int8_t outputType; int8_t outputType;
...@@ -639,14 +663,18 @@ typedef struct { ...@@ -639,14 +663,18 @@ typedef struct {
int64_t signature; int64_t signature;
int32_t commentSize; int32_t commentSize;
int32_t codeSize; int32_t codeSize;
char pCont[]; char pComment[TSDB_FUNC_COMMENT_LEN];
char pCode[TSDB_FUNC_CODE_LEN];
} SFuncInfo; } SFuncInfo;
typedef struct { typedef struct {
int32_t numOfFuncs; int32_t numOfFuncs;
char pFuncInfos[]; SArray* pFuncInfos;
} SRetrieveFuncRsp; } SRetrieveFuncRsp;
int32_t tSerializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
int32_t tDeserializeSRetrieveFuncRsp(void* buf, int32_t bufLen, SRetrieveFuncRsp* pRsp);
typedef struct { typedef struct {
int32_t statusInterval; int32_t statusInterval;
int64_t checkTime; // 1970-01-01 00:00:00.000 int64_t checkTime; // 1970-01-01 00:00:00.000
...@@ -813,27 +841,22 @@ typedef struct { ...@@ -813,27 +841,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;
...@@ -845,6 +868,26 @@ typedef struct { ...@@ -845,6 +868,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;
...@@ -1509,19 +1552,11 @@ typedef struct { ...@@ -1509,19 +1552,11 @@ typedef struct {
static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) { return taosIntHash_64(key, keyLen); } static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t 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);
} }
} }
...@@ -1530,13 +1565,12 @@ static FORCE_INLINE void tFreeClientHbReq(void* pReq) { ...@@ -1530,13 +1565,12 @@ 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;
...@@ -1560,40 +1594,41 @@ static FORCE_INLINE void tFreeClientHbRsp(void* pRsp) { ...@@ -1560,40 +1594,41 @@ static FORCE_INLINE void tFreeClientHbRsp(void* 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);
} }
int tSerializeSClientHbBatchRsp(void** buf, const SClientHbBatchRsp* pBatchRsp); int32_t tSerializeSClientHbBatchRsp(void* buf, int32_t bufLen, const SClientHbBatchRsp* pBatchRsp);
void* tDeserializeSClientHbBatchRsp(void* buf, SClientHbBatchRsp* pBatchRsp); int32_t tDeserializeSClientHbBatchRsp(void* buf, int32_t bufLen, SClientHbBatchRsp* pBatchRsp);
static FORCE_INLINE int taosEncodeSKv(void** buf, const SKv* pKv) { static FORCE_INLINE int32_t tEncodeSKv(SCoder* pEncoder, const SKv* pKv) {
int tlen = 0; if (tEncodeI32(pEncoder, pKv->key) < 0) return -1;
tlen += taosEncodeFixedI32(buf, pKv->key); if (tEncodeI32(pEncoder, pKv->valueLen) < 0) return -1;
tlen += taosEncodeFixedI32(buf, pKv->valueLen); if (tEncodeCStrWithLen(pEncoder, (const char*)pKv->value, pKv->valueLen) < 0) return -1;
tlen += taosEncodeBinary(buf, pKv->value, pKv->valueLen); return 0;
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 {
......
...@@ -30,7 +30,7 @@ extern "C" { ...@@ -30,7 +30,7 @@ extern "C" {
#include "tmsg.h" #include "tmsg.h"
#include "transport.h" #include "transport.h"
struct SCatalog; typedef struct SCatalog SCatalog;
enum { enum {
CTG_DBG_DB_NUM = 1, CTG_DBG_DB_NUM = 1,
...@@ -64,6 +64,7 @@ typedef struct SCatalogCfg { ...@@ -64,6 +64,7 @@ typedef struct SCatalogCfg {
typedef struct SSTableMetaVersion { typedef struct SSTableMetaVersion {
char dbFName[TSDB_DB_FNAME_LEN]; char dbFName[TSDB_DB_FNAME_LEN];
char stbName[TSDB_TABLE_NAME_LEN]; char stbName[TSDB_TABLE_NAME_LEN];
uint64_t dbId;
uint64_t suid; uint64_t suid;
int16_t sversion; int16_t sversion;
int16_t tversion; int16_t tversion;
...@@ -84,7 +85,7 @@ int32_t catalogInit(SCatalogCfg *cfg); ...@@ -84,7 +85,7 @@ int32_t catalogInit(SCatalogCfg *cfg);
* @param catalogHandle (output, NO need to free it) * @param catalogHandle (output, NO need to free it)
* @return error code * @return error code
*/ */
int32_t catalogGetHandle(uint64_t clusterId, struct SCatalog** catalogHandle); int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle);
/** /**
* Free a cluster's all catalog info, usually it's not necessary, until the application is closing. * Free a cluster's all catalog info, usually it's not necessary, until the application is closing.
...@@ -92,9 +93,9 @@ int32_t catalogGetHandle(uint64_t clusterId, struct SCatalog** catalogHandle); ...@@ -92,9 +93,9 @@ int32_t catalogGetHandle(uint64_t clusterId, struct SCatalog** catalogHandle);
* @param pCatalog (input, NO more usage) * @param pCatalog (input, NO more usage)
* @return error code * @return error code
*/ */
void catalogFreeHandle(struct SCatalog* pCatalog); void catalogFreeHandle(SCatalog* pCatalog);
int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName, int32_t* version); int32_t catalogGetDBVgVersion(SCatalog* pCatalog, const char* dbName, int32_t* version);
/** /**
* Get a DB's all vgroup info. * Get a DB's all vgroup info.
...@@ -106,13 +107,13 @@ int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName, ...@@ -106,13 +107,13 @@ int32_t catalogGetDBVgroupVersion(struct SCatalog* pCatalog, const char* dbName,
* @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller) * @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
* @return error code * @return error code
*/ */
int32_t catalogGetDBVgroup(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const char* pDBName, bool forceUpdate, SArray** pVgroupList); int32_t catalogGetDBVgInfo(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const char* pDBName, bool forceUpdate, SArray** pVgroupList);
int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, uint64_t dbId, SDBVgroupInfo* dbInfo); int32_t catalogUpdateDBVgInfo(SCatalog* pCatalog, const char* dbName, uint64_t dbId, SDBVgInfo* dbInfo);
int32_t catalogRemoveDB(struct SCatalog* pCatalog, const char* dbName, uint64_t dbId); int32_t catalogRemoveDB(SCatalog* pCatalog, const char* dbName, uint64_t dbId);
int32_t catalogRemoveSTableMeta(struct SCatalog* pCatalog, const char* dbName, const char* stbName, uint64_t suid); int32_t catalogRemoveStbMeta(SCatalog* pCtg, const char* dbFName, uint64_t dbId, const char* stbName, uint64_t suid);
/** /**
* Get a table's meta data. * Get a table's meta data.
...@@ -123,7 +124,7 @@ int32_t catalogRemoveSTableMeta(struct SCatalog* pCatalog, const char* dbName, c ...@@ -123,7 +124,7 @@ int32_t catalogRemoveSTableMeta(struct SCatalog* pCatalog, const char* dbName, c
* @param pTableMeta(output, table meta data, NEED to free it by calller) * @param pTableMeta(output, table meta data, NEED to free it by calller)
* @return error code * @return error code
*/ */
int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); int32_t catalogGetTableMeta(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
/** /**
* Get a super table's meta data. * Get a super table's meta data.
...@@ -134,13 +135,13 @@ int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, cons ...@@ -134,13 +135,13 @@ int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, cons
* @param pTableMeta(output, table meta data, NEED to free it by calller) * @param pTableMeta(output, table meta data, NEED to free it by calller)
* @return error code * @return error code
*/ */
int32_t catalogGetSTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); int32_t catalogGetSTableMeta(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
int32_t catalogUpdateSTableMeta(struct SCatalog* pCatalog, STableMetaRsp *rspMsg); int32_t catalogUpdateSTableMeta(SCatalog* pCatalog, STableMetaRsp *rspMsg);
/** /**
* Force renew a table's local cached meta data. * Force refresh a table's local cached meta data.
* @param pCatalog (input, got with catalogGetHandle) * @param pCatalog (input, got with catalogGetHandle)
* @param pTransporter (input, rpc object) * @param pTransporter (input, rpc object)
* @param pMgmtEps (input, mnode EPs) * @param pMgmtEps (input, mnode EPs)
...@@ -148,10 +149,10 @@ int32_t catalogUpdateSTableMeta(struct SCatalog* pCatalog, STableMetaRsp *rspMsg ...@@ -148,10 +149,10 @@ int32_t catalogUpdateSTableMeta(struct SCatalog* pCatalog, STableMetaRsp *rspMsg
* @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure) * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure)
* @return error code * @return error code
*/ */
int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable); int32_t catalogRefreshTableMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable);
/** /**
* Force renew a table's local cached meta data and get the new one. * Force refresh a table's local cached meta data and get the new one.
* @param pCatalog (input, got with catalogGetHandle) * @param pCatalog (input, got with catalogGetHandle)
* @param pTransporter (input, rpc object) * @param pTransporter (input, rpc object)
* @param pMgmtEps (input, mnode EPs) * @param pMgmtEps (input, mnode EPs)
...@@ -160,7 +161,7 @@ int32_t catalogUpdateSTableMeta(struct SCatalog* pCatalog, STableMetaRsp *rspMsg ...@@ -160,7 +161,7 @@ int32_t catalogUpdateSTableMeta(struct SCatalog* pCatalog, STableMetaRsp *rspMsg
* @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure) * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure)
* @return error code * @return error code
*/ */
int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable); int32_t catalogRefreshGetTableMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable);
...@@ -173,7 +174,7 @@ int32_t catalogUpdateSTableMeta(struct SCatalog* pCatalog, STableMetaRsp *rspMsg ...@@ -173,7 +174,7 @@ int32_t catalogUpdateSTableMeta(struct SCatalog* pCatalog, STableMetaRsp *rspMsg
* @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller) * @param pVgroupList (output, vgroup info list, element is SVgroupInfo, NEED to simply free the array by caller)
* @return error code * @return error code
*/ */
int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList); int32_t catalogGetTableDistVgInfo(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList);
/** /**
* Get a table's vgroup from its name's hash value. * Get a table's vgroup from its name's hash value.
...@@ -184,7 +185,7 @@ int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pTransporter, ...@@ -184,7 +185,7 @@ int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pTransporter,
* @param vgInfo (output, vgroup info) * @param vgInfo (output, vgroup info)
* @return error code * @return error code
*/ */
int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pName, SVgroupInfo* vgInfo); int32_t catalogGetTableHashVgroup(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pName, SVgroupInfo* vgInfo);
/** /**
...@@ -196,14 +197,14 @@ int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void * pTransporter ...@@ -196,14 +197,14 @@ int32_t catalogGetTableHashVgroup(struct SCatalog* pCatalog, void * pTransporter
* @param pRsp (output, response data) * @param pRsp (output, response data)
* @return error code * @return error code
*/ */
int32_t catalogGetAllMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp); int32_t catalogGetAllMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
int32_t catalogGetQnodeList(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, SArray* pQnodeList); int32_t catalogGetQnodeList(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, SArray* pQnodeList);
int32_t catalogGetExpiredSTables(struct SCatalog* pCatalog, SSTableMetaVersion **stables, uint32_t *num); int32_t catalogGetExpiredSTables(SCatalog* pCatalog, SSTableMetaVersion **stables, uint32_t *num);
int32_t catalogGetExpiredDBs(struct SCatalog* pCatalog, SDbVgVersion **dbs, uint32_t *num); int32_t catalogGetExpiredDBs(SCatalog* pCatalog, SDbVgVersion **dbs, uint32_t *num);
/** /**
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include "nodes.h" #include "querynodes.h"
typedef enum EFunctionType { typedef enum EFunctionType {
// aggregate function // aggregate function
......
/*
* 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 _TD_NODES_H_
#define _TD_NODES_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "tdef.h"
#define nodeType(nodeptr) (((const SNode*)(nodeptr))->type)
#define setNodeType(nodeptr, type) (((SNode*)(nodeptr))->type = (type))
#define LIST_LENGTH(l) (NULL != (l) ? (l)->length : 0)
#define FOREACH(node, list) \
for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = cell->pNode, true) : (node = NULL, false)); cell = cell->pNext)
// only be use in FOREACH
#define ERASE_NODE(list) cell = nodesListErase(list, cell);
#define REPLACE_NODE(newNode) cell->pNode = (SNode*)(newNode)
#define FORBOTH(node1, list1, node2, list2) \
for (SListCell* cell1 = (NULL != (list1) ? (list1)->pHead : NULL), *cell2 = (NULL != (list2) ? (list2)->pHead : NULL); \
(NULL == cell1 ? (node1 = NULL, false) : (node1 = cell1->pNode, true)), (NULL == cell2 ? (node2 = NULL, false) : (node2 = cell2->pNode, true)), (node1 != NULL && node2 != NULL); \
cell1 = cell1->pNext, cell2 = cell2->pNext)
#define FOREACH_FOR_REWRITE(node, list) \
for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = &(cell->pNode), true) : (node = NULL, false)); cell = cell->pNext)
typedef enum ENodeType {
// Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN, VALUE, OPERATOR, FUNCTION and so on.
QUERY_NODE_COLUMN = 1,
QUERY_NODE_VALUE,
QUERY_NODE_OPERATOR,
QUERY_NODE_LOGIC_CONDITION,
QUERY_NODE_IS_NULL_CONDITION,
QUERY_NODE_FUNCTION,
QUERY_NODE_REAL_TABLE,
QUERY_NODE_TEMP_TABLE,
QUERY_NODE_JOIN_TABLE,
QUERY_NODE_GROUPING_SET,
QUERY_NODE_ORDER_BY_EXPR,
QUERY_NODE_LIMIT,
QUERY_NODE_STATE_WINDOW,
QUERY_NODE_SESSION_WINDOW,
QUERY_NODE_INTERVAL_WINDOW,
QUERY_NODE_NODE_LIST,
QUERY_NODE_FILL,
// Only be used in parser module.
QUERY_NODE_RAW_EXPR,
// Statement nodes are used in parser and planner module.
QUERY_NODE_SET_OPERATOR,
QUERY_NODE_SELECT_STMT,
QUERY_NODE_SHOW_STMT
} ENodeType;
/**
* The first field of a node of any type is guaranteed to be the ENodeType.
* Hence the type of any node can be gotten by casting it to SNode.
*/
typedef struct SNode {
ENodeType type;
} SNode;
typedef struct SListCell {
struct SListCell* pPrev;
struct SListCell* pNext;
SNode* pNode;
} SListCell;
typedef struct SNodeList {
int16_t length;
SListCell* pHead;
SListCell* pTail;
} SNodeList;
SNode* nodesMakeNode(ENodeType type);
void nodesDestroyNode(SNode* pNode);
SNodeList* nodesMakeList();
SNodeList* nodesListAppend(SNodeList* pList, SNode* pNode);
SListCell* nodesListErase(SNodeList* pList, SListCell* pCell);
SNode* nodesListGetNode(SNodeList* pList, int32_t index);
void nodesDestroyList(SNodeList* pList);
typedef enum EDealRes {
DEAL_RES_CONTINUE = 1,
DEAL_RES_IGNORE_CHILD,
DEAL_RES_ERROR,
} EDealRes;
typedef EDealRes (*FNodeWalker)(SNode* pNode, void* pContext);
void nodesWalkNode(SNode* pNode, FNodeWalker walker, void* pContext);
void nodesWalkList(SNodeList* pList, FNodeWalker walker, void* pContext);
void nodesWalkNodePostOrder(SNode* pNode, FNodeWalker walker, void* pContext);
void nodesWalkListPostOrder(SNodeList* pList, FNodeWalker walker, void* pContext);
typedef EDealRes (*FNodeRewriter)(SNode** pNode, void* pContext);
void nodesRewriteNode(SNode** pNode, FNodeRewriter rewriter, void* pContext);
void nodesRewriteList(SNodeList* pList, FNodeRewriter rewriter, void* pContext);
void nodesRewriteNodePostOrder(SNode** pNode, FNodeRewriter rewriter, void* pContext);
void nodesRewriteListPostOrder(SNodeList* pList, FNodeRewriter rewriter, void* pContext);
bool nodesEqualNode(const SNode* a, const SNode* b);
void nodesCloneNode(const SNode* pNode);
int32_t nodesNodeToString(const SNode* pNode, char** pStr, int32_t* pLen);
int32_t nodesStringToNode(const char* pStr, SNode** pNode);
#ifdef __cplusplus
}
#endif
#endif /*_TD_NODES_H_*/
...@@ -13,79 +13,14 @@ ...@@ -13,79 +13,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_NODES_H_ #ifndef _TD_QUERY_NODES_H_
#define _TD_NODES_H_ #define _TD_QUERY_NODES_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "tdef.h" #include "nodes.h"
#define nodeType(nodeptr) (((const SNode*)(nodeptr))->type)
#define setNodeType(nodeptr, type) (((SNode*)(nodeptr))->type = (type))
#define LIST_LENGTH(l) (NULL != (l) ? (l)->length : 0)
#define FOREACH(node, list) \
for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = cell->pNode, true) : (node = NULL, false)); cell = cell->pNext)
// only be use in FOREACH
#define ERASE_NODE(list) cell = nodesListErase(list, cell);
#define REPLACE_NODE(newNode) cell->pNode = (SNode*)(newNode)
#define FORBOTH(node1, list1, node2, list2) \
for (SListCell* cell1 = (NULL != (list1) ? (list1)->pHead : NULL), *cell2 = (NULL != (list2) ? (list2)->pHead : NULL); \
(NULL == cell1 ? (node1 = NULL, false) : (node1 = cell1->pNode, true)), (NULL == cell2 ? (node2 = NULL, false) : (node2 = cell2->pNode, true)), (node1 != NULL && node2 != NULL); \
cell1 = cell1->pNext, cell2 = cell2->pNext)
typedef enum ENodeType {
QUERY_NODE_COLUMN = 1,
QUERY_NODE_VALUE,
QUERY_NODE_OPERATOR,
QUERY_NODE_LOGIC_CONDITION,
QUERY_NODE_IS_NULL_CONDITION,
QUERY_NODE_FUNCTION,
QUERY_NODE_REAL_TABLE,
QUERY_NODE_TEMP_TABLE,
QUERY_NODE_JOIN_TABLE,
QUERY_NODE_GROUPING_SET,
QUERY_NODE_ORDER_BY_EXPR,
QUERY_NODE_LIMIT,
QUERY_NODE_STATE_WINDOW,
QUERY_NODE_SESSION_WINDOW,
QUERY_NODE_INTERVAL_WINDOW,
QUERY_NODE_NODE_LIST,
QUERY_NODE_FILL,
// only for parser
QUERY_NODE_RAW_EXPR,
QUERY_NODE_SET_OPERATOR,
QUERY_NODE_SELECT_STMT,
QUERY_NODE_SHOW_STMT
} ENodeType;
/**
* The first field of a node of any type is guaranteed to be the ENodeType.
* Hence the type of any node can be gotten by casting it to SNode.
*/
typedef struct SNode {
ENodeType type;
} SNode;
typedef struct SListCell {
struct SListCell* pPrev;
struct SListCell* pNext;
SNode* pNode;
} SListCell;
typedef struct SNodeList {
int16_t length;
SListCell* pHead;
SListCell* pTail;
} SNodeList;
typedef struct SRawExprNode { typedef struct SRawExprNode {
ENodeType nodeType; ENodeType nodeType;
...@@ -329,34 +264,6 @@ typedef struct SSetOperator { ...@@ -329,34 +264,6 @@ typedef struct SSetOperator {
SNode* pLimit; SNode* pLimit;
} SSetOperator; } SSetOperator;
SNode* nodesMakeNode(ENodeType type);
void nodesDestroyNode(SNode* pNode);
SNodeList* nodesMakeList();
SNodeList* nodesListAppend(SNodeList* pList, SNode* pNode);
SListCell* nodesListErase(SNodeList* pList, SListCell* pCell);
SNode* nodesListGetNode(SNodeList* pList, int32_t index);
void nodesDestroyList(SNodeList* pList);
typedef enum EDealRes {
DEAL_RES_CONTINUE = 1,
DEAL_RES_IGNORE_CHILD,
DEAL_RES_ERROR,
} EDealRes;
typedef EDealRes (*FQueryNodeWalker)(SNode* pNode, void* pContext);
void nodesWalkNode(SNode* pNode, FQueryNodeWalker walker, void* pContext);
void nodesWalkList(SNodeList* pList, FQueryNodeWalker walker, void* pContext);
void nodesWalkNodePostOrder(SNode* pNode, FQueryNodeWalker walker, void* pContext);
void nodesWalkListPostOrder(SNodeList* pList, FQueryNodeWalker walker, void* pContext);
bool nodesEqualNode(const SNode* a, const SNode* b);
void nodesCloneNode(const SNode* pNode);
int32_t nodesNodeToString(const SNode* pNode, char** pStr, int32_t* pLen);
int32_t nodesStringToNode(const char* pStr, SNode** pNode);
bool nodesIsExprNode(const SNode* pNode); bool nodesIsExprNode(const SNode* pNode);
bool nodesIsArithmeticOp(const SOperatorNode* pOp); bool nodesIsArithmeticOp(const SOperatorNode* pOp);
...@@ -370,4 +277,4 @@ bool nodesIsTimelineQuery(const SNode* pQuery); ...@@ -370,4 +277,4 @@ bool nodesIsTimelineQuery(const SNode* pQuery);
} }
#endif #endif
#endif /*_TD_NODES_H_*/ #endif /*_TD_QUERY_NODES_H_*/
\ No newline at end of file
...@@ -80,16 +80,16 @@ typedef struct STableMeta { ...@@ -80,16 +80,16 @@ typedef struct STableMeta {
SSchema schema[]; SSchema schema[];
} STableMeta; } STableMeta;
typedef struct SDBVgroupInfo { typedef struct SDBVgInfo {
int32_t vgVersion; int32_t vgVersion;
int8_t hashMethod; int8_t hashMethod;
SHashObj *vgHash; //key:vgId, value:SVgroupInfo SHashObj *vgHash; //key:vgId, value:SVgroupInfo
} SDBVgroupInfo; } SDBVgInfo;
typedef struct SUseDbOutput { typedef struct SUseDbOutput {
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
uint64_t dbId; uint64_t dbId;
SDBVgroupInfo *dbVgroup; SDBVgInfo *dbVgroup;
} SUseDbOutput; } SUseDbOutput;
enum { enum {
......
/* /*
* Copyright (c) 2019 TAOS Data, Inc. <cli@taosdata.com> * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
* *
* This program is free software: you can use, redistribute, and/or modify * 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 * it under the terms of the GNU Affero General Public License, version 3
...@@ -23,7 +23,7 @@ extern "C" { ...@@ -23,7 +23,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include "taosdef.h" #include "taosdef.h"
typedef int32_t SyncNodeId; typedef uint64_t SyncNodeId;
typedef int32_t SyncGroupId; typedef int32_t SyncGroupId;
typedef int64_t SyncIndex; typedef int64_t SyncIndex;
typedef uint64_t SyncTerm; typedef uint64_t SyncTerm;
...@@ -46,109 +46,113 @@ typedef struct { ...@@ -46,109 +46,113 @@ typedef struct {
} SNodeInfo; } SNodeInfo;
typedef struct { typedef struct {
int32_t selfIndex; int32_t replicaNum;
int32_t replica;
SNodeInfo nodeInfo[TSDB_MAX_REPLICA]; SNodeInfo nodeInfo[TSDB_MAX_REPLICA];
} SSyncCluster; } SSyncCfg;
typedef struct { typedef struct {
int32_t selfIndex; int32_t replicaNum;
int32_t replica; SNodeInfo nodeInfo[TSDB_MAX_REPLICA];
SNodeInfo node[TSDB_MAX_REPLICA];
ESyncState role[TSDB_MAX_REPLICA]; ESyncState role[TSDB_MAX_REPLICA];
} SNodesRole; } SNodesRole;
typedef struct SSyncFSM { // abstract definition of snapshot
void* pData; typedef struct SSnapshot {
void* data;
// apply committed log, bufs will be free by sync module SyncIndex lastApplyIndex;
int32_t (*applyLog)(struct SSyncFSM* fsm, SyncIndex index, const SSyncBuffer* buf, void* pData); } SSnapshot;
// cluster commit callback typedef struct SSyncFSM {
int32_t (*onClusterChanged)(struct SSyncFSM* fsm, const SSyncCluster* cluster, void* pData); void* data;
// fsm return snapshot in ppBuf, bufs will be free by sync module // when value in pBuf finish a raft flow, FpCommitCb is called, code indicates the result
// TODO: getSnapshot SHOULD be async? // user can do something according to the code and isWeak. for example, write data into tsdb
int32_t (*getSnapshot)(struct SSyncFSM* fsm, SSyncBuffer** ppBuf, int32_t* objId, bool* isLast); void (*FpCommitCb)(struct SSyncFSM* pFsm, const SSyncBuffer* pBuf, SyncIndex index, bool isWeak, int32_t code);
// fsm apply snapshot with pBuf data // when value in pBuf has been written into local log store, FpPreCommitCb is called, code indicates the result
int32_t (*applySnapshot)(struct SSyncFSM* fsm, SSyncBuffer* pBuf, int32_t objId, bool isLast); // user can do something according to the code and isWeak. for example, write data into tsdb
void (*FpPreCommitCb)(struct SSyncFSM* pFsm, const SSyncBuffer* pBuf, SyncIndex index, bool isWeak, int32_t code);
// call when restore snapshot and log done // when log entry is updated by a new one, FpRollBackCb is called
int32_t (*onRestoreDone)(struct SSyncFSM* fsm); // user can do something to roll back. for example, delete data from tsdb, or just ignore it
void (*FpRollBackCb)(struct SSyncFSM* pFsm, const SSyncBuffer* pBuf, SyncIndex index, bool isWeak, int32_t code);
void (*onRollback)(struct SSyncFSM* fsm, SyncIndex index, const SSyncBuffer* buf); // user should implement this function, use "data" to take snapshot into "snapshot"
int32_t (*FpTakeSnapshot)(SSnapshot* snapshot);
void (*onRoleChanged)(struct SSyncFSM* fsm, const SNodesRole* pRole); // user should implement this function, restore "data" from "snapshot"
int32_t (*FpRestoreSnapshot)(const SSnapshot* snapshot);
} SSyncFSM; } SSyncFSM;
// abstract definition of log store in raft
// SWal implements it
typedef struct SSyncLogStore { typedef struct SSyncLogStore {
void* pData; void* data;
// append one log entry
int32_t (*appendEntry)(struct SSyncLogStore* pLogStore, SSyncBuffer* pBuf);
// write log with given index // get one log entry, user need to free pBuf->data
int32_t (*logWrite)(struct SSyncLogStore* logStore, SyncIndex index, SSyncBuffer* pBuf); int32_t (*getEntry)(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncBuffer* pBuf);
/** // update log store commit index with "index"
* read log from given index(included) with limit, return the actual num in nBuf, int32_t (*updateCommitIndex)(struct SSyncLogStore* pLogStore, SyncIndex index);
* pBuf will be free in sync module
**/
int32_t (*logRead)(struct SSyncLogStore* logStore, SyncIndex index, int limit,
SSyncBuffer* pBuf, int* nBuf);
// mark log with given index has been commtted // truncate log with index, entries after the given index (>index) will be deleted
int32_t (*logCommit)(struct SSyncLogStore* logStore, SyncIndex index); int32_t (*truncate)(struct SSyncLogStore* pLogStore, SyncIndex index);
// prune log before given index(not included) // return commit index of log
int32_t (*logPrune)(struct SSyncLogStore* logStore, SyncIndex index); SyncIndex (*getCommitIndex)(struct SSyncLogStore* pLogStore);
// rollback log after given index(included) // return index of last entry
int32_t (*logRollback)(struct SSyncLogStore* logStore, SyncIndex index); SyncIndex (*getLastIndex)(struct SSyncLogStore* pLogStore);
// return term of last entry
SyncTerm (*getLastTerm)(struct SSyncLogStore* pLogStore);
// return last index of log
SyncIndex (*logLastIndex)(struct SSyncLogStore* logStore);
} SSyncLogStore; } SSyncLogStore;
typedef struct SStateManager { // raft need to persist two variables in storage: currentTerm, voteFor
void* pData; typedef struct SStateMgr {
void* data;
// save serialized server state data, buffer will be free by Sync int32_t (*getCurrentTerm)(struct SStateMgr* pMgr, SyncTerm* pCurrentTerm);
int32_t (*saveServerState)(struct SStateManager* stateMng, const char* buffer, int n); int32_t (*persistCurrentTerm)(struct SStateMgr* pMgr, SyncTerm pCurrentTerm);
// read serialized server state data, buffer will be free by Sync int32_t (*getVoteFor)(struct SStateMgr* pMgr, SyncNodeId* pVoteFor);
int32_t (*readServerState)(struct SStateManager* stateMng, char** ppBuffer, int* n); int32_t (*persistVoteFor)(struct SStateMgr* pMgr, SyncNodeId voteFor);
// save serialized cluster state data, buffer will be free by Sync int32_t (*getSyncCfg)(struct SStateMgr* pMgr, SSyncCfg* pSyncCfg);
void (*saveClusterState)(struct SStateManager* stateMng, const char* buffer, int n); int32_t (*persistSyncCfg)(struct SStateMgr* pMgr, SSyncCfg* pSyncCfg);
// read serialized cluster state data, buffer will be free by Sync } SStateMgr;
int32_t (*readClusterState)(struct SStateManager* stateMng, char** ppBuffer, int* n);
} SStateManager;
typedef struct { typedef struct {
SyncGroupId vgId; SyncGroupId vgId;
SyncIndex appliedIndex; SSyncCfg syncCfg;
SSyncCluster syncCfg;
SSyncFSM fsm;
SSyncLogStore logStore; SSyncLogStore logStore;
SStateManager stateManager; SStateMgr stateManager;
SSyncFSM syncFsm;
} SSyncInfo; } SSyncInfo;
struct SSyncNode; // will be defined in syncInt.h, here just for complie
typedef struct SSyncNode SSyncNode; typedef struct SSyncNode {
} SSyncNode;
int32_t syncInit(); int32_t syncInit();
void syncCleanUp(); void syncCleanUp();
SSyncNode* syncStart(const SSyncInfo*); int64_t syncStart(const SSyncInfo*);
void syncReconfig(const SSyncNode*, const SSyncCluster*); void syncStop(int64_t rid);
void syncStop(const SSyncNode*); int32_t syncReconfig(int64_t rid, const SSyncCfg*);
int32_t syncPropose(SSyncNode* syncNode, const SSyncBuffer* pBuf, void* pData, bool isWeak);
int32_t syncAddNode(SSyncNode syncNode, const SNodeInfo *pNode); // int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pBuf, bool isWeak);
int32_t syncForwardToPeer(int64_t rid, const SSyncBuffer* pBuf, bool isWeak);
int32_t syncRemoveNode(SSyncNode syncNode, const SNodeInfo *pNode); ESyncState syncGetMyRole(int64_t rid);
void syncGetNodesRole(int64_t rid, SNodesRole*);
extern int32_t sDebugFlag; extern int32_t sDebugFlag;
......
...@@ -457,6 +457,8 @@ int32_t* taosGetErrno(); ...@@ -457,6 +457,8 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608) //There mustn't be aggregation #define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608) //There mustn't be aggregation
#define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609) //ORDER BY item must be the number of a SELECT-list expression #define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609) //ORDER BY item must be the number of a SELECT-list expression
#define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A) //Not a GROUP BY expression #define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A) //Not a GROUP BY expression
#define TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260B) //Not SELECTed expression
#define TSDB_CODE_PAR_NOT_SINGLE_GROUP TAOS_DEF_ERROR_CODE(0, 0x260C) //Not a single-group group function
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -3,5 +3,4 @@ add_subdirectory(util) ...@@ -3,5 +3,4 @@ add_subdirectory(util)
add_subdirectory(common) add_subdirectory(common)
add_subdirectory(libs) add_subdirectory(libs)
add_subdirectory(client) add_subdirectory(client)
add_subdirectory(dnode) add_subdirectory(dnode)
add_subdirectory(nodes) \ No newline at end of file
\ No newline at end of file
...@@ -28,22 +28,23 @@ static int32_t hbMqHbRspHandle(struct SAppHbMgr *pAppHbMgr, SClientHbRsp* pRsp) ...@@ -28,22 +28,23 @@ 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) {
code = catalogRemoveDB(pCatalog, rsp->db, rsp->uid); code = catalogRemoveDB(pCatalog, rsp->db, rsp->uid);
} else { } else {
SDBVgroupInfo vgInfo = {0}; SDBVgInfo vgInfo = {0};
vgInfo.vgVersion = rsp->vgVersion; vgInfo.vgVersion = rsp->vgVersion;
vgInfo.hashMethod = rsp->hashMethod; vgInfo.hashMethod = rsp->hashMethod;
vgInfo.vgHash = taosHashInit(rsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); vgInfo.vgHash = taosHashInit(rsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
...@@ -52,33 +53,21 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog ...@@ -52,33 +53,21 @@ 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;
} }
} }
code = catalogUpdateDBVgroup(pCatalog, rsp->db, rsp->uid, &vgInfo); catalogUpdateDBVgInfo(pCatalog, rsp->db, rsp->uid, &vgInfo);
if (code) {
taosHashCleanup(vgInfo.vgHash);
}
} }
if (code) { if (code) {
return code; return code;
} }
msgLen += sizeof(SUseDbRsp) + rsp->vgNum * sizeof(SVgroupInfo);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -94,13 +83,14 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo ...@@ -94,13 +83,14 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
rsp->numOfColumns = ntohl(rsp->numOfColumns); rsp->numOfColumns = ntohl(rsp->numOfColumns);
rsp->suid = be64toh(rsp->suid); rsp->suid = be64toh(rsp->suid);
rsp->dbId = be64toh(rsp->dbId);
if (rsp->numOfColumns < 0) { if (rsp->numOfColumns < 0) {
schemaNum = 0; schemaNum = 0;
tscDebug("hb remove stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName); tscDebug("hb remove stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
catalogRemoveSTableMeta(pCatalog, rsp->dbFName, rsp->stbName, rsp->suid); catalogRemoveStbMeta(pCatalog, rsp->dbFName, rsp->dbId, rsp->stbName, rsp->suid);
} else { } else {
tscDebug("hb update stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName); tscDebug("hb update stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
...@@ -201,9 +191,10 @@ static int32_t hbMqAsyncCallBack(void* param, const SDataBuf* pMsg, int32_t code ...@@ -201,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);
...@@ -416,7 +407,7 @@ static void* hbThreadFunc(void* param) { ...@@ -416,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;
...@@ -424,8 +415,7 @@ static void* hbThreadFunc(void* param) { ...@@ -424,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;
......
此差异已折叠。
...@@ -382,7 +382,7 @@ static void *dnodeOpenVnodeFunc(void *param) { ...@@ -382,7 +382,7 @@ static void *dnodeOpenVnodeFunc(void *param) {
pMgmt->openVnodes, pMgmt->totalVnodes); pMgmt->openVnodes, pMgmt->totalVnodes);
dndReportStartup(pDnode, "open-vnodes", stepDesc); dndReportStartup(pDnode, "open-vnodes", stepDesc);
SVnodeCfg cfg = {.pDnode = pDnode, .pTfs = pDnode->pTfs, .vgId = pCfg->vgId}; SVnodeCfg cfg = {.pDnode = pDnode, .pTfs = pDnode->pTfs, .vgId = pCfg->vgId, .dbId = pCfg->dbUid};
SVnode * pImpl = vnodeOpen(pCfg->path, &cfg); SVnode * pImpl = vnodeOpen(pCfg->path, &cfg);
if (pImpl == NULL) { if (pImpl == NULL) {
dError("vgId:%d, failed to open vnode by thread:%d", pCfg->vgId, pThread->threadIndex); dError("vgId:%d, failed to open vnode by thread:%d", pCfg->vgId, pThread->threadIndex);
...@@ -594,6 +594,7 @@ int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *pReq) { ...@@ -594,6 +594,7 @@ int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *pReq) {
vnodeCfg.pDnode = pDnode; vnodeCfg.pDnode = pDnode;
vnodeCfg.pTfs = pDnode->pTfs; vnodeCfg.pTfs = pDnode->pTfs;
vnodeCfg.dbId = wrapperCfg.dbUid;
SVnode *pImpl = vnodeOpen(wrapperCfg.path, &vnodeCfg); SVnode *pImpl = vnodeOpen(wrapperCfg.path, &vnodeCfg);
if (pImpl == NULL) { if (pImpl == NULL) {
dError("vgId:%d, failed to create vnode since %s", pCreate->vgId, terrstr()); dError("vgId:%d, failed to create vnode since %s", pCreate->vgId, terrstr());
......
...@@ -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);
......
...@@ -29,9 +29,12 @@ int32_t mndCheckCreateUserAuth(SUserObj *pOperUser); ...@@ -29,9 +29,12 @@ int32_t mndCheckCreateUserAuth(SUserObj *pOperUser);
int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SDbObj *pDb, SAlterUserReq *pAlter); int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SDbObj *pDb, SAlterUserReq *pAlter);
int32_t mndCheckDropUserAuth(SUserObj *pOperUser); int32_t mndCheckDropUserAuth(SUserObj *pOperUser);
int32_t mndCheckCreateNodeAuth(SUserObj *pOperUser); int32_t mndCheckNodeAuth(SUserObj *pOperUser);
int32_t mndCheckDropNodeAuth(SUserObj *pOperUser); int32_t mndCheckFuncAuth(SUserObj *pOperUser);
int32_t mndCheckAlterNodeAuth(SUserObj *pOperUser);
int32_t mndCheckCreateDbAuth(SUserObj *pOperUser);
int32_t mndCheckAlterDropCompactSyncDbAuth(SUserObj *pOperUser, SDbObj *pDb);
int32_t mndCheckUseDbAuth(SUserObj *pOperUser, SDbObj *pDb);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -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
} }
......
...@@ -111,7 +111,7 @@ int32_t mndCheckDropUserAuth(SUserObj *pOperUser) { ...@@ -111,7 +111,7 @@ int32_t mndCheckDropUserAuth(SUserObj *pOperUser) {
return -1; return -1;
} }
int32_t mndCheckCreateNodeAuth(SUserObj *pOperUser) { int32_t mndCheckNodeAuth(SUserObj *pOperUser) {
if (pOperUser->superUser) { if (pOperUser->superUser) {
return 0; return 0;
} }
...@@ -120,6 +120,24 @@ int32_t mndCheckCreateNodeAuth(SUserObj *pOperUser) { ...@@ -120,6 +120,24 @@ int32_t mndCheckCreateNodeAuth(SUserObj *pOperUser) {
return -1; return -1;
} }
int32_t mndCheckDropNodeAuth(SUserObj *pOperUser) { return mndCheckCreateNodeAuth(pOperUser); } int32_t mndCheckFuncAuth(SUserObj *pOperUser) {
if (pOperUser->superUser) {
return 0;
}
terrno = TSDB_CODE_MND_NO_RIGHTS;
return -1;
}
int32_t mndCheckCreateDbAuth(SUserObj *pOperUser) { return 0; }
int32_t mndCheckAlterDropCompactSyncDbAuth(SUserObj *pOperUser, SDbObj *pDb) {
if (pOperUser->superUser || strcmp(pOperUser->user, pDb->createUser) == 0) {
return 0;
}
terrno = TSDB_CODE_MND_NO_RIGHTS;
return -1;
}
int32_t mndCheckAlterNodeAuth(SUserObj *pOperUser) { return mndCheckCreateNodeAuth(pOperUser); } int32_t mndCheckUseDbAuth(SUserObj *pOperUser, SDbObj *pDb) { return 0; }
...@@ -293,7 +293,7 @@ static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pReq) { ...@@ -293,7 +293,7 @@ static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pReq) {
goto CREATE_BNODE_OVER; goto CREATE_BNODE_OVER;
} }
if (mndCheckDropNodeAuth(pUser)) { if (mndCheckNodeAuth(pUser)) {
goto CREATE_BNODE_OVER; goto CREATE_BNODE_OVER;
} }
...@@ -400,7 +400,7 @@ static int32_t mndProcessDropBnodeReq(SMnodeMsg *pReq) { ...@@ -400,7 +400,7 @@ static int32_t mndProcessDropBnodeReq(SMnodeMsg *pReq) {
goto DROP_BNODE_OVER; goto DROP_BNODE_OVER;
} }
if (mndCheckCreateNodeAuth(pUser)) { if (mndCheckNodeAuth(pUser)) {
goto DROP_BNODE_OVER; goto DROP_BNODE_OVER;
} }
......
...@@ -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) {
......
...@@ -496,7 +496,7 @@ static int32_t mndProcessCreateDnodeReq(SMnodeMsg *pReq) { ...@@ -496,7 +496,7 @@ static int32_t mndProcessCreateDnodeReq(SMnodeMsg *pReq) {
goto CREATE_DNODE_OVER; goto CREATE_DNODE_OVER;
} }
if (mndCheckDropNodeAuth(pUser)) { if (mndCheckNodeAuth(pUser)) {
goto CREATE_DNODE_OVER; goto CREATE_DNODE_OVER;
} }
...@@ -506,7 +506,6 @@ static int32_t mndProcessCreateDnodeReq(SMnodeMsg *pReq) { ...@@ -506,7 +506,6 @@ static int32_t mndProcessCreateDnodeReq(SMnodeMsg *pReq) {
CREATE_DNODE_OVER: CREATE_DNODE_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("dnode:%s:%d, failed to create since %s", createReq.fqdn, createReq.port, terrstr()); mError("dnode:%s:%d, failed to create since %s", createReq.fqdn, createReq.port, terrstr());
return -1;
} }
mndReleaseDnode(pMnode, pDnode); mndReleaseDnode(pMnode, pDnode);
...@@ -541,13 +540,13 @@ static int32_t mndDropDnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode) ...@@ -541,13 +540,13 @@ static int32_t mndDropDnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode)
} }
static int32_t mndProcessDropDnodeReq(SMnodeMsg *pReq) { static int32_t mndProcessDropDnodeReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
int32_t code = -1; int32_t code = -1;
SUserObj *pUser = NULL; SUserObj *pUser = NULL;
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
SDropDnodeReq dropReq = {0}; SMDropMnodeReq dropReq = {0};
if (tDeserializeSDropDnodeReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &dropReq) != 0) { if (tDeserializeSMCreateDropMnodeReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &dropReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG; terrno = TSDB_CODE_INVALID_MSG;
goto DROP_DNODE_OVER; goto DROP_DNODE_OVER;
} }
...@@ -571,7 +570,7 @@ static int32_t mndProcessDropDnodeReq(SMnodeMsg *pReq) { ...@@ -571,7 +570,7 @@ static int32_t mndProcessDropDnodeReq(SMnodeMsg *pReq) {
goto DROP_DNODE_OVER; goto DROP_DNODE_OVER;
} }
if (mndCheckCreateNodeAuth(pUser)) { if (mndCheckNodeAuth(pUser)) {
goto DROP_DNODE_OVER; goto DROP_DNODE_OVER;
} }
...@@ -581,7 +580,6 @@ static int32_t mndProcessDropDnodeReq(SMnodeMsg *pReq) { ...@@ -581,7 +580,6 @@ static int32_t mndProcessDropDnodeReq(SMnodeMsg *pReq) {
DROP_DNODE_OVER: DROP_DNODE_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("dnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr()); mError("dnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr());
return -1;
} }
mndReleaseDnode(pMnode, pDnode); mndReleaseDnode(pMnode, pDnode);
...@@ -591,14 +589,18 @@ DROP_DNODE_OVER: ...@@ -591,14 +589,18 @@ DROP_DNODE_OVER:
} }
static int32_t mndProcessConfigDnodeReq(SMnodeMsg *pReq) { static int32_t mndProcessConfigDnodeReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SMCfgDnodeReq *pCfg = pReq->rpcMsg.pCont;
pCfg->dnodeId = htonl(pCfg->dnodeId); SMCfgDnodeReq cfgReq = {0};
if (tDeserializeSMCfgDnodeReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &cfgReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
return -1;
}
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCfg->dnodeId); SDnodeObj *pDnode = mndAcquireDnode(pMnode, cfgReq.dnodeId);
if (pDnode == NULL) { if (pDnode == NULL) {
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
mError("dnode:%d, failed to config since %s ", pCfg->dnodeId, terrstr()); mError("dnode:%d, failed to config since %s ", cfgReq.dnodeId, terrstr());
return -1; return -1;
} }
...@@ -606,15 +608,15 @@ static int32_t mndProcessConfigDnodeReq(SMnodeMsg *pReq) { ...@@ -606,15 +608,15 @@ static int32_t mndProcessConfigDnodeReq(SMnodeMsg *pReq) {
mndReleaseDnode(pMnode, pDnode); mndReleaseDnode(pMnode, pDnode);
SDCfgDnodeReq *pCfgDnode = rpcMallocCont(sizeof(SDCfgDnodeReq)); SDCfgDnodeReq *pCfgDnode = rpcMallocCont(sizeof(SDCfgDnodeReq));
pCfgDnode->dnodeId = htonl(pCfg->dnodeId); pCfgDnode->dnodeId = htonl(cfgReq.dnodeId);
memcpy(pCfgDnode->config, pCfg->config, TSDB_DNODE_CONFIG_LEN); memcpy(pCfgDnode->config, cfgReq.config, TSDB_DNODE_CONFIG_LEN);
SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE, SRpcMsg rpcMsg = {.msgType = TDMT_DND_CONFIG_DNODE,
.pCont = pCfgDnode, .pCont = pCfgDnode,
.contLen = sizeof(SDCfgDnodeReq), .contLen = sizeof(SDCfgDnodeReq),
.ahandle = pReq->rpcMsg.ahandle}; .ahandle = pReq->rpcMsg.ahandle};
mInfo("dnode:%d, app:%p config:%s req send to dnode", pCfg->dnodeId, rpcMsg.ahandle, pCfg->config); mInfo("dnode:%d, app:%p config:%s req send to dnode", cfgReq.dnodeId, rpcMsg.ahandle, cfgReq.config);
mndSendReqToDnode(pMnode, &epSet, &rpcMsg); mndSendReqToDnode(pMnode, &epSet, &rpcMsg);
return 0; return 0;
......
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "mndFunc.h" #include "mndFunc.h"
#include "mndAuth.h"
#include "mndShow.h" #include "mndShow.h"
#include "mndSync.h" #include "mndSync.h"
#include "mndTrans.h" #include "mndTrans.h"
#include "mndUser.h"
#define SDB_FUNC_VER 1 #define SDB_FUNC_VER 1
#define SDB_FUNC_RESERVE_SIZE 64 #define SDB_FUNC_RESERVE_SIZE 64
...@@ -201,8 +203,8 @@ static int32_t mndCreateFunc(SMnode *pMnode, SMnodeMsg *pReq, SCreateFuncReq *pC ...@@ -201,8 +203,8 @@ static int32_t mndCreateFunc(SMnode *pMnode, SMnodeMsg *pReq, SCreateFuncReq *pC
goto CREATE_FUNC_OVER; goto CREATE_FUNC_OVER;
} }
memcpy(func.pComment, pCreate->pCont, pCreate->commentSize); memcpy(func.pComment, pCreate->pComment, pCreate->commentSize);
memcpy(func.pCode, pCreate->pCont + pCreate->commentSize, func.codeSize); memcpy(func.pCode, pCreate->pCode, func.codeSize);
pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg);
if (pTrans == NULL) goto CREATE_FUNC_OVER; if (pTrans == NULL) goto CREATE_FUNC_OVER;
...@@ -261,164 +263,202 @@ DROP_FUNC_OVER: ...@@ -261,164 +263,202 @@ DROP_FUNC_OVER:
} }
static int32_t mndProcessCreateFuncReq(SMnodeMsg *pReq) { static int32_t mndProcessCreateFuncReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
int32_t code = -1;
SCreateFuncReq *pCreate = pReq->rpcMsg.pCont; SUserObj *pUser = NULL;
pCreate->outputLen = htonl(pCreate->outputLen); SFuncObj *pFunc = NULL;
pCreate->bufSize = htonl(pCreate->bufSize); SCreateFuncReq createReq = {0};
pCreate->signature = htobe64(pCreate->signature);
pCreate->commentSize = htonl(pCreate->commentSize); if (tDeserializeSCreateFuncReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &createReq) != 0) {
pCreate->codeSize = htonl(pCreate->codeSize); terrno = TSDB_CODE_INVALID_MSG;
goto CREATE_FUNC_OVER;
}
mDebug("func:%s, start to create", pCreate->name); mDebug("func:%s, start to create", createReq.name);
SFuncObj *pFunc = mndAcquireFunc(pMnode, pCreate->name); pFunc = mndAcquireFunc(pMnode, createReq.name);
if (pFunc != NULL) { if (pFunc != NULL) {
mndReleaseFunc(pMnode, pFunc); if (createReq.igExists) {
if (pCreate->igExists) { mDebug("func:%s, already exist, ignore exist is set", createReq.name);
mDebug("stb:%s, already exist, ignore exist is set", pCreate->name); code = 0;
return 0; goto CREATE_FUNC_OVER;
} else { } else {
terrno = TSDB_CODE_MND_FUNC_ALREADY_EXIST; terrno = TSDB_CODE_MND_FUNC_ALREADY_EXIST;
mError("func:%s, failed to create since %s", pCreate->name, terrstr()); goto CREATE_FUNC_OVER;
return -1;
} }
} else if (terrno == TSDB_CODE_MND_FUNC_ALREADY_EXIST) { } else if (terrno == TSDB_CODE_MND_FUNC_ALREADY_EXIST) {
mError("stb:%s, failed to create since %s", pCreate->name, terrstr()); goto CREATE_FUNC_OVER;
return -1;
} }
if (pCreate->name[0] == 0) { if (createReq.name[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_FUNC_NAME; terrno = TSDB_CODE_MND_INVALID_FUNC_NAME;
mError("func:%s, failed to create since %s", pCreate->name, terrstr()); goto CREATE_FUNC_OVER;
return -1;
} }
if (pCreate->commentSize <= 0 || pCreate->commentSize > TSDB_FUNC_COMMENT_LEN) { if (createReq.commentSize <= 0 || createReq.commentSize > TSDB_FUNC_COMMENT_LEN) {
terrno = TSDB_CODE_MND_INVALID_FUNC_COMMENT; terrno = TSDB_CODE_MND_INVALID_FUNC_COMMENT;
mError("func:%s, failed to create since %s", pCreate->name, terrstr()); goto CREATE_FUNC_OVER;
return -1;
} }
if (pCreate->codeSize <= 0 || pCreate->codeSize > TSDB_FUNC_CODE_LEN) { if (createReq.codeSize <= 0 || createReq.codeSize > TSDB_FUNC_CODE_LEN) {
terrno = TSDB_CODE_MND_INVALID_FUNC_CODE; terrno = TSDB_CODE_MND_INVALID_FUNC_CODE;
mError("func:%s, failed to create since %s", pCreate->name, terrstr()); goto CREATE_FUNC_OVER;
return -1;
} }
if (pCreate->pCont[0] == 0) { if (createReq.pCode[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_FUNC_CODE; terrno = TSDB_CODE_MND_INVALID_FUNC_CODE;
mError("func:%s, failed to create since %s", pCreate->name, terrstr()); goto CREATE_FUNC_OVER;
return -1;
} }
if (pCreate->bufSize <= 0 || pCreate->bufSize > TSDB_FUNC_BUF_SIZE) { if (createReq.bufSize <= 0 || createReq.bufSize > TSDB_FUNC_BUF_SIZE) {
terrno = TSDB_CODE_MND_INVALID_FUNC_BUFSIZE; terrno = TSDB_CODE_MND_INVALID_FUNC_BUFSIZE;
mError("func:%s, failed to create since %s", pCreate->name, terrstr()); goto CREATE_FUNC_OVER;
return -1;
} }
int32_t code = mndCreateFunc(pMnode, pReq, pCreate); pUser = mndAcquireUser(pMnode, pReq->user);
if (code != 0) { if (pUser == NULL) {
mError("func:%s, failed to create since %s", pCreate->name, terrstr()); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
return -1; goto CREATE_FUNC_OVER;
}
if (mndCheckFuncAuth(pUser)) {
goto CREATE_FUNC_OVER;
}
code = mndCreateFunc(pMnode, pReq, &createReq);
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
CREATE_FUNC_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("func:%s, failed to create since %s", createReq.name, terrstr());
} }
return TSDB_CODE_MND_ACTION_IN_PROGRESS; mndReleaseFunc(pMnode, pFunc);
mndReleaseUser(pMnode, pUser);
return code;
} }
static int32_t mndProcessDropFuncReq(SMnodeMsg *pReq) { static int32_t mndProcessDropFuncReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SDropFuncReq *pDrop = pReq->rpcMsg.pCont; int32_t code = -1;
SUserObj *pUser = NULL;
SFuncObj *pFunc = NULL;
SDropFuncReq dropReq = {0};
if (tDeserializeSDropFuncReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &dropReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto DROP_FUNC_OVER;
}
mDebug("func:%s, start to drop", pDrop->name); mDebug("func:%s, start to drop", dropReq.name);
if (pDrop->name[0] == 0) { if (dropReq.name[0] == 0) {
terrno = TSDB_CODE_MND_INVALID_FUNC_NAME; terrno = TSDB_CODE_MND_INVALID_FUNC_NAME;
mError("func:%s, failed to drop since %s", pDrop->name, terrstr()); goto DROP_FUNC_OVER;
return -1;
} }
SFuncObj *pFunc = mndAcquireFunc(pMnode, pDrop->name); pFunc = mndAcquireFunc(pMnode, dropReq.name);
if (pFunc == NULL) { if (pFunc == NULL) {
if (pDrop->igNotExists) { if (dropReq.igNotExists) {
mDebug("func:%s, not exist, ignore not exist is set", pDrop->name); mDebug("func:%s, not exist, ignore not exist is set", dropReq.name);
return 0; code = 0;
goto DROP_FUNC_OVER;
} else { } else {
terrno = TSDB_CODE_MND_FUNC_NOT_EXIST; terrno = TSDB_CODE_MND_FUNC_NOT_EXIST;
mError("func:%s, failed to drop since %s", pDrop->name, terrstr()); goto DROP_FUNC_OVER;
return -1;
} }
} }
int32_t code = mndDropFunc(pMnode, pReq, pFunc); pUser = mndAcquireUser(pMnode, pReq->user);
mndReleaseFunc(pMnode, pFunc); if (pUser == NULL) {
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
goto DROP_FUNC_OVER;
}
if (mndCheckFuncAuth(pUser)) {
goto DROP_FUNC_OVER;
}
code = mndDropFunc(pMnode, pReq, pFunc);
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
if (code != 0) { DROP_FUNC_OVER:
mError("func:%s, failed to drop since %s", pDrop->name, terrstr()); if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
return -1; mError("func:%s, failed to drop since %s", dropReq.name, terrstr());
} }
return TSDB_CODE_MND_ACTION_IN_PROGRESS; mndReleaseFunc(pMnode, pFunc);
mndReleaseUser(pMnode, pUser);
return code;
} }
static int32_t mndProcessRetrieveFuncReq(SMnodeMsg *pReq) { static int32_t mndProcessRetrieveFuncReq(SMnodeMsg *pReq) {
int32_t code = -1; SMnode *pMnode = pReq->pMnode;
SMnode *pMnode = pReq->pMnode; int32_t code = -1;
SRetrieveFuncReq retrieveReq = {0};
SRetrieveFuncRsp retrieveRsp = {0};
if (tDeserializeSRetrieveFuncReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &retrieveReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto RETRIEVE_FUNC_OVER;
}
SRetrieveFuncReq *pRetrieve = pReq->rpcMsg.pCont; if (retrieveReq.numOfFuncs <= 0 || retrieveReq.numOfFuncs > TSDB_FUNC_MAX_RETRIEVE) {
pRetrieve->numOfFuncs = htonl(pRetrieve->numOfFuncs);
if (pRetrieve->numOfFuncs <= 0 || pRetrieve->numOfFuncs > TSDB_FUNC_MAX_RETRIEVE) {
terrno = TSDB_CODE_MND_INVALID_FUNC_RETRIEVE; terrno = TSDB_CODE_MND_INVALID_FUNC_RETRIEVE;
return -1; goto RETRIEVE_FUNC_OVER;
} }
int32_t fsize = sizeof(SFuncInfo) + TSDB_FUNC_CODE_LEN + TSDB_FUNC_COMMENT_LEN; retrieveRsp.numOfFuncs = retrieveReq.numOfFuncs;
int32_t size = sizeof(SRetrieveFuncRsp) + fsize * pRetrieve->numOfFuncs; retrieveRsp.pFuncInfos = taosArrayInit(retrieveReq.numOfFuncs, sizeof(SFuncInfo));
if (retrieveRsp.pFuncInfos == NULL) {
SRetrieveFuncRsp *pRetrieveRsp = rpcMallocCont(size);
if (pRetrieveRsp == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
goto FUNC_RETRIEVE_OVER; goto RETRIEVE_FUNC_OVER;
} }
pRetrieveRsp->numOfFuncs = htonl(pRetrieve->numOfFuncs); for (int32_t i = 0; i < retrieveReq.numOfFuncs; ++i) {
char *pOutput = pRetrieveRsp->pFuncInfos; char *funcName = taosArrayGet(retrieveReq.pFuncNames, i);
for (int32_t i = 0; i < pRetrieve->numOfFuncs; ++i) {
char funcName[TSDB_FUNC_NAME_LEN] = {0};
memcpy(funcName, pRetrieve->pFuncNames + i * TSDB_FUNC_NAME_LEN, TSDB_FUNC_NAME_LEN);
SFuncObj *pFunc = mndAcquireFunc(pMnode, funcName); SFuncObj *pFunc = mndAcquireFunc(pMnode, funcName);
if (pFunc == NULL) { if (pFunc == NULL) {
terrno = TSDB_CODE_MND_INVALID_FUNC; terrno = TSDB_CODE_MND_INVALID_FUNC;
mError("func:%s, failed to retrieve since %s", funcName, terrstr()); goto RETRIEVE_FUNC_OVER;
goto FUNC_RETRIEVE_OVER;
} }
SFuncInfo *pFuncInfo = (SFuncInfo *)pOutput; SFuncInfo funcInfo = {0};
memcpy(pFuncInfo->name, pFunc->name, TSDB_FUNC_NAME_LEN); memcpy(funcInfo.name, pFunc->name, TSDB_FUNC_NAME_LEN);
pFuncInfo->funcType = pFunc->funcType; funcInfo.funcType = pFunc->funcType;
pFuncInfo->scriptType = pFunc->scriptType; funcInfo.scriptType = pFunc->scriptType;
pFuncInfo->outputType = pFunc->outputType; funcInfo.outputType = pFunc->outputType;
pFuncInfo->outputLen = htonl(pFunc->outputLen); funcInfo.outputLen = pFunc->outputLen;
pFuncInfo->bufSize = htonl(pFunc->bufSize); funcInfo.bufSize = pFunc->bufSize;
pFuncInfo->signature = htobe64(pFunc->signature); funcInfo.signature = pFunc->signature;
pFuncInfo->commentSize = htonl(pFunc->commentSize); funcInfo.commentSize = pFunc->commentSize;
pFuncInfo->codeSize = htonl(pFunc->codeSize); funcInfo.codeSize = pFunc->codeSize;
memcpy(pFuncInfo->pCont, pFunc->pComment, pFunc->commentSize); memcpy(funcInfo.pComment, pFunc->pComment, pFunc->commentSize);
memcpy(pFuncInfo->pCont + pFunc->commentSize, pFunc->pCode, pFunc->codeSize); memcpy(funcInfo.pCode, pFunc->pCode, pFunc->codeSize);
pOutput += (sizeof(SFuncInfo) + pFunc->commentSize + pFunc->codeSize); taosArrayPush(retrieveRsp.pFuncInfos, &funcInfo);
mndReleaseFunc(pMnode, pFunc); mndReleaseFunc(pMnode, pFunc);
} }
pReq->pCont = pRetrieveRsp; int32_t contLen = tSerializeSRetrieveFuncRsp(NULL, 0, &retrieveRsp);
pReq->contLen = (int32_t)(pOutput - (char *)pRetrieveRsp); void *pRsp = rpcMallocCont(contLen);
if (pRsp == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto RETRIEVE_FUNC_OVER;
}
tSerializeSRetrieveFuncRsp(pRsp, contLen, &retrieveRsp);
pReq->pCont = pRsp;
pReq->contLen = contLen;
code = 0; code = 0;
FUNC_RETRIEVE_OVER: RETRIEVE_FUNC_OVER:
if (code != 0) rpcFreeCont(pRetrieveRsp); taosArrayDestroy(retrieveReq.pFuncNames);
taosArrayDestroy(retrieveRsp.pFuncInfos);
return code; return code;
} }
......
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "mndMnode.h" #include "mndMnode.h"
#include "mndAuth.h"
#include "mndDnode.h" #include "mndDnode.h"
#include "mndShow.h" #include "mndShow.h"
#include "mndTrans.h" #include "mndTrans.h"
#include "mndUser.h"
#define TSDB_MNODE_VER_NUMBER 1 #define TSDB_MNODE_VER_NUMBER 1
#define TSDB_MNODE_RESERVE_SIZE 64 #define TSDB_MNODE_RESERVE_SIZE 64
...@@ -379,40 +381,57 @@ CREATE_MNODE_OVER: ...@@ -379,40 +381,57 @@ CREATE_MNODE_OVER:
} }
static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pReq) { static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SMCreateMnodeReq *pCreate = pReq->rpcMsg.pCont; int32_t code = -1;
SMnodeObj *pObj = NULL;
pCreate->dnodeId = htonl(pCreate->dnodeId); SDnodeObj *pDnode = NULL;
SUserObj *pUser = NULL;
SMCreateMnodeReq createReq = {0};
if (tDeserializeSMCreateDropMnodeReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &createReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto CREATE_MNODE_OVER;
}
mDebug("mnode:%d, start to create", pCreate->dnodeId); mDebug("mnode:%d, start to create", createReq.dnodeId);
SMnodeObj *pObj = mndAcquireMnode(pMnode, pCreate->dnodeId); pObj = mndAcquireMnode(pMnode, createReq.dnodeId);
if (pObj != NULL) { if (pObj != NULL) {
mndReleaseMnode(pMnode, pObj);
mError("mnode:%d, mnode already exist", pObj->id);
terrno = TSDB_CODE_MND_MNODE_ALREADY_EXIST; terrno = TSDB_CODE_MND_MNODE_ALREADY_EXIST;
return -1; goto CREATE_MNODE_OVER;
} else if (terrno != TSDB_CODE_MND_MNODE_NOT_EXIST) { } else if (terrno != TSDB_CODE_MND_MNODE_NOT_EXIST) {
mError("qnode:%d, failed to create mnode since %s", pCreate->dnodeId, terrstr()); goto CREATE_MNODE_OVER;
return -1;
} }
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); pDnode = mndAcquireDnode(pMnode, createReq.dnodeId);
if (pDnode == NULL) { if (pDnode == NULL) {
mError("mnode:%d, dnode not exist", pCreate->dnodeId);
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
return -1; goto CREATE_MNODE_OVER;
} }
int32_t code = mndCreateMnode(pMnode, pReq, pDnode, pCreate); pUser = mndAcquireUser(pMnode, pReq->user);
mndReleaseDnode(pMnode, pDnode); if (pUser == NULL) {
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
goto CREATE_MNODE_OVER;
}
if (code != 0) { if (mndCheckNodeAuth(pUser)) {
mError("mnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); goto CREATE_MNODE_OVER;
return -1;
} }
return TSDB_CODE_MND_ACTION_IN_PROGRESS; code = mndCreateMnode(pMnode, pReq, pDnode, &createReq);
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
CREATE_MNODE_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("mnode:%d, failed to create since %s", createReq.dnodeId, terrstr());
}
mndReleaseMnode(pMnode, pObj);
mndReleaseDnode(pMnode, pDnode);
mndReleaseUser(pMnode, pUser);
return code;
} }
static int32_t mndSetDropMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) { static int32_t mndSetDropMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
...@@ -534,32 +553,51 @@ DROP_MNODE_OVER: ...@@ -534,32 +553,51 @@ DROP_MNODE_OVER:
} }
static int32_t mndProcessDropMnodeReq(SMnodeMsg *pReq) { static int32_t mndProcessDropMnodeReq(SMnodeMsg *pReq) {
SMnode *pMnode = pReq->pMnode; SMnode *pMnode = pReq->pMnode;
SMDropMnodeReq *pDrop = pReq->rpcMsg.pCont; int32_t code = -1;
pDrop->dnodeId = htonl(pDrop->dnodeId); SUserObj *pUser = NULL;
SMnodeObj *pObj = NULL;
SMDropMnodeReq dropReq = {0};
if (tDeserializeSMCreateDropMnodeReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &dropReq) != 0) {
terrno = TSDB_CODE_INVALID_MSG;
goto DROP_MNODE_OVER;
}
mDebug("mnode:%d, start to drop", pDrop->dnodeId); mDebug("mnode:%d, start to drop", dropReq.dnodeId);
if (pDrop->dnodeId <= 0) { if (dropReq.dnodeId <= 0) {
terrno = TSDB_CODE_SDB_APP_ERROR; terrno = TSDB_CODE_SDB_APP_ERROR;
mError("mnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); goto DROP_MNODE_OVER;
return -1;
} }
SMnodeObj *pObj = mndAcquireMnode(pMnode, pDrop->dnodeId); pObj = mndAcquireMnode(pMnode, dropReq.dnodeId);
if (pObj == NULL) { if (pObj == NULL) {
mError("mnode:%d, not exist", pDrop->dnodeId); goto DROP_MNODE_OVER;
return -1;
} }
int32_t code = mndDropMnode(pMnode, pReq, pObj); pUser = mndAcquireUser(pMnode, pReq->user);
if (code != 0) { if (pUser == NULL) {
mError("mnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
return -1; goto DROP_MNODE_OVER;
}
if (mndCheckNodeAuth(pUser)) {
goto DROP_MNODE_OVER;
} }
sdbRelease(pMnode->pSdb, pObj); code = mndDropMnode(pMnode, pReq, pObj);
return TSDB_CODE_MND_ACTION_IN_PROGRESS; if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
DROP_MNODE_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("mnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr());
}
mndReleaseMnode(pMnode, pObj);
mndReleaseUser(pMnode, pUser);
return code;
} }
static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pRsp) { static int32_t mndProcessCreateMnodeRsp(SMnodeMsg *pRsp) {
......
...@@ -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);
......
...@@ -293,7 +293,7 @@ static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pReq) { ...@@ -293,7 +293,7 @@ static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pReq) {
goto CREATE_QNODE_OVER; goto CREATE_QNODE_OVER;
} }
if (mndCheckDropNodeAuth(pUser)) { if (mndCheckNodeAuth(pUser)) {
goto CREATE_QNODE_OVER; goto CREATE_QNODE_OVER;
} }
...@@ -303,7 +303,6 @@ static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pReq) { ...@@ -303,7 +303,6 @@ static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pReq) {
CREATE_QNODE_OVER: CREATE_QNODE_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("qnode:%d, failed to create since %s", createReq.dnodeId, terrstr()); mError("qnode:%d, failed to create since %s", createReq.dnodeId, terrstr());
return -1;
} }
mndReleaseQnode(pMnode, pObj); mndReleaseQnode(pMnode, pObj);
...@@ -401,7 +400,7 @@ static int32_t mndProcessDropQnodeReq(SMnodeMsg *pReq) { ...@@ -401,7 +400,7 @@ static int32_t mndProcessDropQnodeReq(SMnodeMsg *pReq) {
goto DROP_QNODE_OVER; goto DROP_QNODE_OVER;
} }
if (mndCheckCreateNodeAuth(pUser)) { if (mndCheckNodeAuth(pUser)) {
goto DROP_QNODE_OVER; goto DROP_QNODE_OVER;
} }
...@@ -411,7 +410,6 @@ static int32_t mndProcessDropQnodeReq(SMnodeMsg *pReq) { ...@@ -411,7 +410,6 @@ static int32_t mndProcessDropQnodeReq(SMnodeMsg *pReq) {
DROP_QNODE_OVER: DROP_QNODE_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("qnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); mError("qnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
return -1;
} }
mndReleaseQnode(pMnode, pObj); mndReleaseQnode(pMnode, pObj);
......
...@@ -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);
} }
......
...@@ -294,7 +294,7 @@ static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pReq) { ...@@ -294,7 +294,7 @@ static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pReq) {
goto CREATE_SNODE_OVER; goto CREATE_SNODE_OVER;
} }
if (mndCheckDropNodeAuth(pUser)) { if (mndCheckNodeAuth(pUser)) {
goto CREATE_SNODE_OVER; goto CREATE_SNODE_OVER;
} }
...@@ -403,7 +403,7 @@ static int32_t mndProcessDropSnodeReq(SMnodeMsg *pReq) { ...@@ -403,7 +403,7 @@ static int32_t mndProcessDropSnodeReq(SMnodeMsg *pReq) {
goto DROP_SNODE_OVER; goto DROP_SNODE_OVER;
} }
if (mndCheckCreateNodeAuth(pUser)) { if (mndCheckNodeAuth(pUser)) {
goto DROP_SNODE_OVER; goto DROP_SNODE_OVER;
} }
...@@ -413,7 +413,6 @@ static int32_t mndProcessDropSnodeReq(SMnodeMsg *pReq) { ...@@ -413,7 +413,6 @@ static int32_t mndProcessDropSnodeReq(SMnodeMsg *pReq) {
DROP_SNODE_OVER: DROP_SNODE_OVER:
if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { if (code != 0 && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
return -1;
} }
mndReleaseSnode(pMnode, pObj); mndReleaseSnode(pMnode, pObj);
......
...@@ -1523,4 +1523,4 @@ static int32_t mndRetrieveStb(SMnodeMsg *pReq, SShowObj *pShow, char *data, int3 ...@@ -1523,4 +1523,4 @@ static int32_t mndRetrieveStb(SMnodeMsg *pReq, SShowObj *pShow, char *data, int3
static void mndCancelGetNextStb(SMnode *pMnode, void *pIter) { static void mndCancelGetNextStb(SMnode *pMnode, void *pIter) {
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
sdbCancelFetch(pSdb, pIter); sdbCancelFetch(pSdb, pIter);
} }
\ No newline at end of file
...@@ -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);
} }
} }
...@@ -75,11 +75,14 @@ TEST_F(MndTestDnode, 01_ShowDnode) { ...@@ -75,11 +75,14 @@ TEST_F(MndTestDnode, 01_ShowDnode) {
} }
TEST_F(MndTestDnode, 02_ConfigDnode) { TEST_F(MndTestDnode, 02_ConfigDnode) {
int32_t contLen = sizeof(SMCfgDnodeReq); SMCfgDnodeReq cfgReq = {0};
cfgReq.dnodeId = 1;
SMCfgDnodeReq* pReq = (SMCfgDnodeReq*)rpcMallocCont(contLen); strcpy(cfgReq.config, "ddebugflag");
pReq->dnodeId = htonl(1); strcpy(cfgReq.value, "131");
strcpy(pReq->config, "ddebugflag 131");
int32_t contLen = tSerializeSMCfgDnodeReq(NULL, 0, &cfgReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSMCfgDnodeReq(pReq, contLen, &cfgReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONFIG_DNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONFIG_DNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
......
...@@ -60,10 +60,12 @@ TEST_F(MndTestMnode, 01_ShowDnode) { ...@@ -60,10 +60,12 @@ TEST_F(MndTestMnode, 01_ShowDnode) {
TEST_F(MndTestMnode, 02_Create_Mnode_Invalid_Id) { TEST_F(MndTestMnode, 02_Create_Mnode_Invalid_Id) {
{ {
int32_t contLen = sizeof(SMCreateMnodeReq); SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 1;
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &createReq);
pReq->dnodeId = htonl(1); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -73,10 +75,12 @@ TEST_F(MndTestMnode, 02_Create_Mnode_Invalid_Id) { ...@@ -73,10 +75,12 @@ TEST_F(MndTestMnode, 02_Create_Mnode_Invalid_Id) {
TEST_F(MndTestMnode, 03_Create_Mnode_Invalid_Id) { TEST_F(MndTestMnode, 03_Create_Mnode_Invalid_Id) {
{ {
int32_t contLen = sizeof(SMCreateMnodeReq); SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &createReq);
pReq->dnodeId = htonl(2); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -107,10 +111,12 @@ TEST_F(MndTestMnode, 04_Create_Mnode) { ...@@ -107,10 +111,12 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
{ {
// create mnode // create mnode
int32_t contLen = sizeof(SMCreateMnodeReq); SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &createReq);
pReq->dnodeId = htonl(2); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -134,10 +140,12 @@ TEST_F(MndTestMnode, 04_Create_Mnode) { ...@@ -134,10 +140,12 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
{ {
// drop mnode // drop mnode
int32_t contLen = sizeof(SMDropMnodeReq); SMDropMnodeReq dropReq = {0};
dropReq.dnodeId = 2;
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &dropReq);
pReq->dnodeId = htonl(2); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -156,10 +164,12 @@ TEST_F(MndTestMnode, 04_Create_Mnode) { ...@@ -156,10 +164,12 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
{ {
// drop mnode // drop mnode
int32_t contLen = sizeof(SMDropMnodeReq); SMDropMnodeReq dropReq = {0};
dropReq.dnodeId = 2;
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &dropReq);
pReq->dnodeId = htonl(2); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -170,10 +180,12 @@ TEST_F(MndTestMnode, 04_Create_Mnode) { ...@@ -170,10 +180,12 @@ TEST_F(MndTestMnode, 04_Create_Mnode) {
TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) { TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) {
{ {
// send message first, then dnode2 crash, result is returned, and rollback is started // send message first, then dnode2 crash, result is returned, and rollback is started
int32_t contLen = sizeof(SMCreateMnodeReq); SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &createReq);
pReq->dnodeId = htonl(2); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &createReq);
server2.Stop(); server2.Stop();
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
...@@ -183,10 +195,12 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) { ...@@ -183,10 +195,12 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) {
{ {
// continue send message, mnode is creating // continue send message, mnode is creating
int32_t contLen = sizeof(SMCreateMnodeReq); SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &createReq);
pReq->dnodeId = htonl(2); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -195,10 +209,12 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) { ...@@ -195,10 +209,12 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) {
{ {
// continue send message, mnode is creating // continue send message, mnode is creating
int32_t contLen = sizeof(SMDropMnodeReq); SMDropMnodeReq dropReq = {0};
dropReq.dnodeId = 2;
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &dropReq);
pReq->dnodeId = htonl(2); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -214,10 +230,12 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) { ...@@ -214,10 +230,12 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) {
int32_t retryMax = 20; int32_t retryMax = 20;
for (retry = 0; retry < retryMax; retry++) { for (retry = 0; retry < retryMax; retry++) {
int32_t contLen = sizeof(SMCreateMnodeReq); SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &createReq);
pReq->dnodeId = htonl(2); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -232,10 +250,12 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) { ...@@ -232,10 +250,12 @@ TEST_F(MndTestMnode, 03_Create_Mnode_Rollback) {
TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) { TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) {
{ {
// send message first, then dnode2 crash, result is returned, and rollback is started // send message first, then dnode2 crash, result is returned, and rollback is started
int32_t contLen = sizeof(SMDropMnodeReq); SMDropMnodeReq dropReq = {0};
dropReq.dnodeId = 2;
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &dropReq);
pReq->dnodeId = htonl(2); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &dropReq);
server2.Stop(); server2.Stop();
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
...@@ -245,10 +265,12 @@ TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) { ...@@ -245,10 +265,12 @@ TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) {
{ {
// continue send message, mnode is dropping // continue send message, mnode is dropping
int32_t contLen = sizeof(SMCreateMnodeReq); SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &createReq);
pReq->dnodeId = htonl(2); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -257,10 +279,12 @@ TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) { ...@@ -257,10 +279,12 @@ TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) {
{ {
// continue send message, mnode is dropping // continue send message, mnode is dropping
int32_t contLen = sizeof(SMDropMnodeReq); SMDropMnodeReq dropReq = {0};
dropReq.dnodeId = 2;
SMDropMnodeReq* pReq = (SMDropMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &dropReq);
pReq->dnodeId = htonl(2); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &dropReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -276,10 +300,12 @@ TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) { ...@@ -276,10 +300,12 @@ TEST_F(MndTestMnode, 04_Drop_Mnode_Rollback) {
int32_t retryMax = 20; int32_t retryMax = 20;
for (retry = 0; retry < retryMax; retry++) { for (retry = 0; retry < retryMax; retry++) {
int32_t contLen = sizeof(SMCreateMnodeReq); SMCreateMnodeReq createReq = {0};
createReq.dnodeId = 2;
SMCreateMnodeReq* pReq = (SMCreateMnodeReq*)rpcMallocCont(contLen); int32_t contLen = tSerializeSMCreateDropMnodeReq(NULL, 0, &createReq);
pReq->dnodeId = htonl(2); void* pReq = rpcMallocCont(contLen);
tSerializeSMCreateDropMnodeReq(pReq, contLen, &createReq);
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
......
...@@ -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);
......
...@@ -42,6 +42,7 @@ typedef struct { ...@@ -42,6 +42,7 @@ typedef struct {
typedef struct { typedef struct {
int32_t vgId; int32_t vgId;
uint64_t dbId;
SDnode *pDnode; SDnode *pDnode;
STfs *pTfs; STfs *pTfs;
uint64_t wsize; uint64_t wsize;
......
...@@ -29,6 +29,7 @@ SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) { ...@@ -29,6 +29,7 @@ SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) {
cfg.vgId = pVnodeCfg->vgId; cfg.vgId = pVnodeCfg->vgId;
cfg.pDnode = pVnodeCfg->pDnode; cfg.pDnode = pVnodeCfg->pDnode;
cfg.pTfs = pVnodeCfg->pTfs; cfg.pTfs = pVnodeCfg->pTfs;
cfg.dbId = pVnodeCfg->dbId;
} }
// Validate options // Validate options
......
...@@ -93,6 +93,7 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) { ...@@ -93,6 +93,7 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
if (pTbCfg->type == META_CHILD_TABLE) { if (pTbCfg->type == META_CHILD_TABLE) {
pStbCfg = metaGetTbInfoByUid(pVnode->pMeta, pTbCfg->ctbCfg.suid); pStbCfg = metaGetTbInfoByUid(pVnode->pMeta, pTbCfg->ctbCfg.suid);
if (pStbCfg == NULL) { if (pStbCfg == NULL) {
code = TSDB_CODE_VND_TB_NOT_EXIST;
goto _exit; goto _exit;
} }
...@@ -116,9 +117,11 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) { ...@@ -116,9 +117,11 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
msgLen = sizeof(STableMetaRsp) + sizeof(SSchema) * (nCols + nTagCols); msgLen = sizeof(STableMetaRsp) + sizeof(SSchema) * (nCols + nTagCols);
pTbMetaMsg = (STableMetaRsp *)rpcMallocCont(msgLen); pTbMetaMsg = (STableMetaRsp *)rpcMallocCont(msgLen);
if (pTbMetaMsg == NULL) { if (pTbMetaMsg == NULL) {
code = TSDB_CODE_VND_OUT_OF_MEMORY;
goto _exit; goto _exit;
} }
pTbMetaMsg->dbId = htobe64(pVnode->config.dbId);
memcpy(pTbMetaMsg->dbFName, pReq->dbFName, sizeof(pTbMetaMsg->dbFName)); memcpy(pTbMetaMsg->dbFName, pReq->dbFName, sizeof(pTbMetaMsg->dbFName));
strcpy(pTbMetaMsg->tbName, pReq->tbName); strcpy(pTbMetaMsg->tbName, pReq->tbName);
if (pTbCfg->type == META_CHILD_TABLE) { if (pTbCfg->type == META_CHILD_TABLE) {
......
...@@ -13,3 +13,4 @@ add_subdirectory(function) ...@@ -13,3 +13,4 @@ add_subdirectory(function)
add_subdirectory(qcom) add_subdirectory(qcom)
add_subdirectory(qworker) add_subdirectory(qworker)
add_subdirectory(tfs) add_subdirectory(tfs)
add_subdirectory(nodes)
\ No newline at end of file
此差异已折叠。
...@@ -47,10 +47,11 @@ int32_t fmGetHandle(FuncMgtHandle* pHandle) { ...@@ -47,10 +47,11 @@ int32_t fmGetHandle(FuncMgtHandle* pHandle) {
int32_t fmGetFuncInfo(FuncMgtHandle handle, const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType) { int32_t fmGetFuncInfo(FuncMgtHandle handle, const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType) {
SFuncMgtService* pService = (SFuncMgtService*)handle; SFuncMgtService* pService = (SFuncMgtService*)handle;
pFuncId = taosHashGet(pService->pFuncNameHashTable, pFuncName, strlen(pFuncName)); void* pVal = taosHashGet(pService->pFuncNameHashTable, pFuncName, strlen(pFuncName));
if (NULL == pFuncId) { if (NULL == pVal) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
*pFuncId = *(int32_t*)pVal;
if (*pFuncId < 0 || *pFuncId >= funcMgtBuiltinsNum) { if (*pFuncId < 0 || *pFuncId >= funcMgtBuiltinsNum) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
......
...@@ -2,7 +2,7 @@ aux_source_directory(src NODES_SRC) ...@@ -2,7 +2,7 @@ aux_source_directory(src NODES_SRC)
add_library(nodes STATIC ${NODES_SRC}) add_library(nodes STATIC ${NODES_SRC})
target_include_directories( target_include_directories(
nodes nodes
PUBLIC "${CMAKE_SOURCE_DIR}/include/nodes" PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/nodes"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
) )
target_link_libraries( target_link_libraries(
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "nodes.h" #include "querynodes.h"
#define COMPARE_SCALAR_FIELD(fldname) \ #define COMPARE_SCALAR_FIELD(fldname) \
do { \ do { \
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "nodes.h" #include "querynodes.h"
#include "nodesShowStmts.h" #include "nodesShowStmts.h"
#include "taoserror.h" #include "taoserror.h"
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册