Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4cdaafe6
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4cdaafe6
编写于
9月 08, 2022
作者:
haoranc
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of github.com:taosdata/TDengine into test/chr/TD-14699
上级
9465b356
053df87d
变更
58
展开全部
隐藏空白更改
内联
并排
Showing
58 changed file
with
3074 addition
and
665 deletion
+3074
-665
cmake/cmake.platform
cmake/cmake.platform
+1
-1
cmake/cmake.version
cmake/cmake.version
+1
-1
cmake/taosadapter_CMakeLists.txt.in
cmake/taosadapter_CMakeLists.txt.in
+1
-1
cmake/taostools_CMakeLists.txt.in
cmake/taostools_CMakeLists.txt.in
+1
-1
cmake/taosws_CMakeLists.txt.in
cmake/taosws_CMakeLists.txt.in
+1
-1
docs/zh/05-get-started/01-docker.md
docs/zh/05-get-started/01-docker.md
+1
-1
docs/zh/07-develop/09-udf.md
docs/zh/07-develop/09-udf.md
+1
-1
docs/zh/12-taos-sql/03-table.md
docs/zh/12-taos-sql/03-table.md
+1
-4
docs/zh/12-taos-sql/20-keywords.md
docs/zh/12-taos-sql/20-keywords.md
+3
-1
docs/zh/28-releases/01-tdengine.md
docs/zh/28-releases/01-tdengine.md
+2
-6
docs/zh/28-releases/02-tools.md
docs/zh/28-releases/02-tools.md
+2
-2
include/common/tmsgdef.h
include/common/tmsgdef.h
+2
-0
include/libs/stream/tstream.h
include/libs/stream/tstream.h
+2
-0
include/libs/sync/syncTools.h
include/libs/sync/syncTools.h
+64
-0
source/dnode/mnode/impl/src/mndDb.c
source/dnode/mnode/impl/src/mndDb.c
+9
-6
source/dnode/vnode/src/inc/sma.h
source/dnode/vnode/src/inc/sma.h
+1
-0
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+18
-1
source/dnode/vnode/src/sma/smaCommit.c
source/dnode/vnode/src/sma/smaCommit.c
+16
-5
source/dnode/vnode/src/sma/smaFS.c
source/dnode/vnode/src/sma/smaFS.c
+13
-1
source/dnode/vnode/src/sma/smaRollup.c
source/dnode/vnode/src/sma/smaRollup.c
+25
-15
source/dnode/vnode/src/tsdb/tsdbCache.c
source/dnode/vnode/src/tsdb/tsdbCache.c
+1
-1
source/dnode/vnode/src/tsdb/tsdbMergeTree.c
source/dnode/vnode/src/tsdb/tsdbMergeTree.c
+266
-101
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+143
-74
source/libs/executor/inc/executil.h
source/libs/executor/inc/executil.h
+1
-0
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+9
-1
source/libs/executor/src/executil.c
source/libs/executor/src/executil.c
+95
-93
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+149
-3
source/libs/executor/src/groupoperator.c
source/libs/executor/src/groupoperator.c
+135
-122
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+79
-24
source/libs/executor/src/timewindowoperator.c
source/libs/executor/src/timewindowoperator.c
+183
-92
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+15
-5
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+9
-2
source/libs/index/src/indexComm.c
source/libs/index/src/indexComm.c
+6
-6
source/libs/index/src/indexFilter.c
source/libs/index/src/indexFilter.c
+33
-34
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+11
-1
source/libs/stream/src/streamState.c
source/libs/stream/src/streamState.c
+23
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+2
-2
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+307
-0
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+28
-0
source/libs/sync/test/syncHeartbeatReplyTest.cpp
source/libs/sync/test/syncHeartbeatReplyTest.cpp
+105
-0
source/libs/sync/test/syncHeartbeatTest.cpp
source/libs/sync/test/syncHeartbeatTest.cpp
+99
-0
source/libs/tdb/src/db/tdbPager.c
source/libs/tdb/src/db/tdbPager.c
+1
-1
source/libs/transport/src/thttp.c
source/libs/transport/src/thttp.c
+5
-5
source/libs/transport/src/transCli.c
source/libs/transport/src/transCli.c
+28
-31
source/libs/transport/src/transComm.c
source/libs/transport/src/transComm.c
+1
-1
source/libs/transport/src/transSvr.c
source/libs/transport/src/transSvr.c
+11
-11
source/util/test/pageBufferTest.cpp
source/util/test/pageBufferTest.cpp
+4
-4
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+6
-0
tests/script/tsim/column/table.sim
tests/script/tsim/column/table.sim
+1
-0
tests/script/tsim/parser/commit.sim
tests/script/tsim/parser/commit.sim
+1
-0
tests/script/tsim/stream/basic1.sim
tests/script/tsim/stream/basic1.sim
+2
-2
tests/script/tsim/stream/deleteInterval.sim
tests/script/tsim/stream/deleteInterval.sim
+419
-0
tests/script/tsim/stream/deleteSession.sim
tests/script/tsim/stream/deleteSession.sim
+532
-0
tests/script/tsim/stream/deleteState.sim
tests/script/tsim/stream/deleteState.sim
+198
-0
tests/script/tsim/stream/partitionbyColumnInterval.sim
tests/script/tsim/stream/partitionbyColumnInterval.sim
+0
-0
tests/script/tsim/stream/partitionbyColumnSession.sim
tests/script/tsim/stream/partitionbyColumnSession.sim
+0
-0
tests/script/tsim/stream/partitionbyColumnState.sim
tests/script/tsim/stream/partitionbyColumnState.sim
+0
-0
tests/system-test/fulltest.sh
tests/system-test/fulltest.sh
+1
-1
未找到文件。
cmake/cmake.platform
浏览文件 @
4cdaafe6
...
...
@@ -87,7 +87,7 @@ IF ("${CPUTYPE}" STREQUAL "")
SET(TD_ARM_32 TRUE)
ADD_DEFINITIONS("-D_TD_ARM_")
ADD_DEFINITIONS("-D_TD_ARM_32")
ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "
aarch64
")
ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "
(aarch64)|(arm64)
")
MESSAGE(STATUS "The current platform is aarch64")
SET(PLATFORM_ARCH_STR "arm64")
SET(TD_ARM_64 TRUE)
...
...
cmake/cmake.version
浏览文件 @
4cdaafe6
...
...
@@ -2,7 +2,7 @@
IF (DEFINED VERNUMBER)
SET(TD_VER_NUMBER ${VERNUMBER})
ELSE ()
SET(TD_VER_NUMBER "3.0.
0.1
")
SET(TD_VER_NUMBER "3.0.
1.0
")
ENDIF ()
IF (DEFINED VERCOMPATIBLE)
...
...
cmake/taosadapter_CMakeLists.txt.in
浏览文件 @
4cdaafe6
...
...
@@ -2,7 +2,7 @@
# taosadapter
ExternalProject_Add(taosadapter
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
GIT_TAG
abed566
GIT_TAG
71e7ccf
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
...
...
cmake/taostools_CMakeLists.txt.in
浏览文件 @
4cdaafe6
...
...
@@ -2,7 +2,7 @@
# taos-tools
ExternalProject_Add(taos-tools
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
GIT_TAG
a4d9b92
GIT_TAG
7d5c1c0
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
...
...
cmake/taosws_CMakeLists.txt.in
浏览文件 @
4cdaafe6
...
...
@@ -2,7 +2,7 @@
# taosws-rs
ExternalProject_Add(taosws-rs
GIT_REPOSITORY https://github.com/taosdata/taos-connector-rust.git
GIT_TAG
6fc47d7
GIT_TAG
e771403
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosws-rs"
BINARY_DIR ""
#BUILD_IN_SOURCE TRUE
...
...
docs/zh/05-get-started/01-docker.md
浏览文件 @
4cdaafe6
...
...
@@ -62,7 +62,7 @@ taos>
## 体验查询
使用上述 taosBenchmark 插入数据后,可以在 TDengine CLI 输入查询命令,体验查询速度。
。
使用上述 taosBenchmark 插入数据后,可以在 TDengine CLI 输入查询命令,体验查询速度。
查询超级表下记录总条数:
...
...
docs/zh/07-develop/09-udf.md
浏览文件 @
4cdaafe6
...
...
@@ -116,7 +116,7 @@ aggfn为函数名的占位符,需要修改为自己的函数名,如l2norm。
参数的具体含义是:
-
inputDataBlock: 输入的数据块
-
resultColumn: 输出列
。输出列
-
resultColumn: 输出列
### 聚合接口函数
...
...
docs/zh/12-taos-sql/03-table.md
浏览文件 @
4cdaafe6
...
...
@@ -23,10 +23,7 @@ create_subtable_clause: {
}
create_definition
:
col_name
column_definition
column_definition
:
type_name
[
comment
'string_value'
]
col_name
column_type
table_options
:
table_option
...
...
...
docs/zh/12-taos-sql/20-keywords.md
浏览文件 @
4cdaafe6
...
...
@@ -6,7 +6,8 @@ description: TDengine 保留关键字的详细列表
## 保留关键字
目前 TDengine 有将近 200 个内部保留关键字,这些关键字无论大小写均不可以用作库名、表名、STable 名、数据列名及标签列名等。这些关键字列表如下:
目前 TDengine 有将近 200 个内部保留关键字,这些关键字无论大小写如果需要用作库名、表名、STable 名、数据列名及标签列名等,需要使用符合
``将关键字括起来使用,例如`
ADD
`
。
关键字列表如下:
### A
...
...
@@ -239,6 +240,7 @@ description: TDengine 保留关键字的详细列表
-
TOPICS
-
TRIGGER
-
TSERIES
-
TTL
### U
...
...
docs/zh/28-releases/01-tdengine.md
浏览文件 @
4cdaafe6
...
...
@@ -6,11 +6,7 @@ description: TDengine 发布历史、Release Notes 及下载链接
import Release from "/components/ReleaseV3";
## 3.0.
0.1
## 3.0.
1.0
<Release
type=
"tdengine"
version=
"3.0.0.1"
/>
<!-- ## 3.0.0.0
<Release
type=
"tdengine"
version=
"3.0.0.0"
/>
-->
<Release
type=
"tdengine"
version=
"3.0.1.0"
/>
docs/zh/28-releases/02-tools.md
浏览文件 @
4cdaafe6
...
...
@@ -6,6 +6,6 @@ description: taosTools 的发布历史、Release Notes 和下载链接
import Release from "/components/ReleaseV3";
## 2.1.
2
## 2.1.
3
<Release
type=
"tools"
version=
"2.1.2"
/>
\ No newline at end of file
<Release
type=
"tools"
version=
"2.1.3"
/>
include/common/tmsgdef.h
浏览文件 @
4cdaafe6
...
...
@@ -272,6 +272,8 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_SYNC_LEADER_TRANSFER
,
"sync-leader-transfer"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_SET_MNODE_STANDBY
,
"set-mnode-standby"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_SET_VNODE_STANDBY
,
"set-vnode-standby"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_HEARTBEAT
,
"sync-heartbeat"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_HEARTBEAT_REPLY
,
"sync-heartbeat-reply"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_MAX_MSG
,
"sync-max"
,
NULL
,
NULL
)
#if defined(TD_MSG_NUMBER_)
...
...
include/libs/stream/tstream.h
浏览文件 @
4cdaafe6
...
...
@@ -554,6 +554,8 @@ typedef struct {
int32_t
streamStatePut
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
const
void
*
value
,
int32_t
vLen
);
int32_t
streamStateGet
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateDel
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
int32_t
streamStateAddIfNotExist
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
);
int32_t
streamStateReleaseBuf
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
*
pVal
);
void
streamFreeVal
(
void
*
val
);
SStreamStateCur
*
streamStateGetCur
(
SStreamState
*
pState
,
const
SWinKey
*
key
);
...
...
include/libs/sync/syncTools.h
浏览文件 @
4cdaafe6
...
...
@@ -444,6 +444,70 @@ void syncAppendEntriesReplyPrint2(char* s, const SyncAppendEntriesReply* pMsg);
void
syncAppendEntriesReplyLog
(
const
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplyLog2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
);
// ---------------------------------------------
typedef
struct
SyncHeartbeat
{
uint32_t
bytes
;
int32_t
vgId
;
uint32_t
msgType
;
SRaftId
srcId
;
SRaftId
destId
;
// private data
SyncTerm
term
;
SyncIndex
commitIndex
;
SyncTerm
privateTerm
;
}
SyncHeartbeat
;
SyncHeartbeat
*
syncHeartbeatBuild
(
int32_t
vgId
);
void
syncHeartbeatDestroy
(
SyncHeartbeat
*
pMsg
);
void
syncHeartbeatSerialize
(
const
SyncHeartbeat
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncHeartbeatDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncHeartbeat
*
pMsg
);
char
*
syncHeartbeatSerialize2
(
const
SyncHeartbeat
*
pMsg
,
uint32_t
*
len
);
SyncHeartbeat
*
syncHeartbeatDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncHeartbeat2RpcMsg
(
const
SyncHeartbeat
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncHeartbeatFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncHeartbeat
*
pMsg
);
SyncHeartbeat
*
syncHeartbeatFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncHeartbeat2Json
(
const
SyncHeartbeat
*
pMsg
);
char
*
syncHeartbeat2Str
(
const
SyncHeartbeat
*
pMsg
);
// for debug ----------------------
void
syncHeartbeatPrint
(
const
SyncHeartbeat
*
pMsg
);
void
syncHeartbeatPrint2
(
char
*
s
,
const
SyncHeartbeat
*
pMsg
);
void
syncHeartbeatLog
(
const
SyncHeartbeat
*
pMsg
);
void
syncHeartbeatLog2
(
char
*
s
,
const
SyncHeartbeat
*
pMsg
);
// ---------------------------------------------
typedef
struct
SyncHeartbeatReply
{
uint32_t
bytes
;
int32_t
vgId
;
uint32_t
msgType
;
SRaftId
srcId
;
SRaftId
destId
;
// private data
SyncTerm
term
;
SyncTerm
privateTerm
;
int64_t
startTime
;
}
SyncHeartbeatReply
;
SyncHeartbeatReply
*
syncHeartbeatReplyBuild
(
int32_t
vgId
);
void
syncHeartbeatReplyDestroy
(
SyncHeartbeatReply
*
pMsg
);
void
syncHeartbeatReplySerialize
(
const
SyncHeartbeatReply
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncHeartbeatReplyDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncHeartbeatReply
*
pMsg
);
char
*
syncHeartbeatReplySerialize2
(
const
SyncHeartbeatReply
*
pMsg
,
uint32_t
*
len
);
SyncHeartbeatReply
*
syncHeartbeatReplyDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncHeartbeatReply2RpcMsg
(
const
SyncHeartbeatReply
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncHeartbeatReplyFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncHeartbeatReply
*
pMsg
);
SyncHeartbeatReply
*
syncHeartbeatReplyFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncHeartbeatReply2Json
(
const
SyncHeartbeatReply
*
pMsg
);
char
*
syncHeartbeatReply2Str
(
const
SyncHeartbeatReply
*
pMsg
);
// for debug ----------------------
void
syncHeartbeatReplyPrint
(
const
SyncHeartbeatReply
*
pMsg
);
void
syncHeartbeatReplyPrint2
(
char
*
s
,
const
SyncHeartbeatReply
*
pMsg
);
void
syncHeartbeatReplyLog
(
const
SyncHeartbeatReply
*
pMsg
);
void
syncHeartbeatReplyLog2
(
char
*
s
,
const
SyncHeartbeatReply
*
pMsg
);
// ---------------------------------------------
typedef
struct
SyncApplyMsg
{
uint32_t
bytes
;
...
...
source/dnode/mnode/impl/src/mndDb.c
浏览文件 @
4cdaafe6
...
...
@@ -15,6 +15,7 @@
#define _DEFAULT_SOURCE
#include "mndDb.h"
#include "mndCluster.h"
#include "mndDnode.h"
#include "mndOffset.h"
#include "mndPrivilege.h"
...
...
@@ -1592,6 +1593,8 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
if
(
i
==
0
)
{
colDataAppend
(
pColInfo
,
rows
,
buf
,
false
);
}
else
if
(
i
==
1
)
{
colDataAppend
(
pColInfo
,
rows
,
(
const
char
*
)
&
pDb
->
createdTime
,
false
);
}
else
if
(
i
==
3
)
{
colDataAppend
(
pColInfo
,
rows
,
(
const
char
*
)
&
numOfTables
,
false
);
}
else
if
(
i
==
14
)
{
...
...
@@ -1712,18 +1715,18 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
taosMemoryFree
(
buf
);
}
static
void
setInformationSchemaDbCfg
(
SDbObj
*
pDbObj
)
{
static
void
setInformationSchemaDbCfg
(
S
Mnode
*
pMnode
,
S
DbObj
*
pDbObj
)
{
tstrncpy
(
pDbObj
->
name
,
TSDB_INFORMATION_SCHEMA_DB
,
tListLen
(
pDbObj
->
name
));
pDbObj
->
createdTime
=
0
;
pDbObj
->
createdTime
=
mndGetClusterCreateTime
(
pMnode
)
;
pDbObj
->
cfg
.
numOfVgroups
=
0
;
pDbObj
->
cfg
.
strict
=
1
;
pDbObj
->
cfg
.
replications
=
1
;
pDbObj
->
cfg
.
precision
=
TSDB_TIME_PRECISION_MILLI
;
}
static
void
setPerfSchemaDbCfg
(
SDbObj
*
pDbObj
)
{
static
void
setPerfSchemaDbCfg
(
S
Mnode
*
pMnode
,
S
DbObj
*
pDbObj
)
{
tstrncpy
(
pDbObj
->
name
,
TSDB_PERFORMANCE_SCHEMA_DB
,
tListLen
(
pDbObj
->
name
));
pDbObj
->
createdTime
=
0
;
pDbObj
->
createdTime
=
mndGetClusterCreateTime
(
pMnode
)
;
pDbObj
->
cfg
.
numOfVgroups
=
0
;
pDbObj
->
cfg
.
strict
=
1
;
pDbObj
->
cfg
.
replications
=
1
;
...
...
@@ -1754,7 +1757,7 @@ static int32_t mndRetrieveDbs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc
// Append the information_schema database into the result.
if
(
!
pShow
->
sysDbRsp
)
{
SDbObj
infoschemaDb
=
{
0
};
setInformationSchemaDbCfg
(
&
infoschemaDb
);
setInformationSchemaDbCfg
(
pMnode
,
&
infoschemaDb
);
size_t
numOfTables
=
0
;
getVisibleInfosTablesNum
(
sysinfo
,
&
numOfTables
);
mndDumpDbInfoData
(
pMnode
,
pBlock
,
&
infoschemaDb
,
pShow
,
numOfRows
,
numOfTables
,
true
,
0
,
1
);
...
...
@@ -1762,7 +1765,7 @@ static int32_t mndRetrieveDbs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc
numOfRows
+=
1
;
SDbObj
perfschemaDb
=
{
0
};
setPerfSchemaDbCfg
(
&
perfschemaDb
);
setPerfSchemaDbCfg
(
pMnode
,
&
perfschemaDb
);
numOfTables
=
0
;
getPerfDbMeta
(
NULL
,
&
numOfTables
);
mndDumpDbInfoData
(
pMnode
,
pBlock
,
&
perfschemaDb
,
pShow
,
numOfRows
,
numOfTables
,
true
,
0
,
1
);
...
...
source/dnode/vnode/src/inc/sma.h
浏览文件 @
4cdaafe6
...
...
@@ -211,6 +211,7 @@ int32_t tdRSmaFSOpen(SSma *pSma, int64_t version);
void
tdRSmaFSClose
(
SRSmaFS
*
fs
);
int32_t
tdRSmaFSRef
(
SSma
*
pSma
,
SRSmaStat
*
pStat
,
int64_t
version
);
void
tdRSmaFSUnRef
(
SSma
*
pSma
,
SRSmaStat
*
pStat
,
int64_t
version
);
int64_t
tdRSmaFSMaxVer
(
SSma
*
pSma
,
SRSmaStat
*
pStat
);
int32_t
tdRSmaFSUpsertQTaskFile
(
SRSmaFS
*
pFS
,
SQTaskFile
*
qTaskFile
);
int32_t
tdRSmaRestore
(
SSma
*
pSma
,
int8_t
type
,
int64_t
committedVer
);
int32_t
tdRSmaProcessCreateImpl
(
SSma
*
pSma
,
SRSmaParam
*
param
,
int64_t
suid
,
const
char
*
tbName
);
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
4cdaafe6
...
...
@@ -643,20 +643,37 @@ typedef struct {
TSDBROW
row
;
}
SRowInfo
;
typedef
struct
SSttBlockLoadInfo
{
SBlockData
blockData
[
2
];
SArray
*
aSttBlk
;
int32_t
blockIndex
[
2
];
// to denote the loaded block in the corresponding position.
int32_t
currentLoadBlockIndex
;
int32_t
loadBlocks
;
double
elapsedTime
;
}
SSttBlockLoadInfo
;
typedef
struct
SMergeTree
{
int8_t
backward
;
SRBTree
rbt
;
SArray
*
pIterList
;
SLDataIter
*
pIter
;
bool
destroyLoadInfo
;
SSttBlockLoadInfo
*
pLoadInfo
;
const
char
*
idStr
;
}
SMergeTree
;
int32_t
tMergeTreeOpen
(
SMergeTree
*
pMTree
,
int8_t
backward
,
SDataFReader
*
pFReader
,
uint64_t
suid
,
uint64_t
uid
,
STimeWindow
*
pTimeWindow
,
SVersionRange
*
pVerRange
);
STimeWindow
*
pTimeWindow
,
SVersionRange
*
pVerRange
,
void
*
pLoadInfo
,
const
char
*
idStr
);
void
tMergeTreeAddIter
(
SMergeTree
*
pMTree
,
SLDataIter
*
pIter
);
bool
tMergeTreeNext
(
SMergeTree
*
pMTree
);
TSDBROW
tMergeTreeGetRow
(
SMergeTree
*
pMTree
);
void
tMergeTreeClose
(
SMergeTree
*
pMTree
);
SSttBlockLoadInfo
*
tCreateLastBlockLoadInfo
();
void
resetLastBlockLoadInfo
(
SSttBlockLoadInfo
*
pLoadInfo
);
void
getLastBlockLoadInfo
(
SSttBlockLoadInfo
*
pLoadInfo
,
int64_t
*
blocks
,
double
*
el
);
void
*
destroyLastBlockLoadInfo
(
SSttBlockLoadInfo
*
pLoadInfo
);
// ========== inline functions ==========
static
FORCE_INLINE
int32_t
tsdbKeyCmprFn
(
const
void
*
p1
,
const
void
*
p2
)
{
TSDBKEY
*
pKey1
=
(
TSDBKEY
*
)
p1
;
...
...
source/dnode/vnode/src/sma/smaCommit.c
浏览文件 @
4cdaafe6
...
...
@@ -182,6 +182,7 @@ static int32_t tdUpdateQTaskInfoFiles(SSma *pSma, SRSmaStat *pStat) {
SVnode
*
pVnode
=
pSma
->
pVnode
;
SRSmaFS
*
pFS
=
RSMA_FS
(
pStat
);
int64_t
committed
=
pStat
->
commitAppliedVer
;
int64_t
fsMaxVer
=
-
1
;
char
qTaskInfoFullName
[
TSDB_FILENAME_LEN
];
taosWLockLatch
(
RSMA_FS_LOCK
(
pStat
));
...
...
@@ -204,10 +205,20 @@ static int32_t tdUpdateQTaskInfoFiles(SSma *pSma, SRSmaStat *pStat) {
++
i
;
}
SQTaskFile
qFile
=
{.
nRef
=
1
,
.
padding
=
0
,
.
version
=
committed
,
.
size
=
0
};
if
(
tdRSmaFSUpsertQTaskFile
(
pFS
,
&
qFile
)
<
0
)
{
taosWUnLockLatch
(
RSMA_FS_LOCK
(
pStat
));
return
TSDB_CODE_FAILED
;
if
(
taosArrayGetSize
(
pFS
->
aQTaskInf
)
>
0
)
{
fsMaxVer
=
((
SQTaskFile
*
)
taosArrayGetLast
(
pFS
->
aQTaskInf
))
->
version
;
}
if
(
fsMaxVer
<
committed
)
{
SQTaskFile
qFile
=
{.
nRef
=
1
,
.
padding
=
0
,
.
version
=
committed
,
.
size
=
0
};
if
(
taosArrayPush
(
pFS
->
aQTaskInf
,
&
qFile
)
<
0
)
{
taosWUnLockLatch
(
RSMA_FS_LOCK
(
pStat
));
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
}
else
{
smaDebug
(
"vgId:%d, update qinf, no need as committed %"
PRIi64
" not larger than fsMaxVer %"
PRIi64
,
TD_VID
(
pVnode
),
committed
,
fsMaxVer
);
}
taosWUnLockLatch
(
RSMA_FS_LOCK
(
pStat
));
...
...
@@ -365,7 +376,7 @@ static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma) {
return
TSDB_CODE_SUCCESS
;
}
SRSmaStat
*
pRSmaStat
=
(
SRSmaStat
*
)
SMA_ENV_STAT
(
pEnv
);
SRSmaStat
*
pRSmaStat
=
(
SRSmaStat
*
)
SMA_ENV_STAT
(
pEnv
);
// step 1: merge qTaskInfo and iQTaskInfo
// lock
...
...
source/dnode/vnode/src/sma/smaFS.c
浏览文件 @
4cdaafe6
...
...
@@ -49,7 +49,7 @@ int32_t tdRSmaFSOpen(SSma *pSma, int64_t version) {
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
output
);
++
i
)
{
int32_t
vid
=
0
;
int64_t
version
=
-
1
;
sscanf
((
const
char
*
)
taosArrayGetP
(
output
,
i
),
"v%dqinf
o
.v%"
PRIi64
,
&
vid
,
&
version
);
sscanf
((
const
char
*
)
taosArrayGetP
(
output
,
i
),
"v%dqinf.v%"
PRIi64
,
&
vid
,
&
version
);
SQTaskFile
qTaskFile
=
{.
version
=
version
,
.
nRef
=
1
};
if
((
terrno
=
tdRSmaFSUpsertQTaskFile
(
RSMA_FS
(
pStat
),
&
qTaskFile
))
<
0
)
{
goto
_end
;
...
...
@@ -96,6 +96,18 @@ int32_t tdRSmaFSRef(SSma *pSma, SRSmaStat *pStat, int64_t version) {
return
oldVal
;
}
int64_t
tdRSmaFSMaxVer
(
SSma
*
pSma
,
SRSmaStat
*
pStat
)
{
SArray
*
aQTaskInf
=
RSMA_FS
(
pStat
)
->
aQTaskInf
;
int64_t
version
=
-
1
;
taosRLockLatch
(
RSMA_FS_LOCK
(
pStat
));
if
(
taosArrayGetSize
(
aQTaskInf
)
>
0
)
{
version
=
((
SQTaskFile
*
)
taosArrayGetLast
(
aQTaskInf
))
->
version
;
}
taosRUnLockLatch
(
RSMA_FS_LOCK
(
pStat
));
return
version
;
}
void
tdRSmaFSUnRef
(
SSma
*
pSma
,
SRSmaStat
*
pStat
,
int64_t
version
)
{
SVnode
*
pVnode
=
pSma
->
pVnode
;
SArray
*
aQTaskInf
=
RSMA_FS
(
pStat
)
->
aQTaskInf
;
...
...
source/dnode/vnode/src/sma/smaRollup.c
浏览文件 @
4cdaafe6
...
...
@@ -1342,29 +1342,31 @@ static int32_t tdRSmaQTaskInfoIterNextBlock(SRSmaQTaskInfoIter *pIter, bool *isF
return
TSDB_CODE_FAILED
;
}
if
(
tdReadTFile
(
pTFile
,
pIter
->
q
Buf
,
nBytes
)
!=
nBytes
)
{
if
(
tdReadTFile
(
pTFile
,
pIter
->
p
Buf
,
nBytes
)
!=
nBytes
)
{
return
TSDB_CODE_FAILED
;
}
int32_t
infoLen
=
0
;
taosDecodeFixedI32
(
pIter
->
q
Buf
,
&
infoLen
);
taosDecodeFixedI32
(
pIter
->
p
Buf
,
&
infoLen
);
if
(
infoLen
>
nBytes
)
{
if
(
infoLen
<=
RSMA_QTASKINFO_BUFSIZE
)
{
terrno
=
TSDB_CODE_RSMA_FILE_CORRUPTED
;
smaError
(
"iterate rsma qtaskinfo file %s failed since %s"
,
TD_TFILE_FULL_NAME
(
pIter
->
pTFile
),
terrstr
());
return
TSDB_CODE_FAILED
;
}
pIter
->
nAlloc
=
infoLen
;
void
*
pBuf
=
taosMemoryRealloc
(
pIter
->
pBuf
,
infoLen
);
if
(
!
pBuf
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
if
(
pIter
->
nAlloc
<
infoLen
)
{
pIter
->
nAlloc
=
infoLen
;
void
*
pBuf
=
taosMemoryRealloc
(
pIter
->
pBuf
,
infoLen
);
if
(
!
pBuf
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
pIter
->
pBuf
=
pBuf
;
}
pIter
->
pBuf
=
pBuf
;
pIter
->
qBuf
=
pIter
->
pBuf
;
nBytes
=
infoLen
;
if
(
tdSeekTFile
(
pTFile
,
pIter
->
offset
,
SEEK_SET
))
{
if
(
tdSeekTFile
(
pTFile
,
pIter
->
offset
,
SEEK_SET
)
<
0
)
{
return
TSDB_CODE_FAILED
;
}
...
...
@@ -1373,6 +1375,7 @@ static int32_t tdRSmaQTaskInfoIterNextBlock(SRSmaQTaskInfoIter *pIter, bool *isF
}
}
pIter
->
qBuf
=
pIter
->
pBuf
;
pIter
->
offset
+=
nBytes
;
pIter
->
nBytes
=
nBytes
;
pIter
->
nBufPos
=
0
;
...
...
@@ -1450,17 +1453,24 @@ int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash) {
return
TSDB_CODE_SUCCESS
;
}
int64_t
fsMaxVer
=
tdRSmaFSMaxVer
(
pSma
,
pRSmaStat
);
if
(
pRSmaStat
->
commitAppliedVer
<=
fsMaxVer
)
{
smaDebug
(
"vgId:%d, rsma persist, no need as applied %"
PRIi64
" not larger than fsMaxVer %"
PRIi64
,
vid
,
pRSmaStat
->
commitAppliedVer
,
fsMaxVer
);
return
TSDB_CODE_SUCCESS
;
}
STFile
tFile
=
{
0
};
#if 0
if (pRSmaStat->commitAppliedVer > 0) {
char qTaskInfoFName[TSDB_FILENAME_LEN];
tdRSmaQTaskInfoGetFileName(vid, pRSmaStat->commitAppliedVer, qTaskInfoFName);
if (tdInitTFile(&tFile, tfsGetPrimaryPath(pVnode->pTfs), qTaskInfoFName) < 0) {
smaError("vgId:%d, rsma persit, init %s failed since %s", vid, qTaskInfoFName, terrstr());
smaError("vgId:%d, rsma persi
s
t, init %s failed since %s", vid, qTaskInfoFName, terrstr());
goto _err;
}
if (tdCreateTFile(&tFile, true, TD_FTYPE_RSMA_QTASKINFO) < 0) {
smaError("vgId:%d, rsma persit, create %s failed since %s", vid, TD_TFILE_FULL_NAME(&tFile), terrstr());
smaError("vgId:%d, rsma persi
s
t, create %s failed since %s", vid, TD_TFILE_FULL_NAME(&tFile), terrstr());
goto _err;
}
smaDebug("vgId:%d, rsma, serialize qTaskInfo, file %s created", vid, TD_TFILE_FULL_NAME(&tFile));
...
...
@@ -1510,11 +1520,11 @@ int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash) {
char
qTaskInfoFName
[
TSDB_FILENAME_LEN
];
tdRSmaQTaskInfoGetFileName
(
vid
,
pRSmaStat
->
commitAppliedVer
,
qTaskInfoFName
);
if
(
tdInitTFile
(
&
tFile
,
tfsGetPrimaryPath
(
pVnode
->
pTfs
),
qTaskInfoFName
)
<
0
)
{
smaError
(
"vgId:%d, rsma persit, init %s failed since %s"
,
vid
,
qTaskInfoFName
,
terrstr
());
smaError
(
"vgId:%d, rsma persi
s
t, init %s failed since %s"
,
vid
,
qTaskInfoFName
,
terrstr
());
goto
_err
;
}
if
(
tdCreateTFile
(
&
tFile
,
true
,
TD_FTYPE_RSMA_QTASKINFO
)
<
0
)
{
smaError
(
"vgId:%d, rsma persit, create %s failed since %s"
,
vid
,
TD_TFILE_FULL_NAME
(
&
tFile
),
terrstr
());
smaError
(
"vgId:%d, rsma persi
s
t, create %s failed since %s"
,
vid
,
TD_TFILE_FULL_NAME
(
&
tFile
),
terrstr
());
goto
_err
;
}
smaDebug
(
"vgId:%d, rsma, table %"
PRIi64
" serialize qTaskInfo, file %s created"
,
vid
,
pRSmaInfo
->
suid
,
...
...
@@ -1558,7 +1568,7 @@ int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash) {
}
return
TSDB_CODE_SUCCESS
;
_err:
smaError
(
"vgId:%d, rsma persit failed since %s"
,
vid
,
terrstr
());
smaError
(
"vgId:%d, rsma persi
s
t failed since %s"
,
vid
,
terrstr
());
if
(
isFileCreated
)
{
tdRemoveTFile
(
&
tFile
);
tdDestroyTFile
(
&
tFile
);
...
...
source/dnode/vnode/src/tsdb/tsdbCache.c
浏览文件 @
4cdaafe6
...
...
@@ -457,7 +457,7 @@ static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow) {
tMergeTreeOpen
(
&
state
->
mergeTree
,
1
,
state
->
pDataFReader
,
state
->
suid
,
state
->
uid
,
&
(
STimeWindow
){.
skey
=
TSKEY_MIN
,
.
ekey
=
TSKEY_MAX
},
&
(
SVersionRange
){.
minVer
=
0
,
.
maxVer
=
UINT64_MAX
});
&
(
SVersionRange
){.
minVer
=
0
,
.
maxVer
=
UINT64_MAX
}
,
NULL
,
NULL
);
bool
hasVal
=
tMergeTreeNext
(
&
state
->
mergeTree
);
if
(
!
hasVal
)
{
state
->
state
=
SFSLASTNEXTROW_FILESET
;
...
...
source/dnode/vnode/src/tsdb/tsdbMergeTree.c
浏览文件 @
4cdaafe6
...
...
@@ -22,26 +22,207 @@ struct SLDataIter {
SDataFReader
*
pReader
;
int32_t
iStt
;
int8_t
backward
;
SArray
*
aSttBlk
;
int32_t
iSttBlk
;
SBlockData
bData
[
2
];
int32_t
loadIndex
;
int32_t
iRow
;
SRowInfo
rInfo
;
uint64_t
uid
;
STimeWindow
timeWindow
;
SVersionRange
verRange
;
SSttBlockLoadInfo
*
pBlockLoadInfo
;
};
static
SBlockData
*
getCurrentBlock
(
SLDataIter
*
pIter
)
{
return
&
pIter
->
bData
[
pIter
->
loadIndex
];
}
SSttBlockLoadInfo
*
tCreateLastBlockLoadInfo
()
{
SSttBlockLoadInfo
*
pLoadInfo
=
taosMemoryCalloc
(
TSDB_DEFAULT_STT_FILE
,
sizeof
(
SSttBlockLoadInfo
));
if
(
pLoadInfo
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
TSDB_DEFAULT_STT_FILE
;
++
i
)
{
pLoadInfo
[
i
].
blockIndex
[
0
]
=
-
1
;
pLoadInfo
[
i
].
blockIndex
[
1
]
=
-
1
;
pLoadInfo
[
i
].
currentLoadBlockIndex
=
1
;
int32_t
code
=
tBlockDataCreate
(
&
pLoadInfo
[
i
].
blockData
[
0
]);
if
(
code
)
{
terrno
=
code
;
}
code
=
tBlockDataCreate
(
&
pLoadInfo
[
i
].
blockData
[
1
]);
if
(
code
)
{
terrno
=
code
;
}
pLoadInfo
[
i
].
aSttBlk
=
taosArrayInit
(
4
,
sizeof
(
SSttBlk
));
}
return
pLoadInfo
;
}
void
resetLastBlockLoadInfo
(
SSttBlockLoadInfo
*
pLoadInfo
)
{
for
(
int32_t
i
=
0
;
i
<
TSDB_DEFAULT_STT_FILE
;
++
i
)
{
pLoadInfo
[
i
].
currentLoadBlockIndex
=
1
;
pLoadInfo
[
i
].
blockIndex
[
0
]
=
-
1
;
pLoadInfo
[
i
].
blockIndex
[
1
]
=
-
1
;
taosArrayClear
(
pLoadInfo
[
i
].
aSttBlk
);
pLoadInfo
[
i
].
elapsedTime
=
0
;
pLoadInfo
[
i
].
loadBlocks
=
0
;
}
}
void
getLastBlockLoadInfo
(
SSttBlockLoadInfo
*
pLoadInfo
,
int64_t
*
blocks
,
double
*
el
)
{
for
(
int32_t
i
=
0
;
i
<
TSDB_DEFAULT_STT_FILE
;
++
i
)
{
*
el
+=
pLoadInfo
[
i
].
elapsedTime
;
*
blocks
+=
pLoadInfo
[
i
].
loadBlocks
;
}
}
void
*
destroyLastBlockLoadInfo
(
SSttBlockLoadInfo
*
pLoadInfo
)
{
for
(
int32_t
i
=
0
;
i
<
TSDB_DEFAULT_STT_FILE
;
++
i
)
{
pLoadInfo
[
i
].
currentLoadBlockIndex
=
1
;
pLoadInfo
[
i
].
blockIndex
[
0
]
=
-
1
;
pLoadInfo
[
i
].
blockIndex
[
1
]
=
-
1
;
tBlockDataDestroy
(
&
pLoadInfo
[
i
].
blockData
[
0
],
true
);
tBlockDataDestroy
(
&
pLoadInfo
[
i
].
blockData
[
1
],
true
);
taosArrayDestroy
(
pLoadInfo
[
i
].
aSttBlk
);
}
taosMemoryFree
(
pLoadInfo
);
return
NULL
;
}
static
SBlockData
*
loadLastBlock
(
SLDataIter
*
pIter
,
const
char
*
idStr
)
{
int32_t
code
=
0
;
SSttBlockLoadInfo
*
pInfo
=
pIter
->
pBlockLoadInfo
;
if
(
pInfo
->
blockIndex
[
0
]
==
pIter
->
iSttBlk
)
{
return
&
pInfo
->
blockData
[
0
];
}
if
(
pInfo
->
blockIndex
[
1
]
==
pIter
->
iSttBlk
)
{
return
&
pInfo
->
blockData
[
1
];
}
pInfo
->
currentLoadBlockIndex
^=
1
;
if
(
pIter
->
pSttBlk
!=
NULL
)
{
// current block not loaded yet
int64_t
st
=
taosGetTimestampUs
();
code
=
tsdbReadSttBlock
(
pIter
->
pReader
,
pIter
->
iStt
,
pIter
->
pSttBlk
,
&
pInfo
->
blockData
[
pInfo
->
currentLoadBlockIndex
]);
double
el
=
(
taosGetTimestampUs
()
-
st
)
/
1000
.
0
;
pInfo
->
elapsedTime
+=
el
;
pInfo
->
loadBlocks
+=
1
;
tsdbDebug
(
"read last block, index:%d, last file index:%d, elapsed time:%.2f ms, %s"
,
pIter
->
iSttBlk
,
pIter
->
iStt
,
el
,
idStr
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_exit
;
}
pInfo
->
blockIndex
[
pInfo
->
currentLoadBlockIndex
]
=
pIter
->
iSttBlk
;
pIter
->
iRow
=
(
pIter
->
backward
)
?
pInfo
->
blockData
[
pInfo
->
currentLoadBlockIndex
].
nRow
:
-
1
;
}
return
&
pInfo
->
blockData
[
pInfo
->
currentLoadBlockIndex
];
_exit:
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
code
;
}
return
NULL
;
}
// find the earliest block that contains the required records
static
FORCE_INLINE
int32_t
findEarliestIndex
(
int32_t
index
,
uint64_t
uid
,
const
SSttBlk
*
pBlockList
,
int32_t
num
,
int32_t
backward
)
{
int32_t
i
=
index
;
int32_t
step
=
backward
?
1
:-
1
;
while
(
i
>=
0
&&
i
<
num
&&
uid
>=
pBlockList
[
i
].
minUid
&&
uid
<=
pBlockList
[
i
].
maxUid
)
{
i
+=
step
;
}
return
i
-
step
;
}
static
int32_t
binarySearchForStartBlock
(
SSttBlk
*
pBlockList
,
int32_t
num
,
uint64_t
uid
,
int32_t
backward
)
{
int32_t
midPos
=
-
1
;
if
(
num
<=
0
)
{
return
-
1
;
}
int32_t
firstPos
=
0
;
int32_t
lastPos
=
num
-
1
;
// find the first position which is bigger than the key
if
((
uid
>
pBlockList
[
lastPos
].
maxUid
)
||
(
uid
<
pBlockList
[
firstPos
].
minUid
))
{
return
-
1
;
}
while
(
1
)
{
if
(
uid
>=
pBlockList
[
firstPos
].
minUid
&&
uid
<=
pBlockList
[
firstPos
].
maxUid
)
{
return
findEarliestIndex
(
firstPos
,
uid
,
pBlockList
,
num
,
backward
);
}
if
(
uid
>
pBlockList
[
lastPos
].
maxUid
||
uid
<
pBlockList
[
firstPos
].
minUid
)
{
return
-
1
;
}
int32_t
numOfRows
=
lastPos
-
firstPos
+
1
;
midPos
=
(
numOfRows
>>
1u
)
+
firstPos
;
if
(
uid
<
pBlockList
[
midPos
].
minUid
)
{
lastPos
=
midPos
-
1
;
}
else
if
(
uid
>
pBlockList
[
midPos
].
maxUid
)
{
firstPos
=
midPos
+
1
;
}
else
{
return
findEarliestIndex
(
midPos
,
uid
,
pBlockList
,
num
,
backward
);
}
}
}
static
FORCE_INLINE
int32_t
findEarliestRow
(
int32_t
index
,
uint64_t
uid
,
const
uint64_t
*
uidList
,
int32_t
num
,
int32_t
backward
)
{
int32_t
i
=
index
;
int32_t
step
=
backward
?
1
:-
1
;
while
(
i
>=
0
&&
i
<
num
&&
uid
==
uidList
[
i
])
{
i
+=
step
;
}
return
i
-
step
;
}
static
int32_t
binarySearchForStartRowIndex
(
uint64_t
*
uidList
,
int32_t
num
,
uint64_t
uid
,
int32_t
backward
)
{
int32_t
firstPos
=
0
;
int32_t
lastPos
=
num
-
1
;
// find the first position which is bigger than the key
if
((
uid
>
uidList
[
lastPos
])
||
(
uid
<
uidList
[
firstPos
]))
{
return
-
1
;
}
while
(
1
)
{
if
(
uid
==
uidList
[
firstPos
])
{
return
findEarliestRow
(
firstPos
,
uid
,
uidList
,
num
,
backward
);
}
if
(
uid
>
uidList
[
lastPos
]
||
uid
<
uidList
[
firstPos
])
{
return
-
1
;
}
int32_t
numOfRows
=
lastPos
-
firstPos
+
1
;
int32_t
midPos
=
(
numOfRows
>>
1u
)
+
firstPos
;
static
SBlockData
*
getNextBlock
(
SLDataIter
*
pIter
)
{
pIter
->
loadIndex
^=
1
;
return
getCurrentBlock
(
pIter
);
if
(
uid
<
uidList
[
midPos
])
{
lastPos
=
midPos
-
1
;
}
else
if
(
uid
>
uidList
[
midPos
])
{
firstPos
=
midPos
+
1
;
}
else
{
return
findEarliestRow
(
midPos
,
uid
,
uidList
,
num
,
backward
);
}
}
}
int32_t
tLDataIterOpen
(
struct
SLDataIter
**
pIter
,
SDataFReader
*
pReader
,
int32_t
iStt
,
int8_t
backward
,
uint64_t
suid
,
uint64_t
uid
,
STimeWindow
*
pTimeWindow
,
SVersionRange
*
pRange
)
{
uint64_t
uid
,
STimeWindow
*
pTimeWindow
,
SVersionRange
*
pRange
,
SSttBlockLoadInfo
*
pBlockLoadInfo
)
{
int32_t
code
=
0
;
*
pIter
=
taosMemoryCalloc
(
1
,
sizeof
(
SLDataIter
));
if
(
*
pIter
==
NULL
)
{
...
...
@@ -55,60 +236,34 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t
(
*
pIter
)
->
backward
=
backward
;
(
*
pIter
)
->
verRange
=
*
pRange
;
(
*
pIter
)
->
timeWindow
=
*
pTimeWindow
;
(
*
pIter
)
->
aSttBlk
=
taosArrayInit
(
0
,
sizeof
(
SSttBlk
));
if
((
*
pIter
)
->
aSttBlk
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
code
=
tBlockDataCreate
(
&
(
*
pIter
)
->
bData
[
0
]);
if
(
code
)
{
goto
_exit
;
}
code
=
tBlockDataCreate
(
&
(
*
pIter
)
->
bData
[
1
]);
if
(
code
)
{
goto
_exit
;
}
code
=
tsdbReadSttBlk
(
pReader
,
iStt
,
(
*
pIter
)
->
aSttBlk
);
if
(
code
)
{
goto
_exit
;
}
size_t
size
=
taosArrayGetSize
((
*
pIter
)
->
aSttBlk
);
// find the start block
int32_t
index
=
-
1
;
if
(
!
backward
)
{
// asc
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SSttBlk
*
p
=
taosArrayGet
((
*
pIter
)
->
aSttBlk
,
i
);
if
(
p
->
suid
!=
suid
)
{
continue
;
}
if
(
p
->
minUid
<=
uid
&&
p
->
maxUid
>=
uid
)
{
index
=
i
;
break
;
}
}
}
else
{
// desc
for
(
int32_t
i
=
size
-
1
;
i
>=
0
;
--
i
)
{
SSttBlk
*
p
=
taosArrayGet
((
*
pIter
)
->
aSttBlk
,
i
);
if
(
p
->
suid
!=
suid
)
{
continue
;
(
*
pIter
)
->
pBlockLoadInfo
=
pBlockLoadInfo
;
if
(
taosArrayGetSize
(
pBlockLoadInfo
->
aSttBlk
)
==
0
)
{
code
=
tsdbReadSttBlk
(
pReader
,
iStt
,
pBlockLoadInfo
->
aSttBlk
);
if
(
code
)
{
goto
_exit
;
}
else
{
size_t
size
=
taosArrayGetSize
(
pBlockLoadInfo
->
aSttBlk
);
SArray
*
pTmp
=
taosArrayInit
(
size
,
sizeof
(
SSttBlk
));
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SSttBlk
*
p
=
taosArrayGet
(
pBlockLoadInfo
->
aSttBlk
,
i
);
if
(
p
->
suid
==
suid
)
{
taosArrayPush
(
pTmp
,
p
);
}
}
if
(
p
->
minUid
<=
uid
&&
p
->
maxUid
>=
uid
)
{
index
=
i
;
break
;
}
taosArrayDestroy
(
pBlockLoadInfo
->
aSttBlk
);
pBlockLoadInfo
->
aSttBlk
=
pTmp
;
}
}
(
*
pIter
)
->
iSttBlk
=
index
;
if
(
index
!=
-
1
)
{
(
*
pIter
)
->
pSttBlk
=
taosArrayGet
((
*
pIter
)
->
aSttBlk
,
(
*
pIter
)
->
iSttBlk
);
size_t
size
=
taosArrayGetSize
(
pBlockLoadInfo
->
aSttBlk
);
// find the start block
(
*
pIter
)
->
iSttBlk
=
binarySearchForStartBlock
(
pBlockLoadInfo
->
aSttBlk
->
pData
,
size
,
uid
,
backward
);
if
((
*
pIter
)
->
iSttBlk
!=
-
1
)
{
(
*
pIter
)
->
pSttBlk
=
taosArrayGet
(
pBlockLoadInfo
->
aSttBlk
,
(
*
pIter
)
->
iSttBlk
);
(
*
pIter
)
->
iRow
=
((
*
pIter
)
->
backward
)
?
(
*
pIter
)
->
pSttBlk
->
nRow
:
-
1
;
}
_exit:
...
...
@@ -116,9 +271,6 @@ _exit:
}
void
tLDataIterClose
(
SLDataIter
*
pIter
)
{
tBlockDataDestroy
(
&
pIter
->
bData
[
0
],
1
);
tBlockDataDestroy
(
&
pIter
->
bData
[
1
],
1
);
taosArrayDestroy
(
pIter
->
aSttBlk
);
taosMemoryFree
(
pIter
);
}
...
...
@@ -127,9 +279,9 @@ void tLDataIterNextBlock(SLDataIter *pIter) {
pIter
->
iSttBlk
+=
step
;
int32_t
index
=
-
1
;
size_t
size
=
taosArrayGetSize
(
pIter
->
aSttBlk
)
;
size_t
size
=
pIter
->
pBlockLoadInfo
->
aSttBlk
->
size
;
for
(
int32_t
i
=
pIter
->
iSttBlk
;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
SSttBlk
*
p
=
taosArrayGet
(
pIter
->
aSttBlk
,
i
);
SSttBlk
*
p
=
taosArrayGet
(
pIter
->
pBlockLoadInfo
->
aSttBlk
,
i
);
if
((
!
pIter
->
backward
)
&&
p
->
minUid
>
pIter
->
uid
)
{
break
;
}
...
...
@@ -166,32 +318,41 @@ void tLDataIterNextBlock(SLDataIter *pIter) {
}
}
if
(
index
==
-
1
)
{
pIter
->
pSttBlk
=
NULL
;
}
else
{
pIter
->
pSttBlk
=
(
SSttBlk
*
)
taosArrayGet
(
pIter
->
aSttBlk
,
pIter
->
iSttBlk
);
pIter
->
pSttBlk
=
NULL
;
if
(
index
!=
-
1
)
{
pIter
->
pSttBlk
=
(
SSttBlk
*
)
taosArrayGet
(
pIter
->
pBlockLoadInfo
->
aSttBlk
,
pIter
->
iSttBlk
);
}
}
static
void
findNextValidRow
(
SLDataIter
*
pIter
)
{
static
void
findNextValidRow
(
SLDataIter
*
pIter
,
const
char
*
idStr
)
{
int32_t
step
=
pIter
->
backward
?
-
1
:
1
;
bool
hasVal
=
false
;
int32_t
i
=
pIter
->
iRow
;
SBlockData
*
pBlockData
=
getCurrentBlock
(
pIter
);
SBlockData
*
pBlockData
=
loadLastBlock
(
pIter
,
idStr
);
// mostly we only need to find the start position for a given table
if
((((
i
==
0
)
&&
(
!
pIter
->
backward
))
||
(
i
==
pBlockData
->
nRow
-
1
&&
pIter
->
backward
))
&&
pBlockData
->
aUid
!=
NULL
)
{
i
=
binarySearchForStartRowIndex
((
uint64_t
*
)
pBlockData
->
aUid
,
pBlockData
->
nRow
,
pIter
->
uid
,
pIter
->
backward
);
if
(
i
==
-
1
)
{
pIter
->
iRow
=
-
1
;
return
;
}
}
for
(;
i
<
pBlockData
->
nRow
&&
i
>=
0
;
i
+=
step
)
{
if
(
pBlockData
->
aUid
!=
NULL
)
{
if
(
!
pIter
->
backward
)
{
if
(
pBlockData
->
aUid
[
i
]
<
pIter
->
uid
)
{
/*
if (pBlockData->aUid[i] < pIter->uid) {
continue;
}
else
if
(
pBlockData
->
aUid
[
i
]
>
pIter
->
uid
)
{
} else
*/
if
(
pBlockData
->
aUid
[
i
]
>
pIter
->
uid
)
{
break
;
}
}
else
{
if
(
pBlockData
->
aUid
[
i
]
>
pIter
->
uid
)
{
/*
if (pBlockData->aUid[i] > pIter->uid) {
continue;
}
else
if
(
pBlockData
->
aUid
[
i
]
<
pIter
->
uid
)
{
} else
*/
if
(
pBlockData
->
aUid
[
i
]
<
pIter
->
uid
)
{
break
;
}
}
...
...
@@ -229,7 +390,7 @@ static void findNextValidRow(SLDataIter *pIter) {
pIter
->
iRow
=
(
hasVal
)
?
i
:
-
1
;
}
bool
tLDataIterNextRow
(
SLDataIter
*
pIter
)
{
bool
tLDataIterNextRow
(
SLDataIter
*
pIter
,
const
char
*
idStr
)
{
int32_t
code
=
0
;
int32_t
step
=
pIter
->
backward
?
-
1
:
1
;
...
...
@@ -238,23 +399,12 @@ bool tLDataIterNextRow(SLDataIter *pIter) {
return
false
;
}
int32_t
iBlockL
=
pIter
->
iSttBlk
;
SBlockData
*
pBlockData
=
getCurrentBlock
(
pIter
);
if
(
pBlockData
->
nRow
==
0
&&
pIter
->
pSttBlk
!=
NULL
)
{
// current block not loaded yet
pBlockData
=
getNextBlock
(
pIter
);
code
=
tsdbReadSttBlock
(
pIter
->
pReader
,
pIter
->
iStt
,
pIter
->
pSttBlk
,
pBlockData
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_exit
;
}
pIter
->
iRow
=
(
pIter
->
backward
)
?
pBlockData
->
nRow
:
-
1
;
}
int32_t
iBlockL
=
pIter
->
iSttBlk
;
SBlockData
*
pBlockData
=
loadLastBlock
(
pIter
,
idStr
);
pIter
->
iRow
+=
step
;
while
(
1
)
{
findNextValidRow
(
pIter
);
findNextValidRow
(
pIter
,
idStr
);
if
(
pIter
->
iRow
>=
pBlockData
->
nRow
||
pIter
->
iRow
<
0
)
{
tLDataIterNextBlock
(
pIter
);
...
...
@@ -266,12 +416,8 @@ bool tLDataIterNextRow(SLDataIter *pIter) {
}
if
(
iBlockL
!=
pIter
->
iSttBlk
)
{
pBlockData
=
getNextBlock
(
pIter
);
code
=
tsdbReadSttBlock
(
pIter
->
pReader
,
pIter
->
iStt
,
pIter
->
pSttBlk
,
pBlockData
);
if
(
code
)
{
goto
_exit
;
}
pIter
->
iRow
=
pIter
->
backward
?
(
pBlockData
->
nRow
-
1
)
:
0
;
pBlockData
=
loadLastBlock
(
pIter
,
idStr
);
pIter
->
iRow
+=
step
;
}
}
...
...
@@ -313,7 +459,7 @@ static FORCE_INLINE int32_t tLDataIterCmprFn(const void *p1, const void *p2) {
}
int32_t
tMergeTreeOpen
(
SMergeTree
*
pMTree
,
int8_t
backward
,
SDataFReader
*
pFReader
,
uint64_t
suid
,
uint64_t
uid
,
STimeWindow
*
pTimeWindow
,
SVersionRange
*
pVerRange
)
{
STimeWindow
*
pTimeWindow
,
SVersionRange
*
pVerRange
,
void
*
pBlockLoadInfo
,
const
char
*
idStr
)
{
pMTree
->
backward
=
backward
;
pMTree
->
pIter
=
NULL
;
pMTree
->
pIterList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
...
...
@@ -321,22 +467,36 @@ int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFRead
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pMTree
->
idStr
=
idStr
;
tRBTreeCreate
(
&
pMTree
->
rbt
,
tLDataIterCmprFn
);
int32_t
code
=
TSDB_CODE_OUT_OF_MEMORY
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
SSttBlockLoadInfo
*
pLoadInfo
=
NULL
;
if
(
pBlockLoadInfo
==
NULL
)
{
if
(
pMTree
->
pLoadInfo
==
NULL
)
{
pMTree
->
destroyLoadInfo
=
true
;
pMTree
->
pLoadInfo
=
tCreateLastBlockLoadInfo
();
}
pLoadInfo
=
pMTree
->
pLoadInfo
;
}
else
{
pLoadInfo
=
pBlockLoadInfo
;
}
struct
SLDataIter
*
pIterList
[
TSDB_DEFAULT_STT_FILE
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
pFReader
->
pSet
->
nSttF
;
++
i
)
{
// open all last file
code
=
tLDataIterOpen
(
&
pIterList
[
i
],
pFReader
,
i
,
pMTree
->
backward
,
suid
,
uid
,
pTimeWindow
,
pVerRange
);
struct
SLDataIter
*
pIter
=
NULL
;
code
=
tLDataIterOpen
(
&
pIter
,
pFReader
,
i
,
pMTree
->
backward
,
suid
,
uid
,
pTimeWindow
,
pVerRange
,
&
pLoadInfo
[
i
]);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_end
;
}
bool
hasVal
=
tLDataIterNextRow
(
pIter
List
[
i
]
);
bool
hasVal
=
tLDataIterNextRow
(
pIter
,
pMTree
->
idStr
);
if
(
hasVal
)
{
taosArrayPush
(
pMTree
->
pIterList
,
&
pIter
List
[
i
]
);
tMergeTreeAddIter
(
pMTree
,
pIter
List
[
i
]
);
taosArrayPush
(
pMTree
->
pIterList
,
&
pIter
);
tMergeTreeAddIter
(
pMTree
,
pIter
);
}
else
{
tLDataIterClose
(
pIter
List
[
i
]
);
tLDataIterClose
(
pIter
);
}
}
...
...
@@ -354,7 +514,7 @@ bool tMergeTreeNext(SMergeTree *pMTree) {
if
(
pMTree
->
pIter
)
{
SLDataIter
*
pIter
=
pMTree
->
pIter
;
bool
hasVal
=
tLDataIterNextRow
(
pIter
);
bool
hasVal
=
tLDataIterNextRow
(
pIter
,
pMTree
->
idStr
);
if
(
!
hasVal
)
{
pMTree
->
pIter
=
NULL
;
}
...
...
@@ -393,4 +553,9 @@ void tMergeTreeClose(SMergeTree *pMTree) {
pMTree
->
pIterList
=
taosArrayDestroy
(
pMTree
->
pIterList
);
pMTree
->
pIter
=
NULL
;
if
(
pMTree
->
destroyLoadInfo
)
{
pMTree
->
pLoadInfo
=
destroyLastBlockLoadInfo
(
pMTree
->
pLoadInfo
);
pMTree
->
destroyLoadInfo
=
false
;
}
}
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
4cdaafe6
...
...
@@ -17,8 +17,6 @@
#include "tsdb.h"
#define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC)
#define ALL_ROWS_CHECKED_INDEX (INT16_MIN)
#define INITIAL_ROW_INDEX_VAL (-1)
typedef
enum
{
EXTERNAL_ROWS_PREV
=
0x1
,
...
...
@@ -72,6 +70,8 @@ typedef struct SIOCostSummary {
double
smaLoadTime
;
int64_t
lastBlockLoad
;
double
lastBlockLoadTime
;
int64_t
composedBlocks
;
double
buildComposedBlockTime
;
}
SIOCostSummary
;
typedef
struct
SBlockLoadSuppInfo
{
...
...
@@ -88,6 +88,7 @@ typedef struct SLastBlockReader {
int32_t
order
;
uint64_t
uid
;
SMergeTree
mergeTree
;
SSttBlockLoadInfo
*
pInfo
;
}
SLastBlockReader
;
typedef
struct
SFilesetIter
{
...
...
@@ -226,13 +227,14 @@ static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, const STableK
return
NULL
;
}
int32_t
step
=
ASCENDING_TRAVERSE
(
pTsdbReader
->
order
)
?
1
:-
1
;
for
(
int32_t
j
=
0
;
j
<
numOfTables
;
++
j
)
{
STableBlockScanInfo
info
=
{.
lastKey
=
0
,
.
uid
=
idList
[
j
].
uid
};
if
(
ASCENDING_TRAVERSE
(
pTsdbReader
->
order
))
{
info
.
lastKey
=
pTsdbReader
->
window
.
skey
-
step
;
int64_t
skey
=
pTsdbReader
->
window
.
skey
;
info
.
lastKey
=
(
skey
>
INT64_MIN
)
?
(
skey
-
1
)
:
skey
;
}
else
{
info
.
lastKey
=
pTsdbReader
->
window
.
ekey
-
step
;
int64_t
ekey
=
pTsdbReader
->
window
.
ekey
;
info
.
lastKey
=
(
ekey
<
INT64_MAX
)
?
(
ekey
+
1
)
:
ekey
;
}
taosHashPut
(
pTableMap
,
&
info
.
uid
,
sizeof
(
uint64_t
),
&
info
,
sizeof
(
info
));
...
...
@@ -319,8 +321,7 @@ static void limitOutputBufferSize(const SQueryTableDataCond* pCond, int32_t* cap
}
// init file iterator
static
int32_t
initFilesetIterator
(
SFilesetIter
*
pIter
,
SArray
*
aDFileSet
,
STsdbReader
*
pReader
/*int32_t order, const char* idstr*/
)
{
static
int32_t
initFilesetIterator
(
SFilesetIter
*
pIter
,
SArray
*
aDFileSet
,
STsdbReader
*
pReader
)
{
size_t
numOfFileset
=
taosArrayGetSize
(
aDFileSet
);
pIter
->
index
=
ASCENDING_TRAVERSE
(
pReader
->
order
)
?
-
1
:
numOfFileset
;
...
...
@@ -345,6 +346,14 @@ static int32_t initFilesetIterator(SFilesetIter* pIter, SArray* aDFileSet,
pLReader
->
uid
=
0
;
tMergeTreeClose
(
&
pLReader
->
mergeTree
);
if
(
pLReader
->
pInfo
==
NULL
)
{
pLReader
->
pInfo
=
tCreateLastBlockLoadInfo
();
if
(
pLReader
->
pInfo
==
NULL
)
{
tsdbDebug
(
"init fileset iterator failed, code:%s %s"
,
tstrerror
(
terrno
),
pReader
->
idStr
);
return
terrno
;
}
}
tsdbDebug
(
"init fileset iterator, total files:%d %s"
,
pIter
->
numOfFiles
,
pReader
->
idStr
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -358,8 +367,12 @@ static bool filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader) {
return
false
;
}
SIOCostSummary
*
pSum
=
&
pReader
->
cost
;
getLastBlockLoadInfo
(
pIter
->
pLastBlockReader
->
pInfo
,
&
pSum
->
lastBlockLoad
,
&
pReader
->
cost
.
lastBlockLoadTime
);
pIter
->
pLastBlockReader
->
uid
=
0
;
tMergeTreeClose
(
&
pIter
->
pLastBlockReader
->
mergeTree
);
resetLastBlockLoadInfo
(
pIter
->
pLastBlockReader
->
pInfo
);
// check file the time range of coverage
STimeWindow
win
=
{
0
};
...
...
@@ -1230,6 +1243,38 @@ static bool tryCopyDistinctRowFromFileBlock(STsdbReader* pReader, SBlockData* pB
return
false
;
}
static
bool
nextRowFromLastBlocks
(
SLastBlockReader
*
pLastBlockReader
,
STableBlockScanInfo
*
pBlockScanInfo
)
{
while
(
1
)
{
bool
hasVal
=
tMergeTreeNext
(
&
pLastBlockReader
->
mergeTree
);
if
(
!
hasVal
)
{
return
false
;
}
TSDBROW
row
=
tMergeTreeGetRow
(
&
pLastBlockReader
->
mergeTree
);
TSDBKEY
k
=
TSDBROW_KEY
(
&
row
);
if
(
!
hasBeenDropped
(
pBlockScanInfo
->
delSkyline
,
&
pBlockScanInfo
->
lastBlockDelIndex
,
&
k
,
pLastBlockReader
->
order
))
{
return
true
;
}
}
}
static
bool
tryCopyDistinctRowFromSttBlock
(
TSDBROW
*
fRow
,
SLastBlockReader
*
pLastBlockReader
,
STableBlockScanInfo
*
pScanInfo
,
int64_t
ts
,
STsdbReader
*
pReader
)
{
bool
hasVal
=
nextRowFromLastBlocks
(
pLastBlockReader
,
pScanInfo
);
if
(
hasVal
)
{
int64_t
next1
=
getCurrentKeyInLastBlock
(
pLastBlockReader
);
if
(
next1
!=
ts
)
{
doAppendRowFromFileBlock
(
pReader
->
pResBlock
,
pReader
,
fRow
->
pBlockData
,
fRow
->
iRow
);
return
true
;
}
}
else
{
doAppendRowFromFileBlock
(
pReader
->
pResBlock
,
pReader
,
fRow
->
pBlockData
,
fRow
->
iRow
);
return
true
;
}
return
false
;
}
static
FORCE_INLINE
STSchema
*
doGetSchemaForTSRow
(
int32_t
sversion
,
STsdbReader
*
pReader
,
uint64_t
uid
)
{
// always set the newest schema version in pReader->pSchema
if
(
pReader
->
pSchema
==
NULL
)
{
...
...
@@ -1377,30 +1422,54 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
STableBlockScanInfo
*
pBlockScanInfo
,
SBlockData
*
pBlockData
,
bool
mergeBlockData
)
{
SFileBlockDumpInfo
*
pDumpInfo
=
&
pReader
->
status
.
fBlockDumpInfo
;
// SBlockData* pLastBlockData = &pLastBlockReader->lastBlockData;
int64_t
tsLastBlock
=
getCurrentKeyInLastBlock
(
pLastBlockReader
);
int64_t
tsLastBlock
=
getCurrentKeyInLastBlock
(
pLastBlockReader
);
STSRow
*
pTSRow
=
NULL
;
SRowMerger
merge
=
{
0
};
TSDBROW
fRow
=
tMergeTreeGetRow
(
&
pLastBlockReader
->
mergeTree
);
TSDBROW
fRow
=
tMergeTreeGetRow
(
&
pLastBlockReader
->
mergeTree
);
tRowMergerInit
(
&
merge
,
&
fRow
,
pReader
->
pSchema
);
doMergeRowsInLastBlock
(
pLastBlockReader
,
pBlockScanInfo
,
tsLastBlock
,
&
merge
);
// only last block exists
if
((
!
mergeBlockData
)
||
(
tsLastBlock
!=
pBlockData
->
aTSKEY
[
pDumpInfo
->
rowIndex
]))
{
if
(
tryCopyDistinctRowFromSttBlock
(
&
fRow
,
pLastBlockReader
,
pBlockScanInfo
,
tsLastBlock
,
pReader
))
{
return
TSDB_CODE_SUCCESS
;
}
else
{
tRowMergerInit
(
&
merge
,
&
fRow
,
pReader
->
pSchema
);
// merge with block data if ts == key
if
(
mergeBlockData
&&
(
tsLastBlock
==
pBlockData
->
aTSKEY
[
pDumpInfo
->
rowIndex
]))
{
doMergeRowsInFileBlocks
(
pBlockData
,
pBlockScanInfo
,
pReader
,
&
merge
);
}
TSDBROW
fRow1
=
tMergeTreeGetRow
(
&
pLastBlockReader
->
mergeTree
);
tRowMerge
(
&
merge
,
&
fRow1
);
doMergeRowsInLastBlock
(
pLastBlockReader
,
pBlockScanInfo
,
tsLastBlock
,
&
merge
);
int32_t
code
=
tRowMergerGetRow
(
&
merge
,
&
pTSRow
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
int32_t
code
=
tRowMergerGetRow
(
&
merge
,
&
pTSRow
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
doAppendRowFromTSRow
(
pReader
->
pResBlock
,
pReader
,
pTSRow
,
pBlockScanInfo
->
uid
);
doAppendRowFromTSRow
(
pReader
->
pResBlock
,
pReader
,
pTSRow
,
pBlockScanInfo
->
uid
);
taosMemoryFree
(
pTSRow
);
tRowMergerClear
(
&
merge
);
}
}
else
{
// not merge block data
tRowMergerInit
(
&
merge
,
&
fRow
,
pReader
->
pSchema
);
doMergeRowsInLastBlock
(
pLastBlockReader
,
pBlockScanInfo
,
tsLastBlock
,
&
merge
);
ASSERT
(
mergeBlockData
);
// merge with block data if ts == key
if
(
tsLastBlock
==
pBlockData
->
aTSKEY
[
pDumpInfo
->
rowIndex
])
{
doMergeRowsInFileBlocks
(
pBlockData
,
pBlockScanInfo
,
pReader
,
&
merge
);
}
int32_t
code
=
tRowMergerGetRow
(
&
merge
,
&
pTSRow
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
doAppendRowFromTSRow
(
pReader
->
pResBlock
,
pReader
,
pTSRow
,
pBlockScanInfo
->
uid
);
taosMemoryFree
(
pTSRow
);
tRowMergerClear
(
&
merge
);
}
taosMemoryFree
(
pTSRow
);
tRowMergerClear
(
&
merge
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -1851,57 +1920,40 @@ static bool isValidFileBlockRow(SBlockData* pBlockData, SFileBlockDumpInfo* pDum
static
bool
outOfTimeWindow
(
int64_t
ts
,
STimeWindow
*
pWindow
)
{
return
(
ts
>
pWindow
->
ekey
)
||
(
ts
<
pWindow
->
skey
);
}
static
bool
nextRowFromLastBlocks
(
SLastBlockReader
*
pLastBlockReader
,
STableBlockScanInfo
*
pBlockScanInfo
)
{
while
(
1
)
{
bool
hasVal
=
tMergeTreeNext
(
&
pLastBlockReader
->
mergeTree
);
if
(
!
hasVal
)
{
return
false
;
}
TSDBROW
row
=
tMergeTreeGetRow
(
&
pLastBlockReader
->
mergeTree
);
TSDBKEY
k
=
TSDBROW_KEY
(
&
row
);
if
(
!
hasBeenDropped
(
pBlockScanInfo
->
delSkyline
,
&
pBlockScanInfo
->
lastBlockDelIndex
,
&
k
,
pLastBlockReader
->
order
))
{
return
true
;
}
}
}
static
bool
initLastBlockReader
(
SLastBlockReader
*
pLastBlockReader
,
STableBlockScanInfo
*
pBlockScanInfo
,
STsdbReader
*
pReader
)
{
static
bool
initLastBlockReader
(
SLastBlockReader
*
pLBlockReader
,
STableBlockScanInfo
*
pScanInfo
,
STsdbReader
*
pReader
)
{
// the last block reader has been initialized for this table.
if
(
pL
astBlockReader
->
uid
==
pBlock
ScanInfo
->
uid
)
{
if
(
pL
BlockReader
->
uid
==
p
ScanInfo
->
uid
)
{
return
true
;
}
if
(
pL
ast
BlockReader
->
uid
!=
0
)
{
tMergeTreeClose
(
&
pL
ast
BlockReader
->
mergeTree
);
if
(
pLBlockReader
->
uid
!=
0
)
{
tMergeTreeClose
(
&
pLBlockReader
->
mergeTree
);
}
initMemDataIterator
(
p
Block
ScanInfo
,
pReader
);
pL
astBlockReader
->
uid
=
pBlock
ScanInfo
->
uid
;
initMemDataIterator
(
pScanInfo
,
pReader
);
pL
BlockReader
->
uid
=
p
ScanInfo
->
uid
;
int32_t
step
=
ASCENDING_TRAVERSE
(
pL
ast
BlockReader
->
order
)
?
1
:-
1
;
STimeWindow
w
=
pL
ast
BlockReader
->
window
;
if
(
ASCENDING_TRAVERSE
(
pL
ast
BlockReader
->
order
))
{
w
.
skey
=
p
Block
ScanInfo
->
lastKey
+
step
;
int32_t
step
=
ASCENDING_TRAVERSE
(
pLBlockReader
->
order
)
?
1
:-
1
;
STimeWindow
w
=
pLBlockReader
->
window
;
if
(
ASCENDING_TRAVERSE
(
pLBlockReader
->
order
))
{
w
.
skey
=
pScanInfo
->
lastKey
+
step
;
}
else
{
w
.
ekey
=
p
Block
ScanInfo
->
lastKey
+
step
;
w
.
ekey
=
pScanInfo
->
lastKey
+
step
;
}
int32_t
code
=
tMergeTreeOpen
(
&
pL
astBlockReader
->
mergeTree
,
(
pLast
BlockReader
->
order
==
TSDB_ORDER_DESC
),
pReader
->
pFileReader
,
pReader
->
suid
,
pBlockScanInfo
->
uid
,
&
w
,
&
pLastBlockReader
->
verRange
);
tMergeTreeOpen
(
&
pL
BlockReader
->
mergeTree
,
(
pL
BlockReader
->
order
==
TSDB_ORDER_DESC
),
pReader
->
pFileReader
,
pReader
->
suid
,
pScanInfo
->
uid
,
&
w
,
&
pLBlockReader
->
verRange
,
pLBlockReader
->
pInfo
,
pReader
->
idStr
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
false
;
}
return
nextRowFromLastBlocks
(
pL
astBlockReader
,
pBlock
ScanInfo
);
return
nextRowFromLastBlocks
(
pL
BlockReader
,
p
ScanInfo
);
}
static
int64_t
getCurrentKeyInLastBlock
(
SLastBlockReader
*
pLastBlockReader
)
{
TSDBROW
row
=
tMergeTreeGetRow
(
&
pLastBlockReader
->
mergeTree
);
TSDBKEY
key
=
TSDBROW_KEY
(
&
row
);
return
key
.
ts
;
return
TSDBROW_TS
(
&
row
);
}
static
bool
hasDataInLastBlock
(
SLastBlockReader
*
pLastBlockReader
)
{
return
pLastBlockReader
->
mergeTree
.
pIter
!=
NULL
;
}
...
...
@@ -1931,8 +1983,6 @@ int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBloc
tRowMergerClear
(
&
merge
);
return
TSDB_CODE_SUCCESS
;
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
buildComposedDataBlockImpl
(
STsdbReader
*
pReader
,
STableBlockScanInfo
*
pBlockScanInfo
,
...
...
@@ -2025,13 +2075,16 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
blockDataUpdateTsWindow
(
pResBlock
,
0
);
setComposedBlockFlag
(
pReader
,
true
);
int64_t
et
=
taosGetTimestampUs
();
double
el
=
(
taosGetTimestampUs
()
-
st
)
/
1000
.
0
;
pReader
->
cost
.
composedBlocks
+=
1
;
pReader
->
cost
.
buildComposedBlockTime
+=
el
;
if
(
pResBlock
->
info
.
rows
>
0
)
{
tsdbDebug
(
"%p uid:%"
PRIu64
", composed data block created, brange:%"
PRIu64
"-%"
PRIu64
" rows:%d, elapsed time:%.2f ms %s"
,
pReader
,
pBlockScanInfo
->
uid
,
pResBlock
->
info
.
window
.
skey
,
pResBlock
->
info
.
window
.
ekey
,
pResBlock
->
info
.
rows
,
(
et
-
st
)
/
1000
.
0
,
pReader
->
idStr
);
pResBlock
->
info
.
rows
,
el
,
pReader
->
idStr
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -3074,11 +3127,16 @@ int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, S
SColumnInfoData
*
pCol
=
taosArrayGet
(
pResBlock
->
pDataBlock
,
i
);
SColData
*
pData
=
tBlockDataGetColDataByIdx
(
pBlockData
,
j
);
if
(
pData
->
cid
<
pCol
->
info
.
colId
)
{
j
+=
1
;
continue
;
}
if
(
pData
->
cid
==
pCol
->
info
.
colId
)
{
tColDataGetValue
(
pData
,
rowIndex
,
&
cv
);
doCopyColVal
(
pCol
,
outputRowIndex
,
i
,
&
cv
,
pSupInfo
);
j
+=
1
;
}
else
{
// the specified column does not exist in file block, fill with null data
}
else
if
(
pData
->
cid
>
pCol
->
info
.
colId
)
{
// the specified column does not exist in file block, fill with null data
colDataAppendNULL
(
pCol
,
outputRowIndex
);
}
...
...
@@ -3200,11 +3258,18 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl
}
}
// NOTE: the endVersion in pCond is the data version not schema version, so pCond->endVersion is not correct here.
if
(
pCond
->
suid
!=
0
)
{
pReader
->
pSchema
=
metaGetTbTSchema
(
pReader
->
pTsdb
->
pVnode
->
pMeta
,
pReader
->
suid
,
pCond
->
endVersion
);
pReader
->
pSchema
=
metaGetTbTSchema
(
pReader
->
pTsdb
->
pVnode
->
pMeta
,
pReader
->
suid
,
/*pCond->endVersion*/
-
1
);
if
(
pReader
->
pSchema
==
NULL
)
{
tsdbError
(
"failed to get table schema, suid:%"
PRIu64
", ver:%"
PRId64
" , %s"
,
pReader
->
suid
,
-
1
,
pReader
->
idStr
);
}
}
else
if
(
taosArrayGetSize
(
pTableList
)
>
0
)
{
STableKeyInfo
*
pKey
=
taosArrayGet
(
pTableList
,
0
);
pReader
->
pSchema
=
metaGetTbTSchema
(
pReader
->
pTsdb
->
pVnode
->
pMeta
,
pKey
->
uid
,
pCond
->
endVersion
);
pReader
->
pSchema
=
metaGetTbTSchema
(
pReader
->
pTsdb
->
pVnode
->
pMeta
,
pKey
->
uid
,
/*pCond->endVersion*/
-
1
);
if
(
pReader
->
pSchema
==
NULL
)
{
tsdbError
(
"failed to get table schema, uid:%"
PRIu64
", ver:%"
PRId64
" , %s"
,
pKey
->
uid
,
-
1
,
pReader
->
idStr
);
}
}
int32_t
numOfTables
=
taosArrayGetSize
(
pTableList
);
...
...
@@ -3301,23 +3366,27 @@ void tsdbReaderClose(STsdbReader* pReader) {
tsdbUntakeReadSnap
(
pReader
->
pTsdb
,
pReader
->
pReadSnap
);
taosMemoryFree
(
pReader
->
status
.
uidCheckInfo
.
tableUidList
);
SIOCostSummary
*
pCost
=
&
pReader
->
cost
;
SFilesetIter
*
pFilesetIter
=
&
pReader
->
status
.
fileIter
;
if
(
pFilesetIter
->
pLastBlockReader
!=
NULL
)
{
tMergeTreeClose
(
&
pFilesetIter
->
pLastBlockReader
->
mergeTree
);
taosMemoryFree
(
pFilesetIter
->
pLastBlockReader
);
}
SLastBlockReader
*
pLReader
=
pFilesetIter
->
pLastBlockReader
;
tMergeTreeClose
(
&
pLReader
->
mergeTree
);
SIOCostSummary
*
pCost
=
&
pReader
->
cost
;
getLastBlockLoadInfo
(
pLReader
->
pInfo
,
&
pCost
->
lastBlockLoad
,
&
pCost
->
lastBlockLoadTime
)
;
tsdbDebug
(
"%p :io-cost summary: head-file:%"
PRIu64
", head-file time:%.2f ms, SMA:%"
PRId64
" SMA-time:%.2f ms, fileBlocks:%"
PRId64
", fileBlocks-time:%.2f ms, "
"build in-memory-block-time:%.2f ms, lastBlocks:%"
PRId64
", lastBlocks-time:%.2f ms, STableBlockScanInfo size:%.2f Kb %s"
,
pReader
,
pCost
->
headFileLoad
,
pCost
->
headFileLoadTime
,
pCost
->
smaDataLoad
,
pCost
->
smaLoadTime
,
pCost
->
numOfBlocks
,
pCost
->
blockLoadTime
,
pCost
->
buildmemBlock
,
pCost
->
lastBlockLoad
,
pCost
->
lastBlockLoadTime
,
numOfTables
*
sizeof
(
STableBlockScanInfo
)
/
1000
.
0
,
pReader
->
idStr
);
pLReader
->
pInfo
=
destroyLastBlockLoadInfo
(
pLReader
->
pInfo
);
taosMemoryFree
(
pLReader
);
}
tsdbDebug
(
"%p :io-cost summary: head-file:%"
PRIu64
", head-file time:%.2f ms, SMA:%"
PRId64
" SMA-time:%.2f ms, fileBlocks:%"
PRId64
", fileBlocks-load-time:%.2f ms, "
"build in-memory-block-time:%.2f ms, lastBlocks:%"
PRId64
", lastBlocks-time:%.2f ms, composed-blocks:%"
PRId64
", composed-blocks-time:%.2fms, STableBlockScanInfo size:%.2f Kb %s"
,
pReader
,
pCost
->
headFileLoad
,
pCost
->
headFileLoadTime
,
pCost
->
smaDataLoad
,
pCost
->
smaLoadTime
,
pCost
->
numOfBlocks
,
pCost
->
blockLoadTime
,
pCost
->
buildmemBlock
,
pCost
->
lastBlockLoad
,
pCost
->
lastBlockLoadTime
,
pCost
->
composedBlocks
,
pCost
->
buildComposedBlockTime
,
numOfTables
*
sizeof
(
STableBlockScanInfo
)
/
1000
.
0
,
pReader
->
idStr
);
taosMemoryFree
(
pReader
->
idStr
);
taosMemoryFree
(
pReader
->
pSchema
);
...
...
source/libs/executor/inc/executil.h
浏览文件 @
4cdaafe6
...
...
@@ -126,6 +126,7 @@ SArray* extractPartitionColInfo(SNodeList* pNodeList);
SArray
*
extractColMatchInfo
(
SNodeList
*
pNodeList
,
SDataBlockDescNode
*
pOutputNodeList
,
int32_t
*
numOfOutputCols
,
int32_t
type
);
void
createExprFromTargetNode
(
SExprInfo
*
pExp
,
STargetNode
*
pTargetNode
);
SExprInfo
*
createExprInfo
(
SNodeList
*
pNodeList
,
SNodeList
*
pGroupKeys
,
int32_t
*
numOfExprs
);
SqlFunctionCtx
*
createSqlFunctionCtx
(
SExprInfo
*
pExprInfo
,
int32_t
numOfOutput
,
int32_t
**
rowEntryInfoOffset
);
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
4cdaafe6
...
...
@@ -411,7 +411,7 @@ typedef enum EStreamScanMode {
STREAM_SCAN_FROM_READERHANDLE
=
1
,
STREAM_SCAN_FROM_RES
,
STREAM_SCAN_FROM_UPDATERES
,
STREAM_SCAN_FROM_DELETE
RES
,
STREAM_SCAN_FROM_DELETE
_DATA
,
STREAM_SCAN_FROM_DATAREADER_RETRIEVE
,
STREAM_SCAN_FROM_DATAREADER_RANGE
,
}
EStreamScanMode
;
...
...
@@ -794,6 +794,7 @@ typedef struct SStreamPartitionOperatorInfo {
void
*
parIte
;
SSDataBlock
*
pInputDataBlock
;
int32_t
tsColIndex
;
SSDataBlock
*
pDelRes
;
}
SStreamPartitionOperatorInfo
;
typedef
struct
STimeSliceOperatorInfo
{
...
...
@@ -1108,6 +1109,13 @@ void copyUpdateDataBlock(SSDataBlock* pDest, SSDataBlock* pSource, int32_t tsCol
bool
groupbyTbname
(
SNodeList
*
pGroupList
);
int32_t
generateGroupIdMap
(
STableListInfo
*
pTableListInfo
,
SReadHandle
*
pHandle
,
SNodeList
*
groupKey
);
void
*
destroySqlFunctionCtx
(
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
);
int32_t
buildDataBlockFromGroupRes
(
SExecTaskInfo
*
pTaskInfo
,
SSDataBlock
*
pBlock
,
SExprSupp
*
pSup
,
SGroupResInfo
*
pGroupResInfo
);
int32_t
setOutputBuf
(
STimeWindow
*
win
,
SResultRow
**
pResult
,
int64_t
tableGroupId
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
int32_t
*
rowEntryInfoOffset
,
SAggSupporter
*
pAggSup
,
SExecTaskInfo
*
pTaskInfo
);
int32_t
releaseOutputBuf
(
SExecTaskInfo
*
pTaskInfo
,
SWinKey
*
pKey
,
SResultRow
*
pResult
);
int32_t
saveOutput
(
SExecTaskInfo
*
pTaskInfo
,
SWinKey
*
pKey
,
SResultRow
*
pResult
,
int32_t
resSize
);
#ifdef __cplusplus
}
...
...
source/libs/executor/src/executil.c
浏览文件 @
4cdaafe6
...
...
@@ -475,7 +475,6 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, uint64_t suid, SArray
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
code
;
qError
(
"failed to create result, reason:%s"
,
tstrerror
(
code
));
terrno
=
code
;
goto
end
;
}
...
...
@@ -1012,6 +1011,100 @@ static SColumn* createColumn(int32_t blockId, int32_t slotId, int32_t colId, SDa
return
pCol
;
}
void
createExprFromTargetNode
(
SExprInfo
*
pExp
,
STargetNode
*
pTargetNode
)
{
pExp
->
pExpr
=
taosMemoryCalloc
(
1
,
sizeof
(
tExprNode
));
pExp
->
pExpr
->
_function
.
num
=
1
;
pExp
->
pExpr
->
_function
.
functionId
=
-
1
;
int32_t
type
=
nodeType
(
pTargetNode
->
pExpr
);
// it is a project query, or group by column
if
(
type
==
QUERY_NODE_COLUMN
)
{
pExp
->
pExpr
->
nodeType
=
QUERY_NODE_COLUMN
;
SColumnNode
*
pColNode
=
(
SColumnNode
*
)
pTargetNode
->
pExpr
;
pExp
->
base
.
pParam
=
taosMemoryCalloc
(
1
,
sizeof
(
SFunctParam
));
pExp
->
base
.
numOfParams
=
1
;
SDataType
*
pType
=
&
pColNode
->
node
.
resType
;
pExp
->
base
.
resSchema
=
createResSchema
(
pType
->
type
,
pType
->
bytes
,
pTargetNode
->
slotId
,
pType
->
scale
,
pType
->
precision
,
pColNode
->
colName
);
pExp
->
base
.
pParam
[
0
].
pCol
=
createColumn
(
pColNode
->
dataBlockId
,
pColNode
->
slotId
,
pColNode
->
colId
,
pType
,
pColNode
->
colType
);
pExp
->
base
.
pParam
[
0
].
type
=
FUNC_PARAM_TYPE_COLUMN
;
}
else
if
(
type
==
QUERY_NODE_VALUE
)
{
pExp
->
pExpr
->
nodeType
=
QUERY_NODE_VALUE
;
SValueNode
*
pValNode
=
(
SValueNode
*
)
pTargetNode
->
pExpr
;
pExp
->
base
.
pParam
=
taosMemoryCalloc
(
1
,
sizeof
(
SFunctParam
));
pExp
->
base
.
numOfParams
=
1
;
SDataType
*
pType
=
&
pValNode
->
node
.
resType
;
pExp
->
base
.
resSchema
=
createResSchema
(
pType
->
type
,
pType
->
bytes
,
pTargetNode
->
slotId
,
pType
->
scale
,
pType
->
precision
,
pValNode
->
node
.
aliasName
);
pExp
->
base
.
pParam
[
0
].
type
=
FUNC_PARAM_TYPE_VALUE
;
nodesValueNodeToVariant
(
pValNode
,
&
pExp
->
base
.
pParam
[
0
].
param
);
}
else
if
(
type
==
QUERY_NODE_FUNCTION
)
{
pExp
->
pExpr
->
nodeType
=
QUERY_NODE_FUNCTION
;
SFunctionNode
*
pFuncNode
=
(
SFunctionNode
*
)
pTargetNode
->
pExpr
;
SDataType
*
pType
=
&
pFuncNode
->
node
.
resType
;
pExp
->
base
.
resSchema
=
createResSchema
(
pType
->
type
,
pType
->
bytes
,
pTargetNode
->
slotId
,
pType
->
scale
,
pType
->
precision
,
pFuncNode
->
node
.
aliasName
);
pExp
->
pExpr
->
_function
.
functionId
=
pFuncNode
->
funcId
;
pExp
->
pExpr
->
_function
.
pFunctNode
=
pFuncNode
;
strncpy
(
pExp
->
pExpr
->
_function
.
functionName
,
pFuncNode
->
functionName
,
tListLen
(
pExp
->
pExpr
->
_function
.
functionName
));
#if 1
// todo refactor: add the parameter for tbname function
if
(
!
pFuncNode
->
pParameterList
&&
(
strcmp
(
pExp
->
pExpr
->
_function
.
functionName
,
"tbname"
)
==
0
))
{
pFuncNode
->
pParameterList
=
nodesMakeList
();
ASSERT
(
LIST_LENGTH
(
pFuncNode
->
pParameterList
)
==
0
);
SValueNode
*
res
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
if
(
NULL
==
res
)
{
// todo handle error
}
else
{
res
->
node
.
resType
=
(
SDataType
){.
bytes
=
sizeof
(
int64_t
),
.
type
=
TSDB_DATA_TYPE_BIGINT
};
nodesListAppend
(
pFuncNode
->
pParameterList
,
(
SNode
*
)
res
);
}
}
#endif
int32_t
numOfParam
=
LIST_LENGTH
(
pFuncNode
->
pParameterList
);
pExp
->
base
.
pParam
=
taosMemoryCalloc
(
numOfParam
,
sizeof
(
SFunctParam
));
pExp
->
base
.
numOfParams
=
numOfParam
;
for
(
int32_t
j
=
0
;
j
<
numOfParam
;
++
j
)
{
SNode
*
p1
=
nodesListGetNode
(
pFuncNode
->
pParameterList
,
j
);
if
(
p1
->
type
==
QUERY_NODE_COLUMN
)
{
SColumnNode
*
pcn
=
(
SColumnNode
*
)
p1
;
pExp
->
base
.
pParam
[
j
].
type
=
FUNC_PARAM_TYPE_COLUMN
;
pExp
->
base
.
pParam
[
j
].
pCol
=
createColumn
(
pcn
->
dataBlockId
,
pcn
->
slotId
,
pcn
->
colId
,
&
pcn
->
node
.
resType
,
pcn
->
colType
);
}
else
if
(
p1
->
type
==
QUERY_NODE_VALUE
)
{
SValueNode
*
pvn
=
(
SValueNode
*
)
p1
;
pExp
->
base
.
pParam
[
j
].
type
=
FUNC_PARAM_TYPE_VALUE
;
nodesValueNodeToVariant
(
pvn
,
&
pExp
->
base
.
pParam
[
j
].
param
);
}
}
}
else
if
(
type
==
QUERY_NODE_OPERATOR
)
{
pExp
->
pExpr
->
nodeType
=
QUERY_NODE_OPERATOR
;
SOperatorNode
*
pNode
=
(
SOperatorNode
*
)
pTargetNode
->
pExpr
;
pExp
->
base
.
pParam
=
taosMemoryCalloc
(
1
,
sizeof
(
SFunctParam
));
pExp
->
base
.
numOfParams
=
1
;
SDataType
*
pType
=
&
pNode
->
node
.
resType
;
pExp
->
base
.
resSchema
=
createResSchema
(
pType
->
type
,
pType
->
bytes
,
pTargetNode
->
slotId
,
pType
->
scale
,
pType
->
precision
,
pNode
->
node
.
aliasName
);
pExp
->
pExpr
->
_optrRoot
.
pRootNode
=
pTargetNode
->
pExpr
;
}
else
{
ASSERT
(
0
);
}
}
SExprInfo
*
createExprInfo
(
SNodeList
*
pNodeList
,
SNodeList
*
pGroupKeys
,
int32_t
*
numOfExprs
)
{
int32_t
numOfFuncs
=
LIST_LENGTH
(
pNodeList
);
int32_t
numOfGroupKeys
=
0
;
...
...
@@ -1035,98 +1128,7 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t*
}
SExprInfo
*
pExp
=
&
pExprs
[
i
];
pExp
->
pExpr
=
taosMemoryCalloc
(
1
,
sizeof
(
tExprNode
));
pExp
->
pExpr
->
_function
.
num
=
1
;
pExp
->
pExpr
->
_function
.
functionId
=
-
1
;
int32_t
type
=
nodeType
(
pTargetNode
->
pExpr
);
// it is a project query, or group by column
if
(
type
==
QUERY_NODE_COLUMN
)
{
pExp
->
pExpr
->
nodeType
=
QUERY_NODE_COLUMN
;
SColumnNode
*
pColNode
=
(
SColumnNode
*
)
pTargetNode
->
pExpr
;
pExp
->
base
.
pParam
=
taosMemoryCalloc
(
1
,
sizeof
(
SFunctParam
));
pExp
->
base
.
numOfParams
=
1
;
SDataType
*
pType
=
&
pColNode
->
node
.
resType
;
pExp
->
base
.
resSchema
=
createResSchema
(
pType
->
type
,
pType
->
bytes
,
pTargetNode
->
slotId
,
pType
->
scale
,
pType
->
precision
,
pColNode
->
colName
);
pExp
->
base
.
pParam
[
0
].
pCol
=
createColumn
(
pColNode
->
dataBlockId
,
pColNode
->
slotId
,
pColNode
->
colId
,
pType
,
pColNode
->
colType
);
pExp
->
base
.
pParam
[
0
].
type
=
FUNC_PARAM_TYPE_COLUMN
;
}
else
if
(
type
==
QUERY_NODE_VALUE
)
{
pExp
->
pExpr
->
nodeType
=
QUERY_NODE_VALUE
;
SValueNode
*
pValNode
=
(
SValueNode
*
)
pTargetNode
->
pExpr
;
pExp
->
base
.
pParam
=
taosMemoryCalloc
(
1
,
sizeof
(
SFunctParam
));
pExp
->
base
.
numOfParams
=
1
;
SDataType
*
pType
=
&
pValNode
->
node
.
resType
;
pExp
->
base
.
resSchema
=
createResSchema
(
pType
->
type
,
pType
->
bytes
,
pTargetNode
->
slotId
,
pType
->
scale
,
pType
->
precision
,
pValNode
->
node
.
aliasName
);
pExp
->
base
.
pParam
[
0
].
type
=
FUNC_PARAM_TYPE_VALUE
;
nodesValueNodeToVariant
(
pValNode
,
&
pExp
->
base
.
pParam
[
0
].
param
);
}
else
if
(
type
==
QUERY_NODE_FUNCTION
)
{
pExp
->
pExpr
->
nodeType
=
QUERY_NODE_FUNCTION
;
SFunctionNode
*
pFuncNode
=
(
SFunctionNode
*
)
pTargetNode
->
pExpr
;
SDataType
*
pType
=
&
pFuncNode
->
node
.
resType
;
pExp
->
base
.
resSchema
=
createResSchema
(
pType
->
type
,
pType
->
bytes
,
pTargetNode
->
slotId
,
pType
->
scale
,
pType
->
precision
,
pFuncNode
->
node
.
aliasName
);
pExp
->
pExpr
->
_function
.
functionId
=
pFuncNode
->
funcId
;
pExp
->
pExpr
->
_function
.
pFunctNode
=
pFuncNode
;
strncpy
(
pExp
->
pExpr
->
_function
.
functionName
,
pFuncNode
->
functionName
,
tListLen
(
pExp
->
pExpr
->
_function
.
functionName
));
#if 1
// todo refactor: add the parameter for tbname function
if
(
!
pFuncNode
->
pParameterList
&&
(
strcmp
(
pExp
->
pExpr
->
_function
.
functionName
,
"tbname"
)
==
0
))
{
pFuncNode
->
pParameterList
=
nodesMakeList
();
ASSERT
(
LIST_LENGTH
(
pFuncNode
->
pParameterList
)
==
0
);
SValueNode
*
res
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
if
(
NULL
==
res
)
{
// todo handle error
}
else
{
res
->
node
.
resType
=
(
SDataType
){.
bytes
=
sizeof
(
int64_t
),
.
type
=
TSDB_DATA_TYPE_BIGINT
};
nodesListAppend
(
pFuncNode
->
pParameterList
,
(
SNode
*
)
res
);
}
}
#endif
int32_t
numOfParam
=
LIST_LENGTH
(
pFuncNode
->
pParameterList
);
pExp
->
base
.
pParam
=
taosMemoryCalloc
(
numOfParam
,
sizeof
(
SFunctParam
));
pExp
->
base
.
numOfParams
=
numOfParam
;
for
(
int32_t
j
=
0
;
j
<
numOfParam
;
++
j
)
{
SNode
*
p1
=
nodesListGetNode
(
pFuncNode
->
pParameterList
,
j
);
if
(
p1
->
type
==
QUERY_NODE_COLUMN
)
{
SColumnNode
*
pcn
=
(
SColumnNode
*
)
p1
;
pExp
->
base
.
pParam
[
j
].
type
=
FUNC_PARAM_TYPE_COLUMN
;
pExp
->
base
.
pParam
[
j
].
pCol
=
createColumn
(
pcn
->
dataBlockId
,
pcn
->
slotId
,
pcn
->
colId
,
&
pcn
->
node
.
resType
,
pcn
->
colType
);
}
else
if
(
p1
->
type
==
QUERY_NODE_VALUE
)
{
SValueNode
*
pvn
=
(
SValueNode
*
)
p1
;
pExp
->
base
.
pParam
[
j
].
type
=
FUNC_PARAM_TYPE_VALUE
;
nodesValueNodeToVariant
(
pvn
,
&
pExp
->
base
.
pParam
[
j
].
param
);
}
}
}
else
if
(
type
==
QUERY_NODE_OPERATOR
)
{
pExp
->
pExpr
->
nodeType
=
QUERY_NODE_OPERATOR
;
SOperatorNode
*
pNode
=
(
SOperatorNode
*
)
pTargetNode
->
pExpr
;
pExp
->
base
.
pParam
=
taosMemoryCalloc
(
1
,
sizeof
(
SFunctParam
));
pExp
->
base
.
numOfParams
=
1
;
SDataType
*
pType
=
&
pNode
->
node
.
resType
;
pExp
->
base
.
resSchema
=
createResSchema
(
pType
->
type
,
pType
->
bytes
,
pTargetNode
->
slotId
,
pType
->
scale
,
pType
->
precision
,
pNode
->
node
.
aliasName
);
pExp
->
pExpr
->
_optrRoot
.
pRootNode
=
pTargetNode
->
pExpr
;
}
else
{
ASSERT
(
0
);
}
createExprFromTargetNode
(
pExp
,
pTargetNode
);
}
return
pExprs
;
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
4cdaafe6
...
...
@@ -3439,6 +3439,44 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t
}
}
static
bool
isWstartColumnExist
(
SFillOperatorInfo
*
pInfo
)
{
if
(
pInfo
->
numOfNotFillExpr
==
0
)
{
return
false
;
}
for
(
int32_t
i
=
0
;
i
<
pInfo
->
numOfNotFillExpr
;
++
i
)
{
SExprInfo
*
exprInfo
=
pInfo
->
pNotFillExprInfo
+
i
;
if
(
exprInfo
->
pExpr
->
nodeType
==
QUERY_NODE_COLUMN
&&
exprInfo
->
base
.
numOfParams
==
1
&&
exprInfo
->
base
.
pParam
[
0
].
pCol
->
colType
==
COLUMN_TYPE_WINDOW_START
)
{
return
true
;
}
}
return
false
;
}
static
int32_t
createWStartTsAsNotFillExpr
(
SFillOperatorInfo
*
pInfo
,
SFillPhysiNode
*
pPhyFillNode
)
{
bool
wstartExist
=
isWstartColumnExist
(
pInfo
);
if
(
wstartExist
==
false
)
{
if
(
pPhyFillNode
->
pWStartTs
->
type
!=
QUERY_NODE_TARGET
)
{
qError
(
"pWStartTs of fill physical node is not a target node"
);
return
TSDB_CODE_QRY_SYS_ERROR
;
}
SExprInfo
*
notFillExprs
=
taosMemoryRealloc
(
pInfo
->
pNotFillExprInfo
,
(
pInfo
->
numOfNotFillExpr
+
1
)
*
sizeof
(
SExprInfo
));
if
(
notFillExprs
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
createExprFromTargetNode
(
notFillExprs
+
pInfo
->
numOfNotFillExpr
,
(
STargetNode
*
)
pPhyFillNode
->
pWStartTs
);
++
pInfo
->
numOfNotFillExpr
;
pInfo
->
pNotFillExprInfo
=
notFillExprs
;
return
TSDB_CODE_SUCCESS
;
}
return
TSDB_CODE_SUCCESS
;
}
SOperatorInfo
*
createFillOperatorInfo
(
SOperatorInfo
*
downstream
,
SFillPhysiNode
*
pPhyFillNode
,
SExecTaskInfo
*
pTaskInfo
)
{
SFillOperatorInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SFillOperatorInfo
));
...
...
@@ -3450,7 +3488,10 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pPhyFillNode
->
node
.
pOutputDataBlockDesc
);
SExprInfo
*
pExprInfo
=
createExprInfo
(
pPhyFillNode
->
pFillExprs
,
NULL
,
&
pInfo
->
numOfExpr
);
pInfo
->
pNotFillExprInfo
=
createExprInfo
(
pPhyFillNode
->
pNotFillExprs
,
NULL
,
&
pInfo
->
numOfNotFillExpr
);
int32_t
code
=
createWStartTsAsNotFillExpr
(
pInfo
,
pPhyFillNode
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
SInterval
*
pInterval
=
QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL
==
downstream
->
operatorType
?
&
((
SMergeAlignedIntervalAggOperatorInfo
*
)
downstream
->
info
)
->
intervalAggOperatorInfo
->
interval
...
...
@@ -3471,7 +3512,7 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
SArray
*
pColMatchColInfo
=
extractColMatchInfo
(
pPhyFillNode
->
pFillExprs
,
pPhyFillNode
->
node
.
pOutputDataBlockDesc
,
&
numOfOutputCols
,
COL_MATCH_FROM_SLOT_ID
);
int32_t
code
=
initFillInfo
(
pInfo
,
pExprInfo
,
pInfo
->
numOfExpr
,
pInfo
->
pNotFillExprInfo
,
pInfo
->
numOfNotFillExpr
,
code
=
initFillInfo
(
pInfo
,
pExprInfo
,
pInfo
->
numOfExpr
,
pInfo
->
pNotFillExprInfo
,
pInfo
->
numOfNotFillExpr
,
(
SNodeListNode
*
)
pPhyFillNode
->
pValues
,
pPhyFillNode
->
timeRange
,
pResultInfo
->
capacity
,
pTaskInfo
->
id
.
str
,
pInterval
,
type
,
order
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -3938,7 +3979,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
pOptr
=
createIntervalOperatorInfo
(
ops
[
0
],
pExprInfo
,
num
,
pResBlock
,
&
interval
,
tsSlotId
,
&
as
,
pIntervalPhyNode
,
pTaskInfo
,
isStream
);
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL
==
type
)
{
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL
==
type
)
{
pOptr
=
createStreamIntervalOperatorInfo
(
ops
[
0
],
pPhyNode
,
pTaskInfo
);
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL
==
type
)
{
SMergeAlignedIntervalPhysiNode
*
pIntervalPhyNode
=
(
SMergeAlignedIntervalPhysiNode
*
)
pPhyNode
;
...
...
@@ -4410,3 +4451,108 @@ int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, const char* pKey, SqlF
return
code
;
}
int32_t
setOutputBuf
(
STimeWindow
*
win
,
SResultRow
**
pResult
,
int64_t
tableGroupId
,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
,
int32_t
*
rowEntryInfoOffset
,
SAggSupporter
*
pAggSup
,
SExecTaskInfo
*
pTaskInfo
)
{
SWinKey
key
=
{
.
ts
=
win
->
skey
,
.
groupId
=
tableGroupId
,
};
char
*
value
=
NULL
;
int32_t
size
=
pAggSup
->
resultRowSize
;
if
(
streamStateAddIfNotExist
(
pTaskInfo
->
streamInfo
.
pState
,
&
key
,
(
void
**
)
&
value
,
&
size
)
<
0
)
{
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
*
pResult
=
(
SResultRow
*
)
value
;
ASSERT
(
*
pResult
);
// set time window for current result
(
*
pResult
)
->
win
=
(
*
win
);
setResultRowInitCtx
(
*
pResult
,
pCtx
,
numOfOutput
,
rowEntryInfoOffset
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
releaseOutputBuf
(
SExecTaskInfo
*
pTaskInfo
,
SWinKey
*
pKey
,
SResultRow
*
pResult
)
{
streamStateReleaseBuf
(
pTaskInfo
->
streamInfo
.
pState
,
pKey
,
pResult
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
saveOutput
(
SExecTaskInfo
*
pTaskInfo
,
SWinKey
*
pKey
,
SResultRow
*
pResult
,
int32_t
resSize
)
{
streamStatePut
(
pTaskInfo
->
streamInfo
.
pState
,
pKey
,
pResult
,
resSize
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
buildDataBlockFromGroupRes
(
SExecTaskInfo
*
pTaskInfo
,
SSDataBlock
*
pBlock
,
SExprSupp
*
pSup
,
SGroupResInfo
*
pGroupResInfo
)
{
SExprInfo
*
pExprInfo
=
pSup
->
pExprInfo
;
int32_t
numOfExprs
=
pSup
->
numOfExprs
;
int32_t
*
rowEntryOffset
=
pSup
->
rowEntryInfoOffset
;
SqlFunctionCtx
*
pCtx
=
pSup
->
pCtx
;
int32_t
numOfRows
=
getNumOfTotalRes
(
pGroupResInfo
);
for
(
int32_t
i
=
pGroupResInfo
->
index
;
i
<
numOfRows
;
i
+=
1
)
{
SResKeyPos
*
pPos
=
taosArrayGetP
(
pGroupResInfo
->
pRows
,
i
);
int32_t
size
=
0
;
void
*
pVal
=
NULL
;
SWinKey
key
=
{
.
ts
=
*
(
TSKEY
*
)
pPos
->
key
,
.
groupId
=
pPos
->
groupId
,
};
int32_t
code
=
streamStateGet
(
pTaskInfo
->
streamInfo
.
pState
,
&
key
,
&
pVal
,
&
size
);
ASSERT
(
code
==
0
);
SResultRow
*
pRow
=
(
SResultRow
*
)
pVal
;
doUpdateNumOfRows
(
pCtx
,
pRow
,
numOfExprs
,
rowEntryOffset
);
// no results, continue to check the next one
if
(
pRow
->
numOfRows
==
0
)
{
pGroupResInfo
->
index
+=
1
;
releaseOutputBuf
(
pTaskInfo
,
&
key
,
pRow
);
continue
;
}
if
(
pBlock
->
info
.
groupId
==
0
)
{
pBlock
->
info
.
groupId
=
pPos
->
groupId
;
}
else
{
// current value belongs to different group, it can't be packed into one datablock
if
(
pBlock
->
info
.
groupId
!=
pPos
->
groupId
)
{
releaseOutputBuf
(
pTaskInfo
,
&
key
,
pRow
);
break
;
}
}
if
(
pBlock
->
info
.
rows
+
pRow
->
numOfRows
>
pBlock
->
info
.
capacity
)
{
ASSERT
(
pBlock
->
info
.
rows
>
0
);
releaseOutputBuf
(
pTaskInfo
,
&
key
,
pRow
);
break
;
}
pGroupResInfo
->
index
+=
1
;
for
(
int32_t
j
=
0
;
j
<
numOfExprs
;
++
j
)
{
int32_t
slotId
=
pExprInfo
[
j
].
base
.
resSchema
.
slotId
;
pCtx
[
j
].
resultInfo
=
getResultEntryInfo
(
pRow
,
j
,
rowEntryOffset
);
if
(
pCtx
[
j
].
fpSet
.
finalize
)
{
int32_t
code
=
pCtx
[
j
].
fpSet
.
finalize
(
&
pCtx
[
j
],
pBlock
);
if
(
TAOS_FAILED
(
code
))
{
qError
(
"%s build result data block error, code %s"
,
GET_TASKID
(
pTaskInfo
),
tstrerror
(
code
));
T_LONG_JMP
(
pTaskInfo
->
env
,
code
);
}
}
else
if
(
strcmp
(
pCtx
[
j
].
pExpr
->
pExpr
->
_function
.
functionName
,
"_select_value"
)
==
0
)
{
// do nothing, todo refactor
}
else
{
// expand the result into multiple rows. E.g., _wstart, top(k, 20)
// the _wstart needs to copy to 20 following rows, since the results of top-k expands to 20 different rows.
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
char
*
in
=
GET_ROWCELL_INTERBUF
(
pCtx
[
j
].
resultInfo
);
for
(
int32_t
k
=
0
;
k
<
pRow
->
numOfRows
;
++
k
)
{
colDataAppend
(
pColInfoData
,
pBlock
->
info
.
rows
+
k
,
in
,
pCtx
[
j
].
resultInfo
->
isNullRes
);
}
}
}
releaseOutputBuf
(
pTaskInfo
,
&
key
,
pRow
);
pBlock
->
info
.
rows
+=
pRow
->
numOfRows
;
}
blockDataUpdateTsWindow
(
pBlock
,
0
);
return
TSDB_CODE_SUCCESS
;
}
source/libs/executor/src/groupoperator.c
浏览文件 @
4cdaafe6
此差异已折叠。
点击以展开。
source/libs/executor/src/scanoperator.c
浏览文件 @
4cdaafe6
...
...
@@ -1057,24 +1057,24 @@ static bool prepareRangeScan(SStreamScanInfo* pInfo, SSDataBlock* pBlock, int32_
return
true
;
}
static
STimeWindow
getSlidingWindow
(
TSKEY
*
tsCol
,
SInterval
*
pInterval
,
SDataBlockInfo
*
pDataBlockInfo
,
int32_t
*
pRowIndex
,
bool
hasGroup
)
{
static
STimeWindow
getSlidingWindow
(
TSKEY
*
startTsCol
,
TSKEY
*
endTsCol
,
SInterval
*
pInterval
,
SDataBlockInfo
*
pDataBlockInfo
,
int32_t
*
pRowIndex
,
bool
hasGroup
)
{
SResultRowInfo
dumyInfo
;
dumyInfo
.
cur
.
pageId
=
-
1
;
STimeWindow
win
=
getActiveTimeWindow
(
NULL
,
&
dumyInfo
,
t
sCol
[
*
pRowIndex
],
pInterval
,
TSDB_ORDER_ASC
);
STimeWindow
win
=
getActiveTimeWindow
(
NULL
,
&
dumyInfo
,
startT
sCol
[
*
pRowIndex
],
pInterval
,
TSDB_ORDER_ASC
);
STimeWindow
endWin
=
win
;
STimeWindow
preWin
=
win
;
while
(
1
)
{
if
(
hasGroup
)
{
(
*
pRowIndex
)
+=
1
;
}
else
{
(
*
pRowIndex
)
+=
getNumOfRowsInTimeWindow
(
pDataBlockInfo
,
tsCol
,
*
pRowIndex
,
endWin
.
ekey
,
binarySearchForKey
,
NULL
,
TSDB_ORDER_ASC
);
(
*
pRowIndex
)
+=
getNumOfRowsInTimeWindow
(
pDataBlockInfo
,
startTsCol
,
*
pRowIndex
,
endWin
.
ekey
,
binarySearchForKey
,
NULL
,
TSDB_ORDER_ASC
);
}
do
{
preWin
=
endWin
;
getNextTimeWindow
(
pInterval
,
&
endWin
,
TSDB_ORDER_ASC
);
}
while
(
t
sCol
[(
*
pRowIndex
)
-
1
]
>=
endWin
.
skey
);
}
while
(
endT
sCol
[(
*
pRowIndex
)
-
1
]
>=
endWin
.
skey
);
endWin
=
preWin
;
if
(
win
.
ekey
==
endWin
.
ekey
||
(
*
pRowIndex
)
==
pDataBlockInfo
->
rows
)
{
win
.
ekey
=
endWin
.
ekey
;
...
...
@@ -1102,6 +1102,11 @@ static SSDataBlock* doRangeScan(SStreamScanInfo* pInfo, SSDataBlock* pSDB, int32
return
NULL
;
}
doFilter
(
pInfo
->
pCondition
,
pResult
,
NULL
);
if
(
pResult
->
info
.
rows
==
0
)
{
continue
;
}
if
(
pInfo
->
partitionSup
.
needCalc
)
{
SSDataBlock
*
tmpBlock
=
createOneDataBlock
(
pResult
,
true
);
blockDataCleanup
(
pResult
);
...
...
@@ -1188,13 +1193,15 @@ static int32_t generateIntervalScanRange(SStreamScanInfo* pInfo, SSDataBlock* pS
return
code
;
}
SColumnInfoData
*
pSrcTsCol
=
(
SColumnInfoData
*
)
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
START_TS_COLUMN_INDEX
);
SColumnInfoData
*
pSrcStartTsCol
=
(
SColumnInfoData
*
)
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
START_TS_COLUMN_INDEX
);
SColumnInfoData
*
pSrcEndTsCol
=
(
SColumnInfoData
*
)
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
END_TS_COLUMN_INDEX
);
SColumnInfoData
*
pSrcUidCol
=
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
UID_COLUMN_INDEX
);
uint64_t
*
srcUidData
=
(
uint64_t
*
)
pSrcUidCol
->
pData
;
SColumnInfoData
*
pSrcGpCol
=
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
GROUPID_COLUMN_INDEX
);
uint64_t
*
srcGp
=
(
uint64_t
*
)
pSrcGpCol
->
pData
;
ASSERT
(
pSrcTsCol
->
info
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
);
TSKEY
*
tsCol
=
(
TSKEY
*
)
pSrcTsCol
->
pData
;
ASSERT
(
pSrcStartTsCol
->
info
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
);
TSKEY
*
srcStartTsCol
=
(
TSKEY
*
)
pSrcStartTsCol
->
pData
;
TSKEY
*
srcEndTsCol
=
(
TSKEY
*
)
pSrcEndTsCol
->
pData
;
SColumnInfoData
*
pStartTsCol
=
taosArrayGet
(
pDestBlock
->
pDataBlock
,
START_TS_COLUMN_INDEX
);
SColumnInfoData
*
pEndTsCol
=
taosArrayGet
(
pDestBlock
->
pDataBlock
,
END_TS_COLUMN_INDEX
);
SColumnInfoData
*
pDeUidCol
=
taosArrayGet
(
pDestBlock
->
pDataBlock
,
UID_COLUMN_INDEX
);
...
...
@@ -1204,12 +1211,13 @@ static int32_t generateIntervalScanRange(SStreamScanInfo* pInfo, SSDataBlock* pS
int64_t
version
=
pSrcBlock
->
info
.
version
-
1
;
for
(
int32_t
i
=
0
;
i
<
rows
;)
{
uint64_t
srcUid
=
srcUidData
[
i
];
uint64_t
groupId
=
getGroupIdByData
(
pInfo
,
srcUid
,
t
sCol
[
i
],
version
);
uint64_t
groupId
=
getGroupIdByData
(
pInfo
,
srcUid
,
srcStartT
sCol
[
i
],
version
);
uint64_t
srcGpId
=
srcGp
[
i
];
TSKEY
calStartTs
=
t
sCol
[
i
];
TSKEY
calStartTs
=
srcStartT
sCol
[
i
];
colDataAppend
(
pCalStartTsCol
,
pDestBlock
->
info
.
rows
,
(
const
char
*
)(
&
calStartTs
),
false
);
STimeWindow
win
=
getSlidingWindow
(
tsCol
,
&
pInfo
->
interval
,
&
pSrcBlock
->
info
,
&
i
,
pInfo
->
partitionSup
.
needCalc
);
TSKEY
calEndTs
=
tsCol
[
i
-
1
];
STimeWindow
win
=
getSlidingWindow
(
srcStartTsCol
,
srcEndTsCol
,
&
pInfo
->
interval
,
&
pSrcBlock
->
info
,
&
i
,
pInfo
->
partitionSup
.
needCalc
);
TSKEY
calEndTs
=
srcStartTsCol
[
i
-
1
];
colDataAppend
(
pCalEndTsCol
,
pDestBlock
->
info
.
rows
,
(
const
char
*
)(
&
calEndTs
),
false
);
colDataAppend
(
pDeUidCol
,
pDestBlock
->
info
.
rows
,
(
const
char
*
)(
&
srcUid
),
false
);
colDataAppend
(
pStartTsCol
,
pDestBlock
->
info
.
rows
,
(
const
char
*
)(
&
win
.
skey
),
false
);
...
...
@@ -1229,11 +1237,49 @@ static int32_t generateIntervalScanRange(SStreamScanInfo* pInfo, SSDataBlock* pS
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
generateDeleteResultBlock
(
SStreamScanInfo
*
pInfo
,
SSDataBlock
*
pSrcBlock
,
SSDataBlock
*
pDestBlock
)
{
if
(
pSrcBlock
->
info
.
rows
==
0
)
{
return
TSDB_CODE_SUCCESS
;
}
blockDataCleanup
(
pDestBlock
);
int32_t
code
=
blockDataEnsureCapacity
(
pDestBlock
,
pSrcBlock
->
info
.
rows
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
ASSERT
(
taosArrayGetSize
(
pSrcBlock
->
pDataBlock
)
>=
3
);
SColumnInfoData
*
pStartTsCol
=
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
START_TS_COLUMN_INDEX
);
TSKEY
*
startData
=
(
TSKEY
*
)
pStartTsCol
->
pData
;
SColumnInfoData
*
pEndTsCol
=
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
END_TS_COLUMN_INDEX
);
TSKEY
*
endData
=
(
TSKEY
*
)
pEndTsCol
->
pData
;
SColumnInfoData
*
pUidCol
=
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
UID_COLUMN_INDEX
);
uint64_t
*
uidCol
=
(
uint64_t
*
)
pUidCol
->
pData
;
SColumnInfoData
*
pDestStartCol
=
taosArrayGet
(
pDestBlock
->
pDataBlock
,
START_TS_COLUMN_INDEX
);
SColumnInfoData
*
pDestEndCol
=
taosArrayGet
(
pDestBlock
->
pDataBlock
,
END_TS_COLUMN_INDEX
);
SColumnInfoData
*
pDestUidCol
=
taosArrayGet
(
pDestBlock
->
pDataBlock
,
UID_COLUMN_INDEX
);
SColumnInfoData
*
pDestGpCol
=
taosArrayGet
(
pDestBlock
->
pDataBlock
,
GROUPID_COLUMN_INDEX
);
SColumnInfoData
*
pDestCalStartTsCol
=
taosArrayGet
(
pDestBlock
->
pDataBlock
,
CALCULATE_START_TS_COLUMN_INDEX
);
SColumnInfoData
*
pDestCalEndTsCol
=
taosArrayGet
(
pDestBlock
->
pDataBlock
,
CALCULATE_END_TS_COLUMN_INDEX
);
int32_t
dummy
=
0
;
int64_t
version
=
pSrcBlock
->
info
.
version
-
1
;
for
(
int32_t
i
=
0
;
i
<
pSrcBlock
->
info
.
rows
;
i
++
)
{
uint64_t
groupId
=
getGroupIdByData
(
pInfo
,
uidCol
[
i
],
startData
[
i
],
version
);
colDataAppend
(
pDestStartCol
,
i
,
(
const
char
*
)(
startData
+
i
),
false
);
colDataAppend
(
pDestEndCol
,
i
,
(
const
char
*
)(
endData
+
i
),
false
);
colDataAppendNULL
(
pDestUidCol
,
i
);
colDataAppend
(
pDestGpCol
,
i
,
(
const
char
*
)
&
groupId
,
false
);
colDataAppendNULL
(
pDestCalStartTsCol
,
i
);
colDataAppendNULL
(
pDestCalEndTsCol
,
i
);
pDestBlock
->
info
.
rows
++
;
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
generateScanRange
(
SStreamScanInfo
*
pInfo
,
SSDataBlock
*
pSrcBlock
,
SSDataBlock
*
pDestBlock
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
isIntervalWindow
(
pInfo
))
{
code
=
generateIntervalScanRange
(
pInfo
,
pSrcBlock
,
pDestBlock
);
}
else
{
}
else
if
(
isSessionWindow
(
pInfo
)
||
isStateWindow
(
pInfo
))
{
code
=
generateSessionScanRange
(
pInfo
,
pSrcBlock
,
pDestBlock
);
}
pDestBlock
->
info
.
type
=
STREAM_CLEAR
;
...
...
@@ -1510,14 +1556,23 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
updateInfoAddCloseWindowSBF
(
pInfo
->
pUpdateInfo
);
}
break
;
case
STREAM_DELETE_DATA
:
{
pInfo
->
blockType
=
STREAM_INPUT__DATA_SUBMIT
;
pInfo
->
updateResIndex
=
0
;
generateScanRange
(
pInfo
,
pBlock
,
pInfo
->
pUpdateRes
);
prepareRangeScan
(
pInfo
,
pInfo
->
pUpdateRes
,
&
pInfo
->
updateResIndex
);
copyDataBlock
(
pInfo
->
pDeleteDataRes
,
pInfo
->
pUpdateRes
);
pInfo
->
pDeleteDataRes
->
info
.
type
=
STREAM_DELETE_DATA
;
pInfo
->
scanMode
=
STREAM_SCAN_FROM_DATAREADER_RANGE
;
return
pInfo
->
pDeleteDataRes
;
printDataBlock
(
pBlock
,
"stream scan delete recv"
);
if
(
!
isIntervalWindow
(
pInfo
)
&&
!
isSessionWindow
(
pInfo
)
&&
!
isStateWindow
(
pInfo
))
{
generateDeleteResultBlock
(
pInfo
,
pBlock
,
pInfo
->
pDeleteDataRes
);
pInfo
->
pDeleteDataRes
->
info
.
type
=
STREAM_DELETE_RESULT
;
printDataBlock
(
pBlock
,
"stream scan delete result"
);
return
pInfo
->
pDeleteDataRes
;
}
else
{
pInfo
->
blockType
=
STREAM_INPUT__DATA_SUBMIT
;
pInfo
->
updateResIndex
=
0
;
generateScanRange
(
pInfo
,
pBlock
,
pInfo
->
pUpdateRes
);
prepareRangeScan
(
pInfo
,
pInfo
->
pUpdateRes
,
&
pInfo
->
updateResIndex
);
copyDataBlock
(
pInfo
->
pDeleteDataRes
,
pInfo
->
pUpdateRes
);
pInfo
->
pDeleteDataRes
->
info
.
type
=
STREAM_DELETE_DATA
;
pInfo
->
scanMode
=
STREAM_SCAN_FROM_DATAREADER_RANGE
;
printDataBlock
(
pBlock
,
"stream scan delete data"
);
return
pInfo
->
pDeleteDataRes
;
}
}
break
;
default:
break
;
...
...
@@ -1532,7 +1587,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
pInfo
->
scanMode
=
STREAM_SCAN_FROM_READERHANDLE
;
return
pInfo
->
pRes
;
}
break
;
case
STREAM_SCAN_FROM_DELETE
RES
:
{
case
STREAM_SCAN_FROM_DELETE
_DATA
:
{
generateScanRange
(
pInfo
,
pInfo
->
pUpdateDataRes
,
pInfo
->
pUpdateRes
);
prepareRangeScan
(
pInfo
,
pInfo
->
pUpdateRes
,
&
pInfo
->
updateResIndex
);
pInfo
->
scanMode
=
STREAM_SCAN_FROM_DATAREADER_RANGE
;
...
...
@@ -1646,7 +1701,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
pInfo
->
scanMode
=
STREAM_SCAN_FROM_RES
;
return
pInfo
->
pUpdateDataRes
;
}
else
if
(
pInfo
->
pUpdateDataRes
->
info
.
type
==
STREAM_DELETE_DATA
)
{
pInfo
->
scanMode
=
STREAM_SCAN_FROM_DELETE
RES
;
pInfo
->
scanMode
=
STREAM_SCAN_FROM_DELETE
_DATA
;
}
}
}
...
...
source/libs/executor/src/timewindowoperator.c
浏览文件 @
4cdaafe6
此差异已折叠。
点击以展开。
source/libs/function/src/builtinsimpl.c
浏览文件 @
4cdaafe6
...
...
@@ -2795,6 +2795,8 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
// All null data column, return directly.
if
(
pInput
->
colDataAggIsSet
&&
(
pInput
->
pColumnDataAgg
[
0
]
->
numOfNull
==
pInput
->
totalRows
))
{
ASSERT
(
pInputCol
->
hasNull
==
true
);
// save selectivity value for column consisted of all null values
firstlastSaveTupleData
(
pCtx
->
pSrcBlock
,
pInput
->
startRowIndex
,
pCtx
,
pInfo
);
return
0
;
}
...
...
@@ -2871,7 +2873,10 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
}
}
#endif
if
(
numOfElems
==
0
)
{
// save selectivity value for column consisted of all null values
firstlastSaveTupleData
(
pCtx
->
pSrcBlock
,
pInput
->
startRowIndex
,
pCtx
,
pInfo
);
}
SET_VAL
(
pResInfo
,
numOfElems
,
1
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -2892,6 +2897,8 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
// All null data column, return directly.
if
(
pInput
->
colDataAggIsSet
&&
(
pInput
->
pColumnDataAgg
[
0
]
->
numOfNull
==
pInput
->
totalRows
))
{
ASSERT
(
pInputCol
->
hasNull
==
true
);
// save selectivity value for column consisted of all null values
firstlastSaveTupleData
(
pCtx
->
pSrcBlock
,
pInput
->
startRowIndex
,
pCtx
,
pInfo
);
return
0
;
}
...
...
@@ -2952,7 +2959,10 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
}
}
#endif
if
(
numOfElems
==
0
)
{
// save selectivity value for column consisted of all null values
firstlastSaveTupleData
(
pCtx
->
pSrcBlock
,
pInput
->
startRowIndex
,
pCtx
,
pInfo
);
}
SET_VAL
(
pResInfo
,
numOfElems
,
1
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -4701,7 +4711,7 @@ int32_t stateCountFunction(SqlFunctionCtx* pCtx) {
colDataAppendNULL
(
pOutput
,
i
);
// handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
appendSelectivityValue
(
pCtx
,
i
,
i
);
appendSelectivityValue
(
pCtx
,
i
,
pCtx
->
offset
+
numOfElems
-
1
);
}
continue
;
}
...
...
@@ -4714,11 +4724,11 @@ int32_t stateCountFunction(SqlFunctionCtx* pCtx) {
}
else
{
pInfo
->
count
=
0
;
}
colDataAppend
(
pOutput
,
i
,
(
char
*
)
&
output
,
false
);
colDataAppend
(
pOutput
,
pCtx
->
offset
+
numOfElems
-
1
,
(
char
*
)
&
output
,
false
);
// handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
appendSelectivityValue
(
pCtx
,
i
,
i
);
appendSelectivityValue
(
pCtx
,
i
,
pCtx
->
offset
+
numOfElems
-
1
);
}
}
...
...
source/libs/function/src/tudf.c
浏览文件 @
4cdaafe6
...
...
@@ -1183,7 +1183,9 @@ void onUdfcPipeClose(uv_handle_t *handle) {
QUEUE_REMOVE
(
&
task
->
procTaskQueue
);
uv_sem_post
(
&
task
->
taskSem
);
}
conn
->
session
->
udfUvPipe
=
NULL
;
if
(
conn
->
session
!=
NULL
)
{
conn
->
session
->
udfUvPipe
=
NULL
;
}
taosMemoryFree
(
conn
->
readBuf
.
buf
);
taosMemoryFree
(
conn
);
taosMemoryFree
((
uv_pipe_t
*
)
handle
);
...
...
@@ -1803,6 +1805,7 @@ int32_t doTeardownUdf(UdfcFuncHandle handle) {
if
(
session
->
udfUvPipe
==
NULL
)
{
fnError
(
"tear down udf. pipe to udfd does not exist. udf name: %s"
,
session
->
udfName
);
taosMemoryFree
(
session
);
return
TSDB_CODE_UDF_PIPE_NO_PIPE
;
}
...
...
@@ -1821,7 +1824,11 @@ int32_t doTeardownUdf(UdfcFuncHandle handle) {
udfcRunUdfUvTask
(
task
,
UV_TASK_DISCONNECT
);
fnInfo
(
"tear down udf. udf name: %s, udf func handle: %p"
,
session
->
udfName
,
handle
);
//TODO: synchronization refactor between libuv event loop and request thread
if
(
session
->
udfUvPipe
!=
NULL
&&
session
->
udfUvPipe
->
data
!=
NULL
)
{
SClientUvConn
*
conn
=
session
->
udfUvPipe
->
data
;
conn
->
session
=
NULL
;
}
taosMemoryFree
(
session
);
taosMemoryFree
(
task
);
...
...
source/libs/index/src/indexComm.c
浏览文件 @
4cdaafe6
...
...
@@ -81,28 +81,28 @@ __compar_fn_t idxGetCompar(int8_t type) {
}
return
getComparFunc
(
type
,
0
);
}
static
TExeCond
tCompareLessThan
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
static
FORCE_INLINE
TExeCond
tCompareLessThan
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
idxGetCompar
(
type
);
return
tCompare
(
func
,
QUERY_LESS_THAN
,
a
,
b
,
type
);
}
static
TExeCond
tCompareLessEqual
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
static
FORCE_INLINE
TExeCond
tCompareLessEqual
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
idxGetCompar
(
type
);
return
tCompare
(
func
,
QUERY_LESS_EQUAL
,
a
,
b
,
type
);
}
static
TExeCond
tCompareGreaterThan
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
static
FORCE_INLINE
TExeCond
tCompareGreaterThan
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
idxGetCompar
(
type
);
return
tCompare
(
func
,
QUERY_GREATER_THAN
,
a
,
b
,
type
);
}
static
TExeCond
tCompareGreaterEqual
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
static
FORCE_INLINE
TExeCond
tCompareGreaterEqual
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
idxGetCompar
(
type
);
return
tCompare
(
func
,
QUERY_GREATER_EQUAL
,
a
,
b
,
type
);
}
static
TExeCond
tCompareContains
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
static
FORCE_INLINE
TExeCond
tCompareContains
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
idxGetCompar
(
type
);
return
tCompare
(
func
,
QUERY_TERM
,
a
,
b
,
type
);
}
static
TExeCond
tCompareEqual
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
static
FORCE_INLINE
TExeCond
tCompareEqual
(
void
*
a
,
void
*
b
,
int8_t
type
)
{
__compar_fn_t
func
=
idxGetCompar
(
type
);
return
tCompare
(
func
,
QUERY_TERM
,
a
,
b
,
type
);
}
...
...
source/libs/index/src/indexFilter.c
浏览文件 @
4cdaafe6
...
...
@@ -88,7 +88,7 @@ typedef struct SIFCtx {
SIndexMetaArg
arg
;
}
SIFCtx
;
static
int32_t
sifGetFuncFromSql
(
EOperatorType
src
,
EIndexQueryType
*
dst
)
{
static
FORCE_INLINE
int32_t
sifGetFuncFromSql
(
EOperatorType
src
,
EIndexQueryType
*
dst
)
{
if
(
src
==
OP_TYPE_GREATER_THAN
)
{
*
dst
=
QUERY_GREATER_THAN
;
}
else
if
(
src
==
OP_TYPE_GREATER_EQUAL
)
{
...
...
@@ -110,10 +110,9 @@ static int32_t sifGetFuncFromSql(EOperatorType src, EIndexQueryType *dst) {
}
typedef
int32_t
(
*
sif_func_t
)(
SIFParam
*
left
,
SIFParam
*
rigth
,
SIFParam
*
output
);
static
sif_func_t
sifNullFunc
=
NULL
;
static
void
sifFreeParam
(
SIFParam
*
param
)
{
static
FORCE_INLINE
void
sifFreeParam
(
SIFParam
*
param
)
{
if
(
param
==
NULL
)
return
;
taosArrayDestroy
(
param
->
result
);
...
...
@@ -123,7 +122,7 @@ static void sifFreeParam(SIFParam *param) {
param
->
pFilter
=
NULL
;
}
static
int32_t
sifGetOperParamNum
(
EOperatorType
ty
)
{
static
FORCE_INLINE
int32_t
sifGetOperParamNum
(
EOperatorType
ty
)
{
if
(
OP_TYPE_IS_NULL
==
ty
||
OP_TYPE_IS_NOT_NULL
==
ty
||
OP_TYPE_IS_TRUE
==
ty
||
OP_TYPE_IS_NOT_TRUE
==
ty
||
OP_TYPE_IS_FALSE
==
ty
||
OP_TYPE_IS_NOT_FALSE
==
ty
||
OP_TYPE_IS_UNKNOWN
==
ty
||
OP_TYPE_IS_NOT_UNKNOWN
==
ty
||
OP_TYPE_MINUS
==
ty
)
{
...
...
@@ -131,14 +130,14 @@ static int32_t sifGetOperParamNum(EOperatorType ty) {
}
return
2
;
}
static
int32_t
sifValidOp
(
EOperatorType
ty
)
{
static
FORCE_INLINE
int32_t
sifValidOp
(
EOperatorType
ty
)
{
if
((
ty
>=
OP_TYPE_ADD
&&
ty
<=
OP_TYPE_BIT_OR
)
||
(
ty
==
OP_TYPE_IN
||
ty
==
OP_TYPE_NOT_IN
)
||
(
ty
==
OP_TYPE_LIKE
||
ty
==
OP_TYPE_NOT_LIKE
||
ty
==
OP_TYPE_MATCH
||
ty
==
OP_TYPE_NMATCH
))
{
return
-
1
;
}
return
0
;
}
static
int32_t
sifValidColumn
(
SColumnNode
*
cn
)
{
static
FORCE_INLINE
int32_t
sifValidColumn
(
SColumnNode
*
cn
)
{
// add more check
if
(
cn
==
NULL
)
{
return
TSDB_CODE_QRY_INVALID_INPUT
;
...
...
@@ -149,7 +148,7 @@ static int32_t sifValidColumn(SColumnNode *cn) {
return
TSDB_CODE_SUCCESS
;
}
static
SIdxFltStatus
sifMergeCond
(
ELogicConditionType
type
,
SIdxFltStatus
ls
,
SIdxFltStatus
rs
)
{
static
FORCE_INLINE
SIdxFltStatus
sifMergeCond
(
ELogicConditionType
type
,
SIdxFltStatus
ls
,
SIdxFltStatus
rs
)
{
// enh rule later
if
(
type
==
LOGIC_COND_TYPE_AND
)
{
if
(
ls
==
SFLT_NOT_INDEX
||
rs
==
SFLT_NOT_INDEX
)
{
...
...
@@ -167,7 +166,7 @@ static SIdxFltStatus sifMergeCond(ELogicConditionType type, SIdxFltStatus ls, SI
return
SFLT_NOT_INDEX
;
}
static
int32_t
sifGetValueFromNode
(
SNode
*
node
,
char
**
value
)
{
static
FORCE_INLINE
int32_t
sifGetValueFromNode
(
SNode
*
node
,
char
**
value
)
{
// covert data From snode;
SValueNode
*
vn
=
(
SValueNode
*
)
node
;
...
...
@@ -205,7 +204,7 @@ static int32_t sifGetValueFromNode(SNode *node, char **value) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
sifInitJsonParam
(
SNode
*
node
,
SIFParam
*
param
,
SIFCtx
*
ctx
)
{
static
FORCE_INLINE
int32_t
sifInitJsonParam
(
SNode
*
node
,
SIFParam
*
param
,
SIFCtx
*
ctx
)
{
SOperatorNode
*
nd
=
(
SOperatorNode
*
)
node
;
assert
(
nodeType
(
node
)
==
QUERY_NODE_OPERATOR
);
SColumnNode
*
l
=
(
SColumnNode
*
)
nd
->
pLeft
;
...
...
@@ -355,30 +354,30 @@ static int32_t sifExecFunction(SFunctionNode *node, SIFCtx *ctx, SIFParam *outpu
return
TSDB_CODE_QRY_INVALID_INPUT
;
}
typedef
int
(
*
Filter
)(
void
*
a
,
void
*
b
,
int16_t
dtype
);
typedef
int
(
*
Filter
Func
)(
void
*
a
,
void
*
b
,
int16_t
dtype
);
int
sifGreaterThan
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
static
FORCE_INLINE
int
sifGreaterThan
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
__compar_fn_t
func
=
getComparFunc
(
dtype
,
0
);
return
tDoCompare
(
func
,
QUERY_GREATER_THAN
,
a
,
b
);
}
int
sifGreaterEqual
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
static
FORCE_INLINE
int
sifGreaterEqual
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
__compar_fn_t
func
=
getComparFunc
(
dtype
,
0
);
return
tDoCompare
(
func
,
QUERY_GREATER_EQUAL
,
a
,
b
);
}
int
sifLessEqual
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
static
FORCE_INLINE
int
sifLessEqual
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
__compar_fn_t
func
=
getComparFunc
(
dtype
,
0
);
return
tDoCompare
(
func
,
QUERY_LESS_EQUAL
,
a
,
b
);
}
int
sifLessThan
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
static
FORCE_INLINE
int
sifLessThan
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
__compar_fn_t
func
=
getComparFunc
(
dtype
,
0
);
return
(
int
)
tDoCompare
(
func
,
QUERY_LESS_THAN
,
a
,
b
);
}
int
sifEqual
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
static
FORCE_INLINE
int
sifEqual
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
__compar_fn_t
func
=
getComparFunc
(
dtype
,
0
);
//__compar_fn_t func = idxGetCompar(dtype);
return
(
int
)
tDoCompare
(
func
,
QUERY_TERM
,
a
,
b
);
}
static
F
ilter
sifGetFilterFunc
(
EIndexQueryType
type
,
bool
*
reverse
)
{
static
F
ORCE_INLINE
FilterFunc
sifGetFilterFunc
(
EIndexQueryType
type
,
bool
*
reverse
)
{
if
(
type
==
QUERY_LESS_EQUAL
||
type
==
QUERY_LESS_THAN
)
{
*
reverse
=
true
;
}
else
{
...
...
@@ -470,8 +469,8 @@ static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFP
indexMultiTermQueryAdd
(
mtm
,
tm
,
qtype
);
ret
=
indexJsonSearch
(
arg
->
ivtIdx
,
mtm
,
output
->
result
);
}
else
{
bool
reverse
;
Filter
filterFunc
=
sifGetFilterFunc
(
qtype
,
&
reverse
);
bool
reverse
;
Filter
Func
filterFunc
=
sifGetFilterFunc
(
qtype
,
&
reverse
);
SMetaFltParam
param
=
{.
suid
=
arg
->
suid
,
.
cid
=
left
->
colId
,
...
...
@@ -498,72 +497,72 @@ static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFP
return
ret
;
}
static
int32_t
sifLessThanFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifLessThanFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_LOWER_THAN
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifLessEqualFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifLessEqualFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_LOWER_EQUAL
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifGreaterThanFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifGreaterThanFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_GREATER_THAN
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifGreaterEqualFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifGreaterEqualFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_GREATER_EQUAL
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifEqualFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifEqualFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_EQUAL
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifNotEqualFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifNotEqualFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_NOT_EQUAL
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifInFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifInFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_IN
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifNotInFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifNotInFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_NOT_IN
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifLikeFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifLikeFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_LIKE
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifNotLikeFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifNotLikeFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_NOT_LIKE
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifMatchFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifMatchFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_MATCH
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifNotMatchFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifNotMatchFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_NMATCH
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifJsonContains
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifJsonContains
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
int
id
=
OP_TYPE_JSON_CONTAINS
;
return
sifDoIndex
(
left
,
right
,
id
,
output
);
}
static
int32_t
sifJsonGetValue
(
SIFParam
*
left
,
SIFParam
*
rigth
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifJsonGetValue
(
SIFParam
*
left
,
SIFParam
*
rigth
,
SIFParam
*
output
)
{
// return 0
return
0
;
}
static
int32_t
sifDefaultFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
static
FORCE_INLINE
int32_t
sifDefaultFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
// add more except
return
TSDB_CODE_QRY_INVALID_INPUT
;
}
static
int32_t
sifGetOperFn
(
int32_t
funcId
,
sif_func_t
*
func
,
SIdxFltStatus
*
status
)
{
static
FORCE_INLINE
int32_t
sifGetOperFn
(
int32_t
funcId
,
sif_func_t
*
func
,
SIdxFltStatus
*
status
)
{
// impl later
*
status
=
SFLT_ACCURATE_INDEX
;
switch
(
funcId
)
{
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
4cdaafe6
...
...
@@ -6604,7 +6604,17 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
pReq
->
colId
=
pSchema
->
colId
;
SDataType
targetDt
=
schemaToDataType
(
pTableMeta
->
tableInfo
.
precision
,
pSchema
);
if
(
DEAL_RES_ERROR
==
translateValueImpl
(
pCxt
,
pStmt
->
pVal
,
targetDt
,
true
))
{
if
(
QUERY_NODE_VALUE
!=
pStmt
->
pVal
->
node
.
type
)
{
SValueNode
*
pVal
=
NULL
;
pCxt
->
errCode
=
createTagValFromExpr
(
pCxt
,
targetDt
,
(
SNode
*
)
pStmt
->
pVal
,
&
pVal
);
if
(
pCxt
->
errCode
)
{
return
pCxt
->
errCode
;
}
nodesDestroyNode
((
SNode
*
)
pStmt
->
pVal
);
pStmt
->
pVal
=
pVal
;
}
else
if
(
DEAL_RES_ERROR
==
translateValueImpl
(
pCxt
,
pStmt
->
pVal
,
targetDt
,
true
))
{
return
pCxt
->
errCode
;
}
...
...
source/libs/stream/src/streamState.c
浏览文件 @
4cdaafe6
...
...
@@ -112,6 +112,29 @@ int32_t streamStateDel(SStreamState* pState, const SWinKey* key) {
return
tdbTbDelete
(
pState
->
pStateDb
,
key
,
sizeof
(
SWinKey
),
&
pState
->
txn
);
}
int32_t
streamStateAddIfNotExist
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
**
pVal
,
int32_t
*
pVLen
)
{
// todo refactor
int32_t
size
=
*
pVLen
;
if
(
streamStateGet
(
pState
,
key
,
pVal
,
pVLen
)
==
0
)
{
return
0
;
}
void
*
tmp
=
taosMemoryCalloc
(
1
,
size
);
if
(
streamStatePut
(
pState
,
key
,
&
tmp
,
size
)
==
0
)
{
taosMemoryFree
(
tmp
);
int32_t
code
=
streamStateGet
(
pState
,
key
,
pVal
,
pVLen
);
ASSERT
(
code
==
0
);
return
code
;
}
taosMemoryFree
(
tmp
);
return
-
1
;
}
int32_t
streamStateReleaseBuf
(
SStreamState
*
pState
,
const
SWinKey
*
key
,
void
*
pVal
)
{
// todo refactor
streamFreeVal
(
pVal
);
return
0
;
}
SStreamStateCur
*
streamStateGetCur
(
SStreamState
*
pState
,
const
SWinKey
*
key
)
{
SStreamStateCur
*
pCur
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamStateCur
));
if
(
pCur
==
NULL
)
return
NULL
;
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
4cdaafe6
...
...
@@ -2766,8 +2766,6 @@ const char* syncStr(ESyncState state) {
}
int32_t
syncDoLeaderTransfer
(
SSyncNode
*
ths
,
SRpcMsg
*
pRpcMsg
,
SSyncRaftEntry
*
pEntry
)
{
SyncLeaderTransfer
*
pSyncLeaderTransfer
=
syncLeaderTransferFromRpcMsg2
(
pRpcMsg
);
if
(
ths
->
state
!=
TAOS_SYNC_STATE_FOLLOWER
)
{
syncNodeEventLog
(
ths
,
"I am not follower, can not do leader transfer"
);
return
0
;
...
...
@@ -2799,6 +2797,8 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
}
*/
SyncLeaderTransfer
*
pSyncLeaderTransfer
=
syncLeaderTransferFromRpcMsg2
(
pRpcMsg
);
do
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"do leader transfer, index:%ld"
,
pEntry
->
index
);
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
4cdaafe6
...
...
@@ -1992,6 +1992,313 @@ void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg) {
}
}
// ---- message process SyncHeartbeat----
SyncHeartbeat
*
syncHeartbeatBuild
(
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncHeartbeat
);
SyncHeartbeat
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
pMsg
->
msgType
=
TDMT_SYNC_HEARTBEAT
;
return
pMsg
;
}
void
syncHeartbeatDestroy
(
SyncHeartbeat
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncHeartbeatSerialize
(
const
SyncHeartbeat
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncHeartbeatDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncHeartbeat
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
}
char
*
syncHeartbeatSerialize2
(
const
SyncHeartbeat
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncHeartbeatSerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncHeartbeat
*
syncHeartbeatDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncHeartbeat
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncHeartbeatDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncHeartbeat2RpcMsg
(
const
SyncHeartbeat
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncHeartbeatSerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncHeartbeatFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncHeartbeat
*
pMsg
)
{
syncHeartbeatDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncHeartbeat
*
syncHeartbeatFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncHeartbeat
*
pMsg
=
syncHeartbeatDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
ASSERT
(
pMsg
!=
NULL
);
return
pMsg
;
}
cJSON
*
syncHeartbeat2Json
(
const
SyncHeartbeat
*
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
),
"%"
PRIu64
,
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
),
"%"
PRIu64
,
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
),
"%"
PRIu64
,
pMsg
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
privateTerm
);
cJSON_AddStringToObject
(
pRoot
,
"privateTerm"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
commitIndex
);
cJSON_AddStringToObject
(
pRoot
,
"commitIndex"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncHeartbeat"
,
pRoot
);
return
pJson
;
}
char
*
syncHeartbeat2Str
(
const
SyncHeartbeat
*
pMsg
)
{
cJSON
*
pJson
=
syncHeartbeat2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
void
syncHeartbeatPrint
(
const
SyncHeartbeat
*
pMsg
)
{
char
*
serialized
=
syncHeartbeat2Str
(
pMsg
);
printf
(
"syncHeartbeatPrint | len:%"
PRIu64
" | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncHeartbeatPrint2
(
char
*
s
,
const
SyncHeartbeat
*
pMsg
)
{
char
*
serialized
=
syncHeartbeat2Str
(
pMsg
);
printf
(
"syncHeartbeatPrint2 | len:%"
PRIu64
" | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncHeartbeatLog
(
const
SyncHeartbeat
*
pMsg
)
{
char
*
serialized
=
syncHeartbeat2Str
(
pMsg
);
sTrace
(
"syncHeartbeatLog | len:%"
PRIu64
" | %s"
,
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
syncHeartbeatLog2
(
char
*
s
,
const
SyncHeartbeat
*
pMsg
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
syncHeartbeat2Str
(
pMsg
);
sTrace
(
"syncHeartbeatLog2 | len:%"
PRIu64
" | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
}
// ---- message process SyncHeartbeatReply----
SyncHeartbeatReply
*
syncHeartbeatReplyBuild
(
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncHeartbeatReply
);
SyncHeartbeatReply
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
pMsg
->
msgType
=
TDMT_SYNC_HEARTBEAT_REPLY
;
return
pMsg
;
}
void
syncHeartbeatReplyDestroy
(
SyncHeartbeatReply
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncHeartbeatReplySerialize
(
const
SyncHeartbeatReply
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncHeartbeatReplyDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncHeartbeatReply
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
}
char
*
syncHeartbeatReplySerialize2
(
const
SyncHeartbeatReply
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncHeartbeatReplySerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncHeartbeatReply
*
syncHeartbeatReplyDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncHeartbeatReply
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncHeartbeatReplyDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncHeartbeatReply2RpcMsg
(
const
SyncHeartbeatReply
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncHeartbeatReplySerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncHeartbeatReplyFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncHeartbeatReply
*
pMsg
)
{
syncHeartbeatReplyDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncHeartbeatReply
*
syncHeartbeatReplyFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncHeartbeatReply
*
pMsg
=
syncHeartbeatReplyDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
ASSERT
(
pMsg
!=
NULL
);
return
pMsg
;
}
cJSON
*
syncHeartbeatReply2Json
(
const
SyncHeartbeatReply
*
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
),
"%"
PRIu64
,
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
),
"%"
PRIu64
,
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
),
"%"
PRIu64
,
pMsg
->
privateTerm
);
cJSON_AddStringToObject
(
pRoot
,
"privateTerm"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"matchIndex"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
startTime
);
cJSON_AddStringToObject
(
pRoot
,
"startTime"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncHeartbeatReply"
,
pRoot
);
return
pJson
;
}
char
*
syncHeartbeatReply2Str
(
const
SyncHeartbeatReply
*
pMsg
)
{
cJSON
*
pJson
=
syncHeartbeatReply2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
void
syncHeartbeatReplyPrint
(
const
SyncHeartbeatReply
*
pMsg
)
{
char
*
serialized
=
syncHeartbeatReply2Str
(
pMsg
);
printf
(
"syncHeartbeatReplyPrint | len:%"
PRIu64
" | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncHeartbeatReplyPrint2
(
char
*
s
,
const
SyncHeartbeatReply
*
pMsg
)
{
char
*
serialized
=
syncHeartbeatReply2Str
(
pMsg
);
printf
(
"syncHeartbeatReplyPrint2 | len:%"
PRIu64
" | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncHeartbeatReplyLog
(
const
SyncHeartbeatReply
*
pMsg
)
{
char
*
serialized
=
syncHeartbeatReply2Str
(
pMsg
);
sTrace
(
"syncHeartbeatReplyLog | len:%"
PRIu64
" | %s"
,
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
syncHeartbeatReplyLog2
(
char
*
s
,
const
SyncHeartbeatReply
*
pMsg
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
syncHeartbeatReply2Str
(
pMsg
);
sTrace
(
"syncHeartbeatReplyLog2 | len:%"
PRIu64
" | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
}
// ---- message process SyncApplyMsg----
SyncApplyMsg
*
syncApplyMsgBuild
(
uint32_t
dataLen
)
{
uint32_t
bytes
=
sizeof
(
SyncApplyMsg
)
+
dataLen
;
...
...
source/libs/sync/test/CMakeLists.txt
浏览文件 @
4cdaafe6
...
...
@@ -57,6 +57,8 @@ add_executable(syncLeaderTransferTest "")
add_executable
(
syncReconfigFinishTest
""
)
add_executable
(
syncRestoreFromSnapshot
""
)
add_executable
(
syncRaftCfgIndexTest
""
)
add_executable
(
syncHeartbeatTest
""
)
add_executable
(
syncHeartbeatReplyTest
""
)
target_sources
(
syncTest
...
...
@@ -295,6 +297,14 @@ target_sources(syncRaftCfgIndexTest
PRIVATE
"syncRaftCfgIndexTest.cpp"
)
target_sources
(
syncHeartbeatTest
PRIVATE
"syncHeartbeatTest.cpp"
)
target_sources
(
syncHeartbeatReplyTest
PRIVATE
"syncHeartbeatReplyTest.cpp"
)
target_include_directories
(
syncTest
...
...
@@ -592,6 +602,16 @@ target_include_directories(syncRaftCfgIndexTest
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncHeartbeatTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncHeartbeatReplyTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_link_libraries
(
syncTest
...
...
@@ -830,6 +850,14 @@ target_link_libraries(syncRaftCfgIndexTest
sync
gtest_main
)
target_link_libraries
(
syncHeartbeatTest
sync
gtest_main
)
target_link_libraries
(
syncHeartbeatReplyTest
sync
gtest_main
)
enable_testing
()
...
...
source/libs/sync/test/syncHeartbeatReplyTest.cpp
0 → 100644
浏览文件 @
4cdaafe6
#include <gtest/gtest.h>
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncMessage.h"
#include "syncUtil.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"
);
}
SyncHeartbeatReply
*
createMsg
()
{
SyncHeartbeatReply
*
pMsg
=
syncHeartbeatReplyBuild
(
1000
);
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
->
term
=
33
;
pMsg
->
privateTerm
=
44
;
pMsg
->
startTime
=
taosGetTimestampMs
();
return
pMsg
;
}
void
test1
()
{
SyncHeartbeatReply
*
pMsg
=
createMsg
();
syncHeartbeatReplyLog2
((
char
*
)
"test1:"
,
pMsg
);
syncHeartbeatReplyDestroy
(
pMsg
);
}
void
test2
()
{
SyncHeartbeatReply
*
pMsg
=
createMsg
();
uint32_t
len
=
pMsg
->
bytes
;
char
*
serialized
=
(
char
*
)
taosMemoryMalloc
(
len
);
syncHeartbeatReplySerialize
(
pMsg
,
serialized
,
len
);
SyncHeartbeatReply
*
pMsg2
=
syncHeartbeatReplyBuild
(
1000
);
syncHeartbeatReplyDeserialize
(
serialized
,
len
,
pMsg2
);
syncHeartbeatReplyLog2
((
char
*
)
"test2: syncHeartbeatReplySerialize -> syncHeartbeatReplyDeserialize "
,
pMsg2
);
taosMemoryFree
(
serialized
);
syncHeartbeatReplyDestroy
(
pMsg
);
syncHeartbeatReplyDestroy
(
pMsg2
);
}
void
test3
()
{
SyncHeartbeatReply
*
pMsg
=
createMsg
();
uint32_t
len
;
char
*
serialized
=
syncHeartbeatReplySerialize2
(
pMsg
,
&
len
);
SyncHeartbeatReply
*
pMsg2
=
syncHeartbeatReplyDeserialize2
(
serialized
,
len
);
syncHeartbeatReplyLog2
((
char
*
)
"test3: syncHeartbeatReplySerialize3 -> syncHeartbeatReplyDeserialize2 "
,
pMsg2
);
taosMemoryFree
(
serialized
);
syncHeartbeatReplyDestroy
(
pMsg
);
syncHeartbeatReplyDestroy
(
pMsg2
);
}
void
test4
()
{
SyncHeartbeatReply
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncHeartbeatReply2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncHeartbeatReply
*
pMsg2
=
syncHeartbeatReplyBuild
(
1000
);
syncHeartbeatReplyFromRpcMsg
(
&
rpcMsg
,
pMsg2
);
syncHeartbeatReplyLog2
((
char
*
)
"test4: syncHeartbeatReply2RpcMsg -> syncHeartbeatReplyFromRpcMsg "
,
pMsg2
);
rpcFreeCont
(
rpcMsg
.
pCont
);
syncHeartbeatReplyDestroy
(
pMsg
);
syncHeartbeatReplyDestroy
(
pMsg2
);
}
void
test5
()
{
SyncHeartbeatReply
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncHeartbeatReply2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncHeartbeatReply
*
pMsg2
=
syncHeartbeatReplyFromRpcMsg2
(
&
rpcMsg
);
syncHeartbeatReplyLog2
((
char
*
)
"test5: syncHeartbeatReply2RpcMsg -> syncHeartbeatReplyFromRpcMsg2 "
,
pMsg2
);
rpcFreeCont
(
rpcMsg
.
pCont
);
syncHeartbeatReplyDestroy
(
pMsg
);
syncHeartbeatReplyDestroy
(
pMsg2
);
}
int
main
()
{
gRaftDetailLog
=
true
;
tsAsyncLog
=
0
;
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
;
logTest
();
test1
();
test2
();
test3
();
test4
();
test5
();
return
0
;
}
source/libs/sync/test/syncHeartbeatTest.cpp
0 → 100644
浏览文件 @
4cdaafe6
#include <gtest/gtest.h>
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncMessage.h"
#include "syncUtil.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"
);
}
SyncHeartbeat
*
createMsg
()
{
SyncHeartbeat
*
pMsg
=
syncHeartbeatBuild
(
789
);
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
->
term
=
8
;
pMsg
->
commitIndex
=
33
;
pMsg
->
privateTerm
=
44
;
return
pMsg
;
}
void
test1
()
{
SyncHeartbeat
*
pMsg
=
createMsg
();
syncHeartbeatLog2
((
char
*
)
"test1:"
,
pMsg
);
syncHeartbeatDestroy
(
pMsg
);
}
void
test2
()
{
SyncHeartbeat
*
pMsg
=
createMsg
();
uint32_t
len
=
pMsg
->
bytes
;
char
*
serialized
=
(
char
*
)
taosMemoryMalloc
(
len
);
syncHeartbeatSerialize
(
pMsg
,
serialized
,
len
);
SyncHeartbeat
*
pMsg2
=
syncHeartbeatBuild
(
789
);
syncHeartbeatDeserialize
(
serialized
,
len
,
pMsg2
);
syncHeartbeatLog2
((
char
*
)
"test2: syncHeartbeatSerialize -> syncHeartbeatDeserialize "
,
pMsg2
);
taosMemoryFree
(
serialized
);
syncHeartbeatDestroy
(
pMsg
);
syncHeartbeatDestroy
(
pMsg2
);
}
void
test3
()
{
SyncHeartbeat
*
pMsg
=
createMsg
();
uint32_t
len
;
char
*
serialized
=
syncHeartbeatSerialize2
(
pMsg
,
&
len
);
SyncHeartbeat
*
pMsg2
=
syncHeartbeatDeserialize2
(
serialized
,
len
);
syncHeartbeatLog2
((
char
*
)
"test3: syncHeartbeatSerialize2 -> syncHeartbeatDeserialize2 "
,
pMsg2
);
taosMemoryFree
(
serialized
);
syncHeartbeatDestroy
(
pMsg
);
syncHeartbeatDestroy
(
pMsg2
);
}
void
test4
()
{
SyncHeartbeat
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncHeartbeat2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncHeartbeat
*
pMsg2
=
(
SyncHeartbeat
*
)
taosMemoryMalloc
(
rpcMsg
.
contLen
);
syncHeartbeatFromRpcMsg
(
&
rpcMsg
,
pMsg2
);
syncHeartbeatLog2
((
char
*
)
"test4: syncHeartbeat2RpcMsg -> syncHeartbeatFromRpcMsg "
,
pMsg2
);
rpcFreeCont
(
rpcMsg
.
pCont
);
syncHeartbeatDestroy
(
pMsg
);
syncHeartbeatDestroy
(
pMsg2
);
}
void
test5
()
{
SyncHeartbeat
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncHeartbeat2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncHeartbeat
*
pMsg2
=
syncHeartbeatFromRpcMsg2
(
&
rpcMsg
);
syncHeartbeatLog2
((
char
*
)
"test5: syncHeartbeat2RpcMsg -> syncHeartbeatFromRpcMsg2 "
,
pMsg2
);
rpcFreeCont
(
rpcMsg
.
pCont
);
syncHeartbeatDestroy
(
pMsg
);
syncHeartbeatDestroy
(
pMsg2
);
}
int
main
()
{
tsAsyncLog
=
0
;
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
;
gRaftDetailLog
=
true
;
logTest
();
test1
();
test2
();
test3
();
test4
();
test5
();
return
0
;
}
source/libs/tdb/src/db/tdbPager.c
浏览文件 @
4cdaafe6
...
...
@@ -502,7 +502,7 @@ static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage) {
i64
offset
;
int
ret
;
offset
=
pPage
->
pageSize
*
(
TDB_PAGE_PGNO
(
pPage
)
-
1
);
offset
=
(
i64
)
pPage
->
pageSize
*
(
TDB_PAGE_PGNO
(
pPage
)
-
1
);
if
(
tdbOsLSeek
(
pPager
->
fd
,
offset
,
SEEK_SET
)
<
0
)
{
ASSERT
(
0
);
return
-
1
;
...
...
source/libs/transport/src/thttp.c
浏览文件 @
4cdaafe6
...
...
@@ -126,22 +126,22 @@ _OVER:
return
code
;
}
static
void
destroyHttpClient
(
SHttpClient
*
cli
)
{
static
FORCE_INLINE
void
destroyHttpClient
(
SHttpClient
*
cli
)
{
taosMemoryFree
(
cli
->
wbuf
);
taosMemoryFree
(
cli
->
rbuf
);
taosMemoryFree
(
cli
->
addr
);
taosMemoryFree
(
cli
);
}
static
void
clientCloseCb
(
uv_handle_t
*
handle
)
{
static
FORCE_INLINE
void
clientCloseCb
(
uv_handle_t
*
handle
)
{
SHttpClient
*
cli
=
handle
->
data
;
destroyHttpClient
(
cli
);
}
static
void
clientAllocBuffCb
(
uv_handle_t
*
handle
,
size_t
suggested_size
,
uv_buf_t
*
buf
)
{
static
FORCE_INLINE
void
clientAllocBuffCb
(
uv_handle_t
*
handle
,
size_t
suggested_size
,
uv_buf_t
*
buf
)
{
SHttpClient
*
cli
=
handle
->
data
;
buf
->
base
=
cli
->
rbuf
;
buf
->
len
=
HTTP_RECV_BUF_SIZE
;
}
static
void
clientRecvCb
(
uv_stream_t
*
handle
,
ssize_t
nread
,
const
uv_buf_t
*
buf
)
{
static
FORCE_INLINE
void
clientRecvCb
(
uv_stream_t
*
handle
,
ssize_t
nread
,
const
uv_buf_t
*
buf
)
{
SHttpClient
*
cli
=
handle
->
data
;
if
(
nread
<
0
)
{
uError
(
"http-report recv error:%s"
,
uv_err_name
(
nread
));
...
...
@@ -173,7 +173,7 @@ static void clientConnCb(uv_connect_t* req, int32_t status) {
uv_write
(
&
cli
->
req
,
(
uv_stream_t
*
)
&
cli
->
tcp
,
cli
->
wbuf
,
2
,
clientSentCb
);
}
static
int32_t
taosBuildDstAddr
(
const
char
*
server
,
uint16_t
port
,
struct
sockaddr_in
*
dest
)
{
static
FORCE_INLINE
int32_t
taosBuildDstAddr
(
const
char
*
server
,
uint16_t
port
,
struct
sockaddr_in
*
dest
)
{
uint32_t
ip
=
taosGetIpv4FromFqdn
(
server
);
if
(
ip
==
0xffffffff
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
...
...
source/libs/transport/src/transCli.c
浏览文件 @
4cdaafe6
...
...
@@ -69,11 +69,9 @@ typedef struct SCliThrd {
SAsyncPool
*
asyncPool
;
uv_prepare_t
*
prepare
;
void
*
pool
;
// conn pool
// timer handles
SArray
*
timerList
;
// msg queue
queue
msg
;
TdThreadMutex
msgMtx
;
SDelayQueue
*
delayQueue
;
...
...
@@ -108,7 +106,7 @@ static void cliReadTimeoutCb(uv_timer_t* handle);
// register timer in each thread to clear expire conn
// static void cliTimeoutCb(uv_timer_t* handle);
// alloc buffer for recv
static
void
cliAllocRecvBufferCb
(
uv_handle_t
*
handle
,
size_t
suggested_size
,
uv_buf_t
*
buf
);
static
FORCE_INLINE
void
cliAllocRecvBufferCb
(
uv_handle_t
*
handle
,
size_t
suggested_size
,
uv_buf_t
*
buf
);
// callback after recv nbytes from socket
static
void
cliRecvCb
(
uv_stream_t
*
cli
,
ssize_t
nread
,
const
uv_buf_t
*
buf
);
// callback after send data to socket
...
...
@@ -132,10 +130,10 @@ static void cliSend(SCliConn* pConn);
static
void
cliDestroyConnMsgs
(
SCliConn
*
conn
,
bool
destroy
);
// cli util func
static
bool
cliIsEpsetUpdated
(
int32_t
code
,
STransConnCtx
*
pCtx
);
static
void
cliMayCvtFqdnToIp
(
SEpSet
*
pEpSet
,
SCvtAddr
*
pCvtAddr
);
static
FORCE_INLINE
bool
cliIsEpsetUpdated
(
int32_t
code
,
STransConnCtx
*
pCtx
);
static
FORCE_INLINE
void
cliMayCvtFqdnToIp
(
SEpSet
*
pEpSet
,
SCvtAddr
*
pCvtAddr
);
static
int32_t
cliBuildExceptResp
(
SCliMsg
*
pMsg
,
STransMsg
*
resp
);
static
FORCE_INLINE
int32_t
cliBuildExceptResp
(
SCliMsg
*
pMsg
,
STransMsg
*
resp
);
// process data read from server, add decompress etc later
static
void
cliHandleResp
(
SCliConn
*
conn
);
...
...
@@ -150,13 +148,11 @@ static void cliHandleUpdate(SCliMsg* pMsg, SCliThrd* pThrd);
static
void
(
*
cliAsyncHandle
[])(
SCliMsg
*
pMsg
,
SCliThrd
*
pThrd
)
=
{
cliHandleReq
,
cliHandleQuit
,
cliHandleRelease
,
NULL
,
cliHandleUpdate
};
static
void
cliSendQuit
(
SCliThrd
*
thrd
);
static
void
destroyUserdata
(
STransMsg
*
userdata
);
static
int
cliRBChoseIdx
(
STrans
*
pTransInst
);
static
FORCE_INLINE
void
destroyUserdata
(
STransMsg
*
userdata
);
static
FORCE_INLINE
void
destroyCmsg
(
void
*
cmsg
);
static
FORCE_INLINE
int
cliRBChoseIdx
(
STrans
*
pTransInst
);
static
FORCE_INLINE
void
transDestroyConnCtx
(
STransConnCtx
*
ctx
);
static
void
destroyCmsg
(
void
*
cmsg
);
static
void
transDestroyConnCtx
(
STransConnCtx
*
ctx
);
// thread obj
static
SCliThrd
*
createThrdObj
();
static
void
destroyThrdObj
(
SCliThrd
*
pThrd
);
...
...
@@ -434,6 +430,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) {
if
(
pCtx
==
NULL
||
pCtx
->
pSem
==
NULL
)
{
if
(
transMsg
.
info
.
ahandle
==
NULL
)
{
if
(
REQUEST_NO_RESP
(
&
pMsg
->
msg
))
destroyCmsg
(
pMsg
);
once
=
true
;
continue
;
}
...
...
@@ -885,26 +882,23 @@ SCliConn* cliGetConn(SCliMsg* pMsg, SCliThrd* pThrd, bool* ignore) {
}
return
conn
;
}
void
cliMayCvtFqdnToIp
(
SEpSet
*
pEpSet
,
SCvtAddr
*
pCvtAddr
)
{
FORCE_INLINE
void
cliMayCvtFqdnToIp
(
SEpSet
*
pEpSet
,
SCvtAddr
*
pCvtAddr
)
{
if
(
pCvtAddr
->
cvt
==
false
)
{
return
;
}
for
(
int
i
=
0
;
i
<
pEpSet
->
numOfEps
&&
pEpSet
->
numOfEps
==
1
;
i
++
)
{
if
(
strncmp
(
pEpSet
->
eps
[
i
].
fqdn
,
pCvtAddr
->
fqdn
,
TSDB_FQDN_LEN
)
==
0
)
{
memset
(
pEpSet
->
eps
[
i
].
fqdn
,
0
,
TSDB_FQDN_LEN
);
memcpy
(
pEpSet
->
eps
[
i
].
fqdn
,
pCvtAddr
->
ip
,
TSDB_FQDN_LEN
);
}
if
(
pEpSet
->
numOfEps
==
1
&&
strncmp
(
pEpSet
->
eps
[
0
].
fqdn
,
pCvtAddr
->
fqdn
,
TSDB_FQDN_LEN
)
==
0
)
{
memset
(
pEpSet
->
eps
[
0
].
fqdn
,
0
,
TSDB_FQDN_LEN
);
memcpy
(
pEpSet
->
eps
[
0
].
fqdn
,
pCvtAddr
->
ip
,
TSDB_FQDN_LEN
);
}
}
bool
cliIsEpsetUpdated
(
int32_t
code
,
STransConnCtx
*
pCtx
)
{
FORCE_INLINE
bool
cliIsEpsetUpdated
(
int32_t
code
,
STransConnCtx
*
pCtx
)
{
if
(
code
!=
0
)
return
false
;
if
(
pCtx
->
retryCnt
==
0
)
return
false
;
if
(
transEpSetIsEqual
(
&
pCtx
->
epSet
,
&
pCtx
->
origEpSet
))
return
false
;
return
true
;
}
int32_t
cliBuildExceptResp
(
SCliMsg
*
pMsg
,
STransMsg
*
pResp
)
{
FORCE_INLINE
int32_t
cliBuildExceptResp
(
SCliMsg
*
pMsg
,
STransMsg
*
pResp
)
{
if
(
pMsg
==
NULL
)
return
-
1
;
memset
(
pResp
,
0
,
sizeof
(
STransMsg
));
...
...
@@ -980,6 +974,8 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) {
return
;
}
}
STraceId
*
trace
=
&
pMsg
->
msg
.
info
.
traceId
;
tGTrace
(
"%s conn %p ready"
,
pTransInst
->
label
,
conn
);
}
static
void
cliAsyncCb
(
uv_async_t
*
handle
)
{
SAsyncItem
*
item
=
handle
->
data
;
...
...
@@ -1128,14 +1124,15 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads,
return
cli
;
}
static
void
destroyUserdata
(
STransMsg
*
userdata
)
{
static
FORCE_INLINE
void
destroyUserdata
(
STransMsg
*
userdata
)
{
if
(
userdata
->
pCont
==
NULL
)
{
return
;
}
transFreeMsg
(
userdata
->
pCont
);
userdata
->
pCont
=
NULL
;
}
static
void
destroyCmsg
(
void
*
arg
)
{
static
FORCE_INLINE
void
destroyCmsg
(
void
*
arg
)
{
SCliMsg
*
pMsg
=
arg
;
if
(
pMsg
==
NULL
)
{
return
;
...
...
@@ -1201,7 +1198,7 @@ static void destroyThrdObj(SCliThrd* pThrd) {
taosMemoryFree
(
pThrd
);
}
static
void
transDestroyConnCtx
(
STransConnCtx
*
ctx
)
{
static
FORCE_INLINE
void
transDestroyConnCtx
(
STransConnCtx
*
ctx
)
{
//
taosMemoryFree
(
ctx
);
}
...
...
@@ -1220,7 +1217,7 @@ void cliWalkCb(uv_handle_t* handle, void* arg) {
}
}
int
cliRBChoseIdx
(
STrans
*
pTransInst
)
{
FORCE_INLINE
int
cliRBChoseIdx
(
STrans
*
pTransInst
)
{
int8_t
index
=
pTransInst
->
index
;
if
(
pTransInst
->
numOfThreads
==
0
)
{
return
-
1
;
...
...
@@ -1230,7 +1227,7 @@ int cliRBChoseIdx(STrans* pTransInst) {
}
return
index
%
pTransInst
->
numOfThreads
;
}
static
void
doDelayTask
(
void
*
param
)
{
static
FORCE_INLINE
void
doDelayTask
(
void
*
param
)
{
STaskArg
*
arg
=
param
;
SCliMsg
*
pMsg
=
arg
->
param1
;
SCliThrd
*
pThrd
=
arg
->
param2
;
...
...
@@ -1264,13 +1261,13 @@ static void cliSchedMsgToNextNode(SCliMsg* pMsg, SCliThrd* pThrd) {
transDQSched
(
pThrd
->
delayQueue
,
doDelayTask
,
arg
,
TRANS_RETRY_INTERVAL
);
}
void
cliCompareAndSwap
(
int8_t
*
val
,
int8_t
exp
,
int8_t
newVal
)
{
FORCE_INLINE
void
cliCompareAndSwap
(
int8_t
*
val
,
int8_t
exp
,
int8_t
newVal
)
{
if
(
*
val
!=
exp
)
{
*
val
=
newVal
;
}
}
bool
cliTryExtractEpSet
(
STransMsg
*
pResp
,
SEpSet
*
dst
)
{
FORCE_INLINE
bool
cliTryExtractEpSet
(
STransMsg
*
pResp
,
SEpSet
*
dst
)
{
if
((
pResp
==
NULL
||
pResp
->
info
.
hasEpSet
==
0
))
{
return
false
;
}
...
...
@@ -1300,7 +1297,7 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) {
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
if
(
pMsg
==
NULL
||
pMsg
->
ctx
==
NULL
)
{
t
Trace
(
"%s conn %p handle resp"
,
pTransInst
->
label
,
pConn
);
t
Debug
(
"%s conn %p handle resp"
,
pTransInst
->
label
,
pConn
);
pTransInst
->
cfp
(
pTransInst
->
parent
,
pResp
,
NULL
);
return
0
;
}
...
...
@@ -1402,7 +1399,7 @@ void transUnrefCliHandle(void* handle) {
cliDestroyConn
((
SCliConn
*
)
handle
,
true
);
}
}
SCliThrd
*
transGetWorkThrdFromHandle
(
int64_t
handle
,
bool
*
validHandle
)
{
static
FORCE_INLINE
SCliThrd
*
transGetWorkThrdFromHandle
(
int64_t
handle
,
bool
*
validHandle
)
{
SCliThrd
*
pThrd
=
NULL
;
SExHandle
*
exh
=
transAcquireExHandle
(
transGetRefMgt
(),
handle
);
if
(
exh
==
NULL
)
{
...
...
source/libs/transport/src/transComm.c
浏览文件 @
4cdaafe6
...
...
@@ -424,7 +424,7 @@ void transQueueDestroy(STransQueue* queue) {
taosArrayDestroy
(
queue
->
q
);
}
static
int32_t
timeCompare
(
const
HeapNode
*
a
,
const
HeapNode
*
b
)
{
static
FORCE_INLINE
int32_t
timeCompare
(
const
HeapNode
*
a
,
const
HeapNode
*
b
)
{
SDelayTask
*
arg1
=
container_of
(
a
,
SDelayTask
,
node
);
SDelayTask
*
arg2
=
container_of
(
b
,
SDelayTask
,
node
);
if
(
arg1
->
execTime
>
arg2
->
execTime
)
{
...
...
source/libs/transport/src/transSvr.c
浏览文件 @
4cdaafe6
...
...
@@ -125,17 +125,17 @@ static void uvWorkAfterTask(uv_work_t* req, int status);
static
void
uvWalkCb
(
uv_handle_t
*
handle
,
void
*
arg
);
static
void
uvFreeCb
(
uv_handle_t
*
handle
);
static
void
uvStartSendRespImpl
(
SSvrMsg
*
smsg
);
static
FORCE_INLINE
void
uvStartSendRespImpl
(
SSvrMsg
*
smsg
);
static
void
uvPrepareSendData
(
SSvrMsg
*
msg
,
uv_buf_t
*
wb
);
static
void
uvStartSendResp
(
SSvrMsg
*
msg
);
static
void
uvNotifyLinkBrokenToApp
(
SSvrConn
*
conn
);
static
void
destroySmsg
(
SSvrMsg
*
smsg
);
// check whether already read complete packet
static
SSvrConn
*
createConn
(
void
*
hThrd
);
static
void
destroyConn
(
SSvrConn
*
conn
,
bool
clear
/*clear handle or not*/
);
static
void
destroyConnRegArg
(
SSvrConn
*
conn
);
static
FORCE_INLINE
void
destroySmsg
(
SSvrMsg
*
smsg
);
static
FORCE_INLINE
SSvrConn
*
createConn
(
void
*
hThrd
);
static
FORCE_INLINE
void
destroyConn
(
SSvrConn
*
conn
,
bool
clear
/*clear handle or not*/
);
static
FORCE_INLINE
void
destroyConnRegArg
(
SSvrConn
*
conn
);
static
int
reallocConnRef
(
SSvrConn
*
conn
);
...
...
@@ -413,7 +413,7 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) {
wb
->
len
=
len
;
}
static
void
uvStartSendRespImpl
(
SSvrMsg
*
smsg
)
{
static
FORCE_INLINE
void
uvStartSendRespImpl
(
SSvrMsg
*
smsg
)
{
SSvrConn
*
pConn
=
smsg
->
pConn
;
if
(
pConn
->
broken
)
{
return
;
...
...
@@ -447,7 +447,7 @@ static void uvStartSendResp(SSvrMsg* smsg) {
return
;
}
static
void
destroySmsg
(
SSvrMsg
*
smsg
)
{
static
FORCE_INLINE
void
destroySmsg
(
SSvrMsg
*
smsg
)
{
if
(
smsg
==
NULL
)
{
return
;
}
...
...
@@ -812,7 +812,7 @@ void* transWorkerThread(void* arg) {
return
NULL
;
}
static
SSvrConn
*
createConn
(
void
*
hThrd
)
{
static
FORCE_INLINE
SSvrConn
*
createConn
(
void
*
hThrd
)
{
SWorkThrd
*
pThrd
=
hThrd
;
SSvrConn
*
pConn
=
(
SSvrConn
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SSvrConn
));
...
...
@@ -842,7 +842,7 @@ static SSvrConn* createConn(void* hThrd) {
return
pConn
;
}
static
void
destroyConn
(
SSvrConn
*
conn
,
bool
clear
)
{
static
FORCE_INLINE
void
destroyConn
(
SSvrConn
*
conn
,
bool
clear
)
{
if
(
conn
==
NULL
)
{
return
;
}
...
...
@@ -854,7 +854,7 @@ static void destroyConn(SSvrConn* conn, bool clear) {
}
}
}
static
void
destroyConnRegArg
(
SSvrConn
*
conn
)
{
static
FORCE_INLINE
void
destroyConnRegArg
(
SSvrConn
*
conn
)
{
if
(
conn
->
regArg
.
init
==
1
)
{
transFreeMsg
(
conn
->
regArg
.
msg
.
pCont
);
conn
->
regArg
.
init
=
0
;
...
...
source/util/test/pageBufferTest.cpp
浏览文件 @
4cdaafe6
...
...
@@ -23,9 +23,9 @@ void simpleTest() {
ASSERT_EQ
(
getTotalBufSize
(
pBuf
),
1024
);
SIDList
list
=
getDataBufPagesIdList
(
pBuf
,
groupId
);
SIDList
list
=
getDataBufPagesIdList
(
pBuf
);
ASSERT_EQ
(
taosArrayGetSize
(
list
),
1
);
ASSERT_EQ
(
getNumOfBufGroupId
(
pBuf
),
1
);
//
ASSERT_EQ(getNumOfBufGroupId(pBuf), 1);
releaseBufPage
(
pBuf
,
pBufPage
);
...
...
@@ -98,7 +98,7 @@ void writeDownTest() {
SFilePage
*
pBufPagex
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
writePageId
));
ASSERT_EQ
(
*
(
int32_t
*
)
pBufPagex
->
data
,
nx
);
SArray
*
pa
=
getDataBufPagesIdList
(
pBuf
,
groupId
);
SArray
*
pa
=
getDataBufPagesIdList
(
pBuf
);
ASSERT_EQ
(
taosArrayGetSize
(
pa
),
5
);
destroyDiskbasedBuf
(
pBuf
);
...
...
@@ -152,7 +152,7 @@ void recyclePageTest() {
SFilePage
*
pBufPagex1
=
static_cast
<
SFilePage
*>
(
getBufPage
(
pBuf
,
1
));
SArray
*
pa
=
getDataBufPagesIdList
(
pBuf
,
groupId
);
SArray
*
pa
=
getDataBufPagesIdList
(
pBuf
);
ASSERT_EQ
(
taosArrayGetSize
(
pa
),
6
);
destroyDiskbasedBuf
(
pBuf
);
...
...
tests/script/jenkins/basic.txt
浏览文件 @
4cdaafe6
...
...
@@ -248,6 +248,12 @@
./test.sh -f tsim/stream/windowClose.sim
./test.sh -f tsim/stream/ignoreExpiredData.sim
./test.sh -f tsim/stream/sliding.sim
#./test.sh -f tsim/stream/partitionbyColumnInterval.sim
#./test.sh -f tsim/stream/partitionbyColumnSession.sim
#./test.sh -f tsim/stream/partitionbyColumnState.sim
#./test.sh -f tsim/stream/deleteInterval.sim
#./test.sh -f tsim/stream/deleteSession.sim
#./test.sh -f tsim/stream/deleteState.sim
# ---- transaction ----
./test.sh -f tsim/trans/lossdata1.sim
...
...
tests/script/tsim/column/table.sim
浏览文件 @
4cdaafe6
...
...
@@ -159,6 +159,7 @@ if $data01 != 10 then
return -1
endi
if $data02 != 4.500000000 then
print expect 4.500000000, actual: $data02
return -1
endi
if $data03 != 4.500000000 then
...
...
tests/script/tsim/parser/commit.sim
浏览文件 @
4cdaafe6
...
...
@@ -97,6 +97,7 @@ while $loop <= $loops
endw
sql select count(*) from $stb
if $data00 != $totalNum then
print expect $totalNum , actual: $data00
return -1
endi
$loop = $loop + 1
...
...
tests/script/tsim/stream/basic1.sim
浏览文件 @
4cdaafe6
...
...
@@ -5,7 +5,7 @@ sleep 50
sql connect
print =============== create database
sql create database test vgroups 1
sql create database test vgroups 1
;
sql select * from information_schema.ins_databases
if $rows != 3 then
return -1
...
...
@@ -13,7 +13,7 @@ endi
print $data00 $data01 $data02
sql use test
sql use test
;
sql create table t1(ts timestamp, a int, b int , c int, d double);
...
...
tests/script/tsim/stream/deleteInterval.sim
0 → 100644
浏览文件 @
4cdaafe6
$loop_all = 0
looptest:
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sleep 200
sql connect
sql drop stream if exists streams0;
sql drop stream if exists streams1;
sql drop stream if exists streams2;
sql drop stream if exists streams3;
sql drop stream if exists streams4;
sql drop database if exists test;
sql create database test vgroups 1;
sql use test;
sql create table t1(ts timestamp, a int, b int , c int, d double);
sql create stream streams0 trigger at_once into streamt as select _wstart c1, count(*) c2, max(a) c3 from t1 interval(10s);
sql insert into t1 values(1648791213000,NULL,NULL,NULL,NULL);
sleep 200
sql delete from t1 where ts = 1648791213000;
$loop_count = 0
loop0:
sleep 200
sql select * from streamt order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $rows != 0 then
print =====rows=$rows
goto loop0
endi
sql insert into t1 values(1648791213000,NULL,NULL,NULL,NULL);
$loop_count = 0
loop1:
sleep 200
sql select * from streamt order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $data01 != 1 then
print =====data01=$data01
goto loop1
endi
if $data02 != NULL then
print =====data02=$data02
goto loop1
endi
sql insert into t1 values(1648791213000,1,1,1,1.0);
sql insert into t1 values(1648791213001,2,2,2,2.0);
sql insert into t1 values(1648791213002,3,3,3,3.0);
sql insert into t1 values(1648791213003,4,4,4,4.0);
sleep 200
sql delete from t1 where ts >= 1648791213001 and ts <= 1648791213002;
$loop_count = 0
loop3:
sleep 200
sql select * from streamt order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $data01 != 2 then
print =====data01=$data01
goto loop3
endi
if $data02 != 4 then
print =====data02=$data02
goto loop3
endi
sql insert into t1 values(1648791223000,1,2,3,1.0);
sql insert into t1 values(1648791223001,1,2,3,1.0);
sql insert into t1 values(1648791223002,3,2,3,1.0);
sql insert into t1 values(1648791223003,3,2,3,1.0);
$loop_count = 0
loop4:
sleep 200
sql select * from streamt order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $rows != 2 then
print =====rows=$rows
goto loop4
endi
sleep 200
sql delete from t1 where ts >= 1648791223000 and ts <= 1648791223003;
$loop_count = 0
loop5:
sleep 200
sql select * from streamt order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $data01 != 2 then
print =====data01=$data01
goto loop5
endi
if $data02 != 4 then
print =====data02=$data02
goto loop5
endi
sql insert into t1 values(1648791213000,1,1,1,1.0);
sql insert into t1 values(1648791213005,2,2,2,2.0);
sql insert into t1 values(1648791213006,3,3,3,3.0);
sql insert into t1 values(1648791213007,4,4,4,4.0);
sql insert into t1 values(1648791223000,1,1,1,1.0);
sql insert into t1 values(1648791223001,2,2,2,2.0);
sql insert into t1 values(1648791223002,3,3,3,3.0);
sql insert into t1 values(1648791223003,4,4,4,4.0);
sql insert into t1 values(1648791233000,1,1,1,1.0);
sql insert into t1 values(1648791233001,2,2,2,2.0);
sql insert into t1 values(1648791233008,3,3,3,3.0);
sql insert into t1 values(1648791233009,4,4,4,4.0);
sql delete from t1 where ts >= 1648791213001 and ts <= 1648791233005;
$loop_count = 0
loop6:
sleep 200
sql select * from streamt order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $data01 != 1 then
print =====data01=$data01
goto loop6
endi
if $data02 != 1 then
print =====data02=$data02
goto loop6
endi
if $data11 != 2 then
print =====data11=$data11
goto loop6
endi
if $data12 != 4 then
print =====data12=$data12
goto loop6
endi
sql drop stream if exists streams2;
sql drop database if exists test2;
sql create database test2 vgroups 4;
sql use test2;
sql create stable st(ts timestamp, a int, b int, c int, d double) tags(ta int,tb int,tc int);
sql create table t1 using st tags(1,1,1);
sql create table t2 using st tags(2,2,2);
sql create stream streams2 trigger at_once into test.streamt2 as select _wstart c1, count(*) c2, max(a) c3 from st interval(10s);
sql insert into t1 values(1648791213000,NULL,NULL,NULL,NULL);
sql insert into t2 values(1648791213000,NULL,NULL,NULL,NULL);
$loop_count = 0
loop7:
sleep 200
sql select * from test.streamt2 order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $rows != 1 then
print =====rows=$rows
goto loop7
endi
sleep 200
sql delete from t1 where ts = 1648791213000;
$loop_count = 0
loop8:
sleep 200
sql select * from test.streamt2 order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $data01 != 1 then
print =====data01=$data01
goto loop8
endi
if $data02 != NULL then
print =====data02=$data02
goto loop8
endi
sql insert into t1 values(1648791223000,1,2,3,1.0);
sql insert into t1 values(1648791223001,1,2,3,1.0);
sql insert into t1 values(1648791223002,3,2,3,1.0);
sql insert into t1 values(1648791223003,3,2,3,1.0);
sql insert into t2 values(1648791223000,1,2,3,1.0);
sql insert into t2 values(1648791223001,1,2,3,1.0);
sql insert into t2 values(1648791223002,3,2,3,1.0);
sql insert into t2 values(1648791223003,3,2,3,1.0);
sleep 200
sql delete from t2 where ts >= 1648791223000 and ts <= 1648791223001;
$loop_count = 0
loop11:
sleep 200
sql select * from test.streamt2 order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $data01 != 1 then
print =====data01=$data01
goto loop11
endi
if $data02 != NULL then
print =====data02=$data02
goto loop11
endi
if $data11 != 6 then
print =====data11=$data11
goto loop11
endi
if $data12 != 3 then
print =====data12=$data12
goto loop11
endi
sleep 200
sql delete from st where ts >= 1648791223000 and ts <= 1648791223003;
$loop_count = 0
loop12:
sleep 200
sql select * from test.streamt2 order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $rows != 1 then
print =====rows=$rows
goto loop12
endi
if $data01 != 1 then
print =====data01=$data01
goto loop12
endi
if $data02 != NULL then
print =====data02=$data02
goto loop12
endi
sql insert into t1 values(1648791213004,3,2,3,1.0);
sql insert into t1 values(1648791213005,3,2,3,1.0);
sql insert into t1 values(1648791213006,3,2,3,1.0);
sql insert into t1 values(1648791223004,1,2,3,1.0);
sql insert into t2 values(1648791213004,3,2,3,1.0);
sql insert into t2 values(1648791213005,3,2,3,1.0);
sql insert into t2 values(1648791213006,3,2,3,1.0);
sql insert into t2 values(1648791223004,1,2,3,1.0);
sleep 200
sql delete from t2 where ts >= 1648791213004 and ts <= 1648791213006;
$loop_count = 0
loop13:
sleep 200
sql select * from test.streamt2 order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $rows != 2 then
print =====rows=$rows
goto loop13
endi
if $data01 != 4 then
print =====data01=$data01
goto loop13
endi
if $data02 != 3 then
print =====data02=$data02
goto loop13
endi
if $data11 != 2 then
print =====data11=$data11
goto loop13
endi
if $data12 != 1 then
print =====data12=$data12
goto loop13
endi
sql insert into t1 values(1648791223005,1,2,3,1.0);
sql insert into t1 values(1648791223006,1,2,3,1.0);
sql insert into t2 values(1648791223005,1,2,3,1.0);
sql insert into t2 values(1648791223006,1,2,3,1.0);
sql insert into t1 values(1648791233005,4,2,3,1.0);
sql insert into t1 values(1648791233006,2,2,3,1.0);
sql insert into t2 values(1648791233005,5,2,3,1.0);
sql insert into t2 values(1648791233006,3,2,3,1.0);
sleep 200
sql delete from st where ts >= 1648791213001 and ts <= 1648791233005;
$loop_count = 0
loop14:
sleep 200
sql select * from test.streamt2 order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $rows != 2 then
print =====rows=$rows
goto loop14
endi
if $data01 != 1 then
print =====data01=$data01
goto loop14
endi
if $data02 != NULL then
print =====data02=$data02
goto loop14
endi
if $data11 != 2 then
print =====data11=$data11
goto loop14
endi
if $data12 != 3 then
print =====data12=$data12
goto loop14
endi
$loop_all = $loop_all + 1
print ============loop_all=$loop_all
system sh/stop_dnodes.sh
#goto looptest
\ No newline at end of file
tests/script/tsim/stream/deleteSession.sim
0 → 100644
浏览文件 @
4cdaafe6
此差异已折叠。
点击以展开。
tests/script/tsim/stream/deleteState.sim
0 → 100644
浏览文件 @
4cdaafe6
$loop_all = 0
looptest:
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sleep 200
sql connect
sql drop stream if exists streams0;
sql drop stream if exists streams1;
sql drop stream if exists streams2;
sql drop stream if exists streams3;
sql drop stream if exists streams4;
sql drop database if exists test;
sql create database test vgroups 1;
sql use test;
sql create table t1(ts timestamp, a int, b int , c int, d double);
sql create stream streams0 trigger at_once into streamt as select _wstart c1, count(*) c2, max(b) c3 from t1 state_window(a);
sql insert into t1 values(1648791213000,NULL,NULL,NULL,NULL);
sleep 200
sql delete from t1 where ts = 1648791213000;
$loop_count = 0
loop0:
sleep 200
sql select * from streamt order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $rows != 0 then
print =====rows=$rows
goto loop0
endi
sql insert into t1 values(1648791213000,NULL,NULL,NULL,NULL);
$loop_count = 0
loop1:
sleep 200
sql select * from streamt order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $data01 != 1 then
print =====data01=$data01
goto loop1
endi
if $data02 != NULL then
print =====data02=$data02
goto loop1
endi
sql insert into t1 values(1648791213000,1,1,1,1.0);
sql insert into t1 values(1648791213001,1,2,2,2.0);
sql insert into t1 values(1648791213002,1,3,3,3.0);
sql insert into t1 values(1648791213003,1,4,4,4.0);
sleep 200
sql delete from t1 where ts >= 1648791213001 and ts <= 1648791213002;
$loop_count = 0
loop3:
sleep 200
sql select * from streamt order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $data01 != 2 then
print =====data01=$data01
goto loop3
endi
if $data02 != 4 then
print =====data02=$data02
goto loop3
endi
sql insert into t1 values(1648791223000,2,2,3,1.0);
sql insert into t1 values(1648791223001,2,2,3,1.0);
sql insert into t1 values(1648791223002,2,2,3,1.0);
sql insert into t1 values(1648791223003,2,2,3,1.0);
$loop_count = 0
loop4:
sleep 200
sql select * from streamt order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $rows != 2 then
print =====rows=$rows
goto loop4
endi
sleep 200
sql delete from t1 where ts >= 1648791223000 and ts <= 1648791223003;
$loop_count = 0
loop5:
sleep 200
sql select * from streamt order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $data01 != 2 then
print =====data01=$data01
goto loop5
endi
if $data02 != 4 then
print =====data02=$data02
goto loop5
endi
sql insert into t1 values(1648791213000,1,1,1,1.0);
sql insert into t1 values(1648791213005,1,2,2,2.0);
sql insert into t1 values(1648791213006,1,3,3,3.0);
sql insert into t1 values(1648791213007,1,4,4,4.0);
sql insert into t1 values(1648791223000,2,1,1,1.0);
sql insert into t1 values(1648791223001,2,2,2,2.0);
sql insert into t1 values(1648791223002,2,3,3,3.0);
sql insert into t1 values(1648791223003,2,4,4,4.0);
sql insert into t1 values(1648791233000,3,1,1,1.0);
sql insert into t1 values(1648791233001,3,2,2,2.0);
sql insert into t1 values(1648791233008,3,3,3,3.0);
sql insert into t1 values(1648791233009,3,4,4,4.0);
sql delete from t1 where ts >= 1648791213001 and ts <= 1648791233005;
$loop_count = 0
loop6:
sleep 200
sql select * from streamt order by c1, c2, c3;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
if $rows != 2 then
print =====rows=$rows
goto loop6
endi
if $data01 != 1 then
print =====data01=$data01
goto loop6
endi
if $data02 != 1 then
print =====data02=$data02
goto loop6
endi
if $data11 != 2 then
print =====data11=$data11
goto loop6
endi
if $data12 != 4 then
print =====data12=$data12
goto loop6
endi
$loop_all = $loop_all + 1
print ============loop_all=$loop_all
system sh/stop_dnodes.sh
#goto looptest
\ No newline at end of file
tests/script/tsim/stream/partitionbyColumn
0
.sim
→
tests/script/tsim/stream/partitionbyColumn
Interval
.sim
浏览文件 @
4cdaafe6
文件已移动
tests/script/tsim/stream/partitionbyColumn
1
.sim
→
tests/script/tsim/stream/partitionbyColumn
Session
.sim
浏览文件 @
4cdaafe6
文件已移动
tests/script/tsim/stream/partitionbyColumn
2
.sim
→
tests/script/tsim/stream/partitionbyColumn
State
.sim
浏览文件 @
4cdaafe6
文件已移动
tests/system-test/fulltest.sh
浏览文件 @
4cdaafe6
...
...
@@ -333,7 +333,7 @@ python3 ./test.py -f 7-tmq/stbTagFilter-1ctb.py
python3 ./test.py
-f
7-tmq/dataFromTsdbNWal.py
python3 ./test.py
-f
7-tmq/dataFromTsdbNWal-multiCtb.py
python3 ./test.py
-f
7-tmq/tmq_taosx.py
#
python3 ./test.py -f 7-tmq/stbTagFilter-multiCtb.py
python3 ./test.py
-f
7-tmq/stbTagFilter-multiCtb.py
#------------querPolicy 2-----------
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录