Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e0b3e97d
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看板
提交
e0b3e97d
编写于
5月 16, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of
https://github.com/taosdata/TDengine
into feature/data_format
上级
6e3a0bb7
4adba6ff
变更
91
展开全部
显示空白变更内容
内联
并排
Showing
91 changed file
with
5584 addition
and
1206 deletion
+5584
-1206
include/common/taosdef.h
include/common/taosdef.h
+2
-1
include/common/tmsg.h
include/common/tmsg.h
+45
-118
include/common/ttime.h
include/common/ttime.h
+8
-7
include/libs/function/function.h
include/libs/function/function.h
+1
-1
include/libs/function/tudf.h
include/libs/function/tudf.h
+18
-16
include/libs/qcom/query.h
include/libs/qcom/query.h
+71
-48
include/libs/stream/tstream.h
include/libs/stream/tstream.h
+94
-8
include/os/osAtomic.h
include/os/osAtomic.h
+45
-45
include/util/taoserror.h
include/util/taoserror.h
+5
-1
include/util/tlog.h
include/util/tlog.h
+1
-0
packaging/release.sh
packaging/release.sh
+0
-1
packaging/tools/install.sh
packaging/tools/install.sh
+0
-6
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+3
-3
source/client/src/clientSml.c
source/client/src/clientSml.c
+146
-132
source/client/test/smlTest.cpp
source/client/test/smlTest.cpp
+102
-78
source/common/src/tglobal.c
source/common/src/tglobal.c
+2
-0
source/common/src/tmsg.c
source/common/src/tmsg.c
+75
-22
source/dnode/mnode/impl/src/mndDef.c
source/dnode/mnode/impl/src/mndDef.c
+141
-141
source/dnode/mnode/impl/src/mndScheduler.c
source/dnode/mnode/impl/src/mndScheduler.c
+5
-0
source/dnode/mnode/impl/src/mndSma.c
source/dnode/mnode/impl/src/mndSma.c
+53
-21
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+4
-0
source/dnode/mnode/impl/test/trans/trans2.cpp
source/dnode/mnode/impl/test/trans/trans2.cpp
+1
-1
source/dnode/vnode/CMakeLists.txt
source/dnode/vnode/CMakeLists.txt
+11
-2
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+3
-0
source/dnode/vnode/src/inc/meta.h
source/dnode/vnode/src/inc/meta.h
+7
-1
source/dnode/vnode/src/inc/sma.h
source/dnode/vnode/src/inc/sma.h
+225
-0
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+2
-78
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+60
-20
source/dnode/vnode/src/meta/metaEntry.c
source/dnode/vnode/src/meta/metaEntry.c
+5
-1
source/dnode/vnode/src/meta/metaIdx.c
source/dnode/vnode/src/meta/metaIdx.c
+0
-31
source/dnode/vnode/src/meta/metaOpen.c
source/dnode/vnode/src/meta/metaOpen.c
+31
-2
source/dnode/vnode/src/meta/metaSma.c
source/dnode/vnode/src/meta/metaSma.c
+208
-0
source/dnode/vnode/src/sma/sma.c
source/dnode/vnode/src/sma/sma.c
+8
-25
source/dnode/vnode/src/sma/smaEnv.c
source/dnode/vnode/src/sma/smaEnv.c
+463
-0
source/dnode/vnode/src/sma/smaOpen.c
source/dnode/vnode/src/sma/smaOpen.c
+137
-0
source/dnode/vnode/src/sma/smaRollup.c
source/dnode/vnode/src/sma/smaRollup.c
+484
-0
source/dnode/vnode/src/sma/smaTDBImpl.c
source/dnode/vnode/src/sma/smaTDBImpl.c
+128
-0
source/dnode/vnode/src/sma/smaTimeRange.c
source/dnode/vnode/src/sma/smaTimeRange.c
+1103
-0
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+89
-1
source/dnode/vnode/src/tsdb/tsdbCommit2.c
source/dnode/vnode/src/tsdb/tsdbCommit2.c
+2
-0
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+8
-8
source/dnode/vnode/src/tsdb/tsdbFile.c
source/dnode/vnode/src/tsdb/tsdbFile.c
+1
-9
source/dnode/vnode/src/tsdb/tsdbOpen.c
source/dnode/vnode/src/tsdb/tsdbOpen.c
+22
-101
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+0
-12
source/dnode/vnode/src/vnd/vnodeCommit.c
source/dnode/vnode/src/vnd/vnodeCommit.c
+1
-1
source/dnode/vnode/src/vnd/vnodeOpen.c
source/dnode/vnode/src/vnd/vnodeOpen.c
+14
-26
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+39
-10
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+1
-1
source/libs/executor/src/executorMain.c
source/libs/executor/src/executorMain.c
+5
-3
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+8
-9
source/libs/executor/src/groupoperator.c
source/libs/executor/src/groupoperator.c
+1
-1
source/libs/executor/src/indexoperator.c
source/libs/executor/src/indexoperator.c
+4
-0
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+12
-8
source/libs/executor/test/index_executor_tests.cpp
source/libs/executor/test/index_executor_tests.cpp
+2
-2
source/libs/function/inc/udfc.h
source/libs/function/inc/udfc.h
+1
-1
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+162
-45
source/libs/function/test/runUdf.c
source/libs/function/test/runUdf.c
+3
-3
source/libs/index/inc/indexComm.h
source/libs/index/inc/indexComm.h
+2
-0
source/libs/index/inc/indexInt.h
source/libs/index/inc/indexInt.h
+6
-3
source/libs/index/src/index.c
source/libs/index/src/index.c
+72
-20
source/libs/index/src/indexCache.c
source/libs/index/src/indexCache.c
+3
-0
source/libs/index/src/indexComm.c
source/libs/index/src/indexComm.c
+110
-4
source/libs/index/src/indexFstUtil.c
source/libs/index/src/indexFstUtil.c
+4
-1
source/libs/index/src/indexTfile.c
source/libs/index/src/indexTfile.c
+10
-3
source/libs/index/test/jsonUT.cc
source/libs/index/test/jsonUT.cc
+20
-0
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+162
-42
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+17
-0
source/libs/parser/src/parAuthenticator.c
source/libs/parser/src/parAuthenticator.c
+11
-2
source/libs/parser/src/parCalcConst.c
source/libs/parser/src/parCalcConst.c
+2
-2
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+3
-0
source/libs/parser/src/parInsertData.c
source/libs/parser/src/parInsertData.c
+3
-3
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+45
-8
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+4
-0
source/libs/parser/test/parSelectTest.cpp
source/libs/parser/test/parSelectTest.cpp
+5
-3
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+7
-3
source/libs/planner/src/planPhysiCreater.c
source/libs/planner/src/planPhysiCreater.c
+18
-0
source/libs/planner/test/planJoinTest.cpp
source/libs/planner/test/planJoinTest.cpp
+10
-4
source/libs/planner/test/planSubqueryTest.cpp
source/libs/planner/test/planSubqueryTest.cpp
+6
-2
source/libs/planner/test/planTestMain.cpp
source/libs/planner/test/planTestMain.cpp
+31
-1
source/libs/planner/test/planTestUtil.cpp
source/libs/planner/test/planTestUtil.cpp
+1
-0
source/libs/planner/test/planTestUtil.h
source/libs/planner/test/planTestUtil.h
+2
-0
source/libs/scalar/inc/sclInt.h
source/libs/scalar/inc/sclInt.h
+0
-2
source/libs/scalar/src/scalar.c
source/libs/scalar/src/scalar.c
+5
-45
source/libs/stream/src/tstream.c
source/libs/stream/src/tstream.c
+401
-4
source/libs/tdb/CMakeLists.txt
source/libs/tdb/CMakeLists.txt
+1
-1
source/util/src/terror.c
source/util/src/terror.c
+2
-1
source/util/src/tlog.c
source/util/src/tlog.c
+2
-0
tests/script/tsim/tstream/basic1.sim
tests/script/tsim/tstream/basic1.sim
+1
-1
tests/system-test/0-others/udfTest.py
tests/system-test/0-others/udfTest.py
+544
-0
tests/system-test/fulltest.sh
tests/system-test/fulltest.sh
+1
-0
tools/shell/src/shellEngine.c
tools/shell/src/shellEngine.c
+1
-0
未找到文件。
include/common/taosdef.h
浏览文件 @
e0b3e97d
...
...
@@ -37,7 +37,8 @@ typedef enum {
TSDB_STREAM_TABLE
=
4
,
// table created from stream computing
TSDB_TEMP_TABLE
=
5
,
// temp table created by nest query
TSDB_SYSTEM_TABLE
=
6
,
TSDB_TABLE_MAX
=
7
TSDB_TSMA_TABLE
=
7
,
// time-range-wise sma
TSDB_TABLE_MAX
=
8
}
ETableType
;
typedef
enum
{
...
...
include/common/tmsg.h
浏览文件 @
e0b3e97d
...
...
@@ -2175,14 +2175,11 @@ typedef struct {
int64_t
interval
;
int64_t
offset
;
// use unit by precision of DB
int64_t
sliding
;
c
har
*
expr
;
// sma expression
c
har
*
tagsFilter
;
c
onst
char
*
expr
;
// sma expression
c
onst
char
*
tagsFilter
;
}
STSma
;
// Time-range-wise SMA
typedef
struct
{
int64_t
ver
;
// use a general definition
STSma
tSma
;
}
SVCreateTSmaReq
;
typedef
STSma
SVCreateTSmaReq
;
typedef
struct
{
int8_t
type
;
// 0 status report, 1 update data
...
...
@@ -2191,7 +2188,6 @@ typedef struct {
}
STSmaMsg
;
typedef
struct
{
int64_t
ver
;
// use a general definition
int64_t
indexUid
;
char
indexName
[
TSDB_INDEX_NAME_LEN
];
}
SVDropTSmaReq
;
...
...
@@ -2200,27 +2196,20 @@ typedef struct {
int
tmp
;
// TODO: to avoid compile error
}
SVCreateTSmaRsp
,
SVDropTSmaRsp
;
#if 0
int32_t tSerializeSVCreateTSmaReq(void** buf, SVCreateTSmaReq* pReq);
void* tDeserializeSVCreateTSmaReq(void* buf, SVCreateTSmaReq* pReq);
int32_t tSerializeSVDropTSmaReq(void** buf, SVDropTSmaReq* pReq);
void* tDeserializeSVDropTSmaReq(void* buf, SVDropTSmaReq* pReq);
#endif
// RSma: Rollup SMA
typedef
struct
{
int64_t
interval
;
int32_t
retention
;
// unit: day
uint16_t
days
;
// unit: day
int8_t
intervalUnit
;
}
SSmaParams
;
int32_t
tEncodeSVCreateTSmaReq
(
SEncoder
*
pCoder
,
const
SVCreateTSmaReq
*
pReq
);
int32_t
tDecodeSVCreateTSmaReq
(
SDecoder
*
pCoder
,
SVCreateTSmaReq
*
pReq
);
int32_t
tEncodeSVDropTSmaReq
(
SEncoder
*
pCoder
,
const
SVDropTSmaReq
*
pReq
);
int32_t
tDecodeSVDropTSmaReq
(
SDecoder
*
pCoder
,
SVDropTSmaReq
*
pReq
);
typedef
struct
{
STSma
tsma
;
float
xFilesFactor
;
SArray
*
smaParams
;
// SSmaParams
}
SRSma
;
typedef
struct
{
uint32_t
number
;
int32_t
number
;
STSma
*
tSma
;
}
STSmaWrapper
;
...
...
@@ -2248,96 +2237,26 @@ static FORCE_INLINE void* tdFreeTSmaWrapper(STSmaWrapper* pSW) {
return
NULL
;
}
static
FORCE_INLINE
int32_t
tEncodeTSma
(
void
**
buf
,
const
STSma
*
pSma
)
{
int32_t
tlen
=
0
;
int32_t
tEncodeSVCreateTSmaReq
(
SEncoder
*
pCoder
,
const
SVCreateTSmaReq
*
pReq
);
int32_t
tDecodeSVCreateTSmaReq
(
SDecoder
*
pCoder
,
SVCreateTSmaReq
*
pReq
)
;
tlen
+=
taosEncodeFixedI8
(
buf
,
pSma
->
version
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pSma
->
intervalUnit
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pSma
->
slidingUnit
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pSma
->
timezoneInt
);
tlen
+=
taosEncodeString
(
buf
,
pSma
->
indexName
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pSma
->
exprLen
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pSma
->
tagsFilterLen
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSma
->
indexUid
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSma
->
tableUid
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSma
->
interval
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSma
->
offset
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pSma
->
sliding
);
if
(
pSma
->
exprLen
>
0
)
{
tlen
+=
taosEncodeString
(
buf
,
pSma
->
expr
);
}
int32_t
tEncodeTSma
(
SEncoder
*
pCoder
,
const
STSma
*
pSma
);
int32_t
tDecodeTSma
(
SDecoder
*
pCoder
,
STSma
*
pSma
);
if
(
pSma
->
tagsFilterLen
>
0
)
{
tlen
+=
taosEncodeString
(
buf
,
pSma
->
tagsFilter
);
static
int32_t
tEncodeTSmaWrapper
(
SEncoder
*
pEncoder
,
const
STSmaWrapper
*
pReq
)
{
if
(
tEncodeI32
(
pEncoder
,
pReq
->
number
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pReq
->
number
;
++
i
)
{
tEncodeTSma
(
pEncoder
,
pReq
->
tSma
+
i
);
}
return
tlen
;
}
static
FORCE_INLINE
int32_t
tEncodeTSmaWrapper
(
void
**
buf
,
const
STSmaWrapper
*
pSW
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedU32
(
buf
,
pSW
->
number
);
for
(
uint32_t
i
=
0
;
i
<
pSW
->
number
;
++
i
)
{
tlen
+=
tEncodeTSma
(
buf
,
pSW
->
tSma
+
i
);
}
return
tlen
;
}
static
FORCE_INLINE
void
*
tDecodeTSma
(
void
*
buf
,
STSma
*
pSma
)
{
buf
=
taosDecodeFixedI8
(
buf
,
&
pSma
->
version
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pSma
->
intervalUnit
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pSma
->
slidingUnit
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pSma
->
timezoneInt
);
buf
=
taosDecodeStringTo
(
buf
,
pSma
->
indexName
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pSma
->
exprLen
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pSma
->
tagsFilterLen
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
indexUid
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
tableUid
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
interval
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
offset
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pSma
->
sliding
);
if
(
pSma
->
exprLen
>
0
)
{
if
((
buf
=
taosDecodeString
(
buf
,
&
pSma
->
expr
))
==
NULL
)
{
tdDestroyTSma
(
pSma
);
return
NULL
;
}
}
else
{
pSma
->
expr
=
NULL
;
}
if
(
pSma
->
tagsFilterLen
>
0
)
{
if
((
buf
=
taosDecodeString
(
buf
,
&
pSma
->
tagsFilter
))
==
NULL
)
{
tdDestroyTSma
(
pSma
);
return
NULL
;
}
}
else
{
pSma
->
tagsFilter
=
NULL
;
}
return
buf
;
return
0
;
}
static
FORCE_INLINE
void
*
tDecodeTSmaWrapper
(
void
*
buf
,
STSmaWrapper
*
pSW
)
{
buf
=
taosDecodeFixedU32
(
buf
,
&
pSW
->
number
);
pSW
->
tSma
=
(
STSma
*
)
taosMemoryCalloc
(
pSW
->
number
,
sizeof
(
STSma
));
if
(
pSW
->
tSma
==
NULL
)
{
return
NULL
;
}
for
(
uint32_t
i
=
0
;
i
<
pSW
->
number
;
++
i
)
{
if
((
buf
=
tDecodeTSma
(
buf
,
pSW
->
tSma
+
i
))
==
NULL
)
{
for
(
uint32_t
j
=
i
;
j
>=
0
;
--
i
)
{
tdDestroyTSma
(
pSW
->
tSma
+
j
);
}
taosMemoryFree
(
pSW
->
tSma
);
return
NULL
;
}
static
int32_t
tDecodeTSmaWrapper
(
SDecoder
*
pDecoder
,
STSmaWrapper
*
pReq
)
{
if
(
tDecodeI32
(
pDecoder
,
&
pReq
->
number
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pReq
->
number
;
++
i
)
{
tDecodeTSma
(
pDecoder
,
pReq
->
tSma
+
i
);
}
return
buf
;
return
0
;
}
typedef
struct
{
...
...
@@ -2577,6 +2496,14 @@ static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
taosArrayDestroyEx
(
pRsp
->
topics
,
(
void
(
*
)(
void
*
))
tDeleteSMqSubTopicEp
);
}
typedef
struct
{
void
*
data
;
}
SStreamDispatchReq
;
typedef
struct
{
int8_t
status
;
}
SStreamDispatchRsp
;
#define TD_AUTO_CREATE_TABLE 0x1
typedef
struct
{
int64_t
suid
;
...
...
include/common/ttime.h
浏览文件 @
e0b3e97d
...
...
@@ -59,10 +59,11 @@ static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) {
* precision == TSDB_TIME_PRECISION_NANO, it returns timestamp in nanosecond.
*/
static
FORCE_INLINE
int64_t
taosGetTimestampToday
(
int32_t
precision
)
{
int64_t
factor
=
(
precision
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
1000000
:
1000000000
;
int64_t
factor
=
(
precision
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
?
1000000
:
1000000000
;
time_t
t
=
taosTime
(
NULL
);
struct
tm
*
tm
=
taosLocalTime
(
&
t
,
NULL
);
struct
tm
*
tm
=
taosLocalTime
(
&
t
,
NULL
);
tm
->
tm_hour
=
0
;
tm
->
tm_min
=
0
;
tm
->
tm_sec
=
0
;
...
...
@@ -83,9 +84,9 @@ char getPrecisionUnit(int32_t precision);
int64_t
convertTimePrecision
(
int64_t
time
,
int32_t
fromPrecision
,
int32_t
toPrecision
);
int64_t
convertTimeFromPrecisionToUnit
(
int64_t
time
,
int32_t
fromPrecision
,
char
toUnit
);
int32_t
convertStringToTimestamp
(
int16_t
type
,
char
*
inputData
,
int64_t
timePrec
,
int64_t
*
timeVal
);
int32_t
convertStringToTimestamp
(
int16_t
type
,
char
*
inputData
,
int64_t
timePrec
,
int64_t
*
timeVal
);
void
taosFormatUtcTime
(
char
*
buf
,
int32_t
bufLen
,
int64_t
time
,
int32_t
precision
);
void
taosFormatUtcTime
(
char
*
buf
,
int32_t
bufLen
,
int64_t
time
,
int32_t
precision
);
#ifdef __cplusplus
}
...
...
include/libs/function/function.h
浏览文件 @
e0b3e97d
...
...
@@ -309,7 +309,7 @@ void qAddUdfInfo(uint64_t id, struct SUdfInfo* pUdfInfo);
void
qRemoveUdfInfo
(
uint64_t
id
,
struct
SUdfInfo
*
pUdfInfo
);
/**
* create udfd proxy, called once in process that call
setupUdf/callUdfxxx/t
eardownUdf
* create udfd proxy, called once in process that call
doSetupUdf/callUdfxxx/doT
eardownUdf
* @return error code
*/
int32_t
udfcOpen
();
...
...
include/libs/function/tudf.h
浏览文件 @
e0b3e97d
...
...
@@ -39,16 +39,6 @@ extern "C" {
//======================================================================================
//begin API to taosd and qworker
typedef
void
*
UdfcFuncHandle
;
/**
* setup udf
* @param udf, in
* @param handle, out
* @return error code
*/
int32_t
setupUdf
(
char
udfName
[],
UdfcFuncHandle
*
handle
);
typedef
struct
SUdfColumnMeta
{
int16_t
type
;
int32_t
bytes
;
...
...
@@ -95,32 +85,44 @@ typedef struct SUdfInterBuf {
char
*
buf
;
int8_t
numOfResult
;
//zero or one
}
SUdfInterBuf
;
typedef
void
*
UdfcFuncHandle
;
/**
* setup udf
* @param udf, in
* @param funcHandle, out
* @return error code
*/
int32_t
doSetupUdf
(
char
udfName
[],
UdfcFuncHandle
*
funcHandle
);
// output: interBuf
int32_t
c
allUdfAggInit
(
UdfcFuncHandle
handle
,
SUdfInterBuf
*
interBuf
);
int32_t
doC
allUdfAggInit
(
UdfcFuncHandle
handle
,
SUdfInterBuf
*
interBuf
);
// input: block, state
// output: newState
int32_t
c
allUdfAggProcess
(
UdfcFuncHandle
handle
,
SSDataBlock
*
block
,
SUdfInterBuf
*
state
,
SUdfInterBuf
*
newState
);
int32_t
doC
allUdfAggProcess
(
UdfcFuncHandle
handle
,
SSDataBlock
*
block
,
SUdfInterBuf
*
state
,
SUdfInterBuf
*
newState
);
// input: interBuf
// output: resultData
int32_t
c
allUdfAggFinalize
(
UdfcFuncHandle
handle
,
SUdfInterBuf
*
interBuf
,
SUdfInterBuf
*
resultData
);
int32_t
doC
allUdfAggFinalize
(
UdfcFuncHandle
handle
,
SUdfInterBuf
*
interBuf
,
SUdfInterBuf
*
resultData
);
// input: interbuf1, interbuf2
// output: resultBuf
int32_t
c
allUdfAggMerge
(
UdfcFuncHandle
handle
,
SUdfInterBuf
*
interBuf1
,
SUdfInterBuf
*
interBuf2
,
SUdfInterBuf
*
resultBuf
);
int32_t
doC
allUdfAggMerge
(
UdfcFuncHandle
handle
,
SUdfInterBuf
*
interBuf1
,
SUdfInterBuf
*
interBuf2
,
SUdfInterBuf
*
resultBuf
);
// input: block
// output: resultData
int32_t
c
allUdfScalarFunc
(
UdfcFuncHandle
handle
,
SScalarParam
*
input
,
int32_t
numOfCols
,
SScalarParam
*
output
);
int32_t
doC
allUdfScalarFunc
(
UdfcFuncHandle
handle
,
SScalarParam
*
input
,
int32_t
numOfCols
,
SScalarParam
*
output
);
/**
* tearn down udf
* @param handle
* @return
*/
int32_t
t
eardownUdf
(
UdfcFuncHandle
handle
);
int32_t
doT
eardownUdf
(
UdfcFuncHandle
handle
);
bool
udfAggGetEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
udfAggInit
(
struct
SqlFunctionCtx
*
pCtx
,
struct
SResultRowEntryInfo
*
pResultCellInfo
);
int32_t
udfAggProcess
(
struct
SqlFunctionCtx
*
pCtx
);
int32_t
udfAggFinalize
(
struct
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
int32_t
callUdfScalarFunc
(
char
*
udfName
,
SScalarParam
*
input
,
int32_t
numOfCols
,
SScalarParam
*
output
);
int32_t
teardownUdfs
();
// end API to taosd and qworker
//=============================================================================================================================
// begin API to UDF writer.
...
...
include/libs/qcom/query.h
浏览文件 @
e0b3e97d
...
...
@@ -51,14 +51,12 @@ typedef struct STableComInfo {
}
STableComInfo
;
typedef
struct
SIndexMeta
{
#ifdef WINDOWS
size_t
avoidCompilationErrors
;
#endif
}
SIndexMeta
;
/*
* ASSERT(sizeof(SCTableMeta) == 24)
* ASSERT(tableType == TSDB_CHILD_TABLE)
...
...
@@ -95,7 +93,7 @@ typedef struct SDBVgInfo {
int32_t
vgVersion
;
int8_t
hashMethod
;
int32_t
numOfTable
;
// DB's table num, unit is TSDB_TABLE_NUM_UNIT
SHashObj
*
vgHash
;
//
key:vgId, value:SVgroupInfo
SHashObj
*
vgHash
;
//
key:vgId, value:SVgroupInfo
}
SDBVgInfo
;
typedef
struct
SUseDbOutput
{
...
...
@@ -172,7 +170,7 @@ const SSchema* tGetTbnameColumnSchema();
bool
tIsValidSchema
(
struct
SSchema
*
pSchema
,
int32_t
numOfCols
,
int32_t
numOfTags
);
int32_t
queryCreateTableMetaFromMsg
(
STableMetaRsp
*
msg
,
bool
isSuperTable
,
STableMeta
**
pMeta
);
char
*
jobTaskStatusStr
(
int32_t
status
);
char
*
jobTaskStatusStr
(
int32_t
status
);
SSchema
createSchema
(
int8_t
type
,
int32_t
bytes
,
col_id_t
colId
,
const
char
*
name
);
...
...
@@ -184,62 +182,87 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
#define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE
#define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST)
#define NEED_CLIENT_REFRESH_VG_ERROR(_code) ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID)
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \
((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST)
#define NEED_CLIENT_REFRESH_VG_ERROR(_code) \
((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID)
#define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_TABLE_RECREATED)
#define NEED_CLIENT_HANDLE_ERROR(_code) (NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code))
#define NEED_CLIENT_HANDLE_ERROR(_code) \
(NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || \
NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code))
#define NEED_SCHEDULER_RETRY_ERROR(_code) ((_code) == TSDB_CODE_RPC_REDIRECT || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL)
#define NEED_SCHEDULER_RETRY_ERROR(_code) \
((_code) == TSDB_CODE_RPC_REDIRECT || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL)
#define REQUEST_MAX_TRY_TIMES 5
#define qFatal(...) \
do { \
if (qDebugFlag & DEBUG_FATAL) { \
taosPrintLog("QRY FATAL ", DEBUG_FATAL, qDebugFlag, __VA_ARGS__); \
taosPrintLog("QRY FATAL ", DEBUG_FATAL,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define qError(...) \
do { \
if (qDebugFlag & DEBUG_ERROR) { \
taosPrintLog("QRY ERROR ", DEBUG_ERROR, qDebugFlag, __VA_ARGS__); \
taosPrintLog("QRY ERROR ", DEBUG_ERROR,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define qWarn(...) \
do { \
if (qDebugFlag & DEBUG_WARN) { \
taosPrintLog("QRY WARN ", DEBUG_WARN, qDebugFlag, __VA_ARGS__); \
taosPrintLog("QRY WARN ", DEBUG_WARN,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define qInfo(...) \
do { \
if (qDebugFlag & DEBUG_INFO) { \
taosPrintLog("QRY ", DEBUG_INFO, qDebugFlag, __VA_ARGS__); \
taosPrintLog("QRY ", DEBUG_INFO,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define qDebug(...) \
do { \
if (qDebugFlag & DEBUG_DEBUG) { \
taosPrintLog("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); \
taosPrintLog("QRY ", DEBUG_DEBUG,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define qTrace(...) \
do { \
if (qDebugFlag & DEBUG_TRACE) { \
taosPrintLog("QRY ", DEBUG_TRACE, qDebugFlag, __VA_ARGS__); \
taosPrintLog("QRY ", DEBUG_TRACE,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define qDebugL(...) \
do { \
if (qDebugFlag & DEBUG_DEBUG) { \
taosPrintLongString("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); \
taosPrintLongString("QRY ", DEBUG_DEBUG,
tsLogEmbedded ? 255 :
qDebugFlag, __VA_ARGS__); \
} \
} while (0)
#define QRY_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
#define QRY_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
#define QRY_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
#define QRY_ERR_RET(c) \
do { \
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
return _code; \
} \
} while (0)
#define QRY_RET(c) \
do { \
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
} \
return _code; \
} while (0)
#define QRY_ERR_JRET(c) \
do { \
code = c; \
if (code != TSDB_CODE_SUCCESS) { \
terrno = code; \
goto _return; \
} \
} while (0)
#ifdef __cplusplus
}
...
...
include/libs/stream/tstream.h
浏览文件 @
e0b3e97d
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "tdatablock.h"
#include "tmsg.h"
#include "tmsgcb.h"
...
...
@@ -29,8 +30,23 @@ extern "C" {
typedef
struct
SStreamTask
SStreamTask
;
enum
{
STREAM_TASK_STATUS__RUNNING
=
1
,
STREAM_TASK_STATUS__STOP
,
TASK_STATUS__IDLE
=
1
,
TASK_STATUS__EXECUTING
,
TASK_STATUS__CLOSING
,
};
enum
{
TASK_INPUT_STATUS__NORMAL
=
1
,
TASK_INPUT_STATUS__BLOCKED
,
TASK_INPUT_STATUS__RECOVER
,
TASK_INPUT_STATUS__STOP
,
TASK_INPUT_STATUS__FAILED
,
};
enum
{
TASK_OUTPUT_STATUS__NORMAL
=
1
,
TASK_OUTPUT_STATUS__WAIT
,
TASK_OUTPUT_STATUS__BLOCKED
,
};
enum
{
...
...
@@ -38,10 +54,64 @@ enum {
STREAM_CREATED_BY__SMA
,
};
enum
{
STREAM_INPUT__DATA_SUBMIT
=
1
,
STREAM_INPUT__DATA_BLOCK
,
STREAM_INPUT__CHECKPOINT
,
};
typedef
struct
{
int32_t
nodeId
;
// 0 for snode
SEpSet
epSet
;
}
SStreamTaskEp
;
int8_t
type
;
int32_t
sourceVg
;
int64_t
sourceVer
;
int32_t
*
dataRef
;
SSubmitReq
*
data
;
}
SStreamDataSubmit
;
typedef
struct
{
int8_t
type
;
int32_t
sourceVg
;
int64_t
sourceVer
;
SArray
*
blocks
;
// SArray<SSDataBlock*>
}
SStreamDataBlock
;
typedef
struct
{
int8_t
type
;
}
SStreamCheckpoint
;
static
FORCE_INLINE
SStreamDataSubmit
*
streamDataSubmitNew
(
SSubmitReq
*
pReq
)
{
SStreamDataSubmit
*
pDataSubmit
=
(
SStreamDataSubmit
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SStreamDataSubmit
));
if
(
pDataSubmit
==
NULL
)
return
NULL
;
pDataSubmit
->
data
=
pReq
;
pDataSubmit
->
dataRef
=
(
int32_t
*
)
taosMemoryMalloc
(
sizeof
(
int32_t
));
if
(
pDataSubmit
->
data
==
NULL
)
goto
FAIL
;
*
pDataSubmit
->
dataRef
=
1
;
return
pDataSubmit
;
FAIL:
taosMemoryFree
(
pDataSubmit
);
return
NULL
;
}
static
FORCE_INLINE
void
streamDataSubmitRefInc
(
SStreamDataSubmit
*
pDataSubmit
)
{
//
atomic_add_fetch_32
(
pDataSubmit
->
dataRef
,
1
);
}
static
FORCE_INLINE
void
streamDataSubmitRefDec
(
SStreamDataSubmit
*
pDataSubmit
)
{
int32_t
ref
=
atomic_sub_fetch_32
(
pDataSubmit
->
dataRef
,
1
);
ASSERT
(
ref
>=
0
);
if
(
ref
==
0
)
{
taosMemoryFree
(
pDataSubmit
->
data
);
taosMemoryFree
(
pDataSubmit
->
dataRef
);
}
}
int32_t
streamDataBlockEncode
(
void
**
buf
,
const
SStreamDataBlock
*
pOutput
);
void
*
streamDataBlockDecode
(
const
void
*
buf
,
SStreamDataBlock
*
pInput
);
typedef
struct
{
void
*
inputHandle
;
...
...
@@ -122,9 +192,15 @@ enum {
TASK_SINK__FETCH
,
};
enum
{
TASK_INPUT_TYPE__SUMBIT_BLOCK
=
1
,
TASK_INPUT_TYPE__DATA_BLOCK
,
};
struct
SStreamTask
{
int64_t
streamId
;
int32_t
taskId
;
int8_t
inputType
;
int8_t
status
;
int8_t
sourceType
;
...
...
@@ -155,9 +231,13 @@ struct SStreamTask {
STaskDispatcherShuffle
shuffleDispatcher
;
};
// msg buffer
int32_t
memUsed
;
int8_t
inputStatus
;
int8_t
outputStatus
;
STaosQueue
*
inputQ
;
STaosQall
*
inputQAll
;
STaosQueue
*
outputQ
;
STaosQall
*
outputQAll
;
// application storage
void
*
ahandle
;
...
...
@@ -199,10 +279,16 @@ typedef struct {
SArray
*
res
;
// SArray<SSDataBlock>
}
SStreamSinkReq
;
int32_t
streamEnqueueData
(
SStreamTask
*
pTask
,
const
void
*
input
,
int32_t
inputType
);
int32_t
streamEnqueueDataSubmit
(
SStreamTask
*
pTask
,
SStreamDataSubmit
*
input
);
int32_t
streamEnqueueDataBlk
(
SStreamTask
*
pTask
,
SStreamDataBlock
*
input
);
int32_t
streamDequeueOutput
(
SStreamTask
*
pTask
,
void
**
output
);
int32_t
streamExecTask
(
SStreamTask
*
pTask
,
SMsgCb
*
pMsgCb
,
const
void
*
input
,
int32_t
inputType
,
int32_t
workId
);
int32_t
streamTaskRun
(
SStreamTask
*
pTask
);
int32_t
streamTaskHandleInput
(
SStreamTask
*
pTask
,
void
*
data
);
#ifdef __cplusplus
}
#endif
...
...
include/os/osAtomic.h
浏览文件 @
e0b3e97d
...
...
@@ -23,27 +23,27 @@ extern "C" {
// If the error is in a third-party library, place this header file under the third-party library header file.
// When you want to use this feature, you should find or add the same function in the following section.
#ifndef ALLOW_FORBID_FUNC
#define __atomic_load_n
__ATOMIC_LOAD_N_FUNC_TAOS_FORBID
#define __atomic_store_n
__ATOMIC_STORE_N_FUNC_TAOS_FORBID
#define __atomic_exchange_n
__ATOMIC_EXCHANGE_N_FUNC_TAOS_FORBID
#define __sync_val_compare_and_swap __SYNC_VAL_COMPARE_AND_SWAP_FUNC_TAOS_FORBID
#define __atomic_add_fetch
__ATOMIC_ADD_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_add
__ATOMIC_FETCH_ADD_FUNC_TAOS_FORBID
#define __atomic_sub_fetch
__ATOMIC_SUB_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_sub
__ATOMIC_FETCH_SUB_FUNC_TAOS_FORBID
#define __atomic_and_fetch
__ATOMIC_AND_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_and
__ATOMIC_FETCH_AND_FUNC_TAOS_FORBID
#define __atomic_or_fetch
__ATOMIC_OR_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_or
__ATOMIC_FETCH_OR_FUNC_TAOS_FORBID
#define __atomic_xor_fetch
__ATOMIC_XOR_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_xor
__ATOMIC_FETCH_XOR_FUNC_TAOS_FORBID
#define __atomic_load_n
__ATOMIC_LOAD_N_FUNC_TAOS_FORBID
#define __atomic_store_n
__ATOMIC_STORE_N_FUNC_TAOS_FORBID
#define __atomic_exchange_n
__ATOMIC_EXCHANGE_N_FUNC_TAOS_FORBID
#define __sync_val_compare_and_swap __SYNC_VAL_COMPARE_AND_SWAP_FUNC_TAOS_FORBID
#define __atomic_add_fetch
__ATOMIC_ADD_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_add
__ATOMIC_FETCH_ADD_FUNC_TAOS_FORBID
#define __atomic_sub_fetch
__ATOMIC_SUB_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_sub
__ATOMIC_FETCH_SUB_FUNC_TAOS_FORBID
#define __atomic_and_fetch
__ATOMIC_AND_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_and
__ATOMIC_FETCH_AND_FUNC_TAOS_FORBID
#define __atomic_or_fetch
__ATOMIC_OR_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_or
__ATOMIC_FETCH_OR_FUNC_TAOS_FORBID
#define __atomic_xor_fetch
__ATOMIC_XOR_FETCH_FUNC_TAOS_FORBID
#define __atomic_fetch_xor
__ATOMIC_FETCH_XOR_FUNC_TAOS_FORBID
#endif
int8_t
atomic_load_8
(
int8_t
volatile
*
ptr
);
int16_t
atomic_load_16
(
int16_t
volatile
*
ptr
);
int32_t
atomic_load_32
(
int32_t
volatile
*
ptr
);
int64_t
atomic_load_64
(
int64_t
volatile
*
ptr
);
void
*
atomic_load_ptr
(
void
*
ptr
);
void
*
atomic_load_ptr
(
void
*
ptr
);
void
atomic_store_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
void
atomic_store_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
void
atomic_store_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
...
...
@@ -53,62 +53,62 @@ int8_t atomic_exchange_8(int8_t volatile *ptr, int8_t val);
int16_t
atomic_exchange_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_exchange_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_exchange_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_exchange_ptr
(
void
*
ptr
,
void
*
val
);
void
*
atomic_exchange_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_val_compare_exchange_8
(
int8_t
volatile
*
ptr
,
int8_t
oldval
,
int8_t
newval
);
int16_t
atomic_val_compare_exchange_16
(
int16_t
volatile
*
ptr
,
int16_t
oldval
,
int16_t
newval
);
int32_t
atomic_val_compare_exchange_32
(
int32_t
volatile
*
ptr
,
int32_t
oldval
,
int32_t
newval
);
int64_t
atomic_val_compare_exchange_64
(
int64_t
volatile
*
ptr
,
int64_t
oldval
,
int64_t
newval
);
void
*
atomic_val_compare_exchange_ptr
(
void
*
ptr
,
void
*
oldval
,
void
*
newval
);
void
*
atomic_val_compare_exchange_ptr
(
void
*
ptr
,
void
*
oldval
,
void
*
newval
);
int8_t
atomic_add_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_add_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_add_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_add_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_add_fetch_ptr
(
void
*
ptr
,
void
*
val
);
void
*
atomic_add_fetch_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_fetch_add_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_fetch_add_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_fetch_add_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_fetch_add_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_fetch_add_ptr
(
void
*
ptr
,
void
*
val
);
void
*
atomic_fetch_add_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_sub_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_sub_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_sub_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_sub_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_sub_fetch_ptr
(
void
*
ptr
,
void
*
val
);
void
*
atomic_sub_fetch_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_fetch_sub_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_fetch_sub_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_fetch_sub_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_fetch_sub_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_fetch_sub_ptr
(
void
*
ptr
,
void
*
val
);
void
*
atomic_fetch_sub_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_and_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_and_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_and_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_and_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_and_fetch_ptr
(
void
*
ptr
,
void
*
val
);
void
*
atomic_and_fetch_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_fetch_and_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_fetch_and_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_fetch_and_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_fetch_and_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_fetch_and_ptr
(
void
*
ptr
,
void
*
val
);
void
*
atomic_fetch_and_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_or_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_or_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_or_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_or_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_or_fetch_ptr
(
void
*
ptr
,
void
*
val
);
void
*
atomic_or_fetch_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_fetch_or_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_fetch_or_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_fetch_or_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_fetch_or_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_fetch_or_ptr
(
void
*
ptr
,
void
*
val
);
void
*
atomic_fetch_or_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_xor_fetch_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_xor_fetch_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_xor_fetch_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_xor_fetch_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_xor_fetch_ptr
(
void
*
ptr
,
void
*
val
);
void
*
atomic_xor_fetch_ptr
(
void
*
ptr
,
void
*
val
);
int8_t
atomic_fetch_xor_8
(
int8_t
volatile
*
ptr
,
int8_t
val
);
int16_t
atomic_fetch_xor_16
(
int16_t
volatile
*
ptr
,
int16_t
val
);
int32_t
atomic_fetch_xor_32
(
int32_t
volatile
*
ptr
,
int32_t
val
);
int64_t
atomic_fetch_xor_64
(
int64_t
volatile
*
ptr
,
int64_t
val
);
void
*
atomic_fetch_xor_ptr
(
void
*
ptr
,
void
*
val
);
void
*
atomic_fetch_xor_ptr
(
void
*
ptr
,
void
*
val
);
#ifdef __cplusplus
}
...
...
include/util/taoserror.h
浏览文件 @
e0b3e97d
...
...
@@ -354,7 +354,8 @@ int32_t* taosGetErrno();
#define TSDB_CODE_TDB_TABLE_RECREATED TAOS_DEF_ERROR_CODE(0, 0x061A)
#define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x061B)
#define TSDB_CODE_TDB_NO_SMA_INDEX_IN_META TAOS_DEF_ERROR_CODE(0, 0x061C)
#define TSDB_CODE_TDB_INVALID_SMA_STAT TAOS_DEF_ERROR_CODE(0, 0x062D)
#define TSDB_CODE_TDB_INVALID_SMA_STAT TAOS_DEF_ERROR_CODE(0, 0x061D)
#define TSDB_CODE_TDB_TSMA_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x061E)
// query
#define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700)
...
...
@@ -636,6 +637,8 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_PERMISSION_DENIED TAOS_DEF_ERROR_CODE(0, 0x2644)
#define TSDB_CODE_PAR_INVALID_STREAM_QUERY TAOS_DEF_ERROR_CODE(0, 0x2645)
#define TSDB_CODE_PAR_INVALID_INTERNAL_PK TAOS_DEF_ERROR_CODE(0, 0x2646)
#define TSDB_CODE_PAR_INVALID_TIMELINE_FUNC TAOS_DEF_ERROR_CODE(0, 0x2647)
#define TSDB_CODE_PAR_INVALID_PASSWD TAOS_DEF_ERROR_CODE(0, 0x2648)
//planner
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
...
...
@@ -657,6 +660,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_UDF_LOAD_UDF_FAILURE TAOS_DEF_ERROR_CODE(0, 0x2905)
#define TSDB_CODE_UDF_INVALID_STATE TAOS_DEF_ERROR_CODE(0, 0x2906)
#define TSDB_CODE_UDF_INVALID_INPUT TAOS_DEF_ERROR_CODE(0, 0x2907)
#define TSDB_CODE_UDF_NO_FUNC_HANDLE TAOS_DEF_ERROR_CODE(0, 0x2908)
#define TSDB_CODE_SML_INVALID_PROTOCOL_TYPE TAOS_DEF_ERROR_CODE(0, 0x3000)
#define TSDB_CODE_SML_INVALID_PRECISION_TYPE TAOS_DEF_ERROR_CODE(0, 0x3001)
...
...
include/util/tlog.h
浏览文件 @
e0b3e97d
...
...
@@ -61,6 +61,7 @@ extern int32_t tqDebugFlag;
extern
int32_t
fsDebugFlag
;
extern
int32_t
metaDebugFlag
;
extern
int32_t
fnDebugFlag
;
extern
int32_t
smaDebugFlag
;
int32_t
taosInitLog
(
const
char
*
logName
,
int32_t
maxFiles
);
void
taosCloseLog
();
...
...
packaging/release.sh
浏览文件 @
e0b3e97d
...
...
@@ -67,7 +67,6 @@ bin_files="${compile_dir}/build/bin/taosd ${compile_dir}/build/bin/taos ${compi
cp
-rf
${
bin_files
}
${
install_dir
}
/bin
&&
chmod
a+x
${
install_dir
}
/bin/
*
||
:
cp
${
compile_dir
}
/build/lib/libtaos.so
${
install_dir
}
/lib/
cp
${
compile_dir
}
/build/lib/libtdb.so
${
install_dir
}
/lib/
cp
${
compile_dir
}
/build/lib/libavro
*
${
install_dir
}
/lib/
>
/dev/null
||
echo
-e
"failed to copy avro libraries"
cp
-rf
${
compile_dir
}
/build/lib/pkgconfig
${
install_dir
}
/lib/
>
/dev/null
||
echo
-e
"failed to copy pkgconfig directory"
...
...
packaging/tools/install.sh
浏览文件 @
e0b3e97d
...
...
@@ -215,15 +215,9 @@ function install_lib() {
${
csudo
}
ln
-s
${
install_main_dir
}
/lib/libtaos.
*
${
lib_link_dir
}
/libtaos.so.1
${
csudo
}
ln
-s
${
lib_link_dir
}
/libtaos.so.1
${
lib_link_dir
}
/libtaos.so
${
csudo
}
ln
-s
${
install_main_dir
}
/lib/libtdb.
*
${
lib_link_dir
}
/libtdb.so.1
${
csudo
}
ln
-s
${
lib_link_dir
}
/libtdb.so.1
${
lib_link_dir
}
/libtdb.so
if
[[
-d
${
lib64_link_dir
}
&&
!
-e
${
lib64_link_dir
}
/libtaos.so
]]
;
then
${
csudo
}
ln
-s
${
install_main_dir
}
/lib/libtaos.
*
${
lib64_link_dir
}
/libtaos.so.1
||
:
${
csudo
}
ln
-s
${
lib64_link_dir
}
/libtaos.so.1
${
lib64_link_dir
}
/libtaos.so
||
:
${
csudo
}
ln
-s
${
install_main_dir
}
/lib/libtdb.
*
${
lib64_link_dir
}
/libtdb.so.1
||
:
${
csudo
}
ln
-s
${
lib64_link_dir
}
/libtdb.so.1
${
lib64_link_dir
}
/libtdb.so
||
:
fi
${
csudo
}
ldconfig
...
...
source/client/src/clientImpl.c
浏览文件 @
e0b3e97d
...
...
@@ -172,7 +172,8 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC
.
msgLen
=
ERROR_MSG_BUF_DEFAULT_SIZE
,
.
pTransporter
=
pTscObj
->
pAppInfo
->
pTransporter
,
.
pStmtCb
=
pStmtCb
,
.
pUser
=
pTscObj
->
user
};
.
pUser
=
pTscObj
->
user
,
.
isSuperUser
=
(
0
==
strcmp
(
pTscObj
->
user
,
TSDB_DEFAULT_USER
))};
cxt
.
mgmtEpSet
=
getEpSet_s
(
&
pTscObj
->
pAppInfo
->
mgmtEp
);
int32_t
code
=
catalogGetHandle
(
pTscObj
->
pAppInfo
->
clusterId
,
&
cxt
.
pCatalog
);
...
...
@@ -947,8 +948,7 @@ int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableR
// TODO handle the compressed case
pResultInfo
->
totalRows
+=
pResultInfo
->
numOfRows
;
return
setResultDataPtr
(
pResultInfo
,
pResultInfo
->
fields
,
pResultInfo
->
numOfCols
,
pResultInfo
->
numOfRows
,
convertUcs4
);
return
setResultDataPtr
(
pResultInfo
,
pResultInfo
->
fields
,
pResultInfo
->
numOfCols
,
pResultInfo
->
numOfRows
,
convertUcs4
);
}
TSDB_SERVER_STATUS
taos_check_server_status
(
const
char
*
fqdn
,
int
port
,
char
*
details
,
int
maxlen
)
{
...
...
source/client/src/clientSml.c
浏览文件 @
e0b3e97d
...
...
@@ -9,7 +9,6 @@
#include "tdef.h"
#include "tlog.h"
#include "tmsg.h"
#include "tstrbuild.h"
#include "ttime.h"
#include "ttypes.h"
#include "tcommon.h"
...
...
@@ -26,6 +25,35 @@
#define SLASH '\\'
#define tsMaxSQLStringLen (1024*1024)
#define JUMP_SPACE(sql) while (*sql != '\0'){if(*sql == SPACE) sql++;else break;}
// comma ,
#define IS_SLASH_COMMA(sql) (*(sql) == COMMA && *((sql) - 1) == SLASH)
#define IS_COMMA(sql) (*(sql) == COMMA && *((sql) - 1) != SLASH)
// space
#define IS_SLASH_SPACE(sql) (*(sql) == SPACE && *((sql) - 1) == SLASH)
#define IS_SPACE(sql) (*(sql) == SPACE && *((sql) - 1) != SLASH)
// equal =
#define IS_SLASH_EQUAL(sql) (*(sql) == EQUAL && *((sql) - 1) == SLASH)
#define IS_EQUAL(sql) (*(sql) == EQUAL && *((sql) - 1) != SLASH)
// quote "
#define IS_SLASH_QUOTE(sql) (*(sql) == QUOTE && *((sql) - 1) == SLASH)
#define IS_QUOTE(sql) (*(sql) == QUOTE && *((sql) - 1) != SLASH)
// SLASH
#define IS_SLASH_SLASH(sql) (*(sql) == SLASH && *((sql) - 1) == SLASH)
#define IS_SLASH_LETTER(sql) (IS_SLASH_COMMA(sql) || IS_SLASH_SPACE(sql) || IS_SLASH_EQUAL(sql) || IS_SLASH_QUOTE(sql) || IS_SLASH_SLASH(sql))
#define MOVE_FORWARD_ONE(sql,len) (memmove((void*)((sql) - 1), (sql), len))
#define PROCESS_SLASH(key,keyLen) \
for (int i = 1; i < keyLen; ++i) { \
if(IS_SLASH_LETTER(key+i)){ \
MOVE_FORWARD_ONE(key+i, keyLen-i); \
i--; \
keyLen--; \
} \
}
#define OTD_MAX_FIELDS_NUM 2
#define OTD_JSON_SUB_FIELDS_NUM 2
#define OTD_JSON_FIELDS_NUM 4
...
...
@@ -42,6 +70,7 @@
#define BINARY_ADD_LEN 2 // "binary" 2 means " "
#define NCHAR_ADD_LEN 3 // L"nchar" 3 means L" "
#define CHAR_SAVE_LENGTH 8
//=================================================================================================
typedef
TSDB_SML_PROTOCOL_TYPE
SMLProtocolType
;
...
...
@@ -231,7 +260,7 @@ static int32_t smlBuildColumnDescription(SSmlKv* field, char* buf, int32_t bufSi
char
tname
[
TSDB_TABLE_NAME_LEN
]
=
{
0
};
memcpy
(
tname
,
field
->
key
,
field
->
keyLen
);
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
bytes
=
field
->
length
;
// todo
int32_t
bytes
=
field
->
length
>
CHAR_SAVE_LENGTH
?
(
2
*
field
->
length
)
:
CHAR_SAVE_LENGTH
;
int
out
=
snprintf
(
buf
,
bufSize
,
"`%s` %s(%d)"
,
tname
,
tDataTypes
[
field
->
type
].
name
,
bytes
);
*
outBytes
=
out
;
...
...
@@ -431,7 +460,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle* info) {
SEpSet
ep
=
getEpSet_s
(
&
info
->
taos
->
pAppInfo
->
mgmtEp
);
size_t
superTableLen
=
0
;
void
*
superTable
=
taosHashGetKey
(
tableMetaSml
,
&
superTableLen
);
// todo escape
void
*
superTable
=
taosHashGetKey
(
tableMetaSml
,
&
superTableLen
);
SName
pName
=
{
TSDB_TABLE_NAME_T
,
info
->
taos
->
acctId
,
{
0
},
{
0
}};
strcpy
(
pName
.
dbname
,
info
->
pRequest
->
pDb
);
memcpy
(
pName
.
tname
,
superTable
,
superTableLen
);
...
...
@@ -760,7 +789,7 @@ static int64_t smlParseInfluxTime(SSmlHandle* info, const char* data, int32_t le
smlBuildInvalidDataMsg
(
&
info
->
msgBuf
,
"invalid timestamp precision"
,
NULL
);
return
-
1
;
}
if
(
!
data
){
if
(
len
==
0
){
return
smlGetTimeNow
(
tsType
);
}
...
...
@@ -850,66 +879,56 @@ static bool smlParseValue(SSmlKv *pVal, SSmlMsgBuf *msg) {
static
int32_t
smlParseInfluxString
(
const
char
*
sql
,
SSmlLineInfo
*
elements
,
SSmlMsgBuf
*
msg
){
if
(
!
sql
)
return
TSDB_CODE_SML_INVALID_DATA
;
while
(
*
sql
!=
'\0'
)
{
// jump the space at the begining
if
(
*
sql
!=
SPACE
)
{
JUMP_SPACE
(
sql
)
if
(
*
sql
==
COMMA
)
return
TSDB_CODE_SML_INVALID_DATA
;
elements
->
measure
=
sql
;
break
;
}
sql
++
;
}
if
(
!
elements
->
measure
||
*
sql
==
COMMA
)
{
smlBuildInvalidDataMsg
(
msg
,
"invalid data"
,
sql
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
// parse measure
and tag
// parse measure
while
(
*
sql
!=
'\0'
)
{
if
(
elements
->
measureLen
==
0
&&
*
sql
==
COMMA
&&
*
(
sql
-
1
)
!=
SLASH
)
{
// find the first comma
elements
->
measureLen
=
sql
-
elements
->
measure
;
sql
++
;
elements
->
tags
=
sql
;
if
((
sql
!=
elements
->
measure
)
&&
IS_SLASH_LETTER
(
sql
)){
MOVE_FORWARD_ONE
(
sql
,
strlen
(
sql
)
+
1
);
continue
;
}
if
(
*
sql
==
SPACE
&&
*
(
sql
-
1
)
!=
SLASH
)
{
// find the first space
if
(
elements
->
measureLen
==
0
)
{
elements
->
measureLen
=
sql
-
elements
->
measure
;
elements
->
tags
=
sql
;
}
elements
->
tagsLen
=
sql
-
elements
->
tags
;
elements
->
measureTagsLen
=
sql
-
elements
->
measure
;
if
(
IS_COMMA
(
sql
)){
break
;
}
sql
++
;
if
(
IS_SPACE
(
sql
)){
break
;
}
if
(
elements
->
tagsLen
==
0
){
// measure, cols1=a measure cols1=a
elements
->
measureTagsLen
=
elements
->
measureLen
;
sql
++
;
}
elements
->
measureLen
=
sql
-
elements
->
measure
;
if
(
elements
->
measureLen
==
0
)
{
smlBuildInvalidDataMsg
(
msg
,
"
invalid measure"
,
elements
->
measure
);
smlBuildInvalidDataMsg
(
msg
,
"
measure is empty"
,
NULL
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
// parse cols
// parse tag
if
(
*
sql
==
SPACE
){
elements
->
tagsLen
=
0
;
}
else
{
if
(
*
sql
==
COMMA
)
sql
++
;
elements
->
tags
=
sql
;
while
(
*
sql
!=
'\0'
)
{
if
(
*
sql
!=
SPACE
)
{
elements
->
cols
=
sql
;
if
(
IS_SPACE
(
sql
)){
break
;
}
sql
++
;
}
if
(
!
elements
->
cols
)
{
smlBuildInvalidDataMsg
(
msg
,
"invalid columns"
,
elements
->
cols
);
return
TSDB_CODE_SML_INVALID_DATA
;
elements
->
tagsLen
=
sql
-
elements
->
tags
;
}
elements
->
measureTagsLen
=
sql
-
elements
->
measure
;
// parse cols
JUMP_SPACE
(
sql
)
elements
->
cols
=
sql
;
bool
isInQuote
=
false
;
while
(
*
sql
!=
'\0'
)
{
if
(
*
sql
==
QUOTE
&&
*
(
sql
-
1
)
!=
SLASH
){
if
(
IS_QUOTE
(
sql
)
){
isInQuote
=
!
isInQuote
;
}
if
(
!
isInQuote
&&
*
sql
==
SPACE
&&
*
(
sql
-
1
)
!=
SLASH
)
{
if
(
!
isInQuote
&&
IS_SPACE
(
sql
))
{
break
;
}
sql
++
;
...
...
@@ -919,20 +938,21 @@ static int32_t smlParseInfluxString(const char* sql, SSmlLineInfo *elements, SSm
return
TSDB_CODE_SML_INVALID_DATA
;
}
elements
->
colsLen
=
sql
-
elements
->
cols
;
if
(
elements
->
colsLen
==
0
)
{
smlBuildInvalidDataMsg
(
msg
,
"cols is empty"
,
NULL
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
// parse ts,ts can be empty
while
(
*
sql
!=
'\0'
)
{
if
(
*
sql
!=
SPACE
&&
elements
->
timestamp
==
NULL
)
{
// parse timestamp
JUMP_SPACE
(
sql
)
elements
->
timestamp
=
sql
;
}
if
(
*
sql
==
SPACE
&&
elements
->
timestamp
!=
NULL
){
while
(
*
sql
!=
'\0'
)
{
if
(
*
sql
==
SPACE
){
break
;
}
sql
++
;
}
if
(
elements
->
timestamp
){
elements
->
timestampLen
=
sql
-
elements
->
timestamp
;
}
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -949,38 +969,58 @@ static void smlParseTelnetElement(const char **sql, const char **data, int32_t *
}
}
static
int32_t
smlParseTelnetTags
(
const
char
*
data
,
int32_t
len
,
SArray
*
cols
,
SHashObj
*
dumplicateKey
,
SSmlMsgBuf
*
msg
){
for
(
int
i
=
0
;
i
<
len
;
i
++
){
// parse key
const
char
*
key
=
data
+
i
;
static
int32_t
smlParseTelnetTags
(
const
char
*
data
,
SArray
*
cols
,
SHashObj
*
dumplicateKey
,
SSmlMsgBuf
*
msg
){
const
char
*
sql
=
data
;
while
(
*
sql
!=
'\0'
){
JUMP_SPACE
(
sql
)
if
(
*
sql
==
'\0'
)
break
;
const
char
*
key
=
sql
;
int32_t
keyLen
=
0
;
while
(
i
<
len
){
if
(
data
[
i
]
==
EQUAL
){
keyLen
=
data
+
i
-
key
;
// parse key
while
(
*
sql
!=
'\0'
){
if
(
*
sql
==
SPACE
)
{
smlBuildInvalidDataMsg
(
msg
,
"invalid data"
,
sql
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
if
(
*
sql
==
EQUAL
)
{
keyLen
=
sql
-
key
;
sql
++
;
break
;
}
i
++
;
sql
++
;
}
if
(
keyLen
==
0
||
keyLen
>=
TSDB_COL_NAME_LEN
){
smlBuildInvalidDataMsg
(
msg
,
"invalid key or key is too long than 64"
,
key
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
if
(
smlCheckDuplicateKey
(
key
,
keyLen
,
dumplicateKey
)){
smlBuildInvalidDataMsg
(
msg
,
"dumplicate key"
,
key
);
return
TSDB_CODE_TSC_DUP_TAG_NAMES
;
}
// parse value
i
++
;
const
char
*
value
=
data
+
i
;
while
(
i
<
len
){
if
(
data
[
i
]
==
SPACE
){
const
char
*
value
=
sql
;
int32_t
valueLen
=
0
;
while
(
*
sql
!=
'\0'
)
{
// parse value
if
(
*
sql
==
SPACE
)
{
valueLen
=
sql
-
value
;
sql
++
;
break
;
}
i
++
;
if
(
*
sql
==
EQUAL
)
{
smlBuildInvalidDataMsg
(
msg
,
"invalid data"
,
sql
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
sql
++
;
}
int32_t
valueLen
=
data
+
i
-
value
;
if
(
valueLen
==
0
){
valueLen
=
sql
-
value
;
}
if
(
valueLen
==
0
){
smlBuildInvalidDataMsg
(
msg
,
"invalid value"
,
value
);
return
TSDB_CODE_SML_INVALID_DATA
;
...
...
@@ -993,13 +1033,14 @@ static int32_t smlParseTelnetTags(const char* data, int32_t len, SArray *cols, S
kv
->
keyLen
=
keyLen
;
kv
->
value
=
value
;
kv
->
length
=
valueLen
;
kv
->
type
=
TSDB_DATA_TYPE_NCHAR
;
//todo
kv
->
type
=
TSDB_DATA_TYPE_NCHAR
;
if
(
cols
)
taosArrayPush
(
cols
,
&
kv
);
}
return
TSDB_CODE_SUCCESS
;
}
// format: <metric> <timestamp> <value> <tagk_1>=<tagv_1>[ <tagk_n>=<tagv_n>]
static
int32_t
smlParseTelnetString
(
SSmlHandle
*
info
,
const
char
*
sql
,
SSmlTableInfo
*
tinfo
,
SArray
*
cols
){
if
(
!
sql
)
return
TSDB_CODE_SML_INVALID_DATA
;
...
...
@@ -1048,10 +1089,7 @@ static int32_t smlParseTelnetString(SSmlHandle *info, const char* sql, SSmlTable
}
// parse tags
while
(
*
sql
==
SPACE
){
sql
++
;
}
ret
=
smlParseTelnetTags
(
sql
,
strlen
(
sql
),
tinfo
->
tags
,
info
->
dumplicateKey
,
&
info
->
msgBuf
);
ret
=
smlParseTelnetTags
(
sql
,
tinfo
->
tags
,
info
->
dumplicateKey
,
&
info
->
msgBuf
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
smlBuildInvalidDataMsg
(
&
info
->
msgBuf
,
"invalid data"
,
sql
);
return
TSDB_CODE_SML_INVALID_DATA
;
...
...
@@ -1073,49 +1111,67 @@ static int32_t smlParseCols(const char* data, int32_t len, SArray *cols, bool is
return
TSDB_CODE_SUCCESS
;
}
for
(
int
i
=
0
;
i
<
len
;
i
++
){
// parse key
const
char
*
key
=
data
+
i
;
const
char
*
sql
=
data
;
while
(
sql
<
data
+
len
){
const
char
*
key
=
sql
;
int32_t
keyLen
=
0
;
while
(
i
<
len
){
if
(
data
[
i
]
==
EQUAL
&&
i
>
0
&&
data
[
i
-
1
]
!=
SLASH
){
keyLen
=
data
+
i
-
key
;
while
(
sql
<
data
+
len
){
// parse key
if
(
IS_COMMA
(
sql
))
{
smlBuildInvalidDataMsg
(
msg
,
"invalid data"
,
sql
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
if
(
IS_EQUAL
(
sql
))
{
keyLen
=
sql
-
key
;
sql
++
;
break
;
}
i
++
;
sql
++
;
}
if
(
keyLen
==
0
||
keyLen
>=
TSDB_COL_NAME_LEN
){
smlBuildInvalidDataMsg
(
msg
,
"invalid key or key is too long than 64"
,
key
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
if
(
smlCheckDuplicateKey
(
key
,
keyLen
,
dumplicateKey
)){
smlBuildInvalidDataMsg
(
msg
,
"dumplicate key"
,
key
);
return
TSDB_CODE_TSC_DUP_TAG_NAMES
;
}
// parse value
i
++
;
const
char
*
value
=
data
+
i
;
const
char
*
value
=
sql
;
int32_t
valueLen
=
0
;
bool
isInQuote
=
false
;
while
(
i
<
len
){
if
(
!
isTag
&&
data
[
i
]
==
QUOTE
&&
data
[
i
-
1
]
!=
SLASH
){
while
(
sql
<
data
+
len
)
{
// parse value
if
(
!
isTag
&&
IS_QUOTE
(
sql
)){
isInQuote
=
!
isInQuote
;
sql
++
;
continue
;
}
if
(
!
isInQuote
&&
data
[
i
]
==
COMMA
&&
i
>
0
&&
data
[
i
-
1
]
!=
SLASH
)
{
if
(
!
isInQuote
&&
IS_COMMA
(
sql
))
{
break
;
}
i
++
;
if
(
!
isInQuote
&&
IS_EQUAL
(
sql
))
{
smlBuildInvalidDataMsg
(
msg
,
"invalid data"
,
sql
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
sql
++
;
}
if
(
!
isTag
&&
isInQuote
){
valueLen
=
sql
-
value
;
sql
++
;
if
(
isInQuote
){
smlBuildInvalidDataMsg
(
msg
,
"only one quote"
,
value
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
int32_t
valueLen
=
data
+
i
-
value
;
if
(
valueLen
==
0
){
smlBuildInvalidDataMsg
(
msg
,
"invalid value"
,
value
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
PROCESS_SLASH
(
key
,
keyLen
)
PROCESS_SLASH
(
value
,
valueLen
)
// add kv to SSmlKv
SSmlKv
*
kv
=
(
SSmlKv
*
)
taosMemoryCalloc
(
sizeof
(
SSmlKv
),
1
);
...
...
@@ -1138,49 +1194,6 @@ static int32_t smlParseCols(const char* data, int32_t len, SArray *cols, bool is
return
TSDB_CODE_SUCCESS
;
}
//static int32_t parseSmlCols(const char* data, SArray *cols){
// while(*data != '\0'){
// if(*data == EQUAL) return TSDB_CODE_SML_INVALID_DATA;
// const char *key = data;
// int32_t keyLen = 0;
// while(*data != '\0'){
// if(*data == EQUAL && *(data-1) != SLASH){
// keyLen = data - key;
// data ++;
// break;
// }
// data++;
// }
// if(keyLen == 0){
// return TSDB_CODE_SML_INVALID_DATA;
// }
//
// if(*data == COMMA) return TSDB_CODE_SML_INVALID_DATA;
// const char *value = data;
// int32_t valueLen = 0;
// while(*data != '\0'){
// if(*data == COMMA && *(data-1) != SLASH){
// valueLen = data - value;
// data ++;
// break;
// }
// data++;
// }
// if(valueLen == 0){
// return TSDB_CODE_SML_INVALID_DATA;
// }
//
// TAOS_SML_KV *kv = taosMemoryCalloc(sizeof(TAOS_SML_KV), 1);
// kv->key = key;
// kv->keyLen = keyLen;
// kv->value = value;
// kv->valueLen = valueLen;
// kv->type = TSDB_DATA_TYPE_NCHAR;
// if(cols) taosArrayPush(cols, &kv);
// }
// return TSDB_CODE_SUCCESS;
//}
static
bool
smlUpdateMeta
(
SHashObj
*
metaHash
,
SArray
*
metaArray
,
SArray
*
cols
,
SSmlMsgBuf
*
msg
){
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
cols
);
++
i
)
{
//jump timestamp
SSmlKv
*
kv
=
(
SSmlKv
*
)
taosArrayGetP
(
cols
,
i
);
...
...
@@ -1298,7 +1311,7 @@ static int32_t smlDealCols(SSmlTableInfo* oneTable, bool dataFormat, SArray *col
}
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
cols
);
i
++
){
SSmlKv
*
kv
=
(
SSmlKv
*
)
taosArrayGetP
(
cols
,
i
);
taosHashPut
(
kvHash
,
kv
->
key
,
kv
->
keyLen
,
&
kv
,
POINTER_BYTES
);
// todo key need escape, like \=, because find by schema name later
taosHashPut
(
kvHash
,
kv
->
key
,
kv
->
keyLen
,
&
kv
,
POINTER_BYTES
);
}
taosArrayPush
(
oneTable
->
cols
,
&
kvHash
);
...
...
@@ -1346,6 +1359,7 @@ static void smlDestroySTableMeta(SSmlSTableMeta *meta){
taosArrayDestroy
(
meta
->
tags
);
taosArrayDestroy
(
meta
->
cols
);
taosMemoryFree
(
meta
->
tableMeta
);
taosMemoryFree
(
meta
);
}
static
void
smlDestroyCols
(
SArray
*
cols
)
{
...
...
source/client/test/smlTest.cpp
浏览文件 @
e0b3e97d
...
...
@@ -41,12 +41,14 @@ TEST(testCase, smlParseInfluxString_Test) {
SSmlLineInfo
elements
=
{
0
};
// case 1
char
*
sql
=
"st,t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000 ,32,c=3"
;
char
*
tmp
=
"
\\
,st,t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000 ,32,c=3"
;
char
*
sql
=
(
char
*
)
taosMemoryCalloc
(
256
,
1
);
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
int
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
measure
,
sql
);
ASSERT_EQ
(
elements
.
measureLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"st,t1=3,t2=4,t3=t3"
));
ASSERT_EQ
(
elements
.
measureLen
,
strlen
(
"
,
st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"
,
st,t1=3,t2=4,t3=t3"
));
ASSERT_EQ
(
elements
.
tags
,
sql
+
elements
.
measureLen
+
1
);
ASSERT_EQ
(
elements
.
tagsLen
,
strlen
(
"t1=3,t2=4,t3=t3"
));
...
...
@@ -58,76 +60,79 @@ TEST(testCase, smlParseInfluxString_Test) {
ASSERT_EQ
(
elements
.
timestampLen
,
strlen
(
"1626006833639000000"
));
// case 2 false
sql
=
"st,t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2,c2=false,c4=4f64 1626006833639000000"
;
tmp
=
"st,t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2,c2=false,c4=4f64 1626006833639000000"
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_NE
(
ret
,
0
);
// case 3 false
sql
=
"st, t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2,c2=false,c4=4f64 1626006833639000000"
;
tmp
=
"st, t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2,c2=false,c4=4f64 1626006833639000000"
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
2
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
1
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
"t1=3,t2=4,t3=t3"
));
// case 4 tag is null
sql
=
"st, c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000"
;
tmp
=
"st, c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000"
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
measure
,
sql
);
ASSERT_EQ
(
elements
.
measureLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"st
,
"
));
ASSERT_EQ
(
elements
.
tags
,
sql
+
elements
.
measure
Len
+
1
);
ASSERT_EQ
(
elements
.
tags
,
sql
+
elements
.
measure
TagsLen
);
ASSERT_EQ
(
elements
.
tagsLen
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
2
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
1
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
"c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64"
));
ASSERT_EQ
(
elements
.
timestamp
,
sql
+
elements
.
measureTagsLen
+
2
+
elements
.
colsLen
+
1
);
ASSERT_EQ
(
elements
.
timestamp
,
sql
+
elements
.
measureTagsLen
+
1
+
elements
.
colsLen
+
1
);
ASSERT_EQ
(
elements
.
timestampLen
,
strlen
(
"1626006833639000000"
));
// case 5 tag is null
sql
=
" st c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000 "
;
tmp
=
" st c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000 "
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
sql
++
;
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
measure
,
sql
);
ASSERT_EQ
(
elements
.
measure
,
sql
+
1
);
ASSERT_EQ
(
elements
.
measureLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
tags
,
sql
+
elements
.
measureLen
);
ASSERT_EQ
(
elements
.
tagsLen
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
3
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
1
+
elements
.
measureTagsLen
+
3
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
"c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64"
));
ASSERT_EQ
(
elements
.
timestamp
,
sql
+
elements
.
measureTagsLen
+
3
+
elements
.
colsLen
+
2
);
ASSERT_EQ
(
elements
.
timestamp
,
sql
+
1
+
elements
.
measureTagsLen
+
3
+
elements
.
colsLen
+
2
);
ASSERT_EQ
(
elements
.
timestampLen
,
strlen
(
"1626006833639000000"
));
// case 6
sql
=
" st c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 "
;
tmp
=
" st c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 "
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
// case 7
sql
=
" st , "
;
tmp
=
" st , "
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
sql
++
;
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
3
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
","
));
// case 8 false
sql
=
", st , "
;
tmp
=
", st , "
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_NE
(
ret
,
0
);
taosMemoryFree
(
sql
);
}
TEST
(
testCase
,
smlParseCols_Error_Test
)
{
...
...
@@ -188,7 +193,8 @@ TEST(testCase, smlParseCols_Error_Test) {
"c=-3.402823466e+39u64"
,
"c=-339u64"
,
"c=18446744073709551616u64"
,
"c=1,c=2"
"c=1,c=2"
,
"c=1=2"
};
SHashObj
*
dumplicateKey
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
...
...
@@ -198,9 +204,18 @@ TEST(testCase, smlParseCols_Error_Test) {
msgBuf
.
buf
=
msg
;
msgBuf
.
len
=
256
;
int32_t
len
=
strlen
(
data
[
i
]);
int32_t
ret
=
smlParseCols
(
data
[
i
],
len
,
NULL
,
false
,
dumplicateKey
,
&
msgBuf
);
char
*
sql
=
(
char
*
)
taosMemoryCalloc
(
256
,
1
);
memcpy
(
sql
,
data
[
i
],
len
+
1
);
SArray
*
cols
=
taosArrayInit
(
8
,
POINTER_BYTES
);
int32_t
ret
=
smlParseCols
(
sql
,
len
,
cols
,
false
,
dumplicateKey
,
&
msgBuf
);
ASSERT_NE
(
ret
,
TSDB_CODE_SUCCESS
);
taosHashClear
(
dumplicateKey
);
taosMemoryFree
(
sql
);
for
(
int
j
=
0
;
j
<
taosArrayGetSize
(
cols
);
j
++
){
void
*
kv
=
taosArrayGetP
(
cols
,
j
);
taosMemoryFree
(
kv
);
}
taosArrayDestroy
(
cols
);
}
taosHashCleanup
(
dumplicateKey
);
}
...
...
@@ -216,7 +231,7 @@ TEST(testCase, smlParseCols_tag_Test) {
SHashObj
*
dumplicateKey
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
const
char
*
data
=
"cbin=
\"
passit helloc
=2
\"
,cnch=L
\"
iisdfsf
\"
,cbool=false,cf64=4.31f64,cf64_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_=l
\"
iuwq
\"
"
;
"cbin=
\"
passit helloc
\"
,cnch=L
\"
iisdfsf
\"
,cbool=false,cf64=4.31f64,cf64_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_=l
\"
iuwq
\"
"
;
int32_t
len
=
strlen
(
data
);
int32_t
ret
=
smlParseCols
(
data
,
len
,
cols
,
true
,
dumplicateKey
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
TSDB_CODE_SUCCESS
);
...
...
@@ -228,9 +243,8 @@ TEST(testCase, smlParseCols_tag_Test) {
ASSERT_EQ
(
strncasecmp
(
kv
->
key
,
"cbin"
,
4
),
0
);
ASSERT_EQ
(
kv
->
keyLen
,
4
);
ASSERT_EQ
(
kv
->
type
,
TSDB_DATA_TYPE_NCHAR
);
ASSERT_EQ
(
kv
->
length
,
1
7
);
ASSERT_EQ
(
kv
->
length
,
1
5
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"
\"
passit"
,
7
),
0
);
taosMemoryFree
(
kv
);
// nchar
kv
=
(
SSmlKv
*
)
taosArrayGetP
(
cols
,
3
);
...
...
@@ -239,11 +253,13 @@ TEST(testCase, smlParseCols_tag_Test) {
ASSERT_EQ
(
kv
->
type
,
TSDB_DATA_TYPE_NCHAR
);
ASSERT_EQ
(
kv
->
length
,
7
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"4.31f64"
,
7
),
0
);
taosMemoryFree
(
kv
);
for
(
int
i
=
0
;
i
<
size
;
i
++
){
void
*
tmp
=
taosArrayGetP
(
cols
,
i
);
taosMemoryFree
(
tmp
);
}
taosArrayClear
(
cols
);
// test tag is null
data
=
"t=3e"
;
len
=
0
;
...
...
@@ -278,20 +294,22 @@ TEST(testCase, smlParseCols_Test) {
SHashObj
*
dumplicateKey
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
const
char
*
data
=
"cb
in=
\"
passit hello,c=2
\"
,cnch=L
\"
ii
sdfsf
\"
,cbool=false,cf64=4.31f64,cf64_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_=l
\"
iuwq
\"
"
;
const
char
*
data
=
"cb
\\
=in=
\"
pass
\\
,it hello,c=2
\"
,cnch=L
\"
ii
\\
=
sdfsf
\"
,cbool=false,cf64=4.31f64,cf64_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_=l
\"
iuwq
\"
"
;
int32_t
len
=
strlen
(
data
);
int32_t
ret
=
smlParseCols
(
data
,
len
,
cols
,
false
,
dumplicateKey
,
&
msgBuf
);
char
*
sql
=
(
char
*
)
taosMemoryCalloc
(
1024
,
1
);
memcpy
(
sql
,
data
,
len
+
1
);
int32_t
ret
=
smlParseCols
(
sql
,
len
,
cols
,
false
,
dumplicateKey
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
TSDB_CODE_SUCCESS
);
int32_t
size
=
taosArrayGetSize
(
cols
);
ASSERT_EQ
(
size
,
19
);
// binary
SSmlKv
*
kv
=
(
SSmlKv
*
)
taosArrayGetP
(
cols
,
0
);
ASSERT_EQ
(
strncasecmp
(
kv
->
key
,
"cb
in"
,
4
),
0
);
ASSERT_EQ
(
kv
->
keyLen
,
4
);
ASSERT_EQ
(
strncasecmp
(
kv
->
key
,
"cb
=in"
,
5
),
0
);
ASSERT_EQ
(
kv
->
keyLen
,
5
);
ASSERT_EQ
(
kv
->
type
,
TSDB_DATA_TYPE_BINARY
);
ASSERT_EQ
(
kv
->
length
,
1
6
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"pass
it"
,
6
),
0
);
ASSERT_EQ
(
kv
->
length
,
1
7
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"pass
,it "
,
8
),
0
);
taosMemoryFree
(
kv
);
// nchar
...
...
@@ -299,8 +317,8 @@ TEST(testCase, smlParseCols_Test) {
ASSERT_EQ
(
strncasecmp
(
kv
->
key
,
"cnch"
,
4
),
0
);
ASSERT_EQ
(
kv
->
keyLen
,
4
);
ASSERT_EQ
(
kv
->
type
,
TSDB_DATA_TYPE_NCHAR
);
ASSERT_EQ
(
kv
->
length
,
7
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"ii
sd"
,
4
),
0
);
ASSERT_EQ
(
kv
->
length
,
8
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"ii
=sd"
,
5
),
0
);
taosMemoryFree
(
kv
);
// bool
...
...
@@ -463,6 +481,7 @@ TEST(testCase, smlParseCols_Test) {
taosArrayDestroy
(
cols
);
taosHashCleanup
(
dumplicateKey
);
taosMemoryFree
(
sql
);
}
TEST
(
testCase
,
smlProcess_influx_Test
)
{
...
...
@@ -481,7 +500,7 @@ TEST(testCase, smlProcess_influx_Test) {
SSmlHandle
*
info
=
smlBuildSmlInfo
(
taos
,
request
,
TSDB_SML_LINE_PROTOCOL
,
TSDB_SML_TIMESTAMP_NANO_SECONDS
,
true
);
ASSERT_NE
(
info
,
nullptr
);
const
char
*
sql
[
11
]
=
{
const
char
*
sql
[]
=
{
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 load_capacity=1500,fuel_capacity=150,nominal_fuel_consumption=12,latitude=52.31854,longitude=4.72037,elevation=124,velocity=0,heading=221,grade=0 1451606400000000000"
,
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 load_capacity=1500,fuel_capacity=150,nominal_fuel_consumption=12,latitude=52.31854,longitude=4.72037,elevation=124,velocity=0,heading=221,grade=0,fuel_consumption=25 1451607400000000000"
,
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 load_capacity=1500,fuel_capacity=150,nominal_fuel_consumption=12,latitude=52.31854,longitude=4.72037,elevation=124,heading=221,grade=0,fuel_consumption=25 1451608400000000000"
,
...
...
@@ -492,20 +511,22 @@ TEST(testCase, smlProcess_influx_Test) {
"readings,name=truck_2,fleet=North,driver=Derek,model=F-150 load_capacity=2000,fuel_capacity=200,nominal_fuel_consumption=15,latitude=24.5208,longitude=28.09377,elevation=428,velocity=0,heading=304,grade=0,fuel_consumption=25 1451609400000000000"
,
"readings,fleet=South,name=truck_0,driver=Trish,model=H-2,device_version=v2.3 fuel_consumption=25,grade=0 1451629400000000000"
,
"stable,t1=t1,t2=t2,t3=t3 c1=1,c2=2,c3=3,c4=4 1451629500000000000"
,
"stable,t2=t2,t1=t1,t3=t3 c1=1,c3=3,c4=4 1451629600000000000"
"stable,t2=t2,t1=t1,t3=t3 c1=1,c3=3,c4=4 1451629600000000000"
,
};
smlProcess
(
info
,
(
char
**
)
sql
,
sizeof
(
sql
)
/
sizeof
(
sql
[
0
]));
int
ret
=
smlProcess
(
info
,
(
char
**
)
sql
,
sizeof
(
sql
)
/
sizeof
(
sql
[
0
]));
ASSERT_EQ
(
ret
,
0
);
TAOS_RES
*
res
=
taos_query
(
taos
,
"select * from t_6885c584b98481584ee13dac399e173d"
);
ASSERT_NE
(
res
,
nullptr
);
int
fieldNum
=
taos_field_count
(
res
);
ASSERT_EQ
(
fieldNum
,
5
);
int
rowNum
=
taos_affected_rows
(
res
);
ASSERT_EQ
(
rowNum
,
2
);
for
(
int
i
=
0
;
i
<
rowNum
;
++
i
)
{
TAOS_ROW
rows
=
taos_fetch_row
(
res
);
}
//
int fieldNum = taos_field_count(res);
//
ASSERT_EQ(fieldNum, 5);
//
int rowNum = taos_affected_rows(res);
//
ASSERT_EQ(rowNum, 2);
//
for (int i = 0; i < rowNum; ++i) {
//
TAOS_ROW rows = taos_fetch_row(res);
//
}
taos_free_result
(
res
);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
...
...
@@ -526,7 +547,7 @@ TEST(testCase, smlParseLine_error_Test) {
SSmlHandle
*
info
=
smlBuildSmlInfo
(
taos
,
request
,
TSDB_SML_LINE_PROTOCOL
,
TSDB_SML_TIMESTAMP_NANO_SECONDS
,
true
);
ASSERT_NE
(
info
,
nullptr
);
const
char
*
sql
[
2
]
=
{
const
char
*
sql
[]
=
{
"measure,t1=3 c1=8"
,
"measure,t2=3 c1=8u8"
};
...
...
@@ -575,37 +596,37 @@ TEST(testCase, smlProcess_telnet_Test) {
SSmlHandle
*
info
=
smlBuildSmlInfo
(
taos
,
request
,
TSDB_SML_TELNET_PROTOCOL
,
TSDB_SML_TIMESTAMP_NANO_SECONDS
,
true
);
ASSERT_NE
(
info
,
nullptr
);
const
char
*
sql
[
5
]
=
{
const
char
*
sql
[]
=
{
"sys.if.bytes.out 1479496100 1.3E0 host=web01 interface=eth0"
,
"sys.if.bytes.out
1479496101 1.3E1 interface=eth0 host=web01
"
,
"sys.if.bytes.out
1479496101 1.3E1 interface=eth0 host=web01
"
,
"sys.if.bytes.out 1479496102 1.3E3 network=tcp"
,
"sys.procs.running 1479496100 42 host=web01 "
,
" sys.procs.running 1479496200 42 host=web01=4"
" sys.procs.running 1479496100 42 host=web01 "
};
int
ret
=
smlProcess
(
info
,
(
char
**
)
sql
,
sizeof
(
sql
)
/
sizeof
(
sql
[
0
]));
ASSERT_EQ
(
ret
,
0
);
TAOS_RES
*
res
=
taos_query
(
taos
,
"select * from t_8c30283b3c4131a071d1e16cf6d7094a"
);
ASSERT_NE
(
res
,
nullptr
);
int
fieldNum
=
taos_field_count
(
res
);
ASSERT_EQ
(
fieldNum
,
2
);
int
rowNum
=
taos_affected_rows
(
res
);
ASSERT_EQ
(
rowNum
,
1
);
for
(
int
i
=
0
;
i
<
rowNum
;
++
i
)
{
TAOS_ROW
rows
=
taos_fetch_row
(
res
);
}
taos_free_result
(
pR
es
);
//
int fieldNum = taos_field_count(res);
//
ASSERT_EQ(fieldNum, 2);
//
int rowNum = taos_affected_rows(res);
//
ASSERT_EQ(rowNum, 1);
//
for (int i = 0; i < rowNum; ++i) {
//
TAOS_ROW rows = taos_fetch_row(res);
//
}
taos_free_result
(
r
es
);
res
=
taos_query
(
taos
,
"select * from t_6931529054e5637ca92c78a1ad441961"
);
ASSERT_NE
(
res
,
nullptr
);
fieldNum
=
taos_field_count
(
res
);
ASSERT_EQ
(
fieldNum
,
2
);
rowNum
=
taos_affected_rows
(
res
);
ASSERT_EQ
(
rowNum
,
2
);
for
(
int
i
=
0
;
i
<
rowNum
;
++
i
)
{
TAOS_ROW
rows
=
taos_fetch_row
(
res
);
}
taos_free_result
(
pRes
);
// res = taos_query(taos, "select * from t_6931529054e5637ca92c78a1ad441961");
// ASSERT_NE(res, nullptr);
// fieldNum = taos_field_count(res);
// ASSERT_EQ(fieldNum, 2);
// rowNum = taos_affected_rows(res);
// ASSERT_EQ(rowNum, 2);
// for (int i = 0; i < rowNum; ++i) {
// TAOS_ROW rows = taos_fetch_row(res);
// }
// taos_free_result(res);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
...
...
@@ -658,7 +679,8 @@ TEST(testCase, smlProcess_json1_Test) {
// for (int i = 0; i < rowNum; ++i) {
// TAOS_ROW rows = taos_fetch_row(res);
// }
taos_free_result
(
pRes
);
taos_free_result
(
res
);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
...
...
@@ -702,7 +724,7 @@ TEST(testCase, smlProcess_json2_Test) {
"}"
;
int32_t
ret
=
smlProcess
(
info
,
(
char
**
)(
&
sql
),
-
1
);
ASSERT_EQ
(
ret
,
0
);
taos_free_result
(
pRes
);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
...
...
@@ -774,7 +796,7 @@ TEST(testCase, smlProcess_json3_Test) {
"}"
;
int32_t
ret
=
smlProcess
(
info
,
(
char
**
)(
&
sql
),
-
1
);
ASSERT_EQ
(
ret
,
0
);
taos_free_result
(
pRes
);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
...
...
@@ -836,7 +858,7 @@ TEST(testCase, smlProcess_json4_Test) {
"}"
;
int32_t
ret
=
smlProcess
(
info
,
(
char
**
)(
&
sql
),
-
1
);
ASSERT_EQ
(
ret
,
0
);
taos_free_result
(
pRes
);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
...
...
@@ -857,7 +879,7 @@ TEST(testCase, smlParseTelnetLine_error_Test) {
ASSERT_NE
(
info
,
nullptr
);
int32_t
ret
=
0
;
const
char
*
sql
[
19
]
=
{
const
char
*
sql
[]
=
{
"sys.procs.running 14794961040 42 host=web01"
,
"sys.procs.running 14791040 42 host=web01"
,
"sys.procs.running erere 42 host=web01"
,
...
...
@@ -877,6 +899,8 @@ TEST(testCase, smlParseTelnetLine_error_Test) {
"sys.procs.running 1479496100 42 host=web01 cpu= "
,
"sys.procs.running 1479496100 42 host=web01 host=w2"
,
"sys.procs.running 1479496100 42 host=web01 host"
,
"sys.procs.running 1479496100 42 host=web01=er"
,
"sys.procs.running 1479496100 42 host= web01"
,
};
for
(
int
i
=
0
;
i
<
sizeof
(
sql
)
/
sizeof
(
sql
[
0
]);
i
++
){
ret
=
smlParseTelnetLine
(
info
,
(
void
*
)
sql
[
i
]);
...
...
source/common/src/tglobal.c
浏览文件 @
e0b3e97d
...
...
@@ -299,6 +299,7 @@ static int32_t taosAddServerLogCfg(SConfig *pCfg) {
if
(
cfgAddInt32
(
pCfg
,
"tqDebugFlag"
,
tqDebugFlag
,
0
,
255
,
0
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"fsDebugFlag"
,
fsDebugFlag
,
0
,
255
,
0
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"fnDebugFlag"
,
fnDebugFlag
,
0
,
255
,
0
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"smaDebugFlag"
,
smaDebugFlag
,
0
,
255
,
0
)
!=
0
)
return
-
1
;
return
0
;
}
...
...
@@ -480,6 +481,7 @@ static void taosSetServerLogCfg(SConfig *pCfg) {
tqDebugFlag
=
cfgGetItem
(
pCfg
,
"tqDebugFlag"
)
->
i32
;
fsDebugFlag
=
cfgGetItem
(
pCfg
,
"fsDebugFlag"
)
->
i32
;
fnDebugFlag
=
cfgGetItem
(
pCfg
,
"fnDebugFlag"
)
->
i32
;
smaDebugFlag
=
cfgGetItem
(
pCfg
,
"smaDebugFlag"
)
->
i32
;
}
static
int32_t
taosSetClientCfg
(
SConfig
*
pCfg
)
{
...
...
source/common/src/tmsg.c
浏览文件 @
e0b3e97d
...
...
@@ -3562,39 +3562,92 @@ int tDecodeSVCreateTbBatchRsp(SDecoder *pCoder, SVCreateTbBatchRsp *pRsp) {
return
0
;
}
int32_t
tSerializeSVCreateTSmaReq
(
void
**
buf
,
SVCreateTSmaReq
*
pReq
)
{
int32_t
tlen
=
0
;
int32_t
tEncodeTSma
(
SEncoder
*
pCoder
,
const
STSma
*
pSma
)
{
if
(
tEncodeI8
(
pCoder
,
pSma
->
version
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pCoder
,
pSma
->
intervalUnit
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pCoder
,
pSma
->
slidingUnit
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pCoder
,
pSma
->
timezoneInt
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pCoder
,
pSma
->
indexName
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pCoder
,
pSma
->
exprLen
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pCoder
,
pSma
->
tagsFilterLen
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
indexUid
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
tableUid
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
interval
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
offset
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pSma
->
sliding
)
<
0
)
return
-
1
;
if
(
pSma
->
exprLen
>
0
)
{
if
(
tEncodeCStr
(
pCoder
,
pSma
->
expr
)
<
0
)
return
-
1
;
}
if
(
pSma
->
tagsFilterLen
>
0
)
{
if
(
tEncodeCStr
(
pCoder
,
pSma
->
tagsFilter
)
<
0
)
return
-
1
;
}
tlen
+=
taosEncodeFixedI64
(
buf
,
pReq
->
ver
)
;
tlen
+=
tEncodeTSma
(
buf
,
&
pReq
->
tSma
);
return
0
;
}
return
tlen
;
int32_t
tDecodeTSma
(
SDecoder
*
pCoder
,
STSma
*
pSma
)
{
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
version
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
intervalUnit
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
slidingUnit
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pCoder
,
&
pSma
->
timezoneInt
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pCoder
,
pSma
->
indexName
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pSma
->
exprLen
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pSma
->
tagsFilterLen
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
indexUid
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
tableUid
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
interval
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
offset
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pSma
->
sliding
)
<
0
)
return
-
1
;
if
(
pSma
->
exprLen
>
0
)
{
if
(
tDecodeCStr
(
pCoder
,
&
pSma
->
expr
)
<
0
)
return
-
1
;
}
else
{
pSma
->
expr
=
NULL
;
}
if
(
pSma
->
tagsFilterLen
>
0
)
{
if
(
tDecodeCStr
(
pCoder
,
&
pSma
->
tagsFilter
)
<
0
)
return
-
1
;
}
else
{
pSma
->
tagsFilter
=
NULL
;
}
return
0
;
}
void
*
tDeserializeSVCreateTSmaReq
(
void
*
buf
,
SVCreateTSmaReq
*
pReq
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
(
pReq
->
ver
))
;
int32_t
tEncodeSVCreateTSmaReq
(
SEncoder
*
pCoder
,
const
SVCreateTSmaReq
*
pReq
)
{
if
(
tStartEncode
(
pCoder
)
<
0
)
return
-
1
;
if
((
buf
=
tDecodeTSma
(
buf
,
&
pReq
->
tSma
))
==
NULL
)
{
tdDestroyTSma
(
&
pReq
->
tSma
);
}
return
buf
;
tEncodeTSma
(
pCoder
,
pReq
);
tEndEncode
(
pCoder
);
return
0
;
}
int32_t
t
SerializeSVDropTSmaReq
(
void
**
buf
,
SVDrop
TSmaReq
*
pReq
)
{
i
nt32_t
tlen
=
0
;
int32_t
t
DecodeSVCreateTSmaReq
(
SDecoder
*
pCoder
,
SVCreate
TSmaReq
*
pReq
)
{
i
f
(
tStartDecode
(
pCoder
)
<
0
)
return
-
1
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pReq
->
ver
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pReq
->
indexUid
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
indexName
);
tDecodeTSma
(
pCoder
,
pReq
);
return
tlen
;
tEndDecode
(
pCoder
);
return
0
;
}
int32_t
tEncodeSVDropTSmaReq
(
SEncoder
*
pCoder
,
const
SVDropTSmaReq
*
pReq
)
{
if
(
tStartEncode
(
pCoder
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pCoder
,
pReq
->
indexUid
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pCoder
,
pReq
->
indexName
)
<
0
)
return
-
1
;
tEndEncode
(
pCoder
);
return
0
;
}
void
*
tDeserializeSVDropTSmaReq
(
void
*
buf
,
SVDropTSmaReq
*
pReq
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
(
pReq
->
ver
));
buf
=
taosDecodeFixedI64
(
buf
,
&
(
pReq
->
indexUid
));
buf
=
taosDecodeStringTo
(
buf
,
pReq
->
indexName
);
return
buf
;
int32_t
tDecodeSVDropTSmaReq
(
SDecoder
*
pCoder
,
SVDropTSmaReq
*
pReq
)
{
if
(
tStartDecode
(
pCoder
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pCoder
,
&
pReq
->
indexUid
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pCoder
,
pReq
->
indexName
)
<
0
)
return
-
1
;
tEndDecode
(
pCoder
);
return
0
;
}
int32_t
tSerializeSCMCreateStreamReq
(
void
*
buf
,
int32_t
bufLen
,
const
SCMCreateStreamReq
*
pReq
)
{
...
...
source/dnode/mnode/impl/src/mndDef.c
浏览文件 @
e0b3e97d
...
...
@@ -17,6 +17,147 @@
#include "mndDef.h"
#include "mndConsumer.h"
int32_t
tEncodeSStreamObj
(
SEncoder
*
pEncoder
,
const
SStreamObj
*
pObj
)
{
int32_t
sz
=
0
;
/*int32_t outputNameSz = 0;*/
if
(
tEncodeCStr
(
pEncoder
,
pObj
->
name
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pObj
->
sourceDb
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pObj
->
targetDb
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pObj
->
targetSTbName
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
targetStbUid
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
createTime
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
updateTime
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
uid
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
dbUid
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pObj
->
version
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pObj
->
status
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pObj
->
createdBy
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pObj
->
trigger
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pObj
->
triggerParam
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
waterMark
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pObj
->
fixedSinkVgId
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
smaId
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pObj
->
sql
)
<
0
)
return
-
1
;
/*if (tEncodeCStr(pEncoder, pObj->logicalPlan) < 0) return -1;*/
if
(
tEncodeCStr
(
pEncoder
,
pObj
->
physicalPlan
)
<
0
)
return
-
1
;
// TODO encode tasks
if
(
pObj
->
tasks
)
{
sz
=
taosArrayGetSize
(
pObj
->
tasks
);
}
if
(
tEncodeI32
(
pEncoder
,
sz
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SArray
*
pArray
=
taosArrayGetP
(
pObj
->
tasks
,
i
);
int32_t
innerSz
=
taosArrayGetSize
(
pArray
);
if
(
tEncodeI32
(
pEncoder
,
innerSz
)
<
0
)
return
-
1
;
for
(
int32_t
j
=
0
;
j
<
innerSz
;
j
++
)
{
SStreamTask
*
pTask
=
taosArrayGetP
(
pArray
,
j
);
if
(
tEncodeSStreamTask
(
pEncoder
,
pTask
)
<
0
)
return
-
1
;
}
}
if
(
tEncodeSSchemaWrapper
(
pEncoder
,
&
pObj
->
outputSchema
)
<
0
)
return
-
1
;
#if 0
if (pObj->ColAlias != NULL) {
outputNameSz = taosArrayGetSize(pObj->ColAlias);
}
if (tEncodeI32(pEncoder, outputNameSz) < 0) return -1;
for (int32_t i = 0; i < outputNameSz; i++) {
char *name = taosArrayGetP(pObj->ColAlias, i);
if (tEncodeCStr(pEncoder, name) < 0) return -1;
}
#endif
return
pEncoder
->
pos
;
}
int32_t
tDecodeSStreamObj
(
SDecoder
*
pDecoder
,
SStreamObj
*
pObj
)
{
if
(
tDecodeCStrTo
(
pDecoder
,
pObj
->
name
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pDecoder
,
pObj
->
sourceDb
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pDecoder
,
pObj
->
targetDb
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pDecoder
,
pObj
->
targetSTbName
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
targetStbUid
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
createTime
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
updateTime
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
uid
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
dbUid
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pObj
->
version
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pObj
->
status
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pObj
->
createdBy
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pObj
->
trigger
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pObj
->
triggerParam
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
waterMark
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pObj
->
fixedSinkVgId
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
smaId
)
<
0
)
return
-
1
;
if
(
tDecodeCStrAlloc
(
pDecoder
,
&
pObj
->
sql
)
<
0
)
return
-
1
;
/*if (tDecodeCStrAlloc(pDecoder, &pObj->logicalPlan) < 0) return -1;*/
if
(
tDecodeCStrAlloc
(
pDecoder
,
&
pObj
->
physicalPlan
)
<
0
)
return
-
1
;
pObj
->
tasks
=
NULL
;
int32_t
sz
;
if
(
tDecodeI32
(
pDecoder
,
&
sz
)
<
0
)
return
-
1
;
if
(
sz
!=
0
)
{
pObj
->
tasks
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
int32_t
innerSz
;
if
(
tDecodeI32
(
pDecoder
,
&
innerSz
)
<
0
)
return
-
1
;
SArray
*
pArray
=
taosArrayInit
(
innerSz
,
sizeof
(
void
*
));
for
(
int32_t
j
=
0
;
j
<
innerSz
;
j
++
)
{
SStreamTask
*
pTask
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamTask
));
if
(
pTask
==
NULL
)
return
-
1
;
if
(
tDecodeSStreamTask
(
pDecoder
,
pTask
)
<
0
)
return
-
1
;
taosArrayPush
(
pArray
,
&
pTask
);
}
taosArrayPush
(
pObj
->
tasks
,
&
pArray
);
}
}
if
(
tDecodeSSchemaWrapper
(
pDecoder
,
&
pObj
->
outputSchema
)
<
0
)
return
-
1
;
#if 0
int32_t outputNameSz;
if (tDecodeI32(pDecoder, &outputNameSz) < 0) return -1;
if (outputNameSz != 0) {
pObj->ColAlias = taosArrayInit(outputNameSz, sizeof(void *));
if (pObj->ColAlias == NULL) {
return -1;
}
}
for (int32_t i = 0; i < outputNameSz; i++) {
char *name;
if (tDecodeCStrAlloc(pDecoder, &name) < 0) return -1;
taosArrayPush(pObj->ColAlias, &name);
}
#endif
return
0
;
}
SMqVgEp
*
tCloneSMqVgEp
(
const
SMqVgEp
*
pVgEp
)
{
SMqVgEp
*
pVgEpNew
=
taosMemoryMalloc
(
sizeof
(
SMqVgEp
));
if
(
pVgEpNew
==
NULL
)
return
NULL
;
pVgEpNew
->
vgId
=
pVgEp
->
vgId
;
pVgEpNew
->
qmsg
=
strdup
(
pVgEp
->
qmsg
);
pVgEpNew
->
epSet
=
pVgEp
->
epSet
;
return
pVgEpNew
;
}
void
tDeleteSMqVgEp
(
SMqVgEp
*
pVgEp
)
{
if
(
pVgEp
->
qmsg
)
taosMemoryFree
(
pVgEp
->
qmsg
);
}
int32_t
tEncodeSMqVgEp
(
void
**
buf
,
const
SMqVgEp
*
pVgEp
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI32
(
buf
,
pVgEp
->
vgId
);
tlen
+=
taosEncodeString
(
buf
,
pVgEp
->
qmsg
);
tlen
+=
taosEncodeSEpSet
(
buf
,
&
pVgEp
->
epSet
);
return
tlen
;
}
void
*
tDecodeSMqVgEp
(
const
void
*
buf
,
SMqVgEp
*
pVgEp
)
{
buf
=
taosDecodeFixedI32
(
buf
,
&
pVgEp
->
vgId
);
buf
=
taosDecodeString
(
buf
,
&
pVgEp
->
qmsg
);
buf
=
taosDecodeSEpSet
(
buf
,
&
pVgEp
->
epSet
);
return
(
void
*
)
buf
;
}
SMqConsumerObj
*
tNewSMqConsumerObj
(
int64_t
consumerId
,
char
cgroup
[
TSDB_CGROUP_LEN
])
{
SMqConsumerObj
*
pConsumer
=
taosMemoryCalloc
(
1
,
sizeof
(
SMqConsumerObj
));
if
(
pConsumer
==
NULL
)
{
...
...
@@ -187,34 +328,6 @@ void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer) {
return
(
void
*
)
buf
;
}
SMqVgEp
*
tCloneSMqVgEp
(
const
SMqVgEp
*
pVgEp
)
{
SMqVgEp
*
pVgEpNew
=
taosMemoryMalloc
(
sizeof
(
SMqVgEp
));
if
(
pVgEpNew
==
NULL
)
return
NULL
;
pVgEpNew
->
vgId
=
pVgEp
->
vgId
;
pVgEpNew
->
qmsg
=
strdup
(
pVgEp
->
qmsg
);
pVgEpNew
->
epSet
=
pVgEp
->
epSet
;
return
pVgEpNew
;
}
void
tDeleteSMqVgEp
(
SMqVgEp
*
pVgEp
)
{
if
(
pVgEp
->
qmsg
)
taosMemoryFree
(
pVgEp
->
qmsg
);
}
int32_t
tEncodeSMqVgEp
(
void
**
buf
,
const
SMqVgEp
*
pVgEp
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI32
(
buf
,
pVgEp
->
vgId
);
tlen
+=
taosEncodeString
(
buf
,
pVgEp
->
qmsg
);
tlen
+=
taosEncodeSEpSet
(
buf
,
&
pVgEp
->
epSet
);
return
tlen
;
}
void
*
tDecodeSMqVgEp
(
const
void
*
buf
,
SMqVgEp
*
pVgEp
)
{
buf
=
taosDecodeFixedI32
(
buf
,
&
pVgEp
->
vgId
);
buf
=
taosDecodeString
(
buf
,
&
pVgEp
->
qmsg
);
buf
=
taosDecodeSEpSet
(
buf
,
&
pVgEp
->
epSet
);
return
(
void
*
)
buf
;
}
SMqConsumerEp
*
tCloneSMqConsumerEp
(
const
SMqConsumerEp
*
pConsumerEpOld
)
{
SMqConsumerEp
*
pConsumerEpNew
=
taosMemoryMalloc
(
sizeof
(
SMqConsumerEp
));
if
(
pConsumerEpNew
==
NULL
)
return
NULL
;
...
...
@@ -413,119 +526,6 @@ void *tDecodeSMqSubActionLogObj(const void *buf, SMqSubActionLogObj *pLog) {
return
(
void
*
)
buf
;
}
int32_t
tEncodeSStreamObj
(
SEncoder
*
pEncoder
,
const
SStreamObj
*
pObj
)
{
int32_t
sz
=
0
;
/*int32_t outputNameSz = 0;*/
if
(
tEncodeCStr
(
pEncoder
,
pObj
->
name
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pObj
->
sourceDb
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pObj
->
targetDb
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pObj
->
targetSTbName
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
targetStbUid
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
createTime
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
updateTime
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
uid
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
dbUid
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pObj
->
version
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pObj
->
status
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pObj
->
createdBy
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pObj
->
trigger
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pObj
->
triggerParam
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
waterMark
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pObj
->
fixedSinkVgId
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
pEncoder
,
pObj
->
smaId
)
<
0
)
return
-
1
;
if
(
tEncodeCStr
(
pEncoder
,
pObj
->
sql
)
<
0
)
return
-
1
;
/*if (tEncodeCStr(pEncoder, pObj->logicalPlan) < 0) return -1;*/
if
(
tEncodeCStr
(
pEncoder
,
pObj
->
physicalPlan
)
<
0
)
return
-
1
;
// TODO encode tasks
if
(
pObj
->
tasks
)
{
sz
=
taosArrayGetSize
(
pObj
->
tasks
);
}
if
(
tEncodeI32
(
pEncoder
,
sz
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SArray
*
pArray
=
taosArrayGetP
(
pObj
->
tasks
,
i
);
int32_t
innerSz
=
taosArrayGetSize
(
pArray
);
if
(
tEncodeI32
(
pEncoder
,
innerSz
)
<
0
)
return
-
1
;
for
(
int32_t
j
=
0
;
j
<
innerSz
;
j
++
)
{
SStreamTask
*
pTask
=
taosArrayGetP
(
pArray
,
j
);
if
(
tEncodeSStreamTask
(
pEncoder
,
pTask
)
<
0
)
return
-
1
;
}
}
if
(
tEncodeSSchemaWrapper
(
pEncoder
,
&
pObj
->
outputSchema
)
<
0
)
return
-
1
;
#if 0
if (pObj->ColAlias != NULL) {
outputNameSz = taosArrayGetSize(pObj->ColAlias);
}
if (tEncodeI32(pEncoder, outputNameSz) < 0) return -1;
for (int32_t i = 0; i < outputNameSz; i++) {
char *name = taosArrayGetP(pObj->ColAlias, i);
if (tEncodeCStr(pEncoder, name) < 0) return -1;
}
#endif
return
pEncoder
->
pos
;
}
int32_t
tDecodeSStreamObj
(
SDecoder
*
pDecoder
,
SStreamObj
*
pObj
)
{
if
(
tDecodeCStrTo
(
pDecoder
,
pObj
->
name
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pDecoder
,
pObj
->
sourceDb
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pDecoder
,
pObj
->
targetDb
)
<
0
)
return
-
1
;
if
(
tDecodeCStrTo
(
pDecoder
,
pObj
->
targetSTbName
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
targetStbUid
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
createTime
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
updateTime
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
uid
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
dbUid
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pObj
->
version
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pObj
->
status
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pObj
->
createdBy
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pObj
->
trigger
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pObj
->
triggerParam
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
waterMark
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pObj
->
fixedSinkVgId
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
pDecoder
,
&
pObj
->
smaId
)
<
0
)
return
-
1
;
if
(
tDecodeCStrAlloc
(
pDecoder
,
&
pObj
->
sql
)
<
0
)
return
-
1
;
/*if (tDecodeCStrAlloc(pDecoder, &pObj->logicalPlan) < 0) return -1;*/
if
(
tDecodeCStrAlloc
(
pDecoder
,
&
pObj
->
physicalPlan
)
<
0
)
return
-
1
;
pObj
->
tasks
=
NULL
;
int32_t
sz
;
if
(
tDecodeI32
(
pDecoder
,
&
sz
)
<
0
)
return
-
1
;
if
(
sz
!=
0
)
{
pObj
->
tasks
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
int32_t
innerSz
;
if
(
tDecodeI32
(
pDecoder
,
&
innerSz
)
<
0
)
return
-
1
;
SArray
*
pArray
=
taosArrayInit
(
innerSz
,
sizeof
(
void
*
));
for
(
int32_t
j
=
0
;
j
<
innerSz
;
j
++
)
{
SStreamTask
*
pTask
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamTask
));
if
(
pTask
==
NULL
)
return
-
1
;
if
(
tDecodeSStreamTask
(
pDecoder
,
pTask
)
<
0
)
return
-
1
;
taosArrayPush
(
pArray
,
&
pTask
);
}
taosArrayPush
(
pObj
->
tasks
,
&
pArray
);
}
}
if
(
tDecodeSSchemaWrapper
(
pDecoder
,
&
pObj
->
outputSchema
)
<
0
)
return
-
1
;
#if 0
int32_t outputNameSz;
if (tDecodeI32(pDecoder, &outputNameSz) < 0) return -1;
if (outputNameSz != 0) {
pObj->ColAlias = taosArrayInit(outputNameSz, sizeof(void *));
if (pObj->ColAlias == NULL) {
return -1;
}
}
for (int32_t i = 0; i < outputNameSz; i++) {
char *name;
if (tDecodeCStrAlloc(pDecoder, &name) < 0) return -1;
taosArrayPush(pObj->ColAlias, &name);
}
#endif
return
0
;
}
int32_t
tEncodeSMqOffsetObj
(
void
**
buf
,
const
SMqOffsetObj
*
pOffset
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeString
(
buf
,
pOffset
->
key
);
...
...
source/dnode/mnode/impl/src/mndScheduler.c
浏览文件 @
e0b3e97d
...
...
@@ -194,6 +194,7 @@ int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* p
// source
pTask
->
sourceType
=
TASK_SOURCE__MERGE
;
pTask
->
inputType
=
TASK_INPUT_TYPE__DATA_BLOCK
;
// exec
pTask
->
execType
=
TASK_EXEC__NONE
;
...
...
@@ -235,6 +236,7 @@ int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStr
pTask
->
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
// source
pTask
->
sourceType
=
TASK_SOURCE__MERGE
;
pTask
->
inputType
=
TASK_INPUT_TYPE__DATA_BLOCK
;
// exec
pTask
->
execType
=
TASK_EXEC__NONE
;
...
...
@@ -309,6 +311,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
SStreamTask
*
pTask
=
tNewSStreamTask
(
pStream
->
uid
);
// source part
pTask
->
sourceType
=
TASK_SOURCE__SCAN
;
pTask
->
inputType
=
TASK_INPUT_TYPE__SUMBIT_BLOCK
;
// sink part
if
(
level
==
0
)
{
...
...
@@ -372,6 +375,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
// source part, currently only support multi source
pTask
->
sourceType
=
TASK_SOURCE__PIPE
;
pTask
->
inputType
=
TASK_INPUT_TYPE__DATA_BLOCK
;
// sink part
pTask
->
sinkType
=
TASK_SINK__NONE
;
...
...
@@ -459,6 +463,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
// source part
pTask
->
sourceType
=
TASK_SOURCE__MERGE
;
pTask
->
inputType
=
TASK_INPUT_TYPE__DATA_BLOCK
;
// sink part
pTask
->
sinkType
=
TASK_SINK__NONE
;
...
...
source/dnode/mnode/impl/src/mndSma.c
浏览文件 @
e0b3e97d
...
...
@@ -242,26 +242,35 @@ SDbObj *mndAcquireDbBySma(SMnode *pMnode, const char *smaName) {
}
static
void
*
mndBuildVCreateSmaReq
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
SSmaObj
*
pSma
,
int32_t
*
pContLen
)
{
SEncoder
encoder
=
{
0
};
int32_t
contLen
=
0
;
SName
name
=
{
0
};
tNameFromString
(
&
name
,
pSma
->
name
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
SVCreateTSmaReq
req
=
{
0
};
req
.
tSma
.
version
=
0
;
req
.
tSma
.
intervalUnit
=
pSma
->
intervalUnit
;
req
.
tSma
.
slidingUnit
=
pSma
->
slidingUnit
;
req
.
tSma
.
timezoneInt
=
pSma
->
timezone
;
tstrncpy
(
req
.
tSma
.
indexName
,
(
char
*
)
tNameGetTableName
(
&
name
),
TSDB_INDEX_NAME_LEN
);
req
.
tSma
.
exprLen
=
pSma
->
exprLen
;
req
.
tSma
.
tagsFilterLen
=
pSma
->
tagsFilterLen
;
req
.
tSma
.
indexUid
=
pSma
->
uid
;
req
.
tSma
.
tableUid
=
pSma
->
stbUid
;
req
.
tSma
.
interval
=
pSma
->
interval
;
req
.
tSma
.
offset
=
pSma
->
offset
;
req
.
tSma
.
sliding
=
pSma
->
sliding
;
req
.
tSma
.
expr
=
pSma
->
expr
;
req
.
tSma
.
tagsFilter
=
pSma
->
tagsFilter
;
int32_t
contLen
=
tSerializeSVCreateTSmaReq
(
NULL
,
&
req
)
+
sizeof
(
SMsgHead
);
req
.
version
=
0
;
req
.
intervalUnit
=
pSma
->
intervalUnit
;
req
.
slidingUnit
=
pSma
->
slidingUnit
;
req
.
timezoneInt
=
pSma
->
timezone
;
tstrncpy
(
req
.
indexName
,
(
char
*
)
tNameGetTableName
(
&
name
),
TSDB_INDEX_NAME_LEN
);
req
.
exprLen
=
pSma
->
exprLen
;
req
.
tagsFilterLen
=
pSma
->
tagsFilterLen
;
req
.
indexUid
=
pSma
->
uid
;
req
.
tableUid
=
pSma
->
stbUid
;
req
.
interval
=
pSma
->
interval
;
req
.
offset
=
pSma
->
offset
;
req
.
sliding
=
pSma
->
sliding
;
req
.
expr
=
pSma
->
expr
;
req
.
tagsFilter
=
pSma
->
tagsFilter
;
// get length
int32_t
ret
=
0
;
tEncodeSize
(
tEncodeSVCreateTSmaReq
,
&
req
,
contLen
,
ret
);
if
(
ret
<
0
)
{
return
NULL
;
}
contLen
+=
sizeof
(
SMsgHead
);
SMsgHead
*
pHead
=
taosMemoryMalloc
(
contLen
);
if
(
pHead
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -272,22 +281,38 @@ static void *mndBuildVCreateSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSm
pHead
->
vgId
=
htonl
(
pVgroup
->
vgId
);
void
*
pBuf
=
POINTER_SHIFT
(
pHead
,
sizeof
(
SMsgHead
));
tSerializeSVCreateTSmaReq
(
&
pBuf
,
&
req
);
tEncoderInit
(
&
encoder
,
pBuf
,
contLen
-
sizeof
(
SMsgHead
));
if
(
tEncodeSVCreateTSmaReq
(
&
encoder
,
&
req
)
<
0
)
{
taosMemoryFreeClear
(
pHead
);
tEncoderClear
(
&
encoder
);
return
NULL
;
}
tEncoderClear
(
&
encoder
);
*
pContLen
=
contLen
;
return
pHead
;
}
static
void
*
mndBuildVDropSmaReq
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
SSmaObj
*
pSma
,
int32_t
*
pContLen
)
{
SEncoder
encoder
=
{
0
};
int32_t
contLen
;
SName
name
=
{
0
};
tNameFromString
(
&
name
,
pSma
->
name
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
SVDropTSmaReq
req
=
{
0
};
req
.
ver
=
0
;
req
.
indexUid
=
pSma
->
uid
;
tstrncpy
(
req
.
indexName
,
(
char
*
)
tNameGetTableName
(
&
name
),
TSDB_INDEX_NAME_LEN
);
int32_t
contLen
=
tSerializeSVDropTSmaReq
(
NULL
,
&
req
)
+
sizeof
(
SMsgHead
);
// get length
int32_t
ret
=
0
;
tEncodeSize
(
tEncodeSVDropTSmaReq
,
&
req
,
contLen
,
ret
);
if
(
ret
<
0
)
{
return
NULL
;
}
contLen
+=
sizeof
(
SMsgHead
);
SMsgHead
*
pHead
=
taosMemoryMalloc
(
contLen
);
if
(
pHead
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -298,7 +323,14 @@ static void *mndBuildVDropSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSma,
pHead
->
vgId
=
htonl
(
pVgroup
->
vgId
);
void
*
pBuf
=
POINTER_SHIFT
(
pHead
,
sizeof
(
SMsgHead
));
tDeserializeSVDropTSmaReq
(
&
pBuf
,
&
req
);
tEncoderInit
(
&
encoder
,
pBuf
,
contLen
-
sizeof
(
SMsgHead
));
if
(
tEncodeSVDropTSmaReq
(
&
encoder
,
&
req
)
<
0
)
{
taosMemoryFreeClear
(
pHead
);
tEncoderClear
(
&
encoder
);
return
NULL
;
}
tEncoderClear
(
&
encoder
);
*
pContLen
=
contLen
;
return
pHead
;
...
...
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
e0b3e97d
...
...
@@ -425,6 +425,10 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
void
*
pBuf
=
POINTER_SHIFT
(
pHead
,
sizeof
(
SMsgHead
));
tEncoderInit
(
&
encoder
,
pBuf
,
contLen
-
sizeof
(
SMsgHead
));
if
(
tEncodeSVCreateStbReq
(
&
encoder
,
&
req
)
<
0
)
{
taosMemoryFreeClear
(
pHead
);
taosMemoryFreeClear
(
req
.
pRSmaParam
.
qmsg1
);
taosMemoryFreeClear
(
req
.
pRSmaParam
.
qmsg2
);
tEncoderClear
(
&
encoder
);
return
NULL
;
}
tEncoderClear
(
&
encoder
);
...
...
source/dnode/mnode/impl/test/trans/trans2.cpp
浏览文件 @
e0b3e97d
source/dnode/vnode/CMakeLists.txt
浏览文件 @
e0b3e97d
...
...
@@ -18,12 +18,21 @@ target_sources(
"src/meta/metaOpen.c"
"src/meta/metaIdx.c"
"src/meta/metaTable.c"
"src/meta/metaSma.c"
"src/meta/metaQuery.c"
"src/meta/metaCommit.c"
"src/meta/metaEntry.c"
# sma
"src/sma/sma.c"
"src/sma/smaTDBImpl.c"
"src/sma/smaEnv.c"
"src/sma/smaOpen.c"
"src/sma/smaRollup.c"
"src/sma/smaTimeRange.c"
# tsdb
"src/tsdb/tsdbTDBImpl.c"
#
"src/tsdb/tsdbTDBImpl.c"
"src/tsdb/tsdbCommit.c"
"src/tsdb/tsdbCommit2.c"
"src/tsdb/tsdbFile.c"
...
...
@@ -33,7 +42,7 @@ target_sources(
"src/tsdb/tsdbMemTable2.c"
"src/tsdb/tsdbRead.c"
"src/tsdb/tsdbReadImpl.c"
"src/tsdb/tsdbSma.c"
#
"src/tsdb/tsdbSma.c"
"src/tsdb/tsdbWrite.c"
# tq
...
...
source/dnode/vnode/inc/vnode.h
浏览文件 @
e0b3e97d
...
...
@@ -191,6 +191,9 @@ struct SMetaEntry {
int32_t
ttlDays
;
SSchemaWrapper
schema
;
}
ntbEntry
;
struct
{
STSma
*
tsma
;
}
smaEntry
;
};
};
...
...
source/dnode/vnode/src/inc/meta.h
浏览文件 @
e0b3e97d
...
...
@@ -73,6 +73,7 @@ struct SMeta {
TDB
*
pCtbIdx
;
TDB
*
pTagIdx
;
TDB
*
pTtlIdx
;
TDB
*
pSmaIdx
;
SMetaIdx
*
pIdx
;
};
...
...
@@ -108,6 +109,11 @@ typedef struct {
tb_uid_t
uid
;
}
STtlIdxKey
;
typedef
struct
{
tb_uid_t
uid
;
int64_t
smaUid
;
}
SSmaIdxKey
;
#if 1
SMSmaCursor
*
metaOpenSmaCursor
(
SMeta
*
pMeta
,
tb_uid_t
uid
);
...
...
@@ -118,7 +124,7 @@ int64_t metaSmaCursorNext(SMSmaCursor* pSmaCur);
// SMetaDB
int
metaOpenDB
(
SMeta
*
pMeta
);
void
metaCloseDB
(
SMeta
*
pMeta
);
//
int metaSaveTableToDB(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
int
metaSaveTableToDB
(
SMeta
*
pMeta
,
STbCfg
*
pTbCfg
,
STbDdlH
*
pHandle
);
int
metaRemoveTableFromDb
(
SMeta
*
pMeta
,
tb_uid_t
uid
);
int
metaSaveSmaToDB
(
SMeta
*
pMeta
,
STSma
*
pTbCfg
);
int
metaRemoveSmaFromDb
(
SMeta
*
pMeta
,
int64_t
indexUid
);
...
...
source/dnode/vnode/src/inc/sma.h
0 → 100644
浏览文件 @
e0b3e97d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_VNODE_SMA_H_
#define _TD_VNODE_SMA_H_
#include "vnodeInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
// smaDebug ================
// clang-format off
#define smaFatal(...) do { if (smaDebugFlag & DEBUG_FATAL) { taosPrintLog("SMA FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0)
#define smaError(...) do { if (smaDebugFlag & DEBUG_ERROR) { taosPrintLog("SMA ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0)
#define smaWarn(...) do { if (smaDebugFlag & DEBUG_WARN) { taosPrintLog("SMA WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0)
#define smaInfo(...) do { if (smaDebugFlag & DEBUG_INFO) { taosPrintLog("SMA ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0)
#define smaDebug(...) do { if (smaDebugFlag & DEBUG_DEBUG) { taosPrintLog("SMA ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0)
#define smaTrace(...) do { if (smaDebugFlag & DEBUG_TRACE) { taosPrintLog("SMA ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0)
// clang-format on
typedef
struct
SSmaEnv
SSmaEnv
;
typedef
struct
SSmaStat
SSmaStat
;
typedef
struct
SSmaStatItem
SSmaStatItem
;
typedef
struct
SSmaKey
SSmaKey
;
typedef
struct
SRSmaInfo
SRSmaInfo
;
#define SMA_IVLD_FID INT_MIN
struct
SSmaEnv
{
TdThreadRwlock
lock
;
int8_t
type
;
TXN
txn
;
void
*
pPool
;
// SPoolMem
SDiskID
did
;
TENV
*
dbEnv
;
// TODO: If it's better to put it in smaIndex level?
char
*
path
;
// relative path
SSmaStat
*
pStat
;
};
#define SMA_ENV_LOCK(env) ((env)->lock)
#define SMA_ENV_TYPE(env) ((env)->type)
#define SMA_ENV_DID(env) ((env)->did)
#define SMA_ENV_ENV(env) ((env)->dbEnv)
#define SMA_ENV_PATH(env) ((env)->path)
#define SMA_ENV_STAT(env) ((env)->pStat)
#define SMA_ENV_STAT_ITEMS(env) ((env)->pStat->smaStatItems)
struct
SSmaStatItem
{
/**
* @brief The field 'state' is here to demonstrate if one smaIndex is ready to provide service.
* - TSDB_SMA_STAT_OK: 1) The sma calculation of history data is finished; 2) Or recevied information from
* Streaming Module or TSDB local persistence.
* - TSDB_SMA_STAT_EXPIRED: 1) If sma calculation of history TS data is not finished; 2) Or if the TSDB is open,
* without information about its previous state.
* - TSDB_SMA_STAT_DROPPED: 1)sma dropped
* N.B. only applicable to tsma
*/
int8_t
state
;
// ETsdbSmaStat
SHashObj
*
expiredWindows
;
// key: skey of time window, value: N/A
STSma
*
pTSma
;
// cache schema
};
struct
SSmaStat
{
union
{
SHashObj
*
smaStatItems
;
// key: indexUid, value: SSmaStatItem for tsma
SHashObj
*
rsmaInfoHash
;
// key: stbUid, value: SRSmaInfo;
};
T_REF_DECLARE
()
};
#define SMA_STAT_ITEMS(s) ((s)->smaStatItems)
#define SMA_STAT_INFO_HASH(s) ((s)->rsmaInfoHash)
struct
SSmaKey
{
TSKEY
skey
;
int64_t
groupId
;
};
typedef
struct
SDBFile
SDBFile
;
struct
SDBFile
{
int32_t
fid
;
TDB
*
pDB
;
char
*
path
;
};
int32_t
tdSmaBeginCommit
(
SSmaEnv
*
pEnv
);
int32_t
tdSmaEndCommit
(
SSmaEnv
*
pEnv
);
int32_t
smaOpenDBEnv
(
TENV
**
ppEnv
,
const
char
*
path
);
int32_t
smaCloseDBEnv
(
TENV
*
pEnv
);
int32_t
smaOpenDBF
(
TENV
*
pEnv
,
SDBFile
*
pDBF
);
int32_t
smaCloseDBF
(
SDBFile
*
pDBF
);
int32_t
smaSaveSmaToDB
(
SDBFile
*
pDBF
,
void
*
pKey
,
int32_t
keyLen
,
void
*
pVal
,
int32_t
valLen
,
TXN
*
txn
);
void
*
smaGetSmaDataByKey
(
SDBFile
*
pDBF
,
const
void
*
pKey
,
int32_t
keyLen
,
int32_t
*
valLen
);
void
tdDestroySmaEnv
(
SSmaEnv
*
pSmaEnv
);
void
*
tdFreeSmaEnv
(
SSmaEnv
*
pSmaEnv
);
#if 0
int32_t tbGetTSmaStatus(SSma *pSma, STSma *param, void *result);
int32_t tbRemoveTSmaData(SSma *pSma, STSma *param, STimeWindow *pWin);
#endif
static
FORCE_INLINE
int32_t
tdEncodeTSmaKey
(
int64_t
groupId
,
TSKEY
tsKey
,
void
**
pData
)
{
int32_t
len
=
0
;
len
+=
taosEncodeFixedI64
(
pData
,
tsKey
);
len
+=
taosEncodeFixedI64
(
pData
,
groupId
);
return
len
;
}
int32_t
tdInitSma
(
SSma
*
pSma
);
int32_t
tdDropTSma
(
SSma
*
pSma
,
char
*
pMsg
);
int32_t
tdDropTSmaData
(
SSma
*
pSma
,
int64_t
indexUid
);
int32_t
tdInsertRSmaData
(
SSma
*
pSma
,
char
*
msg
);
int32_t
tdRefSmaStat
(
SSma
*
pSma
,
SSmaStat
*
pStat
);
int32_t
tdUnRefSmaStat
(
SSma
*
pSma
,
SSmaStat
*
pStat
);
int32_t
tdCheckAndInitSmaEnv
(
SSma
*
pSma
,
int8_t
smaType
);
int32_t
tdLockSma
(
SSma
*
pSma
);
int32_t
tdUnLockSma
(
SSma
*
pSma
);
int32_t
tdProcessTSmaInsertImpl
(
SSma
*
pSma
,
int64_t
indexUid
,
const
char
*
msg
);
static
FORCE_INLINE
int16_t
tdTSmaAdd
(
SSma
*
pSma
,
int16_t
n
)
{
return
atomic_add_fetch_16
(
&
SMA_TSMA_NUM
(
pSma
),
n
);
}
static
FORCE_INLINE
int16_t
tdTSmaSub
(
SSma
*
pSma
,
int16_t
n
)
{
return
atomic_sub_fetch_16
(
&
SMA_TSMA_NUM
(
pSma
),
n
);
}
static
FORCE_INLINE
int32_t
tdRLockSmaEnv
(
SSmaEnv
*
pEnv
)
{
int
code
=
taosThreadRwlockRdlock
(
&
(
pEnv
->
lock
));
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
return
0
;
}
static
FORCE_INLINE
int32_t
tdWLockSmaEnv
(
SSmaEnv
*
pEnv
)
{
int
code
=
taosThreadRwlockWrlock
(
&
(
pEnv
->
lock
));
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
return
0
;
}
static
FORCE_INLINE
int32_t
tdUnLockSmaEnv
(
SSmaEnv
*
pEnv
)
{
int
code
=
taosThreadRwlockUnlock
(
&
(
pEnv
->
lock
));
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
return
0
;
}
static
FORCE_INLINE
int8_t
tdSmaStat
(
SSmaStatItem
*
pStatItem
)
{
if
(
pStatItem
)
{
return
atomic_load_8
(
&
pStatItem
->
state
);
}
return
TSDB_SMA_STAT_UNKNOWN
;
}
static
FORCE_INLINE
bool
tdSmaStatIsOK
(
SSmaStatItem
*
pStatItem
,
int8_t
*
state
)
{
if
(
!
pStatItem
)
{
return
false
;
}
if
(
state
)
{
*
state
=
atomic_load_8
(
&
pStatItem
->
state
);
return
*
state
==
TSDB_SMA_STAT_OK
;
}
return
atomic_load_8
(
&
pStatItem
->
state
)
==
TSDB_SMA_STAT_OK
;
}
static
FORCE_INLINE
bool
tdSmaStatIsExpired
(
SSmaStatItem
*
pStatItem
)
{
return
pStatItem
?
(
atomic_load_8
(
&
pStatItem
->
state
)
&
TSDB_SMA_STAT_EXPIRED
)
:
true
;
}
static
FORCE_INLINE
bool
tdSmaStatIsDropped
(
SSmaStatItem
*
pStatItem
)
{
return
pStatItem
?
(
atomic_load_8
(
&
pStatItem
->
state
)
&
TSDB_SMA_STAT_DROPPED
)
:
true
;
}
static
FORCE_INLINE
void
tdSmaStatSetOK
(
SSmaStatItem
*
pStatItem
)
{
if
(
pStatItem
)
{
atomic_store_8
(
&
pStatItem
->
state
,
TSDB_SMA_STAT_OK
);
}
}
static
FORCE_INLINE
void
tdSmaStatSetExpired
(
SSmaStatItem
*
pStatItem
)
{
if
(
pStatItem
)
{
atomic_or_fetch_8
(
&
pStatItem
->
state
,
TSDB_SMA_STAT_EXPIRED
);
}
}
static
FORCE_INLINE
void
tdSmaStatSetDropped
(
SSmaStatItem
*
pStatItem
)
{
if
(
pStatItem
)
{
atomic_or_fetch_8
(
&
pStatItem
->
state
,
TSDB_SMA_STAT_DROPPED
);
}
}
static
int32_t
tdInitSmaStat
(
SSmaStat
**
pSmaStat
,
int8_t
smaType
);
void
*
tdFreeSmaStatItem
(
SSmaStatItem
*
pSmaStatItem
);
static
int32_t
tdDestroySmaState
(
SSmaStat
*
pSmaStat
,
int8_t
smaType
);
static
SSmaEnv
*
tdNewSmaEnv
(
const
SSma
*
pSma
,
int8_t
smaType
,
const
char
*
path
,
SDiskID
did
);
static
int32_t
tdInitSmaEnv
(
SSma
*
pSma
,
int8_t
smaType
,
const
char
*
path
,
SDiskID
did
,
SSmaEnv
**
pEnv
);
void
*
tdFreeRSmaInfo
(
SRSmaInfo
*
pInfo
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_VNODE_SMA_H_*/
\ No newline at end of file
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
e0b3e97d
...
...
@@ -60,31 +60,22 @@ typedef struct {
TSKEY
minKey
;
}
SRtn
;
struct
SSmaEnvs
{
int16_t
nTSma
;
int16_t
nRSma
;
SSmaEnv
*
pTSmaEnv
;
SSmaEnv
*
pRSmaEnv
;
};
#define TSDB_DATA_DIR_LEN 6
struct
STsdb
{
char
*
path
;
SVnode
*
pVnode
;
TdThreadMutex
mutex
;
char
dir
[
TSDB_DATA_DIR_LEN
];
bool
repoLocked
;
int8_t
level
;
// retention level
STsdbKeepCfg
keepCfg
;
STsdbMemTable
*
mem
;
STsdbMemTable
*
imem
;
SRtn
rtn
;
STsdbFS
*
fs
;
SSmaEnvs
smaEnvs
;
};
#if 1 // ======================================
typedef
struct
SSmaStat
SSmaStat
;
struct
STable
{
uint64_t
tid
;
uint64_t
uid
;
...
...
@@ -95,10 +86,6 @@ struct STable {
#define TABLE_UID(t) (t)->uid
int
tsdbPrepareCommit
(
STsdb
*
pTsdb
);
int32_t
tsdbInitSma
(
STsdb
*
pTsdb
);
int32_t
tsdbDropTSma
(
STsdb
*
pTsdb
,
char
*
pMsg
);
int32_t
tsdbDropTSmaData
(
STsdb
*
pTsdb
,
int64_t
indexUid
);
int32_t
tsdbInsertRSmaData
(
STsdb
*
pTsdb
,
char
*
msg
);
typedef
enum
{
TSDB_FILE_HEAD
=
0
,
// .head
TSDB_FILE_DATA
,
// .data
...
...
@@ -107,8 +94,6 @@ typedef enum {
TSDB_FILE_SMAL
,
// .smal(Block-wise SMA)
TSDB_FILE_MAX
,
//
TSDB_FILE_META
,
// meta
TSDB_FILE_TSMA
,
// v2t100.${sma_index_name}, Time-range-wise SMA
TSDB_FILE_RSMA
,
// v2r100.${sma_index_name}, Time-range-wise Rollup SMA
}
E_TSDB_FILE_T
;
typedef
struct
{
...
...
@@ -186,15 +171,10 @@ struct STsdbFS {
#define REPO_ID(r) TD_VID((r)->pVnode)
#define REPO_CFG(r) (&(r)->pVnode->config.tsdbCfg)
#define REPO_KEEP_CFG(r) (&(r)->keepCfg)
#define REPO_LEVEL(r) ((r)->level)
#define REPO_FS(r) ((r)->fs)
#define REPO_META(r) ((r)->pVnode->pMeta)
#define REPO_TFS(r) ((r)->pVnode->pTfs)
#define IS_REPO_LOCKED(r) ((r)->repoLocked)
#define REPO_TSMA_NUM(r) ((r)->smaEnvs.nTSma)
#define REPO_RSMA_NUM(r) ((r)->smaEnvs.nRSma)
#define REPO_TSMA_ENV(r) ((r)->smaEnvs.pTSmaEnv)
#define REPO_RSMA_ENV(r) ((r)->smaEnvs.pRSmaEnv)
int
tsdbLockRepo
(
STsdb
*
pTsdb
);
int
tsdbUnlockRepo
(
STsdb
*
pTsdb
);
...
...
@@ -794,25 +774,6 @@ typedef struct {
}
SFSHeader
;
// ================== TSDB File System Meta
/**
* @brief Directory structure of .tsma data files.
*
* /vnode2/tsdb $ tree tsma/
* tsma/
* ├── v2f100.index_name_1
* ├── v2f101.index_name_1
* ├── v2f102.index_name_1
* ├── v2f1900.index_name_3
* ├── v2f1901.index_name_3
* ├── v2f1902.index_name_3
* ├── v2f200.index_name_2
* ├── v2f201.index_name_2
* └── v2f202.index_name_2
*
* 0 directories, 9 files
*/
#define FS_CURRENT_STATUS(pfs) ((pfs)->cstatus)
#define FS_NEW_STATUS(pfs) ((pfs)->nstatus)
#define FS_IN_TXN(pfs) (pfs)->intxn
...
...
@@ -874,43 +835,6 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) {
return
0
;
}
typedef
struct
SSmaKey
SSmaKey
;
struct
SSmaKey
{
TSKEY
skey
;
int64_t
groupId
;
};
typedef
struct
SDBFile
SDBFile
;
struct
SDBFile
{
int32_t
fid
;
TDB
*
pDB
;
char
*
path
;
};
int32_t
tsdbOpenDBEnv
(
TENV
**
ppEnv
,
const
char
*
path
);
int32_t
tsdbCloseDBEnv
(
TENV
*
pEnv
);
int32_t
tsdbOpenDBF
(
TENV
*
pEnv
,
SDBFile
*
pDBF
);
int32_t
tsdbCloseDBF
(
SDBFile
*
pDBF
);
int32_t
tsdbSaveSmaToDB
(
SDBFile
*
pDBF
,
void
*
pKey
,
int32_t
keyLen
,
void
*
pVal
,
int32_t
valLen
,
TXN
*
txn
);
void
*
tsdbGetSmaDataByKey
(
SDBFile
*
pDBF
,
const
void
*
pKey
,
int32_t
keyLen
,
int32_t
*
valLen
);
void
tsdbDestroySmaEnv
(
SSmaEnv
*
pSmaEnv
);
void
*
tsdbFreeSmaEnv
(
SSmaEnv
*
pSmaEnv
);
#if 0
int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result);
int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin);
#endif
// internal func
static
FORCE_INLINE
int32_t
tsdbEncodeTSmaKey
(
int64_t
groupId
,
TSKEY
tsKey
,
void
**
pData
)
{
int32_t
len
=
0
;
len
+=
taosEncodeFixedI64
(
pData
,
tsKey
);
len
+=
taosEncodeFixedI64
(
pData
,
groupId
);
return
len
;
}
#endif
#ifdef __cplusplus
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
e0b3e97d
...
...
@@ -49,11 +49,13 @@ extern "C" {
typedef
struct
SVnodeInfo
SVnodeInfo
;
typedef
struct
SMeta
SMeta
;
typedef
struct
SSma
SSma
;
typedef
struct
STsdb
STsdb
;
typedef
struct
STQ
STQ
;
typedef
struct
SVState
SVState
;
typedef
struct
SVBufPool
SVBufPool
;
typedef
struct
SQWorker
SQHandle
;
typedef
struct
STsdbKeepCfg
STsdbKeepCfg
;
#define VNODE_META_DIR "meta"
#define VNODE_TSDB_DIR "tsdb"
...
...
@@ -90,17 +92,14 @@ tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur);
SArray
*
metaGetSmaTbUids
(
SMeta
*
pMeta
,
bool
isDup
);
void
*
metaGetSmaInfoByIndex
(
SMeta
*
pMeta
,
int64_t
indexUid
,
bool
isDecode
);
STSmaWrapper
*
metaGetSmaInfoByTable
(
SMeta
*
pMeta
,
tb_uid_t
uid
);
int32_t
metaCreateTSma
(
SMeta
*
pMeta
,
SSmaCfg
*
pCfg
);
int32_t
metaCreateTSma
(
SMeta
*
pMeta
,
int64_t
version
,
SSmaCfg
*
pCfg
);
int32_t
metaDropTSma
(
SMeta
*
pMeta
,
int64_t
indexUid
);
// tsdb
int
tsdbOpen
(
SVnode
*
pVnode
,
int8_t
type
);
int
tsdbClose
(
STsdb
*
pTsdb
);
int
tsdbOpen
(
SVnode
*
pVnode
,
STsdb
**
ppTsdb
,
const
char
*
dir
,
STsdbKeepCfg
*
pKeepCfg
);
int
tsdbClose
(
STsdb
*
*
pTsdb
);
int
tsdbBegin
(
STsdb
*
pTsdb
);
int
tsdbCommit
(
STsdb
*
pTsdb
);
int32_t
tsdbUpdateSmaWindow
(
STsdb
*
pTsdb
,
SSubmitReq
*
pMsg
,
int64_t
version
);
int32_t
tsdbCreateTSma
(
STsdb
*
pTsdb
,
char
*
pMsg
);
int32_t
tsdbInsertTSmaData
(
STsdb
*
pTsdb
,
int64_t
indexUid
,
const
char
*
msg
);
int
tsdbInsertData
(
STsdb
*
pTsdb
,
int64_t
version
,
SSubmitReq
*
pMsg
,
SSubmitRsp
*
pRsp
);
int
tsdbInsertTableData
(
STsdb
*
pTsdb
,
SSubmitMsgIter
*
pMsgIter
,
SSubmitBlk
*
pBlock
,
SSubmitBlkRsp
*
pRsp
);
tsdbReaderT
*
tsdbQueryTables
(
SVnode
*
pVnode
,
SQueryTableDataCond
*
pCond
,
STableGroupInfo
*
groupList
,
uint64_t
qId
,
...
...
@@ -121,13 +120,31 @@ int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t wo
int32_t
tqProcessPollReq
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
,
int32_t
workerId
);
// sma
int32_t
smaOpen
(
SVnode
*
pVnode
);
int32_t
smaClose
(
SSma
*
pSma
);
int32_t
tdUpdateExpireWindow
(
SSma
*
pSma
,
SSubmitReq
*
pMsg
,
int64_t
version
);
int32_t
tdProcessTSmaCreate
(
SSma
*
pSma
,
char
*
pMsg
);
int32_t
tdProcessTSmaInsert
(
SSma
*
pSma
,
int64_t
indexUid
,
const
char
*
msg
);
int32_t
tdProcessRSmaCreate
(
SSma
*
pSma
,
SMeta
*
pMeta
,
SVCreateStbReq
*
pReq
,
SMsgCb
*
pMsgCb
);
int32_t
tdProcessRSmaSubmit
(
SSma
*
pSma
,
void
*
pMsg
,
int32_t
inputType
);
int32_t
tdFetchTbUidList
(
SSma
*
pSma
,
STbUidStore
**
ppStore
,
tb_uid_t
suid
,
tb_uid_t
uid
);
int32_t
tdUpdateTbUidList
(
SSma
*
pSma
,
STbUidStore
*
pUidStore
);
void
tdUidStoreDestory
(
STbUidStore
*
pStore
);
void
*
tdUidStoreFree
(
STbUidStore
*
pStore
);
#if 0
int32_t tsdbUpdateSmaWindow(STsdb* pTsdb, SSubmitReq* pMsg, int64_t version);
int32_t tsdbCreateTSma(STsdb* pTsdb, char* pMsg);
int32_t tsdbInsertTSmaData(STsdb* pTsdb, int64_t indexUid, const char* msg);
int32_t tsdbRegisterRSma(STsdb* pTsdb, SMeta* pMeta, SVCreateStbReq* pReq, SMsgCb* pMsgCb);
int32_t tsdbFetchTbUidList(STsdb* pTsdb, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid);
int32_t tsdbUpdateTbUidList(STsdb* pTsdb, STbUidStore* pUidStore);
void tsdbUidStoreDestory(STbUidStore* pStore);
void* tsdbUidStoreFree(STbUidStore* pStore);
int32_t tsdbTriggerRSma(STsdb* pTsdb, void* pMsg, int32_t inputType);
#endif
typedef
struct
{
int8_t
streamType
;
// sma or other
...
...
@@ -164,13 +181,13 @@ typedef enum {
TSDB_TYPE_RSMA_L2
=
4
,
// RSMA Level 2
}
ETsdbType
;
typedef
struct
{
struct
STsdbKeepCfg
{
int8_t
precision
;
// precision always be used with below keep cfgs
int32_t
days
;
int32_t
keep0
;
int32_t
keep1
;
int32_t
keep2
;
}
STsdbKeepCfg
;
};
struct
SVnode
{
char
*
path
;
...
...
@@ -183,9 +200,8 @@ struct SVnode {
SVBufPool
*
onCommit
;
SVBufPool
*
onRecycle
;
SMeta
*
pMeta
;
SSma
*
pSma
;
STsdb
*
pTsdb
;
STsdb
*
pRSma1
;
STsdb
*
pRSma2
;
SWal
*
pWal
;
STQ
*
pTq
;
SSink
*
pSink
;
...
...
@@ -194,10 +210,12 @@ struct SVnode {
SQHandle
*
pQuery
;
};
#define TD_VID(PVNODE) (PVNODE)->config.vgId
#define VND_TSDB(vnd) ((vnd)->pTsdb)
#define VND_RSMA0(vnd) ((vnd)->pTsdb)
#define VND_RSMA1(vnd) ((vnd)->p
RSma
1)
#define VND_RSMA2(vnd) ((vnd)->p
RSma
2)
#define VND_RSMA1(vnd) ((vnd)->p
Sma->pRSmaTsdb
1)
#define VND_RSMA2(vnd) ((vnd)->p
Sma->pRSmaTsdb
2)
#define VND_RETENTIONS(vnd) (&(vnd)->config.tsdbCfg.retentions)
struct
STbUidStore
{
...
...
@@ -207,7 +225,29 @@ struct STbUidStore {
SHashObj
*
uidHash
;
};
#define TD_VID(PVNODE) (PVNODE)->config.vgId
struct
SSma
{
int16_t
nTSma
;
bool
locked
;
TdThreadMutex
mutex
;
SVnode
*
pVnode
;
STsdb
*
pRSmaTsdb1
;
STsdb
*
pRSmaTsdb2
;
void
*
pTSmaEnv
;
void
*
pRSmaEnv
;
};
#define SMA_CFG(s) (&(s)->pVnode->config)
#define SMA_TSDB_CFG(s) (&(s)->pVnode->config.tsdbCfg)
#define SMA_LOCKED(s) ((s)->locked)
#define SMA_META(s) ((s)->pVnode->pMeta)
#define SMA_VID(s) TD_VID((s)->pVnode)
#define SMA_TFS(s) ((s)->pVnode->pTfs)
#define SMA_TSMA_NUM(s) ((s)->nTSma)
#define SMA_TSMA_ENV(s) ((s)->pTSmaEnv)
#define SMA_RSMA_ENV(s) ((s)->pRSmaEnv)
#define SMA_RSMA_TSDB0(s) ((s)->pVnode->pTsdb)
#define SMA_RSMA_TSDB1(s) ((s)->pRSmaTsdb1)
#define SMA_RSMA_TSDB2(s) ((s)->pRSmaTsdb2)
static
FORCE_INLINE
bool
vnodeIsRollup
(
SVnode
*
pVnode
)
{
SRetention
*
pRetention
=
&
(
pVnode
->
config
.
tsdbCfg
.
retentions
[
0
]);
...
...
source/dnode/vnode/src/meta/metaEntry.c
浏览文件 @
e0b3e97d
...
...
@@ -35,6 +35,8 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) {
if
(
tEncodeI64
(
pCoder
,
pME
->
ntbEntry
.
ctime
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pCoder
,
pME
->
ntbEntry
.
ttlDays
)
<
0
)
return
-
1
;
if
(
tEncodeSSchemaWrapper
(
pCoder
,
&
pME
->
ntbEntry
.
schema
)
<
0
)
return
-
1
;
}
else
if
(
pME
->
type
==
TSDB_TSMA_TABLE
)
{
if
(
tEncodeTSma
(
pCoder
,
pME
->
smaEntry
.
tsma
)
<
0
)
return
-
1
;
}
else
{
ASSERT
(
0
);
}
...
...
@@ -64,6 +66,8 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) {
if
(
tDecodeI64
(
pCoder
,
&
pME
->
ntbEntry
.
ctime
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pCoder
,
&
pME
->
ntbEntry
.
ttlDays
)
<
0
)
return
-
1
;
if
(
tDecodeSSchemaWrapper
(
pCoder
,
&
pME
->
ntbEntry
.
schema
)
<
0
)
return
-
1
;
}
else
if
(
pME
->
type
==
TSDB_TSMA_TABLE
)
{
if
(
tDecodeTSma
(
pCoder
,
pME
->
smaEntry
.
tsma
)
<
0
)
return
-
1
;
}
else
{
ASSERT
(
0
);
}
...
...
source/dnode/vnode/src/meta/metaIdx.c
浏览文件 @
e0b3e97d
...
...
@@ -113,34 +113,3 @@ int metaRemoveTableFromIdx(SMeta *pMeta, tb_uid_t uid) {
// TODO
return
0
;
}
\ No newline at end of file
int32_t
metaCreateTSma
(
SMeta
*
pMeta
,
SSmaCfg
*
pCfg
)
{
// TODO: Validate the cfg
// The table uid should exists and be super table or common table.
// Check other cfg value
// TODO: add atomicity
#ifdef META_REFACT
#else
if
(
metaSaveSmaToDB
(
pMeta
,
&
pCfg
->
tSma
)
<
0
)
{
// TODO: handle error
return
-
1
;
}
#endif
return
TSDB_CODE_SUCCESS
;
}
int32_t
metaDropTSma
(
SMeta
*
pMeta
,
int64_t
indexUid
)
{
// TODO: Validate the cfg
// TODO: add atomicity
#ifdef META_REFACT
#else
if
(
metaRemoveSmaFromDb
(
pMeta
,
indexUid
)
<
0
)
{
// TODO: handle error
return
-
1
;
}
#endif
return
TSDB_CODE_SUCCESS
;
}
\ No newline at end of file
source/dnode/vnode/src/meta/metaOpen.c
浏览文件 @
e0b3e97d
...
...
@@ -21,6 +21,7 @@ static int ctbIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL
static
int
tagIdxKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int
ttlIdxKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int
uidIdxKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int
smaIdxKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int32_t
metaInitLock
(
SMeta
*
pMeta
)
{
return
taosThreadRwlockInit
(
&
pMeta
->
lock
,
NULL
);
}
static
int32_t
metaDestroyLock
(
SMeta
*
pMeta
)
{
return
taosThreadRwlockDestroy
(
&
pMeta
->
lock
);
}
...
...
@@ -104,6 +105,13 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
goto
_err
;
}
// open pSmaIdx
ret
=
tdbDbOpen
(
"sma.idx"
,
sizeof
(
SSmaIdxKey
),
0
,
smaIdxKeyCmpr
,
pMeta
->
pEnv
,
&
pMeta
->
pSmaIdx
);
if
(
ret
<
0
)
{
metaError
(
"vgId:%d failed to open meta sma index since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
goto
_err
;
}
// open index
if
(
metaOpenIdx
(
pMeta
)
<
0
)
{
metaError
(
"vgId:%d failed to open meta index since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
...
...
@@ -117,11 +125,12 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
_err:
if
(
pMeta
->
pIdx
)
metaCloseIdx
(
pMeta
);
if
(
pMeta
->
pSmaIdx
)
tdbDbClose
(
pMeta
->
pSmaIdx
);
if
(
pMeta
->
pTtlIdx
)
tdbDbClose
(
pMeta
->
pTtlIdx
);
if
(
pMeta
->
pTagIdx
)
tdbDbClose
(
pMeta
->
pTagIdx
);
if
(
pMeta
->
pCtbIdx
)
tdbDbClose
(
pMeta
->
pCtbIdx
);
if
(
pMeta
->
pNameIdx
)
tdbDbClose
(
pMeta
->
pNameIdx
);
if
(
pMeta
->
p
Name
Idx
)
tdbDbClose
(
pMeta
->
pUidIdx
);
if
(
pMeta
->
p
Uid
Idx
)
tdbDbClose
(
pMeta
->
pUidIdx
);
if
(
pMeta
->
pSkmDb
)
tdbDbClose
(
pMeta
->
pSkmDb
);
if
(
pMeta
->
pTbDb
)
tdbDbClose
(
pMeta
->
pTbDb
);
if
(
pMeta
->
pEnv
)
tdbEnvClose
(
pMeta
->
pEnv
);
...
...
@@ -133,11 +142,12 @@ _err:
int
metaClose
(
SMeta
*
pMeta
)
{
if
(
pMeta
)
{
if
(
pMeta
->
pIdx
)
metaCloseIdx
(
pMeta
);
if
(
pMeta
->
pSmaIdx
)
tdbDbClose
(
pMeta
->
pSmaIdx
);
if
(
pMeta
->
pTtlIdx
)
tdbDbClose
(
pMeta
->
pTtlIdx
);
if
(
pMeta
->
pTagIdx
)
tdbDbClose
(
pMeta
->
pTagIdx
);
if
(
pMeta
->
pCtbIdx
)
tdbDbClose
(
pMeta
->
pCtbIdx
);
if
(
pMeta
->
pNameIdx
)
tdbDbClose
(
pMeta
->
pNameIdx
);
if
(
pMeta
->
p
Name
Idx
)
tdbDbClose
(
pMeta
->
pUidIdx
);
if
(
pMeta
->
p
Uid
Idx
)
tdbDbClose
(
pMeta
->
pUidIdx
);
if
(
pMeta
->
pSkmDb
)
tdbDbClose
(
pMeta
->
pSkmDb
);
if
(
pMeta
->
pTbDb
)
tdbDbClose
(
pMeta
->
pTbDb
);
if
(
pMeta
->
pEnv
)
tdbEnvClose
(
pMeta
->
pEnv
);
...
...
@@ -295,3 +305,22 @@ static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL
return
0
;
}
static
int
smaIdxKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
)
{
SSmaIdxKey
*
pSmaIdxKey1
=
(
SSmaIdxKey
*
)
pKey1
;
SSmaIdxKey
*
pSmaIdxKey2
=
(
SSmaIdxKey
*
)
pKey2
;
if
(
pSmaIdxKey1
->
uid
>
pSmaIdxKey2
->
uid
)
{
return
1
;
}
else
if
(
pSmaIdxKey1
->
uid
<
pSmaIdxKey2
->
uid
)
{
return
-
1
;
}
if
(
pSmaIdxKey1
->
smaUid
>
pSmaIdxKey2
->
smaUid
)
{
return
1
;
}
else
if
(
pSmaIdxKey1
->
smaUid
<
pSmaIdxKey2
->
smaUid
)
{
return
-
1
;
}
return
0
;
}
source/dnode/vnode/src/meta/metaSma.c
0 → 100644
浏览文件 @
e0b3e97d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "meta.h"
static
int
metaHandleSmaEntry
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaSaveSmaToDB
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
int32_t
metaCreateTSma
(
SMeta
*
pMeta
,
int64_t
version
,
SSmaCfg
*
pCfg
)
{
// TODO: Validate the cfg
// The table uid should exists and be super table or normal table.
// Check other cfg value
SMetaEntry
me
=
{
0
};
int
kLen
=
0
;
int
vLen
=
0
;
const
void
*
pKey
=
NULL
;
const
void
*
pVal
=
NULL
;
void
*
pBuf
=
NULL
;
int32_t
szBuf
=
0
;
void
*
p
=
NULL
;
SMetaReader
mr
=
{
0
};
// validate req
metaReaderInit
(
&
mr
,
pMeta
,
0
);
if
(
metaGetTableEntryByUid
(
&
mr
,
pCfg
->
indexUid
)
==
0
)
{
// TODO: just for pass case
#if 1
terrno
=
TSDB_CODE_TDB_TSMA_ALREADY_EXIST
;
metaReaderClear
(
&
mr
);
return
-
1
;
#else
metaReaderClear
(
&
mr
);
return
0
;
#endif
}
metaReaderClear
(
&
mr
);
// set structs
me
.
version
=
version
;
me
.
type
=
TSDB_TSMA_TABLE
;
me
.
uid
=
pCfg
->
indexUid
;
me
.
name
=
pCfg
->
indexName
;
me
.
smaEntry
.
tsma
=
pCfg
;
if
(
metaHandleSmaEntry
(
pMeta
,
&
me
)
<
0
)
goto
_err
;
metaDebug
(
"vgId:%d tsma is created, name:%s uid: %"
PRId64
,
TD_VID
(
pMeta
->
pVnode
),
pCfg
->
indexName
,
pCfg
->
indexUid
);
return
0
;
_err:
metaError
(
"vgId:%d failed to create tsma: %s uid: %"
PRId64
" since %s"
,
TD_VID
(
pMeta
->
pVnode
),
pCfg
->
indexName
,
pCfg
->
indexUid
,
tstrerror
(
terrno
));
return
-
1
;
}
int32_t
metaDropTSma
(
SMeta
*
pMeta
,
int64_t
indexUid
)
{
// TODO: Validate the cfg
// TODO: add atomicity
#ifdef META_REFACT
#else
if
(
metaRemoveSmaFromDb
(
pMeta
,
indexUid
)
<
0
)
{
// TODO: handle error
return
-
1
;
}
#endif
return
TSDB_CODE_SUCCESS
;
}
// static int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
// int32_t ret = 0;
// void *pBuf = NULL, *qBuf = NULL;
// void *key = {0}, *val = {0};
// // save sma info
// int32_t len = tEncodeTSma(NULL, pSmaCfg);
// pBuf = taosMemoryCalloc(1, len);
// if (pBuf == NULL) {
// terrno = TSDB_CODE_OUT_OF_MEMORY;
// return -1;
// }
// key = (void *)&pSmaCfg->indexUid;
// qBuf = pBuf;
// tEncodeTSma(&qBuf, pSmaCfg);
// val = pBuf;
// int32_t kLen = sizeof(pSmaCfg->indexUid);
// int32_t vLen = POINTER_DISTANCE(qBuf, pBuf);
// ret = tdbDbInsert(pMeta->pTbDb, key, kLen, val, vLen, &pMeta->txn);
// if (ret < 0) {
// taosMemoryFreeClear(pBuf);
// return -1;
// }
// // add sma idx
// SSmaIdxKey smaIdxKey;
// smaIdxKey.uid = pSmaCfg->tableUid;
// smaIdxKey.smaUid = pSmaCfg->indexUid;
// key = &smaIdxKey;
// kLen = sizeof(smaIdxKey);
// val = NULL;
// vLen = 0;
// ret = tdbDbInsert(pMeta->pSmaIdx, key, kLen, val, vLen, &pMeta->txn);
// if (ret < 0) {
// taosMemoryFreeClear(pBuf);
// return -1;
// }
// // release
// taosMemoryFreeClear(pBuf);
// return 0;
// }
static
int
metaSaveSmaToDB
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
STbDbKey
tbDbKey
;
void
*
pKey
=
NULL
;
void
*
pVal
=
NULL
;
int
kLen
=
0
;
int
vLen
=
0
;
SEncoder
coder
=
{
0
};
// set key and value
tbDbKey
.
version
=
pME
->
version
;
tbDbKey
.
uid
=
pME
->
uid
;
pKey
=
&
tbDbKey
;
kLen
=
sizeof
(
tbDbKey
);
int32_t
ret
=
0
;
tEncodeSize
(
metaEncodeEntry
,
pME
,
vLen
,
ret
);
if
(
ret
<
0
)
{
goto
_err
;
}
pVal
=
taosMemoryMalloc
(
vLen
);
if
(
pVal
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_err
;
}
tEncoderInit
(
&
coder
,
pVal
,
vLen
);
if
(
metaEncodeEntry
(
&
coder
,
pME
)
<
0
)
{
goto
_err
;
}
tEncoderClear
(
&
coder
);
// write to table.db
if
(
tdbDbInsert
(
pMeta
->
pTbDb
,
pKey
,
kLen
,
pVal
,
vLen
,
&
pMeta
->
txn
)
<
0
)
{
goto
_err
;
}
taosMemoryFree
(
pVal
);
return
0
;
_err:
taosMemoryFree
(
pVal
);
return
-
1
;
}
static
int
metaUpdateUidIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
return
tdbDbInsert
(
pMeta
->
pUidIdx
,
&
pME
->
uid
,
sizeof
(
tb_uid_t
),
&
pME
->
version
,
sizeof
(
int64_t
),
&
pMeta
->
txn
);
}
static
int
metaUpdateSmaIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SSmaIdxKey
smaIdxKey
=
{.
uid
=
pME
->
smaEntry
.
tsma
->
tableUid
,
.
smaUid
=
pME
->
smaEntry
.
tsma
->
indexUid
};
return
tdbDbInsert
(
pMeta
->
pSmaIdx
,
&
smaIdxKey
,
sizeof
(
smaIdxKey
),
NULL
,
0
,
&
pMeta
->
txn
);
}
static
int
metaHandleSmaEntry
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
metaWLock
(
pMeta
);
// save to table.db
if
(
metaSaveSmaToDB
(
pMeta
,
pME
)
<
0
)
goto
_err
;
// // update uid.idx
if
(
metaUpdateUidIdx
(
pMeta
,
pME
)
<
0
)
goto
_err
;
if
(
metaUpdateSmaIdx
(
pMeta
,
pME
)
<
0
)
goto
_err
;
metaULock
(
pMeta
);
return
0
;
_err:
metaULock
(
pMeta
);
return
-
1
;
}
source/dnode/vnode/src/
inc/tsdbSma.h
→
source/dnode/vnode/src/
sma/sma.c
浏览文件 @
e0b3e97d
...
...
@@ -13,35 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_VNODE_TSDB_SMA_H_
#define _TD_VNODE_TSDB_SMA_H_
#include "sma.h"
#include "tsdb.h"
#ifdef __cplusplus
extern
"C"
{
#endif
// TODO: Who is responsible for resource allocate and release?
int32_t
tdProcessTSmaInsert
(
SSma
*
pSma
,
int64_t
indexUid
,
const
char
*
msg
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
// typedef int32_t (*__tb_ddl_fn_t)(void *ahandle, void **result, void *p1, void *p2);
// struct STbDdlH {
// void *ahandle;
// void *result;
// __tb_ddl_fn_t fp;
// };
static
FORCE_INLINE
int32_t
tsdbUidStoreInit
(
STbUidStore
**
pStore
)
{
ASSERT
(
*
pStore
==
NULL
);
*
pStore
=
taosMemoryCalloc
(
1
,
sizeof
(
STbUidStore
));
if
(
*
pStore
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
if
((
code
=
tdProcessTSmaInsertImpl
(
pSma
,
indexUid
,
msg
))
<
0
)
{
smaWarn
(
"vgId:%d insert tsma data failed since %s"
,
SMA_VID
(
pSma
),
tstrerror
(
terrno
));
}
return
TSDB_CODE_SUCCESS
;
// TODO: destroy SSDataBlocks(msg)
return
code
;
}
#ifdef __cplusplus
}
#endif
#endif
/*_TD_VNODE_TSDB_SMA_H_*/
\ No newline at end of file
source/dnode/vnode/src/sma/smaEnv.c
0 → 100644
浏览文件 @
e0b3e97d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sma.h"
typedef
struct
SSmaStat
SSmaStat
;
static
const
char
*
TSDB_SMA_DNAME
[]
=
{
""
,
// TSDB_SMA_TYPE_BLOCK
"tsma"
,
// TSDB_SMA_TYPE_TIME_RANGE
"rsma"
,
// TSDB_SMA_TYPE_ROLLUP
};
#define SMA_TEST_INDEX_NAME "smaTestIndexName" // TODO: just for test
#define SMA_TEST_INDEX_UID 2000000001 // TODO: just for test
#define SMA_STATE_HASH_SLOT 4
#define RSMA_TASK_INFO_HASH_SLOT 8
typedef
struct
SPoolMem
{
int64_t
size
;
struct
SPoolMem
*
prev
;
struct
SPoolMem
*
next
;
}
SPoolMem
;
// declaration of static functions
// insert data
static
void
tdGetSmaDir
(
int32_t
vgId
,
ETsdbSmaType
smaType
,
char
dirName
[]);
// Pool Memory
static
SPoolMem
*
openPool
();
static
void
clearPool
(
SPoolMem
*
pPool
);
static
void
closePool
(
SPoolMem
*
pPool
);
static
void
*
poolMalloc
(
void
*
arg
,
size_t
size
);
static
void
poolFree
(
void
*
arg
,
void
*
ptr
);
// implementation
static
SPoolMem
*
openPool
()
{
SPoolMem
*
pPool
=
(
SPoolMem
*
)
taosMemoryMalloc
(
sizeof
(
*
pPool
));
pPool
->
prev
=
pPool
->
next
=
pPool
;
pPool
->
size
=
0
;
return
pPool
;
}
static
void
clearPool
(
SPoolMem
*
pPool
)
{
if
(
!
pPool
)
return
;
SPoolMem
*
pMem
;
do
{
pMem
=
pPool
->
next
;
if
(
pMem
==
pPool
)
break
;
pMem
->
next
->
prev
=
pMem
->
prev
;
pMem
->
prev
->
next
=
pMem
->
next
;
pPool
->
size
-=
pMem
->
size
;
taosMemoryFree
(
pMem
);
}
while
(
1
);
assert
(
pPool
->
size
==
0
);
}
static
void
closePool
(
SPoolMem
*
pPool
)
{
if
(
pPool
)
{
clearPool
(
pPool
);
taosMemoryFree
(
pPool
);
}
}
static
void
*
poolMalloc
(
void
*
arg
,
size_t
size
)
{
void
*
ptr
=
NULL
;
SPoolMem
*
pPool
=
(
SPoolMem
*
)
arg
;
SPoolMem
*
pMem
;
pMem
=
(
SPoolMem
*
)
taosMemoryMalloc
(
sizeof
(
*
pMem
)
+
size
);
if
(
!
pMem
)
{
assert
(
0
);
}
pMem
->
size
=
sizeof
(
*
pMem
)
+
size
;
pMem
->
next
=
pPool
->
next
;
pMem
->
prev
=
pPool
;
pPool
->
next
->
prev
=
pMem
;
pPool
->
next
=
pMem
;
pPool
->
size
+=
pMem
->
size
;
ptr
=
(
void
*
)(
&
pMem
[
1
]);
return
ptr
;
}
static
void
poolFree
(
void
*
arg
,
void
*
ptr
)
{
SPoolMem
*
pPool
=
(
SPoolMem
*
)
arg
;
SPoolMem
*
pMem
;
pMem
=
&
(((
SPoolMem
*
)
ptr
)[
-
1
]);
pMem
->
next
->
prev
=
pMem
->
prev
;
pMem
->
prev
->
next
=
pMem
->
next
;
pPool
->
size
-=
pMem
->
size
;
taosMemoryFree
(
pMem
);
}
int32_t
tdInitSma
(
SSma
*
pSma
)
{
// tSma
int32_t
numOfTSma
=
taosArrayGetSize
(
metaGetSmaTbUids
(
SMA_META
(
pSma
),
false
));
if
(
numOfTSma
>
0
)
{
atomic_store_16
(
&
SMA_TSMA_NUM
(
pSma
),
(
int16_t
)
numOfTSma
);
}
// TODO: rSma
return
TSDB_CODE_SUCCESS
;
}
static
void
tdGetSmaDir
(
int32_t
vgId
,
ETsdbSmaType
smaType
,
char
dirName
[])
{
snprintf
(
dirName
,
TSDB_FILENAME_LEN
,
"vnode%svnode%d%s%s"
,
TD_DIRSEP
,
vgId
,
TD_DIRSEP
,
TSDB_SMA_DNAME
[
smaType
]);
}
static
SSmaEnv
*
tdNewSmaEnv
(
const
SSma
*
pSma
,
int8_t
smaType
,
const
char
*
path
,
SDiskID
did
)
{
SSmaEnv
*
pEnv
=
NULL
;
pEnv
=
(
SSmaEnv
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SSmaEnv
));
if
(
!
pEnv
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
SMA_ENV_TYPE
(
pEnv
)
=
smaType
;
int
code
=
taosThreadRwlockInit
(
&
(
pEnv
->
lock
),
NULL
);
if
(
code
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
taosMemoryFree
(
pEnv
);
return
NULL
;
}
ASSERT
(
path
&&
(
strlen
(
path
)
>
0
));
SMA_ENV_PATH
(
pEnv
)
=
strdup
(
path
);
if
(
!
SMA_ENV_PATH
(
pEnv
))
{
tdFreeSmaEnv
(
pEnv
);
return
NULL
;
}
SMA_ENV_DID
(
pEnv
)
=
did
;
if
(
tdInitSmaStat
(
&
SMA_ENV_STAT
(
pEnv
),
smaType
)
!=
TSDB_CODE_SUCCESS
)
{
tdFreeSmaEnv
(
pEnv
);
return
NULL
;
}
char
aname
[
TSDB_FILENAME_LEN
]
=
{
0
};
tfsAbsoluteName
(
SMA_TFS
(
pSma
),
did
,
path
,
aname
);
if
(
smaOpenDBEnv
(
&
pEnv
->
dbEnv
,
aname
)
!=
TSDB_CODE_SUCCESS
)
{
tdFreeSmaEnv
(
pEnv
);
return
NULL
;
}
if
(
!
(
pEnv
->
pPool
=
openPool
()))
{
tdFreeSmaEnv
(
pEnv
);
return
NULL
;
}
return
pEnv
;
}
static
int32_t
tdInitSmaEnv
(
SSma
*
pSma
,
int8_t
smaType
,
const
char
*
path
,
SDiskID
did
,
SSmaEnv
**
pEnv
)
{
if
(
!
pEnv
)
{
terrno
=
TSDB_CODE_INVALID_PTR
;
return
TSDB_CODE_FAILED
;
}
if
(
!
(
*
pEnv
))
{
if
(
!
(
*
pEnv
=
tdNewSmaEnv
(
pSma
,
smaType
,
path
,
did
)))
{
return
TSDB_CODE_FAILED
;
}
}
return
TSDB_CODE_SUCCESS
;
}
/**
* @brief Release resources allocated for its member fields, not including itself.
*
* @param pSmaEnv
* @return int32_t
*/
void
tdDestroySmaEnv
(
SSmaEnv
*
pSmaEnv
)
{
if
(
pSmaEnv
)
{
tdDestroySmaState
(
pSmaEnv
->
pStat
,
SMA_ENV_TYPE
(
pSmaEnv
));
taosMemoryFreeClear
(
pSmaEnv
->
pStat
);
taosMemoryFreeClear
(
pSmaEnv
->
path
);
taosThreadRwlockDestroy
(
&
(
pSmaEnv
->
lock
));
smaCloseDBEnv
(
pSmaEnv
->
dbEnv
);
closePool
(
pSmaEnv
->
pPool
);
}
}
void
*
tdFreeSmaEnv
(
SSmaEnv
*
pSmaEnv
)
{
tdDestroySmaEnv
(
pSmaEnv
);
taosMemoryFreeClear
(
pSmaEnv
);
return
NULL
;
}
int32_t
tdRefSmaStat
(
SSma
*
pSma
,
SSmaStat
*
pStat
)
{
if
(
!
pStat
)
return
0
;
int
ref
=
T_REF_INC
(
pStat
);
smaDebug
(
"vgId:%d ref sma stat:%p, val:%d"
,
SMA_VID
(
pSma
),
pStat
,
ref
);
return
0
;
}
int32_t
tdUnRefSmaStat
(
SSma
*
pSma
,
SSmaStat
*
pStat
)
{
if
(
!
pStat
)
return
0
;
int
ref
=
T_REF_DEC
(
pStat
);
smaDebug
(
"vgId:%d unref sma stat:%p, val:%d"
,
SMA_VID
(
pSma
),
pStat
,
ref
);
return
0
;
}
static
int32_t
tdInitSmaStat
(
SSmaStat
**
pSmaStat
,
int8_t
smaType
)
{
ASSERT
(
pSmaStat
!=
NULL
);
if
(
*
pSmaStat
)
{
// no lock
return
TSDB_CODE_SUCCESS
;
}
/**
* 1. Lazy mode utilized when init SSmaStat to update expired window(or hungry mode when tdNew).
* 2. Currently, there is mutex lock when init SSmaEnv, thus no need add lock on SSmaStat, and please add lock if
* tdInitSmaStat invoked in other multithread environment later.
*/
if
(
!
(
*
pSmaStat
))
{
*
pSmaStat
=
(
SSmaStat
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SSmaStat
));
if
(
!
(
*
pSmaStat
))
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
if
(
smaType
==
TSDB_SMA_TYPE_ROLLUP
)
{
SMA_STAT_INFO_HASH
(
*
pSmaStat
)
=
taosHashInit
(
RSMA_TASK_INFO_HASH_SLOT
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
HASH_ENTRY_LOCK
);
if
(
!
SMA_STAT_INFO_HASH
(
*
pSmaStat
))
{
taosMemoryFreeClear
(
*
pSmaStat
);
return
TSDB_CODE_FAILED
;
}
}
else
if
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
{
SMA_STAT_ITEMS
(
*
pSmaStat
)
=
taosHashInit
(
SMA_STATE_HASH_SLOT
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
if
(
!
SMA_STAT_ITEMS
(
*
pSmaStat
))
{
taosMemoryFreeClear
(
*
pSmaStat
);
return
TSDB_CODE_FAILED
;
}
}
else
{
ASSERT
(
0
);
}
}
return
TSDB_CODE_SUCCESS
;
}
void
*
tdFreeSmaStatItem
(
SSmaStatItem
*
pSmaStatItem
)
{
if
(
pSmaStatItem
)
{
tdDestroyTSma
(
pSmaStatItem
->
pTSma
);
taosMemoryFreeClear
(
pSmaStatItem
->
pTSma
);
taosHashCleanup
(
pSmaStatItem
->
expiredWindows
);
taosMemoryFreeClear
(
pSmaStatItem
);
}
return
NULL
;
}
/**
* @brief Release resources allocated for its member fields, not including itself.
*
* @param pSmaStat
* @return int32_t
*/
int32_t
tdDestroySmaState
(
SSmaStat
*
pSmaStat
,
int8_t
smaType
)
{
if
(
pSmaStat
)
{
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
if
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
{
void
*
item
=
taosHashIterate
(
SMA_STAT_ITEMS
(
pSmaStat
),
NULL
);
while
(
item
)
{
SSmaStatItem
*
pItem
=
*
(
SSmaStatItem
**
)
item
;
tdFreeSmaStatItem
(
pItem
);
item
=
taosHashIterate
(
SMA_STAT_ITEMS
(
pSmaStat
),
item
);
}
taosHashCleanup
(
SMA_STAT_ITEMS
(
pSmaStat
));
}
else
if
(
smaType
==
TSDB_SMA_TYPE_ROLLUP
)
{
void
*
infoHash
=
taosHashIterate
(
SMA_STAT_INFO_HASH
(
pSmaStat
),
NULL
);
while
(
infoHash
)
{
SRSmaInfo
*
pInfoHash
=
*
(
SRSmaInfo
**
)
infoHash
;
tdFreeRSmaInfo
(
pInfoHash
);
infoHash
=
taosHashIterate
(
SMA_STAT_INFO_HASH
(
pSmaStat
),
infoHash
);
}
taosHashCleanup
(
SMA_STAT_INFO_HASH
(
pSmaStat
));
}
else
{
ASSERT
(
0
);
}
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
tdLockSma
(
SSma
*
pSma
)
{
int
code
=
taosThreadMutexLock
(
&
pSma
->
mutex
);
if
(
code
!=
0
)
{
smaError
(
"vgId:%d failed to lock td since %s"
,
SMA_VID
(
pSma
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
pSma
->
locked
=
true
;
return
0
;
}
int32_t
tdUnLockSma
(
SSma
*
pSma
)
{
ASSERT
(
SMA_LOCKED
(
pSma
));
pSma
->
locked
=
false
;
int
code
=
taosThreadMutexUnlock
(
&
pSma
->
mutex
);
if
(
code
!=
0
)
{
smaError
(
"vgId:%d failed to unlock td since %s"
,
SMA_VID
(
pSma
),
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
return
0
;
}
int32_t
tdCheckAndInitSmaEnv
(
SSma
*
pSma
,
int8_t
smaType
)
{
SSmaEnv
*
pEnv
=
NULL
;
// return if already init
switch
(
smaType
)
{
case
TSDB_SMA_TYPE_TIME_RANGE
:
if
((
pEnv
=
(
SSmaEnv
*
)
atomic_load_ptr
(
&
SMA_TSMA_ENV
(
pSma
))))
{
return
TSDB_CODE_SUCCESS
;
}
break
;
case
TSDB_SMA_TYPE_ROLLUP
:
if
((
pEnv
=
(
SSmaEnv
*
)
atomic_load_ptr
(
&
SMA_RSMA_ENV
(
pSma
))))
{
return
TSDB_CODE_SUCCESS
;
}
break
;
default:
TASSERT
(
0
);
return
TSDB_CODE_FAILED
;
}
// init sma env
tdLockSma
(
pSma
);
pEnv
=
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
?
atomic_load_ptr
(
&
SMA_TSMA_ENV
(
pSma
))
:
atomic_load_ptr
(
&
SMA_RSMA_ENV
(
pSma
));
if
(
!
pEnv
)
{
char
rname
[
TSDB_FILENAME_LEN
]
=
{
0
};
SDiskID
did
=
{
0
};
if
(
tfsAllocDisk
(
SMA_TFS
(
pSma
),
TFS_PRIMARY_LEVEL
,
&
did
)
<
0
)
{
tdUnLockSma
(
pSma
);
return
TSDB_CODE_FAILED
;
}
if
(
did
.
level
<
0
||
did
.
id
<
0
)
{
tdUnLockSma
(
pSma
);
smaError
(
"vgId:%d init sma env failed since invalid did(%d,%d)"
,
SMA_VID
(
pSma
),
did
.
level
,
did
.
id
);
return
TSDB_CODE_FAILED
;
}
tdGetSmaDir
(
SMA_VID
(
pSma
),
smaType
,
rname
);
if
(
tfsMkdirRecurAt
(
SMA_TFS
(
pSma
),
rname
,
did
)
<
0
)
{
tdUnLockSma
(
pSma
);
return
TSDB_CODE_FAILED
;
}
if
(
tdInitSmaEnv
(
pSma
,
smaType
,
rname
,
did
,
&
pEnv
)
<
0
)
{
tdUnLockSma
(
pSma
);
return
TSDB_CODE_FAILED
;
}
(
smaType
==
TSDB_SMA_TYPE_TIME_RANGE
)
?
atomic_store_ptr
(
&
SMA_TSMA_ENV
(
pSma
),
pEnv
)
:
atomic_store_ptr
(
&
SMA_RSMA_ENV
(
pSma
),
pEnv
);
}
tdUnLockSma
(
pSma
);
return
TSDB_CODE_SUCCESS
;
};
int32_t
tdSmaBeginCommit
(
SSmaEnv
*
pEnv
)
{
TXN
*
pTxn
=
&
pEnv
->
txn
;
// start a new txn
tdbTxnOpen
(
pTxn
,
0
,
poolMalloc
,
poolFree
,
pEnv
->
pPool
,
TDB_TXN_WRITE
|
TDB_TXN_READ_UNCOMMITTED
);
if
(
tdbBegin
(
pEnv
->
dbEnv
,
pTxn
)
!=
0
)
{
smaWarn
(
"tdSma tdb begin commit fail"
);
return
-
1
;
}
return
0
;
}
int32_t
tdSmaEndCommit
(
SSmaEnv
*
pEnv
)
{
TXN
*
pTxn
=
&
pEnv
->
txn
;
// Commit current txn
if
(
tdbCommit
(
pEnv
->
dbEnv
,
pTxn
)
!=
0
)
{
smaWarn
(
"tdSma tdb end commit fail"
);
return
-
1
;
}
tdbTxnClose
(
pTxn
);
clearPool
(
pEnv
->
pPool
);
return
0
;
}
#if 0
/**
* @brief Get the start TS key of the last data block of one interval/sliding.
*
* @param pSma
* @param param
* @param result
* @return int32_t
* 1) Return 0 and fill the result if the check procedure is normal;
* 2) Return -1 if error occurs during the check procedure.
*/
int32_t tdGetTSmaStatus(SSma *pSma, void *smaIndex, void *result) {
const char *procedure = "";
if (strncmp(procedure, "get the start TS key of the last data block", 100) != 0) {
return -1;
}
// fill the result
return TSDB_CODE_SUCCESS;
}
/**
* @brief Remove the tSma data files related to param between pWin.
*
* @param pSma
* @param param
* @param pWin
* @return int32_t
*/
int32_t tdRemoveTSmaData(SSma *pSma, void *smaIndex, STimeWindow *pWin) {
// for ("tSmaFiles of param-interval-sliding between pWin") {
// // remove the tSmaFile
// }
return TSDB_CODE_SUCCESS;
}
#endif
source/dnode/vnode/src/sma/smaOpen.c
0 → 100644
浏览文件 @
e0b3e97d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sma.h"
#include "tsdb.h"
static
int32_t
smaEvalDays
(
SRetention
*
r
,
int8_t
precision
);
static
int32_t
smaSetKeepCfg
(
STsdbKeepCfg
*
pKeepCfg
,
STsdbCfg
*
pCfg
,
int
type
);
#define SMA_SET_KEEP_CFG(l) \
do { \
SRetention *r = &pCfg->retentions[l]; \
pKeepCfg->keep2 = convertTimeFromPrecisionToUnit(r->keep, pCfg->precision, TIME_UNIT_MINUTE); \
pKeepCfg->keep0 = pKeepCfg->keep2; \
pKeepCfg->keep1 = pKeepCfg->keep2; \
pKeepCfg->days = smaEvalDays(r, pCfg->precision); \
} while (0)
#define SMA_OPEN_RSMA_IMPL(v, l) \
do { \
SRetention *r = (SRetention *)VND_RETENTIONS(v) + l; \
if (!RETENTION_VALID(r)) { \
if (l == 0) { \
goto _err; \
} \
break; \
} \
smaSetKeepCfg(&keepCfg, pCfg, TSDB_TYPE_RSMA_L##l); \
if (tsdbOpen(v, &SMA_RSMA_TSDB##l(pSma), VNODE_RSMA##l##_DIR, &keepCfg) < 0) { \
goto _err; \
} \
} while (0)
#define RETENTION_DAYS_SPLIT_RATIO 10
#define RETENTION_DAYS_SPLIT_MIN 1
#define RETENTION_DAYS_SPLIT_MAX 30
static
int32_t
smaEvalDays
(
SRetention
*
r
,
int8_t
precision
)
{
int32_t
keepDays
=
convertTimeFromPrecisionToUnit
(
r
->
keep
,
precision
,
TIME_UNIT_DAY
);
int32_t
freqDays
=
convertTimeFromPrecisionToUnit
(
r
->
freq
,
precision
,
TIME_UNIT_DAY
);
int32_t
days
=
keepDays
/
RETENTION_DAYS_SPLIT_RATIO
;
if
(
days
<=
RETENTION_DAYS_SPLIT_MIN
)
{
days
=
RETENTION_DAYS_SPLIT_MIN
;
if
(
days
<
freqDays
)
{
days
=
freqDays
+
1
;
}
}
else
{
if
(
days
>
RETENTION_DAYS_SPLIT_MAX
)
{
days
=
RETENTION_DAYS_SPLIT_MAX
;
}
if
(
days
<
freqDays
)
{
days
=
freqDays
+
1
;
}
}
return
days
*
1440
;
}
int
smaSetKeepCfg
(
STsdbKeepCfg
*
pKeepCfg
,
STsdbCfg
*
pCfg
,
int
type
)
{
pKeepCfg
->
precision
=
pCfg
->
precision
;
switch
(
type
)
{
case
TSDB_TYPE_TSMA
:
ASSERT
(
0
);
break
;
case
TSDB_TYPE_RSMA_L0
:
SMA_SET_KEEP_CFG
(
0
);
break
;
case
TSDB_TYPE_RSMA_L1
:
SMA_SET_KEEP_CFG
(
1
);
break
;
case
TSDB_TYPE_RSMA_L2
:
SMA_SET_KEEP_CFG
(
2
);
break
;
default:
ASSERT
(
0
);
break
;
}
return
0
;
}
int32_t
smaOpen
(
SVnode
*
pVnode
)
{
STsdbCfg
*
pCfg
=
&
pVnode
->
config
.
tsdbCfg
;
ASSERT
(
!
pVnode
->
pSma
);
SSma
*
pSma
=
taosMemoryCalloc
(
1
,
sizeof
(
SSma
));
if
(
!
pSma
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pSma
->
pVnode
=
pVnode
;
taosThreadMutexInit
(
&
pSma
->
mutex
,
NULL
);
pSma
->
locked
=
false
;
if
(
vnodeIsRollup
(
pVnode
))
{
STsdbKeepCfg
keepCfg
=
{
0
};
for
(
int
i
=
0
;
i
<
TSDB_RETENTION_MAX
;
++
i
)
{
if
(
i
==
TSDB_RETENTION_L0
)
{
SMA_OPEN_RSMA_IMPL
(
pVnode
,
0
);
}
else
if
(
i
==
TSDB_RETENTION_L1
)
{
SMA_OPEN_RSMA_IMPL
(
pVnode
,
1
);
}
else
if
(
i
==
TSDB_RETENTION_L2
)
{
SMA_OPEN_RSMA_IMPL
(
pVnode
,
2
);
}
else
{
ASSERT
(
0
);
}
}
}
pVnode
->
pSma
=
pSma
;
return
0
;
_err:
taosMemoryFreeClear
(
pSma
);
return
-
1
;
}
int32_t
smaClose
(
SSma
*
pSma
)
{
if
(
pSma
)
{
taosThreadMutexDestroy
(
&
pSma
->
mutex
);
if
SMA_RSMA_TSDB0
(
pSma
)
tsdbClose
(
&
SMA_RSMA_TSDB0
(
pSma
));
if
SMA_RSMA_TSDB1
(
pSma
)
tsdbClose
(
&
SMA_RSMA_TSDB1
(
pSma
));
if
SMA_RSMA_TSDB2
(
pSma
)
tsdbClose
(
&
SMA_RSMA_TSDB2
(
pSma
));
}
return
0
;
}
\ No newline at end of file
source/dnode/vnode/src/sma/smaRollup.c
0 → 100644
浏览文件 @
e0b3e97d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sma.h"
static
FORCE_INLINE
int32_t
tdUidStorePut
(
STbUidStore
*
pStore
,
tb_uid_t
suid
,
tb_uid_t
*
uid
);
static
FORCE_INLINE
int32_t
tdUpdateTbUidListImpl
(
SSma
*
pSma
,
tb_uid_t
*
suid
,
SArray
*
tbUids
);
static
FORCE_INLINE
int32_t
tdExecuteRSmaImpl
(
SSma
*
pSma
,
const
void
*
pMsg
,
int32_t
inputType
,
qTaskInfo_t
*
taskInfo
,
STSchema
*
pTSchema
,
tb_uid_t
suid
,
tb_uid_t
uid
,
int8_t
level
);
struct
SRSmaInfo
{
void
*
taskInfo
[
TSDB_RETENTION_L2
];
// qTaskInfo_t
};
static
FORCE_INLINE
void
tdFreeTaskHandle
(
qTaskInfo_t
*
taskHandle
)
{
// Note: free/kill may in RC
qTaskInfo_t
otaskHandle
=
atomic_load_ptr
(
taskHandle
);
if
(
otaskHandle
&&
atomic_val_compare_exchange_ptr
(
taskHandle
,
otaskHandle
,
NULL
))
{
qDestroyTask
(
otaskHandle
);
}
}
void
*
tdFreeRSmaInfo
(
SRSmaInfo
*
pInfo
)
{
for
(
int32_t
i
=
0
;
i
<
TSDB_RETENTION_MAX
;
++
i
)
{
if
(
pInfo
->
taskInfo
[
i
])
{
tdFreeTaskHandle
(
pInfo
->
taskInfo
[
i
]);
}
}
return
NULL
;
}
static
FORCE_INLINE
int32_t
tdUidStoreInit
(
STbUidStore
**
pStore
)
{
ASSERT
(
*
pStore
==
NULL
);
*
pStore
=
taosMemoryCalloc
(
1
,
sizeof
(
STbUidStore
));
if
(
*
pStore
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
return
TSDB_CODE_SUCCESS
;
}
static
FORCE_INLINE
int32_t
tdUpdateTbUidListImpl
(
SSma
*
pSma
,
tb_uid_t
*
suid
,
SArray
*
tbUids
)
{
SSmaEnv
*
pEnv
=
SMA_RSMA_ENV
(
pSma
);
SSmaStat
*
pStat
=
SMA_ENV_STAT
(
pEnv
);
SRSmaInfo
*
pRSmaInfo
=
NULL
;
if
(
!
suid
||
!
tbUids
)
{
terrno
=
TSDB_CODE_INVALID_PTR
;
smaError
(
"vgId:%d failed to get rsma info for uid:%"
PRIi64
" since %s"
,
SMA_VID
(
pSma
),
*
suid
,
terrstr
(
terrno
));
return
TSDB_CODE_FAILED
;
}
pRSmaInfo
=
taosHashGet
(
SMA_STAT_INFO_HASH
(
pStat
),
suid
,
sizeof
(
tb_uid_t
));
if
(
!
pRSmaInfo
||
!
(
pRSmaInfo
=
*
(
SRSmaInfo
**
)
pRSmaInfo
))
{
smaError
(
"vgId:%d failed to get rsma info for uid:%"
PRIi64
,
SMA_VID
(
pSma
),
*
suid
);
terrno
=
TSDB_CODE_TDB_INVALID_SMA_STAT
;
return
TSDB_CODE_FAILED
;
}
if
(
pRSmaInfo
->
taskInfo
[
0
]
&&
(
qUpdateQualifiedTableId
(
pRSmaInfo
->
taskInfo
[
0
],
tbUids
,
true
)
!=
0
))
{
smaError
(
"vgId:%d update tbUidList failed for uid:%"
PRIi64
" since %s"
,
SMA_VID
(
pSma
),
*
suid
,
terrstr
(
terrno
));
return
TSDB_CODE_FAILED
;
}
else
{
smaDebug
(
"vgId:%d update tbUidList succeed for qTaskInfo:%p with suid:%"
PRIi64
", uid:%"
PRIi64
,
SMA_VID
(
pSma
),
pRSmaInfo
->
taskInfo
[
0
],
*
suid
,
*
(
int64_t
*
)
taosArrayGet
(
tbUids
,
0
));
}
if
(
pRSmaInfo
->
taskInfo
[
1
]
&&
(
qUpdateQualifiedTableId
(
pRSmaInfo
->
taskInfo
[
1
],
tbUids
,
true
)
!=
0
))
{
smaError
(
"vgId:%d update tbUidList failed for uid:%"
PRIi64
" since %s"
,
SMA_VID
(
pSma
),
*
suid
,
terrstr
(
terrno
));
return
TSDB_CODE_FAILED
;
}
else
{
smaDebug
(
"vgId:%d update tbUidList succeed for qTaskInfo:%p with suid:%"
PRIi64
", uid:%"
PRIi64
,
SMA_VID
(
pSma
),
pRSmaInfo
->
taskInfo
[
1
],
*
suid
,
*
(
int64_t
*
)
taosArrayGet
(
tbUids
,
0
));
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
tdUpdateTbUidList
(
SSma
*
pSma
,
STbUidStore
*
pStore
)
{
if
(
!
pStore
||
(
taosArrayGetSize
(
pStore
->
tbUids
)
==
0
))
{
return
TSDB_CODE_SUCCESS
;
}
if
(
tdUpdateTbUidListImpl
(
pSma
,
&
pStore
->
suid
,
pStore
->
tbUids
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_FAILED
;
}
void
*
pIter
=
taosHashIterate
(
pStore
->
uidHash
,
NULL
);
while
(
pIter
)
{
tb_uid_t
*
pTbSuid
=
(
tb_uid_t
*
)
taosHashGetKey
(
pIter
,
NULL
);
SArray
*
pTbUids
=
*
(
SArray
**
)
pIter
;
if
(
tdUpdateTbUidListImpl
(
pSma
,
pTbSuid
,
pTbUids
)
!=
TSDB_CODE_SUCCESS
)
{
taosHashCancelIterate
(
pStore
->
uidHash
,
pIter
);
return
TSDB_CODE_FAILED
;
}
pIter
=
taosHashIterate
(
pStore
->
uidHash
,
pIter
);
}
return
TSDB_CODE_SUCCESS
;
}
/**
* @brief fetch suid/uids when create child tables of rollup SMA
*
* @param pTsdb
* @param ppStore
* @param suid
* @param uid
* @return int32_t
*/
int32_t
tdFetchTbUidList
(
SSma
*
pSma
,
STbUidStore
**
ppStore
,
tb_uid_t
suid
,
tb_uid_t
uid
)
{
SSmaEnv
*
pEnv
=
SMA_RSMA_ENV
(
pSma
);
// only applicable to rollup SMA ctables
if
(
!
pEnv
)
{
return
TSDB_CODE_SUCCESS
;
}
SSmaStat
*
pStat
=
SMA_ENV_STAT
(
pEnv
);
SHashObj
*
infoHash
=
NULL
;
if
(
!
pStat
||
!
(
infoHash
=
SMA_STAT_INFO_HASH
(
pStat
)))
{
terrno
=
TSDB_CODE_TDB_INVALID_SMA_STAT
;
return
TSDB_CODE_FAILED
;
}
// info cached when create rsma stable and return directly for non-rsma ctables
if
(
!
taosHashGet
(
infoHash
,
&
suid
,
sizeof
(
tb_uid_t
)))
{
return
TSDB_CODE_SUCCESS
;
}
ASSERT
(
ppStore
!=
NULL
);
if
(
!
(
*
ppStore
))
{
if
(
tdUidStoreInit
(
ppStore
)
!=
0
)
{
return
TSDB_CODE_FAILED
;
}
}
if
(
tdUidStorePut
(
*
ppStore
,
suid
,
&
uid
)
!=
0
)
{
*
ppStore
=
tdUidStoreFree
(
*
ppStore
);
return
TSDB_CODE_FAILED
;
}
return
TSDB_CODE_SUCCESS
;
}
/**
* @brief Check and init qTaskInfo_t, only applicable to stable with SRSmaParam.
*
* @param pTsdb
* @param pMeta
* @param pReq
* @return int32_t
*/
int32_t
tdProcessRSmaCreate
(
SSma
*
pSma
,
SMeta
*
pMeta
,
SVCreateStbReq
*
pReq
,
SMsgCb
*
pMsgCb
)
{
if
(
!
pReq
->
rollup
)
{
smaTrace
(
"vgId:%d return directly since no rollup for stable %s %"
PRIi64
,
SMA_VID
(
pSma
),
pReq
->
name
,
pReq
->
suid
);
return
TSDB_CODE_SUCCESS
;
}
SRSmaParam
*
param
=
&
pReq
->
pRSmaParam
;
if
((
param
->
qmsg1Len
==
0
)
&&
(
param
->
qmsg2Len
==
0
))
{
smaWarn
(
"vgId:%d no qmsg1/qmsg2 for rollup stable %s %"
PRIi64
,
SMA_VID
(
pSma
),
pReq
->
name
,
pReq
->
suid
);
return
TSDB_CODE_SUCCESS
;
}
if
(
tdCheckAndInitSmaEnv
(
pSma
,
TSDB_SMA_TYPE_ROLLUP
)
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
TSDB_CODE_TDB_INIT_FAILED
;
return
TSDB_CODE_FAILED
;
}
SSmaEnv
*
pEnv
=
SMA_RSMA_ENV
(
pSma
);
SSmaStat
*
pStat
=
SMA_ENV_STAT
(
pEnv
);
SRSmaInfo
*
pRSmaInfo
=
NULL
;
pRSmaInfo
=
taosHashGet
(
SMA_STAT_INFO_HASH
(
pStat
),
&
pReq
->
suid
,
sizeof
(
tb_uid_t
));
if
(
pRSmaInfo
)
{
smaWarn
(
"vgId:%d rsma info already exists for stb: %s, %"
PRIi64
,
SMA_VID
(
pSma
),
pReq
->
name
,
pReq
->
suid
);
return
TSDB_CODE_SUCCESS
;
}
pRSmaInfo
=
(
SRSmaInfo
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SRSmaInfo
));
if
(
!
pRSmaInfo
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
STqReadHandle
*
pReadHandle
=
tqInitSubmitMsgScanner
(
pMeta
);
if
(
!
pReadHandle
)
{
taosMemoryFree
(
pRSmaInfo
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
SReadHandle
handle
=
{
.
reader
=
pReadHandle
,
.
meta
=
pMeta
,
.
pMsgCb
=
pMsgCb
,
};
if
(
param
->
qmsg1
)
{
pRSmaInfo
->
taskInfo
[
0
]
=
qCreateStreamExecTaskInfo
(
param
->
qmsg1
,
&
handle
);
if
(
!
pRSmaInfo
->
taskInfo
[
0
])
{
taosMemoryFree
(
pRSmaInfo
);
taosMemoryFree
(
pReadHandle
);
return
TSDB_CODE_FAILED
;
}
}
if
(
param
->
qmsg2
)
{
pRSmaInfo
->
taskInfo
[
1
]
=
qCreateStreamExecTaskInfo
(
param
->
qmsg2
,
&
handle
);
if
(
!
pRSmaInfo
->
taskInfo
[
1
])
{
taosMemoryFree
(
pRSmaInfo
);
taosMemoryFree
(
pReadHandle
);
return
TSDB_CODE_FAILED
;
}
}
if
(
taosHashPut
(
SMA_STAT_INFO_HASH
(
pStat
),
&
pReq
->
suid
,
sizeof
(
tb_uid_t
),
&
pRSmaInfo
,
sizeof
(
pRSmaInfo
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_FAILED
;
}
else
{
smaDebug
(
"vgId:%d register rsma info succeed for suid:%"
PRIi64
,
SMA_VID
(
pSma
),
pReq
->
suid
);
}
return
TSDB_CODE_SUCCESS
;
}
/**
* @brief store suid/[uids], prefer to use array and then hash
*
* @param pStore
* @param suid
* @param uid
* @return int32_t
*/
static
int32_t
tdUidStorePut
(
STbUidStore
*
pStore
,
tb_uid_t
suid
,
tb_uid_t
*
uid
)
{
// prefer to store suid/uids in array
if
((
suid
==
pStore
->
suid
)
||
(
pStore
->
suid
==
0
))
{
if
(
pStore
->
suid
==
0
)
{
pStore
->
suid
=
suid
;
}
if
(
uid
)
{
if
(
!
pStore
->
tbUids
)
{
if
(
!
(
pStore
->
tbUids
=
taosArrayInit
(
1
,
sizeof
(
tb_uid_t
))))
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
}
if
(
!
taosArrayPush
(
pStore
->
tbUids
,
uid
))
{
return
TSDB_CODE_FAILED
;
}
}
}
else
{
// store other suid/uids in hash when multiple stable/table included in 1 batch of request
if
(
!
pStore
->
uidHash
)
{
pStore
->
uidHash
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_ENTRY_LOCK
);
if
(
!
pStore
->
uidHash
)
{
return
TSDB_CODE_FAILED
;
}
}
if
(
uid
)
{
SArray
*
uidArray
=
taosHashGet
(
pStore
->
uidHash
,
&
suid
,
sizeof
(
tb_uid_t
));
if
(
uidArray
&&
((
uidArray
=
*
(
SArray
**
)
uidArray
)))
{
taosArrayPush
(
uidArray
,
uid
);
}
else
{
SArray
*
pUidArray
=
taosArrayInit
(
1
,
sizeof
(
tb_uid_t
));
if
(
!
pUidArray
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
if
(
!
taosArrayPush
(
pUidArray
,
uid
))
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
if
(
taosHashPut
(
pStore
->
uidHash
,
&
suid
,
sizeof
(
suid
),
&
pUidArray
,
sizeof
(
pUidArray
))
!=
0
)
{
return
TSDB_CODE_FAILED
;
}
}
}
else
{
if
(
taosHashPut
(
pStore
->
uidHash
,
&
suid
,
sizeof
(
suid
),
NULL
,
0
)
!=
0
)
{
return
TSDB_CODE_FAILED
;
}
}
}
return
TSDB_CODE_SUCCESS
;
}
void
tdUidStoreDestory
(
STbUidStore
*
pStore
)
{
if
(
pStore
)
{
if
(
pStore
->
uidHash
)
{
if
(
pStore
->
tbUids
)
{
// When pStore->tbUids not NULL, the pStore->uidHash has k/v; otherwise pStore->uidHash only has keys.
void
*
pIter
=
taosHashIterate
(
pStore
->
uidHash
,
NULL
);
while
(
pIter
)
{
SArray
*
arr
=
*
(
SArray
**
)
pIter
;
taosArrayDestroy
(
arr
);
pIter
=
taosHashIterate
(
pStore
->
uidHash
,
pIter
);
}
}
taosHashCleanup
(
pStore
->
uidHash
);
}
taosArrayDestroy
(
pStore
->
tbUids
);
}
}
void
*
tdUidStoreFree
(
STbUidStore
*
pStore
)
{
if
(
pStore
)
{
tdUidStoreDestory
(
pStore
);
taosMemoryFree
(
pStore
);
}
return
NULL
;
}
static
int32_t
tdProcessSubmitReq
(
STsdb
*
pTsdb
,
int64_t
version
,
void
*
pReq
)
{
if
(
!
pReq
)
{
terrno
=
TSDB_CODE_INVALID_PTR
;
return
TSDB_CODE_FAILED
;
}
SSubmitReq
*
pSubmitReq
=
(
SSubmitReq
*
)
pReq
;
if
(
tsdbInsertData
(
pTsdb
,
version
,
pSubmitReq
,
NULL
)
<
0
)
{
return
TSDB_CODE_FAILED
;
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tdFetchSubmitReqSuids
(
SSubmitReq
*
pMsg
,
STbUidStore
*
pStore
)
{
ASSERT
(
pMsg
!=
NULL
);
SSubmitMsgIter
msgIter
=
{
0
};
SSubmitBlk
*
pBlock
=
NULL
;
SSubmitBlkIter
blkIter
=
{
0
};
STSRow
*
row
=
NULL
;
terrno
=
TSDB_CODE_SUCCESS
;
if
(
tInitSubmitMsgIter
(
pMsg
,
&
msgIter
)
<
0
)
return
-
1
;
while
(
true
)
{
if
(
tGetSubmitMsgNext
(
&
msgIter
,
&
pBlock
)
<
0
)
return
-
1
;
if
(
!
pBlock
)
break
;
tdUidStorePut
(
pStore
,
msgIter
.
suid
,
NULL
);
pStore
->
uid
=
msgIter
.
uid
;
// TODO: remove, just for debugging
}
if
(
terrno
!=
TSDB_CODE_SUCCESS
)
return
-
1
;
return
0
;
}
static
FORCE_INLINE
int32_t
tdExecuteRSmaImpl
(
SSma
*
pSma
,
const
void
*
pMsg
,
int32_t
inputType
,
qTaskInfo_t
*
taskInfo
,
STSchema
*
pTSchema
,
tb_uid_t
suid
,
tb_uid_t
uid
,
int8_t
level
)
{
SArray
*
pResult
=
NULL
;
if
(
!
taskInfo
)
{
smaDebug
(
"vgId:%d no qTaskInfo to execute rsma %"
PRIi8
" task for suid:%"
PRIu64
,
SMA_VID
(
pSma
),
level
,
suid
);
return
TSDB_CODE_SUCCESS
;
}
smaDebug
(
"vgId:%d execute rsma %"
PRIi8
" task for qTaskInfo:%p suid:%"
PRIu64
,
SMA_VID
(
pSma
),
level
,
taskInfo
,
suid
);
qSetStreamInput
(
taskInfo
,
pMsg
,
inputType
);
while
(
1
)
{
SSDataBlock
*
output
=
NULL
;
uint64_t
ts
;
if
(
qExecTask
(
taskInfo
,
&
output
,
&
ts
)
<
0
)
{
ASSERT
(
false
);
}
if
(
!
output
)
{
break
;
}
if
(
!
pResult
)
{
pResult
=
taosArrayInit
(
0
,
sizeof
(
SSDataBlock
));
if
(
!
pResult
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
}
taosArrayPush
(
pResult
,
output
);
}
if
(
taosArrayGetSize
(
pResult
)
>
0
)
{
blockDebugShowData
(
pResult
);
STsdb
*
sinkTsdb
=
(
level
==
TSDB_RETENTION_L1
?
pSma
->
pRSmaTsdb1
:
pSma
->
pRSmaTsdb2
);
SSubmitReq
*
pReq
=
NULL
;
if
(
buildSubmitReqFromDataBlock
(
&
pReq
,
pResult
,
pTSchema
,
SMA_VID
(
pSma
),
uid
,
suid
)
!=
0
)
{
taosArrayDestroy
(
pResult
);
return
TSDB_CODE_FAILED
;
}
if
(
tdProcessSubmitReq
(
sinkTsdb
,
INT64_MAX
,
pReq
)
!=
0
)
{
taosArrayDestroy
(
pResult
);
taosMemoryFreeClear
(
pReq
);
return
TSDB_CODE_FAILED
;
}
taosMemoryFreeClear
(
pReq
);
}
else
{
smaWarn
(
"vgId:%d no rsma % "
PRIi8
" data generated since %s"
,
SMA_VID
(
pSma
),
level
,
tstrerror
(
terrno
));
}
taosArrayDestroy
(
pResult
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tdExecuteRSma
(
SSma
*
pSma
,
const
void
*
pMsg
,
int32_t
inputType
,
tb_uid_t
suid
,
tb_uid_t
uid
)
{
SSmaEnv
*
pEnv
=
SMA_RSMA_ENV
(
pSma
);
if
(
!
pEnv
)
{
// only applicable when rsma env exists
return
TSDB_CODE_SUCCESS
;
}
ASSERT
(
uid
!=
0
);
// TODO: remove later
SSmaStat
*
pStat
=
SMA_ENV_STAT
(
pEnv
);
SRSmaInfo
*
pRSmaInfo
=
NULL
;
pRSmaInfo
=
taosHashGet
(
SMA_STAT_INFO_HASH
(
pStat
),
&
suid
,
sizeof
(
tb_uid_t
));
if
(
!
pRSmaInfo
||
!
(
pRSmaInfo
=
*
(
SRSmaInfo
**
)
pRSmaInfo
))
{
smaDebug
(
"vgId:%d no rsma info for suid:%"
PRIu64
,
SMA_VID
(
pSma
),
suid
);
return
TSDB_CODE_SUCCESS
;
}
if
(
!
pRSmaInfo
->
taskInfo
[
0
])
{
smaDebug
(
"vgId:%d no rsma qTaskInfo for suid:%"
PRIu64
,
SMA_VID
(
pSma
),
suid
);
return
TSDB_CODE_SUCCESS
;
}
if
(
inputType
==
STREAM_DATA_TYPE_SUBMIT_BLOCK
)
{
// TODO: use the proper schema instead of 0, and cache STSchema in cache
STSchema
*
pTSchema
=
metaGetTbTSchema
(
SMA_META
(
pSma
),
suid
,
0
);
if
(
!
pTSchema
)
{
terrno
=
TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION
;
return
TSDB_CODE_FAILED
;
}
tdExecuteRSmaImpl
(
pSma
,
pMsg
,
inputType
,
pRSmaInfo
->
taskInfo
[
0
],
pTSchema
,
suid
,
uid
,
TSDB_RETENTION_L1
);
tdExecuteRSmaImpl
(
pSma
,
pMsg
,
inputType
,
pRSmaInfo
->
taskInfo
[
1
],
pTSchema
,
suid
,
uid
,
TSDB_RETENTION_L2
);
taosMemoryFree
(
pTSchema
);
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
tdProcessRSmaSubmit
(
SSma
*
pSma
,
void
*
pMsg
,
int32_t
inputType
)
{
SSmaEnv
*
pEnv
=
SMA_RSMA_ENV
(
pSma
);
if
(
!
pEnv
)
{
// only applicable when rsma env exists
return
TSDB_CODE_SUCCESS
;
}
if
(
inputType
==
STREAM_DATA_TYPE_SUBMIT_BLOCK
)
{
STbUidStore
uidStore
=
{
0
};
tdFetchSubmitReqSuids
(
pMsg
,
&
uidStore
);
if
(
uidStore
.
suid
!=
0
)
{
tdExecuteRSma
(
pSma
,
pMsg
,
inputType
,
uidStore
.
suid
,
uidStore
.
uid
);
void
*
pIter
=
taosHashIterate
(
uidStore
.
uidHash
,
NULL
);
while
(
pIter
)
{
tb_uid_t
*
pTbSuid
=
(
tb_uid_t
*
)
taosHashGetKey
(
pIter
,
NULL
);
tdExecuteRSma
(
pSma
,
pMsg
,
inputType
,
*
pTbSuid
,
0
);
pIter
=
taosHashIterate
(
uidStore
.
uidHash
,
pIter
);
}
tdUidStoreDestory
(
&
uidStore
);
}
}
return
TSDB_CODE_SUCCESS
;
}
source/dnode/vnode/src/sma/smaTDBImpl.c
0 → 100644
浏览文件 @
e0b3e97d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define ALLOW_FORBID_FUNC
#include "sma.h"
int32_t
smaOpenDBEnv
(
TENV
**
ppEnv
,
const
char
*
path
)
{
int
ret
=
0
;
if
(
path
==
NULL
)
return
-
1
;
ret
=
tdbEnvOpen
(
path
,
4096
,
256
,
ppEnv
);
// use as param
if
(
ret
!=
0
)
{
smaError
(
"failed to create tsdb db env, ret = %d"
,
ret
);
return
-
1
;
}
return
0
;
}
int32_t
smaCloseDBEnv
(
TENV
*
pEnv
)
{
return
tdbEnvClose
(
pEnv
);
}
static
inline
int
tdSmaKeyCmpr
(
const
void
*
arg1
,
int
len1
,
const
void
*
arg2
,
int
len2
)
{
const
SSmaKey
*
pKey1
=
(
const
SSmaKey
*
)
arg1
;
const
SSmaKey
*
pKey2
=
(
const
SSmaKey
*
)
arg2
;
ASSERT
(
len1
==
len2
&&
len1
==
sizeof
(
SSmaKey
));
if
(
pKey1
->
skey
<
pKey2
->
skey
)
{
return
-
1
;
}
else
if
(
pKey1
->
skey
>
pKey2
->
skey
)
{
return
1
;
}
if
(
pKey1
->
groupId
<
pKey2
->
groupId
)
{
return
-
1
;
}
else
if
(
pKey1
->
groupId
>
pKey2
->
groupId
)
{
return
1
;
}
return
0
;
}
static
int32_t
smaOpenDBDb
(
TDB
**
ppDB
,
TENV
*
pEnv
,
const
char
*
pFName
)
{
int
ret
;
tdb_cmpr_fn_t
compFunc
;
// Create a database
compFunc
=
tdSmaKeyCmpr
;
ret
=
tdbDbOpen
(
pFName
,
-
1
,
-
1
,
compFunc
,
pEnv
,
ppDB
);
return
0
;
}
static
int32_t
smaCloseDBDb
(
TDB
*
pDB
)
{
return
tdbDbClose
(
pDB
);
}
int32_t
smaOpenDBF
(
TENV
*
pEnv
,
SDBFile
*
pDBF
)
{
// TEnv is shared by a group of SDBFile
if
(
!
pEnv
||
!
pDBF
)
{
terrno
=
TSDB_CODE_INVALID_PTR
;
return
-
1
;
}
// Open DBF
if
(
smaOpenDBDb
(
&
(
pDBF
->
pDB
),
pEnv
,
pDBF
->
path
)
<
0
)
{
terrno
=
TSDB_CODE_TDB_INIT_FAILED
;
smaCloseDBDb
(
pDBF
->
pDB
);
return
-
1
;
}
return
0
;
}
int32_t
smaCloseDBF
(
SDBFile
*
pDBF
)
{
int32_t
ret
=
0
;
if
(
pDBF
->
pDB
)
{
ret
=
smaCloseDBDb
(
pDBF
->
pDB
);
pDBF
->
pDB
=
NULL
;
}
taosMemoryFreeClear
(
pDBF
->
path
);
return
ret
;
}
int32_t
smaSaveSmaToDB
(
SDBFile
*
pDBF
,
void
*
pKey
,
int32_t
keyLen
,
void
*
pVal
,
int32_t
valLen
,
TXN
*
txn
)
{
int32_t
ret
;
ret
=
tdbDbInsert
(
pDBF
->
pDB
,
pKey
,
keyLen
,
pVal
,
valLen
,
txn
);
if
(
ret
<
0
)
{
smaError
(
"failed to create insert sma data into db, ret = %d"
,
ret
);
return
-
1
;
}
return
0
;
}
void
*
smaGetSmaDataByKey
(
SDBFile
*
pDBF
,
const
void
*
pKey
,
int32_t
keyLen
,
int32_t
*
valLen
)
{
void
*
pVal
=
NULL
;
int
ret
;
ret
=
tdbDbGet
(
pDBF
->
pDB
,
pKey
,
keyLen
,
&
pVal
,
valLen
);
if
(
ret
<
0
)
{
smaError
(
"failed to get sma data from db, ret = %d"
,
ret
);
return
NULL
;
}
ASSERT
(
*
valLen
>=
0
);
// TODO: lock?
// TODO: Would the key/value be destoryed during return the data?
// TODO: How about the key is updated while value length is changed? The original value buffer would be freed
// automatically?
return
pVal
;
}
\ No newline at end of file
source/dnode/vnode/src/sma/smaTimeRange.c
0 → 100644
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/dnode/vnode/src/tq/tq.c
浏览文件 @
e0b3e97d
...
...
@@ -14,6 +14,7 @@
*/
#include "tq.h"
#include "tqueue.h"
int32_t
tqInit
()
{
//
...
...
@@ -234,7 +235,7 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
if
(
msgType
!=
TDMT_VND_SUBMIT
)
return
0
;
// make sure msgType == TDMT_VND_SUBMIT
if
(
t
sdbUpdateSmaWindow
(
pTq
->
pVnode
->
pTsdb
,
msg
,
ver
)
!=
0
)
{
if
(
t
dUpdateExpireWindow
(
pTq
->
pVnode
->
pSma
,
msg
,
ver
)
!=
0
)
{
return
-
1
;
}
...
...
@@ -1031,3 +1032,90 @@ int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId)
}
return
0
;
}
int32_t
tqProcessStreamTrigger2
(
STQ
*
pTq
,
SSubmitReq
*
pReq
,
int64_t
ver
)
{
void
*
pIter
=
NULL
;
bool
failed
=
false
;
SStreamDataSubmit
*
pSubmit
=
taosAllocateQitem
(
sizeof
(
SStreamDataSubmit
),
DEF_QITEM
);
if
(
pSubmit
==
NULL
)
{
failed
=
true
;
}
pSubmit
->
dataRef
=
taosMemoryMalloc
(
sizeof
(
int32_t
));
if
(
pSubmit
->
dataRef
==
NULL
)
{
failed
=
true
;
}
pSubmit
->
type
=
STREAM_DATA_TYPE_SUBMIT_BLOCK
;
pSubmit
->
sourceVer
=
ver
;
pSubmit
->
sourceVg
=
pTq
->
pVnode
->
config
.
vgId
;
pSubmit
->
data
=
pReq
;
*
pSubmit
->
dataRef
=
1
;
while
(
1
)
{
pIter
=
taosHashIterate
(
pTq
->
pStreamTasks
,
pIter
);
if
(
pIter
==
NULL
)
break
;
SStreamTask
*
pTask
=
(
SStreamTask
*
)
pIter
;
if
(
pTask
->
inputType
!=
STREAM_INPUT__DATA_SUBMIT
)
continue
;
int8_t
inputStatus
=
atomic_load_8
(
&
pTask
->
inputStatus
);
if
(
inputStatus
==
TASK_INPUT_STATUS__NORMAL
)
{
if
(
failed
)
{
atomic_store_8
(
&
pTask
->
inputStatus
,
TASK_INPUT_STATUS__FAILED
);
continue
;
}
streamDataSubmitRefInc
(
pSubmit
);
taosWriteQitem
(
pTask
->
inputQ
,
pSubmit
);
int8_t
execStatus
=
atomic_load_8
(
&
pTask
->
status
);
if
(
execStatus
==
TASK_STATUS__IDLE
||
execStatus
==
TASK_STATUS__CLOSING
)
{
// TODO dispatch task launch msg to fetch queue
}
}
else
{
// blocked or stopped, do nothing
}
}
if
(
!
failed
)
{
streamDataSubmitRefDec
(
pSubmit
);
return
0
;
}
else
{
return
-
1
;
}
}
int32_t
tqProcessTaskExec2
(
STQ
*
pTq
,
char
*
msg
,
int32_t
msgLen
)
{
SStreamTaskExecReq
req
=
{
0
};
tDecodeSStreamTaskExecReq
(
msg
,
&
req
);
int32_t
taskId
=
req
.
taskId
;
SStreamTask
*
pTask
=
taosHashGet
(
pTq
->
pStreamTasks
,
&
taskId
,
sizeof
(
int32_t
));
ASSERT
(
pTask
);
ASSERT
(
pTask
->
inputType
==
TASK_INPUT_TYPE__DATA_BLOCK
);
// enqueue
int32_t
inputStatus
=
streamEnqueueDataBlk
(
pTask
,
(
SStreamDataBlock
*
)
req
.
data
);
if
(
inputStatus
==
TASK_INPUT_STATUS__BLOCKED
)
{
// TODO rsp blocked
return
0
;
}
// try exec
int8_t
execStatus
=
atomic_val_compare_exchange_8
(
&
pTask
->
status
,
TASK_STATUS__IDLE
,
TASK_STATUS__EXECUTING
);
if
(
execStatus
==
TASK_STATUS__IDLE
)
{
if
(
streamTaskRun
(
pTask
)
<
0
)
{
atomic_store_8
(
&
pTask
->
status
,
TASK_STATUS__CLOSING
);
goto
FAIL
;
}
}
else
if
(
execStatus
==
TASK_STATUS__EXECUTING
)
{
return
0
;
}
// TODO rsp success
return
0
;
FAIL:
return
-
1
;
}
source/dnode/vnode/src/tsdb/tsdbCommit2.c
浏览文件 @
e0b3e97d
...
...
@@ -16,6 +16,8 @@
#include "tsdb.h"
int
tsdbBegin
(
STsdb
*
pTsdb
)
{
if
(
!
pTsdb
)
return
0
;
STsdbMemTable
*
pMem
;
if
(
tsdbMemTableCreate
(
pTsdb
,
&
pTsdb
->
mem
)
<
0
)
{
...
...
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
e0b3e97d
...
...
@@ -37,12 +37,12 @@ static void tsdbScanAndTryFixDFilesHeader(STsdb *pRepo, int32_t *nExpired);
// static int tsdbProcessExpiredFS(STsdb *pRepo);
// static int tsdbCreateMeta(STsdb *pRepo);
static
void
tsdbGetRootDir
(
int
repoid
,
int8_t
level
,
char
dirName
[])
{
snprintf
(
dirName
,
TSDB_FILENAME_LEN
,
"vnode/vnode%d/%s"
,
repoid
,
TSDB_LEVEL_DNAME
[
level
]
);
static
void
tsdbGetRootDir
(
int
repoid
,
const
char
*
dir
,
char
dirName
[])
{
snprintf
(
dirName
,
TSDB_FILENAME_LEN
,
"vnode/vnode%d/%s"
,
repoid
,
dir
);
}
static
void
tsdbGetDataDir
(
int
repoid
,
int8_t
level
,
char
dirName
[])
{
snprintf
(
dirName
,
TSDB_FILENAME_LEN
,
"vnode/vnode%d/%s/data"
,
repoid
,
TSDB_LEVEL_DNAME
[
level
]
);
static
void
tsdbGetDataDir
(
int
repoid
,
const
char
*
dir
,
char
dirName
[])
{
snprintf
(
dirName
,
TSDB_FILENAME_LEN
,
"vnode/vnode%d/%s/data"
,
repoid
,
dir
);
}
// For backward compatibility
...
...
@@ -591,7 +591,7 @@ static int tsdbComparFidFSet(const void *arg1, const void *arg2) {
static
void
tsdbGetTxnFname
(
STsdb
*
pRepo
,
TSDB_TXN_FILE_T
ftype
,
char
fname
[])
{
snprintf
(
fname
,
TSDB_FILENAME_LEN
,
"%s/vnode/vnode%d/%s/%s"
,
tfsGetPrimaryPath
(
REPO_TFS
(
pRepo
)),
REPO_ID
(
pRepo
),
TSDB_LEVEL_DNAME
[
REPO_LEVEL
(
pRepo
)]
,
tsdbTxnFname
[
ftype
]);
pRepo
->
dir
,
tsdbTxnFname
[
ftype
]);
}
static
int
tsdbOpenFSFromCurrent
(
STsdb
*
pRepo
)
{
...
...
@@ -721,7 +721,7 @@ static int tsdbScanRootDir(STsdb *pRepo) {
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
const
STfsFile
*
pf
;
tsdbGetRootDir
(
REPO_ID
(
pRepo
),
REPO_LEVEL
(
pRepo
)
,
rootDir
);
tsdbGetRootDir
(
REPO_ID
(
pRepo
),
pRepo
->
dir
,
rootDir
);
STfsDir
*
tdir
=
tfsOpendir
(
REPO_TFS
(
pRepo
),
rootDir
);
if
(
tdir
==
NULL
)
{
tsdbError
(
"vgId:%d failed to open directory %s since %s"
,
REPO_ID
(
pRepo
),
rootDir
,
tstrerror
(
terrno
));
...
...
@@ -755,7 +755,7 @@ static int tsdbScanDataDir(STsdb *pRepo) {
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
const
STfsFile
*
pf
;
tsdbGetDataDir
(
REPO_ID
(
pRepo
),
REPO_LEVEL
(
pRepo
)
,
dataDir
);
tsdbGetDataDir
(
REPO_ID
(
pRepo
),
pRepo
->
dir
,
dataDir
);
STfsDir
*
tdir
=
tfsOpendir
(
REPO_TFS
(
pRepo
),
dataDir
);
if
(
tdir
==
NULL
)
{
tsdbError
(
"vgId:%d failed to open directory %s since %s"
,
REPO_ID
(
pRepo
),
dataDir
,
tstrerror
(
terrno
));
...
...
@@ -803,7 +803,7 @@ static int tsdbRestoreDFileSet(STsdb *pRepo) {
regex_t
regex
;
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
tsdbGetDataDir
(
REPO_ID
(
pRepo
),
REPO_LEVEL
(
pRepo
)
,
dataDir
);
tsdbGetDataDir
(
REPO_ID
(
pRepo
),
pRepo
->
dir
,
dataDir
);
// Resource allocation and init
regcomp
(
&
regex
,
pattern
,
REG_EXTENDED
);
...
...
source/dnode/vnode/src/tsdb/tsdbFile.c
浏览文件 @
e0b3e97d
...
...
@@ -23,14 +23,6 @@ static const char *TSDB_FNAME_SUFFIX[] = {
"smal"
,
// TSDB_FILE_SMAL
""
,
// TSDB_FILE_MAX
"meta"
,
// TSDB_FILE_META
"tsma"
,
// TSDB_FILE_TSMA
"rsma"
,
// TSDB_FILE_RSMA
};
const
char
*
TSDB_LEVEL_DNAME
[]
=
{
"tsdb"
,
"rsma1"
,
"rsma2"
,
};
static
void
tsdbGetFilename
(
int
vid
,
int
fid
,
uint32_t
ver
,
TSDB_FILE_T
ftype
,
const
char
*
dname
,
char
*
fname
);
...
...
@@ -51,7 +43,7 @@ void tsdbInitDFile(STsdb *pRepo, SDFile *pDFile, SDiskID did, int fid, uint32_t
pDFile
->
info
.
magic
=
TSDB_FILE_INIT_MAGIC
;
pDFile
->
info
.
fver
=
tsdbGetDFSVersion
(
ftype
);
tsdbGetFilename
(
REPO_ID
(
pRepo
),
fid
,
ver
,
ftype
,
TSDB_LEVEL_DNAME
[
pRepo
->
level
]
,
fname
);
tsdbGetFilename
(
REPO_ID
(
pRepo
),
fid
,
ver
,
ftype
,
pRepo
->
dir
,
fname
);
tfsInitFile
(
REPO_TFS
(
pRepo
),
&
(
pDFile
->
f
),
did
,
fname
);
}
...
...
source/dnode/vnode/src/tsdb/tsdbOpen.c
浏览文件 @
e0b3e97d
...
...
@@ -15,100 +15,17 @@
#include "tsdb.h"
#define TSDB_OPEN_RSMA_IMPL(v, l) \
do { \
SRetention *r = VND_RETENTIONS(v)[0]; \
if (RETENTION_VALID(r)) { \
return tsdbOpenImpl((v), type, &VND_RSMA##l(v), VNODE_RSMA##l##_DIR, TSDB_RETENTION_L##l); \
} \
} while (0)
#define TSDB_SET_KEEP_CFG(l) \
do { \
SRetention *r = &pCfg->retentions[l]; \
pKeepCfg->keep2 = convertTimeFromPrecisionToUnit(r->keep, pCfg->precision, TIME_UNIT_MINUTE); \
pKeepCfg->keep0 = pKeepCfg->keep2; \
pKeepCfg->keep1 = pKeepCfg->keep2; \
pKeepCfg->days = tsdbEvalDays(r, pCfg->precision); \
} while (0)
#define RETENTION_DAYS_SPLIT_RATIO 10
#define RETENTION_DAYS_SPLIT_MIN 1
#define RETENTION_DAYS_SPLIT_MAX 30
static
int32_t
tsdbSetKeepCfg
(
STsdbKeepCfg
*
pKeepCfg
,
STsdbCfg
*
pCfg
,
int8_t
type
);
static
int32_t
tsdbEvalDays
(
SRetention
*
r
,
int8_t
precision
);
static
int32_t
tsdbOpenImpl
(
SVnode
*
pVnode
,
int8_t
type
,
STsdb
**
ppTsdb
,
const
char
*
dir
,
int8_t
level
);
int
tsdbOpen
(
SVnode
*
pVnode
,
int8_t
type
)
{
switch
(
type
)
{
case
TSDB_TYPE_TSDB
:
return
tsdbOpenImpl
(
pVnode
,
type
,
&
VND_TSDB
(
pVnode
),
VNODE_TSDB_DIR
,
TSDB_RETENTION_L0
);
case
TSDB_TYPE_TSMA
:
ASSERT
(
0
);
break
;
case
TSDB_TYPE_RSMA_L0
:
TSDB_OPEN_RSMA_IMPL
(
pVnode
,
0
);
break
;
case
TSDB_TYPE_RSMA_L1
:
TSDB_OPEN_RSMA_IMPL
(
pVnode
,
1
);
break
;
case
TSDB_TYPE_RSMA_L2
:
TSDB_OPEN_RSMA_IMPL
(
pVnode
,
2
);
break
;
default:
ASSERT
(
0
);
break
;
}
return
0
;
}
static
int
tsdbSetKeepCfg
(
STsdbKeepCfg
*
pKeepCfg
,
STsdbCfg
*
pCfg
);
static
int32_t
tsdbEvalDays
(
SRetention
*
r
,
int8_t
precision
)
{
int32_t
keepDays
=
convertTimeFromPrecisionToUnit
(
r
->
keep
,
precision
,
TIME_UNIT_DAY
);
int32_t
freqDays
=
convertTimeFromPrecisionToUnit
(
r
->
freq
,
precision
,
TIME_UNIT_DAY
);
int32_t
days
=
keepDays
/
RETENTION_DAYS_SPLIT_RATIO
;
if
(
days
<=
RETENTION_DAYS_SPLIT_MIN
)
{
days
=
RETENTION_DAYS_SPLIT_MIN
;
if
(
days
<
freqDays
)
{
days
=
freqDays
+
1
;
}
}
else
{
if
(
days
>
RETENTION_DAYS_SPLIT_MAX
)
{
days
=
RETENTION_DAYS_SPLIT_MAX
;
}
if
(
days
<
freqDays
)
{
days
=
freqDays
+
1
;
}
}
return
days
*
1440
;
}
// implementation
static
int
32_t
tsdbSetKeepCfg
(
STsdbKeepCfg
*
pKeepCfg
,
STsdbCfg
*
pCfg
,
int8_t
type
)
{
static
int
tsdbSetKeepCfg
(
STsdbKeepCfg
*
pKeepCfg
,
STsdbCfg
*
pCfg
)
{
pKeepCfg
->
precision
=
pCfg
->
precision
;
switch
(
type
)
{
case
TSDB_TYPE_TSDB
:
pKeepCfg
->
days
=
pCfg
->
days
;
pKeepCfg
->
keep0
=
pCfg
->
keep0
;
pKeepCfg
->
keep1
=
pCfg
->
keep1
;
pKeepCfg
->
keep2
=
pCfg
->
keep2
;
break
;
case
TSDB_TYPE_TSMA
:
ASSERT
(
0
);
break
;
case
TSDB_TYPE_RSMA_L0
:
TSDB_SET_KEEP_CFG
(
0
);
break
;
case
TSDB_TYPE_RSMA_L1
:
TSDB_SET_KEEP_CFG
(
1
);
break
;
case
TSDB_TYPE_RSMA_L2
:
TSDB_SET_KEEP_CFG
(
2
);
break
;
default:
ASSERT
(
0
);
break
;
}
return
0
;
}
...
...
@@ -116,18 +33,16 @@ static int32_t tsdbSetKeepCfg(STsdbKeepCfg *pKeepCfg, STsdbCfg *pCfg, int8_t typ
* @brief
*
* @param pVnode
* @param type
* @param ppTsdb
* @param dir
* @param level retention level
* @return int
*/
int
32_t
tsdbOpenImpl
(
SVnode
*
pVnode
,
int8_t
type
,
STsdb
**
ppTsdb
,
const
char
*
dir
,
int8_t
level
)
{
int
tsdbOpen
(
SVnode
*
pVnode
,
STsdb
**
ppTsdb
,
const
char
*
dir
,
STsdbKeepCfg
*
pKeepCfg
)
{
STsdb
*
pTsdb
=
NULL
;
int
slen
=
0
;
*
ppTsdb
=
NULL
;
slen
=
strlen
(
tfsGetPrimaryPath
(
pVnode
->
pTfs
))
+
strlen
(
pVnode
->
path
)
+
strlen
(
dir
)
+
3
;
slen
=
strlen
(
tfsGetPrimaryPath
(
pVnode
->
pTfs
))
+
strlen
(
pVnode
->
path
)
+
strlen
(
dir
)
+
TSDB_DATA_DIR_LEN
+
3
;
// create handle
pTsdb
=
(
STsdb
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pTsdb
)
+
slen
);
...
...
@@ -136,13 +51,18 @@ int32_t tsdbOpenImpl(SVnode *pVnode, int8_t type, STsdb **ppTsdb, const char *di
return
-
1
;
}
ASSERT
(
strlen
(
dir
)
<
TSDB_DATA_DIR_LEN
);
memcpy
(
pTsdb
->
dir
,
dir
,
strlen
(
dir
));
pTsdb
->
path
=
(
char
*
)
&
pTsdb
[
1
];
sprintf
(
pTsdb
->
path
,
"%s%s%s%s%s"
,
tfsGetPrimaryPath
(
pVnode
->
pTfs
),
TD_DIRSEP
,
pVnode
->
path
,
TD_DIRSEP
,
dir
);
pTsdb
->
pVnode
=
pVnode
;
pTsdb
->
level
=
level
;
pTsdb
->
repoLocked
=
false
;
taosThreadMutexInit
(
&
pTsdb
->
mutex
,
NULL
);
tsdbSetKeepCfg
(
REPO_KEEP_CFG
(
pTsdb
),
REPO_CFG
(
pTsdb
),
type
);
if
(
!
pKeepCfg
)
{
tsdbSetKeepCfg
(
&
pTsdb
->
keepCfg
,
&
pVnode
->
config
.
tsdbCfg
);
}
else
{
memcpy
(
&
pTsdb
->
keepCfg
,
pKeepCfg
,
sizeof
(
STsdbKeepCfg
));
}
pTsdb
->
fs
=
tsdbNewFS
(
REPO_KEEP_CFG
(
pTsdb
));
// create dir (TODO: use tfsMkdir)
...
...
@@ -163,12 +83,13 @@ _err:
return
-
1
;
}
int
tsdbClose
(
STsdb
*
pTsdb
)
{
if
(
pTsdb
)
{
int
tsdbClose
(
STsdb
*
*
pTsdb
)
{
if
(
*
pTsdb
)
{
// TODO: destroy mem/imem
tsdbCloseFS
(
pTsdb
);
tsdbFreeFS
(
pTsdb
->
fs
);
taosMemoryFree
(
pTsdb
);
taosThreadMutexDestroy
(
&
(
*
pTsdb
)
->
mutex
);
tsdbCloseFS
(
*
pTsdb
);
tsdbFreeFS
((
*
pTsdb
)
->
fs
);
taosMemoryFreeClear
(
*
pTsdb
);
}
return
0
;
}
...
...
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
e0b3e97d
...
...
@@ -2769,20 +2769,8 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
}
while
(
moveToNextRowInMem
(
pCheckInfo
));
taosMemoryFreeClear
(
pSchema
);
// free the STSChema
assert
(
numOfRows
<=
maxRowsToRead
);
// if the buffer is not full in case of descending order query, move the data in the front of the buffer
if
(
!
ASCENDING_TRAVERSE
(
pTsdbReadHandle
->
order
)
&&
numOfRows
<
maxRowsToRead
)
{
int32_t
emptySize
=
maxRowsToRead
-
numOfRows
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pTsdbReadHandle
->
pColumns
,
i
);
memmove
((
char
*
)
pColInfo
->
pData
,
(
char
*
)
pColInfo
->
pData
+
emptySize
*
pColInfo
->
info
.
bytes
,
numOfRows
*
pColInfo
->
info
.
bytes
);
}
}
int64_t
elapsedTime
=
taosGetTimestampUs
()
-
st
;
tsdbDebug
(
"%p build data block from cache completed, elapsed time:%"
PRId64
" us, numOfRows:%d, numOfCols:%d, %s"
,
pTsdbReadHandle
,
elapsedTime
,
numOfRows
,
numOfCols
,
pTsdbReadHandle
->
idStr
);
...
...
source/dnode/vnode/src/vnd/vnodeCommit.c
浏览文件 @
e0b3e97d
...
...
@@ -47,7 +47,7 @@ int vnodeBegin(SVnode *pVnode) {
}
// begin tsdb
if
(
vnodeIsRollup
(
pVnode
)
)
{
if
(
pVnode
->
pSma
)
{
if
(
tsdbBegin
(
VND_RSMA0
(
pVnode
))
<
0
)
{
vError
(
"vgId:%d failed to begin rsma0 since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
return
-
1
;
...
...
source/dnode/vnode/src/vnd/vnodeOpen.c
浏览文件 @
e0b3e97d
...
...
@@ -96,27 +96,16 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
}
// open tsdb
if
(
vnodeIsRollup
(
pVnode
))
{
if
(
tsdbOpen
(
pVnode
,
TSDB_TYPE_RSMA_L0
)
<
0
)
{
vError
(
"vgId:%d failed to open vnode rsma0 since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
goto
_err
;
}
if
(
tsdbOpen
(
pVnode
,
TSDB_TYPE_RSMA_L1
)
<
0
)
{
vError
(
"vgId:%d failed to open vnode rsma1 since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
if
(
!
vnodeIsRollup
(
pVnode
)
&&
tsdbOpen
(
pVnode
,
&
VND_TSDB
(
pVnode
),
VNODE_TSDB_DIR
,
TSDB_TYPE_TSDB
)
<
0
)
{
vError
(
"vgId:%d failed to open vnode tsdb since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
goto
_err
;
}
if
(
tsdbOpen
(
pVnode
,
TSDB_TYPE_RSMA_L2
)
<
0
)
{
vError
(
"vgId:%d failed to open vnode rsma2 since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
goto
_err
;
}
}
else
{
if
(
tsdbOpen
(
pVnode
,
TSDB_TYPE_TSDB
)
<
0
)
{
// open sma
if
(
smaOpen
(
pVnode
))
{
vError
(
"vgId:%d failed to open vnode tsdb since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
goto
_err
;
}
}
// open wal
sprintf
(
tdir
,
"%s%s%s"
,
dir
,
TD_DIRSEP
,
VNODE_WAL_DIR
);
...
...
@@ -161,10 +150,10 @@ _err:
if
(
pVnode
->
pQuery
)
vnodeQueryClose
(
pVnode
);
if
(
pVnode
->
pTq
)
tqClose
(
pVnode
->
pTq
);
if
(
pVnode
->
pWal
)
walClose
(
pVnode
->
pWal
);
if
(
pVnode
->
pTsdb
)
tsdbClose
(
pVnode
->
pTsdb
);
if
(
pVnode
->
pTsdb
)
tsdbClose
(
&
pVnode
->
pTsdb
);
if
(
pVnode
->
pMeta
)
metaClose
(
pVnode
->
pMeta
);
tsdbClose
(
VND_RSMA1
(
pVnode
)
);
tsdbClose
(
VND_RSMA2
(
pVnode
));
if
(
pVnode
->
pSma
)
smaClose
(
pVnode
->
pSma
);
tsem_destroy
(
&
(
pVnode
->
canCommit
));
taosMemoryFree
(
pVnode
);
return
NULL
;
...
...
@@ -177,9 +166,8 @@ void vnodeClose(SVnode *pVnode) {
vnodeQueryClose
(
pVnode
);
walClose
(
pVnode
->
pWal
);
tqClose
(
pVnode
->
pTq
);
tsdbClose
(
VND_TSDB
(
pVnode
));
tsdbClose
(
VND_RSMA1
(
pVnode
));
tsdbClose
(
VND_RSMA2
(
pVnode
));
if
(
pVnode
->
pTsdb
)
tsdbClose
(
&
pVnode
->
pTsdb
);
smaClose
(
pVnode
->
pSma
);
metaClose
(
pVnode
->
pMeta
);
vnodeCloseBufPool
(
pVnode
);
// destroy handle
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
e0b3e97d
...
...
@@ -22,6 +22,7 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq,
static
int
vnodeProcessAlterTbReq
(
SVnode
*
pVnode
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
);
static
int
vnodeProcessDropTbReq
(
SVnode
*
pVnode
,
int64_t
version
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
);
static
int
vnodeProcessSubmitReq
(
SVnode
*
pVnode
,
int64_t
version
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
);
static
int
vnodeProcessCreateTSmaReq
(
SVnode
*
pVnode
,
int64_t
version
,
void
*
pReq
,
int
len
,
SRpcMsg
*
pRsp
);
int
vnodePreprocessWriteReqs
(
SVnode
*
pVnode
,
SArray
*
pMsgs
,
int64_t
*
version
)
{
#if 0
...
...
@@ -86,10 +87,8 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
case
TDMT_VND_DROP_TABLE
:
if
(
vnodeProcessDropTbReq
(
pVnode
,
version
,
pReq
,
len
,
pRsp
)
<
0
)
goto
_err
;
break
;
case
TDMT_VND_CREATE_SMA
:
{
// timeRangeSMA
if
(
tsdbCreateTSma
(
pVnode
->
pTsdb
,
POINTER_SHIFT
(
pMsg
->
pCont
,
sizeof
(
SMsgHead
)))
<
0
)
{
// TODO
}
case
TDMT_VND_CREATE_SMA
:
{
if
(
vnodeProcessCreateTSmaReq
(
pVnode
,
version
,
pReq
,
len
,
pRsp
)
<
0
)
goto
_err
;
}
break
;
/* TSDB */
case
TDMT_VND_SUBMIT
:
...
...
@@ -195,7 +194,7 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
// TODO
// blockDebugShowData(data);
t
sdbInsertTSmaData
(((
SVnode
*
)
pVnode
)
->
pTsdb
,
smaId
,
(
const
char
*
)
data
);
t
dProcessTSmaInsert
(((
SVnode
*
)
pVnode
)
->
pSma
,
smaId
,
(
const
char
*
)
data
);
}
int
vnodeProcessSyncReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
...
...
@@ -305,7 +304,7 @@ static int vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *pReq,
goto
_err
;
}
t
sdbRegisterRSma
(
pVnode
->
pTsdb
,
pVnode
->
pMeta
,
&
req
,
&
pVnode
->
msgCb
);
t
dProcessRSmaCreate
(
pVnode
->
pSma
,
pVnode
->
pMeta
,
&
req
,
&
pVnode
->
msgCb
);
tDecoderClear
(
&
coder
);
return
0
;
...
...
@@ -366,7 +365,7 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq,
}
}
else
{
cRsp
.
code
=
TSDB_CODE_SUCCESS
;
t
sdbFetchTbUidList
(
pVnode
->
pTsdb
,
&
pStore
,
pCreateReq
->
ctb
.
suid
,
pCreateReq
->
uid
);
t
dFetchTbUidList
(
pVnode
->
pSma
,
&
pStore
,
pCreateReq
->
ctb
.
suid
,
pCreateReq
->
uid
);
}
taosArrayPush
(
rsp
.
pArray
,
&
cRsp
);
...
...
@@ -374,8 +373,8 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq,
tDecoderClear
(
&
decoder
);
t
sdbUpdateTbUidList
(
pVnode
->
pTsdb
,
pStore
);
t
sdb
UidStoreFree
(
pStore
);
t
dUpdateTbUidList
(
pVnode
->
pSma
,
pStore
);
t
d
UidStoreFree
(
pStore
);
// prepare rsp
SEncoder
encoder
=
{
0
};
...
...
@@ -649,8 +648,38 @@ _exit:
// TODO: refactor
if
((
terrno
==
TSDB_CODE_SUCCESS
||
terrno
==
TSDB_CODE_TDB_TABLE_ALREADY_EXIST
)
&&
(
pRsp
->
code
==
TSDB_CODE_SUCCESS
))
{
t
sdbTriggerRSma
(
pVnode
->
pTsdb
,
pReq
,
STREAM_DATA_TYPE_SUBMIT_BLOCK
);
t
dProcessRSmaSubmit
(
pVnode
->
pSma
,
pReq
,
STREAM_DATA_TYPE_SUBMIT_BLOCK
);
}
return
0
;
}
static
int
vnodeProcessCreateTSmaReq
(
SVnode
*
pVnode
,
int64_t
version
,
void
*
pReq
,
int
len
,
SRpcMsg
*
pRsp
)
{
SVCreateTSmaReq
req
=
{
0
};
SDecoder
coder
;
pRsp
->
msgType
=
TDMT_VND_CREATE_SMA_RSP
;
pRsp
->
code
=
TSDB_CODE_SUCCESS
;
pRsp
->
pCont
=
NULL
;
pRsp
->
contLen
=
0
;
// decode and process req
tDecoderInit
(
&
coder
,
pReq
,
len
);
if
(
tDecodeSVCreateTSmaReq
(
&
coder
,
&
req
)
<
0
)
{
pRsp
->
code
=
terrno
;
goto
_err
;
}
if
(
metaCreateTSma
(
pVnode
->
pMeta
,
version
,
&
req
)
<
0
)
{
pRsp
->
code
=
terrno
;
goto
_err
;
}
tDecoderClear
(
&
coder
);
return
0
;
_err:
tDecoderClear
(
&
coder
);
return
-
1
;
}
source/libs/executor/inc/executorimpl.h
浏览文件 @
e0b3e97d
...
...
@@ -651,7 +651,7 @@ void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t
int32_t
getTableScanInfo
(
SOperatorInfo
*
pOperator
,
int32_t
*
order
,
int32_t
*
scanFlag
);
void
doSetOperatorCompleted
(
SOperatorInfo
*
pOperator
);
void
doFilter
(
const
SNode
*
pFilterNode
,
SSDataBlock
*
pBlock
);
void
doFilter
(
const
SNode
*
pFilterNode
,
SSDataBlock
*
pBlock
,
SArray
*
pColMatchInfo
);
SqlFunctionCtx
*
createSqlFunctionCtx
(
SExprInfo
*
pExprInfo
,
int32_t
numOfOutput
,
int32_t
**
rowCellInfoOffset
);
void
relocateColumnData
(
SSDataBlock
*
pBlock
,
const
SArray
*
pColMatchInfo
,
SArray
*
pCols
);
void
initExecTimeWindowInfo
(
SColumnInfoData
*
pColData
,
STimeWindow
*
pQueryWindow
);
...
...
source/libs/executor/src/executorMain.c
浏览文件 @
e0b3e97d
...
...
@@ -21,13 +21,14 @@
#include "tcache.h"
#include "tglobal.h"
#include "tmsg.h"
#include "tudf.h"
#include "thash.h"
#include "executorimpl.h"
#include "executor.h"
#include "executorimpl.h"
#include "query.h"
#include "thash.h"
#include "tlosertree.h"
#include "ttypes.h"
#include "query.h"
typedef
struct
STaskMgmt
{
TdThreadMutex
lock
;
...
...
@@ -156,6 +157,7 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) {
int32_t
current
=
(
*
pRes
!=
NULL
)
?
(
*
pRes
)
->
info
.
rows
:
0
;
pTaskInfo
->
totalRows
+=
current
;
teardownUdfs
();
qDebug
(
"%s task suspended, %d rows returned, total:%"
PRId64
" rows, in sinkNode:%d, elapsed:%.2f ms"
,
GET_TASKID
(
pTaskInfo
),
current
,
pTaskInfo
->
totalRows
,
0
,
el
/
1000
.
0
);
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
e0b3e97d
...
...
@@ -2115,7 +2115,7 @@ void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numO
}
static
void
extractQualifiedTupleByFilterResult
(
SSDataBlock
*
pBlock
,
const
int8_t
*
rowRes
,
bool
keep
);
void
doFilter
(
const
SNode
*
pFilterNode
,
SSDataBlock
*
pBlock
)
{
void
doFilter
(
const
SNode
*
pFilterNode
,
SSDataBlock
*
pBlock
,
SArray
*
pColMatchInfo
)
{
if
(
pFilterNode
==
NULL
)
{
return
;
}
...
...
@@ -2129,6 +2129,7 @@ void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock) {
code
=
filterSetDataFromSlotId
(
filter
,
&
param1
);
int8_t
*
rowRes
=
NULL
;
// todo the keep seems never to be True??
bool
keep
=
filterExecute
(
filter
,
pBlock
,
&
rowRes
,
NULL
,
param1
.
numOfCols
);
filterFreeInfo
(
filter
);
...
...
@@ -2152,11 +2153,6 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const int8_t* rowR
SColumnInfoData
*
pDst
=
taosArrayGet
(
px
->
pDataBlock
,
i
);
SColumnInfoData
*
pSrc
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
// For the reserved column, the value is not filled yet, so the whole column data may be NULL.
if
(
pSrc
->
pData
==
NULL
)
{
continue
;
}
int32_t
numOfRows
=
0
;
for
(
int32_t
j
=
0
;
j
<
totalRows
;
++
j
)
{
if
(
rowRes
[
j
]
==
0
)
{
...
...
@@ -5504,18 +5500,21 @@ static SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator) {
int32_t
blockId
=
pExprInfo
->
base
.
pParam
[
0
].
pCol
->
dataBlockId
;
int32_t
slotId
=
pExprInfo
->
base
.
pParam
[
0
].
pCol
->
slotId
;
int32_t
rowIndex
=
-
1
;
SColumnInfoData
*
pSrc
=
NULL
;
if
(
pJoinInfo
->
pLeft
->
info
.
blockId
==
blockId
)
{
pSrc
=
taosArrayGet
(
pJoinInfo
->
pLeft
->
pDataBlock
,
slotId
);
rowIndex
=
pJoinInfo
->
leftPos
;
}
else
{
pSrc
=
taosArrayGet
(
pJoinInfo
->
pRight
->
pDataBlock
,
slotId
);
rowIndex
=
pJoinInfo
->
rightPos
;
}
if
(
colDataIsNull_s
(
pSrc
,
pJoinInfo
->
leftPos
))
{
if
(
colDataIsNull_s
(
pSrc
,
rowIndex
))
{
colDataAppendNULL
(
pDst
,
nrows
);
}
else
{
char
*
p
=
colDataGetData
(
pSrc
,
pJoinInfo
->
leftPos
);
char
*
p
=
colDataGetData
(
pSrc
,
rowIndex
);
colDataAppend
(
pDst
,
nrows
,
p
,
false
);
}
}
...
...
source/libs/executor/src/groupoperator.c
浏览文件 @
e0b3e97d
...
...
@@ -318,7 +318,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
while
(
1
)
{
doBuildResultDatablock
(
pOperator
,
&
pInfo
->
binfo
,
&
pInfo
->
groupResInfo
,
pInfo
->
aggSup
.
pResultBuf
);
doFilter
(
pInfo
->
pCondition
,
pRes
);
doFilter
(
pInfo
->
pCondition
,
pRes
,
NULL
);
bool
hasRemain
=
hasRemainDataInCurrentGroup
(
&
pInfo
->
groupResInfo
);
if
(
!
hasRemain
)
{
...
...
source/libs/executor/src/indexoperator.c
浏览文件 @
e0b3e97d
...
...
@@ -398,6 +398,10 @@ static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) {
output
->
status
=
SFLT_ACCURATE_INDEX
;
}
if
(
ctx
->
noExec
)
{
SIF_RET
(
code
);
}
return
operFn
(
&
params
[
0
],
nParam
>
1
?
&
params
[
1
]
:
NULL
,
output
);
_return:
taosMemoryFree
(
params
);
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
e0b3e97d
...
...
@@ -159,6 +159,8 @@ static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockIn
return
false
;
}
static
void
addTagPseudoColumnData
(
STableScanInfo
*
pTableScanInfo
,
SSDataBlock
*
pBlock
);
static
int32_t
loadDataBlock
(
SOperatorInfo
*
pOperator
,
STableScanInfo
*
pTableScanInfo
,
SSDataBlock
*
pBlock
,
uint32_t
*
status
)
{
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
...
...
@@ -238,8 +240,15 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca
}
relocateColumnData
(
pBlock
,
pTableScanInfo
->
pColMatchInfo
,
pCols
);
// currently only the tbname pseudo column
if
(
pTableScanInfo
->
numOfPseudoExpr
>
0
)
{
addTagPseudoColumnData
(
pTableScanInfo
,
pBlock
);
}
// todo record the filter time cost
doFilter
(
pTableScanInfo
->
pFilterNode
,
pBlock
);
doFilter
(
pTableScanInfo
->
pFilterNode
,
pBlock
,
pTableScanInfo
->
pColMatchInfo
);
if
(
pBlock
->
info
.
rows
==
0
)
{
pCost
->
filterOutBlocks
+=
1
;
qDebug
(
"%s data block filter out, brange:%"
PRId64
"-%"
PRId64
", rows:%d"
,
GET_TASKID
(
pTaskInfo
),
...
...
@@ -260,7 +269,7 @@ static void prepareForDescendingScan(STableScanInfo* pTableScanInfo, SqlFunction
pTableScanInfo
->
cond
.
order
=
TSDB_ORDER_DESC
;
}
static
void
addTagPseudoColumnData
(
STableScanInfo
*
pTableScanInfo
,
SSDataBlock
*
pBlock
)
{
void
addTagPseudoColumnData
(
STableScanInfo
*
pTableScanInfo
,
SSDataBlock
*
pBlock
)
{
// currently only the tbname pseudo column
if
(
pTableScanInfo
->
numOfPseudoExpr
==
0
)
{
return
;
...
...
@@ -330,11 +339,6 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
continue
;
}
// currently only the tbname pseudo column
if
(
pTableScanInfo
->
numOfPseudoExpr
>
0
)
{
addTagPseudoColumnData
(
pTableScanInfo
,
pBlock
);
}
return
pBlock
;
}
...
...
@@ -750,7 +754,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
return
NULL
;
}
rows
=
pBlockInfo
->
rows
;
doFilter
(
pInfo
->
pCondition
,
pInfo
->
pRes
);
doFilter
(
pInfo
->
pCondition
,
pInfo
->
pRes
,
NULL
);
break
;
}
...
...
source/libs/executor/test/index_executor_tests.cpp
浏览文件 @
e0b3e97d
...
...
@@ -249,7 +249,7 @@ TEST(testCase, index_filter_varify) {
sifMakeOpNode
(
&
opNode
,
OP_TYPE_LOWER_THAN
,
TSDB_DATA_TYPE_DOUBLE
,
pLeft
,
pRight
);
SIdxFltStatus
st
=
idxGetFltStatus
(
opNode
);
EXPECT_EQ
(
st
,
SFLT_
COARS
E_INDEX
);
EXPECT_EQ
(
st
,
SFLT_
ACCURAT
E_INDEX
);
nodesDestroyNode
(
res
);
}
{
...
...
@@ -269,7 +269,7 @@ TEST(testCase, index_filter_varify) {
sifMakeOpNode
(
&
opNode
,
OP_TYPE_GREATER_THAN
,
TSDB_DATA_TYPE_DOUBLE
,
pLeft
,
pRight
);
SIdxFltStatus
st
=
idxGetFltStatus
(
opNode
);
EXPECT_EQ
(
st
,
SFLT_
COARS
E_INDEX
);
EXPECT_EQ
(
st
,
SFLT_
ACCURAT
E_INDEX
);
nodesDestroyNode
(
res
);
}
}
...
...
source/libs/function/inc/udfc.h
浏览文件 @
e0b3e97d
...
...
@@ -43,7 +43,7 @@ int32_t setupUdf(SUdfInfo* udf, UdfcFuncHandle* handle);
int32_t
callUdf
(
UdfcFuncHandle
handle
,
int8_t
step
,
char
*
state
,
int32_t
stateSize
,
SSDataBlock
input
,
char
**
newstate
,
int32_t
*
newStateSize
,
SSDataBlock
*
output
);
int32_t
t
eardownUdf
(
UdfcFuncHandle
handle
);
int32_t
doT
eardownUdf
(
UdfcFuncHandle
handle
);
typedef
struct
SUdfSetupRequest
{
char
udfName
[
16
];
//
...
...
source/libs/function/src/tudf.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/function/test/runUdf.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/index/inc/indexComm.h
浏览文件 @
e0b3e97d
...
...
@@ -37,6 +37,8 @@ TExeCond tDoCommpare(__compar_fn_t func, int8_t comType, void* a, void* b);
_cache_range_compare
indexGetCompare
(
RangeType
ty
);
int32_t
indexConvertData
(
void
*
src
,
int8_t
type
,
void
**
dst
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/index/inc/indexInt.h
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/index/src/index.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/index/src/indexCache.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/index/src/indexComm.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/index/src/indexFstUtil.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/index/src/indexTfile.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/index/test/jsonUT.cc
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/parser/src/parAstCreater.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/parser/src/parAuthenticator.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/parser/src/parCalcConst.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/parser/src/parInsert.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/parser/src/parInsertData.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/parser/src/parTranslater.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/parser/src/parUtil.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/parser/test/parSelectTest.cpp
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/planner/src/planOptimizer.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/planner/src/planPhysiCreater.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/planner/test/planJoinTest.cpp
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/planner/test/planSubqueryTest.cpp
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/planner/test/planTestMain.cpp
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/planner/test/planTestUtil.cpp
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/planner/test/planTestUtil.h
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/scalar/inc/sclInt.h
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/scalar/src/scalar.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/stream/src/tstream.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/libs/tdb/CMakeLists.txt
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/util/src/terror.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
source/util/src/tlog.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
tests/script/tsim/tstream/basic1.sim
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
tests/system-test/0-others/udfTest.py
0 → 100644
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
tests/system-test/fulltest.sh
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
tools/shell/src/shellEngine.c
浏览文件 @
e0b3e97d
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录