Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7923d51f
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7923d51f
编写于
6月 10, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' into feature/qnode
上级
6b3495af
bf605737
变更
41
隐藏空白更改
内联
并排
Showing
41 changed file
with
1331 addition
and
485 deletion
+1331
-485
include/libs/sync/sync.h
include/libs/sync/sync.h
+6
-3
include/util/taoserror.h
include/util/taoserror.h
+2
-1
source/client/src/clientSml.c
source/client/src/clientSml.c
+112
-85
source/client/test/smlTest.cpp
source/client/test/smlTest.cpp
+1
-1
source/common/src/systable.c
source/common/src/systable.c
+1
-1
source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
+3
-0
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+3
-3
source/dnode/mnode/impl/src/mndMain.c
source/dnode/mnode/impl/src/mndMain.c
+2
-2
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+9
-1
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+61
-33
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+94
-50
source/dnode/mnode/sdb/src/sdbFile.c
source/dnode/mnode/sdb/src/sdbFile.c
+1
-1
source/dnode/mnode/sdb/src/sdbHash.c
source/dnode/mnode/sdb/src/sdbHash.c
+2
-0
source/dnode/mnode/sdb/src/sdbRaw.c
source/dnode/mnode/sdb/src/sdbRaw.c
+4
-0
source/dnode/mnode/sdb/src/sdbRow.c
source/dnode/mnode/sdb/src/sdbRow.c
+4
-0
source/dnode/vnode/src/inc/tq.h
source/dnode/vnode/src/inc/tq.h
+1
-1
source/dnode/vnode/src/tq/tqRead.c
source/dnode/vnode/src/tq/tqRead.c
+4
-3
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+11
-1
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+8
-0
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+66
-0
source/libs/executor/src/timewindowoperator.c
source/libs/executor/src/timewindowoperator.c
+316
-39
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+1
-1
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+82
-71
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+2
-2
source/libs/sync/inc/syncRaftStore.h
source/libs/sync/inc/syncRaftStore.h
+2
-2
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+11
-10
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+27
-11
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+29
-8
source/libs/sync/src/syncCommit.c
source/libs/sync/src/syncCommit.c
+33
-11
source/libs/sync/src/syncEnv.c
source/libs/sync/src/syncEnv.c
+1
-1
source/libs/sync/src/syncIndexMgr.c
source/libs/sync/src/syncIndexMgr.c
+1
-1
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+92
-72
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+4
-1
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+1
-2
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+142
-60
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
+1
-1
source/libs/sync/test/syncConfigChangeTest.cpp
source/libs/sync/test/syncConfigChangeTest.cpp
+1
-1
source/libs/sync/test/syncSnapshotReceiverTest.cpp
source/libs/sync/test/syncSnapshotReceiverTest.cpp
+5
-1
source/libs/sync/test/syncTestTool.cpp
source/libs/sync/test/syncTestTool.cpp
+2
-3
source/util/src/terror.c
source/util/src/terror.c
+2
-1
tests/script/tsim/dnode/redistribute_vgroup_replica3_move_1_vnode.sim
.../tsim/dnode/redistribute_vgroup_replica3_move_1_vnode.sim
+181
-0
未找到文件。
include/libs/sync/sync.h
浏览文件 @
7923d51f
...
@@ -83,8 +83,10 @@ typedef struct SReConfigCbMeta {
...
@@ -83,8 +83,10 @@ typedef struct SReConfigCbMeta {
SyncTerm
term
;
SyncTerm
term
;
SyncTerm
currentTerm
;
SyncTerm
currentTerm
;
SSyncCfg
oldCfg
;
SSyncCfg
oldCfg
;
SSyncCfg
newCfg
;
bool
isDrop
;
bool
isDrop
;
uint64_t
flag
;
uint64_t
flag
;
uint64_t
seqNum
;
}
SReConfigCbMeta
;
}
SReConfigCbMeta
;
typedef
struct
SSnapshot
{
typedef
struct
SSnapshot
{
...
@@ -106,7 +108,7 @@ typedef struct SSyncFSM {
...
@@ -106,7 +108,7 @@ typedef struct SSyncFSM {
void
(
*
FpRollBackCb
)(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
);
void
(
*
FpRollBackCb
)(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
);
void
(
*
FpRestoreFinishCb
)(
struct
SSyncFSM
*
pFsm
);
void
(
*
FpRestoreFinishCb
)(
struct
SSyncFSM
*
pFsm
);
void
(
*
FpReConfigCb
)(
struct
SSyncFSM
*
pFsm
,
SSyncCfg
newCf
g
,
SReConfigCbMeta
cbMeta
);
void
(
*
FpReConfigCb
)(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMs
g
,
SReConfigCbMeta
cbMeta
);
int32_t
(
*
FpGetSnapshot
)(
struct
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
);
int32_t
(
*
FpGetSnapshot
)(
struct
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
);
...
@@ -184,7 +186,6 @@ int64_t syncOpen(const SSyncInfo* pSyncInfo);
...
@@ -184,7 +186,6 @@ int64_t syncOpen(const SSyncInfo* pSyncInfo);
void
syncStart
(
int64_t
rid
);
void
syncStart
(
int64_t
rid
);
void
syncStop
(
int64_t
rid
);
void
syncStop
(
int64_t
rid
);
int32_t
syncSetStandby
(
int64_t
rid
);
int32_t
syncSetStandby
(
int64_t
rid
);
int32_t
syncReconfig
(
int64_t
rid
,
const
SSyncCfg
*
pSyncCfg
);
ESyncState
syncGetMyRole
(
int64_t
rid
);
ESyncState
syncGetMyRole
(
int64_t
rid
);
const
char
*
syncGetMyRoleStr
(
int64_t
rid
);
const
char
*
syncGetMyRoleStr
(
int64_t
rid
);
SyncTerm
syncGetMyTerm
(
int64_t
rid
);
SyncTerm
syncGetMyTerm
(
int64_t
rid
);
...
@@ -194,8 +195,10 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak);
...
@@ -194,8 +195,10 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak);
bool
syncEnvIsStart
();
bool
syncEnvIsStart
();
const
char
*
syncStr
(
ESyncState
state
);
const
char
*
syncStr
(
ESyncState
state
);
bool
syncIsRestoreFinish
(
int64_t
rid
);
bool
syncIsRestoreFinish
(
int64_t
rid
);
int32_t
syncGetSnapshotMeta
(
int64_t
rid
,
struct
SSnapshotMeta
*
sMeta
);
int32_t
syncGetSnapshotMeta
(
int64_t
rid
,
struct
SSnapshotMeta
*
sMeta
);
int32_t
syncReconfig
(
int64_t
rid
,
const
SSyncCfg
*
pNewCfg
);
int32_t
syncReconfigRaw
(
int64_t
rid
,
const
SSyncCfg
*
pNewCfg
,
SRpcMsg
*
pRpcMsg
);
// to be moved to static
// to be moved to static
void
syncStartNormal
(
int64_t
rid
);
void
syncStartNormal
(
int64_t
rid
);
...
...
include/util/taoserror.h
浏览文件 @
7923d51f
...
@@ -85,7 +85,6 @@ int32_t* taosGetErrno();
...
@@ -85,7 +85,6 @@ int32_t* taosGetErrno();
#define TSDB_CODE_RPC_NETWORK_UNAVAIL TAOS_DEF_ERROR_CODE(0, 0x0102)
#define TSDB_CODE_RPC_NETWORK_UNAVAIL TAOS_DEF_ERROR_CODE(0, 0x0102)
#define TSDB_CODE_RPC_FQDN_ERROR TAOS_DEF_ERROR_CODE(0, 0x0103)
#define TSDB_CODE_RPC_FQDN_ERROR TAOS_DEF_ERROR_CODE(0, 0x0103)
#define TSDB_CODE_RPC_PORT_EADDRINUSE TAOS_DEF_ERROR_CODE(0, 0x0104)
#define TSDB_CODE_RPC_PORT_EADDRINUSE TAOS_DEF_ERROR_CODE(0, 0x0104)
#define TSDB_CODE_RPC_INDIRECT_NETWORK_UNAVAIL TAOS_DEF_ERROR_CODE(0, 0x0105)
//client
//client
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)
...
@@ -220,6 +219,7 @@ int32_t* taosGetErrno();
...
@@ -220,6 +219,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0392)
#define TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0392)
#define TSDB_CODE_MND_VGROUP_UN_CHANGED TAOS_DEF_ERROR_CODE(0, 0x0393)
#define TSDB_CODE_MND_VGROUP_UN_CHANGED TAOS_DEF_ERROR_CODE(0, 0x0393)
#define TSDB_CODE_MND_HAS_OFFLINE_DNODE TAOS_DEF_ERROR_CODE(0, 0x0394)
#define TSDB_CODE_MND_HAS_OFFLINE_DNODE TAOS_DEF_ERROR_CODE(0, 0x0394)
#define TSDB_CODE_MND_INVALID_REPLICA TAOS_DEF_ERROR_CODE(0, 0x0395)
// mnode-stable
// mnode-stable
#define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A0)
#define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A0)
...
@@ -260,6 +260,7 @@ int32_t* taosGetErrno();
...
@@ -260,6 +260,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_TRANS_CONFLICT TAOS_DEF_ERROR_CODE(0, 0x03D3)
#define TSDB_CODE_MND_TRANS_CONFLICT TAOS_DEF_ERROR_CODE(0, 0x03D3)
#define TSDB_CODE_MND_TRANS_UNKNOW_ERROR TAOS_DEF_ERROR_CODE(0, 0x03D4)
#define TSDB_CODE_MND_TRANS_UNKNOW_ERROR TAOS_DEF_ERROR_CODE(0, 0x03D4)
#define TSDB_CODE_MND_TRANS_CLOG_IS_NULL TAOS_DEF_ERROR_CODE(0, 0x03D5)
#define TSDB_CODE_MND_TRANS_CLOG_IS_NULL TAOS_DEF_ERROR_CODE(0, 0x03D5)
#define TSDB_CODE_MND_TRANS_NETWORK_UNAVAILL TAOS_DEF_ERROR_CODE(0, 0x03D6)
// mnode-mq
// mnode-mq
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E0)
#define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E0)
...
...
source/client/src/clientSml.c
浏览文件 @
7923d51f
...
@@ -17,6 +17,9 @@
...
@@ -17,6 +17,9 @@
#include "tname.h"
#include "tname.h"
#include "cJSON.h"
#include "cJSON.h"
#include "tglobal.h"
#include "tglobal.h"
#include "osSemaphore.h"
#include "osThread.h"
//=================================================================================================
//=================================================================================================
#define SPACE ' '
#define SPACE ' '
...
@@ -67,6 +70,9 @@ for (int i = 1; i < keyLen; ++i) { \
...
@@ -67,6 +70,9 @@ for (int i = 1; i < keyLen; ++i) { \
#define BINARY_ADD_LEN 2 // "binary" 2 means " "
#define BINARY_ADD_LEN 2 // "binary" 2 means " "
#define NCHAR_ADD_LEN 3 // L"nchar" 3 means L" "
#define NCHAR_ADD_LEN 3 // L"nchar" 3 means L" "
#define MAX_RETRY_TIMES 5
#define LINE_BATCH 20
//=================================================================================================
//=================================================================================================
typedef
TSDB_SML_PROTOCOL_TYPE
SMLProtocolType
;
typedef
TSDB_SML_PROTOCOL_TYPE
SMLProtocolType
;
...
@@ -153,8 +159,17 @@ typedef struct {
...
@@ -153,8 +159,17 @@ typedef struct {
int64_t
endTime
;
int64_t
endTime
;
}
SSmlCostInfo
;
}
SSmlCostInfo
;
typedef
struct
{
SRequestObj
*
request
;
SCatalog
*
catalog
;
tsem_t
sem
;
TdThreadSpinlock
lock
;
}
Params
;
typedef
struct
{
typedef
struct
{
int64_t
id
;
int64_t
id
;
Params
*
params
;
bool
isLast
;
SMLProtocolType
protocol
;
SMLProtocolType
protocol
;
int8_t
precision
;
int8_t
precision
;
...
@@ -303,7 +318,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
...
@@ -303,7 +318,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
uError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
uError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
}
}
taos_free_result
(
res2
);
taos_free_result
(
res2
);
taosMsleep
(
1
0
);
taosMsleep
(
50
0
);
}
}
break
;
break
;
}
}
...
@@ -327,7 +342,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
...
@@ -327,7 +342,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
uError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
uError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
}
}
taos_free_result
(
res2
);
taos_free_result
(
res2
);
taosMsleep
(
1
0
);
taosMsleep
(
50
0
);
}
}
break
;
break
;
}
}
...
@@ -350,7 +365,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
...
@@ -350,7 +365,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
uError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
uError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
}
}
taos_free_result
(
res2
);
taos_free_result
(
res2
);
taosMsleep
(
1
0
);
taosMsleep
(
50
0
);
}
}
break
;
break
;
}
}
...
@@ -373,7 +388,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
...
@@ -373,7 +388,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
uError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
uError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
}
}
taos_free_result
(
res2
);
taos_free_result
(
res2
);
taosMsleep
(
1
0
);
taosMsleep
(
50
0
);
}
}
break
;
break
;
}
}
...
@@ -424,7 +439,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
...
@@ -424,7 +439,7 @@ static int32_t smlApplySchemaAction(SSmlHandle* info, SSchemaAction* action) {
uError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
uError
(
"SML:0x%"
PRIx64
" apply schema action. reset query cache. error: %s"
,
info
->
id
,
taos_errstr
(
res2
));
}
}
taos_free_result
(
res2
);
taos_free_result
(
res2
);
taosMsleep
(
1
0
);
taosMsleep
(
50
0
);
}
}
break
;
break
;
}
}
...
@@ -545,56 +560,6 @@ end:
...
@@ -545,56 +560,6 @@ end:
return
code
;
return
code
;
}
}
//=========================================================================
/* Field Escape charaters
1: measurement Comma,Space
2: tag_key, tag_value, field_key Comma,Equal Sign,Space
3: field_value Double quote,Backslash
*/
//static void escapeSpecialCharacter(uint8_t field, const char **pos) {
// const char *cur = *pos;
// if (*cur != '\\') {
// return;
// }
// switch (field) {
// case 1:
// switch (*(cur + 1)) {
// case ',':
// case ' ':
// cur++;
// break;
// default:
// break;
// }
// break;
// case 2:
// switch (*(cur + 1)) {
// case ',':
// case ' ':
// case '=':
// cur++;
// break;
// default:
// break;
// }
// break;
// case 3:
// switch (*(cur + 1)) {
// case '"':
// case '\\':
// cur++;
// break;
// default:
// break;
// }
// break;
// default:
// break;
// }
// *pos = cur;
//}
static
bool
smlParseNumber
(
SSmlKv
*
kvVal
,
SSmlMsgBuf
*
msg
){
static
bool
smlParseNumber
(
SSmlKv
*
kvVal
,
SSmlMsgBuf
*
msg
){
const
char
*
pVal
=
kvVal
->
value
;
const
char
*
pVal
=
kvVal
->
value
;
int32_t
len
=
kvVal
->
length
;
int32_t
len
=
kvVal
->
length
;
...
@@ -1430,6 +1395,7 @@ static void smlDestroyInfo(SSmlHandle* info){
...
@@ -1430,6 +1395,7 @@ static void smlDestroyInfo(SSmlHandle* info){
if
(
!
info
->
dataFormat
){
if
(
!
info
->
dataFormat
){
taosArrayDestroy
(
info
->
colsContainer
);
taosArrayDestroy
(
info
->
colsContainer
);
}
}
destroyRequest
(
info
->
pRequest
);
taosMemoryFreeClear
(
info
);
taosMemoryFreeClear
(
info
);
}
}
...
@@ -1457,11 +1423,6 @@ static SSmlHandle* smlBuildSmlInfo(TAOS* taos, SRequestObj* request, SMLProtocol
...
@@ -1457,11 +1423,6 @@ static SSmlHandle* smlBuildSmlInfo(TAOS* taos, SRequestObj* request, SMLProtocol
((
SVnodeModifOpStmt
*
)(
info
->
pQuery
->
pRoot
))
->
payloadType
=
PAYLOAD_TYPE_KV
;
((
SVnodeModifOpStmt
*
)(
info
->
pQuery
->
pRoot
))
->
payloadType
=
PAYLOAD_TYPE_KV
;
info
->
taos
=
(
STscObj
*
)
taos
;
info
->
taos
=
(
STscObj
*
)
taos
;
code
=
catalogGetHandle
(
info
->
taos
->
pAppInfo
->
clusterId
,
&
info
->
pCatalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
){
uError
(
"SML:0x%"
PRIx64
" get catalog error %d"
,
info
->
id
,
code
);
goto
cleanup
;
}
info
->
precision
=
precision
;
info
->
precision
=
precision
;
info
->
protocol
=
protocol
;
info
->
protocol
=
protocol
;
...
@@ -2210,7 +2171,6 @@ end:
...
@@ -2210,7 +2171,6 @@ end:
return
ret
;
return
ret
;
}
}
static
int32_t
smlInsertData
(
SSmlHandle
*
info
)
{
static
int32_t
smlInsertData
(
SSmlHandle
*
info
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
@@ -2255,10 +2215,12 @@ static int32_t smlInsertData(SSmlHandle* info) {
...
@@ -2255,10 +2215,12 @@ static int32_t smlInsertData(SSmlHandle* info) {
}
}
info
->
cost
.
insertRpcTime
=
taosGetTimestampUs
();
info
->
cost
.
insertRpcTime
=
taosGetTimestampUs
();
launchQueryImpl
(
info
->
pRequest
,
info
->
pQuery
,
true
,
NULL
);
//launchQueryImpl(info->pRequest, info->pQuery, false, NULL);
// info->affectedRows = taos_affected_rows(info->pRequest);
// return info->pRequest->code;
info
->
affectedRows
=
taos_affected_rows
(
info
->
pRequest
);
launchAsyncQuery
(
info
->
pRequest
,
info
->
pQuery
);
return
info
->
pRequest
->
code
;
return
TSDB_CODE_SUCCESS
;
}
}
static
void
smlPrintStatisticInfo
(
SSmlHandle
*
info
){
static
void
smlPrintStatisticInfo
(
SSmlHandle
*
info
){
...
@@ -2318,7 +2280,7 @@ static int smlProcess(SSmlHandle *info, char* lines[], int numLines) {
...
@@ -2318,7 +2280,7 @@ static int smlProcess(SSmlHandle *info, char* lines[], int numLines) {
do
{
do
{
code
=
smlModifyDBSchemas
(
info
);
code
=
smlModifyDBSchemas
(
info
);
if
(
code
==
0
)
break
;
if
(
code
==
0
)
break
;
}
while
(
retryNum
++
<
taosHashGetSize
(
info
->
superTables
));
}
while
(
retryNum
++
<
taosHashGetSize
(
info
->
superTables
)
*
MAX_RETRY_TIMES
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
uError
(
"SML:0x%"
PRIx64
" smlModifyDBSchemas error : %s"
,
info
->
id
,
tstrerror
(
code
));
uError
(
"SML:0x%"
PRIx64
" smlModifyDBSchemas error : %s"
,
info
->
id
,
tstrerror
(
code
));
...
@@ -2339,9 +2301,9 @@ cleanup:
...
@@ -2339,9 +2301,9 @@ cleanup:
return
code
;
return
code
;
}
}
static
int32_t
isSchemalessDb
(
S
SmlHandle
*
info
){
static
int32_t
isSchemalessDb
(
S
TscObj
*
taos
,
SCatalog
*
catalog
){
SName
name
;
SName
name
;
tNameSetDbName
(
&
name
,
info
->
taos
->
acctId
,
info
->
taos
->
db
,
strlen
(
info
->
taos
->
db
));
tNameSetDbName
(
&
name
,
taos
->
acctId
,
taos
->
db
,
strlen
(
taos
->
db
));
char
dbFname
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
char
dbFname
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
tNameGetFullDbName
(
&
name
,
dbFname
);
tNameGetFullDbName
(
&
name
,
dbFname
);
SDbCfgInfo
pInfo
=
{
0
};
SDbCfgInfo
pInfo
=
{
0
};
...
@@ -2352,20 +2314,38 @@ static int32_t isSchemalessDb(SSmlHandle* info){
...
@@ -2352,20 +2314,38 @@ static int32_t isSchemalessDb(SSmlHandle* info){
int32_t
code
=
catalogGetDBCfg
(
info
->
pCatalog
,
&
conn
,
dbFname
,
&
pInfo
);
int32_t
code
=
catalogGetDBCfg
(
info
->
pCatalog
,
&
conn
,
dbFname
,
&
pInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
info
->
pRequest
->
code
=
code
;
smlBuildInvalidDataMsg
(
&
info
->
msgBuf
,
"catalogGetDBCfg error, code:"
,
tstrerror
(
code
));
return
code
;
return
code
;
}
}
taosArrayDestroy
(
pInfo
.
pRetensions
);
taosArrayDestroy
(
pInfo
.
pRetensions
);
if
(
!
pInfo
.
schemaless
){
if
(
!
pInfo
.
schemaless
){
info
->
pRequest
->
code
=
TSDB_CODE_SML_INVALID_DB_CONF
;
smlBuildInvalidDataMsg
(
&
info
->
msgBuf
,
"can not insert into schemaless db:"
,
dbFname
);
return
TSDB_CODE_SML_INVALID_DB_CONF
;
return
TSDB_CODE_SML_INVALID_DB_CONF
;
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
void
smlInsertCallback
(
void
*
param
,
void
*
res
,
int32_t
code
)
{
SRequestObj
*
pRequest
=
(
SRequestObj
*
)
res
;
SSmlHandle
*
info
=
(
SSmlHandle
*
)
param
;
// lock
if
(
code
!=
TSDB_CODE_SUCCESS
){
taosThreadSpinLock
(
&
info
->
params
->
lock
);
info
->
params
->
request
->
code
=
code
;
taosThreadSpinUnlock
(
&
info
->
params
->
lock
);
}
// unlock
printf
(
"SML:0x%"
PRIx64
" insert finished, code: %d, total: %d
\n
"
,
info
->
id
,
code
,
info
->
affectedRows
);
Params
*
pParam
=
info
->
params
;
bool
isLast
=
info
->
isLast
;
smlDestroyInfo
(
info
);
if
(
isLast
){
tsem_post
(
&
pParam
->
sem
);
}
}
/**
/**
* taos_schemaless_insert() parse and insert data points into database according to
* taos_schemaless_insert() parse and insert data points into database according to
* different protocol.
* different protocol.
...
@@ -2394,48 +2374,95 @@ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int pr
...
@@ -2394,48 +2374,95 @@ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int pr
return
NULL
;
return
NULL
;
}
}
SSmlHandle
*
info
=
smlBuildSmlInfo
(
taos
,
request
,
(
SMLProtocolType
)
protocol
,
precision
);
((
STscObj
*
)
taos
)
->
schemalessType
=
1
;
if
(
!
info
){
SSmlMsgBuf
msg
=
{
ERROR_MSG_BUF_DEFAULT_SIZE
,
request
->
msgBuf
};
return
(
TAOS_RES
*
)
request
;
int
cnt
=
ceil
(((
double
)
numLines
)
/
LINE_BATCH
);
Params
params
;
params
.
request
=
request
;
tsem_init
(
&
params
.
sem
,
0
,
0
);
taosThreadSpinInit
(
&
(
params
.
lock
),
0
);
int32_t
code
=
catalogGetHandle
(((
STscObj
*
)
taos
)
->
pAppInfo
->
clusterId
,
&
params
.
catalog
);
if
(
code
!=
TSDB_CODE_SUCCESS
){
uError
(
"SML get catalog error %d"
,
code
);
request
->
code
=
code
;
goto
end
;
}
}
info
->
taos
->
schemalessType
=
1
;
if
(
request
->
pDb
==
NULL
){
if
(
request
->
pDb
==
NULL
){
request
->
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
request
->
code
=
TSDB_CODE_PAR_DB_NOT_SPECIFIED
;
smlBuildInvalidDataMsg
(
&
info
->
msgBuf
,
"Database not specified"
,
NULL
);
smlBuildInvalidDataMsg
(
&
msg
,
"Database not specified"
,
NULL
);
goto
end
;
goto
end
;
}
}
if
(
isSchemalessDb
(
info
)
!=
TSDB_CODE_SUCCESS
){
if
(
isSchemalessDb
(
((
STscObj
*
)
taos
),
params
.
catalog
)
!=
TSDB_CODE_SUCCESS
){
request
->
code
=
TSDB_CODE_SML_INVALID_DB_CONF
;
request
->
code
=
TSDB_CODE_SML_INVALID_DB_CONF
;
smlBuildInvalidDataMsg
(
&
info
->
msgBuf
,
"Cannot write data to a non schemaless database"
,
NULL
);
smlBuildInvalidDataMsg
(
&
msg
,
"Cannot write data to a non schemaless database"
,
NULL
);
goto
end
;
goto
end
;
}
}
if
(
!
lines
)
{
if
(
!
lines
)
{
request
->
code
=
TSDB_CODE_SML_INVALID_DATA
;
request
->
code
=
TSDB_CODE_SML_INVALID_DATA
;
smlBuildInvalidDataMsg
(
&
info
->
msgBuf
,
"lines is null"
,
NULL
);
smlBuildInvalidDataMsg
(
&
msg
,
"lines is null"
,
NULL
);
goto
end
;
goto
end
;
}
}
if
(
protocol
<
TSDB_SML_LINE_PROTOCOL
||
protocol
>
TSDB_SML_JSON_PROTOCOL
){
if
(
protocol
<
TSDB_SML_LINE_PROTOCOL
||
protocol
>
TSDB_SML_JSON_PROTOCOL
){
request
->
code
=
TSDB_CODE_SML_INVALID_PROTOCOL_TYPE
;
request
->
code
=
TSDB_CODE_SML_INVALID_PROTOCOL_TYPE
;
smlBuildInvalidDataMsg
(
&
info
->
msgBuf
,
"protocol invalidate"
,
NULL
);
smlBuildInvalidDataMsg
(
&
msg
,
"protocol invalidate"
,
NULL
);
goto
end
;
goto
end
;
}
}
if
(
protocol
==
TSDB_SML_LINE_PROTOCOL
&&
(
precision
<
TSDB_SML_TIMESTAMP_NOT_CONFIGURED
||
precision
>
TSDB_SML_TIMESTAMP_NANO_SECONDS
)){
if
(
protocol
==
TSDB_SML_LINE_PROTOCOL
&&
(
precision
<
TSDB_SML_TIMESTAMP_NOT_CONFIGURED
||
precision
>
TSDB_SML_TIMESTAMP_NANO_SECONDS
)){
request
->
code
=
TSDB_CODE_SML_INVALID_PRECISION_TYPE
;
request
->
code
=
TSDB_CODE_SML_INVALID_PRECISION_TYPE
;
smlBuildInvalidDataMsg
(
&
info
->
msgBuf
,
"precision invalidate for line protocol"
,
NULL
);
smlBuildInvalidDataMsg
(
&
msg
,
"precision invalidate for line protocol"
,
NULL
);
goto
end
;
goto
end
;
}
}
info
->
pRequest
->
code
=
smlProcess
(
info
,
lines
,
numLines
);
for
(
int
i
=
0
;
i
<
cnt
;
++
i
)
{
SRequestObj
*
req
=
(
SRequestObj
*
)
createRequest
((
STscObj
*
)
taos
,
TSDB_SQL_INSERT
);
if
(
!
req
){
request
->
code
=
TSDB_CODE_OUT_OF_MEMORY
;
uError
(
"SML:taos_schemaless_insert error request is null"
);
goto
end
;
}
SSmlHandle
*
info
=
smlBuildSmlInfo
(
taos
,
req
,
(
SMLProtocolType
)
protocol
,
precision
);
if
(
!
info
){
request
->
code
=
TSDB_CODE_OUT_OF_MEMORY
;
uError
(
"SML:taos_schemaless_insert error SSmlHandle is null"
);
goto
end
;
}
int32_t
perBatch
=
LINE_BATCH
;
if
(
numLines
>
perBatch
){
numLines
-=
perBatch
;
info
->
isLast
=
false
;
}
else
{
perBatch
=
numLines
;
numLines
=
0
;
info
->
isLast
=
true
;
}
info
->
params
=
&
params
;
info
->
pCatalog
=
params
.
catalog
;
info
->
affectedRows
=
perBatch
;
info
->
pRequest
->
body
.
queryFp
=
smlInsertCallback
;
info
->
pRequest
->
body
.
param
=
info
;
code
=
smlProcess
(
info
,
lines
,
perBatch
);
lines
+=
perBatch
;
if
(
code
!=
TSDB_CODE_SUCCESS
){
info
->
pRequest
->
body
.
queryFp
(
info
,
req
,
code
);
}
}
tsem_wait
(
&
params
.
sem
);
end:
end:
info
->
taos
->
schemalessType
=
0
;
taosThreadSpinDestroy
(
&
params
.
lock
);
uDebug
(
"result:%s"
,
info
->
msgBuf
.
buf
);
tsem_destroy
(
&
params
.
sem
);
smlDestroyInfo
(
info
);
((
STscObj
*
)
taos
)
->
schemalessType
=
0
;
uDebug
(
"result:%s"
,
request
->
msgBuf
);
return
(
TAOS_RES
*
)
request
;
return
(
TAOS_RES
*
)
request
;
}
}
source/client/test/smlTest.cpp
浏览文件 @
7923d51f
...
@@ -1325,7 +1325,7 @@ TEST(testCase, sml_oom_Test) {
...
@@ -1325,7 +1325,7 @@ TEST(testCase, sml_oom_Test) {
pRes
=
taos_query
(
taos
,
"use oom"
);
pRes
=
taos_query
(
taos
,
"use oom"
);
taos_free_result
(
pRes
);
taos_free_result
(
pRes
);
TAOS_RES
*
res
=
taos_schemaless_insert
(
taos
,
(
char
**
)
sql
,
100
,
TSDB_SML_LINE_PROTOCOL
,
0
);
TAOS_RES
*
res
=
taos_schemaless_insert
(
taos
,
(
char
**
)
sql
,
sizeof
(
sql
)
/
sizeof
(
sql
[
0
])
,
TSDB_SML_LINE_PROTOCOL
,
0
);
ASSERT_EQ
(
taos_errno
(
res
),
0
);
ASSERT_EQ
(
taos_errno
(
res
),
0
);
taos_free_result
(
pRes
);
taos_free_result
(
pRes
);
}
}
...
...
source/common/src/systable.c
浏览文件 @
7923d51f
...
@@ -221,7 +221,7 @@ static const SSysDbTableSchema transSchema[] = {
...
@@ -221,7 +221,7 @@ static const SSysDbTableSchema transSchema[] = {
{.
name
=
"db"
,
.
bytes
=
SYSTABLE_SCH_DB_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"db"
,
.
bytes
=
SYSTABLE_SCH_DB_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"failed_times"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"failed_times"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"last_exec_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
{.
name
=
"last_exec_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
{.
name
=
"last_
error
"
,
.
bytes
=
(
TSDB_TRANS_ERROR_LEN
-
1
)
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
{.
name
=
"last_
action_info
"
,
.
bytes
=
(
TSDB_TRANS_ERROR_LEN
-
1
)
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
},
};
};
static
const
SSysDbTableSchema
configSchema
[]
=
{
static
const
SSysDbTableSchema
configSchema
[]
=
{
...
...
source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
浏览文件 @
7923d51f
...
@@ -170,6 +170,9 @@ SArray *mmGetMsgHandles() {
...
@@ -170,6 +170,9 @@ SArray *mmGetMsgHandles() {
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_COMPACT_DB
,
mmPutNodeMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_COMPACT_DB
,
mmPutNodeMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_GET_DB_CFG
,
mmPutNodeMsgToReadQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_GET_DB_CFG
,
mmPutNodeMsgToReadQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_VGROUP_LIST
,
mmPutNodeMsgToReadQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_VGROUP_LIST
,
mmPutNodeMsgToReadQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_REDISTRIBUTE_VGROUP
,
mmPutNodeMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_MERGE_VGROUP
,
mmPutNodeMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_BALANCE_VGROUP
,
mmPutNodeMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_CREATE_FUNC
,
mmPutNodeMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_CREATE_FUNC
,
mmPutNodeMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_RETRIEVE_FUNC
,
mmPutNodeMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_RETRIEVE_FUNC
,
mmPutNodeMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_DROP_FUNC
,
mmPutNodeMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MND_DROP_FUNC
,
mmPutNodeMsgToWriteQueue
,
0
)
==
NULL
)
goto
_OVER
;
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
7923d51f
...
@@ -120,10 +120,10 @@ typedef struct {
...
@@ -120,10 +120,10 @@ typedef struct {
SArray
*
commitActions
;
SArray
*
commitActions
;
int64_t
createdTime
;
int64_t
createdTime
;
int64_t
lastExecTime
;
int64_t
lastExecTime
;
int32_t
last
Error
Action
;
int32_t
lastAction
;
int32_t
lastErrorNo
;
int32_t
lastErrorNo
;
tmsg_t
last
Error
MsgType
;
tmsg_t
lastMsgType
;
SEpSet
lastE
rrorE
pset
;
SEpSet
lastEpset
;
char
dbname
[
TSDB_DB_FNAME_LEN
];
char
dbname
[
TSDB_DB_FNAME_LEN
];
int32_t
startFunc
;
int32_t
startFunc
;
int32_t
stopFunc
;
int32_t
stopFunc
;
...
...
source/dnode/mnode/impl/src/mndMain.c
浏览文件 @
7923d51f
...
@@ -217,8 +217,8 @@ static int32_t mndInitSteps(SMnode *pMnode) {
...
@@ -217,8 +217,8 @@ static int32_t mndInitSteps(SMnode *pMnode) {
if
(
mndAllocStep
(
pMnode
,
"mnode-cluster"
,
mndInitCluster
,
mndCleanupCluster
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-cluster"
,
mndInitCluster
,
mndCleanupCluster
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-mnode"
,
mndInitMnode
,
mndCleanupMnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-mnode"
,
mndInitMnode
,
mndCleanupMnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-qnode"
,
mndInitQnode
,
mndCleanupQnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-qnode"
,
mndInitQnode
,
mndCleanupQnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-
q
node"
,
mndInitSnode
,
mndCleanupSnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-
s
node"
,
mndInitSnode
,
mndCleanupSnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-
q
node"
,
mndInitBnode
,
mndCleanupBnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-
b
node"
,
mndInitBnode
,
mndCleanupBnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-dnode"
,
mndInitDnode
,
mndCleanupDnode
)
!=
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-user"
,
mndInitUser
,
mndCleanupUser
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-grant"
,
mndInitGrant
,
mndCleanupGrant
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-grant"
,
mndInitGrant
,
mndCleanupGrant
)
!=
0
)
return
-
1
;
...
...
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
7923d51f
...
@@ -96,10 +96,18 @@ void mndRestoreFinish(struct SSyncFSM *pFsm) {
...
@@ -96,10 +96,18 @@ void mndRestoreFinish(struct SSyncFSM *pFsm) {
}
}
}
}
void
mndReConfig
(
struct
SSyncFSM
*
pFsm
,
SSyncCfg
newCf
g
,
SReConfigCbMeta
cbMeta
)
{
void
mndReConfig
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMs
g
,
SReConfigCbMeta
cbMeta
)
{
SMnode
*
pMnode
=
pFsm
->
data
;
SMnode
*
pMnode
=
pFsm
->
data
;
SSyncMgmt
*
pMgmt
=
&
pMnode
->
syncMgmt
;
SSyncMgmt
*
pMgmt
=
&
pMnode
->
syncMgmt
;
#if 0
// send response
SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen, .conn.applyIndex = cbMeta.index};
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen);
syncGetAndDelRespRpc(pMnode->syncMgmt.sync, cbMeta.seqNum, &rpcMsg.info);
#endif
pMgmt
->
errCode
=
cbMeta
.
code
;
pMgmt
->
errCode
=
cbMeta
.
code
;
mInfo
(
"trans:-1, sync reconfig is proposed, saved:%d code:0x%x, index:%"
PRId64
" term:%"
PRId64
,
pMgmt
->
transId
,
mInfo
(
"trans:-1, sync reconfig is proposed, saved:%d code:0x%x, index:%"
PRId64
" term:%"
PRId64
,
pMgmt
->
transId
,
cbMeta
.
code
,
cbMeta
.
index
,
cbMeta
.
term
);
cbMeta
.
code
,
cbMeta
.
index
,
cbMeta
.
term
);
...
...
source/dnode/mnode/impl/src/mndTrans.c
浏览文件 @
7923d51f
...
@@ -781,7 +781,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
...
@@ -781,7 +781,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
sendRsp
=
true
;
sendRsp
=
true
;
}
}
}
else
{
}
else
{
if
(
pTrans
->
stage
==
TRN_STAGE_REDO_ACTION
&&
pTrans
->
failedTimes
>
3
)
{
if
(
pTrans
->
stage
==
TRN_STAGE_REDO_ACTION
&&
pTrans
->
failedTimes
>
2
)
{
if
(
code
==
0
)
code
=
TSDB_CODE_MND_TRANS_UNKNOW_ERROR
;
if
(
code
==
0
)
code
=
TSDB_CODE_MND_TRANS_UNKNOW_ERROR
;
sendRsp
=
true
;
sendRsp
=
true
;
}
}
...
@@ -791,7 +791,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
...
@@ -791,7 +791,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
mDebug
(
"trans:%d, send rsp, code:0x%x stage:%s app:%p"
,
pTrans
->
id
,
code
,
mndTransStr
(
pTrans
->
stage
),
mDebug
(
"trans:%d, send rsp, code:0x%x stage:%s app:%p"
,
pTrans
->
id
,
code
,
mndTransStr
(
pTrans
->
stage
),
pTrans
->
rpcInfo
.
ahandle
);
pTrans
->
rpcInfo
.
ahandle
);
if
(
code
==
TSDB_CODE_RPC_NETWORK_UNAVAIL
)
{
if
(
code
==
TSDB_CODE_RPC_NETWORK_UNAVAIL
)
{
code
=
TSDB_CODE_
RPC_INDIRECT_NETWORK_UNAVAI
L
;
code
=
TSDB_CODE_
MND_TRANS_NETWORK_UNAVAIL
L
;
}
}
SRpcMsg
rspMsg
=
{.
code
=
code
,
.
info
=
pTrans
->
rpcInfo
};
SRpcMsg
rspMsg
=
{.
code
=
code
,
.
info
=
pTrans
->
rpcInfo
};
...
@@ -894,10 +894,19 @@ static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransActi
...
@@ -894,10 +894,19 @@ static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransActi
code
=
0
;
code
=
0
;
mDebug
(
"trans:%d, %s:%d write to sdb, type:%s status:%s"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
,
mDebug
(
"trans:%d, %s:%d write to sdb, type:%s status:%s"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
,
sdbTableName
(
pAction
->
pRaw
->
type
),
sdbStatusName
(
pAction
->
pRaw
->
status
));
sdbTableName
(
pAction
->
pRaw
->
type
),
sdbStatusName
(
pAction
->
pRaw
->
status
));
pTrans
->
lastAction
=
pAction
->
id
;
pTrans
->
lastMsgType
=
pAction
->
msgType
;
pTrans
->
lastEpset
=
pAction
->
epSet
;
pTrans
->
lastErrorNo
=
0
;
}
else
{
}
else
{
pAction
->
errCode
=
(
terrno
!=
0
)
?
terrno
:
code
;
pAction
->
errCode
=
(
terrno
!=
0
)
?
terrno
:
code
;
mError
(
"trans:%d, %s:%d failed to write sdb since %s, type:%s status:%s"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
mError
(
"trans:%d, %s:%d failed to write sdb since %s, type:%s status:%s"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
,
terrstr
(),
sdbTableName
(
pAction
->
pRaw
->
type
),
sdbStatusName
(
pAction
->
pRaw
->
status
));
pAction
->
id
,
terrstr
(),
sdbTableName
(
pAction
->
pRaw
->
type
),
sdbStatusName
(
pAction
->
pRaw
->
status
));
pTrans
->
lastAction
=
pAction
->
id
;
pTrans
->
lastMsgType
=
pAction
->
msgType
;
pTrans
->
lastEpset
=
pAction
->
epSet
;
pTrans
->
lastErrorNo
=
pAction
->
errCode
;
}
}
return
code
;
return
code
;
...
@@ -933,27 +942,48 @@ static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransActio
...
@@ -933,27 +942,48 @@ static int32_t mndTransSendSingleMsg(SMnode *pMnode, STrans *pTrans, STransActio
pAction
->
msgReceived
=
0
;
pAction
->
msgReceived
=
0
;
pAction
->
errCode
=
0
;
pAction
->
errCode
=
0
;
mDebug
(
"trans:%d, %s:%d is sent, %s"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
,
detail
);
mDebug
(
"trans:%d, %s:%d is sent, %s"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
,
detail
);
pTrans
->
lastAction
=
pAction
->
id
;
pTrans
->
lastMsgType
=
pAction
->
msgType
;
pTrans
->
lastEpset
=
pAction
->
epSet
;
if
(
pTrans
->
lastErrorNo
==
0
)
{
pTrans
->
lastErrorNo
=
TSDB_CODE_ACTION_IN_PROGRESS
;
}
}
else
{
}
else
{
pAction
->
msgSent
=
0
;
pAction
->
msgSent
=
0
;
pAction
->
msgReceived
=
0
;
pAction
->
msgReceived
=
0
;
pAction
->
errCode
=
(
terrno
!=
0
)
?
terrno
:
code
;
pAction
->
errCode
=
(
terrno
!=
0
)
?
terrno
:
code
;
mError
(
"trans:%d, %s:%d not send since %s, %s"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
,
terrstr
(),
mError
(
"trans:%d, %s:%d not send since %s, %s"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
,
terrstr
(),
detail
);
detail
);
pTrans
->
lastAction
=
pAction
->
id
;
pTrans
->
lastMsgType
=
pAction
->
msgType
;
pTrans
->
lastEpset
=
pAction
->
epSet
;
pTrans
->
lastErrorNo
=
pAction
->
errCode
;
}
}
return
code
;
return
code
;
}
}
static
int32_t
mndTransExecNullMsg
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
STransAction
*
pAction
)
{
pAction
->
rawWritten
=
0
;
pAction
->
errCode
=
0
;
mDebug
(
"trans:%d, %s:%d null action executed"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
);
pTrans
->
lastAction
=
pAction
->
id
;
pTrans
->
lastMsgType
=
pAction
->
msgType
;
pTrans
->
lastEpset
=
pAction
->
epSet
;
pTrans
->
lastErrorNo
==
0
;
return
0
;
}
static
int32_t
mndTransExecSingleAction
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
STransAction
*
pAction
)
{
static
int32_t
mndTransExecSingleAction
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
STransAction
*
pAction
)
{
if
(
pAction
->
actionType
==
TRANS_ACTION_RAW
)
{
if
(
pAction
->
actionType
==
TRANS_ACTION_RAW
)
{
return
mndTransWriteSingleLog
(
pMnode
,
pTrans
,
pAction
);
return
mndTransWriteSingleLog
(
pMnode
,
pTrans
,
pAction
);
}
else
if
(
pAction
->
actionType
==
TRANS_ACTION_MSG
)
{
}
else
if
(
pAction
->
actionType
==
TRANS_ACTION_MSG
)
{
return
mndTransSendSingleMsg
(
pMnode
,
pTrans
,
pAction
);
return
mndTransSendSingleMsg
(
pMnode
,
pTrans
,
pAction
);
}
else
{
}
else
{
pAction
->
rawWritten
=
0
;
return
mndTransExecNullMsg
(
pMnode
,
pTrans
,
pAction
);
pAction
->
errCode
=
0
;
mDebug
(
"trans:%d, %s:%d null action executed"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
);
return
0
;
}
}
}
}
...
@@ -994,19 +1024,19 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA
...
@@ -994,19 +1024,19 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA
if
(
numOfExecuted
==
numOfActions
)
{
if
(
numOfExecuted
==
numOfActions
)
{
if
(
errCode
==
0
)
{
if
(
errCode
==
0
)
{
pTrans
->
last
Error
Action
=
0
;
pTrans
->
lastAction
=
0
;
pTrans
->
lastErrorNo
=
0
;
pTrans
->
lastErrorNo
=
0
;
pTrans
->
last
Error
MsgType
=
0
;
pTrans
->
lastMsgType
=
0
;
memset
(
&
pTrans
->
lastE
rrorEpset
,
0
,
sizeof
(
pTrans
->
lastError
Epset
));
memset
(
&
pTrans
->
lastE
pset
,
0
,
sizeof
(
pTrans
->
last
Epset
));
mDebug
(
"trans:%d, all %d actions execute successfully"
,
pTrans
->
id
,
numOfActions
);
mDebug
(
"trans:%d, all %d actions execute successfully"
,
pTrans
->
id
,
numOfActions
);
return
0
;
return
0
;
}
else
{
}
else
{
mError
(
"trans:%d, all %d actions executed, code:0x%x"
,
pTrans
->
id
,
numOfActions
,
errCode
&
0XFFFF
);
mError
(
"trans:%d, all %d actions executed, code:0x%x"
,
pTrans
->
id
,
numOfActions
,
errCode
&
0XFFFF
);
if
(
pErrAction
!=
NULL
)
{
if
(
pErrAction
!=
NULL
)
{
pTrans
->
last
Error
MsgType
=
pErrAction
->
msgType
;
pTrans
->
lastMsgType
=
pErrAction
->
msgType
;
pTrans
->
last
Error
Action
=
pErrAction
->
id
;
pTrans
->
lastAction
=
pErrAction
->
id
;
pTrans
->
lastErrorNo
=
pErrAction
->
errCode
;
pTrans
->
lastErrorNo
=
pErrAction
->
errCode
;
pTrans
->
lastE
rrorE
pset
=
pErrAction
->
epSet
;
pTrans
->
lastEpset
=
pErrAction
->
epSet
;
}
}
mndTransResetActions
(
pMnode
,
pTrans
,
pArray
);
mndTransResetActions
(
pMnode
,
pTrans
,
pArray
);
terrno
=
errCode
;
terrno
=
errCode
;
...
@@ -1073,15 +1103,15 @@ static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans)
...
@@ -1073,15 +1103,15 @@ static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans)
}
}
if
(
code
==
0
)
{
if
(
code
==
0
)
{
pTrans
->
last
Error
Action
=
0
;
pTrans
->
lastAction
=
0
;
pTrans
->
lastErrorNo
=
0
;
pTrans
->
lastErrorNo
=
0
;
pTrans
->
last
Error
MsgType
=
0
;
pTrans
->
lastMsgType
=
0
;
memset
(
&
pTrans
->
lastE
rrorEpset
,
0
,
sizeof
(
pTrans
->
lastError
Epset
));
memset
(
&
pTrans
->
lastE
pset
,
0
,
sizeof
(
pTrans
->
last
Epset
));
}
else
{
}
else
{
pTrans
->
last
Error
MsgType
=
pAction
->
msgType
;
pTrans
->
lastMsgType
=
pAction
->
msgType
;
pTrans
->
last
Error
Action
=
action
;
pTrans
->
lastAction
=
action
;
pTrans
->
lastErrorNo
=
pAction
->
errC
ode
;
pTrans
->
lastErrorNo
=
c
ode
;
pTrans
->
lastE
rrorE
pset
=
pAction
->
epSet
;
pTrans
->
lastEpset
=
pAction
->
epSet
;
}
}
if
(
code
==
0
)
{
if
(
code
==
0
)
{
...
@@ -1432,23 +1462,21 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
...
@@ -1432,23 +1462,21 @@ static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pTrans
->
lastExecTime
,
false
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pTrans
->
lastExecTime
,
false
);
char
lastError
[
TSDB_TRANS_ERROR_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
char
lastInfo
[
TSDB_TRANS_ERROR_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
char
detail
[
TSDB_TRANS_ERROR_LEN
]
=
{
0
};
char
detail
[
TSDB_TRANS_ERROR_LEN
]
=
{
0
};
if
(
pTrans
->
lastErrorNo
!=
0
)
{
int32_t
len
=
snprintf
(
detail
,
sizeof
(
detail
),
"action:%d code:0x%x(%s) "
,
pTrans
->
lastAction
,
int32_t
len
=
snprintf
(
detail
,
sizeof
(
detail
),
"action:%d errno:0x%x(%s) "
,
pTrans
->
lastErrorAction
,
pTrans
->
lastErrorNo
&
0xFFFF
,
tstrerror
(
pTrans
->
lastErrorNo
));
pTrans
->
lastErrorNo
&
0xFFFF
,
tstrerror
(
pTrans
->
lastErrorNo
));
SEpSet
epset
=
pTrans
->
lastEpset
;
SEpSet
epset
=
pTrans
->
lastErrorEpset
;
if
(
epset
.
numOfEps
>
0
)
{
if
(
epset
.
numOfEps
>
0
)
{
len
+=
snprintf
(
detail
+
len
,
sizeof
(
detail
)
-
len
,
"msgType:%s numOfEps:%d inUse:%d "
,
len
+=
snprintf
(
detail
+
len
,
sizeof
(
detail
)
-
len
,
"msgType:%s numOfEps:%d inUse:%d "
,
TMSG_INFO
(
pTrans
->
lastMsgType
),
epset
.
numOfEps
,
epset
.
inUse
);
TMSG_INFO
(
pTrans
->
lastErrorMsgType
),
epset
.
numOfEps
,
epset
.
inUse
);
for
(
int32_t
i
=
0
;
i
<
pTrans
->
lastEpset
.
numOfEps
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pTrans
->
lastErrorEpset
.
numOfEps
;
++
i
)
{
len
+=
snprintf
(
detail
+
len
,
sizeof
(
detail
)
-
len
,
"ep:%d-%s:%u "
,
i
,
epset
.
eps
[
i
].
fqdn
,
epset
.
eps
[
i
].
port
);
len
+=
snprintf
(
detail
+
len
,
sizeof
(
detail
)
-
len
,
"ep:%d-%s:%u "
,
i
,
epset
.
eps
[
i
].
fqdn
,
epset
.
eps
[
i
].
port
);
}
}
}
}
}
STR_WITH_MAXSIZE_TO_VARSTR
(
last
Error
,
detail
,
pShow
->
pMeta
->
pSchemas
[
cols
].
bytes
);
STR_WITH_MAXSIZE_TO_VARSTR
(
last
Info
,
detail
,
pShow
->
pMeta
->
pSchemas
[
cols
].
bytes
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
last
Error
,
false
);
colDataAppend
(
pColInfo
,
numOfRows
,
(
const
char
*
)
last
Info
,
false
);
numOfRows
++
;
numOfRows
++
;
sdbRelease
(
pSdb
,
pTrans
);
sdbRelease
(
pSdb
,
pTrans
);
...
...
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
7923d51f
...
@@ -59,6 +59,10 @@ int32_t mndInitVgroup(SMnode *pMnode) {
...
@@ -59,6 +59,10 @@ int32_t mndInitVgroup(SMnode *pMnode) {
mndSetMsgHandle
(
pMnode
,
TDMT_DND_DROP_VNODE_RSP
,
mndTransProcessRsp
);
mndSetMsgHandle
(
pMnode
,
TDMT_DND_DROP_VNODE_RSP
,
mndTransProcessRsp
);
mndSetMsgHandle
(
pMnode
,
TDMT_VND_COMPACT_RSP
,
mndTransProcessRsp
);
mndSetMsgHandle
(
pMnode
,
TDMT_VND_COMPACT_RSP
,
mndTransProcessRsp
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_REDISTRIBUTE_VGROUP
,
mndProcessRedistributeVgroupMsg
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_MERGE_VGROUP
,
mndProcessSplitVgroupMsg
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_BALANCE_VGROUP
,
mndProcessBalanceVgroupMsg
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_VGROUP
,
mndRetrieveVgroups
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_VGROUP
,
mndRetrieveVgroups
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_VGROUP
,
mndCancelGetNextVgroup
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_VGROUP
,
mndCancelGetNextVgroup
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_VNODES
,
mndRetrieveVnodes
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_VNODES
,
mndRetrieveVnodes
);
...
@@ -1009,10 +1013,10 @@ static int32_t mndAddDecVgroupReplicaFromTrans(SMnode *pMnode, STrans *pTrans, S
...
@@ -1009,10 +1013,10 @@ static int32_t mndAddDecVgroupReplicaFromTrans(SMnode *pMnode, STrans *pTrans, S
if
(
pGid
==
NULL
)
return
0
;
if
(
pGid
==
NULL
)
return
0
;
pVgroup
->
replica
--
;
memcpy
(
&
delGid
,
pGid
,
sizeof
(
SVnodeGid
));
memcpy
(
&
delGid
,
pGid
,
sizeof
(
SVnodeGid
));
memcpy
(
pGid
,
&
pVgroup
->
vnodeGid
[
pVgroup
->
replica
],
sizeof
(
SVnodeGid
));
memcpy
(
pGid
,
&
pVgroup
->
vnodeGid
[
pVgroup
->
replica
],
sizeof
(
SVnodeGid
));
memset
(
&
pVgroup
->
vnodeGid
[
pVgroup
->
replica
],
0
,
sizeof
(
SVnodeGid
));
memset
(
&
pVgroup
->
vnodeGid
[
pVgroup
->
replica
],
0
,
sizeof
(
SVnodeGid
));
pVgroup
->
replica
--
;
if
(
mndAddAlterVnodeAction
(
pMnode
,
pTrans
,
pDb
,
pVgroup
,
TDMT_VND_ALTER_REPLICA
)
!=
0
)
return
-
1
;
if
(
mndAddAlterVnodeAction
(
pMnode
,
pTrans
,
pDb
,
pVgroup
,
TDMT_VND_ALTER_REPLICA
)
!=
0
)
return
-
1
;
if
(
mndAddDropVnodeAction
(
pMnode
,
pTrans
,
pDb
,
pVgroup
,
&
delGid
,
true
)
!=
0
)
return
-
1
;
if
(
mndAddDropVnodeAction
(
pMnode
,
pTrans
,
pDb
,
pVgroup
,
&
delGid
,
true
)
!=
0
)
return
-
1
;
...
@@ -1040,11 +1044,36 @@ static int32_t mndRedistributeVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb,
...
@@ -1040,11 +1044,36 @@ static int32_t mndRedistributeVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb,
mInfo
(
"vgId:%d, vnode:%d dnode:%d"
,
newVg
.
vgId
,
i
,
newVg
.
vnodeGid
[
i
].
dnodeId
);
mInfo
(
"vgId:%d, vnode:%d dnode:%d"
,
newVg
.
vgId
,
i
,
newVg
.
vnodeGid
[
i
].
dnodeId
);
}
}
if
(
mndAddIncVgroupReplicaToTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pNew1
->
id
)
!=
0
)
goto
_OVER
;
if
(
pNew1
!=
pOld1
)
{
if
(
mndAddDecVgroupReplicaFromTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pOld1
->
id
)
!=
0
)
goto
_OVER
;
int32_t
numOfVnodes
=
mndGetVnodesNum
(
pMnode
,
pNew1
->
id
);
if
(
pNew2
!=
NULL
)
{
if
(
numOfVnodes
>=
pNew1
->
numOfSupportVnodes
)
{
mError
(
"vgId:%d, no enough vnodes in dnode:%d, numOfVnodes:%d support:%d"
,
newVg
.
vgId
,
pNew1
->
id
,
numOfVnodes
,
pNew1
->
numOfSupportVnodes
);
terrno
=
TSDB_CODE_MND_NO_ENOUGH_DNODES
;
goto
_OVER
;
}
if
(
mndAddIncVgroupReplicaToTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pNew1
->
id
)
!=
0
)
goto
_OVER
;
if
(
mndAddDecVgroupReplicaFromTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pOld1
->
id
)
!=
0
)
goto
_OVER
;
}
if
(
pNew2
!=
pOld2
)
{
int32_t
numOfVnodes
=
mndGetVnodesNum
(
pMnode
,
pNew2
->
id
);
if
(
numOfVnodes
>=
pNew2
->
numOfSupportVnodes
)
{
mError
(
"vgId:%d, no enough vnodes in dnode:%d, numOfVnodes:%d support:%d"
,
newVg
.
vgId
,
pNew2
->
id
,
numOfVnodes
,
pNew2
->
numOfSupportVnodes
);
terrno
=
TSDB_CODE_MND_NO_ENOUGH_DNODES
;
goto
_OVER
;
}
if
(
mndAddIncVgroupReplicaToTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pNew2
->
id
)
!=
0
)
goto
_OVER
;
if
(
mndAddIncVgroupReplicaToTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pNew2
->
id
)
!=
0
)
goto
_OVER
;
if
(
mndAddDecVgroupReplicaFromTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pOld2
->
id
)
!=
0
)
goto
_OVER
;
if
(
mndAddDecVgroupReplicaFromTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pOld2
->
id
)
!=
0
)
goto
_OVER
;
}
if
(
pNew3
!=
pOld3
)
{
int32_t
numOfVnodes
=
mndGetVnodesNum
(
pMnode
,
pNew3
->
id
);
if
(
numOfVnodes
>=
pNew3
->
numOfSupportVnodes
)
{
mError
(
"vgId:%d, no enough vnodes in dnode:%d, numOfVnodes:%d support:%d"
,
newVg
.
vgId
,
pNew3
->
id
,
numOfVnodes
,
pNew3
->
numOfSupportVnodes
);
terrno
=
TSDB_CODE_MND_NO_ENOUGH_DNODES
;
goto
_OVER
;
}
if
(
mndAddIncVgroupReplicaToTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pNew3
->
id
)
!=
0
)
goto
_OVER
;
if
(
mndAddIncVgroupReplicaToTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pNew3
->
id
)
!=
0
)
goto
_OVER
;
if
(
mndAddDecVgroupReplicaFromTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pOld3
->
id
)
!=
0
)
goto
_OVER
;
if
(
mndAddDecVgroupReplicaFromTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pOld3
->
id
)
!=
0
)
goto
_OVER
;
}
}
...
@@ -1070,88 +1099,105 @@ _OVER:
...
@@ -1070,88 +1099,105 @@ _OVER:
}
}
static
int32_t
mndProcessRedistributeVgroupMsg
(
SRpcMsg
*
pReq
)
{
static
int32_t
mndProcessRedistributeVgroupMsg
(
SRpcMsg
*
pReq
)
{
SMnode
*
pMnode
=
pReq
->
info
.
node
;
SMnode
*
pMnode
=
pReq
->
info
.
node
;
SUserObj
*
pUser
=
NULL
;
SUserObj
*
pUser
=
NULL
;
SDnodeObj
*
pNew1
=
NULL
;
SDnodeObj
*
pNew1
=
NULL
;
SDnodeObj
*
pNew2
=
NULL
;
SDnodeObj
*
pNew2
=
NULL
;
SDnodeObj
*
pNew3
=
NULL
;
SDnodeObj
*
pNew3
=
NULL
;
SDnodeObj
*
pOld1
=
NULL
;
SDnodeObj
*
pOld1
=
NULL
;
SDnodeObj
*
pOld2
=
NULL
;
SDnodeObj
*
pOld2
=
NULL
;
SDnodeObj
*
pOld3
=
NULL
;
SDnodeObj
*
pOld3
=
NULL
;
SVgObj
*
pVgroup
=
NULL
;
SVgObj
*
pVgroup
=
NULL
;
SDbObj
*
pDb
=
NULL
;
SDbObj
*
pDb
=
NULL
;
int32_t
code
=
-
1
;
int32_t
code
=
-
1
;
int64_t
curMs
=
taosGetTimestampMs
();
int64_t
curMs
=
taosGetTimestampMs
();
SMDropMnodeReq
redReq
=
{
0
};
SRedistributeVgroupReq
redReq
=
{
0
};
#if 0
if
(
tDeserializeSRedistributeVgroupReq
(
pReq
->
pCont
,
pReq
->
contLen
,
&
redReq
)
!=
0
)
{
if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
terrno
=
TSDB_CODE_INVALID_MSG
;
terrno
=
TSDB_CODE_INVALID_MSG
;
goto
_OVER
;
goto
_OVER
;
}
}
#endif
mDebug
(
"vgId:%d, start to redistribute"
,
2
);
mInfo
(
"vgId:%d, start to redistribute to dnode %d:%d:%d"
,
redReq
.
vgId
,
redReq
.
dnodeId1
,
redReq
.
dnodeId2
,
redReq
.
dnodeId3
);
pUser
=
mndAcquireUser
(
pMnode
,
pReq
->
conn
.
user
);
pUser
=
mndAcquireUser
(
pMnode
,
pReq
->
conn
.
user
);
if
(
pUser
==
NULL
)
{
if
(
pUser
==
NULL
)
{
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
goto
_OVER
;
goto
_OVER
;
}
}
if
(
mndCheckNodeAuth
(
pUser
)
!=
0
)
{
if
(
mndCheckNodeAuth
(
pUser
)
!=
0
)
goto
_OVER
;
goto
_OVER
;
}
pVgroup
=
mndAcquireVgroup
(
pMnode
,
2
);
pVgroup
=
mndAcquireVgroup
(
pMnode
,
redReq
.
vgId
);
if
(
pVgroup
==
NULL
)
goto
_OVER
;
if
(
pVgroup
==
NULL
)
goto
_OVER
;
pDb
=
mndAcquireDb
(
pMnode
,
pVgroup
->
dbName
);
pDb
=
mndAcquireDb
(
pMnode
,
pVgroup
->
dbName
);
if
(
pDb
==
NULL
)
goto
_OVER
;
if
(
pDb
==
NULL
)
goto
_OVER
;
if
(
pVgroup
->
replica
==
1
)
{
if
(
pVgroup
->
replica
==
1
)
{
pNew1
=
mndAcquireDnode
(
pMnode
,
1
);
if
(
redReq
.
dnodeId2
!=
-
1
||
redReq
.
dnodeId3
!=
-
1
)
{
terrno
=
TSDB_CODE_MND_INVALID_REPLICA
;
goto
_OVER
;
}
pNew1
=
mndAcquireDnode
(
pMnode
,
redReq
.
dnodeId1
);
pOld1
=
mndAcquireDnode
(
pMnode
,
pVgroup
->
vnodeGid
[
0
].
dnodeId
);
pOld1
=
mndAcquireDnode
(
pMnode
,
pVgroup
->
vnodeGid
[
0
].
dnodeId
);
if
(
pNew1
==
NULL
||
pOld1
==
NULL
)
goto
_OVER
;
if
(
pNew1
==
NULL
||
pOld1
==
NULL
)
{
if
(
!
mndIsDnodeOnline
(
pNew1
,
curMs
)
||
!
mndIsDnodeOnline
(
pOld1
,
curMs
))
{
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
terrno
=
TSDB_CODE_NODE_OFFLINE
;
goto
_OVER
;
goto
_OVER
;
}
}
if
(
pNew1
==
pOld1
)
{
if
(
pNew1
==
pOld1
)
{
terrno
=
TSDB_CODE_MND_VGROUP_UN_CHANGED
;
terrno
=
TSDB_CODE_MND_VGROUP_UN_CHANGED
;
goto
_OVER
;
goto
_OVER
;
}
}
if
(
mndRedistributeVgroup
(
pMnode
,
pReq
,
pDb
,
pVgroup
,
pNew1
,
pOld1
,
NULL
,
NULL
,
NULL
,
NULL
)
!=
0
)
goto
_OVER
;
if
(
!
mndIsDnodeOnline
(
pNew1
,
curMs
)
||
!
mndIsDnodeOnline
(
pOld1
,
curMs
))
{
}
terrno
=
TSDB_CODE_MND_HAS_OFFLINE_DNODE
;
goto
_OVER
;
if
(
pVgroup
->
replica
==
3
)
{
}
pNew1
=
mndAcquireDnode
(
pMnode
,
1
);
code
=
mndRedistributeVgroup
(
pMnode
,
pReq
,
pDb
,
pVgroup
,
pNew1
,
pOld1
,
NULL
,
NULL
,
NULL
,
NULL
);
pNew2
=
mndAcquireDnode
(
pMnode
,
2
);
}
else
if
(
pVgroup
->
replica
==
3
)
{
pNew3
=
mndAcquireDnode
(
pMnode
,
3
);
if
(
redReq
.
dnodeId2
==
-
1
||
redReq
.
dnodeId3
==
-
1
)
{
terrno
=
TSDB_CODE_MND_INVALID_REPLICA
;
goto
_OVER
;
}
pNew1
=
mndAcquireDnode
(
pMnode
,
redReq
.
dnodeId1
);
pNew2
=
mndAcquireDnode
(
pMnode
,
redReq
.
dnodeId2
);
pNew3
=
mndAcquireDnode
(
pMnode
,
redReq
.
dnodeId3
);
pOld1
=
mndAcquireDnode
(
pMnode
,
pVgroup
->
vnodeGid
[
0
].
dnodeId
);
pOld1
=
mndAcquireDnode
(
pMnode
,
pVgroup
->
vnodeGid
[
0
].
dnodeId
);
pOld2
=
mndAcquireDnode
(
pMnode
,
pVgroup
->
vnodeGid
[
1
].
dnodeId
);
pOld2
=
mndAcquireDnode
(
pMnode
,
pVgroup
->
vnodeGid
[
1
].
dnodeId
);
pOld3
=
mndAcquireDnode
(
pMnode
,
pVgroup
->
vnodeGid
[
2
].
dnodeId
);
pOld3
=
mndAcquireDnode
(
pMnode
,
pVgroup
->
vnodeGid
[
2
].
dnodeId
);
if
(
pNew1
==
NULL
||
pOld1
==
NULL
||
pNew2
==
NULL
||
pOld2
==
NULL
||
pNew3
==
NULL
||
pOld3
==
NULL
)
goto
_OVER
;
if
(
pNew1
==
NULL
||
pOld1
==
NULL
||
pNew2
==
NULL
||
pOld2
==
NULL
||
pNew3
==
NULL
||
pOld3
==
NULL
)
{
if
(
!
mndIsDnodeOnline
(
pNew1
,
curMs
)
||
!
mndIsDnodeOnline
(
pOld1
,
curMs
)
||
!
mndIsDnodeOnline
(
pNew2
,
curMs
)
||
terrno
=
TSDB_CODE_MND_DNODE_NOT_EXIST
;
!
mndIsDnodeOnline
(
pOld2
,
curMs
)
||
!
mndIsDnodeOnline
(
pNew3
,
curMs
)
||
!
mndIsDnodeOnline
(
pOld3
,
curMs
))
{
goto
_OVER
;
terrno
=
TSDB_CODE_NODE_OFFLINE
;
}
if
(
pNew1
==
pNew2
||
pNew1
==
pNew3
||
pNew2
==
pNew3
)
{
terrno
=
TSDB_CODE_MND_INVALID_REPLICA
;
goto
_OVER
;
goto
_OVER
;
}
}
bool
changed
=
tru
e
;
bool
changed
=
fals
e
;
if
(
pNew1
!=
pOld1
||
pNew1
!=
pOld2
||
pNew1
!=
pOld3
)
changed
=
true
;
if
(
pNew1
!=
pOld1
&&
pNew1
!=
pOld2
&&
pNew1
!=
pOld3
)
changed
=
true
;
if
(
pNew2
!=
pOld1
||
pNew2
!=
pOld2
||
pNew2
!=
pOld3
)
changed
=
true
;
if
(
pNew2
!=
pOld1
&&
pNew2
!=
pOld2
&&
pNew2
!=
pOld3
)
changed
=
true
;
if
(
pNew3
!=
pOld1
||
pNew3
!=
pOld2
||
pNew3
!=
pOld3
)
changed
=
true
;
if
(
pNew3
!=
pOld1
&&
pNew3
!=
pOld2
&&
pNew3
!=
pOld3
)
changed
=
true
;
if
(
!
changed
)
{
if
(
!
changed
)
{
terrno
=
TSDB_CODE_MND_VGROUP_UN_CHANGED
;
terrno
=
TSDB_CODE_MND_VGROUP_UN_CHANGED
;
goto
_OVER
;
goto
_OVER
;
}
}
if
(
mndRedistributeVgroup
(
pMnode
,
pReq
,
pDb
,
pVgroup
,
pNew1
,
pOld1
,
pNew2
,
pOld2
,
pNew3
,
pOld3
)
!=
0
)
goto
_OVER
;
if
(
!
mndIsDnodeOnline
(
pNew1
,
curMs
)
||
!
mndIsDnodeOnline
(
pOld1
,
curMs
)
||
!
mndIsDnodeOnline
(
pNew2
,
curMs
)
||
!
mndIsDnodeOnline
(
pOld2
,
curMs
)
||
!
mndIsDnodeOnline
(
pNew3
,
curMs
)
||
!
mndIsDnodeOnline
(
pOld3
,
curMs
))
{
terrno
=
TSDB_CODE_MND_HAS_OFFLINE_DNODE
;
goto
_OVER
;
}
code
=
mndRedistributeVgroup
(
pMnode
,
pReq
,
pDb
,
pVgroup
,
pNew1
,
pOld1
,
pNew2
,
pOld2
,
pNew3
,
pOld3
);
}
else
{
terrno
=
TSDB_CODE_MND_INVALID_REPLICA
;
goto
_OVER
;
}
}
if
(
code
==
0
)
code
=
TSDB_CODE_ACTION_IN_PROGRESS
;
if
(
code
==
0
)
code
=
TSDB_CODE_ACTION_IN_PROGRESS
;
_OVER:
_OVER:
if
(
code
!=
0
&&
code
!=
TSDB_CODE_ACTION_IN_PROGRESS
)
{
if
(
code
!=
0
&&
code
!=
TSDB_CODE_ACTION_IN_PROGRESS
)
{
mDebug
(
"vgId:%d, failed to redistribute since %s"
,
1
,
terrstr
());
mError
(
"vgId:%d, failed to redistribute to dnode %d %d %d since %s"
,
redReq
.
vgId
,
redReq
.
dnodeId1
,
redReq
.
dnodeId2
,
redReq
.
dnodeId3
,
terrstr
());
}
}
mndReleaseDnode
(
pMnode
,
pNew1
);
mndReleaseDnode
(
pMnode
,
pNew1
);
...
@@ -1303,9 +1349,7 @@ static int32_t mndProcessSplitVgroupMsg(SRpcMsg *pReq) {
...
@@ -1303,9 +1349,7 @@ static int32_t mndProcessSplitVgroupMsg(SRpcMsg *pReq) {
goto
_OVER
;
goto
_OVER
;
}
}
if
(
mndCheckNodeAuth
(
pUser
)
!=
0
)
{
if
(
mndCheckNodeAuth
(
pUser
)
!=
0
)
goto
_OVER
;
goto
_OVER
;
}
code
=
mndSplitVgroup
(
pMnode
,
pReq
,
pDb
,
pVgroup
);
code
=
mndSplitVgroup
(
pMnode
,
pReq
,
pDb
,
pVgroup
);
if
(
code
==
0
)
code
=
TSDB_CODE_ACTION_IN_PROGRESS
;
if
(
code
==
0
)
code
=
TSDB_CODE_ACTION_IN_PROGRESS
;
...
...
source/dnode/mnode/sdb/src/sdbFile.c
浏览文件 @
7923d51f
...
@@ -357,7 +357,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
...
@@ -357,7 +357,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
SdbEncodeFp
encodeFp
=
pSdb
->
encodeFps
[
i
];
SdbEncodeFp
encodeFp
=
pSdb
->
encodeFps
[
i
];
if
(
encodeFp
==
NULL
)
continue
;
if
(
encodeFp
==
NULL
)
continue
;
m
Trace
(
"write %s to sdb file, total %d rows"
,
sdbTableName
(
i
),
sdbGetSize
(
pSdb
,
i
));
m
Debug
(
"write %s to sdb file, total %d rows"
,
sdbTableName
(
i
),
sdbGetSize
(
pSdb
,
i
));
SHashObj
*
hash
=
pSdb
->
hashObjs
[
i
];
SHashObj
*
hash
=
pSdb
->
hashObjs
[
i
];
TdThreadRwlock
*
pLock
=
&
pSdb
->
locks
[
i
];
TdThreadRwlock
*
pLock
=
&
pSdb
->
locks
[
i
];
...
...
source/dnode/mnode/sdb/src/sdbHash.c
浏览文件 @
7923d51f
...
@@ -83,6 +83,7 @@ const char *sdbStatusName(ESdbStatus status) {
...
@@ -83,6 +83,7 @@ const char *sdbStatusName(ESdbStatus status) {
}
}
void
sdbPrintOper
(
SSdb
*
pSdb
,
SSdbRow
*
pRow
,
const
char
*
oper
)
{
void
sdbPrintOper
(
SSdb
*
pSdb
,
SSdbRow
*
pRow
,
const
char
*
oper
)
{
#if 0
EKeyType keyType = pSdb->keyTypes[pRow->type];
EKeyType keyType = pSdb->keyTypes[pRow->type];
if (keyType == SDB_KEY_BINARY) {
if (keyType == SDB_KEY_BINARY) {
...
@@ -96,6 +97,7 @@ void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) {
...
@@ -96,6 +97,7 @@ void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) {
pRow->refCount, oper, pRow->pObj, sdbStatusName(pRow->status));
pRow->refCount, oper, pRow->pObj, sdbStatusName(pRow->status));
} else {
} else {
}
}
#endif
}
}
static
SHashObj
*
sdbGetHash
(
SSdb
*
pSdb
,
int32_t
type
)
{
static
SHashObj
*
sdbGetHash
(
SSdb
*
pSdb
,
int32_t
type
)
{
...
...
source/dnode/mnode/sdb/src/sdbRaw.c
浏览文件 @
7923d51f
...
@@ -37,13 +37,17 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
...
@@ -37,13 +37,17 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
pRaw
->
sver
=
sver
;
pRaw
->
sver
=
sver
;
pRaw
->
dataLen
=
dataLen
;
pRaw
->
dataLen
=
dataLen
;
#if 0
mTrace("raw:%p, is created, len:%d table:%s", pRaw, dataLen, sdbTableName(type));
mTrace("raw:%p, is created, len:%d table:%s", pRaw, dataLen, sdbTableName(type));
#endif
return
pRaw
;
return
pRaw
;
}
}
void
sdbFreeRaw
(
SSdbRaw
*
pRaw
)
{
void
sdbFreeRaw
(
SSdbRaw
*
pRaw
)
{
if
(
pRaw
!=
NULL
)
{
if
(
pRaw
!=
NULL
)
{
#if 0
mTrace("raw:%p, is freed", pRaw);
mTrace("raw:%p, is freed", pRaw);
#endif
taosMemoryFree
(
pRaw
);
taosMemoryFree
(
pRaw
);
}
}
}
}
...
...
source/dnode/mnode/sdb/src/sdbRow.c
浏览文件 @
7923d51f
...
@@ -23,7 +23,9 @@ SSdbRow *sdbAllocRow(int32_t objSize) {
...
@@ -23,7 +23,9 @@ SSdbRow *sdbAllocRow(int32_t objSize) {
return
NULL
;
return
NULL
;
}
}
#if 0
mTrace("row:%p, is created, len:%d", pRow->pObj, objSize);
mTrace("row:%p, is created, len:%d", pRow->pObj, objSize);
#endif
return
pRow
;
return
pRow
;
}
}
...
@@ -45,6 +47,8 @@ void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow, bool callFunc) {
...
@@ -45,6 +47,8 @@ void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow, bool callFunc) {
sdbPrintOper
(
pSdb
,
pRow
,
"free"
);
sdbPrintOper
(
pSdb
,
pRow
,
"free"
);
#if 0
mTrace("row:%p, is freed", pRow->pObj);
mTrace("row:%p, is freed", pRow->pObj);
#endif
taosMemoryFreeClear
(
pRow
);
taosMemoryFreeClear
(
pRow
);
}
}
source/dnode/vnode/src/inc/tq.h
浏览文件 @
7923d51f
...
@@ -58,7 +58,7 @@ struct STqReadHandle {
...
@@ -58,7 +58,7 @@ struct STqReadHandle {
SArray
*
pColIdList
;
// SArray<int16_t>
SArray
*
pColIdList
;
// SArray<int16_t>
int32_t
cachedSchemaVer
;
int32_t
cachedSchemaVer
;
int64_t
cachedSchema
U
id
;
int64_t
cachedSchema
Su
id
;
SSchemaWrapper
*
pSchemaWrapper
;
SSchemaWrapper
*
pSchemaWrapper
;
STSchema
*
pSchema
;
STSchema
*
pSchema
;
};
};
...
...
source/dnode/vnode/src/tq/tqRead.c
浏览文件 @
7923d51f
...
@@ -67,7 +67,7 @@ STqReadHandle* tqInitSubmitMsgScanner(SMeta* pMeta) {
...
@@ -67,7 +67,7 @@ STqReadHandle* tqInitSubmitMsgScanner(SMeta* pMeta) {
pReadHandle
->
ver
=
-
1
;
pReadHandle
->
ver
=
-
1
;
pReadHandle
->
pColIdList
=
NULL
;
pReadHandle
->
pColIdList
=
NULL
;
pReadHandle
->
cachedSchemaVer
=
-
1
;
pReadHandle
->
cachedSchemaVer
=
-
1
;
pReadHandle
->
cachedSchema
U
id
=
-
1
;
pReadHandle
->
cachedSchema
Su
id
=
-
1
;
pReadHandle
->
pSchema
=
NULL
;
pReadHandle
->
pSchema
=
NULL
;
pReadHandle
->
pSchemaWrapper
=
NULL
;
pReadHandle
->
pSchemaWrapper
=
NULL
;
pReadHandle
->
tbIdHash
=
NULL
;
pReadHandle
->
tbIdHash
=
NULL
;
...
@@ -130,7 +130,8 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
...
@@ -130,7 +130,8 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
// TODO set to real sversion
// TODO set to real sversion
/*int32_t sversion = 1;*/
/*int32_t sversion = 1;*/
int32_t
sversion
=
htonl
(
pHandle
->
pBlock
->
sversion
);
int32_t
sversion
=
htonl
(
pHandle
->
pBlock
->
sversion
);
if
(
pHandle
->
cachedSchemaVer
!=
sversion
||
pHandle
->
cachedSchemaUid
!=
pHandle
->
msgIter
.
suid
)
{
if
(
pHandle
->
cachedSchemaSuid
==
0
||
pHandle
->
cachedSchemaVer
!=
sversion
||
pHandle
->
cachedSchemaSuid
!=
pHandle
->
msgIter
.
suid
)
{
pHandle
->
pSchema
=
metaGetTbTSchema
(
pHandle
->
pVnodeMeta
,
pHandle
->
msgIter
.
uid
,
sversion
);
pHandle
->
pSchema
=
metaGetTbTSchema
(
pHandle
->
pVnodeMeta
,
pHandle
->
msgIter
.
uid
,
sversion
);
if
(
pHandle
->
pSchema
==
NULL
)
{
if
(
pHandle
->
pSchema
==
NULL
)
{
tqWarn
(
"cannot found tsschema for table: uid: %ld (suid: %ld), version %d, possibly dropped table"
,
tqWarn
(
"cannot found tsschema for table: uid: %ld (suid: %ld), version %d, possibly dropped table"
,
...
@@ -150,7 +151,7 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
...
@@ -150,7 +151,7 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
return
-
1
;
return
-
1
;
}
}
pHandle
->
cachedSchemaVer
=
sversion
;
pHandle
->
cachedSchemaVer
=
sversion
;
pHandle
->
cachedSchema
U
id
=
pHandle
->
msgIter
.
suid
;
pHandle
->
cachedSchema
Su
id
=
pHandle
->
msgIter
.
suid
;
}
}
STSchema
*
pTschema
=
pHandle
->
pSchema
;
STSchema
*
pTschema
=
pHandle
->
pSchema
;
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
7923d51f
...
@@ -180,13 +180,22 @@ static int32_t vnodeSyncGetSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) {
...
@@ -180,13 +180,22 @@ static int32_t vnodeSyncGetSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) {
return
0
;
return
0
;
}
}
static
void
vnodeSyncReconfig
(
struct
SSyncFSM
*
pFsm
,
SSyncCfg
newCf
g
,
SReConfigCbMeta
cbMeta
)
{
static
void
vnodeSyncReconfig
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMs
g
,
SReConfigCbMeta
cbMeta
)
{
SVnode
*
pVnode
=
pFsm
->
data
;
SVnode
*
pVnode
=
pFsm
->
data
;
vInfo
(
"vgId:%d, sync reconfig is confirmed"
,
TD_VID
(
pVnode
));
vInfo
(
"vgId:%d, sync reconfig is confirmed"
,
TD_VID
(
pVnode
));
#if 0
// send response
SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen, .conn.applyIndex = cbMeta.index};
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen);
syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &rpcMsg.info);
#endif
// todo rpc response here
// todo rpc response here
// build rpc msg
// build rpc msg
// put into apply queue
// put into apply queue
vnodePostBlockMsg
(
pVnode
,
TDMT_VND_ALTER_REPLICA
);
}
}
static
void
vnodeSyncCommitMsg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
static
void
vnodeSyncCommitMsg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
...
@@ -212,6 +221,7 @@ static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta c
...
@@ -212,6 +221,7 @@ static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta c
memcpy
(
rpcMsg
.
pCont
,
pMsg
->
pCont
,
pMsg
->
contLen
);
memcpy
(
rpcMsg
.
pCont
,
pMsg
->
pCont
,
pMsg
->
contLen
);
syncGetAndDelRespRpc
(
pVnode
->
sync
,
cbMeta
.
seqNum
,
&
rpcMsg
.
info
);
syncGetAndDelRespRpc
(
pVnode
->
sync
,
cbMeta
.
seqNum
,
&
rpcMsg
.
info
);
tmsgPutToQueue
(
&
pVnode
->
msgCb
,
APPLY_QUEUE
,
&
rpcMsg
);
tmsgPutToQueue
(
&
pVnode
->
msgCb
,
APPLY_QUEUE
,
&
rpcMsg
);
}
else
{
}
else
{
char
logBuf
[
256
]
=
{
0
};
char
logBuf
[
256
]
=
{
0
};
snprintf
(
logBuf
,
sizeof
(
logBuf
),
snprintf
(
logBuf
,
sizeof
(
logBuf
),
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
7923d51f
...
@@ -809,6 +809,11 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t
...
@@ -809,6 +809,11 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t
SOperatorInfo
*
createIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SOperatorInfo
*
createIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SSDataBlock
*
pResBlock
,
SInterval
*
pInterval
,
int32_t
primaryTsSlotId
,
SSDataBlock
*
pResBlock
,
SInterval
*
pInterval
,
int32_t
primaryTsSlotId
,
STimeWindowAggSupp
*
pTwAggSupp
,
SExecTaskInfo
*
pTaskInfo
,
bool
isStream
);
STimeWindowAggSupp
*
pTwAggSupp
,
SExecTaskInfo
*
pTaskInfo
,
bool
isStream
);
SOperatorInfo
*
createMergeIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SSDataBlock
*
pResBlock
,
SInterval
*
pInterval
,
int32_t
primaryTsSlotId
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createStreamFinalIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SOperatorInfo
*
createStreamFinalIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SPhysiNode
*
pPhyNode
,
SExecTaskInfo
*
pTaskInfo
,
int32_t
numOfChild
);
SPhysiNode
*
pPhyNode
,
SExecTaskInfo
*
pTaskInfo
,
int32_t
numOfChild
);
SOperatorInfo
*
createStreamIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SOperatorInfo
*
createStreamIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
...
@@ -907,6 +912,9 @@ int64_t getSmaWaterMark(int64_t interval, double filesFactor);
...
@@ -907,6 +912,9 @@ int64_t getSmaWaterMark(int64_t interval, double filesFactor);
bool
isSmaStream
(
int8_t
triggerType
);
bool
isSmaStream
(
int8_t
triggerType
);
int32_t
compareTimeWindow
(
const
void
*
p1
,
const
void
*
p2
,
const
void
*
param
);
int32_t
compareTimeWindow
(
const
void
*
p1
,
const
void
*
p2
,
const
void
*
param
);
int32_t
finalizeResultRowIntoResultDataBlock
(
SDiskbasedBuf
*
pBuf
,
SResultRowPosition
*
resultRowPosition
,
SqlFunctionCtx
*
pCtx
,
SExprInfo
*
pExprInfo
,
int32_t
numOfExprs
,
const
int32_t
*
rowCellOffset
,
SSDataBlock
*
pBlock
,
SExecTaskInfo
*
pTaskInfo
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
7923d51f
...
@@ -1956,6 +1956,57 @@ static void doUpdateNumOfRows(SResultRow* pRow, int32_t numOfExprs, const int32_
...
@@ -1956,6 +1956,57 @@ static void doUpdateNumOfRows(SResultRow* pRow, int32_t numOfExprs, const int32_
}
}
}
}
int32_t
finalizeResultRowIntoResultDataBlock
(
SDiskbasedBuf
*
pBuf
,
SResultRowPosition
*
resultRowPosition
,
SqlFunctionCtx
*
pCtx
,
SExprInfo
*
pExprInfo
,
int32_t
numOfExprs
,
const
int32_t
*
rowCellOffset
,
SSDataBlock
*
pBlock
,
SExecTaskInfo
*
pTaskInfo
)
{
SFilePage
*
page
=
getBufPage
(
pBuf
,
resultRowPosition
->
pageId
);
SResultRow
*
pRow
=
(
SResultRow
*
)((
char
*
)
page
+
resultRowPosition
->
offset
);
doUpdateNumOfRows
(
pRow
,
numOfExprs
,
rowCellOffset
);
if
(
pRow
->
numOfRows
==
0
)
{
releaseBufPage
(
pBuf
,
page
);
return
0
;
}
while
(
pBlock
->
info
.
rows
+
pRow
->
numOfRows
>
pBlock
->
info
.
capacity
)
{
int32_t
code
=
blockDataEnsureCapacity
(
pBlock
,
pBlock
->
info
.
capacity
*
1
.
25
);
if
(
TAOS_FAILED
(
code
))
{
releaseBufPage
(
pBuf
,
page
);
qError
(
"%s ensure result data capacity failed, code %s"
,
GET_TASKID
(
pTaskInfo
),
tstrerror
(
code
));
longjmp
(
pTaskInfo
->
env
,
code
);
}
}
for
(
int32_t
j
=
0
;
j
<
numOfExprs
;
++
j
)
{
int32_t
slotId
=
pExprInfo
[
j
].
base
.
resSchema
.
slotId
;
pCtx
[
j
].
resultInfo
=
getResultCell
(
pRow
,
j
,
rowCellOffset
);
if
(
pCtx
[
j
].
fpSet
.
finalize
)
{
int32_t
code
=
pCtx
[
j
].
fpSet
.
finalize
(
&
pCtx
[
j
],
pBlock
);
if
(
TAOS_FAILED
(
code
))
{
qError
(
"%s build result data block error, code %s"
,
GET_TASKID
(
pTaskInfo
),
tstrerror
(
code
));
longjmp
(
pTaskInfo
->
env
,
code
);
}
}
else
if
(
strcmp
(
pCtx
[
j
].
pExpr
->
pExpr
->
_function
.
functionName
,
"_select_value"
)
==
0
)
{
// do nothing, todo refactor
}
else
{
// expand the result into multiple rows. E.g., _wstartts, top(k, 20)
// the _wstartts needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
char
*
in
=
GET_ROWCELL_INTERBUF
(
pCtx
[
j
].
resultInfo
);
for
(
int32_t
k
=
0
;
k
<
pRow
->
numOfRows
;
++
k
)
{
colDataAppend
(
pColInfoData
,
pBlock
->
info
.
rows
+
k
,
in
,
pCtx
[
j
].
resultInfo
->
isNullRes
);
}
}
}
releaseBufPage
(
pBuf
,
page
);
pBlock
->
info
.
rows
+=
pRow
->
numOfRows
;
return
0
;
}
int32_t
doCopyToSDataBlock
(
SExecTaskInfo
*
pTaskInfo
,
SSDataBlock
*
pBlock
,
SExprInfo
*
pExprInfo
,
SDiskbasedBuf
*
pBuf
,
int32_t
doCopyToSDataBlock
(
SExecTaskInfo
*
pTaskInfo
,
SSDataBlock
*
pBlock
,
SExprInfo
*
pExprInfo
,
SDiskbasedBuf
*
pBuf
,
SGroupResInfo
*
pGroupResInfo
,
const
int32_t
*
rowCellOffset
,
SqlFunctionCtx
*
pCtx
,
SGroupResInfo
*
pGroupResInfo
,
const
int32_t
*
rowCellOffset
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfExprs
)
{
int32_t
numOfExprs
)
{
...
@@ -4700,6 +4751,21 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
...
@@ -4700,6 +4751,21 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
pOptr
=
pOptr
=
createIntervalOperatorInfo
(
ops
[
0
],
pExprInfo
,
num
,
pResBlock
,
&
interval
,
tsSlotId
,
&
as
,
pTaskInfo
,
isStream
);
createIntervalOperatorInfo
(
ops
[
0
],
pExprInfo
,
num
,
pResBlock
,
&
interval
,
tsSlotId
,
&
as
,
pTaskInfo
,
isStream
);
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL
==
type
)
{
SMergeIntervalPhysiNode
*
pIntervalPhyNode
=
(
SMergeIntervalPhysiNode
*
)
pPhyNode
;
SExprInfo
*
pExprInfo
=
createExprInfo
(
pIntervalPhyNode
->
window
.
pFuncs
,
NULL
,
&
num
);
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pPhyNode
->
pOutputDataBlockDesc
);
SInterval
interval
=
{.
interval
=
pIntervalPhyNode
->
interval
,
.
sliding
=
pIntervalPhyNode
->
sliding
,
.
intervalUnit
=
pIntervalPhyNode
->
intervalUnit
,
.
slidingUnit
=
pIntervalPhyNode
->
slidingUnit
,
.
offset
=
pIntervalPhyNode
->
offset
,
.
precision
=
((
SColumnNode
*
)
pIntervalPhyNode
->
window
.
pTspk
)
->
node
.
resType
.
precision
};
int32_t
tsSlotId
=
((
SColumnNode
*
)
pIntervalPhyNode
->
window
.
pTspk
)
->
slotId
;
pOptr
=
createMergeIntervalOperatorInfo
(
ops
[
0
],
pExprInfo
,
num
,
pResBlock
,
&
interval
,
tsSlotId
,
pTaskInfo
);
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL
==
type
)
{
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL
==
type
)
{
qDebug
(
"[******]create Semi"
);
qDebug
(
"[******]create Semi"
);
int32_t
children
=
0
;
int32_t
children
=
0
;
...
...
source/libs/executor/src/timewindowoperator.c
浏览文件 @
7923d51f
...
@@ -1881,8 +1881,8 @@ _error:
...
@@ -1881,8 +1881,8 @@ _error:
return
NULL
;
return
NULL
;
}
}
static
void
doHashInterval
(
SOperatorInfo
*
pOperatorInfo
,
SSDataBlock
*
pSDataBlock
,
static
void
doHashInterval
(
SOperatorInfo
*
pOperatorInfo
,
SSDataBlock
*
pSDataBlock
,
int32_t
tableGroupId
,
int32_t
tableGroupId
,
SArray
*
pUpdated
)
{
SArray
*
pUpdated
)
{
SStreamFinalIntervalOperatorInfo
*
pInfo
=
(
SStreamFinalIntervalOperatorInfo
*
)
pOperatorInfo
->
info
;
SStreamFinalIntervalOperatorInfo
*
pInfo
=
(
SStreamFinalIntervalOperatorInfo
*
)
pOperatorInfo
->
info
;
SResultRowInfo
*
pResultRowInfo
=
&
(
pInfo
->
binfo
.
resultRowInfo
);
SResultRowInfo
*
pResultRowInfo
=
&
(
pInfo
->
binfo
.
resultRowInfo
);
SExecTaskInfo
*
pTaskInfo
=
pOperatorInfo
->
pTaskInfo
;
SExecTaskInfo
*
pTaskInfo
=
pOperatorInfo
->
pTaskInfo
;
...
@@ -1897,7 +1897,7 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc
...
@@ -1897,7 +1897,7 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc
SColumnInfoData
*
pColDataInfo
=
taosArrayGet
(
pSDataBlock
->
pDataBlock
,
pInfo
->
primaryTsIndex
);
SColumnInfoData
*
pColDataInfo
=
taosArrayGet
(
pSDataBlock
->
pDataBlock
,
pInfo
->
primaryTsIndex
);
tsCols
=
(
int64_t
*
)
pColDataInfo
->
pData
;
tsCols
=
(
int64_t
*
)
pColDataInfo
->
pData
;
}
else
{
}
else
{
return
;
return
;
}
}
int32_t
startPos
=
ascScan
?
0
:
(
pSDataBlock
->
info
.
rows
-
1
);
int32_t
startPos
=
ascScan
?
0
:
(
pSDataBlock
->
info
.
rows
-
1
);
...
@@ -1914,13 +1914,14 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc
...
@@ -1914,13 +1914,14 @@ static void doHashInterval(SOperatorInfo* pOperatorInfo, SSDataBlock* pSDataBloc
pos
->
groupId
=
tableGroupId
;
pos
->
groupId
=
tableGroupId
;
pos
->
pos
=
(
SResultRowPosition
){.
pageId
=
pResult
->
pageId
,
.
offset
=
pResult
->
offset
};
pos
->
pos
=
(
SResultRowPosition
){.
pageId
=
pResult
->
pageId
,
.
offset
=
pResult
->
offset
};
*
(
int64_t
*
)
pos
->
key
=
pResult
->
win
.
skey
;
*
(
int64_t
*
)
pos
->
key
=
pResult
->
win
.
skey
;
forwardRows
=
getNumOfRowsInTimeWindow
(
&
pSDataBlock
->
info
,
tsCols
,
startPos
,
forwardRows
=
getNumOfRowsInTimeWindow
(
&
pSDataBlock
->
info
,
tsCols
,
startPos
,
nextWin
.
ekey
,
binarySearchForKey
,
NULL
,
nextWin
.
ekey
,
binarySearchForKey
,
NULL
,
TSDB_ORDER_ASC
);
TSDB_ORDER_ASC
);
if
(
pInfo
->
twAggSup
.
calTrigger
==
STREAM_TRIGGER_AT_ONCE
&&
pUpdated
)
{
if
(
pInfo
->
twAggSup
.
calTrigger
==
STREAM_TRIGGER_AT_ONCE
&&
pUpdated
)
{
saveResult
(
pResult
,
tableGroupId
,
pUpdated
);
saveResult
(
pResult
,
tableGroupId
,
pUpdated
);
}
}
// window start(end) key interpolation
// window start(end) key interpolation
// doWindowBorderInterpolation(pInfo, pSDataBlock, numOfOutput, pInfo->binfo.pCtx, pResult, &nextWin, startPos, forwardRows);
// doWindowBorderInterpolation(pInfo, pSDataBlock, numOfOutput, pInfo->binfo.pCtx, pResult, &nextWin, startPos,
// forwardRows);
updateTimeWindowInfo
(
&
pInfo
->
twAggSup
.
timeWindowData
,
&
nextWin
,
true
);
updateTimeWindowInfo
(
&
pInfo
->
twAggSup
.
timeWindowData
,
&
nextWin
,
true
);
doApplyFunctions
(
pTaskInfo
,
pInfo
->
binfo
.
pCtx
,
&
nextWin
,
&
pInfo
->
twAggSup
.
timeWindowData
,
startPos
,
forwardRows
,
doApplyFunctions
(
pTaskInfo
,
pInfo
->
binfo
.
pCtx
,
&
nextWin
,
&
pInfo
->
twAggSup
.
timeWindowData
,
startPos
,
forwardRows
,
tsCols
,
pSDataBlock
->
info
.
rows
,
numOfOutput
,
TSDB_ORDER_ASC
);
tsCols
,
pSDataBlock
->
info
.
rows
,
numOfOutput
,
TSDB_ORDER_ASC
);
...
@@ -2049,10 +2050,10 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
...
@@ -2049,10 +2050,10 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
int32_t
childIndex
=
getChildIndex
(
pBlock
);
int32_t
childIndex
=
getChildIndex
(
pBlock
);
SOperatorInfo
*
pChildOp
=
taosArrayGetP
(
pInfo
->
pChildren
,
childIndex
);
SOperatorInfo
*
pChildOp
=
taosArrayGetP
(
pInfo
->
pChildren
,
childIndex
);
SIntervalAggOperatorInfo
*
pChildInfo
=
pChildOp
->
info
;
SIntervalAggOperatorInfo
*
pChildInfo
=
pChildOp
->
info
;
doClearWindows
(
&
pChildInfo
->
aggSup
,
&
pChildInfo
->
binfo
,
&
pChildInfo
->
interval
,
doClearWindows
(
&
pChildInfo
->
aggSup
,
&
pChildInfo
->
binfo
,
&
pChildInfo
->
interval
,
pChildInfo
->
primaryTsIndex
,
pChildInfo
->
primaryTsIndex
,
pChildOp
->
numOfExprs
,
pBlock
,
NULL
);
pChildOp
->
numOfExprs
,
pBlock
,
NULL
);
rebuildIntervalWindow
(
pInfo
,
pUpWins
,
pInfo
->
binfo
.
pRes
->
info
.
groupId
,
rebuildIntervalWindow
(
pInfo
,
pUpWins
,
pInfo
->
binfo
.
pRes
->
info
.
groupId
,
pOperator
->
numOfExprs
,
pOperator
->
numOfExprs
,
pOperator
->
pTaskInfo
);
pOperator
->
pTaskInfo
);
taosArrayDestroy
(
pUpWins
);
taosArrayDestroy
(
pUpWins
);
continue
;
continue
;
}
}
...
@@ -2062,7 +2063,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
...
@@ -2062,7 +2063,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
break
;
break
;
}
}
if
(
isFinalInterval
(
pInfo
))
{
if
(
isFinalInterval
(
pInfo
))
{
int32_t
chIndex
=
getChildIndex
(
pBlock
);
int32_t
chIndex
=
getChildIndex
(
pBlock
);
int32_t
size
=
taosArrayGetSize
(
pInfo
->
pChildren
);
int32_t
size
=
taosArrayGetSize
(
pInfo
->
pChildren
);
// if chIndex + 1 - size > 0, add new child
// if chIndex + 1 - size > 0, add new child
for
(
int32_t
i
=
0
;
i
<
chIndex
+
1
-
size
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
chIndex
+
1
-
size
;
i
++
)
{
...
@@ -2072,7 +2073,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
...
@@ -2072,7 +2073,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
}
}
taosArrayPush
(
pInfo
->
pChildren
,
&
pChildOp
);
taosArrayPush
(
pInfo
->
pChildren
,
&
pChildOp
);
}
}
SOperatorInfo
*
pChildOp
=
taosArrayGetP
(
pInfo
->
pChildren
,
chIndex
);
SOperatorInfo
*
pChildOp
=
taosArrayGetP
(
pInfo
->
pChildren
,
chIndex
);
SStreamFinalIntervalOperatorInfo
*
pChInfo
=
pChildOp
->
info
;
SStreamFinalIntervalOperatorInfo
*
pChInfo
=
pChildOp
->
info
;
setInputDataBlock
(
pChildOp
,
pChInfo
->
binfo
.
pCtx
,
pBlock
,
pChInfo
->
order
,
MAIN_SCAN
,
true
);
setInputDataBlock
(
pChildOp
,
pChInfo
->
binfo
.
pCtx
,
pBlock
,
pChInfo
->
order
,
MAIN_SCAN
,
true
);
doHashInterval
(
pChildOp
,
pBlock
,
pBlock
->
info
.
groupId
,
NULL
);
doHashInterval
(
pChildOp
,
pBlock
,
pBlock
->
info
.
groupId
,
NULL
);
...
@@ -2080,12 +2081,10 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
...
@@ -2080,12 +2081,10 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
doHashInterval
(
pOperator
,
pBlock
,
pBlock
->
info
.
groupId
,
pUpdated
);
doHashInterval
(
pOperator
,
pBlock
,
pBlock
->
info
.
groupId
,
pUpdated
);
pInfo
->
twAggSup
.
maxTs
=
TMAX
(
pInfo
->
twAggSup
.
maxTs
,
pBlock
->
info
.
window
.
ekey
);
pInfo
->
twAggSup
.
maxTs
=
TMAX
(
pInfo
->
twAggSup
.
maxTs
,
pBlock
->
info
.
window
.
ekey
);
}
}
if
(
isFinalInterval
(
pInfo
))
{
if
(
isFinalInterval
(
pInfo
))
{
closeIntervalWindow
(
pInfo
->
aggSup
.
pResultRowHashTable
,
&
pInfo
->
twAggSup
,
closeIntervalWindow
(
pInfo
->
aggSup
.
pResultRowHashTable
,
&
pInfo
->
twAggSup
,
&
pInfo
->
interval
,
pClosed
);
&
pInfo
->
interval
,
pClosed
);
finalizeUpdatedResult
(
pOperator
->
numOfExprs
,
pInfo
->
aggSup
.
pResultBuf
,
pClosed
,
pInfo
->
binfo
.
rowCellInfoOffset
);
finalizeUpdatedResult
(
pOperator
->
numOfExprs
,
pInfo
->
aggSup
.
pResultBuf
,
pClosed
,
pInfo
->
binfo
.
rowCellInfoOffset
);
if
(
pInfo
->
twAggSup
.
calTrigger
==
STREAM_TRIGGER_WINDOW_CLOSE
)
{
if
(
pInfo
->
twAggSup
.
calTrigger
==
STREAM_TRIGGER_WINDOW_CLOSE
)
{
taosArrayAddAll
(
pUpdated
,
pClosed
);
taosArrayAddAll
(
pUpdated
,
pClosed
);
}
}
...
@@ -2109,31 +2108,32 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
...
@@ -2109,31 +2108,32 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
return
pInfo
->
binfo
.
pRes
;
return
pInfo
->
binfo
.
pRes
;
}
}
SOperatorInfo
*
createStreamFinalIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SOperatorInfo
*
createStreamFinalIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SPhysiNode
*
pPhyNode
,
SPhysiNode
*
pPhyNode
,
SExecTaskInfo
*
pTaskInfo
,
int32_t
numOfChild
)
{
SExecTaskInfo
*
pTaskInfo
,
int32_t
numOfChild
)
{
SIntervalPhysiNode
*
pIntervalPhyNode
=
(
SIntervalPhysiNode
*
)
pPhyNode
;
SIntervalPhysiNode
*
pIntervalPhyNode
=
(
SIntervalPhysiNode
*
)
pPhyNode
;
SStreamFinalIntervalOperatorInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamFinalIntervalOperatorInfo
));
SStreamFinalIntervalOperatorInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamFinalIntervalOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
goto
_error
;
goto
_error
;
}
}
pInfo
->
order
=
TSDB_ORDER_ASC
;
pInfo
->
order
=
TSDB_ORDER_ASC
;
pInfo
->
interval
=
(
SInterval
)
{.
interval
=
pIntervalPhyNode
->
interval
,
pInfo
->
interval
=
(
SInterval
){.
interval
=
pIntervalPhyNode
->
interval
,
.
sliding
=
pIntervalPhyNode
->
sliding
,
.
sliding
=
pIntervalPhyNode
->
sliding
,
.
intervalUnit
=
pIntervalPhyNode
->
intervalUnit
,
.
intervalUnit
=
pIntervalPhyNode
->
intervalUnit
,
.
slidingUnit
=
pIntervalPhyNode
->
slidingUnit
,
.
slidingUnit
=
pIntervalPhyNode
->
slidingUnit
,
.
offset
=
pIntervalPhyNode
->
offset
,
.
offset
=
pIntervalPhyNode
->
offset
,
.
precision
=
.
precision
=
((
SColumnNode
*
)
pIntervalPhyNode
->
window
.
pTspk
)
->
node
.
resType
.
precision
};
((
SColumnNode
*
)
pIntervalPhyNode
->
window
.
pTspk
)
->
node
.
resType
.
precision
};
pInfo
->
twAggSup
=
(
STimeWindowAggSupp
){
pInfo
->
twAggSup
=
(
STimeWindowAggSupp
){
.
waterMark
=
pIntervalPhyNode
->
window
.
watermark
,
.
waterMark
=
pIntervalPhyNode
->
window
.
watermark
,
.
calTrigger
=
pIntervalPhyNode
->
window
.
triggerType
,
.
calTrigger
=
pIntervalPhyNode
->
window
.
triggerType
,
.
maxTs
=
INT64_MIN
,
.
maxTs
=
INT64_MIN
,
.
winMap
=
NULL
,
};
.
winMap
=
NULL
,
};
pInfo
->
primaryTsIndex
=
((
SColumnNode
*
)
pIntervalPhyNode
->
window
.
pTspk
)
->
slotId
;
pInfo
->
primaryTsIndex
=
((
SColumnNode
*
)
pIntervalPhyNode
->
window
.
pTspk
)
->
slotId
;
size_t
keyBufSize
=
sizeof
(
int64_t
)
+
sizeof
(
int64_t
)
+
POINTER_BYTES
;
size_t
keyBufSize
=
sizeof
(
int64_t
)
+
sizeof
(
int64_t
)
+
POINTER_BYTES
;
initResultSizeInfo
(
pOperator
,
4096
);
initResultSizeInfo
(
pOperator
,
4096
);
int32_t
numOfCols
=
0
;
int32_t
numOfCols
=
0
;
SExprInfo
*
pExprInfo
=
createExprInfo
(
pIntervalPhyNode
->
window
.
pFuncs
,
NULL
,
&
numOfCols
);
SExprInfo
*
pExprInfo
=
createExprInfo
(
pIntervalPhyNode
->
window
.
pFuncs
,
NULL
,
&
numOfCols
);
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pPhyNode
->
pOutputDataBlockDesc
);
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pPhyNode
->
pOutputDataBlockDesc
);
int32_t
code
=
initAggInfo
(
&
pInfo
->
binfo
,
&
pInfo
->
aggSup
,
pExprInfo
,
numOfCols
,
int32_t
code
=
initAggInfo
(
&
pInfo
->
binfo
,
&
pInfo
->
aggSup
,
pExprInfo
,
numOfCols
,
pResBlock
,
keyBufSize
,
pTaskInfo
->
id
.
str
);
pResBlock
,
keyBufSize
,
pTaskInfo
->
id
.
str
);
...
@@ -2160,7 +2160,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
...
@@ -2160,7 +2160,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
if
(
!
isFinalInterval
(
pInfo
))
{
if
(
!
isFinalInterval
(
pInfo
))
{
pInfo
->
twAggSup
.
calTrigger
=
STREAM_TRIGGER_AT_ONCE
;
pInfo
->
twAggSup
.
calTrigger
=
STREAM_TRIGGER_AT_ONCE
;
}
}
pInfo
->
pUpdateRes
=
createResDataBlock
(
pPhyNode
->
pOutputDataBlockDesc
);
\
pInfo
->
pUpdateRes
=
createResDataBlock
(
pPhyNode
->
pOutputDataBlockDesc
);
pInfo
->
pUpdateRes
->
info
.
type
=
STREAM_REPROCESS
;
pInfo
->
pUpdateRes
->
info
.
type
=
STREAM_REPROCESS
;
blockDataEnsureCapacity
(
pInfo
->
pUpdateRes
,
128
);
blockDataEnsureCapacity
(
pInfo
->
pUpdateRes
,
128
);
pInfo
->
pPhyNode
=
nodesCloneNode
(
pPhyNode
);
pInfo
->
pPhyNode
=
nodesCloneNode
(
pPhyNode
);
...
@@ -2174,9 +2174,9 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
...
@@ -2174,9 +2174,9 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
pOperator
->
numOfExprs
=
numOfCols
;
pOperator
->
numOfExprs
=
numOfCols
;
pOperator
->
info
=
pInfo
;
pOperator
->
info
=
pInfo
;
pOperator
->
fpSet
=
createOperatorFpSet
(
NULL
,
doStreamFinalIntervalAgg
,
NULL
,
NULL
,
pOperator
->
fpSet
=
destroyStreamFinalIntervalOperatorInfo
,
aggEncodeResultRow
,
aggDecodeResultRow
,
createOperatorFpSet
(
NULL
,
doStreamFinalIntervalAgg
,
NULL
,
NULL
,
destroyStreamFinalIntervalOperatorInfo
,
NULL
);
aggEncodeResultRow
,
aggDecodeResultRow
,
NULL
);
code
=
appendDownstream
(
pOperator
,
&
downstream
,
1
);
code
=
appendDownstream
(
pOperator
,
&
downstream
,
1
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
@@ -2216,8 +2216,7 @@ void destroyStreamSessionAggOperatorInfo(void* param, int32_t numOfOutput) {
...
@@ -2216,8 +2216,7 @@ void destroyStreamSessionAggOperatorInfo(void* param, int32_t numOfOutput) {
}
}
}
}
int32_t
initBiasicInfo
(
SOptrBasicInfo
*
pBasicInfo
,
SExprInfo
*
pExprInfo
,
int32_t
initBiasicInfo
(
SOptrBasicInfo
*
pBasicInfo
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SSDataBlock
*
pResultBlock
)
{
int32_t
numOfCols
,
SSDataBlock
*
pResultBlock
)
{
pBasicInfo
->
pCtx
=
createSqlFunctionCtx
(
pExprInfo
,
numOfCols
,
&
pBasicInfo
->
rowCellInfoOffset
);
pBasicInfo
->
pCtx
=
createSqlFunctionCtx
(
pExprInfo
,
numOfCols
,
&
pBasicInfo
->
rowCellInfoOffset
);
pBasicInfo
->
pRes
=
pResultBlock
;
pBasicInfo
->
pRes
=
pResultBlock
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
...
@@ -3195,3 +3194,281 @@ _error:
...
@@ -3195,3 +3194,281 @@ _error:
pTaskInfo
->
code
=
code
;
pTaskInfo
->
code
=
code
;
return
NULL
;
return
NULL
;
}
}
typedef
struct
SMergeIntervalAggOperatorInfo
{
SIntervalAggOperatorInfo
intervalAggOperatorInfo
;
SHashObj
*
groupIntervalHash
;
bool
hasGroupId
;
uint64_t
groupId
;
SSDataBlock
*
prefetchedBlock
;
bool
inputBlocksFinished
;
}
SMergeIntervalAggOperatorInfo
;
void
destroyMergeIntervalOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
SMergeIntervalAggOperatorInfo
*
miaInfo
=
(
SMergeIntervalAggOperatorInfo
*
)
param
;
taosHashCleanup
(
miaInfo
->
groupIntervalHash
);
destroyIntervalOperatorInfo
(
&
miaInfo
->
intervalAggOperatorInfo
,
numOfOutput
);
}
static
int32_t
outputPrevIntervalResult
(
SOperatorInfo
*
pOperatorInfo
,
uint64_t
tableGroupId
,
SSDataBlock
*
pResultBlock
,
STimeWindow
*
newWin
)
{
SMergeIntervalAggOperatorInfo
*
miaInfo
=
pOperatorInfo
->
info
;
SIntervalAggOperatorInfo
*
iaInfo
=
&
miaInfo
->
intervalAggOperatorInfo
;
SExecTaskInfo
*
pTaskInfo
=
pOperatorInfo
->
pTaskInfo
;
bool
ascScan
=
(
iaInfo
->
order
==
TSDB_ORDER_ASC
);
STimeWindow
*
prevWin
=
taosHashGet
(
miaInfo
->
groupIntervalHash
,
&
tableGroupId
,
sizeof
(
tableGroupId
));
if
(
prevWin
==
NULL
)
{
taosHashPut
(
miaInfo
->
groupIntervalHash
,
&
tableGroupId
,
sizeof
(
tableGroupId
),
newWin
,
sizeof
(
STimeWindow
));
return
0
;
}
if
(
newWin
==
NULL
||
(
ascScan
&&
newWin
->
skey
>
prevWin
->
ekey
||
(
!
ascScan
)
&&
newWin
->
skey
<
prevWin
->
ekey
)
)
{
SET_RES_WINDOW_KEY
(
iaInfo
->
aggSup
.
keyBuf
,
&
prevWin
->
skey
,
TSDB_KEYSIZE
,
tableGroupId
);
SResultRowPosition
*
p1
=
(
SResultRowPosition
*
)
taosHashGet
(
iaInfo
->
aggSup
.
pResultRowHashTable
,
iaInfo
->
aggSup
.
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
TSDB_KEYSIZE
));
ASSERT
(
p1
!=
NULL
);
finalizeResultRowIntoResultDataBlock
(
iaInfo
->
aggSup
.
pResultBuf
,
p1
,
iaInfo
->
binfo
.
pCtx
,
pOperatorInfo
->
pExpr
,
pOperatorInfo
->
numOfExprs
,
iaInfo
->
binfo
.
rowCellInfoOffset
,
pResultBlock
,
pTaskInfo
);
taosHashRemove
(
iaInfo
->
aggSup
.
pResultRowHashTable
,
iaInfo
->
aggSup
.
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
TSDB_KEYSIZE
));
if
(
newWin
==
NULL
)
{
taosHashRemove
(
miaInfo
->
groupIntervalHash
,
&
tableGroupId
,
sizeof
(
tableGroupId
));
}
else
{
taosHashPut
(
miaInfo
->
groupIntervalHash
,
&
tableGroupId
,
sizeof
(
tableGroupId
),
newWin
,
sizeof
(
STimeWindow
));
}
}
return
0
;
}
static
void
doMergeIntervalAggImpl
(
SOperatorInfo
*
pOperatorInfo
,
SResultRowInfo
*
pResultRowInfo
,
SSDataBlock
*
pBlock
,
int32_t
scanFlag
,
SSDataBlock
*
pResultBlock
)
{
SMergeIntervalAggOperatorInfo
*
miaInfo
=
pOperatorInfo
->
info
;
SIntervalAggOperatorInfo
*
iaInfo
=
&
miaInfo
->
intervalAggOperatorInfo
;
SExecTaskInfo
*
pTaskInfo
=
pOperatorInfo
->
pTaskInfo
;
int32_t
startPos
=
0
;
int32_t
numOfOutput
=
pOperatorInfo
->
numOfExprs
;
int64_t
*
tsCols
=
extractTsCol
(
pBlock
,
iaInfo
);
uint64_t
tableGroupId
=
pBlock
->
info
.
groupId
;
bool
ascScan
=
(
iaInfo
->
order
==
TSDB_ORDER_ASC
);
TSKEY
blockStartTs
=
getStartTsKey
(
&
pBlock
->
info
.
window
,
tsCols
);
SResultRow
*
pResult
=
NULL
;
STimeWindow
win
=
getActiveTimeWindow
(
iaInfo
->
aggSup
.
pResultBuf
,
pResultRowInfo
,
blockStartTs
,
&
iaInfo
->
interval
,
iaInfo
->
interval
.
precision
,
&
iaInfo
->
win
);
int32_t
ret
=
setTimeWindowOutputBuf
(
pResultRowInfo
,
&
win
,
(
scanFlag
==
MAIN_SCAN
),
&
pResult
,
tableGroupId
,
iaInfo
->
binfo
.
pCtx
,
numOfOutput
,
iaInfo
->
binfo
.
rowCellInfoOffset
,
&
iaInfo
->
aggSup
,
pTaskInfo
);
if
(
ret
!=
TSDB_CODE_SUCCESS
||
pResult
==
NULL
)
{
longjmp
(
pTaskInfo
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
TSKEY
ekey
=
ascScan
?
win
.
ekey
:
win
.
skey
;
int32_t
forwardRows
=
getNumOfRowsInTimeWindow
(
&
pBlock
->
info
,
tsCols
,
startPos
,
ekey
,
binarySearchForKey
,
NULL
,
iaInfo
->
order
);
ASSERT
(
forwardRows
>
0
);
// prev time window not interpolation yet.
if
(
iaInfo
->
timeWindowInterpo
)
{
SResultRowPosition
pos
=
addToOpenWindowList
(
pResultRowInfo
,
pResult
);
doInterpUnclosedTimeWindow
(
pOperatorInfo
,
numOfOutput
,
pResultRowInfo
,
pBlock
,
scanFlag
,
tsCols
,
&
pos
);
// restore current time window
ret
=
setTimeWindowOutputBuf
(
pResultRowInfo
,
&
win
,
(
scanFlag
==
MAIN_SCAN
),
&
pResult
,
tableGroupId
,
iaInfo
->
binfo
.
pCtx
,
numOfOutput
,
iaInfo
->
binfo
.
rowCellInfoOffset
,
&
iaInfo
->
aggSup
,
pTaskInfo
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pTaskInfo
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
// window start key interpolation
doWindowBorderInterpolation
(
iaInfo
,
pBlock
,
numOfOutput
,
iaInfo
->
binfo
.
pCtx
,
pResult
,
&
win
,
startPos
,
forwardRows
);
}
updateTimeWindowInfo
(
&
iaInfo
->
twAggSup
.
timeWindowData
,
&
win
,
true
);
doApplyFunctions
(
pTaskInfo
,
iaInfo
->
binfo
.
pCtx
,
&
win
,
&
iaInfo
->
twAggSup
.
timeWindowData
,
startPos
,
forwardRows
,
tsCols
,
pBlock
->
info
.
rows
,
numOfOutput
,
iaInfo
->
order
);
doCloseWindow
(
pResultRowInfo
,
iaInfo
,
pResult
);
// output previous interval results after this interval (&win) is closed
outputPrevIntervalResult
(
pOperatorInfo
,
tableGroupId
,
pResultBlock
,
&
win
);
STimeWindow
nextWin
=
win
;
while
(
1
)
{
int32_t
prevEndPos
=
forwardRows
-
1
+
startPos
;
startPos
=
getNextQualifiedWindow
(
&
iaInfo
->
interval
,
&
nextWin
,
&
pBlock
->
info
,
tsCols
,
prevEndPos
,
iaInfo
->
order
);
if
(
startPos
<
0
)
{
break
;
}
// null data, failed to allocate more memory buffer
int32_t
code
=
setTimeWindowOutputBuf
(
pResultRowInfo
,
&
nextWin
,
(
scanFlag
==
MAIN_SCAN
),
&
pResult
,
tableGroupId
,
iaInfo
->
binfo
.
pCtx
,
numOfOutput
,
iaInfo
->
binfo
.
rowCellInfoOffset
,
&
iaInfo
->
aggSup
,
pTaskInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
||
pResult
==
NULL
)
{
longjmp
(
pTaskInfo
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
ekey
=
ascScan
?
nextWin
.
ekey
:
nextWin
.
skey
;
forwardRows
=
getNumOfRowsInTimeWindow
(
&
pBlock
->
info
,
tsCols
,
startPos
,
ekey
,
binarySearchForKey
,
NULL
,
iaInfo
->
order
);
// window start(end) key interpolation
doWindowBorderInterpolation
(
iaInfo
,
pBlock
,
numOfOutput
,
iaInfo
->
binfo
.
pCtx
,
pResult
,
&
nextWin
,
startPos
,
forwardRows
);
updateTimeWindowInfo
(
&
iaInfo
->
twAggSup
.
timeWindowData
,
&
nextWin
,
true
);
doApplyFunctions
(
pTaskInfo
,
iaInfo
->
binfo
.
pCtx
,
&
nextWin
,
&
iaInfo
->
twAggSup
.
timeWindowData
,
startPos
,
forwardRows
,
tsCols
,
pBlock
->
info
.
rows
,
numOfOutput
,
iaInfo
->
order
);
doCloseWindow
(
pResultRowInfo
,
iaInfo
,
pResult
);
// output previous interval results after this interval (&nextWin) is closed
outputPrevIntervalResult
(
pOperatorInfo
,
tableGroupId
,
pResultBlock
,
&
nextWin
);
}
if
(
iaInfo
->
timeWindowInterpo
)
{
saveDataBlockLastRow
(
iaInfo
->
pPrevValues
,
pBlock
,
iaInfo
->
pInterpCols
);
}
}
static
SSDataBlock
*
doMergeIntervalAgg
(
SOperatorInfo
*
pOperator
)
{
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SMergeIntervalAggOperatorInfo
*
miaInfo
=
pOperator
->
info
;
SIntervalAggOperatorInfo
*
iaInfo
=
&
miaInfo
->
intervalAggOperatorInfo
;
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
return
NULL
;
}
SSDataBlock
*
pRes
=
iaInfo
->
binfo
.
pRes
;
blockDataCleanup
(
pRes
);
blockDataEnsureCapacity
(
pRes
,
pOperator
->
resultInfo
.
capacity
);
if
(
!
miaInfo
->
inputBlocksFinished
)
{
SOperatorInfo
*
downstream
=
pOperator
->
pDownstream
[
0
];
int32_t
scanFlag
=
MAIN_SCAN
;
while
(
1
)
{
SSDataBlock
*
pBlock
=
NULL
;
if
(
miaInfo
->
prefetchedBlock
==
NULL
)
{
pBlock
=
downstream
->
fpSet
.
getNextFn
(
downstream
);
}
else
{
pBlock
=
miaInfo
->
prefetchedBlock
;
miaInfo
->
groupId
=
pBlock
->
info
.
groupId
;
}
if
(
pBlock
==
NULL
)
{
miaInfo
->
inputBlocksFinished
=
true
;
break
;
}
if
(
!
miaInfo
->
hasGroupId
)
{
miaInfo
->
hasGroupId
=
true
;
miaInfo
->
groupId
=
pBlock
->
info
.
groupId
;
}
else
if
(
miaInfo
->
groupId
!=
pBlock
->
info
.
groupId
)
{
miaInfo
->
prefetchedBlock
=
pBlock
;
break
;
}
getTableScanInfo
(
pOperator
,
&
iaInfo
->
order
,
&
scanFlag
);
setInputDataBlock
(
pOperator
,
iaInfo
->
binfo
.
pCtx
,
pBlock
,
iaInfo
->
order
,
scanFlag
,
true
);
STableQueryInfo
*
pTableQueryInfo
=
iaInfo
->
pCurrent
;
setIntervalQueryRange
(
pTableQueryInfo
,
pBlock
->
info
.
window
.
skey
,
&
pTaskInfo
->
window
);
doMergeIntervalAggImpl
(
pOperator
,
&
iaInfo
->
binfo
.
resultRowInfo
,
pBlock
,
scanFlag
,
pRes
);
if
(
pRes
->
info
.
rows
>=
pOperator
->
resultInfo
.
threshold
)
{
break
;
}
}
pRes
->
info
.
groupId
=
miaInfo
->
groupId
;
}
else
{
void
*
p
=
taosHashIterate
(
miaInfo
->
groupIntervalHash
,
NULL
);
if
(
p
!=
NULL
)
{
size_t
len
=
0
;
uint64_t
*
pKey
=
taosHashGetKey
(
p
,
&
len
);
outputPrevIntervalResult
(
pOperator
,
*
pKey
,
pRes
,
NULL
);
}
}
if
(
pRes
->
info
.
rows
==
0
)
{
doSetOperatorCompleted
(
pOperator
);
}
size_t
rows
=
pRes
->
info
.
rows
;
pOperator
->
resultInfo
.
totalRows
+=
rows
;
return
(
rows
==
0
)
?
NULL
:
pRes
;
}
SOperatorInfo
*
createMergeIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SSDataBlock
*
pResBlock
,
SInterval
*
pInterval
,
int32_t
primaryTsSlotId
,
SExecTaskInfo
*
pTaskInfo
)
{
SMergeIntervalAggOperatorInfo
*
miaInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SMergeIntervalAggOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
if
(
miaInfo
==
NULL
||
pOperator
==
NULL
)
{
goto
_error
;
}
SIntervalAggOperatorInfo
*
iaInfo
=
&
miaInfo
->
intervalAggOperatorInfo
;
iaInfo
->
win
=
pTaskInfo
->
window
;
iaInfo
->
order
=
TSDB_ORDER_ASC
;
iaInfo
->
interval
=
*
pInterval
;
iaInfo
->
execModel
=
pTaskInfo
->
execModel
;
iaInfo
->
primaryTsIndex
=
primaryTsSlotId
;
miaInfo
->
groupIntervalHash
=
taosHashInit
(
10
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UBIGINT
),
true
,
HASH_NO_LOCK
);
size_t
keyBufSize
=
sizeof
(
int64_t
)
+
sizeof
(
int64_t
)
+
POINTER_BYTES
;
initResultSizeInfo
(
pOperator
,
4096
);
int32_t
code
=
initAggInfo
(
&
iaInfo
->
binfo
,
&
iaInfo
->
aggSup
,
pExprInfo
,
numOfCols
,
pResBlock
,
keyBufSize
,
pTaskInfo
->
id
.
str
);
initExecTimeWindowInfo
(
&
iaInfo
->
twAggSup
.
timeWindowData
,
&
iaInfo
->
win
);
iaInfo
->
timeWindowInterpo
=
timeWindowinterpNeeded
(
iaInfo
->
binfo
.
pCtx
,
numOfCols
,
iaInfo
);
if
(
iaInfo
->
timeWindowInterpo
)
{
iaInfo
->
binfo
.
resultRowInfo
.
openWindow
=
tdListNew
(
sizeof
(
SResultRowPosition
));
}
// iaInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo);
if
(
code
!=
TSDB_CODE_SUCCESS
/* || iaInfo->pTableQueryInfo == NULL*/
)
{
goto
_error
;
}
initResultRowInfo
(
&
iaInfo
->
binfo
.
resultRowInfo
,
(
int32_t
)
1
);
pOperator
->
name
=
"TimeMergeIntervalAggOperator"
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL
;
pOperator
->
blocking
=
false
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
pExpr
=
pExprInfo
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
numOfExprs
=
numOfCols
;
pOperator
->
info
=
miaInfo
;
pOperator
->
fpSet
=
createOperatorFpSet
(
operatorDummyOpenFn
,
doMergeIntervalAgg
,
NULL
,
NULL
,
destroyMergeIntervalOperatorInfo
,
NULL
,
NULL
,
NULL
);
code
=
appendDownstream
(
pOperator
,
&
downstream
,
1
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
return
pOperator
;
_error:
destroyMergeIntervalOperatorInfo
(
miaInfo
,
numOfCols
);
taosMemoryFreeClear
(
miaInfo
);
taosMemoryFreeClear
(
pOperator
);
pTaskInfo
->
code
=
code
;
return
NULL
;
}
source/libs/function/src/builtins.c
浏览文件 @
7923d51f
...
@@ -1112,7 +1112,7 @@ static bool validateHourRange(int8_t hour) {
...
@@ -1112,7 +1112,7 @@ static bool validateHourRange(int8_t hour) {
}
}
static
bool
validateMinuteRange
(
int8_t
hour
,
int8_t
minute
,
char
sign
)
{
static
bool
validateMinuteRange
(
int8_t
hour
,
int8_t
minute
,
char
sign
)
{
if
(
minute
==
0
||
(
minute
==
30
&&
(
hour
==
3
||
hour
==
5
)
&&
sign
==
'
-
'
))
{
if
(
minute
==
0
||
(
minute
==
30
&&
(
hour
==
3
||
hour
==
5
)
&&
sign
==
'
+
'
))
{
return
true
;
return
true
;
}
}
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
7923d51f
...
@@ -2103,70 +2103,65 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) {
...
@@ -2103,70 +2103,65 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
apercentileFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
static
void
apercentileTransferInfo
(
SAPercentileInfo
*
pInput
,
SAPercentileInfo
*
pOutput
)
{
int32_t
numOfElems
=
0
;
pOutput
->
percent
=
pInput
->
percent
;
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
pOutput
->
algo
=
pInput
->
algo
;
if
(
pOutput
->
algo
==
APERCT_ALGO_TDIGEST
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
buildTDigestInfo
(
pInput
);
tdigestAutoFill
(
pInput
->
pTDigest
,
COMPRESSION
);
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
if
(
pInput
->
pTDigest
->
num_centroids
==
0
&&
pInput
->
pTDigest
->
num_buffered_pts
==
0
)
{
ASSERT
(
pCol
->
info
.
type
==
TSDB_DATA_TYPE_BINARY
);
return
;
SAPercentileInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
SAPercentileInfo
*
pInputInfo
;
int32_t
start
=
pInput
->
startRowIndex
;
for
(
int32_t
i
=
start
;
i
<
pInput
->
numOfRows
+
start
;
++
i
)
{
//if (colDataIsNull_s(pCol, i)) {
// continue;
//}
numOfElems
+=
1
;
char
*
data
=
colDataGetData
(
pCol
,
i
);
pInputInfo
=
(
SAPercentileInfo
*
)
varDataVal
(
data
);
}
pInfo
->
percent
=
pInputInfo
->
percent
;
pInfo
->
algo
=
pInputInfo
->
algo
;
if
(
pInfo
->
algo
==
APERCT_ALGO_TDIGEST
)
{
buildTDigestInfo
(
pInputInfo
);
tdigestAutoFill
(
pInputInfo
->
pTDigest
,
COMPRESSION
);
if
(
pInputInfo
->
pTDigest
->
num_centroids
==
0
&&
pInputInfo
->
pTDigest
->
num_buffered_pts
==
0
)
{
return
TSDB_CODE_SUCCESS
;
}
}
buildTDigestInfo
(
p
Info
);
buildTDigestInfo
(
p
Output
);
TDigest
*
pTDigest
=
p
Info
->
pTDigest
;
TDigest
*
pTDigest
=
p
Output
->
pTDigest
;
if
(
pTDigest
->
num_centroids
<=
0
)
{
if
(
pTDigest
->
num_centroids
<=
0
)
{
memcpy
(
pTDigest
,
pInput
Info
->
pTDigest
,
(
size_t
)
TDIGEST_SIZE
(
COMPRESSION
));
memcpy
(
pTDigest
,
pInput
->
pTDigest
,
(
size_t
)
TDIGEST_SIZE
(
COMPRESSION
));
tdigestAutoFill
(
pTDigest
,
COMPRESSION
);
tdigestAutoFill
(
pTDigest
,
COMPRESSION
);
}
else
{
}
else
{
tdigestMerge
(
pTDigest
,
pInput
Info
->
pTDigest
);
tdigestMerge
(
pTDigest
,
pInput
->
pTDigest
);
}
}
}
else
{
}
else
{
buildHistogramInfo
(
pInput
Info
);
buildHistogramInfo
(
pInput
);
if
(
pInput
Info
->
pHisto
->
numOfElems
<=
0
)
{
if
(
pInput
->
pHisto
->
numOfElems
<=
0
)
{
return
TSDB_CODE_SUCCESS
;
return
;
}
}
buildHistogramInfo
(
p
Info
);
buildHistogramInfo
(
p
Output
);
SHistogramInfo
*
pHisto
=
p
Info
->
pHisto
;
SHistogramInfo
*
pHisto
=
p
Output
->
pHisto
;
if
(
pHisto
->
numOfElems
<=
0
)
{
if
(
pHisto
->
numOfElems
<=
0
)
{
memcpy
(
pHisto
,
pInput
Info
->
pHisto
,
sizeof
(
SHistogramInfo
)
+
sizeof
(
SHistBin
)
*
(
MAX_HISTOGRAM_BIN
+
1
));
memcpy
(
pHisto
,
pInput
->
pHisto
,
sizeof
(
SHistogramInfo
)
+
sizeof
(
SHistBin
)
*
(
MAX_HISTOGRAM_BIN
+
1
));
pHisto
->
elems
=
(
SHistBin
*
)
((
char
*
)
pHisto
+
sizeof
(
SHistogramInfo
));
pHisto
->
elems
=
(
SHistBin
*
)
((
char
*
)
pHisto
+
sizeof
(
SHistogramInfo
));
}
else
{
}
else
{
pHisto
->
elems
=
(
SHistBin
*
)
((
char
*
)
pHisto
+
sizeof
(
SHistogramInfo
));
pHisto
->
elems
=
(
SHistBin
*
)
((
char
*
)
pHisto
+
sizeof
(
SHistogramInfo
));
SHistogramInfo
*
pRes
=
tHistogramMerge
(
pHisto
,
pInput
Info
->
pHisto
,
MAX_HISTOGRAM_BIN
);
SHistogramInfo
*
pRes
=
tHistogramMerge
(
pHisto
,
pInput
->
pHisto
,
MAX_HISTOGRAM_BIN
);
memcpy
(
pHisto
,
pRes
,
sizeof
(
SHistogramInfo
)
+
sizeof
(
SHistBin
)
*
MAX_HISTOGRAM_BIN
);
memcpy
(
pHisto
,
pRes
,
sizeof
(
SHistogramInfo
)
+
sizeof
(
SHistBin
)
*
MAX_HISTOGRAM_BIN
);
pHisto
->
elems
=
(
SHistBin
*
)
((
char
*
)
pHisto
+
sizeof
(
SHistogramInfo
));
pHisto
->
elems
=
(
SHistBin
*
)
((
char
*
)
pHisto
+
sizeof
(
SHistogramInfo
));
tHistogramDestroy
(
&
pRes
);
tHistogramDestroy
(
&
pRes
);
}
}
}
}
}
SET_VAL
(
pResInfo
,
numOfElems
,
1
);
int32_t
apercentileFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
ASSERT
(
pCol
->
info
.
type
==
TSDB_DATA_TYPE_BINARY
);
SAPercentileInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
int32_t
start
=
pInput
->
startRowIndex
;
char
*
data
=
colDataGetData
(
pCol
,
start
);
SAPercentileInfo
*
pInputInfo
=
(
SAPercentileInfo
*
)
varDataVal
(
data
);
apercentileTransferInfo
(
pInputInfo
,
pInfo
);
SET_VAL
(
pResInfo
,
1
,
1
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -3049,6 +3044,17 @@ _spread_over:
...
@@ -3049,6 +3044,17 @@ _spread_over:
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
void
spreadTransferInfo
(
SSpreadInfo
*
pInput
,
SSpreadInfo
*
pOutput
)
{
pOutput
->
hasResult
=
pInput
->
hasResult
;
if
(
pInput
->
max
>
pOutput
->
max
)
{
pOutput
->
max
=
pInput
->
max
;
}
if
(
pInput
->
min
<
pOutput
->
min
)
{
pOutput
->
min
=
pInput
->
min
;
}
}
int32_t
spreadFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
spreadFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
...
@@ -3061,14 +3067,7 @@ int32_t spreadFunctionMerge(SqlFunctionCtx *pCtx) {
...
@@ -3061,14 +3067,7 @@ int32_t spreadFunctionMerge(SqlFunctionCtx *pCtx) {
char
*
data
=
colDataGetData
(
pCol
,
start
);
char
*
data
=
colDataGetData
(
pCol
,
start
);
pInputInfo
=
(
SSpreadInfo
*
)
varDataVal
(
data
);
pInputInfo
=
(
SSpreadInfo
*
)
varDataVal
(
data
);
pInfo
->
hasResult
=
pInputInfo
->
hasResult
;
spreadTransferInfo
(
pInputInfo
,
pInfo
);
if
(
pInputInfo
->
max
>
pInfo
->
max
)
{
pInfo
->
max
=
pInputInfo
->
max
;
}
if
(
pInputInfo
->
min
<
pInfo
->
min
)
{
pInfo
->
min
=
pInputInfo
->
min
;
}
SET_VAL
(
GET_RES_INFO
(
pCtx
),
1
,
1
);
SET_VAL
(
GET_RES_INFO
(
pCtx
),
1
,
1
);
...
@@ -3206,6 +3205,17 @@ _elapsed_over:
...
@@ -3206,6 +3205,17 @@ _elapsed_over:
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
void
elapsedTransferInfo
(
SElapsedInfo
*
pInput
,
SElapsedInfo
*
pOutput
)
{
pOutput
->
timeUnit
=
pInput
->
timeUnit
;
if
(
pOutput
->
min
>
pInput
->
min
)
{
pOutput
->
min
=
pInput
->
min
;
}
if
(
pOutput
->
max
<
pInput
->
max
)
{
pOutput
->
max
=
pInput
->
max
;
}
}
int32_t
elapsedFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
elapsedFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
...
@@ -3217,14 +3227,7 @@ int32_t elapsedFunctionMerge(SqlFunctionCtx *pCtx) {
...
@@ -3217,14 +3227,7 @@ int32_t elapsedFunctionMerge(SqlFunctionCtx *pCtx) {
char
*
data
=
colDataGetData
(
pCol
,
start
);
char
*
data
=
colDataGetData
(
pCol
,
start
);
SElapsedInfo
*
pInputInfo
=
(
SElapsedInfo
*
)
varDataVal
(
data
);
SElapsedInfo
*
pInputInfo
=
(
SElapsedInfo
*
)
varDataVal
(
data
);
pInfo
->
timeUnit
=
pInputInfo
->
timeUnit
;
elapsedTransferInfo
(
pInputInfo
,
pInfo
);
if
(
pInfo
->
min
>
pInputInfo
->
min
)
{
pInfo
->
min
=
pInputInfo
->
min
;
}
if
(
pInfo
->
max
<
pInputInfo
->
max
)
{
pInfo
->
max
=
pInputInfo
->
max
;
}
SET_VAL
(
GET_RES_INFO
(
pCtx
),
1
,
1
);
SET_VAL
(
GET_RES_INFO
(
pCtx
),
1
,
1
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -3470,6 +3473,17 @@ int32_t histogramFunction(SqlFunctionCtx *pCtx) {
...
@@ -3470,6 +3473,17 @@ int32_t histogramFunction(SqlFunctionCtx *pCtx) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
void
histogramTransferInfo
(
SHistoFuncInfo
*
pInput
,
SHistoFuncInfo
*
pOutput
)
{
pOutput
->
normalized
=
pInput
->
normalized
;
pOutput
->
numOfBins
=
pInput
->
numOfBins
;
pOutput
->
totalCount
+=
pInput
->
totalCount
;
for
(
int32_t
k
=
0
;
k
<
pOutput
->
numOfBins
;
++
k
)
{
pOutput
->
bins
[
k
].
lower
=
pInput
->
bins
[
k
].
lower
;
pOutput
->
bins
[
k
].
upper
=
pInput
->
bins
[
k
].
upper
;
pOutput
->
bins
[
k
].
count
+=
pInput
->
bins
[
k
].
count
;
}
}
int32_t
histogramFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
histogramFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
...
@@ -3481,14 +3495,7 @@ int32_t histogramFunctionMerge(SqlFunctionCtx *pCtx) {
...
@@ -3481,14 +3495,7 @@ int32_t histogramFunctionMerge(SqlFunctionCtx *pCtx) {
char
*
data
=
colDataGetData
(
pCol
,
start
);
char
*
data
=
colDataGetData
(
pCol
,
start
);
SHistoFuncInfo
*
pInputInfo
=
(
SHistoFuncInfo
*
)
varDataVal
(
data
);
SHistoFuncInfo
*
pInputInfo
=
(
SHistoFuncInfo
*
)
varDataVal
(
data
);
pInfo
->
normalized
=
pInputInfo
->
normalized
;
histogramTransferInfo
(
pInputInfo
,
pInfo
);
pInfo
->
numOfBins
=
pInputInfo
->
numOfBins
;
pInfo
->
totalCount
+=
pInputInfo
->
totalCount
;
for
(
int32_t
k
=
0
;
k
<
pInfo
->
numOfBins
;
++
k
)
{
pInfo
->
bins
[
k
].
lower
=
pInputInfo
->
bins
[
k
].
lower
;
pInfo
->
bins
[
k
].
upper
=
pInputInfo
->
bins
[
k
].
upper
;
pInfo
->
bins
[
k
].
count
+=
pInputInfo
->
bins
[
k
].
count
;
}
SET_VAL
(
GET_RES_INFO
(
pCtx
),
pInfo
->
numOfBins
,
pInfo
->
numOfBins
);
SET_VAL
(
GET_RES_INFO
(
pCtx
),
pInfo
->
numOfBins
,
pInfo
->
numOfBins
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -3676,6 +3683,14 @@ int32_t hllFunction(SqlFunctionCtx *pCtx) {
...
@@ -3676,6 +3683,14 @@ int32_t hllFunction(SqlFunctionCtx *pCtx) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
void
hllTransferInfo
(
SHLLInfo
*
pInput
,
SHLLInfo
*
pOutput
)
{
for
(
int32_t
k
=
0
;
k
<
HLL_BUCKETS
;
++
k
)
{
if
(
pOutput
->
buckets
[
k
]
<
pInput
->
buckets
[
k
])
{
pOutput
->
buckets
[
k
]
=
pInput
->
buckets
[
k
];
}
}
}
int32_t
hllFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
hllFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
...
@@ -3687,11 +3702,7 @@ int32_t hllFunctionMerge(SqlFunctionCtx *pCtx) {
...
@@ -3687,11 +3702,7 @@ int32_t hllFunctionMerge(SqlFunctionCtx *pCtx) {
char
*
data
=
colDataGetData
(
pCol
,
start
);
char
*
data
=
colDataGetData
(
pCol
,
start
);
SHLLInfo
*
pInputInfo
=
(
SHLLInfo
*
)
varDataVal
(
data
);
SHLLInfo
*
pInputInfo
=
(
SHLLInfo
*
)
varDataVal
(
data
);
for
(
int32_t
k
=
0
;
k
<
HLL_BUCKETS
;
++
k
)
{
hllTransferInfo
(
pInputInfo
,
pInfo
);
if
(
pInfo
->
buckets
[
k
]
<
pInputInfo
->
buckets
[
k
])
{
pInfo
->
buckets
[
k
]
=
pInputInfo
->
buckets
[
k
];
}
}
SET_VAL
(
GET_RES_INFO
(
pCtx
),
1
,
1
);
SET_VAL
(
GET_RES_INFO
(
pCtx
),
1
,
1
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
7923d51f
...
@@ -201,8 +201,8 @@ void syncNodeRelease(SSyncNode* pNode);
...
@@ -201,8 +201,8 @@ void syncNodeRelease(SSyncNode* pNode);
// raft state change --------------
// raft state change --------------
void
syncNodeUpdateTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
);
void
syncNodeUpdateTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
);
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
);
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
,
const
char
*
debugStr
);
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
);
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
,
const
char
*
debugStr
);
void
syncNodeCandidate2Leader
(
SSyncNode
*
pSyncNode
);
void
syncNodeCandidate2Leader
(
SSyncNode
*
pSyncNode
);
void
syncNodeFollower2Candidate
(
SSyncNode
*
pSyncNode
);
void
syncNodeFollower2Candidate
(
SSyncNode
*
pSyncNode
);
...
...
source/libs/sync/inc/syncRaftStore.h
浏览文件 @
7923d51f
...
@@ -49,8 +49,8 @@ void raftStoreClearVote(SRaftStore *pRaftStore);
...
@@ -49,8 +49,8 @@ void raftStoreClearVote(SRaftStore *pRaftStore);
void
raftStoreNextTerm
(
SRaftStore
*
pRaftStore
);
void
raftStoreNextTerm
(
SRaftStore
*
pRaftStore
);
void
raftStoreSetTerm
(
SRaftStore
*
pRaftStore
,
SyncTerm
term
);
void
raftStoreSetTerm
(
SRaftStore
*
pRaftStore
,
SyncTerm
term
);
int32_t
raftStoreFromJson
(
SRaftStore
*
pRaftStore
,
cJSON
*
pJson
);
int32_t
raftStoreFromJson
(
SRaftStore
*
pRaftStore
,
cJSON
*
pJson
);
cJSON
*
raftStore2Json
(
SRaftStore
*
pRaftStore
);
cJSON
*
raftStore2Json
(
SRaftStore
*
pRaftStore
);
char
*
raftStore2Str
(
SRaftStore
*
pRaftStore
);
char
*
raftStore2Str
(
SRaftStore
*
pRaftStore
);
// for debug -------------------
// for debug -------------------
void
raftStorePrint
(
SRaftStore
*
pObj
);
void
raftStorePrint
(
SRaftStore
*
pObj
);
...
...
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
7923d51f
...
@@ -39,8 +39,8 @@ typedef struct SSyncSnapshotSender {
...
@@ -39,8 +39,8 @@ typedef struct SSyncSnapshotSender {
bool
start
;
bool
start
;
int32_t
seq
;
int32_t
seq
;
int32_t
ack
;
int32_t
ack
;
void
*
pReader
;
void
*
pReader
;
void
*
pCurrentBlock
;
void
*
pCurrentBlock
;
int32_t
blockLen
;
int32_t
blockLen
;
SSnapshot
snapshot
;
SSnapshot
snapshot
;
int64_t
sendingMS
;
int64_t
sendingMS
;
...
@@ -58,28 +58,29 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender);
...
@@ -58,28 +58,29 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender);
void
snapshotSenderStop
(
SSyncSnapshotSender
*
pSender
);
void
snapshotSenderStop
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotSend
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotSend
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotReSend
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotReSend
(
SSyncSnapshotSender
*
pSender
);
cJSON
*
snapshotSender2Json
(
SSyncSnapshotSender
*
pSender
);
cJSON
*
snapshotSender2Json
(
SSyncSnapshotSender
*
pSender
);
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
);
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
);
typedef
struct
SSyncSnapshotReceiver
{
typedef
struct
SSyncSnapshotReceiver
{
bool
start
;
bool
start
;
int32_t
ack
;
int32_t
ack
;
void
*
pWriter
;
void
*
pWriter
;
SyncTerm
term
;
SyncTerm
term
;
SyncTerm
privateTerm
;
SyncTerm
privateTerm
;
SSyncNode
*
pSyncNode
;
SSyncNode
*
pSyncNode
;
int32_t
replicaIndex
;
SRaftId
fromId
;
}
SSyncSnapshotReceiver
;
}
SSyncSnapshotReceiver
;
SSyncSnapshotReceiver
*
snapshotReceiverCreate
(
SSyncNode
*
pSyncNode
,
int32_t
replicaIndex
);
SSyncSnapshotReceiver
*
snapshotReceiverCreate
(
SSyncNode
*
pSyncNode
,
SRaftId
fromId
);
void
snapshotReceiverDestroy
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverDestroy
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
);
void
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
,
SRaftId
fromId
);
bool
snapshotReceiverIsStart
(
SSyncSnapshotReceiver
*
pReceiver
);
bool
snapshotReceiverIsStart
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
,
bool
apply
);
void
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
,
bool
apply
);
cJSON
*
snapshotReceiver2Json
(
SSyncSnapshotReceiver
*
pReceiver
);
cJSON
*
snapshotReceiver2Json
(
SSyncSnapshotReceiver
*
pReceiver
);
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
);
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
);
int32_t
syncNodeOnSnapshotSendCb
(
SSyncNode
*
ths
,
SyncSnapshotSend
*
pMsg
);
int32_t
syncNodeOnSnapshotSendCb
(
SSyncNode
*
ths
,
SyncSnapshotSend
*
pMsg
);
int32_t
syncNodeOnSnapshotRspCb
(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
);
int32_t
syncNodeOnSnapshotRspCb
(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
);
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
7923d51f
...
@@ -150,7 +150,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -150,7 +150,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
"ths->state:%d, logOK:%d"
,
"ths->state:%d, logOK:%d"
,
pMsg
->
term
,
ths
->
pRaftStore
->
currentTerm
,
ths
->
state
,
logOK
);
pMsg
->
term
,
ths
->
pRaftStore
->
currentTerm
,
ths
->
state
,
logOK
);
syncNodeBecomeFollower
(
ths
);
syncNodeBecomeFollower
(
ths
,
"from candidate by append entries"
);
// ret or reply?
// ret or reply?
return
ret
;
return
ret
;
...
@@ -380,17 +380,19 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -380,17 +380,19 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
// change isStandBy to normal
// change isStandBy to normal
if
(
!
isDrop
)
{
if
(
!
isDrop
)
{
if
(
ths
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
if
(
ths
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
syncNodeBecomeLeader
(
ths
);
syncNodeBecomeLeader
(
ths
,
"config change"
);
}
else
{
}
else
{
syncNodeBecomeFollower
(
ths
);
syncNodeBecomeFollower
(
ths
,
"config change"
);
}
}
}
}
char
*
sOld
=
syncCfg2Str
(
&
oldSyncCfg
);
if
(
gRaftDetailLog
)
{
char
*
sNew
=
syncCfg2Str
(
&
newSyncCfg
);
char
*
sOld
=
syncCfg2Str
(
&
oldSyncCfg
);
sInfo
(
"==config change== 0x11 old:%s new:%s isDrop:%d
\n
"
,
sOld
,
sNew
,
isDrop
);
char
*
sNew
=
syncCfg2Str
(
&
newSyncCfg
);
taosMemoryFree
(
sOld
);
sInfo
(
"==config change== 0x11 old:%s new:%s isDrop:%d
\n
"
,
sOld
,
sNew
,
isDrop
);
taosMemoryFree
(
sNew
);
taosMemoryFree
(
sOld
);
taosMemoryFree
(
sNew
);
}
}
}
// always call FpReConfigCb
// always call FpReConfigCb
...
@@ -399,10 +401,12 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -399,10 +401,12 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
cbMeta
.
currentTerm
=
ths
->
pRaftStore
->
currentTerm
;
cbMeta
.
currentTerm
=
ths
->
pRaftStore
->
currentTerm
;
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
term
=
pEntry
->
term
;
cbMeta
.
term
=
pEntry
->
term
;
cbMeta
.
newCfg
=
newSyncCfg
;
cbMeta
.
oldCfg
=
oldSyncCfg
;
cbMeta
.
oldCfg
=
oldSyncCfg
;
cbMeta
.
seqNum
=
pEntry
->
seqNum
;
cbMeta
.
flag
=
0x11
;
cbMeta
.
flag
=
0x11
;
cbMeta
.
isDrop
=
isDrop
;
cbMeta
.
isDrop
=
isDrop
;
ths
->
pFsm
->
FpReConfigCb
(
ths
->
pFsm
,
newSyncCf
g
,
cbMeta
);
ths
->
pFsm
->
FpReConfigCb
(
ths
->
pFsm
,
&
rpcMs
g
,
cbMeta
);
}
}
}
}
...
@@ -469,7 +473,7 @@ static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -469,7 +473,7 @@ static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) {
// delete confict entries
// delete confict entries
code
=
ths
->
pLogStore
->
syncLogTruncate
(
ths
->
pLogStore
,
delBegin
);
code
=
ths
->
pLogStore
->
syncLogTruncate
(
ths
->
pLogStore
,
delBegin
);
ASSERT
(
code
==
0
);
ASSERT
(
code
==
0
);
sInfo
(
"sync event
log truncate, from %ld to %ld"
,
delBegin
,
delEnd
);
sInfo
(
"sync event
vgId:%d log truncate, from %ld to %ld"
,
ths
->
vgId
,
delBegin
,
delEnd
);
logStoreSimpleLog2
(
"after syncNodeMakeLogSame"
,
ths
->
pLogStore
);
logStoreSimpleLog2
(
"after syncNodeMakeLogSame"
,
ths
->
pLogStore
);
return
code
;
return
code
;
...
@@ -571,7 +575,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
...
@@ -571,7 +575,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
if
(
condition
)
{
if
(
condition
)
{
sTrace
(
"recv SyncAppendEntries, candidate to follower"
);
sTrace
(
"recv SyncAppendEntries, candidate to follower"
);
syncNodeBecomeFollower
(
ths
);
syncNodeBecomeFollower
(
ths
,
"from candidate by append entries"
);
// do not reply?
// do not reply?
return
ret
;
return
ret
;
}
}
...
@@ -742,6 +746,18 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
...
@@ -742,6 +746,18 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
if
(
pMsg
->
commitIndex
>
ths
->
commitIndex
)
{
if
(
pMsg
->
commitIndex
>
ths
->
commitIndex
)
{
// has commit entry in local
// has commit entry in local
if
(
pMsg
->
commitIndex
<=
ths
->
pLogStore
->
syncLogLastIndex
(
ths
->
pLogStore
))
{
if
(
pMsg
->
commitIndex
<=
ths
->
pLogStore
->
syncLogLastIndex
(
ths
->
pLogStore
))
{
// advance commit index to sanpshot first
SSnapshot
snapshot
;
ths
->
pFsm
->
FpGetSnapshot
(
ths
->
pFsm
,
&
snapshot
);
if
(
snapshot
.
lastApplyIndex
>=
0
&&
snapshot
.
lastApplyIndex
>
ths
->
commitIndex
)
{
SyncIndex
commitBegin
=
ths
->
commitIndex
;
SyncIndex
commitEnd
=
snapshot
.
lastApplyIndex
;
ths
->
commitIndex
=
snapshot
.
lastApplyIndex
;
sInfo
(
"sync event vgId:%d commit by snapshot from index:%ld to index:%ld, %s"
,
ths
->
vgId
,
commitBegin
,
commitEnd
,
syncUtilState2String
(
ths
->
state
));
}
SyncIndex
beginIndex
=
ths
->
commitIndex
+
1
;
SyncIndex
beginIndex
=
ths
->
commitIndex
+
1
;
SyncIndex
endIndex
=
pMsg
->
commitIndex
;
SyncIndex
endIndex
=
pMsg
->
commitIndex
;
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
7923d51f
...
@@ -121,7 +121,7 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
...
@@ -121,7 +121,7 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
syncIndexMgrLog2
(
"recv SyncAppendEntriesReply, before pNextIndex:"
,
ths
->
pNextIndex
);
syncIndexMgrLog2
(
"recv SyncAppendEntriesReply, before pNextIndex:"
,
ths
->
pNextIndex
);
syncIndexMgrLog2
(
"recv SyncAppendEntriesReply, before pMatchIndex:"
,
ths
->
pMatchIndex
);
syncIndexMgrLog2
(
"recv SyncAppendEntriesReply, before pMatchIndex:"
,
ths
->
pMatchIndex
);
{
if
(
gRaftDetailLog
)
{
SSnapshot
snapshot
;
SSnapshot
snapshot
;
ths
->
pFsm
->
FpGetSnapshot
(
ths
->
pFsm
,
&
snapshot
);
ths
->
pFsm
->
FpGetSnapshot
(
ths
->
pFsm
,
&
snapshot
);
sTrace
(
"recv SyncAppendEntriesReply, before snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu"
,
sTrace
(
"recv SyncAppendEntriesReply, before snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu"
,
...
@@ -147,7 +147,10 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
...
@@ -147,7 +147,10 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
if
(
pMsg
->
success
)
{
if
(
pMsg
->
success
)
{
// nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1]
// nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1]
syncIndexMgrSetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
pMsg
->
matchIndex
+
1
);
syncIndexMgrSetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
pMsg
->
matchIndex
+
1
);
sTrace
(
"update next match, index:%ld, success:%d"
,
pMsg
->
matchIndex
+
1
,
pMsg
->
success
);
if
(
gRaftDetailLog
)
{
sTrace
(
"update next match, index:%ld, success:%d"
,
pMsg
->
matchIndex
+
1
,
pMsg
->
success
);
}
// matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex]
// matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex]
syncIndexMgrSetIndex
(
ths
->
pMatchIndex
,
&
(
pMsg
->
srcId
),
pMsg
->
matchIndex
);
syncIndexMgrSetIndex
(
ths
->
pMatchIndex
,
&
(
pMsg
->
srcId
),
pMsg
->
matchIndex
);
...
@@ -159,7 +162,9 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
...
@@ -159,7 +162,9 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
}
else
{
}
else
{
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
));
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
));
sTrace
(
"update next not match, begin, index:%ld, success:%d"
,
nextIndex
,
pMsg
->
success
);
if
(
gRaftDetailLog
)
{
sTrace
(
"update next index not match, begin, index:%ld, success:%d"
,
nextIndex
,
pMsg
->
success
);
}
// notice! int64, uint64
// notice! int64, uint64
if
(
nextIndex
>
SYNC_INDEX_BEGIN
)
{
if
(
nextIndex
>
SYNC_INDEX_BEGIN
)
{
...
@@ -178,9 +183,23 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
...
@@ -178,9 +183,23 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
pMsg
->
privateTerm
<
pSender
->
privateTerm
)
{
pMsg
->
privateTerm
<
pSender
->
privateTerm
)
{
snapshotSenderStart
(
pSender
);
snapshotSenderStart
(
pSender
);
char
*
s
=
snapshotSender2Str
(
pSender
);
char
host
[
128
];
sInfo
(
"sync event snapshot send start sender first time, sender:%s"
,
s
);
uint16_t
port
;
taosMemoryFree
(
s
);
syncUtilU642Addr
(
pSender
->
pSyncNode
->
replicasId
[
pSender
->
replicaIndex
].
addr
,
host
,
sizeof
(
host
),
&
port
);
if
(
gRaftDetailLog
)
{
char
*
s
=
snapshotSender2Str
(
pSender
);
sInfo
(
"sync event vgId:%d snapshot send to %s:%d start sender first time, lastApplyIndex:%ld lastApplyTerm:%lu "
"sender:%s"
,
ths
->
vgId
,
host
,
port
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
s
);
taosMemoryFree
(
s
);
}
else
{
sInfo
(
"sync event vgId:%d snapshot send to %s:%d start sender first time, lastApplyIndex:%ld "
"lastApplyTerm:%lu"
,
ths
->
vgId
,
host
,
port
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
);
}
}
}
SyncIndex
sentryIndex
=
pSender
->
snapshot
.
lastApplyIndex
+
1
;
SyncIndex
sentryIndex
=
pSender
->
snapshot
.
lastApplyIndex
+
1
;
...
@@ -195,12 +214,14 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
...
@@ -195,12 +214,14 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
}
}
syncIndexMgrSetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
nextIndex
);
syncIndexMgrSetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
nextIndex
);
sTrace
(
"update next not match, end, index:%ld, success:%d"
,
nextIndex
,
pMsg
->
success
);
if
(
gRaftDetailLog
)
{
sTrace
(
"update next index not match, end, index:%ld, success:%d"
,
nextIndex
,
pMsg
->
success
);
}
}
}
syncIndexMgrLog2
(
"recv SyncAppendEntriesReply, after pNextIndex:"
,
ths
->
pNextIndex
);
syncIndexMgrLog2
(
"recv SyncAppendEntriesReply, after pNextIndex:"
,
ths
->
pNextIndex
);
syncIndexMgrLog2
(
"recv SyncAppendEntriesReply, after pMatchIndex:"
,
ths
->
pMatchIndex
);
syncIndexMgrLog2
(
"recv SyncAppendEntriesReply, after pMatchIndex:"
,
ths
->
pMatchIndex
);
{
if
(
gRaftDetailLog
)
{
SSnapshot
snapshot
;
SSnapshot
snapshot
;
ths
->
pFsm
->
FpGetSnapshot
(
ths
->
pFsm
,
&
snapshot
);
ths
->
pFsm
->
FpGetSnapshot
(
ths
->
pFsm
,
&
snapshot
);
sTrace
(
"recv SyncAppendEntriesReply, after snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu"
,
sTrace
(
"recv SyncAppendEntriesReply, after snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu"
,
...
...
source/libs/sync/src/syncCommit.c
浏览文件 @
7923d51f
...
@@ -48,13 +48,28 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
...
@@ -48,13 +48,28 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
syncIndexMgrLog2
(
"==syncNodeMaybeAdvanceCommitIndex== pNextIndex"
,
pSyncNode
->
pNextIndex
);
syncIndexMgrLog2
(
"==syncNodeMaybeAdvanceCommitIndex== pNextIndex"
,
pSyncNode
->
pNextIndex
);
syncIndexMgrLog2
(
"==syncNodeMaybeAdvanceCommitIndex== pMatchIndex"
,
pSyncNode
->
pMatchIndex
);
syncIndexMgrLog2
(
"==syncNodeMaybeAdvanceCommitIndex== pMatchIndex"
,
pSyncNode
->
pMatchIndex
);
// advance commit index to sanpshot first
SSnapshot
snapshot
;
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSyncNode
->
pFsm
,
&
snapshot
);
if
(
snapshot
.
lastApplyIndex
>
0
&&
snapshot
.
lastApplyIndex
>
pSyncNode
->
commitIndex
)
{
SyncIndex
commitBegin
=
pSyncNode
->
commitIndex
;
SyncIndex
commitEnd
=
snapshot
.
lastApplyIndex
;
pSyncNode
->
commitIndex
=
snapshot
.
lastApplyIndex
;
sInfo
(
"sync event vgId:%d commit by snapshot from index:%ld to index:%ld, %s"
,
pSyncNode
->
vgId
,
pSyncNode
->
commitIndex
,
snapshot
.
lastApplyIndex
,
syncUtilState2String
(
pSyncNode
->
state
));
}
// update commit index
// update commit index
SyncIndex
newCommitIndex
=
pSyncNode
->
commitIndex
;
SyncIndex
newCommitIndex
=
pSyncNode
->
commitIndex
;
for
(
SyncIndex
index
=
pSyncNode
->
pLogStore
->
getLastIndex
(
pSyncNode
->
pLogStore
);
index
>
pSyncNode
->
commitIndex
;
for
(
SyncIndex
index
=
syncNodeGetLastIndex
(
pSyncNode
);
index
>
pSyncNode
->
commitIndex
;
--
index
)
{
--
index
)
{
bool
agree
=
syncAgree
(
pSyncNode
,
index
);
bool
agree
=
syncAgree
(
pSyncNode
,
index
);
sTrace
(
"syncMaybeAdvanceCommitIndex syncAgree:%d, index:%ld, pSyncNode->commitIndex:%ld"
,
agree
,
index
,
pSyncNode
->
commitIndex
);
if
(
gRaftDetailLog
)
{
sTrace
(
"syncMaybeAdvanceCommitIndex syncAgree:%d, index:%ld, pSyncNode->commitIndex:%ld"
,
agree
,
index
,
pSyncNode
->
commitIndex
);
}
if
(
agree
)
{
if
(
agree
)
{
// term
// term
SSyncRaftEntry
*
pEntry
=
pSyncNode
->
pLogStore
->
getEntry
(
pSyncNode
->
pLogStore
,
index
);
SSyncRaftEntry
*
pEntry
=
pSyncNode
->
pLogStore
->
getEntry
(
pSyncNode
->
pLogStore
,
index
);
...
@@ -64,16 +79,21 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
...
@@ -64,16 +79,21 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
if
(
pEntry
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
)
{
if
(
pEntry
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
)
{
// update commit index
// update commit index
newCommitIndex
=
index
;
newCommitIndex
=
index
;
sTrace
(
"syncMaybeAdvanceCommitIndex maybe to update, newCommitIndex:%ld commit, pSyncNode->commitIndex:%ld"
,
newCommitIndex
,
pSyncNode
->
commitIndex
);
if
(
gRaftDetailLog
)
{
sTrace
(
"syncMaybeAdvanceCommitIndex maybe to update, newCommitIndex:%ld commit, pSyncNode->commitIndex:%ld"
,
newCommitIndex
,
pSyncNode
->
commitIndex
);
}
syncEntryDestory
(
pEntry
);
syncEntryDestory
(
pEntry
);
break
;
break
;
}
else
{
}
else
{
sTrace
(
if
(
gRaftDetailLog
)
{
"syncMaybeAdvanceCommitIndex can not commit due to term not equal, pEntry->term:%lu, "
sTrace
(
"pSyncNode->pRaftStore->currentTerm:%lu"
,
"syncMaybeAdvanceCommitIndex can not commit due to term not equal, pEntry->term:%lu, "
pEntry
->
term
,
pSyncNode
->
pRaftStore
->
currentTerm
);
"pSyncNode->pRaftStore->currentTerm:%lu"
,
pEntry
->
term
,
pSyncNode
->
pRaftStore
->
currentTerm
);
}
}
}
syncEntryDestory
(
pEntry
);
syncEntryDestory
(
pEntry
);
...
@@ -84,7 +104,9 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
...
@@ -84,7 +104,9 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
SyncIndex
beginIndex
=
pSyncNode
->
commitIndex
+
1
;
SyncIndex
beginIndex
=
pSyncNode
->
commitIndex
+
1
;
SyncIndex
endIndex
=
newCommitIndex
;
SyncIndex
endIndex
=
newCommitIndex
;
sTrace
(
"syncMaybeAdvanceCommitIndex sync commit %ld"
,
newCommitIndex
);
if
(
gRaftDetailLog
)
{
sTrace
(
"syncMaybeAdvanceCommitIndex sync commit %ld"
,
newCommitIndex
);
}
// update commit index
// update commit index
pSyncNode
->
commitIndex
=
newCommitIndex
;
pSyncNode
->
commitIndex
=
newCommitIndex
;
...
...
source/libs/sync/src/syncEnv.c
浏览文件 @
7923d51f
...
@@ -40,7 +40,7 @@ int32_t syncEnvStart() {
...
@@ -40,7 +40,7 @@ int32_t syncEnvStart() {
// gSyncEnv = doSyncEnvStart(gSyncEnv);
// gSyncEnv = doSyncEnvStart(gSyncEnv);
gSyncEnv
=
doSyncEnvStart
();
gSyncEnv
=
doSyncEnvStart
();
assert
(
gSyncEnv
!=
NULL
);
assert
(
gSyncEnv
!=
NULL
);
sTrace
(
"sync
EnvStart ok!
"
);
sTrace
(
"sync
env start ok
"
);
return
ret
;
return
ret
;
}
}
...
...
source/libs/sync/src/syncIndexMgr.c
浏览文件 @
7923d51f
...
@@ -119,7 +119,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
...
@@ -119,7 +119,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
char
*
syncIndexMgr2Str
(
SSyncIndexMgr
*
pSyncIndexMgr
)
{
char
*
syncIndexMgr2Str
(
SSyncIndexMgr
*
pSyncIndexMgr
)
{
cJSON
*
pJson
=
syncIndexMgr2Json
(
pSyncIndexMgr
);
cJSON
*
pJson
=
syncIndexMgr2Json
(
pSyncIndexMgr
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
return
serialized
;
}
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
7923d51f
...
@@ -87,7 +87,9 @@ int64_t syncOpen(const SSyncInfo* pSyncInfo) {
...
@@ -87,7 +87,9 @@ int64_t syncOpen(const SSyncInfo* pSyncInfo) {
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
pSyncInfo
);
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
pSyncInfo
);
assert
(
pSyncNode
!=
NULL
);
assert
(
pSyncNode
!=
NULL
);
syncNodeLog2
(
"syncNodeOpen open success"
,
pSyncNode
);
if
(
gRaftDetailLog
)
{
syncNodeLog2
(
"syncNodeOpen open success"
,
pSyncNode
);
}
pSyncNode
->
rid
=
taosAddRef
(
tsNodeRefId
,
pSyncNode
);
pSyncNode
->
rid
=
taosAddRef
(
tsNodeRefId
,
pSyncNode
);
if
(
pSyncNode
->
rid
<
0
)
{
if
(
pSyncNode
->
rid
<
0
)
{
...
@@ -173,20 +175,37 @@ int32_t syncSetStandby(int64_t rid) {
...
@@ -173,20 +175,37 @@ int32_t syncSetStandby(int64_t rid) {
int32_t
syncReconfig
(
int64_t
rid
,
const
SSyncCfg
*
pSyncCfg
)
{
int32_t
syncReconfig
(
int64_t
rid
,
const
SSyncCfg
*
pSyncCfg
)
{
int32_t
ret
=
0
;
int32_t
ret
=
0
;
char
*
configChange
=
syncCfg2Str
((
SSyncCfg
*
)
pSyncCfg
);
char
*
newconfig
=
syncCfg2Str
((
SSyncCfg
*
)
pSyncCfg
);
sInfo
(
"==syncReconfig== newconfig:%s"
,
configChange
);
if
(
gRaftDetailLog
)
{
sInfo
(
"==syncReconfig== newconfig:%s"
,
newconfig
);
}
SRpcMsg
rpcMsg
=
{
0
};
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
msgType
=
TDMT_SYNC_CONFIG_CHANGE
;
rpcMsg
.
msgType
=
TDMT_SYNC_CONFIG_CHANGE
;
rpcMsg
.
info
.
noResp
=
1
;
rpcMsg
.
info
.
noResp
=
1
;
rpcMsg
.
contLen
=
strlen
(
configChange
)
+
1
;
rpcMsg
.
contLen
=
strlen
(
newconfig
)
+
1
;
rpcMsg
.
pCont
=
rpcMallocCont
(
rpcMsg
.
contLen
);
rpcMsg
.
pCont
=
rpcMallocCont
(
rpcMsg
.
contLen
);
snprintf
(
rpcMsg
.
pCont
,
rpcMsg
.
contLen
,
"%s"
,
configChange
);
snprintf
(
rpcMsg
.
pCont
,
rpcMsg
.
contLen
,
"%s"
,
newconfig
);
taosMemoryFree
(
configChange
);
taosMemoryFree
(
newconfig
);
ret
=
syncPropose
(
rid
,
&
rpcMsg
,
false
);
ret
=
syncPropose
(
rid
,
&
rpcMsg
,
false
);
return
ret
;
return
ret
;
}
}
int32_t
syncReconfigRaw
(
int64_t
rid
,
const
SSyncCfg
*
pNewCfg
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
ret
=
0
;
char
*
newconfig
=
syncCfg2Str
((
SSyncCfg
*
)
pNewCfg
);
pRpcMsg
->
msgType
=
TDMT_SYNC_CONFIG_CHANGE
;
pRpcMsg
->
info
.
noResp
=
1
;
pRpcMsg
->
contLen
=
strlen
(
newconfig
)
+
1
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
snprintf
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
"%s"
,
newconfig
);
taosMemoryFree
(
newconfig
);
return
ret
;
}
int32_t
syncForwardToPeer
(
int64_t
rid
,
const
SRpcMsg
*
pMsg
,
bool
isWeak
)
{
int32_t
syncForwardToPeer
(
int64_t
rid
,
const
SRpcMsg
*
pMsg
,
bool
isWeak
)
{
int32_t
ret
=
syncPropose
(
rid
,
pMsg
,
isWeak
);
int32_t
ret
=
syncPropose
(
rid
,
pMsg
,
isWeak
);
return
ret
;
return
ret
;
...
@@ -374,13 +393,14 @@ void setHeartbeatTimerMS(int64_t rid, int32_t hbTimerMS) {
...
@@ -374,13 +393,14 @@ void setHeartbeatTimerMS(int64_t rid, int32_t hbTimerMS) {
}
}
int32_t
syncPropose
(
int64_t
rid
,
const
SRpcMsg
*
pMsg
,
bool
isWeak
)
{
int32_t
syncPropose
(
int64_t
rid
,
const
SRpcMsg
*
pMsg
,
bool
isWeak
)
{
sTrace
(
"syncPropose msgType:%d "
,
pMsg
->
msgType
)
;
int32_t
ret
=
TAOS_SYNC_PROPOSE_SUCCESS
;
int32_t
ret
=
TAOS_SYNC_PROPOSE_SUCCESS
;
SSyncNode
*
pSyncNode
=
taosAcquireRef
(
tsNodeRefId
,
rid
);
SSyncNode
*
pSyncNode
=
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
return
TAOS_SYNC_PROPOSE_OTHER_ERROR
;
if
(
pSyncNode
==
NULL
)
{
return
TAOS_SYNC_PROPOSE_OTHER_ERROR
;
}
assert
(
rid
==
pSyncNode
->
rid
);
assert
(
rid
==
pSyncNode
->
rid
);
sTrace
(
"sync event vgId:%d propose msgType:%s"
,
pSyncNode
->
vgId
,
TMSG_INFO
(
pMsg
->
msgType
));
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
SRespStub
stub
;
SRespStub
stub
;
...
@@ -411,6 +431,8 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak) {
...
@@ -411,6 +431,8 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak) {
SSyncNode
*
syncNodeOpen
(
const
SSyncInfo
*
pOldSyncInfo
)
{
SSyncNode
*
syncNodeOpen
(
const
SSyncInfo
*
pOldSyncInfo
)
{
SSyncInfo
*
pSyncInfo
=
(
SSyncInfo
*
)
pOldSyncInfo
;
SSyncInfo
*
pSyncInfo
=
(
SSyncInfo
*
)
pOldSyncInfo
;
sInfo
(
"sync event vgId:%d sync open"
,
pSyncInfo
->
vgId
);
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosMemoryMalloc
(
sizeof
(
SSyncNode
));
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosMemoryMalloc
(
sizeof
(
SSyncNode
));
assert
(
pSyncNode
!=
NULL
);
assert
(
pSyncNode
!=
NULL
);
memset
(
pSyncNode
,
0
,
sizeof
(
SSyncNode
));
memset
(
pSyncNode
,
0
,
sizeof
(
SSyncNode
));
...
@@ -439,9 +461,11 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
...
@@ -439,9 +461,11 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
assert
(
pSyncNode
->
pRaftCfg
!=
NULL
);
assert
(
pSyncNode
->
pRaftCfg
!=
NULL
);
pSyncInfo
->
syncCfg
=
pSyncNode
->
pRaftCfg
->
cfg
;
pSyncInfo
->
syncCfg
=
pSyncNode
->
pRaftCfg
->
cfg
;
char
*
seralized
=
raftCfg2Str
(
pSyncNode
->
pRaftCfg
);
if
(
gRaftDetailLog
)
{
sInfo
(
"syncNodeOpen update config :%s"
,
seralized
);
char
*
seralized
=
raftCfg2Str
(
pSyncNode
->
pRaftCfg
);
taosMemoryFree
(
seralized
);
sInfo
(
"syncNodeOpen update config :%s"
,
seralized
);
taosMemoryFree
(
seralized
);
}
raftCfgClose
(
pSyncNode
->
pRaftCfg
);
raftCfgClose
(
pSyncNode
->
pRaftCfg
);
}
}
...
@@ -612,7 +636,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
...
@@ -612,7 +636,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
}
}
// snapshot receivers
// snapshot receivers
pSyncNode
->
pNewNodeReceiver
=
snapshotReceiverCreate
(
pSyncNode
,
100
);
pSyncNode
->
pNewNodeReceiver
=
snapshotReceiverCreate
(
pSyncNode
,
EMPTY_RAFT_ID
);
// start in syncNodeStart
// start in syncNodeStart
// start raft
// start raft
...
@@ -628,9 +652,7 @@ void syncNodeStart(SSyncNode* pSyncNode) {
...
@@ -628,9 +652,7 @@ void syncNodeStart(SSyncNode* pSyncNode) {
// start raft
// start raft
if
(
pSyncNode
->
replicaNum
==
1
)
{
if
(
pSyncNode
->
replicaNum
==
1
)
{
raftStoreNextTerm
(
pSyncNode
->
pRaftStore
);
raftStoreNextTerm
(
pSyncNode
->
pRaftStore
);
syncNodeBecomeLeader
(
pSyncNode
);
syncNodeBecomeLeader
(
pSyncNode
,
"one replica start"
);
syncNodeLog2
(
"==state change become leader immediately=="
,
pSyncNode
);
// Raft 3.6.2 Committing entries from previous terms
// Raft 3.6.2 Committing entries from previous terms
...
@@ -638,41 +660,22 @@ void syncNodeStart(SSyncNode* pSyncNode) {
...
@@ -638,41 +660,22 @@ void syncNodeStart(SSyncNode* pSyncNode) {
syncNodeAppendNoop
(
pSyncNode
);
syncNodeAppendNoop
(
pSyncNode
);
syncMaybeAdvanceCommitIndex
(
pSyncNode
);
// maybe only one replica
syncMaybeAdvanceCommitIndex
(
pSyncNode
);
// maybe only one replica
/*
if
(
gRaftDetailLog
)
{
sInfo("==syncNodeStart== RestoreFinish begin 1 replica tsem_wait %p", pSyncNode);
syncNodeLog2
(
"==state change become leader immediately=="
,
pSyncNode
);
tsem_wait(&pSyncNode->restoreSem);
sInfo("==syncNodeStart== RestoreFinish end 1 replica tsem_wait %p", pSyncNode);
*/
/*
while (pSyncNode->restoreFinish != true) {
taosMsleep(10);
}
}
*/
sInfo
(
"==syncNodeStart== restoreFinish ok 1 replica %p vgId:%d"
,
pSyncNode
,
pSyncNode
->
vgId
);
return
;
return
;
}
}
syncNodeBecomeFollower
(
pSyncNode
);
syncNodeBecomeFollower
(
pSyncNode
,
"first start"
);
// for test
// int32_t ret = 0;
int32_t
ret
=
0
;
// ret = syncNodeStartPingTimer(pSyncNode);
// ret = syncNodeStartPingTimer(pSyncNode);
assert
(
ret
==
0
);
// assert(ret == 0);
/*
sInfo("==syncNodeStart== RestoreFinish begin multi replica tsem_wait %p", pSyncNode);
tsem_wait(&pSyncNode->restoreSem);
sInfo("==syncNodeStart== RestoreFinish end multi replica tsem_wait %p", pSyncNode);
*/
/*
if
(
gRaftDetailLog
)
{
while (pSyncNode->restoreFinish != true) {
syncNodeLog2
(
"==state change become leader immediately=="
,
pSyncNode
);
taosMsleep(10);
}
}
*/
sInfo
(
"==syncNodeStart== restoreFinish ok multi replica %p vgId:%d"
,
pSyncNode
,
pSyncNode
->
vgId
);
}
}
void
syncNodeStartStandBy
(
SSyncNode
*
pSyncNode
)
{
void
syncNodeStartStandBy
(
SSyncNode
*
pSyncNode
)
{
...
@@ -687,6 +690,8 @@ void syncNodeStartStandBy(SSyncNode* pSyncNode) {
...
@@ -687,6 +690,8 @@ void syncNodeStartStandBy(SSyncNode* pSyncNode) {
}
}
void
syncNodeClose
(
SSyncNode
*
pSyncNode
)
{
void
syncNodeClose
(
SSyncNode
*
pSyncNode
)
{
sInfo
(
"sync event vgId:%d sync close"
,
pSyncNode
->
vgId
);
int32_t
ret
;
int32_t
ret
;
assert
(
pSyncNode
!=
NULL
);
assert
(
pSyncNode
!=
NULL
);
...
@@ -1131,7 +1136,10 @@ void syncNodeUpdateConfig(SSyncNode* pSyncNode, SSyncCfg* newConfig, bool* isDro
...
@@ -1131,7 +1136,10 @@ void syncNodeUpdateConfig(SSyncNode* pSyncNode, SSyncCfg* newConfig, bool* isDro
}
}
raftCfgPersist
(
pSyncNode
->
pRaftCfg
);
raftCfgPersist
(
pSyncNode
->
pRaftCfg
);
syncNodeLog2
(
"==syncNodeUpdateConfig=="
,
pSyncNode
);
if
(
gRaftDetailLog
)
{
syncNodeLog2
(
"==syncNodeUpdateConfig=="
,
pSyncNode
);
}
}
}
SSyncNode
*
syncNodeAcquire
(
int64_t
rid
)
{
SSyncNode
*
syncNodeAcquire
(
int64_t
rid
)
{
...
@@ -1149,12 +1157,14 @@ void syncNodeRelease(SSyncNode* pNode) { taosReleaseRef(tsNodeRefId, pNode->rid)
...
@@ -1149,12 +1157,14 @@ void syncNodeRelease(SSyncNode* pNode) { taosReleaseRef(tsNodeRefId, pNode->rid)
void
syncNodeUpdateTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
)
{
void
syncNodeUpdateTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
)
{
if
(
term
>
pSyncNode
->
pRaftStore
->
currentTerm
)
{
if
(
term
>
pSyncNode
->
pRaftStore
->
currentTerm
)
{
raftStoreSetTerm
(
pSyncNode
->
pRaftStore
,
term
);
raftStoreSetTerm
(
pSyncNode
->
pRaftStore
,
term
);
syncNodeBecomeFollower
(
pSyncNode
);
syncNodeBecomeFollower
(
pSyncNode
,
"update term"
);
raftStoreClearVote
(
pSyncNode
->
pRaftStore
);
raftStoreClearVote
(
pSyncNode
->
pRaftStore
);
}
}
}
}
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
)
{
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
,
const
char
*
debugStr
)
{
sInfo
(
"sync event vgId:%d become follower, %s"
,
pSyncNode
->
vgId
,
debugStr
);
// maybe clear leader cache
// maybe clear leader cache
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
pSyncNode
->
leaderCache
=
EMPTY_RAFT_ID
;
pSyncNode
->
leaderCache
=
EMPTY_RAFT_ID
;
...
@@ -1186,7 +1196,9 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode) {
...
@@ -1186,7 +1196,9 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode) {
// evoterLog |-> voterLog[i]]}
// evoterLog |-> voterLog[i]]}
// /\ UNCHANGED <<messages, currentTerm, votedFor, candidateVars, logVars>>
// /\ UNCHANGED <<messages, currentTerm, votedFor, candidateVars, logVars>>
//
//
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
)
{
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
,
const
char
*
debugStr
)
{
sInfo
(
"sync event vgId:%d become leader, %s"
,
pSyncNode
->
vgId
,
debugStr
);
// state change
// state change
pSyncNode
->
state
=
TAOS_SYNC_STATE_LEADER
;
pSyncNode
->
state
=
TAOS_SYNC_STATE_LEADER
;
...
@@ -1237,7 +1249,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode) {
...
@@ -1237,7 +1249,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode) {
void
syncNodeCandidate2Leader
(
SSyncNode
*
pSyncNode
)
{
void
syncNodeCandidate2Leader
(
SSyncNode
*
pSyncNode
)
{
assert
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_CANDIDATE
);
assert
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_CANDIDATE
);
assert
(
voteGrantedMajority
(
pSyncNode
->
pVotesGranted
));
assert
(
voteGrantedMajority
(
pSyncNode
->
pVotesGranted
));
syncNodeBecomeLeader
(
pSyncNode
);
syncNodeBecomeLeader
(
pSyncNode
,
"candidate to leader"
);
syncNodeLog2
(
"==state change syncNodeCandidate2Leader=="
,
pSyncNode
);
syncNodeLog2
(
"==state change syncNodeCandidate2Leader=="
,
pSyncNode
);
...
@@ -1260,14 +1272,14 @@ void syncNodeFollower2Candidate(SSyncNode* pSyncNode) {
...
@@ -1260,14 +1272,14 @@ void syncNodeFollower2Candidate(SSyncNode* pSyncNode) {
void
syncNodeLeader2Follower
(
SSyncNode
*
pSyncNode
)
{
void
syncNodeLeader2Follower
(
SSyncNode
*
pSyncNode
)
{
assert
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
);
assert
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
);
syncNodeBecomeFollower
(
pSyncNode
);
syncNodeBecomeFollower
(
pSyncNode
,
"leader to follower"
);
syncNodeLog2
(
"==state change syncNodeLeader2Follower=="
,
pSyncNode
);
syncNodeLog2
(
"==state change syncNodeLeader2Follower=="
,
pSyncNode
);
}
}
void
syncNodeCandidate2Follower
(
SSyncNode
*
pSyncNode
)
{
void
syncNodeCandidate2Follower
(
SSyncNode
*
pSyncNode
)
{
assert
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_CANDIDATE
);
assert
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_CANDIDATE
);
syncNodeBecomeFollower
(
pSyncNode
);
syncNodeBecomeFollower
(
pSyncNode
,
"candidate to follower"
);
syncNodeLog2
(
"==state change syncNodeCandidate2Follower=="
,
pSyncNode
);
syncNodeLog2
(
"==state change syncNodeCandidate2Follower=="
,
pSyncNode
);
}
}
...
@@ -1467,9 +1479,11 @@ void syncNodeLog(SSyncNode* pObj) {
...
@@ -1467,9 +1479,11 @@ void syncNodeLog(SSyncNode* pObj) {
}
}
void
syncNodeLog2
(
char
*
s
,
SSyncNode
*
pObj
)
{
void
syncNodeLog2
(
char
*
s
,
SSyncNode
*
pObj
)
{
char
*
serialized
=
syncNode2Str
(
pObj
);
if
(
gRaftDetailLog
)
{
sTraceLong
(
"syncNodeLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
char
*
serialized
=
syncNode2Str
(
pObj
);
taosMemoryFree
(
serialized
);
sTraceLong
(
"syncNodeLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
}
}
// ------ local funciton ---------
// ------ local funciton ---------
...
@@ -1724,17 +1738,19 @@ const char* syncStr(ESyncState state) {
...
@@ -1724,17 +1738,19 @@ const char* syncStr(ESyncState state) {
int32_t
syncNodeCommit
(
SSyncNode
*
ths
,
SyncIndex
beginIndex
,
SyncIndex
endIndex
,
uint64_t
flag
)
{
int32_t
syncNodeCommit
(
SSyncNode
*
ths
,
SyncIndex
beginIndex
,
SyncIndex
endIndex
,
uint64_t
flag
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
ESyncState
state
=
flag
;
ESyncState
state
=
flag
;
sInfo
(
"sync event
commit from index:%"
PRId64
" to index:%"
PRId64
", %s"
,
beginIndex
,
end
Index
,
sInfo
(
"sync event
vgId:%d commit by wal from index:%"
PRId64
" to index:%"
PRId64
", %s"
,
ths
->
vgId
,
begin
Index
,
syncUtilState2String
(
state
));
endIndex
,
syncUtilState2String
(
state
));
// maybe execute by leader, skip snapshot
/*
SSnapshot
snapshot
=
{.
data
=
NULL
,
.
lastApplyIndex
=
-
1
,
.
lastApplyTerm
=
0
};
// maybe execute by leader, skip snapshot
if
(
ths
->
pFsm
->
FpGetSnapshot
!=
NULL
)
{
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
ths
->
pFsm
->
FpGetSnapshot
(
ths
->
pFsm
,
&
snapshot
);
if (ths->pFsm->FpGetSnapshot != NULL) {
}
ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot);
if
(
beginIndex
<=
snapshot
.
lastApplyIndex
)
{
}
beginIndex
=
snapshot
.
lastApplyIndex
+
1
;
if (beginIndex <= snapshot.lastApplyIndex) {
}
beginIndex = snapshot.lastApplyIndex + 1;
}
*/
// execute fsm
// execute fsm
if
(
ths
->
pFsm
!=
NULL
)
{
if
(
ths
->
pFsm
!=
NULL
)
{
...
@@ -1791,17 +1807,19 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
...
@@ -1791,17 +1807,19 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
// change isStandBy to normal
// change isStandBy to normal
if
(
!
isDrop
)
{
if
(
!
isDrop
)
{
if
(
ths
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
if
(
ths
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
syncNodeBecomeLeader
(
ths
);
syncNodeBecomeLeader
(
ths
,
"config change"
);
}
else
{
}
else
{
syncNodeBecomeFollower
(
ths
);
syncNodeBecomeFollower
(
ths
,
"config change"
);
}
}
}
}
char
*
sOld
=
syncCfg2Str
(
&
oldSyncCfg
);
if
(
gRaftDetailLog
)
{
char
*
sNew
=
syncCfg2Str
(
&
newSyncCfg
);
char
*
sOld
=
syncCfg2Str
(
&
oldSyncCfg
);
sInfo
(
"==config change== 0x11 old:%s new:%s isDrop:%d
\n
"
,
sOld
,
sNew
,
isDrop
);
char
*
sNew
=
syncCfg2Str
(
&
newSyncCfg
);
taosMemoryFree
(
sOld
);
sInfo
(
"==config change== 0x11 old:%s new:%s isDrop:%d
\n
"
,
sOld
,
sNew
,
isDrop
);
taosMemoryFree
(
sNew
);
taosMemoryFree
(
sOld
);
taosMemoryFree
(
sNew
);
}
}
}
// always call FpReConfigCb
// always call FpReConfigCb
...
@@ -1810,10 +1828,12 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
...
@@ -1810,10 +1828,12 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
cbMeta
.
currentTerm
=
ths
->
pRaftStore
->
currentTerm
;
cbMeta
.
currentTerm
=
ths
->
pRaftStore
->
currentTerm
;
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
term
=
pEntry
->
term
;
cbMeta
.
term
=
pEntry
->
term
;
cbMeta
.
newCfg
=
newSyncCfg
;
cbMeta
.
oldCfg
=
oldSyncCfg
;
cbMeta
.
oldCfg
=
oldSyncCfg
;
cbMeta
.
seqNum
=
pEntry
->
seqNum
;
cbMeta
.
flag
=
0x11
;
cbMeta
.
flag
=
0x11
;
cbMeta
.
isDrop
=
isDrop
;
cbMeta
.
isDrop
=
isDrop
;
ths
->
pFsm
->
FpReConfigCb
(
ths
->
pFsm
,
newSyncCf
g
,
cbMeta
);
ths
->
pFsm
->
FpReConfigCb
(
ths
->
pFsm
,
&
rpcMs
g
,
cbMeta
);
}
}
}
}
...
@@ -1824,7 +1844,7 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
...
@@ -1824,7 +1844,7 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
ths
->
pFsm
->
FpRestoreFinishCb
(
ths
->
pFsm
);
ths
->
pFsm
->
FpRestoreFinishCb
(
ths
->
pFsm
);
}
}
ths
->
restoreFinish
=
true
;
ths
->
restoreFinish
=
true
;
sInfo
(
"
restore finish %p vgId:%d"
,
ths
,
ths
->
vgId
);
sInfo
(
"
sync event vgId:%d restore finish"
,
ths
->
vgId
);
}
}
}
}
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
7923d51f
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
*/
*/
#include "syncRaftLog.h"
#include "syncRaftLog.h"
#include "syncRaftCfg.h"
#include "wal.h"
#include "wal.h"
// refactor, log[0 .. n] ==> log[m .. n]
// refactor, log[0 .. n] ==> log[m .. n]
...
@@ -161,7 +162,9 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
...
@@ -161,7 +162,9 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
walFsync
(
pWal
,
true
);
walFsync
(
pWal
,
true
);
sTrace
(
"sync event write index:%"
PRId64
,
pEntry
->
index
);
sTrace
(
"sync event vgId:%d write index:%ld, %s, isStandBy:%d, msgType:%s, originalRpcType:%s"
,
pData
->
pSyncNode
->
vgId
,
pEntry
->
index
,
syncUtilState2String
(
pData
->
pSyncNode
->
state
),
pData
->
pSyncNode
->
pRaftCfg
->
isStandBy
,
TMSG_INFO
(
pEntry
->
msgType
),
TMSG_INFO
(
pEntry
->
originalRpcType
));
return
code
;
return
code
;
}
}
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
7923d51f
...
@@ -122,7 +122,7 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) {
...
@@ -122,7 +122,7 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) {
syncIndexMgrLog2
(
"begin append entries peers pNextIndex:"
,
pSyncNode
->
pNextIndex
);
syncIndexMgrLog2
(
"begin append entries peers pNextIndex:"
,
pSyncNode
->
pNextIndex
);
syncIndexMgrLog2
(
"begin append entries peers pMatchIndex:"
,
pSyncNode
->
pMatchIndex
);
syncIndexMgrLog2
(
"begin append entries peers pMatchIndex:"
,
pSyncNode
->
pMatchIndex
);
logStoreSimpleLog2
(
"begin append entries peers LogStore:"
,
pSyncNode
->
pLogStore
);
logStoreSimpleLog2
(
"begin append entries peers LogStore:"
,
pSyncNode
->
pLogStore
);
{
if
(
gRaftDetailLog
)
{
SSnapshot
snapshot
;
SSnapshot
snapshot
;
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSyncNode
->
pFsm
,
&
snapshot
);
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSyncNode
->
pFsm
,
&
snapshot
);
sTrace
(
"begin append entries peers, snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu"
,
sTrace
(
"begin append entries peers, snapshot.lastApplyIndex:%ld, snapshot.lastApplyTerm:%lu"
,
...
@@ -201,7 +201,6 @@ int32_t syncNodeReplicate(SSyncNode* pSyncNode) {
...
@@ -201,7 +201,6 @@ int32_t syncNodeReplicate(SSyncNode* pSyncNode) {
}
}
int32_t
syncNodeAppendEntries
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncAppendEntries
*
pMsg
)
{
int32_t
syncNodeAppendEntries
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncAppendEntries
*
pMsg
)
{
sTrace
(
"syncNodeAppendEntries pSyncNode:%p "
,
pSyncNode
);
int32_t
ret
=
0
;
int32_t
ret
=
0
;
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
7923d51f
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
#include "syncUtil.h"
#include "syncUtil.h"
#include "wal.h"
#include "wal.h"
static
void
snapshotReceiverDoStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
);
static
void
snapshotReceiverDoStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
,
SRaftId
fromId
);
//----------------------------------
//----------------------------------
SSyncSnapshotSender
*
snapshotSenderCreate
(
SSyncNode
*
pSyncNode
,
int32_t
replicaIndex
)
{
SSyncSnapshotSender
*
snapshotSenderCreate
(
SSyncNode
*
pSyncNode
,
int32_t
replicaIndex
)
{
...
@@ -105,13 +105,23 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender) {
...
@@ -105,13 +105,23 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender) {
syncSnapshotSend2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncSnapshotSend2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
char
host
[
128
];
char
host
[
128
];
uint16_t
port
;
uint16_t
port
;
syncUtilU642Addr
(
pSender
->
pSyncNode
->
replicasId
[
pSender
->
replicaIndex
].
addr
,
host
,
sizeof
(
host
),
&
port
);
syncUtilU642Addr
(
pSender
->
pSyncNode
->
replicasId
[
pSender
->
replicaIndex
].
addr
,
host
,
sizeof
(
host
),
&
port
);
sTrace
(
"sync event snapshot send to %s:%d begin seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu send msg:%s"
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
msgStr
);
if
(
gRaftDetailLog
)
{
taosMemoryFree
(
msgStr
);
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
sTrace
(
"sync event vgId:%d snapshot send to %s:%d begin seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu send "
"msg:%s"
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
{
sTrace
(
"sync event vgId:%d snapshot send to %s:%d begin seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu"
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
);
}
syncSnapshotSendDestroy
(
pMsg
);
syncSnapshotSendDestroy
(
pMsg
);
}
}
...
@@ -183,9 +193,11 @@ void snapshotSenderStop(SSyncSnapshotSender *pSender) {
...
@@ -183,9 +193,11 @@ void snapshotSenderStop(SSyncSnapshotSender *pSender) {
pSender
->
start
=
false
;
pSender
->
start
=
false
;
char
*
s
=
snapshotSender2Str
(
pSender
);
if
(
gRaftDetailLog
)
{
sInfo
(
"snapshotSenderStop %s"
,
s
);
char
*
s
=
snapshotSender2Str
(
pSender
);
taosMemoryFree
(
s
);
sInfo
(
"snapshotSenderStop %s"
,
s
);
taosMemoryFree
(
s
);
}
}
}
// when sender receiver ack, call this function to send msg from seq
// when sender receiver ack, call this function to send msg from seq
...
@@ -225,20 +237,29 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
...
@@ -225,20 +237,29 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
syncSnapshotSend2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncSnapshotSend2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
char
host
[
128
];
char
host
[
128
];
uint16_t
port
;
uint16_t
port
;
syncUtilU642Addr
(
pSender
->
pSyncNode
->
replicasId
[
pSender
->
replicaIndex
].
addr
,
host
,
sizeof
(
host
),
&
port
);
syncUtilU642Addr
(
pSender
->
pSyncNode
->
replicasId
[
pSender
->
replicaIndex
].
addr
,
host
,
sizeof
(
host
),
&
port
);
if
(
pSender
->
seq
==
SYNC_SNAPSHOT_SEQ_END
)
{
if
(
pSender
->
seq
==
SYNC_SNAPSHOT_SEQ_END
)
{
sTrace
(
"sync event snapshot send to %s:%d finish seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu send msg:%s"
,
if
(
gRaftDetailLog
)
{
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
msgStr
);
sTrace
(
"sync event vgId:%d snapshot send to %s:%d finish seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu send "
"msg:%s"
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
{
sTrace
(
"sync event vgId:%d snapshot send to %s:%d finish seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu"
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
);
}
}
else
{
}
else
{
sTrace
(
"sync event
snapshot send to %s:%d sending seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu send msg:%s
"
,
sTrace
(
"sync event
vgId:%d snapshot send to %s:%d sending seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu
"
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
msgStr
);
pSender
->
snapshot
.
lastApplyTerm
);
}
}
taosMemoryFree
(
msgStr
);
syncSnapshotSendDestroy
(
pMsg
);
syncSnapshotSendDestroy
(
pMsg
);
return
0
;
return
0
;
...
@@ -260,13 +281,19 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
...
@@ -260,13 +281,19 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
syncSnapshotSend2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncSnapshotSend2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
char
host
[
128
];
char
host
[
128
];
uint16_t
port
;
uint16_t
port
;
syncUtilU642Addr
(
pSender
->
pSyncNode
->
replicasId
[
pSender
->
replicaIndex
].
addr
,
host
,
sizeof
(
host
),
&
port
);
syncUtilU642Addr
(
pSender
->
pSyncNode
->
replicasId
[
pSender
->
replicaIndex
].
addr
,
host
,
sizeof
(
host
),
&
port
);
sTrace
(
"sync event snapshot send to %s:%d resend seq:%d ack:%d send msg:%s"
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
msgStr
);
if
(
gRaftDetailLog
)
{
taosMemoryFree
(
msgStr
);
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
sTrace
(
"sync event vgId:%d snapshot send to %s:%d resend seq:%d ack:%d send msg:%s"
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
{
sTrace
(
"sync event vgId:%d snapshot send to %s:%d resend seq:%d ack:%d"
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
);
}
syncSnapshotSendDestroy
(
pMsg
);
syncSnapshotSendDestroy
(
pMsg
);
}
}
...
@@ -331,7 +358,7 @@ char *snapshotSender2Str(SSyncSnapshotSender *pSender) {
...
@@ -331,7 +358,7 @@ char *snapshotSender2Str(SSyncSnapshotSender *pSender) {
}
}
// -------------------------------------
// -------------------------------------
SSyncSnapshotReceiver
*
snapshotReceiverCreate
(
SSyncNode
*
pSyncNode
,
int32_t
replicaIndex
)
{
SSyncSnapshotReceiver
*
snapshotReceiverCreate
(
SSyncNode
*
pSyncNode
,
SRaftId
fromId
)
{
bool
condition
=
(
pSyncNode
->
pFsm
->
FpSnapshotStartWrite
!=
NULL
)
&&
(
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
!=
NULL
)
&&
bool
condition
=
(
pSyncNode
->
pFsm
->
FpSnapshotStartWrite
!=
NULL
)
&&
(
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
!=
NULL
)
&&
(
pSyncNode
->
pFsm
->
FpSnapshotDoWrite
!=
NULL
);
(
pSyncNode
->
pFsm
->
FpSnapshotDoWrite
!=
NULL
);
...
@@ -345,7 +372,7 @@ SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, int32_t repl
...
@@ -345,7 +372,7 @@ SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, int32_t repl
pReceiver
->
ack
=
SYNC_SNAPSHOT_SEQ_BEGIN
;
pReceiver
->
ack
=
SYNC_SNAPSHOT_SEQ_BEGIN
;
pReceiver
->
pWriter
=
NULL
;
pReceiver
->
pWriter
=
NULL
;
pReceiver
->
pSyncNode
=
pSyncNode
;
pReceiver
->
pSyncNode
=
pSyncNode
;
pReceiver
->
replicaIndex
=
replicaIndex
;
pReceiver
->
fromId
=
fromId
;
pReceiver
->
term
=
pSyncNode
->
pRaftStore
->
currentTerm
;
pReceiver
->
term
=
pSyncNode
->
pRaftStore
->
currentTerm
;
pReceiver
->
privateTerm
=
0
;
pReceiver
->
privateTerm
=
0
;
...
@@ -365,10 +392,11 @@ void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver) {
...
@@ -365,10 +392,11 @@ void snapshotReceiverDestroy(SSyncSnapshotReceiver *pReceiver) {
bool
snapshotReceiverIsStart
(
SSyncSnapshotReceiver
*
pReceiver
)
{
return
pReceiver
->
start
;
}
bool
snapshotReceiverIsStart
(
SSyncSnapshotReceiver
*
pReceiver
)
{
return
pReceiver
->
start
;
}
// begin receive snapshot msg (current term, seq begin)
// begin receive snapshot msg (current term, seq begin)
static
void
snapshotReceiverDoStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
)
{
static
void
snapshotReceiverDoStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
,
SRaftId
fromId
)
{
pReceiver
->
term
=
pReceiver
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pReceiver
->
term
=
pReceiver
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pReceiver
->
privateTerm
=
privateTerm
;
pReceiver
->
privateTerm
=
privateTerm
;
pReceiver
->
ack
=
SYNC_SNAPSHOT_SEQ_BEGIN
;
pReceiver
->
ack
=
SYNC_SNAPSHOT_SEQ_BEGIN
;
pReceiver
->
fromId
=
fromId
;
ASSERT
(
pReceiver
->
pWriter
==
NULL
);
ASSERT
(
pReceiver
->
pWriter
==
NULL
);
int32_t
ret
=
pReceiver
->
pSyncNode
->
pFsm
->
FpSnapshotStartWrite
(
pReceiver
->
pSyncNode
->
pFsm
,
&
(
pReceiver
->
pWriter
));
int32_t
ret
=
pReceiver
->
pSyncNode
->
pFsm
->
FpSnapshotStartWrite
(
pReceiver
->
pSyncNode
->
pFsm
,
&
(
pReceiver
->
pWriter
));
...
@@ -377,14 +405,15 @@ static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm p
...
@@ -377,14 +405,15 @@ static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm p
// if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver
// if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver
// if already start, force close, start again
// if already start, force close, start again
void
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
)
{
void
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
,
SRaftId
fromId
)
{
if
(
!
snapshotReceiverIsStart
(
pReceiver
))
{
if
(
!
snapshotReceiverIsStart
(
pReceiver
))
{
// start
// start
snapshotReceiverDoStart
(
pReceiver
,
privateTerm
);
snapshotReceiverDoStart
(
pReceiver
,
privateTerm
,
fromId
);
pReceiver
->
start
=
true
;
pReceiver
->
start
=
true
;
}
else
{
}
else
{
// already start
// already start
sInfo
(
"snapshot recv, receiver already start"
);
// force close, abandon incomplete data
// force close, abandon incomplete data
int32_t
ret
=
int32_t
ret
=
...
@@ -393,15 +422,15 @@ void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTer
...
@@ -393,15 +422,15 @@ void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTer
pReceiver
->
pWriter
=
NULL
;
pReceiver
->
pWriter
=
NULL
;
// start again
// start again
snapshotReceiverDoStart
(
pReceiver
,
privateTerm
);
snapshotReceiverDoStart
(
pReceiver
,
privateTerm
,
fromId
);
pReceiver
->
start
=
true
;
pReceiver
->
start
=
true
;
ASSERT
(
0
);
}
}
char
*
s
=
snapshotReceiver2Str
(
pReceiver
);
if
(
gRaftDetailLog
)
{
sInfo
(
"snapshotReceiverStart %s"
,
s
);
char
*
s
=
snapshotReceiver2Str
(
pReceiver
);
taosMemoryFree
(
s
);
sInfo
(
"snapshotReceiverStart %s"
,
s
);
taosMemoryFree
(
s
);
}
}
}
void
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
,
bool
apply
)
{
void
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
,
bool
apply
)
{
...
@@ -418,9 +447,11 @@ void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver, bool apply) {
...
@@ -418,9 +447,11 @@ void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver, bool apply) {
++
(
pReceiver
->
privateTerm
);
++
(
pReceiver
->
privateTerm
);
}
}
char
*
s
=
snapshotReceiver2Str
(
pReceiver
);
if
(
gRaftDetailLog
)
{
sInfo
(
"snapshotReceiverStop %s"
,
s
);
char
*
s
=
snapshotReceiver2Str
(
pReceiver
);
taosMemoryFree
(
s
);
sInfo
(
"snapshotReceiverStop %s"
,
s
);
taosMemoryFree
(
s
);
}
}
}
cJSON
*
snapshotReceiver2Json
(
SSyncSnapshotReceiver
*
pReceiver
)
{
cJSON
*
snapshotReceiver2Json
(
SSyncSnapshotReceiver
*
pReceiver
)
{
...
@@ -436,7 +467,22 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
...
@@ -436,7 +467,22 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pReceiver
->
pSyncNode
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pReceiver
->
pSyncNode
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"replicaIndex"
,
pReceiver
->
replicaIndex
);
cJSON
*
pFromId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pReceiver
->
fromId
.
addr
);
cJSON_AddStringToObject
(
pFromId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pReceiver
->
fromId
.
addr
;
cJSON
*
pTmp
=
pFromId
;
char
host
[
128
]
=
{
0
};
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
cJSON_AddNumberToObject
(
pFromId
,
"vgId"
,
pReceiver
->
fromId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"fromId"
,
pFromId
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pReceiver
->
term
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pReceiver
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
...
@@ -468,17 +514,23 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
...
@@ -468,17 +514,23 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
if
(
pMsg
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
)
{
if
(
pMsg
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
)
{
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_BEGIN
)
{
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_BEGIN
)
{
// begin
// begin
snapshotReceiverStart
(
pReceiver
,
pMsg
->
privateTerm
);
snapshotReceiverStart
(
pReceiver
,
pMsg
->
privateTerm
,
pMsg
->
srcId
);
pReceiver
->
ack
=
pMsg
->
seq
;
pReceiver
->
ack
=
pMsg
->
seq
;
needRsp
=
true
;
needRsp
=
true
;
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
char
host
[
128
];
char
host
[
128
];
uint16_t
port
;
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sTrace
(
"sync event snapshot recv from %s:%d begin ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
host
,
port
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
if
(
gRaftDetailLog
)
{
taosMemoryFree
(
msgStr
);
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
sTrace
(
"sync event vgId:%d snapshot recv from %s:%d begin ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
pSyncNode
->
vgId
,
host
,
port
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
{
sTrace
(
"sync event vgId:%d snapshot recv from %s:%d begin ack:%d, lastIndex:%ld, lastTerm:%lu"
,
pSyncNode
->
vgId
,
host
,
port
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
);
}
}
else
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_END
)
{
}
else
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_END
)
{
// end, finish FSM
// end, finish FSM
...
@@ -486,29 +538,46 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
...
@@ -486,29 +538,46 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
ASSERT
(
writeCode
==
0
);
ASSERT
(
writeCode
==
0
);
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
(
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
true
);
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
(
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
true
);
pSyncNode
->
pLogStore
->
syncLogSetBeginIndex
(
pSyncNode
->
pLogStore
,
pMsg
->
lastIndex
+
1
);
pSyncNode
->
pLogStore
->
syncLogSetBeginIndex
(
pSyncNode
->
pLogStore
,
pMsg
->
lastIndex
+
1
);
char
*
logSimpleStr
=
logStoreSimple2Str
(
pSyncNode
->
pLogStore
);
SSnapshot
snapshot
;
SSnapshot
snapshot
;
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSyncNode
->
pFsm
,
&
snapshot
);
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSyncNode
->
pFsm
,
&
snapshot
);
char
host
[
128
];
char
host
[
128
];
uint16_t
port
;
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sInfo
(
"sync event snapshot recv from %s:%d finish, update log begin index:%ld, snapshot.lastApplyIndex:%ld, "
if
(
gRaftDetailLog
)
{
"snapshot.lastApplyTerm:%lu, raft log:%s"
,
char
*
logSimpleStr
=
logStoreSimple2Str
(
pSyncNode
->
pLogStore
);
host
,
port
,
pMsg
->
lastIndex
+
1
,
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
,
logSimpleStr
);
sInfo
(
taosMemoryFree
(
logSimpleStr
);
"sync event vgId:%d snapshot recv from %s:%d finish, update log begin index:%ld, "
"snapshot.lastApplyIndex:%ld, "
"snapshot.lastApplyTerm:%lu, raft log:%s"
,
pSyncNode
->
vgId
,
host
,
port
,
pMsg
->
lastIndex
+
1
,
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
,
logSimpleStr
);
taosMemoryFree
(
logSimpleStr
);
}
else
{
sInfo
(
"sync event vgId:%d snapshot recv from %s:%d finish, update log begin index:%ld, "
"snapshot.lastApplyIndex:%ld, "
"snapshot.lastApplyTerm:%lu"
,
pSyncNode
->
vgId
,
host
,
port
,
pMsg
->
lastIndex
+
1
,
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
);
}
pReceiver
->
pWriter
=
NULL
;
pReceiver
->
pWriter
=
NULL
;
snapshotReceiverStop
(
pReceiver
,
true
);
snapshotReceiverStop
(
pReceiver
,
true
);
pReceiver
->
ack
=
pMsg
->
seq
;
pReceiver
->
ack
=
pMsg
->
seq
;
needRsp
=
true
;
needRsp
=
true
;
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
if
(
gRaftDetailLog
)
{
sTrace
(
"sync event snapshot recv from %s:%d end ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
host
,
port
,
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
sTrace
(
"sync event vgId:%d snapshot recv from %s:%d end ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
taosMemoryFree
(
msgStr
);
pReceiver
->
pSyncNode
->
vgId
,
host
,
port
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
{
sTrace
(
"sync event vgId:%d snapshot recv from %s:%d end ack:%d, lastIndex:%ld, lastTerm:%lu"
,
pReceiver
->
pSyncNode
->
vgId
,
host
,
port
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
);
}
}
else
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_FORCE_CLOSE
)
{
}
else
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_FORCE_CLOSE
)
{
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
(
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
false
);
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
(
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
false
);
...
@@ -519,11 +588,17 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
...
@@ -519,11 +588,17 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
uint16_t
port
;
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
if
(
gRaftDetailLog
)
{
sTrace
(
"sync event snapshot recv from %s:%d force close ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
host
,
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
port
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
sTrace
(
"sync event vgId:%d snapshot recv from %s:%d force close ack:%d, lastIndex:%ld, lastTerm:%lu, recv "
taosMemoryFree
(
msgStr
);
"msg:%s"
,
pReceiver
->
pSyncNode
->
vgId
,
host
,
port
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
{
sTrace
(
"sync event vgId:%d snapshot recv from %s:%d force close ack:%d, lastIndex:%ld, lastTerm:%lu"
,
pReceiver
->
pSyncNode
->
vgId
,
host
,
port
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
);
}
}
else
if
(
pMsg
->
seq
>
SYNC_SNAPSHOT_SEQ_BEGIN
&&
pMsg
->
seq
<
SYNC_SNAPSHOT_SEQ_END
)
{
}
else
if
(
pMsg
->
seq
>
SYNC_SNAPSHOT_SEQ_BEGIN
&&
pMsg
->
seq
<
SYNC_SNAPSHOT_SEQ_END
)
{
// transfering
// transfering
...
@@ -535,13 +610,20 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
...
@@ -535,13 +610,20 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
}
}
needRsp
=
true
;
needRsp
=
true
;
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
char
host
[
128
];
char
host
[
128
];
uint16_t
port
;
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sTrace
(
"sync event snapshot recv from %s:%d receiving ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
host
,
port
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
if
(
gRaftDetailLog
)
{
taosMemoryFree
(
msgStr
);
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
sTrace
(
"sync event vgId:%d snapshot recv from %s:%d receiving ack:%d, lastIndex:%ld, lastTerm:%lu, recv msg:%s"
,
pSyncNode
->
vgId
,
host
,
port
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
{
sTrace
(
"sync event vgId:%d snapshot recv from %s:%d receiving ack:%d, lastIndex:%ld, lastTerm:%lu"
,
pSyncNode
->
vgId
,
host
,
port
,
pReceiver
->
ack
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
);
}
}
else
{
}
else
{
ASSERT
(
0
);
ASSERT
(
0
);
...
...
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
浏览文件 @
7923d51f
...
@@ -146,7 +146,7 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
...
@@ -146,7 +146,7 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
void
RestoreFinishCb
(
struct
SSyncFSM
*
pFsm
)
{
sTrace
(
"==callback== ==RestoreFinishCb=="
);
}
void
RestoreFinishCb
(
struct
SSyncFSM
*
pFsm
)
{
sTrace
(
"==callback== ==RestoreFinishCb=="
);
}
void
ReConfigCb
(
struct
SSyncFSM
*
pFsm
,
SSyncCfg
newCf
g
,
SReConfigCbMeta
cbMeta
)
{
void
ReConfigCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMs
g
,
SReConfigCbMeta
cbMeta
)
{
sTrace
(
"==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu"
,
sTrace
(
"==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu"
,
cbMeta
.
flag
,
cbMeta
.
isDrop
,
cbMeta
.
index
,
cbMeta
.
code
,
cbMeta
.
currentTerm
,
cbMeta
.
term
);
cbMeta
.
flag
,
cbMeta
.
isDrop
,
cbMeta
.
index
,
cbMeta
.
code
,
cbMeta
.
currentTerm
,
cbMeta
.
term
);
}
}
...
...
source/libs/sync/test/syncConfigChangeTest.cpp
浏览文件 @
7923d51f
...
@@ -77,7 +77,7 @@ int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) {
...
@@ -77,7 +77,7 @@ int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) {
void
RestoreFinishCb
(
struct
SSyncFSM
*
pFsm
)
{
sTrace
(
"==callback== ==RestoreFinishCb=="
);
}
void
RestoreFinishCb
(
struct
SSyncFSM
*
pFsm
)
{
sTrace
(
"==callback== ==RestoreFinishCb=="
);
}
void
ReConfigCb
(
struct
SSyncFSM
*
pFsm
,
SSyncCfg
newCf
g
,
SReConfigCbMeta
cbMeta
)
{
void
ReConfigCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMs
g
,
SReConfigCbMeta
cbMeta
)
{
sTrace
(
"==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu"
,
sTrace
(
"==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu"
,
cbMeta
.
flag
,
cbMeta
.
isDrop
,
cbMeta
.
index
,
cbMeta
.
code
,
cbMeta
.
currentTerm
,
cbMeta
.
term
);
cbMeta
.
flag
,
cbMeta
.
isDrop
,
cbMeta
.
index
,
cbMeta
.
code
,
cbMeta
.
currentTerm
,
cbMeta
.
term
);
}
}
...
...
source/libs/sync/test/syncSnapshotReceiverTest.cpp
浏览文件 @
7923d51f
...
@@ -41,7 +41,11 @@ SSyncSnapshotReceiver* createReceiver() {
...
@@ -41,7 +41,11 @@ SSyncSnapshotReceiver* createReceiver() {
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
=
SnapshotStopWrite
;
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
=
SnapshotStopWrite
;
pSyncNode
->
pFsm
->
FpSnapshotDoWrite
=
SnapshotDoWrite
;
pSyncNode
->
pFsm
->
FpSnapshotDoWrite
=
SnapshotDoWrite
;
SSyncSnapshotReceiver
*
pReceiver
=
snapshotReceiverCreate
(
pSyncNode
,
2
);
SRaftId
id
;
id
.
addr
=
syncUtilAddr2U64
(
"1.2.3.4"
,
99
);
id
.
vgId
=
100
;
SSyncSnapshotReceiver
*
pReceiver
=
snapshotReceiverCreate
(
pSyncNode
,
id
);
pReceiver
->
start
=
true
;
pReceiver
->
start
=
true
;
pReceiver
->
ack
=
20
;
pReceiver
->
ack
=
20
;
pReceiver
->
pWriter
=
(
void
*
)
0x11
;
pReceiver
->
pWriter
=
(
void
*
)
0x11
;
...
...
source/libs/sync/test/syncTestTool.cpp
浏览文件 @
7923d51f
...
@@ -146,8 +146,8 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
...
@@ -146,8 +146,8 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
void
RestoreFinishCb
(
struct
SSyncFSM
*
pFsm
)
{
sTrace
(
"==callback== ==RestoreFinishCb== pFsm:%p"
,
pFsm
);
}
void
RestoreFinishCb
(
struct
SSyncFSM
*
pFsm
)
{
sTrace
(
"==callback== ==RestoreFinishCb== pFsm:%p"
,
pFsm
);
}
void
ReConfigCb
(
struct
SSyncFSM
*
pFsm
,
SSyncCfg
newCf
g
,
SReConfigCbMeta
cbMeta
)
{
void
ReConfigCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMs
g
,
SReConfigCbMeta
cbMeta
)
{
char
*
s
=
syncCfg2Str
(
&
newCfg
);
char
*
s
=
syncCfg2Str
(
&
(
cbMeta
.
newCfg
)
);
sTrace
(
"==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu, newCfg:%s"
,
sTrace
(
"==callback== ==ReConfigCb== flag:0x%lX, isDrop:%d, index:%ld, code:%d, currentTerm:%lu, term:%lu, newCfg:%s"
,
cbMeta
.
flag
,
cbMeta
.
isDrop
,
cbMeta
.
index
,
cbMeta
.
code
,
cbMeta
.
currentTerm
,
cbMeta
.
term
,
s
);
cbMeta
.
flag
,
cbMeta
.
isDrop
,
cbMeta
.
index
,
cbMeta
.
code
,
cbMeta
.
currentTerm
,
cbMeta
.
term
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
...
@@ -235,7 +235,6 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal*
...
@@ -235,7 +235,6 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal*
}
}
}
}
int64_t
rid
=
syncOpen
(
&
syncInfo
);
int64_t
rid
=
syncOpen
(
&
syncInfo
);
assert
(
rid
>
0
);
assert
(
rid
>
0
);
...
...
source/util/src/terror.c
浏览文件 @
7923d51f
...
@@ -90,7 +90,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_RPC_AUTH_FAILURE, "Authentication failur
...
@@ -90,7 +90,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_RPC_AUTH_FAILURE, "Authentication failur
TAOS_DEFINE_ERROR
(
TSDB_CODE_RPC_NETWORK_UNAVAIL
,
"Unable to establish connection"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_RPC_NETWORK_UNAVAIL
,
"Unable to establish connection"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_RPC_FQDN_ERROR
,
"Unable to resolve FQDN"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_RPC_FQDN_ERROR
,
"Unable to resolve FQDN"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_RPC_PORT_EADDRINUSE
,
"Port already in use"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_RPC_PORT_EADDRINUSE
,
"Port already in use"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_RPC_INDIRECT_NETWORK_UNAVAIL
,
"Unable to establish connection"
)
//client
//client
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSC_INVALID_OPERATION
,
"Invalid operation"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSC_INVALID_OPERATION
,
"Invalid operation"
)
...
@@ -225,6 +224,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_IN_DNODE, "Vgroup not in dnode")
...
@@ -225,6 +224,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_IN_DNODE, "Vgroup not in dnode")
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_VGROUP_NOT_EXIST
,
"Vgroup does not exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_VGROUP_NOT_EXIST
,
"Vgroup does not exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_VGROUP_UN_CHANGED
,
"Vgroup distribution has not changed"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_VGROUP_UN_CHANGED
,
"Vgroup distribution has not changed"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_HAS_OFFLINE_DNODE
,
"Offline dnode exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_HAS_OFFLINE_DNODE
,
"Offline dnode exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_REPLICA
,
"Invalid vgroup replica"
)
// mnode-stable
// mnode-stable
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_STB_ALREADY_EXIST
,
"STable already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_STB_ALREADY_EXIST
,
"STable already exists"
)
...
@@ -265,6 +265,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_INVALID_STAGE, "Invalid stage to kill
...
@@ -265,6 +265,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_INVALID_STAGE, "Invalid stage to kill
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TRANS_CONFLICT
,
"Conflict transaction not completed"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TRANS_CONFLICT
,
"Conflict transaction not completed"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TRANS_UNKNOW_ERROR
,
"Unknown transaction error"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TRANS_UNKNOW_ERROR
,
"Unknown transaction error"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TRANS_CLOG_IS_NULL
,
"Transaction commitlog is null"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TRANS_CLOG_IS_NULL
,
"Transaction commitlog is null"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TRANS_NETWORK_UNAVAILL
,
"Unable to establish connection While execute transaction"
)
// mnode-mq
// mnode-mq
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TOPIC_ALREADY_EXIST
,
"Topic already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_TOPIC_ALREADY_EXIST
,
"Topic already exists"
)
...
...
tests/script/tsim/dnode/redistribute_vgroup_replica3_move_1_vnode.sim
0 → 100644
浏览文件 @
7923d51f
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4
system sh/deploy.sh -n dnode5 -i 5
system sh/cfg.sh -n dnode1 -c supportVnodes -v 0
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
system sh/exec.sh -n dnode4 -s start
#system sh/exec.sh -n dnode5 -s start
sql connect
sql create user u1 pass 'taosdata'
print =============== step1 create dnode2
sql create dnode $hostname port 7200
sql create dnode $hostname port 7300
sql create dnode $hostname port 7400
sql create dnode $hostname port 7500
$x = 0
step1:
$ = $x + 1
sleep 1000
if $x == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
print ===> $data40 $data41 $data42 $data43 $data44 $data45
if $rows != 5 then
return -1
endi
if $data(1)[4] != ready then
goto step1
endi
if $data(2)[4] != ready then
goto step1
endi
if $data(3)[4] != ready then
goto step1
endi
if $data(4)[4] != ready then
goto step1
endi
#if $data(5)[4] != ready then
# goto step1
#endi
print =============== step2: create db
sql create database d1 vgroups 1 replica 3
# Invalid vgroup
sql_error redistribute vgroup 3 dnode 5 dnode 3 dnode 4
# un changed
sql_error redistribute vgroup 2 dnode 2 dnode 3 dnode 4
# no enought vnodes
sql_error redistribute vgroup 2 dnode 1 dnode 3 dnode 4
# offline vnodes
sql_error redistribute vgroup 2 dnode 5 dnode 3 dnode 4
# Invalid replica
sql_error redistribute vgroup 2 dnode 5
sql_error redistribute vgroup 2 dnode 5 dnode 3
sql_error redistribute vgroup 2 dnode 2 dnode 3
sql_error redistribute vgroup 2 dnode 2 dnode 2
sql_error redistribute vgroup 3 dnode 2 dnode 2
system sh/exec.sh -n dnode5 -s start
$x = 0
step2:
$ = $x + 1
sleep 1000
if $x == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
print ===> $data40 $data41 $data42 $data43 $data44 $data45
if $rows != 5 then
return -1
endi
if $data(1)[4] != ready then
goto step2
endi
if $data(2)[4] != ready then
goto step2
endi
if $data(3)[4] != ready then
goto step2
endi
if $data(4)[4] != ready then
goto step2
endi
if $data(5)[4] != ready then
goto step2
endi
print =============== step31: move follower
$leaderExist = 0
$leaderVnode = 0
$follower1 = 0
$follower2 = 0
$x = 0
step3:
$ = $x + 1
sleep 1000
if $x == 10 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
if $rows != 1 then
return -1
endi
if $data(2)[4] == leader then
$leaderExist = 1
$leaderVnode = 4
$follower1 = 2
$follower2 = 3
endi
if $data(2)[6] == leader then
$leaderExist = 1
$leaderVnode = 3
$follower1 = 2
$follower2 = 4
endi
if $data(2)[8] == leader then
$leaderExist = 1
$leaderVnode = 2
$follower1 = 3
$follower2 = 4
endi
if $leaderExist != 1 then
goto step3
endi
print leader $leaderVnode
print follower1 $follower1
print follower2 $follower2
print =============== step32: move follower2
print redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode 5
sql redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode 5
return
print =============== step33: move follower1
print redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 5
sql redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 5
print =============== step34: move follower2
print redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower2
sql redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower2
print =============== step35: move follower1
print redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower1
sql redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode $follower1
print =============== step4: move leader
return
print =============== step3: drop dnode 3
return
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT
system sh/exec.sh -n dnode5 -s stop -x SIGINT
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录