Merge branch 'enh/rocksRevert' of https://github.com/taosdata/TDengine into enh/rocksRevert
This commit is contained in:
commit
efa7b48c1b
|
@ -2,7 +2,7 @@
|
|||
# taosadapter
|
||||
ExternalProject_Add(taosadapter
|
||||
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
|
||||
GIT_TAG cb1e89c
|
||||
GIT_TAG e02ddb2
|
||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# taos-tools
|
||||
ExternalProject_Add(taos-tools
|
||||
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
|
||||
GIT_TAG 149ac34
|
||||
GIT_TAG 0681d8b
|
||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
-DLINUX
|
||||
-DWEBSOCKET
|
||||
-I/usr/include
|
||||
-Iinclude
|
||||
-Iinclude/os
|
||||
-Iinclude/common
|
||||
-Iinclude/util
|
||||
-Iinclude/libs/transport
|
||||
-Itools/shell/inc
|
|
@ -178,7 +178,7 @@ Active: inactive (dead)
|
|||
|
||||
:::
|
||||
|
||||
## TDengine 命令行(CLI)
|
||||
**TDengine 命令行(CLI)**
|
||||
|
||||
为便于检查 TDengine 的状态,执行数据库(Database)的各种即席(Ad Hoc)查询,TDengine 提供一命令行应用程序(以下简称为 TDengine CLI)taos。要进入 TDengine 命令行,您只要在终端执行 `taos` 即可。
|
||||
|
||||
|
@ -188,7 +188,7 @@ Active: inactive (dead)
|
|||
|
||||
安装后,可以在拥有管理员权限的 cmd 窗口执行 `sc start taosd` 或在 `C:\TDengine` 目录下,运行 `taosd.exe` 来启动 TDengine 服务进程。
|
||||
|
||||
## TDengine 命令行(CLI)
|
||||
**TDengine 命令行(CLI)**
|
||||
|
||||
为便于检查 TDengine 的状态,执行数据库(Database)的各种即席(Ad Hoc)查询,TDengine 提供一命令行应用程序(以下简称为 TDengine CLI)taos。要进入 TDengine 命令行,您只要在终端执行 `taos` 即可。
|
||||
|
||||
|
@ -215,7 +215,7 @@ Active: inactive (dead)
|
|||
|
||||
:::
|
||||
|
||||
## TDengine 命令行(CLI)
|
||||
**TDengine 命令行(CLI)**
|
||||
|
||||
为便于检查 TDengine 的状态,执行数据库(Database)的各种即席(Ad Hoc)查询,TDengine 提供一命令行应用程序(以下简称为 TDengine CLI)taos。要进入 TDengine 命令行,您只要在 Windows 终端的 C:\TDengine 目录下,运行 taos.exe 来启动 TDengine 命令行。
|
||||
|
||||
|
|
|
@ -231,7 +231,7 @@ bit_add 实现多列的按位与功能。如果只有一列,返回这一列。
|
|||
|
||||
</details>
|
||||
|
||||
### 聚合函数示例 [l2norm](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/l2norm.c)
|
||||
### 聚合函数示例1 返回值为数值类型 [l2norm](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/l2norm.c)
|
||||
|
||||
l2norm 实现了输入列的所有数据的二阶范数,即对每个数据先平方,再累加求和,最后开方。
|
||||
|
||||
|
@ -243,3 +243,29 @@ l2norm 实现了输入列的所有数据的二阶范数,即对每个数据先
|
|||
```
|
||||
|
||||
</details>
|
||||
|
||||
### 聚合函数示例2 返回值为字符串类型 [max_vol](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/max_vol.c)
|
||||
|
||||
max_vol 实现了从多个输入的电压列中找到最大电压,返回由设备ID + 最大电压所在(行,列)+ 最大电压值 组成的组合字符串值
|
||||
|
||||
创建表:
|
||||
```bash
|
||||
create table battery(ts timestamp, vol1 float, vol2 float, vol3 float, deviceId varchar(16));
|
||||
```
|
||||
创建自定义函数:
|
||||
```bash
|
||||
create aggregate function max_vol as '/root/udf/libmaxvol.so' outputtype binary(64) bufsize 10240 language 'C';
|
||||
```
|
||||
使用自定义函数:
|
||||
```bash
|
||||
select max_vol(vol1,vol2,vol3,deviceid) from battery;
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>max_vol.c</summary>
|
||||
|
||||
```c
|
||||
{{#include tests/script/sh/max_vol.c}}
|
||||
```
|
||||
|
||||
</details>
|
|
@ -208,15 +208,12 @@ typedef struct SSDataBlock {
|
|||
} SSDataBlock;
|
||||
|
||||
enum {
|
||||
FETCH_TYPE__DATA = 1,
|
||||
FETCH_TYPE__META,
|
||||
FETCH_TYPE__SEP,
|
||||
FETCH_TYPE__DATA = 0,
|
||||
FETCH_TYPE__NONE,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int8_t fetchType;
|
||||
STqOffsetVal offset;
|
||||
union {
|
||||
SSDataBlock data;
|
||||
void* meta;
|
||||
|
|
|
@ -104,6 +104,7 @@ extern int32_t tsCacheLazyLoadThreshold; // cost threshold for last/last_row lo
|
|||
// query client
|
||||
extern int32_t tsQueryPolicy;
|
||||
extern int32_t tsQueryRspPolicy;
|
||||
extern int64_t tsQueryMaxConcurrentTables;
|
||||
extern int32_t tsQuerySmaOptimize;
|
||||
extern int32_t tsQueryRsmaTolerance;
|
||||
extern bool tsQueryPlannerTrace;
|
||||
|
|
|
@ -177,6 +177,12 @@ typedef enum _mgmt_table {
|
|||
#define TSDB_ALTER_USER_SYSINFO 0xA
|
||||
#define TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC 0xB
|
||||
#define TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC 0xC
|
||||
#define TSDB_ALTER_USER_ADD_READ_TABLE 0xD
|
||||
#define TSDB_ALTER_USER_REMOVE_READ_TABLE 0xE
|
||||
#define TSDB_ALTER_USER_ADD_WRITE_TABLE 0xF
|
||||
#define TSDB_ALTER_USER_REMOVE_WRITE_TABLE 0x10
|
||||
#define TSDB_ALTER_USER_ADD_ALL_TABLE 0x11
|
||||
#define TSDB_ALTER_USER_REMOVE_ALL_TABLE 0x12
|
||||
|
||||
#define TSDB_ALTER_USER_PRIVILEGES 0x2
|
||||
|
||||
|
@ -669,13 +675,16 @@ int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq
|
|||
int32_t tDeserializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int8_t alterType;
|
||||
int8_t superUser;
|
||||
int8_t sysInfo;
|
||||
int8_t enable;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_USET_PASSWORD_LEN];
|
||||
char objname[TSDB_DB_FNAME_LEN]; // db or topic
|
||||
int8_t alterType;
|
||||
int8_t superUser;
|
||||
int8_t sysInfo;
|
||||
int8_t enable;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_USET_PASSWORD_LEN];
|
||||
char objname[TSDB_DB_FNAME_LEN]; // db or topic
|
||||
char tabName[TSDB_TABLE_NAME_LEN];
|
||||
char* tagCond;
|
||||
int32_t tagCondLen;
|
||||
} SAlterUserReq;
|
||||
|
||||
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
|
||||
|
@ -698,6 +707,9 @@ typedef struct {
|
|||
SHashObj* createdDbs;
|
||||
SHashObj* readDbs;
|
||||
SHashObj* writeDbs;
|
||||
SHashObj* readTbs;
|
||||
SHashObj* writeTbs;
|
||||
SHashObj* useDbs;
|
||||
} SGetUserAuthRsp;
|
||||
|
||||
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
|
||||
|
|
|
@ -63,55 +63,55 @@
|
|||
#define TK_READ 45
|
||||
#define TK_WRITE 46
|
||||
#define TK_NK_DOT 47
|
||||
#define TK_DNODE 48
|
||||
#define TK_PORT 49
|
||||
#define TK_DNODES 50
|
||||
#define TK_NK_IPTOKEN 51
|
||||
#define TK_FORCE 52
|
||||
#define TK_LOCAL 53
|
||||
#define TK_QNODE 54
|
||||
#define TK_BNODE 55
|
||||
#define TK_SNODE 56
|
||||
#define TK_MNODE 57
|
||||
#define TK_DATABASE 58
|
||||
#define TK_USE 59
|
||||
#define TK_FLUSH 60
|
||||
#define TK_TRIM 61
|
||||
#define TK_COMPACT 62
|
||||
#define TK_IF 63
|
||||
#define TK_NOT 64
|
||||
#define TK_EXISTS 65
|
||||
#define TK_BUFFER 66
|
||||
#define TK_CACHEMODEL 67
|
||||
#define TK_CACHESIZE 68
|
||||
#define TK_COMP 69
|
||||
#define TK_DURATION 70
|
||||
#define TK_NK_VARIABLE 71
|
||||
#define TK_MAXROWS 72
|
||||
#define TK_MINROWS 73
|
||||
#define TK_KEEP 74
|
||||
#define TK_PAGES 75
|
||||
#define TK_PAGESIZE 76
|
||||
#define TK_TSDB_PAGESIZE 77
|
||||
#define TK_PRECISION 78
|
||||
#define TK_REPLICA 79
|
||||
#define TK_VGROUPS 80
|
||||
#define TK_SINGLE_STABLE 81
|
||||
#define TK_RETENTIONS 82
|
||||
#define TK_SCHEMALESS 83
|
||||
#define TK_WAL_LEVEL 84
|
||||
#define TK_WAL_FSYNC_PERIOD 85
|
||||
#define TK_WAL_RETENTION_PERIOD 86
|
||||
#define TK_WAL_RETENTION_SIZE 87
|
||||
#define TK_WAL_ROLL_PERIOD 88
|
||||
#define TK_WAL_SEGMENT_SIZE 89
|
||||
#define TK_STT_TRIGGER 90
|
||||
#define TK_TABLE_PREFIX 91
|
||||
#define TK_TABLE_SUFFIX 92
|
||||
#define TK_NK_COLON 93
|
||||
#define TK_MAX_SPEED 94
|
||||
#define TK_START 95
|
||||
#define TK_WITH 96
|
||||
#define TK_WITH 48
|
||||
#define TK_DNODE 49
|
||||
#define TK_PORT 50
|
||||
#define TK_DNODES 51
|
||||
#define TK_NK_IPTOKEN 52
|
||||
#define TK_FORCE 53
|
||||
#define TK_LOCAL 54
|
||||
#define TK_QNODE 55
|
||||
#define TK_BNODE 56
|
||||
#define TK_SNODE 57
|
||||
#define TK_MNODE 58
|
||||
#define TK_DATABASE 59
|
||||
#define TK_USE 60
|
||||
#define TK_FLUSH 61
|
||||
#define TK_TRIM 62
|
||||
#define TK_COMPACT 63
|
||||
#define TK_IF 64
|
||||
#define TK_NOT 65
|
||||
#define TK_EXISTS 66
|
||||
#define TK_BUFFER 67
|
||||
#define TK_CACHEMODEL 68
|
||||
#define TK_CACHESIZE 69
|
||||
#define TK_COMP 70
|
||||
#define TK_DURATION 71
|
||||
#define TK_NK_VARIABLE 72
|
||||
#define TK_MAXROWS 73
|
||||
#define TK_MINROWS 74
|
||||
#define TK_KEEP 75
|
||||
#define TK_PAGES 76
|
||||
#define TK_PAGESIZE 77
|
||||
#define TK_TSDB_PAGESIZE 78
|
||||
#define TK_PRECISION 79
|
||||
#define TK_REPLICA 80
|
||||
#define TK_VGROUPS 81
|
||||
#define TK_SINGLE_STABLE 82
|
||||
#define TK_RETENTIONS 83
|
||||
#define TK_SCHEMALESS 84
|
||||
#define TK_WAL_LEVEL 85
|
||||
#define TK_WAL_FSYNC_PERIOD 86
|
||||
#define TK_WAL_RETENTION_PERIOD 87
|
||||
#define TK_WAL_RETENTION_SIZE 88
|
||||
#define TK_WAL_ROLL_PERIOD 89
|
||||
#define TK_WAL_SEGMENT_SIZE 90
|
||||
#define TK_STT_TRIGGER 91
|
||||
#define TK_TABLE_PREFIX 92
|
||||
#define TK_TABLE_SUFFIX 93
|
||||
#define TK_NK_COLON 94
|
||||
#define TK_MAX_SPEED 95
|
||||
#define TK_START 96
|
||||
#define TK_TIMESTAMP 97
|
||||
#define TK_END 98
|
||||
#define TK_TABLE 99
|
||||
|
@ -127,24 +127,24 @@
|
|||
#define TK_NK_EQ 109
|
||||
#define TK_USING 110
|
||||
#define TK_TAGS 111
|
||||
#define TK_COMMENT 112
|
||||
#define TK_BOOL 113
|
||||
#define TK_TINYINT 114
|
||||
#define TK_SMALLINT 115
|
||||
#define TK_INT 116
|
||||
#define TK_INTEGER 117
|
||||
#define TK_BIGINT 118
|
||||
#define TK_FLOAT 119
|
||||
#define TK_DOUBLE 120
|
||||
#define TK_BINARY 121
|
||||
#define TK_NCHAR 122
|
||||
#define TK_UNSIGNED 123
|
||||
#define TK_JSON 124
|
||||
#define TK_VARCHAR 125
|
||||
#define TK_MEDIUMBLOB 126
|
||||
#define TK_BLOB 127
|
||||
#define TK_VARBINARY 128
|
||||
#define TK_DECIMAL 129
|
||||
#define TK_BOOL 112
|
||||
#define TK_TINYINT 113
|
||||
#define TK_SMALLINT 114
|
||||
#define TK_INT 115
|
||||
#define TK_INTEGER 116
|
||||
#define TK_BIGINT 117
|
||||
#define TK_FLOAT 118
|
||||
#define TK_DOUBLE 119
|
||||
#define TK_BINARY 120
|
||||
#define TK_NCHAR 121
|
||||
#define TK_UNSIGNED 122
|
||||
#define TK_JSON 123
|
||||
#define TK_VARCHAR 124
|
||||
#define TK_MEDIUMBLOB 125
|
||||
#define TK_BLOB 126
|
||||
#define TK_VARBINARY 127
|
||||
#define TK_DECIMAL 128
|
||||
#define TK_COMMENT 129
|
||||
#define TK_MAX_DELAY 130
|
||||
#define TK_WATERMARK 131
|
||||
#define TK_ROLLUP 132
|
||||
|
|
|
@ -29,6 +29,7 @@ extern "C" {
|
|||
#include "tmsg.h"
|
||||
#include "tname.h"
|
||||
#include "transport.h"
|
||||
#include "nodes.h"
|
||||
|
||||
typedef struct SCatalog SCatalog;
|
||||
|
||||
|
@ -49,10 +50,15 @@ typedef enum {
|
|||
|
||||
typedef struct SUserAuthInfo {
|
||||
char user[TSDB_USER_LEN];
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
SName tbName;
|
||||
AUTH_TYPE type;
|
||||
} SUserAuthInfo;
|
||||
|
||||
typedef struct SUserAuthRes {
|
||||
bool pass;
|
||||
SNode* pCond;
|
||||
} SUserAuthRes;
|
||||
|
||||
typedef struct SDbInfo {
|
||||
int32_t vgVer;
|
||||
int32_t tbNum;
|
||||
|
@ -96,7 +102,7 @@ typedef struct SMetaData {
|
|||
SArray* pTableIndex; // pRes = SArray<STableIndexInfo>*
|
||||
SArray* pUdfList; // pRes = SFuncInfo*
|
||||
SArray* pIndex; // pRes = SIndexInfo*
|
||||
SArray* pUser; // pRes = bool*
|
||||
SArray* pUser; // pRes = SUserAuthRes*
|
||||
SArray* pQnodeList; // pRes = SArray<SQueryNodeLoad>*
|
||||
SArray* pTableCfg; // pRes = STableCfg*
|
||||
SArray* pDnodeList; // pRes = SArray<SEpSet>*
|
||||
|
@ -312,11 +318,9 @@ int32_t catalogUpdateTableIndex(SCatalog* pCtg, STableIndexRsp* pRsp);
|
|||
|
||||
int32_t catalogGetUdfInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* funcName, SFuncInfo* pInfo);
|
||||
|
||||
int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type,
|
||||
bool* pass);
|
||||
int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, SUserAuthInfo *pAuth, SUserAuthRes* pRes);
|
||||
|
||||
int32_t catalogChkAuthFromCache(SCatalog* pCtg, const char* user, const char* dbFName, AUTH_TYPE type, bool* pass,
|
||||
bool* exists);
|
||||
int32_t catalogChkAuthFromCache(SCatalog* pCtg, SUserAuthInfo *pAuth, SUserAuthRes* pRes, bool* exists);
|
||||
|
||||
int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ extern "C" {
|
|||
|
||||
typedef void* qTaskInfo_t;
|
||||
typedef void* DataSinkHandle;
|
||||
|
||||
struct SRpcMsg;
|
||||
struct SSubplan;
|
||||
|
||||
|
@ -91,7 +92,9 @@ void qSetTaskId(qTaskInfo_t tinfo, uint64_t taskId, uint64_t queryId);
|
|||
|
||||
int32_t qSetStreamOpOpen(qTaskInfo_t tinfo);
|
||||
|
||||
// todo refactor
|
||||
void qGetCheckpointVersion(qTaskInfo_t tinfo, int64_t* dataVer, int64_t* ckId);
|
||||
|
||||
/**
|
||||
* Set multiple input data blocks for the stream scan.
|
||||
* @param tinfo
|
||||
|
@ -120,7 +123,7 @@ int32_t qSetSMAInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks,
|
|||
* @param isAdd
|
||||
* @return
|
||||
*/
|
||||
int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd);
|
||||
int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd, SArray* pList);
|
||||
|
||||
/**
|
||||
* Create the exec task object according to task json
|
||||
|
@ -164,6 +167,7 @@ void qCleanExecTaskBlockBuf(qTaskInfo_t tinfo);
|
|||
* @return
|
||||
*/
|
||||
int32_t qAsyncKillTask(qTaskInfo_t tinfo, int32_t rspCode);
|
||||
|
||||
int32_t qKillTask(qTaskInfo_t tinfo, int32_t rspCode);
|
||||
|
||||
bool qTaskIsExecuting(qTaskInfo_t qinfo);
|
||||
|
@ -183,29 +187,19 @@ int32_t qSerializeTaskStatus(qTaskInfo_t tinfo, char** pOutput, int32_t* len);
|
|||
int32_t qDeserializeTaskStatus(qTaskInfo_t tinfo, const char* pInput, int32_t len);
|
||||
|
||||
STimeWindow getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key);
|
||||
/**
|
||||
* return the scan info, in the form of tuple of two items, including table uid and current timestamp
|
||||
* @param tinfo
|
||||
* @param uid
|
||||
* @param ts
|
||||
* @return
|
||||
*/
|
||||
int32_t qGetStreamScanStatus(qTaskInfo_t tinfo, uint64_t* uid, int64_t* ts);
|
||||
|
||||
int32_t qStreamPrepareTsdbScan(qTaskInfo_t tinfo, uint64_t uid, int64_t ts);
|
||||
SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo);
|
||||
|
||||
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType);
|
||||
|
||||
// int32_t qStreamScanMemData(qTaskInfo_t tinfo, const SSubmitReq* pReq, int64_t ver);
|
||||
//
|
||||
int32_t qStreamSetScanMemData(qTaskInfo_t tinfo, SPackedData submit);
|
||||
|
||||
int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset);
|
||||
void qStreamSetOpen(qTaskInfo_t tinfo);
|
||||
|
||||
void qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset);
|
||||
|
||||
SMqMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo);
|
||||
|
||||
int64_t qStreamExtractPrepareUid(qTaskInfo_t tinfo);
|
||||
|
||||
const SSchemaWrapper* qExtractSchemaFromTask(qTaskInfo_t tinfo);
|
||||
|
||||
const char* qExtractTbnameFromTask(qTaskInfo_t tinfo);
|
||||
|
|
|
@ -458,7 +458,9 @@ typedef struct SGrantStmt {
|
|||
ENodeType type;
|
||||
char userName[TSDB_USER_LEN];
|
||||
char objName[TSDB_DB_NAME_LEN]; // db or topic
|
||||
char tabName[TSDB_TABLE_NAME_LEN];
|
||||
int64_t privileges;
|
||||
SNode* pTagCond;
|
||||
} SGrantStmt;
|
||||
|
||||
typedef SGrantStmt SRevokeStmt;
|
||||
|
|
|
@ -298,6 +298,7 @@ typedef struct SSelectStmt {
|
|||
bool hasUniqueFunc;
|
||||
bool hasTailFunc;
|
||||
bool hasInterpFunc;
|
||||
bool hasInterpPseudoColFunc;
|
||||
bool hasLastRowFunc;
|
||||
bool hasLastFunc;
|
||||
bool hasTimeLineFunc;
|
||||
|
|
|
@ -194,6 +194,7 @@ typedef struct SRequestConnInfo {
|
|||
|
||||
typedef void (*__freeFunc)(void* param);
|
||||
|
||||
// todo add creator/destroyer function
|
||||
typedef struct SMsgSendInfo {
|
||||
__async_send_cb_fn_t fp; // async callback function
|
||||
STargetInfo target; // for update epset
|
||||
|
|
|
@ -88,6 +88,8 @@ int32_t streamStateGetByPos(SStreamState* pState, void* pos, void** pVal);
|
|||
int32_t streamStateDel(SStreamState* pState, const SWinKey* key);
|
||||
int32_t streamStateClear(SStreamState* pState);
|
||||
void streamStateSetNumber(SStreamState* pState, int32_t number);
|
||||
int32_t streamStateSaveInfo(SStreamState* pState, void* pKey, int32_t keyLen, void* pVal, int32_t vLen);
|
||||
int32_t streamStateGetInfo(SStreamState* pState, void* pKey, int32_t keyLen, void** pVal, int32_t* pLen);
|
||||
|
||||
int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal, int32_t* pVLen);
|
||||
int32_t streamStateSessionPut(SStreamState* pState, const SSessionKey* key, const void* value, int32_t vLen);
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "executor.h"
|
||||
#include "os.h"
|
||||
#include "executor.h"
|
||||
#include "query.h"
|
||||
#include "streamState.h"
|
||||
#include "tdatablock.h"
|
||||
|
@ -31,6 +31,7 @@ extern "C" {
|
|||
#ifndef _STREAM_H_
|
||||
#define _STREAM_H_
|
||||
|
||||
typedef void (*_free_reader_fn_t)(void*);
|
||||
typedef struct SStreamTask SStreamTask;
|
||||
|
||||
enum {
|
||||
|
@ -50,6 +51,7 @@ enum {
|
|||
TASK_STATUS__RECOVER_PREPARE,
|
||||
TASK_STATUS__RECOVER1,
|
||||
TASK_STATUS__RECOVER2,
|
||||
TASK_STATUS__RESTORE, // only available for source task to replay WAL from the checkpoint
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -103,21 +105,8 @@ typedef struct {
|
|||
int8_t type;
|
||||
} SStreamQueueItem;
|
||||
|
||||
#if 0
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
int64_t ver;
|
||||
int32_t* dataRef;
|
||||
SSubmitReq* data;
|
||||
} SStreamDataSubmit;
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
int64_t ver;
|
||||
SArray* dataRefs; // SArray<int32_t*>
|
||||
SArray* reqs; // SArray<SSubmitReq*>
|
||||
} SStreamMergedSubmit;
|
||||
#endif
|
||||
typedef void FTbSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
||||
typedef int32_t FTaskExpand(void* ahandle, SStreamTask* pTask, int64_t ver);
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
|
@ -219,36 +208,21 @@ static FORCE_INLINE void streamQueueProcessFail(SStreamQueue* queue) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE void* streamQueueCurItem(SStreamQueue* queue) {
|
||||
//
|
||||
return queue->qItem;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* streamQueueNextItem(SStreamQueue* queue) {
|
||||
int8_t dequeueFlag = atomic_exchange_8(&queue->status, STREAM_QUEUE__PROCESSING);
|
||||
if (dequeueFlag == STREAM_QUEUE__FAILED) {
|
||||
ASSERT(queue->qItem != NULL);
|
||||
return streamQueueCurItem(queue);
|
||||
} else {
|
||||
queue->qItem = NULL;
|
||||
taosGetQitem(queue->qall, &queue->qItem);
|
||||
if (queue->qItem == NULL) {
|
||||
taosReadAllQitems(queue->queue, queue->qall);
|
||||
taosGetQitem(queue->qall, &queue->qItem);
|
||||
}
|
||||
return streamQueueCurItem(queue);
|
||||
}
|
||||
}
|
||||
void* streamQueueNextItem(SStreamQueue* queue);
|
||||
|
||||
SStreamDataSubmit2* streamDataSubmitNew(SPackedData submit);
|
||||
SStreamDataSubmit2* streamDataSubmitNew(SPackedData submit, int32_t type);
|
||||
void streamDataSubmitDestroy(SStreamDataSubmit2* pDataSubmit);
|
||||
|
||||
void streamDataSubmitRefDec(SStreamDataSubmit2* pDataSubmit);
|
||||
|
||||
SStreamDataSubmit2* streamSubmitRefClone(SStreamDataSubmit2* pSubmit);
|
||||
SStreamDataSubmit2* streamSubmitBlockClone(SStreamDataSubmit2* pSubmit);
|
||||
|
||||
typedef struct {
|
||||
char* qmsg;
|
||||
// followings are not applicable to encoder and decoder
|
||||
void* executor;
|
||||
char* qmsg;
|
||||
void* pExecutor; // not applicable to encoder and decoder
|
||||
struct STqReader* pTqReader; // not applicable to encoder and decoder
|
||||
struct SWalReader* pWalReader; // not applicable to encoder and decoder
|
||||
} STaskExec;
|
||||
|
||||
typedef struct {
|
||||
|
@ -263,16 +237,13 @@ typedef struct {
|
|||
SUseDbRsp dbInfo;
|
||||
} STaskDispatcherShuffle;
|
||||
|
||||
typedef void FTbSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
||||
|
||||
typedef struct {
|
||||
int64_t stbUid;
|
||||
char stbFullName[TSDB_TABLE_FNAME_LEN];
|
||||
SSchemaWrapper* pSchemaWrapper;
|
||||
// not applicable to encoder and decoder
|
||||
void* vnode;
|
||||
FTbSink* tbSinkFunc;
|
||||
STSchema* pTSchema;
|
||||
void* vnode; // not available to encoder and decoder
|
||||
FTbSink* tbSinkFunc;
|
||||
STSchema* pTSchema;
|
||||
} STaskSinkTb;
|
||||
|
||||
typedef void FSmaSink(void* vnode, int64_t smaId, const SArray* data);
|
||||
|
@ -295,24 +266,34 @@ typedef struct {
|
|||
SEpSet epSet;
|
||||
} SStreamChildEpInfo;
|
||||
|
||||
struct SStreamTask {
|
||||
int64_t streamId;
|
||||
int32_t taskId;
|
||||
int32_t totalLevel;
|
||||
int8_t taskLevel;
|
||||
int8_t outputType;
|
||||
int16_t dispatchMsgType;
|
||||
typedef struct SStreamId {
|
||||
int64_t streamId;
|
||||
int32_t taskId;
|
||||
const char* idStr;
|
||||
} SStreamId;
|
||||
|
||||
typedef struct SCheckpointInfo {
|
||||
int64_t id;
|
||||
int64_t version; // offset in WAL
|
||||
} SCheckpointInfo;
|
||||
|
||||
typedef struct SStreamStatus {
|
||||
int8_t taskStatus;
|
||||
int8_t schedStatus;
|
||||
} SStreamStatus;
|
||||
|
||||
// node info
|
||||
int32_t selfChildId;
|
||||
int32_t nodeId;
|
||||
SEpSet epSet;
|
||||
|
||||
int64_t recoverSnapVer;
|
||||
int64_t startVer;
|
||||
struct SStreamTask {
|
||||
SStreamId id;
|
||||
int32_t totalLevel;
|
||||
int8_t taskLevel;
|
||||
int8_t outputType;
|
||||
int16_t dispatchMsgType;
|
||||
SStreamStatus status;
|
||||
int32_t selfChildId;
|
||||
int32_t nodeId;
|
||||
SEpSet epSet;
|
||||
SCheckpointInfo chkInfo;
|
||||
STaskExec exec;
|
||||
|
||||
// fill history
|
||||
int8_t fillHistory;
|
||||
|
@ -322,9 +303,6 @@ struct SStreamTask {
|
|||
int32_t nextCheckId;
|
||||
SArray* checkpointInfo; // SArray<SStreamCheckpointInfo>
|
||||
|
||||
// exec
|
||||
STaskExec exec;
|
||||
|
||||
// output
|
||||
union {
|
||||
STaskDispatcherFixedEp fixedEpDispatcher;
|
||||
|
@ -334,82 +312,56 @@ struct SStreamTask {
|
|||
STaskSinkFetch fetchSink;
|
||||
};
|
||||
|
||||
int8_t inputStatus;
|
||||
int8_t outputStatus;
|
||||
|
||||
// STaosQueue* inputQueue1;
|
||||
// STaosQall* inputQall;
|
||||
int8_t inputStatus;
|
||||
int8_t outputStatus;
|
||||
SStreamQueue* inputQueue;
|
||||
SStreamQueue* outputQueue;
|
||||
|
||||
// trigger
|
||||
int8_t triggerStatus;
|
||||
int64_t triggerParam;
|
||||
void* timer;
|
||||
int8_t triggerStatus;
|
||||
int64_t triggerParam;
|
||||
void* timer;
|
||||
SMsgCb* pMsgCb; // msg handle
|
||||
SStreamState* pState; // state backend
|
||||
|
||||
// msg handle
|
||||
SMsgCb* pMsgCb;
|
||||
|
||||
// state backend
|
||||
SStreamState* pState;
|
||||
|
||||
// do not serialize
|
||||
int32_t recoverTryingDownstream;
|
||||
int32_t recoverWaitingUpstream;
|
||||
int64_t checkReqId;
|
||||
SArray* checkReqIds; // shuffle
|
||||
int32_t refCnt;
|
||||
|
||||
int64_t checkpointingId;
|
||||
int32_t checkpointAlignCnt;
|
||||
// the followings attributes don't be serialized
|
||||
int32_t recoverTryingDownstream;
|
||||
int32_t recoverWaitingUpstream;
|
||||
int64_t checkReqId;
|
||||
SArray* checkReqIds; // shuffle
|
||||
int32_t refCnt;
|
||||
int64_t checkpointingId;
|
||||
int32_t checkpointAlignCnt;
|
||||
struct SStreamMeta* pMeta;
|
||||
_free_reader_fn_t freeFp;
|
||||
};
|
||||
|
||||
// meta
|
||||
typedef struct SStreamMeta {
|
||||
char* path;
|
||||
TDB* db;
|
||||
TTB* pTaskDb;
|
||||
TTB* pCheckpointDb;
|
||||
SHashObj* pTasks;
|
||||
SHashObj* pWalReadTasks;
|
||||
void* ahandle;
|
||||
TXN* txn;
|
||||
FTaskExpand* expandFunc;
|
||||
int32_t vgId;
|
||||
SRWLatch lock;
|
||||
int8_t walScan;
|
||||
bool quit;
|
||||
} SStreamMeta;
|
||||
|
||||
int32_t tEncodeStreamEpInfo(SEncoder* pEncoder, const SStreamChildEpInfo* pInfo);
|
||||
int32_t tDecodeStreamEpInfo(SDecoder* pDecoder, SStreamChildEpInfo* pInfo);
|
||||
|
||||
SStreamTask* tNewSStreamTask(int64_t streamId);
|
||||
int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask);
|
||||
int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask);
|
||||
void tFreeSStreamTask(SStreamTask* pTask);
|
||||
|
||||
static FORCE_INLINE int32_t streamTaskInput(SStreamTask* pTask, SStreamQueueItem* pItem) {
|
||||
int32_t code = 0;
|
||||
int8_t type = pItem->type;
|
||||
if (type == STREAM_INPUT__DATA_SUBMIT) {
|
||||
SStreamDataSubmit2* pSubmitClone = streamSubmitRefClone((SStreamDataSubmit2*)pItem);
|
||||
if (pSubmitClone == NULL) {
|
||||
qDebug("task %d %p submit enqueue failed since out of memory", pTask->taskId, pTask);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
||||
return -1;
|
||||
}
|
||||
qDebug("task %d %p submit enqueue %p %p %p %d %" PRId64, pTask->taskId, pTask, pItem, pSubmitClone,
|
||||
pSubmitClone->submit.msgStr, pSubmitClone->submit.msgLen, pSubmitClone->submit.ver);
|
||||
code = taosWriteQitem(pTask->inputQueue->queue, pSubmitClone);
|
||||
// qStreamInput(pTask->exec.executor, pSubmitClone);
|
||||
} else if (type == STREAM_INPUT__DATA_BLOCK || type == STREAM_INPUT__DATA_RETRIEVE ||
|
||||
type == STREAM_INPUT__REF_DATA_BLOCK) {
|
||||
code = taosWriteQitem(pTask->inputQueue->queue, pItem);
|
||||
// qStreamInput(pTask->exec.executor, pItem);
|
||||
} else if (type == STREAM_INPUT__CHECKPOINT) {
|
||||
code = taosWriteQitem(pTask->inputQueue->queue, pItem);
|
||||
// qStreamInput(pTask->exec.executor, pItem);
|
||||
} else if (type == STREAM_INPUT__GET_RES) {
|
||||
code = taosWriteQitem(pTask->inputQueue->queue, pItem);
|
||||
// qStreamInput(pTask->exec.executor, pItem);
|
||||
}
|
||||
if (code != 0) return code;
|
||||
|
||||
if (type != STREAM_INPUT__GET_RES && type != STREAM_INPUT__CHECKPOINT && pTask->triggerParam != 0) {
|
||||
atomic_val_compare_exchange_8(&pTask->triggerStatus, TASK_TRIGGER_STATUS__INACTIVE, TASK_TRIGGER_STATUS__ACTIVE);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// TODO: back pressure
|
||||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__NORMAL);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
SStreamTask* tNewStreamTask(int64_t streamId);
|
||||
int32_t tEncodeStreamTask(SEncoder* pEncoder, const SStreamTask* pTask);
|
||||
int32_t tDecodeStreamTask(SDecoder* pDecoder, SStreamTask* pTask);
|
||||
void tFreeStreamTask(SStreamTask* pTask);
|
||||
int32_t tAppendDataToInputQueue(SStreamTask* pTask, SStreamQueueItem* pItem);
|
||||
bool tInputQueueIsFull(const SStreamTask* pTask);
|
||||
|
||||
static FORCE_INLINE void streamTaskInputFail(SStreamTask* pTask) {
|
||||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
||||
|
@ -617,40 +569,23 @@ int32_t streamAggRecoverPrepare(SStreamTask* pTask);
|
|||
// int32_t streamAggChildrenRecoverFinish(SStreamTask* pTask);
|
||||
int32_t streamProcessRecoverFinishReq(SStreamTask* pTask, int32_t childId);
|
||||
|
||||
// expand and deploy
|
||||
typedef int32_t FTaskExpand(void* ahandle, SStreamTask* pTask, int64_t ver);
|
||||
|
||||
// meta
|
||||
typedef struct SStreamMeta {
|
||||
char* path;
|
||||
TDB* db;
|
||||
TTB* pTaskDb;
|
||||
TTB* pCheckpointDb;
|
||||
SHashObj* pTasks;
|
||||
SHashObj* pRecoverStatus;
|
||||
void* ahandle;
|
||||
TXN* txn;
|
||||
FTaskExpand* expandFunc;
|
||||
int32_t vgId;
|
||||
SRWLatch lock;
|
||||
} SStreamMeta;
|
||||
|
||||
SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandFunc, int32_t vgId);
|
||||
void streamMetaClose(SStreamMeta* streamMeta);
|
||||
|
||||
int32_t streamMetaSaveTask(SStreamMeta* pMeta, SStreamTask* pTask);
|
||||
int32_t streamMetaAddTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTask);
|
||||
int32_t streamMetaAddSerializedTask(SStreamMeta* pMeta, int64_t startVer, char* msg, int32_t msgLen);
|
||||
// SStreamTask* streamMetaGetTask(SStreamMeta* pMeta, int32_t taskId);
|
||||
int32_t streamMetaSaveTask(SStreamMeta* pMeta, SStreamTask* pTask);
|
||||
int32_t streamMetaAddDeployedTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTask);
|
||||
int32_t streamMetaAddSerializedTask(SStreamMeta* pMeta, int64_t checkpointVer, char* msg, int32_t msgLen);
|
||||
int32_t streamMetaGetNumOfTasks(const SStreamMeta* pMeta);
|
||||
|
||||
SStreamTask* streamMetaAcquireTaskEx(SStreamMeta* pMeta, int32_t taskId);
|
||||
SStreamTask* streamMetaAcquireTask(SStreamMeta* pMeta, int32_t taskId);
|
||||
void streamMetaReleaseTask(SStreamMeta* pMeta, SStreamTask* pTask);
|
||||
void streamMetaRemoveTask(SStreamMeta* pMeta, int32_t taskId);
|
||||
|
||||
int32_t streamMetaBegin(SStreamMeta* pMeta);
|
||||
int32_t streamMetaCommit(SStreamMeta* pMeta);
|
||||
int32_t streamMetaRollBack(SStreamMeta* pMeta);
|
||||
int32_t streamLoadTasks(SStreamMeta* pMeta, int64_t ver);
|
||||
int32_t streamMetaBegin(SStreamMeta* pMeta);
|
||||
int32_t streamMetaCommit(SStreamMeta* pMeta);
|
||||
int32_t streamMetaRollBack(SStreamMeta* pMeta);
|
||||
int32_t streamLoadTasks(SStreamMeta* pMeta, int64_t ver);
|
||||
|
||||
// checkpoint
|
||||
int32_t streamProcessCheckpointSourceReq(SStreamMeta* pMeta, SStreamTask* pTask, SStreamCheckpointSourceReq* pReq);
|
||||
|
|
|
@ -138,7 +138,8 @@ typedef struct {
|
|||
int8_t enableRef;
|
||||
} SWalFilterCond;
|
||||
|
||||
typedef struct {
|
||||
// todo hide this struct
|
||||
typedef struct SWalReader {
|
||||
SWal *pWal;
|
||||
int64_t readerId;
|
||||
TdFilePtr pLogFile;
|
||||
|
@ -146,8 +147,8 @@ typedef struct {
|
|||
int64_t curFileFirstVer;
|
||||
int64_t curVersion;
|
||||
int64_t capacity;
|
||||
int8_t curInvalid;
|
||||
int8_t curStopped;
|
||||
// int8_t curInvalid;
|
||||
// int8_t curStopped;
|
||||
TdThreadMutex mutex;
|
||||
SWalFilterCond cond;
|
||||
// TODO remove it
|
||||
|
@ -196,6 +197,7 @@ void walReadReset(SWalReader *pReader);
|
|||
int32_t walReadVer(SWalReader *pRead, int64_t ver);
|
||||
int32_t walReadSeekVer(SWalReader *pRead, int64_t ver);
|
||||
int32_t walNextValidMsg(SWalReader *pRead);
|
||||
int64_t walReaderGetCurrentVer(const SWalReader* pReader);
|
||||
|
||||
// only for tq usage
|
||||
void walSetReaderCapacity(SWalReader *pRead, int32_t capacity);
|
||||
|
|
|
@ -242,6 +242,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_INVALID_ALTER_OPER TAOS_DEF_ERROR_CODE(0, 0x0356)
|
||||
#define TSDB_CODE_MND_AUTH_FAILURE TAOS_DEF_ERROR_CODE(0, 0x0357)
|
||||
#define TSDB_CODE_MND_USER_NOT_AVAILABLE TAOS_DEF_ERROR_CODE(0, 0x0358)
|
||||
#define TSDB_CODE_MND_PRIVILEDGE_EXIST TAOS_DEF_ERROR_CODE(0, 0x0359)
|
||||
|
||||
// mnode-stable-part1
|
||||
#define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
|
@ -762,6 +763,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_TMQ_INVALID_MSG TAOS_DEF_ERROR_CODE(0, 0x4000)
|
||||
#define TSDB_CODE_TMQ_CONSUMER_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x4001)
|
||||
#define TSDB_CODE_TMQ_CONSUMER_CLOSED TAOS_DEF_ERROR_CODE(0, 0x4002)
|
||||
#define TSDB_CODE_TMQ_CONSUMER_ERROR TAOS_DEF_ERROR_CODE(0, 0x4003)
|
||||
|
||||
// stream
|
||||
#define TSDB_CODE_STREAM_TASK_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x4100)
|
||||
|
|
|
@ -198,6 +198,7 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_STREAM_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_DB_NAME_LEN 65
|
||||
#define TSDB_DB_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
#define TSDB_PRIVILEDGE_CONDITION_LEN 200
|
||||
|
||||
#define TSDB_FUNC_NAME_LEN 65
|
||||
#define TSDB_FUNC_COMMENT_LEN 1024 * 1024
|
||||
|
|
|
@ -61,7 +61,7 @@ typedef void (*FItems)(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfItems);
|
|||
|
||||
typedef struct STaosQnode STaosQnode;
|
||||
|
||||
typedef struct STaosQnode {
|
||||
struct STaosQnode {
|
||||
STaosQnode *next;
|
||||
STaosQueue *queue;
|
||||
int64_t timestamp;
|
||||
|
@ -70,9 +70,9 @@ typedef struct STaosQnode {
|
|||
int8_t itype;
|
||||
int8_t reserved[3];
|
||||
char item[];
|
||||
} STaosQnode;
|
||||
};
|
||||
|
||||
typedef struct STaosQueue {
|
||||
struct STaosQueue {
|
||||
STaosQnode *head;
|
||||
STaosQnode *tail;
|
||||
STaosQueue *next; // for queue set
|
||||
|
@ -86,22 +86,22 @@ typedef struct STaosQueue {
|
|||
int64_t threadId;
|
||||
int64_t memLimit;
|
||||
int64_t itemLimit;
|
||||
} STaosQueue;
|
||||
};
|
||||
|
||||
typedef struct STaosQset {
|
||||
struct STaosQset {
|
||||
STaosQueue *head;
|
||||
STaosQueue *current;
|
||||
TdThreadMutex mutex;
|
||||
tsem_t sem;
|
||||
int32_t numOfQueues;
|
||||
int32_t numOfItems;
|
||||
} STaosQset;
|
||||
};
|
||||
|
||||
typedef struct STaosQall {
|
||||
struct STaosQall {
|
||||
STaosQnode *current;
|
||||
STaosQnode *start;
|
||||
int32_t numOfItems;
|
||||
} STaosQall;
|
||||
};
|
||||
|
||||
STaosQueue *taosOpenQueue();
|
||||
void taosCloseQueue(STaosQueue *queue);
|
||||
|
|
|
@ -12,7 +12,7 @@ ENV TINI_VERSION v0.19.0
|
|||
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${cpuType} /tini
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
WORKDIR /root/
|
||||
RUN tar -zxf ${pkgFile} && cd /root/${dirName}/ && /bin/bash install.sh -e no && cd /root && rm /root/${pkgFile} && rm -rf /root/${dirName} && apt-get update && apt-get install -y locales tzdata netcat && locale-gen en_US.UTF-8 && apt-get clean && rm -rf /var/lib/apt/lists/ && chmod +x /tini
|
||||
RUN tar -zxf ${pkgFile} && cd /root/${dirName}/ && /bin/bash install.sh -e no && cd /root && rm /root/${pkgFile} && rm -rf /root/${dirName} && apt-get update && apt-get install -y locales tzdata netcat curl gdb vim tmux less net-tools valgrind && locale-gen en_US.UTF-8 && apt-get clean && rm -rf /var/lib/apt/lists/ && chmod +x /tini
|
||||
|
||||
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib" \
|
||||
LC_CTYPE=en_US.UTF-8 \
|
||||
|
|
|
@ -572,6 +572,22 @@ function install_config() {
|
|||
done
|
||||
}
|
||||
|
||||
function install_share_etc() {
|
||||
[ ! -d ${script_dir}/share/etc ] && return
|
||||
for c in `ls ${script_dir}/share/etc/`; do
|
||||
if [ -e /etc/${clientName2}/$c ]; then
|
||||
out=/etc/${clientName2}/$c.new.`date +%F`
|
||||
${csudo}cp -f ${script_dir}/share/etc/$c $out ||:
|
||||
else
|
||||
${csudo}mkdir -p /etc/${clientName2} >/dev/null 2>/dev/null ||:
|
||||
${csudo}cp -f ${script_dir}/share/etc/$c /etc/${clientName2}/$c ||:
|
||||
fi
|
||||
done
|
||||
|
||||
[ ! -d ${script_dir}/share/srv ] && return
|
||||
${csudo} cp ${script_dir}/share/srv/* ${service_config_dir} ||:
|
||||
}
|
||||
|
||||
function install_log() {
|
||||
${csudo}rm -rf ${log_dir} || :
|
||||
${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
|
||||
|
@ -599,7 +615,7 @@ function install_examples() {
|
|||
|
||||
function install_web() {
|
||||
if [ -d "${script_dir}/share" ]; then
|
||||
${csudo}cp -rf ${script_dir}/share/* ${install_main_dir}/share
|
||||
${csudo}cp -rf ${script_dir}/share/* ${install_main_dir}/share > /dev/null 2>&1 ||:
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -687,11 +703,33 @@ function clean_service_on_systemd() {
|
|||
# if [ "$verMode" == "cluster" ] && [ "$clientName" != "$clientName2" ]; then
|
||||
# ${csudo}rm -f ${service_config_dir}/${serverName2}.service
|
||||
# fi
|
||||
x_service_config="${service_config_dir}/${xName2}.service"
|
||||
if [ -e "$x_service_config" ]; then
|
||||
if systemctl is-active --quiet ${xName2}; then
|
||||
echo "${productName2} ${xName2} is running, stopping it..."
|
||||
${csudo}systemctl stop ${xName2} &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable ${xName2} &>/dev/null || echo &>/dev/null
|
||||
${csudo}rm -f ${x_service_config}
|
||||
fi
|
||||
|
||||
explorer_service_config="${service_config_dir}/${explorerName2}.service"
|
||||
if [ -e "$explorer_service_config" ]; then
|
||||
if systemctl is-active --quiet ${explorerName2}; then
|
||||
echo "${productName2} ${explorerName2} is running, stopping it..."
|
||||
${csudo}systemctl stop ${explorerName2} &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable ${explorerName2} &>/dev/null || echo &>/dev/null
|
||||
${csudo}rm -f ${explorer_service_config}
|
||||
${csudo}rm -f /etc/${clientName2}/explorer.toml
|
||||
fi
|
||||
}
|
||||
|
||||
function install_service_on_systemd() {
|
||||
clean_service_on_systemd
|
||||
|
||||
install_share_etc
|
||||
|
||||
[ -f ${script_dir}/cfg/${serverName2}.service ] &&
|
||||
${csudo}cp ${script_dir}/cfg/${serverName2}.service \
|
||||
${service_config_dir}/ || :
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
TDengine is an open-source, cloud-native time-series database optimized for Internet of Things (IoT), Connected Cars, and Industrial IoT. With its built-in caching, stream processing, and data subscription capabilities, TDengine offers a simplified solution for time-series data processing.
|
||||
|
||||
To configure TDengine : edit /etc/taos/taos.cfg
|
||||
To start service : launchctl start com.tdengine.taosd
|
||||
To start Taos Adapter : launchctl start com.tdengine.taosadapter
|
||||
To access TDengine : use taos in shell
|
||||
• To configure TDengine, edit /etc/taos/taos.cfg
|
||||
• To start service, run launchctl start com.tdengine.taosd
|
||||
• To start Taos Adapter, run launchctl start com.tdengine.taosadapter
|
||||
• To access TDengine from your local machine, run taos
|
||||
|
||||
If you're experiencing problems installing TDengine, check the file /var/log/taos/tdengine_install.log to help troubleshoot the installation.
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
TDengine is an open-source, cloud-native time-series database optimized for Internet of Things (IoT), Connected Cars, and Industrial IoT. With its built-in caching, stream processing, and data subscription capabilities, TDengine offers a simplified solution for time-series data processing.
|
||||
|
||||
Once it's installed, please take the steps below:
|
||||
1: open a terminal/shell in Mac
|
||||
2: if connecting to Cloud Service, follow the instructions on your cloud service account and configure the environment variable
|
||||
3: if connecting to another TDengine Service, you can also view help information via "taos --help"
|
||||
4: execute command taos
|
||||
After the installation process is complete, perform the following steps to start using TDengine:
|
||||
1: Open Terminal on your Mac.
|
||||
2: To connect to a TDengine server using the default settings and credentials, run the taos command.
|
||||
3: To connect to a TDengine server using custom settings or credentials, run taos --help for more information.
|
||||
4: To connect to TDengine Cloud, follow the instructions on the Tools - TDengine CLI page in your TDengine Cloud account.
|
||||
|
||||
If you're experiencing problems installing TDengine, check the file /var/log/taos/tdengine_install.log to help troubleshoot the installation.
|
||||
If any issues occur during installation, check the /var/log/taos/tdengine_install.log file to troubleshoot.
|
|
@ -51,11 +51,9 @@ fi
|
|||
|
||||
if [ -d ${top_dir}/tools/taos-tools/packaging/deb ]; then
|
||||
cd ${top_dir}/tools/taos-tools/packaging/deb
|
||||
|
||||
taostools_ver=$(git for-each-ref --sort=taggerdate --format '%(tag)' refs/tags|grep -v taos | tail -1)
|
||||
[ -z "$taos_tools_ver" ] && taos_tools_ver="0.1.0"
|
||||
|
||||
taostools_ver=$(git for-each-ref --sort=taggerdate --format '%(tag)' refs/tags|grep -v taos | tail -1)
|
||||
[ -z "$taostools_ver" ] && taostools_ver="0.1.0"
|
||||
taostools_install_dir="${release_dir}/${clientName2}Tools-${taostools_ver}"
|
||||
|
||||
cd ${curr_dir}
|
||||
|
@ -152,6 +150,7 @@ fi
|
|||
mkdir -p ${install_dir}/bin && cp ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/* || :
|
||||
mkdir -p ${install_dir}/init.d && cp ${init_file_deb} ${install_dir}/init.d/${serverName}.deb
|
||||
mkdir -p ${install_dir}/init.d && cp ${init_file_rpm} ${install_dir}/init.d/${serverName}.rpm
|
||||
mkdir -p ${install_dir}/share && cp -rf ${build_dir}/share/{etc,srv} ${install_dir}/share ||:
|
||||
|
||||
if [ $adapterName != "taosadapter" ]; then
|
||||
mv ${install_dir}/cfg/${clientName2}adapter.toml ${install_dir}/cfg/$adapterName.toml
|
||||
|
|
|
@ -192,7 +192,27 @@ function clean_service_on_systemd() {
|
|||
${csudo}systemctl stop ${tarbitrator_service_name} &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable ${tarbitrator_service_name} &>/dev/null || echo &>/dev/null
|
||||
${csudo}rm -f ${tarbitratord_service_config}
|
||||
|
||||
x_service_config="${service_config_dir}/${xName2}.service"
|
||||
if [ -e "$x_service_config" ]; then
|
||||
if systemctl is-active --quiet ${xName2}; then
|
||||
echo "${productName2} ${xName2} is running, stopping it..."
|
||||
${csudo}systemctl stop ${xName2} &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable ${xName2} &>/dev/null || echo &>/dev/null
|
||||
${csudo}rm -f ${x_service_config}
|
||||
fi
|
||||
|
||||
explorer_service_config="${service_config_dir}/${explorerName2}.service"
|
||||
if [ -e "$explorer_service_config" ]; then
|
||||
if systemctl is-active --quiet ${explorerName2}; then
|
||||
echo "${productName2} ${explorerName2} is running, stopping it..."
|
||||
${csudo}systemctl stop ${explorerName2} &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable ${explorerName2} &>/dev/null || echo &>/dev/null
|
||||
${csudo}rm -f ${explorer_service_config}
|
||||
${csudo}rm -f /etc/${clientName2}/explorer.toml
|
||||
fi
|
||||
}
|
||||
|
||||
function clean_service_on_sysvinit() {
|
||||
|
|
|
@ -36,14 +36,6 @@ extern "C" {
|
|||
|
||||
#include "tconfig.h"
|
||||
|
||||
#define CHECK_CODE_GOTO(expr, label) \
|
||||
do { \
|
||||
code = expr; \
|
||||
if (TSDB_CODE_SUCCESS != code) { \
|
||||
goto label; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ERROR_MSG_BUF_DEFAULT_SIZE 512
|
||||
#define HEARTBEAT_INTERVAL 1500 // ms
|
||||
|
||||
|
@ -286,28 +278,7 @@ static FORCE_INLINE SReqResultInfo* tmqGetCurResInfo(TAOS_RES* res) {
|
|||
return (SReqResultInfo*)&msg->resInfo;
|
||||
}
|
||||
|
||||
static FORCE_INLINE SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res, bool convertUcs4) {
|
||||
SMqRspObj* pRspObj = (SMqRspObj*)res;
|
||||
pRspObj->resIter++;
|
||||
|
||||
if (pRspObj->resIter < pRspObj->rsp.blockNum) {
|
||||
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(pRspObj->rsp.blockData, pRspObj->resIter);
|
||||
if (pRspObj->rsp.withSchema) {
|
||||
SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(pRspObj->rsp.blockSchema, pRspObj->resIter);
|
||||
setResSchemaInfo(&pRspObj->resInfo, pSW->pSchema, pSW->nCols);
|
||||
taosMemoryFreeClear(pRspObj->resInfo.row);
|
||||
taosMemoryFreeClear(pRspObj->resInfo.pCol);
|
||||
taosMemoryFreeClear(pRspObj->resInfo.length);
|
||||
taosMemoryFreeClear(pRspObj->resInfo.convertBuf);
|
||||
taosMemoryFreeClear(pRspObj->resInfo.convertJson);
|
||||
}
|
||||
|
||||
setQueryResultFromRsp(&pRspObj->resInfo, pRetrieve, convertUcs4, false);
|
||||
return &pRspObj->resInfo;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res, bool convertUcs4);
|
||||
|
||||
static FORCE_INLINE SReqResultInfo* tscGetCurResInfo(TAOS_RES* res) {
|
||||
if (TD_RES_QUERY(res)) return &(((SRequestObj*)res)->body.resInfo);
|
||||
|
@ -320,7 +291,6 @@ extern int32_t clientConnRefPool;
|
|||
extern int32_t timestampDeltaLimit;
|
||||
extern int64_t lastClusterId;
|
||||
|
||||
|
||||
__async_send_cb_fn_t getMsgRspHandle(int32_t msgType);
|
||||
|
||||
SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pReqObj);
|
||||
|
@ -373,7 +343,6 @@ void taos_close_internal(void* taos);
|
|||
// global, called by mgmt
|
||||
int hbMgrInit();
|
||||
void hbMgrCleanUp();
|
||||
int hbHandleRsp(SClientHbBatchRsp* hbRsp);
|
||||
|
||||
// cluster level
|
||||
SAppHbMgr* appHbMgrInit(SAppInstInfo* pAppInstInfo, char* key);
|
||||
|
@ -386,9 +355,6 @@ void stopAllRequests(SHashObj* pRequests);
|
|||
int hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType);
|
||||
void hbDeregisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey);
|
||||
|
||||
// --- mq
|
||||
void hbMgrInitMqHbRspHandle();
|
||||
|
||||
typedef struct SSqlCallbackWrapper {
|
||||
SParseContext* pParseCtx;
|
||||
SCatalogReq* pCatalogReq;
|
||||
|
|
|
@ -26,6 +26,7 @@ extern "C" {
|
|||
#define tscFatal(...) do { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", DEBUG_FATAL, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscError(...) do { if (cDebugFlag & DEBUG_ERROR) { taosPrintLog("TSC ERROR ", DEBUG_ERROR, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscWarn(...) do { if (cDebugFlag & DEBUG_WARN) { taosPrintLog("TSC WARN ", DEBUG_WARN, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscWarnL(...) do { if (cDebugFlag & DEBUG_WARN) { taosPrintLongString("TSC WARN ", DEBUG_WARN, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscInfo(...) do { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", DEBUG_INFO, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscDebug(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC ", DEBUG_DEBUG, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define tscTrace(...) do { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", DEBUG_TRACE, cDebugFlag, __VA_ARGS__); }} while(0)
|
||||
|
|
|
@ -102,6 +102,7 @@ typedef struct STscStmt {
|
|||
SStmtBindInfo bInfo;
|
||||
|
||||
int64_t reqid;
|
||||
int32_t errCode;
|
||||
} STscStmt;
|
||||
|
||||
extern char *gStmtStatusStr[];
|
||||
|
@ -121,6 +122,7 @@ extern char *gStmtStatusStr[];
|
|||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
pStmt->errCode = _code; \
|
||||
return _code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
@ -129,6 +131,7 @@ extern char *gStmtStatusStr[];
|
|||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
pStmt->errCode = _code; \
|
||||
} \
|
||||
return _code; \
|
||||
} while (0)
|
||||
|
@ -137,9 +140,19 @@ extern char *gStmtStatusStr[];
|
|||
code = c; \
|
||||
if (code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = code; \
|
||||
pStmt->errCode = code; \
|
||||
goto _return; \
|
||||
} \
|
||||
} while (0)
|
||||
#define STMT_ERRI_JRET(c) \
|
||||
do { \
|
||||
code = c; \
|
||||
if (code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = code; \
|
||||
goto _return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define STMT_ELOG(param, ...) qError("stmt:%p " param, pStmt, __VA_ARGS__)
|
||||
#define STMT_DLOG(param, ...) qDebug("stmt:%p " param, pStmt, __VA_ARGS__)
|
||||
|
|
|
@ -107,6 +107,7 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
|||
|
||||
if (duration >= SLOW_QUERY_INTERVAL) {
|
||||
atomic_add_fetch_64((int64_t *)&pActivity->numOfSlowQueries, 1);
|
||||
tscWarnL("slow query: %s, duration:%" PRId64, pRequest->sqlstr, duration);
|
||||
}
|
||||
|
||||
releaseTscObj(pTscObj->id);
|
||||
|
|
|
@ -1039,8 +1039,7 @@ static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaDat
|
|||
.sysInfo = pRequest->pTscObj->sysInfo,
|
||||
.allocatorId = pRequest->allocatorRefId};
|
||||
|
||||
SAppInstInfo* pAppInfo = getAppInfo(pRequest);
|
||||
SQueryPlan* pDag = NULL;
|
||||
SQueryPlan* pDag = NULL;
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
int32_t code = qCreateQueryPlan(&cxt, &pDag, pMnodeList);
|
||||
|
@ -1052,7 +1051,6 @@ static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaDat
|
|||
}
|
||||
|
||||
pRequest->metric.execStart = taosGetTimestampUs();
|
||||
|
||||
pRequest->metric.planCostUs = pRequest->metric.execStart - st;
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && !pRequest->validateOnly) {
|
||||
|
|
|
@ -174,6 +174,7 @@ static int32_t smlParseTableName(SArray *tags, char *childTableName) {
|
|||
if (childTableNameLen == tag->keyLen && strncmp(tag->key, tsSmlChildTableName, tag->keyLen) == 0) {
|
||||
memset(childTableName, 0, TSDB_TABLE_NAME_LEN);
|
||||
strncpy(childTableName, tag->value, (tag->length < TSDB_TABLE_NAME_LEN ? tag->length : TSDB_TABLE_NAME_LEN));
|
||||
taosArrayRemove(tags, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -533,8 +534,7 @@ static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSm
|
|||
uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
|
||||
if (index) {
|
||||
if (colField[*index].type != kv->type) {
|
||||
uError("SML:0x%" PRIx64 " point type and db type mismatch. key: %s. point type: %d, db type: %d", info->id,
|
||||
kv->key, colField[*index].type, kv->type);
|
||||
uError("SML:0x%" PRIx64 " point type and db type mismatch. point type: %d, db type: %d, key: %s", info->id, colField[*index].type, kv->type, kv->key);
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
|
||||
|
@ -699,7 +699,7 @@ static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns,
|
|||
pReq.numOfTags = 1;
|
||||
SField field = {0};
|
||||
field.type = TSDB_DATA_TYPE_NCHAR;
|
||||
field.bytes = 1;
|
||||
field.bytes = TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
|
||||
strcpy(field.name, tsSmlTagName);
|
||||
taosArrayPush(pReq.pTags, &field);
|
||||
}
|
||||
|
|
|
@ -32,8 +32,14 @@ int32_t stmtSwitchStatus(STscStmt* pStmt, STMT_STATUS newStatus) {
|
|||
STMT_LOG_SEQ(newStatus);
|
||||
}
|
||||
|
||||
if (pStmt->errCode && newStatus != STMT_PREPARE) {
|
||||
STMT_DLOG("stmt already failed with err: %s", tstrerror(pStmt->errCode));
|
||||
return pStmt->errCode;
|
||||
}
|
||||
|
||||
switch (newStatus) {
|
||||
case STMT_PREPARE:
|
||||
pStmt->errCode = 0;
|
||||
break;
|
||||
case STMT_SETTBNAME:
|
||||
if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND) || STMT_STATUS_EQ(BIND_COL)) {
|
||||
|
@ -197,7 +203,10 @@ int32_t stmtGetExecInfo(TAOS_STMT* stmt, SHashObj** pVgHash, SHashObj** pBlockHa
|
|||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
*pVgHash = pStmt->sql.pVgHash;
|
||||
pStmt->sql.pVgHash = NULL;
|
||||
|
||||
*pBlockHash = pStmt->exec.pBlockHash;
|
||||
pStmt->exec.pBlockHash = NULL;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -325,6 +334,8 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable, bool deepClean) {
|
|||
}
|
||||
|
||||
int32_t stmtCleanSQLInfo(STscStmt* pStmt) {
|
||||
STMT_DLOG_E("start to free SQL info");
|
||||
|
||||
taosMemoryFree(pStmt->sql.queryRes.fields);
|
||||
taosMemoryFree(pStmt->sql.queryRes.userFields);
|
||||
taosMemoryFree(pStmt->sql.sqlStr);
|
||||
|
@ -351,6 +362,8 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) {
|
|||
|
||||
memset(&pStmt->sql, 0, sizeof(pStmt->sql));
|
||||
|
||||
STMT_DLOG_E("end to free SQL info");
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -441,11 +454,10 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
|
|||
.mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)};
|
||||
int32_t code = catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta);
|
||||
if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) {
|
||||
STMT_ERR_RET(stmtCleanBindInfo(pStmt));
|
||||
|
||||
tscDebug("tb %s not exist", pStmt->bInfo.tbFName);
|
||||
stmtCleanBindInfo(pStmt);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
STMT_ERR_RET(code);
|
||||
}
|
||||
|
||||
STMT_ERR_RET(code);
|
||||
|
@ -922,9 +934,13 @@ _return:
|
|||
int stmtClose(TAOS_STMT* stmt) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
STMT_DLOG_E("start to free stmt");
|
||||
|
||||
stmtCleanSQLInfo(pStmt);
|
||||
taosMemoryFree(stmt);
|
||||
|
||||
STMT_DLOG_E("stmt freed");
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -959,15 +975,17 @@ int stmtIsInsert(TAOS_STMT* stmt, int* insert) {
|
|||
}
|
||||
|
||||
int stmtGetTagFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) {
|
||||
int32_t code = 0;
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
int32_t preCode = pStmt->errCode;
|
||||
|
||||
STMT_DLOG_E("start to get tag fields");
|
||||
|
||||
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
||||
STMT_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||
STMT_ERRI_JRET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||
}
|
||||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS));
|
||||
STMT_ERRI_JRET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS));
|
||||
|
||||
if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
|
||||
STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
|
||||
|
@ -979,27 +997,33 @@ int stmtGetTagFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) {
|
|||
pStmt->exec.pRequest = NULL;
|
||||
}
|
||||
|
||||
STMT_ERR_RET(stmtCreateRequest(pStmt));
|
||||
STMT_ERRI_JRET(stmtCreateRequest(pStmt));
|
||||
|
||||
if (pStmt->bInfo.needParse) {
|
||||
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||
STMT_ERRI_JRET(stmtParseSql(pStmt));
|
||||
}
|
||||
|
||||
STMT_ERR_RET(stmtFetchTagFields(stmt, nums, fields));
|
||||
STMT_ERRI_JRET(stmtFetchTagFields(stmt, nums, fields));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_return:
|
||||
|
||||
pStmt->errCode = preCode;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int stmtGetColFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) {
|
||||
int32_t code = 0;
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
int32_t preCode = pStmt->errCode;
|
||||
|
||||
STMT_DLOG_E("start to get col fields");
|
||||
|
||||
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
||||
STMT_RET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||
STMT_ERRI_JRET(TSDB_CODE_TSC_STMT_API_ERROR);
|
||||
}
|
||||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS));
|
||||
STMT_ERRI_JRET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS));
|
||||
|
||||
if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
|
||||
STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
|
||||
|
@ -1011,15 +1035,19 @@ int stmtGetColFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) {
|
|||
pStmt->exec.pRequest = NULL;
|
||||
}
|
||||
|
||||
STMT_ERR_RET(stmtCreateRequest(pStmt));
|
||||
STMT_ERRI_JRET(stmtCreateRequest(pStmt));
|
||||
|
||||
if (pStmt->bInfo.needParse) {
|
||||
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||
STMT_ERRI_JRET(stmtParseSql(pStmt));
|
||||
}
|
||||
|
||||
STMT_ERR_RET(stmtFetchColFields(stmt, nums, fields));
|
||||
STMT_ERRI_JRET(stmtFetchColFields(stmt, nums, fields));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_return:
|
||||
|
||||
pStmt->errCode = preCode;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int stmtGetParamNum(TAOS_STMT* stmt, int* nums) {
|
||||
|
|
|
@ -98,17 +98,16 @@ struct tmq_t {
|
|||
int64_t totalRows;
|
||||
|
||||
// timer
|
||||
tmr_h hbLiveTimer;
|
||||
tmr_h epTimer;
|
||||
tmr_h reportTimer;
|
||||
tmr_h commitTimer;
|
||||
STscObj* pTscObj; // connection
|
||||
SArray* clientTopics; // SArray<SMqClientTopic>
|
||||
STaosQueue* mqueue; // queue of rsp
|
||||
STaosQall* qall;
|
||||
STaosQueue* delayedTask; // delayed task queue for heartbeat and auto commit
|
||||
TdThreadMutex lock; // used to protect the operation on each topic, when updating the epsets.
|
||||
tsem_t rspSem;
|
||||
tmr_h hbLiveTimer;
|
||||
tmr_h epTimer;
|
||||
tmr_h reportTimer;
|
||||
tmr_h commitTimer;
|
||||
STscObj* pTscObj; // connection
|
||||
SArray* clientTopics; // SArray<SMqClientTopic>
|
||||
STaosQueue* mqueue; // queue of rsp
|
||||
STaosQall* qall;
|
||||
STaosQueue* delayedTask; // delayed task queue for heartbeat and auto commit
|
||||
tsem_t rspSem;
|
||||
};
|
||||
|
||||
typedef struct SAskEpInfo {
|
||||
|
@ -188,7 +187,6 @@ typedef struct {
|
|||
SMqClientVg* pVg;
|
||||
SMqClientTopic* pTopic;
|
||||
int32_t vgId;
|
||||
tsem_t rspSem;
|
||||
uint64_t requestId; // request id for debug purpose
|
||||
} SMqPollCbParam;
|
||||
|
||||
|
@ -212,6 +210,11 @@ typedef struct {
|
|||
tmq_t* pTmq;
|
||||
} SMqCommitCbParam;
|
||||
|
||||
typedef struct SSyncCommitInfo {
|
||||
tsem_t sem;
|
||||
int32_t code;
|
||||
} SSyncCommitInfo;
|
||||
|
||||
static int32_t doAskEp(tmq_t* tmq);
|
||||
static int32_t makeTopicVgroupKey(char* dst, const char* topicName, int32_t vg);
|
||||
static int32_t tmqCommitDone(SMqCommitCbParamSet* pParamSet);
|
||||
|
@ -523,11 +526,7 @@ static int32_t doSendCommitMsg(tmq_t* tmq, SMqClientVg* pVg, const char* pTopicN
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pMsgSendInfo->msgInfo = (SDataBuf){
|
||||
.pData = buf,
|
||||
.len = sizeof(SMsgHead) + len,
|
||||
.handle = NULL,
|
||||
};
|
||||
pMsgSendInfo->msgInfo = (SDataBuf) { .pData = buf, .len = sizeof(SMsgHead) + len, .handle = NULL };
|
||||
|
||||
pMsgSendInfo->requestId = generateRequestId();
|
||||
pMsgSendInfo->requestObjRefId = 0;
|
||||
|
@ -788,11 +787,7 @@ void tmqSendHbReq(void* param, void* tmrId) {
|
|||
goto OVER;
|
||||
}
|
||||
|
||||
sendInfo->msgInfo = (SDataBuf){
|
||||
.pData = pReq,
|
||||
.len = tlen,
|
||||
.handle = NULL,
|
||||
};
|
||||
sendInfo->msgInfo = (SDataBuf){ .pData = pReq, .len = tlen, .handle = NULL };
|
||||
|
||||
sendInfo->requestId = generateRequestId();
|
||||
sendInfo->requestObjRefId = 0;
|
||||
|
@ -979,7 +974,6 @@ void tmqFreeImpl(void* handle) {
|
|||
|
||||
taosFreeQall(tmq->qall);
|
||||
tsem_destroy(&tmq->rspSem);
|
||||
taosThreadMutexDestroy(&tmq->lock);
|
||||
|
||||
taosArrayDestroyEx(tmq->clientTopics, freeClientVgImpl);
|
||||
taos_close_internal(tmq->pTscObj);
|
||||
|
@ -1024,7 +1018,6 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
|||
pTmq->delayedTask = taosOpenQueue();
|
||||
pTmq->qall = taosAllocateQall();
|
||||
|
||||
taosThreadMutexInit(&pTmq->lock, NULL);
|
||||
if (pTmq->clientTopics == NULL || pTmq->mqueue == NULL || pTmq->qall == NULL || pTmq->delayedTask == NULL ||
|
||||
conf->groupId[0] == 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -1155,6 +1148,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
};
|
||||
|
||||
if (tsem_init(¶m.rspSem, 0, 0) != 0) {
|
||||
code = TSDB_CODE_TSC_INTERNAL_ERROR;
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
@ -1190,6 +1184,8 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
|||
int32_t retryCnt = 0;
|
||||
while (TSDB_CODE_MND_CONSUMER_NOT_READY == doAskEp(tmq)) {
|
||||
if (retryCnt++ > MAX_RETRY_COUNT) {
|
||||
tscError("consumer:0x%" PRIx64 ", mnd not ready for subscribe, retry:%d in 500ms", tmq->consumerId, retryCnt);
|
||||
code = TSDB_CODE_TSC_INTERNAL_ERROR;
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
|
@ -1233,7 +1229,6 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
|
||||
tmq_t* tmq = taosAcquireRef(tmqMgmt.rsetId, refId);
|
||||
if (tmq == NULL) {
|
||||
tsem_destroy(&pParam->rspSem);
|
||||
taosMemoryFree(pParam);
|
||||
taosMemoryFree(pMsg->pData);
|
||||
taosMemoryFree(pMsg->pEpSet);
|
||||
|
@ -1270,6 +1265,8 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
|
||||
pRspWrapper->tmqRspType = TMQ_MSG_TYPE__END_RSP;
|
||||
taosWriteQitem(tmq->mqueue, pRspWrapper);
|
||||
} else if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) { // poll data while insert
|
||||
taosMsleep(500);
|
||||
}
|
||||
|
||||
goto CREATE_MSG_FAIL;
|
||||
|
@ -1346,8 +1343,9 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
taosMemoryFree(pMsg->pData);
|
||||
taosWriteQitem(tmq->mqueue, pRspWrapper);
|
||||
|
||||
int32_t total = taosQueueItemSize(tmq->mqueue);
|
||||
tscDebug("consumer:0x%" PRIx64 " put poll res into mqueue, type:%d, vgId:%d, total in queue:%d, reqId:0x%" PRIx64,
|
||||
tmq->consumerId, rspType, vgId, tmq->mqueue->numOfItems, requestId);
|
||||
tmq->consumerId, rspType, vgId, total, requestId);
|
||||
|
||||
tsem_post(&tmq->rspSem);
|
||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||
|
@ -1422,7 +1420,7 @@ static void freeClientVgInfo(void* param) {
|
|||
taosArrayDestroy(pTopic->vgs);
|
||||
}
|
||||
|
||||
static bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) {
|
||||
static bool doUpdateLocalEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) {
|
||||
bool set = false;
|
||||
|
||||
int32_t topicNumCur = taosArrayGetSize(tmq->clientTopics);
|
||||
|
@ -1431,6 +1429,9 @@ static bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) {
|
|||
char vgKey[TSDB_TOPIC_FNAME_LEN + 22];
|
||||
tscDebug("consumer:0x%" PRIx64 " update ep epoch from %d to epoch %d, incoming topics:%d, existed topics:%d",
|
||||
tmq->consumerId, tmq->epoch, epoch, topicNumGet, topicNumCur);
|
||||
if (epoch <= tmq->epoch) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SArray* newTopics = taosArrayInit(topicNumGet, sizeof(SMqClientTopic));
|
||||
if (newTopics == NULL) {
|
||||
|
@ -1474,14 +1475,11 @@ static bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) {
|
|||
|
||||
taosHashCleanup(pVgOffsetHashMap);
|
||||
|
||||
taosThreadMutexLock(&tmq->lock);
|
||||
// destroy current buffered existed topics info
|
||||
if (tmq->clientTopics) {
|
||||
taosArrayDestroyEx(tmq->clientTopics, freeClientVgInfo);
|
||||
}
|
||||
|
||||
tmq->clientTopics = newTopics;
|
||||
taosThreadMutexUnlock(&tmq->lock);
|
||||
|
||||
int8_t flag = (topicNumGet == 0) ? TMQ_CONSUMER_STATUS__NO_TOPIC : TMQ_CONSUMER_STATUS__READY;
|
||||
atomic_store_8(&tmq->status, flag);
|
||||
|
@ -1537,8 +1535,8 @@ int32_t askEpCallbackFn(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
} else {
|
||||
tscDebug("consumer:0x%" PRIx64 ", recv ep, msg epoch %d, current epoch %d, update local ep", tmq->consumerId,
|
||||
head->epoch, epoch);
|
||||
pParam->pUserFn(tmq, code, pMsg, pParam->pParam);
|
||||
}
|
||||
pParam->pUserFn(tmq, code, pMsg, pParam->pParam);
|
||||
|
||||
taosReleaseRef(tmqMgmt.rsetId, pParam->refId);
|
||||
|
||||
|
@ -1745,7 +1743,7 @@ static int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspWrapper* rspWrapper, bool* p
|
|||
if (rspWrapper->epoch > atomic_load_32(&tmq->epoch)) {
|
||||
SMqAskEpRspWrapper* pEpRspWrapper = (SMqAskEpRspWrapper*)rspWrapper;
|
||||
SMqAskEpRsp* rspMsg = &pEpRspWrapper->msg;
|
||||
tmqUpdateEp(tmq, rspWrapper->epoch, rspMsg);
|
||||
doUpdateLocalEp(tmq, rspWrapper->epoch, rspMsg);
|
||||
/*tmqClearUnhandleMsg(tmq);*/
|
||||
tDeleteSMqAskEpRsp(rspMsg);
|
||||
*pReset = true;
|
||||
|
@ -2125,13 +2123,8 @@ void tmq_commit_async(tmq_t* tmq, const TAOS_RES* pRes, tmq_commit_cb* cb, void*
|
|||
}
|
||||
}
|
||||
|
||||
typedef struct SSyncCommitInfo {
|
||||
tsem_t sem;
|
||||
int32_t code;
|
||||
} SSyncCommitInfo;
|
||||
|
||||
static void commitCallBackFn(tmq_t* pTmq, int32_t code, void* param) {
|
||||
SSyncCommitInfo* pInfo = (SSyncCommitInfo*)param;
|
||||
static void commitCallBackFn(tmq_t *pTmq, int32_t code, void* param) {
|
||||
SSyncCommitInfo* pInfo = (SSyncCommitInfo*) param;
|
||||
pInfo->code = code;
|
||||
tsem_post(&pInfo->sem);
|
||||
}
|
||||
|
@ -2168,7 +2161,7 @@ void updateEpCallbackFn(tmq_t* pTmq, int32_t code, SDataBuf* pDataBuf, void* par
|
|||
|
||||
SMqAskEpRsp rsp;
|
||||
tDecodeSMqAskEpRsp(POINTER_SHIFT(pDataBuf->pData, sizeof(SMqRspHead)), &rsp);
|
||||
tmqUpdateEp(pTmq, head->epoch, &rsp);
|
||||
doUpdateLocalEp(pTmq, head->epoch, &rsp);
|
||||
tDeleteSMqAskEpRsp(&rsp);
|
||||
}
|
||||
|
||||
|
@ -2308,3 +2301,26 @@ void commitRspCountDown(SMqCommitCbParamSet* pParamSet, int64_t consumerId, cons
|
|||
waitingRspNum);
|
||||
}
|
||||
}
|
||||
|
||||
SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res, bool convertUcs4) {
|
||||
SMqRspObj* pRspObj = (SMqRspObj*)res;
|
||||
pRspObj->resIter++;
|
||||
|
||||
if (pRspObj->resIter < pRspObj->rsp.blockNum) {
|
||||
SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(pRspObj->rsp.blockData, pRspObj->resIter);
|
||||
if (pRspObj->rsp.withSchema) {
|
||||
SSchemaWrapper* pSW = (SSchemaWrapper*)taosArrayGetP(pRspObj->rsp.blockSchema, pRspObj->resIter);
|
||||
setResSchemaInfo(&pRspObj->resInfo, pSW->pSchema, pSW->nCols);
|
||||
taosMemoryFreeClear(pRspObj->resInfo.row);
|
||||
taosMemoryFreeClear(pRspObj->resInfo.pCol);
|
||||
taosMemoryFreeClear(pRspObj->resInfo.length);
|
||||
taosMemoryFreeClear(pRspObj->resInfo.convertBuf);
|
||||
taosMemoryFreeClear(pRspObj->resInfo.convertJson);
|
||||
}
|
||||
|
||||
setQueryResultFromRsp(&pRspObj->resInfo, pRetrieve, convertUcs4, false);
|
||||
return &pRspObj->resInfo;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
|
@ -162,9 +162,11 @@ void* queryThread(void* arg) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t numOfThreads = 1;
|
||||
int32_t numOfThreads = 1;
|
||||
|
||||
void tmq_commit_cb_print(tmq_t* pTmq, int32_t code, void* param) { printf("success, code:%d\n", code); }
|
||||
void tmq_commit_cb_print(tmq_t* pTmq, int32_t code, void* param) {
|
||||
printf("auto commit success, code:%d\n\n\n\n", code);
|
||||
}
|
||||
|
||||
void* doConsumeData(void* param) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
|
@ -172,7 +174,7 @@ void* doConsumeData(void* param) {
|
|||
tmq_conf_t* conf = tmq_conf_new();
|
||||
tmq_conf_set(conf, "enable.auto.commit", "true");
|
||||
tmq_conf_set(conf, "auto.commit.interval.ms", "1000");
|
||||
tmq_conf_set(conf, "group.id", "cgrpName12");
|
||||
tmq_conf_set(conf, "group.id", "cgrpName41");
|
||||
tmq_conf_set(conf, "td.connect.user", "root");
|
||||
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
||||
tmq_conf_set(conf, "auto.offset.reset", "earliest");
|
||||
|
@ -1059,7 +1061,7 @@ TEST(clientCase, sub_tb_test) {
|
|||
tmq_conf_t* conf = tmq_conf_new();
|
||||
tmq_conf_set(conf, "enable.auto.commit", "true");
|
||||
tmq_conf_set(conf, "auto.commit.interval.ms", "1000");
|
||||
tmq_conf_set(conf, "group.id", "cgrpName27");
|
||||
tmq_conf_set(conf, "group.id", "cgrpName45");
|
||||
tmq_conf_set(conf, "td.connect.user", "root");
|
||||
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
||||
tmq_conf_set(conf, "auto.offset.reset", "earliest");
|
||||
|
|
|
@ -299,7 +299,9 @@ static const SSysDbTableSchema vnodesSchema[] = {
|
|||
static const SSysDbTableSchema userUserPrivilegesSchema[] = {
|
||||
{.name = "user_name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "privilege", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "object_name", .bytes = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "db_name", .bytes = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "table_name", .bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "condition", .bytes = TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
};
|
||||
|
||||
static const SSysTableMeta infosMeta[] = {
|
||||
|
|
|
@ -1590,12 +1590,13 @@ static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) {
|
|||
i += 1;
|
||||
}
|
||||
} else if (n > 8) {
|
||||
int32_t gap = len - newLen;
|
||||
int32_t remain = (total % 8 != 0 && total % 8 <= tail) ? 1 : 0;
|
||||
int32_t gap = len - newLen - remain;
|
||||
while (i < newLen) {
|
||||
uint8_t v = p[i + gap];
|
||||
p[i] = (v << tail);
|
||||
|
||||
if (i < newLen - 1) {
|
||||
if (i < newLen - 1 + remain) {
|
||||
uint8_t next = p[i + gap + 1];
|
||||
p[i] |= (next >> (8 - tail));
|
||||
}
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
#include "tlog.h"
|
||||
#include "tmisce.h"
|
||||
|
||||
#if defined(CUS_NAME) || defined(CUS_PROMPT) || defined(CUS_EMAIL)
|
||||
#include "cus_name.h"
|
||||
#endif
|
||||
|
||||
GRANT_CFG_DECLARE;
|
||||
|
||||
SConfig *tsCfg = NULL;
|
||||
|
@ -99,6 +103,7 @@ char tsSmlChildTableName[TSDB_TABLE_NAME_LEN] = ""; // user defined child table
|
|||
// query
|
||||
int32_t tsQueryPolicy = 1;
|
||||
int32_t tsQueryRspPolicy = 0;
|
||||
int64_t tsQueryMaxConcurrentTables = 200; // unit is TSDB_TABLE_NUM_UNIT
|
||||
bool tsEnableQueryHb = false;
|
||||
int32_t tsQuerySmaOptimize = 0;
|
||||
int32_t tsQueryRsmaTolerance = 1000; // the tolerance time (ms) to judge from which level to query rsma data.
|
||||
|
@ -338,6 +343,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
|
|||
if (cfgAddInt32(pCfg, "maxRetryWaitTime", tsMaxRetryWaitTime, 0, 86400000, 0) != 0) return -1;
|
||||
if (cfgAddBool(pCfg, "useAdapter", tsUseAdapter, true) != 0) return -1;
|
||||
if (cfgAddBool(pCfg, "crashReporting", tsEnableCrashReport, true) != 0) return -1;
|
||||
if (cfgAddInt64(pCfg, "queryMaxConcurrentTables", tsQueryMaxConcurrentTables, INT64_MIN, INT64_MAX, 1) != 0) return -1;
|
||||
|
||||
tsNumOfRpcThreads = tsNumOfCores / 2;
|
||||
tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 2, TSDB_MAX_RPC_THREADS);
|
||||
|
@ -735,6 +741,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
|||
tsKeepColumnName = cfgGetItem(pCfg, "keepColumnName")->bval;
|
||||
tsUseAdapter = cfgGetItem(pCfg, "useAdapter")->bval;
|
||||
tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval;
|
||||
tsQueryMaxConcurrentTables = cfgGetItem(pCfg, "queryMaxConcurrentTables")->i64;
|
||||
|
||||
tsMaxRetryWaitTime = cfgGetItem(pCfg, "maxRetryWaitTime")->i32;
|
||||
|
||||
|
|
|
@ -1368,6 +1368,12 @@ int32_t tSerializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq)
|
|||
if (tEncodeCStr(&encoder, pReq->user) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->pass) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->objname) < 0) return -1;
|
||||
int32_t len = strlen(pReq->tabName);
|
||||
if (tEncodeI32(&encoder, len) < 0) return -1;
|
||||
if (len > 0) {
|
||||
if (tEncodeCStr(&encoder, pReq->tabName) < 0) return -1;
|
||||
}
|
||||
if (tEncodeBinary(&encoder, pReq->tagCond, pReq->tagCondLen) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
|
@ -1387,6 +1393,16 @@ int32_t tDeserializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq
|
|||
if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->pass) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->objname) < 0) return -1;
|
||||
if (!tDecodeIsEnd(&decoder)) {
|
||||
int32_t len = 0;
|
||||
if (tDecodeI32(&decoder, &len) < 0) return -1;
|
||||
if (len > 0) {
|
||||
if (tDecodeCStrTo(&decoder, pReq->tabName) < 0) return -1;
|
||||
}
|
||||
uint64_t tagCondLen = 0;
|
||||
if (tDecodeBinaryAlloc(&decoder, (void **)&pReq->tagCond, &tagCondLen) < 0) return -1;
|
||||
pReq->tagCondLen = tagCondLen;
|
||||
}
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
|
@ -1429,6 +1445,7 @@ int32_t tSerializeSGetUserAuthRspImpl(SEncoder *pEncoder, SGetUserAuthRsp *pRsp)
|
|||
int32_t numOfCreatedDbs = taosHashGetSize(pRsp->createdDbs);
|
||||
int32_t numOfReadDbs = taosHashGetSize(pRsp->readDbs);
|
||||
int32_t numOfWriteDbs = taosHashGetSize(pRsp->writeDbs);
|
||||
|
||||
if (tEncodeI32(pEncoder, numOfCreatedDbs) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, numOfReadDbs) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, numOfWriteDbs) < 0) return -1;
|
||||
|
@ -1451,6 +1468,54 @@ int32_t tSerializeSGetUserAuthRspImpl(SEncoder *pEncoder, SGetUserAuthRsp *pRsp)
|
|||
db = taosHashIterate(pRsp->writeDbs, db);
|
||||
}
|
||||
|
||||
int32_t numOfReadTbs = taosHashGetSize(pRsp->readTbs);
|
||||
int32_t numOfWriteTbs = taosHashGetSize(pRsp->writeTbs);
|
||||
int32_t numOfUseTbs = taosHashGetSize(pRsp->useDbs);
|
||||
if (tEncodeI32(pEncoder, numOfReadTbs) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, numOfWriteTbs) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, numOfUseTbs) < 0) return -1;
|
||||
|
||||
char *tb = taosHashIterate(pRsp->readTbs, NULL);
|
||||
while (tb != NULL) {
|
||||
size_t keyLen = 0;
|
||||
void *key = taosHashGetKey(tb, &keyLen);
|
||||
if (tEncodeI32(pEncoder, keyLen) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, key) < 0) return -1;
|
||||
|
||||
size_t valueLen = 0;
|
||||
valueLen = strlen(tb);
|
||||
if (tEncodeI32(pEncoder, valueLen) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, tb) < 0) return -1;
|
||||
|
||||
tb = taosHashIterate(pRsp->readTbs, tb);
|
||||
}
|
||||
|
||||
tb = taosHashIterate(pRsp->writeTbs, NULL);
|
||||
while (tb != NULL) {
|
||||
size_t keyLen = 0;
|
||||
void *key = taosHashGetKey(tb, &keyLen);
|
||||
if (tEncodeI32(pEncoder, keyLen) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, key) < 0) return -1;
|
||||
|
||||
size_t valueLen = 0;
|
||||
valueLen = strlen(tb);
|
||||
if (tEncodeI32(pEncoder, valueLen) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, tb) < 0) return -1;
|
||||
|
||||
tb = taosHashIterate(pRsp->writeTbs, tb);
|
||||
}
|
||||
|
||||
int32_t *useDb = taosHashIterate(pRsp->useDbs, NULL);
|
||||
while (useDb != NULL) {
|
||||
size_t keyLen = 0;
|
||||
void *key = taosHashGetKey(useDb, &keyLen);
|
||||
if (tEncodeI32(pEncoder, keyLen) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, key) < 0) return -1;
|
||||
|
||||
if (tEncodeI32(pEncoder, *useDb) < 0) return -1;
|
||||
useDb = taosHashIterate(pRsp->useDbs, useDb);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1473,7 +1538,11 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs
|
|||
pRsp->createdDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pRsp->readDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pRsp->writeDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (pRsp->readDbs == NULL || pRsp->writeDbs == NULL) {
|
||||
pRsp->readTbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pRsp->writeTbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pRsp->useDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (pRsp->createdDbs == NULL || pRsp->readDbs == NULL || pRsp->writeDbs == NULL || pRsp->readTbs == NULL ||
|
||||
pRsp->writeTbs == NULL || pRsp->useDbs == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1512,6 +1581,63 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs
|
|||
taosHashPut(pRsp->writeDbs, db, len, db, len);
|
||||
}
|
||||
|
||||
if (!tDecodeIsEnd(pDecoder)) {
|
||||
int32_t numOfReadTbs = 0;
|
||||
int32_t numOfWriteTbs = 0;
|
||||
int32_t numOfUseDbs = 0;
|
||||
if (tDecodeI32(pDecoder, &numOfReadTbs) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &numOfWriteTbs) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &numOfUseDbs) < 0) return -1;
|
||||
|
||||
for (int32_t i = 0; i < numOfReadTbs; ++i) {
|
||||
int32_t keyLen = 0;
|
||||
if (tDecodeI32(pDecoder, &keyLen) < 0) return -1;
|
||||
|
||||
char *key = taosMemoryCalloc(keyLen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, key) < 0) return -1;
|
||||
|
||||
int32_t valuelen = 0;
|
||||
if (tDecodeI32(pDecoder, &valuelen) < 0) return -1;
|
||||
char *value = taosMemoryCalloc(valuelen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, value) < 0) return -1;
|
||||
|
||||
taosHashPut(pRsp->readTbs, key, strlen(key), value, valuelen + 1);
|
||||
|
||||
taosMemoryFree(key);
|
||||
taosMemoryFree(value);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfWriteTbs; ++i) {
|
||||
int32_t keyLen = 0;
|
||||
if (tDecodeI32(pDecoder, &keyLen) < 0) return -1;
|
||||
|
||||
char *key = taosMemoryCalloc(keyLen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, key) < 0) return -1;
|
||||
|
||||
int32_t valuelen = 0;
|
||||
if (tDecodeI32(pDecoder, &valuelen) < 0) return -1;
|
||||
char *value = taosMemoryCalloc(valuelen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, value) < 0) return -1;
|
||||
|
||||
taosHashPut(pRsp->writeTbs, key, strlen(key), value, valuelen + 1);
|
||||
|
||||
taosMemoryFree(key);
|
||||
taosMemoryFree(value);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfUseDbs; ++i) {
|
||||
int32_t keyLen = 0;
|
||||
if (tDecodeI32(pDecoder, &keyLen) < 0) return -1;
|
||||
|
||||
char *key = taosMemoryCalloc(keyLen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, key) < 0) return -1;
|
||||
|
||||
int32_t ref = 0;
|
||||
if (tDecodeI32(pDecoder, &ref) < 0) return -1;
|
||||
taosHashPut(pRsp->useDbs, key, strlen(key), &ref, sizeof(ref));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1533,6 +1659,9 @@ void tFreeSGetUserAuthRsp(SGetUserAuthRsp *pRsp) {
|
|||
taosHashCleanup(pRsp->createdDbs);
|
||||
taosHashCleanup(pRsp->readDbs);
|
||||
taosHashCleanup(pRsp->writeDbs);
|
||||
taosHashCleanup(pRsp->writeTbs);
|
||||
taosHashCleanup(pRsp->readTbs);
|
||||
taosHashCleanup(pRsp->useDbs);
|
||||
}
|
||||
|
||||
int32_t tSerializeSCreateDropMQSNodeReq(void *buf, int32_t bufLen, SMCreateQnodeReq *pReq) {
|
||||
|
@ -7317,6 +7446,7 @@ void tDestroySSubmitReq2(SSubmitReq2 *pReq, int32_t flag) {
|
|||
tDestroySSubmitTbData(&aSubmitTbData[i], flag);
|
||||
}
|
||||
taosArrayDestroy(pReq->aSubmitTbData);
|
||||
pReq->aSubmitTbData = NULL;
|
||||
}
|
||||
|
||||
int32_t tEncodeSSubmitRsp2(SEncoder *pCoder, const SSubmitRsp2 *pRsp) {
|
||||
|
|
|
@ -114,11 +114,11 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
|
|||
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
|
||||
if (code != 0) {
|
||||
if (terrno != 0) code = terrno;
|
||||
dGError("vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr(code));
|
||||
dGError("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
|
||||
vmSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
|
||||
dGTrace("vnodeProcessFetchMsg vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
@ -163,8 +163,8 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
|||
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId);
|
||||
if (pVnode == NULL) {
|
||||
dGError("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
|
||||
terrstr(), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
|
||||
dGWarn("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
|
||||
terrstr(), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
|
||||
terrno = (terrno != 0) ? terrno : -1;
|
||||
return terrno;
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@ extern "C" {
|
|||
|
||||
enum {
|
||||
MQ_CONSUMER_STATUS__MODIFY = 1,
|
||||
MQ_CONSUMER_STATUS__MODIFY_IN_REB, // this value is not used anymore
|
||||
// MQ_CONSUMER_STATUS__MODIFY_IN_REB, // this value is not used anymore
|
||||
MQ_CONSUMER_STATUS__READY,
|
||||
MQ_CONSUMER_STATUS__LOST,
|
||||
MQ_CONSUMER_STATUS__LOST_IN_REB, // this value is not used anymore
|
||||
// MQ_CONSUMER_STATUS__LOST_IN_REB, // this value is not used anymore
|
||||
MQ_CONSUMER_STATUS__LOST_REBD,
|
||||
MQ_CONSUMER_STATUS__REMOVED,
|
||||
};
|
||||
|
|
|
@ -281,6 +281,9 @@ typedef struct {
|
|||
SHashObj* readDbs;
|
||||
SHashObj* writeDbs;
|
||||
SHashObj* topics;
|
||||
SHashObj* readTbs;
|
||||
SHashObj* writeTbs;
|
||||
SHashObj* useDbs;
|
||||
SRWLatch lock;
|
||||
} SUserObj;
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ void mndFreeStb(SStbObj *pStb);
|
|||
int32_t mndBuildSMCreateStbRsp(SMnode *pMnode, char *dbFName, char *stbFName, void **pCont, int32_t *pLen);
|
||||
|
||||
void mndExtractDbNameFromStbFullName(const char *stbFullName, char *dst);
|
||||
void mndExtractShortDbNameFromStbFullName(const char *stbFullName, char *dst);
|
||||
void mndExtractTbNameFromStbFullName(const char *stbFullName, char *dst, int32_t dstSize);
|
||||
|
||||
const char *mndGetStbStr(const char *src);
|
||||
|
|
|
@ -31,6 +31,7 @@ void mndReleaseUser(SMnode *pMnode, SUserObj *pUser);
|
|||
// for trans test
|
||||
SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
||||
SHashObj *mndDupDbHash(SHashObj *pOld);
|
||||
SHashObj *mndDupTableHash(SHashObj *pOld);
|
||||
SHashObj *mndDupTopicHash(SHashObj *pOld);
|
||||
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
||||
int32_t *pRspLen);
|
||||
|
|
|
@ -67,7 +67,7 @@ int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static SClusterObj *mndAcquireCluster(SMnode *pMnode) {
|
||||
static SClusterObj *mndAcquireCluster(SMnode *pMnode, void **ppIter) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
|
||||
|
@ -76,23 +76,27 @@ static SClusterObj *mndAcquireCluster(SMnode *pMnode) {
|
|||
pIter = sdbFetch(pSdb, SDB_CLUSTER, pIter, (void **)&pCluster);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
*ppIter = pIter;
|
||||
|
||||
return pCluster;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void mndReleaseCluster(SMnode *pMnode, SClusterObj *pCluster) {
|
||||
static void mndReleaseCluster(SMnode *pMnode, SClusterObj *pCluster, void *pIter) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pCluster);
|
||||
}
|
||||
|
||||
int64_t mndGetClusterId(SMnode *pMnode) {
|
||||
int64_t clusterId = 0;
|
||||
SClusterObj *pCluster = mndAcquireCluster(pMnode);
|
||||
void *pIter = NULL;
|
||||
SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
|
||||
if (pCluster != NULL) {
|
||||
clusterId = pCluster->id;
|
||||
mndReleaseCluster(pMnode, pCluster);
|
||||
mndReleaseCluster(pMnode, pCluster, pIter);
|
||||
}
|
||||
|
||||
return clusterId;
|
||||
|
@ -100,10 +104,11 @@ int64_t mndGetClusterId(SMnode *pMnode) {
|
|||
|
||||
int64_t mndGetClusterCreateTime(SMnode *pMnode) {
|
||||
int64_t createTime = 0;
|
||||
SClusterObj *pCluster = mndAcquireCluster(pMnode);
|
||||
void *pIter = NULL;
|
||||
SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
|
||||
if (pCluster != NULL) {
|
||||
createTime = pCluster->createdTime;
|
||||
mndReleaseCluster(pMnode, pCluster);
|
||||
mndReleaseCluster(pMnode, pCluster, pIter);
|
||||
}
|
||||
|
||||
return createTime;
|
||||
|
@ -121,10 +126,11 @@ static int32_t mndGetClusterUpTimeImp(SClusterObj *pCluster) {
|
|||
|
||||
float mndGetClusterUpTime(SMnode *pMnode) {
|
||||
int64_t upTime = 0;
|
||||
SClusterObj *pCluster = mndAcquireCluster(pMnode);
|
||||
void *pIter = NULL;
|
||||
SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
|
||||
if (pCluster != NULL) {
|
||||
upTime = mndGetClusterUpTimeImp(pCluster);
|
||||
mndReleaseCluster(pMnode, pCluster);
|
||||
mndReleaseCluster(pMnode, pCluster, pIter);
|
||||
}
|
||||
|
||||
return upTime / 86400.0f;
|
||||
|
@ -321,11 +327,12 @@ static void mndCancelGetNextCluster(SMnode *pMnode, void *pIter) {
|
|||
static int32_t mndProcessUptimeTimer(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SClusterObj clusterObj = {0};
|
||||
SClusterObj *pCluster = mndAcquireCluster(pMnode);
|
||||
void *pIter = NULL;
|
||||
SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
|
||||
if (pCluster != NULL) {
|
||||
memcpy(&clusterObj, pCluster, sizeof(SClusterObj));
|
||||
clusterObj.upTime += tsUptimeInterval;
|
||||
mndReleaseCluster(pMnode, pCluster);
|
||||
mndReleaseCluster(pMnode, pCluster, pIter);
|
||||
}
|
||||
|
||||
if (clusterObj.id <= 0) {
|
||||
|
|
|
@ -335,7 +335,7 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
|
|||
taosArrayPush(pRebSub->removedConsumers, &pConsumer->consumerId);
|
||||
}
|
||||
taosRUnLockLatch(&pConsumer->lock);
|
||||
} else if (status == MQ_CONSUMER_STATUS__MODIFY || status == MQ_CONSUMER_STATUS__MODIFY_IN_REB) {
|
||||
} else if (status == MQ_CONSUMER_STATUS__MODIFY) {
|
||||
taosRLockLatch(&pConsumer->lock);
|
||||
|
||||
int32_t newTopicNum = taosArrayGetSize(pConsumer->rebNewTopics);
|
||||
|
@ -873,17 +873,11 @@ static void updateConsumerStatus(SMqConsumerObj *pConsumer) {
|
|||
int32_t status = pConsumer->status;
|
||||
|
||||
if (taosArrayGetSize(pConsumer->rebNewTopics) == 0 && taosArrayGetSize(pConsumer->rebRemovedTopics) == 0) {
|
||||
if (status == MQ_CONSUMER_STATUS__MODIFY || status == MQ_CONSUMER_STATUS__MODIFY_IN_REB) {
|
||||
if (status == MQ_CONSUMER_STATUS__MODIFY) {
|
||||
pConsumer->status = MQ_CONSUMER_STATUS__READY;
|
||||
} else if (status == MQ_CONSUMER_STATUS__LOST_IN_REB || status == MQ_CONSUMER_STATUS__LOST) {
|
||||
} else if (status == MQ_CONSUMER_STATUS__LOST) {
|
||||
pConsumer->status = MQ_CONSUMER_STATUS__LOST_REBD;
|
||||
}
|
||||
} else {
|
||||
if (status == MQ_CONSUMER_STATUS__MODIFY || status == MQ_CONSUMER_STATUS__MODIFY_IN_REB) {
|
||||
pConsumer->status = MQ_CONSUMER_STATUS__MODIFY;
|
||||
} else if (status == MQ_CONSUMER_STATUS__LOST || status == MQ_CONSUMER_STATUS__LOST_IN_REB) {
|
||||
pConsumer->status = MQ_CONSUMER_STATUS__LOST;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1192,10 +1186,8 @@ static const char *mndConsumerStatusName(int status) {
|
|||
return "ready";
|
||||
case MQ_CONSUMER_STATUS__LOST:
|
||||
case MQ_CONSUMER_STATUS__LOST_REBD:
|
||||
case MQ_CONSUMER_STATUS__LOST_IN_REB:
|
||||
return "lost";
|
||||
case MQ_CONSUMER_STATUS__MODIFY:
|
||||
case MQ_CONSUMER_STATUS__MODIFY_IN_REB:
|
||||
return "rebalancing";
|
||||
default:
|
||||
return "unknown";
|
||||
|
|
|
@ -70,7 +70,7 @@ int32_t tEncodeSStreamObj(SEncoder *pEncoder, const SStreamObj *pObj) {
|
|||
if (tEncodeI32(pEncoder, innerSz) < 0) return -1;
|
||||
for (int32_t j = 0; j < innerSz; j++) {
|
||||
SStreamTask *pTask = taosArrayGetP(pArray, j);
|
||||
if (tEncodeSStreamTask(pEncoder, pTask) < 0) return -1;
|
||||
if (tEncodeStreamTask(pEncoder, pTask) < 0) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ int32_t tDecodeSStreamObj(SDecoder *pDecoder, SStreamObj *pObj, int32_t sver) {
|
|||
taosArrayDestroy(pArray);
|
||||
return -1;
|
||||
}
|
||||
if (tDecodeSStreamTask(pDecoder, pTask) < 0) {
|
||||
if (tDecodeStreamTask(pDecoder, pTask) < 0) {
|
||||
taosMemoryFree(pTask);
|
||||
taosArrayDestroy(pArray);
|
||||
return -1;
|
||||
|
@ -158,7 +158,10 @@ void tFreeStreamObj(SStreamObj *pStream) {
|
|||
taosMemoryFree(pStream->sql);
|
||||
taosMemoryFree(pStream->ast);
|
||||
taosMemoryFree(pStream->physicalPlan);
|
||||
if (pStream->outputSchema.nCols) taosMemoryFree(pStream->outputSchema.pSchema);
|
||||
|
||||
if (pStream->outputSchema.nCols) {
|
||||
taosMemoryFree(pStream->outputSchema.pSchema);
|
||||
}
|
||||
|
||||
int32_t sz = taosArrayGetSize(pStream->tasks);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
|
@ -166,11 +169,14 @@ void tFreeStreamObj(SStreamObj *pStream) {
|
|||
int32_t taskSz = taosArrayGetSize(pLevel);
|
||||
for (int32_t j = 0; j < taskSz; j++) {
|
||||
SStreamTask *pTask = taosArrayGetP(pLevel, j);
|
||||
tFreeSStreamTask(pTask);
|
||||
tFreeStreamTask(pTask);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pLevel);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pStream->tasks);
|
||||
|
||||
// tagSchema.pSchema
|
||||
if (pStream->tagSchema.nCols > 0) {
|
||||
taosMemoryFree(pStream->tagSchema.pSchema);
|
||||
|
|
|
@ -35,6 +35,7 @@ int32_t mndCheckTopicPrivilegeByName(SMnode *pMnode, const char *user, EOperType
|
|||
int32_t mndSetUserAuthRsp(SMnode *pMnode, SUserObj *pUser, SGetUserAuthRsp *pRsp) {
|
||||
memcpy(pRsp->user, pUser->user, TSDB_USER_LEN);
|
||||
pRsp->superAuth = 1;
|
||||
pRsp->enable = pUser->enable;
|
||||
pRsp->version = pUser->authVersion;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ int32_t mndAddDispatcherToInnerTask(SMnode* pMnode, SStreamObj* pStream, SStream
|
|||
for (int32_t j = 0; j < sinkLvSize; j++) {
|
||||
SStreamTask* pLastLevelTask = taosArrayGetP(sinkLv, j);
|
||||
if (pLastLevelTask->nodeId == pVgInfo->vgId) {
|
||||
pVgInfo->taskId = pLastLevelTask->taskId;
|
||||
pVgInfo->taskId = pLastLevelTask->id.taskId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ int32_t mndAddDispatcherToInnerTask(SMnode* pMnode, SStreamObj* pStream, SStream
|
|||
SArray* pArray = taosArrayGetP(pStream->tasks, 0);
|
||||
// one sink only
|
||||
SStreamTask* lastLevelTask = taosArrayGetP(pArray, 0);
|
||||
pTask->fixedEpDispatcher.taskId = lastLevelTask->taskId;
|
||||
pTask->fixedEpDispatcher.taskId = lastLevelTask->id.taskId;
|
||||
pTask->fixedEpDispatcher.nodeId = lastLevelTask->nodeId;
|
||||
pTask->fixedEpDispatcher.epSet = lastLevelTask->epSet;
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ int32_t mndAddShuffleSinkTasksToStream(SMnode* pMnode, SStreamObj* pStream) {
|
|||
continue;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
SStreamTask* pTask = tNewStreamTask(pStream->uid);
|
||||
if (pTask == NULL) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -260,7 +260,7 @@ int32_t mndAddShuffleSinkTasksToStream(SMnode* pMnode, SStreamObj* pStream) {
|
|||
|
||||
int32_t mndAddFixedSinkTaskToStream(SMnode* pMnode, SStreamObj* pStream) {
|
||||
SArray* tasks = taosArrayGetP(pStream->tasks, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
SStreamTask* pTask = tNewStreamTask(pStream->uid);
|
||||
if (pTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
|
@ -350,7 +350,7 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
pInnerTask = tNewSStreamTask(pStream->uid);
|
||||
pInnerTask = tNewStreamTask(pStream->uid);
|
||||
if (pInnerTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
qDestroyQueryPlan(pPlan);
|
||||
|
@ -421,7 +421,7 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) {
|
|||
continue;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
SStreamTask* pTask = tNewStreamTask(pStream->uid);
|
||||
if (pTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
|
@ -440,7 +440,7 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) {
|
|||
pTask->dispatchMsgType = TDMT_STREAM_TASK_DISPATCH;
|
||||
pTask->outputType = TASK_OUTPUT__FIXED_DISPATCH;
|
||||
|
||||
pTask->fixedEpDispatcher.taskId = pInnerTask->taskId;
|
||||
pTask->fixedEpDispatcher.taskId = pInnerTask->id.taskId;
|
||||
pTask->fixedEpDispatcher.nodeId = pInnerTask->nodeId;
|
||||
pTask->fixedEpDispatcher.epSet = pInnerTask->epSet;
|
||||
|
||||
|
@ -460,7 +460,7 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) {
|
|||
pEpInfo->childId = pTask->selfChildId;
|
||||
pEpInfo->epSet = pTask->epSet;
|
||||
pEpInfo->nodeId = pTask->nodeId;
|
||||
pEpInfo->taskId = pTask->taskId;
|
||||
pEpInfo->taskId = pTask->id.taskId;
|
||||
taosArrayPush(pInnerTask->childEpInfo, &pEpInfo);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
@ -491,7 +491,7 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) {
|
|||
continue;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
SStreamTask* pTask = tNewStreamTask(pStream->uid);
|
||||
if (pTask == NULL) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
|
|
|
@ -2614,6 +2614,13 @@ void mndExtractDbNameFromStbFullName(const char *stbFullName, char *dst) {
|
|||
tNameGetFullDbName(&name, dst);
|
||||
}
|
||||
|
||||
void mndExtractShortDbNameFromStbFullName(const char *stbFullName, char *dst) {
|
||||
SName name = {0};
|
||||
tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
|
||||
tNameGetDbName(&name, dst);
|
||||
}
|
||||
|
||||
void mndExtractTbNameFromStbFullName(const char *stbFullName, char *dst, int32_t dstSize) {
|
||||
int32_t pos = -1;
|
||||
int32_t num = 0;
|
||||
|
|
|
@ -35,12 +35,12 @@
|
|||
|
||||
static int32_t mndStreamActionInsert(SSdb *pSdb, SStreamObj *pStream);
|
||||
static int32_t mndStreamActionDelete(SSdb *pSdb, SStreamObj *pStream);
|
||||
static int32_t mndStreamActionUpdate(SSdb *pSdb, SStreamObj *pStream, SStreamObj *pNewStream);
|
||||
static int32_t mndStreamActionUpdate(SSdb *pSdb, SStreamObj *pOldStream, SStreamObj *pNewStream);
|
||||
static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq);
|
||||
static int32_t mndProcessDropStreamReq(SRpcMsg *pReq);
|
||||
static int32_t mndProcessStreamCheckpointTmr(SRpcMsg *pReq);
|
||||
// static int32_t mndProcessStreamDoCheckpoint(SRpcMsg *pReq);
|
||||
/*static int32_t mndProcessRecoverStreamReq(SRpcMsg *pReq);*/
|
||||
static int32_t mndProcessStreamDoCheckpoint(SRpcMsg *pReq);
|
||||
static int32_t mndProcessRecoverStreamReq(SRpcMsg *pReq);
|
||||
static int32_t mndProcessStreamMetaReq(SRpcMsg *pReq);
|
||||
static int32_t mndGetStreamMeta(SRpcMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta);
|
||||
static int32_t mndRetrieveStream(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||
|
@ -418,7 +418,7 @@ FAIL:
|
|||
int32_t mndPersistTaskDeployReq(STrans *pTrans, const SStreamTask *pTask) {
|
||||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, NULL, 0);
|
||||
tEncodeSStreamTask(&encoder, pTask);
|
||||
tEncodeStreamTask(&encoder, pTask);
|
||||
int32_t size = encoder.pos;
|
||||
int32_t tlen = sizeof(SMsgHead) + size;
|
||||
tEncoderClear(&encoder);
|
||||
|
@ -430,7 +430,7 @@ int32_t mndPersistTaskDeployReq(STrans *pTrans, const SStreamTask *pTask) {
|
|||
((SMsgHead *)buf)->vgId = htonl(pTask->nodeId);
|
||||
void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||
tEncoderInit(&encoder, abuf, size);
|
||||
tEncodeSStreamTask(&encoder, pTask);
|
||||
tEncodeStreamTask(&encoder, pTask);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
STransAction action = {0};
|
||||
|
@ -601,7 +601,7 @@ static int32_t mndPersistTaskDropReq(STrans *pTrans, SStreamTask *pTask) {
|
|||
return -1;
|
||||
}
|
||||
pReq->head.vgId = htonl(pTask->nodeId);
|
||||
pReq->taskId = pTask->taskId;
|
||||
pReq->taskId = pTask->id.taskId;
|
||||
STransAction action = {0};
|
||||
memcpy(&action.epSet, &pTask->epSet, sizeof(SEpSet));
|
||||
action.pCont = pReq;
|
||||
|
@ -1209,7 +1209,7 @@ static int32_t mndRetrieveStreamTask(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
|
||||
// task id
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pTask->taskId, false);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)&pTask->id.taskId, false);
|
||||
|
||||
// node type
|
||||
char nodeType[20 + VARSTR_HEADER_SIZE] = {0};
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
#include "mndDb.h"
|
||||
#include "mndPrivilege.h"
|
||||
#include "mndShow.h"
|
||||
#include "mndStb.h"
|
||||
#include "mndTopic.h"
|
||||
#include "mndTrans.h"
|
||||
#include "tbase64.h"
|
||||
|
||||
#define USER_VER_NUMBER 2
|
||||
#define USER_VER_NUMBER 3
|
||||
#define USER_RESERVE_SIZE 64
|
||||
|
||||
static int32_t mndCreateDefaultUsers(SMnode *pMnode);
|
||||
|
@ -124,9 +125,40 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
|||
|
||||
int32_t numOfReadDbs = taosHashGetSize(pUser->readDbs);
|
||||
int32_t numOfWriteDbs = taosHashGetSize(pUser->writeDbs);
|
||||
int32_t numOfReadStbs = taosHashGetSize(pUser->readTbs);
|
||||
int32_t numOfWriteStbs = taosHashGetSize(pUser->writeTbs);
|
||||
int32_t numOfTopics = taosHashGetSize(pUser->topics);
|
||||
int32_t size = sizeof(SUserObj) + USER_RESERVE_SIZE + (numOfReadDbs + numOfWriteDbs) * TSDB_DB_FNAME_LEN +
|
||||
numOfTopics * TSDB_TOPIC_FNAME_LEN;
|
||||
int32_t numOfUseDbs = taosHashGetSize(pUser->useDbs);
|
||||
int32_t size = sizeof(SUserObj) + USER_RESERVE_SIZE +
|
||||
(numOfReadDbs + numOfWriteDbs + numOfUseDbs) * TSDB_DB_FNAME_LEN + numOfTopics * TSDB_TOPIC_FNAME_LEN;
|
||||
|
||||
char *stb = taosHashIterate(pUser->readTbs, NULL);
|
||||
while (stb != NULL) {
|
||||
size_t keyLen = 0;
|
||||
void *key = taosHashGetKey(stb, &keyLen);
|
||||
size += sizeof(int32_t);
|
||||
size += keyLen;
|
||||
|
||||
size_t valueLen = 0;
|
||||
valueLen = strlen(stb);
|
||||
size += sizeof(int32_t);
|
||||
size += valueLen;
|
||||
stb = taosHashIterate(pUser->readTbs, stb);
|
||||
}
|
||||
|
||||
stb = taosHashIterate(pUser->writeTbs, NULL);
|
||||
while (stb != NULL) {
|
||||
size_t keyLen = 0;
|
||||
void *key = taosHashGetKey(stb, &keyLen);
|
||||
size += sizeof(int32_t);
|
||||
size += keyLen;
|
||||
|
||||
size_t valueLen = 0;
|
||||
valueLen = strlen(stb);
|
||||
size += sizeof(int32_t);
|
||||
size += valueLen;
|
||||
stb = taosHashIterate(pUser->writeTbs, stb);
|
||||
}
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, USER_VER_NUMBER, size);
|
||||
if (pRaw == NULL) goto _OVER;
|
||||
|
@ -164,6 +196,49 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
|||
topic = taosHashIterate(pUser->topics, topic);
|
||||
}
|
||||
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfReadStbs, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfWriteStbs, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfUseDbs, _OVER)
|
||||
|
||||
stb = taosHashIterate(pUser->readTbs, NULL);
|
||||
while (stb != NULL) {
|
||||
size_t keyLen = 0;
|
||||
void *key = taosHashGetKey(stb, &keyLen);
|
||||
SDB_SET_INT32(pRaw, dataPos, keyLen, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, key, keyLen, _OVER);
|
||||
|
||||
size_t valueLen = 0;
|
||||
valueLen = strlen(stb) + 1;
|
||||
SDB_SET_INT32(pRaw, dataPos, valueLen, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, stb, valueLen, _OVER);
|
||||
stb = taosHashIterate(pUser->readTbs, stb);
|
||||
}
|
||||
|
||||
stb = taosHashIterate(pUser->writeTbs, NULL);
|
||||
while (stb != NULL) {
|
||||
size_t keyLen = 0;
|
||||
void *key = taosHashGetKey(stb, &keyLen);
|
||||
SDB_SET_INT32(pRaw, dataPos, keyLen, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, key, keyLen, _OVER);
|
||||
|
||||
size_t valueLen = 0;
|
||||
valueLen = strlen(stb) + 1;
|
||||
SDB_SET_INT32(pRaw, dataPos, valueLen, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, stb, valueLen, _OVER);
|
||||
stb = taosHashIterate(pUser->writeTbs, stb);
|
||||
}
|
||||
|
||||
int32_t *useDb = taosHashIterate(pUser->useDbs, NULL);
|
||||
while (useDb != NULL) {
|
||||
size_t keyLen = 0;
|
||||
void *key = taosHashGetKey(useDb, &keyLen);
|
||||
SDB_SET_INT32(pRaw, dataPos, keyLen, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, key, keyLen, _OVER);
|
||||
|
||||
SDB_SET_INT32(pRaw, dataPos, *useDb, _OVER)
|
||||
useDb = taosHashIterate(pUser->writeTbs, useDb);
|
||||
}
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, USER_RESERVE_SIZE, _OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
||||
|
||||
|
@ -188,7 +263,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
||||
|
||||
if (sver != 1 && sver != 2) {
|
||||
if (sver != 1 && sver != 2 && sver != 3) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -249,6 +324,75 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
|||
}
|
||||
}
|
||||
|
||||
if (sver >= 3) {
|
||||
int32_t numOfReadStbs = 0;
|
||||
int32_t numOfWriteStbs = 0;
|
||||
int32_t numOfUseDbs = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfReadStbs, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfWriteStbs, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfUseDbs, _OVER)
|
||||
|
||||
pUser->readTbs =
|
||||
taosHashInit(numOfReadStbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pUser->writeTbs =
|
||||
taosHashInit(numOfWriteStbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pUser->useDbs = taosHashInit(numOfUseDbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
|
||||
for (int32_t i = 0; i < numOfReadStbs; ++i) {
|
||||
int32_t keyLen = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &keyLen, _OVER);
|
||||
|
||||
char *key = taosMemoryCalloc(keyLen, sizeof(char));
|
||||
memset(key, 0, keyLen);
|
||||
SDB_GET_BINARY(pRaw, dataPos, key, keyLen, _OVER);
|
||||
|
||||
int32_t valuelen = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &valuelen, _OVER);
|
||||
char *value = taosMemoryCalloc(valuelen, sizeof(char));
|
||||
memset(value, 0, valuelen);
|
||||
SDB_GET_BINARY(pRaw, dataPos, value, valuelen, _OVER)
|
||||
|
||||
taosHashPut(pUser->readTbs, key, keyLen, value, valuelen);
|
||||
|
||||
taosMemoryFree(key);
|
||||
taosMemoryFree(value);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfWriteStbs; ++i) {
|
||||
int32_t keyLen = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &keyLen, _OVER);
|
||||
|
||||
char *key = taosMemoryCalloc(keyLen, sizeof(char));
|
||||
memset(key, 0, keyLen);
|
||||
SDB_GET_BINARY(pRaw, dataPos, key, keyLen, _OVER);
|
||||
|
||||
int32_t valuelen = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &valuelen, _OVER);
|
||||
char *value = taosMemoryCalloc(valuelen, sizeof(char));
|
||||
memset(value, 0, valuelen);
|
||||
SDB_GET_BINARY(pRaw, dataPos, value, valuelen, _OVER)
|
||||
|
||||
taosHashPut(pUser->writeTbs, key, keyLen, value, valuelen);
|
||||
|
||||
taosMemoryFree(key);
|
||||
taosMemoryFree(value);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfUseDbs; ++i) {
|
||||
int32_t keyLen = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &keyLen, _OVER);
|
||||
|
||||
char *key = taosMemoryCalloc(keyLen, sizeof(char));
|
||||
memset(key, 0, keyLen);
|
||||
SDB_GET_BINARY(pRaw, dataPos, key, keyLen, _OVER);
|
||||
|
||||
int32_t ref = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &ref, _OVER);
|
||||
|
||||
taosHashPut(pUser->useDbs, key, keyLen, &ref, sizeof(ref));
|
||||
}
|
||||
}
|
||||
|
||||
SDB_GET_RESERVE(pRaw, dataPos, USER_RESERVE_SIZE, _OVER)
|
||||
taosInitRWLatch(&pUser->lock);
|
||||
|
||||
|
@ -261,6 +405,9 @@ _OVER:
|
|||
taosHashCleanup(pUser->readDbs);
|
||||
taosHashCleanup(pUser->writeDbs);
|
||||
taosHashCleanup(pUser->topics);
|
||||
taosHashCleanup(pUser->readTbs);
|
||||
taosHashCleanup(pUser->writeTbs);
|
||||
taosHashCleanup(pUser->useDbs);
|
||||
}
|
||||
taosMemoryFreeClear(pRow);
|
||||
return NULL;
|
||||
|
@ -285,6 +432,57 @@ static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
SHashObj *mndDupTableHash(SHashObj *pOld) {
|
||||
SHashObj *pNew =
|
||||
taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (pNew == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *tb = taosHashIterate(pOld, NULL);
|
||||
while (tb != NULL) {
|
||||
size_t keyLen = 0;
|
||||
char *key = taosHashGetKey(tb, &keyLen);
|
||||
|
||||
int32_t valueLen = strlen(tb) + 1;
|
||||
if (taosHashPut(pNew, key, keyLen, tb, valueLen) != 0) {
|
||||
taosHashCancelIterate(pOld, tb);
|
||||
taosHashCleanup(pNew);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
tb = taosHashIterate(pOld, tb);
|
||||
}
|
||||
|
||||
return pNew;
|
||||
}
|
||||
|
||||
SHashObj *mndDupUseDbHash(SHashObj *pOld) {
|
||||
SHashObj *pNew =
|
||||
taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (pNew == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t *db = taosHashIterate(pOld, NULL);
|
||||
while (db != NULL) {
|
||||
size_t keyLen = 0;
|
||||
char *key = taosHashGetKey(db, &keyLen);
|
||||
|
||||
if (taosHashPut(pNew, key, keyLen, db, sizeof(*db)) != 0) {
|
||||
taosHashCancelIterate(pOld, db);
|
||||
taosHashCleanup(pNew);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
db = taosHashIterate(pOld, db);
|
||||
}
|
||||
|
||||
return pNew;
|
||||
}
|
||||
|
||||
static int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
|
||||
memcpy(pNew, pUser, sizeof(SUserObj));
|
||||
pNew->authVersion++;
|
||||
|
@ -293,7 +491,10 @@ static int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
|
|||
taosRLockLatch(&pUser->lock);
|
||||
pNew->readDbs = mndDupDbHash(pUser->readDbs);
|
||||
pNew->writeDbs = mndDupDbHash(pUser->writeDbs);
|
||||
pNew->readTbs = mndDupTableHash(pUser->readTbs);
|
||||
pNew->writeTbs = mndDupTableHash(pUser->writeTbs);
|
||||
pNew->topics = mndDupTopicHash(pUser->topics);
|
||||
pNew->useDbs = mndDupUseDbHash(pUser->useDbs);
|
||||
taosRUnLockLatch(&pUser->lock);
|
||||
|
||||
if (pNew->readDbs == NULL || pNew->writeDbs == NULL || pNew->topics == NULL) {
|
||||
|
@ -306,9 +507,15 @@ static void mndUserFreeObj(SUserObj *pUser) {
|
|||
taosHashCleanup(pUser->readDbs);
|
||||
taosHashCleanup(pUser->writeDbs);
|
||||
taosHashCleanup(pUser->topics);
|
||||
taosHashCleanup(pUser->readTbs);
|
||||
taosHashCleanup(pUser->writeTbs);
|
||||
taosHashCleanup(pUser->useDbs);
|
||||
pUser->readDbs = NULL;
|
||||
pUser->writeDbs = NULL;
|
||||
pUser->topics = NULL;
|
||||
pUser->readTbs = NULL;
|
||||
pUser->writeTbs = NULL;
|
||||
pUser->useDbs = NULL;
|
||||
}
|
||||
|
||||
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
||||
|
@ -328,6 +535,9 @@ static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) {
|
|||
TSWAP(pOld->readDbs, pNew->readDbs);
|
||||
TSWAP(pOld->writeDbs, pNew->writeDbs);
|
||||
TSWAP(pOld->topics, pNew->topics);
|
||||
TSWAP(pOld->readTbs, pNew->readTbs);
|
||||
TSWAP(pOld->writeTbs, pNew->writeTbs);
|
||||
TSWAP(pOld->useDbs, pNew->useDbs);
|
||||
taosWUnLockLatch(&pOld->lock);
|
||||
|
||||
return 0;
|
||||
|
@ -498,6 +708,71 @@ SHashObj *mndDupDbHash(SHashObj *pOld) { return mndDupObjHash(pOld, TSDB_DB_FNAM
|
|||
|
||||
SHashObj *mndDupTopicHash(SHashObj *pOld) { return mndDupObjHash(pOld, TSDB_TOPIC_FNAME_LEN); }
|
||||
|
||||
static int32_t mndTablePriviledge(SMnode *pMnode, SHashObj *hash, SHashObj *useDbHash, SAlterUserReq *alterReq,
|
||||
SSdb *pSdb) {
|
||||
void *pIter = NULL;
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
|
||||
snprintf(tbFName, sizeof(tbFName), "%s.%s", alterReq->objname, alterReq->tabName);
|
||||
int32_t len = strlen(tbFName) + 1;
|
||||
|
||||
if (alterReq->tagCond != NULL && alterReq->tagCondLen != 0) {
|
||||
char *value = taosHashGet(hash, tbFName, len);
|
||||
if (value != NULL) {
|
||||
terrno = TSDB_CODE_MND_PRIVILEDGE_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t condLen = alterReq->tagCondLen;
|
||||
if (taosHashPut(hash, tbFName, len, alterReq->tagCond, condLen) != 0) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (taosHashPut(hash, tbFName, len, "t", 2) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dbKeyLen = strlen(alterReq->objname) + 1;
|
||||
int32_t ref = 1;
|
||||
int32_t *currRef = taosHashGet(useDbHash, alterReq->objname, dbKeyLen);
|
||||
if (NULL != currRef) {
|
||||
ref = (*currRef) + 1;
|
||||
}
|
||||
if (taosHashPut(useDbHash, alterReq->objname, dbKeyLen, &ref, sizeof(ref)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRemoveTablePriviledge(SMnode *pMnode, SHashObj *hash, SHashObj *useDbHash, SAlterUserReq *alterReq,
|
||||
SSdb *pSdb) {
|
||||
void *pIter = NULL;
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
snprintf(tbFName, sizeof(tbFName), "%s.%s", alterReq->objname, alterReq->tabName);
|
||||
int32_t len = strlen(tbFName) + 1;
|
||||
|
||||
if (taosHashRemove(hash, tbFName, len) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t dbKeyLen = strlen(alterReq->objname) + 1;
|
||||
int32_t *currRef = taosHashGet(useDbHash, alterReq->objname, dbKeyLen);
|
||||
if (NULL == currRef || 1 == *currRef) {
|
||||
if (taosHashRemove(useDbHash, alterReq->objname, dbKeyLen) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t ref = (*currRef) - 1;
|
||||
if (taosHashPut(useDbHash, alterReq->objname, dbKeyLen, &ref, sizeof(ref)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
@ -637,6 +912,22 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
|||
}
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_ADD_READ_TABLE) {
|
||||
if (mndTablePriviledge(pMnode, newUser.readTbs, newUser.useDbs, &alterReq, pSdb) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_TABLE) {
|
||||
if (mndTablePriviledge(pMnode, newUser.writeTbs, newUser.useDbs, &alterReq, pSdb) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_READ_TABLE) {
|
||||
if (mndRemoveTablePriviledge(pMnode, newUser.readTbs, newUser.useDbs, &alterReq, pSdb) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_WRITE_TABLE) {
|
||||
if (mndRemoveTablePriviledge(pMnode, newUser.writeTbs, newUser.useDbs, &alterReq, pSdb) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC) {
|
||||
int32_t len = strlen(alterReq.objname) + 1;
|
||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, alterReq.objname);
|
||||
|
@ -830,6 +1121,70 @@ static void mndCancelGetNextUser(SMnode *pMnode, void *pIter) {
|
|||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
||||
static void mndLoopHash(SHashObj *hash, char *priType, SSDataBlock *pBlock, int32_t *numOfRows, char *user,
|
||||
SShowObj *pShow) {
|
||||
char *value = taosHashIterate(hash, NULL);
|
||||
int32_t cols = 0;
|
||||
|
||||
while (value != NULL) {
|
||||
cols = 0;
|
||||
char userName[TSDB_USER_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(userName, user, pShow->pMeta->pSchemas[cols].bytes);
|
||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)userName, false);
|
||||
|
||||
char privilege[20] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(privilege, priType, pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)privilege, false);
|
||||
|
||||
size_t keyLen = 0;
|
||||
void *key = taosHashGetKey(value, &keyLen);
|
||||
|
||||
char dbName[TSDB_DB_NAME_LEN] = {0};
|
||||
mndExtractShortDbNameFromStbFullName(key, dbName);
|
||||
char dbNameContent[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(dbNameContent, dbName, pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)dbNameContent, false);
|
||||
|
||||
char tableName[TSDB_TABLE_NAME_LEN] = {0};
|
||||
mndExtractTbNameFromStbFullName(key, tableName, TSDB_TABLE_NAME_LEN);
|
||||
char tableNameContent[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(tableNameContent, tableName, pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)tableNameContent, false);
|
||||
|
||||
if (strcmp("t", value) != 0) {
|
||||
SNode *pAst = NULL;
|
||||
int32_t sqlLen = 0;
|
||||
char sql[TSDB_EXPLAIN_RESULT_ROW_SIZE] = {0};
|
||||
|
||||
if (nodesStringToNode(value, &pAst) == 0) {
|
||||
nodesNodeToSQL(pAst, sql, TSDB_EXPLAIN_RESULT_ROW_SIZE, &sqlLen);
|
||||
nodesDestroyNode(pAst);
|
||||
} else {
|
||||
sqlLen = 5;
|
||||
sprintf(sql, "error");
|
||||
}
|
||||
|
||||
char obj[TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(obj, sql, pShow->pMeta->pSchemas[cols].bytes);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)obj, false);
|
||||
} else {
|
||||
char condition[TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(condition, "", pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)condition, false);
|
||||
}
|
||||
|
||||
(*numOfRows)++;
|
||||
value = taosHashIterate(hash, value);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
@ -845,7 +1200,9 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
int32_t numOfReadDbs = taosHashGetSize(pUser->readDbs);
|
||||
int32_t numOfWriteDbs = taosHashGetSize(pUser->writeDbs);
|
||||
int32_t numOfTopics = taosHashGetSize(pUser->topics);
|
||||
if (numOfRows + numOfReadDbs + numOfWriteDbs + numOfTopics >= rows) break;
|
||||
int32_t numOfReadTbs = taosHashGetSize(pUser->readTbs);
|
||||
int32_t numOfWriteTbs = taosHashGetSize(pUser->writeTbs);
|
||||
if (numOfRows + numOfReadDbs + numOfWriteDbs + numOfTopics + numOfReadTbs + numOfWriteTbs >= rows) break;
|
||||
|
||||
if (pUser->superUser) {
|
||||
cols = 0;
|
||||
|
@ -864,6 +1221,16 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)objName, false);
|
||||
|
||||
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(tableName, "", pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)tableName, false);
|
||||
|
||||
char condition[TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(condition, "", pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)condition, false);
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
|
||||
|
@ -888,6 +1255,16 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)objName, false);
|
||||
|
||||
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(tableName, "", pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)tableName, false);
|
||||
|
||||
char condition[TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(condition, "", pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)condition, false);
|
||||
|
||||
numOfRows++;
|
||||
db = taosHashIterate(pUser->readDbs, db);
|
||||
}
|
||||
|
@ -913,10 +1290,24 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)objName, false);
|
||||
|
||||
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(tableName, "", pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)tableName, false);
|
||||
|
||||
char condition[TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(condition, "", pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)condition, false);
|
||||
|
||||
numOfRows++;
|
||||
db = taosHashIterate(pUser->writeDbs, db);
|
||||
}
|
||||
|
||||
mndLoopHash(pUser->readTbs, "read", pBlock, &numOfRows, pUser->user, pShow);
|
||||
|
||||
mndLoopHash(pUser->writeTbs, "write", pBlock, &numOfRows, pUser->user, pShow);
|
||||
|
||||
char *topic = taosHashIterate(pUser->topics, NULL);
|
||||
while (topic != NULL) {
|
||||
cols = 0;
|
||||
|
@ -936,6 +1327,16 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)topicName, false);
|
||||
|
||||
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(tableName, "", pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)tableName, false);
|
||||
|
||||
char condition[TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(condition, "", pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)condition, false);
|
||||
|
||||
numOfRows++;
|
||||
topic = taosHashIterate(pUser->topics, topic);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ int32_t sndExpandTask(SSnode *pSnode, SStreamTask *pTask, int64_t ver) {
|
|||
ASSERT(taosArrayGetSize(pTask->childEpInfo) != 0);
|
||||
|
||||
pTask->refCnt = 1;
|
||||
pTask->schedStatus = TASK_SCHED_STATUS__INACTIVE;
|
||||
pTask->status.schedStatus = TASK_SCHED_STATUS__INACTIVE;
|
||||
|
||||
pTask->inputQueue = streamQueueOpen(0);
|
||||
pTask->outputQueue = streamQueueOpen(0);
|
||||
|
@ -77,21 +77,18 @@ int32_t sndExpandTask(SSnode *pSnode, SStreamTask *pTask, int64_t ver) {
|
|||
pTask->inputStatus = TASK_INPUT_STATUS__NORMAL;
|
||||
pTask->outputStatus = TASK_OUTPUT_STATUS__NORMAL;
|
||||
pTask->pMsgCb = &pSnode->msgCb;
|
||||
pTask->startVer = ver;
|
||||
pTask->chkInfo.version = ver;
|
||||
|
||||
pTask->pState = streamStateOpen(pSnode->path, pTask, false, -1, -1);
|
||||
if (pTask->pState == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SReadHandle mgHandle = {
|
||||
.vnode = NULL,
|
||||
.numOfVgroups = (int32_t)taosArrayGetSize(pTask->childEpInfo),
|
||||
.pStateBackend = pTask->pState,
|
||||
};
|
||||
int32_t numOfChildEp = taosArrayGetSize(pTask->childEpInfo);
|
||||
SReadHandle mgHandle = { .vnode = NULL, .numOfVgroups = numOfChildEp, .pStateBackend = pTask->pState };
|
||||
|
||||
pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &mgHandle, 0);
|
||||
ASSERT(pTask->exec.executor);
|
||||
pTask->exec.pExecutor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &mgHandle, 0);
|
||||
ASSERT(pTask->exec.pExecutor);
|
||||
|
||||
streamSetupTrigger(pTask);
|
||||
return 0;
|
||||
|
@ -143,7 +140,7 @@ int32_t sndProcessTaskDeployReq(SSnode *pSnode, char *msg, int32_t msgLen) {
|
|||
}
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, (uint8_t *)msg, msgLen);
|
||||
code = tDecodeSStreamTask(&decoder, pTask);
|
||||
code = tDecodeStreamTask(&decoder, pTask);
|
||||
if (code < 0) {
|
||||
tDecoderClear(&decoder);
|
||||
taosMemoryFree(pTask);
|
||||
|
@ -154,7 +151,7 @@ int32_t sndProcessTaskDeployReq(SSnode *pSnode, char *msg, int32_t msgLen) {
|
|||
ASSERT(pTask->taskLevel == TASK_LEVEL__AGG);
|
||||
|
||||
// 2.save task
|
||||
code = streamMetaAddTask(pSnode->pMeta, -1, pTask);
|
||||
code = streamMetaAddDeployedTask(pSnode->pMeta, -1, pTask);
|
||||
if (code < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ target_sources(
|
|||
|
||||
# tq
|
||||
"src/tq/tq.c"
|
||||
"src/tq/tqUtil.c"
|
||||
"src/tq/tqScan.c"
|
||||
"src/tq/tqMeta.c"
|
||||
"src/tq/tqRead.c"
|
||||
|
@ -64,6 +65,7 @@ target_sources(
|
|||
"src/tq/tqPush.c"
|
||||
"src/tq/tqSink.c"
|
||||
"src/tq/tqCommit.c"
|
||||
"src/tq/tqRestore.c"
|
||||
"src/tq/tqSnapshot.c"
|
||||
"src/tq/tqOffsetSnapshot.c"
|
||||
)
|
||||
|
|
|
@ -228,19 +228,12 @@ typedef struct SSnapContext {
|
|||
SArray *idList;
|
||||
int32_t index;
|
||||
bool withMeta;
|
||||
bool queryMetaOrData; // true-get meta, false-get data
|
||||
bool queryMeta; // true-get meta, false-get data
|
||||
} SSnapContext;
|
||||
|
||||
typedef struct STqReader {
|
||||
// const SSubmitReq *pMsg;
|
||||
// SSubmitBlk *pBlock;
|
||||
// SSubmitMsgIter msgIter;
|
||||
// SSubmitBlkIter blkIter;
|
||||
|
||||
int64_t ver;
|
||||
SPackedData msg2;
|
||||
|
||||
int8_t setMsg;
|
||||
SSubmitReq2 submit;
|
||||
int32_t nextBlk;
|
||||
|
||||
|
@ -263,15 +256,16 @@ void tqCloseReader(STqReader *);
|
|||
|
||||
void tqReaderSetColIdList(STqReader *pReader, SArray *pColIdList);
|
||||
int32_t tqReaderSetTbUidList(STqReader *pReader, const SArray *tbUidList);
|
||||
int32_t tqReaderAddTbUidList(STqReader *pReader, const SArray *tbUidList);
|
||||
int32_t tqReaderAddTbUidList(STqReader *pReader, const SArray *pTableUidList);
|
||||
int32_t tqReaderRemoveTbUidList(STqReader *pReader, const SArray *tbUidList);
|
||||
|
||||
int32_t tqSeekVer(STqReader *pReader, int64_t ver, const char *id);
|
||||
int32_t tqNextBlock(STqReader *pReader, SFetchRet *ret);
|
||||
void tqNextBlock(STqReader *pReader, SFetchRet *ret);
|
||||
int32_t extractSubmitMsgFromWal(SWalReader *pReader, SPackedData *pPackedData);
|
||||
|
||||
int32_t tqReaderSetSubmitReq2(STqReader *pReader, void *msgStr, int32_t msgLen, int64_t ver);
|
||||
int32_t tqReaderSetSubmitMsg(STqReader *pReader, void *msgStr, int32_t msgLen, int64_t ver);
|
||||
// int32_t tqReaderSetDataMsg(STqReader *pReader, const SSubmitReq *pMsg, int64_t ver);
|
||||
bool tqNextDataBlock2(STqReader *pReader);
|
||||
bool tqNextDataBlock(STqReader *pReader);
|
||||
bool tqNextDataBlockFilterOut2(STqReader *pReader, SHashObj *filterOutUids);
|
||||
int32_t tqRetrieveDataBlock2(SSDataBlock *pBlock, STqReader *pReader, SSubmitTbData **pSubmitTbDataRet);
|
||||
int32_t tqRetrieveTaosxBlock2(STqReader *pReader, SArray *blocks, SArray *schemas, SSubmitTbData **pSubmitTbDataRet);
|
||||
|
|
|
@ -80,7 +80,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
int8_t subType;
|
||||
STqReader* pExecReader;
|
||||
STqReader* pTqReader;
|
||||
qTaskInfo_t task;
|
||||
union {
|
||||
STqExecCol execCol;
|
||||
|
@ -128,6 +128,10 @@ typedef struct {
|
|||
tmr_h timer;
|
||||
} STqMgmt;
|
||||
|
||||
typedef struct {
|
||||
int32_t size;
|
||||
} STqOffsetHead;
|
||||
|
||||
static STqMgmt tqMgmt = {0};
|
||||
|
||||
int32_t tEncodeSTqHandle(SEncoder* pEncoder, const STqHandle* pHandle);
|
||||
|
@ -154,10 +158,6 @@ int32_t tqMetaSaveCheckInfo(STQ* pTq, const char* key, const void* value, int32_
|
|||
int32_t tqMetaDeleteCheckInfo(STQ* pTq, const char* key);
|
||||
int32_t tqMetaRestoreCheckInfo(STQ* pTq);
|
||||
|
||||
typedef struct {
|
||||
int32_t size;
|
||||
} STqOffsetHead;
|
||||
|
||||
STqOffsetStore* tqOffsetOpen(STQ* pTq);
|
||||
void tqOffsetClose(STqOffsetStore*);
|
||||
STqOffset* tqOffsetRead(STqOffsetStore* pStore, const char* subscribeKey);
|
||||
|
@ -176,6 +176,18 @@ int32_t tqOffsetRestoreFromFile(STqOffsetStore* pStore, const char* fname);
|
|||
|
||||
// tqStream
|
||||
int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver);
|
||||
int32_t tqStreamTasksScanWal(STQ* pTq);
|
||||
|
||||
// tq util
|
||||
void createStreamTaskOffsetKey(char* dst, uint64_t streamId, uint32_t taskId);
|
||||
int32_t tqAddInputBlockNLaunchTask(SStreamTask* pTask, SStreamQueueItem* pQueueItem, int64_t ver);
|
||||
int32_t launchTaskForWalBlock(SStreamTask* pTask, SFetchRet* pRet, STqOffset* pOffset);
|
||||
int32_t tqExtractDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest, SRpcMsg* pMsg);
|
||||
|
||||
void doSaveTaskOffset(STqOffsetStore* pOffsetStore, const char* pKey, int64_t ver);
|
||||
void saveOffsetForAllTasks(STQ* pTq, int64_t ver);
|
||||
void initOffsetForAllRestoreTasks(STQ* pTq);
|
||||
int32_t transferToWalReadTask(SStreamMeta* pStreamMeta, SArray* pTaskList);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -123,12 +123,12 @@ int32_t tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema)
|
|||
void tsdbRowClose(STSDBRowIter *pIter);
|
||||
SColVal *tsdbRowIterNext(STSDBRowIter *pIter);
|
||||
// SRowMerger
|
||||
int32_t tsdbRowMergerInit2(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRow, STSchema *pTSchema);
|
||||
int32_t tsdbRowMergerInit(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRow, STSchema *pTSchema);
|
||||
int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
||||
|
||||
int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
||||
void tsdbRowMergerClear(SRowMerger *pMerger);
|
||||
int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow);
|
||||
// int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
||||
void tsdbRowMergerClear(SRowMerger *pMerger);
|
||||
// int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow);
|
||||
int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow);
|
||||
// TABLEID
|
||||
int32_t tTABLEIDCmprFn(const void *p1, const void *p2);
|
||||
|
@ -224,7 +224,7 @@ int32_t tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward,
|
|||
void *tsdbTbDataIterDestroy(STbDataIter *pIter);
|
||||
void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter);
|
||||
bool tsdbTbDataIterNext(STbDataIter *pIter);
|
||||
void tsdbMemTableCountRows(SMemTable *pMemTable, SHashObj* pTableMap, int64_t *rowsNum);
|
||||
void tsdbMemTableCountRows(SMemTable *pMemTable, SHashObj *pTableMap, int64_t *rowsNum);
|
||||
|
||||
// STbData
|
||||
int32_t tsdbGetNRowsInTbData(STbData *pTbData);
|
||||
|
|
|
@ -192,9 +192,10 @@ void tqCleanUp();
|
|||
STQ* tqOpen(const char* path, SVnode* pVnode);
|
||||
void tqClose(STQ*);
|
||||
int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver);
|
||||
int tqRegisterPushEntry(STQ* pTq, void* pHandle, const SMqPollReq* pRequest, SRpcMsg* pRpcMsg, SMqDataRsp* pDataRsp,
|
||||
int tqRegisterPushHandle(STQ* pTq, void* pHandle, const SMqPollReq* pRequest, SRpcMsg* pRpcMsg, SMqDataRsp* pDataRsp,
|
||||
int32_t type);
|
||||
int tqUnregisterPushEntry(STQ* pTq, const char* pKey, int32_t keyLen, uint64_t consumerId, bool rspConsumer);
|
||||
int tqUnregisterPushHandle(STQ* pTq, const char* pKey, int32_t keyLen, uint64_t consumerId, bool rspConsumer);
|
||||
int tqStartStreamTasks(STQ* pTq); // restore all stream tasks after vnode launching completed.
|
||||
|
||||
int tqCommit(STQ*);
|
||||
int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd);
|
||||
|
|
|
@ -531,10 +531,11 @@ static void freePayload(const void* key, size_t keyLen, void* value) {
|
|||
return;
|
||||
}
|
||||
|
||||
SHashObj* pHashObj = (SHashObj*)p[0];
|
||||
SHashObj* pHashObj = (SHashObj*)p[0];
|
||||
|
||||
STagFilterResEntry** pEntry = taosHashGet(pHashObj, &p[1], sizeof(uint64_t));
|
||||
|
||||
{
|
||||
if (pEntry != NULL && (*pEntry) != NULL) {
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
||||
SListIter iter = {0};
|
||||
|
@ -547,9 +548,9 @@ static void freePayload(const void* key, size_t keyLen, void* value) {
|
|||
void* tmp = tdListPopNode(&((*pEntry)->list), pNode);
|
||||
taosMemoryFree(tmp);
|
||||
|
||||
int64_t et = taosGetTimestampUs();
|
||||
metaInfo("clear items in cache, remain cached item:%d, elapsed time:%.2fms", listNEles(&((*pEntry)->list)),
|
||||
(et - st) / 1000.0);
|
||||
double el = (taosGetTimestampUs() - st) / 1000.0;
|
||||
metaInfo("clear items in meta-cache, remain cached item:%d, elapsed time:%.2fms", listNEles(&((*pEntry)->list)),
|
||||
el);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ int32_t buildSnapContext(SMeta* pMeta, int64_t snapVersion, int64_t suid, int8_t
|
|||
ctx->snapVersion = snapVersion;
|
||||
ctx->suid = suid;
|
||||
ctx->subType = subType;
|
||||
ctx->queryMetaOrData = withMeta;
|
||||
ctx->queryMeta = withMeta;
|
||||
ctx->withMeta = withMeta;
|
||||
ctx->idVersion = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
||||
if (ctx->idVersion == NULL) {
|
||||
|
@ -475,7 +475,7 @@ int32_t getMetafromSnapShot(SSnapContext* ctx, void** pBuf, int32_t* contLen, in
|
|||
if (ctx->index >= taosArrayGetSize(ctx->idList)) {
|
||||
metaDebug("tmqsnap get meta end");
|
||||
ctx->index = 0;
|
||||
ctx->queryMetaOrData = false; // change to get data
|
||||
ctx->queryMeta = false; // change to get data
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids,
|
|||
|
||||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||
if (pRSmaInfo->taskInfo[i]) {
|
||||
if ((terrno = qUpdateQualifiedTableId(pRSmaInfo->taskInfo[i], tbUids, isAdd)) < 0) {
|
||||
if ((terrno = qUpdateTableListForStreamScanner(pRSmaInfo->taskInfo[i], tbUids, isAdd, NULL)) < 0) {
|
||||
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||
smaError("vgId:%d, update tbUidList failed for uid:%" PRIi64 " level %d since %s", SMA_VID(pSma), *suid, i,
|
||||
terrstr());
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
// 0: not init
|
||||
// 1: already inited
|
||||
// 2: wait to be inited or cleaup
|
||||
#define WAL_READ_TASKS_ID (-1)
|
||||
|
||||
int32_t tqInit() {
|
||||
int8_t old;
|
||||
|
@ -61,12 +62,12 @@ static void destroyTqHandle(void* data) {
|
|||
if (pData->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
taosMemoryFreeClear(pData->execHandle.execCol.qmsg);
|
||||
} else if (pData->execHandle.subType == TOPIC_SUB_TYPE__DB) {
|
||||
tqCloseReader(pData->execHandle.pExecReader);
|
||||
tqCloseReader(pData->execHandle.pTqReader);
|
||||
walCloseReader(pData->pWalReader);
|
||||
taosHashCleanup(pData->execHandle.execDb.pFilterOutTbUid);
|
||||
} else if (pData->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
walCloseReader(pData->pWalReader);
|
||||
tqCloseReader(pData->execHandle.pExecReader);
|
||||
tqCloseReader(pData->execHandle.pTqReader);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,12 +83,18 @@ static void tqPushEntryFree(void* data) {
|
|||
taosMemoryFree(p);
|
||||
}
|
||||
|
||||
static bool tqOffsetLessOrEqual(const STqOffset* pLeft, const STqOffset* pRight) {
|
||||
return pLeft->val.type == TMQ_OFFSET__LOG && pRight->val.type == TMQ_OFFSET__LOG &&
|
||||
pLeft->val.version <= pRight->val.version;
|
||||
}
|
||||
|
||||
STQ* tqOpen(const char* path, SVnode* pVnode) {
|
||||
STQ* pTq = taosMemoryCalloc(1, sizeof(STQ));
|
||||
if (pTq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTq->path = taosStrdup(path);
|
||||
pTq->pVnode = pVnode;
|
||||
pTq->walLogLastVer = pVnode->pWal->vers.lastVer;
|
||||
|
@ -138,44 +145,6 @@ void tqClose(STQ* pTq) {
|
|||
taosMemoryFree(pTq);
|
||||
}
|
||||
|
||||
int32_t tqSendMetaPollRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqMetaRsp* pRsp) {
|
||||
int32_t len = 0;
|
||||
int32_t code = 0;
|
||||
tEncodeSize(tEncodeSMqMetaRsp, pRsp, len, code);
|
||||
if (code < 0) {
|
||||
return -1;
|
||||
}
|
||||
int32_t tlen = sizeof(SMqRspHead) + len;
|
||||
void* buf = rpcMallocCont(tlen);
|
||||
if (buf == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_META_RSP;
|
||||
((SMqRspHead*)buf)->epoch = pReq->epoch;
|
||||
((SMqRspHead*)buf)->consumerId = pReq->consumerId;
|
||||
|
||||
void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
|
||||
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, abuf, len);
|
||||
tEncodeSMqMetaRsp(&encoder, pRsp);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
SRpcMsg resp = {
|
||||
.info = pMsg->info,
|
||||
.pCont = buf,
|
||||
.contLen = tlen,
|
||||
.code = 0,
|
||||
};
|
||||
tmsgSendRsp(&resp);
|
||||
|
||||
tqDebug("vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) send rsp, res msg type %d, offset type:%d",
|
||||
TD_VID(pTq->pVnode), pReq->consumerId, pReq->epoch, pRsp->resMsgType, pRsp->rspOffset.type);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t doSendDataRsp(const SRpcHandleInfo* pRpcHandleInfo, const SMqDataRsp* pRsp, int32_t epoch,
|
||||
int64_t consumerId, int32_t type) {
|
||||
int32_t len = 0;
|
||||
|
@ -240,17 +209,6 @@ int32_t tqPushDataRsp(STQ* pTq, STqPushEntry* pPushEntry) {
|
|||
}
|
||||
|
||||
int32_t tqSendDataRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataRsp* pRsp, int32_t type) {
|
||||
#if 0
|
||||
A(taosArrayGetSize(pRsp->blockData) == pRsp->blockNum);
|
||||
A(taosArrayGetSize(pRsp->blockDataLen) == pRsp->blockNum);
|
||||
|
||||
A(!pRsp->withSchema);
|
||||
A(taosArrayGetSize(pRsp->blockSchema) == 0);
|
||||
|
||||
if (pRsp->reqOffset.type == TMQ_OFFSET__LOG) {
|
||||
A(pRsp->rspOffset.version > pRsp->reqOffset.version);
|
||||
}
|
||||
#endif
|
||||
doSendDataRsp(&pMsg->info, pRsp, pReq->epoch, pReq->consumerId, type);
|
||||
|
||||
char buf1[80] = {0};
|
||||
|
@ -264,11 +222,6 @@ int32_t tqSendDataRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, con
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE bool tqOffsetLessOrEqual(const STqOffset* pLeft, const STqOffset* pRight) {
|
||||
return pLeft->val.type == TMQ_OFFSET__LOG && pRight->val.type == TMQ_OFFSET__LOG &&
|
||||
pLeft->val.version <= pRight->val.version;
|
||||
}
|
||||
|
||||
int32_t tqProcessOffsetCommitReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
|
||||
STqOffset offset = {0};
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
|
@ -341,324 +294,6 @@ int32_t tqCheckColModifiable(STQ* pTq, int64_t tbUid, int32_t colId) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tqInitDataRsp(SMqDataRsp* pRsp, const SMqPollReq* pReq, int8_t subType) {
|
||||
pRsp->reqOffset = pReq->reqOffset;
|
||||
|
||||
pRsp->blockData = taosArrayInit(0, sizeof(void*));
|
||||
pRsp->blockDataLen = taosArrayInit(0, sizeof(int32_t));
|
||||
|
||||
if (pRsp->blockData == NULL || pRsp->blockDataLen == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pRsp->withTbName = 0;
|
||||
#if 0
|
||||
pRsp->withTbName = pReq->withTbName;
|
||||
if (pRsp->withTbName) {
|
||||
pRsp->blockTbName = taosArrayInit(0, sizeof(void*));
|
||||
if (pRsp->blockTbName == NULL) {
|
||||
// TODO free
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
pRsp->withSchema = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tqInitTaosxRsp(STaosxRsp* pRsp, const SMqPollReq* pReq) {
|
||||
pRsp->reqOffset = pReq->reqOffset;
|
||||
|
||||
pRsp->withTbName = 1;
|
||||
pRsp->withSchema = 1;
|
||||
pRsp->blockData = taosArrayInit(0, sizeof(void*));
|
||||
pRsp->blockDataLen = taosArrayInit(0, sizeof(int32_t));
|
||||
pRsp->blockTbName = taosArrayInit(0, sizeof(void*));
|
||||
pRsp->blockSchema = taosArrayInit(0, sizeof(void*));
|
||||
|
||||
if (pRsp->blockData == NULL || pRsp->blockDataLen == NULL || pRsp->blockTbName == NULL || pRsp->blockSchema == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t extractResetOffsetVal(STqOffsetVal* pOffsetVal, STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
|
||||
SRpcMsg* pMsg, bool* pBlockReturned) {
|
||||
uint64_t consumerId = pRequest->consumerId;
|
||||
STqOffsetVal reqOffset = pRequest->reqOffset;
|
||||
STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, pRequest->subKey);
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
|
||||
*pBlockReturned = false;
|
||||
|
||||
// In this vnode, data has been polled by consumer for this topic, so let's continue from the last offset value.
|
||||
if (pOffset != NULL) {
|
||||
*pOffsetVal = pOffset->val;
|
||||
|
||||
char formatBuf[80];
|
||||
tFormatOffset(formatBuf, 80, pOffsetVal);
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64
|
||||
", subkey %s, vgId:%d, existed offset found, offset reset to %s and continue. reqId:0x%" PRIx64,
|
||||
consumerId, pHandle->subKey, vgId, formatBuf, pRequest->reqId);
|
||||
return 0;
|
||||
} else {
|
||||
// no poll occurs in this vnode for this topic, let's seek to the right offset value.
|
||||
if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEAST) {
|
||||
if (pRequest->useSnapshot) {
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey:%s, vgId:%d, (earliest) set offset to be snapshot",
|
||||
consumerId, pHandle->subKey, vgId);
|
||||
|
||||
if (pHandle->fetchMeta) {
|
||||
tqOffsetResetToMeta(pOffsetVal, 0);
|
||||
} else {
|
||||
tqOffsetResetToData(pOffsetVal, 0, 0);
|
||||
}
|
||||
} else {
|
||||
pHandle->pRef = walRefFirstVer(pTq->pVnode->pWal, pHandle->pRef);
|
||||
if (pHandle->pRef == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tqOffsetResetToLog(pOffsetVal, pHandle->pRef->refVer - 1);
|
||||
}
|
||||
} else if (reqOffset.type == TMQ_OFFSET__RESET_LATEST) {
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
SMqDataRsp dataRsp = {0};
|
||||
tqInitDataRsp(&dataRsp, pRequest, pHandle->execHandle.subType);
|
||||
|
||||
tqOffsetResetToLog(&dataRsp.rspOffset, walGetLastVer(pTq->pVnode->pWal));
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, (latest) offset reset to %" PRId64, consumerId,
|
||||
pHandle->subKey, vgId, dataRsp.rspOffset.version);
|
||||
int32_t code = tqSendDataRsp(pTq, pMsg, pRequest, &dataRsp, TMQ_MSG_TYPE__POLL_RSP);
|
||||
tDeleteSMqDataRsp(&dataRsp);
|
||||
|
||||
*pBlockReturned = true;
|
||||
return code;
|
||||
} else {
|
||||
STaosxRsp taosxRsp = {0};
|
||||
tqInitTaosxRsp(&taosxRsp, pRequest);
|
||||
tqOffsetResetToLog(&taosxRsp.rspOffset, walGetLastVer(pTq->pVnode->pWal));
|
||||
int32_t code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
|
||||
*pBlockReturned = true;
|
||||
return code;
|
||||
}
|
||||
} else if (reqOffset.type == TMQ_OFFSET__RESET_NONE) {
|
||||
tqError("tmq poll: subkey:%s, no offset committed for consumer:0x%" PRIx64
|
||||
" in vg %d, subkey %s, reset none failed",
|
||||
pHandle->subKey, consumerId, vgId, pRequest->subKey);
|
||||
terrno = TSDB_CODE_TQ_NO_COMMITTED_OFFSET;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define IS_OFFSET_RESET_TYPE(_t) ((_t) < 0)
|
||||
|
||||
static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
|
||||
SRpcMsg* pMsg, STqOffsetVal* pOffset) {
|
||||
int32_t code = 0;
|
||||
uint64_t consumerId = pRequest->consumerId;
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
|
||||
SMqDataRsp dataRsp = {0};
|
||||
tqInitDataRsp(&dataRsp, pRequest, pHandle->execHandle.subType);
|
||||
|
||||
// lock
|
||||
taosWLockLatch(&pTq->lock);
|
||||
|
||||
qSetTaskId(pHandle->execHandle.task, consumerId, pRequest->reqId);
|
||||
code = tqScanData(pTq, pHandle, &dataRsp, pOffset);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosWUnLockLatch(&pTq->lock);
|
||||
return code;
|
||||
}
|
||||
|
||||
// till now, all data has been transferred to consumer, new data needs to push client once arrived.
|
||||
if (dataRsp.blockNum == 0 && dataRsp.reqOffset.type == TMQ_OFFSET__LOG &&
|
||||
dataRsp.reqOffset.version == dataRsp.rspOffset.version && pHandle->consumerId == pRequest->consumerId) {
|
||||
code = tqRegisterPushEntry(pTq, pHandle, pRequest, pMsg, &dataRsp, TMQ_MSG_TYPE__POLL_RSP);
|
||||
taosWUnLockLatch(&pTq->lock);
|
||||
return code;
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pTq->lock);
|
||||
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&dataRsp, TMQ_MSG_TYPE__POLL_RSP);
|
||||
|
||||
// NOTE: this pHandle->consumerId may have been changed already.
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, rsp block:%d, offset type:%d, uid/version:%" PRId64
|
||||
", ts:%" PRId64 ", reqId:0x%" PRIx64,
|
||||
consumerId, pHandle->subKey, vgId, dataRsp.blockNum, dataRsp.rspOffset.type, dataRsp.rspOffset.uid,
|
||||
dataRsp.rspOffset.ts, pRequest->reqId);
|
||||
|
||||
tDeleteSMqDataRsp(&dataRsp);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t doPollDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest, SRpcMsg* pMsg) {
|
||||
int32_t code = -1;
|
||||
STqOffsetVal offset = {0};
|
||||
SWalCkHead* pCkHead = NULL;
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
|
||||
STqOffsetVal reqOffset = pRequest->reqOffset;
|
||||
uint64_t consumerId = pRequest->consumerId;
|
||||
|
||||
// 1. reset the offset if needed
|
||||
if (IS_OFFSET_RESET_TYPE(reqOffset.type)) {
|
||||
// handle the reset offset cases, according to the consumer's choice.
|
||||
bool blockReturned = false;
|
||||
code = extractResetOffsetVal(&offset, pTq, pHandle, pRequest, pMsg, &blockReturned);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
// empty block returned, quit
|
||||
if (blockReturned) {
|
||||
return 0;
|
||||
}
|
||||
} else { // use the consumer specified offset
|
||||
// the offset value can not be monotonious increase??
|
||||
offset = reqOffset;
|
||||
}
|
||||
|
||||
// this is a normal subscribe requirement
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
return extractDataAndRspForNormalSubscribe(pTq, pHandle, pRequest, pMsg, &offset);
|
||||
}
|
||||
|
||||
// todo handle the case where re-balance occurs.
|
||||
// for taosx
|
||||
SMqMetaRsp metaRsp = {0};
|
||||
STaosxRsp taosxRsp = {0};
|
||||
tqInitTaosxRsp(&taosxRsp, pRequest);
|
||||
|
||||
if (offset.type != TMQ_OFFSET__LOG) {
|
||||
if (tqScanTaosx(pTq, pHandle, &taosxRsp, &metaRsp, &offset) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (metaRsp.metaRspLen > 0) {
|
||||
code = tqSendMetaPollRsp(pTq, pMsg, pRequest, &metaRsp);
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send meta offset type:%d,uid:%" PRId64
|
||||
",ts:%" PRId64,
|
||||
consumerId, pHandle->subKey, vgId, metaRsp.rspOffset.type, metaRsp.rspOffset.uid, metaRsp.rspOffset.ts);
|
||||
taosMemoryFree(metaRsp.metaRsp);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
return code;
|
||||
}
|
||||
|
||||
if (taosxRsp.blockNum > 0) {
|
||||
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
return code;
|
||||
} else {
|
||||
offset = taosxRsp.rspOffset;
|
||||
}
|
||||
|
||||
tqDebug("taosx poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send data blockNum:%d, offset type:%d,uid:%" PRId64
|
||||
",version:%" PRId64,
|
||||
consumerId, pHandle->subKey, vgId, taosxRsp.blockNum, taosxRsp.rspOffset.type, taosxRsp.rspOffset.uid,
|
||||
taosxRsp.rspOffset.version);
|
||||
}
|
||||
|
||||
if (offset.type == TMQ_OFFSET__LOG) {
|
||||
int64_t fetchVer = offset.version + 1;
|
||||
pCkHead = taosMemoryMalloc(sizeof(SWalCkHead) + 2048);
|
||||
if (pCkHead == NULL) {
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
walSetReaderCapacity(pHandle->pWalReader, 2048);
|
||||
int totalRows = 0;
|
||||
while (1) {
|
||||
// todo refactor: this is not correct.
|
||||
int32_t savedEpoch = atomic_load_32(&pHandle->epoch);
|
||||
if (savedEpoch > pRequest->epoch) {
|
||||
tqWarn("tmq poll: consumer:0x%" PRIx64 " (epoch %d), subkey:%s vgId:%d offset %" PRId64
|
||||
", found new consumer epoch %d, discard req epoch %d",
|
||||
consumerId, pRequest->epoch, pHandle->subKey, vgId, fetchVer, savedEpoch, pRequest->epoch);
|
||||
break;
|
||||
}
|
||||
|
||||
if (tqFetchLog(pTq, pHandle, &fetchVer, &pCkHead, pRequest->reqId) < 0) {
|
||||
tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);
|
||||
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
return code;
|
||||
}
|
||||
|
||||
SWalCont* pHead = &pCkHead->head;
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, vgId:%d offset %" PRId64 " msgType %d", consumerId,
|
||||
pRequest->epoch, vgId, fetchVer, pHead->msgType);
|
||||
|
||||
// process meta
|
||||
if (pHead->msgType != TDMT_VND_SUBMIT) {
|
||||
if (totalRows > 0) {
|
||||
tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer - 1);
|
||||
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
return code;
|
||||
}
|
||||
|
||||
tqDebug("fetch meta msg, ver:%" PRId64 ", type:%s", pHead->version, TMSG_INFO(pHead->msgType));
|
||||
tqOffsetResetToLog(&metaRsp.rspOffset, fetchVer);
|
||||
metaRsp.resMsgType = pHead->msgType;
|
||||
metaRsp.metaRspLen = pHead->bodyLen;
|
||||
metaRsp.metaRsp = pHead->body;
|
||||
if (tqSendMetaPollRsp(pTq, pMsg, pRequest, &metaRsp) < 0) {
|
||||
code = -1;
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
return code;
|
||||
}
|
||||
code = 0;
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
return code;
|
||||
}
|
||||
|
||||
// process data
|
||||
SPackedData submit = {
|
||||
.msgStr = POINTER_SHIFT(pHead->body, sizeof(SSubmitReq2Msg)),
|
||||
.msgLen = pHead->bodyLen - sizeof(SSubmitReq2Msg),
|
||||
.ver = pHead->version,
|
||||
};
|
||||
|
||||
if (tqTaosxScanLog(pTq, pHandle, submit, &taosxRsp, &totalRows) < 0) {
|
||||
tqError("tmq poll: tqTaosxScanLog error %" PRId64 ", in vgId:%d, subkey %s", consumerId, vgId,
|
||||
pRequest->subKey);
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (totalRows >= 4096 || taosxRsp.createTableNum > 0) {
|
||||
tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);
|
||||
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
return code;
|
||||
} else {
|
||||
fetchVer++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||
SMqPollReq req = {0};
|
||||
if (tDeserializeSMqPollReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
|
||||
|
@ -706,7 +341,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d), subkey %s, recv poll req vgId:%d, req:%s, reqId:0x%" PRIx64,
|
||||
consumerId, req.epoch, pHandle->subKey, vgId, buf, req.reqId);
|
||||
|
||||
return doPollDataForMq(pTq, pHandle, &req, pMsg);
|
||||
return tqExtractDataForMq(pTq, pHandle, &req, pMsg);
|
||||
}
|
||||
|
||||
int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
|
||||
|
@ -821,13 +456,7 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
|
|||
pHandle->pRef = pRef;
|
||||
|
||||
SReadHandle handle = {
|
||||
.meta = pVnode->pMeta,
|
||||
.vnode = pVnode,
|
||||
.initTableReader = true,
|
||||
.initTqReader = true,
|
||||
.version = ver,
|
||||
};
|
||||
|
||||
.meta = pVnode->pMeta, .vnode = pVnode, .initTableReader = true, .initTqReader = true, .version = ver};
|
||||
pHandle->snapshotVer = ver;
|
||||
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
|
@ -838,10 +467,10 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
|
|||
&pHandle->execHandle.numOfCols, req.newConsumerId);
|
||||
void* scanner = NULL;
|
||||
qExtractStreamScanner(pHandle->execHandle.task, &scanner);
|
||||
pHandle->execHandle.pExecReader = qExtractReaderFromStreamScanner(scanner);
|
||||
pHandle->execHandle.pTqReader = qExtractReaderFromStreamScanner(scanner);
|
||||
} else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
|
||||
pHandle->pWalReader = walOpenReader(pVnode->pWal, NULL);
|
||||
pHandle->execHandle.pExecReader = tqOpenReader(pVnode);
|
||||
pHandle->execHandle.pTqReader = tqOpenReader(pVnode);
|
||||
|
||||
pHandle->execHandle.execDb.pFilterOutTbUid =
|
||||
taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||
|
@ -860,8 +489,8 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
|
|||
int64_t tbUid = *(int64_t*)taosArrayGet(tbUidList, i);
|
||||
tqDebug("vgId:%d, idx %d, uid:%" PRId64, vgId, i, tbUid);
|
||||
}
|
||||
pHandle->execHandle.pExecReader = tqOpenReader(pVnode);
|
||||
tqReaderSetTbUidList(pHandle->execHandle.pExecReader, tbUidList);
|
||||
pHandle->execHandle.pTqReader = tqOpenReader(pVnode);
|
||||
tqReaderSetTbUidList(pHandle->execHandle.pTqReader, tbUidList);
|
||||
taosArrayDestroy(tbUidList);
|
||||
|
||||
buildSnapContext(handle.meta, handle.version, req.suid, pHandle->execHandle.subType, pHandle->fetchMeta,
|
||||
|
@ -897,7 +526,7 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
|
|||
atomic_store_32(&pHandle->epoch, -1);
|
||||
|
||||
// remove if it has been register in the push manager, and return one empty block to consumer
|
||||
tqUnregisterPushEntry(pTq, req.subKey, (int32_t)strlen(req.subKey), pHandle->consumerId, true);
|
||||
tqUnregisterPushHandle(pTq, req.subKey, (int32_t)strlen(req.subKey), pHandle->consumerId, true);
|
||||
|
||||
atomic_store_64(&pHandle->consumerId, req.newConsumerId);
|
||||
atomic_add_fetch_32(&pHandle->epoch, 1);
|
||||
|
@ -919,16 +548,14 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
|
|||
}
|
||||
|
||||
int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) {
|
||||
#if 0
|
||||
if (pTask->taskLevel == TASK_LEVEL__AGG) {
|
||||
A(taosArrayGetSize(pTask->childEpInfo) != 0);
|
||||
}
|
||||
#endif
|
||||
// todo extract method
|
||||
char buf[128] = {0};
|
||||
sprintf(buf, "0x%"PRIx64"-%d", pTask->id.streamId, pTask->id.taskId);
|
||||
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
pTask->id.idStr = taosStrdup(buf);
|
||||
pTask->refCnt = 1;
|
||||
pTask->schedStatus = TASK_SCHED_STATUS__INACTIVE;
|
||||
|
||||
pTask->status.schedStatus = TASK_SCHED_STATUS__INACTIVE;
|
||||
pTask->inputQueue = streamQueueOpen(512 << 10);
|
||||
pTask->outputQueue = streamQueueOpen(512 << 10);
|
||||
|
||||
|
@ -939,11 +566,13 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) {
|
|||
pTask->inputStatus = TASK_INPUT_STATUS__NORMAL;
|
||||
pTask->outputStatus = TASK_OUTPUT_STATUS__NORMAL;
|
||||
pTask->pMsgCb = &pTq->pVnode->msgCb;
|
||||
pTask->startVer = ver;
|
||||
pTask->pMeta = pTq->pStreamMeta;
|
||||
|
||||
// expand executor
|
||||
if (pTask->fillHistory) {
|
||||
pTask->taskStatus = TASK_STATUS__WAIT_DOWNSTREAM;
|
||||
pTask->status.taskStatus = TASK_STATUS__WAIT_DOWNSTREAM;
|
||||
} else {
|
||||
pTask->status.taskStatus = TASK_STATUS__RESTORE;
|
||||
}
|
||||
|
||||
if (pTask->taskLevel == TASK_LEVEL__SOURCE) {
|
||||
|
@ -953,14 +582,10 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) {
|
|||
}
|
||||
|
||||
SReadHandle handle = {
|
||||
.meta = pTq->pVnode->pMeta,
|
||||
.vnode = pTq->pVnode,
|
||||
.initTqReader = 1,
|
||||
.pStateBackend = pTask->pState,
|
||||
};
|
||||
.meta = pTq->pVnode->pMeta, .vnode = pTq->pVnode, .initTqReader = 1, .pStateBackend = pTask->pState};
|
||||
|
||||
pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle, vgId);
|
||||
if (pTask->exec.executor == NULL) {
|
||||
pTask->exec.pExecutor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle, vgId);
|
||||
if (pTask->exec.pExecutor == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -969,14 +594,12 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) {
|
|||
if (pTask->pState == NULL) {
|
||||
return -1;
|
||||
}
|
||||
SReadHandle mgHandle = {
|
||||
.vnode = NULL,
|
||||
.numOfVgroups = (int32_t)taosArrayGetSize(pTask->childEpInfo),
|
||||
.pStateBackend = pTask->pState,
|
||||
};
|
||||
|
||||
pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &mgHandle, vgId);
|
||||
if (pTask->exec.executor == NULL) {
|
||||
int32_t numOfVgroups = (int32_t)taosArrayGetSize(pTask->childEpInfo);
|
||||
SReadHandle mgHandle = { .vnode = NULL, .numOfVgroups = numOfVgroups, .pStateBackend = pTask->pState};
|
||||
|
||||
pTask->exec.pExecutor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &mgHandle, vgId);
|
||||
if (pTask->exec.pExecutor == NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -997,16 +620,31 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) {
|
|||
ver1 = info.skmVer;
|
||||
}
|
||||
|
||||
pTask->tbSink.pTSchema =
|
||||
tBuildTSchema(pTask->tbSink.pSchemaWrapper->pSchema, pTask->tbSink.pSchemaWrapper->nCols, ver1);
|
||||
if (pTask->tbSink.pTSchema == NULL) {
|
||||
SSchemaWrapper* pschemaWrapper = pTask->tbSink.pSchemaWrapper;
|
||||
pTask->tbSink.pTSchema = tBuildTSchema(pschemaWrapper->pSchema, pschemaWrapper->nCols, ver1);
|
||||
if(pTask->tbSink.pTSchema == NULL) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pTask->taskLevel == TASK_LEVEL__SOURCE) {
|
||||
pTask->exec.pTqReader = tqOpenReader(pTq->pVnode);
|
||||
if (pTask->exec.pTqReader == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pTask->exec.pWalReader = walOpenReader(pTq->pVnode->pWal, NULL);
|
||||
|
||||
pTask->freeFp = (_free_reader_fn_t)tqCloseReader;
|
||||
SArray* pList = qGetQueriedTableListInfo(pTask->exec.pExecutor);
|
||||
tqReaderAddTbUidList(pTask->exec.pTqReader, pList);
|
||||
taosArrayDestroy(pList);
|
||||
}
|
||||
|
||||
streamSetupTrigger(pTask);
|
||||
tqInfo("expand stream task on vg %d, task id %d, child id %d, level %d", vgId, pTask->taskId, pTask->selfChildId,
|
||||
pTask->taskLevel);
|
||||
tqInfo("vgId:%d expand stream task, s-task:%s, ver:%" PRId64 " child id:%d, level:%d", vgId, pTask->id.idStr,
|
||||
pTask->chkInfo.version, pTask->selfChildId, pTask->taskLevel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1029,8 +667,9 @@ int32_t tqProcessStreamTaskCheckReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
.upstreamNodeId = req.upstreamNodeId,
|
||||
.upstreamTaskId = req.upstreamTaskId,
|
||||
};
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pTq->pStreamMeta, taskId);
|
||||
if (pTask && atomic_load_8(&pTask->taskStatus) == TASK_STATUS__NORMAL) {
|
||||
if (pTask && atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__NORMAL) {
|
||||
rsp.status = 1;
|
||||
} else {
|
||||
rsp.status = 0;
|
||||
|
@ -1113,17 +752,20 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t sversion, char* msg, int32_t ms
|
|||
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, (uint8_t*)msg, msgLen);
|
||||
code = tDecodeSStreamTask(&decoder, pTask);
|
||||
code = tDecodeStreamTask(&decoder, pTask);
|
||||
if (code < 0) {
|
||||
tDecoderClear(&decoder);
|
||||
taosMemoryFree(pTask);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
|
||||
// 2.save task
|
||||
code = streamMetaAddTask(pTq->pStreamMeta, sversion, pTask);
|
||||
code = streamMetaAddDeployedTask(pTq->pStreamMeta, sversion, pTask);
|
||||
if (code < 0) {
|
||||
tqError("vgId:%d failed to add s-task:%s, total:%d", TD_VID(pTq->pVnode), pTask->id.idStr,
|
||||
streamMetaGetNumOfTasks(pTq->pStreamMeta));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1132,6 +774,8 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t sversion, char* msg, int32_t ms
|
|||
streamTaskCheckDownstream(pTask, sversion);
|
||||
}
|
||||
|
||||
tqDebug("vgId:%d s-task:%s is deployed from mnd, status:%d, total:%d", TD_VID(pTq->pVnode), pTask->id.idStr,
|
||||
pTask->status.taskStatus, streamMetaGetNumOfTasks(pTq->pStreamMeta));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1147,7 +791,7 @@ int32_t tqProcessTaskRecover1Req(STQ* pTq, SRpcMsg* pMsg) {
|
|||
}
|
||||
|
||||
// check param
|
||||
int64_t fillVer1 = pTask->startVer;
|
||||
int64_t fillVer1 = pTask->chkInfo.version;
|
||||
if (fillVer1 <= 0) {
|
||||
streamMetaReleaseTask(pTq->pStreamMeta, pTask);
|
||||
return -1;
|
||||
|
@ -1156,7 +800,7 @@ int32_t tqProcessTaskRecover1Req(STQ* pTq, SRpcMsg* pMsg) {
|
|||
// do recovery step 1
|
||||
streamSourceRecoverScanStep1(pTask);
|
||||
|
||||
if (atomic_load_8(&pTask->taskStatus) == TASK_STATUS__DROPPING) {
|
||||
if (atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__DROPPING) {
|
||||
streamMetaReleaseTask(pTq->pStreamMeta, pTask);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1171,7 +815,7 @@ int32_t tqProcessTaskRecover1Req(STQ* pTq, SRpcMsg* pMsg) {
|
|||
|
||||
streamMetaReleaseTask(pTq->pStreamMeta, pTask);
|
||||
|
||||
if (atomic_load_8(&pTask->taskStatus) == TASK_STATUS__DROPPING) {
|
||||
if (atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__DROPPING) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1213,7 +857,7 @@ int32_t tqProcessTaskRecover2Req(STQ* pTq, int64_t sversion, char* msg, int32_t
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (atomic_load_8(&pTask->taskStatus) == TASK_STATUS__DROPPING) {
|
||||
if (atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__DROPPING) {
|
||||
streamMetaReleaseTask(pTq->pStreamMeta, pTask);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1332,7 +976,7 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
|
|||
SStreamTask* pTask = *(SStreamTask**)pIter;
|
||||
if (pTask->taskLevel != TASK_LEVEL__SOURCE) continue;
|
||||
|
||||
qDebug("delete req enqueue stream task: %d, ver: %" PRId64, pTask->taskId, ver);
|
||||
qDebug("delete req enqueue stream task: %d, ver: %" PRId64, pTask->id.taskId, ver);
|
||||
|
||||
if (!failed) {
|
||||
SStreamRefDataBlock* pRefBlock = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0);
|
||||
|
@ -1341,8 +985,8 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
|
|||
pRefBlock->dataRef = pRef;
|
||||
atomic_add_fetch_32(pRefBlock->dataRef, 1);
|
||||
|
||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pRefBlock) < 0) {
|
||||
qError("stream task input del failed, task id %d", pTask->taskId);
|
||||
if (tAppendDataToInputQueue(pTask, (SStreamQueueItem*)pRefBlock) < 0) {
|
||||
qError("stream task input del failed, task id %d", pTask->id.taskId);
|
||||
|
||||
atomic_sub_fetch_32(pRef, 1);
|
||||
taosFreeQitem(pRefBlock);
|
||||
|
@ -1350,7 +994,7 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
|
|||
}
|
||||
|
||||
if (streamSchedExec(pTask) < 0) {
|
||||
qError("stream task launch failed, task id %d", pTask->taskId);
|
||||
qError("stream task launch failed, task id %d", pTask->id.taskId);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1376,13 +1020,13 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
|
|||
taosArrayPush(pStreamBlock->blocks, &block);
|
||||
|
||||
if (!failed) {
|
||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pStreamBlock) < 0) {
|
||||
qError("stream task input del failed, task id %d", pTask->taskId);
|
||||
if (tAppendDataToInputQueue(pTask, (SStreamQueueItem*)pStreamBlock) < 0) {
|
||||
qError("stream task input del failed, task id %d", pTask->id.taskId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (streamSchedExec(pTask) < 0) {
|
||||
qError("stream task launch failed, task id %d", pTask->taskId);
|
||||
qError("stream task launch failed, task id %d", pTask->id.taskId);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
|
@ -1395,18 +1039,32 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqProcessSubmitReq(STQ* pTq, SPackedData submit) {
|
||||
void* pIter = NULL;
|
||||
bool failed = false;
|
||||
SStreamDataSubmit2* pSubmit = NULL;
|
||||
static int32_t addSubmitBlockNLaunchTask(STqOffsetStore* pOffsetStore, SStreamTask* pTask, SStreamDataSubmit2* pSubmit,
|
||||
const char* key, int64_t ver) {
|
||||
doSaveTaskOffset(pOffsetStore, key, ver);
|
||||
int32_t code = tqAddInputBlockNLaunchTask(pTask, (SStreamQueueItem*)pSubmit, ver);
|
||||
|
||||
pSubmit = streamDataSubmitNew(submit);
|
||||
// remove the offset, if all functions are completed successfully.
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
tqOffsetDelete(pOffsetStore, key);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqProcessSubmitReq(STQ* pTq, SPackedData submit) {
|
||||
#if 0
|
||||
void* pIter = NULL;
|
||||
SStreamDataSubmit2* pSubmit = streamDataSubmitNew(submit, STREAM_INPUT__DATA_SUBMIT);
|
||||
if (pSubmit == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tqError("failed to create data submit for stream since out of memory");
|
||||
failed = true;
|
||||
saveOffsetForAllTasks(pTq, submit.ver);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SArray* pInputQueueFullTasks = taosArrayInit(4, POINTER_BYTES);
|
||||
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pTq->pStreamMeta->pTasks, pIter);
|
||||
if (pIter == NULL) {
|
||||
|
@ -1414,46 +1072,80 @@ int32_t tqProcessSubmitReq(STQ* pTq, SPackedData submit) {
|
|||
}
|
||||
|
||||
SStreamTask* pTask = *(SStreamTask**)pIter;
|
||||
if (pTask->taskLevel != TASK_LEVEL__SOURCE) continue;
|
||||
if (pTask->taskStatus == TASK_STATUS__RECOVER_PREPARE || pTask->taskStatus == TASK_STATUS__WAIT_DOWNSTREAM) {
|
||||
tqDebug("skip push task %d, task status %d", pTask->taskId, pTask->taskStatus);
|
||||
if (pTask->taskLevel != TASK_LEVEL__SOURCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
tqDebug("data submit enqueue stream task: %d, ver: %" PRId64, pTask->taskId, submit.ver);
|
||||
|
||||
if (!failed) {
|
||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pSubmit) < 0) {
|
||||
tqError("stream task input failed, task id %d", pTask->taskId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (streamSchedExec(pTask) < 0) {
|
||||
tqError("stream task launch failed, task id %d", pTask->taskId);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
streamTaskInputFail(pTask);
|
||||
if (pTask->status.taskStatus == TASK_STATUS__RECOVER_PREPARE || pTask->status.taskStatus == TASK_STATUS__WAIT_DOWNSTREAM) {
|
||||
tqDebug("stream task:%d skip push data, not ready for processing, status %d", pTask->id.taskId,
|
||||
pTask->status.taskStatus);
|
||||
continue;
|
||||
}
|
||||
|
||||
// check if offset value exists
|
||||
char key[128] = {0};
|
||||
createStreamTaskOffsetKey(key, pTask->id.streamId, pTask->id.taskId);
|
||||
|
||||
if (tInputQueueIsFull(pTask)) {
|
||||
STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, key);
|
||||
|
||||
int64_t ver = submit.ver;
|
||||
if (pOffset == NULL) {
|
||||
doSaveTaskOffset(pTq->pOffsetStore, key, submit.ver);
|
||||
} else {
|
||||
ver = pOffset->val.version;
|
||||
}
|
||||
|
||||
tqDebug("s-task:%s input queue is full, discard submit block, ver:%" PRId64, pTask->id.idStr, ver);
|
||||
taosArrayPush(pInputQueueFullTasks, &pTask);
|
||||
continue;
|
||||
}
|
||||
|
||||
// check if offset value exists
|
||||
STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, key);
|
||||
ASSERT(pOffset == NULL);
|
||||
|
||||
addSubmitBlockNLaunchTask(pTq->pOffsetStore, pTask, pSubmit, key, submit.ver);
|
||||
}
|
||||
|
||||
if (pSubmit) {
|
||||
streamDataSubmitRefDec(pSubmit);
|
||||
taosFreeQitem(pSubmit);
|
||||
}
|
||||
streamDataSubmitDestroy(pSubmit);
|
||||
taosFreeQitem(pSubmit);
|
||||
#endif
|
||||
|
||||
return failed ? -1 : 0;
|
||||
tqStartStreamTasks(pTq);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||
SStreamTaskRunReq* pReq = pMsg->pCont;
|
||||
int32_t taskId = pReq->taskId;
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pTq->pStreamMeta, taskId);
|
||||
if (pTask) {
|
||||
streamProcessRunReq(pTask);
|
||||
|
||||
int32_t taskId = pReq->taskId;
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
|
||||
if (taskId == WAL_READ_TASKS_ID) { // all tasks are extracted submit data from the wal
|
||||
tqStreamTasksScanWal(pTq);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTaskEx(pTq->pStreamMeta, taskId);
|
||||
if (pTask != NULL) {
|
||||
if (pTask->status.taskStatus == TASK_STATUS__NORMAL) {
|
||||
tqDebug("vgId:%d s-task:%s start to process run req", vgId, pTask->id.idStr);
|
||||
streamProcessRunReq(pTask);
|
||||
} else if (pTask->status.taskStatus == TASK_STATUS__RESTORE) {
|
||||
tqDebug("vgId:%d s-task:%s start to process block from wal, last chk point:%" PRId64, vgId,
|
||||
pTask->id.idStr, pTask->chkInfo.version);
|
||||
streamProcessRunReq(pTask);
|
||||
} else {
|
||||
tqDebug("vgId:%d s-task:%s ignore run req since not in ready state", vgId, pTask->id.idStr);
|
||||
}
|
||||
|
||||
streamMetaReleaseTask(pTq->pStreamMeta, pTask);
|
||||
|
||||
tqStartStreamTasks(pTq);
|
||||
return 0;
|
||||
} else {
|
||||
tqError("vgId:%d failed to found s-task, taskId:%d", vgId, taskId);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -1466,14 +1158,10 @@ int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg, bool exec) {
|
|||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, (uint8_t*)msgBody, msgLen);
|
||||
tDecodeStreamDispatchReq(&decoder, &req);
|
||||
int32_t taskId = req.taskId;
|
||||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pTq->pStreamMeta, taskId);
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pTq->pStreamMeta, req.taskId);
|
||||
if (pTask) {
|
||||
SRpcMsg rsp = {
|
||||
.info = pMsg->info,
|
||||
.code = 0,
|
||||
};
|
||||
SRpcMsg rsp = { .info = pMsg->info, .code = 0 };
|
||||
streamProcessDispatchReq(pTask, &req, &rsp, exec);
|
||||
streamMetaReleaseTask(pTq->pStreamMeta, pTask);
|
||||
return 0;
|
||||
|
@ -1486,7 +1174,7 @@ int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg) {
|
|||
SStreamDispatchRsp* pRsp = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
||||
int32_t taskId = ntohl(pRsp->upstreamTaskId);
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pTq->pStreamMeta, taskId);
|
||||
tqDebug("recv dispatch rsp, code: %x", pMsg->code);
|
||||
tqDebug("recv dispatch rsp, code:%x", pMsg->code);
|
||||
if (pTask) {
|
||||
streamProcessDispatchRsp(pTask, pRsp, pMsg->code);
|
||||
streamMetaReleaseTask(pTq->pStreamMeta, pTask);
|
||||
|
@ -1514,10 +1202,7 @@ int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
int32_t taskId = req.dstTaskId;
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pTq->pStreamMeta, taskId);
|
||||
if (pTask) {
|
||||
SRpcMsg rsp = {
|
||||
.info = pMsg->info,
|
||||
.code = 0,
|
||||
};
|
||||
SRpcMsg rsp = { .info = pMsg->info, .code = 0 };
|
||||
streamProcessRetrieveReq(pTask, &req, &rsp);
|
||||
streamMetaReleaseTask(pTq->pStreamMeta, pTask);
|
||||
tDeleteStreamRetrieveReq(&req);
|
||||
|
@ -1553,15 +1238,14 @@ int32_t vnodeEnqueueStreamMsg(SVnode* pVnode, SRpcMsg* pMsg) {
|
|||
|
||||
SStreamTask* pTask = streamMetaAcquireTask(pTq->pStreamMeta, taskId);
|
||||
if (pTask) {
|
||||
SRpcMsg rsp = {
|
||||
.info = pMsg->info,
|
||||
.code = 0,
|
||||
};
|
||||
SRpcMsg rsp = { .info = pMsg->info, .code = 0 };
|
||||
streamProcessDispatchReq(pTask, &req, &rsp, false);
|
||||
streamMetaReleaseTask(pTq->pStreamMeta, pTask);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
return 0;
|
||||
} else {
|
||||
tDeleteStreamDispatchReq(&req);
|
||||
}
|
||||
|
||||
code = TSDB_CODE_STREAM_TASK_NOT_EXIST;
|
||||
|
@ -1571,10 +1255,7 @@ FAIL:
|
|||
|
||||
SMsgHead* pRspHead = rpcMallocCont(sizeof(SMsgHead) + sizeof(SStreamDispatchRsp));
|
||||
if (pRspHead == NULL) {
|
||||
SRpcMsg rsp = {
|
||||
.code = TSDB_CODE_OUT_OF_MEMORY,
|
||||
.info = pMsg->info,
|
||||
};
|
||||
SRpcMsg rsp = { .code = TSDB_CODE_OUT_OF_MEMORY, .info = pMsg->info };
|
||||
tqDebug("send dispatch error rsp, code: %x", code);
|
||||
tmsgSendRsp(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
@ -1592,11 +1273,7 @@ FAIL:
|
|||
pRsp->inputStatus = TASK_OUTPUT_STATUS__NORMAL;
|
||||
|
||||
SRpcMsg rsp = {
|
||||
.code = code,
|
||||
.info = pMsg->info,
|
||||
.contLen = sizeof(SMsgHead) + sizeof(SStreamDispatchRsp),
|
||||
.pCont = pRspHead,
|
||||
};
|
||||
.code = code, .info = pMsg->info, .contLen = sizeof(SMsgHead) + sizeof(SStreamDispatchRsp), .pCont = pRspHead};
|
||||
tqDebug("send dispatch error rsp, code: %x", code);
|
||||
tmsgSendRsp(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
@ -1605,3 +1282,40 @@ FAIL:
|
|||
}
|
||||
|
||||
int32_t tqCheckLogInWal(STQ* pTq, int64_t sversion) { return sversion <= pTq->walLogLastVer; }
|
||||
|
||||
int32_t tqStartStreamTasks(STQ* pTq) {
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
|
||||
SStreamMeta* pMeta = pTq->pStreamMeta;
|
||||
taosWLockLatch(&pMeta->lock);
|
||||
pMeta->walScan += 1;
|
||||
|
||||
if (pMeta->walScan > 1) {
|
||||
tqDebug("vgId:%d wal read task has been launched, remain scan times:%d", vgId, pMeta->walScan);
|
||||
taosWUnLockLatch(&pTq->pStreamMeta->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SStreamTaskRunReq* pRunReq = rpcMallocCont(sizeof(SStreamTaskRunReq));
|
||||
if (pRunReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tqError("vgId:%d failed restore stream tasks, code:%s", vgId, terrstr(terrno));
|
||||
taosWUnLockLatch(&pTq->pStreamMeta->lock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t numOfTasks = taosHashGetSize(pTq->pStreamMeta->pTasks);
|
||||
|
||||
tqInfo("vgId:%d start wal scan stream tasks, tasks:%d", vgId, numOfTasks);
|
||||
initOffsetForAllRestoreTasks(pTq);
|
||||
|
||||
pRunReq->head.vgId = vgId;
|
||||
pRunReq->streamId = 0;
|
||||
pRunReq->taskId = WAL_READ_TASKS_ID;
|
||||
|
||||
SRpcMsg msg = {.msgType = TDMT_STREAM_TASK_RUN, .pCont = pRunReq, .contLen = sizeof(SStreamTaskRunReq)};
|
||||
tmsgPutToQueue(&pTq->pVnode->msgCb, STREAM_QUEUE, &msg);
|
||||
taosWUnLockLatch(&pTq->pStreamMeta->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -16,10 +16,13 @@
|
|||
#include "tq.h"
|
||||
|
||||
int tqCommit(STQ* pTq) {
|
||||
#if 0
|
||||
// stream meta commit does not be aligned to the vnode commit
|
||||
if (streamMetaCommit(pTq->pStreamMeta) < 0) {
|
||||
tqError("vgId:%d, failed to commit stream meta since %s", TD_VID(pTq->pVnode), terrstr());
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return tqOffsetCommitFile(pTq->pOffsetStore);
|
||||
}
|
||||
|
|
|
@ -320,15 +320,15 @@ int32_t tqMetaRestoreHandle(STQ* pTq) {
|
|||
code = -1;
|
||||
goto end;
|
||||
}
|
||||
handle.execHandle.pExecReader = qExtractReaderFromStreamScanner(scanner);
|
||||
if (handle.execHandle.pExecReader == NULL) {
|
||||
handle.execHandle.pTqReader = qExtractReaderFromStreamScanner(scanner);
|
||||
if (handle.execHandle.pTqReader == NULL) {
|
||||
tqError("cannot extract exec reader for %s", handle.subKey);
|
||||
code = -1;
|
||||
goto end;
|
||||
}
|
||||
} else if (handle.execHandle.subType == TOPIC_SUB_TYPE__DB) {
|
||||
handle.pWalReader = walOpenReader(pTq->pVnode->pWal, NULL);
|
||||
handle.execHandle.pExecReader = tqOpenReader(pTq->pVnode);
|
||||
handle.execHandle.pTqReader = tqOpenReader(pTq->pVnode);
|
||||
|
||||
buildSnapContext(reader.meta, reader.version, 0, handle.execHandle.subType, handle.fetchMeta,
|
||||
(SSnapContext**)(&reader.sContext));
|
||||
|
@ -343,8 +343,8 @@ int32_t tqMetaRestoreHandle(STQ* pTq) {
|
|||
int64_t tbUid = *(int64_t*)taosArrayGet(tbUidList, i);
|
||||
tqDebug("vgId:%d, idx %d, uid:%" PRId64, vgId, i, tbUid);
|
||||
}
|
||||
handle.execHandle.pExecReader = tqOpenReader(pTq->pVnode);
|
||||
tqReaderSetTbUidList(handle.execHandle.pExecReader, tbUidList);
|
||||
handle.execHandle.pTqReader = tqOpenReader(pTq->pVnode);
|
||||
tqReaderSetTbUidList(handle.execHandle.pTqReader, tbUidList);
|
||||
taosArrayDestroy(tbUidList);
|
||||
|
||||
buildSnapContext(reader.meta, reader.version, handle.execHandle.execTb.suid, handle.execHandle.subType,
|
||||
|
|
|
@ -128,31 +128,35 @@ int32_t tqOffsetDelete(STqOffsetStore* pStore, const char* subscribeKey) {
|
|||
}
|
||||
|
||||
int32_t tqOffsetCommitFile(STqOffsetStore* pStore) {
|
||||
if (!pStore->needCommit) return 0;
|
||||
if (!pStore->needCommit) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO file name should be with a newer version
|
||||
char* fname = tqOffsetBuildFName(pStore->pTq->path, 0);
|
||||
TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
|
||||
int32_t err = terrno;
|
||||
const char* errStr = tstrerror(err);
|
||||
int32_t sysErr = errno;
|
||||
const char* sysErrStr = strerror(errno);
|
||||
tqError("vgId:%d, cannot open file %s when commit offset since %s", pStore->pTq->pVnode->config.vgId, fname,
|
||||
sysErrStr);
|
||||
const char* err = strerror(errno);
|
||||
tqError("vgId:%d, failed to open offset file %s, since %s", TD_VID(pStore->pTq->pVnode), fname, err);
|
||||
taosMemoryFree(fname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosMemoryFree(fname);
|
||||
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pStore->pHash, pIter);
|
||||
if (pIter == NULL) break;
|
||||
if (pIter == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
STqOffset* pOffset = (STqOffset*)pIter;
|
||||
int32_t bodyLen;
|
||||
int32_t code;
|
||||
tEncodeSize(tEncodeSTqOffset, pOffset, bodyLen, code);
|
||||
|
||||
if (code < 0) {
|
||||
taosHashCancelIterate(pStore->pHash, pIter);
|
||||
return -1;
|
||||
|
@ -166,6 +170,7 @@ int32_t tqOffsetCommitFile(STqOffsetStore* pStore) {
|
|||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, abuf, bodyLen);
|
||||
tEncodeSTqOffset(&encoder, pOffset);
|
||||
|
||||
// write file
|
||||
int64_t writeLen;
|
||||
if ((writeLen = taosWriteFile(pFile, buf, totLen)) != totLen) {
|
||||
|
@ -174,8 +179,10 @@ int32_t tqOffsetCommitFile(STqOffsetStore* pStore) {
|
|||
taosMemoryFree(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosMemoryFree(buf);
|
||||
}
|
||||
|
||||
// close and rename file
|
||||
taosCloseFile(&pFile);
|
||||
pStore->needCommit = 0;
|
||||
|
|
|
@ -30,7 +30,7 @@ static int32_t tqLoopExecFromQueue(STQ* pTq, STqHandle* pHandle, SStreamDataSubm
|
|||
// update processed
|
||||
atomic_store_64(&pHandle->pushHandle.processedVer, pSubmit->ver);
|
||||
streamQueueProcessSuccess(&pHandle->pushHandle.inputQ);
|
||||
streamDataSubmitRefDec(pSubmit);
|
||||
streamDataSubmitDestroy(pSubmit);
|
||||
if (pRsp->blockNum > 0) {
|
||||
*ppSubmit = pSubmit;
|
||||
return 0;
|
||||
|
@ -58,7 +58,7 @@ int32_t tqExecFromInputQ(STQ* pTq, STqHandle* pHandle) {
|
|||
}
|
||||
while (pHandle->pushHandle.processedVer > pSubmit->ver + 1) {
|
||||
streamQueueProcessSuccess(&pHandle->pushHandle.inputQ);
|
||||
streamDataSubmitRefDec(pSubmit);
|
||||
streamDataSubmitDestroy(pSubmit);
|
||||
pSubmit = streamQueueNextItem(&pHandle->pushHandle.inputQ);
|
||||
if (pSubmit == NULL) break;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ int32_t tqPreparePush(STQ* pTq, STqHandle* pHandle, int64_t reqId, const SRpcHan
|
|||
int32_t tqEnqueue(STqHandle* pHandle, SStreamDataSubmit* pSubmit) {
|
||||
int8_t inputStatus = atomic_load_8(&pHandle->pushHandle.inputStatus);
|
||||
if (inputStatus == TASK_INPUT_STATUS__NORMAL) {
|
||||
SStreamDataSubmit* pSubmitClone = streamSubmitRefClone(pSubmit);
|
||||
SStreamDataSubmit* pSubmitClone = streamSubmitBlockClone(pSubmit);
|
||||
if (pSubmitClone == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -212,28 +212,13 @@ typedef struct {
|
|||
} SItem;
|
||||
|
||||
static void recordPushedEntry(SArray* cachedKey, void* pIter);
|
||||
static void doRemovePushedEntry(SArray* pCachedKeys, STQ* pTq);
|
||||
|
||||
static void freeItem(void* param) {
|
||||
SItem* p = (SItem*)param;
|
||||
taosMemoryFree(p->pKey);
|
||||
}
|
||||
|
||||
static void doRemovePushedEntry(SArray* pCachedKeys, STQ* pTq) {
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
int32_t numOfKeys = (int32_t)taosArrayGetSize(pCachedKeys);
|
||||
|
||||
for (int32_t i = 0; i < numOfKeys; i++) {
|
||||
SItem* pItem = taosArrayGet(pCachedKeys, i);
|
||||
if (taosHashRemove(pTq->pPushMgr, pItem->pKey, pItem->keyLen) != 0) {
|
||||
tqError("vgId:%d, tq push hash remove key error, key: %s", vgId, (char*)pItem->pKey);
|
||||
}
|
||||
}
|
||||
|
||||
if (numOfKeys > 0) {
|
||||
tqDebug("vgId:%d, pushed %d items and remain:%d", vgId, numOfKeys, (int32_t)taosHashGetSize(pTq->pPushMgr));
|
||||
}
|
||||
}
|
||||
|
||||
static void doPushDataForEntry(void* pIter, STqExecHandle* pExec, STQ* pTq, int64_t ver, int32_t vgId, char* pData,
|
||||
int32_t dataLen, SArray* pCachedKey) {
|
||||
STqPushEntry* pPushEntry = *(STqPushEntry**)pIter;
|
||||
|
@ -253,7 +238,7 @@ static void doPushDataForEntry(void* pIter, STqExecHandle* pExec, STQ* pTq, int6
|
|||
if (qStreamSetScanMemData(pTaskInfo, submit) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
qStreamSetOpen(pTaskInfo);
|
||||
// here start to scan submit block to extract the subscribed data
|
||||
int32_t totalRows = 0;
|
||||
|
||||
|
@ -338,24 +323,34 @@ int32_t tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t v
|
|||
taosWUnLockLatch(&pTq->lock);
|
||||
}
|
||||
|
||||
// push data for stream processing
|
||||
if (!tsDisableStream && vnodeIsRoleLeader(pTq->pVnode)) {
|
||||
tqDebug("handle submit, restore:%d, size:%d", pTq->pVnode->restored, (int)taosHashGetSize(pTq->pStreamMeta->pTasks));
|
||||
|
||||
// push data for stream processing:
|
||||
// 1. the vnode has already been restored.
|
||||
// 2. the vnode should be the leader.
|
||||
// 3. the stream is not suspended yet.
|
||||
if (!tsDisableStream && vnodeIsRoleLeader(pTq->pVnode) && pTq->pVnode->restored) {
|
||||
if (taosHashGetSize(pTq->pStreamMeta->pTasks) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (msgType == TDMT_VND_SUBMIT) {
|
||||
#if 0
|
||||
void* data = taosMemoryMalloc(len);
|
||||
if (data == NULL) {
|
||||
// todo: for all stream in this vnode, keep this offset in the offset files, and wait for a moment, and then retry
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tqError("failed to copy data for stream since out of memory");
|
||||
tqError("vgId:%d, failed to copy submit data for stream processing, since out of memory", vgId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(data, pReq, len);
|
||||
SPackedData submit = {.msgStr = data, .msgLen = len, .ver = ver};
|
||||
|
||||
tqDebug("tq copy write msg %p %d %" PRId64 " from %p", data, len, ver, pReq);
|
||||
tqDebug("vgId:%d tq copy submit msg:%p len:%d ver:%" PRId64 " from %p for stream", vgId, data, len, ver, pReq);
|
||||
tqProcessSubmitReq(pTq, submit);
|
||||
#endif
|
||||
SPackedData submit = {0};
|
||||
tqProcessSubmitReq(pTq, submit);
|
||||
}
|
||||
|
||||
|
@ -367,14 +362,7 @@ int32_t tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t v
|
|||
return 0;
|
||||
}
|
||||
|
||||
void recordPushedEntry(SArray* cachedKey, void* pIter) {
|
||||
size_t kLen = 0;
|
||||
void* key = taosHashGetKey(pIter, &kLen);
|
||||
SItem item = {.pKey = strndup(key, kLen), .keyLen = kLen};
|
||||
taosArrayPush(cachedKey, &item);
|
||||
}
|
||||
|
||||
int32_t tqRegisterPushEntry(STQ* pTq, void* pHandle, const SMqPollReq* pRequest, SRpcMsg* pRpcMsg, SMqDataRsp* pDataRsp,
|
||||
int32_t tqRegisterPushHandle(STQ* pTq, void* pHandle, const SMqPollReq* pRequest, SRpcMsg* pRpcMsg, SMqDataRsp* pDataRsp,
|
||||
int32_t type) {
|
||||
uint64_t consumerId = pRequest->consumerId;
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
|
@ -411,7 +399,7 @@ int32_t tqRegisterPushEntry(STQ* pTq, void* pHandle, const SMqPollReq* pRequest,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqUnregisterPushEntry(STQ* pTq, const char* pKey, int32_t keyLen, uint64_t consumerId, bool rspConsumer) {
|
||||
int32_t tqUnregisterPushHandle(STQ* pTq, const char* pKey, int32_t keyLen, uint64_t consumerId, bool rspConsumer) {
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
STqPushEntry** pEntry = taosHashGet(pTq->pPushMgr, pKey, keyLen);
|
||||
|
||||
|
@ -431,3 +419,26 @@ int32_t tqUnregisterPushEntry(STQ* pTq, const char* pKey, int32_t keyLen, uint64
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void recordPushedEntry(SArray* cachedKey, void* pIter) {
|
||||
size_t kLen = 0;
|
||||
void* key = taosHashGetKey(pIter, &kLen);
|
||||
SItem item = {.pKey = strndup(key, kLen), .keyLen = kLen};
|
||||
taosArrayPush(cachedKey, &item);
|
||||
}
|
||||
|
||||
void doRemovePushedEntry(SArray* pCachedKeys, STQ* pTq) {
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
int32_t numOfKeys = (int32_t)taosArrayGetSize(pCachedKeys);
|
||||
|
||||
for (int32_t i = 0; i < numOfKeys; i++) {
|
||||
SItem* pItem = taosArrayGet(pCachedKeys, i);
|
||||
if (taosHashRemove(pTq->pPushMgr, pItem->pKey, pItem->keyLen) != 0) {
|
||||
tqError("vgId:%d, tq push hash remove key error, key: %s", vgId, (char*)pItem->pKey);
|
||||
}
|
||||
}
|
||||
|
||||
if (numOfKeys > 0) {
|
||||
tqDebug("vgId:%d, pushed %d items and remain:%d", vgId, numOfKeys, (int32_t)taosHashGetSize(pTq->pPushMgr));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ bool isValValidForTable(STqHandle* pHandle, SWalCont* pHead) {
|
|||
}
|
||||
|
||||
SMetaReader mr = {0};
|
||||
metaReaderInit(&mr, pHandle->execHandle.pExecReader->pVnodeMeta, 0);
|
||||
metaReaderInit(&mr, pHandle->execHandle.pTqReader->pVnodeMeta, 0);
|
||||
|
||||
if (metaGetTableEntryByName(&mr, req.tbName) < 0) {
|
||||
metaReaderClear(&mr);
|
||||
|
@ -262,8 +262,6 @@ STqReader* tqOpenReader(SVnode* pVnode) {
|
|||
}
|
||||
|
||||
pReader->pVnodeMeta = pVnode->pMeta;
|
||||
/*pReader->pMsg = NULL;*/
|
||||
pReader->ver = -1;
|
||||
pReader->pColIdList = NULL;
|
||||
pReader->cachedSchemaVer = 0;
|
||||
pReader->cachedSchemaSuid = 0;
|
||||
|
@ -290,163 +288,112 @@ void tqCloseReader(STqReader* pReader) {
|
|||
}
|
||||
// free hash
|
||||
taosHashCleanup(pReader->tbIdHash);
|
||||
tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
|
||||
taosMemoryFree(pReader);
|
||||
}
|
||||
|
||||
int32_t tqSeekVer(STqReader* pReader, int64_t ver, const char* id) {
|
||||
// todo set the correct vgId
|
||||
tqDebug("tmq poll: wal seek to version:%"PRId64" %s", ver, id);
|
||||
if (walReadSeekVer(pReader->pWalReader, ver) < 0) {
|
||||
tqDebug("tmq poll: wal reader failed to seek to ver:%"PRId64" code:%s, %s", ver, tstrerror(terrno), id);
|
||||
return -1;
|
||||
} else {
|
||||
tqDebug("tmq poll: wal reader seek to ver:%"PRId64" %s", ver, id);
|
||||
return 0;
|
||||
}
|
||||
tqDebug("wal reader seek to ver:%"PRId64" %s", ver, id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
||||
bool fromProcessedMsg = pReader->msg2.msgStr != NULL;
|
||||
int32_t extractSubmitMsgFromWal(SWalReader* pReader, SPackedData* pPackedData) {
|
||||
if (walNextValidMsg(pReader) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void* pBody = POINTER_SHIFT(pReader->pHead->head.body, sizeof(SSubmitReq2Msg));
|
||||
int32_t len = pReader->pHead->head.bodyLen - sizeof(SSubmitReq2Msg);
|
||||
int64_t ver = pReader->pHead->head.version;
|
||||
|
||||
void* data = taosMemoryMalloc(len);
|
||||
if (data == NULL) {
|
||||
// todo: for all stream in this vnode, keep this offset in the offset files, and wait for a moment, and then retry
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tqError("vgId:%d, failed to copy submit data for stream processing, since out of memory", 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(data, pBody, len);
|
||||
*pPackedData = (SPackedData){.ver = ver, .msgLen = len, .msgStr = data};
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
||||
while (1) {
|
||||
if (!fromProcessedMsg) {
|
||||
if (pReader->msg2.msgStr == NULL) {
|
||||
if (walNextValidMsg(pReader->pWalReader) < 0) {
|
||||
// pReader->ver = pReader->pWalReader->curVersion - pReader->pWalReader->curStopped;
|
||||
if(pReader->pWalReader->curInvalid == 0){
|
||||
pReader->ver = pReader->pWalReader->curVersion - pReader->pWalReader->curStopped;
|
||||
}else{
|
||||
pReader->ver = walGetLastVer(pReader->pWalReader->pWal);
|
||||
}
|
||||
ret->offset.type = TMQ_OFFSET__LOG;
|
||||
|
||||
ret->offset.version = pReader->ver;
|
||||
ret->fetchType = FETCH_TYPE__NONE;
|
||||
tqDebug("return offset %" PRId64 ", no more valid msg in wal", ret->offset.version);
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
|
||||
void* body = POINTER_SHIFT(pReader->pWalReader->pHead->head.body, sizeof(SSubmitReq2Msg));
|
||||
void* pBody = POINTER_SHIFT(pReader->pWalReader->pHead->head.body, sizeof(SSubmitReq2Msg));
|
||||
int32_t bodyLen = pReader->pWalReader->pHead->head.bodyLen - sizeof(SSubmitReq2Msg);
|
||||
int64_t ver = pReader->pWalReader->pHead->head.version;
|
||||
|
||||
tqReaderSetSubmitReq2(pReader, body, bodyLen, ver);
|
||||
tqReaderSetSubmitMsg(pReader, pBody, bodyLen, ver);
|
||||
}
|
||||
|
||||
while (tqNextDataBlock2(pReader)) {
|
||||
// TODO mem free
|
||||
while (tqNextDataBlock(pReader)) {
|
||||
memset(&ret->data, 0, sizeof(SSDataBlock));
|
||||
int32_t code = tqRetrieveDataBlock2(&ret->data, pReader, NULL);
|
||||
if (code != 0 || ret->data.info.rows == 0) {
|
||||
continue;
|
||||
}
|
||||
ret->fetchType = FETCH_TYPE__DATA;
|
||||
tqDebug("return data rows %" PRId64, ret->data.info.rows);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (fromProcessedMsg) {
|
||||
ret->offset.type = TMQ_OFFSET__LOG;
|
||||
ret->offset.version = pReader->ver;
|
||||
ret->fetchType = FETCH_TYPE__SEP;
|
||||
tqDebug("return offset %" PRId64 ", processed finish", ret->offset.version);
|
||||
return 0;
|
||||
ret->fetchType = FETCH_TYPE__DATA;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
int32_t tqReaderSetDataMsg(STqReader* pReader, const SSubmitReq* pMsg, int64_t ver) {
|
||||
pReader->pMsg = pMsg;
|
||||
|
||||
// if (tInitSubmitMsgIter(pMsg, &pReader->msgIter) < 0) return -1;
|
||||
// while (true) {
|
||||
// if (tGetSubmitMsgNext(&pReader->msgIter, &pReader->pBlock) < 0) return -1;
|
||||
// tqDebug("submitnext vgId:%d, block:%p, dataLen:%d, len:%d, uid:%"PRId64, pWalReader->pWal->cfg.vgId, pReader->pBlock, pReader->msgIter.dataLen,
|
||||
// pReader->msgIter.len, pReader->msgIter.uid);
|
||||
// if (pReader->pBlock == NULL) break;
|
||||
// }
|
||||
|
||||
if (tInitSubmitMsgIter(pMsg, &pReader->msgIter) < 0) return -1;
|
||||
pReader->ver = ver;
|
||||
memset(&pReader->blkIter, 0, sizeof(SSubmitBlkIter));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tqReaderSetSubmitReq2(STqReader* pReader, void* msgStr, int32_t msgLen, int64_t ver) {
|
||||
ASSERT(pReader->msg2.msgStr == NULL && msgStr && msgLen && (ver >= 0));
|
||||
|
||||
int32_t tqReaderSetSubmitMsg(STqReader* pReader, void* msgStr, int32_t msgLen, int64_t ver) {
|
||||
pReader->msg2.msgStr = msgStr;
|
||||
pReader->msg2.msgLen = msgLen;
|
||||
pReader->msg2.ver = ver;
|
||||
pReader->ver = ver;
|
||||
|
||||
tqDebug("tq reader set msg %p %d", msgStr, msgLen);
|
||||
|
||||
if (pReader->setMsg == 0) {
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, pReader->msg2.msgStr, pReader->msg2.msgLen);
|
||||
if (tDecodeSSubmitReq2(&decoder, &pReader->submit) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, pReader->msg2.msgStr, pReader->msg2.msgLen);
|
||||
if (tDecodeSSubmitReq2(&decoder, &pReader->submit) < 0) {
|
||||
tDecoderClear(&decoder);
|
||||
pReader->setMsg = 1;
|
||||
tqError("DecodeSSubmitReq2 error, msgLen:%d, ver:%"PRId64, msgLen, ver);
|
||||
return -1;
|
||||
}
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool tqNextDataBlock(STqReader* pReader) {
|
||||
if (pReader->pMsg == NULL) return false;
|
||||
while (1) {
|
||||
if (tGetSubmitMsgNext(&pReader->msgIter, &pReader->pBlock) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (pReader->pBlock == NULL) {
|
||||
pReader->pMsg = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pReader->tbIdHash == NULL) {
|
||||
return true;
|
||||
}
|
||||
void* ret = taosHashGet(pReader->tbIdHash, &pReader->msgIter.uid, sizeof(int64_t));
|
||||
/*tqDebug("search uid %" PRId64, pHandle->msgIter.uid);*/
|
||||
if (ret != NULL) {
|
||||
/*tqDebug("find uid %" PRId64, pHandle->msgIter.uid);*/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool tqNextDataBlock2(STqReader* pReader) {
|
||||
if (pReader->msg2.msgStr == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ASSERT(pReader->setMsg == 1);
|
||||
|
||||
tqDebug("tq reader next data block %p, %d %" PRId64 " %d", pReader->msg2.msgStr, pReader->msg2.msgLen,
|
||||
pReader->msg2.ver, pReader->nextBlk);
|
||||
|
||||
int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
|
||||
while (pReader->nextBlk < blockSz) {
|
||||
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
|
||||
ASSERT(pSubmitTbData->uid);
|
||||
tqDebug("tq reader next data block %p, %d %" PRId64 " %d", pReader->msg2.msgStr, pReader->msg2.msgLen,
|
||||
pReader->msg2.ver, pReader->nextBlk);
|
||||
|
||||
if (pReader->tbIdHash == NULL) return true;
|
||||
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
|
||||
if (pReader->tbIdHash == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void* ret = taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t));
|
||||
if (ret != NULL) {
|
||||
tqDebug("tq reader block found, ver:%"PRId64", uid:%"PRId64, pReader->msg2.ver, pSubmitTbData->uid);
|
||||
return true;
|
||||
} else {
|
||||
tqDebug("tq reader discard block, uid:%"PRId64", continue", pSubmitTbData->uid);
|
||||
}
|
||||
|
||||
pReader->nextBlk++;
|
||||
}
|
||||
|
||||
tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
|
||||
pReader->setMsg = 0;
|
||||
pReader->nextBlk = 0;
|
||||
pReader->msg2.msgStr = NULL;
|
||||
|
||||
|
@ -455,7 +402,6 @@ bool tqNextDataBlock2(STqReader* pReader) {
|
|||
|
||||
bool tqNextDataBlockFilterOut2(STqReader* pReader, SHashObj* filterOutUids) {
|
||||
if (pReader->msg2.msgStr == NULL) return false;
|
||||
ASSERT(pReader->setMsg == 1);
|
||||
|
||||
int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
|
||||
while (pReader->nextBlk < blockSz) {
|
||||
|
@ -470,7 +416,6 @@ bool tqNextDataBlockFilterOut2(STqReader* pReader, SHashObj* filterOutUids) {
|
|||
}
|
||||
|
||||
tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
|
||||
pReader->setMsg = 0;
|
||||
pReader->nextBlk = 0;
|
||||
pReader->msg2.msgStr = NULL;
|
||||
|
||||
|
@ -506,67 +451,15 @@ int32_t tqMaskBlock(SSchemaWrapper* pDst, SSDataBlock* pBlock, const SSchemaWrap
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool tqNextDataBlockFilterOut(STqReader* pHandle, SHashObj* filterOutUids) {
|
||||
while (1) {
|
||||
if (tGetSubmitMsgNext(&pHandle->msgIter, &pHandle->pBlock) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (pHandle->pBlock == NULL) return false;
|
||||
|
||||
void* ret = taosHashGet(filterOutUids, &pHandle->msgIter.uid, sizeof(int64_t));
|
||||
if (ret == NULL) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t tqScanSubmitSplit(SArray* pBlocks, SArray* schemas, STqReader* pReader) {
|
||||
//
|
||||
int32_t sversion = htonl(pReader->pBlock->sversion);
|
||||
if (pReader->cachedSchemaSuid == 0 || pReader->cachedSchemaVer != sversion ||
|
||||
pReader->cachedSchemaSuid != pReader->msgIter.suid) {
|
||||
taosMemoryFree(pReader->pSchema);
|
||||
pReader->pSchema = metaGetTbTSchema(pReader->pVnodeMeta, pReader->msgIter.uid, sversion, 1);
|
||||
if (pReader->pSchema == NULL) {
|
||||
tqWarn("vgId:%d, cannot found tsschema for table: uid:%" PRId64 " (suid:%" PRId64
|
||||
"), version %d, possibly dropped table",
|
||||
pWalReader->pWal->cfg.vgId, pReader->msgIter.uid, pReader->msgIter.suid, sversion);
|
||||
pReader->cachedSchemaSuid = 0;
|
||||
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
tDeleteSSchemaWrapper(pReader->pSchemaWrapper);
|
||||
pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, pReader->msgIter.uid, sversion, 1);
|
||||
if (pReader->pSchemaWrapper == NULL) {
|
||||
tqWarn("vgId:%d, cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table",
|
||||
pWalReader->pWal->cfg.vgId, pReader->msgIter.uid, pReader->cachedSchemaVer);
|
||||
pReader->cachedSchemaSuid = 0;
|
||||
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
STSchema* pTschema = pReader->pSchema;
|
||||
SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
|
||||
|
||||
int32_t colNumNeed = taosArrayGetSize(pReader->pColIdList);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbData** pSubmitTbDataRet) {
|
||||
int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
|
||||
ASSERT(pReader->nextBlk < blockSz);
|
||||
|
||||
tqDebug("tq reader retrieve data block %p, %d", pReader->msg2.msgStr, pReader->nextBlk);
|
||||
|
||||
tqDebug("tq reader retrieve data block %p, index:%d", pReader->msg2.msgStr, pReader->nextBlk);
|
||||
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
|
||||
pReader->nextBlk++;
|
||||
|
||||
if (pSubmitTbDataRet) *pSubmitTbDataRet = pSubmitTbData;
|
||||
if (pSubmitTbDataRet) {
|
||||
*pSubmitTbDataRet = pSubmitTbData;
|
||||
}
|
||||
|
||||
int32_t sversion = pSubmitTbData->sver;
|
||||
int64_t suid = pSubmitTbData->suid;
|
||||
int64_t uid = pSubmitTbData->uid;
|
||||
|
@ -666,33 +559,27 @@ int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbD
|
|||
int32_t targetIdx = 0;
|
||||
int32_t sourceIdx = 0;
|
||||
while (targetIdx < colActual) {
|
||||
ASSERT(sourceIdx < numOfCols);
|
||||
|
||||
if(sourceIdx >= numOfCols){
|
||||
tqError("tqRetrieveDataBlock2 sourceIdx:%d >= numOfCols:%d", sourceIdx, numOfCols);
|
||||
goto FAIL;
|
||||
}
|
||||
SColData* pCol = taosArrayGet(pCols, sourceIdx);
|
||||
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
|
||||
SColVal colVal;
|
||||
|
||||
ASSERT(pCol->nVal == numOfRows);
|
||||
if(pCol->nVal != numOfRows){
|
||||
tqError("tqRetrieveDataBlock2 pCol->nVal:%d != numOfRows:%d", pCol->nVal, numOfRows);
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
if (pCol->cid < pColData->info.colId) {
|
||||
sourceIdx++;
|
||||
} else if (pCol->cid == pColData->info.colId) {
|
||||
for (int32_t i = 0; i < pCol->nVal; i++) {
|
||||
tColDataGetValue(pCol, i, &colVal);
|
||||
#if 0
|
||||
void* val = NULL;
|
||||
if (IS_STR_DATA_TYPE(colVal.type)) {
|
||||
val = colVal.value.pData;
|
||||
} else {
|
||||
val = &colVal.value.val;
|
||||
}
|
||||
if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
||||
goto FAIL;
|
||||
}
|
||||
#endif
|
||||
if (IS_STR_DATA_TYPE(colVal.type)) {
|
||||
if (colVal.value.pData != NULL) {
|
||||
char val[65535 + 2];
|
||||
char val[65535 + 2] = {0};
|
||||
memcpy(varDataVal(val), colVal.value.pData, colVal.value.nData);
|
||||
varDataSetLen(val, colVal.value.nData);
|
||||
if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
||||
|
@ -726,8 +613,6 @@ int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbD
|
|||
for (int32_t j = 0; j < colActual; j++) {
|
||||
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, j);
|
||||
while (1) {
|
||||
ASSERT(sourceIdx < pTschema->numOfCols);
|
||||
|
||||
SColVal colVal;
|
||||
tRowGet(pRow, pTschema, sourceIdx, &colVal);
|
||||
if (colVal.cid < pColData->info.colId) {
|
||||
|
@ -736,7 +621,7 @@ int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbD
|
|||
} else if (colVal.cid == pColData->info.colId) {
|
||||
if (IS_STR_DATA_TYPE(colVal.type)) {
|
||||
if (colVal.value.pData != NULL) {
|
||||
char val[65535 + 2];
|
||||
char val[65535 + 2] = {0};
|
||||
memcpy(varDataVal(val), colVal.value.pData, colVal.value.nData);
|
||||
varDataSetLen(val, colVal.value.nData);
|
||||
if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
||||
|
@ -745,7 +630,6 @@ int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbD
|
|||
} else {
|
||||
colDataSetNULL(pColData, i);
|
||||
}
|
||||
/*val = colVal.value.pData;*/
|
||||
} else {
|
||||
if (colDataAppend(pColData, i, (void*)&colVal.value.val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
||||
goto FAIL;
|
||||
|
@ -771,253 +655,6 @@ FAIL:
|
|||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int32_t tqRetrieveDataBlock(SSDataBlock* pBlock, STqReader* pReader) {
|
||||
// TODO: cache multiple schema
|
||||
int32_t sversion = htonl(pReader->pBlock->sversion);
|
||||
if (pReader->cachedSchemaSuid == 0 || pReader->cachedSchemaVer != sversion ||
|
||||
pReader->cachedSchemaSuid != pReader->msgIter.suid) {
|
||||
if (pReader->pSchema) taosMemoryFree(pReader->pSchema);
|
||||
pReader->pSchema = metaGetTbTSchema(pReader->pVnodeMeta, pReader->msgIter.uid, sversion, 1);
|
||||
if (pReader->pSchema == NULL) {
|
||||
tqWarn("cannot found tsschema for table: uid:%" PRId64 " (suid:%" PRId64 "), version %d, possibly dropped table",
|
||||
pReader->msgIter.uid, pReader->msgIter.suid, pReader->cachedSchemaVer);
|
||||
pReader->cachedSchemaSuid = 0;
|
||||
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pReader->pSchemaWrapper) tDeleteSSchemaWrapper(pReader->pSchemaWrapper);
|
||||
pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, pReader->msgIter.uid, sversion, 1);
|
||||
if (pReader->pSchemaWrapper == NULL) {
|
||||
tqWarn("cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table",
|
||||
pReader->msgIter.uid, pReader->cachedSchemaVer);
|
||||
pReader->cachedSchemaSuid = 0;
|
||||
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
pReader->cachedSchemaVer = sversion;
|
||||
pReader->cachedSchemaSuid = pReader->msgIter.suid;
|
||||
}
|
||||
|
||||
STSchema* pTschema = pReader->pSchema;
|
||||
SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
|
||||
|
||||
int32_t colNumNeed = taosArrayGetSize(pReader->pColIdList);
|
||||
|
||||
if (colNumNeed == 0) {
|
||||
int32_t colMeta = 0;
|
||||
while (colMeta < pSchemaWrapper->nCols) {
|
||||
SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta];
|
||||
SColumnInfoData colInfo = createColumnInfoData(pColSchema->type, pColSchema->bytes, pColSchema->colId);
|
||||
int32_t code = blockDataAppendColInfo(pBlock, &colInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto FAIL;
|
||||
}
|
||||
colMeta++;
|
||||
}
|
||||
} else {
|
||||
if (colNumNeed > pSchemaWrapper->nCols) {
|
||||
colNumNeed = pSchemaWrapper->nCols;
|
||||
}
|
||||
|
||||
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(pReader->pColIdList, colNeed);
|
||||
if (colIdSchema < colIdNeed) {
|
||||
colMeta++;
|
||||
} else if (colIdSchema > colIdNeed) {
|
||||
colNeed++;
|
||||
} else {
|
||||
SColumnInfoData colInfo = createColumnInfoData(pColSchema->type, pColSchema->bytes, pColSchema->colId);
|
||||
int32_t code = blockDataAppendColInfo(pBlock, &colInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto FAIL;
|
||||
}
|
||||
colMeta++;
|
||||
colNeed++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (blockDataEnsureCapacity(pBlock, pReader->msgIter.numOfRows) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
int32_t colActual = blockDataGetNumOfCols(pBlock);
|
||||
|
||||
STSRowIter iter = {0};
|
||||
tdSTSRowIterInit(&iter, pTschema);
|
||||
STSRow* row;
|
||||
int32_t curRow = 0;
|
||||
|
||||
tInitSubmitBlkIter(&pReader->msgIter, pReader->pBlock, &pReader->blkIter);
|
||||
|
||||
pBlock->info.id.uid = pReader->msgIter.uid;
|
||||
pBlock->info.rows = pReader->msgIter.numOfRows;
|
||||
pBlock->info.version = pReader->pMsg->version;
|
||||
pBlock->info.dataLoad = 1;
|
||||
|
||||
while ((row = tGetSubmitBlkNext(&pReader->blkIter)) != NULL) {
|
||||
tdSTSRowIterReset(&iter, row);
|
||||
// get all wanted col of that block
|
||||
for (int32_t i = 0; i < colActual; i++) {
|
||||
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
|
||||
SCellVal sVal = {0};
|
||||
if (!tdSTSRowIterFetch(&iter, pColData->info.colId, pColData->info.type, &sVal)) {
|
||||
break;
|
||||
}
|
||||
if (colDataSetVal(pColData, curRow, sVal.val, sVal.valType != TD_VTYPE_NORM) < 0) {
|
||||
goto FAIL;
|
||||
}
|
||||
}
|
||||
curRow++;
|
||||
}
|
||||
return 0;
|
||||
|
||||
FAIL:
|
||||
blockDataFreeRes(pBlock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t tqRetrieveTaosxBlock(STqReader* pReader, SArray* blocks, SArray* schemas) {
|
||||
int32_t sversion = htonl(pReader->pBlock->sversion);
|
||||
|
||||
if (pReader->cachedSchemaSuid == 0 || pReader->cachedSchemaVer != sversion ||
|
||||
pReader->cachedSchemaSuid != pReader->msgIter.suid) {
|
||||
if (pReader->pSchema) taosMemoryFree(pReader->pSchema);
|
||||
pReader->pSchema = metaGetTbTSchema(pReader->pVnodeMeta, pReader->msgIter.uid, sversion, 1);
|
||||
if (pReader->pSchema == NULL) {
|
||||
tqWarn("cannot found tsschema for table: uid:%" PRId64 " (suid:%" PRId64 "), version %d, possibly dropped table",
|
||||
pReader->msgIter.uid, pReader->msgIter.suid, pReader->cachedSchemaVer);
|
||||
pReader->cachedSchemaSuid = 0;
|
||||
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pReader->pSchemaWrapper) tDeleteSSchemaWrapper(pReader->pSchemaWrapper);
|
||||
pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, pReader->msgIter.uid, sversion, 1);
|
||||
if (pReader->pSchemaWrapper == NULL) {
|
||||
tqWarn("cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table",
|
||||
pReader->msgIter.uid, pReader->cachedSchemaVer);
|
||||
pReader->cachedSchemaSuid = 0;
|
||||
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
pReader->cachedSchemaVer = sversion;
|
||||
pReader->cachedSchemaSuid = pReader->msgIter.suid;
|
||||
}
|
||||
|
||||
STSchema* pTschema = pReader->pSchema;
|
||||
SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
|
||||
|
||||
int32_t colAtMost = pSchemaWrapper->nCols;
|
||||
|
||||
int32_t curRow = 0;
|
||||
int32_t lastRow = 0;
|
||||
|
||||
char* assigned = taosMemoryCalloc(1, pSchemaWrapper->nCols);
|
||||
if (assigned == NULL) return -1;
|
||||
|
||||
tInitSubmitBlkIter(&pReader->msgIter, pReader->pBlock, &pReader->blkIter);
|
||||
STSRowIter iter = {0};
|
||||
tdSTSRowIterInit(&iter, pTschema);
|
||||
STSRow* row;
|
||||
|
||||
while ((row = tGetSubmitBlkNext(&pReader->blkIter)) != NULL) {
|
||||
bool buildNew = false;
|
||||
tdSTSRowIterReset(&iter, row);
|
||||
|
||||
tqDebug("vgId:%d, row of block %d", pReader->pWalReader->pWal->cfg.vgId, curRow);
|
||||
for (int32_t i = 0; i < colAtMost; i++) {
|
||||
SCellVal sVal = {0};
|
||||
if (!tdSTSRowIterFetch(&iter, pSchemaWrapper->pSchema[i].colId, pSchemaWrapper->pSchema[i].type, &sVal)) {
|
||||
break;
|
||||
}
|
||||
tqDebug("vgId:%d, %d col, type %d", pReader->pWalReader->pWal->cfg.vgId, i, sVal.valType);
|
||||
if (curRow == 0) {
|
||||
assigned[i] = sVal.valType != TD_VTYPE_NONE;
|
||||
buildNew = true;
|
||||
} else {
|
||||
bool currentRowAssigned = sVal.valType != TD_VTYPE_NONE;
|
||||
if (currentRowAssigned != assigned[i]) {
|
||||
assigned[i] = currentRowAssigned;
|
||||
buildNew = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (buildNew) {
|
||||
if (taosArrayGetSize(blocks) > 0) {
|
||||
SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
|
||||
pLastBlock->info.rows = curRow - lastRow;
|
||||
lastRow = curRow;
|
||||
}
|
||||
SSDataBlock* pBlock = createDataBlock();
|
||||
SSchemaWrapper* pSW = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
|
||||
if (tqMaskBlock(pSW, pBlock, pSchemaWrapper, assigned) < 0) {
|
||||
blockDataDestroy(pBlock);
|
||||
goto FAIL;
|
||||
}
|
||||
SSDataBlock block = {0};
|
||||
assignOneDataBlock(&block, pBlock);
|
||||
blockDataDestroy(pBlock);
|
||||
|
||||
tqDebug("vgId:%d, build new block, col %d", pReader->pWalReader->pWal->cfg.vgId,
|
||||
(int32_t)taosArrayGetSize(block.pDataBlock));
|
||||
|
||||
taosArrayPush(blocks, &block);
|
||||
taosArrayPush(schemas, &pSW);
|
||||
}
|
||||
|
||||
SSDataBlock* pBlock = taosArrayGetLast(blocks);
|
||||
pBlock->info.id.uid = pReader->msgIter.uid;
|
||||
pBlock->info.rows = 0;
|
||||
pBlock->info.version = pReader->pMsg->version;
|
||||
|
||||
tqDebug("vgId:%d, taosx scan, block num: %d", pReader->pWalReader->pWal->cfg.vgId,
|
||||
(int32_t)taosArrayGetSize(blocks));
|
||||
|
||||
if (blockDataEnsureCapacity(pBlock, pReader->msgIter.numOfRows - curRow) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
tdSTSRowIterReset(&iter, row);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pBlock->pDataBlock); i++) {
|
||||
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, i);
|
||||
SCellVal sVal = {0};
|
||||
|
||||
if (!tdSTSRowIterFetch(&iter, pColData->info.colId, pColData->info.type, &sVal)) {
|
||||
break;
|
||||
}
|
||||
|
||||
ASSERT(sVal.valType != TD_VTYPE_NONE);
|
||||
|
||||
if (colDataSetVal(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL) < 0) {
|
||||
goto FAIL;
|
||||
}
|
||||
tqDebug("vgId:%d, row %d col %d append %d", pReader->pWalReader->pWal->cfg.vgId, curRow, i,
|
||||
sVal.valType == TD_VTYPE_NULL);
|
||||
}
|
||||
curRow++;
|
||||
}
|
||||
SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
|
||||
pLastBlock->info.rows = curRow - lastRow;
|
||||
|
||||
taosMemoryFree(assigned);
|
||||
return 0;
|
||||
|
||||
FAIL:
|
||||
taosMemoryFree(assigned);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tqRetrieveTaosxBlock2(STqReader* pReader, SArray* blocks, SArray* schemas, SSubmitTbData** pSubmitTbDataRet) {
|
||||
tqDebug("tq reader retrieve data block %p, %d", pReader->msg2.msgStr, pReader->nextBlk);
|
||||
|
||||
|
@ -1295,7 +932,7 @@ int tqReaderSetTbUidList(STqReader* pReader, const SArray* tbUidList) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tqReaderAddTbUidList(STqReader* pReader, const SArray* tbUidList) {
|
||||
int tqReaderAddTbUidList(STqReader* pReader, const SArray* pTableUidList) {
|
||||
if (pReader->tbIdHash == NULL) {
|
||||
pReader->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
|
||||
if (pReader->tbIdHash == NULL) {
|
||||
|
@ -1304,8 +941,9 @@ int tqReaderAddTbUidList(STqReader* pReader, const SArray* tbUidList) {
|
|||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < taosArrayGetSize(tbUidList); i++) {
|
||||
int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i);
|
||||
int32_t numOfTables = taosArrayGetSize(pTableUidList);
|
||||
for (int i = 0; i < numOfTables; i++) {
|
||||
int64_t* pKey = (int64_t*)taosArrayGet(pTableUidList, i);
|
||||
taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0);
|
||||
}
|
||||
|
||||
|
@ -1321,30 +959,34 @@ int tqReaderRemoveTbUidList(STqReader* pReader, const SArray* tbUidList) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// todo update the table list in wal reader
|
||||
int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
|
||||
void* pIter = NULL;
|
||||
void* pIter = NULL;
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
|
||||
// update the table list for each consumer handle
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pTq->pHandle, pIter);
|
||||
if (pIter == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
STqHandle* pExec = (STqHandle*)pIter;
|
||||
if (pExec->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
int32_t code = qUpdateQualifiedTableId(pExec->execHandle.task, tbUidList, isAdd);
|
||||
STqHandle* pTqHandle = (STqHandle*)pIter;
|
||||
if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
int32_t code = qUpdateTableListForStreamScanner(pTqHandle->execHandle.task, tbUidList, isAdd, NULL);
|
||||
if (code != 0) {
|
||||
tqError("update qualified table error for %s", pExec->subKey);
|
||||
tqError("update qualified table error for %s", pTqHandle->subKey);
|
||||
continue;
|
||||
}
|
||||
} else if (pExec->execHandle.subType == TOPIC_SUB_TYPE__DB) {
|
||||
} else if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
|
||||
if (!isAdd) {
|
||||
int32_t sz = taosArrayGetSize(tbUidList);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
int64_t tbUid = *(int64_t*)taosArrayGet(tbUidList, i);
|
||||
taosHashPut(pExec->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0);
|
||||
taosHashPut(pTqHandle->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0);
|
||||
}
|
||||
}
|
||||
} else if (pExec->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
} else if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
if (isAdd) {
|
||||
SArray* qa = taosArrayInit(4, sizeof(tb_uid_t));
|
||||
SMetaReader mr = {0};
|
||||
|
@ -1359,35 +1001,50 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
|
|||
}
|
||||
|
||||
tDecoderClear(&mr.coder);
|
||||
|
||||
if (mr.me.type != TSDB_CHILD_TABLE || mr.me.ctbEntry.suid != pExec->execHandle.execTb.suid) {
|
||||
if (mr.me.type != TSDB_CHILD_TABLE || mr.me.ctbEntry.suid != pTqHandle->execHandle.execTb.suid) {
|
||||
tqDebug("table uid %" PRId64 " does not add to tq handle", *id);
|
||||
continue;
|
||||
}
|
||||
|
||||
tqDebug("table uid %" PRId64 " add to tq handle", *id);
|
||||
taosArrayPush(qa, id);
|
||||
}
|
||||
|
||||
metaReaderClear(&mr);
|
||||
if (taosArrayGetSize(qa) > 0) {
|
||||
tqReaderAddTbUidList(pExec->execHandle.pExecReader, qa);
|
||||
tqReaderAddTbUidList(pTqHandle->execHandle.pTqReader, qa);
|
||||
}
|
||||
|
||||
taosArrayDestroy(qa);
|
||||
} else {
|
||||
tqReaderRemoveTbUidList(pExec->execHandle.pExecReader, tbUidList);
|
||||
tqReaderRemoveTbUidList(pTqHandle->execHandle.pTqReader, tbUidList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update the table list handle for each stream scanner/wal reader
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pTq->pStreamMeta->pTasks, pIter);
|
||||
if (pIter == NULL) break;
|
||||
if (pIter == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = *(SStreamTask**)pIter;
|
||||
if (pTask->taskLevel == TASK_LEVEL__SOURCE) {
|
||||
int32_t code = qUpdateQualifiedTableId(pTask->exec.executor, tbUidList, isAdd);
|
||||
SArray* pList = NULL;
|
||||
int32_t code = qUpdateTableListForStreamScanner(pTask->exec.pExecutor, tbUidList, isAdd, pList);
|
||||
if (code != 0) {
|
||||
tqError("update qualified table error for stream task %d", pTask->taskId);
|
||||
tqError("vgId:%d, s-task:%s update qualified table error for stream task", vgId, pTask->id.idStr);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isAdd) { // only add qualified tables
|
||||
tqReaderAddTbUidList(pTask->exec.pTqReader, pList);
|
||||
} else {
|
||||
tqReaderRemoveTbUidList(pTask->exec.pTqReader, tbUidList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tq.h"
|
||||
|
||||
static int32_t streamTaskReplayWal(SStreamMeta* pStreamMeta, STqOffsetStore* pOffsetStore, bool* pScanIdle);
|
||||
static int32_t transferToNormalTask(SStreamMeta* pStreamMeta, SArray* pTaskList);
|
||||
|
||||
// this function should be executed by stream threads.
|
||||
// there is a case that the WAL increases more fast than the restore procedure, and this restore procedure
|
||||
// will not stop eventually.
|
||||
int tqStreamTasksScanWal(STQ* pTq) {
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
SStreamMeta* pMeta = pTq->pStreamMeta;
|
||||
int64_t st = taosGetTimestampMs();
|
||||
|
||||
while (1) {
|
||||
tqInfo("vgId:%d continue check if data in wal are available", vgId);
|
||||
|
||||
// check all restore tasks
|
||||
bool allFull = true;
|
||||
streamTaskReplayWal(pTq->pStreamMeta, pTq->pOffsetStore, &allFull);
|
||||
|
||||
int32_t times = 0;
|
||||
|
||||
if (allFull) {
|
||||
taosWLockLatch(&pMeta->lock);
|
||||
pMeta->walScan -= 1;
|
||||
times = pMeta->walScan;
|
||||
|
||||
if (pMeta->walScan <= 0) {
|
||||
taosWUnLockLatch(&pMeta->lock);
|
||||
break;
|
||||
}
|
||||
|
||||
taosWUnLockLatch(&pMeta->lock);
|
||||
tqInfo("vgId:%d scan wal for stream tasks for %d times", vgId, times);
|
||||
}
|
||||
}
|
||||
|
||||
double el = (taosGetTimestampMs() - st) / 1000.0;
|
||||
tqInfo("vgId:%d scan wal for stream tasks completed, elapsed time:%.2f sec", vgId, el);
|
||||
|
||||
// restore wal scan flag
|
||||
// atomic_store_8(&pTq->pStreamMeta->walScan, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//int32_t transferToNormalTask(SStreamMeta* pStreamMeta, SArray* pTaskList) {
|
||||
// int32_t numOfTask = taosArrayGetSize(pTaskList);
|
||||
// if (numOfTask <= 0) {
|
||||
// return TSDB_CODE_SUCCESS;
|
||||
// }
|
||||
//
|
||||
// // todo: add lock
|
||||
// for (int32_t i = 0; i < numOfTask; ++i) {
|
||||
// SStreamTask* pTask = taosArrayGetP(pTaskList, i);
|
||||
// tqDebug("vgId:%d transfer s-task:%s state restore -> ready, checkpoint:%" PRId64 " checkpoint id:%" PRId64,
|
||||
// pStreamMeta->vgId, pTask->id.idStr, pTask->chkInfo.version, pTask->chkInfo.id);
|
||||
// taosHashRemove(pStreamMeta->pWalReadTasks, &pTask->id.taskId, sizeof(pTask->id.taskId));
|
||||
//
|
||||
// // NOTE: do not change the following order
|
||||
// atomic_store_8(&pTask->status.taskStatus, TASK_STATUS__NORMAL);
|
||||
// taosHashPut(pStreamMeta->pTasks, &pTask->id.taskId, sizeof(pTask->id.taskId), &pTask, POINTER_BYTES);
|
||||
// }
|
||||
//
|
||||
// return TSDB_CODE_SUCCESS;
|
||||
//}
|
||||
|
||||
int32_t streamTaskReplayWal(SStreamMeta* pStreamMeta, STqOffsetStore* pOffsetStore, bool* pScanIdle) {
|
||||
void* pIter = NULL;
|
||||
int32_t vgId = pStreamMeta->vgId;
|
||||
|
||||
*pScanIdle = true;
|
||||
|
||||
bool allWalChecked = true;
|
||||
tqDebug("vgId:%d start to check wal to extract new submit block", vgId);
|
||||
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pStreamMeta->pTasks, pIter);
|
||||
if (pIter == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = *(SStreamTask**)pIter;
|
||||
if (pTask->taskLevel != TASK_LEVEL__SOURCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pTask->status.taskStatus == TASK_STATUS__RECOVER_PREPARE ||
|
||||
pTask->status.taskStatus == TASK_STATUS__WAIT_DOWNSTREAM) {
|
||||
tqDebug("s-task:%s skip push data, not ready for processing, status %d", pTask->id.idStr,
|
||||
pTask->status.taskStatus);
|
||||
continue;
|
||||
}
|
||||
|
||||
// check if offset value exists
|
||||
char key[128] = {0};
|
||||
createStreamTaskOffsetKey(key, pTask->id.streamId, pTask->id.taskId);
|
||||
|
||||
if (tInputQueueIsFull(pTask)) {
|
||||
tqDebug("vgId:%d s-task:%s input queue is full, do nothing", vgId, pTask->id.idStr);
|
||||
continue;
|
||||
}
|
||||
|
||||
*pScanIdle = false;
|
||||
|
||||
// check if offset value exists
|
||||
STqOffset* pOffset = tqOffsetRead(pOffsetStore, key);
|
||||
ASSERT(pOffset != NULL);
|
||||
|
||||
// seek the stored version and extract data from WAL
|
||||
int32_t code = walReadSeekVer(pTask->exec.pWalReader, pOffset->val.version);
|
||||
if (code != TSDB_CODE_SUCCESS) { // no data in wal, quit
|
||||
continue;
|
||||
}
|
||||
|
||||
// append the data for the stream
|
||||
tqDebug("vgId:%d wal reader seek to ver:%" PRId64 " %s", vgId, pOffset->val.version, pTask->id.idStr);
|
||||
|
||||
SPackedData packData = {0};
|
||||
code = extractSubmitMsgFromWal(pTask->exec.pWalReader, &packData);
|
||||
if (code != TSDB_CODE_SUCCESS) { // failed, continue
|
||||
continue;
|
||||
}
|
||||
|
||||
SStreamDataSubmit2* p = streamDataSubmitNew(packData, STREAM_INPUT__DATA_SUBMIT);
|
||||
if (p == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tqError("%s failed to create data submit for stream since out of memory", pTask->id.idStr);
|
||||
continue;
|
||||
}
|
||||
|
||||
allWalChecked = false;
|
||||
|
||||
tqDebug("s-task:%s submit data extracted from WAL", pTask->id.idStr);
|
||||
code = tqAddInputBlockNLaunchTask(pTask, (SStreamQueueItem*)p, packData.ver);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
pOffset->val.version = walReaderGetCurrentVer(pTask->exec.pWalReader);
|
||||
tqDebug("s-task:%s set the ver:%" PRId64 " from WALReader after extract block from WAL", pTask->id.idStr,
|
||||
pOffset->val.version);
|
||||
} else {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
streamDataSubmitDestroy(p);
|
||||
taosFreeQitem(p);
|
||||
}
|
||||
|
||||
if (allWalChecked) {
|
||||
*pScanIdle = true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ int32_t tqAddBlockDataToRsp(const SSDataBlock* pBlock, SMqDataRsp* pRsp, int32_t
|
|||
}
|
||||
|
||||
static int32_t tqAddBlockSchemaToRsp(const STqExecHandle* pExec, STaosxRsp* pRsp) {
|
||||
SSchemaWrapper* pSW = tCloneSSchemaWrapper(pExec->pExecReader->pSchemaWrapper);
|
||||
SSchemaWrapper* pSW = tCloneSSchemaWrapper(pExec->pTqReader->pSchemaWrapper);
|
||||
if (pSW == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -74,33 +74,23 @@ int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffs
|
|||
qTaskInfo_t task = pExec->task;
|
||||
|
||||
if (qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType) < 0) {
|
||||
tqDebug("prepare scan failed, vgId:%d, consumer:0x%" PRIx64, vgId, pHandle->consumerId);
|
||||
if (pOffset->type == TMQ_OFFSET__LOG) {
|
||||
pRsp->rspOffset = *pOffset;
|
||||
return code;
|
||||
} else {
|
||||
tqOffsetResetToLog(pOffset, pHandle->snapshotVer);
|
||||
if (qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType) < 0) {
|
||||
tqDebug("prepare scan failed, vgId:%d, consumer:0x%" PRIx64, vgId, pHandle->consumerId);
|
||||
pRsp->rspOffset = *pOffset;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
tqError("prepare scan failed, return");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
SSDataBlock* pDataBlock = NULL;
|
||||
uint64_t ts = 0;
|
||||
|
||||
tqDebug("vgId:%d, tmq task start to execute, consumer:0x%" PRIx64, vgId, pHandle->consumerId);
|
||||
|
||||
code = qExecTask(task, &pDataBlock, &ts);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tqError("vgId:%d, task exec error since %s, consumer:0x%" PRIx64, vgId, terrstr(), pHandle->consumerId);
|
||||
return code;
|
||||
qStreamSetOpen(task);
|
||||
tqDebug("consumer:0x%" PRIx64 " vgId:%d, tmq one task start execute", pHandle->consumerId, vgId);
|
||||
if (qExecTask(task, &pDataBlock, &ts) != TSDB_CODE_SUCCESS) {
|
||||
tqError("consumer:0x%" PRIx64 " vgId:%d, task exec error since %s", pHandle->consumerId, vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// current scan should be stopped ASAP, since the re-balance occurs.
|
||||
tqDebug("consumer:0x%" PRIx64 " vgId:%d tmq one task end executed, pDataBlock:%p", pHandle->consumerId, vgId,
|
||||
pDataBlock);
|
||||
// current scan should be stopped asap, since the rebalance occurs.
|
||||
if (pDataBlock == NULL) {
|
||||
break;
|
||||
}
|
||||
|
@ -112,37 +102,16 @@ int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffs
|
|||
}
|
||||
|
||||
pRsp->blockNum++;
|
||||
|
||||
tqDebug("vgId:%d, consumer:0x%" PRIx64 " tmq task executed, rows:%" PRId64 ", total blocks:%d", vgId,
|
||||
pHandle->consumerId, pDataBlock->info.rows, pRsp->blockNum);
|
||||
|
||||
if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
totalRows += pDataBlock->info.rows;
|
||||
if (totalRows >= MAX_ROWS_TO_RETURN) {
|
||||
break;
|
||||
}
|
||||
totalRows += pDataBlock->info.rows;
|
||||
if (totalRows >= MAX_ROWS_TO_RETURN) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tqDebug("consumer:0x%" PRIx64 " vgId:%d tmq task executed finished, total blocks:%d, totalRows:%d",
|
||||
pHandle->consumerId, vgId, pRsp->blockNum, totalRows);
|
||||
qStreamExtractOffset(task, &pRsp->rspOffset);
|
||||
|
||||
if (pRsp->rspOffset.type == 0) {
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
tqError("vgId:%d, expected rsp offset: type %d %" PRId64 " %" PRId64 " %" PRId64, vgId, pRsp->rspOffset.type,
|
||||
pRsp->rspOffset.ts, pRsp->rspOffset.uid, pRsp->rspOffset.version);
|
||||
return code;
|
||||
}
|
||||
|
||||
if (pRsp->withTbName || pRsp->withSchema) {
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
tqError("vgId:%d, get column should not with meta:%d,%d", vgId, pRsp->withTbName, pRsp->withSchema);
|
||||
return code;
|
||||
}
|
||||
|
||||
tqDebug("vgId:%d, consumer:0x%" PRIx64 " tmq task executed, total blocks:%d, rows:%d", vgId, pHandle->consumerId,
|
||||
pRsp->blockNum, totalRows);
|
||||
|
||||
return code;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMetaRsp* pMetaRsp, STqOffsetVal* pOffset) {
|
||||
|
@ -150,18 +119,8 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMeta
|
|||
qTaskInfo_t task = pExec->task;
|
||||
|
||||
if (qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType) < 0) {
|
||||
tqDebug("prepare scan failed, return");
|
||||
if (pOffset->type == TMQ_OFFSET__LOG) {
|
||||
pRsp->rspOffset = *pOffset;
|
||||
return 0;
|
||||
} else {
|
||||
tqOffsetResetToLog(pOffset, pHandle->snapshotVer);
|
||||
if (qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType) < 0) {
|
||||
tqDebug("prepare scan failed, return");
|
||||
pRsp->rspOffset = *pOffset;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
tqDebug("tqScanTaosx prepare scan failed, return");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t rowCnt = 0;
|
||||
|
@ -178,7 +137,7 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMeta
|
|||
if (pDataBlock != NULL && pDataBlock->info.rows > 0) {
|
||||
if (pRsp->withTbName) {
|
||||
if (pOffset->type == TMQ_OFFSET__LOG) {
|
||||
int64_t uid = pExec->pExecReader->lastBlkUid;
|
||||
int64_t uid = pExec->pTqReader->lastBlkUid;
|
||||
if (tqAddTbNameToRsp(pTq, uid, pRsp, 1) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
@ -207,42 +166,32 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMeta
|
|||
}
|
||||
}
|
||||
|
||||
if (pDataBlock == NULL && pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
if (qStreamExtractPrepareUid(task) != 0) {
|
||||
// get meta
|
||||
SMqMetaRsp* tmp = qStreamExtractMetaMsg(task);
|
||||
if (tmp->metaRspLen > 0) {
|
||||
qStreamExtractOffset(task, &tmp->rspOffset);
|
||||
*pMetaRsp = *tmp;
|
||||
|
||||
tqDebug("tmqsnap task get meta");
|
||||
break;
|
||||
}
|
||||
|
||||
if (pDataBlock == NULL) {
|
||||
qStreamExtractOffset(task, pOffset);
|
||||
if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
continue;
|
||||
}
|
||||
tqDebug("tmqsnap vgId: %d, tsdb consume over, switch to wal, ver %" PRId64, TD_VID(pTq->pVnode),
|
||||
pHandle->snapshotVer + 1);
|
||||
qStreamExtractOffset(task, &pRsp->rspOffset);
|
||||
break;
|
||||
}
|
||||
|
||||
if (pRsp->blockNum > 0) {
|
||||
tqDebug("tmqsnap task exec exited, get data");
|
||||
qStreamExtractOffset(task, &pRsp->rspOffset);
|
||||
break;
|
||||
}
|
||||
|
||||
SMqMetaRsp* tmp = qStreamExtractMetaMsg(task);
|
||||
if (tmp->rspOffset.type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
tqOffsetResetToData(pOffset, tmp->rspOffset.uid, tmp->rspOffset.ts);
|
||||
qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType);
|
||||
tmp->rspOffset.type = TMQ_OFFSET__SNAPSHOT_META;
|
||||
tqDebug("tmqsnap task exec change to get data");
|
||||
continue;
|
||||
}
|
||||
|
||||
*pMetaRsp = *tmp;
|
||||
tqDebug("tmqsnap task exec exited, get meta");
|
||||
|
||||
tqDebug("task exec exited");
|
||||
break;
|
||||
}
|
||||
|
||||
qStreamExtractOffset(task, &pRsp->rspOffset);
|
||||
|
||||
if (pRsp->rspOffset.type == 0) {
|
||||
tqError("expected rsp offset: type %d %" PRId64 " %" PRId64 " %" PRId64, pRsp->rspOffset.type, pRsp->rspOffset.ts,
|
||||
pRsp->rspOffset.uid, pRsp->rspOffset.version);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -254,9 +203,9 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxR
|
|||
SArray* pSchemas = taosArrayInit(0, sizeof(void*));
|
||||
|
||||
if (pExec->subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
STqReader* pReader = pExec->pExecReader;
|
||||
tqReaderSetSubmitReq2(pReader, submit.msgStr, submit.msgLen, submit.ver);
|
||||
while (tqNextDataBlock2(pReader)) {
|
||||
STqReader* pReader = pExec->pTqReader;
|
||||
tqReaderSetSubmitMsg(pReader, submit.msgStr, submit.msgLen, submit.ver);
|
||||
while (tqNextDataBlock(pReader)) {
|
||||
taosArrayClear(pBlocks);
|
||||
taosArrayClear(pSchemas);
|
||||
SSubmitTbData* pSubmitTbDataRet = NULL;
|
||||
|
@ -264,7 +213,7 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxR
|
|||
if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;
|
||||
}
|
||||
if (pRsp->withTbName) {
|
||||
int64_t uid = pExec->pExecReader->lastBlkUid;
|
||||
int64_t uid = pExec->pTqReader->lastBlkUid;
|
||||
if (tqAddTbNameToRsp(pTq, uid, pRsp, taosArrayGetSize(pBlocks)) < 0) {
|
||||
taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
|
||||
taosArrayDestroyP(pSchemas, (FDelete)tDeleteSSchemaWrapper);
|
||||
|
@ -313,8 +262,8 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxR
|
|||
}
|
||||
}
|
||||
} else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
|
||||
STqReader* pReader = pExec->pExecReader;
|
||||
tqReaderSetSubmitReq2(pReader, submit.msgStr, submit.msgLen, submit.ver);
|
||||
STqReader* pReader = pExec->pTqReader;
|
||||
tqReaderSetSubmitMsg(pReader, submit.msgStr, submit.msgLen, submit.ver);
|
||||
while (tqNextDataBlockFilterOut2(pReader, pExec->execDb.pFilterOutTbUid)) {
|
||||
taosArrayClear(pBlocks);
|
||||
taosArrayClear(pSchemas);
|
||||
|
@ -323,7 +272,7 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxR
|
|||
if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;
|
||||
}
|
||||
if (pRsp->withTbName) {
|
||||
int64_t uid = pExec->pExecReader->lastBlkUid;
|
||||
int64_t uid = pExec->pTqReader->lastBlkUid;
|
||||
if (tqAddTbNameToRsp(pTq, uid, pRsp, taosArrayGetSize(pBlocks)) < 0) {
|
||||
taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
|
||||
taosArrayDestroyP(pSchemas, (FDelete)tDeleteSSchemaWrapper);
|
||||
|
|
|
@ -131,7 +131,7 @@ void tqSinkToTablePipeline2(SStreamTask* pTask, void* vnode, int64_t ver, void*
|
|||
|
||||
int32_t blockSz = taosArrayGetSize(pBlocks);
|
||||
|
||||
tqDebug("vgId:%d, task %d write into table, block num: %d", TD_VID(pVnode), pTask->taskId, blockSz);
|
||||
tqDebug("vgId:%d, s-task:%s write results blocks:%d into table", TD_VID(pVnode), pTask->id.idStr, blockSz);
|
||||
|
||||
void* pBuf = NULL;
|
||||
SArray* tagArray = NULL;
|
||||
|
@ -224,11 +224,9 @@ void tqSinkToTablePipeline2(SStreamTask* pTask, void* vnode, int64_t ver, void*
|
|||
}
|
||||
for (int32_t tagId = UD_TAG_COLUMN_INDEX, step = 1; tagId < size; tagId++, step++) {
|
||||
SColumnInfoData* pTagData = taosArrayGet(pDataBlock->pDataBlock, tagId);
|
||||
STagVal tagVal = {
|
||||
.cid = pTSchema->numOfCols + step,
|
||||
.type = pTagData->info.type,
|
||||
};
|
||||
void* pData = colDataGetData(pTagData, rowId);
|
||||
|
||||
STagVal tagVal = {.cid = pTSchema->numOfCols + step, .type = pTagData->info.type};
|
||||
void* pData = colDataGetData(pTagData, rowId);
|
||||
if (colDataIsNull_s(pTagData, rowId)) {
|
||||
continue;
|
||||
} else if (IS_VAR_DATA_TYPE(pTagData->info.type)) {
|
||||
|
|
|
@ -0,0 +1,489 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tq.h"
|
||||
|
||||
#define IS_OFFSET_RESET_TYPE(_t) ((_t) < 0)
|
||||
|
||||
static int32_t tqSendMetaPollRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqMetaRsp* pRsp);
|
||||
|
||||
// stream_task:stream_id:task_id
|
||||
void createStreamTaskOffsetKey(char* dst, uint64_t streamId, uint32_t taskId) {
|
||||
int32_t n = 12;
|
||||
char* p = dst;
|
||||
|
||||
memcpy(p, "stream_task:", n);
|
||||
p += n;
|
||||
|
||||
int32_t inc = tintToHex(streamId, p);
|
||||
p += inc;
|
||||
|
||||
*(p++) = ':';
|
||||
tintToHex(taskId, p);
|
||||
}
|
||||
|
||||
int32_t tqAddInputBlockNLaunchTask(SStreamTask* pTask, SStreamQueueItem* pQueueItem, int64_t ver) {
|
||||
int32_t code = tAppendDataToInputQueue(pTask, pQueueItem);
|
||||
if (code < 0) {
|
||||
tqError("s-task:%s failed to put into queue, too many, next start ver:%" PRId64, pTask->id.idStr, ver);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (streamSchedExec(pTask) < 0) {
|
||||
tqError("stream task:%d failed to be launched, code:%s", pTask->id.taskId, tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t launchTaskForWalBlock(SStreamTask* pTask, SFetchRet* pRet, STqOffset* pOffset) {
|
||||
SStreamDataBlock* pBlocks = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, 0);
|
||||
if (pBlocks == NULL) { // failed, do nothing
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pRet->data.info.type = STREAM_NORMAL;
|
||||
pBlocks->type = STREAM_INPUT__DATA_BLOCK;
|
||||
pBlocks->sourceVer = pOffset->val.version;
|
||||
pBlocks->blocks = taosArrayInit(0, sizeof(SSDataBlock));
|
||||
taosArrayPush(pBlocks->blocks, &pRet->data);
|
||||
|
||||
// int64_t* ts = (int64_t*)(((SColumnInfoData*)ret.data.pDataBlock->pData)->pData);
|
||||
// tqDebug("-----------%ld\n", ts[0]);
|
||||
|
||||
int32_t code = tqAddInputBlockNLaunchTask(pTask, (SStreamQueueItem*)pBlocks, pBlocks->sourceVer);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
pOffset->val.version = walReaderGetCurrentVer(pTask->exec.pTqReader->pWalReader);
|
||||
tqDebug("s-task:%s set the ver:%" PRId64 " from WALReader after extract block from WAL", pTask->id.idStr,
|
||||
pOffset->val.version);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void initOffsetForAllRestoreTasks(STQ* pTq) {
|
||||
void* pIter = NULL;
|
||||
|
||||
while(1) {
|
||||
pIter = taosHashIterate(pTq->pStreamMeta->pTasks, pIter);
|
||||
if (pIter == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = *(SStreamTask**)pIter;
|
||||
if (pTask->taskLevel != TASK_LEVEL__SOURCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pTask->status.taskStatus == TASK_STATUS__RECOVER_PREPARE || pTask->status.taskStatus == TASK_STATUS__WAIT_DOWNSTREAM) {
|
||||
tqDebug("stream task:%d skip push data, not ready for processing, status %d", pTask->id.taskId,
|
||||
pTask->status.taskStatus);
|
||||
continue;
|
||||
}
|
||||
|
||||
char key[128] = {0};
|
||||
createStreamTaskOffsetKey(key, pTask->id.streamId, pTask->id.taskId);
|
||||
|
||||
STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, key);
|
||||
if (pOffset == NULL) {
|
||||
doSaveTaskOffset(pTq->pOffsetStore, key, pTask->chkInfo.version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void saveOffsetForAllTasks(STQ* pTq, int64_t ver) {
|
||||
void* pIter = NULL;
|
||||
|
||||
while(1) {
|
||||
pIter = taosHashIterate(pTq->pStreamMeta->pTasks, pIter);
|
||||
if (pIter == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
SStreamTask* pTask = *(SStreamTask**)pIter;
|
||||
if (pTask->taskLevel != TASK_LEVEL__SOURCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pTask->status.taskStatus == TASK_STATUS__RECOVER_PREPARE || pTask->status.taskStatus == TASK_STATUS__WAIT_DOWNSTREAM) {
|
||||
tqDebug("stream task:%d skip push data, not ready for processing, status %d", pTask->id.taskId,
|
||||
pTask->status.taskStatus);
|
||||
continue;
|
||||
}
|
||||
|
||||
char key[128] = {0};
|
||||
createStreamTaskOffsetKey(key, pTask->id.streamId, pTask->id.taskId);
|
||||
|
||||
STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, key);
|
||||
if (pOffset == NULL) {
|
||||
doSaveTaskOffset(pTq->pOffsetStore, key, ver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void doSaveTaskOffset(STqOffsetStore* pOffsetStore, const char* pKey, int64_t ver) {
|
||||
STqOffset offset = {0};
|
||||
tqOffsetResetToLog(&offset.val, ver);
|
||||
|
||||
tstrncpy(offset.subKey, pKey, tListLen(offset.subKey));
|
||||
|
||||
// keep the offset info in the offset store
|
||||
tqOffsetWrite(pOffsetStore, &offset);
|
||||
}
|
||||
|
||||
static int32_t tqInitDataRsp(SMqDataRsp* pRsp, const SMqPollReq* pReq, int8_t subType) {
|
||||
pRsp->reqOffset = pReq->reqOffset;
|
||||
|
||||
pRsp->blockData = taosArrayInit(0, sizeof(void*));
|
||||
pRsp->blockDataLen = taosArrayInit(0, sizeof(int32_t));
|
||||
|
||||
if (pRsp->blockData == NULL || pRsp->blockDataLen == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pRsp->withTbName = 0;
|
||||
pRsp->withSchema = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tqInitTaosxRsp(STaosxRsp* pRsp, const SMqPollReq* pReq) {
|
||||
pRsp->reqOffset = pReq->reqOffset;
|
||||
|
||||
pRsp->withTbName = 1;
|
||||
pRsp->withSchema = 1;
|
||||
pRsp->blockData = taosArrayInit(0, sizeof(void*));
|
||||
pRsp->blockDataLen = taosArrayInit(0, sizeof(int32_t));
|
||||
pRsp->blockTbName = taosArrayInit(0, sizeof(void*));
|
||||
pRsp->blockSchema = taosArrayInit(0, sizeof(void*));
|
||||
|
||||
if (pRsp->blockData == NULL || pRsp->blockDataLen == NULL || pRsp->blockTbName == NULL || pRsp->blockSchema == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t extractResetOffsetVal(STqOffsetVal* pOffsetVal, STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
|
||||
SRpcMsg* pMsg, bool* pBlockReturned) {
|
||||
uint64_t consumerId = pRequest->consumerId;
|
||||
STqOffsetVal reqOffset = pRequest->reqOffset;
|
||||
STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, pRequest->subKey);
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
|
||||
*pBlockReturned = false;
|
||||
|
||||
// In this vnode, data has been polled by consumer for this topic, so let's continue from the last offset value.
|
||||
if (pOffset != NULL) {
|
||||
*pOffsetVal = pOffset->val;
|
||||
|
||||
char formatBuf[80];
|
||||
tFormatOffset(formatBuf, 80, pOffsetVal);
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, existed offset found, offset reset to %s and continue. reqId:0x%"PRIx64,
|
||||
consumerId, pHandle->subKey, vgId, formatBuf, pRequest->reqId);
|
||||
return 0;
|
||||
} else {
|
||||
// no poll occurs in this vnode for this topic, let's seek to the right offset value.
|
||||
if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEAST) {
|
||||
if (pRequest->useSnapshot) {
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey:%s, vgId:%d, (earliest) set offset to be snapshot",
|
||||
consumerId, pHandle->subKey, vgId);
|
||||
|
||||
if (pHandle->fetchMeta) {
|
||||
tqOffsetResetToMeta(pOffsetVal, 0);
|
||||
} else {
|
||||
tqOffsetResetToData(pOffsetVal, 0, 0);
|
||||
}
|
||||
} else {
|
||||
pHandle->pRef = walRefFirstVer(pTq->pVnode->pWal, pHandle->pRef);
|
||||
if (pHandle->pRef == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// offset set to previous version when init
|
||||
tqOffsetResetToLog(pOffsetVal, pHandle->pRef->refVer - 1);
|
||||
}
|
||||
} else if (reqOffset.type == TMQ_OFFSET__RESET_LATEST) {
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
SMqDataRsp dataRsp = {0};
|
||||
tqInitDataRsp(&dataRsp, pRequest, pHandle->execHandle.subType);
|
||||
|
||||
tqOffsetResetToLog(&dataRsp.rspOffset, walGetLastVer(pTq->pVnode->pWal));
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, (latest) offset reset to %" PRId64, consumerId,
|
||||
pHandle->subKey, vgId, dataRsp.rspOffset.version);
|
||||
int32_t code = tqSendDataRsp(pTq, pMsg, pRequest, &dataRsp, TMQ_MSG_TYPE__POLL_RSP);
|
||||
tDeleteSMqDataRsp(&dataRsp);
|
||||
|
||||
*pBlockReturned = true;
|
||||
return code;
|
||||
} else {
|
||||
STaosxRsp taosxRsp = {0};
|
||||
tqInitTaosxRsp(&taosxRsp, pRequest);
|
||||
tqOffsetResetToLog(&taosxRsp.rspOffset, walGetLastVer(pTq->pVnode->pWal));
|
||||
int32_t code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
|
||||
*pBlockReturned = true;
|
||||
return code;
|
||||
}
|
||||
} else if (reqOffset.type == TMQ_OFFSET__RESET_NONE) {
|
||||
tqError("tmq poll: subkey:%s, no offset committed for consumer:0x%" PRIx64 " in vg %d, subkey %s, reset none failed",
|
||||
pHandle->subKey, consumerId, vgId, pRequest->subKey);
|
||||
terrno = TSDB_CODE_TQ_NO_COMMITTED_OFFSET;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
|
||||
SRpcMsg* pMsg, STqOffsetVal* pOffset) {
|
||||
uint64_t consumerId = pRequest->consumerId;
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
|
||||
SMqDataRsp dataRsp = {0};
|
||||
tqInitDataRsp(&dataRsp, pRequest, pHandle->execHandle.subType);
|
||||
|
||||
// lock
|
||||
taosWLockLatch(&pTq->lock);
|
||||
|
||||
qSetTaskId(pHandle->execHandle.task, consumerId, pRequest->reqId);
|
||||
int code = tqScanData(pTq, pHandle, &dataRsp, pOffset);
|
||||
if(code != 0) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
// till now, all data has been transferred to consumer, new data needs to push client once arrived.
|
||||
if (dataRsp.blockNum == 0 && dataRsp.reqOffset.type == TMQ_OFFSET__LOG &&
|
||||
dataRsp.reqOffset.version == dataRsp.rspOffset.version && pHandle->consumerId == pRequest->consumerId) {
|
||||
code = tqRegisterPushHandle(pTq, pHandle, pRequest, pMsg, &dataRsp, TMQ_MSG_TYPE__POLL_RSP);
|
||||
taosWUnLockLatch(&pTq->lock);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&dataRsp, TMQ_MSG_TYPE__POLL_RSP);
|
||||
|
||||
// NOTE: this pHandle->consumerId may have been changed already.
|
||||
|
||||
end:
|
||||
{
|
||||
char buf[80] = {0};
|
||||
tFormatOffset(buf, 80, &dataRsp.rspOffset);
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, rsp block:%d, rsp offset type:%s, reqId:0x%" PRIx64 " code:%d",
|
||||
consumerId, pHandle->subKey, vgId, dataRsp.blockNum, buf, pRequest->reqId, code);
|
||||
taosWUnLockLatch(&pTq->lock);
|
||||
tDeleteSMqDataRsp(&dataRsp);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest, SRpcMsg* pMsg, STqOffsetVal *offset) {
|
||||
int code = 0;
|
||||
int32_t vgId = TD_VID(pTq->pVnode);
|
||||
SWalCkHead* pCkHead = NULL;
|
||||
SMqMetaRsp metaRsp = {0};
|
||||
STaosxRsp taosxRsp = {0};
|
||||
tqInitTaosxRsp(&taosxRsp, pRequest);
|
||||
|
||||
if (offset->type != TMQ_OFFSET__LOG) {
|
||||
if (tqScanTaosx(pTq, pHandle, &taosxRsp, &metaRsp, offset) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (metaRsp.metaRspLen > 0) {
|
||||
code = tqSendMetaPollRsp(pTq, pMsg, pRequest, &metaRsp);
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send meta offset type:%d,uid:%" PRId64 ",ts:%" PRId64,
|
||||
pRequest->consumerId, pHandle->subKey, vgId, metaRsp.rspOffset.type, metaRsp.rspOffset.uid, metaRsp.rspOffset.ts);
|
||||
taosMemoryFree(metaRsp.metaRsp);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
return code;
|
||||
}
|
||||
|
||||
tqDebug("taosx poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send data blockNum:%d, offset type:%d,uid:%" PRId64
|
||||
",ts:%" PRId64,pRequest->consumerId, pHandle->subKey, vgId, taosxRsp.blockNum, taosxRsp.rspOffset.type, taosxRsp.rspOffset.uid,taosxRsp.rspOffset.ts);
|
||||
if (taosxRsp.blockNum > 0) {
|
||||
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
return code;
|
||||
}else {
|
||||
*offset = taosxRsp.rspOffset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (offset->type == TMQ_OFFSET__LOG) {
|
||||
int64_t fetchVer = offset->version + 1;
|
||||
pCkHead = taosMemoryMalloc(sizeof(SWalCkHead) + 2048);
|
||||
if (pCkHead == NULL) {
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
walSetReaderCapacity(pHandle->pWalReader, 2048);
|
||||
int totalRows = 0;
|
||||
while (1) {
|
||||
int32_t savedEpoch = atomic_load_32(&pHandle->epoch);
|
||||
if (savedEpoch > pRequest->epoch) {
|
||||
tqWarn("tmq poll: consumer:0x%" PRIx64 " (epoch %d), subkey:%s vgId:%d offset %" PRId64
|
||||
", found new consumer epoch %d, discard req epoch %d", pRequest->consumerId, pRequest->epoch, pHandle->subKey, vgId, fetchVer, savedEpoch, pRequest->epoch);
|
||||
break;
|
||||
}
|
||||
|
||||
if (tqFetchLog(pTq, pHandle, &fetchVer, &pCkHead, pRequest->reqId) < 0) {
|
||||
tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);
|
||||
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
return code;
|
||||
}
|
||||
|
||||
SWalCont* pHead = &pCkHead->head;
|
||||
tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, vgId:%d offset %" PRId64 " msgType %d", pRequest->consumerId,
|
||||
pRequest->epoch, vgId, fetchVer, pHead->msgType);
|
||||
|
||||
// process meta
|
||||
if (pHead->msgType != TDMT_VND_SUBMIT) {
|
||||
if(totalRows > 0) {
|
||||
tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer - 1);
|
||||
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
return code;
|
||||
}
|
||||
|
||||
tqDebug("fetch meta msg, ver:%" PRId64 ", type:%s", pHead->version, TMSG_INFO(pHead->msgType));
|
||||
tqOffsetResetToLog(&metaRsp.rspOffset, fetchVer);
|
||||
metaRsp.resMsgType = pHead->msgType;
|
||||
metaRsp.metaRspLen = pHead->bodyLen;
|
||||
metaRsp.metaRsp = pHead->body;
|
||||
if (tqSendMetaPollRsp(pTq, pMsg, pRequest, &metaRsp) < 0) {
|
||||
code = -1;
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
return code;
|
||||
}
|
||||
code = 0;
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
return code;
|
||||
}
|
||||
|
||||
// process data
|
||||
SPackedData submit = {
|
||||
.msgStr = POINTER_SHIFT(pHead->body, sizeof(SSubmitReq2Msg)),
|
||||
.msgLen = pHead->bodyLen - sizeof(SSubmitReq2Msg),
|
||||
.ver = pHead->version,
|
||||
};
|
||||
|
||||
if (tqTaosxScanLog(pTq, pHandle, submit, &taosxRsp, &totalRows) < 0) {
|
||||
tqError("tmq poll: tqTaosxScanLog error %" PRId64 ", in vgId:%d, subkey %s", pRequest->consumerId, vgId,
|
||||
pRequest->subKey);
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (totalRows >= 4096 || taosxRsp.createTableNum > 0) {
|
||||
tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);
|
||||
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
return code;
|
||||
} else {
|
||||
fetchVer++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tDeleteSTaosxRsp(&taosxRsp);
|
||||
taosMemoryFreeClear(pCkHead);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tqExtractDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest, SRpcMsg* pMsg) {
|
||||
int32_t code = -1;
|
||||
STqOffsetVal offset = {0};
|
||||
STqOffsetVal reqOffset = pRequest->reqOffset;
|
||||
|
||||
// 1. reset the offset if needed
|
||||
if (IS_OFFSET_RESET_TYPE(reqOffset.type)) {
|
||||
// handle the reset offset cases, according to the consumer's choice.
|
||||
bool blockReturned = false;
|
||||
code = extractResetOffsetVal(&offset, pTq, pHandle, pRequest, pMsg, &blockReturned);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
// empty block returned, quit
|
||||
if (blockReturned) {
|
||||
return 0;
|
||||
}
|
||||
} else { // use the consumer specified offset
|
||||
// the offset value can not be monotonious increase??
|
||||
offset = reqOffset;
|
||||
}
|
||||
|
||||
// this is a normal subscribe requirement
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
return extractDataAndRspForNormalSubscribe(pTq, pHandle, pRequest, pMsg, &offset);
|
||||
}
|
||||
|
||||
// todo handle the case where re-balance occurs.
|
||||
// for taosx
|
||||
return extractDataAndRspForDbStbSubscribe(pTq, pHandle, pRequest, pMsg, &offset);
|
||||
}
|
||||
|
||||
int32_t tqSendMetaPollRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqMetaRsp* pRsp) {
|
||||
int32_t len = 0;
|
||||
int32_t code = 0;
|
||||
tEncodeSize(tEncodeSMqMetaRsp, pRsp, len, code);
|
||||
if (code < 0) {
|
||||
return -1;
|
||||
}
|
||||
int32_t tlen = sizeof(SMqRspHead) + len;
|
||||
void* buf = rpcMallocCont(tlen);
|
||||
if (buf == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_META_RSP;
|
||||
((SMqRspHead*)buf)->epoch = pReq->epoch;
|
||||
((SMqRspHead*)buf)->consumerId = pReq->consumerId;
|
||||
|
||||
void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
|
||||
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, abuf, len);
|
||||
tEncodeSMqMetaRsp(&encoder, pRsp);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
SRpcMsg resp = {
|
||||
.info = pMsg->info,
|
||||
.pCont = buf,
|
||||
.contLen = tlen,
|
||||
.code = 0,
|
||||
};
|
||||
tmsgSendRsp(&resp);
|
||||
|
||||
tqDebug("vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) send rsp, res msg type %d, offset type:%d",
|
||||
TD_VID(pTq->pVnode), pReq->consumerId, pReq->epoch, pRsp->resMsgType, pRsp->rspOffset.type);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -35,7 +35,11 @@ _err:
|
|||
static void tsdbCloseBICache(STsdb *pTsdb) {
|
||||
SLRUCache *pCache = pTsdb->biCache;
|
||||
if (pCache) {
|
||||
int32_t elems = taosLRUCacheGetElems(pCache);
|
||||
tsdbTrace("vgId:%d, elems: %d", TD_VID(pTsdb->pVnode), elems);
|
||||
taosLRUCacheEraseUnrefEntries(pCache);
|
||||
elems = taosLRUCacheGetElems(pCache);
|
||||
tsdbTrace("vgId:%d, elems: %d", TD_VID(pTsdb->pVnode), elems);
|
||||
|
||||
taosLRUCacheCleanup(pCache);
|
||||
|
||||
|
@ -820,7 +824,12 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie
|
|||
* &state->blockIdx);
|
||||
*/
|
||||
state->pBlockIdx = taosArraySearch(state->aBlockIdx, state->pBlockIdxExp, tCmprBlockIdx, TD_EQ);
|
||||
if (!state->pBlockIdx) { /*
|
||||
if (!state->pBlockIdx) {
|
||||
tsdbBICacheRelease(state->pTsdb->biCache, state->aBlockIdxHandle);
|
||||
|
||||
state->aBlockIdxHandle = NULL;
|
||||
state->aBlockIdx = NULL;
|
||||
/*
|
||||
tsdbDataFReaderClose(state->pDataFReader);
|
||||
*state->pDataFReader = NULL;
|
||||
resetLastBlockLoadInfo(state->pLoadInfo);*/
|
||||
|
@ -1469,11 +1478,14 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, SArray **ppCo
|
|||
|
||||
hasRow = true;
|
||||
|
||||
code = updateTSchema(TSDBROW_SVERSION(pRow), pr, uid);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _err;
|
||||
int32_t sversion = TSDBROW_SVERSION(pRow);
|
||||
if (sversion != -1) {
|
||||
code = updateTSchema(sversion, pr, uid);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _err;
|
||||
}
|
||||
pTSchema = pr->pCurrSchema;
|
||||
}
|
||||
pTSchema = pr->pCurrSchema;
|
||||
int16_t nCol = pTSchema->numOfCols;
|
||||
|
||||
TSKEY rowTs = TSDBROW_TS(pRow);
|
||||
|
@ -1623,11 +1635,14 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SCach
|
|||
|
||||
hasRow = true;
|
||||
|
||||
code = updateTSchema(TSDBROW_SVERSION(pRow), pr, uid);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _err;
|
||||
int32_t sversion = TSDBROW_SVERSION(pRow);
|
||||
if (sversion != -1) {
|
||||
code = updateTSchema(sversion, pr, uid);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
goto _err;
|
||||
}
|
||||
pTSchema = pr->pCurrSchema;
|
||||
}
|
||||
pTSchema = pr->pCurrSchema;
|
||||
int16_t nCol = pTSchema->numOfCols;
|
||||
|
||||
TSKEY rowTs = TSDBROW_TS(pRow);
|
||||
|
@ -1931,6 +1946,7 @@ int32_t tsdbCacheGetBlockIdx(SLRUCache *pCache, SDataFReader *pFileReader, LRUHa
|
|||
taosThreadMutexUnlock(&pTsdb->biMutex);
|
||||
}
|
||||
|
||||
tsdbTrace("bi cache:%p, ref", pCache);
|
||||
*handle = h;
|
||||
|
||||
return code;
|
||||
|
@ -1940,6 +1956,7 @@ int32_t tsdbBICacheRelease(SLRUCache *pCache, LRUHandle *h) {
|
|||
int32_t code = 0;
|
||||
|
||||
taosLRUCacheRelease(pCache, h, false);
|
||||
tsdbTrace("bi cache:%p, release", pCache);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -831,6 +831,7 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFReader* pFileReader,
|
|||
// this block belongs to a table that is not queried.
|
||||
STableBlockScanInfo* pScanInfo = getTableBlockScanInfo(pReader->status.pTableMap, pBlockIdx->uid, pReader->idStr);
|
||||
if (pScanInfo == NULL) {
|
||||
tsdbBICacheRelease(pFileReader->pTsdb->biCache, handle);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
|
@ -1969,7 +1970,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
if (pReader->order == TSDB_ORDER_ASC) {
|
||||
if (minKey == key) {
|
||||
init = true;
|
||||
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||
int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -1979,10 +1980,10 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
if (minKey == tsLast) {
|
||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||
if (init) {
|
||||
tsdbRowMerge(&merge, &fRow1);
|
||||
tsdbRowMergerAdd(&merge, &fRow1, NULL);
|
||||
} else {
|
||||
init = true;
|
||||
int32_t code = tsdbRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
||||
int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow1, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -1999,7 +2000,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
tsdbRowMergerAdd(&merge, pRow, pSchema);
|
||||
} else {
|
||||
init = true;
|
||||
int32_t code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
||||
int32_t code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2013,7 +2014,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
if (minKey == k.ts) {
|
||||
init = true;
|
||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||
int32_t code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
||||
int32_t code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2027,10 +2028,10 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
if (minKey == tsLast) {
|
||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||
if (init) {
|
||||
tsdbRowMerge(&merge, &fRow1);
|
||||
tsdbRowMergerAdd(&merge, &fRow1, NULL);
|
||||
} else {
|
||||
init = true;
|
||||
int32_t code = tsdbRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
||||
int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow1, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2040,10 +2041,10 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
|
||||
if (minKey == key) {
|
||||
if (init) {
|
||||
tsdbRowMerge(&merge, &fRow);
|
||||
tsdbRowMergerAdd(&merge, &fRow, NULL);
|
||||
} else {
|
||||
init = true;
|
||||
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||
int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2088,13 +2089,13 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
|||
pBlockScanInfo->lastKey = tsLastBlock;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else {
|
||||
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||
code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||
tsdbRowMerge(&merge, &fRow1);
|
||||
tsdbRowMergerAdd(&merge, &fRow1, NULL);
|
||||
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge, &pReader->verRange, pReader->idStr);
|
||||
|
||||
code = tsdbRowMergerGetRow(&merge, &pTSRow);
|
||||
|
@ -2112,7 +2113,7 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
|||
}
|
||||
}
|
||||
} else { // not merge block data
|
||||
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||
code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2164,7 +2165,7 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader
|
|||
SRow* pTSRow = NULL;
|
||||
SRowMerger merge = {0};
|
||||
|
||||
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||
int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2172,7 +2173,7 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader
|
|||
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
||||
|
||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||
tsdbRowMerge(&merge, &fRow1);
|
||||
tsdbRowMergerAdd(&merge, &fRow1, NULL);
|
||||
|
||||
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, ts, &merge, &pReader->verRange, pReader->idStr);
|
||||
|
||||
|
@ -2215,8 +2216,16 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
|
||||
int64_t key = hasDataInFileBlock(pBlockData, pDumpInfo) ? pBlockData->aTSKEY[pDumpInfo->rowIndex] : INT64_MIN;
|
||||
|
||||
TSDBKEY k = TSDBROW_KEY(pRow);
|
||||
TSDBKEY ik = TSDBROW_KEY(piRow);
|
||||
TSDBKEY k = TSDBROW_KEY(pRow);
|
||||
TSDBKEY ik = TSDBROW_KEY(piRow);
|
||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||
if (pSchema == NULL) {
|
||||
return code;
|
||||
}
|
||||
STSchema* piSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
||||
if (piSchema == NULL) {
|
||||
return code;
|
||||
}
|
||||
|
||||
int64_t minKey = 0;
|
||||
if (ASCENDING_TRAVERSE(pReader->order)) {
|
||||
|
@ -2263,7 +2272,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
if (minKey == key) {
|
||||
init = true;
|
||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
||||
code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||
code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2274,10 +2283,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
if (minKey == tsLast) {
|
||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||
if (init) {
|
||||
tsdbRowMerge(&merge, &fRow1);
|
||||
tsdbRowMergerAdd(&merge, &fRow1, NULL);
|
||||
} else {
|
||||
init = true;
|
||||
code = tsdbRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
||||
code = tsdbRowMergerInit(&merge, NULL, &fRow1, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2288,15 +2297,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
|
||||
if (minKey == ik.ts) {
|
||||
if (init) {
|
||||
tsdbRowMerge(&merge, piRow);
|
||||
tsdbRowMergerAdd(&merge, piRow, piSchema);
|
||||
} else {
|
||||
init = true;
|
||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
||||
if (pSchema == NULL) {
|
||||
return code;
|
||||
}
|
||||
|
||||
code = tsdbRowMergerInit(&merge, piRow, pSchema);
|
||||
code = tsdbRowMergerInit(&merge, pSchema, piRow, piSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2315,10 +2319,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
return code;
|
||||
}
|
||||
|
||||
tsdbRowMerge(&merge, pRow);
|
||||
tsdbRowMergerAdd(&merge, pRow, pSchema);
|
||||
} else {
|
||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||
code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
||||
// STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||
code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2332,8 +2336,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
} else {
|
||||
if (minKey == k.ts) {
|
||||
init = true;
|
||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||
code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
||||
code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2347,11 +2350,11 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
|
||||
if (minKey == ik.ts) {
|
||||
if (init) {
|
||||
tsdbRowMerge(&merge, piRow);
|
||||
tsdbRowMergerAdd(&merge, piRow, piSchema);
|
||||
} else {
|
||||
init = true;
|
||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
||||
code = tsdbRowMergerInit(&merge, piRow, pSchema);
|
||||
// STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
||||
code = tsdbRowMergerInit(&merge, pSchema, piRow, piSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2366,10 +2369,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
if (minKey == tsLast) {
|
||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||
if (init) {
|
||||
tsdbRowMerge(&merge, &fRow1);
|
||||
tsdbRowMergerAdd(&merge, &fRow1, NULL);
|
||||
} else {
|
||||
init = true;
|
||||
code = tsdbRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
||||
code = tsdbRowMergerInit(&merge, NULL, &fRow1, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2380,7 +2383,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
if (minKey == key) {
|
||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
||||
if (!init) {
|
||||
code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||
code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2388,7 +2391,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
|||
if (merge.pTSchema == NULL) {
|
||||
return code;
|
||||
}
|
||||
tsdbRowMerge(&merge, &fRow);
|
||||
tsdbRowMergerAdd(&merge, &fRow, NULL);
|
||||
}
|
||||
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
||||
}
|
||||
|
@ -2573,7 +2576,7 @@ int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBloc
|
|||
SRow* pTSRow = NULL;
|
||||
SRowMerger merge = {0};
|
||||
|
||||
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
||||
code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -3240,8 +3243,8 @@ static int32_t readRowsCountFromFiles(STsdbReader* pReader) {
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
while (1) {
|
||||
bool hasNext = false;
|
||||
int32_t code = filesetIteratorNext(&pReader->status.fileIter, pReader, &hasNext);
|
||||
bool hasNext = false;
|
||||
code = filesetIteratorNext(&pReader->status.fileIter, pReader, &hasNext);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
@ -3513,8 +3516,8 @@ SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, int8_
|
|||
int64_t startVer = (pCond->startVersion == -1) ? 0 : pCond->startVersion;
|
||||
|
||||
int64_t endVer = 0;
|
||||
if (pCond->endVersion ==
|
||||
-1) { // user not specified end version, set current maximum version of vnode as the endVersion
|
||||
if (pCond->endVersion == -1) {
|
||||
// user not specified end version, set current maximum version of vnode as the endVersion
|
||||
endVer = pVnode->state.applied;
|
||||
} else {
|
||||
endVer = (pCond->endVersion > pVnode->state.applied) ? pVnode->state.applied : pCond->endVersion;
|
||||
|
@ -3694,7 +3697,7 @@ int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDe
|
|||
|
||||
tsdbRowMergerAdd(pMerger, pRow, pTSchema);
|
||||
} else { // column format
|
||||
tsdbRowMerge(pMerger, pRow);
|
||||
tsdbRowMergerAdd(pMerger, pRow, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3710,7 +3713,7 @@ static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t rowInd
|
|||
}
|
||||
|
||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, rowIndex);
|
||||
tsdbRowMerge(pMerger, &fRow);
|
||||
tsdbRowMergerAdd(pMerger, &fRow, NULL);
|
||||
rowIndex += step;
|
||||
}
|
||||
|
||||
|
@ -3788,7 +3791,7 @@ int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockSc
|
|||
int64_t next1 = getCurrentKeyInLastBlock(pLastBlockReader);
|
||||
if (next1 == ts) {
|
||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||
tsdbRowMerge(pMerger, &fRow1);
|
||||
tsdbRowMergerAdd(pMerger, &fRow1, NULL);
|
||||
} else {
|
||||
tsdbTrace("uid:%" PRIu64 " last del index:%d, del range:%d, lastKeyInStt:%" PRId64 ", %s", pScanInfo->uid,
|
||||
pScanInfo->lastBlockDelIndex, (int32_t)taosArrayGetSize(pScanInfo->delSkyline), pScanInfo->lastKeyInStt,
|
||||
|
@ -3844,7 +3847,7 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
|
|||
pReader->pSchema = pTSchema;
|
||||
}
|
||||
|
||||
code = tsdbRowMergerInit2(&merge, pReader->pSchema, ¤t, pTSchema);
|
||||
code = tsdbRowMergerInit(&merge, pReader->pSchema, ¤t, pTSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -3856,12 +3859,12 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
|
|||
|
||||
tsdbRowMergerAdd(&merge, pNextRow, pTSchema1);
|
||||
} else { // let's merge rows in file block
|
||||
code = tsdbRowMergerInit(&merge, ¤t, pReader->pSchema);
|
||||
code = tsdbRowMergerInit(&merge, NULL, ¤t, pReader->pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
tsdbRowMerge(&merge, pNextRow);
|
||||
tsdbRowMergerAdd(&merge, pNextRow, NULL);
|
||||
}
|
||||
|
||||
code = doMergeRowsInBuf(pIter, uid, TSDBROW_TS(¤t), pDelList, &merge, pReader);
|
||||
|
@ -3885,14 +3888,13 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
|||
SRow** pTSRow) {
|
||||
SRowMerger merge = {0};
|
||||
|
||||
TSDBKEY k = TSDBROW_KEY(pRow);
|
||||
TSDBKEY ik = TSDBROW_KEY(piRow);
|
||||
TSDBKEY k = TSDBROW_KEY(pRow);
|
||||
TSDBKEY ik = TSDBROW_KEY(piRow);
|
||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||
STSchema* piSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
||||
|
||||
if (ASCENDING_TRAVERSE(pReader->order)) { // ascending order imem --> mem
|
||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||
STSchema* piSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
||||
|
||||
int32_t code = tsdbRowMergerInit2(&merge, pSchema, piRow, piSchema);
|
||||
int32_t code = tsdbRowMergerInit(&merge, pSchema, piRow, piSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -3911,9 +3913,7 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
|||
}
|
||||
|
||||
} else {
|
||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||
|
||||
int32_t code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
||||
int32_t code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS || merge.pTSchema == NULL) {
|
||||
return code;
|
||||
}
|
||||
|
@ -3924,7 +3924,7 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
|||
return code;
|
||||
}
|
||||
|
||||
tsdbRowMerge(&merge, piRow);
|
||||
tsdbRowMergerAdd(&merge, piRow, piSchema);
|
||||
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, &merge,
|
||||
pReader);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -638,13 +638,17 @@ SColVal *tsdbRowIterNext(STSDBRowIter *pIter) {
|
|||
|
||||
// SRowMerger ======================================================
|
||||
|
||||
int32_t tsdbRowMergerInit2(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRow, STSchema *pTSchema) {
|
||||
int32_t tsdbRowMergerInit(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRow, STSchema *pTSchema) {
|
||||
int32_t code = 0;
|
||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||
SColVal *pColVal = &(SColVal){0};
|
||||
STColumn *pTColumn;
|
||||
int32_t iCol, jCol = 0;
|
||||
|
||||
if (NULL == pResTSchema) {
|
||||
pResTSchema = pTSchema;
|
||||
}
|
||||
|
||||
pMerger->pTSchema = pResTSchema;
|
||||
pMerger->version = key.version;
|
||||
|
||||
|
@ -712,6 +716,9 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
|||
STColumn *pTColumn;
|
||||
int32_t iCol, jCol = 1;
|
||||
|
||||
if (NULL == pTSchema) {
|
||||
pTSchema = pMerger->pTSchema;
|
||||
}
|
||||
ASSERT(((SColVal *)pMerger->pArray->pData)->value.val == key.ts);
|
||||
|
||||
for (iCol = 1; iCol < pMerger->pTSchema->numOfCols && jCol < pTSchema->numOfCols; ++iCol) {
|
||||
|
@ -727,23 +734,6 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
|||
tsdbRowGetColVal(pRow, pTSchema, jCol++, pColVal);
|
||||
|
||||
if (key.version > pMerger->version) {
|
||||
#if 0
|
||||
if (!COL_VAL_IS_NONE(pColVal)) {
|
||||
if ((!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->type)) {
|
||||
SColVal *tColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||
code = tRealloc(&tColVal->value.pData, pColVal->value.nData);
|
||||
if (code) return code;
|
||||
|
||||
tColVal->value.nData = pColVal->value.nData;
|
||||
if (pColVal->value.nData) {
|
||||
memcpy(tColVal->value.pData, pColVal->value.pData, pColVal->value.nData);
|
||||
}
|
||||
tColVal->flag = 0;
|
||||
} else {
|
||||
taosArraySet(pMerger->pArray, iCol, pColVal);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!COL_VAL_IS_NONE(pColVal)) {
|
||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
||||
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||
|
@ -758,7 +748,6 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
|||
pTColVal->flag = 0;
|
||||
} else {
|
||||
tFree(pTColVal->value.pData);
|
||||
pTColVal->value.pData = NULL;
|
||||
taosArraySet(pMerger->pArray, iCol, pColVal);
|
||||
}
|
||||
} else {
|
||||
|
@ -789,7 +778,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
|||
pMerger->version = key.version;
|
||||
return code;
|
||||
}
|
||||
|
||||
/*
|
||||
int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
||||
int32_t code = 0;
|
||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||
|
@ -840,7 +829,7 @@ int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema
|
|||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
*/
|
||||
void tsdbRowMergerClear(SRowMerger *pMerger) {
|
||||
for (int32_t iCol = 1; iCol < pMerger->pTSchema->numOfCols; iCol++) {
|
||||
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||
|
@ -851,7 +840,7 @@ void tsdbRowMergerClear(SRowMerger *pMerger) {
|
|||
|
||||
taosArrayDestroy(pMerger->pArray);
|
||||
}
|
||||
|
||||
/*
|
||||
int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow) {
|
||||
int32_t code = 0;
|
||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||
|
@ -916,7 +905,7 @@ int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow) {
|
|||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
*/
|
||||
int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow) {
|
||||
return tRowBuild(pMerger->pArray, pMerger->pTSchema, ppRow);
|
||||
}
|
||||
|
|
|
@ -400,7 +400,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
|||
}
|
||||
break;
|
||||
case TDMT_STREAM_TASK_DEPLOY: {
|
||||
if (tqProcessTaskDeployReq(pVnode->pTq, version, pReq, len) < 0) {
|
||||
if (pVnode->restored && tqProcessTaskDeployReq(pVnode->pTq, version, pReq, len) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
} break;
|
||||
|
@ -447,13 +447,11 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
|||
|
||||
walApplyVer(pVnode->pWal, version);
|
||||
|
||||
/*vInfo("vgId:%d, push msg begin", pVnode->config.vgId);*/
|
||||
if (tqPushMsg(pVnode->pTq, pMsg->pCont, pMsg->contLen, pMsg->msgType, version) < 0) {
|
||||
/*vInfo("vgId:%d, push msg end", pVnode->config.vgId);*/
|
||||
vError("vgId:%d, failed to push msg to TQ since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
/*vInfo("vgId:%d, push msg end", pVnode->config.vgId);*/
|
||||
|
||||
// commit if need
|
||||
if (needCommit) {
|
||||
|
@ -543,10 +541,8 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
|
|||
return tqProcessPollReq(pVnode->pTq, pMsg);
|
||||
case TDMT_STREAM_TASK_RUN:
|
||||
return tqProcessTaskRunReq(pVnode->pTq, pMsg);
|
||||
#if 1
|
||||
case TDMT_STREAM_TASK_DISPATCH:
|
||||
return tqProcessTaskDispatchReq(pVnode->pTq, pMsg, true);
|
||||
#endif
|
||||
case TDMT_STREAM_TASK_CHECK:
|
||||
return tqProcessStreamTaskCheckReq(pVnode->pTq, pMsg);
|
||||
case TDMT_STREAM_TASK_DISPATCH_RSP:
|
||||
|
|
|
@ -549,6 +549,9 @@ static void vnodeRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx)
|
|||
|
||||
pVnode->restored = true;
|
||||
vInfo("vgId:%d, sync restore finished", pVnode->config.vgId);
|
||||
|
||||
// start to restore all stream tasks
|
||||
tqStartStreamTasks(pVnode->pTq);
|
||||
}
|
||||
|
||||
static void vnodeBecomeFollower(const SSyncFSM *pFsm) {
|
||||
|
|
|
@ -8,9 +8,9 @@ target_include_directories(
|
|||
|
||||
target_link_libraries(
|
||||
catalog
|
||||
PRIVATE os util transport qcom
|
||||
PRIVATE os util transport qcom nodes
|
||||
)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
ADD_SUBDIRECTORY(test)
|
||||
endif(${BUILD_TEST})
|
||||
endif(${BUILD_TEST})
|
||||
|
|
|
@ -66,8 +66,8 @@ typedef enum {
|
|||
} CTG_CACHE_ITEM;
|
||||
|
||||
#define CTG_CI_FLAG_LEVEL_GLOBAL (1)
|
||||
#define CTG_CI_FLAG_LEVEL_CLUSTER (1<<1)
|
||||
#define CTG_CI_FLAG_LEVEL_DB (1<<2)
|
||||
#define CTG_CI_FLAG_LEVEL_CLUSTER (1 << 1)
|
||||
#define CTG_CI_FLAG_LEVEL_DB (1 << 2)
|
||||
|
||||
enum {
|
||||
CTG_READ = 1,
|
||||
|
@ -132,6 +132,19 @@ typedef struct SCtgCacheStat {
|
|||
uint64_t cacheNHit[CTG_CI_MAX_VALUE];
|
||||
} SCtgCacheStat;
|
||||
|
||||
typedef struct SCtgAuthReq {
|
||||
SRequestConnInfo* pConn;
|
||||
SUserAuthInfo* pRawReq;
|
||||
SGetUserAuthRsp authInfo;
|
||||
AUTH_TYPE singleType;
|
||||
bool onlyCache;
|
||||
} SCtgAuthReq;
|
||||
|
||||
typedef struct SCtgAuthRsp {
|
||||
SUserAuthRes* pRawRes;
|
||||
bool metaNotExists;
|
||||
} SCtgAuthRsp;
|
||||
|
||||
typedef struct SCtgTbCacheInfo {
|
||||
bool inCache;
|
||||
uint64_t dbId;
|
||||
|
@ -224,13 +237,13 @@ typedef struct SCtgVgCache {
|
|||
} SCtgVgCache;
|
||||
|
||||
typedef struct SCtgDBCache {
|
||||
SRWLatch dbLock; // RC between destroy tbCache/stbCache and all reads
|
||||
uint64_t dbId;
|
||||
int8_t deleted;
|
||||
SCtgVgCache vgCache;
|
||||
SHashObj* tbCache; // key:tbname, value:SCtgTbCache
|
||||
SHashObj* stbCache; // key:suid, value:char*
|
||||
uint64_t dbCacheNum[CTG_CI_MAX_VALUE];
|
||||
SRWLatch dbLock; // RC between destroy tbCache/stbCache and all reads
|
||||
uint64_t dbId;
|
||||
int8_t deleted;
|
||||
SCtgVgCache vgCache;
|
||||
SHashObj* tbCache; // key:tbname, value:SCtgTbCache
|
||||
SHashObj* stbCache; // key:suid, value:char*
|
||||
uint64_t dbCacheNum[CTG_CI_MAX_VALUE];
|
||||
} SCtgDBCache;
|
||||
|
||||
typedef struct SCtgRentSlot {
|
||||
|
@ -248,12 +261,8 @@ typedef struct SCtgRentMgmt {
|
|||
} SCtgRentMgmt;
|
||||
|
||||
typedef struct SCtgUserAuth {
|
||||
int32_t version;
|
||||
SRWLatch lock;
|
||||
bool superUser;
|
||||
SHashObj* createdDbs;
|
||||
SHashObj* readDbs;
|
||||
SHashObj* writeDbs;
|
||||
SRWLatch lock;
|
||||
SGetUserAuthRsp userAuth;
|
||||
} SCtgUserAuth;
|
||||
|
||||
typedef struct SCatalog {
|
||||
|
@ -505,11 +514,11 @@ typedef struct SCtgOperation {
|
|||
} SCtgOperation;
|
||||
|
||||
typedef struct SCtgCacheItemInfo {
|
||||
char *name;
|
||||
char* name;
|
||||
int32_t flag;
|
||||
} SCtgCacheItemInfo;
|
||||
|
||||
#define CTG_AUTH_READ(_t) ((_t) == AUTH_TYPE_READ || (_t) == AUTH_TYPE_READ_OR_WRITE)
|
||||
#define CTG_AUTH_READ(_t) ((_t) == AUTH_TYPE_READ || (_t) == AUTH_TYPE_READ_OR_WRITE)
|
||||
#define CTG_AUTH_WRITE(_t) ((_t) == AUTH_TYPE_WRITE || (_t) == AUTH_TYPE_READ_OR_WRITE)
|
||||
|
||||
#define CTG_QUEUE_INC() atomic_add_fetch_64(&gCtgMgmt.queue.qRemainNum, 1)
|
||||
|
@ -519,88 +528,90 @@ typedef struct SCtgCacheItemInfo {
|
|||
#define CTG_STAT_DEC(_item, _n) atomic_sub_fetch_64(&(_item), _n)
|
||||
#define CTG_STAT_GET(_item) atomic_load_64(&(_item))
|
||||
|
||||
#define CTG_DB_NUM_INC(_item) dbCache->dbCacheNum[_item] += 1
|
||||
#define CTG_DB_NUM_DEC(_item) dbCache->dbCacheNum[_item] -= 1
|
||||
#define CTG_DB_NUM_SET(_item) dbCache->dbCacheNum[_item] = 1
|
||||
#define CTG_DB_NUM_INC(_item) dbCache->dbCacheNum[_item] += 1
|
||||
#define CTG_DB_NUM_DEC(_item) dbCache->dbCacheNum[_item] -= 1
|
||||
#define CTG_DB_NUM_SET(_item) dbCache->dbCacheNum[_item] = 1
|
||||
#define CTG_DB_NUM_RESET(_item) dbCache->dbCacheNum[_item] = 0
|
||||
|
||||
#define CTG_STAT_API_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.api.item, n))
|
||||
#define CTG_STAT_RT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.runtime.item, n))
|
||||
#define CTG_STAT_NUM_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.cache.cacheNum[item], n))
|
||||
#define CTG_STAT_NUM_DEC(item, n) (CTG_STAT_DEC(gCtgMgmt.statInfo.cache.cacheNum[item], n))
|
||||
#define CTG_STAT_HIT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.cache.cacheHit[item], n))
|
||||
#define CTG_STAT_HIT_DEC(item, n) (CTG_STAT_DEC(gCtgMgmt.statInfo.cache.cacheHit[item], n))
|
||||
#define CTG_STAT_API_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.api.item, n))
|
||||
#define CTG_STAT_RT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.runtime.item, n))
|
||||
#define CTG_STAT_NUM_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.cache.cacheNum[item], n))
|
||||
#define CTG_STAT_NUM_DEC(item, n) (CTG_STAT_DEC(gCtgMgmt.statInfo.cache.cacheNum[item], n))
|
||||
#define CTG_STAT_HIT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.cache.cacheHit[item], n))
|
||||
#define CTG_STAT_HIT_DEC(item, n) (CTG_STAT_DEC(gCtgMgmt.statInfo.cache.cacheHit[item], n))
|
||||
#define CTG_STAT_NHIT_INC(item, n) (CTG_STAT_INC(gCtgMgmt.statInfo.cache.cacheNHit[item], n))
|
||||
#define CTG_STAT_NHIT_DEC(item, n) (CTG_STAT_DEC(gCtgMgmt.statInfo.cache.cacheNHit[item], n))
|
||||
|
||||
#define CTG_CACHE_NUM_INC(item, n) (CTG_STAT_INC(pCtg->cacheStat.cacheNum[item], n))
|
||||
#define CTG_CACHE_NUM_DEC(item, n) (CTG_STAT_DEC(pCtg->cacheStat.cacheNum[item], n))
|
||||
#define CTG_CACHE_HIT_INC(item, n) (CTG_STAT_INC(pCtg->cacheStat.cacheHit[item], n))
|
||||
#define CTG_CACHE_NUM_INC(item, n) (CTG_STAT_INC(pCtg->cacheStat.cacheNum[item], n))
|
||||
#define CTG_CACHE_NUM_DEC(item, n) (CTG_STAT_DEC(pCtg->cacheStat.cacheNum[item], n))
|
||||
#define CTG_CACHE_HIT_INC(item, n) (CTG_STAT_INC(pCtg->cacheStat.cacheHit[item], n))
|
||||
#define CTG_CACHE_NHIT_INC(item, n) (CTG_STAT_INC(pCtg->cacheStat.cacheNHit[item], n))
|
||||
|
||||
#define CTG_META_NUM_INC(type) do { \
|
||||
switch (type) { \
|
||||
case TSDB_SUPER_TABLE: \
|
||||
CTG_DB_NUM_INC(CTG_CI_STABLE_META); \
|
||||
break; \
|
||||
case TSDB_CHILD_TABLE: \
|
||||
CTG_DB_NUM_INC(CTG_CI_CTABLE_META); \
|
||||
break; \
|
||||
case TSDB_NORMAL_TABLE: \
|
||||
CTG_DB_NUM_INC(CTG_CI_NTABLE_META); \
|
||||
break; \
|
||||
case TSDB_SYSTEM_TABLE: \
|
||||
CTG_DB_NUM_INC(CTG_CI_SYSTABLE_META); \
|
||||
break; \
|
||||
default: \
|
||||
CTG_DB_NUM_INC(CTG_CI_OTHERTABLE_META); \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
#define CTG_META_NUM_INC(type) \
|
||||
do { \
|
||||
switch (type) { \
|
||||
case TSDB_SUPER_TABLE: \
|
||||
CTG_DB_NUM_INC(CTG_CI_STABLE_META); \
|
||||
break; \
|
||||
case TSDB_CHILD_TABLE: \
|
||||
CTG_DB_NUM_INC(CTG_CI_CTABLE_META); \
|
||||
break; \
|
||||
case TSDB_NORMAL_TABLE: \
|
||||
CTG_DB_NUM_INC(CTG_CI_NTABLE_META); \
|
||||
break; \
|
||||
case TSDB_SYSTEM_TABLE: \
|
||||
CTG_DB_NUM_INC(CTG_CI_SYSTABLE_META); \
|
||||
break; \
|
||||
default: \
|
||||
CTG_DB_NUM_INC(CTG_CI_OTHERTABLE_META); \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CTG_META_NUM_DEC(type) do { \
|
||||
switch (type) { \
|
||||
case TSDB_SUPER_TABLE: \
|
||||
CTG_DB_NUM_DEC(CTG_CI_STABLE_META); \
|
||||
break; \
|
||||
case TSDB_CHILD_TABLE: \
|
||||
CTG_DB_NUM_DEC(CTG_CI_CTABLE_META); \
|
||||
break; \
|
||||
case TSDB_NORMAL_TABLE: \
|
||||
CTG_DB_NUM_DEC(CTG_CI_NTABLE_META); \
|
||||
break; \
|
||||
case TSDB_SYSTEM_TABLE: \
|
||||
CTG_DB_NUM_DEC(CTG_CI_SYSTABLE_META); \
|
||||
break; \
|
||||
default: \
|
||||
CTG_DB_NUM_DEC(CTG_CI_OTHERTABLE_META); \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
#define CTG_META_NUM_DEC(type) \
|
||||
do { \
|
||||
switch (type) { \
|
||||
case TSDB_SUPER_TABLE: \
|
||||
CTG_DB_NUM_DEC(CTG_CI_STABLE_META); \
|
||||
break; \
|
||||
case TSDB_CHILD_TABLE: \
|
||||
CTG_DB_NUM_DEC(CTG_CI_CTABLE_META); \
|
||||
break; \
|
||||
case TSDB_NORMAL_TABLE: \
|
||||
CTG_DB_NUM_DEC(CTG_CI_NTABLE_META); \
|
||||
break; \
|
||||
case TSDB_SYSTEM_TABLE: \
|
||||
CTG_DB_NUM_DEC(CTG_CI_SYSTABLE_META); \
|
||||
break; \
|
||||
default: \
|
||||
CTG_DB_NUM_DEC(CTG_CI_OTHERTABLE_META); \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CTG_META_HIT_INC(type) do { \
|
||||
switch (type) { \
|
||||
case TSDB_SUPER_TABLE: \
|
||||
CTG_CACHE_HIT_INC(CTG_CI_STABLE_META, 1); \
|
||||
break; \
|
||||
case TSDB_CHILD_TABLE: \
|
||||
CTG_CACHE_HIT_INC(CTG_CI_CTABLE_META, 1); \
|
||||
break; \
|
||||
case TSDB_NORMAL_TABLE: \
|
||||
CTG_CACHE_HIT_INC(CTG_CI_NTABLE_META, 1); \
|
||||
break; \
|
||||
case TSDB_SYSTEM_TABLE: \
|
||||
CTG_CACHE_HIT_INC(CTG_CI_SYSTABLE_META, 1); \
|
||||
break; \
|
||||
default: \
|
||||
CTG_CACHE_HIT_INC(CTG_CI_OTHERTABLE_META, 1); \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
#define CTG_META_HIT_INC(type) \
|
||||
do { \
|
||||
switch (type) { \
|
||||
case TSDB_SUPER_TABLE: \
|
||||
CTG_CACHE_HIT_INC(CTG_CI_STABLE_META, 1); \
|
||||
break; \
|
||||
case TSDB_CHILD_TABLE: \
|
||||
CTG_CACHE_HIT_INC(CTG_CI_CTABLE_META, 1); \
|
||||
break; \
|
||||
case TSDB_NORMAL_TABLE: \
|
||||
CTG_CACHE_HIT_INC(CTG_CI_NTABLE_META, 1); \
|
||||
break; \
|
||||
case TSDB_SYSTEM_TABLE: \
|
||||
CTG_CACHE_HIT_INC(CTG_CI_SYSTABLE_META, 1); \
|
||||
break; \
|
||||
default: \
|
||||
CTG_CACHE_HIT_INC(CTG_CI_OTHERTABLE_META, 1); \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CTG_META_NHIT_INC() CTG_CACHE_NHIT_INC(CTG_CI_OTHERTABLE_META, 1)
|
||||
|
||||
|
||||
#define CTG_IS_META_NULL(type) ((type) == META_TYPE_NULL_TABLE)
|
||||
#define CTG_IS_META_CTABLE(type) ((type) == META_TYPE_CTABLE)
|
||||
#define CTG_IS_META_TABLE(type) ((type) == META_TYPE_TABLE)
|
||||
|
@ -659,7 +670,6 @@ typedef struct SCtgCacheItemInfo {
|
|||
#define ctgTaskDebug(param, ...) qDebug("QID:%" PRIx64 " CTG:%p " param, pTask->pJob->queryId, pCtg, __VA_ARGS__)
|
||||
#define ctgTaskTrace(param, ...) qTrace("QID:%" PRIx64 " CTG:%p " param, pTask->pJob->queryId, pCtg, __VA_ARGS__)
|
||||
|
||||
|
||||
#define CTG_LOCK_DEBUG(...) \
|
||||
do { \
|
||||
if (gCTGDebug.lockEnable) { \
|
||||
|
@ -681,38 +691,38 @@ typedef struct SCtgCacheItemInfo {
|
|||
|
||||
#define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000
|
||||
|
||||
#define CTG_LOCK(type, _lock) \
|
||||
do { \
|
||||
if (CTG_READ == (type)) { \
|
||||
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value before read lock"); \
|
||||
CTG_LOCK_DEBUG("CTG RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
taosRLockLatch(_lock); \
|
||||
CTG_LOCK_DEBUG("CTG RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
ASSERTS(atomic_load_32((_lock)) > 0, "invalid lock value after read lock"); \
|
||||
} else { \
|
||||
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value before write lock"); \
|
||||
CTG_LOCK_DEBUG("CTG WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
taosWLockLatch(_lock); \
|
||||
CTG_LOCK_DEBUG("CTG WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
ASSERTS(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY, "invalid lock value after write lock"); \
|
||||
} \
|
||||
#define CTG_LOCK(type, _lock) \
|
||||
do { \
|
||||
if (CTG_READ == (type)) { \
|
||||
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value before read lock"); \
|
||||
CTG_LOCK_DEBUG("CTG RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
taosRLockLatch(_lock); \
|
||||
CTG_LOCK_DEBUG("CTG RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
ASSERTS(atomic_load_32((_lock)) > 0, "invalid lock value after read lock"); \
|
||||
} else { \
|
||||
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value before write lock"); \
|
||||
CTG_LOCK_DEBUG("CTG WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
taosWLockLatch(_lock); \
|
||||
CTG_LOCK_DEBUG("CTG WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
ASSERTS(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY, "invalid lock value after write lock"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CTG_UNLOCK(type, _lock) \
|
||||
do { \
|
||||
if (CTG_READ == (type)) { \
|
||||
ASSERTS(atomic_load_32((_lock)) > 0, "invalid lock value before read unlock"); \
|
||||
CTG_LOCK_DEBUG("CTG RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
taosRUnLockLatch(_lock); \
|
||||
CTG_LOCK_DEBUG("CTG RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value after read unlock"); \
|
||||
} else { \
|
||||
ASSERTS(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY, "invalid lock value before write unlock"); \
|
||||
CTG_LOCK_DEBUG("CTG WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
taosWUnLockLatch(_lock); \
|
||||
CTG_LOCK_DEBUG("CTG WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value after write unlock"); \
|
||||
} \
|
||||
#define CTG_UNLOCK(type, _lock) \
|
||||
do { \
|
||||
if (CTG_READ == (type)) { \
|
||||
ASSERTS(atomic_load_32((_lock)) > 0, "invalid lock value before read unlock"); \
|
||||
CTG_LOCK_DEBUG("CTG RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
taosRUnLockLatch(_lock); \
|
||||
CTG_LOCK_DEBUG("CTG RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value after read unlock"); \
|
||||
} else { \
|
||||
ASSERTS(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY, "invalid lock value before write unlock"); \
|
||||
CTG_LOCK_DEBUG("CTG WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
taosWUnLockLatch(_lock); \
|
||||
CTG_LOCK_DEBUG("CTG WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value after write unlock"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CTG_ERR_RET(c) \
|
||||
|
@ -806,7 +816,7 @@ int32_t ctgTbMetaExistInCache(SCatalog* pCtg, char* dbFName, char* tbName, int32
|
|||
int32_t ctgReadTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta);
|
||||
int32_t ctgReadTbVerFromCache(SCatalog* pCtg, SName* pTableName, int32_t* sver, int32_t* tver, int32_t* tbType,
|
||||
uint64_t* suid, char* stbName);
|
||||
int32_t ctgChkAuthFromCache(SCatalog* pCtg, char* user, char* dbFName, AUTH_TYPE type, bool* inCache, bool* pass);
|
||||
int32_t ctgChkAuthFromCache(SCatalog* pCtg, SUserAuthInfo* pReq, bool* inCache, SCtgAuthRsp* pRes);
|
||||
int32_t ctgDropDbCacheEnqueue(SCatalog* pCtg, const char* dbFName, int64_t dbId);
|
||||
int32_t ctgDropDbVgroupEnqueue(SCatalog* pCtg, const char* dbFName, bool syncReq);
|
||||
int32_t ctgDropStbMetaEnqueue(SCatalog* pCtg, const char* dbFName, int64_t dbId, const char* stbName, uint64_t suid,
|
||||
|
@ -879,7 +889,8 @@ void ctgFreeHandleImpl(SCatalog* pCtg);
|
|||
int32_t ctgGetVgInfoFromHashValue(SCatalog* pCtg, SDBVgInfo* dbInfo, const SName* pTableName, SVgroupInfo* pVgroup);
|
||||
int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SCtgTaskReq* tReq, SDBVgInfo* dbInfo, SCtgTbHashsCtx* pCtx,
|
||||
char* dbFName, SArray* pNames, bool update);
|
||||
int32_t ctgGetVgIdsFromHashValue(SCatalog* pCtg, SDBVgInfo* dbInfo, char* dbFName, const char* pTbs[], int32_t tbNum, int32_t* vgId);
|
||||
int32_t ctgGetVgIdsFromHashValue(SCatalog* pCtg, SDBVgInfo* dbInfo, char* dbFName, const char* pTbs[], int32_t tbNum,
|
||||
int32_t* vgId);
|
||||
void ctgResetTbMetaTask(SCtgTask* pTask);
|
||||
void ctgFreeDbCache(SCtgDBCache* dbCache);
|
||||
int32_t ctgStbVersionSortCompare(const void* key1, const void* key2);
|
||||
|
@ -900,20 +911,24 @@ void ctgFreeQNode(SCtgQNode* node);
|
|||
void ctgClearHandle(SCatalog* pCtg);
|
||||
void ctgFreeTbCacheImpl(SCtgTbCache* pCache);
|
||||
int32_t ctgRemoveTbMeta(SCatalog* pCtg, SName* pTableName);
|
||||
int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup, bool* exists);
|
||||
int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup,
|
||||
bool* exists);
|
||||
SName* ctgGetFetchName(SArray* pNames, SCtgFetch* pFetch);
|
||||
int32_t ctgdGetOneHandle(SCatalog **pHandle);
|
||||
int32_t ctgdGetOneHandle(SCatalog** pHandle);
|
||||
int ctgVgInfoComp(const void* lp, const void* rp);
|
||||
int32_t ctgMakeVgArray(SDBVgInfo* dbInfo);
|
||||
int32_t ctgAcquireVgMetaFromCache(SCatalog *pCtg, const char *dbFName, const char *tbName, SCtgDBCache **pDb, SCtgTbCache **pTb);
|
||||
int32_t ctgCopyTbMeta(SCatalog *pCtg, SCtgTbMetaCtx *ctx, SCtgDBCache **pDb, SCtgTbCache **pTb, STableMeta **pTableMeta, char* dbFName);
|
||||
void ctgReleaseVgMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, SCtgTbCache *pCache);
|
||||
void ctgReleaseTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, SCtgTbCache *pCache);
|
||||
void ctgGetGlobalCacheStat(SCtgCacheStat *pStat);
|
||||
int32_t ctgAcquireVgMetaFromCache(SCatalog* pCtg, const char* dbFName, const char* tbName, SCtgDBCache** pDb,
|
||||
SCtgTbCache** pTb);
|
||||
int32_t ctgCopyTbMeta(SCatalog* pCtg, SCtgTbMetaCtx* ctx, SCtgDBCache** pDb, SCtgTbCache** pTb, STableMeta** pTableMeta,
|
||||
char* dbFName);
|
||||
void ctgReleaseVgMetaToCache(SCatalog* pCtg, SCtgDBCache* dbCache, SCtgTbCache* pCache);
|
||||
void ctgReleaseTbMetaToCache(SCatalog* pCtg, SCtgDBCache* dbCache, SCtgTbCache* pCache);
|
||||
void ctgGetGlobalCacheStat(SCtgCacheStat* pStat);
|
||||
int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res);
|
||||
|
||||
extern SCatalogMgmt gCtgMgmt;
|
||||
extern SCtgDebug gCTGDebug;
|
||||
extern SCtgAsyncFps gCtgAsyncFps[];
|
||||
extern SCatalogMgmt gCtgMgmt;
|
||||
extern SCtgDebug gCTGDebug;
|
||||
extern SCtgAsyncFps gCtgAsyncFps[];
|
||||
extern SCtgCacheItemInfo gCtgStatItem[CTG_CI_MAX_VALUE];
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -319,14 +319,13 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type,
|
||||
bool* pass, bool* exists) {
|
||||
int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, SUserAuthInfo *pReq, SUserAuthRes* pRes, bool* exists) {
|
||||
bool inCache = false;
|
||||
int32_t code = 0;
|
||||
SCtgAuthRsp rsp = {0};
|
||||
rsp.pRawRes = pRes;
|
||||
|
||||
*pass = false;
|
||||
|
||||
CTG_ERR_RET(ctgChkAuthFromCache(pCtg, (char*)user, (char*)dbFName, type, &inCache, pass));
|
||||
CTG_ERR_RET(ctgChkAuthFromCache(pCtg, pReq, &inCache, &rsp));
|
||||
|
||||
if (inCache) {
|
||||
if (exists) {
|
||||
|
@ -339,30 +338,22 @@ int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, co
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SGetUserAuthRsp authRsp = {0};
|
||||
CTG_ERR_RET(ctgGetUserDbAuthFromMnode(pCtg, pConn, user, &authRsp, NULL));
|
||||
SCtgAuthReq req = {0};
|
||||
req.pRawReq = pReq;
|
||||
req.pConn = pConn;
|
||||
req.onlyCache = exists ? true : false;
|
||||
CTG_ERR_RET(ctgGetUserDbAuthFromMnode(pCtg, pConn, pReq->user, &req.authInfo, NULL));
|
||||
|
||||
if (authRsp.superAuth) {
|
||||
*pass = true;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (authRsp.createdDbs && taosHashGet(authRsp.createdDbs, dbFName, strlen(dbFName))) {
|
||||
*pass = true;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (CTG_AUTH_READ(type) && authRsp.readDbs && taosHashGet(authRsp.readDbs, dbFName, strlen(dbFName))) {
|
||||
*pass = true;
|
||||
} else if (CTG_AUTH_WRITE(type) && authRsp.writeDbs && taosHashGet(authRsp.writeDbs, dbFName, strlen(dbFName))) {
|
||||
*pass = true;
|
||||
CTG_ERR_JRET(ctgChkSetAuthRes(pCtg, &req, &rsp));
|
||||
if (rsp.metaNotExists && exists) {
|
||||
*exists = false;
|
||||
}
|
||||
|
||||
_return:
|
||||
|
||||
ctgUpdateUserEnqueue(pCtg, &authRsp, false);
|
||||
ctgUpdateUserEnqueue(pCtg, &req.authInfo, false);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgGetTbType(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTableName, int32_t* tbType) {
|
||||
|
@ -1373,7 +1364,7 @@ int32_t catalogGetExpiredUsers(SCatalog* pCtg, SUserAuthVersion** users, uint32_
|
|||
void* key = taosHashGetKey(pAuth, &len);
|
||||
strncpy((*users)[i].user, key, len);
|
||||
(*users)[i].user[len] = 0;
|
||||
(*users)[i].version = pAuth->version;
|
||||
(*users)[i].version = pAuth->userAuth.version;
|
||||
++i;
|
||||
if (i >= *num) {
|
||||
taosHashCancelIterate(pCtg->userCache, pAuth);
|
||||
|
@ -1457,32 +1448,30 @@ _return:
|
|||
CTG_API_LEAVE(code);
|
||||
}
|
||||
|
||||
int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type,
|
||||
bool* pass) {
|
||||
int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, SUserAuthInfo *pAuth, SUserAuthRes* pRes) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
if (NULL == pCtg || NULL == pConn || NULL == user || NULL == dbFName || NULL == pass) {
|
||||
if (NULL == pCtg || NULL == pConn || NULL == pAuth || NULL == pRes) {
|
||||
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
CTG_ERR_JRET(ctgChkAuth(pCtg, pConn, user, dbFName, type, pass, NULL));
|
||||
CTG_ERR_JRET(ctgChkAuth(pCtg, pConn, pAuth, pRes, NULL));
|
||||
|
||||
_return:
|
||||
|
||||
CTG_API_LEAVE(code);
|
||||
}
|
||||
|
||||
int32_t catalogChkAuthFromCache(SCatalog* pCtg, const char* user, const char* dbFName, AUTH_TYPE type,
|
||||
bool* pass, bool* exists) {
|
||||
int32_t catalogChkAuthFromCache(SCatalog* pCtg, SUserAuthInfo *pAuth, SUserAuthRes* pRes, bool* exists) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
if (NULL == pCtg || NULL == user || NULL == dbFName || NULL == pass || NULL == exists) {
|
||||
if (NULL == pCtg || NULL == pAuth || NULL == pRes || NULL == exists) {
|
||||
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
CTG_ERR_JRET(ctgChkAuth(pCtg, NULL, user, dbFName, type, pass, exists));
|
||||
CTG_ERR_JRET(ctgChkAuth(pCtg, NULL, pAuth, pRes, exists));
|
||||
|
||||
_return:
|
||||
|
||||
|
|
|
@ -1550,45 +1550,20 @@ _return:
|
|||
int32_t ctgHandleGetUserRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf* pMsg, int32_t rspCode) {
|
||||
int32_t code = 0;
|
||||
SCtgTask* pTask = tReq->pTask;
|
||||
SCtgUserCtx* ctx = (SCtgUserCtx*)pTask->taskCtx;
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
bool pass = false;
|
||||
SGetUserAuthRsp* pOut = (SGetUserAuthRsp*)pTask->msgCtx.out;
|
||||
|
||||
CTG_ERR_JRET(ctgProcessRspMsg(pTask->msgCtx.out, reqType, pMsg->pData, pMsg->len, rspCode, pTask->msgCtx.target));
|
||||
|
||||
if (pOut->superAuth) {
|
||||
pass = true;
|
||||
goto _return;
|
||||
}
|
||||
ctgUpdateUserEnqueue(pCtg, pOut, true);
|
||||
taosMemoryFreeClear(pTask->msgCtx.out);
|
||||
|
||||
if (pOut->createdDbs && taosHashGet(pOut->createdDbs, ctx->user.dbFName, strlen(ctx->user.dbFName))) {
|
||||
pass = true;
|
||||
goto _return;
|
||||
}
|
||||
CTG_ERR_JRET((*gCtgAsyncFps[pTask->type].launchFp)(pTask));
|
||||
|
||||
if (CTG_AUTH_READ(ctx->user.type) && pOut->readDbs &&
|
||||
taosHashGet(pOut->readDbs, ctx->user.dbFName, strlen(ctx->user.dbFName))) {
|
||||
pass = true;
|
||||
} else if (CTG_AUTH_WRITE(ctx->user.type) && pOut->writeDbs &&
|
||||
taosHashGet(pOut->writeDbs, ctx->user.dbFName, strlen(ctx->user.dbFName))) {
|
||||
pass = true;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pTask->res = taosMemoryCalloc(1, sizeof(bool));
|
||||
if (NULL == pTask->res) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
*(bool*)pTask->res = pass;
|
||||
}
|
||||
}
|
||||
|
||||
ctgUpdateUserEnqueue(pCtg, pOut, false);
|
||||
taosMemoryFreeClear(pTask->msgCtx.out);
|
||||
|
||||
ctgHandleTaskEnd(pTask, code);
|
||||
|
||||
CTG_RET(code);
|
||||
|
@ -2081,31 +2056,39 @@ int32_t ctgLaunchGetUdfTask(SCtgTask* pTask) {
|
|||
}
|
||||
|
||||
int32_t ctgLaunchGetUserTask(SCtgTask* pTask) {
|
||||
int32_t code = 0;
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
SRequestConnInfo* pConn = &pTask->pJob->conn;
|
||||
SCtgUserCtx* pCtx = (SCtgUserCtx*)pTask->taskCtx;
|
||||
bool inCache = false;
|
||||
bool pass = false;
|
||||
SCtgAuthRsp rsp = {0};
|
||||
SCtgJob* pJob = pTask->pJob;
|
||||
SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, -1);
|
||||
if (NULL == pMsgCtx->pBatchs) {
|
||||
pMsgCtx->pBatchs = pJob->pBatchs;
|
||||
}
|
||||
|
||||
CTG_ERR_RET(ctgChkAuthFromCache(pCtg, pCtx->user.user, pCtx->user.dbFName, pCtx->user.type, &inCache, &pass));
|
||||
rsp.pRawRes = taosMemoryCalloc(1, sizeof(SUserAuthRes));
|
||||
if (NULL == rsp.pRawRes) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
CTG_ERR_RET(ctgChkAuthFromCache(pCtg, &pCtx->user, &inCache, &rsp));
|
||||
if (inCache) {
|
||||
pTask->res = taosMemoryCalloc(1, sizeof(bool));
|
||||
if (NULL == pTask->res) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
*(bool*)pTask->res = pass;
|
||||
pTask->res = rsp.pRawRes;
|
||||
|
||||
CTG_ERR_RET(ctgHandleTaskEnd(pTask, 0));
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
CTG_ERR_RET(ctgGetUserDbAuthFromMnode(pCtg, pConn, pCtx->user.user, NULL, pTask));
|
||||
taosMemoryFreeClear(rsp.pRawRes);
|
||||
|
||||
if (rsp.metaNotExists) {
|
||||
CTG_ERR_RET(ctgLaunchSubTask(pTask, CTG_TASK_GET_TB_META, ctgGetTbCfgCb, &pCtx->user.tbName));
|
||||
} else {
|
||||
CTG_ERR_RET(ctgGetUserDbAuthFromMnode(pCtg, pConn, pCtx->user.user, NULL, pTask));
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -2155,6 +2138,20 @@ _return:
|
|||
CTG_RET(ctgHandleTaskEnd(pTask, pTask->subRes.code));
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgGetUserCb(SCtgTask* pTask) {
|
||||
int32_t code = 0;
|
||||
|
||||
CTG_ERR_JRET(pTask->subRes.code);
|
||||
|
||||
CTG_RET(ctgLaunchGetUserTask(pTask));
|
||||
|
||||
_return:
|
||||
|
||||
CTG_RET(ctgHandleTaskEnd(pTask, pTask->subRes.code));
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgCompDbVgTasks(SCtgTask* pTask, void* param, bool* equal) {
|
||||
SCtgDbVgCtx* ctx = pTask->taskCtx;
|
||||
|
||||
|
|
|
@ -32,27 +32,26 @@ SCtgOperation gCtgCacheOperation[CTG_OP_MAX] = {{CTG_OP_UPDATE_VGROUP, "update v
|
|||
{CTG_OP_CLEAR_CACHE, "clear cache", ctgOpClearCache}};
|
||||
|
||||
SCtgCacheItemInfo gCtgStatItem[CTG_CI_MAX_VALUE] = {
|
||||
{"Cluster ", CTG_CI_FLAG_LEVEL_GLOBAL}, //CTG_CI_CLUSTER
|
||||
{"Dnode ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_DNODE,
|
||||
{"Qnode ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_QNODE,
|
||||
{"DB ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_DB,
|
||||
{"DbVgroup ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_DB_VGROUP,
|
||||
{"DbCfg ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_DB_CFG,
|
||||
{"DbInfo ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_DB_INFO,
|
||||
{"StbMeta ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_STABLE_META,
|
||||
{"NtbMeta ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_NTABLE_META,
|
||||
{"CtbMeta ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_CTABLE_META,
|
||||
{"SysTblMeta", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_SYSTABLE_META,
|
||||
{"OthTblMeta", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_OTHERTABLE_META,
|
||||
{"TblSMA ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_TBL_SMA,
|
||||
{"TblCfg ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_TBL_CFG,
|
||||
{"IndexInfo ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_INDEX_INFO,
|
||||
{"User ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_USER,
|
||||
{"UDF ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_UDF,
|
||||
{"SvrVer ", CTG_CI_FLAG_LEVEL_CLUSTER} //CTG_CI_SVR_VER,
|
||||
{"Cluster ", CTG_CI_FLAG_LEVEL_GLOBAL}, // CTG_CI_CLUSTER
|
||||
{"Dnode ", CTG_CI_FLAG_LEVEL_CLUSTER}, // CTG_CI_DNODE,
|
||||
{"Qnode ", CTG_CI_FLAG_LEVEL_CLUSTER}, // CTG_CI_QNODE,
|
||||
{"DB ", CTG_CI_FLAG_LEVEL_CLUSTER}, // CTG_CI_DB,
|
||||
{"DbVgroup ", CTG_CI_FLAG_LEVEL_DB}, // CTG_CI_DB_VGROUP,
|
||||
{"DbCfg ", CTG_CI_FLAG_LEVEL_DB}, // CTG_CI_DB_CFG,
|
||||
{"DbInfo ", CTG_CI_FLAG_LEVEL_DB}, // CTG_CI_DB_INFO,
|
||||
{"StbMeta ", CTG_CI_FLAG_LEVEL_DB}, // CTG_CI_STABLE_META,
|
||||
{"NtbMeta ", CTG_CI_FLAG_LEVEL_DB}, // CTG_CI_NTABLE_META,
|
||||
{"CtbMeta ", CTG_CI_FLAG_LEVEL_DB}, // CTG_CI_CTABLE_META,
|
||||
{"SysTblMeta", CTG_CI_FLAG_LEVEL_DB}, // CTG_CI_SYSTABLE_META,
|
||||
{"OthTblMeta", CTG_CI_FLAG_LEVEL_DB}, // CTG_CI_OTHERTABLE_META,
|
||||
{"TblSMA ", CTG_CI_FLAG_LEVEL_DB}, // CTG_CI_TBL_SMA,
|
||||
{"TblCfg ", CTG_CI_FLAG_LEVEL_DB}, // CTG_CI_TBL_CFG,
|
||||
{"IndexInfo ", CTG_CI_FLAG_LEVEL_DB}, // CTG_CI_INDEX_INFO,
|
||||
{"User ", CTG_CI_FLAG_LEVEL_CLUSTER}, // CTG_CI_USER,
|
||||
{"UDF ", CTG_CI_FLAG_LEVEL_CLUSTER}, // CTG_CI_UDF,
|
||||
{"SvrVer ", CTG_CI_FLAG_LEVEL_CLUSTER} // CTG_CI_SVR_VER,
|
||||
};
|
||||
|
||||
|
||||
int32_t ctgRLockVgInfo(SCatalog *pCtg, SCtgDBCache *dbCache, bool *inCache) {
|
||||
CTG_LOCK(CTG_READ, &dbCache->vgCache.vgLock);
|
||||
|
||||
|
@ -263,10 +262,11 @@ _return:
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgAcquireVgMetaFromCache(SCatalog *pCtg, const char *dbFName, const char *tbName, SCtgDBCache **pDb, SCtgTbCache **pTb) {
|
||||
int32_t ctgAcquireVgMetaFromCache(SCatalog *pCtg, const char *dbFName, const char *tbName, SCtgDBCache **pDb,
|
||||
SCtgTbCache **pTb) {
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
SCtgTbCache *tbCache = NULL;
|
||||
bool vgInCache = false;
|
||||
bool vgInCache = false;
|
||||
|
||||
ctgAcquireDBCache(pCtg, dbFName, &dbCache);
|
||||
if (NULL == dbCache) {
|
||||
|
@ -331,7 +331,6 @@ _return:
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
int32_t ctgAcquireStbMetaFromCache(SCatalog *pCtg, char *dbFName, uint64_t suid, SCtgDBCache **pDb, SCtgTbCache **pTb) {
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
|
@ -385,9 +384,10 @@ _return:
|
|||
}
|
||||
*/
|
||||
|
||||
int32_t ctgAcquireStbMetaFromCache(SCtgDBCache *dbCache, SCatalog *pCtg, char *dbFName, uint64_t suid, SCtgTbCache **pTb) {
|
||||
int32_t ctgAcquireStbMetaFromCache(SCtgDBCache *dbCache, SCatalog *pCtg, char *dbFName, uint64_t suid,
|
||||
SCtgTbCache **pTb) {
|
||||
SCtgTbCache *pCache = NULL;
|
||||
char *stName = taosHashAcquire(dbCache->stbCache, &suid, sizeof(suid));
|
||||
char *stName = taosHashAcquire(dbCache->stbCache, &suid, sizeof(suid));
|
||||
if (NULL == stName) {
|
||||
ctgDebug("stb 0x%" PRIx64 " not in cache, dbFName:%s", suid, dbFName);
|
||||
goto _return;
|
||||
|
@ -484,10 +484,11 @@ int32_t ctgTbMetaExistInCache(SCatalog *pCtg, char *dbFName, char *tbName, int32
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgCopyTbMeta(SCatalog *pCtg, SCtgTbMetaCtx *ctx, SCtgDBCache **pDb, SCtgTbCache **pTb, STableMeta **pTableMeta, char* dbFName) {
|
||||
int32_t ctgCopyTbMeta(SCatalog *pCtg, SCtgTbMetaCtx *ctx, SCtgDBCache **pDb, SCtgTbCache **pTb, STableMeta **pTableMeta,
|
||||
char *dbFName) {
|
||||
SCtgDBCache *dbCache = *pDb;
|
||||
SCtgTbCache *tbCache = *pTb;
|
||||
STableMeta *tbMeta = tbCache->pMeta;
|
||||
STableMeta *tbMeta = tbCache->pMeta;
|
||||
ctx->tbInfo.inCache = true;
|
||||
ctx->tbInfo.dbId = dbCache->dbId;
|
||||
ctx->tbInfo.suid = tbMeta->suid;
|
||||
|
@ -516,12 +517,12 @@ int32_t ctgCopyTbMeta(SCatalog *pCtg, SCtgTbMetaCtx *ctx, SCtgDBCache **pDb, SCt
|
|||
|
||||
memcpy(*pTableMeta, tbMeta, metaSize);
|
||||
|
||||
//ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||
// ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||
|
||||
CTG_UNLOCK(CTG_READ, &tbCache->metaLock);
|
||||
taosHashRelease(dbCache->tbCache, tbCache);
|
||||
*pTb = NULL;
|
||||
|
||||
|
||||
ctgDebug("Got ctb %s meta from cache, will continue to get its stb meta, type:%d, dbFName:%s", ctx->pName->tname,
|
||||
ctx->tbInfo.tbType, dbFName);
|
||||
|
||||
|
@ -553,7 +554,6 @@ int32_t ctgCopyTbMeta(SCatalog *pCtg, SCtgTbMetaCtx *ctx, SCtgDBCache **pDb, SCt
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgReadTbMetaFromCache(SCatalog *pCtg, SCtgTbMetaCtx *ctx, STableMeta **pTableMeta) {
|
||||
int32_t code = 0;
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
|
@ -623,17 +623,17 @@ int32_t ctgReadTbVerFromCache(SCatalog *pCtg, SName *pTableName, int32_t *sver,
|
|||
|
||||
// PROCESS FOR CHILD TABLE
|
||||
|
||||
//ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||
// ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||
if (tbCache) {
|
||||
CTG_UNLOCK(CTG_READ, &tbCache->metaLock);
|
||||
taosHashRelease(dbCache->tbCache, tbCache);
|
||||
}
|
||||
|
||||
|
||||
ctgDebug("Got ctb %s ver from cache, will continue to get its stb ver, dbFName:%s", pTableName->tname, dbFName);
|
||||
|
||||
ctgAcquireStbMetaFromCache(dbCache, pCtg, dbFName, *suid, &tbCache);
|
||||
if (NULL == tbCache) {
|
||||
//ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||
// ctgReleaseTbMetaToCache(pCtg, dbCache, tbCache);
|
||||
ctgDebug("stb 0x%" PRIx64 " meta not in cache", *suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -703,55 +703,40 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgChkAuthFromCache(SCatalog *pCtg, char *user, char *dbFName, AUTH_TYPE type, bool *inCache, bool *pass) {
|
||||
char *p = strchr(dbFName, '.');
|
||||
if (p) {
|
||||
++p;
|
||||
} else {
|
||||
p = dbFName;
|
||||
}
|
||||
|
||||
if (IS_SYS_DBNAME(p)) {
|
||||
int32_t ctgChkAuthFromCache(SCatalog *pCtg, SUserAuthInfo *pReq, bool *inCache, SCtgAuthRsp *pRes) {
|
||||
if (IS_SYS_DBNAME(pReq->tbName.dbname)) {
|
||||
*inCache = true;
|
||||
*pass = true;
|
||||
ctgDebug("sysdb %s, pass", dbFName);
|
||||
pRes->pRawRes->pass = true;
|
||||
ctgDebug("sysdb %s, pass", pReq->tbName.dbname);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SCtgUserAuth *pUser = (SCtgUserAuth *)taosHashGet(pCtg->userCache, user, strlen(user));
|
||||
SCtgUserAuth *pUser = (SCtgUserAuth *)taosHashGet(pCtg->userCache, pReq->user, strlen(pReq->user));
|
||||
if (NULL == pUser) {
|
||||
ctgDebug("user not in cache, user:%s", user);
|
||||
ctgDebug("user not in cache, user:%s", pReq->user);
|
||||
goto _return;
|
||||
}
|
||||
|
||||
*inCache = true;
|
||||
|
||||
ctgDebug("Got user from cache, user:%s", user);
|
||||
ctgDebug("Got user from cache, user:%s", pReq->user);
|
||||
CTG_CACHE_HIT_INC(CTG_CI_USER, 1);
|
||||
|
||||
if (pUser->superUser) {
|
||||
*pass = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SCtgAuthReq req = {0};
|
||||
req.pRawReq = pReq;
|
||||
req.onlyCache = true;
|
||||
|
||||
CTG_LOCK(CTG_READ, &pUser->lock);
|
||||
if (pUser->createdDbs && taosHashGet(pUser->createdDbs, dbFName, strlen(dbFName))) {
|
||||
*pass = true;
|
||||
CTG_UNLOCK(CTG_READ, &pUser->lock);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (pUser->readDbs && taosHashGet(pUser->readDbs, dbFName, strlen(dbFName)) && CTG_AUTH_READ(type)) {
|
||||
*pass = true;
|
||||
}
|
||||
|
||||
if (pUser->writeDbs && taosHashGet(pUser->writeDbs, dbFName, strlen(dbFName)) && CTG_AUTH_WRITE(type)) {
|
||||
*pass = true;
|
||||
}
|
||||
|
||||
memcpy(&req.authInfo, &pUser->userAuth, sizeof(pUser->userAuth));
|
||||
int32_t code = ctgChkSetAuthRes(pCtg, &req, pRes);
|
||||
CTG_UNLOCK(CTG_READ, &pUser->lock);
|
||||
CTG_ERR_JRET(code);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
if (pRes->metaNotExists) {
|
||||
goto _return;
|
||||
}
|
||||
|
||||
CTG_RET(code);
|
||||
|
||||
_return:
|
||||
|
||||
|
@ -1639,7 +1624,7 @@ int32_t ctgWriteTbIndexToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNa
|
|||
}
|
||||
|
||||
CTG_DB_NUM_INC(CTG_CI_TBL_SMA);
|
||||
|
||||
|
||||
*index = NULL;
|
||||
ctgDebug("table %s index updated to cache, ver:%d, num:%d", tbName, pIndex->version,
|
||||
(int32_t)taosArrayGetSize(pIndex->pIndex));
|
||||
|
@ -1725,9 +1710,9 @@ void ctgFreeAllInstance(void) {
|
|||
taosHashClear(gCtgMgmt.pCluster);
|
||||
}
|
||||
|
||||
int32_t ctgVgInfoIdComp(void const* lp, void const* rp) {
|
||||
int32_t* key = (int32_t*)lp;
|
||||
SVgroupInfo* pVg = (SVgroupInfo*)rp;
|
||||
int32_t ctgVgInfoIdComp(void const *lp, void const *rp) {
|
||||
int32_t *key = (int32_t *)lp;
|
||||
SVgroupInfo *pVg = (SVgroupInfo *)rp;
|
||||
|
||||
if (*key < pVg->vgId) {
|
||||
return -1;
|
||||
|
@ -1738,7 +1723,6 @@ int32_t ctgVgInfoIdComp(void const* lp, void const* rp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgOpUpdateVgroup(SCtgCacheOperation *operation) {
|
||||
int32_t code = 0;
|
||||
SCtgUpdateVgMsg *msg = operation->data;
|
||||
|
@ -1805,10 +1789,10 @@ int32_t ctgOpUpdateVgroup(SCtgCacheOperation *operation) {
|
|||
|
||||
dbCache = NULL;
|
||||
|
||||
//if (!IS_SYS_DBNAME(dbFName)) {
|
||||
tstrncpy(vgVersion.dbFName, dbFName, sizeof(vgVersion.dbFName));
|
||||
CTG_ERR_JRET(ctgMetaRentUpdate(&msg->pCtg->dbRent, &vgVersion, vgVersion.dbId, sizeof(SDbVgVersion),
|
||||
ctgDbVgVersionSortCompare, ctgDbVgVersionSearchCompare));
|
||||
// if (!IS_SYS_DBNAME(dbFName)) {
|
||||
tstrncpy(vgVersion.dbFName, dbFName, sizeof(vgVersion.dbFName));
|
||||
CTG_ERR_JRET(ctgMetaRentUpdate(&msg->pCtg->dbRent, &vgVersion, vgVersion.dbId, sizeof(SDbVgVersion),
|
||||
ctgDbVgVersionSortCompare, ctgDbVgVersionSearchCompare));
|
||||
//}
|
||||
|
||||
_return:
|
||||
|
@ -2054,11 +2038,7 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
|
|||
if (NULL == pUser) {
|
||||
SCtgUserAuth userAuth = {0};
|
||||
|
||||
userAuth.version = msg->userAuth.version;
|
||||
userAuth.superUser = msg->userAuth.superAuth;
|
||||
userAuth.createdDbs = msg->userAuth.createdDbs;
|
||||
userAuth.readDbs = msg->userAuth.readDbs;
|
||||
userAuth.writeDbs = msg->userAuth.writeDbs;
|
||||
memcpy(&userAuth.userAuth, &msg->userAuth, sizeof(msg->userAuth));
|
||||
|
||||
if (taosHashPut(pCtg->userCache, msg->userAuth.user, strlen(msg->userAuth.user), &userAuth, sizeof(userAuth))) {
|
||||
ctgError("taosHashPut user %s to cache failed", msg->userAuth.user);
|
||||
|
@ -2072,22 +2052,32 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pUser->version = msg->userAuth.version;
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &pUser->lock);
|
||||
|
||||
taosHashCleanup(pUser->createdDbs);
|
||||
pUser->createdDbs = msg->userAuth.createdDbs;
|
||||
taosHashCleanup(pUser->userAuth.createdDbs);
|
||||
pUser->userAuth.createdDbs = msg->userAuth.createdDbs;
|
||||
msg->userAuth.createdDbs = NULL;
|
||||
|
||||
taosHashCleanup(pUser->readDbs);
|
||||
pUser->readDbs = msg->userAuth.readDbs;
|
||||
taosHashCleanup(pUser->userAuth.readDbs);
|
||||
pUser->userAuth.readDbs = msg->userAuth.readDbs;
|
||||
msg->userAuth.readDbs = NULL;
|
||||
|
||||
taosHashCleanup(pUser->writeDbs);
|
||||
pUser->writeDbs = msg->userAuth.writeDbs;
|
||||
taosHashCleanup(pUser->userAuth.writeDbs);
|
||||
pUser->userAuth.writeDbs = msg->userAuth.writeDbs;
|
||||
msg->userAuth.writeDbs = NULL;
|
||||
|
||||
taosHashCleanup(pUser->userAuth.readTbs);
|
||||
pUser->userAuth.readTbs = msg->userAuth.readTbs;
|
||||
msg->userAuth.readTbs = NULL;
|
||||
|
||||
taosHashCleanup(pUser->userAuth.writeTbs);
|
||||
pUser->userAuth.writeTbs = msg->userAuth.writeTbs;
|
||||
msg->userAuth.writeTbs = NULL;
|
||||
|
||||
taosHashCleanup(pUser->userAuth.useDbs);
|
||||
pUser->userAuth.useDbs = msg->userAuth.useDbs;
|
||||
msg->userAuth.useDbs = NULL;
|
||||
|
||||
CTG_UNLOCK(CTG_WRITE, &pUser->lock);
|
||||
|
||||
_return:
|
||||
|
@ -2095,6 +2085,9 @@ _return:
|
|||
taosHashCleanup(msg->userAuth.createdDbs);
|
||||
taosHashCleanup(msg->userAuth.readDbs);
|
||||
taosHashCleanup(msg->userAuth.writeDbs);
|
||||
taosHashCleanup(msg->userAuth.readTbs);
|
||||
taosHashCleanup(msg->userAuth.writeTbs);
|
||||
taosHashCleanup(msg->userAuth.useDbs);
|
||||
|
||||
taosMemoryFreeClear(msg);
|
||||
|
||||
|
@ -2287,6 +2280,9 @@ void ctgFreeCacheOperationData(SCtgCacheOperation *op) {
|
|||
taosHashCleanup(msg->userAuth.createdDbs);
|
||||
taosHashCleanup(msg->userAuth.readDbs);
|
||||
taosHashCleanup(msg->userAuth.writeDbs);
|
||||
taosHashCleanup(msg->userAuth.readTbs);
|
||||
taosHashCleanup(msg->userAuth.writeTbs);
|
||||
taosHashCleanup(msg->userAuth.useDbs);
|
||||
taosMemoryFreeClear(op->data);
|
||||
break;
|
||||
}
|
||||
|
@ -2526,7 +2522,7 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
|
|||
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
|
||||
taosArrayPush(ctx->pResList, &(SMetaRes){0});
|
||||
CTG_META_NHIT_INC();
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2544,7 +2540,7 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
|
|||
STableMeta *tbMeta = pCache->pMeta;
|
||||
|
||||
CTG_META_HIT_INC(tbMeta->tableType);
|
||||
|
||||
|
||||
SCtgTbMetaCtx nctx = {0};
|
||||
nctx.flag = flag;
|
||||
nctx.tbInfo.inCache = true;
|
||||
|
@ -2626,7 +2622,7 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
|
|||
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
|
||||
taosArrayPush(ctx->pResList, &(SMetaRes){0});
|
||||
taosMemoryFreeClear(pTableMeta);
|
||||
|
||||
|
||||
CTG_META_NHIT_INC();
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -174,9 +174,12 @@ void ctgFreeSMetaData(SMetaData* pData) {
|
|||
}
|
||||
|
||||
void ctgFreeSCtgUserAuth(SCtgUserAuth* userCache) {
|
||||
taosHashCleanup(userCache->createdDbs);
|
||||
taosHashCleanup(userCache->readDbs);
|
||||
taosHashCleanup(userCache->writeDbs);
|
||||
taosHashCleanup(userCache->userAuth.createdDbs);
|
||||
taosHashCleanup(userCache->userAuth.readDbs);
|
||||
taosHashCleanup(userCache->userAuth.writeDbs);
|
||||
taosHashCleanup(userCache->userAuth.readTbs);
|
||||
taosHashCleanup(userCache->userAuth.writeTbs);
|
||||
taosHashCleanup(userCache->userAuth.useDbs);
|
||||
}
|
||||
|
||||
void ctgFreeMetaRent(SCtgRentMgmt* mgmt) {
|
||||
|
@ -419,6 +422,9 @@ void ctgFreeMsgCtx(SCtgMsgCtx* pCtx) {
|
|||
taosHashCleanup(pOut->createdDbs);
|
||||
taosHashCleanup(pOut->readDbs);
|
||||
taosHashCleanup(pOut->writeDbs);
|
||||
taosHashCleanup(pOut->readTbs);
|
||||
taosHashCleanup(pOut->writeTbs);
|
||||
taosHashCleanup(pOut->useDbs);
|
||||
taosMemoryFreeClear(pCtx->out);
|
||||
break;
|
||||
}
|
||||
|
@ -1325,6 +1331,143 @@ static void* ctgCloneDnodeList(void* pSrc) { return taosArrayDup((const SArray*)
|
|||
|
||||
static void ctgFreeDnodeList(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); }
|
||||
|
||||
int32_t ctgChkSetTbAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
||||
int32_t code = 0;
|
||||
STableMeta* pMeta = NULL;
|
||||
SGetUserAuthRsp* pInfo = &req->authInfo;
|
||||
SHashObj* pTbs = (AUTH_TYPE_READ == req->singleType) ? pInfo->readTbs : pInfo->writeTbs;
|
||||
|
||||
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
||||
tNameExtractFullName(&req->pRawReq->tbName, tbFullName);
|
||||
char* pCond = taosHashGet(pTbs, tbFullName, strlen(tbFullName));
|
||||
if (pCond) {
|
||||
if (strlen(pCond) > 1) {
|
||||
CTG_ERR_RET(nodesStringToNode(pCond, &res->pRawRes->pCond));
|
||||
}
|
||||
|
||||
res->pRawRes->pass = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
res->pRawRes->pass = false;
|
||||
|
||||
// CTG_ERR_RET(catalogGetCachedTableMeta(pCtg, &req->pRawReq->tbName, &pMeta));
|
||||
// if (NULL == pMeta) {
|
||||
// if (req->onlyCache) {
|
||||
// res->metaNotExists = true;
|
||||
// ctgDebug("db %s tb %s meta not in cache for auth", req->pRawReq->tbName.dbname, req->pRawReq->tbName.tname);
|
||||
// return TSDB_CODE_SUCCESS;
|
||||
// }
|
||||
|
||||
// CTG_ERR_RET(catalogGetTableMeta(pCtg, req->pConn, &req->pRawReq->tbName, &pMeta));
|
||||
// }
|
||||
|
||||
// if (TSDB_SUPER_TABLE == pMeta->tableType || TSDB_NORMAL_TABLE == pMeta->tableType) {
|
||||
// res->pRawRes->pass = false;
|
||||
// goto _return;
|
||||
// }
|
||||
|
||||
// if (TSDB_CHILD_TABLE == pMeta->tableType) {
|
||||
// res->pRawRes->pass = true;
|
||||
|
||||
// /*
|
||||
// char stbName[TSDB_TABLE_NAME_LEN] = {0};
|
||||
// CTG_ERR_JRET(ctgGetCachedStbNameFromSuid(pCtg, pMeta->suid, stbName));
|
||||
// if (0 == stbName[0]) {
|
||||
// if (req->onlyCache) {
|
||||
// res->notExists = true;
|
||||
// return TSDB_CODE_SUCCESS;
|
||||
// }
|
||||
|
||||
// CTG_ERR_RET(catalogRefreshTableMeta(pCtg, req->pConn, &req->pRawReq->tbName, 0));
|
||||
// }
|
||||
// */
|
||||
// }
|
||||
|
||||
_return:
|
||||
|
||||
taosMemoryFree(pMeta);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
||||
int32_t code = 0;
|
||||
SUserAuthInfo* pReq = req->pRawReq;
|
||||
SUserAuthRes* pRes = res->pRawRes;
|
||||
SGetUserAuthRsp* pInfo = &req->authInfo;
|
||||
|
||||
pRes->pass = false;
|
||||
pRes->pCond = NULL;
|
||||
|
||||
if (!pInfo->enable) {
|
||||
pRes->pass = false;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (pInfo->superAuth) {
|
||||
pRes->pass = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
tNameGetFullDbName(&pReq->tbName, dbFName);
|
||||
|
||||
if (pInfo->createdDbs && taosHashGet(pInfo->createdDbs, dbFName, strlen(dbFName))) {
|
||||
pRes->pass = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
switch (pReq->type) {
|
||||
case AUTH_TYPE_READ: {
|
||||
if (pInfo->readTbs && taosHashGetSize(pInfo->readTbs) > 0) {
|
||||
req->singleType = AUTH_TYPE_READ;
|
||||
CTG_ERR_RET(ctgChkSetTbAuthRes(pCtg, req, res));
|
||||
if (pRes->pass) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
if (pInfo->readDbs && taosHashGet(pInfo->readDbs, dbFName, strlen(dbFName))) {
|
||||
pRes->pass = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case AUTH_TYPE_WRITE: {
|
||||
if (pInfo->writeTbs && taosHashGetSize(pInfo->writeTbs) > 0) {
|
||||
req->singleType = AUTH_TYPE_WRITE;
|
||||
CTG_ERR_RET(ctgChkSetTbAuthRes(pCtg, req, res));
|
||||
if (pRes->pass) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
if (pInfo->writeDbs && taosHashGet(pInfo->writeDbs, dbFName, strlen(dbFName))) {
|
||||
pRes->pass = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case AUTH_TYPE_READ_OR_WRITE: {
|
||||
if ((pInfo->readDbs && taosHashGet(pInfo->readDbs, dbFName, strlen(dbFName))) ||
|
||||
(pInfo->writeDbs && taosHashGet(pInfo->writeDbs, dbFName, strlen(dbFName))) ||
|
||||
(pInfo->useDbs && taosHashGet(pInfo->useDbs, dbFName, strlen(dbFName)))) {
|
||||
pRes->pass = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int32_t ctgCloneMetaDataArray(SArray* pSrc, __array_item_dup_fn_t copyFunc, SArray** pDst) {
|
||||
if (NULL == pSrc) {
|
||||
|
|
|
@ -9,7 +9,7 @@ IF(NOT TD_DARWIN)
|
|||
ADD_EXECUTABLE(catalogTest ${SOURCE_LIST})
|
||||
TARGET_LINK_LIBRARIES(
|
||||
catalogTest
|
||||
PUBLIC os util common catalog transport gtest qcom taos_static
|
||||
PUBLIC os util common nodes catalog transport gtest qcom taos_static
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
#ifdef WINDOWS
|
||||
#define TD_USE_WINSOCK
|
||||
#endif
|
||||
#include "catalogInt.h"
|
||||
#include "catalog.h"
|
||||
#include "catalogInt.h"
|
||||
#include "os.h"
|
||||
#include "stub.h"
|
||||
#include "taos.h"
|
||||
|
@ -48,7 +48,7 @@ void ctgTestSetRspCTableMeta();
|
|||
void ctgTestSetRspSTableMeta();
|
||||
void ctgTestSetRspMultiSTableMeta();
|
||||
|
||||
extern int32_t clientConnRefPool;
|
||||
extern int32_t clientConnRefPool;
|
||||
|
||||
enum {
|
||||
CTGT_RSP_VGINFO = 1,
|
||||
|
@ -298,7 +298,7 @@ void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) {
|
|||
|
||||
void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
|
||||
SUseDbRsp usedbRsp = {0};
|
||||
strcpy(usedbRsp.db, ctgTestDbname);
|
||||
usedbRsp.vgVersion = ctgTestVgVersion;
|
||||
|
@ -343,7 +343,7 @@ void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *
|
|||
|
||||
void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
|
||||
STableMetaRsp metaRsp = {0};
|
||||
strcpy(metaRsp.dbFName, ctgTestDbname);
|
||||
strcpy(metaRsp.tbName, ctgTestTablename);
|
||||
|
@ -384,13 +384,13 @@ void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *
|
|||
|
||||
void ctgTestRspTableMetaNotExist(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
|
||||
pRsp->code = CTG_ERR_CODE_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
|
||||
STableMetaRsp metaRsp = {0};
|
||||
strcpy(metaRsp.dbFName, ctgTestDbname);
|
||||
strcpy(metaRsp.tbName, ctgTestCurrentCTableName ? ctgTestCurrentCTableName : ctgTestCTablename);
|
||||
|
@ -438,7 +438,7 @@ void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg
|
|||
|
||||
void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
|
||||
STableMetaRsp metaRsp = {0};
|
||||
strcpy(metaRsp.dbFName, ctgTestDbname);
|
||||
strcpy(metaRsp.tbName, ctgTestCurrentSTableName ? ctgTestCurrentSTableName : ctgTestSTablename);
|
||||
|
@ -450,7 +450,7 @@ void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg
|
|||
metaRsp.sversion = ctgTestSVersion;
|
||||
metaRsp.tversion = ctgTestTVersion;
|
||||
metaRsp.suid = ctgTestSuid;
|
||||
metaRsp.tuid = ctgTestSuid+1;
|
||||
metaRsp.tuid = ctgTestSuid + 1;
|
||||
metaRsp.vgId = 0;
|
||||
metaRsp.pSchemas = (SSchema *)taosMemoryMalloc((metaRsp.numOfTags + metaRsp.numOfColumns) * sizeof(SSchema));
|
||||
|
||||
|
@ -486,7 +486,7 @@ void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg
|
|||
|
||||
void ctgTestRspMultiSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
|
||||
static int32_t idx = 1;
|
||||
|
||||
STableMetaRsp metaRsp = {0};
|
||||
|
@ -536,16 +536,14 @@ void ctgTestRspMultiSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRp
|
|||
tFreeSTableMetaRsp(&metaRsp);
|
||||
}
|
||||
|
||||
|
||||
void ctgTestRspErrIndexInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
|
||||
pRsp->code = TSDB_CODE_MND_DB_INDEX_NOT_EXIST;
|
||||
pRsp->contLen = 0;
|
||||
pRsp->pCont = NULL;
|
||||
}
|
||||
|
||||
|
||||
void ctgTestRspUserAuth(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
|
@ -553,6 +551,7 @@ void ctgTestRspUserAuth(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *p
|
|||
strcpy(userRsp.user, ctgTestUsername);
|
||||
userRsp.version = 1;
|
||||
userRsp.superAuth = 1;
|
||||
userRsp.enable = 1;
|
||||
|
||||
int32_t contLen = tSerializeSGetUserAuthRsp(NULL, 0, &userRsp);
|
||||
void *pReq = rpcMallocCont(contLen);
|
||||
|
@ -565,7 +564,7 @@ void ctgTestRspUserAuth(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *p
|
|||
|
||||
void ctgTestRspTableCfg(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
|
||||
static int32_t idx = 1;
|
||||
|
||||
STableCfgRsp tblRsp = {0};
|
||||
|
@ -600,7 +599,7 @@ void ctgTestRspTableCfg(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *p
|
|||
|
||||
void ctgTestRspTableIndex(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
|
||||
static int32_t idx = 1;
|
||||
|
||||
STableIndexRsp tblRsp = {0};
|
||||
|
@ -611,10 +610,10 @@ void ctgTestRspTableIndex(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg
|
|||
STableIndexInfo info = {0};
|
||||
for (int32_t i = 0; i < ctgTestIndexNum; ++i) {
|
||||
info.interval = 1 + i;
|
||||
info.expr = (char*)taosMemoryCalloc(1, 10);
|
||||
info.expr = (char *)taosMemoryCalloc(1, 10);
|
||||
taosArrayPush(tblRsp.pIndex, &info);
|
||||
}
|
||||
|
||||
|
||||
int32_t contLen = tSerializeSTableIndexRsp(NULL, 0, &tblRsp);
|
||||
void *pReq = rpcMallocCont(contLen);
|
||||
tSerializeSTableIndexRsp(pReq, contLen, &tblRsp);
|
||||
|
@ -628,12 +627,12 @@ void ctgTestRspTableIndex(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg
|
|||
|
||||
void ctgTestRspDBCfg(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
||||
|
||||
static int32_t idx = 1;
|
||||
|
||||
SDbCfgRsp dbRsp = {0};
|
||||
dbRsp.numOfVgroups = ctgTestVgNum;
|
||||
|
||||
|
||||
int32_t contLen = tSerializeSDbCfgRsp(NULL, 0, &dbRsp);
|
||||
void *pReq = rpcMallocCont(contLen);
|
||||
tSerializeSDbCfgRsp(pReq, contLen, &dbRsp);
|
||||
|
@ -651,7 +650,7 @@ void ctgTestRspQnodeList(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *
|
|||
for (int32_t i = 0; i < ctgTestQnodeNum; ++i) {
|
||||
SQueryNodeLoad nodeLoad = {0};
|
||||
nodeLoad.addr.nodeId = i;
|
||||
|
||||
|
||||
(void)taosArrayPush(qlistRsp.qnodeList, &nodeLoad);
|
||||
}
|
||||
|
||||
|
@ -676,7 +675,7 @@ void ctgTestRspUdfInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pR
|
|||
SFuncInfo funcInfo = {0};
|
||||
strcpy(funcInfo.name, "func1");
|
||||
funcInfo.funcType = ctgTestFuncType;
|
||||
|
||||
|
||||
(void)taosArrayPush(funcRsp.pFuncInfos, &funcInfo);
|
||||
SFuncExtraInfo extraInfo = {0};
|
||||
extraInfo.funcVersion = 0;
|
||||
|
@ -699,7 +698,7 @@ void ctgTestRspSvrVer(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRs
|
|||
|
||||
SServerVerRsp verRsp = {0};
|
||||
strcpy(verRsp.ver, "1.0");
|
||||
|
||||
|
||||
int32_t rspLen = tSerializeSServerVerRsp(NULL, 0, &verRsp);
|
||||
void *pReq = rpcMallocCont(rspLen);
|
||||
tSerializeSServerVerRsp(pReq, rspLen, &verRsp);
|
||||
|
@ -718,9 +717,9 @@ void ctgTestRspDndeList(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *p
|
|||
epSet.numOfEps = 1;
|
||||
tstrncpy(epSet.eps[0].fqdn, "localhost", TSDB_FQDN_LEN);
|
||||
epSet.eps[0].port = 6030;
|
||||
|
||||
|
||||
(void)taosArrayPush(dRsp.dnodeList, &epSet);
|
||||
|
||||
|
||||
int32_t rspLen = tSerializeSDnodeListRsp(NULL, 0, &dRsp);
|
||||
void *pReq = rpcMallocCont(rspLen);
|
||||
tSerializeSDnodeListRsp(pReq, rspLen, &dRsp);
|
||||
|
@ -732,8 +731,6 @@ void ctgTestRspDndeList(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *p
|
|||
tFreeSDnodeListRsp(&dRsp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ctgTestRspAuto(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
switch (pMsg->msgType) {
|
||||
case TDMT_MND_USE_DB:
|
||||
|
@ -750,7 +747,7 @@ void ctgTestRspAuto(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp)
|
|||
ctgTestRspDBCfg(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case TDMT_MND_QNODE_LIST:
|
||||
ctgTestRspQnodeList(shandle, pEpSet, pMsg, pRsp);
|
||||
ctgTestRspQnodeList(shandle, pEpSet, pMsg, pRsp);
|
||||
break;
|
||||
case TDMT_MND_RETRIEVE_FUNC:
|
||||
ctgTestRspUdfInfo(shandle, pEpSet, pMsg, pRsp);
|
||||
|
@ -768,7 +765,6 @@ void ctgTestRspAuto(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp)
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
void ctgTestRspByIdx(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
switch (ctgTestRspFunc[ctgTestRspIdx]) {
|
||||
case CTGT_RSP_VGINFO:
|
||||
|
@ -1063,7 +1059,7 @@ void ctgTestSetRspDbVgroupsAndMultiSuperMeta() {
|
|||
void *ctgTestGetDbVgroupThread(void *param) {
|
||||
struct SCatalog *pCtg = (struct SCatalog *)param;
|
||||
int32_t code = 0;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SArray *vgList = NULL;
|
||||
int32_t n = 0;
|
||||
|
@ -1209,7 +1205,6 @@ void *ctgTestSetCtableMetaThread(void *param) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void ctgTestFetchRows(TAOS_RES *result, int32_t *rows) {
|
||||
TAOS_ROW row;
|
||||
int num_fields = taos_num_fields(result);
|
||||
|
@ -1225,23 +1220,22 @@ void ctgTestFetchRows(TAOS_RES *result, int32_t *rows) {
|
|||
}
|
||||
}
|
||||
|
||||
void ctgTestExecQuery(TAOS * taos, char* sql, bool fetch, int32_t *rows) {
|
||||
void ctgTestExecQuery(TAOS *taos, char *sql, bool fetch, int32_t *rows) {
|
||||
TAOS_RES *result = taos_query(taos, sql);
|
||||
int code = taos_errno(result);
|
||||
int code = taos_errno(result);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
if (fetch) {
|
||||
ctgTestFetchRows(result, rows);
|
||||
}
|
||||
|
||||
|
||||
taos_free_result(result);
|
||||
}
|
||||
|
||||
|
||||
TEST(tableMeta, normalTable) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
@ -1377,7 +1371,7 @@ TEST(tableMeta, normalTable) {
|
|||
|
||||
TEST(tableMeta, childTableCase) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
|
||||
|
@ -1489,7 +1483,7 @@ TEST(tableMeta, childTableCase) {
|
|||
|
||||
TEST(tableMeta, superTableCase) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
|
||||
|
@ -1631,7 +1625,7 @@ TEST(tableMeta, superTableCase) {
|
|||
|
||||
TEST(tableMeta, rmStbMeta) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
|
||||
|
@ -1701,7 +1695,7 @@ TEST(tableMeta, rmStbMeta) {
|
|||
|
||||
TEST(tableMeta, updateStbMeta) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
|
||||
|
@ -1790,7 +1784,7 @@ TEST(tableMeta, updateStbMeta) {
|
|||
|
||||
TEST(getIndexInfo, notExists) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SArray *vgList = NULL;
|
||||
|
@ -1814,13 +1808,13 @@ TEST(getIndexInfo, notExists) {
|
|||
SIndexInfo info;
|
||||
code = catalogGetIndexMeta(pCtg, mockPointer, "index1", &info);
|
||||
ASSERT_TRUE(code != 0);
|
||||
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
TEST(refreshGetMeta, normal2normal) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SArray *vgList = NULL;
|
||||
|
@ -1899,7 +1893,7 @@ TEST(refreshGetMeta, normal2normal) {
|
|||
|
||||
TEST(refreshGetMeta, normal2notexist) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SArray *vgList = NULL;
|
||||
|
@ -1969,7 +1963,7 @@ TEST(refreshGetMeta, normal2notexist) {
|
|||
|
||||
TEST(refreshGetMeta, normal2child) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SArray *vgList = NULL;
|
||||
|
@ -2050,10 +2044,9 @@ TEST(refreshGetMeta, normal2child) {
|
|||
ctgTestCurrentSTableName = NULL;
|
||||
}
|
||||
|
||||
|
||||
TEST(refreshGetMeta, stable2child) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SArray *vgList = NULL;
|
||||
|
@ -2139,7 +2132,7 @@ TEST(refreshGetMeta, stable2child) {
|
|||
|
||||
TEST(refreshGetMeta, stable2stable) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SArray *vgList = NULL;
|
||||
|
@ -2225,7 +2218,7 @@ TEST(refreshGetMeta, stable2stable) {
|
|||
|
||||
TEST(refreshGetMeta, child2stable) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SArray *vgList = NULL;
|
||||
|
@ -2311,7 +2304,7 @@ TEST(refreshGetMeta, child2stable) {
|
|||
|
||||
TEST(tableDistVgroup, normalTable) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo *vgInfo = NULL;
|
||||
SArray *vgList = NULL;
|
||||
|
@ -2348,7 +2341,7 @@ TEST(tableDistVgroup, normalTable) {
|
|||
|
||||
TEST(tableDistVgroup, childTableCase) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo *vgInfo = NULL;
|
||||
SArray *vgList = NULL;
|
||||
|
@ -2386,7 +2379,7 @@ TEST(tableDistVgroup, childTableCase) {
|
|||
|
||||
TEST(tableDistVgroup, superTableCase) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo *vgInfo = NULL;
|
||||
SArray *vgList = NULL;
|
||||
|
@ -2435,7 +2428,7 @@ TEST(tableDistVgroup, superTableCase) {
|
|||
|
||||
TEST(dbVgroup, getSetDbVgroupCase) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SVgroupInfo *pvgInfo = NULL;
|
||||
|
@ -2525,7 +2518,7 @@ TEST(dbVgroup, getSetDbVgroupCase) {
|
|||
|
||||
TEST(multiThread, getSetRmSameDbVgroup) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SVgroupInfo *pvgInfo = NULL;
|
||||
|
@ -2577,7 +2570,7 @@ TEST(multiThread, getSetRmSameDbVgroup) {
|
|||
|
||||
TEST(multiThread, getSetRmDiffDbVgroup) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SVgroupInfo *pvgInfo = NULL;
|
||||
|
@ -2629,7 +2622,7 @@ TEST(multiThread, getSetRmDiffDbVgroup) {
|
|||
|
||||
TEST(multiThread, ctableMeta) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SVgroupInfo *pvgInfo = NULL;
|
||||
|
@ -2680,7 +2673,7 @@ TEST(multiThread, ctableMeta) {
|
|||
|
||||
TEST(rentTest, allRent) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
SVgroupInfo vgInfo = {0};
|
||||
SVgroupInfo *pvgInfo = NULL;
|
||||
|
@ -2759,7 +2752,7 @@ TEST(rentTest, allRent) {
|
|||
|
||||
TEST(apiTest, catalogRefreshDBVgInfo_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
@ -2786,7 +2779,7 @@ TEST(apiTest, catalogRefreshDBVgInfo_test) {
|
|||
|
||||
TEST(apiTest, catalogChkAuth_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
@ -2805,15 +2798,19 @@ TEST(apiTest, catalogChkAuth_test) {
|
|||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
bool pass = false;
|
||||
SUserAuthInfo authInfo = {0};
|
||||
SUserAuthRes authRes = {0};
|
||||
strcpy(authInfo.user, ctgTestUsername);
|
||||
toName(1, ctgTestDbname, ctgTestSTablename, &authInfo.tbName);
|
||||
authInfo.type = AUTH_TYPE_READ;
|
||||
bool exists = false;
|
||||
code = catalogChkAuthFromCache(pCtg, ctgTestUsername, ctgTestDbname, AUTH_TYPE_READ, &pass, &exists);
|
||||
code = catalogChkAuthFromCache(pCtg, &authInfo, &authRes, &exists);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(exists, false);
|
||||
|
||||
code = catalogChkAuth(pCtg, mockPointer, ctgTestUsername, ctgTestDbname, AUTH_TYPE_READ, &pass);
|
||||
|
||||
code = catalogChkAuth(pCtg, mockPointer, &authInfo, &authRes);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(pass, true);
|
||||
ASSERT_EQ(authRes.pass, true);
|
||||
|
||||
while (true) {
|
||||
uint64_t n = 0;
|
||||
|
@ -2825,9 +2822,9 @@ TEST(apiTest, catalogChkAuth_test) {
|
|||
}
|
||||
}
|
||||
|
||||
code = catalogChkAuthFromCache(pCtg, ctgTestUsername, ctgTestDbname, AUTH_TYPE_READ, &pass, &exists);
|
||||
code = catalogChkAuthFromCache(pCtg, &authInfo, &authRes, &exists);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(pass, true);
|
||||
ASSERT_EQ(authRes.pass, true);
|
||||
ASSERT_EQ(exists, true);
|
||||
|
||||
catalogDestroy();
|
||||
|
@ -2835,7 +2832,7 @@ TEST(apiTest, catalogChkAuth_test) {
|
|||
|
||||
TEST(apiTest, catalogRefreshGetTableCfg_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
@ -2873,7 +2870,7 @@ TEST(apiTest, catalogRefreshGetTableCfg_test) {
|
|||
|
||||
TEST(apiTest, catalogGetTableIndex_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
@ -2909,7 +2906,7 @@ TEST(apiTest, catalogGetTableIndex_test) {
|
|||
|
||||
TEST(apiTest, catalogGetDBCfg_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
@ -2942,7 +2939,7 @@ TEST(apiTest, catalogGetDBCfg_test) {
|
|||
|
||||
TEST(apiTest, catalogGetQnodeList_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
@ -2967,17 +2964,16 @@ TEST(apiTest, catalogGetQnodeList_test) {
|
|||
ASSERT_EQ(taosArrayGetSize(qnodeList), ctgTestQnodeNum);
|
||||
|
||||
for (int32_t i = 0; i < ctgTestQnodeNum; ++i) {
|
||||
SQueryNodeLoad * pLoad = (SQueryNodeLoad *)taosArrayGet(qnodeList, i);
|
||||
SQueryNodeLoad *pLoad = (SQueryNodeLoad *)taosArrayGet(qnodeList, i);
|
||||
ASSERT_EQ(pLoad->addr.nodeId, i);
|
||||
}
|
||||
|
||||
catalogDestroy();
|
||||
}
|
||||
|
||||
|
||||
TEST(apiTest, catalogGetUdfInfo_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
@ -3004,10 +3000,9 @@ TEST(apiTest, catalogGetUdfInfo_test) {
|
|||
catalogDestroy();
|
||||
}
|
||||
|
||||
|
||||
TEST(apiTest, catalogGetServerVersion_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
@ -3026,7 +3021,7 @@ TEST(apiTest, catalogGetServerVersion_test) {
|
|||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
char* ver = NULL;
|
||||
char *ver = NULL;
|
||||
code = catalogGetServerVersion(pCtg, mockPointer, &ver);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(0 == strcmp(ver, "1.0"));
|
||||
|
@ -3036,7 +3031,7 @@ TEST(apiTest, catalogGetServerVersion_test) {
|
|||
|
||||
TEST(apiTest, catalogUpdateTableIndex_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
@ -3066,10 +3061,9 @@ TEST(apiTest, catalogUpdateTableIndex_test) {
|
|||
catalogDestroy();
|
||||
}
|
||||
|
||||
|
||||
TEST(apiTest, catalogGetDnodeList_test) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo connInfo = {0};
|
||||
SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo;
|
||||
|
||||
ctgTestInitLogFile();
|
||||
|
@ -3088,7 +3082,7 @@ TEST(apiTest, catalogGetDnodeList_test) {
|
|||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SArray* pList = NULL;
|
||||
SArray *pList = NULL;
|
||||
code = catalogGetDnodeList(pCtg, mockPointer, &pList);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(taosArrayGetSize(pList), 1);
|
||||
|
@ -3100,23 +3094,23 @@ TEST(apiTest, catalogGetDnodeList_test) {
|
|||
|
||||
#ifdef INTEGRATION_TEST
|
||||
TEST(intTest, autoCreateTableTest) {
|
||||
struct SCatalog *pCtg = NULL;
|
||||
struct SCatalog *pCtg = NULL;
|
||||
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_TRUE(NULL != taos);
|
||||
TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_TRUE(NULL != taos);
|
||||
|
||||
ctgdEnableDebug("api", true);
|
||||
ctgdEnableDebug("meta", true);
|
||||
ctgdEnableDebug("cache", true);
|
||||
ctgdEnableDebug("lock", true);
|
||||
|
||||
|
||||
ctgTestExecQuery(taos, "drop database if exists db1", false, NULL);
|
||||
ctgTestExecQuery(taos, "create database db1", false, NULL);
|
||||
ctgTestExecQuery(taos, "create stable db1.st1 (ts timestamp, f1 int) tags(tg1 int)", false, NULL);
|
||||
ctgTestExecQuery(taos, "insert into db1.tb1 using db1.st1 tags(1) values(now, 1)", false, NULL);
|
||||
|
||||
ctgdGetOneHandle(&pCtg);
|
||||
|
||||
|
||||
while (true) {
|
||||
uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM);
|
||||
if (2 != n) {
|
||||
|
@ -3142,15 +3136,14 @@ TEST(intTest, autoCreateTableTest) {
|
|||
ctgTestExecQuery(taos, "alter table db1.st1 add column f2 double", false, NULL);
|
||||
|
||||
ctgdEnableDebug("stopUpdate", false);
|
||||
|
||||
|
||||
ctgTestExecQuery(taos, "insert into db1.tb1 (ts, f1) values(now, 4)", false, NULL);
|
||||
|
||||
|
||||
taos_close(taos);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
|
|
|
@ -29,7 +29,6 @@ struct SDataSinkHandle;
|
|||
|
||||
typedef struct SDataSinkManager {
|
||||
SDataSinkMgtCfg cfg;
|
||||
TdThreadMutex mutex;
|
||||
} SDataSinkManager;
|
||||
|
||||
typedef int32_t (*FPutDataBlock)(struct SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue);
|
||||
|
|
|
@ -127,14 +127,9 @@ enum {
|
|||
};
|
||||
|
||||
typedef struct {
|
||||
// TODO remove prepareStatus
|
||||
STqOffsetVal prepareStatus; // for tmq
|
||||
STqOffsetVal lastStatus; // for tmq
|
||||
SMqMetaRsp metaRsp; // for tmq fetching meta
|
||||
int8_t returned;
|
||||
int64_t snapshotVer;
|
||||
// const SSubmitReq* pReq;
|
||||
|
||||
STqOffsetVal currentOffset; // for tmq
|
||||
SMqMetaRsp metaRsp; // for tmq fetching meta
|
||||
int64_t snapshotVer;
|
||||
SPackedData submit;
|
||||
SSchemaWrapper* schema;
|
||||
char tbName[TSDB_TABLE_NAME_LEN];
|
||||
|
@ -193,7 +188,6 @@ enum {
|
|||
OP_OPENED = 0x1,
|
||||
OP_RES_TO_RETURN = 0x5,
|
||||
OP_EXEC_DONE = 0x9,
|
||||
OP_EXEC_RECV = 0x11,
|
||||
};
|
||||
|
||||
typedef struct SOperatorFpSet {
|
||||
|
@ -507,32 +501,12 @@ typedef struct STableCountScanSupp {
|
|||
char stbNameFilter[TSDB_TABLE_NAME_LEN];
|
||||
} STableCountScanSupp;
|
||||
|
||||
typedef struct STableCountScanOperatorInfo {
|
||||
SReadHandle readHandle;
|
||||
SSDataBlock* pRes;
|
||||
|
||||
STableCountScanSupp supp;
|
||||
|
||||
int32_t currGrpIdx;
|
||||
SArray* stbUidList; // when group by db_name and/or stable_name
|
||||
} STableCountScanOperatorInfo;
|
||||
|
||||
typedef struct SOptrBasicInfo {
|
||||
SResultRowInfo resultRowInfo;
|
||||
SSDataBlock* pRes;
|
||||
bool mergeResultBlock;
|
||||
} SOptrBasicInfo;
|
||||
|
||||
typedef struct SAggOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SAggSupporter aggSup;
|
||||
STableQueryInfo* current;
|
||||
uint64_t groupId;
|
||||
SGroupResInfo groupResInfo;
|
||||
SExprSupp scalarExprSup;
|
||||
bool groupKeyOptimized;
|
||||
} SAggOperatorInfo;
|
||||
|
||||
typedef struct SIntervalAggOperatorInfo {
|
||||
SOptrBasicInfo binfo; // basic info
|
||||
SAggSupporter aggSup; // aggregate supporter
|
||||
|
@ -859,8 +833,7 @@ SArray* getTableListInfo(const SExecTaskInfo* pTaskInfo);
|
|||
|
||||
int32_t createExecTaskInfo(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId,
|
||||
int32_t vgId, char* sql, EOPTR_EXEC_MODEL model);
|
||||
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, STableListInfo* pTableListInfo,
|
||||
SReadHandle* readHandle);
|
||||
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle);
|
||||
int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SArray* pExecInfoList);
|
||||
|
||||
STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval,
|
||||
|
|
|
@ -40,6 +40,16 @@ typedef struct {
|
|||
int32_t startOffset;
|
||||
} SFunctionCtxStatus;
|
||||
|
||||
typedef struct SAggOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SAggSupporter aggSup;
|
||||
STableQueryInfo* current;
|
||||
uint64_t groupId;
|
||||
SGroupResInfo groupResInfo;
|
||||
SExprSupp scalarExprSup;
|
||||
bool groupKeyOptimized;
|
||||
} SAggOperatorInfo;
|
||||
|
||||
static void destroyAggOperatorInfo(void* param);
|
||||
static void setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId);
|
||||
|
||||
|
@ -162,9 +172,9 @@ int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) {
|
|||
int32_t scanFlag = MAIN_SCAN;
|
||||
|
||||
bool hasValidBlock = false;
|
||||
bool blockAllocated = false;
|
||||
|
||||
while (1) {
|
||||
bool blockAllocated = false;
|
||||
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
||||
if (pBlock == NULL) {
|
||||
if (!hasValidBlock) {
|
||||
|
@ -560,4 +570,4 @@ void functionCtxRestore(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus) {
|
|||
pCtx->input.colDataSMAIsSet = pStatus->hasAgg;
|
||||
pCtx->input.numOfRows = pStatus->numOfRows;
|
||||
pCtx->input.startRowIndex = pStatus->startOffset;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ SDataSinkStat gDataSinkStat = {0};
|
|||
|
||||
int32_t dsDataSinkMgtInit(SDataSinkMgtCfg* cfg) {
|
||||
gDataSinkManager.cfg = *cfg;
|
||||
taosThreadMutexInit(&gDataSinkManager.mutex, NULL);
|
||||
return 0; // to avoid compiler eror
|
||||
}
|
||||
|
||||
|
|
|
@ -127,12 +127,10 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu
|
|||
pOperator->status = OP_NOT_OPENED;
|
||||
|
||||
SStreamScanInfo* pInfo = pOperator->info;
|
||||
qDebug("stream set total blocks:%d, task id:%s" PRIx64, (int32_t)numOfBlocks, id);
|
||||
ASSERT(pInfo->validBlockIndex == 0);
|
||||
ASSERT(taosArrayGetSize(pInfo->pBlockLists) == 0);
|
||||
qDebug("s-task set source blocks:%d %s", (int32_t)numOfBlocks, id);
|
||||
ASSERT(pInfo->validBlockIndex == 0 && taosArrayGetSize(pInfo->pBlockLists) == 0);
|
||||
|
||||
if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
||||
// ASSERT(numOfBlocks > 1);
|
||||
for (int32_t i = 0; i < numOfBlocks; i++) {
|
||||
SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
|
||||
taosArrayPush(pInfo->pBlockLists, pReq);
|
||||
|
@ -206,6 +204,7 @@ void qGetCheckpointVersion(qTaskInfo_t tinfo, int64_t* dataVer, int64_t* ckId) {
|
|||
*ckId = pTaskInfo->streamInfo.checkPointId;
|
||||
}
|
||||
|
||||
|
||||
int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type) {
|
||||
if (tinfo == NULL) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
|
@ -371,27 +370,28 @@ static SArray* filterUnqualifiedTables(const SStreamScanInfo* pScanInfo, const S
|
|||
return qa;
|
||||
}
|
||||
|
||||
int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd) {
|
||||
int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd, SArray* pList) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
const char* id = GET_TASKID(pTaskInfo);
|
||||
int32_t code = 0;
|
||||
|
||||
if (isAdd) {
|
||||
qDebug("add %d tables id into query list, %s", (int32_t)taosArrayGetSize(tableIdList), pTaskInfo->id.str);
|
||||
qDebug("add %d tables id into query list, %s", (int32_t)taosArrayGetSize(tableIdList), id);
|
||||
}
|
||||
|
||||
// traverse to the stream scanner node to add this table id
|
||||
SOperatorInfo* pInfo = pTaskInfo->pRoot;
|
||||
while (pInfo->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||
pInfo = pInfo->pDownstream[0];
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
SOperatorInfo* pInfo = extractOperatorInTree(pTaskInfo->pRoot, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id);
|
||||
SStreamScanInfo* pScanInfo = pInfo->info;
|
||||
|
||||
if (isAdd) { // add new table id
|
||||
SArray* qa = filterUnqualifiedTables(pScanInfo, tableIdList, GET_TASKID(pTaskInfo));
|
||||
int32_t numOfQualifiedTables = taosArrayGetSize(qa);
|
||||
|
||||
qDebug(" %d qualified child tables added into stream scanner", numOfQualifiedTables);
|
||||
if (pList != NULL) {
|
||||
taosArrayAddAll(pList, qa);
|
||||
}
|
||||
|
||||
qDebug("%d qualified child tables added into stream scanner, %s", numOfQualifiedTables, id);
|
||||
code = tqReaderAddTbUidList(pScanInfo->tqReader, qa);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosArrayDestroy(qa);
|
||||
|
@ -432,19 +432,6 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool exists = false;
|
||||
for (int32_t k = 0; k < taosArrayGetSize(pListInfo->pTableList); ++k) {
|
||||
STableKeyInfo* pKeyInfo = taosArrayGet(pListInfo->pTableList, k);
|
||||
if (pKeyInfo->uid == keyInfo.uid) {
|
||||
qWarn("ignore duplicated query table uid:%" PRIu64 " added, %s", pKeyInfo->uid, pTaskInfo->id.str);
|
||||
exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!exists) {
|
||||
#endif
|
||||
|
||||
tableListAddTableInfo(pTableListInfo, keyInfo.uid, keyInfo.groupId);
|
||||
}
|
||||
|
||||
|
@ -455,7 +442,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo
|
|||
|
||||
taosArrayDestroy(qa);
|
||||
} else { // remove the table id in current list
|
||||
qDebug(" %d remove child tables from the stream scanner", (int32_t)taosArrayGetSize(tableIdList));
|
||||
qDebug("%d remove child tables from the stream scanner, %s", (int32_t)taosArrayGetSize(tableIdList), id);
|
||||
taosWLockLatch(&pTaskInfo->lock);
|
||||
code = tqReaderRemoveTbUidList(pScanInfo->tqReader, tableIdList);
|
||||
taosWUnLockLatch(&pTaskInfo->lock);
|
||||
|
@ -511,12 +498,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
|
|||
|
||||
if (handle) {
|
||||
void* pSinkParam = NULL;
|
||||
|
||||
SArray* pInfoList = getTableListInfo(*pTask);
|
||||
STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
|
||||
taosArrayDestroy(pInfoList);
|
||||
|
||||
code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, pTableListInfo, readHandle);
|
||||
code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, (*pTask), readHandle);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
qError("failed to createDataSinkParam, vgId:%d, code:%s, %s", vgId, tstrerror(code), (*pTask)->id.str);
|
||||
goto _error;
|
||||
|
@ -1035,15 +1017,9 @@ SMqMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo) {
|
|||
return &pTaskInfo->streamInfo.metaRsp;
|
||||
}
|
||||
|
||||
int64_t qStreamExtractPrepareUid(qTaskInfo_t tinfo) {
|
||||
void qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
return pTaskInfo->streamInfo.prepareStatus.uid;
|
||||
}
|
||||
|
||||
int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
memcpy(pOffset, &pTaskInfo->streamInfo.lastStatus, sizeof(STqOffsetVal));
|
||||
return 0;
|
||||
memcpy(pOffset, &pTaskInfo->streamInfo.currentOffset, sizeof(STqOffsetVal));
|
||||
}
|
||||
|
||||
int32_t initQueryTableDataCondForTmq(SQueryTableDataCond* pCond, SSnapContext* sContext, SMetaTableInfo* pMtInfo) {
|
||||
|
@ -1081,6 +1057,7 @@ int32_t qStreamSetScanMemData(qTaskInfo_t tinfo, SPackedData submit) {
|
|||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
if ((pTaskInfo->execModel != OPTR_EXEC_MODEL_QUEUE) || (pTaskInfo->streamInfo.submit.msgStr != NULL)) {
|
||||
qError("qStreamSetScanMemData err:%d,%p", pTaskInfo->execModel, pTaskInfo->streamInfo.submit.msgStr);
|
||||
terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
return -1;
|
||||
}
|
||||
qDebug("set the submit block for future scan");
|
||||
|
@ -1089,22 +1066,27 @@ int32_t qStreamSetScanMemData(qTaskInfo_t tinfo, SPackedData submit) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void qStreamSetOpen(qTaskInfo_t tinfo) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
SOperatorInfo* pOperator = pTaskInfo->pRoot;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
}
|
||||
|
||||
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType) {
|
||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||
SOperatorInfo* pOperator = pTaskInfo->pRoot;
|
||||
const char* id = GET_TASKID(pTaskInfo);
|
||||
|
||||
pTaskInfo->streamInfo.prepareStatus = *pOffset;
|
||||
pTaskInfo->streamInfo.returned = 0;
|
||||
|
||||
if (tOffsetEqual(pOffset, &pTaskInfo->streamInfo.lastStatus)) {
|
||||
// if pOffset equal to current offset, means continue consume
|
||||
if (tOffsetEqual(pOffset, &pTaskInfo->streamInfo.currentOffset)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
pOperator->status = OP_OPENED;
|
||||
pOperator = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id);
|
||||
|
||||
if (pOperator == NULL) {
|
||||
return -1;
|
||||
}
|
||||
SStreamScanInfo* pInfo = pOperator->info;
|
||||
STableScanInfo* pScanInfo = pInfo->pTableScanOp->info;
|
||||
STableScanBase* pScanBaseInfo = &pScanInfo->base;
|
||||
|
@ -1115,7 +1097,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
pScanBaseInfo->dataReader = NULL;
|
||||
|
||||
// let's seek to the next version in wal file
|
||||
if (tqSeekVer(pInfo->tqReader, pOffset->version + 1, pTaskInfo->id.str) < 0) {
|
||||
if (tqSeekVer(pInfo->tqReader, pOffset->version + 1, id) < 0) {
|
||||
qError("tqSeekVer failed ver:%" PRId64 ", %s", pOffset->version + 1, id);
|
||||
return -1;
|
||||
}
|
||||
|
@ -1139,10 +1121,13 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
} else {
|
||||
taosRUnLockLatch(&pTaskInfo->lock);
|
||||
qError("no table in table list, %s", id);
|
||||
terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
qDebug("switch to table uid:%" PRId64 " ts:%" PRId64 "% " PRId64 " rows returned", uid, ts,
|
||||
pInfo->pTableScanOp->resultInfo.totalRows);
|
||||
pInfo->pTableScanOp->resultInfo.totalRows = 0;
|
||||
|
||||
// start from current accessed position
|
||||
|
@ -1156,6 +1141,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
} else {
|
||||
qError("vgId:%d uid:%" PRIu64 " not found in table list, total:%d, index:%d %s", pTaskInfo->id.vgId, uid,
|
||||
numOfTables, pScanInfo->currentTable, id);
|
||||
terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1188,6 +1174,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
pScanBaseInfo->cond.twindows.skey = oldSkey;
|
||||
} else {
|
||||
qError("invalid pOffset->type:%d, %s", pOffset->type, id);
|
||||
terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1202,6 +1189,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
|
||||
if (setForSnapShot(sContext, pOffset->uid) != 0) {
|
||||
qError("setDataForSnapShot error. uid:%" PRId64 " , %s", pOffset->uid, id);
|
||||
terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1213,7 +1201,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
tableListClear(pTableListInfo);
|
||||
|
||||
if (mtInfo.uid == 0) {
|
||||
return 0; // no data
|
||||
goto end; // no data
|
||||
}
|
||||
|
||||
initQueryTableDataCondForTmq(&pTaskInfo->streamInfo.tableCond, sContext, &mtInfo);
|
||||
|
@ -1238,6 +1226,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
SSnapContext* sContext = pInfo->sContext;
|
||||
if (setForSnapShot(sContext, pOffset->uid) != 0) {
|
||||
qError("setForSnapShot error. uid:%" PRIu64 " ,version:%" PRId64, pOffset->uid, pOffset->version);
|
||||
terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
return -1;
|
||||
}
|
||||
qDebug("tmqsnap qStreamPrepareScan snapshot meta uid:%" PRId64 " ts %" PRId64 " %s", pOffset->uid, pOffset->ts,
|
||||
|
@ -1250,6 +1239,9 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
|||
}
|
||||
}
|
||||
|
||||
end:
|
||||
pTaskInfo->streamInfo.currentOffset = *pOffset;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1276,3 +1268,22 @@ void qProcessRspMsg(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
|||
rpcFreeCont(pMsg->pCont);
|
||||
destroySendMsgInfo(pSendInfo);
|
||||
}
|
||||
|
||||
SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo) {
|
||||
SExecTaskInfo* pTaskInfo = tinfo;
|
||||
SArray* plist = getTableListInfo(pTaskInfo);
|
||||
|
||||
// only extract table in the first elements
|
||||
STableListInfo* pTableListInfo = taosArrayGetP(plist, 0);
|
||||
|
||||
SArray* pUidList = taosArrayInit(10, sizeof(uint64_t));
|
||||
|
||||
int32_t numOfTables = tableListGetSize(pTableListInfo);
|
||||
for(int32_t i = 0; i < numOfTables; ++i) {
|
||||
STableKeyInfo* pKeyInfo = tableListGetInfo(pTableListInfo, i);
|
||||
taosArrayPush(pUidList, &pKeyInfo->uid);
|
||||
}
|
||||
|
||||
taosArrayDestroy(plist);
|
||||
return pUidList;
|
||||
}
|
||||
|
|
|
@ -972,6 +972,7 @@ int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scan
|
|||
SOperatorInfo* extractOperatorInTree(SOperatorInfo* pOperator, int32_t type, const char* id) {
|
||||
if (pOperator == NULL) {
|
||||
qError("invalid operator, failed to find tableScanOperator %s", id);
|
||||
terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -980,6 +981,7 @@ SOperatorInfo* extractOperatorInTree(SOperatorInfo* pOperator, int32_t type, con
|
|||
} else {
|
||||
if (pOperator->pDownstream == NULL || pOperator->pDownstream[0] == NULL) {
|
||||
qError("invalid operator, failed to find tableScanOperator %s", id);
|
||||
terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1565,8 +1567,7 @@ int32_t extractTableScanNode(SPhysiNode* pNode, STableScanPhysiNode** ppNode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, STableListInfo* pTableListInfo,
|
||||
SReadHandle* readHandle) {
|
||||
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle) {
|
||||
switch (pNode->type) {
|
||||
case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
|
||||
SInserterParam* pInserterParam = taosMemoryCalloc(1, sizeof(SInserterParam));
|
||||
|
@ -1584,23 +1585,26 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, STableListInfo*
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t tbNum = tableListGetSize(pTableListInfo);
|
||||
SArray* pInfoList = getTableListInfo(pTask);
|
||||
STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
|
||||
taosArrayDestroy(pInfoList);
|
||||
|
||||
pDeleterParam->suid = tableListGetSuid(pTableListInfo);
|
||||
|
||||
// TODO extract uid list
|
||||
pDeleterParam->pUidList = taosArrayInit(tbNum, sizeof(uint64_t));
|
||||
int32_t numOfTables = tableListGetSize(pTableListInfo);
|
||||
pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t));
|
||||
if (NULL == pDeleterParam->pUidList) {
|
||||
taosMemoryFree(pDeleterParam);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < tbNum; ++i) {
|
||||
for (int32_t i = 0; i < numOfTables; ++i) {
|
||||
STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
|
||||
taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
|
||||
}
|
||||
|
||||
*pParam = pDeleterParam;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1965,11 +1969,11 @@ void qStreamCloseTsdbReader(void* task) {
|
|||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)task;
|
||||
SOperatorInfo* pOp = pTaskInfo->pRoot;
|
||||
|
||||
qDebug("stream close tsdb reader, reset status uid:%" PRId64 " ts:%" PRId64, pTaskInfo->streamInfo.lastStatus.uid,
|
||||
pTaskInfo->streamInfo.lastStatus.ts);
|
||||
qDebug("stream close tsdb reader, reset status uid:%" PRId64 " ts:%" PRId64, pTaskInfo->streamInfo.currentOffset.uid,
|
||||
pTaskInfo->streamInfo.currentOffset.ts);
|
||||
|
||||
// todo refactor, other thread may already use this read to extract data.
|
||||
pTaskInfo->streamInfo.lastStatus = (STqOffsetVal){0};
|
||||
pTaskInfo->streamInfo.currentOffset = (STqOffsetVal){0};
|
||||
while (pOp->numOfDownstream == 1 && pOp->pDownstream[0]) {
|
||||
SOperatorInfo* pDownstreamOp = pOp->pDownstream[0];
|
||||
if (pDownstreamOp->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||
|
@ -1996,7 +2000,11 @@ void qStreamCloseTsdbReader(void* task) {
|
|||
}
|
||||
|
||||
static void extractTableList(SArray* pList, const SOperatorInfo* pOperator) {
|
||||
if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
|
||||
if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||
SStreamScanInfo* pScanInfo = pOperator->info;
|
||||
STableScanInfo* pTableScanInfo = pScanInfo->pTableScanOp->info;
|
||||
taosArrayPush(pList, &pTableScanInfo->base.pTableListInfo);
|
||||
} else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
|
||||
STableScanInfo* pScanInfo = pOperator->info;
|
||||
taosArrayPush(pList, &pScanInfo->base.pTableListInfo);
|
||||
} else {
|
||||
|
|
|
@ -227,17 +227,8 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
|||
blockDataCleanup(pFinalRes);
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
if (pTaskInfo->streamInfo.submit.msgStr) {
|
||||
pOperator->status = OP_OPENED;
|
||||
}
|
||||
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) {
|
||||
pOperator->status = OP_OPENED;
|
||||
qDebug("projection in queue model, set status open and return null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -263,23 +254,14 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
|||
// The downstream exec may change the value of the newgroup, so use a local variable instead.
|
||||
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
||||
if (pBlock == NULL) {
|
||||
if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE && pFinalRes->info.rows == 0) {
|
||||
pOperator->status = OP_OPENED;
|
||||
if (pOperator->status == OP_EXEC_RECV) {
|
||||
continue;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
qDebug("set op close, exec %d, status %d rows %" PRId64 , pTaskInfo->execModel, pOperator->status,
|
||||
pFinalRes->info.rows);
|
||||
qDebug("set op close, exec %d, status %d rows %" PRId64 , pTaskInfo->execModel, pOperator->status, pFinalRes->info.rows);
|
||||
setOperatorCompleted(pOperator);
|
||||
break;
|
||||
}
|
||||
if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) {
|
||||
qDebug("set status recv");
|
||||
pOperator->status = OP_EXEC_RECV;
|
||||
}
|
||||
// if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) {
|
||||
// qDebug("set status recv");
|
||||
// pOperator->status = OP_EXEC_RECV;
|
||||
// }
|
||||
|
||||
// for stream interval
|
||||
if (pBlock->info.type == STREAM_RETRIEVE || pBlock->info.type == STREAM_DELETE_RESULT ||
|
||||
|
|
|
@ -36,6 +36,7 @@ int32_t scanDebug = 0;
|
|||
#define MULTI_READER_MAX_TABLE_NUM 5000
|
||||
#define SET_REVERSE_SCAN_FLAG(_info) ((_info)->scanFlag = REVERSE_SCAN)
|
||||
#define SWITCH_ORDER(n) (((n) = ((n) == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC))
|
||||
#define STREAM_SCAN_OP_NAME "StreamScanOperator"
|
||||
|
||||
typedef struct STableMergeScanExecInfo {
|
||||
SFileBlockLoadRecorder blockRecorder;
|
||||
|
@ -51,6 +52,16 @@ typedef struct STableMergeScanSortSourceParam {
|
|||
STsdbReader* dataReader;
|
||||
} STableMergeScanSortSourceParam;
|
||||
|
||||
typedef struct STableCountScanOperatorInfo {
|
||||
SReadHandle readHandle;
|
||||
SSDataBlock* pRes;
|
||||
|
||||
STableCountScanSupp supp;
|
||||
|
||||
int32_t currGrpIdx;
|
||||
SArray* stbUidList; // when group by db_name and/or stable_name
|
||||
} STableCountScanOperatorInfo;
|
||||
|
||||
static bool processBlockWithProbability(const SSampleExecInfo* pInfo);
|
||||
|
||||
bool processBlockWithProbability(const SSampleExecInfo* pInfo) {
|
||||
|
@ -320,7 +331,7 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanBase* pTableSca
|
|||
qDebug("%s data block skipped, brange:%" PRId64 "-%" PRId64 ", rows:%" PRId64 ", uid:%" PRIu64,
|
||||
GET_TASKID(pTaskInfo), pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows,
|
||||
pBlockInfo->id.uid);
|
||||
doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo, 1);
|
||||
doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo, pBlock->info.rows);
|
||||
pCost->skipBlocks += 1;
|
||||
tsdbReleaseDataBlock(pTableScanInfo->dataReader);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -331,7 +342,7 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanBase* pTableSca
|
|||
if (success) { // failed to load the block sma data, data block statistics does not exist, load data block instead
|
||||
qDebug("%s data block SMA loaded, brange:%" PRId64 "-%" PRId64 ", rows:%" PRId64, GET_TASKID(pTaskInfo),
|
||||
pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows);
|
||||
doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo, 1);
|
||||
doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo, pBlock->info.rows);
|
||||
tsdbReleaseDataBlock(pTableScanInfo->dataReader);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else {
|
||||
|
@ -698,9 +709,9 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
|
|||
// todo refactor
|
||||
/*pTableScanInfo->lastStatus.uid = pBlock->info.id.uid;*/
|
||||
/*pTableScanInfo->lastStatus.ts = pBlock->info.window.ekey;*/
|
||||
pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__SNAPSHOT_DATA;
|
||||
pTaskInfo->streamInfo.lastStatus.uid = pBlock->info.id.uid;
|
||||
pTaskInfo->streamInfo.lastStatus.ts = pBlock->info.window.ekey;
|
||||
// pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__SNAPSHOT_DATA;
|
||||
// pTaskInfo->streamInfo.lastStatus.uid = pBlock->info.id.uid;
|
||||
// pTaskInfo->streamInfo.lastStatus.ts = pBlock->info.window.ekey;
|
||||
|
||||
return pBlock;
|
||||
}
|
||||
|
@ -890,9 +901,11 @@ static void destroyTableScanOperatorInfo(void* param) {
|
|||
|
||||
SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* readHandle,
|
||||
STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo) {
|
||||
int32_t code = 0;
|
||||
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
if (pInfo == NULL || pOperator == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
|
@ -900,7 +913,7 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
|
|||
SDataBlockDescNode* pDescNode = pScanNode->node.pOutputDataBlockDesc;
|
||||
|
||||
int32_t numOfCols = 0;
|
||||
int32_t code =
|
||||
code =
|
||||
extractColMatchInfo(pScanNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, &pInfo->base.matchInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
@ -1601,18 +1614,16 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
|||
if (pTaskInfo->streamInfo.submit.msgStr != NULL) {
|
||||
if (pInfo->tqReader->msg2.msgStr == NULL) {
|
||||
SPackedData submit = pTaskInfo->streamInfo.submit;
|
||||
if (tqReaderSetSubmitReq2(pInfo->tqReader, submit.msgStr, submit.msgLen, submit.ver) < 0) {
|
||||
qError("submit msg messed up when initing stream submit block %p, %s", submit.msgStr, id);
|
||||
pInfo->tqReader->msg2 = (SPackedData){0};
|
||||
pInfo->tqReader->setMsg = 0;
|
||||
ASSERT(0);
|
||||
if (tqReaderSetSubmitMsg(pInfo->tqReader, submit.msgStr, submit.msgLen, submit.ver) < 0) {
|
||||
qError("submit msg messed up when initing stream submit block %p", submit.msgStr);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
blockDataCleanup(pInfo->pRes);
|
||||
SDataBlockInfo* pBlockInfo = &pInfo->pRes->info;
|
||||
|
||||
while (tqNextDataBlock2(pInfo->tqReader)) {
|
||||
while (tqNextDataBlock(pInfo->tqReader)) {
|
||||
SSDataBlock block = {0};
|
||||
|
||||
int32_t code = tqRetrieveDataBlock2(&block, pInfo->tqReader, NULL);
|
||||
|
@ -1628,73 +1639,54 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
pInfo->tqReader->msg2 = (SPackedData){0};
|
||||
pInfo->tqReader->setMsg = 0;
|
||||
pTaskInfo->streamInfo.submit = (SPackedData){0};
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
SSDataBlock* pResult = doTableScan(pInfo->pTableScanOp);
|
||||
if (pResult && pResult->info.rows > 0) {
|
||||
qDebug("queue scan tsdb return %" PRId64 " rows min:%" PRId64 " max:%" PRId64 " wal curVersion:%" PRId64 " %s",
|
||||
qDebug("queue scan tsdb return %" PRId64 " rows min:%" PRId64 " max:%" PRId64 " wal curVersion:%" PRId64,
|
||||
pResult->info.rows, pResult->info.window.skey, pResult->info.window.ekey,
|
||||
pInfo->tqReader->pWalReader->curVersion, id);
|
||||
pTaskInfo->streamInfo.returned = 1;
|
||||
pInfo->tqReader->pWalReader->curVersion);
|
||||
tqOffsetResetToData(&pTaskInfo->streamInfo.currentOffset, pResult->info.id.uid, pResult->info.window.ekey);
|
||||
return pResult;
|
||||
} else {
|
||||
// no data has return already, try to extract data in the WAL
|
||||
if (!pTaskInfo->streamInfo.returned) {
|
||||
STableScanInfo* pTSInfo = pInfo->pTableScanOp->info;
|
||||
tsdbReaderClose(pTSInfo->base.dataReader);
|
||||
pTSInfo->base.dataReader = NULL;
|
||||
tqOffsetResetToLog(&pTaskInfo->streamInfo.prepareStatus, pTaskInfo->streamInfo.snapshotVer);
|
||||
|
||||
qDebug("queue scan tsdb over, switch to wal ver:%" PRId64 " %s", pTaskInfo->streamInfo.snapshotVer + 1, id);
|
||||
if (tqSeekVer(pInfo->tqReader, pTaskInfo->streamInfo.snapshotVer + 1, pTaskInfo->id.str) < 0) {
|
||||
tqOffsetResetToLog(&pTaskInfo->streamInfo.lastStatus, pTaskInfo->streamInfo.snapshotVer);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
STableScanInfo* pTSInfo = pInfo->pTableScanOp->info;
|
||||
tsdbReaderClose(pTSInfo->base.dataReader);
|
||||
pTSInfo->base.dataReader = NULL;
|
||||
qDebug("queue scan tsdb over, switch to wal ver %" PRId64 "", pTaskInfo->streamInfo.snapshotVer + 1);
|
||||
if (tqSeekVer(pInfo->tqReader, pTaskInfo->streamInfo.snapshotVer + 1, pTaskInfo->id.str) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
tqOffsetResetToLog(&pTaskInfo->streamInfo.currentOffset, pTaskInfo->streamInfo.snapshotVer);
|
||||
}
|
||||
|
||||
if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__LOG) {
|
||||
if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__LOG) {
|
||||
while (1) {
|
||||
SFetchRet ret = {0};
|
||||
terrno = 0;
|
||||
|
||||
if (tqNextBlock(pInfo->tqReader, &ret) < 0) {
|
||||
// if the end is reached, terrno is 0
|
||||
if (terrno != 0) {
|
||||
qError("failed to get next log block since %s, %s", terrstr(), id);
|
||||
}
|
||||
}
|
||||
tqNextBlock(pInfo->tqReader, &ret);
|
||||
tqOffsetResetToLog(
|
||||
&pTaskInfo->streamInfo.currentOffset,
|
||||
pInfo->tqReader->pWalReader->curVersion - 1); // curVersion move to next, so currentOffset = curVersion - 1
|
||||
|
||||
if (ret.fetchType == FETCH_TYPE__DATA) {
|
||||
qDebug("doQueueScan get data from log %" PRId64 " rows, version:%" PRId64, ret.data.info.rows,
|
||||
pTaskInfo->streamInfo.currentOffset.version);
|
||||
blockDataCleanup(pInfo->pRes);
|
||||
setBlockIntoRes(pInfo, &ret.data, true);
|
||||
if (pInfo->pRes->info.rows > 0) {
|
||||
pOperator->status = OP_EXEC_RECV;
|
||||
qDebug("queue scan log return %" PRId64 " rows", pInfo->pRes->info.rows);
|
||||
qDebug("doQueueScan get data from log %" PRId64 " rows, return, version:%" PRId64, pInfo->pRes->info.rows,
|
||||
pTaskInfo->streamInfo.currentOffset.version);
|
||||
return pInfo->pRes;
|
||||
}
|
||||
} else if (ret.fetchType == FETCH_TYPE__META) {
|
||||
qError("unexpected ret.fetchType:%d", ret.fetchType);
|
||||
continue;
|
||||
} else if (ret.fetchType == FETCH_TYPE__NONE ||
|
||||
(ret.fetchType == FETCH_TYPE__SEP && pOperator->status == OP_EXEC_RECV)) {
|
||||
pTaskInfo->streamInfo.lastStatus = ret.offset;
|
||||
char formatBuf[80];
|
||||
tFormatOffset(formatBuf, 80, &ret.offset);
|
||||
qDebug("queue scan log return null, offset %s", formatBuf);
|
||||
pOperator->status = OP_OPENED;
|
||||
} else if (ret.fetchType == FETCH_TYPE__NONE) {
|
||||
qDebug("doQueueScan get none from log, return, version:%" PRId64, pTaskInfo->streamInfo.currentOffset.version);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qError("unexpected streamInfo prepare type: %d %s", pTaskInfo->streamInfo.prepareStatus.type, id);
|
||||
qError("unexpected streamInfo prepare type: %d", pTaskInfo->streamInfo.currentOffset.type);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -1780,7 +1772,7 @@ int32_t streamScanOperatorEncode(SStreamScanInfo* pInfo, void** pBuff) {
|
|||
|
||||
// other properties are recovered from the execution plan
|
||||
void streamScanOperatorDeocde(void* pBuff, int32_t len, SStreamScanInfo* pInfo) {
|
||||
if (!pBuff) {
|
||||
if (!pBuff || len == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1817,7 +1809,6 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
tsdbReaderClose(pTSInfo->base.dataReader);
|
||||
qDebug("4");
|
||||
|
||||
pTSInfo->base.dataReader = NULL;
|
||||
pInfo->pTableScanOp->status = OP_OPENED;
|
||||
|
@ -1898,7 +1889,6 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
|
|||
pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__NONE;
|
||||
STableScanInfo* pTSInfo = pInfo->pTableScanOp->info;
|
||||
tsdbReaderClose(pTSInfo->base.dataReader);
|
||||
qDebug("5");
|
||||
|
||||
pTSInfo->base.dataReader = NULL;
|
||||
|
||||
|
@ -1925,6 +1915,7 @@ FETCH_NEXT_BLOCK:
|
|||
if (pBlock->info.parTbName[0]) {
|
||||
streamStatePutParName(pTaskInfo->streamInfo.pState, pBlock->info.id.groupId, pBlock->info.parTbName);
|
||||
}
|
||||
|
||||
// TODO move into scan
|
||||
pBlock->info.calWin.skey = INT64_MIN;
|
||||
pBlock->info.calWin.ekey = INT64_MAX;
|
||||
|
@ -2064,17 +2055,18 @@ FETCH_NEXT_BLOCK:
|
|||
updateInfoDestoryColseWinSBF(pInfo->pUpdateInfo);
|
||||
doClearBufferedBlocks(pInfo);
|
||||
qDebug("stream scan return empty, consume block %d", totBlockNum);
|
||||
// void* buff = NULL;
|
||||
// int32_t len = streamScanOperatorEncode(pInfo, &buff);
|
||||
// todo(liuyao) save buff
|
||||
// taosMemoryFreeClear(buff);
|
||||
void* buff = NULL;
|
||||
int32_t len = streamScanOperatorEncode(pInfo, &buff);
|
||||
if (len > 0) {
|
||||
streamStateSaveInfo(pInfo->pState, STREAM_SCAN_OP_NAME, strlen(STREAM_SCAN_OP_NAME), buff, len);
|
||||
}
|
||||
taosMemoryFreeClear(buff);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t current = pInfo->validBlockIndex++;
|
||||
SPackedData* pSubmit = taosArrayGet(pInfo->pBlockLists, current);
|
||||
/*if (tqReaderSetDataMsg(pInfo->tqReader, pSubmit, 0) < 0) {*/
|
||||
if (tqReaderSetSubmitReq2(pInfo->tqReader, pSubmit->msgStr, pSubmit->msgLen, pSubmit->ver) < 0) {
|
||||
if (tqReaderSetSubmitMsg(pInfo->tqReader, pSubmit->msgStr, pSubmit->msgLen, pSubmit->ver) < 0) {
|
||||
qError("submit msg messed up when initing stream submit block %p, current %d, total %d", pSubmit, current,
|
||||
totBlockNum);
|
||||
continue;
|
||||
|
@ -2083,7 +2075,7 @@ FETCH_NEXT_BLOCK:
|
|||
|
||||
blockDataCleanup(pInfo->pRes);
|
||||
|
||||
while (tqNextDataBlock2(pInfo->tqReader)) {
|
||||
while (tqNextDataBlock(pInfo->tqReader)) {
|
||||
SSDataBlock block = {0};
|
||||
|
||||
int32_t code = tqRetrieveDataBlock2(&block, pInfo->tqReader, NULL);
|
||||
|
@ -2158,7 +2150,7 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
|||
pTaskInfo->streamInfo.metaRsp.metaRsp = NULL;
|
||||
|
||||
qDebug("tmqsnap doRawScan called");
|
||||
if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
||||
bool hasNext = false;
|
||||
if (pInfo->dataReader) {
|
||||
code = tsdbNextDataBlock(pInfo->dataReader, &hasNext);
|
||||
|
@ -2180,28 +2172,23 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
qDebug("tmqsnap doRawScan get data uid:%" PRId64 "", pBlock->info.id.uid);
|
||||
pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__SNAPSHOT_DATA;
|
||||
pTaskInfo->streamInfo.lastStatus.uid = pBlock->info.id.uid;
|
||||
pTaskInfo->streamInfo.lastStatus.ts = pBlock->info.window.ekey;
|
||||
tqOffsetResetToData(&pTaskInfo->streamInfo.currentOffset, pBlock->info.id.uid, pBlock->info.window.ekey);
|
||||
return pBlock;
|
||||
}
|
||||
|
||||
SMetaTableInfo mtInfo = getUidfromSnapShot(pInfo->sContext);
|
||||
STqOffsetVal offset = {0};
|
||||
if (mtInfo.uid == 0) { // read snapshot done, change to get data from wal
|
||||
qDebug("tmqsnap read snapshot done, change to get data from wal");
|
||||
pTaskInfo->streamInfo.prepareStatus.uid = mtInfo.uid;
|
||||
pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__LOG;
|
||||
pTaskInfo->streamInfo.lastStatus.version = pInfo->sContext->snapVersion;
|
||||
tqOffsetResetToLog(&offset, pInfo->sContext->snapVersion);
|
||||
} else {
|
||||
pTaskInfo->streamInfo.prepareStatus.uid = mtInfo.uid;
|
||||
pTaskInfo->streamInfo.prepareStatus.ts = INT64_MIN;
|
||||
tqOffsetResetToData(&offset, mtInfo.uid, INT64_MIN);
|
||||
qDebug("tmqsnap change get data uid:%" PRId64 "", mtInfo.uid);
|
||||
qStreamPrepareScan(pTaskInfo, &pTaskInfo->streamInfo.prepareStatus, pInfo->sContext->subType);
|
||||
}
|
||||
qStreamPrepareScan(pTaskInfo, &offset, pInfo->sContext->subType);
|
||||
tDeleteSSchemaWrapper(mtInfo.schema);
|
||||
qDebug("tmqsnap stream scan tsdb return null");
|
||||
return NULL;
|
||||
} else if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_META) {
|
||||
} else if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__SNAPSHOT_META) {
|
||||
SSnapContext* sContext = pInfo->sContext;
|
||||
void* data = NULL;
|
||||
int32_t dataLen = 0;
|
||||
|
@ -2213,16 +2200,12 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!sContext->queryMetaOrData) { // change to get data next poll request
|
||||
pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__SNAPSHOT_META;
|
||||
pTaskInfo->streamInfo.lastStatus.uid = uid;
|
||||
pTaskInfo->streamInfo.metaRsp.rspOffset.type = TMQ_OFFSET__SNAPSHOT_DATA;
|
||||
pTaskInfo->streamInfo.metaRsp.rspOffset.uid = 0;
|
||||
pTaskInfo->streamInfo.metaRsp.rspOffset.ts = INT64_MIN;
|
||||
if (!sContext->queryMeta) { // change to get data next poll request
|
||||
STqOffsetVal offset = {0};
|
||||
tqOffsetResetToData(&offset, 0, INT64_MIN);
|
||||
qStreamPrepareScan(pTaskInfo, &offset, pInfo->sContext->subType);
|
||||
} else {
|
||||
pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__SNAPSHOT_META;
|
||||
pTaskInfo->streamInfo.lastStatus.uid = uid;
|
||||
pTaskInfo->streamInfo.metaRsp.rspOffset = pTaskInfo->streamInfo.lastStatus;
|
||||
tqOffsetResetToMeta(&pTaskInfo->streamInfo.currentOffset, uid);
|
||||
pTaskInfo->streamInfo.metaRsp.resMsgType = type;
|
||||
pTaskInfo->streamInfo.metaRsp.metaRspLen = dataLen;
|
||||
pTaskInfo->streamInfo.metaRsp.metaRsp = data;
|
||||
|
@ -2436,7 +2419,6 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
|||
if (pHandle->initTableReader) {
|
||||
pTSInfo->scanMode = TABLE_SCAN__TABLE_ORDER;
|
||||
pTSInfo->base.dataReader = NULL;
|
||||
pTaskInfo->streamInfo.lastStatus.uid = -1;
|
||||
}
|
||||
|
||||
if (pHandle->initTqReader) {
|
||||
|
@ -2505,12 +2487,12 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
|||
pInfo->twAggSup.maxTs = INT64_MIN;
|
||||
pInfo->pState = NULL;
|
||||
|
||||
// todo(liuyao) get buff from rocks db;
|
||||
void* buff = NULL;
|
||||
int32_t len = 0;
|
||||
streamStateGetInfo(pTaskInfo->streamInfo.pState, STREAM_SCAN_OP_NAME, strlen(STREAM_SCAN_OP_NAME), &buff, &len);
|
||||
streamScanOperatorDeocde(buff, len, pInfo);
|
||||
|
||||
setOperatorInfo(pOperator, "StreamScanOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, false, OP_NOT_OPENED, pInfo,
|
||||
setOperatorInfo(pOperator, STREAM_SCAN_OP_NAME, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, false, OP_NOT_OPENED, pInfo,
|
||||
pTaskInfo);
|
||||
pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock);
|
||||
|
||||
|
|
|
@ -2846,6 +2846,7 @@ void initDownStream(SOperatorInfo* downstream, SStreamAggSupporter* pAggSup, uin
|
|||
}
|
||||
SStreamScanInfo* pScanInfo = downstream->info;
|
||||
pScanInfo->windowSup = (SWindowSupporter){.pStreamAggSup = pAggSup, .gap = pAggSup->gap, .parentType = type};
|
||||
pScanInfo->pState = pAggSup->pState;
|
||||
if (!pScanInfo->igCheckUpdate && !pScanInfo->pUpdateInfo) {
|
||||
pScanInfo->pUpdateInfo = updateInfoInit(60000, TSDB_TIME_PRECISION_MILLI, pTwSup->waterMark);
|
||||
}
|
||||
|
@ -4745,6 +4746,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
|
|||
if (!pInfo->pUpdated) {
|
||||
pInfo->pUpdated = taosArrayInit(4096, POINTER_BYTES);
|
||||
}
|
||||
|
||||
if (!pInfo->pUpdatedMap) {
|
||||
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
|
||||
pInfo->pUpdatedMap = tSimpleHashInit(4096, hashFn);
|
||||
|
@ -4757,6 +4759,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
|
|||
pInfo->numOfDatapack = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
pInfo->numOfDatapack++;
|
||||
printDataBlock(pBlock, "single interval recv");
|
||||
|
||||
|
|
|
@ -3353,7 +3353,7 @@ int32_t spreadFunction(SqlFunctionCtx* pCtx) {
|
|||
goto _spread_over;
|
||||
}
|
||||
double tmin = 0.0, tmax = 0.0;
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type) || IS_TIMESTAMP_TYPE(type)) {
|
||||
tmin = (double)GET_INT64_VAL(&pAgg->min);
|
||||
tmax = (double)GET_INT64_VAL(&pAgg->max);
|
||||
} else if (IS_FLOAT_TYPE(type)) {
|
||||
|
|
|
@ -24,7 +24,7 @@ DLL_EXPORT int32_t udf1(SUdfDataBlock *block, SUdfColumn *resultCol) {
|
|||
}
|
||||
}
|
||||
if (j == block->numOfCols) {
|
||||
int32_t luckyNum = 88;
|
||||
int32_t luckyNum = 1;
|
||||
udfColDataSet(resultCol, i, (char *)&luckyNum, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -925,6 +925,7 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
taosMemoryFree(((SDescribeStmt*)pNode)->pMeta);
|
||||
break;
|
||||
case QUERY_NODE_RESET_QUERY_CACHE_STMT: // no pointer field
|
||||
break;
|
||||
case QUERY_NODE_COMPACT_DATABASE_STMT: {
|
||||
SCompactDatabaseStmt* pStmt = (SCompactDatabaseStmt*)pNode;
|
||||
nodesDestroyNode(pStmt->pStart);
|
||||
|
@ -942,10 +943,10 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
nodesDestroyNode(pStmt->pSubtable);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_DROP_STREAM_STMT: // no pointer field
|
||||
case QUERY_NODE_BALANCE_VGROUP_STMT: // no pointer field
|
||||
case QUERY_NODE_DROP_STREAM_STMT: // no pointer field
|
||||
case QUERY_NODE_BALANCE_VGROUP_STMT: // no pointer field
|
||||
case QUERY_NODE_BALANCE_VGROUP_LEADER_STMT: // no pointer field
|
||||
case QUERY_NODE_MERGE_VGROUP_STMT: // no pointer field
|
||||
case QUERY_NODE_MERGE_VGROUP_STMT: // no pointer field
|
||||
break;
|
||||
case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT:
|
||||
nodesDestroyList(((SRedistributeVgroupStmt*)pNode)->pDnodes);
|
||||
|
|
|
@ -82,6 +82,11 @@ typedef struct SAlterOption {
|
|||
SNodeList* pList;
|
||||
} SAlterOption;
|
||||
|
||||
typedef struct STokenPair {
|
||||
SToken first;
|
||||
SToken second;
|
||||
} STokenPair;
|
||||
|
||||
extern SToken nil_token;
|
||||
|
||||
void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt);
|
||||
|
@ -229,8 +234,10 @@ SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, cons
|
|||
SNode* createRedistributeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId, SNodeList* pDnodes);
|
||||
SNode* createSplitVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId);
|
||||
SNode* createSyncdbStmt(SAstCreateContext* pCxt, const SToken* pDbName);
|
||||
SNode* createGrantStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbName, SToken* pUserName);
|
||||
SNode* createRevokeStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbName, SToken* pUserName);
|
||||
SNode* createGrantStmt(SAstCreateContext* pCxt, int64_t privileges, STokenPair* pPrivLevel, SToken* pUserName,
|
||||
SNode* pTagCond);
|
||||
SNode* createRevokeStmt(SAstCreateContext* pCxt, int64_t privileges, STokenPair* pPrivLevel, SToken* pUserName,
|
||||
SNode* pTagCond);
|
||||
SNode* createDeleteStmt(SAstCreateContext* pCxt, SNode* pTable, SNode* pWhere);
|
||||
SNode* createInsertStmt(SAstCreateContext* pCxt, SNode* pTable, SNodeList* pCols, SNode* pQuery);
|
||||
|
||||
|
|
|
@ -97,9 +97,8 @@ int32_t reserveTableVgroupInCache(int32_t acctId, const char* pDb, const char* p
|
|||
int32_t reserveTableVgroupInCacheExt(const SName* pName, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveDbVgVersionInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveDbCfgInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, AUTH_TYPE type,
|
||||
int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
|
||||
SParseMetaCache* pMetaCache);
|
||||
int32_t reserveUserAuthInCacheExt(const char* pUser, const SName* pName, AUTH_TYPE type, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveUdfInCache(const char* pFunc, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveTableIndexInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveTableCfgInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
|
||||
|
@ -110,8 +109,7 @@ int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName,
|
|||
int32_t getDbVgVersionFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, int32_t* pVersion, int64_t* pDbId,
|
||||
int32_t* pTableNum, int64_t* pStateTs);
|
||||
int32_t getDbCfgFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SDbCfgInfo* pInfo);
|
||||
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, const char* pUser, const char* pDbFName, AUTH_TYPE type,
|
||||
bool* pPass);
|
||||
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, SUserAuthInfo* pAuthReq, SUserAuthRes* pAuthRes);
|
||||
int32_t getUdfInfoFromCache(SParseMetaCache* pMetaCache, const char* pFunc, SFuncInfo* pInfo);
|
||||
int32_t getTableIndexFromCache(SParseMetaCache* pMetaCache, const SName* pName, SArray** pIndexes);
|
||||
int32_t getTableCfgFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableCfg** pOutput);
|
||||
|
|
|
@ -94,8 +94,8 @@ sysinfo_opt(A) ::= .
|
|||
sysinfo_opt(A) ::= SYSINFO NK_INTEGER(B). { A = taosStr2Int8(B.z, NULL, 10); }
|
||||
|
||||
/************************************************ grant/revoke ********************************************************/
|
||||
cmd ::= GRANT privileges(A) ON priv_level(B) TO user_name(C). { pCxt->pRootNode = createGrantStmt(pCxt, A, &B, &C); }
|
||||
cmd ::= REVOKE privileges(A) ON priv_level(B) FROM user_name(C). { pCxt->pRootNode = createRevokeStmt(pCxt, A, &B, &C); }
|
||||
cmd ::= GRANT privileges(A) ON priv_level(B) with_opt(D) TO user_name(C). { pCxt->pRootNode = createGrantStmt(pCxt, A, &B, &C, D); }
|
||||
cmd ::= REVOKE privileges(A) ON priv_level(B) with_opt(D) FROM user_name(C). { pCxt->pRootNode = createRevokeStmt(pCxt, A, &B, &C, D); }
|
||||
|
||||
%type privileges { int64_t }
|
||||
%destructor privileges { }
|
||||
|
@ -113,11 +113,15 @@ priv_type_list(A) ::= priv_type_list(B) NK_COMMA priv_type(C).
|
|||
priv_type(A) ::= READ. { A = PRIVILEGE_TYPE_READ; }
|
||||
priv_type(A) ::= WRITE. { A = PRIVILEGE_TYPE_WRITE; }
|
||||
|
||||
%type priv_level { SToken }
|
||||
%type priv_level { STokenPair }
|
||||
%destructor priv_level { }
|
||||
priv_level(A) ::= NK_STAR(B) NK_DOT NK_STAR. { A = B; }
|
||||
priv_level(A) ::= db_name(B) NK_DOT NK_STAR. { A = B; }
|
||||
priv_level(A) ::= topic_name(B). { A = B; }
|
||||
priv_level(A) ::= NK_STAR(B) NK_DOT NK_STAR(C). { A.first = B; A.second = C; }
|
||||
priv_level(A) ::= db_name(B) NK_DOT NK_STAR(C). { A.first = B; A.second = C; }
|
||||
priv_level(A) ::= db_name(B) NK_DOT table_name(C). { A.first = B; A.second = C; }
|
||||
priv_level(A) ::= topic_name(B). { A.first = B; A.second = nil_token; }
|
||||
|
||||
with_opt(A) ::= . { A = NULL; }
|
||||
with_opt(A) ::= WITH search_condition(B). { A = B; }
|
||||
|
||||
/************************************************ create/drop/alter dnode *********************************************/
|
||||
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); }
|
||||
|
@ -342,7 +346,7 @@ column_def_list(A) ::= column_def(B).
|
|||
column_def_list(A) ::= column_def_list(B) NK_COMMA column_def(C). { A = addNodeToList(pCxt, B, C); }
|
||||
|
||||
column_def(A) ::= column_name(B) type_name(C). { A = createColumnDefNode(pCxt, &B, C, NULL); }
|
||||
column_def(A) ::= column_name(B) type_name(C) COMMENT NK_STRING(D). { A = createColumnDefNode(pCxt, &B, C, &D); }
|
||||
//column_def(A) ::= column_name(B) type_name(C) COMMENT NK_STRING(D). { A = createColumnDefNode(pCxt, &B, C, &D); }
|
||||
|
||||
%type type_name { SDataType }
|
||||
%destructor type_name { }
|
||||
|
|
|
@ -1994,29 +1994,39 @@ SNode* createSyncdbStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
|
|||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createGrantStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbName, SToken* pUserName) {
|
||||
SNode* createGrantStmt(SAstCreateContext* pCxt, int64_t privileges, STokenPair* pPrivLevel, SToken* pUserName,
|
||||
SNode* pTagCond) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkDbName(pCxt, pDbName, false) || !checkUserName(pCxt, pUserName)) {
|
||||
if (!checkDbName(pCxt, &pPrivLevel->first, false) || !checkUserName(pCxt, pUserName)) {
|
||||
return NULL;
|
||||
}
|
||||
SGrantStmt* pStmt = (SGrantStmt*)nodesMakeNode(QUERY_NODE_GRANT_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->privileges = privileges;
|
||||
COPY_STRING_FORM_ID_TOKEN(pStmt->objName, pDbName);
|
||||
COPY_STRING_FORM_ID_TOKEN(pStmt->objName, &pPrivLevel->first);
|
||||
if (TK_NK_NIL != pPrivLevel->second.type && TK_NK_STAR != pPrivLevel->second.type) {
|
||||
COPY_STRING_FORM_ID_TOKEN(pStmt->tabName, &pPrivLevel->second);
|
||||
}
|
||||
COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName);
|
||||
pStmt->pTagCond = pTagCond;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createRevokeStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbName, SToken* pUserName) {
|
||||
SNode* createRevokeStmt(SAstCreateContext* pCxt, int64_t privileges, STokenPair* pPrivLevel, SToken* pUserName,
|
||||
SNode* pTagCond) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkDbName(pCxt, pDbName, false) || !checkUserName(pCxt, pUserName)) {
|
||||
if (!checkDbName(pCxt, &pPrivLevel->first, false) || !checkUserName(pCxt, pUserName)) {
|
||||
return NULL;
|
||||
}
|
||||
SRevokeStmt* pStmt = (SRevokeStmt*)nodesMakeNode(QUERY_NODE_REVOKE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->privileges = privileges;
|
||||
COPY_STRING_FORM_ID_TOKEN(pStmt->objName, pDbName);
|
||||
COPY_STRING_FORM_ID_TOKEN(pStmt->objName, &pPrivLevel->first);
|
||||
if (TK_NK_NIL != pPrivLevel->second.type && TK_NK_STAR != pPrivLevel->second.type) {
|
||||
COPY_STRING_FORM_ID_TOKEN(pStmt->tabName, &pPrivLevel->second);
|
||||
}
|
||||
COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName);
|
||||
pStmt->pTagCond = pTagCond;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue