Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
98bc4630
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
98bc4630
编写于
6月 11, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of
https://github.com/taosdata/TDengine
into feat/tsdb_refact
上级
6af7d4cf
67baa489
变更
65
展开全部
显示空白变更内容
内联
并排
Showing
65 changed file
with
1534 addition
and
2753 deletion
+1534
-2753
include/common/tmsg.h
include/common/tmsg.h
+22
-40
include/common/tmsgdef.h
include/common/tmsgdef.h
+1
-1
include/libs/function/functionMgt.h
include/libs/function/functionMgt.h
+2
-1
include/libs/nodes/cmdnodes.h
include/libs/nodes/cmdnodes.h
+1
-1
include/libs/sync/sync.h
include/libs/sync/sync.h
+4
-0
include/libs/sync/syncTools.h
include/libs/sync/syncTools.h
+32
-0
include/util/taoserror.h
include/util/taoserror.h
+14
-3
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+23
-17
source/common/src/tmsg.c
source/common/src/tmsg.c
+12
-84
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+26
-25
source/dnode/mnode/impl/inc/mndTrans.h
source/dnode/mnode/impl/inc/mndTrans.h
+1
-0
source/dnode/mnode/impl/src/mndDb.c
source/dnode/mnode/impl/src/mndDb.c
+2
-3
source/dnode/mnode/impl/src/mndSma.c
source/dnode/mnode/impl/src/mndSma.c
+37
-59
source/dnode/mnode/impl/src/mndStream.c
source/dnode/mnode/impl/src/mndStream.c
+4
-0
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+6
-0
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+16
-7
source/dnode/vnode/CMakeLists.txt
source/dnode/vnode/CMakeLists.txt
+0
-1
source/dnode/vnode/src/inc/sma.h
source/dnode/vnode/src/inc/sma.h
+5
-58
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+1
-2
source/dnode/vnode/src/meta/metaSma.c
source/dnode/vnode/src/meta/metaSma.c
+3
-3
source/dnode/vnode/src/sma/sma.c
source/dnode/vnode/src/sma/sma.c
+1
-17
source/dnode/vnode/src/sma/smaEnv.c
source/dnode/vnode/src/sma/smaEnv.c
+2
-86
source/dnode/vnode/src/sma/smaRollup.c
source/dnode/vnode/src/sma/smaRollup.c
+5
-5
source/dnode/vnode/src/sma/smaTDBImpl.c
source/dnode/vnode/src/sma/smaTDBImpl.c
+0
-130
source/dnode/vnode/src/sma/smaTimeRange.c
source/dnode/vnode/src/sma/smaTimeRange.c
+0
-1037
source/dnode/vnode/src/sma/smaTimeRange2.c
source/dnode/vnode/src/sma/smaTimeRange2.c
+18
-936
source/dnode/vnode/src/tq/tqPush.c
source/dnode/vnode/src/tq/tqPush.c
+0
-3
source/dnode/vnode/src/tsdb/tsdbCommit.c
source/dnode/vnode/src/tsdb/tsdbCommit.c
+1
-1
source/dnode/vnode/src/tsdb/tsdbMemTable.c
source/dnode/vnode/src/tsdb/tsdbMemTable.c
+2
-2
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+2
-4
source/dnode/vnode/test/tsdbSmaTest.cpp
source/dnode/vnode/test/tsdbSmaTest.cpp
+1
-1
source/libs/executor/src/timewindowoperator.c
source/libs/executor/src/timewindowoperator.c
+30
-26
source/libs/function/inc/functionMgtInt.h
source/libs/function/inc/functionMgtInt.h
+1
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+11
-8
source/libs/function/src/functionMgt.c
source/libs/function/src/functionMgt.c
+2
-0
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+17
-12
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+67
-16
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+3
-1
source/libs/parser/test/parInitialATest.cpp
source/libs/parser/test/parInitialATest.cpp
+16
-4
source/libs/parser/test/parInitialCTest.cpp
source/libs/parser/test/parInitialCTest.cpp
+21
-3
source/libs/parser/test/parSelectTest.cpp
source/libs/parser/test/parSelectTest.cpp
+7
-3
source/libs/parser/test/parTestUtil.h
source/libs/parser/test/parTestUtil.h
+1
-1
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+2
-2
source/libs/sync/inc/syncRaftCfg.h
source/libs/sync/inc/syncRaftCfg.h
+4
-2
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+1
-0
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+241
-1
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+6
-3
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+165
-78
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+172
-0
source/libs/sync/src/syncRaftCfg.c
source/libs/sync/src/syncRaftCfg.c
+8
-0
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+10
-6
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+93
-16
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+5
-3
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+14
-0
source/libs/sync/test/syncLeaderTransferTest.cpp
source/libs/sync/test/syncLeaderTransferTest.cpp
+101
-0
source/libs/sync/test/syncRaftCfgTest.cpp
source/libs/sync/test/syncRaftCfgTest.cpp
+2
-0
source/libs/sync/test/syncSnapshotSendTest.cpp
source/libs/sync/test/syncSnapshotSendTest.cpp
+12
-0
source/util/src/terror.c
source/util/src/terror.c
+28
-18
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+2
-1
tests/script/tsim/db/alter_option.sim
tests/script/tsim/db/alter_option.sim
+2
-2
tests/script/tsim/db/basic6.sim
tests/script/tsim/db/basic6.sim
+1
-1
tests/script/tsim/db/create_all_options.sim
tests/script/tsim/db/create_all_options.sim
+1
-1
tests/script/tsim/mnode/basic2.sim
tests/script/tsim/mnode/basic2.sim
+4
-0
tests/script/tsim/mnode/basic3.sim
tests/script/tsim/mnode/basic3.sim
+64
-18
tests/script/tsim/stream/distributeInterval0.sim
tests/script/tsim/stream/distributeInterval0.sim
+176
-0
未找到文件。
include/common/tmsg.h
浏览文件 @
98bc4630
...
@@ -2344,15 +2344,17 @@ typedef struct {
...
@@ -2344,15 +2344,17 @@ typedef struct {
char
indexName
[
TSDB_INDEX_NAME_LEN
];
char
indexName
[
TSDB_INDEX_NAME_LEN
];
int32_t
exprLen
;
int32_t
exprLen
;
int32_t
tagsFilterLen
;
int32_t
tagsFilterLen
;
int32_t
numOfVgroups
;
int64_t
indexUid
;
int64_t
indexUid
;
tb_uid_t
tableUid
;
// super/child/common table uid
tb_uid_t
tableUid
;
// super/child/common table uid
tb_uid_t
dstTbUid
;
// for dstVgroup
int64_t
interval
;
int64_t
interval
;
int64_t
offset
;
// use unit by precision of DB
int64_t
offset
;
// use unit by precision of DB
int64_t
sliding
;
int64_t
sliding
;
char
*
dstTbName
;
// for dstVgroup
char
*
expr
;
// sma expression
char
*
expr
;
// sma expression
char
*
tagsFilter
;
char
*
tagsFilter
;
SVgEpSet
*
pVgEpSet
;
SSchemaWrapper
schemaRow
;
// for dstVgroup
SSchemaWrapper
schemaTag
;
// for dstVgroup
}
STSma
;
// Time-range-wise SMA
}
STSma
;
// Time-range-wise SMA
typedef
STSma
SVCreateTSmaReq
;
typedef
STSma
SVCreateTSmaReq
;
...
@@ -2437,27 +2439,6 @@ static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq) {
...
@@ -2437,27 +2439,6 @@ static int32_t tDecodeTSmaWrapper(SDecoder* pDecoder, STSmaWrapper* pReq) {
return
0
;
return
0
;
}
}
typedef
struct
{
int64_t
indexUid
;
STimeWindow
queryWindow
;
}
SVGetTsmaExpWndsReq
;
#define SMA_WNDS_EXPIRE_FLAG (0x1)
#define SMA_WNDS_IS_EXPIRE(flag) (((flag)&SMA_WNDS_EXPIRE_FLAG) != 0)
#define SMA_WNDS_SET_EXPIRE(flag) ((flag) |= SMA_WNDS_EXPIRE_FLAG)
typedef
struct
{
int64_t
indexUid
;
int8_t
flags
;
// 0x1 all window expired
int32_t
numExpWnds
;
TSKEY
wndSKeys
[];
}
SVGetTsmaExpWndsRsp
;
int32_t
tEncodeSVGetTSmaExpWndsReq
(
SEncoder
*
pCoder
,
const
SVGetTsmaExpWndsReq
*
pReq
);
int32_t
tDecodeSVGetTsmaExpWndsReq
(
SDecoder
*
pCoder
,
SVGetTsmaExpWndsReq
*
pReq
);
int32_t
tEncodeSVGetTSmaExpWndsRsp
(
SEncoder
*
pCoder
,
const
SVGetTsmaExpWndsRsp
*
pReq
);
int32_t
tDecodeSVGetTsmaExpWndsRsp
(
SDecoder
*
pCoder
,
SVGetTsmaExpWndsRsp
*
pReq
);
typedef
struct
{
typedef
struct
{
int
idx
;
int
idx
;
}
SMCreateFullTextReq
;
}
SMCreateFullTextReq
;
...
@@ -2517,6 +2498,7 @@ typedef struct {
...
@@ -2517,6 +2498,7 @@ typedef struct {
int32_t
tSerializeSTableIndexRsp
(
void
*
buf
,
int32_t
bufLen
,
const
STableIndexRsp
*
pRsp
);
int32_t
tSerializeSTableIndexRsp
(
void
*
buf
,
int32_t
bufLen
,
const
STableIndexRsp
*
pRsp
);
int32_t
tDeserializeSTableIndexRsp
(
void
*
buf
,
int32_t
bufLen
,
STableIndexRsp
*
pRsp
);
int32_t
tDeserializeSTableIndexRsp
(
void
*
buf
,
int32_t
bufLen
,
STableIndexRsp
*
pRsp
);
void
tFreeSTableIndexInfo
(
void
*
pInfo
);
void
tFreeSTableIndexInfo
(
void
*
pInfo
);
typedef
struct
{
typedef
struct
{
...
...
include/common/tmsgdef.h
浏览文件 @
98bc4630
...
@@ -190,7 +190,6 @@ enum {
...
@@ -190,7 +190,6 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_VND_CANCEL_SMA
,
"vnode-cancel-sma"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_CANCEL_SMA
,
"vnode-cancel-sma"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_DROP_SMA
,
"vnode-drop-sma"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_DROP_SMA
,
"vnode-drop-sma"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SUBMIT_RSMA
,
"vnode-submit-rsma"
,
SSubmitReq
,
SSubmitRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SUBMIT_RSMA
,
"vnode-submit-rsma"
,
SSubmitReq
,
SSubmitRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_GET_TSMA_EXP_WNDS
,
"vnode-get-tsma-expired-windows"
,
SVGetTsmaExpWndsReq
,
SVGetTsmaExpWndsRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_DELETE
,
"delete-data"
,
SVDeleteReq
,
SVDeleteRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_DELETE
,
"delete-data"
,
SVDeleteReq
,
SVDeleteRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_ALTER_CONFIG
,
"alter-config"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_ALTER_CONFIG
,
"alter-config"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_ALTER_REPLICA
,
"alter-replica"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_ALTER_REPLICA
,
"alter-replica"
,
NULL
,
NULL
)
...
@@ -237,6 +236,7 @@ enum {
...
@@ -237,6 +236,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_SYNC_CONFIG_CHANGE
,
"sync-config-change"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_CONFIG_CHANGE
,
"sync-config-change"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_SNAPSHOT_SEND
,
"sync-snapshot-send"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_SNAPSHOT_SEND
,
"sync-snapshot-send"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_SNAPSHOT_RSP
,
"sync-snapshot-rsp"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_SNAPSHOT_RSP
,
"sync-snapshot-rsp"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_LEADER_TRANSFER
,
"sync-leader-transfer"
,
NULL
,
NULL
)
#if defined(TD_MSG_NUMBER_)
#if defined(TD_MSG_NUMBER_)
TDMT_MAX
TDMT_MAX
...
...
include/libs/function/functionMgt.h
浏览文件 @
98bc4630
...
@@ -170,6 +170,7 @@ bool fmIsMultiResFunc(int32_t funcId);
...
@@ -170,6 +170,7 @@ bool fmIsMultiResFunc(int32_t funcId);
bool
fmIsRepeatScanFunc
(
int32_t
funcId
);
bool
fmIsRepeatScanFunc
(
int32_t
funcId
);
bool
fmIsUserDefinedFunc
(
int32_t
funcId
);
bool
fmIsUserDefinedFunc
(
int32_t
funcId
);
bool
fmIsDistExecFunc
(
int32_t
funcId
);
bool
fmIsDistExecFunc
(
int32_t
funcId
);
bool
fmIsForbidFillFunc
(
int32_t
funcId
);
int32_t
fmGetDistMethod
(
const
SFunctionNode
*
pFunc
,
SFunctionNode
**
pPartialFunc
,
SFunctionNode
**
pMergeFunc
);
int32_t
fmGetDistMethod
(
const
SFunctionNode
*
pFunc
,
SFunctionNode
**
pPartialFunc
,
SFunctionNode
**
pMergeFunc
);
...
...
include/libs/nodes/cmdnodes.h
浏览文件 @
98bc4630
...
@@ -47,7 +47,7 @@ typedef struct SDatabaseOptions {
...
@@ -47,7 +47,7 @@ typedef struct SDatabaseOptions {
int32_t
maxRowsPerBlock
;
int32_t
maxRowsPerBlock
;
int32_t
minRowsPerBlock
;
int32_t
minRowsPerBlock
;
SNodeList
*
pKeep
;
SNodeList
*
pKeep
;
int
32
_t
keep
[
3
];
int
64
_t
keep
[
3
];
int32_t
pages
;
int32_t
pages
;
int32_t
pagesize
;
int32_t
pagesize
;
char
precisionStr
[
3
];
char
precisionStr
[
3
];
...
...
include/libs/sync/sync.h
浏览文件 @
98bc4630
...
@@ -48,6 +48,7 @@ typedef enum {
...
@@ -48,6 +48,7 @@ typedef enum {
TAOS_SYNC_PROPOSE_SUCCESS
=
0
,
TAOS_SYNC_PROPOSE_SUCCESS
=
0
,
TAOS_SYNC_PROPOSE_NOT_LEADER
=
1
,
TAOS_SYNC_PROPOSE_NOT_LEADER
=
1
,
TAOS_SYNC_PROPOSE_OTHER_ERROR
=
2
,
TAOS_SYNC_PROPOSE_OTHER_ERROR
=
2
,
TAOS_SYNC_ONLY_ONE_REPLICA
=
3
,
}
ESyncProposeCode
;
}
ESyncProposeCode
;
typedef
enum
{
typedef
enum
{
...
@@ -200,6 +201,9 @@ int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta);
...
@@ -200,6 +201,9 @@ int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta);
int32_t
syncReconfig
(
int64_t
rid
,
const
SSyncCfg
*
pNewCfg
);
int32_t
syncReconfig
(
int64_t
rid
,
const
SSyncCfg
*
pNewCfg
);
int32_t
syncReconfigRaw
(
int64_t
rid
,
const
SSyncCfg
*
pNewCfg
,
SRpcMsg
*
pRpcMsg
);
int32_t
syncReconfigRaw
(
int64_t
rid
,
const
SSyncCfg
*
pNewCfg
,
SRpcMsg
*
pRpcMsg
);
int32_t
syncLeaderTransfer
(
int64_t
rid
);
int32_t
syncLeaderTransferTo
(
int64_t
rid
,
SNodeInfo
newLeader
);
// to be moved to static
// to be moved to static
void
syncStartNormal
(
int64_t
rid
);
void
syncStartNormal
(
int64_t
rid
);
void
syncStartStandBy
(
int64_t
rid
);
void
syncStartStandBy
(
int64_t
rid
);
...
...
include/libs/sync/syncTools.h
浏览文件 @
98bc4630
...
@@ -398,6 +398,8 @@ typedef struct SyncSnapshotSend {
...
@@ -398,6 +398,8 @@ typedef struct SyncSnapshotSend {
SyncTerm
term
;
SyncTerm
term
;
SyncIndex
lastIndex
;
// lastIndex of snapshot
SyncIndex
lastIndex
;
// lastIndex of snapshot
SyncTerm
lastTerm
;
// lastTerm of snapshot
SyncTerm
lastTerm
;
// lastTerm of snapshot
SyncIndex
lastConfigIndex
;
SSyncCfg
lastConfig
;
SyncTerm
privateTerm
;
SyncTerm
privateTerm
;
int32_t
seq
;
int32_t
seq
;
uint32_t
dataLen
;
uint32_t
dataLen
;
...
@@ -456,6 +458,36 @@ void syncSnapshotRspPrint2(char* s, const SyncSnapshotRsp* pMsg);
...
@@ -456,6 +458,36 @@ void syncSnapshotRspPrint2(char* s, const SyncSnapshotRsp* pMsg);
void
syncSnapshotRspLog
(
const
SyncSnapshotRsp
*
pMsg
);
void
syncSnapshotRspLog
(
const
SyncSnapshotRsp
*
pMsg
);
void
syncSnapshotRspLog2
(
char
*
s
,
const
SyncSnapshotRsp
*
pMsg
);
void
syncSnapshotRspLog2
(
char
*
s
,
const
SyncSnapshotRsp
*
pMsg
);
// ---------------------------------------------
typedef
struct
SyncLeaderTransfer
{
uint32_t
bytes
;
int32_t
vgId
;
uint32_t
msgType
;
/*
SRaftId srcId;
SRaftId destId;
*/
SRaftId
newLeaderId
;
}
SyncLeaderTransfer
;
SyncLeaderTransfer
*
syncLeaderTransferBuild
(
int32_t
vgId
);
void
syncLeaderTransferDestroy
(
SyncLeaderTransfer
*
pMsg
);
void
syncLeaderTransferSerialize
(
const
SyncLeaderTransfer
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncLeaderTransferDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncLeaderTransfer
*
pMsg
);
char
*
syncLeaderTransferSerialize2
(
const
SyncLeaderTransfer
*
pMsg
,
uint32_t
*
len
);
SyncLeaderTransfer
*
syncLeaderTransferDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncLeaderTransfer2RpcMsg
(
const
SyncLeaderTransfer
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncLeaderTransferFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncLeaderTransfer
*
pMsg
);
SyncLeaderTransfer
*
syncLeaderTransferFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncLeaderTransfer2Json
(
const
SyncLeaderTransfer
*
pMsg
);
char
*
syncLeaderTransfer2Str
(
const
SyncLeaderTransfer
*
pMsg
);
// for debug ----------------------
void
syncLeaderTransferPrint
(
const
SyncLeaderTransfer
*
pMsg
);
void
syncLeaderTransferPrint2
(
char
*
s
,
const
SyncLeaderTransfer
*
pMsg
);
void
syncLeaderTransferLog
(
const
SyncLeaderTransfer
*
pMsg
);
void
syncLeaderTransferLog2
(
char
*
s
,
const
SyncLeaderTransfer
*
pMsg
);
// on message ----------------------
// on message ----------------------
int32_t
syncNodeOnPingCb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
int32_t
syncNodeOnPingCb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
...
...
include/util/taoserror.h
浏览文件 @
98bc4630
...
@@ -352,9 +352,6 @@ int32_t* taosGetErrno();
...
@@ -352,9 +352,6 @@ int32_t* taosGetErrno();
#define TSDB_CODE_TDB_NO_CACHE_LAST_ROW TAOS_DEF_ERROR_CODE(0, 0x0619)
#define TSDB_CODE_TDB_NO_CACHE_LAST_ROW TAOS_DEF_ERROR_CODE(0, 0x0619)
#define TSDB_CODE_TDB_TABLE_RECREATED TAOS_DEF_ERROR_CODE(0, 0x061A)
#define TSDB_CODE_TDB_TABLE_RECREATED TAOS_DEF_ERROR_CODE(0, 0x061A)
#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x061B)
#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x061B)
#define TSDB_CODE_TDB_NO_SMA_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x061C)
#define TSDB_CODE_TDB_INVALID_SMA_STAT TAOS_DEF_ERROR_CODE(0, 0x061D)
#define TSDB_CODE_TDB_TSMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x061E)
// query
// query
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700)
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700)
...
@@ -655,6 +652,7 @@ int32_t* taosGetErrno();
...
@@ -655,6 +652,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2654)
#define TSDB_CODE_PAR_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2654)
#define TSDB_CODE_PAR_INVALID_DELETE_WHERE TAOS_DEF_ERROR_CODE(0, 0x2655)
#define TSDB_CODE_PAR_INVALID_DELETE_WHERE TAOS_DEF_ERROR_CODE(0, 0x2655)
#define TSDB_CODE_PAR_INVALID_REDISTRIBUTE_VG TAOS_DEF_ERROR_CODE(0, 0x2656)
#define TSDB_CODE_PAR_INVALID_REDISTRIBUTE_VG TAOS_DEF_ERROR_CODE(0, 0x2656)
#define TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC TAOS_DEF_ERROR_CODE(0, 0x2657)
//planner
//planner
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
...
@@ -685,6 +683,19 @@ int32_t* taosGetErrno();
...
@@ -685,6 +683,19 @@ int32_t* taosGetErrno();
#define TSDB_CODE_SML_INVALID_DATA TAOS_DEF_ERROR_CODE(0, 0x3002)
#define TSDB_CODE_SML_INVALID_DATA TAOS_DEF_ERROR_CODE(0, 0x3002)
#define TSDB_CODE_SML_INVALID_DB_CONF TAOS_DEF_ERROR_CODE(0, 0x3003)
#define TSDB_CODE_SML_INVALID_DB_CONF TAOS_DEF_ERROR_CODE(0, 0x3003)
//tsma
#define TSDB_CODE_TSMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x3100)
#define TSDB_CODE_TSMA_NO_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x3101)
#define TSDB_CODE_TSMA_INVALID_ENV TAOS_DEF_ERROR_CODE(0, 0x3102)
#define TSDB_CODE_TSMA_INVALID_STAT TAOS_DEF_ERROR_CODE(0, 0x3103)
#define TSDB_CODE_TSMA_NO_INDEX_IN_CACHE TAOS_DEF_ERROR_CODE(0, 0x3104)
#define TSDB_CODE_TSMA_RM_SKEY_IN_HASH TAOS_DEF_ERROR_CODE(0, 0x3105)
//rsma
#define TSDB_CODE_RSMA_INVALID_ENV TAOS_DEF_ERROR_CODE(0, 0x3150)
#define TSDB_CODE_RSMA_INVALID_STAT TAOS_DEF_ERROR_CODE(0, 0x3151)
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/common/src/tdatablock.c
浏览文件 @
98bc4630
...
@@ -1634,6 +1634,10 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
...
@@ -1634,6 +1634,10 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
break
;
break
;
default:
default:
if
(
pColInfoData
->
info
.
type
<
TSDB_DATA_TYPE_MAX
&&
pColInfoData
->
info
.
type
>
TSDB_DATA_TYPE_NULL
)
{
if
(
pColInfoData
->
info
.
type
<
TSDB_DATA_TYPE_MAX
&&
pColInfoData
->
info
.
type
>
TSDB_DATA_TYPE_NULL
)
{
if
(
pCol
->
type
==
pColInfoData
->
info
.
type
)
{
tdAppendColValToRow
(
&
rb
,
PRIMARYKEY_TIMESTAMP_COL_ID
+
k
,
pCol
->
type
,
TD_VTYPE_NORM
,
var
,
true
,
offset
,
k
);
}
else
{
char
tv
[
8
]
=
{
0
};
char
tv
[
8
]
=
{
0
};
if
(
pColInfoData
->
info
.
type
==
TSDB_DATA_TYPE_FLOAT
)
{
if
(
pColInfoData
->
info
.
type
==
TSDB_DATA_TYPE_FLOAT
)
{
float
v
=
0
;
float
v
=
0
;
...
@@ -1652,7 +1656,9 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
...
@@ -1652,7 +1656,9 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
GET_TYPED_DATA
(
v
,
uint64_t
,
pColInfoData
->
info
.
type
,
var
);
GET_TYPED_DATA
(
v
,
uint64_t
,
pColInfoData
->
info
.
type
,
var
);
SET_TYPED_DATA
(
&
tv
,
pCol
->
type
,
v
);
SET_TYPED_DATA
(
&
tv
,
pCol
->
type
,
v
);
}
}
tdAppendColValToRow
(
&
rb
,
PRIMARYKEY_TIMESTAMP_COL_ID
+
k
,
pCol
->
type
,
TD_VTYPE_NORM
,
tv
,
true
,
offset
,
k
);
tdAppendColValToRow
(
&
rb
,
PRIMARYKEY_TIMESTAMP_COL_ID
+
k
,
pCol
->
type
,
TD_VTYPE_NORM
,
tv
,
true
,
offset
,
k
);
}
}
else
{
}
else
{
uError
(
"the column type %"
PRIi16
" is undefined
\n
"
,
pColInfoData
->
info
.
type
);
uError
(
"the column type %"
PRIi16
" is undefined
\n
"
,
pColInfoData
->
info
.
type
);
TASSERT
(
0
);
TASSERT
(
0
);
...
...
source/common/src/tmsg.c
浏览文件 @
98bc4630
...
@@ -3877,9 +3877,10 @@ int32_t tEncodeTSma(SEncoder *pCoder, const STSma *pSma) {
...
@@ -3877,9 +3877,10 @@ int32_t tEncodeTSma(SEncoder *pCoder, const STSma *pSma) {
if
(
tEncodeCStr
(
pCoder
,
pSma
->
indexName
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pCoder
,
pSma
->
indexName
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pCoder
,
pSma
->
exprLen
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pCoder
,
pSma
->
exprLen
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pCoder
,
pSma
->
tagsFilterLen
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pCoder
,
pSma
->
tagsFilterLen
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pCoder
,
pSma
->
numOfVgroups
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
indexUid
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
indexUid
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
tableUid
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
tableUid
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
dstTbUid
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pCoder
,
pSma
->
dstTbName
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
interval
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
interval
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
offset
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
offset
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
sliding
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
sliding
)
<
0
)
return
-
1
;
...
@@ -3889,17 +3890,10 @@ int32_t tEncodeTSma(SEncoder *pCoder, const STSma *pSma) {
...
@@ -3889,17 +3890,10 @@ int32_t tEncodeTSma(SEncoder *pCoder, const STSma *pSma) {
if
(
pSma
->
tagsFilterLen
>
0
)
{
if
(
pSma
->
tagsFilterLen
>
0
)
{
if
(
tEncodeCStr
(
pCoder
,
pSma
->
tagsFilter
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pCoder
,
pSma
->
tagsFilter
)
<
0
)
return
-
1
;
}
}
for
(
int32_t
v
=
0
;
v
<
pSma
->
numOfVgroups
;
++
v
)
{
if
(
tEncodeI32
(
pCoder
,
pSma
->
pVgEpSet
[
v
].
vgId
)
<
0
)
return
-
1
;
tEncodeSSchemaWrapper
(
pCoder
,
&
pSma
->
schemaRow
);
if
(
tEncodeI8
(
pCoder
,
pSma
->
pVgEpSet
[
v
].
epSet
.
inUse
)
<
0
)
return
-
1
;
tEncodeSSchemaWrapper
(
pCoder
,
&
pSma
->
schemaTag
);
int8_t
numOfEps
=
pSma
->
pVgEpSet
[
v
].
epSet
.
numOfEps
;
if
(
tEncodeI8
(
pCoder
,
numOfEps
)
<
0
)
return
-
1
;
for
(
int32_t
n
=
0
;
n
<
numOfEps
;
++
n
)
{
const
SEp
*
pEp
=
&
pSma
->
pVgEpSet
[
v
].
epSet
.
eps
[
n
];
if
(
tEncodeCStr
(
pCoder
,
pEp
->
fqdn
)
<
0
)
return
-
1
;
if
(
tEncodeU16
(
pCoder
,
pEp
->
port
)
<
0
)
return
-
1
;
}
}
return
0
;
return
0
;
}
}
...
@@ -3907,14 +3901,15 @@ int32_t tDecodeTSma(SDecoder *pCoder, STSma *pSma) {
...
@@ -3907,14 +3901,15 @@ int32_t tDecodeTSma(SDecoder *pCoder, STSma *pSma) {
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
version
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
version
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
intervalUnit
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
intervalUnit
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
slidingUnit
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
slidingUnit
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pSma
->
dstVgId
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
timezoneInt
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
timezoneInt
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pSma
->
dstVgId
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pCoder
,
pSma
->
indexName
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pCoder
,
pSma
->
indexName
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pSma
->
exprLen
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pSma
->
exprLen
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pSma
->
tagsFilterLen
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pSma
->
tagsFilterLen
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pSma
->
numOfVgroups
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
indexUid
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
indexUid
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
tableUid
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
tableUid
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
dstTbUid
)
<
0
)
return
-
1
;
if
(
tDecodeCStr
(
pCoder
,
&
pSma
->
dstTbName
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
interval
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
interval
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
offset
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
offset
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
sliding
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
sliding
)
<
0
)
return
-
1
;
...
@@ -3928,27 +3923,9 @@ int32_t tDecodeTSma(SDecoder *pCoder, STSma *pSma) {
...
@@ -3928,27 +3923,9 @@ int32_t tDecodeTSma(SDecoder *pCoder, STSma *pSma) {
}
else
{
}
else
{
pSma
->
tagsFilter
=
NULL
;
pSma
->
tagsFilter
=
NULL
;
}
}
if
(
pSma
->
numOfVgroups
>
0
)
{
// only needed in dstVgroup
pSma
->
pVgEpSet
=
(
SVgEpSet
*
)
tDecoderMalloc
(
pCoder
,
pSma
->
numOfVgroups
*
sizeof
(
SVgEpSet
));
tDecodeSSchemaWrapperEx
(
pCoder
,
&
pSma
->
schemaRow
);
if
(
!
pSma
->
pVgEpSet
)
{
tDecodeSSchemaWrapperEx
(
pCoder
,
&
pSma
->
schemaTag
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
memset
(
pSma
->
pVgEpSet
,
0
,
pSma
->
numOfVgroups
*
sizeof
(
SVgEpSet
));
for
(
int32_t
v
=
0
;
v
<
pSma
->
numOfVgroups
;
++
v
)
{
if
(
tDecodeI32
(
pCoder
,
&
pSma
->
pVgEpSet
[
v
].
vgId
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
pVgEpSet
[
v
].
epSet
.
inUse
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
pVgEpSet
[
v
].
epSet
.
numOfEps
)
<
0
)
return
-
1
;
int8_t
numOfEps
=
pSma
->
pVgEpSet
[
v
].
epSet
.
numOfEps
;
for
(
int32_t
n
=
0
;
n
<
numOfEps
;
++
n
)
{
SEp
*
pEp
=
&
pSma
->
pVgEpSet
[
v
].
epSet
.
eps
[
n
];
if
(
tDecodeCStrTo
(
pCoder
,
pEp
->
fqdn
)
<
0
)
return
-
1
;
if
(
tDecodeU16
(
pCoder
,
&
pEp
->
port
)
<
0
)
return
-
1
;
}
}
}
return
0
;
return
0
;
}
}
...
@@ -3991,55 +3968,6 @@ int32_t tDecodeSVDropTSmaReq(SDecoder *pCoder, SVDropTSmaReq *pReq) {
...
@@ -3991,55 +3968,6 @@ int32_t tDecodeSVDropTSmaReq(SDecoder *pCoder, SVDropTSmaReq *pReq) {
return
0
;
return
0
;
}
}
int32_t
tEncodeSVGetTSmaExpWndsReq
(
SEncoder
*
pCoder
,
const
SVGetTsmaExpWndsReq
*
pReq
)
{
if
(
tStartEncode
(
pCoder
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pReq
->
indexUid
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pReq
->
queryWindow
.
skey
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pReq
->
queryWindow
.
ekey
)
<
0
)
return
-
1
;
tEndEncode
(
pCoder
);
return
0
;
}
int32_t
tDecodeSVGetTsmaExpWndsReq
(
SDecoder
*
pCoder
,
SVGetTsmaExpWndsReq
*
pReq
)
{
if
(
tStartDecode
(
pCoder
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pReq
->
indexUid
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pReq
->
queryWindow
.
skey
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pReq
->
queryWindow
.
ekey
)
<
0
)
return
-
1
;
tEndDecode
(
pCoder
);
return
0
;
}
int32_t
tEncodeSVGetTSmaExpWndsRsp
(
SEncoder
*
pCoder
,
const
SVGetTsmaExpWndsRsp
*
pReq
)
{
if
(
tStartEncode
(
pCoder
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pReq
->
indexUid
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pCoder
,
pReq
->
flags
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pCoder
,
pReq
->
numExpWnds
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pReq
->
numExpWnds
;
++
i
)
{
if
(
tEncodeI64
(
pCoder
,
pReq
->
wndSKeys
[
i
])
<
0
)
return
-
1
;
}
tEndEncode
(
pCoder
);
return
0
;
}
int32_t
tDecodeSVGetTsmaExpWndsRsp
(
SDecoder
*
pCoder
,
SVGetTsmaExpWndsRsp
*
pReq
)
{
if
(
tStartDecode
(
pCoder
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pReq
->
indexUid
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pReq
->
flags
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pReq
->
numExpWnds
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pReq
->
numExpWnds
;
++
i
)
{
if
(
tDecodeI64
(
pCoder
,
&
pReq
->
wndSKeys
[
i
])
<
0
)
return
-
1
;
}
tEndDecode
(
pCoder
);
return
0
;
}
int32_t
tSerializeSVDeleteReq
(
void
*
buf
,
int32_t
bufLen
,
SVDeleteReq
*
pReq
)
{
int32_t
tSerializeSVDeleteReq
(
void
*
buf
,
int32_t
bufLen
,
SVDeleteReq
*
pReq
)
{
int32_t
headLen
=
sizeof
(
SMsgHead
);
int32_t
headLen
=
sizeof
(
SMsgHead
);
if
(
buf
!=
NULL
)
{
if
(
buf
!=
NULL
)
{
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
98bc4630
...
@@ -301,15 +301,16 @@ typedef struct {
...
@@ -301,15 +301,16 @@ typedef struct {
char
name
[
TSDB_TABLE_FNAME_LEN
];
char
name
[
TSDB_TABLE_FNAME_LEN
];
char
stb
[
TSDB_TABLE_FNAME_LEN
];
char
stb
[
TSDB_TABLE_FNAME_LEN
];
char
db
[
TSDB_DB_FNAME_LEN
];
char
db
[
TSDB_DB_FNAME_LEN
];
char
dstTbName
[
TSDB_TABLE_FNAME_LEN
];
int64_t
createdTime
;
int64_t
createdTime
;
int64_t
uid
;
int64_t
uid
;
int64_t
stbUid
;
int64_t
stbUid
;
int64_t
dbUid
;
int64_t
dbUid
;
int64_t
dstTbUid
;
int8_t
intervalUnit
;
int8_t
intervalUnit
;
int8_t
slidingUnit
;
int8_t
slidingUnit
;
int8_t
timezone
;
int8_t
timezone
;
int32_t
dstVgId
;
// for stream
int32_t
dstVgId
;
// for stream
int64_t
dstTbUid
;
int64_t
interval
;
int64_t
interval
;
int64_t
offset
;
int64_t
offset
;
int64_t
sliding
;
int64_t
sliding
;
...
@@ -317,12 +318,12 @@ typedef struct {
...
@@ -317,12 +318,12 @@ typedef struct {
int32_t
tagsFilterLen
;
int32_t
tagsFilterLen
;
int32_t
sqlLen
;
int32_t
sqlLen
;
int32_t
astLen
;
int32_t
astLen
;
int32_t
numOfVgroups
;
char
*
expr
;
char
*
expr
;
char
*
tagsFilter
;
char
*
tagsFilter
;
char
*
sql
;
char
*
sql
;
char
*
ast
;
char
*
ast
;
SVgEpSet
*
pVgEpSet
;
SSchemaWrapper
schemaRow
;
// for dstVgroup
SSchemaWrapper
schemaTag
;
// for dstVgroup
}
SSmaObj
;
}
SSmaObj
;
typedef
struct
{
typedef
struct
{
...
...
source/dnode/mnode/impl/inc/mndTrans.h
浏览文件 @
98bc4630
...
@@ -75,6 +75,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans);
...
@@ -75,6 +75,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans);
int32_t
mndTransProcessRsp
(
SRpcMsg
*
pRsp
);
int32_t
mndTransProcessRsp
(
SRpcMsg
*
pRsp
);
void
mndTransPullup
(
SMnode
*
pMnode
);
void
mndTransPullup
(
SMnode
*
pMnode
);
int32_t
mndKillTrans
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
int32_t
mndKillTrans
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
void
mndTransExecute
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/dnode/mnode/impl/src/mndDb.c
浏览文件 @
98bc4630
...
@@ -1424,10 +1424,10 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in
...
@@ -1424,10 +1424,10 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in
char
tmp
[
128
]
=
{
0
};
char
tmp
[
128
]
=
{
0
};
int32_t
len
=
0
;
int32_t
len
=
0
;
if
(
pDb
->
cfg
.
daysToKeep0
>
pDb
->
cfg
.
daysToKeep1
||
pDb
->
cfg
.
daysToKeep0
>
pDb
->
cfg
.
daysToKeep2
)
{
if
(
pDb
->
cfg
.
daysToKeep0
>
pDb
->
cfg
.
daysToKeep1
||
pDb
->
cfg
.
daysToKeep0
>
pDb
->
cfg
.
daysToKeep2
)
{
len
=
sprintf
(
&
tmp
[
VARSTR_HEADER_SIZE
],
"%d
,%d,%d
"
,
pDb
->
cfg
.
daysToKeep1
,
pDb
->
cfg
.
daysToKeep2
,
len
=
sprintf
(
&
tmp
[
VARSTR_HEADER_SIZE
],
"%d
m,%dm,%dm
"
,
pDb
->
cfg
.
daysToKeep1
,
pDb
->
cfg
.
daysToKeep2
,
pDb
->
cfg
.
daysToKeep0
);
pDb
->
cfg
.
daysToKeep0
);
}
else
{
}
else
{
len
=
sprintf
(
&
tmp
[
VARSTR_HEADER_SIZE
],
"%d
,%d,%d
"
,
pDb
->
cfg
.
daysToKeep0
,
pDb
->
cfg
.
daysToKeep1
,
len
=
sprintf
(
&
tmp
[
VARSTR_HEADER_SIZE
],
"%d
m,%dm,%dm
"
,
pDb
->
cfg
.
daysToKeep0
,
pDb
->
cfg
.
daysToKeep1
,
pDb
->
cfg
.
daysToKeep2
);
pDb
->
cfg
.
daysToKeep2
);
}
}
...
@@ -1592,4 +1592,3 @@ static void mndCancelGetNextDb(SMnode *pMnode, void *pIter) {
...
@@ -1592,4 +1592,3 @@ static void mndCancelGetNextDb(SMnode *pMnode, void *pIter) {
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
sdbCancelFetch
(
pSdb
,
pIter
);
}
}
source/dnode/mnode/impl/src/mndSma.c
浏览文件 @
98bc4630
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#include "mndTrans.h"
#include "mndTrans.h"
#include "mndUser.h"
#include "mndUser.h"
#include "mndVgroup.h"
#include "mndVgroup.h"
#include "parser.h"
#include "tname.h"
#include "tname.h"
#define TSDB_SMA_VER_NUMBER 1
#define TSDB_SMA_VER_NUMBER 1
...
@@ -82,10 +83,12 @@ static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) {
...
@@ -82,10 +83,12 @@ static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) {
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pSma
->
name
,
TSDB_TABLE_FNAME_LEN
,
_OVER
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pSma
->
name
,
TSDB_TABLE_FNAME_LEN
,
_OVER
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pSma
->
stb
,
TSDB_TABLE_FNAME_LEN
,
_OVER
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pSma
->
stb
,
TSDB_TABLE_FNAME_LEN
,
_OVER
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pSma
->
db
,
TSDB_DB_FNAME_LEN
,
_OVER
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pSma
->
db
,
TSDB_DB_FNAME_LEN
,
_OVER
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pSma
->
dstTbName
,
TSDB_DB_FNAME_LEN
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pSma
->
createdTime
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pSma
->
createdTime
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pSma
->
uid
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pSma
->
uid
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pSma
->
stbUid
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pSma
->
stbUid
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pSma
->
dbUid
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pSma
->
dbUid
,
_OVER
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pSma
->
dstTbUid
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pSma
->
intervalUnit
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pSma
->
intervalUnit
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pSma
->
slidingUnit
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pSma
->
slidingUnit
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pSma
->
timezone
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pSma
->
timezone
,
_OVER
)
...
@@ -147,10 +150,12 @@ static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw) {
...
@@ -147,10 +150,12 @@ static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw) {
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pSma
->
name
,
TSDB_TABLE_FNAME_LEN
,
_OVER
)
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pSma
->
name
,
TSDB_TABLE_FNAME_LEN
,
_OVER
)
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pSma
->
stb
,
TSDB_TABLE_FNAME_LEN
,
_OVER
)
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pSma
->
stb
,
TSDB_TABLE_FNAME_LEN
,
_OVER
)
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pSma
->
db
,
TSDB_DB_FNAME_LEN
,
_OVER
)
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pSma
->
db
,
TSDB_DB_FNAME_LEN
,
_OVER
)
SDB_GET_BINARY
(
pRaw
,
dataPos
,
pSma
->
dstTbName
,
TSDB_DB_FNAME_LEN
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pSma
->
createdTime
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pSma
->
createdTime
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pSma
->
uid
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pSma
->
uid
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pSma
->
stbUid
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pSma
->
stbUid
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pSma
->
dbUid
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pSma
->
dbUid
,
_OVER
)
SDB_GET_INT64
(
pRaw
,
dataPos
,
&
pSma
->
dstTbUid
,
_OVER
)
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
pSma
->
intervalUnit
,
_OVER
)
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
pSma
->
intervalUnit
,
_OVER
)
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
pSma
->
slidingUnit
,
_OVER
)
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
pSma
->
slidingUnit
,
_OVER
)
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
pSma
->
timezone
,
_OVER
)
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
pSma
->
timezone
,
_OVER
)
...
@@ -260,13 +265,16 @@ static void *mndBuildVCreateSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSm
...
@@ -260,13 +265,16 @@ static void *mndBuildVCreateSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSm
req
.
tagsFilterLen
=
pSma
->
tagsFilterLen
;
req
.
tagsFilterLen
=
pSma
->
tagsFilterLen
;
req
.
indexUid
=
pSma
->
uid
;
req
.
indexUid
=
pSma
->
uid
;
req
.
tableUid
=
pSma
->
stbUid
;
req
.
tableUid
=
pSma
->
stbUid
;
req
.
dstVgId
=
pSma
->
dstVgId
;
req
.
dstTbUid
=
pSma
->
dstTbUid
;
req
.
interval
=
pSma
->
interval
;
req
.
interval
=
pSma
->
interval
;
req
.
offset
=
pSma
->
offset
;
req
.
offset
=
pSma
->
offset
;
req
.
sliding
=
pSma
->
sliding
;
req
.
sliding
=
pSma
->
sliding
;
req
.
expr
=
pSma
->
expr
;
req
.
expr
=
pSma
->
expr
;
req
.
tagsFilter
=
pSma
->
tagsFilter
;
req
.
tagsFilter
=
pSma
->
tagsFilter
;
req
.
numOfVgroups
=
pSma
->
numOfVgroups
;
req
.
schemaRow
=
pSma
->
schemaRow
;
req
.
pVgEpSet
=
pSma
->
pVgEpSet
;
req
.
schemaTag
=
pSma
->
schemaTag
;
req
.
dstTbName
=
pSma
->
dstTbName
;
// get length
// get length
int32_t
ret
=
0
;
int32_t
ret
=
0
;
...
@@ -425,14 +433,30 @@ static int32_t mndSetCreateSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans,
...
@@ -425,14 +433,30 @@ static int32_t mndSetCreateSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans,
mndReleaseDnode
(
pMnode
,
pDnode
);
mndReleaseDnode
(
pMnode
,
pDnode
);
// todo add sma info here
// todo add sma info here
SVgEpSet
*
pVgEpSet
=
NULL
;
SNode
*
pAst
=
NULL
;
int32_t
numOfVgroups
=
0
;
if
(
nodesStringToNode
(
pSma
->
ast
,
&
pAst
)
<
0
)
{
if
(
mndSmaGetVgEpSet
(
pMnode
,
pDb
,
&
pVgEpSet
,
&
numOfVgroups
)
!=
0
)
{
return
-
1
;
return
-
1
;
}
}
if
(
qExtractResultSchema
(
pAst
,
&
pSma
->
schemaRow
.
nCols
,
&
pSma
->
schemaRow
.
pSchema
)
!=
0
)
{
nodesDestroyNode
(
pAst
);
return
-
1
;
}
nodesDestroyNode
(
pAst
);
pSma
->
schemaRow
.
version
=
1
;
// TODO: the schemaTag generated by qExtractResultXXX later.
pSma
->
schemaTag
.
nCols
=
1
;
pSma
->
schemaTag
.
version
=
1
;
pSma
->
schemaTag
.
pSchema
=
taosMemoryCalloc
(
1
,
sizeof
(
SSchema
));
if
(
!
pSma
->
schemaTag
.
pSchema
)
{
return
-
1
;
}
pSma
->
schemaTag
.
pSchema
[
0
].
type
=
TSDB_DATA_TYPE_BIGINT
;
pSma
->
schemaTag
.
pSchema
[
0
].
bytes
=
TYPE_BYTES
[
TSDB_DATA_TYPE_BIGINT
];
pSma
->
schemaTag
.
pSchema
[
0
].
colId
=
pSma
->
schemaRow
.
nCols
+
PRIMARYKEY_TIMESTAMP_COL_ID
;
pSma
->
schemaTag
.
pSchema
[
0
].
flags
=
0
;
snprintf
(
pSma
->
schemaTag
.
pSchema
[
0
].
name
,
TSDB_COL_NAME_LEN
,
"groupId"
);
pSma
->
pVgEpSet
=
pVgEpSet
;
pSma
->
numOfVgroups
=
numOfVgroups
;
int32_t
smaContLen
=
0
;
int32_t
smaContLen
=
0
;
void
*
pSmaReq
=
mndBuildVCreateSmaReq
(
pMnode
,
pVgroup
,
pSma
,
&
smaContLen
);
void
*
pSmaReq
=
mndBuildVCreateSmaReq
(
pMnode
,
pVgroup
,
pSma
,
&
smaContLen
);
...
@@ -464,12 +488,15 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
...
@@ -464,12 +488,15 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
memcpy
(
smaObj
.
db
,
pDb
->
name
,
TSDB_DB_FNAME_LEN
);
memcpy
(
smaObj
.
db
,
pDb
->
name
,
TSDB_DB_FNAME_LEN
);
smaObj
.
createdTime
=
taosGetTimestampMs
();
smaObj
.
createdTime
=
taosGetTimestampMs
();
smaObj
.
uid
=
mndGenerateUid
(
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
smaObj
.
uid
=
mndGenerateUid
(
pCreate
->
name
,
TSDB_TABLE_FNAME_LEN
);
char
resultTbName
[
TSDB_TABLE_FNAME_LEN
+
16
]
=
{
0
};
snprintf
(
resultTbName
,
TSDB_TABLE_FNAME_LEN
+
16
,
"td.tsma.rst.tb.%s"
,
pCreate
->
name
);
memcpy
(
smaObj
.
dstTbName
,
resultTbName
,
TSDB_TABLE_FNAME_LEN
);
smaObj
.
dstTbUid
=
mndGenerateUid
(
smaObj
.
dstTbName
,
TSDB_TABLE_FNAME_LEN
);
smaObj
.
stbUid
=
pStb
->
uid
;
smaObj
.
stbUid
=
pStb
->
uid
;
smaObj
.
dbUid
=
pStb
->
dbUid
;
smaObj
.
dbUid
=
pStb
->
dbUid
;
smaObj
.
intervalUnit
=
pCreate
->
intervalUnit
;
smaObj
.
intervalUnit
=
pCreate
->
intervalUnit
;
smaObj
.
slidingUnit
=
pCreate
->
slidingUnit
;
smaObj
.
slidingUnit
=
pCreate
->
slidingUnit
;
smaObj
.
timezone
=
pCreate
->
timezone
;
smaObj
.
timezone
=
pCreate
->
timezone
;
smaObj
.
dstVgId
=
pCreate
->
dstVgId
;
smaObj
.
interval
=
pCreate
->
interval
;
smaObj
.
interval
=
pCreate
->
interval
;
smaObj
.
offset
=
pCreate
->
offset
;
smaObj
.
offset
=
pCreate
->
offset
;
smaObj
.
sliding
=
pCreate
->
sliding
;
smaObj
.
sliding
=
pCreate
->
sliding
;
...
@@ -1088,52 +1115,3 @@ static void mndCancelGetNextSma(SMnode *pMnode, void *pIter) {
...
@@ -1088,52 +1115,3 @@ static void mndCancelGetNextSma(SMnode *pMnode, void *pIter) {
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
sdbCancelFetch
(
pSdb
,
pIter
);
}
}
\ No newline at end of file
static
int32_t
mndSmaGetVgEpSet
(
SMnode
*
pMnode
,
SDbObj
*
pDb
,
SVgEpSet
**
ppVgEpSet
,
int32_t
*
numOfVgroups
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SVgObj
*
pVgroup
=
NULL
;
void
*
pIter
=
NULL
;
SVgEpSet
*
pVgEpSet
=
NULL
;
int32_t
nAllocVgs
=
16
;
int32_t
nVgs
=
0
;
pVgEpSet
=
taosMemoryCalloc
(
nAllocVgs
,
sizeof
(
SVgEpSet
));
if
(
!
pVgEpSet
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
while
(
1
)
{
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pIter
,
(
void
**
)
&
pVgroup
);
if
(
pIter
==
NULL
)
break
;
if
(
pVgroup
->
dbUid
!=
pDb
->
uid
)
{
sdbRelease
(
pSdb
,
pVgroup
);
continue
;
}
if
(
nVgs
>=
nAllocVgs
)
{
void
*
p
=
taosMemoryRealloc
(
pVgEpSet
,
nAllocVgs
*
2
*
sizeof
(
SVgEpSet
));
if
(
!
p
)
{
taosMemoryFree
(
pVgEpSet
);
sdbCancelFetch
(
pSdb
,
pIter
);
sdbRelease
(
pSdb
,
pVgroup
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pVgEpSet
=
(
SVgEpSet
*
)
p
;
nAllocVgs
*=
2
;
}
(
pVgEpSet
+
nVgs
)
->
vgId
=
pVgroup
->
vgId
;
(
pVgEpSet
+
nVgs
)
->
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
++
nVgs
;
sdbRelease
(
pSdb
,
pVgroup
);
}
*
ppVgEpSet
=
pVgEpSet
;
*
numOfVgroups
=
nVgs
;
return
0
;
}
source/dnode/mnode/impl/src/mndStream.c
浏览文件 @
98bc4630
...
@@ -252,8 +252,12 @@ int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast
...
@@ -252,8 +252,12 @@ int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast
}
}
if
(
qExtractResultSchema
(
pAst
,
(
int32_t
*
)
&
pStream
->
outputSchema
.
nCols
,
&
pStream
->
outputSchema
.
pSchema
)
!=
0
)
{
if
(
qExtractResultSchema
(
pAst
,
(
int32_t
*
)
&
pStream
->
outputSchema
.
nCols
,
&
pStream
->
outputSchema
.
pSchema
)
!=
0
)
{
nodesDestroyNode
(
pAst
);
return
-
1
;
return
-
1
;
}
}
// free
nodesDestroyNode
(
pAst
);
#if 0
#if 0
printf("|");
printf("|");
...
...
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
98bc4630
...
@@ -61,6 +61,12 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM
...
@@ -61,6 +61,12 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM
}
}
tsem_post
(
&
pMgmt
->
syncSem
);
tsem_post
(
&
pMgmt
->
syncSem
);
}
else
{
}
else
{
STrans
*
pTrans
=
mndAcquireTrans
(
pMnode
,
transId
);
if
(
pTrans
!=
NULL
)
{
mndTransExecute
(
pMnode
,
pTrans
);
mndReleaseTrans
(
pMnode
,
pTrans
);
}
if
(
cbMeta
.
index
-
sdbGetApplyIndex
(
pMnode
->
pSdb
)
>
100
)
{
if
(
cbMeta
.
index
-
sdbGetApplyIndex
(
pMnode
->
pSdb
)
>
100
)
{
SSnapshotMeta
sMeta
=
{
0
};
SSnapshotMeta
sMeta
=
{
0
};
if
(
syncGetSnapshotMeta
(
pMnode
->
syncMgmt
.
sync
,
&
sMeta
)
==
0
)
{
if
(
syncGetSnapshotMeta
(
pMnode
->
syncMgmt
.
sync
,
&
sMeta
)
==
0
)
{
...
...
source/dnode/mnode/impl/src/mndTrans.c
浏览文件 @
98bc4630
...
@@ -52,8 +52,8 @@ static bool mndTransPerformCommitActionStage(SMnode *pMnode, STrans *pTrans);
...
@@ -52,8 +52,8 @@ static bool mndTransPerformCommitActionStage(SMnode *pMnode, STrans *pTrans);
static
bool
mndTransPerformCommitStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
static
bool
mndTransPerformCommitStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
static
bool
mndTransPerformRollbackStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
static
bool
mndTransPerformRollbackStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
static
bool
mndTransPerfromFinishedStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
static
bool
mndTransPerfromFinishedStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
static
bool
mndCantExecuteTransAction
(
SMnode
*
pMnode
)
{
return
!
pMnode
->
deploy
&&
!
mndIsMaster
(
pMnode
);
}
static
void
mndTransExecute
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
static
void
mndTransSendRpcRsp
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
static
void
mndTransSendRpcRsp
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
static
int32_t
mndProcessTransReq
(
SRpcMsg
*
pReq
);
static
int32_t
mndProcessTransReq
(
SRpcMsg
*
pReq
);
static
int32_t
mndProcessKillTransReq
(
SRpcMsg
*
pReq
);
static
int32_t
mndProcessKillTransReq
(
SRpcMsg
*
pReq
);
...
@@ -517,12 +517,12 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOld, STrans *pNew) {
...
@@ -517,12 +517,12 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOld, STrans *pNew) {
if
(
pOld
->
stage
==
TRN_STAGE_COMMIT
)
{
if
(
pOld
->
stage
==
TRN_STAGE_COMMIT
)
{
pOld
->
stage
=
TRN_STAGE_COMMIT_ACTION
;
pOld
->
stage
=
TRN_STAGE_COMMIT_ACTION
;
mTrace
(
"trans:%d, stage from commit to commitAction"
,
pNew
->
id
);
mTrace
(
"trans:%d, stage from commit to commitAction
since perform update action
"
,
pNew
->
id
);
}
}
if
(
pOld
->
stage
==
TRN_STAGE_ROLLBACK
)
{
if
(
pOld
->
stage
==
TRN_STAGE_ROLLBACK
)
{
pOld
->
stage
=
TRN_STAGE_FINISHED
;
pOld
->
stage
=
TRN_STAGE_FINISHED
;
mTrace
(
"trans:%d, stage from rollback to finished"
,
pNew
->
id
);
mTrace
(
"trans:%d, stage from rollback to finished
since perform update action
"
,
pNew
->
id
);
}
}
return
0
;
return
0
;
}
}
...
@@ -914,7 +914,7 @@ static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransActi
...
@@ -914,7 +914,7 @@ static int32_t mndTransWriteSingleLog(SMnode *pMnode, STrans *pTrans, STransActi
static
int32_t
mndTransSendSingleMsg
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
STransAction
*
pAction
)
{
static
int32_t
mndTransSendSingleMsg
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
STransAction
*
pAction
)
{
if
(
pAction
->
msgSent
)
return
0
;
if
(
pAction
->
msgSent
)
return
0
;
if
(
!
pMnode
->
deploy
&&
!
mndIsMaster
(
pMnode
))
return
-
1
;
if
(
mndCantExecuteTransAction
(
pMnode
))
return
-
1
;
int64_t
signature
=
pTrans
->
id
;
int64_t
signature
=
pTrans
->
id
;
signature
=
(
signature
<<
32
);
signature
=
(
signature
<<
32
);
...
@@ -1114,9 +1114,9 @@ static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans)
...
@@ -1114,9 +1114,9 @@ static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans)
pTrans
->
lastEpset
=
pAction
->
epSet
;
pTrans
->
lastEpset
=
pAction
->
epSet
;
}
}
if
(
code
==
0
)
{
if
(
mndCantExecuteTransAction
(
pMnode
))
break
;
if
(
!
pMnode
->
deploy
&&
!
mndIsMaster
(
pMnode
))
break
;
if
(
code
==
0
)
{
pTrans
->
code
=
0
;
pTrans
->
code
=
0
;
pTrans
->
redoActionPos
++
;
pTrans
->
redoActionPos
++
;
mDebug
(
"trans:%d, %s:%d is executed and need sync to other mnodes"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
mDebug
(
"trans:%d, %s:%d is executed and need sync to other mnodes"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
...
@@ -1160,6 +1160,8 @@ static bool mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans) {
...
@@ -1160,6 +1160,8 @@ static bool mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans) {
code
=
mndTransExecuteRedoActions
(
pMnode
,
pTrans
);
code
=
mndTransExecuteRedoActions
(
pMnode
,
pTrans
);
}
}
if
(
mndCantExecuteTransAction
(
pMnode
))
return
false
;
if
(
code
==
0
)
{
if
(
code
==
0
)
{
pTrans
->
code
=
0
;
pTrans
->
code
=
0
;
pTrans
->
stage
=
TRN_STAGE_COMMIT
;
pTrans
->
stage
=
TRN_STAGE_COMMIT
;
...
@@ -1185,6 +1187,8 @@ static bool mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans) {
...
@@ -1185,6 +1187,8 @@ static bool mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans) {
}
}
static
bool
mndTransPerformCommitStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
static
bool
mndTransPerformCommitStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
if
(
mndCantExecuteTransAction
(
pMnode
))
return
false
;
bool
continueExec
=
true
;
bool
continueExec
=
true
;
int32_t
code
=
mndTransCommit
(
pMnode
,
pTrans
);
int32_t
code
=
mndTransCommit
(
pMnode
,
pTrans
);
...
@@ -1233,6 +1237,8 @@ static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans) {
...
@@ -1233,6 +1237,8 @@ static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans) {
bool
continueExec
=
true
;
bool
continueExec
=
true
;
int32_t
code
=
mndTransExecuteUndoActions
(
pMnode
,
pTrans
);
int32_t
code
=
mndTransExecuteUndoActions
(
pMnode
,
pTrans
);
if
(
mndCantExecuteTransAction
(
pMnode
))
return
false
;
if
(
code
==
0
)
{
if
(
code
==
0
)
{
pTrans
->
stage
=
TRN_STAGE_ROLLBACK
;
pTrans
->
stage
=
TRN_STAGE_ROLLBACK
;
mDebug
(
"trans:%d, stage from undoAction to rollback"
,
pTrans
->
id
);
mDebug
(
"trans:%d, stage from undoAction to rollback"
,
pTrans
->
id
);
...
@@ -1250,6 +1256,8 @@ static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans) {
...
@@ -1250,6 +1256,8 @@ static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans) {
}
}
static
bool
mndTransPerformRollbackStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
static
bool
mndTransPerformRollbackStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
if
(
mndCantExecuteTransAction
(
pMnode
))
return
false
;
bool
continueExec
=
true
;
bool
continueExec
=
true
;
int32_t
code
=
mndTransRollback
(
pMnode
,
pTrans
);
int32_t
code
=
mndTransRollback
(
pMnode
,
pTrans
);
...
@@ -1284,10 +1292,11 @@ static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans) {
...
@@ -1284,10 +1292,11 @@ static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans) {
return
continueExec
;
return
continueExec
;
}
}
static
void
mndTransExecute
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
void
mndTransExecute
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
bool
continueExec
=
true
;
bool
continueExec
=
true
;
while
(
continueExec
)
{
while
(
continueExec
)
{
mDebug
(
"trans:%d, continue to execute, stage:%s"
,
pTrans
->
id
,
mndTransStr
(
pTrans
->
stage
));
pTrans
->
lastExecTime
=
taosGetTimestampMs
();
pTrans
->
lastExecTime
=
taosGetTimestampMs
();
switch
(
pTrans
->
stage
)
{
switch
(
pTrans
->
stage
)
{
case
TRN_STAGE_PREPARE
:
case
TRN_STAGE_PREPARE
:
...
...
source/dnode/vnode/CMakeLists.txt
浏览文件 @
98bc4630
...
@@ -28,7 +28,6 @@ target_sources(
...
@@ -28,7 +28,6 @@ target_sources(
# sma
# sma
"src/sma/sma.c"
"src/sma/sma.c"
"src/sma/smaTDBImpl.c"
"src/sma/smaEnv.c"
"src/sma/smaEnv.c"
"src/sma/smaOpen.c"
"src/sma/smaOpen.c"
"src/sma/smaRollup.c"
"src/sma/smaRollup.c"
...
...
source/dnode/vnode/src/inc/sma.h
浏览文件 @
98bc4630
...
@@ -43,34 +43,16 @@ typedef struct SRSmaInfo SRSmaInfo;
...
@@ -43,34 +43,16 @@ typedef struct SRSmaInfo SRSmaInfo;
struct
SSmaEnv
{
struct
SSmaEnv
{
TdThreadRwlock
lock
;
TdThreadRwlock
lock
;
int8_t
type
;
int8_t
type
;
TXN
txn
;
void
*
pPool
;
// SPoolMem
SDiskID
did
;
TDB
*
dbEnv
;
// TODO: If it's better to put it in smaIndex level?
char
*
path
;
// relative path
SSmaStat
*
pStat
;
SSmaStat
*
pStat
;
};
};
#define SMA_ENV_LOCK(env) ((env)->lock)
#define SMA_ENV_LOCK(env) ((env)->lock)
#define SMA_ENV_TYPE(env) ((env)->type)
#define SMA_ENV_TYPE(env) ((env)->type)
#define SMA_ENV_DID(env) ((env)->did)
#define SMA_ENV_ENV(env) ((env)->dbEnv)
#define SMA_ENV_PATH(env) ((env)->path)
#define SMA_ENV_STAT(env) ((env)->pStat)
#define SMA_ENV_STAT(env) ((env)->pStat)
#define SMA_ENV_STAT_ITEMS(env) ((env)->pStat->smaStatItems)
#define SMA_ENV_STAT_ITEMS(env) ((env)->pStat->smaStatItems)
struct
SSmaStatItem
{
struct
SSmaStatItem
{
/**
* @brief The field 'state' is here to demonstrate if one smaIndex is ready to provide service.
* - TSDB_SMA_STAT_OK: 1) The sma calculation of history data is finished; 2) Or recevied information from
* Streaming Module or TSDB local persistence.
* - TSDB_SMA_STAT_EXPIRED: 1) If sma calculation of history TS data is not finished; 2) Or if the TSDB is open,
* without information about its previous state.
* - TSDB_SMA_STAT_DROPPED: 1)sma dropped
* N.B. only applicable to tsma
*/
int8_t
state
;
// ETsdbSmaStat
int8_t
state
;
// ETsdbSmaStat
SHashObj
*
expiredWindows
;
// key: skey of time window, value: version
STSma
*
pTSma
;
// cache schema
STSma
*
pTSma
;
// cache schema
};
};
...
@@ -84,29 +66,6 @@ struct SSmaStat {
...
@@ -84,29 +66,6 @@ struct SSmaStat {
#define SMA_STAT_ITEMS(s) ((s)->smaStatItems)
#define SMA_STAT_ITEMS(s) ((s)->smaStatItems)
#define SMA_STAT_INFO_HASH(s) ((s)->rsmaInfoHash)
#define SMA_STAT_INFO_HASH(s) ((s)->rsmaInfoHash)
struct
SSmaKey
{
TSKEY
skey
;
int64_t
groupId
;
};
typedef
struct
SDBFile
SDBFile
;
struct
SDBFile
{
int32_t
fid
;
TTB
*
pDB
;
char
*
path
;
};
int32_t
tdSmaBeginCommit
(
SSmaEnv
*
pEnv
);
int32_t
tdSmaEndCommit
(
SSmaEnv
*
pEnv
);
int32_t
smaOpenDBEnv
(
TDB
**
ppEnv
,
const
char
*
path
);
int32_t
smaCloseDBEnv
(
TDB
*
pEnv
);
int32_t
smaOpenDBF
(
TDB
*
pEnv
,
SDBFile
*
pDBF
);
int32_t
smaCloseDBF
(
SDBFile
*
pDBF
);
int32_t
smaSaveSmaToDB
(
SDBFile
*
pDBF
,
void
*
pKey
,
int32_t
keyLen
,
void
*
pVal
,
int32_t
valLen
,
TXN
*
txn
);
void
*
smaGetSmaDataByKey
(
SDBFile
*
pDBF
,
const
void
*
pKey
,
int32_t
keyLen
,
int32_t
*
valLen
);
void
tdDestroySmaEnv
(
SSmaEnv
*
pSmaEnv
);
void
tdDestroySmaEnv
(
SSmaEnv
*
pSmaEnv
);
void
*
tdFreeSmaEnv
(
SSmaEnv
*
pSmaEnv
);
void
*
tdFreeSmaEnv
(
SSmaEnv
*
pSmaEnv
);
#if 0
#if 0
...
@@ -114,13 +73,6 @@ int32_t tbGetTSmaStatus(SSma *pSma, STSma *param, void *result);
...
@@ -114,13 +73,6 @@ int32_t tbGetTSmaStatus(SSma *pSma, STSma *param, void *result);
int32_t tbRemoveTSmaData(SSma *pSma, STSma *param, STimeWindow *pWin);
int32_t tbRemoveTSmaData(SSma *pSma, STSma *param, STimeWindow *pWin);
#endif
#endif
static
FORCE_INLINE
int32_t
tdEncodeTSmaKey
(
int64_t
groupId
,
TSKEY
tsKey
,
void
**
pData
)
{
int32_t
len
=
0
;
len
+=
taosEncodeFixedI64
(
pData
,
tsKey
);
len
+=
taosEncodeFixedI64
(
pData
,
groupId
);
return
len
;
}
int32_t
tdInitSma
(
SSma
*
pSma
);
int32_t
tdInitSma
(
SSma
*
pSma
);
int32_t
tdDropTSma
(
SSma
*
pSma
,
char
*
pMsg
);
int32_t
tdDropTSma
(
SSma
*
pSma
,
char
*
pMsg
);
int32_t
tdDropTSmaData
(
SSma
*
pSma
,
int64_t
indexUid
);
int32_t
tdDropTSmaData
(
SSma
*
pSma
,
int64_t
indexUid
);
...
@@ -128,13 +80,11 @@ int32_t tdInsertRSmaData(SSma *pSma, char *msg);
...
@@ -128,13 +80,11 @@ int32_t tdInsertRSmaData(SSma *pSma, char *msg);
int32_t
tdRefSmaStat
(
SSma
*
pSma
,
SSmaStat
*
pStat
);
int32_t
tdRefSmaStat
(
SSma
*
pSma
,
SSmaStat
*
pStat
);
int32_t
tdUnRefSmaStat
(
SSma
*
pSma
,
SSmaStat
*
pStat
);
int32_t
tdUnRefSmaStat
(
SSma
*
pSma
,
SSmaStat
*
pStat
);
int32_t
tdCheckAndInitSmaEnv
(
SSma
*
pSma
,
int8_t
smaType
);
int32_t
tdCheckAndInitSmaEnv
(
SSma
*
pSma
,
int8_t
smaType
,
bool
onlyCheck
);
int32_t
tdLockSma
(
SSma
*
pSma
);
int32_t
tdLockSma
(
SSma
*
pSma
);
int32_t
tdUnLockSma
(
SSma
*
pSma
);
int32_t
tdUnLockSma
(
SSma
*
pSma
);
int32_t
tdProcessTSmaInsertImpl
(
SSma
*
pSma
,
int64_t
indexUid
,
const
char
*
msg
);
static
FORCE_INLINE
int16_t
tdTSmaAdd
(
SSma
*
pSma
,
int16_t
n
)
{
return
atomic_add_fetch_16
(
&
SMA_TSMA_NUM
(
pSma
),
n
);
}
static
FORCE_INLINE
int16_t
tdTSmaAdd
(
SSma
*
pSma
,
int16_t
n
)
{
return
atomic_add_fetch_16
(
&
SMA_TSMA_NUM
(
pSma
),
n
);
}
static
FORCE_INLINE
int16_t
tdTSmaSub
(
SSma
*
pSma
,
int16_t
n
)
{
return
atomic_sub_fetch_16
(
&
SMA_TSMA_NUM
(
pSma
),
n
);
}
static
FORCE_INLINE
int16_t
tdTSmaSub
(
SSma
*
pSma
,
int16_t
n
)
{
return
atomic_sub_fetch_16
(
&
SMA_TSMA_NUM
(
pSma
),
n
);
}
...
@@ -219,11 +169,8 @@ static int32_t tdInitSmaEnv(SSma *pSma, int8_t smaType, const char *path, SDisk
...
@@ -219,11 +169,8 @@ static int32_t tdInitSmaEnv(SSma *pSma, int8_t smaType, const char *path, SDisk
void
*
tdFreeRSmaInfo
(
SRSmaInfo
*
pInfo
);
void
*
tdFreeRSmaInfo
(
SRSmaInfo
*
pInfo
);
int32_t
tdProcessTSmaCreateImpl
(
SSma
*
pSma
,
int64_t
version
,
const
char
*
pMsg
);
int32_t
tdProcessTSmaCreateImpl
(
SSma
*
pSma
,
int64_t
version
,
const
char
*
pMsg
);
int32_t
tdUpdateExpiredWindowImpl
(
SSma
*
pSma
,
const
SSubmitReq
*
pMsg
,
int64_t
version
);
int32_t
tdProcessTSmaInsertImpl
(
SSma
*
pSma
,
int64_t
indexUid
,
const
char
*
msg
);
// TODO: This is the basic params, and should wrap the params to a queryHandle.
int32_t
tdProcessTSmaGetDaysImpl
(
SVnodeCfg
*
pCfg
,
void
*
pCont
,
uint32_t
contLen
,
int32_t
*
days
);
int32_t
tdGetTSmaDataImpl
(
SSma
*
pSma
,
char
*
pData
,
int64_t
indexUid
,
TSKEY
querySKey
,
int32_t
nMaxResult
);
int32_t
tdGetTSmaDaysImpl
(
SVnodeCfg
*
pCfg
,
void
*
pCont
,
uint32_t
contLen
,
int32_t
*
days
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
98bc4630
...
@@ -150,7 +150,6 @@ int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg);
...
@@ -150,7 +150,6 @@ int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg);
int32_t
smaOpen
(
SVnode
*
pVnode
);
int32_t
smaOpen
(
SVnode
*
pVnode
);
int32_t
smaClose
(
SSma
*
pSma
);
int32_t
smaClose
(
SSma
*
pSma
);
int32_t
tdUpdateExpireWindow
(
SSma
*
pSma
,
const
SSubmitReq
*
pMsg
,
int64_t
version
);
int32_t
tdProcessTSmaCreate
(
SSma
*
pSma
,
int64_t
version
,
const
char
*
msg
);
int32_t
tdProcessTSmaCreate
(
SSma
*
pSma
,
int64_t
version
,
const
char
*
msg
);
int32_t
tdProcessTSmaInsert
(
SSma
*
pSma
,
int64_t
indexUid
,
const
char
*
msg
);
int32_t
tdProcessTSmaInsert
(
SSma
*
pSma
,
int64_t
indexUid
,
const
char
*
msg
);
...
@@ -227,7 +226,7 @@ struct SVnode {
...
@@ -227,7 +226,7 @@ struct SVnode {
SQHandle
*
pQuery
;
SQHandle
*
pQuery
;
};
};
#define TD_VID(PVNODE) (
PVNODE)->config.vgId
#define TD_VID(PVNODE) (
(PVNODE)->config.vgId)
#define VND_TSDB(vnd) ((vnd)->pTsdb)
#define VND_TSDB(vnd) ((vnd)->pTsdb)
#define VND_RSMA0(vnd) ((vnd)->pTsdb)
#define VND_RSMA0(vnd) ((vnd)->pTsdb)
...
...
source/dnode/vnode/src/meta/metaSma.c
浏览文件 @
98bc4630
...
@@ -34,13 +34,13 @@ int32_t metaCreateTSma(SMeta *pMeta, int64_t version, SSmaCfg *pCfg) {
...
@@ -34,13 +34,13 @@ int32_t metaCreateTSma(SMeta *pMeta, int64_t version, SSmaCfg *pCfg) {
SMetaReader
mr
=
{
0
};
SMetaReader
mr
=
{
0
};
// validate req
// validate req
// save smaIndex
metaReaderInit
(
&
mr
,
pMeta
,
0
);
metaReaderInit
(
&
mr
,
pMeta
,
0
);
if
(
metaGetTableEntryByUid
(
&
mr
,
pCfg
->
indexUid
)
==
0
)
{
if
(
metaGetTableEntryByUid
(
&
mr
,
pCfg
->
indexUid
)
==
0
)
{
// TODO: just for pass case
#if 1
#if 1
terrno
=
TSDB_CODE_T
DB_T
SMA_ALREADY_EXIST
;
terrno
=
TSDB_CODE_TSMA_ALREADY_EXIST
;
metaReaderClear
(
&
mr
);
metaReaderClear
(
&
mr
);
return
-
1
;
return
-
1
;
// don't goto _err;
#else
#else
metaReaderClear
(
&
mr
);
metaReaderClear
(
&
mr
);
return
0
;
return
0
;
...
...
source/dnode/vnode/src/sma/sma.c
浏览文件 @
98bc4630
...
@@ -36,25 +36,9 @@ int32_t tdProcessTSmaCreate(SSma* pSma, int64_t version, const char* msg) {
...
@@ -36,25 +36,9 @@ int32_t tdProcessTSmaCreate(SSma* pSma, int64_t version, const char* msg) {
return
code
;
return
code
;
}
}
int32_t
tdUpdateExpireWindow
(
SSma
*
pSma
,
const
SSubmitReq
*
pMsg
,
int64_t
version
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
((
code
=
tdUpdateExpiredWindowImpl
(
pSma
,
pMsg
,
version
))
<
0
)
{
smaWarn
(
"vgId:%d, update expired sma window failed since %s"
,
SMA_VID
(
pSma
),
tstrerror
(
terrno
));
}
return
code
;
}
int32_t
tdGetTSmaData
(
SSma
*
pSma
,
char
*
pData
,
int64_t
indexUid
,
TSKEY
querySKey
,
int32_t
nMaxResult
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
((
code
=
tdGetTSmaDataImpl
(
pSma
,
pData
,
indexUid
,
querySKey
,
nMaxResult
))
<
0
)
{
smaWarn
(
"vgId:%d, get tsma data failed since %s"
,
SMA_VID
(
pSma
),
tstrerror
(
terrno
));
}
return
code
;
}
int32_t
smaGetTSmaDays
(
SVnodeCfg
*
pCfg
,
void
*
pCont
,
uint32_t
contLen
,
int32_t
*
days
)
{
int32_t
smaGetTSmaDays
(
SVnodeCfg
*
pCfg
,
void
*
pCont
,
uint32_t
contLen
,
int32_t
*
days
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
((
code
=
td
GetTSma
DaysImpl
(
pCfg
,
pCont
,
contLen
,
days
))
<
0
)
{
if
((
code
=
td
ProcessTSmaGet
DaysImpl
(
pCfg
,
pCont
,
contLen
,
days
))
<
0
)
{
smaWarn
(
"vgId:%d, get tsma days failed since %s"
,
pCfg
->
vgId
,
tstrerror
(
terrno
));
smaWarn
(
"vgId:%d, get tsma days failed since %s"
,
pCfg
->
vgId
,
tstrerror
(
terrno
));
}
}
smaDebug
(
"vgId:%d, get tsma days %d"
,
pCfg
->
vgId
,
*
days
);
smaDebug
(
"vgId:%d, get tsma days %d"
,
pCfg
->
vgId
,
*
days
);
...
...
source/dnode/vnode/src/sma/smaEnv.c
浏览文件 @
98bc4630
...
@@ -151,31 +151,11 @@ static SSmaEnv *tdNewSmaEnv(const SSma *pSma, int8_t smaType, const char *path,
...
@@ -151,31 +151,11 @@ static SSmaEnv *tdNewSmaEnv(const SSma *pSma, int8_t smaType, const char *path,
return
NULL
;
return
NULL
;
}
}
ASSERT
(
path
&&
(
strlen
(
path
)
>
0
));
SMA_ENV_PATH
(
pEnv
)
=
strdup
(
path
);
if
(
!
SMA_ENV_PATH
(
pEnv
))
{
tdFreeSmaEnv
(
pEnv
);
return
NULL
;
}
SMA_ENV_DID
(
pEnv
)
=
did
;
if
(
tdInitSmaStat
(
&
SMA_ENV_STAT
(
pEnv
),
smaType
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tdInitSmaStat
(
&
SMA_ENV_STAT
(
pEnv
),
smaType
)
!=
TSDB_CODE_SUCCESS
)
{
tdFreeSmaEnv
(
pEnv
);
tdFreeSmaEnv
(
pEnv
);
return
NULL
;
return
NULL
;
}
}
char
aname
[
TSDB_FILENAME_LEN
]
=
{
0
};
tfsAbsoluteName
(
SMA_TFS
(
pSma
),
did
,
path
,
aname
);
if
(
smaOpenDBEnv
(
&
pEnv
->
dbEnv
,
aname
)
!=
TSDB_CODE_SUCCESS
)
{
tdFreeSmaEnv
(
pEnv
);
return
NULL
;
}
if
(
!
(
pEnv
->
pPool
=
openPool
()))
{
tdFreeSmaEnv
(
pEnv
);
return
NULL
;
}
return
pEnv
;
return
pEnv
;
}
}
...
@@ -205,10 +185,7 @@ void tdDestroySmaEnv(SSmaEnv *pSmaEnv) {
...
@@ -205,10 +185,7 @@ void tdDestroySmaEnv(SSmaEnv *pSmaEnv) {
if
(
pSmaEnv
)
{
if
(
pSmaEnv
)
{
tdDestroySmaState
(
pSmaEnv
->
pStat
,
SMA_ENV_TYPE
(
pSmaEnv
));
tdDestroySmaState
(
pSmaEnv
->
pStat
,
SMA_ENV_TYPE
(
pSmaEnv
));
taosMemoryFreeClear
(
pSmaEnv
->
pStat
);
taosMemoryFreeClear
(
pSmaEnv
->
pStat
);
taosMemoryFreeClear
(
pSmaEnv
->
path
);
taosThreadRwlockDestroy
(
&
(
pSmaEnv
->
lock
));
taosThreadRwlockDestroy
(
&
(
pSmaEnv
->
lock
));
smaCloseDBEnv
(
pSmaEnv
->
dbEnv
);
closePool
(
pSmaEnv
->
pPool
);
}
}
}
}
...
@@ -242,7 +219,7 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType) {
...
@@ -242,7 +219,7 @@ static int32_t tdInitSmaStat(SSmaStat **pSmaStat, int8_t smaType) {
}
}
/**
/**
* 1. Lazy mode utilized when init SSmaStat to update expire
d
window(or hungry mode when tdNew).
* 1. Lazy mode utilized when init SSmaStat to update expire window(or hungry mode when tdNew).
* 2. Currently, there is mutex lock when init SSmaEnv, thus no need add lock on SSmaStat, and please add lock if
* 2. Currently, there is mutex lock when init SSmaEnv, thus no need add lock on SSmaStat, and please add lock if
* tdInitSmaStat invoked in other multithread environment later.
* tdInitSmaStat invoked in other multithread environment later.
*/
*/
...
@@ -280,7 +257,6 @@ void *tdFreeSmaStatItem(SSmaStatItem *pSmaStatItem) {
...
@@ -280,7 +257,6 @@ void *tdFreeSmaStatItem(SSmaStatItem *pSmaStatItem) {
if
(
pSmaStatItem
)
{
if
(
pSmaStatItem
)
{
tDestroyTSma
(
pSmaStatItem
->
pTSma
);
tDestroyTSma
(
pSmaStatItem
->
pTSma
);
taosMemoryFreeClear
(
pSmaStatItem
->
pTSma
);
taosMemoryFreeClear
(
pSmaStatItem
->
pTSma
);
taosHashCleanup
(
pSmaStatItem
->
expiredWindows
);
taosMemoryFreeClear
(
pSmaStatItem
);
taosMemoryFreeClear
(
pSmaStatItem
);
}
}
return
NULL
;
return
NULL
;
...
@@ -341,7 +317,7 @@ int32_t tdUnLockSma(SSma *pSma) {
...
@@ -341,7 +317,7 @@ int32_t tdUnLockSma(SSma *pSma) {
return
0
;
return
0
;
}
}
int32_t
tdCheckAndInitSmaEnv
(
SSma
*
pSma
,
int8_t
smaType
)
{
int32_t
tdCheckAndInitSmaEnv
(
SSma
*
pSma
,
int8_t
smaType
,
bool
onlyCheck
)
{
SSmaEnv
*
pEnv
=
NULL
;
SSmaEnv
*
pEnv
=
NULL
;
// return if already init
// return if already init
...
@@ -399,63 +375,3 @@ int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType) {
...
@@ -399,63 +375,3 @@ int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
};
};
int32_t
tdSmaBeginCommit
(
SSmaEnv
*
pEnv
)
{
TXN
*
pTxn
=
&
pEnv
->
txn
;
// start a new txn
tdbTxnOpen
(
pTxn
,
0
,
poolMalloc
,
poolFree
,
pEnv
->
pPool
,
TDB_TXN_WRITE
|
TDB_TXN_READ_UNCOMMITTED
);
if
(
tdbBegin
(
pEnv
->
dbEnv
,
pTxn
)
!=
0
)
{
smaWarn
(
"tdSma tdb begin commit fail"
);
return
-
1
;
}
return
0
;
}
int32_t
tdSmaEndCommit
(
SSmaEnv
*
pEnv
)
{
TXN
*
pTxn
=
&
pEnv
->
txn
;
// Commit current txn
if
(
tdbCommit
(
pEnv
->
dbEnv
,
pTxn
)
!=
0
)
{
smaWarn
(
"tdSma tdb end commit fail"
);
return
-
1
;
}
tdbTxnClose
(
pTxn
);
clearPool
(
pEnv
->
pPool
);
return
0
;
}
#if 0
/**
* @brief Get the start TS key of the last data block of one interval/sliding.
*
* @param pSma
* @param param
* @param result
* @return int32_t
* 1) Return 0 and fill the result if the check procedure is normal;
* 2) Return -1 if error occurs during the check procedure.
*/
int32_t tdGetTSmaStatus(SSma *pSma, void *smaIndex, void *result) {
const char *procedure = "";
if (strncmp(procedure, "get the start TS key of the last data block", 100) != 0) {
return -1;
}
// fill the result
return TSDB_CODE_SUCCESS;
}
/**
* @brief Remove the tSma data files related to param between pWin.
*
* @param pSma
* @param param
* @param pWin
* @return int32_t
*/
int32_t tdRemoveTSmaData(SSma *pSma, void *smaIndex, STimeWindow *pWin) {
// for ("tSmaFiles of param-interval-sliding between pWin") {
// // remove the tSmaFile
// }
return TSDB_CODE_SUCCESS;
}
#endif
source/dnode/vnode/src/sma/smaRollup.c
浏览文件 @
98bc4630
...
@@ -65,7 +65,7 @@ static FORCE_INLINE int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SA
...
@@ -65,7 +65,7 @@ static FORCE_INLINE int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SA
pRSmaInfo
=
taosHashGet
(
SMA_STAT_INFO_HASH
(
pStat
),
suid
,
sizeof
(
tb_uid_t
));
pRSmaInfo
=
taosHashGet
(
SMA_STAT_INFO_HASH
(
pStat
),
suid
,
sizeof
(
tb_uid_t
));
if
(
!
pRSmaInfo
||
!
(
pRSmaInfo
=
*
(
SRSmaInfo
**
)
pRSmaInfo
))
{
if
(
!
pRSmaInfo
||
!
(
pRSmaInfo
=
*
(
SRSmaInfo
**
)
pRSmaInfo
))
{
smaError
(
"vgId:%d, failed to get rsma info for uid:%"
PRIi64
,
SMA_VID
(
pSma
),
*
suid
);
smaError
(
"vgId:%d, failed to get rsma info for uid:%"
PRIi64
,
SMA_VID
(
pSma
),
*
suid
);
terrno
=
TSDB_CODE_
TDB_INVALID_SMA
_STAT
;
terrno
=
TSDB_CODE_
RSMA_INVALID
_STAT
;
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
...
@@ -132,7 +132,7 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui
...
@@ -132,7 +132,7 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui
SSmaStat
*
pStat
=
SMA_ENV_STAT
(
pEnv
);
SSmaStat
*
pStat
=
SMA_ENV_STAT
(
pEnv
);
SHashObj
*
infoHash
=
NULL
;
SHashObj
*
infoHash
=
NULL
;
if
(
!
pStat
||
!
(
infoHash
=
SMA_STAT_INFO_HASH
(
pStat
)))
{
if
(
!
pStat
||
!
(
infoHash
=
SMA_STAT_INFO_HASH
(
pStat
)))
{
terrno
=
TSDB_CODE_
TDB_INVALID_SMA
_STAT
;
terrno
=
TSDB_CODE_
RSMA_INVALID
_STAT
;
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
...
@@ -167,13 +167,13 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui
...
@@ -167,13 +167,13 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui
*/
*/
int32_t
tdProcessRSmaCreate
(
SVnode
*
pVnode
,
SVCreateStbReq
*
pReq
)
{
int32_t
tdProcessRSmaCreate
(
SVnode
*
pVnode
,
SVCreateStbReq
*
pReq
)
{
SSma
*
pSma
=
pVnode
->
pSma
;
SSma
*
pSma
=
pVnode
->
pSma
;
SMeta
*
pMeta
=
pVnode
->
pMeta
;
SMsgCb
*
pMsgCb
=
&
pVnode
->
msgCb
;
if
(
!
pReq
->
rollup
)
{
if
(
!
pReq
->
rollup
)
{
smaTrace
(
"vgId:%d, return directly since no rollup for stable %s %"
PRIi64
,
SMA_VID
(
pSma
),
pReq
->
name
,
pReq
->
suid
);
smaTrace
(
"vgId:%d, return directly since no rollup for stable %s %"
PRIi64
,
SMA_VID
(
pSma
),
pReq
->
name
,
pReq
->
suid
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SMeta
*
pMeta
=
pVnode
->
pMeta
;
SMsgCb
*
pMsgCb
=
&
pVnode
->
msgCb
;
SRSmaParam
*
param
=
&
pReq
->
pRSmaParam
;
SRSmaParam
*
param
=
&
pReq
->
pRSmaParam
;
if
((
param
->
qmsg1Len
==
0
)
&&
(
param
->
qmsg2Len
==
0
))
{
if
((
param
->
qmsg1Len
==
0
)
&&
(
param
->
qmsg2Len
==
0
))
{
...
@@ -181,7 +181,7 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) {
...
@@ -181,7 +181,7 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
tdCheckAndInitSmaEnv
(
pSma
,
TSDB_SMA_TYPE_ROLLUP
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tdCheckAndInitSmaEnv
(
pSma
,
TSDB_SMA_TYPE_ROLLUP
,
false
)
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
TSDB_CODE_TDB_INIT_FAILED
;
terrno
=
TSDB_CODE_TDB_INIT_FAILED
;
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
...
...
source/dnode/vnode/src/sma/smaTDBImpl.c
已删除
100644 → 0
浏览文件 @
6af7d4cf
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define ALLOW_FORBID_FUNC
#include "sma.h"
int32_t
smaOpenDBEnv
(
TDB
**
ppEnv
,
const
char
*
path
)
{
int
ret
=
0
;
if
(
path
==
NULL
)
return
-
1
;
ret
=
tdbOpen
(
path
,
4096
,
256
,
ppEnv
);
// use as param
if
(
ret
!=
0
)
{
smaError
(
"failed to create tsdb db env, ret = %d"
,
ret
);
return
-
1
;
}
return
0
;
}
int32_t
smaCloseDBEnv
(
TDB
*
pEnv
)
{
return
tdbClose
(
pEnv
);
}
static
inline
int
tdSmaKeyCmpr
(
const
void
*
arg1
,
int
len1
,
const
void
*
arg2
,
int
len2
)
{
const
SSmaKey
*
pKey1
=
(
const
SSmaKey
*
)
arg1
;
const
SSmaKey
*
pKey2
=
(
const
SSmaKey
*
)
arg2
;
ASSERT
(
len1
==
len2
&&
len1
==
sizeof
(
SSmaKey
));
if
(
pKey1
->
skey
<
pKey2
->
skey
)
{
return
-
1
;
}
else
if
(
pKey1
->
skey
>
pKey2
->
skey
)
{
return
1
;
}
if
(
pKey1
->
groupId
<
pKey2
->
groupId
)
{
return
-
1
;
}
else
if
(
pKey1
->
groupId
>
pKey2
->
groupId
)
{
return
1
;
}
return
0
;
}
static
int32_t
smaOpenDBDb
(
TTB
**
ppDB
,
TDB
*
pEnv
,
const
char
*
pFName
)
{
tdb_cmpr_fn_t
compFunc
;
// Create a database
compFunc
=
tdSmaKeyCmpr
;
if
(
tdbTbOpen
(
pFName
,
-
1
,
-
1
,
compFunc
,
pEnv
,
ppDB
)
<
0
)
{
return
-
1
;
}
return
0
;
}
static
int32_t
smaCloseDBDb
(
TTB
*
pDB
)
{
return
tdbTbClose
(
pDB
);
}
int32_t
smaOpenDBF
(
TDB
*
pEnv
,
SDBFile
*
pDBF
)
{
// TEnv is shared by a group of SDBFile
if
(
!
pEnv
||
!
pDBF
)
{
terrno
=
TSDB_CODE_INVALID_PTR
;
return
-
1
;
}
// Open DBF
if
(
smaOpenDBDb
(
&
(
pDBF
->
pDB
),
pEnv
,
pDBF
->
path
)
<
0
)
{
smaError
(
"failed to open DBF: %s"
,
pDBF
->
path
);
smaCloseDBDb
(
pDBF
->
pDB
);
return
-
1
;
}
return
0
;
}
int32_t
smaCloseDBF
(
SDBFile
*
pDBF
)
{
int32_t
ret
=
0
;
if
(
pDBF
->
pDB
)
{
ret
=
smaCloseDBDb
(
pDBF
->
pDB
);
pDBF
->
pDB
=
NULL
;
}
taosMemoryFreeClear
(
pDBF
->
path
);
return
ret
;
}
int32_t
smaSaveSmaToDB
(
SDBFile
*
pDBF
,
void
*
pKey
,
int32_t
keyLen
,
void
*
pVal
,
int32_t
valLen
,
TXN
*
txn
)
{
int32_t
ret
;
printf
(
"save tsma data into %s, keyLen:%d valLen:%d txn:%p
\n
"
,
pDBF
->
path
,
keyLen
,
valLen
,
txn
);
ret
=
tdbTbUpsert
(
pDBF
->
pDB
,
pKey
,
keyLen
,
pVal
,
valLen
,
txn
);
if
(
ret
<
0
)
{
smaError
(
"failed to upsert tsma data into db, ret = %d"
,
ret
);
return
-
1
;
}
return
0
;
}
void
*
smaGetSmaDataByKey
(
SDBFile
*
pDBF
,
const
void
*
pKey
,
int32_t
keyLen
,
int32_t
*
valLen
)
{
void
*
pVal
=
NULL
;
int
ret
;
ret
=
tdbTbGet
(
pDBF
->
pDB
,
pKey
,
keyLen
,
&
pVal
,
valLen
);
if
(
ret
<
0
)
{
smaError
(
"failed to get tsma data from db, ret = %d"
,
ret
);
return
NULL
;
}
ASSERT
(
*
valLen
>=
0
);
// TODO: lock?
// TODO: Would the key/value be destoryed during return the data?
// TODO: How about the key is updated while value length is changed? The original value buffer would be freed
// automatically?
return
pVal
;
}
\ No newline at end of file
source/dnode/vnode/src/sma/smaTimeRange.c
已删除
100644 → 0
浏览文件 @
6af7d4cf
此差异已折叠。
点击以展开。
source/dnode/vnode/src/sma/smaTimeRange2.c
浏览文件 @
98bc4630
此差异已折叠。
点击以展开。
source/dnode/vnode/src/tq/tqPush.c
浏览文件 @
98bc4630
...
@@ -238,9 +238,6 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
...
@@ -238,9 +238,6 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
if
(
msgType
==
TDMT_VND_SUBMIT
)
{
if
(
msgType
==
TDMT_VND_SUBMIT
)
{
if
(
taosHashGetSize
(
pTq
->
pStreamTasks
)
==
0
)
return
0
;
if
(
taosHashGetSize
(
pTq
->
pStreamTasks
)
==
0
)
return
0
;
if
(
tdUpdateExpireWindow
(
pTq
->
pVnode
->
pSma
,
msg
,
ver
)
!=
0
)
{
// TODO handle sma error
}
void
*
data
=
taosMemoryMalloc
(
msgLen
);
void
*
data
=
taosMemoryMalloc
(
msgLen
);
if
(
data
==
NULL
)
{
if
(
data
==
NULL
)
{
return
-
1
;
return
-
1
;
...
...
source/dnode/vnode/src/tsdb/tsdbCommit.c
浏览文件 @
98bc4630
...
@@ -106,7 +106,7 @@ int32_t tsdbCommit(STsdb *pTsdb) {
...
@@ -106,7 +106,7 @@ int32_t tsdbCommit(STsdb *pTsdb) {
return
code
;
return
code
;
_err:
_err:
tsdbError
(
"vgId:%d failed to commit since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
tsdbError
(
"vgId:%d
,
failed to commit since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
tstrerror
(
code
));
return
code
;
return
code
;
}
}
...
...
source/dnode/vnode/src/tsdb/tsdbMemTable.c
浏览文件 @
98bc4630
...
@@ -176,13 +176,13 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid
...
@@ -176,13 +176,13 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid
pMemTable
->
nDel
++
;
pMemTable
->
nDel
++
;
tsdbError
(
"vgId:%d delete data from table suid:%"
PRId64
" uid:%"
PRId64
" skey:%"
PRId64
" eKey:%"
PRId64
tsdbError
(
"vgId:%d
,
delete data from table suid:%"
PRId64
" uid:%"
PRId64
" skey:%"
PRId64
" eKey:%"
PRId64
" since %s"
,
" since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
suid
,
uid
,
sKey
,
eKey
,
tstrerror
(
code
));
TD_VID
(
pTsdb
->
pVnode
),
suid
,
uid
,
sKey
,
eKey
,
tstrerror
(
code
));
return
code
;
return
code
;
_err:
_err:
tsdbError
(
"vgId:%d failed to delete data from table suid:%"
PRId64
" uid:%"
PRId64
" skey:%"
PRId64
" eKey:%"
PRId64
tsdbError
(
"vgId:%d
,
failed to delete data from table suid:%"
PRId64
" uid:%"
PRId64
" skey:%"
PRId64
" eKey:%"
PRId64
" since %s"
,
" since %s"
,
TD_VID
(
pTsdb
->
pVnode
),
suid
,
uid
,
sKey
,
eKey
,
tstrerror
(
code
));
TD_VID
(
pTsdb
->
pVnode
),
suid
,
uid
,
sKey
,
eKey
,
tstrerror
(
code
));
return
code
;
return
code
;
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
98bc4630
...
@@ -225,6 +225,7 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
...
@@ -225,6 +225,7 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
vTrace
(
"message in fetch queue is processing"
);
vTrace
(
"message in fetch queue is processing"
);
char
*
msgstr
=
POINTER_SHIFT
(
pMsg
->
pCont
,
sizeof
(
SMsgHead
));
char
*
msgstr
=
POINTER_SHIFT
(
pMsg
->
pCont
,
sizeof
(
SMsgHead
));
int32_t
msgLen
=
pMsg
->
contLen
-
sizeof
(
SMsgHead
);
int32_t
msgLen
=
pMsg
->
contLen
-
sizeof
(
SMsgHead
);
switch
(
pMsg
->
msgType
)
{
switch
(
pMsg
->
msgType
)
{
case
TDMT_VND_FETCH
:
case
TDMT_VND_FETCH
:
return
qWorkerProcessFetchMsg
(
pVnode
,
pVnode
->
pQuery
,
pMsg
,
0
);
return
qWorkerProcessFetchMsg
(
pVnode
,
pVnode
->
pQuery
,
pMsg
,
0
);
...
@@ -236,13 +237,10 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
...
@@ -236,13 +237,10 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
return
qWorkerProcessDropMsg
(
pVnode
,
pVnode
->
pQuery
,
pMsg
,
0
);
return
qWorkerProcessDropMsg
(
pVnode
,
pVnode
->
pQuery
,
pMsg
,
0
);
case
TDMT_VND_QUERY_HEARTBEAT
:
case
TDMT_VND_QUERY_HEARTBEAT
:
return
qWorkerProcessHbMsg
(
pVnode
,
pVnode
->
pQuery
,
pMsg
,
0
);
return
qWorkerProcessHbMsg
(
pVnode
,
pVnode
->
pQuery
,
pMsg
,
0
);
case
TDMT_VND_TABLE_META
:
case
TDMT_VND_TABLE_META
:
return
vnodeGetTableMeta
(
pVnode
,
pMsg
);
return
vnodeGetTableMeta
(
pVnode
,
pMsg
);
case
TDMT_VND_CONSUME
:
case
TDMT_VND_CONSUME
:
return
tqProcessPollReq
(
pVnode
->
pTq
,
pMsg
,
pInfo
->
workerId
);
return
tqProcessPollReq
(
pVnode
->
pTq
,
pMsg
,
pInfo
->
workerId
);
case
TDMT_STREAM_TASK_RUN
:
case
TDMT_STREAM_TASK_RUN
:
return
tqProcessTaskRunReq
(
pVnode
->
pTq
,
pMsg
);
return
tqProcessTaskRunReq
(
pVnode
->
pTq
,
pMsg
);
case
TDMT_STREAM_TASK_DISPATCH
:
case
TDMT_STREAM_TASK_DISPATCH
:
...
@@ -279,7 +277,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRp
...
@@ -279,7 +277,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRp
void
smaHandleRes
(
void
*
pVnode
,
int64_t
smaId
,
const
SArray
*
data
)
{
void
smaHandleRes
(
void
*
pVnode
,
int64_t
smaId
,
const
SArray
*
data
)
{
// TODO
// TODO
// blockDebugShowData(data);
// blockDebugShowData(data
, __func__
);
tdProcessTSmaInsert
(((
SVnode
*
)
pVnode
)
->
pSma
,
smaId
,
(
const
char
*
)
data
);
tdProcessTSmaInsert
(((
SVnode
*
)
pVnode
)
->
pSma
,
smaId
,
(
const
char
*
)
data
);
}
}
...
...
source/dnode/vnode/test/tsdbSmaTest.cpp
浏览文件 @
98bc4630
...
@@ -373,7 +373,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
...
@@ -373,7 +373,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
pTsdb
->
pTfs
=
tfsOpen
(
&
pDisks
,
numOfDisks
);
pTsdb
->
pTfs
=
tfsOpen
(
&
pDisks
,
numOfDisks
);
EXPECT_NE
(
pTsdb
->
pTfs
,
nullptr
);
EXPECT_NE
(
pTsdb
->
pTfs
,
nullptr
);
// generate SSubmitReq msg and update expire
d
window
// generate SSubmitReq msg and update expire window
int16_t
schemaVer
=
0
;
int16_t
schemaVer
=
0
;
uint32_t
mockRowLen
=
sizeof
(
STSRow
);
uint32_t
mockRowLen
=
sizeof
(
STSRow
);
uint32_t
mockRowNum
=
2
;
uint32_t
mockRowNum
=
2
;
...
...
source/libs/executor/src/timewindowoperator.c
浏览文件 @
98bc4630
...
@@ -2649,7 +2649,7 @@ typedef SResultWindowInfo* (*__get_win_info_)(void*);
...
@@ -2649,7 +2649,7 @@ typedef SResultWindowInfo* (*__get_win_info_)(void*);
SResultWindowInfo
*
getSessionWinInfo
(
void
*
pData
)
{
return
(
SResultWindowInfo
*
)
pData
;
}
SResultWindowInfo
*
getSessionWinInfo
(
void
*
pData
)
{
return
(
SResultWindowInfo
*
)
pData
;
}
SResultWindowInfo
*
getStateWinInfo
(
void
*
pData
)
{
return
&
((
SStateWindowInfo
*
)
pData
)
->
winInfo
;
}
SResultWindowInfo
*
getStateWinInfo
(
void
*
pData
)
{
return
&
((
SStateWindowInfo
*
)
pData
)
->
winInfo
;
}
int32_t
closeSessionWindow
(
SArray
*
pWins
,
STimeWindowAggSupp
*
pTwSup
,
SArray
*
pClosed
,
int8_t
calTrigger
,
int32_t
closeSessionWindow
(
SArray
*
pWins
,
STimeWindowAggSupp
*
pTwSup
,
SArray
*
pClosed
,
__get_win_info_
fn
)
{
__get_win_info_
fn
)
{
// Todo(liuyao) save window to tdb
// Todo(liuyao) save window to tdb
int32_t
size
=
taosArrayGetSize
(
pWins
);
int32_t
size
=
taosArrayGetSize
(
pWins
);
...
@@ -2658,19 +2658,9 @@ int32_t closeSessionWindow(SArray* pWins, STimeWindowAggSupp* pTwSup, SArray* pC
...
@@ -2658,19 +2658,9 @@ int32_t closeSessionWindow(SArray* pWins, STimeWindowAggSupp* pTwSup, SArray* pC
SResultWindowInfo
*
pSeWin
=
fn
(
pWin
);
SResultWindowInfo
*
pSeWin
=
fn
(
pWin
);
if
(
pSeWin
->
win
.
ekey
<
pTwSup
->
maxTs
-
pTwSup
->
waterMark
)
{
if
(
pSeWin
->
win
.
ekey
<
pTwSup
->
maxTs
-
pTwSup
->
waterMark
)
{
if
(
!
pSeWin
->
isClosed
)
{
if
(
!
pSeWin
->
isClosed
)
{
SResKeyPos
*
pos
=
taosMemoryMalloc
(
sizeof
(
SResKeyPos
)
+
sizeof
(
uint64_t
));
if
(
pos
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pos
->
groupId
=
0
;
pos
->
pos
=
pSeWin
->
pos
;
*
(
int64_t
*
)
pos
->
key
=
pSeWin
->
win
.
ekey
;
if
(
!
taosArrayPush
(
pClosed
,
&
pos
))
{
taosMemoryFree
(
pos
);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pSeWin
->
isClosed
=
true
;
pSeWin
->
isClosed
=
true
;
if
(
calTrigger
==
STREAM_TRIGGER_WINDOW_CLOSE
)
{
if
(
pTwSup
->
calTrigger
==
STREAM_TRIGGER_WINDOW_CLOSE
)
{
int32_t
code
=
saveResult
(
pSeWin
->
win
.
skey
,
pSeWin
->
pos
.
pageId
,
pSeWin
->
pos
.
offset
,
0
,
pClosed
);
pSeWin
->
isOutput
=
true
;
pSeWin
->
isOutput
=
true
;
}
}
}
}
...
@@ -2681,6 +2671,19 @@ int32_t closeSessionWindow(SArray* pWins, STimeWindowAggSupp* pTwSup, SArray* pC
...
@@ -2681,6 +2671,19 @@ int32_t closeSessionWindow(SArray* pWins, STimeWindowAggSupp* pTwSup, SArray* pC
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
getAllSessionWindow
(
SArray
*
pWins
,
SArray
*
pClosed
,
__get_win_info_
fn
)
{
int32_t
size
=
taosArrayGetSize
(
pWins
);
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
void
*
pWin
=
taosArrayGet
(
pWins
,
i
);
SResultWindowInfo
*
pSeWin
=
fn
(
pWin
);
if
(
!
pSeWin
->
isClosed
)
{
int32_t
code
=
saveResult
(
pSeWin
->
win
.
skey
,
pSeWin
->
pos
.
pageId
,
pSeWin
->
pos
.
offset
,
0
,
pClosed
);
pSeWin
->
isOutput
=
true
;
}
}
return
TSDB_CODE_SUCCESS
;
}
static
SSDataBlock
*
doStreamSessionAgg
(
SOperatorInfo
*
pOperator
)
{
static
SSDataBlock
*
doStreamSessionAgg
(
SOperatorInfo
*
pOperator
)
{
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
return
NULL
;
return
NULL
;
...
@@ -2703,6 +2706,7 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
...
@@ -2703,6 +2706,7 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
_hash_fn_t
hashFn
=
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
);
_hash_fn_t
hashFn
=
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
);
SHashObj
*
pStUpdated
=
taosHashInit
(
64
,
hashFn
,
true
,
HASH_NO_LOCK
);
SHashObj
*
pStUpdated
=
taosHashInit
(
64
,
hashFn
,
true
,
HASH_NO_LOCK
);
SOperatorInfo
*
downstream
=
pOperator
->
pDownstream
[
0
];
SOperatorInfo
*
downstream
=
pOperator
->
pDownstream
[
0
];
SArray
*
pUpdated
=
taosArrayInit
(
16
,
POINTER_BYTES
);
while
(
1
)
{
while
(
1
)
{
SSDataBlock
*
pBlock
=
downstream
->
fpSet
.
getNextFn
(
downstream
);
SSDataBlock
*
pBlock
=
downstream
->
fpSet
.
getNextFn
(
downstream
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
...
@@ -2723,7 +2727,12 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
...
@@ -2723,7 +2727,12 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
}
}
taosArrayDestroy
(
pWins
);
taosArrayDestroy
(
pWins
);
continue
;
continue
;
}
else
if
(
pBlock
->
info
.
type
==
STREAM_GET_ALL
&&
pInfo
->
twAggSup
.
calTrigger
==
STREAM_TRIGGER_MAX_DELAY
)
{
getAllSessionWindow
(
pInfo
->
streamAggSup
.
pResultRows
,
pUpdated
,
getSessionWinInfo
);
continue
;
}
}
if
(
isFinalSession
(
pInfo
))
{
if
(
isFinalSession
(
pInfo
))
{
int32_t
childIndex
=
0
;
// Todo(liuyao) get child id from SSDataBlock
int32_t
childIndex
=
0
;
// Todo(liuyao) get child id from SSDataBlock
SOptrBasicInfo
*
pChildOp
=
taosArrayGetP
(
pInfo
->
pChildren
,
childIndex
);
SOptrBasicInfo
*
pChildOp
=
taosArrayGetP
(
pInfo
->
pChildren
,
childIndex
);
...
@@ -2735,15 +2744,10 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
...
@@ -2735,15 +2744,10 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
// restore the value
// restore the value
pOperator
->
status
=
OP_RES_TO_RETURN
;
pOperator
->
status
=
OP_RES_TO_RETURN
;
SArray
*
pClosed
=
taosArrayInit
(
16
,
POINTER_BYTES
);
closeSessionWindow
(
pInfo
->
streamAggSup
.
pResultRows
,
&
pInfo
->
twAggSup
,
pUpdated
,
closeSessionWindow
(
pInfo
->
streamAggSup
.
pResultRows
,
&
pInfo
->
twAggSup
,
pClosed
,
pInfo
->
twAggSup
.
calTrigger
,
getSessionWinInfo
);
getSessionWinInfo
);
SArray
*
pUpdated
=
taosArrayInit
(
16
,
POINTER_BYTES
);
copyUpdateResult
(
pStUpdated
,
pUpdated
,
pBInfo
->
pRes
->
info
.
groupId
);
copyUpdateResult
(
pStUpdated
,
pUpdated
,
pBInfo
->
pRes
->
info
.
groupId
);
taosHashCleanup
(
pStUpdated
);
taosHashCleanup
(
pStUpdated
);
if
(
pInfo
->
twAggSup
.
calTrigger
==
STREAM_TRIGGER_WINDOW_CLOSE
)
{
taosArrayAddAll
(
pUpdated
,
pClosed
);
}
finalizeUpdatedResult
(
pOperator
->
numOfExprs
,
pInfo
->
streamAggSup
.
pResultBuf
,
pUpdated
,
finalizeUpdatedResult
(
pOperator
->
numOfExprs
,
pInfo
->
streamAggSup
.
pResultBuf
,
pUpdated
,
pInfo
->
binfo
.
rowCellInfoOffset
);
pInfo
->
binfo
.
rowCellInfoOffset
);
...
@@ -3067,6 +3071,7 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) {
...
@@ -3067,6 +3071,7 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) {
_hash_fn_t
hashFn
=
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
);
_hash_fn_t
hashFn
=
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
);
SHashObj
*
pSeUpdated
=
taosHashInit
(
64
,
hashFn
,
true
,
HASH_NO_LOCK
);
SHashObj
*
pSeUpdated
=
taosHashInit
(
64
,
hashFn
,
true
,
HASH_NO_LOCK
);
SOperatorInfo
*
downstream
=
pOperator
->
pDownstream
[
0
];
SOperatorInfo
*
downstream
=
pOperator
->
pDownstream
[
0
];
SArray
*
pUpdated
=
taosArrayInit
(
16
,
POINTER_BYTES
);
while
(
1
)
{
while
(
1
)
{
SSDataBlock
*
pBlock
=
downstream
->
fpSet
.
getNextFn
(
downstream
);
SSDataBlock
*
pBlock
=
downstream
->
fpSet
.
getNextFn
(
downstream
);
if
(
pBlock
==
NULL
)
{
if
(
pBlock
==
NULL
)
{
...
@@ -3078,6 +3083,10 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) {
...
@@ -3078,6 +3083,10 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) {
doClearStateWindows
(
&
pInfo
->
streamAggSup
,
pBlock
,
pInfo
->
primaryTsIndex
,
&
pInfo
->
stateCol
,
pInfo
->
stateCol
.
slotId
,
doClearStateWindows
(
&
pInfo
->
streamAggSup
,
pBlock
,
pInfo
->
primaryTsIndex
,
&
pInfo
->
stateCol
,
pInfo
->
stateCol
.
slotId
,
pSeUpdated
,
pInfo
->
pSeDeleted
);
pSeUpdated
,
pInfo
->
pSeDeleted
);
continue
;
continue
;
}
else
if
(
pBlock
->
info
.
type
==
STREAM_GET_ALL
&&
pInfo
->
twAggSup
.
calTrigger
==
STREAM_TRIGGER_MAX_DELAY
)
{
getAllSessionWindow
(
pInfo
->
streamAggSup
.
pResultRows
,
pUpdated
,
getStateWinInfo
);
continue
;
}
}
doStreamStateAggImpl
(
pOperator
,
pBlock
,
pSeUpdated
,
pInfo
->
pSeDeleted
);
doStreamStateAggImpl
(
pOperator
,
pBlock
,
pSeUpdated
,
pInfo
->
pSeDeleted
);
pInfo
->
twAggSup
.
maxTs
=
TMAX
(
pInfo
->
twAggSup
.
maxTs
,
pBlock
->
info
.
window
.
ekey
);
pInfo
->
twAggSup
.
maxTs
=
TMAX
(
pInfo
->
twAggSup
.
maxTs
,
pBlock
->
info
.
window
.
ekey
);
...
@@ -3085,15 +3094,10 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) {
...
@@ -3085,15 +3094,10 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) {
// restore the value
// restore the value
pOperator
->
status
=
OP_RES_TO_RETURN
;
pOperator
->
status
=
OP_RES_TO_RETURN
;
SArray
*
pClosed
=
taosArrayInit
(
16
,
POINTER_BYTES
);
closeSessionWindow
(
pInfo
->
streamAggSup
.
pResultRows
,
&
pInfo
->
twAggSup
,
pUpdated
,
closeSessionWindow
(
pInfo
->
streamAggSup
.
pResultRows
,
&
pInfo
->
twAggSup
,
pClosed
,
pInfo
->
twAggSup
.
calTrigger
,
getStateWinInfo
);
getStateWinInfo
);
SArray
*
pUpdated
=
taosArrayInit
(
16
,
POINTER_BYTES
);
copyUpdateResult
(
pSeUpdated
,
pUpdated
,
pBInfo
->
pRes
->
info
.
groupId
);
copyUpdateResult
(
pSeUpdated
,
pUpdated
,
pBInfo
->
pRes
->
info
.
groupId
);
taosHashCleanup
(
pSeUpdated
);
taosHashCleanup
(
pSeUpdated
);
if
(
pInfo
->
twAggSup
.
calTrigger
==
STREAM_TRIGGER_WINDOW_CLOSE
)
{
taosArrayAddAll
(
pUpdated
,
pClosed
);
}
finalizeUpdatedResult
(
pOperator
->
numOfExprs
,
pInfo
->
streamAggSup
.
pResultBuf
,
pUpdated
,
finalizeUpdatedResult
(
pOperator
->
numOfExprs
,
pInfo
->
streamAggSup
.
pResultBuf
,
pUpdated
,
pInfo
->
binfo
.
rowCellInfoOffset
);
pInfo
->
binfo
.
rowCellInfoOffset
);
...
...
source/libs/function/inc/functionMgtInt.h
浏览文件 @
98bc4630
...
@@ -41,6 +41,7 @@ extern "C" {
...
@@ -41,6 +41,7 @@ extern "C" {
#define FUNC_MGT_SCAN_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(12)
#define FUNC_MGT_SCAN_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(12)
#define FUNC_MGT_SELECT_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(13)
#define FUNC_MGT_SELECT_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(13)
#define FUNC_MGT_REPEAT_SCAN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(14)
#define FUNC_MGT_REPEAT_SCAN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(14)
#define FUNC_MGT_FORBID_FILL_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(15)
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
...
...
source/libs/function/src/builtins.c
浏览文件 @
98bc4630
...
@@ -294,7 +294,8 @@ static int32_t translateApercentileImpl(SFunctionNode* pFunc, char* pErrBuf, int
...
@@ -294,7 +294,8 @@ static int32_t translateApercentileImpl(SFunctionNode* pFunc, char* pErrBuf, int
pValue
->
notReserved
=
true
;
pValue
->
notReserved
=
true
;
}
}
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
getApercentileMaxSize
()
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
getApercentileMaxSize
()
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
}
else
{
}
else
{
if
(
1
!=
numOfParams
)
{
if
(
1
!=
numOfParams
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
...
@@ -479,7 +480,8 @@ static int32_t translateElapsedImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t
...
@@ -479,7 +480,8 @@ static int32_t translateElapsedImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t
}
}
}
}
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
getElapsedInfoSize
()
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
getElapsedInfoSize
()
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
}
else
{
}
else
{
if
(
1
!=
numOfParams
)
{
if
(
1
!=
numOfParams
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
...
@@ -593,7 +595,8 @@ static int32_t translateHistogramImpl(SFunctionNode* pFunc, char* pErrBuf, int32
...
@@ -593,7 +595,8 @@ static int32_t translateHistogramImpl(SFunctionNode* pFunc, char* pErrBuf, int32
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
}
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
getHistogramInfoSize
()
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
getHistogramInfoSize
()
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
}
else
{
}
else
{
if
(
1
!=
numOfParams
)
{
if
(
1
!=
numOfParams
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
...
@@ -631,7 +634,8 @@ static int32_t translateHLLImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len
...
@@ -631,7 +634,8 @@ static int32_t translateHLLImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len
}
}
if
(
isPartial
)
{
if
(
isPartial
)
{
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
getHistogramInfoSize
()
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
getHistogramInfoSize
()
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
}
else
{
}
else
{
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_BIGINT
].
bytes
,
.
type
=
TSDB_DATA_TYPE_BIGINT
};
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_BIGINT
].
bytes
,
.
type
=
TSDB_DATA_TYPE_BIGINT
};
}
}
...
@@ -1320,7 +1324,7 @@ static int32_t translateSelectValue(SFunctionNode* pFunc, char* pErrBuf, int32_t
...
@@ -1320,7 +1324,7 @@ static int32_t translateSelectValue(SFunctionNode* pFunc, char* pErrBuf, int32_t
}
}
static
int32_t
translateBlockDistFunc
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
static
int32_t
translateBlockDistFunc
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
pFunc
->
node
.
resType
=
(
SDataType
)
{.
bytes
=
128
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
};
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
128
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
};
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -1329,7 +1333,6 @@ static bool getBlockDistFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv
...
@@ -1329,7 +1333,6 @@ static bool getBlockDistFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv
return
true
;
return
true
;
}
}
// clang-format off
// clang-format off
const
SBuiltinFuncDefinition
funcMgtBuiltins
[]
=
{
const
SBuiltinFuncDefinition
funcMgtBuiltins
[]
=
{
{
{
...
@@ -1625,7 +1628,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -1625,7 +1628,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
{
.
name
=
"histogram"
,
.
name
=
"histogram"
,
.
type
=
FUNCTION_TYPE_HISTOGRAM
,
.
type
=
FUNCTION_TYPE_HISTOGRAM
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_FORBID_FILL_FUNC
,
.
translateFunc
=
translateHistogram
,
.
translateFunc
=
translateHistogram
,
.
getEnvFunc
=
getHistogramFuncEnv
,
.
getEnvFunc
=
getHistogramFuncEnv
,
.
initFunc
=
histogramFunctionSetup
,
.
initFunc
=
histogramFunctionSetup
,
...
...
source/libs/function/src/functionMgt.c
浏览文件 @
98bc4630
...
@@ -159,6 +159,8 @@ bool fmIsRepeatScanFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId,
...
@@ -159,6 +159,8 @@ bool fmIsRepeatScanFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId,
bool
fmIsUserDefinedFunc
(
int32_t
funcId
)
{
return
funcId
>
FUNC_UDF_ID_START
;
}
bool
fmIsUserDefinedFunc
(
int32_t
funcId
)
{
return
funcId
>
FUNC_UDF_ID_START
;
}
bool
fmIsForbidFillFunc
(
int32_t
funcId
)
{
return
isSpecificClassifyFunc
(
funcId
,
FUNC_MGT_FORBID_FILL_FUNC
);
}
void
fmFuncMgtDestroy
()
{
void
fmFuncMgtDestroy
()
{
void
*
m
=
gFunMgtService
.
pFuncNameHashTable
;
void
*
m
=
gFunMgtService
.
pFuncNameHashTable
;
if
(
m
!=
NULL
&&
atomic_val_compare_exchange_ptr
((
void
**
)
&
gFunMgtService
.
pFuncNameHashTable
,
m
,
0
)
==
m
)
{
if
(
m
!=
NULL
&&
atomic_val_compare_exchange_ptr
((
void
**
)
&
gFunMgtService
.
pFuncNameHashTable
,
m
,
0
)
==
m
)
{
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
98bc4630
...
@@ -346,25 +346,30 @@ SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLitera
...
@@ -346,25 +346,30 @@ SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLitera
return
(
SNode
*
)
val
;
return
(
SNode
*
)
val
;
}
}
static
int32_t
addParamToLogicConditionNode
(
SLogicConditionNode
*
pCond
,
SNode
*
pParam
)
{
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pParam
)
&&
pCond
->
condType
==
((
SLogicConditionNode
*
)
pParam
)
->
condType
)
{
int32_t
code
=
nodesListAppendList
(
pCond
->
pParameterList
,
((
SLogicConditionNode
*
)
pParam
)
->
pParameterList
);
((
SLogicConditionNode
*
)
pParam
)
->
pParameterList
=
NULL
;
nodesDestroyNode
(
pParam
);
return
code
;
}
else
{
return
nodesListAppend
(
pCond
->
pParameterList
,
pParam
);
}
}
SNode
*
createLogicConditionNode
(
SAstCreateContext
*
pCxt
,
ELogicConditionType
type
,
SNode
*
pParam1
,
SNode
*
pParam2
)
{
SNode
*
createLogicConditionNode
(
SAstCreateContext
*
pCxt
,
ELogicConditionType
type
,
SNode
*
pParam1
,
SNode
*
pParam2
)
{
CHECK_PARSER_STATUS
(
pCxt
);
CHECK_PARSER_STATUS
(
pCxt
);
SLogicConditionNode
*
cond
=
(
SLogicConditionNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_CONDITION
);
SLogicConditionNode
*
cond
=
(
SLogicConditionNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_CONDITION
);
CHECK_OUT_OF_MEM
(
cond
);
CHECK_OUT_OF_MEM
(
cond
);
cond
->
condType
=
type
;
cond
->
condType
=
type
;
cond
->
pParameterList
=
nodesMakeList
();
cond
->
pParameterList
=
nodesMakeList
();
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pParam1
)
&&
type
==
((
SLogicConditionNode
*
)
pParam1
)
->
condType
)
{
int32_t
code
=
addParamToLogicConditionNode
(
cond
,
pParam1
);
nodesListAppendList
(
cond
->
pParameterList
,
((
SLogicConditionNode
*
)
pParam1
)
->
pParameterList
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pParam2
)
{
((
SLogicConditionNode
*
)
pParam1
)
->
pParameterList
=
NULL
;
code
=
addParamToLogicConditionNode
(
cond
,
pParam2
);
nodesDestroyNode
(
pParam1
);
}
else
{
nodesListAppend
(
cond
->
pParameterList
,
pParam1
);
}
}
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pParam2
)
&&
type
==
((
SLogicConditionNode
*
)
pParam2
)
->
condType
)
{
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
nodesListAppendList
(
cond
->
pParameterList
,
((
SLogicConditionNode
*
)
pParam2
)
->
pParameterList
);
nodesDestroyNode
(
cond
);
((
SLogicConditionNode
*
)
pParam2
)
->
pParameterList
=
NULL
;
return
NULL
;
nodesDestroyNode
(
pParam2
);
}
else
{
nodesListAppend
(
cond
->
pParameterList
,
pParam2
);
}
}
return
(
SNode
*
)
cond
;
return
(
SNode
*
)
cond
;
}
}
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
98bc4630
...
@@ -733,7 +733,7 @@ static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SD
...
@@ -733,7 +733,7 @@ static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SD
}
}
int32_t
len
=
0
;
int32_t
len
=
0
;
if
(
!
taosMbsToUcs4
(
pVal
->
literal
,
pVal
->
node
.
resType
.
bytes
,
(
TdUcs4
*
)
varDataVal
(
pVal
->
datum
.
p
),
if
(
!
taosMbsToUcs4
(
pVal
->
literal
,
strlen
(
pVal
->
literal
)
,
(
TdUcs4
*
)
varDataVal
(
pVal
->
datum
.
p
),
targetDt
.
bytes
-
VARSTR_HEADER_SIZE
,
&
len
))
{
targetDt
.
bytes
-
VARSTR_HEADER_SIZE
,
&
len
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
}
...
@@ -974,6 +974,9 @@ static int32_t getFuncInfo(STranslateContext* pCxt, SFunctionNode* pFunc) {
...
@@ -974,6 +974,9 @@ static int32_t getFuncInfo(STranslateContext* pCxt, SFunctionNode* pFunc) {
}
}
static
int32_t
translateAggFunc
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
static
int32_t
translateAggFunc
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
if
(
!
fmIsAggFunc
(
pFunc
->
funcId
))
{
return
TSDB_CODE_SUCCESS
;
}
if
(
beforeHaving
(
pCxt
->
currClause
))
{
if
(
beforeHaving
(
pCxt
->
currClause
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
);
}
}
...
@@ -991,6 +994,9 @@ static int32_t translateAggFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
...
@@ -991,6 +994,9 @@ static int32_t translateAggFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
}
}
static
int32_t
translateScanPseudoColumnFunc
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
static
int32_t
translateScanPseudoColumnFunc
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
if
(
!
fmIsScanPseudoColumnFunc
(
pFunc
->
funcId
))
{
return
TSDB_CODE_SUCCESS
;
}
if
(
0
==
LIST_LENGTH
(
pFunc
->
pParameterList
))
{
if
(
0
==
LIST_LENGTH
(
pFunc
->
pParameterList
))
{
if
(
QUERY_NODE_REAL_TABLE
!=
nodeType
(
pCxt
->
pCurrSelectStmt
->
pFromTable
))
{
if
(
QUERY_NODE_REAL_TABLE
!=
nodeType
(
pCxt
->
pCurrSelectStmt
->
pFromTable
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TBNAME
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TBNAME
);
...
@@ -1007,6 +1013,9 @@ static int32_t translateScanPseudoColumnFunc(STranslateContext* pCxt, SFunctionN
...
@@ -1007,6 +1013,9 @@ static int32_t translateScanPseudoColumnFunc(STranslateContext* pCxt, SFunctionN
}
}
static
int32_t
translateIndefiniteRowsFunc
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
static
int32_t
translateIndefiniteRowsFunc
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
if
(
!
fmIsIndefiniteRowsFunc
(
pFunc
->
funcId
))
{
return
TSDB_CODE_SUCCESS
;
}
if
(
SQL_CLAUSE_SELECT
!=
pCxt
->
currClause
||
pCxt
->
pCurrSelectStmt
->
hasIndefiniteRowsFunc
||
if
(
SQL_CLAUSE_SELECT
!=
pCxt
->
currClause
||
pCxt
->
pCurrSelectStmt
->
hasIndefiniteRowsFunc
||
pCxt
->
pCurrSelectStmt
->
hasAggFuncs
)
{
pCxt
->
pCurrSelectStmt
->
hasAggFuncs
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NOT_ALLOWED_FUNC
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NOT_ALLOWED_FUNC
);
...
@@ -1017,6 +1026,18 @@ static int32_t translateIndefiniteRowsFunc(STranslateContext* pCxt, SFunctionNod
...
@@ -1017,6 +1026,18 @@ static int32_t translateIndefiniteRowsFunc(STranslateContext* pCxt, SFunctionNod
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
translateForbidFillFunc
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
if
(
!
fmIsForbidFillFunc
(
pFunc
->
funcId
))
{
return
TSDB_CODE_SUCCESS
;
}
if
(
NULL
!=
pCxt
->
pCurrSelectStmt
->
pWindow
&&
QUERY_NODE_INTERVAL_WINDOW
==
nodeType
(
pCxt
->
pCurrSelectStmt
->
pWindow
)
&&
NULL
!=
((
SIntervalWindowNode
*
)
pCxt
->
pCurrSelectStmt
->
pWindow
)
->
pFill
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC
,
pFunc
->
functionName
);
}
return
TSDB_CODE_SUCCESS
;
}
static
void
setFuncClassification
(
SSelectStmt
*
pSelect
,
SFunctionNode
*
pFunc
)
{
static
void
setFuncClassification
(
SSelectStmt
*
pSelect
,
SFunctionNode
*
pFunc
)
{
if
(
NULL
!=
pSelect
)
{
if
(
NULL
!=
pSelect
)
{
pSelect
->
hasAggFuncs
=
pSelect
->
hasAggFuncs
?
true
:
fmIsAggFunc
(
pFunc
->
funcId
);
pSelect
->
hasAggFuncs
=
pSelect
->
hasAggFuncs
?
true
:
fmIsAggFunc
(
pFunc
->
funcId
);
...
@@ -1034,15 +1055,18 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
...
@@ -1034,15 +1055,18 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
}
}
pCxt
->
errCode
=
getFuncInfo
(
pCxt
,
pFunc
);
pCxt
->
errCode
=
getFuncInfo
(
pCxt
,
pFunc
);
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
&&
fmIsAggFunc
(
pFunc
->
funcId
)
)
{
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
)
{
pCxt
->
errCode
=
translateAggFunc
(
pCxt
,
pFunc
);
pCxt
->
errCode
=
translateAggFunc
(
pCxt
,
pFunc
);
}
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
&&
fmIsScanPseudoColumnFunc
(
pFunc
->
funcId
)
)
{
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
)
{
pCxt
->
errCode
=
translateScanPseudoColumnFunc
(
pCxt
,
pFunc
);
pCxt
->
errCode
=
translateScanPseudoColumnFunc
(
pCxt
,
pFunc
);
}
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
&&
fmIsIndefiniteRowsFunc
(
pFunc
->
funcId
)
)
{
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
)
{
pCxt
->
errCode
=
translateIndefiniteRowsFunc
(
pCxt
,
pFunc
);
pCxt
->
errCode
=
translateIndefiniteRowsFunc
(
pCxt
,
pFunc
);
}
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
)
{
pCxt
->
errCode
=
translateForbidFillFunc
(
pCxt
,
pFunc
);
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
)
{
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
)
{
setFuncClassification
(
pCxt
->
pCurrSelectStmt
,
pFunc
);
setFuncClassification
(
pCxt
->
pCurrSelectStmt
,
pFunc
);
}
}
...
@@ -2365,6 +2389,8 @@ static int32_t checkDbRetentionsOption(STranslateContext* pCxt, SNodeList* pRete
...
@@ -2365,6 +2389,8 @@ static int32_t checkDbRetentionsOption(STranslateContext* pCxt, SNodeList* pRete
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION
);
}
}
SValueNode
*
pPrevFreq
=
NULL
;
SValueNode
*
pPrevKeep
=
NULL
;
SNode
*
pRetention
=
NULL
;
SNode
*
pRetention
=
NULL
;
FOREACH
(
pRetention
,
pRetentions
)
{
FOREACH
(
pRetention
,
pRetentions
)
{
SNode
*
pNode
=
NULL
;
SNode
*
pNode
=
NULL
;
...
@@ -2374,6 +2400,16 @@ static int32_t checkDbRetentionsOption(STranslateContext* pCxt, SNodeList* pRete
...
@@ -2374,6 +2400,16 @@ static int32_t checkDbRetentionsOption(STranslateContext* pCxt, SNodeList* pRete
return
pCxt
->
errCode
;
return
pCxt
->
errCode
;
}
}
}
}
SValueNode
*
pFreq
=
(
SValueNode
*
)
nodesListGetNode
(((
SNodeListNode
*
)
pRetention
)
->
pNodeList
,
0
);
SValueNode
*
pKeep
=
(
SValueNode
*
)
nodesListGetNode
(((
SNodeListNode
*
)
pRetention
)
->
pNodeList
,
1
);
if
(
pFreq
->
datum
.
i
<=
0
||
'n'
==
pFreq
->
unit
||
'y'
==
pFreq
->
unit
||
pFreq
->
datum
.
i
>=
pKeep
->
datum
.
i
||
(
NULL
!=
pPrevFreq
&&
pPrevFreq
->
datum
.
i
>=
pFreq
->
datum
.
i
)
||
(
NULL
!=
pPrevKeep
&&
pPrevKeep
->
datum
.
i
>
pKeep
->
datum
.
i
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION
);
}
pPrevFreq
=
pFreq
;
pPrevKeep
=
pKeep
;
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -2593,12 +2629,23 @@ static int32_t checkTableSmaOption(STranslateContext* pCxt, SCreateTableStmt* pS
...
@@ -2593,12 +2629,23 @@ static int32_t checkTableSmaOption(STranslateContext* pCxt, SCreateTableStmt* pS
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
bool
validRollupFunc
(
const
char
*
pFunc
)
{
static
const
char
*
rollupFuncs
[]
=
{
"avg"
,
"sum"
,
"min"
,
"max"
,
"last"
,
"first"
};
static
const
int32_t
numOfRollupFuncs
=
(
sizeof
(
rollupFuncs
)
/
sizeof
(
char
*
));
for
(
int
i
=
0
;
i
<
numOfRollupFuncs
;
++
i
)
{
if
(
0
==
strcmp
(
rollupFuncs
[
i
],
pFunc
))
{
return
true
;
}
}
return
false
;
}
static
int32_t
checkTableRollupOption
(
STranslateContext
*
pCxt
,
SNodeList
*
pFuncs
)
{
static
int32_t
checkTableRollupOption
(
STranslateContext
*
pCxt
,
SNodeList
*
pFuncs
)
{
if
(
NULL
==
pFuncs
)
{
if
(
NULL
==
pFuncs
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
1
!=
LIST_LENGTH
(
pFuncs
))
{
if
(
1
!=
LIST_LENGTH
(
pFuncs
)
||
!
validRollupFunc
(((
SFunctionNode
*
)
nodesListGetNode
(
pFuncs
,
0
))
->
functionName
)
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_ROLLUP_OPTION
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_ROLLUP_OPTION
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -3083,15 +3130,14 @@ static int32_t translateAlterTable(STranslateContext* pCxt, SAlterTableStmt* pSt
...
@@ -3083,15 +3130,14 @@ static int32_t translateAlterTable(STranslateContext* pCxt, SAlterTableStmt* pSt
SName
tableName
;
SName
tableName
;
tNameExtractFullName
(
toName
(
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
pStmt
->
tableName
,
&
tableName
),
alterReq
.
name
);
tNameExtractFullName
(
toName
(
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
pStmt
->
tableName
,
&
tableName
),
alterReq
.
name
);
alterReq
.
alterType
=
pStmt
->
alterType
;
alterReq
.
alterType
=
pStmt
->
alterType
;
if
(
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
==
pStmt
->
alterType
)
{
if
(
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
==
pStmt
->
alterType
||
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
==
pStmt
->
alterType
)
{
return
TSDB_CODE_FAILED
;
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_ALTER_TABLE
);
}
else
{
if
(
TSDB_CODE_SUCCESS
!=
setAlterTableField
(
pStmt
,
&
alterReq
))
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
int32_t
code
=
setAlterTableField
(
pStmt
,
&
alterReq
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
buildCmdMsg
(
pCxt
,
TDMT_MND_ALTER_STB
,
(
FSerializeFunc
)
tSerializeSMAlterStbReq
,
&
alterReq
);
}
}
return
code
;
return
buildCmdMsg
(
pCxt
,
TDMT_MND_ALTER_STB
,
(
FSerializeFunc
)
tSerializeSMAlterStbReq
,
&
alterReq
);
}
}
static
int32_t
translateUseDatabase
(
STranslateContext
*
pCxt
,
SUseDatabaseStmt
*
pStmt
)
{
static
int32_t
translateUseDatabase
(
STranslateContext
*
pCxt
,
SUseDatabaseStmt
*
pStmt
)
{
...
@@ -3171,7 +3217,7 @@ static int32_t nodeTypeToShowType(ENodeType nt) {
...
@@ -3171,7 +3217,7 @@ static int32_t nodeTypeToShowType(ENodeType nt) {
case
QUERY_NODE_SHOW_QUERIES_STMT
:
case
QUERY_NODE_SHOW_QUERIES_STMT
:
return
TSDB_MGMT_TABLE_QUERIES
;
return
TSDB_MGMT_TABLE_QUERIES
;
case
QUERY_NODE_SHOW_VARIABLE_STMT
:
case
QUERY_NODE_SHOW_VARIABLE_STMT
:
return
0
;
// todo
return
TSDB_MGMT_TABLE_CONFIGS
;
default:
default:
break
;
break
;
}
}
...
@@ -3778,6 +3824,7 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
...
@@ -3778,6 +3824,7 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
case
QUERY_NODE_SHOW_CONNECTIONS_STMT
:
case
QUERY_NODE_SHOW_CONNECTIONS_STMT
:
case
QUERY_NODE_SHOW_QUERIES_STMT
:
case
QUERY_NODE_SHOW_QUERIES_STMT
:
case
QUERY_NODE_SHOW_TOPICS_STMT
:
case
QUERY_NODE_SHOW_TOPICS_STMT
:
case
QUERY_NODE_SHOW_VARIABLE_STMT
:
code
=
translateShow
(
pCxt
,
(
SShowStmt
*
)
pNode
);
code
=
translateShow
(
pCxt
,
(
SShowStmt
*
)
pNode
);
break
;
break
;
case
QUERY_NODE_CREATE_INDEX_STMT
:
case
QUERY_NODE_CREATE_INDEX_STMT
:
...
@@ -4932,7 +4979,11 @@ static int32_t buildAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pStmt,
...
@@ -4932,7 +4979,11 @@ static int32_t buildAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pStmt,
case
TSDB_ALTER_TABLE_UPDATE_OPTIONS
:
case
TSDB_ALTER_TABLE_UPDATE_OPTIONS
:
return
buildUpdateOptionsReq
(
pCxt
,
pStmt
,
pReq
);
return
buildUpdateOptionsReq
(
pCxt
,
pStmt
,
pReq
);
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
case
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
:
if
(
TSDB_CHILD_TABLE
==
pTableMeta
->
tableType
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_ALTER_TABLE
);
}
else
{
return
buildRenameColReq
(
pCxt
,
pStmt
,
pTableMeta
,
pReq
);
return
buildRenameColReq
(
pCxt
,
pStmt
,
pTableMeta
,
pReq
);
}
default:
default:
break
;
break
;
}
}
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
98bc4630
...
@@ -76,7 +76,7 @@ static char* getSyntaxErrFormat(int32_t errCode) {
...
@@ -76,7 +76,7 @@ static char* getSyntaxErrFormat(int32_t errCode) {
case
TSDB_CODE_PAR_INVALID_KEEP_ORDER
:
case
TSDB_CODE_PAR_INVALID_KEEP_ORDER
:
return
"Invalid keep value, should be keep0 <= keep1 <= keep2"
;
return
"Invalid keep value, should be keep0 <= keep1 <= keep2"
;
case
TSDB_CODE_PAR_INVALID_KEEP_VALUE
:
case
TSDB_CODE_PAR_INVALID_KEEP_VALUE
:
return
"Invalid option keep: %
d, %d, %d valid range: [%d, %d
]"
;
return
"Invalid option keep: %
"
PRId64
", %"
PRId64
", %"
PRId64
" valid range: [%dm, %dm
]"
;
case
TSDB_CODE_PAR_INVALID_COMMENT_OPTION
:
case
TSDB_CODE_PAR_INVALID_COMMENT_OPTION
:
return
"Invalid option comment, length cannot exceed %d"
;
return
"Invalid option comment, length cannot exceed %d"
;
case
TSDB_CODE_PAR_INVALID_F_RANGE_OPTION
:
case
TSDB_CODE_PAR_INVALID_F_RANGE_OPTION
:
...
@@ -182,6 +182,8 @@ static char* getSyntaxErrFormat(int32_t errCode) {
...
@@ -182,6 +182,8 @@ static char* getSyntaxErrFormat(int32_t errCode) {
return
"The DELETE statement must have a definite time window range"
;
return
"The DELETE statement must have a definite time window range"
;
case
TSDB_CODE_PAR_INVALID_REDISTRIBUTE_VG
:
case
TSDB_CODE_PAR_INVALID_REDISTRIBUTE_VG
:
return
"The REDISTRIBUTE VGROUP statement only support 1 to 3 dnodes"
;
return
"The REDISTRIBUTE VGROUP statement only support 1 to 3 dnodes"
;
case
TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC
:
return
"%s function not allowed in fill query"
;
case
TSDB_CODE_OUT_OF_MEMORY
:
case
TSDB_CODE_OUT_OF_MEMORY
:
return
"Out of memory"
;
return
"Out of memory"
;
default:
default:
...
...
source/libs/parser/test/parInitialATest.cpp
浏览文件 @
98bc4630
...
@@ -24,7 +24,7 @@ class ParserInitialATest : public ParserDdlTest {};
...
@@ -24,7 +24,7 @@ class ParserInitialATest : public ParserDdlTest {};
TEST_F
(
ParserInitialATest
,
alterAccount
)
{
TEST_F
(
ParserInitialATest
,
alterAccount
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
run
(
"ALTER ACCOUNT ac_wxy PASS '123456'"
,
TSDB_CODE_PAR_EXPRIE_STATEMENT
);
run
(
"ALTER ACCOUNT ac_wxy PASS '123456'"
,
TSDB_CODE_PAR_EXPRIE_STATEMENT
,
PARSER_STAGE_PARSE
);
}
}
TEST_F
(
ParserInitialATest
,
alterDnode
)
{
TEST_F
(
ParserInitialATest
,
alterDnode
)
{
...
@@ -157,8 +157,8 @@ TEST_F(ParserInitialATest, alterSTable) {
...
@@ -157,8 +157,8 @@ TEST_F(ParserInitialATest, alterSTable) {
20
+
VARSTR_HEADER_SIZE
);
20
+
VARSTR_HEADER_SIZE
);
run
(
"ALTER TABLE st1 MODIFY COLUMN c1 VARCHAR(20)"
);
run
(
"ALTER TABLE st1 MODIFY COLUMN c1 VARCHAR(20)"
);
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
,
2
,
"c1"
,
0
,
0
,
"cc1"
);
//
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, 2, "c1", 0, 0, "cc1");
run
(
"ALTER TABLE st1 RENAME COLUMN c1 cc1"
);
//
run("ALTER TABLE st1 RENAME COLUMN c1 cc1");
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_ADD_TAG
,
1
,
"tag11"
,
TSDB_DATA_TYPE_BIGINT
);
setAlterStbReqFunc
(
"st1"
,
TSDB_ALTER_TABLE_ADD_TAG
,
1
,
"tag11"
,
TSDB_DATA_TYPE_BIGINT
);
run
(
"ALTER TABLE st1 ADD TAG tag11 BIGINT"
);
run
(
"ALTER TABLE st1 ADD TAG tag11 BIGINT"
);
...
@@ -177,6 +177,12 @@ TEST_F(ParserInitialATest, alterSTable) {
...
@@ -177,6 +177,12 @@ TEST_F(ParserInitialATest, alterSTable) {
// ADD {FULLTEXT | SMA} INDEX index_name (col_name [, col_name] ...) [index_option]
// ADD {FULLTEXT | SMA} INDEX index_name (col_name [, col_name] ...) [index_option]
}
}
TEST_F
(
ParserInitialATest
,
alterSTableSemanticCheck
)
{
useDb
(
"root"
,
"test"
);
run
(
"ALTER TABLE st1 RENAME COLUMN c1 cc1"
,
TSDB_CODE_PAR_INVALID_ALTER_TABLE
);
}
TEST_F
(
ParserInitialATest
,
alterTable
)
{
TEST_F
(
ParserInitialATest
,
alterTable
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
...
@@ -299,6 +305,12 @@ TEST_F(ParserInitialATest, alterTable) {
...
@@ -299,6 +305,12 @@ TEST_F(ParserInitialATest, alterTable) {
// ADD {FULLTEXT | SMA} INDEX index_name (col_name [, col_name] ...) [index_option]
// ADD {FULLTEXT | SMA} INDEX index_name (col_name [, col_name] ...) [index_option]
}
}
TEST_F
(
ParserInitialATest
,
alterTableSemanticCheck
)
{
useDb
(
"root"
,
"test"
);
run
(
"ALTER TABLE st1s1 RENAME COLUMN c1 cc1"
,
TSDB_CODE_PAR_INVALID_ALTER_TABLE
);
}
TEST_F
(
ParserInitialATest
,
alterUser
)
{
TEST_F
(
ParserInitialATest
,
alterUser
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
...
@@ -323,7 +335,7 @@ TEST_F(ParserInitialATest, balanceVgroup) {
...
@@ -323,7 +335,7 @@ TEST_F(ParserInitialATest, balanceVgroup) {
TEST_F
(
ParserInitialATest
,
bug001
)
{
TEST_F
(
ParserInitialATest
,
bug001
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
run
(
"ALTER DATABASE db WAL 0 # td-14436"
,
TSDB_CODE_PAR_SYNTAX_ERROR
);
run
(
"ALTER DATABASE db WAL 0 # td-14436"
,
TSDB_CODE_PAR_SYNTAX_ERROR
,
PARSER_STAGE_PARSE
);
}
}
}
// namespace ParserTest
}
// namespace ParserTest
\ No newline at end of file
source/libs/parser/test/parInitialCTest.cpp
浏览文件 @
98bc4630
...
@@ -27,7 +27,7 @@ class ParserInitialCTest : public ParserDdlTest {};
...
@@ -27,7 +27,7 @@ class ParserInitialCTest : public ParserDdlTest {};
TEST_F
(
ParserInitialCTest
,
createAccount
)
{
TEST_F
(
ParserInitialCTest
,
createAccount
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
run
(
"CREATE ACCOUNT ac_wxy PASS '123456'"
,
TSDB_CODE_PAR_EXPRIE_STATEMENT
);
run
(
"CREATE ACCOUNT ac_wxy PASS '123456'"
,
TSDB_CODE_PAR_EXPRIE_STATEMENT
,
PARSER_STAGE_PARSE
);
}
}
TEST_F
(
ParserInitialCTest
,
createBnode
)
{
TEST_F
(
ParserInitialCTest
,
createBnode
)
{
...
@@ -186,7 +186,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
...
@@ -186,7 +186,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
setDbReplicaFunc
(
3
);
setDbReplicaFunc
(
3
);
addDbRetentionFunc
(
15
*
MILLISECOND_PER_SECOND
,
7
*
MILLISECOND_PER_DAY
,
TIME_UNIT_SECOND
,
TIME_UNIT_DAY
);
addDbRetentionFunc
(
15
*
MILLISECOND_PER_SECOND
,
7
*
MILLISECOND_PER_DAY
,
TIME_UNIT_SECOND
,
TIME_UNIT_DAY
);
addDbRetentionFunc
(
1
*
MILLISECOND_PER_MINUTE
,
21
*
MILLISECOND_PER_DAY
,
TIME_UNIT_MINUTE
,
TIME_UNIT_DAY
);
addDbRetentionFunc
(
1
*
MILLISECOND_PER_MINUTE
,
21
*
MILLISECOND_PER_DAY
,
TIME_UNIT_MINUTE
,
TIME_UNIT_DAY
);
addDbRetentionFunc
(
15
*
MILLISECOND_PER_MINUTE
,
5
,
TIME_UNIT_MINUTE
,
TIME_UNIT_YEAR
);
addDbRetentionFunc
(
15
*
MILLISECOND_PER_MINUTE
,
5
00
*
MILLISECOND_PER_DAY
,
TIME_UNIT_MINUTE
,
TIME_UNIT_DAY
);
setDbStrictaFunc
(
1
);
setDbStrictaFunc
(
1
);
setDbWalLevelFunc
(
2
);
setDbWalLevelFunc
(
2
);
setDbVgroupsFunc
(
100
);
setDbVgroupsFunc
(
100
);
...
@@ -205,7 +205,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
...
@@ -205,7 +205,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
"PAGESIZE 8 "
"PAGESIZE 8 "
"PRECISION 'ns' "
"PRECISION 'ns' "
"REPLICA 3 "
"REPLICA 3 "
"RETENTIONS 15s:7d,1m:21d,15m:5
y
"
"RETENTIONS 15s:7d,1m:21d,15m:5
00d
"
"STRICT 1 "
"STRICT 1 "
"WAL 2 "
"WAL 2 "
"VGROUPS 100 "
"VGROUPS 100 "
...
@@ -220,6 +220,17 @@ TEST_F(ParserInitialCTest, createDatabase) {
...
@@ -220,6 +220,17 @@ TEST_F(ParserInitialCTest, createDatabase) {
"KEEP 1440m,300h,400d "
);
"KEEP 1440m,300h,400d "
);
}
}
TEST_F
(
ParserInitialCTest
,
createDatabaseSemanticCheck
)
{
useDb
(
"root"
,
"test"
);
run
(
"create database db2 retentions 0s:1d"
,
TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION
);
run
(
"create database db2 retentions 10s:0d"
,
TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION
);
run
(
"create database db2 retentions 1w:1d"
,
TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION
);
run
(
"create database db2 retentions 1w:1n"
,
TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION
);
run
(
"create database db2 retentions 15s:7d,15m:21d,10m:500d"
,
TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION
);
run
(
"create database db2 retentions 15s:7d,5m:21d,10m:10d"
,
TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION
);
}
TEST_F
(
ParserInitialCTest
,
createDnode
)
{
TEST_F
(
ParserInitialCTest
,
createDnode
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
...
@@ -434,6 +445,13 @@ TEST_F(ParserInitialCTest, createStable) {
...
@@ -434,6 +445,13 @@ TEST_F(ParserInitialCTest, createStable) {
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (MIN) FILE_FACTOR 0.1"
);
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (MIN) FILE_FACTOR 0.1"
);
}
}
TEST_F
(
ParserInitialCTest
,
createStableSemanticCheck
)
{
useDb
(
"root"
,
"test"
);
run
(
"CREATE STABLE stb2 (ts TIMESTAMP, c1 INT) TAGS (tag1 INT) ROLLUP(CEIL) FILE_FACTOR 0.1"
,
TSDB_CODE_PAR_INVALID_ROLLUP_OPTION
,
PARSER_STAGE_TRANSLATE
);
}
TEST_F
(
ParserInitialCTest
,
createStream
)
{
TEST_F
(
ParserInitialCTest
,
createStream
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
...
...
source/libs/parser/test/parSelectTest.cpp
浏览文件 @
98bc4630
...
@@ -65,6 +65,8 @@ TEST_F(ParserSelectTest, condition) {
...
@@ -65,6 +65,8 @@ TEST_F(ParserSelectTest, condition) {
run
(
"SELECT c1 FROM t1 WHERE ts in (true, false)"
);
run
(
"SELECT c1 FROM t1 WHERE ts in (true, false)"
);
run
(
"SELECT c1 FROM t1 WHERE NOT ts in (true, false)"
);
run
(
"SELECT * FROM t1 WHERE c1 > 10 and c1 is not null"
);
run
(
"SELECT * FROM t1 WHERE c1 > 10 and c1 is not null"
);
}
}
...
@@ -212,9 +214,11 @@ TEST_F(ParserSelectTest, interval) {
...
@@ -212,9 +214,11 @@ TEST_F(ParserSelectTest, interval) {
TEST_F
(
ParserSelectTest
,
intervalSemanticCheck
)
{
TEST_F
(
ParserSelectTest
,
intervalSemanticCheck
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
run
(
"SELECT c1 FROM t1 INTERVAL(10s)"
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT c1 FROM t1 INTERVAL(10s)"
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
);
run
(
"SELECT DISTINCT c1, c2 FROM t1 WHERE c1 > 3 INTERVAL(1d) FILL(NEXT)"
,
TSDB_CODE_PAR_INVALID_FILL_TIME_RANGE
,
run
(
"SELECT DISTINCT c1, c2 FROM t1 WHERE c1 > 3 INTERVAL(1d) FILL(NEXT)"
,
TSDB_CODE_PAR_INVALID_FILL_TIME_RANGE
);
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT HISTOGRAM(c1, 'log_bin', '{
\"
start
\"
: -33,
\"
factor
\"
: 55,
\"
count
\"
: 5,
\"
infinity
\"
: false}', 1) FROM t1 "
"WHERE ts > TIMESTAMP '2022-04-01 00:00:00' and ts < TIMESTAMP '2022-04-30 23:59:59' INTERVAL(10s) FILL(NULL)"
,
TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC
);
}
}
TEST_F
(
ParserSelectTest
,
subquery
)
{
TEST_F
(
ParserSelectTest
,
subquery
)
{
...
...
source/libs/parser/test/parTestUtil.h
浏览文件 @
98bc4630
...
@@ -36,7 +36,7 @@ class ParserTestBase : public testing::Test {
...
@@ -36,7 +36,7 @@ class ParserTestBase : public testing::Test {
void
login
(
const
std
::
string
&
user
);
void
login
(
const
std
::
string
&
user
);
void
useDb
(
const
std
::
string
&
acctId
,
const
std
::
string
&
db
);
void
useDb
(
const
std
::
string
&
acctId
,
const
std
::
string
&
db
);
void
run
(
const
std
::
string
&
sql
,
int32_t
expect
=
TSDB_CODE_SUCCESS
,
ParserStage
checkStage
=
PARSER_STAGE_
ALL
);
void
run
(
const
std
::
string
&
sql
,
int32_t
expect
=
TSDB_CODE_SUCCESS
,
ParserStage
checkStage
=
PARSER_STAGE_
TRANSLATE
);
virtual
void
checkDdl
(
const
SQuery
*
pQuery
,
ParserStage
stage
);
virtual
void
checkDdl
(
const
SQuery
*
pQuery
,
ParserStage
stage
);
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
98bc4630
...
@@ -159,7 +159,7 @@ typedef struct SSyncNode {
...
@@ -159,7 +159,7 @@ typedef struct SSyncNode {
SSyncSnapshotSender
*
senders
[
TSDB_MAX_REPLICA
];
SSyncSnapshotSender
*
senders
[
TSDB_MAX_REPLICA
];
SSyncSnapshotReceiver
*
pNewNodeReceiver
;
SSyncSnapshotReceiver
*
pNewNodeReceiver
;
SSnapshotMeta
sMeta
;
//
SSnapshotMeta sMeta;
}
SSyncNode
;
}
SSyncNode
;
...
@@ -194,7 +194,7 @@ int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, S
...
@@ -194,7 +194,7 @@ int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, S
cJSON
*
syncNode2Json
(
const
SSyncNode
*
pSyncNode
);
cJSON
*
syncNode2Json
(
const
SSyncNode
*
pSyncNode
);
char
*
syncNode2Str
(
const
SSyncNode
*
pSyncNode
);
char
*
syncNode2Str
(
const
SSyncNode
*
pSyncNode
);
char
*
syncNode2SimpleStr
(
const
SSyncNode
*
pSyncNode
);
char
*
syncNode2SimpleStr
(
const
SSyncNode
*
pSyncNode
);
void
syncNodeUpdateConfig
(
SSyncNode
*
pSyncNode
,
SSyncCfg
*
newConfig
,
bool
*
isDrop
);
void
syncNodeUpdateConfig
(
SSyncNode
*
pSyncNode
,
SSyncCfg
*
newConfig
,
SyncIndex
lastConfigChangeIndex
,
bool
*
isDrop
);
SSyncNode
*
syncNodeAcquire
(
int64_t
rid
);
SSyncNode
*
syncNodeAcquire
(
int64_t
rid
);
void
syncNodeRelease
(
SSyncNode
*
pNode
);
void
syncNodeRelease
(
SSyncNode
*
pNode
);
...
...
source/libs/sync/inc/syncRaftCfg.h
浏览文件 @
98bc4630
...
@@ -35,6 +35,7 @@ typedef struct SRaftCfg {
...
@@ -35,6 +35,7 @@ typedef struct SRaftCfg {
char
path
[
TSDB_FILENAME_LEN
*
2
];
char
path
[
TSDB_FILENAME_LEN
*
2
];
int8_t
isStandBy
;
int8_t
isStandBy
;
int8_t
snapshotEnable
;
int8_t
snapshotEnable
;
SyncIndex
lastConfigIndex
;
}
SRaftCfg
;
}
SRaftCfg
;
SRaftCfg
*
raftCfgOpen
(
const
char
*
path
);
SRaftCfg
*
raftCfgOpen
(
const
char
*
path
);
...
@@ -54,6 +55,7 @@ int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg);
...
@@ -54,6 +55,7 @@ int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg);
typedef
struct
SRaftCfgMeta
{
typedef
struct
SRaftCfgMeta
{
int8_t
isStandBy
;
int8_t
isStandBy
;
int8_t
snapshotEnable
;
int8_t
snapshotEnable
;
SyncIndex
lastConfigIndex
;
}
SRaftCfgMeta
;
}
SRaftCfgMeta
;
int32_t
raftCfgCreateFile
(
SSyncCfg
*
pCfg
,
SRaftCfgMeta
meta
,
const
char
*
path
);
int32_t
raftCfgCreateFile
(
SSyncCfg
*
pCfg
,
SRaftCfgMeta
meta
,
const
char
*
path
);
...
...
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
98bc4630
...
@@ -43,6 +43,7 @@ typedef struct SSyncSnapshotSender {
...
@@ -43,6 +43,7 @@ typedef struct SSyncSnapshotSender {
void
*
pCurrentBlock
;
void
*
pCurrentBlock
;
int32_t
blockLen
;
int32_t
blockLen
;
SSnapshot
snapshot
;
SSnapshot
snapshot
;
SSyncCfg
lastConfig
;
int64_t
sendingMS
;
int64_t
sendingMS
;
SSyncNode
*
pSyncNode
;
SSyncNode
*
pSyncNode
;
int32_t
replicaIndex
;
int32_t
replicaIndex
;
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
98bc4630
...
@@ -88,6 +88,245 @@
...
@@ -88,6 +88,245 @@
// /\ UNCHANGED <<serverVars, commitIndex, messages>>
// /\ UNCHANGED <<serverVars, commitIndex, messages>>
// /\ UNCHANGED <<candidateVars, leaderVars>>
// /\ UNCHANGED <<candidateVars, leaderVars>>
//
//
int32_t
syncNodeOnAppendEntriesCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
int32_t
ret
=
0
;
char
logBuf
[
128
]
=
{
0
};
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==syncNodeOnAppendEntriesCb== term:%lu"
,
ths
->
pRaftStore
->
currentTerm
);
syncAppendEntriesLog2
(
logBuf
,
pMsg
);
if
(
pMsg
->
term
>
ths
->
pRaftStore
->
currentTerm
)
{
syncNodeUpdateTerm
(
ths
,
pMsg
->
term
);
}
assert
(
pMsg
->
term
<=
ths
->
pRaftStore
->
currentTerm
);
// reset elect timer
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
)
{
ths
->
leaderCache
=
pMsg
->
srcId
;
syncNodeResetElectTimer
(
ths
);
}
assert
(
pMsg
->
dataLen
>=
0
);
SyncTerm
localPreLogTerm
=
0
;
if
(
pMsg
->
prevLogIndex
>=
SYNC_INDEX_BEGIN
&&
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
{
SSyncRaftEntry
*
pEntry
=
ths
->
pLogStore
->
getEntry
(
ths
->
pLogStore
,
pMsg
->
prevLogIndex
);
assert
(
pEntry
!=
NULL
);
localPreLogTerm
=
pEntry
->
term
;
syncEntryDestory
(
pEntry
);
}
bool
logOK
=
(
pMsg
->
prevLogIndex
==
SYNC_INDEX_INVALID
)
||
((
pMsg
->
prevLogIndex
>=
SYNC_INDEX_BEGIN
)
&&
(
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
&&
(
pMsg
->
prevLogTerm
==
localPreLogTerm
));
// reject request
if
((
pMsg
->
term
<
ths
->
pRaftStore
->
currentTerm
)
||
((
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
)
&&
(
ths
->
state
==
TAOS_SYNC_STATE_FOLLOWER
)
&&
!
logOK
))
{
sTrace
(
"syncNodeOnAppendEntriesCb --> reject, pMsg->term:%lu, ths->pRaftStore->currentTerm:%lu, ths->state:%d, "
"logOK:%d"
,
pMsg
->
term
,
ths
->
pRaftStore
->
currentTerm
,
ths
->
state
,
logOK
);
SyncAppendEntriesReply
*
pReply
=
syncAppendEntriesReplyBuild
(
ths
->
vgId
);
pReply
->
srcId
=
ths
->
myRaftId
;
pReply
->
destId
=
pMsg
->
srcId
;
pReply
->
term
=
ths
->
pRaftStore
->
currentTerm
;
pReply
->
success
=
false
;
pReply
->
matchIndex
=
SYNC_INDEX_INVALID
;
SRpcMsg
rpcMsg
;
syncAppendEntriesReply2RpcMsg
(
pReply
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
pReply
->
destId
,
ths
,
&
rpcMsg
);
syncAppendEntriesReplyDestroy
(
pReply
);
return
ret
;
}
// return to follower state
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
&&
ths
->
state
==
TAOS_SYNC_STATE_CANDIDATE
)
{
sTrace
(
"syncNodeOnAppendEntriesCb --> return to follower, pMsg->term:%lu, ths->pRaftStore->currentTerm:%lu, "
"ths->state:%d, logOK:%d"
,
pMsg
->
term
,
ths
->
pRaftStore
->
currentTerm
,
ths
->
state
,
logOK
);
syncNodeBecomeFollower
(
ths
,
"from candidate by append entries"
);
// ret or reply?
return
ret
;
}
// accept request
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
&&
ths
->
state
==
TAOS_SYNC_STATE_FOLLOWER
&&
logOK
)
{
// preIndex = -1, or has preIndex entry in local log
assert
(
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
));
// has extra entries (> preIndex) in local log
bool
hasExtraEntries
=
pMsg
->
prevLogIndex
<
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
);
// has entries in SyncAppendEntries msg
bool
hasAppendEntries
=
pMsg
->
dataLen
>
0
;
sTrace
(
"syncNodeOnAppendEntriesCb --> accept, pMsg->term:%lu, ths->pRaftStore->currentTerm:%lu, ths->state:%d, "
"logOK:%d, hasExtraEntries:%d, hasAppendEntries:%d"
,
pMsg
->
term
,
ths
->
pRaftStore
->
currentTerm
,
ths
->
state
,
logOK
,
hasExtraEntries
,
hasAppendEntries
);
if
(
hasExtraEntries
&&
hasAppendEntries
)
{
// not conflict by default
bool
conflict
=
false
;
SyncIndex
extraIndex
=
pMsg
->
prevLogIndex
+
1
;
SSyncRaftEntry
*
pExtraEntry
=
ths
->
pLogStore
->
getEntry
(
ths
->
pLogStore
,
extraIndex
);
assert
(
pExtraEntry
!=
NULL
);
SSyncRaftEntry
*
pAppendEntry
=
syncEntryDeserialize
(
pMsg
->
data
,
pMsg
->
dataLen
);
assert
(
pAppendEntry
!=
NULL
);
// log not match, conflict
assert
(
extraIndex
==
pAppendEntry
->
index
);
if
(
pExtraEntry
->
term
!=
pAppendEntry
->
term
)
{
conflict
=
true
;
}
if
(
conflict
)
{
// roll back
SyncIndex
delBegin
=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
);
SyncIndex
delEnd
=
extraIndex
;
sTrace
(
"syncNodeOnAppendEntriesCb --> conflict:%d, delBegin:%ld, delEnd:%ld"
,
conflict
,
delBegin
,
delEnd
);
// notice! reverse roll back!
for
(
SyncIndex
index
=
delEnd
;
index
>=
delBegin
;
--
index
)
{
if
(
ths
->
pFsm
->
FpRollBackCb
!=
NULL
)
{
SSyncRaftEntry
*
pRollBackEntry
=
ths
->
pLogStore
->
getEntry
(
ths
->
pLogStore
,
index
);
assert
(
pRollBackEntry
!=
NULL
);
// if (pRollBackEntry->msgType != TDMT_SYNC_NOOP) {
if
(
syncUtilUserRollback
(
pRollBackEntry
->
msgType
))
{
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pRollBackEntry
,
&
rpcMsg
);
SFsmCbMeta
cbMeta
;
cbMeta
.
index
=
pRollBackEntry
->
index
;
cbMeta
.
isWeak
=
pRollBackEntry
->
isWeak
;
cbMeta
.
code
=
0
;
cbMeta
.
state
=
ths
->
state
;
cbMeta
.
seqNum
=
pRollBackEntry
->
seqNum
;
ths
->
pFsm
->
FpRollBackCb
(
ths
->
pFsm
,
&
rpcMsg
,
cbMeta
);
rpcFreeCont
(
rpcMsg
.
pCont
);
}
syncEntryDestory
(
pRollBackEntry
);
}
}
// delete confict entries
ths
->
pLogStore
->
truncate
(
ths
->
pLogStore
,
extraIndex
);
// append new entries
ths
->
pLogStore
->
appendEntry
(
ths
->
pLogStore
,
pAppendEntry
);
// pre commit
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pAppendEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
// if (ths->pFsm->FpPreCommitCb != NULL && pAppendEntry->originalRpcType != TDMT_SYNC_NOOP) {
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
syncUtilUserPreCommit
(
pAppendEntry
->
originalRpcType
))
{
SFsmCbMeta
cbMeta
;
cbMeta
.
index
=
pAppendEntry
->
index
;
cbMeta
.
isWeak
=
pAppendEntry
->
isWeak
;
cbMeta
.
code
=
2
;
cbMeta
.
state
=
ths
->
state
;
cbMeta
.
seqNum
=
pAppendEntry
->
seqNum
;
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
cbMeta
);
}
}
rpcFreeCont
(
rpcMsg
.
pCont
);
}
// free memory
syncEntryDestory
(
pExtraEntry
);
syncEntryDestory
(
pAppendEntry
);
}
else
if
(
hasExtraEntries
&&
!
hasAppendEntries
)
{
// do nothing
}
else
if
(
!
hasExtraEntries
&&
hasAppendEntries
)
{
SSyncRaftEntry
*
pAppendEntry
=
syncEntryDeserialize
(
pMsg
->
data
,
pMsg
->
dataLen
);
assert
(
pAppendEntry
!=
NULL
);
// append new entries
ths
->
pLogStore
->
appendEntry
(
ths
->
pLogStore
,
pAppendEntry
);
// pre commit
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pAppendEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
!=
NULL
)
{
// if (ths->pFsm->FpPreCommitCb != NULL && pAppendEntry->originalRpcType != TDMT_SYNC_NOOP) {
if
(
ths
->
pFsm
->
FpPreCommitCb
!=
NULL
&&
syncUtilUserPreCommit
(
pAppendEntry
->
originalRpcType
))
{
SFsmCbMeta
cbMeta
;
cbMeta
.
index
=
pAppendEntry
->
index
;
cbMeta
.
isWeak
=
pAppendEntry
->
isWeak
;
cbMeta
.
code
=
3
;
cbMeta
.
state
=
ths
->
state
;
cbMeta
.
seqNum
=
pAppendEntry
->
seqNum
;
ths
->
pFsm
->
FpPreCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
cbMeta
);
}
}
rpcFreeCont
(
rpcMsg
.
pCont
);
// free memory
syncEntryDestory
(
pAppendEntry
);
}
else
if
(
!
hasExtraEntries
&&
!
hasAppendEntries
)
{
// do nothing
}
else
{
assert
(
0
);
}
SyncAppendEntriesReply
*
pReply
=
syncAppendEntriesReplyBuild
(
ths
->
vgId
);
pReply
->
srcId
=
ths
->
myRaftId
;
pReply
->
destId
=
pMsg
->
srcId
;
pReply
->
term
=
ths
->
pRaftStore
->
currentTerm
;
pReply
->
success
=
true
;
if
(
hasAppendEntries
)
{
pReply
->
matchIndex
=
pMsg
->
prevLogIndex
+
1
;
}
else
{
pReply
->
matchIndex
=
pMsg
->
prevLogIndex
;
}
SRpcMsg
rpcMsg
;
syncAppendEntriesReply2RpcMsg
(
pReply
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
pReply
->
destId
,
ths
,
&
rpcMsg
);
syncAppendEntriesReplyDestroy
(
pReply
);
// maybe update commit index from leader
if
(
pMsg
->
commitIndex
>
ths
->
commitIndex
)
{
// has commit entry in local
if
(
pMsg
->
commitIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
{
SyncIndex
beginIndex
=
ths
->
commitIndex
+
1
;
SyncIndex
endIndex
=
pMsg
->
commitIndex
;
// update commit index
ths
->
commitIndex
=
pMsg
->
commitIndex
;
// call back Wal
ths
->
pLogStore
->
updateCommitIndex
(
ths
->
pLogStore
,
ths
->
commitIndex
);
int32_t
code
=
syncNodeCommit
(
ths
,
beginIndex
,
endIndex
,
ths
->
state
);
ASSERT
(
code
==
0
);
}
}
}
return
ret
;
}
#if 0
int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
int32_t ret = 0;
int32_t ret = 0;
...
@@ -375,7 +614,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -375,7 +614,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
// I am in newConfig
// I am in newConfig
if (hit) {
if (hit) {
syncNodeUpdateConfig
(
ths
,
&
newSyncCfg
,
&
isDrop
);
syncNodeUpdateConfig(ths, &newSyncCfg,
pEntry->index,
&isDrop);
// change isStandBy to normal
// change isStandBy to normal
if (!isDrop) {
if (!isDrop) {
...
@@ -437,6 +676,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -437,6 +676,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
return ret;
return ret;
}
}
#endif
static
int32_t
syncNodeMakeLogSame
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
static
int32_t
syncNodeMakeLogSame
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
int32_t
code
;
int32_t
code
;
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
98bc4630
...
@@ -191,14 +191,17 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
...
@@ -191,14 +191,17 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
char
*
s
=
snapshotSender2Str
(
pSender
);
char
*
s
=
snapshotSender2Str
(
pSender
);
sInfo
(
sInfo
(
"sync event vgId:%d snapshot send to %s:%d start sender first time, lastApplyIndex:%ld lastApplyTerm:%lu "
"sync event vgId:%d snapshot send to %s:%d start sender first time, lastApplyIndex:%ld lastApplyTerm:%lu "
"lastConfigIndex:%ld"
"sender:%s"
,
"sender:%s"
,
ths
->
vgId
,
host
,
port
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
s
);
ths
->
vgId
,
host
,
port
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
pSender
->
snapshot
.
lastConfigIndex
,
s
);
taosMemoryFree
(
s
);
taosMemoryFree
(
s
);
}
else
{
}
else
{
sInfo
(
sInfo
(
"sync event vgId:%d snapshot send to %s:%d start sender first time, lastApplyIndex:%ld "
"sync event vgId:%d snapshot send to %s:%d start sender first time, lastApplyIndex:%ld "
"lastApplyTerm:%lu"
,
"lastApplyTerm:%lu lastConfigIndex:%ld"
,
ths
->
vgId
,
host
,
port
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
);
ths
->
vgId
,
host
,
port
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
pSender
->
snapshot
.
lastConfigIndex
);
}
}
}
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
98bc4630
...
@@ -192,6 +192,40 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg) {
...
@@ -192,6 +192,40 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg) {
return
ret
;
return
ret
;
}
}
int32_t
syncLeaderTransfer
(
int64_t
rid
)
{
int32_t
ret
=
0
;
return
ret
;
}
int32_t
syncLeaderTransferTo
(
int64_t
rid
,
SNodeInfo
newLeader
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
return
false
;
}
assert
(
rid
==
pSyncNode
->
rid
);
int32_t
ret
=
0
;
if
(
pSyncNode
->
replicaNum
==
1
)
{
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
sError
(
"only one replica, cannot drop leader"
);
return
TAOS_SYNC_ONLY_ONE_REPLICA
;
}
SyncLeaderTransfer
*
pMsg
=
syncLeaderTransferBuild
(
pSyncNode
->
vgId
);
pMsg
->
newLeaderId
.
addr
=
syncUtilAddr2U64
(
newLeader
.
nodeFqdn
,
newLeader
.
nodePort
);
pMsg
->
newLeaderId
.
vgId
=
pSyncNode
->
vgId
;
ASSERT
(
pMsg
!=
NULL
);
SRpcMsg
rpcMsg
=
{
0
};
syncLeaderTransfer2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncLeaderTransferDestroy
(
pMsg
);
ret
=
syncPropose
(
rid
,
&
rpcMsg
,
false
);
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
return
ret
;
}
int32_t
syncReconfigRaw
(
int64_t
rid
,
const
SSyncCfg
*
pNewCfg
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
syncReconfigRaw
(
int64_t
rid
,
const
SSyncCfg
*
pNewCfg
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
ret
=
0
;
int32_t
ret
=
0
;
char
*
newconfig
=
syncCfg2Str
((
SSyncCfg
*
)
pNewCfg
);
char
*
newconfig
=
syncCfg2Str
((
SSyncCfg
*
)
pNewCfg
);
...
@@ -206,6 +240,40 @@ int32_t syncReconfigRaw(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg)
...
@@ -206,6 +240,40 @@ int32_t syncReconfigRaw(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg)
return
ret
;
return
ret
;
}
}
bool
syncCanLeaderTransfer
(
int64_t
rid
)
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
return
false
;
}
assert
(
rid
==
pSyncNode
->
rid
);
if
(
pSyncNode
->
replicaNum
==
1
)
{
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
return
false
;
}
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_FOLLOWER
)
{
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
return
true
;
}
bool
matchOK
=
true
;
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_CANDIDATE
||
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
SyncIndex
myCommitIndex
=
pSyncNode
->
commitIndex
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
SyncIndex
peerMatchIndex
=
syncIndexMgrGetIndex
(
pSyncNode
->
pMatchIndex
,
&
(
pSyncNode
->
peersId
)[
i
]);
if
(
peerMatchIndex
<
myCommitIndex
)
{
matchOK
=
false
;
}
}
}
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
return
matchOK
;
}
int32_t
syncGiveUpLeader
(
int64_t
rid
)
{
return
0
;
}
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
;
...
@@ -241,7 +309,9 @@ int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta) {
...
@@ -241,7 +309,9 @@ int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta) {
return
-
1
;
return
-
1
;
}
}
assert
(
rid
==
pSyncNode
->
rid
);
assert
(
rid
==
pSyncNode
->
rid
);
*
sMeta
=
pSyncNode
->
sMeta
;
sMeta
->
lastConfigIndex
=
pSyncNode
->
pRaftCfg
->
lastConfigIndex
;
sTrace
(
"sync get snapshot meta: lastConfigIndex:%ld"
,
pSyncNode
->
pRaftCfg
->
lastConfigIndex
);
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
return
0
;
return
0
;
...
@@ -452,6 +522,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
...
@@ -452,6 +522,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
SRaftCfgMeta
meta
;
SRaftCfgMeta
meta
;
meta
.
isStandBy
=
pSyncInfo
->
isStandBy
;
meta
.
isStandBy
=
pSyncInfo
->
isStandBy
;
meta
.
snapshotEnable
=
pSyncInfo
->
snapshotEnable
;
meta
.
snapshotEnable
=
pSyncInfo
->
snapshotEnable
;
meta
.
lastConfigIndex
=
SYNC_INDEX_INVALID
;
ret
=
raftCfgCreateFile
((
SSyncCfg
*
)
&
(
pSyncInfo
->
syncCfg
),
meta
,
pSyncNode
->
configPath
);
ret
=
raftCfgCreateFile
((
SSyncCfg
*
)
&
(
pSyncInfo
->
syncCfg
),
meta
,
pSyncNode
->
configPath
);
assert
(
ret
==
0
);
assert
(
ret
==
0
);
...
@@ -643,7 +714,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
...
@@ -643,7 +714,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
// syncNodeBecomeFollower(pSyncNode);
// syncNodeBecomeFollower(pSyncNode);
// snapshot meta
// snapshot meta
pSyncNode
->
sMeta
.
lastConfigIndex
=
-
1
;
//
pSyncNode->sMeta.lastConfigIndex = -1;
return
pSyncNode
;
return
pSyncNode
;
}
}
...
@@ -1076,9 +1147,11 @@ char* syncNode2SimpleStr(const SSyncNode* pSyncNode) {
...
@@ -1076,9 +1147,11 @@ char* syncNode2SimpleStr(const SSyncNode* pSyncNode) {
return
s
;
return
s
;
}
}
void
syncNodeUpdateConfig
(
SSyncNode
*
pSyncNode
,
SSyncCfg
*
newConfig
,
bool
*
isDrop
)
{
void
syncNodeUpdateConfig
(
SSyncNode
*
pSyncNode
,
SSyncCfg
*
newConfig
,
SyncIndex
lastConfigChangeIndex
,
bool
*
isDrop
)
{
SSyncCfg
oldConfig
=
pSyncNode
->
pRaftCfg
->
cfg
;
SSyncCfg
oldConfig
=
pSyncNode
->
pRaftCfg
->
cfg
;
pSyncNode
->
pRaftCfg
->
cfg
=
*
newConfig
;
pSyncNode
->
pRaftCfg
->
cfg
=
*
newConfig
;
pSyncNode
->
pRaftCfg
->
lastConfigIndex
=
lastConfigChangeIndex
;
int32_t
ret
=
0
;
int32_t
ret
=
0
;
// init internal
// init internal
...
@@ -1111,13 +1184,12 @@ void syncNodeUpdateConfig(SSyncNode* pSyncNode, SSyncCfg* newConfig, bool* isDro
...
@@ -1111,13 +1184,12 @@ void syncNodeUpdateConfig(SSyncNode* pSyncNode, SSyncCfg* newConfig, bool* isDro
pSyncNode
->
quorum
=
syncUtilQuorum
(
pSyncNode
->
pRaftCfg
->
cfg
.
replicaNum
);
pSyncNode
->
quorum
=
syncUtilQuorum
(
pSyncNode
->
pRaftCfg
->
cfg
.
replicaNum
);
// isDrop
bool
IamInOld
=
false
;
*
isDrop
=
true
;
bool
IamInNew
=
false
;
bool
IamInOld
,
IamInNew
;
for
(
int
i
=
0
;
i
<
oldConfig
.
replicaNum
;
++
i
)
{
for
(
int
i
=
0
;
i
<
oldConfig
.
replicaNum
;
++
i
)
{
if
(
strcmp
((
oldConfig
.
nodeInfo
)[
i
].
nodeFqdn
,
pSyncNode
->
myNodeInfo
.
nodeFqdn
)
==
0
&&
if
(
strcmp
((
oldConfig
.
nodeInfo
)[
i
].
nodeFqdn
,
pSyncNode
->
myNodeInfo
.
nodeFqdn
)
==
0
&&
(
oldConfig
.
nodeInfo
)[
i
].
nodePort
==
pSyncNode
->
myNodeInfo
.
nodePort
)
{
(
oldConfig
.
nodeInfo
)[
i
].
nodePort
==
pSyncNode
->
myNodeInfo
.
nodePort
)
{
*
isDrop
=
fals
e
;
IamInOld
=
tru
e
;
break
;
break
;
}
}
}
}
...
@@ -1125,16 +1197,21 @@ void syncNodeUpdateConfig(SSyncNode* pSyncNode, SSyncCfg* newConfig, bool* isDro
...
@@ -1125,16 +1197,21 @@ void syncNodeUpdateConfig(SSyncNode* pSyncNode, SSyncCfg* newConfig, bool* isDro
for
(
int
i
=
0
;
i
<
newConfig
->
replicaNum
;
++
i
)
{
for
(
int
i
=
0
;
i
<
newConfig
->
replicaNum
;
++
i
)
{
if
(
strcmp
((
newConfig
->
nodeInfo
)[
i
].
nodeFqdn
,
pSyncNode
->
myNodeInfo
.
nodeFqdn
)
==
0
&&
if
(
strcmp
((
newConfig
->
nodeInfo
)[
i
].
nodeFqdn
,
pSyncNode
->
myNodeInfo
.
nodeFqdn
)
==
0
&&
(
newConfig
->
nodeInfo
)[
i
].
nodePort
==
pSyncNode
->
myNodeInfo
.
nodePort
)
{
(
newConfig
->
nodeInfo
)[
i
].
nodePort
==
pSyncNode
->
myNodeInfo
.
nodePort
)
{
*
isDrop
=
fals
e
;
IamInNew
=
tru
e
;
break
;
break
;
}
}
}
}
if
(
!
(
*
isDrop
))
{
*
isDrop
=
true
;
// change isStandBy to normal
if
(
IamInOld
&&
!
IamInNew
)
{
pSyncNode
->
pRaftCfg
->
isStandBy
=
0
;
*
isDrop
=
true
;
}
else
{
*
isDrop
=
false
;
}
}
if
(
IamInNew
)
{
pSyncNode
->
pRaftCfg
->
isStandBy
=
0
;
// change isStandBy to normal
}
raftCfgPersist
(
pSyncNode
->
pRaftCfg
);
raftCfgPersist
(
pSyncNode
->
pRaftCfg
);
if
(
gRaftDetailLog
)
{
if
(
gRaftDetailLog
)
{
...
@@ -1163,7 +1240,7 @@ void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) {
...
@@ -1163,7 +1240,7 @@ void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) {
}
}
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
,
const
char
*
debugStr
)
{
void
syncNodeBecomeFollower
(
SSyncNode
*
pSyncNode
,
const
char
*
debugStr
)
{
sInfo
(
"sync event vgId:%d become follower,
%s"
,
pSyncNode
->
vgId
,
debugStr
);
sInfo
(
"sync event vgId:%d become follower,
isStandBy:%d, %s"
,
pSyncNode
->
vgId
,
pSyncNode
->
pRaftCfg
->
isStandBy
,
debugStr
);
// maybe clear leader cache
// maybe clear leader cache
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
...
@@ -1197,7 +1274,7 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) {
...
@@ -1197,7 +1274,7 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) {
// /\ UNCHANGED <<messages, currentTerm, votedFor, candidateVars, logVars>>
// /\ UNCHANGED <<messages, currentTerm, votedFor, candidateVars, logVars>>
//
//
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
,
const
char
*
debugStr
)
{
void
syncNodeBecomeLeader
(
SSyncNode
*
pSyncNode
,
const
char
*
debugStr
)
{
sInfo
(
"sync event vgId:%d become leader,
%s"
,
pSyncNode
->
vgId
,
debugStr
);
sInfo
(
"sync event vgId:%d become leader,
isStandBy:%d, %s"
,
pSyncNode
->
vgId
,
pSyncNode
->
pRaftCfg
->
isStandBy
,
debugStr
);
// state change
// state change
pSyncNode
->
state
=
TAOS_SYNC_STATE_LEADER
;
pSyncNode
->
state
=
TAOS_SYNC_STATE_LEADER
;
...
@@ -1735,74 +1812,36 @@ const char* syncStr(ESyncState state) {
...
@@ -1735,74 +1812,36 @@ const char* syncStr(ESyncState state) {
}
}
}
}
int32_t
syncNodeCommit
(
SSyncNode
*
ths
,
SyncIndex
beginIndex
,
SyncIndex
endIndex
,
uint64_t
flag
)
{
static
int32_t
syncDoLeaderTransfer
(
SSyncNode
*
ths
,
SRpcMsg
*
pRpcMsg
,
SSyncRaftEntry
*
pEntry
)
{
int32_t
code
=
0
;
SyncLeaderTransfer
*
pSyncLeaderTransfer
;
ESyncState
state
=
flag
;
if
(
syncUtilSameId
(
&
(
pSyncLeaderTransfer
->
newLeaderId
),
&
(
ths
->
myRaftId
)))
{
sInfo
(
"sync event vgId:%d commit by wal from index:%"
PRId64
" to index:%"
PRId64
", %s"
,
ths
->
vgId
,
beginIndex
,
endIndex
,
syncUtilState2String
(
state
));
/*
// maybe execute by leader, skip snapshot
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
if (ths->pFsm->FpGetSnapshot != NULL) {
ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot);
}
if (beginIndex <= snapshot.lastApplyIndex) {
beginIndex = snapshot.lastApplyIndex + 1;
}
}
*/
// execute fsm
return
0
;
if
(
ths
->
pFsm
!=
NULL
)
{
}
for
(
SyncIndex
i
=
beginIndex
;
i
<=
endIndex
;
++
i
)
{
if
(
i
!=
SYNC_INDEX_INVALID
)
{
SSyncRaftEntry
*
pEntry
;
code
=
ths
->
pLogStore
->
syncLogGetEntry
(
ths
->
pLogStore
,
i
,
&
pEntry
);
ASSERT
(
code
==
0
);
ASSERT
(
pEntry
!=
NULL
);
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
if
(
ths
->
pFsm
->
FpCommitCb
!=
NULL
&&
syncUtilUserCommit
(
pEntry
->
originalRpcType
))
{
SFsmCbMeta
cbMeta
;
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
isWeak
=
pEntry
->
isWeak
;
cbMeta
.
code
=
0
;
cbMeta
.
state
=
ths
->
state
;
cbMeta
.
seqNum
=
pEntry
->
seqNum
;
cbMeta
.
term
=
pEntry
->
term
;
cbMeta
.
currentTerm
=
ths
->
pRaftStore
->
currentTerm
;
cbMeta
.
flag
=
flag
;
ths
->
pFsm
->
FpCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
cbMeta
);
}
// config change
static
int32_t
syncNodeConfigChange
(
SSyncNode
*
ths
,
SRpcMsg
*
pRpcMsg
,
SSyncRaftEntry
*
pEntry
)
{
if
(
pEntry
->
originalRpcType
==
TDMT_SYNC_CONFIG_CHANGE
)
{
SSyncCfg
oldSyncCfg
=
ths
->
pRaftCfg
->
cfg
;
SSyncCfg
oldSyncCfg
=
ths
->
pRaftCfg
->
cfg
;
SSyncCfg
newSyncCfg
;
SSyncCfg
newSyncCfg
;
int32_t
ret
=
syncCfgFromStr
(
rpcMsg
.
pCont
,
&
newSyncCfg
);
int32_t
ret
=
syncCfgFromStr
(
pRpcMsg
->
pCont
,
&
newSyncCfg
);
ASSERT
(
ret
==
0
);
ASSERT
(
ret
==
0
);
// update new config myIndex
// update new config myIndex
bool
hit
=
false
;
bool
IamInNew
=
false
;
for
(
int
i
=
0
;
i
<
newSyncCfg
.
replicaNum
;
++
i
)
{
for
(
int
i
=
0
;
i
<
newSyncCfg
.
replicaNum
;
++
i
)
{
if
(
strcmp
(
ths
->
myNodeInfo
.
nodeFqdn
,
(
newSyncCfg
.
nodeInfo
)[
i
].
nodeFqdn
)
==
0
&&
if
(
strcmp
(
ths
->
myNodeInfo
.
nodeFqdn
,
(
newSyncCfg
.
nodeInfo
)[
i
].
nodeFqdn
)
==
0
&&
ths
->
myNodeInfo
.
nodePort
==
(
newSyncCfg
.
nodeInfo
)[
i
].
nodePort
)
{
ths
->
myNodeInfo
.
nodePort
==
(
newSyncCfg
.
nodeInfo
)[
i
].
nodePort
)
{
newSyncCfg
.
myIndex
=
i
;
newSyncCfg
.
myIndex
=
i
;
hit
=
true
;
IamInNew
=
true
;
break
;
break
;
}
}
}
}
SReConfigCbMeta
cbMeta
=
{
0
};
bool
isDrop
;
bool
isDrop
;
// I am in newConfig
if
(
IamInNew
||
(
!
IamInNew
&&
ths
->
state
!=
TAOS_SYNC_STATE_LEADER
))
{
if
(
hit
)
{
syncNodeUpdateConfig
(
ths
,
&
newSyncCfg
,
pEntry
->
index
,
&
isDrop
);
syncNodeUpdateConfig
(
ths
,
&
newSyncCfg
,
&
isDrop
);
// change isStandBy to normal
// change isStandBy to normal
if
(
!
isDrop
)
{
if
(
!
isDrop
)
{
...
@@ -1824,6 +1863,7 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
...
@@ -1824,6 +1863,7 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
// always call FpReConfigCb
// always call FpReConfigCb
if
(
ths
->
pFsm
->
FpReConfigCb
!=
NULL
)
{
if
(
ths
->
pFsm
->
FpReConfigCb
!=
NULL
)
{
SReConfigCbMeta
cbMeta
=
{
0
};
cbMeta
.
code
=
0
;
cbMeta
.
code
=
0
;
cbMeta
.
currentTerm
=
ths
->
pRaftStore
->
currentTerm
;
cbMeta
.
currentTerm
=
ths
->
pRaftStore
->
currentTerm
;
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
index
=
pEntry
->
index
;
...
@@ -1833,8 +1873,55 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
...
@@ -1833,8 +1873,55 @@ int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex,
cbMeta
.
seqNum
=
pEntry
->
seqNum
;
cbMeta
.
seqNum
=
pEntry
->
seqNum
;
cbMeta
.
flag
=
0x11
;
cbMeta
.
flag
=
0x11
;
cbMeta
.
isDrop
=
isDrop
;
cbMeta
.
isDrop
=
isDrop
;
ths
->
pFsm
->
FpReConfigCb
(
ths
->
pFsm
,
&
r
pcMsg
,
cbMeta
);
ths
->
pFsm
->
FpReConfigCb
(
ths
->
pFsm
,
pR
pcMsg
,
cbMeta
);
}
}
return
0
;
}
int32_t
syncNodeCommit
(
SSyncNode
*
ths
,
SyncIndex
beginIndex
,
SyncIndex
endIndex
,
uint64_t
flag
)
{
int32_t
code
=
0
;
ESyncState
state
=
flag
;
sInfo
(
"sync event vgId:%d commit by wal from index:%"
PRId64
" to index:%"
PRId64
", %s"
,
ths
->
vgId
,
beginIndex
,
endIndex
,
syncUtilState2String
(
state
));
// execute fsm
if
(
ths
->
pFsm
!=
NULL
)
{
for
(
SyncIndex
i
=
beginIndex
;
i
<=
endIndex
;
++
i
)
{
if
(
i
!=
SYNC_INDEX_INVALID
)
{
SSyncRaftEntry
*
pEntry
;
code
=
ths
->
pLogStore
->
syncLogGetEntry
(
ths
->
pLogStore
,
i
,
&
pEntry
);
ASSERT
(
code
==
0
);
ASSERT
(
pEntry
!=
NULL
);
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
// user commit
if
(
ths
->
pFsm
->
FpCommitCb
!=
NULL
&&
syncUtilUserCommit
(
pEntry
->
originalRpcType
))
{
SFsmCbMeta
cbMeta
;
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
isWeak
=
pEntry
->
isWeak
;
cbMeta
.
code
=
0
;
cbMeta
.
state
=
ths
->
state
;
cbMeta
.
seqNum
=
pEntry
->
seqNum
;
cbMeta
.
term
=
pEntry
->
term
;
cbMeta
.
currentTerm
=
ths
->
pRaftStore
->
currentTerm
;
cbMeta
.
flag
=
flag
;
ths
->
pFsm
->
FpCommitCb
(
ths
->
pFsm
,
&
rpcMsg
,
cbMeta
);
}
// config change
if
(
pEntry
->
originalRpcType
==
TDMT_SYNC_CONFIG_CHANGE
)
{
code
=
syncNodeConfigChange
(
ths
,
&
rpcMsg
,
pEntry
);
ASSERT
(
code
==
0
);
}
// config change
if
(
pEntry
->
originalRpcType
==
TDMT_SYNC_LEADER_TRANSFER
)
{
code
=
syncDoLeaderTransfer
(
ths
,
&
rpcMsg
,
pEntry
);
ASSERT
(
code
==
0
);
}
}
// restore finish
// restore finish
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
98bc4630
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
*/
*/
#include "syncMessage.h"
#include "syncMessage.h"
#include "syncRaftCfg.h"
#include "syncUtil.h"
#include "syncUtil.h"
#include "tcoding.h"
#include "tcoding.h"
...
@@ -75,6 +76,11 @@ cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg) {
...
@@ -75,6 +76,11 @@ cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg) {
pRoot
=
syncSnapshotRsp2Json
(
pSyncMsg
);
pRoot
=
syncSnapshotRsp2Json
(
pSyncMsg
);
syncSnapshotRspDestroy
(
pSyncMsg
);
syncSnapshotRspDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_LEADER_TRANSFER
)
{
SyncLeaderTransfer
*
pSyncMsg
=
syncLeaderTransferDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
pRoot
=
syncLeaderTransfer2Json
(
pSyncMsg
);
syncLeaderTransferDestroy
(
pSyncMsg
);
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_COMMON_RESPONSE
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_COMMON_RESPONSE
)
{
pRoot
=
cJSON_CreateObject
();
pRoot
=
cJSON_CreateObject
();
char
*
s
;
char
*
s
;
...
@@ -1841,6 +1847,10 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) {
...
@@ -1841,6 +1847,10 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) {
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%ld"
,
pMsg
->
lastIndex
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%ld"
,
pMsg
->
lastIndex
);
cJSON_AddStringToObject
(
pRoot
,
"lastIndex"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"lastIndex"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%ld"
,
pMsg
->
lastConfigIndex
);
cJSON_AddStringToObject
(
pRoot
,
"lastConfigIndex"
,
u64buf
);
cJSON_AddItemToObject
(
pRoot
,
"lastConfig"
,
syncCfg2Json
((
SSyncCfg
*
)
&
(
pMsg
->
lastConfig
)));
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pMsg
->
lastTerm
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pMsg
->
lastTerm
);
cJSON_AddStringToObject
(
pRoot
,
"lastTerm"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"lastTerm"
,
u64buf
);
...
@@ -2056,3 +2066,165 @@ void syncSnapshotRspLog2(char* s, const SyncSnapshotRsp* pMsg) {
...
@@ -2056,3 +2066,165 @@ void syncSnapshotRspLog2(char* s, const SyncSnapshotRsp* pMsg) {
taosMemoryFree
(
serialized
);
taosMemoryFree
(
serialized
);
}
}
}
}
// ---------------------------------------------
SyncLeaderTransfer
*
syncLeaderTransferBuild
(
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncLeaderTransfer
);
SyncLeaderTransfer
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
pMsg
->
msgType
=
TDMT_SYNC_LEADER_TRANSFER
;
return
pMsg
;
}
void
syncLeaderTransferDestroy
(
SyncLeaderTransfer
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncLeaderTransferSerialize
(
const
SyncLeaderTransfer
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
assert
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncLeaderTransferDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncLeaderTransfer
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
assert
(
len
==
pMsg
->
bytes
);
}
char
*
syncLeaderTransferSerialize2
(
const
SyncLeaderTransfer
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
assert
(
buf
!=
NULL
);
syncLeaderTransferSerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncLeaderTransfer
*
syncLeaderTransferDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncLeaderTransfer
*
pMsg
=
taosMemoryMalloc
(
bytes
);
assert
(
pMsg
!=
NULL
);
syncLeaderTransferDeserialize
(
buf
,
len
,
pMsg
);
assert
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncLeaderTransfer2RpcMsg
(
const
SyncLeaderTransfer
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncLeaderTransferSerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncLeaderTransferFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncLeaderTransfer
*
pMsg
)
{
syncLeaderTransferDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncLeaderTransfer
*
syncLeaderTransferFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncLeaderTransfer
*
pMsg
=
syncLeaderTransferDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
assert
(
pMsg
!=
NULL
);
return
pMsg
;
}
cJSON
*
syncLeaderTransfer2Json
(
const
SyncLeaderTransfer
*
pMsg
)
{
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pMsg
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pMsg
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"vgId"
,
pMsg
->
vgId
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pMsg
->
msgType
);
/*
cJSON* pSrcId = cJSON_CreateObject();
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->srcId.addr);
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
{
uint64_t u64 = pMsg->srcId.addr;
cJSON* pTmp = pSrcId;
char host[128];
uint16_t port;
syncUtilU642Addr(u64, host, sizeof(host), &port);
cJSON_AddStringToObject(pTmp, "addr_host", host);
cJSON_AddNumberToObject(pTmp, "addr_port", port);
}
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
cJSON* pDestId = cJSON_CreateObject();
snprintf(u64buf, sizeof(u64buf), "%lu", pMsg->destId.addr);
cJSON_AddStringToObject(pDestId, "addr", u64buf);
{
uint64_t u64 = pMsg->destId.addr;
cJSON* pTmp = pDestId;
char host[128];
uint16_t port;
syncUtilU642Addr(u64, host, sizeof(host), &port);
cJSON_AddStringToObject(pTmp, "addr_host", host);
cJSON_AddNumberToObject(pTmp, "addr_port", port);
}
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
cJSON_AddItemToObject(pRoot, "destId", pDestId);
*/
cJSON
*
pNewerId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pMsg
->
newLeaderId
.
addr
);
cJSON_AddStringToObject
(
pNewerId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
newLeaderId
.
addr
;
cJSON
*
pTmp
=
pNewerId
;
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
cJSON_AddNumberToObject
(
pNewerId
,
"vgId"
,
pMsg
->
newLeaderId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"newLeaderId"
,
pNewerId
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncLeaderTransfer"
,
pRoot
);
return
pJson
;
}
char
*
syncLeaderTransfer2Str
(
const
SyncLeaderTransfer
*
pMsg
)
{
cJSON
*
pJson
=
syncLeaderTransfer2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
// for debug ----------------------
void
syncLeaderTransferPrint
(
const
SyncLeaderTransfer
*
pMsg
)
{
char
*
serialized
=
syncLeaderTransfer2Str
(
pMsg
);
printf
(
"syncLeaderTransferPrint | len:%lu | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncLeaderTransferPrint2
(
char
*
s
,
const
SyncLeaderTransfer
*
pMsg
)
{
char
*
serialized
=
syncLeaderTransfer2Str
(
pMsg
);
printf
(
"syncLeaderTransferPrint2 | len:%lu | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncLeaderTransferLog
(
const
SyncLeaderTransfer
*
pMsg
)
{
char
*
serialized
=
syncLeaderTransfer2Str
(
pMsg
);
sTrace
(
"syncLeaderTransferLog | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
syncLeaderTransferLog2
(
char
*
s
,
const
SyncLeaderTransfer
*
pMsg
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
syncLeaderTransfer2Str
(
pMsg
);
sTrace
(
"syncLeaderTransferLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
}
\ No newline at end of file
source/libs/sync/src/syncRaftCfg.c
浏览文件 @
98bc4630
...
@@ -150,6 +150,10 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) {
...
@@ -150,6 +150,10 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) {
cJSON_AddNumberToObject
(
pRoot
,
"isStandBy"
,
pRaftCfg
->
isStandBy
);
cJSON_AddNumberToObject
(
pRoot
,
"isStandBy"
,
pRaftCfg
->
isStandBy
);
cJSON_AddNumberToObject
(
pRoot
,
"snapshotEnable"
,
pRaftCfg
->
snapshotEnable
);
cJSON_AddNumberToObject
(
pRoot
,
"snapshotEnable"
,
pRaftCfg
->
snapshotEnable
);
char
buf64
[
128
];
snprintf
(
buf64
,
sizeof
(
buf64
),
"%ld"
,
pRaftCfg
->
lastConfigIndex
);
cJSON_AddStringToObject
(
pRoot
,
"lastConfigIndex"
,
buf64
);
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"RaftCfg"
,
pRoot
);
cJSON_AddItemToObject
(
pJson
,
"RaftCfg"
,
pRoot
);
return
pJson
;
return
pJson
;
...
@@ -172,6 +176,7 @@ int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path) {
...
@@ -172,6 +176,7 @@ int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path) {
raftCfg
.
cfg
=
*
pCfg
;
raftCfg
.
cfg
=
*
pCfg
;
raftCfg
.
isStandBy
=
meta
.
isStandBy
;
raftCfg
.
isStandBy
=
meta
.
isStandBy
;
raftCfg
.
snapshotEnable
=
meta
.
snapshotEnable
;
raftCfg
.
snapshotEnable
=
meta
.
snapshotEnable
;
raftCfg
.
lastConfigIndex
=
meta
.
lastConfigIndex
;
char
*
s
=
raftCfg2Str
(
&
raftCfg
);
char
*
s
=
raftCfg2Str
(
&
raftCfg
);
char
buf
[
CONFIG_FILE_LEN
]
=
{
0
};
char
buf
[
CONFIG_FILE_LEN
]
=
{
0
};
...
@@ -199,6 +204,9 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) {
...
@@ -199,6 +204,9 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) {
cJSON
*
pJsonSnapshotEnable
=
cJSON_GetObjectItem
(
pJson
,
"snapshotEnable"
);
cJSON
*
pJsonSnapshotEnable
=
cJSON_GetObjectItem
(
pJson
,
"snapshotEnable"
);
pRaftCfg
->
snapshotEnable
=
cJSON_GetNumberValue
(
pJsonSnapshotEnable
);
pRaftCfg
->
snapshotEnable
=
cJSON_GetNumberValue
(
pJsonSnapshotEnable
);
cJSON
*
pJsonLastConfigIndex
=
cJSON_GetObjectItem
(
pJson
,
"lastConfigIndex"
);
pRaftCfg
->
lastConfigIndex
=
atoll
(
cJSON_GetStringValue
(
pJsonLastConfigIndex
));
cJSON
*
pJsonSyncCfg
=
cJSON_GetObjectItem
(
pJson
,
"SSyncCfg"
);
cJSON
*
pJsonSyncCfg
=
cJSON_GetObjectItem
(
pJson
,
"SSyncCfg"
);
int32_t
code
=
syncCfgFromJson
(
pJsonSyncCfg
,
&
(
pRaftCfg
->
cfg
));
int32_t
code
=
syncCfgFromJson
(
pJsonSyncCfg
,
&
(
pRaftCfg
->
cfg
));
ASSERT
(
code
==
0
);
ASSERT
(
code
==
0
);
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
98bc4630
...
@@ -553,15 +553,19 @@ void logStorePrint2(char* s, SSyncLogStore* pLogStore) {
...
@@ -553,15 +553,19 @@ void logStorePrint2(char* s, SSyncLogStore* pLogStore) {
}
}
void
logStoreLog
(
SSyncLogStore
*
pLogStore
)
{
void
logStoreLog
(
SSyncLogStore
*
pLogStore
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
logStore2Str
(
pLogStore
);
char
*
serialized
=
logStore2Str
(
pLogStore
);
sTraceLong
(
"logStoreLog | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
sTraceLong
(
"logStoreLog | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
taosMemoryFree
(
serialized
);
}
}
}
void
logStoreLog2
(
char
*
s
,
SSyncLogStore
*
pLogStore
)
{
void
logStoreLog2
(
char
*
s
,
SSyncLogStore
*
pLogStore
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
logStore2Str
(
pLogStore
);
char
*
serialized
=
logStore2Str
(
pLogStore
);
sTraceLong
(
"logStoreLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
sTraceLong
(
"logStoreLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
taosMemoryFree
(
serialized
);
}
}
}
// for debug -----------------
// for debug -----------------
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
98bc4630
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#include "syncSnapshot.h"
#include "syncSnapshot.h"
#include "syncIndexMgr.h"
#include "syncIndexMgr.h"
#include "syncRaftCfg.h"
#include "syncRaftLog.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
#include "syncUtil.h"
...
@@ -83,6 +84,32 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender) {
...
@@ -83,6 +84,32 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender) {
// get current snapshot info
// get current snapshot info
pSender
->
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSender
->
pSyncNode
->
pFsm
,
&
(
pSender
->
snapshot
));
pSender
->
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSender
->
pSyncNode
->
pFsm
,
&
(
pSender
->
snapshot
));
if
(
pSender
->
snapshot
.
lastConfigIndex
!=
SYNC_INDEX_INVALID
)
{
/*
SSyncRaftEntry *pEntry = NULL;
int32_t code = pSender->pSyncNode->pLogStore->syncLogGetEntry(pSender->pSyncNode->pLogStore,
pSender->snapshot.lastConfigIndex, &pEntry);
ASSERT(code == 0);
ASSERT(pEntry != NULL);
*/
SSyncRaftEntry
*
pEntry
=
pSender
->
pSyncNode
->
pLogStore
->
getEntry
(
pSender
->
pSyncNode
->
pLogStore
,
pSender
->
snapshot
.
lastConfigIndex
);
ASSERT
(
pEntry
!=
NULL
);
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
SSyncCfg
lastConfig
;
int32_t
ret
=
syncCfgFromStr
(
rpcMsg
.
pCont
,
&
lastConfig
);
ASSERT
(
ret
==
0
);
pSender
->
lastConfig
=
lastConfig
;
rpcFreeCont
(
rpcMsg
.
pCont
);
syncEntryDestory
(
pEntry
);
}
else
{
memset
(
&
(
pSender
->
lastConfig
),
0
,
sizeof
(
SSyncCfg
));
}
pSender
->
sendingMS
=
SYNC_SNAPSHOT_RETRY_MS
;
pSender
->
sendingMS
=
SYNC_SNAPSHOT_RETRY_MS
;
pSender
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pSender
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
...
@@ -97,6 +124,8 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender) {
...
@@ -97,6 +124,8 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender) {
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
lastIndex
=
pSender
->
snapshot
.
lastApplyIndex
;
pMsg
->
lastIndex
=
pSender
->
snapshot
.
lastApplyIndex
;
pMsg
->
lastTerm
=
pSender
->
snapshot
.
lastApplyTerm
;
pMsg
->
lastTerm
=
pSender
->
snapshot
.
lastApplyTerm
;
pMsg
->
lastConfigIndex
=
pSender
->
snapshot
.
lastConfigIndex
;
pMsg
->
lastConfig
=
pSender
->
lastConfig
;
pMsg
->
seq
=
pSender
->
seq
;
// SYNC_SNAPSHOT_SEQ_BEGIN
pMsg
->
seq
=
pSender
->
seq
;
// SYNC_SNAPSHOT_SEQ_BEGIN
pMsg
->
privateTerm
=
pSender
->
privateTerm
;
pMsg
->
privateTerm
=
pSender
->
privateTerm
;
...
@@ -112,15 +141,18 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender) {
...
@@ -112,15 +141,18 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender) {
if
(
gRaftDetailLog
)
{
if
(
gRaftDetailLog
)
{
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
sTrace
(
sTrace
(
"sync event vgId:%d snapshot send to %s:%d begin seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu send "
"sync event vgId:%d snapshot send to %s:%d begin seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu "
"lastConfigIndex:%ld send "
"msg:%s"
,
"msg:%s"
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
msgStr
);
pSender
->
snapshot
.
lastApplyTerm
,
pSender
->
snapshot
.
lastConfigIndex
,
msgStr
);
taosMemoryFree
(
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
{
}
else
{
sTrace
(
"sync event vgId:%d snapshot send to %s:%d begin seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu"
,
sTrace
(
"sync event vgId:%d snapshot send to %s:%d begin seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu "
"lastConfigIndex:%ld"
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
);
pSender
->
snapshot
.
lastApplyTerm
,
pSender
->
snapshot
.
lastConfigIndex
);
}
}
syncSnapshotSendDestroy
(
pMsg
);
syncSnapshotSendDestroy
(
pMsg
);
...
@@ -228,6 +260,8 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
...
@@ -228,6 +260,8 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
lastIndex
=
pSender
->
snapshot
.
lastApplyIndex
;
pMsg
->
lastIndex
=
pSender
->
snapshot
.
lastApplyIndex
;
pMsg
->
lastTerm
=
pSender
->
snapshot
.
lastApplyTerm
;
pMsg
->
lastTerm
=
pSender
->
snapshot
.
lastApplyTerm
;
pMsg
->
lastConfigIndex
=
pSender
->
snapshot
.
lastConfigIndex
;
pMsg
->
lastConfig
=
pSender
->
lastConfig
;
pMsg
->
seq
=
pSender
->
seq
;
pMsg
->
seq
=
pSender
->
seq
;
pMsg
->
privateTerm
=
pSender
->
privateTerm
;
pMsg
->
privateTerm
=
pSender
->
privateTerm
;
memcpy
(
pMsg
->
data
,
pSender
->
pCurrentBlock
,
pSender
->
blockLen
);
memcpy
(
pMsg
->
data
,
pSender
->
pCurrentBlock
,
pSender
->
blockLen
);
...
@@ -245,20 +279,25 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
...
@@ -245,20 +279,25 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
if
(
gRaftDetailLog
)
{
if
(
gRaftDetailLog
)
{
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
sTrace
(
sTrace
(
"sync event vgId:%d snapshot send to %s:%d finish seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu send "
"sync event vgId:%d snapshot send to %s:%d finish seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu "
"lastConfigIndex:%ld send "
"msg:%s"
,
"msg:%s"
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
msgStr
);
pSender
->
snapshot
.
lastApplyTerm
,
pSender
->
snapshot
.
lastConfigIndex
,
msgStr
);
taosMemoryFree
(
msgStr
);
taosMemoryFree
(
msgStr
);
}
else
{
}
else
{
sTrace
(
"sync event vgId:%d snapshot send to %s:%d finish seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu"
,
sTrace
(
"sync event vgId:%d snapshot send to %s:%d finish seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu "
"lastConfigIndex:%ld"
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
);
pSender
->
snapshot
.
lastApplyTerm
,
pSender
->
snapshot
.
lastConfigIndex
);
}
}
}
else
{
}
else
{
sTrace
(
"sync event vgId:%d snapshot send to %s:%d sending seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu"
,
sTrace
(
"sync event vgId:%d snapshot send to %s:%d sending seq:%d ack:%d lastApplyIndex:%ld lastApplyTerm:%lu "
"lastConfigIndex:%ld"
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
pSyncNode
->
vgId
,
host
,
port
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
);
pSender
->
snapshot
.
lastApplyTerm
,
pSender
->
snapshot
.
lastConfigIndex
);
}
}
syncSnapshotSendDestroy
(
pMsg
);
syncSnapshotSendDestroy
(
pMsg
);
...
@@ -274,6 +313,8 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
...
@@ -274,6 +313,8 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
lastIndex
=
pSender
->
snapshot
.
lastApplyIndex
;
pMsg
->
lastIndex
=
pSender
->
snapshot
.
lastApplyIndex
;
pMsg
->
lastTerm
=
pSender
->
snapshot
.
lastApplyTerm
;
pMsg
->
lastTerm
=
pSender
->
snapshot
.
lastApplyTerm
;
pMsg
->
lastConfigIndex
=
pSender
->
snapshot
.
lastConfigIndex
;
pMsg
->
lastConfig
=
pSender
->
lastConfig
;
pMsg
->
seq
=
pSender
->
seq
;
pMsg
->
seq
=
pSender
->
seq
;
memcpy
(
pMsg
->
data
,
pSender
->
pCurrentBlock
,
pSender
->
blockLen
);
memcpy
(
pMsg
->
data
,
pSender
->
pCurrentBlock
,
pSender
->
blockLen
);
...
@@ -352,7 +393,7 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) {
...
@@ -352,7 +393,7 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) {
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
)
{
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
)
{
cJSON
*
pJson
=
snapshotSender2Json
(
pSender
);
cJSON
*
pJson
=
snapshotSender2Json
(
pSender
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
return
serialized
;
}
}
...
@@ -473,7 +514,7 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
...
@@ -473,7 +514,7 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
cJSON_AddStringToObject
(
pFromId
,
"addr"
,
u64buf
);
cJSON_AddStringToObject
(
pFromId
,
"addr"
,
u64buf
);
{
{
uint64_t
u64
=
pReceiver
->
fromId
.
addr
;
uint64_t
u64
=
pReceiver
->
fromId
.
addr
;
cJSON
*
pTmp
=
pFromId
;
cJSON
*
pTmp
=
pFromId
;
char
host
[
128
]
=
{
0
};
char
host
[
128
]
=
{
0
};
uint16_t
port
;
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
...
@@ -497,7 +538,7 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
...
@@ -497,7 +538,7 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
)
{
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
)
{
cJSON
*
pJson
=
snapshotReceiver2Json
(
pReceiver
);
cJSON
*
pJson
=
snapshotReceiver2Json
(
pReceiver
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
return
serialized
;
}
}
...
@@ -540,6 +581,42 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
...
@@ -540,6 +581,42 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
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
);
// maybe update lastconfig
if
(
pMsg
->
lastConfigIndex
>=
SYNC_INDEX_BEGIN
)
{
// update new config myIndex
bool
IamInNew
=
false
;
SSyncCfg
newSyncCfg
=
pMsg
->
lastConfig
;
for
(
int
i
=
0
;
i
<
newSyncCfg
.
replicaNum
;
++
i
)
{
if
(
strcmp
(
pSyncNode
->
myNodeInfo
.
nodeFqdn
,
(
newSyncCfg
.
nodeInfo
)[
i
].
nodeFqdn
)
==
0
&&
pSyncNode
->
myNodeInfo
.
nodePort
==
(
newSyncCfg
.
nodeInfo
)[
i
].
nodePort
)
{
newSyncCfg
.
myIndex
=
i
;
IamInNew
=
true
;
break
;
}
}
bool
isDrop
;
if
(
IamInNew
)
{
sTrace
(
"sync event vgId:%d update config by snapshot, lastIndex:%ld, lastTerm:%lu, lastConfigIndex:%ld "
,
pSyncNode
->
vgId
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
pMsg
->
lastConfigIndex
);
syncNodeUpdateConfig
(
pSyncNode
,
&
newSyncCfg
,
pMsg
->
lastConfigIndex
,
&
isDrop
);
}
else
{
sTrace
(
"sync event vgId:%d do not update config by snapshot, I am not in newCfg, lastIndex:%ld, lastTerm:%lu, "
"lastConfigIndex:%ld "
,
pSyncNode
->
vgId
,
pMsg
->
lastIndex
,
pMsg
->
lastTerm
,
pMsg
->
lastConfigIndex
);
}
// change isStandBy to normal
if
(
!
isDrop
)
{
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
syncNodeBecomeLeader
(
pSyncNode
,
"config change"
);
}
else
{
syncNodeBecomeFollower
(
pSyncNode
,
"config change"
);
}
}
}
SSnapshot
snapshot
;
SSnapshot
snapshot
;
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSyncNode
->
pFsm
,
&
snapshot
);
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSyncNode
->
pFsm
,
&
snapshot
);
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
98bc4630
...
@@ -214,29 +214,31 @@ void syncUtilMsgNtoH(void* msg) {
...
@@ -214,29 +214,31 @@ void syncUtilMsgNtoH(void* msg) {
pHead
->
vgId
=
ntohl
(
pHead
->
vgId
);
pHead
->
vgId
=
ntohl
(
pHead
->
vgId
);
}
}
#if 0
bool syncUtilIsData(tmsg_t msgType) {
bool syncUtilIsData(tmsg_t msgType) {
if (msgType == TDMT_SYNC_NOOP || msgType == TDMT_SYNC_CONFIG_CHANGE) {
if (msgType == TDMT_SYNC_NOOP || msgType == TDMT_SYNC_CONFIG_CHANGE) {
return false;
return false;
}
}
return true;
return true;
}
}
#endif
bool
syncUtilUserPreCommit
(
tmsg_t
msgType
)
{
bool
syncUtilUserPreCommit
(
tmsg_t
msgType
)
{
if
(
msgType
!=
TDMT_SYNC_NOOP
&&
msgType
!=
TDMT_SYNC_CONFIG_CHANGE
)
{
if
(
msgType
!=
TDMT_SYNC_NOOP
&&
msgType
!=
TDMT_SYNC_CONFIG_CHANGE
&&
msgType
!=
TDMT_SYNC_LEADER_TRANSFER
)
{
return
true
;
return
true
;
}
}
return
false
;
return
false
;
}
}
bool
syncUtilUserCommit
(
tmsg_t
msgType
)
{
bool
syncUtilUserCommit
(
tmsg_t
msgType
)
{
if
(
msgType
!=
TDMT_SYNC_NOOP
&&
msgType
!=
TDMT_SYNC_CONFIG_CHANGE
)
{
if
(
msgType
!=
TDMT_SYNC_NOOP
&&
msgType
!=
TDMT_SYNC_CONFIG_CHANGE
&&
msgType
!=
TDMT_SYNC_LEADER_TRANSFER
)
{
return
true
;
return
true
;
}
}
return
false
;
return
false
;
}
}
bool
syncUtilUserRollback
(
tmsg_t
msgType
)
{
bool
syncUtilUserRollback
(
tmsg_t
msgType
)
{
if
(
msgType
!=
TDMT_SYNC_NOOP
&&
msgType
!=
TDMT_SYNC_CONFIG_CHANGE
)
{
if
(
msgType
!=
TDMT_SYNC_NOOP
&&
msgType
!=
TDMT_SYNC_CONFIG_CHANGE
&&
msgType
!=
TDMT_SYNC_LEADER_TRANSFER
)
{
return
true
;
return
true
;
}
}
return
false
;
return
false
;
...
...
source/libs/sync/test/CMakeLists.txt
浏览文件 @
98bc4630
...
@@ -47,6 +47,7 @@ add_executable(syncTestTool "")
...
@@ -47,6 +47,7 @@ add_executable(syncTestTool "")
add_executable
(
syncRaftLogTest
""
)
add_executable
(
syncRaftLogTest
""
)
add_executable
(
syncRaftLogTest2
""
)
add_executable
(
syncRaftLogTest2
""
)
add_executable
(
syncRaftLogTest3
""
)
add_executable
(
syncRaftLogTest3
""
)
add_executable
(
syncLeaderTransferTest
""
)
target_sources
(
syncTest
target_sources
(
syncTest
...
@@ -245,6 +246,10 @@ target_sources(syncRaftLogTest3
...
@@ -245,6 +246,10 @@ target_sources(syncRaftLogTest3
PRIVATE
PRIVATE
"syncRaftLogTest3.cpp"
"syncRaftLogTest3.cpp"
)
)
target_sources
(
syncLeaderTransferTest
PRIVATE
"syncLeaderTransferTest.cpp"
)
target_include_directories
(
syncTest
target_include_directories
(
syncTest
...
@@ -492,6 +497,11 @@ target_include_directories(syncRaftLogTest3
...
@@ -492,6 +497,11 @@ target_include_directories(syncRaftLogTest3
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
)
target_include_directories
(
syncLeaderTransferTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_link_libraries
(
syncTest
target_link_libraries
(
syncTest
...
@@ -690,6 +700,10 @@ target_link_libraries(syncRaftLogTest3
...
@@ -690,6 +700,10 @@ target_link_libraries(syncRaftLogTest3
sync
sync
gtest_main
gtest_main
)
)
target_link_libraries
(
syncLeaderTransferTest
sync
gtest_main
)
enable_testing
()
enable_testing
()
...
...
source/libs/sync/test/syncLeaderTransferTest.cpp
0 → 100644
浏览文件 @
98bc4630
此差异已折叠。
点击以展开。
source/libs/sync/test/syncRaftCfgTest.cpp
浏览文件 @
98bc4630
...
@@ -74,6 +74,7 @@ void test3() {
...
@@ -74,6 +74,7 @@ void test3() {
SRaftCfgMeta
meta
;
SRaftCfgMeta
meta
;
meta
.
isStandBy
=
7
;
meta
.
isStandBy
=
7
;
meta
.
snapshotEnable
=
9
;
meta
.
snapshotEnable
=
9
;
meta
.
lastConfigIndex
=
789
;
raftCfgCreateFile
(
pCfg
,
meta
,
s
);
raftCfgCreateFile
(
pCfg
,
meta
,
s
);
printf
(
"%s create json file: %s
\n
"
,
(
char
*
)
__FUNCTION__
,
s
);
printf
(
"%s create json file: %s
\n
"
,
(
char
*
)
__FUNCTION__
,
s
);
}
}
...
@@ -98,6 +99,7 @@ void test5() {
...
@@ -98,6 +99,7 @@ void test5() {
pCfg
->
cfg
.
myIndex
=
taosGetTimestampSec
();
pCfg
->
cfg
.
myIndex
=
taosGetTimestampSec
();
pCfg
->
isStandBy
+=
2
;
pCfg
->
isStandBy
+=
2
;
pCfg
->
snapshotEnable
+=
3
;
pCfg
->
snapshotEnable
+=
3
;
pCfg
->
lastConfigIndex
+=
1000
;
raftCfgPersist
(
pCfg
);
raftCfgPersist
(
pCfg
);
printf
(
"%s update json file: %s myIndex->%d
\n
"
,
(
char
*
)
__FUNCTION__
,
"./test3_raft_cfg.json"
,
pCfg
->
cfg
.
myIndex
);
printf
(
"%s update json file: %s myIndex->%d
\n
"
,
(
char
*
)
__FUNCTION__
,
"./test3_raft_cfg.json"
,
pCfg
->
cfg
.
myIndex
);
...
...
source/libs/sync/test/syncSnapshotSendTest.cpp
浏览文件 @
98bc4630
...
@@ -24,6 +24,16 @@ SyncSnapshotSend *createMsg() {
...
@@ -24,6 +24,16 @@ SyncSnapshotSend *createMsg() {
pMsg
->
privateTerm
=
99
;
pMsg
->
privateTerm
=
99
;
pMsg
->
lastIndex
=
22
;
pMsg
->
lastIndex
=
22
;
pMsg
->
lastTerm
=
33
;
pMsg
->
lastTerm
=
33
;
pMsg
->
lastConfigIndex
=
99
;
pMsg
->
lastConfig
.
replicaNum
=
3
;
pMsg
->
lastConfig
.
myIndex
=
1
;
for
(
int
i
=
0
;
i
<
pMsg
->
lastConfig
.
replicaNum
;
++
i
)
{
((
pMsg
->
lastConfig
.
nodeInfo
)[
i
]).
nodePort
=
i
*
100
;
snprintf
(((
pMsg
->
lastConfig
.
nodeInfo
)[
i
]).
nodeFqdn
,
sizeof
(((
pMsg
->
lastConfig
.
nodeInfo
)[
i
]).
nodeFqdn
),
"100.200.300.%d"
,
i
);
}
pMsg
->
seq
=
44
;
pMsg
->
seq
=
44
;
strcpy
(
pMsg
->
data
,
"hello world"
);
strcpy
(
pMsg
->
data
,
"hello world"
);
return
pMsg
;
return
pMsg
;
...
@@ -87,6 +97,8 @@ void test5() {
...
@@ -87,6 +97,8 @@ void test5() {
}
}
int
main
()
{
int
main
()
{
gRaftDetailLog
=
true
;
tsAsyncLog
=
0
;
tsAsyncLog
=
0
;
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
;
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
;
logTest
();
logTest
();
...
...
source/util/src/terror.c
浏览文件 @
98bc4630
...
@@ -353,9 +353,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDB_IVLD_TAG_VAL, "TSDB invalid tag valu
...
@@ -353,9 +353,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDB_IVLD_TAG_VAL, "TSDB invalid tag valu
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_NO_CACHE_LAST_ROW
,
"TSDB no cache last row data"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_NO_CACHE_LAST_ROW
,
"TSDB no cache last row data"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_TABLE_RECREATED
,
"Table re-created"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_TABLE_RECREATED
,
"Table re-created"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR
,
"TDB env open error"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR
,
"TDB env open error"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_NO_SMA_INDEX_IN_META
,
"No sma index in meta"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_INVALID_SMA_STAT
,
"Invalid sma state"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TDB_TSMA_ALREADY_EXIST
,
"TSMA already exists"
)
// query
// query
...
@@ -557,6 +554,19 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SML_INVALID_PRECISION_TYPE, "Invalid timestamp pre
...
@@ -557,6 +554,19 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SML_INVALID_PRECISION_TYPE, "Invalid timestamp pre
TAOS_DEFINE_ERROR
(
TSDB_CODE_SML_INVALID_DATA
,
"Invalid data type"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SML_INVALID_DATA
,
"Invalid data type"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SML_INVALID_DB_CONF
,
"Invalid schemaless db config"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SML_INVALID_DB_CONF
,
"Invalid schemaless db config"
)
//tsma
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSMA_ALREADY_EXIST
,
"Tsma already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSMA_NO_INDEX_IN_META
,
"No tsma index in meta"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSMA_INVALID_ENV
,
"Invalid tsma env"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSMA_INVALID_STAT
,
"Invalid tsma state"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSMA_NO_INDEX_IN_CACHE
,
"No tsma index in cache"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_TSMA_RM_SKEY_IN_HASH
,
"Rm tsma skey in cache"
)
//rsma
TAOS_DEFINE_ERROR
(
TSDB_CODE_RSMA_INVALID_ENV
,
"Invalid rsma env"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_RSMA_INVALID_STAT
,
"Invalid rsma state"
)
#ifdef TAOS_ERROR_C
#ifdef TAOS_ERROR_C
};
};
#endif
#endif
...
...
tests/script/jenkins/basic.txt
浏览文件 @
98bc4630
...
@@ -57,7 +57,7 @@
...
@@ -57,7 +57,7 @@
# ---- mnode
# ---- mnode
./test.sh -f tsim/mnode/basic1.sim
./test.sh -f tsim/mnode/basic1.sim
#
./test.sh -f tsim/mnode/basic2.sim
./test.sh -f tsim/mnode/basic2.sim
./test.sh -f tsim/mnode/basic3.sim
./test.sh -f tsim/mnode/basic3.sim
./test.sh -f tsim/mnode/basic4.sim
./test.sh -f tsim/mnode/basic4.sim
...
@@ -71,6 +71,7 @@
...
@@ -71,6 +71,7 @@
./test.sh -f tsim/stream/basic0.sim
./test.sh -f tsim/stream/basic0.sim
./test.sh -f tsim/stream/basic1.sim
./test.sh -f tsim/stream/basic1.sim
./test.sh -f tsim/stream/basic2.sim
./test.sh -f tsim/stream/basic2.sim
# ./test.sh -f tsim/stream/distributeInterval0.sim
# ./test.sh -f tsim/stream/session0.sim
# ./test.sh -f tsim/stream/session0.sim
# ./test.sh -f tsim/stream/session1.sim
# ./test.sh -f tsim/stream/session1.sim
# ./test.sh -f tsim/stream/state0.sim
# ./test.sh -f tsim/stream/state0.sim
...
...
tests/script/tsim/db/alter_option.sim
浏览文件 @
98bc4630
此差异已折叠。
点击以展开。
tests/script/tsim/db/basic6.sim
浏览文件 @
98bc4630
此差异已折叠。
点击以展开。
tests/script/tsim/db/create_all_options.sim
浏览文件 @
98bc4630
此差异已折叠。
点击以展开。
tests/script/tsim/mnode/basic2.sim
浏览文件 @
98bc4630
此差异已折叠。
点击以展开。
tests/script/tsim/mnode/basic3.sim
浏览文件 @
98bc4630
此差异已折叠。
点击以展开。
tests/script/tsim/stream/distributeInterval0.sim
0 → 100644
浏览文件 @
98bc4630
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录