chore: merge with 3.0
This commit is contained in:
commit
c6a08b64b5
|
@ -118,12 +118,18 @@ ELSE ()
|
|||
IF (${BUILD_SANITIZER})
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=shift-base -fno-sanitize=alignment -g3 -Wformat=0")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-literal-suffix -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=shift-base -fno-sanitize=alignment -g3 -Wformat=0")
|
||||
MESSAGE(STATUS "Will compile with Address Sanitizer!")
|
||||
MESSAGE(STATUS "Compile with Address Sanitizer!")
|
||||
ELSE ()
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3 -Wformat=2 -Wno-format-nonliteral -Wno-format-truncation -Wno-format-y2k")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-literal-suffix -Werror=return-type -fPIC -gdwarf-2 -g3 -Wformat=2 -Wno-format-nonliteral -Wno-format-truncation -Wno-format-y2k")
|
||||
ENDIF ()
|
||||
|
||||
# disable all assert
|
||||
IF ((${DISABLE_ASSERT} MATCHES "true") OR (${DISABLE_ASSERTS} MATCHES "true"))
|
||||
ADD_DEFINITIONS(-DDISABLE_ASSERT)
|
||||
MESSAGE(STATUS "Disable all asserts")
|
||||
ENDIF()
|
||||
|
||||
INCLUDE(CheckCCompilerFlag)
|
||||
IF (TD_ARM_64 OR TD_ARM_32)
|
||||
SET(COMPILER_SUPPORT_SSE42 false)
|
||||
|
@ -156,7 +162,7 @@ ELSE ()
|
|||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")
|
||||
ENDIF()
|
||||
MESSAGE(STATUS "SIMD instructions (AVX/AVX2) is ACTIVATED")
|
||||
MESSAGE(STATUS "SIMD instructions (FMA/AVX/AVX2) is ACTIVATED")
|
||||
ENDIF()
|
||||
|
||||
ENDIF ()
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
IF (DEFINED VERNUMBER)
|
||||
SET(TD_VER_NUMBER ${VERNUMBER})
|
||||
ELSE ()
|
||||
SET(TD_VER_NUMBER "3.0.2.1")
|
||||
SET(TD_VER_NUMBER "3.0.2.2")
|
||||
ENDIF ()
|
||||
|
||||
IF (DEFINED VERCOMPATIBLE)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# taosadapter
|
||||
ExternalProject_Add(taosadapter
|
||||
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
|
||||
GIT_TAG 5662a6d
|
||||
GIT_TAG a2e9920
|
||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# taos-tools
|
||||
ExternalProject_Add(taos-tools
|
||||
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
|
||||
GIT_TAG 11b60a4
|
||||
GIT_TAG 4776778
|
||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
|
||||
BINARY_DIR ""
|
||||
#BUILD_IN_SOURCE TRUE
|
||||
|
|
|
@ -94,6 +94,7 @@ description: "TDengine 3.0 版本的语法变更说明"
|
|||
| 9 | SAMPLE | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
|
||||
| 10 | STATECOUNT | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
|
||||
| 11 | STATEDURATION | 增强 | 可以直接用于超级表了。没有PARTITION BY时,超级表的数据会被合并成一条时间线。
|
||||
| 12 | TIMETRUNCATE | 增强 | 增加ignore_timezone参数,可选是否使用,默认值为1.
|
||||
|
||||
|
||||
## SCHEMALESS 变更
|
||||
|
|
|
@ -161,6 +161,8 @@ DLL_EXPORT int taos_stmt_set_tags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags)
|
|||
DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name);
|
||||
DLL_EXPORT int taos_stmt_get_tag_fields(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields);
|
||||
DLL_EXPORT int taos_stmt_get_col_fields(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fields);
|
||||
// let stmt to reclaim TAOS_FIELD_E that was allocated by `taos_stmt_get_tag_fields`/`taos_stmt_get_col_fields`
|
||||
DLL_EXPORT void taos_stmt_reclaim_fields(TAOS_STMT *stmt, TAOS_FIELD_E *fields);
|
||||
|
||||
DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert);
|
||||
DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums);
|
||||
|
@ -218,6 +220,7 @@ DLL_EXPORT const void *taos_get_raw_block(TAOS_RES *res);
|
|||
|
||||
DLL_EXPORT int taos_get_db_route_info(TAOS *taos, const char *db, TAOS_DB_ROUTE_INFO *dbInfo);
|
||||
DLL_EXPORT int taos_get_table_vgId(TAOS *taos, const char *db, const char *table, int *vgId);
|
||||
DLL_EXPORT int taos_get_tables_vgId(TAOS *taos, const char *db, const char *table[], int tableNum, int *vgId);
|
||||
|
||||
DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList);
|
||||
|
||||
|
|
|
@ -30,6 +30,11 @@ typedef int64_t tb_uid_t;
|
|||
#define IS_TSWINDOW_SPECIFIED(win) (((win).skey != INT64_MIN) || ((win).ekey != INT64_MAX))
|
||||
#define TSWINDOW_IS_EQUAL(t1, t2) (((t1).skey == (t2).skey) && ((t1).ekey == (t2).ekey))
|
||||
|
||||
//define show cluster alive and show db.alive
|
||||
#define SHOW_STATUS_NOT_AVAILABLE 0
|
||||
#define SHOW_STATUS_AVAILABLE 1
|
||||
#define SHOW_STATUS_HALF_AVAILABLE 2
|
||||
|
||||
typedef enum {
|
||||
TSDB_SUPER_TABLE = 1, // super table
|
||||
TSDB_CHILD_TABLE = 2, // table created from super table
|
||||
|
|
|
@ -292,6 +292,7 @@ typedef struct STableBlockDistInfo {
|
|||
uint16_t numOfFiles;
|
||||
uint32_t numOfTables;
|
||||
uint32_t numOfBlocks;
|
||||
uint32_t numOfVgroups;
|
||||
uint64_t totalSize;
|
||||
uint64_t totalRows;
|
||||
int32_t maxRows;
|
||||
|
|
|
@ -39,6 +39,7 @@ typedef enum {
|
|||
QUEUE_MAX,
|
||||
} EQueueType;
|
||||
|
||||
typedef int32_t (*UpdateDnodeInfoFp)(void* pData, int32_t* dnodeId, int64_t* clusterId, char* fqdn, uint16_t* port);
|
||||
typedef int32_t (*PutToQueueFp)(void* pMgmt, EQueueType qtype, SRpcMsg* pMsg);
|
||||
typedef int32_t (*GetQueueSizeFp)(void* pMgmt, int32_t vgId, EQueueType qtype);
|
||||
typedef int32_t (*SendReqFp)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||
|
@ -48,6 +49,7 @@ typedef void (*ReleaseHandleFp)(SRpcHandleInfo* pHandle, int8_t type);
|
|||
typedef void (*ReportStartup)(const char* name, const char* desc);
|
||||
|
||||
typedef struct {
|
||||
void* data;
|
||||
void* mgmt;
|
||||
void* clientRpc;
|
||||
PutToQueueFp putToQueueFp;
|
||||
|
@ -57,6 +59,7 @@ typedef struct {
|
|||
RegisterBrokenLinkArgFp registerBrokenLinkArgFp;
|
||||
ReleaseHandleFp releaseHandleFp;
|
||||
ReportStartup reportStartupFp;
|
||||
UpdateDnodeInfoFp updateDnodeInfoFp;
|
||||
} SMsgCb;
|
||||
|
||||
void tmsgSetDefault(const SMsgCb* msgcb);
|
||||
|
@ -67,6 +70,7 @@ void tmsgSendRsp(SRpcMsg* pMsg);
|
|||
void tmsgRegisterBrokenLinkArg(SRpcMsg* pMsg);
|
||||
void tmsgReleaseHandle(SRpcHandleInfo* pHandle, int8_t type);
|
||||
void tmsgReportStartup(const char* name, const char* desc);
|
||||
int32_t tmsgUpdateDnodeInfo(int32_t* dnodeId, int64_t* clusterId, char* fqdn, uint16_t* port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "talgo.h"
|
||||
#include "taosdef.h"
|
||||
#include "taoserror.h"
|
||||
#include "tbuffer.h"
|
||||
#include "tdataformat.h"
|
||||
#include "tdef.h"
|
||||
#include "ttypes.h"
|
||||
|
|
|
@ -175,171 +175,172 @@
|
|||
#define TK_CONSUMERS 157
|
||||
#define TK_SUBSCRIPTIONS 158
|
||||
#define TK_VNODES 159
|
||||
#define TK_LIKE 160
|
||||
#define TK_TBNAME 161
|
||||
#define TK_QTAGS 162
|
||||
#define TK_AS 163
|
||||
#define TK_INDEX 164
|
||||
#define TK_FUNCTION 165
|
||||
#define TK_INTERVAL 166
|
||||
#define TK_COUNT 167
|
||||
#define TK_LAST_ROW 168
|
||||
#define TK_TOPIC 169
|
||||
#define TK_WITH 170
|
||||
#define TK_META 171
|
||||
#define TK_CONSUMER 172
|
||||
#define TK_GROUP 173
|
||||
#define TK_DESC 174
|
||||
#define TK_DESCRIBE 175
|
||||
#define TK_RESET 176
|
||||
#define TK_QUERY 177
|
||||
#define TK_CACHE 178
|
||||
#define TK_EXPLAIN 179
|
||||
#define TK_ANALYZE 180
|
||||
#define TK_VERBOSE 181
|
||||
#define TK_NK_BOOL 182
|
||||
#define TK_RATIO 183
|
||||
#define TK_NK_FLOAT 184
|
||||
#define TK_OUTPUTTYPE 185
|
||||
#define TK_AGGREGATE 186
|
||||
#define TK_BUFSIZE 187
|
||||
#define TK_STREAM 188
|
||||
#define TK_INTO 189
|
||||
#define TK_TRIGGER 190
|
||||
#define TK_AT_ONCE 191
|
||||
#define TK_WINDOW_CLOSE 192
|
||||
#define TK_IGNORE 193
|
||||
#define TK_EXPIRED 194
|
||||
#define TK_FILL_HISTORY 195
|
||||
#define TK_SUBTABLE 196
|
||||
#define TK_KILL 197
|
||||
#define TK_CONNECTION 198
|
||||
#define TK_TRANSACTION 199
|
||||
#define TK_BALANCE 200
|
||||
#define TK_VGROUP 201
|
||||
#define TK_MERGE 202
|
||||
#define TK_REDISTRIBUTE 203
|
||||
#define TK_SPLIT 204
|
||||
#define TK_DELETE 205
|
||||
#define TK_INSERT 206
|
||||
#define TK_NULL 207
|
||||
#define TK_NK_QUESTION 208
|
||||
#define TK_NK_ARROW 209
|
||||
#define TK_ROWTS 210
|
||||
#define TK_QSTART 211
|
||||
#define TK_QEND 212
|
||||
#define TK_QDURATION 213
|
||||
#define TK_WSTART 214
|
||||
#define TK_WEND 215
|
||||
#define TK_WDURATION 216
|
||||
#define TK_IROWTS 217
|
||||
#define TK_ISFILLED 218
|
||||
#define TK_CAST 219
|
||||
#define TK_NOW 220
|
||||
#define TK_TODAY 221
|
||||
#define TK_TIMEZONE 222
|
||||
#define TK_CLIENT_VERSION 223
|
||||
#define TK_SERVER_VERSION 224
|
||||
#define TK_SERVER_STATUS 225
|
||||
#define TK_CURRENT_USER 226
|
||||
#define TK_CASE 227
|
||||
#define TK_END 228
|
||||
#define TK_WHEN 229
|
||||
#define TK_THEN 230
|
||||
#define TK_ELSE 231
|
||||
#define TK_BETWEEN 232
|
||||
#define TK_IS 233
|
||||
#define TK_NK_LT 234
|
||||
#define TK_NK_GT 235
|
||||
#define TK_NK_LE 236
|
||||
#define TK_NK_GE 237
|
||||
#define TK_NK_NE 238
|
||||
#define TK_MATCH 239
|
||||
#define TK_NMATCH 240
|
||||
#define TK_CONTAINS 241
|
||||
#define TK_IN 242
|
||||
#define TK_JOIN 243
|
||||
#define TK_INNER 244
|
||||
#define TK_SELECT 245
|
||||
#define TK_DISTINCT 246
|
||||
#define TK_WHERE 247
|
||||
#define TK_PARTITION 248
|
||||
#define TK_BY 249
|
||||
#define TK_SESSION 250
|
||||
#define TK_STATE_WINDOW 251
|
||||
#define TK_EVENT_WINDOW 252
|
||||
#define TK_START 253
|
||||
#define TK_SLIDING 254
|
||||
#define TK_FILL 255
|
||||
#define TK_VALUE 256
|
||||
#define TK_NONE 257
|
||||
#define TK_PREV 258
|
||||
#define TK_LINEAR 259
|
||||
#define TK_NEXT 260
|
||||
#define TK_HAVING 261
|
||||
#define TK_RANGE 262
|
||||
#define TK_EVERY 263
|
||||
#define TK_ORDER 264
|
||||
#define TK_SLIMIT 265
|
||||
#define TK_SOFFSET 266
|
||||
#define TK_LIMIT 267
|
||||
#define TK_OFFSET 268
|
||||
#define TK_ASC 269
|
||||
#define TK_NULLS 270
|
||||
#define TK_ABORT 271
|
||||
#define TK_AFTER 272
|
||||
#define TK_ATTACH 273
|
||||
#define TK_BEFORE 274
|
||||
#define TK_BEGIN 275
|
||||
#define TK_BITAND 276
|
||||
#define TK_BITNOT 277
|
||||
#define TK_BITOR 278
|
||||
#define TK_BLOCKS 279
|
||||
#define TK_CHANGE 280
|
||||
#define TK_COMMA 281
|
||||
#define TK_COMPACT 282
|
||||
#define TK_CONCAT 283
|
||||
#define TK_CONFLICT 284
|
||||
#define TK_COPY 285
|
||||
#define TK_DEFERRED 286
|
||||
#define TK_DELIMITERS 287
|
||||
#define TK_DETACH 288
|
||||
#define TK_DIVIDE 289
|
||||
#define TK_DOT 290
|
||||
#define TK_EACH 291
|
||||
#define TK_FAIL 292
|
||||
#define TK_FILE 293
|
||||
#define TK_FOR 294
|
||||
#define TK_GLOB 295
|
||||
#define TK_ID 296
|
||||
#define TK_IMMEDIATE 297
|
||||
#define TK_IMPORT 298
|
||||
#define TK_INITIALLY 299
|
||||
#define TK_INSTEAD 300
|
||||
#define TK_ISNULL 301
|
||||
#define TK_KEY 302
|
||||
#define TK_MODULES 303
|
||||
#define TK_NK_BITNOT 304
|
||||
#define TK_NK_SEMI 305
|
||||
#define TK_NOTNULL 306
|
||||
#define TK_OF 307
|
||||
#define TK_PLUS 308
|
||||
#define TK_PRIVILEGE 309
|
||||
#define TK_RAISE 310
|
||||
#define TK_REPLACE 311
|
||||
#define TK_RESTRICT 312
|
||||
#define TK_ROW 313
|
||||
#define TK_SEMI 314
|
||||
#define TK_STAR 315
|
||||
#define TK_STATEMENT 316
|
||||
#define TK_STRICT 317
|
||||
#define TK_STRING 318
|
||||
#define TK_TIMES 319
|
||||
#define TK_UPDATE 320
|
||||
#define TK_VALUES 321
|
||||
#define TK_VARIABLE 322
|
||||
#define TK_VIEW 323
|
||||
#define TK_WAL 324
|
||||
#define TK_ALIVE 160
|
||||
#define TK_LIKE 161
|
||||
#define TK_TBNAME 162
|
||||
#define TK_QTAGS 163
|
||||
#define TK_AS 164
|
||||
#define TK_INDEX 165
|
||||
#define TK_FUNCTION 166
|
||||
#define TK_INTERVAL 167
|
||||
#define TK_COUNT 168
|
||||
#define TK_LAST_ROW 169
|
||||
#define TK_TOPIC 170
|
||||
#define TK_WITH 171
|
||||
#define TK_META 172
|
||||
#define TK_CONSUMER 173
|
||||
#define TK_GROUP 174
|
||||
#define TK_DESC 175
|
||||
#define TK_DESCRIBE 176
|
||||
#define TK_RESET 177
|
||||
#define TK_QUERY 178
|
||||
#define TK_CACHE 179
|
||||
#define TK_EXPLAIN 180
|
||||
#define TK_ANALYZE 181
|
||||
#define TK_VERBOSE 182
|
||||
#define TK_NK_BOOL 183
|
||||
#define TK_RATIO 184
|
||||
#define TK_NK_FLOAT 185
|
||||
#define TK_OUTPUTTYPE 186
|
||||
#define TK_AGGREGATE 187
|
||||
#define TK_BUFSIZE 188
|
||||
#define TK_STREAM 189
|
||||
#define TK_INTO 190
|
||||
#define TK_TRIGGER 191
|
||||
#define TK_AT_ONCE 192
|
||||
#define TK_WINDOW_CLOSE 193
|
||||
#define TK_IGNORE 194
|
||||
#define TK_EXPIRED 195
|
||||
#define TK_FILL_HISTORY 196
|
||||
#define TK_SUBTABLE 197
|
||||
#define TK_KILL 198
|
||||
#define TK_CONNECTION 199
|
||||
#define TK_TRANSACTION 200
|
||||
#define TK_BALANCE 201
|
||||
#define TK_VGROUP 202
|
||||
#define TK_MERGE 203
|
||||
#define TK_REDISTRIBUTE 204
|
||||
#define TK_SPLIT 205
|
||||
#define TK_DELETE 206
|
||||
#define TK_INSERT 207
|
||||
#define TK_NULL 208
|
||||
#define TK_NK_QUESTION 209
|
||||
#define TK_NK_ARROW 210
|
||||
#define TK_ROWTS 211
|
||||
#define TK_QSTART 212
|
||||
#define TK_QEND 213
|
||||
#define TK_QDURATION 214
|
||||
#define TK_WSTART 215
|
||||
#define TK_WEND 216
|
||||
#define TK_WDURATION 217
|
||||
#define TK_IROWTS 218
|
||||
#define TK_ISFILLED 219
|
||||
#define TK_CAST 220
|
||||
#define TK_NOW 221
|
||||
#define TK_TODAY 222
|
||||
#define TK_TIMEZONE 223
|
||||
#define TK_CLIENT_VERSION 224
|
||||
#define TK_SERVER_VERSION 225
|
||||
#define TK_SERVER_STATUS 226
|
||||
#define TK_CURRENT_USER 227
|
||||
#define TK_CASE 228
|
||||
#define TK_END 229
|
||||
#define TK_WHEN 230
|
||||
#define TK_THEN 231
|
||||
#define TK_ELSE 232
|
||||
#define TK_BETWEEN 233
|
||||
#define TK_IS 234
|
||||
#define TK_NK_LT 235
|
||||
#define TK_NK_GT 236
|
||||
#define TK_NK_LE 237
|
||||
#define TK_NK_GE 238
|
||||
#define TK_NK_NE 239
|
||||
#define TK_MATCH 240
|
||||
#define TK_NMATCH 241
|
||||
#define TK_CONTAINS 242
|
||||
#define TK_IN 243
|
||||
#define TK_JOIN 244
|
||||
#define TK_INNER 245
|
||||
#define TK_SELECT 246
|
||||
#define TK_DISTINCT 247
|
||||
#define TK_WHERE 248
|
||||
#define TK_PARTITION 249
|
||||
#define TK_BY 250
|
||||
#define TK_SESSION 251
|
||||
#define TK_STATE_WINDOW 252
|
||||
#define TK_EVENT_WINDOW 253
|
||||
#define TK_START 254
|
||||
#define TK_SLIDING 255
|
||||
#define TK_FILL 256
|
||||
#define TK_VALUE 257
|
||||
#define TK_NONE 258
|
||||
#define TK_PREV 259
|
||||
#define TK_LINEAR 260
|
||||
#define TK_NEXT 261
|
||||
#define TK_HAVING 262
|
||||
#define TK_RANGE 263
|
||||
#define TK_EVERY 264
|
||||
#define TK_ORDER 265
|
||||
#define TK_SLIMIT 266
|
||||
#define TK_SOFFSET 267
|
||||
#define TK_LIMIT 268
|
||||
#define TK_OFFSET 269
|
||||
#define TK_ASC 270
|
||||
#define TK_NULLS 271
|
||||
#define TK_ABORT 272
|
||||
#define TK_AFTER 273
|
||||
#define TK_ATTACH 274
|
||||
#define TK_BEFORE 275
|
||||
#define TK_BEGIN 276
|
||||
#define TK_BITAND 277
|
||||
#define TK_BITNOT 278
|
||||
#define TK_BITOR 279
|
||||
#define TK_BLOCKS 280
|
||||
#define TK_CHANGE 281
|
||||
#define TK_COMMA 282
|
||||
#define TK_COMPACT 283
|
||||
#define TK_CONCAT 284
|
||||
#define TK_CONFLICT 285
|
||||
#define TK_COPY 286
|
||||
#define TK_DEFERRED 287
|
||||
#define TK_DELIMITERS 288
|
||||
#define TK_DETACH 289
|
||||
#define TK_DIVIDE 290
|
||||
#define TK_DOT 291
|
||||
#define TK_EACH 292
|
||||
#define TK_FAIL 293
|
||||
#define TK_FILE 294
|
||||
#define TK_FOR 295
|
||||
#define TK_GLOB 296
|
||||
#define TK_ID 297
|
||||
#define TK_IMMEDIATE 298
|
||||
#define TK_IMPORT 299
|
||||
#define TK_INITIALLY 300
|
||||
#define TK_INSTEAD 301
|
||||
#define TK_ISNULL 302
|
||||
#define TK_KEY 303
|
||||
#define TK_MODULES 304
|
||||
#define TK_NK_BITNOT 305
|
||||
#define TK_NK_SEMI 306
|
||||
#define TK_NOTNULL 307
|
||||
#define TK_OF 308
|
||||
#define TK_PLUS 309
|
||||
#define TK_PRIVILEGE 310
|
||||
#define TK_RAISE 311
|
||||
#define TK_REPLACE 312
|
||||
#define TK_RESTRICT 313
|
||||
#define TK_ROW 314
|
||||
#define TK_SEMI 315
|
||||
#define TK_STAR 316
|
||||
#define TK_STATEMENT 317
|
||||
#define TK_STRICT 318
|
||||
#define TK_STRING 319
|
||||
#define TK_TIMES 320
|
||||
#define TK_UPDATE 321
|
||||
#define TK_VALUES 322
|
||||
#define TK_VARIABLE 323
|
||||
#define TK_VIEW 324
|
||||
#define TK_WAL 325
|
||||
|
||||
#define TK_NK_SPACE 600
|
||||
#define TK_NK_COMMENT 601
|
||||
|
|
|
@ -210,6 +210,9 @@ int32_t catalogGetCachedTableMeta(SCatalog* pCtg, const SName* pTableName, STabl
|
|||
|
||||
int32_t catalogGetCachedSTableMeta(SCatalog* pCtg, const SName* pTableName, STableMeta** pTableMeta);
|
||||
|
||||
int32_t catalogGetTablesHashVgId(SCatalog* pCtg, SRequestConnInfo* pConn, int32_t acctId, const char* pDb, const char* pTableName[],
|
||||
int32_t tableNum, int32_t *vgId);
|
||||
|
||||
int32_t catalogGetCachedTableHashVgroup(SCatalog* pCtg, const SName* pTableName, SVgroupInfo* pVgroup, bool* exists);
|
||||
|
||||
int32_t catalogGetCachedTableVgMeta(SCatalog* pCtg, const SName* pTableName, SVgroupInfo* pVgroup, STableMeta** pTableMeta);
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
typedef struct SExplainCtx SExplainCtx;
|
||||
|
||||
int32_t qExecCommand(bool sysInfoUser, SNode *pStmt, SRetrieveTableRsp **pRsp);
|
||||
int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode *pStmt, SRetrieveTableRsp **pRsp);
|
||||
|
||||
int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp);
|
||||
int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs);
|
||||
|
|
|
@ -216,6 +216,7 @@ int32_t qStreamSourceRecoverStep2(qTaskInfo_t tinfo, int64_t ver);
|
|||
int32_t qStreamRecoverFinish(qTaskInfo_t tinfo);
|
||||
int32_t qStreamRestoreParam(qTaskInfo_t tinfo);
|
||||
bool qStreamRecoverScanFinished(qTaskInfo_t tinfo);
|
||||
void qStreamCloseTsdbReader(void* task);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tbuffer.h"
|
||||
#include "tcommon.h"
|
||||
#include "tvariant.h"
|
||||
|
||||
|
@ -138,7 +137,7 @@ typedef struct SqlFunctionCtx {
|
|||
char *pOutput; // final result output buffer, point to sdata->data
|
||||
int32_t numOfParams;
|
||||
// input parameter, e.g., top(k, 20), the number of results of top query is kept in param
|
||||
SFunctParam *param;
|
||||
SFunctParam *param;
|
||||
// corresponding output buffer for timestamp of each result, e.g., diff/csum
|
||||
SColumnInfoData *pTsOutput;
|
||||
int32_t offset;
|
||||
|
@ -152,6 +151,7 @@ typedef struct SqlFunctionCtx {
|
|||
struct SSDataBlock *pSrcBlock;
|
||||
struct SSDataBlock *pDstBlock; // used by indefinite rows function to set selectivity
|
||||
SSerializeDataHandle saveHandle;
|
||||
int32_t exprIdx;
|
||||
char udfName[TSDB_FUNC_NAME_LEN];
|
||||
} SqlFunctionCtx;
|
||||
|
||||
|
@ -182,9 +182,9 @@ struct SScalarParam {
|
|||
int32_t numOfQualified; // number of qualified elements in the final results
|
||||
};
|
||||
|
||||
void cleanupResultRowEntry(struct SResultRowEntryInfo *pCell);
|
||||
bool isRowEntryCompleted(struct SResultRowEntryInfo *pEntry);
|
||||
bool isRowEntryInitialized(struct SResultRowEntryInfo *pEntry);
|
||||
void cleanupResultRowEntry(struct SResultRowEntryInfo *pCell);
|
||||
bool isRowEntryCompleted(struct SResultRowEntryInfo *pEntry);
|
||||
bool isRowEntryInitialized(struct SResultRowEntryInfo *pEntry);
|
||||
|
||||
typedef struct SPoint {
|
||||
int64_t key;
|
||||
|
|
|
@ -40,6 +40,7 @@ extern "C" {
|
|||
#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)
|
||||
|
||||
#define SHOW_ALIVE_RESULT_COLS 1
|
||||
#define PRIVILEGE_TYPE_MASK(n) (1 << n)
|
||||
|
||||
#define PRIVILEGE_TYPE_ALL PRIVILEGE_TYPE_MASK(0)
|
||||
|
@ -262,6 +263,11 @@ typedef struct SShowCreateDatabaseStmt {
|
|||
void* pCfg; // SDbCfgInfo
|
||||
} SShowCreateDatabaseStmt;
|
||||
|
||||
typedef struct SShowAliveStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
} SShowAliveStmt;
|
||||
|
||||
typedef struct SShowCreateTableStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
|
@ -401,6 +407,7 @@ typedef struct SCreateStreamStmt {
|
|||
SNode* pQuery;
|
||||
SNodeList* pTags;
|
||||
SNode* pSubtable;
|
||||
SNodeList* pCols;
|
||||
} SCreateStreamStmt;
|
||||
|
||||
typedef struct SDropStreamStmt {
|
||||
|
|
|
@ -208,6 +208,8 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_DELETE_STMT,
|
||||
QUERY_NODE_INSERT_STMT,
|
||||
QUERY_NODE_QUERY,
|
||||
QUERY_NODE_SHOW_DB_ALIVE_STMT,
|
||||
QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT,
|
||||
|
||||
// logic plan node
|
||||
QUERY_NODE_LOGIC_PLAN_SCAN = 1000,
|
||||
|
|
|
@ -121,6 +121,7 @@ typedef struct SAggLogicNode {
|
|||
bool hasLast;
|
||||
bool hasTimeLineFunc;
|
||||
bool onlyHasKeepOrderFunc;
|
||||
bool hasGroupKeyOptimized;
|
||||
} SAggLogicNode;
|
||||
|
||||
typedef struct SProjectLogicNode {
|
||||
|
@ -409,6 +410,7 @@ typedef struct SAggPhysiNode {
|
|||
SNodeList* pGroupKeys;
|
||||
SNodeList* pAggFuncs;
|
||||
bool mergeDataBlock;
|
||||
bool groupKeyOptimized;
|
||||
} SAggPhysiNode;
|
||||
|
||||
typedef struct SDownstreamSourceNode {
|
||||
|
|
|
@ -78,6 +78,8 @@ typedef enum {
|
|||
} ESyncState;
|
||||
|
||||
typedef struct SNodeInfo {
|
||||
int64_t clusterId;
|
||||
int32_t nodeId;
|
||||
uint16_t nodePort;
|
||||
char nodeFqdn[TSDB_FQDN_LEN];
|
||||
} SNodeInfo;
|
||||
|
|
|
@ -116,6 +116,7 @@ extern "C" {
|
|||
#include "osTimer.h"
|
||||
#include "osTimezone.h"
|
||||
#include "taoserror.h"
|
||||
#include "tlog.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -22,12 +22,16 @@ extern "C" {
|
|||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
// When you want to use this feature, you should find or add the same function in the following sectio
|
||||
#if !defined(WINDOWS)
|
||||
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define malloc MALLOC_FUNC_TAOS_FORBID
|
||||
#define calloc CALLOC_FUNC_TAOS_FORBID
|
||||
#define realloc REALLOC_FUNC_TAOS_FORBID
|
||||
#define free FREE_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
#endif // ifndef ALLOW_FORBID_FUNC
|
||||
|
||||
#endif // if !defined(WINDOWS)
|
||||
|
||||
void *taosMemoryMalloc(int64_t size);
|
||||
void *taosMemoryCalloc(int64_t num, int64_t size);
|
||||
|
|
|
@ -62,11 +62,38 @@ void taosResetTerminalMode();
|
|||
taosMemoryFree(strings); \
|
||||
}
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <dbghelp.h>
|
||||
|
||||
#define STACKSIZE 64
|
||||
#define taosPrintTrace(flags, level, dflag) \
|
||||
{ \
|
||||
taosPrintLog(flags, level, dflag, \
|
||||
"backtrace not implemented on windows, so detailed stack information cannot be printed"); \
|
||||
}
|
||||
unsigned int i; \
|
||||
void* stack[STACKSIZE]; \
|
||||
unsigned short frames; \
|
||||
SYMBOL_INFO* symbol; \
|
||||
HANDLE process; \
|
||||
\
|
||||
process = GetCurrentProcess(); \
|
||||
\
|
||||
SymInitialize(process, NULL, TRUE); \
|
||||
\
|
||||
frames = CaptureStackBackTrace(0, STACKSIZE, stack, NULL); \
|
||||
symbol = (SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO) + 256 * sizeof(char), 1); \
|
||||
if (symbol != NULL) { \
|
||||
symbol->MaxNameLen = 255; \
|
||||
symbol->SizeOfStruct = sizeof(SYMBOL_INFO); \
|
||||
\
|
||||
if (frames > 0) { \
|
||||
taosPrintLog(flags, level, dflag, "obtained %d stack frames", frames); \
|
||||
for (i = 0; i < frames; i++) { \
|
||||
SymFromAddr(process, (DWORD64)(stack[i]), 0, symbol); \
|
||||
taosPrintLog(flags, level, dflag, "frame:%i: %s - 0x%0X", frames - i - 1, symbol->Name, symbol->Address); \
|
||||
} \
|
||||
} \
|
||||
free(symbol); \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -346,6 +346,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_TOPIC_SUBSCRIBED TAOS_DEF_ERROR_CODE(0, 0x03EB)
|
||||
#define TSDB_CODE_MND_CGROUP_USED TAOS_DEF_ERROR_CODE(0, 0x03EC)
|
||||
#define TSDB_CODE_MND_TOPIC_MUST_BE_DELETED TAOS_DEF_ERROR_CODE(0, 0x03ED)
|
||||
#define TSDB_CODE_MND_INVALID_SUB_OPTION TAOS_DEF_ERROR_CODE(0, 0x03EE)
|
||||
#define TSDB_CODE_MND_IN_REBALANCE TAOS_DEF_ERROR_CODE(0, 0x03EF)
|
||||
|
||||
// mnode-stream
|
||||
|
|
|
@ -1,168 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020 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_UTIL_BUFFER_H_
|
||||
#define _TD_UTIL_BUFFER_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// usage example
|
||||
/*
|
||||
#include <stdio.h>
|
||||
#include "texception.h"
|
||||
|
||||
int32_t main( int32_t argc, char** argv ) {
|
||||
SBufferWriter bw = tbufInitWriter( NULL, false );
|
||||
|
||||
TRY( 1 ) {
|
||||
//--------------------- write ------------------------
|
||||
// reserve 1024 bytes for the buffer to improve performance
|
||||
tbufEnsureCapacity( &bw, 1024 );
|
||||
|
||||
// reserve space for the interger count
|
||||
size_t pos = tbufReserve( &bw, sizeof(int32_t) );
|
||||
// write 5 integers to the buffer
|
||||
for( int32_t i = 0; i < 5; i++) {
|
||||
tbufWriteInt32( &bw, i );
|
||||
}
|
||||
// write the integer count to buffer at reserved position
|
||||
tbufWriteInt32At( &bw, pos, 5 );
|
||||
|
||||
// write a string to the buffer
|
||||
tbufWriteString( &bw, "this is a string.\n" );
|
||||
// acquire the result and close the write buffer
|
||||
size_t size = tbufTell( &bw );
|
||||
char* data = tbufGetData( &bw, false );
|
||||
|
||||
//------------------------ read -----------------------
|
||||
SBufferReader br = tbufInitReader( data, size, false );
|
||||
// read & print out all integers
|
||||
int32_t count = tbufReadInt32( &br );
|
||||
for( int32_t i = 0; i < count; i++ ) {
|
||||
printf( "%d\n", tbufReadInt32(&br) );
|
||||
}
|
||||
// read & print out a string
|
||||
puts( tbufReadString(&br, NULL) );
|
||||
// try read another integer, this result in an error as there no this integer
|
||||
tbufReadInt32( &br );
|
||||
printf( "you should not see this message.\n" );
|
||||
} CATCH( code ) {
|
||||
printf( "exception code is: %d, you will see this message after print out 5 integers and a string.\n", code );
|
||||
} END_TRY
|
||||
|
||||
tbufCloseWriter( &bw );
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
typedef struct SBufferReader {
|
||||
bool endian;
|
||||
const char* data;
|
||||
size_t pos;
|
||||
size_t size;
|
||||
} SBufferReader;
|
||||
|
||||
typedef struct SBufferWriter {
|
||||
bool endian;
|
||||
char* data;
|
||||
size_t pos;
|
||||
size_t size;
|
||||
void* (*allocator)(void*, size_t);
|
||||
} SBufferWriter;
|
||||
|
||||
// common functions & macros for both reader & writer
|
||||
|
||||
#define tbufTell(buf) ((buf)->pos)
|
||||
|
||||
/* ------------------------ BUFFER WRITER FUNCTIONS AND MACROS ------------------------ */
|
||||
// *Allocator*, function to allocate memory, will use 'realloc' if NULL
|
||||
// *Endian*, if true, writer functions of primitive types will do 'hton' automatically
|
||||
#define tbufInitWriter(Allocator, Endian) \
|
||||
{ .endian = (Endian), .data = NULL, .pos = 0, .size = 0, .allocator = ((Allocator) == NULL ? realloc : (Allocator)) }
|
||||
|
||||
void tbufCloseWriter(SBufferWriter* buf);
|
||||
void tbufEnsureCapacity(SBufferWriter* buf, size_t size);
|
||||
size_t tbufReserve(SBufferWriter* buf, size_t size);
|
||||
char* tbufGetData(SBufferWriter* buf, bool takeOver);
|
||||
void tbufWrite(SBufferWriter* buf, const void* data, size_t size);
|
||||
void tbufWriteAt(SBufferWriter* buf, size_t pos, const void* data, size_t size);
|
||||
void tbufWriteStringLen(SBufferWriter* buf, const char* str, size_t len);
|
||||
void tbufWriteString(SBufferWriter* buf, const char* str);
|
||||
// the prototype of tbufWriteBinary and tbufWrite are identical
|
||||
// the difference is: tbufWriteBinary writes the length of the data to the buffer
|
||||
// first, then the actual data, which means the reader don't need to know data
|
||||
// size before read. Write only write the data itself, which means the reader
|
||||
// need to know data size before read.
|
||||
void tbufWriteBinary(SBufferWriter* buf, const void* data, size_t len);
|
||||
void tbufWriteBool(SBufferWriter* buf, bool data);
|
||||
void tbufWriteBoolAt(SBufferWriter* buf, size_t pos, bool data);
|
||||
void tbufWriteChar(SBufferWriter* buf, char data);
|
||||
void tbufWriteCharAt(SBufferWriter* buf, size_t pos, char data);
|
||||
void tbufWriteInt8(SBufferWriter* buf, int8_t data);
|
||||
void tbufWriteInt8At(SBufferWriter* buf, size_t pos, int8_t data);
|
||||
void tbufWriteUint8(SBufferWriter* buf, uint8_t data);
|
||||
void tbufWriteUint8At(SBufferWriter* buf, size_t pos, uint8_t data);
|
||||
void tbufWriteInt16(SBufferWriter* buf, int16_t data);
|
||||
void tbufWriteInt16At(SBufferWriter* buf, size_t pos, int16_t data);
|
||||
void tbufWriteUint16(SBufferWriter* buf, uint16_t data);
|
||||
void tbufWriteUint16At(SBufferWriter* buf, size_t pos, uint16_t data);
|
||||
void tbufWriteInt32(SBufferWriter* buf, int32_t data);
|
||||
void tbufWriteInt32At(SBufferWriter* buf, size_t pos, int32_t data);
|
||||
void tbufWriteUint32(SBufferWriter* buf, uint32_t data);
|
||||
void tbufWriteUint32At(SBufferWriter* buf, size_t pos, uint32_t data);
|
||||
void tbufWriteInt64(SBufferWriter* buf, int64_t data);
|
||||
void tbufWriteInt64At(SBufferWriter* buf, size_t pos, int64_t data);
|
||||
void tbufWriteUint64(SBufferWriter* buf, uint64_t data);
|
||||
void tbufWriteUint64At(SBufferWriter* buf, size_t pos, uint64_t data);
|
||||
void tbufWriteFloat(SBufferWriter* buf, float data);
|
||||
void tbufWriteFloatAt(SBufferWriter* buf, size_t pos, float data);
|
||||
void tbufWriteDouble(SBufferWriter* buf, double data);
|
||||
void tbufWriteDoubleAt(SBufferWriter* buf, size_t pos, double data);
|
||||
|
||||
/* ------------------------ BUFFER READER FUNCTIONS AND MACROS ------------------------ */
|
||||
// *Endian*, if true, reader functions of primitive types will do 'ntoh' automatically
|
||||
#define tbufInitReader(Data, Size, Endian) \
|
||||
{ .endian = (Endian), .data = (Data), .pos = 0, .size = ((Data) == NULL ? 0 : (Size)) }
|
||||
|
||||
size_t tbufSkip(SBufferReader* buf, size_t size);
|
||||
const char* tbufRead(SBufferReader* buf, size_t size);
|
||||
void tbufReadToBuffer(SBufferReader* buf, void* dst, size_t size);
|
||||
const char* tbufReadString(SBufferReader* buf, size_t* len);
|
||||
size_t tbufReadToString(SBufferReader* buf, char* dst, size_t size);
|
||||
const char* tbufReadBinary(SBufferReader* buf, size_t* len);
|
||||
size_t tbufReadToBinary(SBufferReader* buf, void* dst, size_t size);
|
||||
bool tbufReadBool(SBufferReader* buf);
|
||||
char tbufReadChar(SBufferReader* buf);
|
||||
int8_t tbufReadInt8(SBufferReader* buf);
|
||||
uint8_t tbufReadUint8(SBufferReader* buf);
|
||||
int16_t tbufReadInt16(SBufferReader* buf);
|
||||
uint16_t tbufReadUint16(SBufferReader* buf);
|
||||
int32_t tbufReadInt32(SBufferReader* buf);
|
||||
uint32_t tbufReadUint32(SBufferReader* buf);
|
||||
int64_t tbufReadInt64(SBufferReader* buf);
|
||||
uint64_t tbufReadUint64(SBufferReader* buf);
|
||||
float tbufReadFloat(SBufferReader* buf);
|
||||
double tbufReadDouble(SBufferReader* buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_UTIL_BUFFER_H_*/
|
|
@ -36,17 +36,18 @@ extern "C" {
|
|||
#define FLT_GREATEREQUAL(_x, _y) (FLT_EQUAL((_x), (_y)) || ((_x) > (_y)))
|
||||
#define FLT_LESSEQUAL(_x, _y) (FLT_EQUAL((_x), (_y)) || ((_x) < (_y)))
|
||||
|
||||
#define PATTERN_COMPARE_INFO_INITIALIZER \
|
||||
{ '%', '_' }
|
||||
#define PATTERN_COMPARE_INFO_INITIALIZER { '%', '_', L'%', L'_' }
|
||||
|
||||
typedef struct SPatternCompareInfo {
|
||||
char matchAll; // symbol for match all wildcard, default: '%'
|
||||
char matchOne; // symbol for match one wildcard, default: '_'
|
||||
char matchAll; // symbol for match all wildcard, default: '%'
|
||||
char matchOne; // symbol for match one wildcard, default: '_'
|
||||
TdUcs4 umatchAll; // unicode version matchAll
|
||||
TdUcs4 umatchOne; // unicode version matchOne
|
||||
} SPatternCompareInfo;
|
||||
|
||||
int32_t patternMatch(const char *pattern, const char *str, size_t size, const SPatternCompareInfo *pInfo);
|
||||
int32_t patternMatch(const char *pattern, size_t psize, const char *str, size_t ssize, const SPatternCompareInfo *pInfo);
|
||||
|
||||
int32_t WCSPatternMatch(const TdUcs4 *pattern, const TdUcs4 *str, size_t size, const SPatternCompareInfo *pInfo);
|
||||
int32_t wcsPatternMatch(const TdUcs4 *pattern, size_t psize, const TdUcs4 *str, size_t ssize, const SPatternCompareInfo *pInfo);
|
||||
|
||||
int32_t taosArrayCompareString(const void *a, const void *b);
|
||||
|
||||
|
@ -79,9 +80,11 @@ int32_t compareDoubleVal(const void *pLeft, const void *pRight);
|
|||
int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight);
|
||||
int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareStrRegexComp(const void *pLeft, const void *pRight);
|
||||
int32_t compareStrRegexCompMatch(const void *pLeft, const void *pRight);
|
||||
int32_t compareStrRegexCompNMatch(const void *pLeft, const void *pRight);
|
||||
int32_t comparestrRegexMatch(const void *pLeft, const void *pRight);
|
||||
int32_t comparestrRegexNMatch(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t comparewcsRegexMatch(const void *pLeft, const void *pRight);
|
||||
int32_t comparewcsRegexNMatch(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareInt8ValDesc(const void *pLeft, const void *pRight);
|
||||
int32_t compareInt16ValDesc(const void *pLeft, const void *pRight);
|
||||
|
@ -99,11 +102,11 @@ int32_t compareUint64ValDesc(const void *pLeft, const void *pRight);
|
|||
int32_t compareLenPrefixedStrDesc(const void *pLeft, const void *pRight);
|
||||
int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareStrPatternMatch(const void *pLeft, const void *pRight);
|
||||
int32_t compareStrPatternNotMatch(const void *pLeft, const void *pRight);
|
||||
int32_t comparestrPatternMatch(const void *pLeft, const void *pRight);
|
||||
int32_t comparestrPatternNMatch(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight);
|
||||
int32_t compareWStrPatternNotMatch(const void *pLeft, const void *pRight);
|
||||
int32_t comparewcsPatternMatch(const void *pLeft, const void *pRight);
|
||||
int32_t comparewcsPatternNMatch(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareInt8Int16(const void *pLeft, const void *pRight);
|
||||
int32_t compareInt8Int32(const void *pLeft, const void *pRight);
|
||||
|
|
|
@ -194,6 +194,7 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_TOPIC_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_CGROUP_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_USER_CGROUP_LEN (TSDB_USER_LEN + TSDB_CGROUP_LEN) // it is a null-terminated string
|
||||
#define TSDB_STREAM_NAME_LEN 193 // it is a null-terminated string
|
||||
#define TSDB_DB_NAME_LEN 65
|
||||
#define TSDB_DB_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
|
||||
|
@ -213,8 +214,8 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_INDEX_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_INDEX_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
#define TSDB_TYPE_STR_MAX_LEN 32
|
||||
#define TSDB_TABLE_FNAME_LEN (TSDB_DB_FNAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
#define TSDB_TOPIC_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
#define TSDB_STREAM_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_TABLE_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
#define TSDB_TOPIC_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_TOPIC_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
#define TSDB_STREAM_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_STREAM_NAME_LEN + TSDB_NAME_DELIMITER_LEN)
|
||||
#define TSDB_SUBSCRIBE_KEY_LEN (TSDB_CGROUP_LEN + TSDB_TOPIC_FNAME_LEN + 2)
|
||||
#define TSDB_PARTITION_KEY_LEN (TSDB_SUBSCRIBE_KEY_LEN + 20)
|
||||
#define TSDB_COL_NAME_LEN 65
|
||||
|
@ -311,7 +312,7 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_MIN_KEEP (1 * 1440) // data in db to be reserved. unit minute
|
||||
#define TSDB_MAX_KEEP (365000 * 1440) // data in db to be reserved.
|
||||
#define TSDB_MAX_KEEP_NS (365 * 292 * 1440) // data in db to be reserved.
|
||||
#define TSDB_DEFAULT_KEEP (3650 * 1440) // ten years
|
||||
#define TSDB_DEFAULT_KEEP (3650 * 1440) // ten years
|
||||
#define TSDB_MIN_MINROWS_FBLOCK 10
|
||||
#define TSDB_MAX_MINROWS_FBLOCK 1000
|
||||
#define TSDB_DEFAULT_MINROWS_FBLOCK 100
|
||||
|
|
|
@ -30,6 +30,27 @@ extern "C" {
|
|||
val = _tmp; \
|
||||
} while (0)
|
||||
|
||||
#define tjsonGetInt32ValueFromDouble(pJson, pName, val, code) \
|
||||
do { \
|
||||
double _tmp = 0; \
|
||||
code = tjsonGetDoubleValue(pJson, pName, &_tmp); \
|
||||
val = (int32_t)_tmp; \
|
||||
} while (0)
|
||||
|
||||
#define tjsonGetInt8ValueFromDouble(pJson, pName, val, code) \
|
||||
do { \
|
||||
double _tmp = 0; \
|
||||
code = tjsonGetDoubleValue(pJson, pName, &_tmp); \
|
||||
val = (int8_t)_tmp; \
|
||||
} while (0)
|
||||
|
||||
#define tjsonGetUInt16ValueFromDouble(pJson, pName, val, code) \
|
||||
do { \
|
||||
double _tmp = 0; \
|
||||
code = tjsonGetDoubleValue(pJson, pName, &_tmp); \
|
||||
val = (uint16_t)_tmp; \
|
||||
} while (0)
|
||||
|
||||
typedef void SJson;
|
||||
|
||||
SJson* tjsonCreateObject();
|
||||
|
|
|
@ -83,9 +83,21 @@ void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, cons
|
|||
#endif
|
||||
;
|
||||
|
||||
bool taosAssert(bool condition, const char *file, int32_t line, const char *format, ...);
|
||||
#define ASSERTS(condition, ...) taosAssert(condition, __FILE__, __LINE__, __VA_ARGS__)
|
||||
#define ASSERT(condition) ASSERTS(condition, "assert info not provided")
|
||||
bool taosAssertDebug(bool condition, const char *file, int32_t line, const char *format, ...);
|
||||
bool taosAssertRelease(bool condition);
|
||||
|
||||
// Disable all asserts that may compromise the performance.
|
||||
#if defined DISABLE_ASSERT
|
||||
#define ASSERT(condition)
|
||||
#define ASSERTS(condition, ...)
|
||||
#else
|
||||
#define ASSERTS(condition, ...) taosAssertDebug(condition, __FILE__, __LINE__, __VA_ARGS__)
|
||||
#ifdef NDEBUG
|
||||
#define ASSERT(condition) taosAssertRelease(condition)
|
||||
#else
|
||||
#define ASSERT(condition) taosAssertDebug(condition, __FILE__, __LINE__, "assert info not provided")
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// clang-format off
|
||||
#define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", DEBUG_FATAL, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
|
||||
|
|
|
@ -29,11 +29,17 @@ extern "C" {
|
|||
int32_t strdequote(char *src);
|
||||
size_t strtrim(char *src);
|
||||
char *strnchr(const char *haystack, char needle, int32_t len, bool skipquote);
|
||||
TdUcs4* wcsnchr(const TdUcs4* haystack, TdUcs4 needle, size_t len);
|
||||
|
||||
char **strsplit(char *src, const char *delim, int32_t *num);
|
||||
char *strtolower(char *dst, const char *src);
|
||||
char *strntolower(char *dst, const char *src, int32_t n);
|
||||
char *strntolower_s(char *dst, const char *src, int32_t n);
|
||||
int64_t strnatoi(char *num, int32_t len);
|
||||
|
||||
size_t tstrncspn(const char *str, size_t ssize, const char *reject, size_t rsize);
|
||||
size_t twcsncspn(const TdUcs4 *wcs, size_t size, const TdUcs4 *reject, size_t rsize);
|
||||
|
||||
char *strbetween(char *string, char *begin, char *end);
|
||||
char *paGetToken(char *src, char **token, int32_t *tokenLen);
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ extern "C" {
|
|||
#define VALUE "_value"
|
||||
#define VALUE_LEN 6
|
||||
|
||||
#define OTD_JSON_FIELDS_NUM 4
|
||||
#define MAX_RETRY_TIMES 5
|
||||
typedef TSDB_SML_PROTOCOL_TYPE SMLProtocolType;
|
||||
|
||||
|
@ -177,12 +178,15 @@ typedef struct {
|
|||
int32_t lineNum;
|
||||
SSmlMsgBuf msgBuf;
|
||||
|
||||
// cJSON *root; // for parse json
|
||||
int8_t offset[4];
|
||||
cJSON *root; // for parse json
|
||||
int8_t offset[OTD_JSON_FIELDS_NUM];
|
||||
SSmlLineInfo *lines; // element is SSmlLineInfo
|
||||
bool parseJsonByLib;
|
||||
SArray *tagJsonArray;
|
||||
|
||||
//
|
||||
SArray *preLineTagKV;
|
||||
SArray *maxTagKVs;
|
||||
SArray *preLineColKV;
|
||||
|
||||
SSmlLineInfo preLine;
|
||||
|
@ -197,7 +201,7 @@ typedef struct {
|
|||
#define IS_SAME_SUPER_TABLE (elements->measureLen == info->preLine.measureLen \
|
||||
&& memcmp(elements->measure, info->preLine.measure, elements->measureLen) == 0)
|
||||
|
||||
#define IS_SAME_KEY (preKV->keyLen == kv.keyLen && memcmp(preKV->key, kv.key, kv.keyLen) == 0)
|
||||
#define IS_SAME_KEY (maxKV->keyLen == kv.keyLen && memcmp(maxKV->key, kv.key, kv.keyLen) == 0)
|
||||
|
||||
extern int64_t smlFactorNS[3];
|
||||
extern int64_t smlFactorS[3];
|
||||
|
@ -206,9 +210,9 @@ typedef int32_t (*_equal_fn_sml)(const void *, const void *);
|
|||
|
||||
SSmlHandle *smlBuildSmlInfo(TAOS *taos);
|
||||
void smlDestroyInfo(SSmlHandle *info);
|
||||
void smlJsonParseObjFirst(char **start, SSmlLineInfo *element, int8_t *offset);
|
||||
void smlJsonParseObj(char **start, SSmlLineInfo *element, int8_t *offset);
|
||||
SArray *smlJsonParseTags(char *start, char *end);
|
||||
int smlJsonParseObjFirst(char **start, SSmlLineInfo *element, int8_t *offset);
|
||||
int smlJsonParseObj(char **start, SSmlLineInfo *element, int8_t *offset);
|
||||
//SArray *smlJsonParseTags(char *start, char *end);
|
||||
bool smlParseNumberOld(SSmlKv *kvVal, SSmlMsgBuf *msg);
|
||||
void* nodeListGet(NodeList* list, const void *key, int32_t len, _equal_fn_sml fn);
|
||||
int nodeListSet(NodeList** list, const void *key, int32_t len, void* value, _equal_fn_sml fn);
|
||||
|
@ -226,6 +230,8 @@ int32_t is_same_child_table_telnet(const void *a, const void *b);
|
|||
int64_t smlParseOpenTsdbTime(SSmlHandle *info, const char *data, int32_t len);
|
||||
int32_t smlClearForRerun(SSmlHandle *info);
|
||||
int32_t smlParseValue(SSmlKv *pVal, SSmlMsgBuf *msg);
|
||||
uint8_t smlGetTimestampLen(int64_t num);
|
||||
void clearColValArray(SArray* pCols);
|
||||
|
||||
int32_t smlParseInfluxString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLineInfo *elements);
|
||||
int32_t smlParseTelnetString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLineInfo *elements);
|
||||
|
|
|
@ -272,7 +272,7 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC
|
|||
|
||||
int32_t execLocalCmd(SRequestObj* pRequest, SQuery* pQuery) {
|
||||
SRetrieveTableRsp* pRsp = NULL;
|
||||
int32_t code = qExecCommand(pRequest->pTscObj->sysInfo, pQuery->pRoot, &pRsp);
|
||||
int32_t code = qExecCommand(&pRequest->pTscObj->id, pRequest->pTscObj->sysInfo, pQuery->pRoot, &pRsp);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pRsp) {
|
||||
code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false, true);
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ void asyncExecLocalCmd(SRequestObj* pRequest, SQuery* pQuery) {
|
|||
return;
|
||||
}
|
||||
|
||||
int32_t code = qExecCommand(pRequest->pTscObj->sysInfo, pQuery->pRoot, &pRsp);
|
||||
int32_t code = qExecCommand(&pRequest->pTscObj->id ,pRequest->pTscObj->sysInfo, pQuery->pRoot, &pRsp);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pRsp) {
|
||||
code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false, true);
|
||||
}
|
||||
|
|
|
@ -802,7 +802,7 @@ static void doAsyncQueryFromParse(SMetaData *pResultMeta, void *param, int32_t c
|
|||
tstrerror(code));
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
//pWrapper->pCatalogReq->forceUpdate = false;
|
||||
// pWrapper->pCatalogReq->forceUpdate = false;
|
||||
code = qContinueParseSql(pWrapper->pParseCtx, pWrapper->pCatalogReq, pResultMeta, pQuery);
|
||||
}
|
||||
|
||||
|
@ -831,8 +831,8 @@ void continueInsertFromCsv(SSqlCallbackWrapper *pWrapper, SRequestObj *pRequest)
|
|||
tstrerror(code), pWrapper->pRequest->requestId);
|
||||
destorySqlCallbackWrapper(pWrapper);
|
||||
terrno = code;
|
||||
pWrapper->pRequest->code = code;
|
||||
pWrapper->pRequest->body.queryFp(pWrapper->pRequest->body.param, pWrapper->pRequest, code);
|
||||
pRequest->code = code;
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1167,6 +1167,54 @@ _return:
|
|||
return code;
|
||||
}
|
||||
|
||||
int taos_get_tables_vgId(TAOS *taos, const char *db, const char *table[], int tableNum, int *vgId) {
|
||||
if (NULL == taos) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (NULL == db || NULL == table || NULL == vgId || tableNum <= 0) {
|
||||
tscError("invalid input param, db:%p, table:%p, vgId:%p, tbNum:%d", db, table, vgId, tableNum);
|
||||
terrno = TSDB_CODE_TSC_INVALID_INPUT;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
int64_t connId = *(int64_t *)taos;
|
||||
SRequestObj *pRequest = NULL;
|
||||
char *sql = "taos_get_table_vgId";
|
||||
int32_t code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest, 0);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pRequest->syncQuery = true;
|
||||
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
SCatalog *pCtg = NULL;
|
||||
code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCtg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _return;
|
||||
}
|
||||
|
||||
SRequestConnInfo conn = {
|
||||
.pTrans = pTscObj->pAppInfo->pTransporter, .requestId = pRequest->requestId, .requestObjRefId = pRequest->self};
|
||||
|
||||
conn.mgmtEps = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
code = catalogGetTablesHashVgId(pCtg, &conn, pTscObj->acctId, db, table, tableNum, vgId);
|
||||
if (code) {
|
||||
goto _return;
|
||||
}
|
||||
|
||||
_return:
|
||||
|
||||
terrno = code;
|
||||
|
||||
destroyRequest(pRequest);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
int taos_load_table_info(TAOS *taos, const char *tableNameList) {
|
||||
if (NULL == taos) {
|
||||
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||
|
@ -1330,6 +1378,13 @@ int taos_stmt_get_col_fields(TAOS_STMT *stmt, int *fieldNum, TAOS_FIELD_E **fiel
|
|||
return stmtGetColFields(stmt, fieldNum, fields);
|
||||
}
|
||||
|
||||
// let stmt to reclaim TAOS_FIELD_E that was allocated by `taos_stmt_get_tag_fields`/`taos_stmt_get_col_fields`
|
||||
void taos_stmt_reclaim_fields(TAOS_STMT *stmt, TAOS_FIELD_E *fields) {
|
||||
(void)stmt;
|
||||
if (!fields) return;
|
||||
taosMemoryFree(fields);
|
||||
}
|
||||
|
||||
int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
|
||||
if (stmt == NULL || bind == NULL) {
|
||||
tscError("NULL parameter for %s", __FUNCTION__);
|
||||
|
|
|
@ -1008,18 +1008,32 @@ static int32_t smlUpdateMeta(SHashObj *metaHash, SArray *metaArray, SArray *cols
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void smlDestroyTableInfo(SSmlTableInfo *tag) {
|
||||
static void smlDestroyTableInfo(SSmlHandle *info, SSmlTableInfo *tag) {
|
||||
for (size_t i = 0; i < taosArrayGetSize(tag->cols); i++) {
|
||||
SHashObj *kvHash = (SHashObj *)taosArrayGetP(tag->cols, i);
|
||||
taosHashCleanup(kvHash);
|
||||
}
|
||||
|
||||
if(info->parseJsonByLib){
|
||||
SSmlLineInfo *key = (SSmlLineInfo *)(tag->key);
|
||||
if(key != NULL) taosMemoryFree(key->tags);
|
||||
}
|
||||
taosMemoryFree(tag->key);
|
||||
taosArrayDestroy(tag->cols);
|
||||
taosArrayDestroy(tag->tags);
|
||||
taosMemoryFree(tag);
|
||||
}
|
||||
|
||||
void clearColValArray(SArray* pCols) {
|
||||
int32_t num = taosArrayGetSize(pCols);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SColVal* pCol = taosArrayGet(pCols, i);
|
||||
if (TSDB_DATA_TYPE_NCHAR == pCol->type) {
|
||||
taosMemoryFreeClear(pCol->value.pData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void smlDestroyInfo(SSmlHandle *info) {
|
||||
if (!info) return;
|
||||
qDestroyQuery(info->pQuery);
|
||||
|
@ -1028,7 +1042,7 @@ void smlDestroyInfo(SSmlHandle *info) {
|
|||
NodeList *tmp = info->childTables;
|
||||
while (tmp) {
|
||||
if (tmp->data.used) {
|
||||
smlDestroyTableInfo((SSmlTableInfo *)tmp->data.value);
|
||||
smlDestroyTableInfo(info, (SSmlTableInfo *)tmp->data.value);
|
||||
}
|
||||
NodeList *t = tmp->next;
|
||||
taosMemoryFree(tmp);
|
||||
|
@ -1049,16 +1063,27 @@ void smlDestroyInfo(SSmlHandle *info) {
|
|||
// destroy info->pVgHash
|
||||
taosHashCleanup(info->pVgHash);
|
||||
|
||||
for(int i = 0; i< taosArrayGetSize(info->tagJsonArray); i++){
|
||||
cJSON *tags = (cJSON *)taosArrayGetP(info->tagJsonArray, i);
|
||||
cJSON_Delete(tags);
|
||||
}
|
||||
taosArrayDestroy(info->tagJsonArray);
|
||||
|
||||
taosArrayDestroy(info->preLineTagKV);
|
||||
taosArrayDestroy(info->maxTagKVs);
|
||||
taosArrayDestroy(info->preLineColKV);
|
||||
|
||||
if (!info->dataFormat) {
|
||||
for (int i = 0; i < info->lineNum; i++) {
|
||||
taosArrayDestroy(info->lines[i].colArray);
|
||||
if(info->parseJsonByLib){
|
||||
taosMemoryFree(info->lines[i].tags);
|
||||
}
|
||||
}
|
||||
taosMemoryFree(info->lines);
|
||||
}
|
||||
|
||||
cJSON_Delete(info->root);
|
||||
taosMemoryFreeClear(info);
|
||||
}
|
||||
|
||||
|
@ -1082,7 +1107,9 @@ SSmlHandle *smlBuildSmlInfo(TAOS *taos) {
|
|||
info->pQuery = smlInitHandle();
|
||||
info->dataFormat = true;
|
||||
|
||||
info->tagJsonArray = taosArrayInit(8, POINTER_BYTES);
|
||||
info->preLineTagKV = taosArrayInit(8, sizeof(SSmlKv));
|
||||
info->maxTagKVs = taosArrayInit(8, sizeof(SSmlKv));
|
||||
info->preLineColKV = taosArrayInit(8, sizeof(SSmlKv));
|
||||
|
||||
if (NULL == info->pVgHash) {
|
||||
|
@ -1251,7 +1278,7 @@ int32_t smlClearForRerun(SSmlHandle *info) {
|
|||
NodeList *pList = info->childTables;
|
||||
while (pList) {
|
||||
if (pList->data.used) {
|
||||
smlDestroyTableInfo((SSmlTableInfo *)pList->data.value);
|
||||
smlDestroyTableInfo(info, (SSmlTableInfo *)pList->data.value);
|
||||
pList->data.used = false;
|
||||
}
|
||||
pList = pList->next;
|
||||
|
@ -1267,11 +1294,13 @@ int32_t smlClearForRerun(SSmlHandle *info) {
|
|||
pList = pList->next;
|
||||
}
|
||||
|
||||
if (unlikely(info->lines != NULL)) {
|
||||
uError("SML:0x%" PRIx64 " info->lines != NULL", info->id);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
if (!info->dataFormat){
|
||||
if (unlikely(info->lines != NULL)) {
|
||||
uError("SML:0x%" PRIx64 " info->lines != NULL", info->id);
|
||||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
info->lines = (SSmlLineInfo *)taosMemoryCalloc(info->lineNum, sizeof(SSmlLineInfo));
|
||||
}
|
||||
info->lines = (SSmlLineInfo *)taosMemoryCalloc(info->lineNum, sizeof(SSmlLineInfo));
|
||||
|
||||
memset(&info->preLine, 0, sizeof(SSmlLineInfo));
|
||||
info->currSTableMeta = NULL;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -57,52 +57,6 @@ uint8_t smlPrecisionConvert[7] = {TSDB_TIME_PRECISION_NANO, TSDB_TIME_PRECISION_
|
|||
TSDB_TIME_PRECISION_SECONDS, TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO,
|
||||
TSDB_TIME_PRECISION_NANO};
|
||||
|
||||
static bool smlParseBool(SSmlKv *kvVal) {
|
||||
const char *pVal = kvVal->value;
|
||||
int32_t len = kvVal->length;
|
||||
if ((len == 1) && (pVal[0] == 't' || pVal[0] == 'T')) {
|
||||
kvVal->i = TSDB_TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((len == 1) && (pVal[0] == 'f' || pVal[0] == 'F')) {
|
||||
kvVal->i = TSDB_FALSE;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((len == 4) && !strncasecmp(pVal, "true", len)) {
|
||||
kvVal->i = TSDB_TRUE;
|
||||
return true;
|
||||
}
|
||||
if ((len == 5) && !strncasecmp(pVal, "false", len)) {
|
||||
kvVal->i = TSDB_FALSE;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool smlIsBinary(const char *pVal, uint16_t len) {
|
||||
// binary: "abc"
|
||||
if (len < 2) {
|
||||
return false;
|
||||
}
|
||||
if (pVal[0] == '"' && pVal[len - 1] == '"') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool smlIsNchar(const char *pVal, uint16_t len) {
|
||||
// nchar: L"abc"
|
||||
if (len < 3) {
|
||||
return false;
|
||||
}
|
||||
if (pVal[1] == '"' && pVal[len - 1] == '"' && (pVal[0] == 'l' || pVal[0] == 'L')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int64_t smlParseInfluxTime(SSmlHandle *info, const char *data, int32_t len) {
|
||||
uint8_t toPrecision = info->currSTableMeta ? info->currSTableMeta->tableInfo.precision : TSDB_TIME_PRECISION_NANO;
|
||||
|
||||
|
@ -189,6 +143,7 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd,
|
|||
|
||||
int cnt = 0;
|
||||
SArray *preLineKV = info->preLineTagKV;
|
||||
SArray *maxKVs = info->maxTagKVs;
|
||||
bool isSuperKVInit = true;
|
||||
SArray *superKV = NULL;
|
||||
if(info->dataFormat){
|
||||
|
@ -196,14 +151,14 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd,
|
|||
SSmlSTableMeta *sMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, currElement->measure, currElement->measureLen, NULL);
|
||||
|
||||
if(unlikely(sMeta == NULL)){
|
||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||
STableMeta * pTableMeta = smlGetMeta(info, currElement->measure, currElement->measureLen);
|
||||
sMeta->tableMeta = pTableMeta;
|
||||
if(pTableMeta == NULL){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||
sMeta->tableMeta = pTableMeta;
|
||||
nodeListSet(&info->superTables, currElement->measure, currElement->measureLen, sMeta, NULL);
|
||||
}
|
||||
info->currSTableMeta = sMeta->tableMeta;
|
||||
|
@ -212,12 +167,12 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd,
|
|||
if(unlikely(taosArrayGetSize(superKV) == 0)){
|
||||
isSuperKVInit = false;
|
||||
}
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
taosArraySetSize(maxKVs, 0);
|
||||
}
|
||||
}else{
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
taosArraySetSize(maxKVs, 0);
|
||||
}
|
||||
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
|
||||
while (*sql < sqlEnd) {
|
||||
if (unlikely(IS_SPACE(*sql))) {
|
||||
|
@ -295,14 +250,14 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd,
|
|||
}
|
||||
|
||||
if(isSameMeasure){
|
||||
if(unlikely(cnt >= taosArrayGetSize(preLineKV))) {
|
||||
if(unlikely(cnt >= taosArrayGetSize(maxKVs))) {
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(preLineKV, cnt);
|
||||
if(unlikely(kv.length > preKV->length)){
|
||||
preKV->length = kv.length;
|
||||
SSmlKv *maxKV = (SSmlKv *)taosArrayGet(maxKVs, cnt);
|
||||
if(unlikely(kv.length > maxKV->length)){
|
||||
maxKV->length = kv.length;
|
||||
SSmlSTableMeta *tableMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, currElement->measure, currElement->measureLen, NULL);
|
||||
ASSERT(tableMeta != NULL);
|
||||
|
||||
|
@ -322,11 +277,11 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd,
|
|||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(superKV, cnt);
|
||||
if(unlikely(kv.length > preKV->length)) {
|
||||
preKV->length = kv.length;
|
||||
SSmlKv *maxKV = (SSmlKv *)taosArrayGet(superKV, cnt);
|
||||
if(unlikely(kv.length > maxKV->length)) {
|
||||
maxKV->length = kv.length;
|
||||
}else{
|
||||
kv.length = preKV->length;
|
||||
kv.length = maxKV->length;
|
||||
}
|
||||
info->needModifySchema = true;
|
||||
|
||||
|
@ -338,11 +293,12 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd,
|
|||
}else{
|
||||
taosArrayPush(superKV, &kv);
|
||||
}
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
taosArrayPush(maxKVs, &kv);
|
||||
}
|
||||
}else{
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
taosArrayPush(maxKVs, &kv);
|
||||
}
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
|
||||
cnt++;
|
||||
if(IS_SPACE(*sql)){
|
||||
|
@ -397,14 +353,14 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd,
|
|||
SSmlSTableMeta *sMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, currElement->measure, currElement->measureLen, NULL);
|
||||
|
||||
if(unlikely(sMeta == NULL)){
|
||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||
STableMeta * pTableMeta = smlGetMeta(info, currElement->measure, currElement->measureLen);
|
||||
sMeta->tableMeta = pTableMeta;
|
||||
if(pTableMeta == NULL){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||
sMeta->tableMeta = pTableMeta;
|
||||
nodeListSet(&info->superTables, currElement->measure, currElement->measureLen, sMeta, NULL);
|
||||
}
|
||||
info->currSTableMeta = sMeta->tableMeta;
|
||||
|
@ -518,15 +474,15 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd,
|
|||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(preLineKV, cnt);
|
||||
if(kv.type != preKV->type){
|
||||
SSmlKv *maxKV = (SSmlKv *)taosArrayGet(preLineKV, cnt);
|
||||
if(kv.type != maxKV->type){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if(unlikely(IS_VAR_DATA_TYPE(kv.type) && kv.length > preKV->length)){
|
||||
preKV->length = kv.length;
|
||||
if(unlikely(IS_VAR_DATA_TYPE(kv.type) && kv.length > maxKV->length)){
|
||||
maxKV->length = kv.length;
|
||||
SSmlSTableMeta *tableMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, currElement->measure, currElement->measureLen, NULL);
|
||||
ASSERT(tableMeta != NULL);
|
||||
|
||||
|
@ -546,18 +502,18 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd,
|
|||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(superKV, cnt);
|
||||
if(unlikely(kv.type != preKV->type)){
|
||||
SSmlKv *maxKV = (SSmlKv *)taosArrayGet(superKV, cnt);
|
||||
if(unlikely(kv.type != maxKV->type)){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if(IS_VAR_DATA_TYPE(kv.type)){
|
||||
if(kv.length > preKV->length) {
|
||||
preKV->length = kv.length;
|
||||
if(kv.length > maxKV->length) {
|
||||
maxKV->length = kv.length;
|
||||
}else{
|
||||
kv.length = preKV->length;
|
||||
kv.length = maxKV->length;
|
||||
}
|
||||
info->needModifySchema = true;
|
||||
}
|
||||
|
@ -690,6 +646,7 @@ int32_t smlParseInfluxString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLine
|
|||
if(info->dataFormat){
|
||||
smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, &kv, 0);
|
||||
smlBuildRow(info->currTableDataCtx);
|
||||
clearColValArray(info->currTableDataCtx->pValues);
|
||||
}else{
|
||||
taosArraySet(elements->colArray, 0, &kv);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,11 @@
|
|||
int32_t is_same_child_table_telnet(const void *a, const void *b){
|
||||
SSmlLineInfo *t1 = (SSmlLineInfo *)a;
|
||||
SSmlLineInfo *t2 = (SSmlLineInfo *)b;
|
||||
// uError("is_same_child_table_telnet len:%d,%d %s,%s @@@ len:%d,%d %s,%s", t1->measureLen, t2->measureLen,
|
||||
// t1->measure, t2->measure, t1->tagsLen, t2->tagsLen, t1->tags, t2->tags);
|
||||
if(t1 == NULL || t2 == NULL || t1->measure == NULL || t2->measure == NULL
|
||||
|| t1->tags == NULL || t2->tags == NULL)
|
||||
return 1;
|
||||
return (((t1->measureLen == t2->measureLen) && memcmp(t1->measure, t2->measure, t1->measureLen) == 0)
|
||||
&& ((t1->tagsLen == t2->tagsLen) && memcmp(t1->tags, t2->tags, t1->tagsLen) == 0)) ? 0 : 1;
|
||||
}
|
||||
|
@ -73,6 +78,7 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS
|
|||
|
||||
int cnt = 0;
|
||||
SArray *preLineKV = info->preLineTagKV;
|
||||
SArray *maxKVs = info->maxTagKVs;
|
||||
bool isSuperKVInit = true;
|
||||
SArray *superKV = NULL;
|
||||
if(info->dataFormat){
|
||||
|
@ -80,14 +86,14 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS
|
|||
SSmlSTableMeta *sMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, elements->measure, elements->measureLen, NULL);
|
||||
|
||||
if(unlikely(sMeta == NULL)){
|
||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||
STableMeta * pTableMeta = smlGetMeta(info, elements->measure, elements->measureLen);
|
||||
sMeta->tableMeta = pTableMeta;
|
||||
if(pTableMeta == NULL){
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
sMeta = smlBuildSTableMeta(info->dataFormat);
|
||||
sMeta->tableMeta = pTableMeta;
|
||||
nodeListSet(&info->superTables, elements->measure, elements->measureLen, sMeta, NULL);
|
||||
}
|
||||
info->currSTableMeta = sMeta->tableMeta;
|
||||
|
@ -96,12 +102,13 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS
|
|||
if(unlikely(taosArrayGetSize(superKV) == 0)){
|
||||
isSuperKVInit = false;
|
||||
}
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
taosArraySetSize(maxKVs, 0);
|
||||
}
|
||||
}else{
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
taosArraySetSize(maxKVs, 0);
|
||||
}
|
||||
|
||||
taosArraySetSize(preLineKV, 0);
|
||||
const char *sql = data;
|
||||
while (sql < sqlEnd) {
|
||||
JUMP_SPACE(sql, sqlEnd)
|
||||
|
@ -168,14 +175,14 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS
|
|||
}
|
||||
|
||||
if(isSameMeasure){
|
||||
if(unlikely(cnt >= taosArrayGetSize(preLineKV))) {
|
||||
if(unlikely(cnt >= taosArrayGetSize(maxKVs))) {
|
||||
info->dataFormat = false;
|
||||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(preLineKV, cnt);
|
||||
if(unlikely(kv.length > preKV->length)){
|
||||
preKV->length = kv.length;
|
||||
SSmlKv *maxKV = (SSmlKv *)taosArrayGet(maxKVs, cnt);
|
||||
if(unlikely(kv.length > maxKV->length)){
|
||||
maxKV->length = kv.length;
|
||||
SSmlSTableMeta *tableMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, elements->measure, elements->measureLen, NULL);
|
||||
ASSERT(tableMeta != NULL);
|
||||
|
||||
|
@ -195,11 +202,11 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS
|
|||
info->reRun = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SSmlKv *preKV = (SSmlKv *)taosArrayGet(superKV, cnt);
|
||||
if(unlikely(kv.length > preKV->length)) {
|
||||
preKV->length = kv.length;
|
||||
SSmlKv *maxKV = (SSmlKv *)taosArrayGet(superKV, cnt);
|
||||
if(unlikely(kv.length > maxKV->length)) {
|
||||
maxKV->length = kv.length;
|
||||
}else{
|
||||
kv.length = preKV->length;
|
||||
kv.length = maxKV->length;
|
||||
}
|
||||
info->needModifySchema = true;
|
||||
|
||||
|
@ -211,11 +218,12 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS
|
|||
}else{
|
||||
taosArrayPush(superKV, &kv);
|
||||
}
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
taosArrayPush(maxKVs, &kv);
|
||||
}
|
||||
}else{
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
taosArrayPush(maxKVs, &kv);
|
||||
}
|
||||
taosArrayPush(preLineKV, &kv);
|
||||
cnt++;
|
||||
}
|
||||
SSmlTableInfo *tinfo = (SSmlTableInfo *)nodeListGet(info->childTables, elements, POINTER_BYTES, is_same_child_table_telnet);
|
||||
|
@ -316,6 +324,7 @@ int32_t smlParseTelnetString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLine
|
|||
if(ret == TSDB_CODE_SUCCESS){
|
||||
ret = smlBuildRow(info->currTableDataCtx);
|
||||
}
|
||||
clearColValArray(info->currTableDataCtx->pValues);
|
||||
if (unlikely(ret != TSDB_CODE_SUCCESS)) {
|
||||
smlBuildInvalidDataMsg(&info->msgBuf, "smlBuildCol error", NULL);
|
||||
return ret;
|
||||
|
|
|
@ -909,10 +909,12 @@ void tmqFreeImpl(void* handle) {
|
|||
tmq_t* tmq = (tmq_t*)handle;
|
||||
|
||||
// TODO stop timer
|
||||
tmqClearUnhandleMsg(tmq);
|
||||
if (tmq->mqueue) taosCloseQueue(tmq->mqueue);
|
||||
if (tmq->mqueue) {
|
||||
tmqClearUnhandleMsg(tmq);
|
||||
taosCloseQueue(tmq->mqueue);
|
||||
}
|
||||
if (tmq->delayedTask) taosCloseQueue(tmq->delayedTask);
|
||||
if (tmq->qall) taosFreeQall(tmq->qall);
|
||||
taosFreeQall(tmq->qall);
|
||||
|
||||
tsem_destroy(&tmq->rspSem);
|
||||
|
||||
|
|
|
@ -411,28 +411,28 @@ TEST(testCase, smlParseCols_Test) {
|
|||
smlDestroyInfo(info);
|
||||
}
|
||||
|
||||
//TEST(testCase, smlGetTimestampLen_Test) {
|
||||
// uint8_t len = smlGetTimestampLen(0);
|
||||
// ASSERT_EQ(len, 1);
|
||||
//
|
||||
// len = smlGetTimestampLen(1);
|
||||
// ASSERT_EQ(len, 1);
|
||||
//
|
||||
// len = smlGetTimestampLen(10);
|
||||
// ASSERT_EQ(len, 2);
|
||||
//
|
||||
// len = smlGetTimestampLen(390);
|
||||
// ASSERT_EQ(len, 3);
|
||||
//
|
||||
// len = smlGetTimestampLen(-1);
|
||||
// ASSERT_EQ(len, 1);
|
||||
//
|
||||
// len = smlGetTimestampLen(-10);
|
||||
// ASSERT_EQ(len, 2);
|
||||
//
|
||||
// len = smlGetTimestampLen(-390);
|
||||
// ASSERT_EQ(len, 3);
|
||||
//}
|
||||
TEST(testCase, smlGetTimestampLen_Test) {
|
||||
uint8_t len = smlGetTimestampLen(0);
|
||||
ASSERT_EQ(len, 1);
|
||||
|
||||
len = smlGetTimestampLen(1);
|
||||
ASSERT_EQ(len, 1);
|
||||
|
||||
len = smlGetTimestampLen(10);
|
||||
ASSERT_EQ(len, 2);
|
||||
|
||||
len = smlGetTimestampLen(390);
|
||||
ASSERT_EQ(len, 3);
|
||||
|
||||
len = smlGetTimestampLen(-1);
|
||||
ASSERT_EQ(len, 1);
|
||||
|
||||
len = smlGetTimestampLen(-10);
|
||||
ASSERT_EQ(len, 2);
|
||||
|
||||
len = smlGetTimestampLen(-390);
|
||||
ASSERT_EQ(len, 3);
|
||||
}
|
||||
|
||||
TEST(testCase, smlParseNumber_Test) {
|
||||
SSmlKv kv = {0};
|
||||
|
@ -503,35 +503,35 @@ TEST(testCase, smlParseTelnetLine_Test) {
|
|||
smlDestroyInfo(info);
|
||||
}
|
||||
|
||||
TEST(testCase, smlParseTelnetLine_diff_json_type2_Test) {
|
||||
SSmlHandle *info = smlBuildSmlInfo(NULL);
|
||||
info->protocol = TSDB_SML_JSON_PROTOCOL;
|
||||
ASSERT_NE(info, nullptr);
|
||||
|
||||
const char *sql[] = {
|
||||
"[{\"metric\":\"sys.cpu.nice\",\"timestamp\": 1346846400,\"value\": 18,\"tags\": {\"host\": \"lga\"}},{\"metric\": \"sys.sdfa\",\"timestamp\": 1346846400,\"value\": \"18\",\"tags\": {\"host\": 8932}},]",
|
||||
};
|
||||
for (int i = 0; i < sizeof(sql) / sizeof(sql[0]); i++) {
|
||||
char *dataPointStart = (char *)sql[i];
|
||||
int8_t offset[4] = {0};
|
||||
while (1) {
|
||||
SSmlLineInfo elements = {0};
|
||||
if(offset[0] == 0){
|
||||
smlJsonParseObjFirst(&dataPointStart, &elements, offset);
|
||||
}else{
|
||||
smlJsonParseObj(&dataPointStart, &elements, offset);
|
||||
}
|
||||
if(*dataPointStart == '\0') break;
|
||||
|
||||
SArray *tags = smlJsonParseTags(elements.tags, elements.tags + elements.tagsLen);
|
||||
size_t num = taosArrayGetSize(tags);
|
||||
ASSERT_EQ(num, 1);
|
||||
|
||||
taosArrayDestroy(tags);
|
||||
}
|
||||
}
|
||||
smlDestroyInfo(info);
|
||||
}
|
||||
//TEST(testCase, smlParseTelnetLine_diff_json_type2_Test) {
|
||||
// SSmlHandle *info = smlBuildSmlInfo(NULL);
|
||||
// info->protocol = TSDB_SML_JSON_PROTOCOL;
|
||||
// ASSERT_NE(info, nullptr);
|
||||
//
|
||||
// const char *sql[] = {
|
||||
// "[{\"metric\":\"sys.cpu.nice\",\"timestamp\": 1346846400,\"value\": 18,\"tags\": {\"host\": \"lga\"}},{\"metric\": \"sys.sdfa\",\"timestamp\": 1346846400,\"value\": \"18\",\"tags\": {\"host\": 8932}},]",
|
||||
// };
|
||||
// for (int i = 0; i < sizeof(sql) / sizeof(sql[0]); i++) {
|
||||
// char *dataPointStart = (char *)sql[i];
|
||||
// int8_t offset[4] = {0};
|
||||
// while (1) {
|
||||
// SSmlLineInfo elements = {0};
|
||||
// if(offset[0] == 0){
|
||||
// smlJsonParseObjFirst(&dataPointStart, &elements, offset);
|
||||
// }else{
|
||||
// smlJsonParseObj(&dataPointStart, &elements, offset);
|
||||
// }
|
||||
// if(*dataPointStart == '\0') break;
|
||||
//
|
||||
// SArray *tags = smlJsonParseTags(elements.tags, elements.tags + elements.tagsLen);
|
||||
// size_t num = taosArrayGetSize(tags);
|
||||
// ASSERT_EQ(num, 1);
|
||||
//
|
||||
// taosArrayDestroy(tags);
|
||||
// }
|
||||
// }
|
||||
// smlDestroyInfo(info);
|
||||
//}
|
||||
|
||||
TEST(testCase, smlParseNumber_performance_Test) {
|
||||
char msg[256] = {0};
|
||||
|
|
|
@ -1879,7 +1879,7 @@ void blockDebugShowDataBlocks(const SArray* dataBlocks, const char* flag) {
|
|||
char pBuf[128] = {0};
|
||||
int32_t sz = taosArrayGetSize(dataBlocks);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SSDataBlock* pDataBlock = taosArrayGetP(dataBlocks, i);
|
||||
SSDataBlock* pDataBlock = taosArrayGet(dataBlocks, i);
|
||||
size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock);
|
||||
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
|
@ -1891,21 +1891,37 @@ void blockDebugShowDataBlocks(const SArray* dataBlocks, const char* flag) {
|
|||
for (int32_t k = 0; k < numOfCols; k++) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes);
|
||||
if (k == 0) {
|
||||
printf("cols:%d |", (int32_t)numOfCols);
|
||||
}
|
||||
if (colDataIsNull(pColInfoData, rows, j, NULL)) {
|
||||
printf(" %15s |", "NULL");
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (pColInfoData->info.type) {
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
formatTimestamp(pBuf, *(uint64_t*)var, TSDB_TIME_PRECISION_MILLI);
|
||||
printf(" %25s |", pBuf);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
printf(" %15d |", *(int32_t*)var);
|
||||
printf(" %15" PRIi8 " |", *(int8_t*)var);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
printf(" %15" PRIi8 " |", *(int8_t*)var);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
printf(" %15" PRIi16 " |", *(int16_t*)var);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
printf(" %15d |", *(int32_t*)var);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
printf(" %15" PRIu8 " |", *(uint8_t*)var);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
printf(" %15" PRIu16 " |", *(uint16_t*)var);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
printf(" %15u |", *(uint32_t*)var);
|
||||
break;
|
||||
|
|
|
@ -715,6 +715,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
tsNumOfSnodeWriteThreads = cfgGetItem(pCfg, "numOfSnodeUniqueThreads")->i32;
|
||||
tsRpcQueueMemoryAllowed = cfgGetItem(pCfg, "rpcQueueMemoryAllowed")->i64;
|
||||
|
||||
tsSIMDBuiltins = (bool) cfgGetItem(pCfg, "SIMD-builtins")->bval;
|
||||
|
||||
tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval;
|
||||
tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32;
|
||||
tstrncpy(tsMonitorFqdn, cfgGetItem(pCfg, "monitorFqdn")->str, TSDB_FQDN_LEN);
|
||||
|
|
|
@ -90,10 +90,8 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in
|
|||
SName* toName(int32_t acctId, const char* pDbName, const char* pTableName, SName* pName) {
|
||||
pName->type = TSDB_TABLE_NAME_T;
|
||||
pName->acctId = acctId;
|
||||
memset(pName->dbname, 0, TSDB_DB_NAME_LEN);
|
||||
strncpy(pName->dbname, pDbName, TSDB_DB_NAME_LEN - 1);
|
||||
memset(pName->tname, 0, TSDB_TABLE_NAME_LEN);
|
||||
strncpy(pName->tname, pTableName, TSDB_TABLE_NAME_LEN - 1);
|
||||
snprintf(pName->dbname, sizeof(pName->dbname), "%s", pDbName);
|
||||
snprintf(pName->tname, sizeof(pName->tname), "%s", pTableName);
|
||||
return pName;
|
||||
}
|
||||
|
||||
|
@ -316,7 +314,7 @@ static int compareKv(const void* p1, const void* p2) {
|
|||
void buildChildTableName(RandTableName* rName) {
|
||||
SStringBuilder sb = {0};
|
||||
taosStringBuilderAppendStringLen(&sb, rName->stbFullName, rName->stbFullNameLen);
|
||||
if(sb.buf == NULL) return;
|
||||
if (sb.buf == NULL) return;
|
||||
taosArraySort(rName->tags, compareKv);
|
||||
for (int j = 0; j < taosArrayGetSize(rName->tags); ++j) {
|
||||
taosStringBuilderAppendChar(&sb, ',');
|
||||
|
|
|
@ -131,7 +131,10 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
|
|||
varDataCopy(val, src);
|
||||
break;
|
||||
default: {
|
||||
memcpy(val, src, len);
|
||||
if (len > 0) {
|
||||
memcpy(val, src, len);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ static int32_t dmInitLog() {
|
|||
}
|
||||
|
||||
static void taosCleanupArgs() {
|
||||
if (global.envCmd != NULL) taosMemoryFree(global.envCmd);
|
||||
if (global.envCmd != NULL) taosMemoryFreeClear(global.envCmd);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
|
@ -271,7 +271,6 @@ int mainWindows(int argc, char **argv) {
|
|||
|
||||
taosCleanupCfg();
|
||||
taosCloseLog();
|
||||
taosCleanupArgs();
|
||||
taosConvDestroy();
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -180,6 +180,6 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
dDebug("successed to write %s, deployed:%d", realfile, pOption->deploy);
|
||||
dDebug("succeed to write %s, deployed:%d", realfile, pOption->deploy);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -58,11 +58,7 @@ static void smProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
dTrace("msg:%p, get from snode-stream queue", pMsg);
|
||||
int32_t code = sndProcessStreamMsg(pMgmt->pSnode, pMsg);
|
||||
if (code < 0) {
|
||||
if (pMsg) {
|
||||
dGError("snd, msg:%p failed to process stream msg %s since %s", pMsg, TMSG_INFO(pMsg->msgType), terrstr(code));
|
||||
} else {
|
||||
dGError("snd, msg:%p failed to process stream empty msg since %s", pMsg, terrstr(code));
|
||||
}
|
||||
dGError("snd, msg:%p failed to process stream msg %s since %s", pMsg, TMSG_INFO(pMsg->msgType), terrstr(code));
|
||||
smSendRsp(pMsg, terrno);
|
||||
}
|
||||
|
||||
|
@ -161,8 +157,10 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
smPutNodeMsgToWriteQueue(pMgmt, pMsg);
|
||||
break;
|
||||
default:
|
||||
ASSERTS(0, "msg:%p failed to put into snode queue since %s, type:%s qtype:%d", pMsg, terrstr(),
|
||||
TMSG_INFO(pMsg->msgType), qtype);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "vmInt.h"
|
||||
|
||||
#define MAX_CONTENT_LEN 1024 * 1024
|
||||
#define MAX_CONTENT_LEN 2 * 1024 * 1024
|
||||
|
||||
SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
|
||||
taosThreadRwlockRdlock(&pMgmt->lock);
|
||||
|
@ -60,7 +60,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
|||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
dDebug("file %s not exist", file);
|
||||
dInfo("file %s not exist", file);
|
||||
code = 0;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
|||
|
||||
*numOfVnodes = vnodesNum;
|
||||
code = 0;
|
||||
dDebug("succcessed to read file %s, numOfVnodes:%d", file, vnodesNum);
|
||||
dInfo("succcessed to read file %s, numOfVnodes:%d", file, vnodesNum);
|
||||
|
||||
_OVER:
|
||||
if (content != NULL) taosMemoryFree(content);
|
||||
|
@ -163,6 +163,7 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
|
|||
if (ppVnodes == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = -1;
|
||||
dError("failed to write %s while get vnodelist", file);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -172,6 +173,7 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
|
|||
if (content == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = -1;
|
||||
dError("failed to write %s while malloc content", file);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -213,6 +215,12 @@ _OVER:
|
|||
|
||||
if (code != 0) return -1;
|
||||
|
||||
dDebug("successed to write %s, numOfVnodes:%d", realfile, numOfVnodes);
|
||||
return taosRenameFile(file, realfile);
|
||||
dInfo("succeed to write %s, numOfVnodes:%d", realfile, numOfVnodes);
|
||||
code = taosRenameFile(file, realfile);
|
||||
|
||||
if (code != 0) {
|
||||
dError("failed to rename %s to %s", file, realfile);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
|
@ -132,10 +132,12 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
|
|||
pCfg->syncCfg.myIndex = pCreate->selfIndex;
|
||||
pCfg->syncCfg.replicaNum = pCreate->replica;
|
||||
memset(&pCfg->syncCfg.nodeInfo, 0, sizeof(pCfg->syncCfg.nodeInfo));
|
||||
for (int i = 0; i < pCreate->replica; ++i) {
|
||||
for (int32_t i = 0; i < pCreate->replica; ++i) {
|
||||
SNodeInfo *pNode = &pCfg->syncCfg.nodeInfo[i];
|
||||
pNode->nodeId = pCreate->replicas[i].id;
|
||||
pNode->nodePort = pCreate->replicas[i].port;
|
||||
tstrncpy(pNode->nodeFqdn, pCreate->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
|
||||
tstrncpy(pNode->nodeFqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN);
|
||||
(void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,8 +190,8 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
req.walRollPeriod, req.walSegmentSize, req.hashMethod, req.hashBegin, req.hashEnd, req.hashPrefix,
|
||||
req.hashSuffix, req.replica, req.selfIndex, req.strict);
|
||||
for (int32_t i = 0; i < req.replica; ++i) {
|
||||
dInfo("vgId:%d, replica:%d id:%d fqdn:%s port:%u", req.vgId, i, req.replicas[i].id, req.replicas[i].fqdn,
|
||||
req.replicas[i].port);
|
||||
dInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d", req.vgId, i, req.replicas[i].fqdn, req.replicas[i].port,
|
||||
req.replicas[i].id);
|
||||
}
|
||||
|
||||
SReplica *pReplica = &req.replicas[req.selfIndex];
|
||||
|
@ -213,7 +215,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, req.vgId);
|
||||
if (pVnode != NULL) {
|
||||
dDebug("vgId:%d, already exist", req.vgId);
|
||||
dInfo("vgId:%d, already exist", req.vgId);
|
||||
tFreeSCreateVnodeReq(&req);
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
terrno = TSDB_CODE_VND_ALREADY_EXIST;
|
||||
|
@ -286,7 +288,8 @@ int32_t vmProcessAlterVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
dInfo("vgId:%d, start to alter vnode, replica:%d selfIndex:%d strict:%d", alterReq.vgId, alterReq.replica,
|
||||
alterReq.selfIndex, alterReq.strict);
|
||||
for (int32_t i = 0; i < alterReq.replica; ++i) {
|
||||
dInfo("vgId:%d, replica:%d ep:%s:%u", alterReq.vgId, i, alterReq.replicas[i].fqdn, alterReq.replicas[i].port);
|
||||
SReplica *pReplica = &alterReq.replicas[i];
|
||||
dInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d", alterReq.vgId, i, pReplica->fqdn, pReplica->port, pReplica->port);
|
||||
}
|
||||
|
||||
if (alterReq.replica <= 0 || alterReq.selfIndex < 0 || alterReq.selfIndex >= alterReq.replica) {
|
||||
|
@ -358,7 +361,7 @@ int32_t vmProcessDropVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int32_t vgId = dropReq.vgId;
|
||||
dDebug("vgId:%d, start to drop vnode", vgId);
|
||||
dInfo("vgId:%d, start to drop vnode", vgId);
|
||||
|
||||
if (dropReq.dnodeId != pMgmt->pData->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
|
@ -368,7 +371,7 @@ int32_t vmProcessDropVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
|
||||
if (pVnode == NULL) {
|
||||
dDebug("vgId:%d, failed to drop since %s", vgId, terrstr());
|
||||
dInfo("vgId:%d, failed to drop since %s", vgId, terrstr());
|
||||
terrno = TSDB_CODE_VND_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
@ -383,6 +386,7 @@ int32_t vmProcessDropVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
vmCloseVnode(pMgmt, pVnode);
|
||||
vmWriteVnodeListToFile(pMgmt);
|
||||
|
||||
dInfo("vgId:%d, is dropped", vgId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ static void *vmOpenVnodeInThread(void *param) {
|
|||
SVnodeMgmt *pMgmt = pThread->pMgmt;
|
||||
char path[TSDB_FILENAME_LEN];
|
||||
|
||||
dDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum);
|
||||
dInfo("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum);
|
||||
setThreadName("open-vnodes");
|
||||
|
||||
for (int32_t v = 0; v < pThread->vnodeNum; ++v) {
|
||||
|
@ -156,14 +156,14 @@ static void *vmOpenVnodeInThread(void *param) {
|
|||
pThread->failed++;
|
||||
} else {
|
||||
vmOpenVnode(pMgmt, pCfg, pImpl);
|
||||
dDebug("vgId:%d, is opened by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
dInfo("vgId:%d, is opened by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
pThread->opened++;
|
||||
atomic_add_fetch_32(&pMgmt->state.openVnodes, 1);
|
||||
}
|
||||
}
|
||||
|
||||
dDebug("thread:%d, numOfVnodes:%d, opened:%d failed:%d", pThread->threadIndex, pThread->vnodeNum, pThread->opened,
|
||||
pThread->failed);
|
||||
dInfo("thread:%d, numOfVnodes:%d, opened:%d failed:%d", pThread->threadIndex, pThread->vnodeNum, pThread->opened,
|
||||
pThread->failed);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -496,7 +496,7 @@ static void *vmRestoreVnodeInThread(void *param) {
|
|||
dError("vgId:%d, failed to restore vnode by thread:%d", pVnode->vgId, pThread->threadIndex);
|
||||
pThread->failed++;
|
||||
} else {
|
||||
dDebug("vgId:%d, is restored by thread:%d", pVnode->vgId, pThread->threadIndex);
|
||||
dInfo("vgId:%d, is restored by thread:%d", pVnode->vgId, pThread->threadIndex);
|
||||
pThread->opened++;
|
||||
atomic_add_fetch_32(&pMgmt->state.openVnodes, 1);
|
||||
}
|
||||
|
|
|
@ -86,12 +86,8 @@ static void vmProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
|
||||
if (code != 0) {
|
||||
if (terrno != 0) code = terrno;
|
||||
if (pMsg) {
|
||||
dGError("vgId:%d, msg:%p failed to process stream msg %s since %s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType),
|
||||
terrstr(code));
|
||||
} else {
|
||||
dGError("vgId:%d, msg:%p failed to process stream empty msg since %s", pVnode->vgId, pMsg, terrstr(code));
|
||||
}
|
||||
dGError("vgId:%d, msg:%p failed to process stream msg %s since %s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType),
|
||||
terrstr(code));
|
||||
vmSendRsp(pMsg, code);
|
||||
}
|
||||
|
||||
|
@ -146,16 +142,16 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
|||
return -1;
|
||||
}
|
||||
|
||||
SMsgHead *pHead = pMsg->pCont;
|
||||
int32_t code = 0;
|
||||
SMsgHead *pHead = pMsg->pCont;
|
||||
int32_t code = 0;
|
||||
|
||||
pHead->contLen = ntohl(pHead->contLen);
|
||||
pHead->vgId = ntohl(pHead->vgId);
|
||||
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId);
|
||||
if (pVnode == NULL) {
|
||||
dGError("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg, terrstr(),
|
||||
TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
|
||||
dGError("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
|
||||
terrstr(), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
|
||||
return terrno != 0 ? terrno : -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -345,6 +345,8 @@ SMsgCb dmGetMsgcb(SDnode *pDnode) {
|
|||
.registerBrokenLinkArgFp = dmRegisterBrokenLinkArg,
|
||||
.releaseHandleFp = dmReleaseHandle,
|
||||
.reportStartupFp = dmReportStartup,
|
||||
.updateDnodeInfoFp = dmUpdateDnodeInfo,
|
||||
.data = &pDnode->data,
|
||||
};
|
||||
return msgCb;
|
||||
}
|
||||
|
|
|
@ -167,6 +167,7 @@ void dmUpdateEps(SDnodeData *pData, SArray *pDnodeEps);
|
|||
void dmGetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
|
||||
void dmGetMnodeEpSetForRedirect(SDnodeData *pData, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
|
||||
int32_t dmUpdateDnodeInfo(void *pData, int32_t *dnodeId, int64_t *clusterId, char *fqdn, uint16_t *port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -182,22 +182,25 @@ _OVER:
|
|||
}
|
||||
|
||||
int32_t dmWriteEps(SDnodeData *pData) {
|
||||
int32_t code = -1;
|
||||
char *content = NULL;
|
||||
TdFilePtr pFile = NULL;
|
||||
|
||||
char file[PATH_MAX] = {0};
|
||||
char realfile[PATH_MAX] = {0};
|
||||
|
||||
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
dError("failed to write %s since %s", file, strerror(errno));
|
||||
dError("failed to open %s since %s", file, strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 256 * 1024;
|
||||
char *content = taosMemoryCalloc(1, maxLen + 1);
|
||||
content = taosMemoryCalloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pData->dnodeId);
|
||||
|
@ -221,20 +224,39 @@ int32_t dmWriteEps(SDnodeData *pData) {
|
|||
}
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
taosWriteFile(pFile, content, len);
|
||||
taosFsyncFile(pFile);
|
||||
if (taosWriteFile(pFile, content, len) != len) {
|
||||
dError("failed to write %s since %s", file, strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosFsyncFile(pFile) < 0) {
|
||||
dError("failed to fsync %s since %s", file, strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
taosMemoryFree(content);
|
||||
taosMemoryFreeClear(content);
|
||||
|
||||
if (taosRenameFile(file, realfile) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to rename %s since %s", file, terrstr());
|
||||
return -1;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
pData->updateTime = taosGetTimestampMs();
|
||||
dDebug("successed to write %s, dnodeVer:%" PRId64, realfile, pData->dnodeVer);
|
||||
return 0;
|
||||
dInfo("succeed to write %s, dnodeVer:%" PRId64, realfile, pData->dnodeVer);
|
||||
|
||||
_OVER:
|
||||
if (content != NULL) taosMemoryFreeClear(content);
|
||||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
if (code != 0) {
|
||||
dError("failed to write file %s since %s", realfile, terrstr());
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
void dmUpdateEps(SDnodeData *pData, SArray *eps) {
|
||||
|
@ -332,3 +354,41 @@ void dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet) {
|
|||
dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dmUpdateDnodeInfo(void *data, int32_t *dnodeId, int64_t *clusterId, char *fqdn, uint16_t *port) {
|
||||
SDnodeData *pData = data;
|
||||
int32_t ret = -1;
|
||||
taosThreadRwlockRdlock(&pData->lock);
|
||||
if (*dnodeId <= 0) {
|
||||
for (int32_t i = 0; i < (int32_t)taosArrayGetSize(pData->dnodeEps); ++i) {
|
||||
SDnodeEp *pDnodeEp = taosArrayGet(pData->dnodeEps, i);
|
||||
if (strcmp(pDnodeEp->ep.fqdn, fqdn) == 0 && pDnodeEp->ep.port == *port) {
|
||||
dInfo("dnode:%s:%u, update dnodeId from %d to %d", fqdn, *port, *dnodeId, pDnodeEp->id);
|
||||
*dnodeId = pDnodeEp->id;
|
||||
*clusterId = pData->clusterId;
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if (ret != 0) {
|
||||
dInfo("dnode:%s:%u, failed to update dnodeId:%d", fqdn, *port, *dnodeId);
|
||||
}
|
||||
} else {
|
||||
SDnodeEp *pDnodeEp = taosHashGet(pData->dnodeHash, dnodeId, sizeof(int32_t));
|
||||
if (pDnodeEp) {
|
||||
if (strcmp(pDnodeEp->ep.fqdn, fqdn) != 0) {
|
||||
dInfo("dnode:%d, update port from %s to %s", *dnodeId, fqdn, pDnodeEp->ep.fqdn);
|
||||
tstrncpy(fqdn, pDnodeEp->ep.fqdn, TSDB_FQDN_LEN);
|
||||
}
|
||||
if (pDnodeEp->ep.port != *port) {
|
||||
dInfo("dnode:%d, update port from %u to %u", *dnodeId, *port, pDnodeEp->ep.port);
|
||||
*port = pDnodeEp->ep.port;
|
||||
}
|
||||
*clusterId = pData->clusterId;
|
||||
ret = 0;
|
||||
} else {
|
||||
dInfo("dnode:%d, failed to update dnode info", *dnodeId);
|
||||
}
|
||||
}
|
||||
taosThreadRwlockUnlock(&pData->lock);
|
||||
return ret;
|
||||
}
|
|
@ -105,7 +105,7 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
dInfo("successed to write %s, deployed:%d", realfile, deployed);
|
||||
dInfo("succeed to write %s, deployed:%d", realfile, deployed);
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
|
|
|
@ -112,7 +112,6 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
|
|||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.hashMethod, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfRetensions, _OVER)
|
||||
for (int32_t i = 0; i < pDb->cfg.numOfRetensions; ++i) {
|
||||
ASSERT(taosArrayGetSize(pDb->cfg.pRetensions) == pDb->cfg.numOfRetensions);
|
||||
SRetention *pRetension = taosArrayGet(pDb->cfg.pRetensions, i);
|
||||
SDB_SET_INT64(pRaw, dataPos, pRetension->freq, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pRetension->keep, _OVER)
|
||||
|
@ -364,6 +363,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
|
|||
if (pCfg->hashPrefix < TSDB_MIN_HASH_PREFIX || pCfg->hashPrefix > TSDB_MAX_HASH_PREFIX) return -1;
|
||||
if (pCfg->hashSuffix < TSDB_MIN_HASH_SUFFIX || pCfg->hashSuffix > TSDB_MAX_HASH_SUFFIX) return -1;
|
||||
if (pCfg->tsdbPageSize < TSDB_MIN_TSDB_PAGESIZE || pCfg->tsdbPageSize > TSDB_MAX_TSDB_PAGESIZE) return -1;
|
||||
if (taosArrayGetSize(pCfg->pRetensions) != pCfg->numOfRetensions) return -1;
|
||||
|
||||
terrno = 0;
|
||||
return terrno;
|
||||
|
|
|
@ -489,7 +489,7 @@ int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) {
|
|||
tlen += tEncodeSMqConsumerEp(buf, pConsumerEp);
|
||||
cnt++;
|
||||
}
|
||||
ASSERT(cnt == sz);
|
||||
if(cnt != sz) return -1;
|
||||
tlen += taosEncodeArray(buf, pSub->unassignedVgs, (FEncode)tEncodeSMqVgEp);
|
||||
tlen += taosEncodeString(buf, pSub->dbName);
|
||||
return tlen;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "mndSync.h"
|
||||
#include "mndTrans.h"
|
||||
#include "tmisce.h"
|
||||
#include "mndCluster.h"
|
||||
|
||||
#define MNODE_VER_NUMBER 1
|
||||
#define MNODE_RESERVE_SIZE 64
|
||||
|
@ -743,8 +744,12 @@ static void mndReloadSyncConfig(SMnode *pMnode) {
|
|||
|
||||
if (objStatus == SDB_STATUS_READY || objStatus == SDB_STATUS_CREATING) {
|
||||
SNodeInfo *pNode = &cfg.nodeInfo[cfg.replicaNum];
|
||||
tstrncpy(pNode->nodeFqdn, pObj->pDnode->fqdn, sizeof(pNode->nodeFqdn));
|
||||
pNode->nodeId = pObj->pDnode->id;
|
||||
pNode->clusterId = mndGetClusterId(pMnode);
|
||||
pNode->nodePort = pObj->pDnode->port;
|
||||
tstrncpy(pNode->nodeFqdn, pObj->pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
(void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
||||
mInfo("vgId:1, ep:%s:%u dnode:%d", pNode->nodeFqdn, pNode->nodePort, pNode->nodeId);
|
||||
if (pObj->pDnode->id == pMnode->selfDnodeId) {
|
||||
cfg.myIndex = cfg.replicaNum;
|
||||
}
|
||||
|
@ -758,7 +763,6 @@ static void mndReloadSyncConfig(SMnode *pMnode) {
|
|||
mInfo("vgId:1, mnode sync not reconfig since readyMnodes:%d updatingMnodes:%d", readyMnodes, updatingMnodes);
|
||||
return;
|
||||
}
|
||||
// ASSERT(0);
|
||||
|
||||
if (cfg.myIndex == -1) {
|
||||
#if 1
|
||||
|
@ -775,7 +779,8 @@ static void mndReloadSyncConfig(SMnode *pMnode) {
|
|||
mInfo("vgId:1, mnode sync reconfig, replica:%d myIndex:%d", cfg.replicaNum, cfg.myIndex);
|
||||
for (int32_t i = 0; i < cfg.replicaNum; ++i) {
|
||||
SNodeInfo *pNode = &cfg.nodeInfo[i];
|
||||
mInfo("vgId:1, index:%d, fqdn:%s port:%d", i, pNode->nodeFqdn, pNode->nodePort);
|
||||
mInfo("vgId:1, index:%d, ep:%s:%u dnode:%d cluster:%" PRId64, i, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId,
|
||||
pNode->clusterId);
|
||||
}
|
||||
|
||||
int32_t code = syncReconfig(pMnode->syncMgmt.sync, &cfg);
|
||||
|
|
|
@ -111,7 +111,7 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
|
|||
} else if (strncasecmp(name, TSDB_INS_TABLE_USER_PRIVILEGES, len) == 0) {
|
||||
type = TSDB_MGMT_TABLE_PRIVILEGES;
|
||||
} else {
|
||||
// ASSERT(0);
|
||||
mError("invalid show name:%s len:%d", name, len);
|
||||
}
|
||||
|
||||
return type;
|
||||
|
|
|
@ -488,7 +488,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
|
|||
memcpy(smaObj.db, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
smaObj.createdTime = taosGetTimestampMs();
|
||||
smaObj.uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN);
|
||||
ASSERT(smaObj.uid != 0);
|
||||
|
||||
char resultTbName[TSDB_TABLE_FNAME_LEN + 16] = {0};
|
||||
snprintf(resultTbName, TSDB_TABLE_FNAME_LEN + 16, "%s_td_tsma_rst_tb", pCreate->name);
|
||||
memcpy(smaObj.dstTbName, resultTbName, TSDB_TABLE_FNAME_LEN);
|
||||
|
@ -558,13 +558,15 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
|
|||
|
||||
SNode *pAst = NULL;
|
||||
if (nodesStringToNode(streamObj.ast, &pAst) < 0) {
|
||||
ASSERT(0);
|
||||
terrno = TSDB_CODE_MND_INVALID_SMA_OPTION;
|
||||
mError("sma:%s, failed to create since parse ast error", smaObj.name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// extract output schema from ast
|
||||
if (qExtractResultSchema(pAst, (int32_t *)&streamObj.outputSchema.nCols, &streamObj.outputSchema.pSchema) != 0) {
|
||||
ASSERT(0);
|
||||
terrno = TSDB_CODE_MND_INVALID_SMA_OPTION;
|
||||
mError("sma:%s, failed to create since extract result schema error", smaObj.name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -579,15 +581,18 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
|
|||
};
|
||||
|
||||
if (qCreateQueryPlan(&cxt, &pPlan, NULL) < 0) {
|
||||
ASSERT(0);
|
||||
terrno = TSDB_CODE_MND_INVALID_SMA_OPTION;
|
||||
mError("sma:%s, failed to create since create query plan error", smaObj.name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// save physcial plan
|
||||
if (nodesNodeToString((SNode *)pPlan, false, &streamObj.physicalPlan, NULL) != 0) {
|
||||
ASSERT(0);
|
||||
terrno = TSDB_CODE_MND_INVALID_SMA_OPTION;
|
||||
mError("sma:%s, failed to create since save physcial plan error", smaObj.name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pAst != NULL) nodesDestroyNode(pAst);
|
||||
nodesDestroyNode((SNode *)pPlan);
|
||||
|
||||
|
@ -826,14 +831,13 @@ static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *p
|
|||
if (mndDropStreamTasks(pMnode, pTrans, pStream) < 0) {
|
||||
mError("stream:%s, failed to drop task since %s", pStream->name, terrstr());
|
||||
sdbRelease(pMnode->pSdb, pStream);
|
||||
ASSERT(0);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
// drop stream
|
||||
if (mndPersistDropStreamLog(pMnode, pTrans, pStream) < 0) {
|
||||
mError("stream:%s, failed to drop log since %s", pStream->name, terrstr());
|
||||
sdbRelease(pMnode->pSdb, pStream);
|
||||
ASSERT(0);
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1177,7 +1177,9 @@ static int32_t mndCheckAlterColForTopic(SMnode *pMnode, const char *stbFullName,
|
|||
|
||||
SNode *pAst = NULL;
|
||||
if (nodesStringToNode(pTopic->ast, &pAst) != 0) {
|
||||
ASSERT(0);
|
||||
terrno = TSDB_CODE_MND_FIELD_CONFLICT_WITH_TOPIC;
|
||||
mError("topic:%s, create ast error", pTopic->name);
|
||||
sdbRelease(pSdb, pTopic);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1222,7 +1224,9 @@ static int32_t mndCheckAlterColForStream(SMnode *pMnode, const char *stbFullName
|
|||
|
||||
SNode *pAst = NULL;
|
||||
if (nodesStringToNode(pStream->ast, &pAst) != 0) {
|
||||
ASSERT(0);
|
||||
terrno = TSDB_CODE_MND_INVALID_STREAM_OPTION;
|
||||
mError("stream:%s, create ast error", pStream->name);
|
||||
sdbRelease(pSdb, pStream);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -2094,7 +2098,9 @@ static int32_t mndCheckDropStbForTopic(SMnode *pMnode, const char *stbFullName,
|
|||
|
||||
SNode *pAst = NULL;
|
||||
if (nodesStringToNode(pTopic->ast, &pAst) != 0) {
|
||||
ASSERT(0);
|
||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION;
|
||||
mError("topic:%s, create ast error", pTopic->name);
|
||||
sdbRelease(pSdb, pTopic);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -2141,7 +2147,9 @@ static int32_t mndCheckDropStbForStream(SMnode *pMnode, const char *stbFullName,
|
|||
|
||||
SNode *pAst = NULL;
|
||||
if (nodesStringToNode(pStream->ast, &pAst) != 0) {
|
||||
ASSERT(0);
|
||||
terrno = TSDB_CODE_MND_INVALID_STREAM_OPTION;
|
||||
mError("stream:%s, create ast error", pStream->name);
|
||||
sdbRelease(pSdb, pStream);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,18 +96,12 @@ static SMqSubscribeObj *mndCreateSub(SMnode *pMnode, const SMqTopicObj *pTopic,
|
|||
pSub->subType = pTopic->subType;
|
||||
pSub->withMeta = pTopic->withMeta;
|
||||
|
||||
ASSERT(pSub->unassignedVgs->size == 0);
|
||||
ASSERT(taosHashGetSize(pSub->consumerHash) == 0);
|
||||
|
||||
if (mndSchedInitSubEp(pMnode, pTopic, pSub) < 0) {
|
||||
tDeleteSubscribeObj(pSub);
|
||||
taosMemoryFree(pSub);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASSERT(pSub->unassignedVgs->size > 0);
|
||||
ASSERT(taosHashGetSize(pSub->consumerHash) == 0);
|
||||
|
||||
return pSub;
|
||||
}
|
||||
|
||||
|
@ -144,7 +138,10 @@ static int32_t mndBuildSubChangeReq(void **pBuf, int32_t *pLen, const SMqSubscri
|
|||
|
||||
static int32_t mndPersistSubChangeVgReq(SMnode *pMnode, STrans *pTrans, const SMqSubscribeObj *pSub,
|
||||
const SMqRebOutputVg *pRebVg) {
|
||||
ASSERT(pRebVg->oldConsumerId != pRebVg->newConsumerId);
|
||||
if (pRebVg->oldConsumerId == pRebVg->newConsumerId) {
|
||||
terrno = TSDB_CODE_MND_INVALID_SUB_OPTION;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *buf;
|
||||
int32_t tlen;
|
||||
|
@ -155,8 +152,8 @@ static int32_t mndPersistSubChangeVgReq(SMnode *pMnode, STrans *pTrans, const SM
|
|||
int32_t vgId = pRebVg->pVgEp->vgId;
|
||||
SVgObj *pVgObj = mndAcquireVgroup(pMnode, vgId);
|
||||
if (pVgObj == NULL) {
|
||||
ASSERT(0);
|
||||
taosMemoryFree(buf);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -206,9 +203,9 @@ static SMqRebInfo *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) {
|
|||
}
|
||||
|
||||
static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqRebOutputObj *pOutput) {
|
||||
int32_t totalVgNum = pOutput->pSub->vgNum;
|
||||
|
||||
mInfo("mq rebalance: subscription: %s, vgNum: %d", pOutput->pSub->key, pOutput->pSub->vgNum);
|
||||
int32_t totalVgNum = pOutput->pSub->vgNum;
|
||||
const char *sub = pOutput->pSub->key;
|
||||
mInfo("sub:%s, mq rebalance vgNum:%d", sub, pOutput->pSub->vgNum);
|
||||
|
||||
// 1. build temporary hash(vgId -> SMqRebOutputVg) to store modified vg
|
||||
SHashObj *pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
|
||||
|
@ -218,11 +215,10 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
int32_t actualRemoved = 0;
|
||||
for (int32_t i = 0; i < removedNum; i++) {
|
||||
int64_t consumerId = *(int64_t *)taosArrayGet(pInput->pRebInfo->removedConsumers, i);
|
||||
ASSERT(consumerId > 0);
|
||||
|
||||
SMqConsumerEp *pConsumerEp = taosHashGet(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t));
|
||||
ASSERT(pConsumerEp);
|
||||
|
||||
if (pConsumerEp) {
|
||||
ASSERT(consumerId == pConsumerEp->consumerId);
|
||||
actualRemoved++;
|
||||
int32_t consumerVgNum = taosArrayGetSize(pConsumerEp->vgs);
|
||||
for (int32_t j = 0; j < consumerVgNum; j++) {
|
||||
|
@ -233,7 +229,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
.pVgEp = pVgEp,
|
||||
};
|
||||
taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg));
|
||||
mInfo("mq rebalance: remove vgId:%d from consumer:%" PRId64, pVgEp->vgId, consumerId);
|
||||
mInfo("sub:%s, mq rebalance remove vgId:%d from consumer:%" PRId64, sub, pVgEp->vgId, consumerId);
|
||||
}
|
||||
taosArrayDestroy(pConsumerEp->vgs);
|
||||
taosHashRemove(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t));
|
||||
|
@ -241,7 +237,10 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
taosArrayPush(pOutput->removedConsumers, &consumerId);
|
||||
}
|
||||
}
|
||||
ASSERT(removedNum == actualRemoved);
|
||||
|
||||
if (removedNum != actualRemoved) {
|
||||
mError("sub:%s, mq rebalance removedNum:%d not matched with actual:%d", sub, removedNum, actualRemoved);
|
||||
}
|
||||
|
||||
// if previously no consumer, there are vgs not assigned
|
||||
{
|
||||
|
@ -254,7 +253,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
.pVgEp = pVgEp,
|
||||
};
|
||||
taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &rebOutput, sizeof(SMqRebOutputVg));
|
||||
mInfo("mq rebalance: remove vgId:%d from unassigned", pVgEp->vgId);
|
||||
mInfo("sub:%s, mq rebalance remove vgId:%d from unassigned", sub, pVgEp->vgId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,8 +267,8 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
minVgCnt = totalVgNum / afterRebConsumerNum;
|
||||
imbConsumerNum = totalVgNum % afterRebConsumerNum;
|
||||
}
|
||||
mInfo("mq rebalance: %d consumer after rebalance, at least %d vg each, %d consumer has more vg", afterRebConsumerNum,
|
||||
minVgCnt, imbConsumerNum);
|
||||
mInfo("sub:%s, mq rebalance %d consumer after rebalance, at least %d vg each, %d consumer has more vg", sub,
|
||||
afterRebConsumerNum, minVgCnt, imbConsumerNum);
|
||||
|
||||
// 4. first scan: remove consumer more than wanted, put to remove hash
|
||||
int32_t imbCnt = 0;
|
||||
|
@ -278,7 +277,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter);
|
||||
if (pIter == NULL) break;
|
||||
SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
|
||||
ASSERT(pConsumerEp->consumerId > 0);
|
||||
|
||||
int32_t consumerVgNum = taosArrayGetSize(pConsumerEp->vgs);
|
||||
// all old consumers still existing are touched
|
||||
// TODO optimize: touch only consumer whose vgs changed
|
||||
|
@ -298,7 +297,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
.pVgEp = pVgEp,
|
||||
};
|
||||
taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg));
|
||||
mInfo("mq rebalance: remove vgId:%d from consumer:%" PRId64 ",(first scan)", pVgEp->vgId,
|
||||
mInfo("sub:%s, mq rebalance remove vgId:%d from consumer:%" PRId64 ",(first scan)", sub, pVgEp->vgId,
|
||||
pConsumerEp->consumerId);
|
||||
}
|
||||
imbCnt++;
|
||||
|
@ -313,7 +312,7 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
.pVgEp = pVgEp,
|
||||
};
|
||||
taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg));
|
||||
mInfo("mq rebalance: remove vgId:%d from consumer:%" PRId64 ",(first scan)", pVgEp->vgId,
|
||||
mInfo("sub:%s, mq rebalance remove vgId:%d from consumer:%" PRId64 ",(first scan)", sub, pVgEp->vgId,
|
||||
pConsumerEp->consumerId);
|
||||
}
|
||||
}
|
||||
|
@ -325,13 +324,13 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
int32_t consumerNum = taosArrayGetSize(pInput->pRebInfo->newConsumers);
|
||||
for (int32_t i = 0; i < consumerNum; i++) {
|
||||
int64_t consumerId = *(int64_t *)taosArrayGet(pInput->pRebInfo->newConsumers, i);
|
||||
ASSERT(consumerId > 0);
|
||||
|
||||
SMqConsumerEp newConsumerEp;
|
||||
newConsumerEp.consumerId = consumerId;
|
||||
newConsumerEp.vgs = taosArrayInit(0, sizeof(void *));
|
||||
taosHashPut(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t), &newConsumerEp, sizeof(SMqConsumerEp));
|
||||
taosArrayPush(pOutput->newConsumers, &consumerId);
|
||||
mInfo("mq rebalance: add new consumer:%" PRId64, consumerId);
|
||||
mInfo("sub:%s, mq rebalance add new consumer:%" PRId64, sub, consumerId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -344,13 +343,16 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter);
|
||||
if (pIter == NULL) break;
|
||||
SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
|
||||
ASSERT(pConsumerEp->consumerId > 0);
|
||||
|
||||
// push until equal minVg
|
||||
while (taosArrayGetSize(pConsumerEp->vgs) < minVgCnt) {
|
||||
// iter hash and find one vg
|
||||
pRemovedIter = taosHashIterate(pHash, pRemovedIter);
|
||||
ASSERT(pRemovedIter);
|
||||
if (pRemovedIter == NULL) {
|
||||
mError("sub:%s, removed iter is null", sub);
|
||||
continue;
|
||||
}
|
||||
|
||||
pRebVg = (SMqRebOutputVg *)pRemovedIter;
|
||||
// push
|
||||
taosArrayPush(pConsumerEp->vgs, &pRebVg->pVgEp);
|
||||
|
@ -361,7 +363,6 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
}
|
||||
}
|
||||
|
||||
ASSERT(pIter == NULL);
|
||||
// 7. handle unassigned vg
|
||||
if (taosHashGetSize(pOutput->pSub->consumerHash) != 0) {
|
||||
// if has consumer, assign all left vg
|
||||
|
@ -377,9 +378,8 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
}
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter);
|
||||
ASSERT(pIter);
|
||||
pConsumerEp = (SMqConsumerEp *)pIter;
|
||||
ASSERT(pConsumerEp->consumerId > 0);
|
||||
|
||||
if (taosArrayGetSize(pConsumerEp->vgs) == minVgCnt) {
|
||||
break;
|
||||
}
|
||||
|
@ -404,19 +404,19 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
pIter = taosHashIterate(pHash, pIter);
|
||||
if (pIter == NULL) break;
|
||||
pRebOutput = (SMqRebOutputVg *)pIter;
|
||||
ASSERT(pRebOutput->newConsumerId == -1);
|
||||
|
||||
taosArrayPush(pOutput->pSub->unassignedVgs, &pRebOutput->pVgEp);
|
||||
taosArrayPush(pOutput->rebVgs, pRebOutput);
|
||||
mInfo("mq rebalance: unassign vgId:%d (second scan)", pRebOutput->pVgEp->vgId);
|
||||
mInfo("sub:%s, mq rebalance unassign vgId:%d (second scan)", sub, pRebOutput->pVgEp->vgId);
|
||||
}
|
||||
}
|
||||
|
||||
// 8. generate logs
|
||||
mInfo("mq rebalance: calculation completed, rebalanced vg:");
|
||||
mInfo("sub:%s, mq rebalance calculation completed, rebalanced vg", sub);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pOutput->rebVgs); i++) {
|
||||
SMqRebOutputVg *pOutputRebVg = taosArrayGet(pOutput->rebVgs, i);
|
||||
mInfo("mq rebalance: vgId:%d, moved from consumer:%" PRId64 ", to consumer:%" PRId64, pOutputRebVg->pVgEp->vgId,
|
||||
pOutputRebVg->oldConsumerId, pOutputRebVg->newConsumerId);
|
||||
mInfo("sub:%s, mq rebalance vgId:%d, moved from consumer:%" PRId64 ", to consumer:%" PRId64, sub,
|
||||
pOutputRebVg->pVgEp->vgId, pOutputRebVg->oldConsumerId, pOutputRebVg->newConsumerId);
|
||||
}
|
||||
{
|
||||
void *pIter = NULL;
|
||||
|
@ -425,10 +425,11 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
|
|||
if (pIter == NULL) break;
|
||||
SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
|
||||
int32_t sz = taosArrayGetSize(pConsumerEp->vgs);
|
||||
mInfo("mq rebalance: final cfg: consumer %" PRId64 " has %d vg", pConsumerEp->consumerId, sz);
|
||||
mInfo("sub:%s, mq rebalance final cfg: consumer %" PRId64 " has %d vg", sub, pConsumerEp->consumerId, sz);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, i);
|
||||
mInfo("mq rebalance: final cfg: vg %d to consumer %" PRId64 "", pVgEp->vgId, pConsumerEp->consumerId);
|
||||
mInfo("sub:%s, mq rebalance final cfg: vg %d to consumer %" PRId64 "", sub, pVgEp->vgId,
|
||||
pConsumerEp->consumerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -487,7 +488,7 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
|
|||
consumerNum = taosArrayGetSize(pOutput->newConsumers);
|
||||
for (int32_t i = 0; i < consumerNum; i++) {
|
||||
int64_t consumerId = *(int64_t *)taosArrayGet(pOutput->newConsumers, i);
|
||||
ASSERT(consumerId > 0);
|
||||
|
||||
SMqConsumerObj *pConsumerOld = mndAcquireConsumer(pMnode, consumerId);
|
||||
SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumerOld->consumerId, pConsumerOld->cgroup);
|
||||
pConsumerNew->updateType = CONSUMER_UPDATE__ADD;
|
||||
|
@ -497,7 +498,6 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
|
|||
taosArrayPush(pConsumerNew->rebNewTopics, &topic);
|
||||
mndReleaseConsumer(pMnode, pConsumerOld);
|
||||
if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) {
|
||||
ASSERT(0);
|
||||
tDeleteSMqConsumerObj(pConsumerNew);
|
||||
taosMemoryFree(pConsumerNew);
|
||||
goto REB_FAIL;
|
||||
|
@ -510,7 +510,7 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
|
|||
consumerNum = taosArrayGetSize(pOutput->removedConsumers);
|
||||
for (int32_t i = 0; i < consumerNum; i++) {
|
||||
int64_t consumerId = *(int64_t *)taosArrayGet(pOutput->removedConsumers, i);
|
||||
ASSERT(consumerId > 0);
|
||||
|
||||
SMqConsumerObj *pConsumerOld = mndAcquireConsumer(pMnode, consumerId);
|
||||
SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumerOld->consumerId, pConsumerOld->cgroup);
|
||||
pConsumerNew->updateType = CONSUMER_UPDATE__REMOVE;
|
||||
|
@ -520,7 +520,6 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
|
|||
taosArrayPush(pConsumerNew->rebRemovedTopics, &topic);
|
||||
mndReleaseConsumer(pMnode, pConsumerOld);
|
||||
if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) {
|
||||
ASSERT(0);
|
||||
tDeleteSMqConsumerObj(pConsumerNew);
|
||||
taosMemoryFree(pConsumerNew);
|
||||
goto REB_FAIL;
|
||||
|
@ -577,7 +576,6 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
|
|||
char cgroup[TSDB_CGROUP_LEN];
|
||||
mndSplitSubscribeKey(pRebInfo->key, topic, cgroup, true);
|
||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic);
|
||||
/*ASSERT(pTopic);*/
|
||||
if (pTopic == NULL) {
|
||||
mError("mq rebalance %s failed since topic %s not exist, abort", pRebInfo->key, topic);
|
||||
continue;
|
||||
|
@ -585,8 +583,14 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
|
|||
taosRLockLatch(&pTopic->lock);
|
||||
|
||||
rebOutput.pSub = mndCreateSub(pMnode, pTopic, pRebInfo->key);
|
||||
|
||||
if (rebOutput.pSub == NULL) {
|
||||
mError("mq rebalance %s failed create sub since %s, abort", pRebInfo->key, terrstr());
|
||||
taosRUnLockLatch(&pTopic->lock);
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
continue;
|
||||
}
|
||||
memcpy(rebOutput.pSub->dbName, pTopic->db, TSDB_DB_FNAME_LEN);
|
||||
ASSERT(taosHashGetSize(rebOutput.pSub->consumerHash) == 0);
|
||||
|
||||
taosRUnLockLatch(&pTopic->lock);
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
|
@ -606,7 +610,6 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
|
|||
|
||||
// if add more consumer to balanced subscribe,
|
||||
// possibly no vg is changed
|
||||
/*ASSERT(taosArrayGetSize(rebOutput.rebVgs) != 0);*/
|
||||
|
||||
if (mndPersistRebResult(pMnode, pMsg, &rebOutput) < 0) {
|
||||
mError("mq rebalance persist rebalance output error, possibly vnode splitted or dropped");
|
||||
|
@ -693,6 +696,7 @@ static SSdbRaw *mndSubActionEncode(SMqSubscribeObj *pSub) {
|
|||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
void *buf = NULL;
|
||||
int32_t tlen = tEncodeSubscribeObj(NULL, pSub);
|
||||
if (tlen <= 0) goto SUB_ENCODE_OVER;
|
||||
int32_t size = sizeof(int32_t) + tlen + MND_SUBSCRIBE_RESERVE_SIZE;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_SUBSCRIBE, MND_SUBSCRIBE_VER_NUMBER, size);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mndSync.h"
|
||||
#include "mndCluster.h"
|
||||
#include "mndTrans.h"
|
||||
|
||||
static int32_t mndSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||
|
@ -297,9 +298,12 @@ int32_t mndInitSync(SMnode *pMnode) {
|
|||
pCfg->myIndex = pMgmt->selfIndex;
|
||||
for (int32_t i = 0; i < pMgmt->numOfReplicas; ++i) {
|
||||
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
||||
tstrncpy(pNode->nodeFqdn, pMgmt->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
|
||||
pNode->nodeId = pMgmt->replicas[i].id;
|
||||
pNode->nodePort = pMgmt->replicas[i].port;
|
||||
mInfo("vgId:1, index:%d ep:%s:%u", i, pNode->nodeFqdn, pNode->nodePort);
|
||||
tstrncpy(pNode->nodeFqdn, pMgmt->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
|
||||
(void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
||||
mInfo("vgId:1, index:%d ep:%s:%u dnode:%d cluster:%" PRId64, i, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId,
|
||||
pNode->clusterId);
|
||||
}
|
||||
|
||||
tsem_init(&pMgmt->syncSem, 0, 0);
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "mndTelem.h"
|
||||
#include "mndCluster.h"
|
||||
#include "mndSync.h"
|
||||
#include "tbuffer.h"
|
||||
#include "thttp.h"
|
||||
#include "tjson.h"
|
||||
|
||||
|
|
|
@ -384,7 +384,11 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
|||
topicObj.subType = pCreate->subType;
|
||||
topicObj.withMeta = pCreate->withMeta;
|
||||
if (topicObj.withMeta) {
|
||||
ASSERT(topicObj.subType != TOPIC_SUB_TYPE__COLUMN);
|
||||
if (topicObj.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION;
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pCreate->subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
|
@ -499,7 +503,6 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
|||
if (code < 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
mndTransDrop(pTrans);
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
void *buf = taosMemoryCalloc(1, sizeof(SMsgHead) + len);
|
||||
|
@ -718,7 +721,6 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
|||
|
||||
// TODO check if rebalancing
|
||||
if (mndDropSubByTopic(pMnode, pTrans, dropReq.name) < 0) {
|
||||
/*ASSERT(0);*/
|
||||
mError("topic:%s, failed to drop since %s", pTopic->name, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
mndReleaseTopic(pMnode, pTopic);
|
||||
|
|
|
@ -54,7 +54,7 @@ int32_t vnodeAlter(const char *path, SAlterVnodeReplicaReq *pReq, STfs *pTfs);
|
|||
void vnodeDestroy(const char *path, STfs *pTfs);
|
||||
SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb);
|
||||
void vnodePreClose(SVnode *pVnode);
|
||||
void vnodeSyncCheckTimeout(SVnode* pVnode);
|
||||
void vnodeSyncCheckTimeout(SVnode *pVnode);
|
||||
void vnodeClose(SVnode *pVnode);
|
||||
|
||||
int32_t vnodeStart(SVnode *pVnode);
|
||||
|
@ -175,7 +175,8 @@ int32_t tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, void *pTableL
|
|||
void tsdbReaderClose(STsdbReader *pReader);
|
||||
bool tsdbNextDataBlock(STsdbReader *pReader);
|
||||
void tsdbRetrieveDataBlockInfo(const STsdbReader *pReader, int32_t *rows, uint64_t *uid, STimeWindow *pWindow);
|
||||
int32_t tsdbRetrieveDatablockSMA(STsdbReader *pReader, SSDataBlock* pDataBlock, bool *allHave);
|
||||
int32_t tsdbRetrieveDatablockSMA(STsdbReader *pReader, SSDataBlock *pDataBlock, bool *allHave);
|
||||
void tsdbReleaseDataBlock(STsdbReader *pReader);
|
||||
SSDataBlock *tsdbRetrieveDataBlock(STsdbReader *pTsdbReadHandle, SArray *pColumnIdList);
|
||||
int32_t tsdbReaderReset(STsdbReader *pReader, SQueryTableDataCond *pCond);
|
||||
int32_t tsdbGetFileBlocksDistInfo(STsdbReader *pReader, STableBlockDistInfo *pTableBlockInfo);
|
||||
|
@ -185,7 +186,7 @@ void *tsdbGetIvtIdx(SMeta *pMeta);
|
|||
uint64_t getReaderMaxVersion(STsdbReader *pReader);
|
||||
|
||||
int32_t tsdbCacherowsReaderOpen(void *pVnode, int32_t type, void *pTableIdList, int32_t numOfTables, int32_t numOfCols,
|
||||
uint64_t suid, void **pReader, const char* idstr);
|
||||
uint64_t suid, void **pReader, const char *idstr);
|
||||
int32_t tsdbRetrieveCacheRows(void *pReader, SSDataBlock *pResBlock, const int32_t *slotIds, SArray *pTableUids);
|
||||
void *tsdbCacherowsReaderClose(void *pReader);
|
||||
int32_t tsdbGetTableSchema(SVnode *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid);
|
||||
|
|
|
@ -182,9 +182,9 @@ int32_t tqOffsetDelete(STqOffsetStore* pStore, const char* subscribeKey)
|
|||
int32_t tqOffsetCommitFile(STqOffsetStore* pStore);
|
||||
|
||||
// tqSink
|
||||
// void tqSinkToTableMerge(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
||||
// void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
||||
void tqSinkToTablePipeline2(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
||||
int32_t tqBuildDeleteReq(SVnode* pVnode, const char* stbFullName, const SSDataBlock* pDataBlock,
|
||||
SBatchDeleteReq* deleteReq);
|
||||
void tqSinkToTablePipeline2(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
||||
|
||||
// tqOffset
|
||||
char* tqOffsetBuildFName(const char* path, int32_t fVer);
|
||||
|
|
|
@ -65,6 +65,7 @@ typedef struct SSmaInfo SSmaInfo;
|
|||
typedef struct SBlockCol SBlockCol;
|
||||
typedef struct SVersionRange SVersionRange;
|
||||
typedef struct SLDataIter SLDataIter;
|
||||
typedef struct SQueryNode SQueryNode;
|
||||
typedef struct SDiskCol SDiskCol;
|
||||
typedef struct SDiskData SDiskData;
|
||||
typedef struct SDiskDataBuilder SDiskDataBuilder;
|
||||
|
@ -208,11 +209,13 @@ int32_t tsdbDecmprColData(uint8_t *pIn, SBlockCol *pBlockCol, int8_t cmprAlg, in
|
|||
uint8_t **ppBuf);
|
||||
// tsdbMemTable ==============================================================================================
|
||||
// SMemTable
|
||||
typedef int32_t (*_tsdb_reseek_func_t)(void *pQHandle);
|
||||
|
||||
int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable);
|
||||
void tsdbMemTableDestroy(SMemTable *pMemTable);
|
||||
STbData *tsdbGetTbDataFromMemTable(SMemTable *pMemTable, tb_uid_t suid, tb_uid_t uid);
|
||||
void tsdbRefMemTable(SMemTable *pMemTable);
|
||||
void tsdbUnrefMemTable(SMemTable *pMemTable);
|
||||
int32_t tsdbRefMemTable(SMemTable *pMemTable, void *pQHandle, _tsdb_reseek_func_t reseek, SQueryNode **ppNode);
|
||||
int32_t tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode);
|
||||
SArray *tsdbMemTableGetTbDataArray(SMemTable *pMemTable);
|
||||
// STbDataIter
|
||||
int32_t tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter **ppIter);
|
||||
|
@ -290,8 +293,8 @@ int32_t tsdbDelFReaderClose(SDelFReader **ppReader);
|
|||
int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData);
|
||||
int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx);
|
||||
// tsdbRead.c ==============================================================================================
|
||||
int32_t tsdbTakeReadSnap(STsdb *pTsdb, STsdbReadSnap **ppSnap, const char *id);
|
||||
void tsdbUntakeReadSnap(STsdb *pTsdb, STsdbReadSnap *pSnap, const char *id);
|
||||
int32_t tsdbTakeReadSnap(STsdbReader *pReader, _tsdb_reseek_func_t reseek, STsdbReadSnap **ppSnap);
|
||||
void tsdbUntakeReadSnap(STsdbReader *pReader, STsdbReadSnap *pSnap);
|
||||
// tsdbMerge.c ==============================================================================================
|
||||
int32_t tsdbMerge(STsdb *pTsdb);
|
||||
|
||||
|
@ -366,11 +369,20 @@ struct STbData {
|
|||
STbData *next;
|
||||
};
|
||||
|
||||
struct SQueryNode {
|
||||
SQueryNode *pNext;
|
||||
SQueryNode **ppNext;
|
||||
void *pQHandle;
|
||||
_tsdb_reseek_func_t reseek;
|
||||
};
|
||||
|
||||
struct SMemTable {
|
||||
SRWLatch latch;
|
||||
STsdb *pTsdb;
|
||||
SVBufPool *pPool;
|
||||
volatile int32_t nRef;
|
||||
int64_t minVer;
|
||||
int64_t maxVer;
|
||||
TSKEY minKey;
|
||||
TSKEY maxKey;
|
||||
int64_t nRow;
|
||||
|
@ -380,6 +392,7 @@ struct SMemTable {
|
|||
int32_t nBucket;
|
||||
STbData **aBucket;
|
||||
};
|
||||
SQueryNode qList;
|
||||
};
|
||||
|
||||
struct TSDBROW {
|
||||
|
@ -605,9 +618,11 @@ struct SDelFWriter {
|
|||
};
|
||||
|
||||
struct STsdbReadSnap {
|
||||
SMemTable *pMem;
|
||||
SMemTable *pIMem;
|
||||
STsdbFS fs;
|
||||
SMemTable *pMem;
|
||||
SQueryNode *pNode;
|
||||
SMemTable *pIMem;
|
||||
SQueryNode *pINode;
|
||||
STsdbFS fs;
|
||||
};
|
||||
|
||||
struct SDataFWriter {
|
||||
|
@ -726,6 +741,9 @@ void *destroyLastBlockLoadInfo(SSttBlockLoadInfo *pLoadInfo);
|
|||
|
||||
// tsdbCache ==============================================================================================
|
||||
typedef struct SCacheRowsReader {
|
||||
STsdb *pTsdb;
|
||||
SVersionRange verRange;
|
||||
TdThreadMutex readerMutex;
|
||||
SVnode *pVnode;
|
||||
STSchema *pSchema;
|
||||
uint64_t uid;
|
||||
|
@ -785,8 +803,8 @@ static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
|
||||
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
|
||||
// #define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
|
||||
// #define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
|
||||
|
||||
static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) {
|
||||
if (pIter == NULL) return NULL;
|
||||
|
|
|
@ -87,7 +87,8 @@ typedef struct SCommitInfo SCommitInfo;
|
|||
#define VNODE_RSMA1_DIR "rsma1"
|
||||
#define VNODE_RSMA2_DIR "rsma2"
|
||||
|
||||
#define VND_INFO_FNAME "vnode.json"
|
||||
#define VNODE_BUF_POOL_SEG 1 // TODO: change parameter here for sync/async commit
|
||||
#define VND_INFO_FNAME "vnode.json"
|
||||
|
||||
// vnd.h
|
||||
|
||||
|
@ -203,10 +204,6 @@ int32_t tqProcessTaskRecoverFinishReq(STQ* pTq, SRpcMsg* pMsg);
|
|||
int32_t tqProcessTaskRecoverFinishRsp(STQ* pTq, SRpcMsg* pMsg);
|
||||
int32_t tqCheckLogInWal(STQ* pTq, int64_t version);
|
||||
|
||||
int32_t tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pSchema,
|
||||
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
||||
SBatchDeleteReq* pDeleteReq, void** ppData, int32_t* pLen);
|
||||
|
||||
// sma
|
||||
int32_t smaInit();
|
||||
void smaCleanUp();
|
||||
|
|
|
@ -192,7 +192,8 @@ int32_t metaSnapWrite(SMetaSnapWriter* pWriter, uint8_t* pData, uint32_t nData)
|
|||
SDecoder* pDecoder = &(SDecoder){0};
|
||||
|
||||
tDecoderInit(pDecoder, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
|
||||
metaDecodeEntry(pDecoder, &metaEntry);
|
||||
code = metaDecodeEntry(pDecoder, &metaEntry);
|
||||
if (code) goto _err;
|
||||
|
||||
code = metaHandleEntry(pMeta, &metaEntry);
|
||||
if (code) goto _err;
|
||||
|
@ -201,6 +202,7 @@ int32_t metaSnapWrite(SMetaSnapWriter* pWriter, uint8_t* pData, uint32_t nData)
|
|||
return code;
|
||||
|
||||
_err:
|
||||
tDecoderClear(pDecoder);
|
||||
metaError("vgId:%d, vnode snapshot meta write failed since %s", TD_VID(pMeta->pVnode), tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -116,68 +116,6 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
// SQTaskFile ======================================================
|
||||
|
||||
/**
|
||||
* @brief At most time, there is only one qtaskinfo file committed latest in aTaskFile. Sometimes, there would be
|
||||
* multiple qtaskinfo files supporting snapshot replication.
|
||||
*
|
||||
* @param pSma
|
||||
* @param pStat
|
||||
* @return int32_t
|
||||
*/
|
||||
static int32_t tdUpdateQTaskInfoFiles(SSma *pSma, SRSmaStat *pStat) {
|
||||
#if 0
|
||||
SVnode *pVnode = pSma->pVnode;
|
||||
SRSmaFS *pFS = RSMA_FS(pStat);
|
||||
int64_t committed = pStat->commitAppliedVer;
|
||||
int64_t fsMaxVer = -1;
|
||||
char qTaskInfoFullName[TSDB_FILENAME_LEN];
|
||||
|
||||
taosWLockLatch(RSMA_FS_LOCK(pStat));
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pFS->aQTaskInf);) {
|
||||
SQTaskFile *pTaskF = taosArrayGet(pFS->aQTaskInf, i);
|
||||
int32_t oldVal = atomic_fetch_sub_32(&pTaskF->nRef, 1);
|
||||
if ((oldVal <= 1) && (pTaskF->version < committed)) {
|
||||
tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->version, tfsGetPrimaryPath(pVnode->pTfs), qTaskInfoFullName);
|
||||
if (taosRemoveFile(qTaskInfoFullName) < 0) {
|
||||
smaWarn("vgId:%d, cleanup qinf, committed %" PRIi64 ", failed to remove %s since %s", TD_VID(pVnode), committed,
|
||||
qTaskInfoFullName, tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||
} else {
|
||||
smaDebug("vgId:%d, cleanup qinf, committed %" PRIi64 ", success to remove %s", TD_VID(pVnode), committed,
|
||||
qTaskInfoFullName);
|
||||
}
|
||||
taosArrayRemove(pFS->aQTaskInf, i);
|
||||
continue;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
if (taosArrayGetSize(pFS->aQTaskInf) > 0) {
|
||||
fsMaxVer = ((SQTaskFile *)taosArrayGetLast(pFS->aQTaskInf))->version;
|
||||
}
|
||||
|
||||
if (fsMaxVer < committed) {
|
||||
tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), committed, tfsGetPrimaryPath(pVnode->pTfs), qTaskInfoFullName);
|
||||
if (taosCheckExistFile(qTaskInfoFullName)) {
|
||||
SQTaskFile qFile = {.nRef = 1, .padding = 0, .version = committed, .size = 0};
|
||||
if (!taosArrayPush(pFS->aQTaskInf, &qFile)) {
|
||||
taosWUnLockLatch(RSMA_FS_LOCK(pStat));
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
smaDebug("vgId:%d, update qinf, no need as committed %" PRIi64 " not larger than fsMaxVer %" PRIi64, TD_VID(pVnode),
|
||||
committed, fsMaxVer);
|
||||
}
|
||||
|
||||
taosWUnLockLatch(RSMA_FS_LOCK(pStat));
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rsma async commit implementation(only do some necessary light weighted task)
|
||||
* 1) set rsma stat TASK_TRIGGER_STAT_PAUSED
|
||||
|
@ -187,7 +125,8 @@ static int32_t tdUpdateQTaskInfoFiles(SSma *pSma, SRSmaStat *pStat) {
|
|||
* @return int32_t
|
||||
*/
|
||||
static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
|
||||
int32_t code = 0;
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
SSmaEnv *pEnv = SMA_RSMA_ENV(pSma);
|
||||
if (!pEnv) {
|
||||
|
@ -208,7 +147,11 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
|
|||
}
|
||||
}
|
||||
pRSmaStat->commitAppliedVer = pSma->pVnode->state.applied;
|
||||
// ASSERT(pRSmaStat->commitAppliedVer > 0);
|
||||
if (ASSERTS(pRSmaStat->commitAppliedVer >= 0, "commit applied version %" PRIi64 " < 0",
|
||||
pRSmaStat->commitAppliedVer)) {
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
// step 2: wait for all triggered fetch tasks to finish
|
||||
nLoops = 0;
|
||||
|
@ -242,9 +185,9 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
|
|||
}
|
||||
}
|
||||
smaInfo("vgId:%d, rsma commit, all items are consumed, TID:%p", SMA_VID(pSma), (void *)taosGetSelfPthreadId());
|
||||
if ((code = tdRSmaPersistExecImpl(pRSmaStat, RSMA_INFO_HASH(pRSmaStat))) != 0) {
|
||||
return code;
|
||||
}
|
||||
code = tdRSmaPersistExecImpl(pRSmaStat, RSMA_INFO_HASH(pRSmaStat));
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
smaInfo("vgId:%d, rsma commit, operator state committed, TID:%p", SMA_VID(pSma), (void *)taosGetSelfPthreadId());
|
||||
|
||||
#if 0 // consuming task of qTaskInfo clone
|
||||
|
@ -252,8 +195,6 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
|
|||
// lock
|
||||
taosWLockLatch(SMA_ENV_LOCK(pEnv));
|
||||
|
||||
ASSERT(RSMA_INFO_HASH(pRSmaStat));
|
||||
|
||||
void *pIter = taosHashIterate(RSMA_INFO_HASH(pRSmaStat), NULL);
|
||||
|
||||
while (pIter) {
|
||||
|
@ -271,9 +212,19 @@ static int32_t tdProcessRSmaAsyncPreCommitImpl(SSma *pSma) {
|
|||
|
||||
// all rsma results are written completely
|
||||
STsdb *pTsdb = NULL;
|
||||
if ((pTsdb = VND_RSMA1(pSma->pVnode))) tsdbPrepareCommit(pTsdb);
|
||||
if ((pTsdb = VND_RSMA2(pSma->pVnode))) tsdbPrepareCommit(pTsdb);
|
||||
if ((pTsdb = VND_RSMA1(pSma->pVnode))) {
|
||||
code = tsdbPrepareCommit(pTsdb);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
if ((pTsdb = VND_RSMA2(pSma->pVnode))) {
|
||||
code = tsdbPrepareCommit(pTsdb);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
smaError("vgId:%d, %s failed at line %d since %s", SMA_VID(pSma), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -360,8 +311,6 @@ static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma) {
|
|||
taosWUnLockLatch(SMA_ENV_LOCK(pEnv));
|
||||
}
|
||||
|
||||
tdUpdateQTaskInfoFiles(pSma, pRSmaStat);
|
||||
|
||||
atomic_store_8(RSMA_COMMIT_STAT(pRSmaStat), 0);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
|
|
@ -131,7 +131,7 @@ static int32_t tdNewSmaEnv(SSma *pSma, int8_t smaType, SSmaEnv **ppEnv) {
|
|||
(smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_store_ptr(&SMA_TSMA_ENV(pSma), *ppEnv)
|
||||
: atomic_store_ptr(&SMA_RSMA_ENV(pSma), *ppEnv);
|
||||
|
||||
if (tdInitSmaStat(&SMA_ENV_STAT(pEnv), smaType, pSma) != TSDB_CODE_SUCCESS) {
|
||||
if ((terrno = tdInitSmaStat(&SMA_ENV_STAT(pEnv), smaType, pSma)) != TSDB_CODE_SUCCESS) {
|
||||
tdFreeSmaEnv(pEnv);
|
||||
*ppEnv = NULL;
|
||||
(smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_store_ptr(&SMA_TSMA_ENV(pSma), NULL)
|
||||
|
@ -193,10 +193,16 @@ static void tRSmaInfoHashFreeNode(void *data) {
|
|||
}
|
||||
|
||||
static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pSma) {
|
||||
ASSERT(pSmaStat != NULL);
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
if (ASSERTS(pSmaStat != NULL, "pSmaStat is NULL")) {
|
||||
terrno = TSDB_CODE_RSMA_INVALID_ENV;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
if (*pSmaStat) { // no lock
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return code; // success, return directly
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,8 +213,8 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
|
|||
if (!(*pSmaStat)) {
|
||||
*pSmaStat = (SSmaStat *)taosMemoryCalloc(1, sizeof(SSmaStat) + sizeof(TdThread) * tsNumOfVnodeRsmaThreads);
|
||||
if (!(*pSmaStat)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
if (smaType == TSDB_SMA_TYPE_ROLLUP) {
|
||||
|
@ -224,7 +230,8 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
|
|||
if (refId < 0) {
|
||||
smaError("vgId:%d, taosAddRef refId:%" PRIi64 " to rsetId rsetId:%d max:%d failed since:%s", SMA_VID(pSma),
|
||||
refId, smaMgmt.rsetId, SMA_MGMT_REF_NUM, tstrerror(terrno));
|
||||
return TSDB_CODE_FAILED;
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
} else {
|
||||
smaDebug("vgId:%d, taosAddRef refId:%" PRIi64 " to rsetId rsetId:%d max:%d succeed", SMA_VID(pSma), refId,
|
||||
smaMgmt.rsetId, SMA_MGMT_REF_NUM);
|
||||
|
@ -235,22 +242,30 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType, const SSma *pS
|
|||
RSMA_INFO_HASH(pRSmaStat) = taosHashInit(
|
||||
RSMA_TASK_INFO_HASH_SLOT, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
|
||||
if (!RSMA_INFO_HASH(pRSmaStat)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
taosHashSetFreeFp(RSMA_INFO_HASH(pRSmaStat), tRSmaInfoHashFreeNode);
|
||||
|
||||
if (tdRsmaStartExecutor(pSma) < 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
taosInitRWLatch(RSMA_FS_LOCK(pRSmaStat));
|
||||
} else if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||
// TODO
|
||||
} else {
|
||||
ASSERT(0);
|
||||
ASSERTS(0, "unknown smaType:%" PRIi8, smaType);
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_exit:
|
||||
if (code) {
|
||||
smaError("vgId:%d, %s failed at line %d since %s", SMA_VID(pSma), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static void tdDestroyTSmaStat(STSmaStat *pStat) {
|
||||
|
@ -339,7 +354,10 @@ static int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
|
|||
smaDebug("vgId:%d, remove refId:%" PRIi64 " from rsmaRef:%" PRIi32 " succeed", vid, refId, smaMgmt.rsetId);
|
||||
}
|
||||
} else {
|
||||
ASSERT(0);
|
||||
ASSERTS(0, "unknown smaType:%" PRIi8, smaType);
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
smaError("%s failed at line %d since %s", __func__, __LINE__, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -348,7 +366,7 @@ static int32_t tdDestroySmaState(SSmaStat *pSmaStat, int8_t smaType) {
|
|||
int32_t tdLockSma(SSma *pSma) {
|
||||
int code = taosThreadMutexLock(&pSma->mutex);
|
||||
if (code != 0) {
|
||||
smaError("vgId:%d, failed to lock td since %s", SMA_VID(pSma), strerror(errno));
|
||||
smaError("vgId:%d, failed to lock since %s", SMA_VID(pSma), strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
return -1;
|
||||
}
|
||||
|
@ -357,12 +375,17 @@ int32_t tdLockSma(SSma *pSma) {
|
|||
}
|
||||
|
||||
int32_t tdUnLockSma(SSma *pSma) {
|
||||
ASSERT(SMA_LOCKED(pSma));
|
||||
if (ASSERTS(SMA_LOCKED(pSma), "pSma %p is not locked:%d", pSma, pSma->locked)) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
smaError("vgId:%d, failed to unlock since %s", SMA_VID(pSma), tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
pSma->locked = false;
|
||||
int code = taosThreadMutexUnlock(&pSma->mutex);
|
||||
if (code != 0) {
|
||||
smaError("vgId:%d, failed to unlock td since %s", SMA_VID(pSma), strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(code);
|
||||
smaError("vgId:%d, failed to unlock since %s", SMA_VID(pSma), strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -77,7 +77,7 @@ static int32_t tsdbBinaryToFS(uint8_t *pData, int64_t nData, SRSmaFS *pFS) {
|
|||
|
||||
int32_t nt = tdRSmaGetQTaskF(pData + n, &qTaskF);
|
||||
if (nt < 0) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,11 @@ static int32_t tsdbBinaryToFS(uint8_t *pData, int64_t nData, SRSmaFS *pFS) {
|
|||
}
|
||||
}
|
||||
|
||||
ASSERT(n + sizeof(TSCKSUM) == nData);
|
||||
if (ASSERTS(n + sizeof(TSCKSUM) == nData, "n:%d + sizeof(TSCKSUM):%d != nData:%d", n, (int32_t)sizeof(TSCKSUM),
|
||||
nData)) {
|
||||
code = TSDB_CODE_FILE_CORRUPTED;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
|
@ -545,87 +549,6 @@ int32_t tdRSmaFSUpsertQTaskFile(SSma *pSma, SRSmaFS *pFS, SQTaskFile *qTaskFile,
|
|||
_exit:
|
||||
return code;
|
||||
}
|
||||
#if 0
|
||||
int32_t tdRSmaFSRef(SSma *pSma, SRSmaStat *pStat, int64_t suid, int8_t level, int64_t version) {
|
||||
SArray *aQTaskInf = RSMA_FS(pStat)->aQTaskInf;
|
||||
SQTaskFile qTaskF = {.level = level, .suid = suid, .version = version};
|
||||
SQTaskFile *pTaskF = NULL;
|
||||
int32_t oldVal = 0;
|
||||
|
||||
taosRLockLatch(RSMA_FS_LOCK(pStat));
|
||||
if (suid > 0 && level > 0) {
|
||||
ASSERT(version > 0);
|
||||
if ((pTaskF = taosArraySearch(aQTaskInf, &qTaskF, tdQTaskInfCmprFn1, TD_EQ))) {
|
||||
oldVal = atomic_fetch_add_32(&pTaskF->nRef, 1);
|
||||
ASSERT(oldVal > 0);
|
||||
}
|
||||
} else {
|
||||
// ref all
|
||||
int32_t size = taosArrayGetSize(aQTaskInf);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
pTaskF = TARRAY_GET_ELEM(aQTaskInf, i);
|
||||
oldVal = atomic_fetch_add_32(&pTaskF->nRef, 1);
|
||||
ASSERT(oldVal > 0);
|
||||
}
|
||||
}
|
||||
taosRUnLockLatch(RSMA_FS_LOCK(pStat));
|
||||
return oldVal;
|
||||
}
|
||||
|
||||
void tdRSmaFSUnRef(SSma *pSma, SRSmaStat *pStat, int64_t suid, int8_t level, int64_t version) {
|
||||
SVnode *pVnode = pSma->pVnode;
|
||||
SArray *aQTaskInf = RSMA_FS(pStat)->aQTaskInf;
|
||||
char qTaskFullName[TSDB_FILENAME_LEN];
|
||||
SQTaskFile qTaskF = {.level = level, .suid = suid, .version = version};
|
||||
SQTaskFile *pTaskF = NULL;
|
||||
int32_t idx = -1;
|
||||
|
||||
taosWLockLatch(RSMA_FS_LOCK(pStat));
|
||||
if (suid > 0 && level > 0) {
|
||||
ASSERT(version > 0);
|
||||
if ((idx = taosArraySearchIdx(aQTaskInf, &qTaskF, tdQTaskInfCmprFn1, TD_EQ)) >= 0) {
|
||||
ASSERT(idx < taosArrayGetSize(aQTaskInf));
|
||||
pTaskF = taosArrayGet(aQTaskInf, idx);
|
||||
if (atomic_sub_fetch_32(&pTaskF->nRef, 1) <= 0) {
|
||||
tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->suid, level, pTaskF->version,
|
||||
tfsGetPrimaryPath(pVnode->pTfs), qTaskFullName);
|
||||
if (taosRemoveFile(qTaskFullName) < 0) {
|
||||
smaWarn("vgId:%d, failed to remove %s since %s", TD_VID(pVnode), qTaskFullName,
|
||||
tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||
} else {
|
||||
smaDebug("vgId:%d, success to remove %s", TD_VID(pVnode), qTaskFullName);
|
||||
}
|
||||
taosArrayRemove(aQTaskInf, idx);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int32_t i = 0; i < taosArrayGetSize(aQTaskInf);) {
|
||||
pTaskF = TARRAY_GET_ELEM(aQTaskInf, i);
|
||||
int32_t nRef = INT32_MAX;
|
||||
if (pTaskF->version == version) {
|
||||
nRef = atomic_sub_fetch_32(&pTaskF->nRef, 1);
|
||||
} else if (pTaskF->version < version) {
|
||||
nRef = atomic_load_32(&pTaskF->nRef);
|
||||
}
|
||||
if (nRef <= 0) {
|
||||
tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->suid, pTaskF->level, pTaskF->version,
|
||||
tfsGetPrimaryPath(pVnode->pTfs), qTaskFullName);
|
||||
if (taosRemoveFile(qTaskFullName) < 0) {
|
||||
smaWarn("vgId:%d, failed to remove %s since %s", TD_VID(pVnode), qTaskFullName,
|
||||
tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||
} else {
|
||||
smaDebug("vgId:%d, success to remove %s", TD_VID(pVnode), qTaskFullName);
|
||||
}
|
||||
taosArrayRemove(aQTaskInf, i);
|
||||
continue;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
taosWUnLockLatch(RSMA_FS_LOCK(pStat));
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tdRSmaFSRef(SSma *pSma, SRSmaFS *pFS) {
|
||||
int32_t code = 0;
|
||||
|
|
|
@ -34,13 +34,16 @@ static int32_t rsmaRestore(SSma *pSma);
|
|||
SRetention *r = (SRetention *)VND_RETENTIONS(v) + l; \
|
||||
if (!RETENTION_VALID(r)) { \
|
||||
if (l == 0) { \
|
||||
goto _err; \
|
||||
code = TSDB_CODE_INVALID_PARA; \
|
||||
TSDB_CHECK_CODE(code, lino, _exit); \
|
||||
} \
|
||||
break; \
|
||||
} \
|
||||
smaSetKeepCfg(v, &keepCfg, pCfg, TSDB_TYPE_RSMA_L##l); \
|
||||
code = smaSetKeepCfg(v, &keepCfg, pCfg, TSDB_TYPE_RSMA_L##l); \
|
||||
TSDB_CHECK_CODE(code, lino, _exit); \
|
||||
if (tsdbOpen(v, &SMA_RSMA_TSDB##l(pSma), VNODE_RSMA##l##_DIR, &keepCfg, rollback) < 0) { \
|
||||
goto _err; \
|
||||
code = terrno; \
|
||||
TSDB_CHECK_CODE(code, lino, _exit); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
@ -68,12 +71,10 @@ static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t p
|
|||
days = keepDuration;
|
||||
}
|
||||
|
||||
if (level == TSDB_RETENTION_L0) {
|
||||
goto end;
|
||||
if (level < TSDB_RETENTION_L1 || level > TSDB_RETENTION_L2) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
ASSERT(level >= TSDB_RETENTION_L1 && level <= TSDB_RETENTION_L2);
|
||||
|
||||
freqDuration = convertTimeFromPrecisionToUnit((r + level)->freq, precision, TIME_UNIT_MINUTE);
|
||||
keepDuration = convertTimeFromPrecisionToUnit((r + level)->keep, precision, TIME_UNIT_MINUTE);
|
||||
|
||||
|
@ -91,16 +92,18 @@ static int32_t smaEvalDays(SVnode *pVnode, SRetention *r, int8_t level, int8_t p
|
|||
if (days < freqDuration) {
|
||||
days = freqDuration;
|
||||
}
|
||||
end:
|
||||
_exit:
|
||||
smaInfo("vgId:%d, evaluated duration for level %d is %d, raw val:%d", TD_VID(pVnode), level + 1, days, duration);
|
||||
return days;
|
||||
}
|
||||
|
||||
int smaSetKeepCfg(SVnode *pVnode, STsdbKeepCfg *pKeepCfg, STsdbCfg *pCfg, int type) {
|
||||
terrno = 0;
|
||||
pKeepCfg->precision = pCfg->precision;
|
||||
switch (type) {
|
||||
case TSDB_TYPE_TSMA:
|
||||
ASSERT(0);
|
||||
ASSERTS(0, "undefined smaType:%d", (int32_t)type);
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
break;
|
||||
case TSDB_TYPE_RSMA_L0:
|
||||
SMA_SET_KEEP_CFG(pVnode, 0);
|
||||
|
@ -112,19 +115,22 @@ int smaSetKeepCfg(SVnode *pVnode, STsdbKeepCfg *pKeepCfg, STsdbCfg *pCfg, int ty
|
|||
SMA_SET_KEEP_CFG(pVnode, 2);
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
ASSERTS(0, "unknown smaType:%d", (int32_t)type);
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
int32_t smaOpen(SVnode *pVnode, int8_t rollback) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
STsdbCfg *pCfg = &pVnode->config.tsdbCfg;
|
||||
|
||||
SSma *pSma = taosMemoryCalloc(1, sizeof(SSma));
|
||||
if (!pSma) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
pVnode->pSma = pSma;
|
||||
|
@ -143,21 +149,24 @@ int32_t smaOpen(SVnode *pVnode, int8_t rollback) {
|
|||
} else if (i == TSDB_RETENTION_L2) {
|
||||
SMA_OPEN_RSMA_IMPL(pVnode, 2);
|
||||
} else {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
smaError("vgId:%d, sma open failed since %s, level:%d", TD_VID(pVnode), terrstr(), i);
|
||||
goto _err;
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
smaError("vgId:%d, sma open failed since %s, level:%d", TD_VID(pVnode), tstrerror(code), i);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
}
|
||||
|
||||
// restore the rsma
|
||||
if (tdRSmaRestore(pSma, RSMA_RESTORE_REBOOT, pVnode->state.committed, rollback) < 0) {
|
||||
goto _err;
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
_err:
|
||||
return -1;
|
||||
_exit:
|
||||
if (code) {
|
||||
smaError("vgId:%d, %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t smaClose(SSma *pSma) {
|
||||
|
|
|
@ -129,12 +129,17 @@ void *tdFreeRSmaInfo(SSma *pSma, SRSmaInfo *pInfo, bool isDeepFree) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tdUidStoreInit(STbUidStore **pStore) {
|
||||
ASSERT(*pStore == NULL);
|
||||
if (ASSERTS(*pStore == NULL, "*pStore:%p != NULL", *pStore)) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
*pStore = taosMemoryCalloc(1, sizeof(STbUidStore));
|
||||
if (*pStore == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -163,15 +168,14 @@ static int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SArray *tbUids,
|
|||
|
||||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||
if (pRSmaInfo->taskInfo[i]) {
|
||||
if (((terrno = qUpdateQualifiedTableId(pRSmaInfo->taskInfo[i], tbUids, isAdd)) < 0)) {
|
||||
if ((terrno = qUpdateQualifiedTableId(pRSmaInfo->taskInfo[i], tbUids, isAdd)) < 0) {
|
||||
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||
smaError("vgId:%d, update tbUidList failed for uid:%" PRIi64 " level %d since %s", SMA_VID(pSma), *suid, i,
|
||||
terrstr());
|
||||
return TSDB_CODE_FAILED;
|
||||
} else {
|
||||
smaDebug("vgId:%d, update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 " uid:%" PRIi64 " level %d",
|
||||
SMA_VID(pSma), pRSmaInfo->taskInfo[0], *suid, *(int64_t *)taosArrayGet(tbUids, 0), i);
|
||||
}
|
||||
smaDebug("vgId:%d, update tbUidList succeed for qTaskInfo:%p with suid:%" PRIi64 " uid:%" PRIi64 " level %d",
|
||||
SMA_VID(pSma), pRSmaInfo->taskInfo[i], *suid, *(int64_t *)taosArrayGet(tbUids, 0), i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,8 +236,6 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
ASSERT(ppStore != NULL);
|
||||
|
||||
if (!(*ppStore)) {
|
||||
if (tdUidStoreInit(ppStore) < 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
|
@ -300,12 +302,15 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat
|
|||
}
|
||||
|
||||
pItem->level = idx == 0 ? TSDB_RETENTION_L1 : TSDB_RETENTION_L2;
|
||||
ASSERT(pItem->level > 0);
|
||||
|
||||
if (ASSERTS(pItem->level > 0, "pItem level:%" PRIi8 " should > 0", pItem->level)) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SRSmaRef rsmaRef = {.refId = pStat->refId, .suid = pRSmaInfo->suid};
|
||||
taosHashPut(smaMgmt.refHash, &pItem, POINTER_BYTES, &rsmaRef, sizeof(rsmaRef));
|
||||
|
||||
pItem->fetchLevel = pItem->level;
|
||||
taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId);
|
||||
|
||||
smaInfo("vgId:%d, item:%p table:%" PRIi64 " level:%" PRIi8 " maxdelay:%" PRIi64 " watermark:%" PRIi64
|
||||
|
@ -831,50 +836,51 @@ static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSize,
|
|||
|
||||
static int32_t tdCloneQTaskInfo(SSma *pSma, qTaskInfo_t dstTaskInfo, qTaskInfo_t srcTaskInfo, SRSmaParam *param,
|
||||
tb_uid_t suid, int8_t idx) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SVnode *pVnode = pSma->pVnode;
|
||||
char *pOutput = NULL;
|
||||
int32_t len = 0;
|
||||
|
||||
if (!srcTaskInfo) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
code = TSDB_CODE_INVALID_PTR;
|
||||
smaWarn("vgId:%d, rsma clone, table %" PRIi64 ", no need since srcTaskInfo is NULL", TD_VID(pVnode), suid);
|
||||
return TSDB_CODE_FAILED;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
if ((terrno = qSerializeTaskStatus(srcTaskInfo, &pOutput, &len)) < 0) {
|
||||
smaError("vgId:%d, rsma clone, table %" PRIi64 " serialize qTaskInfo failed since %s", TD_VID(pVnode), suid,
|
||||
terrstr());
|
||||
goto _err;
|
||||
}
|
||||
code = qSerializeTaskStatus(srcTaskInfo, &pOutput, &len);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
SReadHandle handle = {
|
||||
.meta = pVnode->pMeta,
|
||||
.vnode = pVnode,
|
||||
.initTqReader = 1,
|
||||
};
|
||||
ASSERT(!dstTaskInfo);
|
||||
dstTaskInfo = qCreateStreamExecTaskInfo(param->qmsg[idx], &handle);
|
||||
if (!dstTaskInfo) {
|
||||
terrno = TSDB_CODE_RSMA_QTASKINFO_CREATE;
|
||||
goto _err;
|
||||
|
||||
if (ASSERTS(!dstTaskInfo, "dstTaskInfo:%p is not NULL", dstTaskInfo)) {
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
if (qDeserializeTaskStatus(dstTaskInfo, pOutput, len) < 0) {
|
||||
smaError("vgId:%d, rsma clone, restore rsma task for table:%" PRIi64 " failed since %s", TD_VID(pVnode), suid,
|
||||
terrstr());
|
||||
goto _err;
|
||||
dstTaskInfo = qCreateStreamExecTaskInfo(param->qmsg[idx], &handle);
|
||||
if (!dstTaskInfo) {
|
||||
code = TSDB_CODE_RSMA_QTASKINFO_CREATE;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
code = qDeserializeTaskStatus(dstTaskInfo, pOutput, len);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
smaDebug("vgId:%d, rsma clone, restore rsma task for table:%" PRIi64 " succeed", TD_VID(pVnode), suid);
|
||||
|
||||
_exit:
|
||||
taosMemoryFreeClear(pOutput);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_err:
|
||||
taosMemoryFreeClear(pOutput);
|
||||
tdRSmaQTaskInfoFree(dstTaskInfo, TD_VID(pVnode), idx + 1);
|
||||
smaError("vgId:%d, rsma clone, restore rsma task for table:%" PRIi64 " failed since %s", TD_VID(pVnode), suid,
|
||||
terrstr());
|
||||
return TSDB_CODE_FAILED;
|
||||
if (code) {
|
||||
tdRSmaQTaskInfoFree(dstTaskInfo, TD_VID(pVnode), idx + 1);
|
||||
smaError("vgId:%d, rsma clone, restore rsma task for table:%" PRIi64 " failed since %s", TD_VID(pVnode), suid,
|
||||
terrstr());
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -885,43 +891,53 @@ _err:
|
|||
* @return int32_t
|
||||
*/
|
||||
static int32_t tdRSmaInfoClone(SSma *pSma, SRSmaInfo *pInfo) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SRSmaParam *param = NULL;
|
||||
SMetaReader mr = {0};
|
||||
|
||||
if (!pInfo) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SMetaReader mr = {0};
|
||||
metaReaderInit(&mr, SMA_META(pSma), 0);
|
||||
smaDebug("vgId:%d, rsma clone qTaskInfo for suid:%" PRIi64, SMA_VID(pSma), pInfo->suid);
|
||||
if (metaGetTableEntryByUidCache(&mr, pInfo->suid) < 0) {
|
||||
smaError("vgId:%d, rsma clone, failed to get table meta for %" PRIi64 " since %s", SMA_VID(pSma), pInfo->suid,
|
||||
terrstr());
|
||||
goto _err;
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
ASSERT(mr.me.type == TSDB_SUPER_TABLE);
|
||||
ASSERT(mr.me.uid == pInfo->suid);
|
||||
|
||||
if (mr.me.type != TSDB_SUPER_TABLE) {
|
||||
code = TSDB_CODE_RSMA_INVALID_SCHEMA;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
if (mr.me.uid != pInfo->suid) {
|
||||
code = TSDB_CODE_RSMA_INVALID_SCHEMA;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
if (TABLE_IS_ROLLUP(mr.me.flags)) {
|
||||
param = &mr.me.stbEntry.rsmaParam;
|
||||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||
if (!pInfo->iTaskInfo[i]) {
|
||||
continue;
|
||||
}
|
||||
if (tdCloneQTaskInfo(pSma, pInfo->taskInfo[i], pInfo->iTaskInfo[i], param, pInfo->suid, i) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
code = tdCloneQTaskInfo(pSma, pInfo->taskInfo[i], pInfo->iTaskInfo[i], param, pInfo->suid, i);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
smaDebug("vgId:%d, rsma clone env success for %" PRIi64, SMA_VID(pSma), pInfo->suid);
|
||||
} else {
|
||||
terrno = TSDB_CODE_RSMA_INVALID_SCHEMA;
|
||||
goto _err;
|
||||
code = TSDB_CODE_RSMA_INVALID_SCHEMA;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
smaError("vgId:%d, %s failed at line %d since %s, suid:%" PRIi64 ", flags:%" PRIi8 ",type:%" PRIi8 ", uid:%" PRIi64,
|
||||
SMA_VID(pSma), __func__, lino, tstrerror(code), pInfo->suid, mr.me.flags, mr.me.type, mr.me.uid);
|
||||
}
|
||||
metaReaderClear(&mr);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_err:
|
||||
metaReaderClear(&mr);
|
||||
smaError("vgId:%d, rsma clone env failed for %" PRIi64 " since %s", SMA_VID(pSma), pInfo->suid, terrstr());
|
||||
return TSDB_CODE_FAILED;
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -932,10 +948,14 @@ _err:
|
|||
* @return SRSmaInfo*
|
||||
*/
|
||||
static SRSmaInfo *tdAcquireRSmaInfoBySuid(SSma *pSma, int64_t suid) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SSmaEnv *pEnv = SMA_RSMA_ENV(pSma);
|
||||
SRSmaStat *pStat = NULL;
|
||||
SRSmaInfo *pRSmaInfo = NULL;
|
||||
|
||||
terrno = 0;
|
||||
|
||||
if (!pEnv) {
|
||||
terrno = TSDB_CODE_RSMA_INVALID_ENV;
|
||||
return NULL;
|
||||
|
@ -955,14 +975,17 @@ static SRSmaInfo *tdAcquireRSmaInfoBySuid(SSma *pSma, int64_t suid) {
|
|||
return NULL;
|
||||
}
|
||||
if (!pRSmaInfo->taskInfo[0]) {
|
||||
if (tdRSmaInfoClone(pSma, pRSmaInfo) < 0) {
|
||||
if ((terrno = tdRSmaInfoClone(pSma, pRSmaInfo)) < 0) {
|
||||
taosRUnLockLatch(SMA_ENV_LOCK(pEnv));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
tdRefRSmaInfo(pSma, pRSmaInfo);
|
||||
taosRUnLockLatch(SMA_ENV_LOCK(pEnv));
|
||||
ASSERT(pRSmaInfo->suid == suid);
|
||||
if (ASSERTS(pRSmaInfo->suid == suid, "suid:%" PRIi64 " != %" PRIi64, pRSmaInfo->suid, suid)) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
return pRSmaInfo;
|
||||
}
|
||||
taosRUnLockLatch(SMA_ENV_LOCK(pEnv));
|
||||
|
@ -1010,7 +1033,11 @@ static int32_t tdExecuteRSmaAsync(SSma *pSma, int64_t version, const void *pMsg,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
ASSERT(0);
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||
smaError("vgId:%d, execute rsma, failed for suid:%" PRIu64 " since %s, type:%d", SMA_VID(pSma), suid,
|
||||
tstrerror(terrno), inputType);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
tdReleaseRSmaInfo(pSma, pRSmaInfo);
|
||||
|
@ -1063,19 +1090,22 @@ _err:
|
|||
* @return int32_t
|
||||
*/
|
||||
static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SVnode *pVnode = pSma->pVnode;
|
||||
SArray *suidList = NULL;
|
||||
STbUidStore uidStore = {0};
|
||||
SMetaReader mr = {0};
|
||||
tb_uid_t suid = 0;
|
||||
|
||||
if (!(suidList = taosArrayInit(1, sizeof(tb_uid_t)))) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
if (vnodeGetStbIdList(pSma->pVnode, 0, suidList) < 0) {
|
||||
smaError("vgId:%d, failed to restore rsma env since get stb id list error: %s", TD_VID(pVnode), terrstr());
|
||||
goto _err;
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
int64_t arrSize = taosArrayGetSize(suidList);
|
||||
|
@ -1092,19 +1122,26 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
|
|||
int64_t nRsmaTables = 0;
|
||||
metaReaderInit(&mr, SMA_META(pSma), 0);
|
||||
if (!(uidStore.tbUids = taosArrayInit(1024, sizeof(tb_uid_t)))) {
|
||||
goto _err;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
for (int64_t i = 0; i < arrSize; ++i) {
|
||||
tb_uid_t suid = *(tb_uid_t *)taosArrayGet(suidList, i);
|
||||
suid = *(tb_uid_t *)taosArrayGet(suidList, i);
|
||||
smaDebug("vgId:%d, rsma restore, suid is %" PRIi64, TD_VID(pVnode), suid);
|
||||
if (metaGetTableEntryByUidCache(&mr, suid) < 0) {
|
||||
smaError("vgId:%d, rsma restore, failed to get table meta for %" PRIi64 " since %s", TD_VID(pVnode), suid,
|
||||
terrstr());
|
||||
goto _err;
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
tDecoderClear(&mr.coder);
|
||||
ASSERT(mr.me.type == TSDB_SUPER_TABLE);
|
||||
ASSERT(mr.me.uid == suid);
|
||||
if (mr.me.type != TSDB_SUPER_TABLE) {
|
||||
code = TSDB_CODE_RSMA_INVALID_SCHEMA;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
if (mr.me.uid != suid) {
|
||||
code = TSDB_CODE_RSMA_INVALID_SCHEMA;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
if (TABLE_IS_ROLLUP(mr.me.flags)) {
|
||||
++nRsmaTables;
|
||||
SRSmaParam *param = &mr.me.stbEntry.rsmaParam;
|
||||
|
@ -1114,22 +1151,20 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
|
|||
TD_VID(pVnode), suid, i, param->maxdelay[i], param->watermark[i], param->qmsgLen[i]);
|
||||
}
|
||||
if (tdRSmaProcessCreateImpl(pSma, &mr.me.stbEntry.rsmaParam, suid, mr.me.name) < 0) {
|
||||
smaError("vgId:%d, rsma restore env failed for %" PRIi64 " since %s", TD_VID(pVnode), suid, terrstr());
|
||||
goto _err;
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
// reload all ctbUids for suid
|
||||
uidStore.suid = suid;
|
||||
if (vnodeGetCtbIdList(pVnode, suid, uidStore.tbUids) < 0) {
|
||||
smaError("vgId:%d, rsma restore, get ctb idlist failed for %" PRIi64 " since %s", TD_VID(pVnode), suid,
|
||||
terrstr());
|
||||
goto _err;
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
if (tdUpdateTbUidList(pVnode->pSma, &uidStore, true) < 0) {
|
||||
smaError("vgId:%d, rsma restore, update tb uid list failed for %" PRIi64 " since %s", TD_VID(pVnode), suid,
|
||||
terrstr());
|
||||
goto _err;
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
taosArrayClear(uidStore.tbUids);
|
||||
|
@ -1138,21 +1173,18 @@ static int32_t tdRSmaRestoreQTaskInfoInit(SSma *pSma, int64_t *nTables) {
|
|||
}
|
||||
}
|
||||
|
||||
metaReaderClear(&mr);
|
||||
taosArrayDestroy(suidList);
|
||||
tdUidStoreDestory(&uidStore);
|
||||
|
||||
if (nTables) {
|
||||
*nTables = nRsmaTables;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_err:
|
||||
_exit:
|
||||
if (code) {
|
||||
smaError("vgId:%d, %s failed at line %d since %s, suid:%" PRIi64 ", type:%" PRIi8 ", uid:%" PRIi64, TD_VID(pVnode),
|
||||
__func__, lino, tstrerror(code), suid, mr.me.type, mr.me.uid);
|
||||
}
|
||||
metaReaderClear(&mr);
|
||||
taosArrayDestroy(suidList);
|
||||
tdUidStoreDestory(&uidStore);
|
||||
|
||||
return TSDB_CODE_FAILED;
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1254,7 +1286,6 @@ int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash) {
|
|||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
ASSERT(size > 0);
|
||||
|
||||
int64_t offset = 0;
|
||||
if (taosFSendFile(pOutFD, pInFD, &offset, size) < 0) {
|
||||
|
@ -1374,10 +1405,11 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) {
|
|||
// async process
|
||||
pItem->fetchLevel = pItem->level;
|
||||
#if 0
|
||||
// debugging codes
|
||||
SRSmaInfo *qInfo = tdAcquireRSmaInfoBySuid(pSma, pRSmaInfo->suid);
|
||||
SRSmaInfoItem *qItem = RSMA_INFO_ITEM(qInfo, pItem->level - 1);
|
||||
ASSERT(qItem->level == pItem->level);
|
||||
ASSERT(qItem->fetchLevel == pItem->fetchLevel);
|
||||
make sure(qItem->level == pItem->level);
|
||||
make sure(qItem->fetchLevel == pItem->fetchLevel);
|
||||
#endif
|
||||
if (atomic_load_8(&pRSmaInfo->assigned) == 0) {
|
||||
tsem_post(&(pStat->notEmpty));
|
||||
|
@ -1524,6 +1556,8 @@ _err:
|
|||
*/
|
||||
|
||||
int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
SVnode *pVnode = pSma->pVnode;
|
||||
SSmaEnv *pEnv = SMA_RSMA_ENV(pSma);
|
||||
SRSmaStat *pRSmaStat = (SRSmaStat *)SMA_ENV_STAT(pEnv);
|
||||
|
@ -1532,14 +1566,14 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
|
|||
bool isFetchAll = false;
|
||||
|
||||
if (!pRSmaStat || !(infoHash = RSMA_INFO_HASH(pRSmaStat))) {
|
||||
terrno = TSDB_CODE_RSMA_INVALID_STAT;
|
||||
goto _err;
|
||||
code = TSDB_CODE_RSMA_INVALID_STAT;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
if (!(pSubmitArr =
|
||||
taosArrayInit(TMIN(RSMA_SUBMIT_BATCH_SIZE, atomic_load_64(&pRSmaStat->nBufItems)), sizeof(SPackedData)))) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
|
@ -1570,7 +1604,11 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
|
|||
if (oldStat == 0 ||
|
||||
((oldStat == 2) && atomic_load_8(RSMA_TRIGGER_STAT(pRSmaStat)) < TASK_TRIGGER_STAT_PAUSED)) {
|
||||
int32_t oldVal = atomic_fetch_add_32(&pRSmaStat->nFetchAll, 1);
|
||||
ASSERT(oldVal >= 0);
|
||||
|
||||
if (ASSERTS(oldVal >= 0, "oldVal of nFetchAll: %d < 0", oldVal)) {
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
int8_t curStat = atomic_load_8(RSMA_COMMIT_STAT(pRSmaStat));
|
||||
if (curStat == 1) {
|
||||
|
@ -1600,7 +1638,9 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
ASSERT(0);
|
||||
ASSERTS(0, "unknown rsma exec type:%d", (int32_t)type);
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
if (atomic_load_64(&pRSmaStat->nBufItems) <= 0) {
|
||||
|
@ -1619,10 +1659,10 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) {
|
|||
|
||||
} // end of while(true)
|
||||
|
||||
_end:
|
||||
_exit:
|
||||
taosArrayDestroy(pSubmitArr);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_err:
|
||||
taosArrayDestroy(pSubmitArr);
|
||||
return TSDB_CODE_FAILED;
|
||||
if (code) {
|
||||
smaError("vgId:%d, %s failed at line %d since %s", TD_VID(pVnode), __func__, lino, tstrerror(code));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "sma.h"
|
||||
#include "tq.h"
|
||||
#include "tsdb.h"
|
||||
|
||||
#define SMA_STORAGE_MINUTES_MAX 86400
|
||||
|
@ -155,6 +156,200 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *pTSchema,
|
||||
SSchemaWrapper *pTagSchemaWrapper, bool createTb, int64_t suid, const char *stbFullName,
|
||||
SBatchDeleteReq *pDeleteReq, void **ppData, int32_t *pLen) {
|
||||
void *pBuf = NULL;
|
||||
int32_t len = 0;
|
||||
SSubmitReq2 *pReq = NULL;
|
||||
SArray *tagArray = NULL;
|
||||
SArray *createTbArray = NULL;
|
||||
SArray *pVals = NULL;
|
||||
|
||||
int32_t sz = taosArrayGetSize(pBlocks);
|
||||
|
||||
if (!(tagArray = taosArrayInit(1, sizeof(STagVal)))) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(createTbArray = taosArrayInit(sz, POINTER_BYTES))) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(pReq = taosMemoryCalloc(1, sizeof(SSubmitReq2)))) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(pReq->aSubmitTbData = taosArrayInit(1, sizeof(SSubmitTbData)))) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
// create table req
|
||||
if (createTb) {
|
||||
for (int32_t i = 0; i < sz; ++i) {
|
||||
SSDataBlock *pDataBlock = taosArrayGet(pBlocks, i);
|
||||
SVCreateTbReq *pCreateTbReq = NULL;
|
||||
if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
|
||||
taosArrayPush(createTbArray, &pCreateTbReq);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateStbReq)))) {
|
||||
goto _end;
|
||||
};
|
||||
|
||||
// don't move to the end of loop as to destroy in the end of func when error occur
|
||||
taosArrayPush(createTbArray, &pCreateTbReq);
|
||||
|
||||
// set const
|
||||
pCreateTbReq->flags = 0;
|
||||
pCreateTbReq->type = TSDB_CHILD_TABLE;
|
||||
pCreateTbReq->ctb.suid = suid;
|
||||
|
||||
// set super table name
|
||||
SName name = {0};
|
||||
tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
pCreateTbReq->ctb.stbName = strdup((char *)tNameGetTableName(&name)); // strdup(stbFullName);
|
||||
|
||||
// set tag content
|
||||
taosArrayClear(tagArray);
|
||||
STagVal tagVal = {
|
||||
.cid = taosArrayGetSize(pDataBlock->pDataBlock) + 1,
|
||||
.type = TSDB_DATA_TYPE_UBIGINT,
|
||||
.i64 = (int64_t)pDataBlock->info.id.groupId,
|
||||
};
|
||||
taosArrayPush(tagArray, &tagVal);
|
||||
pCreateTbReq->ctb.tagNum = taosArrayGetSize(tagArray);
|
||||
|
||||
STag *pTag = NULL;
|
||||
tTagNew(tagArray, 1, false, &pTag);
|
||||
if (pTag == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _end;
|
||||
}
|
||||
pCreateTbReq->ctb.pTag = (uint8_t *)pTag;
|
||||
|
||||
// set tag name
|
||||
SArray *tagName = taosArrayInit(1, TSDB_COL_NAME_LEN);
|
||||
char tagNameStr[TSDB_COL_NAME_LEN] = {0};
|
||||
strcpy(tagNameStr, "group_id");
|
||||
taosArrayPush(tagName, tagNameStr);
|
||||
pCreateTbReq->ctb.tagName = tagName;
|
||||
|
||||
// set table name
|
||||
if (pDataBlock->info.parTbName[0]) {
|
||||
pCreateTbReq->name = strdup(pDataBlock->info.parTbName);
|
||||
} else {
|
||||
pCreateTbReq->name = buildCtbNameByGroupId(stbFullName, pDataBlock->info.id.groupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SSubmitTbData req
|
||||
for (int32_t i = 0; i < sz; ++i) {
|
||||
SSDataBlock *pDataBlock = taosArrayGet(pBlocks, i);
|
||||
if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
|
||||
pDeleteReq->suid = suid;
|
||||
pDeleteReq->deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq));
|
||||
tqBuildDeleteReq(pVnode, stbFullName, pDataBlock, pDeleteReq);
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
|
||||
SSubmitTbData *pTbData = (SSubmitTbData *)taosMemoryCalloc(1, sizeof(SSubmitTbData));
|
||||
if (!pTbData) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(pTbData->aRowP = taosArrayInit(rows, sizeof(SRow *)))) {
|
||||
taosMemoryFree(pTbData);
|
||||
goto _end;
|
||||
}
|
||||
pTbData->suid = suid;
|
||||
pTbData->uid = 0; // uid is assigned by vnode
|
||||
pTbData->sver = pTSchema->version;
|
||||
|
||||
if (createTb) {
|
||||
pTbData->pCreateTbReq = taosArrayGetP(createTbArray, i);
|
||||
if (pTbData->pCreateTbReq) pTbData->flags = SUBMIT_REQ_AUTO_CREATE_TABLE;
|
||||
}
|
||||
|
||||
if (!pVals && !(pVals = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal)))) {
|
||||
taosArrayDestroy(pTbData->aRowP);
|
||||
taosMemoryFree(pTbData);
|
||||
goto _end;
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < rows; ++j) {
|
||||
taosArrayClear(pVals);
|
||||
for (int32_t k = 0; k < pTSchema->numOfCols; k++) {
|
||||
const STColumn *pCol = &pTSchema->columns[k];
|
||||
SColumnInfoData *pColData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
if (colDataIsNull_s(pColData, j)) {
|
||||
SColVal cv = COL_VAL_NULL(pCol->colId, pCol->type);
|
||||
taosArrayPush(pVals, &cv);
|
||||
} else {
|
||||
void *data = colDataGetData(pColData, j);
|
||||
if (IS_STR_DATA_TYPE(pCol->type)) {
|
||||
SValue sv = (SValue){.nData = varDataLen(data), .pData = varDataVal(data)}; // address copy, no value
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
||||
taosArrayPush(pVals, &cv);
|
||||
} else {
|
||||
SValue sv;
|
||||
memcpy(&sv.val, data, tDataTypes[pCol->type].bytes);
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
||||
taosArrayPush(pVals, &cv);
|
||||
}
|
||||
}
|
||||
}
|
||||
SRow *pRow = NULL;
|
||||
if ((terrno = tRowBuild(pVals, (STSchema *)pTSchema, &pRow)) < 0) {
|
||||
tDestroySSubmitTbData(pTbData, TSDB_MSG_FLG_ENCODE);
|
||||
goto _end;
|
||||
}
|
||||
ASSERT(pRow);
|
||||
taosArrayPush(pTbData->aRowP, &pRow);
|
||||
}
|
||||
|
||||
taosArrayPush(pReq->aSubmitTbData, pTbData);
|
||||
}
|
||||
|
||||
// encode
|
||||
tEncodeSize(tEncodeSSubmitReq2, pReq, len, terrno);
|
||||
if (TSDB_CODE_SUCCESS == terrno) {
|
||||
SEncoder encoder;
|
||||
len += sizeof(SMsgHead);
|
||||
pBuf = rpcMallocCont(len);
|
||||
if (NULL == pBuf) {
|
||||
goto _end;
|
||||
}
|
||||
((SMsgHead *)pBuf)->vgId = TD_VID(pVnode);
|
||||
((SMsgHead *)pBuf)->contLen = htonl(len);
|
||||
tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len - sizeof(SMsgHead));
|
||||
if (tEncodeSSubmitReq2(&encoder, pReq) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
/*vError("failed to encode submit req since %s", terrstr());*/
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
}
|
||||
_end:
|
||||
taosArrayDestroy(tagArray);
|
||||
taosArrayDestroy(pVals);
|
||||
tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
|
||||
|
||||
if (terrno != 0) {
|
||||
rpcFreeCont(pBuf);
|
||||
taosArrayDestroy(pDeleteReq->deleteReqs);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (ppData) *ppData = pBuf;
|
||||
if (pLen) *pLen = len;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Insert/Update Time-range-wise SMA data.
|
||||
*
|
||||
|
@ -220,8 +415,9 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char
|
|||
void *pSubmitReq = NULL;
|
||||
int32_t contLen = 0;
|
||||
|
||||
if (tqBlockToSubmit(pSma->pVnode, (const SArray *)msg, pTsmaStat->pTSchema, &pTsmaStat->pTSma->schemaTag, true,
|
||||
pTsmaStat->pTSma->dstTbUid, pTsmaStat->pTSma->dstTbName, &deleteReq, &pSubmitReq, &contLen) < 0) {
|
||||
if (smaBlockToSubmit(pSma->pVnode, (const SArray *)msg, pTsmaStat->pTSchema, &pTsmaStat->pTSma->schemaTag, true,
|
||||
pTsmaStat->pTSma->dstTbUid, pTsmaStat->pTSma->dstTbName, &deleteReq, &pSubmitReq,
|
||||
&contLen) < 0) {
|
||||
smaError("vgId:%d, failed to gen submit msg while tsma insert for smaIndex %" PRIi64 " since %s", SMA_VID(pSma),
|
||||
indexUid, tstrerror(terrno));
|
||||
goto _err;
|
||||
|
@ -241,7 +437,7 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char
|
|||
SRpcMsg submitReqMsg = {
|
||||
.msgType = TDMT_VND_SUBMIT,
|
||||
.pCont = pSubmitReq,
|
||||
.contLen = ntohl(contLen),
|
||||
.contLen = contLen,
|
||||
};
|
||||
|
||||
if (tmsgPutToQueue(&pSma->pVnode->msgCb, WRITE_QUEUE, &submitReqMsg) < 0) {
|
||||
|
|
|
@ -725,6 +725,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen) {
|
||||
SMqVDeleteReq* pReq = (SMqVDeleteReq*)msg;
|
||||
|
||||
tqDebug("vgId:%d, tq process delete sub req %s", pTq->pVnode->config.vgId, pReq->subKey);
|
||||
|
||||
taosWLockLatch(&pTq->pushLock);
|
||||
int32_t code = taosHashRemove(pTq->pPushMgr, pReq->subKey, strlen(pReq->subKey));
|
||||
if (code != 0) {
|
||||
|
@ -791,6 +793,9 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t version, char* msg, int32_t msgL
|
|||
SMqRebVgReq req = {0};
|
||||
tDecodeSMqRebVgReq(msg, &req);
|
||||
// todo lock
|
||||
|
||||
tqDebug("vgId:%d, tq process sub req %s", pTq->pVnode->config.vgId, req.subKey);
|
||||
|
||||
STqHandle* pHandle = taosHashGet(pTq->pHandle, req.subKey, strlen(req.subKey));
|
||||
if (pHandle == NULL) {
|
||||
if (req.oldConsumerId != -1) {
|
||||
|
@ -881,6 +886,9 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t version, char* msg, int32_t msgL
|
|||
atomic_store_64(&pHandle->consumerId, req.newConsumerId);
|
||||
atomic_add_fetch_32(&pHandle->epoch, 1);
|
||||
taosMemoryFree(req.qmsg);
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
qStreamCloseTsdbReader(pHandle->execHandle.task);
|
||||
}
|
||||
if (tqMetaSaveHandle(pTq, req.subKey, pHandle) < 0) {
|
||||
}
|
||||
// close handle
|
||||
|
@ -1117,6 +1125,11 @@ int32_t tqProcessTaskRecover1Req(STQ* pTq, SRpcMsg* pMsg) {
|
|||
// do recovery step 1
|
||||
streamSourceRecoverScanStep1(pTask);
|
||||
|
||||
if (atomic_load_8(&pTask->taskStatus) == TASK_STATUS__DROPPING) {
|
||||
streamMetaReleaseTask(pTq->pStreamMeta, pTask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// build msg to launch next step
|
||||
SStreamRecoverStep2Req req;
|
||||
code = streamBuildSourceRecover2Req(pTask, &req);
|
||||
|
@ -1127,6 +1140,10 @@ int32_t tqProcessTaskRecover1Req(STQ* pTq, SRpcMsg* pMsg) {
|
|||
|
||||
streamMetaReleaseTask(pTq->pStreamMeta, pTask);
|
||||
|
||||
if (atomic_load_8(&pTask->taskStatus) == TASK_STATUS__DROPPING) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// serialize msg
|
||||
int32_t len = sizeof(SStreamRecoverStep1Req);
|
||||
|
||||
|
@ -1165,6 +1182,11 @@ int32_t tqProcessTaskRecover2Req(STQ* pTq, int64_t version, char* msg, int32_t m
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (atomic_load_8(&pTask->taskStatus) == TASK_STATUS__DROPPING) {
|
||||
streamMetaReleaseTask(pTq->pStreamMeta, pTask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// restore param
|
||||
code = streamRestoreParam(pTask);
|
||||
if (code < 0) {
|
||||
|
|
|
@ -45,19 +45,37 @@ int32_t tqOffsetRestoreFromFile(STqOffsetStore* pStore, const char* fname) {
|
|||
}
|
||||
int32_t size = htonl(head.size);
|
||||
void* memBuf = taosMemoryCalloc(1, size);
|
||||
if (memBuf == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if ((code = taosReadFile(pFile, memBuf, size)) != size) {
|
||||
taosMemoryFree(memBuf);
|
||||
return -1;
|
||||
}
|
||||
STqOffset offset;
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, memBuf, size);
|
||||
if (tDecodeSTqOffset(&decoder, &offset) < 0) {
|
||||
taosMemoryFree(memBuf);
|
||||
tDecoderClear(&decoder);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
if (taosHashPut(pStore->pHash, offset.subKey, strlen(offset.subKey), &offset, sizeof(STqOffset)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (offset.val.type == TMQ_OFFSET__LOG) {
|
||||
STqHandle* pHandle = taosHashGet(pStore->pTq->pHandle, offset.subKey, strlen(offset.subKey));
|
||||
if (pHandle) {
|
||||
if (walRefVer(pHandle->pRef, offset.val.version) < 0) {
|
||||
tqError("vgId: %d, tq handle %s ref ver %" PRId64 "error", pStore->pTq->pVnode->config.vgId,
|
||||
pHandle->subKey, offset.val.version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
taosMemoryFree(memBuf);
|
||||
}
|
||||
|
||||
|
@ -123,6 +141,7 @@ int32_t tqOffsetCommitFile(STqOffsetStore* pStore) {
|
|||
const char* sysErrStr = strerror(errno);
|
||||
tqError("vgId:%d, cannot open file %s when commit offset since %s", pStore->pTq->pVnode->config.vgId, fname,
|
||||
sysErrStr);
|
||||
taosMemoryFree(fname);
|
||||
return -1;
|
||||
}
|
||||
taosMemoryFree(fname);
|
||||
|
|
|
@ -63,7 +63,7 @@ int32_t tqBuildDeleteReq(SVnode* pVnode, const char* stbFullName, const SSDataBl
|
|||
.startTs = startTs,
|
||||
.endTs = endTs,
|
||||
};
|
||||
strncpy(req.tbname, name, TSDB_TABLE_NAME_LEN);
|
||||
strncpy(req.tbname, name, TSDB_TABLE_NAME_LEN - 1);
|
||||
taosMemoryFree(name);
|
||||
/*tqDebug("stream delete msg, active: vgId:%d, ts:%" PRId64 " name:%s", pVnode->config.vgId, ts, name);*/
|
||||
taosArrayPush(deleteReq->deleteReqs, &req);
|
||||
|
@ -71,427 +71,6 @@ int32_t tqBuildDeleteReq(SVnode* pVnode, const char* stbFullName, const SSDataBl
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pTSchema,
|
||||
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
||||
SBatchDeleteReq* pDeleteReq) {
|
||||
SSubmitReq* ret = NULL;
|
||||
SArray* schemaReqs = NULL;
|
||||
SArray* schemaReqSz = NULL;
|
||||
SArray* tagArray = taosArrayInit(1, sizeof(STagVal));
|
||||
if (!tagArray) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t sz = taosArrayGetSize(pBlocks);
|
||||
|
||||
if (createTb) {
|
||||
schemaReqs = taosArrayInit(sz, sizeof(void*));
|
||||
schemaReqSz = taosArrayInit(sz, sizeof(int32_t));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
||||
if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
|
||||
int32_t padding1 = 0;
|
||||
void* padding2 = NULL;
|
||||
taosArrayPush(schemaReqSz, &padding1);
|
||||
taosArrayPush(schemaReqs, &padding2);
|
||||
continue;
|
||||
}
|
||||
|
||||
// STag* pTag = NULL;
|
||||
// taosArrayClear(tagArray);
|
||||
// SArray *tagName = taosArrayInit(1, TSDB_COL_NAME_LEN);
|
||||
// for(int j = 0; j < pTagSchemaWrapper->nCols; j++){
|
||||
// STagVal tagVal = {
|
||||
// .cid = pTagSchemaWrapper->pSchema[j].colId,
|
||||
// .type = pTagSchemaWrapper->pSchema[j].type,
|
||||
// .i64 = (int64_t)pDataBlock->info.id.groupId,
|
||||
// };
|
||||
// taosArrayPush(tagArray, &tagVal);
|
||||
// taosArrayPush(tagName, pTagSchemaWrapper->pSchema[j].name);
|
||||
// }
|
||||
//
|
||||
// tTagNew(tagArray, 1, false, &pTag);
|
||||
// if (pTag == NULL) {
|
||||
// terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
// taosArrayDestroy(tagArray);
|
||||
// taosArrayDestroy(tagName);
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
SVCreateTbReq createTbReq = {0};
|
||||
|
||||
// set const
|
||||
createTbReq.flags = 0;
|
||||
createTbReq.type = TSDB_CHILD_TABLE;
|
||||
createTbReq.ctb.suid = suid;
|
||||
|
||||
// set super table name
|
||||
SName name = {0};
|
||||
tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
createTbReq.ctb.stbName = strdup((char*)tNameGetTableName(&name)); // strdup(stbFullName);
|
||||
|
||||
// set tag content
|
||||
taosArrayClear(tagArray);
|
||||
STagVal tagVal = {
|
||||
.cid = taosArrayGetSize(pDataBlock->pDataBlock) + 1,
|
||||
.type = TSDB_DATA_TYPE_UBIGINT,
|
||||
.i64 = (int64_t)pDataBlock->info.id.groupId,
|
||||
};
|
||||
taosArrayPush(tagArray, &tagVal);
|
||||
createTbReq.ctb.tagNum = taosArrayGetSize(tagArray);
|
||||
|
||||
STag* pTag = NULL;
|
||||
tTagNew(tagArray, 1, false, &pTag);
|
||||
if (pTag == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosArrayDestroy(tagArray);
|
||||
taosArrayDestroyP(schemaReqs, taosMemoryFree);
|
||||
taosArrayDestroy(schemaReqSz);
|
||||
return NULL;
|
||||
}
|
||||
createTbReq.ctb.pTag = (uint8_t*)pTag;
|
||||
|
||||
// set tag name
|
||||
SArray* tagName = taosArrayInit(1, TSDB_COL_NAME_LEN);
|
||||
char tagNameStr[TSDB_COL_NAME_LEN] = {0};
|
||||
strcpy(tagNameStr, "group_id");
|
||||
taosArrayPush(tagName, tagNameStr);
|
||||
createTbReq.ctb.tagName = tagName;
|
||||
|
||||
// set table name
|
||||
if (pDataBlock->info.parTbName[0]) {
|
||||
createTbReq.name = strdup(pDataBlock->info.parTbName);
|
||||
} else {
|
||||
createTbReq.name = buildCtbNameByGroupId(stbFullName, pDataBlock->info.id.groupId);
|
||||
}
|
||||
|
||||
// save schema len
|
||||
int32_t code;
|
||||
int32_t schemaLen;
|
||||
tEncodeSize(tEncodeSVCreateTbReq, &createTbReq, schemaLen, code);
|
||||
if (code < 0) {
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
taosArrayDestroy(tagArray);
|
||||
taosArrayDestroyP(schemaReqs, taosMemoryFree);
|
||||
taosArrayDestroy(schemaReqSz);
|
||||
return NULL;
|
||||
}
|
||||
taosArrayPush(schemaReqSz, &schemaLen);
|
||||
|
||||
// save schema str
|
||||
void* schemaStr = taosMemoryMalloc(schemaLen);
|
||||
if (schemaStr == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
taosArrayDestroy(tagArray);
|
||||
taosArrayDestroyP(schemaReqs, taosMemoryFree);
|
||||
taosArrayDestroy(schemaReqSz);
|
||||
return NULL;
|
||||
}
|
||||
taosArrayPush(schemaReqs, &schemaStr);
|
||||
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, schemaStr, schemaLen);
|
||||
code = tEncodeSVCreateTbReq(&encoder, &createTbReq);
|
||||
if (code < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
taosArrayDestroy(tagArray);
|
||||
taosArrayDestroyP(schemaReqs, taosMemoryFree);
|
||||
taosArrayDestroy(schemaReqSz);
|
||||
tEncoderClear(&encoder);
|
||||
return NULL;
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
}
|
||||
}
|
||||
taosArrayDestroy(tagArray);
|
||||
|
||||
// cal size
|
||||
int32_t cap = sizeof(SSubmitReq);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
||||
if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
|
||||
continue;
|
||||
}
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
/*int32_t rowSize = pDataBlock->info.rowSize;*/
|
||||
int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema);
|
||||
|
||||
int32_t schemaLen = 0;
|
||||
if (createTb) {
|
||||
schemaLen = *(int32_t*)taosArrayGet(schemaReqSz, i);
|
||||
}
|
||||
cap += sizeof(SSubmitBlk) + schemaLen + rows * maxLen;
|
||||
}
|
||||
|
||||
// assign data
|
||||
ret = rpcMallocCont(cap);
|
||||
ret->header.vgId = pVnode->config.vgId;
|
||||
ret->length = sizeof(SSubmitReq);
|
||||
ret->numOfBlocks = htonl(sz);
|
||||
|
||||
SSubmitBlk* blkHead = POINTER_SHIFT(ret, sizeof(SSubmitReq));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
||||
if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
|
||||
pDeleteReq->suid = suid;
|
||||
pDeleteReq->deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq));
|
||||
tqBuildDeleteReq(pVnode, stbFullName, pDataBlock, pDeleteReq);
|
||||
continue;
|
||||
}
|
||||
|
||||
blkHead->numOfRows = htonl(pDataBlock->info.rows);
|
||||
blkHead->sversion = htonl(pTSchema->version);
|
||||
blkHead->suid = htobe64(suid);
|
||||
// uid is assigned by vnode
|
||||
blkHead->uid = 0;
|
||||
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
|
||||
int32_t dataLen = 0;
|
||||
int32_t schemaLen = 0;
|
||||
void* blkSchema = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk));
|
||||
if (createTb) {
|
||||
schemaLen = *(int32_t*)taosArrayGet(schemaReqSz, i);
|
||||
void* schemaStr = taosArrayGetP(schemaReqs, i);
|
||||
memcpy(blkSchema, schemaStr, schemaLen);
|
||||
}
|
||||
blkHead->schemaLen = htonl(schemaLen);
|
||||
|
||||
STSRow* rowData = POINTER_SHIFT(blkSchema, schemaLen);
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
SRowBuilder rb = {0};
|
||||
tdSRowInit(&rb, pTSchema->version);
|
||||
tdSRowSetTpInfo(&rb, pTSchema->numOfCols, pTSchema->flen);
|
||||
tdSRowResetBuf(&rb, rowData);
|
||||
|
||||
for (int32_t k = 0; k < pTSchema->numOfCols; k++) {
|
||||
const STColumn* pColumn = &pTSchema->columns[k];
|
||||
SColumnInfoData* pColData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
if (colDataIsNull_s(pColData, j)) {
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NULL, NULL, false, pColumn->offset, k);
|
||||
} else {
|
||||
void* data = colDataGetData(pColData, j);
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, pColumn->offset, k);
|
||||
}
|
||||
}
|
||||
tdSRowEnd(&rb);
|
||||
int32_t rowLen = TD_ROW_LEN(rowData);
|
||||
rowData = POINTER_SHIFT(rowData, rowLen);
|
||||
dataLen += rowLen;
|
||||
}
|
||||
blkHead->dataLen = htonl(dataLen);
|
||||
|
||||
ret->length += sizeof(SSubmitBlk) + schemaLen + dataLen;
|
||||
blkHead = POINTER_SHIFT(blkHead, sizeof(SSubmitBlk) + schemaLen + dataLen);
|
||||
}
|
||||
|
||||
ret->length = htonl(ret->length);
|
||||
|
||||
taosArrayDestroyP(schemaReqs, taosMemoryFree);
|
||||
taosArrayDestroy(schemaReqSz);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pTSchema,
|
||||
SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName,
|
||||
SBatchDeleteReq* pDeleteReq, void** ppData, int32_t* pLen) {
|
||||
void* pBuf = NULL;
|
||||
int32_t len = 0;
|
||||
SSubmitReq2* pReq = NULL;
|
||||
SArray* tagArray = NULL;
|
||||
SArray* createTbArray = NULL;
|
||||
SArray* pVals = NULL;
|
||||
|
||||
int32_t sz = taosArrayGetSize(pBlocks);
|
||||
|
||||
if (!(tagArray = taosArrayInit(1, sizeof(STagVal)))) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(createTbArray = taosArrayInit(sz, POINTER_BYTES))) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(pReq = taosMemoryCalloc(1, sizeof(SSubmitReq2)))) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(pReq->aSubmitTbData = taosArrayInit(1, sizeof(SSubmitTbData)))) {
|
||||
goto _end;
|
||||
}
|
||||
|
||||
// create table req
|
||||
if (createTb) {
|
||||
for (int32_t i = 0; i < sz; ++i) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
||||
SVCreateTbReq* pCreateTbReq = NULL;
|
||||
if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
|
||||
taosArrayPush(createTbArray, &pCreateTbReq);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateStbReq)))) {
|
||||
goto _end;
|
||||
};
|
||||
|
||||
// don't move to the end of loop as to destroy in the end of func when error occur
|
||||
taosArrayPush(createTbArray, &pCreateTbReq);
|
||||
|
||||
// set const
|
||||
pCreateTbReq->flags = 0;
|
||||
pCreateTbReq->type = TSDB_CHILD_TABLE;
|
||||
pCreateTbReq->ctb.suid = suid;
|
||||
|
||||
// set super table name
|
||||
SName name = {0};
|
||||
tNameFromString(&name, stbFullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
pCreateTbReq->ctb.stbName = strdup((char*)tNameGetTableName(&name)); // strdup(stbFullName);
|
||||
|
||||
// set tag content
|
||||
taosArrayClear(tagArray);
|
||||
STagVal tagVal = {
|
||||
.cid = taosArrayGetSize(pDataBlock->pDataBlock) + 1,
|
||||
.type = TSDB_DATA_TYPE_UBIGINT,
|
||||
.i64 = (int64_t)pDataBlock->info.id.groupId,
|
||||
};
|
||||
taosArrayPush(tagArray, &tagVal);
|
||||
pCreateTbReq->ctb.tagNum = taosArrayGetSize(tagArray);
|
||||
|
||||
STag* pTag = NULL;
|
||||
tTagNew(tagArray, 1, false, &pTag);
|
||||
if (pTag == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _end;
|
||||
}
|
||||
pCreateTbReq->ctb.pTag = (uint8_t*)pTag;
|
||||
|
||||
// set tag name
|
||||
SArray* tagName = taosArrayInit(1, TSDB_COL_NAME_LEN);
|
||||
char tagNameStr[TSDB_COL_NAME_LEN] = {0};
|
||||
strcpy(tagNameStr, "group_id");
|
||||
taosArrayPush(tagName, tagNameStr);
|
||||
pCreateTbReq->ctb.tagName = tagName;
|
||||
|
||||
// set table name
|
||||
if (pDataBlock->info.parTbName[0]) {
|
||||
pCreateTbReq->name = strdup(pDataBlock->info.parTbName);
|
||||
} else {
|
||||
pCreateTbReq->name = buildCtbNameByGroupId(stbFullName, pDataBlock->info.id.groupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SSubmitTbData req
|
||||
for (int32_t i = 0; i < sz; ++i) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
||||
if (pDataBlock->info.type == STREAM_DELETE_RESULT) {
|
||||
pDeleteReq->suid = suid;
|
||||
pDeleteReq->deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq));
|
||||
tqBuildDeleteReq(pVnode, stbFullName, pDataBlock, pDeleteReq);
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
|
||||
SSubmitTbData* pTbData = (SSubmitTbData*)taosMemoryCalloc(1, sizeof(SSubmitTbData));
|
||||
if (!pTbData) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _end;
|
||||
}
|
||||
|
||||
if (!(pTbData->aRowP = taosArrayInit(rows, sizeof(SRow*)))) {
|
||||
taosMemoryFree(pTbData);
|
||||
goto _end;
|
||||
}
|
||||
pTbData->suid = suid;
|
||||
pTbData->uid = 0; // uid is assigned by vnode
|
||||
pTbData->sver = pTSchema->version;
|
||||
|
||||
if (createTb) {
|
||||
pTbData->pCreateTbReq = taosArrayGetP(createTbArray, i);
|
||||
if (pTbData->pCreateTbReq) pTbData->flags = SUBMIT_REQ_AUTO_CREATE_TABLE;
|
||||
}
|
||||
|
||||
if (!pVals && !(pVals = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal)))) {
|
||||
taosArrayDestroy(pTbData->aRowP);
|
||||
taosMemoryFree(pTbData);
|
||||
goto _end;
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < rows; j++) {
|
||||
taosArrayClear(pVals);
|
||||
for (int32_t k = 0; k < pTSchema->numOfCols; k++) {
|
||||
const STColumn* pCol = &pTSchema->columns[k];
|
||||
SColumnInfoData* pColData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
if (colDataIsNull_s(pColData, j)) {
|
||||
SColVal cv = COL_VAL_NULL(pCol->colId, pCol->type);
|
||||
taosArrayPush(pVals, &cv);
|
||||
} else {
|
||||
void* data = colDataGetData(pColData, j);
|
||||
if (IS_STR_DATA_TYPE(pCol->type)) {
|
||||
SValue sv = (SValue){.nData = varDataLen(data), .pData = varDataVal(data)}; // address copy, no value
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
||||
taosArrayPush(pVals, &cv);
|
||||
} else {
|
||||
SValue sv;
|
||||
memcpy(&sv.val, data, tDataTypes[pCol->type].bytes);
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
||||
taosArrayPush(pVals, &cv);
|
||||
}
|
||||
}
|
||||
}
|
||||
SRow* pRow = NULL;
|
||||
if ((terrno = tRowBuild(pVals, (STSchema*)pTSchema, &pRow)) < 0) {
|
||||
tDestroySSubmitTbData(pTbData, TSDB_MSG_FLG_ENCODE);
|
||||
goto _end;
|
||||
}
|
||||
ASSERT(pRow);
|
||||
taosArrayPush(pTbData->aRowP, &pRow);
|
||||
}
|
||||
|
||||
taosArrayPush(pReq->aSubmitTbData, pTbData);
|
||||
}
|
||||
|
||||
// encode
|
||||
tEncodeSize(tEncodeSSubmitReq2, pReq, len, terrno);
|
||||
if (TSDB_CODE_SUCCESS == terrno) {
|
||||
SEncoder encoder;
|
||||
len += sizeof(SMsgHead);
|
||||
pBuf = rpcMallocCont(len);
|
||||
if (NULL == pBuf) {
|
||||
goto _end;
|
||||
}
|
||||
((SMsgHead*)pBuf)->vgId = htonl(TD_VID(pVnode));
|
||||
((SMsgHead*)pBuf)->contLen = htonl(len);
|
||||
tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len - sizeof(SMsgHead));
|
||||
if (tEncodeSSubmitReq2(&encoder, pReq) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tqError("failed to encode submit req since %s", terrstr());
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
}
|
||||
_end:
|
||||
taosArrayDestroy(tagArray);
|
||||
taosArrayDestroy(pVals);
|
||||
tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
|
||||
|
||||
if (terrno != 0) {
|
||||
rpcFreeCont(pBuf);
|
||||
taosArrayDestroy(pDeleteReq->deleteReqs);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (ppData) *ppData = pBuf;
|
||||
if (pLen) *pLen = len;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
|
||||
const SArray* pBlocks = (const SArray*)data;
|
||||
|
@ -984,56 +563,3 @@ _end:
|
|||
taosArrayDestroy(pVals);
|
||||
// TODO: change
|
||||
}
|
||||
|
||||
#if 0
|
||||
void tqSinkToTableMerge(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
|
||||
const SArray* pRes = (const SArray*)data;
|
||||
SVnode* pVnode = (SVnode*)vnode;
|
||||
SBatchDeleteReq deleteReq = {0};
|
||||
|
||||
tqDebug("vgId:%d, task %d write into table, block num: %d", TD_VID(pVnode), pTask->taskId, (int32_t)pRes->size);
|
||||
|
||||
deleteReq.deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq));
|
||||
SSubmitReq* submitReq = tqBlockToSubmit(pVnode, pRes, pTask->tbSink.pTSchema, pTask->tbSink.pSchemaWrapper, true,
|
||||
pTask->tbSink.stbUid, pTask->tbSink.stbFullName, &deleteReq);
|
||||
|
||||
tqDebug("vgId:%d, task %d convert blocks over, put into write-queue", TD_VID(pVnode), pTask->taskId);
|
||||
|
||||
if (taosArrayGetSize(deleteReq.deleteReqs) != 0) {
|
||||
int32_t code;
|
||||
int32_t len;
|
||||
tEncodeSize(tEncodeSBatchDeleteReq, &deleteReq, len, code);
|
||||
SEncoder encoder;
|
||||
void* serializedDeleteReq = rpcMallocCont(len + sizeof(SMsgHead));
|
||||
void* abuf = POINTER_SHIFT(serializedDeleteReq, sizeof(SMsgHead));
|
||||
tEncoderInit(&encoder, abuf, len);
|
||||
tEncodeSBatchDeleteReq(&encoder, &deleteReq);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
((SMsgHead*)serializedDeleteReq)->vgId = pVnode->config.vgId;
|
||||
|
||||
SRpcMsg msg = {
|
||||
.msgType = TDMT_VND_BATCH_DEL,
|
||||
.pCont = serializedDeleteReq,
|
||||
.contLen = len + sizeof(SMsgHead),
|
||||
};
|
||||
if (tmsgPutToQueue(&pVnode->msgCb, WRITE_QUEUE, &msg) != 0) {
|
||||
rpcFreeCont(serializedDeleteReq);
|
||||
tqDebug("failed to put into write-queue since %s", terrstr());
|
||||
}
|
||||
}
|
||||
taosArrayDestroy(deleteReq.deleteReqs);
|
||||
|
||||
/*tPrintFixedSchemaSubmitReq(pReq, pTask->tbSink.pTSchema);*/
|
||||
// build write msg
|
||||
SRpcMsg msg = {
|
||||
.msgType = TDMT_VND_SUBMIT,
|
||||
.pCont = submitReq,
|
||||
.contLen = ntohl(submitReq->length),
|
||||
};
|
||||
|
||||
if (tmsgPutToQueue(&pVnode->msgCb, WRITE_QUEUE, &msg) != 0) {
|
||||
tqDebug("failed to put into write-queue since %s", terrstr());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -173,6 +173,8 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) {
|
|||
if (code) goto _err;
|
||||
}
|
||||
|
||||
int vgId = TD_VID(pWriter->pTq->pVnode);
|
||||
|
||||
taosMemoryFree(pWriter);
|
||||
*ppWriter = NULL;
|
||||
|
||||
|
@ -184,7 +186,7 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) {
|
|||
return code;
|
||||
|
||||
_err:
|
||||
tqError("vgId:%d, tq snapshot writer close failed since %s", TD_VID(pWriter->pTq->pVnode), tstrerror(code));
|
||||
tqError("vgId:%d, tq snapshot writer close failed since %s", vgId, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -109,6 +109,8 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, void* pTableIdList,
|
|||
|
||||
p->type = type;
|
||||
p->pVnode = pVnode;
|
||||
p->pTsdb = p->pVnode->pTsdb;
|
||||
p->verRange = (SVersionRange){.minVer = 0, .maxVer = UINT64_MAX};
|
||||
p->numOfCols = numOfCols;
|
||||
p->suid = suid;
|
||||
|
||||
|
@ -145,6 +147,7 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, void* pTableIdList,
|
|||
}
|
||||
|
||||
p->idstr = taosMemoryStrDup(idstr);
|
||||
taosThreadMutexInit(&p->readerMutex, NULL);
|
||||
|
||||
*pReader = p;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -164,7 +167,9 @@ void* tsdbCacherowsReaderClose(void* pReader) {
|
|||
|
||||
destroyLastBlockLoadInfo(p->pLoadInfo);
|
||||
|
||||
taosMemoryFree((void*) p->idstr);
|
||||
taosMemoryFree((void*)p->idstr);
|
||||
taosThreadMutexDestroy(&p->readerMutex);
|
||||
|
||||
taosMemoryFree(pReader);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -199,6 +204,19 @@ static void freeItem(void* pItem) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t tsdbCacheQueryReseek(void* pQHandle) {
|
||||
int32_t code = 0;
|
||||
SCacheRowsReader* pReader = pQHandle;
|
||||
|
||||
taosThreadMutexLock(&pReader->readerMutex);
|
||||
|
||||
// pause current reader's state if not paused, save ts & version for resuming
|
||||
// just wait for the big all tables' snapshot untaking for now
|
||||
|
||||
taosThreadMutexUnlock(&pReader->readerMutex);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32_t* slotIds, SArray* pTableUidList) {
|
||||
if (pReader == NULL || pResBlock == NULL) {
|
||||
return TSDB_CODE_INVALID_PARA;
|
||||
|
@ -241,7 +259,8 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
|||
taosArrayPush(pLastCols, &p);
|
||||
}
|
||||
|
||||
tsdbTakeReadSnap(pr->pVnode->pTsdb, &pr->pReadSnap, "cache-l");
|
||||
taosThreadMutexLock(&pr->readerMutex);
|
||||
tsdbTakeReadSnap((STsdbReader*)pr, tsdbCacheQueryReseek, &pr->pReadSnap);
|
||||
pr->pDataFReader = NULL;
|
||||
pr->pDataFReaderLast = NULL;
|
||||
|
||||
|
@ -355,8 +374,9 @@ _end:
|
|||
tsdbDataFReaderClose(&pr->pDataFReaderLast);
|
||||
tsdbDataFReaderClose(&pr->pDataFReader);
|
||||
|
||||
tsdbUntakeReadSnap(pr->pVnode->pTsdb, pr->pReadSnap, "cache-l");
|
||||
resetLastBlockLoadInfo(pr->pLoadInfo);
|
||||
tsdbUntakeReadSnap((STsdbReader*)pr, pr->pReadSnap);
|
||||
taosThreadMutexUnlock(&pr->readerMutex);
|
||||
|
||||
for (int32_t j = 0; j < pr->numOfCols; ++j) {
|
||||
taosMemoryFree(pRes[j]);
|
||||
|
|
|
@ -175,7 +175,7 @@ int32_t tsdbCommit(STsdb *pTsdb, SCommitInfo *pInfo) {
|
|||
pTsdb->imem = NULL;
|
||||
taosThreadRwlockUnlock(&pTsdb->rwLock);
|
||||
|
||||
tsdbUnrefMemTable(pMemTable);
|
||||
tsdbUnrefMemTable(pMemTable, NULL);
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
|
@ -1664,7 +1664,7 @@ int32_t tsdbFinishCommit(STsdb *pTsdb) {
|
|||
// unlock
|
||||
taosThreadRwlockUnlock(&pTsdb->rwLock);
|
||||
if (pMemTable) {
|
||||
tsdbUnrefMemTable(pMemTable);
|
||||
tsdbUnrefMemTable(pMemTable, NULL);
|
||||
}
|
||||
|
||||
_exit:
|
||||
|
|
|
@ -19,9 +19,13 @@
|
|||
#define SL_MAX_LEVEL 5
|
||||
|
||||
// sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l) * 2
|
||||
#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + ((l) << 4))
|
||||
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
|
||||
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
|
||||
#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + ((l) << 4))
|
||||
#define SL_NODE_FORWARD(n, l) ((n)->forwards[l])
|
||||
#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)])
|
||||
#define SL_GET_NODE_FORWARD(n, l) ((SMemSkipListNode *)atomic_load_64((int64_t *)&SL_NODE_FORWARD(n, l)))
|
||||
#define SL_GET_NODE_BACKWARD(n, l) ((SMemSkipListNode *)atomic_load_64((int64_t *)&SL_NODE_BACKWARD(n, l)))
|
||||
#define SL_SET_NODE_FORWARD(n, l, p) atomic_store_64((int64_t *)&SL_NODE_FORWARD(n, l), (int64_t)(p))
|
||||
#define SL_SET_NODE_BACKWARD(n, l, p) atomic_store_64((int64_t *)&SL_NODE_BACKWARD(n, l), (int64_t)(p))
|
||||
|
||||
#define SL_MOVE_BACKWARD 0x1
|
||||
#define SL_MOVE_FROM_POS 0x2
|
||||
|
@ -46,6 +50,8 @@ int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable) {
|
|||
pMemTable->pTsdb = pTsdb;
|
||||
pMemTable->pPool = pTsdb->pVnode->inUse;
|
||||
pMemTable->nRef = 1;
|
||||
pMemTable->minVer = VERSION_MAX;
|
||||
pMemTable->maxVer = VERSION_MIN;
|
||||
pMemTable->minKey = TSKEY_MAX;
|
||||
pMemTable->maxKey = TSKEY_MIN;
|
||||
pMemTable->nRow = 0;
|
||||
|
@ -58,6 +64,8 @@ int32_t tsdbMemTableCreate(STsdb *pTsdb, SMemTable **ppMemTable) {
|
|||
taosMemoryFree(pMemTable);
|
||||
goto _err;
|
||||
}
|
||||
pMemTable->qList.pNext = &pMemTable->qList;
|
||||
pMemTable->qList.ppNext = &pMemTable->qList.pNext;
|
||||
vnodeBufPoolRef(pMemTable->pPool);
|
||||
|
||||
*ppMemTable = pMemTable;
|
||||
|
@ -142,6 +150,10 @@ int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitTbData *pSubmi
|
|||
}
|
||||
if (code) goto _err;
|
||||
|
||||
// update
|
||||
pMemTable->minVer = TMIN(pMemTable->minVer, version);
|
||||
pMemTable->maxVer = TMAX(pMemTable->maxVer, version);
|
||||
|
||||
return code;
|
||||
|
||||
_err:
|
||||
|
@ -193,6 +205,8 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid
|
|||
}
|
||||
|
||||
pMemTable->nDel++;
|
||||
pMemTable->minVer = TMIN(pMemTable->minVer, version);
|
||||
pMemTable->maxVer = TMIN(pMemTable->maxVer, version);
|
||||
|
||||
if (TSDB_CACHE_LAST_ROW(pMemTable->pTsdb->pVnode->config) && tsdbKeyCmprFn(&lastKey, &pTbData->maxKey) >= 0) {
|
||||
tsdbCacheDeleteLastrow(pTsdb->lruCache, pTbData->uid, eKey);
|
||||
|
@ -233,7 +247,6 @@ void *tsdbTbDataIterDestroy(STbDataIter *pIter) {
|
|||
if (pIter) {
|
||||
taosMemoryFree(pIter);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -250,18 +263,18 @@ void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDa
|
|||
if (pFrom == NULL) {
|
||||
// create from head or tail
|
||||
if (backward) {
|
||||
pIter->pNode = SL_NODE_BACKWARD(pTbData->sl.pTail, 0);
|
||||
pIter->pNode = SL_GET_NODE_BACKWARD(pTbData->sl.pTail, 0);
|
||||
} else {
|
||||
pIter->pNode = SL_NODE_FORWARD(pTbData->sl.pHead, 0);
|
||||
pIter->pNode = SL_GET_NODE_FORWARD(pTbData->sl.pHead, 0);
|
||||
}
|
||||
} else {
|
||||
// create from a key
|
||||
if (backward) {
|
||||
tbDataMovePosTo(pTbData, pos, pFrom, SL_MOVE_BACKWARD);
|
||||
pIter->pNode = SL_NODE_BACKWARD(pos[0], 0);
|
||||
pIter->pNode = SL_GET_NODE_BACKWARD(pos[0], 0);
|
||||
} else {
|
||||
tbDataMovePosTo(pTbData, pos, pFrom, 0);
|
||||
pIter->pNode = SL_NODE_FORWARD(pos[0], 0);
|
||||
pIter->pNode = SL_GET_NODE_FORWARD(pos[0], 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -275,7 +288,7 @@ bool tsdbTbDataIterNext(STbDataIter *pIter) {
|
|||
return false;
|
||||
}
|
||||
|
||||
pIter->pNode = SL_NODE_BACKWARD(pIter->pNode, 0);
|
||||
pIter->pNode = SL_GET_NODE_BACKWARD(pIter->pNode, 0);
|
||||
if (pIter->pNode == pIter->pTbData->sl.pHead) {
|
||||
return false;
|
||||
}
|
||||
|
@ -286,7 +299,7 @@ bool tsdbTbDataIterNext(STbDataIter *pIter) {
|
|||
return false;
|
||||
}
|
||||
|
||||
pIter->pNode = SL_NODE_FORWARD(pIter->pNode, 0);
|
||||
pIter->pNode = SL_GET_NODE_FORWARD(pIter->pNode, 0);
|
||||
if (pIter->pNode == pIter->pTbData->sl.pTail) {
|
||||
return false;
|
||||
}
|
||||
|
@ -339,7 +352,7 @@ static int32_t tsdbGetOrCreateTbData(SMemTable *pMemTable, tb_uid_t suid, tb_uid
|
|||
int8_t maxLevel = pMemTable->pTsdb->pVnode->config.tsdbCfg.slLevel;
|
||||
|
||||
ASSERT(pPool != NULL);
|
||||
pTbData = vnodeBufPoolMalloc(pPool, sizeof(*pTbData) + SL_NODE_SIZE(maxLevel) * 2);
|
||||
pTbData = vnodeBufPoolMallocAligned(pPool, sizeof(*pTbData) + SL_NODE_SIZE(maxLevel) * 2);
|
||||
if (pTbData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
|
@ -412,7 +425,7 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
|
|||
if (fromPos) px = pos[pTbData->sl.level - 1];
|
||||
|
||||
for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) {
|
||||
pn = SL_NODE_BACKWARD(px, iLevel);
|
||||
pn = SL_GET_NODE_BACKWARD(px, iLevel);
|
||||
while (pn != pTbData->sl.pHead) {
|
||||
if (pn->flag == TSDBROW_ROW_FMT) {
|
||||
tKey.version = pn->version;
|
||||
|
@ -427,7 +440,7 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
|
|||
break;
|
||||
} else {
|
||||
px = pn;
|
||||
pn = SL_NODE_BACKWARD(px, iLevel);
|
||||
pn = SL_GET_NODE_BACKWARD(px, iLevel);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -447,7 +460,7 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
|
|||
if (fromPos) px = pos[pTbData->sl.level - 1];
|
||||
|
||||
for (int8_t iLevel = pTbData->sl.level - 1; iLevel >= 0; iLevel--) {
|
||||
pn = SL_NODE_FORWARD(px, iLevel);
|
||||
pn = SL_GET_NODE_FORWARD(px, iLevel);
|
||||
while (pn != pTbData->sl.pTail) {
|
||||
if (pn->flag == TSDBROW_ROW_FMT) {
|
||||
tKey.version = pn->version;
|
||||
|
@ -462,7 +475,7 @@ static void tbDataMovePosTo(STbData *pTbData, SMemSkipListNode **pos, TSDBKEY *p
|
|||
break;
|
||||
} else {
|
||||
px = pn;
|
||||
pn = SL_NODE_FORWARD(px, iLevel);
|
||||
pn = SL_GET_NODE_FORWARD(px, iLevel);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -488,26 +501,28 @@ static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListN
|
|||
int8_t level;
|
||||
SMemSkipListNode *pNode;
|
||||
SVBufPool *pPool = pMemTable->pTsdb->pVnode->inUse;
|
||||
int64_t nSize;
|
||||
|
||||
ASSERT(pPool != NULL);
|
||||
|
||||
// node
|
||||
// create node
|
||||
level = tsdbMemSkipListRandLevel(&pTbData->sl);
|
||||
pNode = (SMemSkipListNode *)vnodeBufPoolMalloc(pPool, SL_NODE_SIZE(level));
|
||||
nSize = SL_NODE_SIZE(level);
|
||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||
pNode = (SMemSkipListNode *)vnodeBufPoolMallocAligned(pPool, nSize + pRow->pTSRow->len);
|
||||
} else if (pRow->type == TSDBROW_COL_FMT) {
|
||||
pNode = (SMemSkipListNode *)vnodeBufPoolMallocAligned(pPool, nSize);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
if (pNode == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
pNode->level = level;
|
||||
pNode->flag = pRow->type;
|
||||
|
||||
if (pRow->type == TSDBROW_ROW_FMT) {
|
||||
pNode->version = pRow->version;
|
||||
pNode->pData = vnodeBufPoolMalloc(pPool, pRow->pTSRow->len);
|
||||
if (NULL == pNode->pData) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
pNode->pData = (char *)pNode + nSize;
|
||||
memcpy(pNode->pData, pRow->pTSRow, pRow->pTSRow->len);
|
||||
} else if (pRow->type == TSDBROW_COL_FMT) {
|
||||
pNode->iRow = pRow->iRow;
|
||||
|
@ -516,40 +531,38 @@ static int32_t tbDataDoPut(SMemTable *pMemTable, STbData *pTbData, SMemSkipListN
|
|||
ASSERT(0);
|
||||
}
|
||||
|
||||
for (int8_t iLevel = level - 1; iLevel >= 0; iLevel--) {
|
||||
SMemSkipListNode *pn = pos[iLevel];
|
||||
SMemSkipListNode *px;
|
||||
|
||||
if (forward) {
|
||||
px = SL_NODE_FORWARD(pn, iLevel);
|
||||
|
||||
SL_NODE_BACKWARD(pNode, iLevel) = pn;
|
||||
SL_NODE_FORWARD(pNode, iLevel) = px;
|
||||
} else {
|
||||
px = SL_NODE_BACKWARD(pn, iLevel);
|
||||
|
||||
SL_NODE_BACKWARD(pNode, iLevel) = px;
|
||||
SL_NODE_FORWARD(pNode, iLevel) = pn;
|
||||
// set node
|
||||
if (forward) {
|
||||
for (int8_t iLevel = 0; iLevel < level; iLevel++) {
|
||||
SL_NODE_FORWARD(pNode, iLevel) = SL_NODE_FORWARD(pos[iLevel], iLevel);
|
||||
SL_NODE_BACKWARD(pNode, iLevel) = pos[iLevel];
|
||||
}
|
||||
} else {
|
||||
for (int8_t iLevel = 0; iLevel < level; iLevel++) {
|
||||
SL_NODE_FORWARD(pNode, iLevel) = pos[iLevel];
|
||||
SL_NODE_BACKWARD(pNode, iLevel) = SL_NODE_BACKWARD(pos[iLevel], iLevel);
|
||||
}
|
||||
}
|
||||
|
||||
for (int8_t iLevel = level - 1; iLevel >= 0; iLevel--) {
|
||||
SMemSkipListNode *pn = pos[iLevel];
|
||||
SMemSkipListNode *px;
|
||||
// set forward and backward
|
||||
if (forward) {
|
||||
for (int8_t iLevel = level - 1; iLevel >= 0; iLevel--) {
|
||||
SMemSkipListNode *pNext = pos[iLevel]->forwards[iLevel];
|
||||
|
||||
if (forward) {
|
||||
px = SL_NODE_FORWARD(pn, iLevel);
|
||||
SL_SET_NODE_FORWARD(pos[iLevel], iLevel, pNode);
|
||||
SL_SET_NODE_BACKWARD(pNext, iLevel, pNode);
|
||||
|
||||
SL_NODE_FORWARD(pn, iLevel) = pNode;
|
||||
SL_NODE_BACKWARD(px, iLevel) = pNode;
|
||||
} else {
|
||||
px = SL_NODE_BACKWARD(pn, iLevel);
|
||||
|
||||
SL_NODE_FORWARD(px, iLevel) = pNode;
|
||||
SL_NODE_BACKWARD(pn, iLevel) = pNode;
|
||||
pos[iLevel] = pNode;
|
||||
}
|
||||
} else {
|
||||
for (int8_t iLevel = level - 1; iLevel >= 0; iLevel--) {
|
||||
SMemSkipListNode *pPrev = pos[iLevel]->forwards[pos[iLevel]->level + iLevel];
|
||||
|
||||
pos[iLevel] = pNode;
|
||||
SL_SET_NODE_FORWARD(pPrev, iLevel, pNode);
|
||||
SL_SET_NODE_BACKWARD(pos[iLevel], iLevel, pNode);
|
||||
|
||||
pos[iLevel] = pNode;
|
||||
}
|
||||
}
|
||||
|
||||
pTbData->sl.size++;
|
||||
|
@ -736,16 +749,45 @@ _exit:
|
|||
|
||||
int32_t tsdbGetNRowsInTbData(STbData *pTbData) { return pTbData->sl.size; }
|
||||
|
||||
void tsdbRefMemTable(SMemTable *pMemTable) {
|
||||
int32_t tsdbRefMemTable(SMemTable *pMemTable, void *pQHandle, _tsdb_reseek_func_t reseek, SQueryNode **ppNode) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t nRef = atomic_fetch_add_32(&pMemTable->nRef, 1);
|
||||
ASSERT(nRef > 0);
|
||||
/*
|
||||
// register handle (todo: take concurrency in consideration)
|
||||
*ppNode = taosMemoryMalloc(sizeof(SQueryNode));
|
||||
if (*ppNode == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exit;
|
||||
}
|
||||
(*ppNode)->pQHandle = pQHandle;
|
||||
(*ppNode)->reseek = reseek;
|
||||
(*ppNode)->pNext = pMemTable->qList.pNext;
|
||||
(*ppNode)->ppNext = &pMemTable->qList.pNext;
|
||||
pMemTable->qList.pNext->ppNext = &(*ppNode)->pNext;
|
||||
pMemTable->qList.pNext = *ppNode;
|
||||
*/
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
void tsdbUnrefMemTable(SMemTable *pMemTable) {
|
||||
int32_t tsdbUnrefMemTable(SMemTable *pMemTable, SQueryNode *pNode) {
|
||||
int32_t code = 0;
|
||||
/*
|
||||
// unregister handle (todo: take concurrency in consideration)
|
||||
if (pNode) {
|
||||
pNode->pNext->ppNext = pNode->ppNext;
|
||||
*pNode->ppNext = pNode->pNext;
|
||||
taosMemoryFree(pNode);
|
||||
}
|
||||
*/
|
||||
int32_t nRef = atomic_sub_fetch_32(&pMemTable->nRef, 1);
|
||||
if (nRef == 0) {
|
||||
tsdbMemTableDestroy(pMemTable);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tbDataPCmprFn(const void *p1, const void *p2) {
|
||||
|
@ -785,3 +827,29 @@ SArray *tsdbMemTableGetTbDataArray(SMemTable *pMemTable) {
|
|||
_exit:
|
||||
return aTbDataP;
|
||||
}
|
||||
|
||||
int32_t tsdbRecycleMemTable(SMemTable *pMemTable) {
|
||||
int32_t code = 0;
|
||||
|
||||
SQueryNode *pNode = pMemTable->qList.pNext;
|
||||
while (1) {
|
||||
ASSERT(pNode != &pMemTable->qList);
|
||||
SQueryNode *pNextNode = pNode->pNext;
|
||||
|
||||
if (pNextNode == &pMemTable->qList) {
|
||||
code = (*pNode->reseek)(pNode->pQHandle);
|
||||
if (code) goto _exit;
|
||||
break;
|
||||
} else {
|
||||
code = (*pNode->reseek)(pNode->pQHandle);
|
||||
if (code) goto _exit;
|
||||
pNode = pMemTable->qList.pNext;
|
||||
ASSERT(pNode == pNextNode);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Take care here, pMemTable is destroyed
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -156,6 +156,9 @@ typedef struct SBlockInfoBuf {
|
|||
|
||||
struct STsdbReader {
|
||||
STsdb* pTsdb;
|
||||
SVersionRange verRange;
|
||||
TdThreadMutex readerMutex;
|
||||
bool suspended;
|
||||
uint64_t suid;
|
||||
int16_t order;
|
||||
bool freeBlock;
|
||||
|
@ -173,10 +176,10 @@ struct STsdbReader {
|
|||
SDataFReader* pFileReader; // the file reader
|
||||
SDelFReader* pDelFReader; // the del file reader
|
||||
SArray* pDelIdx; // del file block index;
|
||||
SVersionRange verRange;
|
||||
SBlockInfoBuf blockInfoBuf;
|
||||
int32_t step;
|
||||
STsdbReader* innerReader[2];
|
||||
// SVersionRange verRange;
|
||||
SBlockInfoBuf blockInfoBuf;
|
||||
int32_t step;
|
||||
STsdbReader* innerReader[2];
|
||||
};
|
||||
|
||||
static SFileDataBlockInfo* getCurrentBlockInfo(SDataBlockIter* pBlockIter);
|
||||
|
@ -399,9 +402,7 @@ static void destroyAllBlockScanInfo(SHashObj* pTableMap) {
|
|||
taosHashCleanup(pTableMap);
|
||||
}
|
||||
|
||||
static bool isEmptyQueryTimeWindow(STimeWindow* pWindow) {
|
||||
return pWindow->skey > pWindow->ekey;
|
||||
}
|
||||
static bool isEmptyQueryTimeWindow(STimeWindow* pWindow) { return pWindow->skey > pWindow->ekey; }
|
||||
|
||||
// Update the query time window according to the data time to live(TTL) information, in order to avoid to return
|
||||
// the expired data to client, even it is queried already.
|
||||
|
@ -635,6 +636,8 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd
|
|||
|
||||
setColumnIdSlotList(&pReader->suppInfo, pCond->colList, pCond->pSlotList, pCond->numOfCols);
|
||||
|
||||
taosThreadMutexInit(&pReader->readerMutex, NULL);
|
||||
|
||||
*ppReader = pReader;
|
||||
return code;
|
||||
|
||||
|
@ -729,12 +732,25 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
|
|||
|
||||
sizeInDisk += pScanInfo->mapData.nData;
|
||||
|
||||
int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1;
|
||||
STimeWindow w = pReader->window;
|
||||
if (ASCENDING_TRAVERSE(pReader->order)) {
|
||||
w.skey = pScanInfo->lastKey + step;
|
||||
} else {
|
||||
w.ekey = pScanInfo->lastKey + step;
|
||||
}
|
||||
|
||||
if (isEmptyQueryTimeWindow(&w)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SDataBlk block = {0};
|
||||
for (int32_t j = 0; j < pScanInfo->mapData.nItem; ++j) {
|
||||
tGetDataBlk(pScanInfo->mapData.pData + pScanInfo->mapData.aOffset[j], &block);
|
||||
|
||||
// 1. time range check
|
||||
if (block.minKey.ts > pReader->window.ekey || block.maxKey.ts < pReader->window.skey) {
|
||||
// if (block.minKey.ts > pReader->window.ekey || block.maxKey.ts < pReader->window.skey) {
|
||||
if (block.minKey.ts > w.ekey || block.maxKey.ts < w.skey) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -915,7 +931,7 @@ static void copyNumericCols(const SColData* pData, SFileBlockDumpInfo* pDumpInfo
|
|||
int32_t step = asc ? 1 : -1;
|
||||
|
||||
// make sure it is aligned to 8bit, the allocated memory address is aligned to 256bit
|
||||
// ASSERT((((uint64_t)pColData->pData) & (0x8 - 1)) == 0);
|
||||
// ASSERT((((uint64_t)pColData->pData) & (0x8 - 1)) == 0);
|
||||
|
||||
// 1. copy data in a batch model
|
||||
memcpy(pColData->pData, p, dumpedRows * tDataTypes[pData->type].bytes);
|
||||
|
@ -2170,9 +2186,11 @@ static int32_t initMemDataIterator(STableBlockScanInfo* pBlockScanInfo, STsdbRea
|
|||
|
||||
TSDBKEY startKey = {0};
|
||||
if (ASCENDING_TRAVERSE(pReader->order)) {
|
||||
startKey = (TSDBKEY){.ts = pReader->window.skey, .version = pReader->verRange.minVer};
|
||||
// startKey = (TSDBKEY){.ts = pReader->window.skey, .version = pReader->verRange.minVer};
|
||||
startKey = (TSDBKEY){.ts = pBlockScanInfo->lastKey + 1, .version = pReader->verRange.minVer};
|
||||
} else {
|
||||
startKey = (TSDBKEY){.ts = pReader->window.ekey, .version = pReader->verRange.maxVer};
|
||||
// startKey = (TSDBKEY){.ts = pReader->window.ekey, .version = pReader->verRange.maxVer};
|
||||
startKey = (TSDBKEY){.ts = pBlockScanInfo->lastKey - 1, .version = pReader->verRange.maxVer};
|
||||
}
|
||||
|
||||
int32_t backward = (!ASCENDING_TRAVERSE(pReader->order));
|
||||
|
@ -2295,7 +2313,7 @@ static bool hasDataInLastBlock(SLastBlockReader* pLastBlockReader) { return pLas
|
|||
|
||||
bool hasDataInFileBlock(const SBlockData* pBlockData, const SFileBlockDumpInfo* pDumpInfo) {
|
||||
if ((pBlockData->nRow > 0) && (pBlockData->nRow != pDumpInfo->totalRows)) {
|
||||
return false; // this is an invalid result.
|
||||
return false; // this is an invalid result.
|
||||
}
|
||||
return pBlockData->nRow > 0 && (!pDumpInfo->allDumped);
|
||||
}
|
||||
|
@ -2451,7 +2469,8 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
|
|||
while (1) {
|
||||
bool hasBlockData = false;
|
||||
{
|
||||
while (pBlockData->nRow > 0 && pBlockData->uid == pBlockScanInfo->uid) { // find the first qualified row in data block
|
||||
while (pBlockData->nRow > 0 &&
|
||||
pBlockData->uid == pBlockScanInfo->uid) { // find the first qualified row in data block
|
||||
if (isValidFileBlockRow(pBlockData, pDumpInfo, pBlockScanInfo, pReader)) {
|
||||
hasBlockData = true;
|
||||
break;
|
||||
|
@ -2882,9 +2901,16 @@ static int32_t buildBlockFromBufferSequentially(STsdbReader* pReader) {
|
|||
}
|
||||
|
||||
// set the correct start position in case of the first/last file block, according to the query time window
|
||||
void initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter) {
|
||||
SDataBlk* pBlock = getCurrentBlock(pBlockIter);
|
||||
|
||||
static void initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter) {
|
||||
int64_t lastKey = ASCENDING_TRAVERSE(pReader->order) ? INT64_MIN : INT64_MAX;
|
||||
SDataBlk* pBlock = getCurrentBlock(pBlockIter);
|
||||
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
|
||||
if (pBlockInfo) {
|
||||
STableBlockScanInfo* pScanInfo = taosHashGet(pBlockIter->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
||||
if (pScanInfo) {
|
||||
lastKey = pScanInfo->lastKey;
|
||||
}
|
||||
}
|
||||
SReaderStatus* pStatus = &pReader->status;
|
||||
|
||||
SFileBlockDumpInfo* pDumpInfo = &pStatus->fBlockDumpInfo;
|
||||
|
@ -2892,6 +2918,7 @@ void initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter) {
|
|||
pDumpInfo->totalRows = pBlock->nRow;
|
||||
pDumpInfo->allDumped = false;
|
||||
pDumpInfo->rowIndex = ASCENDING_TRAVERSE(pReader->order) ? 0 : pBlock->nRow - 1;
|
||||
pDumpInfo->lastKey = lastKey;
|
||||
}
|
||||
|
||||
static int32_t initForFirstBlockInFile(STsdbReader* pReader, SDataBlockIter* pBlockIter) {
|
||||
|
@ -3096,7 +3123,8 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32
|
|||
return false;
|
||||
} else if (pKey->ts == last->ts) {
|
||||
TSDBKEY* prev = taosArrayGet(pDelList, num - 2);
|
||||
return (prev->version >= pKey->version && prev->version <= pVerRange->maxVer && prev->version >= pVerRange->minVer);
|
||||
return (prev->version >= pKey->version && prev->version <= pVerRange->maxVer &&
|
||||
prev->version >= pVerRange->minVer);
|
||||
}
|
||||
} else {
|
||||
TSDBKEY* pCurrent = taosArrayGet(pDelList, *index);
|
||||
|
@ -3285,7 +3313,7 @@ static int32_t checkForNeighborFileBlock(STsdbReader* pReader, STableBlockScanIn
|
|||
*state = CHECK_FILEBLOCK_QUIT;
|
||||
int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1;
|
||||
|
||||
bool loadNeighbor = true;
|
||||
bool loadNeighbor = true;
|
||||
int32_t code = loadNeighborIfOverlap(pFBlock, pScanInfo, pReader, &loadNeighbor);
|
||||
|
||||
if (loadNeighbor && (code == TSDB_CODE_SUCCESS)) {
|
||||
|
@ -3826,40 +3854,7 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, void* pTableL
|
|||
goto _err;
|
||||
}
|
||||
|
||||
if (numOfTables > 0) {
|
||||
code = tsdbTakeReadSnap(pReader->pTsdb, &pReader->pReadSnap, pReader->idStr);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (pReader->type == TIMEWINDOW_RANGE_CONTAINED) {
|
||||
code = doOpenReaderImpl(pReader);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
STsdbReader* pPrevReader = pReader->innerReader[0];
|
||||
STsdbReader* pNextReader = pReader->innerReader[1];
|
||||
|
||||
// we need only one row
|
||||
pPrevReader->capacity = 1;
|
||||
pPrevReader->status.pTableMap = pReader->status.pTableMap;
|
||||
pPrevReader->pSchema = pReader->pSchema;
|
||||
pPrevReader->pMemSchema = pReader->pMemSchema;
|
||||
pPrevReader->pReadSnap = pReader->pReadSnap;
|
||||
|
||||
pNextReader->capacity = 1;
|
||||
pNextReader->status.pTableMap = pReader->status.pTableMap;
|
||||
pNextReader->pSchema = pReader->pSchema;
|
||||
pNextReader->pMemSchema = pReader->pMemSchema;
|
||||
pNextReader->pReadSnap = pReader->pReadSnap;
|
||||
|
||||
code = doOpenReaderImpl(pPrevReader);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
pReader->suspended = true;
|
||||
|
||||
tsdbDebug("%p total numOfTable:%d in this query %s", pReader, numOfTables, pReader->idStr);
|
||||
return code;
|
||||
|
@ -3932,7 +3927,10 @@ void tsdbReaderClose(STsdbReader* pReader) {
|
|||
pReader->pDelIdx = NULL;
|
||||
}
|
||||
|
||||
tsdbUntakeReadSnap(pReader->pTsdb, pReader->pReadSnap, pReader->idStr);
|
||||
qTrace("tsdb/reader: %p, untake snapshot", pReader);
|
||||
tsdbUntakeReadSnap(pReader, pReader->pReadSnap);
|
||||
|
||||
taosThreadMutexDestroy(&pReader->readerMutex);
|
||||
|
||||
taosMemoryFree(pReader->status.uidCheckInfo.tableUidList);
|
||||
SIOCostSummary* pCost = &pReader->cost;
|
||||
|
@ -3964,9 +3962,156 @@ void tsdbReaderClose(STsdbReader* pReader) {
|
|||
if (pReader->pMemSchema != pReader->pSchema) {
|
||||
taosMemoryFree(pReader->pMemSchema);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pReader);
|
||||
}
|
||||
|
||||
int32_t tsdbReaderSuspend(STsdbReader* pReader) {
|
||||
int32_t code = 0;
|
||||
|
||||
// save reader's base state & reset top state to be reconstructed from base state
|
||||
SReaderStatus* pStatus = &pReader->status;
|
||||
STableBlockScanInfo* pBlockScanInfo = NULL;
|
||||
|
||||
if (pStatus->loadFromFile) {
|
||||
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pReader->status.blockIter);
|
||||
if (pBlockInfo != NULL) {
|
||||
pBlockScanInfo = taosHashGet(pStatus->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
||||
if (pBlockScanInfo == NULL) {
|
||||
code = TSDB_CODE_INVALID_PARA;
|
||||
tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, total tables:%d, %s", pBlockInfo->uid,
|
||||
taosHashGetSize(pReader->status.pTableMap), pReader->idStr);
|
||||
goto _err;
|
||||
}
|
||||
} else {
|
||||
pBlockScanInfo = *pStatus->pTableIter;
|
||||
}
|
||||
|
||||
tsdbDataFReaderClose(&pReader->pFileReader);
|
||||
|
||||
// resetDataBlockScanInfo excluding lastKey
|
||||
STableBlockScanInfo* p = NULL;
|
||||
|
||||
while ((p = taosHashIterate(pStatus->pTableMap, p)) != NULL) {
|
||||
p->iterInit = false;
|
||||
p->iiter.hasVal = false;
|
||||
if (p->iter.iter != NULL) {
|
||||
p->iter.iter = tsdbTbDataIterDestroy(p->iter.iter);
|
||||
}
|
||||
|
||||
p->delSkyline = taosArrayDestroy(p->delSkyline);
|
||||
// p->lastKey = ts;
|
||||
}
|
||||
} else {
|
||||
pBlockScanInfo = *pStatus->pTableIter;
|
||||
if (pBlockScanInfo) {
|
||||
// save lastKey to restore memory iterator
|
||||
STimeWindow w = pReader->pResBlock->info.window;
|
||||
pBlockScanInfo->lastKey = ASCENDING_TRAVERSE(pReader->order) ? w.ekey : w.skey;
|
||||
|
||||
// reset current current table's data block scan info,
|
||||
pBlockScanInfo->iterInit = false;
|
||||
// pBlockScanInfo->iiter.hasVal = false;
|
||||
if (pBlockScanInfo->iter.iter != NULL) {
|
||||
pBlockScanInfo->iter.iter = tsdbTbDataIterDestroy(pBlockScanInfo->iter.iter);
|
||||
}
|
||||
|
||||
if (pBlockScanInfo->iiter.iter != NULL) {
|
||||
pBlockScanInfo->iiter.iter = tsdbTbDataIterDestroy(pBlockScanInfo->iiter.iter);
|
||||
}
|
||||
|
||||
pBlockScanInfo->pBlockList = taosArrayDestroy(pBlockScanInfo->pBlockList);
|
||||
tMapDataClear(&pBlockScanInfo->mapData);
|
||||
// TODO: keep skyline for reuse
|
||||
pBlockScanInfo->delSkyline = taosArrayDestroy(pBlockScanInfo->delSkyline);
|
||||
}
|
||||
}
|
||||
|
||||
tsdbUntakeReadSnap(pReader, pReader->pReadSnap);
|
||||
|
||||
pReader->suspended = true;
|
||||
|
||||
tsdbDebug("reader: %p suspended uid %" PRIu64 " in this query %s", pReader, pBlockScanInfo->uid, pReader->idStr);
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tsdbError("failed to suspend data reader, code:%s %s", tstrerror(code), pReader->idStr);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbSetQueryReseek(void* pQHandle) {
|
||||
int32_t code = 0;
|
||||
STsdbReader* pReader = pQHandle;
|
||||
|
||||
taosThreadMutexLock(&pReader->readerMutex);
|
||||
|
||||
if (pReader->suspended) {
|
||||
taosThreadMutexUnlock(&pReader->readerMutex);
|
||||
return code;
|
||||
}
|
||||
|
||||
tsdbReaderSuspend(pReader);
|
||||
|
||||
taosThreadMutexUnlock(&pReader->readerMutex);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tsdbReaderResume(STsdbReader* pReader) {
|
||||
int32_t code = 0;
|
||||
|
||||
STableBlockScanInfo** pBlockScanInfo = pReader->status.pTableIter;
|
||||
|
||||
// restore reader's state
|
||||
// task snapshot
|
||||
int32_t numOfTables = taosHashGetSize(pReader->status.pTableMap);
|
||||
if (numOfTables > 0) {
|
||||
qTrace("tsdb/reader: %p, take snapshot", pReader);
|
||||
code = tsdbTakeReadSnap(pReader, tsdbSetQueryReseek, &pReader->pReadSnap);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (pReader->type == TIMEWINDOW_RANGE_CONTAINED) {
|
||||
code = doOpenReaderImpl(pReader);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
STsdbReader* pPrevReader = pReader->innerReader[0];
|
||||
STsdbReader* pNextReader = pReader->innerReader[1];
|
||||
|
||||
// we need only one row
|
||||
pPrevReader->capacity = 1;
|
||||
pPrevReader->status.pTableMap = pReader->status.pTableMap;
|
||||
pPrevReader->pSchema = pReader->pSchema;
|
||||
pPrevReader->pMemSchema = pReader->pMemSchema;
|
||||
pPrevReader->pReadSnap = pReader->pReadSnap;
|
||||
|
||||
pNextReader->capacity = 1;
|
||||
pNextReader->status.pTableMap = pReader->status.pTableMap;
|
||||
pNextReader->pSchema = pReader->pSchema;
|
||||
pNextReader->pMemSchema = pReader->pMemSchema;
|
||||
pNextReader->pReadSnap = pReader->pReadSnap;
|
||||
|
||||
code = doOpenReaderImpl(pPrevReader);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pReader->suspended = false;
|
||||
|
||||
tsdbDebug("reader: %p resumed uid %" PRIu64 ", numOfTable:%" PRId32 ", in this query %s", pReader,
|
||||
pBlockScanInfo ? (*pBlockScanInfo)->uid : 0, numOfTables, pReader->idStr);
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tsdbError("failed to resume data reader, code:%s %s", tstrerror(code), pReader->idStr);
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool doTsdbNextDataBlock(STsdbReader* pReader) {
|
||||
// cleanup the data that belongs to the previous data block
|
||||
SSDataBlock* pBlock = pReader->pResBlock;
|
||||
|
@ -4000,10 +4145,24 @@ bool tsdbNextDataBlock(STsdbReader* pReader) {
|
|||
return false;
|
||||
}
|
||||
|
||||
SReaderStatus* pStatus = &pReader->status;
|
||||
|
||||
qTrace("tsdb/read: %p, take read mutex", pReader);
|
||||
taosThreadMutexLock(&pReader->readerMutex);
|
||||
if (pReader->suspended) {
|
||||
tsdbReaderResume(pReader);
|
||||
}
|
||||
|
||||
if (pReader->innerReader[0] != NULL && pReader->step == 0) {
|
||||
bool ret = doTsdbNextDataBlock(pReader->innerReader[0]);
|
||||
pReader->step = EXTERNAL_ROWS_PREV;
|
||||
if (ret) {
|
||||
pStatus = &pReader->innerReader[0]->status;
|
||||
if (pStatus->composedDataBlock) {
|
||||
qTrace("tsdb/read: %p, unlock read mutex", pReader);
|
||||
taosThreadMutexUnlock(&pReader->readerMutex);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -4022,6 +4181,11 @@ bool tsdbNextDataBlock(STsdbReader* pReader) {
|
|||
|
||||
bool ret = doTsdbNextDataBlock(pReader);
|
||||
if (ret) {
|
||||
if (pStatus->composedDataBlock) {
|
||||
qTrace("tsdb/read: %p, unlock read mutex", pReader);
|
||||
taosThreadMutexUnlock(&pReader->readerMutex);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -4036,10 +4200,19 @@ bool tsdbNextDataBlock(STsdbReader* pReader) {
|
|||
bool ret1 = doTsdbNextDataBlock(pReader->innerReader[1]);
|
||||
pReader->step = EXTERNAL_ROWS_NEXT;
|
||||
if (ret1) {
|
||||
pStatus = &pReader->innerReader[1]->status;
|
||||
if (pStatus->composedDataBlock) {
|
||||
qTrace("tsdb/read: %p, unlock read mutex", pReader);
|
||||
taosThreadMutexUnlock(&pReader->readerMutex);
|
||||
}
|
||||
|
||||
return ret1;
|
||||
}
|
||||
}
|
||||
|
||||
qTrace("tsdb/read: %p, unlock read mutex", pReader);
|
||||
taosThreadMutexUnlock(&pReader->readerMutex);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -4175,12 +4348,7 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock,
|
|||
}
|
||||
|
||||
static SSDataBlock* doRetrieveDataBlock(STsdbReader* pReader) {
|
||||
SReaderStatus* pStatus = &pReader->status;
|
||||
|
||||
if (pStatus->composedDataBlock) {
|
||||
return pReader->pResBlock;
|
||||
}
|
||||
|
||||
SReaderStatus* pStatus = &pReader->status;
|
||||
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pStatus->blockIter);
|
||||
STableBlockScanInfo* pBlockScanInfo =
|
||||
*(STableBlockScanInfo**)taosHashGet(pStatus->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
||||
|
@ -4202,20 +4370,50 @@ static SSDataBlock* doRetrieveDataBlock(STsdbReader* pReader) {
|
|||
return pReader->pResBlock;
|
||||
}
|
||||
|
||||
void tsdbReleaseDataBlock(STsdbReader* pReader) {
|
||||
// SReaderStatus* pStatus = &pReader->status;
|
||||
// if (!pStatus->composedDataBlock) {
|
||||
taosThreadMutexUnlock(&pReader->readerMutex);
|
||||
//}
|
||||
}
|
||||
|
||||
SSDataBlock* tsdbRetrieveDataBlock(STsdbReader* pReader, SArray* pIdList) {
|
||||
STsdbReader* pTReader = pReader;
|
||||
if (pReader->type == TIMEWINDOW_RANGE_EXTERNAL) {
|
||||
if (pReader->step == EXTERNAL_ROWS_PREV) {
|
||||
return doRetrieveDataBlock(pReader->innerReader[0]);
|
||||
pTReader = pReader->innerReader[0];
|
||||
} else if (pReader->step == EXTERNAL_ROWS_NEXT) {
|
||||
return doRetrieveDataBlock(pReader->innerReader[1]);
|
||||
pTReader = pReader->innerReader[1];
|
||||
}
|
||||
}
|
||||
|
||||
return doRetrieveDataBlock(pReader);
|
||||
SReaderStatus* pStatus = &pTReader->status;
|
||||
if (pStatus->composedDataBlock) {
|
||||
return pTReader->pResBlock;
|
||||
}
|
||||
|
||||
SSDataBlock* ret = doRetrieveDataBlock(pTReader);
|
||||
|
||||
qTrace("tsdb/read-retrieve: %p, unlock read mutex", pReader);
|
||||
taosThreadMutexUnlock(&pReader->readerMutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) {
|
||||
SReaderStatus* pStatus = &pReader->status;
|
||||
|
||||
qTrace("tsdb/read: %p, take read mutex", pReader);
|
||||
taosThreadMutexLock(&pReader->readerMutex);
|
||||
|
||||
if (pReader->suspended) {
|
||||
tsdbReaderResume(pReader);
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&pReader->readerMutex);
|
||||
|
||||
if (isEmptyQueryTimeWindow(&pReader->window) || pReader->pReadSnap == NULL) {
|
||||
tsdbDebug("tsdb reader reset return %p", pReader->pReadSnap);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -4271,6 +4469,7 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
pTableBlockInfo->totalSize = 0;
|
||||
pTableBlockInfo->totalRows = 0;
|
||||
pTableBlockInfo->numOfVgroups = 1;
|
||||
|
||||
// find the start data block in file
|
||||
SReaderStatus* pStatus = &pReader->status;
|
||||
|
@ -4342,13 +4541,18 @@ int64_t tsdbGetNumOfRowsInMemTable(STsdbReader* pReader) {
|
|||
int64_t rows = 0;
|
||||
|
||||
SReaderStatus* pStatus = &pReader->status;
|
||||
taosThreadMutexLock(&pReader->readerMutex);
|
||||
if (pReader->suspended) {
|
||||
tsdbReaderResume(pReader);
|
||||
}
|
||||
|
||||
pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, NULL);
|
||||
|
||||
while (pStatus->pTableIter != NULL) {
|
||||
STableBlockScanInfo* pBlockScanInfo = *(STableBlockScanInfo**)pStatus->pTableIter;
|
||||
|
||||
STbData* d = NULL;
|
||||
if (pReader->pTsdb->mem != NULL) {
|
||||
if (pReader->pReadSnap->pMem != NULL) {
|
||||
d = tsdbGetTbDataFromMemTable(pReader->pReadSnap->pMem, pReader->suid, pBlockScanInfo->uid);
|
||||
if (d != NULL) {
|
||||
rows += tsdbGetNRowsInTbData(d);
|
||||
|
@ -4356,7 +4560,7 @@ int64_t tsdbGetNumOfRowsInMemTable(STsdbReader* pReader) {
|
|||
}
|
||||
|
||||
STbData* di = NULL;
|
||||
if (pReader->pTsdb->imem != NULL) {
|
||||
if (pReader->pReadSnap->pIMem != NULL) {
|
||||
di = tsdbGetTbDataFromMemTable(pReader->pReadSnap->pIMem, pReader->suid, pBlockScanInfo->uid);
|
||||
if (di != NULL) {
|
||||
rows += tsdbGetNRowsInTbData(di);
|
||||
|
@ -4367,6 +4571,8 @@ int64_t tsdbGetNumOfRowsInMemTable(STsdbReader* pReader) {
|
|||
pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, pStatus->pTableIter);
|
||||
}
|
||||
|
||||
taosThreadMutexUnlock(&pReader->readerMutex);
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
@ -4408,8 +4614,10 @@ int32_t tsdbGetTableSchema(SVnode* pVnode, int64_t uid, STSchema** pSchema, int6
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tsdbTakeReadSnap(STsdb* pTsdb, STsdbReadSnap** ppSnap, const char* idStr) {
|
||||
int32_t code = 0;
|
||||
int32_t tsdbTakeReadSnap(STsdbReader* pReader, _tsdb_reseek_func_t reseek, STsdbReadSnap** ppSnap) {
|
||||
int32_t code = 0;
|
||||
STsdb* pTsdb = pReader->pTsdb;
|
||||
SVersionRange* pRange = &pReader->verRange;
|
||||
|
||||
// alloc
|
||||
*ppSnap = (STsdbReadSnap*)taosMemoryCalloc(1, sizeof(STsdbReadSnap));
|
||||
|
@ -4426,15 +4634,14 @@ int32_t tsdbTakeReadSnap(STsdb* pTsdb, STsdbReadSnap** ppSnap, const char* idStr
|
|||
}
|
||||
|
||||
// take snapshot
|
||||
(*ppSnap)->pMem = pTsdb->mem;
|
||||
(*ppSnap)->pIMem = pTsdb->imem;
|
||||
|
||||
if ((*ppSnap)->pMem) {
|
||||
tsdbRefMemTable((*ppSnap)->pMem);
|
||||
if (pTsdb->mem && (pRange->minVer <= pTsdb->mem->maxVer && pRange->maxVer >= pTsdb->mem->minVer)) {
|
||||
tsdbRefMemTable(pTsdb->mem, pReader, reseek, &(*ppSnap)->pNode);
|
||||
(*ppSnap)->pMem = pTsdb->mem;
|
||||
}
|
||||
|
||||
if ((*ppSnap)->pIMem) {
|
||||
tsdbRefMemTable((*ppSnap)->pIMem);
|
||||
if (pTsdb->imem && (pRange->minVer <= pTsdb->imem->maxVer && pRange->maxVer >= pTsdb->imem->minVer)) {
|
||||
tsdbRefMemTable(pTsdb->imem, pReader, reseek, &(*ppSnap)->pINode);
|
||||
(*ppSnap)->pIMem = pTsdb->imem;
|
||||
}
|
||||
|
||||
// fs
|
||||
|
@ -4451,23 +4658,25 @@ int32_t tsdbTakeReadSnap(STsdb* pTsdb, STsdbReadSnap** ppSnap, const char* idStr
|
|||
goto _exit;
|
||||
}
|
||||
|
||||
tsdbTrace("vgId:%d, take read snapshot, %s", TD_VID(pTsdb->pVnode), idStr);
|
||||
tsdbTrace("vgId:%d, take read snapshot", TD_VID(pTsdb->pVnode));
|
||||
_exit:
|
||||
return code;
|
||||
}
|
||||
|
||||
void tsdbUntakeReadSnap(STsdb* pTsdb, STsdbReadSnap* pSnap, const char* idStr) {
|
||||
void tsdbUntakeReadSnap(STsdbReader* pReader, STsdbReadSnap* pSnap) {
|
||||
STsdb* pTsdb = pReader->pTsdb;
|
||||
|
||||
if (pSnap) {
|
||||
if (pSnap->pMem) {
|
||||
tsdbUnrefMemTable(pSnap->pMem);
|
||||
tsdbUnrefMemTable(pSnap->pMem, pSnap->pNode);
|
||||
}
|
||||
|
||||
if (pSnap->pIMem) {
|
||||
tsdbUnrefMemTable(pSnap->pIMem);
|
||||
tsdbUnrefMemTable(pSnap->pIMem, pSnap->pINode);
|
||||
}
|
||||
|
||||
tsdbFSUnref(pTsdb, &pSnap->fs);
|
||||
taosMemoryFree(pSnap);
|
||||
}
|
||||
tsdbTrace("vgId:%d, untake read snapshot, %s", TD_VID(pTsdb->pVnode), idStr);
|
||||
tsdbTrace("vgId:%d, untake read snapshot", TD_VID(pTsdb->pVnode));
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@ static int32_t tFDataIterCmprFn(const SRBTreeNode* pNode1, const SRBTreeNode* pN
|
|||
|
||||
static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
SDFileSet dFileSet = {.fid = pReader->fid};
|
||||
SDFileSet* pSet = taosArraySearch(pReader->fs.aDFileSet, &dFileSet, tDFileSetCmprFn, TD_GT);
|
||||
|
@ -83,7 +84,7 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
|
|||
|
||||
pReader->fid = pSet->fid;
|
||||
code = tsdbDataFReaderOpen(&pReader->pDataFReader, pReader->pTsdb, pSet);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
pReader->pIter = NULL;
|
||||
tRBTreeCreate(&pReader->rbt, tFDataIterCmprFn);
|
||||
|
@ -93,13 +94,13 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
|
|||
pIter->type = SNAP_DATA_FILE_ITER;
|
||||
|
||||
code = tsdbReadBlockIdx(pReader->pDataFReader, pIter->aBlockIdx);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
for (pIter->iBlockIdx = 0; pIter->iBlockIdx < taosArrayGetSize(pIter->aBlockIdx); pIter->iBlockIdx++) {
|
||||
pIter->pBlockIdx = (SBlockIdx*)taosArrayGet(pIter->aBlockIdx, pIter->iBlockIdx);
|
||||
|
||||
code = tsdbReadDataBlk(pReader->pDataFReader, pIter->pBlockIdx, &pIter->mBlock);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
for (pIter->iBlock = 0; pIter->iBlock < pIter->mBlock.nItem; pIter->iBlock++) {
|
||||
SDataBlk dataBlk;
|
||||
|
@ -108,7 +109,7 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
|
|||
if (dataBlk.minVer > pReader->ever || dataBlk.maxVer < pReader->sver) continue;
|
||||
|
||||
code = tsdbReadDataBlockEx(pReader->pDataFReader, &dataBlk, &pIter->bData);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
ASSERT(pIter->pBlockIdx->suid == pIter->bData.suid);
|
||||
ASSERT(pIter->pBlockIdx->uid == pIter->bData.uid);
|
||||
|
@ -139,7 +140,7 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
|
|||
pIter->iStt = iStt;
|
||||
|
||||
code = tsdbReadSttBlk(pReader->pDataFReader, iStt, pIter->aSttBlk);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
for (pIter->iSttBlk = 0; pIter->iSttBlk < taosArrayGetSize(pIter->aSttBlk); pIter->iSttBlk++) {
|
||||
SSttBlk* pSttBlk = (SSttBlk*)taosArrayGet(pIter->aSttBlk, pIter->iSttBlk);
|
||||
|
@ -148,7 +149,7 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
|
|||
if (pSttBlk->maxVer < pReader->sver) continue;
|
||||
|
||||
code = tsdbReadSttBlockEx(pReader->pDataFReader, iStt, pSttBlk, &pIter->bData);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
for (pIter->iRow = 0; pIter->iRow < pIter->bData.nRow; pIter->iRow++) {
|
||||
int64_t rowVer = pIter->bData.aVersion[pIter->iRow];
|
||||
|
@ -169,13 +170,13 @@ static int32_t tsdbSnapReadOpenFile(STsdbSnapReader* pReader) {
|
|||
pIter++;
|
||||
}
|
||||
|
||||
tsdbInfo("vgId:%d, vnode snapshot tsdb open data file to read for %s, fid:%d", TD_VID(pReader->pTsdb->pVnode),
|
||||
pReader->pTsdb->path, pReader->fid);
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tsdbError("vgId:%d, vnode snapshot tsdb snap read open file failed since %s", TD_VID(pReader->pTsdb->pVnode),
|
||||
tstrerror(code));
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d, %s failed since %s", TD_VID(pReader->pTsdb->pVnode), __func__, tstrerror(code));
|
||||
} else {
|
||||
tsdbInfo("vgId:%d, %s done, path:%s, fid:%d", TD_VID(pReader->pTsdb->pVnode), __func__, pReader->pTsdb->path,
|
||||
pReader->fid);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -318,12 +319,14 @@ _exit:
|
|||
|
||||
static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
|
||||
int32_t code = 0;
|
||||
STsdb* pTsdb = pReader->pTsdb;
|
||||
int32_t lino = 0;
|
||||
|
||||
STsdb* pTsdb = pReader->pTsdb;
|
||||
|
||||
while (true) {
|
||||
if (pReader->pDataFReader == NULL) {
|
||||
code = tsdbSnapReadOpenFile(pReader);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
if (pReader->pDataFReader == NULL) break;
|
||||
|
@ -338,17 +341,17 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
|
|||
SBlockData* pBlockData = &pReader->bData;
|
||||
|
||||
code = tsdbUpdateTableSchema(pTsdb->pVnode->pMeta, id.suid, id.uid, &pReader->skmTable);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tBlockDataInit(pBlockData, &id, pReader->skmTable.pTSchema, NULL, 0);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
while (pRowInfo->suid == id.suid && pRowInfo->uid == id.uid) {
|
||||
code = tBlockDataAppendRow(pBlockData, &pRowInfo->row, NULL, pRowInfo->uid);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
code = tsdbSnapNextRow(pReader);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
pRowInfo = tsdbSnapGetRow(pReader);
|
||||
if (pRowInfo == NULL) {
|
||||
|
@ -360,21 +363,22 @@ static int32_t tsdbSnapReadData(STsdbSnapReader* pReader, uint8_t** ppData) {
|
|||
}
|
||||
|
||||
code = tsdbSnapCmprData(pReader, ppData);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tsdbError("vgId:%d, vnode snapshot tsdb read data for %s failed since %s", TD_VID(pTsdb->pVnode), pTsdb->path,
|
||||
tstrerror(code));
|
||||
_exit:
|
||||
if (code) {
|
||||
tsdbError("vgId:%d, %s failed since %s, path:%s", TD_VID(pTsdb->pVnode), __func__, tstrerror(code), pTsdb->path);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) {
|
||||
int32_t code = 0;
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
STsdb* pTsdb = pReader->pTsdb;
|
||||
SDelFile* pDelFile = pReader->fs.pDelFile;
|
||||
|
||||
|
@ -385,11 +389,11 @@ static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) {
|
|||
|
||||
// open
|
||||
code = tsdbDelFReaderOpen(&pReader->pDelFReader, pDelFile, pTsdb);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
// read index
|
||||
code = tsdbReadDelIdx(pReader->pDelFReader, pReader->aDelIdx);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
pReader->iDelIdx = 0;
|
||||
}
|
||||
|
@ -405,7 +409,7 @@ static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) {
|
|||
pReader->iDelIdx++;
|
||||
|
||||
code = tsdbReadDelData(pReader->pDelFReader, pDelIdx, pReader->aDelData);
|
||||
if (code) goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
||||
int32_t size = 0;
|
||||
for (int32_t iDelData = 0; iDelData < taosArrayGetSize(pReader->aDelData); iDelData++) {
|
||||
|
@ -422,7 +426,7 @@ static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) {
|
|||
*ppData = taosMemoryMalloc(sizeof(SSnapDataHdr) + size);
|
||||
if (*ppData == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
SSnapDataHdr* pHdr = (SSnapDataHdr*)(*ppData);
|
||||
|
@ -449,11 +453,9 @@ static int32_t tsdbSnapReadDel(STsdbSnapReader* pReader, uint8_t** ppData) {
|
|||
}
|
||||
|
||||
_exit:
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tsdbError("vgId:%d, vnode snapshot tsdb read del for %s failed since %s", TD_VID(pTsdb->pVnode), pTsdb->path,
|
||||
tstrerror(code));
|
||||
if (code) {
|
||||
tsdbError("vgId:%d, %s failed since %s, path:%s", TD_VID(pTsdb->pVnode), __func__, tstrerror(code), pTsdb->path);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -591,44 +593,39 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** ppReader) {
|
|||
|
||||
int32_t tsdbSnapRead(STsdbSnapReader* pReader, uint8_t** ppData) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
*ppData = NULL;
|
||||
|
||||
// read data file
|
||||
if (!pReader->dataDone) {
|
||||
code = tsdbSnapReadData(pReader, ppData);
|
||||
if (code) {
|
||||
goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
if (*ppData) {
|
||||
goto _exit;
|
||||
} else {
|
||||
if (*ppData) {
|
||||
goto _exit;
|
||||
} else {
|
||||
pReader->dataDone = 1;
|
||||
}
|
||||
pReader->dataDone = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// read del file
|
||||
if (!pReader->delDone) {
|
||||
code = tsdbSnapReadDel(pReader, ppData);
|
||||
if (code) {
|
||||
goto _err;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
if (*ppData) {
|
||||
goto _exit;
|
||||
} else {
|
||||
if (*ppData) {
|
||||
goto _exit;
|
||||
} else {
|
||||
pReader->delDone = 1;
|
||||
}
|
||||
pReader->delDone = 1;
|
||||
}
|
||||
}
|
||||
|
||||
_exit:
|
||||
tsdbDebug("vgId:%d, vnode snapshot tsdb read for %s", TD_VID(pReader->pTsdb->pVnode), pReader->pTsdb->path);
|
||||
return code;
|
||||
|
||||
_err:
|
||||
tsdbError("vgId:%d, vnode snapshot tsdb read for %s failed since %s", TD_VID(pReader->pTsdb->pVnode),
|
||||
pReader->pTsdb->path, tstrerror(code));
|
||||
if (code) {
|
||||
tsdbError("vgId:%d, %s failed since %s, path:%s", TD_VID(pReader->pTsdb->pVnode), __func__, tstrerror(code),
|
||||
pReader->pTsdb->path);
|
||||
} else {
|
||||
tsdbDebug("vgId:%d, %s done, path:%s", TD_VID(pReader->pTsdb->pVnode), __func__, pReader->pTsdb->path);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,8 +83,7 @@ static FORCE_INLINE int tsdbCheckRowRange(STsdb *pTsdb, tb_uid_t uid, TSKEY rowK
|
|||
tsdbError("vgId:%d, table uid %" PRIu64 " timestamp is out of range! now %" PRId64 " minKey %" PRId64
|
||||
" maxKey %" PRId64 " row key %" PRId64,
|
||||
TD_VID(pTsdb->pVnode), uid, now, minKey, maxKey, rowKey);
|
||||
terrno = TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
|
||||
return -1;
|
||||
return TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -164,15 +163,13 @@ int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) {
|
|||
#endif
|
||||
|
||||
int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq2 *pMsg) {
|
||||
ASSERT(pMsg != NULL);
|
||||
int32_t code = 0;
|
||||
STsdbKeepCfg *pCfg = &pTsdb->keepCfg;
|
||||
TSKEY now = taosGetTimestamp(pCfg->precision);
|
||||
TSKEY minKey = now - tsTickPerMin[pCfg->precision] * pCfg->keep2;
|
||||
TSKEY maxKey = tsMaxKeyByPrecision[pCfg->precision];
|
||||
int32_t size = taosArrayGetSize(pMsg->aSubmitTbData);
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSubmitTbData *pData = TARRAY_GET_ELEM(pMsg->aSubmitTbData, i);
|
||||
if (pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
|
||||
|
@ -182,8 +179,8 @@ int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq2 *pMsg) {
|
|||
int32_t nRows = aColData[0].nVal;
|
||||
TSKEY *aKey = (TSKEY *)aColData[0].pData;
|
||||
for (int32_t r = 0; r < nRows; ++r) {
|
||||
if (tsdbCheckRowRange(pTsdb, pData->uid, aKey[r], minKey, maxKey, now) < 0) {
|
||||
return -1;
|
||||
if ((code = tsdbCheckRowRange(pTsdb, pData->uid, aKey[r], minKey, maxKey, now)) < 0) {
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,13 +188,13 @@ int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq2 *pMsg) {
|
|||
int32_t nRows = taosArrayGetSize(pData->aRowP);
|
||||
for (int32_t r = 0; r < nRows; ++r) {
|
||||
SRow *pRow = (SRow *)taosArrayGetP(pData->aRowP, r);
|
||||
if (tsdbCheckRowRange(pTsdb, pData->uid, pRow->ts, minKey, maxKey, now) < 0) {
|
||||
return -1;
|
||||
if ((code = tsdbCheckRowRange(pTsdb, pData->uid, pRow->ts, minKey, maxKey, now)) < 0) {
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (terrno != TSDB_CODE_SUCCESS) return -1;
|
||||
return 0;
|
||||
_exit:
|
||||
return code;
|
||||
}
|
|
@ -74,7 +74,7 @@ int vnodeOpenBufPool(SVnode *pVnode) {
|
|||
|
||||
ASSERT(pVnode->pPool == NULL);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int i = 0; i < VNODE_BUF_POOL_SEG; i++) {
|
||||
// create pool
|
||||
if (vnodeBufPoolCreate(pVnode, size, &pPool)) {
|
||||
vError("vgId:%d, failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
|
|
|
@ -125,13 +125,22 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
|
|||
if (tjsonAddIntegerToObject(pJson, "vndStats.timeseries", pCfg->vndStats.numOfTimeSeries) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "vndStats.ntimeseries", pCfg->vndStats.numOfNTimeSeries) < 0) return -1;
|
||||
|
||||
SJson *pNodeInfoArr = tjsonCreateArray();
|
||||
tjsonAddItemToObject(pJson, "syncCfg.nodeInfo", pNodeInfoArr);
|
||||
SJson *nodeInfo = tjsonCreateArray();
|
||||
if (nodeInfo == NULL) return -1;
|
||||
if (tjsonAddItemToObject(pJson, "syncCfg.nodeInfo", nodeInfo) < 0) return -1;
|
||||
vDebug("vgId:%d, encode config, replicas:%d selfIndex:%d", pCfg->vgId, pCfg->syncCfg.replicaNum,
|
||||
pCfg->syncCfg.myIndex);
|
||||
for (int i = 0; i < pCfg->syncCfg.replicaNum; ++i) {
|
||||
SJson *pNodeInfo = tjsonCreateObject();
|
||||
tjsonAddIntegerToObject(pNodeInfo, "nodePort", (pCfg->syncCfg.nodeInfo)[i].nodePort);
|
||||
tjsonAddStringToObject(pNodeInfo, "nodeFqdn", (pCfg->syncCfg.nodeInfo)[i].nodeFqdn);
|
||||
tjsonAddItemToArray(pNodeInfoArr, pNodeInfo);
|
||||
SJson *info = tjsonCreateObject();
|
||||
SNodeInfo *pNode = (SNodeInfo *)&pCfg->syncCfg.nodeInfo[i];
|
||||
if (info == NULL) return -1;
|
||||
if (tjsonAddIntegerToObject(info, "nodePort", pNode->nodePort) < 0) return -1;
|
||||
if (tjsonAddStringToObject(info, "nodeFqdn", pNode->nodeFqdn) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(info, "nodeId", pNode->nodeId) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(info, "clusterId", pNode->clusterId) < 0) return -1;
|
||||
if (tjsonAddItemToArray(nodeInfo, info) < 0) return -1;
|
||||
vDebug("vgId:%d, encode config, replica:%d ep:%s:%u dnode:%d", pCfg->vgId, i, pNode->nodeFqdn, pNode->nodePort,
|
||||
pNode->nodeId);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -240,15 +249,24 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
|
|||
tjsonGetNumberValue(pJson, "vndStats.ntimeseries", pCfg->vndStats.numOfNTimeSeries, code);
|
||||
if (code < 0) return -1;
|
||||
|
||||
SJson *pNodeInfoArr = tjsonGetObjectItem(pJson, "syncCfg.nodeInfo");
|
||||
int arraySize = tjsonGetArraySize(pNodeInfoArr);
|
||||
assert(arraySize == pCfg->syncCfg.replicaNum);
|
||||
SJson *nodeInfo = tjsonGetObjectItem(pJson, "syncCfg.nodeInfo");
|
||||
int arraySize = tjsonGetArraySize(nodeInfo);
|
||||
if (arraySize != pCfg->syncCfg.replicaNum) return -1;
|
||||
|
||||
vDebug("vgId:%d, decode config, replicas:%d selfIndex:%d", pCfg->vgId, pCfg->syncCfg.replicaNum,
|
||||
pCfg->syncCfg.myIndex);
|
||||
for (int i = 0; i < arraySize; ++i) {
|
||||
SJson *pNodeInfo = tjsonGetArrayItem(pNodeInfoArr, i);
|
||||
assert(pNodeInfo != NULL);
|
||||
tjsonGetNumberValue(pNodeInfo, "nodePort", (pCfg->syncCfg.nodeInfo)[i].nodePort, code);
|
||||
tjsonGetStringValue(pNodeInfo, "nodeFqdn", (pCfg->syncCfg.nodeInfo)[i].nodeFqdn);
|
||||
SJson *info = tjsonGetArrayItem(nodeInfo, i);
|
||||
SNodeInfo *pNode = &pCfg->syncCfg.nodeInfo[i];
|
||||
if (info == NULL) return -1;
|
||||
tjsonGetNumberValue(info, "nodePort", pNode->nodePort, code);
|
||||
if (code < 0) return -1;
|
||||
tjsonGetStringValue(info, "nodeFqdn", pNode->nodeFqdn);
|
||||
if (code < 0) return -1;
|
||||
tjsonGetNumberValue(info, "nodeId", pNode->nodeId, code);
|
||||
tjsonGetNumberValue(info, "clusterId", pNode->clusterId, code);
|
||||
vDebug("vgId:%d, decode config, replica:%d ep:%s:%u dnode:%d", pCfg->vgId, i, pNode->nodeFqdn, pNode->nodePort,
|
||||
pNode->nodeId);
|
||||
}
|
||||
|
||||
tjsonGetNumberValue(pJson, "tsdbPageSize", pCfg->tsdbPageSize, code);
|
||||
|
|
|
@ -105,8 +105,8 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) {
|
|||
// free info binary
|
||||
taosMemoryFree(data);
|
||||
|
||||
vInfo("vgId:%d, vnode info is saved, fname:%s replica:%d", pInfo->config.vgId, fname,
|
||||
pInfo->config.syncCfg.replicaNum);
|
||||
vInfo("vgId:%d, vnode info is saved, fname:%s replica:%d selfIndex:%d", pInfo->config.vgId, fname,
|
||||
pInfo->config.syncCfg.replicaNum, pInfo->config.syncCfg.myIndex);
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -206,6 +206,8 @@ static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) {
|
|||
} else {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path);
|
||||
}
|
||||
|
||||
vDebug("vgId:%d, save config while prepare commit", TD_VID(pVnode));
|
||||
if (vnodeSaveInfo(dir, &pInfo->info) < 0) {
|
||||
code = terrno;
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
|
|
|
@ -48,6 +48,7 @@ int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) {
|
|||
info.state.applied = -1;
|
||||
info.state.commitID = 0;
|
||||
|
||||
vInfo("vgId:%d, save config while create", pCfg->vgId);
|
||||
if (vnodeSaveInfo(dir, &info) < 0 || vnodeCommitInfo(dir, &info) < 0) {
|
||||
vError("vgId:%d, failed to save vnode config since %s", pCfg ? pCfg->vgId : 0, tstrerror(terrno));
|
||||
return -1;
|
||||
|
@ -79,12 +80,14 @@ int32_t vnodeAlter(const char *path, SAlterVnodeReplicaReq *pReq, STfs *pTfs) {
|
|||
pCfg->replicaNum = pReq->replica;
|
||||
memset(&pCfg->nodeInfo, 0, sizeof(pCfg->nodeInfo));
|
||||
|
||||
vInfo("vgId:%d, save config, replicas:%d selfIndex:%d", pReq->vgId, pCfg->replicaNum, pCfg->myIndex);
|
||||
vInfo("vgId:%d, save config while alter, replicas:%d selfIndex:%d", pReq->vgId, pCfg->replicaNum, pCfg->myIndex);
|
||||
for (int i = 0; i < pReq->replica; ++i) {
|
||||
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
||||
pNode->nodeId = pReq->replicas[i].id;
|
||||
pNode->nodePort = pReq->replicas[i].port;
|
||||
tstrncpy(pNode->nodeFqdn, pReq->replicas[i].fqdn, sizeof(pNode->nodeFqdn));
|
||||
vInfo("vgId:%d, save config, replica:%d ep:%s:%u", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort);
|
||||
(void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort);
|
||||
vInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId);
|
||||
}
|
||||
|
||||
info.config.syncCfg = *pCfg;
|
||||
|
|
|
@ -405,6 +405,10 @@ static int32_t vnodeSnapWriteInfo(SVSnapWriter *pWriter, uint8_t *pData, uint32_
|
|||
} else {
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s", pWriter->pVnode->path);
|
||||
}
|
||||
|
||||
SVnode *pVnode = pWriter->pVnode;
|
||||
pWriter->info.config = pVnode->config;
|
||||
vDebug("vgId:%d, save config while write snapshot", pWriter->pVnode->config.vgId);
|
||||
if (vnodeSaveInfo(dir, &pWriter->info) < 0) {
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
|
|
|
@ -578,7 +578,8 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
|||
vInfo("vgId:%d, start to open sync, replica:%d selfIndex:%d", pVnode->config.vgId, pCfg->replicaNum, pCfg->myIndex);
|
||||
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
||||
vInfo("vgId:%d, index:%d ep:%s:%u", pVnode->config.vgId, i, pNode->nodeFqdn, pNode->nodePort);
|
||||
vInfo("vgId:%d, index:%d ep:%s:%u dnode:%d cluster:%" PRId64, pVnode->config.vgId, i, pNode->nodeFqdn, pNode->nodePort,
|
||||
pNode->nodeId, pNode->clusterId);
|
||||
}
|
||||
|
||||
pVnode->sync = syncOpen(&syncInfo);
|
||||
|
|
|
@ -582,34 +582,34 @@ typedef struct SCtgOperation {
|
|||
#define CTG_LOCK(type, _lock) \
|
||||
do { \
|
||||
if (CTG_READ == (type)) { \
|
||||
assert(atomic_load_32((_lock)) >= 0); \
|
||||
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value before read lock"); \
|
||||
CTG_LOCK_DEBUG("CTG RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
taosRLockLatch(_lock); \
|
||||
CTG_LOCK_DEBUG("CTG RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
assert(atomic_load_32((_lock)) > 0); \
|
||||
ASSERTS(atomic_load_32((_lock)) > 0, "invalid lock value after read lock"); \
|
||||
} else { \
|
||||
assert(atomic_load_32((_lock)) >= 0); \
|
||||
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value before write lock"); \
|
||||
CTG_LOCK_DEBUG("CTG WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
taosWLockLatch(_lock); \
|
||||
CTG_LOCK_DEBUG("CTG WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \
|
||||
ASSERTS(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY, "invalid lock value after write lock"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CTG_UNLOCK(type, _lock) \
|
||||
do { \
|
||||
if (CTG_READ == (type)) { \
|
||||
assert(atomic_load_32((_lock)) > 0); \
|
||||
ASSERTS(atomic_load_32((_lock)) > 0, "invalid lock value before read unlock"); \
|
||||
CTG_LOCK_DEBUG("CTG RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
taosRUnLockLatch(_lock); \
|
||||
CTG_LOCK_DEBUG("CTG RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
assert(atomic_load_32((_lock)) >= 0); \
|
||||
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value after read unlock"); \
|
||||
} else { \
|
||||
assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \
|
||||
ASSERTS(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY, "invalid lock value before write unlock"); \
|
||||
CTG_LOCK_DEBUG("CTG WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
taosWUnLockLatch(_lock); \
|
||||
CTG_LOCK_DEBUG("CTG WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
|
||||
assert(atomic_load_32((_lock)) >= 0); \
|
||||
ASSERTS(atomic_load_32((_lock)) >= 0, "invalid lock value after write unlock"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
@ -776,6 +776,7 @@ void ctgFreeHandleImpl(SCatalog* pCtg);
|
|||
int32_t ctgGetVgInfoFromHashValue(SCatalog* pCtg, SDBVgInfo* dbInfo, const SName* pTableName, SVgroupInfo* pVgroup);
|
||||
int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SCtgTaskReq* tReq, SDBVgInfo* dbInfo, SCtgTbHashsCtx* pCtx,
|
||||
char* dbFName, SArray* pNames, bool update);
|
||||
int32_t ctgGetVgIdsFromHashValue(SCatalog* pCtg, SDBVgInfo* dbInfo, char* dbFName, const char* pTbs[], int32_t tbNum, int32_t* vgId);
|
||||
void ctgResetTbMetaTask(SCtgTask* pTask);
|
||||
void ctgFreeDbCache(SCtgDBCache* dbCache);
|
||||
int32_t ctgStbVersionSortCompare(const void* key1, const void* key2);
|
||||
|
|
|
@ -551,6 +551,37 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgGetTbsHashVgId(SCatalog* pCtg, SRequestConnInfo* pConn, int32_t acctId, const char* pDb, const char* pTbs[], int32_t tbNum, int32_t* vgId) {
|
||||
if (IS_SYS_DBNAME(pDb)) {
|
||||
ctgError("no valid vgInfo for db, dbname:%s", pDb);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT);
|
||||
}
|
||||
|
||||
SCtgDBCache* dbCache = NULL;
|
||||
int32_t code = 0;
|
||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||
snprintf(dbFName, TSDB_DB_FNAME_LEN, "%d.%s", acctId, pDb);
|
||||
|
||||
SDBVgInfo* vgInfo = NULL;
|
||||
CTG_ERR_JRET(ctgGetDBVgInfo(pCtg, pConn, dbFName, &dbCache, &vgInfo, NULL));
|
||||
|
||||
CTG_ERR_JRET(ctgGetVgIdsFromHashValue(pCtg, vgInfo ? vgInfo : dbCache->vgCache.vgInfo, dbFName, pTbs, tbNum, vgId));
|
||||
|
||||
_return:
|
||||
|
||||
if (dbCache) {
|
||||
ctgRUnlockVgInfo(dbCache);
|
||||
ctgReleaseDBCache(pCtg, dbCache);
|
||||
}
|
||||
|
||||
if (vgInfo) {
|
||||
freeVgInfo(vgInfo);
|
||||
}
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgGetCachedTbVgMeta(SCatalog* pCtg, const SName* pTableName, SVgroupInfo* pVgroup, STableMeta** pTableMeta) {
|
||||
int32_t code = 0;
|
||||
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||
|
@ -1141,6 +1172,13 @@ int32_t catalogGetTableHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const
|
|||
CTG_API_LEAVE(ctgGetTbHashVgroup(pCtg, pConn, pTableName, pVgroup, NULL));
|
||||
}
|
||||
|
||||
int32_t catalogGetTablesHashVgId(SCatalog* pCtg, SRequestConnInfo* pConn, int32_t acctId, const char* pDb, const char* pTableName[],
|
||||
int32_t tableNum, int32_t *vgId) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
CTG_API_LEAVE(ctgGetTbsHashVgId(pCtg, pConn, acctId, pDb, pTableName, tableNum, vgId));
|
||||
}
|
||||
|
||||
int32_t catalogGetCachedTableHashVgroup(SCatalog* pCtg, const SName* pTableName, SVgroupInfo* pVgroup, bool* exists) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ extern SCatalogMgmt gCtgMgmt;
|
|||
SCtgDebug gCTGDebug = {0};
|
||||
|
||||
void ctgdUserCallback(SMetaData *pResult, void *param, int32_t code) {
|
||||
ASSERT(*(int32_t *)param == 1);
|
||||
taosMemoryFree(param);
|
||||
|
||||
qDebug("async call result: %s", tstrerror(code));
|
||||
|
|
|
@ -40,7 +40,9 @@ int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBu
|
|||
msgNum = taosArrayGetSize(batchRsp.pRsps);
|
||||
}
|
||||
|
||||
ASSERT(taskNum == msgNum || 0 == msgNum);
|
||||
if (ASSERTS(taskNum == msgNum || 0 == msgNum, "taskNum %d mis-match msgNum %d", taskNum, msgNum)) {
|
||||
msgNum = 0;
|
||||
}
|
||||
|
||||
ctgDebug("QID:0x%" PRIx64 " ctg got batch %d rsp %s", pJob->queryId, cbParam->batchId,
|
||||
TMSG_INFO(cbParam->reqType + 1));
|
||||
|
@ -58,11 +60,19 @@ int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBu
|
|||
if (msgNum > 0) {
|
||||
pRsp = taosArrayGet(batchRsp.pRsps, i);
|
||||
|
||||
taskMsg.msgType = pRsp->reqType;
|
||||
taskMsg.pData = pRsp->msg;
|
||||
taskMsg.len = pRsp->msgLen;
|
||||
|
||||
ASSERT(pRsp->msgIdx == *msgIdx);
|
||||
if (ASSERTS(pRsp->msgIdx == *msgIdx, "rsp msgIdx %d mis-match msgIdx %d", pRsp->msgIdx, *msgIdx)) {
|
||||
pRsp = &rsp;
|
||||
pRsp->msgIdx = *msgIdx;
|
||||
pRsp->reqType = -1;
|
||||
pRsp->rspCode = 0;
|
||||
taskMsg.msgType = -1;
|
||||
taskMsg.pData = NULL;
|
||||
taskMsg.len = 0;
|
||||
} else {
|
||||
taskMsg.msgType = pRsp->reqType;
|
||||
taskMsg.pData = pRsp->msg;
|
||||
taskMsg.len = pRsp->msgLen;
|
||||
}
|
||||
} else {
|
||||
pRsp = &rsp;
|
||||
pRsp->msgIdx = *msgIdx;
|
||||
|
|
|
@ -986,6 +986,43 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SCtgTaskReq* tReq, SDBVgInfo*
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgGetVgIdsFromHashValue(SCatalog* pCtg, SDBVgInfo* dbInfo, char* dbFName, const char* pTbs[], int32_t tbNum, int32_t* vgId) {
|
||||
int32_t code = 0;
|
||||
CTG_ERR_RET(ctgMakeVgArray(dbInfo));
|
||||
|
||||
int32_t vgNum = taosArrayGetSize(dbInfo->vgArray);
|
||||
|
||||
if (vgNum <= 0) {
|
||||
ctgError("db vgroup cache invalid, db:%s, vgroup number:%d", dbFName, vgNum);
|
||||
CTG_ERR_RET(TSDB_CODE_TSC_DB_NOT_SELECTED);
|
||||
}
|
||||
|
||||
SVgroupInfo* vgInfo = NULL;
|
||||
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
||||
snprintf(tbFullName, sizeof(tbFullName), "%s.", dbFName);
|
||||
int32_t offset = strlen(tbFullName);
|
||||
|
||||
for (int32_t i = 0; i < tbNum; ++i) {
|
||||
snprintf(tbFullName + offset, sizeof(tbFullName) - offset, "%s", pTbs[i]);
|
||||
uint32_t hashValue = taosGetTbHashVal(tbFullName, (uint32_t)strlen(tbFullName), dbInfo->hashMethod,
|
||||
dbInfo->hashPrefix, dbInfo->hashSuffix);
|
||||
|
||||
vgInfo = taosArraySearch(dbInfo->vgArray, &hashValue, ctgHashValueComp, TD_EQ);
|
||||
if (NULL == vgInfo) {
|
||||
ctgError("no hash range found for hash value [%u], db:%s, numOfVgId:%d", hashValue, dbFName,
|
||||
(int32_t)taosArrayGetSize(dbInfo->vgArray));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
vgId[i] = vgInfo->vgId;
|
||||
|
||||
ctgDebug("Got tb %s vgId:%d", tbFullName, vgInfo->vgId);
|
||||
}
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgStbVersionSearchCompare(const void* key1, const void* key2) {
|
||||
if (*(uint64_t*)key1 < ((SSTableVersion*)key2)->suid) {
|
||||
return -1;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "tdatablock.h"
|
||||
#include "tglobal.h"
|
||||
#include "tgrant.h"
|
||||
#include "taosdef.h"
|
||||
|
||||
extern SConfig* tsCfg;
|
||||
|
||||
|
@ -40,7 +41,6 @@ static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRe
|
|||
(*pRsp)->numOfCols = htonl(numOfCols);
|
||||
|
||||
int32_t len = blockEncode(pBlock, (*pRsp)->data, numOfCols);
|
||||
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -154,6 +154,23 @@ static int32_t buildCreateDBResultDataBlock(SSDataBlock** pOutput) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t buildAliveResultDataBlock(SSDataBlock** pOutput) {
|
||||
SSDataBlock* pBlock = createDataBlock();
|
||||
if (NULL == pBlock) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_INT, sizeof(int32_t), 1);
|
||||
int32_t code = blockDataAppendColInfo(pBlock, &infoData);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOutput = pBlock;
|
||||
} else {
|
||||
blockDataDestroy(pBlock);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int64_t getValOfDiffPrecision(int8_t unit, int64_t val) {
|
||||
int64_t v = 0;
|
||||
switch (unit) {
|
||||
|
@ -281,6 +298,108 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbFName, S
|
|||
colDataAppend(pCol2, 0, buf2, false);
|
||||
}
|
||||
|
||||
#define CHECK_LEADER(n) (row[n] && (fields[n].type == TSDB_DATA_TYPE_VARCHAR && strncasecmp(row[n], "leader", varDataLen((char *)row[n] - VARSTR_HEADER_SIZE)) == 0))
|
||||
// on this row, if have leader return true else return false
|
||||
bool existLeaderRole(TAOS_ROW row, TAOS_FIELD* fields, int nFields) {
|
||||
// vgroup_id | db_name | tables | v1_dnode | v1_status | v2_dnode | v2_status | v3_dnode | v3_status | v4_dnode |
|
||||
// v4_status | cacheload | tsma |
|
||||
if (nFields != 13) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check have leader on cloumn v*_status on 4 6 8 10
|
||||
if (CHECK_LEADER(4) || CHECK_LEADER(6) || CHECK_LEADER(8) || CHECK_LEADER(10)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// get db alive status, return 1 is alive else return 0
|
||||
int32_t getAliveStatusFromApi(int64_t* pConnId, char* dbName, int32_t* pStatus) {
|
||||
char sql[128 + TSDB_DB_NAME_LEN] = "select * from information_schema.ins_vgroups";
|
||||
int32_t code;
|
||||
|
||||
// filter with db name
|
||||
if (dbName && dbName[0] != 0) {
|
||||
char str[64 + TSDB_DB_NAME_LEN] = "";
|
||||
// test db name exist
|
||||
sprintf(str, "show create database %s ;", dbName);
|
||||
TAOS_RES* dbRes = taos_query(pConnId, str);
|
||||
code = taos_errno(dbRes);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taos_free_result(dbRes);
|
||||
return code;
|
||||
}
|
||||
taos_free_result(dbRes);
|
||||
|
||||
sprintf(str, " where db_name='%s' ;", dbName);
|
||||
strcat(sql, str);
|
||||
}
|
||||
|
||||
TAOS_RES* res = taos_query(pConnId, sql);
|
||||
code = taos_errno(res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taos_free_result(res);
|
||||
return code;
|
||||
}
|
||||
|
||||
TAOS_ROW row = NULL;
|
||||
TAOS_FIELD* fields = taos_fetch_fields(res);
|
||||
int32_t nFields = taos_num_fields(res);
|
||||
int32_t nAvailble = 0;
|
||||
int32_t nUnAvailble = 0;
|
||||
|
||||
while ((row = taos_fetch_row(res)) != NULL) {
|
||||
if (existLeaderRole(row, fields, nFields)) {
|
||||
nAvailble++;
|
||||
} else {
|
||||
nUnAvailble++;
|
||||
}
|
||||
}
|
||||
taos_free_result(res);
|
||||
|
||||
int32_t status = 0;
|
||||
if (nAvailble + nUnAvailble == 0 || nUnAvailble == 0) {
|
||||
status = SHOW_STATUS_AVAILABLE;
|
||||
} else if (nAvailble > 0 && nUnAvailble > 0) {
|
||||
status = SHOW_STATUS_HALF_AVAILABLE;
|
||||
} else {
|
||||
status = SHOW_STATUS_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
if (pStatus) {
|
||||
*pStatus = status;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setAliveResultIntoDataBlock(int64_t* pConnId, SSDataBlock* pBlock, char* dbName) {
|
||||
blockDataEnsureCapacity(pBlock, 1);
|
||||
pBlock->info.rows = 1;
|
||||
|
||||
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
int32_t status = 0;
|
||||
int32_t code = getAliveStatusFromApi(pConnId, dbName, &status);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
colDataAppend(pCol1, 0, (const char*)&status, false);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t execShowAliveStatus(int64_t* pConnId, SShowAliveStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
SSDataBlock* pBlock = NULL;
|
||||
int32_t code = buildAliveResultDataBlock(&pBlock);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setAliveResultIntoDataBlock(pConnId, pBlock, pStmt->dbName);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildRetrieveTableRsp(pBlock, SHOW_ALIVE_RESULT_COLS, pRsp);
|
||||
}
|
||||
blockDataDestroy(pBlock);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
SSDataBlock* pBlock = NULL;
|
||||
int32_t code = buildCreateDBResultDataBlock(&pBlock);
|
||||
|
@ -736,7 +855,7 @@ static int32_t execSelectWithoutFrom(SSelectStmt* pSelect, SRetrieveTableRsp** p
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t qExecCommand(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
||||
switch (nodeType(pStmt)) {
|
||||
case QUERY_NODE_DESCRIBE_STMT:
|
||||
return execDescribe(sysInfoUser, pStmt, pRsp);
|
||||
|
@ -754,6 +873,9 @@ int32_t qExecCommand(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp) {
|
|||
return execShowLocalVariables(pRsp);
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return execSelectWithoutFrom((SSelectStmt*)pStmt, pRsp);
|
||||
case QUERY_NODE_SHOW_DB_ALIVE_STMT:
|
||||
case QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT:
|
||||
return execShowAliveStatus(pConnId, (SShowAliveStmt*)pStmt, pRsp);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1666,7 +1666,6 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
|
|||
rsp->numOfRows = htobe64((int64_t)rowNum);
|
||||
|
||||
int32_t len = blockEncode(pBlock, rsp->data, taosArrayGetSize(pBlock->pDataBlock));
|
||||
ASSERT(len == rspSize - sizeof(SRetrieveTableRsp));
|
||||
|
||||
rsp->compLen = htonl(len);
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "function.h"
|
||||
#include "nodes.h"
|
||||
#include "plannodes.h"
|
||||
#include "tbuffer.h"
|
||||
#include "tcommon.h"
|
||||
#include "tpagedbuf.h"
|
||||
#include "tsimplehash.h"
|
||||
|
@ -116,6 +115,10 @@ struct SResultRowEntryInfo* getResultEntryInfo(const SResultRow* pRow, int32_t i
|
|||
|
||||
static FORCE_INLINE SResultRow* getResultRowByPos(SDiskbasedBuf* pBuf, SResultRowPosition* pos, bool forUpdate) {
|
||||
SFilePage* bufPage = (SFilePage*)getBufPage(pBuf, pos->pageId);
|
||||
if (NULL == bufPage) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (forUpdate) {
|
||||
setBufPageDirty(bufPage, true);
|
||||
}
|
||||
|
|
|
@ -696,7 +696,7 @@ void cleanupExprSupp(SExprSupp* pSup);
|
|||
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs);
|
||||
|
||||
int32_t initAggSup(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize,
|
||||
const char* pkey);
|
||||
const char* pkey, void* pState);
|
||||
void cleanupAggSup(SAggSupporter* pAggSup);
|
||||
|
||||
void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows);
|
||||
|
@ -855,6 +855,8 @@ int32_t releaseOutputBuf(SStreamState* pState, SWinKey* pKey, SResultRow* pResul
|
|||
int32_t saveOutputBuf(SStreamState* pState, SWinKey* pKey, SResultRow* pResult, int32_t resSize);
|
||||
void getNextIntervalWindow(SInterval* pInterval, STimeWindow* tw, int32_t order);
|
||||
int32_t qAppendTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo);
|
||||
int32_t getForwardStepsInBlock(int32_t numOfRows, __block_search_fn_t searchFn, TSKEY ekey, int32_t pos,
|
||||
int32_t order, int64_t* pData);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
extern SDataSinkStat gDataSinkStat;
|
||||
|
||||
typedef struct SSubmitRes {
|
||||
int64_t affectedRows;
|
||||
int32_t code;
|
||||
int64_t affectedRows;
|
||||
int32_t code;
|
||||
SSubmitRsp2* pRsp;
|
||||
} SSubmitRes;
|
||||
|
||||
|
@ -41,6 +41,7 @@ typedef struct SDataInserterHandle {
|
|||
SHashObj* pCols;
|
||||
int32_t status;
|
||||
bool queryEnd;
|
||||
bool fullOrderColList;
|
||||
uint64_t useconds;
|
||||
uint64_t cachedSize;
|
||||
TdThreadMutex mutex;
|
||||
|
@ -84,7 +85,7 @@ int32_t inserterCallback(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
}
|
||||
|
||||
pInserter->submitRes.affectedRows += pInserter->submitRes.pRsp->affectedRows;
|
||||
qDebug("submit rsp received, affectedRows:%d, total:%"PRId64, pInserter->submitRes.pRsp->affectedRows,
|
||||
qDebug("submit rsp received, affectedRows:%d, total:%" PRId64, pInserter->submitRes.pRsp->affectedRows,
|
||||
pInserter->submitRes.affectedRows);
|
||||
tDecoderClear(&coder);
|
||||
taosMemoryFree(pInserter->submitRes.pRsp);
|
||||
|
@ -96,7 +97,8 @@ _return:
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t sendSubmitRequest(SDataInserterHandle* pInserter, void* pMsg, int32_t msgLen, void* pTransporter, SEpSet* pEpset) {
|
||||
static int32_t sendSubmitRequest(SDataInserterHandle* pInserter, void* pMsg, int32_t msgLen, void* pTransporter,
|
||||
SEpSet* pEpset) {
|
||||
// send the fetch remote task result reques
|
||||
SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (NULL == pMsgSendInfo) {
|
||||
|
@ -120,9 +122,9 @@ static int32_t sendSubmitRequest(SDataInserterHandle* pInserter, void* pMsg, int
|
|||
}
|
||||
|
||||
static int32_t submitReqToMsg(int32_t vgId, SSubmitReq2* pReq, void** pData, int32_t* pLen) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t len = 0;
|
||||
void* pBuf = NULL;
|
||||
void* pBuf = NULL;
|
||||
tEncodeSize(tEncodeSSubmitReq2, pReq, len, code);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SEncoder encoder;
|
||||
|
@ -147,13 +149,11 @@ static int32_t submitReqToMsg(int32_t vgId, SSubmitReq2* pReq, void** pData, int
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** ppReq, const SSDataBlock* pDataBlock, const STSchema* pTSchema,
|
||||
int64_t uid, int32_t vgId, tb_uid_t suid) {
|
||||
int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** ppReq, const SSDataBlock* pDataBlock,
|
||||
const STSchema* pTSchema, int64_t uid, int32_t vgId, tb_uid_t suid) {
|
||||
SSubmitReq2* pReq = *ppReq;
|
||||
SArray* pVals = NULL;
|
||||
int32_t numOfBlks = 0;
|
||||
bool fullCol = (pInserter->pNode->pCols->length == pTSchema->numOfCols);
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -194,9 +194,9 @@ int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** pp
|
|||
|
||||
int32_t offset = 0;
|
||||
for (int32_t k = 0; k < pTSchema->numOfCols; ++k) { // iterate by column
|
||||
int16_t colIdx = k;
|
||||
const STColumn* pCol = &pTSchema->columns[k];
|
||||
if (!fullCol) {
|
||||
int16_t colIdx = k;
|
||||
const STColumn* pCol = &pTSchema->columns[k];
|
||||
if (!pInserter->fullOrderColList) {
|
||||
int16_t* slotId = taosHashGet(pInserter->pCols, &pCol->colId, sizeof(pCol->colId));
|
||||
if (NULL == slotId) {
|
||||
continue;
|
||||
|
@ -204,7 +204,7 @@ int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** pp
|
|||
|
||||
colIdx = *slotId;
|
||||
}
|
||||
|
||||
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, colIdx);
|
||||
void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes);
|
||||
|
||||
|
@ -246,7 +246,7 @@ int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** pp
|
|||
lastTs = *(int64_t*)var;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SValue sv;
|
||||
memcpy(&sv.val, var, tDataTypes[pCol->type].bytes);
|
||||
SColVal cv = COL_VAL_VALUE(pCol->colId, pCol->type, sv);
|
||||
|
@ -268,7 +268,7 @@ int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** pp
|
|||
ignoreRow = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
SRow* pRow = NULL;
|
||||
if ((terrno = tRowBuild(pVals, pTSchema, &pRow)) < 0) {
|
||||
tDestroySSubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
|
||||
|
@ -286,7 +286,6 @@ int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** pp
|
|||
|
||||
taosArrayPush(pReq->aSubmitTbData, &tbData);
|
||||
|
||||
|
||||
_end:
|
||||
taosArrayDestroy(pVals);
|
||||
if (terrno != 0) {
|
||||
|
@ -301,7 +300,6 @@ _end:
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t dataBlocksToSubmitReq(SDataInserterHandle* pInserter, void** pMsg, int32_t* msgLen) {
|
||||
const SArray* pBlocks = pInserter->pDataBlocks;
|
||||
const STSchema* pTSchema = pInserter->pSchema;
|
||||
|
@ -310,7 +308,7 @@ int32_t dataBlocksToSubmitReq(SDataInserterHandle* pInserter, void** pMsg, int32
|
|||
int32_t vgId = pInserter->pNode->vgId;
|
||||
int32_t sz = taosArrayGetSize(pBlocks);
|
||||
int32_t code = 0;
|
||||
SSubmitReq2 *pReq = NULL;
|
||||
SSubmitReq2* pReq = NULL;
|
||||
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SSDataBlock* pDataBlock = taosArrayGetP(pBlocks, i);
|
||||
|
@ -329,23 +327,24 @@ int32_t dataBlocksToSubmitReq(SDataInserterHandle* pInserter, void** pMsg, int32
|
|||
code = submitReqToMsg(vgId, pReq, pMsg, msgLen);
|
||||
tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
|
||||
taosMemoryFree(pReq);
|
||||
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) {
|
||||
SDataInserterHandle* pInserter = (SDataInserterHandle*)pHandle;
|
||||
taosArrayPush(pInserter->pDataBlocks, &pInput->pData);
|
||||
void* pMsg = NULL;
|
||||
void* pMsg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t code = dataBlocksToSubmitReq(pInserter, &pMsg, &msgLen);
|
||||
int32_t code = dataBlocksToSubmitReq(pInserter, &pMsg, &msgLen);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
taosArrayClear(pInserter->pDataBlocks);
|
||||
|
||||
code = sendSubmitRequest(pInserter, pMsg, msgLen, pInserter->pParam->readHandle->pMsgCb->clientRpc, &pInserter->pNode->epSet);
|
||||
|
||||
code = sendSubmitRequest(pInserter, pMsg, msgLen, pInserter->pParam->readHandle->pMsgCb->clientRpc,
|
||||
&pInserter->pNode->epSet);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
@ -439,12 +438,19 @@ int32_t createDataInserter(SDataSinkManager* pManager, const SDataSinkNode* pDat
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
inserter->fullOrderColList = pInserterNode->pCols->length == inserter->pSchema->numOfCols;
|
||||
|
||||
inserter->pCols = taosHashInit(pInserterNode->pCols->length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_SMALLINT),
|
||||
false, HASH_NO_LOCK);
|
||||
SNode* pNode = NULL;
|
||||
SNode* pNode = NULL;
|
||||
int32_t i = 0;
|
||||
FOREACH(pNode, pInserterNode->pCols) {
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
taosHashPut(inserter->pCols, &pCol->colId, sizeof(pCol->colId), &pCol->slotId, sizeof(pCol->slotId));
|
||||
if (inserter->fullOrderColList && pCol->colId != inserter->pSchema->columns[i].colId) {
|
||||
inserter->fullOrderColList = false;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
tsem_init(&inserter->ready, 0, 0);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue