merge main
This commit is contained in:
commit
4c04b155d5
|
@ -208,15 +208,12 @@ typedef struct SSDataBlock {
|
||||||
} SSDataBlock;
|
} SSDataBlock;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
FETCH_TYPE__DATA = 1,
|
FETCH_TYPE__DATA = 0,
|
||||||
FETCH_TYPE__META,
|
|
||||||
FETCH_TYPE__SEP,
|
|
||||||
FETCH_TYPE__NONE,
|
FETCH_TYPE__NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t fetchType;
|
int8_t fetchType;
|
||||||
STqOffsetVal offset;
|
|
||||||
union {
|
union {
|
||||||
SSDataBlock data;
|
SSDataBlock data;
|
||||||
void* meta;
|
void* meta;
|
||||||
|
|
|
@ -104,6 +104,7 @@ extern int32_t tsCacheLazyLoadThreshold; // cost threshold for last/last_row lo
|
||||||
// query client
|
// query client
|
||||||
extern int32_t tsQueryPolicy;
|
extern int32_t tsQueryPolicy;
|
||||||
extern int32_t tsQueryRspPolicy;
|
extern int32_t tsQueryRspPolicy;
|
||||||
|
extern int64_t tsQueryMaxConcurrentTables;
|
||||||
extern int32_t tsQuerySmaOptimize;
|
extern int32_t tsQuerySmaOptimize;
|
||||||
extern int32_t tsQueryRsmaTolerance;
|
extern int32_t tsQueryRsmaTolerance;
|
||||||
extern bool tsQueryPlannerTrace;
|
extern bool tsQueryPlannerTrace;
|
||||||
|
|
|
@ -177,6 +177,12 @@ typedef enum _mgmt_table {
|
||||||
#define TSDB_ALTER_USER_SYSINFO 0xA
|
#define TSDB_ALTER_USER_SYSINFO 0xA
|
||||||
#define TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC 0xB
|
#define TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC 0xB
|
||||||
#define TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC 0xC
|
#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
|
#define TSDB_ALTER_USER_PRIVILEGES 0x2
|
||||||
|
|
||||||
|
@ -676,6 +682,9 @@ typedef struct {
|
||||||
char user[TSDB_USER_LEN];
|
char user[TSDB_USER_LEN];
|
||||||
char pass[TSDB_USET_PASSWORD_LEN];
|
char pass[TSDB_USET_PASSWORD_LEN];
|
||||||
char objname[TSDB_DB_FNAME_LEN]; // db or topic
|
char objname[TSDB_DB_FNAME_LEN]; // db or topic
|
||||||
|
char tabName[TSDB_TABLE_NAME_LEN];
|
||||||
|
char* tagCond;
|
||||||
|
int32_t tagCondLen;
|
||||||
} SAlterUserReq;
|
} SAlterUserReq;
|
||||||
|
|
||||||
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
|
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
|
||||||
|
@ -698,6 +707,9 @@ typedef struct {
|
||||||
SHashObj* createdDbs;
|
SHashObj* createdDbs;
|
||||||
SHashObj* readDbs;
|
SHashObj* readDbs;
|
||||||
SHashObj* writeDbs;
|
SHashObj* writeDbs;
|
||||||
|
SHashObj* readTbs;
|
||||||
|
SHashObj* writeTbs;
|
||||||
|
SHashObj* useDbs;
|
||||||
} SGetUserAuthRsp;
|
} SGetUserAuthRsp;
|
||||||
|
|
||||||
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
|
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
|
||||||
|
|
|
@ -63,55 +63,55 @@
|
||||||
#define TK_READ 45
|
#define TK_READ 45
|
||||||
#define TK_WRITE 46
|
#define TK_WRITE 46
|
||||||
#define TK_NK_DOT 47
|
#define TK_NK_DOT 47
|
||||||
#define TK_DNODE 48
|
#define TK_WITH 48
|
||||||
#define TK_PORT 49
|
#define TK_DNODE 49
|
||||||
#define TK_DNODES 50
|
#define TK_PORT 50
|
||||||
#define TK_NK_IPTOKEN 51
|
#define TK_DNODES 51
|
||||||
#define TK_FORCE 52
|
#define TK_NK_IPTOKEN 52
|
||||||
#define TK_LOCAL 53
|
#define TK_FORCE 53
|
||||||
#define TK_QNODE 54
|
#define TK_LOCAL 54
|
||||||
#define TK_BNODE 55
|
#define TK_QNODE 55
|
||||||
#define TK_SNODE 56
|
#define TK_BNODE 56
|
||||||
#define TK_MNODE 57
|
#define TK_SNODE 57
|
||||||
#define TK_DATABASE 58
|
#define TK_MNODE 58
|
||||||
#define TK_USE 59
|
#define TK_DATABASE 59
|
||||||
#define TK_FLUSH 60
|
#define TK_USE 60
|
||||||
#define TK_TRIM 61
|
#define TK_FLUSH 61
|
||||||
#define TK_COMPACT 62
|
#define TK_TRIM 62
|
||||||
#define TK_IF 63
|
#define TK_COMPACT 63
|
||||||
#define TK_NOT 64
|
#define TK_IF 64
|
||||||
#define TK_EXISTS 65
|
#define TK_NOT 65
|
||||||
#define TK_BUFFER 66
|
#define TK_EXISTS 66
|
||||||
#define TK_CACHEMODEL 67
|
#define TK_BUFFER 67
|
||||||
#define TK_CACHESIZE 68
|
#define TK_CACHEMODEL 68
|
||||||
#define TK_COMP 69
|
#define TK_CACHESIZE 69
|
||||||
#define TK_DURATION 70
|
#define TK_COMP 70
|
||||||
#define TK_NK_VARIABLE 71
|
#define TK_DURATION 71
|
||||||
#define TK_MAXROWS 72
|
#define TK_NK_VARIABLE 72
|
||||||
#define TK_MINROWS 73
|
#define TK_MAXROWS 73
|
||||||
#define TK_KEEP 74
|
#define TK_MINROWS 74
|
||||||
#define TK_PAGES 75
|
#define TK_KEEP 75
|
||||||
#define TK_PAGESIZE 76
|
#define TK_PAGES 76
|
||||||
#define TK_TSDB_PAGESIZE 77
|
#define TK_PAGESIZE 77
|
||||||
#define TK_PRECISION 78
|
#define TK_TSDB_PAGESIZE 78
|
||||||
#define TK_REPLICA 79
|
#define TK_PRECISION 79
|
||||||
#define TK_VGROUPS 80
|
#define TK_REPLICA 80
|
||||||
#define TK_SINGLE_STABLE 81
|
#define TK_VGROUPS 81
|
||||||
#define TK_RETENTIONS 82
|
#define TK_SINGLE_STABLE 82
|
||||||
#define TK_SCHEMALESS 83
|
#define TK_RETENTIONS 83
|
||||||
#define TK_WAL_LEVEL 84
|
#define TK_SCHEMALESS 84
|
||||||
#define TK_WAL_FSYNC_PERIOD 85
|
#define TK_WAL_LEVEL 85
|
||||||
#define TK_WAL_RETENTION_PERIOD 86
|
#define TK_WAL_FSYNC_PERIOD 86
|
||||||
#define TK_WAL_RETENTION_SIZE 87
|
#define TK_WAL_RETENTION_PERIOD 87
|
||||||
#define TK_WAL_ROLL_PERIOD 88
|
#define TK_WAL_RETENTION_SIZE 88
|
||||||
#define TK_WAL_SEGMENT_SIZE 89
|
#define TK_WAL_ROLL_PERIOD 89
|
||||||
#define TK_STT_TRIGGER 90
|
#define TK_WAL_SEGMENT_SIZE 90
|
||||||
#define TK_TABLE_PREFIX 91
|
#define TK_STT_TRIGGER 91
|
||||||
#define TK_TABLE_SUFFIX 92
|
#define TK_TABLE_PREFIX 92
|
||||||
#define TK_NK_COLON 93
|
#define TK_TABLE_SUFFIX 93
|
||||||
#define TK_MAX_SPEED 94
|
#define TK_NK_COLON 94
|
||||||
#define TK_START 95
|
#define TK_MAX_SPEED 95
|
||||||
#define TK_WITH 96
|
#define TK_START 96
|
||||||
#define TK_TIMESTAMP 97
|
#define TK_TIMESTAMP 97
|
||||||
#define TK_END 98
|
#define TK_END 98
|
||||||
#define TK_TABLE 99
|
#define TK_TABLE 99
|
||||||
|
@ -127,24 +127,24 @@
|
||||||
#define TK_NK_EQ 109
|
#define TK_NK_EQ 109
|
||||||
#define TK_USING 110
|
#define TK_USING 110
|
||||||
#define TK_TAGS 111
|
#define TK_TAGS 111
|
||||||
#define TK_COMMENT 112
|
#define TK_BOOL 112
|
||||||
#define TK_BOOL 113
|
#define TK_TINYINT 113
|
||||||
#define TK_TINYINT 114
|
#define TK_SMALLINT 114
|
||||||
#define TK_SMALLINT 115
|
#define TK_INT 115
|
||||||
#define TK_INT 116
|
#define TK_INTEGER 116
|
||||||
#define TK_INTEGER 117
|
#define TK_BIGINT 117
|
||||||
#define TK_BIGINT 118
|
#define TK_FLOAT 118
|
||||||
#define TK_FLOAT 119
|
#define TK_DOUBLE 119
|
||||||
#define TK_DOUBLE 120
|
#define TK_BINARY 120
|
||||||
#define TK_BINARY 121
|
#define TK_NCHAR 121
|
||||||
#define TK_NCHAR 122
|
#define TK_UNSIGNED 122
|
||||||
#define TK_UNSIGNED 123
|
#define TK_JSON 123
|
||||||
#define TK_JSON 124
|
#define TK_VARCHAR 124
|
||||||
#define TK_VARCHAR 125
|
#define TK_MEDIUMBLOB 125
|
||||||
#define TK_MEDIUMBLOB 126
|
#define TK_BLOB 126
|
||||||
#define TK_BLOB 127
|
#define TK_VARBINARY 127
|
||||||
#define TK_VARBINARY 128
|
#define TK_DECIMAL 128
|
||||||
#define TK_DECIMAL 129
|
#define TK_COMMENT 129
|
||||||
#define TK_MAX_DELAY 130
|
#define TK_MAX_DELAY 130
|
||||||
#define TK_WATERMARK 131
|
#define TK_WATERMARK 131
|
||||||
#define TK_ROLLUP 132
|
#define TK_ROLLUP 132
|
||||||
|
|
|
@ -29,6 +29,7 @@ extern "C" {
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
#include "tname.h"
|
#include "tname.h"
|
||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
|
#include "nodes.h"
|
||||||
|
|
||||||
typedef struct SCatalog SCatalog;
|
typedef struct SCatalog SCatalog;
|
||||||
|
|
||||||
|
@ -49,10 +50,15 @@ typedef enum {
|
||||||
|
|
||||||
typedef struct SUserAuthInfo {
|
typedef struct SUserAuthInfo {
|
||||||
char user[TSDB_USER_LEN];
|
char user[TSDB_USER_LEN];
|
||||||
char dbFName[TSDB_DB_FNAME_LEN];
|
SName tbName;
|
||||||
AUTH_TYPE type;
|
AUTH_TYPE type;
|
||||||
} SUserAuthInfo;
|
} SUserAuthInfo;
|
||||||
|
|
||||||
|
typedef struct SUserAuthRes {
|
||||||
|
bool pass;
|
||||||
|
SNode* pCond;
|
||||||
|
} SUserAuthRes;
|
||||||
|
|
||||||
typedef struct SDbInfo {
|
typedef struct SDbInfo {
|
||||||
int32_t vgVer;
|
int32_t vgVer;
|
||||||
int32_t tbNum;
|
int32_t tbNum;
|
||||||
|
@ -96,7 +102,7 @@ typedef struct SMetaData {
|
||||||
SArray* pTableIndex; // pRes = SArray<STableIndexInfo>*
|
SArray* pTableIndex; // pRes = SArray<STableIndexInfo>*
|
||||||
SArray* pUdfList; // pRes = SFuncInfo*
|
SArray* pUdfList; // pRes = SFuncInfo*
|
||||||
SArray* pIndex; // pRes = SIndexInfo*
|
SArray* pIndex; // pRes = SIndexInfo*
|
||||||
SArray* pUser; // pRes = bool*
|
SArray* pUser; // pRes = SUserAuthRes*
|
||||||
SArray* pQnodeList; // pRes = SArray<SQueryNodeLoad>*
|
SArray* pQnodeList; // pRes = SArray<SQueryNodeLoad>*
|
||||||
SArray* pTableCfg; // pRes = STableCfg*
|
SArray* pTableCfg; // pRes = STableCfg*
|
||||||
SArray* pDnodeList; // pRes = SArray<SEpSet>*
|
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 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,
|
int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, SUserAuthInfo *pAuth, SUserAuthRes* pRes);
|
||||||
bool* pass);
|
|
||||||
|
|
||||||
int32_t catalogChkAuthFromCache(SCatalog* pCtg, const char* user, const char* dbFName, AUTH_TYPE type, bool* pass,
|
int32_t catalogChkAuthFromCache(SCatalog* pCtg, SUserAuthInfo *pAuth, SUserAuthRes* pRes, bool* exists);
|
||||||
bool* exists);
|
|
||||||
|
|
||||||
int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth);
|
int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth);
|
||||||
|
|
||||||
|
|
|
@ -199,12 +199,12 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
||||||
//
|
//
|
||||||
int32_t qStreamSetScanMemData(qTaskInfo_t tinfo, SPackedData submit);
|
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);
|
SMqMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo);
|
||||||
|
|
||||||
int64_t qStreamExtractPrepareUid(qTaskInfo_t tinfo);
|
|
||||||
|
|
||||||
const SSchemaWrapper* qExtractSchemaFromTask(qTaskInfo_t tinfo);
|
const SSchemaWrapper* qExtractSchemaFromTask(qTaskInfo_t tinfo);
|
||||||
|
|
||||||
const char* qExtractTbnameFromTask(qTaskInfo_t tinfo);
|
const char* qExtractTbnameFromTask(qTaskInfo_t tinfo);
|
||||||
|
|
|
@ -458,7 +458,9 @@ typedef struct SGrantStmt {
|
||||||
ENodeType type;
|
ENodeType type;
|
||||||
char userName[TSDB_USER_LEN];
|
char userName[TSDB_USER_LEN];
|
||||||
char objName[TSDB_DB_NAME_LEN]; // db or topic
|
char objName[TSDB_DB_NAME_LEN]; // db or topic
|
||||||
|
char tabName[TSDB_TABLE_NAME_LEN];
|
||||||
int64_t privileges;
|
int64_t privileges;
|
||||||
|
SNode* pTagCond;
|
||||||
} SGrantStmt;
|
} SGrantStmt;
|
||||||
|
|
||||||
typedef SGrantStmt SRevokeStmt;
|
typedef SGrantStmt SRevokeStmt;
|
||||||
|
|
|
@ -298,6 +298,7 @@ typedef struct SSelectStmt {
|
||||||
bool hasUniqueFunc;
|
bool hasUniqueFunc;
|
||||||
bool hasTailFunc;
|
bool hasTailFunc;
|
||||||
bool hasInterpFunc;
|
bool hasInterpFunc;
|
||||||
|
bool hasInterpPseudoColFunc;
|
||||||
bool hasLastRowFunc;
|
bool hasLastRowFunc;
|
||||||
bool hasLastFunc;
|
bool hasLastFunc;
|
||||||
bool hasTimeLineFunc;
|
bool hasTimeLineFunc;
|
||||||
|
|
|
@ -223,27 +223,12 @@ static FORCE_INLINE void* streamQueueCurItem(SStreamQueue* queue) {
|
||||||
return queue->qItem;
|
return queue->qItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void* streamQueueNextItem(SStreamQueue* queue) {
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SStreamDataSubmit2* streamDataSubmitNew(SPackedData submit);
|
SStreamDataSubmit2* streamDataSubmitNew(SPackedData submit);
|
||||||
|
void streamDataSubmitDestroy(SStreamDataSubmit2* pDataSubmit);
|
||||||
|
|
||||||
void streamDataSubmitRefDec(SStreamDataSubmit2* pDataSubmit);
|
SStreamDataSubmit2* streamSubmitBlockClone(SStreamDataSubmit2* pSubmit);
|
||||||
|
|
||||||
SStreamDataSubmit2* streamSubmitRefClone(SStreamDataSubmit2* pSubmit);
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char* qmsg;
|
char* qmsg;
|
||||||
|
@ -371,43 +356,7 @@ SStreamTask* tNewSStreamTask(int64_t streamId);
|
||||||
int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask);
|
int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask);
|
||||||
int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask);
|
int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask);
|
||||||
void tFreeSStreamTask(SStreamTask* pTask);
|
void tFreeSStreamTask(SStreamTask* pTask);
|
||||||
|
int32_t tAppendDataForStream(SStreamTask* pTask, SStreamQueueItem* pItem);
|
||||||
static FORCE_INLINE int32_t streamTaskInput(SStreamTask* pTask, SStreamQueueItem* pItem) {
|
|
||||||
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);
|
|
||||||
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) {
|
|
||||||
taosWriteQitem(pTask->inputQueue->queue, pItem);
|
|
||||||
// qStreamInput(pTask->exec.executor, pItem);
|
|
||||||
} else if (type == STREAM_INPUT__CHECKPOINT) {
|
|
||||||
taosWriteQitem(pTask->inputQueue->queue, pItem);
|
|
||||||
// qStreamInput(pTask->exec.executor, pItem);
|
|
||||||
} else if (type == STREAM_INPUT__GET_RES) {
|
|
||||||
taosWriteQitem(pTask->inputQueue->queue, pItem);
|
|
||||||
// qStreamInput(pTask->exec.executor, pItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static FORCE_INLINE void streamTaskInputFail(SStreamTask* pTask) {
|
static FORCE_INLINE void streamTaskInputFail(SStreamTask* pTask) {
|
||||||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
||||||
|
|
|
@ -146,8 +146,8 @@ typedef struct {
|
||||||
int64_t curFileFirstVer;
|
int64_t curFileFirstVer;
|
||||||
int64_t curVersion;
|
int64_t curVersion;
|
||||||
int64_t capacity;
|
int64_t capacity;
|
||||||
int8_t curInvalid;
|
// int8_t curInvalid;
|
||||||
int8_t curStopped;
|
// int8_t curStopped;
|
||||||
TdThreadMutex mutex;
|
TdThreadMutex mutex;
|
||||||
SWalFilterCond cond;
|
SWalFilterCond cond;
|
||||||
// TODO remove it
|
// TODO remove it
|
||||||
|
|
|
@ -242,6 +242,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_MND_INVALID_ALTER_OPER TAOS_DEF_ERROR_CODE(0, 0x0356)
|
#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_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_USER_NOT_AVAILABLE TAOS_DEF_ERROR_CODE(0, 0x0358)
|
||||||
|
#define TSDB_CODE_MND_PRIVILEDGE_EXIST TAOS_DEF_ERROR_CODE(0, 0x0359)
|
||||||
|
|
||||||
// mnode-stable-part1
|
// mnode-stable-part1
|
||||||
#define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
|
#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_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_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x4001)
|
||||||
#define TSDB_CODE_TMQ_CONSUMER_CLOSED TAOS_DEF_ERROR_CODE(0, 0x4002)
|
#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
|
// stream
|
||||||
#define TSDB_CODE_STREAM_TASK_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x4100)
|
#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_STREAM_NAME_LEN 193 // it is a null-terminated string
|
||||||
#define TSDB_DB_NAME_LEN 65
|
#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_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_NAME_LEN 65
|
||||||
#define TSDB_FUNC_COMMENT_LEN 1024 * 1024
|
#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 STaosQnode;
|
||||||
|
|
||||||
typedef struct STaosQnode {
|
struct STaosQnode {
|
||||||
STaosQnode *next;
|
STaosQnode *next;
|
||||||
STaosQueue *queue;
|
STaosQueue *queue;
|
||||||
int64_t timestamp;
|
int64_t timestamp;
|
||||||
|
@ -70,9 +70,9 @@ typedef struct STaosQnode {
|
||||||
int8_t itype;
|
int8_t itype;
|
||||||
int8_t reserved[3];
|
int8_t reserved[3];
|
||||||
char item[];
|
char item[];
|
||||||
} STaosQnode;
|
};
|
||||||
|
|
||||||
typedef struct STaosQueue {
|
struct STaosQueue {
|
||||||
STaosQnode *head;
|
STaosQnode *head;
|
||||||
STaosQnode *tail;
|
STaosQnode *tail;
|
||||||
STaosQueue *next; // for queue set
|
STaosQueue *next; // for queue set
|
||||||
|
@ -84,22 +84,22 @@ typedef struct STaosQueue {
|
||||||
int64_t memOfItems;
|
int64_t memOfItems;
|
||||||
int32_t numOfItems;
|
int32_t numOfItems;
|
||||||
int64_t threadId;
|
int64_t threadId;
|
||||||
} STaosQueue;
|
};
|
||||||
|
|
||||||
typedef struct STaosQset {
|
struct STaosQset {
|
||||||
STaosQueue *head;
|
STaosQueue *head;
|
||||||
STaosQueue *current;
|
STaosQueue *current;
|
||||||
TdThreadMutex mutex;
|
TdThreadMutex mutex;
|
||||||
tsem_t sem;
|
tsem_t sem;
|
||||||
int32_t numOfQueues;
|
int32_t numOfQueues;
|
||||||
int32_t numOfItems;
|
int32_t numOfItems;
|
||||||
} STaosQset;
|
};
|
||||||
|
|
||||||
typedef struct STaosQall {
|
struct STaosQall {
|
||||||
STaosQnode *current;
|
STaosQnode *current;
|
||||||
STaosQnode *start;
|
STaosQnode *start;
|
||||||
int32_t numOfItems;
|
int32_t numOfItems;
|
||||||
} STaosQall;
|
};
|
||||||
|
|
||||||
STaosQueue *taosOpenQueue();
|
STaosQueue *taosOpenQueue();
|
||||||
void taosCloseQueue(STaosQueue *queue);
|
void taosCloseQueue(STaosQueue *queue);
|
||||||
|
|
|
@ -572,6 +572,19 @@ function install_config() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function install_share_etc() {
|
||||||
|
for c in `ls ${script_dir}/share/etc/`; do
|
||||||
|
if [ -e /etc/$c ]; then
|
||||||
|
out=/etc/$c.new.`date +%F`
|
||||||
|
${csudo}cp -f ${script_dir}/share/etc/$c $out
|
||||||
|
else
|
||||||
|
${csudo}cp -f ${script_dir}/share/etc/$c /etc/$c
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
${csudo} cp ${script_dir}/share/srv/* ${service_config_dir}
|
||||||
|
}
|
||||||
|
|
||||||
function install_log() {
|
function install_log() {
|
||||||
${csudo}rm -rf ${log_dir} || :
|
${csudo}rm -rf ${log_dir} || :
|
||||||
${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
|
${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
|
||||||
|
@ -687,11 +700,33 @@ function clean_service_on_systemd() {
|
||||||
# if [ "$verMode" == "cluster" ] && [ "$clientName" != "$clientName2" ]; then
|
# if [ "$verMode" == "cluster" ] && [ "$clientName" != "$clientName2" ]; then
|
||||||
# ${csudo}rm -f ${service_config_dir}/${serverName2}.service
|
# ${csudo}rm -f ${service_config_dir}/${serverName2}.service
|
||||||
# fi
|
# 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() {
|
function install_service_on_systemd() {
|
||||||
clean_service_on_systemd
|
clean_service_on_systemd
|
||||||
|
|
||||||
|
install_share_etc
|
||||||
|
|
||||||
[ -f ${script_dir}/cfg/${serverName2}.service ] &&
|
[ -f ${script_dir}/cfg/${serverName2}.service ] &&
|
||||||
${csudo}cp ${script_dir}/cfg/${serverName2}.service \
|
${csudo}cp ${script_dir}/cfg/${serverName2}.service \
|
||||||
${service_config_dir}/ || :
|
${service_config_dir}/ || :
|
||||||
|
|
|
@ -53,9 +53,7 @@ if [ -d ${top_dir}/tools/taos-tools/packaging/deb ]; then
|
||||||
cd ${top_dir}/tools/taos-tools/packaging/deb
|
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)
|
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"
|
[ -z "$taostools_ver" ] && taostools_ver="0.1.0"
|
||||||
|
|
||||||
taostools_ver=$(git for-each-ref --sort=taggerdate --format '%(tag)' refs/tags|grep -v taos | tail -1)
|
|
||||||
taostools_install_dir="${release_dir}/${clientName2}Tools-${taostools_ver}"
|
taostools_install_dir="${release_dir}/${clientName2}Tools-${taostools_ver}"
|
||||||
|
|
||||||
cd ${curr_dir}
|
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}/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_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}/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
|
if [ $adapterName != "taosadapter" ]; then
|
||||||
mv ${install_dir}/cfg/${clientName2}adapter.toml ${install_dir}/cfg/$adapterName.toml
|
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
|
${csudo}systemctl stop ${tarbitrator_service_name} &>/dev/null || echo &>/dev/null
|
||||||
fi
|
fi
|
||||||
${csudo}systemctl disable ${tarbitrator_service_name} &>/dev/null || echo &>/dev/null
|
${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() {
|
function clean_service_on_sysvinit() {
|
||||||
|
|
|
@ -26,6 +26,7 @@ extern "C" {
|
||||||
#define tscFatal(...) do { if (cDebugFlag & DEBUG_FATAL) { taosPrintLog("TSC FATAL ", DEBUG_FATAL, cDebugFlag, __VA_ARGS__); }} while(0)
|
#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 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 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 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 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)
|
#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;
|
SStmtBindInfo bInfo;
|
||||||
|
|
||||||
int64_t reqid;
|
int64_t reqid;
|
||||||
|
int32_t errCode;
|
||||||
} STscStmt;
|
} STscStmt;
|
||||||
|
|
||||||
extern char *gStmtStatusStr[];
|
extern char *gStmtStatusStr[];
|
||||||
|
@ -121,6 +122,7 @@ extern char *gStmtStatusStr[];
|
||||||
int32_t _code = c; \
|
int32_t _code = c; \
|
||||||
if (_code != TSDB_CODE_SUCCESS) { \
|
if (_code != TSDB_CODE_SUCCESS) { \
|
||||||
terrno = _code; \
|
terrno = _code; \
|
||||||
|
pStmt->errCode = _code; \
|
||||||
return _code; \
|
return _code; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@ -129,6 +131,7 @@ extern char *gStmtStatusStr[];
|
||||||
int32_t _code = c; \
|
int32_t _code = c; \
|
||||||
if (_code != TSDB_CODE_SUCCESS) { \
|
if (_code != TSDB_CODE_SUCCESS) { \
|
||||||
terrno = _code; \
|
terrno = _code; \
|
||||||
|
pStmt->errCode = _code; \
|
||||||
} \
|
} \
|
||||||
return _code; \
|
return _code; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@ -137,6 +140,7 @@ extern char *gStmtStatusStr[];
|
||||||
code = c; \
|
code = c; \
|
||||||
if (code != TSDB_CODE_SUCCESS) { \
|
if (code != TSDB_CODE_SUCCESS) { \
|
||||||
terrno = code; \
|
terrno = code; \
|
||||||
|
pStmt->errCode = code; \
|
||||||
goto _return; \
|
goto _return; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
|
@ -107,6 +107,7 @@ static void deregisterRequest(SRequestObj *pRequest) {
|
||||||
|
|
||||||
if (duration >= SLOW_QUERY_INTERVAL) {
|
if (duration >= SLOW_QUERY_INTERVAL) {
|
||||||
atomic_add_fetch_64((int64_t *)&pActivity->numOfSlowQueries, 1);
|
atomic_add_fetch_64((int64_t *)&pActivity->numOfSlowQueries, 1);
|
||||||
|
tscWarnL("slow query: %s, duration:%" PRId64, pRequest->sqlstr, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseTscObj(pTscObj->id);
|
releaseTscObj(pTscObj->id);
|
||||||
|
|
|
@ -174,6 +174,7 @@ static int32_t smlParseTableName(SArray *tags, char *childTableName) {
|
||||||
if (childTableNameLen == tag->keyLen && strncmp(tag->key, tsSmlChildTableName, tag->keyLen) == 0) {
|
if (childTableNameLen == tag->keyLen && strncmp(tag->key, tsSmlChildTableName, tag->keyLen) == 0) {
|
||||||
memset(childTableName, 0, TSDB_TABLE_NAME_LEN);
|
memset(childTableName, 0, TSDB_TABLE_NAME_LEN);
|
||||||
strncpy(childTableName, tag->value, (tag->length < TSDB_TABLE_NAME_LEN ? tag->length : TSDB_TABLE_NAME_LEN));
|
strncpy(childTableName, tag->value, (tag->length < TSDB_TABLE_NAME_LEN ? tag->length : TSDB_TABLE_NAME_LEN));
|
||||||
|
taosArrayRemove(tags, i);
|
||||||
break;
|
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;
|
uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
|
||||||
if (index) {
|
if (index) {
|
||||||
if (colField[*index].type != kv->type) {
|
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,
|
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);
|
||||||
kv->key, colField[*index].type, kv->type);
|
|
||||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,14 @@ int32_t stmtSwitchStatus(STscStmt* pStmt, STMT_STATUS newStatus) {
|
||||||
STMT_LOG_SEQ(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) {
|
switch (newStatus) {
|
||||||
case STMT_PREPARE:
|
case STMT_PREPARE:
|
||||||
|
pStmt->errCode = 0;
|
||||||
break;
|
break;
|
||||||
case STMT_SETTBNAME:
|
case STMT_SETTBNAME:
|
||||||
if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND) || STMT_STATUS_EQ(BIND_COL)) {
|
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;
|
STscStmt* pStmt = (STscStmt*)stmt;
|
||||||
|
|
||||||
*pVgHash = pStmt->sql.pVgHash;
|
*pVgHash = pStmt->sql.pVgHash;
|
||||||
|
pStmt->sql.pVgHash = NULL;
|
||||||
|
|
||||||
*pBlockHash = pStmt->exec.pBlockHash;
|
*pBlockHash = pStmt->exec.pBlockHash;
|
||||||
|
pStmt->exec.pBlockHash = NULL;
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -325,6 +334,8 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable, bool deepClean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t stmtCleanSQLInfo(STscStmt* pStmt) {
|
int32_t stmtCleanSQLInfo(STscStmt* pStmt) {
|
||||||
|
STMT_DLOG_E("start to free SQL info");
|
||||||
|
|
||||||
taosMemoryFree(pStmt->sql.queryRes.fields);
|
taosMemoryFree(pStmt->sql.queryRes.fields);
|
||||||
taosMemoryFree(pStmt->sql.queryRes.userFields);
|
taosMemoryFree(pStmt->sql.queryRes.userFields);
|
||||||
taosMemoryFree(pStmt->sql.sqlStr);
|
taosMemoryFree(pStmt->sql.sqlStr);
|
||||||
|
@ -351,6 +362,8 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) {
|
||||||
|
|
||||||
memset(&pStmt->sql, 0, sizeof(pStmt->sql));
|
memset(&pStmt->sql, 0, sizeof(pStmt->sql));
|
||||||
|
|
||||||
|
STMT_DLOG_E("end to free SQL info");
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,11 +454,10 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
|
||||||
.mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)};
|
.mgmtEps = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp)};
|
||||||
int32_t code = catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta);
|
int32_t code = catalogGetTableMeta(pStmt->pCatalog, &conn, &pStmt->bInfo.sname, &pTableMeta);
|
||||||
if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) {
|
if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) {
|
||||||
STMT_ERR_RET(stmtCleanBindInfo(pStmt));
|
|
||||||
|
|
||||||
tscDebug("tb %s not exist", pStmt->bInfo.tbFName);
|
tscDebug("tb %s not exist", pStmt->bInfo.tbFName);
|
||||||
|
stmtCleanBindInfo(pStmt);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
STMT_ERR_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
STMT_ERR_RET(code);
|
STMT_ERR_RET(code);
|
||||||
|
@ -922,9 +934,13 @@ _return:
|
||||||
int stmtClose(TAOS_STMT* stmt) {
|
int stmtClose(TAOS_STMT* stmt) {
|
||||||
STscStmt* pStmt = (STscStmt*)stmt;
|
STscStmt* pStmt = (STscStmt*)stmt;
|
||||||
|
|
||||||
|
STMT_DLOG_E("start to free stmt");
|
||||||
|
|
||||||
stmtCleanSQLInfo(pStmt);
|
stmtCleanSQLInfo(pStmt);
|
||||||
taosMemoryFree(stmt);
|
taosMemoryFree(stmt);
|
||||||
|
|
||||||
|
STMT_DLOG_E("stmt freed");
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,6 @@ struct tmq_t {
|
||||||
STaosQueue* mqueue; // queue of rsp
|
STaosQueue* mqueue; // queue of rsp
|
||||||
STaosQall* qall;
|
STaosQall* qall;
|
||||||
STaosQueue* delayedTask; // delayed task queue for heartbeat and auto commit
|
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;
|
tsem_t rspSem;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -188,7 +187,6 @@ typedef struct {
|
||||||
SMqClientVg* pVg;
|
SMqClientVg* pVg;
|
||||||
SMqClientTopic* pTopic;
|
SMqClientTopic* pTopic;
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
tsem_t rspSem;
|
|
||||||
uint64_t requestId; // request id for debug purpose
|
uint64_t requestId; // request id for debug purpose
|
||||||
} SMqPollCbParam;
|
} SMqPollCbParam;
|
||||||
|
|
||||||
|
@ -979,7 +977,6 @@ void tmqFreeImpl(void* handle) {
|
||||||
|
|
||||||
taosFreeQall(tmq->qall);
|
taosFreeQall(tmq->qall);
|
||||||
tsem_destroy(&tmq->rspSem);
|
tsem_destroy(&tmq->rspSem);
|
||||||
taosThreadMutexDestroy(&tmq->lock);
|
|
||||||
|
|
||||||
taosArrayDestroyEx(tmq->clientTopics, freeClientVgImpl);
|
taosArrayDestroyEx(tmq->clientTopics, freeClientVgImpl);
|
||||||
taos_close_internal(tmq->pTscObj);
|
taos_close_internal(tmq->pTscObj);
|
||||||
|
@ -1024,7 +1021,6 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
||||||
pTmq->delayedTask = taosOpenQueue();
|
pTmq->delayedTask = taosOpenQueue();
|
||||||
pTmq->qall = taosAllocateQall();
|
pTmq->qall = taosAllocateQall();
|
||||||
|
|
||||||
taosThreadMutexInit(&pTmq->lock, NULL);
|
|
||||||
if (pTmq->clientTopics == NULL || pTmq->mqueue == NULL || pTmq->qall == NULL || pTmq->delayedTask == NULL ||
|
if (pTmq->clientTopics == NULL || pTmq->mqueue == NULL || pTmq->qall == NULL || pTmq->delayedTask == NULL ||
|
||||||
conf->groupId[0] == 0) {
|
conf->groupId[0] == 0) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -1155,6 +1151,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tsem_init(¶m.rspSem, 0, 0) != 0) {
|
if (tsem_init(¶m.rspSem, 0, 0) != 0) {
|
||||||
|
code = TSDB_CODE_TSC_INTERNAL_ERROR;
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1190,6 +1187,8 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) {
|
||||||
int32_t retryCnt = 0;
|
int32_t retryCnt = 0;
|
||||||
while (TSDB_CODE_MND_CONSUMER_NOT_READY == doAskEp(tmq)) {
|
while (TSDB_CODE_MND_CONSUMER_NOT_READY == doAskEp(tmq)) {
|
||||||
if (retryCnt++ > MAX_RETRY_COUNT) {
|
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;
|
goto FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1233,7 +1232,6 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
|
|
||||||
tmq_t* tmq = taosAcquireRef(tmqMgmt.rsetId, refId);
|
tmq_t* tmq = taosAcquireRef(tmqMgmt.rsetId, refId);
|
||||||
if (tmq == NULL) {
|
if (tmq == NULL) {
|
||||||
tsem_destroy(&pParam->rspSem);
|
|
||||||
taosMemoryFree(pParam);
|
taosMemoryFree(pParam);
|
||||||
taosMemoryFree(pMsg->pData);
|
taosMemoryFree(pMsg->pData);
|
||||||
taosMemoryFree(pMsg->pEpSet);
|
taosMemoryFree(pMsg->pEpSet);
|
||||||
|
@ -1270,6 +1268,8 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
|
|
||||||
pRspWrapper->tmqRspType = TMQ_MSG_TYPE__END_RSP;
|
pRspWrapper->tmqRspType = TMQ_MSG_TYPE__END_RSP;
|
||||||
taosWriteQitem(tmq->mqueue, pRspWrapper);
|
taosWriteQitem(tmq->mqueue, pRspWrapper);
|
||||||
|
} else if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) { // poll data while insert
|
||||||
|
taosMsleep(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
goto CREATE_MSG_FAIL;
|
goto CREATE_MSG_FAIL;
|
||||||
|
@ -1346,8 +1346,9 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
taosMemoryFree(pMsg->pData);
|
taosMemoryFree(pMsg->pData);
|
||||||
taosWriteQitem(tmq->mqueue, pRspWrapper);
|
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,
|
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);
|
tsem_post(&tmq->rspSem);
|
||||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||||
|
@ -1422,7 +1423,7 @@ static void freeClientVgInfo(void* param) {
|
||||||
taosArrayDestroy(pTopic->vgs);
|
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;
|
bool set = false;
|
||||||
|
|
||||||
int32_t topicNumCur = taosArrayGetSize(tmq->clientTopics);
|
int32_t topicNumCur = taosArrayGetSize(tmq->clientTopics);
|
||||||
|
@ -1431,6 +1432,9 @@ static bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) {
|
||||||
char vgKey[TSDB_TOPIC_FNAME_LEN + 22];
|
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",
|
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);
|
tmq->consumerId, tmq->epoch, epoch, topicNumGet, topicNumCur);
|
||||||
|
if (epoch <= tmq->epoch) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
SArray* newTopics = taosArrayInit(topicNumGet, sizeof(SMqClientTopic));
|
SArray* newTopics = taosArrayInit(topicNumGet, sizeof(SMqClientTopic));
|
||||||
if (newTopics == NULL) {
|
if (newTopics == NULL) {
|
||||||
|
@ -1474,14 +1478,11 @@ static bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) {
|
||||||
|
|
||||||
taosHashCleanup(pVgOffsetHashMap);
|
taosHashCleanup(pVgOffsetHashMap);
|
||||||
|
|
||||||
taosThreadMutexLock(&tmq->lock);
|
|
||||||
// destroy current buffered existed topics info
|
// destroy current buffered existed topics info
|
||||||
if (tmq->clientTopics) {
|
if (tmq->clientTopics) {
|
||||||
taosArrayDestroyEx(tmq->clientTopics, freeClientVgInfo);
|
taosArrayDestroyEx(tmq->clientTopics, freeClientVgInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmq->clientTopics = newTopics;
|
tmq->clientTopics = newTopics;
|
||||||
taosThreadMutexUnlock(&tmq->lock);
|
|
||||||
|
|
||||||
int8_t flag = (topicNumGet == 0) ? TMQ_CONSUMER_STATUS__NO_TOPIC : TMQ_CONSUMER_STATUS__READY;
|
int8_t flag = (topicNumGet == 0) ? TMQ_CONSUMER_STATUS__NO_TOPIC : TMQ_CONSUMER_STATUS__READY;
|
||||||
atomic_store_8(&tmq->status, flag);
|
atomic_store_8(&tmq->status, flag);
|
||||||
|
@ -1537,8 +1538,8 @@ int32_t askEpCallbackFn(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
} else {
|
} else {
|
||||||
tscDebug("consumer:0x%" PRIx64 ", recv ep, msg epoch %d, current epoch %d, update local ep", tmq->consumerId,
|
tscDebug("consumer:0x%" PRIx64 ", recv ep, msg epoch %d, current epoch %d, update local ep", tmq->consumerId,
|
||||||
head->epoch, epoch);
|
head->epoch, epoch);
|
||||||
pParam->pUserFn(tmq, code, pMsg, pParam->pParam);
|
|
||||||
}
|
}
|
||||||
|
pParam->pUserFn(tmq, code, pMsg, pParam->pParam);
|
||||||
|
|
||||||
taosReleaseRef(tmqMgmt.rsetId, pParam->refId);
|
taosReleaseRef(tmqMgmt.rsetId, pParam->refId);
|
||||||
|
|
||||||
|
@ -1745,7 +1746,7 @@ static int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspWrapper* rspWrapper, bool* p
|
||||||
if (rspWrapper->epoch > atomic_load_32(&tmq->epoch)) {
|
if (rspWrapper->epoch > atomic_load_32(&tmq->epoch)) {
|
||||||
SMqAskEpRspWrapper* pEpRspWrapper = (SMqAskEpRspWrapper*)rspWrapper;
|
SMqAskEpRspWrapper* pEpRspWrapper = (SMqAskEpRspWrapper*)rspWrapper;
|
||||||
SMqAskEpRsp* rspMsg = &pEpRspWrapper->msg;
|
SMqAskEpRsp* rspMsg = &pEpRspWrapper->msg;
|
||||||
tmqUpdateEp(tmq, rspWrapper->epoch, rspMsg);
|
doUpdateLocalEp(tmq, rspWrapper->epoch, rspMsg);
|
||||||
/*tmqClearUnhandleMsg(tmq);*/
|
/*tmqClearUnhandleMsg(tmq);*/
|
||||||
tDeleteSMqAskEpRsp(rspMsg);
|
tDeleteSMqAskEpRsp(rspMsg);
|
||||||
*pReset = true;
|
*pReset = true;
|
||||||
|
@ -2168,7 +2169,7 @@ void updateEpCallbackFn(tmq_t* pTmq, int32_t code, SDataBuf* pDataBuf, void* par
|
||||||
|
|
||||||
SMqAskEpRsp rsp;
|
SMqAskEpRsp rsp;
|
||||||
tDecodeSMqAskEpRsp(POINTER_SHIFT(pDataBuf->pData, sizeof(SMqRspHead)), &rsp);
|
tDecodeSMqAskEpRsp(POINTER_SHIFT(pDataBuf->pData, sizeof(SMqRspHead)), &rsp);
|
||||||
tmqUpdateEp(pTmq, head->epoch, &rsp);
|
doUpdateLocalEp(pTmq, head->epoch, &rsp);
|
||||||
tDeleteSMqAskEpRsp(&rsp);
|
tDeleteSMqAskEpRsp(&rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,9 +162,11 @@ void* queryThread(void* arg) {
|
||||||
return NULL;
|
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) {
|
void* doConsumeData(void* param) {
|
||||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
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_t* conf = tmq_conf_new();
|
||||||
tmq_conf_set(conf, "enable.auto.commit", "true");
|
tmq_conf_set(conf, "enable.auto.commit", "true");
|
||||||
tmq_conf_set(conf, "auto.commit.interval.ms", "1000");
|
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.user", "root");
|
||||||
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
||||||
tmq_conf_set(conf, "auto.offset.reset", "earliest");
|
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_t* conf = tmq_conf_new();
|
||||||
tmq_conf_set(conf, "enable.auto.commit", "true");
|
tmq_conf_set(conf, "enable.auto.commit", "true");
|
||||||
tmq_conf_set(conf, "auto.commit.interval.ms", "1000");
|
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.user", "root");
|
||||||
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
||||||
tmq_conf_set(conf, "auto.offset.reset", "earliest");
|
tmq_conf_set(conf, "auto.offset.reset", "earliest");
|
||||||
|
|
|
@ -298,7 +298,9 @@ static const SSysDbTableSchema vnodesSchema[] = {
|
||||||
static const SSysDbTableSchema userUserPrivilegesSchema[] = {
|
static const SSysDbTableSchema userUserPrivilegesSchema[] = {
|
||||||
{.name = "user_name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
{.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 = "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[] = {
|
static const SSysTableMeta infosMeta[] = {
|
||||||
|
|
|
@ -1590,12 +1590,13 @@ static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) {
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
} else if (n > 8) {
|
} 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) {
|
while (i < newLen) {
|
||||||
uint8_t v = p[i + gap];
|
uint8_t v = p[i + gap];
|
||||||
p[i] = (v << tail);
|
p[i] = (v << tail);
|
||||||
|
|
||||||
if (i < newLen - 1) {
|
if (i < newLen - 1 + remain) {
|
||||||
uint8_t next = p[i + gap + 1];
|
uint8_t next = p[i + gap + 1];
|
||||||
p[i] |= (next >> (8 - tail));
|
p[i] |= (next >> (8 - tail));
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,10 @@
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tmisce.h"
|
#include "tmisce.h"
|
||||||
|
|
||||||
|
#if defined(CUS_NAME) || defined(CUS_PROMPT) || defined(CUS_EMAIL)
|
||||||
|
#include "cus_name.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
GRANT_CFG_DECLARE;
|
GRANT_CFG_DECLARE;
|
||||||
|
|
||||||
SConfig *tsCfg = NULL;
|
SConfig *tsCfg = NULL;
|
||||||
|
@ -99,6 +103,7 @@ char tsSmlChildTableName[TSDB_TABLE_NAME_LEN] = ""; // user defined child table
|
||||||
// query
|
// query
|
||||||
int32_t tsQueryPolicy = 1;
|
int32_t tsQueryPolicy = 1;
|
||||||
int32_t tsQueryRspPolicy = 0;
|
int32_t tsQueryRspPolicy = 0;
|
||||||
|
int64_t tsQueryMaxConcurrentTables = 200; // unit is TSDB_TABLE_NUM_UNIT
|
||||||
bool tsEnableQueryHb = false;
|
bool tsEnableQueryHb = false;
|
||||||
int32_t tsQuerySmaOptimize = 0;
|
int32_t tsQuerySmaOptimize = 0;
|
||||||
int32_t tsQueryRsmaTolerance = 1000; // the tolerance time (ms) to judge from which level to query rsma data.
|
int32_t tsQueryRsmaTolerance = 1000; // the tolerance time (ms) to judge from which level to query rsma data.
|
||||||
|
@ -336,6 +341,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
|
||||||
if (cfgAddInt32(pCfg, "maxRetryWaitTime", tsMaxRetryWaitTime, 0, 86400000, 0) != 0) return -1;
|
if (cfgAddInt32(pCfg, "maxRetryWaitTime", tsMaxRetryWaitTime, 0, 86400000, 0) != 0) return -1;
|
||||||
if (cfgAddBool(pCfg, "useAdapter", tsUseAdapter, true) != 0) return -1;
|
if (cfgAddBool(pCfg, "useAdapter", tsUseAdapter, true) != 0) return -1;
|
||||||
if (cfgAddBool(pCfg, "crashReporting", tsEnableCrashReport, 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 = tsNumOfCores / 2;
|
||||||
tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 2, TSDB_MAX_RPC_THREADS);
|
tsNumOfRpcThreads = TRANGE(tsNumOfRpcThreads, 2, TSDB_MAX_RPC_THREADS);
|
||||||
|
@ -731,6 +737,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
||||||
tsKeepColumnName = cfgGetItem(pCfg, "keepColumnName")->bval;
|
tsKeepColumnName = cfgGetItem(pCfg, "keepColumnName")->bval;
|
||||||
tsUseAdapter = cfgGetItem(pCfg, "useAdapter")->bval;
|
tsUseAdapter = cfgGetItem(pCfg, "useAdapter")->bval;
|
||||||
tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval;
|
tsEnableCrashReport = cfgGetItem(pCfg, "crashReporting")->bval;
|
||||||
|
tsQueryMaxConcurrentTables = cfgGetItem(pCfg, "queryMaxConcurrentTables")->i64;
|
||||||
|
|
||||||
tsMaxRetryWaitTime = cfgGetItem(pCfg, "maxRetryWaitTime")->i32;
|
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->user) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pReq->pass) < 0) return -1;
|
if (tEncodeCStr(&encoder, pReq->pass) < 0) return -1;
|
||||||
if (tEncodeCStr(&encoder, pReq->objname) < 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);
|
tEndEncode(&encoder);
|
||||||
|
|
||||||
int32_t tlen = encoder.pos;
|
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->user) < 0) return -1;
|
||||||
if (tDecodeCStrTo(&decoder, pReq->pass) < 0) return -1;
|
if (tDecodeCStrTo(&decoder, pReq->pass) < 0) return -1;
|
||||||
if (tDecodeCStrTo(&decoder, pReq->objname) < 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);
|
tEndDecode(&decoder);
|
||||||
|
|
||||||
tDecoderClear(&decoder);
|
tDecoderClear(&decoder);
|
||||||
|
@ -1429,6 +1445,7 @@ int32_t tSerializeSGetUserAuthRspImpl(SEncoder *pEncoder, SGetUserAuthRsp *pRsp)
|
||||||
int32_t numOfCreatedDbs = taosHashGetSize(pRsp->createdDbs);
|
int32_t numOfCreatedDbs = taosHashGetSize(pRsp->createdDbs);
|
||||||
int32_t numOfReadDbs = taosHashGetSize(pRsp->readDbs);
|
int32_t numOfReadDbs = taosHashGetSize(pRsp->readDbs);
|
||||||
int32_t numOfWriteDbs = taosHashGetSize(pRsp->writeDbs);
|
int32_t numOfWriteDbs = taosHashGetSize(pRsp->writeDbs);
|
||||||
|
|
||||||
if (tEncodeI32(pEncoder, numOfCreatedDbs) < 0) return -1;
|
if (tEncodeI32(pEncoder, numOfCreatedDbs) < 0) return -1;
|
||||||
if (tEncodeI32(pEncoder, numOfReadDbs) < 0) return -1;
|
if (tEncodeI32(pEncoder, numOfReadDbs) < 0) return -1;
|
||||||
if (tEncodeI32(pEncoder, numOfWriteDbs) < 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);
|
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;
|
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->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->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);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1512,6 +1581,63 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs
|
||||||
taosHashPut(pRsp->writeDbs, db, len, db, len);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1533,6 +1659,9 @@ void tFreeSGetUserAuthRsp(SGetUserAuthRsp *pRsp) {
|
||||||
taosHashCleanup(pRsp->createdDbs);
|
taosHashCleanup(pRsp->createdDbs);
|
||||||
taosHashCleanup(pRsp->readDbs);
|
taosHashCleanup(pRsp->readDbs);
|
||||||
taosHashCleanup(pRsp->writeDbs);
|
taosHashCleanup(pRsp->writeDbs);
|
||||||
|
taosHashCleanup(pRsp->writeTbs);
|
||||||
|
taosHashCleanup(pRsp->readTbs);
|
||||||
|
taosHashCleanup(pRsp->useDbs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tSerializeSCreateDropMQSNodeReq(void *buf, int32_t bufLen, SMCreateQnodeReq *pReq) {
|
int32_t tSerializeSCreateDropMQSNodeReq(void *buf, int32_t bufLen, SMCreateQnodeReq *pReq) {
|
||||||
|
@ -7291,6 +7420,7 @@ void tDestroySSubmitReq2(SSubmitReq2 *pReq, int32_t flag) {
|
||||||
tDestroySSubmitTbData(&aSubmitTbData[i], flag);
|
tDestroySSubmitTbData(&aSubmitTbData[i], flag);
|
||||||
}
|
}
|
||||||
taosArrayDestroy(pReq->aSubmitTbData);
|
taosArrayDestroy(pReq->aSubmitTbData);
|
||||||
|
pReq->aSubmitTbData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tEncodeSSubmitRsp2(SEncoder *pCoder, const SSubmitRsp2 *pRsp) {
|
int32_t tEncodeSSubmitRsp2(SEncoder *pCoder, const SSubmitRsp2 *pRsp) {
|
||||||
|
|
|
@ -24,10 +24,10 @@ extern "C" {
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MQ_CONSUMER_STATUS__MODIFY = 1,
|
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__READY,
|
||||||
MQ_CONSUMER_STATUS__LOST,
|
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__LOST_REBD,
|
||||||
MQ_CONSUMER_STATUS__REMOVED,
|
MQ_CONSUMER_STATUS__REMOVED,
|
||||||
};
|
};
|
||||||
|
|
|
@ -281,6 +281,9 @@ typedef struct {
|
||||||
SHashObj* readDbs;
|
SHashObj* readDbs;
|
||||||
SHashObj* writeDbs;
|
SHashObj* writeDbs;
|
||||||
SHashObj* topics;
|
SHashObj* topics;
|
||||||
|
SHashObj* readTbs;
|
||||||
|
SHashObj* writeTbs;
|
||||||
|
SHashObj* useDbs;
|
||||||
SRWLatch lock;
|
SRWLatch lock;
|
||||||
} SUserObj;
|
} SUserObj;
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ void mndFreeStb(SStbObj *pStb);
|
||||||
int32_t mndBuildSMCreateStbRsp(SMnode *pMnode, char *dbFName, char *stbFName, void **pCont, int32_t *pLen);
|
int32_t mndBuildSMCreateStbRsp(SMnode *pMnode, char *dbFName, char *stbFName, void **pCont, int32_t *pLen);
|
||||||
|
|
||||||
void mndExtractDbNameFromStbFullName(const char *stbFullName, char *dst);
|
void mndExtractDbNameFromStbFullName(const char *stbFullName, char *dst);
|
||||||
|
void mndExtractShortDbNameFromStbFullName(const char *stbFullName, char *dst);
|
||||||
void mndExtractTbNameFromStbFullName(const char *stbFullName, char *dst, int32_t dstSize);
|
void mndExtractTbNameFromStbFullName(const char *stbFullName, char *dst, int32_t dstSize);
|
||||||
|
|
||||||
const char *mndGetStbStr(const char *src);
|
const char *mndGetStbStr(const char *src);
|
||||||
|
|
|
@ -31,6 +31,7 @@ void mndReleaseUser(SMnode *pMnode, SUserObj *pUser);
|
||||||
// for trans test
|
// for trans test
|
||||||
SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
||||||
SHashObj *mndDupDbHash(SHashObj *pOld);
|
SHashObj *mndDupDbHash(SHashObj *pOld);
|
||||||
|
SHashObj *mndDupTableHash(SHashObj *pOld);
|
||||||
SHashObj *mndDupTopicHash(SHashObj *pOld);
|
SHashObj *mndDupTopicHash(SHashObj *pOld);
|
||||||
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
||||||
int32_t *pRspLen);
|
int32_t *pRspLen);
|
||||||
|
|
|
@ -335,7 +335,7 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
|
||||||
taosArrayPush(pRebSub->removedConsumers, &pConsumer->consumerId);
|
taosArrayPush(pRebSub->removedConsumers, &pConsumer->consumerId);
|
||||||
}
|
}
|
||||||
taosRUnLockLatch(&pConsumer->lock);
|
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);
|
taosRLockLatch(&pConsumer->lock);
|
||||||
|
|
||||||
int32_t newTopicNum = taosArrayGetSize(pConsumer->rebNewTopics);
|
int32_t newTopicNum = taosArrayGetSize(pConsumer->rebNewTopics);
|
||||||
|
@ -873,17 +873,11 @@ static void updateConsumerStatus(SMqConsumerObj *pConsumer) {
|
||||||
int32_t status = pConsumer->status;
|
int32_t status = pConsumer->status;
|
||||||
|
|
||||||
if (taosArrayGetSize(pConsumer->rebNewTopics) == 0 && taosArrayGetSize(pConsumer->rebRemovedTopics) == 0) {
|
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;
|
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;
|
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";
|
return "ready";
|
||||||
case MQ_CONSUMER_STATUS__LOST:
|
case MQ_CONSUMER_STATUS__LOST:
|
||||||
case MQ_CONSUMER_STATUS__LOST_REBD:
|
case MQ_CONSUMER_STATUS__LOST_REBD:
|
||||||
case MQ_CONSUMER_STATUS__LOST_IN_REB:
|
|
||||||
return "lost";
|
return "lost";
|
||||||
case MQ_CONSUMER_STATUS__MODIFY:
|
case MQ_CONSUMER_STATUS__MODIFY:
|
||||||
case MQ_CONSUMER_STATUS__MODIFY_IN_REB:
|
|
||||||
return "rebalancing";
|
return "rebalancing";
|
||||||
default:
|
default:
|
||||||
return "unknown";
|
return "unknown";
|
||||||
|
|
|
@ -35,6 +35,7 @@ int32_t mndCheckTopicPrivilegeByName(SMnode *pMnode, const char *user, EOperType
|
||||||
int32_t mndSetUserAuthRsp(SMnode *pMnode, SUserObj *pUser, SGetUserAuthRsp *pRsp) {
|
int32_t mndSetUserAuthRsp(SMnode *pMnode, SUserObj *pUser, SGetUserAuthRsp *pRsp) {
|
||||||
memcpy(pRsp->user, pUser->user, TSDB_USER_LEN);
|
memcpy(pRsp->user, pUser->user, TSDB_USER_LEN);
|
||||||
pRsp->superAuth = 1;
|
pRsp->superAuth = 1;
|
||||||
|
pRsp->enable = pUser->enable;
|
||||||
pRsp->version = pUser->authVersion;
|
pRsp->version = pUser->authVersion;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2614,6 +2614,13 @@ void mndExtractDbNameFromStbFullName(const char *stbFullName, char *dst) {
|
||||||
tNameGetFullDbName(&name, 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) {
|
void mndExtractTbNameFromStbFullName(const char *stbFullName, char *dst, int32_t dstSize) {
|
||||||
int32_t pos = -1;
|
int32_t pos = -1;
|
||||||
int32_t num = 0;
|
int32_t num = 0;
|
||||||
|
|
|
@ -18,11 +18,12 @@
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndPrivilege.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
|
#include "mndStb.h"
|
||||||
#include "mndTopic.h"
|
#include "mndTopic.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
#include "tbase64.h"
|
#include "tbase64.h"
|
||||||
|
|
||||||
#define USER_VER_NUMBER 2
|
#define USER_VER_NUMBER 3
|
||||||
#define USER_RESERVE_SIZE 64
|
#define USER_RESERVE_SIZE 64
|
||||||
|
|
||||||
static int32_t mndCreateDefaultUsers(SMnode *pMnode);
|
static int32_t mndCreateDefaultUsers(SMnode *pMnode);
|
||||||
|
@ -124,9 +125,40 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
||||||
|
|
||||||
int32_t numOfReadDbs = taosHashGetSize(pUser->readDbs);
|
int32_t numOfReadDbs = taosHashGetSize(pUser->readDbs);
|
||||||
int32_t numOfWriteDbs = taosHashGetSize(pUser->writeDbs);
|
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 numOfTopics = taosHashGetSize(pUser->topics);
|
||||||
int32_t size = sizeof(SUserObj) + USER_RESERVE_SIZE + (numOfReadDbs + numOfWriteDbs) * TSDB_DB_FNAME_LEN +
|
int32_t numOfUseDbs = taosHashGetSize(pUser->useDbs);
|
||||||
numOfTopics * TSDB_TOPIC_FNAME_LEN;
|
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 += keyLen;
|
||||||
|
stb = taosHashIterate(pUser->writeTbs, stb);
|
||||||
|
}
|
||||||
|
|
||||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, USER_VER_NUMBER, size);
|
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, USER_VER_NUMBER, size);
|
||||||
if (pRaw == NULL) goto _OVER;
|
if (pRaw == NULL) goto _OVER;
|
||||||
|
@ -164,6 +196,49 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
||||||
topic = taosHashIterate(pUser->topics, topic);
|
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_RESERVE(pRaw, dataPos, USER_RESERVE_SIZE, _OVER)
|
||||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
||||||
|
|
||||||
|
@ -188,7 +263,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
||||||
int8_t sver = 0;
|
int8_t sver = 0;
|
||||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER;
|
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;
|
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||||
goto _OVER;
|
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, keyLen);
|
||||||
|
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)
|
SDB_GET_RESERVE(pRaw, dataPos, USER_RESERVE_SIZE, _OVER)
|
||||||
taosInitRWLatch(&pUser->lock);
|
taosInitRWLatch(&pUser->lock);
|
||||||
|
|
||||||
|
@ -261,6 +405,9 @@ _OVER:
|
||||||
taosHashCleanup(pUser->readDbs);
|
taosHashCleanup(pUser->readDbs);
|
||||||
taosHashCleanup(pUser->writeDbs);
|
taosHashCleanup(pUser->writeDbs);
|
||||||
taosHashCleanup(pUser->topics);
|
taosHashCleanup(pUser->topics);
|
||||||
|
taosHashCleanup(pUser->readTbs);
|
||||||
|
taosHashCleanup(pUser->writeTbs);
|
||||||
|
taosHashCleanup(pUser->useDbs);
|
||||||
}
|
}
|
||||||
taosMemoryFreeClear(pRow);
|
taosMemoryFreeClear(pRow);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -285,6 +432,32 @@ static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
|
static int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
|
||||||
memcpy(pNew, pUser, sizeof(SUserObj));
|
memcpy(pNew, pUser, sizeof(SUserObj));
|
||||||
pNew->authVersion++;
|
pNew->authVersion++;
|
||||||
|
@ -293,7 +466,10 @@ static int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
|
||||||
taosRLockLatch(&pUser->lock);
|
taosRLockLatch(&pUser->lock);
|
||||||
pNew->readDbs = mndDupDbHash(pUser->readDbs);
|
pNew->readDbs = mndDupDbHash(pUser->readDbs);
|
||||||
pNew->writeDbs = mndDupDbHash(pUser->writeDbs);
|
pNew->writeDbs = mndDupDbHash(pUser->writeDbs);
|
||||||
|
pNew->readTbs = mndDupTableHash(pUser->readTbs);
|
||||||
|
pNew->writeTbs = mndDupTableHash(pUser->writeTbs);
|
||||||
pNew->topics = mndDupTopicHash(pUser->topics);
|
pNew->topics = mndDupTopicHash(pUser->topics);
|
||||||
|
pNew->useDbs = mndDupDbHash(pUser->useDbs);
|
||||||
taosRUnLockLatch(&pUser->lock);
|
taosRUnLockLatch(&pUser->lock);
|
||||||
|
|
||||||
if (pNew->readDbs == NULL || pNew->writeDbs == NULL || pNew->topics == NULL) {
|
if (pNew->readDbs == NULL || pNew->writeDbs == NULL || pNew->topics == NULL) {
|
||||||
|
@ -306,9 +482,15 @@ static void mndUserFreeObj(SUserObj *pUser) {
|
||||||
taosHashCleanup(pUser->readDbs);
|
taosHashCleanup(pUser->readDbs);
|
||||||
taosHashCleanup(pUser->writeDbs);
|
taosHashCleanup(pUser->writeDbs);
|
||||||
taosHashCleanup(pUser->topics);
|
taosHashCleanup(pUser->topics);
|
||||||
|
taosHashCleanup(pUser->readTbs);
|
||||||
|
taosHashCleanup(pUser->writeTbs);
|
||||||
|
taosHashCleanup(pUser->useDbs);
|
||||||
pUser->readDbs = NULL;
|
pUser->readDbs = NULL;
|
||||||
pUser->writeDbs = NULL;
|
pUser->writeDbs = NULL;
|
||||||
pUser->topics = NULL;
|
pUser->topics = NULL;
|
||||||
|
pUser->readTbs = NULL;
|
||||||
|
pUser->writeTbs = NULL;
|
||||||
|
pUser->useDbs = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
||||||
|
@ -328,6 +510,9 @@ static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) {
|
||||||
TSWAP(pOld->readDbs, pNew->readDbs);
|
TSWAP(pOld->readDbs, pNew->readDbs);
|
||||||
TSWAP(pOld->writeDbs, pNew->writeDbs);
|
TSWAP(pOld->writeDbs, pNew->writeDbs);
|
||||||
TSWAP(pOld->topics, pNew->topics);
|
TSWAP(pOld->topics, pNew->topics);
|
||||||
|
TSWAP(pOld->readTbs, pNew->readTbs);
|
||||||
|
TSWAP(pOld->writeTbs, pNew->writeTbs);
|
||||||
|
TSWAP(pOld->useDbs, pNew->useDbs);
|
||||||
taosWUnLockLatch(&pOld->lock);
|
taosWUnLockLatch(&pOld->lock);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -498,6 +683,71 @@ SHashObj *mndDupDbHash(SHashObj *pOld) { return mndDupObjHash(pOld, TSDB_DB_FNAM
|
||||||
|
|
||||||
SHashObj *mndDupTopicHash(SHashObj *pOld) { return mndDupObjHash(pOld, TSDB_TOPIC_FNAME_LEN); }
|
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) {
|
static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
@ -637,6 +887,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) {
|
if (alterReq.alterType == TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC) {
|
||||||
int32_t len = strlen(alterReq.objname) + 1;
|
int32_t len = strlen(alterReq.objname) + 1;
|
||||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, alterReq.objname);
|
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, alterReq.objname);
|
||||||
|
@ -830,6 +1096,72 @@ static void mndCancelGetNextUser(SMnode *pMnode, void *pIter) {
|
||||||
sdbCancelFetch(pSdb, 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 = taosMemoryMalloc(sqlLen + VARSTR_HEADER_SIZE + 1);
|
||||||
|
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);
|
||||||
|
// taosMemoryFree(obj);
|
||||||
|
} else {
|
||||||
|
char condition[20] = {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) {
|
static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
@ -845,7 +1177,9 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
||||||
int32_t numOfReadDbs = taosHashGetSize(pUser->readDbs);
|
int32_t numOfReadDbs = taosHashGetSize(pUser->readDbs);
|
||||||
int32_t numOfWriteDbs = taosHashGetSize(pUser->writeDbs);
|
int32_t numOfWriteDbs = taosHashGetSize(pUser->writeDbs);
|
||||||
int32_t numOfTopics = taosHashGetSize(pUser->topics);
|
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) {
|
if (pUser->superUser) {
|
||||||
cols = 0;
|
cols = 0;
|
||||||
|
@ -864,6 +1198,16 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
colDataSetVal(pColInfo, numOfRows, (const char *)objName, false);
|
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++;
|
numOfRows++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -888,6 +1232,16 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
colDataSetVal(pColInfo, numOfRows, (const char *)objName, false);
|
colDataSetVal(pColInfo, numOfRows, (const char *)objName, false);
|
||||||
|
|
||||||
|
char tableName[20] = {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[20] = {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++;
|
numOfRows++;
|
||||||
db = taosHashIterate(pUser->readDbs, db);
|
db = taosHashIterate(pUser->readDbs, db);
|
||||||
}
|
}
|
||||||
|
@ -913,10 +1267,24 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
colDataSetVal(pColInfo, numOfRows, (const char *)objName, false);
|
colDataSetVal(pColInfo, numOfRows, (const char *)objName, false);
|
||||||
|
|
||||||
|
char tableName[20] = {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[20] = {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++;
|
numOfRows++;
|
||||||
db = taosHashIterate(pUser->writeDbs, db);
|
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);
|
char *topic = taosHashIterate(pUser->topics, NULL);
|
||||||
while (topic != NULL) {
|
while (topic != NULL) {
|
||||||
cols = 0;
|
cols = 0;
|
||||||
|
@ -936,6 +1304,16 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
colDataSetVal(pColInfo, numOfRows, (const char *)topicName, false);
|
colDataSetVal(pColInfo, numOfRows, (const char *)topicName, false);
|
||||||
|
|
||||||
|
char tableName[20] = {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[20] = {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++;
|
numOfRows++;
|
||||||
topic = taosHashIterate(pUser->topics, topic);
|
topic = taosHashIterate(pUser->topics, topic);
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,19 +228,12 @@ typedef struct SSnapContext {
|
||||||
SArray *idList;
|
SArray *idList;
|
||||||
int32_t index;
|
int32_t index;
|
||||||
bool withMeta;
|
bool withMeta;
|
||||||
bool queryMetaOrData; // true-get meta, false-get data
|
bool queryMeta; // true-get meta, false-get data
|
||||||
} SSnapContext;
|
} SSnapContext;
|
||||||
|
|
||||||
typedef struct STqReader {
|
typedef struct STqReader {
|
||||||
// const SSubmitReq *pMsg;
|
|
||||||
// SSubmitBlk *pBlock;
|
|
||||||
// SSubmitMsgIter msgIter;
|
|
||||||
// SSubmitBlkIter blkIter;
|
|
||||||
|
|
||||||
int64_t ver;
|
|
||||||
SPackedData msg2;
|
SPackedData msg2;
|
||||||
|
|
||||||
int8_t setMsg;
|
|
||||||
SSubmitReq2 submit;
|
SSubmitReq2 submit;
|
||||||
int32_t nextBlk;
|
int32_t nextBlk;
|
||||||
|
|
||||||
|
@ -267,7 +260,7 @@ int32_t tqReaderAddTbUidList(STqReader *pReader, const SArray *tbUidList);
|
||||||
int32_t tqReaderRemoveTbUidList(STqReader *pReader, const SArray *tbUidList);
|
int32_t tqReaderRemoveTbUidList(STqReader *pReader, const SArray *tbUidList);
|
||||||
|
|
||||||
int32_t tqSeekVer(STqReader *pReader, int64_t ver, const char *id);
|
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 tqReaderSetSubmitReq2(STqReader *pReader, void *msgStr, int32_t msgLen, int64_t ver);
|
int32_t tqReaderSetSubmitReq2(STqReader *pReader, void *msgStr, int32_t msgLen, int64_t ver);
|
||||||
// int32_t tqReaderSetDataMsg(STqReader *pReader, const SSubmitReq *pMsg, int64_t ver);
|
// int32_t tqReaderSetDataMsg(STqReader *pReader, const SSubmitReq *pMsg, int64_t ver);
|
||||||
|
|
|
@ -123,12 +123,12 @@ int32_t tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema)
|
||||||
void tsdbRowClose(STSDBRowIter *pIter);
|
void tsdbRowClose(STSDBRowIter *pIter);
|
||||||
SColVal *tsdbRowIterNext(STSDBRowIter *pIter);
|
SColVal *tsdbRowIterNext(STSDBRowIter *pIter);
|
||||||
// SRowMerger
|
// 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 tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
||||||
|
|
||||||
int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
// int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
|
||||||
void tsdbRowMergerClear(SRowMerger *pMerger);
|
void tsdbRowMergerClear(SRowMerger *pMerger);
|
||||||
int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow);
|
// int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow);
|
||||||
int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow);
|
int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow);
|
||||||
// TABLEID
|
// TABLEID
|
||||||
int32_t tTABLEIDCmprFn(const void *p1, const void *p2);
|
int32_t tTABLEIDCmprFn(const void *p1, const void *p2);
|
||||||
|
|
|
@ -268,7 +268,7 @@ int32_t buildSnapContext(SMeta* pMeta, int64_t snapVersion, int64_t suid, int8_t
|
||||||
ctx->snapVersion = snapVersion;
|
ctx->snapVersion = snapVersion;
|
||||||
ctx->suid = suid;
|
ctx->suid = suid;
|
||||||
ctx->subType = subType;
|
ctx->subType = subType;
|
||||||
ctx->queryMetaOrData = withMeta;
|
ctx->queryMeta = withMeta;
|
||||||
ctx->withMeta = withMeta;
|
ctx->withMeta = withMeta;
|
||||||
ctx->idVersion = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
ctx->idVersion = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
||||||
if (ctx->idVersion == NULL) {
|
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)) {
|
if (ctx->index >= taosArrayGetSize(ctx->idList)) {
|
||||||
metaDebug("tmqsnap get meta end");
|
metaDebug("tmqsnap get meta end");
|
||||||
ctx->index = 0;
|
ctx->index = 0;
|
||||||
ctx->queryMetaOrData = false; // change to get data
|
ctx->queryMeta = false; // change to get data
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -240,17 +240,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) {
|
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);
|
doSendDataRsp(&pMsg->info, pRsp, pReq->epoch, pReq->consumerId, type);
|
||||||
|
|
||||||
char buf1[80] = {0};
|
char buf1[80] = {0};
|
||||||
|
@ -352,17 +341,6 @@ static int32_t tqInitDataRsp(SMqDataRsp* pRsp, const SMqPollReq* pReq, int8_t su
|
||||||
}
|
}
|
||||||
|
|
||||||
pRsp->withTbName = 0;
|
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;
|
pRsp->withSchema = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -422,6 +400,7 @@ static int32_t extractResetOffsetVal(STqOffsetVal* pOffsetVal, STQ* pTq, STqHand
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// offset set to previous version when init
|
||||||
tqOffsetResetToLog(pOffsetVal, pHandle->pRef->refVer - 1);
|
tqOffsetResetToLog(pOffsetVal, pHandle->pRef->refVer - 1);
|
||||||
}
|
}
|
||||||
} else if (reqOffset.type == TMQ_OFFSET__RESET_LATEST) {
|
} else if (reqOffset.type == TMQ_OFFSET__RESET_LATEST) {
|
||||||
|
@ -463,7 +442,6 @@ static int32_t extractResetOffsetVal(STqOffsetVal* pOffsetVal, STQ* pTq, STqHand
|
||||||
|
|
||||||
static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
|
static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
|
||||||
SRpcMsg* pMsg, STqOffsetVal* pOffset) {
|
SRpcMsg* pMsg, STqOffsetVal* pOffset) {
|
||||||
int32_t code = 0;
|
|
||||||
uint64_t consumerId = pRequest->consumerId;
|
uint64_t consumerId = pRequest->consumerId;
|
||||||
int32_t vgId = TD_VID(pTq->pVnode);
|
int32_t vgId = TD_VID(pTq->pVnode);
|
||||||
|
|
||||||
|
@ -474,10 +452,9 @@ static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle,
|
||||||
taosWLockLatch(&pTq->lock);
|
taosWLockLatch(&pTq->lock);
|
||||||
|
|
||||||
qSetTaskId(pHandle->execHandle.task, consumerId, pRequest->reqId);
|
qSetTaskId(pHandle->execHandle.task, consumerId, pRequest->reqId);
|
||||||
code = tqScanData(pTq, pHandle, &dataRsp, pOffset);
|
int code = tqScanData(pTq, pHandle, &dataRsp, pOffset);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != 0) {
|
||||||
taosWUnLockLatch(&pTq->lock);
|
goto end;
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// till now, all data has been transferred to consumer, new data needs to push client once arrived.
|
// till now, all data has been transferred to consumer, new data needs to push client once arrived.
|
||||||
|
@ -488,59 +465,33 @@ static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle,
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosWUnLockLatch(&pTq->lock);
|
|
||||||
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&dataRsp, TMQ_MSG_TYPE__POLL_RSP);
|
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&dataRsp, TMQ_MSG_TYPE__POLL_RSP);
|
||||||
|
|
||||||
// NOTE: this pHandle->consumerId may have been changed already.
|
// 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);
|
|
||||||
|
|
||||||
|
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);
|
tDeleteSMqDataRsp(&dataRsp);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doPollDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest, SRpcMsg* pMsg) {
|
static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
|
||||||
int32_t code = -1;
|
SRpcMsg* pMsg, STqOffsetVal* offset) {
|
||||||
STqOffsetVal offset = {0};
|
int code = 0;
|
||||||
SWalCkHead* pCkHead = NULL;
|
|
||||||
int32_t vgId = TD_VID(pTq->pVnode);
|
int32_t vgId = TD_VID(pTq->pVnode);
|
||||||
|
SWalCkHead* pCkHead = NULL;
|
||||||
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};
|
SMqMetaRsp metaRsp = {0};
|
||||||
STaosxRsp taosxRsp = {0};
|
STaosxRsp taosxRsp = {0};
|
||||||
tqInitTaosxRsp(&taosxRsp, pRequest);
|
tqInitTaosxRsp(&taosxRsp, pRequest);
|
||||||
|
|
||||||
if (offset.type != TMQ_OFFSET__LOG) {
|
if (offset->type != TMQ_OFFSET__LOG) {
|
||||||
if (tqScanTaosx(pTq, pHandle, &taosxRsp, &metaRsp, &offset) < 0) {
|
if (tqScanTaosx(pTq, pHandle, &taosxRsp, &metaRsp, offset) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,28 +499,28 @@ static int32_t doPollDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* p
|
||||||
code = tqSendMetaPollRsp(pTq, pMsg, pRequest, &metaRsp);
|
code = tqSendMetaPollRsp(pTq, pMsg, pRequest, &metaRsp);
|
||||||
tqDebug("tmq poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send meta offset type:%d,uid:%" PRId64
|
tqDebug("tmq poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send meta offset type:%d,uid:%" PRId64
|
||||||
",ts:%" PRId64,
|
",ts:%" PRId64,
|
||||||
consumerId, pHandle->subKey, vgId, metaRsp.rspOffset.type, metaRsp.rspOffset.uid, metaRsp.rspOffset.ts);
|
pRequest->consumerId, pHandle->subKey, vgId, metaRsp.rspOffset.type, metaRsp.rspOffset.uid,
|
||||||
|
metaRsp.rspOffset.ts);
|
||||||
taosMemoryFree(metaRsp.metaRsp);
|
taosMemoryFree(metaRsp.metaRsp);
|
||||||
tDeleteSTaosxRsp(&taosxRsp);
|
tDeleteSTaosxRsp(&taosxRsp);
|
||||||
return code;
|
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) {
|
if (taosxRsp.blockNum > 0) {
|
||||||
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
|
code = tqSendDataRsp(pTq, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP);
|
||||||
tDeleteSTaosxRsp(&taosxRsp);
|
tDeleteSTaosxRsp(&taosxRsp);
|
||||||
return code;
|
return code;
|
||||||
} else {
|
} else {
|
||||||
offset = taosxRsp.rspOffset;
|
*offset = taosxRsp.rspOffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tqDebug("taosx poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send data blockNum:%d, offset type:%d,uid:%" PRId64
|
if (offset->type == TMQ_OFFSET__LOG) {
|
||||||
",version:%" PRId64,
|
int64_t fetchVer = offset->version + 1;
|
||||||
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);
|
pCkHead = taosMemoryMalloc(sizeof(SWalCkHead) + 2048);
|
||||||
if (pCkHead == NULL) {
|
if (pCkHead == NULL) {
|
||||||
tDeleteSTaosxRsp(&taosxRsp);
|
tDeleteSTaosxRsp(&taosxRsp);
|
||||||
|
@ -579,12 +530,11 @@ static int32_t doPollDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* p
|
||||||
walSetReaderCapacity(pHandle->pWalReader, 2048);
|
walSetReaderCapacity(pHandle->pWalReader, 2048);
|
||||||
int totalRows = 0;
|
int totalRows = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
// todo refactor: this is not correct.
|
|
||||||
int32_t savedEpoch = atomic_load_32(&pHandle->epoch);
|
int32_t savedEpoch = atomic_load_32(&pHandle->epoch);
|
||||||
if (savedEpoch > pRequest->epoch) {
|
if (savedEpoch > pRequest->epoch) {
|
||||||
tqWarn("tmq poll: consumer:0x%" PRIx64 " (epoch %d), subkey:%s vgId:%d offset %" PRId64
|
tqWarn("tmq poll: consumer:0x%" PRIx64 " (epoch %d), subkey:%s vgId:%d offset %" PRId64
|
||||||
", found new consumer epoch %d, discard req epoch %d",
|
", found new consumer epoch %d, discard req epoch %d",
|
||||||
consumerId, pRequest->epoch, pHandle->subKey, vgId, fetchVer, savedEpoch, pRequest->epoch);
|
pRequest->consumerId, pRequest->epoch, pHandle->subKey, vgId, fetchVer, savedEpoch, pRequest->epoch);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,8 +547,8 @@ static int32_t doPollDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* p
|
||||||
}
|
}
|
||||||
|
|
||||||
SWalCont* pHead = &pCkHead->head;
|
SWalCont* pHead = &pCkHead->head;
|
||||||
tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, vgId:%d offset %" PRId64 " msgType %d", consumerId,
|
tqDebug("tmq poll: consumer:0x%" PRIx64 " (epoch %d) iter log, vgId:%d offset %" PRId64 " msgType %d",
|
||||||
pRequest->epoch, vgId, fetchVer, pHead->msgType);
|
pRequest->consumerId, pRequest->epoch, vgId, fetchVer, pHead->msgType);
|
||||||
|
|
||||||
// process meta
|
// process meta
|
||||||
if (pHead->msgType != TDMT_VND_SUBMIT) {
|
if (pHead->msgType != TDMT_VND_SUBMIT) {
|
||||||
|
@ -635,7 +585,7 @@ static int32_t doPollDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* p
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tqTaosxScanLog(pTq, pHandle, submit, &taosxRsp, &totalRows) < 0) {
|
if (tqTaosxScanLog(pTq, pHandle, submit, &taosxRsp, &totalRows) < 0) {
|
||||||
tqError("tmq poll: tqTaosxScanLog error %" PRId64 ", in vgId:%d, subkey %s", consumerId, vgId,
|
tqError("tmq poll: tqTaosxScanLog error %" PRId64 ", in vgId:%d, subkey %s", pRequest->consumerId, vgId,
|
||||||
pRequest->subKey);
|
pRequest->subKey);
|
||||||
taosMemoryFreeClear(pCkHead);
|
taosMemoryFreeClear(pCkHead);
|
||||||
tDeleteSTaosxRsp(&taosxRsp);
|
tDeleteSTaosxRsp(&taosxRsp);
|
||||||
|
@ -659,6 +609,39 @@ static int32_t doPollDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* p
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t doPollDataForMq(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 tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||||
SMqPollReq req = {0};
|
SMqPollReq req = {0};
|
||||||
if (tDeserializeSMqPollReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
|
if (tDeserializeSMqPollReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
|
||||||
|
@ -821,13 +804,7 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
|
||||||
pHandle->pRef = pRef;
|
pHandle->pRef = pRef;
|
||||||
|
|
||||||
SReadHandle handle = {
|
SReadHandle handle = {
|
||||||
.meta = pVnode->pMeta,
|
.meta = pVnode->pMeta, .vnode = pVnode, .initTableReader = true, .initTqReader = true, .version = ver};
|
||||||
.vnode = pVnode,
|
|
||||||
.initTableReader = true,
|
|
||||||
.initTqReader = true,
|
|
||||||
.version = ver,
|
|
||||||
};
|
|
||||||
|
|
||||||
pHandle->snapshotVer = ver;
|
pHandle->snapshotVer = ver;
|
||||||
|
|
||||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||||
|
@ -1341,7 +1318,7 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
|
||||||
pRefBlock->dataRef = pRef;
|
pRefBlock->dataRef = pRef;
|
||||||
atomic_add_fetch_32(pRefBlock->dataRef, 1);
|
atomic_add_fetch_32(pRefBlock->dataRef, 1);
|
||||||
|
|
||||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pRefBlock) < 0) {
|
if (tAppendDataForStream(pTask, (SStreamQueueItem*)pRefBlock) < 0) {
|
||||||
qError("stream task input del failed, task id %d", pTask->taskId);
|
qError("stream task input del failed, task id %d", pTask->taskId);
|
||||||
|
|
||||||
atomic_sub_fetch_32(pRef, 1);
|
atomic_sub_fetch_32(pRef, 1);
|
||||||
|
@ -1376,7 +1353,7 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
|
||||||
taosArrayPush(pStreamBlock->blocks, &block);
|
taosArrayPush(pStreamBlock->blocks, &block);
|
||||||
|
|
||||||
if (!failed) {
|
if (!failed) {
|
||||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pStreamBlock) < 0) {
|
if (tAppendDataForStream(pTask, (SStreamQueueItem*)pStreamBlock) < 0) {
|
||||||
qError("stream task input del failed, task id %d", pTask->taskId);
|
qError("stream task input del failed, task id %d", pTask->taskId);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1397,14 +1374,13 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
|
||||||
|
|
||||||
int32_t tqProcessSubmitReq(STQ* pTq, SPackedData submit) {
|
int32_t tqProcessSubmitReq(STQ* pTq, SPackedData submit) {
|
||||||
void* pIter = NULL;
|
void* pIter = NULL;
|
||||||
bool failed = false;
|
bool succ = true;
|
||||||
SStreamDataSubmit2* pSubmit = NULL;
|
|
||||||
|
|
||||||
pSubmit = streamDataSubmitNew(submit);
|
SStreamDataSubmit2* pSubmit = streamDataSubmitNew(submit);
|
||||||
if (pSubmit == NULL) {
|
if (pSubmit == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
tqError("failed to create data submit for stream since out of memory");
|
tqError("failed to create data submit for stream since out of memory");
|
||||||
failed = true;
|
succ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -1414,22 +1390,27 @@ int32_t tqProcessSubmitReq(STQ* pTq, SPackedData submit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SStreamTask* pTask = *(SStreamTask**)pIter;
|
SStreamTask* pTask = *(SStreamTask**)pIter;
|
||||||
if (pTask->taskLevel != TASK_LEVEL__SOURCE) continue;
|
if (pTask->taskLevel != TASK_LEVEL__SOURCE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (pTask->taskStatus == TASK_STATUS__RECOVER_PREPARE || pTask->taskStatus == TASK_STATUS__WAIT_DOWNSTREAM) {
|
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);
|
tqDebug("stream task:%d skip push data, not ready for processing, status %d", pTask->taskId, pTask->taskStatus);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
tqDebug("data submit enqueue stream task:%d, ver: %" PRId64, pTask->taskId, submit.ver);
|
tqDebug("data submit enqueue stream task:%d, ver: %" PRId64, pTask->taskId, submit.ver);
|
||||||
|
if (succ) {
|
||||||
|
int32_t code = tAppendDataForStream(pTask, (SStreamQueueItem*)pSubmit);
|
||||||
|
if (code < 0) {
|
||||||
|
// let's handle the back pressure
|
||||||
|
|
||||||
if (!failed) {
|
tqError("stream task:%d failed to put into queue for, too many", pTask->taskId);
|
||||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pSubmit) < 0) {
|
|
||||||
tqError("stream task input failed, task id %d", pTask->taskId);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (streamSchedExec(pTask) < 0) {
|
if (streamSchedExec(pTask) < 0) {
|
||||||
tqError("stream task launch failed, task id %d", pTask->taskId);
|
tqError("stream task:%d launch failed, code:%s", pTask->taskId, tstrerror(terrno));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1437,12 +1418,12 @@ int32_t tqProcessSubmitReq(STQ* pTq, SPackedData submit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSubmit) {
|
if (pSubmit != NULL) {
|
||||||
streamDataSubmitRefDec(pSubmit);
|
streamDataSubmitDestroy(pSubmit);
|
||||||
taosFreeQitem(pSubmit);
|
taosFreeQitem(pSubmit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return failed ? -1 : 0;
|
return succ ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) {
|
int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||||
|
@ -1562,6 +1543,8 @@ int32_t vnodeEnqueueStreamMsg(SVnode* pVnode, SRpcMsg* pMsg) {
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
taosFreeQitem(pMsg);
|
taosFreeQitem(pMsg);
|
||||||
return 0;
|
return 0;
|
||||||
|
} else {
|
||||||
|
tDeleteStreamDispatchReq(&req);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = TSDB_CODE_STREAM_TASK_NOT_EXIST;
|
code = TSDB_CODE_STREAM_TASK_NOT_EXIST;
|
||||||
|
|
|
@ -30,7 +30,7 @@ static int32_t tqLoopExecFromQueue(STQ* pTq, STqHandle* pHandle, SStreamDataSubm
|
||||||
// update processed
|
// update processed
|
||||||
atomic_store_64(&pHandle->pushHandle.processedVer, pSubmit->ver);
|
atomic_store_64(&pHandle->pushHandle.processedVer, pSubmit->ver);
|
||||||
streamQueueProcessSuccess(&pHandle->pushHandle.inputQ);
|
streamQueueProcessSuccess(&pHandle->pushHandle.inputQ);
|
||||||
streamDataSubmitRefDec(pSubmit);
|
streamDataSubmitDestroy(pSubmit);
|
||||||
if (pRsp->blockNum > 0) {
|
if (pRsp->blockNum > 0) {
|
||||||
*ppSubmit = pSubmit;
|
*ppSubmit = pSubmit;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -58,7 +58,7 @@ int32_t tqExecFromInputQ(STQ* pTq, STqHandle* pHandle) {
|
||||||
}
|
}
|
||||||
while (pHandle->pushHandle.processedVer > pSubmit->ver + 1) {
|
while (pHandle->pushHandle.processedVer > pSubmit->ver + 1) {
|
||||||
streamQueueProcessSuccess(&pHandle->pushHandle.inputQ);
|
streamQueueProcessSuccess(&pHandle->pushHandle.inputQ);
|
||||||
streamDataSubmitRefDec(pSubmit);
|
streamDataSubmitDestroy(pSubmit);
|
||||||
pSubmit = streamQueueNextItem(&pHandle->pushHandle.inputQ);
|
pSubmit = streamQueueNextItem(&pHandle->pushHandle.inputQ);
|
||||||
if (pSubmit == NULL) break;
|
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) {
|
int32_t tqEnqueue(STqHandle* pHandle, SStreamDataSubmit* pSubmit) {
|
||||||
int8_t inputStatus = atomic_load_8(&pHandle->pushHandle.inputStatus);
|
int8_t inputStatus = atomic_load_8(&pHandle->pushHandle.inputStatus);
|
||||||
if (inputStatus == TASK_INPUT_STATUS__NORMAL) {
|
if (inputStatus == TASK_INPUT_STATUS__NORMAL) {
|
||||||
SStreamDataSubmit* pSubmitClone = streamSubmitRefClone(pSubmit);
|
SStreamDataSubmit* pSubmitClone = streamSubmitBlockClone(pSubmit);
|
||||||
if (pSubmitClone == NULL) {
|
if (pSubmitClone == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -212,28 +212,13 @@ typedef struct {
|
||||||
} SItem;
|
} SItem;
|
||||||
|
|
||||||
static void recordPushedEntry(SArray* cachedKey, void* pIter);
|
static void recordPushedEntry(SArray* cachedKey, void* pIter);
|
||||||
|
static void doRemovePushedEntry(SArray* pCachedKeys, STQ* pTq);
|
||||||
|
|
||||||
static void freeItem(void* param) {
|
static void freeItem(void* param) {
|
||||||
SItem* p = (SItem*)param;
|
SItem* p = (SItem*)param;
|
||||||
taosMemoryFree(p->pKey);
|
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,
|
static void doPushDataForEntry(void* pIter, STqExecHandle* pExec, STQ* pTq, int64_t ver, int32_t vgId, char* pData,
|
||||||
int32_t dataLen, SArray* pCachedKey) {
|
int32_t dataLen, SArray* pCachedKey) {
|
||||||
STqPushEntry* pPushEntry = *(STqPushEntry**)pIter;
|
STqPushEntry* pPushEntry = *(STqPushEntry**)pIter;
|
||||||
|
@ -253,7 +238,7 @@ static void doPushDataForEntry(void* pIter, STqExecHandle* pExec, STQ* pTq, int6
|
||||||
if (qStreamSetScanMemData(pTaskInfo, submit) != 0) {
|
if (qStreamSetScanMemData(pTaskInfo, submit) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
qStreamSetOpen(pTaskInfo);
|
||||||
// here start to scan submit block to extract the subscribed data
|
// here start to scan submit block to extract the subscribed data
|
||||||
int32_t totalRows = 0;
|
int32_t totalRows = 0;
|
||||||
|
|
||||||
|
@ -348,7 +333,7 @@ int32_t tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t v
|
||||||
void* data = taosMemoryMalloc(len);
|
void* data = taosMemoryMalloc(len);
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,13 +352,6 @@ int32_t tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t v
|
||||||
return 0;
|
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 tqRegisterPushEntry(STQ* pTq, void* pHandle, const SMqPollReq* pRequest, SRpcMsg* pRpcMsg, SMqDataRsp* pDataRsp,
|
||||||
int32_t type) {
|
int32_t type) {
|
||||||
uint64_t consumerId = pRequest->consumerId;
|
uint64_t consumerId = pRequest->consumerId;
|
||||||
|
@ -431,3 +409,26 @@ int32_t tqUnregisterPushEntry(STQ* pTq, const char* pKey, int32_t keyLen, uint64
|
||||||
|
|
||||||
return 0;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -263,7 +263,7 @@ STqReader* tqOpenReader(SVnode* pVnode) {
|
||||||
|
|
||||||
pReader->pVnodeMeta = pVnode->pMeta;
|
pReader->pVnodeMeta = pVnode->pMeta;
|
||||||
/*pReader->pMsg = NULL;*/
|
/*pReader->pMsg = NULL;*/
|
||||||
pReader->ver = -1;
|
// pReader->ver = -1;
|
||||||
pReader->pColIdList = NULL;
|
pReader->pColIdList = NULL;
|
||||||
pReader->cachedSchemaVer = 0;
|
pReader->cachedSchemaVer = 0;
|
||||||
pReader->cachedSchemaSuid = 0;
|
pReader->cachedSchemaSuid = 0;
|
||||||
|
@ -290,41 +290,26 @@ void tqCloseReader(STqReader* pReader) {
|
||||||
}
|
}
|
||||||
// free hash
|
// free hash
|
||||||
taosHashCleanup(pReader->tbIdHash);
|
taosHashCleanup(pReader->tbIdHash);
|
||||||
|
tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
|
||||||
taosMemoryFree(pReader);
|
taosMemoryFree(pReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqSeekVer(STqReader* pReader, int64_t ver, const char* id) {
|
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) {
|
if (walReadSeekVer(pReader->pWalReader, ver) < 0) {
|
||||||
tqDebug("tmq poll: wal reader failed to seek to ver:%"PRId64" code:%s, %s", ver, tstrerror(terrno), id);
|
tqDebug("tmq poll: wal reader failed to seek to ver:%"PRId64" code:%s, %s", ver, tstrerror(terrno), id);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
}
|
||||||
tqDebug("tmq poll: wal reader seek to ver:%"PRId64" %s", ver, id);
|
tqDebug("tmq poll: wal reader seek to ver:%"PRId64" %s", ver, id);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
|
||||||
bool fromProcessedMsg = pReader->msg2.msgStr != NULL;
|
|
||||||
|
|
||||||
|
void tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!fromProcessedMsg) {
|
if (pReader->msg2.msgStr == NULL) {
|
||||||
if (walNextValidMsg(pReader->pWalReader) < 0) {
|
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;
|
ret->fetchType = FETCH_TYPE__NONE;
|
||||||
tqDebug("return offset %" PRId64 ", no more valid msg in wal", ret->offset.version);
|
return;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void* body = POINTER_SHIFT(pReader->pWalReader->pHead->head.body, sizeof(SSubmitReq2Msg));
|
void* body = POINTER_SHIFT(pReader->pWalReader->pHead->head.body, sizeof(SSubmitReq2Msg));
|
||||||
int32_t bodyLen = pReader->pWalReader->pHead->head.bodyLen - sizeof(SSubmitReq2Msg);
|
int32_t bodyLen = pReader->pWalReader->pHead->head.bodyLen - sizeof(SSubmitReq2Msg);
|
||||||
int64_t ver = pReader->pWalReader->pHead->head.version;
|
int64_t ver = pReader->pWalReader->pHead->head.version;
|
||||||
|
@ -333,109 +318,44 @@ int32_t tqNextBlock(STqReader* pReader, SFetchRet* ret) {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (tqNextDataBlock2(pReader)) {
|
while (tqNextDataBlock2(pReader)) {
|
||||||
// TODO mem free
|
|
||||||
memset(&ret->data, 0, sizeof(SSDataBlock));
|
memset(&ret->data, 0, sizeof(SSDataBlock));
|
||||||
int32_t code = tqRetrieveDataBlock2(&ret->data, pReader, NULL);
|
int32_t code = tqRetrieveDataBlock2(&ret->data, pReader, NULL);
|
||||||
if (code != 0 || ret->data.info.rows == 0) {
|
if (code != 0 || ret->data.info.rows == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ret->fetchType = FETCH_TYPE__DATA;
|
ret->fetchType = FETCH_TYPE__DATA;
|
||||||
tqDebug("return data rows %" PRId64, ret->data.info.rows);
|
return;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#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) {
|
int32_t tqReaderSetSubmitReq2(STqReader* pReader, void* msgStr, int32_t msgLen, int64_t ver) {
|
||||||
ASSERT(pReader->msg2.msgStr == NULL && msgStr && msgLen && (ver >= 0));
|
|
||||||
|
|
||||||
pReader->msg2.msgStr = msgStr;
|
pReader->msg2.msgStr = msgStr;
|
||||||
pReader->msg2.msgLen = msgLen;
|
pReader->msg2.msgLen = msgLen;
|
||||||
pReader->msg2.ver = ver;
|
pReader->msg2.ver = ver;
|
||||||
pReader->ver = ver;
|
|
||||||
|
|
||||||
tqDebug("tq reader set msg %p %d", msgStr, msgLen);
|
tqDebug("tq reader set msg %p %d", msgStr, msgLen);
|
||||||
|
|
||||||
if (pReader->setMsg == 0) {
|
|
||||||
SDecoder decoder;
|
SDecoder decoder;
|
||||||
tDecoderInit(&decoder, pReader->msg2.msgStr, pReader->msg2.msgLen);
|
tDecoderInit(&decoder, pReader->msg2.msgStr, pReader->msg2.msgLen);
|
||||||
if (tDecodeSSubmitReq2(&decoder, &pReader->submit) < 0) {
|
if (tDecodeSSubmitReq2(&decoder, &pReader->submit) < 0) {
|
||||||
ASSERT(0);
|
tDecoderClear(&decoder);
|
||||||
|
tqError("DecodeSSubmitReq2 error, msgLen:%d, ver:%"PRId64, msgLen, ver);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
tDecoderClear(&decoder);
|
tDecoderClear(&decoder);
|
||||||
pReader->setMsg = 1;
|
|
||||||
}
|
|
||||||
return 0;
|
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) {
|
bool tqNextDataBlock2(STqReader* pReader) {
|
||||||
if (pReader->msg2.msgStr == NULL) {
|
if (pReader->msg2.msgStr == NULL) {
|
||||||
return false;
|
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);
|
int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
|
||||||
while (pReader->nextBlk < blockSz) {
|
while (pReader->nextBlk < blockSz) {
|
||||||
|
tqDebug("tq reader next data block %p, %d %" PRId64 " %d", pReader->msg2.msgStr, pReader->msg2.msgLen,
|
||||||
|
pReader->msg2.ver, pReader->nextBlk);
|
||||||
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
|
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
|
||||||
ASSERT(pSubmitTbData->uid);
|
|
||||||
|
|
||||||
if (pReader->tbIdHash == NULL) return true;
|
if (pReader->tbIdHash == NULL) return true;
|
||||||
|
|
||||||
void* ret = taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t));
|
void* ret = taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t));
|
||||||
|
@ -446,7 +366,6 @@ bool tqNextDataBlock2(STqReader* pReader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
|
tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
|
||||||
pReader->setMsg = 0;
|
|
||||||
pReader->nextBlk = 0;
|
pReader->nextBlk = 0;
|
||||||
pReader->msg2.msgStr = NULL;
|
pReader->msg2.msgStr = NULL;
|
||||||
|
|
||||||
|
@ -455,7 +374,6 @@ bool tqNextDataBlock2(STqReader* pReader) {
|
||||||
|
|
||||||
bool tqNextDataBlockFilterOut2(STqReader* pReader, SHashObj* filterOutUids) {
|
bool tqNextDataBlockFilterOut2(STqReader* pReader, SHashObj* filterOutUids) {
|
||||||
if (pReader->msg2.msgStr == NULL) return false;
|
if (pReader->msg2.msgStr == NULL) return false;
|
||||||
ASSERT(pReader->setMsg == 1);
|
|
||||||
|
|
||||||
int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
|
int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
|
||||||
while (pReader->nextBlk < blockSz) {
|
while (pReader->nextBlk < blockSz) {
|
||||||
|
@ -470,7 +388,6 @@ bool tqNextDataBlockFilterOut2(STqReader* pReader, SHashObj* filterOutUids) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
|
tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
|
||||||
pReader->setMsg = 0;
|
|
||||||
pReader->nextBlk = 0;
|
pReader->nextBlk = 0;
|
||||||
pReader->msg2.msgStr = NULL;
|
pReader->msg2.msgStr = NULL;
|
||||||
|
|
||||||
|
@ -506,63 +423,8 @@ int32_t tqMaskBlock(SSchemaWrapper* pDst, SSDataBlock* pBlock, const SSchemaWrap
|
||||||
return 0;
|
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 tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbData** pSubmitTbDataRet) {
|
||||||
int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
|
tqDebug("tq reader retrieve data block %p, index:%d", pReader->msg2.msgStr, pReader->nextBlk);
|
||||||
ASSERT(pReader->nextBlk < blockSz);
|
|
||||||
|
|
||||||
tqDebug("tq reader retrieve data block %p, %d", pReader->msg2.msgStr, pReader->nextBlk);
|
|
||||||
|
|
||||||
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
|
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
|
||||||
pReader->nextBlk++;
|
pReader->nextBlk++;
|
||||||
|
|
||||||
|
@ -666,33 +528,27 @@ int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbD
|
||||||
int32_t targetIdx = 0;
|
int32_t targetIdx = 0;
|
||||||
int32_t sourceIdx = 0;
|
int32_t sourceIdx = 0;
|
||||||
while (targetIdx < colActual) {
|
while (targetIdx < colActual) {
|
||||||
ASSERT(sourceIdx < numOfCols);
|
if(sourceIdx >= numOfCols){
|
||||||
|
tqError("tqRetrieveDataBlock2 sourceIdx:%d >= numOfCols:%d", sourceIdx, numOfCols);
|
||||||
|
goto FAIL;
|
||||||
|
}
|
||||||
SColData* pCol = taosArrayGet(pCols, sourceIdx);
|
SColData* pCol = taosArrayGet(pCols, sourceIdx);
|
||||||
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
|
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
|
||||||
SColVal colVal;
|
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) {
|
if (pCol->cid < pColData->info.colId) {
|
||||||
sourceIdx++;
|
sourceIdx++;
|
||||||
} else if (pCol->cid == pColData->info.colId) {
|
} else if (pCol->cid == pColData->info.colId) {
|
||||||
for (int32_t i = 0; i < pCol->nVal; i++) {
|
for (int32_t i = 0; i < pCol->nVal; i++) {
|
||||||
tColDataGetValue(pCol, i, &colVal);
|
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 (IS_STR_DATA_TYPE(colVal.type)) {
|
||||||
if (colVal.value.pData != NULL) {
|
if (colVal.value.pData != NULL) {
|
||||||
char val[65535 + 2];
|
char val[65535 + 2] = {0};
|
||||||
memcpy(varDataVal(val), colVal.value.pData, colVal.value.nData);
|
memcpy(varDataVal(val), colVal.value.pData, colVal.value.nData);
|
||||||
varDataSetLen(val, colVal.value.nData);
|
varDataSetLen(val, colVal.value.nData);
|
||||||
if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
||||||
|
@ -726,8 +582,6 @@ int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbD
|
||||||
for (int32_t j = 0; j < colActual; j++) {
|
for (int32_t j = 0; j < colActual; j++) {
|
||||||
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, j);
|
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, j);
|
||||||
while (1) {
|
while (1) {
|
||||||
ASSERT(sourceIdx < pTschema->numOfCols);
|
|
||||||
|
|
||||||
SColVal colVal;
|
SColVal colVal;
|
||||||
tRowGet(pRow, pTschema, sourceIdx, &colVal);
|
tRowGet(pRow, pTschema, sourceIdx, &colVal);
|
||||||
if (colVal.cid < pColData->info.colId) {
|
if (colVal.cid < pColData->info.colId) {
|
||||||
|
@ -736,7 +590,7 @@ int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbD
|
||||||
} else if (colVal.cid == pColData->info.colId) {
|
} else if (colVal.cid == pColData->info.colId) {
|
||||||
if (IS_STR_DATA_TYPE(colVal.type)) {
|
if (IS_STR_DATA_TYPE(colVal.type)) {
|
||||||
if (colVal.value.pData != NULL) {
|
if (colVal.value.pData != NULL) {
|
||||||
char val[65535 + 2];
|
char val[65535 + 2] = {0};
|
||||||
memcpy(varDataVal(val), colVal.value.pData, colVal.value.nData);
|
memcpy(varDataVal(val), colVal.value.pData, colVal.value.nData);
|
||||||
varDataSetLen(val, colVal.value.nData);
|
varDataSetLen(val, colVal.value.nData);
|
||||||
if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
||||||
|
@ -745,7 +599,6 @@ int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbD
|
||||||
} else {
|
} else {
|
||||||
colDataSetNULL(pColData, i);
|
colDataSetNULL(pColData, i);
|
||||||
}
|
}
|
||||||
/*val = colVal.value.pData;*/
|
|
||||||
} else {
|
} else {
|
||||||
if (colDataAppend(pColData, i, (void*)&colVal.value.val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
if (colDataAppend(pColData, i, (void*)&colVal.value.val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
|
@ -771,253 +624,6 @@ FAIL:
|
||||||
return -1;
|
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) {
|
int32_t tqRetrieveTaosxBlock2(STqReader* pReader, SArray* blocks, SArray* schemas, SSubmitTbData** pSubmitTbDataRet) {
|
||||||
tqDebug("tq reader retrieve data block %p, %d", pReader->msg2.msgStr, pReader->nextBlk);
|
tqDebug("tq reader retrieve data block %p, %d", pReader->msg2.msgStr, pReader->nextBlk);
|
||||||
|
|
||||||
|
|
|
@ -74,33 +74,23 @@ int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffs
|
||||||
qTaskInfo_t task = pExec->task;
|
qTaskInfo_t task = pExec->task;
|
||||||
|
|
||||||
if (qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType) < 0) {
|
if (qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType) < 0) {
|
||||||
tqDebug("prepare scan failed, vgId:%d, consumer:0x%" PRIx64, vgId, pHandle->consumerId);
|
tqError("prepare scan failed, return");
|
||||||
if (pOffset->type == TMQ_OFFSET__LOG) {
|
return -1;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
SSDataBlock* pDataBlock = NULL;
|
SSDataBlock* pDataBlock = NULL;
|
||||||
uint64_t ts = 0;
|
uint64_t ts = 0;
|
||||||
|
qStreamSetOpen(task);
|
||||||
tqDebug("vgId:%d, tmq task start to execute, consumer:0x%" PRIx64, vgId, pHandle->consumerId);
|
tqDebug("consumer:0x%" PRIx64 " vgId:%d, tmq one task start execute", pHandle->consumerId, vgId);
|
||||||
|
if (qExecTask(task, &pDataBlock, &ts) != TSDB_CODE_SUCCESS) {
|
||||||
code = qExecTask(task, &pDataBlock, &ts);
|
tqError("consumer:0x%" PRIx64 " vgId:%d, task exec error since %s", pHandle->consumerId, vgId, terrstr());
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
return -1;
|
||||||
tqError("vgId:%d, task exec error since %s, consumer:0x%" PRIx64, vgId, terrstr(), pHandle->consumerId);
|
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
if (pDataBlock == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -112,37 +102,16 @@ int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffs
|
||||||
}
|
}
|
||||||
|
|
||||||
pRsp->blockNum++;
|
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;
|
totalRows += pDataBlock->info.rows;
|
||||||
if (totalRows >= MAX_ROWS_TO_RETURN) {
|
if (totalRows >= MAX_ROWS_TO_RETURN) {
|
||||||
break;
|
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);
|
qStreamExtractOffset(task, &pRsp->rspOffset);
|
||||||
|
return 0;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMetaRsp* pMetaRsp, STqOffsetVal* pOffset) {
|
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;
|
qTaskInfo_t task = pExec->task;
|
||||||
|
|
||||||
if (qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType) < 0) {
|
if (qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType) < 0) {
|
||||||
tqDebug("prepare scan failed, return");
|
tqDebug("tqScanTaosx prepare scan failed, return");
|
||||||
if (pOffset->type == TMQ_OFFSET__LOG) {
|
return -1;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t rowCnt = 0;
|
int32_t rowCnt = 0;
|
||||||
|
@ -207,42 +166,32 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMeta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pDataBlock == NULL && pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
|
// get meta
|
||||||
if (qStreamExtractPrepareUid(task) != 0) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
tqDebug("tmqsnap vgId: %d, tsdb consume over, switch to wal, ver %" PRId64, TD_VID(pTq->pVnode),
|
tqDebug("tmqsnap vgId: %d, tsdb consume over, switch to wal, ver %" PRId64, TD_VID(pTq->pVnode),
|
||||||
pHandle->snapshotVer + 1);
|
pHandle->snapshotVer + 1);
|
||||||
|
qStreamExtractOffset(task, &pRsp->rspOffset);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRsp->blockNum > 0) {
|
if (pRsp->blockNum > 0) {
|
||||||
tqDebug("tmqsnap task exec exited, get data");
|
tqDebug("tmqsnap task exec exited, get data");
|
||||||
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);
|
qStreamExtractOffset(task, &pRsp->rspOffset);
|
||||||
|
break;
|
||||||
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;
|
return 0;
|
||||||
|
|
|
@ -1969,7 +1969,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (pReader->order == TSDB_ORDER_ASC) {
|
if (pReader->order == TSDB_ORDER_ASC) {
|
||||||
if (minKey == key) {
|
if (minKey == key) {
|
||||||
init = true;
|
init = true;
|
||||||
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1979,10 +1979,10 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == tsLast) {
|
if (minKey == tsLast) {
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
if (init) {
|
if (init) {
|
||||||
tsdbRowMerge(&merge, &fRow1);
|
tsdbRowMergerAdd(&merge, &fRow1, NULL);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
int32_t code = tsdbRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow1, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1999,7 +1999,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
tsdbRowMergerAdd(&merge, pRow, pSchema);
|
tsdbRowMergerAdd(&merge, pRow, pSchema);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
int32_t code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2013,7 +2013,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == k.ts) {
|
if (minKey == k.ts) {
|
||||||
init = true;
|
init = true;
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
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) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2027,10 +2027,10 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == tsLast) {
|
if (minKey == tsLast) {
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
if (init) {
|
if (init) {
|
||||||
tsdbRowMerge(&merge, &fRow1);
|
tsdbRowMergerAdd(&merge, &fRow1, NULL);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
int32_t code = tsdbRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow1, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2040,10 +2040,10 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
|
|
||||||
if (minKey == key) {
|
if (minKey == key) {
|
||||||
if (init) {
|
if (init) {
|
||||||
tsdbRowMerge(&merge, &fRow);
|
tsdbRowMergerAdd(&merge, &fRow, NULL);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2088,13 +2088,13 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
||||||
pBlockScanInfo->lastKey = tsLastBlock;
|
pBlockScanInfo->lastKey = tsLastBlock;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
tsdbRowMerge(&merge, &fRow1);
|
tsdbRowMergerAdd(&merge, &fRow1, NULL);
|
||||||
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge, &pReader->verRange, pReader->idStr);
|
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge, &pReader->verRange, pReader->idStr);
|
||||||
|
|
||||||
code = tsdbRowMergerGetRow(&merge, &pTSRow);
|
code = tsdbRowMergerGetRow(&merge, &pTSRow);
|
||||||
|
@ -2112,7 +2112,7 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // not merge block data
|
} else { // not merge block data
|
||||||
int32_t code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2164,7 +2164,7 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader
|
||||||
SRow* pTSRow = NULL;
|
SRow* pTSRow = NULL;
|
||||||
SRowMerger merge = {0};
|
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) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2172,7 +2172,7 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader
|
||||||
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
||||||
|
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
tsdbRowMerge(&merge, &fRow1);
|
tsdbRowMergerAdd(&merge, &fRow1, NULL);
|
||||||
|
|
||||||
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, ts, &merge, &pReader->verRange, pReader->idStr);
|
doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, ts, &merge, &pReader->verRange, pReader->idStr);
|
||||||
|
|
||||||
|
@ -2217,6 +2217,14 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
|
|
||||||
TSDBKEY k = TSDBROW_KEY(pRow);
|
TSDBKEY k = TSDBROW_KEY(pRow);
|
||||||
TSDBKEY ik = TSDBROW_KEY(piRow);
|
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;
|
int64_t minKey = 0;
|
||||||
if (ASCENDING_TRAVERSE(pReader->order)) {
|
if (ASCENDING_TRAVERSE(pReader->order)) {
|
||||||
|
@ -2263,7 +2271,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == key) {
|
if (minKey == key) {
|
||||||
init = true;
|
init = true;
|
||||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
||||||
code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2274,10 +2282,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == tsLast) {
|
if (minKey == tsLast) {
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
if (init) {
|
if (init) {
|
||||||
tsdbRowMerge(&merge, &fRow1);
|
tsdbRowMergerAdd(&merge, &fRow1, NULL);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
code = tsdbRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
code = tsdbRowMergerInit(&merge, NULL, &fRow1, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2288,15 +2296,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
|
|
||||||
if (minKey == ik.ts) {
|
if (minKey == ik.ts) {
|
||||||
if (init) {
|
if (init) {
|
||||||
tsdbRowMerge(&merge, piRow);
|
tsdbRowMergerAdd(&merge, piRow, piSchema);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
code = tsdbRowMergerInit(&merge, pSchema, piRow, piSchema);
|
||||||
if (pSchema == NULL) {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = tsdbRowMergerInit(&merge, piRow, pSchema);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2315,10 +2318,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbRowMerge(&merge, pRow);
|
tsdbRowMergerAdd(&merge, pRow, pSchema);
|
||||||
} else {
|
} else {
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
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) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2332,8 +2335,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
} else {
|
} else {
|
||||||
if (minKey == k.ts) {
|
if (minKey == k.ts) {
|
||||||
init = true;
|
init = true;
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
|
||||||
code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2347,11 +2349,11 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
|
|
||||||
if (minKey == ik.ts) {
|
if (minKey == ik.ts) {
|
||||||
if (init) {
|
if (init) {
|
||||||
tsdbRowMerge(&merge, piRow);
|
tsdbRowMergerAdd(&merge, piRow, piSchema);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
||||||
code = tsdbRowMergerInit(&merge, piRow, pSchema);
|
code = tsdbRowMergerInit(&merge, pSchema, piRow, piSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2366,10 +2368,10 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == tsLast) {
|
if (minKey == tsLast) {
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
if (init) {
|
if (init) {
|
||||||
tsdbRowMerge(&merge, &fRow1);
|
tsdbRowMergerAdd(&merge, &fRow1, NULL);
|
||||||
} else {
|
} else {
|
||||||
init = true;
|
init = true;
|
||||||
code = tsdbRowMergerInit(&merge, &fRow1, pReader->pSchema);
|
code = tsdbRowMergerInit(&merge, NULL, &fRow1, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2380,7 +2382,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (minKey == key) {
|
if (minKey == key) {
|
||||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
|
||||||
if (!init) {
|
if (!init) {
|
||||||
code = tsdbRowMergerInit(&merge, &fRow, pReader->pSchema);
|
code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2388,7 +2390,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
|
||||||
if (merge.pTSchema == NULL) {
|
if (merge.pTSchema == NULL) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
tsdbRowMerge(&merge, &fRow);
|
tsdbRowMergerAdd(&merge, &fRow, NULL);
|
||||||
}
|
}
|
||||||
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
|
||||||
}
|
}
|
||||||
|
@ -2573,7 +2575,7 @@ int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBloc
|
||||||
SRow* pTSRow = NULL;
|
SRow* pTSRow = NULL;
|
||||||
SRowMerger merge = {0};
|
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) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3694,7 +3696,7 @@ int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDe
|
||||||
|
|
||||||
tsdbRowMergerAdd(pMerger, pRow, pTSchema);
|
tsdbRowMergerAdd(pMerger, pRow, pTSchema);
|
||||||
} else { // column format
|
} else { // column format
|
||||||
tsdbRowMerge(pMerger, pRow);
|
tsdbRowMergerAdd(pMerger, pRow, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3710,7 +3712,7 @@ static int32_t doMergeRowsInFileBlockImpl(SBlockData* pBlockData, int32_t rowInd
|
||||||
}
|
}
|
||||||
|
|
||||||
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, rowIndex);
|
TSDBROW fRow = tsdbRowFromBlockData(pBlockData, rowIndex);
|
||||||
tsdbRowMerge(pMerger, &fRow);
|
tsdbRowMergerAdd(pMerger, &fRow, NULL);
|
||||||
rowIndex += step;
|
rowIndex += step;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3788,7 +3790,7 @@ int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockSc
|
||||||
int64_t next1 = getCurrentKeyInLastBlock(pLastBlockReader);
|
int64_t next1 = getCurrentKeyInLastBlock(pLastBlockReader);
|
||||||
if (next1 == ts) {
|
if (next1 == ts) {
|
||||||
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
|
||||||
tsdbRowMerge(pMerger, &fRow1);
|
tsdbRowMergerAdd(pMerger, &fRow1, NULL);
|
||||||
} else {
|
} else {
|
||||||
tsdbTrace("uid:%" PRIu64 " last del index:%d, del range:%d, lastKeyInStt:%" PRId64 ", %s", pScanInfo->uid,
|
tsdbTrace("uid:%" PRIu64 " last del index:%d, del range:%d, lastKeyInStt:%" PRId64 ", %s", pScanInfo->uid,
|
||||||
pScanInfo->lastBlockDelIndex, (int32_t)taosArrayGetSize(pScanInfo->delSkyline), pScanInfo->lastKeyInStt,
|
pScanInfo->lastBlockDelIndex, (int32_t)taosArrayGetSize(pScanInfo->delSkyline), pScanInfo->lastKeyInStt,
|
||||||
|
@ -3844,7 +3846,7 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
|
||||||
pReader->pSchema = pTSchema;
|
pReader->pSchema = pTSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tsdbRowMergerInit2(&merge, pReader->pSchema, ¤t, pTSchema);
|
code = tsdbRowMergerInit(&merge, pReader->pSchema, ¤t, pTSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3856,12 +3858,12 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
|
||||||
|
|
||||||
tsdbRowMergerAdd(&merge, pNextRow, pTSchema1);
|
tsdbRowMergerAdd(&merge, pNextRow, pTSchema1);
|
||||||
} else { // let's merge rows in file block
|
} 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) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbRowMerge(&merge, pNextRow);
|
tsdbRowMergerAdd(&merge, pNextRow, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = doMergeRowsInBuf(pIter, uid, TSDBROW_TS(¤t), pDelList, &merge, pReader);
|
code = doMergeRowsInBuf(pIter, uid, TSDBROW_TS(¤t), pDelList, &merge, pReader);
|
||||||
|
@ -3887,12 +3889,11 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
||||||
|
|
||||||
TSDBKEY k = TSDBROW_KEY(pRow);
|
TSDBKEY k = TSDBROW_KEY(pRow);
|
||||||
TSDBKEY ik = TSDBROW_KEY(piRow);
|
TSDBKEY ik = TSDBROW_KEY(piRow);
|
||||||
|
|
||||||
if (ASCENDING_TRAVERSE(pReader->order)) { // ascending order imem --> mem
|
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
||||||
STSchema* piSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
STSchema* piSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
|
||||||
|
|
||||||
int32_t code = tsdbRowMergerInit2(&merge, pSchema, piRow, piSchema);
|
if (ASCENDING_TRAVERSE(pReader->order)) { // ascending order imem --> mem
|
||||||
|
int32_t code = tsdbRowMergerInit(&merge, pSchema, piRow, piSchema);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3911,9 +3912,7 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
|
int32_t code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
|
||||||
|
|
||||||
int32_t code = tsdbRowMergerInit(&merge, pRow, pSchema);
|
|
||||||
if (code != TSDB_CODE_SUCCESS || merge.pTSchema == NULL) {
|
if (code != TSDB_CODE_SUCCESS || merge.pTSchema == NULL) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3924,7 +3923,7 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbRowMerge(&merge, piRow);
|
tsdbRowMergerAdd(&merge, piRow, piSchema);
|
||||||
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, &merge,
|
code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, &merge,
|
||||||
pReader);
|
pReader);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
|
|
@ -638,13 +638,17 @@ SColVal *tsdbRowIterNext(STSDBRowIter *pIter) {
|
||||||
|
|
||||||
// SRowMerger ======================================================
|
// 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;
|
int32_t code = 0;
|
||||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||||
SColVal *pColVal = &(SColVal){0};
|
SColVal *pColVal = &(SColVal){0};
|
||||||
STColumn *pTColumn;
|
STColumn *pTColumn;
|
||||||
int32_t iCol, jCol = 0;
|
int32_t iCol, jCol = 0;
|
||||||
|
|
||||||
|
if (NULL == pResTSchema) {
|
||||||
|
pResTSchema = pTSchema;
|
||||||
|
}
|
||||||
|
|
||||||
pMerger->pTSchema = pResTSchema;
|
pMerger->pTSchema = pResTSchema;
|
||||||
pMerger->version = key.version;
|
pMerger->version = key.version;
|
||||||
|
|
||||||
|
@ -712,6 +716,9 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
||||||
STColumn *pTColumn;
|
STColumn *pTColumn;
|
||||||
int32_t iCol, jCol = 1;
|
int32_t iCol, jCol = 1;
|
||||||
|
|
||||||
|
if (NULL == pTSchema) {
|
||||||
|
pTSchema = pMerger->pTSchema;
|
||||||
|
}
|
||||||
ASSERT(((SColVal *)pMerger->pArray->pData)->value.val == key.ts);
|
ASSERT(((SColVal *)pMerger->pArray->pData)->value.val == key.ts);
|
||||||
|
|
||||||
for (iCol = 1; iCol < pMerger->pTSchema->numOfCols && jCol < pTSchema->numOfCols; ++iCol) {
|
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);
|
tsdbRowGetColVal(pRow, pTSchema, jCol++, pColVal);
|
||||||
|
|
||||||
if (key.version > pMerger->version) {
|
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 (!COL_VAL_IS_NONE(pColVal)) {
|
||||||
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
if (IS_VAR_DATA_TYPE(pColVal->type)) {
|
||||||
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||||
|
@ -758,7 +748,6 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
||||||
pTColVal->flag = 0;
|
pTColVal->flag = 0;
|
||||||
} else {
|
} else {
|
||||||
tFree(pTColVal->value.pData);
|
tFree(pTColVal->value.pData);
|
||||||
pTColVal->value.pData = NULL;
|
|
||||||
taosArraySet(pMerger->pArray, iCol, pColVal);
|
taosArraySet(pMerger->pArray, iCol, pColVal);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -789,7 +778,7 @@ int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema)
|
||||||
pMerger->version = key.version;
|
pMerger->version = key.version;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||||
|
@ -840,7 +829,7 @@ int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema
|
||||||
_exit:
|
_exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
void tsdbRowMergerClear(SRowMerger *pMerger) {
|
void tsdbRowMergerClear(SRowMerger *pMerger) {
|
||||||
for (int32_t iCol = 1; iCol < pMerger->pTSchema->numOfCols; iCol++) {
|
for (int32_t iCol = 1; iCol < pMerger->pTSchema->numOfCols; iCol++) {
|
||||||
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
|
||||||
|
@ -851,7 +840,7 @@ void tsdbRowMergerClear(SRowMerger *pMerger) {
|
||||||
|
|
||||||
taosArrayDestroy(pMerger->pArray);
|
taosArrayDestroy(pMerger->pArray);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow) {
|
int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
TSDBKEY key = TSDBROW_KEY(pRow);
|
TSDBKEY key = TSDBROW_KEY(pRow);
|
||||||
|
@ -916,7 +905,7 @@ int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow) {
|
||||||
_exit:
|
_exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow) {
|
int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow) {
|
||||||
return tRowBuild(pMerger->pArray, pMerger->pTSchema, ppRow);
|
return tRowBuild(pMerger->pArray, pMerger->pTSchema, ppRow);
|
||||||
}
|
}
|
||||||
|
|
|
@ -541,6 +541,7 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
|
||||||
return vnodeGetBatchMeta(pVnode, pMsg);
|
return vnodeGetBatchMeta(pVnode, pMsg);
|
||||||
case TDMT_VND_TMQ_CONSUME:
|
case TDMT_VND_TMQ_CONSUME:
|
||||||
return tqProcessPollReq(pVnode->pTq, pMsg);
|
return tqProcessPollReq(pVnode->pTq, pMsg);
|
||||||
|
|
||||||
case TDMT_STREAM_TASK_RUN:
|
case TDMT_STREAM_TASK_RUN:
|
||||||
return tqProcessTaskRunReq(pVnode->pTq, pMsg);
|
return tqProcessTaskRunReq(pVnode->pTq, pMsg);
|
||||||
#if 1
|
#if 1
|
||||||
|
|
|
@ -8,7 +8,7 @@ target_include_directories(
|
||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
catalog
|
catalog
|
||||||
PRIVATE os util transport qcom
|
PRIVATE os util transport qcom nodes
|
||||||
)
|
)
|
||||||
|
|
||||||
if(${BUILD_TEST})
|
if(${BUILD_TEST})
|
||||||
|
|
|
@ -132,6 +132,19 @@ typedef struct SCtgCacheStat {
|
||||||
uint64_t cacheNHit[CTG_CI_MAX_VALUE];
|
uint64_t cacheNHit[CTG_CI_MAX_VALUE];
|
||||||
} SCtgCacheStat;
|
} 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 {
|
typedef struct SCtgTbCacheInfo {
|
||||||
bool inCache;
|
bool inCache;
|
||||||
uint64_t dbId;
|
uint64_t dbId;
|
||||||
|
@ -248,12 +261,8 @@ typedef struct SCtgRentMgmt {
|
||||||
} SCtgRentMgmt;
|
} SCtgRentMgmt;
|
||||||
|
|
||||||
typedef struct SCtgUserAuth {
|
typedef struct SCtgUserAuth {
|
||||||
int32_t version;
|
|
||||||
SRWLatch lock;
|
SRWLatch lock;
|
||||||
bool superUser;
|
SGetUserAuthRsp userAuth;
|
||||||
SHashObj* createdDbs;
|
|
||||||
SHashObj* readDbs;
|
|
||||||
SHashObj* writeDbs;
|
|
||||||
} SCtgUserAuth;
|
} SCtgUserAuth;
|
||||||
|
|
||||||
typedef struct SCatalog {
|
typedef struct SCatalog {
|
||||||
|
@ -538,7 +547,8 @@ typedef struct SCtgCacheItemInfo {
|
||||||
#define CTG_CACHE_HIT_INC(item, n) (CTG_STAT_INC(pCtg->cacheStat.cacheHit[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_CACHE_NHIT_INC(item, n) (CTG_STAT_INC(pCtg->cacheStat.cacheNHit[item], n))
|
||||||
|
|
||||||
#define CTG_META_NUM_INC(type) do { \
|
#define CTG_META_NUM_INC(type) \
|
||||||
|
do { \
|
||||||
switch (type) { \
|
switch (type) { \
|
||||||
case TSDB_SUPER_TABLE: \
|
case TSDB_SUPER_TABLE: \
|
||||||
CTG_DB_NUM_INC(CTG_CI_STABLE_META); \
|
CTG_DB_NUM_INC(CTG_CI_STABLE_META); \
|
||||||
|
@ -558,7 +568,8 @@ typedef struct SCtgCacheItemInfo {
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define CTG_META_NUM_DEC(type) do { \
|
#define CTG_META_NUM_DEC(type) \
|
||||||
|
do { \
|
||||||
switch (type) { \
|
switch (type) { \
|
||||||
case TSDB_SUPER_TABLE: \
|
case TSDB_SUPER_TABLE: \
|
||||||
CTG_DB_NUM_DEC(CTG_CI_STABLE_META); \
|
CTG_DB_NUM_DEC(CTG_CI_STABLE_META); \
|
||||||
|
@ -578,7 +589,8 @@ typedef struct SCtgCacheItemInfo {
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define CTG_META_HIT_INC(type) do { \
|
#define CTG_META_HIT_INC(type) \
|
||||||
|
do { \
|
||||||
switch (type) { \
|
switch (type) { \
|
||||||
case TSDB_SUPER_TABLE: \
|
case TSDB_SUPER_TABLE: \
|
||||||
CTG_CACHE_HIT_INC(CTG_CI_STABLE_META, 1); \
|
CTG_CACHE_HIT_INC(CTG_CI_STABLE_META, 1); \
|
||||||
|
@ -600,7 +612,6 @@ typedef struct SCtgCacheItemInfo {
|
||||||
|
|
||||||
#define CTG_META_NHIT_INC() CTG_CACHE_NHIT_INC(CTG_CI_OTHERTABLE_META, 1)
|
#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_NULL(type) ((type) == META_TYPE_NULL_TABLE)
|
||||||
#define CTG_IS_META_CTABLE(type) ((type) == META_TYPE_CTABLE)
|
#define CTG_IS_META_CTABLE(type) ((type) == META_TYPE_CTABLE)
|
||||||
#define CTG_IS_META_TABLE(type) ((type) == META_TYPE_TABLE)
|
#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 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 ctgTaskTrace(param, ...) qTrace("QID:%" PRIx64 " CTG:%p " param, pTask->pJob->queryId, pCtg, __VA_ARGS__)
|
||||||
|
|
||||||
|
|
||||||
#define CTG_LOCK_DEBUG(...) \
|
#define CTG_LOCK_DEBUG(...) \
|
||||||
do { \
|
do { \
|
||||||
if (gCTGDebug.lockEnable) { \
|
if (gCTGDebug.lockEnable) { \
|
||||||
|
@ -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 ctgReadTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta);
|
||||||
int32_t ctgReadTbVerFromCache(SCatalog* pCtg, SName* pTableName, int32_t* sver, int32_t* tver, int32_t* tbType,
|
int32_t ctgReadTbVerFromCache(SCatalog* pCtg, SName* pTableName, int32_t* sver, int32_t* tver, int32_t* tbType,
|
||||||
uint64_t* suid, char* stbName);
|
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 ctgDropDbCacheEnqueue(SCatalog* pCtg, const char* dbFName, int64_t dbId);
|
||||||
int32_t ctgDropDbVgroupEnqueue(SCatalog* pCtg, const char* dbFName, bool syncReq);
|
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,
|
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 ctgGetVgInfoFromHashValue(SCatalog* pCtg, SDBVgInfo* dbInfo, const SName* pTableName, SVgroupInfo* pVgroup);
|
||||||
int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SCtgTaskReq* tReq, SDBVgInfo* dbInfo, SCtgTbHashsCtx* pCtx,
|
int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SCtgTaskReq* tReq, SDBVgInfo* dbInfo, SCtgTbHashsCtx* pCtx,
|
||||||
char* dbFName, SArray* pNames, bool update);
|
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 ctgResetTbMetaTask(SCtgTask* pTask);
|
||||||
void ctgFreeDbCache(SCtgDBCache* dbCache);
|
void ctgFreeDbCache(SCtgDBCache* dbCache);
|
||||||
int32_t ctgStbVersionSortCompare(const void* key1, const void* key2);
|
int32_t ctgStbVersionSortCompare(const void* key1, const void* key2);
|
||||||
|
@ -900,16 +911,20 @@ void ctgFreeQNode(SCtgQNode* node);
|
||||||
void ctgClearHandle(SCatalog* pCtg);
|
void ctgClearHandle(SCatalog* pCtg);
|
||||||
void ctgFreeTbCacheImpl(SCtgTbCache* pCache);
|
void ctgFreeTbCacheImpl(SCtgTbCache* pCache);
|
||||||
int32_t ctgRemoveTbMeta(SCatalog* pCtg, SName* pTableName);
|
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);
|
SName* ctgGetFetchName(SArray* pNames, SCtgFetch* pFetch);
|
||||||
int32_t ctgdGetOneHandle(SCatalog** pHandle);
|
int32_t ctgdGetOneHandle(SCatalog** pHandle);
|
||||||
int ctgVgInfoComp(const void* lp, const void* rp);
|
int ctgVgInfoComp(const void* lp, const void* rp);
|
||||||
int32_t ctgMakeVgArray(SDBVgInfo* dbInfo);
|
int32_t ctgMakeVgArray(SDBVgInfo* dbInfo);
|
||||||
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,
|
||||||
int32_t ctgCopyTbMeta(SCatalog *pCtg, SCtgTbMetaCtx *ctx, SCtgDBCache **pDb, SCtgTbCache **pTb, STableMeta **pTableMeta, char* dbFName);
|
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 ctgReleaseVgMetaToCache(SCatalog* pCtg, SCtgDBCache* dbCache, SCtgTbCache* pCache);
|
||||||
void ctgReleaseTbMetaToCache(SCatalog* pCtg, SCtgDBCache* dbCache, SCtgTbCache* pCache);
|
void ctgReleaseTbMetaToCache(SCatalog* pCtg, SCtgDBCache* dbCache, SCtgTbCache* pCache);
|
||||||
void ctgGetGlobalCacheStat(SCtgCacheStat* pStat);
|
void ctgGetGlobalCacheStat(SCtgCacheStat* pStat);
|
||||||
|
int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res);
|
||||||
|
|
||||||
extern SCatalogMgmt gCtgMgmt;
|
extern SCatalogMgmt gCtgMgmt;
|
||||||
extern SCtgDebug gCTGDebug;
|
extern SCtgDebug gCTGDebug;
|
||||||
|
|
|
@ -319,14 +319,13 @@ _return:
|
||||||
CTG_RET(code);
|
CTG_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type,
|
int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, SUserAuthInfo *pReq, SUserAuthRes* pRes, bool* exists) {
|
||||||
bool* pass, bool* exists) {
|
|
||||||
bool inCache = false;
|
bool inCache = false;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
SCtgAuthRsp rsp = {0};
|
||||||
|
rsp.pRawRes = pRes;
|
||||||
|
|
||||||
*pass = false;
|
CTG_ERR_RET(ctgChkAuthFromCache(pCtg, pReq, &inCache, &rsp));
|
||||||
|
|
||||||
CTG_ERR_RET(ctgChkAuthFromCache(pCtg, (char*)user, (char*)dbFName, type, &inCache, pass));
|
|
||||||
|
|
||||||
if (inCache) {
|
if (inCache) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
|
@ -339,30 +338,22 @@ int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, co
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SGetUserAuthRsp authRsp = {0};
|
SCtgAuthReq req = {0};
|
||||||
CTG_ERR_RET(ctgGetUserDbAuthFromMnode(pCtg, pConn, user, &authRsp, NULL));
|
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) {
|
CTG_ERR_JRET(ctgChkSetAuthRes(pCtg, &req, &rsp));
|
||||||
*pass = true;
|
if (rsp.metaNotExists && exists) {
|
||||||
goto _return;
|
*exists = false;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_return:
|
_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) {
|
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);
|
void* key = taosHashGetKey(pAuth, &len);
|
||||||
strncpy((*users)[i].user, key, len);
|
strncpy((*users)[i].user, key, len);
|
||||||
(*users)[i].user[len] = 0;
|
(*users)[i].user[len] = 0;
|
||||||
(*users)[i].version = pAuth->version;
|
(*users)[i].version = pAuth->userAuth.version;
|
||||||
++i;
|
++i;
|
||||||
if (i >= *num) {
|
if (i >= *num) {
|
||||||
taosHashCancelIterate(pCtg->userCache, pAuth);
|
taosHashCancelIterate(pCtg->userCache, pAuth);
|
||||||
|
@ -1457,32 +1448,30 @@ _return:
|
||||||
CTG_API_LEAVE(code);
|
CTG_API_LEAVE(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type,
|
int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, SUserAuthInfo *pAuth, SUserAuthRes* pRes) {
|
||||||
bool* pass) {
|
|
||||||
CTG_API_ENTER();
|
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);
|
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = 0;
|
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:
|
_return:
|
||||||
|
|
||||||
CTG_API_LEAVE(code);
|
CTG_API_LEAVE(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t catalogChkAuthFromCache(SCatalog* pCtg, const char* user, const char* dbFName, AUTH_TYPE type,
|
int32_t catalogChkAuthFromCache(SCatalog* pCtg, SUserAuthInfo *pAuth, SUserAuthRes* pRes, bool* exists) {
|
||||||
bool* pass, bool* exists) {
|
|
||||||
CTG_API_ENTER();
|
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);
|
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = 0;
|
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:
|
_return:
|
||||||
|
|
||||||
|
|
|
@ -1550,45 +1550,20 @@ _return:
|
||||||
int32_t ctgHandleGetUserRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf* pMsg, int32_t rspCode) {
|
int32_t ctgHandleGetUserRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf* pMsg, int32_t rspCode) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SCtgTask* pTask = tReq->pTask;
|
SCtgTask* pTask = tReq->pTask;
|
||||||
SCtgUserCtx* ctx = (SCtgUserCtx*)pTask->taskCtx;
|
|
||||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||||
bool pass = false;
|
|
||||||
SGetUserAuthRsp* pOut = (SGetUserAuthRsp*)pTask->msgCtx.out;
|
SGetUserAuthRsp* pOut = (SGetUserAuthRsp*)pTask->msgCtx.out;
|
||||||
|
|
||||||
CTG_ERR_JRET(ctgProcessRspMsg(pTask->msgCtx.out, reqType, pMsg->pData, pMsg->len, rspCode, pTask->msgCtx.target));
|
CTG_ERR_JRET(ctgProcessRspMsg(pTask->msgCtx.out, reqType, pMsg->pData, pMsg->len, rspCode, pTask->msgCtx.target));
|
||||||
|
|
||||||
if (pOut->superAuth) {
|
ctgUpdateUserEnqueue(pCtg, pOut, true);
|
||||||
pass = true;
|
taosMemoryFreeClear(pTask->msgCtx.out);
|
||||||
goto _return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pOut->createdDbs && taosHashGet(pOut->createdDbs, ctx->user.dbFName, strlen(ctx->user.dbFName))) {
|
CTG_ERR_JRET((*gCtgAsyncFps[pTask->type].launchFp)(pTask));
|
||||||
pass = true;
|
|
||||||
goto _return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CTG_AUTH_READ(ctx->user.type) && pOut->readDbs &&
|
return TSDB_CODE_SUCCESS;
|
||||||
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:
|
_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);
|
ctgHandleTaskEnd(pTask, code);
|
||||||
|
|
||||||
CTG_RET(code);
|
CTG_RET(code);
|
||||||
|
@ -2081,30 +2056,38 @@ int32_t ctgLaunchGetUdfTask(SCtgTask* pTask) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ctgLaunchGetUserTask(SCtgTask* pTask) {
|
int32_t ctgLaunchGetUserTask(SCtgTask* pTask) {
|
||||||
|
int32_t code = 0;
|
||||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||||
SRequestConnInfo* pConn = &pTask->pJob->conn;
|
SRequestConnInfo* pConn = &pTask->pJob->conn;
|
||||||
SCtgUserCtx* pCtx = (SCtgUserCtx*)pTask->taskCtx;
|
SCtgUserCtx* pCtx = (SCtgUserCtx*)pTask->taskCtx;
|
||||||
bool inCache = false;
|
bool inCache = false;
|
||||||
bool pass = false;
|
SCtgAuthRsp rsp = {0};
|
||||||
SCtgJob* pJob = pTask->pJob;
|
SCtgJob* pJob = pTask->pJob;
|
||||||
SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, -1);
|
SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, -1);
|
||||||
if (NULL == pMsgCtx->pBatchs) {
|
if (NULL == pMsgCtx->pBatchs) {
|
||||||
pMsgCtx->pBatchs = pJob->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 (inCache) {
|
if (NULL == rsp.pRawRes) {
|
||||||
pTask->res = taosMemoryCalloc(1, sizeof(bool));
|
|
||||||
if (NULL == pTask->res) {
|
|
||||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
*(bool*)pTask->res = pass;
|
|
||||||
|
CTG_ERR_RET(ctgChkAuthFromCache(pCtg, &pCtx->user, &inCache, &rsp));
|
||||||
|
if (inCache) {
|
||||||
|
pTask->res = rsp.pRawRes;
|
||||||
|
|
||||||
CTG_ERR_RET(ctgHandleTaskEnd(pTask, 0));
|
CTG_ERR_RET(ctgHandleTaskEnd(pTask, 0));
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
CTG_ERR_RET(ctgGetUserDbAuthFromMnode(pCtg, pConn, pCtx->user.user, NULL, pTask));
|
||||||
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -2155,6 +2138,20 @@ _return:
|
||||||
CTG_RET(ctgHandleTaskEnd(pTask, pTask->subRes.code));
|
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) {
|
int32_t ctgCompDbVgTasks(SCtgTask* pTask, void* param, bool* equal) {
|
||||||
SCtgDbVgCtx* ctx = pTask->taskCtx;
|
SCtgDbVgCtx* ctx = pTask->taskCtx;
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,6 @@ SCtgCacheItemInfo gCtgStatItem[CTG_CI_MAX_VALUE] = {
|
||||||
{"SvrVer ", CTG_CI_FLAG_LEVEL_CLUSTER} // CTG_CI_SVR_VER,
|
{"SvrVer ", CTG_CI_FLAG_LEVEL_CLUSTER} // CTG_CI_SVR_VER,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int32_t ctgRLockVgInfo(SCatalog *pCtg, SCtgDBCache *dbCache, bool *inCache) {
|
int32_t ctgRLockVgInfo(SCatalog *pCtg, SCtgDBCache *dbCache, bool *inCache) {
|
||||||
CTG_LOCK(CTG_READ, &dbCache->vgCache.vgLock);
|
CTG_LOCK(CTG_READ, &dbCache->vgCache.vgLock);
|
||||||
|
|
||||||
|
@ -263,7 +262,8 @@ _return:
|
||||||
return TSDB_CODE_SUCCESS;
|
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;
|
SCtgDBCache *dbCache = NULL;
|
||||||
SCtgTbCache *tbCache = NULL;
|
SCtgTbCache *tbCache = NULL;
|
||||||
bool vgInCache = false;
|
bool vgInCache = false;
|
||||||
|
@ -331,7 +331,6 @@ _return:
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int32_t ctgAcquireStbMetaFromCache(SCatalog *pCtg, char *dbFName, uint64_t suid, SCtgDBCache **pDb, SCtgTbCache **pTb) {
|
int32_t ctgAcquireStbMetaFromCache(SCatalog *pCtg, char *dbFName, uint64_t suid, SCtgDBCache **pDb, SCtgTbCache **pTb) {
|
||||||
SCtgDBCache *dbCache = NULL;
|
SCtgDBCache *dbCache = NULL;
|
||||||
|
@ -385,7 +384,8 @@ _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;
|
SCtgTbCache *pCache = NULL;
|
||||||
char *stName = taosHashAcquire(dbCache->stbCache, &suid, sizeof(suid));
|
char *stName = taosHashAcquire(dbCache->stbCache, &suid, sizeof(suid));
|
||||||
if (NULL == stName) {
|
if (NULL == stName) {
|
||||||
|
@ -484,7 +484,8 @@ int32_t ctgTbMetaExistInCache(SCatalog *pCtg, char *dbFName, char *tbName, int32
|
||||||
return TSDB_CODE_SUCCESS;
|
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;
|
SCtgDBCache *dbCache = *pDb;
|
||||||
SCtgTbCache *tbCache = *pTb;
|
SCtgTbCache *tbCache = *pTb;
|
||||||
STableMeta *tbMeta = tbCache->pMeta;
|
STableMeta *tbMeta = tbCache->pMeta;
|
||||||
|
@ -553,7 +554,6 @@ int32_t ctgCopyTbMeta(SCatalog *pCtg, SCtgTbMetaCtx *ctx, SCtgDBCache **pDb, SCt
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t ctgReadTbMetaFromCache(SCatalog *pCtg, SCtgTbMetaCtx *ctx, STableMeta **pTableMeta) {
|
int32_t ctgReadTbMetaFromCache(SCatalog *pCtg, SCtgTbMetaCtx *ctx, STableMeta **pTableMeta) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SCtgDBCache *dbCache = NULL;
|
SCtgDBCache *dbCache = NULL;
|
||||||
|
@ -703,55 +703,40 @@ _return:
|
||||||
CTG_RET(code);
|
CTG_RET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
char *p = strchr(dbFName, '.');
|
if (IS_SYS_DBNAME(pReq->tbName.dbname)) {
|
||||||
if (p) {
|
|
||||||
++p;
|
|
||||||
} else {
|
|
||||||
p = dbFName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IS_SYS_DBNAME(p)) {
|
|
||||||
*inCache = true;
|
*inCache = true;
|
||||||
*pass = true;
|
pRes->pRawRes->pass = true;
|
||||||
ctgDebug("sysdb %s, pass", dbFName);
|
ctgDebug("sysdb %s, pass", pReq->tbName.dbname);
|
||||||
return TSDB_CODE_SUCCESS;
|
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) {
|
if (NULL == pUser) {
|
||||||
ctgDebug("user not in cache, user:%s", user);
|
ctgDebug("user not in cache, user:%s", pReq->user);
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*inCache = true;
|
*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);
|
CTG_CACHE_HIT_INC(CTG_CI_USER, 1);
|
||||||
|
|
||||||
if (pUser->superUser) {
|
SCtgAuthReq req = {0};
|
||||||
*pass = true;
|
req.pRawReq = pReq;
|
||||||
return TSDB_CODE_SUCCESS;
|
req.onlyCache = true;
|
||||||
}
|
|
||||||
|
|
||||||
CTG_LOCK(CTG_READ, &pUser->lock);
|
CTG_LOCK(CTG_READ, &pUser->lock);
|
||||||
if (pUser->createdDbs && taosHashGet(pUser->createdDbs, dbFName, strlen(dbFName))) {
|
memcpy(&req.authInfo, &pUser->userAuth, sizeof(pUser->userAuth));
|
||||||
*pass = true;
|
int32_t code = ctgChkSetAuthRes(pCtg, &req, pRes);
|
||||||
CTG_UNLOCK(CTG_READ, &pUser->lock);
|
CTG_UNLOCK(CTG_READ, &pUser->lock);
|
||||||
return TSDB_CODE_SUCCESS;
|
CTG_ERR_JRET(code);
|
||||||
|
|
||||||
|
if (pRes->metaNotExists) {
|
||||||
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pUser->readDbs && taosHashGet(pUser->readDbs, dbFName, strlen(dbFName)) && CTG_AUTH_READ(type)) {
|
CTG_RET(code);
|
||||||
*pass = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pUser->writeDbs && taosHashGet(pUser->writeDbs, dbFName, strlen(dbFName)) && CTG_AUTH_WRITE(type)) {
|
|
||||||
*pass = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
CTG_UNLOCK(CTG_READ, &pUser->lock);
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
|
@ -1738,7 +1723,6 @@ int32_t ctgVgInfoIdComp(void const* lp, void const* rp) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t ctgOpUpdateVgroup(SCtgCacheOperation *operation) {
|
int32_t ctgOpUpdateVgroup(SCtgCacheOperation *operation) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SCtgUpdateVgMsg *msg = operation->data;
|
SCtgUpdateVgMsg *msg = operation->data;
|
||||||
|
@ -2054,11 +2038,7 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
|
||||||
if (NULL == pUser) {
|
if (NULL == pUser) {
|
||||||
SCtgUserAuth userAuth = {0};
|
SCtgUserAuth userAuth = {0};
|
||||||
|
|
||||||
userAuth.version = msg->userAuth.version;
|
memcpy(&userAuth.userAuth, &msg->userAuth, sizeof(msg->userAuth));
|
||||||
userAuth.superUser = msg->userAuth.superAuth;
|
|
||||||
userAuth.createdDbs = msg->userAuth.createdDbs;
|
|
||||||
userAuth.readDbs = msg->userAuth.readDbs;
|
|
||||||
userAuth.writeDbs = msg->userAuth.writeDbs;
|
|
||||||
|
|
||||||
if (taosHashPut(pCtg->userCache, msg->userAuth.user, strlen(msg->userAuth.user), &userAuth, sizeof(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);
|
ctgError("taosHashPut user %s to cache failed", msg->userAuth.user);
|
||||||
|
@ -2072,22 +2052,32 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
pUser->version = msg->userAuth.version;
|
|
||||||
|
|
||||||
CTG_LOCK(CTG_WRITE, &pUser->lock);
|
CTG_LOCK(CTG_WRITE, &pUser->lock);
|
||||||
|
|
||||||
taosHashCleanup(pUser->createdDbs);
|
taosHashCleanup(pUser->userAuth.createdDbs);
|
||||||
pUser->createdDbs = msg->userAuth.createdDbs;
|
pUser->userAuth.createdDbs = msg->userAuth.createdDbs;
|
||||||
msg->userAuth.createdDbs = NULL;
|
msg->userAuth.createdDbs = NULL;
|
||||||
|
|
||||||
taosHashCleanup(pUser->readDbs);
|
taosHashCleanup(pUser->userAuth.readDbs);
|
||||||
pUser->readDbs = msg->userAuth.readDbs;
|
pUser->userAuth.readDbs = msg->userAuth.readDbs;
|
||||||
msg->userAuth.readDbs = NULL;
|
msg->userAuth.readDbs = NULL;
|
||||||
|
|
||||||
taosHashCleanup(pUser->writeDbs);
|
taosHashCleanup(pUser->userAuth.writeDbs);
|
||||||
pUser->writeDbs = msg->userAuth.writeDbs;
|
pUser->userAuth.writeDbs = msg->userAuth.writeDbs;
|
||||||
msg->userAuth.writeDbs = NULL;
|
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);
|
CTG_UNLOCK(CTG_WRITE, &pUser->lock);
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
@ -2095,6 +2085,9 @@ _return:
|
||||||
taosHashCleanup(msg->userAuth.createdDbs);
|
taosHashCleanup(msg->userAuth.createdDbs);
|
||||||
taosHashCleanup(msg->userAuth.readDbs);
|
taosHashCleanup(msg->userAuth.readDbs);
|
||||||
taosHashCleanup(msg->userAuth.writeDbs);
|
taosHashCleanup(msg->userAuth.writeDbs);
|
||||||
|
taosHashCleanup(msg->userAuth.readTbs);
|
||||||
|
taosHashCleanup(msg->userAuth.writeTbs);
|
||||||
|
taosHashCleanup(msg->userAuth.useDbs);
|
||||||
|
|
||||||
taosMemoryFreeClear(msg);
|
taosMemoryFreeClear(msg);
|
||||||
|
|
||||||
|
@ -2287,6 +2280,9 @@ void ctgFreeCacheOperationData(SCtgCacheOperation *op) {
|
||||||
taosHashCleanup(msg->userAuth.createdDbs);
|
taosHashCleanup(msg->userAuth.createdDbs);
|
||||||
taosHashCleanup(msg->userAuth.readDbs);
|
taosHashCleanup(msg->userAuth.readDbs);
|
||||||
taosHashCleanup(msg->userAuth.writeDbs);
|
taosHashCleanup(msg->userAuth.writeDbs);
|
||||||
|
taosHashCleanup(msg->userAuth.readTbs);
|
||||||
|
taosHashCleanup(msg->userAuth.writeTbs);
|
||||||
|
taosHashCleanup(msg->userAuth.useDbs);
|
||||||
taosMemoryFreeClear(op->data);
|
taosMemoryFreeClear(op->data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,9 +174,12 @@ void ctgFreeSMetaData(SMetaData* pData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctgFreeSCtgUserAuth(SCtgUserAuth* userCache) {
|
void ctgFreeSCtgUserAuth(SCtgUserAuth* userCache) {
|
||||||
taosHashCleanup(userCache->createdDbs);
|
taosHashCleanup(userCache->userAuth.createdDbs);
|
||||||
taosHashCleanup(userCache->readDbs);
|
taosHashCleanup(userCache->userAuth.readDbs);
|
||||||
taosHashCleanup(userCache->writeDbs);
|
taosHashCleanup(userCache->userAuth.writeDbs);
|
||||||
|
taosHashCleanup(userCache->userAuth.readTbs);
|
||||||
|
taosHashCleanup(userCache->userAuth.writeTbs);
|
||||||
|
taosHashCleanup(userCache->userAuth.useDbs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctgFreeMetaRent(SCtgRentMgmt* mgmt) {
|
void ctgFreeMetaRent(SCtgRentMgmt* mgmt) {
|
||||||
|
@ -419,6 +422,9 @@ void ctgFreeMsgCtx(SCtgMsgCtx* pCtx) {
|
||||||
taosHashCleanup(pOut->createdDbs);
|
taosHashCleanup(pOut->createdDbs);
|
||||||
taosHashCleanup(pOut->readDbs);
|
taosHashCleanup(pOut->readDbs);
|
||||||
taosHashCleanup(pOut->writeDbs);
|
taosHashCleanup(pOut->writeDbs);
|
||||||
|
taosHashCleanup(pOut->readTbs);
|
||||||
|
taosHashCleanup(pOut->writeTbs);
|
||||||
|
taosHashCleanup(pOut->useDbs);
|
||||||
taosMemoryFreeClear(pCtx->out);
|
taosMemoryFreeClear(pCtx->out);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1325,6 +1331,142 @@ static void* ctgCloneDnodeList(void* pSrc) { return taosArrayDup((const SArray*)
|
||||||
|
|
||||||
static void ctgFreeDnodeList(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); }
|
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)))) {
|
||||||
|
pRes->pass = true;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static int32_t ctgCloneMetaDataArray(SArray* pSrc, __array_item_dup_fn_t copyFunc, SArray** pDst) {
|
static int32_t ctgCloneMetaDataArray(SArray* pSrc, __array_item_dup_fn_t copyFunc, SArray** pDst) {
|
||||||
if (NULL == pSrc) {
|
if (NULL == pSrc) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ IF(NOT TD_DARWIN)
|
||||||
ADD_EXECUTABLE(catalogTest ${SOURCE_LIST})
|
ADD_EXECUTABLE(catalogTest ${SOURCE_LIST})
|
||||||
TARGET_LINK_LIBRARIES(
|
TARGET_LINK_LIBRARIES(
|
||||||
catalogTest
|
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(
|
TARGET_INCLUDE_DIRECTORIES(
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
#define TD_USE_WINSOCK
|
#define TD_USE_WINSOCK
|
||||||
#endif
|
#endif
|
||||||
#include "catalogInt.h"
|
|
||||||
#include "catalog.h"
|
#include "catalog.h"
|
||||||
|
#include "catalogInt.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "stub.h"
|
#include "stub.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
|
@ -536,7 +536,6 @@ void ctgTestRspMultiSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRp
|
||||||
tFreeSTableMetaRsp(&metaRsp);
|
tFreeSTableMetaRsp(&metaRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ctgTestRspErrIndexInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
void ctgTestRspErrIndexInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
|
|
||||||
|
@ -545,7 +544,6 @@ void ctgTestRspErrIndexInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMs
|
||||||
pRsp->pCont = NULL;
|
pRsp->pCont = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ctgTestRspUserAuth(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
void ctgTestRspUserAuth(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
|
|
||||||
|
@ -553,6 +551,7 @@ void ctgTestRspUserAuth(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *p
|
||||||
strcpy(userRsp.user, ctgTestUsername);
|
strcpy(userRsp.user, ctgTestUsername);
|
||||||
userRsp.version = 1;
|
userRsp.version = 1;
|
||||||
userRsp.superAuth = 1;
|
userRsp.superAuth = 1;
|
||||||
|
userRsp.enable = 1;
|
||||||
|
|
||||||
int32_t contLen = tSerializeSGetUserAuthRsp(NULL, 0, &userRsp);
|
int32_t contLen = tSerializeSGetUserAuthRsp(NULL, 0, &userRsp);
|
||||||
void *pReq = rpcMallocCont(contLen);
|
void *pReq = rpcMallocCont(contLen);
|
||||||
|
@ -727,8 +726,6 @@ void ctgTestRspDndeList(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *p
|
||||||
tFreeSDnodeListRsp(&dRsp);
|
tFreeSDnodeListRsp(&dRsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ctgTestRspAuto(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
void ctgTestRspAuto(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||||
switch (pMsg->msgType) {
|
switch (pMsg->msgType) {
|
||||||
case TDMT_MND_USE_DB:
|
case TDMT_MND_USE_DB:
|
||||||
|
@ -763,7 +760,6 @@ void ctgTestRspAuto(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ctgTestRspByIdx(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
void ctgTestRspByIdx(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||||
switch (ctgTestRspFunc[ctgTestRspIdx]) {
|
switch (ctgTestRspFunc[ctgTestRspIdx]) {
|
||||||
case CTGT_RSP_VGINFO:
|
case CTGT_RSP_VGINFO:
|
||||||
|
@ -1204,7 +1200,6 @@ void *ctgTestSetCtableMetaThread(void *param) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ctgTestFetchRows(TAOS_RES *result, int32_t *rows) {
|
void ctgTestFetchRows(TAOS_RES *result, int32_t *rows) {
|
||||||
TAOS_ROW row;
|
TAOS_ROW row;
|
||||||
int num_fields = taos_num_fields(result);
|
int num_fields = taos_num_fields(result);
|
||||||
|
@ -1232,7 +1227,6 @@ void ctgTestExecQuery(TAOS * taos, char* sql, bool fetch, int32_t *rows) {
|
||||||
taos_free_result(result);
|
taos_free_result(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(tableMeta, normalTable) {
|
TEST(tableMeta, normalTable) {
|
||||||
struct SCatalog *pCtg = NULL;
|
struct SCatalog *pCtg = NULL;
|
||||||
SVgroupInfo vgInfo = {0};
|
SVgroupInfo vgInfo = {0};
|
||||||
|
@ -2045,7 +2039,6 @@ TEST(refreshGetMeta, normal2child) {
|
||||||
ctgTestCurrentSTableName = NULL;
|
ctgTestCurrentSTableName = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(refreshGetMeta, stable2child) {
|
TEST(refreshGetMeta, stable2child) {
|
||||||
struct SCatalog *pCtg = NULL;
|
struct SCatalog *pCtg = NULL;
|
||||||
SRequestConnInfo connInfo = {0};
|
SRequestConnInfo connInfo = {0};
|
||||||
|
@ -2800,15 +2793,19 @@ TEST(apiTest, catalogChkAuth_test) {
|
||||||
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
code = catalogGetHandle(ctgTestClusterId, &pCtg);
|
||||||
ASSERT_EQ(code, 0);
|
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;
|
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(code, 0);
|
||||||
ASSERT_EQ(exists, false);
|
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(code, 0);
|
||||||
ASSERT_EQ(pass, true);
|
ASSERT_EQ(authRes.pass, true);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
uint64_t n = 0;
|
uint64_t n = 0;
|
||||||
|
@ -2820,9 +2817,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(code, 0);
|
||||||
ASSERT_EQ(pass, true);
|
ASSERT_EQ(authRes.pass, true);
|
||||||
ASSERT_EQ(exists, true);
|
ASSERT_EQ(exists, true);
|
||||||
|
|
||||||
catalogDestroy();
|
catalogDestroy();
|
||||||
|
@ -2969,7 +2966,6 @@ TEST(apiTest, catalogGetQnodeList_test) {
|
||||||
catalogDestroy();
|
catalogDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(apiTest, catalogGetUdfInfo_test) {
|
TEST(apiTest, catalogGetUdfInfo_test) {
|
||||||
struct SCatalog *pCtg = NULL;
|
struct SCatalog *pCtg = NULL;
|
||||||
SRequestConnInfo connInfo = {0};
|
SRequestConnInfo connInfo = {0};
|
||||||
|
@ -2999,7 +2995,6 @@ TEST(apiTest, catalogGetUdfInfo_test) {
|
||||||
catalogDestroy();
|
catalogDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(apiTest, catalogGetServerVersion_test) {
|
TEST(apiTest, catalogGetServerVersion_test) {
|
||||||
struct SCatalog *pCtg = NULL;
|
struct SCatalog *pCtg = NULL;
|
||||||
SRequestConnInfo connInfo = {0};
|
SRequestConnInfo connInfo = {0};
|
||||||
|
@ -3061,7 +3056,6 @@ TEST(apiTest, catalogUpdateTableIndex_test) {
|
||||||
catalogDestroy();
|
catalogDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(apiTest, catalogGetDnodeList_test) {
|
TEST(apiTest, catalogGetDnodeList_test) {
|
||||||
struct SCatalog *pCtg = NULL;
|
struct SCatalog *pCtg = NULL;
|
||||||
SRequestConnInfo connInfo = {0};
|
SRequestConnInfo connInfo = {0};
|
||||||
|
@ -3145,7 +3139,6 @@ TEST(intTest, autoCreateTableTest) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
testing::InitGoogleTest(&argc, argv);
|
testing::InitGoogleTest(&argc, argv);
|
||||||
return RUN_ALL_TESTS();
|
return RUN_ALL_TESTS();
|
||||||
|
|
|
@ -29,7 +29,6 @@ struct SDataSinkHandle;
|
||||||
|
|
||||||
typedef struct SDataSinkManager {
|
typedef struct SDataSinkManager {
|
||||||
SDataSinkMgtCfg cfg;
|
SDataSinkMgtCfg cfg;
|
||||||
TdThreadMutex mutex;
|
|
||||||
} SDataSinkManager;
|
} SDataSinkManager;
|
||||||
|
|
||||||
typedef int32_t (*FPutDataBlock)(struct SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue);
|
typedef int32_t (*FPutDataBlock)(struct SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue);
|
||||||
|
|
|
@ -128,10 +128,10 @@ enum {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// TODO remove prepareStatus
|
// TODO remove prepareStatus
|
||||||
STqOffsetVal prepareStatus; // for tmq
|
// STqOffsetVal prepareStatus; // for tmq
|
||||||
STqOffsetVal lastStatus; // for tmq
|
STqOffsetVal currentOffset; // for tmq
|
||||||
SMqMetaRsp metaRsp; // for tmq fetching meta
|
SMqMetaRsp metaRsp; // for tmq fetching meta
|
||||||
int8_t returned;
|
// int8_t returned;
|
||||||
int64_t snapshotVer;
|
int64_t snapshotVer;
|
||||||
// const SSubmitReq* pReq;
|
// const SSubmitReq* pReq;
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ enum {
|
||||||
OP_OPENED = 0x1,
|
OP_OPENED = 0x1,
|
||||||
OP_RES_TO_RETURN = 0x5,
|
OP_RES_TO_RETURN = 0x5,
|
||||||
OP_EXEC_DONE = 0x9,
|
OP_EXEC_DONE = 0x9,
|
||||||
OP_EXEC_RECV = 0x11,
|
// OP_EXEC_RECV = 0x11,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct SOperatorFpSet {
|
typedef struct SOperatorFpSet {
|
||||||
|
@ -502,32 +502,12 @@ typedef struct STableCountScanSupp {
|
||||||
char stbNameFilter[TSDB_TABLE_NAME_LEN];
|
char stbNameFilter[TSDB_TABLE_NAME_LEN];
|
||||||
} STableCountScanSupp;
|
} 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 {
|
typedef struct SOptrBasicInfo {
|
||||||
SResultRowInfo resultRowInfo;
|
SResultRowInfo resultRowInfo;
|
||||||
SSDataBlock* pRes;
|
SSDataBlock* pRes;
|
||||||
bool mergeResultBlock;
|
bool mergeResultBlock;
|
||||||
} SOptrBasicInfo;
|
} SOptrBasicInfo;
|
||||||
|
|
||||||
typedef struct SAggOperatorInfo {
|
|
||||||
SOptrBasicInfo binfo;
|
|
||||||
SAggSupporter aggSup;
|
|
||||||
STableQueryInfo* current;
|
|
||||||
uint64_t groupId;
|
|
||||||
SGroupResInfo groupResInfo;
|
|
||||||
SExprSupp scalarExprSup;
|
|
||||||
bool groupKeyOptimized;
|
|
||||||
} SAggOperatorInfo;
|
|
||||||
|
|
||||||
typedef struct SIntervalAggOperatorInfo {
|
typedef struct SIntervalAggOperatorInfo {
|
||||||
SOptrBasicInfo binfo; // basic info
|
SOptrBasicInfo binfo; // basic info
|
||||||
SAggSupporter aggSup; // aggregate supporter
|
SAggSupporter aggSup; // aggregate supporter
|
||||||
|
@ -853,8 +833,7 @@ SArray* getTableListInfo(const SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
int32_t createExecTaskInfo(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId,
|
int32_t createExecTaskInfo(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId,
|
||||||
int32_t vgId, char* sql, EOPTR_EXEC_MODEL model);
|
int32_t vgId, char* sql, EOPTR_EXEC_MODEL model);
|
||||||
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, STableListInfo* pTableListInfo,
|
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle);
|
||||||
SReadHandle* readHandle);
|
|
||||||
int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SArray* pExecInfoList);
|
int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SArray* pExecInfoList);
|
||||||
|
|
||||||
STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval,
|
STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval,
|
||||||
|
|
|
@ -40,6 +40,16 @@ typedef struct {
|
||||||
int32_t startOffset;
|
int32_t startOffset;
|
||||||
} SFunctionCtxStatus;
|
} 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 destroyAggOperatorInfo(void* param);
|
||||||
static void setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t groupId);
|
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;
|
int32_t scanFlag = MAIN_SCAN;
|
||||||
|
|
||||||
bool hasValidBlock = false;
|
bool hasValidBlock = false;
|
||||||
bool blockAllocated = false;
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
bool blockAllocated = false;
|
||||||
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
||||||
if (pBlock == NULL) {
|
if (pBlock == NULL) {
|
||||||
if (!hasValidBlock) {
|
if (!hasValidBlock) {
|
||||||
|
|
|
@ -23,7 +23,6 @@ SDataSinkStat gDataSinkStat = {0};
|
||||||
|
|
||||||
int32_t dsDataSinkMgtInit(SDataSinkMgtCfg* cfg) {
|
int32_t dsDataSinkMgtInit(SDataSinkMgtCfg* cfg) {
|
||||||
gDataSinkManager.cfg = *cfg;
|
gDataSinkManager.cfg = *cfg;
|
||||||
taosThreadMutexInit(&gDataSinkManager.mutex, NULL);
|
|
||||||
return 0; // to avoid compiler eror
|
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;
|
pOperator->status = OP_NOT_OPENED;
|
||||||
|
|
||||||
SStreamScanInfo* pInfo = pOperator->info;
|
SStreamScanInfo* pInfo = pOperator->info;
|
||||||
qDebug("stream set total blocks:%d, task id:%s" PRIx64, (int32_t)numOfBlocks, id);
|
qDebug("task stream set total blocks:%d %s", (int32_t)numOfBlocks, id);
|
||||||
ASSERT(pInfo->validBlockIndex == 0);
|
ASSERT(pInfo->validBlockIndex == 0 && taosArrayGetSize(pInfo->pBlockLists) == 0);
|
||||||
ASSERT(taosArrayGetSize(pInfo->pBlockLists) == 0);
|
|
||||||
|
|
||||||
if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
||||||
// ASSERT(numOfBlocks > 1);
|
|
||||||
for (int32_t i = 0; i < numOfBlocks; i++) {
|
for (int32_t i = 0; i < numOfBlocks; i++) {
|
||||||
SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
|
SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
|
||||||
taosArrayPush(pInfo->pBlockLists, pReq);
|
taosArrayPush(pInfo->pBlockLists, pReq);
|
||||||
|
@ -505,12 +503,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
|
||||||
|
|
||||||
if (handle) {
|
if (handle) {
|
||||||
void* pSinkParam = NULL;
|
void* pSinkParam = NULL;
|
||||||
|
code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, (*pTask), readHandle);
|
||||||
SArray* pInfoList = getTableListInfo(*pTask);
|
|
||||||
STableListInfo* pTableListInfo = taosArrayGetP(pInfoList, 0);
|
|
||||||
taosArrayDestroy(pInfoList);
|
|
||||||
|
|
||||||
code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, pTableListInfo, readHandle);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
qError("failed to createDataSinkParam, vgId:%d, code:%s, %s", vgId, tstrerror(code), (*pTask)->id.str);
|
qError("failed to createDataSinkParam, vgId:%d, code:%s, %s", vgId, tstrerror(code), (*pTask)->id.str);
|
||||||
goto _error;
|
goto _error;
|
||||||
|
@ -1029,15 +1022,9 @@ SMqMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo) {
|
||||||
return &pTaskInfo->streamInfo.metaRsp;
|
return &pTaskInfo->streamInfo.metaRsp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t qStreamExtractPrepareUid(qTaskInfo_t tinfo) {
|
void qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) {
|
||||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||||
return pTaskInfo->streamInfo.prepareStatus.uid;
|
memcpy(pOffset, &pTaskInfo->streamInfo.currentOffset, sizeof(STqOffsetVal));
|
||||||
}
|
|
||||||
|
|
||||||
int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) {
|
|
||||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
|
||||||
memcpy(pOffset, &pTaskInfo->streamInfo.lastStatus, sizeof(STqOffsetVal));
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t initQueryTableDataCondForTmq(SQueryTableDataCond* pCond, SSnapContext* sContext, SMetaTableInfo* pMtInfo) {
|
int32_t initQueryTableDataCondForTmq(SQueryTableDataCond* pCond, SSnapContext* sContext, SMetaTableInfo* pMtInfo) {
|
||||||
|
@ -1083,22 +1070,27 @@ int32_t qStreamSetScanMemData(qTaskInfo_t tinfo, SPackedData submit) {
|
||||||
return 0;
|
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) {
|
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType) {
|
||||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
|
||||||
SOperatorInfo* pOperator = pTaskInfo->pRoot;
|
SOperatorInfo* pOperator = pTaskInfo->pRoot;
|
||||||
const char* id = GET_TASKID(pTaskInfo);
|
const char* id = GET_TASKID(pTaskInfo);
|
||||||
|
|
||||||
pTaskInfo->streamInfo.prepareStatus = *pOffset;
|
// if pOffset equal to current offset, means continue consume
|
||||||
pTaskInfo->streamInfo.returned = 0;
|
if (tOffsetEqual(pOffset, &pTaskInfo->streamInfo.currentOffset)) {
|
||||||
|
|
||||||
if (tOffsetEqual(pOffset, &pTaskInfo->streamInfo.lastStatus)) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subType == TOPIC_SUB_TYPE__COLUMN) {
|
if (subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||||
pOperator->status = OP_OPENED;
|
|
||||||
pOperator = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id);
|
pOperator = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id);
|
||||||
|
if (pOperator == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
SStreamScanInfo* pInfo = pOperator->info;
|
SStreamScanInfo* pInfo = pOperator->info;
|
||||||
STableScanInfo* pScanInfo = pInfo->pTableScanOp->info;
|
STableScanInfo* pScanInfo = pInfo->pTableScanOp->info;
|
||||||
STableScanBase* pScanBaseInfo = &pScanInfo->base;
|
STableScanBase* pScanBaseInfo = &pScanInfo->base;
|
||||||
|
@ -1109,7 +1101,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
||||||
pScanBaseInfo->dataReader = NULL;
|
pScanBaseInfo->dataReader = NULL;
|
||||||
|
|
||||||
// let's seek to the next version in wal file
|
// 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);
|
qError("tqSeekVer failed ver:%" PRId64 ", %s", pOffset->version + 1, id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1137,6 +1129,8 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug("switch to table uid:%" PRId64 " ts:%" PRId64 "% " PRId64 " rows returned", uid, ts,
|
||||||
|
pInfo->pTableScanOp->resultInfo.totalRows);
|
||||||
pInfo->pTableScanOp->resultInfo.totalRows = 0;
|
pInfo->pTableScanOp->resultInfo.totalRows = 0;
|
||||||
|
|
||||||
// start from current accessed position
|
// start from current accessed position
|
||||||
|
@ -1207,7 +1201,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
||||||
tableListClear(pTableListInfo);
|
tableListClear(pTableListInfo);
|
||||||
|
|
||||||
if (mtInfo.uid == 0) {
|
if (mtInfo.uid == 0) {
|
||||||
return 0; // no data
|
goto end; // no data
|
||||||
}
|
}
|
||||||
|
|
||||||
initQueryTableDataCondForTmq(&pTaskInfo->streamInfo.tableCond, sContext, &mtInfo);
|
initQueryTableDataCondForTmq(&pTaskInfo->streamInfo.tableCond, sContext, &mtInfo);
|
||||||
|
@ -1244,6 +1238,9 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
pTaskInfo->streamInfo.currentOffset = *pOffset;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1591,8 +1591,7 @@ int32_t extractTableScanNode(SPhysiNode* pNode, STableScanPhysiNode** ppNode) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, STableListInfo* pTableListInfo,
|
int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle) {
|
||||||
SReadHandle* readHandle) {
|
|
||||||
switch (pNode->type) {
|
switch (pNode->type) {
|
||||||
case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
|
case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
|
||||||
SInserterParam* pInserterParam = taosMemoryCalloc(1, sizeof(SInserterParam));
|
SInserterParam* pInserterParam = taosMemoryCalloc(1, sizeof(SInserterParam));
|
||||||
|
@ -1610,23 +1609,26 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, STableListInfo*
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
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);
|
pDeleterParam->suid = tableListGetSuid(pTableListInfo);
|
||||||
|
|
||||||
// TODO extract uid list
|
// 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) {
|
if (NULL == pDeleterParam->pUidList) {
|
||||||
taosMemoryFree(pDeleterParam);
|
taosMemoryFree(pDeleterParam);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
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);
|
STableKeyInfo* pTable = tableListGetInfo(pTableListInfo, i);
|
||||||
taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
|
taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
*pParam = pDeleterParam;
|
*pParam = pDeleterParam;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -1973,11 +1975,11 @@ void qStreamCloseTsdbReader(void* task) {
|
||||||
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)task;
|
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)task;
|
||||||
SOperatorInfo* pOp = pTaskInfo->pRoot;
|
SOperatorInfo* pOp = pTaskInfo->pRoot;
|
||||||
|
|
||||||
qDebug("stream close tsdb reader, reset status uid:%" PRId64 " ts:%" PRId64, pTaskInfo->streamInfo.lastStatus.uid,
|
qDebug("stream close tsdb reader, reset status uid:%" PRId64 " ts:%" PRId64, pTaskInfo->streamInfo.currentOffset.uid,
|
||||||
pTaskInfo->streamInfo.lastStatus.ts);
|
pTaskInfo->streamInfo.currentOffset.ts);
|
||||||
|
|
||||||
// todo refactor, other thread may already use this read to extract data.
|
// 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]) {
|
while (pOp->numOfDownstream == 1 && pOp->pDownstream[0]) {
|
||||||
SOperatorInfo* pDownstreamOp = pOp->pDownstream[0];
|
SOperatorInfo* pDownstreamOp = pOp->pDownstream[0];
|
||||||
if (pDownstreamOp->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
if (pDownstreamOp->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||||
|
|
|
@ -227,17 +227,8 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
||||||
blockDataCleanup(pFinalRes);
|
blockDataCleanup(pFinalRes);
|
||||||
|
|
||||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||||
if (pTaskInfo->streamInfo.submit.msgStr) {
|
|
||||||
pOperator->status = OP_OPENED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pOperator->status == OP_EXEC_DONE) {
|
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;
|
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.
|
// The downstream exec may change the value of the newgroup, so use a local variable instead.
|
||||||
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
||||||
if (pBlock == NULL) {
|
if (pBlock == NULL) {
|
||||||
if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE && pFinalRes->info.rows == 0) {
|
qDebug("set op close, exec %d, status %d rows %" PRId64 , pTaskInfo->execModel, pOperator->status, pFinalRes->info.rows);
|
||||||
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);
|
|
||||||
setOperatorCompleted(pOperator);
|
setOperatorCompleted(pOperator);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) {
|
// if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) {
|
||||||
qDebug("set status recv");
|
// qDebug("set status recv");
|
||||||
pOperator->status = OP_EXEC_RECV;
|
// pOperator->status = OP_EXEC_RECV;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// for stream interval
|
// for stream interval
|
||||||
if (pBlock->info.type == STREAM_RETRIEVE || pBlock->info.type == STREAM_DELETE_RESULT ||
|
if (pBlock->info.type == STREAM_RETRIEVE || pBlock->info.type == STREAM_DELETE_RESULT ||
|
||||||
|
|
|
@ -51,6 +51,16 @@ typedef struct STableMergeScanSortSourceParam {
|
||||||
STsdbReader* dataReader;
|
STsdbReader* dataReader;
|
||||||
} STableMergeScanSortSourceParam;
|
} 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);
|
static bool processBlockWithProbability(const SSampleExecInfo* pInfo);
|
||||||
|
|
||||||
bool processBlockWithProbability(const SSampleExecInfo* pInfo) {
|
bool processBlockWithProbability(const SSampleExecInfo* pInfo) {
|
||||||
|
@ -698,9 +708,9 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
|
||||||
// todo refactor
|
// todo refactor
|
||||||
/*pTableScanInfo->lastStatus.uid = pBlock->info.id.uid;*/
|
/*pTableScanInfo->lastStatus.uid = pBlock->info.id.uid;*/
|
||||||
/*pTableScanInfo->lastStatus.ts = pBlock->info.window.ekey;*/
|
/*pTableScanInfo->lastStatus.ts = pBlock->info.window.ekey;*/
|
||||||
pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__SNAPSHOT_DATA;
|
// pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__SNAPSHOT_DATA;
|
||||||
pTaskInfo->streamInfo.lastStatus.uid = pBlock->info.id.uid;
|
// pTaskInfo->streamInfo.lastStatus.uid = pBlock->info.id.uid;
|
||||||
pTaskInfo->streamInfo.lastStatus.ts = pBlock->info.window.ekey;
|
// pTaskInfo->streamInfo.lastStatus.ts = pBlock->info.window.ekey;
|
||||||
|
|
||||||
return pBlock;
|
return pBlock;
|
||||||
}
|
}
|
||||||
|
@ -890,9 +900,11 @@ static void destroyTableScanOperatorInfo(void* param) {
|
||||||
|
|
||||||
SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* readHandle,
|
SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* readHandle,
|
||||||
STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo) {
|
STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo) {
|
||||||
|
int32_t code = 0;
|
||||||
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
if (pInfo == NULL || pOperator == NULL) {
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -900,8 +912,7 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
|
||||||
SDataBlockDescNode* pDescNode = pScanNode->node.pOutputDataBlockDesc;
|
SDataBlockDescNode* pDescNode = pScanNode->node.pOutputDataBlockDesc;
|
||||||
|
|
||||||
int32_t numOfCols = 0;
|
int32_t numOfCols = 0;
|
||||||
int32_t code =
|
code = extractColMatchInfo(pScanNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, &pInfo->base.matchInfo);
|
||||||
extractColMatchInfo(pScanNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, &pInfo->base.matchInfo);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
@ -1626,10 +1637,8 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
||||||
if (pInfo->tqReader->msg2.msgStr == NULL) {
|
if (pInfo->tqReader->msg2.msgStr == NULL) {
|
||||||
SPackedData submit = pTaskInfo->streamInfo.submit;
|
SPackedData submit = pTaskInfo->streamInfo.submit;
|
||||||
if (tqReaderSetSubmitReq2(pInfo->tqReader, submit.msgStr, submit.msgLen, submit.ver) < 0) {
|
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);
|
qError("submit msg messed up when initing stream submit block %p", submit.msgStr);
|
||||||
pInfo->tqReader->msg2 = (SPackedData){0};
|
return NULL;
|
||||||
pInfo->tqReader->setMsg = 0;
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1652,73 +1661,49 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->tqReader->msg2 = (SPackedData){0};
|
pInfo->tqReader->msg2 = (SPackedData){0};
|
||||||
pInfo->tqReader->setMsg = 0;
|
|
||||||
pTaskInfo->streamInfo.submit = (SPackedData){0};
|
pTaskInfo->streamInfo.submit = (SPackedData){0};
|
||||||
return NULL;
|
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);
|
SSDataBlock* pResult = doTableScan(pInfo->pTableScanOp);
|
||||||
if (pResult && pResult->info.rows > 0) {
|
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.rows, pResult->info.window.skey, pResult->info.window.ekey,
|
pResult->info.window.skey, pResult->info.window.ekey, pInfo->tqReader->pWalReader->curVersion);
|
||||||
pInfo->tqReader->pWalReader->curVersion, id);
|
tqOffsetResetToData(&pTaskInfo->streamInfo.currentOffset, pResult->info.id.uid, pResult->info.window.ekey);
|
||||||
pTaskInfo->streamInfo.returned = 1;
|
|
||||||
return pResult;
|
return pResult;
|
||||||
} else {
|
}
|
||||||
// no data has return already, try to extract data in the WAL
|
|
||||||
if (!pTaskInfo->streamInfo.returned) {
|
|
||||||
STableScanInfo* pTSInfo = pInfo->pTableScanOp->info;
|
STableScanInfo* pTSInfo = pInfo->pTableScanOp->info;
|
||||||
tsdbReaderClose(pTSInfo->base.dataReader);
|
tsdbReaderClose(pTSInfo->base.dataReader);
|
||||||
pTSInfo->base.dataReader = NULL;
|
pTSInfo->base.dataReader = NULL;
|
||||||
tqOffsetResetToLog(&pTaskInfo->streamInfo.prepareStatus, pTaskInfo->streamInfo.snapshotVer);
|
qDebug("queue scan tsdb over, switch to wal ver %" PRId64 "", pTaskInfo->streamInfo.snapshotVer + 1);
|
||||||
|
|
||||||
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) {
|
if (tqSeekVer(pInfo->tqReader, pTaskInfo->streamInfo.snapshotVer + 1, pTaskInfo->id.str) < 0) {
|
||||||
tqOffsetResetToLog(&pTaskInfo->streamInfo.lastStatus, pTaskInfo->streamInfo.snapshotVer);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
tqOffsetResetToLog(&pTaskInfo->streamInfo.currentOffset, pTaskInfo->streamInfo.snapshotVer);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__LOG) {
|
if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__LOG) {
|
||||||
while (1) {
|
while (1) {
|
||||||
SFetchRet ret = {0};
|
SFetchRet ret = {0};
|
||||||
terrno = 0;
|
tqNextBlock(pInfo->tqReader, &ret);
|
||||||
|
tqOffsetResetToLog(&pTaskInfo->streamInfo.currentOffset, pInfo->tqReader->pWalReader->curVersion - 1); //curVersion move to next, so currentOffset = curVersion - 1
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret.fetchType == FETCH_TYPE__DATA) {
|
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);
|
blockDataCleanup(pInfo->pRes);
|
||||||
setBlockIntoRes(pInfo, &ret.data, true);
|
setBlockIntoRes(pInfo, &ret.data, true);
|
||||||
if (pInfo->pRes->info.rows > 0) {
|
if (pInfo->pRes->info.rows > 0) {
|
||||||
pOperator->status = OP_EXEC_RECV;
|
qDebug("doQueueScan get data from log %"PRId64" rows, return, version:%" PRId64, pInfo->pRes->info.rows, pTaskInfo->streamInfo.currentOffset.version);
|
||||||
qDebug("queue scan log return %" PRId64 " rows", pInfo->pRes->info.rows);
|
|
||||||
return pInfo->pRes;
|
return pInfo->pRes;
|
||||||
}
|
}
|
||||||
} else if (ret.fetchType == FETCH_TYPE__META) {
|
}else if(ret.fetchType == FETCH_TYPE__NONE){
|
||||||
qError("unexpected ret.fetchType:%d", ret.fetchType);
|
qDebug("doQueueScan get none from log, return, version:%" PRId64, pTaskInfo->streamInfo.currentOffset.version);
|
||||||
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;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2073,7 +2058,6 @@ FETCH_NEXT_BLOCK:
|
||||||
|
|
||||||
int32_t current = pInfo->validBlockIndex++;
|
int32_t current = pInfo->validBlockIndex++;
|
||||||
SPackedData* pSubmit = taosArrayGet(pInfo->pBlockLists, current);
|
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 (tqReaderSetSubmitReq2(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,
|
qError("submit msg messed up when initing stream submit block %p, current %d, total %d", pSubmit, current,
|
||||||
totBlockNum);
|
totBlockNum);
|
||||||
|
@ -2165,7 +2149,7 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
||||||
pTaskInfo->streamInfo.metaRsp.metaRsp = NULL;
|
pTaskInfo->streamInfo.metaRsp.metaRsp = NULL;
|
||||||
|
|
||||||
qDebug("tmqsnap doRawScan called");
|
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;
|
bool hasNext = false;
|
||||||
if (pInfo->dataReader) {
|
if (pInfo->dataReader) {
|
||||||
code = tsdbNextDataBlock(pInfo->dataReader, &hasNext);
|
code = tsdbNextDataBlock(pInfo->dataReader, &hasNext);
|
||||||
|
@ -2187,28 +2171,23 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug("tmqsnap doRawScan get data uid:%" PRId64 "", pBlock->info.id.uid);
|
qDebug("tmqsnap doRawScan get data uid:%" PRId64 "", pBlock->info.id.uid);
|
||||||
pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__SNAPSHOT_DATA;
|
tqOffsetResetToData(&pTaskInfo->streamInfo.currentOffset, pBlock->info.id.uid, pBlock->info.window.ekey);
|
||||||
pTaskInfo->streamInfo.lastStatus.uid = pBlock->info.id.uid;
|
|
||||||
pTaskInfo->streamInfo.lastStatus.ts = pBlock->info.window.ekey;
|
|
||||||
return pBlock;
|
return pBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMetaTableInfo mtInfo = getUidfromSnapShot(pInfo->sContext);
|
SMetaTableInfo mtInfo = getUidfromSnapShot(pInfo->sContext);
|
||||||
|
STqOffsetVal offset = {0};
|
||||||
if (mtInfo.uid == 0) { // read snapshot done, change to get data from wal
|
if (mtInfo.uid == 0) { // read snapshot done, change to get data from wal
|
||||||
qDebug("tmqsnap 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;
|
tqOffsetResetToLog(&offset, pInfo->sContext->snapVersion);
|
||||||
pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__LOG;
|
|
||||||
pTaskInfo->streamInfo.lastStatus.version = pInfo->sContext->snapVersion;
|
|
||||||
} else {
|
} else {
|
||||||
pTaskInfo->streamInfo.prepareStatus.uid = mtInfo.uid;
|
tqOffsetResetToData(&offset, mtInfo.uid, INT64_MIN);
|
||||||
pTaskInfo->streamInfo.prepareStatus.ts = INT64_MIN;
|
|
||||||
qDebug("tmqsnap change get data uid:%" PRId64 "", mtInfo.uid);
|
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);
|
tDeleteSSchemaWrapper(mtInfo.schema);
|
||||||
qDebug("tmqsnap stream scan tsdb return null");
|
|
||||||
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;
|
SSnapContext* sContext = pInfo->sContext;
|
||||||
void* data = NULL;
|
void* data = NULL;
|
||||||
int32_t dataLen = 0;
|
int32_t dataLen = 0;
|
||||||
|
@ -2220,16 +2199,12 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sContext->queryMetaOrData) { // change to get data next poll request
|
if (!sContext->queryMeta) { // change to get data next poll request
|
||||||
pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__SNAPSHOT_META;
|
STqOffsetVal offset = {0};
|
||||||
pTaskInfo->streamInfo.lastStatus.uid = uid;
|
tqOffsetResetToData(&offset, 0, INT64_MIN);
|
||||||
pTaskInfo->streamInfo.metaRsp.rspOffset.type = TMQ_OFFSET__SNAPSHOT_DATA;
|
qStreamPrepareScan(pTaskInfo, &offset, pInfo->sContext->subType);
|
||||||
pTaskInfo->streamInfo.metaRsp.rspOffset.uid = 0;
|
|
||||||
pTaskInfo->streamInfo.metaRsp.rspOffset.ts = INT64_MIN;
|
|
||||||
} else {
|
} else {
|
||||||
pTaskInfo->streamInfo.lastStatus.type = TMQ_OFFSET__SNAPSHOT_META;
|
tqOffsetResetToMeta(&pTaskInfo->streamInfo.currentOffset, uid);
|
||||||
pTaskInfo->streamInfo.lastStatus.uid = uid;
|
|
||||||
pTaskInfo->streamInfo.metaRsp.rspOffset = pTaskInfo->streamInfo.lastStatus;
|
|
||||||
pTaskInfo->streamInfo.metaRsp.resMsgType = type;
|
pTaskInfo->streamInfo.metaRsp.resMsgType = type;
|
||||||
pTaskInfo->streamInfo.metaRsp.metaRspLen = dataLen;
|
pTaskInfo->streamInfo.metaRsp.metaRspLen = dataLen;
|
||||||
pTaskInfo->streamInfo.metaRsp.metaRsp = data;
|
pTaskInfo->streamInfo.metaRsp.metaRsp = data;
|
||||||
|
@ -2443,7 +2418,6 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
|
||||||
if (pHandle->initTableReader) {
|
if (pHandle->initTableReader) {
|
||||||
pTSInfo->scanMode = TABLE_SCAN__TABLE_ORDER;
|
pTSInfo->scanMode = TABLE_SCAN__TABLE_ORDER;
|
||||||
pTSInfo->base.dataReader = NULL;
|
pTSInfo->base.dataReader = NULL;
|
||||||
pTaskInfo->streamInfo.lastStatus.uid = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pHandle->initTqReader) {
|
if (pHandle->initTqReader) {
|
||||||
|
|
|
@ -4758,6 +4758,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
|
||||||
if (!pInfo->pUpdated) {
|
if (!pInfo->pUpdated) {
|
||||||
pInfo->pUpdated = taosArrayInit(4, sizeof(SWinKey));
|
pInfo->pUpdated = taosArrayInit(4, sizeof(SWinKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pInfo->pUpdatedMap) {
|
if (!pInfo->pUpdatedMap) {
|
||||||
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
|
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
|
||||||
pInfo->pUpdatedMap = tSimpleHashInit(1024, hashFn);
|
pInfo->pUpdatedMap = tSimpleHashInit(1024, hashFn);
|
||||||
|
|
|
@ -925,6 +925,7 @@ void nodesDestroyNode(SNode* pNode) {
|
||||||
taosMemoryFree(((SDescribeStmt*)pNode)->pMeta);
|
taosMemoryFree(((SDescribeStmt*)pNode)->pMeta);
|
||||||
break;
|
break;
|
||||||
case QUERY_NODE_RESET_QUERY_CACHE_STMT: // no pointer field
|
case QUERY_NODE_RESET_QUERY_CACHE_STMT: // no pointer field
|
||||||
|
break;
|
||||||
case QUERY_NODE_COMPACT_DATABASE_STMT: {
|
case QUERY_NODE_COMPACT_DATABASE_STMT: {
|
||||||
SCompactDatabaseStmt* pStmt = (SCompactDatabaseStmt*)pNode;
|
SCompactDatabaseStmt* pStmt = (SCompactDatabaseStmt*)pNode;
|
||||||
nodesDestroyNode(pStmt->pStart);
|
nodesDestroyNode(pStmt->pStart);
|
||||||
|
|
|
@ -82,6 +82,11 @@ typedef struct SAlterOption {
|
||||||
SNodeList* pList;
|
SNodeList* pList;
|
||||||
} SAlterOption;
|
} SAlterOption;
|
||||||
|
|
||||||
|
typedef struct STokenPair {
|
||||||
|
SToken first;
|
||||||
|
SToken second;
|
||||||
|
} STokenPair;
|
||||||
|
|
||||||
extern SToken nil_token;
|
extern SToken nil_token;
|
||||||
|
|
||||||
void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt);
|
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* createRedistributeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId, SNodeList* pDnodes);
|
||||||
SNode* createSplitVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId);
|
SNode* createSplitVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId);
|
||||||
SNode* createSyncdbStmt(SAstCreateContext* pCxt, const SToken* pDbName);
|
SNode* createSyncdbStmt(SAstCreateContext* pCxt, const SToken* pDbName);
|
||||||
SNode* createGrantStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbName, SToken* pUserName);
|
SNode* createGrantStmt(SAstCreateContext* pCxt, int64_t privileges, STokenPair* pPrivLevel, SToken* pUserName,
|
||||||
SNode* createRevokeStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbName, 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* createDeleteStmt(SAstCreateContext* pCxt, SNode* pTable, SNode* pWhere);
|
||||||
SNode* createInsertStmt(SAstCreateContext* pCxt, SNode* pTable, SNodeList* pCols, SNode* pQuery);
|
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 reserveTableVgroupInCacheExt(const SName* pName, SParseMetaCache* pMetaCache);
|
||||||
int32_t reserveDbVgVersionInCache(int32_t acctId, const char* pDb, 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 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);
|
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 reserveUdfInCache(const char* pFunc, SParseMetaCache* pMetaCache);
|
||||||
int32_t reserveTableIndexInCache(int32_t acctId, const char* pDb, const char* pTable, 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);
|
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 getDbVgVersionFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, int32_t* pVersion, int64_t* pDbId,
|
||||||
int32_t* pTableNum, int64_t* pStateTs);
|
int32_t* pTableNum, int64_t* pStateTs);
|
||||||
int32_t getDbCfgFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SDbCfgInfo* pInfo);
|
int32_t getDbCfgFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SDbCfgInfo* pInfo);
|
||||||
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, const char* pUser, const char* pDbFName, AUTH_TYPE type,
|
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, SUserAuthInfo* pAuthReq, SUserAuthRes* pAuthRes);
|
||||||
bool* pPass);
|
|
||||||
int32_t getUdfInfoFromCache(SParseMetaCache* pMetaCache, const char* pFunc, SFuncInfo* pInfo);
|
int32_t getUdfInfoFromCache(SParseMetaCache* pMetaCache, const char* pFunc, SFuncInfo* pInfo);
|
||||||
int32_t getTableIndexFromCache(SParseMetaCache* pMetaCache, const SName* pName, SArray** pIndexes);
|
int32_t getTableIndexFromCache(SParseMetaCache* pMetaCache, const SName* pName, SArray** pIndexes);
|
||||||
int32_t getTableCfgFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableCfg** pOutput);
|
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); }
|
sysinfo_opt(A) ::= SYSINFO NK_INTEGER(B). { A = taosStr2Int8(B.z, NULL, 10); }
|
||||||
|
|
||||||
/************************************************ grant/revoke ********************************************************/
|
/************************************************ grant/revoke ********************************************************/
|
||||||
cmd ::= GRANT privileges(A) ON priv_level(B) TO user_name(C). { pCxt->pRootNode = createGrantStmt(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) FROM user_name(C). { pCxt->pRootNode = createRevokeStmt(pCxt, A, &B, &C); }
|
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 }
|
%type privileges { int64_t }
|
||||||
%destructor privileges { }
|
%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) ::= READ. { A = PRIVILEGE_TYPE_READ; }
|
||||||
priv_type(A) ::= WRITE. { A = PRIVILEGE_TYPE_WRITE; }
|
priv_type(A) ::= WRITE. { A = PRIVILEGE_TYPE_WRITE; }
|
||||||
|
|
||||||
%type priv_level { SToken }
|
%type priv_level { STokenPair }
|
||||||
%destructor priv_level { }
|
%destructor priv_level { }
|
||||||
priv_level(A) ::= NK_STAR(B) NK_DOT NK_STAR. { 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. { A = B; }
|
priv_level(A) ::= db_name(B) NK_DOT NK_STAR(C). { A.first = B; A.second = C; }
|
||||||
priv_level(A) ::= topic_name(B). { A = B; }
|
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 *********************************************/
|
/************************************************ create/drop/alter dnode *********************************************/
|
||||||
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); }
|
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_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). { 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 }
|
%type type_name { SDataType }
|
||||||
%destructor type_name { }
|
%destructor type_name { }
|
||||||
|
|
|
@ -1994,29 +1994,39 @@ SNode* createSyncdbStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
|
||||||
return pStmt;
|
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);
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
if (!checkDbName(pCxt, pDbName, false) || !checkUserName(pCxt, pUserName)) {
|
if (!checkDbName(pCxt, &pPrivLevel->first, false) || !checkUserName(pCxt, pUserName)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
SGrantStmt* pStmt = (SGrantStmt*)nodesMakeNode(QUERY_NODE_GRANT_STMT);
|
SGrantStmt* pStmt = (SGrantStmt*)nodesMakeNode(QUERY_NODE_GRANT_STMT);
|
||||||
CHECK_OUT_OF_MEM(pStmt);
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
pStmt->privileges = privileges;
|
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);
|
COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName);
|
||||||
|
pStmt->pTagCond = pTagCond;
|
||||||
return (SNode*)pStmt;
|
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);
|
CHECK_PARSER_STATUS(pCxt);
|
||||||
if (!checkDbName(pCxt, pDbName, false) || !checkUserName(pCxt, pUserName)) {
|
if (!checkDbName(pCxt, &pPrivLevel->first, false) || !checkUserName(pCxt, pUserName)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
SRevokeStmt* pStmt = (SRevokeStmt*)nodesMakeNode(QUERY_NODE_REVOKE_STMT);
|
SRevokeStmt* pStmt = (SRevokeStmt*)nodesMakeNode(QUERY_NODE_REVOKE_STMT);
|
||||||
CHECK_OUT_OF_MEM(pStmt);
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
pStmt->privileges = privileges;
|
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);
|
COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName);
|
||||||
|
pStmt->pTagCond = pTagCond;
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,8 @@ static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, const c
|
||||||
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
|
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pDb, authType, pCxt->pMetaCache);
|
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pDb, pTable, authType,
|
||||||
|
pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pDb, pCxt->pMetaCache);
|
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pDb, pCxt->pMetaCache);
|
||||||
|
@ -247,7 +248,7 @@ static int32_t collectMetaKeyFromCreateTable(SCollectMetaKeyCxt* pCxt, SCreateTa
|
||||||
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
|
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, AUTH_TYPE_WRITE,
|
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, AUTH_TYPE_WRITE,
|
||||||
pCxt->pMetaCache);
|
pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
|
@ -267,8 +268,8 @@ static int32_t collectMetaKeyFromCreateMultiTable(SCollectMetaKeyCxt* pCxt, SCre
|
||||||
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
|
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, AUTH_TYPE_WRITE,
|
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, NULL,
|
||||||
pCxt->pMetaCache);
|
AUTH_TYPE_WRITE, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
break;
|
break;
|
||||||
|
@ -286,6 +287,10 @@ static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableS
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
|
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName,
|
||||||
|
pClause->tableName, AUTH_TYPE_WRITE, pCxt->pMetaCache);
|
||||||
|
}
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -293,6 +298,11 @@ static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableS
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t collectMetaKeyFromDropStable(SCollectMetaKeyCxt* pCxt, SDropSuperTableStmt* pStmt) {
|
||||||
|
return reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
|
||||||
|
AUTH_TYPE_WRITE, pCxt->pMetaCache);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t collectMetaKeyFromAlterTable(SCollectMetaKeyCxt* pCxt, SAlterTableStmt* pStmt) {
|
static int32_t collectMetaKeyFromAlterTable(SCollectMetaKeyCxt* pCxt, SAlterTableStmt* pStmt) {
|
||||||
int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
|
int32_t code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
@ -301,6 +311,10 @@ static int32_t collectMetaKeyFromAlterTable(SCollectMetaKeyCxt* pCxt, SAlterTabl
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
|
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
|
||||||
|
AUTH_TYPE_WRITE, pCxt->pMetaCache);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,6 +323,10 @@ static int32_t collectMetaKeyFromAlterStable(SCollectMetaKeyCxt* pCxt, SAlterTab
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
|
code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName,
|
||||||
|
AUTH_TYPE_WRITE, pCxt->pMetaCache);
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,8 +457,9 @@ static int32_t collectMetaKeyFromShowStables(SCollectMetaKeyCxt* pCxt, SShowStmt
|
||||||
int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_STABLES,
|
int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_STABLES,
|
||||||
pCxt->pMetaCache);
|
pCxt->pMetaCache);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser,
|
code =
|
||||||
((SValueNode*)pStmt->pDbName)->literal, AUTH_TYPE_READ_OR_WRITE, pCxt->pMetaCache);
|
reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
|
||||||
|
NULL, AUTH_TYPE_READ_OR_WRITE, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -457,8 +476,9 @@ static int32_t collectMetaKeyFromShowTables(SCollectMetaKeyCxt* pCxt, SShowStmt*
|
||||||
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
|
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser,
|
code =
|
||||||
((SValueNode*)pStmt->pDbName)->literal, AUTH_TYPE_READ_OR_WRITE, pCxt->pMetaCache);
|
reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
|
||||||
|
NULL, AUTH_TYPE_READ_OR_WRITE, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -561,7 +581,8 @@ static int32_t collectMetaKeyFromShowCreateTable(SCollectMetaKeyCxt* pCxt, SShow
|
||||||
code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
|
code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = reserveUserAuthInCacheExt(pCxt->pParseCxt->pUser, &name, AUTH_TYPE_READ, pCxt->pMetaCache);
|
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, AUTH_TYPE_READ,
|
||||||
|
pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -610,6 +631,13 @@ static int32_t collectMetaKeyFromCompactDatabase(SCollectMetaKeyCxt* pCxt, SComp
|
||||||
return reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
|
return reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t collectMetaKeyFromGrant(SCollectMetaKeyCxt* pCxt, SGrantStmt* pStmt) {
|
||||||
|
if ('\0' == pStmt->tabName[0]) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, pCxt->pMetaCache);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
||||||
pCxt->pStmt = pStmt;
|
pCxt->pStmt = pStmt;
|
||||||
switch (nodeType(pStmt)) {
|
switch (nodeType(pStmt)) {
|
||||||
|
@ -627,6 +655,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
||||||
return collectMetaKeyFromCreateMultiTable(pCxt, (SCreateMultiTablesStmt*)pStmt);
|
return collectMetaKeyFromCreateMultiTable(pCxt, (SCreateMultiTablesStmt*)pStmt);
|
||||||
case QUERY_NODE_DROP_TABLE_STMT:
|
case QUERY_NODE_DROP_TABLE_STMT:
|
||||||
return collectMetaKeyFromDropTable(pCxt, (SDropTableStmt*)pStmt);
|
return collectMetaKeyFromDropTable(pCxt, (SDropTableStmt*)pStmt);
|
||||||
|
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
|
||||||
|
return collectMetaKeyFromDropStable(pCxt, (SDropSuperTableStmt*)pStmt);
|
||||||
case QUERY_NODE_ALTER_TABLE_STMT:
|
case QUERY_NODE_ALTER_TABLE_STMT:
|
||||||
return collectMetaKeyFromAlterTable(pCxt, (SAlterTableStmt*)pStmt);
|
return collectMetaKeyFromAlterTable(pCxt, (SAlterTableStmt*)pStmt);
|
||||||
case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
|
case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
|
||||||
|
@ -645,6 +675,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
||||||
return collectMetaKeyFromCompactDatabase(pCxt, (SCompactDatabaseStmt*)pStmt);
|
return collectMetaKeyFromCompactDatabase(pCxt, (SCompactDatabaseStmt*)pStmt);
|
||||||
case QUERY_NODE_CREATE_STREAM_STMT:
|
case QUERY_NODE_CREATE_STREAM_STMT:
|
||||||
return collectMetaKeyFromCreateStream(pCxt, (SCreateStreamStmt*)pStmt);
|
return collectMetaKeyFromCreateStream(pCxt, (SCreateStreamStmt*)pStmt);
|
||||||
|
case QUERY_NODE_GRANT_STMT:
|
||||||
|
return collectMetaKeyFromGrant(pCxt, (SGrantStmt*)pStmt);
|
||||||
case QUERY_NODE_SHOW_DNODES_STMT:
|
case QUERY_NODE_SHOW_DNODES_STMT:
|
||||||
return collectMetaKeyFromShowDnodes(pCxt, (SShowStmt*)pStmt);
|
return collectMetaKeyFromShowDnodes(pCxt, (SShowStmt*)pStmt);
|
||||||
case QUERY_NODE_SHOW_MNODES_STMT:
|
case QUERY_NODE_SHOW_MNODES_STMT:
|
||||||
|
|
|
@ -23,49 +23,112 @@ typedef struct SAuthCxt {
|
||||||
int32_t errCode;
|
int32_t errCode;
|
||||||
} SAuthCxt;
|
} SAuthCxt;
|
||||||
|
|
||||||
|
typedef struct SSelectAuthCxt {
|
||||||
|
SAuthCxt* pAuthCxt;
|
||||||
|
SSelectStmt* pSelect;
|
||||||
|
} SSelectAuthCxt;
|
||||||
|
|
||||||
static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt);
|
static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt);
|
||||||
|
|
||||||
static int32_t checkAuth(SAuthCxt* pCxt, const char* pDbName, AUTH_TYPE type) {
|
static void setUserAuthInfo(SParseContext* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type,
|
||||||
|
SUserAuthInfo* pAuth) {
|
||||||
|
snprintf(pAuth->user, sizeof(pAuth->user), "%s", pCxt->pUser);
|
||||||
|
if (NULL == pTabName) {
|
||||||
|
tNameSetDbName(&pAuth->tbName, pCxt->acctId, pDbName, strlen(pDbName));
|
||||||
|
} else {
|
||||||
|
toName(pCxt->acctId, pDbName, pTabName, &pAuth->tbName);
|
||||||
|
}
|
||||||
|
pAuth->type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t checkAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond) {
|
||||||
SParseContext* pParseCxt = pCxt->pParseCxt;
|
SParseContext* pParseCxt = pCxt->pParseCxt;
|
||||||
if (pParseCxt->isSuperUser) {
|
if (pParseCxt->isSuperUser) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
SName name;
|
|
||||||
tNameSetDbName(&name, pParseCxt->acctId, pDbName, strlen(pDbName));
|
SUserAuthInfo authInfo = {0};
|
||||||
char dbFname[TSDB_DB_FNAME_LEN] = {0};
|
setUserAuthInfo(pCxt->pParseCxt, pDbName, pTabName, type, &authInfo);
|
||||||
tNameGetFullDbName(&name, dbFname);
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
bool pass = false;
|
SUserAuthRes authRes = {0};
|
||||||
if (NULL != pCxt->pMetaCache) {
|
if (NULL != pCxt->pMetaCache) {
|
||||||
code = getUserAuthFromCache(pCxt->pMetaCache, pParseCxt->pUser, dbFname, type, &pass);
|
code = getUserAuthFromCache(pCxt->pMetaCache, &authInfo, &authRes);
|
||||||
} else {
|
} else {
|
||||||
SRequestConnInfo conn = {.pTrans = pParseCxt->pTransporter,
|
SRequestConnInfo conn = {.pTrans = pParseCxt->pTransporter,
|
||||||
.requestId = pParseCxt->requestId,
|
.requestId = pParseCxt->requestId,
|
||||||
.requestObjRefId = pParseCxt->requestRid,
|
.requestObjRefId = pParseCxt->requestRid,
|
||||||
.mgmtEps = pParseCxt->mgmtEpSet};
|
.mgmtEps = pParseCxt->mgmtEpSet};
|
||||||
|
code = catalogChkAuth(pParseCxt->pCatalog, &conn, &authInfo, &authRes);
|
||||||
code = catalogChkAuth(pParseCxt->pCatalog, &conn, pParseCxt->pUser, dbFname, type, &pass);
|
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS == code ? (pass ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED) : code;
|
if (TSDB_CODE_SUCCESS == code && NULL != pCond) {
|
||||||
|
*pCond = authRes.pCond;
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS == code ? (authRes.pass ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED) : code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static EDealRes authSubquery(SAuthCxt* pCxt, SNode* pStmt) {
|
static EDealRes authSubquery(SAuthCxt* pCxt, SNode* pStmt) {
|
||||||
return TSDB_CODE_SUCCESS == authQuery(pCxt, pStmt) ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
return TSDB_CODE_SUCCESS == authQuery(pCxt, pStmt) ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t mergeStableTagCond(SNode** pWhere, SNode** pTagCond) {
|
||||||
|
SLogicConditionNode* pLogicCond = (SLogicConditionNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
|
||||||
|
if (NULL == pLogicCond) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
pLogicCond->node.resType.type = TSDB_DATA_TYPE_BOOL;
|
||||||
|
pLogicCond->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes;
|
||||||
|
pLogicCond->condType = LOGIC_COND_TYPE_AND;
|
||||||
|
int32_t code = nodesListMakeStrictAppend(&pLogicCond->pParameterList, *pTagCond);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodesListMakeAppend(&pLogicCond->pParameterList, *pWhere);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
*pWhere = (SNode*)pLogicCond;
|
||||||
|
} else {
|
||||||
|
nodesDestroyNode((SNode*)pLogicCond);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t appendStableTagCond(SNode** pWhere, SNode* pTagCond) {
|
||||||
|
SNode* pTagCondCopy = nodesCloneNode(pTagCond);
|
||||||
|
if (NULL == pTagCondCopy) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NULL == *pWhere) {
|
||||||
|
*pWhere = pTagCondCopy;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pWhere) &&
|
||||||
|
LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)*pWhere)->condType) {
|
||||||
|
return nodesListStrictAppend(((SLogicConditionNode*)*pWhere)->pParameterList, pTagCondCopy);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mergeStableTagCond(pWhere, &pTagCondCopy);
|
||||||
|
}
|
||||||
|
|
||||||
static EDealRes authSelectImpl(SNode* pNode, void* pContext) {
|
static EDealRes authSelectImpl(SNode* pNode, void* pContext) {
|
||||||
SAuthCxt* pCxt = pContext;
|
SSelectAuthCxt* pCxt = pContext;
|
||||||
|
SAuthCxt* pAuthCxt = pCxt->pAuthCxt;
|
||||||
if (QUERY_NODE_REAL_TABLE == nodeType(pNode)) {
|
if (QUERY_NODE_REAL_TABLE == nodeType(pNode)) {
|
||||||
pCxt->errCode = checkAuth(pCxt, ((SRealTableNode*)pNode)->table.dbName, AUTH_TYPE_READ);
|
SNode* pTagCond = NULL;
|
||||||
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
STableNode* pTable = (STableNode*)pNode;
|
||||||
|
pAuthCxt->errCode = checkAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, &pTagCond);
|
||||||
|
if (TSDB_CODE_SUCCESS == pAuthCxt->errCode && NULL != pTagCond) {
|
||||||
|
pAuthCxt->errCode = appendStableTagCond(&pCxt->pSelect->pWhere, pTagCond);
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS == pAuthCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
||||||
} else if (QUERY_NODE_TEMP_TABLE == nodeType(pNode)) {
|
} else if (QUERY_NODE_TEMP_TABLE == nodeType(pNode)) {
|
||||||
return authSubquery(pCxt, ((STempTableNode*)pNode)->pSubquery);
|
return authSubquery(pAuthCxt, ((STempTableNode*)pNode)->pSubquery);
|
||||||
}
|
}
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t authSelect(SAuthCxt* pCxt, SSelectStmt* pSelect) {
|
static int32_t authSelect(SAuthCxt* pCxt, SSelectStmt* pSelect) {
|
||||||
nodesWalkSelectStmt(pSelect, SQL_CLAUSE_FROM, authSelectImpl, pCxt);
|
SSelectAuthCxt cxt = {.pAuthCxt = pCxt, .pSelect = pSelect};
|
||||||
|
nodesWalkSelectStmt(pSelect, SQL_CLAUSE_FROM, authSelectImpl, &cxt);
|
||||||
return pCxt->errCode;
|
return pCxt->errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,11 +148,20 @@ static int32_t authDropUser(SAuthCxt* pCxt, SDropUserStmt* pStmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t authDelete(SAuthCxt* pCxt, SDeleteStmt* pDelete) {
|
static int32_t authDelete(SAuthCxt* pCxt, SDeleteStmt* pDelete) {
|
||||||
return checkAuth(pCxt, ((SRealTableNode*)pDelete->pFromTable)->table.dbName, AUTH_TYPE_WRITE);
|
SNode* pTagCond = NULL;
|
||||||
|
STableNode* pTable = (STableNode*)pDelete->pFromTable;
|
||||||
|
int32_t code = checkAuth(pCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_WRITE, &pTagCond);
|
||||||
|
if (TSDB_CODE_SUCCESS == code && NULL != pTagCond) {
|
||||||
|
code = appendStableTagCond(&pDelete->pWhere, pTagCond);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t authInsert(SAuthCxt* pCxt, SInsertStmt* pInsert) {
|
static int32_t authInsert(SAuthCxt* pCxt, SInsertStmt* pInsert) {
|
||||||
int32_t code = checkAuth(pCxt, ((SRealTableNode*)pInsert->pTable)->table.dbName, AUTH_TYPE_WRITE);
|
SNode* pTagCond = NULL;
|
||||||
|
STableNode* pTable = (STableNode*)pInsert->pTable;
|
||||||
|
// todo check tag condition for subtable
|
||||||
|
int32_t code = checkAuth(pCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_WRITE, &pTagCond);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = authQuery(pCxt, pInsert->pQuery);
|
code = authQuery(pCxt, pInsert->pQuery);
|
||||||
}
|
}
|
||||||
|
@ -97,22 +169,27 @@ static int32_t authInsert(SAuthCxt* pCxt, SInsertStmt* pInsert) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t authShowTables(SAuthCxt* pCxt, SShowStmt* pStmt) {
|
static int32_t authShowTables(SAuthCxt* pCxt, SShowStmt* pStmt) {
|
||||||
return checkAuth(pCxt, ((SValueNode*)pStmt->pDbName)->literal, AUTH_TYPE_READ_OR_WRITE);
|
return checkAuth(pCxt, ((SValueNode*)pStmt->pDbName)->literal, NULL, AUTH_TYPE_READ_OR_WRITE, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t authShowCreateTable(SAuthCxt* pCxt, SShowCreateTableStmt* pStmt) {
|
static int32_t authShowCreateTable(SAuthCxt* pCxt, SShowCreateTableStmt* pStmt) {
|
||||||
return checkAuth(pCxt, pStmt->dbName, AUTH_TYPE_READ);
|
SNode* pTagCond = NULL;
|
||||||
|
// todo check tag condition for subtable
|
||||||
|
return checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_READ, &pTagCond);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t authCreateTable(SAuthCxt* pCxt, SCreateTableStmt* pStmt) {
|
static int32_t authCreateTable(SAuthCxt* pCxt, SCreateTableStmt* pStmt) {
|
||||||
return checkAuth(pCxt, pStmt->dbName, AUTH_TYPE_WRITE);
|
SNode* pTagCond = NULL;
|
||||||
|
// todo check tag condition for subtable
|
||||||
|
return checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, &pTagCond);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t authCreateMultiTable(SAuthCxt* pCxt, SCreateMultiTablesStmt* pStmt) {
|
static int32_t authCreateMultiTable(SAuthCxt* pCxt, SCreateMultiTablesStmt* pStmt) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
SNode* pNode = NULL;
|
SNode* pNode = NULL;
|
||||||
FOREACH(pNode, pStmt->pSubTables) {
|
FOREACH(pNode, pStmt->pSubTables) {
|
||||||
code = checkAuth(pCxt, ((SCreateSubTableClause*)pNode)->dbName, AUTH_TYPE_WRITE);
|
SCreateSubTableClause* pClause = (SCreateSubTableClause*)pNode;
|
||||||
|
code = checkAuth(pCxt, pClause->dbName, NULL, AUTH_TYPE_WRITE, NULL);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -120,6 +197,29 @@ static int32_t authCreateMultiTable(SAuthCxt* pCxt, SCreateMultiTablesStmt* pStm
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t authDropTable(SAuthCxt* pCxt, SDropTableStmt* pStmt) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
SNode* pNode = NULL;
|
||||||
|
FOREACH(pNode, pStmt->pTables) {
|
||||||
|
SDropTableClause* pClause = (SDropTableClause*)pNode;
|
||||||
|
code = checkAuth(pCxt, pClause->dbName, pClause->tableName, AUTH_TYPE_WRITE, NULL);
|
||||||
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t authDropStable(SAuthCxt* pCxt, SDropSuperTableStmt* pStmt) {
|
||||||
|
return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t authAlterTable(SAuthCxt* pCxt, SAlterTableStmt* pStmt) {
|
||||||
|
SNode* pTagCond = NULL;
|
||||||
|
// todo check tag condition for subtable
|
||||||
|
return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
|
static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
|
||||||
switch (nodeType(pStmt)) {
|
switch (nodeType(pStmt)) {
|
||||||
case QUERY_NODE_SET_OPERATOR:
|
case QUERY_NODE_SET_OPERATOR:
|
||||||
|
@ -136,6 +236,13 @@ static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
|
||||||
return authCreateTable(pCxt, (SCreateTableStmt*)pStmt);
|
return authCreateTable(pCxt, (SCreateTableStmt*)pStmt);
|
||||||
case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
|
case QUERY_NODE_CREATE_MULTI_TABLES_STMT:
|
||||||
return authCreateMultiTable(pCxt, (SCreateMultiTablesStmt*)pStmt);
|
return authCreateMultiTable(pCxt, (SCreateMultiTablesStmt*)pStmt);
|
||||||
|
case QUERY_NODE_DROP_TABLE_STMT:
|
||||||
|
return authDropTable(pCxt, (SDropTableStmt*)pStmt);
|
||||||
|
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
|
||||||
|
return authDropStable(pCxt, (SDropSuperTableStmt*)pStmt);
|
||||||
|
case QUERY_NODE_ALTER_TABLE_STMT:
|
||||||
|
case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
|
||||||
|
return authAlterTable(pCxt, (SAlterTableStmt*)pStmt);
|
||||||
case QUERY_NODE_SHOW_DNODES_STMT:
|
case QUERY_NODE_SHOW_DNODES_STMT:
|
||||||
case QUERY_NODE_SHOW_MNODES_STMT:
|
case QUERY_NODE_SHOW_MNODES_STMT:
|
||||||
case QUERY_NODE_SHOW_MODULES_STMT:
|
case QUERY_NODE_SHOW_MODULES_STMT:
|
||||||
|
|
|
@ -125,6 +125,12 @@ static int32_t smlBuildTagRow(SArray* cols, SBoundColInfo* tags, SSchema* pSchem
|
||||||
SSchema* pTagSchema = &pSchema[tags->pColIndex[i]];
|
SSchema* pTagSchema = &pSchema[tags->pColIndex[i]];
|
||||||
SSmlKv* kv = taosArrayGet(cols, i);
|
SSmlKv* kv = taosArrayGet(cols, i);
|
||||||
|
|
||||||
|
if(kv->keyLen != strlen(pTagSchema->name) || memcmp(kv->key, pTagSchema->name, kv->keyLen) != 0 || kv->type != pTagSchema->type){
|
||||||
|
code = TSDB_CODE_SML_INVALID_DATA;
|
||||||
|
uError("SML smlBuildCol error col not same %s", pTagSchema->name);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
taosArrayPush(*tagName, pTagSchema->name);
|
taosArrayPush(*tagName, pTagSchema->name);
|
||||||
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
|
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
|
||||||
// strcpy(val.colName, pTagSchema->name);
|
// strcpy(val.colName, pTagSchema->name);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "parInsertUtil.h"
|
#include "parInsertUtil.h"
|
||||||
#include "parToken.h"
|
#include "parToken.h"
|
||||||
|
#include "scalar.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
|
||||||
|
@ -565,6 +566,120 @@ static int32_t checkAndTrimValue(SToken* pToken, char* tmpTokenBuf, SMsgBuf* pMs
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct SRewriteTagCondCxt {
|
||||||
|
SArray* pTagVals;
|
||||||
|
SArray* pTagName;
|
||||||
|
int32_t code;
|
||||||
|
} SRewriteTagCondCxt;
|
||||||
|
|
||||||
|
static int32_t rewriteTagCondColumnImpl(STagVal* pVal, SNode** pNode) {
|
||||||
|
SValueNode* pValue = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||||
|
if (NULL == pValue) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
pValue->node.resType.type = pVal->type;
|
||||||
|
switch (pVal->type) {
|
||||||
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
|
pValue->datum.b = *(int8_t*)(&pVal->i64);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_TINYINT:
|
||||||
|
pValue->datum.i = *(int8_t*)(&pVal->i64);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
pValue->datum.i = *(int16_t*)(&pVal->i64);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_INT:
|
||||||
|
pValue->datum.i = *(int32_t*)(&pVal->i64);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_BIGINT:
|
||||||
|
pValue->datum.i = pVal->i64;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_FLOAT:
|
||||||
|
pValue->datum.d = *(float*)(&pVal->i64);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_DOUBLE:
|
||||||
|
pValue->datum.d = *(double*)(&pVal->i64);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_VARCHAR:
|
||||||
|
case TSDB_DATA_TYPE_NCHAR:
|
||||||
|
pValue->datum.p = taosMemoryCalloc(1, pVal->nData + VARSTR_HEADER_SIZE);
|
||||||
|
if (NULL == pValue->datum.p) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
varDataSetLen(pValue->datum.p, pVal->nData);
|
||||||
|
memcpy(varDataVal(pValue->datum.p), pVal->pData, pVal->nData);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
pValue->datum.i = pVal->i64;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UTINYINT:
|
||||||
|
pValue->datum.i = *(uint8_t*)(&pVal->i64);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_USMALLINT:
|
||||||
|
pValue->datum.i = *(uint16_t*)(&pVal->i64);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UINT:
|
||||||
|
pValue->datum.i = *(uint32_t*)(&pVal->i64);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_UBIGINT:
|
||||||
|
pValue->datum.i = *(uint64_t*)(&pVal->i64);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_JSON:
|
||||||
|
case TSDB_DATA_TYPE_VARBINARY:
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL:
|
||||||
|
case TSDB_DATA_TYPE_BLOB:
|
||||||
|
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
||||||
|
default:
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t rewriteTagCondColumn(SArray* pTagVals, SArray* pTagName, SNode** pNode) {
|
||||||
|
SColumnNode* pCol = (SColumnNode*)*pNode;
|
||||||
|
int32_t ntags = taosArrayGetSize(pTagName);
|
||||||
|
for (int32_t i = 0; i < ntags; ++i) {
|
||||||
|
char* pTagColName = taosArrayGet(pTagName, i);
|
||||||
|
if (0 == strcmp(pTagColName, pCol->colName)) {
|
||||||
|
return rewriteTagCondColumnImpl(taosArrayGet(pTagVals, i), pNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TSDB_CODE_PAR_PERMISSION_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static EDealRes rewriteTagCond(SNode** pNode, void* pContext) {
|
||||||
|
if (QUERY_NODE_COLUMN == nodeType(*pNode)) {
|
||||||
|
SRewriteTagCondCxt* pCxt = pContext;
|
||||||
|
pCxt->code = rewriteTagCondColumn(pCxt->pTagVals, pCxt->pTagName, pNode);
|
||||||
|
return (TSDB_CODE_SUCCESS == pCxt->code ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
|
||||||
|
}
|
||||||
|
return DEAL_RES_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t setTagVal(SArray* pTagVals, SArray* pTagName, SNode* pCond) {
|
||||||
|
SRewriteTagCondCxt cxt = {.code = TSDB_CODE_SUCCESS, .pTagVals = pTagVals, .pTagName = pTagName};
|
||||||
|
nodesRewriteExpr(&pCond, rewriteTagCond, &cxt);
|
||||||
|
return cxt.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t checkTagCondResult(SNode* pResult) {
|
||||||
|
return (QUERY_NODE_VALUE == nodeType(pResult) && ((SValueNode*)pResult)->datum.b) ? TSDB_CODE_SUCCESS
|
||||||
|
: TSDB_CODE_PAR_PERMISSION_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t checkSubtablePrivilege(SArray* pTagVals, SArray* pTagName, SNode* pCond) {
|
||||||
|
int32_t code = setTagVal(pTagVals, pTagName, pCond);
|
||||||
|
SNode* pNew = NULL;
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = scalarCalculateConstants(pCond, &pNew);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = checkTagCondResult(pNew);
|
||||||
|
}
|
||||||
|
nodesDestroyNode(pNew);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
// pSql -> tag1_value, ...)
|
// pSql -> tag1_value, ...)
|
||||||
static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
@ -722,25 +837,31 @@ static int32_t parseUsingClauseBottom(SInsertParseContext* pCxt, SVnodeModifyOpS
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setUserAuthInfo(SParseContext* pCxt, SName* pTbName, SUserAuthInfo* pInfo) {
|
||||||
|
snprintf(pInfo->user, sizeof(pInfo->user), "%s", pCxt->pUser);
|
||||||
|
memcpy(&pInfo->tbName, pTbName, sizeof(SName));
|
||||||
|
pInfo->type = AUTH_TYPE_WRITE;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t checkAuth(SParseContext* pCxt, SName* pTbName, bool* pMissCache) {
|
static int32_t checkAuth(SParseContext* pCxt, SName* pTbName, bool* pMissCache) {
|
||||||
char dbFName[TSDB_DB_FNAME_LEN];
|
|
||||||
tNameGetFullDbName(pTbName, dbFName);
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
bool pass = true;
|
SUserAuthInfo authInfo = {0};
|
||||||
|
setUserAuthInfo(pCxt, pTbName, &authInfo);
|
||||||
|
SUserAuthRes authRes = {0};
|
||||||
bool exists = true;
|
bool exists = true;
|
||||||
if (pCxt->async) {
|
if (pCxt->async) {
|
||||||
code = catalogChkAuthFromCache(pCxt->pCatalog, pCxt->pUser, dbFName, AUTH_TYPE_WRITE, &pass, &exists);
|
code = catalogChkAuthFromCache(pCxt->pCatalog, &authInfo, &authRes, &exists);
|
||||||
} else {
|
} else {
|
||||||
SRequestConnInfo conn = {.pTrans = pCxt->pTransporter,
|
SRequestConnInfo conn = {.pTrans = pCxt->pTransporter,
|
||||||
.requestId = pCxt->requestId,
|
.requestId = pCxt->requestId,
|
||||||
.requestObjRefId = pCxt->requestRid,
|
.requestObjRefId = pCxt->requestRid,
|
||||||
.mgmtEps = pCxt->mgmtEpSet};
|
.mgmtEps = pCxt->mgmtEpSet};
|
||||||
code = catalogChkAuth(pCxt->pCatalog, &conn, pCxt->pUser, dbFName, AUTH_TYPE_WRITE, &pass);
|
code = catalogChkAuth(pCxt->pCatalog, &conn, &authInfo, &authRes);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
*pMissCache = true;
|
*pMissCache = true;
|
||||||
} else if (!pass) {
|
} else if (!authRes.pass) {
|
||||||
code = TSDB_CODE_PAR_PERMISSION_DENIED;
|
code = TSDB_CODE_PAR_PERMISSION_DENIED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1906,7 +2027,7 @@ static int32_t buildInsertUserAuthReq(const char* pUser, SName* pName, SArray**
|
||||||
|
|
||||||
SUserAuthInfo userAuth = {.type = AUTH_TYPE_WRITE};
|
SUserAuthInfo userAuth = {.type = AUTH_TYPE_WRITE};
|
||||||
snprintf(userAuth.user, sizeof(userAuth.user), "%s", pUser);
|
snprintf(userAuth.user, sizeof(userAuth.user), "%s", pUser);
|
||||||
tNameGetFullDbName(pName, userAuth.dbFName);
|
// tNameGetFullDbName(pName, userAuth.dbFName);
|
||||||
taosArrayPush(*pUserAuth, &userAuth);
|
taosArrayPush(*pUserAuth, &userAuth);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
|
@ -470,11 +470,11 @@ int32_t insMergeTableDataCxt(SHashObj* pTableHash, SArray** pVgDataBlocks) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
SVgroupDataCxt* pVgCxt = NULL;
|
SVgroupDataCxt* pVgCxt = NULL;
|
||||||
int32_t vgId = pTableCxt->pMeta->vgId;
|
int32_t vgId = pTableCxt->pMeta->vgId;
|
||||||
void** p = taosHashGet(pVgroupHash, &vgId, sizeof(vgId));
|
void** pp = taosHashGet(pVgroupHash, &vgId, sizeof(vgId));
|
||||||
if (NULL == p) {
|
if (NULL == pp) {
|
||||||
code = createVgroupDataCxt(pTableCxt, pVgroupHash, pVgroupList, &pVgCxt);
|
code = createVgroupDataCxt(pTableCxt, pVgroupHash, pVgroupList, &pVgCxt);
|
||||||
} else {
|
} else {
|
||||||
pVgCxt = *(SVgroupDataCxt**)p;
|
pVgCxt = *(SVgroupDataCxt**)pp;
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = fillVgroupDataCxt(pTableCxt, pVgCxt);
|
code = fillVgroupDataCxt(pTableCxt, pVgCxt);
|
||||||
|
|
|
@ -978,7 +978,8 @@ static EDealRes translateColumnUseAlias(STranslateContext* pCxt, SColumnNode** p
|
||||||
}
|
}
|
||||||
|
|
||||||
static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) {
|
static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) {
|
||||||
if (NULL == pCxt->pCurrStmt || isSelectStmt(pCxt->pCurrStmt) && NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable) {
|
if (NULL == pCxt->pCurrStmt ||
|
||||||
|
(isSelectStmt(pCxt->pCurrStmt) && NULL == ((SSelectStmt*)pCxt->pCurrStmt)->pFromTable)) {
|
||||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName);
|
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1691,6 +1692,7 @@ static void setFuncClassification(SNode* pCurrStmt, SFunctionNode* pFunc) {
|
||||||
pSelect->hasUniqueFunc = pSelect->hasUniqueFunc ? true : (FUNCTION_TYPE_UNIQUE == pFunc->funcType);
|
pSelect->hasUniqueFunc = pSelect->hasUniqueFunc ? true : (FUNCTION_TYPE_UNIQUE == pFunc->funcType);
|
||||||
pSelect->hasTailFunc = pSelect->hasTailFunc ? true : (FUNCTION_TYPE_TAIL == pFunc->funcType);
|
pSelect->hasTailFunc = pSelect->hasTailFunc ? true : (FUNCTION_TYPE_TAIL == pFunc->funcType);
|
||||||
pSelect->hasInterpFunc = pSelect->hasInterpFunc ? true : (FUNCTION_TYPE_INTERP == pFunc->funcType);
|
pSelect->hasInterpFunc = pSelect->hasInterpFunc ? true : (FUNCTION_TYPE_INTERP == pFunc->funcType);
|
||||||
|
pSelect->hasInterpPseudoColFunc = pSelect->hasInterpPseudoColFunc ? true : fmIsInterpPseudoColumnFunc(pFunc->funcId);
|
||||||
pSelect->hasLastRowFunc = pSelect->hasLastRowFunc ? true : (FUNCTION_TYPE_LAST_ROW == pFunc->funcType);
|
pSelect->hasLastRowFunc = pSelect->hasLastRowFunc ? true : (FUNCTION_TYPE_LAST_ROW == pFunc->funcType);
|
||||||
pSelect->hasLastFunc = pSelect->hasLastFunc ? true : (FUNCTION_TYPE_LAST == pFunc->funcType);
|
pSelect->hasLastFunc = pSelect->hasLastFunc ? true : (FUNCTION_TYPE_LAST == pFunc->funcType);
|
||||||
pSelect->hasTimeLineFunc = pSelect->hasTimeLineFunc ? true : fmIsTimelineFunc(pFunc->funcId);
|
pSelect->hasTimeLineFunc = pSelect->hasTimeLineFunc ? true : fmIsTimelineFunc(pFunc->funcId);
|
||||||
|
@ -3369,6 +3371,9 @@ static int32_t translateInterp(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
if (NULL != pSelect->pRange || NULL != pSelect->pEvery || NULL != pSelect->pFill) {
|
if (NULL != pSelect->pRange || NULL != pSelect->pEvery || NULL != pSelect->pFill) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_INTERP_CLAUSE);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_INTERP_CLAUSE);
|
||||||
}
|
}
|
||||||
|
if (pSelect->hasInterpPseudoColFunc) {
|
||||||
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC, "Has Interp pseudo column(s) but missing interp function");
|
||||||
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6485,22 +6490,69 @@ static int32_t translateDropFunction(STranslateContext* pCxt, SDropFunctionStmt*
|
||||||
return buildCmdMsg(pCxt, TDMT_MND_DROP_FUNC, (FSerializeFunc)tSerializeSDropFuncReq, &req);
|
return buildCmdMsg(pCxt, TDMT_MND_DROP_FUNC, (FSerializeFunc)tSerializeSDropFuncReq, &req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t createRealTableForGrantTable(SGrantStmt* pStmt, SRealTableNode** pTable) {
|
||||||
|
SRealTableNode* pRealTable = (SRealTableNode*)nodesMakeNode(QUERY_NODE_REAL_TABLE);
|
||||||
|
if (NULL == pRealTable) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
strcpy(pRealTable->table.dbName, pStmt->objName);
|
||||||
|
strcpy(pRealTable->table.tableName, pStmt->tabName);
|
||||||
|
strcpy(pRealTable->table.tableAlias, pStmt->tabName);
|
||||||
|
*pTable = pRealTable;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateGrantTagCond(STranslateContext* pCxt, SGrantStmt* pStmt, SAlterUserReq* pReq) {
|
||||||
|
if (NULL == pStmt->pTagCond) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
if ('\0' == pStmt->tabName[0] || '*' == pStmt->tabName[0]) {
|
||||||
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
|
||||||
|
"The With clause can only be used for table level privilege");
|
||||||
|
}
|
||||||
|
|
||||||
|
pCxt->pCurrStmt = (SNode*)pStmt;
|
||||||
|
SRealTableNode* pTable = NULL;
|
||||||
|
int32_t code = createRealTableForGrantTable(pStmt, &pTable);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
SName name;
|
||||||
|
code = getTableMetaImpl(pCxt, toName(pCxt->pParseCxt->acctId, pTable->table.dbName, pTable->table.tableName, &name),
|
||||||
|
&(pTable->pMeta));
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = addNamespace(pCxt, pTable);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = translateExpr(pCxt, &pStmt->pTagCond);
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodesNodeToString(pStmt->pTagCond, false, &pReq->tagCond, &pReq->tagCondLen);
|
||||||
|
}
|
||||||
|
nodesDestroyNode((SNode*)pTable);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t translateGrant(STranslateContext* pCxt, SGrantStmt* pStmt) {
|
static int32_t translateGrant(STranslateContext* pCxt, SGrantStmt* pStmt) {
|
||||||
SAlterUserReq req = {0};
|
SAlterUserReq req = {0};
|
||||||
if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_ALL) ||
|
if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_ALL) ||
|
||||||
(BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_READ) &&
|
(BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_READ) &&
|
||||||
BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_WRITE))) {
|
BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_WRITE))) {
|
||||||
req.alterType = TSDB_ALTER_USER_ADD_ALL_DB;
|
req.alterType = ('\0' == pStmt->tabName[0] ? TSDB_ALTER_USER_ADD_ALL_DB : TSDB_ALTER_USER_ADD_ALL_TABLE);
|
||||||
} else if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_READ)) {
|
} else if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_READ)) {
|
||||||
req.alterType = TSDB_ALTER_USER_ADD_READ_DB;
|
req.alterType = ('\0' == pStmt->tabName[0] ? TSDB_ALTER_USER_ADD_READ_DB : TSDB_ALTER_USER_ADD_READ_TABLE);
|
||||||
} else if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_WRITE)) {
|
} else if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_WRITE)) {
|
||||||
req.alterType = TSDB_ALTER_USER_ADD_WRITE_DB;
|
req.alterType = ('\0' == pStmt->tabName[0] ? TSDB_ALTER_USER_ADD_WRITE_DB : TSDB_ALTER_USER_ADD_WRITE_TABLE);
|
||||||
} else if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_SUBSCRIBE)) {
|
} else if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_SUBSCRIBE)) {
|
||||||
req.alterType = TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC;
|
req.alterType = TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC;
|
||||||
}
|
}
|
||||||
strcpy(req.user, pStmt->userName);
|
strcpy(req.user, pStmt->userName);
|
||||||
sprintf(req.objname, "%d.%s", pCxt->pParseCxt->acctId, pStmt->objName);
|
sprintf(req.objname, "%d.%s", pCxt->pParseCxt->acctId, pStmt->objName);
|
||||||
return buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &req);
|
sprintf(req.tabName, "%s", pStmt->tabName);
|
||||||
|
int32_t code = translateGrantTagCond(pCxt, pStmt, &req);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &req);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateRevoke(STranslateContext* pCxt, SRevokeStmt* pStmt) {
|
static int32_t translateRevoke(STranslateContext* pCxt, SRevokeStmt* pStmt) {
|
||||||
|
@ -6508,16 +6560,17 @@ static int32_t translateRevoke(STranslateContext* pCxt, SRevokeStmt* pStmt) {
|
||||||
if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_ALL) ||
|
if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_ALL) ||
|
||||||
(BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_READ) &&
|
(BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_READ) &&
|
||||||
BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_WRITE))) {
|
BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_WRITE))) {
|
||||||
req.alterType = TSDB_ALTER_USER_REMOVE_ALL_DB;
|
req.alterType = ('\0' == pStmt->tabName[0] ? TSDB_ALTER_USER_REMOVE_ALL_DB : TSDB_ALTER_USER_REMOVE_ALL_TABLE);
|
||||||
} else if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_READ)) {
|
} else if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_READ)) {
|
||||||
req.alterType = TSDB_ALTER_USER_REMOVE_READ_DB;
|
req.alterType = ('\0' == pStmt->tabName[0] ? TSDB_ALTER_USER_REMOVE_READ_DB : TSDB_ALTER_USER_REMOVE_READ_TABLE);
|
||||||
} else if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_WRITE)) {
|
} else if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_WRITE)) {
|
||||||
req.alterType = TSDB_ALTER_USER_REMOVE_WRITE_DB;
|
req.alterType = ('\0' == pStmt->tabName[0] ? TSDB_ALTER_USER_REMOVE_WRITE_DB : TSDB_ALTER_USER_REMOVE_WRITE_TABLE);
|
||||||
} else if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_SUBSCRIBE)) {
|
} else if (BIT_FLAG_TEST_MASK(pStmt->privileges, PRIVILEGE_TYPE_SUBSCRIBE)) {
|
||||||
req.alterType = TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC;
|
req.alterType = TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC;
|
||||||
}
|
}
|
||||||
strcpy(req.user, pStmt->userName);
|
strcpy(req.user, pStmt->userName);
|
||||||
sprintf(req.objname, "%d.%s", pCxt->pParseCxt->acctId, pStmt->objName);
|
sprintf(req.objname, "%d.%s", pCxt->pParseCxt->acctId, pStmt->objName);
|
||||||
|
sprintf(req.tabName, "%s", pStmt->tabName);
|
||||||
return buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &req);
|
return buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
#include "querynodes.h"
|
#include "querynodes.h"
|
||||||
|
|
||||||
#define USER_AUTH_KEY_MAX_LEN TSDB_USER_LEN + TSDB_DB_FNAME_LEN + 2
|
#define USER_AUTH_KEY_MAX_LEN TSDB_USER_LEN + TSDB_TABLE_FNAME_LEN + 2
|
||||||
|
|
||||||
const void* nullPointer = NULL;
|
const void* nullPointer = NULL;
|
||||||
|
|
||||||
|
@ -496,24 +496,44 @@ int32_t getVnodeSysTableTargetName(int32_t acctId, SNode* pWhere, SName* pName)
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t userAuthToString(int32_t acctId, const char* pUser, const char* pDb, AUTH_TYPE type, char* pStr) {
|
static int32_t userAuthToString(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
|
||||||
return sprintf(pStr, "%s*%d.%s*%d", pUser, acctId, pDb, type);
|
char* pStr) {
|
||||||
|
return sprintf(pStr, "%s*%d*%s*%s*%d", pUser, acctId, pDb, (NULL != pTable && '\0' == pTable[0]) ? NULL : pTable,
|
||||||
|
type);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t userAuthToStringExt(const char* pUser, const char* pDbFName, AUTH_TYPE type, char* pStr) {
|
static int32_t getIntegerFromAuthStr(const char* pStart, char** pNext) {
|
||||||
return sprintf(pStr, "%s*%s*%d", pUser, pDbFName, type);
|
char* p = strchr(pStart, '*');
|
||||||
|
char buf[10] = {0};
|
||||||
|
if (NULL == p) {
|
||||||
|
strcpy(buf, pStart);
|
||||||
|
*pNext = NULL;
|
||||||
|
} else {
|
||||||
|
strncpy(buf, pStart, p - pStart);
|
||||||
|
*pNext = ++p;
|
||||||
|
}
|
||||||
|
return taosStr2Int32(buf, NULL, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void getStringFromAuthStr(const char* pStart, char* pStr, char** pNext) {
|
||||||
|
char* p = strchr(pStart, '*');
|
||||||
|
if (NULL == p) {
|
||||||
|
strcpy(pStr, pStart);
|
||||||
|
*pNext = NULL;
|
||||||
|
} else {
|
||||||
|
strncpy(pStr, pStart, p - pStart);
|
||||||
|
*pNext = ++p;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void stringToUserAuth(const char* pStr, int32_t len, SUserAuthInfo* pUserAuth) {
|
static void stringToUserAuth(const char* pStr, int32_t len, SUserAuthInfo* pUserAuth) {
|
||||||
char* p1 = strchr(pStr, '*');
|
char* p = NULL;
|
||||||
strncpy(pUserAuth->user, pStr, p1 - pStr);
|
getStringFromAuthStr(pStr, pUserAuth->user, &p);
|
||||||
++p1;
|
pUserAuth->tbName.acctId = getIntegerFromAuthStr(p, &p);
|
||||||
char* p2 = strchr(p1, '*');
|
getStringFromAuthStr(p, pUserAuth->tbName.dbname, &p);
|
||||||
strncpy(pUserAuth->dbFName, p1, p2 - p1);
|
getStringFromAuthStr(p, pUserAuth->tbName.tname, &p);
|
||||||
++p2;
|
pUserAuth->tbName.type = TSDB_TABLE_NAME_T;
|
||||||
char buf[10] = {0};
|
pUserAuth->type = getIntegerFromAuthStr(p, &p);
|
||||||
strncpy(buf, p2, len - (p2 - pStr));
|
|
||||||
pUserAuth->type = taosStr2Int32(buf, NULL, 10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t buildTableReq(SHashObj* pTablesHash, SArray** pTables) {
|
static int32_t buildTableReq(SHashObj* pTablesHash, SArray** pTables) {
|
||||||
|
@ -586,8 +606,10 @@ static int32_t buildUserAuthReq(SHashObj* pUserAuthHash, SArray** pUserAuth) {
|
||||||
while (NULL != p) {
|
while (NULL != p) {
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
char* pKey = taosHashGetKey(p, &len);
|
char* pKey = taosHashGetKey(p, &len);
|
||||||
|
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||||
|
strncpy(key, pKey, len);
|
||||||
SUserAuthInfo userAuth = {0};
|
SUserAuthInfo userAuth = {0};
|
||||||
stringToUserAuth(pKey, len, &userAuth);
|
stringToUserAuth(key, len, &userAuth);
|
||||||
taosArrayPush(*pUserAuth, &userAuth);
|
taosArrayPush(*pUserAuth, &userAuth);
|
||||||
p = taosHashIterate(pUserAuthHash, p);
|
p = taosHashIterate(pUserAuthHash, p);
|
||||||
}
|
}
|
||||||
|
@ -712,7 +734,8 @@ static int32_t putUserAuthToCache(const SArray* pUserAuthReq, const SArray* pUse
|
||||||
for (int32_t i = 0; i < nvgs; ++i) {
|
for (int32_t i = 0; i < nvgs; ++i) {
|
||||||
SUserAuthInfo* pUser = taosArrayGet(pUserAuthReq, i);
|
SUserAuthInfo* pUser = taosArrayGet(pUserAuthReq, i);
|
||||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||||
int32_t len = userAuthToStringExt(pUser->user, pUser->dbFName, pUser->type, key);
|
int32_t len = userAuthToString(pUser->tbName.acctId, pUser->user, pUser->tbName.dbname, pUser->tbName.tname,
|
||||||
|
pUser->type, key);
|
||||||
if (TSDB_CODE_SUCCESS != putMetaDataToHash(key, len, pUserAuthData, i, pUserAuth)) {
|
if (TSDB_CODE_SUCCESS != putMetaDataToHash(key, len, pUserAuthData, i, pUserAuth)) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -910,33 +933,24 @@ static int32_t reserveUserAuthInCacheImpl(const char* pKey, int32_t len, SParseM
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool pass = false;
|
return taosHashPut(pMetaCache->pUserAuth, pKey, len, &nullPointer, POINTER_BYTES);
|
||||||
return taosHashPut(pMetaCache->pUserAuth, pKey, len, &pass, sizeof(pass));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
SParseMetaCache* pMetaCache) {
|
||||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||||
int32_t len = userAuthToString(acctId, pUser, pDb, type, key);
|
int32_t len = userAuthToString(acctId, pUser, pDb, pTable, type, key);
|
||||||
return reserveUserAuthInCacheImpl(key, len, pMetaCache);
|
return reserveUserAuthInCacheImpl(key, len, pMetaCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t reserveUserAuthInCacheExt(const char* pUser, const SName* pName, AUTH_TYPE type, SParseMetaCache* pMetaCache) {
|
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, SUserAuthInfo* pAuthReq, SUserAuthRes* pAuthRes) {
|
||||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
|
||||||
tNameGetFullDbName(pName, dbFName);
|
|
||||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||||
int32_t len = userAuthToStringExt(pUser, dbFName, type, key);
|
int32_t len = userAuthToString(pAuthReq->tbName.acctId, pAuthReq->user, pAuthReq->tbName.dbname,
|
||||||
return reserveUserAuthInCacheImpl(key, len, pMetaCache);
|
pAuthReq->tbName.tname, pAuthReq->type, key);
|
||||||
}
|
SUserAuthRes* pAuth = NULL;
|
||||||
|
int32_t code = getMetaDataFromHash(key, len, pMetaCache->pUserAuth, (void**)&pAuth);
|
||||||
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, const char* pUser, const char* pDbFName, AUTH_TYPE type,
|
|
||||||
bool* pPass) {
|
|
||||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
|
||||||
int32_t len = userAuthToStringExt(pUser, pDbFName, type, key);
|
|
||||||
bool* pRes = NULL;
|
|
||||||
int32_t code = getMetaDataFromHash(key, len, pMetaCache->pUserAuth, (void**)&pRes);
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
*pPass = *pRes;
|
memcpy(pAuthRes, pAuth, sizeof(SUserAuthRes));
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -279,15 +279,13 @@ int32_t __catalogGetDBCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const char* d
|
||||||
return g_mockCatalogService->catalogGetDBCfg(dbFName, pDbCfg);
|
return g_mockCatalogService->catalogGetDBCfg(dbFName, pDbCfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type,
|
int32_t __catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, SUserAuthInfo *pAuth, SUserAuthRes* pRes) {
|
||||||
bool* pass) {
|
pRes->pass = true;
|
||||||
*pass = true;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogChkAuthFromCache(SCatalog* pCtg, const char* user, const char* dbFName, AUTH_TYPE type, bool* pass,
|
int32_t __catalogChkAuthFromCache(SCatalog* pCtg, SUserAuthInfo *pAuth, SUserAuthRes* pRes, bool* exists) {
|
||||||
bool* exists) {
|
pRes->pass = true;
|
||||||
*pass = true;
|
|
||||||
*exists = true;
|
*exists = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -589,8 +589,8 @@ class MockCatalogServiceImpl {
|
||||||
*pUserAuthData = taosArrayInit(num, sizeof(SMetaRes));
|
*pUserAuthData = taosArrayInit(num, sizeof(SMetaRes));
|
||||||
for (int32_t i = 0; i < num; ++i) {
|
for (int32_t i = 0; i < num; ++i) {
|
||||||
SMetaRes res = {0};
|
SMetaRes res = {0};
|
||||||
res.pRes = taosMemoryCalloc(1, sizeof(bool));
|
res.pRes = taosMemoryCalloc(1, sizeof(SUserAuthRes));
|
||||||
*(bool*)(res.pRes) = true;
|
((SUserAuthRes*)res.pRes)->pass = true;
|
||||||
taosArrayPush(*pUserAuthData, &res);
|
taosArrayPush(*pUserAuthData, &res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -760,10 +760,10 @@ TEST_F(ParserInitialCTest, createStable) {
|
||||||
addFieldToCreateStbReq(false, "a15", TSDB_DATA_TYPE_VARCHAR, 50 + VARSTR_HEADER_SIZE);
|
addFieldToCreateStbReq(false, "a15", TSDB_DATA_TYPE_VARCHAR, 50 + VARSTR_HEADER_SIZE);
|
||||||
run("CREATE STABLE IF NOT EXISTS rollup_db.t1("
|
run("CREATE STABLE IF NOT EXISTS rollup_db.t1("
|
||||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), "
|
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), "
|
||||||
"c8 SMALLINT, c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, "
|
"c8 SMALLINT, c9 SMALLINT UNSIGNED, c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, "
|
||||||
"c13 NCHAR(30), c14 VARCHAR(50)) "
|
"c13 NCHAR(30), c14 VARCHAR(50)) "
|
||||||
"TAGS (a1 TIMESTAMP, a2 INT, a3 INT UNSIGNED, a4 BIGINT, a5 BIGINT UNSIGNED, a6 FLOAT, a7 DOUBLE, "
|
"TAGS (a1 TIMESTAMP, a2 INT, a3 INT UNSIGNED, a4 BIGINT, a5 BIGINT UNSIGNED, a6 FLOAT, a7 DOUBLE, "
|
||||||
"a8 BINARY(20), a9 SMALLINT, a10 SMALLINT UNSIGNED COMMENT 'test column comment', a11 TINYINT, "
|
"a8 BINARY(20), a9 SMALLINT, a10 SMALLINT UNSIGNED, a11 TINYINT, "
|
||||||
"a12 TINYINT UNSIGNED, a13 BOOL, a14 NCHAR(30), a15 VARCHAR(50)) "
|
"a12 TINYINT UNSIGNED, a13 BOOL, a14 NCHAR(30), a15 VARCHAR(50)) "
|
||||||
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (MIN) MAX_DELAY 100s,10m WATERMARK 10a,1m "
|
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (MIN) MAX_DELAY 100s,10m WATERMARK 10a,1m "
|
||||||
"DELETE_MARK 1000s,200m");
|
"DELETE_MARK 1000s,200m");
|
||||||
|
@ -1023,16 +1023,16 @@ TEST_F(ParserInitialCTest, createTable) {
|
||||||
|
|
||||||
run("CREATE TABLE IF NOT EXISTS test.t1("
|
run("CREATE TABLE IF NOT EXISTS test.t1("
|
||||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), "
|
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), "
|
||||||
"c8 SMALLINT, c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, "
|
"c8 SMALLINT, c9 SMALLINT UNSIGNED, c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, "
|
||||||
"c13 NCHAR(30), c15 VARCHAR(50)) "
|
"c13 NCHAR(30), c15 VARCHAR(50)) "
|
||||||
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)");
|
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)");
|
||||||
|
|
||||||
run("CREATE TABLE IF NOT EXISTS rollup_db.t1("
|
run("CREATE TABLE IF NOT EXISTS rollup_db.t1("
|
||||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), "
|
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), "
|
||||||
"c8 SMALLINT, c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, "
|
"c8 SMALLINT, c9 SMALLINT UNSIGNED, c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, "
|
||||||
"c13 NCHAR(30), c14 VARCHAR(50)) "
|
"c13 NCHAR(30), c14 VARCHAR(50)) "
|
||||||
"TAGS (a1 TIMESTAMP, a2 INT, a3 INT UNSIGNED, a4 BIGINT, a5 BIGINT UNSIGNED, a6 FLOAT, a7 DOUBLE, a8 BINARY(20), "
|
"TAGS (a1 TIMESTAMP, a2 INT, a3 INT UNSIGNED, a4 BIGINT, a5 BIGINT UNSIGNED, a6 FLOAT, a7 DOUBLE, a8 BINARY(20), "
|
||||||
"a9 SMALLINT, a10 SMALLINT UNSIGNED COMMENT 'test column comment', a11 TINYINT, a12 TINYINT UNSIGNED, a13 BOOL, "
|
"a9 SMALLINT, a10 SMALLINT UNSIGNED, a11 TINYINT, a12 TINYINT UNSIGNED, a13 BOOL, "
|
||||||
"a14 NCHAR(30), a15 VARCHAR(50)) "
|
"a14 NCHAR(30), a15 VARCHAR(50)) "
|
||||||
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (MIN)");
|
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (MIN)");
|
||||||
|
|
||||||
|
|
|
@ -1079,11 +1079,23 @@ static bool sortPriKeyOptMayBeOptimized(SLogicNode* pNode) {
|
||||||
if (!sortPriKeyOptIsPriKeyOrderBy(pSort->pSortKeys) || 1 != LIST_LENGTH(pSort->node.pChildren)) {
|
if (!sortPriKeyOptIsPriKeyOrderBy(pSort->pSortKeys) || 1 != LIST_LENGTH(pSort->node.pChildren)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
SNode* pChild;
|
||||||
|
FOREACH(pChild, pSort->node.pChildren) {
|
||||||
|
SLogicNode* pSortDescendent = optFindPossibleNode((SLogicNode*)pChild, sortPriKeyOptMayBeOptimized);
|
||||||
|
if (pSortDescendent != NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sortPriKeyOptGetSequencingNodesImpl(SLogicNode* pNode, bool groupSort, bool* pNotOptimize,
|
static int32_t sortPriKeyOptGetSequencingNodesImpl(SLogicNode* pNode, bool groupSort, bool* pNotOptimize,
|
||||||
SNodeList** pSequencingNodes) {
|
SNodeList** pSequencingNodes) {
|
||||||
|
if (NULL != pNode->pLimit || NULL != pNode->pSlimit) {
|
||||||
|
*pNotOptimize = false;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
switch (nodeType(pNode)) {
|
switch (nodeType(pNode)) {
|
||||||
case QUERY_NODE_LOGIC_PLAN_SCAN: {
|
case QUERY_NODE_LOGIC_PLAN_SCAN: {
|
||||||
SScanLogicNode* pScan = (SScanLogicNode*)pNode;
|
SScanLogicNode* pScan = (SScanLogicNode*)pNode;
|
||||||
|
|
|
@ -54,7 +54,6 @@ typedef enum {
|
||||||
|
|
||||||
#define SCHEDULE_DEFAULT_MAX_JOB_NUM 1000
|
#define SCHEDULE_DEFAULT_MAX_JOB_NUM 1000
|
||||||
#define SCHEDULE_DEFAULT_MAX_TASK_NUM 1000
|
#define SCHEDULE_DEFAULT_MAX_TASK_NUM 1000
|
||||||
#define SCHEDULE_DEFAULT_MAX_NODE_TABLE_NUM 200 // unit is TSDB_TABLE_NUM_UNIT
|
|
||||||
#define SCHEDULE_DEFAULT_POLICY SCH_LOAD_SEQ
|
#define SCHEDULE_DEFAULT_POLICY SCH_LOAD_SEQ
|
||||||
#define SCHEDULE_DEFAULT_MAX_NODE_NUM 20
|
#define SCHEDULE_DEFAULT_MAX_NODE_NUM 20
|
||||||
|
|
||||||
|
@ -134,7 +133,7 @@ typedef struct SSchStatusFps {
|
||||||
|
|
||||||
typedef struct SSchedulerCfg {
|
typedef struct SSchedulerCfg {
|
||||||
uint32_t maxJobNum;
|
uint32_t maxJobNum;
|
||||||
int32_t maxNodeTableNum;
|
int64_t maxNodeTableNum;
|
||||||
SCH_POLICY schPolicy;
|
SCH_POLICY schPolicy;
|
||||||
bool enableReSchedule;
|
bool enableReSchedule;
|
||||||
} SSchedulerCfg;
|
} SSchedulerCfg;
|
||||||
|
@ -175,7 +174,7 @@ typedef struct SSchHbCallbackParam {
|
||||||
typedef struct SSchFlowControl {
|
typedef struct SSchFlowControl {
|
||||||
SRWLatch lock;
|
SRWLatch lock;
|
||||||
bool sorted;
|
bool sorted;
|
||||||
int32_t tableNumSum;
|
int64_t tableNumSum;
|
||||||
uint32_t execTaskNum;
|
uint32_t execTaskNum;
|
||||||
SArray *taskList; // Element is SSchTask*
|
SArray *taskList; // Element is SSchTask*
|
||||||
} SSchFlowControl;
|
} SSchFlowControl;
|
||||||
|
|
|
@ -46,7 +46,7 @@ int32_t schChkJobNeedFlowCtrl(SSchJob *pJob, SSchLevel *pLevel) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sum = 0;
|
int64_t sum = 0;
|
||||||
int32_t taskNum = taosArrayGetSize(pJob->dataSrcTasks);
|
int32_t taskNum = taosArrayGetSize(pJob->dataSrcTasks);
|
||||||
for (int32_t i = 0; i < taskNum; ++i) {
|
for (int32_t i = 0; i < taskNum; ++i) {
|
||||||
SSchTask *pTask = *(SSchTask **)taosArrayGet(pJob->dataSrcTasks, i);
|
SSchTask *pTask = *(SSchTask **)taosArrayGet(pJob->dataSrcTasks, i);
|
||||||
|
@ -55,7 +55,7 @@ int32_t schChkJobNeedFlowCtrl(SSchJob *pJob, SSchLevel *pLevel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schMgmt.cfg.maxNodeTableNum <= 0 || sum < schMgmt.cfg.maxNodeTableNum) {
|
if (schMgmt.cfg.maxNodeTableNum <= 0 || sum < schMgmt.cfg.maxNodeTableNum) {
|
||||||
SCH_JOB_DLOG("job no need flow ctrl, totalTableNum:%d", sum);
|
SCH_JOB_DLOG("job no need flow ctrl, totalTableNum:%" PRId64, sum);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ int32_t schChkJobNeedFlowCtrl(SSchJob *pJob, SSchLevel *pLevel) {
|
||||||
|
|
||||||
SCH_SET_JOB_NEED_FLOW_CTRL(pJob);
|
SCH_SET_JOB_NEED_FLOW_CTRL(pJob);
|
||||||
|
|
||||||
SCH_JOB_DLOG("job NEED flow ctrl, totalTableNum:%d", sum);
|
SCH_JOB_DLOG("job NEED flow ctrl, totalTableNum:%" PRId64, sum);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ int32_t schDecTaskFlowQuota(SSchJob *pJob, SSchTask *pTask) {
|
||||||
--ctrl->execTaskNum;
|
--ctrl->execTaskNum;
|
||||||
ctrl->tableNumSum -= pTask->plan->execNodeStat.tableNum;
|
ctrl->tableNumSum -= pTask->plan->execNodeStat.tableNum;
|
||||||
|
|
||||||
SCH_TASK_DLOG("task quota removed, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", ep->fqdn,
|
SCH_TASK_DLOG("task quota removed, fqdn:%s, port:%d, tableNum:%d, remainNum:%" PRId64 ", remainExecTaskNum:%d", ep->fqdn,
|
||||||
ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum);
|
ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum);
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
@ -125,7 +125,7 @@ int32_t schCheckIncTaskFlowQuota(SSchJob *pJob, SSchTask *pTask, bool *enough) {
|
||||||
SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCH_TASK_DLOG("task quota added, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", ep->fqdn,
|
SCH_TASK_DLOG("task quota added, fqdn:%s, port:%d, tableNum:%d, remainNum:%" PRId64 ", remainExecTaskNum:%d", ep->fqdn,
|
||||||
ep->port, pTask->plan->execNodeStat.tableNum, nctrl.tableNumSum, nctrl.execTaskNum);
|
ep->port, pTask->plan->execNodeStat.tableNum, nctrl.tableNumSum, nctrl.execTaskNum);
|
||||||
|
|
||||||
*enough = true;
|
*enough = true;
|
||||||
|
@ -142,7 +142,7 @@ int32_t schCheckIncTaskFlowQuota(SSchJob *pJob, SSchTask *pTask, bool *enough) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sum = pTask->plan->execNodeStat.tableNum + ctrl->tableNumSum;
|
int64_t sum = pTask->plan->execNodeStat.tableNum + ctrl->tableNumSum;
|
||||||
|
|
||||||
if (sum <= schMgmt.cfg.maxNodeTableNum) {
|
if (sum <= schMgmt.cfg.maxNodeTableNum) {
|
||||||
ctrl->tableNumSum = sum;
|
ctrl->tableNumSum = sum;
|
||||||
|
@ -173,7 +173,7 @@ int32_t schCheckIncTaskFlowQuota(SSchJob *pJob, SSchTask *pTask, bool *enough) {
|
||||||
|
|
||||||
_return:
|
_return:
|
||||||
|
|
||||||
SCH_TASK_DLOG("task quota %s added, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d",
|
SCH_TASK_DLOG("task quota %s added, fqdn:%s, port:%d, tableNum:%d, remainNum:%" PRId64 ", remainExecTaskNum:%d",
|
||||||
((*enough) ? "" : "NOT"), ep->fqdn, ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum,
|
((*enough) ? "" : "NOT"), ep->fqdn, ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum,
|
||||||
ctrl->execTaskNum);
|
ctrl->execTaskNum);
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ int32_t schLaunchTasksInFlowCtrlListImpl(SSchJob *pJob, SSchFlowControl *ctrl) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t remainNum = schMgmt.cfg.maxNodeTableNum - ctrl->tableNumSum;
|
int64_t remainNum = schMgmt.cfg.maxNodeTableNum - ctrl->tableNumSum;
|
||||||
int32_t taskNum = taosArrayGetSize(ctrl->taskList);
|
int32_t taskNum = taosArrayGetSize(ctrl->taskList);
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SSchTask *pTask = NULL;
|
SSchTask *pTask = NULL;
|
||||||
|
@ -217,7 +217,7 @@ int32_t schLaunchTasksInFlowCtrlListImpl(SSchJob *pJob, SSchFlowControl *ctrl) {
|
||||||
SEp *ep = SCH_GET_CUR_EP(&pTask->plan->execNode);
|
SEp *ep = SCH_GET_CUR_EP(&pTask->plan->execNode);
|
||||||
|
|
||||||
if (pTask->plan->execNodeStat.tableNum > remainNum && ctrl->execTaskNum > 0) {
|
if (pTask->plan->execNodeStat.tableNum > remainNum && ctrl->execTaskNum > 0) {
|
||||||
SCH_TASK_DLOG("task NOT to launch, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", ep->fqdn,
|
SCH_TASK_DLOG("task NOT to launch, fqdn:%s, port:%d, tableNum:%d, remainNum:%" PRId64 ", remainExecTaskNum:%d", ep->fqdn,
|
||||||
ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum);
|
ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -228,14 +228,14 @@ int32_t schLaunchTasksInFlowCtrlListImpl(SSchJob *pJob, SSchFlowControl *ctrl) {
|
||||||
|
|
||||||
taosArrayRemove(ctrl->taskList, i);
|
taosArrayRemove(ctrl->taskList, i);
|
||||||
|
|
||||||
SCH_TASK_DLOG("task to launch, fqdn:%s, port:%d, tableNum:%d, remainNum:%d, remainExecTaskNum:%d", ep->fqdn,
|
SCH_TASK_DLOG("task to launch, fqdn:%s, port:%d, tableNum:%d, remainNum:%" PRId64 ", remainExecTaskNum:%d", ep->fqdn,
|
||||||
ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum);
|
ep->port, pTask->plan->execNodeStat.tableNum, ctrl->tableNumSum, ctrl->execTaskNum);
|
||||||
|
|
||||||
SCH_ERR_JRET(schAsyncLaunchTaskImpl(pJob, pTask));
|
SCH_ERR_JRET(schAsyncLaunchTaskImpl(pJob, pTask));
|
||||||
|
|
||||||
remainNum -= pTask->plan->execNodeStat.tableNum;
|
remainNum -= pTask->plan->execNodeStat.tableNum;
|
||||||
if (remainNum <= 0) {
|
if (remainNum <= 0) {
|
||||||
SCH_TASK_DLOG("no more task to launch, fqdn:%s, port:%d, remainNum:%d, remainExecTaskNum:%d", ep->fqdn, ep->port,
|
SCH_TASK_DLOG("no more task to launch, fqdn:%s, port:%d, remainNum:%" PRId64 ", remainExecTaskNum:%d", ep->fqdn, ep->port,
|
||||||
ctrl->tableNumSum, ctrl->execTaskNum);
|
ctrl->tableNumSum, ctrl->execTaskNum);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -244,7 +244,7 @@ int32_t schLaunchTasksInFlowCtrlListImpl(SSchJob *pJob, SSchFlowControl *ctrl) {
|
||||||
if (i < (taskNum - 1)) {
|
if (i < (taskNum - 1)) {
|
||||||
SSchTask *pLastTask = *(SSchTask **)taosArrayGetLast(ctrl->taskList);
|
SSchTask *pLastTask = *(SSchTask **)taosArrayGetLast(ctrl->taskList);
|
||||||
if (remainNum < pLastTask->plan->execNodeStat.tableNum) {
|
if (remainNum < pLastTask->plan->execNodeStat.tableNum) {
|
||||||
SCH_TASK_DLOG("no more task to launch, fqdn:%s, port:%d, remainNum:%d, remainExecTaskNum:%d, smallestInList:%d",
|
SCH_TASK_DLOG("no more task to launch, fqdn:%s, port:%d, remainNum:%" PRId64 ", remainExecTaskNum:%d, smallestInList:%d",
|
||||||
ep->fqdn, ep->port, ctrl->tableNumSum, ctrl->execTaskNum, pLastTask->plan->execNodeStat.tableNum);
|
ep->fqdn, ep->port, ctrl->tableNumSum, ctrl->execTaskNum, pLastTask->plan->execNodeStat.tableNum);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "schInt.h"
|
#include "schInt.h"
|
||||||
#include "tmsg.h"
|
#include "tmsg.h"
|
||||||
#include "tref.h"
|
#include "tref.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
|
||||||
SSchedulerMgmt schMgmt = {
|
SSchedulerMgmt schMgmt = {
|
||||||
.jobRef = -1,
|
.jobRef = -1,
|
||||||
|
@ -30,11 +31,12 @@ int32_t schedulerInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
schMgmt.cfg.maxJobNum = SCHEDULE_DEFAULT_MAX_JOB_NUM;
|
schMgmt.cfg.maxJobNum = SCHEDULE_DEFAULT_MAX_JOB_NUM;
|
||||||
schMgmt.cfg.maxNodeTableNum = SCHEDULE_DEFAULT_MAX_NODE_TABLE_NUM;
|
schMgmt.cfg.maxNodeTableNum = tsQueryMaxConcurrentTables;
|
||||||
schMgmt.cfg.schPolicy = SCHEDULE_DEFAULT_POLICY;
|
schMgmt.cfg.schPolicy = SCHEDULE_DEFAULT_POLICY;
|
||||||
schMgmt.cfg.enableReSchedule = true;
|
schMgmt.cfg.enableReSchedule = true;
|
||||||
|
|
||||||
qDebug("schedule policy init to %d", schMgmt.cfg.schPolicy);
|
qDebug("schedule init, policy: %d, maxNodeTableNum: %" PRId64", reSchedule:%d",
|
||||||
|
schMgmt.cfg.schPolicy, schMgmt.cfg.maxNodeTableNum, schMgmt.cfg.enableReSchedule);
|
||||||
|
|
||||||
schMgmt.jobRef = taosOpenRef(schMgmt.cfg.maxJobNum, schFreeJobImpl);
|
schMgmt.jobRef = taosOpenRef(schMgmt.cfg.maxJobNum, schFreeJobImpl);
|
||||||
if (schMgmt.jobRef < 0) {
|
if (schMgmt.jobRef < 0) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ void streamSchedByTimer(void* param, void* tmrId) {
|
||||||
|
|
||||||
atomic_store_8(&pTask->triggerStatus, TASK_TRIGGER_STATUS__INACTIVE);
|
atomic_store_8(&pTask->triggerStatus, TASK_TRIGGER_STATUS__INACTIVE);
|
||||||
|
|
||||||
if (streamTaskInput(pTask, (SStreamQueueItem*)trigger) < 0) {
|
if (tAppendDataForStream(pTask, (SStreamQueueItem*)trigger) < 0) {
|
||||||
taosFreeQitem(trigger);
|
taosFreeQitem(trigger);
|
||||||
taosTmrReset(streamSchedByTimer, (int32_t)pTask->triggerParam, pTask, streamEnv.timer, &pTask->timer);
|
taosTmrReset(streamSchedByTimer, (int32_t)pTask->triggerParam, pTask, streamEnv.timer, &pTask->timer);
|
||||||
return;
|
return;
|
||||||
|
@ -92,22 +92,22 @@ int32_t streamSetupTrigger(SStreamTask* pTask) {
|
||||||
int32_t streamSchedExec(SStreamTask* pTask) {
|
int32_t streamSchedExec(SStreamTask* pTask) {
|
||||||
int8_t schedStatus =
|
int8_t schedStatus =
|
||||||
atomic_val_compare_exchange_8(&pTask->schedStatus, TASK_SCHED_STATUS__INACTIVE, TASK_SCHED_STATUS__WAITING);
|
atomic_val_compare_exchange_8(&pTask->schedStatus, TASK_SCHED_STATUS__INACTIVE, TASK_SCHED_STATUS__WAITING);
|
||||||
|
|
||||||
if (schedStatus == TASK_SCHED_STATUS__INACTIVE) {
|
if (schedStatus == TASK_SCHED_STATUS__INACTIVE) {
|
||||||
SStreamTaskRunReq* pRunReq = rpcMallocCont(sizeof(SStreamTaskRunReq));
|
SStreamTaskRunReq* pRunReq = rpcMallocCont(sizeof(SStreamTaskRunReq));
|
||||||
if (pRunReq == NULL) {
|
if (pRunReq == NULL) {
|
||||||
atomic_store_8(&pTask->schedStatus, TASK_SCHED_STATUS__INACTIVE);
|
atomic_store_8(&pTask->schedStatus, TASK_SCHED_STATUS__INACTIVE);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pRunReq->head.vgId = pTask->nodeId;
|
pRunReq->head.vgId = pTask->nodeId;
|
||||||
pRunReq->streamId = pTask->streamId;
|
pRunReq->streamId = pTask->streamId;
|
||||||
pRunReq->taskId = pTask->taskId;
|
pRunReq->taskId = pTask->taskId;
|
||||||
SRpcMsg msg = {
|
|
||||||
.msgType = TDMT_STREAM_TASK_RUN,
|
SRpcMsg msg = { .msgType = TDMT_STREAM_TASK_RUN, .pCont = pRunReq, .contLen = sizeof(SStreamTaskRunReq) };
|
||||||
.pCont = pRunReq,
|
|
||||||
.contLen = sizeof(SStreamTaskRunReq),
|
|
||||||
};
|
|
||||||
tmsgPutToQueue(pTask->pMsgCb, STREAM_QUEUE, &msg);
|
tmsgPutToQueue(pTask->pMsgCb, STREAM_QUEUE, &msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ int32_t streamTaskEnqueue(SStreamTask* pTask, const SStreamDispatchReq* pReq, SR
|
||||||
/*pData->blocks = pReq->data;*/
|
/*pData->blocks = pReq->data;*/
|
||||||
/*pBlock->sourceVer = pReq->sourceVer;*/
|
/*pBlock->sourceVer = pReq->sourceVer;*/
|
||||||
streamDispatchReqToData(pReq, pData);
|
streamDispatchReqToData(pReq, pData);
|
||||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pData) == 0) {
|
if (tAppendDataForStream(pTask, (SStreamQueueItem*)pData) == 0) {
|
||||||
status = TASK_INPUT_STATUS__NORMAL;
|
status = TASK_INPUT_STATUS__NORMAL;
|
||||||
} else {
|
} else {
|
||||||
status = TASK_INPUT_STATUS__FAILED;
|
status = TASK_INPUT_STATUS__FAILED;
|
||||||
|
@ -164,7 +164,7 @@ int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* pReq,
|
||||||
/*pData->blocks = pReq->data;*/
|
/*pData->blocks = pReq->data;*/
|
||||||
/*pBlock->sourceVer = pReq->sourceVer;*/
|
/*pBlock->sourceVer = pReq->sourceVer;*/
|
||||||
streamRetrieveReqToData(pReq, pData);
|
streamRetrieveReqToData(pReq, pData);
|
||||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pData) == 0) {
|
if (tAppendDataForStream(pTask, (SStreamQueueItem*)pData) == 0) {
|
||||||
status = TASK_INPUT_STATUS__NORMAL;
|
status = TASK_INPUT_STATUS__NORMAL;
|
||||||
} else {
|
} else {
|
||||||
status = TASK_INPUT_STATUS__FAILED;
|
status = TASK_INPUT_STATUS__FAILED;
|
||||||
|
@ -275,7 +275,57 @@ int32_t streamProcessRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* pReq, S
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// int32_t streamProcessRetrieveRsp(SStreamTask* pTask, SStreamRetrieveRsp* pRsp) {
|
int32_t tAppendDataForStream(SStreamTask* pTask, SStreamQueueItem* pItem) {
|
||||||
// //
|
int8_t type = pItem->type;
|
||||||
// return 0;
|
|
||||||
// }
|
if (type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
|
SStreamDataSubmit2* pSubmitBlock = streamSubmitBlockClone((SStreamDataSubmit2*)pItem);
|
||||||
|
if (pSubmitBlock == 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t total = taosQueueItemSize(pTask->inputQueue->queue) + 1;
|
||||||
|
qDebug("stream task:%d %p submit enqueue %p %p %p msgLen:%d ver:%" PRId64 ", total in queue:%d", pTask->taskId,
|
||||||
|
pTask, pItem, pSubmitBlock, pSubmitBlock->submit.msgStr, pSubmitBlock->submit.msgLen,
|
||||||
|
pSubmitBlock->submit.ver, total);
|
||||||
|
|
||||||
|
taosWriteQitem(pTask->inputQueue->queue, pSubmitBlock);
|
||||||
|
} else if (type == STREAM_INPUT__DATA_BLOCK || type == STREAM_INPUT__DATA_RETRIEVE ||
|
||||||
|
type == STREAM_INPUT__REF_DATA_BLOCK) {
|
||||||
|
taosWriteQitem(pTask->inputQueue->queue, pItem);
|
||||||
|
} else if (type == STREAM_INPUT__CHECKPOINT) {
|
||||||
|
taosWriteQitem(pTask->inputQueue->queue, pItem);
|
||||||
|
} else if (type == STREAM_INPUT__GET_RES) {
|
||||||
|
taosWriteQitem(pTask->inputQueue->queue, pItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,10 +48,12 @@ int32_t streamRetrieveReqToData(const SStreamRetrieveReq* pReq, SStreamDataBlock
|
||||||
if (pArray == NULL) {
|
if (pArray == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayPush(pArray, &(SSDataBlock){0});
|
taosArrayPush(pArray, &(SSDataBlock){0});
|
||||||
SRetrieveTableRsp* pRetrieve = pReq->pRetrieve;
|
SRetrieveTableRsp* pRetrieve = pReq->pRetrieve;
|
||||||
SSDataBlock* pDataBlock = taosArrayGet(pArray, 0);
|
SSDataBlock* pDataBlock = taosArrayGet(pArray, 0);
|
||||||
blockDecode(pDataBlock, pRetrieve->data);
|
blockDecode(pDataBlock, pRetrieve->data);
|
||||||
|
|
||||||
// TODO: refactor
|
// TODO: refactor
|
||||||
pDataBlock->info.window.skey = be64toh(pRetrieve->skey);
|
pDataBlock->info.window.skey = be64toh(pRetrieve->skey);
|
||||||
pDataBlock->info.window.ekey = be64toh(pRetrieve->ekey);
|
pDataBlock->info.window.ekey = be64toh(pRetrieve->ekey);
|
||||||
|
@ -68,34 +70,53 @@ int32_t streamRetrieveReqToData(const SStreamRetrieveReq* pReq, SStreamDataBlock
|
||||||
SStreamDataSubmit2* streamDataSubmitNew(SPackedData submit) {
|
SStreamDataSubmit2* streamDataSubmitNew(SPackedData submit) {
|
||||||
SStreamDataSubmit2* pDataSubmit = (SStreamDataSubmit2*)taosAllocateQitem(sizeof(SStreamDataSubmit2), DEF_QITEM, 0);
|
SStreamDataSubmit2* pDataSubmit = (SStreamDataSubmit2*)taosAllocateQitem(sizeof(SStreamDataSubmit2), DEF_QITEM, 0);
|
||||||
|
|
||||||
if (pDataSubmit == NULL) return NULL;
|
if (pDataSubmit == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pDataSubmit->dataRef = (int32_t*)taosMemoryMalloc(sizeof(int32_t));
|
pDataSubmit->dataRef = (int32_t*)taosMemoryMalloc(sizeof(int32_t));
|
||||||
if (pDataSubmit->dataRef == NULL) goto FAIL;
|
if (pDataSubmit->dataRef == NULL) {
|
||||||
pDataSubmit->submit = submit;
|
|
||||||
*pDataSubmit->dataRef = 1;
|
|
||||||
pDataSubmit->type = STREAM_INPUT__DATA_SUBMIT;
|
|
||||||
return pDataSubmit;
|
|
||||||
FAIL:
|
|
||||||
taosFreeQitem(pDataSubmit);
|
taosFreeQitem(pDataSubmit);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pDataSubmit->submit = submit;
|
||||||
|
*pDataSubmit->dataRef = 1; // initialize the reference count to be 1
|
||||||
|
pDataSubmit->type = STREAM_INPUT__DATA_SUBMIT;
|
||||||
|
|
||||||
|
return pDataSubmit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void streamDataSubmitDestroy(SStreamDataSubmit2* pDataSubmit) {
|
||||||
|
int32_t ref = atomic_sub_fetch_32(pDataSubmit->dataRef, 1);
|
||||||
|
ASSERT(ref >= 0 && pDataSubmit->type == STREAM_INPUT__DATA_SUBMIT);
|
||||||
|
|
||||||
|
if (ref == 0) {
|
||||||
|
taosMemoryFree(pDataSubmit->submit.msgStr);
|
||||||
|
taosMemoryFree(pDataSubmit->dataRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SStreamMergedSubmit2* streamMergedSubmitNew() {
|
SStreamMergedSubmit2* streamMergedSubmitNew() {
|
||||||
SStreamMergedSubmit2* pMerged = (SStreamMergedSubmit2*)taosAllocateQitem(sizeof(SStreamMergedSubmit2), DEF_QITEM, 0);
|
SStreamMergedSubmit2* pMerged = (SStreamMergedSubmit2*)taosAllocateQitem(sizeof(SStreamMergedSubmit2), DEF_QITEM, 0);
|
||||||
|
if (pMerged == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (pMerged == NULL) return NULL;
|
|
||||||
pMerged->submits = taosArrayInit(0, sizeof(SPackedData));
|
pMerged->submits = taosArrayInit(0, sizeof(SPackedData));
|
||||||
pMerged->dataRefs = taosArrayInit(0, sizeof(void*));
|
pMerged->dataRefs = taosArrayInit(0, sizeof(void*));
|
||||||
if (pMerged->dataRefs == NULL || pMerged->submits == NULL) goto FAIL;
|
|
||||||
pMerged->type = STREAM_INPUT__MERGED_SUBMIT;
|
if (pMerged->dataRefs == NULL || pMerged->submits == NULL) {
|
||||||
return pMerged;
|
taosArrayDestroy(pMerged->submits);
|
||||||
FAIL:
|
taosArrayDestroy(pMerged->dataRefs);
|
||||||
if (pMerged->submits) taosArrayDestroy(pMerged->submits);
|
|
||||||
if (pMerged->dataRefs) taosArrayDestroy(pMerged->dataRefs);
|
|
||||||
taosFreeQitem(pMerged);
|
taosFreeQitem(pMerged);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pMerged->type = STREAM_INPUT__MERGED_SUBMIT;
|
||||||
|
return pMerged;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t streamMergeSubmit(SStreamMergedSubmit2* pMerged, SStreamDataSubmit2* pSubmit) {
|
int32_t streamMergeSubmit(SStreamMergedSubmit2* pMerged, SStreamDataSubmit2* pSubmit) {
|
||||||
taosArrayPush(pMerged->dataRefs, &pSubmit->dataRef);
|
taosArrayPush(pMerged->dataRefs, &pSubmit->dataRef);
|
||||||
taosArrayPush(pMerged->submits, &pSubmit->submit);
|
taosArrayPush(pMerged->submits, &pSubmit->submit);
|
||||||
|
@ -107,26 +128,17 @@ static FORCE_INLINE void streamDataSubmitRefInc(SStreamDataSubmit2* pDataSubmit)
|
||||||
atomic_add_fetch_32(pDataSubmit->dataRef, 1);
|
atomic_add_fetch_32(pDataSubmit->dataRef, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SStreamDataSubmit2* streamSubmitRefClone(SStreamDataSubmit2* pSubmit) {
|
SStreamDataSubmit2* streamSubmitBlockClone(SStreamDataSubmit2* pSubmit) {
|
||||||
SStreamDataSubmit2* pSubmitClone = taosAllocateQitem(sizeof(SStreamDataSubmit2), DEF_QITEM, 0);
|
SStreamDataSubmit2* pSubmitClone = taosAllocateQitem(sizeof(SStreamDataSubmit2), DEF_QITEM, 0);
|
||||||
|
|
||||||
if (pSubmitClone == NULL) {
|
if (pSubmitClone == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
streamDataSubmitRefInc(pSubmit);
|
streamDataSubmitRefInc(pSubmit);
|
||||||
memcpy(pSubmitClone, pSubmit, sizeof(SStreamDataSubmit2));
|
memcpy(pSubmitClone, pSubmit, sizeof(SStreamDataSubmit2));
|
||||||
return pSubmitClone;
|
return pSubmitClone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void streamDataSubmitRefDec(SStreamDataSubmit2* pDataSubmit) {
|
|
||||||
int32_t ref = atomic_sub_fetch_32(pDataSubmit->dataRef, 1);
|
|
||||||
ASSERT(ref >= 0);
|
|
||||||
if (ref == 0) {
|
|
||||||
taosMemoryFree(pDataSubmit->submit.msgStr);
|
|
||||||
taosMemoryFree(pDataSubmit->dataRef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SStreamQueueItem* streamMergeQueueItem(SStreamQueueItem* dst, SStreamQueueItem* elem) {
|
SStreamQueueItem* streamMergeQueueItem(SStreamQueueItem* dst, SStreamQueueItem* elem) {
|
||||||
ASSERT(elem);
|
ASSERT(elem);
|
||||||
if (dst->type == STREAM_INPUT__DATA_BLOCK && elem->type == STREAM_INPUT__DATA_BLOCK) {
|
if (dst->type == STREAM_INPUT__DATA_BLOCK && elem->type == STREAM_INPUT__DATA_BLOCK) {
|
||||||
|
@ -164,7 +176,7 @@ void streamFreeQitem(SStreamQueueItem* data) {
|
||||||
taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)blockDataFreeRes);
|
taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)blockDataFreeRes);
|
||||||
taosFreeQitem(data);
|
taosFreeQitem(data);
|
||||||
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
} else if (type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
streamDataSubmitRefDec((SStreamDataSubmit2*)data);
|
streamDataSubmitDestroy((SStreamDataSubmit2*)data);
|
||||||
taosFreeQitem(data);
|
taosFreeQitem(data);
|
||||||
} else if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
} else if (type == STREAM_INPUT__MERGED_SUBMIT) {
|
||||||
SStreamMergedSubmit2* pMerge = (SStreamMergedSubmit2*)data;
|
SStreamMergedSubmit2* pMerge = (SStreamMergedSubmit2*)data;
|
||||||
|
|
|
@ -34,7 +34,7 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, const void* data, SArray*
|
||||||
} else if (pItem->type == STREAM_INPUT__DATA_SUBMIT) {
|
} else if (pItem->type == STREAM_INPUT__DATA_SUBMIT) {
|
||||||
ASSERT(pTask->taskLevel == TASK_LEVEL__SOURCE);
|
ASSERT(pTask->taskLevel == TASK_LEVEL__SOURCE);
|
||||||
const SStreamDataSubmit2* pSubmit = (const SStreamDataSubmit2*)data;
|
const SStreamDataSubmit2* pSubmit = (const SStreamDataSubmit2*)data;
|
||||||
qDebug("task %d %p set submit input %p %p %d %" PRId64, pTask->taskId, pTask, pSubmit, pSubmit->submit.msgStr,
|
qDebug("stream task:%d %p set submit input %p %p %d %" PRId64, pTask->taskId, pTask, pSubmit, pSubmit->submit.msgStr,
|
||||||
pSubmit->submit.msgLen, pSubmit->submit.ver);
|
pSubmit->submit.msgLen, pSubmit->submit.ver);
|
||||||
qSetMultiStreamInput(exec, &pSubmit->submit, 1, STREAM_INPUT__DATA_SUBMIT);
|
qSetMultiStreamInput(exec, &pSubmit->submit, 1, STREAM_INPUT__DATA_SUBMIT);
|
||||||
} else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE) {
|
} else if (pItem->type == STREAM_INPUT__DATA_BLOCK || pItem->type == STREAM_INPUT__DATA_RETRIEVE) {
|
||||||
|
@ -268,9 +268,10 @@ int32_t streamExecForAll(SStreamTask* pTask) {
|
||||||
|
|
||||||
SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock));
|
SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock));
|
||||||
|
|
||||||
qDebug("stream task %d exec begin, msg batch: %d", pTask->taskId, batchCnt);
|
qDebug("stream task:%d exec begin, msg batch: %d", pTask->taskId, batchCnt);
|
||||||
streamTaskExecImpl(pTask, input, pRes);
|
streamTaskExecImpl(pTask, input, pRes);
|
||||||
qDebug("stream task %d exec end", pTask->taskId);
|
|
||||||
|
qDebug("stream task:%d exec end", pTask->taskId);
|
||||||
|
|
||||||
if (taosArrayGetSize(pRes) != 0) {
|
if (taosArrayGetSize(pRes) != 0) {
|
||||||
SStreamDataBlock* qRes = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, 0);
|
SStreamDataBlock* qRes = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, 0);
|
||||||
|
|
|
@ -59,36 +59,36 @@ typedef struct SSyncLogBuffer {
|
||||||
} SSyncLogBuffer;
|
} SSyncLogBuffer;
|
||||||
|
|
||||||
// SSyncLogRepMgr
|
// SSyncLogRepMgr
|
||||||
SSyncLogReplMgr* syncLogReplMgrCreate();
|
SSyncLogReplMgr* syncLogReplCreate();
|
||||||
void syncLogReplMgrDestroy(SSyncLogReplMgr* pMgr);
|
void syncLogReplDestroy(SSyncLogReplMgr* pMgr);
|
||||||
void syncLogReplMgrReset(SSyncLogReplMgr* pMgr);
|
void syncLogReplReset(SSyncLogReplMgr* pMgr);
|
||||||
|
|
||||||
int32_t syncNodeLogReplMgrInit(SSyncNode* pNode);
|
int32_t syncNodeLogReplInit(SSyncNode* pNode);
|
||||||
void syncNodeLogReplMgrDestroy(SSyncNode* pNode);
|
void syncNodeLogReplDestroy(SSyncNode* pNode);
|
||||||
|
|
||||||
// access
|
// access
|
||||||
static FORCE_INLINE int64_t syncLogGetRetryBackoffTimeMs(SSyncLogReplMgr* pMgr) {
|
static FORCE_INLINE int64_t syncLogReplGetRetryBackoffTimeMs(SSyncLogReplMgr* pMgr) {
|
||||||
return ((int64_t)1 << pMgr->retryBackoff) * SYNC_LOG_REPL_RETRY_WAIT_MS;
|
return ((int64_t)1 << pMgr->retryBackoff) * SYNC_LOG_REPL_RETRY_WAIT_MS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t syncLogGetNextRetryBackoff(SSyncLogReplMgr* pMgr) {
|
static FORCE_INLINE int32_t syncLogReplGetNextRetryBackoff(SSyncLogReplMgr* pMgr) {
|
||||||
return TMIN(pMgr->retryBackoff + 1, SYNC_MAX_RETRY_BACKOFF);
|
return TMIN(pMgr->retryBackoff + 1, SYNC_MAX_RETRY_BACKOFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncTerm syncLogReplMgrGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index);
|
SyncTerm syncLogReplGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index);
|
||||||
|
|
||||||
int32_t syncLogReplMgrReplicateOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode);
|
int32_t syncLogReplReplicateOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode);
|
||||||
int32_t syncLogReplMgrReplicateOneTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index, SyncTerm* pTerm,
|
int32_t syncLogReplReplicateOneTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index, SyncTerm* pTerm,
|
||||||
SRaftId* pDestId, bool* pBarrier);
|
SRaftId* pDestId, bool* pBarrier);
|
||||||
int32_t syncLogReplMgrReplicateAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode);
|
int32_t syncLogReplReplicateAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode);
|
||||||
int32_t syncLogReplMgrReplicateProbe(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index);
|
int32_t syncLogReplReplicateProbe(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index);
|
||||||
|
|
||||||
int32_t syncLogReplMgrProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg);
|
int32_t syncLogReplProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg);
|
||||||
int32_t syncLogReplMgrProcessReplyAsRecovery(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg);
|
int32_t syncLogReplProcessReplyAsRecovery(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg);
|
||||||
int32_t syncLogReplMgrProcessReplyAsNormal(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg);
|
int32_t syncLogReplProcessReplyAsNormal(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg);
|
||||||
|
|
||||||
int32_t syncLogReplMgrProcessHeartbeatReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncHeartbeatReply* pMsg);
|
int32_t syncLogReplProcessHeartbeatReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncHeartbeatReply* pMsg);
|
||||||
int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode);
|
int32_t syncLogReplRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode);
|
||||||
|
|
||||||
// SSyncLogBuffer
|
// SSyncLogBuffer
|
||||||
SSyncLogBuffer* syncLogBufferCreate();
|
SSyncLogBuffer* syncLogBufferCreate();
|
||||||
|
@ -111,7 +111,7 @@ SSyncRaftEntry* syncLogBufferGetOneEntry(SSyncLogBuffer* pBuf, SSyncNode* pNode,
|
||||||
int32_t syncLogBufferValidate(SSyncLogBuffer* pBuf);
|
int32_t syncLogBufferValidate(SSyncLogBuffer* pBuf);
|
||||||
int32_t syncLogBufferRollback(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncIndex toIndex);
|
int32_t syncLogBufferRollback(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncIndex toIndex);
|
||||||
|
|
||||||
int32_t syncLogFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, SyncTerm term, SSyncRaftEntry* pEntry,
|
int32_t syncFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, SyncTerm term, SSyncRaftEntry* pEntry,
|
||||||
int32_t applyCode);
|
int32_t applyCode);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
sError("vgId:%d, failed to get log repl mgr for src addr: 0x%016" PRIx64, ths->vgId, pMsg->srcId.addr);
|
sError("vgId:%d, failed to get log repl mgr for src addr: 0x%016" PRIx64, ths->vgId, pMsg->srcId.addr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
(void)syncLogReplMgrProcessReply(pMgr, ths, pMsg);
|
(void)syncLogReplProcessReply(pMgr, ths, pMsg);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -967,7 +967,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
|
||||||
pSyncNode->changing = false;
|
pSyncNode->changing = false;
|
||||||
|
|
||||||
// replication mgr
|
// replication mgr
|
||||||
if (syncNodeLogReplMgrInit(pSyncNode) < 0) {
|
if (syncNodeLogReplInit(pSyncNode) < 0) {
|
||||||
sError("vgId:%d, failed to init repl mgr since %s.", pSyncNode->vgId, terrstr());
|
sError("vgId:%d, failed to init repl mgr since %s.", pSyncNode->vgId, terrstr());
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
@ -1140,7 +1140,7 @@ void syncNodeClose(SSyncNode* pSyncNode) {
|
||||||
syncNodeStopPingTimer(pSyncNode);
|
syncNodeStopPingTimer(pSyncNode);
|
||||||
syncNodeStopElectTimer(pSyncNode);
|
syncNodeStopElectTimer(pSyncNode);
|
||||||
syncNodeStopHeartbeatTimer(pSyncNode);
|
syncNodeStopHeartbeatTimer(pSyncNode);
|
||||||
syncNodeLogReplMgrDestroy(pSyncNode);
|
syncNodeLogReplDestroy(pSyncNode);
|
||||||
|
|
||||||
syncRespMgrDestroy(pSyncNode->pSyncRespMgr);
|
syncRespMgrDestroy(pSyncNode->pSyncRespMgr);
|
||||||
pSyncNode->pSyncRespMgr = NULL;
|
pSyncNode->pSyncRespMgr = NULL;
|
||||||
|
@ -2182,7 +2182,7 @@ int32_t syncNodeAppend(SSyncNode* ths, SSyncRaftEntry* pEntry) {
|
||||||
if (syncLogBufferAppend(ths->pLogBuf, ths, pEntry) < 0) {
|
if (syncLogBufferAppend(ths->pLogBuf, ths, pEntry) < 0) {
|
||||||
sError("vgId:%d, failed to enqueue sync log buffer, index:%" PRId64, ths->vgId, pEntry->index);
|
sError("vgId:%d, failed to enqueue sync log buffer, index:%" PRId64, ths->vgId, pEntry->index);
|
||||||
ASSERT(terrno != 0);
|
ASSERT(terrno != 0);
|
||||||
(void)syncLogFsmExecute(ths, ths->pFsm, ths->state, raftStoreGetTerm(ths), pEntry, terrno);
|
(void)syncFsmExecute(ths, ths->pFsm, ths->state, raftStoreGetTerm(ths), pEntry, terrno);
|
||||||
syncEntryDestroy(pEntry);
|
syncEntryDestroy(pEntry);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -2400,7 +2400,7 @@ int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
|
|
||||||
syncIndexMgrSetRecvTime(ths->pMatchIndex, &pMsg->srcId, tsMs);
|
syncIndexMgrSetRecvTime(ths->pMatchIndex, &pMsg->srcId, tsMs);
|
||||||
|
|
||||||
return syncLogReplMgrProcessHeartbeatReply(pMgr, ths, pMsg);
|
return syncLogReplProcessHeartbeatReply(pMgr, ths, pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeOnHeartbeatReplyOld(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
int32_t syncNodeOnHeartbeatReplyOld(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
||||||
|
|
|
@ -86,7 +86,7 @@ _err:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncTerm syncLogReplMgrGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index) {
|
SyncTerm syncLogReplGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index) {
|
||||||
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
SSyncRaftEntry* pEntry = NULL;
|
SSyncRaftEntry* pEntry = NULL;
|
||||||
SyncIndex prevIndex = index - 1;
|
SyncIndex prevIndex = index - 1;
|
||||||
|
@ -316,7 +316,7 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
|
||||||
" %" PRId64 ", %" PRId64 ")",
|
" %" PRId64 ", %" PRId64 ")",
|
||||||
pNode->vgId, pEntry->index, pEntry->term, pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex,
|
pNode->vgId, pEntry->index, pEntry->term, pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex,
|
||||||
pBuf->endIndex);
|
pBuf->endIndex);
|
||||||
SyncTerm term = syncLogReplMgrGetPrevLogTerm(NULL, pNode, index + 1);
|
SyncTerm term = syncLogReplGetPrevLogTerm(NULL, pNode, index + 1);
|
||||||
ASSERT(pEntry->term >= 0);
|
ASSERT(pEntry->term >= 0);
|
||||||
if (term == pEntry->term) {
|
if (term == pEntry->term) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
@ -351,7 +351,7 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt
|
||||||
" %" PRId64 " %" PRId64 ", %" PRId64 ")",
|
" %" PRId64 " %" PRId64 ", %" PRId64 ")",
|
||||||
pNode->vgId, pEntry->index, pEntry->term, pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex,
|
pNode->vgId, pEntry->index, pEntry->term, pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex,
|
||||||
pBuf->endIndex);
|
pBuf->endIndex);
|
||||||
SyncTerm existPrevTerm = syncLogReplMgrGetPrevLogTerm(NULL, pNode, index);
|
SyncTerm existPrevTerm = syncLogReplGetPrevLogTerm(NULL, pNode, index);
|
||||||
ASSERT(pEntry->term == pExist->term && (pEntry->index > pBuf->matchIndex || prevTerm == existPrevTerm));
|
ASSERT(pEntry->term == pExist->term && (pEntry->index > pBuf->matchIndex || prevTerm == existPrevTerm));
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto _out;
|
goto _out;
|
||||||
|
@ -482,7 +482,7 @@ _out:
|
||||||
return matchIndex;
|
return matchIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, SyncTerm term, SSyncRaftEntry* pEntry,
|
int32_t syncFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, SyncTerm term, SSyncRaftEntry* pEntry,
|
||||||
int32_t applyCode) {
|
int32_t applyCode) {
|
||||||
if (pNode->replicaNum == 1 && pNode->restoreFinish && pNode->vgId != 1) {
|
if (pNode->replicaNum == 1 && pNode->restoreFinish && pNode->vgId != 1) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -564,7 +564,7 @@ int32_t syncLogBufferCommit(SSyncLogBuffer* pBuf, SSyncNode* pNode, int64_t comm
|
||||||
pEntry->term, TMSG_INFO(pEntry->originalRpcType));
|
pEntry->term, TMSG_INFO(pEntry->originalRpcType));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (syncLogFsmExecute(pNode, pFsm, role, currentTerm, pEntry, 0) != 0) {
|
if (syncFsmExecute(pNode, pFsm, role, currentTerm, pEntry, 0) != 0) {
|
||||||
sError("vgId:%d, failed to execute sync log entry. index:%" PRId64 ", term:%" PRId64
|
sError("vgId:%d, failed to execute sync log entry. index:%" PRId64 ", term:%" PRId64
|
||||||
", role:%d, current term:%" PRId64,
|
", role:%d, current term:%" PRId64,
|
||||||
vgId, pEntry->index, pEntry->term, role, currentTerm);
|
vgId, pEntry->index, pEntry->term, role, currentTerm);
|
||||||
|
@ -611,7 +611,7 @@ _out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogReplMgrReset(SSyncLogReplMgr* pMgr) {
|
void syncLogReplReset(SSyncLogReplMgr* pMgr) {
|
||||||
if (pMgr == NULL) return;
|
if (pMgr == NULL) return;
|
||||||
|
|
||||||
ASSERT(pMgr->startIndex >= 0);
|
ASSERT(pMgr->startIndex >= 0);
|
||||||
|
@ -625,14 +625,14 @@ void syncLogReplMgrReset(SSyncLogReplMgr* pMgr) {
|
||||||
pMgr->retryBackoff = 0;
|
pMgr->retryBackoff = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
int32_t syncLogReplRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
||||||
if (pMgr->endIndex <= pMgr->startIndex) {
|
if (pMgr->endIndex <= pMgr->startIndex) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
||||||
if (pMgr->retryBackoff == SYNC_MAX_RETRY_BACKOFF) {
|
if (pMgr->retryBackoff == SYNC_MAX_RETRY_BACKOFF) {
|
||||||
syncLogReplMgrReset(pMgr);
|
syncLogReplReset(pMgr);
|
||||||
sWarn("vgId:%d, reset sync log repl mgr since retry backoff exceeding limit. peer:%" PRIx64, pNode->vgId,
|
sWarn("vgId:%d, reset sync log repl mgr since retry backoff exceeding limit. peer:%" PRIx64, pNode->vgId,
|
||||||
pDestId->addr);
|
pDestId->addr);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -640,7 +640,7 @@ int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
||||||
|
|
||||||
int32_t ret = -1;
|
int32_t ret = -1;
|
||||||
bool retried = false;
|
bool retried = false;
|
||||||
int64_t retryWaitMs = syncLogGetRetryBackoffTimeMs(pMgr);
|
int64_t retryWaitMs = syncLogReplGetRetryBackoffTimeMs(pMgr);
|
||||||
int64_t nowMs = taosGetMonoTimestampMs();
|
int64_t nowMs = taosGetMonoTimestampMs();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int64_t firstIndex = -1;
|
int64_t firstIndex = -1;
|
||||||
|
@ -657,7 +657,7 @@ int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
||||||
|
|
||||||
if (pMgr->states[pos].acked) {
|
if (pMgr->states[pos].acked) {
|
||||||
if (pMgr->matchIndex < index && pMgr->states[pos].timeMs + (syncGetRetryMaxWaitMs() << 3) < nowMs) {
|
if (pMgr->matchIndex < index && pMgr->states[pos].timeMs + (syncGetRetryMaxWaitMs() << 3) < nowMs) {
|
||||||
syncLogReplMgrReset(pMgr);
|
syncLogReplReset(pMgr);
|
||||||
sWarn("vgId:%d, reset sync log repl mgr since stagnation. index:%" PRId64 ", peer:%" PRIx64, pNode->vgId,
|
sWarn("vgId:%d, reset sync log repl mgr since stagnation. index:%" PRId64 ", peer:%" PRIx64, pNode->vgId,
|
||||||
index, pDestId->addr);
|
index, pDestId->addr);
|
||||||
goto _out;
|
goto _out;
|
||||||
|
@ -666,7 +666,7 @@ int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool barrier = false;
|
bool barrier = false;
|
||||||
if (syncLogReplMgrReplicateOneTo(pMgr, pNode, index, &term, pDestId, &barrier) < 0) {
|
if (syncLogReplReplicateOneTo(pMgr, pNode, index, &term, pDestId, &barrier) < 0) {
|
||||||
sError("vgId:%d, failed to replicate sync log entry since %s. index:%" PRId64 ", dest:%" PRIx64 "", pNode->vgId,
|
sError("vgId:%d, failed to replicate sync log entry since %s. index:%" PRId64 ", dest:%" PRIx64 "", pNode->vgId,
|
||||||
terrstr(), index, pDestId->addr);
|
terrstr(), index, pDestId->addr);
|
||||||
goto _out;
|
goto _out;
|
||||||
|
@ -687,7 +687,7 @@ int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
_out:
|
_out:
|
||||||
if (retried) {
|
if (retried) {
|
||||||
pMgr->retryBackoff = syncLogGetNextRetryBackoff(pMgr);
|
pMgr->retryBackoff = syncLogReplGetNextRetryBackoff(pMgr);
|
||||||
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
sInfo("vgId:%d, resend %d sync log entries. dest:%" PRIx64 ", indexes:%" PRId64 " ..., terms: ... %" PRId64
|
sInfo("vgId:%d, resend %d sync log entries. dest:%" PRIx64 ", indexes:%" PRId64 " ..., terms: ... %" PRId64
|
||||||
", retryWaitMs:%" PRId64 ", mgr: [%" PRId64 " %" PRId64 ", %" PRId64 "), buffer: [%" PRId64 " %" PRId64
|
", retryWaitMs:%" PRId64 ", mgr: [%" PRId64 " %" PRId64 ", %" PRId64 "), buffer: [%" PRId64 " %" PRId64
|
||||||
|
@ -698,7 +698,7 @@ _out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrProcessReplyAsRecovery(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg) {
|
int32_t syncLogReplProcessReplyAsRecovery(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg) {
|
||||||
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
SRaftId destId = pMsg->srcId;
|
SRaftId destId = pMsg->srcId;
|
||||||
ASSERT(pMgr->restored == false);
|
ASSERT(pMgr->restored == false);
|
||||||
|
@ -716,7 +716,7 @@ int32_t syncLogReplMgrProcessReplyAsRecovery(SSyncLogReplMgr* pMgr, SSyncNode* p
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (pMsg->lastSendIndex < pMgr->startIndex || pMsg->lastSendIndex >= pMgr->endIndex) {
|
if (pMsg->lastSendIndex < pMgr->startIndex || pMsg->lastSendIndex >= pMgr->endIndex) {
|
||||||
syncLogReplMgrRetryOnNeed(pMgr, pNode);
|
syncLogReplRetryOnNeed(pMgr, pNode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,7 +750,7 @@ int32_t syncLogReplMgrProcessReplyAsRecovery(SSyncLogReplMgr* pMgr, SSyncNode* p
|
||||||
SyncIndex index = TMIN(pMsg->matchIndex, pNode->pLogBuf->matchIndex);
|
SyncIndex index = TMIN(pMsg->matchIndex, pNode->pLogBuf->matchIndex);
|
||||||
|
|
||||||
if (pMsg->matchIndex < pNode->pLogBuf->matchIndex) {
|
if (pMsg->matchIndex < pNode->pLogBuf->matchIndex) {
|
||||||
term = syncLogReplMgrGetPrevLogTerm(pMgr, pNode, index + 1);
|
term = syncLogReplGetPrevLogTerm(pMgr, pNode, index + 1);
|
||||||
if ((index + 1 < firstVer) || (term < 0) ||
|
if ((index + 1 < firstVer) || (term < 0) ||
|
||||||
(term != pMsg->lastMatchTerm && (index + 1 == firstVer || index == firstVer))) {
|
(term != pMsg->lastMatchTerm && (index + 1 == firstVer || index == firstVer))) {
|
||||||
ASSERT(term >= 0 || terrno == TSDB_CODE_WAL_LOG_NOT_EXIST);
|
ASSERT(term >= 0 || terrno == TSDB_CODE_WAL_LOG_NOT_EXIST);
|
||||||
|
@ -773,53 +773,53 @@ int32_t syncLogReplMgrProcessReplyAsRecovery(SSyncLogReplMgr* pMgr, SSyncNode* p
|
||||||
}
|
}
|
||||||
|
|
||||||
// attempt to replicate the raft log at index
|
// attempt to replicate the raft log at index
|
||||||
(void)syncLogReplMgrReset(pMgr);
|
(void)syncLogReplReset(pMgr);
|
||||||
return syncLogReplMgrReplicateProbe(pMgr, pNode, index);
|
return syncLogReplReplicateProbe(pMgr, pNode, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrProcessHeartbeatReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncHeartbeatReply* pMsg) {
|
int32_t syncLogReplProcessHeartbeatReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncHeartbeatReply* pMsg) {
|
||||||
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
taosThreadMutexLock(&pBuf->mutex);
|
taosThreadMutexLock(&pBuf->mutex);
|
||||||
if (pMsg->startTime != 0 && pMsg->startTime != pMgr->peerStartTime) {
|
if (pMsg->startTime != 0 && pMsg->startTime != pMgr->peerStartTime) {
|
||||||
sInfo("vgId:%d, reset sync log repl mgr in heartbeat. peer:%" PRIx64 ", start time:%" PRId64 ", old:%" PRId64 "",
|
sInfo("vgId:%d, reset sync log repl mgr in heartbeat. peer:%" PRIx64 ", start time:%" PRId64 ", old:%" PRId64 "",
|
||||||
pNode->vgId, pMsg->srcId.addr, pMsg->startTime, pMgr->peerStartTime);
|
pNode->vgId, pMsg->srcId.addr, pMsg->startTime, pMgr->peerStartTime);
|
||||||
syncLogReplMgrReset(pMgr);
|
syncLogReplReset(pMgr);
|
||||||
pMgr->peerStartTime = pMsg->startTime;
|
pMgr->peerStartTime = pMsg->startTime;
|
||||||
}
|
}
|
||||||
taosThreadMutexUnlock(&pBuf->mutex);
|
taosThreadMutexUnlock(&pBuf->mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg) {
|
int32_t syncLogReplProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg) {
|
||||||
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
taosThreadMutexLock(&pBuf->mutex);
|
taosThreadMutexLock(&pBuf->mutex);
|
||||||
if (pMsg->startTime != pMgr->peerStartTime) {
|
if (pMsg->startTime != pMgr->peerStartTime) {
|
||||||
sInfo("vgId:%d, reset sync log repl mgr in appendlog reply. peer:%" PRIx64 ", start time:%" PRId64
|
sInfo("vgId:%d, reset sync log repl mgr in appendlog reply. peer:%" PRIx64 ", start time:%" PRId64
|
||||||
", old:%" PRId64,
|
", old:%" PRId64,
|
||||||
pNode->vgId, pMsg->srcId.addr, pMsg->startTime, pMgr->peerStartTime);
|
pNode->vgId, pMsg->srcId.addr, pMsg->startTime, pMgr->peerStartTime);
|
||||||
syncLogReplMgrReset(pMgr);
|
syncLogReplReset(pMgr);
|
||||||
pMgr->peerStartTime = pMsg->startTime;
|
pMgr->peerStartTime = pMsg->startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMgr->restored) {
|
if (pMgr->restored) {
|
||||||
(void)syncLogReplMgrProcessReplyAsNormal(pMgr, pNode, pMsg);
|
(void)syncLogReplProcessReplyAsNormal(pMgr, pNode, pMsg);
|
||||||
} else {
|
} else {
|
||||||
(void)syncLogReplMgrProcessReplyAsRecovery(pMgr, pNode, pMsg);
|
(void)syncLogReplProcessReplyAsRecovery(pMgr, pNode, pMsg);
|
||||||
}
|
}
|
||||||
taosThreadMutexUnlock(&pBuf->mutex);
|
taosThreadMutexUnlock(&pBuf->mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrReplicateOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
int32_t syncLogReplReplicateOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
||||||
if (pMgr->restored) {
|
if (pMgr->restored) {
|
||||||
(void)syncLogReplMgrReplicateAttempt(pMgr, pNode);
|
(void)syncLogReplReplicateAttempt(pMgr, pNode);
|
||||||
} else {
|
} else {
|
||||||
(void)syncLogReplMgrReplicateProbe(pMgr, pNode, pNode->pLogBuf->matchIndex);
|
(void)syncLogReplReplicateProbe(pMgr, pNode, pNode->pLogBuf->matchIndex);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrReplicateProbe(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index) {
|
int32_t syncLogReplReplicateProbe(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index) {
|
||||||
ASSERT(!pMgr->restored);
|
ASSERT(!pMgr->restored);
|
||||||
ASSERT(pMgr->startIndex >= 0);
|
ASSERT(pMgr->startIndex >= 0);
|
||||||
int64_t retryMaxWaitMs = syncGetRetryMaxWaitMs();
|
int64_t retryMaxWaitMs = syncGetRetryMaxWaitMs();
|
||||||
|
@ -829,12 +829,12 @@ int32_t syncLogReplMgrReplicateProbe(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Sy
|
||||||
nowMs < pMgr->states[pMgr->startIndex % pMgr->size].timeMs + retryMaxWaitMs) {
|
nowMs < pMgr->states[pMgr->startIndex % pMgr->size].timeMs + retryMaxWaitMs) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
(void)syncLogReplMgrReset(pMgr);
|
(void)syncLogReplReset(pMgr);
|
||||||
|
|
||||||
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
||||||
bool barrier = false;
|
bool barrier = false;
|
||||||
SyncTerm term = -1;
|
SyncTerm term = -1;
|
||||||
if (syncLogReplMgrReplicateOneTo(pMgr, pNode, index, &term, pDestId, &barrier) < 0) {
|
if (syncLogReplReplicateOneTo(pMgr, pNode, index, &term, pDestId, &barrier) < 0) {
|
||||||
sError("vgId:%d, failed to replicate log entry since %s. index:%" PRId64 ", dest: 0x%016" PRIx64 "", pNode->vgId,
|
sError("vgId:%d, failed to replicate log entry since %s. index:%" PRId64 ", dest: 0x%016" PRIx64 "", pNode->vgId,
|
||||||
terrstr(), index, pDestId->addr);
|
terrstr(), index, pDestId->addr);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -857,7 +857,7 @@ int32_t syncLogReplMgrReplicateProbe(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Sy
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrReplicateAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
int32_t syncLogReplReplicateAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
|
||||||
ASSERT(pMgr->restored);
|
ASSERT(pMgr->restored);
|
||||||
|
|
||||||
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
||||||
|
@ -879,7 +879,7 @@ int32_t syncLogReplMgrReplicateAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode)
|
||||||
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
SRaftId* pDestId = &pNode->replicasId[pMgr->peerId];
|
||||||
bool barrier = false;
|
bool barrier = false;
|
||||||
SyncTerm term = -1;
|
SyncTerm term = -1;
|
||||||
if (syncLogReplMgrReplicateOneTo(pMgr, pNode, index, &term, pDestId, &barrier) < 0) {
|
if (syncLogReplReplicateOneTo(pMgr, pNode, index, &term, pDestId, &barrier) < 0) {
|
||||||
sError("vgId:%d, failed to replicate log entry since %s. index:%" PRId64 ", dest: 0x%016" PRIx64 "", pNode->vgId,
|
sError("vgId:%d, failed to replicate log entry since %s. index:%" PRId64 ", dest: 0x%016" PRIx64 "", pNode->vgId,
|
||||||
terrstr(), index, pDestId->addr);
|
terrstr(), index, pDestId->addr);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -902,7 +902,7 @@ int32_t syncLogReplMgrReplicateAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
syncLogReplMgrRetryOnNeed(pMgr, pNode);
|
syncLogReplRetryOnNeed(pMgr, pNode);
|
||||||
|
|
||||||
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
sTrace("vgId:%d, replicated %d msgs to peer:%" PRIx64 ". indexes:%" PRId64 "..., terms: ...%" PRId64
|
sTrace("vgId:%d, replicated %d msgs to peer:%" PRIx64 ". indexes:%" PRId64 "..., terms: ...%" PRId64
|
||||||
|
@ -913,7 +913,7 @@ int32_t syncLogReplMgrReplicateAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrProcessReplyAsNormal(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg) {
|
int32_t syncLogReplProcessReplyAsNormal(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEntriesReply* pMsg) {
|
||||||
ASSERT(pMgr->restored == true);
|
ASSERT(pMgr->restored == true);
|
||||||
if (pMgr->startIndex <= pMsg->lastSendIndex && pMsg->lastSendIndex < pMgr->endIndex) {
|
if (pMgr->startIndex <= pMsg->lastSendIndex && pMsg->lastSendIndex < pMgr->endIndex) {
|
||||||
if (pMgr->startIndex < pMgr->matchIndex && pMgr->retryBackoff > 0) {
|
if (pMgr->startIndex < pMgr->matchIndex && pMgr->retryBackoff > 0) {
|
||||||
|
@ -932,10 +932,10 @@ int32_t syncLogReplMgrProcessReplyAsNormal(SSyncLogReplMgr* pMgr, SSyncNode* pNo
|
||||||
pMgr->startIndex = pMgr->matchIndex;
|
pMgr->startIndex = pMgr->matchIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return syncLogReplMgrReplicateAttempt(pMgr, pNode);
|
return syncLogReplReplicateAttempt(pMgr, pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncLogReplMgr* syncLogReplMgrCreate() {
|
SSyncLogReplMgr* syncLogReplCreate() {
|
||||||
SSyncLogReplMgr* pMgr = taosMemoryCalloc(1, sizeof(SSyncLogReplMgr));
|
SSyncLogReplMgr* pMgr = taosMemoryCalloc(1, sizeof(SSyncLogReplMgr));
|
||||||
if (pMgr == NULL) {
|
if (pMgr == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -949,7 +949,7 @@ SSyncLogReplMgr* syncLogReplMgrCreate() {
|
||||||
return pMgr;
|
return pMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogReplMgrDestroy(SSyncLogReplMgr* pMgr) {
|
void syncLogReplDestroy(SSyncLogReplMgr* pMgr) {
|
||||||
if (pMgr == NULL) {
|
if (pMgr == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -957,10 +957,10 @@ void syncLogReplMgrDestroy(SSyncLogReplMgr* pMgr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeLogReplMgrInit(SSyncNode* pNode) {
|
int32_t syncNodeLogReplInit(SSyncNode* pNode) {
|
||||||
for (int i = 0; i < TSDB_MAX_REPLICA; i++) {
|
for (int i = 0; i < TSDB_MAX_REPLICA; i++) {
|
||||||
ASSERT(pNode->logReplMgrs[i] == NULL);
|
ASSERT(pNode->logReplMgrs[i] == NULL);
|
||||||
pNode->logReplMgrs[i] = syncLogReplMgrCreate();
|
pNode->logReplMgrs[i] = syncLogReplCreate();
|
||||||
if (pNode->logReplMgrs[i] == NULL) {
|
if (pNode->logReplMgrs[i] == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -970,9 +970,9 @@ int32_t syncNodeLogReplMgrInit(SSyncNode* pNode) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncNodeLogReplMgrDestroy(SSyncNode* pNode) {
|
void syncNodeLogReplDestroy(SSyncNode* pNode) {
|
||||||
for (int i = 0; i < TSDB_MAX_REPLICA; i++) {
|
for (int i = 0; i < TSDB_MAX_REPLICA; i++) {
|
||||||
syncLogReplMgrDestroy(pNode->logReplMgrs[i]);
|
syncLogReplDestroy(pNode->logReplMgrs[i]);
|
||||||
pNode->logReplMgrs[i] = NULL;
|
pNode->logReplMgrs[i] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1103,7 +1103,7 @@ int32_t syncLogBufferReset(SSyncLogBuffer* pBuf, SSyncNode* pNode) {
|
||||||
// reset repl mgr
|
// reset repl mgr
|
||||||
for (int i = 0; i < pNode->replicaNum; i++) {
|
for (int i = 0; i < pNode->replicaNum; i++) {
|
||||||
SSyncLogReplMgr* pMgr = pNode->logReplMgrs[i];
|
SSyncLogReplMgr* pMgr = pNode->logReplMgrs[i];
|
||||||
syncLogReplMgrReset(pMgr);
|
syncLogReplReset(pMgr);
|
||||||
}
|
}
|
||||||
syncLogBufferValidate(pBuf);
|
syncLogBufferValidate(pBuf);
|
||||||
taosThreadMutexUnlock(&pBuf->mutex);
|
taosThreadMutexUnlock(&pBuf->mutex);
|
||||||
|
@ -1127,7 +1127,7 @@ SSyncRaftEntry* syncLogBufferGetOneEntry(SSyncLogBuffer* pBuf, SSyncNode* pNode,
|
||||||
return pEntry;
|
return pEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncLogReplMgrReplicateOneTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index, SyncTerm* pTerm,
|
int32_t syncLogReplReplicateOneTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex index, SyncTerm* pTerm,
|
||||||
SRaftId* pDestId, bool* pBarrier) {
|
SRaftId* pDestId, bool* pBarrier) {
|
||||||
SSyncRaftEntry* pEntry = NULL;
|
SSyncRaftEntry* pEntry = NULL;
|
||||||
SRpcMsg msgOut = {0};
|
SRpcMsg msgOut = {0};
|
||||||
|
@ -1143,14 +1143,14 @@ int32_t syncLogReplMgrReplicateOneTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Sy
|
||||||
if (pMgr) {
|
if (pMgr) {
|
||||||
sInfo("vgId:%d, reset sync log repl mgr of peer:%" PRIx64 " since %s. index:%" PRId64, pNode->vgId,
|
sInfo("vgId:%d, reset sync log repl mgr of peer:%" PRIx64 " since %s. index:%" PRId64, pNode->vgId,
|
||||||
pDestId->addr, terrstr(), index);
|
pDestId->addr, terrstr(), index);
|
||||||
(void)syncLogReplMgrReset(pMgr);
|
(void)syncLogReplReset(pMgr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
*pBarrier = syncLogIsReplicationBarrier(pEntry);
|
*pBarrier = syncLogIsReplicationBarrier(pEntry);
|
||||||
|
|
||||||
prevLogTerm = syncLogReplMgrGetPrevLogTerm(pMgr, pNode, index);
|
prevLogTerm = syncLogReplGetPrevLogTerm(pMgr, pNode, index);
|
||||||
if (prevLogTerm < 0) {
|
if (prevLogTerm < 0) {
|
||||||
sError("vgId:%d, failed to get prev log term since %s. index:%" PRId64 "", pNode->vgId, terrstr(), index);
|
sError("vgId:%d, failed to get prev log term since %s. index:%" PRId64 "", pNode->vgId, terrstr(), index);
|
||||||
goto _err;
|
goto _err;
|
||||||
|
|
|
@ -52,7 +52,7 @@ int32_t syncNodeReplicateReset(SSyncNode* pNode, SRaftId* pDestId) {
|
||||||
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
SSyncLogBuffer* pBuf = pNode->pLogBuf;
|
||||||
taosThreadMutexLock(&pBuf->mutex);
|
taosThreadMutexLock(&pBuf->mutex);
|
||||||
SSyncLogReplMgr* pMgr = syncNodeGetLogReplMgr(pNode, pDestId);
|
SSyncLogReplMgr* pMgr = syncNodeGetLogReplMgr(pNode, pDestId);
|
||||||
syncLogReplMgrReset(pMgr);
|
syncLogReplReset(pMgr);
|
||||||
taosThreadMutexUnlock(&pBuf->mutex);
|
taosThreadMutexUnlock(&pBuf->mutex);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ int32_t syncNodeReplicateWithoutLock(SSyncNode* pNode) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SSyncLogReplMgr* pMgr = pNode->logReplMgrs[i];
|
SSyncLogReplMgr* pMgr = pNode->logReplMgrs[i];
|
||||||
(void)syncLogReplMgrReplicateOnce(pMgr, pNode);
|
(void)syncLogReplReplicateOnce(pMgr, pNode);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ static void syncLogBufferStates2Str(SSyncNode* pSyncNode, char* buf, int32_t buf
|
||||||
pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncLogReplMgrStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
static void syncLogReplStates2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
||||||
int len = 0;
|
int len = 0;
|
||||||
len += snprintf(buf + len, bufLen - len, "%s", "{");
|
len += snprintf(buf + len, bufLen - len, "%s", "{");
|
||||||
for (int32_t i = 0; i < pSyncNode->replicaNum; i++) {
|
for (int32_t i = 0; i < pSyncNode->replicaNum; i++) {
|
||||||
|
@ -178,7 +178,7 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
|
||||||
syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
|
syncCfg2SimpleStr(&pNode->raftCfg.cfg, cfgStr, sizeof(cfgStr));
|
||||||
|
|
||||||
char replMgrStatesStr[1024] = "";
|
char replMgrStatesStr[1024] = "";
|
||||||
syncLogReplMgrStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
|
syncLogReplStates2Str(pNode, replMgrStatesStr, sizeof(replMgrStatesStr));
|
||||||
|
|
||||||
char bufferStatesStr[256] = "";
|
char bufferStatesStr[256] = "";
|
||||||
syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
|
syncLogBufferStates2Str(pNode, bufferStatesStr, sizeof(bufferStatesStr));
|
||||||
|
|
|
@ -462,6 +462,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) {
|
||||||
if (transQueueEmpty(&pConn->cliMsgs)) {
|
if (transQueueEmpty(&pConn->cliMsgs)) {
|
||||||
if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) {
|
if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) {
|
||||||
tTrace("%s conn %p handle except, persist:0", CONN_GET_INST_LABEL(pConn), pConn);
|
tTrace("%s conn %p handle except, persist:0", CONN_GET_INST_LABEL(pConn), pConn);
|
||||||
|
if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn);
|
||||||
transUnrefCliHandle(pConn);
|
transUnrefCliHandle(pConn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -521,6 +522,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) {
|
||||||
destroyCmsg(pMsg);
|
destroyCmsg(pMsg);
|
||||||
tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, T_REF_VAL_GET(pConn));
|
tTrace("%s conn %p start to destroy, ref:%d", CONN_GET_INST_LABEL(pConn), pConn, T_REF_VAL_GET(pConn));
|
||||||
} while (!transQueueEmpty(&pConn->cliMsgs));
|
} while (!transQueueEmpty(&pConn->cliMsgs));
|
||||||
|
if (T_REF_VAL_GET(pConn) > 1) transUnrefCliHandle(pConn);
|
||||||
transUnrefCliHandle(pConn);
|
transUnrefCliHandle(pConn);
|
||||||
}
|
}
|
||||||
void cliHandleExcept(SCliConn* conn) {
|
void cliHandleExcept(SCliConn* conn) {
|
||||||
|
|
|
@ -33,7 +33,6 @@ SWalReader *walOpenReader(SWal *pWal, SWalFilterCond *cond) {
|
||||||
pReader->pLogFile = NULL;
|
pReader->pLogFile = NULL;
|
||||||
pReader->curVersion = -1;
|
pReader->curVersion = -1;
|
||||||
pReader->curFileFirstVer = -1;
|
pReader->curFileFirstVer = -1;
|
||||||
pReader->curInvalid = 1;
|
|
||||||
pReader->capacity = 0;
|
pReader->capacity = 0;
|
||||||
if (cond) {
|
if (cond) {
|
||||||
pReader->cond = *cond;
|
pReader->cond = *cond;
|
||||||
|
@ -81,7 +80,6 @@ int32_t walNextValidMsg(SWalReader *pReader) {
|
||||||
wDebug("vgId:%d, wal start to fetch, index:%" PRId64 ", last index:%" PRId64 " commit index:%" PRId64
|
wDebug("vgId:%d, wal start to fetch, index:%" PRId64 ", last index:%" PRId64 " commit index:%" PRId64
|
||||||
", applied index:%" PRId64 ", end index:%" PRId64,
|
", applied index:%" PRId64 ", end index:%" PRId64,
|
||||||
pReader->pWal->cfg.vgId, fetchVer, lastVer, committedVer, appliedVer, endVer);
|
pReader->pWal->cfg.vgId, fetchVer, lastVer, committedVer, appliedVer, endVer);
|
||||||
pReader->curStopped = 0;
|
|
||||||
while (fetchVer <= endVer) {
|
while (fetchVer <= endVer) {
|
||||||
if (walFetchHeadNew(pReader, fetchVer) < 0) {
|
if (walFetchHeadNew(pReader, fetchVer) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -99,7 +97,6 @@ int32_t walNextValidMsg(SWalReader *pReader) {
|
||||||
fetchVer = pReader->curVersion;
|
fetchVer = pReader->curVersion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pReader->curStopped = 1;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,17 +193,16 @@ int32_t walReadSeekVerImpl(SWalReader *pReader, int64_t ver) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
wDebug("vgId:%d, wal version reset from %" PRId64 "(invalid:%d) to %" PRId64, pReader->pWal->cfg.vgId,
|
wDebug("vgId:%d, wal version reset from %" PRId64 " to %" PRId64, pReader->pWal->cfg.vgId,
|
||||||
pReader->curVersion, pReader->curInvalid, ver);
|
pReader->curVersion, ver);
|
||||||
|
|
||||||
pReader->curVersion = ver;
|
pReader->curVersion = ver;
|
||||||
pReader->curInvalid = 0;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t walReadSeekVer(SWalReader *pReader, int64_t ver) {
|
int32_t walReadSeekVer(SWalReader *pReader, int64_t ver) {
|
||||||
SWal *pWal = pReader->pWal;
|
SWal *pWal = pReader->pWal;
|
||||||
if (!pReader->curInvalid && ver == pReader->curVersion) {
|
if (ver == pReader->curVersion) {
|
||||||
wDebug("vgId:%d, wal index:%" PRId64 " match, no need to reset", pReader->pWal->cfg.vgId, ver);
|
wDebug("vgId:%d, wal index:%" PRId64 " match, no need to reset", pReader->pWal->cfg.vgId, ver);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -238,7 +234,7 @@ static int32_t walFetchHeadNew(SWalReader *pRead, int64_t fetchVer) {
|
||||||
|
|
||||||
wDebug("vgId:%d, wal starts to fetch head, index:%" PRId64, pRead->pWal->cfg.vgId, fetchVer);
|
wDebug("vgId:%d, wal starts to fetch head, index:%" PRId64, pRead->pWal->cfg.vgId, fetchVer);
|
||||||
|
|
||||||
if (pRead->curInvalid || pRead->curVersion != fetchVer) {
|
if (pRead->curVersion != fetchVer) {
|
||||||
if (walReadSeekVer(pRead, fetchVer) < 0) {
|
if (walReadSeekVer(pRead, fetchVer) < 0) {
|
||||||
// pRead->curVersion = fetchVer;
|
// pRead->curVersion = fetchVer;
|
||||||
// pRead->curInvalid = 1;
|
// pRead->curInvalid = 1;
|
||||||
|
@ -344,7 +340,7 @@ int32_t walFetchHead(SWalReader *pRead, int64_t ver, SWalCkHead *pHead) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRead->curInvalid || pRead->curVersion != ver) {
|
if (pRead->curVersion != ver) {
|
||||||
code = walReadSeekVer(pRead, ver);
|
code = walReadSeekVer(pRead, ver);
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
// pRead->curVersion = ver;
|
// pRead->curVersion = ver;
|
||||||
|
@ -479,7 +475,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
|
||||||
|
|
||||||
taosThreadMutexLock(&pReader->mutex);
|
taosThreadMutexLock(&pReader->mutex);
|
||||||
|
|
||||||
if (pReader->curInvalid || pReader->curVersion != ver) {
|
if (pReader->curVersion != ver) {
|
||||||
if (walReadSeekVer(pReader, ver) < 0) {
|
if (walReadSeekVer(pReader, ver) < 0) {
|
||||||
wError("vgId:%d, unexpected wal log, index:%" PRId64 ", since %s", pReader->pWal->cfg.vgId, ver, terrstr());
|
wError("vgId:%d, unexpected wal log, index:%" PRId64 ", since %s", pReader->pWal->cfg.vgId, ver, terrstr());
|
||||||
taosThreadMutexUnlock(&pReader->mutex);
|
taosThreadMutexUnlock(&pReader->mutex);
|
||||||
|
@ -575,7 +571,6 @@ void walReadReset(SWalReader *pReader) {
|
||||||
taosThreadMutexLock(&pReader->mutex);
|
taosThreadMutexLock(&pReader->mutex);
|
||||||
taosCloseFile(&pReader->pIdxFile);
|
taosCloseFile(&pReader->pIdxFile);
|
||||||
taosCloseFile(&pReader->pLogFile);
|
taosCloseFile(&pReader->pLogFile);
|
||||||
pReader->curInvalid = 1;
|
|
||||||
pReader->curFileFirstVer = -1;
|
pReader->curFileFirstVer = -1;
|
||||||
pReader->curVersion = -1;
|
pReader->curVersion = -1;
|
||||||
taosThreadMutexUnlock(&pReader->mutex);
|
taosThreadMutexUnlock(&pReader->mutex);
|
||||||
|
|
|
@ -190,6 +190,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_NO_USER_FROM_CONN, "Can not get user from
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_USERS, "Too many users")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_USERS, "Too many users")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ALTER_OPER, "Invalid alter operation")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ALTER_OPER, "Invalid alter operation")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_AUTH_FAILURE, "Authentication failure")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_AUTH_FAILURE, "Authentication failure")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_PRIVILEDGE_EXIST, "User already have this priviledge")
|
||||||
|
|
||||||
//mnode-stable-part1
|
//mnode-stable-part1
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_STB_ALREADY_EXIST, "STable already exists")
|
TAOS_DEFINE_ERROR(TSDB_CODE_MND_STB_ALREADY_EXIST, "STable already exists")
|
||||||
|
@ -631,6 +632,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_INDEX_INVALID_FILE, "Index file is inval
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_TMQ_INVALID_MSG, "Invalid message")
|
TAOS_DEFINE_ERROR(TSDB_CODE_TMQ_INVALID_MSG, "Invalid message")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_TMQ_CONSUMER_MISMATCH, "Consumer mismatch")
|
TAOS_DEFINE_ERROR(TSDB_CODE_TMQ_CONSUMER_MISMATCH, "Consumer mismatch")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_TMQ_CONSUMER_CLOSED, "Consumer closed")
|
TAOS_DEFINE_ERROR(TSDB_CODE_TMQ_CONSUMER_CLOSED, "Consumer closed")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_TMQ_CONSUMER_ERROR, "Consumer error, to see log")
|
||||||
|
|
||||||
// stream
|
// stream
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_STREAM_TASK_NOT_EXIST, "Stream task not exist")
|
TAOS_DEFINE_ERROR(TSDB_CODE_STREAM_TASK_NOT_EXIST, "Stream task not exist")
|
||||||
|
|
|
@ -59,9 +59,9 @@ class TDTestCase:
|
||||||
os.system("%s" % cmd)
|
os.system("%s" % cmd)
|
||||||
tdSql.execute("reset query cache")
|
tdSql.execute("reset query cache")
|
||||||
tdSql.query("show db.tables")
|
tdSql.query("show db.tables")
|
||||||
tdSql.checkRows(10)
|
tdSql.checkRows(8)
|
||||||
tdSql.query("select count(*) from db.stb")
|
tdSql.query("select count(*) from db.stb")
|
||||||
tdSql.checkData(0, 0, 100)
|
tdSql.checkData(0, 0, 80)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
tdSql.close()
|
tdSql.close()
|
||||||
|
|
|
@ -15,13 +15,18 @@
|
||||||
"num_of_records_per_req": 10,
|
"num_of_records_per_req": 10,
|
||||||
"databases": [{
|
"databases": [{
|
||||||
"dbinfo": {
|
"dbinfo": {
|
||||||
"name": "db"
|
"name": "db",
|
||||||
|
"drop": "yes"
|
||||||
|
|
||||||
},
|
},
|
||||||
"super_tables": [{
|
"super_tables": [{
|
||||||
|
"child_table_exists":"no",
|
||||||
"name": "stb",
|
"name": "stb",
|
||||||
"childtable_prefix": "stb_",
|
"childtable_prefix": "stb_",
|
||||||
"childtable_count": 10,
|
"childtable_count": 10,
|
||||||
"insert_rows": 10,
|
"insert_rows": 10,
|
||||||
|
"childtable_from": 1,
|
||||||
|
"childtable_to": 9,
|
||||||
"columns": [{"type": "INT"}],
|
"columns": [{"type": "INT"}],
|
||||||
"tags": [{"type": "INT"}]
|
"tags": [{"type": "INT"}]
|
||||||
}]
|
}]
|
||||||
|
|
|
@ -94,7 +94,7 @@
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqDropStbCtb.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqDropStbCtb.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqDropNtb-snapshot0.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqDropNtb-snapshot0.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqDropNtb-snapshot1.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqDropNtb-snapshot1.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqUdf.py
|
#,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqUdf.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot0.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot0.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot1.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqUdf-multCtb-snapshot1.py
|
||||||
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/stbTagFilter-1ctb.py
|
,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/stbTagFilter-1ctb.py
|
||||||
|
@ -878,6 +878,7 @@
|
||||||
,,y,script,./test.sh -f tsim/query/udf_with_const.sim
|
,,y,script,./test.sh -f tsim/query/udf_with_const.sim
|
||||||
,,y,script,./test.sh -f tsim/query/join_interval.sim
|
,,y,script,./test.sh -f tsim/query/join_interval.sim
|
||||||
,,y,script,./test.sh -f tsim/query/unionall_as_table.sim
|
,,y,script,./test.sh -f tsim/query/unionall_as_table.sim
|
||||||
|
,,y,script,./test.sh -f tsim/query/multi_order_by.sim
|
||||||
,,y,script,./test.sh -f tsim/query/sys_tbname.sim
|
,,y,script,./test.sh -f tsim/query/sys_tbname.sim
|
||||||
,,y,script,./test.sh -f tsim/query/groupby.sim
|
,,y,script,./test.sh -f tsim/query/groupby.sim
|
||||||
,,y,script,./test.sh -f tsim/query/event.sim
|
,,y,script,./test.sh -f tsim/query/event.sim
|
||||||
|
|
|
@ -51,7 +51,7 @@ class AutoGen:
|
||||||
metas = []
|
metas = []
|
||||||
for i in range(cnt):
|
for i in range(cnt):
|
||||||
colname = f"{pre}{i}"
|
colname = f"{pre}{i}"
|
||||||
sel = len(types) % len(types)
|
sel = i % len(types)
|
||||||
coltype = types[sel]
|
coltype = types[sel]
|
||||||
sql = f"{colname} {coltype}"
|
sql = f"{colname} {coltype}"
|
||||||
if sqls != "":
|
if sqls != "":
|
||||||
|
|
|
@ -122,9 +122,11 @@ int insertAUTOTest2(TAOS_STMT *stmt, TAOS *taos);
|
||||||
int insertAUTOTest3(TAOS_STMT *stmt, TAOS *taos);
|
int insertAUTOTest3(TAOS_STMT *stmt, TAOS *taos);
|
||||||
int queryColumnTest(TAOS_STMT *stmt, TAOS *taos);
|
int queryColumnTest(TAOS_STMT *stmt, TAOS *taos);
|
||||||
int queryMiscTest(TAOS_STMT *stmt, TAOS *taos);
|
int queryMiscTest(TAOS_STMT *stmt, TAOS *taos);
|
||||||
|
int insertNonExistsTb(TAOS_STMT *stmt, TAOS *taos);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TTYPE_INSERT = 1,
|
TTYPE_INSERT = 1,
|
||||||
|
TTYPE_INSERT_NG,
|
||||||
TTYPE_QUERY,
|
TTYPE_QUERY,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -187,6 +189,8 @@ CaseCfg gCase[] = {
|
||||||
{"query:SUBT-COLUMN", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryColumnTest, 10, 10, 1, 3, 0, 0, 1, 2},
|
{"query:SUBT-COLUMN", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryColumnTest, 10, 10, 1, 3, 0, 0, 1, 2},
|
||||||
{"query:SUBT-MISC", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryMiscTest, 10, 10, 1, 3, 0, 0, 1, 2},
|
{"query:SUBT-MISC", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryMiscTest, 10, 10, 1, 3, 0, 0, 1, 2},
|
||||||
|
|
||||||
|
{"query:NG-TBNEXISTS",tListLen(fullColList), fullColList, TTYPE_INSERT_NG,0, false, false, insertNonExistsTb, 10, 10, 1, 3, 0, 0, 1, -1},
|
||||||
|
|
||||||
// {"query:SUBT-COLUMN", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryColumnTest, 1, 10, 1, 1, 0, 0, 1, 2},
|
// {"query:SUBT-COLUMN", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryColumnTest, 1, 10, 1, 1, 0, 0, 1, 2},
|
||||||
// {"query:SUBT-MISC", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryMiscTest, 2, 10, 1, 1, 0, 0, 1, 2},
|
// {"query:SUBT-MISC", tListLen(fullColList), fullColList, TTYPE_QUERY, 0, false, false, queryMiscTest, 2, 10, 1, 1, 0, 0, 1, 2},
|
||||||
|
|
||||||
|
@ -250,7 +254,7 @@ CaseCtrl gCaseCtrl = {
|
||||||
.funcIdxList = NULL,
|
.funcIdxList = NULL,
|
||||||
.checkParamNum = false,
|
.checkParamNum = false,
|
||||||
.runTimes = 0,
|
.runTimes = 0,
|
||||||
.caseIdx = 24,
|
.caseIdx = 26,
|
||||||
.caseNum = 1,
|
.caseNum = 1,
|
||||||
.caseRunIdx = -1,
|
.caseRunIdx = -1,
|
||||||
.caseRunNum = -1,
|
.caseRunNum = -1,
|
||||||
|
@ -2191,6 +2195,47 @@ int queryMiscTest(TAOS_STMT *stmt, TAOS *taos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int insertNonExistsTb(TAOS_STMT *stmt, TAOS *taos) {
|
||||||
|
BindData data = {0};
|
||||||
|
prepareInsertData(&data);
|
||||||
|
|
||||||
|
int code = taos_stmt_prepare(stmt, data.sql, 0);
|
||||||
|
if (code != 0){
|
||||||
|
printf("!!!failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bpCheckIsInsert(stmt, 1);
|
||||||
|
|
||||||
|
char *buf = "tbnexist";
|
||||||
|
code = bpSetTableNameTags(&data, 0, buf, stmt);
|
||||||
|
if (code == 0){
|
||||||
|
printf("!!!taos_stmt_set_tbname expected error not occurred\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == taos_stmt_bind_param_batch(stmt, data.pBind)) {
|
||||||
|
printf("!!!taos_stmt_bind_param_batch expected error not occurred\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == taos_stmt_add_batch(stmt)) {
|
||||||
|
printf("!!!taos_stmt_add_batch expected error not occurred\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == taos_stmt_execute(stmt)) {
|
||||||
|
printf("!!!taos_stmt_execute expected error not occurred\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
destroyData(&data);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int errorSQLTest1(TAOS_STMT *stmt, TAOS *taos) {
|
int errorSQLTest1(TAOS_STMT *stmt, TAOS *taos) {
|
||||||
BindData data = {0};
|
BindData data = {0};
|
||||||
|
|
||||||
|
@ -2213,6 +2258,10 @@ int errorSQLTest1(TAOS_STMT *stmt, TAOS *taos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void prepareCheckResultImpl(TAOS * taos, char *tname, bool printr, int expected, bool silent) {
|
void prepareCheckResultImpl(TAOS * taos, char *tname, bool printr, int expected, bool silent) {
|
||||||
|
if (TTYPE_INSERT_NG == gCurCase->testType) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
char sql[255] = "SELECT * FROM ";
|
char sql[255] = "SELECT * FROM ";
|
||||||
int32_t rows = 0;
|
int32_t rows = 0;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
sql create database test;
|
||||||
|
sql use test;
|
||||||
|
|
||||||
|
sql create table t(ts timestamp, f int);
|
||||||
|
sql insert into t values(now,0)(now+1s, 1)(now+2s, 2)(now+3s,3)(now+4s,4)(now+5s,5)(now+6s,6)(now+7s,7)(now+8s,8)(now+9s,9)
|
||||||
|
sql select * from (select * from t order by ts desc limit 3 offset 2) order by ts;
|
||||||
|
print $data01 $data11 $data21
|
||||||
|
if $data01 != 5 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data11 != 6 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data21 != 7 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql select * from (select * from t order by ts limit 3 offset 2) order by ts desc;
|
||||||
|
print $data01 $data11 $data21
|
||||||
|
if $data01 != 4 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data11 != 3 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data21 != 2 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql select * from (select * from t order by ts desc limit 3 offset 2) order by ts desc;
|
||||||
|
print $data01 $data11 $data21
|
||||||
|
if $data01 != 7 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data11 != 6 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data21 != 5 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql select * from (select * from t order by ts limit 3 offset 2) order by ts;
|
||||||
|
print $data01 $data11 $data21
|
||||||
|
if $data01 != 2 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data11 != 3 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data21 != 4 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue