Merge branch '3.0' into test/jcy
This commit is contained in:
commit
eaf8812722
|
@ -7,7 +7,7 @@ project(
|
||||||
)
|
)
|
||||||
|
|
||||||
if (NOT DEFINED TD_SOURCE_DIR)
|
if (NOT DEFINED TD_SOURCE_DIR)
|
||||||
set( TD_SOURCE_DIR ${CMAKE_SOURCE_DIR} )
|
set( TD_SOURCE_DIR ${PROJECT_SOURCE_DIR} )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(TD_SUPPORT_DIR "${TD_SOURCE_DIR}/cmake")
|
set(TD_SUPPORT_DIR "${TD_SOURCE_DIR}/cmake")
|
||||||
|
|
|
@ -60,7 +60,6 @@ int32_t init_env() {
|
||||||
pRes =
|
pRes =
|
||||||
taos_query(pConn, "create stable if not exists st1 (ts timestamp, c1 int, c2 float, c3 binary(10)) tags(t1 int)");
|
taos_query(pConn, "create stable if not exists st1 (ts timestamp, c1 int, c2 float, c3 binary(10)) tags(t1 int)");
|
||||||
if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
assert(0);
|
|
||||||
printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -104,8 +103,8 @@ int32_t create_topic() {
|
||||||
}
|
}
|
||||||
taos_free_result(pRes);
|
taos_free_result(pRes);
|
||||||
|
|
||||||
/*pRes = taos_query(pConn, "create topic topic_ctb_column as abc1");*/
|
pRes = taos_query(pConn, "create topic topic_ctb_column as abc1");
|
||||||
pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from ct1");
|
/*pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from ct1");*/
|
||||||
if (taos_errno(pRes) != 0) {
|
if (taos_errno(pRes) != 0) {
|
||||||
printf("failed to create topic topic_ctb_column, reason:%s\n", taos_errstr(pRes));
|
printf("failed to create topic topic_ctb_column, reason:%s\n", taos_errstr(pRes));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -163,9 +162,10 @@ tmq_t* build_consumer() {
|
||||||
tmq_conf_set(conf, "group.id", "tg2");
|
tmq_conf_set(conf, "group.id", "tg2");
|
||||||
tmq_conf_set(conf, "td.connect.user", "root");
|
tmq_conf_set(conf, "td.connect.user", "root");
|
||||||
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
||||||
tmq_conf_set(conf, "td.connect.db", "abc1");
|
/*tmq_conf_set(conf, "td.connect.db", "abc1");*/
|
||||||
tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print);
|
tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print);
|
||||||
tmq_t* tmq = tmq_consumer_new(conf, NULL, 0);
|
tmq_t* tmq = tmq_consumer_new(conf, NULL, 0);
|
||||||
|
assert(tmq);
|
||||||
return tmq;
|
return tmq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
PROJECT(TDengine)
|
PROJECT(TDengine)
|
||||||
|
|
||||||
IF (TD_LINUX)
|
IF (TD_LINUX)
|
||||||
INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc)
|
INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc)
|
||||||
AUX_SOURCE_DIRECTORY(. SRC)
|
AUX_SOURCE_DIRECTORY(. SRC)
|
||||||
ADD_EXECUTABLE(demo apitest.c)
|
ADD_EXECUTABLE(demo apitest.c)
|
||||||
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread )
|
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread )
|
||||||
|
@ -13,7 +13,7 @@ IF (TD_LINUX)
|
||||||
TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread lua)
|
TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread lua)
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
IF (TD_DARWIN)
|
IF (TD_DARWIN)
|
||||||
INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc)
|
INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc)
|
||||||
AUX_SOURCE_DIRECTORY(. SRC)
|
AUX_SOURCE_DIRECTORY(. SRC)
|
||||||
ADD_EXECUTABLE(demo demo.c)
|
ADD_EXECUTABLE(demo demo.c)
|
||||||
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread lua)
|
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread lua)
|
||||||
|
|
|
@ -123,9 +123,9 @@ extern SDiskCfg tsDiskCfg[];
|
||||||
|
|
||||||
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
|
#define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize)
|
||||||
|
|
||||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile,
|
||||||
const char *apolloUrl, SArray *pArgs, bool tsc);
|
char *apolloUrl, SArray *pArgs, bool tsc);
|
||||||
int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc);
|
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc);
|
||||||
void taosCleanupCfg();
|
void taosCleanupCfg();
|
||||||
void taosCfgDynamicOptions(const char *option, const char *value);
|
void taosCfgDynamicOptions(const char *option, const char *value);
|
||||||
void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary);
|
void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary);
|
||||||
|
|
|
@ -227,8 +227,16 @@ typedef struct {
|
||||||
} SSubmitBlkIter;
|
} SSubmitBlkIter;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t totalLen;
|
int32_t totalLen;
|
||||||
int32_t len;
|
int32_t len;
|
||||||
|
// head of SSubmitBlk
|
||||||
|
// int64_t uid; // table unique id
|
||||||
|
// int64_t suid; // stable id
|
||||||
|
// int32_t sversion; // data schema version
|
||||||
|
// int32_t dataLen; // data part length, not including the SSubmitBlk head
|
||||||
|
// int32_t schemaLen; // schema length, if length is 0, no schema exists
|
||||||
|
// int16_t numOfRows; // total number of rows in current submit block
|
||||||
|
// head of SSubmitBlk
|
||||||
const void* pMsg;
|
const void* pMsg;
|
||||||
} SSubmitMsgIter;
|
} SSubmitMsgIter;
|
||||||
|
|
||||||
|
@ -237,6 +245,15 @@ int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
|
||||||
int32_t tInitSubmitBlkIter(SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
|
int32_t tInitSubmitBlkIter(SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
|
||||||
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
|
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
|
||||||
|
|
||||||
|
// TODO: KEEP one suite of iterator API finally.
|
||||||
|
// 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts
|
||||||
|
// 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later
|
||||||
|
// 3) finally, rename tInitSubmitMsgIterEx to tInitSubmitMsgIter
|
||||||
|
// int32_t tInitSubmitMsgIterEx(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
|
||||||
|
// int32_t tGetSubmitMsgNextEx(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
|
||||||
|
// int32_t tInitSubmitBlkIterEx(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
|
||||||
|
// STSRow* tGetSubmitBlkNextEx(SSubmitBlkIter* pIter);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t index; // index of failed block in submit blocks
|
int32_t index; // index of failed block in submit blocks
|
||||||
int32_t vnode; // vnode index of failed block
|
int32_t vnode; // vnode index of failed block
|
||||||
|
@ -1496,8 +1513,8 @@ typedef struct {
|
||||||
int32_t qmsg1Len;
|
int32_t qmsg1Len;
|
||||||
int32_t qmsg2Len;
|
int32_t qmsg2Len;
|
||||||
func_id_t* pFuncIds;
|
func_id_t* pFuncIds;
|
||||||
char* qmsg1; // not null: pAst1:qmsg1:SRetention1 => trigger aggr task1
|
char* qmsg1; // pAst1:qmsg1:SRetention1 => trigger aggr task1
|
||||||
char* qmsg2; // not null: pAst2:qmsg2:SRetention2 => trigger aggr task2
|
char* qmsg2; // pAst2:qmsg2:SRetention2 => trigger aggr task2
|
||||||
int8_t nFuncIds;
|
int8_t nFuncIds;
|
||||||
} SRSmaParam;
|
} SRSmaParam;
|
||||||
|
|
||||||
|
@ -2052,80 +2069,6 @@ static FORCE_INLINE void* tDecodeSMqSetCVgReq(void* buf, SMqSetCVgReq* pReq) {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int64_t leftForVer;
|
|
||||||
int32_t vgId;
|
|
||||||
int32_t epoch;
|
|
||||||
int64_t consumerId;
|
|
||||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
|
||||||
} SMqCancelConnReq;
|
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tEncodeSMqCancelConnReq(void** buf, const SMqCancelConnReq* pReq) {
|
|
||||||
int32_t tlen = 0;
|
|
||||||
tlen += taosEncodeFixedI64(buf, pReq->leftForVer);
|
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->vgId);
|
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->epoch);
|
|
||||||
tlen += taosEncodeFixedI64(buf, pReq->consumerId);
|
|
||||||
tlen += taosEncodeString(buf, pReq->topicName);
|
|
||||||
return tlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE void* tDecodeSMqCancelConnReq(void* buf, SMqCancelConnReq* pReq) {
|
|
||||||
buf = taosDecodeFixedI64(buf, &pReq->leftForVer);
|
|
||||||
buf = taosDecodeFixedI32(buf, &pReq->vgId);
|
|
||||||
buf = taosDecodeFixedI32(buf, &pReq->epoch);
|
|
||||||
buf = taosDecodeFixedI64(buf, &pReq->consumerId);
|
|
||||||
buf = taosDecodeStringTo(buf, pReq->topicName);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int8_t reserved;
|
|
||||||
} SMqCancelConnRsp;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int64_t leftForVer;
|
|
||||||
int32_t vgId;
|
|
||||||
int64_t oldConsumerId;
|
|
||||||
int64_t newConsumerId;
|
|
||||||
char* topic;
|
|
||||||
} SMqMVRebReq;
|
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tEncodeSMqMVRebReq(void** buf, const SMqMVRebReq* pReq) {
|
|
||||||
int32_t tlen = 0;
|
|
||||||
tlen += taosEncodeFixedI64(buf, pReq->leftForVer);
|
|
||||||
tlen += taosEncodeFixedI32(buf, pReq->vgId);
|
|
||||||
tlen += taosEncodeFixedI64(buf, pReq->oldConsumerId);
|
|
||||||
tlen += taosEncodeFixedI64(buf, pReq->newConsumerId);
|
|
||||||
tlen += taosEncodeString(buf, pReq->topic);
|
|
||||||
return tlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE void* tDecodeSMqMVRebReq(void* buf, SMqMVRebReq* pReq) {
|
|
||||||
buf = taosDecodeFixedI64(buf, &pReq->leftForVer);
|
|
||||||
buf = taosDecodeFixedI32(buf, &pReq->vgId);
|
|
||||||
buf = taosDecodeFixedI64(buf, &pReq->oldConsumerId);
|
|
||||||
buf = taosDecodeFixedI64(buf, &pReq->newConsumerId);
|
|
||||||
buf = taosDecodeString(buf, &pReq->topic);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
SMsgHead header;
|
|
||||||
int32_t vgId;
|
|
||||||
int64_t consumerId;
|
|
||||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
|
||||||
char cgroup[TSDB_CGROUP_LEN];
|
|
||||||
} SMqSetCVgRsp;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
SMsgHead header;
|
|
||||||
int32_t vgId;
|
|
||||||
int64_t consumerId;
|
|
||||||
char topicName[TSDB_TOPIC_FNAME_LEN];
|
|
||||||
char cgroup[TSDB_CGROUP_LEN];
|
|
||||||
} SMqMVRebRsp;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
int64_t offset;
|
int64_t offset;
|
||||||
|
@ -2152,6 +2095,24 @@ typedef struct {
|
||||||
SSchema* pSchema;
|
SSchema* pSchema;
|
||||||
} SSchemaWrapper;
|
} SSchemaWrapper;
|
||||||
|
|
||||||
|
static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* pSchemaWrapper) {
|
||||||
|
SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
|
||||||
|
if (pSW == NULL) return pSW;
|
||||||
|
pSW->nCols = pSchemaWrapper->nCols;
|
||||||
|
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||||
|
if (pSW->pSchema == NULL) {
|
||||||
|
taosMemoryFree(pSW);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memcpy(pSW->pSchema, pSchemaWrapper->pSchema, pSW->nCols * sizeof(SSchema));
|
||||||
|
return pSW;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE void tDeleteSSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
|
||||||
|
taosMemoryFree(pSchemaWrapper->pSchema);
|
||||||
|
taosMemoryFree(pSchemaWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
|
static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) {
|
||||||
int32_t tlen = 0;
|
int32_t tlen = 0;
|
||||||
tlen += taosEncodeFixedI8(buf, pSchema->type);
|
tlen += taosEncodeFixedI8(buf, pSchema->type);
|
||||||
|
@ -2162,13 +2123,13 @@ static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema
|
||||||
return tlen;
|
return tlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void* taosDecodeSSchema(void* buf, SSchema* pSchema) {
|
static FORCE_INLINE void* taosDecodeSSchema(const void* buf, SSchema* pSchema) {
|
||||||
buf = taosDecodeFixedI8(buf, &pSchema->type);
|
buf = taosDecodeFixedI8(buf, &pSchema->type);
|
||||||
buf = taosDecodeFixedI8(buf, &pSchema->flags);
|
buf = taosDecodeFixedI8(buf, &pSchema->flags);
|
||||||
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
|
buf = taosDecodeFixedI32(buf, &pSchema->bytes);
|
||||||
buf = taosDecodeFixedI16(buf, &pSchema->colId);
|
buf = taosDecodeFixedI16(buf, &pSchema->colId);
|
||||||
buf = taosDecodeStringTo(buf, pSchema->name);
|
buf = taosDecodeStringTo(buf, pSchema->name);
|
||||||
return buf;
|
return (void*)buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSchema) {
|
static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSchema) {
|
||||||
|
@ -2198,7 +2159,7 @@ static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWr
|
||||||
return tlen;
|
return tlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) {
|
static FORCE_INLINE void* taosDecodeSSchemaWrapper(const void* buf, SSchemaWrapper* pSW) {
|
||||||
buf = taosDecodeFixedU32(buf, &pSW->nCols);
|
buf = taosDecodeFixedU32(buf, &pSW->nCols);
|
||||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||||
if (pSW->pSchema == NULL) {
|
if (pSW->pSchema == NULL) {
|
||||||
|
@ -2208,7 +2169,7 @@ static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pS
|
||||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||||
buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
|
buf = taosDecodeSSchema(buf, &pSW->pSchema[i]);
|
||||||
}
|
}
|
||||||
return buf;
|
return (void*)buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchemaWrapper* pSW) {
|
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchemaWrapper* pSW) {
|
||||||
|
@ -2615,6 +2576,10 @@ static FORCE_INLINE int32_t tEncodeSMqDataBlkRsp(void** buf, const SMqDataBlkRsp
|
||||||
void* data = taosArrayGetP(pRsp->blockData, i);
|
void* data = taosArrayGetP(pRsp->blockData, i);
|
||||||
tlen += taosEncodeFixedI32(buf, bLen);
|
tlen += taosEncodeFixedI32(buf, bLen);
|
||||||
tlen += taosEncodeBinary(buf, data, bLen);
|
tlen += taosEncodeBinary(buf, data, bLen);
|
||||||
|
if (pRsp->withSchema) {
|
||||||
|
SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(pRsp->blockSchema, i);
|
||||||
|
tlen += taosEncodeSSchemaWrapper(buf, pSW);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tlen;
|
return tlen;
|
||||||
|
@ -2627,6 +2592,7 @@ static FORCE_INLINE void* tDecodeSMqDataBlkRsp(const void* buf, SMqDataBlkRsp* p
|
||||||
buf = taosDecodeFixedI32(buf, &pRsp->blockNum);
|
buf = taosDecodeFixedI32(buf, &pRsp->blockNum);
|
||||||
pRsp->blockData = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
pRsp->blockData = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
||||||
pRsp->blockDataLen = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
pRsp->blockDataLen = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
||||||
|
pRsp->blockSchema = taosArrayInit(pRsp->blockNum, sizeof(void*));
|
||||||
if (pRsp->blockNum != 0) {
|
if (pRsp->blockNum != 0) {
|
||||||
buf = taosDecodeFixedI8(buf, &pRsp->withTbName);
|
buf = taosDecodeFixedI8(buf, &pRsp->withTbName);
|
||||||
buf = taosDecodeFixedI8(buf, &pRsp->withSchema);
|
buf = taosDecodeFixedI8(buf, &pRsp->withSchema);
|
||||||
|
@ -2639,6 +2605,11 @@ static FORCE_INLINE void* tDecodeSMqDataBlkRsp(const void* buf, SMqDataBlkRsp* p
|
||||||
buf = taosDecodeBinary(buf, &data, bLen);
|
buf = taosDecodeBinary(buf, &data, bLen);
|
||||||
taosArrayPush(pRsp->blockDataLen, &bLen);
|
taosArrayPush(pRsp->blockDataLen, &bLen);
|
||||||
taosArrayPush(pRsp->blockData, &data);
|
taosArrayPush(pRsp->blockData, &data);
|
||||||
|
if (pRsp->withSchema) {
|
||||||
|
SSchemaWrapper* pSW = (SSchemaWrapper*)taosMemoryMalloc(sizeof(SSchemaWrapper));
|
||||||
|
buf = taosDecodeSSchemaWrapper(buf, pSW);
|
||||||
|
taosArrayPush(pRsp->blockSchema, &pSW);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (void*)buf;
|
return (void*)buf;
|
||||||
|
|
|
@ -30,6 +30,7 @@ typedef enum {
|
||||||
CFG_STYPE_CFG_FILE,
|
CFG_STYPE_CFG_FILE,
|
||||||
CFG_STYPE_ENV_FILE,
|
CFG_STYPE_ENV_FILE,
|
||||||
CFG_STYPE_ENV_VAR,
|
CFG_STYPE_ENV_VAR,
|
||||||
|
CFG_STYPE_ENV_CMD,
|
||||||
CFG_STYPE_APOLLO_URL,
|
CFG_STYPE_APOLLO_URL,
|
||||||
CFG_STYPE_ARG_LIST,
|
CFG_STYPE_ARG_LIST,
|
||||||
CFG_STYPE_TAOS_OPTIONS
|
CFG_STYPE_TAOS_OPTIONS
|
||||||
|
@ -82,7 +83,7 @@ typedef struct SConfig {
|
||||||
} SConfig;
|
} SConfig;
|
||||||
|
|
||||||
SConfig *cfgInit();
|
SConfig *cfgInit();
|
||||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr);
|
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr);
|
||||||
int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
|
int32_t cfgLoadFromArray(SConfig *pCfg, SArray *pArgs); // SConfigPair
|
||||||
void cfgCleanup(SConfig *pCfg);
|
void cfgCleanup(SConfig *pCfg);
|
||||||
|
|
||||||
|
@ -105,6 +106,8 @@ const char *cfgDtypeStr(ECfgDataType type);
|
||||||
|
|
||||||
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump);
|
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump);
|
||||||
|
|
||||||
|
int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TD_ENV_H_
|
||||||
|
#define _TD_ENV_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t cfgNameMaxLen);
|
||||||
|
int32_t taosEnvToCfg(const char *envStr, char *cfgStr);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_ENV_H_*/
|
|
@ -49,6 +49,8 @@ int32_t tjsonAddItemToObject(SJson* pJson, const char* pName, SJson* pItem);
|
||||||
int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem);
|
int32_t tjsonAddItemToArray(SJson* pJson, SJson* pItem);
|
||||||
|
|
||||||
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName);
|
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName);
|
||||||
|
int32_t tjsonGetObjectName(const SJson* pJson, char** pName);
|
||||||
|
int32_t tjsonGetObjectValueString(const SJson* pJson, char** pStringValue);
|
||||||
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal);
|
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal);
|
||||||
int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal);
|
int32_t tjsonDupStringValue(const SJson* pJson, const char* pName, char** pVal);
|
||||||
int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal);
|
int32_t tjsonGetBigIntValue(const SJson* pJson, const char* pName, int64_t* pVal);
|
||||||
|
@ -81,6 +83,7 @@ char* tjsonToUnformattedString(const SJson* pJson);
|
||||||
|
|
||||||
SJson* tjsonParse(const char* pStr);
|
SJson* tjsonParse(const char* pStr);
|
||||||
bool tjsonValidateJson(const char* pJson);
|
bool tjsonValidateJson(const char* pJson);
|
||||||
|
const char* tjsonGetError();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,6 +231,10 @@ static FORCE_INLINE SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res, bool conver
|
||||||
msg->resIter++;
|
msg->resIter++;
|
||||||
if (msg->resIter < msg->rsp.blockNum) {
|
if (msg->resIter < msg->rsp.blockNum) {
|
||||||
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(msg->rsp.blockData, msg->resIter);
|
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(msg->rsp.blockData, msg->resIter);
|
||||||
|
if (msg->rsp.withSchema) {
|
||||||
|
SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(msg->rsp.blockSchema, msg->resIter);
|
||||||
|
setResSchemaInfo(&msg->resInfo, pSW->pSchema, pSW->nCols);
|
||||||
|
}
|
||||||
setQueryResultFromRsp(&msg->resInfo, pRetrieve, convertUcs4);
|
setQueryResultFromRsp(&msg->resInfo, pRetrieve, convertUcs4);
|
||||||
return &msg->resInfo;
|
return &msg->resInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,12 +254,12 @@ void taos_init_imp(void) {
|
||||||
|
|
||||||
deltaToUtcInitOnce();
|
deltaToUtcInitOnce();
|
||||||
|
|
||||||
if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, 1) != 0) {
|
if (taosCreateLog("taoslog", 10, configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||||
tscInitRes = -1;
|
tscInitRes = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosInitCfg(configDir, NULL, NULL, NULL, 1) != 0) {
|
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1) != 0) {
|
||||||
tscInitRes = -1;
|
tscInitRes = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "catalog.h"
|
#include "catalog.h"
|
||||||
#include "scheduler.h"
|
|
||||||
#include "clientInt.h"
|
#include "clientInt.h"
|
||||||
#include "clientLog.h"
|
#include "clientLog.h"
|
||||||
|
#include "scheduler.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
|
|
||||||
static SClientHbMgr clientHbMgr = {0};
|
static SClientHbMgr clientHbMgr = {0};
|
||||||
|
@ -110,7 +110,8 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
|
||||||
static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
||||||
SHbConnInfo *info = taosHashGet(pAppHbMgr->connInfo, &pRsp->connKey, sizeof(SClientHbKey));
|
SHbConnInfo *info = taosHashGet(pAppHbMgr->connInfo, &pRsp->connKey, sizeof(SClientHbKey));
|
||||||
if (NULL == info) {
|
if (NULL == info) {
|
||||||
tscWarn("fail to get connInfo, may be dropped, refId:%" PRIx64 ", type:%d", pRsp->connKey.tscRid, pRsp->connKey.connType);
|
tscWarn("fail to get connInfo, may be dropped, refId:%" PRIx64 ", type:%d", pRsp->connKey.tscRid,
|
||||||
|
pRsp->connKey.connType);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
||||||
} else {
|
} else {
|
||||||
updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &pRsp->query->epSet);
|
updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &pRsp->query->epSet);
|
||||||
pTscObj->connId = pRsp->query->connId;
|
pTscObj->connId = pRsp->query->connId;
|
||||||
|
|
||||||
if (pRsp->query->killRid) {
|
if (pRsp->query->killRid) {
|
||||||
SRequestObj *pRequest = acquireRequest(pRsp->query->killRid);
|
SRequestObj *pRequest = acquireRequest(pRsp->query->killRid);
|
||||||
if (NULL == pRequest) {
|
if (NULL == pRequest) {
|
||||||
|
@ -131,7 +132,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
||||||
releaseRequest(pRsp->query->killRid);
|
releaseRequest(pRsp->query->killRid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRsp->query->killConnection) {
|
if (pRsp->query->killConnection) {
|
||||||
taos_close(pTscObj);
|
taos_close(pTscObj);
|
||||||
}
|
}
|
||||||
|
@ -139,7 +140,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
||||||
releaseTscObj(pRsp->connKey.tscRid);
|
releaseTscObj(pRsp->connKey.tscRid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t kvNum = pRsp->info ? taosArrayGetSize(pRsp->info) : 0;
|
int32_t kvNum = pRsp->info ? taosArrayGetSize(pRsp->info) : 0;
|
||||||
|
|
||||||
tscDebug("hb got %d rsp kv", kvNum);
|
tscDebug("hb got %d rsp kv", kvNum);
|
||||||
|
@ -236,24 +237,24 @@ static int32_t hbAsyncCallBack(void *param, const SDataBuf *pMsg, int32_t code)
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) {
|
int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) {
|
||||||
int64_t now = taosGetTimestampUs();
|
int64_t now = taosGetTimestampUs();
|
||||||
SQueryDesc desc = {0};
|
SQueryDesc desc = {0};
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
void *pIter = taosHashIterate(pObj->pRequests, NULL);
|
void *pIter = taosHashIterate(pObj->pRequests, NULL);
|
||||||
while (pIter != NULL) {
|
while (pIter != NULL) {
|
||||||
int64_t *rid = pIter;
|
int64_t *rid = pIter;
|
||||||
SRequestObj *pRequest = acquireRequest(*rid);
|
SRequestObj *pRequest = acquireRequest(*rid);
|
||||||
if (NULL == pRequest) {
|
if (NULL == pRequest) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
tstrncpy(desc.sql, pRequest->sqlstr, sizeof(desc.sql));
|
tstrncpy(desc.sql, pRequest->sqlstr, sizeof(desc.sql));
|
||||||
desc.stime = pRequest->metric.start;
|
desc.stime = pRequest->metric.start;
|
||||||
desc.queryId = pRequest->requestId;
|
desc.queryId = pRequest->requestId;
|
||||||
desc.useconds = now - pRequest->metric.start;
|
desc.useconds = now - pRequest->metric.start;
|
||||||
desc.reqRid = pRequest->self;
|
desc.reqRid = pRequest->self;
|
||||||
desc.pid = hbBasic->pid;
|
desc.pid = hbBasic->pid;
|
||||||
taosGetFqdn(desc.fqdn);
|
taosGetFqdn(desc.fqdn);
|
||||||
desc.subPlanNum = pRequest->body.pDag ? pRequest->body.pDag->numOfSubplans : 0;
|
desc.subPlanNum = pRequest->body.pDag ? pRequest->body.pDag->numOfSubplans : 0;
|
||||||
|
|
||||||
|
@ -271,9 +272,9 @@ int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseRequest(*rid);
|
releaseRequest(*rid);
|
||||||
taosArrayPush(hbBasic->queryDesc, &desc);
|
taosArrayPush(hbBasic->queryDesc, &desc);
|
||||||
|
|
||||||
pIter = taosHashIterate(pObj->pRequests, pIter);
|
pIter = taosHashIterate(pObj->pRequests, pIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,14 +287,14 @@ int32_t hbGetQueryBasicInfo(SClientHbKey *connKey, SClientHbReq *req) {
|
||||||
tscWarn("tscObj rid %" PRIx64 " not exist", connKey->tscRid);
|
tscWarn("tscObj rid %" PRIx64 " not exist", connKey->tscRid);
|
||||||
return TSDB_CODE_QRY_APP_ERROR;
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t numOfQueries = pTscObj->pRequests ? taosHashGetSize(pTscObj->pRequests) : 0;
|
int32_t numOfQueries = pTscObj->pRequests ? taosHashGetSize(pTscObj->pRequests) : 0;
|
||||||
if (numOfQueries <= 0) {
|
if (numOfQueries <= 0) {
|
||||||
releaseTscObj(connKey->tscRid);
|
releaseTscObj(connKey->tscRid);
|
||||||
tscDebug("no queries on connection");
|
tscDebug("no queries on connection");
|
||||||
return TSDB_CODE_QRY_APP_ERROR;
|
return TSDB_CODE_QRY_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
SQueryHbReqBasic *hbBasic = (SQueryHbReqBasic *)taosMemoryCalloc(1, sizeof(SQueryHbReqBasic));
|
SQueryHbReqBasic *hbBasic = (SQueryHbReqBasic *)taosMemoryCalloc(1, sizeof(SQueryHbReqBasic));
|
||||||
if (NULL == hbBasic) {
|
if (NULL == hbBasic) {
|
||||||
tscError("calloc %d failed", (int32_t)sizeof(SQueryHbReqBasic));
|
tscError("calloc %d failed", (int32_t)sizeof(SQueryHbReqBasic));
|
||||||
|
@ -308,7 +309,7 @@ int32_t hbGetQueryBasicInfo(SClientHbKey *connKey, SClientHbReq *req) {
|
||||||
taosMemoryFree(hbBasic);
|
taosMemoryFree(hbBasic);
|
||||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
hbBasic->connId = pTscObj->connId;
|
hbBasic->connId = pTscObj->connId;
|
||||||
hbBasic->pid = taosGetPId();
|
hbBasic->pid = taosGetPId();
|
||||||
taosGetAppName(hbBasic->app, NULL);
|
taosGetAppName(hbBasic->app, NULL);
|
||||||
|
@ -405,7 +406,7 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req
|
||||||
}
|
}
|
||||||
|
|
||||||
hbGetQueryBasicInfo(connKey, req);
|
hbGetQueryBasicInfo(connKey, req);
|
||||||
|
|
||||||
code = hbGetExpiredDBInfo(connKey, pCatalog, req);
|
code = hbGetExpiredDBInfo(connKey, pCatalog, req);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
return code;
|
return code;
|
||||||
|
@ -471,10 +472,10 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) {
|
||||||
pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter);
|
pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (code) {
|
// if (code) {
|
||||||
// taosArrayDestroyEx(pBatchReq->reqs, hbFreeReq);
|
// taosArrayDestroyEx(pBatchReq->reqs, hbFreeReq);
|
||||||
// taosMemoryFreeClear(pBatchReq);
|
// taosMemoryFreeClear(pBatchReq);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return pBatchReq;
|
return pBatchReq;
|
||||||
}
|
}
|
||||||
|
@ -630,24 +631,23 @@ void appHbMgrCleanup(void) {
|
||||||
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
|
int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
|
||||||
for (int i = 0; i < sz; i++) {
|
for (int i = 0; i < sz; i++) {
|
||||||
SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i);
|
SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i);
|
||||||
|
|
||||||
void *pIter = taosHashIterate(pTarget->activeInfo, NULL);
|
void *pIter = taosHashIterate(pTarget->activeInfo, NULL);
|
||||||
while (pIter != NULL) {
|
while (pIter != NULL) {
|
||||||
SClientHbReq *pOneReq = pIter;
|
SClientHbReq *pOneReq = pIter;
|
||||||
hbFreeReq(pOneReq);
|
hbFreeReq(pOneReq);
|
||||||
taosHashCleanup(pOneReq->info);
|
taosHashCleanup(pOneReq->info);
|
||||||
pIter = taosHashIterate(pTarget->activeInfo, pIter);
|
pIter = taosHashIterate(pTarget->activeInfo, pIter);
|
||||||
}
|
}
|
||||||
taosHashCleanup(pTarget->activeInfo);
|
taosHashCleanup(pTarget->activeInfo);
|
||||||
pTarget->activeInfo = NULL;
|
pTarget->activeInfo = NULL;
|
||||||
|
|
||||||
|
|
||||||
pIter = taosHashIterate(pTarget->connInfo, NULL);
|
pIter = taosHashIterate(pTarget->connInfo, NULL);
|
||||||
while (pIter != NULL) {
|
while (pIter != NULL) {
|
||||||
SHbConnInfo *info = pIter;
|
SHbConnInfo *info = pIter;
|
||||||
taosMemoryFree(info->param);
|
taosMemoryFree(info->param);
|
||||||
pIter = taosHashIterate(pTarget->connInfo, pIter);
|
pIter = taosHashIterate(pTarget->connInfo, pIter);
|
||||||
}
|
}
|
||||||
taosHashCleanup(pTarget->connInfo);
|
taosHashCleanup(pTarget->connInfo);
|
||||||
pTarget->connInfo = NULL;
|
pTarget->connInfo = NULL;
|
||||||
|
|
||||||
|
@ -668,13 +668,13 @@ int hbMgrInit() {
|
||||||
hbMgrInitHandle();
|
hbMgrInitHandle();
|
||||||
|
|
||||||
// init backgroud thread
|
// init backgroud thread
|
||||||
//hbCreateThread();
|
/*hbCreateThread();*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hbMgrCleanUp() {
|
void hbMgrCleanUp() {
|
||||||
//hbStopThread();
|
// hbStopThread();
|
||||||
|
|
||||||
// destroy all appHbMgr
|
// destroy all appHbMgr
|
||||||
int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 1, 0);
|
int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 1, 0);
|
||||||
|
@ -747,11 +747,11 @@ void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey) {
|
||||||
taosMemoryFree(info->param);
|
taosMemoryFree(info->param);
|
||||||
taosHashRemove(pAppHbMgr->connInfo, &connKey, sizeof(SClientHbKey));
|
taosHashRemove(pAppHbMgr->connInfo, &connKey, sizeof(SClientHbKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == pReq || NULL == info) {
|
if (NULL == pReq || NULL == info) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1);
|
atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,17 +226,15 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
||||||
|
|
||||||
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) {
|
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) {
|
||||||
pRequest->type = pQuery->msgType;
|
pRequest->type = pQuery->msgType;
|
||||||
SPlanContext cxt = {
|
SPlanContext cxt = {.queryId = pRequest->requestId,
|
||||||
.queryId = pRequest->requestId,
|
.acctId = pRequest->pTscObj->acctId,
|
||||||
.acctId = pRequest->pTscObj->acctId,
|
.mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
|
||||||
.mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
|
.pAstRoot = pQuery->pRoot,
|
||||||
.pAstRoot = pQuery->pRoot,
|
.showRewrite = pQuery->showRewrite,
|
||||||
.showRewrite = pQuery->showRewrite,
|
.pTransporter = pRequest->pTscObj->pAppInfo->pTransporter,
|
||||||
.pTransporter = pRequest->pTscObj->pAppInfo->pTransporter,
|
.pMsg = pRequest->msgBuf,
|
||||||
.pMsg = pRequest->msgBuf,
|
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE};
|
||||||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE
|
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &cxt.pCatalog);
|
||||||
};
|
|
||||||
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &cxt.pCatalog);
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = qCreateQueryPlan(&cxt, pPlan, pNodeList);
|
code = qCreateQueryPlan(&cxt, pPlan, pNodeList);
|
||||||
}
|
}
|
||||||
|
@ -247,6 +245,7 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
|
||||||
ASSERT(pSchema != NULL && numOfCols > 0);
|
ASSERT(pSchema != NULL && numOfCols > 0);
|
||||||
|
|
||||||
pResInfo->numOfCols = numOfCols;
|
pResInfo->numOfCols = numOfCols;
|
||||||
|
// TODO handle memory leak
|
||||||
pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
pResInfo->fields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
||||||
pResInfo->userFields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
pResInfo->userFields = taosMemoryCalloc(numOfCols, sizeof(TAOS_FIELD));
|
||||||
|
|
||||||
|
@ -282,7 +281,7 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
|
||||||
|
|
||||||
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
||||||
int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr,
|
int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr,
|
||||||
pRequest->metric.start, &res);
|
pRequest->metric.start, &res);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
if (pRequest->body.queryJob != 0) {
|
if (pRequest->body.queryJob != 0) {
|
||||||
schedulerFreeJob(pRequest->body.queryJob);
|
schedulerFreeJob(pRequest->body.queryJob);
|
||||||
|
@ -840,12 +839,12 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* p = (char*) pResultInfo->pData;
|
char* p = (char*)pResultInfo->pData;
|
||||||
|
|
||||||
int32_t dataLen = *(int32_t*) p;
|
int32_t dataLen = *(int32_t*)p;
|
||||||
p += sizeof(int32_t);
|
p += sizeof(int32_t);
|
||||||
|
|
||||||
uint64_t groupId = *(uint64_t*) p;
|
uint64_t groupId = *(uint64_t*)p;
|
||||||
p += sizeof(uint64_t);
|
p += sizeof(uint64_t);
|
||||||
|
|
||||||
int32_t* colLength = (int32_t*)p;
|
int32_t* colLength = (int32_t*)p;
|
||||||
|
|
|
@ -376,7 +376,7 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
||||||
|
|
||||||
ASSERT(user);
|
ASSERT(user);
|
||||||
ASSERT(pass);
|
ASSERT(pass);
|
||||||
ASSERT(conf->db);
|
/*ASSERT(conf->db);*/
|
||||||
ASSERT(conf->groupId[0]);
|
ASSERT(conf->groupId[0]);
|
||||||
|
|
||||||
pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, conf->db, conf->port, CONN_TYPE__TMQ);
|
pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, conf->db, conf->port, CONN_TYPE__TMQ);
|
||||||
|
@ -1118,7 +1118,9 @@ SMqRspObj* tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper) {
|
||||||
|
|
||||||
pRspObj->resInfo.totalRows = 0;
|
pRspObj->resInfo.totalRows = 0;
|
||||||
pRspObj->resInfo.precision = TSDB_TIME_PRECISION_MILLI;
|
pRspObj->resInfo.precision = TSDB_TIME_PRECISION_MILLI;
|
||||||
setResSchemaInfo(&pRspObj->resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols);
|
if (!pWrapper->msg.withSchema) {
|
||||||
|
setResSchemaInfo(&pRspObj->resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols);
|
||||||
|
}
|
||||||
|
|
||||||
taosFreeQitem(pWrapper);
|
taosFreeQitem(pWrapper);
|
||||||
return pRspObj;
|
return pRspObj;
|
||||||
|
|
|
@ -220,7 +220,7 @@ struct SConfig *taosGetCfg() {
|
||||||
return tsCfg;
|
return tsCfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *envFile, const char *apolloUrl) {
|
static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile, char *apolloUrl) {
|
||||||
char cfgDir[PATH_MAX] = {0};
|
char cfgDir[PATH_MAX] = {0};
|
||||||
char cfgFile[PATH_MAX + 100] = {0};
|
char cfgFile[PATH_MAX + 100] = {0};
|
||||||
|
|
||||||
|
@ -231,6 +231,8 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
|
||||||
tstrncpy(cfgFile, cfgDir, sizeof(cfgDir));
|
tstrncpy(cfgFile, cfgDir, sizeof(cfgDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (apolloUrl == NULL || apolloUrl[0] == '\0') cfgGetApollUrl(envCmd, envFile, apolloUrl);
|
||||||
|
|
||||||
if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) {
|
if (cfgLoad(pCfg, CFG_STYPE_APOLLO_URL, apolloUrl) != 0) {
|
||||||
uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr());
|
uError("failed to load from apollo url:%s since %s", apolloUrl, terrstr());
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -251,6 +253,11 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cfgLoad(pCfg, CFG_STYPE_ENV_CMD, envCmd) != 0) {
|
||||||
|
uError("failed to load from cmd env variables since %s", terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,8 +332,8 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) {
|
||||||
if (cfgAddFloat(pCfg, "numOfCores", tsNumOfCores, 0, 100000, 1) != 0) return -1;
|
if (cfgAddFloat(pCfg, "numOfCores", tsNumOfCores, 0, 100000, 1) != 0) return -1;
|
||||||
if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1;
|
if (cfgAddInt64(pCfg, "openMax", tsOpenMax, 0, INT64_MAX, 1) != 0) return -1;
|
||||||
if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1;
|
if (cfgAddInt64(pCfg, "streamMax", tsStreamMax, 0, INT64_MAX, 1) != 0) return -1;
|
||||||
if (cfgAddInt32(pCfg, "pageSize(KB)", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1;
|
if (cfgAddInt32(pCfg, "pageSizeKB", tsPageSizeKB, 0, INT64_MAX, 1) != 0) return -1;
|
||||||
if (cfgAddInt64(pCfg, "totalMemory(KB)", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1;
|
if (cfgAddInt64(pCfg, "totalMemoryKB", tsTotalMemoryKB, 0, INT64_MAX, 1) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1;
|
if (cfgAddString(pCfg, "os sysname", info.sysname, 1) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "os nodename", info.nodename, 1) != 0) return -1;
|
if (cfgAddString(pCfg, "os nodename", info.nodename, 1) != 0) return -1;
|
||||||
if (cfgAddString(pCfg, "os release", info.release, 1) != 0) return -1;
|
if (cfgAddString(pCfg, "os release", info.release, 1) != 0) return -1;
|
||||||
|
@ -572,8 +579,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile,
|
||||||
const char *apolloUrl, SArray *pArgs, bool tsc) {
|
char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||||
osDefaultInit();
|
osDefaultInit();
|
||||||
|
|
||||||
SConfig *pCfg = cfgInit();
|
SConfig *pCfg = cfgInit();
|
||||||
|
@ -588,7 +595,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
||||||
if (taosAddServerLogCfg(pCfg) != 0) return -1;
|
if (taosAddServerLogCfg(pCfg) != 0) return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosLoadCfg(pCfg, cfgDir, envFile, apolloUrl) != 0) {
|
if (taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) {
|
||||||
uError("failed to load cfg since %s", terrstr());
|
uError("failed to load cfg since %s", terrstr());
|
||||||
cfgCleanup(pCfg);
|
cfgCleanup(pCfg);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -625,7 +632,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloUrl, SArray *pArgs, bool tsc) {
|
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||||
if (tsCfg != NULL) return 0;
|
if (tsCfg != NULL) return 0;
|
||||||
tsCfg = cfgInit();
|
tsCfg = cfgInit();
|
||||||
|
|
||||||
|
@ -640,7 +647,7 @@ int32_t taosInitCfg(const char *cfgDir, const char *envFile, const char *apolloU
|
||||||
}
|
}
|
||||||
taosAddSystemCfg(tsCfg);
|
taosAddSystemCfg(tsCfg);
|
||||||
|
|
||||||
if (taosLoadCfg(tsCfg, cfgDir, envFile, apolloUrl) != 0) {
|
if (taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) {
|
||||||
uError("failed to load cfg since %s", terrstr());
|
uError("failed to load cfg since %s", terrstr());
|
||||||
cfgCleanup(tsCfg);
|
cfgCleanup(tsCfg);
|
||||||
tsCfg = NULL;
|
tsCfg = NULL;
|
||||||
|
|
|
@ -93,7 +93,87 @@ STSRow *tGetSubmitBlkNext(SSubmitBlkIter *pIter) {
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
// TODO: KEEP one suite of iterator API finally.
|
||||||
|
// 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts
|
||||||
|
// 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later
|
||||||
|
// 3) finally, rename tInitSubmitMsgIterEx to tInitSubmitMsgIter
|
||||||
|
|
||||||
|
int32_t tInitSubmitMsgIterEx(const SSubmitReq *pMsg, SSubmitMsgIter *pIter) {
|
||||||
|
if (pMsg == NULL) {
|
||||||
|
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pIter->totalLen = htonl(pMsg->length);
|
||||||
|
ASSERT(pIter->totalLen > 0);
|
||||||
|
pIter->len = 0;
|
||||||
|
pIter->pMsg = pMsg;
|
||||||
|
if (pIter->totalLen <= sizeof(SSubmitReq)) {
|
||||||
|
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tGetSubmitMsgNextEx(SSubmitMsgIter *pIter, SSubmitBlk **pPBlock) {
|
||||||
|
ASSERT(pIter->len >= 0);
|
||||||
|
|
||||||
|
if (pIter->len == 0) {
|
||||||
|
pIter->len += sizeof(SSubmitReq);
|
||||||
|
} else {
|
||||||
|
if (pIter->len >= pIter->totalLen) {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
SSubmitBlk *pSubmitBlk = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
|
||||||
|
pIter->len += (sizeof(SSubmitBlk) + pIter->dataLen + pIter->schemaLen);
|
||||||
|
ASSERT(pIter->len > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pIter->len > pIter->totalLen) {
|
||||||
|
terrno = TSDB_CODE_TDB_SUBMIT_MSG_MSSED_UP;
|
||||||
|
*pPBlock = NULL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pIter->len == pIter->totalLen) {
|
||||||
|
*pPBlock = NULL;
|
||||||
|
} else {
|
||||||
|
*pPBlock = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len);
|
||||||
|
pIter->uid = htobe64((*pPBlock)->uid);
|
||||||
|
pIter->suid = htobe64((*pPBlock)->suid);
|
||||||
|
pIter->sversion = htonl((*pPBlock)->sversion);
|
||||||
|
pIter->dataLen = htonl((*pPBlock)->dataLen);
|
||||||
|
pIter->schemaLen = htonl((*pPBlock)->schemaLen);
|
||||||
|
pIter->numOfRows = htons((*pPBlock)->numOfRows);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tInitSubmitBlkIterEx(SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, SSubmitBlkIter *pIter) {
|
||||||
|
if (pMsgIter->dataLen <= 0) return -1;
|
||||||
|
pIter->totalLen = pMsgIter->dataLen;
|
||||||
|
pIter->len = 0;
|
||||||
|
pIter->row = (STSRow *)(pBlock->data + pMsgIter->schemaLen);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
STSRow *tGetSubmitBlkNextEx(SSubmitBlkIter *pIter) {
|
||||||
|
STSRow *row = pIter->row;
|
||||||
|
|
||||||
|
if (pIter->len >= pIter->totalLen) {
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
pIter->len += TD_ROW_LEN(row);
|
||||||
|
if (pIter->len < pIter->totalLen) {
|
||||||
|
pIter->row = POINTER_SHIFT(row, TD_ROW_LEN(row));
|
||||||
|
}
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
int32_t tEncodeSEpSet(SCoder *pEncoder, const SEpSet *pEp) {
|
int32_t tEncodeSEpSet(SCoder *pEncoder, const SEpSet *pEp) {
|
||||||
if (tEncodeI8(pEncoder, pEp->inUse) < 0) return -1;
|
if (tEncodeI8(pEncoder, pEp->inUse) < 0) return -1;
|
||||||
if (tEncodeI8(pEncoder, pEp->numOfEps) < 0) return -1;
|
if (tEncodeI8(pEncoder, pEp->numOfEps) < 0) return -1;
|
||||||
|
|
|
@ -24,6 +24,7 @@ static struct {
|
||||||
bool printVersion;
|
bool printVersion;
|
||||||
char envFile[PATH_MAX];
|
char envFile[PATH_MAX];
|
||||||
char apolloUrl[PATH_MAX];
|
char apolloUrl[PATH_MAX];
|
||||||
|
const char **envCmd;
|
||||||
SArray *pArgs; // SConfigPair
|
SArray *pArgs; // SConfigPair
|
||||||
SDnode *pDnode;
|
SDnode *pDnode;
|
||||||
EDndNodeType ntype;
|
EDndNodeType ntype;
|
||||||
|
@ -56,6 +57,9 @@ static void dmSetSignalHandle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
|
int32_t cmdEnvIndex = 0;
|
||||||
|
global.envCmd = taosMemoryMalloc(argc-1);
|
||||||
|
memset(global.envCmd, 0, argc-1);
|
||||||
for (int32_t i = 1; i < argc; ++i) {
|
for (int32_t i = 1; i < argc; ++i) {
|
||||||
if (strcmp(argv[i], "-c") == 0) {
|
if (strcmp(argv[i], "-c") == 0) {
|
||||||
if (i < argc - 1) {
|
if (i < argc - 1) {
|
||||||
|
@ -70,7 +74,7 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "-a") == 0) {
|
} else if (strcmp(argv[i], "-a") == 0) {
|
||||||
tstrncpy(global.apolloUrl, argv[++i], PATH_MAX);
|
tstrncpy(global.apolloUrl, argv[++i], PATH_MAX);
|
||||||
} else if (strcmp(argv[i], "-e") == 0) {
|
} else if (strcmp(argv[i], "-E") == 0) {
|
||||||
tstrncpy(global.envFile, argv[++i], PATH_MAX);
|
tstrncpy(global.envFile, argv[++i], PATH_MAX);
|
||||||
} else if (strcmp(argv[i], "-n") == 0) {
|
} else if (strcmp(argv[i], "-n") == 0) {
|
||||||
global.ntype = atoi(argv[++i]);
|
global.ntype = atoi(argv[++i]);
|
||||||
|
@ -84,6 +88,9 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
global.dumpConfig = true;
|
global.dumpConfig = true;
|
||||||
} else if (strcmp(argv[i], "-V") == 0) {
|
} else if (strcmp(argv[i], "-V") == 0) {
|
||||||
global.printVersion = true;
|
global.printVersion = true;
|
||||||
|
} else if (strcmp(argv[i], "-e") == 0) {
|
||||||
|
global.envCmd[cmdEnvIndex] = argv[++i];
|
||||||
|
cmdEnvIndex++;
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +136,7 @@ static SDnodeOpt dmGetOpt() {
|
||||||
static int32_t dmInitLog() {
|
static int32_t dmInitLog() {
|
||||||
char logName[12] = {0};
|
char logName[12] = {0};
|
||||||
snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype));
|
snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype));
|
||||||
return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0);
|
return taosCreateLog(logName, 1, configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dmSetProcInfo(int32_t argc, char **argv) {
|
static void dmSetProcInfo(int32_t argc, char **argv) {
|
||||||
|
@ -168,6 +175,10 @@ static int32_t dmRunDnode() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void taosCleanupArgs() {
|
||||||
|
if (global.envCmd != NULL) taosMemoryFree(global.envCmd);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char const *argv[]) {
|
int main(int argc, char const *argv[]) {
|
||||||
if (!taosCheckSystemIsSmallEnd()) {
|
if (!taosCheckSystemIsSmallEnd()) {
|
||||||
printf("failed to start since on non-small-end machines\n");
|
printf("failed to start since on non-small-end machines\n");
|
||||||
|
@ -176,26 +187,31 @@ int main(int argc, char const *argv[]) {
|
||||||
|
|
||||||
if (dmParseArgs(argc, argv) != 0) {
|
if (dmParseArgs(argc, argv) != 0) {
|
||||||
printf("failed to start since parse args error\n");
|
printf("failed to start since parse args error\n");
|
||||||
|
taosCleanupArgs();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.generateGrant) {
|
if (global.generateGrant) {
|
||||||
dmGenerateGrant();
|
dmGenerateGrant();
|
||||||
|
taosCleanupArgs();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.printVersion) {
|
if (global.printVersion) {
|
||||||
dmPrintVersion();
|
dmPrintVersion();
|
||||||
|
taosCleanupArgs();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmInitLog() != 0) {
|
if (dmInitLog() != 0) {
|
||||||
dError("failed to start since init log error");
|
printf("failed to start since init log error");
|
||||||
|
taosCleanupArgs();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosInitCfg(configDir, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
|
if (taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
|
||||||
dError("failed to start since read config error");
|
dError("failed to start since read config error");
|
||||||
|
taosCleanupArgs();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,9 +219,11 @@ int main(int argc, char const *argv[]) {
|
||||||
dmDumpCfg();
|
dmDumpCfg();
|
||||||
taosCleanupCfg();
|
taosCleanupCfg();
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
|
taosCleanupArgs();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dmSetProcInfo(argc, (char **)argv);
|
dmSetProcInfo(argc, (char **)argv);
|
||||||
|
taosCleanupArgs();
|
||||||
return dmRunDnode();
|
return dmRunDnode();
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ TdFilePtr dmCheckRunning(const char *dataDir) {
|
||||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to lock file:%s since %s", filepath, terrstr());
|
dError("failed to open file:%s since %s", filepath, terrstr());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -476,33 +476,37 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||||
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub) {
|
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub) {
|
||||||
SSdb* pSdb = pMnode->pSdb;
|
SSdb* pSdb = pMnode->pSdb;
|
||||||
SVgObj* pVgroup = NULL;
|
SVgObj* pVgroup = NULL;
|
||||||
SQueryPlan* pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
SQueryPlan* pPlan = NULL;
|
||||||
if (pPlan == NULL) {
|
SSubplan* plan = NULL;
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
if (pTopic->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||||
return -1;
|
pPlan = qStringToQueryPlan(pTopic->physicalPlan);
|
||||||
|
if (pPlan == NULL) {
|
||||||
|
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT(pSub->vgNum == -1);
|
||||||
|
|
||||||
|
pSub->vgNum = 0;
|
||||||
|
|
||||||
|
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
|
||||||
|
if (levelNum != 1) {
|
||||||
|
qDestroyQueryPlan(pPlan);
|
||||||
|
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, 0);
|
||||||
|
|
||||||
|
int32_t opNum = LIST_LENGTH(inner->pNodeList);
|
||||||
|
if (opNum != 1) {
|
||||||
|
qDestroyQueryPlan(pPlan);
|
||||||
|
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
plan = nodesListGetNode(inner->pNodeList, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(pSub->vgNum == -1);
|
|
||||||
|
|
||||||
pSub->vgNum = 0;
|
|
||||||
|
|
||||||
int32_t levelNum = LIST_LENGTH(pPlan->pSubplans);
|
|
||||||
if (levelNum != 1) {
|
|
||||||
qDestroyQueryPlan(pPlan);
|
|
||||||
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, 0);
|
|
||||||
|
|
||||||
int32_t opNum = LIST_LENGTH(inner->pNodeList);
|
|
||||||
if (opNum != 1) {
|
|
||||||
qDestroyQueryPlan(pPlan);
|
|
||||||
terrno = TSDB_CODE_MND_UNSUPPORTED_TOPIC;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
SSubplan* plan = nodesListGetNode(inner->pNodeList, 0);
|
|
||||||
|
|
||||||
int64_t unexistKey = -1;
|
int64_t unexistKey = -1;
|
||||||
SMqConsumerEpInSub* pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t));
|
SMqConsumerEpInSub* pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t));
|
||||||
ASSERT(pEpInSub);
|
ASSERT(pEpInSub);
|
||||||
|
@ -519,38 +523,35 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
|
||||||
}
|
}
|
||||||
|
|
||||||
pSub->vgNum++;
|
pSub->vgNum++;
|
||||||
plan->execNode.nodeId = pVgroup->vgId;
|
|
||||||
plan->execNode.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
|
||||||
|
|
||||||
SMqVgEp* pVgEp = taosMemoryMalloc(sizeof(SMqVgEp));
|
SMqVgEp* pVgEp = taosMemoryMalloc(sizeof(SMqVgEp));
|
||||||
pVgEp->epSet = plan->execNode.epSet;
|
pVgEp->epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||||
pVgEp->vgId = plan->execNode.nodeId;
|
pVgEp->vgId = pVgroup->vgId;
|
||||||
|
taosArrayPush(pEpInSub->vgs, &pVgEp);
|
||||||
#if 0
|
|
||||||
SMqConsumerEp consumerEp = {0};
|
|
||||||
consumerEp.status = 0;
|
|
||||||
consumerEp.consumerId = -1;
|
|
||||||
consumerEp.epSet = plan->execNode.epSet;
|
|
||||||
consumerEp.vgId = plan->execNode.nodeId;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mDebug("init subscribption %s, assign vg: %d", pSub->key, pVgEp->vgId);
|
mDebug("init subscribption %s, assign vg: %d", pSub->key, pVgEp->vgId);
|
||||||
|
|
||||||
int32_t msgLen;
|
if (pTopic->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||||
if (qSubPlanToString(plan, &pVgEp->qmsg, &msgLen) < 0) {
|
int32_t msgLen;
|
||||||
sdbRelease(pSdb, pVgroup);
|
|
||||||
qDestroyQueryPlan(pPlan);
|
plan->execNode.epSet = pVgEp->epSet;
|
||||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
plan->execNode.nodeId = pVgEp->vgId;
|
||||||
return -1;
|
|
||||||
|
if (qSubPlanToString(plan, &pVgEp->qmsg, &msgLen) < 0) {
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
qDestroyQueryPlan(pPlan);
|
||||||
|
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pVgEp->qmsg = strdup("");
|
||||||
}
|
}
|
||||||
taosArrayPush(pEpInSub->vgs, &pVgEp);
|
|
||||||
|
|
||||||
ASSERT(taosHashGetSize(pSub->consumerHash) == 1);
|
ASSERT(taosHashGetSize(pSub->consumerHash) == 1);
|
||||||
|
|
||||||
/*taosArrayPush(pSub->unassignedVg, &consumerEp);*/
|
/*taosArrayPush(pSub->unassignedVg, &consumerEp);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(pEpInSub->vgs->size > 0);
|
|
||||||
pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t));
|
pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t));
|
||||||
|
|
||||||
ASSERT(pEpInSub->vgs->size > 0);
|
ASSERT(pEpInSub->vgs->size > 0);
|
||||||
|
|
|
@ -453,7 +453,6 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pStb->ast2Len > 0) {
|
if (pStb->ast2Len > 0) {
|
||||||
int32_t qmsgLen2 = 0;
|
|
||||||
if (mndConvertRSmaTask(pStb->pAst2, 0, 0, &pRSmaParam->qmsg2, &pRSmaParam->qmsg2Len) != TSDB_CODE_SUCCESS) {
|
if (mndConvertRSmaTask(pStb->pAst2, 0, 0, &pRSmaParam->qmsg2, &pRSmaParam->qmsg2Len) != TSDB_CODE_SUCCESS) {
|
||||||
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
taosMemoryFreeClear(pRSmaParam->pFuncIds);
|
||||||
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
taosMemoryFreeClear(pRSmaParam->qmsg1);
|
||||||
|
|
|
@ -282,10 +282,10 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
|
||||||
topicObj.version = 1;
|
topicObj.version = 1;
|
||||||
topicObj.sql = strdup(pCreate->sql);
|
topicObj.sql = strdup(pCreate->sql);
|
||||||
topicObj.sqlLen = strlen(pCreate->sql) + 1;
|
topicObj.sqlLen = strlen(pCreate->sql) + 1;
|
||||||
topicObj.ast = strdup(pCreate->ast);
|
|
||||||
topicObj.astLen = strlen(pCreate->ast) + 1;
|
|
||||||
|
|
||||||
if (pCreate->ast && pCreate->ast[0]) {
|
if (pCreate->ast && pCreate->ast[0]) {
|
||||||
|
topicObj.ast = strdup(pCreate->ast);
|
||||||
|
topicObj.astLen = strlen(pCreate->ast) + 1;
|
||||||
topicObj.subType = TOPIC_SUB_TYPE__TABLE;
|
topicObj.subType = TOPIC_SUB_TYPE__TABLE;
|
||||||
topicObj.withTbName = 0;
|
topicObj.withTbName = 0;
|
||||||
topicObj.withSchema = 0;
|
topicObj.withSchema = 0;
|
||||||
|
@ -314,6 +314,9 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
topicObj.ast = strdup("");
|
||||||
|
topicObj.astLen = 1;
|
||||||
|
topicObj.physicalPlan = strdup("");
|
||||||
topicObj.subType = TOPIC_SUB_TYPE__DB;
|
topicObj.subType = TOPIC_SUB_TYPE__DB;
|
||||||
topicObj.withTbName = 1;
|
topicObj.withTbName = 1;
|
||||||
topicObj.withSchema = 1;
|
topicObj.withSchema = 1;
|
||||||
|
|
|
@ -51,7 +51,7 @@ static FORCE_INLINE tb_uid_t metaGenerateUid(SMeta* pMeta) { return tGenIdPI64()
|
||||||
#define META_CHILD_TABLE TD_CHILD_TABLE
|
#define META_CHILD_TABLE TD_CHILD_TABLE
|
||||||
#define META_NORMAL_TABLE TD_NORMAL_TABLE
|
#define META_NORMAL_TABLE TD_NORMAL_TABLE
|
||||||
|
|
||||||
int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg);
|
int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
|
||||||
int metaDropTable(SMeta* pMeta, tb_uid_t uid);
|
int metaDropTable(SMeta* pMeta, tb_uid_t uid);
|
||||||
int metaCommit(SMeta* pMeta);
|
int metaCommit(SMeta* pMeta);
|
||||||
int32_t metaCreateTSma(SMeta* pMeta, SSmaCfg* pCfg);
|
int32_t metaCreateTSma(SMeta* pMeta, SSmaCfg* pCfg);
|
||||||
|
@ -74,7 +74,7 @@ tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur);
|
||||||
// SMetaDB
|
// SMetaDB
|
||||||
int metaOpenDB(SMeta* pMeta);
|
int metaOpenDB(SMeta* pMeta);
|
||||||
void metaCloseDB(SMeta* pMeta);
|
void metaCloseDB(SMeta* pMeta);
|
||||||
int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg);
|
int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
|
||||||
int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid);
|
int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid);
|
||||||
int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg);
|
int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg);
|
||||||
int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid);
|
int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid);
|
||||||
|
|
|
@ -57,7 +57,6 @@ int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid);
|
||||||
int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg);
|
int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg);
|
||||||
void tsdbCleanupReadHandle(tsdbReaderT queryHandle);
|
void tsdbCleanupReadHandle(tsdbReaderT queryHandle);
|
||||||
int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg);
|
int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TSDB_FILE_HEAD = 0, // .head
|
TSDB_FILE_HEAD = 0, // .head
|
||||||
TSDB_FILE_DATA, // .data
|
TSDB_FILE_DATA, // .data
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TD_VNODE_TSDB_SMA_H_
|
||||||
|
#define _TD_VNODE_TSDB_SMA_H_
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
#include "thash.h"
|
||||||
|
#include "tmsg.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef int32_t (*__tb_ddl_fn_t)(void *ahandle, void **result, void *p1, void *p2);
|
||||||
|
|
||||||
|
struct STbDdlH {
|
||||||
|
void *ahandle;
|
||||||
|
void *result;
|
||||||
|
__tb_ddl_fn_t fp;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tb_uid_t suid;
|
||||||
|
SArray *tbUids;
|
||||||
|
SHashObj *uidHash;
|
||||||
|
} STbUidStore;
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tsdbUidStoreInit(STbUidStore **pStore) {
|
||||||
|
ASSERT(*pStore == NULL);
|
||||||
|
*pStore = taosMemoryCalloc(1, sizeof(STbUidStore));
|
||||||
|
if (*pStore == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid);
|
||||||
|
void tsdbUidStoreDestory(STbUidStore *pStore);
|
||||||
|
void *tsdbUidStoreFree(STbUidStore *pStore);
|
||||||
|
|
||||||
|
int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq);
|
||||||
|
int32_t tsdbFetchTbUidList(void *pTsdb, void **result, void *suid, void *uid);
|
||||||
|
int32_t tsdbUpdateTbUidList(STsdb *pTsdb, STbUidStore *pUidStore);
|
||||||
|
int32_t tsdbTriggerRSma(STsdb *pTsdb, SMeta *pMeta, void *pMsg, int32_t inputType);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_VNODE_TSDB_SMA_H_*/
|
|
@ -103,6 +103,8 @@ struct SVnode {
|
||||||
|
|
||||||
#define TD_VID(PVNODE) (PVNODE)->config.vgId
|
#define TD_VID(PVNODE) (PVNODE)->config.vgId
|
||||||
|
|
||||||
|
typedef struct STbDdlH STbDdlH;
|
||||||
|
|
||||||
// sma
|
// sma
|
||||||
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data);
|
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data);
|
||||||
|
|
||||||
|
@ -116,6 +118,8 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data);
|
||||||
|
|
||||||
#include "vnodeSync.h"
|
#include "vnodeSync.h"
|
||||||
|
|
||||||
|
#include "tsdbSma.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -250,7 +250,7 @@ void metaCloseDB(SMeta *pMeta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
|
int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
||||||
tb_uid_t uid;
|
tb_uid_t uid;
|
||||||
SMetaDB *pMetaDb;
|
SMetaDB *pMetaDb;
|
||||||
void *pKey;
|
void *pKey;
|
||||||
|
@ -349,6 +349,12 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) {
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
// child table handle for rsma
|
||||||
|
if (pHandle && pHandle->fp) {
|
||||||
|
if (((*pHandle->fp)(pHandle->ahandle, &pHandle->result, &ctbIdxKey.suid, &uid)) < 0) {
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
}
|
||||||
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
} else if (pTbCfg->type == META_NORMAL_TABLE) {
|
||||||
pKey = &uid;
|
pKey = &uid;
|
||||||
kLen = sizeof(uid);
|
kLen = sizeof(uid);
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#include "vnodeInt.h"
|
#include "vnodeInt.h"
|
||||||
|
|
||||||
int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) {
|
int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
||||||
// Validate the tbOptions
|
// Validate the tbOptions
|
||||||
// if (metaValidateTbCfg(pMeta, pTbCfg) < 0) {
|
// if (metaValidateTbCfg(pMeta, pTbCfg) < 0) {
|
||||||
// // TODO: handle error
|
// // TODO: handle error
|
||||||
|
@ -24,7 +24,7 @@ int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg) {
|
||||||
|
|
||||||
// TODO: add atomicity
|
// TODO: add atomicity
|
||||||
|
|
||||||
if (metaSaveTableToDB(pMeta, pTbCfg) < 0) {
|
if (metaSaveTableToDB(pMeta, pTbCfg, pHandle) < 0) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -411,8 +411,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
||||||
|
|
||||||
SMqDataBlkRsp rsp = {0};
|
SMqDataBlkRsp rsp = {0};
|
||||||
rsp.reqOffset = pReq->currentOffset;
|
rsp.reqOffset = pReq->currentOffset;
|
||||||
|
rsp.withSchema = pExec->withSchema;
|
||||||
rsp.blockData = taosArrayInit(0, sizeof(void*));
|
rsp.blockData = taosArrayInit(0, sizeof(void*));
|
||||||
rsp.blockDataLen = taosArrayInit(0, sizeof(int32_t));
|
rsp.blockDataLen = taosArrayInit(0, sizeof(int32_t));
|
||||||
|
rsp.blockSchema = taosArrayInit(0, sizeof(void*));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
consumerEpoch = atomic_load_32(&pExec->epoch);
|
consumerEpoch = atomic_load_32(&pExec->epoch);
|
||||||
|
@ -512,6 +514,12 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
||||||
ASSERT(actualLen <= dataStrLen);
|
ASSERT(actualLen <= dataStrLen);
|
||||||
taosArrayPush(rsp.blockDataLen, &actualLen);
|
taosArrayPush(rsp.blockDataLen, &actualLen);
|
||||||
taosArrayPush(rsp.blockData, &buf);
|
taosArrayPush(rsp.blockData, &buf);
|
||||||
|
|
||||||
|
if (pExec->withSchema) {
|
||||||
|
SSchemaWrapper* pSW = tCloneSSchemaWrapper(pExec->pExecReader[workerId]->pSchemaWrapper);
|
||||||
|
taosArrayPush(rsp.blockSchema, &pSW);
|
||||||
|
}
|
||||||
|
|
||||||
rsp.blockNum++;
|
rsp.blockNum++;
|
||||||
}
|
}
|
||||||
// db subscribe
|
// db subscribe
|
||||||
|
@ -540,6 +548,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
||||||
ASSERT(actualLen <= dataStrLen);
|
ASSERT(actualLen <= dataStrLen);
|
||||||
taosArrayPush(rsp.blockDataLen, &actualLen);
|
taosArrayPush(rsp.blockDataLen, &actualLen);
|
||||||
taosArrayPush(rsp.blockData, &buf);
|
taosArrayPush(rsp.blockData, &buf);
|
||||||
|
|
||||||
|
SSchemaWrapper* pSW = tCloneSSchemaWrapper(pExec->pExecReader[workerId]->pSchemaWrapper);
|
||||||
|
taosArrayPush(rsp.blockSchema, &pSW);
|
||||||
|
|
||||||
rsp.blockNum++;
|
rsp.blockNum++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -586,6 +598,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
||||||
// TODO destroy
|
// TODO destroy
|
||||||
taosArrayDestroy(rsp.blockData);
|
taosArrayDestroy(rsp.blockData);
|
||||||
taosArrayDestroy(rsp.blockDataLen);
|
taosArrayDestroy(rsp.blockDataLen);
|
||||||
|
taosArrayDestroyP(rsp.blockSchema, (FDelete)tDeleteSSchemaWrapper);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -827,12 +841,16 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
|
||||||
pExec->pWalReader = walOpenReadHandle(pTq->pVnode->pWal);
|
pExec->pWalReader = walOpenReadHandle(pTq->pVnode->pWal);
|
||||||
for (int32_t i = 0; i < 5; i++) {
|
for (int32_t i = 0; i < 5; i++) {
|
||||||
pExec->pExecReader[i] = tqInitSubmitMsgScanner(pTq->pVnode->pMeta);
|
pExec->pExecReader[i] = tqInitSubmitMsgScanner(pTq->pVnode->pMeta);
|
||||||
SReadHandle handle = {
|
if (pExec->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||||
.reader = pExec->pExecReader[i],
|
SReadHandle handle = {
|
||||||
.meta = pTq->pVnode->pMeta,
|
.reader = pExec->pExecReader[i],
|
||||||
};
|
.meta = pTq->pVnode->pMeta,
|
||||||
pExec->task[i] = qCreateStreamExecTaskInfo(pExec->qmsg, &handle);
|
};
|
||||||
ASSERT(pExec->task[i]);
|
pExec->task[i] = qCreateStreamExecTaskInfo(pExec->qmsg, &handle);
|
||||||
|
ASSERT(pExec->task[i]);
|
||||||
|
} else {
|
||||||
|
pExec->task[i] = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
taosHashPut(pTq->execs, req.subKey, strlen(req.subKey), pExec, sizeof(STqExec));
|
taosHashPut(pTq->execs, req.subKey, strlen(req.subKey), pExec, sizeof(STqExec));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -65,7 +65,9 @@ bool tqNextDataBlock(STqReadHandle* pHandle) {
|
||||||
|
|
||||||
/*pHandle->pBlock->uid = htobe64(pHandle->pBlock->uid);*/
|
/*pHandle->pBlock->uid = htobe64(pHandle->pBlock->uid);*/
|
||||||
/*if (pHandle->tbUid == pHandle->pBlock->uid) {*/
|
/*if (pHandle->tbUid == pHandle->pBlock->uid) {*/
|
||||||
ASSERT(pHandle->tbIdHash);
|
if (pHandle->tbIdHash == NULL) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
void* ret = taosHashGet(pHandle->tbIdHash, &pHandle->pBlock->uid, sizeof(int64_t));
|
void* ret = taosHashGet(pHandle->tbIdHash, &pHandle->pBlock->uid, sizeof(int64_t));
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
/*printf("retrieve one tb %ld\n", pHandle->pBlock->uid);*/
|
/*printf("retrieve one tb %ld\n", pHandle->pBlock->uid);*/
|
||||||
|
@ -107,26 +109,15 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
|
||||||
*pNumOfRows = pHandle->pBlock->numOfRows;
|
*pNumOfRows = pHandle->pBlock->numOfRows;
|
||||||
int32_t colNumNeed = taosArrayGetSize(pHandle->pColIdList);
|
int32_t colNumNeed = taosArrayGetSize(pHandle->pColIdList);
|
||||||
|
|
||||||
if (colNumNeed > pSchemaWrapper->nCols) {
|
if (colNumNeed == 0) {
|
||||||
colNumNeed = pSchemaWrapper->nCols;
|
*ppCols = taosArrayInit(pSchemaWrapper->nCols, sizeof(SColumnInfoData));
|
||||||
}
|
if (*ppCols == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
*ppCols = taosArrayInit(colNumNeed, sizeof(SColumnInfoData));
|
int32_t colMeta = 0;
|
||||||
if (*ppCols == NULL) {
|
while (colMeta < pSchemaWrapper->nCols) {
|
||||||
return -1;
|
SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta];
|
||||||
}
|
|
||||||
|
|
||||||
int32_t colMeta = 0;
|
|
||||||
int32_t colNeed = 0;
|
|
||||||
while (colMeta < pSchemaWrapper->nCols && colNeed < colNumNeed) {
|
|
||||||
SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta];
|
|
||||||
col_id_t colIdSchema = pColSchema->colId;
|
|
||||||
col_id_t colIdNeed = *(col_id_t*)taosArrayGet(pHandle->pColIdList, colNeed);
|
|
||||||
if (colIdSchema < colIdNeed) {
|
|
||||||
colMeta++;
|
|
||||||
} else if (colIdSchema > colIdNeed) {
|
|
||||||
colNeed++;
|
|
||||||
} else {
|
|
||||||
SColumnInfoData colInfo = {0};
|
SColumnInfoData colInfo = {0};
|
||||||
colInfo.info.bytes = pColSchema->bytes;
|
colInfo.info.bytes = pColSchema->bytes;
|
||||||
colInfo.info.colId = pColSchema->colId;
|
colInfo.info.colId = pColSchema->colId;
|
||||||
|
@ -137,7 +128,40 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
|
||||||
}
|
}
|
||||||
taosArrayPush(*ppCols, &colInfo);
|
taosArrayPush(*ppCols, &colInfo);
|
||||||
colMeta++;
|
colMeta++;
|
||||||
colNeed++;
|
}
|
||||||
|
} else {
|
||||||
|
if (colNumNeed > pSchemaWrapper->nCols) {
|
||||||
|
colNumNeed = pSchemaWrapper->nCols;
|
||||||
|
}
|
||||||
|
|
||||||
|
*ppCols = taosArrayInit(colNumNeed, sizeof(SColumnInfoData));
|
||||||
|
if (*ppCols == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t colMeta = 0;
|
||||||
|
int32_t colNeed = 0;
|
||||||
|
while (colMeta < pSchemaWrapper->nCols && colNeed < colNumNeed) {
|
||||||
|
SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta];
|
||||||
|
col_id_t colIdSchema = pColSchema->colId;
|
||||||
|
col_id_t colIdNeed = *(col_id_t*)taosArrayGet(pHandle->pColIdList, colNeed);
|
||||||
|
if (colIdSchema < colIdNeed) {
|
||||||
|
colMeta++;
|
||||||
|
} else if (colIdSchema > colIdNeed) {
|
||||||
|
colNeed++;
|
||||||
|
} else {
|
||||||
|
SColumnInfoData colInfo = {0};
|
||||||
|
colInfo.info.bytes = pColSchema->bytes;
|
||||||
|
colInfo.info.colId = pColSchema->colId;
|
||||||
|
colInfo.info.type = pColSchema->type;
|
||||||
|
|
||||||
|
if (colInfoDataEnsureCapacity(&colInfo, 0, *pNumOfRows) < 0) {
|
||||||
|
goto FAIL;
|
||||||
|
}
|
||||||
|
taosArrayPush(*ppCols, &colInfo);
|
||||||
|
colMeta++;
|
||||||
|
colNeed++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,8 @@ static STsdb *tsdbNew(const char *path, SVnode *pVnode, const STsdbCfg *pTsdbCfg
|
||||||
|
|
||||||
static void tsdbFree(STsdb *pTsdb) {
|
static void tsdbFree(STsdb *pTsdb) {
|
||||||
if (pTsdb) {
|
if (pTsdb) {
|
||||||
// tsdbFreeSmaEnv(REPO_TSMA_ENV(pTsdb));
|
tsdbFreeSmaEnv(REPO_TSMA_ENV(pTsdb));
|
||||||
// tsdbFreeSmaEnv(REPO_RSMA_ENV(pTsdb));
|
tsdbFreeSmaEnv(REPO_RSMA_ENV(pTsdb));
|
||||||
tsdbFreeFS(pTsdb->fs);
|
tsdbFreeFS(pTsdb->fs);
|
||||||
taosMemoryFreeClear(pTsdb->path);
|
taosMemoryFreeClear(pTsdb->path);
|
||||||
taosMemoryFree(pTsdb);
|
taosMemoryFree(pTsdb);
|
||||||
|
|
|
@ -3636,6 +3636,8 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch
|
||||||
tsdbError("%p failed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId);
|
tsdbError("%p failed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId);
|
||||||
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
||||||
goto _error;
|
goto _error;
|
||||||
|
} else {
|
||||||
|
tsdbDebug("%p succeed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTbCfg->type != META_SUPER_TABLE) {
|
if (pTbCfg->type != META_SUPER_TABLE) {
|
||||||
|
|
|
@ -33,6 +33,8 @@ static const char *TSDB_SMA_DNAME[] = {
|
||||||
|
|
||||||
#define SMA_TEST_INDEX_NAME "smaTestIndexName" // TODO: just for test
|
#define SMA_TEST_INDEX_NAME "smaTestIndexName" // TODO: just for test
|
||||||
#define SMA_TEST_INDEX_UID 2000000001 // TODO: just for test
|
#define SMA_TEST_INDEX_UID 2000000001 // TODO: just for test
|
||||||
|
|
||||||
|
typedef struct SRSmaInfo SRSmaInfo;
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SMA_STORAGE_LEVEL_TSDB = 0, // use days of self-defined e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f200.tsma
|
SMA_STORAGE_LEVEL_TSDB = 0, // use days of self-defined e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f200.tsma
|
||||||
SMA_STORAGE_LEVEL_DFILESET = 1 // use days of TS data e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f1906.tsma
|
SMA_STORAGE_LEVEL_DFILESET = 1 // use days of TS data e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f1906.tsma
|
||||||
|
@ -46,6 +48,7 @@ typedef struct SPoolMem {
|
||||||
|
|
||||||
struct SSmaEnv {
|
struct SSmaEnv {
|
||||||
TdThreadRwlock lock;
|
TdThreadRwlock lock;
|
||||||
|
int8_t type;
|
||||||
TXN txn;
|
TXN txn;
|
||||||
SPoolMem *pPool;
|
SPoolMem *pPool;
|
||||||
SDiskID did;
|
SDiskID did;
|
||||||
|
@ -55,6 +58,7 @@ struct SSmaEnv {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SMA_ENV_LOCK(env) ((env)->lock)
|
#define SMA_ENV_LOCK(env) ((env)->lock)
|
||||||
|
#define SMA_ENV_TYPE(env) ((env)->type)
|
||||||
#define SMA_ENV_DID(env) ((env)->did)
|
#define SMA_ENV_DID(env) ((env)->did)
|
||||||
#define SMA_ENV_ENV(env) ((env)->dbEnv)
|
#define SMA_ENV_ENV(env) ((env)->dbEnv)
|
||||||
#define SMA_ENV_PATH(env) ((env)->path)
|
#define SMA_ENV_PATH(env) ((env)->path)
|
||||||
|
@ -91,16 +95,45 @@ typedef struct {
|
||||||
* - TSDB_SMA_STAT_EXPIRED: 1) If sma calculation of history TS data is not finished; 2) Or if the TSDB is open,
|
* - 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.
|
* without information about its previous state.
|
||||||
* - TSDB_SMA_STAT_DROPPED: 1)sma dropped
|
* - TSDB_SMA_STAT_DROPPED: 1)sma dropped
|
||||||
|
* N.B. only applicable to tsma
|
||||||
*/
|
*/
|
||||||
int8_t state; // ETsdbSmaStat
|
int8_t state; // ETsdbSmaStat
|
||||||
SHashObj *expiredWindows; // key: skey of time window, value: N/A
|
SHashObj *expiredWindows; // key: skey of time window, value: N/A
|
||||||
STSma *pSma; // cache schema
|
STSma *pSma; // cache schema
|
||||||
} SSmaStatItem;
|
} SSmaStatItem;
|
||||||
|
|
||||||
|
#define RSMA_MAX_LEVEL 2
|
||||||
|
#define RSMA_TASK_INFO_HASH_SLOT 8
|
||||||
|
struct SRSmaInfo {
|
||||||
|
void *taskInfo[RSMA_MAX_LEVEL]; // qTaskInfo_t
|
||||||
|
};
|
||||||
|
|
||||||
struct SSmaStat {
|
struct SSmaStat {
|
||||||
SHashObj *smaStatItems; // key: indexUid, value: SSmaStatItem
|
union {
|
||||||
|
SHashObj *smaStatItems; // key: indexUid, value: SSmaStatItem for tsma
|
||||||
|
SHashObj *rsmaInfoHash; // key: stbUid, value: SRSmaInfo;
|
||||||
|
};
|
||||||
T_REF_DECLARE()
|
T_REF_DECLARE()
|
||||||
};
|
};
|
||||||
|
#define SMA_STAT_ITEMS(s) ((s)->smaStatItems)
|
||||||
|
#define SMA_STAT_INFO_HASH(s) ((s)->rsmaInfoHash)
|
||||||
|
|
||||||
|
static FORCE_INLINE void tsdbFreeTaskHandle(qTaskInfo_t *taskHandle) {
|
||||||
|
// Note: free/kill may in RC
|
||||||
|
qTaskInfo_t otaskHandle = atomic_load_ptr(taskHandle);
|
||||||
|
if (otaskHandle && atomic_val_compare_exchange_ptr(taskHandle, otaskHandle, NULL)) {
|
||||||
|
qDestroyTask(otaskHandle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE void *tsdbFreeRSmaInfo(SRSmaInfo *pInfo) {
|
||||||
|
for (int32_t i = 0; i < RSMA_MAX_LEVEL; ++i) {
|
||||||
|
if (pInfo->taskInfo[i]) {
|
||||||
|
tsdbFreeTaskHandle(pInfo->taskInfo[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// declaration of static functions
|
// declaration of static functions
|
||||||
|
|
||||||
|
@ -108,11 +141,11 @@ struct SSmaStat {
|
||||||
static int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t version);
|
static int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t version);
|
||||||
static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey,
|
static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey,
|
||||||
int64_t version);
|
int64_t version);
|
||||||
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat);
|
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat, int8_t smaType);
|
||||||
static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem);
|
static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem);
|
||||||
static int32_t tsdbDestroySmaState(SSmaStat *pSmaStat);
|
static int32_t tsdbDestroySmaState(SSmaStat *pSmaStat, int8_t smaType);
|
||||||
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did);
|
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did);
|
||||||
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaEnv **pEnv);
|
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did, SSmaEnv **pEnv);
|
||||||
static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t indexUid, TSKEY skey);
|
static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t indexUid, TSKEY skey);
|
||||||
static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
||||||
static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat);
|
||||||
|
@ -139,6 +172,7 @@ static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[])
|
||||||
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg);
|
static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg);
|
||||||
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg);
|
static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg);
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tsdbUpdateTbUidListImpl(STsdb *pTsdb, tb_uid_t *suid, SArray *tbUids);
|
||||||
// mgmt interface
|
// mgmt interface
|
||||||
static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid);
|
static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid);
|
||||||
|
|
||||||
|
@ -229,7 +263,7 @@ static void *poolMalloc(void *arg, size_t size) {
|
||||||
SPoolMem *pMem;
|
SPoolMem *pMem;
|
||||||
|
|
||||||
pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size);
|
pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size);
|
||||||
if (pMem == NULL) {
|
if (!pMem) {
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,15 +351,17 @@ static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]) {
|
||||||
snprintf(dirName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s", TD_DIRSEP, vgId, TD_DIRSEP, TSDB_SMA_DNAME[smaType]);
|
snprintf(dirName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s", TD_DIRSEP, vgId, TD_DIRSEP, TSDB_SMA_DNAME[smaType]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did) {
|
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did) {
|
||||||
SSmaEnv *pEnv = NULL;
|
SSmaEnv *pEnv = NULL;
|
||||||
|
|
||||||
pEnv = (SSmaEnv *)taosMemoryCalloc(1, sizeof(SSmaEnv));
|
pEnv = (SSmaEnv *)taosMemoryCalloc(1, sizeof(SSmaEnv));
|
||||||
if (pEnv == NULL) {
|
if (!pEnv) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SMA_ENV_TYPE(pEnv) = smaType;
|
||||||
|
|
||||||
int code = taosThreadRwlockInit(&(pEnv->lock), NULL);
|
int code = taosThreadRwlockInit(&(pEnv->lock), NULL);
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(code);
|
terrno = TAOS_SYSTEM_ERROR(code);
|
||||||
|
@ -334,15 +370,15 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(path && (strlen(path) > 0));
|
ASSERT(path && (strlen(path) > 0));
|
||||||
pEnv->path = strdup(path);
|
SMA_ENV_PATH(pEnv) = strdup(path);
|
||||||
if (pEnv->path == NULL) {
|
if (!SMA_ENV_PATH(pEnv)) {
|
||||||
tsdbFreeSmaEnv(pEnv);
|
tsdbFreeSmaEnv(pEnv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pEnv->did = did;
|
SMA_ENV_DID(pEnv) = did;
|
||||||
|
|
||||||
if (tsdbInitSmaStat(&pEnv->pStat) != TSDB_CODE_SUCCESS) {
|
if (tsdbInitSmaStat(&SMA_ENV_STAT(pEnv), smaType) != TSDB_CODE_SUCCESS) {
|
||||||
tsdbFreeSmaEnv(pEnv);
|
tsdbFreeSmaEnv(pEnv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -354,7 +390,7 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pEnv->pPool = openPool()) == NULL) {
|
if (!(pEnv->pPool = openPool())) {
|
||||||
tsdbFreeSmaEnv(pEnv);
|
tsdbFreeSmaEnv(pEnv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -362,14 +398,14 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
|
||||||
return pEnv;
|
return pEnv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaEnv **pEnv) {
|
static int32_t tsdbInitSmaEnv(STsdb *pTsdb, int8_t smaType, const char *path, SDiskID did, SSmaEnv **pEnv) {
|
||||||
if (!pEnv) {
|
if (!pEnv) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*pEnv == NULL) {
|
if (!(*pEnv)) {
|
||||||
if ((*pEnv = tsdbNewSmaEnv(pTsdb, path, did)) == NULL) {
|
if (!(*pEnv = tsdbNewSmaEnv(pTsdb, smaType, path, did))) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -385,7 +421,7 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SDiskID did, SSmaE
|
||||||
*/
|
*/
|
||||||
void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) {
|
void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) {
|
||||||
if (pSmaEnv) {
|
if (pSmaEnv) {
|
||||||
tsdbDestroySmaState(pSmaEnv->pStat);
|
tsdbDestroySmaState(pSmaEnv->pStat, SMA_ENV_TYPE(pSmaEnv));
|
||||||
taosMemoryFreeClear(pSmaEnv->pStat);
|
taosMemoryFreeClear(pSmaEnv->pStat);
|
||||||
taosMemoryFreeClear(pSmaEnv->path);
|
taosMemoryFreeClear(pSmaEnv->path);
|
||||||
taosThreadRwlockDestroy(&(pSmaEnv->lock));
|
taosThreadRwlockDestroy(&(pSmaEnv->lock));
|
||||||
|
@ -401,7 +437,7 @@ void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
||||||
if (pStat == NULL) return 0;
|
if (!pStat) return 0;
|
||||||
|
|
||||||
int ref = T_REF_INC(pStat);
|
int ref = T_REF_INC(pStat);
|
||||||
tsdbDebug("vgId:%d ref sma stat:%p, val:%d", REPO_ID(pTsdb), pStat, ref);
|
tsdbDebug("vgId:%d ref sma stat:%p, val:%d", REPO_ID(pTsdb), pStat, ref);
|
||||||
|
@ -409,17 +445,17 @@ static int32_t tsdbRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
static int32_t tsdbUnRefSmaStat(STsdb *pTsdb, SSmaStat *pStat) {
|
||||||
if (pStat == NULL) return 0;
|
if (!pStat) return 0;
|
||||||
|
|
||||||
int ref = T_REF_DEC(pStat);
|
int ref = T_REF_DEC(pStat);
|
||||||
tsdbDebug("vgId:%d unref sma stat:%p, val:%d", REPO_ID(pTsdb), pStat, ref);
|
tsdbDebug("vgId:%d unref sma stat:%p, val:%d", REPO_ID(pTsdb), pStat, ref);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
|
static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat, int8_t smaType) {
|
||||||
ASSERT(pSmaStat != NULL);
|
ASSERT(pSmaStat != NULL);
|
||||||
|
|
||||||
if (*pSmaStat != NULL) { // no lock
|
if (*pSmaStat) { // no lock
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,19 +464,31 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
|
||||||
* 2. Currently, there is mutex lock when init SSmaEnv, thus no need add lock on SSmaStat, and please add lock if
|
* 2. Currently, there is mutex lock when init SSmaEnv, thus no need add lock on SSmaStat, and please add lock if
|
||||||
* tsdbInitSmaStat invoked in other multithread environment later.
|
* tsdbInitSmaStat invoked in other multithread environment later.
|
||||||
*/
|
*/
|
||||||
if (*pSmaStat == NULL) {
|
if (!(*pSmaStat)) {
|
||||||
*pSmaStat = (SSmaStat *)taosMemoryCalloc(1, sizeof(SSmaStat));
|
*pSmaStat = (SSmaStat *)taosMemoryCalloc(1, sizeof(SSmaStat));
|
||||||
if (*pSmaStat == NULL) {
|
if (!(*pSmaStat)) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*pSmaStat)->smaStatItems =
|
if (smaType == TSDB_SMA_TYPE_ROLLUP) {
|
||||||
taosHashInit(SMA_STATE_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
SMA_STAT_INFO_HASH(*pSmaStat) = taosHashInit(
|
||||||
|
RSMA_TASK_INFO_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
|
||||||
|
|
||||||
if ((*pSmaStat)->smaStatItems == NULL) {
|
if (!SMA_STAT_INFO_HASH(*pSmaStat)) {
|
||||||
taosMemoryFreeClear(*pSmaStat);
|
taosMemoryFreeClear(*pSmaStat);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
} else if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||||
|
SMA_STAT_ITEMS(*pSmaStat) =
|
||||||
|
taosHashInit(SMA_STATE_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||||
|
|
||||||
|
if (!SMA_STAT_ITEMS(*pSmaStat)) {
|
||||||
|
taosMemoryFreeClear(*pSmaStat);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -462,7 +510,7 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem) {
|
static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem) {
|
||||||
if (pSmaStatItem != NULL) {
|
if (pSmaStatItem) {
|
||||||
tdDestroyTSma(pSmaStatItem->pSma);
|
tdDestroyTSma(pSmaStatItem->pSma);
|
||||||
taosMemoryFreeClear(pSmaStatItem->pSma);
|
taosMemoryFreeClear(pSmaStatItem->pSma);
|
||||||
taosHashCleanup(pSmaStatItem->expiredWindows);
|
taosHashCleanup(pSmaStatItem->expiredWindows);
|
||||||
|
@ -477,16 +525,28 @@ static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem) {
|
||||||
* @param pSmaStat
|
* @param pSmaStat
|
||||||
* @return int32_t
|
* @return int32_t
|
||||||
*/
|
*/
|
||||||
int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) {
|
int32_t tsdbDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
|
||||||
if (pSmaStat) {
|
if (pSmaStat) {
|
||||||
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
|
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
|
||||||
void *item = taosHashIterate(pSmaStat->smaStatItems, NULL);
|
if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||||
while (item != NULL) {
|
void *item = taosHashIterate(SMA_STAT_ITEMS(pSmaStat), NULL);
|
||||||
SSmaStatItem *pItem = *(SSmaStatItem **)item;
|
while (item) {
|
||||||
tsdbFreeSmaStatItem(pItem);
|
SSmaStatItem *pItem = *(SSmaStatItem **)item;
|
||||||
item = taosHashIterate(pSmaStat->smaStatItems, item);
|
tsdbFreeSmaStatItem(pItem);
|
||||||
|
item = taosHashIterate(SMA_STAT_ITEMS(pSmaStat), item);
|
||||||
|
}
|
||||||
|
taosHashCleanup(SMA_STAT_ITEMS(pSmaStat));
|
||||||
|
} else if (smaType == TSDB_SMA_TYPE_ROLLUP) {
|
||||||
|
void *infoHash = taosHashIterate(SMA_STAT_INFO_HASH(pSmaStat), NULL);
|
||||||
|
while (infoHash) {
|
||||||
|
SRSmaInfo *pInfoHash = *(SRSmaInfo **)infoHash;
|
||||||
|
tsdbFreeRSmaInfo(pInfoHash);
|
||||||
|
infoHash = taosHashIterate(SMA_STAT_INFO_HASH(pSmaStat), infoHash);
|
||||||
|
}
|
||||||
|
taosHashCleanup(SMA_STAT_INFO_HASH(pSmaStat));
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
taosHashCleanup(pSmaStat->smaStatItems);
|
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -497,12 +557,12 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
||||||
// return if already init
|
// return if already init
|
||||||
switch (smaType) {
|
switch (smaType) {
|
||||||
case TSDB_SMA_TYPE_TIME_RANGE:
|
case TSDB_SMA_TYPE_TIME_RANGE:
|
||||||
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_TSMA_ENV(pTsdb))) != NULL) {
|
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_TSMA_ENV(pTsdb)))) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TSDB_SMA_TYPE_ROLLUP:
|
case TSDB_SMA_TYPE_ROLLUP:
|
||||||
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_RSMA_ENV(pTsdb))) != NULL) {
|
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&REPO_RSMA_ENV(pTsdb)))) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -515,7 +575,7 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
||||||
tsdbLockRepo(pTsdb);
|
tsdbLockRepo(pTsdb);
|
||||||
pEnv = (smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_load_ptr(&REPO_TSMA_ENV(pTsdb))
|
pEnv = (smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_load_ptr(&REPO_TSMA_ENV(pTsdb))
|
||||||
: atomic_load_ptr(&REPO_RSMA_ENV(pTsdb));
|
: atomic_load_ptr(&REPO_RSMA_ENV(pTsdb));
|
||||||
if (pEnv == NULL) {
|
if (!pEnv) {
|
||||||
char rname[TSDB_FILENAME_LEN] = {0};
|
char rname[TSDB_FILENAME_LEN] = {0};
|
||||||
|
|
||||||
SDiskID did = {0};
|
SDiskID did = {0};
|
||||||
|
@ -531,7 +591,7 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tsdbInitSmaEnv(pTsdb, rname, did, &pEnv) != TSDB_CODE_SUCCESS) {
|
if (tsdbInitSmaEnv(pTsdb, smaType, rname, did, &pEnv) != TSDB_CODE_SUCCESS) {
|
||||||
tsdbUnlockRepo(pTsdb);
|
tsdbUnlockRepo(pTsdb);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -547,10 +607,10 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
||||||
static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey,
|
static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey,
|
||||||
int64_t version) {
|
int64_t version) {
|
||||||
SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
||||||
if (pItem == NULL) {
|
if (!pItem) {
|
||||||
// TODO: use TSDB_SMA_STAT_EXPIRED and update by stream computing later
|
// TODO: use TSDB_SMA_STAT_EXPIRED and update by stream computing later
|
||||||
pItem = tsdbNewSmaStatItem(TSDB_SMA_STAT_OK); // TODO use the real state
|
pItem = tsdbNewSmaStatItem(TSDB_SMA_STAT_OK); // TODO use the real state
|
||||||
if (pItem == NULL) {
|
if (!pItem) {
|
||||||
// Response to stream computing: OOM
|
// Response to stream computing: OOM
|
||||||
// For query, if the indexUid not found, the TSDB should tell query module to query raw TS data.
|
// For query, if the indexUid not found, the TSDB should tell query module to query raw TS data.
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
@ -558,7 +618,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
|
||||||
|
|
||||||
// cache smaMeta
|
// cache smaMeta
|
||||||
STSma *pSma = metaGetSmaInfoByIndex(REPO_META(pTsdb), indexUid, true);
|
STSma *pSma = metaGetSmaInfoByIndex(REPO_META(pTsdb), indexUid, true);
|
||||||
if (pSma == NULL) {
|
if (!pSma) {
|
||||||
terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META;
|
terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META;
|
||||||
taosHashCleanup(pItem->expiredWindows);
|
taosHashCleanup(pItem->expiredWindows);
|
||||||
taosMemoryFree(pItem);
|
taosMemoryFree(pItem);
|
||||||
|
@ -574,7 +634,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
|
||||||
taosMemoryFree(pItem);
|
taosMemoryFree(pItem);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
} else if ((pItem = *(SSmaStatItem **)pItem) == NULL) {
|
} else if (!(pItem = *(SSmaStatItem **)pItem)) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -634,7 +694,7 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
||||||
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||||
SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv);
|
SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv);
|
||||||
|
|
||||||
TASSERT(pEnv != NULL && pStat != NULL && pItemsHash != NULL);
|
TASSERT(pEnv && pStat && pItemsHash);
|
||||||
|
|
||||||
// basic procedure
|
// basic procedure
|
||||||
// TODO: optimization
|
// TODO: optimization
|
||||||
|
@ -651,7 +711,7 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
tGetSubmitMsgNext(&msgIter, &pBlock);
|
tGetSubmitMsgNext(&msgIter, &pBlock);
|
||||||
if (pBlock == NULL) break;
|
if (!pBlock) break;
|
||||||
|
|
||||||
STSmaWrapper *pSW = NULL;
|
STSmaWrapper *pSW = NULL;
|
||||||
STSma *pTSma = NULL;
|
STSma *pTSma = NULL;
|
||||||
|
@ -664,7 +724,7 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
STSRow *row = tGetSubmitBlkNext(&blkIter);
|
STSRow *row = tGetSubmitBlkNext(&blkIter);
|
||||||
if (row == NULL) {
|
if (!row) {
|
||||||
tdFreeTSmaWrapper(pSW);
|
tdFreeTSmaWrapper(pSW);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -672,10 +732,10 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
||||||
if (pSW) {
|
if (pSW) {
|
||||||
pSW = tdFreeTSmaWrapper(pSW);
|
pSW = tdFreeTSmaWrapper(pSW);
|
||||||
}
|
}
|
||||||
if ((pSW = metaGetSmaInfoByTable(REPO_META(pTsdb), pBlock->suid)) == NULL) {
|
if (!(pSW = metaGetSmaInfoByTable(REPO_META(pTsdb), pBlock->suid))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ((pSW->number) <= 0 || (pSW->tSma == NULL)) {
|
if ((pSW->number) <= 0 || !pSW->tSma) {
|
||||||
pSW = tdFreeTSmaWrapper(pSW);
|
pSW = tdFreeTSmaWrapper(pSW);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -721,10 +781,10 @@ static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t ind
|
||||||
|
|
||||||
tsdbRefSmaStat(pTsdb, pStat);
|
tsdbRefSmaStat(pTsdb, pStat);
|
||||||
|
|
||||||
if (pStat && pStat->smaStatItems) {
|
if (pStat && SMA_STAT_ITEMS(pStat)) {
|
||||||
pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid));
|
||||||
}
|
}
|
||||||
if ((pItem != NULL) && ((pItem = *(SSmaStatItem **)pItem) != NULL)) {
|
if ((pItem) && ((pItem = *(SSmaStatItem **)pItem))) {
|
||||||
// pItem resides in hash buffer all the time unless drop sma index
|
// pItem resides in hash buffer all the time unless drop sma index
|
||||||
// TODO: multithread protect
|
// TODO: multithread protect
|
||||||
if (taosHashRemove(pItem->expiredWindows, &skey, sizeof(TSKEY)) != 0) {
|
if (taosHashRemove(pItem->expiredWindows, &skey, sizeof(TSKEY)) != 0) {
|
||||||
|
@ -934,7 +994,7 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH) {
|
||||||
|
|
||||||
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid) {
|
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid) {
|
||||||
STsdb *pTsdb = pSmaH->pTsdb;
|
STsdb *pTsdb = pSmaH->pTsdb;
|
||||||
ASSERT(pSmaH->dFile.path == NULL && pSmaH->dFile.pDB == NULL);
|
ASSERT(!pSmaH->dFile.path && !pSmaH->dFile.pDB);
|
||||||
|
|
||||||
pSmaH->dFile.fid = fid;
|
pSmaH->dFile.fid = fid;
|
||||||
char tSmaFile[TSDB_FILENAME_LEN] = {0};
|
char tSmaFile[TSDB_FILENAME_LEN] = {0};
|
||||||
|
@ -1004,6 +1064,8 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
||||||
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
||||||
const SArray *pDataBlocks = (const SArray *)msg;
|
const SArray *pDataBlocks = (const SArray *)msg;
|
||||||
|
|
||||||
|
// TODO: destroy SSDataBlocks(msg)
|
||||||
|
|
||||||
// For super table aggregation, the sma data is stored in vgroup calculated from the hash value of stable name. Thus
|
// For super table aggregation, the sma data is stored in vgroup calculated from the hash value of stable name. Thus
|
||||||
// the sma data would arrive ahead of the update-expired-window msg.
|
// the sma data would arrive ahead of the update-expired-window msg.
|
||||||
if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) {
|
if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -1011,7 +1073,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pDataBlocks == NULL) {
|
if (!pDataBlocks) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
tsdbWarn("vgId:%d insert tSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
|
tsdbWarn("vgId:%d insert tSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
|
||||||
return terrno;
|
return terrno;
|
||||||
|
@ -1029,11 +1091,11 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
||||||
|
|
||||||
tsdbRefSmaStat(pTsdb, pStat);
|
tsdbRefSmaStat(pTsdb, pStat);
|
||||||
|
|
||||||
if (pStat && pStat->smaStatItems) {
|
if (pStat && SMA_STAT_ITEMS(pStat)) {
|
||||||
pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL) || tsdbSmaStatIsDropped(pItem)) {
|
if (!pItem || !(pItem = *(SSmaStatItem **)pItem) || tsdbSmaStatIsDropped(pItem)) {
|
||||||
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
@ -1061,9 +1123,8 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
|
||||||
int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit);
|
int32_t storageLevel = tsdbGetSmaStorageLevel(pSma->interval, pSma->intervalUnit);
|
||||||
int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel);
|
int32_t daysPerFile = tsdbGetTSmaDays(pTsdb, tSmaH.interval, storageLevel);
|
||||||
|
|
||||||
// key: skey + groupId
|
char smaKey[SMA_KEY_LEN] = {0}; // key: skey + groupId
|
||||||
char smaKey[SMA_KEY_LEN] = {0};
|
char dataBuf[512] = {0}; // val: aggr data // TODO: handle 512 buffer?
|
||||||
char dataBuf[512] = {0};
|
|
||||||
void *pDataBuf = NULL;
|
void *pDataBuf = NULL;
|
||||||
int32_t sz = taosArrayGetSize(pDataBlocks);
|
int32_t sz = taosArrayGetSize(pDataBlocks);
|
||||||
for (int32_t i = 0; i < sz; ++i) {
|
for (int32_t i = 0; i < sz; ++i) {
|
||||||
|
@ -1228,7 +1289,7 @@ static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid) {
|
||||||
tsdbDebug("vgId:%d drop tSma local cache for %" PRIi64, REPO_ID(pTsdb), indexUid);
|
tsdbDebug("vgId:%d drop tSma local cache for %" PRIi64, REPO_ID(pTsdb), indexUid);
|
||||||
|
|
||||||
SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
|
SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
|
||||||
if ((pItem != NULL) || ((pItem = *(SSmaStatItem **)pItem) != NULL)) {
|
if ((pItem) || ((pItem = *(SSmaStatItem **)pItem))) {
|
||||||
if (tsdbSmaStatIsDropped(pItem)) {
|
if (tsdbSmaStatIsDropped(pItem)) {
|
||||||
tsdbDebug("vgId:%d tSma stat is already dropped for %" PRIi64, REPO_ID(pTsdb), indexUid);
|
tsdbDebug("vgId:%d tSma stat is already dropped for %" PRIi64, REPO_ID(pTsdb), indexUid);
|
||||||
return TSDB_CODE_TDB_INVALID_ACTION; // TODO: duplicate drop msg would be intercepted by mnode
|
return TSDB_CODE_TDB_INVALID_ACTION; // TODO: duplicate drop msg would be intercepted by mnode
|
||||||
|
@ -1284,19 +1345,13 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg) {
|
||||||
SSmaEnv *pEnv = atomic_load_ptr(&REPO_RSMA_ENV(pTsdb));
|
SSmaEnv *pEnv = atomic_load_ptr(&REPO_RSMA_ENV(pTsdb));
|
||||||
int64_t indexUid = SMA_TEST_INDEX_UID;
|
int64_t indexUid = SMA_TEST_INDEX_UID;
|
||||||
|
|
||||||
if (pEnv == NULL) {
|
if (!pEnv) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pEnv == NULL) {
|
if (!pDataBlocks) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
|
||||||
tsdbWarn("vgId:%d insert rSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
|
||||||
return terrno;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pDataBlocks == NULL) {
|
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
tsdbWarn("vgId:%d insert rSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
|
tsdbWarn("vgId:%d insert rSma data failed since pDataBlocks is NULL", REPO_ID(pTsdb));
|
||||||
return terrno;
|
return terrno;
|
||||||
|
@ -1313,11 +1368,11 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg) {
|
||||||
|
|
||||||
tsdbRefSmaStat(pTsdb, pStat);
|
tsdbRefSmaStat(pTsdb, pStat);
|
||||||
|
|
||||||
if (pStat && pStat->smaStatItems) {
|
if (pStat && SMA_STAT_ITEMS(pStat)) {
|
||||||
pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
pItem = taosHashGet(SMA_STAT_ITEMS(pStat), &indexUid, sizeof(indexUid));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL) || tsdbSmaStatIsDropped(pItem)) {
|
if (!pItem || !(pItem = *(SSmaStatItem **)pItem) || tsdbSmaStatIsDropped(pItem)) {
|
||||||
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
|
@ -1438,7 +1493,7 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) {
|
||||||
++pReadH->smaFsIter.iter;
|
++pReadH->smaFsIter.iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReadH->pDFile != NULL) {
|
if (pReadH->pDFile) {
|
||||||
tsdbDebug("vg%d: smaFile %s matched", REPO_ID(pReadH->pTsdb), "[pSmaFile dir]");
|
tsdbDebug("vg%d: smaFile %s matched", REPO_ID(pReadH->pTsdb), "[pSmaFile dir]");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1471,7 +1526,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
||||||
|
|
||||||
tsdbRefSmaStat(pTsdb, pStat);
|
tsdbRefSmaStat(pTsdb, pStat);
|
||||||
SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
|
SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pEnv), &indexUid, sizeof(indexUid));
|
||||||
if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL)) {
|
if (!pItem || !(pItem = *(SSmaStatItem **)pItem)) {
|
||||||
// Normally pItem should not be NULL, mark all windows as expired and notify query module to fetch raw TS data if
|
// Normally pItem should not be NULL, mark all windows as expired and notify query module to fetch raw TS data if
|
||||||
// it's NULL.
|
// it's NULL.
|
||||||
tsdbUnRefSmaStat(pTsdb, pStat);
|
tsdbUnRefSmaStat(pTsdb, pStat);
|
||||||
|
@ -1484,7 +1539,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
||||||
int32_t nQueryWin = taosArrayGetSize(pQuerySKey);
|
int32_t nQueryWin = taosArrayGetSize(pQuerySKey);
|
||||||
for (int32_t n = 0; n < nQueryWin; ++n) {
|
for (int32_t n = 0; n < nQueryWin; ++n) {
|
||||||
TSKEY skey = taosArrayGet(pQuerySKey, n);
|
TSKEY skey = taosArrayGet(pQuerySKey, n);
|
||||||
if (taosHashGet(pItem->expiredWindows, &skey, sizeof(TSKEY)) != NULL) {
|
if (taosHashGet(pItem->expiredWindows, &skey, sizeof(TSKEY))) {
|
||||||
// TODO: mark this window as expired.
|
// TODO: mark this window as expired.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1500,7 +1555,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosHashGet(pItem->expiredWindows, &querySKey, sizeof(TSKEY)) != NULL) {
|
if (taosHashGet(pItem->expiredWindows, &querySKey, sizeof(TSKEY))) {
|
||||||
// TODO: mark this window as expired.
|
// TODO: mark this window as expired.
|
||||||
tsdbDebug("vgId:%d skey %" PRIi64 " of window exists in expired window for index %" PRIi64, REPO_ID(pTsdb),
|
tsdbDebug("vgId:%d skey %" PRIi64 " of window exists in expired window for index %" PRIi64, REPO_ID(pTsdb),
|
||||||
querySKey, indexUid);
|
querySKey, indexUid);
|
||||||
|
@ -1534,7 +1589,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
||||||
|
|
||||||
void *result = NULL;
|
void *result = NULL;
|
||||||
int32_t valueSize = 0;
|
int32_t valueSize = 0;
|
||||||
if ((result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize)) == NULL) {
|
if (!(result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize))) {
|
||||||
tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s",
|
tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s",
|
||||||
REPO_ID(pTsdb), indexUid, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), tstrerror(terrno));
|
REPO_ID(pTsdb), indexUid, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), tstrerror(terrno));
|
||||||
tsdbCloseDBF(&tReadH.dFile);
|
tsdbCloseDBF(&tReadH.dFile);
|
||||||
|
@ -1578,7 +1633,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
|
||||||
|
|
||||||
int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) {
|
int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) {
|
||||||
SSmaCfg vCreateSmaReq = {0};
|
SSmaCfg vCreateSmaReq = {0};
|
||||||
if (tDeserializeSVCreateTSmaReq(pMsg, &vCreateSmaReq) == NULL) {
|
if (!tDeserializeSVCreateTSmaReq(pMsg, &vCreateSmaReq)) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
tsdbWarn("vgId:%d TDMT_VND_CREATE_SMA received but deserialize failed since %s", REPO_ID(pTsdb), terrstr(terrno));
|
tsdbWarn("vgId:%d TDMT_VND_CREATE_SMA received but deserialize failed since %s", REPO_ID(pTsdb), terrstr(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1604,7 +1659,7 @@ int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) {
|
||||||
|
|
||||||
int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) {
|
int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) {
|
||||||
SVDropTSmaReq vDropSmaReq = {0};
|
SVDropTSmaReq vDropSmaReq = {0};
|
||||||
if (tDeserializeSVDropTSmaReq(pMsg, &vDropSmaReq) == NULL) {
|
if (!tDeserializeSVDropTSmaReq(pMsg, &vDropSmaReq)) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1632,6 +1687,395 @@ int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check and init qTaskInfo_t, only applicable to stable with SRSmaParam.
|
||||||
|
*
|
||||||
|
* @param pTsdb
|
||||||
|
* @param pMeta
|
||||||
|
* @param pReq
|
||||||
|
* @return int32_t
|
||||||
|
*/
|
||||||
|
int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq) {
|
||||||
|
SRSmaParam *param = pReq->stbCfg.pRSmaParam;
|
||||||
|
|
||||||
|
if (!param) {
|
||||||
|
tsdbDebug("vgId:%d return directly since no rollup for stable %s %" PRIi64, REPO_ID(pTsdb), pReq->name,
|
||||||
|
pReq->stbCfg.suid);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((param->qmsg1Len == 0) && (param->qmsg2Len == 0)) {
|
||||||
|
tsdbWarn("vgId:%d no qmsg1/qmsg2 for rollup stable %s %" PRIi64, REPO_ID(pTsdb), pReq->name, pReq->stbCfg.suid);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_ROLLUP) != TSDB_CODE_SUCCESS) {
|
||||||
|
terrno = TSDB_CODE_TDB_INIT_FAILED;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb);
|
||||||
|
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||||
|
SRSmaInfo *pRSmaInfo = NULL;
|
||||||
|
|
||||||
|
pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), &pReq->stbCfg.suid, sizeof(tb_uid_t));
|
||||||
|
if (pRSmaInfo) {
|
||||||
|
tsdbWarn("vgId:%d rsma info already exists for stb: %s, %" PRIi64, REPO_ID(pTsdb), pReq->name, pReq->stbCfg.suid);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
pRSmaInfo = (SRSmaInfo *)taosMemoryCalloc(1, sizeof(SRSmaInfo));
|
||||||
|
if (!pRSmaInfo) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
STqReadHandle *pReadHandle = tqInitSubmitMsgScanner(pMeta);
|
||||||
|
if (!pReadHandle) {
|
||||||
|
taosMemoryFree(pRSmaInfo);
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
SReadHandle handle = {
|
||||||
|
.reader = pReadHandle,
|
||||||
|
.meta = pMeta,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (param->qmsg1) {
|
||||||
|
pRSmaInfo->taskInfo[0] = qCreateStreamExecTaskInfo(param->qmsg1, &handle);
|
||||||
|
if (!pRSmaInfo->taskInfo[0]) {
|
||||||
|
taosMemoryFree(pRSmaInfo);
|
||||||
|
taosMemoryFree(pReadHandle);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param->qmsg2) {
|
||||||
|
pRSmaInfo->taskInfo[1] = qCreateStreamExecTaskInfo(param->qmsg2, &handle);
|
||||||
|
if (!pRSmaInfo->taskInfo[1]) {
|
||||||
|
taosMemoryFree(pRSmaInfo);
|
||||||
|
taosMemoryFree(pReadHandle);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosHashPut(SMA_STAT_INFO_HASH(pStat), &pReq->stbCfg.suid, sizeof(tb_uid_t), &pRSmaInfo, sizeof(pRSmaInfo)) !=
|
||||||
|
TSDB_CODE_SUCCESS) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
} else {
|
||||||
|
tsdbDebug("vgId:%d register rsma info succeed for suid:%" PRIi64, REPO_ID(pTsdb), pReq->stbCfg.suid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief store suid/[uids], prefer to use array and then hash
|
||||||
|
*
|
||||||
|
* @param pStore
|
||||||
|
* @param suid
|
||||||
|
* @param uid
|
||||||
|
* @return int32_t
|
||||||
|
*/
|
||||||
|
int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid) {
|
||||||
|
// prefer to store suid/uids in array
|
||||||
|
if ((suid == pStore->suid) || (pStore->suid == 0)) {
|
||||||
|
if (pStore->suid == 0) {
|
||||||
|
pStore->suid = suid;
|
||||||
|
}
|
||||||
|
if (uid) {
|
||||||
|
if (!pStore->tbUids) {
|
||||||
|
if (!(pStore->tbUids = taosArrayInit(1, sizeof(tb_uid_t)))) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!taosArrayPush(pStore->tbUids, &uid)) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// store other suid/uids in hash when multiple stable/table included in 1 batch of request
|
||||||
|
if (!pStore->uidHash) {
|
||||||
|
pStore->uidHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||||
|
if (!pStore->uidHash) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (uid) {
|
||||||
|
SArray *uidArray = taosHashGet(pStore->uidHash, &suid, sizeof(tb_uid_t));
|
||||||
|
if (uidArray && ((uidArray = *(SArray **)uidArray))) {
|
||||||
|
taosArrayPush(uidArray, &uid);
|
||||||
|
} else {
|
||||||
|
SArray *pUidArray = taosArrayInit(1, sizeof(tb_uid_t));
|
||||||
|
if (!pUidArray) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
if (!taosArrayPush(pUidArray, &uid)) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), &pUidArray, sizeof(pUidArray)) != 0) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (taosHashPut(pStore->uidHash, &suid, sizeof(suid), NULL, 0) != 0) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tsdbUidStoreDestory(STbUidStore *pStore) {
|
||||||
|
if (pStore) {
|
||||||
|
if (pStore->uidHash) {
|
||||||
|
if (pStore->tbUids) {
|
||||||
|
void *pIter = taosHashIterate(pStore->uidHash, NULL);
|
||||||
|
while (pIter) {
|
||||||
|
SArray *arr = *(SArray **)pIter;
|
||||||
|
taosArrayDestroy(arr);
|
||||||
|
pIter = taosHashIterate(pStore->uidHash, pIter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taosHashCleanup(pStore->uidHash);
|
||||||
|
}
|
||||||
|
taosArrayDestroy(pStore->tbUids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *tsdbUidStoreFree(STbUidStore *pStore) {
|
||||||
|
tsdbUidStoreDestory(pStore);
|
||||||
|
taosMemoryFree(pStore);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief fetch suid/uids when create child tables of rollup SMA
|
||||||
|
*
|
||||||
|
* @param pTsdb
|
||||||
|
* @param ppStore
|
||||||
|
* @param suid
|
||||||
|
* @param uid
|
||||||
|
* @return int32_t
|
||||||
|
*/
|
||||||
|
int32_t tsdbFetchTbUidList(void *pTsdb, void **ppStore, void *suid, void *uid) {
|
||||||
|
SSmaEnv *pEnv = REPO_RSMA_ENV((STsdb *)pTsdb);
|
||||||
|
|
||||||
|
// only applicable to rollup SMA ctables
|
||||||
|
if (!pEnv) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||||
|
SHashObj *infoHash = NULL;
|
||||||
|
if (!pStat || !(infoHash = SMA_STAT_INFO_HASH(pStat))) {
|
||||||
|
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// info cached when create rsma stable and return directly for non-rsma ctables
|
||||||
|
if (!taosHashGet(infoHash, suid, sizeof(tb_uid_t))) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(*ppStore)) {
|
||||||
|
if (tsdbUidStoreInit((STbUidStore **)ppStore) != 0) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tsdbUidStorePut(*ppStore, *(tb_uid_t *)suid, (tb_uid_t *)uid) != 0) {
|
||||||
|
*ppStore = tsdbUidStoreFree(*ppStore);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE int32_t tsdbUpdateTbUidListImpl(STsdb *pTsdb, tb_uid_t *suid, SArray *tbUids) {
|
||||||
|
SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb);
|
||||||
|
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||||
|
SRSmaInfo *pRSmaInfo = NULL;
|
||||||
|
|
||||||
|
if (!suid || !tbUids) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PTR;
|
||||||
|
tsdbError("vgId:%d failed to get rsma info for uid:%" PRIi64 " since %s", REPO_ID(pTsdb), *suid, terrstr(terrno));
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), suid, sizeof(tb_uid_t));
|
||||||
|
if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) {
|
||||||
|
tsdbError("vgId:%d failed to get rsma info for uid:%" PRIi64, REPO_ID(pTsdb), *suid);
|
||||||
|
terrno = TSDB_CODE_TDB_INVALID_SMA_STAT;
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pRSmaInfo->taskInfo[0] && (qUpdateQualifiedTableId(pRSmaInfo->taskInfo[0], tbUids, true) != 0)) {
|
||||||
|
tsdbError("vgId:%d update tbUidList failed for uid:%" PRIi64 " since %s", REPO_ID(pTsdb), *suid, terrstr(terrno));
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
} else {
|
||||||
|
tsdbDebug("vgId:%d update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, REPO_ID(pTsdb),
|
||||||
|
pRSmaInfo->taskInfo[0], *suid, *(int64_t *)taosArrayGet(tbUids, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pRSmaInfo->taskInfo[1] && (qUpdateQualifiedTableId(pRSmaInfo->taskInfo[1], tbUids, true) != 0)) {
|
||||||
|
tsdbError("vgId:%d update tbUidList failed for uid:%" PRIi64 " since %s", REPO_ID(pTsdb), *suid, terrstr(terrno));
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
} else {
|
||||||
|
tsdbDebug("vgId:%d update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 ", uid:%" PRIi64, REPO_ID(pTsdb),
|
||||||
|
pRSmaInfo->taskInfo[1], *suid, *(int64_t *)taosArrayGet(tbUids, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsdbUpdateTbUidList(STsdb *pTsdb, STbUidStore *pStore) {
|
||||||
|
if (!pStore || (taosArrayGetSize(pStore->tbUids) == 0)) {
|
||||||
|
tsdbDebug("vgId:%d no need to update tbUids since empty uidStore", REPO_ID(pTsdb));
|
||||||
|
tsdbUidStoreFree(pStore);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tsdbUpdateTbUidListImpl(pTsdb, &pStore->suid, pStore->tbUids) != TSDB_CODE_SUCCESS) {
|
||||||
|
tsdbUidStoreFree(pStore);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *pIter = taosHashIterate(pStore->uidHash, NULL);
|
||||||
|
while (pIter) {
|
||||||
|
tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL);
|
||||||
|
SArray *pTbUids = *(SArray **)pIter;
|
||||||
|
|
||||||
|
if (tsdbUpdateTbUidListImpl(pTsdb, pTbSuid, pTbUids) != TSDB_CODE_SUCCESS) {
|
||||||
|
taosHashCancelIterate(pStore->uidHash, pIter);
|
||||||
|
tsdbUidStoreFree(pStore);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
pIter = taosHashIterate(pStore->uidHash, pIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
tsdbUidStoreFree(pStore);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tsdbFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) {
|
||||||
|
ASSERT(pMsg != NULL);
|
||||||
|
SSubmitMsgIter msgIter = {0};
|
||||||
|
SSubmitBlk *pBlock = NULL;
|
||||||
|
SSubmitBlkIter blkIter = {0};
|
||||||
|
STSRow *row = NULL;
|
||||||
|
|
||||||
|
terrno = TSDB_CODE_SUCCESS;
|
||||||
|
// pMsg->length = htonl(pMsg->length);
|
||||||
|
// pMsg->numOfBlocks = htonl(pMsg->numOfBlocks);
|
||||||
|
|
||||||
|
if (tInitSubmitMsgIter(pMsg, &msgIter) < 0) return -1;
|
||||||
|
while (true) {
|
||||||
|
if (tGetSubmitMsgNext(&msgIter, &pBlock) < 0) return -1;
|
||||||
|
|
||||||
|
if (!pBlock) break;
|
||||||
|
tsdbUidStorePut(pStore, pBlock->suid, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (terrno != TSDB_CODE_SUCCESS) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsdbExecuteRSma(STsdb *pTsdb, SMeta *pMeta, const void *pMsg, int32_t inputType, tb_uid_t *suid) {
|
||||||
|
SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb);
|
||||||
|
if (!pEnv) {
|
||||||
|
// only applicable when rsma env exists
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||||
|
SRSmaInfo *pRSmaInfo = NULL;
|
||||||
|
|
||||||
|
pRSmaInfo = taosHashGet(SMA_STAT_INFO_HASH(pStat), suid, sizeof(tb_uid_t));
|
||||||
|
|
||||||
|
if (!pRSmaInfo || !(pRSmaInfo = *(SRSmaInfo **)pRSmaInfo)) {
|
||||||
|
tsdbDebug("vgId:%d no rsma info for suid:%" PRIu64, REPO_ID(pTsdb), *suid);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
SArray *pResult = NULL;
|
||||||
|
|
||||||
|
pResult = taosArrayInit(0, sizeof(SSDataBlock));
|
||||||
|
if (!pResult) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK) {
|
||||||
|
if (pRSmaInfo->taskInfo[0]) {
|
||||||
|
qSetStreamInput(pRSmaInfo->taskInfo[0], pMsg, inputType);
|
||||||
|
while (1) {
|
||||||
|
SSDataBlock *output;
|
||||||
|
uint64_t ts;
|
||||||
|
if (qExecTask(pRSmaInfo->taskInfo[0], &output, &ts) < 0) {
|
||||||
|
ASSERT(false);
|
||||||
|
}
|
||||||
|
if (!output) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
taosArrayPush(pResult, output);
|
||||||
|
}
|
||||||
|
blockDebugShowData(pResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (pRSmaInfo->taskInfo[1]) {
|
||||||
|
// qSetStreamInput(pRSmaInfo->taskInfo[1], pMsg, inputType);
|
||||||
|
// while (1) {
|
||||||
|
// SSDataBlock *output;
|
||||||
|
// uint64_t ts;
|
||||||
|
// if (qExecTask(pRSmaInfo->taskInfo[1], &output, &ts) < 0) {
|
||||||
|
// ASSERT(false);
|
||||||
|
// }
|
||||||
|
// if (!output) {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// taosArrayPush(pResult, output);
|
||||||
|
// }
|
||||||
|
// blockDebugShowData(pResult);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsdbTriggerRSma(STsdb *pTsdb, SMeta *pMeta, void *pMsg, int32_t inputType) {
|
||||||
|
SSmaEnv *pEnv = REPO_RSMA_ENV(pTsdb);
|
||||||
|
if (!pEnv) {
|
||||||
|
// only applicable when rsma env exists
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK) {
|
||||||
|
STbUidStore uidStore = {0};
|
||||||
|
tsdbFetchSubmitReqSuids(pMsg, &uidStore);
|
||||||
|
|
||||||
|
if (uidStore.suid != 0) {
|
||||||
|
tsdbExecuteRSma(pTsdb, pMeta, pMsg, inputType, &uidStore.suid);
|
||||||
|
|
||||||
|
void *pIter = taosHashIterate(uidStore.uidHash, NULL);
|
||||||
|
while (pIter) {
|
||||||
|
tb_uid_t *pTbSuid = (tb_uid_t *)taosHashGetKey(pIter, NULL);
|
||||||
|
tsdbExecuteRSma(pTsdb, pMeta, pMsg, inputType, pTbSuid);
|
||||||
|
pIter = taosHashIterate(uidStore.uidHash, pIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
tsdbUidStoreDestory(&uidStore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/**
|
/**
|
||||||
* @brief Get the start TS key of the last data block of one interval/sliding.
|
* @brief Get the start TS key of the last data block of one interval/sliding.
|
||||||
|
@ -1674,6 +2118,7 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg) {
|
||||||
if ((code = tsdbInsertTSmaDataImpl(pTsdb, indexUid, msg)) < 0) {
|
if ((code = tsdbInsertTSmaDataImpl(pTsdb, indexUid, msg)) < 0) {
|
||||||
tsdbWarn("vgId:%d insert tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
tsdbWarn("vgId:%d insert tSma data failed since %s", REPO_ID(pTsdb), tstrerror(terrno));
|
||||||
}
|
}
|
||||||
|
// TODO: destroy SSDataBlocks(msg)
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
|
||||||
case TDMT_VND_SUBMIT:
|
case TDMT_VND_SUBMIT:
|
||||||
pRsp->msgType = TDMT_VND_SUBMIT_RSP;
|
pRsp->msgType = TDMT_VND_SUBMIT_RSP;
|
||||||
vnodeProcessSubmitReq(pVnode, ptr, pRsp);
|
vnodeProcessSubmitReq(pVnode, ptr, pRsp);
|
||||||
|
tsdbTriggerRSma(pVnode->pTsdb, pVnode->pMeta, ptr, STREAM_DATA_TYPE_SUBMIT_BLOCK);
|
||||||
break;
|
break;
|
||||||
case TDMT_VND_MQ_VG_CHANGE:
|
case TDMT_VND_MQ_VG_CHANGE:
|
||||||
if (tqProcessVgChangeReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
if (tqProcessVgChangeReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
||||||
|
@ -101,7 +102,6 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case TDMT_VND_CREATE_SMA: { // timeRangeSMA
|
case TDMT_VND_CREATE_SMA: { // timeRangeSMA
|
||||||
|
|
||||||
if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) {
|
if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
@ -277,19 +277,12 @@ int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq) {
|
static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq) {
|
||||||
SVCreateTbReq vCreateTbReq = {0};
|
SVCreateTbReq vCreateTbReq = {0};
|
||||||
tDeserializeSVCreateTbReq(pReq, &vCreateTbReq);
|
tDeserializeSVCreateTbReq(pReq, &vCreateTbReq);
|
||||||
if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) {
|
if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq), NULL) < 0) {
|
||||||
// TODO
|
// TODO
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove the debug log
|
tsdbRegisterRSma(pVnode->pTsdb, pVnode->pMeta, &vCreateTbReq);
|
||||||
SRSmaParam *param = vCreateTbReq.stbCfg.pRSmaParam;
|
|
||||||
if (param) {
|
|
||||||
printf("qmsg1 len = %d, body = %s\n", param->qmsg1 ? (int32_t)strlen(param->qmsg1) : 0,
|
|
||||||
param->qmsg1 ? param->qmsg1 : "");
|
|
||||||
printf("qmsg1 len = %d, body = %s\n", param->qmsg2 ? (int32_t)strlen(param->qmsg2) : 0,
|
|
||||||
param->qmsg2 ? param->qmsg2 : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
taosMemoryFree(vCreateTbReq.stbCfg.pSchema);
|
taosMemoryFree(vCreateTbReq.stbCfg.pSchema);
|
||||||
taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema);
|
taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema);
|
||||||
|
@ -309,6 +302,13 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
||||||
SVCreateTbBatchRsp vCreateTbBatchRsp = {0};
|
SVCreateTbBatchRsp vCreateTbBatchRsp = {0};
|
||||||
tDeserializeSVCreateTbBatchReq(pReq, &vCreateTbBatchReq);
|
tDeserializeSVCreateTbBatchReq(pReq, &vCreateTbBatchReq);
|
||||||
int reqNum = taosArrayGetSize(vCreateTbBatchReq.pArray);
|
int reqNum = taosArrayGetSize(vCreateTbBatchReq.pArray);
|
||||||
|
|
||||||
|
STbDdlH ddlHandle = {
|
||||||
|
.ahandle = pVnode->pTsdb,
|
||||||
|
.result = NULL,
|
||||||
|
.fp = tsdbFetchTbUidList,
|
||||||
|
};
|
||||||
|
|
||||||
for (int i = 0; i < reqNum; i++) {
|
for (int i = 0; i < reqNum; i++) {
|
||||||
SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i);
|
SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i);
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
||||||
taosArrayPush(vCreateTbBatchRsp.rspList, &rsp);
|
taosArrayPush(vCreateTbBatchRsp.rspList, &rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) {
|
if (metaCreateTable(pVnode->pMeta, pCreateTbReq, &ddlHandle) < 0) {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
vError("vgId:%d, failed to create table: %s", TD_VID(pVnode), pCreateTbReq->name);
|
vError("vgId:%d, failed to create table: %s", TD_VID(pVnode), pCreateTbReq->name);
|
||||||
}
|
}
|
||||||
|
@ -348,6 +348,8 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tsdbUpdateTbUidList(pVnode->pTsdb, ddlHandle.result);
|
||||||
|
|
||||||
vTrace("vgId:%d process create %" PRIzu " tables", TD_VID(pVnode), taosArrayGetSize(vCreateTbBatchReq.pArray));
|
vTrace("vgId:%d process create %" PRIzu " tables", TD_VID(pVnode), taosArrayGetSize(vCreateTbBatchReq.pArray));
|
||||||
taosArrayDestroy(vCreateTbBatchReq.pArray);
|
taosArrayDestroy(vCreateTbBatchReq.pArray);
|
||||||
if (vCreateTbBatchRsp.rspList) {
|
if (vCreateTbBatchRsp.rspList) {
|
||||||
|
|
|
@ -407,7 +407,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPECT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS);
|
// EXPECT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS);
|
||||||
|
|
||||||
EXPECT_EQ(tsdbUpdateSmaWindow(pTsdb, pMsg, 0), 0);
|
EXPECT_EQ(tsdbUpdateSmaWindow(pTsdb, pMsg, 0), 0);
|
||||||
|
|
||||||
|
|
|
@ -399,8 +399,8 @@ typedef struct SOptrBasicInfo {
|
||||||
// TODO move the resultrowsiz together with SOptrBasicInfo:rowCellInfoOffset
|
// 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
|
||||||
SDiskbasedBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
SDiskbasedBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
||||||
int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row
|
int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row
|
||||||
|
|
|
@ -268,7 +268,6 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) {
|
||||||
int32_t numOfCols = LIST_LENGTH(pNode->pSlots);
|
int32_t numOfCols = LIST_LENGTH(pNode->pSlots);
|
||||||
|
|
||||||
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||||
pBlock->info.numOfCols = numOfCols;
|
|
||||||
pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData));
|
pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData));
|
||||||
|
|
||||||
pBlock->info.blockId = pNode->dataBlockId;
|
pBlock->info.blockId = pNode->dataBlockId;
|
||||||
|
@ -294,6 +293,7 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) {
|
||||||
taosArrayPush(pBlock->pDataBlock, &idata);
|
taosArrayPush(pBlock->pDataBlock, &idata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pBlock->info.numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
||||||
return pBlock;
|
return pBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,11 +324,16 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, jmp_buf env)
|
||||||
newCapacity = (int64_t)(pResultRowInfo->capacity * 1.5);
|
newCapacity = (int64_t)(pResultRowInfo->capacity * 1.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newCapacity == pResultRowInfo->capacity) {
|
if (newCapacity <= pResultRowInfo->capacity) {
|
||||||
newCapacity += 4;
|
newCapacity += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
pResultRowInfo->pPosition = taosMemoryRealloc(pResultRowInfo->pPosition, newCapacity * sizeof(SResultRowPosition));
|
char* p = taosMemoryRealloc(pResultRowInfo->pPosition, newCapacity * sizeof(SResultRowPosition));
|
||||||
|
if (p == NULL) {
|
||||||
|
longjmp(env, TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
pResultRowInfo->pPosition = (SResultRowPosition*)p;
|
||||||
|
|
||||||
int32_t inc = (int32_t)newCapacity - pResultRowInfo->capacity;
|
int32_t inc = (int32_t)newCapacity - pResultRowInfo->capacity;
|
||||||
memset(&pResultRowInfo->pPosition[pResultRowInfo->capacity], 0, sizeof(SResultRowPosition) * inc);
|
memset(&pResultRowInfo->pPosition[pResultRowInfo->capacity], 0, sizeof(SResultRowPosition) * inc);
|
||||||
|
@ -419,88 +424,56 @@ SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId,
|
||||||
* | 8 bytes | actual length |
|
* | 8 bytes | actual length |
|
||||||
* +----------+---------------+
|
* +----------+---------------+
|
||||||
*/
|
*/
|
||||||
static SResultRow* doSetResultOutBufByKey_rv(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, int64_t uid,
|
static SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, int64_t uid,
|
||||||
char* pData, int16_t bytes, bool masterscan, uint64_t groupId,
|
char* pData, int16_t bytes, bool masterscan, uint64_t groupId,
|
||||||
SExecTaskInfo* pTaskInfo, bool isIntervalQuery, SAggSupporter* pSup) {
|
SExecTaskInfo* pTaskInfo, bool isIntervalQuery, SAggSupporter* pSup) {
|
||||||
bool existInCurrentResusltRowInfo = false;
|
|
||||||
SET_RES_WINDOW_KEY(pSup->keyBuf, pData, bytes, groupId);
|
SET_RES_WINDOW_KEY(pSup->keyBuf, pData, bytes, groupId);
|
||||||
|
|
||||||
SResultRowPosition* p1 =
|
SResultRowPosition* p1 =
|
||||||
(SResultRowPosition*)taosHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
|
(SResultRowPosition*)taosHashGet(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes));
|
||||||
|
|
||||||
|
SResultRow* pResult = NULL;
|
||||||
|
|
||||||
// in case of repeat scan/reverse scan, no new time window added.
|
// in case of repeat scan/reverse scan, no new time window added.
|
||||||
if (isIntervalQuery) {
|
if (isIntervalQuery) {
|
||||||
if (!masterscan) { // the *p1 may be NULL in case of sliding+offset exists.
|
if (masterscan && p1 != NULL) { // the *p1 may be NULL in case of sliding+offset exists.
|
||||||
if (p1 != NULL) {
|
pResult = getResultRowByPos(pResultBuf, p1);
|
||||||
return getResultRowByPos(pResultBuf, p1);
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p1 != NULL) {
|
|
||||||
if (pResultRowInfo->size == 0) {
|
|
||||||
existInCurrentResusltRowInfo =
|
|
||||||
false; // this time window created by other timestamp that does not belongs to current table.
|
|
||||||
} else if (pResultRowInfo->size == 1) {
|
|
||||||
SResultRowPosition* p = &pResultRowInfo->pPosition[0];
|
|
||||||
existInCurrentResusltRowInfo = (p->pageId == p1->pageId && p->offset == p1->offset);
|
|
||||||
} else { // check if current pResultRowInfo contains the existInCurrentResusltRowInfo pResultRow
|
|
||||||
SET_RES_EXT_WINDOW_KEY(pSup->keyBuf, pData, bytes, uid, pResultRowInfo);
|
|
||||||
int64_t* index = taosHashGet(pSup->pResultRowListSet, pSup->keyBuf, GET_RES_EXT_WINDOW_KEY_LEN(bytes));
|
|
||||||
if (index != NULL) {
|
|
||||||
// TODO check the scan order for current opened time window
|
|
||||||
existInCurrentResusltRowInfo = true;
|
|
||||||
} else {
|
|
||||||
existInCurrentResusltRowInfo = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the
|
// In case of group by column query, the required SResultRow object must be existInCurrentResusltRowInfo in the
|
||||||
// pResultRowInfo object.
|
// pResultRowInfo object.
|
||||||
if (p1 != NULL) {
|
if (p1 != NULL) {
|
||||||
return getResultRowByPos(pResultBuf, p1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SResultRow* pResult = NULL;
|
|
||||||
if (!existInCurrentResusltRowInfo) {
|
|
||||||
// 1. close current opened time window
|
|
||||||
if (pResultRowInfo->cur.pageId != -1) { // todo extract function
|
|
||||||
SResultRowPosition pos = pResultRowInfo->cur;
|
|
||||||
SFilePage* pPage = getBufPage(pResultBuf, pos.pageId);
|
|
||||||
SResultRow* pRow = (SResultRow*)((char*)pPage + pos.offset);
|
|
||||||
closeResultRow(pRow);
|
|
||||||
releaseBufPage(pResultBuf, pPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
prepareResultListBuffer(pResultRowInfo, pTaskInfo->env);
|
|
||||||
if (p1 == NULL) {
|
|
||||||
pResult = getNewResultRow_rv(pResultBuf, groupId, pSup->resultRowSize);
|
|
||||||
initResultRow(pResult);
|
|
||||||
|
|
||||||
// add a new result set for a new group
|
|
||||||
SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
|
|
||||||
taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos,
|
|
||||||
sizeof(SResultRowPosition));
|
|
||||||
SResultRowCell cell = {.groupId = groupId, .pos = pos};
|
|
||||||
taosArrayPush(pSup->pResultRowArrayList, &cell);
|
|
||||||
} else {
|
|
||||||
pResult = getResultRowByPos(pResultBuf, p1);
|
pResult = getResultRowByPos(pResultBuf, p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. set the new time window to be the new active time window
|
|
||||||
pResultRowInfo->pPosition[pResultRowInfo->size++] =
|
|
||||||
(SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
|
|
||||||
pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
|
|
||||||
SET_RES_EXT_WINDOW_KEY(pSup->keyBuf, pData, bytes, uid, pResultRowInfo);
|
|
||||||
taosHashPut(pSup->pResultRowListSet, pSup->keyBuf, GET_RES_EXT_WINDOW_KEY_LEN(bytes), &pResultRowInfo->cur,
|
|
||||||
POINTER_BYTES);
|
|
||||||
} else {
|
|
||||||
pResult = getResultRowByPos(pResultBuf, p1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1. close current opened time window
|
||||||
|
if (pResultRowInfo->cur.pageId != -1 && ((pResult == NULL) || (pResult->pageId != pResultRowInfo->cur.pageId &&
|
||||||
|
pResult->offset != pResultRowInfo->cur.offset))) {
|
||||||
|
// todo extract function
|
||||||
|
SResultRowPosition pos = pResultRowInfo->cur;
|
||||||
|
SFilePage* pPage = getBufPage(pResultBuf, pos.pageId);
|
||||||
|
SResultRow* pRow = (SResultRow*)((char*)pPage + pos.offset);
|
||||||
|
closeResultRow(pRow);
|
||||||
|
releaseBufPage(pResultBuf, pPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// allocate a new buffer page
|
||||||
|
prepareResultListBuffer(pResultRowInfo, pTaskInfo->env);
|
||||||
|
if (pResult == NULL) {
|
||||||
|
pResult = getNewResultRow_rv(pResultBuf, groupId, pSup->resultRowSize);
|
||||||
|
initResultRow(pResult);
|
||||||
|
|
||||||
|
// add a new result set for a new group
|
||||||
|
SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
|
||||||
|
taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos, sizeof(SResultRowPosition));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. set the new time window to be the new active time window
|
||||||
|
pResultRowInfo->pPosition[pResultRowInfo->size++] =
|
||||||
|
(SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
|
||||||
|
pResultRowInfo->cur = (SResultRowPosition){.pageId = pResult->pageId, .offset = pResult->offset};
|
||||||
|
|
||||||
// too many time window in query
|
// too many time window in query
|
||||||
if (pResultRowInfo->size > MAX_INTERVAL_TIME_WINDOW) {
|
if (pResultRowInfo->size > MAX_INTERVAL_TIME_WINDOW) {
|
||||||
longjmp(pTaskInfo->env, TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW);
|
longjmp(pTaskInfo->env, TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW);
|
||||||
|
@ -656,7 +629,7 @@ static int32_t setResultOutputBufByKey_rv(SResultRowInfo* pResultRowInfo, int64_
|
||||||
int32_t numOfOutput, int32_t* rowCellInfoOffset, SAggSupporter* pAggSup,
|
int32_t numOfOutput, int32_t* rowCellInfoOffset, SAggSupporter* pAggSup,
|
||||||
SExecTaskInfo* pTaskInfo) {
|
SExecTaskInfo* pTaskInfo) {
|
||||||
assert(win->skey <= win->ekey);
|
assert(win->skey <= win->ekey);
|
||||||
SResultRow* pResultRow = doSetResultOutBufByKey_rv(pAggSup->pResultBuf, pResultRowInfo, id, (char*)&win->skey,
|
SResultRow* pResultRow = doSetResultOutBufByKey(pAggSup->pResultBuf, pResultRowInfo, id, (char*)&win->skey,
|
||||||
TSDB_KEYSIZE, masterscan, tableGroupId, pTaskInfo, true, pAggSup);
|
TSDB_KEYSIZE, masterscan, tableGroupId, pTaskInfo, true, pAggSup);
|
||||||
|
|
||||||
if (pResultRow == NULL) {
|
if (pResultRow == NULL) {
|
||||||
|
@ -1059,6 +1032,8 @@ static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunc
|
||||||
pColInfo->info.bytes = tDataTypes[type].bytes;
|
pColInfo->info.bytes = tDataTypes[type].bytes;
|
||||||
|
|
||||||
pInput->pData[paramIndex] = pColInfo;
|
pInput->pData[paramIndex] = pColInfo;
|
||||||
|
} else {
|
||||||
|
pColInfo = pInput->pData[paramIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(!IS_VAR_DATA_TYPE(type));
|
ASSERT(!IS_VAR_DATA_TYPE(type));
|
||||||
|
@ -1091,6 +1066,7 @@ static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCt
|
||||||
|
|
||||||
SInputColumnInfoData* pInput = &pCtx[i].input;
|
SInputColumnInfoData* pInput = &pCtx[i].input;
|
||||||
pInput->uid = pBlock->info.uid;
|
pInput->uid = pBlock->info.uid;
|
||||||
|
pInput->colDataAggIsSet = false;
|
||||||
|
|
||||||
SExprInfo* pOneExpr = &pOperator->pExpr[i];
|
SExprInfo* pOneExpr = &pOperator->pExpr[i];
|
||||||
for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
|
for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
|
||||||
|
@ -1707,7 +1683,7 @@ int32_t setGroupResultOutputBuf(SOptrBasicInfo* binfo, int32_t numOfCols, char*
|
||||||
SResultRowInfo* pResultRowInfo = &binfo->resultRowInfo;
|
SResultRowInfo* pResultRowInfo = &binfo->resultRowInfo;
|
||||||
SqlFunctionCtx* pCtx = binfo->pCtx;
|
SqlFunctionCtx* pCtx = binfo->pCtx;
|
||||||
|
|
||||||
SResultRow* pResultRow = doSetResultOutBufByKey_rv(pBuf, pResultRowInfo, groupId, (char*)pData, bytes, true, groupId,
|
SResultRow* pResultRow = doSetResultOutBufByKey(pBuf, pResultRowInfo, groupId, (char*)pData, bytes, true, groupId,
|
||||||
pTaskInfo, false, pAggSup);
|
pTaskInfo, false, pAggSup);
|
||||||
assert(pResultRow != NULL);
|
assert(pResultRow != NULL);
|
||||||
|
|
||||||
|
@ -2713,7 +2689,7 @@ void setFunctionResultOutput(SOptrBasicInfo* pInfo, SAggSupporter* pSup, int32_t
|
||||||
|
|
||||||
int64_t tid = 0;
|
int64_t tid = 0;
|
||||||
int64_t groupId = 0;
|
int64_t groupId = 0;
|
||||||
SResultRow* pRow = doSetResultOutBufByKey_rv(pSup->pResultBuf, pResultRowInfo, tid, (char*)&tid, sizeof(tid), true,
|
SResultRow* pRow = doSetResultOutBufByKey(pSup->pResultBuf, pResultRowInfo, tid, (char*)&tid, sizeof(tid), true,
|
||||||
groupId, pTaskInfo, false, pSup);
|
groupId, pTaskInfo, false, pSup);
|
||||||
|
|
||||||
for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) {
|
for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) {
|
||||||
|
@ -3001,7 +2977,7 @@ void doSetTableGroupOutputBuf(SAggOperatorInfo* pAggInfo, int32_t numOfOutput, u
|
||||||
int32_t* rowCellInfoOffset = pAggInfo->binfo.rowCellInfoOffset;
|
int32_t* rowCellInfoOffset = pAggInfo->binfo.rowCellInfoOffset;
|
||||||
|
|
||||||
SResultRow* pResultRow =
|
SResultRow* pResultRow =
|
||||||
doSetResultOutBufByKey_rv(pAggInfo->aggSup.pResultBuf, pResultRowInfo, uid, (char*)&groupId, sizeof(groupId),
|
doSetResultOutBufByKey(pAggInfo->aggSup.pResultBuf, pResultRowInfo, uid, (char*)&groupId, sizeof(groupId),
|
||||||
true, groupId, pTaskInfo, false, &pAggInfo->aggSup);
|
true, groupId, pTaskInfo, false, &pAggInfo->aggSup);
|
||||||
assert(pResultRow != NULL);
|
assert(pResultRow != NULL);
|
||||||
|
|
||||||
|
@ -3775,6 +3751,9 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(pColInfoData->pData, pStart, colLen[i]);
|
memcpy(pColInfoData->pData, pStart, colLen[i]);
|
||||||
|
//TODO setting this flag to true temporarily so aggregate function on stable will
|
||||||
|
//examine NULL value for non-primary key column
|
||||||
|
pColInfoData->hasNull = true;
|
||||||
pStart += colLen[i];
|
pStart += colLen[i];
|
||||||
}
|
}
|
||||||
} else { // extract data according to pColList
|
} else { // extract data according to pColList
|
||||||
|
@ -4895,8 +4874,8 @@ bool aggDecodeResultRow(SOperatorInfo* pOperator, SAggSupporter* pSup, SOptrBasi
|
||||||
initResultRow(resultRow);
|
initResultRow(resultRow);
|
||||||
prepareResultListBuffer(&pInfo->resultRowInfo, pOperator->pTaskInfo->env);
|
prepareResultListBuffer(&pInfo->resultRowInfo, pOperator->pTaskInfo->env);
|
||||||
// pInfo->resultRowInfo.cur = pInfo->resultRowInfo.size;
|
// pInfo->resultRowInfo.cur = pInfo->resultRowInfo.size;
|
||||||
pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] =
|
// pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] =
|
||||||
(SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset};
|
// (SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset};
|
||||||
pInfo->resultRowInfo.cur = (SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset};
|
pInfo->resultRowInfo.cur = (SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5609,10 +5588,10 @@ int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t n
|
||||||
pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
|
pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput);
|
||||||
pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
|
pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize + POINTER_BYTES + sizeof(int64_t));
|
||||||
pAggSup->pResultRowHashTable = taosHashInit(10, hashFn, true, HASH_NO_LOCK);
|
pAggSup->pResultRowHashTable = taosHashInit(10, hashFn, true, HASH_NO_LOCK);
|
||||||
pAggSup->pResultRowListSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK);
|
// pAggSup->pResultRowListSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK);
|
||||||
pAggSup->pResultRowArrayList = taosArrayInit(10, sizeof(SResultRowCell));
|
// pAggSup->pResultRowArrayList = taosArrayInit(10, sizeof(SResultRowCell));
|
||||||
|
|
||||||
if (pAggSup->keyBuf == NULL || pAggSup->pResultRowArrayList == NULL || pAggSup->pResultRowListSet == NULL ||
|
if (pAggSup->keyBuf == NULL /*|| pAggSup->pResultRowArrayList == NULL || pAggSup->pResultRowListSet == NULL*/ ||
|
||||||
pAggSup->pResultRowHashTable == NULL) {
|
pAggSup->pResultRowHashTable == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -5628,8 +5607,8 @@ int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t n
|
||||||
static void cleanupAggSup(SAggSupporter* pAggSup) {
|
static void cleanupAggSup(SAggSupporter* pAggSup) {
|
||||||
taosMemoryFreeClear(pAggSup->keyBuf);
|
taosMemoryFreeClear(pAggSup->keyBuf);
|
||||||
taosHashCleanup(pAggSup->pResultRowHashTable);
|
taosHashCleanup(pAggSup->pResultRowHashTable);
|
||||||
taosHashCleanup(pAggSup->pResultRowListSet);
|
// taosHashCleanup(pAggSup->pResultRowListSet);
|
||||||
taosArrayDestroy(pAggSup->pResultRowArrayList);
|
// taosArrayDestroy(pAggSup->pResultRowArrayList);
|
||||||
destroyDiskbasedBuf(pAggSup->pResultBuf);
|
destroyDiskbasedBuf(pAggSup->pResultBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6352,7 +6331,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
|
|
||||||
int32_t numOfCols = 0;
|
int32_t numOfCols = 0;
|
||||||
tsdbReaderT pDataReader = doCreateDataReader(pTableScanNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId);
|
tsdbReaderT pDataReader = doCreateDataReader(pTableScanNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId);
|
||||||
if (pDataReader == NULL) {
|
if (pDataReader == NULL && terrno != 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -355,7 +355,7 @@ static int32_t translateToIso8601(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
||||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
pFunc->node.resType = (SDataType) { .bytes = 24, .type = TSDB_DATA_TYPE_BINARY};
|
pFunc->node.resType = (SDataType) { .bytes = 64, .type = TSDB_DATA_TYPE_BINARY};
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -548,7 +548,7 @@ static int32_t udfdParseArgs(int32_t argc, char *argv[]) {
|
||||||
static int32_t udfdInitLog() {
|
static int32_t udfdInitLog() {
|
||||||
char logName[12] = {0};
|
char logName[12] = {0};
|
||||||
snprintf(logName, sizeof(logName), "%slog", "udfd");
|
snprintf(logName, sizeof(logName), "%slog", "udfd");
|
||||||
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, 0);
|
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) {
|
void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) {
|
||||||
|
@ -656,7 +656,7 @@ int main(int argc, char *argv[]) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosInitCfg(configDir, NULL, NULL, NULL, 0) != 0) {
|
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) {
|
||||||
fnError("failed to start since read config error");
|
fnError("failed to start since read config error");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,13 +31,13 @@ static int32_t parseArgs(int32_t argc, char *argv[]) {
|
||||||
static int32_t initLog() {
|
static int32_t initLog() {
|
||||||
char logName[12] = {0};
|
char logName[12] = {0};
|
||||||
snprintf(logName, sizeof(logName), "%slog", "udfc");
|
snprintf(logName, sizeof(logName), "%slog", "udfc");
|
||||||
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, 0);
|
return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
parseArgs(argc, argv);
|
parseArgs(argc, argv);
|
||||||
initLog();
|
initLog();
|
||||||
if (taosInitCfg(configDir, NULL, NULL, NULL, 0) != 0) {
|
if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) {
|
||||||
fnError("failed to start since read config error");
|
fnError("failed to start since read config error");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -489,7 +489,7 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
|
||||||
if (fmIsUserDefinedFunc(node->funcId)) {
|
if (fmIsUserDefinedFunc(node->funcId)) {
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
FOREACH(tnode, node->pParameterList) {
|
FOREACH(tnode, node->pParameterList) {
|
||||||
if (!SCL_IS_CONST_NODE(tnode)) {
|
if (!SCL_IS_CONST_NODE(tnode)) {
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
|
@ -517,8 +517,8 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
|
||||||
res->node.resType = node->node.resType;
|
res->node.resType = node->node.resType;
|
||||||
int32_t type = output.columnData->info.type;
|
int32_t type = output.columnData->info.type;
|
||||||
if (IS_VAR_DATA_TYPE(type)) {
|
if (IS_VAR_DATA_TYPE(type)) {
|
||||||
res->datum.p = output.columnData->pData;
|
res->datum.p = taosMemoryCalloc(res->node.resType.bytes + VARSTR_HEADER_SIZE + 1, 1);
|
||||||
output.columnData->pData = NULL;
|
memcpy(res->datum.p, output.columnData->pData, varDataTLen(output.columnData->pData));
|
||||||
} else {
|
} else {
|
||||||
memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes);
|
memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ target_link_libraries(
|
||||||
|
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
sync
|
sync
|
||||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/sync"
|
PUBLIC "${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -199,197 +199,197 @@ target_sources(syncApplyMsgTest
|
||||||
|
|
||||||
target_include_directories(syncTest
|
target_include_directories(syncTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncEnvTest
|
target_include_directories(syncEnvTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncPingTimerTest
|
target_include_directories(syncPingTimerTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncIOTickQTest
|
target_include_directories(syncIOTickQTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncIOTickPingTest
|
target_include_directories(syncIOTickPingTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncIOSendMsgTest
|
target_include_directories(syncIOSendMsgTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncIOClientTest
|
target_include_directories(syncIOClientTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncIOServerTest
|
target_include_directories(syncIOServerTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncRaftStoreTest
|
target_include_directories(syncRaftStoreTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncEnqTest
|
target_include_directories(syncEnqTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncIndexTest
|
target_include_directories(syncIndexTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncInitTest
|
target_include_directories(syncInitTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncUtilTest
|
target_include_directories(syncUtilTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncVotesGrantedTest
|
target_include_directories(syncVotesGrantedTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncVotesRespondTest
|
target_include_directories(syncVotesRespondTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncIndexMgrTest
|
target_include_directories(syncIndexMgrTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncLogStoreTest
|
target_include_directories(syncLogStoreTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncEntryTest
|
target_include_directories(syncEntryTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncRequestVoteTest
|
target_include_directories(syncRequestVoteTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncRequestVoteReplyTest
|
target_include_directories(syncRequestVoteReplyTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncAppendEntriesTest
|
target_include_directories(syncAppendEntriesTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncAppendEntriesReplyTest
|
target_include_directories(syncAppendEntriesReplyTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncClientRequestTest
|
target_include_directories(syncClientRequestTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncTimeoutTest
|
target_include_directories(syncTimeoutTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncPingTest
|
target_include_directories(syncPingTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncPingReplyTest
|
target_include_directories(syncPingReplyTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncRpcMsgTest
|
target_include_directories(syncRpcMsgTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncPingTimerTest2
|
target_include_directories(syncPingTimerTest2
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncPingSelfTest
|
target_include_directories(syncPingSelfTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncElectTest
|
target_include_directories(syncElectTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncEncodeTest
|
target_include_directories(syncEncodeTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncWriteTest
|
target_include_directories(syncWriteTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncReplicateTest
|
target_include_directories(syncReplicateTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncRefTest
|
target_include_directories(syncRefTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncLogStoreCheck
|
target_include_directories(syncLogStoreCheck
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncRaftCfgTest
|
target_include_directories(syncRaftCfgTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncRespMgrTest
|
target_include_directories(syncRespMgrTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncSnapshotTest
|
target_include_directories(syncSnapshotTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncApplyMsgTest
|
target_include_directories(syncApplyMsgTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
#include "tenv.h"
|
||||||
|
#include "cJSON.h"
|
||||||
|
#include "tjson.h"
|
||||||
|
|
||||||
#define CFG_NAME_PRINT_LEN 24
|
#define CFG_NAME_PRINT_LEN 24
|
||||||
#define CFG_SRC_PRINT_LEN 12
|
#define CFG_SRC_PRINT_LEN 12
|
||||||
|
@ -25,6 +28,7 @@
|
||||||
int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath);
|
int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath);
|
||||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath);
|
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath);
|
||||||
int32_t cfgLoadFromEnvVar(SConfig *pConfig);
|
int32_t cfgLoadFromEnvVar(SConfig *pConfig);
|
||||||
|
int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd);
|
||||||
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url);
|
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url);
|
||||||
int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSrcType stype);
|
int32_t cfgSetItem(SConfig *pConfig, const char *name, const char *value, ECfgSrcType stype);
|
||||||
|
|
||||||
|
@ -45,7 +49,7 @@ SConfig *cfgInit() {
|
||||||
return pCfg;
|
return pCfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) {
|
int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const void *sourceStr) {
|
||||||
switch (cfgType) {
|
switch (cfgType) {
|
||||||
case CFG_STYPE_CFG_FILE:
|
case CFG_STYPE_CFG_FILE:
|
||||||
return cfgLoadFromCfgFile(pCfg, sourceStr);
|
return cfgLoadFromCfgFile(pCfg, sourceStr);
|
||||||
|
@ -55,6 +59,8 @@ int32_t cfgLoad(SConfig *pCfg, ECfgSrcType cfgType, const char *sourceStr) {
|
||||||
return cfgLoadFromEnvVar(pCfg);
|
return cfgLoadFromEnvVar(pCfg);
|
||||||
case CFG_STYPE_APOLLO_URL:
|
case CFG_STYPE_APOLLO_URL:
|
||||||
return cfgLoadFromApollUrl(pCfg, sourceStr);
|
return cfgLoadFromApollUrl(pCfg, sourceStr);
|
||||||
|
case CFG_STYPE_ENV_CMD:
|
||||||
|
return cfgLoadFromEnvCmd(pCfg, (const char **)sourceStr);
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -463,6 +469,8 @@ const char *cfgStypeStr(ECfgSrcType type) {
|
||||||
return "arg_list";
|
return "arg_list";
|
||||||
case CFG_STYPE_TAOS_OPTIONS:
|
case CFG_STYPE_TAOS_OPTIONS:
|
||||||
return "taos_options";
|
return "taos_options";
|
||||||
|
case CFG_STYPE_ENV_CMD:
|
||||||
|
return "env_cmd";
|
||||||
default:
|
default:
|
||||||
return "invalid";
|
return "invalid";
|
||||||
}
|
}
|
||||||
|
@ -584,12 +592,154 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
|
int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
|
||||||
uDebug("load from env variables not implemented yet");
|
char *line = NULL, *name, *value, *value2, *value3;
|
||||||
|
int32_t olen, vlen, vlen2, vlen3;
|
||||||
|
ssize_t _bytes = 0;
|
||||||
|
TdCmdPtr pCmd = taosOpenCmd("set");
|
||||||
|
if (pCmd == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
while (!taosEOFCmd(pCmd)) {
|
||||||
|
name = value = value2 = value3 = NULL;
|
||||||
|
olen = vlen = vlen2 = vlen3 = 0;
|
||||||
|
|
||||||
|
_bytes = taosGetLineCmd(pCmd, &line);
|
||||||
|
if (_bytes < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
|
||||||
|
taosEnvToCfg(line, line);
|
||||||
|
|
||||||
|
paGetToken(line, &name, &olen);
|
||||||
|
if (olen == 0) continue;
|
||||||
|
name[olen] = 0;
|
||||||
|
|
||||||
|
paGetToken(name + olen + 1, &value, &vlen);
|
||||||
|
if (vlen == 0) continue;
|
||||||
|
value[vlen] = 0;
|
||||||
|
|
||||||
|
paGetToken(value + vlen + 1, &value2, &vlen2);
|
||||||
|
if (vlen2 != 0) {
|
||||||
|
value2[vlen2] = 0;
|
||||||
|
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
|
||||||
|
if (vlen3 != 0) value3[vlen3] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_VAR);
|
||||||
|
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
|
||||||
|
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_VAR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
taosCloseCmd(&pCmd);
|
||||||
|
if (line != NULL) taosMemoryFreeClear(line);
|
||||||
|
|
||||||
|
uInfo("load from env variables cfg success");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) {
|
int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) {
|
||||||
uDebug("load from env file not implemented yet");
|
char *buf, *name, *value, *value2, *value3;
|
||||||
|
int32_t olen, vlen, vlen2, vlen3;
|
||||||
|
int32_t index = 0;
|
||||||
|
if (envCmd == NULL) return 0;
|
||||||
|
while (envCmd[index]!=NULL) {
|
||||||
|
buf = taosMemoryMalloc(strlen(envCmd[index]));
|
||||||
|
taosEnvToCfg(envCmd[index], buf);
|
||||||
|
index++;
|
||||||
|
|
||||||
|
name = value = value2 = value3 = NULL;
|
||||||
|
olen = vlen = vlen2 = vlen3 = 0;
|
||||||
|
|
||||||
|
paGetToken(buf, &name, &olen);
|
||||||
|
if (olen == 0) continue;
|
||||||
|
name[olen] = 0;
|
||||||
|
|
||||||
|
paGetToken(name + olen + 1, &value, &vlen);
|
||||||
|
if (vlen == 0) continue;
|
||||||
|
value[vlen] = 0;
|
||||||
|
|
||||||
|
paGetToken(value + vlen + 1, &value2, &vlen2);
|
||||||
|
if (vlen2 != 0) {
|
||||||
|
value2[vlen2] = 0;
|
||||||
|
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
|
||||||
|
if (vlen3 != 0) value3[vlen3] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_CMD);
|
||||||
|
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
|
||||||
|
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_CMD);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosMemoryFree(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
uInfo("load from env cmd cfg success");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
|
||||||
|
char *line = NULL, *name, *value, *value2, *value3;
|
||||||
|
int32_t olen, vlen, vlen2, vlen3;
|
||||||
|
ssize_t _bytes = 0;
|
||||||
|
|
||||||
|
const char *filepath = ".env";
|
||||||
|
if (envFile != NULL && strlen(envFile)>0) {
|
||||||
|
if (!taosCheckExistFile(envFile)) {
|
||||||
|
uError("fial to load env file: %s", envFile);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
filepath = envFile;
|
||||||
|
}else {
|
||||||
|
if (!taosCheckExistFile(filepath)) {
|
||||||
|
uInfo("fial to load env file: %s", filepath);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!taosEOFFile(pFile)) {
|
||||||
|
name = value = value2 = value3 = NULL;
|
||||||
|
olen = vlen = vlen2 = vlen3 = 0;
|
||||||
|
|
||||||
|
_bytes = taosGetLineFile(pFile, &line);
|
||||||
|
if (_bytes <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
|
||||||
|
taosEnvToCfg(line, line);
|
||||||
|
|
||||||
|
paGetToken(line, &name, &olen);
|
||||||
|
if (olen == 0) continue;
|
||||||
|
name[olen] = 0;
|
||||||
|
|
||||||
|
paGetToken(name + olen + 1, &value, &vlen);
|
||||||
|
if (vlen == 0) continue;
|
||||||
|
value[vlen] = 0;
|
||||||
|
|
||||||
|
paGetToken(value + vlen + 1, &value2, &vlen2);
|
||||||
|
if (vlen2 != 0) {
|
||||||
|
value2[vlen2] = 0;
|
||||||
|
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
|
||||||
|
if (vlen3 != 0) value3[vlen3] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cfgSetItem(pConfig, name, value, CFG_STYPE_ENV_FILE);
|
||||||
|
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
|
||||||
|
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_ENV_FILE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
if (line != NULL) taosMemoryFreeClear(line);
|
||||||
|
|
||||||
|
uInfo("load from env cfg file %s success", filepath);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,11 +767,11 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
||||||
olen = vlen = vlen2 = vlen3 = 0;
|
olen = vlen = vlen2 = vlen3 = 0;
|
||||||
|
|
||||||
_bytes = taosGetLineFile(pFile, &line);
|
_bytes = taosGetLineFile(pFile, &line);
|
||||||
if (_bytes < 0) {
|
if (_bytes <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
line[_bytes - 1] = 0;
|
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
|
||||||
|
|
||||||
paGetToken(line, &name, &olen);
|
paGetToken(line, &name, &olen);
|
||||||
if (olen == 0) continue;
|
if (olen == 0) continue;
|
||||||
|
@ -659,6 +809,192 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
||||||
uDebug("load from apoll url not implemented yet");
|
char *cfgLineBuf = NULL, *name, *value, *value2, *value3;
|
||||||
|
int32_t olen, vlen, vlen2, vlen3;
|
||||||
|
if (url == NULL || strlen(url) == 0) {
|
||||||
|
uInfo("fail to load apoll url");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *p = strchr(url, ':');
|
||||||
|
if (p == NULL) {
|
||||||
|
uError("fail to load apoll url: %s, unknown format", url);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
|
||||||
|
if (bcmp(url, "jsonFile", 8) == 0) {
|
||||||
|
char *filepath = p;
|
||||||
|
if (!taosCheckExistFile(filepath)) {
|
||||||
|
uError("fial to load json file: %s", filepath);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END);
|
||||||
|
char *buf = taosMemoryMalloc(fileSize);
|
||||||
|
taosLSeekFile(pFile, 0, SEEK_SET);
|
||||||
|
if(taosReadFile(pFile, buf, fileSize) <= 0) {
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
uError("load json file error: %s", filepath);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
SJson* pJson = tjsonParse(buf);
|
||||||
|
if (NULL == pJson) {
|
||||||
|
const char *jsonParseError = tjsonGetError();
|
||||||
|
if (jsonParseError != NULL) {
|
||||||
|
uError("load json file parse error: %s", jsonParseError);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
taosMemoryFreeClear(buf);
|
||||||
|
|
||||||
|
int32_t jsonArraySize = tjsonGetArraySize(pJson);
|
||||||
|
for(int32_t i = 0; i < jsonArraySize; i++) {
|
||||||
|
cJSON* item = tjsonGetArrayItem(pJson, i);
|
||||||
|
if (item == NULL) break;
|
||||||
|
char *itemName = NULL, *itemValueString = NULL;
|
||||||
|
tjsonGetObjectName(item, &itemName);
|
||||||
|
tjsonGetObjectName(item, &itemName);
|
||||||
|
tjsonGetObjectValueString(item, &itemValueString);
|
||||||
|
if (itemValueString != NULL && itemName != NULL) {
|
||||||
|
size_t itemNameLen = strlen(itemName);
|
||||||
|
size_t itemValueStringLen = strlen(itemValueString);
|
||||||
|
cfgLineBuf = taosMemoryMalloc(itemNameLen + itemValueStringLen + 2);
|
||||||
|
memcpy(cfgLineBuf, itemName, itemNameLen);
|
||||||
|
cfgLineBuf[itemNameLen] = ' ';
|
||||||
|
memcpy(&cfgLineBuf[itemNameLen+1], itemValueString, itemValueStringLen);
|
||||||
|
cfgLineBuf[itemNameLen + itemValueStringLen + 1] = '\0';
|
||||||
|
|
||||||
|
paGetToken(cfgLineBuf, &name, &olen);
|
||||||
|
if (olen == 0) continue;
|
||||||
|
name[olen] = 0;
|
||||||
|
|
||||||
|
paGetToken(name + olen + 1, &value, &vlen);
|
||||||
|
if (vlen == 0) continue;
|
||||||
|
value[vlen] = 0;
|
||||||
|
|
||||||
|
paGetToken(value + vlen + 1, &value2, &vlen2);
|
||||||
|
if (vlen2 != 0) {
|
||||||
|
value2[vlen2] = 0;
|
||||||
|
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
|
||||||
|
if (vlen3 != 0) value3[vlen3] = 0;
|
||||||
|
}
|
||||||
|
cfgSetItem(pConfig, name, value, CFG_STYPE_APOLLO_URL);
|
||||||
|
if (value2 != NULL && value3 != NULL && value2[0] != 0 && value3[0] != 0 && strcasecmp(name, "dataDir") == 0) {
|
||||||
|
cfgSetTfsItem(pConfig, name, value, value2, value3, CFG_STYPE_APOLLO_URL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tjsonDelete(pJson);
|
||||||
|
|
||||||
|
// } else if (bcmp(url, "jsonUrl", 7) == 0) {
|
||||||
|
// } else if (bcmp(url, "etcdUrl", 7) == 0) {
|
||||||
|
} else {
|
||||||
|
uError("Unsupported url: %s", url);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uInfo("load from apoll url not implemented yet");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char* apolloUrl) {
|
||||||
|
int32_t index = 0;
|
||||||
|
if (envCmd == NULL) return 0;
|
||||||
|
while (envCmd[index]!=NULL) {
|
||||||
|
if (bcmp(envCmd[index], "TAOS_APOLLO_URL", 14) == 0) {
|
||||||
|
char *p = strchr(envCmd[index], '=');
|
||||||
|
if (p != NULL) {
|
||||||
|
p++;
|
||||||
|
if (*p == '\'') {
|
||||||
|
p++;
|
||||||
|
p[strlen(p)-1] = '\0';
|
||||||
|
}
|
||||||
|
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
|
||||||
|
uInfo("get apollo url from env cmd success");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *line = NULL;
|
||||||
|
ssize_t _bytes = 0;
|
||||||
|
TdCmdPtr pCmd = taosOpenCmd("set");
|
||||||
|
if (pCmd != NULL) {
|
||||||
|
while (!taosEOFCmd(pCmd)) {
|
||||||
|
_bytes = taosGetLineCmd(pCmd, &line);
|
||||||
|
if (_bytes < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
|
||||||
|
if (bcmp(line, "TAOS_APOLLO_URL", 14) == 0) {
|
||||||
|
char *p = strchr(line, '=');
|
||||||
|
if (p != NULL) {
|
||||||
|
p++;
|
||||||
|
if (*p == '\'') {
|
||||||
|
p++;
|
||||||
|
p[strlen(p)-1] = '\0';
|
||||||
|
}
|
||||||
|
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
|
||||||
|
uInfo("get apollo url from env variables success, apolloUrl=%s",apolloUrl);
|
||||||
|
taosCloseCmd(&pCmd);
|
||||||
|
if (line != NULL) taosMemoryFreeClear(line);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taosCloseCmd(&pCmd);
|
||||||
|
if (line != NULL) taosMemoryFreeClear(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *filepath = ".env";
|
||||||
|
if (envFile != NULL && strlen(envFile)>0) {
|
||||||
|
if (!taosCheckExistFile(envFile)) {
|
||||||
|
uError("fial to load env file: %s", envFile);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
filepath = envFile;
|
||||||
|
}else {
|
||||||
|
if (!taosCheckExistFile(filepath)) {
|
||||||
|
uInfo("fial to load env file: %s", filepath);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
|
||||||
|
if (pFile != NULL) {
|
||||||
|
while (!taosEOFFile(pFile)) {
|
||||||
|
_bytes = taosGetLineFile(pFile, &line);
|
||||||
|
if (_bytes <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
|
||||||
|
if (bcmp(line, "TAOS_APOLLO_URL", 14) == 0) {
|
||||||
|
char *p = strchr(line, '=');
|
||||||
|
if (p != NULL) {
|
||||||
|
p++;
|
||||||
|
if (*p == '\'') {
|
||||||
|
p++;
|
||||||
|
p[strlen(p)-1] = '\0';
|
||||||
|
}
|
||||||
|
memcpy(apolloUrl, p, TMIN(strlen(p)+1,PATH_MAX));
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
if (line != NULL) taosMemoryFreeClear(line);
|
||||||
|
uInfo("get apollo url from env file success");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
if (line != NULL) taosMemoryFreeClear(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
uInfo("fail get apollo url from cmd env file");
|
||||||
|
return -1;
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "tenv.h"
|
||||||
|
#include "tconfig.h"
|
||||||
|
|
||||||
|
static char toLowChar(char c) { return (c > 'Z' || c < 'A' ? c : (c - 'A' + 'a')); }
|
||||||
|
|
||||||
|
int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t cfgNameMaxLen) {
|
||||||
|
if (envNameStr == NULL || cfgNameStr == NULL) return -1;
|
||||||
|
char *p = cfgNameStr;
|
||||||
|
if (envNameStr[0] != 'T' || envNameStr[1] != 'A' || envNameStr[2] != 'O' || envNameStr[3] != 'S' ||
|
||||||
|
envNameStr[4] != '_') {
|
||||||
|
// if(p != envNameStr) strncpy(p, envNameStr, cfgNameMaxLen - 1);
|
||||||
|
// p[cfgNameMaxLen - 1] = '\0';
|
||||||
|
// return strlen(cfgNameStr);
|
||||||
|
cfgNameStr[0] = '\0';
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
envNameStr += 5;
|
||||||
|
if (*envNameStr != '\0') {
|
||||||
|
*p = toLowChar(*envNameStr);
|
||||||
|
p++;
|
||||||
|
envNameStr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 1; i < cfgNameMaxLen && *envNameStr != '\0'; i++) {
|
||||||
|
if (*envNameStr == '_') {
|
||||||
|
envNameStr++;
|
||||||
|
*p = *envNameStr;
|
||||||
|
if (*envNameStr == '\0') break;
|
||||||
|
} else {
|
||||||
|
*p = toLowChar(*envNameStr);
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
envNameStr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*p = '\0';
|
||||||
|
return strlen(cfgNameStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t taosEnvToCfg(const char *envStr, char *cfgStr) {
|
||||||
|
if (envStr == NULL && cfgStr == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (cfgStr != envStr) strcpy(cfgStr, envStr);
|
||||||
|
char *p = strchr(cfgStr, '=');
|
||||||
|
|
||||||
|
if (p != NULL) {
|
||||||
|
char buf[CFG_NAME_MAX_LEN];
|
||||||
|
if (*(p+1) == '\'') {
|
||||||
|
*(p+1)= ' ';
|
||||||
|
char *pEnd = &cfgStr[strlen(cfgStr)-1];
|
||||||
|
if (*pEnd == '\'') *pEnd = '\0';
|
||||||
|
}
|
||||||
|
*p = '\0';
|
||||||
|
int32_t cfgNameLen = taosEnvNameToCfgName(cfgStr, buf, CFG_NAME_MAX_LEN);
|
||||||
|
if (cfgNameLen > 0) {
|
||||||
|
memcpy(cfgStr, buf, cfgNameLen);
|
||||||
|
memset(&cfgStr[cfgNameLen], ' ', p - cfgStr - cfgNameLen + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strlen(cfgStr);
|
||||||
|
}
|
|
@ -144,6 +144,22 @@ char* tjsonToUnformattedString(const SJson* pJson) { return cJSON_PrintUnformatt
|
||||||
|
|
||||||
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName) { return cJSON_GetObjectItem(pJson, pName); }
|
SJson* tjsonGetObjectItem(const SJson* pJson, const char* pName) { return cJSON_GetObjectItem(pJson, pName); }
|
||||||
|
|
||||||
|
int32_t tjsonGetObjectName(const SJson* pJson, char** pName) {
|
||||||
|
*pName = ((cJSON*)pJson)->string;
|
||||||
|
if (NULL == *pName) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tjsonGetObjectValueString(const SJson* pJson, char** pValueString) {
|
||||||
|
*pValueString = ((cJSON*)pJson)->valuestring;
|
||||||
|
if (NULL == *pValueString) {
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal) {
|
int32_t tjsonGetStringValue(const SJson* pJson, const char* pName, char* pVal) {
|
||||||
char* p = cJSON_GetStringValue(tjsonGetObjectItem((cJSON*)pJson, pName));
|
char* p = cJSON_GetStringValue(tjsonGetObjectItem((cJSON*)pJson, pName));
|
||||||
if (NULL == p) {
|
if (NULL == p) {
|
||||||
|
@ -309,4 +325,6 @@ bool tjsonValidateJson(const char *jIn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* tjsonGetError() { return cJSON_GetErrorPtr(); }
|
|
@ -31,7 +31,7 @@ ENDIF()
|
||||||
# TARGET_LINK_LIBRARIES(trefTest util common)
|
# TARGET_LINK_LIBRARIES(trefTest util common)
|
||||||
#ENDIF ()
|
#ENDIF ()
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
INCLUDE_DIRECTORIES(${TD_SOURCE_DIR}/src/util/inc)
|
||||||
|
|
||||||
# freelistTest
|
# freelistTest
|
||||||
add_executable(freelistTest "")
|
add_executable(freelistTest "")
|
||||||
|
|
|
@ -32,6 +32,7 @@ TEST_F(CfgTest, 01_Str) {
|
||||||
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_CFG_FILE), "cfg_file");
|
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_CFG_FILE), "cfg_file");
|
||||||
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_FILE), "env_file");
|
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_FILE), "env_file");
|
||||||
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_VAR), "env_var");
|
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_VAR), "env_var");
|
||||||
|
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ENV_CMD), "env_cmd");
|
||||||
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_APOLLO_URL), "apollo_url");
|
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_APOLLO_URL), "apollo_url");
|
||||||
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ARG_LIST), "arg_list");
|
EXPECT_STREQ(cfgStypeStr(CFG_STYPE_ARG_LIST), "arg_list");
|
||||||
EXPECT_STREQ(cfgStypeStr(ECfgSrcType(1024)), "invalid");
|
EXPECT_STREQ(cfgStypeStr(ECfgSrcType(1024)), "invalid");
|
||||||
|
|
|
@ -57,7 +57,8 @@ function compileTDengineVersion() {
|
||||||
|
|
||||||
cd ${debugDir}
|
cd ${debugDir}
|
||||||
cmake ..
|
cmake ..
|
||||||
make -j24
|
make -j24
|
||||||
|
make install
|
||||||
}
|
}
|
||||||
########################################################################################
|
########################################################################################
|
||||||
############################### main process ##########################################
|
############################### main process ##########################################
|
||||||
|
@ -67,20 +68,5 @@ cd ${projectDir}
|
||||||
gitPullBranchInfo $TDengineBrVer
|
gitPullBranchInfo $TDengineBrVer
|
||||||
compileTDengineVersion
|
compileTDengineVersion
|
||||||
|
|
||||||
taos_dir=${projectDir}/debug/build/bin
|
|
||||||
taosd_dir=${projectDir}/debug/build/bin
|
|
||||||
exec_process_dir=${projectDir}/debug/build/bin
|
|
||||||
|
|
||||||
rm -f /usr/bin/taos
|
|
||||||
rm -f /usr/bin/taosd
|
|
||||||
rm -f /usr/bin/create_table
|
|
||||||
rm -f /usr/bin/tmq_demo
|
|
||||||
rm -f /usr/bin/tmq_sim
|
|
||||||
|
|
||||||
ln -s $taos_dir/taos /usr/bin/taos
|
|
||||||
ln -s $taosd_dir/taosd /usr/bin/taosd
|
|
||||||
ln -s $exec_process_dir/create_table /usr/bin/create_table
|
|
||||||
ln -s $exec_process_dir/tmq_demo /usr/bin/tmq_demo
|
|
||||||
ln -s $exec_process_dir/tmq_sim /usr/bin/tmq_sim
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,8 @@ char simScriptDir[PATH_MAX] = {0};
|
||||||
extern bool simExecSuccess;
|
extern bool simExecSuccess;
|
||||||
|
|
||||||
int32_t simInitCfg() {
|
int32_t simInitCfg() {
|
||||||
taosCreateLog("simlog", 1, configDir, NULL, NULL, NULL, 1);
|
taosCreateLog("simlog", 1, configDir, NULL, NULL, NULL, NULL, 1);
|
||||||
taosInitCfg(configDir, NULL, NULL, NULL, 1);
|
taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1);
|
||||||
|
|
||||||
SConfig *pCfg = taosGetCfg();
|
SConfig *pCfg = taosGetCfg();
|
||||||
simDebugFlag = cfgGetItem(pCfg, "simDebugFlag")->i32;
|
simDebugFlag = cfgGetItem(pCfg, "simDebugFlag")->i32;
|
||||||
|
|
|
@ -3,7 +3,7 @@ aux_source_directory(src SHELL_SRC)
|
||||||
add_executable(shell ${SHELL_SRC})
|
add_executable(shell ${SHELL_SRC})
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
shell
|
shell
|
||||||
PUBLIC taos_static
|
PUBLIC taos
|
||||||
PRIVATE os common transport util
|
PRIVATE os common transport util
|
||||||
)
|
)
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
|
|
Loading…
Reference in New Issue