Merge branch '3.0' of github.com:taosdata/TDengine into TEST/3.0/TS-4421
This commit is contained in:
commit
fc75258548
|
@ -29,6 +29,7 @@ extern "C" {
|
|||
#define TSDB_INS_TABLE_QNODES "ins_qnodes"
|
||||
#define TSDB_INS_TABLE_BNODES "ins_bnodes" // no longer used
|
||||
#define TSDB_INS_TABLE_SNODES "ins_snodes"
|
||||
#define TSDB_INS_TABLE_ARBGROUPS "ins_arbgroups"
|
||||
#define TSDB_INS_TABLE_CLUSTER "ins_cluster"
|
||||
#define TSDB_INS_TABLE_DATABASES "ins_databases"
|
||||
#define TSDB_INS_TABLE_FUNCTIONS "ins_functions"
|
||||
|
|
|
@ -76,6 +76,11 @@ extern int32_t tsHeartbeatInterval;
|
|||
extern int32_t tsHeartbeatTimeout;
|
||||
extern int32_t tsSnapReplMaxWaitN;
|
||||
|
||||
// arbitrator
|
||||
extern int32_t tsArbHeartBeatIntervalSec;
|
||||
extern int32_t tsArbCheckSyncIntervalSec;
|
||||
extern int32_t tsArbSetAssignedTimeoutSec;
|
||||
|
||||
// vnode
|
||||
extern int64_t tsVndCommitMaxIntervalMs;
|
||||
|
||||
|
|
|
@ -61,9 +61,6 @@ typedef enum {
|
|||
int32_t grantCheck(EGrantType grant);
|
||||
int32_t grantCheckExpire(EGrantType grant);
|
||||
char* tGetMachineId();
|
||||
#ifdef TD_UNIQ_GRANT
|
||||
int32_t grantCheckLE(EGrantType grant);
|
||||
#endif
|
||||
|
||||
// #ifndef GRANTS_CFG
|
||||
#ifdef TD_ENTERPRISE
|
||||
|
@ -76,7 +73,7 @@ int32_t grantCheckLE(EGrantType grant);
|
|||
{.name = "state", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
|
||||
{.name = "timeseries", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
|
||||
{.name = "dnodes", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
|
||||
{.name = "cpu_cores", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
|
||||
{.name = "cpu_cores", .bytes = 13 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
|
||||
}
|
||||
#else
|
||||
#define GRANTS_SCHEMA \
|
||||
|
@ -88,7 +85,7 @@ int32_t grantCheckLE(EGrantType grant);
|
|||
{.name = "state", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
|
||||
{.name = "timeseries", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
|
||||
{.name = "dnodes", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
|
||||
{.name = "cpu_cores", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
|
||||
{.name = "cpu_cores", .bytes = 13 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, \
|
||||
}
|
||||
#endif
|
||||
// #define GRANT_CFG_ADD
|
||||
|
|
|
@ -150,6 +150,7 @@ typedef enum _mgmt_table {
|
|||
TSDB_MGMT_TABLE_GRANTS_FULL,
|
||||
TSDB_MGMT_TABLE_GRANTS_LOGS,
|
||||
TSDB_MGMT_TABLE_MACHINES,
|
||||
TSDB_MGMT_TABLE_ARBGROUP,
|
||||
TSDB_MGMT_TABLE_MAX,
|
||||
} EShowType;
|
||||
|
||||
|
@ -336,6 +337,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_SHOW_QNODES_STMT,
|
||||
QUERY_NODE_SHOW_SNODES_STMT,
|
||||
QUERY_NODE_SHOW_BNODES_STMT,
|
||||
QUERY_NODE_SHOW_ARBGROUPS_STMT,
|
||||
QUERY_NODE_SHOW_CLUSTER_STMT,
|
||||
QUERY_NODE_SHOW_DATABASES_STMT,
|
||||
QUERY_NODE_SHOW_FUNCTIONS_STMT,
|
||||
|
@ -1152,6 +1154,7 @@ typedef struct {
|
|||
int32_t tsdbPageSize;
|
||||
int32_t sqlLen;
|
||||
char* sql;
|
||||
int8_t withArbitrator;
|
||||
} SCreateDbReq;
|
||||
|
||||
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
|
||||
|
@ -1180,6 +1183,7 @@ typedef struct {
|
|||
int32_t walRetentionSize;
|
||||
int32_t sqlLen;
|
||||
char* sql;
|
||||
int8_t withArbitrator;
|
||||
} SAlterDbReq;
|
||||
|
||||
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
|
||||
|
@ -1302,6 +1306,7 @@ typedef struct {
|
|||
SArray* pRetensions;
|
||||
int8_t schemaless;
|
||||
int16_t sstTrigger;
|
||||
int8_t withArbitrator;
|
||||
} SDbCfgRsp;
|
||||
|
||||
typedef SDbCfgRsp SDbCfgInfo;
|
||||
|
@ -2145,6 +2150,99 @@ typedef struct {
|
|||
int32_t tSerializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
|
||||
int32_t tDeserializeSDCreateMnodeReq(void* buf, int32_t bufLen, SDCreateMnodeReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int32_t hbSeq;
|
||||
} SVArbHbReqMember;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
char* arbToken;
|
||||
int64_t arbTerm;
|
||||
SArray* hbMembers; // SVArbHbReqMember
|
||||
} SVArbHeartBeatReq;
|
||||
|
||||
int32_t tSerializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
|
||||
int32_t tDeserializeSVArbHeartBeatReq(void* buf, int32_t bufLen, SVArbHeartBeatReq* pReq);
|
||||
void tFreeSVArbHeartBeatReq(SVArbHeartBeatReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
char memberToken[TSDB_ARB_TOKEN_SIZE];
|
||||
int32_t hbSeq;
|
||||
} SVArbHbRspMember;
|
||||
|
||||
typedef struct {
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
int32_t dnodeId;
|
||||
SArray* hbMembers; // SVArbHbRspMember
|
||||
} SVArbHeartBeatRsp;
|
||||
|
||||
int32_t tSerializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
|
||||
int32_t tDeserializeSVArbHeartBeatRsp(void* buf, int32_t bufLen, SVArbHeartBeatRsp* pRsp);
|
||||
void tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp* pRsp);
|
||||
|
||||
typedef struct {
|
||||
char* arbToken;
|
||||
int64_t arbTerm;
|
||||
char* member0Token;
|
||||
char* member1Token;
|
||||
} SVArbCheckSyncReq;
|
||||
|
||||
int32_t tSerializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
|
||||
int32_t tDeserializeSVArbCheckSyncReq(void* buf, int32_t bufLen, SVArbCheckSyncReq* pReq);
|
||||
void tFreeSVArbCheckSyncReq(SVArbCheckSyncReq* pRsp);
|
||||
|
||||
typedef struct {
|
||||
char* arbToken;
|
||||
char* member0Token;
|
||||
char* member1Token;
|
||||
int32_t vgId;
|
||||
int32_t errCode;
|
||||
} SVArbCheckSyncRsp;
|
||||
|
||||
int32_t tSerializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
|
||||
int32_t tDeserializeSVArbCheckSyncRsp(void* buf, int32_t bufLen, SVArbCheckSyncRsp* pRsp);
|
||||
void tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp* pRsp);
|
||||
|
||||
typedef struct {
|
||||
char* arbToken;
|
||||
int64_t arbTerm;
|
||||
char* memberToken;
|
||||
} SVArbSetAssignedLeaderReq;
|
||||
|
||||
int32_t tSerializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
|
||||
int32_t tDeserializeSVArbSetAssignedLeaderReq(void* buf, int32_t bufLen, SVArbSetAssignedLeaderReq* pReq);
|
||||
void tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
char* arbToken;
|
||||
char* memberToken;
|
||||
int32_t vgId;
|
||||
} SVArbSetAssignedLeaderRsp;
|
||||
|
||||
int32_t tSerializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
|
||||
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void* buf, int32_t bufLen, SVArbSetAssignedLeaderRsp* pRsp);
|
||||
void tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp* pRsp);
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
char* token;
|
||||
} SMArbUpdateGroupReqMember;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int64_t dbUid;
|
||||
SMArbUpdateGroupReqMember members[2];
|
||||
int8_t isSync;
|
||||
SMArbUpdateGroupReqMember assignedLeader;
|
||||
int64_t version;
|
||||
} SMArbUpdateGroupReq;
|
||||
|
||||
int32_t tSerializeSMArbUpdateGroupReq(void* buf, int32_t bufLen, SMArbUpdateGroupReq* pReq);
|
||||
int32_t tDeserializeSMArbUpdateGroupReq(void* buf, int32_t bufLen, SMArbUpdateGroupReq* pReq);
|
||||
void tFreeSMArbUpdateGroupReq(SMArbUpdateGroupReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
char queryStrId[TSDB_QUERY_ID_LEN];
|
||||
} SKillQueryReq;
|
||||
|
@ -3921,11 +4019,11 @@ int32_t tSerializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
|||
int32_t tDeserializeSMqAskEpReq(void* buf, int32_t bufLen, SMqAskEpReq* pReq);
|
||||
int32_t tSerializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||
int32_t tDeserializeSMqHbReq(void* buf, int32_t bufLen, SMqHbReq* pReq);
|
||||
int32_t tDeatroySMqHbReq(SMqHbReq* pReq);
|
||||
void tDestroySMqHbReq(SMqHbReq* pReq);
|
||||
|
||||
int32_t tSerializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
|
||||
int32_t tDeserializeSMqHbRsp(void* buf, int32_t bufLen, SMqHbRsp* pRsp);
|
||||
int32_t tDeatroySMqHbRsp(SMqHbRsp* pRsp);
|
||||
void tDestroySMqHbRsp(SMqHbRsp* pRsp);
|
||||
|
||||
int32_t tSerializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
|
||||
int32_t tDeserializeSMqSeekReq(void* buf, int32_t bufLen, SMqSeekReq* pReq);
|
||||
|
|
|
@ -36,9 +36,11 @@ typedef enum {
|
|||
SYNC_QUEUE,
|
||||
SYNC_RD_QUEUE,
|
||||
STREAM_QUEUE,
|
||||
ARB_QUEUE,
|
||||
QUEUE_MAX,
|
||||
} EQueueType;
|
||||
|
||||
typedef void (*GetDnodeEp)(void* pData, int32_t dnodeId, char* pEp, char* pFqdn, uint16_t* pPort);
|
||||
typedef bool (*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);
|
||||
|
@ -64,6 +66,7 @@ typedef struct {
|
|||
ReleaseHandleFp releaseHandleFp;
|
||||
ReportStartup reportStartupFp;
|
||||
UpdateDnodeInfoFp updateDnodeInfoFp;
|
||||
GetDnodeEp getDnodeEpFp;
|
||||
} SMsgCb;
|
||||
|
||||
void tmsgSetDefault(const SMsgCb* msgcb);
|
||||
|
|
|
@ -272,6 +272,8 @@
|
|||
TD_DEF_MSG_TYPE(TDMT_VND_DISABLE_WRITE, "vnode-disable-write", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_QUERY_COMPACT_PROGRESS, "vnode-query-compact-progress", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_KILL_COMPACT, "kill-compact", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_ARB_HEARTBEAT, "vnode-arb-hb", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_ARB_CHECK_SYNC, "vnode-arb-check-sync", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MAX_MSG, "vnd-max", NULL, NULL)
|
||||
TD_CLOSE_MSG_SEG(TDMT_END_VND_MSG)
|
||||
|
||||
|
@ -341,6 +343,7 @@
|
|||
TD_DEF_MSG_TYPE(TDMT_SYNC_PREP_SNAPSHOT_REPLY, "sync-prep-snapshot-reply", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_UNUSED_CODE, "sync-unused", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_FORCE_FOLLOWER, "sync-force-become-follower", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_SET_ASSIGNED_LEADER, "sync-set-assigned-leader", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_SYNC_MAX_MSG, "sync-max", NULL, NULL)
|
||||
TD_CLOSE_MSG_SEG(TDMT_END_SYNC_MSG)
|
||||
|
||||
|
@ -367,6 +370,13 @@
|
|||
TD_DEF_MSG_TYPE(TDMT_VND_TMQ_MAX_MSG, "vnd-tmq-max", NULL, NULL)
|
||||
TD_CLOSE_MSG_SEG(TDMT_END_TMQ_MSG)
|
||||
|
||||
TD_NEW_MSG_SEG(TDMT_MND_ARB_MSG) //9 << 8
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_ARB_HEARTBEAT_TIMER, "mnd-arb-hb-tmr", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_ARB_CHECK_SYNC_TIMER, "mnd-arb-check-sync-tmr", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_ARB_UPDATE_GROUP, "mnd-arb-update-group", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_ARB_MAX_MSG, "mnd-arb-max", NULL, NULL)
|
||||
TD_CLOSE_MSG_SEG(TDMT_END_ARB_MSG)
|
||||
|
||||
TD_NEW_MSG_SEG(TDMT_MAX_MSG) // msg end mark
|
||||
TD_CLOSE_MSG_SEG(TDMT_END_MAX_MSG)
|
||||
|
||||
|
|
|
@ -168,208 +168,208 @@
|
|||
#define TK_STABLES 149
|
||||
#define TK_MNODES 150
|
||||
#define TK_QNODES 151
|
||||
#define TK_FUNCTIONS 152
|
||||
#define TK_INDEXES 153
|
||||
#define TK_ACCOUNTS 154
|
||||
#define TK_APPS 155
|
||||
#define TK_CONNECTIONS 156
|
||||
#define TK_LICENCES 157
|
||||
#define TK_GRANTS 158
|
||||
#define TK_FULL 159
|
||||
#define TK_LOGS 160
|
||||
#define TK_MACHINES 161
|
||||
#define TK_QUERIES 162
|
||||
#define TK_SCORES 163
|
||||
#define TK_TOPICS 164
|
||||
#define TK_VARIABLES 165
|
||||
#define TK_BNODES 166
|
||||
#define TK_SNODES 167
|
||||
#define TK_TRANSACTIONS 168
|
||||
#define TK_DISTRIBUTED 169
|
||||
#define TK_CONSUMERS 170
|
||||
#define TK_SUBSCRIPTIONS 171
|
||||
#define TK_VNODES 172
|
||||
#define TK_ALIVE 173
|
||||
#define TK_VIEWS 174
|
||||
#define TK_VIEW 175
|
||||
#define TK_COMPACTS 176
|
||||
#define TK_NORMAL 177
|
||||
#define TK_CHILD 178
|
||||
#define TK_LIKE 179
|
||||
#define TK_TBNAME 180
|
||||
#define TK_QTAGS 181
|
||||
#define TK_AS 182
|
||||
#define TK_SYSTEM 183
|
||||
#define TK_INDEX 184
|
||||
#define TK_FUNCTION 185
|
||||
#define TK_INTERVAL 186
|
||||
#define TK_COUNT 187
|
||||
#define TK_LAST_ROW 188
|
||||
#define TK_META 189
|
||||
#define TK_ONLY 190
|
||||
#define TK_TOPIC 191
|
||||
#define TK_CONSUMER 192
|
||||
#define TK_GROUP 193
|
||||
#define TK_DESC 194
|
||||
#define TK_DESCRIBE 195
|
||||
#define TK_RESET 196
|
||||
#define TK_QUERY 197
|
||||
#define TK_CACHE 198
|
||||
#define TK_EXPLAIN 199
|
||||
#define TK_ANALYZE 200
|
||||
#define TK_VERBOSE 201
|
||||
#define TK_NK_BOOL 202
|
||||
#define TK_RATIO 203
|
||||
#define TK_NK_FLOAT 204
|
||||
#define TK_OUTPUTTYPE 205
|
||||
#define TK_AGGREGATE 206
|
||||
#define TK_BUFSIZE 207
|
||||
#define TK_LANGUAGE 208
|
||||
#define TK_REPLACE 209
|
||||
#define TK_STREAM 210
|
||||
#define TK_INTO 211
|
||||
#define TK_PAUSE 212
|
||||
#define TK_RESUME 213
|
||||
#define TK_TRIGGER 214
|
||||
#define TK_AT_ONCE 215
|
||||
#define TK_WINDOW_CLOSE 216
|
||||
#define TK_IGNORE 217
|
||||
#define TK_EXPIRED 218
|
||||
#define TK_FILL_HISTORY 219
|
||||
#define TK_UPDATE 220
|
||||
#define TK_SUBTABLE 221
|
||||
#define TK_UNTREATED 222
|
||||
#define TK_KILL 223
|
||||
#define TK_CONNECTION 224
|
||||
#define TK_TRANSACTION 225
|
||||
#define TK_BALANCE 226
|
||||
#define TK_VGROUP 227
|
||||
#define TK_LEADER 228
|
||||
#define TK_MERGE 229
|
||||
#define TK_REDISTRIBUTE 230
|
||||
#define TK_SPLIT 231
|
||||
#define TK_DELETE 232
|
||||
#define TK_INSERT 233
|
||||
#define TK_NK_BIN 234
|
||||
#define TK_NK_HEX 235
|
||||
#define TK_NULL 236
|
||||
#define TK_NK_QUESTION 237
|
||||
#define TK_NK_ALIAS 238
|
||||
#define TK_NK_ARROW 239
|
||||
#define TK_ROWTS 240
|
||||
#define TK_QSTART 241
|
||||
#define TK_QEND 242
|
||||
#define TK_QDURATION 243
|
||||
#define TK_WSTART 244
|
||||
#define TK_WEND 245
|
||||
#define TK_WDURATION 246
|
||||
#define TK_IROWTS 247
|
||||
#define TK_ISFILLED 248
|
||||
#define TK_CAST 249
|
||||
#define TK_NOW 250
|
||||
#define TK_TODAY 251
|
||||
#define TK_TIMEZONE 252
|
||||
#define TK_CLIENT_VERSION 253
|
||||
#define TK_SERVER_VERSION 254
|
||||
#define TK_SERVER_STATUS 255
|
||||
#define TK_CURRENT_USER 256
|
||||
#define TK_CASE 257
|
||||
#define TK_WHEN 258
|
||||
#define TK_THEN 259
|
||||
#define TK_ELSE 260
|
||||
#define TK_BETWEEN 261
|
||||
#define TK_IS 262
|
||||
#define TK_NK_LT 263
|
||||
#define TK_NK_GT 264
|
||||
#define TK_NK_LE 265
|
||||
#define TK_NK_GE 266
|
||||
#define TK_NK_NE 267
|
||||
#define TK_MATCH 268
|
||||
#define TK_NMATCH 269
|
||||
#define TK_CONTAINS 270
|
||||
#define TK_IN 271
|
||||
#define TK_JOIN 272
|
||||
#define TK_INNER 273
|
||||
#define TK_SELECT 274
|
||||
#define TK_NK_HINT 275
|
||||
#define TK_DISTINCT 276
|
||||
#define TK_WHERE 277
|
||||
#define TK_PARTITION 278
|
||||
#define TK_BY 279
|
||||
#define TK_SESSION 280
|
||||
#define TK_STATE_WINDOW 281
|
||||
#define TK_EVENT_WINDOW 282
|
||||
#define TK_COUNT_WINDOW 283
|
||||
#define TK_SLIDING 284
|
||||
#define TK_FILL 285
|
||||
#define TK_VALUE 286
|
||||
#define TK_VALUE_F 287
|
||||
#define TK_NONE 288
|
||||
#define TK_PREV 289
|
||||
#define TK_NULL_F 290
|
||||
#define TK_LINEAR 291
|
||||
#define TK_NEXT 292
|
||||
#define TK_HAVING 293
|
||||
#define TK_RANGE 294
|
||||
#define TK_EVERY 295
|
||||
#define TK_ORDER 296
|
||||
#define TK_SLIMIT 297
|
||||
#define TK_SOFFSET 298
|
||||
#define TK_LIMIT 299
|
||||
#define TK_OFFSET 300
|
||||
#define TK_ASC 301
|
||||
#define TK_NULLS 302
|
||||
#define TK_ABORT 303
|
||||
#define TK_AFTER 304
|
||||
#define TK_ATTACH 305
|
||||
#define TK_BEFORE 306
|
||||
#define TK_BEGIN 307
|
||||
#define TK_BITAND 308
|
||||
#define TK_BITNOT 309
|
||||
#define TK_BITOR 310
|
||||
#define TK_BLOCKS 311
|
||||
#define TK_CHANGE 312
|
||||
#define TK_COMMA 313
|
||||
#define TK_CONCAT 314
|
||||
#define TK_CONFLICT 315
|
||||
#define TK_COPY 316
|
||||
#define TK_DEFERRED 317
|
||||
#define TK_DELIMITERS 318
|
||||
#define TK_DETACH 319
|
||||
#define TK_DIVIDE 320
|
||||
#define TK_DOT 321
|
||||
#define TK_EACH 322
|
||||
#define TK_FAIL 323
|
||||
#define TK_FILE 324
|
||||
#define TK_FOR 325
|
||||
#define TK_GLOB 326
|
||||
#define TK_ID 327
|
||||
#define TK_IMMEDIATE 328
|
||||
#define TK_IMPORT 329
|
||||
#define TK_INITIALLY 330
|
||||
#define TK_INSTEAD 331
|
||||
#define TK_ISNULL 332
|
||||
#define TK_KEY 333
|
||||
#define TK_MODULES 334
|
||||
#define TK_NK_BITNOT 335
|
||||
#define TK_NK_SEMI 336
|
||||
#define TK_NOTNULL 337
|
||||
#define TK_OF 338
|
||||
#define TK_PLUS 339
|
||||
#define TK_PRIVILEGE 340
|
||||
#define TK_RAISE 341
|
||||
#define TK_RESTRICT 342
|
||||
#define TK_ROW 343
|
||||
#define TK_SEMI 344
|
||||
#define TK_STAR 345
|
||||
#define TK_STATEMENT 346
|
||||
#define TK_STRICT 347
|
||||
#define TK_STRING 348
|
||||
#define TK_TIMES 349
|
||||
#define TK_VALUES 350
|
||||
#define TK_VARIABLE 351
|
||||
#define TK_WAL 352
|
||||
|
||||
#define TK_ARBGROUPS 152
|
||||
#define TK_FUNCTIONS 153
|
||||
#define TK_INDEXES 154
|
||||
#define TK_ACCOUNTS 155
|
||||
#define TK_APPS 156
|
||||
#define TK_CONNECTIONS 157
|
||||
#define TK_LICENCES 158
|
||||
#define TK_GRANTS 159
|
||||
#define TK_FULL 160
|
||||
#define TK_LOGS 161
|
||||
#define TK_MACHINES 162
|
||||
#define TK_QUERIES 163
|
||||
#define TK_SCORES 164
|
||||
#define TK_TOPICS 165
|
||||
#define TK_VARIABLES 166
|
||||
#define TK_BNODES 167
|
||||
#define TK_SNODES 168
|
||||
#define TK_TRANSACTIONS 169
|
||||
#define TK_DISTRIBUTED 170
|
||||
#define TK_CONSUMERS 171
|
||||
#define TK_SUBSCRIPTIONS 172
|
||||
#define TK_VNODES 173
|
||||
#define TK_ALIVE 174
|
||||
#define TK_VIEWS 175
|
||||
#define TK_VIEW 176
|
||||
#define TK_COMPACTS 177
|
||||
#define TK_NORMAL 178
|
||||
#define TK_CHILD 179
|
||||
#define TK_LIKE 180
|
||||
#define TK_TBNAME 181
|
||||
#define TK_QTAGS 182
|
||||
#define TK_AS 183
|
||||
#define TK_SYSTEM 184
|
||||
#define TK_INDEX 185
|
||||
#define TK_FUNCTION 186
|
||||
#define TK_INTERVAL 187
|
||||
#define TK_COUNT 188
|
||||
#define TK_LAST_ROW 189
|
||||
#define TK_META 190
|
||||
#define TK_ONLY 191
|
||||
#define TK_TOPIC 192
|
||||
#define TK_CONSUMER 193
|
||||
#define TK_GROUP 194
|
||||
#define TK_DESC 195
|
||||
#define TK_DESCRIBE 196
|
||||
#define TK_RESET 197
|
||||
#define TK_QUERY 198
|
||||
#define TK_CACHE 199
|
||||
#define TK_EXPLAIN 200
|
||||
#define TK_ANALYZE 201
|
||||
#define TK_VERBOSE 202
|
||||
#define TK_NK_BOOL 203
|
||||
#define TK_RATIO 204
|
||||
#define TK_NK_FLOAT 205
|
||||
#define TK_OUTPUTTYPE 206
|
||||
#define TK_AGGREGATE 207
|
||||
#define TK_BUFSIZE 208
|
||||
#define TK_LANGUAGE 209
|
||||
#define TK_REPLACE 210
|
||||
#define TK_STREAM 211
|
||||
#define TK_INTO 212
|
||||
#define TK_PAUSE 213
|
||||
#define TK_RESUME 214
|
||||
#define TK_TRIGGER 215
|
||||
#define TK_AT_ONCE 216
|
||||
#define TK_WINDOW_CLOSE 217
|
||||
#define TK_IGNORE 218
|
||||
#define TK_EXPIRED 219
|
||||
#define TK_FILL_HISTORY 220
|
||||
#define TK_UPDATE 221
|
||||
#define TK_SUBTABLE 222
|
||||
#define TK_UNTREATED 223
|
||||
#define TK_KILL 224
|
||||
#define TK_CONNECTION 225
|
||||
#define TK_TRANSACTION 226
|
||||
#define TK_BALANCE 227
|
||||
#define TK_VGROUP 228
|
||||
#define TK_LEADER 229
|
||||
#define TK_MERGE 230
|
||||
#define TK_REDISTRIBUTE 231
|
||||
#define TK_SPLIT 232
|
||||
#define TK_DELETE 233
|
||||
#define TK_INSERT 234
|
||||
#define TK_NK_BIN 235
|
||||
#define TK_NK_HEX 236
|
||||
#define TK_NULL 237
|
||||
#define TK_NK_QUESTION 238
|
||||
#define TK_NK_ALIAS 239
|
||||
#define TK_NK_ARROW 240
|
||||
#define TK_ROWTS 241
|
||||
#define TK_QSTART 242
|
||||
#define TK_QEND 243
|
||||
#define TK_QDURATION 244
|
||||
#define TK_WSTART 245
|
||||
#define TK_WEND 246
|
||||
#define TK_WDURATION 247
|
||||
#define TK_IROWTS 248
|
||||
#define TK_ISFILLED 249
|
||||
#define TK_CAST 250
|
||||
#define TK_NOW 251
|
||||
#define TK_TODAY 252
|
||||
#define TK_TIMEZONE 253
|
||||
#define TK_CLIENT_VERSION 254
|
||||
#define TK_SERVER_VERSION 255
|
||||
#define TK_SERVER_STATUS 256
|
||||
#define TK_CURRENT_USER 257
|
||||
#define TK_CASE 258
|
||||
#define TK_WHEN 259
|
||||
#define TK_THEN 260
|
||||
#define TK_ELSE 261
|
||||
#define TK_BETWEEN 262
|
||||
#define TK_IS 263
|
||||
#define TK_NK_LT 264
|
||||
#define TK_NK_GT 265
|
||||
#define TK_NK_LE 266
|
||||
#define TK_NK_GE 267
|
||||
#define TK_NK_NE 268
|
||||
#define TK_MATCH 269
|
||||
#define TK_NMATCH 270
|
||||
#define TK_CONTAINS 271
|
||||
#define TK_IN 272
|
||||
#define TK_JOIN 273
|
||||
#define TK_INNER 274
|
||||
#define TK_SELECT 275
|
||||
#define TK_NK_HINT 276
|
||||
#define TK_DISTINCT 277
|
||||
#define TK_WHERE 278
|
||||
#define TK_PARTITION 279
|
||||
#define TK_BY 280
|
||||
#define TK_SESSION 281
|
||||
#define TK_STATE_WINDOW 282
|
||||
#define TK_EVENT_WINDOW 283
|
||||
#define TK_COUNT_WINDOW 284
|
||||
#define TK_SLIDING 285
|
||||
#define TK_FILL 286
|
||||
#define TK_VALUE 287
|
||||
#define TK_VALUE_F 288
|
||||
#define TK_NONE 289
|
||||
#define TK_PREV 290
|
||||
#define TK_NULL_F 291
|
||||
#define TK_LINEAR 292
|
||||
#define TK_NEXT 293
|
||||
#define TK_HAVING 294
|
||||
#define TK_RANGE 295
|
||||
#define TK_EVERY 296
|
||||
#define TK_ORDER 297
|
||||
#define TK_SLIMIT 298
|
||||
#define TK_SOFFSET 299
|
||||
#define TK_LIMIT 300
|
||||
#define TK_OFFSET 301
|
||||
#define TK_ASC 302
|
||||
#define TK_NULLS 303
|
||||
#define TK_ABORT 304
|
||||
#define TK_AFTER 305
|
||||
#define TK_ATTACH 306
|
||||
#define TK_BEFORE 307
|
||||
#define TK_BEGIN 308
|
||||
#define TK_BITAND 309
|
||||
#define TK_BITNOT 310
|
||||
#define TK_BITOR 311
|
||||
#define TK_BLOCKS 312
|
||||
#define TK_CHANGE 313
|
||||
#define TK_COMMA 314
|
||||
#define TK_CONCAT 315
|
||||
#define TK_CONFLICT 316
|
||||
#define TK_COPY 317
|
||||
#define TK_DEFERRED 318
|
||||
#define TK_DELIMITERS 319
|
||||
#define TK_DETACH 320
|
||||
#define TK_DIVIDE 321
|
||||
#define TK_DOT 322
|
||||
#define TK_EACH 323
|
||||
#define TK_FAIL 324
|
||||
#define TK_FILE 325
|
||||
#define TK_FOR 326
|
||||
#define TK_GLOB 327
|
||||
#define TK_ID 328
|
||||
#define TK_IMMEDIATE 329
|
||||
#define TK_IMPORT 330
|
||||
#define TK_INITIALLY 331
|
||||
#define TK_INSTEAD 332
|
||||
#define TK_ISNULL 333
|
||||
#define TK_KEY 334
|
||||
#define TK_MODULES 335
|
||||
#define TK_NK_BITNOT 336
|
||||
#define TK_NK_SEMI 337
|
||||
#define TK_NOTNULL 338
|
||||
#define TK_OF 339
|
||||
#define TK_PLUS 340
|
||||
#define TK_PRIVILEGE 341
|
||||
#define TK_RAISE 342
|
||||
#define TK_RESTRICT 343
|
||||
#define TK_ROW 344
|
||||
#define TK_SEMI 345
|
||||
#define TK_STAR 346
|
||||
#define TK_STATEMENT 347
|
||||
#define TK_STRICT 348
|
||||
#define TK_STRING 349
|
||||
#define TK_TIMES 350
|
||||
#define TK_VALUES 351
|
||||
#define TK_VARIABLE 352
|
||||
#define TK_WAL 353
|
||||
|
||||
#define TK_NK_SPACE 600
|
||||
#define TK_NK_COMMENT 601
|
||||
|
|
|
@ -75,6 +75,9 @@ void mndStop(SMnode *pMnode);
|
|||
|
||||
int32_t mndIsCatchUp(SMnode *pMnode);
|
||||
ESyncRole mndGetRole(SMnode *pMnode);
|
||||
int64_t mndGetTerm(SMnode *pMnode);
|
||||
|
||||
int32_t mndGetArbToken(SMnode *pMnode, char *outToken);
|
||||
|
||||
/**
|
||||
* @brief Get mnode monitor info.
|
||||
|
|
|
@ -100,6 +100,7 @@ typedef struct SDatabaseOptions {
|
|||
int32_t sstTrigger;
|
||||
int32_t tablePrefix;
|
||||
int32_t tableSuffix;
|
||||
int8_t withArbitrator;
|
||||
} SDatabaseOptions;
|
||||
|
||||
typedef struct SCreateDatabaseStmt {
|
||||
|
|
|
@ -80,6 +80,7 @@ typedef enum {
|
|||
TAOS_SYNC_STATE_LEADER = 102,
|
||||
TAOS_SYNC_STATE_ERROR = 103,
|
||||
TAOS_SYNC_STATE_LEARNER = 104,
|
||||
TAOS_SYNC_STATE_ASSIGNED_LEADER = 105,
|
||||
} ESyncState;
|
||||
|
||||
typedef enum {
|
||||
|
@ -184,6 +185,7 @@ typedef struct SSyncFSM {
|
|||
void (*FpBecomeLeaderCb)(const struct SSyncFSM* pFsm);
|
||||
void (*FpBecomeFollowerCb)(const struct SSyncFSM* pFsm);
|
||||
void (*FpBecomeLearnerCb)(const struct SSyncFSM* pFsm);
|
||||
void (*FpBecomeAssignedLeaderCb)(const struct SSyncFSM* pFsm);
|
||||
|
||||
int32_t (*FpGetSnapshot)(const struct SSyncFSM* pFsm, SSnapshot* pSnapshot, void* pReaderParam, void** ppReader);
|
||||
int32_t (*FpGetSnapshotInfo)(const struct SSyncFSM* pFsm, SSnapshot* pSnapshot);
|
||||
|
@ -273,6 +275,7 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak, int64_t* seq);
|
|||
int32_t syncCheckMember(int64_t rid);
|
||||
int32_t syncIsCatchUp(int64_t rid);
|
||||
ESyncRole syncGetRole(int64_t rid);
|
||||
int64_t syncGetTerm(int64_t rid);
|
||||
int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg);
|
||||
int32_t syncReconfig(int64_t rid, SSyncCfg* pCfg);
|
||||
int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex);
|
||||
|
@ -284,8 +287,13 @@ bool syncSnapshotSending(int64_t rid);
|
|||
bool syncSnapshotRecving(int64_t rid);
|
||||
int32_t syncSendTimeoutRsp(int64_t rid, int64_t seq);
|
||||
int32_t syncForceBecomeFollower(SSyncNode* ths, const SRpcMsg* pRpcMsg);
|
||||
int32_t syncBecomeAssignedLeader(SSyncNode* ths, SRpcMsg* pRpcMsg);
|
||||
|
||||
int32_t syncUpdateArbTerm(int64_t rid, SyncTerm arbTerm);
|
||||
|
||||
SSyncState syncGetState(int64_t rid);
|
||||
int32_t syncGetArbToken(int64_t rid, char* outToken);
|
||||
int32_t syncGetAssignedLogSynced(int64_t rid);
|
||||
void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet);
|
||||
const char* syncStr(ESyncState state);
|
||||
|
||||
|
|
|
@ -323,6 +323,9 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_BNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A7)
|
||||
#define TSDB_CODE_MND_TOO_FEW_MNODES TAOS_DEF_ERROR_CODE(0, 0x03A8)
|
||||
#define TSDB_CODE_MND_TOO_MANY_MNODES TAOS_DEF_ERROR_CODE(0, 0x03A9)
|
||||
#define TSDB_CODE_MND_ARBGROUP_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AA)
|
||||
#define TSDB_CODE_MND_ARBGROUP_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AB)
|
||||
#define TSDB_CODE_MND_ARB_TOKEN_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x03AC)
|
||||
|
||||
// mnode-dnode-part2
|
||||
#define TSDB_CODE_MND_TOO_MANY_DNODES TAOS_DEF_ERROR_CODE(0, 0x03B0)
|
||||
|
@ -472,6 +475,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_VND_ALREADY_IS_VOTER TAOS_DEF_ERROR_CODE(0, 0x0533) // internal
|
||||
#define TSDB_CODE_VND_DIR_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0534)
|
||||
#define TSDB_CODE_VND_META_DATA_UNSAFE_DELETE TAOS_DEF_ERROR_CODE(0, 0x0535)
|
||||
#define TSDB_CODE_VND_ARB_NOT_SYNCED TAOS_DEF_ERROR_CODE(0, 0x0536) // internal
|
||||
|
||||
// tsdb
|
||||
#define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600)
|
||||
|
|
|
@ -279,6 +279,9 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
||||
#define TSDB_LOG_VAR_LEN 32
|
||||
|
||||
#define TSDB_ARB_GROUP_MEMBER_NUM 2
|
||||
#define TSDB_ARB_TOKEN_SIZE 32
|
||||
|
||||
#define TSDB_TRANS_STAGE_LEN 12
|
||||
#define TSDB_TRANS_TYPE_LEN 16
|
||||
#define TSDB_TRANS_ERROR_LEN 512
|
||||
|
@ -425,6 +428,10 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_DB_MIN_WAL_SEGMENT_SIZE 0
|
||||
#define TSDB_DEFAULT_DB_WAL_SEGMENT_SIZE 0
|
||||
|
||||
#define TSDB_DEFAULT_DB_WITH_ARBITRATOR 0
|
||||
#define TSDB_MIN_DB_WITH_ARBITRATOR 0
|
||||
#define TSDB_MAX_DB_WITH_ARBITRATOR 1
|
||||
|
||||
#define TSDB_MIN_ROLLUP_MAX_DELAY 1 // unit millisecond
|
||||
#define TSDB_MAX_ROLLUP_MAX_DELAY (15 * 60 * 1000)
|
||||
#define TSDB_MIN_ROLLUP_WATERMARK 0 // unit millisecond
|
||||
|
|
|
@ -779,7 +779,7 @@ int32_t tmqHbCb(void* param, SDataBuf* pMsg, int32_t code) {
|
|||
taosWUnLockLatch(&tmq->lock);
|
||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||
}
|
||||
tDeatroySMqHbRsp(&rsp);
|
||||
tDestroySMqHbRsp(&rsp);
|
||||
taosMemoryFree(pMsg->pData);
|
||||
taosMemoryFree(pMsg->pEpSet);
|
||||
}
|
||||
|
@ -861,7 +861,7 @@ void tmqSendHbReq(void* param, void* tmrId) {
|
|||
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
|
||||
OVER:
|
||||
tDeatroySMqHbReq(&req);
|
||||
tDestroySMqHbReq(&req);
|
||||
taosTmrReset(tmqSendHbReq, DEFAULT_HEARTBEAT_INTERVAL, param, tmqMgmt.timer, &tmq->hbLiveTimer);
|
||||
taosReleaseRef(tmqMgmt.rsetId, refId);
|
||||
}
|
||||
|
|
|
@ -68,6 +68,16 @@ static const SSysDbTableSchema snodesSchema[] = {
|
|||
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = true},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema arbGroupsSchema[] = {
|
||||
{.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
||||
{.name = "v1_dnode", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT, .sysInfo = true},
|
||||
{.name = "v2_dnode", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT, .sysInfo = true},
|
||||
{.name = "is_sync", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT, .sysInfo = true},
|
||||
{.name = "assigned_dnode", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT, .sysInfo = true},
|
||||
{.name = "assigned_token", .bytes = TSDB_ARB_TOKEN_SIZE + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema clusterSchema[] = {
|
||||
{.name = "id", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = true},
|
||||
{.name = "name", .bytes = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
|
@ -107,6 +117,7 @@ static const SSysDbTableSchema userDBSchema[] = {
|
|||
{.name = "table_suffix", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT, .sysInfo = true},
|
||||
{.name = "tsdb_pagesize", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
||||
{.name = "keep_time_offset", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = false},
|
||||
{.name = "with_arbitrator", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema userFuncSchema[] = {
|
||||
|
@ -348,21 +359,24 @@ static const SSysDbTableSchema userCompactsDetailSchema[] = {
|
|||
{.name = "start_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP, .sysInfo = false},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema useGrantsFullSchema[] = {
|
||||
static const SSysDbTableSchema userGrantsFullSchema[] = {
|
||||
{.name = "grant_name", .bytes = 32 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
{.name = "display_name", .bytes = 256 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
{.name = "expire", .bytes = 32 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
{.name = "limits", .bytes = 512 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema useGrantsLogsSchema[] = {
|
||||
static const SSysDbTableSchema userGrantsLogsSchema[] = {
|
||||
{.name = "state", .bytes = 1536 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
{.name = "active", .bytes = 512 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
{.name = "machine", .bytes = TSDB_GRANT_LOG_COL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema useMachinesSchema[] = {
|
||||
static const SSysDbTableSchema userMachinesSchema[] = {
|
||||
{.name = "id", .bytes = TSDB_CLUSTER_ID_LEN + 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
#ifndef TD_UNIQ_GRANT
|
||||
{.name = "dnode_num", .bytes = 4, .type = TSDB_DATA_TYPE_INT, .sysInfo = true},
|
||||
#endif
|
||||
{.name = "machine", .bytes = 7552 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true},
|
||||
};
|
||||
|
||||
|
@ -395,9 +409,10 @@ static const SSysTableMeta infosMeta[] = {
|
|||
{TSDB_INS_TABLE_VIEWS, userViewsSchema, tListLen(userViewsSchema), false},
|
||||
{TSDB_INS_TABLE_COMPACTS, userCompactsSchema, tListLen(userCompactsSchema), false},
|
||||
{TSDB_INS_TABLE_COMPACT_DETAILS, userCompactsDetailSchema, tListLen(userCompactsDetailSchema), false},
|
||||
{TSDB_INS_TABLE_GRANTS_FULL, useGrantsFullSchema, tListLen(useGrantsFullSchema), true},
|
||||
{TSDB_INS_TABLE_GRANTS_LOGS, useGrantsLogsSchema, tListLen(useGrantsLogsSchema), true},
|
||||
{TSDB_INS_TABLE_MACHINES, useMachinesSchema, tListLen(useMachinesSchema), true},
|
||||
{TSDB_INS_TABLE_GRANTS_FULL, userGrantsFullSchema, tListLen(userGrantsFullSchema), true},
|
||||
{TSDB_INS_TABLE_GRANTS_LOGS, userGrantsLogsSchema, tListLen(userGrantsLogsSchema), true},
|
||||
{TSDB_INS_TABLE_MACHINES, userMachinesSchema, tListLen(userMachinesSchema), true},
|
||||
{TSDB_INS_TABLE_ARBGROUPS, arbGroupsSchema, tListLen(arbGroupsSchema), true},
|
||||
};
|
||||
|
||||
static const SSysDbTableSchema connectionsSchema[] = {
|
||||
|
|
|
@ -82,6 +82,11 @@ int32_t tsMndGrantMode = 0;
|
|||
bool tsMndSkipGrant = false;
|
||||
bool tsEnableWhiteList = false; // ip white list cfg
|
||||
|
||||
// arbitrator
|
||||
int32_t tsArbHeartBeatIntervalSec = 5;
|
||||
int32_t tsArbCheckSyncIntervalSec = 10;
|
||||
int32_t tsArbSetAssignedTimeoutSec = 30;
|
||||
|
||||
// dnode
|
||||
int64_t tsDndStart = 0;
|
||||
int64_t tsDndStartOsUptime = 0;
|
||||
|
@ -672,6 +677,16 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
|||
(TSDB_SYNC_SNAP_BUFFER_SIZE >> 2), CFG_SCOPE_SERVER, CFG_DYN_NONE) != 0)
|
||||
return -1;
|
||||
|
||||
if (cfgAddInt32(pCfg, "arbHeartBeatIntervalSec", tsArbHeartBeatIntervalSec, 1, 60 * 24 * 2, CFG_SCOPE_SERVER,
|
||||
CFG_DYN_NONE) != 0)
|
||||
return -1;
|
||||
if (cfgAddInt32(pCfg, "arbCheckSyncIntervalSec", tsArbCheckSyncIntervalSec, 1, 60 * 24 * 2, CFG_SCOPE_SERVER,
|
||||
CFG_DYN_NONE) != 0)
|
||||
return -1;
|
||||
if (cfgAddInt32(pCfg, "arbSetAssignedTimeoutSec", tsArbSetAssignedTimeoutSec, 1, 60 * 24 * 2, CFG_SCOPE_SERVER,
|
||||
CFG_DYN_NONE) != 0)
|
||||
return -1;
|
||||
|
||||
if (cfgAddInt64(pCfg, "mndSdbWriteDelta", tsMndSdbWriteDelta, 20, 10000, CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER) != 0)
|
||||
return -1;
|
||||
if (cfgAddInt64(pCfg, "mndLogRetention", tsMndLogRetention, 500, 10000, CFG_SCOPE_SERVER, CFG_DYN_NONE) != 0)
|
||||
|
@ -1187,6 +1202,10 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
tsHeartbeatTimeout = cfgGetItem(pCfg, "syncHeartbeatTimeout")->i32;
|
||||
tsSnapReplMaxWaitN = cfgGetItem(pCfg, "syncSnapReplMaxWaitN")->i32;
|
||||
|
||||
tsArbHeartBeatIntervalSec = cfgGetItem(pCfg, "arbHeartBeatIntervalSec")->i32;
|
||||
tsArbCheckSyncIntervalSec = cfgGetItem(pCfg, "arbCheckSyncIntervalSec")->i32;
|
||||
tsArbSetAssignedTimeoutSec = cfgGetItem(pCfg, "arbSetAssignedTimeoutSec")->i32;
|
||||
|
||||
tsMndSdbWriteDelta = cfgGetItem(pCfg, "mndSdbWriteDelta")->i64;
|
||||
tsMndLogRetention = cfgGetItem(pCfg, "mndLogRetention")->i64;
|
||||
tsMndSkipGrant = cfgGetItem(pCfg, "skipGrant")->bval;
|
||||
|
|
|
@ -21,11 +21,5 @@
|
|||
int32_t grantCheck(EGrantType grant) { return TSDB_CODE_SUCCESS; }
|
||||
int32_t grantCheckExpire(EGrantType grant) { return TSDB_CODE_SUCCESS; }
|
||||
|
||||
#ifdef TD_UNIQ_GRANT
|
||||
int32_t grantCheckLE(EGrantType grant) { return TSDB_CODE_SUCCESS; }
|
||||
#endif
|
||||
#else
|
||||
#ifdef TD_UNIQ_GRANT
|
||||
int32_t grantCheckExpire(EGrantType grant) { return TSDB_CODE_SUCCESS; }
|
||||
#endif
|
||||
#endif
|
|
@ -3024,6 +3024,9 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) {
|
|||
if (tEncodeI32(&encoder, pReq->keepTimeOffset) < 0) return -1;
|
||||
|
||||
ENCODESQL();
|
||||
|
||||
if (tEncodeI32(&encoder, pReq->withArbitrator) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
|
@ -3093,8 +3096,12 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq)
|
|||
|
||||
DECODESQL();
|
||||
|
||||
tEndDecode(&decoder);
|
||||
pReq->withArbitrator = TSDB_DEFAULT_DB_WITH_ARBITRATOR;
|
||||
if (!tDecodeIsEnd(&decoder)) {
|
||||
if (tDecodeI8(&decoder, &pReq->withArbitrator) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndDecode(&decoder);
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
@ -3133,6 +3140,7 @@ int32_t tSerializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) {
|
|||
if (tEncodeI32(&encoder, pReq->walRetentionSize) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->keepTimeOffset) < 0) return -1;
|
||||
ENCODESQL();
|
||||
if (tEncodeI32(&encoder, pReq->withArbitrator) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
|
@ -3182,6 +3190,10 @@ int32_t tDeserializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) {
|
|||
}
|
||||
|
||||
DECODESQL();
|
||||
pReq->withArbitrator = TSDB_DEFAULT_DB_WITH_ARBITRATOR;
|
||||
if (!tDecodeIsEnd(&decoder)) {
|
||||
if (tDecodeI8(&decoder, &pReq->withArbitrator) < 0) return -1;
|
||||
}
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
|
@ -3969,6 +3981,7 @@ int32_t tSerializeSDbCfgRspImpl(SEncoder *encoder, const SDbCfgRsp *pRsp) {
|
|||
if (tEncodeI8(encoder, pRsp->schemaless) < 0) return -1;
|
||||
if (tEncodeI16(encoder, pRsp->sstTrigger) < 0) return -1;
|
||||
if (tEncodeI32(encoder, pRsp->keepTimeOffset) < 0) return -1;
|
||||
if (tEncodeI8(encoder, pRsp->withArbitrator) < 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -4041,6 +4054,10 @@ int32_t tDeserializeSDbCfgRspImpl(SDecoder *decoder, SDbCfgRsp *pRsp) {
|
|||
if (!tDecodeIsEnd(decoder)) {
|
||||
if (tDecodeI32(decoder, &pRsp->keepTimeOffset) < 0) return -1;
|
||||
}
|
||||
pRsp->withArbitrator = TSDB_DEFAULT_DB_WITH_ARBITRATOR;
|
||||
if (!tDecodeIsEnd(decoder)) {
|
||||
if (tDecodeI8(decoder, &pRsp->withArbitrator) < 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -5916,6 +5933,345 @@ int32_t tDeserializeSDCreateMnodeReq(void *buf, int32_t bufLen, SDCreateMnodeReq
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSVArbHeartBeatReq(void *buf, int32_t bufLen, SVArbHeartBeatReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->arbToken) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->arbTerm) < 0) return -1;
|
||||
|
||||
int32_t size = taosArrayGetSize(pReq->hbMembers);
|
||||
if (tEncodeI32(&encoder, size) < 0) return -1;
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
SVArbHbReqMember *pMember = taosArrayGet(pReq->hbMembers, i);
|
||||
if (tEncodeI32(&encoder, pMember->vgId) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pMember->hbSeq) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSVArbHeartBeatReq(void *buf, int32_t bufLen, SVArbHeartBeatReq *pReq) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
|
||||
pReq->arbToken = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pReq->arbToken) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->arbTerm) < 0) return -1;
|
||||
|
||||
pReq->hbMembers = taosArrayInit(16, sizeof(SVArbHbReqMember));
|
||||
int32_t size = 0;
|
||||
if (tDecodeI32(&decoder, &size) < 0) return -1;
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
SVArbHbReqMember member = {0};
|
||||
if (tDecodeI32(&decoder, &member.vgId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &member.hbSeq) < 0) return -1;
|
||||
taosArrayPush(pReq->hbMembers, &member);
|
||||
}
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSVArbHeartBeatReq(SVArbHeartBeatReq *pReq) {
|
||||
if (!pReq) return;
|
||||
taosMemoryFree(pReq->arbToken);
|
||||
taosArrayDestroy(pReq->hbMembers);
|
||||
}
|
||||
|
||||
int32_t tSerializeSVArbHeartBeatRsp(void *buf, int32_t bufLen, SVArbHeartBeatRsp *pRsp) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pRsp->arbToken) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pRsp->dnodeId) < 0) return -1;
|
||||
int32_t sz = taosArrayGetSize(pRsp->hbMembers);
|
||||
if (tEncodeI32(&encoder, sz) < 0) return -1;
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SVArbHbRspMember *pMember = taosArrayGet(pRsp->hbMembers, i);
|
||||
if (tEncodeI32(&encoder, pMember->vgId) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pMember->hbSeq) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pMember->memberToken) < 0) return -1;
|
||||
}
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSVArbHeartBeatRsp(void *buf, int32_t bufLen, SVArbHeartBeatRsp *pRsp) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pRsp->arbToken) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pRsp->dnodeId) < 0) return -1;
|
||||
int32_t sz = 0;
|
||||
if (tDecodeI32(&decoder, &sz) < 0) return -1;
|
||||
pRsp->hbMembers = taosArrayInit(sz, sizeof(SVArbHbRspMember));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SVArbHbRspMember hbMember = {0};
|
||||
if (tDecodeI32(&decoder, &hbMember.vgId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &hbMember.hbSeq) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, hbMember.memberToken) < 0) return -1;
|
||||
taosArrayPush(pRsp->hbMembers, &hbMember);
|
||||
}
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSVArbHeartBeatRsp(SVArbHeartBeatRsp *pRsp) {
|
||||
if (NULL == pRsp) {
|
||||
return;
|
||||
}
|
||||
taosArrayDestroy(pRsp->hbMembers);
|
||||
}
|
||||
|
||||
int32_t tSerializeSVArbCheckSyncReq(void *buf, int32_t bufLen, SVArbCheckSyncReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->arbToken) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->arbTerm) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->member0Token) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->member1Token) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSVArbCheckSyncReq(void *buf, int32_t bufLen, SVArbCheckSyncReq *pReq) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
pReq->arbToken = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pReq->arbToken) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->arbTerm) < 0) return -1;
|
||||
pReq->member0Token = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pReq->member0Token) < 0) return -1;
|
||||
pReq->member1Token = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pReq->member1Token) < 0) return -1;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSVArbCheckSyncReq(SVArbCheckSyncReq *pRsp) {
|
||||
if (NULL == pRsp) {
|
||||
return;
|
||||
}
|
||||
taosMemoryFreeClear(pRsp->arbToken);
|
||||
taosMemoryFreeClear(pRsp->member0Token);
|
||||
taosMemoryFreeClear(pRsp->member1Token);
|
||||
}
|
||||
|
||||
int32_t tSerializeSVArbCheckSyncRsp(void *buf, int32_t bufLen, SVArbCheckSyncRsp *pRsp) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pRsp->arbToken) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pRsp->member0Token) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pRsp->member1Token) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pRsp->vgId) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pRsp->errCode) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSVArbCheckSyncRsp(void *buf, int32_t bufLen, SVArbCheckSyncRsp *pRsp) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
pRsp->arbToken = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pRsp->arbToken) < 0) return -1;
|
||||
pRsp->member0Token = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pRsp->member0Token) < 0) return -1;
|
||||
pRsp->member1Token = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pRsp->member1Token) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pRsp->vgId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pRsp->errCode) < 0) return -1;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSVArbCheckSyncRsp(SVArbCheckSyncRsp *pRsp) {
|
||||
if (NULL == pRsp) {
|
||||
return;
|
||||
}
|
||||
taosMemoryFreeClear(pRsp->arbToken);
|
||||
taosMemoryFreeClear(pRsp->member0Token);
|
||||
taosMemoryFreeClear(pRsp->member1Token);
|
||||
}
|
||||
|
||||
int32_t tSerializeSVArbSetAssignedLeaderReq(void *buf, int32_t bufLen, SVArbSetAssignedLeaderReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->arbToken) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->arbTerm) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->memberToken) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSVArbSetAssignedLeaderReq(void *buf, int32_t bufLen, SVArbSetAssignedLeaderReq *pReq) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
pReq->arbToken = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pReq->arbToken) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->arbTerm) < 0) return -1;
|
||||
pReq->memberToken = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pReq->memberToken) < 0) return -1;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSVArbSetAssignedLeaderReq(SVArbSetAssignedLeaderReq *pReq) {
|
||||
if (NULL == pReq) {
|
||||
return;
|
||||
}
|
||||
taosMemoryFreeClear(pReq->arbToken);
|
||||
taosMemoryFreeClear(pReq->memberToken);
|
||||
}
|
||||
|
||||
int32_t tSerializeSVArbSetAssignedLeaderRsp(void *buf, int32_t bufLen, SVArbSetAssignedLeaderRsp *pRsp) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pRsp->arbToken) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pRsp->memberToken) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pRsp->vgId) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSVArbSetAssignedLeaderRsp(void *buf, int32_t bufLen, SVArbSetAssignedLeaderRsp *pRsp) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
pRsp->arbToken = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pRsp->arbToken) < 0) return -1;
|
||||
pRsp->memberToken = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pRsp->memberToken) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pRsp->vgId) < 0) return -1;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSVArbSetAssignedLeaderRsp(SVArbSetAssignedLeaderRsp *pRsp) {
|
||||
if (NULL == pRsp) {
|
||||
return;
|
||||
}
|
||||
taosMemoryFreeClear(pRsp->arbToken);
|
||||
taosMemoryFreeClear(pRsp->memberToken);
|
||||
}
|
||||
|
||||
int32_t tSerializeSMArbUpdateGroupReq(void *buf, int32_t bufLen, SMArbUpdateGroupReq *pReq) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->vgId) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->dbUid) < 0) return -1;
|
||||
for (int i = 0; i < TSDB_ARB_GROUP_MEMBER_NUM; i++) {
|
||||
if (tEncodeI32(&encoder, pReq->members[i].dnodeId) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->members[i].token) < 0) return -1;
|
||||
}
|
||||
if (tEncodeI8(&encoder, pReq->isSync) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->assignedLeader.dnodeId) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->assignedLeader.token) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->version) < 0) return -1;
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSMArbUpdateGroupReq(void *buf, int32_t bufLen, SMArbUpdateGroupReq *pReq) {
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->vgId) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->dbUid) < 0) return -1;
|
||||
for (int i = 0; i < TSDB_ARB_GROUP_MEMBER_NUM; i++) {
|
||||
if (tDecodeI32(&decoder, &pReq->members[i].dnodeId) < 0) return -1;
|
||||
pReq->members[i].token = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pReq->members[i].token) < 0) return -1;
|
||||
}
|
||||
if (tDecodeI8(&decoder, &pReq->isSync) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->assignedLeader.dnodeId) < 0) return -1;
|
||||
pReq->assignedLeader.token = taosMemoryMalloc(TSDB_ARB_TOKEN_SIZE);
|
||||
if (tDecodeCStrTo(&decoder, pReq->assignedLeader.token) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->version) < 0) return -1;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSMArbUpdateGroupReq(SMArbUpdateGroupReq *pReq) {
|
||||
if (NULL == pReq) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 2; i++) {
|
||||
taosMemoryFreeClear(pReq->members[i].token);
|
||||
}
|
||||
taosMemoryFreeClear(pReq->assignedLeader.token);
|
||||
}
|
||||
|
||||
// int32_t tSerializeSAuthReq(void *buf, int32_t bufLen, SAuthReq *pReq) {
|
||||
// SEncoder encoder = {0};
|
||||
// tEncoderInit(&encoder, buf, bufLen);
|
||||
|
@ -6201,9 +6557,8 @@ int32_t tDeserializeSMqAskEpReq(void *buf, int32_t bufLen, SMqAskEpReq *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDeatroySMqHbRsp(SMqHbRsp *pRsp) {
|
||||
void tDestroySMqHbRsp(SMqHbRsp *pRsp) {
|
||||
taosArrayDestroy(pRsp->topicPrivileges);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSMqHbRsp(void *buf, int32_t bufLen, SMqHbRsp *pRsp) {
|
||||
|
@ -6250,13 +6605,12 @@ int32_t tDeserializeSMqHbRsp(void *buf, int32_t bufLen, SMqHbRsp *pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDeatroySMqHbReq(SMqHbReq *pReq) {
|
||||
void tDestroySMqHbReq(SMqHbReq *pReq) {
|
||||
for (int i = 0; i < taosArrayGetSize(pReq->topics); i++) {
|
||||
TopicOffsetRows *vgs = taosArrayGet(pReq->topics, i);
|
||||
if (vgs) taosArrayDestroy(vgs->offsetRows);
|
||||
}
|
||||
taosArrayDestroy(pReq->topics);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSMqHbReq(void *buf, int32_t bufLen, SMqHbReq *pReq) {
|
||||
|
|
|
@ -90,16 +90,6 @@ static void dmProcessStatusRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) {
|
|||
rpcFreeCont(pRsp->pCont);
|
||||
}
|
||||
|
||||
void dmEpSetToStr(char *buf, int32_t len, SEpSet *epSet) {
|
||||
int32_t n = 0;
|
||||
n += snprintf(buf + n, len - n, "%s", "{");
|
||||
for (int i = 0; i < epSet->numOfEps; i++) {
|
||||
n += snprintf(buf + n, len - n, "%s:%d%s", epSet->eps[i].fqdn, epSet->eps[i].port,
|
||||
(i + 1 < epSet->numOfEps ? ", " : ""));
|
||||
}
|
||||
n += snprintf(buf + n, len - n, "%s", "}");
|
||||
}
|
||||
|
||||
void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
||||
SStatusReq req = {0};
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ typedef struct SMnodeMgmt {
|
|||
SSingleWorker fetchWorker;
|
||||
SSingleWorker readWorker;
|
||||
SSingleWorker writeWorker;
|
||||
SSingleWorker arbWorker;
|
||||
SSingleWorker syncWorker;
|
||||
SSingleWorker syncRdWorker;
|
||||
bool stopped;
|
||||
|
@ -53,6 +54,7 @@ int32_t mmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg);
|
|||
int32_t mmStartWorker(SMnodeMgmt *pMgmt);
|
||||
void mmStopWorker(SMnodeMgmt *pMgmt);
|
||||
int32_t mmPutMsgToWriteQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t mmPutMsgToArbQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t mmPutMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t mmPutMsgToSyncRdQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
|
|
|
@ -235,6 +235,9 @@ SArray *mmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_INDEX_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_INDEX_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DISABLE_WRITE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ARB_HEARTBEAT_RSP, mmPutMsgToArbQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ARB_CHECK_SYNC_RSP, mmPutMsgToArbQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SET_ASSIGNED_LEADER_RSP, mmPutMsgToArbQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_TIMEOUT_ELECTION, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_CLIENT_REQUEST, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||
|
|
|
@ -107,6 +107,10 @@ int32_t mmPutMsgToWriteQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
return mmPutMsgToWorker(pMgmt, &pMgmt->writeWorker, pMsg);
|
||||
}
|
||||
|
||||
int32_t mmPutMsgToArbQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
return mmPutMsgToWorker(pMgmt, &pMgmt->arbWorker, pMsg);
|
||||
}
|
||||
|
||||
int32_t mmPutMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
return mmPutMsgToWorker(pMgmt, &pMgmt->syncWorker, pMsg);
|
||||
}
|
||||
|
@ -153,6 +157,9 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
|||
case READ_QUEUE:
|
||||
pWorker = &pMgmt->readWorker;
|
||||
break;
|
||||
case ARB_QUEUE:
|
||||
pWorker = &pMgmt->arbWorker;
|
||||
break;
|
||||
case SYNC_QUEUE:
|
||||
pWorker = &pMgmt->syncWorker;
|
||||
break;
|
||||
|
@ -252,6 +259,18 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
SSingleWorkerCfg arbCfg = {
|
||||
.min = 1,
|
||||
.max = 1,
|
||||
.name = "mnode-arb",
|
||||
.fp = (FItem)mmProcessRpcMsg,
|
||||
.param = pMgmt,
|
||||
};
|
||||
if (tSingleWorkerInit(&pMgmt->arbWorker, &arbCfg) != 0) {
|
||||
dError("failed to start mnode mnode-arb worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("mnode workers are initialized");
|
||||
return 0;
|
||||
}
|
||||
|
@ -263,6 +282,7 @@ void mmStopWorker(SMnodeMgmt *pMgmt) {
|
|||
tSingleWorkerCleanup(&pMgmt->fetchWorker);
|
||||
tSingleWorkerCleanup(&pMgmt->readWorker);
|
||||
tSingleWorkerCleanup(&pMgmt->writeWorker);
|
||||
tSingleWorkerCleanup(&pMgmt->arbWorker);
|
||||
tSingleWorkerCleanup(&pMgmt->syncWorker);
|
||||
tSingleWorkerCleanup(&pMgmt->syncRdWorker);
|
||||
dDebug("mnode workers are closed");
|
||||
|
|
|
@ -101,6 +101,7 @@ int32_t vmProcessDisableVnodeWriteReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
|||
int32_t vmProcessAlterHashRangeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t vmProcessAlterVnodeTypeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t vmProcessCheckLearnCatchupReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
int32_t vmProcessArbHeartBeatReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||
|
||||
// vmFile.c
|
||||
int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
|
||||
|
|
|
@ -88,7 +88,9 @@ void vmGetMonitorInfo(SVnodeMgmt *pMgmt, SMonVmInfo *pInfo) {
|
|||
numOfInsertSuccessReqs += pLoad->numOfInsertSuccessReqs;
|
||||
numOfBatchInsertReqs += pLoad->numOfBatchInsertReqs;
|
||||
numOfBatchInsertSuccessReqs += pLoad->numOfBatchInsertSuccessReqs;
|
||||
if (pLoad->syncState == TAOS_SYNC_STATE_LEADER) masterNum++;
|
||||
if (pLoad->syncState == TAOS_SYNC_STATE_LEADER || pLoad->syncState == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
masterNum++;
|
||||
}
|
||||
totalVnodes++;
|
||||
}
|
||||
|
||||
|
@ -770,6 +772,89 @@ int32_t vmProcessDropVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t vmProcessArbHeartBeatReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||
SVArbHeartBeatReq arbHbReq = {0};
|
||||
SVArbHeartBeatRsp arbHbRsp = {0};
|
||||
if (tDeserializeSVArbHeartBeatReq(pMsg->pCont, pMsg->contLen, &arbHbReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (arbHbReq.dnodeId != pMgmt->pData->dnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
dError("dnodeId:%d not matched with local dnode", arbHbReq.dnodeId);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (strlen(arbHbReq.arbToken) == 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
dError("dnodeId:%d arbToken is empty", arbHbReq.dnodeId);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
size_t size = taosArrayGetSize(arbHbReq.hbMembers);
|
||||
|
||||
arbHbRsp.dnodeId = pMgmt->pData->dnodeId;
|
||||
strncpy(arbHbRsp.arbToken, arbHbReq.arbToken, TSDB_ARB_TOKEN_SIZE);
|
||||
arbHbRsp.hbMembers = taosArrayInit(size, sizeof(SVArbHbRspMember));
|
||||
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
SVArbHbReqMember *pReqMember = taosArrayGet(arbHbReq.hbMembers, i);
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pReqMember->vgId);
|
||||
if (pVnode == NULL) {
|
||||
dError("dnodeId:%d vgId:%d not found failed to process arb hb req", arbHbReq.dnodeId, pReqMember->vgId);
|
||||
continue;
|
||||
}
|
||||
|
||||
SVArbHbRspMember rspMember = {0};
|
||||
rspMember.vgId = pReqMember->vgId;
|
||||
rspMember.hbSeq = pReqMember->hbSeq;
|
||||
if (vnodeGetArbToken(pVnode->pImpl, rspMember.memberToken) != 0) {
|
||||
dError("dnodeId:%d vgId:%d failed to get arb token", arbHbReq.dnodeId, pReqMember->vgId);
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (vnodeUpdateArbTerm(pVnode->pImpl, arbHbReq.arbTerm) != 0) {
|
||||
dError("dnodeId:%d vgId:%d failed to update arb term", arbHbReq.dnodeId, pReqMember->vgId);
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
continue;
|
||||
}
|
||||
|
||||
taosArrayPush(arbHbRsp.hbMembers, &rspMember);
|
||||
|
||||
vmReleaseVnode(pMgmt, pVnode);
|
||||
}
|
||||
|
||||
SRpcMsg rspMsg = {.info = pMsg->info};
|
||||
int32_t rspLen = tSerializeSVArbHeartBeatRsp(NULL, 0, &arbHbRsp);
|
||||
if (rspLen < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
void *pRsp = rpcMallocCont(rspLen);
|
||||
if (pRsp == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (tSerializeSVArbHeartBeatRsp(pRsp, rspLen, &arbHbRsp) <= 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
rpcFreeCont(pRsp);
|
||||
goto _OVER;
|
||||
}
|
||||
pMsg->info.rsp = pRsp;
|
||||
pMsg->info.rspLen = rspLen;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
_OVER:
|
||||
tFreeSVArbHeartBeatReq(&arbHbReq);
|
||||
tFreeSVArbHeartBeatRsp(&arbHbRsp);
|
||||
return terrno == TSDB_CODE_SUCCESS ? 0 : -1;
|
||||
}
|
||||
|
||||
SArray *vmGetMsgHandles() {
|
||||
int32_t code = -1;
|
||||
SArray *pArray = taosArrayInit(32, sizeof(SMgmtHandle));
|
||||
|
@ -873,6 +958,10 @@ SArray *vmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, vmPutMsgToSyncRdQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_PREP_SNAPSHOT_REPLY, vmPutMsgToSyncRdQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ARB_HEARTBEAT, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ARB_CHECK_SYNC, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SET_ASSIGNED_LEADER, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
|
|
|
@ -56,6 +56,9 @@ static void vmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
|||
case TDMT_DND_CHECK_VNODE_LEARNER_CATCHUP:
|
||||
code = vmProcessCheckLearnCatchupReq(pMgmt, pMsg);
|
||||
break;
|
||||
case TDMT_VND_ARB_HEARTBEAT:
|
||||
code = vmProcessArbHeartBeatReq(pMgmt, pMsg);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
dGError("msg:%p, not processed in vnode-mgmt queue", pMsg);
|
||||
|
|
|
@ -538,6 +538,7 @@ SMsgCb dmGetMsgcb(SDnode *pDnode) {
|
|||
.releaseHandleFp = dmReleaseHandle,
|
||||
.reportStartupFp = dmReportStartup,
|
||||
.updateDnodeInfoFp = dmUpdateDnodeInfo,
|
||||
.getDnodeEpFp = dmGetDnodeEp,
|
||||
.data = &pDnode->data,
|
||||
};
|
||||
return msgCb;
|
||||
|
|
|
@ -184,11 +184,13 @@ int32_t dmReadEps(SDnodeData *pData);
|
|||
int32_t dmWriteEps(SDnodeData *pData);
|
||||
void dmUpdateEps(SDnodeData *pData, SArray *pDnodeEps);
|
||||
void dmGetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
|
||||
void dmEpSetToStr(char *buf, int32_t len, SEpSet *epSet);
|
||||
void dmRotateMnodeEpSet(SDnodeData *pData);
|
||||
void dmGetMnodeEpSetForRedirect(SDnodeData *pData, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
|
||||
bool dmUpdateDnodeInfo(void *pData, int32_t *dnodeId, int64_t *clusterId, char *fqdn, uint16_t *port);
|
||||
void dmRemoveDnodePairs(SDnodeData *pData);
|
||||
void dmGetDnodeEp(void *pData, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -31,7 +31,8 @@ static bool dmIsEpChanged(SDnodeData *pData, int32_t dnodeId, const char *ep)
|
|||
static void dmResetEps(SDnodeData *pData, SArray *dnodeEps);
|
||||
static int32_t dmReadDnodePairs(SDnodeData *pData);
|
||||
|
||||
static void dmGetDnodeEp(SDnodeData *pData, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) {
|
||||
void dmGetDnodeEp(void *data, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) {
|
||||
SDnodeData *pData = data;
|
||||
taosThreadRwlockRdlock(&pData->lock);
|
||||
|
||||
SDnodeEp *pDnodeEp = taosHashGet(pData->dnodeHash, &dnodeId, sizeof(int32_t));
|
||||
|
@ -335,6 +336,16 @@ void dmGetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet) {
|
|||
taosThreadRwlockUnlock(&pData->lock);
|
||||
}
|
||||
|
||||
void dmEpSetToStr(char *buf, int32_t len, SEpSet *epSet) {
|
||||
int32_t n = 0;
|
||||
n += snprintf(buf + n, len - n, "%s", "{");
|
||||
for (int i = 0; i < epSet->numOfEps; i++) {
|
||||
n += snprintf(buf + n, len - n, "%s:%d%s", epSet->eps[i].fqdn, epSet->eps[i].port,
|
||||
(i + 1 < epSet->numOfEps ? ", " : ""));
|
||||
}
|
||||
n += snprintf(buf + n, len - n, "%s", "}");
|
||||
}
|
||||
|
||||
static FORCE_INLINE void dmSwapEps(SEp *epLhs, SEp *epRhs) {
|
||||
SEp epTmp;
|
||||
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_MND_ARBGROUP_H_
|
||||
#define _TD_MND_ARBGROUP_H_
|
||||
|
||||
#include "mndInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mndInitArbGroup(SMnode *pMnode);
|
||||
void mndCleanupArbGroup(SMnode *pMnode);
|
||||
SArbGroup *mndAcquireArbGroup(SMnode *pMnode, int32_t vgId);
|
||||
void mndReleaseArbGroup(SMnode *pMnode, SArbGroup *pObj);
|
||||
SSdbRaw *mndArbGroupActionEncode(SArbGroup *pGroup);
|
||||
SSdbRow *mndArbGroupActionDecode(SSdbRaw *pRaw);
|
||||
|
||||
void mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup);
|
||||
|
||||
int32_t mndSetCreateArbGroupRedoLogs(STrans *pTrans, SArbGroup *pGroup);
|
||||
int32_t mndSetCreateArbGroupUndoLogs(STrans *pTrans, SArbGroup *pGroup);
|
||||
int32_t mndSetCreateArbGroupCommitLogs(STrans *pTrans, SArbGroup *pGroup);
|
||||
|
||||
int32_t mndSetDropArbGroupCommitLogs(STrans *pTrans, SArbGroup *pGroup);
|
||||
|
||||
bool mndUpdateArbGroupByHeartBeat(SArbGroup *pGroup, SVArbHbRspMember *pRspMember, int64_t nowMs, int32_t dnodeId,
|
||||
SArbGroup *pNewGroup);
|
||||
bool mndUpdateArbGroupByCheckSync(SArbGroup *pGroup, int32_t vgId, char *member0Token, char *member1Token,
|
||||
bool newIsSync, SArbGroup *pNewGroup);
|
||||
bool mndUpdateArbGroupBySetAssignedLeader(SArbGroup *pGroup, int32_t vgId, char *memberToken, int32_t errcode,
|
||||
SArbGroup *pNewGroup);
|
||||
|
||||
int32_t mndGetArbGroupSize(SMnode *pMnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MND_ARBGROUP_H_*/
|
|
@ -24,27 +24,22 @@ extern "C" {
|
|||
|
||||
enum {
|
||||
MQ_CONSUMER_STATUS_REBALANCE = 1,
|
||||
// MQ_CONSUMER_STATUS__MODIFY_IN_REB, // this value is not used anymore
|
||||
MQ_CONSUMER_STATUS_READY,
|
||||
MQ_CONSUMER_STATUS_LOST,
|
||||
// MQ_CONSUMER_STATUS__LOST_IN_REB, // this value is not used anymore
|
||||
// MQ_CONSUMER_STATUS__LOST_REBD,
|
||||
};\
|
||||
};
|
||||
|
||||
int32_t mndInitConsumer(SMnode *pMnode);
|
||||
void mndCleanupConsumer(SMnode *pMnode);
|
||||
void mndDropConsumerFromSdb(SMnode *pMnode, int64_t consumerId, SRpcHandleInfo* info);
|
||||
void mndSendConsumerMsg(SMnode *pMnode, int64_t consumerId, uint16_t msgType, SRpcHandleInfo* info);
|
||||
|
||||
SMqConsumerObj *mndAcquireConsumer(SMnode *pMnode, int64_t consumerId);
|
||||
void mndReleaseConsumer(SMnode *pMnode, SMqConsumerObj *pConsumer);
|
||||
|
||||
SMqConsumerObj *mndCreateConsumer(int64_t consumerId, const char *cgroup);
|
||||
|
||||
SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer);
|
||||
SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw);
|
||||
|
||||
int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer);
|
||||
int32_t mndSetConsumerDropLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer);
|
||||
int32_t mndSetConsumerCommitLogs(STrans *pTrans, SMqConsumerObj *pConsumer);
|
||||
int32_t mndSetConsumerDropLogs(STrans *pTrans, SMqConsumerObj *pConsumer);
|
||||
|
||||
const char *mndConsumerStatusName(int status);
|
||||
|
||||
|
|
|
@ -104,6 +104,7 @@ typedef enum {
|
|||
TRN_CONFLICT_DB_INSIDE = 3,
|
||||
TRN_CONFLICT_TOPIC = 4,
|
||||
TRN_CONFLICT_TOPIC_INSIDE = 5,
|
||||
TRN_CONFLICT_ARBGROUP = 6,
|
||||
} ETrnConflct;
|
||||
|
||||
typedef enum {
|
||||
|
@ -149,6 +150,7 @@ typedef enum {
|
|||
CONSUMER_REMOVE_REB, // remove after rebalance
|
||||
CONSUMER_UPDATE_REC, // update after recover
|
||||
CONSUMER_UPDATE_SUB, // update after subscribe req
|
||||
CONSUMER_INSERT_SUB,
|
||||
} ECsmUpdateType;
|
||||
|
||||
typedef struct {
|
||||
|
@ -176,6 +178,7 @@ typedef struct {
|
|||
tmsg_t originRpcType;
|
||||
char dbname[TSDB_TABLE_FNAME_LEN];
|
||||
char stbname[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t arbGroupId;
|
||||
int32_t startFunc;
|
||||
int32_t stopFunc;
|
||||
int32_t paramLen;
|
||||
|
@ -214,8 +217,6 @@ typedef struct {
|
|||
uint16_t port;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
char ep[TSDB_EP_LEN];
|
||||
char active[TSDB_ACTIVE_KEY_LEN];
|
||||
char connActive[TSDB_CONN_ACTIVE_KEY_LEN];
|
||||
char machineId[TSDB_MACHINE_ID_LEN + 1];
|
||||
} SDnodeObj;
|
||||
|
||||
|
@ -247,6 +248,40 @@ typedef struct {
|
|||
SDnodeObj* pDnode;
|
||||
} SSnodeObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
char token[TSDB_ARB_TOKEN_SIZE];
|
||||
} SArbAssignedLeader;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
} SArbMemberInfo;
|
||||
|
||||
typedef struct {
|
||||
int32_t nextHbSeq;
|
||||
int32_t responsedHbSeq;
|
||||
char token[TSDB_ARB_TOKEN_SIZE];
|
||||
int64_t lastHbMs;
|
||||
} SArbMemberState;
|
||||
|
||||
typedef struct {
|
||||
SArbMemberInfo info;
|
||||
SArbMemberState state;
|
||||
} SArbGroupMember;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int64_t dbUid;
|
||||
SArbGroupMember members[TSDB_ARB_GROUP_MEMBER_NUM];
|
||||
int8_t isSync;
|
||||
SArbAssignedLeader assignedLeader;
|
||||
int64_t version;
|
||||
|
||||
// following fields will not be duplicated
|
||||
bool mutexInited;
|
||||
TdThreadMutex mutex;
|
||||
} SArbGroup;
|
||||
|
||||
typedef struct {
|
||||
int32_t maxUsers;
|
||||
int32_t maxDbs;
|
||||
|
@ -343,6 +378,7 @@ typedef struct {
|
|||
int32_t walRollPeriod;
|
||||
int64_t walRetentionSize;
|
||||
int64_t walSegmentSize;
|
||||
int8_t withArbitrator;
|
||||
} SDbCfg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -556,8 +592,9 @@ typedef struct {
|
|||
int32_t resetOffsetCfg;
|
||||
} SMqConsumerObj;
|
||||
|
||||
SMqConsumerObj* tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_LEN]);
|
||||
void tDeleteSMqConsumerObj(SMqConsumerObj* pConsumer, bool isDeleted);
|
||||
SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType, char *topic, SCMSubscribeReq *subscribe);
|
||||
void tClearSMqConsumerObj(SMqConsumerObj* pConsumer);
|
||||
void tDeleteSMqConsumerObj(SMqConsumerObj* pConsumer);
|
||||
int32_t tEncodeSMqConsumerObj(void** buf, const SMqConsumerObj* pConsumer);
|
||||
void* tDecodeSMqConsumerObj(const void* buf, SMqConsumerObj* pConsumer, int8_t sver);
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ void mndCleanupDnode(SMnode *pMnode);
|
|||
SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId);
|
||||
void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode);
|
||||
SEpSet mndGetDnodeEpset(SDnodeObj *pDnode);
|
||||
SEpSet mndGetDnodeEpsetById(SMnode *pMnode, int32_t dnodeId);
|
||||
int32_t mndGetDnodeSize(SMnode *pMnode);
|
||||
bool mndIsDnodeOnline(SDnodeObj *pDnode, int64_t curMs);
|
||||
void mndGetDnodeData(SMnode *pMnode, SArray *pDnodeInfo);
|
||||
|
|
|
@ -107,7 +107,7 @@ SArray *mndTakeVgroupSnapshot(SMnode *pMnode, bool *allReady);
|
|||
void mndKillTransImpl(SMnode *pMnode, int32_t transId, const char *pDbName);
|
||||
int32_t setTransAction(STrans *pTrans, void *pCont, int32_t contLen, int32_t msgType, const SEpSet *pEpset,
|
||||
int32_t retryCode);
|
||||
STrans *doCreateTrans(SMnode *pMnode, SStreamObj *pStream, SRpcMsg *pReq, const char *name, const char *pMsg);
|
||||
STrans *doCreateTrans(SMnode *pMnode, SStreamObj *pStream, SRpcMsg *pReq, ETrnConflct conflict, const char *name, const char *pMsg);
|
||||
int32_t mndPersistTransLog(SStreamObj *pStream, STrans *pTrans, int32_t status);
|
||||
SSdbRaw *mndStreamActionEncode(SStreamObj *pStream);
|
||||
void killAllCheckpointTrans(SMnode *pMnode, SVgroupChangeInfo *pChangeInfo);
|
||||
|
|
|
@ -30,7 +30,7 @@ SMqSubscribeObj *mndAcquireSubscribe(SMnode *pMnode, const char *CGroup, const c
|
|||
SMqSubscribeObj *mndAcquireSubscribeByKey(SMnode *pMnode, const char *key);
|
||||
void mndReleaseSubscribe(SMnode *pMnode, SMqSubscribeObj *pSub);
|
||||
|
||||
int32_t mndMakeSubscribeKey(char *key, const char *cgroup, const char *topicName);
|
||||
void mndMakeSubscribeKey(char *key, const char *cgroup, const char *topicName);
|
||||
|
||||
int32_t mndDropSubByTopic(SMnode *pMnode, STrans *pTrans, const char *topic);
|
||||
int32_t mndSetDropSubCommitLogs(SMnode *pMnode, STrans *pTrans, SMqSubscribeObj *pSub);
|
||||
|
|
|
@ -78,6 +78,7 @@ int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction);
|
|||
void mndTransSetRpcRsp(STrans *pTrans, void *pCont, int32_t contLen);
|
||||
void mndTransSetCb(STrans *pTrans, ETrnFunc startFunc, ETrnFunc stopFunc, void *param, int32_t paramLen);
|
||||
void mndTransSetDbName(STrans *pTrans, const char *dbname, const char *stbname);
|
||||
void mndTransSetArbGroupId(STrans *pTrans, int32_t groupId);
|
||||
void mndTransSetSerial(STrans *pTrans);
|
||||
void mndTransSetParallel(STrans *pTrans);
|
||||
void mndTransSetOper(STrans *pTrans, EOperType oper);
|
||||
|
|
|
@ -29,6 +29,7 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup);
|
|||
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup);
|
||||
SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw);
|
||||
SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup);
|
||||
SEpSet mndGetVgroupEpsetById(SMnode *pMnode, int32_t vgId);
|
||||
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId);
|
||||
void mndSortVnodeGid(SVgObj *pVgroup);
|
||||
int64_t mndGetVnodesMemory(SMnode *pMnode, int32_t dnodeId);
|
||||
|
@ -44,7 +45,7 @@ int32_t mndAddAlterVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pV
|
|||
int32_t mndAddDropVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, bool isRedo);
|
||||
int32_t mndSetMoveVgroupsInfoToTrans(SMnode *, STrans *pTrans, int32_t dropDnodeId, bool force, bool unsafe);
|
||||
int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb, SVgObj *pVgroup,
|
||||
SArray *pArray);
|
||||
SArray *pArray, SVgObj* pNewVgroup);
|
||||
int32_t mndBuildCompactVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int64_t compactTs,
|
||||
STimeWindow tw);
|
||||
int32_t mndBuildRaftAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb, SVgObj *pVgroup,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -68,25 +68,27 @@ int32_t mndInitConsumer(SMnode *pMnode) {
|
|||
|
||||
void mndCleanupConsumer(SMnode *pMnode) {}
|
||||
|
||||
void mndDropConsumerFromSdb(SMnode *pMnode, int64_t consumerId, SRpcHandleInfo *info) {
|
||||
SMqConsumerClearMsg *pClearMsg = rpcMallocCont(sizeof(SMqConsumerClearMsg));
|
||||
if (pClearMsg == NULL) {
|
||||
void mndSendConsumerMsg(SMnode *pMnode, int64_t consumerId, uint16_t msgType, SRpcHandleInfo *info) {
|
||||
void *msg = rpcMallocCont(sizeof(int64_t));
|
||||
if (msg == NULL) {
|
||||
mError("consumer:0x%" PRIx64 " failed to clear consumer due to out of memory. alloc size:%d", consumerId,
|
||||
(int32_t)sizeof(SMqConsumerClearMsg));
|
||||
(int32_t)sizeof(int64_t));
|
||||
return;
|
||||
}
|
||||
|
||||
pClearMsg->consumerId = consumerId;
|
||||
*(int64_t*)msg = consumerId;
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = TDMT_MND_TMQ_LOST_CONSUMER_CLEAR,
|
||||
.pCont = pClearMsg,
|
||||
.contLen = sizeof(SMqConsumerClearMsg),
|
||||
.msgType = msgType,
|
||||
.pCont = msg,
|
||||
.contLen = sizeof(int64_t),
|
||||
.info = *info,
|
||||
};
|
||||
|
||||
mInfo("consumer:0x%" PRIx64 " drop from sdb", consumerId);
|
||||
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
||||
return;
|
||||
mInfo("mndSendConsumerMsg type:%d consumer:0x%" PRIx64, msgType, consumerId);
|
||||
int32_t code = tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
||||
if (code != 0){
|
||||
mError("consumer:%"PRId64" send consumer msg:%d error:%d", consumerId, msgType, code);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t validateTopics(STrans *pTrans, const SArray *pTopicList, SMnode *pMnode, const char *pUser,
|
||||
|
@ -148,54 +150,62 @@ FAILED:
|
|||
}
|
||||
|
||||
static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
SMqConsumerRecoverMsg *pRecoverMsg = pMsg->pCont;
|
||||
SMqConsumerObj *pConsumerNew = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pRecoverMsg->consumerId);
|
||||
if (pConsumer == NULL) {
|
||||
mError("cannot find consumer %" PRId64 " when processing consumer recover msg", pRecoverMsg->consumerId);
|
||||
return -1;
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
|
||||
mInfo("receive consumer recover msg, consumer:0x%" PRIx64 " status:%d(%s)", pRecoverMsg->consumerId,
|
||||
pConsumer->status, mndConsumerStatusName(pConsumer->status));
|
||||
|
||||
if (pConsumer->status != MQ_CONSUMER_STATUS_LOST) {
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
terrno = TSDB_CODE_MND_CONSUMER_NOT_READY;
|
||||
return -1;
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
|
||||
SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup);
|
||||
pConsumerNew->updateType = CONSUMER_UPDATE_REC;
|
||||
pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup, CONSUMER_UPDATE_REC, NULL, NULL);
|
||||
if (pConsumerNew == NULL){
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_TOPIC, pMsg, "recover-csm");
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_TOPIC, pMsg, "recover-csm");
|
||||
if (pTrans == NULL) {
|
||||
goto FAIL;
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
if (validateTopics(pTrans, pConsumer->assignedTopics, pMnode, pMsg->info.conn.user, false) != 0) {
|
||||
goto FAIL;
|
||||
code = validateTopics(pTrans, pConsumer->assignedTopics, pMnode, pMsg->info.conn.user, false);
|
||||
if (code != 0) {
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto FAIL;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto FAIL;
|
||||
|
||||
tDeleteSMqConsumerObj(pConsumerNew, true);
|
||||
code = mndSetConsumerCommitLogs(pTrans, pConsumerNew);
|
||||
if (code != 0) {
|
||||
goto END;
|
||||
}
|
||||
|
||||
code = mndTransPrepare(pMnode, pTrans);
|
||||
END:
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
tDeleteSMqConsumerObj(pConsumerNew);
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
FAIL:
|
||||
tDeleteSMqConsumerObj(pConsumerNew, true);
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
// todo check the clear process
|
||||
static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
SMqConsumerClearMsg *pClearMsg = pMsg->pCont;
|
||||
SMqConsumerObj *pConsumerNew = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
|
||||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pClearMsg->consumerId);
|
||||
if (pConsumer == NULL) {
|
||||
|
@ -206,33 +216,37 @@ static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg) {
|
|||
mInfo("consumer:0x%" PRIx64 " needs to be cleared, status %s", pClearMsg->consumerId,
|
||||
mndConsumerStatusName(pConsumer->status));
|
||||
|
||||
SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup);
|
||||
pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup, -1, NULL, NULL);
|
||||
if (pConsumerNew == NULL){
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg, "clear-csm");
|
||||
if (pTrans == NULL) {
|
||||
code = -1;
|
||||
goto END;
|
||||
}
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg, "clear-csm");
|
||||
if (pTrans == NULL) goto FAIL;
|
||||
// this is the drop action, not the update action
|
||||
if (mndSetConsumerDropLogs(pMnode, pTrans, pConsumerNew) != 0) goto FAIL;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto FAIL;
|
||||
code = mndSetConsumerDropLogs(pTrans, pConsumerNew);
|
||||
if (code != 0) {
|
||||
goto END;
|
||||
}
|
||||
|
||||
tDeleteSMqConsumerObj(pConsumerNew, true);
|
||||
code = mndTransPrepare(pMnode, pTrans);
|
||||
|
||||
END:
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
tDeleteSMqConsumerObj(pConsumerNew);
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
|
||||
FAIL:
|
||||
tDeleteSMqConsumerObj(pConsumerNew, true);
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t checkPrivilege(SMnode *pMnode, SMqConsumerObj *pConsumer, SMqHbRsp *rsp, char *user) {
|
||||
rsp->topicPrivileges = taosArrayInit(taosArrayGetSize(pConsumer->currentTopics), sizeof(STopicPrivilege));
|
||||
if (rsp->topicPrivileges == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pConsumer->currentTopics); i++) {
|
||||
char *topic = taosArrayGetP(pConsumer->currentTopics, i);
|
||||
|
@ -253,6 +267,47 @@ static int32_t checkPrivilege(SMnode *pMnode, SMqConsumerObj *pConsumer, SMqHbRs
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void storeOffsetRows(SMnode *pMnode, SMqHbReq *req, SMqConsumerObj *pConsumer){
|
||||
for (int i = 0; i < taosArrayGetSize(req->topics); i++) {
|
||||
TopicOffsetRows *data = taosArrayGet(req->topics, i);
|
||||
mInfo("heartbeat report offset rows.%s:%s", pConsumer->cgroup, data->topicName);
|
||||
|
||||
SMqSubscribeObj *pSub = mndAcquireSubscribe(pMnode, pConsumer->cgroup, data->topicName);
|
||||
if (pSub == NULL) {
|
||||
continue;
|
||||
}
|
||||
taosWLockLatch(&pSub->lock);
|
||||
SMqConsumerEp *pConsumerEp = taosHashGet(pSub->consumerHash, &pConsumer->consumerId, sizeof(int64_t));
|
||||
if (pConsumerEp) {
|
||||
taosArrayDestroy(pConsumerEp->offsetRows);
|
||||
pConsumerEp->offsetRows = data->offsetRows;
|
||||
data->offsetRows = NULL;
|
||||
}
|
||||
taosWUnLockLatch(&pSub->lock);
|
||||
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t buildMqHbRsp(SRpcMsg *pMsg, SMqHbRsp *rsp){
|
||||
int32_t tlen = tSerializeSMqHbRsp(NULL, 0, rsp);
|
||||
if (tlen <= 0){
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
void *buf = rpcMallocCont(tlen);
|
||||
if (buf == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if(tSerializeSMqHbRsp(buf, tlen, rsp) != 0){
|
||||
rpcFreeCont(buf);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pMsg->info.rsp = buf;
|
||||
pMsg->info.rspLen = tlen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
|
@ -261,7 +316,6 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) {
|
|||
SMqConsumerObj *pConsumer = NULL;
|
||||
|
||||
if (tDeserializeSMqHbReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
|
@ -270,7 +324,6 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) {
|
|||
pConsumer = mndAcquireConsumer(pMnode, consumerId);
|
||||
if (pConsumer == NULL) {
|
||||
mError("consumer:0x%" PRIx64 " not exist", consumerId);
|
||||
terrno = TSDB_CODE_MND_CONSUMER_NOT_EXIST;
|
||||
code = TSDB_CODE_MND_CONSUMER_NOT_EXIST;
|
||||
goto end;
|
||||
}
|
||||
|
@ -284,130 +337,29 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) {
|
|||
int32_t status = atomic_load_32(&pConsumer->status);
|
||||
|
||||
if (status == MQ_CONSUMER_STATUS_LOST) {
|
||||
mInfo("try to recover consumer:0x%" PRIx64 "", consumerId);
|
||||
SMqConsumerRecoverMsg *pRecoverMsg = rpcMallocCont(sizeof(SMqConsumerRecoverMsg));
|
||||
|
||||
pRecoverMsg->consumerId = consumerId;
|
||||
SRpcMsg pRpcMsg = {
|
||||
.msgType = TDMT_MND_TMQ_CONSUMER_RECOVER,
|
||||
.pCont = pRecoverMsg,
|
||||
.contLen = sizeof(SMqConsumerRecoverMsg),
|
||||
.info = pMsg->info,
|
||||
};
|
||||
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &pRpcMsg);
|
||||
mInfo("try to recover consumer:0x%" PRIx64, consumerId);
|
||||
mndSendConsumerMsg(pMnode, pConsumer->consumerId, TDMT_MND_TMQ_CONSUMER_RECOVER, &pMsg->info);
|
||||
}
|
||||
|
||||
for (int i = 0; i < taosArrayGetSize(req.topics); i++) {
|
||||
TopicOffsetRows *data = taosArrayGet(req.topics, i);
|
||||
mInfo("heartbeat report offset rows.%s:%s", pConsumer->cgroup, data->topicName);
|
||||
|
||||
SMqSubscribeObj *pSub = mndAcquireSubscribe(pMnode, pConsumer->cgroup, data->topicName);
|
||||
if (pSub == NULL) {
|
||||
#ifdef TMQ_DEBUG
|
||||
ASSERT(0);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
taosWLockLatch(&pSub->lock);
|
||||
SMqConsumerEp *pConsumerEp = taosHashGet(pSub->consumerHash, &consumerId, sizeof(int64_t));
|
||||
if (pConsumerEp) {
|
||||
taosArrayDestroy(pConsumerEp->offsetRows);
|
||||
pConsumerEp->offsetRows = data->offsetRows;
|
||||
data->offsetRows = NULL;
|
||||
}
|
||||
taosWUnLockLatch(&pSub->lock);
|
||||
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
}
|
||||
|
||||
// encode rsp
|
||||
int32_t tlen = tSerializeSMqHbRsp(NULL, 0, &rsp);
|
||||
void *buf = rpcMallocCont(tlen);
|
||||
if (buf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
|
||||
tSerializeSMqHbRsp(buf, tlen, &rsp);
|
||||
pMsg->info.rsp = buf;
|
||||
pMsg->info.rspLen = tlen;
|
||||
storeOffsetRows(pMnode, &req, pConsumer);
|
||||
code = buildMqHbRsp(pMsg, &rsp);
|
||||
|
||||
end:
|
||||
tDeatroySMqHbRsp(&rsp);
|
||||
tDestroySMqHbRsp(&rsp);
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
tDeatroySMqHbReq(&req);
|
||||
tDestroySMqHbReq(&req);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
SMqAskEpReq req = {0};
|
||||
SMqAskEpRsp rsp = {0};
|
||||
|
||||
if (tDeserializeSMqAskEpReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int64_t consumerId = req.consumerId;
|
||||
int32_t epoch = req.epoch;
|
||||
|
||||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, consumerId);
|
||||
if (pConsumer == NULL) {
|
||||
mError("consumer:0x%" PRIx64 " group:%s not exists in sdb", consumerId, req.cgroup);
|
||||
terrno = TSDB_CODE_MND_CONSUMER_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ret = strncmp(req.cgroup, pConsumer->cgroup, tListLen(pConsumer->cgroup));
|
||||
if (ret != 0) {
|
||||
mError("consumer:0x%" PRIx64 " group:%s not consistent with data in sdb, saved cgroup:%s", consumerId, req.cgroup,
|
||||
pConsumer->cgroup);
|
||||
terrno = TSDB_CODE_MND_CONSUMER_NOT_EXIST;
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
atomic_store_32(&pConsumer->hbStatus, 0);
|
||||
|
||||
// 1. check consumer status
|
||||
int32_t status = atomic_load_32(&pConsumer->status);
|
||||
|
||||
if (status == MQ_CONSUMER_STATUS_LOST) {
|
||||
mInfo("try to recover consumer:0x%" PRIx64, consumerId);
|
||||
SMqConsumerRecoverMsg *pRecoverMsg = rpcMallocCont(sizeof(SMqConsumerRecoverMsg));
|
||||
|
||||
pRecoverMsg->consumerId = consumerId;
|
||||
SRpcMsg pRpcMsg = {
|
||||
.msgType = TDMT_MND_TMQ_CONSUMER_RECOVER,
|
||||
.pCont = pRecoverMsg,
|
||||
.contLen = sizeof(SMqConsumerRecoverMsg),
|
||||
.info = pMsg->info,
|
||||
};
|
||||
|
||||
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &pRpcMsg);
|
||||
}
|
||||
|
||||
if (status != MQ_CONSUMER_STATUS_READY) {
|
||||
mInfo("consumer:0x%" PRIx64 " not ready, status: %s", consumerId, mndConsumerStatusName(status));
|
||||
terrno = TSDB_CODE_MND_CONSUMER_NOT_READY;
|
||||
goto FAIL;
|
||||
}
|
||||
|
||||
int32_t serverEpoch = atomic_load_32(&pConsumer->epoch);
|
||||
|
||||
// 2. check epoch, only send ep info when epochs do not match
|
||||
if (epoch != serverEpoch) {
|
||||
static int32_t addEpSetInfo(SMnode *pMnode, SMqConsumerObj *pConsumer, int32_t epoch, SMqAskEpRsp *rsp){
|
||||
taosRLockLatch(&pConsumer->lock);
|
||||
mInfo("process ask ep, consumer:0x%" PRIx64 "(epoch %d) update with server epoch %d", consumerId, epoch,
|
||||
serverEpoch);
|
||||
|
||||
int32_t numOfTopics = taosArrayGetSize(pConsumer->currentTopics);
|
||||
|
||||
rsp.topics = taosArrayInit(numOfTopics, sizeof(SMqSubTopicEp));
|
||||
if (rsp.topics == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
rsp->topics = taosArrayInit(numOfTopics, sizeof(SMqSubTopicEp));
|
||||
if (rsp->topics == NULL) {
|
||||
taosRUnLockLatch(&pConsumer->lock);
|
||||
goto FAIL;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// handle all topics subscribed by this consumer
|
||||
|
@ -416,9 +368,6 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
|
|||
SMqSubscribeObj *pSub = mndAcquireSubscribe(pMnode, pConsumer->cgroup, topic);
|
||||
// txn guarantees pSub is created
|
||||
if (pSub == NULL) {
|
||||
#ifdef TMQ_DEBUG
|
||||
ASSERT(0);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
taosRLockLatch(&pSub->lock);
|
||||
|
@ -429,9 +378,6 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
|
|||
// 2.1 fetch topic schema
|
||||
SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic);
|
||||
if (pTopic == NULL) {
|
||||
#ifdef TMQ_DEBUG
|
||||
ASSERT(0);
|
||||
#endif
|
||||
taosRUnLockLatch(&pSub->lock);
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
continue;
|
||||
|
@ -447,17 +393,16 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
|
|||
mndReleaseTopic(pMnode, pTopic);
|
||||
|
||||
// 2.2 iterate all vg assigned to the consumer of that topic
|
||||
SMqConsumerEp *pConsumerEp = taosHashGet(pSub->consumerHash, &consumerId, sizeof(int64_t));
|
||||
SMqConsumerEp *pConsumerEp = taosHashGet(pSub->consumerHash, &pConsumer->consumerId, sizeof(int64_t));
|
||||
int32_t vgNum = taosArrayGetSize(pConsumerEp->vgs);
|
||||
|
||||
// this customer assigned vgroups
|
||||
topicEp.vgs = taosArrayInit(vgNum, sizeof(SMqSubVgEp));
|
||||
if (topicEp.vgs == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosRUnLockLatch(&pConsumer->lock);
|
||||
taosRUnLockLatch(&pSub->lock);
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
goto FAIL;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (int32_t j = 0; j < vgNum; j++) {
|
||||
|
@ -481,49 +426,102 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
|
|||
|
||||
taosArrayPush(topicEp.vgs, &vgEp);
|
||||
}
|
||||
taosArrayPush(rsp.topics, &topicEp);
|
||||
taosArrayPush(rsp->topics, &topicEp);
|
||||
|
||||
taosRUnLockLatch(&pSub->lock);
|
||||
mndReleaseSubscribe(pMnode, pSub);
|
||||
}
|
||||
taosRUnLockLatch(&pConsumer->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t buildAskEpRsp(SRpcMsg *pMsg, SMqAskEpRsp *rsp, int32_t serverEpoch, int64_t consumerId){
|
||||
// encode rsp
|
||||
int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqAskEpRsp(NULL, &rsp);
|
||||
int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqAskEpRsp(NULL, rsp);
|
||||
void *buf = rpcMallocCont(tlen);
|
||||
if (buf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto FAIL;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SMqRspHead *pHead = buf;
|
||||
|
||||
pHead->mqMsgType = TMQ_MSG_TYPE__EP_RSP;
|
||||
pHead->epoch = serverEpoch;
|
||||
pHead->consumerId = pConsumer->consumerId;
|
||||
pHead->consumerId = consumerId;
|
||||
pHead->walsver = 0;
|
||||
pHead->walever = 0;
|
||||
|
||||
void *abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
|
||||
tEncodeSMqAskEpRsp(&abuf, &rsp);
|
||||
|
||||
// release consumer and free memory
|
||||
tDeleteSMqAskEpRsp(&rsp);
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
tEncodeSMqAskEpRsp(&abuf, rsp);
|
||||
|
||||
// send rsp
|
||||
pMsg->info.rsp = buf;
|
||||
pMsg->info.rspLen = tlen;
|
||||
return 0;
|
||||
|
||||
FAIL:
|
||||
tDeleteSMqAskEpRsp(&rsp);
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mndSetConsumerDropLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer) {
|
||||
static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
SMqAskEpReq req = {0};
|
||||
SMqAskEpRsp rsp = {0};
|
||||
int32_t code = 0;
|
||||
|
||||
if (tDeserializeSMqAskEpReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int64_t consumerId = req.consumerId;
|
||||
|
||||
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, consumerId);
|
||||
if (pConsumer == NULL) {
|
||||
mError("consumer:0x%" PRIx64 " group:%s not exists in sdb", consumerId, req.cgroup);
|
||||
return TSDB_CODE_MND_CONSUMER_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (strncmp(req.cgroup, pConsumer->cgroup, tListLen(pConsumer->cgroup)) != 0) {
|
||||
mError("consumer:0x%" PRIx64 " group:%s not consistent with data in sdb, saved cgroup:%s", consumerId, req.cgroup,
|
||||
pConsumer->cgroup);
|
||||
code = TSDB_CODE_MND_CONSUMER_NOT_EXIST;
|
||||
goto END;
|
||||
}
|
||||
|
||||
atomic_store_32(&pConsumer->hbStatus, 0);
|
||||
|
||||
// 1. check consumer status
|
||||
int32_t status = atomic_load_32(&pConsumer->status);
|
||||
|
||||
if (status == MQ_CONSUMER_STATUS_LOST) {
|
||||
mndSendConsumerMsg(pMnode, pConsumer->consumerId, TDMT_MND_TMQ_CONSUMER_RECOVER, &pMsg->info);
|
||||
}
|
||||
|
||||
if (status != MQ_CONSUMER_STATUS_READY) {
|
||||
mInfo("consumer:0x%" PRIx64 " not ready, status: %s", consumerId, mndConsumerStatusName(status));
|
||||
code = TSDB_CODE_MND_CONSUMER_NOT_READY;
|
||||
goto END;
|
||||
}
|
||||
|
||||
int32_t epoch = req.epoch;
|
||||
int32_t serverEpoch = atomic_load_32(&pConsumer->epoch);
|
||||
|
||||
// 2. check epoch, only send ep info when epochs do not match
|
||||
if (epoch != serverEpoch) {
|
||||
mInfo("process ask ep, consumer:0x%" PRIx64 "(epoch %d) update with server epoch %d",
|
||||
consumerId, epoch, serverEpoch);
|
||||
code = addEpSetInfo(pMnode, pConsumer, epoch, &rsp);
|
||||
if(code != 0){
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
code = buildAskEpRsp(pMsg, &rsp, serverEpoch, consumerId);
|
||||
|
||||
END:
|
||||
tDeleteSMqAskEpRsp(&rsp);
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndSetConsumerDropLogs(STrans *pTrans, SMqConsumerObj *pConsumer) {
|
||||
SSdbRaw *pCommitRaw = mndConsumerActionEncode(pConsumer);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
|
@ -531,7 +529,7 @@ int32_t mndSetConsumerDropLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *p
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer) {
|
||||
int32_t mndSetConsumerCommitLogs(STrans *pTrans, SMqConsumerObj *pConsumer) {
|
||||
SSdbRaw *pCommitRaw = mndConsumerActionEncode(pConsumer);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
|
@ -539,8 +537,6 @@ int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void *topicNameDup(void *p) { return taosStrdup((char *)p); }
|
||||
|
||||
static void freeItem(void *param) {
|
||||
void *pItem = *(void **)param;
|
||||
if (pItem != NULL) {
|
||||
|
@ -548,97 +544,19 @@ static void freeItem(void *param) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
char *msgStr = pMsg->pCont;
|
||||
int32_t code = -1;
|
||||
|
||||
SCMSubscribeReq subscribe = {0};
|
||||
tDeserializeSCMSubscribeReq(msgStr, &subscribe);
|
||||
|
||||
int64_t consumerId = subscribe.consumerId;
|
||||
char *cgroup = subscribe.cgroup;
|
||||
SMqConsumerObj *pExistedConsumer = NULL;
|
||||
SMqConsumerObj *pConsumerNew = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
|
||||
SArray *pTopicList = subscribe.topicNames;
|
||||
taosArraySort(pTopicList, taosArrayCompareString);
|
||||
taosArrayRemoveDuplicate(pTopicList, taosArrayCompareString, freeItem);
|
||||
|
||||
int32_t newTopicNum = taosArrayGetSize(pTopicList);
|
||||
for (int i = 0; i < newTopicNum; i++) {
|
||||
int32_t gNum = mndGetGroupNumByTopic(pMnode, (const char *)taosArrayGetP(pTopicList, i));
|
||||
if (gNum >= MND_MAX_GROUP_PER_TOPIC) {
|
||||
terrno = TSDB_CODE_TMQ_GROUP_OUT_OF_RANGE;
|
||||
code = terrno;
|
||||
goto _over;
|
||||
static int32_t getTopicAddDelete(SMqConsumerObj *pExistedConsumer, SMqConsumerObj *pConsumerNew){
|
||||
pConsumerNew->rebNewTopics = taosArrayInit(0, sizeof(void *));
|
||||
pConsumerNew->rebRemovedTopics = taosArrayInit(0, sizeof(void *));
|
||||
if(pConsumerNew->rebNewTopics == NULL || pConsumerNew->rebRemovedTopics == NULL){
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// check topic existence
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_TOPIC_INSIDE, pMsg, "subscribe");
|
||||
if (pTrans == NULL) {
|
||||
goto _over;
|
||||
}
|
||||
|
||||
code = validateTopics(pTrans, pTopicList, pMnode, pMsg->info.conn.user, subscribe.enableReplay);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _over;
|
||||
}
|
||||
|
||||
pExistedConsumer = mndAcquireConsumer(pMnode, consumerId);
|
||||
if (pExistedConsumer == NULL) {
|
||||
mInfo("receive subscribe request from new consumer:0x%" PRIx64 " cgroup:%s, numOfTopics:%d", consumerId,
|
||||
subscribe.cgroup, (int32_t)taosArrayGetSize(pTopicList));
|
||||
|
||||
pConsumerNew = tNewSMqConsumerObj(consumerId, cgroup);
|
||||
tstrncpy(pConsumerNew->clientId, subscribe.clientId, tListLen(pConsumerNew->clientId));
|
||||
|
||||
pConsumerNew->withTbName = subscribe.withTbName;
|
||||
pConsumerNew->autoCommit = subscribe.autoCommit;
|
||||
pConsumerNew->autoCommitInterval = subscribe.autoCommitInterval;
|
||||
pConsumerNew->resetOffsetCfg = subscribe.resetOffsetCfg;
|
||||
|
||||
// pConsumerNew->updateType = CONSUMER_UPDATE_SUB; // use insert logic
|
||||
taosArrayDestroy(pConsumerNew->assignedTopics);
|
||||
pConsumerNew->assignedTopics = taosArrayDup(pTopicList, topicNameDup);
|
||||
|
||||
// all subscribed topics should re-balance.
|
||||
taosArrayDestroy(pConsumerNew->rebNewTopics);
|
||||
pConsumerNew->rebNewTopics = pTopicList;
|
||||
subscribe.topicNames = NULL;
|
||||
|
||||
if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto _over;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _over;
|
||||
} else {
|
||||
int32_t status = atomic_load_32(&pExistedConsumer->status);
|
||||
|
||||
mInfo("receive subscribe request from existed consumer:0x%" PRIx64
|
||||
" cgroup:%s, current status:%d(%s), subscribe topic num: %d",
|
||||
consumerId, subscribe.cgroup, status, mndConsumerStatusName(status), newTopicNum);
|
||||
|
||||
if (status != MQ_CONSUMER_STATUS_READY) {
|
||||
terrno = TSDB_CODE_MND_CONSUMER_NOT_READY;
|
||||
goto _over;
|
||||
}
|
||||
|
||||
pConsumerNew = tNewSMqConsumerObj(consumerId, cgroup);
|
||||
if (pConsumerNew == NULL) {
|
||||
goto _over;
|
||||
}
|
||||
|
||||
// set the update type
|
||||
pConsumerNew->updateType = CONSUMER_UPDATE_SUB;
|
||||
taosArrayDestroy(pConsumerNew->assignedTopics);
|
||||
pConsumerNew->assignedTopics = taosArrayDup(pTopicList, topicNameDup);
|
||||
|
||||
int32_t newTopicNum = taosArrayGetSize(pConsumerNew->assignedTopics);
|
||||
int32_t oldTopicNum = taosArrayGetSize(pExistedConsumer->currentTopics);
|
||||
|
||||
int32_t i = 0, j = 0;
|
||||
while (i < oldTopicNum || j < newTopicNum) {
|
||||
if (i >= oldTopicNum) {
|
||||
char *newTopicCopy = taosStrdup(taosArrayGetP(pTopicList, j));
|
||||
char *newTopicCopy = taosStrdup(taosArrayGetP(pConsumerNew->assignedTopics, j));
|
||||
taosArrayPush(pConsumerNew->rebNewTopics, &newTopicCopy);
|
||||
j++;
|
||||
continue;
|
||||
|
@ -649,7 +567,7 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
|||
continue;
|
||||
} else {
|
||||
char *oldTopic = taosArrayGetP(pExistedConsumer->currentTopics, i);
|
||||
char *newTopic = taosArrayGetP(pTopicList, j);
|
||||
char *newTopic = taosArrayGetP(pConsumerNew->assignedTopics, j);
|
||||
int comp = strcmp(oldTopic, newTopic);
|
||||
if (comp == 0) {
|
||||
i++;
|
||||
|
@ -668,28 +586,114 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
|||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// no topics need to be rebalanced
|
||||
if (taosArrayGetSize(pConsumerNew->rebNewTopics) == 0 && taosArrayGetSize(pConsumerNew->rebRemovedTopics) == 0) {
|
||||
static int32_t checkAndSortTopic(SMnode *pMnode, SArray *pTopicList){
|
||||
taosArraySort(pTopicList, taosArrayCompareString);
|
||||
taosArrayRemoveDuplicate(pTopicList, taosArrayCompareString, freeItem);
|
||||
|
||||
int32_t newTopicNum = taosArrayGetSize(pTopicList);
|
||||
for (int i = 0; i < newTopicNum; i++) {
|
||||
int32_t gNum = mndGetGroupNumByTopic(pMnode, (const char *)taosArrayGetP(pTopicList, i));
|
||||
if (gNum >= MND_MAX_GROUP_PER_TOPIC) {
|
||||
terrno = TSDB_CODE_TMQ_GROUP_OUT_OF_RANGE;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SMqConsumerObj* buildSubConsumer(SMnode *pMnode, SCMSubscribeReq *subscribe){
|
||||
int64_t consumerId = subscribe->consumerId;
|
||||
char *cgroup = subscribe->cgroup;
|
||||
SMqConsumerObj *pConsumerNew = NULL;
|
||||
SMqConsumerObj *pExistedConsumer = NULL;
|
||||
pExistedConsumer = mndAcquireConsumer(pMnode, consumerId);
|
||||
if (pExistedConsumer == NULL) {
|
||||
mInfo("receive subscribe request from new consumer:0x%" PRIx64
|
||||
",cgroup:%s, numOfTopics:%d", consumerId,
|
||||
subscribe->cgroup, (int32_t)taosArrayGetSize(subscribe->topicNames));
|
||||
|
||||
pConsumerNew = tNewSMqConsumerObj(consumerId, cgroup, CONSUMER_INSERT_SUB, NULL, subscribe);
|
||||
if (pConsumerNew == NULL) {
|
||||
goto _over;
|
||||
}
|
||||
} else {
|
||||
int32_t status = atomic_load_32(&pExistedConsumer->status);
|
||||
|
||||
mInfo("receive subscribe request from existed consumer:0x%" PRIx64
|
||||
",cgroup:%s, current status:%d(%s), subscribe topic num: %d",
|
||||
consumerId, subscribe->cgroup, status, mndConsumerStatusName(status),
|
||||
(int32_t)taosArrayGetSize(subscribe->topicNames));
|
||||
|
||||
if (status != MQ_CONSUMER_STATUS_READY) {
|
||||
terrno = TSDB_CODE_MND_CONSUMER_NOT_READY;
|
||||
goto _over;
|
||||
}
|
||||
pConsumerNew = tNewSMqConsumerObj(consumerId, cgroup, CONSUMER_UPDATE_SUB, NULL, subscribe);
|
||||
if (pConsumerNew == NULL) {
|
||||
goto _over;
|
||||
}
|
||||
|
||||
if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto _over;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _over;
|
||||
int32_t code = getTopicAddDelete(pExistedConsumer, pConsumerNew);
|
||||
if (code != 0){
|
||||
terrno = code;
|
||||
goto _over;
|
||||
}
|
||||
}
|
||||
mndReleaseConsumer(pMnode, pExistedConsumer);
|
||||
return pConsumerNew;
|
||||
|
||||
_over:
|
||||
mndReleaseConsumer(pMnode, pExistedConsumer);
|
||||
tDeleteSMqConsumerObj(pConsumerNew);
|
||||
taosArrayDestroyP(subscribe->topicNames, (FDelete)taosMemoryFree);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->info.node;
|
||||
char *msgStr = pMsg->pCont;
|
||||
int32_t code = 0;
|
||||
|
||||
SCMSubscribeReq subscribe = {0};
|
||||
tDeserializeSCMSubscribeReq(msgStr, &subscribe);
|
||||
|
||||
SMqConsumerObj *pConsumerNew = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
|
||||
code = checkAndSortTopic(pMnode, subscribe.topicNames);
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
goto _over;
|
||||
}
|
||||
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_TOPIC_INSIDE, pMsg, "subscribe");
|
||||
if (pTrans == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _over;
|
||||
}
|
||||
|
||||
code = validateTopics(pTrans, subscribe.topicNames, pMnode, pMsg->info.conn.user, subscribe.enableReplay);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _over;
|
||||
}
|
||||
|
||||
pConsumerNew = buildSubConsumer(pMnode, &subscribe);
|
||||
if(pConsumerNew == NULL){
|
||||
code = -1;
|
||||
goto _over;
|
||||
}
|
||||
code = mndSetConsumerCommitLogs(pTrans, pConsumerNew);
|
||||
if (code != 0) goto _over;
|
||||
|
||||
code = mndTransPrepare(pMnode, pTrans);
|
||||
if (code != 0) goto _over;
|
||||
code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
||||
_over:
|
||||
mndTransDrop(pTrans);
|
||||
|
||||
if (pExistedConsumer) {
|
||||
/*taosRUnLockLatch(&pExistedConsumer->lock);*/
|
||||
mndReleaseConsumer(pMnode, pExistedConsumer);
|
||||
}
|
||||
|
||||
tDeleteSMqConsumerObj(pConsumerNew, true);
|
||||
|
||||
tDeleteSMqConsumerObj(pConsumerNew);
|
||||
taosArrayDestroyP(subscribe.topicNames, (FDelete)taosMemoryFree);
|
||||
return code;
|
||||
}
|
||||
|
@ -796,7 +800,7 @@ static int32_t mndConsumerActionInsert(SSdb *pSdb, SMqConsumerObj *pConsumer) {
|
|||
static int32_t mndConsumerActionDelete(SSdb *pSdb, SMqConsumerObj *pConsumer) {
|
||||
mInfo("consumer:0x%" PRIx64 " perform delete action, status:(%d)%s", pConsumer->consumerId, pConsumer->status,
|
||||
mndConsumerStatusName(pConsumer->status));
|
||||
tDeleteSMqConsumerObj(pConsumer, false);
|
||||
tClearSMqConsumerObj(pConsumer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -812,48 +816,17 @@ static void updateConsumerStatus(SMqConsumerObj *pConsumer) {
|
|||
}
|
||||
}
|
||||
|
||||
// remove from new topic
|
||||
static void removeFromNewTopicList(SMqConsumerObj *pConsumer, const char *pTopic) {
|
||||
int32_t size = taosArrayGetSize(pConsumer->rebNewTopics);
|
||||
// remove from topic list
|
||||
static void removeFromTopicList(SArray *topicList, const char *pTopic, int64_t consumerId, char *type) {
|
||||
int32_t size = taosArrayGetSize(topicList);
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
char *p = taosArrayGetP(pConsumer->rebNewTopics, i);
|
||||
char *p = taosArrayGetP(topicList, i);
|
||||
if (strcmp(pTopic, p) == 0) {
|
||||
taosArrayRemove(pConsumer->rebNewTopics, i);
|
||||
taosArrayRemove(topicList, i);
|
||||
taosMemoryFree(p);
|
||||
|
||||
mInfo("consumer:0x%" PRIx64 " remove new topic:%s in the topic list, remain newTopics:%d", pConsumer->consumerId,
|
||||
pTopic, (int)taosArrayGetSize(pConsumer->rebNewTopics));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove from removed topic
|
||||
static void removeFromRemoveTopicList(SMqConsumerObj *pConsumer, const char *pTopic) {
|
||||
int32_t size = taosArrayGetSize(pConsumer->rebRemovedTopics);
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
char *p = taosArrayGetP(pConsumer->rebRemovedTopics, i);
|
||||
if (strcmp(pTopic, p) == 0) {
|
||||
taosArrayRemove(pConsumer->rebRemovedTopics, i);
|
||||
taosMemoryFree(p);
|
||||
|
||||
mInfo("consumer:0x%" PRIx64 " remove topic:%s in the removed topic list, remain removedTopics:%d",
|
||||
pConsumer->consumerId, pTopic, (int)taosArrayGetSize(pConsumer->rebRemovedTopics));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void removeFromCurrentTopicList(SMqConsumerObj *pConsumer, const char *pTopic) {
|
||||
int32_t sz = taosArrayGetSize(pConsumer->currentTopics);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *topic = taosArrayGetP(pConsumer->currentTopics, i);
|
||||
if (strcmp(pTopic, topic) == 0) {
|
||||
taosArrayRemove(pConsumer->currentTopics, i);
|
||||
taosMemoryFree(topic);
|
||||
|
||||
mInfo("consumer:0x%" PRIx64 " remove topic:%s in the current topic list, remain currentTopics:%d",
|
||||
pConsumer->consumerId, pTopic, (int)taosArrayGetSize(pConsumer->currentTopics));
|
||||
mInfo("[rebalance] consumer:0x%" PRIx64 " remove topic:%s in the %s topic list, remain newTopics:%d",
|
||||
consumerId, pTopic, type, (int)taosArrayGetSize(topicList));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -887,60 +860,38 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
|
|||
|
||||
pOldConsumer->subscribeTime = taosGetTimestampMs();
|
||||
pOldConsumer->status = MQ_CONSUMER_STATUS_REBALANCE;
|
||||
mInfo("consumer:0x%" PRIx64 " sub update, modify existed consumer", pOldConsumer->consumerId);
|
||||
// } else if (pNewConsumer->updateType == CONSUMER_UPDATE_TIMER_LOST) {
|
||||
// int32_t sz = taosArrayGetSize(pOldConsumer->currentTopics);
|
||||
// for (int32_t i = 0; i < sz; i++) {
|
||||
// char *topic = taosStrdup(taosArrayGetP(pOldConsumer->currentTopics, i));
|
||||
// taosArrayPush(pOldConsumer->rebRemovedTopics, &topic);
|
||||
// }
|
||||
//
|
||||
// int32_t prevStatus = pOldConsumer->status;
|
||||
// pOldConsumer->status = MQ_CONSUMER_STATUS_LOST;
|
||||
// mInfo("consumer:0x%" PRIx64 " timer update, timer lost. state %s -> %s, reb-time:%" PRId64 ",
|
||||
// reb-removed-topics:%d",
|
||||
// pOldConsumer->consumerId, mndConsumerStatusName(prevStatus),
|
||||
// mndConsumerStatusName(pOldConsumer->status), pOldConsumer->rebalanceTime,
|
||||
// (int)taosArrayGetSize(pOldConsumer->rebRemovedTopics));
|
||||
mInfo("consumer:0x%" PRIx64 " subscribe update, modify existed consumer", pOldConsumer->consumerId);
|
||||
} else if (pNewConsumer->updateType == CONSUMER_UPDATE_REC) {
|
||||
int32_t sz = taosArrayGetSize(pOldConsumer->assignedTopics);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *topic = taosStrdup(taosArrayGetP(pOldConsumer->assignedTopics, i));
|
||||
taosArrayPush(pOldConsumer->rebNewTopics, &topic);
|
||||
}
|
||||
|
||||
pOldConsumer->status = MQ_CONSUMER_STATUS_REBALANCE;
|
||||
mInfo("consumer:0x%" PRIx64 " timer update, timer recover", pOldConsumer->consumerId);
|
||||
mInfo("consumer:0x%" PRIx64 " recover update", pOldConsumer->consumerId);
|
||||
} else if (pNewConsumer->updateType == CONSUMER_UPDATE_REB) {
|
||||
atomic_add_fetch_32(&pOldConsumer->epoch, 1);
|
||||
|
||||
pOldConsumer->rebalanceTime = taosGetTimestampMs();
|
||||
mInfo("consumer:0x%" PRIx64 " reb update, only rebalance time", pOldConsumer->consumerId);
|
||||
mInfo("[rebalance] consumer:0x%" PRIx64 " rebalance update, only rebalance time", pOldConsumer->consumerId);
|
||||
} else if (pNewConsumer->updateType == CONSUMER_ADD_REB) {
|
||||
char *pNewTopic = taosStrdup(taosArrayGetP(pNewConsumer->rebNewTopics, 0));
|
||||
|
||||
// check if exist in current topic
|
||||
removeFromNewTopicList(pOldConsumer, pNewTopic);
|
||||
|
||||
// add to current topic
|
||||
removeFromTopicList(pOldConsumer->rebNewTopics, pNewTopic, pOldConsumer->consumerId, "new");
|
||||
bool existing = existInCurrentTopicList(pOldConsumer, pNewTopic);
|
||||
if (existing) {
|
||||
mError("consumer:0x%" PRIx64 "new topic:%s should not in currentTopics", pOldConsumer->consumerId, pNewTopic);
|
||||
mError("[rebalance] consumer:0x%" PRIx64 " add new topic:%s should not in currentTopics", pOldConsumer->consumerId, pNewTopic);
|
||||
taosMemoryFree(pNewTopic);
|
||||
} else { // added into current topic list
|
||||
} else {
|
||||
taosArrayPush(pOldConsumer->currentTopics, &pNewTopic);
|
||||
taosArraySort(pOldConsumer->currentTopics, taosArrayCompareString);
|
||||
}
|
||||
|
||||
// set status
|
||||
int32_t status = pOldConsumer->status;
|
||||
updateConsumerStatus(pOldConsumer);
|
||||
|
||||
// the re-balance is triggered when the new consumer is launched.
|
||||
pOldConsumer->rebalanceTime = taosGetTimestampMs();
|
||||
|
||||
atomic_add_fetch_32(&pOldConsumer->epoch, 1);
|
||||
mInfo("consumer:0x%" PRIx64 " reb update add, state (%d)%s -> (%d)%s, new epoch:%d, reb-time:%" PRId64
|
||||
|
||||
mInfo("[rebalance] consumer:0x%" PRIx64 " rebalance update add, state (%d)%s -> (%d)%s, new epoch:%d, reb-time:%" PRId64
|
||||
", current topics:%d, newTopics:%d, removeTopics:%d",
|
||||
pOldConsumer->consumerId, status, mndConsumerStatusName(status), pOldConsumer->status,
|
||||
mndConsumerStatusName(pOldConsumer->status), pOldConsumer->epoch, pOldConsumer->rebalanceTime,
|
||||
|
@ -948,22 +899,16 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
|
|||
(int)taosArrayGetSize(pOldConsumer->rebRemovedTopics));
|
||||
|
||||
} else if (pNewConsumer->updateType == CONSUMER_REMOVE_REB) {
|
||||
char *removedTopic = taosArrayGetP(pNewConsumer->rebRemovedTopics, 0);
|
||||
char *topic = taosArrayGetP(pNewConsumer->rebRemovedTopics, 0);
|
||||
removeFromTopicList(pOldConsumer->rebRemovedTopics, topic, pOldConsumer->consumerId, "remove");
|
||||
removeFromTopicList(pOldConsumer->currentTopics, topic, pOldConsumer->consumerId, "current");
|
||||
|
||||
// remove from removed topic
|
||||
removeFromRemoveTopicList(pOldConsumer, removedTopic);
|
||||
|
||||
// remove from current topic
|
||||
removeFromCurrentTopicList(pOldConsumer, removedTopic);
|
||||
|
||||
// set status
|
||||
int32_t status = pOldConsumer->status;
|
||||
updateConsumerStatus(pOldConsumer);
|
||||
|
||||
pOldConsumer->rebalanceTime = taosGetTimestampMs();
|
||||
atomic_add_fetch_32(&pOldConsumer->epoch, 1);
|
||||
|
||||
mInfo("consumer:0x%" PRIx64 " reb update remove, state (%d)%s -> (%d)%s, new epoch:%d, reb-time:%" PRId64
|
||||
mInfo("[rebalance]consumer:0x%" PRIx64 " rebalance update remove, state (%d)%s -> (%d)%s, new epoch:%d, reb-time:%" PRId64
|
||||
", current topics:%d, newTopics:%d, removeTopics:%d",
|
||||
pOldConsumer->consumerId, status, mndConsumerStatusName(status), pOldConsumer->status,
|
||||
mndConsumerStatusName(pOldConsumer->status), pOldConsumer->epoch, pOldConsumer->rebalanceTime,
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mndDb.h"
|
||||
#include "audit.h"
|
||||
#include "mndArbGroup.h"
|
||||
#include "mndCluster.h"
|
||||
#include "mndDnode.h"
|
||||
#include "mndIndex.h"
|
||||
|
@ -30,12 +32,11 @@
|
|||
#include "mndVgroup.h"
|
||||
#include "mndView.h"
|
||||
#include "systable.h"
|
||||
#include "tjson.h"
|
||||
#include "thttp.h"
|
||||
#include "audit.h"
|
||||
#include "tjson.h"
|
||||
|
||||
#define DB_VER_NUMBER 1
|
||||
#define DB_RESERVE_SIZE 42
|
||||
#define DB_RESERVE_SIZE 41
|
||||
|
||||
static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndDbActionInsert(SSdb *pSdb, SDbObj *pDb);
|
||||
|
@ -139,6 +140,7 @@ SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
|
|||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.tsdbPageSize, _OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pDb->compactStartTime, _OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.keepTimeOffset, _OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.withArbitrator, _OVER)
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, DB_RESERVE_SIZE, _OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
||||
|
@ -230,6 +232,7 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.tsdbPageSize, _OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pDb->compactStartTime, _OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.keepTimeOffset, _OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.withArbitrator, _OVER)
|
||||
|
||||
SDB_GET_RESERVE(pRaw, dataPos, DB_RESERVE_SIZE, _OVER)
|
||||
taosInitRWLatch(&pDb->lock);
|
||||
|
@ -319,6 +322,7 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) {
|
|||
pOld->cfg.minRows = pNew->cfg.minRows;
|
||||
pOld->cfg.maxRows = pNew->cfg.maxRows;
|
||||
pOld->cfg.tsdbPageSize = pNew->cfg.tsdbPageSize;
|
||||
pOld->cfg.withArbitrator = pNew->cfg.withArbitrator;
|
||||
pOld->compactStartTime = pNew->compactStartTime;
|
||||
taosWUnLockLatch(&pOld->lock);
|
||||
return 0;
|
||||
|
@ -393,7 +397,11 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
|
|||
if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) return -1;
|
||||
if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) return -1;
|
||||
if (pCfg->replications < TSDB_MIN_DB_REPLICA || pCfg->replications > TSDB_MAX_DB_REPLICA) return -1;
|
||||
#ifdef TD_ENTERPRISE
|
||||
if ((pCfg->replications == 2) ^ (pCfg->withArbitrator == TSDB_MAX_DB_WITH_ARBITRATOR)) return -1;
|
||||
#else
|
||||
if (pCfg->replications != 1 && pCfg->replications != 3) return -1;
|
||||
#endif
|
||||
if (pCfg->strict < TSDB_DB_STRICT_OFF || pCfg->strict > TSDB_DB_STRICT_ON) return -1;
|
||||
if (pCfg->schemaless < TSDB_DB_SCHEMALESS_OFF || pCfg->schemaless > TSDB_DB_SCHEMALESS_ON) return -1;
|
||||
if (pCfg->cacheLast < TSDB_CACHE_MODEL_NONE || pCfg->cacheLast > TSDB_CACHE_MODEL_BOTH) return -1;
|
||||
|
@ -418,33 +426,43 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
|
|||
return terrno;
|
||||
}
|
||||
|
||||
static int32_t mndCheckInChangeDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
|
||||
static int32_t mndCheckInChangeDbCfg(SMnode *pMnode, SDbCfg *pOldCfg, SDbCfg *pNewCfg) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
||||
if (pCfg->buffer < TSDB_MIN_BUFFER_PER_VNODE || pCfg->buffer > TSDB_MAX_BUFFER_PER_VNODE) return -1;
|
||||
if (pCfg->pages < TSDB_MIN_PAGES_PER_VNODE || pCfg->pages > TSDB_MAX_PAGES_PER_VNODE) return -1;
|
||||
if (pCfg->pageSize < TSDB_MIN_PAGESIZE_PER_VNODE || pCfg->pageSize > TSDB_MAX_PAGESIZE_PER_VNODE) return -1;
|
||||
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1;
|
||||
if (pCfg->daysToKeep0 < TSDB_MIN_KEEP || pCfg->daysToKeep0 > TSDB_MAX_KEEP) return -1;
|
||||
if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > TSDB_MAX_KEEP) return -1;
|
||||
if (pCfg->daysToKeep2 < TSDB_MIN_KEEP || pCfg->daysToKeep2 > TSDB_MAX_KEEP) return -1;
|
||||
if (pCfg->daysToKeep0 < pCfg->daysPerFile) return -1;
|
||||
if (pCfg->daysToKeep0 > pCfg->daysToKeep1) return -1;
|
||||
if (pCfg->daysToKeep1 > pCfg->daysToKeep2) return -1;
|
||||
if (pCfg->keepTimeOffset < TSDB_MIN_KEEP_TIME_OFFSET || pCfg->keepTimeOffset > TSDB_MAX_KEEP_TIME_OFFSET) return -1;
|
||||
if (pCfg->walFsyncPeriod < TSDB_MIN_FSYNC_PERIOD || pCfg->walFsyncPeriod > TSDB_MAX_FSYNC_PERIOD) return -1;
|
||||
if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL || pCfg->walLevel > TSDB_MAX_WAL_LEVEL) return -1;
|
||||
if (pCfg->cacheLast < TSDB_CACHE_MODEL_NONE || pCfg->cacheLast > TSDB_CACHE_MODEL_BOTH) return -1;
|
||||
if (pCfg->cacheLastSize < TSDB_MIN_DB_CACHE_SIZE || pCfg->cacheLastSize > TSDB_MAX_DB_CACHE_SIZE) return -1;
|
||||
if (pCfg->replications < TSDB_MIN_DB_REPLICA || pCfg->replications > TSDB_MAX_DB_REPLICA) return -1;
|
||||
if (pCfg->replications != 1 && pCfg->replications != 3) return -1;
|
||||
if (pCfg->sstTrigger < TSDB_MIN_STT_TRIGGER || pCfg->sstTrigger > TSDB_MAX_STT_TRIGGER) return -1;
|
||||
if (pCfg->minRows < TSDB_MIN_MINROWS_FBLOCK || pCfg->minRows > TSDB_MAX_MINROWS_FBLOCK) return -1;
|
||||
if (pCfg->maxRows < TSDB_MIN_MAXROWS_FBLOCK || pCfg->maxRows > TSDB_MAX_MAXROWS_FBLOCK) return -1;
|
||||
if (pCfg->minRows > pCfg->maxRows) return -1;
|
||||
if (pCfg->walRetentionPeriod < TSDB_DB_MIN_WAL_RETENTION_PERIOD) return -1;
|
||||
if (pCfg->walRetentionSize < TSDB_DB_MIN_WAL_RETENTION_SIZE) return -1;
|
||||
if (pCfg->strict < TSDB_DB_STRICT_OFF || pCfg->strict > TSDB_DB_STRICT_ON) return -1;
|
||||
if (pCfg->replications > mndGetDnodeSize(pMnode)) {
|
||||
if (pNewCfg->buffer < TSDB_MIN_BUFFER_PER_VNODE || pNewCfg->buffer > TSDB_MAX_BUFFER_PER_VNODE) return -1;
|
||||
if (pNewCfg->pages < TSDB_MIN_PAGES_PER_VNODE || pNewCfg->pages > TSDB_MAX_PAGES_PER_VNODE) return -1;
|
||||
if (pNewCfg->pageSize < TSDB_MIN_PAGESIZE_PER_VNODE || pNewCfg->pageSize > TSDB_MAX_PAGESIZE_PER_VNODE) return -1;
|
||||
if (pNewCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pNewCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1;
|
||||
if (pNewCfg->daysToKeep0 < TSDB_MIN_KEEP || pNewCfg->daysToKeep0 > TSDB_MAX_KEEP) return -1;
|
||||
if (pNewCfg->daysToKeep1 < TSDB_MIN_KEEP || pNewCfg->daysToKeep1 > TSDB_MAX_KEEP) return -1;
|
||||
if (pNewCfg->daysToKeep2 < TSDB_MIN_KEEP || pNewCfg->daysToKeep2 > TSDB_MAX_KEEP) return -1;
|
||||
if (pNewCfg->daysToKeep0 < pNewCfg->daysPerFile) return -1;
|
||||
if (pNewCfg->daysToKeep0 > pNewCfg->daysToKeep1) return -1;
|
||||
if (pNewCfg->daysToKeep1 > pNewCfg->daysToKeep2) return -1;
|
||||
if (pNewCfg->keepTimeOffset < TSDB_MIN_KEEP_TIME_OFFSET || pNewCfg->keepTimeOffset > TSDB_MAX_KEEP_TIME_OFFSET) return -1;
|
||||
if (pNewCfg->walFsyncPeriod < TSDB_MIN_FSYNC_PERIOD || pNewCfg->walFsyncPeriod > TSDB_MAX_FSYNC_PERIOD) return -1;
|
||||
if (pNewCfg->walLevel < TSDB_MIN_WAL_LEVEL || pNewCfg->walLevel > TSDB_MAX_WAL_LEVEL) return -1;
|
||||
if (pNewCfg->cacheLast < TSDB_CACHE_MODEL_NONE || pNewCfg->cacheLast > TSDB_CACHE_MODEL_BOTH) return -1;
|
||||
if (pNewCfg->cacheLastSize < TSDB_MIN_DB_CACHE_SIZE || pNewCfg->cacheLastSize > TSDB_MAX_DB_CACHE_SIZE) return -1;
|
||||
if (pNewCfg->replications < TSDB_MIN_DB_REPLICA || pNewCfg->replications > TSDB_MAX_DB_REPLICA) return -1;
|
||||
#ifdef TD_ENTERPRISE
|
||||
if ((pNewCfg->replications == 2) ^ (pNewCfg->withArbitrator == TSDB_MAX_DB_WITH_ARBITRATOR)) return -1;
|
||||
if (pNewCfg->replications == 2 && pNewCfg->withArbitrator == TSDB_MAX_DB_WITH_ARBITRATOR) {
|
||||
if (pOldCfg->replications != 1 && pOldCfg->replications != 2) {
|
||||
terrno = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (pNewCfg->replications != 1 && pNewCfg->replications != 3) return -1;
|
||||
#endif
|
||||
if (pNewCfg->sstTrigger < TSDB_MIN_STT_TRIGGER || pNewCfg->sstTrigger > TSDB_MAX_STT_TRIGGER) return -1;
|
||||
if (pNewCfg->minRows < TSDB_MIN_MINROWS_FBLOCK || pNewCfg->minRows > TSDB_MAX_MINROWS_FBLOCK) return -1;
|
||||
if (pNewCfg->maxRows < TSDB_MIN_MAXROWS_FBLOCK || pNewCfg->maxRows > TSDB_MAX_MAXROWS_FBLOCK) return -1;
|
||||
if (pNewCfg->minRows > pNewCfg->maxRows) return -1;
|
||||
if (pNewCfg->walRetentionPeriod < TSDB_DB_MIN_WAL_RETENTION_PERIOD) return -1;
|
||||
if (pNewCfg->walRetentionSize < TSDB_DB_MIN_WAL_RETENTION_SIZE) return -1;
|
||||
if (pNewCfg->strict < TSDB_DB_STRICT_OFF || pNewCfg->strict > TSDB_DB_STRICT_ON) return -1;
|
||||
if (pNewCfg->replications > mndGetDnodeSize(pMnode)) {
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
return -1;
|
||||
}
|
||||
|
@ -484,6 +502,7 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
|
|||
if (pCfg->walSegmentSize < 0) pCfg->walSegmentSize = TSDB_DEFAULT_DB_WAL_SEGMENT_SIZE;
|
||||
if (pCfg->sstTrigger <= 0) pCfg->sstTrigger = TSDB_DEFAULT_SST_TRIGGER;
|
||||
if (pCfg->tsdbPageSize <= 0) pCfg->tsdbPageSize = TSDB_DEFAULT_TSDB_PAGESIZE;
|
||||
if (pCfg->withArbitrator < 0) pCfg->withArbitrator = TSDB_DEFAULT_DB_WITH_ARBITRATOR;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateDbPrepareAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
||||
|
@ -515,6 +534,15 @@ static int32_t mndSetCreateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD
|
|||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_UPDATE) != 0) return -1;
|
||||
}
|
||||
|
||||
if (pDb->cfg.withArbitrator) {
|
||||
for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SVgObj *pVgObj = pVgroups + v;
|
||||
SArbGroup arbGroup = {0};
|
||||
mndArbGroupInitFromVgObj(pVgObj, &arbGroup);
|
||||
if (mndSetCreateArbGroupRedoLogs(pTrans, &arbGroup) != 0) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -531,6 +559,15 @@ static int32_t mndSetCreateDbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD
|
|||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
}
|
||||
|
||||
if (pDb->cfg.withArbitrator) {
|
||||
for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SVgObj *pVgObj = pVgroups + v;
|
||||
SArbGroup arbGroup = {0};
|
||||
mndArbGroupInitFromVgObj(pVgObj, &arbGroup);
|
||||
if (mndSetCreateArbGroupUndoLogs(pTrans, &arbGroup) != 0) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -548,6 +585,15 @@ static int32_t mndSetCreateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *
|
|||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
}
|
||||
|
||||
if (pDb->cfg.withArbitrator) {
|
||||
for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SVgObj *pVgObj = pVgroups + v;
|
||||
SArbGroup arbGroup = {0};
|
||||
mndArbGroupInitFromVgObj(pVgObj, &arbGroup);
|
||||
if (mndSetCreateArbGroupCommitLogs(pTrans, &arbGroup) != 0) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (pUserDuped) {
|
||||
SSdbRaw *pUserRaw = mndUserActionEncode(pUserDuped);
|
||||
if (pUserRaw == NULL) return -1;
|
||||
|
@ -629,6 +675,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
|
|||
.hashPrefix = pCreate->hashPrefix,
|
||||
.hashSuffix = pCreate->hashSuffix,
|
||||
.tsdbPageSize = pCreate->tsdbPageSize,
|
||||
.withArbitrator = pCreate->withArbitrator,
|
||||
};
|
||||
|
||||
dbObj.cfg.numOfRetensions = pCreate->numOfRetensions;
|
||||
|
@ -893,6 +940,12 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) {
|
|||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->withArbitrator != pDb->cfg.withArbitrator) {
|
||||
pDb->cfg.withArbitrator = pAlter->withArbitrator;
|
||||
pDb->vgVersion++;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
return terrno;
|
||||
}
|
||||
|
||||
|
@ -931,12 +984,24 @@ static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *
|
|||
if (pIter == NULL) break;
|
||||
|
||||
if (mndVgroupInDb(pVgroup, pNewDb->uid)) {
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pOldDb, pNewDb, pVgroup, pArray) != 0) {
|
||||
SVgObj newVgroup = {0};
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pOldDb, pNewDb, pVgroup, pArray, &newVgroup) != 0) {
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
taosArrayDestroy(pArray);
|
||||
return -1;
|
||||
}
|
||||
if (pNewDb->cfg.withArbitrator != pOldDb->cfg.withArbitrator) {
|
||||
if (pNewDb->cfg.withArbitrator) {
|
||||
SArbGroup arbGroup = {0};
|
||||
mndArbGroupInitFromVgObj(&newVgroup, &arbGroup);
|
||||
if (mndSetCreateArbGroupCommitLogs(pTrans, &arbGroup) != 0) return -1;
|
||||
} else {
|
||||
SArbGroup arbGroup = {0};
|
||||
mndArbGroupInitFromVgObj(pVgroup, &arbGroup);
|
||||
if (mndSetDropArbGroupCommitLogs(pTrans, &arbGroup) != 0) return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
|
@ -1013,7 +1078,7 @@ static int32_t mndProcessAlterDbReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
code = mndCheckInChangeDbCfg(pMnode, &dbObj.cfg);
|
||||
code = mndCheckInChangeDbCfg(pMnode, &pDb->cfg, &dbObj.cfg);
|
||||
if (code != 0) goto _OVER;
|
||||
|
||||
dbObj.cfgVersion++;
|
||||
|
@ -1081,6 +1146,7 @@ static void mndDumpDbCfgInfo(SDbCfgRsp *cfgRsp, SDbObj *pDb) {
|
|||
cfgRsp->pRetensions = taosArrayDup(pDb->cfg.pRetensions, NULL);
|
||||
cfgRsp->schemaless = pDb->cfg.schemaless;
|
||||
cfgRsp->sstTrigger = pDb->cfg.sstTrigger;
|
||||
cfgRsp->withArbitrator = pDb->cfg.withArbitrator;
|
||||
}
|
||||
|
||||
static int32_t mndProcessGetDbCfgReq(SRpcMsg *pReq) {
|
||||
|
@ -1150,6 +1216,22 @@ static int32_t mndSetDropDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pD
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
|
||||
while (1) {
|
||||
SArbGroup *pArbGroup = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_ARBGROUP, pIter, (void **)&pArbGroup);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
if (pArbGroup->dbUid == pDb->uid) {
|
||||
if (mndSetDropArbGroupCommitLogs(pTrans,pArbGroup) != 0) {
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pArbGroup);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pArbGroup);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
SVgObj *pVgroup = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
|
@ -1390,7 +1472,7 @@ static void mndBuildDBVgroupInfo(SDbObj *pDb, SMnode *pMnode, SArray *pVgList) {
|
|||
pEp->port = pDnode->port;
|
||||
}
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
if (pVgid->syncState == TAOS_SYNC_STATE_LEADER) {
|
||||
if (pVgid->syncState == TAOS_SYNC_STATE_LEADER || pVgid->syncState == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
vgInfo.epSet.inUse = gid;
|
||||
}
|
||||
}
|
||||
|
@ -1562,21 +1644,19 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbCacheInfo *pDbs, int32_t numOfDbs,
|
|||
|
||||
int32_t numOfTable = mndGetDBTableNum(pDb, pMnode);
|
||||
|
||||
if (pDbCacheInfo->vgVersion >= pDb->vgVersion &&
|
||||
pDbCacheInfo->cfgVersion >= pDb->cfgVersion &&
|
||||
numOfTable == pDbCacheInfo->numOfTable &&
|
||||
pDbCacheInfo->stateTs == pDb->stateTs) {
|
||||
if (pDbCacheInfo->vgVersion >= pDb->vgVersion && pDbCacheInfo->cfgVersion >= pDb->cfgVersion &&
|
||||
numOfTable == pDbCacheInfo->numOfTable && pDbCacheInfo->stateTs == pDb->stateTs) {
|
||||
mTrace("db:%s, valid dbinfo, vgVersion:%d cfgVersion:%d stateTs:%" PRId64
|
||||
" numOfTables:%d, not changed vgVersion:%d cfgVersion:%d stateTs:%" PRId64 " numOfTables:%d",
|
||||
pDbCacheInfo->dbFName, pDbCacheInfo->vgVersion, pDbCacheInfo->cfgVersion, pDbCacheInfo->stateTs, pDbCacheInfo->numOfTable,
|
||||
pDb->vgVersion, pDb->cfgVersion, pDb->stateTs, numOfTable);
|
||||
pDbCacheInfo->dbFName, pDbCacheInfo->vgVersion, pDbCacheInfo->cfgVersion, pDbCacheInfo->stateTs,
|
||||
pDbCacheInfo->numOfTable, pDb->vgVersion, pDb->cfgVersion, pDb->stateTs, numOfTable);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
continue;
|
||||
} else {
|
||||
mInfo("db:%s, valid dbinfo, vgVersion:%d cfgVersion:%d stateTs:%" PRId64
|
||||
" numOfTables:%d, changed to vgVersion:%d cfgVersion:%d stateTs:%" PRId64 " numOfTables:%d",
|
||||
pDbCacheInfo->dbFName, pDbCacheInfo->vgVersion, pDbCacheInfo->cfgVersion, pDbCacheInfo->stateTs, pDbCacheInfo->numOfTable,
|
||||
pDb->vgVersion, pDb->cfgVersion, pDb->stateTs, numOfTable);
|
||||
pDbCacheInfo->dbFName, pDbCacheInfo->vgVersion, pDbCacheInfo->cfgVersion, pDbCacheInfo->stateTs,
|
||||
pDbCacheInfo->numOfTable, pDb->vgVersion, pDb->cfgVersion, pDb->stateTs, numOfTable);
|
||||
}
|
||||
|
||||
if (pDbCacheInfo->cfgVersion < pDb->cfgVersion) {
|
||||
|
@ -1584,8 +1664,7 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbCacheInfo *pDbs, int32_t numOfDbs,
|
|||
mndDumpDbCfgInfo(rsp.cfgRsp, pDb);
|
||||
}
|
||||
|
||||
if (pDbCacheInfo->vgVersion < pDb->vgVersion ||
|
||||
numOfTable != pDbCacheInfo->numOfTable ||
|
||||
if (pDbCacheInfo->vgVersion < pDb->vgVersion || numOfTable != pDbCacheInfo->numOfTable ||
|
||||
pDbCacheInfo->stateTs != pDb->stateTs) {
|
||||
rsp.useDbRsp = taosMemoryCalloc(1, sizeof(SUseDbRsp));
|
||||
rsp.useDbRsp->pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo));
|
||||
|
@ -1801,7 +1880,8 @@ bool mndIsDbReady(SMnode *pMnode, SDbObj *pDb) {
|
|||
if (pVgroup->dbUid == pDb->uid && pVgroup->replica > 1) {
|
||||
bool hasLeader = false;
|
||||
for (int32_t i = 0; i < pVgroup->replica; ++i) {
|
||||
if (pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_LEADER) {
|
||||
if (pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_LEADER ||
|
||||
pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
hasLeader = true;
|
||||
}
|
||||
}
|
||||
|
@ -1991,6 +2071,9 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
|
|||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, rows, (const char *)&pDb->cfg.keepTimeOffset, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataSetVal(pColInfo, rows, (const char *)&pDb->cfg.withArbitrator, false);
|
||||
}
|
||||
|
||||
taosMemoryFree(buf);
|
||||
|
|
|
@ -249,7 +249,9 @@ void *tDecodeSMqVgEp(const void *buf, SMqVgEp *pVgEp, int8_t sver) {
|
|||
return (void *)buf;
|
||||
}
|
||||
|
||||
SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char *cgroup) {
|
||||
static void *topicNameDup(void *p) { return taosStrdup((char *)p); }
|
||||
|
||||
SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType, char *topic, SCMSubscribeReq *subscribe) {
|
||||
SMqConsumerObj *pConsumer = taosMemoryCalloc(1, sizeof(SMqConsumerObj));
|
||||
if (pConsumer == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -264,36 +266,64 @@ SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char *cgroup) {
|
|||
pConsumer->hbStatus = 0;
|
||||
|
||||
taosInitRWLatch(&pConsumer->lock);
|
||||
pConsumer->createTime = taosGetTimestampMs();
|
||||
pConsumer->updateType = updateType;
|
||||
|
||||
pConsumer->currentTopics = taosArrayInit(0, sizeof(void *));
|
||||
if (updateType == CONSUMER_ADD_REB){
|
||||
pConsumer->rebNewTopics = taosArrayInit(0, sizeof(void *));
|
||||
pConsumer->rebRemovedTopics = taosArrayInit(0, sizeof(void *));
|
||||
pConsumer->assignedTopics = taosArrayInit(0, sizeof(void *));
|
||||
if(pConsumer->rebNewTopics == NULL){
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (pConsumer->currentTopics == NULL || pConsumer->rebNewTopics == NULL || pConsumer->rebRemovedTopics == NULL ||
|
||||
pConsumer->assignedTopics == NULL) {
|
||||
taosArrayDestroy(pConsumer->currentTopics);
|
||||
taosArrayDestroy(pConsumer->rebNewTopics);
|
||||
taosArrayDestroy(pConsumer->rebRemovedTopics);
|
||||
taosArrayDestroy(pConsumer->assignedTopics);
|
||||
taosMemoryFree(pConsumer);
|
||||
char* topicTmp = taosStrdup(topic);
|
||||
taosArrayPush(pConsumer->rebNewTopics, &topicTmp);
|
||||
}else if (updateType == CONSUMER_REMOVE_REB) {
|
||||
pConsumer->rebRemovedTopics = taosArrayInit(0, sizeof(void *));
|
||||
if(pConsumer->rebRemovedTopics == NULL){
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto END;
|
||||
}
|
||||
char* topicTmp = taosStrdup(topic);
|
||||
taosArrayPush(pConsumer->rebRemovedTopics, &topicTmp);
|
||||
}else if (updateType == CONSUMER_INSERT_SUB){
|
||||
tstrncpy(pConsumer->clientId, subscribe->clientId, tListLen(pConsumer->clientId));
|
||||
pConsumer->withTbName = subscribe->withTbName;
|
||||
pConsumer->autoCommit = subscribe->autoCommit;
|
||||
pConsumer->autoCommitInterval = subscribe->autoCommitInterval;
|
||||
pConsumer->resetOffsetCfg = subscribe->resetOffsetCfg;
|
||||
|
||||
|
||||
pConsumer->rebNewTopics = taosArrayDup(subscribe->topicNames, topicNameDup);
|
||||
if (pConsumer->rebNewTopics == NULL){
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto END;
|
||||
}
|
||||
pConsumer->assignedTopics = subscribe->topicNames;
|
||||
subscribe->topicNames = NULL;
|
||||
}else if (updateType == CONSUMER_UPDATE_SUB){
|
||||
pConsumer->assignedTopics = subscribe->topicNames;
|
||||
subscribe->topicNames = NULL;
|
||||
}
|
||||
|
||||
return pConsumer;
|
||||
|
||||
END:
|
||||
tDeleteSMqConsumerObj(pConsumer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pConsumer->createTime = taosGetTimestampMs();
|
||||
|
||||
return pConsumer;
|
||||
}
|
||||
|
||||
void tDeleteSMqConsumerObj(SMqConsumerObj *pConsumer, bool delete) {
|
||||
void tClearSMqConsumerObj(SMqConsumerObj *pConsumer) {
|
||||
if (pConsumer == NULL) return;
|
||||
taosArrayDestroyP(pConsumer->currentTopics, (FDelete)taosMemoryFree);
|
||||
taosArrayDestroyP(pConsumer->rebNewTopics, (FDelete)taosMemoryFree);
|
||||
taosArrayDestroyP(pConsumer->rebRemovedTopics, (FDelete)taosMemoryFree);
|
||||
taosArrayDestroyP(pConsumer->assignedTopics, (FDelete)taosMemoryFree);
|
||||
if (delete) {
|
||||
taosMemoryFree(pConsumer);
|
||||
}
|
||||
|
||||
void tDeleteSMqConsumerObj(SMqConsumerObj *pConsumer) {
|
||||
tClearSMqConsumerObj(pConsumer);
|
||||
taosMemoryFree(pConsumer);
|
||||
}
|
||||
|
||||
int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
|
||||
|
@ -548,6 +578,7 @@ SMqSubscribeObj *tCloneSubscribeObj(const SMqSubscribeObj *pSub) {
|
|||
}
|
||||
|
||||
void tDeleteSubscribeObj(SMqSubscribeObj *pSub) {
|
||||
if (pSub == NULL) return;
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pSub->consumerHash, pIter);
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "taos_monitor.h"
|
||||
|
||||
#define TSDB_DNODE_VER_NUMBER 2
|
||||
#define TSDB_DNODE_RESERVE_SIZE 64
|
||||
#define TSDB_DNODE_RESERVE_SIZE 40
|
||||
|
||||
static const char *offlineReason[] = {
|
||||
"",
|
||||
|
@ -183,11 +183,10 @@ static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) {
|
|||
SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime, _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pDnode->port, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pDnode->machineId, TSDB_MACHINE_ID_LEN, _OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, TSDB_ACTIVE_KEY_LEN, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pDnode->active, TSDB_ACTIVE_KEY_LEN, _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, TSDB_CONN_ACTIVE_KEY_LEN, _OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pDnode->connActive, TSDB_CONN_ACTIVE_KEY_LEN, _OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, 0, _OVER) // forward/backward compatible
|
||||
SDB_SET_INT16(pRaw, dataPos, 0, _OVER) // forward/backward compatible
|
||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER);
|
||||
|
||||
terrno = 0;
|
||||
|
@ -227,13 +226,14 @@ static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT64(pRaw, dataPos, &pDnode->updateTime, _OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &pDnode->port, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pDnode->machineId, TSDB_MACHINE_ID_LEN, _OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, _OVER)
|
||||
if (sver > 1) {
|
||||
int16_t keyLen = 0;
|
||||
SDB_GET_INT16(pRaw, dataPos, &keyLen, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pDnode->active, keyLen, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, NULL, keyLen, _OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &keyLen, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pDnode->connActive, keyLen, _OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, NULL, keyLen, _OVER)
|
||||
}
|
||||
|
||||
terrno = 0;
|
||||
|
@ -271,12 +271,7 @@ static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOld, SDnodeObj *pNew
|
|||
mTrace("dnode:%d, perform update action, old row:%p new row:%p", pOld->id, pOld, pNew);
|
||||
pOld->updateTime = pNew->updateTime;
|
||||
#ifdef TD_ENTERPRISE
|
||||
if (strncmp(pOld->active, pNew->active, TSDB_ACTIVE_KEY_LEN) != 0) {
|
||||
strncpy(pOld->active, pNew->active, TSDB_ACTIVE_KEY_LEN);
|
||||
}
|
||||
if (strncmp(pOld->connActive, pNew->connActive, TSDB_CONN_ACTIVE_KEY_LEN) != 0) {
|
||||
strncpy(pOld->connActive, pNew->connActive, TSDB_CONN_ACTIVE_KEY_LEN);
|
||||
}
|
||||
tstrncpy(pOld->machineId, pNew->machineId, TSDB_MACHINE_ID_LEN + 1);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -311,6 +306,17 @@ SEpSet mndGetDnodeEpset(SDnodeObj *pDnode) {
|
|||
return epSet;
|
||||
}
|
||||
|
||||
SEpSet mndGetDnodeEpsetById(SMnode *pMnode, int32_t dnodeId) {
|
||||
SEpSet epSet = {0};
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, dnodeId);
|
||||
if (!pDnode) return epSet;
|
||||
|
||||
epSet = mndGetDnodeEpset(pDnode);
|
||||
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
return epSet;
|
||||
}
|
||||
|
||||
static SDnodeObj *mndAcquireDnodeByEp(SMnode *pMnode, char *pEpStr) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
|
@ -705,6 +711,35 @@ _OVER:
|
|||
*/
|
||||
}
|
||||
|
||||
static int32_t mndUpdateDnodeObj(SMnode *pMnode, SDnodeObj *pDnode) {
|
||||
int32_t code = 0;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, NULL, "update-dnode-obj");
|
||||
if (pTrans == NULL) {
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
pDnode->updateTime = taosGetTimestampMs();
|
||||
|
||||
SSdbRaw *pCommitRaw = mndDnodeActionEncode(pDnode);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
_exit:
|
||||
mndTransDrop(pTrans);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SStatusReq statusReq = {0};
|
||||
|
@ -776,7 +811,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
|||
|
||||
SVgObj *pVgroup = mndAcquireVgroup(pMnode, pVload->vgId);
|
||||
if (pVgroup != NULL) {
|
||||
if (pVload->syncState == TAOS_SYNC_STATE_LEADER) {
|
||||
if (pVload->syncState == TAOS_SYNC_STATE_LEADER || pVload->syncState == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
pVgroup->cacheUsage = pVload->cacheUsage;
|
||||
pVgroup->numOfCachedTables = pVload->numOfCachedTables;
|
||||
pVgroup->numOfTables = pVload->numOfTables;
|
||||
|
@ -874,8 +909,9 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
|||
pDnode->numOfDiskCfg = statusReq.numOfDiskCfg;
|
||||
pDnode->memAvail = statusReq.memAvail;
|
||||
pDnode->memTotal = statusReq.memTotal;
|
||||
if (pDnode->machineId[0] == 0 && statusReq.machineId[0] != 0) {
|
||||
if (memcmp(pDnode->machineId, statusReq.machineId, TSDB_MACHINE_ID_LEN) != 0) {
|
||||
tstrncpy(pDnode->machineId, statusReq.machineId, TSDB_MACHINE_ID_LEN + 1);
|
||||
mndUpdateDnodeObj(pMnode, pDnode);
|
||||
}
|
||||
|
||||
SStatusRsp statusRsp = {0};
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mndAcct.h"
|
||||
#include "mndArbGroup.h"
|
||||
#include "mndCluster.h"
|
||||
#include "mndCompact.h"
|
||||
#include "mndCompactDetail.h"
|
||||
|
@ -140,6 +141,22 @@ static void mndPullupTrimDb(SMnode *pMnode) {
|
|||
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
||||
}
|
||||
|
||||
static int32_t mndPullupArbHeartbeat(SMnode *pMnode) {
|
||||
mTrace("pullup arb hb");
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildTimerMsg(&contLen);
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_ARB_HEARTBEAT_TIMER, .pCont = pReq, .contLen = contLen, .info.noResp = 1};
|
||||
return tmsgPutToQueue(&pMnode->msgCb, ARB_QUEUE, &rpcMsg);
|
||||
}
|
||||
|
||||
static int32_t mndPullupArbCheckSync(SMnode *pMnode) {
|
||||
mTrace("pullup arb sync");
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildTimerMsg(&contLen);
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_ARB_CHECK_SYNC_TIMER, .pCont = pReq, .contLen = contLen, .info.noResp = 1};
|
||||
return tmsgPutToQueue(&pMnode->msgCb, ARB_QUEUE, &rpcMsg);
|
||||
}
|
||||
|
||||
static void mndCalMqRebalance(SMnode *pMnode) {
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildTimerMsg(&contLen);
|
||||
|
@ -391,6 +408,18 @@ static void *mndThreadFp(void *param) {
|
|||
continue;
|
||||
}
|
||||
mndDoTimerPullupTask(pMnode, sec);
|
||||
|
||||
if (sec % (tsArbHeartBeatIntervalSec) == 0) {
|
||||
if (mndPullupArbHeartbeat(pMnode) != 0) {
|
||||
mError("failed to pullup arb heartbeat, since:%s", terrstr());
|
||||
}
|
||||
}
|
||||
|
||||
if (sec % (tsArbCheckSyncIntervalSec) == 0) {
|
||||
if (mndPullupArbCheckSync(pMnode) != 0) {
|
||||
mError("failed to pullup arb check sync, since:%s", terrstr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -513,6 +542,7 @@ static int32_t mndInitSteps(SMnode *pMnode) {
|
|||
if (mndAllocStep(pMnode, "mnode-mnode", mndInitMnode, mndCleanupMnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-qnode", mndInitQnode, mndCleanupQnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-snode", mndInitSnode, mndCleanupSnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-arbgroup", mndInitArbGroup, mndCleanupArbGroup) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-grant", mndInitGrant, mndCleanupGrant) != 0) return -1;
|
||||
|
@ -694,6 +724,13 @@ ESyncRole mndGetRole(SMnode *pMnode) {
|
|||
return syncGetRole(rid);
|
||||
}
|
||||
|
||||
int64_t mndGetTerm(SMnode *pMnode) {
|
||||
int64_t rid = pMnode->syncMgmt.sync;
|
||||
return syncGetTerm(rid);
|
||||
}
|
||||
|
||||
int32_t mndGetArbToken(SMnode *pMnode, char *outToken) { return syncGetArbToken(pMnode->syncMgmt.sync, outToken); }
|
||||
|
||||
void mndStop(SMnode *pMnode) {
|
||||
mndSetStop(pMnode);
|
||||
mndSyncStop(pMnode);
|
||||
|
@ -768,7 +805,8 @@ _OVER:
|
|||
pMsg->msgType == TDMT_MND_TRIM_DB_TIMER || pMsg->msgType == TDMT_MND_UPTIME_TIMER ||
|
||||
pMsg->msgType == TDMT_MND_COMPACT_TIMER || pMsg->msgType == TDMT_MND_NODECHECK_TIMER ||
|
||||
pMsg->msgType == TDMT_MND_GRANT_HB_TIMER || pMsg->msgType == TDMT_MND_STREAM_CHECKPOINT_CANDIDITATE ||
|
||||
pMsg->msgType == TDMT_MND_STREAM_CHECKPOINT_TIMER || pMsg->msgType == TDMT_MND_STREAM_REQ_CHKPT) {
|
||||
pMsg->msgType == TDMT_MND_STREAM_CHECKPOINT_TIMER || pMsg->msgType == TDMT_MND_STREAM_REQ_CHKPT ||
|
||||
pMsg->msgType == TDMT_MND_ARB_HEARTBEAT_TIMER || pMsg->msgType == TDMT_MND_ARB_CHECK_SYNC_TIMER) {
|
||||
mTrace("timer not process since mnode restored:%d stopped:%d, sync restored:%d role:%s ", pMnode->restored,
|
||||
pMnode->stopped, state.restored, syncStr(state.state));
|
||||
return -1;
|
||||
|
@ -951,7 +989,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
|
|||
pVnDesc->dnode_id = pVgid->dnodeId;
|
||||
tstrncpy(pVnDesc->vnode_role, syncStr(pVgid->syncState), sizeof(pVnDesc->vnode_role));
|
||||
pVnDesc->syncState = pVgid->syncState;
|
||||
if (pVgid->syncState == TAOS_SYNC_STATE_LEADER) {
|
||||
if (pVgid->syncState == TAOS_SYNC_STATE_LEADER || pVgid->syncState == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
tstrncpy(desc.status, "ready", sizeof(desc.status));
|
||||
pClusterInfo->vgroups_alive++;
|
||||
}
|
||||
|
|
|
@ -434,7 +434,7 @@ _OVER:
|
|||
}
|
||||
|
||||
mndReleaseQnode(pMnode, pObj);
|
||||
tFreeSMCreateQnodeReq(&dropReq);
|
||||
tFreeSDDropQnodeReq(&dropReq);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,8 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
|
|||
type = TSDB_MGMT_TABLE_QNODE;
|
||||
} else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, len) == 0) {
|
||||
type = TSDB_MGMT_TABLE_SNODE;
|
||||
} else if (strncasecmp(name, TSDB_INS_TABLE_ARBGROUPS, len) == 0) {
|
||||
type = TSDB_MGMT_TABLE_ARBGROUP;
|
||||
} else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, len) == 0) {
|
||||
type = TSDB_MGMT_TABLE_CLUSTER;
|
||||
} else if (strncasecmp(name, TSDB_INS_TABLE_DATABASES, len) == 0) {
|
||||
|
|
|
@ -513,6 +513,7 @@ static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStre
|
|||
createReq.numOfColumns = pStream->outputSchema.nCols;
|
||||
createReq.numOfTags = 1; // group id
|
||||
createReq.pColumns = taosArrayInit_s(sizeof(SField), createReq.numOfColumns);
|
||||
|
||||
// build fields
|
||||
for (int32_t i = 0; i < createReq.numOfColumns; i++) {
|
||||
SField *pField = taosArrayGet(createReq.pColumns, i);
|
||||
|
@ -586,12 +587,15 @@ static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStre
|
|||
mndFreeStb(&stbObj);
|
||||
mndReleaseStb(pMnode, pStb);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
|
||||
mDebug("stream:%s create dst stable:%s, cols:%d", pStream->name, pStream->targetSTbName, pStream->outputSchema.nCols);
|
||||
return 0;
|
||||
|
||||
_OVER:
|
||||
tFreeSMCreateStbReq(&createReq);
|
||||
mndReleaseStb(pMnode, pStb);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
|
||||
mDebug("stream:%s failed to create dst stable:%s, code:%s", pStream->name, pStream->targetSTbName, tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -647,7 +651,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
|
|||
terrno = TSDB_CODE_MND_INVALID_PLATFORM;
|
||||
goto _OVER;
|
||||
#endif
|
||||
mInfo("stream:%s, start to create, sql:%s", createReq.name, createReq.sql);
|
||||
mInfo("stream:%s, start to create stream, sql:%s", createReq.name, createReq.sql);
|
||||
|
||||
if (mndCheckCreateStreamReq(&createReq) != 0) {
|
||||
mError("stream:%s, failed to create since %s", createReq.name, terrstr());
|
||||
|
@ -684,18 +688,21 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
STrans *pTrans = doCreateTrans(pMnode, &streamObj, pReq, MND_STREAM_CREATE_NAME, "create stream tasks on dnodes");
|
||||
STrans *pTrans = doCreateTrans(pMnode, &streamObj, pReq, TRN_CONFLICT_DB, MND_STREAM_CREATE_NAME, "create stream tasks on dnodes");
|
||||
if (pTrans == NULL) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
// create stb for stream
|
||||
if (createReq.createStb == STREAM_CREATE_STABLE_TRUE &&
|
||||
mndCreateStbForStream(pMnode, pTrans, &streamObj, pReq->info.conn.user) < 0) {
|
||||
if (createReq.createStb == STREAM_CREATE_STABLE_TRUE) {
|
||||
if (mndCreateStbForStream(pMnode, pTrans, &streamObj, pReq->info.conn.user) < 0) {
|
||||
mError("trans:%d, failed to create stb for stream %s since %s", pTrans->id, createReq.name, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
goto _OVER;
|
||||
}
|
||||
} else {
|
||||
mDebug("stream:%s no need create stable", createReq.name);
|
||||
}
|
||||
|
||||
// schedule stream task for stream obj
|
||||
if (mndScheduleStream(pMnode, &streamObj, createReq.lastTs, createReq.pVgroupVerList) < 0) {
|
||||
|
@ -724,7 +731,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
|
|||
// add into buffer firstly
|
||||
// to make sure when the hb from vnode arrived, the newly created tasks have been in the task map already.
|
||||
taosThreadMutexLock(&execInfo.lock);
|
||||
mDebug("stream stream:%s tasks register into node list", createReq.name);
|
||||
mDebug("stream stream:%s start to register tasks into task_node_list", createReq.name);
|
||||
saveStreamTasksInfo(&streamObj, &execInfo);
|
||||
taosThreadMutexUnlock(&execInfo.lock);
|
||||
|
||||
|
@ -890,7 +897,7 @@ static int32_t mndProcessStreamCheckpointTrans(SMnode *pMnode, SStreamObj *pStre
|
|||
return -1;
|
||||
}
|
||||
|
||||
STrans *pTrans = doCreateTrans(pMnode, pStream, NULL, MND_STREAM_CHECKPOINT_NAME, "gen checkpoint for stream");
|
||||
STrans *pTrans = doCreateTrans(pMnode, pStream, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_CHECKPOINT_NAME, "gen checkpoint for stream");
|
||||
if (pTrans == NULL) {
|
||||
mError("failed to checkpoint of stream name%s, checkpointId: %" PRId64 ", reason:%s", pStream->name, checkpointId,
|
||||
tstrerror(TSDB_CODE_MND_TRANS_CONFLICT));
|
||||
|
@ -1143,7 +1150,7 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
STrans *pTrans = doCreateTrans(pMnode, pStream, pReq, MND_STREAM_DROP_NAME, "drop stream");
|
||||
STrans *pTrans = doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_DROP_NAME, "drop stream");
|
||||
if (pTrans == NULL) {
|
||||
mError("stream:%s, failed to drop since %s", dropReq.name, terrstr());
|
||||
sdbRelease(pMnode->pSdb, pStream);
|
||||
|
@ -1573,7 +1580,7 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
STrans *pTrans = doCreateTrans(pMnode, pStream, pReq, MND_STREAM_PAUSE_NAME, "pause the stream");
|
||||
STrans *pTrans = doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_PAUSE_NAME, "pause the stream");
|
||||
if (pTrans == NULL) {
|
||||
mError("stream:%s failed to pause stream since %s", pauseReq.name, terrstr());
|
||||
sdbRelease(pMnode->pSdb, pStream);
|
||||
|
@ -1662,7 +1669,7 @@ static int32_t mndProcessResumeStreamReq(SRpcMsg *pReq) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
STrans *pTrans = doCreateTrans(pMnode, pStream, pReq, MND_STREAM_RESUME_NAME, "resume the stream");
|
||||
STrans *pTrans = doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_RESUME_NAME, "resume the stream");
|
||||
if (pTrans == NULL) {
|
||||
mError("stream:%s, failed to resume stream since %s", resumeReq.name, terrstr());
|
||||
sdbRelease(pMnode->pSdb, pStream);
|
||||
|
@ -1794,7 +1801,7 @@ static int32_t mndProcessVgroupChange(SMnode *pMnode, SVgroupChangeInfo *pChange
|
|||
|
||||
// here create only one trans
|
||||
if (pTrans == NULL) {
|
||||
pTrans = doCreateTrans(pMnode, pStream, NULL, MND_STREAM_TASK_UPDATE_NAME, "update task epsets");
|
||||
pTrans = doCreateTrans(pMnode, pStream, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_TASK_UPDATE_NAME, "update task epsets");
|
||||
if (pTrans == NULL) {
|
||||
sdbRelease(pSdb, pStream);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
|
|
|
@ -66,7 +66,7 @@ static void addIntoCheckpointList(SArray* pList, const SFailedCheckpointInfo* pI
|
|||
}
|
||||
|
||||
int32_t mndCreateStreamResetStatusTrans(SMnode *pMnode, SStreamObj *pStream) {
|
||||
STrans *pTrans = doCreateTrans(pMnode, pStream, NULL, MND_STREAM_TASK_RESET_NAME, " reset from failed checkpoint");
|
||||
STrans *pTrans = doCreateTrans(pMnode, pStream, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_TASK_RESET_NAME, " reset from failed checkpoint");
|
||||
if (pTrans == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ static int32_t mndDropOrphanTasks(SMnode* pMnode, SArray* pList) {
|
|||
}
|
||||
|
||||
SStreamObj dummyObj = {.uid = pTask->streamId, .sourceDb = "", .targetSTbName = ""};
|
||||
STrans* pTrans = doCreateTrans(pMnode, &dummyObj, NULL, MND_STREAM_DROP_NAME, "drop stream");
|
||||
STrans* pTrans = doCreateTrans(pMnode, &dummyObj, NULL, TRN_CONFLICT_NOTHING, MND_STREAM_DROP_NAME, "drop stream");
|
||||
if (pTrans == NULL) {
|
||||
mError("failed to create trans to drop orphan tasks since %s", terrstr());
|
||||
return -1;
|
||||
|
|
|
@ -161,8 +161,8 @@ int32_t mndAddtoCheckpointWaitingList(SStreamObj* pStream, int64_t checkpointId)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
STrans *doCreateTrans(SMnode *pMnode, SStreamObj *pStream, SRpcMsg *pReq, const char *name, const char *pMsg) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq, name);
|
||||
STrans *doCreateTrans(SMnode *pMnode, SStreamObj *pStream, SRpcMsg *pReq, ETrnConflct conflict, const char *name, const char *pMsg) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, conflict, pReq, name);
|
||||
if (pTrans == NULL) {
|
||||
mError("failed to build trans:%s, reason: %s", name, tstrerror(TSDB_CODE_OUT_OF_MEMORY));
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -409,6 +409,7 @@ SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) {
|
|||
pFsm->FpApplyQueueItems = mndApplyQueueItems;
|
||||
pFsm->FpReConfigCb = NULL;
|
||||
pFsm->FpBecomeLeaderCb = mndBecomeLeader;
|
||||
pFsm->FpBecomeAssignedLeaderCb = NULL;
|
||||
pFsm->FpBecomeFollowerCb = mndBecomeFollower;
|
||||
pFsm->FpBecomeLearnerCb = mndBecomeLearner;
|
||||
pFsm->FpGetSnapshot = mndSyncGetSnapshot;
|
||||
|
|
|
@ -353,6 +353,66 @@ static int32_t extractTopicTbInfo(SNode *pAst, SMqTopicObj *pTopic) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t sendCheckInfoToVnode(STrans *pTrans, SMnode *pMnode, SMqTopicObj *topicObj){
|
||||
STqCheckInfo info;
|
||||
memcpy(info.topic, topicObj->name, TSDB_TOPIC_FNAME_LEN);
|
||||
info.ntbUid = topicObj->ntbUid;
|
||||
info.colIdList = topicObj->ntbColIds;
|
||||
// broadcast forbid alter info
|
||||
void *pIter = NULL;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = NULL;
|
||||
int32_t code = 0;
|
||||
void *buf = NULL;
|
||||
|
||||
while (1) {
|
||||
// iterate vg
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (!mndVgroupInDb(pVgroup, topicObj->dbUid)) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
|
||||
// encoder check alter info
|
||||
int32_t len;
|
||||
tEncodeSize(tEncodeSTqCheckInfo, &info, len, code);
|
||||
if (code != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto END;
|
||||
}
|
||||
buf = taosMemoryCalloc(1, sizeof(SMsgHead) + len);
|
||||
void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, abuf, len);
|
||||
code = tEncodeSTqCheckInfo(&encoder, &info);
|
||||
if (code < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto END;
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
((SMsgHead *)buf)->vgId = htonl(pVgroup->vgId);
|
||||
// add redo action
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
action.pCont = buf;
|
||||
action.contLen = sizeof(SMsgHead) + len;
|
||||
action.msgType = TDMT_VND_TMQ_ADD_CHECKINFO;
|
||||
code = mndTransAppendRedoAction(pTrans, &action);
|
||||
if (code != 0) {
|
||||
goto END;
|
||||
}
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
buf = NULL;
|
||||
}
|
||||
|
||||
END:
|
||||
taosMemoryFree(buf);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *pCreate, SDbObj *pDb,
|
||||
const char *userName) {
|
||||
mInfo("start to create topic:%s", pCreate->name);
|
||||
|
@ -396,13 +456,6 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
|||
topicObj.withMeta = pCreate->withMeta;
|
||||
|
||||
if (pCreate->subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
if (pCreate->withMeta) {
|
||||
terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION;
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
code = terrno;
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
topicObj.ast = taosStrdup(pCreate->ast);
|
||||
topicObj.astLen = strlen(pCreate->ast) + 1;
|
||||
|
||||
|
@ -474,60 +527,10 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq *
|
|||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (topicObj.ntbUid != 0) {
|
||||
STqCheckInfo info;
|
||||
memcpy(info.topic, topicObj.name, TSDB_TOPIC_FNAME_LEN);
|
||||
info.ntbUid = topicObj.ntbUid;
|
||||
info.colIdList = topicObj.ntbColIds;
|
||||
// broadcast forbid alter info
|
||||
void *pIter = NULL;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = NULL;
|
||||
while (1) {
|
||||
// iterate vg
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (!mndVgroupInDb(pVgroup, topicObj.dbUid)) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
|
||||
// encoder check alter info
|
||||
int32_t len;
|
||||
tEncodeSize(tEncodeSTqCheckInfo, &info, len, code);
|
||||
if (code < 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
code = sendCheckInfoToVnode(pTrans, pMnode, &topicObj);
|
||||
if (code != 0){
|
||||
goto _OUT;
|
||||
}
|
||||
void *buf = taosMemoryCalloc(1, sizeof(SMsgHead) + len);
|
||||
void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, abuf, len);
|
||||
if (tEncodeSTqCheckInfo(&encoder, &info) < 0) {
|
||||
taosMemoryFree(buf);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
code = -1;
|
||||
goto _OUT;
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
((SMsgHead *)buf)->vgId = htonl(pVgroup->vgId);
|
||||
// add redo action
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
action.pCont = buf;
|
||||
action.contLen = sizeof(SMsgHead) + len;
|
||||
action.msgType = TDMT_VND_TMQ_ADD_CHECKINFO;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(buf);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
code = -1;
|
||||
goto _OUT;
|
||||
}
|
||||
buf = NULL;
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
|
@ -653,9 +656,104 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static bool checkTopic(SArray *topics, char *topicName){
|
||||
int32_t sz = taosArrayGetSize(topics);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *name = taosArrayGetP(topics, i);
|
||||
if (strcmp(name, topicName) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int32_t mndDropConsumerByTopic(SMnode *pMnode, STrans *pTrans, char *topicName){
|
||||
int32_t code = 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
SMqConsumerObj *pConsumer = NULL;
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_CONSUMER, pIter, (void **)&pConsumer);
|
||||
if (pIter == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
bool found = checkTopic(pConsumer->assignedTopics, topicName);
|
||||
if (found){
|
||||
if (pConsumer->status == MQ_CONSUMER_STATUS_LOST) {
|
||||
code = mndSetConsumerDropLogs(pTrans, pConsumer);
|
||||
if (code != 0) {
|
||||
goto end;
|
||||
}
|
||||
sdbRelease(pSdb, pConsumer);
|
||||
continue;
|
||||
}
|
||||
mError("topic:%s, failed to drop since subscribed by consumer:0x%" PRIx64 ", in consumer group %s",
|
||||
topicName, pConsumer->consumerId, pConsumer->cgroup);
|
||||
code = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (checkTopic(pConsumer->rebNewTopics, topicName) || checkTopic(pConsumer->rebRemovedTopics, topicName)) {
|
||||
code = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
||||
mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s (reb new)",
|
||||
topicName, pConsumer->consumerId, pConsumer->cgroup);
|
||||
goto end;
|
||||
}
|
||||
sdbRelease(pSdb, pConsumer);
|
||||
}
|
||||
|
||||
end:
|
||||
sdbRelease(pSdb, pConsumer);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndDropCheckInfoByTopic(SMnode *pMnode, STrans *pTrans, SMqTopicObj *pTopic){
|
||||
// broadcast to all vnode
|
||||
void *pIter = NULL;
|
||||
SVgObj *pVgroup = NULL;
|
||||
int32_t code = 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *buf = NULL;
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (!mndVgroupInDb(pVgroup, pTopic->dbUid)) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
|
||||
buf = taosMemoryCalloc(1, sizeof(SMsgHead) + TSDB_TOPIC_FNAME_LEN);
|
||||
if (buf == NULL){
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto end;
|
||||
}
|
||||
void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||
((SMsgHead *)buf)->vgId = htonl(pVgroup->vgId);
|
||||
memcpy(abuf, pTopic->name, TSDB_TOPIC_FNAME_LEN);
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
action.pCont = buf;
|
||||
action.contLen = sizeof(SMsgHead) + TSDB_TOPIC_FNAME_LEN;
|
||||
action.msgType = TDMT_VND_TMQ_DEL_CHECKINFO;
|
||||
code = mndTransAppendRedoAction(pTrans, &action);
|
||||
if (code != 0) {
|
||||
taosMemoryFree(buf);
|
||||
goto end;
|
||||
}
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
end:
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SMDropTopicReq dropReq = {0};
|
||||
int32_t code = 0;
|
||||
SMqTopicObj *pTopic = NULL;
|
||||
|
@ -705,70 +803,11 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
|||
goto end;
|
||||
}
|
||||
|
||||
void *pIter = NULL;
|
||||
SMqConsumerObj *pConsumer;
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_CONSUMER, pIter, (void **)&pConsumer);
|
||||
if (pIter == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
int32_t sz = taosArrayGetSize(pConsumer->assignedTopics);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *name = taosArrayGetP(pConsumer->assignedTopics, i);
|
||||
if (strcmp(name, pTopic->name) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found){
|
||||
if (pConsumer->status == MQ_CONSUMER_STATUS_LOST) {
|
||||
mndDropConsumerFromSdb(pMnode, pConsumer->consumerId, &pReq->info);
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
continue;
|
||||
}
|
||||
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
||||
mError("topic:%s, failed to drop since subscribed by consumer:0x%" PRIx64 ", in consumer group %s",
|
||||
dropReq.name, pConsumer->consumerId, pConsumer->cgroup);
|
||||
code = -1;
|
||||
code = mndDropConsumerByTopic(pMnode, pTrans, dropReq.name);
|
||||
if (code != 0) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
sz = taosArrayGetSize(pConsumer->rebNewTopics);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *name = taosArrayGetP(pConsumer->rebNewTopics, i);
|
||||
if (strcmp(name, pTopic->name) == 0) {
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
||||
mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s (reb new)",
|
||||
dropReq.name, pConsumer->consumerId, pConsumer->cgroup);
|
||||
code = -1;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
sz = taosArrayGetSize(pConsumer->rebRemovedTopics);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
char *name = taosArrayGetP(pConsumer->rebRemovedTopics, i);
|
||||
if (strcmp(name, pTopic->name) == 0) {
|
||||
mndReleaseConsumer(pMnode, pConsumer);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
terrno = TSDB_CODE_MND_TOPIC_SUBSCRIBED;
|
||||
mError("topic:%s, failed to drop since subscribed by consumer:%" PRId64 ", in consumer group %s (reb remove)",
|
||||
dropReq.name, pConsumer->consumerId, pConsumer->cgroup);
|
||||
code = -1;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pConsumer);
|
||||
}
|
||||
|
||||
code = mndDropSubByTopic(pMnode, pTrans, dropReq.name);
|
||||
if (code < 0) {
|
||||
mError("topic:%s, failed to drop since %s", pTopic->name, terrstr());
|
||||
|
@ -776,37 +815,10 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
|||
}
|
||||
|
||||
if (pTopic->ntbUid != 0) {
|
||||
// broadcast to all vnode
|
||||
pIter = NULL;
|
||||
SVgObj *pVgroup = NULL;
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (!mndVgroupInDb(pVgroup, pTopic->dbUid)) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
|
||||
void *buf = taosMemoryCalloc(1, sizeof(SMsgHead) + TSDB_TOPIC_FNAME_LEN);
|
||||
void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||
((SMsgHead *)buf)->vgId = htonl(pVgroup->vgId);
|
||||
memcpy(abuf, pTopic->name, TSDB_TOPIC_FNAME_LEN);
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
action.pCont = buf;
|
||||
action.contLen = sizeof(SMsgHead) + TSDB_TOPIC_FNAME_LEN;
|
||||
action.msgType = TDMT_VND_TMQ_DEL_CHECKINFO;
|
||||
code = mndTransAppendRedoAction(pTrans, &action);
|
||||
code = mndDropCheckInfoByTopic(pMnode, pTrans, pTopic);
|
||||
if (code != 0) {
|
||||
taosMemoryFree(buf);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
goto end;
|
||||
}
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
}
|
||||
|
||||
code = mndDropTopic(pMnode, pTrans, pReq, pTopic);
|
||||
|
@ -822,7 +834,6 @@ end:
|
|||
|
||||
SName name = {0};
|
||||
tNameFromString(&name, dropReq.name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
//reuse this function for topic
|
||||
|
||||
auditRecord(pReq, pMnode->clusterId, "dropTopic", name.dbname, name.tname, dropReq.sql, dropReq.sqlLen);
|
||||
|
||||
|
|
|
@ -733,6 +733,8 @@ void mndTransSetDbName(STrans *pTrans, const char *dbname, const char *stbname)
|
|||
}
|
||||
}
|
||||
|
||||
void mndTransSetArbGroupId(STrans *pTrans, int32_t groupId) { pTrans->arbGroupId = groupId; }
|
||||
|
||||
void mndTransSetSerial(STrans *pTrans) { pTrans->exec = TRN_EXEC_SERIAL; }
|
||||
|
||||
void mndTransSetParallel(STrans *pTrans) { pTrans->exec = TRN_EXEC_PARALLEL; }
|
||||
|
@ -814,6 +816,12 @@ static bool mndCheckTransConflict(SMnode *pMnode, STrans *pNew) {
|
|||
conflict = true;
|
||||
}
|
||||
}
|
||||
if (pNew->conflict == TRN_CONFLICT_ARBGROUP) {
|
||||
if (pTrans->conflict == TRN_CONFLICT_GLOBAL) conflict = true;
|
||||
if (pTrans->conflict == TRN_CONFLICT_ARBGROUP) {
|
||||
if (pNew->arbGroupId == pTrans->arbGroupId) conflict = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (conflict) {
|
||||
mError("trans:%d, db:%s stb:%s type:%d, can't execute since conflict with trans:%d db:%s stb:%s type:%d",
|
||||
|
@ -1255,9 +1263,9 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA
|
|||
|
||||
for (int32_t action = 0; action < numOfActions; ++action) {
|
||||
STransAction *pAction = taosArrayGet(pArray, action);
|
||||
mDebug("trans:%d, %s:%d Sent:%d, Received:%d, errCode:0x%x, acceptableCode:0x%x, retryCode:0x%x", pTrans->id,
|
||||
mndTransStr(pAction->stage), pAction->id, pAction->msgSent, pAction->msgReceived, pAction->errCode,
|
||||
pAction->acceptableCode, pAction->retryCode);
|
||||
mDebug("trans:%d, %s:%d Sent:%d, Received:%d, errCode:0x%x, acceptableCode:0x%x, retryCode:0x%x",
|
||||
pTrans->id, mndTransStr(pAction->stage), pAction->id, pAction->msgSent, pAction->msgReceived,
|
||||
pAction->errCode, pAction->acceptableCode, pAction->retryCode);
|
||||
if (pAction->msgSent) {
|
||||
if (pAction->msgReceived) {
|
||||
if (pAction->errCode != 0 && pAction->errCode != pAction->acceptableCode) {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "mndVgroup.h"
|
||||
#include "audit.h"
|
||||
#include "mndArbGroup.h"
|
||||
#include "mndDb.h"
|
||||
#include "mndDnode.h"
|
||||
#include "mndMnode.h"
|
||||
|
@ -351,7 +352,7 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg
|
|||
mInfo(
|
||||
"vgId:%d, build create vnode req, replica:%d selfIndex:%d learnerReplica:%d learnerSelfIndex:%d strict:%d "
|
||||
"changeVersion:%d",
|
||||
createReq.vgId, createReq.replica, createReq.selfIndex, createReq.learnerReplica, createReq.learnerReplica,
|
||||
createReq.vgId, createReq.replica, createReq.selfIndex, createReq.learnerReplica, createReq.learnerSelfIndex,
|
||||
createReq.strict, createReq.changeVersion);
|
||||
for (int32_t i = 0; i < createReq.replica; ++i) {
|
||||
mInfo("vgId:%d, replica:%d ep:%s:%u", createReq.vgId, i, createReq.replicas[i].fqdn, createReq.replicas[i].port);
|
||||
|
@ -738,10 +739,6 @@ void mndSortVnodeGid(SVgObj *pVgroup) {
|
|||
}
|
||||
|
||||
static int32_t mndGetAvailableDnode(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, SArray *pArray) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t allocedVnodes = 0;
|
||||
void *pIter = NULL;
|
||||
|
||||
mDebug("start to sort %d dnodes", (int32_t)taosArrayGetSize(pArray));
|
||||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
for (int32_t i = 0; i < (int32_t)taosArrayGetSize(pArray); ++i) {
|
||||
|
@ -883,7 +880,7 @@ SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup) {
|
|||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) continue;
|
||||
|
||||
if (pVgid->syncState == TAOS_SYNC_STATE_LEADER) {
|
||||
if (pVgid->syncState == TAOS_SYNC_STATE_LEADER || pVgid->syncState == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
epset.inUse = epset.numOfEps;
|
||||
}
|
||||
|
||||
|
@ -895,6 +892,29 @@ SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup) {
|
|||
return epset;
|
||||
}
|
||||
|
||||
SEpSet mndGetVgroupEpsetById(SMnode *pMnode, int32_t vgId) {
|
||||
SEpSet epset = {0};
|
||||
|
||||
SVgObj * pVgroup = mndAcquireVgroup(pMnode, vgId);
|
||||
if (!pVgroup) return epset;
|
||||
|
||||
for (int32_t v = 0; v < pVgroup->replica; ++v) {
|
||||
const SVnodeGid *pVgid = &pVgroup->vnodeGid[v];
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) continue;
|
||||
|
||||
if (pVgid->syncState == TAOS_SYNC_STATE_LEADER || pVgid->syncState == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
epset.inUse = epset.numOfEps;
|
||||
}
|
||||
|
||||
addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
}
|
||||
|
||||
mndReleaseVgroup(pMnode, pVgroup);
|
||||
return epset;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
@ -958,7 +978,8 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p
|
|||
strcpy(role, "dropping");
|
||||
} else if (online) {
|
||||
char *star = "";
|
||||
if (pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_LEADER) {
|
||||
if (pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_LEADER ||
|
||||
pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
if (!pVgroup->vnodeGid[i].syncRestore && !pVgroup->vnodeGid[i].syncCanRead) {
|
||||
star = "**";
|
||||
} else if (!pVgroup->vnodeGid[i].syncRestore && pVgroup->vnodeGid[i].syncCanRead) {
|
||||
|
@ -2288,7 +2309,7 @@ int32_t mndAddVgroupBalanceToTrans(SMnode *pMnode, SVgObj *pVgroup, STrans *pTra
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t dnodeId = pVgroup->vnodeGid[0].dnodeId;
|
||||
int32_t dnodeId = 0;
|
||||
|
||||
for (int i = 0; i < replica; i++) {
|
||||
if (pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_LEADER) {
|
||||
|
@ -2389,81 +2410,102 @@ static int32_t mndCheckDnodeMemory(SMnode *pMnode, SDbObj *pOldDb, SDbObj *pNewD
|
|||
}
|
||||
|
||||
int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb, SVgObj *pVgroup,
|
||||
SArray *pArray) {
|
||||
SVgObj newVgroup = {0};
|
||||
memcpy(&newVgroup, pVgroup, sizeof(SVgObj));
|
||||
SArray *pArray, SVgObj *pNewVgroup) {
|
||||
memcpy(pNewVgroup, pVgroup, sizeof(SVgObj));
|
||||
|
||||
if (pVgroup->replica <= 0 || pVgroup->replica == pNewDb->cfg.replications) {
|
||||
if (mndAddAlterVnodeConfigAction(pMnode, pTrans, pNewDb, pVgroup) != 0) return -1;
|
||||
if (mndCheckDnodeMemory(pMnode, pOldDb, pNewDb, &newVgroup, pVgroup, pArray) != 0) return -1;
|
||||
if (mndCheckDnodeMemory(pMnode, pOldDb, pNewDb, pNewVgroup, pVgroup, pArray) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
mndTransSetSerial(pTrans);
|
||||
|
||||
if (newVgroup.replica == 1 && pNewDb->cfg.replications == 3) {
|
||||
if (pNewVgroup->replica == 1 && pNewDb->cfg.replications == 3) {
|
||||
mInfo("db:%s, vgId:%d, will add 2 vnodes, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId,
|
||||
pVgroup->vnodeGid[0].dnodeId);
|
||||
|
||||
// add second
|
||||
if (mndAddVnodeToVgroup(pMnode, pTrans, &newVgroup, pArray) != 0) return -1;
|
||||
if (mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray) != 0) return -1;
|
||||
|
||||
// learner stage
|
||||
newVgroup.vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
newVgroup.vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_LEARNER;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
||||
pNewVgroup->vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
pNewVgroup->vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_LEARNER;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId) != 0)
|
||||
return -1;
|
||||
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[1]) != 0) return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &pNewVgroup->vnodeGid[1]) != 0) return -1;
|
||||
|
||||
// follower stage
|
||||
newVgroup.vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
if (mndAddAlterVnodeTypeAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[1].dnodeId) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
||||
pNewVgroup->vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
if (mndAddAlterVnodeTypeAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[1].dnodeId) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId) != 0)
|
||||
return -1;
|
||||
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup) != 0) return -1;
|
||||
|
||||
// add third
|
||||
if (mndAddVnodeToVgroup(pMnode, pTrans, &newVgroup, pArray) != 0) return -1;
|
||||
if (mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray) != 0) return -1;
|
||||
|
||||
newVgroup.vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
newVgroup.vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
newVgroup.vnodeGid[2].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
||||
pNewVgroup->vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
pNewVgroup->vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
pNewVgroup->vnodeGid[2].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId) != 0)
|
||||
return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[1].dnodeId) != 0)
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[1].dnodeId) != 0)
|
||||
return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[2]) != 0) return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &pNewVgroup->vnodeGid[2]) != 0) return -1;
|
||||
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||
} else if (newVgroup.replica == 3 && pNewDb->cfg.replications == 1) {
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup) != 0) return -1;
|
||||
} else if (pNewVgroup->replica == 3 && pNewDb->cfg.replications == 1) {
|
||||
mInfo("db:%s, vgId:%d, will remove 2 vnodes, vn:0 dnode:%d vn:1 dnode:%d vn:2 dnode:%d", pVgroup->dbName,
|
||||
pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId, pVgroup->vnodeGid[1].dnodeId, pVgroup->vnodeGid[2].dnodeId);
|
||||
|
||||
SVnodeGid del1 = {0};
|
||||
SVnodeGid del2 = {0};
|
||||
if (mndRemoveVnodeFromVgroup(pMnode, pTrans, &newVgroup, pArray, &del1) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &del1, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
||||
if (mndRemoveVnodeFromVgroup(pMnode, pTrans, pNewVgroup, pArray, &del1) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &del1, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId) != 0)
|
||||
return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[1].dnodeId) != 0)
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[1].dnodeId) != 0)
|
||||
return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup) != 0) return -1;
|
||||
|
||||
if (mndRemoveVnodeFromVgroup(pMnode, pTrans, &newVgroup, pArray, &del2) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &del2, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
||||
if (mndRemoveVnodeFromVgroup(pMnode, pTrans, pNewVgroup, pArray, &del2) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &del2, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId) != 0)
|
||||
return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup) != 0) return -1;
|
||||
} else if (pNewVgroup->replica == 1 && pNewDb->cfg.replications == 2) {
|
||||
mInfo("db:%s, vgId:%d, will add 1 vnode, vn:0 dnode:%d", pVgroup->dbName, pVgroup->vgId,
|
||||
pVgroup->vnodeGid[0].dnodeId);
|
||||
|
||||
// add second
|
||||
if (mndAddVnodeToVgroup(pMnode, pTrans, pNewVgroup, pArray) != 0) return -1;
|
||||
|
||||
// learner stage
|
||||
pNewVgroup->vnodeGid[0].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
pNewVgroup->vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_LEARNER;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId) != 0)
|
||||
return -1;
|
||||
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, pNewVgroup, &pNewVgroup->vnodeGid[1]) != 0) return -1;
|
||||
|
||||
// follower stage
|
||||
pNewVgroup->vnodeGid[1].nodeRole = TAOS_SYNC_ROLE_VOTER;
|
||||
if (mndAddAlterVnodeTypeAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[1].dnodeId) != 0) return -1;
|
||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, pNewVgroup, pNewVgroup->vnodeGid[0].dnodeId) != 0)
|
||||
return -1;
|
||||
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, pNewVgroup) != 0) return -1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
mndSortVnodeGid(&newVgroup);
|
||||
mndSortVnodeGid(pNewVgroup);
|
||||
|
||||
{
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(&newVgroup);
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(pNewVgroup);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pVgRaw) != 0) {
|
||||
sdbFreeRaw(pVgRaw);
|
||||
|
@ -2622,7 +2664,7 @@ int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
}
|
||||
}
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, db, &newVgroup, &newVgroup.vnodeGid[selected]) != 0) return -1;
|
||||
} else if (newVgroup.replica == 3) {
|
||||
} else if (newVgroup.replica == 2 || newVgroup.replica == 3) {
|
||||
for (int i = 0; i < newVgroup.replica; i++) {
|
||||
if (newVgroup.vnodeGid[i].dnodeId == pDnode->id) {
|
||||
newVgroup.vnodeGid[i].nodeRole = TAOS_SYNC_ROLE_LEARNER;
|
||||
|
@ -2716,6 +2758,12 @@ int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgro
|
|||
}
|
||||
#endif
|
||||
|
||||
if (pDb->cfg.withArbitrator) {
|
||||
code = TSDB_CODE_OPS_NOT_SUPPORT;
|
||||
mError("vgId:%d, db:%s, with arbitrator, split vgroup not allowed", pVgroup->vgId, pVgroup->dbName);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq, "split-vgroup");
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
mndTransSetSerial(pTrans);
|
||||
|
@ -2813,13 +2861,15 @@ int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgro
|
|||
|
||||
// adjust vgroup replica
|
||||
if (pDb->cfg.replications != newVg1.replica) {
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg1, pArray) != 0) goto _OVER;
|
||||
SVgObj tmpGroup = {0};
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg1, pArray, &tmpGroup) != 0) goto _OVER;
|
||||
} else {
|
||||
if (mndAddVgStatusAction(pTrans, &newVg1, SDB_STATUS_READY, TRN_STAGE_COMMIT_ACTION) < 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (pDb->cfg.replications != newVg2.replica) {
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg2, pArray) != 0) goto _OVER;
|
||||
SVgObj tmpGroup = {0};
|
||||
if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg2, pArray, &tmpGroup) != 0) goto _OVER;
|
||||
} else {
|
||||
if (mndAddVgStatusAction(pTrans, &newVg2, SDB_STATUS_READY, TRN_STAGE_COMMIT_ACTION) < 0) goto _OVER;
|
||||
}
|
||||
|
@ -2907,10 +2957,22 @@ static int32_t mndBalanceVgroupBetweenDnode(SMnode *pMnode, STrans *pTrans, SDno
|
|||
}
|
||||
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName);
|
||||
if (pDb == NULL) {
|
||||
mError("vgId:%d, balance vgroup can't find db obj dbName:%s", pVgroup->vgId, pVgroup->dbName);
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
if (pDb->cfg.withArbitrator) {
|
||||
mInfo("vgId:%d, db:%s, with arbitrator, balance vgroup not allowed", pVgroup->vgId, pVgroup->dbName);
|
||||
goto _OUT;
|
||||
}
|
||||
|
||||
code = mndSetBalanceVgroupInfoToTrans(pMnode, pTrans, pDb, pVgroup, pSrc, pDst);
|
||||
if (code == 0) {
|
||||
code = taosHashPut(pBalancedVgroups, &pVgroup->vgId, sizeof(int32_t), &pVgroup->vgId, sizeof(int32_t));
|
||||
}
|
||||
|
||||
_OUT:
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
enable_testing()
|
||||
|
||||
add_subdirectory(acct)
|
||||
add_subdirectory(arbgroup)
|
||||
#add_subdirectory(db)
|
||||
#add_subdirectory(dnode)
|
||||
add_subdirectory(func)
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
SET(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
aux_source_directory(. MNODE_ARBGROUP_TEST_SRC)
|
||||
add_executable(arbgroupTest ${MNODE_ARBGROUP_TEST_SRC})
|
||||
target_link_libraries(
|
||||
arbgroupTest
|
||||
PRIVATE dnode nodes planner gtest qcom
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME arbgroupTest
|
||||
COMMAND arbgroupTest
|
||||
)
|
|
@ -0,0 +1,286 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// #include <iostream>
|
||||
#include <string>
|
||||
#include <gtest/gtest.h>
|
||||
// #include "nodes.h"
|
||||
// #include "planner.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
|
||||
// #include <libs/transport/trpc.h>
|
||||
#include "../../inc/mndArbGroup.h"
|
||||
|
||||
namespace {
|
||||
|
||||
void generateArbToken(int32_t nodeId, int32_t vgId, char* buf) {
|
||||
memset(buf, 0, TSDB_ARB_TOKEN_SIZE);
|
||||
int32_t randVal = taosSafeRand() % 1000;
|
||||
int64_t currentMs = taosGetTimestampMs();
|
||||
snprintf(buf, TSDB_ARB_TOKEN_SIZE, "d%d#g%d#%" PRId64 "#%d", nodeId, vgId, currentMs, randVal);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class ArbgroupTest : public testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
std::cout << "setup env for arbgroupTest suite" << std::endl;
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() { std::cout << "tearDown env for arbgroupTest suite" << std::endl; }
|
||||
|
||||
virtual void SetUp() override {}
|
||||
|
||||
virtual void TearDown() override {}
|
||||
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
TEST_F(ArbgroupTest, 01_encode_decode_sdb) {
|
||||
SArbGroup group = {0};
|
||||
group.vgId = 5;
|
||||
group.dbUid = 1234;
|
||||
group.members[0].info.dnodeId = 1;
|
||||
generateArbToken(1, 5, group.members[0].state.token);
|
||||
group.members[1].info.dnodeId = 2;
|
||||
generateArbToken(2, 5, group.members[1].state.token);
|
||||
group.isSync = 1;
|
||||
group.assignedLeader.dnodeId = 1;
|
||||
generateArbToken(1, 5, group.assignedLeader.token);
|
||||
group.version = 2234;
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
SSdbRaw* pRaw = mndArbGroupActionEncode(&group);
|
||||
ASSERT_NE(pRaw, nullptr);
|
||||
|
||||
SSdbRow* pRow = mndArbGroupActionDecode(pRaw);
|
||||
ASSERT_NE(pRow, nullptr);
|
||||
|
||||
SArbGroup* pNewGroup = (SArbGroup*)sdbGetRowObj(pRow);
|
||||
|
||||
EXPECT_EQ(group.vgId, pNewGroup->vgId);
|
||||
EXPECT_EQ(group.dbUid, pNewGroup->dbUid);
|
||||
EXPECT_EQ(group.members[0].info.dnodeId, pNewGroup->members[0].info.dnodeId);
|
||||
EXPECT_EQ(group.members[1].info.dnodeId, pNewGroup->members[1].info.dnodeId);
|
||||
EXPECT_EQ(group.isSync, pNewGroup->isSync);
|
||||
EXPECT_EQ(group.assignedLeader.dnodeId, pNewGroup->assignedLeader.dnodeId);
|
||||
|
||||
EXPECT_EQ(std::string(group.members[0].state.token), std::string(pNewGroup->members[0].state.token));
|
||||
EXPECT_EQ(std::string(group.members[1].state.token), std::string(pNewGroup->members[1].state.token));
|
||||
EXPECT_EQ(std::string(group.assignedLeader.token), std::string(pNewGroup->assignedLeader.token));
|
||||
EXPECT_EQ(group.version, pNewGroup->version);
|
||||
|
||||
taosMemoryFree(pRow);
|
||||
taosMemoryFree(pRaw);
|
||||
}
|
||||
|
||||
TEST_F(ArbgroupTest, 02_process_heart_beat_rsp) {
|
||||
const int32_t dnodeId = 1;
|
||||
const int32_t vgId = 5;
|
||||
|
||||
SArbGroup group = {0};
|
||||
group.vgId = vgId;
|
||||
group.dbUid = 1234;
|
||||
group.members[0].info.dnodeId = dnodeId;
|
||||
generateArbToken(dnodeId, vgId, group.members[0].state.token);
|
||||
group.members[0].state.lastHbMs = 1000;
|
||||
group.members[0].state.responsedHbSeq = 100;
|
||||
group.members[0].state.nextHbSeq = 102;
|
||||
|
||||
group.members[1].info.dnodeId = 2;
|
||||
generateArbToken(2, vgId, group.members[1].state.token);
|
||||
|
||||
group.isSync = 1;
|
||||
group.assignedLeader.dnodeId = dnodeId;
|
||||
strncpy(group.assignedLeader.token, group.members[0].state.token, TSDB_ARB_TOKEN_SIZE);
|
||||
|
||||
taosThreadMutexInit(&group.mutex, NULL);
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
{ // expired hb => skip
|
||||
SVArbHbRspMember rspMember = {0};
|
||||
rspMember.vgId = vgId;
|
||||
rspMember.hbSeq = group.members[0].state.responsedHbSeq - 1;
|
||||
strncpy(rspMember.memberToken, group.members[0].state.token, TSDB_ARB_TOKEN_SIZE);
|
||||
int32_t nowMs = group.members[0].state.lastHbMs + 10;
|
||||
|
||||
SArbGroup newGroup = {0};
|
||||
bool updateToken = mndUpdateArbGroupByHeartBeat(&group, &rspMember, nowMs, dnodeId, &newGroup);
|
||||
|
||||
EXPECT_FALSE(updateToken);
|
||||
EXPECT_NE(group.members[0].state.responsedHbSeq, rspMember.hbSeq);
|
||||
EXPECT_NE(group.members[0].state.lastHbMs, nowMs);
|
||||
}
|
||||
|
||||
{ // old token
|
||||
SVArbHbRspMember rspMember = {0};
|
||||
rspMember.vgId = vgId;
|
||||
rspMember.hbSeq = group.members[0].state.responsedHbSeq + 1;
|
||||
strncpy(rspMember.memberToken, group.members[0].state.token, TSDB_ARB_TOKEN_SIZE);
|
||||
int32_t nowMs = group.members[0].state.lastHbMs + 10;
|
||||
|
||||
SArbGroup newGroup = {0};
|
||||
bool updateToken = mndUpdateArbGroupByHeartBeat(&group, &rspMember, nowMs, dnodeId, &newGroup);
|
||||
|
||||
EXPECT_FALSE(updateToken);
|
||||
EXPECT_EQ(group.members[0].state.responsedHbSeq, rspMember.hbSeq);
|
||||
EXPECT_EQ(group.members[0].state.lastHbMs, nowMs);
|
||||
}
|
||||
|
||||
{ // new token
|
||||
SVArbHbRspMember rspMember = {0};
|
||||
rspMember.vgId = vgId;
|
||||
rspMember.hbSeq = group.members[0].state.responsedHbSeq + 1;
|
||||
generateArbToken(dnodeId, vgId, rspMember.memberToken);
|
||||
int32_t nowMs = group.members[0].state.lastHbMs + 10;
|
||||
|
||||
SArbGroup newGroup = {0};
|
||||
bool updateToken = mndUpdateArbGroupByHeartBeat(&group, &rspMember, nowMs, dnodeId, &newGroup);
|
||||
|
||||
EXPECT_TRUE(updateToken);
|
||||
EXPECT_EQ(group.members[0].state.responsedHbSeq, rspMember.hbSeq);
|
||||
EXPECT_EQ(group.members[0].state.lastHbMs, nowMs);
|
||||
|
||||
EXPECT_EQ(std::string(newGroup.members[0].state.token), std::string(rspMember.memberToken));
|
||||
EXPECT_FALSE(newGroup.isSync);
|
||||
EXPECT_EQ(newGroup.assignedLeader.dnodeId, 0);
|
||||
EXPECT_EQ(std::string(newGroup.assignedLeader.token).size(), 0);
|
||||
}
|
||||
|
||||
taosThreadMutexDestroy(&group.mutex);
|
||||
}
|
||||
|
||||
TEST_F(ArbgroupTest, 03_process_check_sync_rsp) {
|
||||
const int32_t dnodeId = 1;
|
||||
const int32_t vgId = 5;
|
||||
|
||||
SArbGroup group = {0};
|
||||
group.vgId = vgId;
|
||||
group.dbUid = 1234;
|
||||
group.members[0].info.dnodeId = dnodeId;
|
||||
generateArbToken(dnodeId, vgId, group.members[0].state.token);
|
||||
group.members[0].state.lastHbMs = 1000;
|
||||
group.members[0].state.responsedHbSeq = 100;
|
||||
group.members[0].state.nextHbSeq = 102;
|
||||
|
||||
group.members[1].info.dnodeId = 2;
|
||||
generateArbToken(2, vgId, group.members[1].state.token);
|
||||
|
||||
group.isSync = 0;
|
||||
|
||||
taosThreadMutexInit(&group.mutex, NULL);
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
{ // token mismatch => skip
|
||||
char member0Token[TSDB_ARB_TOKEN_SIZE] = {0};
|
||||
strncpy(member0Token, group.members[0].state.token, TSDB_ARB_TOKEN_SIZE);
|
||||
char member1Token[TSDB_ARB_TOKEN_SIZE] = {0};
|
||||
generateArbToken(2, 5, member1Token);
|
||||
bool newIsSync = false;
|
||||
|
||||
SArbGroup newGroup = {0};
|
||||
bool updateIsSync = mndUpdateArbGroupByCheckSync(&group, vgId, member0Token, member1Token, newIsSync, &newGroup);
|
||||
|
||||
EXPECT_FALSE(updateIsSync);
|
||||
}
|
||||
|
||||
{ // newIsSync
|
||||
char member0Token[TSDB_ARB_TOKEN_SIZE] = {0};
|
||||
strncpy(member0Token, group.members[0].state.token, TSDB_ARB_TOKEN_SIZE);
|
||||
char member1Token[TSDB_ARB_TOKEN_SIZE] = {0};
|
||||
strncpy(member1Token, group.members[1].state.token, TSDB_ARB_TOKEN_SIZE);
|
||||
bool newIsSync = true;
|
||||
|
||||
SArbGroup newGroup = {0};
|
||||
bool updateIsSync = mndUpdateArbGroupByCheckSync(&group, vgId, member0Token, member1Token, newIsSync, &newGroup);
|
||||
|
||||
EXPECT_TRUE(updateIsSync);
|
||||
EXPECT_TRUE(newGroup.isSync);
|
||||
}
|
||||
|
||||
taosThreadMutexDestroy(&group.mutex);
|
||||
}
|
||||
|
||||
TEST_F(ArbgroupTest, 04_process_set_assigned_leader){
|
||||
const int32_t dnodeId = 1;
|
||||
const int32_t vgId = 5;
|
||||
|
||||
SArbGroup group = {0};
|
||||
group.vgId = vgId;
|
||||
group.dbUid = 1234;
|
||||
group.members[0].info.dnodeId = dnodeId;
|
||||
generateArbToken(dnodeId, vgId, group.members[0].state.token);
|
||||
group.members[0].state.lastHbMs = 1000;
|
||||
group.members[0].state.responsedHbSeq = 100;
|
||||
group.members[0].state.nextHbSeq = 102;
|
||||
|
||||
group.members[1].info.dnodeId = 2;
|
||||
generateArbToken(2, vgId, group.members[1].state.token);
|
||||
|
||||
group.isSync = 1;
|
||||
group.assignedLeader.dnodeId = dnodeId;
|
||||
strncpy(group.assignedLeader.token, group.members[0].state.token, TSDB_ARB_TOKEN_SIZE);
|
||||
|
||||
taosThreadMutexInit(&group.mutex, NULL);
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
{ // token mismatch => skip
|
||||
char memberToken[TSDB_ARB_TOKEN_SIZE] = {0};
|
||||
generateArbToken(dnodeId, vgId, memberToken);
|
||||
int32_t errcode = TSDB_CODE_SUCCESS;
|
||||
|
||||
SArbGroup newGroup = {0};
|
||||
bool updateAssigned = mndUpdateArbGroupBySetAssignedLeader(&group, vgId, memberToken, errcode, &newGroup);
|
||||
|
||||
EXPECT_FALSE(updateAssigned);
|
||||
}
|
||||
|
||||
{ // errcode != TSDB_CODE_SUCCESS
|
||||
char memberToken[TSDB_ARB_TOKEN_SIZE] = {0};
|
||||
strncpy(memberToken, group.assignedLeader.token, TSDB_ARB_TOKEN_SIZE);
|
||||
int32_t errcode = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
|
||||
SArbGroup newGroup = {0};
|
||||
bool updateAssigned = mndUpdateArbGroupBySetAssignedLeader(&group, vgId, memberToken, errcode, &newGroup);
|
||||
|
||||
EXPECT_FALSE(updateAssigned);
|
||||
}
|
||||
|
||||
{ // errcode == TSDB_CODE_SUCCESS
|
||||
char memberToken[TSDB_ARB_TOKEN_SIZE] = {0};
|
||||
strncpy(memberToken, group.assignedLeader.token, TSDB_ARB_TOKEN_SIZE);
|
||||
int32_t errcode = TSDB_CODE_SUCCESS;
|
||||
|
||||
SArbGroup newGroup = {0};
|
||||
bool updateAssigned = mndUpdateArbGroupBySetAssignedLeader(&group, vgId, memberToken, errcode, &newGroup);
|
||||
|
||||
EXPECT_TRUE(updateAssigned);
|
||||
EXPECT_FALSE(newGroup.isSync);
|
||||
}
|
||||
|
||||
taosThreadMutexDestroy(&group.mutex);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -153,7 +153,8 @@ typedef enum {
|
|||
SDB_COMPACT = 24,
|
||||
SDB_COMPACT_DETAIL = 25,
|
||||
SDB_GRANT = 26, // grant log
|
||||
SDB_MAX = 27
|
||||
SDB_ARBGROUP = 27,
|
||||
SDB_MAX = 28
|
||||
} ESdbType;
|
||||
|
||||
typedef struct SSdbRaw {
|
||||
|
|
|
@ -70,6 +70,8 @@ const char *sdbTableName(ESdbType type) {
|
|||
return "compact";
|
||||
case SDB_COMPACT_DETAIL:
|
||||
return "compact_detail";
|
||||
case SDB_ARBGROUP:
|
||||
return "arb_group";
|
||||
default:
|
||||
return "undefine";
|
||||
}
|
||||
|
|
|
@ -76,6 +76,9 @@ int32_t vnodeGetTableList(void *pVnode, int8_t type, SArray *pList);
|
|||
int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list);
|
||||
int32_t vnodeIsCatchUp(SVnode *pVnode);
|
||||
ESyncRole vnodeGetRole(SVnode *pVnode);
|
||||
int32_t vnodeGetArbToken(SVnode *pVnode, char *outToken);
|
||||
|
||||
int32_t vnodeUpdateArbTerm(SVnode *pVnode, int64_t arbTerm);
|
||||
|
||||
int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list);
|
||||
int32_t vnodeGetCtbIdListByFilter(SVnode *pVnode, int64_t suid, SArray *list, bool (*filter)(void *arg), void *arg);
|
||||
|
|
|
@ -246,32 +246,20 @@ int metaAlterCache(SMeta *pMeta, int32_t nPage) {
|
|||
}
|
||||
|
||||
int32_t metaRLock(SMeta *pMeta) {
|
||||
int32_t ret = 0;
|
||||
|
||||
metaTrace("meta rlock %p", &pMeta->lock);
|
||||
|
||||
ret = taosThreadRwlockRdlock(&pMeta->lock);
|
||||
|
||||
int32_t ret = taosThreadRwlockRdlock(&pMeta->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t metaWLock(SMeta *pMeta) {
|
||||
int32_t ret = 0;
|
||||
|
||||
metaTrace("meta wlock %p", &pMeta->lock);
|
||||
|
||||
ret = taosThreadRwlockWrlock(&pMeta->lock);
|
||||
|
||||
int32_t ret = taosThreadRwlockWrlock(&pMeta->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t metaULock(SMeta *pMeta) {
|
||||
int32_t ret = 0;
|
||||
|
||||
metaTrace("meta ulock %p", &pMeta->lock);
|
||||
|
||||
ret = taosThreadRwlockUnlock(&pMeta->lock);
|
||||
|
||||
int32_t ret = taosThreadRwlockUnlock(&pMeta->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,10 +88,6 @@ int32_t tqMetaOpen(STQ* pTq) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
// if (tqMetaRestoreHandle(pTq) < 0) {
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
if (tqMetaRestoreCheckInfo(pTq) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -167,32 +163,30 @@ int32_t tqMetaRestoreCheckInfo(STQ* pTq) {
|
|||
void* pVal = NULL;
|
||||
int vLen = 0;
|
||||
SDecoder decoder;
|
||||
int32_t code = 0;
|
||||
|
||||
tdbTbcMoveToFirst(pCur);
|
||||
|
||||
while (tdbTbcNext(pCur, &pKey, &kLen, &pVal, &vLen) == 0) {
|
||||
STqCheckInfo info;
|
||||
tDecoderInit(&decoder, (uint8_t*)pVal, vLen);
|
||||
if (tDecodeSTqCheckInfo(&decoder, &info) < 0) {
|
||||
code = tDecodeSTqCheckInfo(&decoder, &info);
|
||||
if (code != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
tdbFree(pKey);
|
||||
tdbFree(pVal);
|
||||
tdbTbcClose(pCur);
|
||||
return -1;
|
||||
goto END;
|
||||
}
|
||||
tDecoderClear(&decoder);
|
||||
if (taosHashPut(pTq->pCheckInfo, info.topic, strlen(info.topic), &info, sizeof(STqCheckInfo)) < 0) {
|
||||
code = taosHashPut(pTq->pCheckInfo, info.topic, strlen(info.topic), &info, sizeof(STqCheckInfo));
|
||||
if (code != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
END:
|
||||
tdbFree(pKey);
|
||||
tdbFree(pVal);
|
||||
tdbTbcClose(pCur);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
tdbFree(pKey);
|
||||
tdbFree(pVal);
|
||||
tdbTbcClose(pCur);
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle) {
|
||||
|
|
|
@ -429,7 +429,7 @@ static int32_t doLoadSttFilesBlk(SSttBlockLoadInfo *pBlockLoadInfo, SLDataIter *
|
|||
code = loadTombFn(pReader1, pIter->pReader, pIter->pBlockLoadInfo);
|
||||
|
||||
double el = (taosGetTimestampUs() - st) / 1000.0;
|
||||
tsdbDebug("load the stt file info completed, elapsed time:%.2fms, %s", el, idStr);
|
||||
tsdbDebug("load the stt file blk info completed, elapsed time:%.2fms, %s", el, idStr);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -806,7 +806,7 @@ int32_t tMergeTreeOpen2(SMergeTree *pMTree, SMergeTreeConf *pConf, SSttDataInfoF
|
|||
tMergeTreeAddIter(pMTree, pIter);
|
||||
|
||||
// let's record the time window for current table of uid in the stt files
|
||||
if (pSttDataInfo != NULL) {
|
||||
if (pSttDataInfo != NULL && numOfRows > 0) {
|
||||
taosArrayPush(pSttDataInfo->pTimeWindowList, &w);
|
||||
pSttDataInfo->numOfRows += numOfRows;
|
||||
}
|
||||
|
|
|
@ -2093,7 +2093,7 @@ static bool initSttBlockReader(SSttBlockReader* pSttBlockReader, STableBlockScan
|
|||
pScanInfo->sttKeyInfo.status = taosArrayGetSize(info.pTimeWindowList) ? STT_FILE_HAS_DATA : STT_FILE_NO_DATA;
|
||||
pScanInfo->sttKeyInfo.nextProcKey =
|
||||
ASCENDING_TRAVERSE(pReader->info.order) ? pScanInfo->sttWindow.skey : pScanInfo->sttWindow.ekey;
|
||||
hasData = true;
|
||||
hasData = (pScanInfo->sttKeyInfo.status == STT_FILE_HAS_DATA);
|
||||
} else { // not clean stt blocks
|
||||
INIT_TIMEWINDOW(&pScanInfo->sttWindow); //reset the time window
|
||||
pScanInfo->sttBlockReturned = false;
|
||||
|
|
|
@ -560,6 +560,9 @@ int32_t vnodeIsCatchUp(SVnode *pVnode) { return syncIsCatchUp(pVnode->sync); }
|
|||
|
||||
ESyncRole vnodeGetRole(SVnode *pVnode) { return syncGetRole(pVnode->sync); }
|
||||
|
||||
int32_t vnodeUpdateArbTerm(SVnode *pVnode, int64_t arbTerm) { return syncUpdateArbTerm(pVnode->sync, arbTerm); }
|
||||
int32_t vnodeGetArbToken(SVnode *pVnode, char *outToken) { return syncGetArbToken(pVnode->sync, outToken); }
|
||||
|
||||
void vnodeStop(SVnode *pVnode) {}
|
||||
|
||||
int64_t vnodeGetSyncHandle(SVnode *pVnode) { return pVnode->sync; }
|
||||
|
|
|
@ -406,7 +406,7 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
|
|||
|
||||
int32_t vnodeGetLoadLite(SVnode *pVnode, SVnodeLoadLite *pLoad) {
|
||||
SSyncState syncState = syncGetState(pVnode->sync);
|
||||
if (syncState.state == TAOS_SYNC_STATE_LEADER) {
|
||||
if (syncState.state == TAOS_SYNC_STATE_LEADER || syncState.state == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
pLoad->vgId = TD_VID(pVnode);
|
||||
pLoad->nTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta, 1);
|
||||
return 0;
|
||||
|
|
|
@ -45,6 +45,10 @@ static int32_t vnodeProcessCreateIndexReq(SVnode *pVnode, int64_t ver, void *pRe
|
|||
static int32_t vnodeProcessDropIndexReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
|
||||
static int32_t vnodePreCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token);
|
||||
static int32_t vnodeCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token);
|
||||
|
||||
extern int32_t vnodeProcessKillCompactReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
extern int32_t vnodeQueryCompactProgress(SVnode *pVnode, SRpcMsg *pMsg);
|
||||
|
@ -451,6 +455,21 @@ static int32_t vnodePreProcessBatchDeleteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t vnodePreProcessArbCheckSyncMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||
SVArbCheckSyncReq syncReq = {0};
|
||||
|
||||
if (tDeserializeSVArbCheckSyncReq((char *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead),
|
||||
&syncReq) != 0) {
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
(void)vnodePreCheckAssignedLogSyncd(pVnode, syncReq.member0Token, syncReq.member1Token);
|
||||
int32_t code = terrno;
|
||||
tFreeSVArbCheckSyncReq(&syncReq);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
|
||||
|
@ -473,6 +492,9 @@ int32_t vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
case TDMT_VND_BATCH_DEL: {
|
||||
code = vnodePreProcessBatchDeleteMsg(pVnode, pMsg);
|
||||
} break;
|
||||
case TDMT_VND_ARB_CHECK_SYNC: {
|
||||
code = vnodePreProcessArbCheckSyncMsg(pVnode, pMsg);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -643,6 +665,10 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
|
|||
vnodeProcessKillCompactReq(pVnode, ver, pReq, len, pRsp);
|
||||
break;
|
||||
#endif
|
||||
/* ARB */
|
||||
case TDMT_VND_ARB_CHECK_SYNC:
|
||||
vnodeProcessArbCheckSyncReq(pVnode, pReq, len, pRsp);
|
||||
break;
|
||||
default:
|
||||
vError("vgId:%d, unprocessed msg, %d", TD_VID(pVnode), pMsg->msgType);
|
||||
return -1;
|
||||
|
@ -2119,6 +2145,98 @@ static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pR
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t vnodePreCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
|
||||
SSyncState syncState = syncGetState(pVnode->sync);
|
||||
if (syncState.state != TAOS_SYNC_STATE_LEADER) {
|
||||
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char token[TSDB_ARB_TOKEN_SIZE] = {0};
|
||||
if (vnodeGetArbToken(pVnode, token) != 0) {
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strncmp(token, member0Token, TSDB_ARB_TOKEN_SIZE) != 0 &&
|
||||
strncmp(token, member1Token, TSDB_ARB_TOKEN_SIZE) != 0) {
|
||||
terrno = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
return -1;
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t vnodeCheckAssignedLogSyncd(SVnode *pVnode, char *member0Token, char *member1Token) {
|
||||
int32_t code = vnodePreCheckAssignedLogSyncd(pVnode, member0Token, member1Token);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return syncGetAssignedLogSynced(pVnode->sync);
|
||||
}
|
||||
|
||||
static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
int32_t code = 0;
|
||||
|
||||
SVArbCheckSyncReq syncReq = {0};
|
||||
|
||||
if (tDeserializeSVArbCheckSyncReq(pReq, len, &syncReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pRsp->msgType = TDMT_VND_ARB_CHECK_SYNC_RSP;
|
||||
pRsp->code = TSDB_CODE_SUCCESS;
|
||||
pRsp->pCont = NULL;
|
||||
pRsp->contLen = 0;
|
||||
|
||||
SVArbCheckSyncRsp syncRsp = {0};
|
||||
syncRsp.arbToken = syncReq.arbToken;
|
||||
syncRsp.member0Token = syncReq.member0Token;
|
||||
syncRsp.member1Token = syncReq.member1Token;
|
||||
syncRsp.vgId = TD_VID(pVnode);
|
||||
|
||||
(void)vnodeCheckAssignedLogSyncd(pVnode, syncReq.member0Token, syncReq.member1Token);
|
||||
syncRsp.errCode = terrno;
|
||||
|
||||
if (vnodeUpdateArbTerm(pVnode, syncReq.arbTerm) != 0) {
|
||||
vError("vgId:%d, failed to update arb term", TD_VID(pVnode));
|
||||
code = -1;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t contLen = tSerializeSVArbCheckSyncRsp(NULL, 0, &syncRsp);
|
||||
if (contLen <= 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = -1;
|
||||
goto _OVER;
|
||||
}
|
||||
void *pHead = rpcMallocCont(contLen);
|
||||
if (!pHead) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = -1;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (tSerializeSVArbCheckSyncRsp(pHead, contLen, &syncRsp) <= 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
rpcFreeCont(pHead);
|
||||
code = -1;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pRsp->pCont = pHead;
|
||||
pRsp->contLen = contLen;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
||||
_OVER:
|
||||
tFreeSVArbCheckSyncReq(&syncReq);
|
||||
return code;
|
||||
}
|
||||
|
||||
#ifndef TD_ENTERPRISE
|
||||
int32_t vnodeProcessCompactVnodeReqImpl(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
return 0;
|
||||
|
|
|
@ -638,6 +638,14 @@ static void vnodeBecomeLeader(const SSyncFSM *pFsm) {
|
|||
}
|
||||
}
|
||||
|
||||
static void vnodeBecomeAssignedLeader(const SSyncFSM* pFsm) {
|
||||
SVnode *pVnode = pFsm->data;
|
||||
vDebug("vgId:%d, become assigned leader", pVnode->config.vgId);
|
||||
if (pVnode->pTq) {
|
||||
tqUpdateNodeStage(pVnode->pTq, true);
|
||||
}
|
||||
}
|
||||
|
||||
static bool vnodeApplyQueueEmpty(const SSyncFSM *pFsm) {
|
||||
SVnode *pVnode = pFsm->data;
|
||||
|
||||
|
@ -674,6 +682,7 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
|
|||
pFsm->FpApplyQueueEmptyCb = vnodeApplyQueueEmpty;
|
||||
pFsm->FpApplyQueueItems = vnodeApplyQueueItems;
|
||||
pFsm->FpBecomeLeaderCb = vnodeBecomeLeader;
|
||||
pFsm->FpBecomeAssignedLeaderCb = vnodeBecomeAssignedLeader;
|
||||
pFsm->FpBecomeFollowerCb = vnodeBecomeFollower;
|
||||
pFsm->FpBecomeLearnerCb = vnodeBecomeLearner;
|
||||
pFsm->FpReConfigCb = NULL;
|
||||
|
|
|
@ -209,6 +209,8 @@ const char* nodesNodeName(ENodeType type) {
|
|||
return "ShowSnodesStmt";
|
||||
case QUERY_NODE_SHOW_BNODES_STMT:
|
||||
return "ShowBnodesStmt";
|
||||
case QUERY_NODE_SHOW_ARBGROUPS_STMT:
|
||||
return "ShowArbGroupsStmt";
|
||||
case QUERY_NODE_SHOW_CLUSTER_STMT:
|
||||
return "ShowClusterStmt";
|
||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||
|
@ -6654,6 +6656,10 @@ static int32_t showQnodesStmtToJson(const void* pObj, SJson* pJson) { return sho
|
|||
|
||||
static int32_t jsonToShowQnodesStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }
|
||||
|
||||
static int32_t showArbGroupsStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }
|
||||
|
||||
static int32_t jsonToShowArbGroupsStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }
|
||||
|
||||
static int32_t showClusterStmtToJson(const void* pObj, SJson* pJson) { return showStmtToJson(pObj, pJson); }
|
||||
|
||||
static int32_t jsonToShowClusterStmt(const SJson* pJson, void* pObj) { return jsonToShowStmt(pJson, pObj); }
|
||||
|
@ -7179,6 +7185,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
return showMnodesStmtToJson(pObj, pJson);
|
||||
case QUERY_NODE_SHOW_QNODES_STMT:
|
||||
return showQnodesStmtToJson(pObj, pJson);
|
||||
case QUERY_NODE_SHOW_ARBGROUPS_STMT:
|
||||
return showArbGroupsStmtToJson(pObj, pJson);
|
||||
case QUERY_NODE_SHOW_CLUSTER_STMT:
|
||||
return showClusterStmtToJson(pObj, pJson);
|
||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||
|
@ -7516,6 +7524,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
return jsonToShowMnodesStmt(pJson, pObj);
|
||||
case QUERY_NODE_SHOW_QNODES_STMT:
|
||||
return jsonToShowQnodesStmt(pJson, pObj);
|
||||
case QUERY_NODE_SHOW_ARBGROUPS_STMT:
|
||||
return jsonToShowArbGroupsStmt(pJson, pObj);
|
||||
case QUERY_NODE_SHOW_CLUSTER_STMT:
|
||||
return jsonToShowClusterStmt(pJson, pObj);
|
||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||
|
|
|
@ -419,6 +419,7 @@ SNode* nodesMakeNode(ENodeType type) {
|
|||
case QUERY_NODE_SHOW_QNODES_STMT:
|
||||
case QUERY_NODE_SHOW_SNODES_STMT:
|
||||
case QUERY_NODE_SHOW_BNODES_STMT:
|
||||
case QUERY_NODE_SHOW_ARBGROUPS_STMT:
|
||||
case QUERY_NODE_SHOW_CLUSTER_STMT:
|
||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||
case QUERY_NODE_SHOW_FUNCTIONS_STMT:
|
||||
|
@ -1072,6 +1073,7 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
case QUERY_NODE_SHOW_QNODES_STMT:
|
||||
case QUERY_NODE_SHOW_SNODES_STMT:
|
||||
case QUERY_NODE_SHOW_BNODES_STMT:
|
||||
case QUERY_NODE_SHOW_ARBGROUPS_STMT:
|
||||
case QUERY_NODE_SHOW_CLUSTER_STMT:
|
||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||
case QUERY_NODE_SHOW_FUNCTIONS_STMT:
|
||||
|
|
|
@ -478,6 +478,7 @@ cmd ::= SHOW db_name_cond_opt(A) VGROUPS.
|
|||
cmd ::= SHOW MNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT); }
|
||||
//cmd ::= SHOW MODULES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MODULES_STMT); }
|
||||
cmd ::= SHOW QNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT); }
|
||||
cmd ::= SHOW ARBGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_ARBGROUPS_STMT); }
|
||||
cmd ::= SHOW FUNCTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT); }
|
||||
cmd ::= SHOW INDEXES FROM table_name_cond(A) from_db_opt(B). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, B, A, OP_TYPE_EQUAL); }
|
||||
cmd ::= SHOW INDEXES FROM db_name(B) NK_DOT table_name(A). { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, createIdentifierValueNode(pCxt, &B), createIdentifierValueNode(pCxt, &A), OP_TYPE_EQUAL); }
|
||||
|
|
|
@ -1263,6 +1263,7 @@ SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
|
|||
pOptions->sstTrigger = TSDB_DEFAULT_SST_TRIGGER;
|
||||
pOptions->tablePrefix = TSDB_DEFAULT_HASH_PREFIX;
|
||||
pOptions->tableSuffix = TSDB_DEFAULT_HASH_SUFFIX;
|
||||
pOptions->withArbitrator = TSDB_DEFAULT_DB_WITH_ARBITRATOR;
|
||||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
|
@ -1298,6 +1299,7 @@ SNode* createAlterDatabaseOptions(SAstCreateContext* pCxt) {
|
|||
pOptions->sstTrigger = -1;
|
||||
pOptions->tablePrefix = -1;
|
||||
pOptions->tableSuffix = -1;
|
||||
pOptions->withArbitrator = TSDB_DEFAULT_DB_WITH_ARBITRATOR;
|
||||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
|
@ -1353,6 +1355,7 @@ static SNode* setDatabaseOptionImpl(SAstCreateContext* pCxt, SNode* pOptions, ED
|
|||
break;
|
||||
case DB_OPTION_REPLICA:
|
||||
pDbOptions->replica = taosStr2Int8(((SToken*)pVal)->z, NULL, 10);
|
||||
pDbOptions->withArbitrator = (pDbOptions->replica == 2);
|
||||
if (!alter) {
|
||||
updateWalOptionsDefault(pDbOptions);
|
||||
}
|
||||
|
|
|
@ -459,6 +459,14 @@ static int32_t collectMetaKeyFromShowBnodes(SCollectMetaKeyCxt* pCxt, SShowStmt*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromShowArbGroups(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
|
||||
if (pCxt->pParseCxt->enableSysInfo) {
|
||||
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_ARBGROUPS,
|
||||
pCxt->pMetaCache);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromShowCluster(SCollectMetaKeyCxt* pCxt, SShowStmt* pStmt) {
|
||||
if (pCxt->pParseCxt->enableSysInfo) {
|
||||
return reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_CLUSTER,
|
||||
|
@ -806,6 +814,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
|||
return collectMetaKeyFromShowSnodes(pCxt, (SShowStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_BNODES_STMT:
|
||||
return collectMetaKeyFromShowBnodes(pCxt, (SShowStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_ARBGROUPS_STMT:
|
||||
return collectMetaKeyFromShowArbGroups(pCxt, (SShowStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_CLUSTER_STMT:
|
||||
return collectMetaKeyFromShowCluster(pCxt, (SShowStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||
|
|
|
@ -355,6 +355,7 @@ static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) {
|
|||
case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
|
||||
case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
|
||||
case QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT:
|
||||
case QUERY_NODE_SHOW_ARBGROUPS_STMT:
|
||||
return !pCxt->pParseCxt->enableSysInfo ? TSDB_CODE_PAR_PERMISSION_DENIED : TSDB_CODE_SUCCESS;
|
||||
case QUERY_NODE_SHOW_TABLES_STMT:
|
||||
case QUERY_NODE_SHOW_STABLES_STMT:
|
||||
|
|
|
@ -969,7 +969,7 @@ static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt
|
|||
}
|
||||
|
||||
_exit:
|
||||
for (int32_t i = 0; i < TARRAY_SIZE(pTagVals); ++i) {
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pTagVals); ++i) {
|
||||
STagVal* p = (STagVal*)TARRAY_GET_ELEM(pTagVals, i);
|
||||
if (IS_VAR_DATA_TYPE(p->type)) {
|
||||
taosMemoryFreeClear(p->pData);
|
||||
|
|
|
@ -304,6 +304,7 @@ static SKeyword keywordTable[] = {
|
|||
{"ALIVE", TK_ALIVE},
|
||||
{"VARBINARY", TK_VARBINARY},
|
||||
{"KEEP_TIME_OFFSET", TK_KEEP_TIME_OFFSET},
|
||||
{"ARBGROUPS", TK_ARBGROUPS},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
|
|
|
@ -100,6 +100,13 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
|
|||
.numOfShowCols = 1,
|
||||
.pShowCols = {"*"}
|
||||
},
|
||||
{
|
||||
.showType = QUERY_NODE_SHOW_ARBGROUPS_STMT,
|
||||
.pDbName = TSDB_INFORMATION_SCHEMA_DB,
|
||||
.pTableName = TSDB_INS_TABLE_ARBGROUPS,
|
||||
.numOfShowCols = 1,
|
||||
.pShowCols = {"*"}
|
||||
},
|
||||
{
|
||||
.showType = QUERY_NODE_SHOW_CLUSTER_STMT,
|
||||
.pDbName = TSDB_INFORMATION_SCHEMA_DB,
|
||||
|
@ -5138,6 +5145,7 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS
|
|||
pReq->tsdbPageSize = pStmt->pOptions->tsdbPageSize;
|
||||
pReq->keepTimeOffset = pStmt->pOptions->keepTimeOffset;
|
||||
pReq->ignoreExist = pStmt->ignoreExists;
|
||||
pReq->withArbitrator = pStmt->pOptions->withArbitrator;
|
||||
return buildCreateDbRetentions(pStmt->pOptions->pRetentions, pReq);
|
||||
}
|
||||
|
||||
|
@ -5439,6 +5447,12 @@ static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbNa
|
|||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
|
||||
"Invalid duration value, should be keep2 >= keep1 >= keep0 >= 3 * duration");
|
||||
}
|
||||
|
||||
if ((pOptions->replica == 2) ^ (pOptions->withArbitrator == TSDB_MAX_DB_WITH_ARBITRATOR)) {
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
|
||||
"Invalid database option, with_arbitrator should be used with replica 2");
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -5491,7 +5505,7 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
|
|||
TSDB_MAX_TSDB_PAGESIZE);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkDbEnumOption(pCxt, "replications", pOptions->replica, TSDB_MIN_DB_REPLICA, TSDB_MAX_DB_REPLICA);
|
||||
code = checkDbRangeOption(pCxt, "replications", pOptions->replica, TSDB_MIN_DB_REPLICA, TSDB_MAX_DB_REPLICA);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkDbStrictOption(pCxt, pOptions);
|
||||
|
@ -5530,6 +5544,10 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkDbRangeOption(pCxt, "sstTrigger", pOptions->sstTrigger, TSDB_MIN_STT_TRIGGER, TSDB_MAX_STT_TRIGGER);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkDbEnumOption(pCxt, "withArbitrator", pOptions->withArbitrator, TSDB_MIN_DB_WITH_ARBITRATOR,
|
||||
TSDB_MAX_DB_WITH_ARBITRATOR);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkDbTbPrefixSuffixOptions(pCxt, pOptions->tablePrefix, pOptions->tableSuffix);
|
||||
}
|
||||
|
@ -5742,6 +5760,7 @@ static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt,
|
|||
pReq->minRows = pStmt->pOptions->minRowsPerBlock;
|
||||
pReq->walRetentionPeriod = pStmt->pOptions->walRetentionPeriod;
|
||||
pReq->walRetentionSize = pStmt->pOptions->walRetentionSize;
|
||||
pReq->withArbitrator = pStmt->pOptions->withArbitrator;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -10870,6 +10889,7 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
case QUERY_NODE_SHOW_GRANTS_FULL_STMT:
|
||||
case QUERY_NODE_SHOW_GRANTS_LOGS_STMT:
|
||||
case QUERY_NODE_SHOW_CLUSTER_MACHINES_STMT:
|
||||
case QUERY_NODE_SHOW_ARBGROUPS_STMT:
|
||||
code = rewriteShow(pCxt, pQuery);
|
||||
break;
|
||||
case QUERY_NODE_SHOW_VGROUPS_STMT:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -337,7 +337,7 @@ TEST_F(ParserInitialATest, alterDatabaseSemanticCheck) {
|
|||
run("ALTER DATABASE test PAGES 63", TSDB_CODE_PAR_INVALID_DB_OPTION);
|
||||
run("ALTER DATABASE test WAL_LEVEL 0", TSDB_CODE_PAR_INVALID_DB_OPTION);
|
||||
run("ALTER DATABASE test WAL_LEVEL 3", TSDB_CODE_PAR_INVALID_DB_OPTION);
|
||||
run("ALTER DATABASE test REPLICA 2", TSDB_CODE_PAR_INVALID_DB_OPTION);
|
||||
//run("ALTER DATABASE test REPLICA 2", TSDB_CODE_PAR_INVALID_DB_OPTION);
|
||||
run("ALTER DATABASE test STT_TRIGGER 0", TSDB_CODE_PAR_INVALID_DB_OPTION);
|
||||
run("ALTER DATABASE test STT_TRIGGER 17", TSDB_CODE_PAR_INVALID_DB_OPTION);
|
||||
// Regardless of the specific sentence
|
||||
|
|
|
@ -2049,6 +2049,13 @@ static bool eliminateProjOptMayBeOptimized(SLogicNode* pNode) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (QUERY_NODE_LOGIC_PLAN_DYN_QUERY_CTRL == nodeType(nodesListGetNode(pNode->pChildren, 0))) {
|
||||
SLogicNode* pChild = (SLogicNode*)nodesListGetNode(pNode->pChildren, 0);
|
||||
if(LIST_LENGTH(pChild->pTargets) != LIST_LENGTH(pNode->pTargets)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
SProjectLogicNode* pProjectNode = (SProjectLogicNode*)pNode;
|
||||
if (NULL != pProjectNode->node.pLimit || NULL != pProjectNode->node.pSlimit ||
|
||||
NULL != pProjectNode->node.pConditions) {
|
||||
|
|
|
@ -1128,7 +1128,11 @@ static int32_t metaHeartbeatToMnodeImpl(SStreamMeta* pMeta) {
|
|||
}
|
||||
|
||||
if ((*pTask)->exec.pWalReader != NULL) {
|
||||
entry.processedVer = (*pTask)->chkInfo.nextProcessVer - 1;
|
||||
entry.processedVer = walReaderGetCurrentVer((*pTask)->exec.pWalReader) - 1;
|
||||
if (entry.processedVer < 0) {
|
||||
entry.processedVer = (*pTask)->chkInfo.processedVer;
|
||||
}
|
||||
|
||||
walReaderValidVersionRange((*pTask)->exec.pWalReader, &entry.verStart, &entry.verEnd);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,8 @@ bool syncNodeAgreedUpon(SSyncNode* pNode, SyncIndex index);
|
|||
int64_t syncNodeUpdateCommitIndex(SSyncNode* ths, SyncIndex commitIndex);
|
||||
int64_t syncNodeCheckCommitIndex(SSyncNode* ths, SyncIndex indexLikely);
|
||||
|
||||
int64_t syncNodeUpdateAssignedCommitIndex(SSyncNode* ths, SyncIndex assignedCommitIndex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -160,6 +160,13 @@ typedef struct SSyncNode {
|
|||
SSyncLogStore* pLogStore;
|
||||
SyncIndex commitIndex;
|
||||
|
||||
// assigned leader log vars
|
||||
SyncIndex assignedCommitIndex;
|
||||
|
||||
SyncTerm arbTerm;
|
||||
TdThreadMutex arbTokenMutex;
|
||||
char arbToken[TSDB_ARB_TOKEN_SIZE];
|
||||
|
||||
// timer ms init
|
||||
int32_t pingBaseLine;
|
||||
int32_t electBaseLine;
|
||||
|
@ -219,6 +226,7 @@ typedef struct SSyncNode {
|
|||
|
||||
int32_t electNum;
|
||||
int32_t becomeLeaderNum;
|
||||
int32_t becomeAssignedLeaderNum;
|
||||
int32_t configChangeNum;
|
||||
int32_t hbSlowNum;
|
||||
int32_t hbrSlowNum;
|
||||
|
@ -282,10 +290,12 @@ void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm);
|
|||
void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr);
|
||||
void syncNodeBecomeLearner(SSyncNode* pSyncNode, const char* debugStr);
|
||||
void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr);
|
||||
void syncNodeBecomeAssignedLeader(SSyncNode* pSyncNode);
|
||||
void syncNodeCandidate2Leader(SSyncNode* pSyncNode);
|
||||
void syncNodeFollower2Candidate(SSyncNode* pSyncNode);
|
||||
void syncNodeLeader2Follower(SSyncNode* pSyncNode);
|
||||
void syncNodeCandidate2Follower(SSyncNode* pSyncNode);
|
||||
int32_t syncNodeAssignedLeader2Leader(SSyncNode* pSyncNode);
|
||||
|
||||
// raft vote --------------
|
||||
void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId);
|
||||
|
|
|
@ -78,6 +78,8 @@ void syncUtilMsgHtoN(void* msg);
|
|||
bool syncUtilUserPreCommit(tmsg_t msgType);
|
||||
bool syncUtilUserRollback(tmsg_t msgType);
|
||||
|
||||
void syncUtilGenerateArbToken(int32_t nodeId, int32_t groupId, char* buf);
|
||||
|
||||
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...);
|
||||
void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender,
|
||||
const char* format, ...);
|
||||
|
|
|
@ -55,7 +55,7 @@ int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||
if (ths->state == TAOS_SYNC_STATE_LEADER || ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
if (pMsg->term > raftStoreGetTerm(ths)) {
|
||||
syncLogRecvAppendEntriesReply(ths, pMsg, "error term");
|
||||
syncNodeStepDown(ths, pMsg->term);
|
||||
|
@ -76,8 +76,27 @@ int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
// commit if needed
|
||||
SyncIndex indexLikely = TMIN(pMsg->matchIndex, ths->pLogBuf->matchIndex);
|
||||
SyncIndex commitIndex = syncNodeCheckCommitIndex(ths, indexLikely);
|
||||
if (ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
if (commitIndex >= ths->assignedCommitIndex) {
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
raftStoreNextTerm(ths);
|
||||
if (terrno != TSDB_CODE_SUCCESS) {
|
||||
sError("vgId:%d, failed to update term, reason:%s", ths->vgId, tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
if (syncNodeAssignedLeader2Leader(ths) != 0) {
|
||||
sError("vgId:%d, failed to change state from assigned leader to leader", ths->vgId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&ths->arbTokenMutex);
|
||||
syncUtilGenerateArbToken(ths->myNodeInfo.nodeId, ths->vgId, ths->arbToken);
|
||||
taosThreadMutexUnlock(&ths->arbTokenMutex);
|
||||
}
|
||||
} else {
|
||||
(void)syncLogBufferCommit(ths->pLogBuf, ths, commitIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// replicate log
|
||||
SSyncLogReplMgr* pMgr = syncNodeGetLogReplMgr(ths, &pMsg->srcId);
|
||||
|
|
|
@ -88,3 +88,11 @@ int64_t syncNodeCheckCommitIndex(SSyncNode* ths, SyncIndex indexLikely) {
|
|||
}
|
||||
return ths->commitIndex;
|
||||
}
|
||||
|
||||
int64_t syncNodeUpdateAssignedCommitIndex(SSyncNode* ths, SyncIndex assignedCommitIndex) {
|
||||
SyncIndex lastVer = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
|
||||
assignedCommitIndex = TMAX(assignedCommitIndex, ths->assignedCommitIndex);
|
||||
ths->assignedCommitIndex = TMIN(assignedCommitIndex, lastVer);
|
||||
ths->pLogStore->syncLogUpdateCommitIndex(ths->pLogStore, ths->assignedCommitIndex);
|
||||
return ths->commitIndex;
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) {
|
|||
syncNodeUpdateNewConfigIndex(pSyncNode, pNewCfg);
|
||||
syncNodeDoConfigChange(pSyncNode, pNewCfg, pNewCfg->lastIndex);
|
||||
|
||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER || pSyncNode->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
syncNodeStopHeartbeatTimer(pSyncNode);
|
||||
|
||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA; ++i) {
|
||||
|
@ -235,6 +235,9 @@ int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg) {
|
|||
case TDMT_SYNC_FORCE_FOLLOWER:
|
||||
code = syncForceBecomeFollower(pSyncNode, pMsg);
|
||||
break;
|
||||
case TDMT_SYNC_SET_ASSIGNED_LEADER:
|
||||
code = syncBecomeAssignedLeader(pSyncNode, pMsg);
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
code = -1;
|
||||
|
@ -271,6 +274,78 @@ int32_t syncForceBecomeFollower(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncBecomeAssignedLeader(SSyncNode* ths, SRpcMsg* pRpcMsg) {
|
||||
int32_t ret = -1;
|
||||
|
||||
SVArbSetAssignedLeaderReq req = {0};
|
||||
if (tDeserializeSVArbSetAssignedLeaderReq((char*)pRpcMsg->pCont + sizeof(SMsgHead), pRpcMsg->contLen, &req) != 0) {
|
||||
sError("vgId:%d, failed to deserialize SVArbSetAssignedLeaderReq", ths->vgId);
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t errcode = TSDB_CODE_MND_ARB_TOKEN_MISMATCH;
|
||||
|
||||
if (ths->arbTerm > req.arbTerm) {
|
||||
sInfo("vgId:%d, skip to set assigned leader, msg with lower term, local:%" PRId64 "msg:%" PRId64, ths->vgId,
|
||||
ths->arbTerm, req.arbTerm);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
ths->arbTerm = TMAX(req.arbTerm, ths->arbTerm);
|
||||
|
||||
if (strncmp(req.memberToken, ths->arbToken, TSDB_ARB_TOKEN_SIZE) == 0) {
|
||||
if (ths->state != TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
raftStoreNextTerm(ths);
|
||||
if (terrno != TSDB_CODE_SUCCESS) {
|
||||
sError("vgId:%d, failed to set next term since:%s", ths->vgId, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
syncNodeBecomeAssignedLeader(ths);
|
||||
}
|
||||
errcode = TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SVArbSetAssignedLeaderRsp rsp = {0};
|
||||
rsp.arbToken = req.arbToken;
|
||||
rsp.memberToken = req.memberToken;
|
||||
rsp.vgId = ths->vgId;
|
||||
|
||||
int32_t contLen = tSerializeSVArbSetAssignedLeaderRsp(NULL, 0, &rsp);
|
||||
if (contLen <= 0) {
|
||||
sError("vgId:%d, failed to serialize SVArbSetAssignedLeaderRsp", ths->vgId);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
void* pHead = rpcMallocCont(contLen);
|
||||
if (!pHead) {
|
||||
sError("vgId:%d, failed to malloc memory for SVArbSetAssignedLeaderRsp", ths->vgId);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
if (tSerializeSVArbSetAssignedLeaderRsp(pHead, contLen, &rsp) <= 0) {
|
||||
sError("vgId:%d, failed to serialize SVArbSetAssignedLeaderRsp", ths->vgId);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
rpcFreeCont(pHead);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
SRpcMsg rspMsg = {
|
||||
.code = errcode,
|
||||
.pCont = pHead,
|
||||
.contLen = contLen,
|
||||
.info = pRpcMsg->info,
|
||||
};
|
||||
|
||||
tmsgSendRsp(&rspMsg);
|
||||
|
||||
ret = 0;
|
||||
|
||||
_OVER:
|
||||
tFreeSVArbSetAssignedLeaderReq(&req);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t syncSendTimeoutRsp(int64_t rid, int64_t seq) {
|
||||
SSyncNode* pNode = syncNodeAcquire(rid);
|
||||
if (pNode == NULL) return -1;
|
||||
|
@ -342,7 +417,7 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) {
|
|||
|
||||
if (pSyncNode->totalReplicaNum > 1) {
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER && pSyncNode->state != TAOS_SYNC_STATE_FOLLOWER &&
|
||||
pSyncNode->state != TAOS_SYNC_STATE_LEARNER) {
|
||||
pSyncNode->state != TAOS_SYNC_STATE_LEARNER && pSyncNode->state != TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
sNTrace(pSyncNode, "new-snapshot-index:%" PRId64 " candidate or unknown state, do not delete wal",
|
||||
lastApplyIndex);
|
||||
syncNodeRelease(pSyncNode);
|
||||
|
@ -434,7 +509,7 @@ bool syncNodeIsReadyForRead(SSyncNode* pSyncNode) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER && pSyncNode->state != TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||
return false;
|
||||
}
|
||||
|
@ -562,6 +637,55 @@ SSyncState syncGetState(int64_t rid) {
|
|||
return state;
|
||||
}
|
||||
|
||||
int32_t syncGetArbToken(int64_t rid, char* outToken) {
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(outToken, 0, TSDB_ARB_TOKEN_SIZE);
|
||||
taosThreadMutexLock(&pSyncNode->arbTokenMutex);
|
||||
strncpy(outToken, pSyncNode->arbToken, TSDB_ARB_TOKEN_SIZE);
|
||||
taosThreadMutexUnlock(&pSyncNode->arbTokenMutex);
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncGetAssignedLogSynced(int64_t rid) {
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||
terrno = TSDB_CODE_VND_ARB_NOT_SYNCED;
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool isSync = pSyncNode->commitIndex >= pSyncNode->assignedCommitIndex;
|
||||
terrno = (isSync ? TSDB_CODE_SUCCESS : TSDB_CODE_VND_ARB_NOT_SYNCED);
|
||||
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t syncUpdateArbTerm(int64_t rid, SyncTerm arbTerm) {
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
terrno = TSDB_CODE_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pSyncNode->arbTerm = TMAX(arbTerm, pSyncNode->arbTerm);
|
||||
syncNodeRelease(pSyncNode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapshotLastApplyIndex) {
|
||||
ASSERT(pSyncNode->raftCfg.configIndexCount >= 1);
|
||||
SyncIndex lastIndex = (pSyncNode->raftCfg.configIndexArr)[0];
|
||||
|
@ -668,8 +792,21 @@ ESyncRole syncGetRole(int64_t rid) {
|
|||
return role;
|
||||
}
|
||||
|
||||
int64_t syncGetTerm(int64_t rid) {
|
||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||
if (pSyncNode == NULL) {
|
||||
sError("sync Node Acquire error since %d", errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int64_t term = raftStoreGetTerm(pSyncNode);
|
||||
|
||||
syncNodeRelease(pSyncNode);
|
||||
return term;
|
||||
}
|
||||
|
||||
int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak, int64_t* seq) {
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER && pSyncNode->state != TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||
sNWarn(pSyncNode, "sync propose not leader, type:%s", TMSG_INFO(pMsg->msgType));
|
||||
return -1;
|
||||
|
@ -683,7 +820,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak, int64_
|
|||
}
|
||||
|
||||
// heartbeat timeout
|
||||
if (syncNodeHeartbeatReplyTimeout(pSyncNode)) {
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_ASSIGNED_LEADER && syncNodeHeartbeatReplyTimeout(pSyncNode)) {
|
||||
terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY;
|
||||
sNError(pSyncNode, "failed to sync propose since heartbeat timeout, type:%s, last:%" PRId64 ", cmt:%" PRId64,
|
||||
TMSG_INFO(pMsg->msgType), syncNodeGetLastIndex(pSyncNode), pSyncNode->commitIndex);
|
||||
|
@ -916,6 +1053,10 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo, int32_t vnodeVersion) {
|
|||
goto _error;
|
||||
}
|
||||
|
||||
pSyncNode->arbTerm = -1;
|
||||
taosThreadMutexInit(&pSyncNode->arbTokenMutex, NULL);
|
||||
syncUtilGenerateArbToken(pSyncNode->myNodeInfo.nodeId, pSyncInfo->vgId, pSyncNode->arbToken);
|
||||
|
||||
// init peersNum, peers, peersId
|
||||
pSyncNode->peersNum = pSyncNode->raftCfg.cfg.totalReplicaNum - 1;
|
||||
int32_t j = 0;
|
||||
|
@ -1138,6 +1279,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo, int32_t vnodeVersion) {
|
|||
pSyncNode->isStart = true;
|
||||
pSyncNode->electNum = 0;
|
||||
pSyncNode->becomeLeaderNum = 0;
|
||||
pSyncNode->becomeAssignedLeaderNum = 0;
|
||||
pSyncNode->configChangeNum = 0;
|
||||
pSyncNode->hbSlowNum = 0;
|
||||
pSyncNode->hbrSlowNum = 0;
|
||||
|
@ -1305,6 +1447,8 @@ void syncNodeClose(SSyncNode* pSyncNode) {
|
|||
syncLogBufferDestroy(pSyncNode->pLogBuf);
|
||||
pSyncNode->pLogBuf = NULL;
|
||||
|
||||
taosThreadMutexDestroy(&pSyncNode->arbTokenMutex);
|
||||
|
||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA; ++i) {
|
||||
if (pSyncNode->senders[i] != NULL) {
|
||||
sDebug("vgId:%d, snapshot sender destroy while close, data:%p", pSyncNode->vgId, pSyncNode->senders[i]);
|
||||
|
@ -1906,6 +2050,66 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) {
|
|||
sNInfo(pSyncNode, "become leader %s", debugStr);
|
||||
}
|
||||
|
||||
void syncNodeBecomeAssignedLeader(SSyncNode* pSyncNode) {
|
||||
pSyncNode->becomeAssignedLeaderNum++;
|
||||
pSyncNode->hbrSlowNum = 0;
|
||||
|
||||
// reset restoreFinish
|
||||
//pSyncNode->restoreFinish = false;
|
||||
|
||||
// state change
|
||||
pSyncNode->state = TAOS_SYNC_STATE_ASSIGNED_LEADER;
|
||||
pSyncNode->roleTimeMs = taosGetTimestampMs();
|
||||
|
||||
// set leader cache
|
||||
pSyncNode->leaderCache = pSyncNode->myRaftId;
|
||||
|
||||
for (int32_t i = 0; i < pSyncNode->pNextIndex->replicaNum; ++i) {
|
||||
SyncIndex lastIndex;
|
||||
SyncTerm lastTerm;
|
||||
int32_t code = syncNodeGetLastIndexTerm(pSyncNode, &lastIndex, &lastTerm);
|
||||
ASSERT(code == 0);
|
||||
pSyncNode->pNextIndex->index[i] = lastIndex + 1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pSyncNode->pMatchIndex->replicaNum; ++i) {
|
||||
// maybe overwrite myself, no harm
|
||||
// just do it!
|
||||
pSyncNode->pMatchIndex->index[i] = SYNC_INDEX_INVALID;
|
||||
}
|
||||
|
||||
// init peer mgr
|
||||
syncNodePeerStateInit(pSyncNode);
|
||||
|
||||
// close receiver
|
||||
if (snapshotReceiverIsStart(pSyncNode->pNewNodeReceiver)) {
|
||||
snapshotReceiverStop(pSyncNode->pNewNodeReceiver);
|
||||
}
|
||||
|
||||
// stop elect timer
|
||||
syncNodeStopElectTimer(pSyncNode);
|
||||
|
||||
// start heartbeat timer
|
||||
syncNodeStartHeartbeatTimer(pSyncNode);
|
||||
|
||||
// send heartbeat right now
|
||||
syncNodeHeartbeatPeers(pSyncNode);
|
||||
|
||||
// call back
|
||||
if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpBecomeAssignedLeaderCb != NULL) {
|
||||
pSyncNode->pFsm->FpBecomeAssignedLeaderCb(pSyncNode->pFsm);
|
||||
}
|
||||
|
||||
// min match index
|
||||
pSyncNode->minMatchIndex = SYNC_INDEX_INVALID;
|
||||
|
||||
// reset log buffer
|
||||
syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode);
|
||||
|
||||
// trace log
|
||||
sNInfo(pSyncNode, "become assigned leader");
|
||||
}
|
||||
|
||||
void syncNodeCandidate2Leader(SSyncNode* pSyncNode) {
|
||||
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE);
|
||||
bool granted = voteGrantedMajority(pSyncNode->pVotesGranted);
|
||||
|
@ -1972,6 +2176,24 @@ void syncNodeCandidate2Follower(SSyncNode* pSyncNode) {
|
|||
}
|
||||
#endif
|
||||
|
||||
int32_t syncNodeAssignedLeader2Leader(SSyncNode* pSyncNode) {
|
||||
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_ASSIGNED_LEADER);
|
||||
syncNodeBecomeLeader(pSyncNode, "assigned leader to leader");
|
||||
|
||||
sNTrace(pSyncNode, "assigned leader to leader");
|
||||
|
||||
int32_t ret = syncNodeAppendNoop(pSyncNode);
|
||||
if (ret < 0) {
|
||||
sError("vgId:%d, failed to append noop entry since %s", pSyncNode->vgId, terrstr());
|
||||
}
|
||||
|
||||
SyncIndex lastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
|
||||
sInfo("vgId:%d, become leader from assigned leader. term:%" PRId64 ", commit index:%" PRId64
|
||||
"assigned commit index:%" PRId64 ", last index:%" PRId64,
|
||||
pSyncNode->vgId, raftStoreGetTerm(pSyncNode), pSyncNode->commitIndex, pSyncNode->assignedCommitIndex, lastIndex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// just called by syncNodeVoteForSelf
|
||||
// need assert
|
||||
void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId) {
|
||||
|
@ -2291,7 +2513,7 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER && pSyncNode->state != TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
syncNodeRelease(pSyncNode);
|
||||
syncHbTimerDataRelease(pData);
|
||||
sError("vgId:%d, hb timer sync node not leader", pSyncNode->vgId);
|
||||
|
@ -2426,7 +2648,8 @@ int32_t syncNodeCheckChangeConfig(SSyncNode* ths, SSyncRaftEntry* pEntry) {
|
|||
SSyncCfg cfg = {0};
|
||||
syncBuildConfigFromReq(&req, &cfg);
|
||||
|
||||
if (cfg.totalReplicaNum >= 1 && ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||
if (cfg.totalReplicaNum >= 1 &&
|
||||
(ths->state == TAOS_SYNC_STATE_LEADER || ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER)) {
|
||||
bool incfg = false;
|
||||
for (int32_t j = 0; j < cfg.totalReplicaNum; ++j) {
|
||||
if (strcmp(ths->myNodeInfo.nodeFqdn, cfg.nodeInfo[j].nodeFqdn) == 0 &&
|
||||
|
@ -2934,6 +3157,16 @@ _out:;
|
|||
ths->vgId, pEntry->index, pEntry->term, ths->pLogBuf->startIndex, ths->pLogBuf->commitIndex,
|
||||
ths->pLogBuf->matchIndex, ths->pLogBuf->endIndex);
|
||||
|
||||
if (code == 0 && ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
(void)syncNodeUpdateAssignedCommitIndex(ths, matchIndex);
|
||||
|
||||
if (ths->fsmState != SYNC_FSM_STATE_INCOMPLETE &&
|
||||
syncLogBufferCommit(ths->pLogBuf, ths, ths->assignedCommitIndex) < 0) {
|
||||
sError("vgId:%d, failed to commit until commitIndex:%" PRId64 "", ths->vgId, ths->commitIndex);
|
||||
code = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// multi replica
|
||||
if (ths->replicaNum > 1) {
|
||||
return code;
|
||||
|
@ -3080,7 +3313,8 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
currentTerm = pMsg->term;
|
||||
}
|
||||
|
||||
if (pMsg->term == currentTerm && ths->state != TAOS_SYNC_STATE_LEADER) {
|
||||
if (pMsg->term == currentTerm &&
|
||||
(ths->state != TAOS_SYNC_STATE_LEADER && ths->state != TAOS_SYNC_STATE_ASSIGNED_LEADER)) {
|
||||
syncIndexMgrSetRecvTime(ths->pNextIndex, &(pMsg->srcId), tsMs);
|
||||
resetElect = true;
|
||||
|
||||
|
@ -3109,7 +3343,8 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
|
|||
}
|
||||
}
|
||||
|
||||
if (pMsg->term >= currentTerm && ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||
if (pMsg->term >= currentTerm &&
|
||||
(ths->state == TAOS_SYNC_STATE_LEADER || ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER)) {
|
||||
SRpcMsg rpcMsgLocalCmd = {0};
|
||||
(void)syncBuildLocalCmd(&rpcMsgLocalCmd, ths->vgId);
|
||||
|
||||
|
@ -3239,7 +3474,7 @@ int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIn
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||
if (ths->state == TAOS_SYNC_STATE_LEADER || ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
if (pRetIndex) {
|
||||
(*pRetIndex) = index;
|
||||
}
|
||||
|
@ -3288,6 +3523,8 @@ const char* syncStr(ESyncState state) {
|
|||
return "offline";
|
||||
case TAOS_SYNC_STATE_LEARNER:
|
||||
return "learner";
|
||||
case TAOS_SYNC_STATE_ASSIGNED_LEADER:
|
||||
return "assigned leader";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
|
|
|
@ -64,7 +64,8 @@ int32_t syncNodeReplicate(SSyncNode* pNode) {
|
|||
}
|
||||
|
||||
int32_t syncNodeReplicateWithoutLock(SSyncNode* pNode) {
|
||||
if (pNode->state != TAOS_SYNC_STATE_LEADER || pNode->raftCfg.cfg.totalReplicaNum == 1) {
|
||||
if ((pNode->state != TAOS_SYNC_STATE_LEADER && pNode->state != TAOS_SYNC_STATE_ASSIGNED_LEADER) ||
|
||||
pNode->raftCfg.cfg.totalReplicaNum == 1) {
|
||||
return -1;
|
||||
}
|
||||
for (int32_t i = 0; i < pNode->totalReplicaNum; i++) {
|
||||
|
|
|
@ -1242,7 +1242,7 @@ int32_t syncNodeOnSnapshotRsp(SSyncNode *pSyncNode, SRpcMsg *pRpcMsg) {
|
|||
goto _ERROR;
|
||||
}
|
||||
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER && pSyncNode->state != TAOS_SYNC_STATE_ASSIGNED_LEADER) {
|
||||
sSError(pSender, "snapshot sender not leader");
|
||||
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||
goto _ERROR;
|
||||
|
|
|
@ -77,7 +77,8 @@ static int32_t syncNodeTimerRoutine(SSyncNode* ths) {
|
|||
for (int i = 0; i < ths->peersNum; ++i) {
|
||||
SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(ths, &(ths->peersId[i]));
|
||||
if (pSender != NULL) {
|
||||
if (ths->isStart && ths->state == TAOS_SYNC_STATE_LEADER && pSender->start) {
|
||||
if (ths->isStart && (ths->state == TAOS_SYNC_STATE_LEADER || ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) &&
|
||||
pSender->start) {
|
||||
int64_t elapsedMs = timeNow - pSender->lastSendTime;
|
||||
if (elapsedMs < SYNC_SNAP_RESEND_MS) {
|
||||
continue;
|
||||
|
|
|
@ -103,6 +103,13 @@ bool syncUtilUserPreCommit(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP &&
|
|||
|
||||
bool syncUtilUserRollback(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER; }
|
||||
|
||||
void syncUtilGenerateArbToken(int32_t nodeId, int32_t groupId, char* buf) {
|
||||
memset(buf, 0, TSDB_ARB_TOKEN_SIZE);
|
||||
int32_t randVal = taosSafeRand() % 1000;
|
||||
int64_t currentMs = taosGetTimestampMs();
|
||||
snprintf(buf, TSDB_ARB_TOKEN_SIZE, "d%d#g%d#%" PRId64 "#%d", nodeId, groupId, currentMs, randVal);
|
||||
}
|
||||
|
||||
// for leader
|
||||
static void syncHearbeatReplyTime2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
||||
int32_t len = 0;
|
||||
|
@ -221,19 +228,22 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
|
|||
SyncIndex appliedIndex = pNode->pFsm->FpAppliedIndexCb(pNode->pFsm);
|
||||
|
||||
if (pNode != NULL) {
|
||||
taosPrintLog(flags, level, dflag,
|
||||
"vgId:%d, %s, sync:%s, term:%" PRIu64 ", commit-index:%" PRId64 ", applied-index:%" PRId64
|
||||
", first-ver:%" PRId64 ", last-ver:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64 ", snap-term:%" PRIu64
|
||||
", elect-times:%d, as-leader-times:%d, cfg-ch-times:%d, hb-slow:%d, hbr-slow:%d, "
|
||||
taosPrintLog(
|
||||
flags, level, dflag,
|
||||
"vgId:%d, %s, sync:%s, term:%" PRIu64 ", commit-index:%" PRId64 ", assigned-index:%" PRId64
|
||||
", applied-index:%" PRId64 ", first-ver:%" PRId64 ", last-ver:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
|
||||
", snap-term:%" PRIu64
|
||||
", elect-times:%d, as-leader-times:%d, as-assigned-leader-times:%d, cfg-ch-times:%d, hb-slow:%d, hbr-slow:%d, "
|
||||
"aq-items:%d, snaping:%" PRId64 ", replicas:%d, last-cfg:%" PRId64
|
||||
", chging:%d, restore:%d, quorum:%d, elect-lc-timer:%" PRId64 ", hb:%" PRId64
|
||||
", buffer:%s, repl-mgrs:%s, members:%s, hb:%s, hb-reply:%s",
|
||||
pNode->vgId, eventLog, syncStr(pNode->state), currentTerm, pNode->commitIndex, appliedIndex,
|
||||
logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
||||
pNode->electNum, pNode->becomeLeaderNum, pNode->configChangeNum, pNode->hbSlowNum, pNode->hbrSlowNum,
|
||||
aqItems, pNode->snapshottingIndex, pNode->replicaNum, pNode->raftCfg.lastConfigIndex, pNode->changing,
|
||||
pNode->restoreFinish, syncNodeDynamicQuorum(pNode), pNode->electTimerLogicClock,
|
||||
pNode->heartbeatTimerLogicClockUser, bufferStatesStr, replMgrStatesStr, cfgStr, hbTimeStr, hbrTimeStr);
|
||||
pNode->vgId, eventLog, syncStr(pNode->state), currentTerm, pNode->commitIndex, pNode->assignedCommitIndex,
|
||||
appliedIndex, logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex,
|
||||
snapshot.lastApplyTerm, pNode->electNum, pNode->becomeLeaderNum, pNode->becomeAssignedLeaderNum,
|
||||
pNode->configChangeNum, pNode->hbSlowNum, pNode->hbrSlowNum, aqItems, pNode->snapshottingIndex,
|
||||
pNode->replicaNum, pNode->raftCfg.lastConfigIndex, pNode->changing, pNode->restoreFinish,
|
||||
syncNodeDynamicQuorum(pNode), pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, bufferStatesStr,
|
||||
replMgrStatesStr, cfgStr, hbTimeStr, hbrTimeStr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -254,6 +254,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_SNODE_ALREADY_EXIST, "Snode can only be cre
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_SNODE_NOT_EXIST, "Snode not there")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_FEW_MNODES, "The replica of mnode cannot less than 1")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_MNODES, "The replica of mnode cannot exceed 3")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ARBGROUP_ALREADY_EXIST, "Arbitrator group already exists")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ARBGROUP_NOT_EXIST, "Arbitrator group not there")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ARB_TOKEN_MISMATCH, "Arbitrator token mismatch")
|
||||
|
||||
// mnode-dnode-part2
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_DNODES, "Too many dnodes")
|
||||
|
@ -368,6 +371,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_NOT_CATCH_UP, "Vnode didn't catch up
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_ALREADY_IS_VOTER, "Vnode already is a voter")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_DIR_ALREADY_EXIST, "Vnode directory already exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_META_DATA_UNSAFE_DELETE, "Single replica vnode data will lost permanently after this operation, if you make sure this, please use drop dnode <id> unsafe to execute")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_ARB_NOT_SYNCED, "Vgroup peer is not synced")
|
||||
|
||||
// tsdb
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, "Invalid table ID")
|
||||
|
|
|
@ -41,6 +41,12 @@
|
|||
#define LOG_BUF_SIZE(x) ((x)->buffSize)
|
||||
#define LOG_BUF_MUTEX(x) ((x)->buffMutex)
|
||||
|
||||
#ifdef TD_ENTERPRISE
|
||||
#define LOG_EDITION_FLG ("E")
|
||||
#else
|
||||
#define LOG_EDITION_FLG ("C")
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char *buffer;
|
||||
int32_t buffStart;
|
||||
|
@ -490,8 +496,9 @@ static inline int32_t taosBuildLogHead(char *buffer, const char *flags) {
|
|||
time_t curTime = timeSecs.tv_sec;
|
||||
ptm = taosLocalTime(&curTime, &Tm, NULL);
|
||||
|
||||
return sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " %s", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour,
|
||||
ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId(), flags);
|
||||
return sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " %s %s", ptm->tm_mon + 1, ptm->tm_mday,
|
||||
ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId(),
|
||||
LOG_EDITION_FLG, flags);
|
||||
}
|
||||
|
||||
static inline void taosPrintLogImp(ELogLevel level, int32_t dflag, const char *buffer, int32_t len) {
|
||||
|
|
|
@ -65,7 +65,7 @@ class TDTestCase:
|
|||
|
||||
tdSql.query('select count(*),db_name, stable_name from information_schema.ins_tables group by db_name, stable_name;')
|
||||
tdSql.checkRows(3)
|
||||
tdSql.checkData(0, 0, 29)
|
||||
tdSql.checkData(0, 0, 30)
|
||||
tdSql.checkData(0, 1, 'information_schema')
|
||||
tdSql.checkData(0, 2, None)
|
||||
tdSql.checkData(1, 0, 3)
|
||||
|
@ -77,7 +77,7 @@ class TDTestCase:
|
|||
|
||||
tdSql.query('select count(1) v,db_name, stable_name from information_schema.ins_tables group by db_name, stable_name order by v desc;')
|
||||
tdSql.checkRows(3)
|
||||
tdSql.checkData(0, 0, 29)
|
||||
tdSql.checkData(0, 0, 30)
|
||||
tdSql.checkData(0, 1, 'information_schema')
|
||||
tdSql.checkData(0, 2, None)
|
||||
tdSql.checkData(1, 0, 5)
|
||||
|
@ -93,7 +93,7 @@ class TDTestCase:
|
|||
tdSql.checkData(1, 1, 'performance_schema')
|
||||
tdSql.checkData(0, 0, 3)
|
||||
tdSql.checkData(0, 1, 'tbl_count')
|
||||
tdSql.checkData(2, 0, 29)
|
||||
tdSql.checkData(2, 0, 30)
|
||||
tdSql.checkData(2, 1, 'information_schema')
|
||||
|
||||
tdSql.query("select count(*) from information_schema.ins_tables where db_name='tbl_count'")
|
||||
|
@ -106,7 +106,7 @@ class TDTestCase:
|
|||
|
||||
tdSql.query('select count(*) from information_schema.ins_tables')
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0, 0, 37)
|
||||
tdSql.checkData(0, 0, 38)
|
||||
|
||||
|
||||
tdSql.execute('create table stba (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(10), c9 nchar(10), c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned) TAGS(t1 int, t2 binary(10), t3 double);')
|
||||
|
@ -189,7 +189,7 @@ class TDTestCase:
|
|||
tdSql.checkData(2, 0, 5)
|
||||
tdSql.checkData(2, 1, 'performance_schema')
|
||||
tdSql.checkData(2, 2, None)
|
||||
tdSql.checkData(3, 0, 29)
|
||||
tdSql.checkData(3, 0, 30)
|
||||
tdSql.checkData(3, 1, 'information_schema')
|
||||
tdSql.checkData(3, 2, None)
|
||||
|
||||
|
@ -204,7 +204,7 @@ class TDTestCase:
|
|||
tdSql.checkData(2, 0, 5)
|
||||
tdSql.checkData(2, 1, 'performance_schema')
|
||||
tdSql.checkData(2, 2, None)
|
||||
tdSql.checkData(3, 0, 29)
|
||||
tdSql.checkData(3, 0, 30)
|
||||
tdSql.checkData(3, 1, 'information_schema')
|
||||
tdSql.checkData(3, 2, None)
|
||||
|
||||
|
@ -215,7 +215,7 @@ class TDTestCase:
|
|||
tdSql.checkData(0, 1, 'tbl_count')
|
||||
tdSql.checkData(1, 0, 5)
|
||||
tdSql.checkData(1, 1, 'performance_schema')
|
||||
tdSql.checkData(2, 0, 29)
|
||||
tdSql.checkData(2, 0, 30)
|
||||
tdSql.checkData(2, 1, 'information_schema')
|
||||
|
||||
tdSql.query("select count(*) from information_schema.ins_tables where db_name='tbl_count'")
|
||||
|
@ -228,7 +228,7 @@ class TDTestCase:
|
|||
|
||||
tdSql.query('select count(*) from information_schema.ins_tables')
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0, 0, 38)
|
||||
tdSql.checkData(0, 0, 39)
|
||||
|
||||
|
||||
tdSql.execute('drop database tbl_count')
|
||||
|
|
|
@ -591,6 +591,7 @@
|
|||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/ts-4348-td-27939.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/backslash_g.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/test_ts4467.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/geometry.py
|
||||
|
||||
,,n,system-test,python3 ./test.py -f 2-query/queryQnode.py
|
||||
,,y,system-test,./pytest.sh python3 ./test.py -f 6-cluster/5dnode1mnode.py
|
||||
|
|
|
@ -362,7 +362,7 @@ if $data4_db != 1 then
|
|||
return -1
|
||||
endi
|
||||
sql drop database db
|
||||
sql_error create database db REPLICA 2
|
||||
#sql_error create database db REPLICA 2
|
||||
sql_error create database db REPLICA 0
|
||||
sql_error create database db REPLICA -1
|
||||
sql_error create database db REPLICA 4
|
||||
|
|
|
@ -58,7 +58,7 @@ endi
|
|||
|
||||
sql select tbname from information_schema.ins_tables;
|
||||
print $rows $data00
|
||||
if $rows != 38 then
|
||||
if $rows != 39 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != @ins_tables@ then
|
||||
|
|
|
@ -53,7 +53,7 @@ sql select stable_name,count(table_name) from information_schema.ins_tables grou
|
|||
if $rows != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 35 then
|
||||
if $data01 != 36 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 != 10 then
|
||||
|
@ -72,7 +72,7 @@ endi
|
|||
if $data11 != 5 then
|
||||
return -1
|
||||
endi
|
||||
if $data21 != 29 then
|
||||
if $data21 != 30 then
|
||||
return -1
|
||||
endi
|
||||
if $data31 != 5 then
|
||||
|
@ -97,7 +97,7 @@ endi
|
|||
if $data42 != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data52 != 29 then
|
||||
if $data52 != 30 then
|
||||
return -1
|
||||
endi
|
||||
if $data62 != 5 then
|
||||
|
|
|
@ -58,7 +58,7 @@ class TDTestCase:
|
|||
self.ins_list = ['ins_dnodes','ins_mnodes','ins_qnodes','ins_snodes','ins_cluster','ins_databases','ins_functions',\
|
||||
'ins_indexes','ins_stables','ins_tables','ins_tags','ins_columns','ins_users','ins_grants','ins_vgroups','ins_configs','ins_dnode_variables',\
|
||||
'ins_topics','ins_subscriptions','ins_streams','ins_stream_tasks','ins_vnodes','ins_user_privileges','ins_views',
|
||||
'ins_compacts', 'ins_compact_details', 'ins_grants_full','ins_grants_logs', 'ins_machines']
|
||||
'ins_compacts', 'ins_compact_details', 'ins_grants_full','ins_grants_logs', 'ins_machines', 'ins_arbgroups']
|
||||
self.perf_list = ['perf_connections','perf_queries','perf_consumers','perf_trans','perf_apps']
|
||||
def insert_data(self,column_dict,tbname,row_num):
|
||||
insert_sql = self.setsql.set_insertsql(column_dict,tbname,self.binary_str,self.nchar_str)
|
||||
|
|
|
@ -171,6 +171,25 @@ class TDTestCase:
|
|||
for i in range(tdSql.queryRows):
|
||||
tdSql.checkData(i, 0, expectedResults[5][i+1])
|
||||
|
||||
def test_td28365(self):
|
||||
# verify TD-28365
|
||||
tdSql.execute("create database db2;")
|
||||
tdSql.execute("use db2;")
|
||||
tdSql.execute("create table st (ts timestamp, c1 int) tags(id int, location geometry(512));")
|
||||
tdSql.execute("create table ct1 using st tags(1, 'POINT (3.000000 6.000000)')")
|
||||
tdSql.execute("insert into ct1 values(now, 1)")
|
||||
tdSql.execute("create table ct2 using st tags(2, 'LINESTRING (1.000000 1.000000, 2.000000 2.000000, 5.000000 5.000000)')")
|
||||
tdSql.execute("insert into ct2 values(now, 2)")
|
||||
tdSql.execute("create table ct3 using st tags(3, 'POLYGON ((3.000000 6.000000, 5.000000 6.000000, 5.000000 8.000000, 3.000000 8.000000, 3.000000 6.000000))')")
|
||||
tdSql.execute("insert into ct3 values(now, 3)")
|
||||
tdSql.query("select ST_AsText(location) from st order by location;")
|
||||
tdSql.checkEqual(tdSql.queryRows, 3)
|
||||
tdLog.debug(tdSql.queryResult)
|
||||
# check geometry data
|
||||
tdSql.checkEqual(tdSql.queryResult[0][0], "POINT (3.000000 6.000000)")
|
||||
tdSql.checkEqual(tdSql.queryResult[1][0], "LINESTRING (1.000000 1.000000, 2.000000 2.000000, 5.000000 5.000000)")
|
||||
tdSql.checkEqual(tdSql.queryResult[2][0], "POLYGON ((3.000000 6.000000, 5.000000 6.000000, 5.000000 8.000000, 3.000000 8.000000, 3.000000 6.000000))")
|
||||
|
||||
def run(self):
|
||||
tdSql.prepare()
|
||||
|
||||
|
@ -248,6 +267,7 @@ class TDTestCase:
|
|||
[1, self.point] # in where clause
|
||||
]
|
||||
self.geomRelationFunc_test('ST_ContainsProperly', expectedResults)
|
||||
self.test_td28365()
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
Loading…
Reference in New Issue