Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0d41f9c8
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看板
提交
0d41f9c8
编写于
7月 01, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/3.0' into fix/tsim
上级
344ef7e1
437c06e5
变更
83
展开全部
隐藏空白更改
内联
并排
Showing
83 changed file
with
1618 addition
and
2717 deletion
+1618
-2717
Jenkinsfile2
Jenkinsfile2
+3
-0
include/common/tdatablock.h
include/common/tdatablock.h
+2
-0
include/common/tdataformat.h
include/common/tdataformat.h
+1
-0
include/common/tmsgdef.h
include/common/tmsgdef.h
+2
-0
include/libs/sync/sync.h
include/libs/sync/sync.h
+5
-1
include/libs/sync/syncTools.h
include/libs/sync/syncTools.h
+60
-0
include/libs/wal/wal.h
include/libs/wal/wal.h
+39
-42
include/os/osFile.h
include/os/osFile.h
+34
-34
include/util/taoserror.h
include/util/taoserror.h
+5
-0
include/util/tutil.h
include/util/tutil.h
+6
-4
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+73
-3
source/common/src/tvariant.c
source/common/src/tvariant.c
+5
-2
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+1
-1
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+8
-0
source/dnode/vnode/src/inc/tq.h
source/dnode/vnode/src/inc/tq.h
+2
-1
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+13
-10
source/dnode/vnode/src/tq/tqOffset.c
source/dnode/vnode/src/tq/tqOffset.c
+4
-0
source/dnode/vnode/src/tq/tqRead.c
source/dnode/vnode/src/tq/tqRead.c
+7
-7
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+5
-5
source/libs/command/src/command.c
source/libs/command/src/command.c
+1
-1
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+1
-0
source/libs/executor/src/executil.c
source/libs/executor/src/executil.c
+20
-6
source/libs/executor/src/executorMain.c
source/libs/executor/src/executorMain.c
+5
-3
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+60
-22
source/libs/executor/src/groupoperator.c
source/libs/executor/src/groupoperator.c
+15
-0
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+2
-0
source/libs/executor/src/tsort.c
source/libs/executor/src/tsort.c
+8
-2
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+2
-2
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+46
-27
source/libs/nodes/src/nodesCloneFuncs.c
source/libs/nodes/src/nodesCloneFuncs.c
+10
-1
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+37
-2
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+5
-0
source/libs/parser/inc/parUtil.h
source/libs/parser/inc/parUtil.h
+0
-1
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+2
-1
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+8
-1
source/libs/qcom/src/queryUtil.c
source/libs/qcom/src/queryUtil.c
+12
-5
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+6
-0
source/libs/scalar/src/scalar.c
source/libs/scalar/src/scalar.c
+7
-1
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+13
-25
source/libs/scalar/src/sclvector.c
source/libs/scalar/src/sclvector.c
+23
-1
source/libs/stream/src/streamData.c
source/libs/stream/src/streamData.c
+9
-0
source/libs/stream/src/streamExec.c
source/libs/stream/src/streamExec.c
+0
-1
source/libs/stream/src/streamQueue.c
source/libs/stream/src/streamQueue.c
+0
-9
source/libs/sync/inc/syncAppendEntries.h
source/libs/sync/inc/syncAppendEntries.h
+1
-0
source/libs/sync/inc/syncAppendEntriesReply.h
source/libs/sync/inc/syncAppendEntriesReply.h
+6
-0
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+2
-0
source/libs/sync/inc/syncReplication.h
source/libs/sync/inc/syncReplication.h
+2
-0
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+7
-7
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+2
-0
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+84
-33
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+131
-1
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+316
-1
source/libs/sync/src/syncRaftCfg.c
source/libs/sync/src/syncRaftCfg.c
+4
-4
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+87
-0
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+5
-5
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+14
-0
source/libs/sync/test/syncAppendEntriesBatchTest.cpp
source/libs/sync/test/syncAppendEntriesBatchTest.cpp
+139
-0
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
+1
-1
source/libs/sync/test/syncSnapshotSenderTest.cpp
source/libs/sync/test/syncSnapshotSenderTest.cpp
+1
-1
source/libs/sync/test/syncTestTool.cpp
source/libs/sync/test/syncTestTool.cpp
+1
-1
source/libs/wal/inc/walInt.h
source/libs/wal/inc/walInt.h
+7
-7
source/libs/wal/src/walMeta.c
source/libs/wal/src/walMeta.c
+5
-22
source/libs/wal/src/walMgmt.c
source/libs/wal/src/walMgmt.c
+2
-2
source/libs/wal/src/walRead.c
source/libs/wal/src/walRead.c
+15
-15
source/libs/wal/src/walWrite.c
source/libs/wal/src/walWrite.c
+12
-34
source/libs/wal/test/walMetaTest.cpp
source/libs/wal/test/walMetaTest.cpp
+1
-1
source/os/src/osFile.c
source/os/src/osFile.c
+8
-7
source/os/src/osString.c
source/os/src/osString.c
+4
-4
source/util/src/terror.c
source/util/src/terror.c
+4
-0
source/util/src/tpagedbuf.c
source/util/src/tpagedbuf.c
+16
-4
source/util/src/tutil.c
source/util/src/tutil.c
+17
-0
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+0
-7
tests/script/tsim/dnode/cluster_alter.sim
tests/script/tsim/dnode/cluster_alter.sim
+0
-174
tests/script/tsim/dnode/cluster_balance1.sim
tests/script/tsim/dnode/cluster_balance1.sim
+0
-590
tests/script/tsim/dnode/cluster_balance2.sim
tests/script/tsim/dnode/cluster_balance2.sim
+0
-479
tests/script/tsim/dnode/cluster_balance3.sim
tests/script/tsim/dnode/cluster_balance3.sim
+0
-643
tests/script/tsim/dnode/cluster_cache.sim
tests/script/tsim/dnode/cluster_cache.sim
+0
-65
tests/script/tsim/dnode/cluster_flowctrl.sim
tests/script/tsim/dnode/cluster_flowctrl.sim
+0
-131
tests/script/tsim/dnode/cluster_vgroup100.sim
tests/script/tsim/dnode/cluster_vgroup100.sim
+0
-146
tests/system-test/2-query/json_tag.py
tests/system-test/2-query/json_tag.py
+111
-73
tests/system-test/7-tmq/subscribeDb2.py
tests/system-test/7-tmq/subscribeDb2.py
+11
-6
tests/system-test/7-tmq/tmqConsFromTsdb.py
tests/system-test/7-tmq/tmqConsFromTsdb.py
+34
-32
tools/shell/src/shellCommand.c
tools/shell/src/shellCommand.c
+1
-0
未找到文件。
Jenkinsfile2
浏览文件 @
0d41f9c8
...
@@ -130,6 +130,9 @@ def pre_test(){
...
@@ -130,6 +130,9 @@ def pre_test(){
def pre_test_win(){
def pre_test_win(){
bat '''
bat '''
hostname
hostname
taskkill /f /t /im python.exe
taskkill /f /t /im bash.exe
taskkill /f /t /im taosd.exe
ipconfig
ipconfig
set
set
date /t
date /t
...
...
include/common/tdatablock.h
浏览文件 @
0d41f9c8
...
@@ -222,6 +222,7 @@ void blockDataCleanup(SSDataBlock* pDataBlock);
...
@@ -222,6 +222,7 @@ void blockDataCleanup(SSDataBlock* pDataBlock);
size_t
blockDataGetCapacityInRow
(
const
SSDataBlock
*
pBlock
,
size_t
pageSize
);
size_t
blockDataGetCapacityInRow
(
const
SSDataBlock
*
pBlock
,
size_t
pageSize
);
int32_t
blockDataTrimFirstNRows
(
SSDataBlock
*
pBlock
,
size_t
n
);
int32_t
blockDataTrimFirstNRows
(
SSDataBlock
*
pBlock
,
size_t
n
);
int32_t
blockDataKeepFirstNRows
(
SSDataBlock
*
pBlock
,
size_t
n
);
int32_t
assignOneDataBlock
(
SSDataBlock
*
dst
,
const
SSDataBlock
*
src
);
int32_t
assignOneDataBlock
(
SSDataBlock
*
dst
,
const
SSDataBlock
*
src
);
int32_t
copyDataBlock
(
SSDataBlock
*
dst
,
const
SSDataBlock
*
src
);
int32_t
copyDataBlock
(
SSDataBlock
*
dst
,
const
SSDataBlock
*
src
);
...
@@ -235,6 +236,7 @@ SColumnInfoData* bdGetColumnInfoData(SSDataBlock* pBlock, int32_t index);
...
@@ -235,6 +236,7 @@ SColumnInfoData* bdGetColumnInfoData(SSDataBlock* pBlock, int32_t index);
void
blockEncode
(
const
SSDataBlock
*
pBlock
,
char
*
data
,
int32_t
*
dataLen
,
int32_t
numOfCols
,
int8_t
needCompress
);
void
blockEncode
(
const
SSDataBlock
*
pBlock
,
char
*
data
,
int32_t
*
dataLen
,
int32_t
numOfCols
,
int8_t
needCompress
);
const
char
*
blockDecode
(
SSDataBlock
*
pBlock
,
int32_t
numOfCols
,
int32_t
numOfRows
,
const
char
*
pData
);
const
char
*
blockDecode
(
SSDataBlock
*
pBlock
,
int32_t
numOfCols
,
int32_t
numOfRows
,
const
char
*
pData
);
void
blockDebugShowDataBlock
(
SSDataBlock
*
pBlock
,
const
char
*
flag
);
void
blockDebugShowDataBlocks
(
const
SArray
*
dataBlocks
,
const
char
*
flag
);
void
blockDebugShowDataBlocks
(
const
SArray
*
dataBlocks
,
const
char
*
flag
);
// for debug
// for debug
char
*
dumpBlockData
(
SSDataBlock
*
pDataBlock
,
const
char
*
flag
,
char
**
dumpBuf
);
char
*
dumpBlockData
(
SSDataBlock
*
pDataBlock
,
const
char
*
flag
,
char
**
dumpBuf
);
...
...
include/common/tdataformat.h
浏览文件 @
0d41f9c8
...
@@ -78,6 +78,7 @@ int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag);
...
@@ -78,6 +78,7 @@ int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag);
int32_t
tDecodeTag
(
SDecoder
*
pDecoder
,
STag
**
ppTag
);
int32_t
tDecodeTag
(
SDecoder
*
pDecoder
,
STag
**
ppTag
);
int32_t
tTagToValArray
(
const
STag
*
pTag
,
SArray
**
ppArray
);
int32_t
tTagToValArray
(
const
STag
*
pTag
,
SArray
**
ppArray
);
void
debugPrintSTag
(
STag
*
pTag
,
const
char
*
tag
,
int32_t
ln
);
// TODO: remove
void
debugPrintSTag
(
STag
*
pTag
,
const
char
*
tag
,
int32_t
ln
);
// TODO: remove
int32_t
parseJsontoTagData
(
const
char
*
json
,
SArray
*
pTagVals
,
STag
**
ppTag
,
void
*
pMsgBuf
);
// STRUCT =================
// STRUCT =================
struct
STColumn
{
struct
STColumn
{
...
...
include/common/tmsgdef.h
浏览文件 @
0d41f9c8
...
@@ -233,10 +233,12 @@ enum {
...
@@ -233,10 +233,12 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_SYNC_PING
,
"sync-ping"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_PING
,
"sync-ping"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_PING_REPLY
,
"sync-ping-reply"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_PING_REPLY
,
"sync-ping-reply"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_CLIENT_REQUEST
,
"sync-client-request"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_CLIENT_REQUEST
,
"sync-client-request"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_CLIENT_REQUEST_BATCH
,
"sync-client-request-batch"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_CLIENT_REQUEST_REPLY
,
"sync-client-request-reply"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_CLIENT_REQUEST_REPLY
,
"sync-client-request-reply"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_REQUEST_VOTE
,
"sync-request-vote"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_REQUEST_VOTE
,
"sync-request-vote"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_REQUEST_VOTE_REPLY
,
"sync-request-vote-reply"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_REQUEST_VOTE_REPLY
,
"sync-request-vote-reply"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_APPEND_ENTRIES
,
"sync-append-entries"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_APPEND_ENTRIES
,
"sync-append-entries"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_APPEND_ENTRIES_BATCH
,
"sync-append-entries-batch"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_APPEND_ENTRIES_REPLY
,
"sync-append-entries-reply"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_APPEND_ENTRIES_REPLY
,
"sync-append-entries-reply"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_NOOP
,
"sync-noop"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_NOOP
,
"sync-noop"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_UNKNOWN
,
"sync-unknown"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_UNKNOWN
,
"sync-unknown"
,
NULL
,
NULL
)
...
...
include/libs/sync/sync.h
浏览文件 @
0d41f9c8
...
@@ -26,6 +26,7 @@ extern "C" {
...
@@ -26,6 +26,7 @@ extern "C" {
extern
bool
gRaftDetailLog
;
extern
bool
gRaftDetailLog
;
#define SYNC_MAX_BATCH_SIZE 100
#define SYNC_INDEX_BEGIN 0
#define SYNC_INDEX_BEGIN 0
#define SYNC_INDEX_INVALID -1
#define SYNC_INDEX_INVALID -1
#define SYNC_TERM_INVALID 0xFFFFFFFFFFFFFFFF
#define SYNC_TERM_INVALID 0xFFFFFFFFFFFFFFFF
...
@@ -120,7 +121,7 @@ typedef struct SSyncFSM {
...
@@ -120,7 +121,7 @@ typedef struct SSyncFSM {
int32_t
(
*
FpGetSnapshot
)(
struct
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
,
void
*
pReaderParam
,
void
**
ppReader
);
int32_t
(
*
FpGetSnapshot
)(
struct
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
,
void
*
pReaderParam
,
void
**
ppReader
);
int32_t
(
*
FpGetSnapshotInfo
)(
struct
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
);
int32_t
(
*
FpGetSnapshotInfo
)(
struct
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
);
int32_t
(
*
FpSnapshotStartRead
)(
struct
SSyncFSM
*
pFsm
,
void
**
ppReader
);
int32_t
(
*
FpSnapshotStartRead
)(
struct
SSyncFSM
*
pFsm
,
void
*
pReaderParam
,
void
*
*
ppReader
);
int32_t
(
*
FpSnapshotStopRead
)(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
);
int32_t
(
*
FpSnapshotStopRead
)(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
);
int32_t
(
*
FpSnapshotDoRead
)(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
,
void
**
ppBuf
,
int32_t
*
len
);
int32_t
(
*
FpSnapshotDoRead
)(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
,
void
**
ppBuf
,
int32_t
*
len
);
...
@@ -164,6 +165,7 @@ typedef struct SSyncLogStore {
...
@@ -164,6 +165,7 @@ typedef struct SSyncLogStore {
bool
(
*
syncLogIsEmpty
)(
struct
SSyncLogStore
*
pLogStore
);
bool
(
*
syncLogIsEmpty
)(
struct
SSyncLogStore
*
pLogStore
);
int32_t
(
*
syncLogEntryCount
)(
struct
SSyncLogStore
*
pLogStore
);
int32_t
(
*
syncLogEntryCount
)(
struct
SSyncLogStore
*
pLogStore
);
int32_t
(
*
syncLogRestoreFromSnapshot
)(
struct
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
int32_t
(
*
syncLogRestoreFromSnapshot
)(
struct
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
bool
(
*
syncLogExist
)(
struct
SSyncLogStore
*
pLogStore
,
SyncIndex
index
);
SyncIndex
(
*
syncLogWriteIndex
)(
struct
SSyncLogStore
*
pLogStore
);
SyncIndex
(
*
syncLogWriteIndex
)(
struct
SSyncLogStore
*
pLogStore
);
SyncIndex
(
*
syncLogLastIndex
)(
struct
SSyncLogStore
*
pLogStore
);
SyncIndex
(
*
syncLogLastIndex
)(
struct
SSyncLogStore
*
pLogStore
);
...
@@ -179,6 +181,7 @@ typedef struct SSyncInfo {
...
@@ -179,6 +181,7 @@ typedef struct SSyncInfo {
bool
isStandBy
;
bool
isStandBy
;
bool
snapshotEnable
;
bool
snapshotEnable
;
SyncGroupId
vgId
;
SyncGroupId
vgId
;
int32_t
batchSize
;
SSyncCfg
syncCfg
;
SSyncCfg
syncCfg
;
char
path
[
TSDB_FILENAME_LEN
];
char
path
[
TSDB_FILENAME_LEN
];
SWal
*
pWal
;
SWal
*
pWal
;
...
@@ -202,6 +205,7 @@ SyncGroupId syncGetVgId(int64_t rid);
...
@@ -202,6 +205,7 @@ SyncGroupId syncGetVgId(int64_t rid);
void
syncGetEpSet
(
int64_t
rid
,
SEpSet
*
pEpSet
);
void
syncGetEpSet
(
int64_t
rid
,
SEpSet
*
pEpSet
);
void
syncGetRetryEpSet
(
int64_t
rid
,
SEpSet
*
pEpSet
);
void
syncGetRetryEpSet
(
int64_t
rid
,
SEpSet
*
pEpSet
);
int32_t
syncPropose
(
int64_t
rid
,
SRpcMsg
*
pMsg
,
bool
isWeak
);
int32_t
syncPropose
(
int64_t
rid
,
SRpcMsg
*
pMsg
,
bool
isWeak
);
// int32_t syncProposeBatch(int64_t rid, SRpcMsg* pMsgArr, bool* pIsWeakArr, int32_t arrSize);
bool
syncEnvIsStart
();
bool
syncEnvIsStart
();
const
char
*
syncStr
(
ESyncState
state
);
const
char
*
syncStr
(
ESyncState
state
);
bool
syncIsRestoreFinish
(
int64_t
rid
);
bool
syncIsRestoreFinish
(
int64_t
rid
);
...
...
include/libs/sync/syncTools.h
浏览文件 @
0d41f9c8
...
@@ -219,6 +219,34 @@ void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg);
...
@@ -219,6 +219,34 @@ void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg);
void
syncClientRequestLog
(
const
SyncClientRequest
*
pMsg
);
void
syncClientRequestLog
(
const
SyncClientRequest
*
pMsg
);
void
syncClientRequestLog2
(
char
*
s
,
const
SyncClientRequest
*
pMsg
);
void
syncClientRequestLog2
(
char
*
s
,
const
SyncClientRequest
*
pMsg
);
// ---------------------------------------------
typedef
struct
SOffsetAndContLen
{
int32_t
offset
;
int32_t
contLen
;
}
SOffsetAndContLen
;
typedef
struct
SRaftMeta
{
uint64_t
seqNum
;
bool
isWeak
;
}
SRaftMeta
;
// block1:
// block2: SRaftMeta array
// block3: rpc msg array (with pCont)
typedef
struct
SyncClientRequestBatch
{
uint32_t
bytes
;
int32_t
vgId
;
uint32_t
msgType
;
// SyncClientRequestBatch msgType
uint32_t
dataCount
;
uint32_t
dataLen
;
// user RpcMsg.contLen
char
data
[];
// user RpcMsg.pCont
}
SyncClientRequestBatch
;
SyncClientRequestBatch
*
syncClientRequestBatchBuild
(
SRpcMsg
*
rpcMsgArr
,
SRaftMeta
*
raftArr
,
int32_t
arrSize
,
int32_t
vgId
);
void
syncClientRequestBatch2RpcMsg
(
const
SyncClientRequestBatch
*
pSyncMsg
,
SRpcMsg
*
pRpcMsg
);
// ---------------------------------------------
// ---------------------------------------------
typedef
struct
SyncClientRequestReply
{
typedef
struct
SyncClientRequestReply
{
uint32_t
bytes
;
uint32_t
bytes
;
...
@@ -325,22 +353,53 @@ void syncAppendEntriesLog(const SyncAppendEntries* pMsg);
...
@@ -325,22 +353,53 @@ void syncAppendEntriesLog(const SyncAppendEntries* pMsg);
void
syncAppendEntriesLog2
(
char
*
s
,
const
SyncAppendEntries
*
pMsg
);
void
syncAppendEntriesLog2
(
char
*
s
,
const
SyncAppendEntries
*
pMsg
);
// ---------------------------------------------
// ---------------------------------------------
// define ahead
/*
typedef struct SOffsetAndContLen {
int32_t offset;
int32_t contLen;
} SOffsetAndContLen;
*/
typedef
struct
SyncAppendEntriesBatch
{
typedef
struct
SyncAppendEntriesBatch
{
uint32_t
bytes
;
uint32_t
bytes
;
int32_t
vgId
;
int32_t
vgId
;
uint32_t
msgType
;
uint32_t
msgType
;
SRaftId
srcId
;
SRaftId
srcId
;
SRaftId
destId
;
SRaftId
destId
;
// private data
// private data
SyncTerm
term
;
SyncTerm
term
;
SyncIndex
prevLogIndex
;
SyncIndex
prevLogIndex
;
SyncTerm
prevLogTerm
;
SyncTerm
prevLogTerm
;
SyncIndex
commitIndex
;
SyncIndex
commitIndex
;
SyncTerm
privateTerm
;
SyncTerm
privateTerm
;
int32_t
dataCount
;
uint32_t
dataLen
;
uint32_t
dataLen
;
char
data
[];
char
data
[];
}
SyncAppendEntriesBatch
;
}
SyncAppendEntriesBatch
;
SyncAppendEntriesBatch
*
syncAppendEntriesBatchBuild
(
SRpcMsg
*
rpcMsgArr
,
int32_t
arrSize
,
int32_t
vgId
);
void
syncAppendEntriesBatchDestroy
(
SyncAppendEntriesBatch
*
pMsg
);
void
syncAppendEntriesBatchSerialize
(
const
SyncAppendEntriesBatch
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncAppendEntriesBatchDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncAppendEntriesBatch
*
pMsg
);
char
*
syncAppendEntriesBatchSerialize2
(
const
SyncAppendEntriesBatch
*
pMsg
,
uint32_t
*
len
);
SyncAppendEntriesBatch
*
syncAppendEntriesBatchDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncAppendEntriesBatch2RpcMsg
(
const
SyncAppendEntriesBatch
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncAppendEntriesBatchFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncAppendEntriesBatch
*
pMsg
);
SyncAppendEntriesBatch
*
syncAppendEntriesBatchFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncAppendEntriesBatch2Json
(
const
SyncAppendEntriesBatch
*
pMsg
);
char
*
syncAppendEntriesBatch2Str
(
const
SyncAppendEntriesBatch
*
pMsg
);
void
syncAppendEntriesBatch2RpcMsgArray
(
SyncAppendEntriesBatch
*
pSyncMsg
,
SRpcMsg
*
rpcMsgArr
,
int32_t
maxArrSize
,
int32_t
*
pRetArrSize
);
// for debug ----------------------
void
syncAppendEntriesBatchPrint
(
const
SyncAppendEntriesBatch
*
pMsg
);
void
syncAppendEntriesBatchPrint2
(
char
*
s
,
const
SyncAppendEntriesBatch
*
pMsg
);
void
syncAppendEntriesBatchLog
(
const
SyncAppendEntriesBatch
*
pMsg
);
void
syncAppendEntriesBatchLog2
(
char
*
s
,
const
SyncAppendEntriesBatch
*
pMsg
);
// ---------------------------------------------
// ---------------------------------------------
typedef
struct
SyncAppendEntriesReply
{
typedef
struct
SyncAppendEntriesReply
{
uint32_t
bytes
;
uint32_t
bytes
;
...
@@ -542,6 +601,7 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg);
...
@@ -542,6 +601,7 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg);
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
int32_t
syncNodeOnTimeoutCb
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
);
int32_t
syncNodeOnTimeoutCb
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
);
int32_t
syncNodeOnClientRequestCb
(
SSyncNode
*
ths
,
SyncClientRequest
*
pMsg
,
SyncIndex
*
pRetIndex
);
int32_t
syncNodeOnClientRequestCb
(
SSyncNode
*
ths
,
SyncClientRequest
*
pMsg
,
SyncIndex
*
pRetIndex
);
int32_t
syncNodeOnClientRequestBatchCb
(
SSyncNode
*
ths
,
SyncClientRequestBatch
*
pMsg
);
int32_t
syncNodeOnRequestVoteCb
(
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
);
int32_t
syncNodeOnRequestVoteCb
(
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
);
int32_t
syncNodeOnRequestVoteReplyCb
(
SSyncNode
*
ths
,
SyncRequestVoteReply
*
pMsg
);
int32_t
syncNodeOnRequestVoteReplyCb
(
SSyncNode
*
ths
,
SyncRequestVoteReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeOnAppendEntriesCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
...
...
include/libs/wal/wal.h
浏览文件 @
0d41f9c8
...
@@ -61,45 +61,23 @@ extern "C" {
...
@@ -61,45 +61,23 @@ extern "C" {
} \
} \
}
}
#define WAL_
HEAD_VER
0
#define WAL_
PROTO_VER
0
#define WAL_NOSUFFIX_LEN 20
#define WAL_NOSUFFIX_LEN 20
#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1)
#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1)
#define WAL_LOG_SUFFIX "log"
#define WAL_LOG_SUFFIX "log"
#define WAL_INDEX_SUFFIX "idx"
#define WAL_INDEX_SUFFIX "idx"
#define WAL_REFRESH_MS 1000
#define WAL_REFRESH_MS 1000
#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead))
#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWal
Ck
Head))
#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12)
#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12)
#define WAL_FILE_LEN (WAL_PATH_LEN + 32)
#define WAL_FILE_LEN (WAL_PATH_LEN + 32)
#define WAL_MAGIC 0xFAFBFCFDULL
#define WAL_MAGIC 0xFAFBFCFDULL
#pragma pack(push, 1)
typedef
enum
{
typedef
enum
{
TAOS_WAL_NOLOG
=
0
,
TAOS_WAL_NOLOG
=
0
,
TAOS_WAL_WRITE
=
1
,
TAOS_WAL_WRITE
=
1
,
TAOS_WAL_FSYNC
=
2
,
TAOS_WAL_FSYNC
=
2
,
}
EWalType
;
}
EWalType
;
// used by sync module
typedef
struct
{
int8_t
isWeek
;
uint64_t
seqNum
;
uint64_t
term
;
}
SSyncLogMeta
;
typedef
struct
SWalReadHead
{
int8_t
headVer
;
int8_t
reserved
;
int16_t
msgType
;
int32_t
bodyLen
;
int64_t
ingestTs
;
// not implemented
int64_t
version
;
// sync meta
SSyncLogMeta
syncMeta
;
char
body
[];
}
SWalReadHead
;
typedef
struct
{
typedef
struct
{
int32_t
vgId
;
int32_t
vgId
;
int32_t
fsyncPeriod
;
// millisecond
int32_t
fsyncPeriod
;
// millisecond
...
@@ -110,13 +88,6 @@ typedef struct {
...
@@ -110,13 +88,6 @@ typedef struct {
EWalType
level
;
// wal level
EWalType
level
;
// wal level
}
SWalCfg
;
}
SWalCfg
;
typedef
struct
{
uint64_t
magic
;
uint32_t
cksumHead
;
uint32_t
cksumBody
;
SWalReadHead
head
;
}
SWalHead
;
typedef
struct
SWalVer
{
typedef
struct
SWalVer
{
int64_t
firstVer
;
int64_t
firstVer
;
int64_t
verInSnapshotting
;
int64_t
verInSnapshotting
;
...
@@ -125,6 +96,35 @@ typedef struct SWalVer {
...
@@ -125,6 +96,35 @@ typedef struct SWalVer {
int64_t
lastVer
;
int64_t
lastVer
;
}
SWalVer
;
}
SWalVer
;
#pragma pack(push, 1)
// used by sync module
typedef
struct
{
int8_t
isWeek
;
uint64_t
seqNum
;
uint64_t
term
;
}
SSyncLogMeta
;
typedef
struct
{
int8_t
protoVer
;
int64_t
version
;
int16_t
msgType
;
int32_t
bodyLen
;
int64_t
ingestTs
;
// not implemented
// sync meta
SSyncLogMeta
syncMeta
;
char
body
[];
}
SWalCont
;
typedef
struct
{
uint64_t
magic
;
uint32_t
cksumHead
;
uint32_t
cksumBody
;
SWalCont
head
;
}
SWalCkHead
;
#pragma pack(pop)
typedef
struct
SWal
{
typedef
struct
SWal
{
// cfg
// cfg
SWalCfg
cfg
;
SWalCfg
cfg
;
...
@@ -134,7 +134,7 @@ typedef struct SWal {
...
@@ -134,7 +134,7 @@ typedef struct SWal {
TdFilePtr
pWriteLogTFile
;
TdFilePtr
pWriteLogTFile
;
TdFilePtr
pWriteIdxTFile
;
TdFilePtr
pWriteIdxTFile
;
int32_t
writeCur
;
int32_t
writeCur
;
SArray
*
fileInfoSet
;
SArray
*
fileInfoSet
;
// SArray<SWalFileInfo>
// status
// status
int64_t
totSize
;
int64_t
totSize
;
int64_t
lastRollSeq
;
int64_t
lastRollSeq
;
...
@@ -146,7 +146,7 @@ typedef struct SWal {
...
@@ -146,7 +146,7 @@ typedef struct SWal {
// path
// path
char
path
[
WAL_PATH_LEN
];
char
path
[
WAL_PATH_LEN
];
// reusable write head
// reusable write head
SWalHead
writeHead
;
SWal
Ck
Head
writeHead
;
}
SWal
;
// WAL HANDLE
}
SWal
;
// WAL HANDLE
typedef
struct
SWalReadHandle
{
typedef
struct
SWalReadHandle
{
...
@@ -158,11 +158,8 @@ typedef struct SWalReadHandle {
...
@@ -158,11 +158,8 @@ typedef struct SWalReadHandle {
int64_t
capacity
;
int64_t
capacity
;
int64_t
status
;
// if cursor valid
int64_t
status
;
// if cursor valid
TdThreadMutex
mutex
;
TdThreadMutex
mutex
;
SWal
Head
*
pHead
;
SWal
CkHead
*
pHead
;
}
SWalReadHandle
;
}
SWalReadHandle
;
#pragma pack(pop)
// typedef int32_t (*FWalWrite)(void *ahandle, void *pHead);
// module initialization
// module initialization
int32_t
walInit
();
int32_t
walInit
();
...
@@ -174,9 +171,9 @@ int32_t walAlter(SWal *, SWalCfg *pCfg);
...
@@ -174,9 +171,9 @@ int32_t walAlter(SWal *, SWalCfg *pCfg);
void
walClose
(
SWal
*
);
void
walClose
(
SWal
*
);
// write
// write
int
64
_t
walWriteWithSyncInfo
(
SWal
*
,
int64_t
index
,
tmsg_t
msgType
,
SSyncLogMeta
syncMeta
,
const
void
*
body
,
int
32
_t
walWriteWithSyncInfo
(
SWal
*
,
int64_t
index
,
tmsg_t
msgType
,
SSyncLogMeta
syncMeta
,
const
void
*
body
,
int32_t
bodyLen
);
int32_t
bodyLen
);
int
64
_t
walWrite
(
SWal
*
,
int64_t
index
,
tmsg_t
msgType
,
const
void
*
body
,
int32_t
bodyLen
);
int
32
_t
walWrite
(
SWal
*
,
int64_t
index
,
tmsg_t
msgType
,
const
void
*
body
,
int32_t
bodyLen
);
void
walFsync
(
SWal
*
,
bool
force
);
void
walFsync
(
SWal
*
,
bool
force
);
// apis for lifecycle management
// apis for lifecycle management
...
@@ -196,9 +193,9 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver);
...
@@ -196,9 +193,9 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver);
// only for tq usage
// only for tq usage
void
walSetReaderCapacity
(
SWalReadHandle
*
pRead
,
int32_t
capacity
);
void
walSetReaderCapacity
(
SWalReadHandle
*
pRead
,
int32_t
capacity
);
int32_t
walFetchHead
(
SWalReadHandle
*
pRead
,
int64_t
ver
,
SWalHead
*
pHead
);
int32_t
walFetchHead
(
SWalReadHandle
*
pRead
,
int64_t
ver
,
SWal
Ck
Head
*
pHead
);
int32_t
walFetchBody
(
SWalReadHandle
*
pRead
,
SWalHead
**
ppHead
);
int32_t
walFetchBody
(
SWalReadHandle
*
pRead
,
SWal
Ck
Head
**
ppHead
);
int32_t
walSkipFetchBody
(
SWalReadHandle
*
pRead
,
const
SWalHead
*
pHead
);
int32_t
walSkipFetchBody
(
SWalReadHandle
*
pRead
,
const
SWal
Ck
Head
*
pHead
);
typedef
struct
{
typedef
struct
{
int64_t
refId
;
int64_t
refId
;
...
...
include/os/osFile.h
浏览文件 @
0d41f9c8
...
@@ -25,17 +25,17 @@ extern "C" {
...
@@ -25,17 +25,17 @@ extern "C" {
// If the error is in a third-party library, place this header file under the third-party library header file.
// If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following sectio
// When you want to use this feature, you should find or add the same function in the following sectio
#ifndef ALLOW_FORBID_FUNC
#ifndef ALLOW_FORBID_FUNC
#define open
OPEN_FUNC_TAOS_FORBID
#define open
OPEN_FUNC_TAOS_FORBID
#define fopen
FOPEN_FUNC_TAOS_FORBID
#define fopen
FOPEN_FUNC_TAOS_FORBID
#define access
ACCESS_FUNC_TAOS_FORBID
#define access
ACCESS_FUNC_TAOS_FORBID
#define stat
STAT_FUNC_TAOS_FORBID
#define stat
STAT_FUNC_TAOS_FORBID
#define lstat
LSTAT_FUNC_TAOS_FORBID
#define lstat
LSTAT_FUNC_TAOS_FORBID
#define fstat
FSTAT_FUNC_TAOS_FORBID
#define fstat
FSTAT_FUNC_TAOS_FORBID
#define close
CLOSE_FUNC_TAOS_FORBID
#define close
CLOSE_FUNC_TAOS_FORBID
#define fclose
FCLOSE_FUNC_TAOS_FORBID
#define fclose
FCLOSE_FUNC_TAOS_FORBID
#define fsync
FSYNC_FUNC_TAOS_FORBID
#define fsync
FSYNC_FUNC_TAOS_FORBID
#define getline GETLINE_FUNC_TAOS_FORBID
#define getline GETLINE_FUNC_TAOS_FORBID
// #define fflush FFLUSH_FUNC_TAOS_FORBID
// #define fflush FFLUSH_FUNC_TAOS_FORBID
#endif
#endif
#ifndef PATH_MAX
#ifndef PATH_MAX
...
@@ -43,54 +43,54 @@ extern "C" {
...
@@ -43,54 +43,54 @@ extern "C" {
#endif
#endif
typedef
struct
TdFile
*
TdFilePtr
;
typedef
struct
TdFile
*
TdFilePtr
;
#define TD_FILE_CREATE
0x0001
#define TD_FILE_CREATE 0x0001
#define TD_FILE_WRITE
0x0002
#define TD_FILE_WRITE 0x0002
#define TD_FILE_READ
0x0004
#define TD_FILE_READ 0x0004
#define TD_FILE_TRUNC
0x0008
#define TD_FILE_TRUNC 0x0008
#define TD_FILE_APPEND
0x0010
#define TD_FILE_APPEND 0x0010
#define TD_FILE_TEXT
0x0020
#define TD_FILE_TEXT 0x0020
#define TD_FILE_AUTO_DEL
0x0040
#define TD_FILE_AUTO_DEL 0x0040
#define TD_FILE_EXCL
0x0080
#define TD_FILE_EXCL 0x0080
#define TD_FILE_STREAM
0x0100
// Only support taosFprintfFile, taosGetLineFile, taosEOFFile
#define TD_FILE_STREAM
0x0100
// Only support taosFprintfFile, taosGetLineFile, taosEOFFile
TdFilePtr
taosOpenFile
(
const
char
*
path
,
int32_t
tdFileOptions
);
TdFilePtr
taosOpenFile
(
const
char
*
path
,
int32_t
tdFileOptions
);
#define TD_FILE_ACCESS_EXIST_OK 0x1
#define TD_FILE_ACCESS_EXIST_OK 0x1
#define TD_FILE_ACCESS_READ_OK 0x2
#define TD_FILE_ACCESS_READ_OK 0x2
#define TD_FILE_ACCESS_WRITE_OK 0x4
#define TD_FILE_ACCESS_WRITE_OK 0x4
bool
taosCheckAccessFile
(
const
char
*
pathname
,
int
mode
);
bool
taosCheckAccessFile
(
const
char
*
pathname
,
int
mode
);
int32_t
taosLockFile
(
TdFilePtr
pFile
);
int32_t
taosLockFile
(
TdFilePtr
pFile
);
int32_t
taosUnLockFile
(
TdFilePtr
pFile
);
int32_t
taosUnLockFile
(
TdFilePtr
pFile
);
int32_t
taosUmaskFile
(
int32_t
maskVal
);
int32_t
taosUmaskFile
(
int32_t
maskVal
);
int32_t
taosStatFile
(
const
char
*
path
,
int64_t
*
size
,
int32_t
*
mtime
);
int32_t
taosStatFile
(
const
char
*
path
,
int64_t
*
size
,
int32_t
*
mtime
);
int32_t
taosDevInoFile
(
TdFilePtr
pFile
,
int64_t
*
stDev
,
int64_t
*
stIno
);
int32_t
taosDevInoFile
(
TdFilePtr
pFile
,
int64_t
*
stDev
,
int64_t
*
stIno
);
int32_t
taosFStatFile
(
TdFilePtr
pFile
,
int64_t
*
size
,
int32_t
*
mtime
);
int32_t
taosFStatFile
(
TdFilePtr
pFile
,
int64_t
*
size
,
int32_t
*
mtime
);
bool
taosCheckExistFile
(
const
char
*
pathname
);
bool
taosCheckExistFile
(
const
char
*
pathname
);
int64_t
taosLSeekFile
(
TdFilePtr
pFile
,
int64_t
offset
,
int32_t
whence
);
int64_t
taosLSeekFile
(
TdFilePtr
pFile
,
int64_t
offset
,
int32_t
whence
);
int32_t
taosFtruncateFile
(
TdFilePtr
pFile
,
int64_t
length
);
int32_t
taosFtruncateFile
(
TdFilePtr
pFile
,
int64_t
length
);
int32_t
taosFsyncFile
(
TdFilePtr
pFile
);
int32_t
taosFsyncFile
(
TdFilePtr
pFile
);
int64_t
taosReadFile
(
TdFilePtr
pFile
,
void
*
buf
,
int64_t
count
);
int64_t
taosReadFile
(
TdFilePtr
pFile
,
void
*
buf
,
int64_t
count
);
int64_t
taosPReadFile
(
TdFilePtr
pFile
,
void
*
buf
,
int64_t
count
,
int64_t
offset
);
int64_t
taosPReadFile
(
TdFilePtr
pFile
,
void
*
buf
,
int64_t
count
,
int64_t
offset
);
int64_t
taosWriteFile
(
TdFilePtr
pFile
,
const
void
*
buf
,
int64_t
count
);
int64_t
taosWriteFile
(
TdFilePtr
pFile
,
const
void
*
buf
,
int64_t
count
);
void
taosFprintfFile
(
TdFilePtr
pFile
,
const
char
*
format
,
...);
void
taosFprintfFile
(
TdFilePtr
pFile
,
const
char
*
format
,
...);
int64_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict
ptrBuf
);
int64_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict
ptrBuf
);
int64_t
taosGetsFile
(
TdFilePtr
pFile
,
int32_t
maxSize
,
char
*
__restrict
buf
);
int64_t
taosGetsFile
(
TdFilePtr
pFile
,
int32_t
maxSize
,
char
*
__restrict
buf
);
int32_t
taosEOFFile
(
TdFilePtr
pFile
);
int32_t
taosEOFFile
(
TdFilePtr
pFile
);
int
64
_t
taosCloseFile
(
TdFilePtr
*
ppFile
);
int
32
_t
taosCloseFile
(
TdFilePtr
*
ppFile
);
int32_t
taosRenameFile
(
const
char
*
oldName
,
const
char
*
newName
);
int32_t
taosRenameFile
(
const
char
*
oldName
,
const
char
*
newName
);
int64_t
taosCopyFile
(
const
char
*
from
,
const
char
*
to
);
int64_t
taosCopyFile
(
const
char
*
from
,
const
char
*
to
);
int32_t
taosRemoveFile
(
const
char
*
path
);
int32_t
taosRemoveFile
(
const
char
*
path
);
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
);
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
);
int64_t
taosFSendFile
(
TdFilePtr
pFileOut
,
TdFilePtr
pFileIn
,
int64_t
*
offset
,
int64_t
size
);
int64_t
taosFSendFile
(
TdFilePtr
pFileOut
,
TdFilePtr
pFileIn
,
int64_t
*
offset
,
int64_t
size
);
...
...
include/util/taoserror.h
浏览文件 @
0d41f9c8
...
@@ -388,6 +388,10 @@ int32_t* taosGetErrno();
...
@@ -388,6 +388,10 @@ int32_t* taosGetErrno();
#define TSDB_CODE_QRY_TASK_MSG_ERROR TAOS_DEF_ERROR_CODE(0, 0x0719)
#define TSDB_CODE_QRY_TASK_MSG_ERROR TAOS_DEF_ERROR_CODE(0, 0x0719)
#define TSDB_CODE_QRY_JOB_FREED TAOS_DEF_ERROR_CODE(0, 0x071A)
#define TSDB_CODE_QRY_JOB_FREED TAOS_DEF_ERROR_CODE(0, 0x071A)
#define TSDB_CODE_QRY_TASK_STATUS_ERROR TAOS_DEF_ERROR_CODE(0, 0x071B)
#define TSDB_CODE_QRY_TASK_STATUS_ERROR TAOS_DEF_ERROR_CODE(0, 0x071B)
//json
#define TSDB_CODE_QRY_JSON_IN_ERROR TAOS_DEF_ERROR_CODE(0, 0x071C)
#define TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR TAOS_DEF_ERROR_CODE(0, 0x071D)
#define TSDB_CODE_QRY_JSON_IN_GROUP_ERROR TAOS_DEF_ERROR_CODE(0, 0x071E)
// grant
// grant
#define TSDB_CODE_GRANT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0800)
#define TSDB_CODE_GRANT_EXPIRED TAOS_DEF_ERROR_CODE(0, 0x0800)
...
@@ -423,6 +427,7 @@ int32_t* taosGetErrno();
...
@@ -423,6 +427,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_SYN_RECONFIG_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0910)
#define TSDB_CODE_SYN_RECONFIG_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0910)
#define TSDB_CODE_SYN_PROPOSE_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0911)
#define TSDB_CODE_SYN_PROPOSE_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0911)
#define TSDB_CODE_SYN_STANDBY_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0912)
#define TSDB_CODE_SYN_STANDBY_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0912)
#define TSDB_CODE_SYN_BATCH_ERROR TAOS_DEF_ERROR_CODE(0, 0x0913)
#define TSDB_CODE_SYN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x09FF)
#define TSDB_CODE_SYN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x09FF)
// tq
// tq
...
...
include/util/tutil.h
浏览文件 @
0d41f9c8
...
@@ -44,6 +44,8 @@ uint32_t ip2uint(const char *const ip_addr);
...
@@ -44,6 +44,8 @@ uint32_t ip2uint(const char *const ip_addr);
void
taosIp2String
(
uint32_t
ip
,
char
*
str
);
void
taosIp2String
(
uint32_t
ip
,
char
*
str
);
void
taosIpPort2String
(
uint32_t
ip
,
uint16_t
port
,
char
*
str
);
void
taosIpPort2String
(
uint32_t
ip
,
uint16_t
port
,
char
*
str
);
void
*
tmemmem
(
const
char
*
haystack
,
int
hlen
,
const
char
*
needle
,
int
nlen
);
static
FORCE_INLINE
void
taosEncryptPass
(
uint8_t
*
inBuf
,
size_t
inLen
,
char
*
target
)
{
static
FORCE_INLINE
void
taosEncryptPass
(
uint8_t
*
inBuf
,
size_t
inLen
,
char
*
target
)
{
T_MD5_CTX
context
;
T_MD5_CTX
context
;
tMD5Init
(
&
context
);
tMD5Init
(
&
context
);
...
@@ -59,10 +61,10 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar
...
@@ -59,10 +61,10 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar
tMD5Final
(
&
context
);
tMD5Final
(
&
context
);
char
buf
[
TSDB_PASSWORD_LEN
+
1
];
char
buf
[
TSDB_PASSWORD_LEN
+
1
];
sprintf
(
buf
,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
,
context
.
digest
[
0
],
sprintf
(
buf
,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
,
context
.
digest
[
0
],
context
.
digest
[
1
],
context
.
digest
[
1
],
context
.
digest
[
2
],
context
.
digest
[
3
],
context
.
digest
[
4
],
context
.
digest
[
5
],
context
.
digest
[
2
],
context
.
digest
[
3
],
context
.
digest
[
4
],
context
.
digest
[
5
],
context
.
digest
[
6
],
context
.
digest
[
6
],
context
.
digest
[
7
],
context
.
digest
[
8
],
context
.
digest
[
9
],
context
.
digest
[
10
],
context
.
digest
[
7
],
context
.
digest
[
8
],
context
.
digest
[
9
],
context
.
digest
[
10
],
context
.
digest
[
11
],
context
.
digest
[
1
1
],
context
.
digest
[
1
2
],
context
.
digest
[
13
],
context
.
digest
[
14
],
context
.
digest
[
15
]);
context
.
digest
[
12
],
context
.
digest
[
13
],
context
.
digest
[
14
],
context
.
digest
[
15
]);
memcpy
(
target
,
buf
,
TSDB_PASSWORD_LEN
);
memcpy
(
target
,
buf
,
TSDB_PASSWORD_LEN
);
}
}
...
...
source/common/src/tdatablock.c
浏览文件 @
0d41f9c8
...
@@ -716,7 +716,12 @@ int32_t dataBlockCompar(const void* p1, const void* p2, const void* param) {
...
@@ -716,7 +716,12 @@ int32_t dataBlockCompar(const void* p1, const void* p2, const void* param) {
void
*
left1
=
colDataGetData
(
pColInfoData
,
left
);
void
*
left1
=
colDataGetData
(
pColInfoData
,
left
);
void
*
right1
=
colDataGetData
(
pColInfoData
,
right
);
void
*
right1
=
colDataGetData
(
pColInfoData
,
right
);
if
(
pColInfoData
->
info
.
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
tTagIsJson
(
left1
)
||
tTagIsJson
(
right1
))
{
terrno
=
TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR
;
return
0
;
}
}
__compar_fn_t
fn
=
getKeyComparFunc
(
pColInfoData
->
info
.
type
,
pOrder
->
order
);
__compar_fn_t
fn
=
getKeyComparFunc
(
pColInfoData
->
info
.
type
,
pOrder
->
order
);
int
ret
=
fn
(
left1
,
right1
);
int
ret
=
fn
(
left1
,
right1
);
...
@@ -890,7 +895,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) {
...
@@ -890,7 +895,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) {
SBlockOrderInfo
*
pOrder
=
taosArrayGet
(
pOrderInfo
,
0
);
SBlockOrderInfo
*
pOrder
=
taosArrayGet
(
pOrderInfo
,
0
);
int64_t
p0
=
taosGetTimestampUs
();
int64_t
p0
=
taosGetTimestampUs
();
__compar_fn_t
fn
=
getKeyComparFunc
(
pColInfoData
->
info
.
type
,
pOrder
->
order
);
__compar_fn_t
fn
=
getKeyComparFunc
(
pColInfoData
->
info
.
type
,
pOrder
->
order
);
taosSort
(
pColInfoData
->
pData
,
pDataBlock
->
info
.
rows
,
pColInfoData
->
info
.
bytes
,
fn
);
taosSort
(
pColInfoData
->
pData
,
pDataBlock
->
info
.
rows
,
pColInfoData
->
info
.
bytes
,
fn
);
...
@@ -919,6 +924,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) {
...
@@ -919,6 +924,7 @@ int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo) {
}
}
taosqsort
(
index
,
rows
,
sizeof
(
int32_t
),
&
helper
,
dataBlockCompar
);
taosqsort
(
index
,
rows
,
sizeof
(
int32_t
),
&
helper
,
dataBlockCompar
);
if
(
terrno
)
return
terrno
;
int64_t
p1
=
taosGetTimestampUs
();
int64_t
p1
=
taosGetTimestampUs
();
...
@@ -1431,9 +1437,39 @@ static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) {
...
@@ -1431,9 +1437,39 @@ static void doShiftBitmap(char* nullBitmap, size_t n, size_t total) {
}
}
}
}
static
int32_t
colDataMoveVarData
(
SColumnInfoData
*
pColInfoData
,
size_t
start
,
size_t
end
){
int32_t
dataOffset
=
-
1
;
int32_t
dataLen
=
0
;
int32_t
beigin
=
start
;
while
(
beigin
<
end
){
int32_t
offset
=
pColInfoData
->
varmeta
.
offset
[
beigin
];
if
(
offset
==
-
1
)
{
beigin
++
;
continue
;
}
if
(
start
!=
0
)
{
pColInfoData
->
varmeta
.
offset
[
beigin
]
=
dataLen
;
}
char
*
data
=
pColInfoData
->
pData
+
offset
;
if
(
dataOffset
==
-
1
)
dataOffset
=
offset
;
// mark the begin of data
int32_t
type
=
pColInfoData
->
info
.
type
;
if
(
type
==
TSDB_DATA_TYPE_JSON
)
{
dataLen
+=
getJsonValueLen
(
data
);
}
else
{
dataLen
+=
varDataTLen
(
data
);
}
beigin
++
;
}
if
(
dataOffset
>
0
){
memmove
(
pColInfoData
->
pData
,
pColInfoData
->
pData
+
dataOffset
,
dataLen
);
memmove
(
pColInfoData
->
varmeta
.
offset
,
&
pColInfoData
->
varmeta
.
offset
[
start
],
(
end
-
start
)
*
sizeof
(
int32_t
));
}
return
dataLen
;
}
static
void
colDataTrimFirstNRows
(
SColumnInfoData
*
pColInfoData
,
size_t
n
,
size_t
total
)
{
static
void
colDataTrimFirstNRows
(
SColumnInfoData
*
pColInfoData
,
size_t
n
,
size_t
total
)
{
if
(
IS_VAR_DATA_TYPE
(
pColInfoData
->
info
.
type
))
{
if
(
IS_VAR_DATA_TYPE
(
pColInfoData
->
info
.
type
))
{
memmove
(
pColInfoData
->
varmeta
.
offset
,
&
pColInfoData
->
varmeta
.
offset
[
n
],
(
total
-
n
)
*
sizeof
(
int32_t
)
);
pColInfoData
->
varmeta
.
length
=
colDataMoveVarData
(
pColInfoData
,
n
,
total
);
memset
(
&
pColInfoData
->
varmeta
.
offset
[
total
-
n
],
0
,
n
);
memset
(
&
pColInfoData
->
varmeta
.
offset
[
total
-
n
],
0
,
n
);
}
else
{
}
else
{
int32_t
bytes
=
pColInfoData
->
info
.
bytes
;
int32_t
bytes
=
pColInfoData
->
info
.
bytes
;
...
@@ -1461,6 +1497,33 @@ int32_t blockDataTrimFirstNRows(SSDataBlock* pBlock, size_t n) {
...
@@ -1461,6 +1497,33 @@ int32_t blockDataTrimFirstNRows(SSDataBlock* pBlock, size_t n) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
void
colDataKeepFirstNRows
(
SColumnInfoData
*
pColInfoData
,
size_t
n
,
size_t
total
)
{
if
(
IS_VAR_DATA_TYPE
(
pColInfoData
->
info
.
type
))
{
pColInfoData
->
varmeta
.
length
=
colDataMoveVarData
(
pColInfoData
,
0
,
n
);
memset
(
&
pColInfoData
->
varmeta
.
offset
[
n
],
0
,
total
-
n
);
}
}
int32_t
blockDataKeepFirstNRows
(
SSDataBlock
*
pBlock
,
size_t
n
)
{
if
(
n
==
0
)
{
blockDataCleanup
(
pBlock
);
return
TSDB_CODE_SUCCESS
;
}
if
(
pBlock
->
info
.
rows
<=
n
)
{
return
TSDB_CODE_SUCCESS
;
}
else
{
size_t
numOfCols
=
taosArrayGetSize
(
pBlock
->
pDataBlock
);
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
colDataKeepFirstNRows
(
pColInfoData
,
n
,
pBlock
->
info
.
rows
);
}
pBlock
->
info
.
rows
=
n
;
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
tEncodeDataBlock
(
void
**
buf
,
const
SSDataBlock
*
pBlock
)
{
int32_t
tEncodeDataBlock
(
void
**
buf
,
const
SSDataBlock
*
pBlock
)
{
int64_t
tbUid
=
pBlock
->
info
.
uid
;
int64_t
tbUid
=
pBlock
->
info
.
uid
;
int16_t
numOfCols
=
taosArrayGetSize
(
pBlock
->
pDataBlock
);
int16_t
numOfCols
=
taosArrayGetSize
(
pBlock
->
pDataBlock
);
...
@@ -1605,6 +1668,13 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
...
@@ -1605,6 +1668,13 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
return
buf
;
return
buf
;
}
}
void
blockDebugShowDataBlock
(
SSDataBlock
*
pBlock
,
const
char
*
flag
)
{
SArray
*
dataBlocks
=
taosArrayInit
(
1
,
sizeof
(
SSDataBlock
));
taosArrayPush
(
dataBlocks
,
pBlock
);
blockDebugShowDataBlocks
(
dataBlocks
,
flag
);
taosArrayDestroy
(
dataBlocks
);
}
void
blockDebugShowDataBlocks
(
const
SArray
*
dataBlocks
,
const
char
*
flag
)
{
void
blockDebugShowDataBlocks
(
const
SArray
*
dataBlocks
,
const
char
*
flag
)
{
char
pBuf
[
128
]
=
{
0
};
char
pBuf
[
128
]
=
{
0
};
int32_t
sz
=
taosArrayGetSize
(
dataBlocks
);
int32_t
sz
=
taosArrayGetSize
(
dataBlocks
);
...
...
source/common/src/tvariant.c
浏览文件 @
0d41f9c8
...
@@ -155,7 +155,8 @@ void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uin
...
@@ -155,7 +155,8 @@ void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uin
void
taosVariantDestroy
(
SVariant
*
pVar
)
{
void
taosVariantDestroy
(
SVariant
*
pVar
)
{
if
(
pVar
==
NULL
)
return
;
if
(
pVar
==
NULL
)
return
;
if
(
pVar
->
nType
==
TSDB_DATA_TYPE_BINARY
||
pVar
->
nType
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pVar
->
nType
==
TSDB_DATA_TYPE_BINARY
||
pVar
->
nType
==
TSDB_DATA_TYPE_NCHAR
||
pVar
->
nType
==
TSDB_DATA_TYPE_JSON
)
{
taosMemoryFreeClear
(
pVar
->
pz
);
taosMemoryFreeClear
(
pVar
->
pz
);
pVar
->
nLen
=
0
;
pVar
->
nLen
=
0
;
}
}
...
@@ -184,7 +185,8 @@ void taosVariantAssign(SVariant *pDst, const SVariant *pSrc) {
...
@@ -184,7 +185,8 @@ void taosVariantAssign(SVariant *pDst, const SVariant *pSrc) {
if
(
pSrc
==
NULL
||
pDst
==
NULL
)
return
;
if
(
pSrc
==
NULL
||
pDst
==
NULL
)
return
;
pDst
->
nType
=
pSrc
->
nType
;
pDst
->
nType
=
pSrc
->
nType
;
if
(
pSrc
->
nType
==
TSDB_DATA_TYPE_BINARY
||
pSrc
->
nType
==
TSDB_DATA_TYPE_NCHAR
)
{
if
(
pSrc
->
nType
==
TSDB_DATA_TYPE_BINARY
||
pSrc
->
nType
==
TSDB_DATA_TYPE_NCHAR
||
pSrc
->
nType
==
TSDB_DATA_TYPE_JSON
)
{
int32_t
len
=
pSrc
->
nLen
+
TSDB_NCHAR_SIZE
;
int32_t
len
=
pSrc
->
nLen
+
TSDB_NCHAR_SIZE
;
char
*
p
=
taosMemoryRealloc
(
pDst
->
pz
,
len
);
char
*
p
=
taosMemoryRealloc
(
pDst
->
pz
,
len
);
assert
(
p
);
assert
(
p
);
...
@@ -976,6 +978,7 @@ char *taosVariantGet(SVariant *pVar, int32_t type) {
...
@@ -976,6 +978,7 @@ char *taosVariantGet(SVariant *pVar, int32_t type) {
case
TSDB_DATA_TYPE_FLOAT
:
case
TSDB_DATA_TYPE_FLOAT
:
return
(
char
*
)
&
pVar
->
d
;
return
(
char
*
)
&
pVar
->
d
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_JSON
:
return
(
char
*
)
pVar
->
pz
;
return
(
char
*
)
pVar
->
pz
;
case
TSDB_DATA_TYPE_NCHAR
:
case
TSDB_DATA_TYPE_NCHAR
:
return
(
char
*
)
pVar
->
ucs4
;
return
(
char
*
)
pVar
->
ucs4
;
...
...
source/dnode/mnode/impl/src/mndSync.c
浏览文件 @
0d41f9c8
...
@@ -117,7 +117,7 @@ void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta cbM
...
@@ -117,7 +117,7 @@ void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta cbM
}
}
}
}
int32_t
mndSnapshotStartRead
(
struct
SSyncFSM
*
pFsm
,
void
**
ppReader
)
{
int32_t
mndSnapshotStartRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pParam
,
void
*
*
ppReader
)
{
mDebug
(
"start to read snapshot from sdb"
);
mDebug
(
"start to read snapshot from sdb"
);
SMnode
*
pMnode
=
pFsm
->
data
;
SMnode
*
pMnode
=
pFsm
->
data
;
return
sdbStartRead
(
pMnode
->
pSdb
,
(
SSdbIter
**
)
ppReader
,
NULL
,
NULL
,
NULL
);
return
sdbStartRead
(
pMnode
->
pSdb
,
(
SSdbIter
**
)
ppReader
,
NULL
,
NULL
,
NULL
);
...
...
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
0d41f9c8
...
@@ -426,7 +426,15 @@ static int32_t mndCompareDnodeId(int32_t *dnode1Id, int32_t *dnode2Id) { return
...
@@ -426,7 +426,15 @@ static int32_t mndCompareDnodeId(int32_t *dnode1Id, int32_t *dnode2Id) { return
static
int32_t
mndCompareDnodeVnodes
(
SDnodeObj
*
pDnode1
,
SDnodeObj
*
pDnode2
)
{
static
int32_t
mndCompareDnodeVnodes
(
SDnodeObj
*
pDnode1
,
SDnodeObj
*
pDnode2
)
{
float
d1Score
=
(
float
)
pDnode1
->
numOfVnodes
/
pDnode1
->
numOfSupportVnodes
;
float
d1Score
=
(
float
)
pDnode1
->
numOfVnodes
/
pDnode1
->
numOfSupportVnodes
;
float
d2Score
=
(
float
)
pDnode2
->
numOfVnodes
/
pDnode2
->
numOfSupportVnodes
;
float
d2Score
=
(
float
)
pDnode2
->
numOfVnodes
/
pDnode2
->
numOfSupportVnodes
;
#if 0
if (d1Score == d2Score) {
return pDnode2->id - pDnode1->id;
} else {
return d1Score >= d2Score ? 1 : 0;
}
#else
return
d1Score
>=
d2Score
?
1
:
0
;
return
d1Score
>=
d2Score
?
1
:
0
;
#endif
}
}
void
mndSortVnodeGid
(
SVgObj
*
pVgroup
)
{
void
mndSortVnodeGid
(
SVgObj
*
pVgroup
)
{
...
...
source/dnode/vnode/src/inc/tq.h
浏览文件 @
0d41f9c8
...
@@ -157,7 +157,7 @@ typedef struct {
...
@@ -157,7 +157,7 @@ typedef struct {
static
STqMgmt
tqMgmt
=
{
0
};
static
STqMgmt
tqMgmt
=
{
0
};
// tqRead
// tqRead
int64_t
tqFetchLog
(
STQ
*
pTq
,
STqHandle
*
pHandle
,
int64_t
*
fetchOffset
,
SWalHead
**
pHeadWithCkSum
);
int64_t
tqFetchLog
(
STQ
*
pTq
,
STqHandle
*
pHandle
,
int64_t
*
fetchOffset
,
SWal
Ck
Head
**
pHeadWithCkSum
);
// tqExec
// tqExec
int32_t
tqLogScanExec
(
STQ
*
pTq
,
STqExecHandle
*
pExec
,
SSubmitReq
*
pReq
,
SMqDataRsp
*
pRsp
,
int32_t
workerId
);
int32_t
tqLogScanExec
(
STQ
*
pTq
,
STqExecHandle
*
pExec
,
SSubmitReq
*
pReq
,
SMqDataRsp
*
pRsp
,
int32_t
workerId
);
...
@@ -178,6 +178,7 @@ STqOffsetStore* tqOffsetOpen();
...
@@ -178,6 +178,7 @@ STqOffsetStore* tqOffsetOpen();
void
tqOffsetClose
(
STqOffsetStore
*
);
void
tqOffsetClose
(
STqOffsetStore
*
);
STqOffset
*
tqOffsetRead
(
STqOffsetStore
*
pStore
,
const
char
*
subscribeKey
);
STqOffset
*
tqOffsetRead
(
STqOffsetStore
*
pStore
,
const
char
*
subscribeKey
);
int32_t
tqOffsetWrite
(
STqOffsetStore
*
pStore
,
const
STqOffset
*
pOffset
);
int32_t
tqOffsetWrite
(
STqOffsetStore
*
pStore
,
const
STqOffset
*
pOffset
);
int32_t
tqOffsetDelete
(
STqOffsetStore
*
pStore
,
const
char
*
subscribeKey
);
int32_t
tqOffsetSnapshot
(
STqOffsetStore
*
pStore
);
int32_t
tqOffsetSnapshot
(
STqOffsetStore
*
pStore
);
// tqSink
// tqSink
...
...
source/dnode/vnode/src/tq/tq.c
浏览文件 @
0d41f9c8
...
@@ -271,8 +271,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
...
@@ -271,8 +271,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
STqOffset
*
pOffset
=
tqOffsetRead
(
pTq
->
pOffsetStore
,
pReq
->
subKey
);
STqOffset
*
pOffset
=
tqOffsetRead
(
pTq
->
pOffsetStore
,
pReq
->
subKey
);
if
(
pOffset
!=
NULL
)
{
if
(
pOffset
!=
NULL
)
{
fetchOffsetNew
=
pOffset
->
val
;
fetchOffsetNew
=
pOffset
->
val
;
char
formatBuf
[
5
0
];
char
formatBuf
[
8
0
];
tFormatOffset
(
formatBuf
,
5
0
,
&
fetchOffsetNew
);
tFormatOffset
(
formatBuf
,
8
0
,
&
fetchOffsetNew
);
tqDebug
(
"tmq poll: consumer %ld, offset reset to %s"
,
consumerId
,
formatBuf
);
tqDebug
(
"tmq poll: consumer %ld, offset reset to %s"
,
consumerId
,
formatBuf
);
}
else
{
}
else
{
if
(
reqOffset
.
type
==
TMQ_OFFSET__RESET_EARLIEAST
)
{
if
(
reqOffset
.
type
==
TMQ_OFFSET__RESET_EARLIEAST
)
{
...
@@ -302,9 +302,9 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
...
@@ -302,9 +302,9 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
tqInitDataRsp
(
&
dataRsp
,
pReq
,
pHandle
->
execHandle
.
subType
);
tqInitDataRsp
(
&
dataRsp
,
pReq
,
pHandle
->
execHandle
.
subType
);
if
(
fetchOffsetNew
.
type
==
TMQ_OFFSET__LOG
)
{
if
(
fetchOffsetNew
.
type
==
TMQ_OFFSET__LOG
)
{
int64_t
fetchVer
=
fetchOffsetNew
.
version
+
1
;
int64_t
fetchVer
=
fetchOffsetNew
.
version
+
1
;
SWal
Head
*
pHeadWithCkSum
=
taosMemoryMalloc
(
sizeof
(
SWal
Head
)
+
2048
);
SWal
CkHead
*
pCkHead
=
taosMemoryMalloc
(
sizeof
(
SWalCk
Head
)
+
2048
);
if
(
p
HeadWithCkSum
==
NULL
)
{
if
(
p
CkHead
==
NULL
)
{
return
-
1
;
return
-
1
;
}
}
...
@@ -318,7 +318,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
...
@@ -318,7 +318,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
break
;
break
;
}
}
if
(
tqFetchLog
(
pTq
,
pHandle
,
&
fetchVer
,
&
p
HeadWithCkSum
)
<
0
)
{
if
(
tqFetchLog
(
pTq
,
pHandle
,
&
fetchVer
,
&
p
CkHead
)
<
0
)
{
// TODO add push mgr
// TODO add push mgr
tqOffsetResetToLog
(
&
dataRsp
.
rspOffset
,
fetchVer
);
tqOffsetResetToLog
(
&
dataRsp
.
rspOffset
,
fetchVer
);
...
@@ -329,7 +329,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
...
@@ -329,7 +329,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
goto
OVER
;
goto
OVER
;
}
}
SWal
ReadHead
*
pHead
=
&
pHeadWithCkSum
->
head
;
SWal
Cont
*
pHead
=
&
pCkHead
->
head
;
tqDebug
(
"tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d"
,
consumerId
,
pReq
->
epoch
,
tqDebug
(
"tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d"
,
consumerId
,
pReq
->
epoch
,
TD_VID
(
pTq
->
pVnode
),
fetchVer
,
pHead
->
msgType
);
TD_VID
(
pTq
->
pVnode
),
fetchVer
,
pHead
->
msgType
);
...
@@ -373,9 +373,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
...
@@ -373,9 +373,10 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
}
}
}
}
taosMemoryFree
(
p
HeadWithCkSum
);
taosMemoryFree
(
p
CkHead
);
}
else
if
(
fetchOffsetNew
.
type
==
TMQ_OFFSET__SNAPSHOT_DATA
)
{
}
else
if
(
fetchOffsetNew
.
type
==
TMQ_OFFSET__SNAPSHOT_DATA
)
{
tqInfo
(
"retrieve using snapshot req offset: uid %ld ts %ld"
,
dataRsp
.
reqOffset
.
uid
,
dataRsp
.
reqOffset
.
ts
);
tqInfo
(
"retrieve using snapshot req offset: uid %ld ts %ld, actual offset: uid %ld ts %ld"
,
dataRsp
.
reqOffset
.
uid
,
dataRsp
.
reqOffset
.
ts
,
fetchOffsetNew
.
uid
,
fetchOffsetNew
.
ts
);
if
(
tqScanSnapshot
(
pTq
,
&
pHandle
->
execHandle
,
&
dataRsp
,
fetchOffsetNew
,
workerId
)
<
0
)
{
if
(
tqScanSnapshot
(
pTq
,
&
pHandle
->
execHandle
,
&
dataRsp
,
fetchOffsetNew
,
workerId
)
<
0
)
{
ASSERT
(
0
);
ASSERT
(
0
);
}
}
...
@@ -522,7 +523,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
...
@@ -522,7 +523,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
break;
break;
}
}
SWal
ReadHead
* pHead = &pHeadWithCkSum->head;
SWal
Cont
* pHead = &pHeadWithCkSum->head;
tqDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch,
tqDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch,
TD_VID(pTq->pVnode), fetchOffset, pHead->msgType);
TD_VID(pTq->pVnode), fetchOffset, pHead->msgType);
...
@@ -597,6 +598,8 @@ int32_t tqProcessVgDeleteReq(STQ* pTq, char* msg, int32_t msgLen) {
...
@@ -597,6 +598,8 @@ int32_t tqProcessVgDeleteReq(STQ* pTq, char* msg, int32_t msgLen) {
int32_t
code
=
taosHashRemove
(
pTq
->
handles
,
pReq
->
subKey
,
strlen
(
pReq
->
subKey
));
int32_t
code
=
taosHashRemove
(
pTq
->
handles
,
pReq
->
subKey
,
strlen
(
pReq
->
subKey
));
ASSERT
(
code
==
0
);
ASSERT
(
code
==
0
);
tqOffsetDelete
(
pTq
->
pOffsetStore
,
pReq
->
subKey
);
if
(
tqMetaDeleteHandle
(
pTq
,
pReq
->
subKey
)
<
0
)
{
if
(
tqMetaDeleteHandle
(
pTq
,
pReq
->
subKey
)
<
0
)
{
ASSERT
(
0
);
ASSERT
(
0
);
}
}
...
...
source/dnode/vnode/src/tq/tqOffset.c
浏览文件 @
0d41f9c8
...
@@ -97,6 +97,10 @@ int32_t tqOffsetWrite(STqOffsetStore* pStore, const STqOffset* pOffset) {
...
@@ -97,6 +97,10 @@ int32_t tqOffsetWrite(STqOffsetStore* pStore, const STqOffset* pOffset) {
return
taosHashPut
(
pStore
->
pHash
,
pOffset
->
subKey
,
strlen
(
pOffset
->
subKey
),
pOffset
,
sizeof
(
STqOffset
));
return
taosHashPut
(
pStore
->
pHash
,
pOffset
->
subKey
,
strlen
(
pOffset
->
subKey
),
pOffset
,
sizeof
(
STqOffset
));
}
}
int32_t
tqOffsetDelete
(
STqOffsetStore
*
pStore
,
const
char
*
subscribeKey
)
{
return
taosHashRemove
(
pStore
->
pHash
,
subscribeKey
,
strlen
(
subscribeKey
));
}
int32_t
tqOffsetSnapshot
(
STqOffsetStore
*
pStore
)
{
int32_t
tqOffsetSnapshot
(
STqOffsetStore
*
pStore
)
{
// open file
// open file
// TODO file name should be with a version
// TODO file name should be with a version
...
...
source/dnode/vnode/src/tq/tqRead.c
浏览文件 @
0d41f9c8
...
@@ -15,13 +15,13 @@
...
@@ -15,13 +15,13 @@
#include "tq.h"
#include "tq.h"
int64_t
tqFetchLog
(
STQ
*
pTq
,
STqHandle
*
pHandle
,
int64_t
*
fetchOffset
,
SWal
Head
**
ppHeadWithCkSum
)
{
int64_t
tqFetchLog
(
STQ
*
pTq
,
STqHandle
*
pHandle
,
int64_t
*
fetchOffset
,
SWal
CkHead
**
ppCkHead
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
taosThreadMutexLock
(
&
pHandle
->
pWalReader
->
mutex
);
taosThreadMutexLock
(
&
pHandle
->
pWalReader
->
mutex
);
int64_t
offset
=
*
fetchOffset
;
int64_t
offset
=
*
fetchOffset
;
while
(
1
)
{
while
(
1
)
{
if
(
walFetchHead
(
pHandle
->
pWalReader
,
offset
,
*
pp
HeadWithCkSum
)
<
0
)
{
if
(
walFetchHead
(
pHandle
->
pWalReader
,
offset
,
*
pp
CkHead
)
<
0
)
{
tqDebug
(
"tmq poll: consumer %ld (epoch %d) vg %d offset %ld, no more log to return"
,
pHandle
->
consumerId
,
tqDebug
(
"tmq poll: consumer %ld (epoch %d) vg %d offset %ld, no more log to return"
,
pHandle
->
consumerId
,
pHandle
->
epoch
,
TD_VID
(
pTq
->
pVnode
),
offset
);
pHandle
->
epoch
,
TD_VID
(
pTq
->
pVnode
),
offset
);
*
fetchOffset
=
offset
-
1
;
*
fetchOffset
=
offset
-
1
;
...
@@ -29,8 +29,8 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalHead*
...
@@ -29,8 +29,8 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalHead*
goto
END
;
goto
END
;
}
}
if
((
*
pp
HeadWithCkSum
)
->
head
.
msgType
==
TDMT_VND_SUBMIT
)
{
if
((
*
pp
CkHead
)
->
head
.
msgType
==
TDMT_VND_SUBMIT
)
{
code
=
walFetchBody
(
pHandle
->
pWalReader
,
pp
HeadWithCkSum
);
code
=
walFetchBody
(
pHandle
->
pWalReader
,
pp
CkHead
);
if
(
code
<
0
)
{
if
(
code
<
0
)
{
ASSERT
(
0
);
ASSERT
(
0
);
...
@@ -43,9 +43,9 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalHead*
...
@@ -43,9 +43,9 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalHead*
goto
END
;
goto
END
;
}
else
{
}
else
{
if
(
pHandle
->
fetchMeta
)
{
if
(
pHandle
->
fetchMeta
)
{
SWal
ReadHead
*
pHead
=
&
((
*
ppHeadWithCkSum
)
->
head
);
SWal
Cont
*
pHead
=
&
((
*
ppCkHead
)
->
head
);
if
(
IS_META_MSG
(
pHead
->
msgType
))
{
if
(
IS_META_MSG
(
pHead
->
msgType
))
{
code
=
walFetchBody
(
pHandle
->
pWalReader
,
pp
HeadWithCkSum
);
code
=
walFetchBody
(
pHandle
->
pWalReader
,
pp
CkHead
);
if
(
code
<
0
)
{
if
(
code
<
0
)
{
ASSERT
(
0
);
ASSERT
(
0
);
...
@@ -58,7 +58,7 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalHead*
...
@@ -58,7 +58,7 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalHead*
goto
END
;
goto
END
;
}
}
}
}
code
=
walSkipFetchBody
(
pHandle
->
pWalReader
,
*
pp
HeadWithCkSum
);
code
=
walSkipFetchBody
(
pHandle
->
pWalReader
,
*
pp
CkHead
);
if
(
code
<
0
)
{
if
(
code
<
0
)
{
ASSERT
(
0
);
ASSERT
(
0
);
*
fetchOffset
=
offset
;
*
fetchOffset
=
offset
;
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
0d41f9c8
...
@@ -119,7 +119,7 @@ static int32_t vnodeProcessAlterReplicaReq(SVnode *pVnode, SRpcMsg *pMsg) {
...
@@ -119,7 +119,7 @@ static int32_t vnodeProcessAlterReplicaReq(SVnode *pVnode, SRpcMsg *pMsg) {
}
}
void
vnodeProposeMsg
(
SQueueInfo
*
pInfo
,
STaosQall
*
qall
,
int32_t
numOfMsgs
)
{
void
vnodeProposeMsg
(
SQueueInfo
*
pInfo
,
STaosQall
*
qall
,
int32_t
numOfMsgs
)
{
SVnode
*
pVnode
=
pInfo
->
ahandle
;
SVnode
*
pVnode
=
pInfo
->
ahandle
;
int32_t
vgId
=
pVnode
->
config
.
vgId
;
int32_t
vgId
=
pVnode
->
config
.
vgId
;
int32_t
code
=
0
;
int32_t
code
=
0
;
SRpcMsg
*
pMsg
=
NULL
;
SRpcMsg
*
pMsg
=
NULL
;
...
@@ -199,7 +199,7 @@ void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
...
@@ -199,7 +199,7 @@ void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
}
}
void
vnodeApplyMsg
(
SQueueInfo
*
pInfo
,
STaosQall
*
qall
,
int32_t
numOfMsgs
)
{
void
vnodeApplyMsg
(
SQueueInfo
*
pInfo
,
STaosQall
*
qall
,
int32_t
numOfMsgs
)
{
SVnode
*
pVnode
=
pInfo
->
ahandle
;
SVnode
*
pVnode
=
pInfo
->
ahandle
;
int32_t
vgId
=
pVnode
->
config
.
vgId
;
int32_t
vgId
=
pVnode
->
config
.
vgId
;
int32_t
code
=
0
;
int32_t
code
=
0
;
SRpcMsg
*
pMsg
=
NULL
;
SRpcMsg
*
pMsg
=
NULL
;
...
@@ -240,7 +240,7 @@ int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
...
@@ -240,7 +240,7 @@ int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
do
{
do
{
char
*
syncNodeStr
=
sync2SimpleStr
(
pVnode
->
sync
);
char
*
syncNodeStr
=
sync2SimpleStr
(
pVnode
->
sync
);
static
int64_t
vndTick
=
0
;
static
int64_t
vndTick
=
0
;
if
(
++
vndTick
%
10
==
1
)
{
if
(
++
vndTick
%
10
==
1
)
{
vGTrace
(
"vgId:%d, sync trace msg:%s, %s"
,
syncGetVgId
(
pVnode
->
sync
),
TMSG_INFO
(
pMsg
->
msgType
),
syncNodeStr
);
vGTrace
(
"vgId:%d, sync trace msg:%s, %s"
,
syncGetVgId
(
pVnode
->
sync
),
TMSG_INFO
(
pMsg
->
msgType
),
syncNodeStr
);
...
@@ -375,7 +375,7 @@ static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReCon
...
@@ -375,7 +375,7 @@ static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReCon
}
}
static
void
vnodeSyncCommitMsg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
static
void
vnodeSyncCommitMsg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
SVnode
*
pVnode
=
pFsm
->
data
;
SVnode
*
pVnode
=
pFsm
->
data
;
SSnapshot
snapshot
=
{
0
};
SSnapshot
snapshot
=
{
0
};
SyncIndex
beginIndex
=
SYNC_INDEX_INVALID
;
SyncIndex
beginIndex
=
SYNC_INDEX_INVALID
;
char
logBuf
[
256
]
=
{
0
};
char
logBuf
[
256
]
=
{
0
};
...
@@ -409,7 +409,7 @@ static void vnodeSyncRollBackMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta
...
@@ -409,7 +409,7 @@ static void vnodeSyncRollBackMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta
syncRpcMsgLog2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
syncRpcMsgLog2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
}
static
int32_t
vnodeSnapshotStartRead
(
struct
SSyncFSM
*
pFsm
,
void
**
ppReader
)
{
return
0
;
}
static
int32_t
vnodeSnapshotStartRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pParam
,
void
*
*
ppReader
)
{
return
0
;
}
static
int32_t
vnodeSnapshotStopRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
)
{
return
0
;
}
static
int32_t
vnodeSnapshotStopRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
)
{
return
0
;
}
...
...
source/libs/command/src/command.c
浏览文件 @
0d41f9c8
...
@@ -297,7 +297,7 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
...
@@ -297,7 +297,7 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
SArray
*
pTagVals
=
NULL
;
SArray
*
pTagVals
=
NULL
;
STag
*
pTag
=
(
STag
*
)
pCfg
->
pTags
;
STag
*
pTag
=
(
STag
*
)
pCfg
->
pTags
;
if
(
pCfg
->
pTags
&&
pTag
->
flags
&
TD_TAG_JSON
)
{
if
(
pCfg
->
pTags
&&
tTagIsJson
(
pTag
)
)
{
char
*
pJson
=
parseTagDatatoJson
(
pTag
);
char
*
pJson
=
parseTagDatatoJson
(
pTag
);
if
(
pJson
)
{
if
(
pJson
)
{
*
len
+=
sprintf
(
buf
+
VARSTR_HEADER_SIZE
+
*
len
,
"%s"
,
pJson
);
*
len
+=
sprintf
(
buf
+
VARSTR_HEADER_SIZE
+
*
len
,
"%s"
,
pJson
);
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
0d41f9c8
...
@@ -287,6 +287,7 @@ typedef struct STableScanInfo {
...
@@ -287,6 +287,7 @@ typedef struct STableScanInfo {
}
lastStatus
;
}
lastStatus
;
int8_t
scanMode
;
int8_t
scanMode
;
int8_t
noTable
;
}
STableScanInfo
;
}
STableScanInfo
;
typedef
struct
STagScanInfo
{
typedef
struct
STagScanInfo
{
...
...
source/libs/executor/src/executil.c
浏览文件 @
0d41f9c8
...
@@ -63,6 +63,7 @@ size_t getResultRowSize(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
...
@@ -63,6 +63,7 @@ size_t getResultRowSize(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
rowSize
+=
pCtx
[
i
].
resDataInfo
.
interBufSize
;
rowSize
+=
pCtx
[
i
].
resDataInfo
.
interBufSize
;
}
}
rowSize
+=
(
numOfOutput
*
sizeof
(
bool
));
// expand rowSize to mark if col is null for top/bottom result(saveTupleData)
return
rowSize
;
return
rowSize
;
}
}
...
@@ -112,7 +113,9 @@ void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SHashObj* pHashmap, int
...
@@ -112,7 +113,9 @@ void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SHashObj* pHashmap, int
p
->
groupId
=
*
(
uint64_t
*
)
key
;
p
->
groupId
=
*
(
uint64_t
*
)
key
;
p
->
pos
=
*
(
SResultRowPosition
*
)
pData
;
p
->
pos
=
*
(
SResultRowPosition
*
)
pData
;
memcpy
(
p
->
key
,
(
char
*
)
key
+
sizeof
(
uint64_t
),
keyLen
-
sizeof
(
uint64_t
));
memcpy
(
p
->
key
,
(
char
*
)
key
+
sizeof
(
uint64_t
),
keyLen
-
sizeof
(
uint64_t
));
#ifdef BUF_PAGE_DEBUG
qDebug
(
"page_groupRes, groupId:%"
PRIu64
",pageId:%d,offset:%d
\n
"
,
p
->
groupId
,
p
->
pos
.
pageId
,
p
->
pos
.
offset
);
#endif
taosArrayPush
(
pGroupResInfo
->
pRows
,
&
p
);
taosArrayPush
(
pGroupResInfo
->
pRows
,
&
p
);
}
}
...
@@ -271,6 +274,7 @@ static bool isTableOk(STableKeyInfo* info, SNode* pTagCond, SMeta* metaHandle) {
...
@@ -271,6 +274,7 @@ static bool isTableOk(STableKeyInfo* info, SNode* pTagCond, SMeta* metaHandle) {
SNode
*
pNew
=
NULL
;
SNode
*
pNew
=
NULL
;
int32_t
code
=
scalarCalculateConstants
(
pTagCondTmp
,
&
pNew
);
int32_t
code
=
scalarCalculateConstants
(
pTagCondTmp
,
&
pNew
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
terrno
=
code
;
nodesDestroyNode
(
pTagCondTmp
);
nodesDestroyNode
(
pTagCondTmp
);
return
false
;
return
false
;
}
}
...
@@ -323,12 +327,19 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo
...
@@ -323,12 +327,19 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo
code
=
tsdbGetAllTableList
(
metaHandle
,
tableUid
,
pListInfo
->
pTableList
);
code
=
tsdbGetAllTableList
(
metaHandle
,
tableUid
,
pListInfo
->
pTableList
);
}
}
if
(
pTagCond
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"failed to get tableIds, reason: %s, suid: %"
PRIu64
""
,
tstrerror
(
code
),
tableUid
);
terrno
=
code
;
return
code
;
}
if
(
pTagCond
){
int32_t
i
=
0
;
int32_t
i
=
0
;
while
(
i
<
taosArrayGetSize
(
pListInfo
->
pTableList
))
{
while
(
i
<
taosArrayGetSize
(
pListInfo
->
pTableList
))
{
STableKeyInfo
*
info
=
taosArrayGet
(
pListInfo
->
pTableList
,
i
);
STableKeyInfo
*
info
=
taosArrayGet
(
pListInfo
->
pTableList
,
i
);
bool
isOk
=
isTableOk
(
info
,
pTagCond
,
metaHandle
);
bool
isOk
=
isTableOk
(
info
,
pTagCond
,
metaHandle
);
if
(
!
isOk
)
{
if
(
terrno
)
return
terrno
;
if
(
!
isOk
){
taosArrayRemove
(
pListInfo
->
pTableList
,
i
);
taosArrayRemove
(
pListInfo
->
pTableList
,
i
);
continue
;
continue
;
}
}
...
@@ -586,13 +597,16 @@ static int32_t setSelectValueColumnInfo(SqlFunctionCtx* pCtx, int32_t numOfOutpu
...
@@ -586,13 +597,16 @@ static int32_t setSelectValueColumnInfo(SqlFunctionCtx* pCtx, int32_t numOfOutpu
}
}
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
if
(
strcmp
(
pCtx
[
i
].
pExpr
->
pExpr
->
_function
.
functionName
,
"_select_value"
)
==
0
)
{
if
(
strcmp
(
pCtx
[
i
].
pExpr
->
pExpr
->
_function
.
functionName
,
"_select_value"
)
==
0
||
strcmp
(
pCtx
[
i
].
pExpr
->
pExpr
->
_function
.
functionName
,
"_group_key"
)
==
0
)
{
pValCtx
[
num
++
]
=
&
pCtx
[
i
];
pValCtx
[
num
++
]
=
&
pCtx
[
i
];
}
else
if
(
fmIsSelectFunc
(
pCtx
[
i
].
functionId
))
{
}
else
if
(
fmIsSelectFunc
(
pCtx
[
i
].
functionId
))
{
p
=
&
pCtx
[
i
];
p
=
&
pCtx
[
i
];
}
}
}
}
#ifdef BUF_PAGE_DEBUG
qDebug
(
"page_setSelect num:%d"
,
num
);
#endif
if
(
p
!=
NULL
)
{
if
(
p
!=
NULL
)
{
p
->
subsidiaries
.
pCtx
=
pValCtx
;
p
->
subsidiaries
.
pCtx
=
pValCtx
;
p
->
subsidiaries
.
num
=
num
;
p
->
subsidiaries
.
num
=
num
;
...
...
source/libs/executor/src/executorMain.c
浏览文件 @
0d41f9c8
...
@@ -235,9 +235,11 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, uint64_t uid, int64_t ts) {
...
@@ -235,9 +235,11 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, uint64_t uid, int64_t ts) {
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
tinfo
;
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
tinfo
;
if
(
uid
==
0
)
{
if
(
uid
==
0
)
{
STableKeyInfo
*
pTableInfo
=
taosArrayGet
(
pTaskInfo
->
tableqinfoList
.
pTableList
,
0
);
if
(
taosArrayGetSize
(
pTaskInfo
->
tableqinfoList
.
pTableList
)
!=
0
)
{
uid
=
pTableInfo
->
uid
;
STableKeyInfo
*
pTableInfo
=
taosArrayGet
(
pTaskInfo
->
tableqinfoList
.
pTableList
,
0
);
ts
=
INT64_MIN
;
uid
=
pTableInfo
->
uid
;
ts
=
INT64_MIN
;
}
}
}
return
doPrepareScan
(
pTaskInfo
->
pRoot
,
uid
,
ts
);
return
doPrepareScan
(
pTaskInfo
->
pRoot
,
uid
,
ts
);
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
0d41f9c8
...
@@ -274,6 +274,9 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
...
@@ -274,6 +274,9 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
// 1. close current opened time window
// 1. close current opened time window
if
(
pResultRowInfo
->
cur
.
pageId
!=
-
1
&&
((
pResult
==
NULL
)
||
(
pResult
->
pageId
!=
pResultRowInfo
->
cur
.
pageId
)))
{
if
(
pResultRowInfo
->
cur
.
pageId
!=
-
1
&&
((
pResult
==
NULL
)
||
(
pResult
->
pageId
!=
pResultRowInfo
->
cur
.
pageId
)))
{
#ifdef BUF_PAGE_DEBUG
qDebug
(
"page_1"
);
#endif
SResultRowPosition
pos
=
pResultRowInfo
->
cur
;
SResultRowPosition
pos
=
pResultRowInfo
->
cur
;
SFilePage
*
pPage
=
getBufPage
(
pResultBuf
,
pos
.
pageId
);
SFilePage
*
pPage
=
getBufPage
(
pResultBuf
,
pos
.
pageId
);
releaseBufPage
(
pResultBuf
,
pPage
);
releaseBufPage
(
pResultBuf
,
pPage
);
...
@@ -281,6 +284,9 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
...
@@ -281,6 +284,9 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
// allocate a new buffer page
// allocate a new buffer page
if
(
pResult
==
NULL
)
{
if
(
pResult
==
NULL
)
{
#ifdef BUF_PAGE_DEBUG
qDebug
(
"page_2"
);
#endif
ASSERT
(
pSup
->
resultRowSize
>
0
);
ASSERT
(
pSup
->
resultRowSize
>
0
);
pResult
=
getNewResultRow
(
pResultBuf
,
groupId
,
pSup
->
resultRowSize
);
pResult
=
getNewResultRow
(
pResultBuf
,
groupId
,
pSup
->
resultRowSize
);
...
@@ -538,7 +544,9 @@ static int32_t doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunct
...
@@ -538,7 +544,9 @@ static int32_t doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunct
if
(
pCtx
[
k
].
fpSet
.
process
==
NULL
)
{
if
(
pCtx
[
k
].
fpSet
.
process
==
NULL
)
{
continue
;
continue
;
}
}
#ifdef BUF_PAGE_DEBUG
qDebug
(
"page_process"
);
#endif
int32_t
code
=
pCtx
[
k
].
fpSet
.
process
(
&
pCtx
[
k
]);
int32_t
code
=
pCtx
[
k
].
fpSet
.
process
(
&
pCtx
[
k
]);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"%s aggregate function error happens, code: %s"
,
GET_TASKID
(
pOperator
->
pTaskInfo
),
tstrerror
(
code
));
qError
(
"%s aggregate function error happens, code: %s"
,
GET_TASKID
(
pOperator
->
pTaskInfo
),
tstrerror
(
code
));
...
@@ -1413,7 +1421,9 @@ void setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t
...
@@ -1413,7 +1421,9 @@ void setExecutionContext(SOperatorInfo* pOperator, int32_t numOfOutput, uint64_t
if
(
pAggInfo
->
groupId
!=
INT32_MIN
&&
pAggInfo
->
groupId
==
groupId
)
{
if
(
pAggInfo
->
groupId
!=
INT32_MIN
&&
pAggInfo
->
groupId
==
groupId
)
{
return
;
return
;
}
}
#ifdef BUF_PAGE_DEBUG
qDebug
(
"page_setbuf, groupId:%"
PRIu64
,
groupId
);
#endif
doSetTableGroupOutputBuf
(
pOperator
,
pAggInfo
,
numOfOutput
,
groupId
);
doSetTableGroupOutputBuf
(
pOperator
,
pAggInfo
,
numOfOutput
,
groupId
);
// record the current active group id
// record the current active group id
...
@@ -1489,11 +1499,15 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprI
...
@@ -1489,11 +1499,15 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprI
int32_t
numOfExprs
)
{
int32_t
numOfExprs
)
{
int32_t
numOfRows
=
getNumOfTotalRes
(
pGroupResInfo
);
int32_t
numOfRows
=
getNumOfTotalRes
(
pGroupResInfo
);
int32_t
start
=
pGroupResInfo
->
index
;
int32_t
start
=
pGroupResInfo
->
index
;
#ifdef BUF_PAGE_DEBUG
qDebug
(
"
\n
page_copytoblock rows:%d"
,
numOfRows
);
#endif
for
(
int32_t
i
=
start
;
i
<
numOfRows
;
i
+=
1
)
{
for
(
int32_t
i
=
start
;
i
<
numOfRows
;
i
+=
1
)
{
SResKeyPos
*
pPos
=
taosArrayGetP
(
pGroupResInfo
->
pRows
,
i
);
SResKeyPos
*
pPos
=
taosArrayGetP
(
pGroupResInfo
->
pRows
,
i
);
SFilePage
*
page
=
getBufPage
(
pBuf
,
pPos
->
pos
.
pageId
);
SFilePage
*
page
=
getBufPage
(
pBuf
,
pPos
->
pos
.
pageId
);
#ifdef BUF_PAGE_DEBUG
qDebug
(
"page_copytoblock pos pageId:%d, offset:%d"
,
pPos
->
pos
.
pageId
,
pPos
->
pos
.
offset
);
#endif
SResultRow
*
pRow
=
(
SResultRow
*
)((
char
*
)
page
+
pPos
->
pos
.
offset
);
SResultRow
*
pRow
=
(
SResultRow
*
)((
char
*
)
page
+
pPos
->
pos
.
offset
);
doUpdateNumOfRows
(
pRow
,
numOfExprs
,
rowCellOffset
);
doUpdateNumOfRows
(
pRow
,
numOfExprs
,
rowCellOffset
);
...
@@ -1525,6 +1539,9 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprI
...
@@ -1525,6 +1539,9 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprI
pCtx
[
j
].
resultInfo
=
getResultEntryInfo
(
pRow
,
j
,
rowCellOffset
);
pCtx
[
j
].
resultInfo
=
getResultEntryInfo
(
pRow
,
j
,
rowCellOffset
);
if
(
pCtx
[
j
].
fpSet
.
finalize
)
{
if
(
pCtx
[
j
].
fpSet
.
finalize
)
{
#ifdef BUF_PAGE_DEBUG
qDebug
(
"
\n
page_finalize %d"
,
numOfExprs
);
#endif
int32_t
code
=
pCtx
[
j
].
fpSet
.
finalize
(
&
pCtx
[
j
],
pBlock
);
int32_t
code
=
pCtx
[
j
].
fpSet
.
finalize
(
&
pCtx
[
j
],
pBlock
);
if
(
TAOS_FAILED
(
code
))
{
if
(
TAOS_FAILED
(
code
))
{
qError
(
"%s build result data block error, code %s"
,
GET_TASKID
(
pTaskInfo
),
tstrerror
(
code
));
qError
(
"%s build result data block error, code %s"
,
GET_TASKID
(
pTaskInfo
),
tstrerror
(
code
));
...
@@ -1553,9 +1570,9 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprI
...
@@ -1553,9 +1570,9 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprI
releaseBufPage
(
pBuf
,
page
);
releaseBufPage
(
pBuf
,
page
);
pBlock
->
info
.
rows
+=
pRow
->
numOfRows
;
pBlock
->
info
.
rows
+=
pRow
->
numOfRows
;
if
(
pBlock
->
info
.
rows
>=
pBlock
->
info
.
capacity
)
{
// output buffer is full
//
if (pBlock->info.rows >= pBlock->info.capacity) { // output buffer is full
break
;
//
break;
}
//
}
}
}
qDebug
(
"%s result generated, rows:%d, groupId:%"
PRIu64
,
GET_TASKID
(
pTaskInfo
),
pBlock
->
info
.
rows
,
qDebug
(
"%s result generated, rows:%d, groupId:%"
PRIu64
,
GET_TASKID
(
pTaskInfo
),
pBlock
->
info
.
rows
,
...
@@ -2373,8 +2390,7 @@ static int32_t initExchangeOperator(SExchangePhysiNode* pExNode, SExchangeInfo*
...
@@ -2373,8 +2390,7 @@ static int32_t initExchangeOperator(SExchangePhysiNode* pExNode, SExchangeInfo*
}
}
pInfo
->
pSources
=
taosArrayInit
(
numOfSources
,
sizeof
(
SDownstreamSourceNode
));
pInfo
->
pSources
=
taosArrayInit
(
numOfSources
,
sizeof
(
SDownstreamSourceNode
));
pInfo
->
pSourceDataInfo
=
taosArrayInit
(
numOfSources
,
sizeof
(
SSourceDataInfo
));
if
(
pInfo
->
pSources
==
NULL
)
{
if
(
pInfo
->
pSourceDataInfo
==
NULL
||
pInfo
->
pSources
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
...
@@ -2829,21 +2845,28 @@ int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) {
...
@@ -2829,21 +2845,28 @@ int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) {
pScanInfo
->
blockType
=
STREAM_INPUT__DATA_SCAN
;
pScanInfo
->
blockType
=
STREAM_INPUT__DATA_SCAN
;
STableScanInfo
*
pInfo
=
pScanInfo
->
pSnapshotReadOp
->
info
;
STableScanInfo
*
pInfo
=
pScanInfo
->
pSnapshotReadOp
->
info
;
if
(
uid
==
0
)
{
pInfo
->
noTable
=
1
;
return
TSDB_CODE_SUCCESS
;
}
/*if (pSnapShotScanInfo->dataReader == NULL) {*/
/*if (pSnapShotScanInfo->dataReader == NULL) {*/
/*pSnapShotScanInfo->dataReader = tsdbReaderOpen(pHandle->vnode, &pSTInfo->cond, tableList, 0, 0);*/
/*pSnapShotScanInfo->dataReader = tsdbReaderOpen(pHandle->vnode, &pSTInfo->cond, tableList, 0, 0);*/
/*pSnapShotScanInfo->scanMode = TABLE_SCAN__TABLE_ORDER;*/
/*pSnapShotScanInfo->scanMode = TABLE_SCAN__TABLE_ORDER;*/
/*}*/
/*}*/
pInfo
->
noTable
=
0
;
if
(
pInfo
->
lastStatus
.
uid
!=
uid
||
pInfo
->
lastStatus
.
ts
!=
ts
)
{
if
(
pInfo
->
lastStatus
.
uid
!=
uid
||
pInfo
->
lastStatus
.
ts
!=
ts
)
{
tsdbSetTableId
(
pInfo
->
dataReader
,
uid
);
tsdbSetTableId
(
pInfo
->
dataReader
,
uid
);
int64_t
oldSkey
=
pInfo
->
cond
.
twindows
[
0
].
skey
;
int64_t
oldSkey
=
pInfo
->
cond
.
twindows
[
0
].
skey
;
pInfo
->
cond
.
twindows
[
0
].
skey
=
ts
;
pInfo
->
cond
.
twindows
[
0
].
skey
=
ts
+
1
;
tsdbResetReadHandle
(
pInfo
->
dataReader
,
&
pInfo
->
cond
,
0
);
tsdbResetReadHandle
(
pInfo
->
dataReader
,
&
pInfo
->
cond
,
0
);
pInfo
->
cond
.
twindows
[
0
].
skey
=
oldSkey
;
pInfo
->
cond
.
twindows
[
0
].
skey
=
oldSkey
;
pInfo
->
scanTimes
=
0
;
pInfo
->
scanTimes
=
0
;
pInfo
->
curTWinIdx
=
0
;
pInfo
->
curTWinIdx
=
0
;
}
}
return
TSDB_CODE_SUCCESS
;
}
else
{
}
else
{
if
(
pOperator
->
numOfDownstream
==
1
)
{
if
(
pOperator
->
numOfDownstream
==
1
)
{
...
@@ -2856,8 +2879,6 @@ int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) {
...
@@ -2856,8 +2879,6 @@ int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts) {
return
TSDB_CODE_QRY_APP_ERROR
;
return
TSDB_CODE_QRY_APP_ERROR
;
}
}
}
}
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
doGetScanStatus
(
SOperatorInfo
*
pOperator
,
uint64_t
*
uid
,
int64_t
*
ts
)
{
int32_t
doGetScanStatus
(
SOperatorInfo
*
pOperator
,
uint64_t
*
uid
,
int64_t
*
ts
)
{
...
@@ -3160,8 +3181,9 @@ static int32_t handleLimitOffset(SOperatorInfo* pOperator, SSDataBlock* pBlock)
...
@@ -3160,8 +3181,9 @@ static int32_t handleLimitOffset(SOperatorInfo* pOperator, SSDataBlock* pBlock)
}
}
// check for the limitation in each group
// check for the limitation in each group
if
(
pProjectInfo
->
limit
.
limit
>
0
&&
pProjectInfo
->
curOutput
+
pRes
->
info
.
rows
>=
pProjectInfo
->
limit
.
limit
)
{
if
(
pProjectInfo
->
limit
.
limit
>=
0
&&
pProjectInfo
->
curOutput
+
pRes
->
info
.
rows
>=
pProjectInfo
->
limit
.
limit
)
{
pRes
->
info
.
rows
=
(
int32_t
)(
pProjectInfo
->
limit
.
limit
-
pProjectInfo
->
curOutput
);
int32_t
keepRows
=
(
int32_t
)(
pProjectInfo
->
limit
.
limit
-
pProjectInfo
->
curOutput
);
blockDataKeepFirstNRows
(
pRes
,
keepRows
);
if
(
pProjectInfo
->
slimit
.
limit
>
0
&&
pProjectInfo
->
slimit
.
limit
<=
pProjectInfo
->
curGroupOutput
)
{
if
(
pProjectInfo
->
slimit
.
limit
>
0
&&
pProjectInfo
->
slimit
.
limit
<=
pProjectInfo
->
curGroupOutput
)
{
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
}
}
...
@@ -3235,8 +3257,6 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
...
@@ -3235,8 +3257,6 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
longjmp
(
pTaskInfo
->
env
,
code
);
longjmp
(
pTaskInfo
->
env
,
code
);
}
}
doFilter
(
pProjectInfo
->
pFilterNode
,
pBlock
);
setInputDataBlock
(
pOperator
,
pSup
->
pCtx
,
pBlock
,
order
,
scanFlag
,
false
);
setInputDataBlock
(
pOperator
,
pSup
->
pCtx
,
pBlock
,
order
,
scanFlag
,
false
);
blockDataEnsureCapacity
(
pInfo
->
pRes
,
pInfo
->
pRes
->
info
.
rows
+
pBlock
->
info
.
rows
);
blockDataEnsureCapacity
(
pInfo
->
pRes
,
pInfo
->
pRes
->
info
.
rows
+
pBlock
->
info
.
rows
);
...
@@ -3247,6 +3267,10 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
...
@@ -3247,6 +3267,10 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
}
}
int32_t
status
=
handleLimitOffset
(
pOperator
,
pBlock
);
int32_t
status
=
handleLimitOffset
(
pOperator
,
pBlock
);
// filter shall be applied after apply functions and limit/offset on the result
doFilter
(
pProjectInfo
->
pFilterNode
,
pInfo
->
pRes
);
if
(
status
==
PROJECT_RETRIEVE_CONTINUE
)
{
if
(
status
==
PROJECT_RETRIEVE_CONTINUE
)
{
continue
;
continue
;
}
else
if
(
status
==
PROJECT_RETRIEVE_DONE
)
{
}
else
if
(
status
==
PROJECT_RETRIEVE_DONE
)
{
...
@@ -3473,11 +3497,12 @@ int32_t initAggInfo(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInf
...
@@ -3473,11 +3497,12 @@ int32_t initAggInfo(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInf
}
}
void
initResultSizeInfo
(
SOperatorInfo
*
pOperator
,
int32_t
numOfRows
)
{
void
initResultSizeInfo
(
SOperatorInfo
*
pOperator
,
int32_t
numOfRows
)
{
ASSERT
(
numOfRows
!=
0
);
pOperator
->
resultInfo
.
capacity
=
numOfRows
;
pOperator
->
resultInfo
.
capacity
=
numOfRows
;
pOperator
->
resultInfo
.
threshold
=
numOfRows
*
0
.
75
;
pOperator
->
resultInfo
.
threshold
=
numOfRows
*
0
.
75
;
if
(
pOperator
->
resultInfo
.
threshold
==
0
)
{
if
(
pOperator
->
resultInfo
.
threshold
==
0
)
{
pOperator
->
resultInfo
.
capacity
=
numOfRows
;
pOperator
->
resultInfo
.
threshold
=
numOfRows
;
}
}
}
}
...
@@ -3977,12 +4002,12 @@ static int32_t sortTableGroup(STableListInfo* pTableListInfo, int32_t groupNum)
...
@@ -3977,12 +4002,12 @@ static int32_t sortTableGroup(STableListInfo* pTableListInfo, int32_t groupNum)
return
TSDB_CODE_QRY_APP_ERROR
;
return
TSDB_CODE_QRY_APP_ERROR
;
}
}
if
(
p
==
NULL
)
{
if
(
p
==
NULL
)
{
if
(
taosArrayPush
(
sortSupport
,
groupId
)
!
=
NULL
)
{
if
(
taosArrayPush
(
sortSupport
,
groupId
)
=
=
NULL
)
{
qError
(
"taos push support array error"
);
qError
(
"taos push support array error"
);
taosArrayDestroy
(
sortSupport
);
taosArrayDestroy
(
sortSupport
);
return
TSDB_CODE_QRY_APP_ERROR
;
return
TSDB_CODE_QRY_APP_ERROR
;
}
}
if
(
taosArrayPush
(
pTableListInfo
->
pGroupList
,
&
tGroup
)
!
=
NULL
)
{
if
(
taosArrayPush
(
pTableListInfo
->
pGroupList
,
&
tGroup
)
=
=
NULL
)
{
qError
(
"taos push group array error"
);
qError
(
"taos push group array error"
);
taosArrayDestroy
(
sortSupport
);
taosArrayDestroy
(
sortSupport
);
return
TSDB_CODE_QRY_APP_ERROR
;
return
TSDB_CODE_QRY_APP_ERROR
;
...
@@ -4062,6 +4087,7 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle,
...
@@ -4062,6 +4087,7 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle,
}
else
{
}
else
{
taosMemoryFree
(
keyBuf
);
taosMemoryFree
(
keyBuf
);
nodesClearList
(
groupNew
);
nodesClearList
(
groupNew
);
metaReaderClear
(
&
mr
);
return
code
;
return
code
;
}
}
...
@@ -4074,7 +4100,14 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle,
...
@@ -4074,7 +4100,14 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle,
}
else
{
}
else
{
isNull
[
index
++
]
=
0
;
isNull
[
index
++
]
=
0
;
char
*
data
=
nodesGetValueFromNode
(
pValue
);
char
*
data
=
nodesGetValueFromNode
(
pValue
);
if
(
pValue
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
pValue
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_JSON
){
if
(
tTagIsJson
(
data
)){
terrno
=
TSDB_CODE_QRY_JSON_IN_GROUP_ERROR
;
taosMemoryFree
(
keyBuf
);
nodesClearList
(
groupNew
);
metaReaderClear
(
&
mr
);
return
terrno
;
}
int32_t
len
=
getJsonValueLen
(
data
);
int32_t
len
=
getJsonValueLen
(
data
);
memcpy
(
pStart
,
data
,
len
);
memcpy
(
pStart
,
data
,
len
);
pStart
+=
len
;
pStart
+=
len
;
...
@@ -4133,7 +4166,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
...
@@ -4133,7 +4166,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN
==
type
)
{
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN
==
type
)
{
STableMergeScanPhysiNode
*
pTableScanNode
=
(
STableMergeScanPhysiNode
*
)
pPhyNode
;
STableMergeScanPhysiNode
*
pTableScanNode
=
(
STableMergeScanPhysiNode
*
)
pPhyNode
;
int32_t
code
=
createScanTableListInfo
(
pTableScanNode
,
pHandle
,
pTableListInfo
,
queryId
,
taskId
);
int32_t
code
=
createScanTableListInfo
(
pTableScanNode
,
pHandle
,
pTableListInfo
,
queryId
,
taskId
);
if
(
code
)
{
if
(
code
){
pTaskInfo
->
code
=
code
;
return
NULL
;
return
NULL
;
}
}
code
=
extractTableSchemaVersion
(
pHandle
,
pTableScanNode
->
scan
.
uid
,
pTaskInfo
);
code
=
extractTableSchemaVersion
(
pHandle
,
pTableScanNode
->
scan
.
uid
,
pTaskInfo
);
...
@@ -4160,7 +4194,11 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
...
@@ -4160,7 +4194,11 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
.
maxTs
=
INT64_MIN
,
.
maxTs
=
INT64_MIN
,
};
};
if
(
pHandle
)
{
if
(
pHandle
)
{
createScanTableListInfo
(
pTableScanNode
,
pHandle
,
pTableListInfo
,
queryId
,
taskId
);
int32_t
code
=
createScanTableListInfo
(
pTableScanNode
,
pHandle
,
pTableListInfo
,
queryId
,
taskId
);
if
(
code
){
pTaskInfo
->
code
=
code
;
return
NULL
;
}
}
}
SOperatorInfo
*
pOperator
=
SOperatorInfo
*
pOperator
=
...
...
source/libs/executor/src/groupoperator.c
浏览文件 @
0d41f9c8
...
@@ -141,6 +141,10 @@ static void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSData
...
@@ -141,6 +141,10 @@ static void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSData
pkey
->
isNull
=
false
;
pkey
->
isNull
=
false
;
char
*
val
=
colDataGetData
(
pColInfoData
,
rowIndex
);
char
*
val
=
colDataGetData
(
pColInfoData
,
rowIndex
);
if
(
pkey
->
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
pkey
->
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
tTagIsJson
(
val
)){
terrno
=
TSDB_CODE_QRY_JSON_IN_GROUP_ERROR
;
return
;
}
int32_t
dataLen
=
getJsonValueLen
(
val
);
int32_t
dataLen
=
getJsonValueLen
(
val
);
memcpy
(
pkey
->
pData
,
val
,
dataLen
);
memcpy
(
pkey
->
pData
,
val
,
dataLen
);
}
else
if
(
IS_VAR_DATA_TYPE
(
pkey
->
type
))
{
}
else
if
(
IS_VAR_DATA_TYPE
(
pkey
->
type
))
{
...
@@ -227,11 +231,15 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
...
@@ -227,11 +231,15 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
int32_t
len
=
0
;
int32_t
len
=
0
;
STimeWindow
w
=
TSWINDOW_INITIALIZER
;
STimeWindow
w
=
TSWINDOW_INITIALIZER
;
terrno
=
TSDB_CODE_SUCCESS
;
int32_t
num
=
0
;
int32_t
num
=
0
;
for
(
int32_t
j
=
0
;
j
<
pBlock
->
info
.
rows
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pBlock
->
info
.
rows
;
++
j
)
{
// Compare with the previous row of this column, and do not set the output buffer again if they are identical.
// Compare with the previous row of this column, and do not set the output buffer again if they are identical.
if
(
!
pInfo
->
isInit
)
{
if
(
!
pInfo
->
isInit
)
{
recordNewGroupKeys
(
pInfo
->
pGroupCols
,
pInfo
->
pGroupColVals
,
pBlock
,
j
);
recordNewGroupKeys
(
pInfo
->
pGroupCols
,
pInfo
->
pGroupColVals
,
pBlock
,
j
);
if
(
terrno
!=
TSDB_CODE_SUCCESS
)
{
// group by json error
longjmp
(
pTaskInfo
->
env
,
terrno
);
}
pInfo
->
isInit
=
true
;
pInfo
->
isInit
=
true
;
num
++
;
num
++
;
continue
;
continue
;
...
@@ -247,6 +255,9 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
...
@@ -247,6 +255,9 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
if
(
j
==
0
)
{
if
(
j
==
0
)
{
num
++
;
num
++
;
recordNewGroupKeys
(
pInfo
->
pGroupCols
,
pInfo
->
pGroupColVals
,
pBlock
,
j
);
recordNewGroupKeys
(
pInfo
->
pGroupCols
,
pInfo
->
pGroupColVals
,
pBlock
,
j
);
if
(
terrno
!=
TSDB_CODE_SUCCESS
)
{
// group by json error
longjmp
(
pTaskInfo
->
env
,
terrno
);
}
continue
;
continue
;
}
}
...
@@ -661,7 +672,11 @@ static SSDataBlock* hashPartition(SOperatorInfo* pOperator) {
...
@@ -661,7 +672,11 @@ static SSDataBlock* hashPartition(SOperatorInfo* pOperator) {
}
}
}
}
terrno
=
TSDB_CODE_SUCCESS
;
doHashPartition
(
pOperator
,
pBlock
);
doHashPartition
(
pOperator
,
pBlock
);
if
(
terrno
!=
TSDB_CODE_SUCCESS
)
{
// group by json error
longjmp
(
pTaskInfo
->
env
,
terrno
);
}
}
}
SArray
*
groupArray
=
taosArrayInit
(
taosHashGetSize
(
pInfo
->
pGroupSet
),
sizeof
(
SDataGroupInfo
));
SArray
*
groupArray
=
taosArrayInit
(
taosHashGetSize
(
pInfo
->
pGroupSet
),
sizeof
(
SDataGroupInfo
));
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
0d41f9c8
...
@@ -518,6 +518,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
...
@@ -518,6 +518,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) {
// if scan table by table
// if scan table by table
if
(
pInfo
->
scanMode
==
TABLE_SCAN__TABLE_ORDER
)
{
if
(
pInfo
->
scanMode
==
TABLE_SCAN__TABLE_ORDER
)
{
if
(
pInfo
->
noTable
)
return
NULL
;
while
(
1
)
{
while
(
1
)
{
SSDataBlock
*
result
=
doTableScanGroup
(
pOperator
);
SSDataBlock
*
result
=
doTableScanGroup
(
pOperator
);
if
(
result
)
{
if
(
result
)
{
...
@@ -2089,6 +2090,7 @@ int32_t createScanTableListInfo(STableScanPhysiNode* pTableScanNode, SReadHandle
...
@@ -2089,6 +2090,7 @@ int32_t createScanTableListInfo(STableScanPhysiNode* pTableScanNode, SReadHandle
qDebug
(
"no table qualified for query, TID:0x%"
PRIx64
", QID:0x%"
PRIx64
,
taskId
,
queryId
);
qDebug
(
"no table qualified for query, TID:0x%"
PRIx64
", QID:0x%"
PRIx64
,
taskId
,
queryId
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
pTableListInfo
->
needSortTableByGroupId
=
pTableScanNode
->
groupSort
;
code
=
generateGroupIdMap
(
pTableListInfo
,
pHandle
,
pTableScanNode
->
pGroupTags
);
code
=
generateGroupIdMap
(
pTableListInfo
,
pHandle
,
pTableScanNode
->
pGroupTags
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
...
...
source/libs/executor/src/tsort.c
浏览文件 @
0d41f9c8
...
@@ -593,7 +593,10 @@ static int32_t createInitialSources(SSortHandle* pHandle) {
...
@@ -593,7 +593,10 @@ static int32_t createInitialSources(SSortHandle* pHandle) {
if
(
size
>
sortBufSize
)
{
if
(
size
>
sortBufSize
)
{
// Perform the in-memory sort and then flush data in the buffer into disk.
// Perform the in-memory sort and then flush data in the buffer into disk.
int64_t
p
=
taosGetTimestampUs
();
int64_t
p
=
taosGetTimestampUs
();
blockDataSort
(
pHandle
->
pDataBlock
,
pHandle
->
pSortInfo
);
code
=
blockDataSort
(
pHandle
->
pDataBlock
,
pHandle
->
pSortInfo
);
if
(
code
!=
0
)
{
return
code
;
}
int64_t
el
=
taosGetTimestampUs
()
-
p
;
int64_t
el
=
taosGetTimestampUs
()
-
p
;
pHandle
->
sortElapsed
+=
el
;
pHandle
->
sortElapsed
+=
el
;
...
@@ -608,7 +611,10 @@ static int32_t createInitialSources(SSortHandle* pHandle) {
...
@@ -608,7 +611,10 @@ static int32_t createInitialSources(SSortHandle* pHandle) {
// Perform the in-memory sort and then flush data in the buffer into disk.
// Perform the in-memory sort and then flush data in the buffer into disk.
int64_t
p
=
taosGetTimestampUs
();
int64_t
p
=
taosGetTimestampUs
();
blockDataSort
(
pHandle
->
pDataBlock
,
pHandle
->
pSortInfo
);
int32_t
code
=
blockDataSort
(
pHandle
->
pDataBlock
,
pHandle
->
pSortInfo
);
if
(
code
!=
0
)
{
return
code
;
}
int64_t
el
=
taosGetTimestampUs
()
-
p
;
int64_t
el
=
taosGetTimestampUs
()
-
p
;
pHandle
->
sortElapsed
+=
el
;
pHandle
->
sortElapsed
+=
el
;
...
...
source/libs/function/src/builtins.c
浏览文件 @
0d41f9c8
...
@@ -1543,7 +1543,7 @@ static int32_t translateToJson(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
...
@@ -1543,7 +1543,7 @@ static int32_t translateToJson(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
}
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_
BINARY
].
bytes
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_
JSON
].
bytes
,
.
type
=
TSDB_DATA_TYPE_JSON
};
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -2620,7 +2620,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -2620,7 +2620,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
{
.
name
=
"_group_key"
,
.
name
=
"_group_key"
,
.
type
=
FUNCTION_TYPE_GROUP_KEY
,
.
type
=
FUNCTION_TYPE_GROUP_KEY
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
,
.
translateFunc
=
translateGroupKey
,
.
translateFunc
=
translateGroupKey
,
.
getEnvFunc
=
getGroupKeyFuncEnv
,
.
getEnvFunc
=
getGroupKeyFuncEnv
,
.
initFunc
=
functionSetup
,
.
initFunc
=
functionSetup
,
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
0d41f9c8
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include "tglobal.h"
#include "tglobal.h"
#include "thistogram.h"
#include "thistogram.h"
#include "tpercentile.h"
#include "tpercentile.h"
#include "query.h"
#define HISTOGRAM_MAX_BINS_NUM 1000
#define HISTOGRAM_MAX_BINS_NUM 1000
#define MAVG_MAX_POINTS_NUM 1000
#define MAVG_MAX_POINTS_NUM 1000
...
@@ -1472,8 +1473,8 @@ void setSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, const STuple
...
@@ -1472,8 +1473,8 @@ void setSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, const STuple
int32_t
pageId
=
pTuplePos
->
pageId
;
int32_t
pageId
=
pTuplePos
->
pageId
;
int32_t
offset
=
pTuplePos
->
offset
;
int32_t
offset
=
pTuplePos
->
offset
;
if
(
pTuplePos
->
pageId
!=
-
1
)
{
if
(
pTuplePos
->
pageId
!=
-
1
&&
pCtx
->
subsidiaries
.
num
>
0
)
{
int32_t
numOfCols
=
taosArrayGetSize
(
pCtx
->
pSrcBlock
->
pDataBlock
)
;
int32_t
numOfCols
=
pCtx
->
subsidiaries
.
num
;
SFilePage
*
pPage
=
getBufPage
(
pCtx
->
pBuf
,
pageId
);
SFilePage
*
pPage
=
getBufPage
(
pCtx
->
pBuf
,
pageId
);
bool
*
nullList
=
(
bool
*
)((
char
*
)
pPage
+
offset
);
bool
*
nullList
=
(
bool
*
)((
char
*
)
pPage
+
offset
);
...
@@ -1484,22 +1485,21 @@ void setSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, const STuple
...
@@ -1484,22 +1485,21 @@ void setSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, const STuple
SqlFunctionCtx
*
pc
=
pCtx
->
subsidiaries
.
pCtx
[
j
];
SqlFunctionCtx
*
pc
=
pCtx
->
subsidiaries
.
pCtx
[
j
];
SFunctParam
*
pFuncParam
=
&
pc
->
pExpr
->
base
.
pParam
[
0
];
SFunctParam
*
pFuncParam
=
&
pc
->
pExpr
->
base
.
pParam
[
0
];
int32_t
srcSlotId
=
pFuncParam
->
pCol
->
slotId
;
int32_t
dstSlotId
=
pc
->
pExpr
->
base
.
resSchema
.
slotId
;
int32_t
dstSlotId
=
pc
->
pExpr
->
base
.
resSchema
.
slotId
;
int32_t
ps
=
0
;
int32_t
ps
=
0
;
for
(
int32_t
k
=
0
;
k
<
srcSlotId
;
++
k
)
{
SColumnInfoData
*
pSrcCol
=
taosArrayGet
(
pCtx
->
pSrcBlock
->
pDataBlock
,
k
);
ps
+=
pSrcCol
->
info
.
bytes
;
}
SColumnInfoData
*
pDstCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
dstSlotId
);
SColumnInfoData
*
pDstCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
dstSlotId
);
if
(
nullList
[
srcSlotId
])
{
ASSERT
(
pc
->
pExpr
->
base
.
resSchema
.
bytes
==
pDstCol
->
info
.
bytes
);
if
(
nullList
[
j
])
{
colDataAppendNULL
(
pDstCol
,
rowIndex
);
colDataAppendNULL
(
pDstCol
,
rowIndex
);
}
else
{
}
else
{
colDataAppend
(
pDstCol
,
rowIndex
,
(
pStart
+
ps
)
,
false
);
colDataAppend
(
pDstCol
,
rowIndex
,
pStart
,
false
);
}
}
pStart
+=
pDstCol
->
info
.
bytes
;
}
}
releaseBufPage
(
pCtx
->
pBuf
,
pPage
);
}
}
}
}
...
@@ -3208,7 +3208,9 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
...
@@ -3208,7 +3208,9 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
saveTupleData
(
pCtx
,
rowIndex
,
pSrcBlock
,
&
pItem
->
tuplePos
);
saveTupleData
(
pCtx
,
rowIndex
,
pSrcBlock
,
&
pItem
->
tuplePos
);
}
}
#ifdef BUF_PAGE_DEBUG
qDebug
(
"page_saveTuple i:%d, item:%p,pageId:%d, offset:%d
\n
"
,
pEntryInfo
->
numOfRes
,
pItem
,
pItem
->
tuplePos
.
pageId
,
pItem
->
tuplePos
.
offset
);
#endif
// allocate the buffer and keep the data of this row into the new allocated buffer
// allocate the buffer and keep the data of this row into the new allocated buffer
pEntryInfo
->
numOfRes
++
;
pEntryInfo
->
numOfRes
++
;
taosheapsort
((
void
*
)
pItems
,
sizeof
(
STopBotResItem
),
pEntryInfo
->
numOfRes
,
(
const
void
*
)
&
type
,
topBotResComparFn
,
taosheapsort
((
void
*
)
pItems
,
sizeof
(
STopBotResItem
),
pEntryInfo
->
numOfRes
,
(
const
void
*
)
&
type
,
topBotResComparFn
,
...
@@ -3229,7 +3231,9 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
...
@@ -3229,7 +3231,9 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
rowIndex
,
pSrcBlock
,
&
pItem
->
tuplePos
);
copyTupleData
(
pCtx
,
rowIndex
,
pSrcBlock
,
&
pItem
->
tuplePos
);
}
}
#ifdef BUF_PAGE_DEBUG
qDebug
(
"page_copyTuple pageId:%d, offset:%d"
,
pItem
->
tuplePos
.
pageId
,
pItem
->
tuplePos
.
offset
);
#endif
taosheapadjust
((
void
*
)
pItems
,
sizeof
(
STopBotResItem
),
0
,
pEntryInfo
->
numOfRes
-
1
,
(
const
void
*
)
&
type
,
taosheapadjust
((
void
*
)
pItems
,
sizeof
(
STopBotResItem
),
0
,
pEntryInfo
->
numOfRes
-
1
,
(
const
void
*
)
&
type
,
topBotResComparFn
,
NULL
,
!
isTopQuery
);
topBotResComparFn
,
NULL
,
!
isTopQuery
);
}
}
...
@@ -3239,7 +3243,11 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
...
@@ -3239,7 +3243,11 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
void
saveTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
STuplePos
*
pPos
)
{
void
saveTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
STuplePos
*
pPos
)
{
SFilePage
*
pPage
=
NULL
;
SFilePage
*
pPage
=
NULL
;
int32_t
completeRowSize
=
pSrcBlock
->
info
.
rowSize
+
(
int32_t
)
taosArrayGetSize
(
pSrcBlock
->
pDataBlock
)
*
sizeof
(
bool
);
int32_t
completeRowSize
=
pCtx
->
subsidiaries
.
num
*
sizeof
(
bool
);
for
(
int32_t
j
=
0
;
j
<
pCtx
->
subsidiaries
.
num
;
++
j
)
{
SqlFunctionCtx
*
pc
=
pCtx
->
subsidiaries
.
pCtx
[
j
];
completeRowSize
+=
pc
->
pExpr
->
base
.
resSchema
.
bytes
;
}
if
(
pCtx
->
curBufPage
==
-
1
)
{
if
(
pCtx
->
curBufPage
==
-
1
)
{
pPage
=
getNewBufPage
(
pCtx
->
pBuf
,
0
,
&
pCtx
->
curBufPage
);
pPage
=
getNewBufPage
(
pCtx
->
pBuf
,
0
,
&
pCtx
->
curBufPage
);
...
@@ -3257,19 +3265,22 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
...
@@ -3257,19 +3265,22 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
// keep the current row data, extract method
// keep the current row data, extract method
int32_t
offset
=
0
;
int32_t
offset
=
0
;
bool
*
nullList
=
(
bool
*
)((
char
*
)
pPage
+
pPage
->
num
);
bool
*
nullList
=
(
bool
*
)((
char
*
)
pPage
+
pPage
->
num
);
char
*
pStart
=
(
char
*
)(
nullList
+
sizeof
(
bool
)
*
(
int32_t
)
taosArrayGetSize
(
pSrcBlock
->
pDataBlock
));
char
*
pStart
=
(
char
*
)(
nullList
+
sizeof
(
bool
)
*
pCtx
->
subsidiaries
.
num
);
for
(
int32_t
i
=
0
;
i
<
(
int32_t
)
taosArrayGetSize
(
pSrcBlock
->
pDataBlock
);
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pCtx
->
subsidiaries
.
num
;
++
i
)
{
SColumnInfoData
*
pCol
=
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
i
);
SqlFunctionCtx
*
pc
=
pCtx
->
subsidiaries
.
pCtx
[
i
];
bool
isNull
=
colDataIsNull_s
(
pCol
,
rowIndex
);
if
(
isNull
)
{
SFunctParam
*
pFuncParam
=
&
pc
->
pExpr
->
base
.
pParam
[
0
];
nullList
[
i
]
=
true
;
int32_t
srcSlotId
=
pFuncParam
->
pCol
->
slotId
;
SColumnInfoData
*
pCol
=
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
srcSlotId
);
if
((
nullList
[
i
]
=
colDataIsNull_s
(
pCol
,
rowIndex
))
==
true
)
{
offset
+=
pCol
->
info
.
bytes
;
offset
+=
pCol
->
info
.
bytes
;
continue
;
continue
;
}
}
char
*
p
=
colDataGetData
(
pCol
,
rowIndex
);
char
*
p
=
colDataGetData
(
pCol
,
rowIndex
);
if
(
IS_VAR_DATA_TYPE
(
pCol
->
info
.
type
))
{
if
(
IS_VAR_DATA_TYPE
(
pCol
->
info
.
type
))
{
memcpy
(
pStart
+
offset
,
p
,
varDataTLen
(
p
));
memcpy
(
pStart
+
offset
,
p
,
(
pCol
->
info
.
type
==
TSDB_DATA_TYPE_JSON
)
?
getJsonValueLen
(
p
)
:
varDataTLen
(
p
));
}
else
{
}
else
{
memcpy
(
pStart
+
offset
,
p
,
pCol
->
info
.
bytes
);
memcpy
(
pStart
+
offset
,
p
,
pCol
->
info
.
bytes
);
}
}
...
@@ -3287,14 +3298,18 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
...
@@ -3287,14 +3298,18 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
void
copyTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
STuplePos
*
pPos
)
{
void
copyTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
STuplePos
*
pPos
)
{
SFilePage
*
pPage
=
getBufPage
(
pCtx
->
pBuf
,
pPos
->
pageId
);
SFilePage
*
pPage
=
getBufPage
(
pCtx
->
pBuf
,
pPos
->
pageId
);
int32_t
numOfCols
=
taosArrayGetSize
(
pSrcBlock
->
pDataBlock
)
;
int32_t
numOfCols
=
pCtx
->
subsidiaries
.
num
;
bool
*
nullList
=
(
bool
*
)((
char
*
)
pPage
+
pPos
->
offset
);
bool
*
nullList
=
(
bool
*
)((
char
*
)
pPage
+
pPos
->
offset
);
char
*
pStart
=
(
char
*
)(
nullList
+
numOfCols
*
sizeof
(
bool
));
char
*
pStart
=
(
char
*
)(
nullList
+
numOfCols
*
sizeof
(
bool
));
int32_t
offset
=
0
;
int32_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pCol
=
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
i
);
SqlFunctionCtx
*
pc
=
pCtx
->
subsidiaries
.
pCtx
[
i
];
SFunctParam
*
pFuncParam
=
&
pc
->
pExpr
->
base
.
pParam
[
0
];
int32_t
srcSlotId
=
pFuncParam
->
pCol
->
slotId
;
SColumnInfoData
*
pCol
=
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
srcSlotId
);
if
((
nullList
[
i
]
=
colDataIsNull_s
(
pCol
,
rowIndex
))
==
true
)
{
if
((
nullList
[
i
]
=
colDataIsNull_s
(
pCol
,
rowIndex
))
==
true
)
{
offset
+=
pCol
->
info
.
bytes
;
offset
+=
pCol
->
info
.
bytes
;
continue
;
continue
;
...
@@ -3302,7 +3317,7 @@ void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
...
@@ -3302,7 +3317,7 @@ void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
char
*
p
=
colDataGetData
(
pCol
,
rowIndex
);
char
*
p
=
colDataGetData
(
pCol
,
rowIndex
);
if
(
IS_VAR_DATA_TYPE
(
pCol
->
info
.
type
))
{
if
(
IS_VAR_DATA_TYPE
(
pCol
->
info
.
type
))
{
memcpy
(
pStart
+
offset
,
p
,
varDataTLen
(
p
));
memcpy
(
pStart
+
offset
,
p
,
(
pCol
->
info
.
type
==
TSDB_DATA_TYPE_JSON
)
?
getJsonValueLen
(
p
)
:
varDataTLen
(
p
));
}
else
{
}
else
{
memcpy
(
pStart
+
offset
,
p
,
pCol
->
info
.
bytes
);
memcpy
(
pStart
+
offset
,
p
,
pCol
->
info
.
bytes
);
}
}
...
@@ -3316,7 +3331,7 @@ void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
...
@@ -3316,7 +3331,7 @@ void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
int32_t
topBotFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
int32_t
topBotFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SResultRowEntryInfo
*
pEntryInfo
=
GET_RES_INFO
(
pCtx
);
SResultRowEntryInfo
*
pEntryInfo
=
GET_RES_INFO
(
pCtx
);
STopBotRes
*
pRes
=
GET_ROWCELL_INTERBUF
(
pEntryInfo
);
STopBotRes
*
pRes
=
getTopBotOutputInfo
(
pCtx
);
int16_t
type
=
pCtx
->
input
.
pData
[
0
]
->
info
.
type
;
int16_t
type
=
pCtx
->
input
.
pData
[
0
]
->
info
.
type
;
int32_t
slotId
=
pCtx
->
pExpr
->
base
.
resSchema
.
slotId
;
int32_t
slotId
=
pCtx
->
pExpr
->
base
.
resSchema
.
slotId
;
...
@@ -3333,7 +3348,9 @@ int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
...
@@ -3333,7 +3348,9 @@ int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
}
else
{
}
else
{
colDataAppend
(
pCol
,
currentRow
,
(
const
char
*
)
&
pItem
->
v
.
i
,
false
);
colDataAppend
(
pCol
,
currentRow
,
(
const
char
*
)
&
pItem
->
v
.
i
,
false
);
}
}
#ifdef BUF_PAGE_DEBUG
qDebug
(
"page_finalize i:%d,item:%p,pageId:%d, offset:%d
\n
"
,
i
,
pItem
,
pItem
->
tuplePos
.
pageId
,
pItem
->
tuplePos
.
offset
);
#endif
setSelectivityValue
(
pCtx
,
pBlock
,
&
pRes
->
pItems
[
i
].
tuplePos
,
currentRow
);
setSelectivityValue
(
pCtx
,
pBlock
,
&
pRes
->
pItems
[
i
].
tuplePos
,
currentRow
);
currentRow
+=
1
;
currentRow
+=
1
;
}
}
...
@@ -5629,8 +5646,6 @@ int32_t groupKeyFunction(SqlFunctionCtx* pCtx) {
...
@@ -5629,8 +5646,6 @@ int32_t groupKeyFunction(SqlFunctionCtx* pCtx) {
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pInputCol
=
pInput
->
pData
[
0
];
SColumnInfoData
*
pInputCol
=
pInput
->
pData
[
0
];
int32_t
bytes
=
pInputCol
->
info
.
bytes
;
int32_t
startIndex
=
pInput
->
startRowIndex
;
int32_t
startIndex
=
pInput
->
startRowIndex
;
//escape rest of data blocks to avoid first entry to be overwritten.
//escape rest of data blocks to avoid first entry to be overwritten.
...
@@ -5645,7 +5660,11 @@ int32_t groupKeyFunction(SqlFunctionCtx* pCtx) {
...
@@ -5645,7 +5660,11 @@ int32_t groupKeyFunction(SqlFunctionCtx* pCtx) {
}
}
char
*
data
=
colDataGetData
(
pInputCol
,
startIndex
);
char
*
data
=
colDataGetData
(
pInputCol
,
startIndex
);
memcpy
(
pInfo
->
data
,
data
,
bytes
);
if
(
IS_VAR_DATA_TYPE
(
pInputCol
->
info
.
type
))
{
memcpy
(
pInfo
->
data
,
data
,
(
pInputCol
->
info
.
type
==
TSDB_DATA_TYPE_JSON
)
?
getJsonValueLen
(
data
)
:
varDataTLen
(
data
));
}
else
{
memcpy
(
pInfo
->
data
,
data
,
pInputCol
->
info
.
bytes
);
}
pInfo
->
hasResult
=
true
;
pInfo
->
hasResult
=
true
;
_group_key_over:
_group_key_over:
...
...
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
0d41f9c8
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include "querynodes.h"
#include "querynodes.h"
#include "taos.h"
#include "taos.h"
#include "taoserror.h"
#include "taoserror.h"
#include "tdatablock.h"
#define COPY_SCALAR_FIELD(fldname) \
#define COPY_SCALAR_FIELD(fldname) \
do { \
do { \
...
@@ -164,7 +165,15 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) {
...
@@ -164,7 +165,15 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) {
memcpy
(
pDst
->
datum
.
p
,
pSrc
->
datum
.
p
,
len
);
memcpy
(
pDst
->
datum
.
p
,
pSrc
->
datum
.
p
,
len
);
break
;
break
;
}
}
case
TSDB_DATA_TYPE_JSON
:
case
TSDB_DATA_TYPE_JSON
:{
int32_t
len
=
getJsonValueLen
(
pSrc
->
datum
.
p
);
pDst
->
datum
.
p
=
taosMemoryCalloc
(
1
,
len
);
if
(
NULL
==
pDst
->
datum
.
p
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
memcpy
(
pDst
->
datum
.
p
,
pSrc
->
datum
.
p
,
len
);
break
;
}
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_BLOB
:
case
TSDB_DATA_TYPE_BLOB
:
case
TSDB_DATA_TYPE_MEDIUMBLOB
:
case
TSDB_DATA_TYPE_MEDIUMBLOB
:
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
0d41f9c8
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include "querynodes.h"
#include "querynodes.h"
#include "taoserror.h"
#include "taoserror.h"
#include "tjson.h"
#include "tjson.h"
#include "tdatablock.h"
static
int32_t
nodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
);
static
int32_t
nodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
);
static
int32_t
jsonToNode
(
const
SJson
*
pJson
,
void
*
pObj
);
static
int32_t
jsonToNode
(
const
SJson
*
pJson
,
void
*
pObj
);
...
@@ -2629,7 +2630,18 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) {
...
@@ -2629,7 +2630,18 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) {
case
TSDB_DATA_TYPE_VARBINARY
:
case
TSDB_DATA_TYPE_VARBINARY
:
code
=
tjsonAddStringToObject
(
pJson
,
jkValueDatum
,
varDataVal
(
pNode
->
datum
.
p
));
code
=
tjsonAddStringToObject
(
pJson
,
jkValueDatum
,
varDataVal
(
pNode
->
datum
.
p
));
break
;
break
;
case
TSDB_DATA_TYPE_JSON
:
case
TSDB_DATA_TYPE_JSON
:{
int32_t
len
=
getJsonValueLen
(
pNode
->
datum
.
p
);
char
*
buf
=
taosMemoryCalloc
(
len
*
2
+
1
,
sizeof
(
char
));
code
=
taosHexEncode
(
pNode
->
datum
.
p
,
buf
,
len
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
taosMemoryFree
(
buf
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
code
=
tjsonAddStringToObject
(
pJson
,
jkValueDatum
,
buf
);
taosMemoryFree
(
buf
);
break
;
}
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_BLOB
:
case
TSDB_DATA_TYPE_BLOB
:
// todo
// todo
...
@@ -2752,7 +2764,30 @@ static int32_t jsonToDatum(const SJson* pJson, void* pObj) {
...
@@ -2752,7 +2764,30 @@ static int32_t jsonToDatum(const SJson* pJson, void* pObj) {
}
}
break
;
break
;
}
}
case
TSDB_DATA_TYPE_JSON
:
case
TSDB_DATA_TYPE_JSON
:{
pNode
->
datum
.
p
=
taosMemoryCalloc
(
1
,
pNode
->
node
.
resType
.
bytes
);
if
(
NULL
==
pNode
->
datum
.
p
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
break
;
}
char
*
buf
=
taosMemoryCalloc
(
1
,
pNode
->
node
.
resType
.
bytes
*
2
+
1
);
if
(
NULL
==
buf
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
break
;
}
code
=
tjsonGetStringValue
(
pJson
,
jkValueDatum
,
buf
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
taosMemoryFree
(
buf
);
break
;
}
code
=
taosHexDecode
(
buf
,
pNode
->
datum
.
p
,
pNode
->
node
.
resType
.
bytes
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
taosMemoryFree
(
buf
);
break
;
}
taosMemoryFree
(
buf
);
break
;
}
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_BLOB
:
case
TSDB_DATA_TYPE_BLOB
:
// todo
// todo
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
0d41f9c8
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include "taos.h"
#include "taos.h"
#include "taoserror.h"
#include "taoserror.h"
#include "thash.h"
#include "thash.h"
#include "tdatablock.h"
static
SNode
*
makeNode
(
ENodeType
type
,
size_t
size
)
{
static
SNode
*
makeNode
(
ENodeType
type
,
size_t
size
)
{
SNode
*
p
=
taosMemoryCalloc
(
1
,
size
);
SNode
*
p
=
taosMemoryCalloc
(
1
,
size
);
...
@@ -1675,6 +1676,10 @@ void nodesValueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
...
@@ -1675,6 +1676,10 @@ void nodesValueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
pVal
->
pz
[
pVal
->
nLen
+
VARSTR_HEADER_SIZE
]
=
0
;
pVal
->
pz
[
pVal
->
nLen
+
VARSTR_HEADER_SIZE
]
=
0
;
break
;
break
;
case
TSDB_DATA_TYPE_JSON
:
case
TSDB_DATA_TYPE_JSON
:
pVal
->
nLen
=
getJsonValueLen
(
pNode
->
datum
.
p
);
pVal
->
pz
=
taosMemoryMalloc
(
pVal
->
nLen
);
memcpy
(
pVal
->
pz
,
pNode
->
datum
.
p
,
pVal
->
nLen
);
break
;
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_BLOB
:
case
TSDB_DATA_TYPE_BLOB
:
// todo
// todo
...
...
source/libs/parser/inc/parUtil.h
浏览文件 @
0d41f9c8
...
@@ -62,7 +62,6 @@ int32_t getNumOfColumns(const STableMeta* pTableMeta);
...
@@ -62,7 +62,6 @@ int32_t getNumOfColumns(const STableMeta* pTableMeta);
int32_t
getNumOfTags
(
const
STableMeta
*
pTableMeta
);
int32_t
getNumOfTags
(
const
STableMeta
*
pTableMeta
);
STableComInfo
getTableInfo
(
const
STableMeta
*
pTableMeta
);
STableComInfo
getTableInfo
(
const
STableMeta
*
pTableMeta
);
STableMeta
*
tableMetaDup
(
const
STableMeta
*
pTableMeta
);
STableMeta
*
tableMetaDup
(
const
STableMeta
*
pTableMeta
);
int32_t
parseJsontoTagData
(
const
char
*
json
,
SArray
*
pTagVals
,
STag
**
ppTag
,
SMsgBuf
*
pMsgBuf
);
int32_t
trimString
(
const
char
*
src
,
int32_t
len
,
char
*
dst
,
int32_t
dlen
);
int32_t
trimString
(
const
char
*
src
,
int32_t
len
,
char
*
dst
,
int32_t
dlen
);
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
0d41f9c8
...
@@ -219,6 +219,7 @@ int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) {
...
@@ -219,6 +219,7 @@ int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) {
}
}
int32_t
buildSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
)
{
int32_t
buildSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
)
{
if
(
pBuf
==
NULL
)
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
const
char
*
msgFormat1
=
"syntax error near
\'
%s
\'
"
;
const
char
*
msgFormat1
=
"syntax error near
\'
%s
\'
"
;
const
char
*
msgFormat2
=
"syntax error near
\'
%s
\'
(%s)"
;
const
char
*
msgFormat2
=
"syntax error near
\'
%s
\'
(%s)"
;
const
char
*
msgFormat3
=
"%s"
;
const
char
*
msgFormat3
=
"%s"
;
...
@@ -346,7 +347,7 @@ static bool isValidateTag(char* input) {
...
@@ -346,7 +347,7 @@ static bool isValidateTag(char* input) {
return
true
;
return
true
;
}
}
int32_t
parseJsontoTagData
(
const
char
*
json
,
SArray
*
pTagVals
,
STag
**
ppTag
,
SMsgBuf
*
pMsgBuf
)
{
int32_t
parseJsontoTagData
(
const
char
*
json
,
SArray
*
pTagVals
,
STag
**
ppTag
,
void
*
pMsgBuf
)
{
int32_t
retCode
=
TSDB_CODE_SUCCESS
;
int32_t
retCode
=
TSDB_CODE_SUCCESS
;
cJSON
*
root
=
NULL
;
cJSON
*
root
=
NULL
;
SHashObj
*
keyHash
=
NULL
;
SHashObj
*
keyHash
=
NULL
;
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
0d41f9c8
...
@@ -476,10 +476,16 @@ static int32_t pushDownCondOptPushCondToScan(SOptimizeContext* pCxt, SScanLogicN
...
@@ -476,10 +476,16 @@ static int32_t pushDownCondOptPushCondToScan(SOptimizeContext* pCxt, SScanLogicN
return
pushDownCondOptAppendCond
(
&
pScan
->
node
.
pConditions
,
pCond
);
return
pushDownCondOptAppendCond
(
&
pScan
->
node
.
pConditions
,
pCond
);
}
}
static
int32_t
pushDownCondOptPushCondToProject
(
SOptimizeContext
*
pCxt
,
SProjectLogicNode
*
pProject
,
SNode
**
pCond
)
{
return
pushDownCondOptAppendCond
(
&
pProject
->
node
.
pConditions
,
pCond
);
}
static
int32_t
pushDownCondOptPushCondToChild
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pChild
,
SNode
**
pCond
)
{
static
int32_t
pushDownCondOptPushCondToChild
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pChild
,
SNode
**
pCond
)
{
switch
(
nodeType
(
pChild
))
{
switch
(
nodeType
(
pChild
))
{
case
QUERY_NODE_LOGIC_PLAN_SCAN
:
case
QUERY_NODE_LOGIC_PLAN_SCAN
:
return
pushDownCondOptPushCondToScan
(
pCxt
,
(
SScanLogicNode
*
)
pChild
,
pCond
);
return
pushDownCondOptPushCondToScan
(
pCxt
,
(
SScanLogicNode
*
)
pChild
,
pCond
);
case
QUERY_NODE_LOGIC_PLAN_PROJECT
:
return
pushDownCondOptPushCondToProject
(
pCxt
,
(
SProjectLogicNode
*
)
pChild
,
pCond
);
default:
default:
break
;
break
;
}
}
...
@@ -713,7 +719,8 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
...
@@ -713,7 +719,8 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
}
}
//TODO: remove it after full implementation of pushing down to child
//TODO: remove it after full implementation of pushing down to child
if
(
1
!=
LIST_LENGTH
(
pAgg
->
node
.
pChildren
)
||
if
(
1
!=
LIST_LENGTH
(
pAgg
->
node
.
pChildren
)
||
QUERY_NODE_LOGIC_PLAN_SCAN
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
)))
{
QUERY_NODE_LOGIC_PLAN_SCAN
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
))
&&
QUERY_NODE_LOGIC_PLAN_PROJECT
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
)))
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
...
source/libs/qcom/src/queryUtil.c
浏览文件 @
0d41f9c8
...
@@ -305,18 +305,21 @@ int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t
...
@@ -305,18 +305,21 @@ int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t
char
*
parseTagDatatoJson
(
void
*
p
)
{
char
*
parseTagDatatoJson
(
void
*
p
)
{
char
*
string
=
NULL
;
char
*
string
=
NULL
;
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
end
;
}
SArray
*
pTagVals
=
NULL
;
SArray
*
pTagVals
=
NULL
;
cJSON
*
json
=
NULL
;
if
(
tTagToValArray
((
const
STag
*
)
p
,
&
pTagVals
)
!=
0
)
{
if
(
tTagToValArray
((
const
STag
*
)
p
,
&
pTagVals
)
!=
0
)
{
goto
end
;
goto
end
;
}
}
int16_t
nCols
=
taosArrayGetSize
(
pTagVals
);
int16_t
nCols
=
taosArrayGetSize
(
pTagVals
);
if
(
nCols
==
0
)
{
goto
end
;
}
char
tagJsonKey
[
256
]
=
{
0
};
char
tagJsonKey
[
256
]
=
{
0
};
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
end
;
}
for
(
int
j
=
0
;
j
<
nCols
;
++
j
)
{
for
(
int
j
=
0
;
j
<
nCols
;
++
j
)
{
STagVal
*
pTagVal
=
(
STagVal
*
)
taosArrayGet
(
pTagVals
,
j
);
STagVal
*
pTagVal
=
(
STagVal
*
)
taosArrayGet
(
pTagVals
,
j
);
// json key encode by binary
// json key encode by binary
...
@@ -374,6 +377,10 @@ char* parseTagDatatoJson(void* p) {
...
@@ -374,6 +377,10 @@ char* parseTagDatatoJson(void* p) {
string
=
cJSON_PrintUnformatted
(
json
);
string
=
cJSON_PrintUnformatted
(
json
);
end:
end:
cJSON_Delete
(
json
);
cJSON_Delete
(
json
);
taosArrayDestroy
(
pTagVals
);
if
(
string
==
NULL
){
string
=
strdup
(
TSDB_DATA_NULL_STR_L
);
}
return
string
;
return
string
;
}
}
...
...
source/libs/scalar/src/filter.c
浏览文件 @
0d41f9c8
...
@@ -192,6 +192,9 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
...
@@ -192,6 +192,9 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
case
TSDB_DATA_TYPE_DOUBLE
:
case
TSDB_DATA_TYPE_DOUBLE
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
return
18
;
return
18
;
case
TSDB_DATA_TYPE_JSON
:
terrno
=
TSDB_CODE_QRY_JSON_IN_ERROR
;
return
0
;
default:
default:
assert
(
0
);
assert
(
0
);
}
}
...
@@ -215,6 +218,9 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
...
@@ -215,6 +218,9 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
case
TSDB_DATA_TYPE_DOUBLE
:
case
TSDB_DATA_TYPE_DOUBLE
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
return
24
;
return
24
;
case
TSDB_DATA_TYPE_JSON
:
terrno
=
TSDB_CODE_QRY_JSON_IN_ERROR
;
return
0
;
default:
default:
assert
(
0
);
assert
(
0
);
}
}
...
...
source/libs/scalar/src/scalar.c
浏览文件 @
0d41f9c8
...
@@ -551,7 +551,9 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp
...
@@ -551,7 +551,9 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp
SScalarParam
*
pLeft
=
&
params
[
0
];
SScalarParam
*
pLeft
=
&
params
[
0
];
SScalarParam
*
pRight
=
paramNum
>
1
?
&
params
[
1
]
:
NULL
;
SScalarParam
*
pRight
=
paramNum
>
1
?
&
params
[
1
]
:
NULL
;
terrno
=
TSDB_CODE_SUCCESS
;
OperatorFn
(
pLeft
,
pRight
,
output
,
TSDB_ORDER_ASC
);
OperatorFn
(
pLeft
,
pRight
,
output
,
TSDB_ORDER_ASC
);
code
=
terrno
;
_return:
_return:
for
(
int32_t
i
=
0
;
i
<
paramNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
paramNum
;
++
i
)
{
...
@@ -693,7 +695,11 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
...
@@ -693,7 +695,11 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
res
->
node
.
resType
.
scale
=
output
.
columnData
->
info
.
scale
;
res
->
node
.
resType
.
scale
=
output
.
columnData
->
info
.
scale
;
res
->
node
.
resType
.
precision
=
output
.
columnData
->
info
.
precision
;
res
->
node
.
resType
.
precision
=
output
.
columnData
->
info
.
precision
;
int32_t
type
=
output
.
columnData
->
info
.
type
;
int32_t
type
=
output
.
columnData
->
info
.
type
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
if
(
type
==
TSDB_DATA_TYPE_JSON
){
int32_t
len
=
getJsonValueLen
(
output
.
columnData
->
pData
);
res
->
datum
.
p
=
taosMemoryCalloc
(
len
,
1
);
memcpy
(
res
->
datum
.
p
,
output
.
columnData
->
pData
,
len
);
}
else
if
(
IS_VAR_DATA_TYPE
(
type
))
{
res
->
datum
.
p
=
taosMemoryCalloc
(
res
->
node
.
resType
.
bytes
+
VARSTR_HEADER_SIZE
+
1
,
1
);
res
->
datum
.
p
=
taosMemoryCalloc
(
res
->
node
.
resType
.
bytes
+
VARSTR_HEADER_SIZE
+
1
,
1
);
memcpy
(
res
->
datum
.
p
,
output
.
columnData
->
pData
,
varDataTLen
(
output
.
columnData
->
pData
));
memcpy
(
res
->
datum
.
p
,
output
.
columnData
->
pData
,
varDataTLen
(
output
.
columnData
->
pData
));
}
else
{
}
else
{
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
0d41f9c8
...
@@ -1152,42 +1152,30 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
...
@@ -1152,42 +1152,30 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
char
tmp
[
TSDB_MAX_JSON_TAG_LEN
]
=
{
0
};
char
tmp
[
TSDB_MAX_JSON_TAG_LEN
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInput
[
0
].
columnData
,
i
))
{
SArray
*
pTagVals
=
taosArrayInit
(
8
,
sizeof
(
STagVal
));
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
STag
*
pTag
=
NULL
;
continue
;
}
char
*
input
=
pInput
[
0
].
columnData
->
pData
+
pInput
[
0
].
columnData
->
varmeta
.
offset
[
i
];
if
(
type
==
TSDB_DATA_TYPE_NCHAR
){
if
(
colDataIsNull_s
(
pInput
[
0
].
columnData
,
i
))
{
if
(
varDataTLen
(
input
)
>
TSDB_MAX_JSON_TAG_LEN
){
tTagNew
(
pTagVals
,
1
,
true
,
&
pTag
);
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
int32_t
len
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
input
),
varDataLen
(
input
),
tmp
);
if
(
len
<
0
)
{
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
tmp
[
len
]
=
0
;
}
else
{
}
else
{
char
*
input
=
pInput
[
0
].
columnData
->
pData
+
pInput
[
0
].
columnData
->
varmeta
.
offset
[
i
];
if
(
varDataLen
(
input
)
>
(
TSDB_MAX_JSON_TAG_LEN
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
){
if
(
varDataLen
(
input
)
>
(
TSDB_MAX_JSON_TAG_LEN
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
){
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
taosArrayDestroy
(
pTagVals
);
continue
;
return
TSDB_CODE_FAILED
;
}
}
memcpy
(
tmp
,
varDataVal
(
input
),
varDataLen
(
input
));
memcpy
(
tmp
,
varDataVal
(
input
),
varDataLen
(
input
));
tmp
[
varDataLen
(
input
)]
=
0
;
tmp
[
varDataLen
(
input
)]
=
0
;
if
(
parseJsontoTagData
(
tmp
,
pTagVals
,
&
pTag
,
NULL
)){
tTagNew
(
pTagVals
,
1
,
true
,
&
pTag
);
}
}
}
if
(
!
tjsonValidateJson
(
tmp
)){
colDataAppend
(
pOutput
->
columnData
,
i
,
(
const
char
*
)
pTag
,
false
);
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
tTagFree
(
pTag
);
continue
;
taosArrayDestroy
(
pTagVals
);
}
colDataAppend
(
pOutput
->
columnData
,
i
,
input
,
false
);
}
}
pOutput
->
numOfRows
=
pInput
->
numOfRows
;
pOutput
->
numOfRows
=
pInput
->
numOfRows
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
...
source/libs/scalar/src/sclvector.c
浏览文件 @
0d41f9c8
...
@@ -160,6 +160,9 @@ int64_t getVectorBigintValue_JSON(void *src, int32_t index){
...
@@ -160,6 +160,9 @@ int64_t getVectorBigintValue_JSON(void *src, int32_t index){
return
0
;
return
0
;
}
else
if
(
*
data
==
TSDB_DATA_TYPE_NCHAR
)
{
// json inner type can not be BINARY
}
else
if
(
*
data
==
TSDB_DATA_TYPE_NCHAR
)
{
// json inner type can not be BINARY
convertNcharToDouble
(
data
+
CHAR_BYTES
,
&
out
);
convertNcharToDouble
(
data
+
CHAR_BYTES
,
&
out
);
}
else
if
(
tTagIsJson
(
data
)){
terrno
=
TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR
;
return
0
;
}
else
{
}
else
{
convertNumberToNumber
(
data
+
CHAR_BYTES
,
&
out
,
*
data
,
TSDB_DATA_TYPE_DOUBLE
);
convertNumberToNumber
(
data
+
CHAR_BYTES
,
&
out
,
*
data
,
TSDB_DATA_TYPE_DOUBLE
);
}
}
...
@@ -416,6 +419,9 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
...
@@ -416,6 +419,9 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
else
if
(
*
data
==
TSDB_DATA_TYPE_NCHAR
)
{
else
if
(
*
data
==
TSDB_DATA_TYPE_NCHAR
)
{
data
+=
CHAR_BYTES
;
data
+=
CHAR_BYTES
;
convertType
=
TSDB_DATA_TYPE_NCHAR
;
convertType
=
TSDB_DATA_TYPE_NCHAR
;
}
else
if
(
tTagIsJson
(
data
)){
terrno
=
TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR
;
return
terrno
;
}
else
{
}
else
{
convertNumberToNumber
(
data
+
CHAR_BYTES
,
colDataGetNumData
(
pOut
->
columnData
,
i
),
*
data
,
outType
);
convertNumberToNumber
(
data
+
CHAR_BYTES
,
colDataGetNumData
(
pOut
->
columnData
,
i
),
*
data
,
outType
);
continue
;
continue
;
...
@@ -461,7 +467,10 @@ double getVectorDoubleValue_JSON(void *src, int32_t index){
...
@@ -461,7 +467,10 @@ double getVectorDoubleValue_JSON(void *src, int32_t index){
return
out
;
return
out
;
}
else
if
(
*
data
==
TSDB_DATA_TYPE_NCHAR
)
{
// json inner type can not be BINARY
}
else
if
(
*
data
==
TSDB_DATA_TYPE_NCHAR
)
{
// json inner type can not be BINARY
convertNcharToDouble
(
data
+
CHAR_BYTES
,
&
out
);
convertNcharToDouble
(
data
+
CHAR_BYTES
,
&
out
);
}
else
{
}
else
if
(
tTagIsJson
(
data
)){
terrno
=
TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR
;
return
0
;
}
else
{
convertNumberToNumber
(
data
+
CHAR_BYTES
,
&
out
,
*
data
,
TSDB_DATA_TYPE_DOUBLE
);
convertNumberToNumber
(
data
+
CHAR_BYTES
,
&
out
,
*
data
,
TSDB_DATA_TYPE_DOUBLE
);
}
}
return
out
;
return
out
;
...
@@ -493,10 +502,18 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
...
@@ -493,10 +502,18 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
}
}
if
(
typeLeft
==
TSDB_DATA_TYPE_JSON
){
if
(
typeLeft
==
TSDB_DATA_TYPE_JSON
){
if
(
tTagIsJson
(
*
pLeftData
)){
terrno
=
TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR
;
return
false
;
}
typeLeft
=
**
pLeftData
;
typeLeft
=
**
pLeftData
;
(
*
pLeftData
)
++
;
(
*
pLeftData
)
++
;
}
}
if
(
typeRight
==
TSDB_DATA_TYPE_JSON
){
if
(
typeRight
==
TSDB_DATA_TYPE_JSON
){
if
(
tTagIsJson
(
*
pLeftData
)){
terrno
=
TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR
;
return
false
;
}
typeRight
=
**
pRightData
;
typeRight
=
**
pRightData
;
(
*
pRightData
)
++
;
(
*
pRightData
)
++
;
}
}
...
@@ -1576,7 +1593,11 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
...
@@ -1576,7 +1593,11 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
void
vectorCompareImpl
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
,
int32_t
optr
)
{
void
vectorCompareImpl
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
,
int32_t
optr
)
{
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
numOfRows
,
pRight
->
numOfRows
)
-
1
;
int32_t
i
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
0
:
TMAX
(
pLeft
->
numOfRows
,
pRight
->
numOfRows
)
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
int32_t
step
=
((
_ord
)
==
TSDB_ORDER_ASC
)
?
1
:
-
1
;
__compar_fn_t
fp
=
filterGetCompFunc
(
GET_PARAM_TYPE
(
pLeft
),
optr
);
__compar_fn_t
fp
=
filterGetCompFunc
(
GET_PARAM_TYPE
(
pLeft
),
optr
);
if
(
terrno
!=
TSDB_CODE_SUCCESS
){
return
;
}
pOut
->
numOfRows
=
TMAX
(
pLeft
->
numOfRows
,
pRight
->
numOfRows
);
pOut
->
numOfRows
=
TMAX
(
pLeft
->
numOfRows
,
pRight
->
numOfRows
);
...
@@ -1709,6 +1730,7 @@ void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
...
@@ -1709,6 +1730,7 @@ void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
STagVal
getJsonValue
(
char
*
json
,
char
*
key
,
bool
*
isExist
)
{
STagVal
getJsonValue
(
char
*
json
,
char
*
key
,
bool
*
isExist
)
{
STagVal
val
=
{.
pKey
=
key
};
STagVal
val
=
{.
pKey
=
key
};
if
(
tTagIsJson
((
const
STag
*
)
json
)
==
false
){
if
(
tTagIsJson
((
const
STag
*
)
json
)
==
false
){
terrno
=
TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR
;
if
(
isExist
){
if
(
isExist
){
*
isExist
=
false
;
*
isExist
=
false
;
}
}
...
...
source/libs/stream/src/streamData.c
浏览文件 @
0d41f9c8
...
@@ -88,3 +88,12 @@ SStreamDataSubmit* streamSubmitRefClone(SStreamDataSubmit* pSubmit) {
...
@@ -88,3 +88,12 @@ SStreamDataSubmit* streamSubmitRefClone(SStreamDataSubmit* pSubmit) {
memcpy
(
pSubmitClone
,
pSubmit
,
sizeof
(
SStreamDataSubmit
));
memcpy
(
pSubmitClone
,
pSubmit
,
sizeof
(
SStreamDataSubmit
));
return
pSubmitClone
;
return
pSubmitClone
;
}
}
void
streamDataSubmitRefDec
(
SStreamDataSubmit
*
pDataSubmit
)
{
int32_t
ref
=
atomic_sub_fetch_32
(
pDataSubmit
->
dataRef
,
1
);
ASSERT
(
ref
>=
0
);
if
(
ref
==
0
)
{
taosMemoryFree
(
pDataSubmit
->
data
);
taosMemoryFree
(
pDataSubmit
->
dataRef
);
}
}
source/libs/stream/src/streamExec.c
浏览文件 @
0d41f9c8
...
@@ -63,7 +63,6 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes)
...
@@ -63,7 +63,6 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes)
continue
;
continue
;
}
}
// TODO: do we need free memory?
SSDataBlock
block
=
{
0
};
SSDataBlock
block
=
{
0
};
assignOneDataBlock
(
&
block
,
output
);
assignOneDataBlock
(
&
block
,
output
);
block
.
info
.
childId
=
pTask
->
selfChildId
;
block
.
info
.
childId
=
pTask
->
selfChildId
;
...
...
source/libs/stream/src/streamQueue.c
浏览文件 @
0d41f9c8
...
@@ -41,12 +41,3 @@ void streamQueueClose(SStreamQueue* queue) {
...
@@ -41,12 +41,3 @@ void streamQueueClose(SStreamQueue* queue) {
return
;
return
;
}
}
}
}
void
streamDataSubmitRefDec
(
SStreamDataSubmit
*
pDataSubmit
)
{
int32_t
ref
=
atomic_sub_fetch_32
(
pDataSubmit
->
dataRef
,
1
);
ASSERT
(
ref
>=
0
);
if
(
ref
==
0
)
{
taosMemoryFree
(
pDataSubmit
->
data
);
taosMemoryFree
(
pDataSubmit
->
dataRef
);
}
}
source/libs/sync/inc/syncAppendEntries.h
浏览文件 @
0d41f9c8
...
@@ -94,6 +94,7 @@ extern "C" {
...
@@ -94,6 +94,7 @@ extern "C" {
//
//
int32_t
syncNodeOnAppendEntriesCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeOnAppendEntriesCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeOnAppendEntriesSnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeOnAppendEntriesSnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeOnAppendEntriesSnapshot2Cb
(
SSyncNode
*
ths
,
SyncAppendEntriesBatch
*
pMsg
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/libs/sync/inc/syncAppendEntriesReply.h
浏览文件 @
0d41f9c8
...
@@ -42,6 +42,12 @@ extern "C" {
...
@@ -42,6 +42,12 @@ extern "C" {
//
//
int32_t
syncNodeOnAppendEntriesReplyCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReplyCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReplySnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReplySnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReplySnapshot2Cb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
typedef
struct
SReaderParam
{
SyncIndex
start
;
SyncIndex
end
;
}
SReaderParam
;
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
0d41f9c8
...
@@ -67,6 +67,7 @@ typedef struct SSyncNode {
...
@@ -67,6 +67,7 @@ typedef struct SSyncNode {
char
path
[
TSDB_FILENAME_LEN
];
char
path
[
TSDB_FILENAME_LEN
];
char
raftStorePath
[
TSDB_FILENAME_LEN
*
2
];
char
raftStorePath
[
TSDB_FILENAME_LEN
*
2
];
char
configPath
[
TSDB_FILENAME_LEN
*
2
];
char
configPath
[
TSDB_FILENAME_LEN
*
2
];
int32_t
batchSize
;
// sync io
// sync io
SWal
*
pWal
;
SWal
*
pWal
;
...
@@ -170,6 +171,7 @@ void syncNodeStart(SSyncNode* pSyncNode);
...
@@ -170,6 +171,7 @@ void syncNodeStart(SSyncNode* pSyncNode);
void
syncNodeStartStandBy
(
SSyncNode
*
pSyncNode
);
void
syncNodeStartStandBy
(
SSyncNode
*
pSyncNode
);
void
syncNodeClose
(
SSyncNode
*
pSyncNode
);
void
syncNodeClose
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodePropose
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
,
bool
isWeak
);
int32_t
syncNodePropose
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
,
bool
isWeak
);
int32_t
syncNodeProposeBatch
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsgArr
,
bool
*
pIsWeakArr
,
int32_t
arrSize
);
// option
// option
bool
syncNodeSnapshotEnable
(
SSyncNode
*
pSyncNode
);
bool
syncNodeSnapshotEnable
(
SSyncNode
*
pSyncNode
);
...
...
source/libs/sync/inc/syncReplication.h
浏览文件 @
0d41f9c8
...
@@ -53,8 +53,10 @@ extern "C" {
...
@@ -53,8 +53,10 @@ extern "C" {
//
//
int32_t
syncNodeAppendEntriesPeers
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeAppendEntriesPeers
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeAppendEntriesPeersSnapshot
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeAppendEntriesPeersSnapshot
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeAppendEntriesPeersSnapshot2
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeReplicate
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeReplicate
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeAppendEntries
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeAppendEntries
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncAppendEntries
*
pMsg
);
int32_t
syncNodeAppendEntriesBatch
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncAppendEntriesBatch
*
pMsg
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
0d41f9c8
...
@@ -40,8 +40,8 @@ typedef struct SSyncSnapshotSender {
...
@@ -40,8 +40,8 @@ typedef struct SSyncSnapshotSender {
bool
start
;
bool
start
;
int32_t
seq
;
int32_t
seq
;
int32_t
ack
;
int32_t
ack
;
void
*
pReader
;
void
*
pReader
;
void
*
pCurrentBlock
;
void
*
pCurrentBlock
;
int32_t
blockLen
;
int32_t
blockLen
;
SSnapshot
snapshot
;
SSnapshot
snapshot
;
SSyncCfg
lastConfig
;
SSyncCfg
lastConfig
;
...
@@ -62,14 +62,14 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender);
...
@@ -62,14 +62,14 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender);
int32_t
snapshotReSend
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotReSend
(
SSyncSnapshotSender
*
pSender
);
cJSON
*
snapshotSender2Json
(
SSyncSnapshotSender
*
pSender
);
cJSON
*
snapshotSender2Json
(
SSyncSnapshotSender
*
pSender
);
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
);
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
);
char
*
snapshotSender2SimpleStr
(
SSyncSnapshotSender
*
pSender
,
char
*
event
);
char
*
snapshotSender2SimpleStr
(
SSyncSnapshotSender
*
pSender
,
char
*
event
);
//---------------------------------------------------
//---------------------------------------------------
typedef
struct
SSyncSnapshotReceiver
{
typedef
struct
SSyncSnapshotReceiver
{
bool
start
;
bool
start
;
int32_t
ack
;
int32_t
ack
;
void
*
pWriter
;
void
*
pWriter
;
SyncTerm
term
;
SyncTerm
term
;
SyncTerm
privateTerm
;
SyncTerm
privateTerm
;
SSnapshot
snapshot
;
SSnapshot
snapshot
;
...
@@ -85,8 +85,8 @@ bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver);
...
@@ -85,8 +85,8 @@ bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver);
void
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
);
cJSON
*
snapshotReceiver2Json
(
SSyncSnapshotReceiver
*
pReceiver
);
cJSON
*
snapshotReceiver2Json
(
SSyncSnapshotReceiver
*
pReceiver
);
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
);
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
);
char
*
snapshotReceiver2SimpleStr
(
SSyncSnapshotReceiver
*
pReceiver
,
char
*
event
);
char
*
snapshotReceiver2SimpleStr
(
SSyncSnapshotReceiver
*
pReceiver
,
char
*
event
);
//---------------------------------------------------
//---------------------------------------------------
// on message
// on message
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
0d41f9c8
...
@@ -719,6 +719,8 @@ static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries
...
@@ -719,6 +719,8 @@ static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries
return
false
;
return
false
;
}
}
int32_t
syncNodeOnAppendEntriesSnapshot2Cb
(
SSyncNode
*
ths
,
SyncAppendEntriesBatch
*
pMsg
)
{
return
0
;
}
int32_t
syncNodeOnAppendEntriesSnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
int32_t
syncNodeOnAppendEntriesSnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
)
{
int32_t
ret
=
0
;
int32_t
ret
=
0
;
int32_t
code
=
0
;
int32_t
code
=
0
;
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
0d41f9c8
...
@@ -108,48 +108,82 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
...
@@ -108,48 +108,82 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
return
ret
;
return
ret
;
}
}
#if 0
// only start once
int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
static
void
syncNodeStartSnapshot
(
SSyncNode
*
ths
,
SyncIndex
beginIndex
,
SyncIndex
endIndex
,
SyncTerm
lastApplyTerm
,
SyncAppendEntriesReply
*
pMsg
)
{
// get sender
SSyncSnapshotSender
*
pSender
=
syncNodeGetSnapshotSender
(
ths
,
&
(
pMsg
->
srcId
));
ASSERT
(
pSender
!=
NULL
);
SSnapshot
snapshot
=
{
.
data
=
NULL
,
.
lastApplyIndex
=
endIndex
,
.
lastApplyTerm
=
lastApplyTerm
,
.
lastConfigIndex
=
SYNC_INDEX_INVALID
};
void
*
pReader
=
NULL
;
SReaderParam
readerParam
=
{.
start
=
beginIndex
,
.
end
=
endIndex
};
ths
->
pFsm
->
FpSnapshotStartRead
(
ths
->
pFsm
,
&
readerParam
,
&
pReader
);
if
(
!
snapshotSenderIsStart
(
pSender
)
&&
pMsg
->
privateTerm
<
pSender
->
privateTerm
)
{
ASSERT
(
pReader
!=
NULL
);
snapshotSenderStart
(
pSender
,
snapshot
,
pReader
);
}
else
{
if
(
pReader
!=
NULL
)
{
ths
->
pFsm
->
FpSnapshotStopRead
(
ths
->
pFsm
,
pReader
);
}
}
}
int32_t
syncNodeOnAppendEntriesReplySnapshot2Cb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
ret
=
0
;
int32_t
ret
=
0
;
char logBuf[128] = {0};
// if already drop replica, do not process
snprintf(logBuf, sizeof(logBuf), "==syncNodeOnAppendEntriesReplyCb== term:%lu", ths->pRaftStore->currentTerm);
if
(
!
syncNodeInRaftGroup
(
ths
,
&
(
pMsg
->
srcId
))
&&
!
ths
->
pRaftCfg
->
isStandBy
)
{
syncAppendEntriesReplyLog2(logBuf, pMsg);
syncNodeEventLog
(
ths
,
"recv sync-append-entries-reply, maybe replica already dropped"
);
return
-
1
;
}
// drop stale response
if
(
pMsg
->
term
<
ths
->
pRaftStore
->
currentTerm
)
{
if
(
pMsg
->
term
<
ths
->
pRaftStore
->
currentTerm
)
{
sTrace("DropStaleResponse, receive term:%" PRIu64 ", current term:%" PRIu64 "", pMsg->term,
char
logBuf
[
128
];
ths->pRaftStore->currentTerm);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv sync-append-entries-reply, recv-term:%lu, drop stale response"
,
pMsg
->
term
);
return ret;
syncNodeEventLog
(
ths
,
logBuf
);
return
-
1
;
}
}
syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== before pNextIndex", ths->pNextIndex);
// error term
syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== before pMatchIndex", ths->pMatchIndex);
// no need this code, because if I receive reply.term, then I must have sent for that term.
// if (pMsg->term > ths->pRaftStore->currentTerm) {
// syncNodeUpdateTerm(ths, pMsg->term);
// }
if
(
pMsg
->
term
>
ths
->
pRaftStore
->
currentTerm
)
{
if
(
pMsg
->
term
>
ths
->
pRaftStore
->
currentTerm
)
{
char logBuf[128] = {0};
char
logBuf
[
128
];
snprintf(logBuf, sizeof(logBuf), "syncNodeOnAppendEntriesReplyCb error term, receive:%lu current:%lu", pMsg->term,
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv sync-append-entries-reply, error term, recv-term:%lu"
,
pMsg
->
term
);
ths->pRaftStore->currentTerm);
syncNodeErrorLog
(
ths
,
logBuf
);
syncNodeLog2(logBuf, ths);
return
-
1
;
sError("%s", logBuf);
return ret;
}
}
ASSERT
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
);
ASSERT
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
);
if
(
pMsg
->
success
)
{
if
(
pMsg
->
success
)
{
// nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1]
SyncIndex
newNextIndex
=
pMsg
->
matchIndex
+
1
;
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1)
;
SyncIndex
newMatchIndex
=
pMsg
->
matchIndex
;
// matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex]
if
(
ths
->
pLogStore
->
syncLogExist
(
ths
->
pLogStore
,
newNextIndex
)
&&
syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex);
ths
->
pLogStore
->
syncLogExist
(
ths
->
pLogStore
,
newNextIndex
-
1
))
{
// nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1]
syncIndexMgrSetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
newNextIndex
);
// maybe commit
// matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex]
syncMaybeAdvanceCommitIndex(ths);
syncIndexMgrSetIndex
(
ths
->
pMatchIndex
,
&
(
pMsg
->
srcId
),
newMatchIndex
);
// maybe commit
if
(
ths
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
syncMaybeAdvanceCommitIndex
(
ths
);
}
}
else
{
// start snapshot <match+1, old snapshot.end>
SSnapshot
snapshot
;
ths
->
pFsm
->
FpGetSnapshotInfo
(
ths
->
pFsm
,
&
snapshot
);
syncNodeStartSnapshot
(
ths
,
newMatchIndex
+
1
,
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
,
pMsg
);
syncIndexMgrSetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
snapshot
.
lastApplyIndex
+
1
);
syncIndexMgrSetIndex
(
ths
->
pMatchIndex
,
&
(
pMsg
->
srcId
),
newMatchIndex
);
}
}
else
{
}
else
{
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
));
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
));
...
@@ -157,18 +191,35 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
...
@@ -157,18 +191,35 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
// notice! int64, uint64
// notice! int64, uint64
if
(
nextIndex
>
SYNC_INDEX_BEGIN
)
{
if
(
nextIndex
>
SYNC_INDEX_BEGIN
)
{
--
nextIndex
;
--
nextIndex
;
if
(
ths
->
pLogStore
->
syncLogExist
(
ths
->
pLogStore
,
nextIndex
)
&&
ths
->
pLogStore
->
syncLogExist
(
ths
->
pLogStore
,
nextIndex
-
1
))
{
// do nothing
}
else
{
SSyncRaftEntry
*
pEntry
;
int32_t
code
=
ths
->
pLogStore
->
syncLogGetEntry
(
ths
->
pLogStore
,
nextIndex
,
&
pEntry
);
ASSERT
(
code
==
0
);
syncNodeStartSnapshot
(
ths
,
SYNC_INDEX_BEGIN
,
nextIndex
,
pEntry
->
term
,
pMsg
);
// get sender
SSyncSnapshotSender
*
pSender
=
syncNodeGetSnapshotSender
(
ths
,
&
(
pMsg
->
srcId
));
ASSERT
(
pSender
!=
NULL
);
SyncIndex
sentryIndex
=
pSender
->
snapshot
.
lastApplyIndex
+
1
;
// update nextIndex to sentryIndex
if
(
nextIndex
<=
sentryIndex
)
{
nextIndex
=
sentryIndex
;
}
}
}
else
{
}
else
{
nextIndex
=
SYNC_INDEX_BEGIN
;
nextIndex
=
SYNC_INDEX_BEGIN
;
}
}
syncIndexMgrSetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
nextIndex
);
syncIndexMgrSetIndex
(
ths
->
pNextIndex
,
&
(
pMsg
->
srcId
),
nextIndex
);
}
}
syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== after pNextIndex", ths->pNextIndex);
return
0
;
syncIndexMgrLog2("==syncNodeOnAppendEntriesReplyCb== after pMatchIndex", ths->pMatchIndex);
return ret;
}
}
#endif
int32_t
syncNodeOnAppendEntriesReplySnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
syncNodeOnAppendEntriesReplySnapshotCb
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
ret
=
0
;
int32_t
ret
=
0
;
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
0d41f9c8
...
@@ -50,7 +50,6 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths);
...
@@ -50,7 +50,6 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths);
// process message ----
// process 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
);
int32_t
syncNodeOnClientRequestCb
(
SSyncNode
*
ths
,
SyncClientRequest
*
pMsg
,
SyncIndex
*
pRetIndex
);
// life cycle
// life cycle
static
void
syncFreeNode
(
void
*
param
);
static
void
syncFreeNode
(
void
*
param
);
...
@@ -627,6 +626,94 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
...
@@ -627,6 +626,94 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
return
ret
;
return
ret
;
}
}
int32_t
syncProposeBatch
(
int64_t
rid
,
SRpcMsg
*
pMsgArr
,
bool
*
pIsWeakArr
,
int32_t
arrSize
)
{
if
(
arrSize
<
0
)
{
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
return
-
1
;
}
int32_t
ret
=
0
;
SSyncNode
*
pSyncNode
=
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
return
-
1
;
}
ASSERT
(
rid
==
pSyncNode
->
rid
);
ret
=
syncNodeProposeBatch
(
pSyncNode
,
pMsgArr
,
pIsWeakArr
,
arrSize
);
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
return
ret
;
}
static
bool
syncNodeBatchOK
(
SRpcMsg
*
pMsgArr
,
int32_t
arrSize
)
{
for
(
int32_t
i
=
0
;
i
<
arrSize
;
++
i
)
{
if
(
pMsgArr
[
i
].
msgType
==
TDMT_SYNC_CONFIG_CHANGE
)
{
return
false
;
}
if
(
pMsgArr
[
i
].
msgType
==
TDMT_SYNC_CONFIG_CHANGE_FINISH
)
{
return
false
;
}
}
return
true
;
}
int32_t
syncNodeProposeBatch
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsgArr
,
bool
*
pIsWeakArr
,
int32_t
arrSize
)
{
if
(
!
syncNodeBatchOK
(
pMsgArr
,
arrSize
))
{
syncNodeErrorLog
(
pSyncNode
,
"sync propose batch error"
);
terrno
=
TSDB_CODE_SYN_BATCH_ERROR
;
return
-
1
;
}
if
(
arrSize
>
SYNC_MAX_BATCH_SIZE
)
{
syncNodeErrorLog
(
pSyncNode
,
"sync propose match batch error"
);
terrno
=
TSDB_CODE_SYN_BATCH_ERROR
;
return
-
1
;
}
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
syncNodeErrorLog
(
pSyncNode
,
"sync propose not leader"
);
terrno
=
TSDB_CODE_SYN_NOT_LEADER
;
return
-
1
;
}
if
(
pSyncNode
->
changing
)
{
syncNodeErrorLog
(
pSyncNode
,
"sync propose not ready"
);
terrno
=
TSDB_CODE_SYN_PROPOSE_NOT_READY
;
return
-
1
;
}
SRaftMeta
raftArr
[
SYNC_MAX_BATCH_SIZE
];
for
(
int
i
=
0
;
i
<
arrSize
;
++
i
)
{
SRespStub
stub
;
stub
.
createTime
=
taosGetTimestampMs
();
stub
.
rpcMsg
=
pMsgArr
[
i
];
uint64_t
seqNum
=
syncRespMgrAdd
(
pSyncNode
->
pSyncRespMgr
,
&
stub
);
raftArr
[
i
].
isWeak
=
pIsWeakArr
[
i
];
raftArr
[
i
].
seqNum
=
seqNum
;
}
SyncClientRequestBatch
*
pSyncMsg
=
syncClientRequestBatchBuild
(
pMsgArr
,
raftArr
,
arrSize
,
pSyncNode
->
vgId
);
ASSERT
(
pSyncMsg
!=
NULL
);
SRpcMsg
rpcMsg
;
syncClientRequestBatch2RpcMsg
(
pSyncMsg
,
&
rpcMsg
);
taosMemoryFree
(
pSyncMsg
);
// only free msg body, do not free rpc msg content
if
(
pSyncNode
->
FpEqMsg
!=
NULL
&&
(
*
pSyncNode
->
FpEqMsg
)(
pSyncNode
->
msgcb
,
&
rpcMsg
)
==
0
)
{
// enqueue msg ok
}
else
{
sError
(
"enqueue msg error, FpEqMsg is NULL"
);
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
return
-
1
;
}
return
0
;
}
int32_t
syncNodePropose
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
,
bool
isWeak
)
{
int32_t
syncNodePropose
(
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
,
bool
isWeak
)
{
int32_t
ret
=
0
;
int32_t
ret
=
0
;
...
@@ -2362,6 +2449,49 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncI
...
@@ -2362,6 +2449,49 @@ int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncI
return
ret
;
return
ret
;
}
}
int32_t
syncNodeOnClientRequestBatchCb
(
SSyncNode
*
ths
,
SyncClientRequestBatch
*
pMsg
)
{
int32_t
code
=
0
;
if
(
ths
->
state
!=
TAOS_SYNC_STATE_LEADER
)
{
// call FpCommitCb, delete resp mgr
return
-
1
;
}
SyncIndex
index
=
ths
->
pLogStore
->
syncLogWriteIndex
(
ths
->
pLogStore
);
SyncTerm
term
=
ths
->
pRaftStore
->
currentTerm
;
int32_t
raftMetaArrayLen
=
sizeof
(
SRaftMeta
)
*
pMsg
->
dataCount
;
int32_t
rpcArrayLen
=
sizeof
(
SRpcMsg
)
*
pMsg
->
dataCount
;
SRaftMeta
*
raftMetaArr
=
(
SRaftMeta
*
)(
pMsg
->
data
);
SRpcMsg
*
msgArr
=
(
SRpcMsg
*
)((
char
*
)(
pMsg
->
data
)
+
raftMetaArrayLen
);
for
(
int32_t
i
=
0
;
i
<
pMsg
->
dataCount
;
++
i
)
{
SSyncRaftEntry
*
pEntry
=
syncEntryBuild
(
msgArr
[
i
].
contLen
);
ASSERT
(
pEntry
!=
NULL
);
pEntry
->
originalRpcType
=
msgArr
[
i
].
msgType
;
pEntry
->
seqNum
=
raftMetaArr
[
i
].
seqNum
;
pEntry
->
isWeak
=
raftMetaArr
[
i
].
isWeak
;
pEntry
->
term
=
term
;
pEntry
->
index
=
index
;
memcpy
(
pEntry
->
data
,
msgArr
[
i
].
pCont
,
msgArr
[
i
].
contLen
);
ASSERT
(
msgArr
[
i
].
contLen
==
pEntry
->
dataLen
);
code
=
ths
->
pLogStore
->
syncLogAppendEntry
(
ths
->
pLogStore
,
pEntry
);
if
(
code
!=
0
)
{
// del resp mgr, call FpCommitCb
ASSERT
(
0
);
return
-
1
;
}
}
// fsync once
SSyncLogStoreData
*
pData
=
ths
->
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
walFsync
(
pWal
,
true
);
return
0
;
}
static
void
syncFreeNode
(
void
*
param
)
{
static
void
syncFreeNode
(
void
*
param
)
{
SSyncNode
*
pNode
=
param
;
SSyncNode
*
pNode
=
param
;
// inner object already free
// inner object already free
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
0d41f9c8
...
@@ -591,7 +591,7 @@ void syncPingReplySerialize(const SyncPingReply* pMsg, char* buf, uint32_t bufLe
...
@@ -591,7 +591,7 @@ void syncPingReplySerialize(const SyncPingReply* pMsg, char* buf, uint32_t bufLe
void
syncPingReplyDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncPingReply
*
pMsg
)
{
void
syncPingReplyDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncPingReply
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
ASSERT
(
len
==
pMsg
->
bytes
);
ASSERT
(
pMsg
->
bytes
==
sizeof
(
SyncPing
)
+
pMsg
->
dataLen
);
ASSERT
(
pMsg
->
bytes
==
sizeof
(
SyncPing
Reply
)
+
pMsg
->
dataLen
);
}
}
char
*
syncPingReplySerialize2
(
const
SyncPingReply
*
pMsg
,
uint32_t
*
len
)
{
char
*
syncPingReplySerialize2
(
const
SyncPingReply
*
pMsg
,
uint32_t
*
len
)
{
...
@@ -956,6 +956,48 @@ void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) {
...
@@ -956,6 +956,48 @@ void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) {
}
}
}
}
// ---- message process SyncClientRequestBatch----
// block1:
// block2: SRaftMeta array
// block3: rpc msg array (with pCont)
SyncClientRequestBatch
*
syncClientRequestBatchBuild
(
SRpcMsg
*
rpcMsgArr
,
SRaftMeta
*
raftArr
,
int32_t
arrSize
,
int32_t
vgId
)
{
ASSERT
(
rpcMsgArr
!=
NULL
);
ASSERT
(
arrSize
>
0
);
int32_t
dataLen
=
0
;
int32_t
raftMetaArrayLen
=
sizeof
(
SRaftMeta
)
*
arrSize
;
int32_t
rpcArrayLen
=
sizeof
(
SRpcMsg
)
*
arrSize
;
dataLen
+=
(
raftMetaArrayLen
+
rpcArrayLen
);
uint32_t
bytes
=
sizeof
(
SyncClientRequestBatch
)
+
dataLen
;
SyncClientRequestBatch
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
pMsg
->
msgType
=
TDMT_SYNC_CLIENT_REQUEST_BATCH
;
pMsg
->
dataCount
=
arrSize
;
pMsg
->
dataLen
=
dataLen
;
SRaftMeta
*
raftMetaArr
=
(
SRaftMeta
*
)(
pMsg
->
data
);
SRpcMsg
*
msgArr
=
(
SRpcMsg
*
)((
char
*
)(
pMsg
->
data
)
+
raftMetaArrayLen
);
for
(
int
i
=
0
;
i
<
arrSize
;
++
i
)
{
// init raftMetaArr
raftMetaArr
[
i
].
isWeak
=
raftArr
[
i
].
isWeak
;
raftMetaArr
[
i
].
seqNum
=
raftArr
[
i
].
seqNum
;
// init msgArr
msgArr
[
i
]
=
rpcMsgArr
[
i
];
}
return
pMsg
;
}
void
syncClientRequestBatch2RpcMsg
(
const
SyncClientRequestBatch
*
pSyncMsg
,
SRpcMsg
*
pRpcMsg
)
{}
// ---- message process SyncRequestVote----
// ---- message process SyncRequestVote----
SyncRequestVote
*
syncRequestVoteBuild
(
int32_t
vgId
)
{
SyncRequestVote
*
syncRequestVoteBuild
(
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncRequestVote
);
uint32_t
bytes
=
sizeof
(
SyncRequestVote
);
...
@@ -1426,6 +1468,279 @@ void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) {
...
@@ -1426,6 +1468,279 @@ void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) {
}
}
}
}
// ---- message process SyncAppendEntriesBatch----
// block1: SOffsetAndContLen
// block2: SOffsetAndContLen Array
// block3: SRpcMsg Array
// block4: SRpcMsg pCont Array
SyncAppendEntriesBatch
*
syncAppendEntriesBatchBuild
(
SRpcMsg
*
rpcMsgArr
,
int32_t
arrSize
,
int32_t
vgId
)
{
ASSERT
(
rpcMsgArr
!=
NULL
);
ASSERT
(
arrSize
>
0
);
int32_t
dataLen
=
0
;
int32_t
metaArrayLen
=
sizeof
(
SOffsetAndContLen
)
*
arrSize
;
// <offset, contLen>
int32_t
rpcArrayLen
=
sizeof
(
SRpcMsg
)
*
arrSize
;
// SRpcMsg
int32_t
contArrayLen
=
0
;
for
(
int
i
=
0
;
i
<
arrSize
;
++
i
)
{
// SRpcMsg pCont
contArrayLen
+=
rpcMsgArr
[
i
].
contLen
;
}
dataLen
+=
(
metaArrayLen
+
rpcArrayLen
+
contArrayLen
);
uint32_t
bytes
=
sizeof
(
SyncAppendEntriesBatch
)
+
dataLen
;
SyncAppendEntriesBatch
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
pMsg
->
msgType
=
TDMT_SYNC_APPEND_ENTRIES_BATCH
;
pMsg
->
dataCount
=
arrSize
;
pMsg
->
dataLen
=
dataLen
;
SOffsetAndContLen
*
metaArr
=
(
SOffsetAndContLen
*
)(
pMsg
->
data
);
SRpcMsg
*
msgArr
=
(
SRpcMsg
*
)((
char
*
)(
pMsg
->
data
)
+
metaArrayLen
);
char
*
pData
=
pMsg
->
data
;
for
(
int
i
=
0
;
i
<
arrSize
;
++
i
)
{
// init <offset, contLen>
if
(
i
==
0
)
{
metaArr
[
i
].
offset
=
metaArrayLen
+
rpcArrayLen
;
metaArr
[
i
].
contLen
=
rpcMsgArr
[
i
].
contLen
;
}
else
{
metaArr
[
i
].
offset
=
metaArr
[
i
-
1
].
offset
+
metaArr
[
i
-
1
].
contLen
;
metaArr
[
i
].
contLen
=
rpcMsgArr
[
i
].
contLen
;
}
// init msgArr
msgArr
[
i
]
=
rpcMsgArr
[
i
];
// init data
ASSERT
(
rpcMsgArr
[
i
].
contLen
==
metaArr
[
i
].
contLen
);
memcpy
(
pData
+
metaArr
[
i
].
offset
,
rpcMsgArr
[
i
].
pCont
,
rpcMsgArr
[
i
].
contLen
);
}
return
pMsg
;
}
void
syncAppendEntriesBatchDestroy
(
SyncAppendEntriesBatch
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncAppendEntriesBatchSerialize
(
const
SyncAppendEntriesBatch
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncAppendEntriesBatchDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncAppendEntriesBatch
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
ASSERT
(
pMsg
->
bytes
==
sizeof
(
SyncAppendEntriesBatch
)
+
pMsg
->
dataLen
);
}
char
*
syncAppendEntriesBatchSerialize2
(
const
SyncAppendEntriesBatch
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncAppendEntriesBatchSerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncAppendEntriesBatch
*
syncAppendEntriesBatchDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncAppendEntriesBatch
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncAppendEntriesBatchDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncAppendEntriesBatch2RpcMsg
(
const
SyncAppendEntriesBatch
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncAppendEntriesBatchSerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncAppendEntriesBatchFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncAppendEntriesBatch
*
pMsg
)
{
syncAppendEntriesBatchDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncAppendEntriesBatch
*
syncAppendEntriesBatchFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncAppendEntriesBatch
*
pMsg
=
syncAppendEntriesBatchDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
ASSERT
(
pMsg
!=
NULL
);
return
pMsg
;
}
cJSON
*
syncAppendEntriesBatch2Json
(
const
SyncAppendEntriesBatch
*
pMsg
)
{
char
u64buf
[
128
]
=
{
0
};
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
]
=
{
0
};
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
]
=
{
0
};
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
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pMsg
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%ld"
,
pMsg
->
prevLogIndex
);
cJSON_AddStringToObject
(
pRoot
,
"prevLogIndex"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pMsg
->
prevLogTerm
);
cJSON_AddStringToObject
(
pRoot
,
"prevLogTerm"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%ld"
,
pMsg
->
commitIndex
);
cJSON_AddStringToObject
(
pRoot
,
"commitIndex"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pMsg
->
privateTerm
);
cJSON_AddStringToObject
(
pRoot
,
"privateTerm"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"dataCount"
,
pMsg
->
dataCount
);
cJSON_AddNumberToObject
(
pRoot
,
"dataLen"
,
pMsg
->
dataLen
);
int32_t
metaArrayLen
=
sizeof
(
SOffsetAndContLen
)
*
pMsg
->
dataCount
;
// <offset, contLen>
int32_t
rpcArrayLen
=
sizeof
(
SRpcMsg
)
*
pMsg
->
dataCount
;
// SRpcMsg
int32_t
contArrayLen
=
pMsg
->
dataLen
-
metaArrayLen
-
rpcArrayLen
;
cJSON_AddNumberToObject
(
pRoot
,
"metaArrayLen"
,
metaArrayLen
);
cJSON_AddNumberToObject
(
pRoot
,
"rpcArrayLen"
,
rpcArrayLen
);
cJSON_AddNumberToObject
(
pRoot
,
"contArrayLen"
,
contArrayLen
);
SOffsetAndContLen
*
metaArr
=
(
SOffsetAndContLen
*
)(
pMsg
->
data
);
SRpcMsg
*
msgArr
=
(
SRpcMsg
*
)(
pMsg
->
data
+
metaArrayLen
);
void
*
pData
=
(
void
*
)(
pMsg
->
data
+
metaArrayLen
+
rpcArrayLen
);
cJSON
*
pMetaArr
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"metaArr"
,
pMetaArr
);
for
(
int
i
=
0
;
i
<
pMsg
->
dataCount
;
++
i
)
{
cJSON
*
pMeta
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
pMeta
,
"offset"
,
metaArr
[
i
].
offset
);
cJSON_AddNumberToObject
(
pMeta
,
"contLen"
,
metaArr
[
i
].
contLen
);
cJSON_AddItemToArray
(
pMetaArr
,
pMeta
);
}
cJSON
*
pMsgArr
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"msgArr"
,
pMsgArr
);
for
(
int
i
=
0
;
i
<
pMsg
->
dataCount
;
++
i
)
{
cJSON
*
pRpcMsgJson
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
pRpcMsgJson
,
"code"
,
msgArr
[
i
].
code
);
cJSON_AddNumberToObject
(
pRpcMsgJson
,
"contLen"
,
msgArr
[
i
].
contLen
);
cJSON_AddNumberToObject
(
pRpcMsgJson
,
"msgType"
,
msgArr
[
i
].
msgType
);
cJSON_AddItemToArray
(
pMsgArr
,
pRpcMsgJson
);
}
char
*
s
;
s
=
syncUtilprintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
taosMemoryFree
(
s
);
s
=
syncUtilprintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data2"
,
s
);
taosMemoryFree
(
s
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncAppendEntriesBatch"
,
pRoot
);
return
pJson
;
}
char
*
syncAppendEntriesBatch2Str
(
const
SyncAppendEntriesBatch
*
pMsg
)
{
cJSON
*
pJson
=
syncAppendEntriesBatch2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
void
syncAppendEntriesBatch2RpcMsgArray
(
SyncAppendEntriesBatch
*
pSyncMsg
,
SRpcMsg
*
rpcMsgArr
,
int32_t
maxArrSize
,
int32_t
*
pRetArrSize
)
{
if
(
pRetArrSize
!=
NULL
)
{
*
pRetArrSize
=
pSyncMsg
->
dataCount
;
}
int32_t
arrSize
=
pSyncMsg
->
dataCount
;
if
(
arrSize
>
maxArrSize
)
{
arrSize
=
maxArrSize
;
}
int32_t
metaArrayLen
=
sizeof
(
SOffsetAndContLen
)
*
pSyncMsg
->
dataCount
;
// <offset, contLen>
int32_t
rpcArrayLen
=
sizeof
(
SRpcMsg
)
*
pSyncMsg
->
dataCount
;
// SRpcMsg
int32_t
contArrayLen
=
pSyncMsg
->
dataLen
-
metaArrayLen
-
rpcArrayLen
;
SOffsetAndContLen
*
metaArr
=
(
SOffsetAndContLen
*
)(
pSyncMsg
->
data
);
SRpcMsg
*
msgArr
=
(
SRpcMsg
*
)(
pSyncMsg
->
data
+
metaArrayLen
);
void
*
pData
=
pSyncMsg
->
data
+
metaArrayLen
+
rpcArrayLen
;
for
(
int
i
=
0
;
i
<
arrSize
;
++
i
)
{
rpcMsgArr
[
i
]
=
msgArr
[
i
];
rpcMsgArr
[
i
].
pCont
=
rpcMallocCont
(
msgArr
[
i
].
contLen
);
void
*
pRpcCont
=
pSyncMsg
->
data
+
metaArr
[
i
].
offset
;
memcpy
(
rpcMsgArr
[
i
].
pCont
,
pRpcCont
,
rpcMsgArr
[
i
].
contLen
);
}
}
// for debug ----------------------
void
syncAppendEntriesBatchPrint
(
const
SyncAppendEntriesBatch
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesBatch2Str
(
pMsg
);
printf
(
"syncAppendEntriesBatchPrint | len:%lu | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncAppendEntriesBatchPrint2
(
char
*
s
,
const
SyncAppendEntriesBatch
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesBatch2Str
(
pMsg
);
printf
(
"syncAppendEntriesBatchPrint2 | len:%lu | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncAppendEntriesBatchLog
(
const
SyncAppendEntriesBatch
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesBatch2Str
(
pMsg
);
sTrace
(
"syncAppendEntriesBatchLog | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
syncAppendEntriesBatchLog2
(
char
*
s
,
const
SyncAppendEntriesBatch
*
pMsg
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
syncAppendEntriesBatch2Str
(
pMsg
);
sTraceLong
(
"syncAppendEntriesBatchLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
}
// ---- message process SyncAppendEntriesReply----
// ---- message process SyncAppendEntriesReply----
SyncAppendEntriesReply
*
syncAppendEntriesReplyBuild
(
int32_t
vgId
)
{
SyncAppendEntriesReply
*
syncAppendEntriesReplyBuild
(
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncAppendEntriesReply
);
uint32_t
bytes
=
sizeof
(
SyncAppendEntriesReply
);
...
...
source/libs/sync/src/syncRaftCfg.c
浏览文件 @
0d41f9c8
...
@@ -101,7 +101,7 @@ cJSON *syncCfg2Json(SSyncCfg *pSyncCfg) {
...
@@ -101,7 +101,7 @@ cJSON *syncCfg2Json(SSyncCfg *pSyncCfg) {
char
*
syncCfg2Str
(
SSyncCfg
*
pSyncCfg
)
{
char
*
syncCfg2Str
(
SSyncCfg
*
pSyncCfg
)
{
cJSON
*
pJson
=
syncCfg2Json
(
pSyncCfg
);
cJSON
*
pJson
=
syncCfg2Json
(
pSyncCfg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
return
serialized
;
}
}
...
@@ -109,7 +109,7 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) {
...
@@ -109,7 +109,7 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) {
char
*
syncCfg2SimpleStr
(
SSyncCfg
*
pSyncCfg
)
{
char
*
syncCfg2SimpleStr
(
SSyncCfg
*
pSyncCfg
)
{
if
(
pSyncCfg
!=
NULL
)
{
if
(
pSyncCfg
!=
NULL
)
{
int32_t
len
=
512
;
int32_t
len
=
512
;
char
*
s
=
taosMemoryMalloc
(
len
);
char
*
s
=
taosMemoryMalloc
(
len
);
memset
(
s
,
0
,
len
);
memset
(
s
,
0
,
len
);
snprintf
(
s
,
len
,
"{replica-num:%d, my-index:%d, "
,
pSyncCfg
->
replicaNum
,
pSyncCfg
->
myIndex
);
snprintf
(
s
,
len
,
"{replica-num:%d, my-index:%d, "
,
pSyncCfg
->
replicaNum
,
pSyncCfg
->
myIndex
);
...
@@ -205,7 +205,7 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) {
...
@@ -205,7 +205,7 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) {
char
*
raftCfg2Str
(
SRaftCfg
*
pRaftCfg
)
{
char
*
raftCfg2Str
(
SRaftCfg
*
pRaftCfg
)
{
cJSON
*
pJson
=
raftCfg2Json
(
pRaftCfg
);
cJSON
*
pJson
=
raftCfg2Json
(
pRaftCfg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
return
serialized
;
}
}
...
@@ -280,7 +280,7 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) {
...
@@ -280,7 +280,7 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) {
(
pRaftCfg
->
configIndexArr
)[
i
]
=
atoll
(
pIndex
->
valuestring
);
(
pRaftCfg
->
configIndexArr
)[
i
]
=
atoll
(
pIndex
->
valuestring
);
}
}
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/syncReplication.c
浏览文件 @
0d41f9c8
...
@@ -116,6 +116,73 @@ int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode) {
...
@@ -116,6 +116,73 @@ int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode) {
return
ret
;
return
ret
;
}
}
int32_t
syncNodeAppendEntriesPeersSnapshot2
(
SSyncNode
*
pSyncNode
)
{
if
(
pSyncNode
->
state
!=
TAOS_SYNC_STATE_LEADER
)
{
return
-
1
;
}
int32_t
ret
=
0
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
SRaftId
*
pDestId
=
&
(
pSyncNode
->
peersId
[
i
]);
// next index
SyncIndex
nextIndex
=
syncIndexMgrGetIndex
(
pSyncNode
->
pNextIndex
,
pDestId
);
// pre index, pre term
SyncIndex
preLogIndex
=
syncNodeGetPreIndex
(
pSyncNode
,
nextIndex
);
SyncTerm
preLogTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
nextIndex
);
if
(
preLogTerm
==
SYNC_TERM_INVALID
)
{
SSyncSnapshotSender
*
pSender
=
syncNodeGetSnapshotSender
(
pSyncNode
,
pDestId
);
ASSERT
(
pSender
!=
NULL
);
ASSERT
(
!
snapshotSenderIsStart
(
pSender
));
SyncIndex
newNextIndex
=
syncNodeGetLastIndex
(
pSyncNode
)
+
1
;
syncIndexMgrSetIndex
(
pSyncNode
->
pNextIndex
,
pDestId
,
newNextIndex
);
syncIndexMgrSetIndex
(
pSyncNode
->
pMatchIndex
,
pDestId
,
SYNC_INDEX_INVALID
);
sError
(
"vgId:%d sync get pre term error, nextIndex:%ld, update next-index:%ld, match-index:%d, raftid:%ld"
,
pSyncNode
->
vgId
,
nextIndex
,
newNextIndex
,
SYNC_INDEX_INVALID
,
pDestId
->
addr
);
return
-
1
;
}
SRpcMsg
rpcMsgArr
[
SYNC_MAX_BATCH_SIZE
];
memset
(
rpcMsgArr
,
0
,
sizeof
(
rpcMsgArr
));
int32_t
getCount
=
0
;
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
batchSize
;
++
i
)
{
SSyncRaftEntry
*
pEntry
;
int32_t
code
=
pSyncNode
->
pLogStore
->
syncLogGetEntry
(
pSyncNode
->
pLogStore
,
nextIndex
,
&
pEntry
);
if
(
code
==
0
)
{
ASSERT
(
pEntry
!=
NULL
);
// get rpc msg [i] from entry
syncEntryDestory
(
pEntry
);
getCount
++
;
}
else
{
break
;
}
}
SyncAppendEntriesBatch
*
pMsg
=
syncAppendEntriesBatchBuild
(
rpcMsgArr
,
getCount
,
pSyncNode
->
vgId
);
ASSERT
(
pMsg
!=
NULL
);
// prepare msg
pMsg
->
srcId
=
pSyncNode
->
myRaftId
;
pMsg
->
destId
=
*
pDestId
;
pMsg
->
term
=
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
prevLogIndex
=
preLogIndex
;
pMsg
->
prevLogTerm
=
preLogTerm
;
pMsg
->
commitIndex
=
pSyncNode
->
commitIndex
;
pMsg
->
privateTerm
=
0
;
pMsg
->
dataCount
=
getCount
;
// send msg
syncNodeAppendEntriesBatch
(
pSyncNode
,
pDestId
,
pMsg
);
syncAppendEntriesBatchDestroy
(
pMsg
);
}
return
0
;
}
int32_t
syncNodeAppendEntriesPeersSnapshot
(
SSyncNode
*
pSyncNode
)
{
int32_t
syncNodeAppendEntriesPeersSnapshot
(
SSyncNode
*
pSyncNode
)
{
ASSERT
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
);
ASSERT
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
);
...
@@ -234,4 +301,24 @@ int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, c
...
@@ -234,4 +301,24 @@ int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, c
syncAppendEntries2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncAppendEntries2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
destRaftId
,
pSyncNode
,
&
rpcMsg
);
syncNodeSendMsgById
(
destRaftId
,
pSyncNode
,
&
rpcMsg
);
return
ret
;
return
ret
;
}
int32_t
syncNodeAppendEntriesBatch
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncAppendEntriesBatch
*
pMsg
)
{
do
{
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
destRaftId
->
addr
,
host
,
sizeof
(
host
),
&
port
);
sDebug
(
"vgId:%d, send sync-append-entries-batch to %s:%d, {term:%lu, pre-index:%ld, pre-term:%lu, pterm:%lu, "
"commit:%ld, "
"datalen:%d, dataCount:%d}"
,
pSyncNode
->
vgId
,
host
,
port
,
pMsg
->
term
,
pMsg
->
prevLogIndex
,
pMsg
->
prevLogTerm
,
pMsg
->
privateTerm
,
pMsg
->
commitIndex
,
pMsg
->
dataLen
,
pMsg
->
dataCount
);
}
while
(
0
);
SRpcMsg
rpcMsg
;
syncAppendEntriesBatch2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
destRaftId
,
pSyncNode
,
&
rpcMsg
);
return
0
;
}
}
\ No newline at end of file
source/libs/sync/src/syncSnapshot.c
浏览文件 @
0d41f9c8
...
@@ -349,14 +349,14 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) {
...
@@ -349,14 +349,14 @@ 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
;
}
}
char
*
snapshotSender2SimpleStr
(
SSyncSnapshotSender
*
pSender
,
char
*
event
)
{
char
*
snapshotSender2SimpleStr
(
SSyncSnapshotSender
*
pSender
,
char
*
event
)
{
int32_t
len
=
256
;
int32_t
len
=
256
;
char
*
s
=
taosMemoryMalloc
(
len
);
char
*
s
=
taosMemoryMalloc
(
len
);
SRaftId
destId
=
pSender
->
pSyncNode
->
replicasId
[
pSender
->
replicaIndex
];
SRaftId
destId
=
pSender
->
pSyncNode
->
replicasId
[
pSender
->
replicaIndex
];
char
host
[
64
];
char
host
[
64
];
...
@@ -604,7 +604,7 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
...
@@ -604,7 +604,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
);
...
@@ -637,14 +637,14 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
...
@@ -637,14 +637,14 @@ 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
;
}
}
char
*
snapshotReceiver2SimpleStr
(
SSyncSnapshotReceiver
*
pReceiver
,
char
*
event
)
{
char
*
snapshotReceiver2SimpleStr
(
SSyncSnapshotReceiver
*
pReceiver
,
char
*
event
)
{
int32_t
len
=
256
;
int32_t
len
=
256
;
char
*
s
=
taosMemoryMalloc
(
len
);
char
*
s
=
taosMemoryMalloc
(
len
);
SRaftId
fromId
=
pReceiver
->
fromId
;
SRaftId
fromId
=
pReceiver
->
fromId
;
char
host
[
128
];
char
host
[
128
];
...
...
source/libs/sync/test/CMakeLists.txt
浏览文件 @
0d41f9c8
...
@@ -21,6 +21,7 @@ add_executable(syncEntryCacheTest "")
...
@@ -21,6 +21,7 @@ add_executable(syncEntryCacheTest "")
add_executable
(
syncRequestVoteTest
""
)
add_executable
(
syncRequestVoteTest
""
)
add_executable
(
syncRequestVoteReplyTest
""
)
add_executable
(
syncRequestVoteReplyTest
""
)
add_executable
(
syncAppendEntriesTest
""
)
add_executable
(
syncAppendEntriesTest
""
)
add_executable
(
syncAppendEntriesBatchTest
""
)
add_executable
(
syncAppendEntriesReplyTest
""
)
add_executable
(
syncAppendEntriesReplyTest
""
)
add_executable
(
syncClientRequestTest
""
)
add_executable
(
syncClientRequestTest
""
)
add_executable
(
syncTimeoutTest
""
)
add_executable
(
syncTimeoutTest
""
)
...
@@ -146,6 +147,10 @@ target_sources(syncAppendEntriesTest
...
@@ -146,6 +147,10 @@ target_sources(syncAppendEntriesTest
PRIVATE
PRIVATE
"syncAppendEntriesTest.cpp"
"syncAppendEntriesTest.cpp"
)
)
target_sources
(
syncAppendEntriesBatchTest
PRIVATE
"syncAppendEntriesBatchTest.cpp"
)
target_sources
(
syncAppendEntriesReplyTest
target_sources
(
syncAppendEntriesReplyTest
PRIVATE
PRIVATE
"syncAppendEntriesReplyTest.cpp"
"syncAppendEntriesReplyTest.cpp"
...
@@ -387,6 +392,11 @@ target_include_directories(syncAppendEntriesTest
...
@@ -387,6 +392,11 @@ target_include_directories(syncAppendEntriesTest
"
${
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
(
syncAppendEntriesBatchTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncAppendEntriesReplyTest
target_include_directories
(
syncAppendEntriesReplyTest
PUBLIC
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
...
@@ -636,6 +646,10 @@ target_link_libraries(syncAppendEntriesTest
...
@@ -636,6 +646,10 @@ target_link_libraries(syncAppendEntriesTest
sync
sync
gtest_main
gtest_main
)
)
target_link_libraries
(
syncAppendEntriesBatchTest
sync
gtest_main
)
target_link_libraries
(
syncAppendEntriesReplyTest
target_link_libraries
(
syncAppendEntriesReplyTest
sync
sync
gtest_main
gtest_main
...
...
source/libs/sync/test/syncAppendEntriesBatchTest.cpp
0 → 100644
浏览文件 @
0d41f9c8
//#include <gtest/gtest.h>
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncMessage.h"
#include "syncUtil.h"
#include "trpc.h"
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
sDebug
(
"--- sync log test: debug"
);
sInfo
(
"--- sync log test: info"
);
sWarn
(
"--- sync log test: warn"
);
sError
(
"--- sync log test: error"
);
sFatal
(
"--- sync log test: fatal"
);
}
SRpcMsg
*
createRpcMsg
(
int32_t
i
,
int32_t
dataLen
)
{
SRpcMsg
*
pRpcMsg
=
(
SRpcMsg
*
)
taosMemoryMalloc
(
sizeof
(
SRpcMsg
));
memset
(
pRpcMsg
,
0
,
sizeof
(
SRpcMsg
));
pRpcMsg
->
msgType
=
TDMT_SYNC_PING
;
pRpcMsg
->
contLen
=
dataLen
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
pRpcMsg
->
code
=
10
*
i
;
snprintf
((
char
*
)
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
"value_%d"
,
i
);
return
pRpcMsg
;
}
SyncAppendEntriesBatch
*
createMsg
()
{
SRpcMsg
rpcMsgArr
[
5
];
memset
(
rpcMsgArr
,
0
,
sizeof
(
rpcMsgArr
));
for
(
int32_t
i
=
0
;
i
<
5
;
++
i
)
{
SRpcMsg
*
pRpcMsg
=
createRpcMsg
(
i
,
20
);
rpcMsgArr
[
i
]
=
*
pRpcMsg
;
taosMemoryFree
(
pRpcMsg
);
}
SyncAppendEntriesBatch
*
pMsg
=
syncAppendEntriesBatchBuild
(
rpcMsgArr
,
5
,
1234
);
pMsg
->
srcId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
1234
);
pMsg
->
srcId
.
vgId
=
100
;
pMsg
->
destId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
5678
);
pMsg
->
destId
.
vgId
=
100
;
pMsg
->
prevLogIndex
=
11
;
pMsg
->
prevLogTerm
=
22
;
pMsg
->
commitIndex
=
33
;
pMsg
->
privateTerm
=
44
;
return
pMsg
;
}
void
test1
()
{
SyncAppendEntriesBatch
*
pMsg
=
createMsg
();
syncAppendEntriesBatchLog2
((
char
*
)
"test1:"
,
pMsg
);
SRpcMsg
rpcMsgArr
[
5
];
int32_t
retArrSize
;
syncAppendEntriesBatch2RpcMsgArray
(
pMsg
,
rpcMsgArr
,
5
,
&
retArrSize
);
for
(
int
i
=
0
;
i
<
retArrSize
;
++
i
)
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==test1 decode rpc msg %d: msgType:%d, code:%d, contLen:%d, pCont:%s
\n
"
,
i
,
rpcMsgArr
[
i
].
msgType
,
rpcMsgArr
[
i
].
code
,
rpcMsgArr
[
i
].
contLen
,
(
char
*
)
rpcMsgArr
[
i
].
pCont
);
sTrace
(
"%s"
,
logBuf
);
}
syncAppendEntriesBatchDestroy
(
pMsg
);
}
/*
void test2() {
SyncAppendEntries *pMsg = createMsg();
uint32_t len = pMsg->bytes;
char * serialized = (char *)taosMemoryMalloc(len);
syncAppendEntriesSerialize(pMsg, serialized, len);
SyncAppendEntries *pMsg2 = syncAppendEntriesBuild(pMsg->dataLen, 1000);
syncAppendEntriesDeserialize(serialized, len, pMsg2);
syncAppendEntriesLog2((char *)"test2: syncAppendEntriesSerialize -> syncAppendEntriesDeserialize ", pMsg2);
taosMemoryFree(serialized);
syncAppendEntriesDestroy(pMsg);
syncAppendEntriesDestroy(pMsg2);
}
void test3() {
SyncAppendEntries *pMsg = createMsg();
uint32_t len;
char * serialized = syncAppendEntriesSerialize2(pMsg, &len);
SyncAppendEntries *pMsg2 = syncAppendEntriesDeserialize2(serialized, len);
syncAppendEntriesLog2((char *)"test3: syncAppendEntriesSerialize3 -> syncAppendEntriesDeserialize2 ", pMsg2);
taosMemoryFree(serialized);
syncAppendEntriesDestroy(pMsg);
syncAppendEntriesDestroy(pMsg2);
}
void test4() {
SyncAppendEntries *pMsg = createMsg();
SRpcMsg rpcMsg;
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
SyncAppendEntries *pMsg2 = (SyncAppendEntries *)taosMemoryMalloc(rpcMsg.contLen);
syncAppendEntriesFromRpcMsg(&rpcMsg, pMsg2);
syncAppendEntriesLog2((char *)"test4: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg ", pMsg2);
rpcFreeCont(rpcMsg.pCont);
syncAppendEntriesDestroy(pMsg);
syncAppendEntriesDestroy(pMsg2);
}
void test5() {
SyncAppendEntries *pMsg = createMsg();
SRpcMsg rpcMsg;
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
SyncAppendEntries *pMsg2 = syncAppendEntriesFromRpcMsg2(&rpcMsg);
syncAppendEntriesLog2((char *)"test5: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg2 ", pMsg2);
rpcFreeCont(rpcMsg.pCont);
syncAppendEntriesDestroy(pMsg);
syncAppendEntriesDestroy(pMsg2);
}
*/
int
main
()
{
gRaftDetailLog
=
true
;
tsAsyncLog
=
0
;
sDebugFlag
=
DEBUG_DEBUG
+
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
;
logTest
();
test1
();
/*
test2();
test3();
test4();
test5();
*/
return
0
;
}
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
浏览文件 @
0d41f9c8
...
@@ -77,7 +77,7 @@ int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) {
...
@@ -77,7 +77,7 @@ int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) {
return
0
;
return
0
;
}
}
int32_t
SnapshotStartRead
(
struct
SSyncFSM
*
pFsm
,
void
**
ppReader
)
{
int32_t
SnapshotStartRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pParam
,
void
**
ppReader
)
{
*
ppReader
=
(
void
*
)
0xABCD
;
*
ppReader
=
(
void
*
)
0xABCD
;
char
logBuf
[
256
]
=
{
0
};
char
logBuf
[
256
]
=
{
0
};
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==SnapshotStartRead== pFsm:%p, *ppReader:%p"
,
pFsm
,
*
ppReader
);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==SnapshotStartRead== pFsm:%p, *ppReader:%p"
,
pFsm
,
*
ppReader
);
...
...
source/libs/sync/test/syncSnapshotSenderTest.cpp
浏览文件 @
0d41f9c8
...
@@ -25,7 +25,7 @@ void ReConfigCb(struct SSyncFSM* pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta)
...
@@ -25,7 +25,7 @@ void ReConfigCb(struct SSyncFSM* pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta)
int32_t
GetSnapshot
(
struct
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
)
{
return
0
;
}
int32_t
GetSnapshot
(
struct
SSyncFSM
*
pFsm
,
SSnapshot
*
pSnapshot
)
{
return
0
;
}
int32_t
SnapshotStartRead
(
struct
SSyncFSM
*
pFsm
,
void
**
ppReader
)
{
return
0
;
}
int32_t
SnapshotStartRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pParam
,
void
**
ppReader
)
{
return
0
;
}
int32_t
SnapshotStopRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
)
{
return
0
;
}
int32_t
SnapshotStopRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
)
{
return
0
;
}
int32_t
SnapshotDoRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
,
void
**
ppBuf
,
int32_t
*
len
)
{
return
0
;
}
int32_t
SnapshotDoRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pReader
,
void
**
ppBuf
,
int32_t
*
len
)
{
return
0
;
}
...
...
source/libs/sync/test/syncTestTool.cpp
浏览文件 @
0d41f9c8
...
@@ -74,7 +74,7 @@ int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) {
...
@@ -74,7 +74,7 @@ int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) {
return
0
;
return
0
;
}
}
int32_t
SnapshotStartRead
(
struct
SSyncFSM
*
pFsm
,
void
**
ppReader
)
{
int32_t
SnapshotStartRead
(
struct
SSyncFSM
*
pFsm
,
void
*
pParam
,
void
**
ppReader
)
{
*
ppReader
=
(
void
*
)
0xABCD
;
*
ppReader
=
(
void
*
)
0xABCD
;
char
logBuf
[
256
]
=
{
0
};
char
logBuf
[
256
]
=
{
0
};
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==SnapshotStartRead== pFsm:%p, *ppReader:%p"
,
pFsm
,
*
ppReader
);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==SnapshotStartRead== pFsm:%p, *ppReader:%p"
,
pFsm
,
*
ppReader
);
...
...
source/libs/wal/inc/walInt.h
浏览文件 @
0d41f9c8
...
@@ -27,7 +27,7 @@ extern "C" {
...
@@ -27,7 +27,7 @@ extern "C" {
#endif
#endif
// meta section begin
// meta section begin
typedef
struct
WalFileInfo
{
typedef
struct
{
int64_t
firstVer
;
int64_t
firstVer
;
int64_t
lastVer
;
int64_t
lastVer
;
int64_t
createTs
;
int64_t
createTs
;
...
@@ -98,20 +98,20 @@ static inline int walBuildIdxName(SWal* pWal, int64_t fileFirstVer, char* buf) {
...
@@ -98,20 +98,20 @@ static inline int walBuildIdxName(SWal* pWal, int64_t fileFirstVer, char* buf) {
return
sprintf
(
buf
,
"%s/%020"
PRId64
"."
WAL_INDEX_SUFFIX
,
pWal
->
path
,
fileFirstVer
);
return
sprintf
(
buf
,
"%s/%020"
PRId64
"."
WAL_INDEX_SUFFIX
,
pWal
->
path
,
fileFirstVer
);
}
}
static
inline
int
walValidHeadCksum
(
SWalHead
*
pHead
)
{
static
inline
int
walValidHeadCksum
(
SWal
Ck
Head
*
pHead
)
{
return
taosCheckChecksum
((
uint8_t
*
)
&
pHead
->
head
,
sizeof
(
SWal
ReadHead
),
pHead
->
cksumHead
);
return
taosCheckChecksum
((
uint8_t
*
)
&
pHead
->
head
,
sizeof
(
SWal
Cont
),
pHead
->
cksumHead
);
}
}
static
inline
int
walValidBodyCksum
(
SWalHead
*
pHead
)
{
static
inline
int
walValidBodyCksum
(
SWal
Ck
Head
*
pHead
)
{
return
taosCheckChecksum
((
uint8_t
*
)
pHead
->
head
.
body
,
pHead
->
head
.
bodyLen
,
pHead
->
cksumBody
);
return
taosCheckChecksum
((
uint8_t
*
)
pHead
->
head
.
body
,
pHead
->
head
.
bodyLen
,
pHead
->
cksumBody
);
}
}
static
inline
int
walValidCksum
(
SWalHead
*
pHead
,
void
*
body
,
int64_t
bodyLen
)
{
static
inline
int
walValidCksum
(
SWal
Ck
Head
*
pHead
,
void
*
body
,
int64_t
bodyLen
)
{
return
walValidHeadCksum
(
pHead
)
&&
walValidBodyCksum
(
pHead
);
return
walValidHeadCksum
(
pHead
)
&&
walValidBodyCksum
(
pHead
);
}
}
static
inline
uint32_t
walCalcHeadCksum
(
SWalHead
*
pHead
)
{
static
inline
uint32_t
walCalcHeadCksum
(
SWal
Ck
Head
*
pHead
)
{
return
taosCalcChecksum
(
0
,
(
uint8_t
*
)
&
pHead
->
head
,
sizeof
(
SWal
ReadHead
));
return
taosCalcChecksum
(
0
,
(
uint8_t
*
)
&
pHead
->
head
,
sizeof
(
SWal
Cont
));
}
}
static
inline
uint32_t
walCalcBodyCksum
(
const
void
*
body
,
uint32_t
len
)
{
static
inline
uint32_t
walCalcBodyCksum
(
const
void
*
body
,
uint32_t
len
)
{
...
...
source/libs/wal/src/walMeta.c
浏览文件 @
0d41f9c8
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
#include "cJSON.h"
#include "cJSON.h"
#include "os.h"
#include "os.h"
#include "taoserror.h"
#include "taoserror.h"
#include "t
ref
.h"
#include "t
util
.h"
#include "walInt.h"
#include "walInt.h"
bool
FORCE_INLINE
walLogExist
(
SWal
*
pWal
,
int64_t
ver
)
{
bool
FORCE_INLINE
walLogExist
(
SWal
*
pWal
,
int64_t
ver
)
{
...
@@ -37,26 +37,9 @@ static FORCE_INLINE int walBuildMetaName(SWal* pWal, int metaVer, char* buf) {
...
@@ -37,26 +37,9 @@ static FORCE_INLINE int walBuildMetaName(SWal* pWal, int metaVer, char* buf) {
return
sprintf
(
buf
,
"%s/meta-ver%d"
,
pWal
->
path
,
metaVer
);
return
sprintf
(
buf
,
"%s/meta-ver%d"
,
pWal
->
path
,
metaVer
);
}
}
void
*
tmemmem
(
char
*
haystack
,
int
hlen
,
char
*
needle
,
int
nlen
)
{
char
*
limit
;
if
(
nlen
==
0
||
hlen
<
nlen
)
{
return
NULL
;
}
limit
=
haystack
+
hlen
-
nlen
+
1
;
while
((
haystack
=
(
char
*
)
memchr
(
haystack
,
needle
[
0
],
limit
-
haystack
))
!=
NULL
)
{
if
(
memcmp
(
haystack
,
needle
,
nlen
)
==
0
)
{
return
haystack
;
}
haystack
++
;
}
return
NULL
;
}
static
FORCE_INLINE
int64_t
walScanLogGetLastVer
(
SWal
*
pWal
)
{
static
FORCE_INLINE
int64_t
walScanLogGetLastVer
(
SWal
*
pWal
)
{
ASSERT
(
pWal
->
fileInfoSet
!=
NULL
);
ASSERT
(
pWal
->
fileInfoSet
!=
NULL
);
int
sz
=
taosArrayGetSize
(
pWal
->
fileInfoSet
);
int
32_t
sz
=
taosArrayGetSize
(
pWal
->
fileInfoSet
);
ASSERT
(
sz
>
0
);
ASSERT
(
sz
>
0
);
#if 0
#if 0
for (int i = 0; i < sz; i++) {
for (int i = 0; i < sz; i++) {
...
@@ -101,14 +84,14 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) {
...
@@ -101,14 +84,14 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) {
char
*
candidate
;
char
*
candidate
;
while
((
candidate
=
tmemmem
(
haystack
,
readSize
-
(
haystack
-
buf
),
(
char
*
)
&
magic
,
sizeof
(
uint64_t
)))
!=
NULL
)
{
while
((
candidate
=
tmemmem
(
haystack
,
readSize
-
(
haystack
-
buf
),
(
char
*
)
&
magic
,
sizeof
(
uint64_t
)))
!=
NULL
)
{
// read and validate
// read and validate
SWal
Head
*
logContent
=
(
SWal
Head
*
)
candidate
;
SWal
CkHead
*
logContent
=
(
SWalCk
Head
*
)
candidate
;
if
(
walValidHeadCksum
(
logContent
)
==
0
&&
walValidBodyCksum
(
logContent
)
==
0
)
{
if
(
walValidHeadCksum
(
logContent
)
==
0
&&
walValidBodyCksum
(
logContent
)
==
0
)
{
found
=
candidate
;
found
=
candidate
;
}
}
haystack
=
candidate
+
1
;
haystack
=
candidate
+
1
;
}
}
if
(
found
==
buf
)
{
if
(
found
==
buf
)
{
SWal
Head
*
logContent
=
(
SWal
Head
*
)
found
;
SWal
CkHead
*
logContent
=
(
SWalCk
Head
*
)
found
;
if
(
walValidHeadCksum
(
logContent
)
!=
0
||
walValidBodyCksum
(
logContent
)
!=
0
)
{
if
(
walValidHeadCksum
(
logContent
)
!=
0
||
walValidBodyCksum
(
logContent
)
!=
0
)
{
// file has to be deleted
// file has to be deleted
taosMemoryFree
(
buf
);
taosMemoryFree
(
buf
);
...
@@ -118,7 +101,7 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) {
...
@@ -118,7 +101,7 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal) {
}
}
}
}
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
SWal
Head
*
lastEntry
=
(
SWal
Head
*
)
found
;
SWal
CkHead
*
lastEntry
=
(
SWalCk
Head
*
)
found
;
return
lastEntry
->
head
.
version
;
return
lastEntry
->
head
.
version
;
}
}
...
...
source/libs/wal/src/walMgmt.c
浏览文件 @
0d41f9c8
...
@@ -117,8 +117,8 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
...
@@ -117,8 +117,8 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
pWal
->
lastRollSeq
=
-
1
;
pWal
->
lastRollSeq
=
-
1
;
// init write buffer
// init write buffer
memset
(
&
pWal
->
writeHead
,
0
,
sizeof
(
SWalHead
));
memset
(
&
pWal
->
writeHead
,
0
,
sizeof
(
SWal
Ck
Head
));
pWal
->
writeHead
.
head
.
headVer
=
WAL_HEAD
_VER
;
pWal
->
writeHead
.
head
.
protoVer
=
WAL_PROTO
_VER
;
pWal
->
writeHead
.
magic
=
WAL_MAGIC
;
pWal
->
writeHead
.
magic
=
WAL_MAGIC
;
if
(
taosThreadMutexInit
(
&
pWal
->
mutex
,
NULL
)
<
0
)
{
if
(
taosThreadMutexInit
(
&
pWal
->
mutex
,
NULL
)
<
0
)
{
...
...
source/libs/wal/src/walRead.c
浏览文件 @
0d41f9c8
...
@@ -33,7 +33,7 @@ SWalReadHandle *walOpenReadHandle(SWal *pWal) {
...
@@ -33,7 +33,7 @@ SWalReadHandle *walOpenReadHandle(SWal *pWal) {
taosThreadMutexInit
(
&
pRead
->
mutex
,
NULL
);
taosThreadMutexInit
(
&
pRead
->
mutex
,
NULL
);
pRead
->
pHead
=
taosMemoryMalloc
(
sizeof
(
SWalHead
));
pRead
->
pHead
=
taosMemoryMalloc
(
sizeof
(
SWal
Ck
Head
));
if
(
pRead
->
pHead
==
NULL
)
{
if
(
pRead
->
pHead
==
NULL
)
{
terrno
=
TSDB_CODE_WAL_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_WAL_OUT_OF_MEMORY
;
taosMemoryFree
(
pRead
);
taosMemoryFree
(
pRead
);
...
@@ -155,7 +155,7 @@ static int32_t walReadSeekVer(SWalReadHandle *pRead, int64_t ver) {
...
@@ -155,7 +155,7 @@ static int32_t walReadSeekVer(SWalReadHandle *pRead, int64_t ver) {
void
walSetReaderCapacity
(
SWalReadHandle
*
pRead
,
int32_t
capacity
)
{
pRead
->
capacity
=
capacity
;
}
void
walSetReaderCapacity
(
SWalReadHandle
*
pRead
,
int32_t
capacity
)
{
pRead
->
capacity
=
capacity
;
}
int32_t
walFetchHead
(
SWalReadHandle
*
pRead
,
int64_t
ver
,
SWalHead
*
pHead
)
{
int32_t
walFetchHead
(
SWalReadHandle
*
pRead
,
int64_t
ver
,
SWal
Ck
Head
*
pHead
)
{
int64_t
code
;
int64_t
code
;
// TODO: valid ver
// TODO: valid ver
...
@@ -170,8 +170,8 @@ int32_t walFetchHead(SWalReadHandle *pRead, int64_t ver, SWalHead *pHead) {
...
@@ -170,8 +170,8 @@ int32_t walFetchHead(SWalReadHandle *pRead, int64_t ver, SWalHead *pHead) {
ASSERT
(
taosValidFile
(
pRead
->
pReadLogTFile
)
==
true
);
ASSERT
(
taosValidFile
(
pRead
->
pReadLogTFile
)
==
true
);
code
=
taosReadFile
(
pRead
->
pReadLogTFile
,
pHead
,
sizeof
(
SWalHead
));
code
=
taosReadFile
(
pRead
->
pReadLogTFile
,
pHead
,
sizeof
(
SWal
Ck
Head
));
if
(
code
!=
sizeof
(
SWalHead
))
{
if
(
code
!=
sizeof
(
SWal
Ck
Head
))
{
return
-
1
;
return
-
1
;
}
}
...
@@ -186,7 +186,7 @@ int32_t walFetchHead(SWalReadHandle *pRead, int64_t ver, SWalHead *pHead) {
...
@@ -186,7 +186,7 @@ int32_t walFetchHead(SWalReadHandle *pRead, int64_t ver, SWalHead *pHead) {
return
0
;
return
0
;
}
}
int32_t
walSkipFetchBody
(
SWalReadHandle
*
pRead
,
const
SWalHead
*
pHead
)
{
int32_t
walSkipFetchBody
(
SWalReadHandle
*
pRead
,
const
SWal
Ck
Head
*
pHead
)
{
int64_t
code
;
int64_t
code
;
ASSERT
(
pRead
->
curVersion
==
pHead
->
head
.
version
);
ASSERT
(
pRead
->
curVersion
==
pHead
->
head
.
version
);
...
@@ -203,12 +203,12 @@ int32_t walSkipFetchBody(SWalReadHandle *pRead, const SWalHead *pHead) {
...
@@ -203,12 +203,12 @@ int32_t walSkipFetchBody(SWalReadHandle *pRead, const SWalHead *pHead) {
return
0
;
return
0
;
}
}
int32_t
walFetchBody
(
SWalReadHandle
*
pRead
,
SWalHead
**
ppHead
)
{
int32_t
walFetchBody
(
SWalReadHandle
*
pRead
,
SWal
Ck
Head
**
ppHead
)
{
SWal
ReadHead
*
pReadHead
=
&
((
*
ppHead
)
->
head
);
SWal
Cont
*
pReadHead
=
&
((
*
ppHead
)
->
head
);
int64_t
ver
=
pReadHead
->
version
;
int64_t
ver
=
pReadHead
->
version
;
if
(
pRead
->
capacity
<
pReadHead
->
bodyLen
)
{
if
(
pRead
->
capacity
<
pReadHead
->
bodyLen
)
{
void
*
ptr
=
taosMemoryRealloc
(
*
ppHead
,
sizeof
(
SWalHead
)
+
pReadHead
->
bodyLen
);
void
*
ptr
=
taosMemoryRealloc
(
*
ppHead
,
sizeof
(
SWal
Ck
Head
)
+
pReadHead
->
bodyLen
);
if
(
ptr
==
NULL
)
{
if
(
ptr
==
NULL
)
{
terrno
=
TSDB_CODE_WAL_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_WAL_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
...
@@ -241,18 +241,18 @@ int32_t walFetchBody(SWalReadHandle *pRead, SWalHead **ppHead) {
...
@@ -241,18 +241,18 @@ int32_t walFetchBody(SWalReadHandle *pRead, SWalHead **ppHead) {
return
0
;
return
0
;
}
}
int32_t
walReadWithHandle_s
(
SWalReadHandle
*
pRead
,
int64_t
ver
,
SWal
ReadHead
**
ppHead
)
{
int32_t
walReadWithHandle_s
(
SWalReadHandle
*
pRead
,
int64_t
ver
,
SWal
Cont
**
ppHead
)
{
taosThreadMutexLock
(
&
pRead
->
mutex
);
taosThreadMutexLock
(
&
pRead
->
mutex
);
if
(
walReadWithHandle
(
pRead
,
ver
)
<
0
)
{
if
(
walReadWithHandle
(
pRead
,
ver
)
<
0
)
{
taosThreadMutexUnlock
(
&
pRead
->
mutex
);
taosThreadMutexUnlock
(
&
pRead
->
mutex
);
return
-
1
;
return
-
1
;
}
}
*
ppHead
=
taosMemoryMalloc
(
sizeof
(
SWal
ReadHead
)
+
pRead
->
pHead
->
head
.
bodyLen
);
*
ppHead
=
taosMemoryMalloc
(
sizeof
(
SWal
Cont
)
+
pRead
->
pHead
->
head
.
bodyLen
);
if
(
*
ppHead
==
NULL
)
{
if
(
*
ppHead
==
NULL
)
{
taosThreadMutexUnlock
(
&
pRead
->
mutex
);
taosThreadMutexUnlock
(
&
pRead
->
mutex
);
return
-
1
;
return
-
1
;
}
}
memcpy
(
*
ppHead
,
&
pRead
->
pHead
->
head
,
sizeof
(
SWal
ReadHead
)
+
pRead
->
pHead
->
head
.
bodyLen
);
memcpy
(
*
ppHead
,
&
pRead
->
pHead
->
head
,
sizeof
(
SWal
Cont
)
+
pRead
->
pHead
->
head
.
bodyLen
);
taosThreadMutexUnlock
(
&
pRead
->
mutex
);
taosThreadMutexUnlock
(
&
pRead
->
mutex
);
return
0
;
return
0
;
}
}
...
@@ -282,8 +282,8 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) {
...
@@ -282,8 +282,8 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) {
ASSERT
(
taosValidFile
(
pRead
->
pReadLogTFile
)
==
true
);
ASSERT
(
taosValidFile
(
pRead
->
pReadLogTFile
)
==
true
);
code
=
taosReadFile
(
pRead
->
pReadLogTFile
,
pRead
->
pHead
,
sizeof
(
SWalHead
));
code
=
taosReadFile
(
pRead
->
pReadLogTFile
,
pRead
->
pHead
,
sizeof
(
SWal
Ck
Head
));
if
(
code
!=
sizeof
(
SWalHead
))
{
if
(
code
!=
sizeof
(
SWal
Ck
Head
))
{
if
(
code
<
0
)
if
(
code
<
0
)
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
else
{
else
{
...
@@ -301,7 +301,7 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) {
...
@@ -301,7 +301,7 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) {
}
}
if
(
pRead
->
capacity
<
pRead
->
pHead
->
head
.
bodyLen
)
{
if
(
pRead
->
capacity
<
pRead
->
pHead
->
head
.
bodyLen
)
{
void
*
ptr
=
taosMemoryRealloc
(
pRead
->
pHead
,
sizeof
(
SWalHead
)
+
pRead
->
pHead
->
head
.
bodyLen
);
void
*
ptr
=
taosMemoryRealloc
(
pRead
->
pHead
,
sizeof
(
SWal
Ck
Head
)
+
pRead
->
pHead
->
head
.
bodyLen
);
if
(
ptr
==
NULL
)
{
if
(
ptr
==
NULL
)
{
terrno
=
TSDB_CODE_WAL_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_WAL_OUT_OF_MEMORY
;
return
-
1
;
return
-
1
;
...
...
source/libs/wal/src/walWrite.c
浏览文件 @
0d41f9c8
...
@@ -142,10 +142,10 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
...
@@ -142,10 +142,10 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
return
-
1
;
return
-
1
;
}
}
// validate offset
// validate offset
SWalHead
head
;
SWal
Ck
Head
head
;
ASSERT
(
taosValidFile
(
pLogTFile
));
ASSERT
(
taosValidFile
(
pLogTFile
));
int64_t
size
=
taosReadFile
(
pLogTFile
,
&
head
,
sizeof
(
SWalHead
));
int64_t
size
=
taosReadFile
(
pLogTFile
,
&
head
,
sizeof
(
SWal
Ck
Head
));
if
(
size
!=
sizeof
(
SWalHead
))
{
if
(
size
!=
sizeof
(
SWal
Ck
Head
))
{
return
-
1
;
return
-
1
;
}
}
code
=
walValidHeadCksum
(
&
head
);
code
=
walValidHeadCksum
(
&
head
);
...
@@ -261,7 +261,7 @@ int32_t walEndSnapshot(SWal *pWal) {
...
@@ -261,7 +261,7 @@ int32_t walEndSnapshot(SWal *pWal) {
}
}
int
walRoll
(
SWal
*
pWal
)
{
int
walRoll
(
SWal
*
pWal
)
{
int
code
=
0
;
int
32_t
code
=
0
;
if
(
pWal
->
pWriteIdxTFile
!=
NULL
)
{
if
(
pWal
->
pWriteIdxTFile
!=
NULL
)
{
code
=
taosCloseFile
(
&
pWal
->
pWriteIdxTFile
);
code
=
taosCloseFile
(
&
pWal
->
pWriteIdxTFile
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
...
@@ -321,12 +321,13 @@ static int walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) {
...
@@ -321,12 +321,13 @@ static int walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) {
return
0
;
return
0
;
}
}
int
64
_t
walWriteWithSyncInfo
(
SWal
*
pWal
,
int64_t
index
,
tmsg_t
msgType
,
SSyncLogMeta
syncMeta
,
const
void
*
body
,
int
32
_t
walWriteWithSyncInfo
(
SWal
*
pWal
,
int64_t
index
,
tmsg_t
msgType
,
SSyncLogMeta
syncMeta
,
const
void
*
body
,
int32_t
bodyLen
)
{
int32_t
bodyLen
)
{
int
code
=
0
;
int
32_t
code
=
0
;
// no wal
// no wal
if
(
pWal
->
cfg
.
level
==
TAOS_WAL_NOLOG
)
return
0
;
if
(
pWal
->
cfg
.
level
==
TAOS_WAL_NOLOG
)
return
0
;
if
(
bodyLen
>
TSDB_MAX_WAL_SIZE
)
{
if
(
bodyLen
>
TSDB_MAX_WAL_SIZE
)
{
terrno
=
TSDB_CODE_WAL_SIZE_LIMIT
;
terrno
=
TSDB_CODE_WAL_SIZE_LIMIT
;
return
-
1
;
return
-
1
;
...
@@ -356,6 +357,7 @@ int64_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog
...
@@ -356,6 +357,7 @@ int64_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog
terrno
=
TSDB_CODE_WAL_INVALID_VER
;
terrno
=
TSDB_CODE_WAL_INVALID_VER
;
return
-
1
;
return
-
1
;
}
}
/*if (!tfValid(pWal->pWriteLogTFile)) return -1;*/
/*if (!tfValid(pWal->pWriteLogTFile)) return -1;*/
ASSERT
(
pWal
->
writeCur
>=
0
);
ASSERT
(
pWal
->
writeCur
>=
0
);
...
@@ -380,7 +382,7 @@ int64_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog
...
@@ -380,7 +382,7 @@ int64_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog
pWal
->
writeHead
.
cksumHead
=
walCalcHeadCksum
(
&
pWal
->
writeHead
);
pWal
->
writeHead
.
cksumHead
=
walCalcHeadCksum
(
&
pWal
->
writeHead
);
pWal
->
writeHead
.
cksumBody
=
walCalcBodyCksum
(
body
,
bodyLen
);
pWal
->
writeHead
.
cksumBody
=
walCalcBodyCksum
(
body
,
bodyLen
);
if
(
taosWriteFile
(
pWal
->
pWriteLogTFile
,
&
pWal
->
writeHead
,
sizeof
(
SWal
Head
))
!=
sizeof
(
SWal
Head
))
{
if
(
taosWriteFile
(
pWal
->
pWriteLogTFile
,
&
pWal
->
writeHead
,
sizeof
(
SWal
CkHead
))
!=
sizeof
(
SWalCk
Head
))
{
// TODO ftruncate
// TODO ftruncate
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
wError
(
"vgId:%d, file:%"
PRId64
".log, failed to write since %s"
,
pWal
->
cfg
.
vgId
,
walGetLastFileFirstVer
(
pWal
),
wError
(
"vgId:%d, file:%"
PRId64
".log, failed to write since %s"
,
pWal
->
cfg
.
vgId
,
walGetLastFileFirstVer
(
pWal
),
...
@@ -405,19 +407,19 @@ int64_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog
...
@@ -405,19 +407,19 @@ int64_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog
// set status
// set status
if
(
pWal
->
vers
.
firstVer
==
-
1
)
pWal
->
vers
.
firstVer
=
index
;
if
(
pWal
->
vers
.
firstVer
==
-
1
)
pWal
->
vers
.
firstVer
=
index
;
pWal
->
vers
.
lastVer
=
index
;
pWal
->
vers
.
lastVer
=
index
;
pWal
->
totSize
+=
sizeof
(
SWalHead
)
+
bodyLen
;
pWal
->
totSize
+=
sizeof
(
SWal
Ck
Head
)
+
bodyLen
;
if
(
walGetCurFileInfo
(
pWal
)
->
firstVer
==
-
1
)
{
if
(
walGetCurFileInfo
(
pWal
)
->
firstVer
==
-
1
)
{
walGetCurFileInfo
(
pWal
)
->
firstVer
=
index
;
walGetCurFileInfo
(
pWal
)
->
firstVer
=
index
;
}
}
walGetCurFileInfo
(
pWal
)
->
lastVer
=
index
;
walGetCurFileInfo
(
pWal
)
->
lastVer
=
index
;
walGetCurFileInfo
(
pWal
)
->
fileSize
+=
sizeof
(
SWalHead
)
+
bodyLen
;
walGetCurFileInfo
(
pWal
)
->
fileSize
+=
sizeof
(
SWal
Ck
Head
)
+
bodyLen
;
taosThreadMutexUnlock
(
&
pWal
->
mutex
);
taosThreadMutexUnlock
(
&
pWal
->
mutex
);
return
0
;
return
0
;
}
}
int
64
_t
walWrite
(
SWal
*
pWal
,
int64_t
index
,
tmsg_t
msgType
,
const
void
*
body
,
int32_t
bodyLen
)
{
int
32
_t
walWrite
(
SWal
*
pWal
,
int64_t
index
,
tmsg_t
msgType
,
const
void
*
body
,
int32_t
bodyLen
)
{
SSyncLogMeta
syncMeta
=
{
SSyncLogMeta
syncMeta
=
{
.
isWeek
=
-
1
,
.
isWeek
=
-
1
,
.
seqNum
=
UINT64_MAX
,
.
seqNum
=
UINT64_MAX
,
...
@@ -435,27 +437,3 @@ void walFsync(SWal *pWal, bool forceFsync) {
...
@@ -435,27 +437,3 @@ void walFsync(SWal *pWal, bool forceFsync) {
}
}
}
}
}
}
/*static int walValidateOffset(SWal* pWal, int64_t ver) {*/
/*int code = 0;*/
/*SWalHead *pHead = NULL;*/
/*code = (int)walRead(pWal, &pHead, ver);*/
/*if(pHead->head.version != ver) {*/
/*return -1;*/
/*}*/
/*return 0;*/
/*}*/
/*static int64_t walGetOffset(SWal* pWal, int64_t ver) {*/
/*int code = walSeekVer(pWal, ver);*/
/*if(code != 0) {*/
/*return -1;*/
/*}*/
/*code = walValidateOffset(pWal, ver);*/
/*if(code != 0) {*/
/*return -1;*/
/*}*/
/*return 0;*/
/*}*/
source/libs/wal/test/walMetaTest.cpp
浏览文件 @
0d41f9c8
...
@@ -148,7 +148,7 @@ TEST_F(WalCleanEnv, createNew) {
...
@@ -148,7 +148,7 @@ TEST_F(WalCleanEnv, createNew) {
walRollFileInfo
(
pWal
);
walRollFileInfo
(
pWal
);
ASSERT
(
pWal
->
fileInfoSet
!=
NULL
);
ASSERT
(
pWal
->
fileInfoSet
!=
NULL
);
ASSERT_EQ
(
pWal
->
fileInfoSet
->
size
,
1
);
ASSERT_EQ
(
pWal
->
fileInfoSet
->
size
,
1
);
WalFileInfo
*
pInfo
=
(
WalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
);
SWalFileInfo
*
pInfo
=
(
S
WalFileInfo
*
)
taosArrayGetLast
(
pWal
->
fileInfoSet
);
ASSERT_EQ
(
pInfo
->
firstVer
,
0
);
ASSERT_EQ
(
pInfo
->
firstVer
,
0
);
ASSERT_EQ
(
pInfo
->
lastVer
,
-
1
);
ASSERT_EQ
(
pInfo
->
lastVer
,
-
1
);
ASSERT_EQ
(
pInfo
->
closeTs
,
-
1
);
ASSERT_EQ
(
pInfo
->
closeTs
,
-
1
);
...
...
source/os/src/osFile.c
浏览文件 @
0d41f9c8
...
@@ -300,16 +300,14 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
...
@@ -300,16 +300,14 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
return
pFile
;
return
pFile
;
}
}
int64_t
taosCloseFile
(
TdFilePtr
*
ppFile
)
{
int32_t
taosCloseFile
(
TdFilePtr
*
ppFile
)
{
int32_t
code
=
0
;
if
(
ppFile
==
NULL
||
*
ppFile
==
NULL
)
{
if
(
ppFile
==
NULL
||
*
ppFile
==
NULL
)
{
return
0
;
return
0
;
}
}
#if FILE_WITH_LOCK
#if FILE_WITH_LOCK
taosThreadRwlockWrlock
(
&
((
*
ppFile
)
->
rwlock
));
taosThreadRwlockWrlock
(
&
((
*
ppFile
)
->
rwlock
));
#endif
#endif
if
(
ppFile
==
NULL
||
*
ppFile
==
NULL
)
{
return
0
;
}
if
((
*
ppFile
)
->
fp
!=
NULL
)
{
if
((
*
ppFile
)
->
fp
!=
NULL
)
{
fflush
((
*
ppFile
)
->
fp
);
fflush
((
*
ppFile
)
->
fp
);
fclose
((
*
ppFile
)
->
fp
);
fclose
((
*
ppFile
)
->
fp
);
...
@@ -320,9 +318,10 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
...
@@ -320,9 +318,10 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
HANDLE
h
=
(
HANDLE
)
_get_osfhandle
((
*
ppFile
)
->
fd
);
HANDLE
h
=
(
HANDLE
)
_get_osfhandle
((
*
ppFile
)
->
fd
);
!
FlushFileBuffers
(
h
);
!
FlushFileBuffers
(
h
);
#else
#else
fsync
((
*
ppFile
)
->
fd
);
// warning: never fsync silently in base lib
/*fsync((*ppFile)->fd);*/
#endif
#endif
close
((
*
ppFile
)
->
fd
);
c
ode
=
c
lose
((
*
ppFile
)
->
fd
);
(
*
ppFile
)
->
fd
=
-
1
;
(
*
ppFile
)
->
fd
=
-
1
;
}
}
(
*
ppFile
)
->
refId
=
0
;
(
*
ppFile
)
->
refId
=
0
;
...
@@ -332,7 +331,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
...
@@ -332,7 +331,7 @@ int64_t taosCloseFile(TdFilePtr *ppFile) {
#endif
#endif
taosMemoryFree
(
*
ppFile
);
taosMemoryFree
(
*
ppFile
);
*
ppFile
=
NULL
;
*
ppFile
=
NULL
;
return
0
;
return
code
;
}
}
int64_t
taosReadFile
(
TdFilePtr
pFile
,
void
*
buf
,
int64_t
count
)
{
int64_t
taosReadFile
(
TdFilePtr
pFile
,
void
*
buf
,
int64_t
count
)
{
...
@@ -560,6 +559,8 @@ int32_t taosFsyncFile(TdFilePtr pFile) {
...
@@ -560,6 +559,8 @@ int32_t taosFsyncFile(TdFilePtr pFile) {
return
0
;
return
0
;
}
}
// this implementation is WRONG
// fflush is not a replacement of fsync
if
(
pFile
->
fp
!=
NULL
)
return
fflush
(
pFile
->
fp
);
if
(
pFile
->
fp
!=
NULL
)
return
fflush
(
pFile
->
fp
);
if
(
pFile
->
fd
>=
0
)
{
if
(
pFile
->
fd
>=
0
)
{
#ifdef WINDOWS
#ifdef WINDOWS
...
...
source/os/src/osString.c
浏览文件 @
0d41f9c8
...
@@ -202,7 +202,7 @@ int32_t taosHexEncode(const char *src, char *dst, int32_t len) {
...
@@ -202,7 +202,7 @@ int32_t taosHexEncode(const char *src, char *dst, int32_t len) {
}
}
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
sprintf
(
dst
+
i
*
2
,
"%02x"
,
src
[
i
]
&
0xff
);
sprintf
(
dst
+
i
*
2
,
"%02x"
,
src
[
i
]);
}
}
return
0
;
return
0
;
...
@@ -213,10 +213,10 @@ int32_t taosHexDecode(const char *src, char *dst, int32_t len) {
...
@@ -213,10 +213,10 @@ int32_t taosHexDecode(const char *src, char *dst, int32_t len) {
return
-
1
;
return
-
1
;
}
}
uint
16
_t
hn
,
ln
,
out
;
uint
8
_t
hn
,
ln
,
out
;
for
(
int
i
=
0
,
j
=
0
;
i
<
len
*
2
;
i
+=
2
,
++
j
)
{
for
(
int
i
=
0
,
j
=
0
;
i
<
len
*
2
;
i
+=
2
,
++
j
)
{
hn
=
src
[
i
]
>
'9'
?
src
[
i
]
-
'
A
'
+
10
:
src
[
i
]
-
'0'
;
hn
=
src
[
i
]
>
'9'
?
src
[
i
]
-
'
a
'
+
10
:
src
[
i
]
-
'0'
;
ln
=
src
[
i
+
1
]
>
'9'
?
src
[
i
+
1
]
-
'
A
'
+
10
:
src
[
i
+
1
]
-
'0'
;
ln
=
src
[
i
+
1
]
>
'9'
?
src
[
i
+
1
]
-
'
a
'
+
10
:
src
[
i
+
1
]
-
'0'
;
out
=
(
hn
<<
4
)
|
ln
;
out
=
(
hn
<<
4
)
|
ln
;
memcpy
(
dst
+
j
,
&
out
,
1
);
memcpy
(
dst
+
j
,
&
out
,
1
);
...
...
source/util/src/terror.c
浏览文件 @
0d41f9c8
...
@@ -394,6 +394,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_DUPLICATTED_OPERATION, "Duplicatted operation
...
@@ -394,6 +394,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_DUPLICATTED_OPERATION, "Duplicatted operation
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_TASK_MSG_ERROR
,
"Task message error"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_TASK_MSG_ERROR
,
"Task message error"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_JOB_FREED
,
"Job already freed"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_JOB_FREED
,
"Job already freed"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_TASK_STATUS_ERROR
,
"Task status error"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_TASK_STATUS_ERROR
,
"Task status error"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_JSON_IN_ERROR
,
"Json not support in in/notin operator"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR
,
"Json not support in this place"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_JSON_IN_GROUP_ERROR
,
"Json not support in group/partition by"
)
// grant
// grant
TAOS_DEFINE_ERROR
(
TSDB_CODE_GRANT_EXPIRED
,
"License expired"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_GRANT_EXPIRED
,
"License expired"
)
...
@@ -429,6 +432,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NEW_CONFIG_ERROR, "Sync new config error
...
@@ -429,6 +432,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NEW_CONFIG_ERROR, "Sync new config error
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_RECONFIG_NOT_READY
,
"Sync not ready for reconfig"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_RECONFIG_NOT_READY
,
"Sync not ready for reconfig"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_PROPOSE_NOT_READY
,
"Sync not ready for propose"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_PROPOSE_NOT_READY
,
"Sync not ready for propose"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_STANDBY_NOT_READY
,
"Sync not ready for standby"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_STANDBY_NOT_READY
,
"Sync not ready for standby"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_BATCH_ERROR
,
"Sync batch error"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_INTERNAL_ERROR
,
"Sync internal error"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SYN_INTERNAL_ERROR
,
"Sync internal error"
)
// wal
// wal
...
...
source/util/src/tpagedbuf.c
浏览文件 @
0d41f9c8
...
@@ -193,7 +193,9 @@ static char* doFlushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
...
@@ -193,7 +193,9 @@ static char* doFlushPageToDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
char
*
pDataBuf
=
pg
->
pData
;
char
*
pDataBuf
=
pg
->
pData
;
memset
(
pDataBuf
,
0
,
getAllocPageSize
(
pBuf
->
pageSize
));
memset
(
pDataBuf
,
0
,
getAllocPageSize
(
pBuf
->
pageSize
));
#ifdef BUF_PAGE_DEBUG
uDebug
(
"page_flush %p, pageId:%d, offset:%d"
,
pDataBuf
,
pg
->
pageId
,
pg
->
offset
);
#endif
pg
->
length
=
size
;
// on disk size
pg
->
length
=
size
;
// on disk size
return
pDataBuf
;
return
pDataBuf
;
}
}
...
@@ -440,6 +442,9 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t groupId, int32_t* pageId) {
...
@@ -440,6 +442,9 @@ void* getNewBufPage(SDiskbasedBuf* pBuf, int32_t groupId, int32_t* pageId) {
}
}
((
void
**
)
pi
->
pData
)[
0
]
=
pi
;
((
void
**
)
pi
->
pData
)[
0
]
=
pi
;
#ifdef BUF_PAGE_DEBUG
uDebug
(
"page_getNewBufPage , pi->pData:%p, pageId:%d, offset:%"
PRId64
,
pi
->
pData
,
pi
->
pageId
,
pi
->
offset
);
#endif
return
(
void
*
)(
GET_DATA_PAYLOAD
(
pi
));
return
(
void
*
)(
GET_DATA_PAYLOAD
(
pi
));
}
}
...
@@ -462,7 +467,9 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
...
@@ -462,7 +467,9 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
lruListMoveToFront
(
pBuf
->
lruList
,
(
*
pi
));
lruListMoveToFront
(
pBuf
->
lruList
,
(
*
pi
));
(
*
pi
)
->
used
=
true
;
(
*
pi
)
->
used
=
true
;
#ifdef BUF_PAGE_DEBUG
uDebug
(
"page_getBufPage1 pageId:%d, offset:%"
PRId64
,
(
*
pi
)
->
pageId
,
(
*
pi
)
->
offset
);
#endif
return
(
void
*
)(
GET_DATA_PAYLOAD
(
*
pi
));
return
(
void
*
)(
GET_DATA_PAYLOAD
(
*
pi
));
}
else
{
// not in memory
}
else
{
// not in memory
assert
((
*
pi
)
->
pData
==
NULL
&&
(
*
pi
)
->
pn
==
NULL
&&
(((
*
pi
)
->
length
>=
0
&&
(
*
pi
)
->
offset
>=
0
)
||
((
*
pi
)
->
length
==
-
1
&&
(
*
pi
)
->
offset
==
-
1
)));
assert
((
*
pi
)
->
pData
==
NULL
&&
(
*
pi
)
->
pn
==
NULL
&&
(((
*
pi
)
->
length
>=
0
&&
(
*
pi
)
->
offset
>=
0
)
||
((
*
pi
)
->
length
==
-
1
&&
(
*
pi
)
->
offset
==
-
1
)));
...
@@ -494,7 +501,9 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
...
@@ -494,7 +501,9 @@ void* getBufPage(SDiskbasedBuf* pBuf, int32_t id) {
return
NULL
;
return
NULL
;
}
}
}
}
#ifdef BUF_PAGE_DEBUG
uDebug
(
"page_getBufPage2 pageId:%d, offset:%"
PRId64
,
(
*
pi
)
->
pageId
,
(
*
pi
)
->
offset
);
#endif
return
(
void
*
)(
GET_DATA_PAYLOAD
(
*
pi
));
return
(
void
*
)(
GET_DATA_PAYLOAD
(
*
pi
));
}
}
}
}
...
@@ -506,8 +515,11 @@ void releaseBufPage(SDiskbasedBuf* pBuf, void* page) {
...
@@ -506,8 +515,11 @@ void releaseBufPage(SDiskbasedBuf* pBuf, void* page) {
}
}
void
releaseBufPageInfo
(
SDiskbasedBuf
*
pBuf
,
SPageInfo
*
pi
)
{
void
releaseBufPageInfo
(
SDiskbasedBuf
*
pBuf
,
SPageInfo
*
pi
)
{
#ifdef BUF_PAGE_DEBUG
uDebug
(
"page_releaseBufPageInfo pageId:%d, used:%d, offset:%"
PRId64
,
pi
->
pageId
,
pi
->
used
,
pi
->
offset
);
#endif
assert
(
pi
->
pData
!=
NULL
&&
pi
->
used
==
true
);
assert
(
pi
->
pData
!=
NULL
&&
pi
->
used
==
true
);
// assert(pi->pData != NULL);
pi
->
used
=
false
;
pi
->
used
=
false
;
pBuf
->
statis
.
releasePages
+=
1
;
pBuf
->
statis
.
releasePages
+=
1
;
}
}
...
...
source/util/src/tutil.c
浏览文件 @
0d41f9c8
...
@@ -16,6 +16,23 @@
...
@@ -16,6 +16,23 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "tutil.h"
#include "tutil.h"
void
*
tmemmem
(
const
char
*
haystack
,
int32_t
hlen
,
const
char
*
needle
,
int32_t
nlen
)
{
const
char
*
limit
;
if
(
nlen
==
0
||
hlen
<
nlen
)
{
return
NULL
;
}
limit
=
haystack
+
hlen
-
nlen
+
1
;
while
((
haystack
=
(
char
*
)
memchr
(
haystack
,
needle
[
0
],
limit
-
haystack
))
!=
NULL
)
{
if
(
memcmp
(
haystack
,
needle
,
nlen
)
==
0
)
{
return
(
void
*
)
haystack
;
}
haystack
++
;
}
return
NULL
;
}
int32_t
strdequote
(
char
*
z
)
{
int32_t
strdequote
(
char
*
z
)
{
if
(
z
==
NULL
)
{
if
(
z
==
NULL
)
{
return
0
;
return
0
;
...
...
tests/script/jenkins/basic.txt
浏览文件 @
0d41f9c8
...
@@ -30,13 +30,6 @@
...
@@ -30,13 +30,6 @@
./test.sh -f tsim/dnode/balance2.sim
./test.sh -f tsim/dnode/balance2.sim
./test.sh -f tsim/dnode/balance3.sim
./test.sh -f tsim/dnode/balance3.sim
./test.sh -f tsim/dnode/balancex.sim
./test.sh -f tsim/dnode/balancex.sim
#./test.sh -f tsim/dnode/cluster_alter.sim
#./test.sh -f tsim/dnode/cluster_balance1.sim
#./test.sh -f tsim/dnode/cluster_balance2.sim
#./test.sh -f tsim/dnode/cluster_balance3.sim
#./test.sh -f tsim/dnode/cluster_cache.sim
#./test.sh -f tsim/dnode/cluster_flowctrl.sim
#./test.sh -f tsim/dnode/cluster_vgroup100.sim
./test.sh -f tsim/dnode/create_dnode.sim
./test.sh -f tsim/dnode/create_dnode.sim
./test.sh -f tsim/dnode/drop_dnode_has_mnode.sim
./test.sh -f tsim/dnode/drop_dnode_has_mnode.sim
./test.sh -f tsim/dnode/drop_dnode_has_qnode_snode.sim
./test.sh -f tsim/dnode/drop_dnode_has_qnode_snode.sim
...
...
tests/script/tsim/dnode/cluster_alter.sim
已删除
100644 → 0
浏览文件 @
344ef7e1
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4
system sh/cfg.sh -n dnode1 -c role -v 1
system sh/cfg.sh -n dnode2 -c role -v 2
system sh/cfg.sh -n dnode3 -c role -v 2
system sh/cfg.sh -n dnode4 -c role -v 2
system sh/cfg.sh -n dnode1 -c balanceInterval -v 10
system sh/cfg.sh -n dnode2 -c balanceInterval -v 10
system sh/cfg.sh -n dnode3 -c balanceInterval -v 10
system sh/cfg.sh -n dnode4 -c balanceInterval -v 10
system sh/cfg.sh -n dnode1 -c wallevel -v 2
system sh/cfg.sh -n dnode2 -c wallevel -v 2
system sh/cfg.sh -n dnode3 -c wallevel -v 2
system sh/cfg.sh -n dnode4 -c wallevel -v 2
system sh/cfg.sh -n dnode1 -c balance -v 0
system sh/cfg.sh -n dnode2 -c balance -v 0
system sh/cfg.sh -n dnode3 -c balance -v 0
system sh/cfg.sh -n dnode4 -c balance -v 0
print ========== step1
system sh/exec.sh -n dnode1 -s start
sql connect
sleep 2000
sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start
sleep 2000
print ========== step2
sql create database d1
sql create table d1.t1 (t timestamp, i int)
sql insert into d1.t1 values(now+1s, 15)
sql insert into d1.t1 values(now+2s, 14)
sql insert into d1.t1 values(now+3s, 13)
sql insert into d1.t1 values(now+4s, 12)
sql insert into d1.t1 values(now+5s, 11)
print ========== step3
sleep 2000
sql create dnode $hostname3
system sh/exec.sh -n dnode3 -s start
sql create dnode $hostname4
system sh/exec.sh -n dnode4 -s start
sql show dnodes
print dnode1 openVnodes $data2_1
print dnode2 openVnodes $data2_2
print dnode3 openVnodes $data2_3
print dnode4 openVnodes $data2_4
if $data2_1 != 0 then
return -1
endi
if $data2_2 != 1 then
return -1
endi
if $data2_3 != 0 then
return -1
endi
if $data2_4 != 0 then
return -1
endi
print ========== step4
sql alter dnode 2 balance "vnode:2-dnode:3"
$x = 0
show4:
$x = $x + 1
sleep 2000
if $x == 10 then
return -1
endi
sql show dnodes
print dnode1 openVnodes $data2_1
print dnode2 openVnodes $data2_2
print dnode3 openVnodes $data2_3
print dnode4 openVnodes $data2_4
if $data2_2 != 0 then
goto show4
endi
if $data2_3 != 1 then
goto show4
endi
if $data2_4 != 0 then
goto show4
endi
print ========== step5
sql alter dnode 3 balance "vnode:2-dnode:4"
$x = 0
show5:
$x = $x + 1
sleep 2000
if $x == 10 then
return -1
endi
sql show dnodes
print dnode1 openVnodes $data2_1
print dnode2 openVnodes $data2_2
print dnode3 openVnodes $data2_3
print dnode4 openVnodes $data2_4
if $data2_2 != 0 then
goto show5
endi
if $data2_3 != 0 then
goto show5
endi
if $data2_4 != 1 then
goto show5
endi
print ========== step6
sql alter dnode 4 balance "vnode:2-dnode:2"
$x = 0
show6:
$x = $x + 1
sleep 2000
if $x == 10 then
return -1
endi
sql show dnodes
print dnode1 openVnodes $data2_1
print dnode2 openVnodes $data2_2
print dnode3 openVnodes $data2_3
print dnode4 openVnodes $data2_4
if $data2_2 != 1 then
goto show6
endi
if $data2_3 != 0 then
goto show6
endi
if $data2_4 != 0 then
goto show6
endi
print ========== step7
sql select * from d1.t1 order by t desc
print $data01 $data11 $data21 $data31 $data41
if $data01 != 11 then
return -1
endi
if $data11 != 12 then
return -1
endi
if $data21 != 13 then
return -1
endi
if $data31 != 14 then
return -1
endi
if $data41 != 15 then
return -1
endi
print ========== step8
sql_error sql alter dnode 4 balance "vnode:2-dnode:5"
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT
\ No newline at end of file
tests/script/tsim/dnode/cluster_balance1.sim
已删除
100644 → 0
浏览文件 @
344ef7e1
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4
system sh/deploy.sh -n dnode5 -i 5
system sh/deploy.sh -n dnode6 -i 6
system sh/deploy.sh -n dnode7 -i 7
system sh/deploy.sh -n dnode8 -i 8
system sh/cfg.sh -n dnode1 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode2 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode3 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode4 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode5 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode6 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode7 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode8 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode5 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode6 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode7 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode8 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode1 -c wallevel -v 1
system sh/cfg.sh -n dnode2 -c wallevel -v 1
system sh/cfg.sh -n dnode3 -c wallevel -v 1
system sh/cfg.sh -n dnode4 -c wallevel -v 1
system sh/cfg.sh -n dnode5 -c wallevel -v 1
system sh/cfg.sh -n dnode6 -c wallevel -v 1
system sh/cfg.sh -n dnode7 -c wallevel -v 1
system sh/cfg.sh -n dnode8 -c wallevel -v 1
system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode4 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode5 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode6 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode7 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode8 -c maxTablesPerVnode -v 4
print ============== step1
print ========= start dnode1
system sh/exec.sh -n dnode1 -s start
sql connect
sql create database c_b1_d1
sql use c_b1_d1
sql create table c_b1_t1 (t timestamp, i int)
sql insert into c_b1_t1 values(1520000020015, 15)
sql insert into c_b1_t1 values(1520000021014, 14)
sql insert into c_b1_t1 values(1520000022013, 13)
sql insert into c_b1_t1 values(1520000023012, 12)
sql insert into c_b1_t1 values(1520000024011, 11)
sql create database c_b1_d2
sql use c_b1_d2
sql create table c_b1_t2 (t timestamp, i int)
sql insert into c_b1_t2 values(1520000020025, 25)
sql insert into c_b1_t2 values(1520000021024, 24)
sql insert into c_b1_t2 values(1520000022023, 23)
sql insert into c_b1_t2 values(1520000023022, 22)
sql insert into c_b1_t2 values(1520000024021, 21)
sql show dnodes
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 2 then
return -1
endi
if $dnode2Vnodes != null then
return -1
endi
print ============================== step2
print ========= start dnode2
sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start
$x = 0
show2:
$x = $x + 1
sleep 1000
if $x == 40 then
return -1
endi
sql show dnodes -x show2
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 1 then
goto show2
endi
if $dnode2Vnodes != 1 then
goto show2
endi
sql show mnodes
$dnode1Role = $data2_1
$dnode2Role = $data2_2
print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print ============================== step3
print ========= add db3
sql create database c_b1_d3
sql use c_b1_d3
sql create table c_b1_t3 (t timestamp, i int)
sql insert into c_b1_t3 values(1520000020035, 35)
sql insert into c_b1_t3 values(1520000021034, 34)
sql insert into c_b1_t3 values(1520000022033, 33)
sql insert into c_b1_t3 values(1520000023032, 32)
sql insert into c_b1_t3 values(1520000024031, 31)
print ============================== step4
print ========= drop dnode2
sql drop dnode $hostname2
$x = 0
show4:
$x = $x + 1
sleep 1000
if $x == 40 then
return -1
endi
sql show dnodes -x show4
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes
if $dnode1Vnodes != 3 then
goto show4
endi
if $dnode2Vnodes != null then
goto show4
endi
sql show mnodes
$dnode1Role = $data2_1
$dnode2Role = $data2_2
$dnode3Role = $data2_3
$dnode4Role = $data2_4
print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role
print ============================== step5
print ========= add dnode2
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s start
sql create dnode $hostname3
$x = 0
show5:
$x = $x + 1
sleep 1000
if $x == 40 then
return -1
endi
sql show dnodes -x show5
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode3Vnodes = $data2_3
print dnode2 $dnode3Vnodes
if $dnode1Vnodes != 2 then
goto show5
endi
if $dnode3Vnodes != 1 then
goto show5
endi
sql show mnodes
$dnode1Role = $data2_1
$dnode3Role = $data2_3
$dnode4Role = $data2_4
print dnode1 ==> $dnode1Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role
if $dnode1Role != master then
return -1
endi
if $dnode3Role != slave then
return -1
endi
print ============================== step6
sql_error drop dnode $hostname1
print ============================== step7
sql_error create dnode $hostname1
print ============================== step8
sql drop dnode $hostname3
$x = 0
show8:
$x = $x + 1
sleep 1000
if $x == 40 then
return -1
endi
sql show dnodes -x show8
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 3 then
goto show8
endi
if $dnode3Vnodes != null then
goto show8
endi
sql show mnodes
$dnode1Role = $data2_1
$dnode3Role = $data2_3
$dnode4Role = $data2_4
print dnode1 ==> $dnode1Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role
if $dnode1Role != master then
return -1
endi
if $dnode3Role != null then
return -1
endi
print ============================== step9
sql create dnode $hostname4
system sh/exec.sh -n dnode4 -s start
$x = 0
show9:
$x = $x + 1
sleep 1000
if $x == 40 then
return -1
endi
sql show dnodes -x show9
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 2 then
goto show9
endi
if $dnode4Vnodes != 1 then
goto show9
endi
sql show mnodes
$dnode1Role = $data2_1
$dnode4Role = $data2_4
print dnode1 ==> $dnode1Role
print dnode4 ==> $dnode4Role
if $dnode1Role != master then
return -1
endi
if $dnode4Role != slave then
return -1
endi
print ============================== step10
sql create database c_b1_d4
sql use c_b1_d4
sql create table c_b1_t4 (t timestamp, i int)
sql insert into c_b1_t4 values(1520000020045, 45)
sql insert into c_b1_t4 values(1520000021044, 44)
sql insert into c_b1_t4 values(1520000022043, 43)
sql insert into c_b1_t4 values(1520000023042, 42)
sql insert into c_b1_t4 values(1520000024041, 41)
$x = 0
show10:
$x = $x + 1
sleep 1000
if $x == 40 then
return -1
endi
sql show dnodes -x show10
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes
if $dnode1Vnodes != 2 then
goto show10
endi
if $dnode4Vnodes != 2 then
goto show10
endi
sql reset query cache
sql use c_b1_d3
sql insert into c_b1_t3 values(1520000025036, 36)
sql use c_b1_d2
sql insert into c_b1_t2 values(1520000025026, 26)
print ============================== step12
sql create database c_b1_d5
sql use c_b1_d5
sql_error create table c_b1_t5 (t timestamp, i int) -x error3
print ============================== step13
sql create dnode $hostname5
system sh/exec.sh -n dnode5 -s start
$x = 0
step13:
$x = $x + 1
sleep 1000
if $x == 40 then
return -1
endi
sql show dnodes
print dnode1 $data4_1
print dnode2 $data4_2
print dnode3 $data4_3
print dnode4 $data4_4
print dnode5 $data4_5
if $data4_5 != ready then
goto step13
endi
sql show mnodes
$dnode1Role = $data2_1
$dnode4Role = $data2_4
$dnode5Role = $data2_5
print dnode1 ==> $dnode1Role
print dnode4 ==> $dnode4Role
print dnode5 ==> $dnode5Role
sql use c_b1_d5;
sql create table c_b1_t5 (t timestamp, i int)
sql insert into c_b1_t5 values(1520000020055, 55)
sql insert into c_b1_t5 values(1520000021054, 54)
sql insert into c_b1_t5 values(1520000022053, 53)
sql insert into c_b1_t5 values(1520000023052, 52)
sql insert into c_b1_t5 values(1520000024051, 51)
sql create database c_b1_d6
sql use c_b1_d6
sql create table c_b1_t6 (t timestamp, i int)
sql insert into c_b1_t6 values(1520000020065, 65)
sql insert into c_b1_t6 values(1520000021064, 64)
sql insert into c_b1_t6 values(1520000022063, 63)
sql insert into c_b1_t6 values(1520000023062, 62)
sql insert into c_b1_t6 values(1520000024061, 61)
sql show dnodes
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode4Vnodes = $data2_4
print dnode4 $dnode2Vnodes
$dnode5Vnodes = $data2_5
print dnode5 $dnode2Vnodes
if $dnode1Vnodes != 2 then
goto step13
endi
if $dnode4Vnodes != 2 then
goto step13
endi
if $dnode5Vnodes != 2 then
goto step13
endi
print ============================== step14
sql create dnode $hostname6
system sh/exec.sh -n dnode6 -s start
$x = 0
step14:
$x = $x + 1
sleep 1000
if $x == 40 then
return -1
endi
sql show dnodes
print dnode1 $data4_1
print dnode2 $data4_2
print dnode3 $data4_3
print dnode4 $data4_4
print dnode4 $data4_5
if $data4_6 != ready then
goto step14
endi
sql create database c_b1_d7
sql use c_b1_d7
sql create table c_b1_t7 (t timestamp, i int)
sql insert into c_b1_t7 values(1520000020075, 75)
sql insert into c_b1_t7 values(1520000021074, 74)
sql insert into c_b1_t7 values(1520000022073, 73)
sql insert into c_b1_t7 values(1520000023072, 72)
sql insert into c_b1_t7 values(1520000024071, 71)
sql create database c_b1_d8
sql use c_b1_d8
sql create table c_b1_t8 (t timestamp, i int)
sql insert into c_b1_t8 values(1520000020085, 85)
sql insert into c_b1_t8 values(1520000021084, 84)
sql insert into c_b1_t8 values(1520000022083, 83)
sql insert into c_b1_t8 values(1520000023082, 82)
sql insert into c_b1_t8 values(1520000024081, 81)
$x = 0
show14:
$x = $x + 1
sleep 1000
if $x == 30 then
return -1
endi
sql show dnodes -x show14
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes
$dnode5Vnodes = $data2_5
print dnode5 $dnode5Vnodes
$dnode6Vnodes = $data2_6
print dnode6 $dnode6Vnodes
if $dnode1Vnodes != 2 then
goto show14
endi
if $dnode4Vnodes != 2 then
goto show14
endi
if $dnode5Vnodes != 2 then
goto show14
endi
if $dnode6Vnodes != 2 then
goto show14
endi
sql reset query cache
sleep 1000
print ============================== step17
print ========= check data
sql reset query cache
sleep 100
sql use c_b1_d1
sql select * from c_b1_d1.c_b1_t1
print $rows
print $data01 $data11 $data21 $data31 $data41
if $rows != 5 then
return -1
endi
sql use c_b1_d2
sql select * from c_b1_d2.c_b1_t2
print $rows
print $data01 $data11 $data21 $data31 $data41
if $rows != 6 then
return -1
endi
sql use c_b1_d3
sql select * from c_b1_d3.c_b1_t3 order by t desc
print $rows
print $data01 $data11 $data21 $data31 $data41
if $rows != 6 then
return -1
endi
if $data01 != 36 then
return -1
endi
sql use c_b1_d4
sql select * from c_b1_d4.c_b1_t4 order by t desc
print $rows
print $data01 $data11 $data21 $data31 $data41
sql use c_b1_d5
sql select * from c_b1_d5.c_b1_t5 order by t desc
print $rows
print $data01 $data11 $data21 $data31 $data41
if $data01 != 51 then
return -1
endi
if $data11 != 52 then
return -1
endi
if $data21 != 53 then
return -1
endi
if $data31 != 54 then
return -1
endi
if $data41 != 55 then
return -1
endi
sql use c_b1_d6
sql select * from c_b1_d6.c_b1_t6 order by t desc
print $rows
print $data01 $data11 $data21 $data31 $data41
if $data01 != 61 then
return -1
endi
if $data11 != 62 then
return -1
endi
if $data21 != 63 then
return -1
endi
if $data31 != 64 then
return -1
endi
if $data41 != 65 then
return -1
endi
sql use c_b1_d7
sql select * from c_b1_d7.c_b1_t7 order by t desc
print $rows
print $data01 $data11 $data21 $data31 $data41
if $data01 != 71 then
return -1
endi
if $data11 != 72 then
return -1
endi
if $data21 != 73 then
return -1
endi
if $data31 != 74 then
return -1
endi
if $data41 != 75 then
return -1
endi
sql use c_b1_d8
sql select * from c_b1_d8.c_b1_t8 order by t desc
print $rows
print $data01 $data11 $data21 $data31 $data41
if $data01 != 81 then
return -1
endi
if $data11 != 82 then
return -1
endi
if $data21 != 83 then
return -1
endi
if $data31 != 84 then
return -1
endi
if $data41 != 85 then
return -1
endi
print ============================================ over=
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT
system sh/exec.sh -n dnode5 -s stop -x SIGINT
system sh/exec.sh -n dnode6 -s stop -x SIGINT
system sh/exec.sh -n dnode7 -s stop -x SIGINT
system sh/exec.sh -n dnode8 -s stop -x SIGINT
\ No newline at end of file
tests/script/tsim/dnode/cluster_balance2.sim
已删除
100644 → 0
浏览文件 @
344ef7e1
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4
system sh/deploy.sh -n dnode5 -i 5
system sh/deploy.sh -n dnode6 -i 6
system sh/deploy.sh -n dnode7 -i 7
system sh/deploy.sh -n dnode8 -i 8
system sh/cfg.sh -n dnode1 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode2 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode3 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode4 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode5 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode6 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode7 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode8 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode1 -c wallevel -v 1
system sh/cfg.sh -n dnode2 -c wallevel -v 1
system sh/cfg.sh -n dnode3 -c wallevel -v 1
system sh/cfg.sh -n dnode4 -c wallevel -v 1
system sh/cfg.sh -n dnode5 -c wallevel -v 1
system sh/cfg.sh -n dnode6 -c wallevel -v 1
system sh/cfg.sh -n dnode7 -c wallevel -v 1
system sh/cfg.sh -n dnode8 -c wallevel -v 1
system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode5 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode6 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode7 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode8 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode4 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode5 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode6 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode7 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode8 -c maxTablesPerVnode -v 4
print ============== step1
print ========= start dnode1
system sh/exec.sh -n dnode1 -s start
sql connect
sql create dnode $hostname2
sql create dnode $hostname3
system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
$x = 0
step1:
$x = $x + 1
sleep 1000
if $x == 10 then
return -1
endi
sql show dnodes
print dnode1 $data4_1
print dnode2 $data4_2
print dnode3 $data4_3
print dnode4 $data4_4
if $data4_1 != ready then
goto step1
endi
if $data4_2 != ready then
goto step1
endi
if $data4_3 != ready then
goto step1
endi
sql show mnodes
print mnode1 $data2_1
print mnode1 $data2_2
print mnode1 $data2_3
if $data2_1 != master then
goto step1
endi
if $data2_2 != slave then
goto step1
endi
if $data2_3 != slave then
goto step1
endi
sql create database c_b2_d1 replica 2
sql use c_b2_d1
sql create table c_b2_t1 (t timestamp, i int)
sql insert into c_b2_t1 values(1520000020015, 15)
sql insert into c_b2_t1 values(1520000021014, 14)
sql insert into c_b2_t1 values(1520000022013, 13)
sql insert into c_b2_t1 values(1520000023012, 12)
sql insert into c_b2_t1 values(1520000024011, 11)
sql create database c_b2_d2 replica 2
sql use c_b2_d2
sql create table c_b2_t2 (t timestamp, i int)
sql insert into c_b2_t2 values(1520000020025, 25)
sql insert into c_b2_t2 values(1520000021024, 24)
sql insert into c_b2_t2 values(1520000022023, 23)
sql insert into c_b2_t2 values(1520000023022, 22)
sql insert into c_b2_t2 values(1520000024021, 21)
sql create database c_b2_d3 replica 2
sql use c_b2_d3
sql create table c_b2_t3 (t timestamp, i int)
sql insert into c_b2_t3 values(1520000020035, 35)
sql insert into c_b2_t3 values(1520000021034, 34)
sql insert into c_b2_t3 values(1520000022033, 33)
sql insert into c_b2_t3 values(1520000023032, 32)
sql insert into c_b2_t3 values(1520000024031, 31)
$x = 0
show1:
$x = $x + 1
sleep 3000
if $x == 20 then
return -1
endi
sql show dnodes -x show1
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 2 then
goto show1
endi
if $dnode2Vnodes != 2 then
goto show1
endi
if $dnode3Vnodes != 2 then
goto show1
endi
print ============================== step2
print ========= drop dnode2
sql drop dnode $hostname2
$x = 0
show2:
$x = $x + 1
sleep 1000
if $x == 30 then
return -1
endi
sql show dnodes -x show2
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode2Vnodes = $data2_2
print dnode2 $dnode2Vnodes
$dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 3 then
goto show2
endi
if $dnode2Vnodes != null then
goto show2
endi
if $dnode3Vnodes != 3 then
goto show2
endi
sql show mnodes
$dnode1Role = $data2_1
$dnode2Role = $data2_2
$dnode3Role = $data2_3
$dnode4Role = $data2_4
print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role
system sh/exec.sh -n dnode2 -s stop -x SIGINT
print ============================== step3
print ========= start dnode4
sql create dnode $hostname4
system sh/exec.sh -n dnode4 -s start
$x = 0
show3:
$x = $x + 1
sleep 1000
if $x == 30 then
return -1
endi
sql show dnodes -x show3
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes
$dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 2 then
goto show3
endi
if $dnode4Vnodes != 2 then
goto show3
endi
if $dnode3Vnodes != 2 then
goto show3
endi
sql show mnodes
$dnode1Role = $data2_1
$dnode2Role = $data2_2
$dnode3Role = $data2_3
$dnode4Role = $data2_4
print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role
if $dnode1Role != master then
return -1
endi
if $dnode2Role != null then
return -1
endi
if $dnode3Role != slave then
return -1
endi
if $dnode4Role != slave then
return -1
endi
print ============================== step4
print ========= drop dnode3
sql drop dnode $hostname3
$x = 0
show4:
$x = $x + 1
sleep 1000
if $x == 40 then
return -1
endi
sql show dnodes -x show4
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes
$dnode3Vnodes = $data2_3
print dnode3 $dnode3Vnodes
if $dnode1Vnodes != 3 then
goto show4
endi
if $dnode4Vnodes != 3 then
goto show4
endi
if $dnode3Vnodes != null then
goto show4
endi
sql show mnodes
$dnode1Role = $data2_1
$dnode2Role = $data2_2
$dnode3Role = $data2_3
$dnode4Role = $data2_4
print dnode1 ==> $dnode1Role
print dnode2 ==> $dnode2Role
print dnode3 ==> $dnode3Role
print dnode4 ==> $dnode4Role
if $dnode1Role != master then
return -1
endi
if $dnode2Role != null then
return -1
endi
if $dnode3Role != null then
return -1
endi
if $dnode4Role != slave then
return -1
endi
system sh/exec.sh -n dnode3 -s stop -x SIGINT
print ============================== step5
print ========= start dnode3
sql create dnode $hostname5
system sh/exec.sh -n dnode5 -s start
$x = 0
show5:
$x = $x + 1
sleep 1000
if $x == 30 then
return -1
endi
sql show dnodes -x show5
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes
$dnode5Vnodes = $data2_5
print dnode5 $dnode5Vnodes
if $dnode1Vnodes != 2 then
goto show5
endi
if $dnode4Vnodes != 2 then
goto show5
endi
if $dnode5Vnodes != 2 then
goto show5
endi
sql show mnodes
$dnode1Role = $data2_1
$dnode4Role = $data2_4
$dnode5Role = $data2_5
print dnode1 ==> $dnode1Role
print dnode4 ==> $dnode4Role
print dnode5 ==> $dnode5Role
print ============================== step6
system sh/exec.sh -n dnode1 -s stop -x SIGINT
print stop dnode1 and sleep 3000
sleep 3000
sql show mnodes
$dnode1Role = $data2_1
$dnode4Role = $data2_4
$dnode5Role = $data2_5
print dnode1 ==> $dnode1Role
print dnode4 ==> $dnode4Role
print dnode5 ==> $dnode5Role
if $dnode1Role != offline then
return -1
endi
print ============================== step6.1
system sh/exec.sh -n dnode1 -s start
$x = 0
step6.1:
$x = $x + 1
sleep 1000
if $x == 10 then
return -1
endi
sql show dnodes
print dnode1 $data4_1
if $data4_1 != ready then
goto step6.1
endi
sql drop dnode $hostname1
print drop dnode1 and sleep 9000
sleep 9000
$x = 0
show6:
$x = $x + 1
sleep 2000
if $x == 10 then
return -1
endi
sql show dnodes -x show6
$dnode1Vnodes = $data2_1
print dnode1 $dnode1Vnodes
$dnode4Vnodes = $data2_4
print dnode4 $dnode4Vnodes
$dnode5Vnodes = $data2_5
print dnode5 $dnode5Vnodes
if $dnode1Vnodes != null then
goto show6
endi
if $dnode4Vnodes != 3 then
goto show6
endi
if $dnode5Vnodes != 3 then
goto show6
endi
sql show mnodes
$dnode1Role = $data2_1
$dnode4Role = $data2_4
$dnode5Role = $data2_5
print dnode1 ==> $dnode1Role
print dnode4 ==> $dnode4Role
print dnode5 ==> $dnode5Role
#system sh/exec.sh -n dnode1 -s stop -x SIGINT
print ============================== step12
print ========= check data
sql reset query cache
sleep 100
sql select * from c_b2_d1.c_b2_t1 order by t desc
print $data01 $data11 $data21 $data31 $data41
if $data01 != 11 then
return -1
endi
if $data11 != 12 then
return -1
endi
if $data21 != 13 then
return -1
endi
if $data31 != 14 then
return -1
endi
if $data41 != 15 then
return -1
endi
sql select * from c_b2_d2.c_b2_t2 order by t desc
print $data01 $data11 $data21 $data31 $data41
if $data01 != 21 then
return -1
endi
if $data11 != 22 then
return -1
endi
if $data21 != 23 then
return -1
endi
if $data31 != 24 then
return -1
endi
if $data41 != 25 then
return -1
endi
sql select * from c_b2_d3.c_b2_t3 order by t desc
print $data01 $data11 $data21 $data31 $data41
if $data01 != 31 then
return -1
endi
if $data11 != 32 then
return -1
endi
if $data21 != 33 then
return -1
endi
if $data31 != 34 then
return -1
endi
if $data41 != 35 then
return -1
endi
print ============================================ over
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT
system sh/exec.sh -n dnode5 -s stop -x SIGKILL
system sh/exec.sh -n dnode6 -s stop -x SIGINT
system sh/exec.sh -n dnode7 -s stop -x SIGINT
system sh/exec.sh -n dnode8 -s stop -x SIGINT
tests/script/tsim/dnode/cluster_balance3.sim
已删除
100644 → 0
浏览文件 @
344ef7e1
此差异已折叠。
点击以展开。
tests/script/tsim/dnode/cluster_cache.sim
已删除
100644 → 0
浏览文件 @
344ef7e1
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/cfg.sh -n dnode2 -c walLevel -v 1
system sh/cfg.sh -n dnode1 -c httpMaxThreads -v 2
system sh/cfg.sh -n dnode2 -c httpMaxThreads -v 2
system sh/cfg.sh -n dnode1 -c monitor -v 1
system sh/cfg.sh -n dnode1 -c monitor -v 2
system sh/cfg.sh -n dnode2 -c http -v 1
system sh/cfg.sh -n dnode1 -c enableHttp -v 1
system sh/cfg.sh -n dnode2 -c monitor -v 1
system sh/cfg.sh -n dnode1 -c monitorInterval -v 1
system sh/cfg.sh -n dnode2 -c monitorInterval -v 1
system sh/exec.sh -n dnode1 -s start
sleep 2000
sql connect
sql create database testdb
sql use testdb
sql create table meter1 (ts timestamp, val int)
$x = 0
$v = -100
while $x < 30
$v = $v + 1
$ms = $v . m
sql insert into meter1 values (now $ms , $x )
$x = $x + 1
endw
sleep 2000
system sh/exec.sh -n dnode2 -s start
sql create dnode $hostname2
sleep 10000
sql show log.tables;
if $rows > 6 then
return -1
endi
sql select * from log.dn1
print ===>rows $rows
print $data00 $data01 $data02
print $data10 $data11 $data12
print $data20 $data21 $data22
if $rows < 10 then
return -1
endi
#sql create table sys.st as select avg(taosd), avg(system) from sys.cpu interval(30s)
sql show log.vgroups
if $data05 != master then
return -1
endi
if $data15 != master then
return -1
endi
tests/script/tsim/dnode/cluster_flowctrl.sim
已删除
100644 → 0
浏览文件 @
344ef7e1
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/cfg.sh -n dnode1 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode2 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode3 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4
system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 4
system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 4
system sh/cfg.sh -n dnode1 -c http -v 0
system sh/cfg.sh -n dnode2 -c http -v 0
system sh/cfg.sh -n dnode3 -c http -v 0
system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 20000
system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 20000
system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 20000
system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 20
system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 20
system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 20
system sh/cfg.sh -n dnode1 -c replica -v 3
system sh/cfg.sh -n dnode2 -c replica -v 3
system sh/cfg.sh -n dnode3 -c replica -v 3
print ============== deploy
system sh/exec.sh -n dnode1 -s start
sleep 5001
sql connect
sql create dnode $hostname2
sql create dnode $hostname3
system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
print =============== step1
$x = 0
show1:
$x = $x + 1
sleep 2000
if $x == 5 then
return -1
endi
sql show mnodes -x show1
$mnode1Role = $data2_1
print mnode1Role $mnode1Role
$mnode2Role = $data2_2
print mnode2Role $mnode2Role
$mnode3Role = $data2_3
print mnode3Role $mnode3Role
if $mnode1Role != master then
goto show1
endi
if $mnode2Role != slave then
goto show1
endi
if $mnode3Role != slave then
goto show1
endi
print =============== step2
sql create database db replica 3
sql use db
sql create table tb (ts timestamp, test int)
$x = 0
while $x < 100
$ms = $x . s
sql insert into tb values (now + $ms , $x )
$x = $x + 1
endw
print =============== step3
sleep 2000
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
print =============== step4
sleep 3000
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
print =============== step5
sleep 8000
while $x < 200
$ms = $x . s
sql insert into tb values (now + $ms , $x )
$x = $x + 1
endw
print =============== step6
system sh/exec.sh -n dnode2 -s stop -x SIGINT
sleep 2000
while $x < 300
$ms = $x . s
sql insert into tb values (now + $ms , $x )
$x = $x + 1
endw
system sh/exec.sh -n dnode2 -s start
sleep 6000
print =============== step7
while $x < 400
$ms = $x . s
sql insert into tb values (now + $ms , $x )
$x = $x + 1
sleep 1
endw
print =============== step8
sql select * from tb
print rows $rows
if $rows != 400 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
\ No newline at end of file
tests/script/tsim/dnode/cluster_vgroup100.sim
已删除
100644 → 0
浏览文件 @
344ef7e1
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/cfg.sh -n dnode1 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode2 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode3 -c numOfMnodes -v 3
system sh/cfg.sh -n dnode1 -c maxTables -v 4
system sh/cfg.sh -n dnode2 -c maxTables -v 4
system sh/cfg.sh -n dnode3 -c maxTables -v 4
system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 0
system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 0
print ============================== step1
system sh/exec.sh -n dnode1 -s start
sql connect
print ============================== step2
print ========= start dnode2
sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start
sql create dnode $hostname3
system sh/exec.sh -n dnode3 -s start
$maxNum = 102
$maxNum = 12
$x = 0
show2:
$x = $x + 1
sleep 2000
if $x == 10 then
return -1
endi
sql show mnodes
$dnode1Role = $data2_1
$dnode2Role = $data2_2
$dnode3Role = $data2_3
print $dnode1Role
print $dnode2Role
print $dnode3Role
if $dnode1Role != master then
goto show2
endi
if $dnode2Role != slave then
goto show2
endi
if $dnode3Role != slave then
goto show2
endi
print ============================== step3
$count = 2
while $count < $maxNum
$db = d . $count
$tb = $db . .t
$tb2 = $db . .t2
sql create database $db replica 3 cache 1 blocks 3
sql create table $tb (ts timestamp, i int)
sql insert into $tb values(now, 1)
sql create table $tb2 as select count(*) from $tb interval(10s)
$count = $count + 1
print insert into $tb values(now, 1) ==> finished
endw
print ============================== step4
$count = 2
while $count < $maxNum
$db = d . $count
$tb = $db . .t
sql select * from $tb
if $rows != 1 then
print select * from $tb
return -1
endi
$count = $count + 1
print select * from $tb ==> rows: $rows
endw
print ============================== step5
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
print ============================== step6
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
print ============================== step7
$x = 0
show7:
$x = $x + 1
sleep 2000
if $x == 50 then
return -1
endi
sql show mnodes -x show7
$dnode1Role = $data2_1
$dnode2Role = $data2_2
$dnode3Role = $data2_3
if $dnode1Role != master then
goto show7
endi
if $dnode2Role != slave then
goto show7
endi
if $dnode2Role != slave then
goto show7
endi
print ============================== step8
$x = 0
show8:
$x = $x + 1
sleep 2000
if $x == 20 then
return -1
endi
$count = 2
while $count < $maxNum
$db = d . $count
$tb = $db . .t
sql select * from $tb
if $rows != 1 then
print select * from $tb
goto show8
endi
$count = $count + 1
print select * from $tb ==> rows: $rows
endw
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
\ No newline at end of file
tests/system-test/2-query/json_tag.py
浏览文件 @
0d41f9c8
此差异已折叠。
点击以展开。
tests/system-test/7-tmq/subscribeDb2.py
浏览文件 @
0d41f9c8
...
@@ -5,6 +5,7 @@ import time
...
@@ -5,6 +5,7 @@ import time
import
socket
import
socket
import
os
import
os
import
threading
import
threading
import
math
from
util.log
import
*
from
util.log
import
*
from
util.sql
import
*
from
util.sql
import
*
...
@@ -127,10 +128,14 @@ class TDTestCase:
...
@@ -127,10 +128,14 @@ class TDTestCase:
#tdLog.debug("doing insert data into stable:%s rows:%d ..."%(stbName, allRows))
#tdLog.debug("doing insert data into stable:%s rows:%d ..."%(stbName, allRows))
for
i
in
range
(
ctbNum
):
for
i
in
range
(
ctbNum
):
sql
+=
" %s_%d values "
%
(
stbName
,
i
)
sql
+=
" %s_%d values "
%
(
stbName
,
i
)
batchRows
=
0
for
j
in
range
(
rowsPerTbl
):
for
j
in
range
(
rowsPerTbl
):
sql
+=
"(%d, %d, 'tmqrow_%d') "
%
(
startTs
+
j
,
j
,
j
)
sql
+=
"(%d, %d, 'tmqrow_%d') "
%
(
startTs
+
j
,
j
,
j
)
if
(
j
>
0
)
and
((
j
%
batchNum
==
0
)
or
(
j
==
rowsPerTbl
-
1
)):
batchRows
+=
1
# if (j > 0) and ((j%(batchNum-1) == 0) or (j == rowsPerTbl - 1)):
if
(
j
>
0
)
and
((
batchRows
==
batchNum
)
or
(
j
==
rowsPerTbl
-
1
)):
tsql
.
execute
(
sql
)
tsql
.
execute
(
sql
)
batchRows
=
0
if
j
<
rowsPerTbl
-
1
:
if
j
<
rowsPerTbl
-
1
:
sql
=
"insert into %s_%d values "
%
(
stbName
,
i
)
sql
=
"insert into %s_%d values "
%
(
stbName
,
i
)
else
:
else
:
...
@@ -171,8 +176,8 @@ class TDTestCase:
...
@@ -171,8 +176,8 @@ class TDTestCase:
'dbName'
:
'db8'
,
\
'dbName'
:
'db8'
,
\
'vgroups'
:
4
,
\
'vgroups'
:
4
,
\
'stbName'
:
'stb'
,
\
'stbName'
:
'stb'
,
\
'ctbNum'
:
1
0
,
\
'ctbNum'
:
1
,
\
'rowsPerTbl'
:
1000
0
,
\
'rowsPerTbl'
:
1000
,
\
'batchNum'
:
100
,
\
'batchNum'
:
100
,
\
'startTs'
:
1640966400000
}
# 2022-01-01 00:00:00.000
'startTs'
:
1640966400000
}
# 2022-01-01 00:00:00.000
parameterDict
[
'cfg'
]
=
cfgPath
parameterDict
[
'cfg'
]
=
cfgPath
...
@@ -189,7 +194,7 @@ class TDTestCase:
...
@@ -189,7 +194,7 @@ class TDTestCase:
tdSql
.
execute
(
"create topic %s as database %s"
%
(
topicName1
,
parameterDict
[
'dbName'
]))
tdSql
.
execute
(
"create topic %s as database %s"
%
(
topicName1
,
parameterDict
[
'dbName'
]))
consumerId
=
0
consumerId
=
0
expectrowcnt
=
parameterDict
[
"rowsPerTbl"
]
*
parameterDict
[
"ctbNum"
]
/
2
expectrowcnt
=
math
.
ceil
(
parameterDict
[
"rowsPerTbl"
]
*
parameterDict
[
"ctbNum"
]
/
2
)
topicList
=
topicName1
topicList
=
topicName1
ifcheckdata
=
0
ifcheckdata
=
0
ifManualCommit
=
0
ifManualCommit
=
0
...
@@ -217,7 +222,7 @@ class TDTestCase:
...
@@ -217,7 +222,7 @@ class TDTestCase:
for
i
in
range
(
expectRows
):
for
i
in
range
(
expectRows
):
totalConsumeRows
+=
resultList
[
i
]
totalConsumeRows
+=
resultList
[
i
]
if
totalConsumeRows
!=
expectrowcnt
:
if
not
(
totalConsumeRows
>=
expectrowcnt
)
:
tdLog
.
info
(
"act consume rows: %d, expect consume rows: %d"
%
(
totalConsumeRows
,
expectrowcnt
))
tdLog
.
info
(
"act consume rows: %d, expect consume rows: %d"
%
(
totalConsumeRows
,
expectrowcnt
))
tdLog
.
exit
(
"tmq consume rows error!"
)
tdLog
.
exit
(
"tmq consume rows error!"
)
...
@@ -267,7 +272,7 @@ class TDTestCase:
...
@@ -267,7 +272,7 @@ class TDTestCase:
tdSql
.
execute
(
"create topic %s as database %s"
%
(
topicName1
,
parameterDict
[
'dbName'
]))
tdSql
.
execute
(
"create topic %s as database %s"
%
(
topicName1
,
parameterDict
[
'dbName'
]))
consumerId
=
0
consumerId
=
0
expectrowcnt
=
parameterDict
[
"rowsPerTbl"
]
*
parameterDict
[
"ctbNum"
]
/
2
expectrowcnt
=
math
.
ceil
(
parameterDict
[
"rowsPerTbl"
]
*
parameterDict
[
"ctbNum"
]
/
2
)
topicList
=
topicName1
topicList
=
topicName1
ifcheckdata
=
0
ifcheckdata
=
0
ifManualCommit
=
1
ifManualCommit
=
1
...
...
tests/system-test/7-tmq/tmqConsFromTsdb.py
浏览文件 @
0d41f9c8
此差异已折叠。
点击以展开。
tools/shell/src/shellCommand.c
浏览文件 @
0d41f9c8
...
@@ -482,6 +482,7 @@ int32_t shellReadCommand(char *command) {
...
@@ -482,6 +482,7 @@ int32_t shellReadCommand(char *command) {
#endif
#endif
break
;
break
;
case
4
:
// EOF or Ctrl+D
case
4
:
// EOF or Ctrl+D
taosResetTerminalMode
();
printf
(
"
\n
"
);
printf
(
"
\n
"
);
return
-
1
;
return
-
1
;
case
5
:
// ctrl E
case
5
:
// ctrl E
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录