Merge pull request #23457 from taosdata/feat/TD-25204
feat: support view
This commit is contained in:
commit
647c56e391
|
@ -49,6 +49,7 @@ extern "C" {
|
|||
#define TSDB_INS_TABLE_STREAMS "ins_streams"
|
||||
#define TSDB_INS_TABLE_STREAM_TASKS "ins_stream_tasks"
|
||||
#define TSDB_INS_TABLE_USER_PRIVILEGES "ins_user_privileges"
|
||||
#define TSDB_INS_TABLE_VIEWS "ins_views"
|
||||
|
||||
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
|
||||
#define TSDB_PERFS_TABLE_SMAS "perf_smas"
|
||||
|
|
|
@ -42,7 +42,8 @@ typedef enum {
|
|||
TSDB_TEMP_TABLE = 4, // temp table created by nest query
|
||||
TSDB_SYSTEM_TABLE = 5,
|
||||
TSDB_TSMA_TABLE = 6, // time-range-wise sma
|
||||
TSDB_TABLE_MAX = 7
|
||||
TSDB_VIEW_TABLE = 7,
|
||||
TSDB_TABLE_MAX = 8
|
||||
} ETableType;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -107,6 +107,8 @@ enum {
|
|||
HEARTBEAT_KEY_DBINFO,
|
||||
HEARTBEAT_KEY_STBINFO,
|
||||
HEARTBEAT_KEY_TMQ,
|
||||
HEARTBEAT_KEY_DYN_VIEW,
|
||||
HEARTBEAT_KEY_VIEWINFO,
|
||||
};
|
||||
|
||||
typedef enum _mgmt_table {
|
||||
|
@ -141,6 +143,7 @@ typedef enum _mgmt_table {
|
|||
TSDB_MGMT_TABLE_APPS,
|
||||
TSDB_MGMT_TABLE_STREAM_TASKS,
|
||||
TSDB_MGMT_TABLE_PRIVILEGES,
|
||||
TSDB_MGMT_TABLE_VIEWS,
|
||||
TSDB_MGMT_TABLE_MAX,
|
||||
} EShowType;
|
||||
|
||||
|
@ -168,26 +171,12 @@ typedef enum _mgmt_table {
|
|||
|
||||
#define TSDB_ALTER_USER_PASSWD 0x1
|
||||
#define TSDB_ALTER_USER_SUPERUSER 0x2
|
||||
#define TSDB_ALTER_USER_ADD_READ_DB 0x3
|
||||
#define TSDB_ALTER_USER_REMOVE_READ_DB 0x4
|
||||
#define TSDB_ALTER_USER_ADD_WRITE_DB 0x5
|
||||
#define TSDB_ALTER_USER_REMOVE_WRITE_DB 0x6
|
||||
#define TSDB_ALTER_USER_ADD_ALL_DB 0x7
|
||||
#define TSDB_ALTER_USER_REMOVE_ALL_DB 0x8
|
||||
#define TSDB_ALTER_USER_ENABLE 0x9
|
||||
#define TSDB_ALTER_USER_SYSINFO 0xA
|
||||
#define TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC 0xB
|
||||
#define TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC 0xC
|
||||
#define TSDB_ALTER_USER_ADD_READ_TABLE 0xD
|
||||
#define TSDB_ALTER_USER_REMOVE_READ_TABLE 0xE
|
||||
#define TSDB_ALTER_USER_ADD_WRITE_TABLE 0xF
|
||||
#define TSDB_ALTER_USER_REMOVE_WRITE_TABLE 0x10
|
||||
#define TSDB_ALTER_USER_ADD_ALL_TABLE 0x11
|
||||
#define TSDB_ALTER_USER_REMOVE_ALL_TABLE 0x12
|
||||
#define TSDB_ALTER_USER_ADD_WHITE_LIST 0x13
|
||||
#define TSDB_ALTER_USER_DROP_WHITE_LIST 0x14
|
||||
|
||||
#define TSDB_ALTER_USER_PRIVILEGES 0x2
|
||||
#define TSDB_ALTER_USER_ENABLE 0x3
|
||||
#define TSDB_ALTER_USER_SYSINFO 0x4
|
||||
#define TSDB_ALTER_USER_ADD_PRIVILEGES 0x5
|
||||
#define TSDB_ALTER_USER_DEL_PRIVILEGES 0x6
|
||||
#define TSDB_ALTER_USER_ADD_WHITE_LIST 0x7
|
||||
#define TSDB_ALTER_USER_DROP_WHITE_LIST 0x8
|
||||
|
||||
#define TSDB_KILL_MSG_LEN 30
|
||||
|
||||
|
@ -251,6 +240,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_CASE_WHEN,
|
||||
QUERY_NODE_EVENT_WINDOW,
|
||||
QUERY_NODE_HINT,
|
||||
QUERY_NODE_VIEW,
|
||||
|
||||
// Statement nodes are used in parser and planner module.
|
||||
QUERY_NODE_SET_OPERATOR = 100,
|
||||
|
@ -333,6 +323,8 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT,
|
||||
QUERY_NODE_SHOW_VNODES_STMT,
|
||||
QUERY_NODE_SHOW_USER_PRIVILEGES_STMT,
|
||||
QUERY_NODE_SHOW_VIEWS_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_VIEW_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_TABLE_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_STABLE_STMT,
|
||||
|
@ -354,7 +346,9 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_RESTORE_MNODE_STMT,
|
||||
QUERY_NODE_RESTORE_VNODE_STMT,
|
||||
QUERY_NODE_PAUSE_STREAM_STMT,
|
||||
QUERY_NODE_RESUME_STREAM_STMT,
|
||||
QUERY_NODE_RESUME_STREAM_STMT,
|
||||
QUERY_NODE_CREATE_VIEW_STMT,
|
||||
QUERY_NODE_DROP_VIEW_STMT,
|
||||
|
||||
// logic plan node
|
||||
QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
|
||||
|
@ -943,6 +937,7 @@ typedef struct {
|
|||
int8_t superUser;
|
||||
int8_t sysInfo;
|
||||
int8_t enable;
|
||||
int8_t isView;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_USET_PASSWORD_LEN];
|
||||
char objname[TSDB_DB_FNAME_LEN]; // db or topic
|
||||
|
@ -951,6 +946,7 @@ typedef struct {
|
|||
int32_t tagCondLen;
|
||||
int32_t numIpRanges;
|
||||
SIpV4Range* pIpRanges;
|
||||
int64_t privileges;
|
||||
int32_t sqlLen;
|
||||
char* sql;
|
||||
} SAlterUserReq;
|
||||
|
@ -979,6 +975,10 @@ typedef struct {
|
|||
SHashObj* writeDbs;
|
||||
SHashObj* readTbs;
|
||||
SHashObj* writeTbs;
|
||||
SHashObj* alterTbs;
|
||||
SHashObj* readViews;
|
||||
SHashObj* writeViews;
|
||||
SHashObj* alterViews;
|
||||
SHashObj* useDbs;
|
||||
int64_t whiteListVer;
|
||||
} SGetUserAuthRsp;
|
||||
|
@ -1809,6 +1809,15 @@ int32_t tSerializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
|
|||
int32_t tDeserializeSSTbHbRsp(void* buf, int32_t bufLen, SSTbHbRsp* pRsp);
|
||||
void tFreeSSTbHbRsp(SSTbHbRsp* pRsp);
|
||||
|
||||
typedef struct {
|
||||
SArray* pViewRsp; // Array of SViewMetaRsp*;
|
||||
} SViewHbRsp;
|
||||
|
||||
int32_t tSerializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
|
||||
int32_t tDeserializeSViewHbRsp(void* buf, int32_t bufLen, SViewHbRsp* pRsp);
|
||||
void tFreeSViewHbRsp(SViewHbRsp* pRsp);
|
||||
|
||||
|
||||
typedef struct {
|
||||
int32_t numOfTables;
|
||||
int32_t numOfVgroup;
|
||||
|
@ -3881,6 +3890,58 @@ typedef struct {
|
|||
};
|
||||
} SPackedData;
|
||||
|
||||
typedef struct {
|
||||
char fullname[TSDB_VIEW_FNAME_LEN];
|
||||
char name[TSDB_VIEW_NAME_LEN];
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
char* querySql;
|
||||
char* sql;
|
||||
int8_t orReplace;
|
||||
int8_t precision;
|
||||
int32_t numOfCols;
|
||||
SSchema* pSchema;
|
||||
} SCMCreateViewReq;
|
||||
|
||||
int32_t tSerializeSCMCreateViewReq(void* buf, int32_t bufLen, const SCMCreateViewReq* pReq);
|
||||
int32_t tDeserializeSCMCreateViewReq(void* buf, int32_t bufLen, SCMCreateViewReq* pReq);
|
||||
void tFreeSCMCreateViewReq(SCMCreateViewReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
char fullname[TSDB_VIEW_FNAME_LEN];
|
||||
char name[TSDB_VIEW_NAME_LEN];
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
char* sql;
|
||||
int8_t igNotExists;
|
||||
} SCMDropViewReq;
|
||||
|
||||
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq);
|
||||
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq);
|
||||
void tFreeSCMDropViewReq(SCMDropViewReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
char fullname[TSDB_VIEW_FNAME_LEN];
|
||||
} SViewMetaReq;
|
||||
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq);
|
||||
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_VIEW_NAME_LEN];
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
char* user;
|
||||
uint64_t dbId;
|
||||
uint64_t viewId;
|
||||
char* querySql;
|
||||
int8_t precision;
|
||||
int8_t type;
|
||||
int32_t version;
|
||||
int32_t numOfCols;
|
||||
SSchema* pSchema;
|
||||
} SViewMetaRsp;
|
||||
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp);
|
||||
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp);
|
||||
void tFreeSViewMetaRsp(SViewMetaRsp* pRsp);
|
||||
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -189,6 +189,9 @@ enum { // WARN: new msg should be appended to segment tail
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_STREAM_NODECHANGE_CHECK, "stream-nodechange-check", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_TRIM_DB_TIMER, "trim-db-tmr", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_GRANT_NOTIFY, "grant-notify", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_VIEW, "create-view", SCMCreateViewReq, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_VIEW, "drop-view", SCMDropViewReq, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_VIEW_META, "view-meta", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MAX_MSG, "mnd-max", NULL, NULL)
|
||||
|
||||
TD_NEW_MSG_SEG(TDMT_VND_MSG)
|
||||
|
|
|
@ -187,180 +187,183 @@
|
|||
#define TK_SUBSCRIPTIONS 168
|
||||
#define TK_VNODES 169
|
||||
#define TK_ALIVE 170
|
||||
#define TK_NORMAL 171
|
||||
#define TK_CHILD 172
|
||||
#define TK_LIKE 173
|
||||
#define TK_TBNAME 174
|
||||
#define TK_QTAGS 175
|
||||
#define TK_AS 176
|
||||
#define TK_SYSTEM 177
|
||||
#define TK_INDEX 178
|
||||
#define TK_FUNCTION 179
|
||||
#define TK_INTERVAL 180
|
||||
#define TK_COUNT 181
|
||||
#define TK_LAST_ROW 182
|
||||
#define TK_META 183
|
||||
#define TK_ONLY 184
|
||||
#define TK_TOPIC 185
|
||||
#define TK_CONSUMER 186
|
||||
#define TK_GROUP 187
|
||||
#define TK_DESC 188
|
||||
#define TK_DESCRIBE 189
|
||||
#define TK_RESET 190
|
||||
#define TK_QUERY 191
|
||||
#define TK_CACHE 192
|
||||
#define TK_EXPLAIN 193
|
||||
#define TK_ANALYZE 194
|
||||
#define TK_VERBOSE 195
|
||||
#define TK_NK_BOOL 196
|
||||
#define TK_RATIO 197
|
||||
#define TK_NK_FLOAT 198
|
||||
#define TK_OUTPUTTYPE 199
|
||||
#define TK_AGGREGATE 200
|
||||
#define TK_BUFSIZE 201
|
||||
#define TK_LANGUAGE 202
|
||||
#define TK_REPLACE 203
|
||||
#define TK_STREAM 204
|
||||
#define TK_INTO 205
|
||||
#define TK_PAUSE 206
|
||||
#define TK_RESUME 207
|
||||
#define TK_TRIGGER 208
|
||||
#define TK_AT_ONCE 209
|
||||
#define TK_WINDOW_CLOSE 210
|
||||
#define TK_IGNORE 211
|
||||
#define TK_EXPIRED 212
|
||||
#define TK_FILL_HISTORY 213
|
||||
#define TK_UPDATE 214
|
||||
#define TK_SUBTABLE 215
|
||||
#define TK_UNTREATED 216
|
||||
#define TK_KILL 217
|
||||
#define TK_CONNECTION 218
|
||||
#define TK_TRANSACTION 219
|
||||
#define TK_BALANCE 220
|
||||
#define TK_VGROUP 221
|
||||
#define TK_LEADER 222
|
||||
#define TK_MERGE 223
|
||||
#define TK_REDISTRIBUTE 224
|
||||
#define TK_SPLIT 225
|
||||
#define TK_DELETE 226
|
||||
#define TK_INSERT 227
|
||||
#define TK_NULL 228
|
||||
#define TK_NK_QUESTION 229
|
||||
#define TK_NK_ALIAS 230
|
||||
#define TK_NK_ARROW 231
|
||||
#define TK_ROWTS 232
|
||||
#define TK_QSTART 233
|
||||
#define TK_QEND 234
|
||||
#define TK_QDURATION 235
|
||||
#define TK_WSTART 236
|
||||
#define TK_WEND 237
|
||||
#define TK_WDURATION 238
|
||||
#define TK_IROWTS 239
|
||||
#define TK_ISFILLED 240
|
||||
#define TK_CAST 241
|
||||
#define TK_NOW 242
|
||||
#define TK_TODAY 243
|
||||
#define TK_TIMEZONE 244
|
||||
#define TK_CLIENT_VERSION 245
|
||||
#define TK_SERVER_VERSION 246
|
||||
#define TK_SERVER_STATUS 247
|
||||
#define TK_CURRENT_USER 248
|
||||
#define TK_CASE 249
|
||||
#define TK_WHEN 250
|
||||
#define TK_THEN 251
|
||||
#define TK_ELSE 252
|
||||
#define TK_BETWEEN 253
|
||||
#define TK_IS 254
|
||||
#define TK_NK_LT 255
|
||||
#define TK_NK_GT 256
|
||||
#define TK_NK_LE 257
|
||||
#define TK_NK_GE 258
|
||||
#define TK_NK_NE 259
|
||||
#define TK_MATCH 260
|
||||
#define TK_NMATCH 261
|
||||
#define TK_CONTAINS 262
|
||||
#define TK_IN 263
|
||||
#define TK_JOIN 264
|
||||
#define TK_INNER 265
|
||||
#define TK_SELECT 266
|
||||
#define TK_NK_HINT 267
|
||||
#define TK_DISTINCT 268
|
||||
#define TK_WHERE 269
|
||||
#define TK_PARTITION 270
|
||||
#define TK_BY 271
|
||||
#define TK_SESSION 272
|
||||
#define TK_STATE_WINDOW 273
|
||||
#define TK_EVENT_WINDOW 274
|
||||
#define TK_SLIDING 275
|
||||
#define TK_FILL 276
|
||||
#define TK_VALUE 277
|
||||
#define TK_VALUE_F 278
|
||||
#define TK_NONE 279
|
||||
#define TK_PREV 280
|
||||
#define TK_NULL_F 281
|
||||
#define TK_LINEAR 282
|
||||
#define TK_NEXT 283
|
||||
#define TK_HAVING 284
|
||||
#define TK_RANGE 285
|
||||
#define TK_EVERY 286
|
||||
#define TK_ORDER 287
|
||||
#define TK_SLIMIT 288
|
||||
#define TK_SOFFSET 289
|
||||
#define TK_LIMIT 290
|
||||
#define TK_OFFSET 291
|
||||
#define TK_ASC 292
|
||||
#define TK_NULLS 293
|
||||
#define TK_ABORT 294
|
||||
#define TK_AFTER 295
|
||||
#define TK_ATTACH 296
|
||||
#define TK_BEFORE 297
|
||||
#define TK_BEGIN 298
|
||||
#define TK_BITAND 299
|
||||
#define TK_BITNOT 300
|
||||
#define TK_BITOR 301
|
||||
#define TK_BLOCKS 302
|
||||
#define TK_CHANGE 303
|
||||
#define TK_COMMA 304
|
||||
#define TK_CONCAT 305
|
||||
#define TK_CONFLICT 306
|
||||
#define TK_COPY 307
|
||||
#define TK_DEFERRED 308
|
||||
#define TK_DELIMITERS 309
|
||||
#define TK_DETACH 310
|
||||
#define TK_DIVIDE 311
|
||||
#define TK_DOT 312
|
||||
#define TK_EACH 313
|
||||
#define TK_FAIL 314
|
||||
#define TK_FILE 315
|
||||
#define TK_FOR 316
|
||||
#define TK_GLOB 317
|
||||
#define TK_ID 318
|
||||
#define TK_IMMEDIATE 319
|
||||
#define TK_IMPORT 320
|
||||
#define TK_INITIALLY 321
|
||||
#define TK_INSTEAD 322
|
||||
#define TK_ISNULL 323
|
||||
#define TK_KEY 324
|
||||
#define TK_MODULES 325
|
||||
#define TK_NK_BITNOT 326
|
||||
#define TK_NK_SEMI 327
|
||||
#define TK_NOTNULL 328
|
||||
#define TK_OF 329
|
||||
#define TK_PLUS 330
|
||||
#define TK_PRIVILEGE 331
|
||||
#define TK_RAISE 332
|
||||
#define TK_RESTRICT 333
|
||||
#define TK_ROW 334
|
||||
#define TK_SEMI 335
|
||||
#define TK_STAR 336
|
||||
#define TK_STATEMENT 337
|
||||
#define TK_STRICT 338
|
||||
#define TK_STRING 339
|
||||
#define TK_TIMES 340
|
||||
#define TK_VALUES 341
|
||||
#define TK_VARIABLE 342
|
||||
#define TK_VIEW 343
|
||||
#define TK_WAL 344
|
||||
#define TK_VIEWS 171
|
||||
#define TK_VIEW 172
|
||||
#define TK_NORMAL 173
|
||||
#define TK_CHILD 174
|
||||
#define TK_LIKE 175
|
||||
#define TK_TBNAME 176
|
||||
#define TK_QTAGS 177
|
||||
#define TK_AS 178
|
||||
#define TK_SYSTEM 179
|
||||
#define TK_INDEX 180
|
||||
#define TK_FUNCTION 181
|
||||
#define TK_INTERVAL 182
|
||||
#define TK_COUNT 183
|
||||
#define TK_LAST_ROW 184
|
||||
#define TK_META 185
|
||||
#define TK_ONLY 186
|
||||
#define TK_TOPIC 187
|
||||
#define TK_CONSUMER 188
|
||||
#define TK_GROUP 189
|
||||
#define TK_DESC 190
|
||||
#define TK_DESCRIBE 191
|
||||
#define TK_RESET 192
|
||||
#define TK_QUERY 193
|
||||
#define TK_CACHE 194
|
||||
#define TK_EXPLAIN 195
|
||||
#define TK_ANALYZE 196
|
||||
#define TK_VERBOSE 197
|
||||
#define TK_NK_BOOL 198
|
||||
#define TK_RATIO 199
|
||||
#define TK_NK_FLOAT 200
|
||||
#define TK_OUTPUTTYPE 201
|
||||
#define TK_AGGREGATE 202
|
||||
#define TK_BUFSIZE 203
|
||||
#define TK_LANGUAGE 204
|
||||
#define TK_REPLACE 205
|
||||
#define TK_STREAM 206
|
||||
#define TK_INTO 207
|
||||
#define TK_PAUSE 208
|
||||
#define TK_RESUME 209
|
||||
#define TK_TRIGGER 210
|
||||
#define TK_AT_ONCE 211
|
||||
#define TK_WINDOW_CLOSE 212
|
||||
#define TK_IGNORE 213
|
||||
#define TK_EXPIRED 214
|
||||
#define TK_FILL_HISTORY 215
|
||||
#define TK_UPDATE 216
|
||||
#define TK_SUBTABLE 217
|
||||
#define TK_UNTREATED 218
|
||||
#define TK_KILL 219
|
||||
#define TK_CONNECTION 220
|
||||
#define TK_TRANSACTION 221
|
||||
#define TK_BALANCE 222
|
||||
#define TK_VGROUP 223
|
||||
#define TK_LEADER 224
|
||||
#define TK_MERGE 225
|
||||
#define TK_REDISTRIBUTE 226
|
||||
#define TK_SPLIT 227
|
||||
#define TK_DELETE 228
|
||||
#define TK_INSERT 229
|
||||
#define TK_NULL 230
|
||||
#define TK_NK_QUESTION 231
|
||||
#define TK_NK_ALIAS 232
|
||||
#define TK_NK_ARROW 233
|
||||
#define TK_ROWTS 234
|
||||
#define TK_QSTART 235
|
||||
#define TK_QEND 236
|
||||
#define TK_QDURATION 237
|
||||
#define TK_WSTART 238
|
||||
#define TK_WEND 239
|
||||
#define TK_WDURATION 240
|
||||
#define TK_IROWTS 241
|
||||
#define TK_ISFILLED 242
|
||||
#define TK_CAST 243
|
||||
#define TK_NOW 244
|
||||
#define TK_TODAY 245
|
||||
#define TK_TIMEZONE 246
|
||||
#define TK_CLIENT_VERSION 247
|
||||
#define TK_SERVER_VERSION 248
|
||||
#define TK_SERVER_STATUS 249
|
||||
#define TK_CURRENT_USER 250
|
||||
#define TK_CASE 251
|
||||
#define TK_WHEN 252
|
||||
#define TK_THEN 253
|
||||
#define TK_ELSE 254
|
||||
#define TK_BETWEEN 255
|
||||
#define TK_IS 256
|
||||
#define TK_NK_LT 257
|
||||
#define TK_NK_GT 258
|
||||
#define TK_NK_LE 259
|
||||
#define TK_NK_GE 260
|
||||
#define TK_NK_NE 261
|
||||
#define TK_MATCH 262
|
||||
#define TK_NMATCH 263
|
||||
#define TK_CONTAINS 264
|
||||
#define TK_IN 265
|
||||
#define TK_JOIN 266
|
||||
#define TK_INNER 267
|
||||
#define TK_SELECT 268
|
||||
#define TK_NK_HINT 269
|
||||
#define TK_DISTINCT 270
|
||||
#define TK_WHERE 271
|
||||
#define TK_PARTITION 272
|
||||
#define TK_BY 273
|
||||
#define TK_SESSION 274
|
||||
#define TK_STATE_WINDOW 275
|
||||
#define TK_EVENT_WINDOW 276
|
||||
#define TK_SLIDING 277
|
||||
#define TK_FILL 278
|
||||
#define TK_VALUE 279
|
||||
#define TK_VALUE_F 280
|
||||
#define TK_NONE 281
|
||||
#define TK_PREV 282
|
||||
#define TK_NULL_F 283
|
||||
#define TK_LINEAR 284
|
||||
#define TK_NEXT 285
|
||||
#define TK_HAVING 286
|
||||
#define TK_RANGE 287
|
||||
#define TK_EVERY 288
|
||||
#define TK_ORDER 289
|
||||
#define TK_SLIMIT 290
|
||||
#define TK_SOFFSET 291
|
||||
#define TK_LIMIT 292
|
||||
#define TK_OFFSET 293
|
||||
#define TK_ASC 294
|
||||
#define TK_NULLS 295
|
||||
#define TK_ABORT 296
|
||||
#define TK_AFTER 297
|
||||
#define TK_ATTACH 298
|
||||
#define TK_BEFORE 299
|
||||
#define TK_BEGIN 300
|
||||
#define TK_BITAND 301
|
||||
#define TK_BITNOT 302
|
||||
#define TK_BITOR 303
|
||||
#define TK_BLOCKS 304
|
||||
#define TK_CHANGE 305
|
||||
#define TK_COMMA 306
|
||||
#define TK_CONCAT 307
|
||||
#define TK_CONFLICT 308
|
||||
#define TK_COPY 309
|
||||
#define TK_DEFERRED 310
|
||||
#define TK_DELIMITERS 311
|
||||
#define TK_DETACH 312
|
||||
#define TK_DIVIDE 313
|
||||
#define TK_DOT 314
|
||||
#define TK_EACH 315
|
||||
#define TK_FAIL 316
|
||||
#define TK_FILE 317
|
||||
#define TK_FOR 318
|
||||
#define TK_GLOB 319
|
||||
#define TK_ID 320
|
||||
#define TK_IMMEDIATE 321
|
||||
#define TK_IMPORT 322
|
||||
#define TK_INITIALLY 323
|
||||
#define TK_INSTEAD 324
|
||||
#define TK_ISNULL 325
|
||||
#define TK_KEY 326
|
||||
#define TK_MODULES 327
|
||||
#define TK_NK_BITNOT 328
|
||||
#define TK_NK_SEMI 329
|
||||
#define TK_NOTNULL 330
|
||||
#define TK_OF 331
|
||||
#define TK_PLUS 332
|
||||
#define TK_PRIVILEGE 333
|
||||
#define TK_RAISE 334
|
||||
#define TK_RESTRICT 335
|
||||
#define TK_ROW 336
|
||||
#define TK_SEMI 337
|
||||
#define TK_STAR 338
|
||||
#define TK_STATEMENT 339
|
||||
#define TK_STRICT 340
|
||||
#define TK_STRING 341
|
||||
#define TK_TIMES 342
|
||||
#define TK_VALUES 343
|
||||
#define TK_VARIABLE 344
|
||||
#define TK_WAL 345
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -37,13 +37,16 @@ enum {
|
|||
CTG_DBG_DB_NUM = 1,
|
||||
CTG_DBG_META_NUM,
|
||||
CTG_DBG_STB_NUM,
|
||||
CTG_DBG_VIEW_NUM,
|
||||
CTG_DBG_DB_RENT_NUM,
|
||||
CTG_DBG_STB_RENT_NUM,
|
||||
CTG_DBG_VIEW_RENT_NUM,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
AUTH_TYPE_READ = 1,
|
||||
AUTH_TYPE_WRITE,
|
||||
AUTH_TYPE_ALTER,
|
||||
AUTH_TYPE_OTHER,
|
||||
AUTH_TYPE_READ_OR_WRITE,
|
||||
} AUTH_TYPE;
|
||||
|
@ -51,12 +54,19 @@ typedef enum {
|
|||
typedef struct SUserAuthInfo {
|
||||
char user[TSDB_USER_LEN];
|
||||
SName tbName;
|
||||
bool isView;
|
||||
AUTH_TYPE type;
|
||||
} SUserAuthInfo;
|
||||
|
||||
typedef enum {
|
||||
AUTH_RES_BASIC = 0,
|
||||
AUTH_RES_VIEW,
|
||||
AUTH_RES_MAX_VALUE
|
||||
} AUTH_RES_TYPE;
|
||||
|
||||
typedef struct SUserAuthRes {
|
||||
bool pass;
|
||||
SNode* pCond;
|
||||
bool pass[AUTH_RES_MAX_VALUE];
|
||||
SNode* pCond[AUTH_RES_MAX_VALUE];
|
||||
} SUserAuthRes;
|
||||
|
||||
typedef struct SDbInfo {
|
||||
|
@ -83,6 +93,7 @@ typedef struct SCatalogReq {
|
|||
SArray* pTableIndex; // element is SNAME
|
||||
SArray* pTableCfg; // element is SNAME
|
||||
SArray* pTableTag; // element is SNAME
|
||||
SArray* pView; // element is STablesReq
|
||||
bool qNodeRequired; // valid qnode
|
||||
bool dNodeRequired; // valid dnode
|
||||
bool svrVerRequired;
|
||||
|
@ -96,6 +107,7 @@ typedef struct SMetaRes {
|
|||
} SMetaRes;
|
||||
|
||||
typedef struct SMetaData {
|
||||
bool ctgFree; // need to freed by catalog module
|
||||
SArray* pDbVgroup; // pRes = SArray<SVgroupInfo>*
|
||||
SArray* pDbCfg; // pRes = SDbCfgInfo*
|
||||
SArray* pDbInfo; // pRes = SDbInfo*
|
||||
|
@ -109,21 +121,24 @@ typedef struct SMetaData {
|
|||
SArray* pTableCfg; // pRes = STableCfg*
|
||||
SArray* pTableTag; // pRes = SArray<STagVal>*
|
||||
SArray* pDnodeList; // pRes = SArray<SEpSet>*
|
||||
SArray* pView; // pRes = SViewMeta*
|
||||
SMetaRes* pSvrVer; // pRes = char*
|
||||
} SMetaData;
|
||||
|
||||
typedef struct SCatalogCfg {
|
||||
uint32_t maxTblCacheNum;
|
||||
uint32_t maxViewCacheNum;
|
||||
uint32_t maxDBCacheNum;
|
||||
uint32_t maxUserCacheNum;
|
||||
uint32_t dbRentSec;
|
||||
uint32_t stbRentSec;
|
||||
uint32_t viewRentSec;
|
||||
} SCatalogCfg;
|
||||
|
||||
typedef struct SSTableVersion {
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
char stbName[TSDB_TABLE_NAME_LEN];
|
||||
uint64_t dbId;
|
||||
int64_t dbId;
|
||||
uint64_t suid;
|
||||
int32_t sversion;
|
||||
int32_t tversion;
|
||||
|
@ -139,6 +154,20 @@ typedef struct SDbCacheInfo {
|
|||
int64_t stateTs;
|
||||
} SDbCacheInfo;
|
||||
|
||||
typedef struct SDynViewVersion {
|
||||
int64_t svrBootTs;
|
||||
uint64_t dynViewVer;
|
||||
} SDynViewVersion;
|
||||
|
||||
typedef struct SViewVersion {
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
char viewName[TSDB_VIEW_NAME_LEN];
|
||||
int64_t dbId;
|
||||
uint64_t viewId;
|
||||
int32_t version;
|
||||
} SViewVersion;
|
||||
|
||||
|
||||
typedef struct STbSVersion {
|
||||
char* tbFName;
|
||||
int32_t sver;
|
||||
|
@ -307,6 +336,8 @@ int32_t catalogGetDnodeList(SCatalog* pCatalog, SRequestConnInfo* pConn, SArray*
|
|||
|
||||
int32_t catalogGetExpiredSTables(SCatalog* pCatalog, SSTableVersion** stables, uint32_t* num);
|
||||
|
||||
int32_t catalogGetExpiredViews(SCatalog* pCtg, SViewVersion** views, uint32_t* num, SDynViewVersion** dynViewVersion);
|
||||
|
||||
int32_t catalogGetExpiredDBs(SCatalog* pCatalog, SDbCacheInfo** dbs, uint32_t* num);
|
||||
|
||||
int32_t catalogGetExpiredUsers(SCatalog* pCtg, SUserAuthVersion** users, uint32_t* num);
|
||||
|
@ -343,6 +374,16 @@ SMetaData* catalogCloneMetaData(SMetaData* pData);
|
|||
|
||||
void catalogFreeMetaData(SMetaData* pData);
|
||||
|
||||
int32_t catalogRemoveViewMeta(SCatalog* pCtg, const char* dbFName, uint64_t dbId, const char* viewName, uint64_t viewId);
|
||||
|
||||
int32_t catalogUpdateDynViewVer(SCatalog* pCtg, SDynViewVersion* pVer);
|
||||
|
||||
int32_t catalogUpdateViewMeta(SCatalog* pCtg, SViewMetaRsp* pMsg);
|
||||
|
||||
int32_t catalogAsyncUpdateViewMeta(SCatalog* pCtg, SViewMetaRsp* pMsg);
|
||||
|
||||
int32_t catalogGetViewMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pViewName, STableMeta** pTableMeta);
|
||||
|
||||
int32_t ctgdEnableDebug(char* option, bool enable);
|
||||
|
||||
int32_t ctgdHandleDbgCommand(char* command);
|
||||
|
|
|
@ -26,7 +26,7 @@ extern "C" {
|
|||
#define DESCRIBE_RESULT_COLS 4
|
||||
#define DESCRIBE_RESULT_FIELD_LEN (TSDB_COL_NAME_LEN - 1 + VARSTR_HEADER_SIZE)
|
||||
#define DESCRIBE_RESULT_TYPE_LEN (20 + VARSTR_HEADER_SIZE)
|
||||
#define DESCRIBE_RESULT_NOTE_LEN (8 + VARSTR_HEADER_SIZE)
|
||||
#define DESCRIBE_RESULT_NOTE_LEN (16 + VARSTR_HEADER_SIZE)
|
||||
|
||||
#define SHOW_CREATE_DB_RESULT_COLS 2
|
||||
#define SHOW_CREATE_DB_RESULT_FIELD1_LEN (TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE)
|
||||
|
@ -36,6 +36,11 @@ extern "C" {
|
|||
#define SHOW_CREATE_TB_RESULT_FIELD1_LEN (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE)
|
||||
#define SHOW_CREATE_TB_RESULT_FIELD2_LEN (TSDB_MAX_ALLOWED_SQL_LEN * 3)
|
||||
|
||||
#define SHOW_CREATE_VIEW_RESULT_COLS 2
|
||||
#define SHOW_CREATE_VIEW_RESULT_FIELD1_LEN (TSDB_VIEW_FNAME_LEN + 4 + VARSTR_HEADER_SIZE)
|
||||
#define SHOW_CREATE_VIEW_RESULT_FIELD2_LEN (TSDB_MAX_ALLOWED_SQL_LEN + VARSTR_HEADER_SIZE)
|
||||
|
||||
|
||||
#define SHOW_LOCAL_VARIABLES_RESULT_COLS 3
|
||||
#define SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN (TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE)
|
||||
#define SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN (TSDB_CONFIG_VALUE_LEN + VARSTR_HEADER_SIZE)
|
||||
|
@ -51,6 +56,7 @@ extern "C" {
|
|||
#define PRIVILEGE_TYPE_READ BIT_FLAG_MASK(1)
|
||||
#define PRIVILEGE_TYPE_WRITE BIT_FLAG_MASK(2)
|
||||
#define PRIVILEGE_TYPE_SUBSCRIBE BIT_FLAG_MASK(3)
|
||||
#define PRIVILEGE_TYPE_ALTER BIT_FLAG_MASK(4)
|
||||
|
||||
typedef struct SDatabaseOptions {
|
||||
ENodeType type;
|
||||
|
@ -297,6 +303,13 @@ typedef struct SShowCreateTableStmt {
|
|||
void* pTableCfg; // STableCfg
|
||||
} SShowCreateTableStmt;
|
||||
|
||||
typedef struct SShowCreateViewStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char viewName[TSDB_VIEW_NAME_LEN];
|
||||
void* pViewMeta;
|
||||
} SShowCreateViewStmt;
|
||||
|
||||
typedef struct SShowTableDistributedStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
|
@ -490,6 +503,23 @@ typedef struct SDropFunctionStmt {
|
|||
bool ignoreNotExists;
|
||||
} SDropFunctionStmt;
|
||||
|
||||
typedef struct SCreateViewStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char viewName[TSDB_VIEW_NAME_LEN];
|
||||
char* pQuerySql;
|
||||
bool orReplace;
|
||||
SNode* pQuery;
|
||||
SCMCreateViewReq createReq;
|
||||
} SCreateViewStmt;
|
||||
|
||||
typedef struct SDropViewStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char viewName[TSDB_VIEW_NAME_LEN];
|
||||
bool ignoreNotExists;
|
||||
} SDropViewStmt;
|
||||
|
||||
typedef struct SGrantStmt {
|
||||
ENodeType type;
|
||||
char userName[TSDB_USER_LEN];
|
||||
|
|
|
@ -30,6 +30,11 @@ extern "C" {
|
|||
#define VGROUPS_INFO_SIZE(pInfo) \
|
||||
(NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
|
||||
|
||||
typedef struct SAssociationNode {
|
||||
SNode** pPlace;
|
||||
SNode* pAssociationNode;
|
||||
} SAssociationNode;
|
||||
|
||||
typedef struct SRawExprNode {
|
||||
ENodeType nodeType;
|
||||
char* p;
|
||||
|
@ -182,6 +187,16 @@ typedef struct STempTableNode {
|
|||
SNode* pSubquery;
|
||||
} STempTableNode;
|
||||
|
||||
typedef struct SViewNode {
|
||||
STableNode table; // QUERY_NODE_REAL_TABLE
|
||||
struct STableMeta* pMeta;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
char qualDbName[TSDB_DB_NAME_LEN]; // SHOW qualDbName.TABLES
|
||||
double ratio;
|
||||
SArray* pSmaIndexes;
|
||||
int8_t cacheLastMode;
|
||||
} SViewNode;
|
||||
|
||||
typedef enum EJoinType {
|
||||
JOIN_TYPE_INNER = 1,
|
||||
JOIN_TYPE_LEFT,
|
||||
|
|
|
@ -22,9 +22,7 @@ extern "C" {
|
|||
|
||||
#include "query.h"
|
||||
#include "querynodes.h"
|
||||
|
||||
struct SCatalogReq;
|
||||
struct SMetaData;
|
||||
#include "catalog.h"
|
||||
|
||||
typedef struct SStmtCallback {
|
||||
TAOS_STMT* pStmt;
|
||||
|
@ -33,6 +31,33 @@ typedef struct SStmtCallback {
|
|||
int32_t (*getExecInfoFn)(TAOS_STMT*, SHashObj**, SHashObj**);
|
||||
} SStmtCallback;
|
||||
|
||||
typedef enum {
|
||||
PARSE_SQL_RES_QUERY = 1,
|
||||
PARSE_SQL_RES_SCHEMA,
|
||||
} SParseResType;
|
||||
|
||||
typedef struct SParseSchemaRes {
|
||||
int8_t precision;
|
||||
int32_t numOfCols;
|
||||
SSchema* pSchema;
|
||||
} SParseSchemaRes;
|
||||
|
||||
typedef struct SParseQueryRes {
|
||||
SNode* pQuery;
|
||||
SCatalogReq* pCatalogReq;
|
||||
SMetaData meta;
|
||||
} SParseQueryRes;
|
||||
|
||||
typedef struct SParseSqlRes {
|
||||
SParseResType resType;
|
||||
union {
|
||||
SParseSchemaRes schemaRes;
|
||||
SParseQueryRes queryRes;
|
||||
};
|
||||
} SParseSqlRes;
|
||||
|
||||
typedef int32_t (*parseSqlFn)(void*, const char*, const char*, bool, const char*, SParseSqlRes*);
|
||||
|
||||
typedef struct SParseCsvCxt {
|
||||
TdFilePtr fp; // last parsed file
|
||||
int32_t tableNo; // last parsed table
|
||||
|
@ -55,6 +80,8 @@ typedef struct SParseContext {
|
|||
struct SCatalog* pCatalog;
|
||||
SStmtCallback* pStmtCb;
|
||||
const char* pUser;
|
||||
const char* pEffectiveUser;
|
||||
bool parseOnly;
|
||||
bool isSuperUser;
|
||||
bool enableSysInfo;
|
||||
bool async;
|
||||
|
@ -64,7 +91,10 @@ typedef struct SParseContext {
|
|||
SArray* pTableMetaPos; // sql table pos => catalog data pos
|
||||
SArray* pTableVgroupPos; // sql table pos => catalog data pos
|
||||
int64_t allocatorId;
|
||||
parseSqlFn parseSqlFp;
|
||||
void* parseSqlParam;
|
||||
int8_t biMode;
|
||||
SArray* pSubMetaList;
|
||||
} SParseContext;
|
||||
|
||||
int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery);
|
||||
|
@ -125,6 +155,8 @@ int rawBlockBindData(SQuery *query, STableMeta* pTableMeta, void* data, SVCr
|
|||
int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray);
|
||||
SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap);
|
||||
SArray* serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap);
|
||||
void destoryCatalogReq(SCatalogReq *pCatalogReq);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -119,6 +119,17 @@ typedef struct STableMeta {
|
|||
} STableMeta;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct SViewMeta {
|
||||
uint64_t viewId;
|
||||
char* user;
|
||||
char* querySql;
|
||||
int8_t precision;
|
||||
int8_t type;
|
||||
int32_t version;
|
||||
int32_t numOfCols;
|
||||
SSchema* pSchema;
|
||||
} SViewMeta;
|
||||
|
||||
typedef struct SDBVgInfo {
|
||||
int32_t vgVersion;
|
||||
int16_t hashPrefix;
|
||||
|
@ -148,6 +159,15 @@ typedef struct STableMetaOutput {
|
|||
STableMeta* tbMeta;
|
||||
} STableMetaOutput;
|
||||
|
||||
typedef struct SViewMetaOutput {
|
||||
char name[TSDB_VIEW_NAME_LEN];
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
char* querySql;
|
||||
int8_t precision;
|
||||
int32_t numOfCols;
|
||||
SSchema* pSchema;
|
||||
} SViewMetaOutput;
|
||||
|
||||
typedef struct SDataBuf {
|
||||
int32_t msgType;
|
||||
void* pData;
|
||||
|
@ -300,9 +320,11 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
|
|||
(NO_RET_REDIRECT_ERROR(_code) || SYNC_UNKNOWN_LEADER_REDIRECT_ERROR(_code) || \
|
||||
SYNC_SELF_LEADER_REDIRECT_ERROR(_code) || SYNC_OTHER_LEADER_REDIRECT_ERROR(_code))
|
||||
|
||||
#define IS_VIEW_REQUEST(_type) ((_type) == TDMT_MND_CREATE_VIEW || (_type) == TDMT_MND_DROP_VIEW)
|
||||
|
||||
#define NEED_CLIENT_RM_TBLMETA_REQ(_type) \
|
||||
((_type) == TDMT_VND_CREATE_TABLE || (_type) == TDMT_MND_CREATE_STB || (_type) == TDMT_VND_DROP_TABLE || \
|
||||
(_type) == TDMT_MND_DROP_STB)
|
||||
(_type) == TDMT_MND_DROP_STB || (_type) == TDMT_MND_CREATE_VIEW || (_type) == TDMT_MND_DROP_VIEW)
|
||||
|
||||
#define NEED_SCHEDULER_REDIRECT_ERROR(_code) \
|
||||
(SYNC_UNKNOWN_LEADER_REDIRECT_ERROR(_code) || SYNC_SELF_LEADER_REDIRECT_ERROR(_code) || \
|
||||
|
|
|
@ -384,15 +384,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_TOO_MANY_STREAMS TAOS_DEF_ERROR_CODE(0, 0x03F6)
|
||||
#define TSDB_CODE_MND_INVALID_TARGET_TABLE TAOS_DEF_ERROR_CODE(0, 0x03F7)
|
||||
|
||||
// mnode-sma
|
||||
#define TSDB_CODE_MND_SMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0480)
|
||||
#define TSDB_CODE_MND_SMA_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0481)
|
||||
#define TSDB_CODE_MND_INVALID_SMA_OPTION TAOS_DEF_ERROR_CODE(0, 0x0482)
|
||||
|
||||
// mnode-tag-indxe
|
||||
|
||||
#define TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0483)
|
||||
#define TSDB_CODE_MND_TAG_INDEX_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0484)
|
||||
|
||||
// dnode
|
||||
// #define TSDB_CODE_DND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0400) // 2.x
|
||||
|
@ -419,6 +411,22 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MNODE_NO_NEED_RESTORE TAOS_DEF_ERROR_CODE(0, 0x0415) // internal
|
||||
#define TSDB_CODE_DNODE_ONLY_USE_WHEN_OFFLINE TAOS_DEF_ERROR_CODE(0, 0x0416)
|
||||
|
||||
// mnode-sma
|
||||
#define TSDB_CODE_MND_SMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0480)
|
||||
#define TSDB_CODE_MND_SMA_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0481)
|
||||
#define TSDB_CODE_MND_INVALID_SMA_OPTION TAOS_DEF_ERROR_CODE(0, 0x0482)
|
||||
|
||||
// mnode-tag-indxe
|
||||
|
||||
#define TSDB_CODE_MND_TAG_INDEX_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0483)
|
||||
#define TSDB_CODE_MND_TAG_INDEX_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0484)
|
||||
|
||||
|
||||
// mnode-view
|
||||
#define TSDB_CODE_MND_VIEW_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x04A0)
|
||||
#define TSDB_CODE_MND_VIEW_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x04A1)
|
||||
|
||||
|
||||
// vnode
|
||||
// #define TSDB_CODE_VND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0500) // 2.x
|
||||
// #define TSDB_CODE_VND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0501) // 2.x
|
||||
|
@ -726,6 +734,9 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED TAOS_DEF_ERROR_CODE(0, 0x2669)
|
||||
#define TSDB_CODE_PAR_INVALID_VARBINARY TAOS_DEF_ERROR_CODE(0, 0x266A)
|
||||
#define TSDB_CODE_PAR_INVALID_IP_RANGE TAOS_DEF_ERROR_CODE(0, 0x266B)
|
||||
#define TSDB_CODE_PAR_INVALID_VIEW_QUERY TAOS_DEF_ERROR_CODE(0, 0x266C)
|
||||
#define TSDB_CODE_PAR_COL_QUERY_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x266D)
|
||||
#define TSDB_CODE_PAR_VIEW_CONFLICT_WITH_TABLE TAOS_DEF_ERROR_CODE(0, 0x266E)
|
||||
#define TSDB_CODE_PAR_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x26FF)
|
||||
|
||||
//planner
|
||||
|
|
|
@ -240,6 +240,9 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_MAX_SQL_SHOW_LEN 1024
|
||||
#define TSDB_MAX_ALLOWED_SQL_LEN (1 * 1024 * 1024u) // sql length should be less than 1mb
|
||||
|
||||
#define TSDB_VIEW_NAME_LEN 193
|
||||
#define TSDB_VIEW_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_VIEW_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
|
||||
#define TSDB_APP_NAME_LEN TSDB_UNI_LEN
|
||||
#define TSDB_TB_COMMENT_LEN 1025
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
aux_source_directory(src CLIENT_SRC)
|
||||
|
||||
IF (TD_ENTERPRISE)
|
||||
LIST(APPEND CLIENT_SRC ${TD_ENTERPRISE_DIR}/src/plugins/view/src/clientView.c)
|
||||
ENDIF ()
|
||||
|
||||
if(TD_WINDOWS)
|
||||
add_library(taos SHARED ${CLIENT_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/src/taos.rc.in)
|
||||
else()
|
||||
|
|
|
@ -269,6 +269,7 @@ typedef struct SRequestObj {
|
|||
bool syncQuery; // todo refactor: async query object
|
||||
bool stableQuery; // todo refactor
|
||||
bool validateOnly; // todo refactor
|
||||
bool parseOnly;
|
||||
bool killed;
|
||||
bool inRetry;
|
||||
bool isSubReq;
|
||||
|
@ -279,6 +280,8 @@ typedef struct SRequestObj {
|
|||
void* pPostPlan;
|
||||
SReqRelInfo relation;
|
||||
void* pWrapper;
|
||||
SMetaData parseMeta;
|
||||
char* effectiveUser;
|
||||
} SRequestObj;
|
||||
|
||||
typedef struct SSyncQueryParam {
|
||||
|
@ -305,6 +308,8 @@ void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp,
|
|||
void taosAsyncQueryImplWithReqid(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly,
|
||||
int64_t reqid);
|
||||
void taosAsyncFetchImpl(SRequestObj *pRequest, __taos_async_fn_t fp, void *param);
|
||||
int32_t clientParseSql(void* param, const char* dbName, const char* sql, bool parseOnly, const char* effectiveUser, SParseSqlRes* pRes);
|
||||
void syncQueryFn(void* param, void* res, int32_t code);
|
||||
|
||||
int32_t getVersion1BlockMetaSize(const char* p, int32_t numOfCols);
|
||||
|
||||
|
@ -403,7 +408,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResu
|
|||
int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest);
|
||||
int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList);
|
||||
void doAsyncQuery(SRequestObj* pRequest, bool forceUpdateMeta);
|
||||
int32_t removeMeta(STscObj* pTscObj, SArray* tbList);
|
||||
int32_t removeMeta(STscObj* pTscObj, SArray* tbList, bool isView);
|
||||
int32_t handleAlterTbExecRes(void* res, struct SCatalog* pCatalog);
|
||||
int32_t handleCreateTbExecRes(void* res, SCatalog* pCatalog);
|
||||
bool qnodeRequired(SRequestObj* pRequest);
|
||||
|
@ -415,6 +420,11 @@ int32_t buildPreviousRequest(SRequestObj *pRequest, const char* sql, SRequestObj
|
|||
int32_t prepareAndParseSqlSyntax(SSqlCallbackWrapper **ppWrapper, SRequestObj *pRequest, bool updateMetaForce);
|
||||
void returnToUser(SRequestObj* pRequest);
|
||||
void stopAllQueries(SRequestObj *pRequest);
|
||||
void freeQueryParam(SSyncQueryParam* param);
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
int32_t clientParseSqlImpl(void* param, const char* dbName, const char* sql, bool parseOnly, const char* effeciveUser, SParseSqlRes* pRes);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -447,6 +447,7 @@ void doDestroyRequest(void *p) {
|
|||
qDestroyQuery(pRequest->pQuery);
|
||||
nodesDestroyAllocator(pRequest->allocatorRefId);
|
||||
|
||||
taosMemoryFreeClear(pRequest->effectiveUser);
|
||||
taosMemoryFreeClear(pRequest->sqlstr);
|
||||
taosMemoryFree(pRequest);
|
||||
tscTrace("end to destroy request %" PRIx64 " p:%p", reqId, pRequest);
|
||||
|
|
|
@ -53,7 +53,7 @@ static int32_t hbProcessUserAuthInfoRsp(void *value, int32_t valueLen, struct SC
|
|||
int32_t numOfBatchs = taosArrayGetSize(batchRsp.pArray);
|
||||
for (int32_t i = 0; i < numOfBatchs; ++i) {
|
||||
SGetUserAuthRsp *rsp = taosArrayGet(batchRsp.pArray, i);
|
||||
tscDebug("hb user auth rsp, user:%s, version:%d", rsp->user, rsp->version);
|
||||
tscDebug("hb to update user auth, user:%s, version:%d", rsp->user, rsp->version);
|
||||
|
||||
catalogUpdateUserAuthInfo(pCatalog, rsp);
|
||||
}
|
||||
|
@ -205,6 +205,7 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog
|
|||
rsp->useDbRsp->db, rsp->useDbRsp->vgVersion, rsp->useDbRsp->stateTs, rsp->useDbRsp->uid);
|
||||
|
||||
if (rsp->useDbRsp->vgVersion < 0) {
|
||||
tscDebug("hb to remove db, db:%s", rsp->useDbRsp->db);
|
||||
code = catalogRemoveDB(pCatalog, rsp->useDbRsp->db, rsp->useDbRsp->uid);
|
||||
} else {
|
||||
SDBVgInfo *vgInfo = NULL;
|
||||
|
@ -213,6 +214,8 @@ static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog
|
|||
goto _return;
|
||||
}
|
||||
|
||||
tscDebug("hb to update db vgInfo, db:%s", rsp->useDbRsp->db);
|
||||
|
||||
catalogUpdateDBVgInfo(pCatalog, rsp->useDbRsp->db, rsp->useDbRsp->uid, vgInfo);
|
||||
|
||||
if (IS_SYS_DBNAME(rsp->useDbRsp->db)) {
|
||||
|
@ -253,10 +256,10 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
|
|||
STableMetaRsp *rsp = taosArrayGet(hbRsp.pMetaRsp, i);
|
||||
|
||||
if (rsp->numOfColumns < 0) {
|
||||
tscDebug("hb remove stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
|
||||
tscDebug("hb to remove stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
|
||||
catalogRemoveStbMeta(pCatalog, rsp->dbFName, rsp->dbId, rsp->stbName, rsp->suid);
|
||||
} else {
|
||||
tscDebug("hb update stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
|
||||
tscDebug("hb to update stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
|
||||
if (rsp->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
tscError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", rsp->pSchemas[0].colId);
|
||||
tFreeSSTbHbRsp(&hbRsp);
|
||||
|
@ -281,6 +284,108 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t hbProcessDynViewRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
|
||||
return catalogUpdateDynViewVer(pCatalog, (SDynViewVersion*)value);
|
||||
}
|
||||
|
||||
static void hbFreeSViewMetaInRsp(void* p) {
|
||||
if (NULL == p || NULL == *(void**)p) {
|
||||
return;
|
||||
}
|
||||
SViewMetaRsp *pRsp = *(SViewMetaRsp**)p;
|
||||
tFreeSViewMetaRsp(pRsp);
|
||||
taosMemoryFreeClear(pRsp);
|
||||
}
|
||||
|
||||
static int32_t hbProcessViewInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
|
||||
int32_t code = 0;
|
||||
|
||||
SViewHbRsp hbRsp = {0};
|
||||
if (tDeserializeSViewHbRsp(value, valueLen, &hbRsp) != 0) {
|
||||
taosArrayDestroyEx(hbRsp.pViewRsp, hbFreeSViewMetaInRsp);
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t numOfMeta = taosArrayGetSize(hbRsp.pViewRsp);
|
||||
for (int32_t i = 0; i < numOfMeta; ++i) {
|
||||
SViewMetaRsp *rsp = taosArrayGetP(hbRsp.pViewRsp, i);
|
||||
|
||||
if (rsp->numOfCols < 0) {
|
||||
tscDebug("hb to remove view, db:%s, view:%s", rsp->dbFName, rsp->name);
|
||||
catalogRemoveViewMeta(pCatalog, rsp->dbFName, rsp->dbId, rsp->name, rsp->viewId);
|
||||
tFreeSViewMetaRsp(rsp);
|
||||
taosMemoryFreeClear(rsp);
|
||||
} else {
|
||||
tscDebug("hb to update view, db:%s, view:%s", rsp->dbFName, rsp->name);
|
||||
catalogUpdateViewMeta(pCatalog, rsp);
|
||||
}
|
||||
}
|
||||
|
||||
taosArrayDestroy(hbRsp.pViewRsp);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static void hbProcessQueryRspKvs(int32_t kvNum, SArray* pKvs, struct SCatalog *pCatalog, SAppHbMgr *pAppHbMgr) {
|
||||
for (int32_t i = 0; i < kvNum; ++i) {
|
||||
SKv *kv = taosArrayGet(pKvs, i);
|
||||
switch (kv->key) {
|
||||
case HEARTBEAT_KEY_USER_AUTHINFO: {
|
||||
if (kv->valueLen <= 0 || NULL == kv->value) {
|
||||
tscError("invalid hb user auth info, len:%d, value:%p", kv->valueLen, kv->value);
|
||||
break;
|
||||
}
|
||||
|
||||
hbProcessUserAuthInfoRsp(kv->value, kv->valueLen, pCatalog, pAppHbMgr);
|
||||
break;
|
||||
}
|
||||
case HEARTBEAT_KEY_DBINFO: {
|
||||
if (kv->valueLen <= 0 || NULL == kv->value) {
|
||||
tscError("invalid hb db info, len:%d, value:%p", kv->valueLen, kv->value);
|
||||
break;
|
||||
}
|
||||
|
||||
hbProcessDBInfoRsp(kv->value, kv->valueLen, pCatalog);
|
||||
break;
|
||||
}
|
||||
case HEARTBEAT_KEY_STBINFO: {
|
||||
if (kv->valueLen <= 0 || NULL == kv->value) {
|
||||
tscError("invalid hb stb info, len:%d, value:%p", kv->valueLen, kv->value);
|
||||
break;
|
||||
}
|
||||
|
||||
hbProcessStbInfoRsp(kv->value, kv->valueLen, pCatalog);
|
||||
break;
|
||||
}
|
||||
#ifdef TD_ENTERPRISE
|
||||
case HEARTBEAT_KEY_DYN_VIEW: {
|
||||
if (kv->valueLen <= 0 || NULL == kv->value) {
|
||||
tscError("invalid dyn view info, len:%d, value:%p", kv->valueLen, kv->value);
|
||||
break;
|
||||
}
|
||||
|
||||
hbProcessDynViewRsp(kv->value, kv->valueLen, pCatalog);
|
||||
break;
|
||||
}
|
||||
case HEARTBEAT_KEY_VIEWINFO: {
|
||||
if (kv->valueLen <= 0 || NULL == kv->value) {
|
||||
tscError("invalid view info, len:%d, value:%p", kv->valueLen, kv->value);
|
||||
break;
|
||||
}
|
||||
|
||||
hbProcessViewInfoRsp(kv->value, kv->valueLen, pCatalog);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
tscError("invalid hb key type:%d", kv->key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
||||
SClientHbReq *pReq = taosHashAcquire(pAppHbMgr->activeInfo, &pRsp->connKey, sizeof(SClientHbKey));
|
||||
if (NULL == pReq) {
|
||||
|
@ -338,66 +443,16 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
|||
|
||||
tscDebug("hb got %d rsp kv", kvNum);
|
||||
|
||||
for (int32_t i = 0; i < kvNum; ++i) {
|
||||
SKv *kv = taosArrayGet(pRsp->info, i);
|
||||
switch (kv->key) {
|
||||
case HEARTBEAT_KEY_USER_AUTHINFO: {
|
||||
if (kv->valueLen <= 0 || NULL == kv->value) {
|
||||
tscError("invalid hb user auth info, len:%d, value:%p", kv->valueLen, kv->value);
|
||||
break;
|
||||
}
|
||||
|
||||
struct SCatalog *pCatalog = NULL;
|
||||
|
||||
int32_t code = catalogGetHandle(pReq->clusterId, &pCatalog);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pReq->clusterId, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
|
||||
hbProcessUserAuthInfoRsp(kv->value, kv->valueLen, pCatalog, pAppHbMgr);
|
||||
break;
|
||||
}
|
||||
case HEARTBEAT_KEY_DBINFO: {
|
||||
if (kv->valueLen <= 0 || NULL == kv->value) {
|
||||
tscError("invalid hb db info, len:%d, value:%p", kv->valueLen, kv->value);
|
||||
break;
|
||||
}
|
||||
|
||||
struct SCatalog *pCatalog = NULL;
|
||||
|
||||
int32_t code = catalogGetHandle(pReq->clusterId, &pCatalog);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pReq->clusterId, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
|
||||
hbProcessDBInfoRsp(kv->value, kv->valueLen, pCatalog);
|
||||
break;
|
||||
}
|
||||
case HEARTBEAT_KEY_STBINFO: {
|
||||
if (kv->valueLen <= 0 || NULL == kv->value) {
|
||||
tscError("invalid hb stb info, len:%d, value:%p", kv->valueLen, kv->value);
|
||||
break;
|
||||
}
|
||||
|
||||
struct SCatalog *pCatalog = NULL;
|
||||
|
||||
int32_t code = catalogGetHandle(pReq->clusterId, &pCatalog);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pReq->clusterId, tstrerror(code));
|
||||
break;
|
||||
}
|
||||
|
||||
hbProcessStbInfoRsp(kv->value, kv->valueLen, pCatalog);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
tscError("invalid hb key type:%d", kv->key);
|
||||
break;
|
||||
if (kvNum > 0) {
|
||||
struct SCatalog *pCatalog = NULL;
|
||||
int32_t code = catalogGetHandle(pReq->clusterId, &pCatalog);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pReq->clusterId, tstrerror(code));
|
||||
} else {
|
||||
hbProcessQueryRspKvs(kvNum, pRsp->info, pCatalog, pAppHbMgr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
taosHashRelease(pAppHbMgr->activeInfo, pReq);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -740,8 +795,8 @@ int32_t hbGetExpiredStbInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SC
|
|||
for (int32_t i = 0; i < stbNum; ++i) {
|
||||
SSTableVersion *stb = &stbs[i];
|
||||
stb->suid = htobe64(stb->suid);
|
||||
stb->sversion = htons(stb->sversion);
|
||||
stb->tversion = htons(stb->tversion);
|
||||
stb->sversion = htonl(stb->sversion);
|
||||
stb->tversion = htonl(stb->tversion);
|
||||
stb->smaVer = htonl(stb->smaVer);
|
||||
}
|
||||
|
||||
|
@ -762,6 +817,56 @@ int32_t hbGetExpiredStbInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SC
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t hbGetExpiredViewInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SClientHbReq *req) {
|
||||
SViewVersion *views = NULL;
|
||||
uint32_t viewNum = 0;
|
||||
int32_t code = 0;
|
||||
SDynViewVersion *pDynViewVer = NULL;
|
||||
|
||||
code = catalogGetExpiredViews(pCatalog, &views, &viewNum, &pDynViewVer);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosMemoryFree(views);
|
||||
taosMemoryFree(pDynViewVer);
|
||||
return code;
|
||||
}
|
||||
|
||||
if (viewNum <= 0) {
|
||||
taosMemoryFree(views);
|
||||
taosMemoryFree(pDynViewVer);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < viewNum; ++i) {
|
||||
SViewVersion *view = &views[i];
|
||||
view->dbId = htobe64(view->dbId);
|
||||
view->viewId = htobe64(view->viewId);
|
||||
view->version = htonl(view->version);
|
||||
}
|
||||
|
||||
tscDebug("hb got %d expired view, valueLen:%lu", viewNum, sizeof(SViewVersion) * viewNum);
|
||||
|
||||
if (NULL == req->info) {
|
||||
req->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
|
||||
}
|
||||
|
||||
SKv kv = {
|
||||
.key = HEARTBEAT_KEY_DYN_VIEW,
|
||||
.valueLen = sizeof(SDynViewVersion),
|
||||
.value = pDynViewVer,
|
||||
};
|
||||
|
||||
taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
|
||||
|
||||
kv.key = HEARTBEAT_KEY_VIEWINFO;
|
||||
kv.valueLen = sizeof(SViewVersion) * viewNum;
|
||||
kv.value = views;
|
||||
|
||||
taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t hbGetAppInfo(int64_t clusterId, SClientHbReq *req) {
|
||||
SAppHbReq *pApp = taosHashGet(clientHbMgr.appSummary, &clusterId, sizeof(clusterId));
|
||||
if (NULL != pApp) {
|
||||
|
@ -781,19 +886,17 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req
|
|||
SHbParam *hbParam = (SHbParam *)param;
|
||||
SCatalog *pCatalog = NULL;
|
||||
|
||||
hbGetQueryBasicInfo(connKey, req);
|
||||
|
||||
if (hbParam->reqCnt == 0) {
|
||||
code = catalogGetHandle(hbParam->clusterId, &pCatalog);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
hbGetAppInfo(hbParam->clusterId, req);
|
||||
hbGetAppInfo(hbParam->clusterId, req);
|
||||
|
||||
hbGetQueryBasicInfo(connKey, req);
|
||||
|
||||
if (hbParam->reqCnt == 0) {
|
||||
if (!taosHashGet(clientHbMgr.appHbHash, &hbParam->clusterId, sizeof(hbParam->clusterId))) {
|
||||
code = hbGetExpiredUserInfo(connKey, pCatalog, req);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
|
@ -819,6 +922,15 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req
|
|||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
code = hbGetExpiredViewInfo(connKey, pCatalog, req);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
req->app.appId = 0;
|
||||
}
|
||||
|
||||
++hbParam->reqCnt; // success to get catalog info
|
||||
|
|
|
@ -1009,7 +1009,7 @@ void schedulerExecCb(SExecResult* pResult, void* param, int32_t code) {
|
|||
|
||||
tscDebug("schedulerExecCb request type %s", TMSG_INFO(pRequest->type));
|
||||
if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type) && NULL == pRequest->body.resInfo.execRes.res) {
|
||||
removeMeta(pTscObj, pRequest->targetTableList);
|
||||
removeMeta(pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type));
|
||||
}
|
||||
|
||||
pRequest->metric.execCostUs = taosGetTimestampUs() - pRequest->metric.execStart;
|
||||
|
@ -1097,7 +1097,7 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue
|
|||
}
|
||||
|
||||
if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type) && NULL == pRequest->body.resInfo.execRes.res) {
|
||||
removeMeta(pRequest->pTscObj, pRequest->targetTableList);
|
||||
removeMeta(pRequest->pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type));
|
||||
}
|
||||
|
||||
handleQueryExecRsp(pRequest);
|
||||
|
@ -1116,31 +1116,34 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue
|
|||
|
||||
static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultMeta,
|
||||
SSqlCallbackWrapper* pWrapper) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
pRequest->type = pQuery->msgType;
|
||||
|
||||
SArray* pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad));
|
||||
|
||||
SPlanContext cxt = {.queryId = pRequest->requestId,
|
||||
.acctId = pRequest->pTscObj->acctId,
|
||||
.mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
|
||||
.pAstRoot = pQuery->pRoot,
|
||||
.showRewrite = pQuery->showRewrite,
|
||||
.pMsg = pRequest->msgBuf,
|
||||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
|
||||
.pUser = pRequest->pTscObj->user,
|
||||
.sysInfo = pRequest->pTscObj->sysInfo,
|
||||
.allocatorId = pRequest->allocatorRefId};
|
||||
|
||||
SQueryPlan* pDag = NULL;
|
||||
|
||||
SArray* pMnodeList = NULL;
|
||||
SQueryPlan* pDag = NULL;
|
||||
int64_t st = taosGetTimestampUs();
|
||||
int32_t code = qCreateQueryPlan(&cxt, &pDag, pMnodeList);
|
||||
if (code) {
|
||||
tscError("0x%" PRIx64 " failed to create query plan, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code),
|
||||
pRequest->requestId);
|
||||
} else {
|
||||
pRequest->body.subplanNum = pDag->numOfSubplans;
|
||||
TSWAP(pRequest->pPostPlan, pDag->pPostPlan);
|
||||
|
||||
if (!pRequest->parseOnly) {
|
||||
pMnodeList = taosArrayInit(4, sizeof(SQueryNodeLoad));
|
||||
|
||||
SPlanContext cxt = {.queryId = pRequest->requestId,
|
||||
.acctId = pRequest->pTscObj->acctId,
|
||||
.mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
|
||||
.pAstRoot = pQuery->pRoot,
|
||||
.showRewrite = pQuery->showRewrite,
|
||||
.pMsg = pRequest->msgBuf,
|
||||
.msgLen = ERROR_MSG_BUF_DEFAULT_SIZE,
|
||||
.pUser = pRequest->pTscObj->user,
|
||||
.sysInfo = pRequest->pTscObj->sysInfo,
|
||||
.allocatorId = pRequest->allocatorRefId};
|
||||
|
||||
code = qCreateQueryPlan(&cxt, &pDag, pMnodeList);
|
||||
if (code) {
|
||||
tscError("0x%" PRIx64 " failed to create query plan, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code),
|
||||
pRequest->requestId);
|
||||
} else {
|
||||
pRequest->body.subplanNum = pDag->numOfSubplans;
|
||||
TSWAP(pRequest->pPostPlan, pDag->pPostPlan);
|
||||
}
|
||||
}
|
||||
|
||||
pRequest->metric.execStart = taosGetTimestampUs();
|
||||
|
@ -1173,6 +1176,7 @@ static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaDat
|
|||
code = schedulerExecJob(&req, &pRequest->body.queryJob);
|
||||
taosArrayDestroy(pNodeList);
|
||||
} else {
|
||||
qDestroyQueryPlan(pDag);
|
||||
tscDebug("0x%" PRIx64 " plan not executed, code:%s 0x%" PRIx64, pRequest->self, tstrerror(code),
|
||||
pRequest->requestId);
|
||||
destorySqlCallbackWrapper(pWrapper);
|
||||
|
@ -1193,6 +1197,11 @@ static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaDat
|
|||
void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultMeta, SSqlCallbackWrapper* pWrapper) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (pRequest->parseOnly) {
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
pRequest->body.execMode = pQuery->execMode;
|
||||
if (QUERY_EXEC_MODE_SCHEDULE != pRequest->body.execMode) {
|
||||
destorySqlCallbackWrapper(pWrapper);
|
||||
|
@ -1226,6 +1235,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM
|
|||
pRequest->body.queryFp(pRequest->body.param, pRequest, 0);
|
||||
break;
|
||||
default:
|
||||
tscError("0x%" PRIx64 " invalid execMode %d", pRequest->self, pQuery->execMode);
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, -1);
|
||||
break;
|
||||
}
|
||||
|
@ -1272,7 +1282,7 @@ int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t removeMeta(STscObj* pTscObj, SArray* tbList) {
|
||||
int32_t removeMeta(STscObj* pTscObj, SArray* tbList, bool isView) {
|
||||
SCatalog* pCatalog = NULL;
|
||||
int32_t tbNum = taosArrayGetSize(tbList);
|
||||
int32_t code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
|
@ -1280,9 +1290,18 @@ int32_t removeMeta(STscObj* pTscObj, SArray* tbList) {
|
|||
return code;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < tbNum; ++i) {
|
||||
SName* pTbName = taosArrayGet(tbList, i);
|
||||
catalogRemoveTableMeta(pCatalog, pTbName);
|
||||
if (isView) {
|
||||
for (int32_t i = 0; i < tbNum; ++i) {
|
||||
SName* pViewName = taosArrayGet(tbList, i);
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
tNameGetFullDbName(pViewName, dbFName);
|
||||
catalogRemoveViewMeta(pCatalog, dbFName, 0, pViewName->tname, 0);
|
||||
}
|
||||
} else {
|
||||
for (int32_t i = 0; i < tbNum; ++i) {
|
||||
SName* pTbName = taosArrayGet(tbList, i);
|
||||
catalogRemoveTableMeta(pCatalog, pTbName);
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -2604,3 +2623,13 @@ void taosAsyncFetchImpl(SRequestObj* pRequest, __taos_async_fn_t fp, void* param
|
|||
|
||||
schedulerFetchRows(pRequest->body.queryJob, &req);
|
||||
}
|
||||
|
||||
int32_t clientParseSql(void* param, const char* dbName, const char* sql, bool parseOnly, const char* effectiveUser, SParseSqlRes* pRes) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_SUCCESS;
|
||||
#else
|
||||
return clientParseSqlImpl(param, dbName, sql, parseOnly, effectiveUser, pRes);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#define TSC_VAR_RELEASED 0
|
||||
|
||||
static int32_t sentinel = TSC_VAR_NOT_RELEASE;
|
||||
static int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt);
|
||||
static int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt, SSqlCallbackWrapper *pWrapper);
|
||||
|
||||
int taos_options(TSDB_OPTION option, const void *arg, ...) {
|
||||
static int32_t lock = 0;
|
||||
|
@ -879,39 +879,12 @@ int taos_get_current_db(TAOS *taos, char *database, int len, int *required) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static void destoryTablesReq(void *p) {
|
||||
STablesReq *pRes = (STablesReq *)p;
|
||||
taosArrayDestroy(pRes->pTables);
|
||||
}
|
||||
|
||||
static void destoryCatalogReq(SCatalogReq *pCatalogReq) {
|
||||
if (NULL == pCatalogReq) {
|
||||
return;
|
||||
}
|
||||
taosArrayDestroy(pCatalogReq->pDbVgroup);
|
||||
taosArrayDestroy(pCatalogReq->pDbCfg);
|
||||
taosArrayDestroy(pCatalogReq->pDbInfo);
|
||||
if (pCatalogReq->cloned) {
|
||||
taosArrayDestroy(pCatalogReq->pTableMeta);
|
||||
taosArrayDestroy(pCatalogReq->pTableHash);
|
||||
} else {
|
||||
taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq);
|
||||
taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
|
||||
}
|
||||
taosArrayDestroy(pCatalogReq->pUdf);
|
||||
taosArrayDestroy(pCatalogReq->pIndex);
|
||||
taosArrayDestroy(pCatalogReq->pUser);
|
||||
taosArrayDestroy(pCatalogReq->pTableIndex);
|
||||
taosArrayDestroy(pCatalogReq->pTableCfg);
|
||||
taosArrayDestroy(pCatalogReq->pTableTag);
|
||||
taosMemoryFree(pCatalogReq);
|
||||
}
|
||||
|
||||
void destorySqlCallbackWrapper(SSqlCallbackWrapper *pWrapper) {
|
||||
if (NULL == pWrapper) {
|
||||
return;
|
||||
}
|
||||
destoryCatalogReq(pWrapper->pCatalogReq);
|
||||
taosMemoryFree(pWrapper->pCatalogReq);
|
||||
qDestroyParseContext(pWrapper->pParseCtx);
|
||||
taosMemoryFree(pWrapper);
|
||||
}
|
||||
|
@ -933,6 +906,7 @@ static void doAsyncQueryFromAnalyse(SMetaData *pResultMeta, void *param, int32_t
|
|||
|
||||
int64_t analyseStart = taosGetTimestampUs();
|
||||
pRequest->metric.ctgCostUs = analyseStart - pRequest->metric.ctgStart;
|
||||
pWrapper->pParseCtx->parseOnly = pRequest->parseOnly;
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = qAnalyseSqlSemantic(pWrapper->pParseCtx, pWrapper->pCatalogReq, pResultMeta, pQuery);
|
||||
|
@ -940,6 +914,11 @@ static void doAsyncQueryFromAnalyse(SMetaData *pResultMeta, void *param, int32_t
|
|||
|
||||
pRequest->metric.analyseCostUs += taosGetTimestampUs() - analyseStart;
|
||||
|
||||
if (pRequest->parseOnly) {
|
||||
memcpy(&pRequest->parseMeta, pResultMeta, sizeof(*pResultMeta));
|
||||
memset(pResultMeta, 0, sizeof(*pResultMeta));
|
||||
}
|
||||
|
||||
handleQueryAnslyseRes(pWrapper, pResultMeta, code);
|
||||
}
|
||||
|
||||
|
@ -960,6 +939,7 @@ int32_t cloneCatalogReq(SCatalogReq **ppTarget, SCatalogReq *pSrc) {
|
|||
pTarget->pTableIndex = taosArrayDup(pSrc->pTableIndex, NULL);
|
||||
pTarget->pTableCfg = taosArrayDup(pSrc->pTableCfg, NULL);
|
||||
pTarget->pTableTag = taosArrayDup(pSrc->pTableTag, NULL);
|
||||
pTarget->pView = taosArrayDup(pSrc->pView, NULL);
|
||||
pTarget->qNodeRequired = pSrc->qNodeRequired;
|
||||
pTarget->dNodeRequired = pSrc->dNodeRequired;
|
||||
pTarget->svrVerRequired = pSrc->svrVerRequired;
|
||||
|
@ -1147,7 +1127,7 @@ void taos_query_a_with_reqid(TAOS *taos, const char *sql, __taos_async_fn_t fp,
|
|||
taosAsyncQueryImplWithReqid(connId, sql, fp, param, false, reqid);
|
||||
}
|
||||
|
||||
int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) {
|
||||
int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt, SSqlCallbackWrapper *pWrapper) {
|
||||
const STscObj *pTscObj = pRequest->pTscObj;
|
||||
|
||||
*pCxt = taosMemoryCalloc(1, sizeof(SParseContext));
|
||||
|
@ -1167,12 +1147,15 @@ int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) {
|
|||
.pTransporter = pTscObj->pAppInfo->pTransporter,
|
||||
.pStmtCb = NULL,
|
||||
.pUser = pTscObj->user,
|
||||
.pEffectiveUser = pRequest->effectiveUser,
|
||||
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
||||
.enableSysInfo = pTscObj->sysInfo,
|
||||
.async = true,
|
||||
.svrVer = pTscObj->sVer,
|
||||
.nodeOffline = (pTscObj->pAppInfo->onlineDnodes < pTscObj->pAppInfo->totalDnodes),
|
||||
.allocatorId = pRequest->allocatorRefId};
|
||||
.allocatorId = pRequest->allocatorRefId,
|
||||
.parseSqlFp = clientParseSql,
|
||||
.parseSqlParam = pWrapper};
|
||||
int8_t biMode = atomic_load_8(&((STscObj *)pTscObj)->biMode);
|
||||
(*pCxt)->biMode = biMode;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1191,7 +1174,7 @@ int32_t prepareAndParseSqlSyntax(SSqlCallbackWrapper **ppWrapper, SRequestObj *p
|
|||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createParseContext(pRequest, &pWrapper->pParseCtx);
|
||||
code = createParseContext(pRequest, &pWrapper->pParseCtx, pWrapper);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -1570,7 +1553,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
|||
tsem_wait(&pParam->sem);
|
||||
|
||||
_return:
|
||||
taosArrayDestroyEx(catalogReq.pTableMeta, destoryTablesReq);
|
||||
destoryCatalogReq(&catalogReq);
|
||||
destroyRequest(pRequest);
|
||||
return code;
|
||||
}
|
||||
|
@ -1860,4 +1843,4 @@ int taos_set_conn_mode(TAOS* taos, int mode, int value) {
|
|||
return TSDB_CODE_INVALID_PARA;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ int32_t genericRspCallback(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
setErrno(pRequest, code);
|
||||
|
||||
if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) {
|
||||
removeMeta(pRequest->pTscObj, pRequest->targetTableList);
|
||||
removeMeta(pRequest->pTscObj, pRequest->targetTableList, IS_VIEW_REQUEST(pRequest->type));
|
||||
}
|
||||
|
||||
taosMemoryFree(pMsg->pEpSet);
|
||||
|
|
|
@ -993,7 +993,7 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
|
|||
|
||||
launchQueryImpl(pRequest, pQuery, true, NULL);
|
||||
if (pRequest->code == TSDB_CODE_SUCCESS) {
|
||||
removeMeta(pTscObj, pRequest->tableList);
|
||||
removeMeta(pTscObj, pRequest->tableList, false);
|
||||
}
|
||||
|
||||
code = pRequest->code;
|
||||
|
@ -1139,7 +1139,7 @@ static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) {
|
|||
|
||||
launchQueryImpl(pRequest, pQuery, true, NULL);
|
||||
if (pRequest->code == TSDB_CODE_SUCCESS) {
|
||||
removeMeta(pTscObj, pRequest->tableList);
|
||||
removeMeta(pTscObj, pRequest->tableList, false);
|
||||
}
|
||||
code = pRequest->code;
|
||||
|
||||
|
|
|
@ -104,9 +104,9 @@ static int32_t smlCheckAuth(SSmlHandle *info, SRequestConnInfo* conn, const cha
|
|||
SUserAuthRes authRes = {0};
|
||||
|
||||
code = catalogChkAuth(info->pCatalog, conn, &pAuth, &authRes);
|
||||
nodesDestroyNode(authRes.pCond);
|
||||
nodesDestroyNode(authRes.pCond[AUTH_RES_BASIC]);
|
||||
|
||||
return (code == TSDB_CODE_SUCCESS) ? (authRes.pass ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED) : code;
|
||||
return (code == TSDB_CODE_SUCCESS) ? (authRes.pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED) : code;
|
||||
|
||||
}
|
||||
inline bool smlDoubleToInt64OverFlow(double num) {
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#define SYSTABLE_SCH_TABLE_NAME_LEN ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
#define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
#define SYSTABLE_SCH_COL_NAME_LEN ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
#define SYSTABLE_SCH_VIEW_NAME_LEN ((TSDB_VIEW_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
|
||||
// clang-format off
|
||||
static const SSysDbTableSchema dnodesSchema[] = {
|
||||
|
@ -315,8 +316,23 @@ static const SSysDbTableSchema userUserPrivilegesSchema[] = {
|
|||
{.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},
|
||||
{.name = "notes", .bytes = 64 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema userViewsSchema[] = {
|
||||
{.name = "view_name", .bytes = SYSTABLE_SCH_VIEW_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "effective_user", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
|
||||
{.name = "type", .bytes = 128 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "query_sql", .bytes = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "parameters", .bytes = 2048 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "default_values", .bytes = 2048 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
{.name = "target_table", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
// {.name = "column_list", .bytes = 2048 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false},
|
||||
};
|
||||
|
||||
|
||||
static const SSysTableMeta infosMeta[] = {
|
||||
{TSDB_INS_TABLE_DNODES, dnodesSchema, tListLen(dnodesSchema), true},
|
||||
{TSDB_INS_TABLE_MNODES, mnodesSchema, tListLen(mnodesSchema), true},
|
||||
|
@ -343,6 +359,7 @@ static const SSysTableMeta infosMeta[] = {
|
|||
{TSDB_INS_TABLE_STREAM_TASKS, streamTaskSchema, tListLen(streamTaskSchema), false},
|
||||
{TSDB_INS_TABLE_VNODES, vnodesSchema, tListLen(vnodesSchema), true},
|
||||
{TSDB_INS_TABLE_USER_PRIVILEGES, userUserPrivilegesSchema, tListLen(userUserPrivilegesSchema), true},
|
||||
{TSDB_INS_TABLE_VIEWS, userViewsSchema, tListLen(userViewsSchema), false},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema connectionsSchema[] = {
|
||||
|
|
|
@ -1677,6 +1677,7 @@ int32_t tSerializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq)
|
|||
if (tEncodeI8(&encoder, pReq->superUser) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->sysInfo) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->enable) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->isView) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->user) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->pass) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->objname) < 0) return -1;
|
||||
|
@ -1691,6 +1692,7 @@ int32_t tSerializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq)
|
|||
if (tEncodeU32(&encoder, pReq->pIpRanges[i].ip) < 0) return -1;
|
||||
if (tEncodeU32(&encoder, pReq->pIpRanges[i].mask) < 0) return -1;
|
||||
}
|
||||
if (tEncodeI64(&encoder, pReq->privileges) < 0) return -1;
|
||||
ENCODESQL();
|
||||
tEndEncode(&encoder);
|
||||
|
||||
|
@ -1708,6 +1710,7 @@ int32_t tDeserializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq
|
|||
if (tDecodeI8(&decoder, &pReq->superUser) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->sysInfo) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->enable) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->isView) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->pass) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->objname) < 0) return -1;
|
||||
|
@ -1728,6 +1731,7 @@ int32_t tDeserializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq
|
|||
if (tDecodeU32(&decoder, &(pReq->pIpRanges[i].ip)) < 0) return -1;
|
||||
if (tDecodeU32(&decoder, &(pReq->pIpRanges[i].mask)) < 0) return -1;
|
||||
}
|
||||
if (tDecodeI64(&decoder, &pReq->privileges) < 0) return -1;
|
||||
DECODESQL();
|
||||
tEndDecode(&decoder);
|
||||
|
||||
|
@ -1802,10 +1806,18 @@ int32_t tSerializeSGetUserAuthRspImpl(SEncoder *pEncoder, SGetUserAuthRsp *pRsp)
|
|||
|
||||
int32_t numOfReadTbs = taosHashGetSize(pRsp->readTbs);
|
||||
int32_t numOfWriteTbs = taosHashGetSize(pRsp->writeTbs);
|
||||
int32_t numOfUseTbs = taosHashGetSize(pRsp->useDbs);
|
||||
int32_t numOfAlterTbs = taosHashGetSize(pRsp->alterTbs);
|
||||
int32_t numOfReadViews = taosHashGetSize(pRsp->readViews);
|
||||
int32_t numOfWriteViews = taosHashGetSize(pRsp->writeViews);
|
||||
int32_t numOfAlterViews = taosHashGetSize(pRsp->alterViews);
|
||||
int32_t numOfUseDbs = taosHashGetSize(pRsp->useDbs);
|
||||
if (tEncodeI32(pEncoder, numOfReadTbs) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, numOfWriteTbs) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, numOfUseTbs) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, numOfAlterTbs) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, numOfReadViews) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, numOfWriteViews) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, numOfAlterViews) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, numOfUseDbs) < 0) return -1;
|
||||
|
||||
char *tb = taosHashIterate(pRsp->readTbs, NULL);
|
||||
while (tb != NULL) {
|
||||
|
@ -1837,6 +1849,66 @@ int32_t tSerializeSGetUserAuthRspImpl(SEncoder *pEncoder, SGetUserAuthRsp *pRsp)
|
|||
tb = taosHashIterate(pRsp->writeTbs, tb);
|
||||
}
|
||||
|
||||
tb = taosHashIterate(pRsp->alterTbs, 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->alterTbs, tb);
|
||||
}
|
||||
|
||||
tb = taosHashIterate(pRsp->readViews, 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->readViews, tb);
|
||||
}
|
||||
|
||||
tb = taosHashIterate(pRsp->writeViews, 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->writeViews, tb);
|
||||
}
|
||||
|
||||
tb = taosHashIterate(pRsp->alterViews, 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->alterViews, tb);
|
||||
}
|
||||
|
||||
int32_t *useDb = taosHashIterate(pRsp->useDbs, NULL);
|
||||
while (useDb != NULL) {
|
||||
size_t keyLen = 0;
|
||||
|
@ -1876,9 +1948,14 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs
|
|||
pRsp->writeDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
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->alterTbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pRsp->readViews = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pRsp->writeViews = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pRsp->alterViews = 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) {
|
||||
pRsp->writeTbs == NULL || pRsp->alterTbs == NULL || pRsp->readViews == NULL ||
|
||||
pRsp->writeViews == NULL || pRsp->alterViews == NULL ||pRsp->useDbs == NULL) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
|
@ -1900,29 +1977,37 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs
|
|||
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||
if (tDecodeCStrTo(pDecoder, db) < 0) goto _err;
|
||||
int32_t len = strlen(db);
|
||||
taosHashPut(pRsp->createdDbs, db, len, db, len + 1);
|
||||
taosHashPut(pRsp->createdDbs, db, len + 1, db, len + 1);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfReadDbs; ++i) {
|
||||
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||
if (tDecodeCStrTo(pDecoder, db) < 0) goto _err;
|
||||
int32_t len = strlen(db);
|
||||
taosHashPut(pRsp->readDbs, db, len, db, len + 1);
|
||||
taosHashPut(pRsp->readDbs, db, len + 1, db, len + 1);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfWriteDbs; ++i) {
|
||||
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||
if (tDecodeCStrTo(pDecoder, db) < 0) goto _err;
|
||||
int32_t len = strlen(db);
|
||||
taosHashPut(pRsp->writeDbs, db, len, db, len + 1);
|
||||
taosHashPut(pRsp->writeDbs, db, len + 1, db, len + 1);
|
||||
}
|
||||
|
||||
if (!tDecodeIsEnd(pDecoder)) {
|
||||
int32_t numOfReadTbs = 0;
|
||||
int32_t numOfWriteTbs = 0;
|
||||
int32_t numOfAlterTbs = 0;
|
||||
int32_t numOfReadViews = 0;
|
||||
int32_t numOfWriteViews = 0;
|
||||
int32_t numOfAlterViews = 0;
|
||||
int32_t numOfUseDbs = 0;
|
||||
if (tDecodeI32(pDecoder, &numOfReadTbs) < 0) goto _err;
|
||||
if (tDecodeI32(pDecoder, &numOfWriteTbs) < 0) goto _err;
|
||||
if (tDecodeI32(pDecoder, &numOfAlterTbs) < 0) goto _err;
|
||||
if (tDecodeI32(pDecoder, &numOfReadViews) < 0) goto _err;
|
||||
if (tDecodeI32(pDecoder, &numOfWriteViews) < 0) goto _err;
|
||||
if (tDecodeI32(pDecoder, &numOfAlterViews) < 0) goto _err;
|
||||
if (tDecodeI32(pDecoder, &numOfUseDbs) < 0) goto _err;
|
||||
|
||||
for (int32_t i = 0; i < numOfReadTbs; ++i) {
|
||||
|
@ -1938,7 +2023,7 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs
|
|||
value = taosMemoryCalloc(valuelen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, value) < 0) goto _err;
|
||||
|
||||
taosHashPut(pRsp->readTbs, key, strlen(key), value, valuelen + 1);
|
||||
taosHashPut(pRsp->readTbs, key, keyLen, value, valuelen + 1);
|
||||
|
||||
taosMemoryFreeClear(key);
|
||||
taosMemoryFreeClear(value);
|
||||
|
@ -1957,7 +2042,83 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs
|
|||
value = taosMemoryCalloc(valuelen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, value) < 0) goto _err;
|
||||
|
||||
taosHashPut(pRsp->writeTbs, key, strlen(key), value, valuelen + 1);
|
||||
taosHashPut(pRsp->writeTbs, key, keyLen, value, valuelen + 1);
|
||||
|
||||
taosMemoryFreeClear(key);
|
||||
taosMemoryFreeClear(value);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfAlterTbs; ++i) {
|
||||
int32_t keyLen = 0;
|
||||
if (tDecodeI32(pDecoder, &keyLen) < 0) goto _err;
|
||||
|
||||
key = taosMemoryCalloc(keyLen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, key) < 0) goto _err;
|
||||
|
||||
int32_t valuelen = 0;
|
||||
if (tDecodeI32(pDecoder, &valuelen) < 0) goto _err;
|
||||
|
||||
value = taosMemoryCalloc(valuelen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, value) < 0) goto _err;
|
||||
|
||||
taosHashPut(pRsp->alterTbs, key, keyLen, value, valuelen + 1);
|
||||
|
||||
taosMemoryFreeClear(key);
|
||||
taosMemoryFreeClear(value);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfReadViews; ++i) {
|
||||
int32_t keyLen = 0;
|
||||
if (tDecodeI32(pDecoder, &keyLen) < 0) goto _err;
|
||||
|
||||
key = taosMemoryCalloc(keyLen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, key) < 0) goto _err;
|
||||
|
||||
int32_t valuelen = 0;
|
||||
if (tDecodeI32(pDecoder, &valuelen) < 0) goto _err;
|
||||
|
||||
value = taosMemoryCalloc(valuelen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, value) < 0) goto _err;
|
||||
|
||||
taosHashPut(pRsp->readViews, key, keyLen, value, valuelen + 1);
|
||||
|
||||
taosMemoryFreeClear(key);
|
||||
taosMemoryFreeClear(value);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfWriteViews; ++i) {
|
||||
int32_t keyLen = 0;
|
||||
if (tDecodeI32(pDecoder, &keyLen) < 0) goto _err;
|
||||
|
||||
key = taosMemoryCalloc(keyLen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, key) < 0) goto _err;
|
||||
|
||||
int32_t valuelen = 0;
|
||||
if (tDecodeI32(pDecoder, &valuelen) < 0) goto _err;
|
||||
|
||||
value = taosMemoryCalloc(valuelen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, value) < 0) goto _err;
|
||||
|
||||
taosHashPut(pRsp->writeViews, key, keyLen, value, valuelen + 1);
|
||||
|
||||
taosMemoryFreeClear(key);
|
||||
taosMemoryFreeClear(value);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfAlterViews; ++i) {
|
||||
int32_t keyLen = 0;
|
||||
if (tDecodeI32(pDecoder, &keyLen) < 0) goto _err;
|
||||
|
||||
key = taosMemoryCalloc(keyLen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, key) < 0) goto _err;
|
||||
|
||||
int32_t valuelen = 0;
|
||||
if (tDecodeI32(pDecoder, &valuelen) < 0) goto _err;
|
||||
|
||||
value = taosMemoryCalloc(valuelen + 1, sizeof(char));
|
||||
if (tDecodeCStrTo(pDecoder, value) < 0) goto _err;
|
||||
|
||||
taosHashPut(pRsp->alterViews, key, keyLen, value, valuelen + 1);
|
||||
|
||||
taosMemoryFreeClear(key);
|
||||
taosMemoryFreeClear(value);
|
||||
|
@ -1973,7 +2134,7 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs
|
|||
int32_t ref = 0;
|
||||
if (tDecodeI32(pDecoder, &ref) < 0) goto _err;
|
||||
|
||||
taosHashPut(pRsp->useDbs, key, strlen(key), &ref, sizeof(ref));
|
||||
taosHashPut(pRsp->useDbs, key, keyLen, &ref, sizeof(ref));
|
||||
taosMemoryFreeClear(key);
|
||||
}
|
||||
// since 3.0.7.0
|
||||
|
@ -1993,8 +2154,12 @@ _err:
|
|||
taosHashCleanup(pRsp->createdDbs);
|
||||
taosHashCleanup(pRsp->readDbs);
|
||||
taosHashCleanup(pRsp->writeDbs);
|
||||
taosHashCleanup(pRsp->writeTbs);
|
||||
taosHashCleanup(pRsp->readTbs);
|
||||
taosHashCleanup(pRsp->writeTbs);
|
||||
taosHashCleanup(pRsp->alterTbs);
|
||||
taosHashCleanup(pRsp->readViews);
|
||||
taosHashCleanup(pRsp->writeViews);
|
||||
taosHashCleanup(pRsp->alterViews);
|
||||
taosHashCleanup(pRsp->useDbs);
|
||||
|
||||
taosMemoryFreeClear(key);
|
||||
|
@ -2020,8 +2185,12 @@ void tFreeSGetUserAuthRsp(SGetUserAuthRsp *pRsp) {
|
|||
taosHashCleanup(pRsp->createdDbs);
|
||||
taosHashCleanup(pRsp->readDbs);
|
||||
taosHashCleanup(pRsp->writeDbs);
|
||||
taosHashCleanup(pRsp->writeTbs);
|
||||
taosHashCleanup(pRsp->readTbs);
|
||||
taosHashCleanup(pRsp->writeTbs);
|
||||
taosHashCleanup(pRsp->alterTbs);
|
||||
taosHashCleanup(pRsp->readViews);
|
||||
taosHashCleanup(pRsp->writeViews);
|
||||
taosHashCleanup(pRsp->alterViews);
|
||||
taosHashCleanup(pRsp->useDbs);
|
||||
}
|
||||
|
||||
|
@ -8634,3 +8803,286 @@ void tDeleteMqSubTopicEp(SMqSubTopicEp *pSubTopicEp) {
|
|||
pSubTopicEp->schema.nCols = 0;
|
||||
taosArrayDestroy(pSubTopicEp->vgs);
|
||||
}
|
||||
|
||||
int32_t tSerializeSCMCreateViewReq(void *buf, int32_t bufLen, const SCMCreateViewReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->fullname) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->dbFName) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->querySql) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->orReplace) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->precision) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->numOfCols) < 0) return -1;
|
||||
for (int32_t i = 0; i < pReq->numOfCols; ++i) {
|
||||
SSchema *pSchema = &pReq->pSchema[i];
|
||||
if (tEncodeSSchema(&encoder, pSchema) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSCMCreateViewReq(void *buf, int32_t bufLen, SCMCreateViewReq *pReq) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->fullname) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->dbFName) < 0) return -1;
|
||||
if (tDecodeCStrAlloc(&decoder, &pReq->querySql) < 0) return -1;
|
||||
if (tDecodeCStrAlloc(&decoder, &pReq->sql) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->orReplace) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->precision) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->numOfCols) < 0) return -1;
|
||||
|
||||
if (pReq->numOfCols > 0) {
|
||||
pReq->pSchema = taosMemoryCalloc(pReq->numOfCols, sizeof(SSchema));
|
||||
if (pReq->pSchema == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pReq->numOfCols; ++i) {
|
||||
SSchema* pSchema = pReq->pSchema + i;
|
||||
if (tDecodeSSchema(&decoder, pSchema) < 0) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSCMCreateViewReq(SCMCreateViewReq* pReq) {
|
||||
if (NULL == pReq) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pReq->querySql);
|
||||
taosMemoryFreeClear(pReq->sql);
|
||||
taosMemoryFreeClear(pReq->pSchema);
|
||||
}
|
||||
|
||||
int32_t tSerializeSCMDropViewReq(void* buf, int32_t bufLen, const SCMDropViewReq* pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->fullname) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->name) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->dbFName) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->igNotExists) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSCMDropViewReq(void* buf, int32_t bufLen, SCMDropViewReq* pReq) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->fullname) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->dbFName) < 0) return -1;
|
||||
if (tDecodeCStrAlloc(&decoder, &pReq->sql) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->igNotExists) < 0) return -1;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
void tFreeSCMDropViewReq(SCMDropViewReq* pReq) {
|
||||
if (NULL == pReq) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosMemoryFree(pReq->sql);
|
||||
}
|
||||
|
||||
int32_t tSerializeSViewMetaReq(void* buf, int32_t bufLen, const SViewMetaReq* pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->fullname) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSViewMetaReq(void* buf, int32_t bufLen, SViewMetaReq* pReq) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->fullname) < 0) return -1;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tEncodeSViewMetaRsp(SEncoder *pEncoder, const SViewMetaRsp *pRsp) {
|
||||
if (tEncodeCStr(pEncoder, pRsp->name) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pRsp->dbFName) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pRsp->user) < 0) return -1;
|
||||
if (tEncodeU64(pEncoder, pRsp->dbId) < 0) return -1;
|
||||
if (tEncodeU64(pEncoder, pRsp->viewId) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pRsp->querySql) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pRsp->precision) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pRsp->type) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pRsp->version) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pRsp->numOfCols) < 0) return -1;
|
||||
for (int32_t i = 0; i < pRsp->numOfCols; ++i) {
|
||||
SSchema *pSchema = &pRsp->pSchema[i];
|
||||
if (tEncodeSSchema(pEncoder, pSchema) < 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pRsp) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeSViewMetaRsp(&encoder, pRsp) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
static int32_t tDecodeSViewMetaRsp(SDecoder *pDecoder, SViewMetaRsp *pRsp) {
|
||||
if (tDecodeCStrTo(pDecoder, pRsp->name) < 0) return -1;
|
||||
if (tDecodeCStrTo(pDecoder, pRsp->dbFName) < 0) return -1;
|
||||
if (tDecodeCStrAlloc(pDecoder, &pRsp->user) < 0) return -1;
|
||||
if (tDecodeU64(pDecoder, &pRsp->dbId) < 0) return -1;
|
||||
if (tDecodeU64(pDecoder, &pRsp->viewId) < 0) return -1;
|
||||
if (tDecodeCStrAlloc(pDecoder, &pRsp->querySql) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pRsp->precision) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pRsp->type) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pRsp->version) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pRsp->numOfCols) < 0) return -1;
|
||||
if (pRsp->numOfCols > 0) {
|
||||
pRsp->pSchema = taosMemoryCalloc(pRsp->numOfCols, sizeof(SSchema));
|
||||
if (pRsp->pSchema == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pRsp->numOfCols; ++i) {
|
||||
SSchema* pSchema = pRsp->pSchema + i;
|
||||
if (tDecodeSSchema(pDecoder, pSchema) < 0) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeSViewMetaRsp(&decoder, pRsp) < 0) return -1;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSViewMetaRsp(SViewMetaRsp* pRsp) {
|
||||
if (NULL == pRsp) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosMemoryFree(pRsp->user);
|
||||
taosMemoryFree(pRsp->querySql);
|
||||
taosMemoryFree(pRsp->pSchema);
|
||||
}
|
||||
|
||||
int32_t tSerializeSViewHbRsp(void *buf, int32_t bufLen, SViewHbRsp *pRsp) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
|
||||
int32_t numOfMeta = taosArrayGetSize(pRsp->pViewRsp);
|
||||
if (tEncodeI32(&encoder, numOfMeta) < 0) return -1;
|
||||
for (int32_t i = 0; i < numOfMeta; ++i) {
|
||||
SViewMetaRsp *pMetaRsp = taosArrayGetP(pRsp->pViewRsp, i);
|
||||
if (tEncodeSViewMetaRsp(&encoder, pMetaRsp) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSViewHbRsp(void *buf, int32_t bufLen, SViewHbRsp *pRsp) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
|
||||
int32_t numOfMeta = 0;
|
||||
if (tDecodeI32(&decoder, &numOfMeta) < 0) return -1;
|
||||
pRsp->pViewRsp = taosArrayInit(numOfMeta, POINTER_BYTES);
|
||||
if (pRsp->pViewRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfMeta; ++i) {
|
||||
SViewMetaRsp* metaRsp = taosMemoryCalloc(1, sizeof(SViewMetaRsp));
|
||||
if (NULL == metaRsp) return -1;
|
||||
if (tDecodeSViewMetaRsp(&decoder, metaRsp) < 0) return -1;
|
||||
taosArrayPush(pRsp->pViewRsp, &metaRsp);
|
||||
}
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSViewHbRsp(SViewHbRsp *pRsp) {
|
||||
int32_t numOfMeta = taosArrayGetSize(pRsp->pViewRsp);
|
||||
for (int32_t i = 0; i < numOfMeta; ++i) {
|
||||
SViewMetaRsp *pMetaRsp = taosArrayGetP(pRsp->pViewRsp, i);
|
||||
tFreeSViewMetaRsp(pMetaRsp);
|
||||
taosMemoryFree(pMetaRsp);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pRsp->pViewRsp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -189,6 +189,9 @@ SArray *mmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_INDEX, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_INDEX, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_RESTORE_DNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_VIEW, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_VIEW, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_MND_VIEW_META, mmPutMsgToReadQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SCH_QUERY, mmPutMsgToQueryQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SCH_MERGE_QUERY, mmPutMsgToQueryQueue, 1) == NULL) goto _OVER;
|
||||
|
|
|
@ -7,6 +7,7 @@ IF (TD_ENTERPRISE)
|
|||
LIST(APPEND MNODE_SRC ${TD_ENTERPRISE_DIR}/src/plugins/mnode/src/mndDb.c)
|
||||
LIST(APPEND MNODE_SRC ${TD_ENTERPRISE_DIR}/src/plugins/mnode/src/mndVgroup.c)
|
||||
LIST(APPEND MNODE_SRC ${TD_ENTERPRISE_DIR}/src/plugins/mnode/src/mndDnode.c)
|
||||
LIST(APPEND MNODE_SRC ${TD_ENTERPRISE_DIR}/src/plugins/view/src/mndView.c)
|
||||
ENDIF ()
|
||||
|
||||
add_library(mnode STATIC ${MNODE_SRC})
|
||||
|
|
|
@ -74,6 +74,8 @@ typedef enum {
|
|||
MND_OPER_SUBSCRIBE,
|
||||
MND_OPER_CREATE_TOPIC,
|
||||
MND_OPER_DROP_TOPIC,
|
||||
MND_OPER_CREATE_VIEW,
|
||||
MND_OPER_DROP_VIEW,
|
||||
} EOperType;
|
||||
|
||||
typedef enum {
|
||||
|
@ -297,6 +299,10 @@ typedef struct {
|
|||
SHashObj* topics;
|
||||
SHashObj* readTbs;
|
||||
SHashObj* writeTbs;
|
||||
SHashObj* alterTbs;
|
||||
SHashObj* readViews;
|
||||
SHashObj* writeViews;
|
||||
SHashObj* alterViews;
|
||||
SHashObj* useDbs;
|
||||
SRWLatch lock;
|
||||
} SUserObj;
|
||||
|
@ -704,6 +710,34 @@ void tFreeStreamObj(SStreamObj* pObj);
|
|||
// SArray* childInfo; // SArray<SStreamChildEpInfo>
|
||||
// } SStreamCheckpointObj;
|
||||
|
||||
#define VIEW_TYPE_UPDATABLE (1 << 0)
|
||||
#define VIEW_TYPE_MATERIALIZED (1 << 1)
|
||||
|
||||
typedef struct {
|
||||
char fullname[TSDB_VIEW_FNAME_LEN];
|
||||
char name[TSDB_VIEW_NAME_LEN];
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
char user[TSDB_USER_LEN];
|
||||
char* querySql;
|
||||
char* parameters;
|
||||
void** defaultValues;
|
||||
char* targetTable;
|
||||
uint64_t viewId;
|
||||
uint64_t dbId;
|
||||
int64_t createdTime;
|
||||
int32_t version;
|
||||
int8_t precision;
|
||||
int8_t type;
|
||||
int32_t numOfCols;
|
||||
SSchema* pSchema;
|
||||
SRWLatch lock;
|
||||
} SViewObj;
|
||||
|
||||
int32_t tEncodeSViewObj(SEncoder* pEncoder, const SViewObj* pObj);
|
||||
int32_t tDecodeSViewObj(SDecoder* pDecoder, SViewObj* pObj, int32_t sver);
|
||||
void tFreeSViewObj(SViewObj* pObj);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -28,6 +28,7 @@ void mndCleanupPrivilege(SMnode *pMnode);
|
|||
int32_t mndCheckOperPrivilege(SMnode *pMnode, const char *user, EOperType operType);
|
||||
int32_t mndCheckDbPrivilege(SMnode *pMnode, const char *user, EOperType operType, SDbObj *pDb);
|
||||
int32_t mndCheckDbPrivilegeByName(SMnode *pMnode, const char *user, EOperType operType, const char *dbname);
|
||||
int32_t mndCheckViewPrivilege(SMnode *pMnode, const char *user, EOperType operType, const char *pViewFName);
|
||||
int32_t mndCheckTopicPrivilege(SMnode *pMnode, const char *user, EOperType operType, SMqTopicObj *pTopic);
|
||||
int32_t mndCheckTopicPrivilegeByName(SMnode *pMnode, const char *user, EOperType operType, const char *topicName);
|
||||
int32_t mndCheckShowPrivilege(SMnode *pMnode, const char *user, EShowType showType, const char *dbname);
|
||||
|
|
|
@ -41,6 +41,7 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int3
|
|||
int32_t *pRspLen);
|
||||
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db);
|
||||
int32_t mndUserRemoveStb(SMnode *pMnode, STrans *pTrans, char *stb);
|
||||
int32_t mndUserRemoveView(SMnode *pMnode, STrans *pTrans, char *view);
|
||||
int32_t mndUserRemoveTopic(SMnode *pMnode, STrans *pTrans, char *topic);
|
||||
|
||||
int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew);
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MND_VIEW_H_
|
||||
#define _TD_MND_VIEW_H_
|
||||
|
||||
#include "mndInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mndInitView(SMnode *pMnode);
|
||||
void mndCleanupView(SMnode *pMnode);
|
||||
|
||||
int32_t mndProcessCreateViewReq(SRpcMsg *pReq);
|
||||
int32_t mndProcessDropViewReq(SRpcMsg *pReq);
|
||||
int32_t mndProcessGetViewMetaReq(SRpcMsg *pReq);
|
||||
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
|
||||
void initDynViewVersion(void);
|
||||
|
||||
SViewObj *mndAcquireView(SMnode *pMnode, char *viewName);
|
||||
void mndReleaseView(SMnode *pMnode, SViewObj *pView);
|
||||
|
||||
SSdbRaw *mndViewActionEncode(SViewObj *pView);
|
||||
SSdbRow *mndViewActionDecode(SSdbRaw *pRaw);
|
||||
int32_t mndViewActionInsert(SSdb *pSdb, SViewObj *pView);
|
||||
int32_t mndViewActionDelete(SSdb *pSdb, SViewObj *pView);
|
||||
int32_t mndViewActionUpdate(SSdb *pSdb, SViewObj *pOldView, SViewObj *pNewView);
|
||||
|
||||
int32_t mndProcessCreateViewReqImpl(SCMCreateViewReq* pCreateView, SRpcMsg *pReq);
|
||||
int32_t mndProcessDropViewReqImpl(SCMDropViewReq* pDropView, SRpcMsg *pReq);
|
||||
int32_t mndProcessViewMetaReqImpl(SViewMetaReq* pMetaReq, SRpcMsg *pReq);
|
||||
int32_t mndRetrieveViewImpl(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||
int32_t mndDropViewByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb);
|
||||
int32_t mndValidateDynViewVersion(SMnode *pMnode, SDynViewVersion* pReqVer, bool *needCheck, SDynViewVersion** ppRspVer);
|
||||
int32_t mndValidateViewInfo(SMnode *pMnode, SViewVersion *pViewVersions, int32_t numOfViews, void **ppRsp,
|
||||
int32_t *pRspLen);
|
||||
|
||||
#endif
|
||||
|
||||
int32_t mndRetrieveView(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||
void mndCancelGetNextView(SMnode *pMnode, void *pIter);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MND_VIEW_H_*/
|
|
@ -28,6 +28,7 @@
|
|||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
#include "mndView.h"
|
||||
#include "systable.h"
|
||||
#include "tjson.h"
|
||||
#include "thttp.h"
|
||||
|
@ -1262,6 +1263,9 @@ static int32_t mndDropDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb) {
|
|||
/*if (mndDropSubByDB(pMnode, pTrans, pDb) != 0) goto _OVER;*/
|
||||
/*if (mndDropTopicByDB(pMnode, pTrans, pDb) != 0) goto _OVER;*/
|
||||
if (mndDropStreamByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||
#ifdef TD_ENTERPRISE
|
||||
if (mndDropViewByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||
#endif
|
||||
if (mndDropSmasByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||
if (mndDropIdxsByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||
if (mndSetDropDbRedoActions(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||
|
|
|
@ -78,7 +78,7 @@ int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *
|
|||
STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
|
||||
if (NULL == pMeta) {
|
||||
mError("invalid information schema table name:%s", tbName);
|
||||
terrno = TSDB_CODE_MND_INVALID_SYS_TABLENAME;
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ int32_t mndBuildInsTableCfg(SMnode *pMnode, const char *dbFName, const char *tbN
|
|||
STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName));
|
||||
if (NULL == pMeta) {
|
||||
mError("invalid information schema table name:%s", tbName);
|
||||
terrno = TSDB_CODE_MND_INVALID_SYS_TABLENAME;
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
#include "mndView.h"
|
||||
|
||||
static inline int32_t mndAcquireRpc(SMnode *pMnode) {
|
||||
int32_t code = 0;
|
||||
|
@ -447,6 +448,7 @@ static int32_t mndInitSteps(SMnode *pMnode) {
|
|||
if (mndAllocStep(pMnode, "mnode-perfs", mndInitPerfs, mndCleanupPerfs) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-view", mndInitView, mndCleanupView) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-sdb", mndOpenSdb, NULL) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return -1;
|
||||
|
|
|
@ -75,7 +75,7 @@ int32_t mndBuildPerfsTableSchema(SMnode *pMnode, const char *dbFName, const char
|
|||
STableMetaRsp *meta = (STableMetaRsp *)taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
|
||||
if (NULL == meta) {
|
||||
mError("invalid performance schema table name:%s", tbName);
|
||||
terrno = TSDB_CODE_MND_INVALID_SYS_TABLENAME;
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ int32_t mndBuildPerfsTableCfg(SMnode *pMnode, const char *dbFName, const char *t
|
|||
STableMetaRsp *pMeta = taosHashGet(pMnode->perfsMeta, tbName, strlen(tbName));
|
||||
if (NULL == pMeta) {
|
||||
mError("invalid performance schema table name:%s", tbName);
|
||||
terrno = TSDB_CODE_MND_INVALID_SYS_TABLENAME;
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "mndShow.h"
|
||||
#include "mndStb.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndView.h"
|
||||
#include "tglobal.h"
|
||||
#include "tversion.h"
|
||||
#include "audit.h"
|
||||
|
@ -466,7 +467,9 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
|||
SClientHbRsp hbRsp = {.connKey = pHbReq->connKey, .status = 0, .info = NULL, .query = NULL};
|
||||
SRpcConnInfo connInfo = pMsg->info.conn;
|
||||
|
||||
mndUpdateAppInfo(pMnode, pHbReq, &connInfo);
|
||||
if (0 != pHbReq->app.appId) {
|
||||
mndUpdateAppInfo(pMnode, pHbReq, &connInfo);
|
||||
}
|
||||
|
||||
if (pHbReq->query) {
|
||||
SQueryHbReqBasic *pBasic = pHbReq->query;
|
||||
|
@ -529,6 +532,28 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
|||
return -1;
|
||||
}
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
bool needCheck = true;
|
||||
int32_t key = HEARTBEAT_KEY_DYN_VIEW;
|
||||
SDynViewVersion* pDynViewVer = NULL;
|
||||
SKv* pKv = taosHashGet(pHbReq->info, &key, sizeof(key));
|
||||
if (NULL != pKv) {
|
||||
pDynViewVer = pKv->value;
|
||||
mTrace("recv view dyn ver, bootTs:%" PRId64 ", ver:%" PRIu64, pDynViewVer->svrBootTs, pDynViewVer->dynViewVer);
|
||||
|
||||
SDynViewVersion* pRspVer = NULL;
|
||||
if (0 != mndValidateDynViewVersion(pMnode, pDynViewVer, &needCheck, &pRspVer)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (needCheck) {
|
||||
SKv kv1 = {.key = HEARTBEAT_KEY_DYN_VIEW, .valueLen = sizeof(*pDynViewVer), .value = pRspVer};
|
||||
taosArrayPush(hbRsp.info, &kv1);
|
||||
mTrace("need to check view ver, lastest bootTs:%" PRId64 ", ver:%" PRIu64, pRspVer->svrBootTs, pRspVer->dynViewVer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void *pIter = taosHashIterate(pHbReq->info, NULL);
|
||||
while (pIter != NULL) {
|
||||
SKv *kv = pIter;
|
||||
|
@ -564,6 +589,25 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
|
|||
}
|
||||
break;
|
||||
}
|
||||
#ifdef TD_ENTERPRISE
|
||||
case HEARTBEAT_KEY_DYN_VIEW: {
|
||||
break;
|
||||
}
|
||||
case HEARTBEAT_KEY_VIEWINFO: {
|
||||
if (!needCheck) {
|
||||
break;
|
||||
}
|
||||
|
||||
void *rspMsg = NULL;
|
||||
int32_t rspLen = 0;
|
||||
mndValidateViewInfo(pMnode, kv->value, kv->valueLen / sizeof(SViewVersion), &rspMsg, &rspLen);
|
||||
if (rspMsg && rspLen > 0) {
|
||||
SKv kv1 = {.key = HEARTBEAT_KEY_VIEWINFO, .valueLen = rspLen, .value = rspMsg};
|
||||
taosArrayPush(hbRsp.info, &kv1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
mError("invalid kv key:%d", kv->key);
|
||||
hbRsp.status = TSDB_CODE_APP_ERROR;
|
||||
|
|
|
@ -116,6 +116,8 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
|
|||
type = TSDB_MGMT_TABLE_STREAM_TASKS;
|
||||
} else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
|
||||
type = TSDB_MGMT_TABLE_PRIVILEGES;
|
||||
} else if (strncasecmp(name, TSDB_INS_TABLE_VIEWS, len) == 0) {
|
||||
type = TSDB_MGMT_TABLE_VIEWS;
|
||||
} else {
|
||||
mError("invalid show name:%s len:%d", name, len);
|
||||
}
|
||||
|
@ -211,7 +213,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
|
|||
if (pMeta == NULL) {
|
||||
pMeta = taosHashGet(pMnode->perfsMeta, retrieveReq.tb, strlen(retrieveReq.tb));
|
||||
if (pMeta == NULL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_SYS_TABLENAME;
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
mError("failed to process show-retrieve req:%p since %s", pShow, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -1903,8 +1903,51 @@ static int32_t mndBuildStbCfgImp(SDbObj *pDb, SStbObj *pStb, const char *tbName,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndBuildStbSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp,
|
||||
int32_t *smaVer) {
|
||||
static int32_t mndValidateStbVersion(SMnode *pMnode, SSTableVersion* pStbVer, bool* schema, bool* sma) {
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
snprintf(tbFName, sizeof(tbFName), "%s.%s", pStbVer->dbFName, pStbVer->stbName);
|
||||
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pStbVer->dbFName);
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pDb->uid != pStbVer->dbId) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SStbObj *pStb = mndAcquireStb(pMnode, tbFName);
|
||||
if (pStb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosRLockLatch(&pStb->lock);
|
||||
|
||||
if (pStbVer->sversion != pStb->colVer || pStbVer->tversion != pStb->tagVer) {
|
||||
*schema = true;
|
||||
} else {
|
||||
*schema = false;
|
||||
}
|
||||
|
||||
if (pStbVer->smaVer && pStbVer->smaVer != pStb->smaVer) {
|
||||
*sma = true;
|
||||
} else {
|
||||
*sma = false;
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&pStb->lock);
|
||||
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
mndReleaseStb(pMnode, pStb);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mndBuildStbSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp) {
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
snprintf(tbFName, sizeof(tbFName), "%s.%s", dbFName, tbName);
|
||||
|
||||
|
@ -1921,10 +1964,6 @@ static int32_t mndBuildStbSchema(SMnode *pMnode, const char *dbFName, const char
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (smaVer) {
|
||||
*smaVer = pStb->smaVer;
|
||||
}
|
||||
|
||||
int32_t code = mndBuildStbSchemaImp(pDb, pStb, tbName, pRsp);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
mndReleaseStb(pMnode, pStb);
|
||||
|
@ -2563,7 +2602,7 @@ static int32_t mndProcessTableMetaReq(SRpcMsg *pReq) {
|
|||
}
|
||||
} else {
|
||||
mInfo("stb:%s.%s, start to retrieve meta", infoReq.dbFName, infoReq.tbName);
|
||||
if (mndBuildStbSchema(pMnode, infoReq.dbFName, infoReq.tbName, &metaRsp, NULL) != 0) {
|
||||
if (mndBuildStbSchema(pMnode, infoReq.dbFName, infoReq.tbName, &metaRsp) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
@ -2674,14 +2713,15 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t
|
|||
for (int32_t i = 0; i < numOfStbs; ++i) {
|
||||
SSTableVersion *pStbVersion = &pStbVersions[i];
|
||||
pStbVersion->suid = be64toh(pStbVersion->suid);
|
||||
pStbVersion->sversion = ntohs(pStbVersion->sversion);
|
||||
pStbVersion->tversion = ntohs(pStbVersion->tversion);
|
||||
pStbVersion->sversion = ntohl(pStbVersion->sversion);
|
||||
pStbVersion->tversion = ntohl(pStbVersion->tversion);
|
||||
pStbVersion->smaVer = ntohl(pStbVersion->smaVer);
|
||||
|
||||
STableMetaRsp metaRsp = {0};
|
||||
int32_t smaVer = 0;
|
||||
mInfo("stb:%s.%s, start to retrieve meta", pStbVersion->dbFName, pStbVersion->stbName);
|
||||
if (mndBuildStbSchema(pMnode, pStbVersion->dbFName, pStbVersion->stbName, &metaRsp, &smaVer) != 0) {
|
||||
bool schema = false;
|
||||
bool sma = false;
|
||||
int32_t code = mndValidateStbVersion(pMnode, pStbVersion, &schema, &sma);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
STableMetaRsp metaRsp = {0};
|
||||
metaRsp.numOfColumns = -1;
|
||||
metaRsp.suid = pStbVersion->suid;
|
||||
tstrncpy(metaRsp.dbFName, pStbVersion->dbFName, sizeof(metaRsp.dbFName));
|
||||
|
@ -2691,13 +2731,23 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t
|
|||
continue;
|
||||
}
|
||||
|
||||
if (pStbVersion->sversion != metaRsp.sversion || pStbVersion->tversion != metaRsp.tversion) {
|
||||
if (schema) {
|
||||
STableMetaRsp metaRsp = {0};
|
||||
mInfo("stb:%s.%s, start to retrieve meta", pStbVersion->dbFName, pStbVersion->stbName);
|
||||
if (mndBuildStbSchema(pMnode, pStbVersion->dbFName, pStbVersion->stbName, &metaRsp) != 0) {
|
||||
metaRsp.numOfColumns = -1;
|
||||
metaRsp.suid = pStbVersion->suid;
|
||||
tstrncpy(metaRsp.dbFName, pStbVersion->dbFName, sizeof(metaRsp.dbFName));
|
||||
tstrncpy(metaRsp.tbName, pStbVersion->stbName, sizeof(metaRsp.tbName));
|
||||
tstrncpy(metaRsp.stbName, pStbVersion->stbName, sizeof(metaRsp.stbName));
|
||||
taosArrayPush(hbRsp.pMetaRsp, &metaRsp);
|
||||
continue;
|
||||
}
|
||||
|
||||
taosArrayPush(hbRsp.pMetaRsp, &metaRsp);
|
||||
} else {
|
||||
tFreeSTableMetaRsp(&metaRsp);
|
||||
}
|
||||
|
||||
if (pStbVersion->smaVer && pStbVersion->smaVer != smaVer) {
|
||||
if (sma) {
|
||||
bool exist = false;
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
STableIndexRsp indexRsp = {0};
|
||||
|
|
|
@ -720,7 +720,7 @@ int32_t mndSetRpcInfoForDbTrans(SMnode *pMnode, SRpcMsg *pMsg, EOperType oper, c
|
|||
|
||||
void mndTransSetDbName(STrans *pTrans, const char *dbname, const char *stbname) {
|
||||
if (dbname != NULL) {
|
||||
tstrncpy(pTrans->dbname, dbname, TSDB_TABLE_FNAME_LEN);
|
||||
tstrncpy(pTrans->dbname, dbname, TSDB_DB_FNAME_LEN);
|
||||
}
|
||||
if (stbname != NULL) {
|
||||
tstrncpy(pTrans->stbname, stbname, TSDB_TABLE_FNAME_LEN);
|
||||
|
|
|
@ -28,9 +28,53 @@
|
|||
|
||||
// clang-format on
|
||||
|
||||
#define USER_VER_NUMBER 5
|
||||
#define USER_VER_NUMBER 6
|
||||
#define USER_RESERVE_SIZE 64
|
||||
|
||||
#define BIT_FLAG_MASK(n) (1 << n)
|
||||
#define BIT_FLAG_SET_MASK(val, mask) ((val) |= (mask))
|
||||
#define BIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
||||
#define PRIVILEGE_TYPE_ALL BIT_FLAG_MASK(0)
|
||||
#define PRIVILEGE_TYPE_READ BIT_FLAG_MASK(1)
|
||||
#define PRIVILEGE_TYPE_WRITE BIT_FLAG_MASK(2)
|
||||
#define PRIVILEGE_TYPE_SUBSCRIBE BIT_FLAG_MASK(3)
|
||||
#define PRIVILEGE_TYPE_ALTER BIT_FLAG_MASK(4)
|
||||
|
||||
#define ALTER_USER_ADD_PRIVS(_type) ((_type) == TSDB_ALTER_USER_ADD_PRIVILEGES)
|
||||
#define ALTER_USER_DEL_PRIVS(_type) ((_type) == TSDB_ALTER_USER_DEL_PRIVILEGES)
|
||||
|
||||
#define ALTER_USER_ALL_PRIV(_priv) (BIT_FLAG_TEST_MASK((_priv), PRIVILEGE_TYPE_ALL))
|
||||
#define ALTER_USER_READ_PRIV(_priv) (BIT_FLAG_TEST_MASK((_priv), PRIVILEGE_TYPE_READ) || BIT_FLAG_TEST_MASK((_priv), PRIVILEGE_TYPE_ALL))
|
||||
#define ALTER_USER_WRITE_PRIV(_priv) (BIT_FLAG_TEST_MASK((_priv), PRIVILEGE_TYPE_WRITE) || BIT_FLAG_TEST_MASK((_priv), PRIVILEGE_TYPE_ALL))
|
||||
#define ALTER_USER_ALTER_PRIV(_priv) (BIT_FLAG_TEST_MASK((_priv), PRIVILEGE_TYPE_ALTER) || BIT_FLAG_TEST_MASK((_priv), PRIVILEGE_TYPE_ALL))
|
||||
#define ALTER_USER_SUBSCRIBE_PRIV(_priv) (BIT_FLAG_TEST_MASK((_priv), PRIVILEGE_TYPE_SUBSCRIBE))
|
||||
|
||||
#define ALTER_USER_TARGET_DB(_tbname) (0 == (_tbname)[0])
|
||||
#define ALTER_USER_TARGET_TB(_tbname) (0 != (_tbname)[0])
|
||||
|
||||
#define ALTER_USER_ADD_READ_DB_PRIV(_type, _priv, _tbname) (ALTER_USER_ADD_PRIVS(_type) && ALTER_USER_READ_PRIV(_priv) && ALTER_USER_TARGET_DB(_tbname))
|
||||
#define ALTER_USER_DEL_READ_DB_PRIV(_type, _priv, _tbname) (ALTER_USER_DEL_PRIVS(_type) && ALTER_USER_READ_PRIV(_priv) && ALTER_USER_TARGET_DB(_tbname))
|
||||
#define ALTER_USER_ADD_WRITE_DB_PRIV(_type, _priv, _tbname) (ALTER_USER_ADD_PRIVS(_type) && ALTER_USER_WRITE_PRIV(_priv) && ALTER_USER_TARGET_DB(_tbname))
|
||||
#define ALTER_USER_DEL_WRITE_DB_PRIV(_type, _priv, _tbname) (ALTER_USER_DEL_PRIVS(_type) && ALTER_USER_WRITE_PRIV(_priv) && ALTER_USER_TARGET_DB(_tbname))
|
||||
#define ALTER_USER_ADD_ALTER_DB_PRIV(_type, _priv, _tbname) (ALTER_USER_ADD_PRIVS(_type) && ALTER_USER_ALTER_PRIV(_priv) && ALTER_USER_TARGET_DB(_tbname))
|
||||
#define ALTER_USER_DEL_ALTER_DB_PRIV(_type, _priv, _tbname) (ALTER_USER_DEL_PRIVS(_type) && ALTER_USER_ALTER_PRIV(_priv) && ALTER_USER_TARGET_DB(_tbname))
|
||||
#define ALTER_USER_ADD_ALL_DB_PRIV(_type, _priv, _tbname) (ALTER_USER_ADD_PRIVS(_type) && ALTER_USER_ALL_PRIV(_priv) && ALTER_USER_TARGET_DB(_tbname))
|
||||
#define ALTER_USER_DEL_ALL_DB_PRIV(_type, _priv, _tbname) (ALTER_USER_DEL_PRIVS(_type) && ALTER_USER_ALL_PRIV(_priv) && ALTER_USER_TARGET_DB(_tbname))
|
||||
|
||||
#define ALTER_USER_ADD_READ_TB_PRIV(_type, _priv, _tbname) (ALTER_USER_ADD_PRIVS(_type) && ALTER_USER_READ_PRIV(_priv) && ALTER_USER_TARGET_TB(_tbname))
|
||||
#define ALTER_USER_DEL_READ_TB_PRIV(_type, _priv, _tbname) (ALTER_USER_DEL_PRIVS(_type) && ALTER_USER_READ_PRIV(_priv) && ALTER_USER_TARGET_TB(_tbname))
|
||||
#define ALTER_USER_ADD_WRITE_TB_PRIV(_type, _priv, _tbname) (ALTER_USER_ADD_PRIVS(_type) && ALTER_USER_WRITE_PRIV(_priv) && ALTER_USER_TARGET_TB(_tbname))
|
||||
#define ALTER_USER_DEL_WRITE_TB_PRIV(_type, _priv, _tbname) (ALTER_USER_DEL_PRIVS(_type) && ALTER_USER_WRITE_PRIV(_priv) && ALTER_USER_TARGET_TB(_tbname))
|
||||
#define ALTER_USER_ADD_ALTER_TB_PRIV(_type, _priv, _tbname) (ALTER_USER_ADD_PRIVS(_type) && ALTER_USER_ALTER_PRIV(_priv) && ALTER_USER_TARGET_TB(_tbname))
|
||||
#define ALTER_USER_DEL_ALTER_TB_PRIV(_type, _priv, _tbname) (ALTER_USER_DEL_PRIVS(_type) && ALTER_USER_ALTER_PRIV(_priv) && ALTER_USER_TARGET_TB(_tbname))
|
||||
#define ALTER_USER_ADD_ALL_TB_PRIV(_type, _priv, _tbname) (ALTER_USER_ADD_PRIVS(_type) && ALTER_USER_ALL_PRIV(_priv) && ALTER_USER_TARGET_TB(_tbname))
|
||||
#define ALTER_USER_DEL_ALL_TB_PRIV(_type, _priv, _tbname) (ALTER_USER_DEL_PRIVS(_type) && ALTER_USER_ALL_PRIV(_priv) && ALTER_USER_TARGET_TB(_tbname))
|
||||
|
||||
#define ALTER_USER_ADD_SUBSCRIBE_TOPIC_PRIV(_type, _priv) (ALTER_USER_ADD_PRIVS(_type) && ALTER_USER_SUBSCRIBE_PRIV(_priv))
|
||||
#define ALTER_USER_DEL_SUBSCRIBE_TOPIC_PRIV(_type, _priv) (ALTER_USER_DEL_PRIVS(_type) && ALTER_USER_SUBSCRIBE_PRIV(_priv))
|
||||
|
||||
|
||||
static SIpWhiteList *createDefaultIpWhiteList();
|
||||
SIpWhiteList *createIpWhiteList(void *buf, int32_t len);
|
||||
static bool updateIpWhiteList(SIpWhiteList *pOld, SIpWhiteList *pNew);
|
||||
|
@ -656,8 +700,12 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
|||
pUser->pIpWhiteList ? (sizeof(SIpV4Range) * pUser->pIpWhiteList->num + sizeof(SIpWhiteList) + 4) : 16;
|
||||
int32_t numOfReadDbs = taosHashGetSize(pUser->readDbs);
|
||||
int32_t numOfWriteDbs = taosHashGetSize(pUser->writeDbs);
|
||||
int32_t numOfReadStbs = taosHashGetSize(pUser->readTbs);
|
||||
int32_t numOfWriteStbs = taosHashGetSize(pUser->writeTbs);
|
||||
int32_t numOfReadTbs = taosHashGetSize(pUser->readTbs);
|
||||
int32_t numOfWriteTbs = taosHashGetSize(pUser->writeTbs);
|
||||
int32_t numOfAlterTbs = taosHashGetSize(pUser->alterTbs);
|
||||
int32_t numOfReadViews = taosHashGetSize(pUser->readViews);
|
||||
int32_t numOfWriteViews = taosHashGetSize(pUser->writeViews);
|
||||
int32_t numOfAlterViews = taosHashGetSize(pUser->alterViews);
|
||||
int32_t numOfTopics = taosHashGetSize(pUser->topics);
|
||||
int32_t numOfUseDbs = taosHashGetSize(pUser->useDbs);
|
||||
int32_t size = sizeof(SUserObj) + USER_RESERVE_SIZE +
|
||||
|
@ -692,6 +740,62 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
|||
stb = taosHashIterate(pUser->writeTbs, stb);
|
||||
}
|
||||
|
||||
stb = taosHashIterate(pUser->alterTbs, 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->alterTbs, stb);
|
||||
}
|
||||
|
||||
stb = taosHashIterate(pUser->readViews, 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->readViews, stb);
|
||||
}
|
||||
|
||||
stb = taosHashIterate(pUser->writeViews, 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->writeViews, stb);
|
||||
}
|
||||
|
||||
stb = taosHashIterate(pUser->alterViews, 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->alterViews, stb);
|
||||
}
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, USER_VER_NUMBER, size);
|
||||
if (pRaw == NULL) goto _OVER;
|
||||
|
||||
|
@ -729,8 +833,12 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
|||
topic = taosHashIterate(pUser->topics, topic);
|
||||
}
|
||||
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfReadStbs, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfWriteStbs, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfReadTbs, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfWriteTbs, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfAlterTbs, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfReadViews, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfWriteViews, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfAlterViews, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, numOfUseDbs, _OVER)
|
||||
|
||||
stb = taosHashIterate(pUser->readTbs, NULL);
|
||||
|
@ -761,6 +869,62 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
|||
stb = taosHashIterate(pUser->writeTbs, stb);
|
||||
}
|
||||
|
||||
stb = taosHashIterate(pUser->alterTbs, 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->alterTbs, stb);
|
||||
}
|
||||
|
||||
stb = taosHashIterate(pUser->readViews, 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->readViews, stb);
|
||||
}
|
||||
|
||||
stb = taosHashIterate(pUser->writeViews, 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->writeViews, stb);
|
||||
}
|
||||
|
||||
stb = taosHashIterate(pUser->alterViews, 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->alterViews, stb);
|
||||
}
|
||||
|
||||
int32_t *useDb = taosHashIterate(pUser->useDbs, NULL);
|
||||
while (useDb != NULL) {
|
||||
size_t keyLen = 0;
|
||||
|
@ -873,20 +1037,40 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
|||
}
|
||||
|
||||
if (sver >= 3) {
|
||||
int32_t numOfReadStbs = 0;
|
||||
int32_t numOfWriteStbs = 0;
|
||||
int32_t numOfReadTbs = 0;
|
||||
int32_t numOfWriteTbs = 0;
|
||||
int32_t numOfAlterTbs = 0;
|
||||
int32_t numOfReadViews = 0;
|
||||
int32_t numOfWriteViews = 0;
|
||||
int32_t numOfAlterViews = 0;
|
||||
int32_t numOfUseDbs = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfReadStbs, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfWriteStbs, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfReadTbs, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfWriteTbs, _OVER)
|
||||
if (sver >= 6) {
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfAlterTbs, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfReadViews, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfWriteViews, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfAlterViews, _OVER)
|
||||
}
|
||||
SDB_GET_INT32(pRaw, dataPos, &numOfUseDbs, _OVER)
|
||||
|
||||
pUser->readTbs =
|
||||
taosHashInit(numOfReadStbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
taosHashInit(numOfReadTbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pUser->writeTbs =
|
||||
taosHashInit(numOfWriteStbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
taosHashInit(numOfWriteTbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pUser->alterTbs =
|
||||
taosHashInit(numOfAlterTbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
|
||||
pUser->readViews =
|
||||
taosHashInit(numOfReadViews, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pUser->writeViews =
|
||||
taosHashInit(numOfWriteViews, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
pUser->alterViews =
|
||||
taosHashInit(numOfAlterViews, 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) {
|
||||
for (int32_t i = 0; i < numOfReadTbs; ++i) {
|
||||
int32_t keyLen = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &keyLen, _OVER);
|
||||
|
||||
|
@ -906,7 +1090,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
|||
taosMemoryFree(value);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfWriteStbs; ++i) {
|
||||
for (int32_t i = 0; i < numOfWriteTbs; ++i) {
|
||||
int32_t keyLen = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &keyLen, _OVER);
|
||||
|
||||
|
@ -926,6 +1110,88 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
|||
taosMemoryFree(value);
|
||||
}
|
||||
|
||||
if (sver >= 6) {
|
||||
for (int32_t i = 0; i < numOfAlterTbs; ++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->alterTbs, key, keyLen, value, valuelen);
|
||||
|
||||
taosMemoryFree(key);
|
||||
taosMemoryFree(value);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfReadViews; ++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->readViews, key, keyLen, value, valuelen);
|
||||
|
||||
taosMemoryFree(key);
|
||||
taosMemoryFree(value);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfWriteViews; ++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->writeViews, key, keyLen, value, valuelen);
|
||||
|
||||
taosMemoryFree(key);
|
||||
taosMemoryFree(value);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfAlterViews; ++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->alterViews, 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);
|
||||
|
@ -975,6 +1241,10 @@ _OVER:
|
|||
taosHashCleanup(pUser->topics);
|
||||
taosHashCleanup(pUser->readTbs);
|
||||
taosHashCleanup(pUser->writeTbs);
|
||||
taosHashCleanup(pUser->alterTbs);
|
||||
taosHashCleanup(pUser->readViews);
|
||||
taosHashCleanup(pUser->writeViews);
|
||||
taosHashCleanup(pUser->alterViews);
|
||||
taosHashCleanup(pUser->useDbs);
|
||||
taosMemoryFreeClear(pUser->pIpWhiteList);
|
||||
}
|
||||
|
@ -1062,6 +1332,10 @@ int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
|
|||
pNew->writeDbs = mndDupDbHash(pUser->writeDbs);
|
||||
pNew->readTbs = mndDupTableHash(pUser->readTbs);
|
||||
pNew->writeTbs = mndDupTableHash(pUser->writeTbs);
|
||||
pNew->alterTbs = mndDupTableHash(pUser->alterTbs);
|
||||
pNew->readViews = mndDupTableHash(pUser->readViews);
|
||||
pNew->writeViews = mndDupTableHash(pUser->writeViews);
|
||||
pNew->alterViews = mndDupTableHash(pUser->alterViews);
|
||||
pNew->topics = mndDupTopicHash(pUser->topics);
|
||||
pNew->useDbs = mndDupUseDbHash(pUser->useDbs);
|
||||
pNew->pIpWhiteList = cloneIpWhiteList(pUser->pIpWhiteList);
|
||||
|
@ -1080,6 +1354,10 @@ void mndUserFreeObj(SUserObj *pUser) {
|
|||
taosHashCleanup(pUser->topics);
|
||||
taosHashCleanup(pUser->readTbs);
|
||||
taosHashCleanup(pUser->writeTbs);
|
||||
taosHashCleanup(pUser->alterTbs);
|
||||
taosHashCleanup(pUser->readViews);
|
||||
taosHashCleanup(pUser->writeViews);
|
||||
taosHashCleanup(pUser->alterViews);
|
||||
taosHashCleanup(pUser->useDbs);
|
||||
taosMemoryFreeClear(pUser->pIpWhiteList);
|
||||
pUser->readDbs = NULL;
|
||||
|
@ -1087,6 +1365,10 @@ void mndUserFreeObj(SUserObj *pUser) {
|
|||
pUser->topics = NULL;
|
||||
pUser->readTbs = NULL;
|
||||
pUser->writeTbs = NULL;
|
||||
pUser->alterTbs = NULL;
|
||||
pUser->readViews = NULL;
|
||||
pUser->writeViews = NULL;
|
||||
pUser->alterViews = NULL;
|
||||
pUser->useDbs = NULL;
|
||||
}
|
||||
|
||||
|
@ -1110,6 +1392,10 @@ static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) {
|
|||
TSWAP(pOld->topics, pNew->topics);
|
||||
TSWAP(pOld->readTbs, pNew->readTbs);
|
||||
TSWAP(pOld->writeTbs, pNew->writeTbs);
|
||||
TSWAP(pOld->alterTbs, pNew->alterTbs);
|
||||
TSWAP(pOld->readViews, pNew->readViews);
|
||||
TSWAP(pOld->writeViews, pNew->writeViews);
|
||||
TSWAP(pOld->alterViews, pNew->alterViews);
|
||||
TSWAP(pOld->useDbs, pNew->useDbs);
|
||||
|
||||
int32_t sz = sizeof(SIpWhiteList) + pNew->pIpWhiteList->num * sizeof(SIpV4Range);
|
||||
|
@ -1429,7 +1715,7 @@ static int32_t mndTablePriviledge(SMnode *pMnode, SHashObj *hash, SHashObj *useD
|
|||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (taosHashPut(hash, tbFName, len, "t", 2) != 0) {
|
||||
if (taosHashPut(hash, tbFName, len, alterReq->isView ? "v" : "t", 2) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -1481,60 +1767,162 @@ static char *mndUserAuditTypeStr(int32_t type) {
|
|||
if (type == TSDB_ALTER_USER_SUPERUSER) {
|
||||
return "changeSuperUser";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_ADD_READ_DB) {
|
||||
return "addReadToDB";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_ADD_READ_DB) {
|
||||
return "addReadToDB";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_REMOVE_READ_DB) {
|
||||
return "removeReadFromDB";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_ADD_WRITE_DB) {
|
||||
return "addWriteToDB";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_REMOVE_WRITE_DB) {
|
||||
return "removeWriteFromDB";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_ADD_ALL_DB) {
|
||||
return "addToAllDB";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_REMOVE_ALL_DB) {
|
||||
return "removeFromAllDB";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_ENABLE) {
|
||||
return "enableUser";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_SYSINFO) {
|
||||
return "userSysInfo";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC) {
|
||||
return "addSubscribeTopic";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC) {
|
||||
return "removeSubscribeTopic";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_ADD_READ_TABLE) {
|
||||
return "addReadToTable";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_REMOVE_READ_TABLE) {
|
||||
return "removeReadFromTable";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_ADD_WRITE_TABLE) {
|
||||
return "addWriteToTable";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_REMOVE_WRITE_TABLE) {
|
||||
return "removeWriteFromTable";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_ADD_ALL_TABLE) {
|
||||
return "addToAllTable";
|
||||
}
|
||||
if (type == TSDB_ALTER_USER_REMOVE_ALL_TABLE) {
|
||||
return "removeFromAllTable";
|
||||
}
|
||||
return "error";
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterUserPrivilegesReq(SAlterUserReq *pAlterReq, SMnode *pMnode, SUserObj* pNewUser) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
|
||||
if (ALTER_USER_ADD_READ_DB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName) ||
|
||||
ALTER_USER_ADD_ALL_DB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName)) {
|
||||
if (strcmp(pAlterReq->objname, "1.*") != 0) {
|
||||
int32_t len = strlen(pAlterReq->objname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pAlterReq->objname);
|
||||
if (pDb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
return -1;
|
||||
}
|
||||
if (taosHashPut(pNewUser->readDbs, pAlterReq->objname, len, pAlterReq->objname, TSDB_DB_FNAME_LEN) != 0) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
return -1;
|
||||
}
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
} else {
|
||||
while (1) {
|
||||
SDbObj *pDb = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_DB, pIter, (void **)&pDb);
|
||||
if (pIter == NULL) break;
|
||||
int32_t len = strlen(pDb->name) + 1;
|
||||
taosHashPut(pNewUser->readDbs, pDb->name, len, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
sdbRelease(pSdb, pDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ALTER_USER_ADD_WRITE_DB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName) || ALTER_USER_ADD_ALL_DB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName)) {
|
||||
if (strcmp(pAlterReq->objname, "1.*") != 0) {
|
||||
int32_t len = strlen(pAlterReq->objname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pAlterReq->objname);
|
||||
if (pDb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
return -1;
|
||||
}
|
||||
if (taosHashPut(pNewUser->writeDbs, pAlterReq->objname, len, pAlterReq->objname, TSDB_DB_FNAME_LEN) != 0) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
return -1;
|
||||
}
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
} else {
|
||||
while (1) {
|
||||
SDbObj *pDb = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_DB, pIter, (void **)&pDb);
|
||||
if (pIter == NULL) break;
|
||||
int32_t len = strlen(pDb->name) + 1;
|
||||
taosHashPut(pNewUser->writeDbs, pDb->name, len, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
sdbRelease(pSdb, pDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ALTER_USER_DEL_READ_DB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName) || ALTER_USER_DEL_ALL_DB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName)) {
|
||||
if (strcmp(pAlterReq->objname, "1.*") != 0) {
|
||||
int32_t len = strlen(pAlterReq->objname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pAlterReq->objname);
|
||||
if (pDb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
return -1;
|
||||
}
|
||||
taosHashRemove(pNewUser->readDbs, pAlterReq->objname, len);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
} else {
|
||||
taosHashClear(pNewUser->readDbs);
|
||||
}
|
||||
}
|
||||
|
||||
if (ALTER_USER_DEL_WRITE_DB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName) || ALTER_USER_DEL_ALL_DB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName)) {
|
||||
if (strcmp(pAlterReq->objname, "1.*") != 0) {
|
||||
int32_t len = strlen(pAlterReq->objname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pAlterReq->objname);
|
||||
if (pDb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
return -1;
|
||||
}
|
||||
taosHashRemove(pNewUser->writeDbs, pAlterReq->objname, len);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
} else {
|
||||
taosHashClear(pNewUser->writeDbs);
|
||||
}
|
||||
}
|
||||
|
||||
SHashObj* pReadTbs = pNewUser->readTbs;
|
||||
SHashObj* pWriteTbs = pNewUser->writeTbs;
|
||||
SHashObj* pAlterTbs = pNewUser->alterTbs;
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
if (pAlterReq->isView) {
|
||||
pReadTbs = pNewUser->readViews;
|
||||
pWriteTbs = pNewUser->writeViews;
|
||||
pAlterTbs = pNewUser->alterViews;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ALTER_USER_ADD_READ_TB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName) || ALTER_USER_ADD_ALL_TB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName)) {
|
||||
if (mndTablePriviledge(pMnode, pReadTbs, pNewUser->useDbs, pAlterReq, pSdb) != 0) return -1;
|
||||
}
|
||||
|
||||
if (ALTER_USER_ADD_WRITE_TB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName) || ALTER_USER_ADD_ALL_TB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName)) {
|
||||
if (mndTablePriviledge(pMnode, pWriteTbs, pNewUser->useDbs, pAlterReq, pSdb) != 0) return -1;
|
||||
}
|
||||
|
||||
if (ALTER_USER_ADD_ALTER_TB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName) || ALTER_USER_ADD_ALL_TB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName)) {
|
||||
if (mndTablePriviledge(pMnode, pAlterTbs, pNewUser->useDbs, pAlterReq, pSdb) != 0) return -1;
|
||||
}
|
||||
|
||||
if (ALTER_USER_DEL_READ_TB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName) ||
|
||||
ALTER_USER_DEL_ALL_TB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName)) {
|
||||
if (mndRemoveTablePriviledge(pMnode, pReadTbs, pNewUser->useDbs, pAlterReq, pSdb) != 0) return -1;
|
||||
}
|
||||
|
||||
if (ALTER_USER_DEL_WRITE_TB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName) ||
|
||||
ALTER_USER_DEL_ALL_TB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName)) {
|
||||
if (mndRemoveTablePriviledge(pMnode, pWriteTbs, pNewUser->useDbs, pAlterReq, pSdb) != 0) return -1;
|
||||
}
|
||||
|
||||
if (ALTER_USER_DEL_ALTER_TB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName) ||
|
||||
ALTER_USER_DEL_ALL_TB_PRIV(pAlterReq->alterType, pAlterReq->privileges, pAlterReq->tabName)) {
|
||||
if (mndRemoveTablePriviledge(pMnode, pAlterTbs, pNewUser->useDbs, pAlterReq, pSdb) != 0) return -1;
|
||||
}
|
||||
|
||||
if (ALTER_USER_ADD_SUBSCRIBE_TOPIC_PRIV(pAlterReq->alterType, pAlterReq->privileges)) {
|
||||
int32_t len = strlen(pAlterReq->objname) + 1;
|
||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, pAlterReq->objname);
|
||||
if (pTopic == NULL) {
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
return -1;
|
||||
}
|
||||
taosHashPut(pNewUser->topics, pTopic->name, len, pTopic->name, TSDB_TOPIC_FNAME_LEN);
|
||||
}
|
||||
|
||||
if (ALTER_USER_DEL_SUBSCRIBE_TOPIC_PRIV(pAlterReq->alterType, pAlterReq->privileges)) {
|
||||
int32_t len = strlen(pAlterReq->objname) + 1;
|
||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, pAlterReq->objname);
|
||||
if (pTopic == NULL) {
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
return -1;
|
||||
}
|
||||
taosHashRemove(pNewUser->topics, pAlterReq->objname, len);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
@ -1602,122 +1990,8 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
|||
newUser.sysInfo = alterReq.sysInfo;
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_ADD_READ_DB || alterReq.alterType == TSDB_ALTER_USER_ADD_ALL_DB) {
|
||||
if (strcmp(alterReq.objname, "1.*") != 0) {
|
||||
int32_t len = strlen(alterReq.objname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, alterReq.objname);
|
||||
if (pDb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosHashPut(newUser.readDbs, alterReq.objname, len, alterReq.objname, TSDB_DB_FNAME_LEN) != 0) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
goto _OVER;
|
||||
}
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
} else {
|
||||
while (1) {
|
||||
SDbObj *pDb = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_DB, pIter, (void **)&pDb);
|
||||
if (pIter == NULL) break;
|
||||
int32_t len = strlen(pDb->name) + 1;
|
||||
taosHashPut(newUser.readDbs, pDb->name, len, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
sdbRelease(pSdb, pDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_DB || alterReq.alterType == TSDB_ALTER_USER_ADD_ALL_DB) {
|
||||
if (strcmp(alterReq.objname, "1.*") != 0) {
|
||||
int32_t len = strlen(alterReq.objname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, alterReq.objname);
|
||||
if (pDb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosHashPut(newUser.writeDbs, alterReq.objname, len, alterReq.objname, TSDB_DB_FNAME_LEN) != 0) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
goto _OVER;
|
||||
}
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
} else {
|
||||
while (1) {
|
||||
SDbObj *pDb = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_DB, pIter, (void **)&pDb);
|
||||
if (pIter == NULL) break;
|
||||
int32_t len = strlen(pDb->name) + 1;
|
||||
taosHashPut(newUser.writeDbs, pDb->name, len, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
sdbRelease(pSdb, pDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_READ_DB || alterReq.alterType == TSDB_ALTER_USER_REMOVE_ALL_DB) {
|
||||
if (strcmp(alterReq.objname, "1.*") != 0) {
|
||||
int32_t len = strlen(alterReq.objname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, alterReq.objname);
|
||||
if (pDb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
goto _OVER;
|
||||
}
|
||||
taosHashRemove(newUser.readDbs, alterReq.objname, len);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
} else {
|
||||
taosHashClear(newUser.readDbs);
|
||||
}
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_WRITE_DB || alterReq.alterType == TSDB_ALTER_USER_REMOVE_ALL_DB) {
|
||||
if (strcmp(alterReq.objname, "1.*") != 0) {
|
||||
int32_t len = strlen(alterReq.objname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, alterReq.objname);
|
||||
if (pDb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
goto _OVER;
|
||||
}
|
||||
taosHashRemove(newUser.writeDbs, alterReq.objname, len);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
} else {
|
||||
taosHashClear(newUser.writeDbs);
|
||||
}
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_ADD_READ_TABLE || alterReq.alterType == TSDB_ALTER_USER_ADD_ALL_TABLE) {
|
||||
if (mndTablePriviledge(pMnode, newUser.readTbs, newUser.useDbs, &alterReq, pSdb) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_TABLE || alterReq.alterType == TSDB_ALTER_USER_ADD_ALL_TABLE) {
|
||||
if (mndTablePriviledge(pMnode, newUser.writeTbs, newUser.useDbs, &alterReq, pSdb) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_READ_TABLE ||
|
||||
alterReq.alterType == TSDB_ALTER_USER_REMOVE_ALL_TABLE) {
|
||||
if (mndRemoveTablePriviledge(pMnode, newUser.readTbs, newUser.useDbs, &alterReq, pSdb) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_WRITE_TABLE ||
|
||||
alterReq.alterType == TSDB_ALTER_USER_REMOVE_ALL_TABLE) {
|
||||
if (mndRemoveTablePriviledge(pMnode, newUser.writeTbs, newUser.useDbs, &alterReq, pSdb) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC) {
|
||||
int32_t len = strlen(alterReq.objname) + 1;
|
||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, alterReq.objname);
|
||||
if (pTopic == NULL) {
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
goto _OVER;
|
||||
}
|
||||
taosHashPut(newUser.topics, pTopic->name, len, pTopic->name, TSDB_TOPIC_FNAME_LEN);
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC) {
|
||||
int32_t len = strlen(alterReq.objname) + 1;
|
||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, alterReq.objname);
|
||||
if (pTopic == NULL) {
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
goto _OVER;
|
||||
}
|
||||
taosHashRemove(newUser.topics, alterReq.objname, len);
|
||||
if (ALTER_USER_ADD_PRIVS(alterReq.alterType) || ALTER_USER_DEL_PRIVS(alterReq.alterType)) {
|
||||
if (0 != mndProcessAlterUserPrivilegesReq(&alterReq, pMnode, &newUser)) goto _OVER;
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_ADD_WHITE_LIST) {
|
||||
|
@ -1827,12 +2101,12 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
|||
alterReq.alterType == TSDB_ALTER_USER_SYSINFO){
|
||||
auditRecord(pReq, pMnode->clusterId, "alterUser", alterReq.user, "", alterReq.sql, alterReq.sqlLen);
|
||||
}
|
||||
else if(alterReq.alterType == TSDB_ALTER_USER_ADD_READ_DB||
|
||||
alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_DB||
|
||||
alterReq.alterType == TSDB_ALTER_USER_ADD_ALL_DB||
|
||||
alterReq.alterType == TSDB_ALTER_USER_ADD_READ_TABLE||
|
||||
alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_TABLE||
|
||||
alterReq.alterType == TSDB_ALTER_USER_ADD_ALL_TABLE){
|
||||
else if(ALTER_USER_ADD_READ_DB_PRIV(alterReq.alterType, alterReq.privileges, alterReq.tabName)||
|
||||
ALTER_USER_ADD_WRITE_DB_PRIV(alterReq.alterType, alterReq.privileges, alterReq.tabName)||
|
||||
ALTER_USER_ADD_ALL_DB_PRIV(alterReq.alterType, alterReq.privileges, alterReq.tabName)||
|
||||
ALTER_USER_ADD_READ_TB_PRIV(alterReq.alterType, alterReq.privileges, alterReq.tabName)||
|
||||
ALTER_USER_ADD_WRITE_TB_PRIV(alterReq.alterType, alterReq.privileges, alterReq.tabName)||
|
||||
ALTER_USER_ADD_ALL_TB_PRIV(alterReq.alterType, alterReq.privileges, alterReq.tabName)){
|
||||
if (strcmp(alterReq.objname, "1.*") != 0){
|
||||
SName name = {0};
|
||||
tNameFromString(&name, alterReq.objname, T_NAME_ACCT | T_NAME_DB);
|
||||
|
@ -1843,11 +2117,11 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
|||
alterReq.sql, alterReq.sqlLen);
|
||||
}
|
||||
}
|
||||
else if(alterReq.alterType == TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC){
|
||||
else if(ALTER_USER_ADD_SUBSCRIBE_TOPIC_PRIV(alterReq.alterType, alterReq.privileges)){
|
||||
auditRecord(pReq, pMnode->clusterId, "GrantPrivileges", alterReq.user, alterReq.objname,
|
||||
alterReq.sql, alterReq.sqlLen);
|
||||
}
|
||||
else if(alterReq.alterType == TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC){
|
||||
else if(ALTER_USER_DEL_SUBSCRIBE_TOPIC_PRIV(alterReq.alterType, alterReq.privileges)){
|
||||
auditRecord(pReq, pMnode->clusterId, "RevokePrivileges", alterReq.user, alterReq.objname,
|
||||
alterReq.sql, alterReq.sqlLen);
|
||||
}
|
||||
|
@ -2092,7 +2366,7 @@ static void mndLoopHash(SHashObj *hash, char *priType, SSDataBlock *pBlock, int3
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)tableNameContent, false);
|
||||
|
||||
if (strcmp("t", value) != 0) {
|
||||
if (strcmp("t", value) != 0 && strcmp("v", value) != 0) {
|
||||
SNode *pAst = NULL;
|
||||
int32_t sqlLen = 0;
|
||||
size_t bufSz = strlen(value) + 1;
|
||||
|
@ -2113,12 +2387,22 @@ static void mndLoopHash(SHashObj *hash, char *priType, SSDataBlock *pBlock, int3
|
|||
colDataSetVal(pColInfo, *numOfRows, (const char *)obj, false);
|
||||
taosMemoryFree(obj);
|
||||
taosMemoryFree(sql);
|
||||
|
||||
char notes[2] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(notes, "", sizeof(notes));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)notes, false);
|
||||
} else {
|
||||
char *condition = taosMemoryMalloc(TSDB_PRIVILEDGE_CONDITION_LEN + VARSTR_HEADER_SIZE);
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(condition, "", pShow->pMeta->pSchemas[cols].bytes);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)condition, false);
|
||||
taosMemoryFree(condition);
|
||||
|
||||
char notes[64 + VARSTR_HEADER_SIZE] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(notes, value[0] == 'v' ? "view" : "", sizeof(notes));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, *numOfRows, (const char *)notes, false);
|
||||
}
|
||||
|
||||
(*numOfRows)++;
|
||||
|
@ -2155,11 +2439,15 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
int32_t numOfTopics = taosHashGetSize(pUser->topics);
|
||||
int32_t numOfReadTbs = taosHashGetSize(pUser->readTbs);
|
||||
int32_t numOfWriteTbs = taosHashGetSize(pUser->writeTbs);
|
||||
if (numOfRows + numOfReadDbs + numOfWriteDbs + numOfTopics + numOfReadTbs + numOfWriteTbs >= rows) {
|
||||
int32_t numOfAlterTbs = taosHashGetSize(pUser->alterTbs);
|
||||
int32_t numOfReadViews = taosHashGetSize(pUser->readViews);
|
||||
int32_t numOfWriteViews = taosHashGetSize(pUser->writeViews);
|
||||
int32_t numOfAlterViews = taosHashGetSize(pUser->alterViews);
|
||||
if (numOfRows + numOfReadDbs + numOfWriteDbs + numOfTopics + numOfReadTbs + numOfWriteTbs + numOfAlterTbs + numOfReadViews + numOfWriteViews + numOfAlterViews >= rows) {
|
||||
mInfo(
|
||||
"will restore. current num of rows: %d, read dbs %d, write dbs %d, topics %d, read tables %d, write tables "
|
||||
"%d",
|
||||
numOfRows, numOfReadDbs, numOfWriteDbs, numOfTopics, numOfReadTbs, numOfWriteTbs);
|
||||
"%d, alter tables %d, read views %d, write views %d, alter views %d",
|
||||
numOfRows, numOfReadDbs, numOfWriteDbs, numOfTopics, numOfReadTbs, numOfWriteTbs, numOfAlterTbs, numOfReadViews, numOfWriteViews, numOfAlterViews);
|
||||
pShow->restore = true;
|
||||
sdbRelease(pSdb, pUser);
|
||||
break;
|
||||
|
@ -2193,6 +2481,11 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
colDataSetVal(pColInfo, numOfRows, (const char *)condition, false);
|
||||
taosMemoryFree(condition);
|
||||
|
||||
char notes[2] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(notes, "", sizeof(notes));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)notes, false);
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
|
||||
|
@ -2228,6 +2521,11 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
colDataSetVal(pColInfo, numOfRows, (const char *)condition, false);
|
||||
taosMemoryFree(condition);
|
||||
|
||||
char notes[2] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(notes, "", sizeof(notes));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)notes, false);
|
||||
|
||||
numOfRows++;
|
||||
db = taosHashIterate(pUser->readDbs, db);
|
||||
}
|
||||
|
@ -2264,6 +2562,11 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
colDataSetVal(pColInfo, numOfRows, (const char *)condition, false);
|
||||
taosMemoryFree(condition);
|
||||
|
||||
char notes[2] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(notes, "", sizeof(notes));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)notes, false);
|
||||
|
||||
numOfRows++;
|
||||
db = taosHashIterate(pUser->writeDbs, db);
|
||||
}
|
||||
|
@ -2272,6 +2575,14 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
|
||||
mndLoopHash(pUser->writeTbs, "write", pBlock, &numOfRows, pUser->user, pShow);
|
||||
|
||||
mndLoopHash(pUser->alterTbs, "alter", pBlock, &numOfRows, pUser->user, pShow);
|
||||
|
||||
mndLoopHash(pUser->readViews, "read", pBlock, &numOfRows, pUser->user, pShow);
|
||||
|
||||
mndLoopHash(pUser->writeViews, "write", pBlock, &numOfRows, pUser->user, pShow);
|
||||
|
||||
mndLoopHash(pUser->alterViews, "alter", pBlock, &numOfRows, pUser->user, pShow);
|
||||
|
||||
char *topic = taosHashIterate(pUser->topics, NULL);
|
||||
while (topic != NULL) {
|
||||
cols = 0;
|
||||
|
@ -2302,6 +2613,11 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
colDataSetVal(pColInfo, numOfRows, (const char *)condition, false);
|
||||
taosMemoryFree(condition);
|
||||
|
||||
char notes[2] = {0};
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(notes, "", sizeof(notes));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, numOfRows, (const char *)notes, false);
|
||||
|
||||
numOfRows++;
|
||||
topic = taosHashIterate(pUser->topics, topic);
|
||||
}
|
||||
|
@ -2450,9 +2766,11 @@ int32_t mndUserRemoveStb(SMnode *pMnode, STrans *pTrans, char *stb) {
|
|||
|
||||
bool inRead = (taosHashGet(newUser.readTbs, stb, len) != NULL);
|
||||
bool inWrite = (taosHashGet(newUser.writeTbs, stb, len) != NULL);
|
||||
if (inRead || inWrite) {
|
||||
bool inAlter = (taosHashGet(newUser.alterTbs, stb, len) != NULL);
|
||||
if (inRead || inWrite || inAlter) {
|
||||
(void)taosHashRemove(newUser.readTbs, stb, len);
|
||||
(void)taosHashRemove(newUser.writeTbs, stb, len);
|
||||
(void)taosHashRemove(newUser.alterTbs, stb, len);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
|
@ -2472,6 +2790,50 @@ int32_t mndUserRemoveStb(SMnode *pMnode, STrans *pTrans, char *stb) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t mndUserRemoveView(SMnode *pMnode, STrans *pTrans, char *view) {
|
||||
int32_t code = 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t len = strlen(view) + 1;
|
||||
void *pIter = NULL;
|
||||
SUserObj *pUser = NULL;
|
||||
SUserObj newUser = {0};
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pUser);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
code = -1;
|
||||
if (mndUserDupObj(pUser, &newUser) != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
bool inRead = (taosHashGet(newUser.readViews, view, len) != NULL);
|
||||
bool inWrite = (taosHashGet(newUser.writeViews, view, len) != NULL);
|
||||
bool inAlter = (taosHashGet(newUser.alterViews, view, len) != NULL);
|
||||
if (inRead || inWrite || inAlter) {
|
||||
(void)taosHashRemove(newUser.readViews, view, len);
|
||||
(void)taosHashRemove(newUser.writeViews, view, len);
|
||||
(void)taosHashRemove(newUser.alterViews, view, len);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
break;
|
||||
}
|
||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
}
|
||||
|
||||
mndUserFreeObj(&newUser);
|
||||
sdbRelease(pSdb, pUser);
|
||||
code = 0;
|
||||
}
|
||||
|
||||
if (pUser != NULL) sdbRelease(pSdb, pUser);
|
||||
if (pIter != NULL) sdbCancelFetch(pSdb, pIter);
|
||||
mndUserFreeObj(&newUser);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
int32_t mndUserRemoveTopic(SMnode *pMnode, STrans *pTrans, char *topic) {
|
||||
int32_t code = 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "mndView.h"
|
||||
#include "mndShow.h"
|
||||
|
||||
int32_t mndInitView(SMnode *pMnode) {
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_VIEW, mndProcessCreateViewReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_VIEW, mndProcessDropViewReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_VIEW_META, mndProcessGetViewMetaReq);
|
||||
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_VIEWS, mndRetrieveView);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_VIEWS, mndCancelGetNextView);
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
initDynViewVersion();
|
||||
|
||||
SSdbTable table = {
|
||||
.sdbType = SDB_VIEW,
|
||||
.keyType = SDB_KEY_BINARY,
|
||||
.encodeFp = (SdbEncodeFp)mndViewActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndViewActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndViewActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndViewActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndViewActionDelete,
|
||||
};
|
||||
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
#else
|
||||
return TSDB_CODE_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
void mndCleanupView(SMnode *pMnode) {
|
||||
mDebug("mnd view cleanup");
|
||||
}
|
||||
|
||||
int32_t mndProcessCreateViewReq(SRpcMsg *pReq) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#else
|
||||
SCMCreateViewReq createViewReq = {0};
|
||||
if (tDeserializeSCMCreateViewReq(pReq->pCont, pReq->contLen, &createViewReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mInfo("start to create view:%s, sql:%s", createViewReq.fullname, createViewReq.sql);
|
||||
|
||||
return mndProcessCreateViewReqImpl(&createViewReq, pReq);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t mndProcessDropViewReq(SRpcMsg *pReq) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#else
|
||||
SCMDropViewReq dropViewReq = {0};
|
||||
if (tDeserializeSCMDropViewReq(pReq->pCont, pReq->contLen, &dropViewReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mInfo("start to drop view:%s, sql:%s", dropViewReq.name, dropViewReq.sql);
|
||||
|
||||
return mndProcessDropViewReqImpl(&dropViewReq, pReq);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t mndProcessGetViewMetaReq(SRpcMsg *pReq) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#else
|
||||
SViewMetaReq req = {0};
|
||||
|
||||
if (tDeserializeSViewMetaReq(pReq->pCont, pReq->contLen, &req) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return mndProcessViewMetaReqImpl(&req, pReq);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int32_t mndRetrieveView(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return 0;
|
||||
#else
|
||||
return mndRetrieveViewImpl(pReq, pShow, pBlock, rows);
|
||||
#endif
|
||||
}
|
||||
|
||||
void mndCancelGetNextView(SMnode *pMnode, void *pIter) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -250,7 +250,8 @@ TEST_F(MndTestUser, 03_Alter_User) {
|
|||
|
||||
{
|
||||
SAlterUserReq alterReq = {0};
|
||||
alterReq.alterType = TSDB_ALTER_USER_REMOVE_ALL_DB;
|
||||
alterReq.alterType = TSDB_ALTER_USER_DEL_PRIVILEGES;
|
||||
alterReq.privileges = PRIVILEGE_TYPE_ALL;
|
||||
strcpy(alterReq.user, "u3");
|
||||
strcpy(alterReq.pass, "1");
|
||||
strcpy(alterReq.dbname, "1.*");
|
||||
|
@ -266,7 +267,8 @@ TEST_F(MndTestUser, 03_Alter_User) {
|
|||
|
||||
{
|
||||
SAlterUserReq alterReq = {0};
|
||||
alterReq.alterType = TSDB_ALTER_USER_REMOVE_ALL_DB;
|
||||
alterReq.alterType = TSDB_ALTER_USER_DEL_PRIVILEGES;
|
||||
alterReq.privileges = PRIVILEGE_TYPE_ALL;
|
||||
strcpy(alterReq.user, "u3");
|
||||
strcpy(alterReq.pass, "1");
|
||||
strcpy(alterReq.dbname, "1.*");
|
||||
|
@ -282,7 +284,8 @@ TEST_F(MndTestUser, 03_Alter_User) {
|
|||
|
||||
{
|
||||
SAlterUserReq alterReq = {0};
|
||||
alterReq.alterType = TSDB_ALTER_USER_ADD_READ_DB;
|
||||
alterReq.alterType = TSDB_ALTER_USER_ADD_PRIVILEGES;
|
||||
alterReq.privileges = PRIVILEGE_TYPE_READ;
|
||||
strcpy(alterReq.user, "u3");
|
||||
strcpy(alterReq.pass, "1");
|
||||
strcpy(alterReq.dbname, "d1");
|
||||
|
@ -329,7 +332,8 @@ TEST_F(MndTestUser, 03_Alter_User) {
|
|||
|
||||
{
|
||||
SAlterUserReq alterReq = {0};
|
||||
alterReq.alterType = TSDB_ALTER_USER_ADD_READ_DB;
|
||||
alterReq.alterType = TSDB_ALTER_USER_ADD_PRIVILEGES;
|
||||
alterReq.privileges = PRIVILEGE_TYPE_READ;
|
||||
strcpy(alterReq.user, "u3");
|
||||
strcpy(alterReq.pass, "1");
|
||||
strcpy(alterReq.dbname, "1.d2");
|
||||
|
@ -345,7 +349,8 @@ TEST_F(MndTestUser, 03_Alter_User) {
|
|||
|
||||
{
|
||||
SAlterUserReq alterReq = {0};
|
||||
alterReq.alterType = TSDB_ALTER_USER_ADD_READ_DB;
|
||||
alterReq.alterType = TSDB_ALTER_USER_ADD_PRIVILEGES;
|
||||
alterReq.privileges = PRIVILEGE_TYPE_READ;
|
||||
strcpy(alterReq.user, "u3");
|
||||
strcpy(alterReq.pass, "1");
|
||||
strcpy(alterReq.dbname, "1.d2");
|
||||
|
@ -388,7 +393,8 @@ TEST_F(MndTestUser, 03_Alter_User) {
|
|||
|
||||
{
|
||||
SAlterUserReq alterReq = {0};
|
||||
alterReq.alterType = TSDB_ALTER_USER_REMOVE_READ_DB;
|
||||
alterReq.alterType = TSDB_ALTER_USER_DEL_PRIVILEGES;
|
||||
alterReq.alterType = PRIVILEGE_TYPE_READ;
|
||||
strcpy(alterReq.user, "u3");
|
||||
strcpy(alterReq.pass, "1");
|
||||
strcpy(alterReq.dbname, "1.d2");
|
||||
|
|
|
@ -148,7 +148,8 @@ typedef enum {
|
|||
SDB_DB = 19,
|
||||
SDB_FUNC = 20,
|
||||
SDB_IDX = 21,
|
||||
SDB_MAX = 22
|
||||
SDB_VIEW = 22,
|
||||
SDB_MAX = 23
|
||||
} ESdbType;
|
||||
|
||||
typedef struct SSdbRaw {
|
||||
|
|
|
@ -62,6 +62,8 @@ const char *sdbTableName(ESdbType type) {
|
|||
return "func";
|
||||
case SDB_IDX:
|
||||
return "idx";
|
||||
case SDB_VIEW:
|
||||
return "view";
|
||||
default:
|
||||
return "undefine";
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ extern "C" {
|
|||
#define CTG_DEFAULT_CACHE_VGROUP_NUMBER 100
|
||||
#define CTG_DEFAULT_CACHE_DB_NUMBER 20
|
||||
#define CTG_DEFAULT_CACHE_TBLMETA_NUMBER 1000
|
||||
#define CTG_DEFAULT_CACHE_VIEW_NUMBER 256
|
||||
#define CTG_DEFAULT_RENT_SECOND 10
|
||||
#define CTG_DEFAULT_RENT_SLOT_SIZE 10
|
||||
#define CTG_DEFAULT_MAX_RETRY_TIMES 3
|
||||
|
@ -67,6 +68,7 @@ typedef enum {
|
|||
CTG_CI_USER,
|
||||
CTG_CI_UDF,
|
||||
CTG_CI_SVR_VER,
|
||||
CTG_CI_VIEW,
|
||||
CTG_CI_MAX_VALUE,
|
||||
} CTG_CACHE_ITEM;
|
||||
|
||||
|
@ -82,6 +84,7 @@ enum {
|
|||
enum {
|
||||
CTG_RENT_DB = 1,
|
||||
CTG_RENT_STABLE,
|
||||
CTG_RENT_VIEW,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -96,6 +99,8 @@ enum {
|
|||
CTG_OP_UPDATE_VG_EPSET,
|
||||
CTG_OP_UPDATE_TB_INDEX,
|
||||
CTG_OP_DROP_TB_INDEX,
|
||||
CTG_OP_UPDATE_VIEW_META,
|
||||
CTG_OP_DROP_VIEW_META,
|
||||
CTG_OP_CLEAR_CACHE,
|
||||
CTG_OP_MAX
|
||||
};
|
||||
|
@ -117,6 +122,7 @@ typedef enum {
|
|||
CTG_TASK_GET_TB_META_BATCH,
|
||||
CTG_TASK_GET_TB_HASH_BATCH,
|
||||
CTG_TASK_GET_TB_TAG,
|
||||
CTG_TASK_GET_VIEW,
|
||||
} CTG_TASK_TYPE;
|
||||
|
||||
typedef enum {
|
||||
|
@ -146,6 +152,7 @@ typedef struct SCtgAuthReq {
|
|||
SGetUserAuthRsp authInfo;
|
||||
AUTH_TYPE singleType;
|
||||
bool onlyCache;
|
||||
bool tbNotExists;
|
||||
} SCtgAuthReq;
|
||||
|
||||
typedef struct SCtgAuthRsp {
|
||||
|
@ -238,8 +245,17 @@ typedef struct SCtgUdfCtx {
|
|||
|
||||
typedef struct SCtgUserCtx {
|
||||
SUserAuthInfo user;
|
||||
int32_t subTaskCode;
|
||||
} SCtgUserCtx;
|
||||
|
||||
typedef struct SCtgViewsCtx {
|
||||
int32_t fetchNum;
|
||||
SArray* pNames;
|
||||
SArray* pResList;
|
||||
SArray* pFetchs;
|
||||
} SCtgViewsCtx;
|
||||
|
||||
|
||||
typedef STableIndexRsp STableIndex;
|
||||
|
||||
typedef struct SCtgTbCache {
|
||||
|
@ -259,12 +275,19 @@ typedef struct SCtgCfgCache {
|
|||
SDbCfgInfo* cfgInfo;
|
||||
} SCtgCfgCache;
|
||||
|
||||
typedef struct SCtgViewCache {
|
||||
SRWLatch viewLock;
|
||||
SViewMeta* pMeta;
|
||||
} SCtgViewCache;
|
||||
|
||||
|
||||
typedef struct SCtgDBCache {
|
||||
SRWLatch dbLock; // RC between destroy tbCache/stbCache and all reads
|
||||
uint64_t dbId;
|
||||
int8_t deleted;
|
||||
SCtgVgCache vgCache;
|
||||
SCtgCfgCache cfgCache;
|
||||
SHashObj* viewCache; // key:viewname, value:SCtgViewCache
|
||||
SHashObj* tbCache; // key:tbname, value:SCtgTbCache
|
||||
SHashObj* stbCache; // key:suid, value:char*
|
||||
uint64_t dbCacheNum[CTG_CI_MAX_VALUE];
|
||||
|
@ -294,13 +317,15 @@ typedef struct SCtgUserAuth {
|
|||
} SCtgUserAuth;
|
||||
|
||||
typedef struct SCatalog {
|
||||
uint64_t clusterId;
|
||||
bool stopUpdate;
|
||||
SHashObj* userCache; // key:user, value:SCtgUserAuth
|
||||
SHashObj* dbCache; // key:dbname, value:SCtgDBCache
|
||||
SCtgRentMgmt dbRent;
|
||||
SCtgRentMgmt stbRent;
|
||||
SCtgCacheStat cacheStat;
|
||||
uint64_t clusterId;
|
||||
bool stopUpdate;
|
||||
SDynViewVersion dynViewVer;
|
||||
SHashObj* userCache; // key:user, value:SCtgUserAuth
|
||||
SHashObj* dbCache; // key:dbname, value:SCtgDBCache
|
||||
SCtgRentMgmt dbRent;
|
||||
SCtgRentMgmt stbRent;
|
||||
SCtgRentMgmt viewRent;
|
||||
SCtgCacheStat cacheStat;
|
||||
} SCatalog;
|
||||
|
||||
typedef struct SCtgBatch {
|
||||
|
@ -344,6 +369,7 @@ typedef struct SCtgJob {
|
|||
int32_t tbIndexNum;
|
||||
int32_t tbCfgNum;
|
||||
int32_t svrVerNum;
|
||||
int32_t viewNum;
|
||||
} SCtgJob;
|
||||
|
||||
typedef struct SCtgMsgCtx {
|
||||
|
@ -509,6 +535,20 @@ typedef struct SCtgUpdateEpsetMsg {
|
|||
SEpSet epSet;
|
||||
} SCtgUpdateEpsetMsg;
|
||||
|
||||
typedef struct SCtgUpdateViewMetaMsg {
|
||||
SCatalog* pCtg;
|
||||
SViewMetaRsp* pRsp;
|
||||
} SCtgUpdateViewMetaMsg;
|
||||
|
||||
typedef struct SCtgDropViewMetaMsg {
|
||||
SCatalog* pCtg;
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
char viewName[TSDB_VIEW_NAME_LEN];
|
||||
uint64_t dbId;
|
||||
uint64_t viewId;
|
||||
} SCtgDropViewMetaMsg;
|
||||
|
||||
|
||||
typedef struct SCtgCacheOperation {
|
||||
int32_t opId;
|
||||
void* data;
|
||||
|
@ -686,10 +726,10 @@ typedef struct SCtgCacheItemInfo {
|
|||
(CTG_FLAG_IS_UNKNOWN_STB(_flag) || (CTG_FLAG_IS_STB(_flag) && (tbType) == TSDB_SUPER_TABLE) || \
|
||||
(CTG_FLAG_IS_NOT_STB(_flag) && (tbType) != TSDB_SUPER_TABLE))
|
||||
|
||||
#define CTG_IS_BATCH_TASK(_taskType) ((CTG_TASK_GET_TB_META_BATCH == (_taskType)) || (CTG_TASK_GET_TB_HASH_BATCH == (_taskType)) || (CTG_TASK_GET_VIEW == (_taskType)))
|
||||
|
||||
#define CTG_GET_TASK_MSGCTX(_task, _id) \
|
||||
(((CTG_TASK_GET_TB_META_BATCH == (_task)->type) || (CTG_TASK_GET_TB_HASH_BATCH == (_task)->type)) \
|
||||
? taosArrayGet((_task)->msgCtxs, (_id)) \
|
||||
: &(_task)->msgCtx)
|
||||
(CTG_IS_BATCH_TASK((_task)->type) ? taosArrayGet((_task)->msgCtxs, (_id)) : &(_task)->msgCtx)
|
||||
|
||||
#define CTG_META_SIZE(pMeta) \
|
||||
(sizeof(STableMeta) + ((pMeta)->tableInfo.numOfTags + (pMeta)->tableInfo.numOfColumns) * sizeof(SSchema))
|
||||
|
@ -870,6 +910,7 @@ int32_t ctgOpDropDbCache(SCtgCacheOperation* action);
|
|||
int32_t ctgOpDropDbVgroup(SCtgCacheOperation* action);
|
||||
int32_t ctgOpDropStbMeta(SCtgCacheOperation* action);
|
||||
int32_t ctgOpDropTbMeta(SCtgCacheOperation* action);
|
||||
int32_t ctgOpDropViewMeta(SCtgCacheOperation* action);
|
||||
int32_t ctgOpUpdateUser(SCtgCacheOperation* action);
|
||||
int32_t ctgOpUpdateEpset(SCtgCacheOperation* operation);
|
||||
int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char* dbFName, SCtgDBCache** pCache);
|
||||
|
@ -879,7 +920,7 @@ int32_t ctgTbMetaExistInCache(SCatalog* pCtg, char* dbFName, char* tbName, int32
|
|||
int32_t ctgReadTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta);
|
||||
int32_t ctgReadTbVerFromCache(SCatalog* pCtg, SName* pTableName, int32_t* sver, int32_t* tver, int32_t* tbType,
|
||||
uint64_t* suid, char* stbName);
|
||||
int32_t ctgChkAuthFromCache(SCatalog* pCtg, SUserAuthInfo* pReq, bool* inCache, SCtgAuthRsp* pRes);
|
||||
int32_t ctgChkAuthFromCache(SCatalog* pCtg, SUserAuthInfo* pReq, bool tbNotExists, bool* inCache, SCtgAuthRsp* pRes);
|
||||
int32_t ctgDropDbCacheEnqueue(SCatalog* pCtg, const char* dbFName, int64_t dbId);
|
||||
int32_t ctgDropDbVgroupEnqueue(SCatalog* pCtg, const char* dbFName, bool syncReq);
|
||||
int32_t ctgDropStbMetaEnqueue(SCatalog* pCtg, const char* dbFName, int64_t dbId, const char* stbName, uint64_t suid,
|
||||
|
@ -891,11 +932,22 @@ int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput* output, bool sy
|
|||
int32_t ctgUpdateUserEnqueue(SCatalog* pCtg, SGetUserAuthRsp* pAuth, bool syncReq);
|
||||
int32_t ctgUpdateVgEpsetEnqueue(SCatalog* pCtg, char* dbFName, int32_t vgId, SEpSet* pEpSet);
|
||||
int32_t ctgUpdateTbIndexEnqueue(SCatalog* pCtg, STableIndex** pIndex, bool syncOp);
|
||||
int32_t ctgDropViewMetaEnqueue(SCatalog *pCtg, const char *dbFName, uint64_t dbId, const char *viewName, uint64_t viewId, bool syncOp);
|
||||
int32_t ctgClearCacheEnqueue(SCatalog* pCtg, bool clearMeta, bool freeCtg, bool stopQueue, bool syncOp);
|
||||
int32_t ctgMetaRentInit(SCtgRentMgmt* mgmt, uint32_t rentSec, int8_t type, int32_t size);
|
||||
int32_t ctgMetaRentAdd(SCtgRentMgmt* mgmt, void* meta, int64_t id, int32_t size);
|
||||
int32_t ctgMetaRentUpdate(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size, __compar_fn_t sortCompare,
|
||||
__compar_fn_t searchCompare);
|
||||
int32_t ctgMetaRentGet(SCtgRentMgmt* mgmt, void** res, uint32_t* num, int32_t size);
|
||||
int32_t ctgMetaRentRemove(SCtgRentMgmt *mgmt, int64_t id, __compar_fn_t sortCompare, __compar_fn_t searchCompare);
|
||||
void ctgRemoveStbRent(SCatalog *pCtg, SCtgDBCache *dbCache);
|
||||
void ctgRemoveViewRent(SCatalog *pCtg, SCtgDBCache *dbCache);
|
||||
int32_t ctgUpdateRentStbVersion(SCatalog *pCtg, char *dbFName, char *tbName, uint64_t dbId, uint64_t suid,
|
||||
SCtgTbCache *pCache);
|
||||
int32_t ctgUpdateRentViewVersion(SCatalog *pCtg, char *dbFName, char *viewName, uint64_t dbId, uint64_t viewId,
|
||||
SCtgViewCache *pCache);
|
||||
int32_t ctgUpdateTbMetaToCache(SCatalog* pCtg, STableMetaOutput* pOut, bool syncReq);
|
||||
int32_t ctgUpdateViewMetaToCache(SCatalog *pCtg, SViewMetaRsp *pRsp, bool syncReq);
|
||||
int32_t ctgStartUpdateThread();
|
||||
int32_t ctgRelaunchGetTbMetaTask(SCtgTask* pTask);
|
||||
void ctgReleaseVgInfoToCache(SCatalog* pCtg, SCtgDBCache* dbCache);
|
||||
|
@ -904,9 +956,11 @@ int32_t ctgDropTbIndexEnqueue(SCatalog* pCtg, SName* pName, bool syncOp);
|
|||
int32_t ctgOpDropTbIndex(SCtgCacheOperation* operation);
|
||||
int32_t ctgOpUpdateTbIndex(SCtgCacheOperation* operation);
|
||||
int32_t ctgOpClearCache(SCtgCacheOperation* operation);
|
||||
int32_t ctgOpUpdateViewMeta(SCtgCacheOperation *operation);
|
||||
int32_t ctgReadTbTypeFromCache(SCatalog* pCtg, char* dbFName, char* tableName, int32_t* tbType);
|
||||
int32_t ctgGetTbHashVgroupFromCache(SCatalog* pCtg, const SName* pTableName, SVgroupInfo** pVgroup);
|
||||
|
||||
int32_t ctgGetViewsFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgViewsCtx *ctx, int32_t dbIdx,
|
||||
int32_t *fetchIdx, int32_t baseResIdx, SArray *pList);
|
||||
int32_t ctgProcessRspMsg(void* out, int32_t reqType, char* msg, int32_t msgSize, int32_t rspCode, char* target);
|
||||
int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SBuildUseDBInput* input, SUseDbOutput* out,
|
||||
SCtgTaskReq* tReq);
|
||||
|
@ -932,6 +986,8 @@ int32_t ctgGetTableCfgFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const S
|
|||
int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableCfg** out,
|
||||
SCtgTask* pTask);
|
||||
int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, char** out, SCtgTask* pTask);
|
||||
int32_t ctgGetViewInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pName, SViewMetaOutput* out,
|
||||
SCtgTaskReq* tReq);
|
||||
int32_t ctgLaunchBatchs(SCatalog* pCtg, SCtgJob* pJob, SHashObj* pBatchs);
|
||||
|
||||
int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const SCatalogReq* pReq, catalogCallback fp,
|
||||
|
@ -942,6 +998,7 @@ int32_t ctgLaunchSubTask(SCtgTask** ppTask, CTG_TASK_TYPE type, ctgSubTaskCbFp f
|
|||
int32_t ctgGetTbCfgCb(SCtgTask* pTask);
|
||||
void ctgFreeHandle(SCatalog* pCatalog);
|
||||
|
||||
void ctgFreeSViewMeta(SViewMeta* pMeta);
|
||||
void ctgFreeMsgSendParam(void* param);
|
||||
void ctgFreeBatch(SCtgBatch* pBatch);
|
||||
void ctgFreeBatchs(SHashObj* pBatchs);
|
||||
|
@ -958,9 +1015,11 @@ int32_t ctgGetVgIdsFromHashValue(SCatalog* pCtg, SDBVgInfo* dbInfo, char* dbFNam
|
|||
void ctgResetTbMetaTask(SCtgTask* pTask);
|
||||
void ctgFreeDbCache(SCtgDBCache* dbCache);
|
||||
int32_t ctgStbVersionSortCompare(const void* key1, const void* key2);
|
||||
int32_t ctgViewVersionSortCompare(const void* key1, const void* key2);
|
||||
int32_t ctgDbCacheInfoSortCompare(const void* key1, const void* key2);
|
||||
int32_t ctgStbVersionSearchCompare(const void* key1, const void* key2);
|
||||
int32_t ctgDbCacheInfoSearchCompare(const void* key1, const void* key2);
|
||||
int32_t ctgViewVersionSearchCompare(const void* key1, const void* key2);
|
||||
void ctgFreeSTableMetaOutput(STableMetaOutput* pOutput);
|
||||
int32_t ctgUpdateMsgCtx(SCtgMsgCtx* pCtx, int32_t reqType, void* out, char* target);
|
||||
int32_t ctgAddMsgCtx(SArray* pCtxs, int32_t reqType, void* out, char* target);
|
||||
|
@ -974,8 +1033,9 @@ void ctgClearSubTaskRes(SCtgSubRes* pRes);
|
|||
void ctgFreeQNode(SCtgQNode* node);
|
||||
void ctgClearHandle(SCatalog* pCtg);
|
||||
void ctgFreeTbCacheImpl(SCtgTbCache* pCache, bool lock);
|
||||
void ctgFreeViewCacheImpl(SCtgViewCache* pCache, bool lock);
|
||||
int32_t ctgRemoveTbMeta(SCatalog* pCtg, SName* pTableName);
|
||||
int32_t ctgRemoveCacheUser(SCatalog* pCtg, const char* user);
|
||||
int32_t ctgRemoveCacheUser(SCatalog* pCtg, SCtgUserAuth* pUser, const char* user);
|
||||
int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup,
|
||||
bool* exists);
|
||||
SName* ctgGetFetchName(SArray* pNames, SCtgFetch* pFetch);
|
||||
|
@ -993,8 +1053,12 @@ void ctgReleaseVgMetaToCache(SCatalog* pCtg, SCtgDBCache* dbCache, SCtgTbCach
|
|||
void ctgReleaseTbMetaToCache(SCatalog* pCtg, SCtgDBCache* dbCache, SCtgTbCache* pCache);
|
||||
void ctgGetGlobalCacheStat(SCtgCacheStat* pStat);
|
||||
int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res);
|
||||
int32_t ctgBuildViewNullRes(SCtgTask* pTask, SCtgViewsCtx* pCtx);
|
||||
int32_t dupViewMetaFromRsp(SViewMetaRsp* pRsp, SViewMeta* pViewMeta);
|
||||
void ctgDestroySMetaData(SMetaData* pData);
|
||||
void ctgGetGlobalCacheSize(uint64_t *pSize);
|
||||
uint64_t ctgGetTbIndexCacheSize(STableIndex *pIndex);
|
||||
uint64_t ctgGetViewMetaCacheSize(SViewMeta *pMeta);
|
||||
uint64_t ctgGetTbMetaCacheSize(STableMeta *pMeta);
|
||||
uint64_t ctgGetDbVgroupCacheSize(SDBVgInfo *pVg);
|
||||
uint64_t ctgGetUserCacheSize(SGetUserAuthRsp *pAuth);
|
||||
|
|
|
@ -325,7 +325,7 @@ int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, SUserAuthInfo *pReq,
|
|||
SCtgAuthRsp rsp = {0};
|
||||
rsp.pRawRes = pRes;
|
||||
|
||||
CTG_ERR_RET(ctgChkAuthFromCache(pCtg, pReq, &inCache, &rsp));
|
||||
CTG_ERR_RET(ctgChkAuthFromCache(pCtg, pReq, false, &inCache, &rsp));
|
||||
|
||||
if (inCache) {
|
||||
if (exists) {
|
||||
|
@ -665,9 +665,32 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgRemoveViewMeta(SCatalog* pCtg, const char* dbFName, uint64_t dbId, const char* viewName, uint64_t viewId) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (NULL == pCtg || NULL == dbFName || NULL == viewName) {
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
||||
}
|
||||
|
||||
if (NULL == pCtg->dbCache) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
CTG_ERR_JRET(ctgDropViewMetaEnqueue(pCtg, dbFName, 0, viewName, viewId, true));
|
||||
|
||||
_return:
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
||||
void ctgProcessTimerEvent(void *param, void *tmrId) {
|
||||
CTG_API_NENTER();
|
||||
|
||||
ctgdShowCacheInfo();
|
||||
ctgdShowStatInfo();
|
||||
|
||||
int32_t cacheMaxSize = atomic_load_32(&tsMetaCacheMaxSize);
|
||||
if (cacheMaxSize >= 0) {
|
||||
uint64_t cacheSize = 0;
|
||||
|
@ -732,6 +755,10 @@ int32_t catalogInit(SCatalogCfg* cfg) {
|
|||
gCtgMgmt.cfg.maxTblCacheNum = CTG_DEFAULT_CACHE_TBLMETA_NUMBER;
|
||||
}
|
||||
|
||||
if (gCtgMgmt.cfg.maxViewCacheNum == 0) {
|
||||
gCtgMgmt.cfg.maxViewCacheNum = CTG_DEFAULT_CACHE_VIEW_NUMBER;
|
||||
}
|
||||
|
||||
if (gCtgMgmt.cfg.dbRentSec == 0) {
|
||||
gCtgMgmt.cfg.dbRentSec = CTG_DEFAULT_RENT_SECOND;
|
||||
}
|
||||
|
@ -739,11 +766,17 @@ int32_t catalogInit(SCatalogCfg* cfg) {
|
|||
if (gCtgMgmt.cfg.stbRentSec == 0) {
|
||||
gCtgMgmt.cfg.stbRentSec = CTG_DEFAULT_RENT_SECOND;
|
||||
}
|
||||
|
||||
if (gCtgMgmt.cfg.viewRentSec == 0) {
|
||||
gCtgMgmt.cfg.viewRentSec = CTG_DEFAULT_RENT_SECOND;
|
||||
}
|
||||
} else {
|
||||
gCtgMgmt.cfg.maxDBCacheNum = CTG_DEFAULT_CACHE_DB_NUMBER;
|
||||
gCtgMgmt.cfg.maxTblCacheNum = CTG_DEFAULT_CACHE_TBLMETA_NUMBER;
|
||||
gCtgMgmt.cfg.maxViewCacheNum = CTG_DEFAULT_CACHE_VIEW_NUMBER;
|
||||
gCtgMgmt.cfg.dbRentSec = CTG_DEFAULT_RENT_SECOND;
|
||||
gCtgMgmt.cfg.stbRentSec = CTG_DEFAULT_RENT_SECOND;
|
||||
gCtgMgmt.cfg.viewRentSec = CTG_DEFAULT_RENT_SECOND;
|
||||
}
|
||||
|
||||
gCtgMgmt.pCluster = taosHashInit(CTG_DEFAULT_CACHE_CLUSTER_NUMBER, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT),
|
||||
|
@ -828,6 +861,7 @@ int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle) {
|
|||
|
||||
CTG_ERR_JRET(ctgMetaRentInit(&clusterCtg->dbRent, gCtgMgmt.cfg.dbRentSec, CTG_RENT_DB, sizeof(SDbCacheInfo)));
|
||||
CTG_ERR_JRET(ctgMetaRentInit(&clusterCtg->stbRent, gCtgMgmt.cfg.stbRentSec, CTG_RENT_STABLE, sizeof(SSTableVersion)));
|
||||
CTG_ERR_JRET(ctgMetaRentInit(&clusterCtg->viewRent, gCtgMgmt.cfg.viewRentSec, CTG_RENT_VIEW, sizeof(SViewVersion)));
|
||||
|
||||
clusterCtg->dbCache = taosHashInit(gCtgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY),
|
||||
false, HASH_ENTRY_LOCK);
|
||||
|
@ -1461,6 +1495,25 @@ int32_t catalogGetExpiredSTables(SCatalog* pCtg, SSTableVersion** stables, uint3
|
|||
CTG_API_LEAVE(ctgMetaRentGet(&pCtg->stbRent, (void**)stables, num, sizeof(SSTableVersion)));
|
||||
}
|
||||
|
||||
int32_t catalogGetExpiredViews(SCatalog* pCtg, SViewVersion** views, uint32_t* num, SDynViewVersion** dynViewVersion) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
if (NULL == pCtg || NULL == views || NULL == num) {
|
||||
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||
}
|
||||
|
||||
*dynViewVersion = taosMemoryMalloc(sizeof(SDynViewVersion));
|
||||
if (NULL == *dynViewVersion) {
|
||||
CTG_API_LEAVE(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
(*dynViewVersion)->svrBootTs = atomic_load_64(&pCtg->dynViewVer.svrBootTs);
|
||||
(*dynViewVersion)->dynViewVer = atomic_load_64(&pCtg->dynViewVer.dynViewVer);
|
||||
|
||||
CTG_API_LEAVE(ctgMetaRentGet(&pCtg->viewRent, (void**)views, num, sizeof(SViewVersion)));
|
||||
}
|
||||
|
||||
|
||||
int32_t catalogGetExpiredDBs(SCatalog* pCtg, SDbCacheInfo** dbs, uint32_t* num) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
|
@ -1651,6 +1704,71 @@ int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth) {
|
|||
CTG_API_LEAVE(ctgUpdateUserEnqueue(pCtg, pAuth, false));
|
||||
}
|
||||
|
||||
void catalogFreeMetaData(SMetaData * pData) {
|
||||
ctgDestroySMetaData(pData);
|
||||
}
|
||||
|
||||
int32_t catalogRemoveViewMeta(SCatalog* pCtg, const char* dbFName, uint64_t dbId, const char* viewName, uint64_t viewId) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
CTG_API_LEAVE(ctgRemoveViewMeta(pCtg, dbFName, dbId, viewName, viewId));
|
||||
}
|
||||
|
||||
|
||||
int32_t catalogUpdateDynViewVer(SCatalog* pCtg, SDynViewVersion* pVer) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
if (NULL == pCtg || NULL == pVer) {
|
||||
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||
}
|
||||
|
||||
atomic_store_64(&pCtg->dynViewVer.svrBootTs, pVer->svrBootTs);
|
||||
atomic_store_64(&pCtg->dynViewVer.dynViewVer, pVer->dynViewVer);
|
||||
|
||||
ctgDebug("cluster %" PRIx64 " svrBootTs updated to %" PRId64, pCtg->clusterId, pVer->svrBootTs);
|
||||
ctgDebug("cluster %" PRIx64 " dynViewVer updated to %" PRId64, pCtg->clusterId, pVer->dynViewVer);
|
||||
|
||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t catalogUpdateViewMeta(SCatalog* pCtg, SViewMetaRsp* pMsg) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
if (NULL == pCtg || NULL == pMsg) {
|
||||
tFreeSViewMetaRsp(pMsg);
|
||||
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
CTG_ERR_JRET(ctgUpdateViewMetaToCache(pCtg, pMsg, true));
|
||||
|
||||
_return:
|
||||
|
||||
CTG_API_LEAVE(code);
|
||||
}
|
||||
|
||||
|
||||
int32_t catalogAsyncUpdateViewMeta(SCatalog* pCtg, SViewMetaRsp* pMsg) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
if (NULL == pCtg || NULL == pMsg) {
|
||||
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
CTG_ERR_JRET(ctgUpdateViewMetaToCache(pCtg, pMsg, false));
|
||||
|
||||
_return:
|
||||
|
||||
CTG_API_LEAVE(code);
|
||||
}
|
||||
|
||||
int32_t catalogGetViewMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pViewName, STableMeta** pTableMeta) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
CTG_API_LEAVE(TSDB_CODE_OPS_NOT_SUPPORT);
|
||||
}
|
||||
|
||||
int32_t catalogClearCache(void) {
|
||||
CTG_API_ENTER_NOLOCK();
|
||||
|
||||
|
|
|
@ -20,6 +20,30 @@
|
|||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
|
||||
|
||||
void ctgIsTaskDone(SCtgJob* pJob, CTG_TASK_TYPE type, bool* done) {
|
||||
SCtgTask* pTask = NULL;
|
||||
|
||||
*done = true;
|
||||
|
||||
CTG_LOCK(CTG_READ, &pJob->taskLock);
|
||||
|
||||
int32_t taskNum = taosArrayGetSize(pJob->pTasks);
|
||||
for (int32_t i = 0; i < taskNum; ++i) {
|
||||
pTask = taosArrayGet(pJob->pTasks, i);
|
||||
if (type != pTask->type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pTask->status != CTG_TASK_DONE) {
|
||||
*done = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CTG_UNLOCK(CTG_READ, &pJob->taskLock);
|
||||
}
|
||||
|
||||
int32_t ctgInitGetTbMetaTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
|
||||
SCtgTbMetaParam* pParam = (SCtgTbMetaParam*)param;
|
||||
SName* name = pParam->pName;
|
||||
|
@ -53,7 +77,6 @@ int32_t ctgInitGetTbMetaTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
|
|||
}
|
||||
|
||||
int32_t ctgInitGetTbMetasTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
|
||||
SName* name = (SName*)param;
|
||||
SCtgTask task = {0};
|
||||
|
||||
task.type = CTG_TASK_GET_TB_META_BATCH;
|
||||
|
@ -184,7 +207,6 @@ int32_t ctgInitGetTbHashTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
|
|||
}
|
||||
|
||||
int32_t ctgInitGetTbHashsTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
|
||||
SName* name = (SName*)param;
|
||||
SCtgTask task = {0};
|
||||
|
||||
task.type = CTG_TASK_GET_TB_HASH_BATCH;
|
||||
|
@ -417,6 +439,43 @@ int32_t ctgInitGetTbTagTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgInitGetViewsTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
|
||||
SCtgTask task = {0};
|
||||
|
||||
task.type = CTG_TASK_GET_VIEW;
|
||||
task.taskId = taskIdx;
|
||||
task.pJob = pJob;
|
||||
|
||||
task.taskCtx = taosMemoryCalloc(1, sizeof(SCtgViewsCtx));
|
||||
if (NULL == task.taskCtx) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCtgViewsCtx* ctx = task.taskCtx;
|
||||
ctx->pNames = param;
|
||||
ctx->pResList = taosArrayInit(pJob->viewNum, sizeof(SMetaRes));
|
||||
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:0x%" PRIx64 " the %dth task type %s initialized, dbNum:%lu, viewNum:%d", pJob->queryId, taskIdx,
|
||||
ctgTaskTypeStr(task.type), taosArrayGetSize(ctx->pNames), pJob->viewNum);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgHandleForceUpdateView(SCatalog* pCtg, const SCatalogReq* pReq) {
|
||||
int32_t viewNum = taosArrayGetSize(pReq->pView);
|
||||
for (int32_t i = 0; i < viewNum; ++i) {
|
||||
STablesReq* p = taosArrayGet(pReq->pView, i);
|
||||
int32_t viewNum = taosArrayGetSize(p->pTables);
|
||||
for (int32_t m = 0; m < viewNum; ++m) {
|
||||
SName* name = taosArrayGet(p->pTables, m);
|
||||
ctgDropViewMetaEnqueue(pCtg, p->dbFName, 0, name->tname, 0, true);
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgHandleForceUpdate(SCatalog* pCtg, int32_t taskNum, SCtgJob* pJob, const SCatalogReq* pReq) {
|
||||
SHashObj* pDb = taosHashInit(taskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
|
@ -464,6 +523,12 @@ int32_t ctgHandleForceUpdate(SCatalog* pCtg, int32_t taskNum, SCtgJob* pJob, con
|
|||
}
|
||||
}
|
||||
|
||||
dbNum = taosArrayGetSize(pReq->pView);
|
||||
for (int32_t i = 0; i < dbNum; ++i) {
|
||||
STablesReq* p = taosArrayGet(pReq->pView, i);
|
||||
taosHashPut(pDb, p->dbFName, strlen(p->dbFName), p->dbFName, TSDB_DB_FNAME_LEN);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pJob->tbCfgNum; ++i) {
|
||||
SName* name = taosArrayGet(pReq->pTableCfg, i);
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
|
@ -508,7 +573,8 @@ int32_t ctgHandleForceUpdate(SCatalog* pCtg, int32_t taskNum, SCtgJob* pJob, con
|
|||
ctgDropTbIndexEnqueue(pCtg, name, true);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
// REFRESH VIEW META
|
||||
return ctgHandleForceUpdateView(pCtg, pReq);
|
||||
}
|
||||
|
||||
int32_t ctgInitTask(SCtgJob* pJob, CTG_TASK_TYPE type, void* param, int32_t* taskId) {
|
||||
|
@ -547,9 +613,10 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
|
|||
int32_t tbIndexNum = (int32_t)taosArrayGetSize(pReq->pTableIndex);
|
||||
int32_t tbCfgNum = (int32_t)taosArrayGetSize(pReq->pTableCfg);
|
||||
int32_t tbTagNum = (int32_t)taosArrayGetSize(pReq->pTableTag);
|
||||
int32_t viewNum = (int32_t)ctgGetTablesReqNum(pReq->pView);
|
||||
|
||||
int32_t taskNum = tbMetaNum + dbVgNum + udfNum + tbHashNum + qnodeNum + dnodeNum + svrVerNum + dbCfgNum + indexNum +
|
||||
userNum + dbInfoNum + tbIndexNum + tbCfgNum + tbTagNum;
|
||||
userNum + dbInfoNum + tbIndexNum + tbCfgNum + tbTagNum + viewNum;
|
||||
|
||||
*job = taosMemoryCalloc(1, sizeof(SCtgJob));
|
||||
if (NULL == *job) {
|
||||
|
@ -559,6 +626,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
|
|||
|
||||
SCtgJob* pJob = *job;
|
||||
|
||||
pJob->jobRes.ctgFree = true;
|
||||
pJob->subTaskNum = taskNum;
|
||||
pJob->queryId = pConn->requestId;
|
||||
pJob->userFp = fp;
|
||||
|
@ -580,6 +648,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
|
|||
pJob->tbCfgNum = tbCfgNum;
|
||||
pJob->svrVerNum = svrVerNum;
|
||||
pJob->tbTagNum = tbTagNum;
|
||||
pJob->viewNum = viewNum;
|
||||
|
||||
#if CTG_BATCH_FETCH
|
||||
pJob->pBatchs =
|
||||
|
@ -668,6 +737,10 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
|
|||
CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_USER, user, NULL));
|
||||
}
|
||||
|
||||
if (viewNum > 0) {
|
||||
CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_VIEW, pReq->pView, NULL));
|
||||
}
|
||||
|
||||
if (qnodeNum) {
|
||||
CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_QNODE, NULL, NULL));
|
||||
}
|
||||
|
@ -1001,6 +1074,20 @@ int32_t ctgDumpSvrVer(SCtgTask* pTask) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgDumpViewsRes(SCtgTask* pTask) {
|
||||
if (pTask->subTask) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SCtgJob* pJob = pTask->pJob;
|
||||
|
||||
pJob->jobRes.pView = pTask->res;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgCallSubCb(SCtgTask* pTask) {
|
||||
int32_t code = 0;
|
||||
|
||||
|
@ -1773,6 +1860,68 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgHandleGetViewsRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf* pMsg, int32_t rspCode) {
|
||||
int32_t code = 0;
|
||||
SCtgTask* pTask = tReq->pTask;
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
SRequestConnInfo* pConn = &pTask->pJob->conn;
|
||||
SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx);
|
||||
SCtgViewsCtx* ctx = (SCtgViewsCtx*)pTask->taskCtx;
|
||||
SCtgFetch* pFetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx);
|
||||
SName* pName = ctgGetFetchName(ctx->pNames, pFetch);
|
||||
int32_t flag = pFetch->flag;
|
||||
int32_t* vgId = &pFetch->vgId;
|
||||
bool taskDone = false;
|
||||
|
||||
CTG_ERR_JRET(ctgProcessRspMsg(pMsgCtx->out, reqType, pMsg->pData, pMsg->len, rspCode, pMsgCtx->target));
|
||||
|
||||
SViewMetaRsp* pRsp = *(SViewMetaRsp**)pMsgCtx->out;
|
||||
SViewMeta* pViewMeta = taosMemoryCalloc(1, sizeof(SViewMeta));
|
||||
if (NULL == pViewMeta) {
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS != (code = dupViewMetaFromRsp(pRsp, pViewMeta))) {
|
||||
ctgFreeSViewMeta(pViewMeta);
|
||||
taosMemoryFree(pViewMeta);
|
||||
CTG_ERR_JRET(code);
|
||||
}
|
||||
|
||||
ctgDebug("start to update view meta to cache, view:%s, querySQL:%s", pRsp->name, pRsp->querySql);
|
||||
ctgUpdateViewMetaToCache(pCtg, pRsp, false);
|
||||
taosMemoryFreeClear(pMsgCtx->out);
|
||||
pRsp = NULL;
|
||||
|
||||
SMetaRes* pRes = taosArrayGet(ctx->pResList, pFetch->resIdx);
|
||||
pRes->code = 0;
|
||||
pRes->pRes = pViewMeta;
|
||||
if (0 == atomic_sub_fetch_32(&ctx->fetchNum, 1)) {
|
||||
TSWAP(pTask->res, ctx->pResList);
|
||||
taskDone = true;
|
||||
}
|
||||
|
||||
_return:
|
||||
|
||||
if (code) {
|
||||
SMetaRes* pRes = taosArrayGet(ctx->pResList, pFetch->resIdx);
|
||||
pRes->code = code;
|
||||
pRes->pRes = NULL;
|
||||
ctgTaskError("Get view %d.%s.%s meta failed with error %s", pName->acctId, pName->dbname, pName->tname,
|
||||
tstrerror(code));
|
||||
if (0 == atomic_sub_fetch_32(&ctx->fetchNum, 1)) {
|
||||
TSWAP(pTask->res, ctx->pResList);
|
||||
taskDone = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (pTask->res && taskDone) {
|
||||
ctgHandleTaskEnd(pTask, code);
|
||||
}
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgAsyncRefreshTbMeta(SCtgTaskReq* tReq, int32_t flag, SName* pName, int32_t* vgId) {
|
||||
SCtgTask* pTask = tReq->pTask;
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
|
@ -2305,6 +2454,7 @@ int32_t ctgLaunchGetUserTask(SCtgTask* pTask) {
|
|||
bool inCache = false;
|
||||
SCtgAuthRsp rsp = {0};
|
||||
SCtgJob* pJob = pTask->pJob;
|
||||
bool tbNotExists = false;
|
||||
SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, -1);
|
||||
if (NULL == pMsgCtx->pBatchs) {
|
||||
pMsgCtx->pBatchs = pJob->pBatchs;
|
||||
|
@ -2314,12 +2464,22 @@ int32_t ctgLaunchGetUserTask(SCtgTask* pTask) {
|
|||
if (NULL == rsp.pRawRes) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS != pCtx->subTaskCode) {
|
||||
if (CTG_TABLE_NOT_EXIST(pCtx->subTaskCode)) {
|
||||
tbNotExists = true;
|
||||
pCtx->subTaskCode = 0;
|
||||
} else {
|
||||
CTG_ERR_RET(pCtx->subTaskCode);
|
||||
}
|
||||
}
|
||||
|
||||
CTG_ERR_RET(ctgChkAuthFromCache(pCtg, &pCtx->user, &inCache, &rsp));
|
||||
CTG_ERR_RET(ctgChkAuthFromCache(pCtg, &pCtx->user, tbNotExists, &inCache, &rsp));
|
||||
if (inCache) {
|
||||
pTask->res = rsp.pRawRes;
|
||||
|
||||
ctgTaskDebug("Final res got, pass:%d, pCond:%p", rsp.pRawRes->pass, rsp.pRawRes->pCond);
|
||||
ctgTaskDebug("Final res got, pass:[%d,%d], pCond:[%p,%p]",
|
||||
rsp.pRawRes->pass[0], rsp.pRawRes->pass[1], rsp.pRawRes->pCond[0], rsp.pRawRes->pCond[1]);
|
||||
|
||||
CTG_ERR_RET(ctgHandleTaskEnd(pTask, 0));
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -2355,6 +2515,59 @@ int32_t ctgLaunchGetSvrVerTask(SCtgTask* pTask) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgLaunchGetViewsTask(SCtgTask* pTask) {
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
SRequestConnInfo* pConn = &pTask->pJob->conn;
|
||||
SCtgViewsCtx* pCtx = (SCtgViewsCtx*)pTask->taskCtx;
|
||||
SCtgJob* pJob = pTask->pJob;
|
||||
bool tbMetaDone = false;
|
||||
|
||||
ctgIsTaskDone(pJob, CTG_TASK_GET_TB_META_BATCH, &tbMetaDone);
|
||||
if (tbMetaDone) {
|
||||
CTG_ERR_RET(ctgBuildViewNullRes(pTask, pCtx));
|
||||
TSWAP(pTask->res, pCtx->pResList);
|
||||
|
||||
CTG_ERR_RET(ctgHandleTaskEnd(pTask, 0));
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t dbNum = taosArrayGetSize(pCtx->pNames);
|
||||
int32_t fetchIdx = 0;
|
||||
int32_t baseResIdx = 0;
|
||||
for (int32_t i = 0; i < dbNum; ++i) {
|
||||
STablesReq* pReq = taosArrayGet(pCtx->pNames, i);
|
||||
ctgDebug("start to check views in db %s, viewNum %ld", pReq->dbFName, taosArrayGetSize(pReq->pTables));
|
||||
CTG_ERR_RET(ctgGetViewsFromCache(pCtg, pConn, pCtx, i, &fetchIdx, baseResIdx, pReq->pTables));
|
||||
baseResIdx += taosArrayGetSize(pReq->pTables);
|
||||
}
|
||||
|
||||
pCtx->fetchNum = taosArrayGetSize(pCtx->pFetchs);
|
||||
if (pCtx->fetchNum <= 0) {
|
||||
TSWAP(pTask->res, pCtx->pResList);
|
||||
|
||||
CTG_ERR_RET(ctgHandleTaskEnd(pTask, 0));
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pTask->msgCtxs = taosArrayInit_s(sizeof(SCtgMsgCtx), pCtx->fetchNum);
|
||||
for (int32_t i = 0; i < pCtx->fetchNum; ++i) {
|
||||
SCtgFetch* pFetch = taosArrayGet(pCtx->pFetchs, i);
|
||||
SName* pName = ctgGetFetchName(pCtx->pNames, pFetch);
|
||||
SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, i);
|
||||
if (NULL == pMsgCtx->pBatchs) {
|
||||
pMsgCtx->pBatchs = pJob->pBatchs;
|
||||
}
|
||||
|
||||
SCtgTaskReq tReq;
|
||||
tReq.pTask = pTask;
|
||||
tReq.msgIdx = pFetch->fetchIdx;
|
||||
CTG_ERR_RET(ctgGetViewInfoFromMnode(pCtg, pConn, pName, NULL, &tReq));
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgRelaunchGetTbMetaTask(SCtgTask* pTask) {
|
||||
ctgResetTbMetaTask(pTask);
|
||||
|
||||
|
@ -2410,8 +2623,9 @@ _return:
|
|||
int32_t ctgGetUserCb(SCtgTask* pTask) {
|
||||
int32_t code = 0;
|
||||
|
||||
CTG_ERR_JRET(pTask->subRes.code);
|
||||
|
||||
SCtgUserCtx* pCtx = (SCtgUserCtx*)pTask->taskCtx;
|
||||
pCtx->subTaskCode = pTask->subRes.code;
|
||||
|
||||
CTG_RET(ctgLaunchGetUserTask(pTask));
|
||||
|
||||
_return:
|
||||
|
@ -2470,6 +2684,7 @@ SCtgAsyncFps gCtgAsyncFps[] = {
|
|||
{ctgInitGetTbMetasTask, ctgLaunchGetTbMetasTask, ctgHandleGetTbMetasRsp, ctgDumpTbMetasRes, NULL, NULL},
|
||||
{ctgInitGetTbHashsTask, ctgLaunchGetTbHashsTask, ctgHandleGetTbHashsRsp, ctgDumpTbHashsRes, NULL, NULL},
|
||||
{ctgInitGetTbTagTask, ctgLaunchGetTbTagTask, ctgHandleGetTbTagRsp, ctgDumpTbTagRes, NULL, NULL},
|
||||
{ctgInitGetViewsTask, ctgLaunchGetViewsTask, ctgHandleGetViewsRsp, ctgDumpViewsRes, NULL, NULL},
|
||||
};
|
||||
|
||||
int32_t ctgMakeAsyncRes(SCtgJob* pJob) {
|
||||
|
|
|
@ -30,6 +30,8 @@ SCtgOperation gCtgCacheOperation[CTG_OP_MAX] = {{CTG_OP_UPDATE_VGROUP, "update v
|
|||
{CTG_OP_UPDATE_VG_EPSET, "update epset", ctgOpUpdateEpset},
|
||||
{CTG_OP_UPDATE_TB_INDEX, "update tbIndex", ctgOpUpdateTbIndex},
|
||||
{CTG_OP_DROP_TB_INDEX, "drop tbIndex", ctgOpDropTbIndex},
|
||||
{CTG_OP_UPDATE_VIEW_META, "update viewMeta", ctgOpUpdateViewMeta},
|
||||
{CTG_OP_DROP_VIEW_META, "drop viewMeta", ctgOpDropViewMeta},
|
||||
{CTG_OP_CLEAR_CACHE, "clear cache", ctgOpClearCache}};
|
||||
|
||||
SCtgCacheItemInfo gCtgStatItem[CTG_CI_MAX_VALUE] = {
|
||||
|
@ -49,6 +51,7 @@ SCtgCacheItemInfo gCtgStatItem[CTG_CI_MAX_VALUE] = {
|
|||
{"TblCfg ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_TBL_CFG,
|
||||
{"TblTag ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_TBL_TAG,
|
||||
{"IndexInfo ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_INDEX_INFO,
|
||||
{"viewMeta ", CTG_CI_FLAG_LEVEL_DB}, //CTG_CI_VIEW,
|
||||
{"User ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_USER,
|
||||
{"UDF ", CTG_CI_FLAG_LEVEL_CLUSTER}, //CTG_CI_UDF,
|
||||
{"SvrVer ", CTG_CI_FLAG_LEVEL_CLUSTER} //CTG_CI_SVR_VER,
|
||||
|
@ -171,6 +174,18 @@ void ctgReleaseTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, SCtgTbCache *
|
|||
}
|
||||
}
|
||||
|
||||
void ctgReleaseViewMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, SCtgViewCache *pCache) {
|
||||
if (pCache && dbCache) {
|
||||
CTG_UNLOCK(CTG_READ, &pCache->viewLock);
|
||||
taosHashRelease(dbCache->viewCache, pCache);
|
||||
}
|
||||
|
||||
if (dbCache) {
|
||||
ctgReleaseDBCache(pCtg, dbCache);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ctgReleaseTbIndexToCache(SCatalog *pCtg, SCtgDBCache *dbCache, SCtgTbCache *pCache) {
|
||||
if (pCache) {
|
||||
CTG_UNLOCK(CTG_READ, &pCache->indexLock);
|
||||
|
@ -773,7 +788,7 @@ int32_t ctgGetCachedStbNameFromSuid(SCatalog* pCtg, char* dbFName, uint64_t suid
|
|||
}
|
||||
|
||||
|
||||
int32_t ctgChkAuthFromCache(SCatalog *pCtg, SUserAuthInfo *pReq, bool *inCache, SCtgAuthRsp *pRes) {
|
||||
int32_t ctgChkAuthFromCache(SCatalog *pCtg, SUserAuthInfo *pReq, bool tbNotExists, bool *inCache, SCtgAuthRsp *pRes) {
|
||||
int32_t code = 0;
|
||||
|
||||
SCtgUserAuth *pUser = (SCtgUserAuth *)taosHashGet(pCtg->userCache, pReq->user, strlen(pReq->user));
|
||||
|
@ -790,6 +805,7 @@ int32_t ctgChkAuthFromCache(SCatalog *pCtg, SUserAuthInfo *pReq, bool *inCache,
|
|||
SCtgAuthReq req = {0};
|
||||
req.pRawReq = pReq;
|
||||
req.onlyCache = true;
|
||||
req.tbNotExists = tbNotExists;
|
||||
|
||||
CTG_LOCK(CTG_READ, &pUser->lock);
|
||||
memcpy(&req.authInfo, &pUser->userAuth, sizeof(pUser->userAuth));
|
||||
|
@ -1268,208 +1284,75 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentInit(SCtgRentMgmt *mgmt, uint32_t rentSec, int8_t type, int32_t size) {
|
||||
mgmt->slotRIdx = 0;
|
||||
mgmt->slotNum = rentSec / CTG_RENT_SLOT_SECOND;
|
||||
mgmt->type = type;
|
||||
mgmt->metaSize = size;
|
||||
int32_t ctgUpdateViewMetaEnqueue(SCatalog *pCtg, SViewMetaRsp *pRsp, bool syncOp) {
|
||||
int32_t code = 0;
|
||||
SCtgCacheOperation *op = taosMemoryCalloc(1, sizeof(SCtgCacheOperation));
|
||||
op->opId = CTG_OP_UPDATE_VIEW_META;
|
||||
op->syncOp = syncOp;
|
||||
|
||||
size_t msgSize = sizeof(SCtgRentSlot) * mgmt->slotNum;
|
||||
SCtgUpdateViewMetaMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateViewMetaMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateViewMetaMsg));
|
||||
taosMemoryFree(op);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
mgmt->slots = taosMemoryCalloc(1, msgSize);
|
||||
if (NULL == mgmt->slots) {
|
||||
qError("calloc %d failed", (int32_t)msgSize);
|
||||
char *p = strchr(pRsp->dbFName, '.');
|
||||
if (p && IS_SYS_DBNAME(p + 1)) {
|
||||
int32_t len = strlen(p + 1);
|
||||
memmove(pRsp->dbFName, p + 1, len >= TSDB_DB_FNAME_LEN ? TSDB_DB_FNAME_LEN - 1 : len);
|
||||
}
|
||||
|
||||
msg->pCtg = pCtg;
|
||||
msg->pRsp = pRsp;
|
||||
|
||||
op->data = msg;
|
||||
|
||||
CTG_ERR_RET(ctgEnqueue(pCtg, op));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
|
||||
_return:
|
||||
|
||||
if (pRsp) {
|
||||
tFreeSViewMetaRsp(pRsp);
|
||||
taosMemoryFree(pRsp);
|
||||
}
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgDropViewMetaEnqueue(SCatalog *pCtg, const char *dbFName, uint64_t dbId, const char *viewName, uint64_t viewId, bool syncOp) {
|
||||
int32_t code = 0;
|
||||
SCtgCacheOperation *op = taosMemoryCalloc(1, sizeof(SCtgCacheOperation));
|
||||
op->opId = CTG_OP_DROP_VIEW_META;
|
||||
op->syncOp = syncOp;
|
||||
|
||||
SCtgDropViewMetaMsg *msg = taosMemoryMalloc(sizeof(SCtgDropViewMetaMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgDropViewMetaMsg));
|
||||
taosMemoryFree(op);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
mgmt->rentCacheSize = msgSize;
|
||||
msg->pCtg = pCtg;
|
||||
tstrncpy(msg->dbFName, dbFName, sizeof(msg->dbFName));
|
||||
tstrncpy(msg->viewName, viewName, sizeof(msg->viewName));
|
||||
msg->dbId = dbId;
|
||||
msg->viewId = viewId;
|
||||
|
||||
qDebug("meta rent initialized, type:%d, slotNum:%d", type, mgmt->slotNum);
|
||||
op->data = msg;
|
||||
|
||||
CTG_ERR_JRET(ctgEnqueue(pCtg, op));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentAdd(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size) {
|
||||
int16_t widx = abs((int)(id % mgmt->slotNum));
|
||||
|
||||
SCtgRentSlot *slot = &mgmt->slots[widx];
|
||||
int32_t code = 0;
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &slot->lock);
|
||||
if (NULL == slot->meta) {
|
||||
slot->meta = taosArrayInit(CTG_DEFAULT_RENT_SLOT_SIZE, size);
|
||||
if (NULL == slot->meta) {
|
||||
qError("taosArrayInit %d failed, id:0x%" PRIx64 ", slot idx:%d, type:%d", CTG_DEFAULT_RENT_SLOT_SIZE, id, widx,
|
||||
mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == taosArrayPush(slot->meta, meta)) {
|
||||
qError("taosArrayPush meta to rent failed, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
mgmt->rentCacheSize += size;
|
||||
slot->needSort = true;
|
||||
|
||||
qDebug("add meta to rent, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
|
||||
_return:
|
||||
|
||||
CTG_UNLOCK(CTG_WRITE, &slot->lock);
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentUpdate(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size, __compar_fn_t sortCompare,
|
||||
__compar_fn_t searchCompare) {
|
||||
int16_t widx = abs((int)(id % mgmt->slotNum));
|
||||
|
||||
SCtgRentSlot *slot = &mgmt->slots[widx];
|
||||
int32_t code = 0;
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &slot->lock);
|
||||
if (NULL == slot->meta) {
|
||||
qDebug("empty meta slot, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
if (slot->needSort) {
|
||||
qDebug("meta slot before sorte, slot idx:%d, type:%d, size:%d", widx, mgmt->type,
|
||||
(int32_t)taosArrayGetSize(slot->meta));
|
||||
taosArraySort(slot->meta, sortCompare);
|
||||
slot->needSort = false;
|
||||
qDebug("meta slot sorted, slot idx:%d, type:%d, size:%d", widx, mgmt->type, (int32_t)taosArrayGetSize(slot->meta));
|
||||
}
|
||||
|
||||
void *orig = taosArraySearch(slot->meta, &id, searchCompare, TD_EQ);
|
||||
if (NULL == orig) {
|
||||
qDebug("meta not found in slot, id:0x%" PRIx64 ", slot idx:%d, type:%d, size:%d", id, widx, mgmt->type,
|
||||
(int32_t)taosArrayGetSize(slot->meta));
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
memcpy(orig, meta, size);
|
||||
|
||||
qDebug("meta in rent updated, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
|
||||
_return:
|
||||
|
||||
CTG_UNLOCK(CTG_WRITE, &slot->lock);
|
||||
|
||||
if (code) {
|
||||
qDebug("meta in rent update failed, will try to add it, code:%x, id:0x%" PRIx64 ", slot idx:%d, type:%d", code, id,
|
||||
widx, mgmt->type);
|
||||
CTG_RET(ctgMetaRentAdd(mgmt, meta, id, size));
|
||||
}
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentRemove(SCtgRentMgmt *mgmt, int64_t id, __compar_fn_t sortCompare, __compar_fn_t searchCompare) {
|
||||
int16_t widx = abs((int)(id % mgmt->slotNum));
|
||||
|
||||
SCtgRentSlot *slot = &mgmt->slots[widx];
|
||||
int32_t code = 0;
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &slot->lock);
|
||||
if (NULL == slot->meta) {
|
||||
qError("empty meta slot, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
if (slot->needSort) {
|
||||
taosArraySort(slot->meta, sortCompare);
|
||||
slot->needSort = false;
|
||||
qDebug("meta slot sorted, slot idx:%d, type:%d", widx, mgmt->type);
|
||||
}
|
||||
|
||||
int32_t idx = taosArraySearchIdx(slot->meta, &id, searchCompare, TD_EQ);
|
||||
if (idx < 0) {
|
||||
qError("meta not found in slot, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
taosArrayRemove(slot->meta, idx);
|
||||
mgmt->rentCacheSize -= mgmt->metaSize;
|
||||
|
||||
qDebug("meta in rent removed, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
|
||||
_return:
|
||||
|
||||
CTG_UNLOCK(CTG_WRITE, &slot->lock);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentGetImpl(SCtgRentMgmt *mgmt, void **res, uint32_t *num, int32_t size) {
|
||||
int16_t ridx = atomic_add_fetch_16(&mgmt->slotRIdx, 1);
|
||||
if (ridx >= mgmt->slotNum) {
|
||||
ridx %= mgmt->slotNum;
|
||||
atomic_store_16(&mgmt->slotRIdx, ridx);
|
||||
}
|
||||
|
||||
SCtgRentSlot *slot = &mgmt->slots[ridx];
|
||||
int32_t code = 0;
|
||||
|
||||
CTG_LOCK(CTG_READ, &slot->lock);
|
||||
if (NULL == slot->meta) {
|
||||
qDebug("empty meta in slot:%d, type:%d", ridx, mgmt->type);
|
||||
*num = 0;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
size_t metaNum = taosArrayGetSize(slot->meta);
|
||||
if (metaNum <= 0) {
|
||||
qDebug("no meta in slot:%d, type:%d", ridx, mgmt->type);
|
||||
*num = 0;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
size_t msize = metaNum * size;
|
||||
*res = taosMemoryMalloc(msize);
|
||||
if (NULL == *res) {
|
||||
qError("malloc %d failed", (int32_t)msize);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
void *meta = taosArrayGet(slot->meta, 0);
|
||||
|
||||
memcpy(*res, meta, msize);
|
||||
|
||||
*num = (uint32_t)metaNum;
|
||||
|
||||
qDebug("Got %d meta from rent, type:%d", (int32_t)metaNum, mgmt->type);
|
||||
|
||||
_return:
|
||||
|
||||
CTG_UNLOCK(CTG_READ, &slot->lock);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentGet(SCtgRentMgmt *mgmt, void **res, uint32_t *num, int32_t size) {
|
||||
while (true) {
|
||||
int64_t msec = taosGetTimestampMs();
|
||||
int64_t lsec = atomic_load_64(&mgmt->lastReadMsec);
|
||||
if ((msec - lsec) < CTG_RENT_SLOT_SECOND * 1000) {
|
||||
*res = NULL;
|
||||
*num = 0;
|
||||
qDebug("too short time period to get expired meta, type:%d", mgmt->type);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (lsec != atomic_val_compare_exchange_64(&mgmt->lastReadMsec, lsec, msec)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
CTG_ERR_RET(ctgMetaRentGetImpl(mgmt, res, num, size));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgAddNewDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId) {
|
||||
int32_t code = 0;
|
||||
|
@ -1480,7 +1363,7 @@ int32_t ctgAddNewDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId) {
|
|||
newDBCache.tbCache = taosHashInit(gCtgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY),
|
||||
true, HASH_ENTRY_LOCK);
|
||||
if (NULL == newDBCache.tbCache) {
|
||||
ctgError("taosHashInit %d metaCache failed", gCtgMgmt.cfg.maxTblCacheNum);
|
||||
ctgError("taosHashInit %d tbCache failed", gCtgMgmt.cfg.maxTblCacheNum);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
|
@ -1491,6 +1374,13 @@ int32_t ctgAddNewDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId) {
|
|||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
newDBCache.viewCache = taosHashInit(gCtgMgmt.cfg.maxViewCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY),
|
||||
true, HASH_ENTRY_LOCK);
|
||||
if (NULL == newDBCache.viewCache) {
|
||||
ctgError("taosHashInit %d viewCache failed", gCtgMgmt.cfg.maxViewCacheNum);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
code = taosHashPut(pCtg->dbCache, dbFName, strlen(dbFName), &newDBCache, sizeof(SCtgDBCache));
|
||||
if (code) {
|
||||
if (HASH_NODE_EXIST(code)) {
|
||||
|
@ -1524,25 +1414,6 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
void ctgRemoveStbRent(SCatalog *pCtg, SCtgDBCache *dbCache) {
|
||||
if (NULL == dbCache->stbCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
void *pIter = taosHashIterate(dbCache->stbCache, NULL);
|
||||
while (pIter) {
|
||||
uint64_t *suid = NULL;
|
||||
suid = taosHashGetKey(pIter, NULL);
|
||||
|
||||
if (TSDB_CODE_SUCCESS ==
|
||||
ctgMetaRentRemove(&pCtg->stbRent, *suid, ctgStbVersionSortCompare, ctgStbVersionSearchCompare)) {
|
||||
ctgDebug("stb removed from rent, suid:0x%" PRIx64, *suid);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(dbCache->stbCache, pIter);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ctgRemoveDBFromCache(SCatalog *pCtg, SCtgDBCache *dbCache, const char *dbFName) {
|
||||
uint64_t dbId = dbCache->dbId;
|
||||
|
||||
|
@ -1552,6 +1423,7 @@ int32_t ctgRemoveDBFromCache(SCatalog *pCtg, SCtgDBCache *dbCache, const char *d
|
|||
|
||||
atomic_store_8(&dbCache->deleted, 1);
|
||||
ctgRemoveStbRent(pCtg, dbCache);
|
||||
ctgRemoveViewRent(pCtg, dbCache);
|
||||
ctgFreeDbCache(dbCache);
|
||||
|
||||
CTG_UNLOCK(CTG_WRITE, &dbCache->dbLock);
|
||||
|
@ -1611,30 +1483,6 @@ int32_t ctgGetAddDBCache(SCatalog *pCtg, const char *dbFName, uint64_t dbId, SCt
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgUpdateRentStbVersion(SCatalog *pCtg, char *dbFName, char *tbName, uint64_t dbId, uint64_t suid,
|
||||
SCtgTbCache *pCache) {
|
||||
SSTableVersion metaRent = {.dbId = dbId, .suid = suid};
|
||||
if (pCache->pMeta) {
|
||||
metaRent.sversion = pCache->pMeta->sversion;
|
||||
metaRent.tversion = pCache->pMeta->tversion;
|
||||
}
|
||||
|
||||
if (pCache->pIndex) {
|
||||
metaRent.smaVer = pCache->pIndex->version;
|
||||
}
|
||||
|
||||
tstrncpy(metaRent.dbFName, dbFName, sizeof(metaRent.dbFName));
|
||||
tstrncpy(metaRent.stbName, tbName, sizeof(metaRent.stbName));
|
||||
|
||||
CTG_ERR_RET(ctgMetaRentUpdate(&pCtg->stbRent, &metaRent, metaRent.suid, sizeof(SSTableVersion),
|
||||
ctgStbVersionSortCompare, ctgStbVersionSearchCompare));
|
||||
|
||||
ctgDebug("db %s,0x%" PRIx64 " stb %s,0x%" PRIx64 " sver %d tver %d smaVer %d updated to stbRent", dbFName, dbId,
|
||||
tbName, suid, metaRent.sversion, metaRent.tversion, metaRent.smaVer);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgWriteTbMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, uint64_t dbId, char *tbName,
|
||||
STableMeta *meta, int32_t metaSize) {
|
||||
if (NULL == dbCache->tbCache || NULL == dbCache->stbCache) {
|
||||
|
@ -1787,6 +1635,65 @@ int32_t ctgWriteTbIndexToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFNa
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgWriteViewMetaToCache(SCatalog *pCtg, SCtgDBCache *dbCache, char *dbFName, char *viewName, SViewMeta *pMeta) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (NULL == dbCache->viewCache) {
|
||||
ctgWarn("db is dropping, dbId:0x%" PRIx64, dbCache->dbId);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_DB_DROPPED);
|
||||
}
|
||||
|
||||
SCtgViewCache *pCache = taosHashGet(dbCache->viewCache, viewName, strlen(viewName));
|
||||
if (NULL == pCache) {
|
||||
SCtgViewCache cache = {0};
|
||||
cache.pMeta = pMeta;
|
||||
|
||||
if (taosHashPut(dbCache->viewCache, viewName, strlen(viewName), &cache, sizeof(cache)) != 0) {
|
||||
ctgError("taosHashPut new tbCache failed, viewName:%s", viewName);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
atomic_add_fetch_64(&dbCache->dbCacheSize, strlen(viewName) + sizeof(SCtgViewCache) + ctgGetViewMetaCacheSize(pMeta));
|
||||
|
||||
CTG_DB_NUM_INC(CTG_CI_VIEW);
|
||||
|
||||
ctgDebug("new view meta updated to cache, view:%s, id:%" PRIu64 ", ver:%d, effectiveUser:%s, querySQL:%s",
|
||||
viewName, pMeta->viewId, pMeta->version, pMeta->user, pMeta->querySql);
|
||||
|
||||
CTG_ERR_RET(ctgUpdateRentViewVersion(pCtg, dbFName, viewName, dbCache->dbId, pMeta->viewId, &cache));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &pCache->viewLock);
|
||||
|
||||
if (pCache->pMeta) {
|
||||
atomic_sub_fetch_64(&dbCache->dbCacheSize, ctgGetViewMetaCacheSize(pCache->pMeta));
|
||||
ctgFreeSViewMeta(pCache->pMeta);
|
||||
taosMemoryFree(pCache->pMeta);
|
||||
}
|
||||
|
||||
pCache->pMeta = pMeta;
|
||||
CTG_UNLOCK(CTG_WRITE, &pCache->viewLock);
|
||||
|
||||
atomic_add_fetch_64(&dbCache->dbCacheSize, ctgGetViewMetaCacheSize(pMeta));
|
||||
|
||||
ctgDebug("view meta updated to cache, view:%s, id:%" PRIu64 ", ver:%d, effectiveUser:%s, querySQL:%s",
|
||||
viewName, pMeta->viewId, pMeta->version, pMeta->user, pMeta->querySql);
|
||||
|
||||
CTG_ERR_RET(ctgUpdateRentViewVersion(pCtg, dbFName, viewName, dbCache->dbId, pMeta->viewId, pCache));
|
||||
|
||||
pMeta = NULL;
|
||||
|
||||
_return:
|
||||
|
||||
if (pMeta) {
|
||||
ctgFreeSViewMeta(pMeta);
|
||||
taosMemoryFree(pMeta);
|
||||
}
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgUpdateTbMetaToCache(SCatalog *pCtg, STableMetaOutput *pOut, bool syncReq) {
|
||||
STableMetaOutput *pOutput = NULL;
|
||||
int32_t code = 0;
|
||||
|
@ -1804,6 +1711,11 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgUpdateViewMetaToCache(SCatalog *pCtg, SViewMetaRsp *pRsp, bool syncReq) {
|
||||
CTG_RET(ctgUpdateViewMetaEnqueue(pCtg, pRsp, syncReq));
|
||||
}
|
||||
|
||||
|
||||
void ctgClearAllHandles(void) {
|
||||
SCatalog *pCtg = NULL;
|
||||
|
||||
|
@ -2138,7 +2050,7 @@ int32_t ctgOpDropStbMeta(SCtgCacheOperation *operation) {
|
|||
goto _return;
|
||||
}
|
||||
|
||||
if (msg->dbId && (dbCache->dbId != msg->dbId)) {
|
||||
if ((0 != msg->dbId) && (dbCache->dbId != msg->dbId)) {
|
||||
ctgDebug("dbId already modified, dbFName:%s, current:0x%" PRIx64 ", dbId:0x%" PRIx64 ", stb:%s, suid:0x%" PRIx64,
|
||||
msg->dbFName, dbCache->dbId, msg->dbId, msg->stbName, msg->suid);
|
||||
goto _return;
|
||||
|
@ -2201,7 +2113,7 @@ int32_t ctgOpDropTbMeta(SCtgCacheOperation *operation) {
|
|||
goto _return;
|
||||
}
|
||||
|
||||
if (dbCache->dbId != msg->dbId) {
|
||||
if ((0 != msg->dbId) && (dbCache->dbId != msg->dbId)) {
|
||||
ctgDebug("dbId 0x%" PRIx64 " not match with curId 0x%" PRIx64 ", dbFName:%s, tbName:%s", msg->dbId, dbCache->dbId,
|
||||
msg->dbFName, msg->tbName);
|
||||
goto _return;
|
||||
|
@ -2265,7 +2177,7 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else if (msg->userAuth.dropped == 1) {
|
||||
if (ctgRemoveCacheUser(pCtg, msg->userAuth.user) == 0) {
|
||||
if (ctgRemoveCacheUser(pCtg, pUser, msg->userAuth.user) == 0) {
|
||||
CTG_CACHE_NUM_DEC(CTG_CI_USER, 1);
|
||||
}
|
||||
goto _return;
|
||||
|
@ -2278,6 +2190,10 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
|
|||
taosHashCleanup(pUser->userAuth.writeDbs);
|
||||
taosHashCleanup(pUser->userAuth.readTbs);
|
||||
taosHashCleanup(pUser->userAuth.writeTbs);
|
||||
taosHashCleanup(pUser->userAuth.alterTbs);
|
||||
taosHashCleanup(pUser->userAuth.readViews);
|
||||
taosHashCleanup(pUser->userAuth.writeViews);
|
||||
taosHashCleanup(pUser->userAuth.alterViews);
|
||||
taosHashCleanup(pUser->userAuth.useDbs);
|
||||
|
||||
memcpy(&pUser->userAuth, &msg->userAuth, sizeof(msg->userAuth));
|
||||
|
@ -2287,6 +2203,10 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) {
|
|||
msg->userAuth.writeDbs = NULL;
|
||||
msg->userAuth.readTbs = NULL;
|
||||
msg->userAuth.writeTbs = NULL;
|
||||
msg->userAuth.alterTbs = NULL;
|
||||
msg->userAuth.readViews = NULL;
|
||||
msg->userAuth.writeViews = NULL;
|
||||
msg->userAuth.alterViews = NULL;
|
||||
msg->userAuth.useDbs = NULL;
|
||||
|
||||
CTG_UNLOCK(CTG_WRITE, &pUser->lock);
|
||||
|
@ -2300,6 +2220,10 @@ _return:
|
|||
taosHashCleanup(msg->userAuth.writeDbs);
|
||||
taosHashCleanup(msg->userAuth.readTbs);
|
||||
taosHashCleanup(msg->userAuth.writeTbs);
|
||||
taosHashCleanup(msg->userAuth.alterTbs);
|
||||
taosHashCleanup(msg->userAuth.readViews);
|
||||
taosHashCleanup(msg->userAuth.writeViews);
|
||||
taosHashCleanup(msg->userAuth.alterViews);
|
||||
taosHashCleanup(msg->userAuth.useDbs);
|
||||
|
||||
taosMemoryFreeClear(msg);
|
||||
|
@ -2427,6 +2351,106 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgOpUpdateViewMeta(SCtgCacheOperation *operation) {
|
||||
int32_t code = 0;
|
||||
SCtgUpdateViewMetaMsg *msg = operation->data;
|
||||
SCatalog *pCtg = msg->pCtg;
|
||||
SViewMetaRsp *pRsp = msg->pRsp;
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
SViewMeta *pMeta = NULL;
|
||||
|
||||
taosMemoryFreeClear(msg);
|
||||
|
||||
if (pCtg->stopUpdate) {
|
||||
goto _return;
|
||||
}
|
||||
|
||||
CTG_ERR_JRET(ctgGetAddDBCache(pCtg, pRsp->dbFName, pRsp->dbId, &dbCache));
|
||||
if (NULL == dbCache) {
|
||||
ctgInfo("conflict db update, ignore this update, dbFName:%s, dbId:0x%" PRIx64, pRsp->dbFName, pRsp->dbId);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
pMeta = taosMemoryCalloc(1, sizeof(SViewMeta));
|
||||
if (NULL == pMeta) {
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
CTG_ERR_JRET(dupViewMetaFromRsp(pRsp, pMeta));
|
||||
|
||||
code = ctgWriteViewMetaToCache(pCtg, dbCache, pRsp->dbFName, pRsp->name, pMeta);
|
||||
pMeta = NULL;
|
||||
|
||||
_return:
|
||||
|
||||
tFreeSViewMetaRsp(pRsp);
|
||||
taosMemoryFree(pRsp);
|
||||
ctgFreeSViewMeta(pMeta);
|
||||
taosMemoryFree(pMeta);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgOpDropViewMeta(SCtgCacheOperation *operation) {
|
||||
int32_t code = 0;
|
||||
SCtgDropViewMetaMsg *msg = operation->data;
|
||||
SCatalog *pCtg = msg->pCtg;
|
||||
int32_t tblType = 0;
|
||||
|
||||
if (pCtg->stopUpdate) {
|
||||
goto _return;
|
||||
}
|
||||
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
ctgGetDBCache(pCtg, msg->dbFName, &dbCache);
|
||||
if (NULL == dbCache) {
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if ((0 != msg->dbId) && (dbCache->dbId != msg->dbId)) {
|
||||
ctgDebug("dbId 0x%" PRIx64 " not match with curId 0x%" PRIx64 ", dbFName:%s, viewName:%s", msg->dbId, dbCache->dbId,
|
||||
msg->dbFName, msg->viewName);
|
||||
goto _return;
|
||||
}
|
||||
|
||||
SCtgViewCache *pViewCache = taosHashGet(dbCache->viewCache, msg->viewName, strlen(msg->viewName));
|
||||
if (NULL == pViewCache) {
|
||||
ctgDebug("view %s already not in cache", msg->viewName);
|
||||
goto _return;
|
||||
}
|
||||
|
||||
int64_t viewId = pViewCache->pMeta->viewId;
|
||||
if (0 != msg->viewId && viewId != msg->viewId) {
|
||||
ctgDebug("viewId 0x%" PRIx64 " not match with curId 0x%" PRIx64 ", viewName:%s", msg->viewId, viewId, msg->viewName);
|
||||
goto _return;
|
||||
}
|
||||
|
||||
atomic_sub_fetch_64(&dbCache->dbCacheSize, ctgGetViewMetaCacheSize(pViewCache->pMeta));
|
||||
ctgFreeViewCacheImpl(pViewCache, true);
|
||||
|
||||
if (taosHashRemove(dbCache->viewCache, msg->viewName, strlen(msg->viewName))) {
|
||||
ctgError("view %s not exist in cache, dbFName:%s", msg->viewName, msg->dbFName);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
} else {
|
||||
atomic_sub_fetch_64(&dbCache->dbCacheSize, sizeof(SCtgViewCache) + strlen(msg->viewName));
|
||||
CTG_DB_NUM_DEC(CTG_CI_VIEW);
|
||||
}
|
||||
|
||||
ctgDebug("view %s removed from cache, dbFName:%s", msg->viewName, msg->dbFName);
|
||||
|
||||
CTG_ERR_JRET(ctgMetaRentRemove(&msg->pCtg->viewRent, viewId, ctgViewVersionSortCompare, ctgViewVersionSearchCompare));
|
||||
|
||||
ctgDebug("view %s removed from rent, dbFName:%s, viewId:0x%" PRIx64, msg->viewName, msg->dbFName, viewId);
|
||||
|
||||
_return:
|
||||
|
||||
taosMemoryFreeClear(msg);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
||||
void ctgClearFreeCache(SCtgCacheOperation *operation) {
|
||||
SCtgClearCacheMsg *msg = operation->data;
|
||||
SCatalog *pCtg = msg->pCtg;
|
||||
|
@ -2529,6 +2553,7 @@ void ctgFreeCacheOperationData(SCtgCacheOperation *op) {
|
|||
case CTG_OP_DROP_TB_META:
|
||||
case CTG_OP_UPDATE_VG_EPSET:
|
||||
case CTG_OP_DROP_TB_INDEX:
|
||||
case CTG_OP_DROP_VIEW_META:
|
||||
case CTG_OP_CLEAR_CACHE: {
|
||||
taosMemoryFreeClear(op->data);
|
||||
break;
|
||||
|
@ -2540,6 +2565,10 @@ void ctgFreeCacheOperationData(SCtgCacheOperation *op) {
|
|||
taosHashCleanup(msg->userAuth.writeDbs);
|
||||
taosHashCleanup(msg->userAuth.readTbs);
|
||||
taosHashCleanup(msg->userAuth.writeTbs);
|
||||
taosHashCleanup(msg->userAuth.alterTbs);
|
||||
taosHashCleanup(msg->userAuth.readViews);
|
||||
taosHashCleanup(msg->userAuth.writeViews);
|
||||
taosHashCleanup(msg->userAuth.alterViews);
|
||||
taosHashCleanup(msg->userAuth.useDbs);
|
||||
taosMemoryFreeClear(op->data);
|
||||
break;
|
||||
|
@ -2787,6 +2816,7 @@ int32_t ctgGetTbMetasFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMe
|
|||
CTG_LOCK(CTG_READ, &pCache->metaLock);
|
||||
if (NULL == pCache->pMeta) {
|
||||
CTG_UNLOCK(CTG_READ, &pCache->metaLock);
|
||||
taosHashRelease(dbCache->tbCache, pCache);
|
||||
ctgDebug("tb %s meta not in cache, dbFName:%s", pName->tname, dbFName);
|
||||
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
|
||||
taosArrayPush(ctx->pResList, &(SMetaRes){0});
|
||||
|
@ -3006,3 +3036,105 @@ _return:
|
|||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgGetViewsFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgViewsCtx *ctx, int32_t dbIdx,
|
||||
int32_t *fetchIdx, int32_t baseResIdx, SArray *pList) {
|
||||
int32_t tbNum = taosArrayGetSize(pList);
|
||||
SName *pName = taosArrayGet(pList, 0);
|
||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||
int32_t flag = CTG_FLAG_UNKNOWN_STB;
|
||||
uint64_t lastSuid = 0;
|
||||
STableMeta *lastTableMeta = NULL;
|
||||
|
||||
if (IS_SYS_DBNAME(pName->dbname)) {
|
||||
CTG_FLAG_SET_SYS_DB(flag);
|
||||
strcpy(dbFName, pName->dbname);
|
||||
} else {
|
||||
tNameGetFullDbName(pName, dbFName);
|
||||
}
|
||||
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
SCtgViewCache *pCache = NULL;
|
||||
ctgAcquireDBCache(pCtg, dbFName, &dbCache);
|
||||
|
||||
if (NULL == dbCache) {
|
||||
ctgDebug("db %s not in cache", dbFName);
|
||||
for (int32_t i = 0; i < tbNum; ++i) {
|
||||
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
|
||||
taosArrayPush(ctx->pResList, &(SMetaData){0});
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < tbNum; ++i) {
|
||||
pName = taosArrayGet(pList, i);
|
||||
|
||||
pCache = taosHashAcquire(dbCache->viewCache, pName->tname, strlen(pName->tname));
|
||||
if (NULL == pCache) {
|
||||
ctgDebug("view %s not in cache, dbFName:%s", pName->tname, dbFName);
|
||||
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
|
||||
taosArrayPush(ctx->pResList, &(SMetaRes){0});
|
||||
CTG_CACHE_NHIT_INC(CTG_CI_VIEW, 1);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
CTG_LOCK(CTG_READ, &pCache->viewLock);
|
||||
if (NULL == pCache->pMeta) {
|
||||
CTG_UNLOCK(CTG_READ, &pCache->viewLock);
|
||||
taosHashRelease(dbCache->viewCache, pCache);
|
||||
ctgDebug("view %s meta not in cache, dbFName:%s", pName->tname, dbFName);
|
||||
ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag);
|
||||
taosArrayPush(ctx->pResList, &(SMetaRes){0});
|
||||
CTG_CACHE_NHIT_INC(CTG_CI_VIEW, 1);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
CTG_CACHE_HIT_INC(CTG_CI_VIEW, 1);
|
||||
|
||||
SMetaRes res = {0};
|
||||
SViewMeta *pViewMeta = taosMemoryCalloc(1, sizeof(SViewMeta));
|
||||
if (NULL == pViewMeta) {
|
||||
ctgReleaseViewMetaToCache(pCtg, dbCache, pCache);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(pViewMeta, pCache->pMeta, sizeof(*pViewMeta));
|
||||
pViewMeta->querySql = tstrdup(pCache->pMeta->querySql);
|
||||
pViewMeta->user = tstrdup(pCache->pMeta->user);
|
||||
if (NULL == pViewMeta->querySql || NULL == pViewMeta->user) {
|
||||
ctgReleaseViewMetaToCache(pCtg, dbCache, pCache);
|
||||
pViewMeta->pSchema = NULL;
|
||||
taosMemoryFree(pViewMeta->querySql);
|
||||
taosMemoryFree(pViewMeta->user);
|
||||
taosMemoryFree(pViewMeta);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
pViewMeta->pSchema = taosMemoryMalloc(pViewMeta->numOfCols * sizeof(SSchema));
|
||||
if (pViewMeta->pSchema == NULL) {
|
||||
ctgReleaseViewMetaToCache(pCtg, dbCache, pCache);
|
||||
ctgFreeSViewMeta(pViewMeta);
|
||||
taosMemoryFree(pViewMeta);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
memcpy(pViewMeta->pSchema, pCache->pMeta->pSchema, pViewMeta->numOfCols * sizeof(SSchema));
|
||||
|
||||
CTG_UNLOCK(CTG_READ, &pCache->viewLock);
|
||||
taosHashRelease(dbCache->viewCache, pCache);
|
||||
|
||||
ctgDebug("Got view %s meta from cache, dbFName:%s", pName->tname, dbFName);
|
||||
|
||||
res.pRes = pViewMeta;
|
||||
taosArrayPush(ctx->pResList, &res);
|
||||
}
|
||||
|
||||
ctgReleaseDBCache(pCtg, dbCache);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -253,6 +253,12 @@ int32_t ctgdEnableDebug(char *option, bool enable) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (0 == strcasecmp(option, "stat")) {
|
||||
gCTGDebug.statEnable = enable;
|
||||
qDebug("catalog stat debug set to %d", enable);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (0 == strcasecmp(option, "stopUpdate")) {
|
||||
SCatalog *pCtg = NULL;
|
||||
|
||||
|
@ -320,6 +326,11 @@ int32_t ctgdHandleDbgCommand(char *command) {
|
|||
CTG_RET(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
if (NULL == param || NULL == option) {
|
||||
taosMemoryFree(dup);
|
||||
CTG_RET(TSDB_CODE_INVALID_PARA);
|
||||
}
|
||||
|
||||
bool enable = atoi(param);
|
||||
|
||||
int32_t code = ctgdEnableDebug(option, enable);
|
||||
|
@ -361,6 +372,10 @@ int32_t ctgdGetTbMetaNum(SCtgDBCache *dbCache) {
|
|||
return dbCache->tbCache ? (int32_t)taosHashGetSize(dbCache->tbCache) : 0;
|
||||
}
|
||||
|
||||
int32_t ctgdGetViewNum(SCtgDBCache *dbCache) {
|
||||
return dbCache->viewCache ? (int32_t)taosHashGetSize(dbCache->viewCache) : 0;
|
||||
}
|
||||
|
||||
int32_t ctgdGetStbNum(SCtgDBCache *dbCache) {
|
||||
return dbCache->stbCache ? (int32_t)taosHashGetSize(dbCache->stbCache) : 0;
|
||||
}
|
||||
|
@ -391,6 +406,8 @@ int32_t ctgdGetClusterCacheNum(SCatalog *pCtg, int32_t type) {
|
|||
return ctgdGetRentNum(&pCtg->dbRent);
|
||||
case CTG_DBG_STB_RENT_NUM:
|
||||
return ctgdGetRentNum(&pCtg->stbRent);
|
||||
case CTG_DBG_VIEW_RENT_NUM:
|
||||
return ctgdGetRentNum(&pCtg->viewRent);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -407,6 +424,8 @@ int32_t ctgdGetClusterCacheNum(SCatalog *pCtg, int32_t type) {
|
|||
case CTG_DBG_STB_NUM:
|
||||
num += ctgdGetStbNum(dbCache);
|
||||
break;
|
||||
case CTG_DBG_VIEW_NUM:
|
||||
num += ctgdGetViewNum(dbCache);
|
||||
default:
|
||||
ctgError("invalid type:%d", type);
|
||||
break;
|
||||
|
@ -459,6 +478,7 @@ void ctgdShowDBCache(SCatalog *pCtg, SHashObj *dbHash) {
|
|||
dbFName = taosHashGetKey(pIter, &len);
|
||||
|
||||
int32_t metaNum = dbCache->tbCache ? taosHashGetSize(dbCache->tbCache) : 0;
|
||||
int32_t viewNum = dbCache->viewCache ? taosHashGetSize(dbCache->viewCache) : 0;
|
||||
int32_t stbNum = dbCache->stbCache ? taosHashGetSize(dbCache->stbCache) : 0;
|
||||
int32_t vgVersion = CTG_DEFAULT_INVALID_VERSION;
|
||||
int32_t hashMethod = -1;
|
||||
|
@ -479,8 +499,8 @@ void ctgdShowDBCache(SCatalog *pCtg, SHashObj *dbHash) {
|
|||
}
|
||||
|
||||
ctgDebug("[%d] db [%.*s][0x%" PRIx64
|
||||
"] %s: metaNum:%d, stbNum:%d, vgVersion:%d, stateTs:%" PRId64 ", hashMethod:%d, prefix:%d, suffix:%d, vgNum:%d",
|
||||
i, (int32_t)len, dbFName, dbCache->dbId, dbCache->deleted ? "deleted" : "", metaNum, stbNum, vgVersion, stateTs,
|
||||
"] %s: metaNum:%d, viewNum:%d, stbNum:%d, vgVersion:%d, stateTs:%" PRId64 ", hashMethod:%d, prefix:%d, suffix:%d, vgNum:%d",
|
||||
i, (int32_t)len, dbFName, dbCache->dbId, dbCache->deleted ? "deleted" : "", metaNum, viewNum, stbNum, vgVersion, stateTs,
|
||||
hashMethod, hashPrefix, hashSuffix, vgNum);
|
||||
|
||||
if (dbCache->vgCache.vgInfo) {
|
||||
|
@ -530,9 +550,10 @@ void ctgdShowClusterCache(SCatalog *pCtg) {
|
|||
}
|
||||
|
||||
ctgDebug("## cluster 0x%" PRIx64 " %p cache Info BEGIN ##", pCtg->clusterId, pCtg);
|
||||
ctgDebug("db:%d meta:%d stb:%d dbRent:%d stbRent:%d", ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM),
|
||||
ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM),
|
||||
ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM));
|
||||
ctgDebug("db:%d tbmeta:%d viewmeta:%d stb:%d dbRent:%d stbRent:%d viewRent:%d", ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM),
|
||||
ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_VIEW_NUM),
|
||||
ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_RENT_NUM),
|
||||
ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), ctgdGetClusterCacheNum(pCtg, CTG_DBG_VIEW_RENT_NUM));
|
||||
|
||||
ctgdShowDBCache(pCtg, pCtg->dbCache);
|
||||
|
||||
|
|
|
@ -318,6 +318,21 @@ int32_t ctgProcessRspMsg(void* out, int32_t reqType, char* msg, int32_t msgSize,
|
|||
qDebug("Got svr ver from mnode");
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_VIEW_META: {
|
||||
if (TSDB_CODE_SUCCESS != rspCode) {
|
||||
qError("error rsp for get view-meta, error:%s, viewFName:%s", tstrerror(rspCode), target);
|
||||
CTG_ERR_RET(rspCode);
|
||||
}
|
||||
|
||||
code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
|
||||
if (code) {
|
||||
qError("Process get view-meta rsp failed, error:%s, viewFName:%s", tstrerror(code), target);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
qDebug("Got view-meta from mnode, viewFName:%s", target);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if (TSDB_CODE_SUCCESS != rspCode) {
|
||||
qError("Got error rsp, error:%s", tstrerror(rspCode));
|
||||
|
@ -1388,3 +1403,60 @@ int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, char** ou
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgGetViewInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pName, SViewMetaOutput* out,
|
||||
SCtgTaskReq* tReq) {
|
||||
char* msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_VIEW_META;
|
||||
SCtgTask* pTask = tReq ? tReq->pTask : NULL;
|
||||
void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont;
|
||||
char fullName[TSDB_TABLE_FNAME_LEN];
|
||||
tNameExtractFullName(pName, fullName);
|
||||
|
||||
ctgDebug("try to get view info from mnode, viewFName:%s", fullName);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](fullName, &msg, 0, &msgLen, mallocFp);
|
||||
if (code) {
|
||||
ctgError("Build view-meta msg failed, code:%x, viewFName:%s", code, fullName);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
if (pTask) {
|
||||
void* pOut = taosMemoryCalloc(1, POINTER_BYTES);
|
||||
if (NULL == pOut) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx), reqType, pOut, fullName));
|
||||
|
||||
#if CTG_BATCH_FETCH
|
||||
CTG_RET(ctgAddBatch(pCtg, 0, pConn, tReq, reqType, msg, msgLen));
|
||||
#else
|
||||
SArray* pTaskId = taosArrayInit(1, sizeof(int32_t));
|
||||
if (NULL == pTaskId) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
taosArrayPush(pTaskId, &pTask->taskId);
|
||||
|
||||
CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen));
|
||||
#endif
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = reqType,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
rpcSendRecv(pConn->pTrans, &pConn->mgmtEps, &rpcMsg, &rpcRsp);
|
||||
|
||||
CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, fullName));
|
||||
|
||||
rpcFreeCont(rpcRsp.pCont);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,306 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "catalogInt.h"
|
||||
#include "query.h"
|
||||
#include "systable.h"
|
||||
#include "tname.h"
|
||||
#include "trpc.h"
|
||||
|
||||
int32_t ctgMetaRentInit(SCtgRentMgmt *mgmt, uint32_t rentSec, int8_t type, int32_t size) {
|
||||
mgmt->slotRIdx = 0;
|
||||
mgmt->slotNum = rentSec / CTG_RENT_SLOT_SECOND;
|
||||
mgmt->type = type;
|
||||
mgmt->metaSize = size;
|
||||
|
||||
size_t msgSize = sizeof(SCtgRentSlot) * mgmt->slotNum;
|
||||
|
||||
mgmt->slots = taosMemoryCalloc(1, msgSize);
|
||||
if (NULL == mgmt->slots) {
|
||||
qError("calloc %d failed", (int32_t)msgSize);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
mgmt->rentCacheSize = msgSize;
|
||||
|
||||
qDebug("meta rent initialized, type:%d, slotNum:%d", type, mgmt->slotNum);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentAdd(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size) {
|
||||
int16_t widx = abs((int)(id % mgmt->slotNum));
|
||||
|
||||
SCtgRentSlot *slot = &mgmt->slots[widx];
|
||||
int32_t code = 0;
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &slot->lock);
|
||||
if (NULL == slot->meta) {
|
||||
slot->meta = taosArrayInit(CTG_DEFAULT_RENT_SLOT_SIZE, size);
|
||||
if (NULL == slot->meta) {
|
||||
qError("taosArrayInit %d failed, id:0x%" PRIx64 ", slot idx:%d, type:%d", CTG_DEFAULT_RENT_SLOT_SIZE, id, widx,
|
||||
mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == taosArrayPush(slot->meta, meta)) {
|
||||
qError("taosArrayPush meta to rent failed, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
mgmt->rentCacheSize += size;
|
||||
slot->needSort = true;
|
||||
|
||||
qDebug("add meta to rent, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
|
||||
_return:
|
||||
|
||||
CTG_UNLOCK(CTG_WRITE, &slot->lock);
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentUpdate(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size, __compar_fn_t sortCompare,
|
||||
__compar_fn_t searchCompare) {
|
||||
int16_t widx = abs((int)(id % mgmt->slotNum));
|
||||
|
||||
SCtgRentSlot *slot = &mgmt->slots[widx];
|
||||
int32_t code = 0;
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &slot->lock);
|
||||
if (NULL == slot->meta) {
|
||||
qDebug("empty meta slot, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
if (slot->needSort) {
|
||||
qDebug("meta slot before sorte, slot idx:%d, type:%d, size:%d", widx, mgmt->type,
|
||||
(int32_t)taosArrayGetSize(slot->meta));
|
||||
taosArraySort(slot->meta, sortCompare);
|
||||
slot->needSort = false;
|
||||
qDebug("meta slot sorted, slot idx:%d, type:%d, size:%d", widx, mgmt->type, (int32_t)taosArrayGetSize(slot->meta));
|
||||
}
|
||||
|
||||
void *orig = taosArraySearch(slot->meta, &id, searchCompare, TD_EQ);
|
||||
if (NULL == orig) {
|
||||
qDebug("meta not found in slot, id:0x%" PRIx64 ", slot idx:%d, type:%d, size:%d", id, widx, mgmt->type,
|
||||
(int32_t)taosArrayGetSize(slot->meta));
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
memcpy(orig, meta, size);
|
||||
|
||||
qDebug("meta in rent updated, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
|
||||
_return:
|
||||
|
||||
CTG_UNLOCK(CTG_WRITE, &slot->lock);
|
||||
|
||||
if (code) {
|
||||
qDebug("meta in rent update failed, will try to add it, code:%x, id:0x%" PRIx64 ", slot idx:%d, type:%d", code, id,
|
||||
widx, mgmt->type);
|
||||
CTG_RET(ctgMetaRentAdd(mgmt, meta, id, size));
|
||||
}
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentRemove(SCtgRentMgmt *mgmt, int64_t id, __compar_fn_t sortCompare, __compar_fn_t searchCompare) {
|
||||
int16_t widx = abs((int)(id % mgmt->slotNum));
|
||||
|
||||
SCtgRentSlot *slot = &mgmt->slots[widx];
|
||||
int32_t code = 0;
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &slot->lock);
|
||||
if (NULL == slot->meta) {
|
||||
qError("empty meta slot, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
if (slot->needSort) {
|
||||
taosArraySort(slot->meta, sortCompare);
|
||||
slot->needSort = false;
|
||||
qDebug("meta slot sorted, slot idx:%d, type:%d", widx, mgmt->type);
|
||||
}
|
||||
|
||||
int32_t idx = taosArraySearchIdx(slot->meta, &id, searchCompare, TD_EQ);
|
||||
if (idx < 0) {
|
||||
qError("meta not found in slot, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
taosArrayRemove(slot->meta, idx);
|
||||
mgmt->rentCacheSize -= mgmt->metaSize;
|
||||
|
||||
qDebug("meta in rent removed, id:0x%" PRIx64 ", slot idx:%d, type:%d", id, widx, mgmt->type);
|
||||
|
||||
_return:
|
||||
|
||||
CTG_UNLOCK(CTG_WRITE, &slot->lock);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentGetImpl(SCtgRentMgmt *mgmt, void **res, uint32_t *num, int32_t size) {
|
||||
int16_t ridx = atomic_add_fetch_16(&mgmt->slotRIdx, 1);
|
||||
if (ridx >= mgmt->slotNum) {
|
||||
ridx %= mgmt->slotNum;
|
||||
atomic_store_16(&mgmt->slotRIdx, ridx);
|
||||
}
|
||||
|
||||
SCtgRentSlot *slot = &mgmt->slots[ridx];
|
||||
int32_t code = 0;
|
||||
|
||||
CTG_LOCK(CTG_READ, &slot->lock);
|
||||
if (NULL == slot->meta) {
|
||||
qDebug("empty meta in slot:%d, type:%d", ridx, mgmt->type);
|
||||
*num = 0;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
size_t metaNum = taosArrayGetSize(slot->meta);
|
||||
if (metaNum <= 0) {
|
||||
qDebug("no meta in slot:%d, type:%d", ridx, mgmt->type);
|
||||
*num = 0;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
size_t msize = metaNum * size;
|
||||
*res = taosMemoryMalloc(msize);
|
||||
if (NULL == *res) {
|
||||
qError("malloc %d failed", (int32_t)msize);
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
void *meta = taosArrayGet(slot->meta, 0);
|
||||
|
||||
memcpy(*res, meta, msize);
|
||||
|
||||
*num = (uint32_t)metaNum;
|
||||
|
||||
qDebug("Got %d meta from rent, type:%d", (int32_t)metaNum, mgmt->type);
|
||||
|
||||
_return:
|
||||
|
||||
CTG_UNLOCK(CTG_READ, &slot->lock);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgMetaRentGet(SCtgRentMgmt *mgmt, void **res, uint32_t *num, int32_t size) {
|
||||
while (true) {
|
||||
int64_t msec = taosGetTimestampMs();
|
||||
int64_t lsec = atomic_load_64(&mgmt->lastReadMsec);
|
||||
if ((msec - lsec) < CTG_RENT_SLOT_SECOND * 1000) {
|
||||
*res = NULL;
|
||||
*num = 0;
|
||||
qDebug("too short time period to get expired meta, type:%d", mgmt->type);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (lsec != atomic_val_compare_exchange_64(&mgmt->lastReadMsec, lsec, msec)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
CTG_ERR_RET(ctgMetaRentGetImpl(mgmt, res, num, size));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void ctgRemoveStbRent(SCatalog *pCtg, SCtgDBCache *dbCache) {
|
||||
if (NULL == dbCache->stbCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
void *pIter = taosHashIterate(dbCache->stbCache, NULL);
|
||||
while (pIter) {
|
||||
uint64_t *suid = NULL;
|
||||
suid = taosHashGetKey(pIter, NULL);
|
||||
|
||||
if (TSDB_CODE_SUCCESS ==
|
||||
ctgMetaRentRemove(&pCtg->stbRent, *suid, ctgStbVersionSortCompare, ctgStbVersionSearchCompare)) {
|
||||
ctgDebug("stb removed from rent, suid:0x%" PRIx64, *suid);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(dbCache->stbCache, pIter);
|
||||
}
|
||||
}
|
||||
|
||||
void ctgRemoveViewRent(SCatalog *pCtg, SCtgDBCache *dbCache) {
|
||||
if (NULL == dbCache->stbCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
void *pIter = taosHashIterate(dbCache->viewCache, NULL);
|
||||
while (pIter) {
|
||||
uint64_t viewId = ((SCtgViewCache*)pIter)->pMeta->viewId;
|
||||
|
||||
if (TSDB_CODE_SUCCESS ==
|
||||
ctgMetaRentRemove(&pCtg->viewRent, viewId, ctgViewVersionSortCompare, ctgViewVersionSearchCompare)) {
|
||||
ctgDebug("view removed from rent, viewId:0x%" PRIx64, viewId);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(dbCache->viewCache, pIter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgUpdateRentStbVersion(SCatalog *pCtg, char *dbFName, char *tbName, uint64_t dbId, uint64_t suid,
|
||||
SCtgTbCache *pCache) {
|
||||
SSTableVersion metaRent = {.dbId = dbId, .suid = suid};
|
||||
if (pCache->pMeta) {
|
||||
metaRent.sversion = pCache->pMeta->sversion;
|
||||
metaRent.tversion = pCache->pMeta->tversion;
|
||||
}
|
||||
|
||||
if (pCache->pIndex) {
|
||||
metaRent.smaVer = pCache->pIndex->version;
|
||||
}
|
||||
|
||||
tstrncpy(metaRent.dbFName, dbFName, sizeof(metaRent.dbFName));
|
||||
tstrncpy(metaRent.stbName, tbName, sizeof(metaRent.stbName));
|
||||
|
||||
CTG_ERR_RET(ctgMetaRentUpdate(&pCtg->stbRent, &metaRent, metaRent.suid, sizeof(SSTableVersion),
|
||||
ctgStbVersionSortCompare, ctgStbVersionSearchCompare));
|
||||
|
||||
ctgDebug("db %s,0x%" PRIx64 " stb %s,0x%" PRIx64 " sver %d tver %d smaVer %d updated to stbRent", dbFName, dbId,
|
||||
tbName, suid, metaRent.sversion, metaRent.tversion, metaRent.smaVer);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgUpdateRentViewVersion(SCatalog *pCtg, char *dbFName, char *viewName, uint64_t dbId, uint64_t viewId,
|
||||
SCtgViewCache *pCache) {
|
||||
SViewVersion metaRent = {.dbId = dbId, .viewId = viewId};
|
||||
metaRent.version = pCache->pMeta->version;
|
||||
|
||||
tstrncpy(metaRent.dbFName, dbFName, sizeof(metaRent.dbFName));
|
||||
tstrncpy(metaRent.viewName, viewName, sizeof(metaRent.viewName));
|
||||
|
||||
CTG_ERR_RET(ctgMetaRentUpdate(&pCtg->viewRent, &metaRent, metaRent.viewId, sizeof(SViewVersion),
|
||||
ctgViewVersionSortCompare, ctgViewVersionSearchCompare));
|
||||
|
||||
ctgDebug("db %s,0x%" PRIx64 " view %s,0x%" PRIx64 " version %d updated to viewRent", dbFName, dbId, viewName, viewId, metaRent.version);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -19,6 +19,16 @@
|
|||
#include "tname.h"
|
||||
#include "trpc.h"
|
||||
|
||||
void ctgFreeSViewMeta(SViewMeta* pMeta) {
|
||||
if (NULL == pMeta) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosMemoryFree(pMeta->user);
|
||||
taosMemoryFree(pMeta->querySql);
|
||||
taosMemoryFree(pMeta->pSchema);
|
||||
}
|
||||
|
||||
void ctgFreeMsgSendParam(void* param) {
|
||||
if (NULL == param) {
|
||||
return;
|
||||
|
@ -93,6 +103,10 @@ char* ctgTaskTypeStr(CTG_TASK_TYPE type) {
|
|||
return "[bget table meta]";
|
||||
case CTG_TASK_GET_TB_HASH_BATCH:
|
||||
return "[bget table hash]";
|
||||
case CTG_TASK_GET_TB_TAG:
|
||||
return "[get table tag]";
|
||||
case CTG_TASK_GET_VIEW:
|
||||
return "[get view]";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
|
@ -173,6 +187,9 @@ void ctgFreeSMetaData(SMetaData* pData) {
|
|||
taosArrayDestroy(pData->pTableTag);
|
||||
pData->pTableTag = NULL;
|
||||
|
||||
taosArrayDestroy(pData->pView);
|
||||
pData->pView = NULL;
|
||||
|
||||
taosMemoryFreeClear(pData->pSvrVer);
|
||||
}
|
||||
|
||||
|
@ -182,6 +199,10 @@ void ctgFreeSCtgUserAuth(SCtgUserAuth* userCache) {
|
|||
taosHashCleanup(userCache->userAuth.writeDbs);
|
||||
taosHashCleanup(userCache->userAuth.readTbs);
|
||||
taosHashCleanup(userCache->userAuth.writeTbs);
|
||||
taosHashCleanup(userCache->userAuth.alterTbs);
|
||||
taosHashCleanup(userCache->userAuth.readViews);
|
||||
taosHashCleanup(userCache->userAuth.writeViews);
|
||||
taosHashCleanup(userCache->userAuth.alterViews);
|
||||
taosHashCleanup(userCache->userAuth.useDbs);
|
||||
}
|
||||
|
||||
|
@ -235,12 +256,38 @@ void ctgFreeTbCacheImpl(SCtgTbCache* pCache, bool lock) {
|
|||
}
|
||||
}
|
||||
|
||||
void ctgFreeViewCacheImpl(SCtgViewCache* pCache, bool lock) {
|
||||
if (lock) {
|
||||
CTG_LOCK(CTG_WRITE, &pCache->viewLock);
|
||||
}
|
||||
if (pCache->pMeta) {
|
||||
ctgFreeSViewMeta(pCache->pMeta);
|
||||
taosMemoryFreeClear(pCache->pMeta);
|
||||
}
|
||||
if (lock) {
|
||||
CTG_UNLOCK(CTG_WRITE, &pCache->viewLock);
|
||||
}
|
||||
}
|
||||
|
||||
void ctgFreeViewCache(SCtgDBCache* dbCache) {
|
||||
if (NULL == dbCache->viewCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCtgViewCache* pCache = taosHashIterate(dbCache->viewCache, NULL);
|
||||
while (NULL != pCache) {
|
||||
ctgFreeViewCacheImpl(pCache, false);
|
||||
pCache = taosHashIterate(dbCache->viewCache, pCache);
|
||||
}
|
||||
taosHashCleanup(dbCache->viewCache);
|
||||
dbCache->viewCache = NULL;
|
||||
}
|
||||
|
||||
void ctgFreeTbCache(SCtgDBCache* dbCache) {
|
||||
if (NULL == dbCache->tbCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t tblNum = taosHashGetSize(dbCache->tbCache);
|
||||
SCtgTbCache* pCache = taosHashIterate(dbCache->tbCache, NULL);
|
||||
while (NULL != pCache) {
|
||||
ctgFreeTbCacheImpl(pCache, false);
|
||||
|
@ -262,6 +309,7 @@ void ctgFreeDbCache(SCtgDBCache* dbCache) {
|
|||
ctgFreeCfgInfoCache(dbCache);
|
||||
ctgFreeStbMetaCache(dbCache);
|
||||
ctgFreeTbCache(dbCache);
|
||||
ctgFreeViewCache(dbCache);
|
||||
}
|
||||
|
||||
void ctgFreeInstDbCache(SHashObj* pDbCache) {
|
||||
|
@ -304,6 +352,7 @@ void ctgFreeInstUserCache(SHashObj* pUserCache) {
|
|||
void ctgFreeHandleImpl(SCatalog* pCtg) {
|
||||
ctgFreeMetaRent(&pCtg->dbRent);
|
||||
ctgFreeMetaRent(&pCtg->stbRent);
|
||||
ctgFreeMetaRent(&pCtg->viewRent);
|
||||
|
||||
ctgFreeInstDbCache(pCtg->dbCache);
|
||||
ctgFreeInstUserCache(pCtg->userCache);
|
||||
|
@ -311,17 +360,13 @@ void ctgFreeHandleImpl(SCatalog* pCtg) {
|
|||
taosMemoryFree(pCtg);
|
||||
}
|
||||
|
||||
int32_t ctgRemoveCacheUser(SCatalog* pCtg, const char* user) {
|
||||
if (!pCtg || !user) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SCtgUserAuth* pUser = (SCtgUserAuth*)taosHashGet(pCtg->userCache, user, strlen(user));
|
||||
if (pUser) {
|
||||
ctgFreeSCtgUserAuth(pUser);
|
||||
if (taosHashRemove(pCtg->userCache, user, strlen(user)) == 0) {
|
||||
return 0; // user found and removed
|
||||
}
|
||||
int32_t ctgRemoveCacheUser(SCatalog* pCtg, SCtgUserAuth* pUser, const char* user) {
|
||||
CTG_LOCK(CTG_WRITE, &pUser->lock);
|
||||
ctgFreeSCtgUserAuth(pUser);
|
||||
CTG_UNLOCK(CTG_WRITE, &pUser->lock);
|
||||
|
||||
if (taosHashRemove(pCtg->userCache, user, strlen(user)) == 0) {
|
||||
return 0; // user found and removed
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@ -336,6 +381,7 @@ void ctgFreeHandle(SCatalog* pCtg) {
|
|||
|
||||
ctgFreeMetaRent(&pCtg->dbRent);
|
||||
ctgFreeMetaRent(&pCtg->stbRent);
|
||||
ctgFreeMetaRent(&pCtg->viewRent);
|
||||
|
||||
ctgFreeInstDbCache(pCtg->dbCache);
|
||||
ctgFreeInstUserCache(pCtg->userCache);
|
||||
|
@ -421,12 +467,14 @@ void ctgClearHandle(SCatalog* pCtg) {
|
|||
|
||||
ctgFreeMetaRent(&pCtg->dbRent);
|
||||
ctgFreeMetaRent(&pCtg->stbRent);
|
||||
ctgFreeMetaRent(&pCtg->viewRent);
|
||||
|
||||
ctgFreeInstDbCache(pCtg->dbCache);
|
||||
ctgFreeInstUserCache(pCtg->userCache);
|
||||
|
||||
ctgMetaRentInit(&pCtg->dbRent, gCtgMgmt.cfg.dbRentSec, CTG_RENT_DB, sizeof(SDbCacheInfo));
|
||||
ctgMetaRentInit(&pCtg->stbRent, gCtgMgmt.cfg.stbRentSec, CTG_RENT_STABLE, sizeof(SSTableVersion));
|
||||
ctgMetaRentInit(&pCtg->viewRent, gCtgMgmt.cfg.viewRentSec, CTG_RENT_VIEW, sizeof(SViewVersion));
|
||||
|
||||
pCtg->dbCache = taosHashInit(gCtgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false,
|
||||
HASH_ENTRY_LOCK);
|
||||
|
@ -525,10 +573,25 @@ void ctgFreeMsgCtx(SCtgMsgCtx* pCtx) {
|
|||
taosHashCleanup(pOut->writeDbs);
|
||||
taosHashCleanup(pOut->readTbs);
|
||||
taosHashCleanup(pOut->writeTbs);
|
||||
taosHashCleanup(pOut->alterTbs);
|
||||
taosHashCleanup(pOut->readViews);
|
||||
taosHashCleanup(pOut->writeViews);
|
||||
taosHashCleanup(pOut->alterViews);
|
||||
taosHashCleanup(pOut->useDbs);
|
||||
taosMemoryFreeClear(pCtx->out);
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_VIEW_META: {
|
||||
if (NULL != pCtx->out) {
|
||||
SViewMetaRsp* pOut = *(SViewMetaRsp**)pCtx->out;
|
||||
if (NULL != pOut) {
|
||||
tFreeSViewMetaRsp(pOut);
|
||||
taosMemoryFree(pOut);
|
||||
}
|
||||
taosMemoryFreeClear(pCtx->out);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qError("invalid reqType %d", pCtx->reqType);
|
||||
break;
|
||||
|
@ -587,6 +650,19 @@ void ctgFreeBatchHash(void* hash) {
|
|||
taosMemoryFreeClear(pRes->pRes);
|
||||
}
|
||||
|
||||
void ctgFreeViewMetaRes(void* res) {
|
||||
if (NULL == res) {
|
||||
return;
|
||||
}
|
||||
|
||||
SMetaRes* pRes = (SMetaRes*)res;
|
||||
if (NULL != pRes->pRes) {
|
||||
SViewMeta* pMeta = (SViewMeta*)pRes->pRes;
|
||||
ctgFreeSViewMeta(pMeta);
|
||||
taosMemoryFreeClear(pRes->pRes);
|
||||
}
|
||||
}
|
||||
|
||||
void ctgFreeJsonTagVal(void* val) {
|
||||
if (NULL == val) {
|
||||
return;
|
||||
|
@ -632,7 +708,9 @@ void ctgFreeTaskRes(CTG_TASK_TYPE type, void** pRes) {
|
|||
case CTG_TASK_GET_USER: {
|
||||
if (*pRes) {
|
||||
SUserAuthRes* pAuth = (SUserAuthRes*)*pRes;
|
||||
nodesDestroyNode(pAuth->pCond);
|
||||
for (int32_t i = 0; i < AUTH_RES_MAX_VALUE; ++i) {
|
||||
nodesDestroyNode(pAuth->pCond[i]);
|
||||
}
|
||||
taosMemoryFreeClear(*pRes);
|
||||
}
|
||||
break;
|
||||
|
@ -673,6 +751,15 @@ void ctgFreeTaskRes(CTG_TASK_TYPE type, void** pRes) {
|
|||
*pRes = NULL; // no need to free it
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_VIEW: {
|
||||
SArray* pArray = (SArray*)*pRes;
|
||||
int32_t num = taosArrayGetSize(pArray);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
ctgFreeViewMetaRes(taosArrayGet(pArray, i));
|
||||
}
|
||||
*pRes = NULL; // no need to free it
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qError("invalid task type %d", type);
|
||||
break;
|
||||
|
@ -825,22 +912,35 @@ void ctgFreeTaskCtx(SCtgTask* pTask) {
|
|||
taosMemoryFreeClear(pTask->taskCtx);
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_VIEW: {
|
||||
SCtgViewsCtx* taskCtx = (SCtgViewsCtx*)pTask->taskCtx;
|
||||
taosArrayDestroyEx(taskCtx->pResList, ctgFreeViewMetaRes);
|
||||
taosArrayDestroy(taskCtx->pFetchs);
|
||||
// NO NEED TO FREE pNames
|
||||
|
||||
taosArrayDestroyEx(pTask->msgCtxs, (FDelete)ctgFreeMsgCtx);
|
||||
|
||||
taosMemoryFreeClear(pTask->taskCtx);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qError("invalid task type %d", pTask->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ctgFreeTask(SCtgTask* pTask) {
|
||||
void ctgFreeTask(SCtgTask* pTask, bool freeRes) {
|
||||
ctgFreeMsgCtx(&pTask->msgCtx);
|
||||
ctgFreeTaskRes(pTask->type, &pTask->res);
|
||||
if (freeRes || pTask->subTask) {
|
||||
ctgFreeTaskRes(pTask->type, &pTask->res);
|
||||
}
|
||||
ctgFreeTaskCtx(pTask);
|
||||
|
||||
taosArrayDestroy(pTask->pParents);
|
||||
ctgClearSubTaskRes(&pTask->subRes);
|
||||
}
|
||||
|
||||
void ctgFreeTasks(SArray* pArray) {
|
||||
void ctgFreeTasks(SArray* pArray, bool freeRes) {
|
||||
if (NULL == pArray) {
|
||||
return;
|
||||
}
|
||||
|
@ -848,7 +948,7 @@ void ctgFreeTasks(SArray* pArray) {
|
|||
int32_t num = taosArrayGetSize(pArray);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SCtgTask* pTask = taosArrayGet(pArray, i);
|
||||
ctgFreeTask(pTask);
|
||||
ctgFreeTask(pTask, freeRes);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
|
@ -864,7 +964,7 @@ void ctgFreeJob(void* job) {
|
|||
int64_t rid = pJob->refId;
|
||||
uint64_t qid = pJob->queryId;
|
||||
|
||||
ctgFreeTasks(pJob->pTasks);
|
||||
ctgFreeTasks(pJob->pTasks, pJob->jobRes.ctgFree);
|
||||
ctgFreeBatchs(pJob->pBatchs);
|
||||
|
||||
ctgFreeSMetaData(&pJob->jobRes);
|
||||
|
@ -1218,6 +1318,17 @@ int32_t ctgDbCacheInfoSearchCompare(const void* key1, const void* key2) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t ctgViewVersionSearchCompare(const void* key1, const void* key2) {
|
||||
if (*(uint64_t*)key1 < ((SViewVersion*)key2)->viewId) {
|
||||
return -1;
|
||||
} else if (*(uint64_t*)key1 > ((SViewVersion*)key2)->viewId) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgStbVersionSortCompare(const void* key1, const void* key2) {
|
||||
if (((SSTableVersion*)key1)->suid < ((SSTableVersion*)key2)->suid) {
|
||||
return -1;
|
||||
|
@ -1238,6 +1349,17 @@ int32_t ctgDbCacheInfoSortCompare(const void* key1, const void* key2) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t ctgViewVersionSortCompare(const void* key1, const void* key2) {
|
||||
if (((SViewVersion*)key1)->viewId < ((SViewVersion*)key2)->viewId) {
|
||||
return -1;
|
||||
} else if (((SViewVersion*)key1)->viewId > ((SViewVersion*)key2)->viewId) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgMakeVgArray(SDBVgInfo* dbInfo) {
|
||||
if (NULL == dbInfo) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1452,9 +1574,9 @@ static void* ctgCloneVgroupInfo(void* pSrc) {
|
|||
|
||||
static void ctgFreeVgroupInfo(void* p) { taosMemoryFree(((SMetaRes*)p)->pRes); }
|
||||
|
||||
static void* ctgCloneTableIndices(void* pSrc) { return taosArrayDup((const SArray*)pSrc, NULL); }
|
||||
static void* ctgCloneTableIndexs(void* pSrc) { return taosArrayDup((const SArray*)pSrc, NULL); }
|
||||
|
||||
static void ctgFreeTableIndices(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); }
|
||||
static void ctgFreeTableIndexs(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); }
|
||||
|
||||
static void* ctgCloneFuncInfo(void* pSrc) {
|
||||
SFuncInfo* pDst = taosMemoryMalloc(sizeof(SFuncInfo));
|
||||
|
@ -1508,6 +1630,34 @@ static void* ctgCloneDnodeList(void* pSrc) { return taosArrayDup((const SArray*)
|
|||
|
||||
static void ctgFreeDnodeList(void* p) { taosArrayDestroy((SArray*)((SMetaRes*)p)->pRes); }
|
||||
|
||||
static void* ctgCloneViewMeta(void* pSrc) {
|
||||
SViewMeta* pSrcMeta = pSrc;
|
||||
SViewMeta* pDst = taosMemoryMalloc(sizeof(SViewMeta));
|
||||
if (NULL == pDst) {
|
||||
return NULL;
|
||||
}
|
||||
pDst->user = tstrdup(pSrcMeta->user);
|
||||
pDst->querySql = tstrdup(pSrcMeta->querySql);
|
||||
pDst->pSchema = taosMemoryMalloc(pSrcMeta->numOfCols * sizeof(*pSrcMeta->pSchema));
|
||||
if (NULL == pDst->pSchema) {
|
||||
return pDst;
|
||||
}
|
||||
memcpy(pDst->pSchema, pSrcMeta->pSchema, pSrcMeta->numOfCols * sizeof(*pSrcMeta->pSchema));
|
||||
return pDst;
|
||||
}
|
||||
|
||||
static void ctgFreeViewMeta(void* p) {
|
||||
SViewMeta* pMeta = ((SMetaRes*)p)->pRes;
|
||||
if (NULL == pMeta) {
|
||||
return;
|
||||
}
|
||||
taosMemoryFree(pMeta->user);
|
||||
taosMemoryFree(pMeta->querySql);
|
||||
taosMemoryFree(pMeta->pSchema);
|
||||
taosMemoryFree(pMeta);
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgChkSetTbAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
||||
int32_t code = 0;
|
||||
STableMeta* pMeta = NULL;
|
||||
|
@ -1523,18 +1673,18 @@ int32_t ctgChkSetTbAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
|||
while (true) {
|
||||
taosMemoryFreeClear(pMeta);
|
||||
|
||||
char* pCond = taosHashGet(pTbs, tbFName, strlen(tbFName));
|
||||
char* pCond = taosHashGet(pTbs, tbFName, strlen(tbFName) + 1);
|
||||
if (pCond) {
|
||||
if (strlen(pCond) > 1) {
|
||||
CTG_ERR_JRET(nodesStringToNode(pCond, &res->pRawRes->pCond));
|
||||
CTG_ERR_JRET(nodesStringToNode(pCond, &res->pRawRes->pCond[AUTH_RES_BASIC]));
|
||||
}
|
||||
|
||||
res->pRawRes->pass = true;
|
||||
res->pRawRes->pass[AUTH_RES_BASIC] = true;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
if (stbName) {
|
||||
res->pRawRes->pass = false;
|
||||
res->pRawRes->pass[AUTH_RES_BASIC] = false;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
|
@ -1554,7 +1704,7 @@ int32_t ctgChkSetTbAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
|||
}
|
||||
|
||||
if (TSDB_SUPER_TABLE == pMeta->tableType || TSDB_NORMAL_TABLE == pMeta->tableType) {
|
||||
res->pRawRes->pass = false;
|
||||
res->pRawRes->pass[AUTH_RES_BASIC] = false;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
|
@ -1586,31 +1736,36 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
||||
int32_t ctgChkSetBasicAuthRes(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;
|
||||
pRes->pass[AUTH_RES_BASIC] = false;
|
||||
pRes->pCond[AUTH_RES_BASIC] = NULL;
|
||||
|
||||
if (!pInfo->enable) {
|
||||
pRes->pass = false;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (pInfo->superAuth) {
|
||||
pRes->pass = true;
|
||||
pRes->pass[AUTH_RES_BASIC] = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (IS_SYS_DBNAME(pReq->tbName.dbname)) {
|
||||
pRes->pass = true;
|
||||
pRes->pass[AUTH_RES_BASIC] = true;
|
||||
ctgDebug("sysdb %s, pass", pReq->tbName.dbname);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (req->tbNotExists) {
|
||||
//pRes->pass[AUTH_RES_BASIC] = true;
|
||||
//return TSDB_CODE_SUCCESS;
|
||||
pReq->tbName.type = TSDB_DB_NAME_T;
|
||||
}
|
||||
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
tNameGetFullDbName(&pReq->tbName, dbFName);
|
||||
|
||||
|
@ -1627,13 +1782,13 @@ int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
|||
if (pReq->tbName.type == TSDB_TABLE_NAME_T && pInfo->readTbs && taosHashGetSize(pInfo->readTbs) > 0) {
|
||||
req->singleType = AUTH_TYPE_READ;
|
||||
CTG_ERR_RET(ctgChkSetTbAuthRes(pCtg, req, res));
|
||||
if (pRes->pass || res->metaNotExists) {
|
||||
if (pRes->pass[AUTH_RES_BASIC] || res->metaNotExists) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
if (pInfo->readDbs && taosHashGet(pInfo->readDbs, dbFName, strlen(dbFName))) {
|
||||
pRes->pass = true;
|
||||
if (pInfo->readDbs && taosHashGet(pInfo->readDbs, dbFName, strlen(dbFName) + 1)) {
|
||||
pRes->pass[AUTH_RES_BASIC] = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1643,23 +1798,23 @@ int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
|||
if (pReq->tbName.type == TSDB_TABLE_NAME_T && pInfo->writeTbs && taosHashGetSize(pInfo->writeTbs) > 0) {
|
||||
req->singleType = AUTH_TYPE_WRITE;
|
||||
CTG_ERR_RET(ctgChkSetTbAuthRes(pCtg, req, res));
|
||||
if (pRes->pass || res->metaNotExists) {
|
||||
if (pRes->pass[AUTH_RES_BASIC] || res->metaNotExists) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
if (pInfo->writeDbs && taosHashGet(pInfo->writeDbs, dbFName, strlen(dbFName))) {
|
||||
pRes->pass = true;
|
||||
if (pInfo->writeDbs && taosHashGet(pInfo->writeDbs, dbFName, strlen(dbFName) + 1)) {
|
||||
pRes->pass[AUTH_RES_BASIC] = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case AUTH_TYPE_READ_OR_WRITE: {
|
||||
if ((pInfo->readDbs && taosHashGet(pInfo->readDbs, dbFName, strlen(dbFName))) ||
|
||||
(pInfo->writeDbs && taosHashGet(pInfo->writeDbs, dbFName, strlen(dbFName))) ||
|
||||
(pInfo->useDbs && taosHashGet(pInfo->useDbs, dbFName, strlen(dbFName)))) {
|
||||
pRes->pass = true;
|
||||
if ((pInfo->readDbs && taosHashGet(pInfo->readDbs, dbFName, strlen(dbFName) + 1)) ||
|
||||
(pInfo->writeDbs && taosHashGet(pInfo->writeDbs, dbFName, strlen(dbFName) + 1)) ||
|
||||
(pInfo->useDbs && taosHashGet(pInfo->useDbs, dbFName, strlen(dbFName) + 1))) {
|
||||
pRes->pass[AUTH_RES_BASIC] = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1672,6 +1827,78 @@ int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgChkSetViewAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
||||
int32_t code = 0;
|
||||
SUserAuthInfo* pReq = req->pRawReq;
|
||||
SUserAuthRes* pRes = res->pRawRes;
|
||||
SGetUserAuthRsp* pInfo = &req->authInfo;
|
||||
|
||||
pRes->pass[AUTH_RES_VIEW] = false;
|
||||
pRes->pCond[AUTH_RES_VIEW] = NULL;
|
||||
|
||||
if (!pInfo->enable) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (pInfo->superAuth) {
|
||||
pRes->pass[AUTH_RES_VIEW] = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (pReq->tbName.type != TSDB_TABLE_NAME_T) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
char viewFName[TSDB_VIEW_FNAME_LEN];
|
||||
if (IS_SYS_DBNAME(req->pRawReq->tbName.dbname)) {
|
||||
snprintf(viewFName, sizeof(viewFName), "%s.%s", req->pRawReq->tbName.dbname, req->pRawReq->tbName.tname);
|
||||
} else {
|
||||
tNameExtractFullName(&req->pRawReq->tbName, viewFName);
|
||||
}
|
||||
int32_t len = strlen(viewFName) + 1;
|
||||
|
||||
switch (pReq->type) {
|
||||
case AUTH_TYPE_READ: {
|
||||
char *value = taosHashGet(pInfo->readViews, viewFName, len);
|
||||
if (NULL != value) {
|
||||
pRes->pass[AUTH_RES_VIEW] = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AUTH_TYPE_WRITE: {
|
||||
char *value = taosHashGet(pInfo->writeViews, viewFName, len);
|
||||
if (NULL != value) {
|
||||
pRes->pass[AUTH_RES_VIEW] = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AUTH_TYPE_ALTER: {
|
||||
char *value = taosHashGet(pInfo->alterViews, viewFName, len);
|
||||
if (NULL != value) {
|
||||
pRes->pass[AUTH_RES_VIEW] = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
|
||||
#ifdef TD_ENTERPRISE
|
||||
CTG_ERR_RET(ctgChkSetViewAuthRes(pCtg, req, res));
|
||||
if (req->pRawReq->isView) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
CTG_RET(ctgChkSetBasicAuthRes(pCtg, req, res));
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int32_t ctgCloneMetaDataArray(SArray* pSrc, __array_item_dup_fn_t copyFunc, SArray** pDst) {
|
||||
if (NULL == pSrc) {
|
||||
|
@ -1743,8 +1970,9 @@ SMetaData* catalogCloneMetaData(SMetaData* pData) {
|
|||
|
||||
return pRes;
|
||||
}
|
||||
#endif
|
||||
|
||||
void catalogFreeMetaData(SMetaData* pData) {
|
||||
void ctgDestroySMetaData(SMetaData* pData) {
|
||||
if (NULL == pData) {
|
||||
return;
|
||||
}
|
||||
|
@ -1754,17 +1982,16 @@ void catalogFreeMetaData(SMetaData* pData) {
|
|||
taosArrayDestroyEx(pData->pDbInfo, ctgFreeDbInfo);
|
||||
taosArrayDestroyEx(pData->pTableMeta, ctgFreeTableMeta);
|
||||
taosArrayDestroyEx(pData->pTableHash, ctgFreeVgroupInfo);
|
||||
taosArrayDestroyEx(pData->pTableIndex, ctgFreeTableIndices);
|
||||
taosArrayDestroyEx(pData->pTableIndex, ctgFreeTableIndexs);
|
||||
taosArrayDestroyEx(pData->pUdfList, ctgFreeFuncInfo);
|
||||
taosArrayDestroyEx(pData->pIndex, ctgFreeIndexInfo);
|
||||
taosArrayDestroyEx(pData->pUser, ctgFreeUserAuth);
|
||||
taosArrayDestroyEx(pData->pQnodeList, ctgFreeQnodeList);
|
||||
taosArrayDestroyEx(pData->pTableCfg, ctgFreeTableCfg);
|
||||
taosArrayDestroyEx(pData->pDnodeList, ctgFreeDnodeList);
|
||||
taosArrayDestroyEx(pData->pView, ctgFreeViewMeta);
|
||||
taosMemoryFreeClear(pData->pSvrVer);
|
||||
taosMemoryFree(pData);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint64_t ctgGetTbIndexCacheSize(STableIndex *pIndex) {
|
||||
if (NULL == pIndex) {
|
||||
|
@ -1774,6 +2001,15 @@ uint64_t ctgGetTbIndexCacheSize(STableIndex *pIndex) {
|
|||
return sizeof(*pIndex) + pIndex->indexSize;
|
||||
}
|
||||
|
||||
uint64_t ctgGetViewMetaCacheSize(SViewMeta *pMeta) {
|
||||
if (NULL == pMeta) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sizeof(*pMeta) + strlen(pMeta->querySql) + 1 + strlen(pMeta->user) + 1 + pMeta->numOfCols * sizeof(SSchema);
|
||||
}
|
||||
|
||||
|
||||
FORCE_INLINE uint64_t ctgGetTbMetaCacheSize(STableMeta *pMeta) {
|
||||
if (NULL == pMeta) {
|
||||
return 0;
|
||||
|
@ -1810,7 +2046,7 @@ uint64_t ctgGetUserCacheSize(SGetUserAuthRsp *pAuth) {
|
|||
while (p != NULL) {
|
||||
size_t len = 0;
|
||||
void* key = taosHashGetKey(p, &len);
|
||||
cacheSize += len + strlen(p);
|
||||
cacheSize += len + strlen(p) + 1;
|
||||
|
||||
p = taosHashIterate(pAuth->createdDbs, p);
|
||||
}
|
||||
|
@ -1819,7 +2055,7 @@ uint64_t ctgGetUserCacheSize(SGetUserAuthRsp *pAuth) {
|
|||
while (p != NULL) {
|
||||
size_t len = 0;
|
||||
void* key = taosHashGetKey(p, &len);
|
||||
cacheSize += len + strlen(p);
|
||||
cacheSize += len + strlen(p) + 1;
|
||||
|
||||
p = taosHashIterate(pAuth->readDbs, p);
|
||||
}
|
||||
|
@ -1828,7 +2064,7 @@ uint64_t ctgGetUserCacheSize(SGetUserAuthRsp *pAuth) {
|
|||
while (p != NULL) {
|
||||
size_t len = 0;
|
||||
void* key = taosHashGetKey(p, &len);
|
||||
cacheSize += len + strlen(p);
|
||||
cacheSize += len + strlen(p) + 1;
|
||||
|
||||
p = taosHashIterate(pAuth->writeDbs, p);
|
||||
}
|
||||
|
@ -1837,7 +2073,7 @@ uint64_t ctgGetUserCacheSize(SGetUserAuthRsp *pAuth) {
|
|||
while (p != NULL) {
|
||||
size_t len = 0;
|
||||
void* key = taosHashGetKey(p, &len);
|
||||
cacheSize += len + strlen(p);
|
||||
cacheSize += len + strlen(p) + 1;
|
||||
|
||||
p = taosHashIterate(pAuth->readTbs, p);
|
||||
}
|
||||
|
@ -1846,11 +2082,47 @@ uint64_t ctgGetUserCacheSize(SGetUserAuthRsp *pAuth) {
|
|||
while (p != NULL) {
|
||||
size_t len = 0;
|
||||
void* key = taosHashGetKey(p, &len);
|
||||
cacheSize += len + strlen(p);
|
||||
cacheSize += len + strlen(p) + 1;
|
||||
|
||||
p = taosHashIterate(pAuth->writeTbs, p);
|
||||
}
|
||||
|
||||
p = taosHashIterate(pAuth->alterTbs, NULL);
|
||||
while (p != NULL) {
|
||||
size_t len = 0;
|
||||
void* key = taosHashGetKey(p, &len);
|
||||
cacheSize += len + strlen(p) + 1;
|
||||
|
||||
p = taosHashIterate(pAuth->alterTbs, p);
|
||||
}
|
||||
|
||||
p = taosHashIterate(pAuth->readViews, NULL);
|
||||
while (p != NULL) {
|
||||
size_t len = 0;
|
||||
void* key = taosHashGetKey(p, &len);
|
||||
cacheSize += len + strlen(p) + 1;
|
||||
|
||||
p = taosHashIterate(pAuth->readViews, p);
|
||||
}
|
||||
|
||||
p = taosHashIterate(pAuth->writeViews, NULL);
|
||||
while (p != NULL) {
|
||||
size_t len = 0;
|
||||
void* key = taosHashGetKey(p, &len);
|
||||
cacheSize += len + strlen(p) + 1;
|
||||
|
||||
p = taosHashIterate(pAuth->writeViews, p);
|
||||
}
|
||||
|
||||
p = taosHashIterate(pAuth->alterViews, NULL);
|
||||
while (p != NULL) {
|
||||
size_t len = 0;
|
||||
void* key = taosHashGetKey(p, &len);
|
||||
cacheSize += len + strlen(p) + 1;
|
||||
|
||||
p = taosHashIterate(pAuth->alterViews, p);
|
||||
}
|
||||
|
||||
int32_t *ref = taosHashIterate(pAuth->useDbs, NULL);
|
||||
while (ref != NULL) {
|
||||
size_t len = 0;
|
||||
|
@ -1886,6 +2158,7 @@ uint64_t ctgGetClusterCacheSize(SCatalog *pCtg) {
|
|||
|
||||
cacheSize += pCtg->dbRent.rentCacheSize;
|
||||
cacheSize += pCtg->stbRent.rentCacheSize;
|
||||
cacheSize += pCtg->viewRent.rentCacheSize;
|
||||
|
||||
return cacheSize;
|
||||
}
|
||||
|
@ -1974,3 +2247,45 @@ void ctgGetGlobalCacheSize(uint64_t *pSize) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t ctgBuildViewNullRes(SCtgTask* pTask, SCtgViewsCtx* pCtx) {
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
int32_t dbNum = taosArrayGetSize(pCtx->pNames);
|
||||
for (int32_t i = 0; i < dbNum; ++i) {
|
||||
STablesReq* pReq = taosArrayGet(pCtx->pNames, i);
|
||||
int32_t viewNum = taosArrayGetSize(pReq->pTables);
|
||||
|
||||
ctgDebug("start to check views in db %s, viewNum %d", pReq->dbFName, viewNum);
|
||||
|
||||
for (int32_t m = 0; m < viewNum; ++m) {
|
||||
taosArrayPush(pCtx->pResList, &(SMetaData){0});
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t dupViewMetaFromRsp(SViewMetaRsp* pRsp, SViewMeta* pViewMeta) {
|
||||
pViewMeta->querySql = tstrdup(pRsp->querySql);
|
||||
if (NULL == pViewMeta->querySql) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
pViewMeta->user = tstrdup(pRsp->user);
|
||||
if (NULL == pViewMeta->user) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
pViewMeta->version = pRsp->version;
|
||||
pViewMeta->viewId = pRsp->viewId;
|
||||
pViewMeta->precision = pRsp->precision;
|
||||
pViewMeta->type = pRsp->type;
|
||||
pViewMeta->numOfCols = pRsp->numOfCols;
|
||||
pViewMeta->pSchema = taosMemoryMalloc(pViewMeta->numOfCols * sizeof(SSchema));
|
||||
if (pViewMeta->pSchema == NULL) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
memcpy(pViewMeta->pSchema, pRsp->pSchema, pViewMeta->numOfCols * sizeof(SSchema));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -2814,7 +2814,7 @@ TEST(apiTest, catalogChkAuth_test) {
|
|||
|
||||
code = catalogChkAuth(pCtg, mockPointer, &authInfo, &authRes);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(authRes.pass, true);
|
||||
ASSERT_EQ(authRes.pass[AUTH_RES_BASIC], true);
|
||||
|
||||
while (true) {
|
||||
uint64_t n = 0;
|
||||
|
@ -2828,7 +2828,7 @@ TEST(apiTest, catalogChkAuth_test) {
|
|||
|
||||
code = catalogChkAuthFromCache(pCtg, &authInfo, &authRes, &exists);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(authRes.pass, true);
|
||||
ASSERT_EQ(authRes.pass[AUTH_RES_BASIC], true);
|
||||
ASSERT_EQ(exists, true);
|
||||
|
||||
catalogDestroy();
|
||||
|
|
|
@ -112,7 +112,11 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock,
|
|||
colDataSetVal(pCol2, pBlock->info.rows, buf, false);
|
||||
int32_t bytes = getSchemaBytes(pMeta->schema + i);
|
||||
colDataSetVal(pCol3, pBlock->info.rows, (const char*)&bytes, false);
|
||||
STR_TO_VARSTR(buf, i >= pMeta->tableInfo.numOfColumns ? "TAG" : "");
|
||||
if (TSDB_VIEW_TABLE != pMeta->tableType) {
|
||||
STR_TO_VARSTR(buf, i >= pMeta->tableInfo.numOfColumns ? "TAG" : "");
|
||||
} else {
|
||||
STR_TO_VARSTR(buf, "VIEW COL");
|
||||
}
|
||||
colDataSetVal(pCol4, pBlock->info.rows, buf, false);
|
||||
++(pBlock->info.rows);
|
||||
}
|
||||
|
@ -458,6 +462,29 @@ static int32_t buildCreateTbResultDataBlock(SSDataBlock** pOutput) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) {
|
||||
SSDataBlock* pBlock = createDataBlock();
|
||||
if (NULL == pBlock) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_VIEW_RESULT_FIELD1_LEN, 1);
|
||||
int32_t code = blockDataAppendColInfo(pBlock, &infoData);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_VIEW_RESULT_FIELD2_LEN, 2);
|
||||
code = blockDataAppendColInfo(pBlock, &infoData);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOutput = pBlock;
|
||||
} else {
|
||||
blockDataDestroy(pBlock);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
||||
for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
|
||||
SSchema* pSchema = pCfg->pSchemas + i;
|
||||
|
@ -701,6 +728,36 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreateViewStmt* pStmt) {
|
||||
int32_t code = 0;
|
||||
blockDataEnsureCapacity(pBlock, 1);
|
||||
pBlock->info.rows = 1;
|
||||
|
||||
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
char buf1[SHOW_CREATE_VIEW_RESULT_FIELD1_LEN + 1] = {0};
|
||||
snprintf(varDataVal(buf1), TSDB_VIEW_FNAME_LEN + 4, "`%s`.`%s`", pStmt->dbName, pStmt->viewName);
|
||||
varDataSetLen(buf1, strlen(varDataVal(buf1)));
|
||||
colDataSetVal(pCol1, 0, buf1, false);
|
||||
|
||||
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
|
||||
char* buf2 = taosMemoryMalloc(SHOW_CREATE_VIEW_RESULT_FIELD2_LEN);
|
||||
if (NULL == buf2) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
SViewMeta* pMeta = pStmt->pViewMeta;
|
||||
snprintf(varDataVal(buf2), SHOW_CREATE_VIEW_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE, "CREATE VIEW `%s`.`%s` AS %s", pStmt->dbName, pStmt->viewName, pMeta->querySql);
|
||||
int32_t len = strlen(varDataVal(buf2));
|
||||
varDataLen(buf2) = (len > 65535) ? 65535 : len;
|
||||
colDataSetVal(pCol2, 0, buf2, false);
|
||||
|
||||
taosMemoryFree(buf2);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
SSDataBlock* pBlock = NULL;
|
||||
int32_t code = buildCreateTbResultDataBlock(&pBlock);
|
||||
|
@ -940,6 +997,19 @@ static int32_t execSelectWithoutFrom(SSelectStmt* pSelect, SRetrieveTableRsp** p
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t execShowCreateView(SShowCreateViewStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
SSDataBlock* pBlock = NULL;
|
||||
int32_t code = buildCreateViewResultDataBlock(&pBlock);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setCreateViewResultIntoDataBlock(pBlock, pStmt);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_VIEW_RESULT_COLS, pRsp);
|
||||
}
|
||||
blockDataDestroy(pBlock);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp, int8_t biMode) {
|
||||
switch (nodeType(pStmt)) {
|
||||
case QUERY_NODE_DESCRIBE_STMT:
|
||||
|
@ -952,6 +1022,8 @@ int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieve
|
|||
return execShowCreateTable((SShowCreateTableStmt*)pStmt, pRsp);
|
||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||
return execShowCreateSTable((SShowCreateTableStmt*)pStmt, pRsp);
|
||||
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||
return execShowCreateView((SShowCreateViewStmt*)pStmt, pRsp);
|
||||
case QUERY_NODE_ALTER_LOCAL_STMT:
|
||||
return execAlterLocal((SAlterLocalStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||
|
|
|
@ -152,9 +152,11 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhys
|
|||
optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
|
||||
setOperatorStreamStateFn(pOperator, streamOperatorReleaseState, streamOperatorReloadState);
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
if (NULL != downstream) {
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
}
|
||||
|
||||
return pOperator;
|
||||
|
@ -263,7 +265,7 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
|||
st = taosGetTimestampUs();
|
||||
}
|
||||
|
||||
SOperatorInfo* downstream = pOperator->pDownstream[0];
|
||||
SOperatorInfo* downstream = pOperator->numOfDownstream > 0 ? pOperator->pDownstream[0] : NULL;
|
||||
SLimitInfo* pLimitInfo = &pProjectInfo->limitInfo;
|
||||
|
||||
if (downstream == NULL) {
|
||||
|
|
|
@ -741,6 +741,19 @@ static int32_t selectStmtCopy(const SSelectStmt* pSrc, SSelectStmt* pDst) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setOperatorCopy(const SSetOperator* pSrc, SSetOperator* pDst) {
|
||||
COPY_SCALAR_FIELD(opType);
|
||||
CLONE_NODE_LIST_FIELD(pProjectionList);
|
||||
CLONE_NODE_FIELD(pLeft);
|
||||
CLONE_NODE_FIELD(pRight);
|
||||
CLONE_NODE_LIST_FIELD(pOrderByList);
|
||||
CLONE_NODE_FIELD(pLimit);
|
||||
COPY_CHAR_ARRAY_FIELD(stmtName);
|
||||
COPY_SCALAR_FIELD(precision);
|
||||
COPY_SCALAR_FIELD(timeLineResMode);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SNode* nodesCloneNode(const SNode* pNode) {
|
||||
if (NULL == pNode) {
|
||||
return NULL;
|
||||
|
@ -829,6 +842,9 @@ SNode* nodesCloneNode(const SNode* pNode) {
|
|||
case QUERY_NODE_HINT:
|
||||
code = hintNodeCopy((const SHintNode*)pNode, (SHintNode*)pDst);
|
||||
break;
|
||||
case QUERY_NODE_SET_OPERATOR:
|
||||
code = setOperatorCopy((const SSetOperator*)pNode, (SSetOperator*)pDst);
|
||||
break;
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
code = selectStmtCopy((const SSelectStmt*)pNode, (SSelectStmt*)pDst);
|
||||
break;
|
||||
|
|
|
@ -251,6 +251,8 @@ const char* nodesNodeName(ENodeType type) {
|
|||
return "ShowCreateTablesStmt";
|
||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||
return "ShowCreateStablesStmt";
|
||||
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||
return "ShowCreateViewStmt";
|
||||
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
||||
return "ShowTableDistributedStmt";
|
||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||
|
@ -269,6 +271,10 @@ const char* nodesNodeName(ENodeType type) {
|
|||
return "RestoreMnodeStmt";
|
||||
case QUERY_NODE_RESTORE_VNODE_STMT:
|
||||
return "RestoreVnodeStmt";
|
||||
case QUERY_NODE_CREATE_VIEW_STMT:
|
||||
return "CreateViewStmt";
|
||||
case QUERY_NODE_DROP_VIEW_STMT:
|
||||
return "DropViewStmt";
|
||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
return "LogicScan";
|
||||
case QUERY_NODE_LOGIC_PLAN_JOIN:
|
||||
|
@ -6589,6 +6595,33 @@ static int32_t jsonToShowCreateStableStmt(const SJson* pJson, void* pObj) {
|
|||
return jsonToShowCreateTableStmt(pJson, pObj);
|
||||
}
|
||||
|
||||
static const char* jkShowCreateViewStmtDbName = "DbName";
|
||||
static const char* jkShowCreateViewStmtViewName = "ViewName";
|
||||
|
||||
static int32_t showCreateViewStmtToJson(const void* pObj, SJson* pJson) {
|
||||
const SShowCreateViewStmt* pNode = (const SShowCreateViewStmt*)pObj;
|
||||
|
||||
int32_t code = tjsonAddStringToObject(pJson, jkShowCreateViewStmtDbName, pNode->dbName);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddStringToObject(pJson, jkShowCreateViewStmtViewName, pNode->viewName);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t jsonToShowCreateViewStmt(const SJson* pJson, void* pObj) {
|
||||
SShowCreateViewStmt* pNode = (SShowCreateViewStmt*)pObj;
|
||||
|
||||
int32_t code = tjsonGetStringValue(pJson, jkShowCreateViewStmtDbName, pNode->dbName);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetStringValue(pJson, jkShowCreateViewStmtViewName, pNode->viewName);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
static const char* jkShowTableDistributedStmtDbName = "DbName";
|
||||
static const char* jkShowTableDistributedStmtTableName = "TableName";
|
||||
|
||||
|
@ -6956,6 +6989,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
return showCreateTableStmtToJson(pObj, pJson);
|
||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||
return showCreateStableStmtToJson(pObj, pJson);
|
||||
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||
return showCreateViewStmtToJson(pObj, pJson);
|
||||
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
||||
return showTableDistributedStmtToJson(pObj, pJson);
|
||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||
|
@ -7277,6 +7312,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
return jsonToShowCreateTableStmt(pJson, pObj);
|
||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||
return jsonToShowCreateStableStmt(pJson, pObj);
|
||||
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||
return jsonToShowCreateViewStmt(pJson, pObj);
|
||||
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
||||
return jsonToShowTableDistributedStmt(pJson, pObj);
|
||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||
|
|
|
@ -304,6 +304,8 @@ SNode* nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SEventWindowNode));
|
||||
case QUERY_NODE_HINT:
|
||||
return makeNode(type, sizeof(SHintNode));
|
||||
case QUERY_NODE_VIEW:
|
||||
return makeNode(type, sizeof(SViewNode));
|
||||
case QUERY_NODE_SET_OPERATOR:
|
||||
return makeNode(type, sizeof(SSetOperator));
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
|
@ -436,6 +438,7 @@ SNode* nodesMakeNode(ENodeType type) {
|
|||
case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
|
||||
case QUERY_NODE_SHOW_TAGS_STMT:
|
||||
case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
|
||||
case QUERY_NODE_SHOW_VIEWS_STMT:
|
||||
return makeNode(type, sizeof(SShowStmt));
|
||||
case QUERY_NODE_SHOW_TABLE_TAGS_STMT:
|
||||
return makeNode(type, sizeof(SShowTableTagsStmt));
|
||||
|
@ -449,6 +452,8 @@ SNode* nodesMakeNode(ENodeType type) {
|
|||
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||
return makeNode(type, sizeof(SShowCreateTableStmt));
|
||||
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||
return makeNode(type, sizeof(SShowCreateViewStmt));
|
||||
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT:
|
||||
return makeNode(type, sizeof(SShowTableDistributedStmt));
|
||||
case QUERY_NODE_KILL_QUERY_STMT:
|
||||
|
@ -467,6 +472,10 @@ SNode* nodesMakeNode(ENodeType type) {
|
|||
case QUERY_NODE_RESTORE_MNODE_STMT:
|
||||
case QUERY_NODE_RESTORE_VNODE_STMT:
|
||||
return makeNode(type, sizeof(SRestoreComponentNodeStmt));
|
||||
case QUERY_NODE_CREATE_VIEW_STMT:
|
||||
return makeNode(type, sizeof(SCreateViewStmt));
|
||||
case QUERY_NODE_DROP_VIEW_STMT:
|
||||
return makeNode(type, sizeof(SDropViewStmt));
|
||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
return makeNode(type, sizeof(SScanLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_JOIN:
|
||||
|
@ -832,6 +841,13 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
destroyHintValue(pHint->option, pHint->value);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_VIEW: {
|
||||
SViewNode* pView = (SViewNode*)pNode;
|
||||
taosMemoryFreeClear(pView->pMeta);
|
||||
taosMemoryFreeClear(pView->pVgroupList);
|
||||
taosArrayDestroyEx(pView->pSmaIndexes, destroySmaIndex);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_SET_OPERATOR: {
|
||||
SSetOperator* pStmt = (SSetOperator*)pNode;
|
||||
nodesDestroyList(pStmt->pProjectionList);
|
||||
|
@ -1046,7 +1062,8 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
|
||||
case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
|
||||
case QUERY_NODE_SHOW_TAGS_STMT:
|
||||
case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT: {
|
||||
case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
|
||||
case QUERY_NODE_SHOW_VIEWS_STMT: {
|
||||
SShowStmt* pStmt = (SShowStmt*)pNode;
|
||||
nodesDestroyNode(pStmt->pDbName);
|
||||
nodesDestroyNode(pStmt->pTbName);
|
||||
|
@ -1071,6 +1088,7 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
taosMemoryFreeClear(((SShowCreateTableStmt*)pNode)->pDbCfg);
|
||||
destroyTableCfg((STableCfg*)(((SShowCreateTableStmt*)pNode)->pTableCfg));
|
||||
break;
|
||||
case QUERY_NODE_SHOW_CREATE_VIEW_STMT: // no pointer field
|
||||
case QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT: // no pointer field
|
||||
case QUERY_NODE_KILL_CONNECTION_STMT: // no pointer field
|
||||
case QUERY_NODE_KILL_QUERY_STMT: // no pointer field
|
||||
|
@ -1115,6 +1133,15 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
case QUERY_NODE_RESTORE_MNODE_STMT: // no pointer field
|
||||
case QUERY_NODE_RESTORE_VNODE_STMT: // no pointer field
|
||||
break;
|
||||
case QUERY_NODE_CREATE_VIEW_STMT: {
|
||||
SCreateViewStmt* pStmt = (SCreateViewStmt*)pNode;
|
||||
taosMemoryFree(pStmt->pQuerySql);
|
||||
tFreeSCMCreateViewReq(&pStmt->createReq);
|
||||
nodesDestroyNode(pStmt->pQuery);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_DROP_VIEW_STMT:
|
||||
break;
|
||||
case QUERY_NODE_LOGIC_PLAN_SCAN: {
|
||||
SScanLogicNode* pLogicNode = (SScanLogicNode*)pNode;
|
||||
destroyLogicNode((SLogicNode*)pLogicNode);
|
||||
|
@ -2349,4 +2376,4 @@ bool nodesIsStar(SNode* pNode) {
|
|||
bool nodesIsTableStar(SNode* pNode) {
|
||||
return (QUERY_NODE_COLUMN == nodeType(pNode)) && ('\0' != ((SColumnNode*)pNode)->tableAlias[0]) &&
|
||||
(0 == strcmp(((SColumnNode*)pNode)->colName, "*"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
aux_source_directory(src PARSER_SRC)
|
||||
|
||||
IF (TD_ENTERPRISE)
|
||||
LIST(APPEND PARSER_SRC ${TD_ENTERPRISE_DIR}/src/plugins/view/src/parserView.c)
|
||||
ENDIF ()
|
||||
|
||||
IF (TD_BI_SUPPORT)
|
||||
LIST(APPEND PARSER_SRC ${TD_ENTERPRISE_DIR}/src/plugins/bi/src/biRewriteQuery.c)
|
||||
ENDIF ()
|
||||
|
|
|
@ -125,6 +125,7 @@ SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2);
|
|||
SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTableName, SToken* pTableAlias);
|
||||
SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, const SToken* pTableAlias);
|
||||
SNode* createJoinTableNode(SAstCreateContext* pCxt, EJoinType type, SNode* pLeft, SNode* pRight, SNode* pJoinCond);
|
||||
SNode* createViewNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pViewName);
|
||||
SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const SToken* pOffset);
|
||||
SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder);
|
||||
SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap);
|
||||
|
@ -196,6 +197,7 @@ SNode* createShowTablesStmt(SAstCreateContext* pCxt, SShowTablesOption option, S
|
|||
SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
|
||||
SNode* createShowAliveStmt(SAstCreateContext* pCxt, SNode* pDbName, ENodeType type);
|
||||
SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable);
|
||||
SNode* createShowCreateViewStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable);
|
||||
SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable);
|
||||
SNode* createShowDnodeVariablesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pLikePattern);
|
||||
SNode* createShowVnodesStmt(SAstCreateContext* pCxt, SNode* pDnodeId, SNode* pDnodeEndpoint);
|
||||
|
@ -256,6 +258,8 @@ SNode* createRevokeStmt(SAstCreateContext* pCxt, int64_t privileges, STokenPair*
|
|||
SNode* pTagCond);
|
||||
SNode* createDeleteStmt(SAstCreateContext* pCxt, SNode* pTable, SNode* pWhere);
|
||||
SNode* createInsertStmt(SAstCreateContext* pCxt, SNode* pTable, SNodeList* pCols, SNode* pQuery);
|
||||
SNode* createCreateViewStmt(SAstCreateContext* pCxt, bool orReplace, SNode* pView, const SToken* pAs, SNode* pQuery);
|
||||
SNode* createDropViewStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pView);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ extern "C" {
|
|||
|
||||
#include "parToken.h"
|
||||
#include "parUtil.h"
|
||||
#include "parTranslater.h"
|
||||
#include "parser.h"
|
||||
|
||||
#define QUERY_SMA_OPTIMIZE_DISABLE 0
|
||||
|
@ -36,6 +37,15 @@ int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pS
|
|||
int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery);
|
||||
int32_t translatePostCreateStream(SParseContext* pParseCxt, SQuery* pQuery, void** pResRow);
|
||||
int32_t translatePostCreateSmaIndex(SParseContext* pParseCxt, SQuery* pQuery, void** pResRow);
|
||||
int32_t buildQueryAfterParse(SQuery** pQuery, SNode* pRootNode, int16_t placeholderNo, SArray** pPlaceholderValues);
|
||||
int32_t translateTable(STranslateContext* pCxt, SNode** pTable);
|
||||
int32_t getMetaDataFromHash(const char* pKey, int32_t len, SHashObj* pHash, void** pOutput);
|
||||
void tfreeSParseQueryRes(void* p);
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
int32_t translateView(STranslateContext* pCxt, SNode** pTable, SName* pName);
|
||||
int32_t getViewMetaFromMetaCache(STranslateContext* pCxt, SName* pName, SViewMeta** ppViewMeta);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -48,6 +48,8 @@ typedef struct STranslateContext {
|
|||
|
||||
int32_t biRewriteSelectStar(STranslateContext* pCxt, SSelectStmt* pSelect);
|
||||
int32_t findTable(STranslateContext* pCxt, const char* pTableAlias, STableNode** pOutput);
|
||||
int32_t getTargetMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta, bool couldBeView);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -69,6 +69,7 @@ typedef struct SParseMetaCache {
|
|||
SHashObj* pUdf; // key is funcName, element is SFuncInfo*
|
||||
SHashObj* pTableIndex; // key is tbFName, element is SArray<STableIndexInfo>*
|
||||
SHashObj* pTableCfg; // key is tbFName, element is STableCfg*
|
||||
SHashObj* pViews; // key is viewFName, element is SViewMeta*
|
||||
SArray* pDnodes; // element is SEpSet
|
||||
bool dnodeRequired;
|
||||
} SParseMetaCache;
|
||||
|
@ -93,6 +94,8 @@ int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalog
|
|||
int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveTableMetaInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveTableMetaInCacheExt(const SName* pName, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveViewMetaInCache(int32_t acctId, const char* pDb, const char* pView, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveViewMetaInCacheExt(const SName* pName, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveDbVgInfoInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveTableVgroupInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveTableVgroupInCacheExt(const SName* pName, SParseMetaCache* pMetaCache);
|
||||
|
@ -100,11 +103,15 @@ int32_t reserveDbVgVersionInCache(int32_t acctId, const char* pDb, SParseMetaCac
|
|||
int32_t reserveDbCfgInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
|
||||
SParseMetaCache* pMetaCache);
|
||||
int32_t reserveViewUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
|
||||
SParseMetaCache* pMetaCache);
|
||||
int32_t reserveUdfInCache(const char* pFunc, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveTableIndexInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveTableCfgInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveDnodeRequiredInCache(SParseMetaCache* pMetaCache);
|
||||
int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta);
|
||||
int32_t getViewMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta);
|
||||
int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta);
|
||||
int32_t getDbVgInfoFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SArray** pVgInfo);
|
||||
int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup);
|
||||
int32_t getDbVgVersionFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, int32_t* pVersion, int64_t* pDbId,
|
||||
|
|
|
@ -132,6 +132,7 @@ priv_type_list(A) ::= priv_type_list(B) NK_COMMA priv_type(C).
|
|||
%destructor priv_type { }
|
||||
priv_type(A) ::= READ. { A = PRIVILEGE_TYPE_READ; }
|
||||
priv_type(A) ::= WRITE. { A = PRIVILEGE_TYPE_WRITE; }
|
||||
priv_type(A) ::= ALTER. { A = PRIVILEGE_TYPE_ALTER; }
|
||||
|
||||
%type priv_level { STokenPair }
|
||||
%destructor priv_level { }
|
||||
|
@ -508,6 +509,8 @@ cmd ::= SHOW VNODES.
|
|||
// show alive
|
||||
cmd ::= SHOW db_name_cond_opt(A) ALIVE. { pCxt->pRootNode = createShowAliveStmt(pCxt, A, QUERY_NODE_SHOW_DB_ALIVE_STMT); }
|
||||
cmd ::= SHOW CLUSTER ALIVE. { pCxt->pRootNode = createShowAliveStmt(pCxt, NULL, QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT); }
|
||||
cmd ::= SHOW db_name_cond_opt(A) VIEWS. { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VIEWS_STMT, A, NULL, OP_TYPE_LIKE); }
|
||||
cmd ::= SHOW CREATE VIEW full_table_name(A). { pCxt->pRootNode = createShowCreateViewStmt(pCxt, QUERY_NODE_SHOW_CREATE_VIEW_STMT, A); }
|
||||
|
||||
%type table_kind_db_name_cond_opt { SShowTablesOption }
|
||||
%destructor table_kind_db_name_cond_opt { }
|
||||
|
@ -648,6 +651,14 @@ language_opt(A) ::= LANGUAGE NK_STRING(B).
|
|||
or_replace_opt(A) ::= . { A = false; }
|
||||
or_replace_opt(A) ::= OR REPLACE. { A = true; }
|
||||
|
||||
/************************************************ create/drop view **************************************************/
|
||||
cmd ::= CREATE or_replace_opt(A) VIEW full_view_name(B) AS(C) query_or_subquery(D).
|
||||
{ pCxt->pRootNode = createCreateViewStmt(pCxt, A, B, &C, D); }
|
||||
cmd ::= DROP VIEW exists_opt(A) full_view_name(B). { pCxt->pRootNode = createDropViewStmt(pCxt, A, B); }
|
||||
|
||||
full_view_name(A) ::= view_name(B). { A = createViewNode(pCxt, NULL, &B); }
|
||||
full_view_name(A) ::= db_name(B) NK_DOT view_name(C). { A = createViewNode(pCxt, &B, &C); }
|
||||
|
||||
/************************************************ create/drop stream **************************************************/
|
||||
cmd ::= CREATE STREAM not_exists_opt(E) stream_name(A) stream_options(B) INTO
|
||||
full_table_name(C) col_list_opt(H) tag_def_or_ref_opt(F) subtable_opt(G)
|
||||
|
@ -781,6 +792,10 @@ column_name(A) ::= NK_ID(B).
|
|||
%destructor function_name { }
|
||||
function_name(A) ::= NK_ID(B). { A = B; }
|
||||
|
||||
%type view_name { SToken }
|
||||
%destructor view_name { }
|
||||
view_name(A) ::= NK_ID(B). { A = B; }
|
||||
|
||||
%type table_alias { SToken }
|
||||
%destructor table_alias { }
|
||||
table_alias(A) ::= NK_ID(B). { A = B; }
|
||||
|
|
|
@ -219,6 +219,16 @@ static bool checkCGroupName(SAstCreateContext* pCxt, SToken* pCGroup) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool checkViewName(SAstCreateContext* pCxt, SToken* pViewName) {
|
||||
trimEscape(pViewName);
|
||||
if (pViewName->n >= TSDB_VIEW_NAME_LEN) {
|
||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pViewName->z);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool checkStreamName(SAstCreateContext* pCxt, SToken* pStreamName) {
|
||||
trimEscape(pStreamName);
|
||||
if (pStreamName->n >= TSDB_STREAM_NAME_LEN) {
|
||||
|
@ -772,6 +782,23 @@ SNode* createJoinTableNode(SAstCreateContext* pCxt, EJoinType type, SNode* pLeft
|
|||
return (SNode*)joinTable;
|
||||
}
|
||||
|
||||
SNode* createViewNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pViewName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkDbName(pCxt, pDbName, true) || !checkViewName(pCxt, pViewName)) {
|
||||
return NULL;
|
||||
}
|
||||
SViewNode* pView = (SViewNode*)nodesMakeNode(QUERY_NODE_VIEW);
|
||||
CHECK_OUT_OF_MEM(pView);
|
||||
if (NULL != pDbName) {
|
||||
COPY_STRING_FORM_ID_TOKEN(pView->table.dbName, pDbName);
|
||||
} else {
|
||||
snprintf(pView->table.dbName, sizeof(pView->table.dbName), "%s", pCxt->pQueryCxt->db);
|
||||
}
|
||||
COPY_STRING_FORM_ID_TOKEN(pView->table.tableName, pViewName);
|
||||
return (SNode*)pView;
|
||||
}
|
||||
|
||||
|
||||
SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const SToken* pOffset) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SLimitNode* limitNode = (SLimitNode*)nodesMakeNode(QUERY_NODE_LIMIT);
|
||||
|
@ -1600,7 +1627,8 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
|
|||
static bool needDbShowStmt(ENodeType type) {
|
||||
return QUERY_NODE_SHOW_TABLES_STMT == type || QUERY_NODE_SHOW_STABLES_STMT == type ||
|
||||
QUERY_NODE_SHOW_VGROUPS_STMT == type || QUERY_NODE_SHOW_INDEXES_STMT == type ||
|
||||
QUERY_NODE_SHOW_TAGS_STMT == type || QUERY_NODE_SHOW_TABLE_TAGS_STMT == type;
|
||||
QUERY_NODE_SHOW_TAGS_STMT == type || QUERY_NODE_SHOW_TABLE_TAGS_STMT == type ||
|
||||
QUERY_NODE_SHOW_VIEWS_STMT == type;
|
||||
}
|
||||
|
||||
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type) {
|
||||
|
@ -1701,6 +1729,17 @@ SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode*
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createShowCreateViewStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SShowCreateViewStmt* pStmt = (SShowCreateViewStmt*)nodesMakeNode(type);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
strcpy(pStmt->viewName, ((SRealTableNode*)pRealTable)->table.tableName);
|
||||
nodesDestroyNode(pRealTable);
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
|
||||
SNode* createShowTableDistributedStmt(SAstCreateContext* pCxt, SNode* pRealTable) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SShowTableDistributedStmt* pStmt = (SShowTableDistributedStmt*)nodesMakeNode(QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT);
|
||||
|
@ -2215,6 +2254,35 @@ SNode* createDropFunctionStmt(SAstCreateContext* pCxt, bool ignoreNotExists, con
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createCreateViewStmt(SAstCreateContext* pCxt, bool orReplace, SNode* pView, const SToken* pAs, SNode* pQuery) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SCreateViewStmt* pStmt = (SCreateViewStmt*)nodesMakeNode(QUERY_NODE_CREATE_VIEW_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
int32_t i = pAs->n;
|
||||
while (isspace(*(pAs->z + i))) {
|
||||
++i;
|
||||
}
|
||||
pStmt->pQuerySql = tstrdup(pAs->z + i);
|
||||
CHECK_OUT_OF_MEM(pStmt->pQuerySql);
|
||||
strcpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName);
|
||||
strcpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName);
|
||||
nodesDestroyNode(pView);
|
||||
pStmt->orReplace = orReplace;
|
||||
pStmt->pQuery = pQuery;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createDropViewStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pView) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropViewStmt* pStmt = (SDropViewStmt*)nodesMakeNode(QUERY_NODE_DROP_VIEW_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->ignoreNotExists = ignoreNotExists;
|
||||
strcpy(pStmt->dbName, ((SViewNode*)pView)->table.dbName);
|
||||
strcpy(pStmt->viewName, ((SViewNode*)pView)->table.tableName);
|
||||
nodesDestroyNode(pView);
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createStreamOptions(SAstCreateContext* pCxt) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SStreamOptions* pOptions = (SStreamOptions*)nodesMakeNode(QUERY_NODE_STREAM_OPTIONS);
|
||||
|
|
|
@ -29,6 +29,20 @@ extern void Parse(void*, int, SToken, void*);
|
|||
extern void ParseFree(void*, FFree);
|
||||
extern void ParseTrace(FILE*, char*);
|
||||
|
||||
int32_t buildQueryAfterParse(SQuery** pQuery, SNode* pRootNode, int16_t placeholderNo, SArray** pPlaceholderValues) {
|
||||
*pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
|
||||
if (NULL == *pQuery) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
(*pQuery)->pRoot = pRootNode;
|
||||
(*pQuery)->placeholderNum = placeholderNo;
|
||||
TSWAP((*pQuery)->pPlaceholderValues, *pPlaceholderValues);
|
||||
(*pQuery)->execStage = QUERY_EXEC_STAGE_ANALYSE;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
|
||||
SAstCreateContext cxt;
|
||||
initAstCreateContext(pParseCxt, &cxt);
|
||||
|
@ -77,14 +91,10 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
|
|||
abort_parse:
|
||||
ParseFree(pParser, (FFree)taosMemoryFree);
|
||||
if (TSDB_CODE_SUCCESS == cxt.errCode) {
|
||||
*pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY);
|
||||
if (NULL == *pQuery) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
int32_t code = buildQueryAfterParse(pQuery, cxt.pRootNode, cxt.placeholderNo, &cxt.pPlaceholderValues);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
(*pQuery)->pRoot = cxt.pRootNode;
|
||||
(*pQuery)->placeholderNum = cxt.placeholderNo;
|
||||
TSWAP((*pQuery)->pPlaceholderValues, cxt.pPlaceholderValues);
|
||||
(*pQuery)->execStage = QUERY_EXEC_STAGE_ANALYSE;
|
||||
}
|
||||
taosArrayDestroy(cxt.pPlaceholderValues);
|
||||
return cxt.errCode;
|
||||
|
@ -157,6 +167,12 @@ static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, const c
|
|||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pDb, pTable, authType,
|
||||
pCxt->pMetaCache);
|
||||
}
|
||||
#ifdef TD_ENTERPRISE
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pCxt->pParseCxt->pEffectiveUser) {
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pEffectiveUser, pDb, pTable, authType,
|
||||
pCxt->pMetaCache);
|
||||
}
|
||||
#endif
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pDb, pCxt->pMetaCache);
|
||||
}
|
||||
|
@ -371,6 +387,13 @@ static int32_t collectMetaKeyFromDescribe(SCollectMetaKeyCxt* pCxt, SDescribeStm
|
|||
strcpy(name.dbname, pStmt->dbName);
|
||||
strcpy(name.tname, pStmt->tableName);
|
||||
int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
|
||||
#ifdef TD_ENTERPRISE
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
tNameGetFullDbName(&name, dbFName);
|
||||
code = catalogRemoveViewMeta(pCxt->pParseCxt->pCatalog, dbFName, 0, pStmt->tableName, 0);
|
||||
}
|
||||
#endif
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
|
||||
}
|
||||
|
@ -573,6 +596,18 @@ static int32_t collectMetaKeyFromShowUserPrivileges(SCollectMetaKeyCxt* pCxt, SS
|
|||
pCxt->pMetaCache);
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromShowViews(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
|
||||
int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VIEWS,
|
||||
pCxt->pMetaCache);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code =
|
||||
reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
|
||||
NULL, AUTH_TYPE_READ_OR_WRITE, pCxt->pMetaCache);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t collectMetaKeyFromShowCreateDatabase(SCollectMetaKeyCxt* pCxt, SShowCreateDatabaseStmt* pStmt) {
|
||||
return reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
|
||||
}
|
||||
|
@ -595,6 +630,25 @@ static int32_t collectMetaKeyFromShowCreateTable(SCollectMetaKeyCxt* pCxt, SShow
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromShowCreateView(SCollectMetaKeyCxt* pCxt, SShowCreateViewStmt* pStmt) {
|
||||
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
|
||||
strcpy(name.dbname, pStmt->dbName);
|
||||
strcpy(name.tname, pStmt->viewName);
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
tNameGetFullDbName(&name, dbFName);
|
||||
int32_t code = catalogRemoveViewMeta(pCxt->pParseCxt->pCatalog, dbFName, 0, pStmt->viewName, 0);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveViewUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->viewName,
|
||||
AUTH_TYPE_READ, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, pCxt->pMetaCache);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t collectMetaKeyFromShowApps(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
|
||||
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_PERFORMANCE_SCHEMA_DB, TSDB_PERFS_TABLE_APPS,
|
||||
pCxt->pMetaCache);
|
||||
|
@ -646,6 +700,35 @@ static int32_t collectMetaKeyFromGrant(SCollectMetaKeyCxt* pCxt, SGrantStmt* pSt
|
|||
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, pCxt->pMetaCache);
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromRevoke(SCollectMetaKeyCxt* pCxt, SRevokeStmt* pStmt) {
|
||||
if ('\0' == pStmt->tabName[0]) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, pCxt->pMetaCache);
|
||||
}
|
||||
|
||||
|
||||
static int32_t collectMetaKeyFromCreateViewStmt(SCollectMetaKeyCxt* pCxt, SCreateViewStmt* pStmt) {
|
||||
int32_t code =
|
||||
reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, pCxt->pMetaCache);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, AUTH_TYPE_WRITE,
|
||||
pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveViewUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->viewName, AUTH_TYPE_ALTER,
|
||||
pCxt->pMetaCache);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromDropViewStmt(SCollectMetaKeyCxt* pCxt, SDropViewStmt* pStmt) {
|
||||
int32_t code = reserveViewUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->viewName, AUTH_TYPE_ALTER,
|
||||
pCxt->pMetaCache);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
||||
pCxt->pStmt = pStmt;
|
||||
switch (nodeType(pStmt)) {
|
||||
|
@ -685,6 +768,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
|||
return collectMetaKeyFromCreateStream(pCxt, (SCreateStreamStmt*)pStmt);
|
||||
case QUERY_NODE_GRANT_STMT:
|
||||
return collectMetaKeyFromGrant(pCxt, (SGrantStmt*)pStmt);
|
||||
case QUERY_NODE_REVOKE_STMT:
|
||||
return collectMetaKeyFromRevoke(pCxt, (SRevokeStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_DNODES_STMT:
|
||||
return collectMetaKeyFromShowDnodes(pCxt, (SShowStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_MNODES_STMT:
|
||||
|
@ -737,11 +822,15 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
|||
return collectMetaKeyFromShowVnodes(pCxt, (SShowVnodesStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
|
||||
return collectMetaKeyFromShowUserPrivileges(pCxt, (SShowStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_VIEWS_STMT:
|
||||
return collectMetaKeyFromShowViews(pCxt, (SShowStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
|
||||
return collectMetaKeyFromShowCreateDatabase(pCxt, (SShowCreateDatabaseStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||
return collectMetaKeyFromShowCreateTable(pCxt, (SShowCreateTableStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||
return collectMetaKeyFromShowCreateView(pCxt, (SShowCreateViewStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_APPS_STMT:
|
||||
return collectMetaKeyFromShowApps(pCxt, (SShowStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
|
||||
|
@ -754,6 +843,10 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
|||
return collectMetaKeyFromShowBlockDist(pCxt, (SShowTableDistributedStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
|
||||
return collectMetaKeyFromShowSubscriptions(pCxt, (SShowStmt*)pStmt);
|
||||
case QUERY_NODE_CREATE_VIEW_STMT:
|
||||
return collectMetaKeyFromCreateViewStmt(pCxt, (SCreateViewStmt*)pStmt);
|
||||
case QUERY_NODE_DROP_VIEW_STMT:
|
||||
return collectMetaKeyFromDropViewStmt(pCxt, (SDropViewStmt*)pStmt);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -35,28 +35,41 @@ typedef struct SAuthRewriteCxt {
|
|||
static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt);
|
||||
|
||||
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);
|
||||
bool isView, bool effective, SUserAuthInfo* pAuth) {
|
||||
if (effective) {
|
||||
snprintf(pAuth->user, sizeof(pAuth->user), "%s", pCxt->pEffectiveUser ? pCxt->pEffectiveUser : "");
|
||||
} else {
|
||||
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;
|
||||
pAuth->isView = isView;
|
||||
}
|
||||
|
||||
static int32_t checkAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond) {
|
||||
static int32_t checkAuthImpl(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond, bool isView, bool effective) {
|
||||
SParseContext* pParseCxt = pCxt->pParseCxt;
|
||||
if (pParseCxt->isSuperUser) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
AUTH_RES_TYPE auth_res_type = isView ? AUTH_RES_VIEW : AUTH_RES_BASIC;
|
||||
SUserAuthInfo authInfo = {0};
|
||||
setUserAuthInfo(pCxt->pParseCxt, pDbName, pTabName, type, &authInfo);
|
||||
setUserAuthInfo(pCxt->pParseCxt, pDbName, pTabName, type, isView, effective, &authInfo);
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SUserAuthRes authRes = {0};
|
||||
if (NULL != pCxt->pMetaCache) {
|
||||
code = getUserAuthFromCache(pCxt->pMetaCache, &authInfo, &authRes);
|
||||
#ifdef TD_ENTERPRISE
|
||||
if (isView && TSDB_CODE_PAR_INTERNAL_ERROR == code) {
|
||||
authInfo.isView = false;
|
||||
code = getUserAuthFromCache(pCxt->pMetaCache, &authInfo, &authRes);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
SRequestConnInfo conn = {.pTrans = pParseCxt->pTransporter,
|
||||
.requestId = pParseCxt->requestId,
|
||||
|
@ -65,9 +78,26 @@ static int32_t checkAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabNa
|
|||
code = catalogChkAuth(pParseCxt->pCatalog, &conn, &authInfo, &authRes);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pCond) {
|
||||
*pCond = authRes.pCond;
|
||||
*pCond = authRes.pCond[auth_res_type];
|
||||
}
|
||||
return TSDB_CODE_SUCCESS == code ? (authRes.pass ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED) : code;
|
||||
return TSDB_CODE_SUCCESS == code ? (authRes.pass[auth_res_type] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED) : code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t checkAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond) {
|
||||
return checkAuthImpl(pCxt, pDbName, pTabName, type, pCond, false, false);
|
||||
}
|
||||
|
||||
static int32_t checkEffectiveAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond) {
|
||||
return checkAuthImpl(pCxt, pDbName, pTabName, type, NULL, false, true);
|
||||
}
|
||||
|
||||
static int32_t checkViewAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond) {
|
||||
return checkAuthImpl(pCxt, pDbName, pTabName, type, NULL, true, false);
|
||||
}
|
||||
|
||||
static int32_t checkViewEffectiveAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond) {
|
||||
return checkAuthImpl(pCxt, pDbName, pTabName, type, NULL, true, true);
|
||||
}
|
||||
|
||||
static EDealRes authSubquery(SAuthCxt* pCxt, SNode* pStmt) {
|
||||
|
@ -130,12 +160,33 @@ static int32_t rewriteAppendStableTagCond(SNode** pWhere, SNode* pTagCond, STabl
|
|||
static EDealRes authSelectImpl(SNode* pNode, void* pContext) {
|
||||
SSelectAuthCxt* pCxt = pContext;
|
||||
SAuthCxt* pAuthCxt = pCxt->pAuthCxt;
|
||||
bool isView = false;
|
||||
if (QUERY_NODE_REAL_TABLE == nodeType(pNode)) {
|
||||
SNode* pTagCond = NULL;
|
||||
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 = rewriteAppendStableTagCond(&pCxt->pSelect->pWhere, pTagCond, pTable);
|
||||
#ifdef TD_ENTERPRISE
|
||||
SName name;
|
||||
STableMeta* pTableMeta = NULL;
|
||||
int32_t code = getTargetMetaImpl(
|
||||
pAuthCxt->pParseCxt, pAuthCxt->pMetaCache, toName(pAuthCxt->pParseCxt->acctId, pTable->dbName, pTable->tableName, &name), &pTableMeta, true);
|
||||
if (TSDB_CODE_SUCCESS == code && TSDB_VIEW_TABLE == pTableMeta->tableType) {
|
||||
isView = true;
|
||||
}
|
||||
taosMemoryFree(pTableMeta);
|
||||
#endif
|
||||
if (!isView) {
|
||||
pAuthCxt->errCode = checkAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, &pTagCond);
|
||||
if (TSDB_CODE_SUCCESS != pAuthCxt->errCode && NULL != pAuthCxt->pParseCxt->pEffectiveUser) {
|
||||
pAuthCxt->errCode = checkEffectiveAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, NULL);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pAuthCxt->errCode && NULL != pTagCond) {
|
||||
pAuthCxt->errCode = rewriteAppendStableTagCond(&pCxt->pSelect->pWhere, pTagCond, pTable);
|
||||
}
|
||||
} else {
|
||||
pAuthCxt->errCode = checkViewAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, NULL);
|
||||
if (TSDB_CODE_SUCCESS != pAuthCxt->errCode && NULL != pAuthCxt->pParseCxt->pEffectiveUser) {
|
||||
pAuthCxt->errCode = checkViewEffectiveAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, NULL);
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS == pAuthCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
||||
} else if (QUERY_NODE_TEMP_TABLE == nodeType(pNode)) {
|
||||
|
@ -196,6 +247,14 @@ static int32_t authShowCreateTable(SAuthCxt* pCxt, SShowCreateTableStmt* pStmt)
|
|||
return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_READ, &pTagCond);
|
||||
}
|
||||
|
||||
static int32_t authShowCreateView(SAuthCxt* pCxt, SShowCreateViewStmt* pStmt) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#endif
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t authCreateTable(SAuthCxt* pCxt, SCreateTableStmt* pStmt) {
|
||||
SNode* pTagCond = NULL;
|
||||
// todo check tag condition for subtable
|
||||
|
@ -238,6 +297,20 @@ static int32_t authAlterTable(SAuthCxt* pCxt, SAlterTableStmt* pStmt) {
|
|||
return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL);
|
||||
}
|
||||
|
||||
static int32_t authCreateView(SAuthCxt* pCxt, SCreateViewStmt* pStmt) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#endif
|
||||
return checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, NULL);
|
||||
}
|
||||
|
||||
static int32_t authDropView(SAuthCxt* pCxt, SDropViewStmt* pStmt) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#endif
|
||||
return checkViewAuth(pCxt, pStmt->dbName, pStmt->viewName, AUTH_TYPE_ALTER, NULL);
|
||||
}
|
||||
|
||||
static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
|
||||
switch (nodeType(pStmt)) {
|
||||
case QUERY_NODE_SET_OPERATOR:
|
||||
|
@ -283,6 +356,12 @@ static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
|
|||
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||
return authShowCreateTable(pCxt, (SShowCreateTableStmt*)pStmt);
|
||||
// case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||
// return authShowCreateView(pCxt, (SShowCreateViewStmt*)pStmt);
|
||||
case QUERY_NODE_CREATE_VIEW_STMT:
|
||||
return authCreateView(pCxt, (SCreateViewStmt*)pStmt);
|
||||
case QUERY_NODE_DROP_VIEW_STMT:
|
||||
return authDropView(pCxt, (SDropViewStmt*)pStmt);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -18,10 +18,17 @@
|
|||
#include "scalar.h"
|
||||
#include "ttime.h"
|
||||
|
||||
typedef struct SNodeReplaceContext {
|
||||
SNode* pTarget;
|
||||
SNode* pNew;
|
||||
bool replaced;
|
||||
} SNodeReplaceContext;
|
||||
|
||||
typedef struct SCalcConstContext {
|
||||
SParseContext* pParseCxt;
|
||||
SMsgBuf msgBuf;
|
||||
int32_t code;
|
||||
SParseContext* pParseCxt;
|
||||
SNodeReplaceContext replaceCxt;
|
||||
SMsgBuf msgBuf;
|
||||
int32_t code;
|
||||
} SCalcConstContext;
|
||||
|
||||
static int32_t calcConstQuery(SCalcConstContext* pCxt, SNode* pStmt, bool subquery);
|
||||
|
@ -166,7 +173,35 @@ static int32_t calcConstStmtCondition(SCalcConstContext* pCxt, SNode** pCond, bo
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t calcConstProject(SNode* pProject, bool dual, SNode** pNew) {
|
||||
static EDealRes doFindAndReplaceNode(SNode** pNode, void* pContext) {
|
||||
SCalcConstContext* pCxt = pContext;
|
||||
if (pCxt->replaceCxt.pTarget == *pNode) {
|
||||
nodesDestroyNode(*pNode);
|
||||
*pNode = nodesCloneNode(pCxt->replaceCxt.pNew);
|
||||
if (NULL == *pNode) {
|
||||
pCxt->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
pCxt->replaceCxt.replaced = true;
|
||||
return DEAL_RES_END;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static int32_t findAndReplaceNode(SCalcConstContext* pCxt, SNode** pRoot, SNode* pTarget, SNode* pNew, bool strict) {
|
||||
pCxt->replaceCxt.pNew = pNew;
|
||||
pCxt->replaceCxt.pTarget = pTarget;
|
||||
|
||||
nodesRewriteExprPostOrder(pRoot, doFindAndReplaceNode, pCxt);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->code && strict && !pCxt->replaceCxt.replaced) {
|
||||
parserError("target replace node not found, %p", pTarget);
|
||||
return TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
}
|
||||
return pCxt->code;
|
||||
}
|
||||
|
||||
static int32_t calcConstProject(SCalcConstContext* pCxt, SNode* pProject, bool dual, SNode** pNew) {
|
||||
SArray* pAssociation = NULL;
|
||||
if (NULL != ((SExprNode*)pProject)->pAssociation) {
|
||||
pAssociation = taosArrayDup(((SExprNode*)pProject)->pAssociation, NULL);
|
||||
|
@ -188,12 +223,20 @@ static int32_t calcConstProject(SNode* pProject, bool dual, SNode** pNew) {
|
|||
if (QUERY_NODE_VALUE == nodeType(*pNew) && NULL != pAssociation) {
|
||||
int32_t size = taosArrayGetSize(pAssociation);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SNode** pCol = taosArrayGetP(pAssociation, i);
|
||||
nodesDestroyNode(*pCol);
|
||||
*pCol = nodesCloneNode(*pNew);
|
||||
if (NULL == *pCol) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
break;
|
||||
SAssociationNode* pAssNode = taosArrayGet(pAssociation, i);
|
||||
SNode** pCol = pAssNode->pPlace;
|
||||
if (*pCol == pAssNode->pAssociationNode) {
|
||||
nodesDestroyNode(*pCol);
|
||||
*pCol = nodesCloneNode(*pNew);
|
||||
if (NULL == *pCol) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
code = findAndReplaceNode(pCxt, pCol, pAssNode->pAssociationNode, *pNew, true);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -247,7 +290,7 @@ static int32_t calcConstProjections(SCalcConstContext* pCxt, SSelectStmt* pSelec
|
|||
continue;
|
||||
}
|
||||
SNode* pNew = NULL;
|
||||
int32_t code = calcConstProject(pProj, (NULL == pSelect->pFromTable), &pNew);
|
||||
int32_t code = calcConstProject(pCxt, pProj, (NULL == pSelect->pFromTable), &pNew);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
REPLACE_NODE(pNew);
|
||||
} else {
|
||||
|
@ -514,7 +557,7 @@ static void resetProjectNullTypeImpl(SNodeList* pProjects) {
|
|||
SExprNode* pExpr = (SExprNode*)pProj;
|
||||
if (TSDB_DATA_TYPE_NULL == pExpr->resType.type) {
|
||||
pExpr->resType.type = TSDB_DATA_TYPE_VARCHAR;
|
||||
pExpr->resType.bytes = 0;
|
||||
pExpr->resType.bytes = VARSTR_HEADER_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -965,10 +965,10 @@ static int32_t checkAuth(SParseContext* pCxt, SName* pTbName, bool* pMissCache,
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (!exists) {
|
||||
*pMissCache = true;
|
||||
} else if (!authRes.pass) {
|
||||
} else if (!authRes.pass[AUTH_RES_BASIC]) {
|
||||
code = TSDB_CODE_PAR_PERMISSION_DENIED;
|
||||
} else if (NULL != authRes.pCond) {
|
||||
*pTagCond = authRes.pCond;
|
||||
} else if (NULL != authRes.pCond[AUTH_RES_BASIC]) {
|
||||
*pTagCond = authRes.pCond[AUTH_RES_BASIC];
|
||||
}
|
||||
}
|
||||
return code;
|
||||
|
@ -1168,7 +1168,14 @@ static int32_t parseUsingTableName(SInsertParseContext* pCxt, SVnodeModifyOpStmt
|
|||
}
|
||||
|
||||
static int32_t preParseTargetTableName(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, SToken* pTbName) {
|
||||
return insCreateSName(&pStmt->targetTableName, pTbName, pCxt->pComCxt->acctId, pCxt->pComCxt->db, &pCxt->msg);
|
||||
int32_t code = insCreateSName(&pStmt->targetTableName, pTbName, pCxt->pComCxt->acctId, pCxt->pComCxt->db, &pCxt->msg);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (IS_SYS_DBNAME(pStmt->targetTableName.dbname)) {
|
||||
return TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED;
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
// input pStmt->pSql:
|
||||
|
@ -1952,9 +1959,9 @@ static int32_t checkAuthFromMetaData(const SArray* pUsers, SNode** pTagCond) {
|
|||
if (TSDB_CODE_SUCCESS == pRes->code) {
|
||||
SUserAuthRes* pAuth = pRes->pRes;
|
||||
if (NULL != pAuth->pCond) {
|
||||
*pTagCond = nodesCloneNode(pAuth->pCond);
|
||||
*pTagCond = nodesCloneNode(pAuth->pCond[AUTH_RES_BASIC]);
|
||||
}
|
||||
return pAuth->pass ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED;
|
||||
return pAuth->pass[AUTH_RES_BASIC] ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED;
|
||||
}
|
||||
return pRes->code;
|
||||
}
|
||||
|
|
|
@ -266,6 +266,8 @@ static SKeyword keywordTable[] = {
|
|||
{"VERBOSE", TK_VERBOSE},
|
||||
{"VGROUP", TK_VGROUP},
|
||||
{"VGROUPS", TK_VGROUPS},
|
||||
{"VIEW", TK_VIEW},
|
||||
{"VIEWS", TK_VIEWS},
|
||||
{"VNODE", TK_VNODE},
|
||||
{"VNODES", TK_VNODES},
|
||||
{"WAL_FSYNC_PERIOD", TK_WAL_FSYNC_PERIOD},
|
||||
|
|
|
@ -251,6 +251,12 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
|
|||
.numOfShowCols = 1,
|
||||
.pShowCols = {"*"}
|
||||
},
|
||||
{ .showType = QUERY_NODE_SHOW_VIEWS_STMT,
|
||||
.pDbName = TSDB_INFORMATION_SCHEMA_DB,
|
||||
.pTableName = TSDB_INS_TABLE_VIEWS,
|
||||
.numOfShowCols = 1,
|
||||
.pShowCols = {"*"}
|
||||
},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
|
@ -335,22 +341,67 @@ static int32_t collectUseTable(const SName* pName, SHashObj* pTable) {
|
|||
return taosHashPut(pTable, fullName, strlen(fullName), pName, sizeof(SName));
|
||||
}
|
||||
|
||||
static int32_t getTableMetaImpl(STranslateContext* pCxt, const SName* pName, STableMeta** pMeta) {
|
||||
static int32_t getViewMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
#endif
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (pParCxt->async) {
|
||||
code = getViewMetaFromCache(pMetaCache, pName, pMeta);
|
||||
} else {
|
||||
SRequestConnInfo conn = {.pTrans = pParCxt->pTransporter,
|
||||
.requestId = pParCxt->requestId,
|
||||
.requestObjRefId = pParCxt->requestRid,
|
||||
.mgmtEps = pParCxt->mgmtEpSet};
|
||||
code = catalogGetViewMeta(pParCxt->pCatalog, &conn, pName, pMeta);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_PAR_TABLE_NOT_EXIST != code) {
|
||||
parserError("0x%" PRIx64 " catalogGetViewMeta error, code:%s, dbName:%s, viewName:%s", pParCxt->requestId,
|
||||
tstrerror(code), pName->dbname, pName->tname);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t getTargetMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta, bool couldBeView) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (pParCxt->async) {
|
||||
code = getTableMetaFromCache(pMetaCache, pName, pMeta);
|
||||
#ifdef TD_ENTERPRISE
|
||||
if ((TSDB_CODE_PAR_TABLE_NOT_EXIST == code || TSDB_CODE_PAR_INTERNAL_ERROR == code) && couldBeView) {
|
||||
int32_t origCode = code;
|
||||
code = getViewMetaFromCache(pMetaCache, pName, pMeta);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
code = origCode;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
SRequestConnInfo conn = {.pTrans = pParCxt->pTransporter,
|
||||
.requestId = pParCxt->requestId,
|
||||
.requestObjRefId = pParCxt->requestRid,
|
||||
.mgmtEps = pParCxt->mgmtEpSet};
|
||||
code = catalogGetTableMeta(pParCxt->pCatalog, &conn, pName, pMeta);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_PAR_TABLE_NOT_EXIST != code) {
|
||||
parserError("0x%" PRIx64 " catalogGetTableMeta error, code:%s, dbName:%s, tbName:%s", pParCxt->requestId,
|
||||
tstrerror(code), pName->dbname, pName->tname);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t getTargetMeta(STranslateContext* pCxt, const SName* pName, STableMeta** pMeta, bool couldBeView) {
|
||||
SParseContext* pParCxt = pCxt->pParseCxt;
|
||||
int32_t code = collectUseDatabase(pName, pCxt->pDbs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = collectUseTable(pName, pCxt->pTables);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (pParCxt->async) {
|
||||
code = getTableMetaFromCache(pCxt->pMetaCache, pName, pMeta);
|
||||
} else {
|
||||
SRequestConnInfo conn = {.pTrans = pParCxt->pTransporter,
|
||||
.requestId = pParCxt->requestId,
|
||||
.requestObjRefId = pParCxt->requestRid,
|
||||
.mgmtEps = pParCxt->mgmtEpSet};
|
||||
code = catalogGetTableMeta(pParCxt->pCatalog, &conn, pName, pMeta);
|
||||
}
|
||||
code = getTargetMetaImpl(pParCxt, pCxt->pMetaCache, pName, pMeta, couldBeView);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_PAR_TABLE_NOT_EXIST != code) {
|
||||
parserError("0x%" PRIx64 " catalogGetTableMeta error, code:%s, dbName:%s, tbName:%s", pCxt->pParseCxt->requestId,
|
||||
|
@ -361,7 +412,7 @@ static int32_t getTableMetaImpl(STranslateContext* pCxt, const SName* pName, STa
|
|||
|
||||
static int32_t getTableMeta(STranslateContext* pCxt, const char* pDbName, const char* pTableName, STableMeta** pMeta) {
|
||||
SName name;
|
||||
return getTableMetaImpl(pCxt, toName(pCxt->pParseCxt->acctId, pDbName, pTableName, &name), pMeta);
|
||||
return getTargetMeta(pCxt, toName(pCxt->pParseCxt->acctId, pDbName, pTableName, &name), pMeta, false);
|
||||
}
|
||||
|
||||
static int32_t getTableCfg(STranslateContext* pCxt, const SName* pName, STableCfg** pCfg) {
|
||||
|
@ -855,9 +906,13 @@ static void setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColum
|
|||
SColumnNode* pCol = *pColRef;
|
||||
|
||||
if (NULL == pExpr->pAssociation) {
|
||||
pExpr->pAssociation = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES);
|
||||
pExpr->pAssociation = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SAssociationNode));
|
||||
}
|
||||
taosArrayPush(pExpr->pAssociation, &pColRef);
|
||||
SAssociationNode assNode;
|
||||
assNode.pPlace = (SNode**)pColRef;
|
||||
assNode.pAssociationNode = (SNode*)*pColRef;
|
||||
taosArrayPush(pExpr->pAssociation, &assNode);
|
||||
|
||||
strcpy(pCol->tableAlias, pTable->table.tableAlias);
|
||||
pCol->colId = isPrimaryKey(pTable, (SNode*)pExpr) ? PRIMARYKEY_TIMESTAMP_COL_ID : 0;
|
||||
strcpy(pCol->colName, pExpr->aliasName);
|
||||
|
@ -2839,21 +2894,26 @@ static int32_t checkJoinTable(STranslateContext* pCxt, SJoinTableNode* pJoinTabl
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
|
||||
int32_t translateTable(STranslateContext* pCxt, SNode** pTable) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (nodeType(pTable)) {
|
||||
switch (nodeType(*pTable)) {
|
||||
case QUERY_NODE_REAL_TABLE: {
|
||||
SRealTableNode* pRealTable = (SRealTableNode*)pTable;
|
||||
SRealTableNode* pRealTable = (SRealTableNode*)*pTable;
|
||||
pRealTable->ratio = (NULL != pCxt->pExplainOpt ? pCxt->pExplainOpt->ratio : 1.0);
|
||||
// The SRealTableNode created through ROLLUP already has STableMeta.
|
||||
if (NULL == pRealTable->pMeta) {
|
||||
SName name;
|
||||
code = getTableMetaImpl(
|
||||
code = getTargetMeta(
|
||||
pCxt, toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName, &name),
|
||||
&(pRealTable->pMeta));
|
||||
&(pRealTable->pMeta), true);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code));
|
||||
}
|
||||
#ifdef TD_ENTERPRISE
|
||||
if (TSDB_VIEW_TABLE == pRealTable->pMeta->tableType) {
|
||||
return translateView(pCxt, pTable, &name);
|
||||
}
|
||||
#endif
|
||||
code = setTableVgroupList(pCxt, &name, pRealTable);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setTableIndex(pCxt, &name, pRealTable);
|
||||
|
@ -2878,7 +2938,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
|
|||
break;
|
||||
}
|
||||
case QUERY_NODE_TEMP_TABLE: {
|
||||
STempTableNode* pTempTable = (STempTableNode*)pTable;
|
||||
STempTableNode* pTempTable = (STempTableNode*)*pTable;
|
||||
code = translateSubquery(pCxt, pTempTable->pSubquery);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pTempTable->pSubquery) &&
|
||||
|
@ -2893,10 +2953,10 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
|
|||
break;
|
||||
}
|
||||
case QUERY_NODE_JOIN_TABLE: {
|
||||
SJoinTableNode* pJoinTable = (SJoinTableNode*)pTable;
|
||||
code = translateTable(pCxt, pJoinTable->pLeft);
|
||||
SJoinTableNode* pJoinTable = (SJoinTableNode*)*pTable;
|
||||
code = translateTable(pCxt, &pJoinTable->pLeft);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateTable(pCxt, pJoinTable->pRight);
|
||||
code = translateTable(pCxt, &pJoinTable->pRight);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkJoinTable(pCxt, pJoinTable);
|
||||
|
@ -3877,7 +3937,7 @@ static int32_t translateWhere(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t translateFrom(STranslateContext* pCxt, SNode* pTable) {
|
||||
static int32_t translateFrom(STranslateContext* pCxt, SNode** pTable) {
|
||||
pCxt->currClause = SQL_CLAUSE_FROM;
|
||||
return translateTable(pCxt, pTable);
|
||||
}
|
||||
|
@ -4006,7 +4066,7 @@ static int32_t translateSelectWithoutFrom(STranslateContext* pCxt, SSelectStmt*
|
|||
|
||||
static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||
pCxt->pCurrStmt = (SNode*)pSelect;
|
||||
int32_t code = translateFrom(pCxt, pSelect->pFromTable);
|
||||
int32_t code = translateFrom(pCxt, &pSelect->pFromTable);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pSelect->precision = ((STableNode*)pSelect->pFromTable)->precision;
|
||||
code = translateWhere(pCxt, pSelect);
|
||||
|
@ -4232,7 +4292,7 @@ static int32_t translateDeleteWhere(STranslateContext* pCxt, SDeleteStmt* pDelet
|
|||
|
||||
static int32_t translateDelete(STranslateContext* pCxt, SDeleteStmt* pDelete) {
|
||||
pCxt->pCurrStmt = (SNode*)pDelete;
|
||||
int32_t code = translateFrom(pCxt, pDelete->pFromTable);
|
||||
int32_t code = translateFrom(pCxt, &pDelete->pFromTable);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pDelete->precision = ((STableNode*)pDelete->pFromTable)->precision;
|
||||
code = translateDeleteWhere(pCxt, pDelete);
|
||||
|
@ -4313,7 +4373,7 @@ static int32_t translateInsertProject(STranslateContext* pCxt, SInsertStmt* pIns
|
|||
}
|
||||
snprintf(pExpr->aliasName, sizeof(pExpr->aliasName), "%s", pCol->colName);
|
||||
if (PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId) {
|
||||
pPrimaryKeyExpr = pProj;
|
||||
pPrimaryKeyExpr = (SNode*)pExpr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4325,19 +4385,19 @@ static int32_t translateInsertProject(STranslateContext* pCxt, SInsertStmt* pIns
|
|||
return addOrderByPrimaryKeyToQuery(pCxt, pPrimaryKeyExpr, pInsert->pQuery);
|
||||
}
|
||||
|
||||
static int32_t translateInsertTable(STranslateContext* pCxt, SNode* pTable) {
|
||||
static int32_t translateInsertTable(STranslateContext* pCxt, SNode** pTable) {
|
||||
int32_t code = translateFrom(pCxt, pTable);
|
||||
if (TSDB_CODE_SUCCESS == code && TSDB_CHILD_TABLE != ((SRealTableNode*)pTable)->pMeta->tableType &&
|
||||
TSDB_NORMAL_TABLE != ((SRealTableNode*)pTable)->pMeta->tableType) {
|
||||
code = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
|
||||
"insert data into super table is not supported");
|
||||
if (TSDB_CODE_SUCCESS == code && TSDB_CHILD_TABLE != ((SRealTableNode*)*pTable)->pMeta->tableType &&
|
||||
TSDB_NORMAL_TABLE != ((SRealTableNode*)*pTable)->pMeta->tableType) {
|
||||
code = buildInvalidOperationMsg(&pCxt->msgBuf, "insert data into super table is not supported");
|
||||
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t translateInsert(STranslateContext* pCxt, SInsertStmt* pInsert) {
|
||||
pCxt->pCurrStmt = (SNode*)pInsert;
|
||||
int32_t code = translateInsertTable(pCxt, pInsert->pTable);
|
||||
int32_t code = translateInsertTable(pCxt, &pInsert->pTable);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateInsertCols(pCxt, pInsert);
|
||||
}
|
||||
|
@ -6583,7 +6643,7 @@ static int32_t buildQueryForTableTopic(STranslateContext* pCxt, SCreateTopicStmt
|
|||
.mgmtEps = pParCxt->mgmtEpSet};
|
||||
SName name;
|
||||
STableMeta* pMeta = NULL;
|
||||
int32_t code = getTableMetaImpl(pCxt, toName(pParCxt->acctId, pStmt->subDbName, pStmt->subSTbName, &name), &pMeta);
|
||||
int32_t code = getTargetMeta(pCxt, toName(pParCxt->acctId, pStmt->subDbName, pStmt->subSTbName, &name), &pMeta, false);
|
||||
if (code) {
|
||||
taosMemoryFree(pMeta);
|
||||
return code;
|
||||
|
@ -6687,7 +6747,41 @@ static int32_t translateExplain(STranslateContext* pCxt, SExplainStmt* pStmt) {
|
|||
}
|
||||
|
||||
static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt) {
|
||||
return refreshGetTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pStmt->pMeta);
|
||||
int32_t code = refreshGetTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pStmt->pMeta);
|
||||
#ifdef TD_ENTERPRISE
|
||||
if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) {
|
||||
int32_t origCode = code;
|
||||
SName name;
|
||||
toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name);
|
||||
SViewMeta* pMeta = NULL;
|
||||
code = getViewMetaFromMetaCache(pCxt, &name, &pMeta);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
code = origCode;
|
||||
} else {
|
||||
SParseSqlRes res = {.resType = PARSE_SQL_RES_SCHEMA};
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
tNameGetFullDbName(&name, dbFName);
|
||||
code = (*pCxt->pParseCxt->parseSqlFp)(pCxt->pParseCxt->parseSqlParam, name.dbname, pMeta->querySql, false, pMeta->user, &res);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = collectUseTable(&name, pCxt->pTargetTables);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SViewMeta viewMeta = {0};
|
||||
viewMeta.viewId = pMeta->viewId;
|
||||
viewMeta.precision = res.schemaRes.precision;
|
||||
viewMeta.type = pMeta->type;
|
||||
viewMeta.version = pMeta->version;
|
||||
viewMeta.numOfCols = res.schemaRes.numOfCols;
|
||||
viewMeta.pSchema = res.schemaRes.pSchema;
|
||||
code = buildTableMetaFromViewMeta(&pStmt->pMeta, &viewMeta);
|
||||
parserDebug("rebuild view meta, view:%s.%s, numOfCols:%d, code:0x%x", dbFName, pStmt->tableName, viewMeta.numOfCols, code);
|
||||
}
|
||||
taosMemoryFree(res.schemaRes.pSchema);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t translateCompactRange(STranslateContext* pCxt, SCompactDatabaseStmt* pStmt, SCompactDbReq* pReq) {
|
||||
|
@ -6762,6 +6856,26 @@ static int32_t checkCreateStream(STranslateContext* pCxt, SCreateStreamStmt* pSt
|
|||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Unsupported stream query");
|
||||
}
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
SRealTableNode* pRealTable = (SRealTableNode*)((SSelectStmt*)pStmt->pQuery)->pFromTable;
|
||||
SName name;
|
||||
STableMeta* pMeta = NULL;
|
||||
int8_t tableType = 0;
|
||||
int32_t code = getTargetMeta(
|
||||
pCxt, toName(pCxt->pParseCxt->acctId, pRealTable->table.dbName, pRealTable->table.tableName, &name),
|
||||
&pMeta, true);
|
||||
if (NULL != pMeta) {
|
||||
tableType = pMeta->tableType;
|
||||
taosMemoryFree(pMeta);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code));
|
||||
}
|
||||
if (TSDB_VIEW_TABLE == tableType) {
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Unsupported stream query");
|
||||
}
|
||||
#endif
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -7603,6 +7717,91 @@ static int32_t translateResumeStream(STranslateContext* pCxt, SResumeStreamStmt*
|
|||
return buildCmdMsg(pCxt, TDMT_MND_RESUME_STREAM, (FSerializeFunc)tSerializeSMResumeStreamReq, &req);
|
||||
}
|
||||
|
||||
static int32_t validateCreateView(STranslateContext* pCxt, SCreateViewStmt* pStmt) {
|
||||
if (QUERY_NODE_SELECT_STMT != nodeType(pStmt->pQuery) && QUERY_NODE_SET_OPERATOR != nodeType(pStmt->pQuery)) {
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_VIEW_QUERY, "Invalid view query type");
|
||||
}
|
||||
|
||||
/*
|
||||
STableMeta* pMetaCache = NULL;
|
||||
int32_t code = getTableMeta(pCxt, pStmt->dbName, pStmt->viewName, &pMetaCache);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
taosMemoryFreeClear(pMetaCache);
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_VIEW_CONFLICT_WITH_TABLE, "View name is conflict with table");
|
||||
}
|
||||
*/
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateCreateView(STranslateContext* pCxt, SCreateViewStmt* pStmt) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#endif
|
||||
|
||||
SParseSqlRes res = {.resType = PARSE_SQL_RES_SCHEMA};
|
||||
SName name;
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name);
|
||||
tNameGetFullDbName(&name, dbFName);
|
||||
|
||||
int32_t code = validateCreateView(pCxt, pStmt);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = (*pCxt->pParseCxt->parseSqlFp)(pCxt->pParseCxt->parseSqlParam, pStmt->dbName, pStmt->pQuerySql, false, NULL, &res);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = collectUseTable(&name, pCxt->pTargetTables);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pStmt->createReq.precision = res.schemaRes.precision;
|
||||
pStmt->createReq.numOfCols = res.schemaRes.numOfCols;
|
||||
pStmt->createReq.pSchema = res.schemaRes.pSchema;
|
||||
strncpy(pStmt->createReq.name, pStmt->viewName, sizeof(pStmt->createReq.name) - 1);
|
||||
tstrncpy(pStmt->createReq.dbFName, dbFName, sizeof(pStmt->createReq.dbFName));
|
||||
snprintf(pStmt->createReq.fullname, sizeof(pStmt->createReq.fullname) - 1, "%s.%s", pStmt->createReq.dbFName, pStmt->viewName);
|
||||
TSWAP(pStmt->createReq.querySql, pStmt->pQuerySql);
|
||||
pStmt->createReq.orReplace = pStmt->orReplace;
|
||||
pStmt->createReq.sql = tstrdup(pCxt->pParseCxt->pSql);
|
||||
if (NULL == pStmt->createReq.sql) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildCmdMsg(pCxt, TDMT_MND_CREATE_VIEW, (FSerializeFunc)tSerializeSCMCreateViewReq, &pStmt->createReq);
|
||||
}
|
||||
|
||||
tFreeSCMCreateViewReq(&pStmt->createReq);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t translateDropView(STranslateContext* pCxt, SDropViewStmt* pStmt) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#endif
|
||||
|
||||
SCMDropViewReq dropReq = {0};
|
||||
SName name;
|
||||
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
|
||||
tNameGetFullDbName(&name, dropReq.dbFName);
|
||||
strncpy(dropReq.name, pStmt->viewName, sizeof(dropReq.name) - 1);
|
||||
snprintf(dropReq.fullname, sizeof(dropReq.fullname) - 1, "%s.%s", dropReq.dbFName, dropReq.name);
|
||||
dropReq.sql = (char*)pCxt->pParseCxt->pSql;
|
||||
if (NULL == dropReq.sql) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
dropReq.igNotExists = pStmt->ignoreNotExists;
|
||||
|
||||
toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name);
|
||||
int32_t code = collectUseTable(&name, pCxt->pTargetTables);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return buildCmdMsg(pCxt, TDMT_MND_DROP_VIEW, (FSerializeFunc)tSerializeSCMDropViewReq, &dropReq);
|
||||
}
|
||||
|
||||
|
||||
static int32_t readFromFile(char* pName, int32_t* len, char** buf) {
|
||||
int64_t filesize = 0;
|
||||
if (taosStatFile(pName, &filesize, NULL, NULL) < 0) {
|
||||
|
@ -7702,8 +7901,8 @@ static int32_t translateGrantTagCond(STranslateContext* pCxt, SGrantStmt* pStmt,
|
|||
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));
|
||||
code = getTargetMeta(pCxt, toName(pCxt->pParseCxt->acctId, pTable->table.dbName, pTable->table.tableName, &name),
|
||||
&(pTable->pMeta), false);
|
||||
if (code) {
|
||||
nodesDestroyNode((SNode*)pTable);
|
||||
return code;
|
||||
|
@ -7737,22 +7936,32 @@ static int32_t translateGrantTagCond(STranslateContext* pCxt, SGrantStmt* pStmt,
|
|||
}
|
||||
|
||||
static int32_t translateGrant(STranslateContext* pCxt, SGrantStmt* pStmt) {
|
||||
int32_t code = 0;
|
||||
SAlterUserReq req = {0};
|
||||
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_WRITE))) {
|
||||
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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
req.alterType = TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC;
|
||||
req.alterType = TSDB_ALTER_USER_ADD_PRIVILEGES;
|
||||
req.privileges = pStmt->privileges;
|
||||
#ifdef TD_ENTERPRISE
|
||||
if (0 != pStmt->tabName[0]) {
|
||||
SName name;
|
||||
STableMeta* pTableMeta = NULL;
|
||||
code = getTargetMeta(pCxt, toName(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, &name), &pTableMeta, true);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
if (TSDB_CODE_PAR_TABLE_NOT_EXIST != code) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code));
|
||||
}
|
||||
} else if (TSDB_VIEW_TABLE == pTableMeta->tableType) {
|
||||
req.isView = true;
|
||||
}
|
||||
taosMemoryFree(pTableMeta);
|
||||
}
|
||||
#endif
|
||||
|
||||
strcpy(req.user, pStmt->userName);
|
||||
sprintf(req.objname, "%d.%s", pCxt->pParseCxt->acctId, pStmt->objName);
|
||||
sprintf(req.tabName, "%s", pStmt->tabName);
|
||||
int32_t code = translateGrantTagCond(pCxt, pStmt, &req);
|
||||
if (!req.isView) {
|
||||
code = translateGrantTagCond(pCxt, pStmt, &req);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &req);
|
||||
}
|
||||
|
@ -7761,22 +7970,31 @@ static int32_t translateGrant(STranslateContext* pCxt, SGrantStmt* pStmt) {
|
|||
}
|
||||
|
||||
static int32_t translateRevoke(STranslateContext* pCxt, SRevokeStmt* pStmt) {
|
||||
int32_t code = 0;
|
||||
SAlterUserReq req = {0};
|
||||
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_WRITE))) {
|
||||
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)) {
|
||||
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)) {
|
||||
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)) {
|
||||
req.alterType = TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC;
|
||||
req.alterType = TSDB_ALTER_USER_DEL_PRIVILEGES;
|
||||
req.privileges = pStmt->privileges;
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
if (0 != pStmt->tabName[0]) {
|
||||
SName name;
|
||||
STableMeta* pTableMeta = NULL;
|
||||
code = getTargetMeta(pCxt, toName(pCxt->pParseCxt->acctId, pStmt->objName, pStmt->tabName, &name), &pTableMeta, true);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
if (TSDB_CODE_PAR_TABLE_NOT_EXIST != code) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GET_META_ERROR, tstrerror(code));
|
||||
}
|
||||
} else if (TSDB_VIEW_TABLE == pTableMeta->tableType) {
|
||||
req.isView = true;
|
||||
}
|
||||
taosMemoryFree(pTableMeta);
|
||||
}
|
||||
#endif
|
||||
|
||||
strcpy(req.user, pStmt->userName);
|
||||
sprintf(req.objname, "%d.%s", pCxt->pParseCxt->acctId, pStmt->objName);
|
||||
sprintf(req.tabName, "%s", pStmt->tabName);
|
||||
int32_t code = buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &req);
|
||||
code = buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &req);
|
||||
tFreeSAlterUserReq(&req);
|
||||
return code;
|
||||
}
|
||||
|
@ -7878,6 +8096,16 @@ static int32_t translateShowCreateTable(STranslateContext* pCxt, SShowCreateTabl
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t translateShowCreateView(STranslateContext* pCxt, SShowCreateViewStmt* pStmt) {
|
||||
#ifndef TD_ENTERPRISE
|
||||
return TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
#else
|
||||
SName name;
|
||||
toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->viewName, &name);
|
||||
return getViewMetaFromMetaCache(pCxt, &name, (SViewMeta**)&pStmt->pViewMeta);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (nodeType(pNode)) {
|
||||
|
@ -8036,12 +8264,22 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
|||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||
code = translateShowCreateTable(pCxt, (SShowCreateTableStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||
code = translateShowCreateView(pCxt, (SShowCreateViewStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_RESTORE_DNODE_STMT:
|
||||
case QUERY_NODE_RESTORE_QNODE_STMT:
|
||||
case QUERY_NODE_RESTORE_MNODE_STMT:
|
||||
case QUERY_NODE_RESTORE_VNODE_STMT:
|
||||
code = translateRestoreDnode(pCxt, (SRestoreComponentNodeStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_CREATE_VIEW_STMT:
|
||||
code = translateCreateView(pCxt, (SCreateViewStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_DROP_VIEW_STMT:
|
||||
code = translateDropView(pCxt, (SDropViewStmt*)pNode);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -8073,7 +8311,7 @@ static int32_t extractQueryResultSchema(const SNodeList* pProjections, int32_t*
|
|||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
if (TSDB_DATA_TYPE_NULL == pExpr->resType.type) {
|
||||
(*pSchema)[index].type = TSDB_DATA_TYPE_VARCHAR;
|
||||
(*pSchema)[index].bytes = 0;
|
||||
(*pSchema)[index].bytes = VARSTR_HEADER_SIZE;
|
||||
} else {
|
||||
(*pSchema)[index].type = pExpr->resType.type;
|
||||
(*pSchema)[index].bytes = pExpr->resType.bytes;
|
||||
|
@ -8180,6 +8418,25 @@ static int32_t extractShowCreateTableResultSchema(int32_t* numOfCols, SSchema**
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t extractShowCreateViewResultSchema(int32_t* numOfCols, SSchema** pSchema) {
|
||||
*numOfCols = SHOW_CREATE_VIEW_RESULT_COLS;
|
||||
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
|
||||
if (NULL == (*pSchema)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
(*pSchema)[0].type = TSDB_DATA_TYPE_BINARY;
|
||||
(*pSchema)[0].bytes = SHOW_CREATE_VIEW_RESULT_FIELD1_LEN;
|
||||
strcpy((*pSchema)[0].name, "View");
|
||||
|
||||
(*pSchema)[1].type = TSDB_DATA_TYPE_BINARY;
|
||||
(*pSchema)[1].bytes = SHOW_CREATE_VIEW_RESULT_FIELD2_LEN;
|
||||
strcpy((*pSchema)[1].name, "Create View");
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t extractShowVariablesResultSchema(int32_t* numOfCols, SSchema** pSchema) {
|
||||
*numOfCols = 3;
|
||||
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
|
||||
|
@ -8223,6 +8480,8 @@ int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pS
|
|||
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||
return extractShowCreateTableResultSchema(numOfCols, pSchema);
|
||||
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||
return extractShowCreateViewResultSchema(numOfCols, pSchema);
|
||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||
case QUERY_NODE_SHOW_VARIABLES_STMT:
|
||||
return extractShowVariablesResultSchema(numOfCols, pSchema);
|
||||
|
@ -9201,7 +9460,7 @@ static int32_t buildDropTableVgroupHashmap(STranslateContext* pCxt, SDropTableCl
|
|||
SName name;
|
||||
toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &name);
|
||||
STableMeta* pTableMeta = NULL;
|
||||
int32_t code = getTableMetaImpl(pCxt, &name, &pTableMeta);
|
||||
int32_t code = getTargetMeta(pCxt, &name, &pTableMeta, false);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = collectUseTable(&name, pCxt->pTargetTables);
|
||||
}
|
||||
|
@ -9734,6 +9993,7 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
case QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT:
|
||||
case QUERY_NODE_SHOW_TAGS_STMT:
|
||||
case QUERY_NODE_SHOW_USER_PRIVILEGES_STMT:
|
||||
case QUERY_NODE_SHOW_VIEWS_STMT:
|
||||
code = rewriteShow(pCxt, pQuery);
|
||||
break;
|
||||
case QUERY_NODE_SHOW_VGROUPS_STMT:
|
||||
|
@ -9863,6 +10123,7 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
|
||||
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
|
||||
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
|
||||
pQuery->execMode = QUERY_EXEC_MODE_LOCAL;
|
||||
pQuery->haveResultSet = true;
|
||||
|
|
|
@ -521,9 +521,9 @@ int32_t getVnodeSysTableTargetName(int32_t acctId, SNode* pWhere, SName* pName)
|
|||
}
|
||||
|
||||
static int32_t userAuthToString(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
|
||||
char* pStr) {
|
||||
return sprintf(pStr, "%s*%d*%s*%s*%d", pUser, acctId, pDb, (NULL == pTable || '\0' == pTable[0]) ? "``" : pTable,
|
||||
type);
|
||||
char* pStr, bool isView) {
|
||||
return sprintf(pStr, "%s*%d*%s*%s*%d*%d", pUser, acctId, pDb, (NULL == pTable || '\0' == pTable[0]) ? "``" : pTable,
|
||||
type, isView);
|
||||
}
|
||||
|
||||
static int32_t getIntegerFromAuthStr(const char* pStart, char** pNext) {
|
||||
|
@ -565,6 +565,7 @@ static void stringToUserAuth(const char* pStr, int32_t len, SUserAuthInfo* pUser
|
|||
pUserAuth->tbName.type = TSDB_DB_NAME_T;
|
||||
}
|
||||
pUserAuth->type = getIntegerFromAuthStr(p, &p);
|
||||
pUserAuth->isView = getIntegerFromAuthStr(p, &p);
|
||||
}
|
||||
|
||||
static int32_t buildTableReq(SHashObj* pTablesHash, SArray** pTables) {
|
||||
|
@ -693,6 +694,11 @@ int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalog
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildTableReq(pMetaCache->pTableCfg, &pCatalogReq->pTableCfg);
|
||||
}
|
||||
#ifdef TD_ENTERPRISE
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildTableReqFromDb(pMetaCache->pTableMeta, &pCatalogReq->pView);
|
||||
}
|
||||
#endif
|
||||
pCatalogReq->dNodeRequired = pMetaCache->dnodeRequired;
|
||||
return code;
|
||||
}
|
||||
|
@ -716,7 +722,7 @@ SNode* createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode*
|
|||
|
||||
static int32_t putMetaDataToHash(const char* pKey, int32_t len, const SArray* pData, int32_t index, SHashObj** pHash) {
|
||||
if (NULL == *pHash) {
|
||||
*pHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
*pHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
if (NULL == *pHash) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -725,7 +731,7 @@ static int32_t putMetaDataToHash(const char* pKey, int32_t len, const SArray* pD
|
|||
return taosHashPut(*pHash, pKey, len, &pRes, POINTER_BYTES);
|
||||
}
|
||||
|
||||
static int32_t getMetaDataFromHash(const char* pKey, int32_t len, SHashObj* pHash, void** pOutput) {
|
||||
int32_t getMetaDataFromHash(const char* pKey, int32_t len, SHashObj* pHash, void** pOutput) {
|
||||
SMetaRes** pRes = taosHashGet(pHash, pKey, len);
|
||||
if (NULL == pRes || NULL == *pRes) {
|
||||
return TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
|
@ -783,7 +789,7 @@ static int32_t putUserAuthToCache(const SArray* pUserAuthReq, const SArray* pUse
|
|||
SUserAuthInfo* pUser = taosArrayGet(pUserAuthReq, i);
|
||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||
int32_t len = userAuthToString(pUser->tbName.acctId, pUser->user, pUser->tbName.dbname, pUser->tbName.tname,
|
||||
pUser->type, key);
|
||||
pUser->type, key, pUser->isView);
|
||||
if (TSDB_CODE_SUCCESS != putMetaDataToHash(key, len, pUserAuthData, i, pUserAuth)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -828,6 +834,11 @@ int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMet
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = putTableDataToCache(pCatalogReq->pTableCfg, pMetaData->pTableCfg, &pMetaCache->pTableCfg);
|
||||
}
|
||||
#ifdef TD_ENTERPRISE
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = putDbTableDataToCache(pCatalogReq->pView, pMetaData->pView, &pMetaCache->pViews);
|
||||
}
|
||||
#endif
|
||||
pMetaCache->pDnodes = pMetaData->pDnodeList;
|
||||
return code;
|
||||
}
|
||||
|
@ -896,6 +907,38 @@ int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, S
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta) {
|
||||
*pMeta = taosMemoryCalloc(1, sizeof(STableMeta) + pViewMeta->numOfCols * sizeof(SSchema));
|
||||
if (NULL == *pMeta) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
(*pMeta)->uid = pViewMeta->viewId;
|
||||
(*pMeta)->vgId = MNODE_HANDLE;
|
||||
(*pMeta)->tableType = TSDB_VIEW_TABLE;
|
||||
(*pMeta)->sversion = pViewMeta->version;
|
||||
(*pMeta)->tversion = pViewMeta->version;
|
||||
(*pMeta)->tableInfo.precision = pViewMeta->precision;
|
||||
(*pMeta)->tableInfo.numOfColumns = pViewMeta->numOfCols;
|
||||
memcpy((*pMeta)->schema, pViewMeta->pSchema, sizeof(SSchema) * pViewMeta->numOfCols);
|
||||
|
||||
for (int32_t i = 0; i < pViewMeta->numOfCols; ++i) {
|
||||
(*pMeta)->tableInfo.rowSize += (*pMeta)->schema[i].bytes;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t getViewMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta) {
|
||||
char fullName[TSDB_TABLE_FNAME_LEN];
|
||||
tNameExtractFullName(pName, fullName);
|
||||
SViewMeta* pViewMeta = NULL;
|
||||
int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pViews, (void**)&pViewMeta);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildTableMetaFromViewMeta(pMeta, pViewMeta);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t reserveDbReqInCache(int32_t acctId, const char* pDb, SHashObj** pDbs) {
|
||||
if (NULL == *pDbs) {
|
||||
*pDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
|
@ -987,14 +1030,23 @@ static int32_t reserveUserAuthInCacheImpl(const char* pKey, int32_t len, SParseM
|
|||
int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
|
||||
SParseMetaCache* pMetaCache) {
|
||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||
int32_t len = userAuthToString(acctId, pUser, pDb, pTable, type, key);
|
||||
int32_t len = userAuthToString(acctId, pUser, pDb, pTable, type, key, false);
|
||||
return reserveUserAuthInCacheImpl(key, len, pMetaCache);
|
||||
}
|
||||
|
||||
int32_t reserveViewUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
|
||||
SParseMetaCache* pMetaCache) {
|
||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||
int32_t len = userAuthToString(acctId, pUser, pDb, pTable, type, key, true);
|
||||
return reserveUserAuthInCacheImpl(key, len, pMetaCache);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, SUserAuthInfo* pAuthReq, SUserAuthRes* pAuthRes) {
|
||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||
int32_t len = userAuthToString(pAuthReq->tbName.acctId, pAuthReq->user, pAuthReq->tbName.dbname,
|
||||
pAuthReq->tbName.tname, pAuthReq->type, key);
|
||||
pAuthReq->tbName.tname, pAuthReq->type, key, pAuthReq->isView);
|
||||
SUserAuthRes* pAuth = NULL;
|
||||
int32_t code = getMetaDataFromHash(key, len, pMetaCache->pUserAuth, (void**)&pAuth);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -1137,9 +1189,11 @@ void destoryParseMetaCache(SParseMetaCache* pMetaCache, bool request) {
|
|||
if (request) {
|
||||
destoryParseTablesMetaReqHash(pMetaCache->pTableMeta);
|
||||
destoryParseTablesMetaReqHash(pMetaCache->pTableVgroup);
|
||||
destoryParseTablesMetaReqHash(pMetaCache->pViews);
|
||||
} else {
|
||||
taosHashCleanup(pMetaCache->pTableMeta);
|
||||
taosHashCleanup(pMetaCache->pTableVgroup);
|
||||
taosHashCleanup(pMetaCache->pViews);
|
||||
}
|
||||
taosHashCleanup(pMetaCache->pDbVgroup);
|
||||
taosHashCleanup(pMetaCache->pDbCfg);
|
||||
|
|
|
@ -51,6 +51,10 @@ bool qIsInsertValuesSql(const char* pStr, size_t length) {
|
|||
static int32_t analyseSemantic(SParseContext* pCxt, SQuery* pQuery, SParseMetaCache* pMetaCache) {
|
||||
int32_t code = authenticate(pCxt, pQuery, pMetaCache);
|
||||
|
||||
if (pCxt->parseOnly) {
|
||||
return code;
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && pQuery->placeholderNum > 0) {
|
||||
TSWAP(pQuery->pPrepareRoot, pQuery->pRoot);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -244,11 +248,58 @@ int32_t qContinueParsePostQuery(SParseContext* pCxt, SQuery* pQuery, void** pRes
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
static void destoryTablesReq(void *p) {
|
||||
STablesReq *pRes = (STablesReq *)p;
|
||||
taosArrayDestroy(pRes->pTables);
|
||||
}
|
||||
|
||||
void destoryCatalogReq(SCatalogReq *pCatalogReq) {
|
||||
if (NULL == pCatalogReq) {
|
||||
return;
|
||||
}
|
||||
taosArrayDestroy(pCatalogReq->pDbVgroup);
|
||||
taosArrayDestroy(pCatalogReq->pDbCfg);
|
||||
taosArrayDestroy(pCatalogReq->pDbInfo);
|
||||
if (pCatalogReq->cloned) {
|
||||
taosArrayDestroy(pCatalogReq->pTableMeta);
|
||||
taosArrayDestroy(pCatalogReq->pTableHash);
|
||||
#ifdef TD_ENTERPRISE
|
||||
taosArrayDestroy(pCatalogReq->pView);
|
||||
#endif
|
||||
} else {
|
||||
taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq);
|
||||
taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq);
|
||||
#ifdef TD_ENTERPRISE
|
||||
taosArrayDestroyEx(pCatalogReq->pView, destoryTablesReq);
|
||||
#endif
|
||||
}
|
||||
taosArrayDestroy(pCatalogReq->pUdf);
|
||||
taosArrayDestroy(pCatalogReq->pIndex);
|
||||
taosArrayDestroy(pCatalogReq->pUser);
|
||||
taosArrayDestroy(pCatalogReq->pTableIndex);
|
||||
taosArrayDestroy(pCatalogReq->pTableCfg);
|
||||
taosArrayDestroy(pCatalogReq->pTableTag);
|
||||
}
|
||||
|
||||
|
||||
void tfreeSParseQueryRes(void* p) {
|
||||
if (NULL == p) {
|
||||
return;
|
||||
}
|
||||
|
||||
SParseQueryRes* pRes = p;
|
||||
destoryCatalogReq(pRes->pCatalogReq);
|
||||
taosMemoryFree(pRes->pCatalogReq);
|
||||
catalogFreeMetaData(&pRes->meta);
|
||||
}
|
||||
|
||||
void qDestroyParseContext(SParseContext* pCxt) {
|
||||
if (NULL == pCxt) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosArrayDestroyEx(pCxt->pSubMetaList, tfreeSParseQueryRes);
|
||||
taosArrayDestroy(pCxt->pTableMetaPos);
|
||||
taosArrayDestroy(pCxt->pTableVgroupPos);
|
||||
taosMemoryFree(pCxt);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -110,6 +110,10 @@ void generateInformationSchema(MockCatalogService* mcs) {
|
|||
.addColumn("user_name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN)
|
||||
.addColumn("privilege", TSDB_DATA_TYPE_BINARY, 10)
|
||||
.done();
|
||||
mcs->createTableBuilder(TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_VIEWS, TSDB_SYSTEM_TABLE, 2)
|
||||
.addColumn("view_name", TSDB_DATA_TYPE_BINARY, TSDB_VIEW_NAME_LEN)
|
||||
.addColumn("create_time", TSDB_DATA_TYPE_TIMESTAMP)
|
||||
.done();
|
||||
}
|
||||
|
||||
void generatePerformanceSchema(MockCatalogService* mcs) {
|
||||
|
@ -280,12 +284,12 @@ int32_t __catalogGetDBCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const char* d
|
|||
}
|
||||
|
||||
int32_t __catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, SUserAuthInfo *pAuth, SUserAuthRes* pRes) {
|
||||
pRes->pass = true;
|
||||
pRes->pass[0] = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t __catalogChkAuthFromCache(SCatalog* pCtg, SUserAuthInfo *pAuth, SUserAuthRes* pRes, bool* exists) {
|
||||
pRes->pass = true;
|
||||
pRes->pass[0] = true;
|
||||
*exists = true;
|
||||
return 0;
|
||||
}
|
||||
|
@ -301,6 +305,8 @@ int32_t __catalogRefreshGetTableMeta(SCatalog* pCatalog, SRequestConnInfo* pConn
|
|||
|
||||
int32_t __catalogRemoveTableMeta(SCatalog* pCtg, SName* pTableName) { return 0; }
|
||||
|
||||
int32_t __catalogRemoveViewMeta(SCatalog* pCtg, SName* pTableName) { return 0; }
|
||||
|
||||
int32_t __catalogGetTableIndex(SCatalog* pCtg, void* pTrans, const SEpSet* pMgmtEps, const SName* pName,
|
||||
SArray** pRes) {
|
||||
return g_mockCatalogService->catalogGetTableIndex(pName, pRes);
|
||||
|
@ -337,6 +343,7 @@ void initMetaDataEnv() {
|
|||
stub.set(catalogGetUdfInfo, __catalogGetUdfInfo);
|
||||
stub.set(catalogRefreshGetTableMeta, __catalogRefreshGetTableMeta);
|
||||
stub.set(catalogRemoveTableMeta, __catalogRemoveTableMeta);
|
||||
stub.set(catalogRemoveViewMeta, __catalogRemoveViewMeta);
|
||||
stub.set(catalogGetTableIndex, __catalogGetTableIndex);
|
||||
stub.set(catalogGetDnodeList, __catalogGetDnodeList);
|
||||
stub.set(catalogRefreshGetTableCfg, __catalogRefreshGetTableCfg);
|
||||
|
|
|
@ -225,6 +225,9 @@ class MockCatalogServiceImpl {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = getAllTableCfg(pCatalogReq->pTableCfg, &pMetaData->pTableCfg);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = getAllViewMeta(pCatalogReq->pView, &pMetaData->pView);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -590,7 +593,7 @@ class MockCatalogServiceImpl {
|
|||
for (int32_t i = 0; i < num; ++i) {
|
||||
SMetaRes res = {0};
|
||||
res.pRes = taosMemoryCalloc(1, sizeof(SUserAuthRes));
|
||||
((SUserAuthRes*)res.pRes)->pass = true;
|
||||
((SUserAuthRes*)res.pRes)->pass[0] = true;
|
||||
taosArrayPush(*pUserAuthData, &res);
|
||||
}
|
||||
}
|
||||
|
@ -638,6 +641,20 @@ class MockCatalogServiceImpl {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t getAllViewMeta(SArray* pViewMetaReq, SArray** pViewMetaData) const {
|
||||
if (NULL != pViewMetaReq) {
|
||||
int32_t nviews = taosArrayGetSize(pViewMetaReq);
|
||||
*pViewMetaData = taosArrayInit(nviews, sizeof(SMetaRes));
|
||||
for (int32_t i = 0; i < nviews; ++i) {
|
||||
SMetaRes res = {0};
|
||||
res.pRes = NULL;
|
||||
res.code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
taosArrayPush(*pViewMetaData, &res);
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t getAllDnodeList(SArray** pDnodes) const {
|
||||
SMetaRes res = {0};
|
||||
catalogGetDnodeList((SArray**)&res.pRes);
|
||||
|
|
|
@ -36,8 +36,10 @@ TEST_F(ParserExplainToSyncdbTest, grant) {
|
|||
|
||||
SAlterUserReq expect = {0};
|
||||
|
||||
auto setAlterUserReq = [&](int8_t alterType, const string& user, const string& obj) {
|
||||
auto setAlterUserReq = [&](int8_t alterType, int64_t privileges, const string& user, const string& obj) {
|
||||
expect.alterType = alterType;
|
||||
expect.privileges = privileges;
|
||||
expect.tabName[0] = 0;
|
||||
snprintf(expect.user, sizeof(expect.user), "%s", user.c_str());
|
||||
snprintf(expect.objname, sizeof(expect.objname), "%s", obj.c_str());
|
||||
};
|
||||
|
@ -52,19 +54,22 @@ TEST_F(ParserExplainToSyncdbTest, grant) {
|
|||
ASSERT_EQ(string(req.objname), string(expect.objname));
|
||||
});
|
||||
|
||||
setAlterUserReq(TSDB_ALTER_USER_ADD_ALL_DB, "wxy", "0.*");
|
||||
setAlterUserReq(TSDB_ALTER_USER_ADD_PRIVILEGES, PRIVILEGE_TYPE_ALL, "wxy", "0.*");
|
||||
run("GRANT ALL ON *.* TO wxy");
|
||||
|
||||
setAlterUserReq(TSDB_ALTER_USER_ADD_READ_DB, "wxy", "0.test");
|
||||
setAlterUserReq(TSDB_ALTER_USER_ADD_PRIVILEGES, PRIVILEGE_TYPE_READ, "wxy", "0.test");
|
||||
run("GRANT READ ON test.* TO wxy");
|
||||
|
||||
setAlterUserReq(TSDB_ALTER_USER_ADD_WRITE_DB, "wxy", "0.test");
|
||||
setAlterUserReq(TSDB_ALTER_USER_ADD_PRIVILEGES, PRIVILEGE_TYPE_WRITE, "wxy", "0.test");
|
||||
run("GRANT WRITE ON test.* TO wxy");
|
||||
|
||||
setAlterUserReq(TSDB_ALTER_USER_ADD_ALL_DB, "wxy", "0.test");
|
||||
setAlterUserReq(TSDB_ALTER_USER_ADD_PRIVILEGES, PRIVILEGE_TYPE_ALTER, "wxy", "0.test");
|
||||
run("GRANT ALTER ON test.* TO wxy");
|
||||
|
||||
setAlterUserReq(TSDB_ALTER_USER_ADD_PRIVILEGES, PRIVILEGE_TYPE_READ | PRIVILEGE_TYPE_WRITE, "wxy", "0.test");
|
||||
run("GRANT READ, WRITE ON test.* TO wxy");
|
||||
|
||||
setAlterUserReq(TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC, "wxy", "0.tp1");
|
||||
setAlterUserReq(TSDB_ALTER_USER_ADD_PRIVILEGES, PRIVILEGE_TYPE_SUBSCRIBE, "wxy", "0.tp1");
|
||||
run("GRANT SUBSCRIBE ON tp1 TO wxy");
|
||||
}
|
||||
|
||||
|
@ -251,8 +256,10 @@ TEST_F(ParserExplainToSyncdbTest, revoke) {
|
|||
|
||||
SAlterUserReq expect = {0};
|
||||
|
||||
auto setAlterUserReq = [&](int8_t alterType, const string& user, const string& obj) {
|
||||
auto setAlterUserReq = [&](int8_t alterType, int64_t privileges, const string& user, const string& obj) {
|
||||
expect.alterType = alterType;
|
||||
expect.privileges = privileges;
|
||||
expect.tabName[0] = 0;
|
||||
snprintf(expect.user, sizeof(expect.user), "%s", user.c_str());
|
||||
snprintf(expect.objname, sizeof(expect.objname), "%s", obj.c_str());
|
||||
};
|
||||
|
@ -267,19 +274,22 @@ TEST_F(ParserExplainToSyncdbTest, revoke) {
|
|||
ASSERT_EQ(string(req.objname), string(expect.objname));
|
||||
});
|
||||
|
||||
setAlterUserReq(TSDB_ALTER_USER_REMOVE_ALL_DB, "wxy", "0.*");
|
||||
setAlterUserReq(TSDB_ALTER_USER_DEL_PRIVILEGES, PRIVILEGE_TYPE_ALL, "wxy", "0.*");
|
||||
run("REVOKE ALL ON *.* FROM wxy");
|
||||
|
||||
setAlterUserReq(TSDB_ALTER_USER_REMOVE_READ_DB, "wxy", "0.test");
|
||||
setAlterUserReq(TSDB_ALTER_USER_DEL_PRIVILEGES, PRIVILEGE_TYPE_READ, "wxy", "0.test");
|
||||
run("REVOKE READ ON test.* FROM wxy");
|
||||
|
||||
setAlterUserReq(TSDB_ALTER_USER_REMOVE_WRITE_DB, "wxy", "0.test");
|
||||
setAlterUserReq(TSDB_ALTER_USER_DEL_PRIVILEGES, PRIVILEGE_TYPE_WRITE, "wxy", "0.test");
|
||||
run("REVOKE WRITE ON test.* FROM wxy");
|
||||
|
||||
setAlterUserReq(TSDB_ALTER_USER_REMOVE_ALL_DB, "wxy", "0.test");
|
||||
setAlterUserReq(TSDB_ALTER_USER_DEL_PRIVILEGES, PRIVILEGE_TYPE_ALTER, "wxy", "0.test");
|
||||
run("REVOKE ALTER ON test.* FROM wxy");
|
||||
|
||||
setAlterUserReq(TSDB_ALTER_USER_DEL_PRIVILEGES, PRIVILEGE_TYPE_READ|PRIVILEGE_TYPE_WRITE, "wxy", "0.test");
|
||||
run("REVOKE READ, WRITE ON test.* FROM wxy");
|
||||
|
||||
setAlterUserReq(TSDB_ALTER_USER_REMOVE_SUBSCRIBE_TOPIC, "wxy", "0.tp1");
|
||||
setAlterUserReq(TSDB_ALTER_USER_DEL_PRIVILEGES, PRIVILEGE_TYPE_SUBSCRIBE, "wxy", "0.tp1");
|
||||
run("REVOKE SUBSCRIBE ON tp1 FROM wxy");
|
||||
}
|
||||
|
||||
|
|
|
@ -458,6 +458,130 @@ TEST_F(ParserInitialCTest, createFunction) {
|
|||
run("CREATE OR REPLACE AGGREGATE FUNCTION IF NOT EXISTS udf2 AS 'udf' OUTPUTTYPE DOUBLE BUFSIZE 8 LANGUAGE 'python'");
|
||||
}
|
||||
|
||||
/*
|
||||
* CREATE [ OR REPLACE ] VIEW name [ ( column_name [, ...] ) ] AS query
|
||||
*
|
||||
*/
|
||||
TEST_F(ParserInitialCTest, createView) {
|
||||
useDb("root", "test");
|
||||
|
||||
SCMCreateStreamReq expect = {0};
|
||||
|
||||
auto clearCreateStreamReq = [&]() {
|
||||
tFreeSCMCreateStreamReq(&expect);
|
||||
memset(&expect, 0, sizeof(SCMCreateStreamReq));
|
||||
};
|
||||
|
||||
auto setCreateStreamReq = [&](const char* pStream, const char* pSrcDb, const char* pSql, const char* pDstStb,
|
||||
int8_t igExists = 0) {
|
||||
snprintf(expect.name, sizeof(expect.name), "0.%s", pStream);
|
||||
snprintf(expect.sourceDB, sizeof(expect.sourceDB), "0.%s", pSrcDb);
|
||||
snprintf(expect.targetStbFullName, sizeof(expect.targetStbFullName), "0.test.%s", pDstStb);
|
||||
expect.igExists = igExists;
|
||||
expect.sql = taosStrdup(pSql);
|
||||
};
|
||||
|
||||
auto setStreamOptions =
|
||||
[&](int8_t createStb = STREAM_CREATE_STABLE_TRUE, int8_t triggerType = STREAM_TRIGGER_WINDOW_CLOSE,
|
||||
int64_t maxDelay = 0, int64_t watermark = 0, int8_t igExpired = STREAM_DEFAULT_IGNORE_EXPIRED,
|
||||
int8_t fillHistory = STREAM_DEFAULT_FILL_HISTORY, int8_t igUpdate = STREAM_DEFAULT_IGNORE_UPDATE) {
|
||||
expect.createStb = createStb;
|
||||
expect.triggerType = triggerType;
|
||||
expect.maxDelay = maxDelay;
|
||||
expect.watermark = watermark;
|
||||
expect.fillHistory = fillHistory;
|
||||
expect.igExpired = igExpired;
|
||||
expect.igUpdate = igUpdate;
|
||||
};
|
||||
|
||||
auto addTag = [&](const char* pFieldName, uint8_t type, int32_t bytes = 0) {
|
||||
SField field = {0};
|
||||
strcpy(field.name, pFieldName);
|
||||
field.type = type;
|
||||
field.bytes = bytes > 0 ? bytes : tDataTypes[type].bytes;
|
||||
field.flags |= COL_SMA_ON;
|
||||
|
||||
if (NULL == expect.pTags) {
|
||||
expect.pTags = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SField));
|
||||
}
|
||||
taosArrayPush(expect.pTags, &field);
|
||||
expect.numOfTags += 1;
|
||||
};
|
||||
|
||||
setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
|
||||
ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_CREATE_STREAM_STMT);
|
||||
SCMCreateStreamReq req = {0};
|
||||
ASSERT_TRUE(TSDB_CODE_SUCCESS ==
|
||||
tDeserializeSCMCreateStreamReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req));
|
||||
|
||||
ASSERT_EQ(std::string(req.name), std::string(expect.name));
|
||||
ASSERT_EQ(std::string(req.sourceDB), std::string(expect.sourceDB));
|
||||
ASSERT_EQ(std::string(req.targetStbFullName), std::string(expect.targetStbFullName));
|
||||
ASSERT_EQ(req.igExists, expect.igExists);
|
||||
ASSERT_EQ(std::string(req.sql), std::string(expect.sql));
|
||||
ASSERT_EQ(req.triggerType, expect.triggerType);
|
||||
ASSERT_EQ(req.maxDelay, expect.maxDelay);
|
||||
ASSERT_EQ(req.watermark, expect.watermark);
|
||||
ASSERT_EQ(req.fillHistory, expect.fillHistory);
|
||||
ASSERT_EQ(req.igExpired, expect.igExpired);
|
||||
ASSERT_EQ(req.numOfTags, expect.numOfTags);
|
||||
if (expect.numOfTags > 0) {
|
||||
ASSERT_EQ(taosArrayGetSize(req.pTags), expect.numOfTags);
|
||||
ASSERT_EQ(taosArrayGetSize(req.pTags), taosArrayGetSize(expect.pTags));
|
||||
for (int32_t i = 0; i < expect.numOfTags; ++i) {
|
||||
SField* pField = (SField*)taosArrayGet(req.pTags, i);
|
||||
SField* pExpectField = (SField*)taosArrayGet(expect.pTags, i);
|
||||
ASSERT_EQ(std::string(pField->name), std::string(pExpectField->name));
|
||||
ASSERT_EQ(pField->type, pExpectField->type);
|
||||
ASSERT_EQ(pField->bytes, pExpectField->bytes);
|
||||
ASSERT_EQ(pField->flags, pExpectField->flags);
|
||||
}
|
||||
}
|
||||
ASSERT_EQ(req.checkpointFreq, expect.checkpointFreq);
|
||||
ASSERT_EQ(req.createStb, expect.createStb);
|
||||
ASSERT_EQ(req.igUpdate, expect.igUpdate);
|
||||
tFreeSCMCreateStreamReq(&req);
|
||||
});
|
||||
|
||||
setCreateStreamReq("s1", "test", "create stream s1 into st3 as select count(*) from t1 interval(10s)", "st3");
|
||||
setStreamOptions();
|
||||
run("CREATE STREAM s1 INTO st3 AS SELECT COUNT(*) FROM t1 INTERVAL(10S)");
|
||||
clearCreateStreamReq();
|
||||
|
||||
setCreateStreamReq(
|
||||
"s1", "test",
|
||||
"create stream if not exists s1 trigger max_delay 20s watermark 10s ignore expired 0 fill_history 0 ignore "
|
||||
"update 1 into st3 as select count(*) from t1 interval(10s)",
|
||||
"st3", 1);
|
||||
setStreamOptions(STREAM_CREATE_STABLE_TRUE, STREAM_TRIGGER_MAX_DELAY, 20 * MILLISECOND_PER_SECOND,
|
||||
10 * MILLISECOND_PER_SECOND, 0, 0, 1);
|
||||
run("CREATE STREAM IF NOT EXISTS s1 TRIGGER MAX_DELAY 20s WATERMARK 10s IGNORE EXPIRED 0 FILL_HISTORY 0 IGNORE "
|
||||
"UPDATE 1 INTO st3 AS SELECT COUNT(*) FROM t1 INTERVAL(10S)");
|
||||
clearCreateStreamReq();
|
||||
|
||||
setCreateStreamReq("s1", "test",
|
||||
"create stream s1 into st3 tags(tname varchar(10), id int) subtable(concat('new-', tname)) as "
|
||||
"select _wstart wstart, count(*) cnt from st1 partition by tbname tname, tag1 id interval(10s)",
|
||||
"st3");
|
||||
addTag("tname", TSDB_DATA_TYPE_VARCHAR, 10 + VARSTR_HEADER_SIZE);
|
||||
addTag("id", TSDB_DATA_TYPE_INT);
|
||||
setStreamOptions();
|
||||
run("CREATE STREAM s1 INTO st3 TAGS(tname VARCHAR(10), id INT) SUBTABLE(CONCAT('new-', tname)) "
|
||||
"AS SELECT _WSTART wstart, COUNT(*) cnt FROM st1 PARTITION BY TBNAME tname, tag1 id INTERVAL(10S)");
|
||||
clearCreateStreamReq();
|
||||
|
||||
// st1 already exists
|
||||
setCreateStreamReq(
|
||||
"s1", "test",
|
||||
"create stream s1 into st1 tags(tag2) as select max(c1), c2 from t1 partition by tbname tag2 interval(10s)",
|
||||
"st1");
|
||||
setStreamOptions(STREAM_CREATE_STABLE_FALSE);
|
||||
run("CREATE STREAM s1 INTO st1 TAGS(tag2) AS SELECT MAX(c1), c2 FROM t1 PARTITION BY TBNAME tag2 INTERVAL(10S)");
|
||||
clearCreateStreamReq();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* CREATE MNODE ON DNODE dnode_id
|
||||
*/
|
||||
|
|
|
@ -568,6 +568,7 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
if (TSDB_CODE_SUCCESS == code && NULL != pColList) {
|
||||
code = createColumnByRewriteExprs(pColList, &pJoin->node.pTargets);
|
||||
}
|
||||
nodesDestroyList(pColList);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -587,6 +588,7 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
if (TSDB_CODE_SUCCESS == code && NULL != pColList) {
|
||||
code = createColumnByRewriteExprs(pColList, &pJoin->node.pTargets);
|
||||
}
|
||||
nodesDestroyList(pColList);
|
||||
}
|
||||
|
||||
if (NULL == pJoin->node.pTargets && NULL != pLeft) {
|
||||
|
|
|
@ -286,6 +286,24 @@ int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) {
|
||||
if (NULL == msg || NULL == msgLen) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
SViewMetaReq req = {0};
|
||||
strncpy(req.fullname, input, sizeof(req.fullname) - 1);
|
||||
|
||||
int32_t bufLen = tSerializeSViewMetaReq(NULL, 0, &req);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSViewMetaReq(pBuf, bufLen, &req);
|
||||
|
||||
*msg = pBuf;
|
||||
*msgLen = bufLen;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) {
|
||||
SUseDbOutput *pOut = output;
|
||||
SUseDbRsp usedbRsp = {0};
|
||||
|
@ -637,6 +655,27 @@ int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) {
|
||||
if (NULL == output || NULL == msg || msgSize <= 0) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
SViewMetaRsp *out = taosMemoryCalloc(1, sizeof(SViewMetaRsp));
|
||||
if (tDeserializeSViewMetaRsp(msg, msgSize, out) != 0) {
|
||||
qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize);
|
||||
tFreeSViewMetaRsp(out);
|
||||
taosMemoryFree(out);
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
qDebugL("view meta recved, dbFName:%s, view:%s, querySQL:%s", out->dbFName, out->name, out->querySql);
|
||||
|
||||
*(SViewMetaRsp **)output = out;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void initQueryModuleMsgHandle() {
|
||||
queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg;
|
||||
queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg;
|
||||
|
@ -651,6 +690,7 @@ void initQueryModuleMsgHandle() {
|
|||
queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
|
||||
queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryBuildGetTbCfgMsg;
|
||||
queryBuildMsg[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryBuildGetSerVerMsg;
|
||||
queryBuildMsg[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryBuildGetViewMetaMsg;
|
||||
|
||||
queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp;
|
||||
queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp;
|
||||
|
@ -665,6 +705,7 @@ void initQueryModuleMsgHandle() {
|
|||
queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
|
||||
queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_CFG)] = queryProcessGetTbCfgRsp;
|
||||
queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_SERVER_VERSION)] = queryProcessGetSerVerRsp;
|
||||
queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_VIEW_META)] = queryProcessGetViewMetaRsp;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
|
|
@ -1543,6 +1543,15 @@ EDealRes fltTreeToGroup(SNode *pNode, void *pContext) {
|
|||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
|
||||
if (QUERY_NODE_VALUE == nType && ((SValueNode*)pNode)->node.resType.type == TSDB_DATA_TYPE_BOOL) {
|
||||
if (((SValueNode*)pNode)->datum.b) {
|
||||
FILTER_SET_FLAG(ctx->info->status, FI_STATUS_ALL);
|
||||
} else {
|
||||
FILTER_SET_FLAG(ctx->info->status, FI_STATUS_EMPTY);
|
||||
}
|
||||
return DEAL_RES_END;
|
||||
}
|
||||
|
||||
fltError("invalid node type for filter, type:%d", nodeType(pNode));
|
||||
|
||||
code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
|
@ -3450,7 +3459,9 @@ int32_t fltInitFromNode(SNode *tree, SFilterInfo *info, uint32_t options) {
|
|||
return code;
|
||||
|
||||
_return:
|
||||
qInfo("init from node failed, code:%d", code);
|
||||
if (code) {
|
||||
qInfo("init from node failed, code:%d", code);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -317,6 +317,11 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_SMA_ALREADY_EXIST, "index already exists
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_SMA_NOT_EXIST, "index not exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SMA_OPTION, "Invalid sma index option")
|
||||
|
||||
// mnode-view
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_VIEW_ALREADY_EXIST, "view already exists in db")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_VIEW_NOT_EXIST, "view not exists in db")
|
||||
|
||||
|
||||
// dnode
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_DNODE_OFFLINE, "Dnode is offline")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MNODE_NOT_FOUND, "Mnode not found")
|
||||
|
@ -590,6 +595,10 @@ TAOS_DEFINE_ERROR(TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED, "System table not al
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_VARBINARY, "Invalidate varbinary value")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_IP_RANGE, "Invalid IPV4 address ranges")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTERNAL_ERROR, "Parser internal error")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Invalid stream query")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_VIEW_QUERY, "Invalid view query type")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_COL_QUERY_MISMATCH, "Columns number mismatch with query result")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_VIEW_CONFLICT_WITH_TABLE, "View name is conflict with table")
|
||||
|
||||
//planner
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_PLAN_INTERNAL_ERROR, "Planner internal error")
|
||||
|
|
|
@ -65,7 +65,7 @@ class TDTestCase:
|
|||
|
||||
tdSql.query('select count(*),db_name, stable_name from information_schema.ins_tables group by db_name, stable_name;')
|
||||
tdSql.checkRows(3)
|
||||
tdSql.checkData(0, 0, 23)
|
||||
tdSql.checkData(0, 0, 24)
|
||||
tdSql.checkData(0, 1, 'information_schema')
|
||||
tdSql.checkData(0, 2, None)
|
||||
tdSql.checkData(1, 0, 3)
|
||||
|
@ -77,7 +77,7 @@ class TDTestCase:
|
|||
|
||||
tdSql.query('select count(1) v,db_name, stable_name from information_schema.ins_tables group by db_name, stable_name order by v desc;')
|
||||
tdSql.checkRows(3)
|
||||
tdSql.checkData(0, 0, 23)
|
||||
tdSql.checkData(0, 0, 24)
|
||||
tdSql.checkData(0, 1, 'information_schema')
|
||||
tdSql.checkData(0, 2, None)
|
||||
tdSql.checkData(1, 0, 5)
|
||||
|
@ -93,7 +93,7 @@ class TDTestCase:
|
|||
tdSql.checkData(1, 1, 'performance_schema')
|
||||
tdSql.checkData(0, 0, 3)
|
||||
tdSql.checkData(0, 1, 'tbl_count')
|
||||
tdSql.checkData(2, 0, 23)
|
||||
tdSql.checkData(2, 0, 24)
|
||||
tdSql.checkData(2, 1, 'information_schema')
|
||||
|
||||
tdSql.query("select count(*) from information_schema.ins_tables where db_name='tbl_count'")
|
||||
|
@ -106,7 +106,7 @@ class TDTestCase:
|
|||
|
||||
tdSql.query('select count(*) from information_schema.ins_tables')
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0, 0, 31)
|
||||
tdSql.checkData(0, 0, 32)
|
||||
|
||||
|
||||
tdSql.execute('create table stba (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(10), c9 nchar(10), c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned) TAGS(t1 int, t2 binary(10), t3 double);')
|
||||
|
@ -189,7 +189,7 @@ class TDTestCase:
|
|||
tdSql.checkData(2, 0, 5)
|
||||
tdSql.checkData(2, 1, 'performance_schema')
|
||||
tdSql.checkData(2, 2, None)
|
||||
tdSql.checkData(3, 0, 23)
|
||||
tdSql.checkData(3, 0, 24)
|
||||
tdSql.checkData(3, 1, 'information_schema')
|
||||
tdSql.checkData(3, 2, None)
|
||||
|
||||
|
@ -204,7 +204,7 @@ class TDTestCase:
|
|||
tdSql.checkData(2, 0, 5)
|
||||
tdSql.checkData(2, 1, 'performance_schema')
|
||||
tdSql.checkData(2, 2, None)
|
||||
tdSql.checkData(3, 0, 23)
|
||||
tdSql.checkData(3, 0, 24)
|
||||
tdSql.checkData(3, 1, 'information_schema')
|
||||
tdSql.checkData(3, 2, None)
|
||||
|
||||
|
@ -215,7 +215,7 @@ class TDTestCase:
|
|||
tdSql.checkData(0, 1, 'tbl_count')
|
||||
tdSql.checkData(1, 0, 5)
|
||||
tdSql.checkData(1, 1, 'performance_schema')
|
||||
tdSql.checkData(2, 0, 23)
|
||||
tdSql.checkData(2, 0, 24)
|
||||
tdSql.checkData(2, 1, 'information_schema')
|
||||
|
||||
tdSql.query("select count(*) from information_schema.ins_tables where db_name='tbl_count'")
|
||||
|
@ -228,7 +228,7 @@ class TDTestCase:
|
|||
|
||||
tdSql.query('select count(*) from information_schema.ins_tables')
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0, 0, 32)
|
||||
tdSql.checkData(0, 0, 33)
|
||||
|
||||
|
||||
tdSql.execute('drop database tbl_count')
|
||||
|
|
|
@ -1285,6 +1285,7 @@ e
|
|||
,,y,script,./test.sh -f tmp/monitor.sim
|
||||
,,y,script,./test.sh -f tsim/tagindex/add_index.sim
|
||||
,,n,script,./test.sh -f tsim/tagindex/sma_and_tag_index.sim
|
||||
,,y,script,./test.sh -f tsim/view/view.sim
|
||||
|
||||
|
||||
#develop test
|
||||
|
|
|
@ -17,6 +17,7 @@ exe:
|
|||
gcc $(CFLAGS) ./insertSameTs.c -o $(ROOT)insertSameTs $(LFLAGS)
|
||||
gcc $(CFLAGS) ./passwdTest.c -o $(ROOT)passwdTest $(LFLAGS)
|
||||
gcc $(CFLAGS) ./whiteListTest.c -o $(ROOT)whiteListTest $(LFLAGS)
|
||||
gcc $(CFLAGS) ./tmqViewTest.c -o $(ROOT)tmqViewTest $(LFLAGS)
|
||||
|
||||
clean:
|
||||
rm $(ROOT)batchprepare
|
||||
|
@ -25,3 +26,4 @@ clean:
|
|||
rm $(ROOT)insertSameTs
|
||||
rm $(ROOT)passwdTest
|
||||
rm $(ROOT)whiteListTest
|
||||
rm $(ROOT)tmqViewTest
|
||||
|
|
|
@ -0,0 +1,341 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "taos.h"
|
||||
|
||||
static int running = 1;
|
||||
const char* topic_name = "topicname";
|
||||
|
||||
static int32_t msg_process(TAOS_RES* msg) {
|
||||
char buf[1024];
|
||||
int32_t rows = 0;
|
||||
|
||||
const char* topicName = tmq_get_topic_name(msg);
|
||||
const char* dbName = tmq_get_db_name(msg);
|
||||
int32_t vgroupId = tmq_get_vgroup_id(msg);
|
||||
|
||||
printf("topic: %s\n", topicName);
|
||||
printf("db: %s\n", dbName);
|
||||
printf("vgroup id: %d\n", vgroupId);
|
||||
|
||||
while (1) {
|
||||
TAOS_ROW row = taos_fetch_row(msg);
|
||||
if (row == NULL) break;
|
||||
|
||||
TAOS_FIELD* fields = taos_fetch_fields(msg);
|
||||
int32_t numOfFields = taos_field_count(msg);
|
||||
// int32_t* length = taos_fetch_lengths(msg);
|
||||
int32_t precision = taos_result_precision(msg);
|
||||
rows++;
|
||||
taos_print_row(buf, row, fields, numOfFields);
|
||||
printf("precision: %d, row content: %s\n", precision, buf);
|
||||
}
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
static int32_t init_env() {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
if (pConn == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
TAOS_RES* pRes;
|
||||
// drop database if exists
|
||||
printf("create database\n");
|
||||
pRes = taos_query(pConn, "drop topic topicname");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in drop topicname, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "drop database if exists tmqdb");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in drop tmqdb, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
// create database
|
||||
pRes = taos_query(pConn, "create database tmqdb precision 'ns' WAL_RETENTION_PERIOD 3600");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create tmqdb, reason:%s\n", taos_errstr(pRes));
|
||||
goto END;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
// create super table
|
||||
printf("create super table\n");
|
||||
pRes = taos_query(
|
||||
pConn, "create table tmqdb.stb (ts timestamp, c1 int, c2 float, c3 varchar(16)) tags(t1 int, t3 varchar(16))");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table stb, reason:%s\n", taos_errstr(pRes));
|
||||
goto END;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
// create sub tables
|
||||
printf("create sub tables\n");
|
||||
pRes = taos_query(pConn, "create table tmqdb.ctb0 using tmqdb.stb tags(0, 'subtable0')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table ctb0, reason:%s\n", taos_errstr(pRes));
|
||||
goto END;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table tmqdb.ctb1 using tmqdb.stb tags(1, 'subtable1')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table ctb1, reason:%s\n", taos_errstr(pRes));
|
||||
goto END;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table tmqdb.ctb2 using tmqdb.stb tags(2, 'subtable2')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table ctb2, reason:%s\n", taos_errstr(pRes));
|
||||
goto END;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table tmqdb.ctb3 using tmqdb.stb tags(3, 'subtable3')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table ctb3, reason:%s\n", taos_errstr(pRes));
|
||||
goto END;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
// insert data
|
||||
printf("insert data into sub tables\n");
|
||||
pRes = taos_query(pConn, "insert into tmqdb.ctb0 values(now, 0, 0, 'a0')(now+1s, 0, 0, 'a00')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into ctb0, reason:%s\n", taos_errstr(pRes));
|
||||
goto END;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into tmqdb.ctb1 values(now, 1, 1, 'a1')(now+1s, 11, 11, 'a11')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into ctb0, reason:%s\n", taos_errstr(pRes));
|
||||
goto END;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into tmqdb.ctb2 values(now, 2, 2, 'a1')(now+1s, 22, 22, 'a22')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into ctb0, reason:%s\n", taos_errstr(pRes));
|
||||
goto END;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "insert into tmqdb.ctb3 values(now, 3, 3, 'a1')(now+1s, 33, 33, 'a33')");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to insert into ctb0, reason:%s\n", taos_errstr(pRes));
|
||||
goto END;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create or replace view tmqdb.view1 as select ts, c1, t1 from tmqdb.stb");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create view, reason:%s\n", taos_errstr(pRes));
|
||||
goto END;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
taos_close(pConn);
|
||||
return 0;
|
||||
|
||||
END:
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t create_topic() {
|
||||
printf("create topic\n");
|
||||
TAOS_RES* pRes;
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
if (pConn == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pRes = taos_query(pConn, "use tmqdb");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in use tmqdb, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create topic topicname as select * from tmqdb.view1 where c1 > 1 and c1 <= 22");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create topic topicname, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
taos_close(pConn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tmq_commit_cb_print(tmq_t* tmq, int32_t code, void* param) {
|
||||
printf("tmq_commit_cb_print() code: %d, tmq: %p, param: %p\n", code, tmq, param);
|
||||
}
|
||||
|
||||
tmq_t* build_consumer() {
|
||||
tmq_conf_res_t code;
|
||||
tmq_t* tmq = NULL;
|
||||
|
||||
tmq_conf_t* conf = tmq_conf_new();
|
||||
code = tmq_conf_set(conf, "enable.auto.commit", "true");
|
||||
if (TMQ_CONF_OK != code) {
|
||||
tmq_conf_destroy(conf);
|
||||
return NULL;
|
||||
}
|
||||
code = tmq_conf_set(conf, "auto.commit.interval.ms", "1000");
|
||||
if (TMQ_CONF_OK != code) {
|
||||
tmq_conf_destroy(conf);
|
||||
return NULL;
|
||||
}
|
||||
code = tmq_conf_set(conf, "group.id", "cgrpName");
|
||||
if (TMQ_CONF_OK != code) {
|
||||
tmq_conf_destroy(conf);
|
||||
return NULL;
|
||||
}
|
||||
code = tmq_conf_set(conf, "client.id", "user defined name");
|
||||
if (TMQ_CONF_OK != code) {
|
||||
tmq_conf_destroy(conf);
|
||||
return NULL;
|
||||
}
|
||||
code = tmq_conf_set(conf, "td.connect.user", "root");
|
||||
if (TMQ_CONF_OK != code) {
|
||||
tmq_conf_destroy(conf);
|
||||
return NULL;
|
||||
}
|
||||
code = tmq_conf_set(conf, "td.connect.pass", "taosdata");
|
||||
if (TMQ_CONF_OK != code) {
|
||||
tmq_conf_destroy(conf);
|
||||
return NULL;
|
||||
}
|
||||
code = tmq_conf_set(conf, "auto.offset.reset", "earliest");
|
||||
if (TMQ_CONF_OK != code) {
|
||||
tmq_conf_destroy(conf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL);
|
||||
tmq = tmq_consumer_new(conf, NULL, 0);
|
||||
|
||||
_end:
|
||||
tmq_conf_destroy(conf);
|
||||
return tmq;
|
||||
}
|
||||
|
||||
tmq_list_t* build_topic_list() {
|
||||
tmq_list_t* topicList = tmq_list_new();
|
||||
int32_t code = tmq_list_append(topicList, topic_name);
|
||||
if (code) {
|
||||
tmq_list_destroy(topicList);
|
||||
return NULL;
|
||||
}
|
||||
return topicList;
|
||||
}
|
||||
|
||||
void basic_consume_loop(tmq_t* tmq) {
|
||||
int32_t totalRows = 0;
|
||||
int32_t msgCnt = 0;
|
||||
int32_t timeout = 5000;
|
||||
while (running) {
|
||||
TAOS_RES* tmqmsg = tmq_consumer_poll(tmq, timeout);
|
||||
if (tmqmsg) {
|
||||
msgCnt++;
|
||||
totalRows += msg_process(tmqmsg);
|
||||
taos_free_result(tmqmsg);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "%d msg consumed, include %d rows\n", msgCnt, totalRows);
|
||||
}
|
||||
|
||||
void consume_repeatly(tmq_t* tmq) {
|
||||
int32_t numOfAssignment = 0;
|
||||
tmq_topic_assignment* pAssign = NULL;
|
||||
|
||||
int32_t code = tmq_get_topic_assignment(tmq, topic_name, &pAssign, &numOfAssignment);
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "failed to get assignment, reason:%s", tmq_err2str(code));
|
||||
}
|
||||
|
||||
// seek to the earliest offset
|
||||
for(int32_t i = 0; i < numOfAssignment; ++i) {
|
||||
tmq_topic_assignment* p = &pAssign[i];
|
||||
|
||||
code = tmq_offset_seek(tmq, topic_name, p->vgId, p->begin);
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "failed to seek to %d, reason:%s", (int)p->begin, tmq_err2str(code));
|
||||
}
|
||||
}
|
||||
|
||||
tmq_free_assignment(pAssign);
|
||||
|
||||
// let's do it again
|
||||
basic_consume_loop(tmq);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int32_t code;
|
||||
|
||||
if (init_env() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (create_topic() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmq_t* tmq = build_consumer();
|
||||
if (NULL == tmq) {
|
||||
fprintf(stderr, "build_consumer() fail!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmq_list_t* topic_list = build_topic_list();
|
||||
if (NULL == topic_list) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((code = tmq_subscribe(tmq, topic_list))) {
|
||||
fprintf(stderr, "Failed to tmq_subscribe(): %s\n", tmq_err2str(code));
|
||||
}
|
||||
|
||||
tmq_list_destroy(topic_list);
|
||||
|
||||
basic_consume_loop(tmq);
|
||||
|
||||
consume_repeatly(tmq);
|
||||
|
||||
code = tmq_consumer_close(tmq);
|
||||
if (code) {
|
||||
fprintf(stderr, "Failed to close consumer: %s\n", tmq_err2str(code));
|
||||
} else {
|
||||
fprintf(stderr, "Consumer closed\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -58,7 +58,7 @@ endi
|
|||
|
||||
sql select tbname from information_schema.ins_tables;
|
||||
print $rows $data00
|
||||
if $rows != 32 then
|
||||
if $rows != 33 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @ins_tables@ then
|
||||
|
|
|
@ -53,7 +53,7 @@ sql select stable_name,count(table_name) from information_schema.ins_tables grou
|
|||
if $rows != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 29 then
|
||||
if $data01 != 30 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 != 10 then
|
||||
|
@ -72,7 +72,7 @@ endi
|
|||
if $data11 != 5 then
|
||||
return -1
|
||||
endi
|
||||
if $data21 != 23 then
|
||||
if $data21 != 24 then
|
||||
return -1
|
||||
endi
|
||||
if $data31 != 5 then
|
||||
|
@ -97,7 +97,7 @@ endi
|
|||
if $data42 != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data52 != 23 then
|
||||
if $data52 != 24 then
|
||||
return -1
|
||||
endi
|
||||
if $data62 != 5 then
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
sql connect
|
||||
sql use testa;
|
||||
|
||||
sql create view view1 as select * from sta1;
|
||||
sql drop view view1;
|
||||
|
||||
sql create or replace view view2 as select f from cta11;
|
||||
sql_error create view view2 as select * from cta11;
|
||||
sql drop view if exists view2;
|
||||
sql drop view if exists view3;
|
||||
sql_error drop view view2;
|
||||
sql_error drop view view3;
|
||||
|
||||
sql create view view3 as select avg(f) from st2;
|
||||
sql create or replace view view3 as select f fa from st2;
|
||||
sql_error create view view3 as select * from st2;
|
||||
sql create view view4 as select * from view3;
|
||||
sql create or replace view view4 as select fa from view3;
|
||||
sql drop view view3;
|
||||
sql_error create view view5 as select * from view3;
|
||||
sql drop view view4;
|
||||
|
||||
sql create view testa.view1 as select * from testa.sta1;
|
||||
sql create view testa.view2 as select * from testb.st2;
|
||||
sql create view testb.view1 as select * from testb.stb1;
|
||||
sql create view testb.view2 as select * from testa.st2;
|
||||
sql drop view view1;
|
||||
sql drop view view2;
|
||||
sql drop view testb.view1;
|
||||
sql drop view testb.view2;
|
||||
|
||||
sql_error create view view1 as show tables;
|
||||
sql_error create view view1 as desc sta1;
|
||||
sql_error create view view1 as select * from st;
|
||||
sql_error create view view1 as select count(*) from sta1 group by f interval(1s);
|
||||
|
||||
sql use information_schema;
|
||||
sql create view view1 as select * from ins_tables;
|
||||
sql drop view view1;
|
||||
sql create view information_schema.view1 as select * from ins_tags;
|
||||
sql drop view information_schema.view1;
|
||||
|
||||
sql use testa
|
||||
sql_error create view testb.view1 as select * from sta1;
|
||||
sql create view testb.view1 as select * from stb1;
|
||||
sql_error drop view view1
|
||||
sql drop view testb.view1
|
|
@ -0,0 +1,15 @@
|
|||
sql connect
|
||||
sql use testa;
|
||||
|
||||
sql create view view1 as select * from cta11;
|
||||
sql_error insert into view1 values (now, 1);
|
||||
sql create table ctat using sta1 tags(1);
|
||||
sql insert into ctat select * from view1;
|
||||
sql drop view view1;
|
||||
sql drop table ctat;
|
||||
|
||||
sql use information_schema;
|
||||
sql create view view1 as select * from ins_dnodes;
|
||||
sql_error insert into ins_dnodes select * from view1;
|
||||
sql drop view view1;
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
sql connect
|
||||
sql use testa;
|
||||
|
||||
sql create user u1 pass "taosdata"
|
||||
sql create user u2 pass "taosdata"
|
||||
sql create user u3 pass "taosdata"
|
||||
|
||||
print == root create views ==
|
||||
sql create view view1 as select * from sta1;
|
||||
sql create view view2 as select * from view1;
|
||||
sql create view view3 as select * from view2;
|
||||
|
||||
sql_error grant all on view1 to root;
|
||||
sql_error revoke all on view1 from root;
|
||||
|
||||
sql_error grant read on view1 to u1;
|
||||
sql grant read on testa.view1 to u1;
|
||||
|
||||
sql select * from information_schema.ins_user_privileges order by user_name, privilege;
|
||||
if $rows != 2 then
|
||||
return -1
|
||||
endi
|
||||
if $data10 != u1 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 != read then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql connect u1
|
||||
sql use testa
|
||||
sql_error select * from sta1;
|
||||
sql select * from view1;
|
||||
sql_error select * from view2;
|
||||
sql_error select * from testb.view1;
|
||||
sql_error insert into view1 values (now, 1);
|
||||
sql_error create or replace view1 as select * from st2;
|
||||
sql_error create viewa as select * from sta1;
|
||||
sql_error drop view view1;
|
||||
sql show views;
|
||||
sql show create view view1;
|
||||
sql desc view1;
|
||||
sql select * from information_schema.ins_views;
|
||||
if $rows != 3 then
|
||||
return -1
|
||||
endi
|
||||
sql_error grant read on testa.view1 to u2;
|
||||
sql_error revoke read on testa.view1 from u1;
|
||||
|
||||
sql connect root
|
||||
sql use testa
|
||||
sql drop view testa.view1;
|
||||
sql select * from information_schema.ins_user_privileges order by user_name, privilege;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != root then
|
||||
return -1
|
||||
endi
|
||||
sql grant all on testa.* to u1;
|
||||
sql reset query cache
|
||||
|
||||
print == u1 create view1 ==
|
||||
sql connect u1
|
||||
sql use testa
|
||||
sql select * from sta1;
|
||||
sql_error insert into view1 values (now, 1);
|
||||
sql create view view1 as select * from sta1;
|
||||
|
||||
sql connect root
|
||||
sql grant read on testa.view1 to u2;
|
||||
sql_error insert into view1 values (now, 1);
|
||||
|
||||
sql connect u2
|
||||
sql use testa
|
||||
sql_error select * from sta1;
|
||||
sql_error insert into view1 values (now, 1);
|
||||
sql select * from view1;
|
||||
|
||||
sql connect root
|
||||
sql revoke all on testa.* from u1
|
||||
sql reset query cache
|
||||
|
||||
sql connect u1
|
||||
sql use testa
|
||||
sql_error select * from sta1;
|
||||
sql_error select * from view1;
|
||||
|
||||
sql connect u2
|
||||
sql use testa
|
||||
sql_error select * from view1;
|
||||
|
||||
sql connect root
|
||||
sql grant all on testa.* to u2
|
||||
sql reset query cache
|
||||
|
||||
sql connect u2
|
||||
sql use testa
|
||||
sql select * from view1;
|
||||
sql_error create or replace view1 as select * from st2;
|
||||
|
||||
sql connect u1
|
||||
sql use testa
|
||||
sql_error create or replace view1 as select * from st2;
|
||||
|
||||
sql connect root
|
||||
sql grant all on testa.* to u1
|
||||
sql reset query cache
|
||||
|
||||
sql connect u1
|
||||
sql use testa
|
||||
sql create or replace view view1 as select * from st2;
|
||||
|
||||
sql connect root
|
||||
sql grant alter on testa.view1 to u2
|
||||
sql revoke all on testa.* from u1
|
||||
sql reset query cache
|
||||
|
||||
print == u2 replace view1 ==
|
||||
sql connect u2
|
||||
sql use testa
|
||||
sql select * from view1;
|
||||
sql create or replace view view1 as select * from sta1;
|
||||
sql_error insert into view1 values (now, 1);
|
||||
sql select * from information_schema.ins_views where view_name = 'view1';
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != testa then
|
||||
return -1
|
||||
endi
|
||||
if $data02 != u2 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql connect root
|
||||
sql grant all on testa.view1 to u3;
|
||||
|
||||
sql connect u3
|
||||
sql use testa
|
||||
sql_error select * from sta1
|
||||
sql_error insert into view1 values (now, 1);
|
||||
sql select * from view1
|
||||
|
||||
sql connect root
|
||||
sql revoke all on testa.* from u2
|
||||
sql reset query cache
|
||||
|
||||
sql connect u3
|
||||
sql use testa
|
||||
sql_error select * from view1
|
||||
sql_error insert into view1 values (now, 1);
|
||||
|
||||
sql connect root
|
||||
sql grant all on testa.* to u3
|
||||
sql drop user u1;
|
||||
sql drop user u2;
|
||||
sql reset query cache
|
||||
|
||||
sql connect u3
|
||||
sql use testa
|
||||
sql select * from view1
|
||||
sql_error insert into view1 values (now, 1);
|
||||
|
||||
sql connect root
|
||||
sql drop user u3;
|
||||
sql drop view testa.view1;
|
||||
sql drop view testa.view2;
|
||||
sql drop view testa.view3;
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
sql connect
|
||||
sql use testa;
|
||||
|
||||
sql create user u1 pass "taosdata"
|
||||
sql create user u2 pass "taosdata"
|
||||
sql create user u3 pass "taosdata"
|
||||
|
||||
sql grant all on testa.* to u1;
|
||||
sql grant all on testb.* to u2;
|
||||
sql grant all on testa.stt to u3;
|
||||
|
||||
sql connect u1
|
||||
sql use testa
|
||||
sql create view view1 as select ts, f from st2;
|
||||
|
||||
sql connect u2
|
||||
sql use testb
|
||||
sql create view view1 as select ts, f from st2;
|
||||
|
||||
sql connect root
|
||||
sql use testa
|
||||
sql_error create view view2 as select * from view1 union all select * from view2;
|
||||
sql create view view2 as select * from view1 union all select * from testb.view1;
|
||||
sql use testb
|
||||
sql create view view2 as select a.ts, a.f, b.f from testa.view1 a, view1 b where a.ts=b.ts;
|
||||
sql grant all on testa.view2 to u3;
|
||||
sql grant all on testb.view2 to u3;
|
||||
|
||||
print == start to query ==
|
||||
sql connect u3
|
||||
sql reset query cache
|
||||
sql select * from testa.view2 order by f;
|
||||
if $rows != 8 then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 100221 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 != 100222 then
|
||||
return -1
|
||||
endi
|
||||
if $data21 != 100223 then
|
||||
return -1
|
||||
endi
|
||||
if $data31 != 100224 then
|
||||
return -1
|
||||
endi
|
||||
if $data41 != 110221 then
|
||||
return -1
|
||||
endi
|
||||
if $data51 != 110222 then
|
||||
return -1
|
||||
endi
|
||||
if $data61 != 110223 then
|
||||
return -1
|
||||
endi
|
||||
if $data71 != 110224 then
|
||||
return -1
|
||||
endi
|
||||
sql_error insert into tt (ts, f) select * from testa.view1;
|
||||
sql_error insert into tt (ts, f) select * from testb.view1;
|
||||
sql insert into testa.tt (ts, f) select * from testa.view2 order by ts, f;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
# insert result is not correct now
|
||||
#if $data01 != 110221 then
|
||||
# print $data01
|
||||
# return -1
|
||||
#endi
|
||||
#if $data11 != 110222 then
|
||||
# print $data11
|
||||
# return -1
|
||||
#endi
|
||||
sql delete from testa.tt;
|
||||
sql_error select * from testa.st2;
|
||||
sql_error select * from testb.st2;
|
||||
|
||||
sql connect root
|
||||
sql revoke all on testa.* from u1;
|
||||
|
||||
sql connect u3
|
||||
sql reset query cache
|
||||
sql_error select * from testa.view2;
|
||||
sql_error select * from testa.view1;
|
||||
|
||||
sql connect root
|
||||
sql use testb;
|
||||
sql create or replace view testa.view1 as select ts, f from st2;
|
||||
sql select * from testa.view1 order by ts;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 100221 then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
if $data11 != 100222 then
|
||||
print $data11
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql connect u3
|
||||
sql reset query cache
|
||||
sql select * from testa.view2;
|
||||
sql_error select * from testa.view1;
|
||||
|
||||
print == drop user and views ==
|
||||
sql connect root
|
||||
sql drop user u1;
|
||||
sql drop user u2;
|
||||
sql drop user u3;
|
||||
sql drop view testa.view1;
|
||||
sql drop view testb.view1;
|
||||
sql drop view testa.view2;
|
||||
sql drop view testb.view2;
|
||||
|
|
@ -0,0 +1,238 @@
|
|||
sql connect
|
||||
sql use testa;
|
||||
|
||||
sql create view view1 as select * from sta1;
|
||||
sql explain select * from view1 order by ts;
|
||||
sql explain analyze select * from view1 order by ts;
|
||||
sql select * from view1 order by ts;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @23-10-16 09:10:11.000@ then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 100111 then
|
||||
return -1
|
||||
endi
|
||||
sql select ts from view1 order by ts;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @23-10-16 09:10:11.000@ then
|
||||
return -1
|
||||
endi
|
||||
sql select view1.ts from view1 order by view1.ts;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @23-10-16 09:10:11.000@ then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql create or replace view view1 as select 1, 2;
|
||||
sql explain select * from view1;
|
||||
sql explain analyze select * from view1;
|
||||
sql select * from view1;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 2 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql create or replace view view1 as select tbname as a, f from sta1;
|
||||
sql explain select cast(avg(f) as int) b from view1 group by a having avg(f) > 100111 order by b;
|
||||
sql explain analyze select cast(avg(f) as int) b from view1 group by a having avg(f) > 100111 order by b;
|
||||
sql select cast(avg(f) as int) b from view1 group by a having avg(f) > 100111 order by b;
|
||||
if $rows != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 100112 then
|
||||
return -1
|
||||
endi
|
||||
if $data10 != 100113 then
|
||||
return -1
|
||||
endi
|
||||
if $data20 != 100114 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql create or replace view view1 as select tbname, avg(f) from sta1 partition by tbname;
|
||||
sql explain select * from view1 partition by view1.tbname;
|
||||
sql explain analyze select * from view1 partition by view1.tbname;
|
||||
sql select * from view1 partition by view1.tbname;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql create or replace view view1 as select * from sta1;
|
||||
sql create or replace view testb.view2 as select * from testb.stb1;
|
||||
sql_error explain select avg(t1.f), avg(t2.f) from view1 t1, view2 t2 where t1.ts = t2.ts and t1.f < 100114;
|
||||
sql_error explain analyze select avg(t1.f), avg(t2.f) from view1 t1, view2 t2 where t1.ts = t2.ts and t1.f < 100114;
|
||||
sql_error select avg(t1.f), avg(t2.f) from view1 t1, view2 t2 where t1.ts = t2.ts and t1.f < 100114;
|
||||
sql explain select avg(t1.f), avg(t2.f) from view1 t1, testb.view2 t2 where t1.ts = t2.ts and t1.f < 100114;
|
||||
sql explain analyze select avg(t1.f), avg(t2.f) from view1 t1, testb.view2 t2 where t1.ts = t2.ts and t1.f < 100114;
|
||||
sql select avg(t1.f), avg(t2.f) from view1 t1, testb.view2 t2 where t1.ts = t2.ts and t1.f < 100114;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 100112.000000000 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 110112.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql create or replace view view3 as select t1.ts ts, t1.f a1, t2.f a2 from view1 t1, testb.view2 t2 where t1.ts = t2.ts;
|
||||
sql create or replace view view4 as select t1.ts ts, t1.f a1, t2.f a2 from testa.st2 t1, testb.st2 t2 where t1.ts = t2.ts;
|
||||
sql create view view5 as select t3.ts, cast((t3.a1 + t4.a1) as bigint), cast((t3.a2 - t4.a2) as bigint) from view3 t3, view4 t4 where t3.ts = t4.ts order by t3.ts;
|
||||
sql explain select * from view5;
|
||||
sql explain analyze select * from view5;
|
||||
sql select * from view5;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @23-10-16 09:10:11.000@ then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 200332 then
|
||||
return -1
|
||||
endi
|
||||
if $data02 != -110 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 != 200334 then
|
||||
return -1
|
||||
endi
|
||||
if $data21 != 200336 then
|
||||
return -1
|
||||
endi
|
||||
if $data31 != 200338 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql drop view view1;
|
||||
sql drop view testb.view2;
|
||||
sql drop view view3;
|
||||
sql drop view view4;
|
||||
sql drop view view5;
|
||||
|
||||
sql create or replace view view1 as select * from sta1;
|
||||
sql create or replace view view2 as select * from st2;
|
||||
sql explain select avg(view1.f), avg(view2.f) from view1, view2 where view1.ts = view2.ts and view1.f < 100114;
|
||||
sql explain analyze select avg(view1.f), avg(view2.f) from view1, view2 where view1.ts = view2.ts and view1.f < 100114;
|
||||
sql select avg(view1.f), avg(view2.f) from view1, view2 where view1.ts = view2.ts and view1.f < 100114;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 100112.000000000 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 100222.000000000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql drop view view1;
|
||||
sql drop view view2;
|
||||
|
||||
sql create view view1 as select * from sta1;
|
||||
sql create view view2 as select * from st2;
|
||||
sql create view view3 as select a.ts ts, a.f af, b.f bf from view1 a join view2 b on a.ts = b.ts;
|
||||
sql create view view3a as select a.ts ts, a.f, b.f from view1 a join view2 b on a.ts = b.ts;
|
||||
sql create view view4 as select _wstart, avg(bf) - avg(af) as b from view3 interval(1s);
|
||||
sql_error create view view4a as select _wstart, avg(b.f) - avg(a.f) as b from view3 interval(1s);
|
||||
sql create view view5 as select count(*),avg(b) from view4 interval(1s) having avg(b) > 0;
|
||||
sql explain select * from view5;
|
||||
sql explain analyze select * from view5;
|
||||
sql select * from view5;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 1 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 110.000000000 then
|
||||
return -1
|
||||
endi
|
||||
sql drop view view1;
|
||||
sql drop view view2;
|
||||
sql drop view view3;
|
||||
sql drop view view3a;
|
||||
sql drop view view4;
|
||||
sql drop view view5;
|
||||
|
||||
sql use information_schema;
|
||||
sql create view view1 as select * from ins_views;
|
||||
sql explain select * from view1;
|
||||
sql explain analyze select * from view1;
|
||||
sql select * from view1;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
sql drop view view1;
|
||||
sql use testa;
|
||||
sql create view information_schema.view1 as select * from information_schema.ins_views;
|
||||
sql explain select * from information_schema.view1;
|
||||
sql explain analyze select * from information_schema.view1;
|
||||
sql select * from information_schema.view1;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
sql drop view information_schema.view1;
|
||||
|
||||
sql use testa;
|
||||
sql create view view1 as select * from st2;
|
||||
sql use testb;
|
||||
sql explain select f from testa.view1 order by f;
|
||||
sql explain analyze select f from testa.view1 order by f;
|
||||
sql select f from testa.view1 order by f;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 100221 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
if $data10 != 100222 then
|
||||
return -1
|
||||
endi
|
||||
sql drop view testa.view1;
|
||||
|
||||
sql use performance_schema;
|
||||
sql create view view1 as select 1;
|
||||
sql create view view2 as select 2;
|
||||
sql create view view3 as select server_status();
|
||||
sql create view view4 as select conn_id from perf_connections where 0>1;
|
||||
sql create view view5 as select abs(-1) a;
|
||||
sql create view view6 as select 1 union select conn_id from perf_connections;
|
||||
sql create view view7 as select 1 union select conn_id from perf_connections where 0>1;
|
||||
sql create view view8 as select 1 union all select case when conn_id != 1 then conn_id else conn_id + 1 end from perf_connections;
|
||||
sql explain select * from view1 union all select * from view2 union all select * from view3 union all select * from view4 union all select a from view5 union all select * from view6 union all select * from view7 union all select * from view8;
|
||||
sql explain analyze select * from view1 union all select * from view2 union all select * from view3 union all select * from view4 union all select a from view5 union all select * from view6 union all select * from view7 union all select * from view8;
|
||||
sql select * from view1 union all select * from view2 union all select * from view3 union all select * from view4 union all select a from view5 union all select * from view6 union all select * from view7 union all select * from view8;
|
||||
sql explain select * from view1 union select a from view5;
|
||||
sql explain analyze select * from view1 union select a from view5;
|
||||
sql select * from view1 union select a from view5;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 1 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
sql drop view view1;
|
||||
sql drop view view2;
|
||||
sql drop view view3;
|
||||
sql drop view view4;
|
||||
sql drop view view5;
|
||||
sql drop view view6;
|
||||
sql drop view view7;
|
||||
sql drop view view8;
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
sql connect
|
||||
sql use testa;
|
||||
|
||||
print == create view sta1
|
||||
sql create view sta1 as select * from stv;
|
||||
sql select * from sta1;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
sql desc sta1;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
sql show create table sta1;
|
||||
sql show create view sta1;
|
||||
sql create view view1 as select * from sta1;
|
||||
sql select * from view1;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print == drop view sta1
|
||||
sql reset query cache
|
||||
sql drop view sta1;
|
||||
sql select * from sta1;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
sql desc sta1;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
sql show create table sta1;
|
||||
sql_error show create view sta1;
|
||||
sql select * from view1;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print == create view sta1, drop table sta1
|
||||
sql reset query cache
|
||||
sql create view sta1 as select * from stv;
|
||||
sql drop table sta1;
|
||||
sql select * from sta1;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
sql desc sta1;
|
||||
if $rows != 3 then
|
||||
print $rows
|
||||
return -1
|
||||
endi
|
||||
sql_error show create table sta1;
|
||||
sql show create view sta1;
|
||||
sql select * from view1;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
sql desc view1;
|
||||
if $rows != 3 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print == restore data
|
||||
sql drop view sta1;
|
||||
sql drop view view1;
|
||||
sql create table sta1(ts timestamp, f int, g int) tags (t int);
|
||||
sql insert into cta11 using sta1 tags(1) values('2023-10-16 09:10:11', 100111, 1001110);
|
||||
sql insert into cta12 using sta1 tags(2) values('2023-10-16 09:10:12', 100112, 1001120);
|
||||
sql insert into cta13 using sta1 tags(3) values('2023-10-16 09:10:13', 100113, 1001130);
|
||||
sql insert into cta14 using sta1 tags(4) values('2023-10-16 09:10:14', 100114, 1001140);
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
sql connect
|
||||
sql use testa;
|
||||
|
||||
sql create view view1 as select * from sta1;
|
||||
sql show views;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != view1 then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != testa then
|
||||
return -1
|
||||
endi
|
||||
if $data02 != root then
|
||||
return -1
|
||||
endi
|
||||
if $data04 != NORMAL then
|
||||
return -1
|
||||
endi
|
||||
if $data05 != @select * from sta1;@ then
|
||||
return -1
|
||||
endi
|
||||
if $data06 != NULL then
|
||||
return -1
|
||||
endi
|
||||
if $data07 != NULL then
|
||||
return -1
|
||||
endi
|
||||
if $data08 != NULL then
|
||||
return -1
|
||||
endi
|
||||
sql desc view1
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != ts then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != TIMESTAMP then
|
||||
return -1
|
||||
endi
|
||||
if $data02 != 8 then
|
||||
return -1
|
||||
endi
|
||||
if $data03 != @VIEW COL@ then
|
||||
return -1
|
||||
endi
|
||||
if $data10 != f then
|
||||
return -1
|
||||
endi
|
||||
if $data20 != g then
|
||||
return -1
|
||||
endi
|
||||
if $data30 != t then
|
||||
return -1
|
||||
endi
|
||||
sql show create view view1;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @`testa`.`view1`@ then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != @CREATE VIEW `testa`.`view1` AS select * from sta1;@ then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql create or replace view view2 as select null;
|
||||
sql desc view2;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != null then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != VARCHAR then
|
||||
return -1
|
||||
endi
|
||||
if $data02 != 0 then
|
||||
return -1
|
||||
endi
|
||||
sql create or replace view view2 as select null a;
|
||||
sql desc view2;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != a then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != VARCHAR then
|
||||
return -1
|
||||
endi
|
||||
if $data02 != 0 then
|
||||
return -1
|
||||
endi
|
||||
sql show views;
|
||||
if $rows != 2 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql create view testb.view1 as select * from stb1;
|
||||
sql show views;
|
||||
if $rows != 2 then
|
||||
return -1
|
||||
endi
|
||||
sql show testb.views;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
sql show create view testb.view1;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @`testb`.`view1`@ then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != @CREATE VIEW `testb`.`view1` AS select * from stb1;@ then
|
||||
return -1
|
||||
endi
|
||||
sql desc testb.view1;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql use information_schema;
|
||||
sql create view view1 as select * from ins_views;
|
||||
sql select * from view1;
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
sql select * from view1 where db_name = 'testa';
|
||||
if $rows != 2 then
|
||||
return -1
|
||||
endi
|
||||
sql select * from view1 where db_name like 'test%';
|
||||
if $rows != 3 then
|
||||
return -1
|
||||
endi
|
||||
sql select * from view1 where view_name='view1';
|
||||
if $rows != 3 then
|
||||
return -1
|
||||
endi
|
||||
sql select concat(db_name, '.', view_name) from view1 where view_name='view1';
|
||||
if $rows != 3 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql drop view testa.view1;
|
||||
sql drop view testa.view2;
|
||||
sql drop view testb.view1;
|
||||
sql drop view information_schema.view1;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
sql connect
|
||||
sql use testa;
|
||||
|
||||
sql create view view1 as select * from sta1;
|
||||
sql_error CREATE STREAM s1 INTO s1t AS SELECT _wstart, count(*) FROM view1 PARTITION BY f INTERVAL(1m);
|
||||
|
||||
sql drop view view1;
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
system sh/stop_dnodes.sh
|
||||
system sh/deploy.sh -n dnode1 -i 1
|
||||
system sh/exec.sh -n dnode1 -s start
|
||||
sql connect
|
||||
sql drop database if exists testa
|
||||
sql create database testa vgroups 3;
|
||||
sql use testa;
|
||||
|
||||
sql create table sta1(ts timestamp, f int, g int) tags (t int);
|
||||
sql insert into cta11 using sta1 tags(1) values('2023-10-16 09:10:11', 100111, 1001110);
|
||||
sql insert into cta12 using sta1 tags(2) values('2023-10-16 09:10:12', 100112, 1001120);
|
||||
sql insert into cta13 using sta1 tags(3) values('2023-10-16 09:10:13', 100113, 1001130);
|
||||
sql insert into cta14 using sta1 tags(4) values('2023-10-16 09:10:14', 100114, 1001140);
|
||||
|
||||
sql create table st2(ts timestamp, f int, g int) tags (t int);
|
||||
sql insert into cta21 using st2 tags(1) values('2023-10-16 09:10:11', 100221, 1002210);
|
||||
sql insert into cta22 using st2 tags(2) values('2023-10-16 09:10:12', 100222, 1002220);
|
||||
sql insert into cta23 using st2 tags(3) values('2023-10-16 09:10:13', 100223, 1002230);
|
||||
sql insert into cta24 using st2 tags(4) values('2023-10-16 09:10:14', 100224, 1002240);
|
||||
|
||||
sql create table stt(ts timestamp, f int, g int) tags (t int);
|
||||
sql create table tt using stt tags(99);
|
||||
|
||||
sql create table stv(ts timestamp, h int) tags (t1 int);
|
||||
sql insert into ctv1 using stv tags(1) values('2023-10-16 10:10:10', 1);
|
||||
|
||||
sql drop database if exists testb
|
||||
sql create database testb vgroups 1;
|
||||
sql use testb;
|
||||
|
||||
sql create table stb1(ts timestamp, f int,g int) tags (t int);
|
||||
sql insert into ctb11 using stb1 tags(1) values('2023-10-16 09:10:11', 110111, 1101110);
|
||||
sql insert into ctb12 using stb1 tags(2) values('2023-10-16 09:10:12', 110112, 1101120);
|
||||
sql insert into ctb13 using stb1 tags(3) values('2023-10-16 09:10:13', 110113, 1101130);
|
||||
sql insert into ctb14 using stb1 tags(4) values('2023-10-16 09:10:14', 110114, 1101140);
|
||||
|
||||
sql create table st2(ts timestamp, f int, g int) tags (t int);
|
||||
sql insert into ctb21 using st2 tags(1) values('2023-10-16 09:10:11', 110221, 1102210);
|
||||
sql insert into ctb22 using st2 tags(2) values('2023-10-16 09:10:12', 110222, 1102220);
|
||||
sql insert into ctb23 using st2 tags(3) values('2023-10-16 09:10:13', 110223, 1102230);
|
||||
sql insert into ctb24 using st2 tags(4) values('2023-10-16 09:10:14', 110224, 1102240);
|
||||
|
||||
run tsim/view/privilege_basic_view.sim
|
||||
run tsim/view/privilege_nested_view.sim
|
||||
run tsim/view/create_drop_view.sim
|
||||
run tsim/view/query_view.sim
|
||||
run tsim/view/insert_view.sim
|
||||
run tsim/view/stream_view.sim
|
||||
run tsim/view/show_desc_view.sim
|
||||
run tsim/view/same_name_tb_view.sim
|
||||
|
||||
print ================== restart server to commit data into disk
|
||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||
system sh/exec.sh -n dnode1 -s start
|
||||
print ================== server restart completed
|
||||
|
||||
run tsim/view/privilege_basic_view.sim
|
||||
run tsim/view/privilege_nested_view.sim
|
||||
run tsim/view/create_drop_view.sim
|
||||
run tsim/view/query_view.sim
|
||||
run tsim/view/insert_view.sim
|
||||
run tsim/view/stream_view.sim
|
||||
run tsim/view/show_desc_view.sim
|
||||
run tsim/view/same_name_tb_view.sim
|
||||
|
||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -57,7 +57,7 @@ class TDTestCase:
|
|||
self.nchar_str = '涛思数据'
|
||||
self.ins_list = ['ins_dnodes','ins_mnodes','ins_qnodes','ins_snodes','ins_cluster','ins_databases','ins_functions',\
|
||||
'ins_indexes','ins_stables','ins_tables','ins_tags','ins_columns','ins_users','ins_grants','ins_vgroups','ins_configs','ins_dnode_variables',\
|
||||
'ins_topics','ins_subscriptions','ins_streams','ins_stream_tasks','ins_vnodes','ins_user_privileges']
|
||||
'ins_topics','ins_subscriptions','ins_streams','ins_stream_tasks','ins_vnodes','ins_user_privileges','ins_views']
|
||||
self.perf_list = ['perf_connections','perf_queries','perf_consumers','perf_trans','perf_apps']
|
||||
def insert_data(self,column_dict,tbname,row_num):
|
||||
insert_sql = self.setsql.set_insertsql(column_dict,tbname,self.binary_str,self.nchar_str)
|
||||
|
@ -217,7 +217,7 @@ class TDTestCase:
|
|||
tdSql.checkEqual(20470,len(tdSql.queryResult))
|
||||
|
||||
tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'")
|
||||
tdSql.checkEqual(198, len(tdSql.queryResult))
|
||||
tdSql.checkEqual(208, len(tdSql.queryResult))
|
||||
|
||||
tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'")
|
||||
tdSql.checkEqual(54, len(tdSql.queryResult))
|
||||
|
|
Loading…
Reference in New Issue