提交 9f140cec 编写于 作者: D dapan1121

Merge remote-tracking branch 'origin/3.0_query_integrate' into feature/scheduler

...@@ -10,3 +10,6 @@ ...@@ -10,3 +10,6 @@
[submodule "deps/TSZ"] [submodule "deps/TSZ"]
path = deps/TSZ path = deps/TSZ
url = https://github.com/taosdata/TSZ.git url = https://github.com/taosdata/TSZ.git
[submodule "examples/rust"]
path = examples/rust
url = https://github.com/songtianyi/tdengine-rust-bindings.git
...@@ -377,7 +377,7 @@ void printConf(SRaftServerConfig *pConf) { ...@@ -377,7 +377,7 @@ void printConf(SRaftServerConfig *pConf) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
srand(time(NULL)); taosSeedRand(time(NULL));
int32_t ret; int32_t ret;
exe_name = argv[0]; exe_name = argv[0];
......
...@@ -132,7 +132,7 @@ static void proposeValue(struct raft *r) { ...@@ -132,7 +132,7 @@ static void proposeValue(struct raft *r) {
buf.base = raft_malloc(buf.len); buf.base = raft_malloc(buf.len);
// mock ts value // mock ts value
int vid = rand() % VNODE_COUNT; int vid = taosRand() % VNODE_COUNT;
snprintf(buf.base, buf.len, "%d:value_%ld", vid, time(NULL)); snprintf(buf.base, buf.len, "%d:value_%ld", vid, time(NULL));
printf("propose value: %s \n", (char*)buf.base); printf("propose value: %s \n", (char*)buf.base);
...@@ -174,7 +174,7 @@ void usage() { ...@@ -174,7 +174,7 @@ void usage() {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
srand(time(NULL)); taosSeedRand(time(NULL));
exe_name = argv[0]; exe_name = argv[0];
if (argc < 2) { if (argc < 2) {
......
...@@ -19,7 +19,7 @@ void shuffle(char**lines, size_t n) ...@@ -19,7 +19,7 @@ void shuffle(char**lines, size_t n)
size_t i; size_t i;
for (i = 0; i < n - 1; i++) for (i = 0; i < n - 1; i++)
{ {
size_t j = i + rand() / (RAND_MAX / (n - i) + 1); size_t j = i + taosRand() / (RAND_MAX / (n - i) + 1);
char* t = lines[j]; char* t = lines[j];
lines[j] = lines[i]; lines[j] = lines[i];
lines[i] = t; lines[i] = t;
......
Subproject commit 1c8924dc668e6aa848214c2fc54e3ace3f5bf8df
...@@ -56,6 +56,11 @@ typedef enum { ...@@ -56,6 +56,11 @@ typedef enum {
TSDB_STATIS_NONE = 1, // statis part not exist TSDB_STATIS_NONE = 1, // statis part not exist
} ETsdbStatisStatus; } ETsdbStatisStatus;
typedef enum {
TSDB_SMA_STAT_OK = 0, // ready to provide service
TSDB_SMA_STAT_EXPIRED = 1, // not ready or expired
} ETsdbSmaStat;
extern char *qtypeStr[]; extern char *qtypeStr[];
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -56,7 +56,7 @@ typedef struct SColumnDataAgg { ...@@ -56,7 +56,7 @@ typedef struct SColumnDataAgg {
typedef struct SDataBlockInfo { typedef struct SDataBlockInfo {
STimeWindow window; STimeWindow window;
int32_t rows; int32_t rows;
int32_t tupleSize; int32_t rowSize;
int32_t numOfCols; int32_t numOfCols;
union {int64_t uid; int64_t blockId;}; union {int64_t uid; int64_t blockId;};
} SDataBlockInfo; } SDataBlockInfo;
...@@ -70,9 +70,9 @@ typedef struct SConstantItem { ...@@ -70,9 +70,9 @@ typedef struct SConstantItem {
// info.numOfCols = taosArrayGetSize(pDataBlock) + taosArrayGetSize(pConstantList); // info.numOfCols = taosArrayGetSize(pDataBlock) + taosArrayGetSize(pConstantList);
typedef struct SSDataBlock { typedef struct SSDataBlock {
SColumnDataAgg* pBlockAgg; SColumnDataAgg *pBlockAgg;
SArray* pDataBlock; // SArray<SColumnInfoData> SArray *pDataBlock; // SArray<SColumnInfoData>
SArray* pConstantList; // SArray<SConstantItem>, it is a constant/tags value of the corresponding result value. SArray *pConstantList; // SArray<SConstantItem>, it is a constant/tags value of the corresponding result value.
SDataBlockInfo info; SDataBlockInfo info;
} SSDataBlock; } SSDataBlock;
...@@ -136,7 +136,7 @@ static FORCE_INLINE void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock) ...@@ -136,7 +136,7 @@ static FORCE_INLINE void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock)
return (void*)buf; return (void*)buf;
} }
static FORCE_INLINE int32_t tEncodeSMqConsumeRsp(void** buf, const SMqConsumeRsp* pRsp) { static FORCE_INLINE int32_t tEncodeSMqPollRsp(void** buf, const SMqPollRsp* pRsp) {
int32_t tlen = 0; int32_t tlen = 0;
int32_t sz = 0; int32_t sz = 0;
tlen += taosEncodeFixedI64(buf, pRsp->consumerId); tlen += taosEncodeFixedI64(buf, pRsp->consumerId);
...@@ -157,7 +157,7 @@ static FORCE_INLINE int32_t tEncodeSMqConsumeRsp(void** buf, const SMqConsumeRsp ...@@ -157,7 +157,7 @@ static FORCE_INLINE int32_t tEncodeSMqConsumeRsp(void** buf, const SMqConsumeRsp
return tlen; return tlen;
} }
static FORCE_INLINE void* tDecodeSMqConsumeRsp(void* buf, SMqConsumeRsp* pRsp) { static FORCE_INLINE void* tDecodeSMqPollRsp(void* buf, SMqPollRsp* pRsp) {
int32_t sz; int32_t sz;
buf = taosDecodeFixedI64(buf, &pRsp->consumerId); buf = taosDecodeFixedI64(buf, &pRsp->consumerId);
buf = taosDecodeFixedI64(buf, &pRsp->reqOffset); buf = taosDecodeFixedI64(buf, &pRsp->reqOffset);
...@@ -195,7 +195,7 @@ static FORCE_INLINE void tDeleteSSDataBlock(SSDataBlock* pBlock) { ...@@ -195,7 +195,7 @@ static FORCE_INLINE void tDeleteSSDataBlock(SSDataBlock* pBlock) {
// tfree(pBlock); // tfree(pBlock);
} }
static FORCE_INLINE void tDeleteSMqConsumeRsp(SMqConsumeRsp* pRsp) { static FORCE_INLINE void tDeleteSMqConsumeRsp(SMqPollRsp* pRsp) {
if (pRsp->schemas) { if (pRsp->schemas) {
if (pRsp->schemas->nCols) { if (pRsp->schemas->nCols) {
tfree(pRsp->schemas->pSchema); tfree(pRsp->schemas->pSchema);
...@@ -218,18 +218,17 @@ typedef struct SColumn { ...@@ -218,18 +218,17 @@ typedef struct SColumn {
int64_t dataBlockId; int64_t dataBlockId;
}; };
char name[TSDB_COL_NAME_LEN];
int8_t flag; // column type: normal column, tag, or user-input column (integer/float/string)
union { union {
int16_t colId; int16_t colId;
int16_t slotId; int16_t slotId;
}; };
char name[TSDB_COL_NAME_LEN];
int8_t flag; // column type: normal column, tag, or user-input column (integer/float/string)
int16_t type; int16_t type;
int32_t bytes; int32_t bytes;
uint8_t precision; uint8_t precision;
uint8_t scale; uint8_t scale;
// SColumnInfo info;
} SColumn; } SColumn;
typedef struct SLimit { typedef struct SLimit {
...@@ -254,12 +253,20 @@ typedef struct SFunctParam { ...@@ -254,12 +253,20 @@ typedef struct SFunctParam {
} SFunctParam; } SFunctParam;
// the structure for sql function in select clause // the structure for sql function in select clause
typedef struct SResSchame {
int8_t type;
int32_t colId;
int32_t bytes;
int32_t precision;
int32_t scale;
char name[TSDB_COL_NAME_LEN];
} SResSchema;
// TODO move away to executor.h
typedef struct SExprBasicInfo { typedef struct SExprBasicInfo {
SSchema resSchema; // TODO refactor SResSchema resSchema;
int32_t interBytes; // inter result buffer size, TODO remove it
int16_t numOfParams; // argument value of each function int16_t numOfParams; // argument value of each function
SFunctParam *pParam; SFunctParam *pParam;
// SVariant param[3]; // parameters are not more than 3
} SExprBasicInfo; } SExprBasicInfo;
typedef struct SExprInfo { typedef struct SExprInfo {
......
...@@ -777,7 +777,7 @@ typedef struct SVgroupInfo { ...@@ -777,7 +777,7 @@ typedef struct SVgroupInfo {
int32_t vgId; int32_t vgId;
uint32_t hashBegin; uint32_t hashBegin;
uint32_t hashEnd; uint32_t hashEnd;
SEpSet epset; SEpSet epSet;
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
} SVgroupInfo; } SVgroupInfo;
...@@ -2101,7 +2101,7 @@ typedef struct { ...@@ -2101,7 +2101,7 @@ typedef struct {
int32_t skipLogNum; int32_t skipLogNum;
int32_t numOfTopics; int32_t numOfTopics;
SArray* pBlockData; // SArray<SSDataBlock> SArray* pBlockData; // SArray<SSDataBlock>
} SMqConsumeRsp; } SMqPollRsp;
// one req for one vg+topic // one req for one vg+topic
typedef struct { typedef struct {
...@@ -2114,7 +2114,7 @@ typedef struct { ...@@ -2114,7 +2114,7 @@ typedef struct {
int64_t currentOffset; int64_t currentOffset;
char topic[TSDB_TOPIC_FNAME_LEN]; char topic[TSDB_TOPIC_FNAME_LEN];
} SMqConsumeReq; } SMqPollReq;
typedef struct { typedef struct {
int32_t vgId; int32_t vgId;
...@@ -2136,7 +2136,7 @@ typedef struct { ...@@ -2136,7 +2136,7 @@ typedef struct {
struct tmq_message_t { struct tmq_message_t {
SMqRspHead head; SMqRspHead head;
union { union {
SMqConsumeRsp consumeRsp; SMqPollRsp consumeRsp;
SMqCMGetSubEpRsp getEpRsp; SMqCMGetSubEpRsp getEpRsp;
}; };
void* extra; void* extra;
......
...@@ -132,11 +132,11 @@ struct SqlFunctionCtx; ...@@ -132,11 +132,11 @@ struct SqlFunctionCtx;
struct SResultRowEntryInfo; struct SResultRowEntryInfo;
//for selectivity query, the corresponding tag value is assigned if the data is qualified //for selectivity query, the corresponding tag value is assigned if the data is qualified
typedef struct SExtTagsInfo { typedef struct SSubsidiaryResInfo {
int16_t tagsLen; // keep the tags data for top/bottom query result int16_t bufLen; // keep the tags data for top/bottom query result
int16_t numOfTagCols; int16_t numOfCols;
struct SqlFunctionCtx **pTagCtxList; struct SqlFunctionCtx **pCtx;
} SExtTagsInfo; } SSubsidiaryResInfo;
typedef struct SResultDataInfo { typedef struct SResultDataInfo {
int16_t precision; int16_t precision;
...@@ -187,7 +187,7 @@ typedef struct SqlFunctionCtx { ...@@ -187,7 +187,7 @@ typedef struct SqlFunctionCtx {
void *ptsOutputBuf; // corresponding output buffer for timestamp of each result, e.g., top/bottom*/ void *ptsOutputBuf; // corresponding output buffer for timestamp of each result, e.g., top/bottom*/
SVariant tag; SVariant tag;
struct SResultRowEntryInfo *resultInfo; struct SResultRowEntryInfo *resultInfo;
SExtTagsInfo tagInfo; SSubsidiaryResInfo subsidiaryRes;
SPoint1 start; SPoint1 start;
SPoint1 end; SPoint1 end;
SFuncExecFuncs fpSet; SFuncExecFuncs fpSet;
......
...@@ -66,6 +66,7 @@ typedef enum ENodeType { ...@@ -66,6 +66,7 @@ typedef enum ENodeType {
QUERY_NODE_DATABLOCK_DESC, QUERY_NODE_DATABLOCK_DESC,
QUERY_NODE_SLOT_DESC, QUERY_NODE_SLOT_DESC,
QUERY_NODE_COLUMN_DEF, QUERY_NODE_COLUMN_DEF,
QUERY_NODE_DOWNSTREAM_SOURCE,
// Statement nodes are used in parser and planner module. // Statement nodes are used in parser and planner module.
QUERY_NODE_SET_OPERATOR, QUERY_NODE_SET_OPERATOR,
...@@ -98,6 +99,7 @@ typedef enum ENodeType { ...@@ -98,6 +99,7 @@ typedef enum ENodeType {
QUERY_NODE_LOGIC_PLAN_AGG, QUERY_NODE_LOGIC_PLAN_AGG,
QUERY_NODE_LOGIC_PLAN_PROJECT, QUERY_NODE_LOGIC_PLAN_PROJECT,
QUERY_NODE_LOGIC_PLAN_VNODE_MODIF, QUERY_NODE_LOGIC_PLAN_VNODE_MODIF,
QUERY_NODE_LOGIC_PLAN_EXCHANGE,
QUERY_NODE_LOGIC_SUBPLAN, QUERY_NODE_LOGIC_SUBPLAN,
QUERY_NODE_LOGIC_PLAN, QUERY_NODE_LOGIC_PLAN,
......
...@@ -22,6 +22,7 @@ extern "C" { ...@@ -22,6 +22,7 @@ extern "C" {
#include "querynodes.h" #include "querynodes.h"
#include "query.h" #include "query.h"
#include "tname.h"
typedef struct SLogicNode { typedef struct SLogicNode {
ENodeType type; ENodeType type;
...@@ -67,12 +68,17 @@ typedef struct SProjectLogicNode { ...@@ -67,12 +68,17 @@ typedef struct SProjectLogicNode {
} SProjectLogicNode; } SProjectLogicNode;
typedef struct SVnodeModifLogicNode { typedef struct SVnodeModifLogicNode {
ENodeType type;; SLogicNode node;;
int32_t msgType; int32_t msgType;
SArray* pDataBlocks; SArray* pDataBlocks;
SVgDataBlocks* pVgDataBlocks; SVgDataBlocks* pVgDataBlocks;
} SVnodeModifLogicNode; } SVnodeModifLogicNode;
typedef struct SExchangeLogicNode {
SLogicNode node;
int32_t srcGroupId;
} SExchangeLogicNode;
typedef enum ESubplanType { typedef enum ESubplanType {
SUBPLAN_TYPE_MERGE = 1, SUBPLAN_TYPE_MERGE = 1,
SUBPLAN_TYPE_PARTIAL, SUBPLAN_TYPE_PARTIAL,
...@@ -80,18 +86,28 @@ typedef enum ESubplanType { ...@@ -80,18 +86,28 @@ typedef enum ESubplanType {
SUBPLAN_TYPE_MODIFY SUBPLAN_TYPE_MODIFY
} ESubplanType; } ESubplanType;
typedef struct SSubplanId {
uint64_t queryId;
int32_t groupId;
int32_t subplanId;
} SSubplanId;
typedef struct SSubLogicPlan { typedef struct SSubLogicPlan {
ENodeType type; ENodeType type;
SSubplanId id;
SNodeList* pChildren; SNodeList* pChildren;
SNodeList* pParents; SNodeList* pParents;
SLogicNode* pNode; SLogicNode* pNode;
ESubplanType subplanType; ESubplanType subplanType;
SVgroupsInfo* pVgroupList;
int32_t level; int32_t level;
int32_t splitFlag;
} SSubLogicPlan; } SSubLogicPlan;
typedef struct SQueryLogicPlan { typedef struct SQueryLogicPlan {
ENodeType type; ENodeType type;
SNodeList* pSubplans; int32_t totalLevel;
SNodeList* pTopSubplans;
} SQueryLogicPlan; } SQueryLogicPlan;
typedef struct SSlotDescNode { typedef struct SSlotDescNode {
...@@ -161,20 +177,21 @@ typedef struct SAggPhysiNode { ...@@ -161,20 +177,21 @@ typedef struct SAggPhysiNode {
SNodeList* pAggFuncs; SNodeList* pAggFuncs;
} SAggPhysiNode; } SAggPhysiNode;
typedef struct SDownstreamSource { typedef struct SDownstreamSourceNode {
ENodeType type;
SQueryNodeAddr addr; SQueryNodeAddr addr;
uint64_t taskId; uint64_t taskId;
uint64_t schedId; uint64_t schedId;
} SDownstreamSource; } SDownstreamSourceNode;
typedef struct SExchangePhysiNode { typedef struct SExchangePhysiNode {
SPhysiNode node; SPhysiNode node;
uint64_t srcTemplateId; // template id of datasource suplans int32_t srcGroupId; // group id of datasource suplans
SArray* pSrcEndPoints; // SArray<SDownstreamSource>, scheduler fill by calling qSetSuplanExecutionNode SNodeList* pSrcEndPoints; // element is SDownstreamSource, scheduler fill by calling qSetSuplanExecutionNode
} SExchangePhysiNode; } SExchangePhysiNode;
typedef struct SDataSinkNode { typedef struct SDataSinkNode {
ENodeType type;; ENodeType type;
SDataBlockDescNode* pInputDataBlockDesc; SDataBlockDescNode* pInputDataBlockDesc;
} SDataSinkNode; } SDataSinkNode;
...@@ -189,12 +206,6 @@ typedef struct SDataInserterNode { ...@@ -189,12 +206,6 @@ typedef struct SDataInserterNode {
char *pData; char *pData;
} SDataInserterNode; } SDataInserterNode;
typedef struct SSubplanId {
uint64_t queryId;
int32_t templateId;
int32_t subplanId;
} SSubplanId;
typedef struct SSubplan { typedef struct SSubplan {
ENodeType type; ENodeType type;
SSubplanId id; // unique id of the subplan SSubplanId id; // unique id of the subplan
...@@ -213,7 +224,7 @@ typedef struct SQueryPlan { ...@@ -213,7 +224,7 @@ typedef struct SQueryPlan {
ENodeType type;; ENodeType type;;
uint64_t queryId; uint64_t queryId;
int32_t numOfSubplans; int32_t numOfSubplans;
SNodeList* pSubplans; // SNodeListNode. The execution level of subplan, starting from 0. SNodeList* pSubplans; // Element is SNodeListNode. The execution level of subplan, starting from 0.
} SQueryPlan; } SQueryPlan;
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -31,14 +31,14 @@ typedef struct SPlanContext { ...@@ -31,14 +31,14 @@ typedef struct SPlanContext {
int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNodeList); int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNodeList);
// Set datasource of this subplan, multiple calls may be made to a subplan. // Set datasource of this subplan, multiple calls may be made to a subplan.
// @subplan subplan to be schedule // @pSubplan subplan to be schedule
// @templateId templateId of a group of datasource subplans of this @subplan // @groupId id of a group of datasource subplans of this @pSubplan
// @ep one execution location of this group of datasource subplans // @pSource one execution location of this group of datasource subplans
void qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SDownstreamSource* pSource); int32_t qSetSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId, SDownstreamSourceNode* pSource);
// Convert to subplan to string for the scheduler to send to the executor // Convert to subplan to string for the scheduler to send to the executor
int32_t qSubPlanToString(const SSubplan* subplan, char** str, int32_t* len); int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen);
int32_t qStringToSubplan(const char* str, SSubplan** subplan); int32_t qStringToSubplan(const char* pStr, SSubplan** pSubplan);
char* qQueryPlanToString(const SQueryPlan* pPlan); char* qQueryPlanToString(const SQueryPlan* pPlan);
SQueryPlan* qStringToQueryPlan(const char* pStr); SQueryPlan* qStringToQueryPlan(const char* pStr);
......
...@@ -55,24 +55,26 @@ typedef struct STableComInfo { ...@@ -55,24 +55,26 @@ typedef struct STableComInfo {
* The cached child table meta info. For each child table, 24 bytes are required to keep the essential table info. * The cached child table meta info. For each child table, 24 bytes are required to keep the essential table info.
*/ */
typedef struct SCTableMeta { typedef struct SCTableMeta {
int32_t vgId:24; int32_t vgId : 24;
int8_t tableType; int8_t tableType;
uint64_t uid; uint64_t uid;
uint64_t suid; uint64_t suid;
} SCTableMeta; } SCTableMeta;
/* /*
* Note that the first 24 bytes of STableMeta are identical to SCTableMeta, it is safe to cast a STableMeta to be a SCTableMeta. * Note that the first 24 bytes of STableMeta are identical to SCTableMeta, it is safe to cast a STableMeta to be a
* SCTableMeta.
*/ */
typedef struct STableMeta { typedef struct STableMeta {
//BEGIN: KEEP THIS PART SAME WITH SCTableMeta // BEGIN: KEEP THIS PART SAME WITH SCTableMeta
int32_t vgId:24; int32_t vgId : 24;
int8_t tableType; int8_t tableType;
uint64_t uid; uint64_t uid;
uint64_t suid; uint64_t suid;
//END: KEEP THIS PART SAME WITH SCTableMeta // END: KEEP THIS PART SAME WITH SCTableMeta
// if the table is TSDB_CHILD_TABLE, the following information is acquired from the corresponding super table meta info // if the table is TSDB_CHILD_TABLE, the following information is acquired from the corresponding super table meta
// info
int16_t sversion; int16_t sversion;
int16_t tversion; int16_t tversion;
STableComInfo tableInfo; STableComInfo tableInfo;
...@@ -89,16 +91,10 @@ typedef struct SDBVgInfo { ...@@ -89,16 +91,10 @@ typedef struct 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;
SDBVgInfo *dbVgroup; SDBVgInfo* dbVgroup;
} SUseDbOutput; } SUseDbOutput;
enum { enum { META_TYPE_NULL_TABLE = 1, META_TYPE_CTABLE, META_TYPE_TABLE, META_TYPE_BOTH_TABLE };
META_TYPE_NULL_TABLE = 1,
META_TYPE_CTABLE,
META_TYPE_TABLE,
META_TYPE_BOTH_TABLE
};
typedef struct STableMetaOutput { typedef struct STableMetaOutput {
int32_t metaType; int32_t metaType;
...@@ -107,21 +103,21 @@ typedef struct STableMetaOutput { ...@@ -107,21 +103,21 @@ typedef struct STableMetaOutput {
char ctbName[TSDB_TABLE_NAME_LEN]; char ctbName[TSDB_TABLE_NAME_LEN];
char tbName[TSDB_TABLE_NAME_LEN]; char tbName[TSDB_TABLE_NAME_LEN];
SCTableMeta ctbMeta; SCTableMeta ctbMeta;
STableMeta *tbMeta; STableMeta* tbMeta;
} STableMetaOutput; } STableMetaOutput;
typedef struct SDataBuf { typedef struct SDataBuf {
void *pData; void* pData;
uint32_t len; uint32_t len;
void *handle; void* handle;
} SDataBuf; } SDataBuf;
typedef int32_t (*__async_send_cb_fn_t)(void* param, const SDataBuf* pMsg, int32_t code); typedef int32_t (*__async_send_cb_fn_t)(void* param, const SDataBuf* pMsg, int32_t code);
typedef int32_t (*__async_exec_fn_t)(void* param); typedef int32_t (*__async_exec_fn_t)(void* param);
typedef struct SMsgSendInfo { typedef struct SMsgSendInfo {
__async_send_cb_fn_t fp; //async callback function __async_send_cb_fn_t fp; // async callback function
void *param; void* param;
uint64_t requestId; uint64_t requestId;
uint64_t requestObjRefId; uint64_t requestObjRefId;
int32_t msgType; int32_t msgType;
...@@ -130,7 +126,7 @@ typedef struct SMsgSendInfo { ...@@ -130,7 +126,7 @@ typedef struct SMsgSendInfo {
typedef struct SQueryNodeAddr { typedef struct SQueryNodeAddr {
int32_t nodeId; // vgId or qnodeId int32_t nodeId; // vgId or qnodeId
SEpSet epset; SEpSet epSet;
} SQueryNodeAddr; } SQueryNodeAddr;
...@@ -164,22 +160,21 @@ int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code); ...@@ -164,22 +160,21 @@ int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code);
* @param pInfo * @param pInfo
* @return * @return
*/ */
int32_t asyncSendMsgToServer(void *pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo); int32_t asyncSendMsgToServer(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo);
int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp); int32_t queryBuildUseDbOutput(SUseDbOutput* pOut, SUseDbRsp* usedbRsp);
void initQueryModuleMsgHandle(); void initQueryModuleMsgHandle();
const SSchema* tGetTbnameColumnSchema(); const SSchema* tGetTbnameColumnSchema();
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags); bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);
int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STableMeta **pMeta); int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STableMeta** pMeta);
SSchema createSchema(uint8_t type, int32_t bytes, int32_t colId, const char* name); SSchema createSchema(uint8_t type, int32_t bytes, int32_t colId, const char* name);
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char** msg, int32_t msgSize, int32_t* msgLen);
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen); extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t msgSize);
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t msgSize);
#define SET_META_TYPE_NULL(t) (t) = META_TYPE_NULL_TABLE #define SET_META_TYPE_NULL(t) (t) = META_TYPE_NULL_TABLE
#define SET_META_TYPE_CTABLE(t) (t) = META_TYPE_CTABLE #define SET_META_TYPE_CTABLE(t) (t) = META_TYPE_CTABLE
...@@ -189,14 +184,48 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t ...@@ -189,14 +184,48 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t
#define IS_CLIENT_RETRY_ERROR(_code) ((_code) == TSDB_CODE_VND_HASH_MISMATCH) #define IS_CLIENT_RETRY_ERROR(_code) ((_code) == TSDB_CODE_VND_HASH_MISMATCH)
#define IS_SCHEDULER_RETRY_ERROR(_code) ((_code) == TSDB_CODE_RPC_REDIRECT) #define IS_SCHEDULER_RETRY_ERROR(_code) ((_code) == TSDB_CODE_RPC_REDIRECT)
#define qFatal(...) \
#define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", DEBUG_FATAL, qDebugFlag, __VA_ARGS__); }} while(0) do { \
#define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", DEBUG_ERROR, qDebugFlag, __VA_ARGS__); }} while(0) if (qDebugFlag & DEBUG_FATAL) { \
#define qWarn(...) do { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", DEBUG_WARN, qDebugFlag, __VA_ARGS__); }} while(0) taosPrintLog("QRY FATAL ", DEBUG_FATAL, qDebugFlag, __VA_ARGS__); \
#define qInfo(...) do { if (qDebugFlag & DEBUG_INFO) { taosPrintLog("QRY ", DEBUG_INFO, qDebugFlag, __VA_ARGS__); }} while(0) } \
#define qDebug(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); }} while(0) } while (0)
#define qTrace(...) do { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY ", DEBUG_TRACE, qDebugFlag, __VA_ARGS__); }} while(0) #define qError(...) \
#define qDebugL(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLongString("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); }} while(0) do { \
if (qDebugFlag & DEBUG_ERROR) { \
taosPrintLog("QRY ERROR ", DEBUG_ERROR, qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define qWarn(...) \
do { \
if (qDebugFlag & DEBUG_WARN) { \
taosPrintLog("QRY WARN ", DEBUG_WARN, qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define qInfo(...) \
do { \
if (qDebugFlag & DEBUG_INFO) { \
taosPrintLog("QRY ", DEBUG_INFO, qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define qDebug(...) \
do { \
if (qDebugFlag & DEBUG_DEBUG) { \
taosPrintLog("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define qTrace(...) \
do { \
if (qDebugFlag & DEBUG_TRACE) { \
taosPrintLog("QRY ", DEBUG_TRACE, qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define qDebugL(...) \
do { \
if (qDebugFlag & DEBUG_DEBUG) { \
taosPrintLongString("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -31,9 +31,9 @@ typedef int64_t SyncIndex; ...@@ -31,9 +31,9 @@ typedef int64_t SyncIndex;
typedef uint64_t SyncTerm; typedef uint64_t SyncTerm;
typedef enum { typedef enum {
TAOS_SYNC_STATE_FOLLOWER = 0, TAOS_SYNC_STATE_FOLLOWER = 100,
TAOS_SYNC_STATE_CANDIDATE = 1, TAOS_SYNC_STATE_CANDIDATE = 101,
TAOS_SYNC_STATE_LEADER = 2, TAOS_SYNC_STATE_LEADER = 102,
} ESyncState; } ESyncState;
typedef struct SSyncBuffer { typedef struct SSyncBuffer {
...@@ -134,6 +134,7 @@ typedef struct SSyncInfo { ...@@ -134,6 +134,7 @@ typedef struct SSyncInfo {
SyncGroupId vgId; SyncGroupId vgId;
SSyncCfg syncCfg; SSyncCfg syncCfg;
char path[TSDB_FILENAME_LEN]; char path[TSDB_FILENAME_LEN];
char walPath[TSDB_FILENAME_LEN];
SSyncFSM* pFsm; SSyncFSM* pFsm;
void* rpcClient; void* rpcClient;
......
...@@ -16,10 +16,24 @@ ...@@ -16,10 +16,24 @@
#ifndef _TD_OS_DIR_H_ #ifndef _TD_OS_DIR_H_
#define _TD_OS_DIR_H_ #define _TD_OS_DIR_H_
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define opendir OPENDIR_FUNC_TAOS_FORBID
#define readdir READDIR_FUNC_TAOS_FORBID
#define closedir CLOSEDIR_FUNC_TAOS_FORBID
#define dirname DIRNAME_FUNC_TAOS_FORBID
#undef basename
#define basename BASENAME_FUNC_TAOS_FORBID
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef struct TdDir *TdDirPtr;
typedef struct TdDirEntry *TdDirEntryPtr;
void taosRemoveDir(const char *dirname); void taosRemoveDir(const char *dirname);
bool taosDirExist(char *dirname); bool taosDirExist(char *dirname);
int32_t taosMkDir(const char *dirname); int32_t taosMkDir(const char *dirname);
...@@ -27,6 +41,14 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays); ...@@ -27,6 +41,14 @@ void taosRemoveOldFiles(const char *dirname, int32_t keepDays);
int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen); int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen);
int32_t taosRealPath(char *dirname, int32_t maxlen); int32_t taosRealPath(char *dirname, int32_t maxlen);
bool taosIsDir(const char *dirname); bool taosIsDir(const char *dirname);
char* taosDirName(char *dirname);
char* taosDirEntryBaseName(char *dirname);
TdDirPtr taosOpenDir(const char *dirname);
TdDirEntryPtr taosReadDir(TdDirPtr pDir);
bool taosDirEntryIsDir(TdDirEntryPtr pDirEntry);
char* taosGetDirEntryName(TdDirEntryPtr pDirEntry);
int32_t taosCloseDir(TdDirPtr pDir);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -20,7 +20,16 @@ ...@@ -20,7 +20,16 @@
extern "C" { extern "C" {
#endif #endif
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define rand RAND_FUNC_TAOS_FORBID
#define srand SRAND_FUNC_TAOS_FORBID
#define rand_r RANDR_FUNC_TAOS_FORBID
#endif
void taosSeedRand(uint32_t seed);
uint32_t taosRand(void); uint32_t taosRand(void);
uint32_t taosRandR(uint32_t *pSeed);
void taosRandStr(char* str, int32_t size); void taosRandStr(char* str, int32_t size);
uint32_t taosSafeRand(void); uint32_t taosSafeRand(void);
......
...@@ -21,7 +21,10 @@ ...@@ -21,7 +21,10 @@
#define socket SOCKET_FUNC_TAOS_FORBID #define socket SOCKET_FUNC_TAOS_FORBID
#define bind BIND_FUNC_TAOS_FORBID #define bind BIND_FUNC_TAOS_FORBID
#define listen LISTEN_FUNC_TAOS_FORBID #define listen LISTEN_FUNC_TAOS_FORBID
// #define accept ACCEPT_FUNC_TAOS_FORBID #define accept ACCEPT_FUNC_TAOS_FORBID
#define epoll_create EPOLL_CREATE_FUNC_TAOS_FORBID
#define epoll_ctl EPOLL_CTL_FUNC_TAOS_FORBID
#define epoll_wait EPOLL_WAIT_FUNC_TAOS_FORBID
#endif #endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
...@@ -38,31 +41,6 @@ ...@@ -38,31 +41,6 @@
extern "C" { extern "C" {
#endif #endif
#define TAOS_EPOLL_WAIT_TIME 500
typedef int32_t SOCKET;
typedef SOCKET EpollFd;
#define EpollClose(pollFd) taosCloseSocket(pollFd)
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
typedef SOCKET SocketFd;
#else
typedef int32_t SocketFd;
#endif
int32_t taosSendto(SocketFd fd, void * msg, int len, unsigned int flags, const struct sockaddr * to, int tolen);
int32_t taosWriteSocket(SocketFd fd, void *msg, int len);
int32_t taosReadSocket(SocketFd fd, void *msg, int len);
int32_t taosCloseSocketNoCheck(SocketFd fd);
int32_t taosCloseSocket(SocketFd fd);
void taosShutDownSocketRD(SOCKET fd);
void taosShutDownSocketWR(SOCKET fd);
int32_t taosSetNonblocking(SOCKET sock, int32_t on);
int32_t taosSetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t optlen);
int32_t taosGetSockOpt(SOCKET socketfd, int32_t level, int32_t optname, void *optval, int32_t *optlen);
uint32_t taosInetAddr(const char *ipAddr);
const char *taosInetNtoa(struct in_addr ipInt);
#if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)) #if (defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32))
#define htobe64 htonll #define htobe64 htonll
#if defined(_TD_GO_DLL_) #if defined(_TD_GO_DLL_)
...@@ -74,17 +52,39 @@ const char *taosInetNtoa(struct in_addr ipInt); ...@@ -74,17 +52,39 @@ const char *taosInetNtoa(struct in_addr ipInt);
#define htobe64 htonll #define htobe64 htonll
#endif #endif
int32_t taosReadn(SOCKET sock, char *buffer, int32_t len); #define TAOS_EPOLL_WAIT_TIME 500
int32_t taosWriteMsg(SOCKET fd, void *ptr, int32_t nbytes);
int32_t taosReadMsg(SOCKET fd, void *ptr, int32_t nbytes); typedef struct TdSocketServer *TdSocketServerPtr;
int32_t taosNonblockwrite(SOCKET fd, char *ptr, int32_t nbytes); typedef struct TdSocket *TdSocketPtr;
int64_t taosCopyFds(SOCKET sfd, int32_t dfd, int64_t len); typedef struct TdEpoll *TdEpollPtr;
int32_t taosSetNonblocking(SOCKET sock, int32_t on);
int32_t taosSendto(TdSocketPtr pSocket, void * msg, int len, unsigned int flags, const struct sockaddr * to, int tolen);
int32_t taosWriteSocket(TdSocketPtr pSocket, void *msg, int len);
int32_t taosReadSocket(TdSocketPtr pSocket, void *msg, int len);
int32_t taosReadFromSocket(TdSocketPtr pSocket, void *buf, int32_t len, int32_t flags, struct sockaddr *destAddr, socklen_t *addrLen);
int32_t taosCloseSocket(TdSocketPtr *ppSocket);
int32_t taosCloseSocketServer(TdSocketServerPtr *ppSocketServer);
int32_t taosShutDownSocketRD(TdSocketPtr pSocket);
int32_t taosShutDownSocketServerRD(TdSocketServerPtr pSocketServer);
int32_t taosShutDownSocketWR(TdSocketPtr pSocket);
int32_t taosShutDownSocketServerWR(TdSocketServerPtr pSocketServer);
int32_t taosShutDownSocketRDWR(TdSocketPtr pSocket);
int32_t taosShutDownSocketServerRDWR(TdSocketServerPtr pSocketServer);
int32_t taosSetNonblocking(TdSocketPtr pSocket, int32_t on);
int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t optlen);
int32_t taosGetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t *optlen);
int32_t taosWriteMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
int32_t taosReadMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes);
int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len);
SOCKET taosOpenUdpSocket(uint32_t localIp, uint16_t localPort); TdSocketPtr taosOpenUdpSocket(uint32_t localIp, uint16_t localPort);
SOCKET taosOpenTcpClientSocket(uint32_t ip, uint16_t port, uint32_t localIp); TdSocketPtr taosOpenTcpClientSocket(uint32_t ip, uint16_t port, uint32_t localIp);
SOCKET taosOpenTcpServerSocket(uint32_t ip, uint16_t port); TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port);
int32_t taosKeepTcpAlive(SOCKET sockFd); int32_t taosKeepTcpAlive(TdSocketPtr pSocket);
TdSocketPtr taosAcceptTcpConnectSocket(TdSocketServerPtr pServerSocket, struct sockaddr *destAddr, socklen_t *addrLen);
int32_t taosGetSocketName(TdSocketPtr pSocket,struct sockaddr *destAddr, socklen_t *addrLen);
void taosBlockSIGPIPE(); void taosBlockSIGPIPE();
uint32_t taosGetIpv4FromFqdn(const char *); uint32_t taosGetIpv4FromFqdn(const char *);
...@@ -93,6 +93,13 @@ void tinet_ntoa(char *ipstr, uint32_t ip); ...@@ -93,6 +93,13 @@ void tinet_ntoa(char *ipstr, uint32_t ip);
uint32_t ip2uint(const char *const ip_addr); uint32_t ip2uint(const char *const ip_addr);
void taosIgnSIGPIPE(); void taosIgnSIGPIPE();
void taosSetMaskSIGPIPE(); void taosSetMaskSIGPIPE();
uint32_t taosInetAddr(const char *ipAddr);
const char *taosInetNtoa(struct in_addr ipInt);
TdEpollPtr taosCreateEpoll(int32_t size);
int32_t taosCtlEpoll(TdEpollPtr pEpoll, int32_t epollOperate, TdSocketPtr pSocket, struct epoll_event *event);
int32_t taosWaitEpoll(TdEpollPtr pEpoll, struct epoll_event *event, int32_t maxEvents, int32_t timeout);
int32_t taosCloseEpoll(TdEpollPtr *ppEpoll);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -33,6 +33,7 @@ typedef struct { ...@@ -33,6 +33,7 @@ typedef struct {
SDiskSize size; SDiskSize size;
} SDiskSpace; } SDiskSpace;
bool taosCheckSystemIsSmallEnd();
void taosGetSystemInfo(); void taosGetSystemInfo();
int32_t taosGetEmail(char *email, int32_t maxLen); int32_t taosGetEmail(char *email, int32_t maxLen);
int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen); int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen);
......
...@@ -208,7 +208,7 @@ void taos_init_imp(void) { ...@@ -208,7 +208,7 @@ void taos_init_imp(void) {
atexit(taos_cleanup); atexit(taos_cleanup);
errno = TSDB_CODE_SUCCESS; errno = TSDB_CODE_SUCCESS;
srand(taosGetTimestampSec()); taosSeedRand(taosGetTimestampSec());
deltaToUtcInitOnce(); deltaToUtcInitOnce();
......
...@@ -173,6 +173,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { ...@@ -173,6 +173,7 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
SCmdMsgInfo* pMsgInfo = pQuery->pCmdMsg; SCmdMsgInfo* pMsgInfo = pQuery->pCmdMsg;
pRequest->type = pMsgInfo->msgType; pRequest->type = pMsgInfo->msgType;
pRequest->body.requestMsg = (SDataBuf){.pData = pMsgInfo->pMsg, .len = pMsgInfo->msgLen, .handle = NULL}; pRequest->body.requestMsg = (SDataBuf){.pData = pMsgInfo->pMsg, .len = pMsgInfo->msgLen, .handle = NULL};
pMsgInfo->pMsg = NULL; // pMsg transferred to SMsgSendInfo management
STscObj* pTscObj = pRequest->pTscObj; STscObj* pTscObj = pRequest->pTscObj;
SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest); SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest);
...@@ -243,7 +244,7 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList ...@@ -243,7 +244,7 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
SRequestObj* execQueryImpl(STscObj* pTscObj, const char* sql, int sqlLen) { SRequestObj* execQueryImpl(STscObj* pTscObj, const char* sql, int sqlLen) {
SRequestObj* pRequest = NULL; SRequestObj* pRequest = NULL;
SQuery* pQuery; SQuery* pQuery = NULL;
SArray* pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr)); SArray* pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr));
terrno = TSDB_CODE_SUCCESS; terrno = TSDB_CODE_SUCCESS;
...@@ -589,7 +590,7 @@ void* doFetchRow(SRequestObj* pRequest) { ...@@ -589,7 +590,7 @@ void* doFetchRow(SRequestObj* pRequest) {
SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo; SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo;
SVgroupInfo* pVgroupInfo = taosArrayGet(pShowReqInfo->pArray, pShowReqInfo->currentIndex); SVgroupInfo* pVgroupInfo = taosArrayGet(pShowReqInfo->pArray, pShowReqInfo->currentIndex);
epSet = pVgroupInfo->epset; epSet = pVgroupInfo->epSet;
} else if (pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) { } else if (pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) {
pRequest->type = TDMT_VND_SHOW_TABLES; pRequest->type = TDMT_VND_SHOW_TABLES;
SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo; SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo;
...@@ -606,7 +607,7 @@ void* doFetchRow(SRequestObj* pRequest) { ...@@ -606,7 +607,7 @@ void* doFetchRow(SRequestObj* pRequest) {
pRequest->body.requestMsg.pData = pShowReq; pRequest->body.requestMsg.pData = pShowReq;
SMsgSendInfo* body = buildMsgInfoImpl(pRequest); SMsgSendInfo* body = buildMsgInfoImpl(pRequest);
epSet = pVgroupInfo->epset; epSet = pVgroupInfo->epSet;
int64_t transporterId = 0; int64_t transporterId = 0;
STscObj* pTscObj = pRequest->pTscObj; STscObj* pTscObj = pRequest->pTscObj;
......
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define _DEFAULT_SOURCE
#include "clientInt.h" #include "clientInt.h"
#include "clientLog.h" #include "clientLog.h"
#include "parser.h" #include "parser.h"
...@@ -606,7 +604,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { ...@@ -606,7 +604,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) { int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) {
if (tmq_message == NULL) return 0; if (tmq_message == NULL) return 0;
SMqConsumeRsp* pRsp = &tmq_message->consumeRsp; SMqPollRsp* pRsp = &tmq_message->consumeRsp;
return pRsp->skipLogNum; return pRsp->skipLogNum;
} }
...@@ -615,7 +613,7 @@ void tmqShowMsg(tmq_message_t* tmq_message) { ...@@ -615,7 +613,7 @@ void tmqShowMsg(tmq_message_t* tmq_message) {
static bool noPrintSchema; static bool noPrintSchema;
char pBuf[128]; char pBuf[128];
SMqConsumeRsp* pRsp = &tmq_message->consumeRsp; SMqPollRsp* pRsp = &tmq_message->consumeRsp;
int32_t colNum = pRsp->schemas->nCols; int32_t colNum = pRsp->schemas->nCols;
if (!noPrintSchema) { if (!noPrintSchema) {
printf("|"); printf("|");
...@@ -703,7 +701,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { ...@@ -703,7 +701,7 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
goto WRITE_QUEUE_FAIL; goto WRITE_QUEUE_FAIL;
} }
memcpy(pRsp, pMsg->pData, sizeof(SMqRspHead)); memcpy(pRsp, pMsg->pData, sizeof(SMqRspHead));
tDecodeSMqConsumeRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRsp->consumeRsp); tDecodeSMqPollRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRsp->consumeRsp);
/*printf("rsp commit off:%ld rsp off:%ld has data:%d\n", pRsp->committedOffset, pRsp->rspOffset, pRsp->numOfTopics);*/ /*printf("rsp commit off:%ld rsp off:%ld has data:%d\n", pRsp->committedOffset, pRsp->rspOffset, pRsp->numOfTopics);*/
if (pRsp->consumeRsp.numOfTopics == 0) { if (pRsp->consumeRsp.numOfTopics == 0) {
/*printf("no data\n");*/ /*printf("no data\n");*/
...@@ -874,7 +872,7 @@ tmq_resp_err_t tmq_seek(tmq_t* tmq, const tmq_topic_vgroup_t* offset) { ...@@ -874,7 +872,7 @@ tmq_resp_err_t tmq_seek(tmq_t* tmq, const tmq_topic_vgroup_t* offset) {
return TMQ_RESP_ERR__FAIL; return TMQ_RESP_ERR__FAIL;
} }
SMqConsumeReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTopic* pTopic, SMqClientVg* pVg) { SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTopic* pTopic, SMqClientVg* pVg) {
int64_t reqOffset; int64_t reqOffset;
if (pVg->currentOffset >= 0) { if (pVg->currentOffset >= 0) {
reqOffset = pVg->currentOffset; reqOffset = pVg->currentOffset;
...@@ -886,7 +884,7 @@ SMqConsumeReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClien ...@@ -886,7 +884,7 @@ SMqConsumeReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClien
reqOffset = tmq->resetOffsetCfg; reqOffset = tmq->resetOffsetCfg;
} }
SMqConsumeReq* pReq = malloc(sizeof(SMqConsumeReq)); SMqPollReq* pReq = malloc(sizeof(SMqPollReq));
if (pReq == NULL) { if (pReq == NULL) {
return NULL; return NULL;
} }
...@@ -900,7 +898,7 @@ SMqConsumeReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClien ...@@ -900,7 +898,7 @@ SMqConsumeReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClien
pReq->currentOffset = reqOffset; pReq->currentOffset = reqOffset;
pReq->head.vgId = htonl(pVg->vgId); pReq->head.vgId = htonl(pVg->vgId);
pReq->head.contLen = htonl(sizeof(SMqConsumeReq)); pReq->head.contLen = htonl(sizeof(SMqPollReq));
return pReq; return pReq;
} }
...@@ -914,7 +912,7 @@ tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) { ...@@ -914,7 +912,7 @@ tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) {
/*if (vgStatus != TMQ_VG_STATUS__IDLE) {*/ /*if (vgStatus != TMQ_VG_STATUS__IDLE) {*/
/*continue;*/ /*continue;*/
/*}*/ /*}*/
SMqConsumeReq* pReq = tmqBuildConsumeReqImpl(tmq, blockingTime, pTopic, pVg); SMqPollReq* pReq = tmqBuildConsumeReqImpl(tmq, blockingTime, pTopic, pVg);
if (pReq == NULL) { if (pReq == NULL) {
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
// TODO: out of mem // TODO: out of mem
...@@ -941,7 +939,7 @@ tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) { ...@@ -941,7 +939,7 @@ tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) {
sendInfo->msgInfo = (SDataBuf){ sendInfo->msgInfo = (SDataBuf){
.pData = pReq, .pData = pReq,
.len = sizeof(SMqConsumeReq), .len = sizeof(SMqPollReq),
.handle = NULL, .handle = NULL,
}; };
sendInfo->requestId = generateRequestId(); sendInfo->requestId = generateRequestId();
...@@ -982,7 +980,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { ...@@ -982,7 +980,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
if (vgStatus != TMQ_VG_STATUS__IDLE) { if (vgStatus != TMQ_VG_STATUS__IDLE) {
continue; continue;
} }
SMqConsumeReq* pReq = tmqBuildConsumeReqImpl(tmq, blockingTime, pTopic, pVg); SMqPollReq* pReq = tmqBuildConsumeReqImpl(tmq, blockingTime, pTopic, pVg);
if (pReq == NULL) { if (pReq == NULL) {
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
tsem_post(&tmq->rspSem); tsem_post(&tmq->rspSem);
...@@ -1011,7 +1009,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { ...@@ -1011,7 +1009,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
sendInfo->msgInfo = (SDataBuf){ sendInfo->msgInfo = (SDataBuf){
.pData = pReq, .pData = pReq,
.len = sizeof(SMqConsumeReq), .len = sizeof(SMqPollReq),
.handle = NULL, .handle = NULL,
}; };
sendInfo->requestId = generateRequestId(); sendInfo->requestId = generateRequestId();
...@@ -1271,7 +1269,7 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* tmq_topic_v ...@@ -1271,7 +1269,7 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* tmq_topic_v
void tmq_message_destroy(tmq_message_t* tmq_message) { void tmq_message_destroy(tmq_message_t* tmq_message) {
if (tmq_message == NULL) return; if (tmq_message == NULL) return;
SMqConsumeRsp* pRsp = &tmq_message->consumeRsp; SMqPollRsp* pRsp = &tmq_message->consumeRsp;
tDeleteSMqConsumeRsp(pRsp); tDeleteSMqConsumeRsp(pRsp);
/*free(tmq_message);*/ /*free(tmq_message);*/
taosFreeQitem(tmq_message); taosFreeQitem(tmq_message);
......
...@@ -97,6 +97,11 @@ int32_t dmnRunDnode() { ...@@ -97,6 +97,11 @@ int32_t dmnRunDnode() {
} }
int main(int argc, char const *argv[]) { int main(int argc, char const *argv[]) {
if (!taosCheckSystemIsSmallEnd()) {
uError("TDengine does not run on non-small-end machines.");
return -1;
}
if (dmnParseOption(argc, argv) != 0) { if (dmnParseOption(argc, argv) != 0) {
return -1; return -1;
} }
......
...@@ -924,10 +924,10 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) { ...@@ -924,10 +924,10 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) {
vgInfo.hashBegin = pVgroup->hashBegin; vgInfo.hashBegin = pVgroup->hashBegin;
vgInfo.hashEnd = pVgroup->hashEnd; vgInfo.hashEnd = pVgroup->hashEnd;
vgInfo.numOfTable = pVgroup->numOfTables / TSDB_TABLE_NUM_UNIT; vgInfo.numOfTable = pVgroup->numOfTables / TSDB_TABLE_NUM_UNIT;
vgInfo.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 = &vgInfo.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);
...@@ -935,7 +935,7 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) { ...@@ -935,7 +935,7 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) {
} }
mndReleaseDnode(pMnode, pDnode); mndReleaseDnode(pMnode, pDnode);
if (pVgid->role == TAOS_SYNC_STATE_LEADER) { if (pVgid->role == TAOS_SYNC_STATE_LEADER) {
vgInfo.epset.inUse = gid; vgInfo.epSet.inUse = gid;
} }
} }
vindex++; vindex++;
......
...@@ -33,13 +33,17 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib ...@@ -33,13 +33,17 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
SSdb* pSdb = pMnode->pSdb; SSdb* pSdb = pMnode->pSdb;
SVgObj* pVgroup = NULL; SVgObj* pVgroup = NULL;
SQueryPlan* pPlan = qStringToQueryPlan(pTopic->physicalPlan); SQueryPlan* pPlan = qStringToQueryPlan(pTopic->physicalPlan);
SArray* pAray = NULL; if (pPlan == NULL) {
SArray* unassignedVg = pSub->unassignedVg; terrno = TSDB_CODE_QRY_INVALID_INPUT;
return -1;
}
ASSERT(pSub->vgNum == 0); ASSERT(pSub->vgNum == 0);
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans); int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
if (levelNum != 1) { if (levelNum != 1) {
qDestroyQueryPlan(pPlan);
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
return -1; return -1;
} }
...@@ -47,6 +51,8 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib ...@@ -47,6 +51,8 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
int32_t opNum = LIST_LENGTH(inner->pNodeList); int32_t opNum = LIST_LENGTH(inner->pNodeList);
if (opNum != 1) { if (opNum != 1) {
qDestroyQueryPlan(pPlan);
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
return -1; return -1;
} }
SSubplan* plan = nodesListGetNode(inner->pNodeList, 0); SSubplan* plan = nodesListGetNode(inner->pNodeList, 0);
...@@ -62,17 +68,24 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib ...@@ -62,17 +68,24 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
pSub->vgNum++; pSub->vgNum++;
plan->execNode.nodeId = pVgroup->vgId; plan->execNode.nodeId = pVgroup->vgId;
plan->execNode.epset = mndGetVgroupEpset(pMnode, pVgroup); plan->execNode.epSet = mndGetVgroupEpset(pMnode, pVgroup);
SMqConsumerEp consumerEp = {0}; SMqConsumerEp consumerEp = {0};
consumerEp.status = 0; consumerEp.status = 0;
consumerEp.consumerId = -1; consumerEp.consumerId = -1;
consumerEp.epSet = plan->execNode.epset; consumerEp.epSet = plan->execNode.epSet;
consumerEp.vgId = plan->execNode.nodeId; consumerEp.vgId = plan->execNode.nodeId;
int32_t msgLen; int32_t msgLen;
int32_t code = qSubPlanToString(plan, &consumerEp.qmsg, &msgLen); if (qSubPlanToString(plan, &consumerEp.qmsg, &msgLen) < 0) {
taosArrayPush(unassignedVg, &consumerEp); sdbRelease(pSdb, pVgroup);
qDestroyQueryPlan(pPlan);
terrno = TSDB_CODE_QRY_INVALID_INPUT;
return -1;
}
taosArrayPush(pSub->unassignedVg, &consumerEp);
} }
qDestroyQueryPlan(pPlan);
return 0; return 0;
} }
...@@ -93,7 +93,6 @@ static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj ...@@ -93,7 +93,6 @@ static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj
strcpy(pSub->key, key); strcpy(pSub->key, key);
if (mndSchedInitSubEp(pMnode, pTopic, pSub) < 0) { if (mndSchedInitSubEp(pMnode, pTopic, pSub) < 0) {
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
tDeleteSMqSubscribeObj(pSub); tDeleteSMqSubscribeObj(pSub);
free(pSub); free(pSub);
return NULL; return NULL;
...@@ -295,7 +294,11 @@ static int32_t mndProcessGetSubEpReq(SMnodeMsg *pMsg) { ...@@ -295,7 +294,11 @@ static int32_t mndProcessGetSubEpReq(SMnodeMsg *pMsg) {
for (int32_t k = 0; k < vgsz; k++) { for (int32_t k = 0; k < vgsz; k++) {
char offsetKey[TSDB_PARTITION_KEY_LEN]; char offsetKey[TSDB_PARTITION_KEY_LEN];
SMqConsumerEp *pConsumerEp = taosArrayGet(pSubConsumer->vgInfo, k); SMqConsumerEp *pConsumerEp = taosArrayGet(pSubConsumer->vgInfo, k);
SMqSubVgEp vgEp = {.epSet = pConsumerEp->epSet, .vgId = pConsumerEp->vgId, .offset = -1}; SMqSubVgEp vgEp = {
.epSet = pConsumerEp->epSet,
.vgId = pConsumerEp->vgId,
.offset = -1,
};
mndMakePartitionKey(offsetKey, pConsumer->cgroup, topicName, pConsumerEp->vgId); mndMakePartitionKey(offsetKey, pConsumer->cgroup, topicName, pConsumerEp->vgId);
SMqOffsetObj *pOffsetObj = mndAcquireOffset(pMnode, offsetKey); SMqOffsetObj *pOffsetObj = mndAcquireOffset(pMnode, offsetKey);
if (pOffsetObj != NULL) { if (pOffsetObj != NULL) {
...@@ -345,7 +348,7 @@ static SMqRebSubscribe *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) { ...@@ -345,7 +348,7 @@ static SMqRebSubscribe *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) {
if (pRebSub == NULL) { if (pRebSub == NULL) {
pRebSub = tNewSMqRebSubscribe(key); pRebSub = tNewSMqRebSubscribe(key);
if (pRebSub == NULL) { if (pRebSub == NULL) {
// TODO terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL; return NULL;
} }
taosHashPut(pHash, key, strlen(key), pRebSub, sizeof(SMqRebSubscribe)); taosHashPut(pHash, key, strlen(key), pRebSub, sizeof(SMqRebSubscribe));
...@@ -412,7 +415,11 @@ static int32_t mndProcessMqTimerMsg(SMnodeMsg *pMsg) { ...@@ -412,7 +415,11 @@ static int32_t mndProcessMqTimerMsg(SMnodeMsg *pMsg) {
} }
if (taosHashGetSize(pRebMsg->rebSubHash) != 0) { if (taosHashGetSize(pRebMsg->rebSubHash) != 0) {
mInfo("mq rebalance will be triggered"); mInfo("mq rebalance will be triggered");
SRpcMsg rpcMsg = {.msgType = TDMT_MND_MQ_DO_REBALANCE, .pCont = pRebMsg, .contLen = sizeof(SMqDoRebalanceMsg)}; SRpcMsg rpcMsg = {
.msgType = TDMT_MND_MQ_DO_REBALANCE,
.pCont = pRebMsg,
.contLen = sizeof(SMqDoRebalanceMsg),
};
pMnode->putReqToMWriteQFp(pMnode->pDnode, &rpcMsg); pMnode->putReqToMWriteQFp(pMnode->pDnode, &rpcMsg);
} else { } else {
taosHashCleanup(pRebMsg->rebSubHash); taosHashCleanup(pRebMsg->rebSubHash);
......
...@@ -96,7 +96,11 @@ static void mndCalMqRebalance(void *param, void *tmrId) { ...@@ -96,7 +96,11 @@ static void mndCalMqRebalance(void *param, void *tmrId) {
if (mndIsMaster(pMnode)) { if (mndIsMaster(pMnode)) {
int32_t contLen = 0; int32_t contLen = 0;
void *pReq = mndBuildTimerMsg(&contLen); void *pReq = mndBuildTimerMsg(&contLen);
SRpcMsg rpcMsg = {.msgType = TDMT_MND_MQ_TIMER, .pCont = pReq, .contLen = contLen}; SRpcMsg rpcMsg = {
.msgType = TDMT_MND_MQ_TIMER,
.pCont = pReq,
.contLen = contLen,
};
pMnode->putReqToMReadQFp(pMnode->pDnode, &rpcMsg); pMnode->putReqToMReadQFp(pMnode->pDnode, &rpcMsg);
} }
......
...@@ -292,9 +292,9 @@ TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) { ...@@ -292,9 +292,9 @@ TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) {
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];
EXPECT_EQ(pAddr->port, 9030); EXPECT_EQ(pAddr->port, 9030);
EXPECT_STREQ(pAddr->fqdn, "localhost"); EXPECT_STREQ(pAddr->fqdn, "localhost");
} }
...@@ -307,9 +307,9 @@ TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) { ...@@ -307,9 +307,9 @@ TEST_F(MndTestDb, 03_Create_Use_Restart_Use_Db) {
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];
EXPECT_EQ(pAddr->port, 9030); EXPECT_EQ(pAddr->port, 9030);
EXPECT_STREQ(pAddr->fqdn, "localhost"); EXPECT_STREQ(pAddr->fqdn, "localhost");
} }
......
...@@ -13,16 +13,14 @@ ...@@ -13,16 +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_TQ_H_ #ifndef _TQ_H_
#define _TD_TQ_H_ #define _TQ_H_
#include "tcommon.h"
#include "executor.h" #include "executor.h"
#include "tmallocator.h"
#include "meta.h" #include "meta.h"
#include "scheduler.h"
#include "taoserror.h" #include "taoserror.h"
#include "tlist.h" #include "tcommon.h"
#include "tmallocator.h"
#include "tmsg.h" #include "tmsg.h"
#include "trpc.h" #include "trpc.h"
#include "ttimer.h" #include "ttimer.h"
...@@ -54,7 +52,7 @@ void tqClose(STQ*); ...@@ -54,7 +52,7 @@ void tqClose(STQ*);
int tqPushMsg(STQ*, void* msg, tmsg_t msgType, int64_t version); int tqPushMsg(STQ*, void* msg, tmsg_t msgType, int64_t version);
int tqCommit(STQ*); int tqCommit(STQ*);
int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessSetConnReq(STQ* pTq, char* msg); int32_t tqProcessSetConnReq(STQ* pTq, char* msg);
int32_t tqProcessRebReq(STQ* pTq, char* msg); int32_t tqProcessRebReq(STQ* pTq, char* msg);
...@@ -62,4 +60,4 @@ int32_t tqProcessRebReq(STQ* pTq, char* msg); ...@@ -62,4 +60,4 @@ int32_t tqProcessRebReq(STQ* pTq, char* msg);
} }
#endif #endif
#endif /*_TD_TQ_H_*/ #endif /*_TQ_H_*/
...@@ -205,6 +205,22 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad); ...@@ -205,6 +205,22 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
/* ------------------------- TQ READ --------------------------- */ /* ------------------------- TQ READ --------------------------- */
enum {
TQ_STREAM_TOKEN__DATA = 1,
TQ_STREAM_TOKEN__WATERMARK,
TQ_STREAM_TOKEN__CHECKPOINT,
};
typedef struct {
int8_t type;
int8_t reserved[7];
union {
void *data;
int64_t wmTs;
int64_t checkpointId;
};
} STqStreamToken;
STqReadHandle *tqInitSubmitMsgScanner(SMeta *pMeta); STqReadHandle *tqInitSubmitMsgScanner(SMeta *pMeta);
static FORCE_INLINE void tqReadHandleSetColIdList(STqReadHandle *pReadHandle, SArray *pColIdList) { static FORCE_INLINE void tqReadHandleSetColIdList(STqReadHandle *pReadHandle, SArray *pColIdList) {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "meta.h" #include "meta.h"
#include "tlog.h" #include "tlog.h"
#include "tq.h" #include "tq.h"
#include "trpc.h" #include "tqPush.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -31,30 +31,35 @@ extern "C" { ...@@ -31,30 +31,35 @@ extern "C" {
taosPrintLog("TQ FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ taosPrintLog("TQ FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \
} \ } \
} }
#define tqError(...) \ #define tqError(...) \
{ \ { \
if (tqDebugFlag & DEBUG_ERROR) { \ if (tqDebugFlag & DEBUG_ERROR) { \
taosPrintLog("TQ ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ taosPrintLog("TQ ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \
} \ } \
} }
#define tqWarn(...) \ #define tqWarn(...) \
{ \ { \
if (tqDebugFlag & DEBUG_WARN) { \ if (tqDebugFlag & DEBUG_WARN) { \
taosPrintLog("TQ WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ taosPrintLog("TQ WARN ", DEBUG_WARN, 255, __VA_ARGS__); \
} \ } \
} }
#define tqInfo(...) \ #define tqInfo(...) \
{ \ { \
if (tqDebugFlag & DEBUG_INFO) { \ if (tqDebugFlag & DEBUG_INFO) { \
taosPrintLog("TQ ", DEBUG_INFO, 255, __VA_ARGS__); \ taosPrintLog("TQ ", DEBUG_INFO, 255, __VA_ARGS__); \
} \ } \
} }
#define tqDebug(...) \ #define tqDebug(...) \
{ \ { \
if (tqDebugFlag & DEBUG_DEBUG) { \ if (tqDebugFlag & DEBUG_DEBUG) { \
taosPrintLog("TQ ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); \ taosPrintLog("TQ ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); \
} \ } \
} }
#define tqTrace(...) \ #define tqTrace(...) \
{ \ { \
if (tqDebugFlag & DEBUG_TRACE) { \ if (tqDebugFlag & DEBUG_TRACE) { \
...@@ -138,9 +143,7 @@ typedef struct { ...@@ -138,9 +143,7 @@ typedef struct {
// topics that are not connectted // topics that are not connectted
STqMetaList* unconnectTopic; STqMetaList* unconnectTopic;
// TODO:temporaral use, to be replaced by unified tfile
TdFilePtr pFile; TdFilePtr pFile;
// TODO:temporaral use, to be replaced by unified tfile
TdFilePtr pIdxFile; TdFilePtr pIdxFile;
char* dirPath; char* dirPath;
...@@ -157,6 +160,7 @@ struct STQ { ...@@ -157,6 +160,7 @@ struct STQ {
STqCfg* tqConfig; STqCfg* tqConfig;
STqMemRef tqMemRef; STqMemRef tqMemRef;
STqMetaStore* tqMeta; STqMetaStore* tqMeta;
STqPushMgr* tqPushMgr;
SWal* pWal; SWal* pWal;
SMeta* pVnodeMeta; SMeta* pVnodeMeta;
}; };
......
/*
* 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 _TQ_PUSH_H_
#define _TQ_PUSH_H_
#include "executor.h"
#include "thash.h"
#include "trpc.h"
#include "ttimer.h"
#include "vnode.h"
#ifdef __cplusplus
extern "C" {
#endif
enum {
TQ_PUSHER_TYPE__CLIENT = 1,
TQ_PUSHER_TYPE__STREAM,
};
typedef struct {
int8_t type;
int8_t reserved[3];
int32_t ttl;
int64_t consumerId;
SRpcMsg* pMsg;
// SMqPollRsp* rsp;
} STqClientPusher;
typedef struct {
int8_t type;
int8_t nodeType;
int8_t reserved[6];
int64_t streamId;
qTaskInfo_t task;
// TODO sync function
} STqStreamPusher;
typedef struct {
int8_t type; // mq or stream
} STqPusher;
typedef struct {
SHashObj* pHash; // <id, STqPush*>
} STqPushMgr;
typedef struct {
int8_t inited;
tmr_h timer;
} STqPushMgmt;
static STqPushMgmt tqPushMgmt;
int32_t tqPushMgrInit();
void tqPushMgrCleanUp();
STqPushMgr* tqPushMgrOpen();
void tqPushMgrClose(STqPushMgr* pushMgr);
STqClientPusher* tqAddClientPusher(STqPushMgr* pushMgr, SRpcMsg* pMsg, int64_t consumerId, int64_t ttl);
STqStreamPusher* tqAddStreamPusher(STqPushMgr* pushMgr, int64_t streamId, SEpSet* pEpSet);
#ifdef __cplusplus
}
#endif
#endif /*_TQ_PUSH_H_*/
...@@ -52,6 +52,7 @@ struct STsdb { ...@@ -52,6 +52,7 @@ struct STsdb {
STsdbFS * fs; STsdbFS * fs;
SMeta * pMeta; SMeta * pMeta;
STfs * pTfs; STfs * pTfs;
SSmaStat * pSmaStat;
}; };
#define REPO_ID(r) ((r)->vgId) #define REPO_ID(r) ((r)->vgId)
......
...@@ -42,7 +42,10 @@ typedef struct { ...@@ -42,7 +42,10 @@ typedef struct {
typedef struct { typedef struct {
STsdbFSMeta meta; // FS meta STsdbFSMeta meta; // FS meta
SArray * df; // data file array SArray * df; // data file array
SArray * smaf; // sma data file array
// SArray * v2f100.tsma.index_name
SArray * smaf; // sma data file array v2f1900.tsma.index_name
} SFSStatus; } SFSStatus;
typedef struct { typedef struct {
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#ifndef _TD_TSDB_SMA_H_ #ifndef _TD_TSDB_SMA_H_
#define _TD_TSDB_SMA_H_ #define _TD_TSDB_SMA_H_
typedef struct SSmaStat SSmaStat;
// insert/update interface // insert/update interface
int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData); int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData);
int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData); int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData);
...@@ -26,13 +28,14 @@ int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData); ...@@ -26,13 +28,14 @@ int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData);
int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeWindow *queryWin, int32_t nMaxResult); int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeWindow *queryWin, int32_t nMaxResult);
// management interface // management interface
int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void* result); int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg);
int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result);
int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin); int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
int32_t tsdbFreeSmaState(SSmaStat *pSmaStat);
// internal func
// internal func
static FORCE_INLINE int32_t tsdbEncodeTSmaKey(uint64_t tableUid, col_id_t colId, TSKEY tsKey, void **pData) { static FORCE_INLINE int32_t tsdbEncodeTSmaKey(uint64_t tableUid, col_id_t colId, TSKEY tsKey, void **pData) {
int32_t len = 0; int32_t len = 0;
len += taosEncodeFixedU64(pData, tableUid); len += taosEncodeFixedU64(pData, tableUid);
......
...@@ -923,6 +923,7 @@ SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) { ...@@ -923,6 +923,7 @@ SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) {
SMetaDB *pDB = pMeta->pDB; SMetaDB *pDB = pMeta->pDB;
DBC * pCur = NULL; DBC * pCur = NULL;
DBT pkey = {0}, pval = {0}; DBT pkey = {0}, pval = {0};
uint32_t mode = isDup ? DB_NEXT_DUP : DB_NEXT_NODUP;
int ret; int ret;
pUids = taosArrayInit(16, sizeof(tb_uid_t)); pUids = taosArrayInit(16, sizeof(tb_uid_t));
...@@ -941,13 +942,8 @@ SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) { ...@@ -941,13 +942,8 @@ SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) {
void *pBuf = NULL; void *pBuf = NULL;
// TODO: lock? // TODO: lock?
while (true) { while ((ret = pCur->get(pCur, &pkey, &pval, mode)) == 0) {
ret = pCur->get(pCur, &pkey, &pval, isDup ? DB_NEXT_DUP : DB_NEXT_NODUP);
if(ret == 0) {
taosArrayPush(pUids, pkey.data); taosArrayPush(pUids, pkey.data);
continue;
}
break;
} }
if (pCur) { if (pCur) {
......
...@@ -12,28 +12,16 @@ ...@@ -12,28 +12,16 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define _DEFAULT_SOURCE
#include "tcompare.h" #include "tcompare.h"
#include "tqInt.h" #include "tqInt.h"
#include "tqMetaStore.h" #include "tqMetaStore.h"
int tqInit() { int32_t tqInit() { return tqPushMgrInit(); }
int8_t old = atomic_val_compare_exchange_8(&tqMgmt.inited, 0, 1);
if (old == 1) return 0;
tqMgmt.timer = taosTmrInit(0, 0, 0, "TQ"); void tqCleanUp() { tqPushMgrCleanUp(); }
return 0;
}
void tqCleanUp() { STQ* tqOpen(const char* path, SWal* pWal, SMeta* pVnodeMeta, STqCfg* tqConfig, SMemAllocatorFactory* allocFac) {
int8_t old = atomic_val_compare_exchange_8(&tqMgmt.inited, 1, 0);
if (old == 0) return;
taosTmrStop(tqMgmt.timer);
taosTmrCleanUp(tqMgmt.timer);
}
STQ* tqOpen(const char* path, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, SMemAllocatorFactory* allocFac) {
STQ* pTq = malloc(sizeof(STQ)); STQ* pTq = malloc(sizeof(STQ));
if (pTq == NULL) { if (pTq == NULL) {
terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
...@@ -42,7 +30,7 @@ STQ* tqOpen(const char* path, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, SMemAl ...@@ -42,7 +30,7 @@ STQ* tqOpen(const char* path, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, SMemAl
pTq->path = strdup(path); pTq->path = strdup(path);
pTq->tqConfig = tqConfig; pTq->tqConfig = tqConfig;
pTq->pWal = pWal; pTq->pWal = pWal;
pTq->pVnodeMeta = pMeta; pTq->pVnodeMeta = pVnodeMeta;
#if 0 #if 0
pTq->tqMemRef.pAllocatorFactory = allocFac; pTq->tqMemRef.pAllocatorFactory = allocFac;
pTq->tqMemRef.pAllocator = allocFac->create(allocFac); pTq->tqMemRef.pAllocator = allocFac->create(allocFac);
...@@ -60,6 +48,13 @@ STQ* tqOpen(const char* path, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, SMemAl ...@@ -60,6 +48,13 @@ STQ* tqOpen(const char* path, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, SMemAl
return NULL; return NULL;
} }
pTq->tqPushMgr = tqPushMgrOpen();
if (pTq->tqPushMgr == NULL) {
// free store
free(pTq);
return NULL;
}
return pTq; return pTq;
} }
...@@ -72,6 +67,28 @@ void tqClose(STQ* pTq) { ...@@ -72,6 +67,28 @@ void tqClose(STQ* pTq) {
} }
int tqPushMsg(STQ* pTq, void* msg, tmsg_t msgType, int64_t version) { int tqPushMsg(STQ* pTq, void* msg, tmsg_t msgType, int64_t version) {
if (msgType != TDMT_VND_SUBMIT) return 0;
void* pIter = taosHashIterate(pTq->tqPushMgr->pHash, NULL);
while (pIter != NULL) {
STqPusher* pusher = *(STqPusher**)pIter;
if (pusher->type == TQ_PUSHER_TYPE__STREAM) {
STqStreamPusher* streamPusher = (STqStreamPusher*)pusher;
// repack
STqStreamToken* token = malloc(sizeof(STqStreamToken));
if (token == NULL) {
taosHashCancelIterate(pTq->tqPushMgr->pHash, pIter);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
token->type = TQ_STREAM_TOKEN__DATA;
token->data = msg;
// set input
// exec
}
// send msg to ep
}
// iterate hash
// process all msg
// if waiting // if waiting
// memcpy and send msg to fetch thread // memcpy and send msg to fetch thread
// TODO: add reference // TODO: add reference
...@@ -199,7 +216,10 @@ int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsu ...@@ -199,7 +216,10 @@ int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsu
for (int j = 0; j < TQ_BUFFER_SIZE; j++) { for (int j = 0; j < TQ_BUFFER_SIZE; j++) {
pTopic->buffer.output[j].status = 0; pTopic->buffer.output[j].status = 0;
STqReadHandle* pReadHandle = tqInitSubmitMsgScanner(pTq->pVnodeMeta); STqReadHandle* pReadHandle = tqInitSubmitMsgScanner(pTq->pVnodeMeta);
SReadHandle handle = {.reader = pReadHandle, .meta = pTq->pVnodeMeta}; SReadHandle handle = {
.reader = pReadHandle,
.meta = pTq->pVnodeMeta,
};
pTopic->buffer.output[j].pReadHandle = pReadHandle; pTopic->buffer.output[j].pReadHandle = pReadHandle;
pTopic->buffer.output[j].task = qCreateStreamExecTaskInfo(pTopic->qmsg, &handle); pTopic->buffer.output[j].task = qCreateStreamExecTaskInfo(pTopic->qmsg, &handle);
} }
...@@ -208,8 +228,8 @@ int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsu ...@@ -208,8 +228,8 @@ int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsu
return 0; return 0;
} }
int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) { int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
SMqConsumeReq* pReq = pMsg->pCont; SMqPollReq* pReq = pMsg->pCont;
int64_t consumerId = pReq->consumerId; int64_t consumerId = pReq->consumerId;
int64_t fetchOffset; int64_t fetchOffset;
int64_t blockingTime = pReq->blockingTime; int64_t blockingTime = pReq->blockingTime;
...@@ -222,7 +242,7 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) { ...@@ -222,7 +242,7 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) {
fetchOffset = pReq->currentOffset + 1; fetchOffset = pReq->currentOffset + 1;
} }
SMqConsumeRsp rsp = { SMqPollRsp rsp = {
.consumerId = consumerId, .consumerId = consumerId,
.numOfTopics = 0, .numOfTopics = 0,
.pBlockData = NULL, .pBlockData = NULL,
...@@ -236,6 +256,7 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) { ...@@ -236,6 +256,7 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) {
rpcSendResponse(pMsg); rpcSendResponse(pMsg);
return 0; return 0;
} }
int sz = taosArrayGetSize(pConsumer->topics); int sz = taosArrayGetSize(pConsumer->topics);
ASSERT(sz == 1); ASSERT(sz == 1);
STqTopic* pTopic = taosArrayGet(pConsumer->topics, 0); STqTopic* pTopic = taosArrayGet(pConsumer->topics, 0);
...@@ -247,13 +268,14 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) { ...@@ -247,13 +268,14 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) {
SWalHead* pHead; SWalHead* pHead;
while (1) { while (1) {
int8_t pos = fetchOffset % TQ_BUFFER_SIZE; /*if (fetchOffset > walGetLastVer(pTq->pWal) || walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {*/
if (walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) { if (walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {
// TODO: no more log, set timer to wait blocking time // TODO: no more log, set timer to wait blocking time
// if data inserted during waiting, launch query and // if data inserted during waiting, launch query and
// response to user // response to user
break; break;
} }
int8_t pos = fetchOffset % TQ_BUFFER_SIZE;
pHead = pTopic->pReadhandle->pHead; pHead = pTopic->pReadhandle->pHead;
if (pHead->head.msgType == TDMT_VND_SUBMIT) { if (pHead->head.msgType == TDMT_VND_SUBMIT) {
SSubmitReq* pCont = (SSubmitReq*)&pHead->head.body; SSubmitReq* pCont = (SSubmitReq*)&pHead->head.body;
...@@ -280,7 +302,7 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) { ...@@ -280,7 +302,7 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) {
rsp.numOfTopics = 1; rsp.numOfTopics = 1;
rsp.pBlockData = pRes; rsp.pBlockData = pRes;
int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqConsumeRsp(NULL, &rsp); int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRsp(NULL, &rsp);
void* buf = rpcMallocCont(tlen); void* buf = rpcMallocCont(tlen);
if (buf == NULL) { if (buf == NULL) {
pMsg->code = -1; pMsg->code = -1;
...@@ -290,7 +312,7 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) { ...@@ -290,7 +312,7 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) {
((SMqRspHead*)buf)->epoch = pReq->epoch; ((SMqRspHead*)buf)->epoch = pReq->epoch;
void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead)); void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
tEncodeSMqConsumeRsp(&abuf, &rsp); tEncodeSMqPollRsp(&abuf, &rsp);
taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock); taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);
pMsg->pCont = buf; pMsg->pCont = buf;
pMsg->contLen = tlen; pMsg->contLen = tlen;
...@@ -304,7 +326,10 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) { ...@@ -304,7 +326,10 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) {
} }
} }
int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqConsumeRsp(NULL, &rsp); /*if (blockingTime != 0) {*/
/*tqAddClientPusher(pTq->tqPushMgr, pMsg, consumerId, blockingTime);*/
/*} else {*/
int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRsp(NULL, &rsp);
void* buf = rpcMallocCont(tlen); void* buf = rpcMallocCont(tlen);
if (buf == NULL) { if (buf == NULL) {
pMsg->code = -1; pMsg->code = -1;
...@@ -314,12 +339,14 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) { ...@@ -314,12 +339,14 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg) {
((SMqRspHead*)buf)->epoch = pReq->epoch; ((SMqRspHead*)buf)->epoch = pReq->epoch;
void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead)); void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
tEncodeSMqConsumeRsp(&abuf, &rsp); tEncodeSMqPollRsp(&abuf, &rsp);
rsp.pBlockData = NULL; rsp.pBlockData = NULL;
pMsg->pCont = buf; pMsg->pCont = buf;
pMsg->contLen = tlen; pMsg->contLen = tlen;
pMsg->code = 0; pMsg->code = 0;
rpcSendResponse(pMsg); rpcSendResponse(pMsg);
/*}*/
return 0; return 0;
} }
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tqPush.h"
int32_t tqPushMgrInit() {
//
int8_t old = atomic_val_compare_exchange_8(&tqPushMgmt.inited, 0, 1);
if (old == 1) return 0;
tqPushMgmt.timer = taosTmrInit(0, 0, 0, "TQ");
return 0;
}
void tqPushMgrCleanUp() {
int8_t old = atomic_val_compare_exchange_8(&tqPushMgmt.inited, 1, 0);
if (old == 0) return;
taosTmrStop(tqPushMgmt.timer);
taosTmrCleanUp(tqPushMgmt.timer);
}
STqPushMgr* tqPushMgrOpen() {
STqPushMgr* mgr = malloc(sizeof(STqPushMgr));
if (mgr == NULL) {
return NULL;
}
mgr->pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
return mgr;
}
void tqPushMgrClose(STqPushMgr* pushMgr) {
taosHashCleanup(pushMgr->pHash);
free(pushMgr);
}
STqClientPusher* tqAddClientPusher(STqPushMgr* pushMgr, SRpcMsg* pMsg, int64_t consumerId, int64_t ttl) {
STqClientPusher* clientPusher = malloc(sizeof(STqClientPusher));
if (clientPusher == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
clientPusher->type = TQ_PUSHER_TYPE__CLIENT;
clientPusher->pMsg = pMsg;
clientPusher->consumerId = consumerId;
clientPusher->ttl = ttl;
if (taosHashPut(pushMgr->pHash, &consumerId, sizeof(int64_t), &clientPusher, sizeof(void*)) < 0) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
free(clientPusher);
// TODO send rsp back
return NULL;
}
return clientPusher;
}
STqStreamPusher* tqAddStreamPusher(STqPushMgr* pushMgr, int64_t streamId, SEpSet* pEpSet) {
STqStreamPusher* streamPusher = malloc(sizeof(STqStreamPusher));
if (streamPusher == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
streamPusher->type = TQ_PUSHER_TYPE__STREAM;
streamPusher->nodeType = 0;
streamPusher->streamId = streamId;
/*memcpy(&streamPusher->epSet, pEpSet, sizeof(SEpSet));*/
if (taosHashPut(pushMgr->pHash, &streamId, sizeof(int64_t), &streamPusher, sizeof(void*)) < 0) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
free(streamPusher);
return NULL;
}
return streamPusher;
}
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define _DEFAULT_SOURCE
#include "vnode.h" #include "vnode.h"
...@@ -37,6 +36,7 @@ int32_t tqReadHandleSetMsg(STqReadHandle* pReadHandle, SSubmitReq* pMsg, int64_t ...@@ -37,6 +36,7 @@ int32_t tqReadHandleSetMsg(STqReadHandle* pReadHandle, SSubmitReq* pMsg, int64_t
pMsg->length = htonl(pMsg->length); pMsg->length = htonl(pMsg->length);
pMsg->numOfBlocks = htonl(pMsg->numOfBlocks); pMsg->numOfBlocks = htonl(pMsg->numOfBlocks);
// iterate and convert
if (tInitSubmitMsgIter(pMsg, &pReadHandle->msgIter) < 0) return -1; if (tInitSubmitMsgIter(pMsg, &pReadHandle->msgIter) < 0) return -1;
while (true) { while (true) {
if (tGetSubmitMsgNext(&pReadHandle->msgIter, &pReadHandle->pBlock) < 0) return -1; if (tGetSubmitMsgNext(&pReadHandle->msgIter, &pReadHandle->pBlock) < 0) return -1;
......
...@@ -12,20 +12,3 @@ ...@@ -12,20 +12,3 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef TDENGINE_INSERTPARSER_H
#define TDENGINE_INSERTPARSER_H
#ifdef __cplusplus
extern "C" {
#endif
#include "parser.h"
int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_INSERTPARSER_H
...@@ -365,7 +365,7 @@ int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T ...@@ -365,7 +365,7 @@ int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T
if (errno == ENOENT) { if (errno == ENOENT) {
// Try to create directory recursively // Try to create directory recursively
char *s = strdup(TSDB_FILE_REL_NAME(pDFile)); char *s = strdup(TSDB_FILE_REL_NAME(pDFile));
if (tfsMkdirRecurAt(pRepo->pTfs, dirname(s), TSDB_FILE_DID(pDFile)) < 0) { if (tfsMkdirRecurAt(pRepo->pTfs, taosDirName(s), TSDB_FILE_DID(pDFile)) < 0) {
tfree(s); tfree(s);
return -1; return -1;
} }
......
...@@ -89,6 +89,7 @@ static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, ...@@ -89,6 +89,7 @@ static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg,
static void tsdbFree(STsdb *pTsdb) { static void tsdbFree(STsdb *pTsdb) {
if (pTsdb) { if (pTsdb) {
tsdbFreeFS(pTsdb->fs); tsdbFreeFS(pTsdb->fs);
tsdbFreeSmaState(pTsdb->pSmaStat);
tfree(pTsdb->path); tfree(pTsdb->path);
free(pTsdb); free(pTsdb);
} }
......
...@@ -21,6 +21,10 @@ ...@@ -21,6 +21,10 @@
#define SMA_STORE_SINGLE_BLOCKS // store SMA data by single block or multiple blocks #define SMA_STORE_SINGLE_BLOCKS // store SMA data by single block or multiple blocks
#define SMA_STATE_HASH_SLOT 4
#define SMA_STATE_ITEM_HASH_SLOT 32
#define SMA_TEST_INDEX_NAME "smaTestIndexName" // TODO: just for test
typedef enum { typedef enum {
SMA_STORAGE_LEVEL_TSDB = 0, // store TSma in dir e.g. vnode${N}/tsdb/.tsma SMA_STORAGE_LEVEL_TSDB = 0, // store TSma in dir e.g. vnode${N}/tsdb/.tsma
SMA_STORAGE_LEVEL_DFILESET = 1 // store TSma in file e.g. vnode${N}/tsdb/v2f1900.tsma.${sma_index_name} SMA_STORAGE_LEVEL_DFILESET = 1 // store TSma in file e.g. vnode${N}/tsdb/v2f1900.tsma.${sma_index_name}
...@@ -48,6 +52,22 @@ typedef struct { ...@@ -48,6 +52,22 @@ typedef struct {
// TODO // TODO
} STSmaReadH; } STSmaReadH;
typedef struct {
/**
* @brief The field 'state' is here to demonstrate if one smaIndex is ready to provide service.
* - TSDB_SMA_STAT_EXPIRED: 1) If sma calculation of history TS data is not finished; 2) Or if the TSDB is open,
* without information about its previous state.
* - TSDB_SMA_STAT_OK: 1) The sma calculation of history data is finished; 2) Or recevied information from
* Streaming Module or TSDB local persistence.
*/
int8_t state; // ETsdbSmaStat
SHashObj *expiredWindows; // key: skey of time window, value: N/A
} SSmaStatItem;
struct SSmaStat {
SHashObj *smaStatItems; // key: indexName, value: SSmaStatItem
};
// declaration of static functions // declaration of static functions
static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData); static int32_t tsdbInitTSmaWriteH(STSmaWriteH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData);
static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData); static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param, STSmaData *pData);
...@@ -64,6 +84,125 @@ static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param, ...@@ -64,6 +84,125 @@ static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, STSma *param,
static int32_t tsdbInitTSmaFile(STSmaReadH *pReadH, STSma *param, STimeWindow *queryWin); static int32_t tsdbInitTSmaFile(STSmaReadH *pReadH, STSma *param, STimeWindow *queryWin);
static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, STSma *param, STimeWindow *queryWin); static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, STSma *param, STimeWindow *queryWin);
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
ASSERT(pSmaStat != NULL);
if (*pSmaStat != NULL) { // no lock
return TSDB_CODE_SUCCESS;
}
// TODO: lock. lazy mode when update expired window, or hungry mode during tsdbNew.
if (*pSmaStat == NULL) {
*pSmaStat = (SSmaStat *)calloc(1, sizeof(SSmaStat));
if (*pSmaStat == NULL) {
// TODO: unlock
terrno = TSDB_CODE_OUT_OF_MEMORY;
return TSDB_CODE_FAILED;
}
(*pSmaStat)->smaStatItems =
taosHashInit(SMA_STATE_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
if ((*pSmaStat)->smaStatItems == NULL) {
tfree(*pSmaStat);
// TODO: unlock
return TSDB_CODE_FAILED;
}
}
// TODO: unlock
return TSDB_CODE_SUCCESS;
}
static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) {
SSmaStatItem *pItem = NULL;
pItem = (SSmaStatItem *)calloc(1, sizeof(SSmaStatItem));
if (pItem) {
pItem->state = state;
pItem->expiredWindows = taosHashInit(SMA_STATE_ITEM_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_TIMESTAMP),
true, HASH_ENTRY_LOCK);
if (!pItem->expiredWindows) {
tfree(pItem);
}
}
return pItem;
}
int32_t tsdbFreeSmaState(SSmaStat *pSmaStat) {
if (pSmaStat) {
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
SSmaStatItem *item = taosHashIterate(pSmaStat->smaStatItems, NULL);
while (item != NULL) {
taosHashCleanup(item->expiredWindows);
item = taosHashIterate(pSmaStat->smaStatItems, item);
}
taosHashCleanup(pSmaStat->smaStatItems);
free(pSmaStat);
}
}
/**
* @brief Update expired window according to msg from stream computing module.
*
* @param pTsdb
* @param msg
* @return int32_t
*/
int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg) {
if (msg == NULL) {
return TSDB_CODE_FAILED;
}
tsdbInitSmaStat(&pTsdb->pSmaStat); // lazy mode
// TODO: decode the msg => start
const char * indexName = SMA_TEST_INDEX_NAME;
const int32_t SMA_TEST_EXPIRED_WINDOW_SIZE = 10;
TSKEY expiredWindows[SMA_TEST_EXPIRED_WINDOW_SIZE];
int64_t now = taosGetTimestampMs();
for (int32_t i = 0; i < SMA_TEST_EXPIRED_WINDOW_SIZE; ++i) {
expiredWindows[i] = now + i;
}
// TODO: decode the msg <= end
SHashObj *pItemsHash = pTsdb->pSmaStat->smaStatItems;
SSmaStatItem *pItem = (SSmaStatItem *)taosHashGet(pItemsHash, indexName, strlen(indexName));
if (!pItem) {
pItem = tsdbNewSmaStatItem(TSDB_SMA_STAT_EXPIRED); // TODO use the real state
if (!pItem) {
// Response to stream computing: OOM
// For query, if the indexName not found, the TSDB should tell query module to query raw TS data.
return TSDB_CODE_FAILED;
}
if (taosHashPut(pItemsHash, indexName, strnlen(indexName, TSDB_INDEX_NAME_LEN), &pItem, sizeof(pItem)) != 0) {
// If error occurs during put smaStatItem, free the resources of pItem
taosHashCleanup(pItem->expiredWindows);
free(pItem);
return TSDB_CODE_FAILED;
}
}
int8_t state = TSDB_SMA_STAT_EXPIRED;
for (int32_t i = 0; i < SMA_TEST_EXPIRED_WINDOW_SIZE; ++i) {
if (taosHashPut(pItem->expiredWindows, &expiredWindows[i], sizeof(TSKEY), &state, sizeof(state)) != 0) {
// If error occurs during taosHashPut expired windows, remove the smaIndex from pTsdb->pSmaStat, thus TSDB would
// tell query module to query raw TS data.
// N.B.
// 1) It is assumed to be extemely little probability event of fail to taosHashPut.
// 2) This would solve the inconsistency to some extent, but not completely, unless we record all expired
// windows failed to put into hash table.
taosHashCleanup(pItem->expiredWindows);
taosHashRemove(pItemsHash, indexName, sizeof(indexName));
return TSDB_CODE_FAILED;
}
}
return TSDB_CODE_SUCCESS;
}
/** /**
* @brief Judge the tSma storage level * @brief Judge the tSma storage level
* *
...@@ -484,6 +623,22 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, STSma *param, STimeWindow ...@@ -484,6 +623,22 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, STSma *param, STimeWindow
* @return int32_t * @return int32_t
*/ */
int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeWindow *queryWin, int32_t nMaxResult) { int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData, STimeWindow *queryWin, int32_t nMaxResult) {
const char *indexName = param->indexName;
SSmaStatItem *pItem = (SSmaStatItem *)taosHashGet(pTsdb->pSmaStat->smaStatItems, indexName, strlen(indexName));
if (pItem == NULL) {
// mark all window as expired and notify query module to query raw TS data.
return TSDB_CODE_SUCCESS;
}
int32_t nQueryWin = 0;
for (int32_t n = 0; n < nQueryWin; ++n) {
TSKEY thisWindow = n;
if (taosHashGet(pItem->expiredWindows, &thisWindow, sizeof(thisWindow)) != NULL) {
// TODO: mark this window as expired.
}
}
STSmaReadH tReadH = {0}; STSmaReadH tReadH = {0};
tsdbInitTSmaReadH(&tReadH, pTsdb, param, pData); tsdbInitTSmaReadH(&tReadH, pTsdb, param, pData);
......
...@@ -33,7 +33,7 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { ...@@ -33,7 +33,7 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta, .config = &pVnode->config}; SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta, .config = &pVnode->config};
switch (pMsg->msgType) { switch (pMsg->msgType) {
case TDMT_VND_QUERY:{ case TDMT_VND_QUERY: {
return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg); return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg);
} }
case TDMT_VND_QUERY_CONTINUE: case TDMT_VND_QUERY_CONTINUE:
...@@ -67,7 +67,7 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { ...@@ -67,7 +67,7 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) {
case TDMT_VND_TABLE_META: case TDMT_VND_TABLE_META:
return vnodeGetTableMeta(pVnode, pMsg); return vnodeGetTableMeta(pVnode, pMsg);
case TDMT_VND_CONSUME: case TDMT_VND_CONSUME:
return tqProcessConsumeReq(pVnode->pTq, pMsg); return tqProcessPollReq(pVnode->pTq, pMsg);
case TDMT_VND_QUERY_HEARTBEAT: case TDMT_VND_QUERY_HEARTBEAT:
return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg); return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg);
default: default:
...@@ -77,8 +77,8 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { ...@@ -77,8 +77,8 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) {
} }
static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) { static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
STbCfg * pTbCfg = NULL; STbCfg *pTbCfg = NULL;
STbCfg * pStbCfg = NULL; STbCfg *pStbCfg = NULL;
tb_uid_t uid; tb_uid_t uid;
int32_t nCols; int32_t nCols;
int32_t nTagCols; int32_t nTagCols;
...@@ -210,9 +210,9 @@ static void freeItemHelper(void *pItem) { ...@@ -210,9 +210,9 @@ static void freeItemHelper(void *pItem) {
*/ */
static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) { static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) {
SMTbCursor *pCur = metaOpenTbCursor(pVnode->pMeta); SMTbCursor *pCur = metaOpenTbCursor(pVnode->pMeta);
SArray * pArray = taosArrayInit(10, POINTER_BYTES); SArray *pArray = taosArrayInit(10, POINTER_BYTES);
char * name = NULL; char *name = NULL;
int32_t totalLen = 0; int32_t totalLen = 0;
int32_t numOfTables = 0; int32_t numOfTables = 0;
while ((name = metaTbCursorNext(pCur)) != NULL) { while ((name = metaTbCursorNext(pCur)) != NULL) {
......
...@@ -168,10 +168,10 @@ TEST_F(TqMetaUpdateAppendTest, intxnPersist) { ...@@ -168,10 +168,10 @@ TEST_F(TqMetaUpdateAppendTest, intxnPersist) {
} }
TEST_F(TqMetaUpdateAppendTest, multiplePage) { TEST_F(TqMetaUpdateAppendTest, multiplePage) {
srand(0); taosSeedRand(0);
std::vector<int> v; std::vector<int> v;
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
v.push_back(rand()); v.push_back(taosRand());
Foo foo; Foo foo;
foo.a = v[i]; foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo)); tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
...@@ -202,10 +202,10 @@ TEST_F(TqMetaUpdateAppendTest, multiplePage) { ...@@ -202,10 +202,10 @@ TEST_F(TqMetaUpdateAppendTest, multiplePage) {
} }
TEST_F(TqMetaUpdateAppendTest, multipleRewrite) { TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
srand(0); taosSeedRand(0);
std::vector<int> v; std::vector<int> v;
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
v.push_back(rand()); v.push_back(taosRand());
Foo foo; Foo foo;
foo.a = v[i]; foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo)); tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
...@@ -213,14 +213,14 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) { ...@@ -213,14 +213,14 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
for (int i = 0; i < 500; i++) { for (int i = 0; i < 500; i++) {
tqHandleCommit(pMeta, i); tqHandleCommit(pMeta, i);
v[i] = rand(); v[i] = taosRand();
Foo foo; Foo foo;
foo.a = v[i]; foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo)); tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
} }
for (int i = 500; i < 1000; i++) { for (int i = 500; i < 1000; i++) {
v[i] = rand(); v[i] = taosRand();
Foo foo; Foo foo;
foo.a = v[i]; foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo)); tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
...@@ -235,7 +235,7 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) { ...@@ -235,7 +235,7 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
ASSERT(pMeta); ASSERT(pMeta);
for (int i = 500; i < 1000; i++) { for (int i = 500; i < 1000; i++) {
v[i] = rand(); v[i] = taosRand();
Foo foo; Foo foo;
foo.a = v[i]; foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo)); tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
...@@ -250,10 +250,10 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) { ...@@ -250,10 +250,10 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
} }
TEST_F(TqMetaUpdateAppendTest, dupCommit) { TEST_F(TqMetaUpdateAppendTest, dupCommit) {
srand(0); taosSeedRand(0);
std::vector<int> v; std::vector<int> v;
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
v.push_back(rand()); v.push_back(taosRand());
Foo foo; Foo foo;
foo.a = v[i]; foo.a = v[i];
tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo)); tqHandleCopyPut(pMeta, i, &foo, sizeof(Foo));
......
...@@ -929,7 +929,7 @@ int32_t ctgGetTableMetaFromVnode(SCatalog* pCtg, void *pTrans, const SEpSet* pMg ...@@ -929,7 +929,7 @@ int32_t ctgGetTableMetaFromVnode(SCatalog* pCtg, void *pTrans, const SEpSet* pMg
}; };
SRpcMsg rpcRsp = {0}; SRpcMsg rpcRsp = {0};
rpcSendRecv(pTrans, &vgroupInfo->epset, &rpcMsg, &rpcRsp); rpcSendRecv(pTrans, &vgroupInfo->epSet, &rpcMsg, &rpcRsp);
if (TSDB_CODE_SUCCESS != rpcRsp.code) { if (TSDB_CODE_SUCCESS != rpcRsp.code) {
if (CTG_TABLE_NOT_EXIST(rpcRsp.code)) { if (CTG_TABLE_NOT_EXIST(rpcRsp.code)) {
......
...@@ -228,10 +228,10 @@ void ctgTestBuildDBVgroup(SDBVgInfo **pdbVgroup) { ...@@ -228,10 +228,10 @@ void ctgTestBuildDBVgroup(SDBVgInfo **pdbVgroup) {
vgInfo.vgId = i + 1; vgInfo.vgId = i + 1;
vgInfo.hashBegin = i * hashUnit; vgInfo.hashBegin = i * hashUnit;
vgInfo.hashEnd = hashUnit * (i + 1) - 1; vgInfo.hashEnd = hashUnit * (i + 1) - 1;
vgInfo.epset.numOfEps = i % TSDB_MAX_REPLICA + 1; vgInfo.epSet.numOfEps = i % TSDB_MAX_REPLICA + 1;
vgInfo.epset.inUse = i % vgInfo.epset.numOfEps; vgInfo.epSet.inUse = i % vgInfo.epSet.numOfEps;
for (int32_t n = 0; n < vgInfo.epset.numOfEps; ++n) { for (int32_t n = 0; n < vgInfo.epSet.numOfEps; ++n) {
SEp *addr = &vgInfo.epset.eps[n]; SEp *addr = &vgInfo.epSet.eps[n];
strcpy(addr->fqdn, "a0"); strcpy(addr->fqdn, "a0");
addr->port = n + 22; addr->port = n + 22;
} }
...@@ -301,10 +301,10 @@ void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg * ...@@ -301,10 +301,10 @@ void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *
vg.hashEnd = htonl(UINT32_MAX); vg.hashEnd = htonl(UINT32_MAX);
} }
vg.epset.numOfEps = i % TSDB_MAX_REPLICA + 1; vg.epSet.numOfEps = i % TSDB_MAX_REPLICA + 1;
vg.epset.inUse = i % vg.epset.numOfEps; vg.epSet.inUse = i % vg.epSet.numOfEps;
for (int32_t n = 0; n < vg.epset.numOfEps; ++n) { for (int32_t n = 0; n < vg.epSet.numOfEps; ++n) {
SEp *addr = &vg.epset.eps[n]; SEp *addr = &vg.epSet.eps[n];
strcpy(addr->fqdn, "a0"); strcpy(addr->fqdn, "a0");
addr->port = n + 22; addr->port = n + 22;
} }
...@@ -723,7 +723,7 @@ void *ctgTestGetDbVgroupThread(void *param) { ...@@ -723,7 +723,7 @@ void *ctgTestGetDbVgroupThread(void *param) {
} }
if (ctgTestEnableSleep) { if (ctgTestEnableSleep) {
usleep(rand() % 5); usleep(taosRand() % 5);
} }
if (++n % ctgTestPrintNum == 0) { if (++n % ctgTestPrintNum == 0) {
printf("Get:%d\n", n); printf("Get:%d\n", n);
...@@ -747,7 +747,7 @@ void *ctgTestSetSameDbVgroupThread(void *param) { ...@@ -747,7 +747,7 @@ void *ctgTestSetSameDbVgroupThread(void *param) {
} }
if (ctgTestEnableSleep) { if (ctgTestEnableSleep) {
usleep(rand() % 5); usleep(taosRand() % 5);
} }
if (++n % ctgTestPrintNum == 0) { if (++n % ctgTestPrintNum == 0) {
printf("Set:%d\n", n); printf("Set:%d\n", n);
...@@ -771,7 +771,7 @@ void *ctgTestSetDiffDbVgroupThread(void *param) { ...@@ -771,7 +771,7 @@ void *ctgTestSetDiffDbVgroupThread(void *param) {
} }
if (ctgTestEnableSleep) { if (ctgTestEnableSleep) {
usleep(rand() % 5); usleep(taosRand() % 5);
} }
if (++n % ctgTestPrintNum == 0) { if (++n % ctgTestPrintNum == 0) {
printf("Set:%d\n", n); printf("Set:%d\n", n);
...@@ -801,7 +801,7 @@ void *ctgTestGetCtableMetaThread(void *param) { ...@@ -801,7 +801,7 @@ void *ctgTestGetCtableMetaThread(void *param) {
tfree(tbMeta); tfree(tbMeta);
if (ctgTestEnableSleep) { if (ctgTestEnableSleep) {
usleep(rand() % 5); usleep(taosRand() % 5);
} }
if (++n % ctgTestPrintNum == 0) { if (++n % ctgTestPrintNum == 0) {
...@@ -838,7 +838,7 @@ void *ctgTestSetCtableMetaThread(void *param) { ...@@ -838,7 +838,7 @@ void *ctgTestSetCtableMetaThread(void *param) {
} }
if (ctgTestEnableSleep) { if (ctgTestEnableSleep) {
usleep(rand() % 5); usleep(taosRand() % 5);
} }
if (++n % ctgTestPrintNum == 0) { if (++n % ctgTestPrintNum == 0) {
printf("Set:%d\n", n); printf("Set:%d\n", n);
...@@ -877,7 +877,7 @@ TEST(tableMeta, normalTable) { ...@@ -877,7 +877,7 @@ TEST(tableMeta, normalTable) {
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(vgInfo.vgId, 8); ASSERT_EQ(vgInfo.vgId, 8);
ASSERT_EQ(vgInfo.epset.numOfEps, 3); ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) { while (0 == ctgDbgGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) {
usleep(50000); usleep(50000);
...@@ -1384,7 +1384,7 @@ TEST(refreshGetMeta, normal2normal) { ...@@ -1384,7 +1384,7 @@ TEST(refreshGetMeta, normal2normal) {
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(vgInfo.vgId, 8); ASSERT_EQ(vgInfo.vgId, 8);
ASSERT_EQ(vgInfo.epset.numOfEps, 3); ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
while (true) { while (true) {
uint64_t n = 0; uint64_t n = 0;
...@@ -1463,7 +1463,7 @@ TEST(refreshGetMeta, normal2notexist) { ...@@ -1463,7 +1463,7 @@ TEST(refreshGetMeta, normal2notexist) {
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(vgInfo.vgId, 8); ASSERT_EQ(vgInfo.vgId, 8);
ASSERT_EQ(vgInfo.epset.numOfEps, 3); ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
while (true) { while (true) {
uint64_t n = 0; uint64_t n = 0;
...@@ -1537,7 +1537,7 @@ TEST(refreshGetMeta, normal2child) { ...@@ -1537,7 +1537,7 @@ TEST(refreshGetMeta, normal2child) {
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(vgInfo.vgId, 8); ASSERT_EQ(vgInfo.vgId, 8);
ASSERT_EQ(vgInfo.epset.numOfEps, 3); ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
while (true) { while (true) {
uint64_t n = 0; uint64_t n = 0;
...@@ -1621,7 +1621,7 @@ TEST(refreshGetMeta, stable2child) { ...@@ -1621,7 +1621,7 @@ TEST(refreshGetMeta, stable2child) {
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(vgInfo.vgId, 8); ASSERT_EQ(vgInfo.vgId, 8);
ASSERT_EQ(vgInfo.epset.numOfEps, 3); ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
while (true) { while (true) {
uint64_t n = 0; uint64_t n = 0;
...@@ -1706,7 +1706,7 @@ TEST(refreshGetMeta, stable2stable) { ...@@ -1706,7 +1706,7 @@ TEST(refreshGetMeta, stable2stable) {
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(vgInfo.vgId, 8); ASSERT_EQ(vgInfo.vgId, 8);
ASSERT_EQ(vgInfo.epset.numOfEps, 3); ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
while (true) { while (true) {
uint64_t n = 0; uint64_t n = 0;
...@@ -1794,7 +1794,7 @@ TEST(refreshGetMeta, child2stable) { ...@@ -1794,7 +1794,7 @@ TEST(refreshGetMeta, child2stable) {
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(vgInfo.vgId, 8); ASSERT_EQ(vgInfo.vgId, 8);
ASSERT_EQ(vgInfo.epset.numOfEps, 3); ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
while (true) { while (true) {
uint64_t n = 0; uint64_t n = 0;
...@@ -1879,7 +1879,7 @@ TEST(tableDistVgroup, normalTable) { ...@@ -1879,7 +1879,7 @@ TEST(tableDistVgroup, normalTable) {
ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1); ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0); vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
ASSERT_EQ(vgInfo->vgId, 8); ASSERT_EQ(vgInfo->vgId, 8);
ASSERT_EQ(vgInfo->epset.numOfEps, 3); ASSERT_EQ(vgInfo->epSet.numOfEps, 3);
catalogDestroy(); catalogDestroy();
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
...@@ -1921,7 +1921,7 @@ TEST(tableDistVgroup, childTableCase) { ...@@ -1921,7 +1921,7 @@ TEST(tableDistVgroup, childTableCase) {
ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1); ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0); vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
ASSERT_EQ(vgInfo->vgId, 9); ASSERT_EQ(vgInfo->vgId, 9);
ASSERT_EQ(vgInfo->epset.numOfEps, 4); ASSERT_EQ(vgInfo->epSet.numOfEps, 4);
catalogDestroy(); catalogDestroy();
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
...@@ -1964,13 +1964,13 @@ TEST(tableDistVgroup, superTableCase) { ...@@ -1964,13 +1964,13 @@ TEST(tableDistVgroup, superTableCase) {
ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 10); ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 10);
vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0); vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
ASSERT_EQ(vgInfo->vgId, 1); ASSERT_EQ(vgInfo->vgId, 1);
ASSERT_EQ(vgInfo->epset.numOfEps, 1); ASSERT_EQ(vgInfo->epSet.numOfEps, 1);
vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 1); vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 1);
ASSERT_EQ(vgInfo->vgId, 2); ASSERT_EQ(vgInfo->vgId, 2);
ASSERT_EQ(vgInfo->epset.numOfEps, 2); ASSERT_EQ(vgInfo->epSet.numOfEps, 2);
vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 2); vgInfo = (SVgroupInfo *)taosArrayGet(vgList, 2);
ASSERT_EQ(vgInfo->vgId, 3); ASSERT_EQ(vgInfo->vgId, 3);
ASSERT_EQ(vgInfo->epset.numOfEps, 3); ASSERT_EQ(vgInfo->epSet.numOfEps, 3);
catalogDestroy(); catalogDestroy();
memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); memset(&gCtgMgmt, 0, sizeof(gCtgMgmt));
...@@ -2025,14 +2025,14 @@ TEST(dbVgroup, getSetDbVgroupCase) { ...@@ -2025,14 +2025,14 @@ TEST(dbVgroup, getSetDbVgroupCase) {
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(vgInfo.vgId, 8); ASSERT_EQ(vgInfo.vgId, 8);
ASSERT_EQ(vgInfo.epset.numOfEps, 3); ASSERT_EQ(vgInfo.epSet.numOfEps, 3);
code = catalogGetTableDistVgInfo(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList); code = catalogGetTableDistVgInfo(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1); ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
pvgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0); pvgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
ASSERT_EQ(pvgInfo->vgId, 8); ASSERT_EQ(pvgInfo->vgId, 8);
ASSERT_EQ(pvgInfo->epset.numOfEps, 3); ASSERT_EQ(pvgInfo->epSet.numOfEps, 3);
taosArrayDestroy(vgList); taosArrayDestroy(vgList);
ctgTestBuildDBVgroup(&dbVgroup); ctgTestBuildDBVgroup(&dbVgroup);
...@@ -2053,14 +2053,14 @@ TEST(dbVgroup, getSetDbVgroupCase) { ...@@ -2053,14 +2053,14 @@ TEST(dbVgroup, getSetDbVgroupCase) {
code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo); code = catalogGetTableHashVgroup(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgInfo);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(vgInfo.vgId, 7); ASSERT_EQ(vgInfo.vgId, 7);
ASSERT_EQ(vgInfo.epset.numOfEps, 2); ASSERT_EQ(vgInfo.epSet.numOfEps, 2);
code = catalogGetTableDistVgInfo(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList); code = catalogGetTableDistVgInfo(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &vgList);
ASSERT_EQ(code, 0); ASSERT_EQ(code, 0);
ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1); ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), 1);
pvgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0); pvgInfo = (SVgroupInfo *)taosArrayGet(vgList, 0);
ASSERT_EQ(pvgInfo->vgId, 8); ASSERT_EQ(pvgInfo->vgId, 8);
ASSERT_EQ(pvgInfo->epset.numOfEps, 3); ASSERT_EQ(pvgInfo->epSet.numOfEps, 3);
taosArrayDestroy(vgList); taosArrayDestroy(vgList);
catalogDestroy(); catalogDestroy();
......
...@@ -92,10 +92,11 @@ typedef struct SResultRowPool { ...@@ -92,10 +92,11 @@ typedef struct SResultRowPool {
struct STaskAttr; struct STaskAttr;
struct STaskRuntimeEnv; struct STaskRuntimeEnv;
struct SUdfInfo; struct SUdfInfo;
struct SqlFunctionCtx;
int32_t getOutputInterResultBufSize(struct STaskAttr* pQueryAttr); int32_t getOutputInterResultBufSize(struct STaskAttr* pQueryAttr);
size_t getResultRowSize(SArray* pExprInfo); size_t getResultRowSize(struct SqlFunctionCtx* pCtx, int32_t numOfOutput);
int32_t initResultRowInfo(SResultRowInfo* pResultRowInfo, int32_t size); int32_t initResultRowInfo(SResultRowInfo* pResultRowInfo, int32_t size);
void cleanupResultRowInfo(SResultRowInfo* pResultRowInfo); void cleanupResultRowInfo(SResultRowInfo* pResultRowInfo);
......
...@@ -441,13 +441,20 @@ typedef struct SStreamBlockScanInfo { ...@@ -441,13 +441,20 @@ typedef struct SStreamBlockScanInfo {
} SStreamBlockScanInfo; } SStreamBlockScanInfo;
typedef struct SSysTableScanInfo { typedef struct SSysTableScanInfo {
void *pTransporter; union {
void* pTransporter;
void* readHandle;
};
void *pCur; // cursor
SRetrieveTableReq* pReq;
SEpSet epSet; SEpSet epSet;
int32_t type; // show type int32_t type; // show type
tsem_t ready; tsem_t ready;
void *readHandle; SSchema* pSchema;
SSchema *pSchema; SSDataBlock* pRes;
SSDataBlock *pRes;
int32_t capacity;
int64_t numOfBlocks; // extract basic running information. int64_t numOfBlocks; // extract basic running information.
int64_t totalRows; int64_t totalRows;
int64_t elapsedTime; int64_t elapsedTime;
...@@ -462,12 +469,14 @@ typedef struct SOptrBasicInfo { ...@@ -462,12 +469,14 @@ typedef struct SOptrBasicInfo {
int32_t capacity; int32_t capacity;
} SOptrBasicInfo; } SOptrBasicInfo;
//TODO move the resultrowsiz together with SOptrBasicInfo:rowCellInfoOffset
typedef struct SAggSupporter { typedef struct SAggSupporter {
SHashObj* pResultRowHashTable; // quick locate the window object for each result SHashObj* pResultRowHashTable; // quick locate the window object for each result
SHashObj* pResultRowListSet; // used to check if current ResultRowInfo has ResultRow object or not SHashObj* pResultRowListSet; // used to check if current ResultRowInfo has ResultRow object or not
SArray* pResultRowArrayList; // The array list that contains the Result rows SArray* pResultRowArrayList; // The array list that contains the Result rows
char* keyBuf; // window key buffer char* keyBuf; // window key buffer
SResultRowPool *pool; // The window result objects pool, all the resultRow Objects are allocated and managed by this object. SResultRowPool *pool; // The window result objects pool, all the resultRow Objects are allocated and managed by this object.
int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row
} SAggSupporter; } SAggSupporter;
typedef struct STableIntervalOperatorInfo { typedef struct STableIntervalOperatorInfo {
...@@ -623,14 +632,15 @@ typedef struct SOrderOperatorInfo { ...@@ -623,14 +632,15 @@ typedef struct SOrderOperatorInfo {
uint64_t totalElapsed; // total elapsed time uint64_t totalElapsed; // total elapsed time
} SOrderOperatorInfo; } SOrderOperatorInfo;
SOperatorInfo* createExchangeOperatorInfo(const SArray* pSources, const SArray* pExprInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput,
int32_t repeatTime, int32_t reverseTime, SExecTaskInfo* pTaskInfo); int32_t repeatTime, int32_t reverseTime, SExecTaskInfo* pTaskInfo);
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv); SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv);
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo);
SOperatorInfo* createSystemScanOperatorInfo(void* pSystemTableReadHandle, const SArray* pExprInfo, const SSchema* pSchema, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, const SArray* pExprInfo, const SSchema* pSchema,
int32_t tableType, SEpSet epset, SExecTaskInfo* pTaskInfo);
SOperatorInfo* createLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream); SOperatorInfo* createLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream);
SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SInterval* pInterval, SExecTaskInfo* pTaskInfo); SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SInterval* pInterval, SExecTaskInfo* pTaskInfo);
......
...@@ -46,7 +46,7 @@ int32_t getOutputInterResultBufSize(STaskAttr* pQueryAttr) { ...@@ -46,7 +46,7 @@ int32_t getOutputInterResultBufSize(STaskAttr* pQueryAttr) {
int32_t size = 0; int32_t size = 0;
for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) { for (int32_t i = 0; i < pQueryAttr->numOfOutput; ++i) {
size += pQueryAttr->pExpr1[i].base.interBytes; // size += pQueryAttr->pExpr1[i].base.interBytes;
} }
assert(size >= 0); assert(size >= 0);
...@@ -172,9 +172,14 @@ SResultRowEntryInfo* getResultCell(const SResultRow* pRow, int32_t index, int32_ ...@@ -172,9 +172,14 @@ SResultRowEntryInfo* getResultCell(const SResultRow* pRow, int32_t index, int32_
return (SResultRowEntryInfo*)((char*) pRow->pEntryInfo + offset[index]); return (SResultRowEntryInfo*)((char*) pRow->pEntryInfo + offset[index]);
} }
size_t getResultRowSize(SArray* pExprInfo) { size_t getResultRowSize(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
size_t numOfOutput = taosArrayGetSize(pExprInfo); int32_t rowSize = (numOfOutput * sizeof(SResultRowEntryInfo)) + sizeof(SResultRow);
return (numOfOutput * sizeof(SResultRowEntryInfo)) + /*pQueryAttr->interBufSize +*/ sizeof(SResultRow);
for(int32_t i = 0; i < numOfOutput; ++i) {
rowSize += pCtx[i].resDataInfo.interBufSize;
}
return rowSize;
} }
SResultRowPool* initResultRowPool(size_t size) { SResultRowPool* initResultRowPool(size_t size) {
......
...@@ -1006,7 +1006,7 @@ TEST(testCase, external_sort_Test) { ...@@ -1006,7 +1006,7 @@ TEST(testCase, external_sort_Test) {
#if 0 #if 0
su* v = static_cast<su*>(calloc(1000000, sizeof(su))); su* v = static_cast<su*>(calloc(1000000, sizeof(su)));
for(int32_t i = 0; i < 1000000; ++i) { for(int32_t i = 0; i < 1000000; ++i) {
v[i].v = rand(); v[i].v = taosRand();
v[i].c = static_cast<char*>(malloc(4)); v[i].c = static_cast<char*>(malloc(4));
*(int32_t*) v[i].c = i; *(int32_t*) v[i].c = i;
} }
...@@ -1019,7 +1019,7 @@ TEST(testCase, external_sort_Test) { ...@@ -1019,7 +1019,7 @@ TEST(testCase, external_sort_Test) {
return; return;
#endif #endif
srand(time(NULL)); taosSeedRand(time(NULL));
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0}; SOrder o = {0};
...@@ -1080,7 +1080,7 @@ TEST(testCase, external_sort_Test) { ...@@ -1080,7 +1080,7 @@ TEST(testCase, external_sort_Test) {
} }
TEST(testCase, sorted_merge_Test) { TEST(testCase, sorted_merge_Test) {
srand(time(NULL)); taosSeedRand(time(NULL));
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0}; SOrder o = {0};
...@@ -1152,7 +1152,7 @@ TEST(testCase, sorted_merge_Test) { ...@@ -1152,7 +1152,7 @@ TEST(testCase, sorted_merge_Test) {
} }
TEST(testCase, time_interval_Operator_Test) { TEST(testCase, time_interval_Operator_Test) {
srand(time(NULL)); taosSeedRand(time(NULL));
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder)); SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0}; SOrder o = {0};
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-compare"
TEST(testCase, linear_hash_Tests) { TEST(testCase, linear_hash_Tests) {
srand(time(NULL)); taosSeedRand(time(NULL));
_hash_fn_t fn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT); _hash_fn_t fn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT);
#if 0 #if 0
......
...@@ -31,6 +31,12 @@ void countFunction(SqlFunctionCtx *pCtx); ...@@ -31,6 +31,12 @@ void countFunction(SqlFunctionCtx *pCtx);
bool getSumFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); bool getSumFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
void sumFunction(SqlFunctionCtx *pCtx); void sumFunction(SqlFunctionCtx *pCtx);
bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
bool getMinmaxFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
void minFunction(SqlFunctionCtx* pCtx);
void maxFunction(SqlFunctionCtx *pCtx);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -41,6 +41,26 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { ...@@ -41,6 +41,26 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.processFunc = sumFunction, .processFunc = sumFunction,
.finalizeFunc = functionFinalizer .finalizeFunc = functionFinalizer
}, },
{
.name = "min",
.type = FUNCTION_TYPE_MIN,
.classification = FUNC_MGT_AGG_FUNC,
.checkFunc = stubCheckAndGetResultType,
.getEnvFunc = getMinmaxFuncEnv,
.initFunc = minFunctionSetup,
.processFunc = minFunction,
.finalizeFunc = functionFinalizer
},
{
.name = "max",
.type = FUNCTION_TYPE_MAX,
.classification = FUNC_MGT_AGG_FUNC,
.checkFunc = stubCheckAndGetResultType,
.getEnvFunc = getMinmaxFuncEnv,
.initFunc = maxFunctionSetup,
.processFunc = maxFunction,
.finalizeFunc = functionFinalizer
},
{ {
.name = "concat", .name = "concat",
.type = FUNCTION_TYPE_CONCAT, .type = FUNCTION_TYPE_CONCAT,
...@@ -53,14 +73,44 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { ...@@ -53,14 +73,44 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
} }
}; };
const int funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition)); const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition));
int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) {
switch(pFunc->funcType) { switch(pFunc->funcType) {
case FUNCTION_TYPE_COUNT: pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT};break; case FUNCTION_TYPE_COUNT:
default: pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT};
break;
case FUNCTION_TYPE_SUM: {
SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
int32_t paraType = pParam->node.resType.type;
int32_t resType = 0;
if (IS_SIGNED_NUMERIC_TYPE(paraType)) {
resType = TSDB_DATA_TYPE_BIGINT;
} else if (IS_UNSIGNED_NUMERIC_TYPE(paraType)) {
resType = TSDB_DATA_TYPE_UBIGINT;
} else if (IS_FLOAT_TYPE(paraType)) {
resType = TSDB_DATA_TYPE_DOUBLE;
} else {
ASSERT(0);
}
pFunc->node.resType = (SDataType) { .bytes = tDataTypes[resType].bytes, .type = resType };
break; break;
} }
case FUNCTION_TYPE_MIN:
case FUNCTION_TYPE_MAX: {
SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
int32_t paraType = pParam->node.resType.type;
pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType };
break;
}
case FUNCTION_TYPE_CONCAT:
// todo
break;
default:
ASSERT(0); // to found the fault ASAP.
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include "builtinsimpl.h" #include "builtinsimpl.h"
#include "querynodes.h"
#include "taggfunction.h" #include "taggfunction.h"
#include "tdatablock.h" #include "tdatablock.h"
...@@ -27,7 +28,6 @@ ...@@ -27,7 +28,6 @@
} while (0) } while (0)
typedef struct SSumRes { typedef struct SSumRes {
// int8_t hasResult;
union { union {
int64_t isum; int64_t isum;
uint64_t usum; uint64_t usum;
...@@ -115,7 +115,7 @@ void countFunction(SqlFunctionCtx *pCtx) { ...@@ -115,7 +115,7 @@ void countFunction(SqlFunctionCtx *pCtx) {
} \ } \
} while (0) } while (0)
static void do_sum(SqlFunctionCtx *pCtx) { void sumFunction(SqlFunctionCtx *pCtx) {
int32_t numOfElem = 0; int32_t numOfElem = 0;
// Only the pre-computing information loaded and actual data does not loaded // Only the pre-computing information loaded and actual data does not loaded
...@@ -123,17 +123,18 @@ static void do_sum(SqlFunctionCtx *pCtx) { ...@@ -123,17 +123,18 @@ static void do_sum(SqlFunctionCtx *pCtx) {
SColumnDataAgg *pAgg = pInput->pColumnDataAgg[0]; SColumnDataAgg *pAgg = pInput->pColumnDataAgg[0];
int32_t type = pInput->pData[0]->info.type; int32_t type = pInput->pData[0]->info.type;
SSumRes* pSumRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
if (pInput->colDataAggIsSet) { if (pInput->colDataAggIsSet) {
numOfElem = pInput->numOfRows - pAgg->numOfNull; numOfElem = pInput->numOfRows - pAgg->numOfNull;
ASSERT(numOfElem >= 0); ASSERT(numOfElem >= 0);
SSumRes* pSumInfo = (SSumRes*) pCtx->pOutput;
if (IS_SIGNED_NUMERIC_TYPE(type)) { if (IS_SIGNED_NUMERIC_TYPE(type)) {
pSumInfo->isum += pAgg->sum; pSumRes->isum += pAgg->sum;
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) { } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
pSumInfo->usum += pAgg->sum; pSumRes->usum += pAgg->sum;
} else if (IS_FLOAT_TYPE(type)) { } else if (IS_FLOAT_TYPE(type)) {
pSumInfo->dsum += GET_DOUBLE_VAL((const char*)&(pAgg->sum)); pSumRes->dsum += GET_DOUBLE_VAL((const char*)&(pAgg->sum));
} }
} else { // computing based on the true data block } else { // computing based on the true data block
SColumnInfoData* pCol = pInput->pData[0]; SColumnInfoData* pCol = pInput->pData[0];
...@@ -141,32 +142,30 @@ static void do_sum(SqlFunctionCtx *pCtx) { ...@@ -141,32 +142,30 @@ static void do_sum(SqlFunctionCtx *pCtx) {
int32_t start = pInput->startRowIndex; int32_t start = pInput->startRowIndex;
int32_t numOfRows = pInput->numOfRows; int32_t numOfRows = pInput->numOfRows;
SSumRes* pSum = (SSumRes*) pCtx->pOutput; if (IS_SIGNED_NUMERIC_TYPE(type)) {
if (type == TSDB_DATA_TYPE_TINYINT) {
if (IS_SIGNED_NUMERIC_TYPE(pCtx->inputType)) { LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int8_t, numOfElem);
if (pCtx->inputType == TSDB_DATA_TYPE_TINYINT) { } else if (type == TSDB_DATA_TYPE_SMALLINT) {
LIST_ADD_N(pSum->isum, pCol, start, numOfRows, int8_t, numOfElem); LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int16_t, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_SMALLINT) { } else if (type == TSDB_DATA_TYPE_INT) {
LIST_ADD_N(pSum->isum, pCol, start, numOfRows, int16_t, numOfElem); LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int32_t, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_INT) { } else if (type == TSDB_DATA_TYPE_BIGINT) {
LIST_ADD_N(pSum->isum, pCol, start, numOfRows, int32_t, numOfElem); LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int64_t, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_BIGINT) {
LIST_ADD_N(pSum->isum, pCol, start, numOfRows, int64_t, numOfElem);
} }
} else if (IS_UNSIGNED_NUMERIC_TYPE(pCtx->inputType)) { } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
if (pCtx->inputType == TSDB_DATA_TYPE_UTINYINT) { if (type == TSDB_DATA_TYPE_UTINYINT) {
LIST_ADD_N(pSum->usum, pCol, start, numOfRows, uint8_t, numOfElem); LIST_ADD_N(pSumRes->usum, pCol, start, numOfRows, uint8_t, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_USMALLINT) { } else if (type == TSDB_DATA_TYPE_USMALLINT) {
LIST_ADD_N(pSum->usum, pCol, start, numOfRows, uint16_t, numOfElem); LIST_ADD_N(pSumRes->usum, pCol, start, numOfRows, uint16_t, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_UINT) { } else if (type == TSDB_DATA_TYPE_UINT) {
LIST_ADD_N(pSum->usum, pCol, start, numOfRows, uint32_t, numOfElem); LIST_ADD_N(pSumRes->usum, pCol, start, numOfRows, uint32_t, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_UBIGINT) { } else if (type == TSDB_DATA_TYPE_UBIGINT) {
LIST_ADD_N(pSum->usum, pCol, start, numOfRows, uint64_t, numOfElem); LIST_ADD_N(pSumRes->usum, pCol, start, numOfRows, uint64_t, numOfElem);
} }
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) { } else if (type == TSDB_DATA_TYPE_DOUBLE) {
LIST_ADD_N(pSum->dsum, pCol, start, numOfRows, double, numOfElem); LIST_ADD_N(pSumRes->dsum, pCol, start, numOfRows, double, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT) { } else if (type == TSDB_DATA_TYPE_FLOAT) {
LIST_ADD_N(pSum->dsum, pCol, start, numOfRows, float, numOfElem); LIST_ADD_N(pSumRes->dsum, pCol, start, numOfRows, float, numOfElem);
} }
} }
...@@ -179,14 +178,271 @@ bool getSumFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) { ...@@ -179,14 +178,271 @@ bool getSumFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
return true; return true;
} }
void sumFunction(SqlFunctionCtx *pCtx) { bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) {
do_sum(pCtx); if (!functionSetup(pCtx, pResultInfo)) {
return false;
// keep the result data in output buffer, not in the intermediate buffer }
// SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
// if (pResInfo->hasResult == DATA_SET_FLAG) { char* buf = GET_ROWCELL_INTERBUF(pResultInfo);
// set the flag for super table query switch (pCtx->resDataInfo.type) {
// SSumRes *pSum = (SSumRes *)pCtx->pOutput; case TSDB_DATA_TYPE_INT:
// pSum->hasResult = DATA_SET_FLAG; *((int32_t *)buf) = INT32_MIN;
// } break;
case TSDB_DATA_TYPE_UINT:
*((uint32_t *)buf) = 0;
break;
case TSDB_DATA_TYPE_FLOAT:
*((float *)buf) = -FLT_MAX;
break;
case TSDB_DATA_TYPE_DOUBLE:
SET_DOUBLE_VAL(((double *)buf), -DBL_MAX);
break;
case TSDB_DATA_TYPE_BIGINT:
*((int64_t *)buf) = INT64_MIN;
break;
case TSDB_DATA_TYPE_UBIGINT:
*((uint64_t *)buf) = 0;
break;
case TSDB_DATA_TYPE_SMALLINT:
*((int16_t *)buf) = INT16_MIN;
break;
case TSDB_DATA_TYPE_USMALLINT:
*((uint16_t *)buf) = 0;
break;
case TSDB_DATA_TYPE_TINYINT:
*((int8_t *)buf) = INT8_MIN;
break;
case TSDB_DATA_TYPE_UTINYINT:
*((uint8_t *)buf) = 0;
break;
default:
assert(0);
}
return true;
}
bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) {
if (!functionSetup(pCtx, pResultInfo)) {
return false; // not initialized since it has been initialized
}
char* buf = GET_ROWCELL_INTERBUF(pResultInfo);
switch (pCtx->resDataInfo.type) {
case TSDB_DATA_TYPE_TINYINT:
*((int8_t *)buf) = INT8_MAX;
break;
case TSDB_DATA_TYPE_UTINYINT:
*(uint8_t *) buf = UINT8_MAX;
break;
case TSDB_DATA_TYPE_SMALLINT:
*((int16_t *)buf) = INT16_MAX;
break;
case TSDB_DATA_TYPE_USMALLINT:
*((uint16_t *)buf) = UINT16_MAX;
break;
case TSDB_DATA_TYPE_INT:
*((int32_t *)buf) = INT32_MAX;
break;
case TSDB_DATA_TYPE_UINT:
*((uint32_t *)buf) = UINT32_MAX;
break;
case TSDB_DATA_TYPE_BIGINT:
*((int64_t *)buf) = INT64_MAX;
break;
case TSDB_DATA_TYPE_UBIGINT:
*((uint64_t *)buf) = UINT64_MAX;
break;
case TSDB_DATA_TYPE_FLOAT:
*((float *)buf) = FLT_MAX;
break;
case TSDB_DATA_TYPE_DOUBLE:
SET_DOUBLE_VAL(((double *)buf), DBL_MAX);
break;
default:
assert(0);
}
return true;
}
bool getMinmaxFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
SNode* pNode = nodesListGetNode(pFunc->pParameterList, 0);
pEnv->calcMemSize = sizeof(int64_t);
return true;
}
#define GET_TS_LIST(x) ((TSKEY*)((x)->ptsList))
#define GET_TS_DATA(x, y) (GET_TS_LIST(x)[(y)])
#define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \
do { \
for (int32_t _i = 0; _i < (ctx)->tagInfo.numOfTagCols; ++_i) { \
SqlFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[_i]; \
__ctx->fpSet.process(__ctx); \
} \
} while (0);
#define DO_UPDATE_SUBSID_RES(ctx, ts) \
do { \
for (int32_t _i = 0; _i < (ctx)->subsidiaryRes.numOfCols; ++_i) { \
SqlFunctionCtx *__ctx = (ctx)->subsidiaryRes.pCtx[_i]; \
if (__ctx->functionId == FUNCTION_TS_DUMMY) { \
__ctx->tag.i = (ts); \
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; \
} \
__ctx->fpSet.process(__ctx); \
} \
} while (0)
#define UPDATE_DATA(ctx, left, right, num, sign, _ts) \
do { \
if (((left) < (right)) ^ (sign)) { \
(left) = (right); \
DO_UPDATE_SUBSID_RES(ctx, _ts); \
(num) += 1; \
} \
} while (0)
#define LOOPCHECK_N(val, _col, ctx, _t, _nrow, _start, sign, num) \
do { \
_t* d = (_t*)((_col)->pData); \
for (int32_t i = (_start); i < (_nrow) + (_start); ++i) { \
if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \
continue; \
} \
TSKEY ts = (ctx)->ptsList != NULL ? GET_TS_DATA(ctx, i) : 0; \
UPDATE_DATA(ctx, val, d[i], num, sign, ts); \
} \
} while (0)
int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) {
int32_t numOfElems = 0;
SInputColumnInfoData* pInput = &pCtx->input;
SColumnDataAgg *pAgg = pInput->pColumnDataAgg[0];
SColumnInfoData* pCol = pInput->pData[0];
int32_t type = pCol->info.type;
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
char* buf = GET_ROWCELL_INTERBUF(pResInfo);
// data in current data block are qualified to the query
if (pInput->colDataAggIsSet) {
numOfElems = pInput->numOfRows - pAgg->numOfNull;
ASSERT(pInput->numOfRows == pInput->totalRows && numOfElems >= 0);
if (numOfElems == 0) {
return numOfElems;
}
void* tval = NULL;
int16_t index = 0;
if (isMinFunc) {
tval = &pInput->pColumnDataAgg[0]->min;
index = pInput->pColumnDataAgg[0]->minIndex;
} else {
tval = &pInput->pColumnDataAgg[0]->max;
index = pInput->pColumnDataAgg[0]->maxIndex;
}
TSKEY key = TSKEY_INITIAL_VAL;
if (pCtx->ptsList != NULL) {
// the index is the original position, not the relative position
key = pCtx->ptsList[index];
}
if (IS_SIGNED_NUMERIC_TYPE(type)) {
int64_t val = GET_INT64_VAL(tval);
#if defined(_DEBUG_VIEW)
qDebug("max value updated according to pre-cal:%d", *data);
#endif
if ((*(int64_t*)buf < val) ^ isMinFunc) {
*(int64_t*) buf = val;
for (int32_t i = 0; i < (pCtx)->subsidiaryRes.numOfCols; ++i) {
SqlFunctionCtx* __ctx = pCtx->subsidiaryRes.pCtx[i];
if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
__ctx->tag.i = key;
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
}
__ctx->fpSet.process(__ctx);
}
}
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
uint64_t val = GET_UINT64_VAL(tval);
UPDATE_DATA(pCtx, *(uint64_t*)buf, val, numOfElems, isMinFunc, key);
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
double val = GET_DOUBLE_VAL(tval);
UPDATE_DATA(pCtx, *(double*)buf, val, numOfElems, isMinFunc, key);
} else if (type == TSDB_DATA_TYPE_FLOAT) {
double val = GET_DOUBLE_VAL(tval);
UPDATE_DATA(pCtx, *(float*)buf, (float)val, numOfElems, isMinFunc, key);
}
return numOfElems;
}
int32_t start = pInput->startRowIndex;
int32_t numOfRows = pInput->numOfRows;
if (IS_SIGNED_NUMERIC_TYPE(type)) {
if (type == TSDB_DATA_TYPE_TINYINT) {
LOOPCHECK_N(*(int8_t*)buf, pCol, pCtx, int8_t, numOfRows, start, isMinFunc, numOfElems);
} else if (type == TSDB_DATA_TYPE_SMALLINT) {
LOOPCHECK_N(*(int16_t*) buf, pCol, pCtx, int16_t, numOfRows, start, isMinFunc, numOfElems);
} else if (type == TSDB_DATA_TYPE_INT) {
int32_t *pData = (int32_t*)pCol->pData;
int32_t *val = (int32_t*) buf;
for (int32_t i = 0; i < pCtx->size; ++i) {
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
continue;
}
if ((*val < pData[i]) ^ isMinFunc) {
*val = pData[i];
TSKEY ts = (pCtx->ptsList != NULL)? GET_TS_DATA(pCtx, i) : 0;
DO_UPDATE_SUBSID_RES(pCtx, ts);
}
numOfElems += 1;
}
#if defined(_DEBUG_VIEW)
qDebug("max value updated:%d", *retVal);
#endif
} else if (type == TSDB_DATA_TYPE_BIGINT) {
LOOPCHECK_N(*(int64_t*) buf, pCol, pCtx, int64_t, numOfRows, start, isMinFunc, numOfElems);
}
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
if (type == TSDB_DATA_TYPE_UTINYINT) {
LOOPCHECK_N(*(uint8_t*) buf, pCol, pCtx, uint8_t, numOfRows, start, isMinFunc, numOfElems);
} else if (type == TSDB_DATA_TYPE_USMALLINT) {
LOOPCHECK_N(*(uint16_t*) buf, pCol, pCtx, uint16_t, numOfRows, start, isMinFunc, numOfElems);
} else if (type == TSDB_DATA_TYPE_UINT) {
LOOPCHECK_N(*(uint32_t*) buf, pCol, pCtx, uint32_t, numOfRows, start, isMinFunc, numOfElems);
} else if (type == TSDB_DATA_TYPE_UBIGINT) {
LOOPCHECK_N(*(uint64_t*) buf, pCol, pCtx, uint64_t, numOfRows, start, isMinFunc, numOfElems);
}
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
LOOPCHECK_N(*(double*) buf, pCol, pCtx, double, numOfRows, start, isMinFunc, numOfElems);
} else if (type == TSDB_DATA_TYPE_FLOAT) {
LOOPCHECK_N(*(float*) buf, pCol, pCtx, float, numOfRows, start, isMinFunc, numOfElems);
}
return numOfElems;
}
void minFunction(SqlFunctionCtx *pCtx) {
int32_t numOfElems = doMinMaxHelper(pCtx, 1);
SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1);
}
void maxFunction(SqlFunctionCtx *pCtx) {
int32_t numOfElems = doMinMaxHelper(pCtx, 0);
SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1);
} }
\ No newline at end of file
...@@ -722,13 +722,13 @@ static SArray* tfileGetFileList(const char* path) { ...@@ -722,13 +722,13 @@ static SArray* tfileGetFileList(const char* path) {
uint32_t version; uint32_t version;
SArray* files = taosArrayInit(4, sizeof(void*)); SArray* files = taosArrayInit(4, sizeof(void*));
DIR* dir = opendir(path); TdDirPtr pDir = taosOpenDir(path);
if (NULL == dir) { if (NULL == pDir) {
return NULL; return NULL;
} }
struct dirent* entry; TdDirEntryPtr pDirEntry;
while ((entry = readdir(dir)) != NULL) { while ((pDirEntry = taosReadDir(pDir)) != NULL) {
char* file = entry->d_name; char* file = taosGetDirEntryName(pDirEntry);
if (0 != tfileParseFileName(file, &suid, buf, &version)) { if (0 != tfileParseFileName(file, &suid, buf, &version)) {
continue; continue;
} }
...@@ -738,7 +738,7 @@ static SArray* tfileGetFileList(const char* path) { ...@@ -738,7 +738,7 @@ static SArray* tfileGetFileList(const char* path) {
sprintf(buf, "%s/%s", path, file); sprintf(buf, "%s/%s", path, file);
taosArrayPush(files, &buf); taosArrayPush(files, &buf);
} }
closedir(dir); taosCloseDir(pDir);
taosArraySort(files, tfileCompare); taosArraySort(files, tfileCompare);
tfileRmExpireFile(files); tfileRmExpireFile(files);
......
...@@ -699,7 +699,7 @@ class IndexObj { ...@@ -699,7 +699,7 @@ class IndexObj {
for (int i = 0; i < numOfTable; i++) { for (int i = 0; i < numOfTable; i++) {
for (int k = 0; k < 10 && k < colVal.size(); k++) { for (int k = 0; k < 10 && k < colVal.size(); k++) {
// opt // opt
tColVal[rand() % colValSize] = 'a' + k % 26; tColVal[taosRand() % colValSize] = 'a' + k % 26;
} }
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
tColVal.c_str(), tColVal.size()); tColVal.c_str(), tColVal.size());
......
...@@ -3,7 +3,6 @@ add_library(monitor STATIC ${MONITOR_SRC}) ...@@ -3,7 +3,6 @@ add_library(monitor STATIC ${MONITOR_SRC})
target_include_directories( target_include_directories(
monitor monitor
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/monitor" PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/monitor"
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/transport"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
) )
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "monitor.h" #include "monitor.h"
#include "tarray.h" #include "tarray.h"
#include "tlockfree.h"
#include "tjson.h" #include "tjson.h"
typedef struct { typedef struct {
......
...@@ -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 "nodesint.h" #include "nodesUtil.h"
#include "plannodes.h" #include "plannodes.h"
#include "querynodes.h" #include "querynodes.h"
#include "taos.h" #include "taos.h"
...@@ -60,6 +60,9 @@ ...@@ -60,6 +60,9 @@
#define CLONE_OBJECT_FIELD(fldname, cloneFunc) \ #define CLONE_OBJECT_FIELD(fldname, cloneFunc) \
do { \ do { \
if (NULL == (pSrc)->fldname) { \
break; \
} \
(pDst)->fldname = cloneFunc((pSrc)->fldname); \ (pDst)->fldname = cloneFunc((pSrc)->fldname); \
if (NULL == (pDst)->fldname) { \ if (NULL == (pDst)->fldname) { \
nodesDestroyNode((SNode*)(pDst)); \ nodesDestroyNode((SNode*)(pDst)); \
...@@ -234,10 +237,17 @@ static SNode* logicProjectCopy(const SProjectLogicNode* pSrc, SProjectLogicNode* ...@@ -234,10 +237,17 @@ static SNode* logicProjectCopy(const SProjectLogicNode* pSrc, SProjectLogicNode*
} }
static SNode* logicVnodeModifCopy(const SVnodeModifLogicNode* pSrc, SVnodeModifLogicNode* pDst) { static SNode* logicVnodeModifCopy(const SVnodeModifLogicNode* pSrc, SVnodeModifLogicNode* pDst) {
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
COPY_SCALAR_FIELD(msgType); COPY_SCALAR_FIELD(msgType);
return (SNode*)pDst; return (SNode*)pDst;
} }
static SNode* logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNode* pDst) {
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
COPY_SCALAR_FIELD(srcGroupId);
return (SNode*)pDst;
}
static SNode* logicSubplanCopy(const SSubLogicPlan* pSrc, SSubLogicPlan* pDst) { static SNode* logicSubplanCopy(const SSubLogicPlan* pSrc, SSubLogicPlan* pDst) {
CLONE_NODE_FIELD(pNode); CLONE_NODE_FIELD(pNode);
COPY_SCALAR_FIELD(subplanType); COPY_SCALAR_FIELD(subplanType);
...@@ -261,6 +271,13 @@ static SNode* slotDescCopy(const SSlotDescNode* pSrc, SSlotDescNode* pDst) { ...@@ -261,6 +271,13 @@ static SNode* slotDescCopy(const SSlotDescNode* pSrc, SSlotDescNode* pDst) {
return (SNode*)pDst; return (SNode*)pDst;
} }
static SNode* downstreamSourceCopy(const SDownstreamSourceNode* pSrc, SDownstreamSourceNode* pDst) {
COPY_SCALAR_FIELD(addr);
COPY_SCALAR_FIELD(taskId);
COPY_SCALAR_FIELD(schedId);
return (SNode*)pDst;
}
SNodeptr nodesCloneNode(const SNodeptr pNode) { SNodeptr nodesCloneNode(const SNodeptr pNode) {
if (NULL == pNode) { if (NULL == pNode) {
return NULL; return NULL;
...@@ -296,6 +313,8 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) { ...@@ -296,6 +313,8 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) {
return dataBlockDescCopy((const SDataBlockDescNode*)pNode, (SDataBlockDescNode*)pDst); return dataBlockDescCopy((const SDataBlockDescNode*)pNode, (SDataBlockDescNode*)pDst);
case QUERY_NODE_SLOT_DESC: case QUERY_NODE_SLOT_DESC:
return slotDescCopy((const SSlotDescNode*)pNode, (SSlotDescNode*)pDst); return slotDescCopy((const SSlotDescNode*)pNode, (SSlotDescNode*)pDst);
case QUERY_NODE_DOWNSTREAM_SOURCE:
return downstreamSourceCopy((const SDownstreamSourceNode*)pNode, (SDownstreamSourceNode*)pDst);
case QUERY_NODE_LOGIC_PLAN_SCAN: case QUERY_NODE_LOGIC_PLAN_SCAN:
return logicScanCopy((const SScanLogicNode*)pNode, (SScanLogicNode*)pDst); return logicScanCopy((const SScanLogicNode*)pNode, (SScanLogicNode*)pDst);
case QUERY_NODE_LOGIC_PLAN_AGG: case QUERY_NODE_LOGIC_PLAN_AGG:
...@@ -304,6 +323,8 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) { ...@@ -304,6 +323,8 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) {
return logicProjectCopy((const SProjectLogicNode*)pNode, (SProjectLogicNode*)pDst); return logicProjectCopy((const SProjectLogicNode*)pNode, (SProjectLogicNode*)pDst);
case QUERY_NODE_LOGIC_PLAN_VNODE_MODIF: case QUERY_NODE_LOGIC_PLAN_VNODE_MODIF:
return logicVnodeModifCopy((const SVnodeModifLogicNode*)pNode, (SVnodeModifLogicNode*)pDst); return logicVnodeModifCopy((const SVnodeModifLogicNode*)pNode, (SVnodeModifLogicNode*)pDst);
case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
return logicExchangeCopy((const SExchangeLogicNode*)pNode, (SExchangeLogicNode*)pDst);
case QUERY_NODE_LOGIC_SUBPLAN: case QUERY_NODE_LOGIC_SUBPLAN:
return logicSubplanCopy((const SSubLogicPlan*)pNode, (SSubLogicPlan*)pDst); return logicSubplanCopy((const SSubLogicPlan*)pNode, (SSubLogicPlan*)pDst);
default: default:
......
...@@ -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 "nodesint.h" #include "nodesUtil.h"
#include "plannodes.h" #include "plannodes.h"
#include "querynodes.h" #include "querynodes.h"
#include "query.h" #include "query.h"
...@@ -496,6 +496,37 @@ static int32_t jsonToPhysiAggNode(const SJson* pJson, void* pObj) { ...@@ -496,6 +496,37 @@ static int32_t jsonToPhysiAggNode(const SJson* pJson, void* pObj) {
return code; return code;
} }
static const char* jkExchangePhysiPlanSrcGroupId = "SrcGroupId";
static const char* jkExchangePhysiPlanSrcEndPoints = "SrcEndPoints";
static int32_t physiExchangeNodeToJson(const void* pObj, SJson* pJson) {
const SExchangePhysiNode* pNode = (const SExchangePhysiNode*)pObj;
int32_t code = physicPlanNodeToJson(pObj, pJson);
if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkExchangePhysiPlanSrcGroupId, pNode->srcGroupId);
}
if (TSDB_CODE_SUCCESS == code) {
code = nodeListToJson(pJson, jkExchangePhysiPlanSrcEndPoints, pNode->pSrcEndPoints);
}
return code;
}
static int32_t jsonToPhysiExchangeNode(const SJson* pJson, void* pObj) {
SExchangePhysiNode* pNode = (SExchangePhysiNode*)pObj;
int32_t code = jsonToPhysicPlanNode(pJson, pObj);
if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetIntValue(pJson, jkExchangePhysiPlanSrcGroupId, &pNode->srcGroupId);
}
if (TSDB_CODE_SUCCESS == code) {
code = jsonToNodeList(pJson, jkExchangePhysiPlanSrcEndPoints, &pNode->pSrcEndPoints);
}
return code;
}
static const char* jkDataSinkInputDataBlockDesc = "InputDataBlockDesc"; static const char* jkDataSinkInputDataBlockDesc = "InputDataBlockDesc";
static int32_t physicDataSinkNodeToJson(const void* pObj, SJson* pJson) { static int32_t physicDataSinkNodeToJson(const void* pObj, SJson* pJson) {
...@@ -517,7 +548,7 @@ static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) { ...@@ -517,7 +548,7 @@ static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) {
} }
static const char* jkSubplanIdQueryId = "QueryId"; static const char* jkSubplanIdQueryId = "QueryId";
static const char* jkSubplanIdTemplateId = "TemplateId"; static const char* jkSubplanIdGroupId = "GroupId";
static const char* jkSubplanIdSubplanId = "SubplanId"; static const char* jkSubplanIdSubplanId = "SubplanId";
static int32_t subplanIdToJson(const void* pObj, SJson* pJson) { static int32_t subplanIdToJson(const void* pObj, SJson* pJson) {
...@@ -525,7 +556,7 @@ static int32_t subplanIdToJson(const void* pObj, SJson* pJson) { ...@@ -525,7 +556,7 @@ static int32_t subplanIdToJson(const void* pObj, SJson* pJson) {
int32_t code = tjsonAddIntegerToObject(pJson, jkSubplanIdQueryId, pNode->queryId); int32_t code = tjsonAddIntegerToObject(pJson, jkSubplanIdQueryId, pNode->queryId);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkSubplanIdTemplateId, pNode->templateId); code = tjsonAddIntegerToObject(pJson, jkSubplanIdGroupId, pNode->groupId);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkSubplanIdSubplanId, pNode->subplanId); code = tjsonAddIntegerToObject(pJson, jkSubplanIdSubplanId, pNode->subplanId);
...@@ -539,7 +570,7 @@ static int32_t jsonToSubplanId(const SJson* pJson, void* pObj) { ...@@ -539,7 +570,7 @@ static int32_t jsonToSubplanId(const SJson* pJson, void* pObj) {
int32_t code = tjsonGetUBigIntValue(pJson, jkSubplanIdQueryId, &pNode->queryId); int32_t code = tjsonGetUBigIntValue(pJson, jkSubplanIdQueryId, &pNode->queryId);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetIntValue(pJson, jkSubplanIdTemplateId, &pNode->templateId); code = tjsonGetIntValue(pJson, jkSubplanIdGroupId, &pNode->groupId);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetIntValue(pJson, jkSubplanIdSubplanId, &pNode->subplanId); code = tjsonGetIntValue(pJson, jkSubplanIdSubplanId, &pNode->subplanId);
...@@ -583,13 +614,13 @@ static int32_t queryNodeAddrToJson(const void* pObj, SJson* pJson) { ...@@ -583,13 +614,13 @@ static int32_t queryNodeAddrToJson(const void* pObj, SJson* pJson) {
int32_t code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrId, pNode->nodeId); int32_t code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrId, pNode->nodeId);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrInUse, pNode->epset.inUse); code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrInUse, pNode->epSet.inUse);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrNumOfEps, pNode->epset.numOfEps); code = tjsonAddIntegerToObject(pJson, jkQueryNodeAddrNumOfEps, pNode->epSet.numOfEps);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddArray(pJson, jkQueryNodeAddrEps, epToJson, pNode->epset.eps, sizeof(SEp), pNode->epset.numOfEps); code = tjsonAddArray(pJson, jkQueryNodeAddrEps, epToJson, pNode->epSet.eps, sizeof(SEp), pNode->epSet.numOfEps);
} }
return code; return code;
...@@ -600,13 +631,13 @@ static int32_t jsonToQueryNodeAddr(const SJson* pJson, void* pObj) { ...@@ -600,13 +631,13 @@ static int32_t jsonToQueryNodeAddr(const SJson* pJson, void* pObj) {
int32_t code = tjsonGetIntValue(pJson, jkQueryNodeAddrId, &pNode->nodeId); int32_t code = tjsonGetIntValue(pJson, jkQueryNodeAddrId, &pNode->nodeId);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetTinyIntValue(pJson, jkQueryNodeAddrInUse, &pNode->epset.inUse); code = tjsonGetTinyIntValue(pJson, jkQueryNodeAddrInUse, &pNode->epSet.inUse);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetTinyIntValue(pJson, jkQueryNodeAddrNumOfEps, &pNode->epset.numOfEps); code = tjsonGetTinyIntValue(pJson, jkQueryNodeAddrNumOfEps, &pNode->epSet.numOfEps);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = tjsonToArray(pJson, jkQueryNodeAddrEps, jsonToEp, pNode->epset.eps, sizeof(SEp)); code = tjsonToArray(pJson, jkQueryNodeAddrEps, jsonToEp, pNode->epSet.eps, sizeof(SEp));
} }
return code; return code;
...@@ -1230,6 +1261,38 @@ static int32_t jsonToSlotDescNode(const SJson* pJson, void* pObj) { ...@@ -1230,6 +1261,38 @@ static int32_t jsonToSlotDescNode(const SJson* pJson, void* pObj) {
return code; return code;
} }
static const char* jkDownstreamSourceAddr = "Addr";
static const char* jkDownstreamSourceTaskId = "TaskId";
static const char* jkDownstreamSourceSchedId = "SchedId";
static int32_t downstreamSourceNodeToJson(const void* pObj, SJson* pJson) {
const SDownstreamSourceNode* pNode = (const SDownstreamSourceNode*)pObj;
int32_t code = tjsonAddObject(pJson, jkDownstreamSourceAddr, queryNodeAddrToJson, &pNode->addr);
if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkDownstreamSourceTaskId, pNode->taskId);
}
if (TSDB_CODE_SUCCESS == code) {
code = tjsonAddIntegerToObject(pJson, jkDownstreamSourceSchedId, pNode->schedId);
}
return code;
}
static int32_t jsonToDownstreamSourceNode(const SJson* pJson, void* pObj) {
SDownstreamSourceNode* pNode = (SDownstreamSourceNode*)pObj;
int32_t code = tjsonToObject(pJson, jkDownstreamSourceAddr, jsonToQueryNodeAddr, &pNode->addr);
if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetUBigIntValue(pJson, jkDownstreamSourceTaskId, &pNode->taskId);
}
if (TSDB_CODE_SUCCESS == code) {
code = tjsonGetUBigIntValue(pJson, jkDownstreamSourceSchedId, &pNode->schedId);
}
return code;
}
static const char* jkDataBlockDescDataBlockId = "DataBlockId"; static const char* jkDataBlockDescDataBlockId = "DataBlockId";
static const char* jkDataBlockDescSlots = "Slots"; static const char* jkDataBlockDescSlots = "Slots";
static const char* jkDataBlockResultRowSize = "ResultRowSize"; static const char* jkDataBlockResultRowSize = "ResultRowSize";
...@@ -1350,6 +1413,9 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { ...@@ -1350,6 +1413,9 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
case QUERY_NODE_SLOT_DESC: case QUERY_NODE_SLOT_DESC:
return slotDescNodeToJson(pObj, pJson); return slotDescNodeToJson(pObj, pJson);
case QUERY_NODE_COLUMN_DEF: case QUERY_NODE_COLUMN_DEF:
break;
case QUERY_NODE_DOWNSTREAM_SOURCE:
return downstreamSourceNodeToJson(pObj, pJson);
case QUERY_NODE_SET_OPERATOR: case QUERY_NODE_SET_OPERATOR:
break; break;
case QUERY_NODE_SELECT_STMT: case QUERY_NODE_SELECT_STMT:
...@@ -1387,7 +1453,9 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { ...@@ -1387,7 +1453,9 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
case QUERY_NODE_PHYSICAL_PLAN_AGG: case QUERY_NODE_PHYSICAL_PLAN_AGG:
return physiAggNodeToJson(pObj, pJson); return physiAggNodeToJson(pObj, pJson);
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
return physiExchangeNodeToJson(pObj, pJson);
case QUERY_NODE_PHYSICAL_PLAN_SORT: case QUERY_NODE_PHYSICAL_PLAN_SORT:
break;
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
return physiDispatchNodeToJson(pObj, pJson); return physiDispatchNodeToJson(pObj, pJson);
case QUERY_NODE_PHYSICAL_PLAN_INSERT: case QUERY_NODE_PHYSICAL_PLAN_INSERT:
...@@ -1437,6 +1505,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { ...@@ -1437,6 +1505,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
return jsonToDataBlockDescNode(pJson, pObj); return jsonToDataBlockDescNode(pJson, pObj);
case QUERY_NODE_SLOT_DESC: case QUERY_NODE_SLOT_DESC:
return jsonToSlotDescNode(pJson, pObj); return jsonToSlotDescNode(pJson, pObj);
case QUERY_NODE_DOWNSTREAM_SOURCE:
return jsonToDownstreamSourceNode(pJson, pObj);
// case QUERY_NODE_SET_OPERATOR: // case QUERY_NODE_SET_OPERATOR:
// break; // break;
// case QUERY_NODE_SELECT_STMT: // case QUERY_NODE_SELECT_STMT:
...@@ -1459,6 +1529,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { ...@@ -1459,6 +1529,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
return jsonToPhysiJoinNode(pJson, pObj); return jsonToPhysiJoinNode(pJson, pObj);
case QUERY_NODE_PHYSICAL_PLAN_AGG: case QUERY_NODE_PHYSICAL_PLAN_AGG:
return jsonToPhysiAggNode(pJson, pObj); return jsonToPhysiAggNode(pJson, pObj);
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
return jsonToPhysiExchangeNode(pJson, pObj);
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
return jsonToPhysiDispatchNode(pJson, pObj); return jsonToPhysiDispatchNode(pJson, pObj);
case QUERY_NODE_PHYSICAL_SUBPLAN: case QUERY_NODE_PHYSICAL_SUBPLAN:
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
*/ */
#include "cmdnodes.h" #include "cmdnodes.h"
#include "nodesint.h" #include "nodesUtil.h"
#include "plannodes.h" #include "plannodes.h"
#include "querynodes.h" #include "querynodes.h"
#include "taos.h" #include "taos.h"
...@@ -74,6 +74,8 @@ SNodeptr nodesMakeNode(ENodeType type) { ...@@ -74,6 +74,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
return makeNode(type, sizeof(SSlotDescNode)); return makeNode(type, sizeof(SSlotDescNode));
case QUERY_NODE_COLUMN_DEF: case QUERY_NODE_COLUMN_DEF:
return makeNode(type, sizeof(SColumnDefNode)); return makeNode(type, sizeof(SColumnDefNode));
case QUERY_NODE_DOWNSTREAM_SOURCE:
return makeNode(type, sizeof(SDownstreamSourceNode));
case QUERY_NODE_SET_OPERATOR: case QUERY_NODE_SET_OPERATOR:
return makeNode(type, sizeof(SSetOperator)); return makeNode(type, sizeof(SSetOperator));
case QUERY_NODE_SELECT_STMT: case QUERY_NODE_SELECT_STMT:
...@@ -129,6 +131,8 @@ SNodeptr nodesMakeNode(ENodeType type) { ...@@ -129,6 +131,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
return makeNode(type, sizeof(SProjectLogicNode)); return makeNode(type, sizeof(SProjectLogicNode));
case QUERY_NODE_LOGIC_PLAN_VNODE_MODIF: case QUERY_NODE_LOGIC_PLAN_VNODE_MODIF:
return makeNode(type, sizeof(SVnodeModifLogicNode)); return makeNode(type, sizeof(SVnodeModifLogicNode));
case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
return makeNode(type, sizeof(SExchangeLogicNode));
case QUERY_NODE_LOGIC_SUBPLAN: case QUERY_NODE_LOGIC_SUBPLAN:
return makeNode(type, sizeof(SSubLogicPlan)); return makeNode(type, sizeof(SSubLogicPlan));
case QUERY_NODE_LOGIC_PLAN: case QUERY_NODE_LOGIC_PLAN:
......
此差异已折叠。
...@@ -22,9 +22,9 @@ extern "C" { ...@@ -22,9 +22,9 @@ extern "C" {
#include "cmdnodes.h" #include "cmdnodes.h"
#include "parser.h" #include "parser.h"
#include "parserUtil.h" #include "parToken.h"
#include "parUtil.h"
#include "querynodes.h" #include "querynodes.h"
#include "ttoken.h"
typedef struct SAstCreateContext { typedef struct SAstCreateContext {
SParseContext* pQueryCxt; SParseContext* pQueryCxt;
......
...@@ -22,6 +22,7 @@ extern "C" { ...@@ -22,6 +22,7 @@ extern "C" {
#include "parser.h" #include "parser.h"
int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery);
int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery); int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery);
int32_t doTranslate(SParseContext* pParseCxt, SQuery* pQuery); int32_t doTranslate(SParseContext* pParseCxt, SQuery* pQuery);
......
...@@ -22,7 +22,6 @@ extern "C" { ...@@ -22,7 +22,6 @@ extern "C" {
#include "os.h" #include "os.h"
#include "query.h" #include "query.h"
#include "ttoken.h"
typedef struct SMsgBuf { typedef struct SMsgBuf {
int32_t len; int32_t len;
......
此差异已折叠。
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
* 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 "astCreateFuncs.h" #include "parAst.h"
#include "parserUtil.h" #include "parUtil.h"
#define CHECK_OUT_OF_MEM(p) \ #define CHECK_OUT_OF_MEM(p) \
do { \ do { \
......
...@@ -13,28 +13,28 @@ ...@@ -13,28 +13,28 @@
* 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 "parserInt.h" #include "parInt.h"
#include "astCreateFuncs.h" #include "parAst.h"
#include "ttoken.h" #include "parToken.h"
typedef void* (*FMalloc)(size_t); typedef void* (*FMalloc)(size_t);
typedef void (*FFree)(void*); typedef void (*FFree)(void*);
extern void* NewParseAlloc(FMalloc); extern void* ParseAlloc(FMalloc);
extern void NewParse(void*, int, SToken, void*); extern void Parse(void*, int, SToken, void*);
extern void NewParseFree(void*, FFree); extern void ParseFree(void*, FFree);
extern void NewParseTrace(FILE*, char*); extern void ParseTrace(FILE*, char*);
int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) { int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
SAstCreateContext cxt; SAstCreateContext cxt;
initAstCreateContext(pParseCxt, &cxt); initAstCreateContext(pParseCxt, &cxt);
void *pParser = NewParseAlloc(malloc); void *pParser = ParseAlloc(malloc);
int32_t i = 0; int32_t i = 0;
while (1) { while (1) {
SToken t0 = {0}; SToken t0 = {0};
if (cxt.pQueryCxt->pSql[i] == 0) { if (cxt.pQueryCxt->pSql[i] == 0) {
NewParse(pParser, 0, t0, &cxt); Parse(pParser, 0, t0, &cxt);
goto abort_parse; goto abort_parse;
} }
t0.n = tGetToken((char *)&cxt.pQueryCxt->pSql[i], &t0.type); t0.n = tGetToken((char *)&cxt.pQueryCxt->pSql[i], &t0.type);
...@@ -47,7 +47,7 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) { ...@@ -47,7 +47,7 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
break; break;
} }
case TK_NK_SEMI: { case TK_NK_SEMI: {
NewParse(pParser, 0, t0, &cxt); Parse(pParser, 0, t0, &cxt);
goto abort_parse; goto abort_parse;
} }
case TK_NK_QUESTION: case TK_NK_QUESTION:
...@@ -64,8 +64,8 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) { ...@@ -64,8 +64,8 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
goto abort_parse; goto abort_parse;
} }
default: default:
NewParse(pParser, t0.type, t0, &cxt); Parse(pParser, t0.type, t0, &cxt);
// NewParseTrace(stdout, ""); // ParseTrace(stdout, "");
if (!cxt.valid) { if (!cxt.valid) {
goto abort_parse; goto abort_parse;
} }
...@@ -73,7 +73,7 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) { ...@@ -73,7 +73,7 @@ int32_t doParse(SParseContext* pParseCxt, SQuery** pQuery) {
} }
abort_parse: abort_parse:
NewParseFree(pParser, free); ParseFree(pParser, free);
if (cxt.valid) { if (cxt.valid) {
*pQuery = calloc(1, sizeof(SQuery)); *pQuery = calloc(1, sizeof(SQuery));
if (NULL == *pQuery) { if (NULL == *pQuery) {
......
...@@ -13,13 +13,12 @@ ...@@ -13,13 +13,12 @@
* 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 "insertParser.h" #include "parInsertData.h"
#include "parInt.h"
#include "dataBlockMgt.h" #include "parUtil.h"
#include "parserUtil.h" #include "parToken.h"
#include "tglobal.h" #include "tglobal.h"
#include "ttime.h" #include "ttime.h"
#include "ttoken.h"
#include "ttypes.h" #include "ttypes.h"
#define NEXT_TOKEN(pSql, sToken) \ #define NEXT_TOKEN(pSql, sToken) \
......
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
* 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 "dataBlockMgt.h" #include "parInsertData.h"
#include "catalog.h" #include "catalog.h"
#include "parserUtil.h" #include "parUtil.h"
#include "querynodes.h" #include "querynodes.h"
#define IS_RAW_PAYLOAD(t) \ #define IS_RAW_PAYLOAD(t) \
......
...@@ -14,10 +14,9 @@ ...@@ -14,10 +14,9 @@
*/ */
#include "os.h" #include "os.h"
#include "parToken.h"
#include "thash.h" #include "thash.h"
#include "taosdef.h" #include "taosdef.h"
#include "ttoken.h"
#include "ttokendef.h" #include "ttokendef.h"
// All the keywords of the SQL language are stored in a hash table // All the keywords of the SQL language are stored in a hash table
......
...@@ -13,12 +13,12 @@ ...@@ -13,12 +13,12 @@
* 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 "parserInt.h" #include "parInt.h"
#include "catalog.h" #include "catalog.h"
#include "cmdnodes.h" #include "cmdnodes.h"
#include "functionMgt.h" #include "functionMgt.h"
#include "parserUtil.h" #include "parUtil.h"
#include "ttime.h" #include "ttime.h"
static bool afterGroupBy(ESqlClause clause) { static bool afterGroupBy(ESqlClause clause) {
...@@ -891,7 +891,7 @@ static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt ...@@ -891,7 +891,7 @@ static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt
if (TSDB_SUPER_TABLE == pTableMeta->tableType) { if (TSDB_SUPER_TABLE == pTableMeta->tableType) {
code = doTranslateDropSuperTable(pCxt, &tableName, pClause->ignoreNotExists); code = doTranslateDropSuperTable(pCxt, &tableName, pClause->ignoreNotExists);
} else { } else {
// todo; // todo : drop normal table or child table
code = TSDB_CODE_FAILED; code = TSDB_CODE_FAILED;
} }
} }
...@@ -1106,7 +1106,7 @@ static int32_t translateShowTables(STranslateContext* pCxt) { ...@@ -1106,7 +1106,7 @@ static int32_t translateShowTables(STranslateContext* pCxt) {
if (NULL== pCxt->pCmdMsg) { if (NULL== pCxt->pCmdMsg) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
pCxt->pCmdMsg->epSet = info->epset; pCxt->pCmdMsg->epSet = info->epSet;
pCxt->pCmdMsg->msgType = TDMT_VND_SHOW_TABLES; pCxt->pCmdMsg->msgType = TDMT_VND_SHOW_TABLES;
pCxt->pCmdMsg->msgLen = sizeof(SVShowTablesReq); pCxt->pCmdMsg->msgLen = sizeof(SVShowTablesReq);
pCxt->pCmdMsg->pMsg = pShowReq; pCxt->pCmdMsg->pMsg = pShowReq;
...@@ -1203,6 +1203,9 @@ static int32_t setReslutSchema(STranslateContext* pCxt, SQuery* pQuery) { ...@@ -1203,6 +1203,9 @@ static int32_t setReslutSchema(STranslateContext* pCxt, SQuery* pQuery) {
} }
static void destroyTranslateContext(STranslateContext* pCxt) { static void destroyTranslateContext(STranslateContext* pCxt) {
if (NULL != pCxt->pNsLevel) {
}
taosArrayDestroy(pCxt->pNsLevel); taosArrayDestroy(pCxt->pNsLevel);
if (NULL != pCxt->pCmdMsg) { if (NULL != pCxt->pCmdMsg) {
tfree(pCxt->pCmdMsg->pMsg); tfree(pCxt->pCmdMsg->pMsg);
...@@ -1222,6 +1225,11 @@ static void toSchema(const SColumnDefNode* pCol, int32_t colId, SSchema* pSchema ...@@ -1222,6 +1225,11 @@ static void toSchema(const SColumnDefNode* pCol, int32_t colId, SSchema* pSchema
strcpy(pSchema->name, pCol->colName); strcpy(pSchema->name, pCol->colName);
} }
static void destroyCreateTbReq(SVCreateTbReq* pReq) {
tfree(pReq->name);
tfree(pReq->ntbCfg.pSchema);
}
static int32_t buildNormalTableBatchReq( static int32_t buildNormalTableBatchReq(
const char* pTableName, const SNodeList* pColumns, const SVgroupInfo* pVgroupInfo, SVgroupTablesBatch* pBatch) { const char* pTableName, const SNodeList* pColumns, const SVgroupInfo* pVgroupInfo, SVgroupTablesBatch* pBatch) {
SVCreateTbReq req = {0}; SVCreateTbReq req = {0};
...@@ -1230,6 +1238,7 @@ static int32_t buildNormalTableBatchReq( ...@@ -1230,6 +1238,7 @@ static int32_t buildNormalTableBatchReq(
req.ntbCfg.nCols = LIST_LENGTH(pColumns); req.ntbCfg.nCols = LIST_LENGTH(pColumns);
req.ntbCfg.pSchema = calloc(req.ntbCfg.nCols, sizeof(SSchema)); req.ntbCfg.pSchema = calloc(req.ntbCfg.nCols, sizeof(SSchema));
if (NULL == req.name || NULL == req.ntbCfg.pSchema) { if (NULL == req.name || NULL == req.ntbCfg.pSchema) {
destroyCreateTbReq(&req);
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
SNode* pCol; SNode* pCol;
...@@ -1242,6 +1251,7 @@ static int32_t buildNormalTableBatchReq( ...@@ -1242,6 +1251,7 @@ static int32_t buildNormalTableBatchReq(
pBatch->info = *pVgroupInfo; pBatch->info = *pVgroupInfo;
pBatch->req.pArray = taosArrayInit(1, sizeof(struct SVCreateTbReq)); pBatch->req.pArray = taosArrayInit(1, sizeof(struct SVCreateTbReq));
if (NULL == pBatch->req.pArray) { if (NULL == pBatch->req.pArray) {
destroyCreateTbReq(&req);
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
taosArrayPush(pBatch->req.pArray, &req); taosArrayPush(pBatch->req.pArray, &req);
...@@ -1311,18 +1321,20 @@ static int32_t rewriteToVnodeModifOpStmt(SQuery* pQuery, SArray* pBufArray) { ...@@ -1311,18 +1321,20 @@ static int32_t rewriteToVnodeModifOpStmt(SQuery* pQuery, SArray* pBufArray) {
} }
static int32_t buildCreateTableDataBlock(const SCreateTableStmt* pStmt, const SVgroupInfo* pInfo, SArray** pBufArray) { static int32_t buildCreateTableDataBlock(const SCreateTableStmt* pStmt, const SVgroupInfo* pInfo, SArray** pBufArray) {
SVgroupTablesBatch tbatch = {0};
int32_t code = buildNormalTableBatchReq(pStmt->tableName, pStmt->pCols, pInfo, &tbatch);
if (TSDB_CODE_SUCCESS == code) {
*pBufArray = taosArrayInit(1, POINTER_BYTES); *pBufArray = taosArrayInit(1, POINTER_BYTES);
if (NULL == pBufArray) { if (NULL == *pBufArray) {
code = TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
}
} }
SVgroupTablesBatch tbatch = {0};
int32_t code = buildNormalTableBatchReq(pStmt->tableName, pStmt->pCols, pInfo, &tbatch);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = serializeVgroupTablesBatch(&tbatch, *pBufArray); code = serializeVgroupTablesBatch(&tbatch, *pBufArray);
} }
destroyCreateTbReqBatch(&tbatch); destroyCreateTbReqBatch(&tbatch);
if (TSDB_CODE_SUCCESS != code) {
// todo : destroyCreateTbReqArray(*pBufArray);
}
return code; return code;
} }
...@@ -1331,7 +1343,7 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) { ...@@ -1331,7 +1343,7 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) {
SVgroupInfo info = {0}; SVgroupInfo info = {0};
int32_t code = getTableHashVgroup(pCxt->pParseCxt, pStmt->dbName, pStmt->tableName, &info); int32_t code = getTableHashVgroup(pCxt->pParseCxt, pStmt->dbName, pStmt->tableName, &info);
SArray* pBufArray; SArray* pBufArray = NULL;
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = buildCreateTableDataBlock(pStmt, &info, &pBufArray); code = buildCreateTableDataBlock(pStmt, &info, &pBufArray);
} }
......
...@@ -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 "parserUtil.h" #include "parUtil.h"
static char* getSyntaxErrFormat(int32_t errCode) { static char* getSyntaxErrFormat(int32_t errCode) {
switch (errCode) { switch (errCode) {
......
...@@ -15,9 +15,8 @@ ...@@ -15,9 +15,8 @@
#include "parser.h" #include "parser.h"
#include "insertParser.h" #include "parInt.h"
#include "parserInt.h" #include "parToken.h"
#include "ttoken.h"
static bool isInsertSql(const char* pStr, size_t length) { static bool isInsertSql(const char* pStr, size_t length) {
int32_t index = 0; int32_t index = 0;
...@@ -47,5 +46,14 @@ int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery) { ...@@ -47,5 +46,14 @@ int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery) {
} }
void qDestroyQuery(SQuery* pQueryNode) { void qDestroyQuery(SQuery* pQueryNode) {
// todo if (NULL == pQueryNode) {
return;
}
nodesDestroyNode(pQueryNode->pRoot);
tfree(pQueryNode->pResSchema);
if (NULL != pQueryNode->pCmdMsg) {
tfree(pQueryNode->pCmdMsg->pMsg);
tfree(pQueryNode->pCmdMsg);
}
tfree(pQueryNode);
} }
...@@ -43,11 +43,11 @@ public: ...@@ -43,11 +43,11 @@ public:
SVgroupInfo vgroup = {.vgId = vgid, .hashBegin = 0, .hashEnd = 0, }; SVgroupInfo vgroup = {.vgId = vgid, .hashBegin = 0, .hashEnd = 0, };
vgroup.epset.eps[0] = (SEp){"dnode_1", 6030}; vgroup.epSet.eps[0] = (SEp){"dnode_1", 6030};
vgroup.epset.eps[1] = (SEp){"dnode_2", 6030}; vgroup.epSet.eps[1] = (SEp){"dnode_2", 6030};
vgroup.epset.eps[2] = (SEp){"dnode_3", 6030}; vgroup.epSet.eps[2] = (SEp){"dnode_3", 6030};
vgroup.epset.inUse = 0; vgroup.epSet.inUse = 0;
vgroup.epset.numOfEps = 3; vgroup.epSet.numOfEps = 3;
meta_->vgs.emplace_back(vgroup); meta_->vgs.emplace_back(vgroup);
return *this; return *this;
...@@ -123,14 +123,14 @@ public: ...@@ -123,14 +123,14 @@ public:
int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const { int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const {
// todo // todo
vgInfo->vgId = 1; vgInfo->vgId = 1;
addEpIntoEpSet(&vgInfo->epset, "node1", 6030); addEpIntoEpSet(&vgInfo->epSet, "node1", 6030);
return 0; return 0;
} }
int32_t catalogGetTableDistVgInfo(const SName* pTableName, SArray** pVgList) const { int32_t catalogGetTableDistVgInfo(const SName* pTableName, SArray** pVgList) const {
SVgroupInfo info = {0}; SVgroupInfo info = {0};
info.vgId = 1; info.vgId = 1;
addEpIntoEpSet(&info.epset, "node1", 6030); addEpIntoEpSet(&info.epSet, "node1", 6030);
info.hashBegin = 0; info.hashBegin = 0;
info.hashEnd = 1; info.hashEnd = 1;
...@@ -157,10 +157,10 @@ public: ...@@ -157,10 +157,10 @@ public:
meta_[db][tbname]->schema->uid = id_++; meta_[db][tbname]->schema->uid = id_++;
SVgroupInfo vgroup = {.vgId = vgid, .hashBegin = 0, .hashEnd = 0,}; SVgroupInfo vgroup = {.vgId = vgid, .hashBegin = 0, .hashEnd = 0,};
addEpIntoEpSet(&vgroup.epset, "dnode_1", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_1", 6030);
addEpIntoEpSet(&vgroup.epset, "dnode_2", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_2", 6030);
addEpIntoEpSet(&vgroup.epset, "dnode_3", 6030); addEpIntoEpSet(&vgroup.epSet, "dnode_3", 6030);
vgroup.epset.inUse = 0; vgroup.epSet.inUse = 0;
meta_[db][tbname]->vgs.emplace_back(vgroup); meta_[db][tbname]->vgs.emplace_back(vgroup);
// super table // super table
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "parserInt.h" #include "parInt.h"
using namespace std; using namespace std;
using namespace testing; using namespace testing;
......
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "insertParser.h" #include "parInt.h"
// #include "mockCatalog.h"
using namespace std; using namespace std;
using namespace testing; using namespace testing;
......
此差异已折叠。
...@@ -50,6 +50,7 @@ extern "C" { ...@@ -50,6 +50,7 @@ extern "C" {
int32_t createLogicPlan(SPlanContext* pCxt, SLogicNode** pLogicNode); int32_t createLogicPlan(SPlanContext* pCxt, SLogicNode** pLogicNode);
int32_t optimize(SPlanContext* pCxt, SLogicNode* pLogicNode); int32_t optimize(SPlanContext* pCxt, SLogicNode* pLogicNode);
int32_t applySplitRule(SSubLogicPlan* pSubplan);
int32_t createPhysiPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SQueryPlan** pPlan, SArray* pExecNodeList); int32_t createPhysiPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SQueryPlan** pPlan, SArray* pExecNodeList);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -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 "plannerInt.h" #include "planInt.h"
#include "functionMgt.h" #include "functionMgt.h"
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "planInt.h"
#define SPLIT_FLAG_MASK(n) (1 << n)
#define SPLIT_FLAG_STS SPLIT_FLAG_MASK(0)
#define SPLIT_FLAG_SET_MASK(val, mask) (val) |= (mask)
#define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
typedef struct SSplitContext {
int32_t errCode;
int32_t groupId;
bool match;
void* pInfo;
} SSplitContext;
typedef int32_t (*FMatch)(SSplitContext* pCxt, SSubLogicPlan* pSubplan);
typedef int32_t (*FSplit)(SSplitContext* pCxt);
typedef struct SSplitRule {
char* pName;
FMatch matchFunc;
FSplit splitFunc;
} SSplitRule;
typedef struct SStsInfo {
SScanLogicNode* pScan;
SSubLogicPlan* pSubplan;
} SStsInfo;
static SLogicNode* stsMatchByNode(SLogicNode* pNode) {
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) && TSDB_SUPER_TABLE == ((SScanLogicNode*)pNode)->pMeta->tableType) {
return pNode;
}
SNode* pChild;
FOREACH(pChild, pNode->pChildren) {
SLogicNode* pSplitNode = stsMatchByNode((SLogicNode*)pChild);
if (NULL != pSplitNode) {
return pSplitNode;
}
}
return NULL;
}
static int32_t stsMatch(SSplitContext* pCxt, SSubLogicPlan* pSubplan) {
if (SPLIT_FLAG_TEST_MASK(pSubplan->splitFlag, SPLIT_FLAG_STS)) {
return TSDB_CODE_SUCCESS;
}
SLogicNode* pSplitNode = stsMatchByNode(pSubplan->pNode);
if (NULL != pSplitNode) {
SStsInfo* pInfo = calloc(1, sizeof(SStsInfo));
CHECK_ALLOC(pInfo, TSDB_CODE_OUT_OF_MEMORY);
pInfo->pScan = (SScanLogicNode*)pSplitNode;
pInfo->pSubplan = pSubplan;
pCxt->pInfo = pInfo;
pCxt->match = true;
return TSDB_CODE_SUCCESS;
}
SNode* pChild;
FOREACH(pChild, pSubplan->pChildren) {
int32_t code = stsMatch(pCxt, (SSubLogicPlan*)pChild);
if (TSDB_CODE_SUCCESS != code || pCxt->match) {
return code;
}
}
return TSDB_CODE_SUCCESS;
}
static SSubLogicPlan* stsCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode* pScan) {
SSubLogicPlan* pSubplan = nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN);
if (NULL == pSubplan) {
return NULL;
}
pSubplan->id.groupId = pCxt->groupId;
pSubplan->subplanType = SUBPLAN_TYPE_SCAN;
pSubplan->pNode = (SLogicNode*)nodesCloneNode(pScan);
TSWAP(pSubplan->pVgroupList, ((SScanLogicNode*)pSubplan->pNode)->pVgroupList, SVgroupsInfo);
SPLIT_FLAG_SET_MASK(pSubplan->splitFlag, SPLIT_FLAG_STS);
return pSubplan;
}
static int32_t stsCreateExchangeNode(SSplitContext* pCxt, SSubLogicPlan* pSubplan, SScanLogicNode* pScan) {
SExchangeLogicNode* pExchange = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_EXCHANGE);
if (NULL == pExchange) {
return TSDB_CODE_OUT_OF_MEMORY;
}
pExchange->srcGroupId = pCxt->groupId;
pExchange->node.pTargets = nodesCloneList(pScan->node.pTargets);
if (NULL == pExchange->node.pTargets) {
return TSDB_CODE_OUT_OF_MEMORY;
}
if (NULL == pScan->node.pParent) {
pSubplan->pNode = (SLogicNode*)pExchange;
return TSDB_CODE_SUCCESS;
}
SNode* pNode;
FOREACH(pNode, pScan->node.pParent->pChildren) {
if (nodesEqualNode(pNode, pScan)) {
REPLACE_NODE(pExchange);
nodesDestroyNode(pNode);
return TSDB_CODE_SUCCESS;
}
}
nodesDestroyNode(pExchange);
return TSDB_CODE_FAILED;
}
static int32_t stsSplit(SSplitContext* pCxt) {
SStsInfo* pInfo = pCxt->pInfo;
if (NULL == pInfo->pSubplan->pChildren) {
pInfo->pSubplan->pChildren = nodesMakeList();
if (NULL == pInfo->pSubplan->pChildren) {
return TSDB_CODE_OUT_OF_MEMORY;
}
}
int32_t code = nodesListStrictAppend(pInfo->pSubplan->pChildren, stsCreateScanSubplan(pCxt, pInfo->pScan));
if (TSDB_CODE_SUCCESS == code) {
code = stsCreateExchangeNode(pCxt, pInfo->pSubplan, pInfo->pScan);
}
++(pCxt->groupId);
return code;
}
static const SSplitRule splitRuleSet[] = {
{ .pName = "SuperTableScan", .matchFunc = stsMatch, .splitFunc = stsSplit }
};
static const int32_t splitRuleNum = (sizeof(splitRuleSet) / sizeof(SSplitRule));
int32_t applySplitRule(SSubLogicPlan* pSubplan) {
SSplitContext cxt = { .errCode = TSDB_CODE_SUCCESS, .groupId = pSubplan->id.groupId + 1, .match = false, .pInfo = NULL };
bool split = false;
do {
split = false;
for (int32_t i = 0; i < splitRuleNum; ++i) {
cxt.match = false;
int32_t code = splitRuleSet[i].matchFunc(&cxt, pSubplan);
if (TSDB_CODE_SUCCESS == code && cxt.match) {
code = splitRuleSet[i].splitFunc(&cxt);
split = true;
}
if (TSDB_CODE_SUCCESS != code) {
return code;
}
}
} while (split);
return TSDB_CODE_SUCCESS;
}
此差异已折叠。
...@@ -1286,7 +1286,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) { ...@@ -1286,7 +1286,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
srand(time(NULL)); taosSeedRand(time(NULL));
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
......
...@@ -1435,7 +1435,7 @@ TEST(columnTest, greater_and_lower) { ...@@ -1435,7 +1435,7 @@ TEST(columnTest, greater_and_lower) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
srand(time(NULL)); taosSeedRand(time(NULL));
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册