Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3a26ec4e
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3a26ec4e
编写于
4月 14, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/3.0' into feature/node
上级
c57b1574
313cc0b3
变更
83
展开全部
显示空白变更内容
内联
并排
Showing
83 changed file
with
6438 addition
and
3055 deletion
+6438
-3055
example/src/tmq.c
example/src/tmq.c
+21
-10
include/client/taos.h
include/client/taos.h
+51
-48
include/common/tdatablock.h
include/common/tdatablock.h
+6
-6
include/common/tmsg.h
include/common/tmsg.h
+54
-10
include/common/ttokendef.h
include/common/ttokendef.h
+42
-41
include/libs/nodes/nodes.h
include/libs/nodes/nodes.h
+1
-0
include/libs/scalar/scalar.h
include/libs/scalar/scalar.h
+3
-2
include/os/osFile.h
include/os/osFile.h
+1
-1
include/os/osSystem.h
include/os/osSystem.h
+7
-0
include/util/tdef.h
include/util/tdef.h
+1
-0
source/client/inc/clientInt.h
source/client/inc/clientInt.h
+2
-2
source/client/src/clientMain.c
source/client/src/clientMain.c
+15
-11
source/client/src/tmq.c
source/client/src/tmq.c
+139
-61
source/dnode/mgmt/exe/dmMain.c
source/dnode/mgmt/exe/dmMain.c
+2
-2
source/dnode/mnode/impl/CMakeLists.txt
source/dnode/mnode/impl/CMakeLists.txt
+7
-0
source/dnode/mnode/impl/inc/mndGrant.h
source/dnode/mnode/impl/inc/mndGrant.h
+3
-2
source/dnode/mnode/impl/src/mndGrant.c
source/dnode/mnode/impl/src/mndGrant.c
+6
-4
source/dnode/mnode/impl/src/mndInfoSchema.c
source/dnode/mnode/impl/src/mndInfoSchema.c
+17
-0
source/dnode/mnode/impl/src/mndSubscribe.c
source/dnode/mnode/impl/src/mndSubscribe.c
+30
-14
source/dnode/mnode/impl/src/mndUser.c
source/dnode/mnode/impl/src/mndUser.c
+7
-0
source/dnode/mnode/impl/src/mnode.c
source/dnode/mnode/impl/src/mnode.c
+2
-0
source/dnode/vnode/CMakeLists.txt
source/dnode/vnode/CMakeLists.txt
+2
-1
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+147
-469
source/dnode/vnode/src/inc/meta.h
source/dnode/vnode/src/inc/meta.h
+11
-0
source/dnode/vnode/src/inc/tsdbSma.h
source/dnode/vnode/src/inc/tsdbSma.h
+68
-0
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+7
-1
source/dnode/vnode/src/meta/metaBDBImpl.c
source/dnode/vnode/src/meta/metaBDBImpl.c
+20
-20
source/dnode/vnode/src/meta/metaCfg.c
source/dnode/vnode/src/meta/metaCfg.c
+0
-5
source/dnode/vnode/src/meta/metaQuery.c
source/dnode/vnode/src/meta/metaQuery.c
+3
-1
source/dnode/vnode/src/meta/metaTDBImpl.c
source/dnode/vnode/src/meta/metaTDBImpl.c
+368
-50
source/dnode/vnode/src/meta/metaTbCfg.c
source/dnode/vnode/src/meta/metaTbCfg.c
+0
-1
source/dnode/vnode/src/meta/metaTbTag.c
source/dnode/vnode/src/meta/metaTbTag.c
+3
-1
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+213
-7
source/dnode/vnode/src/tq/tqCommit.c
source/dnode/vnode/src/tq/tqCommit.c
+2
-0
source/dnode/vnode/src/tq/tqMetaStore.c
source/dnode/vnode/src/tq/tqMetaStore.c
+5
-5
source/dnode/vnode/src/tq/tqRead.c
source/dnode/vnode/src/tq/tqRead.c
+40
-3
source/dnode/vnode/src/tsdb/tsdbBDBImpl.c
source/dnode/vnode/src/tsdb/tsdbBDBImpl.c
+2
-4
source/dnode/vnode/src/tsdb/tsdbFS.c
source/dnode/vnode/src/tsdb/tsdbFS.c
+24
-26
source/dnode/vnode/src/tsdb/tsdbOptions.c
source/dnode/vnode/src/tsdb/tsdbOptions.c
+0
-9
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+0
-12
source/dnode/vnode/src/tsdb/tsdbSma.c
source/dnode/vnode/src/tsdb/tsdbSma.c
+208
-53
source/dnode/vnode/src/tsdb/tsdbTDBImpl.c
source/dnode/vnode/src/tsdb/tsdbTDBImpl.c
+137
-0
source/dnode/vnode/src/vnd/vnodeCfg.c
source/dnode/vnode/src/vnd/vnodeCfg.c
+2
-11
source/dnode/vnode/src/vnd/vnodeInt.c
source/dnode/vnode/src/vnd/vnodeInt.c
+0
-1
source/dnode/vnode/src/vnd/vnodeMgr.c
source/dnode/vnode/src/vnd/vnodeMgr.c
+0
-1
source/dnode/vnode/src/vnd/vnodeQuery.c
source/dnode/vnode/src/vnd/vnodeQuery.c
+0
-1
source/dnode/vnode/src/vnd/vnodeWrite.c
source/dnode/vnode/src/vnd/vnodeWrite.c
+12
-12
source/dnode/vnode/test/tsdbSmaTest.cpp
source/dnode/vnode/test/tsdbSmaTest.cpp
+7
-6
source/libs/executor/src/dataDispatcher.c
source/libs/executor/src/dataDispatcher.c
+1
-1
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+3
-1
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+14
-0
source/libs/nodes/src/nodesTraverseFuncs.c
source/libs/nodes/src/nodesTraverseFuncs.c
+26
-24
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+1
-0
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+20
-2
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+5
-0
source/libs/parser/src/parTokenizer.c
source/libs/parser/src/parTokenizer.c
+1
-0
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+3
-1
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+2242
-1827
source/libs/parser/test/mockCatalogService.cpp
source/libs/parser/test/mockCatalogService.cpp
+6
-5
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+0
-1
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+225
-17
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+105
-42
source/libs/planner/test/plannerTest.cpp
source/libs/planner/test/plannerTest.cpp
+11
-5
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+138
-0
source/libs/tdb/src/db/tdbBtree.c
source/libs/tdb/src/db/tdbBtree.c
+13
-12
source/os/src/osFile.c
source/os/src/osFile.c
+1
-1
source/os/src/osSystem.c
source/os/src/osSystem.c
+32
-0
tests/pytest/insert/binary.py
tests/pytest/insert/binary.py
+39
-10
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+12
-0
tests/script/tsim/sma/tsmaCreateInsertData.sim
tests/script/tsim/sma/tsmaCreateInsertData.sim
+48
-0
tests/script/tsim/tmq/insertDataV1.sim
tests/script/tsim/tmq/insertDataV1.sim
+6
-10
tests/script/tsim/tmq/insertDataV4.sim
tests/script/tsim/tmq/insertDataV4.sim
+5
-9
tests/script/tsim/tmq/insertFixedDataV2.sim
tests/script/tsim/tmq/insertFixedDataV2.sim
+51
-0
tests/script/tsim/tmq/insertFixedDataV4.sim
tests/script/tsim/tmq/insertFixedDataV4.sim
+51
-0
tests/script/tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim
tests/script/tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim
+265
-0
tests/script/tsim/tmq/main2Con1Cgrp1TopicFrStb.sim
tests/script/tsim/tmq/main2Con1Cgrp1TopicFrStb.sim
+270
-0
tests/script/tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim
tests/script/tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim
+265
-0
tests/script/tsim/tmq/main2Con1Cgrp2TopicFrStb.sim
tests/script/tsim/tmq/main2Con1Cgrp2TopicFrStb.sim
+270
-0
tests/script/tsim/tmq/mainConsumerInMultiTopic.sim
tests/script/tsim/tmq/mainConsumerInMultiTopic.sim
+30
-22
tests/script/tsim/tmq/mainConsumerInOneTopic.sim
tests/script/tsim/tmq/mainConsumerInOneTopic.sim
+41
-35
tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim
tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim
+240
-0
tests/test/c/tmqDemo.c
tests/test/c/tmqDemo.c
+6
-6
tests/test/c/tmqSim.c
tests/test/c/tmqSim.c
+294
-110
未找到文件。
example/src/tmq.c
浏览文件 @
3a26ec4e
...
@@ -20,7 +20,19 @@
...
@@ -20,7 +20,19 @@
#include "taos.h"
#include "taos.h"
static
int
running
=
1
;
static
int
running
=
1
;
static
void
msg_process
(
tmq_message_t
*
message
)
{
tmqShowMsg
(
message
);
}
static
void
msg_process
(
TAOS_RES
*
msg
)
{
char
buf
[
1024
];
printf
(
"topic: %s
\n
"
,
tmq_get_topic_name
(
msg
));
printf
(
"vg:%d
\n
"
,
tmq_get_vgroup_id
(
msg
));
while
(
1
)
{
TAOS_ROW
row
=
taos_fetch_row
(
msg
);
if
(
row
==
NULL
)
break
;
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
msg
);
int32_t
numOfFields
=
taos_field_count
(
msg
);
taos_print_row
(
buf
,
row
,
fields
,
numOfFields
);
printf
(
"%s
\n
"
,
buf
);
}
}
int32_t
init_env
()
{
int32_t
init_env
()
{
TAOS
*
pConn
=
taos_connect
(
"localhost"
,
"root"
,
"taosdata"
,
NULL
,
0
);
TAOS
*
pConn
=
taos_connect
(
"localhost"
,
"root"
,
"taosdata"
,
NULL
,
0
);
...
@@ -42,8 +54,7 @@ int32_t init_env() {
...
@@ -42,8 +54,7 @@ int32_t init_env() {
}
}
taos_free_result
(
pRes
);
taos_free_result
(
pRes
);
pRes
=
pRes
=
taos_query
(
pConn
,
"create stable if not exists st1 (ts timestamp, c1 int, c2 float, c4 int) tags(t1 int)"
);
taos_query
(
pConn
,
"create stable if not exists st1 (ts timestamp, c1 int, c2 float, c3 binary(10)) tags(t1 int)"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"failed to create super table st1, reason:%s
\n
"
,
taos_errstr
(
pRes
));
printf
(
"failed to create super table st1, reason:%s
\n
"
,
taos_errstr
(
pRes
));
return
-
1
;
return
-
1
;
...
@@ -90,7 +101,7 @@ int32_t create_topic() {
...
@@ -90,7 +101,7 @@ int32_t create_topic() {
/*const char* sql = "select * from tu1";*/
/*const char* sql = "select * from tu1";*/
/*pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql));*/
/*pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql));*/
pRes
=
taos_query
(
pConn
,
"create topic topic_ctb_column as select ts, c1 from ct1"
);
pRes
=
taos_query
(
pConn
,
"create topic topic_ctb_column as select ts, c1
, c2, c4
from ct1"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"failed to create topic topic_ctb_column, reason:%s
\n
"
,
taos_errstr
(
pRes
));
printf
(
"failed to create topic topic_ctb_column, reason:%s
\n
"
,
taos_errstr
(
pRes
));
return
-
1
;
return
-
1
;
...
@@ -166,11 +177,11 @@ void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) {
...
@@ -166,11 +177,11 @@ void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) {
int32_t
cnt
=
0
;
int32_t
cnt
=
0
;
/*clock_t startTime = clock();*/
/*clock_t startTime = clock();*/
while
(
running
)
{
while
(
running
)
{
tmq_message_t
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
500
);
TAOS_RES
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
500
);
if
(
tmqmessage
)
{
if
(
tmqmessage
)
{
cnt
++
;
cnt
++
;
printf
(
"get data
\n
"
);
/*printf("get data\n");*/
msg_process
(
tmqmessage
);
/*msg_process(tmqmessage);*/
tmq_message_destroy
(
tmqmessage
);
tmq_message_destroy
(
tmqmessage
);
/*} else {*/
/*} else {*/
/*break;*/
/*break;*/
...
@@ -198,7 +209,7 @@ void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) {
...
@@ -198,7 +209,7 @@ void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) {
}
}
while
(
running
)
{
while
(
running
)
{
tmq_message_t
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
1000
);
TAOS_RES
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
1000
);
if
(
tmqmessage
)
{
if
(
tmqmessage
)
{
msg_process
(
tmqmessage
);
msg_process
(
tmqmessage
);
tmq_message_destroy
(
tmqmessage
);
tmq_message_destroy
(
tmqmessage
);
...
@@ -226,10 +237,10 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics) {
...
@@ -226,10 +237,10 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics) {
int32_t
skipLogNum
=
0
;
int32_t
skipLogNum
=
0
;
clock_t
startTime
=
clock
();
clock_t
startTime
=
clock
();
while
(
running
)
{
while
(
running
)
{
tmq_message_t
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
500
);
TAOS_RES
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
500
);
if
(
tmqmessage
)
{
if
(
tmqmessage
)
{
batchCnt
++
;
batchCnt
++
;
skipLogNum
+=
tmqGetSkipLogNum
(
tmqmessage
);
/*skipLogNum += tmqGetSkipLogNum(tmqmessage);*/
/*msg_process(tmqmessage);*/
/*msg_process(tmqmessage);*/
tmq_message_destroy
(
tmqmessage
);
tmq_message_destroy
(
tmqmessage
);
}
else
{
}
else
{
...
...
include/client/taos.h
浏览文件 @
3a26ec4e
...
@@ -188,8 +188,8 @@ DLL_EXPORT void taos_stop_query(TAOS_RES *res);
...
@@ -188,8 +188,8 @@ DLL_EXPORT void taos_stop_query(TAOS_RES *res);
DLL_EXPORT
bool
taos_is_null
(
TAOS_RES
*
res
,
int32_t
row
,
int32_t
col
);
DLL_EXPORT
bool
taos_is_null
(
TAOS_RES
*
res
,
int32_t
row
,
int32_t
col
);
DLL_EXPORT
bool
taos_is_update_query
(
TAOS_RES
*
res
);
DLL_EXPORT
bool
taos_is_update_query
(
TAOS_RES
*
res
);
DLL_EXPORT
int
taos_fetch_block
(
TAOS_RES
*
res
,
TAOS_ROW
*
rows
);
DLL_EXPORT
int
taos_fetch_block
(
TAOS_RES
*
res
,
TAOS_ROW
*
rows
);
DLL_EXPORT
int
taos_fetch_block_s
(
TAOS_RES
*
res
,
int
*
numOfRows
,
TAOS_ROW
*
rows
);
DLL_EXPORT
int
taos_fetch_block_s
(
TAOS_RES
*
res
,
int
*
numOfRows
,
TAOS_ROW
*
rows
);
DLL_EXPORT
int
taos_fetch_raw_block
(
TAOS_RES
*
res
,
int
*
numOfRows
,
void
**
pData
);
DLL_EXPORT
int
taos_fetch_raw_block
(
TAOS_RES
*
res
,
int
*
numOfRows
,
void
**
pData
);
DLL_EXPORT
int
*
taos_get_column_data_offset
(
TAOS_RES
*
res
,
int
columnIndex
);
DLL_EXPORT
int
*
taos_get_column_data_offset
(
TAOS_RES
*
res
,
int
columnIndex
);
DLL_EXPORT
int
taos_validate_sql
(
TAOS
*
taos
,
const
char
*
sql
);
DLL_EXPORT
int
taos_validate_sql
(
TAOS
*
taos
,
const
char
*
sql
);
DLL_EXPORT
void
taos_reset_current_db
(
TAOS
*
taos
);
DLL_EXPORT
void
taos_reset_current_db
(
TAOS
*
taos
);
...
@@ -239,7 +239,7 @@ typedef struct tmq_topic_vgroup_list_t tmq_topic_vgroup_list_t;
...
@@ -239,7 +239,7 @@ typedef struct tmq_topic_vgroup_list_t tmq_topic_vgroup_list_t;
typedef
struct
tmq_conf_t
tmq_conf_t
;
typedef
struct
tmq_conf_t
tmq_conf_t
;
typedef
struct
tmq_list_t
tmq_list_t
;
typedef
struct
tmq_list_t
tmq_list_t
;
typedef
struct
tmq_message_t
tmq_message_t
;
//
typedef struct tmq_message_t tmq_message_t;
typedef
void
(
tmq_commit_cb
(
tmq_t
*
,
tmq_resp_err_t
,
tmq_topic_vgroup_list_t
*
,
void
*
param
));
typedef
void
(
tmq_commit_cb
(
tmq_t
*
,
tmq_resp_err_t
,
tmq_topic_vgroup_list_t
*
,
void
*
param
));
...
@@ -259,7 +259,7 @@ DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
...
@@ -259,7 +259,7 @@ DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
DLL_EXPORT
tmq_resp_err_t
tmq_subscribe
(
tmq_t
*
tmq
,
tmq_list_t
*
topic_list
);
DLL_EXPORT
tmq_resp_err_t
tmq_subscribe
(
tmq_t
*
tmq
,
tmq_list_t
*
topic_list
);
DLL_EXPORT
tmq_resp_err_t
tmq_unsubscribe
(
tmq_t
*
tmq
);
DLL_EXPORT
tmq_resp_err_t
tmq_unsubscribe
(
tmq_t
*
tmq
);
DLL_EXPORT
tmq_resp_err_t
tmq_subscription
(
tmq_t
*
tmq
,
tmq_list_t
**
topics
);
DLL_EXPORT
tmq_resp_err_t
tmq_subscription
(
tmq_t
*
tmq
,
tmq_list_t
**
topics
);
DLL_EXPORT
tmq_message_t
*
tmq_consumer_poll
(
tmq_t
*
tmq
,
int64_t
blocking_time
);
DLL_EXPORT
TAOS_RES
*
tmq_consumer_poll
(
tmq_t
*
tmq
,
int64_t
blocking_time
);
DLL_EXPORT
tmq_resp_err_t
tmq_consumer_close
(
tmq_t
*
tmq
);
DLL_EXPORT
tmq_resp_err_t
tmq_consumer_close
(
tmq_t
*
tmq
);
#if 0
#if 0
DLL_EXPORT tmq_resp_err_t tmq_assign(tmq_t* tmq, const tmq_topic_vgroup_list_t* vgroups);
DLL_EXPORT tmq_resp_err_t tmq_assign(tmq_t* tmq, const tmq_topic_vgroup_list_t* vgroups);
...
@@ -268,8 +268,8 @@ DLL_EXPORT tmq_resp_err_t tmq_assignment(tmq_t* tmq, tmq_topic_vgroup_list_t** v
...
@@ -268,8 +268,8 @@ DLL_EXPORT tmq_resp_err_t tmq_assignment(tmq_t* tmq, tmq_topic_vgroup_list_t** v
DLL_EXPORT
tmq_resp_err_t
tmq_commit
(
tmq_t
*
tmq
,
const
tmq_topic_vgroup_list_t
*
offsets
,
int32_t
async
);
DLL_EXPORT
tmq_resp_err_t
tmq_commit
(
tmq_t
*
tmq
,
const
tmq_topic_vgroup_list_t
*
offsets
,
int32_t
async
);
#if 0
#if 0
DLL_EXPORT tmq_resp_err_t tmq_commit_message(tmq_t* tmq, const tmq_message_t* tmqmessage, int32_t async);
DLL_EXPORT tmq_resp_err_t tmq_commit_message(tmq_t* tmq, const tmq_message_t* tmqmessage, int32_t async);
#endif
DLL_EXPORT tmq_resp_err_t tmq_seek(tmq_t *tmq, const tmq_topic_vgroup_t *offset);
DLL_EXPORT tmq_resp_err_t tmq_seek(tmq_t *tmq, const tmq_topic_vgroup_t *offset);
#endif
/* ----------------------TMQ CONFIGURATION INTERFACE---------------------- */
/* ----------------------TMQ CONFIGURATION INTERFACE---------------------- */
enum
tmq_conf_res_t
{
enum
tmq_conf_res_t
{
...
@@ -285,21 +285,24 @@ DLL_EXPORT tmq_conf_res_t tmq_conf_set(tmq_conf_t *conf, const char *key, const
...
@@ -285,21 +285,24 @@ DLL_EXPORT tmq_conf_res_t tmq_conf_set(tmq_conf_t *conf, const char *key, const
DLL_EXPORT
void
tmq_conf_destroy
(
tmq_conf_t
*
conf
);
DLL_EXPORT
void
tmq_conf_destroy
(
tmq_conf_t
*
conf
);
DLL_EXPORT
void
tmq_conf_set_offset_commit_cb
(
tmq_conf_t
*
conf
,
tmq_commit_cb
*
cb
);
DLL_EXPORT
void
tmq_conf_set_offset_commit_cb
(
tmq_conf_t
*
conf
,
tmq_commit_cb
*
cb
);
#if 0
// temporary used function for demo only
// temporary used function for demo only
void tmqShowMsg(tmq_message_t *tmq_message);
void tmqShowMsg(tmq_message_t *tmq_message);
int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message);
int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message);
#endif
/* -------------------------TMQ MSG HANDLE INTERFACE---------------------- */
/* -------------------------TMQ MSG HANDLE INTERFACE---------------------- */
DLL_EXPORT
char
*
tmq_get_topic_name
(
TAOS_RES
*
res
);
DLL_EXPORT
int32_t
tmq_get_vgroup_id
(
TAOS_RES
*
res
);
#if 0
DLL_EXPORT TAOS_ROW tmq_get_row(tmq_message_t *message);
DLL_EXPORT TAOS_ROW tmq_get_row(tmq_message_t *message);
DLL_EXPORT
char
*
tmq_get_topic_name
(
tmq_message_t
*
message
);
DLL_EXPORT
int32_t
tmq_get_vgroup_id
(
tmq_message_t
*
message
);
DLL_EXPORT int64_t tmq_get_request_offset(tmq_message_t *message);
DLL_EXPORT int64_t tmq_get_request_offset(tmq_message_t *message);
DLL_EXPORT int64_t tmq_get_response_offset(tmq_message_t *message);
DLL_EXPORT int64_t tmq_get_response_offset(tmq_message_t *message);
DLL_EXPORT TAOS_FIELD *tmq_get_fields(tmq_t *tmq, const char *topic);
DLL_EXPORT TAOS_FIELD *tmq_get_fields(tmq_t *tmq, const char *topic);
DLL_EXPORT int32_t tmq_field_count(tmq_t *tmq, const char *topic);
DLL_EXPORT int32_t tmq_field_count(tmq_t *tmq, const char *topic);
DLL_EXPORT
void
tmq_message_destroy
(
tmq_message_t
*
tmq_message
);
#endif
DLL_EXPORT
void
tmq_message_destroy
(
TAOS_RES
*
res
);
/* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */
/* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */
#if 0
#if 0
DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen);
DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen);
...
...
include/common/tdatablock.h
浏览文件 @
3a26ec4e
...
@@ -211,8 +211,8 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock);
...
@@ -211,8 +211,8 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock);
void
blockDebugShowData
(
const
SArray
*
dataBlocks
);
void
blockDebugShowData
(
const
SArray
*
dataBlocks
);
static
FORCE_INLINE
int32_t
block
Estimate
EncodeSize
(
const
SSDataBlock
*
pBlock
)
{
static
FORCE_INLINE
int32_t
block
Get
EncodeSize
(
const
SSDataBlock
*
pBlock
)
{
return
blockDataGetSerialMetaSize
(
pBlock
)
+
(
int32_t
)
ceil
(
blockDataGetSerialRowSize
(
pBlock
)
*
pBlock
->
info
.
rows
);
return
blockDataGetSerialMetaSize
(
pBlock
)
+
blockDataGetSize
(
pBlock
);
}
}
static
FORCE_INLINE
int32_t
blockCompressColData
(
SColumnInfoData
*
pColRes
,
int32_t
numOfRows
,
char
*
data
,
static
FORCE_INLINE
int32_t
blockCompressColData
(
SColumnInfoData
*
pColRes
,
int32_t
numOfRows
,
char
*
data
,
...
...
include/common/tmsg.h
浏览文件 @
3a26ec4e
...
@@ -2369,8 +2369,7 @@ typedef struct {
...
@@ -2369,8 +2369,7 @@ typedef struct {
char
topic
[
TSDB_TOPIC_FNAME_LEN
];
char
topic
[
TSDB_TOPIC_FNAME_LEN
];
int8_t
isSchemaAdaptive
;
int8_t
isSchemaAdaptive
;
SArray
*
vgs
;
// SArray<SMqSubVgEp>
SArray
*
vgs
;
// SArray<SMqSubVgEp>
int32_t
numOfFields
;
SSchemaWrapper
schema
;
TAOS_FIELD
*
fields
;
}
SMqSubTopicEp
;
}
SMqSubTopicEp
;
typedef
struct
{
typedef
struct
{
...
@@ -2385,6 +2384,53 @@ typedef struct {
...
@@ -2385,6 +2384,53 @@ typedef struct {
SArray
*
pBlockData
;
// SArray<SSDataBlock>
SArray
*
pBlockData
;
// SArray<SSDataBlock>
}
SMqPollRsp
;
}
SMqPollRsp
;
typedef
struct
{
SMqRspHead
head
;
int64_t
reqOffset
;
int64_t
rspOffset
;
int32_t
skipLogNum
;
int32_t
dataLen
;
SArray
*
blockPos
;
// beginning pos for each SRetrieveTableRsp
void
*
blockData
;
// serialized batched SRetrieveTableRsp
}
SMqPollRspV2
;
static
FORCE_INLINE
int32_t
tEncodeSMqPollRspV2
(
void
**
buf
,
const
SMqPollRspV2
*
pRsp
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pRsp
->
reqOffset
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pRsp
->
rspOffset
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pRsp
->
skipLogNum
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pRsp
->
dataLen
);
if
(
pRsp
->
dataLen
!=
0
)
{
int32_t
sz
=
taosArrayGetSize
(
pRsp
->
blockPos
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
int32_t
blockPos
=
*
(
int32_t
*
)
taosArrayGet
(
pRsp
->
blockPos
,
i
);
tlen
+=
taosEncodeFixedI32
(
buf
,
blockPos
);
}
tlen
+=
taosEncodeBinary
(
buf
,
pRsp
->
blockData
,
pRsp
->
dataLen
);
}
return
tlen
;
}
static
FORCE_INLINE
void
*
tDecodeSMqPollRspV2
(
const
void
*
buf
,
SMqPollRspV2
*
pRsp
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
pRsp
->
reqOffset
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pRsp
->
rspOffset
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pRsp
->
skipLogNum
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pRsp
->
dataLen
);
if
(
pRsp
->
dataLen
!=
0
)
{
int32_t
sz
;
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pRsp
->
blockPos
=
taosArrayInit
(
sz
,
sizeof
(
int32_t
));
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
int32_t
blockPos
;
buf
=
taosDecodeFixedI32
(
buf
,
&
blockPos
);
taosArrayPush
(
pRsp
->
blockPos
,
&
blockPos
);
}
buf
=
taosDecodeBinary
(
buf
,
&
pRsp
->
blockData
,
pRsp
->
dataLen
);
}
return
(
void
*
)
buf
;
}
typedef
struct
{
typedef
struct
{
SMqRspHead
head
;
SMqRspHead
head
;
char
cgroup
[
TSDB_CGROUP_LEN
];
char
cgroup
[
TSDB_CGROUP_LEN
];
...
@@ -2422,8 +2468,7 @@ static FORCE_INLINE int32_t tEncodeSMqSubTopicEp(void** buf, const SMqSubTopicEp
...
@@ -2422,8 +2468,7 @@ static FORCE_INLINE int32_t tEncodeSMqSubTopicEp(void** buf, const SMqSubTopicEp
SMqSubVgEp
*
pVgEp
=
(
SMqSubVgEp
*
)
taosArrayGet
(
pTopicEp
->
vgs
,
i
);
SMqSubVgEp
*
pVgEp
=
(
SMqSubVgEp
*
)
taosArrayGet
(
pTopicEp
->
vgs
,
i
);
tlen
+=
tEncodeSMqSubVgEp
(
buf
,
pVgEp
);
tlen
+=
tEncodeSMqSubVgEp
(
buf
,
pVgEp
);
}
}
tlen
+=
taosEncodeFixedI32
(
buf
,
pTopicEp
->
numOfFields
);
tlen
+=
taosEncodeSSchemaWrapper
(
buf
,
&
pTopicEp
->
schema
);
// tlen += taosEncodeBinary(buf, pTopicEp->fields, pTopicEp->numOfFields * sizeof(TAOS_FIELD));
return
tlen
;
return
tlen
;
}
}
...
@@ -2441,8 +2486,7 @@ static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicE
...
@@ -2441,8 +2486,7 @@ static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicE
buf
=
tDecodeSMqSubVgEp
(
buf
,
&
vgEp
);
buf
=
tDecodeSMqSubVgEp
(
buf
,
&
vgEp
);
taosArrayPush
(
pTopicEp
->
vgs
,
&
vgEp
);
taosArrayPush
(
pTopicEp
->
vgs
,
&
vgEp
);
}
}
buf
=
taosDecodeFixedI32
(
buf
,
&
pTopicEp
->
numOfFields
);
buf
=
taosDecodeSSchemaWrapper
(
buf
,
&
pTopicEp
->
schema
);
// buf = taosDecodeBinary(buf, (void**)&pTopicEp->fields, pTopicEp->numOfFields * sizeof(TAOS_FIELD));
return
buf
;
return
buf
;
}
}
...
...
include/common/ttokendef.h
浏览文件 @
3a26ec4e
...
@@ -182,47 +182,48 @@
...
@@ -182,47 +182,48 @@
#define TK_FIRST 164
#define TK_FIRST 164
#define TK_LAST 165
#define TK_LAST 165
#define TK_NOW 166
#define TK_NOW 166
#define TK_ROWTS 167
#define TK_TODAY 167
#define TK_TBNAME 168
#define TK_ROWTS 168
#define TK_QSTARTTS 169
#define TK_TBNAME 169
#define TK_QENDTS 170
#define TK_QSTARTTS 170
#define TK_WSTARTTS 171
#define TK_QENDTS 171
#define TK_WENDTS 172
#define TK_WSTARTTS 172
#define TK_WDURATION 173
#define TK_WENDTS 173
#define TK_BETWEEN 174
#define TK_WDURATION 174
#define TK_IS 175
#define TK_BETWEEN 175
#define TK_NK_LT 176
#define TK_IS 176
#define TK_NK_GT 177
#define TK_NK_LT 177
#define TK_NK_LE 178
#define TK_NK_GT 178
#define TK_NK_GE 179
#define TK_NK_LE 179
#define TK_NK_NE 180
#define TK_NK_GE 180
#define TK_MATCH 181
#define TK_NK_NE 181
#define TK_NMATCH 182
#define TK_MATCH 182
#define TK_JOIN 183
#define TK_NMATCH 183
#define TK_INNER 184
#define TK_JOIN 184
#define TK_SELECT 185
#define TK_INNER 185
#define TK_DISTINCT 186
#define TK_SELECT 186
#define TK_WHERE 187
#define TK_DISTINCT 187
#define TK_PARTITION 188
#define TK_WHERE 188
#define TK_BY 189
#define TK_PARTITION 189
#define TK_SESSION 190
#define TK_BY 190
#define TK_STATE_WINDOW 191
#define TK_SESSION 191
#define TK_SLIDING 192
#define TK_STATE_WINDOW 192
#define TK_FILL 193
#define TK_SLIDING 193
#define TK_VALUE 194
#define TK_FILL 194
#define TK_NONE 195
#define TK_VALUE 195
#define TK_PREV 196
#define TK_NONE 196
#define TK_LINEAR 197
#define TK_PREV 197
#define TK_NEXT 198
#define TK_LINEAR 198
#define TK_GROUP 199
#define TK_NEXT 199
#define TK_HAVING 200
#define TK_GROUP 200
#define TK_ORDER 201
#define TK_HAVING 201
#define TK_SLIMIT 202
#define TK_ORDER 202
#define TK_SOFFSET 203
#define TK_SLIMIT 203
#define TK_LIMIT 204
#define TK_SOFFSET 204
#define TK_OFFSET 205
#define TK_LIMIT 205
#define TK_ASC 206
#define TK_OFFSET 206
#define TK_NULLS 207
#define TK_ASC 207
#define TK_NULLS 208
#define TK_NK_SPACE 300
#define TK_NK_SPACE 300
#define TK_NK_COMMENT 301
#define TK_NK_COMMENT 301
...
...
include/libs/nodes/nodes.h
浏览文件 @
3a26ec4e
...
@@ -231,6 +231,7 @@ typedef enum EDealRes {
...
@@ -231,6 +231,7 @@ typedef enum EDealRes {
DEAL_RES_CONTINUE
=
1
,
DEAL_RES_CONTINUE
=
1
,
DEAL_RES_IGNORE_CHILD
,
DEAL_RES_IGNORE_CHILD
,
DEAL_RES_ERROR
,
DEAL_RES_ERROR
,
DEAL_RES_END
}
EDealRes
;
}
EDealRes
;
typedef
EDealRes
(
*
FNodeWalker
)(
SNode
*
pNode
,
void
*
pContext
);
typedef
EDealRes
(
*
FNodeWalker
)(
SNode
*
pNode
,
void
*
pContext
);
...
...
include/libs/scalar/scalar.h
浏览文件 @
3a26ec4e
...
@@ -77,6 +77,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
...
@@ -77,6 +77,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
int32_t
toISO8601Function
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
toISO8601Function
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
toUnixtimestampFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
toUnixtimestampFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
timeTruncateFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
timeTruncateFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
timeDiffFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
bool
getTimePseudoFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
getTimePseudoFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
...
...
include/os/osFile.h
浏览文件 @
3a26ec4e
...
@@ -79,7 +79,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
...
@@ -79,7 +79,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
int64_t
taosWriteFile
(
TdFilePtr
pFile
,
const
void
*
buf
,
int64_t
count
);
int64_t
taosWriteFile
(
TdFilePtr
pFile
,
const
void
*
buf
,
int64_t
count
);
void
taosFprintfFile
(
TdFilePtr
pFile
,
const
char
*
format
,
...);
void
taosFprintfFile
(
TdFilePtr
pFile
,
const
char
*
format
,
...);
int64_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict
__
ptrBuf
);
int64_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict
ptrBuf
);
int32_t
taosEOFFile
(
TdFilePtr
pFile
);
int32_t
taosEOFFile
(
TdFilePtr
pFile
);
...
...
include/os/osSystem.h
浏览文件 @
3a26ec4e
...
@@ -29,6 +29,13 @@ extern "C" {
...
@@ -29,6 +29,13 @@ extern "C" {
#define tcgetattr TCGETATTR_FUNC_TAOS_FORBID
#define tcgetattr TCGETATTR_FUNC_TAOS_FORBID
#endif
#endif
typedef
struct
TdCmd
*
TdCmdPtr
;
TdCmdPtr
taosOpenCmd
(
const
char
*
cmd
);
int64_t
taosGetLineCmd
(
TdCmdPtr
pCmd
,
char
**
__restrict
ptrBuf
);
int32_t
taosEOFCmd
(
TdCmdPtr
pCmd
);
int64_t
taosCloseCmd
(
TdCmdPtr
*
ppCmd
);
void
*
taosLoadDll
(
const
char
*
filename
);
void
*
taosLoadDll
(
const
char
*
filename
);
void
*
taosLoadSym
(
void
*
handle
,
char
*
name
);
void
*
taosLoadSym
(
void
*
handle
,
char
*
name
);
void
taosCloseDll
(
void
*
handle
);
void
taosCloseDll
(
void
*
handle
);
...
...
include/util/tdef.h
浏览文件 @
3a26ec4e
...
@@ -117,6 +117,7 @@ extern const int32_t TYPE_BYTES[15];
...
@@ -117,6 +117,7 @@ extern const int32_t TYPE_BYTES[15];
#define TSDB_INS_TABLE_VGROUPS "vgroups"
#define TSDB_INS_TABLE_VGROUPS "vgroups"
#define TSDB_INS_TABLE_BNODES "bnodes"
#define TSDB_INS_TABLE_BNODES "bnodes"
#define TSDB_INS_TABLE_SNODES "snodes"
#define TSDB_INS_TABLE_SNODES "snodes"
#define TSDB_INS_TABLE_LICENCES "grants"
#define TSDB_INDEX_TYPE_SMA "SMA"
#define TSDB_INDEX_TYPE_SMA "SMA"
#define TSDB_INDEX_TYPE_FULLTEXT "FULLTEXT"
#define TSDB_INDEX_TYPE_FULLTEXT "FULLTEXT"
...
...
source/client/inc/clientInt.h
浏览文件 @
3a26ec4e
...
@@ -194,12 +194,12 @@ enum {
...
@@ -194,12 +194,12 @@ enum {
#define TD_RES_QUERY(res) (*(int8_t*)res == RES_TYPE__QUERY)
#define TD_RES_QUERY(res) (*(int8_t*)res == RES_TYPE__QUERY)
#define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ)
#define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ)
typedef
struct
SMqRspObj
{
typedef
struct
{
int8_t
resType
;
int8_t
resType
;
char
*
topic
;
char
*
topic
;
void
*
vg
;
SArray
*
res
;
// SArray<SReqResultInfo>
SArray
*
res
;
// SArray<SReqResultInfo>
int32_t
resIter
;
int32_t
resIter
;
int32_t
vgId
;
}
SMqRspObj
;
}
SMqRspObj
;
typedef
struct
SRequestObj
{
typedef
struct
SRequestObj
{
...
...
source/client/src/clientMain.c
浏览文件 @
3a26ec4e
...
@@ -172,19 +172,23 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
...
@@ -172,19 +172,23 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
}
else
if
(
TD_RES_TMQ
(
res
))
{
}
else
if
(
TD_RES_TMQ
(
res
))
{
SMqRspObj
*
msg
=
((
SMqRspObj
*
)
res
);
SMqRspObj
*
msg
=
((
SMqRspObj
*
)
res
);
if
(
msg
->
resIter
==
-
1
)
msg
->
resIter
++
;
SReqResultInfo
*
pResultInfo
=
taosArrayGet
(
msg
->
res
,
msg
->
resIter
);
SReqResultInfo
*
pResultInfo
=
taosArrayGet
(
msg
->
res
,
msg
->
resIter
);
if
(
pResultInfo
->
current
<
pResultInfo
->
numOfRows
)
{
doSetOneRowPtr
(
pResultInfo
);
doSetOneRowPtr
(
pResultInfo
);
pResultInfo
->
current
+=
1
;
pResultInfo
->
current
+=
1
;
return
pResultInfo
->
row
;
if
(
pResultInfo
->
row
==
NULL
)
{
}
else
{
msg
->
resIter
++
;
msg
->
resIter
++
;
if
(
msg
->
resIter
<
taosArrayGetSize
(
msg
->
res
))
{
pResultInfo
=
taosArrayGet
(
msg
->
res
,
msg
->
resIter
);
pResultInfo
=
taosArrayGet
(
msg
->
res
,
msg
->
resIter
);
doSetOneRowPtr
(
pResultInfo
);
doSetOneRowPtr
(
pResultInfo
);
pResultInfo
->
current
+=
1
;
pResultInfo
->
current
+=
1
;
}
return
pResultInfo
->
row
;
return
pResultInfo
->
row
;
}
else
{
return
NULL
;
}
}
}
else
{
}
else
{
// assert to avoid uninitialization error
// assert to avoid uninitialization error
...
@@ -465,7 +469,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
...
@@ -465,7 +469,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
return
0
;
return
0
;
}
}
doFetchRow
(
pRequest
,
false
,
fals
e
);
doFetchRow
(
pRequest
,
false
,
tru
e
);
SReqResultInfo
*
pResultInfo
=
&
pRequest
->
body
.
resInfo
;
SReqResultInfo
*
pResultInfo
=
&
pRequest
->
body
.
resInfo
;
...
...
source/client/src/tmq.c
浏览文件 @
3a26ec4e
...
@@ -27,11 +27,22 @@
...
@@ -27,11 +27,22 @@
struct
tmq_message_t
{
struct
tmq_message_t
{
SMqPollRsp
msg
;
SMqPollRsp
msg
;
char
*
topic
;
char
*
topic
;
void
*
vg
;
SArray
*
res
;
// SArray<SReqResultInfo>
SArray
*
res
;
// SArray<SReqResultInfo>
int32_t
vgId
;
int32_t
resIter
;
int32_t
resIter
;
};
};
typedef
struct
{
int8_t
tmqRspType
;
int32_t
epoch
;
}
SMqRspWrapper
;
typedef
struct
{
int8_t
tmqRspType
;
int32_t
epoch
;
SMqCMGetSubEpRsp
msg
;
}
SMqAskEpRspWrapper
;
struct
tmq_list_t
{
struct
tmq_list_t
{
SArray
container
;
SArray
container
;
};
};
...
@@ -115,9 +126,17 @@ typedef struct {
...
@@ -115,9 +126,17 @@ typedef struct {
SArray
*
vgs
;
// SArray<SMqClientVg>
SArray
*
vgs
;
// SArray<SMqClientVg>
int8_t
isSchemaAdaptive
;
int8_t
isSchemaAdaptive
;
int32_t
numOfFields
;
int32_t
numOfFields
;
TAOS_FIELD
*
fields
;
SSchemaWrapper
schema
;
}
SMqClientTopic
;
}
SMqClientTopic
;
typedef
struct
{
int8_t
tmqRspType
;
int32_t
epoch
;
SMqClientVg
*
vgHandle
;
SMqClientTopic
*
topicHandle
;
SMqPollRspV2
msg
;
}
SMqPollRspWrapper
;
typedef
struct
{
typedef
struct
{
tmq_t
*
tmq
;
tmq_t
*
tmq
;
tsem_t
rspSem
;
tsem_t
rspSem
;
...
@@ -133,10 +152,10 @@ typedef struct {
...
@@ -133,10 +152,10 @@ typedef struct {
typedef
struct
{
typedef
struct
{
tmq_t
*
tmq
;
tmq_t
*
tmq
;
SMqClientVg
*
pVg
;
SMqClientVg
*
pVg
;
SMqClientTopic
*
pTopic
;
int32_t
epoch
;
int32_t
epoch
;
int32_t
vgId
;
int32_t
vgId
;
tsem_t
rspSem
;
tsem_t
rspSem
;
tmq_message_t
**
msg
;
int32_t
sync
;
int32_t
sync
;
}
SMqPollCbParam
;
}
SMqPollCbParam
;
...
@@ -244,7 +263,7 @@ static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) {
...
@@ -244,7 +263,7 @@ static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) {
}
}
void
tmqClearUnhandleMsg
(
tmq_t
*
tmq
)
{
void
tmqClearUnhandleMsg
(
tmq_t
*
tmq
)
{
tmq_message_t
*
msg
=
NULL
;
SMqRspWrapper
*
msg
=
NULL
;
while
(
1
)
{
while
(
1
)
{
taosGetQitem
(
tmq
->
qall
,
(
void
**
)
&
msg
);
taosGetQitem
(
tmq
->
qall
,
(
void
**
)
&
msg
);
if
(
msg
)
if
(
msg
)
...
@@ -777,7 +796,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
...
@@ -777,7 +796,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
return
buf
;
return
buf
;
}
}
#if 0
int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) {
int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) {
if (tmq_message == NULL) return 0;
if (tmq_message == NULL) return 0;
SMqPollRsp* pRsp = &tmq_message->msg;
SMqPollRsp* pRsp = &tmq_message->msg;
...
@@ -827,11 +846,13 @@ void tmqShowMsg(tmq_message_t* tmq_message) {
...
@@ -827,11 +846,13 @@ void tmqShowMsg(tmq_message_t* tmq_message) {
}
}
}
}
}
}
#endif
int32_t
tmqPollCb
(
void
*
param
,
const
SDataBuf
*
pMsg
,
int32_t
code
)
{
int32_t
tmqPollCb
(
void
*
param
,
const
SDataBuf
*
pMsg
,
int32_t
code
)
{
/*printf("recv poll\n");*/
/*printf("recv poll\n");*/
SMqPollCbParam
*
pParam
=
(
SMqPollCbParam
*
)
param
;
SMqPollCbParam
*
pParam
=
(
SMqPollCbParam
*
)
param
;
SMqClientVg
*
pVg
=
pParam
->
pVg
;
SMqClientVg
*
pVg
=
pParam
->
pVg
;
SMqClientTopic
*
pTopic
=
pParam
->
pTopic
;
tmq_t
*
tmq
=
pParam
->
tmq
;
tmq_t
*
tmq
=
pParam
->
tmq
;
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
tscWarn
(
"msg discard from vg %d, epoch %d, code:%x"
,
pParam
->
vgId
,
pParam
->
epoch
,
code
);
tscWarn
(
"msg discard from vg %d, epoch %d, code:%x"
,
pParam
->
vgId
,
pParam
->
epoch
,
code
);
...
@@ -874,18 +895,22 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
...
@@ -874,18 +895,22 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
#endif
#endif
/*SMqConsumeRsp* pRsp = taosMemoryCalloc(1, sizeof(SMqConsumeRsp));*/
/*SMqConsumeRsp* pRsp = taosMemoryCalloc(1, sizeof(SMqConsumeRsp));*/
tmq_message_t
*
pRsp
=
taosAllocateQitem
(
sizeof
(
tmq_message_t
));
/*tmq_message_t* pRsp = taosAllocateQitem(sizeof(tmq_message_t));*/
if
(
pRsp
==
NULL
)
{
SMqPollRspWrapper
*
pRspWrapper
=
taosAllocateQitem
(
sizeof
(
SMqPollRspWrapper
));
if
(
pRspWrapper
==
NULL
)
{
tscWarn
(
"msg discard from vg %d, epoch %d since out of memory"
,
pParam
->
vgId
,
pParam
->
epoch
);
tscWarn
(
"msg discard from vg %d, epoch %d since out of memory"
,
pParam
->
vgId
,
pParam
->
epoch
);
goto
CREATE_MSG_FAIL
;
goto
CREATE_MSG_FAIL
;
}
}
memcpy
(
pRsp
,
pMsg
->
pData
,
sizeof
(
SMqRspHead
));
pRspWrapper
->
tmqRspType
=
TMQ_MSG_TYPE__POLL_RSP
;
tDecodeSMqPollRsp
(
POINTER_SHIFT
(
pMsg
->
pData
,
sizeof
(
SMqRspHead
)),
&
pRsp
->
msg
);
pRspWrapper
->
vgHandle
=
pVg
;
/*pRsp->iter.curBlock = 0;*/
pRspWrapper
->
topicHandle
=
pTopic
;
/*pRsp->iter.curRow = 0;*/
/*memcpy(pRsp, pMsg->pData, sizeof(SMqRspHead));*/
memcpy
(
&
pRspWrapper
->
msg
,
pMsg
->
pData
,
sizeof
(
SMqRspHead
));
tDecodeSMqPollRspV2
(
POINTER_SHIFT
(
pMsg
->
pData
,
sizeof
(
SMqRspHead
)),
&
pRspWrapper
->
msg
);
// TODO: alloc mem
// TODO: alloc mem
/*pRsp->*/
/*pRsp->*/
/*printf("rsp commit off:%ld rsp off:%ld has data:%d\n", pRsp->committedOffset, pRsp->rspOffset, pRsp->numOfTopics);*/
/*printf("rsp commit off:%ld rsp off:%ld has data:%d\n", pRsp->committedOffset, pRsp->rspOffset, pRsp->numOfTopics);*/
#if 0
#if 0
if (pRsp->msg.numOfTopics == 0) {
if (pRsp->msg.numOfTopics == 0) {
/*printf("no data\n");*/
/*printf("no data\n");*/
...
@@ -894,11 +919,10 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
...
@@ -894,11 +919,10 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
}
}
#endif
#endif
tscDebug
(
"consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld"
,
tmq
->
consumerId
,
p
Param
->
p
Vg
->
vgId
,
tscDebug
(
"consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld"
,
tmq
->
consumerId
,
pVg
->
vgId
,
pRsp
->
msg
.
reqOffset
,
pRsp
->
msg
.
rspOffset
);
pRsp
Wrapper
->
msg
.
reqOffset
,
pRspWrapper
->
msg
.
rspOffset
);
pRsp
->
vg
=
pParam
->
pVg
;
taosWriteQitem
(
tmq
->
mqueue
,
pRspWrapper
);
taosWriteQitem
(
tmq
->
mqueue
,
pRsp
);
atomic_add_fetch_32
(
&
tmq
->
readyRequest
,
1
);
atomic_add_fetch_32
(
&
tmq
->
readyRequest
,
1
);
/*tsem_post(&tmq->rspSem);*/
/*tsem_post(&tmq->rspSem);*/
return
0
;
return
0
;
...
@@ -932,6 +956,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
...
@@ -932,6 +956,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
for
(
int32_t
i
=
0
;
i
<
topicNumGet
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
topicNumGet
;
i
++
)
{
SMqClientTopic
topic
=
{
0
};
SMqClientTopic
topic
=
{
0
};
SMqSubTopicEp
*
pTopicEp
=
taosArrayGet
(
pRsp
->
topics
,
i
);
SMqSubTopicEp
*
pTopicEp
=
taosArrayGet
(
pRsp
->
topics
,
i
);
topic
.
schema
=
pTopicEp
->
schema
;
taosHashClear
(
pHash
);
taosHashClear
(
pHash
);
topic
.
topicName
=
strdup
(
pTopicEp
->
topic
);
topic
.
topicName
=
strdup
(
pTopicEp
->
topic
);
...
@@ -1015,16 +1040,19 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
...
@@ -1015,16 +1040,19 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
}
}
tDeleteSMqCMGetSubEpRsp
(
&
rsp
);
tDeleteSMqCMGetSubEpRsp
(
&
rsp
);
}
else
{
}
else
{
SMqCMGetSubEpRsp
*
pRsp
=
taosAllocateQitem
(
sizeof
(
SMqCMGetSubEpRsp
));
/*SMqCMGetSubEpRsp* pRsp = taosAllocateQitem(sizeof(SMqCMGetSubEpRsp));*/
if
(
pRsp
==
NULL
)
{
SMqAskEpRspWrapper
*
pWrapper
=
taosAllocateQitem
(
sizeof
(
SMqAskEpRspWrapper
));
if
(
pWrapper
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
code
=
-
1
;
code
=
-
1
;
goto
END
;
goto
END
;
}
}
memcpy
(
pRsp
,
pMsg
->
pData
,
sizeof
(
SMqRspHead
));
pWrapper
->
tmqRspType
=
TMQ_MSG_TYPE__EP_RSP
;
tDecodeSMqCMGetSubEpRsp
(
POINTER_SHIFT
(
pMsg
->
pData
,
sizeof
(
SMqRspHead
)),
pRsp
);
pWrapper
->
epoch
=
head
->
epoch
;
memcpy
(
&
pWrapper
->
msg
,
pMsg
->
pData
,
sizeof
(
SMqRspHead
));
tDecodeSMqCMGetSubEpRsp
(
POINTER_SHIFT
(
pMsg
->
pData
,
sizeof
(
SMqRspHead
)),
&
pWrapper
->
msg
);
taosWriteQitem
(
tmq
->
mqueue
,
p
Rsp
);
taosWriteQitem
(
tmq
->
mqueue
,
p
Wrapper
);
/*tsem_post(&tmq->rspSem);*/
/*tsem_post(&tmq->rspSem);*/
}
}
...
@@ -1152,6 +1180,28 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTo
...
@@ -1152,6 +1180,28 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTo
return
pReq
;
return
pReq
;
}
}
SMqRspObj
*
tmqBuildRspFromWrapper
(
SMqPollRspWrapper
*
pWrapper
)
{
SMqRspObj
*
pRspObj
=
taosMemoryCalloc
(
1
,
sizeof
(
SMqRspObj
));
pRspObj
->
resType
=
RES_TYPE__TMQ
;
pRspObj
->
topic
=
strdup
(
pWrapper
->
topicHandle
->
topicName
);
pRspObj
->
resIter
=
-
1
;
pRspObj
->
vgId
=
pWrapper
->
vgHandle
->
vgId
;
SMqPollRspV2
*
pRsp
=
&
pWrapper
->
msg
;
int32_t
blockNum
=
taosArrayGetSize
(
pRsp
->
blockPos
);
pRspObj
->
res
=
taosArrayInit
(
blockNum
,
sizeof
(
SReqResultInfo
));
for
(
int32_t
i
=
0
;
i
<
blockNum
;
i
++
)
{
int32_t
pos
=
*
(
int32_t
*
)
taosArrayGet
(
pRsp
->
blockPos
,
i
);
SRetrieveTableRsp
*
pRetrieve
=
POINTER_SHIFT
(
pRsp
->
blockData
,
pos
);
SReqResultInfo
resInfo
=
{
0
};
resInfo
.
totalRows
=
0
;
resInfo
.
precision
=
TSDB_TIME_PRECISION_MILLI
;
setResSchemaInfo
(
&
resInfo
,
pWrapper
->
topicHandle
->
schema
.
pSchema
,
pWrapper
->
topicHandle
->
schema
.
nCols
);
setQueryResultFromRsp
(
&
resInfo
,
pRetrieve
,
true
);
taosArrayPush
(
pRspObj
->
res
,
&
resInfo
);
}
return
pRspObj
;
}
#if 0
#if 0
tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) {
tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) {
tmq_message_t* msg = NULL;
tmq_message_t* msg = NULL;
...
@@ -1258,6 +1308,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
...
@@ -1258,6 +1308,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
}
}
pParam
->
tmq
=
tmq
;
pParam
->
tmq
=
tmq
;
pParam
->
pVg
=
pVg
;
pParam
->
pVg
=
pVg
;
pParam
->
pTopic
=
pTopic
;
pParam
->
vgId
=
pVg
->
vgId
;
pParam
->
vgId
=
pVg
->
vgId
;
pParam
->
epoch
=
tmq
->
epoch
;
pParam
->
epoch
=
tmq
->
epoch
;
pParam
->
sync
=
0
;
pParam
->
sync
=
0
;
...
@@ -1296,13 +1347,13 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
...
@@ -1296,13 +1347,13 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
return
0
;
return
0
;
}
}
// return
int32_t
tmqHandleNoPollRsp
(
tmq_t
*
tmq
,
SMqRspWrapper
*
rspWrapper
,
bool
*
pReset
)
{
int32_t
tmqHandleNoPollRsp
(
tmq_t
*
tmq
,
SMqRspHead
*
rspHead
,
bool
*
pReset
)
{
if
(
rspWrapper
->
tmqRspType
==
TMQ_MSG_TYPE__EP_RSP
)
{
if
(
rspHead
->
mqMsgType
==
TMQ_MSG_TYPE__EP_RSP
)
{
/*printf("ep %d %d\n", rspMsg->head.epoch, tmq->epoch);*/
/*printf("ep %d %d\n", rspMsg->head.epoch, tmq->epoch);*/
if
(
rspHead
->
epoch
>
atomic_load_32
(
&
tmq
->
epoch
))
{
if
(
rspWrapper
->
epoch
>
atomic_load_32
(
&
tmq
->
epoch
))
{
SMqCMGetSubEpRsp
*
rspMsg
=
(
SMqCMGetSubEpRsp
*
)
rspHead
;
SMqAskEpRspWrapper
*
pEpRspWrapper
=
(
SMqAskEpRspWrapper
*
)
rspWrapper
;
tmqUpdateEp
(
tmq
,
rspHead
->
epoch
,
rspMsg
);
SMqCMGetSubEpRsp
*
rspMsg
=
&
pEpRspWrapper
->
msg
;
tmqUpdateEp
(
tmq
,
rspWrapper
->
epoch
,
rspMsg
);
/*tmqClearUnhandleMsg(tmq);*/
/*tmqClearUnhandleMsg(tmq);*/
*
pReset
=
true
;
*
pReset
=
true
;
}
else
{
}
else
{
...
@@ -1314,41 +1365,43 @@ int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspHead* rspHead, bool* pReset) {
...
@@ -1314,41 +1365,43 @@ int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspHead* rspHead, bool* pReset) {
return
0
;
return
0
;
}
}
tmq_message_t
*
tmqHandleAllRsp
(
tmq_t
*
tmq
,
int64_t
blockingTime
,
bool
pollIfReset
)
{
SMqRspObj
*
tmqHandleAllRsp
(
tmq_t
*
tmq
,
int64_t
blockingTime
,
bool
pollIfReset
)
{
while
(
1
)
{
while
(
1
)
{
SMqRsp
Head
*
rspHead
=
NULL
;
SMqRsp
Wrapper
*
rspWrapper
=
NULL
;
taosGetQitem
(
tmq
->
qall
,
(
void
**
)
&
rsp
Head
);
taosGetQitem
(
tmq
->
qall
,
(
void
**
)
&
rsp
Wrapper
);
if
(
rsp
Head
==
NULL
)
{
if
(
rsp
Wrapper
==
NULL
)
{
taosReadAllQitems
(
tmq
->
mqueue
,
tmq
->
qall
);
taosReadAllQitems
(
tmq
->
mqueue
,
tmq
->
qall
);
taosGetQitem
(
tmq
->
qall
,
(
void
**
)
&
rsp
Head
);
taosGetQitem
(
tmq
->
qall
,
(
void
**
)
&
rsp
Wrapper
);
if
(
rsp
Head
==
NULL
)
return
NULL
;
if
(
rsp
Wrapper
==
NULL
)
return
NULL
;
}
}
if
(
rsp
Head
->
mqMsg
Type
==
TMQ_MSG_TYPE__POLL_RSP
)
{
if
(
rsp
Wrapper
->
tmqRsp
Type
==
TMQ_MSG_TYPE__POLL_RSP
)
{
tmq_message_t
*
rspMsg
=
(
tmq_message_t
*
)
rspHead
;
SMqPollRspWrapper
*
pollRspWrapper
=
(
SMqPollRspWrapper
*
)
rspWrapper
;
atomic_sub_fetch_32
(
&
tmq
->
readyRequest
,
1
);
atomic_sub_fetch_32
(
&
tmq
->
readyRequest
,
1
);
/*printf("handle poll rsp %d\n", rspMsg->head.mqMsgType);*/
/*printf("handle poll rsp %d\n", rspMsg->head.mqMsgType);*/
if
(
rspMsg
->
msg
.
head
.
epoch
==
atomic_load_32
(
&
tmq
->
epoch
))
{
if
(
pollRspWrapper
->
msg
.
head
.
epoch
==
atomic_load_32
(
&
tmq
->
epoch
))
{
/*printf("epoch match\n");*/
/*printf("epoch match\n");*/
SMqClientVg
*
pVg
=
rspMsg
->
vg
;
SMqClientVg
*
pVg
=
pollRspWrapper
->
vgHandle
;
/*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/
/*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/
pVg
->
currentOffset
=
rspMsg
->
msg
.
rspOffset
;
pVg
->
currentOffset
=
pollRspWrapper
->
msg
.
rspOffset
;
atomic_store_32
(
&
pVg
->
vgStatus
,
TMQ_VG_STATUS__IDLE
);
atomic_store_32
(
&
pVg
->
vgStatus
,
TMQ_VG_STATUS__IDLE
);
if
(
rspMsg
->
msg
.
numOfTopics
==
0
)
{
if
(
pollRspWrapper
->
msg
.
dataLen
==
0
)
{
taosFreeQitem
(
rspMsg
);
taosFreeQitem
(
pollRspWrapper
);
rsp
Head
=
NULL
;
rsp
Wrapper
=
NULL
;
continue
;
continue
;
}
}
return
rspMsg
;
// build rsp
SMqRspObj
*
pRsp
=
tmqBuildRspFromWrapper
(
pollRspWrapper
);
return
pRsp
;
}
else
{
}
else
{
/*printf("epoch mismatch\n");*/
/*printf("epoch mismatch\n");*/
taosFreeQitem
(
rspMsg
);
taosFreeQitem
(
pollRspWrapper
);
}
}
}
else
{
}
else
{
/*printf("handle ep rsp %d\n", rspMsg->head.mqMsgType);*/
/*printf("handle ep rsp %d\n", rspMsg->head.mqMsgType);*/
bool
reset
=
false
;
bool
reset
=
false
;
tmqHandleNoPollRsp
(
tmq
,
rsp
Head
,
&
reset
);
tmqHandleNoPollRsp
(
tmq
,
rsp
Wrapper
,
&
reset
);
taosFreeQitem
(
rsp
Head
);
taosFreeQitem
(
rsp
Wrapper
);
if
(
pollIfReset
&&
reset
)
{
if
(
pollIfReset
&&
reset
)
{
tscDebug
(
"consumer %ld reset and repoll"
,
tmq
->
consumerId
);
tscDebug
(
"consumer %ld reset and repoll"
,
tmq
->
consumerId
);
tmqPollImpl
(
tmq
,
blockingTime
);
tmqPollImpl
(
tmq
,
blockingTime
);
...
@@ -1382,17 +1435,17 @@ tmq_message_t* tmq_consumer_poll_v1(tmq_t* tmq, int64_t blocking_time) {
...
@@ -1382,17 +1435,17 @@ tmq_message_t* tmq_consumer_poll_v1(tmq_t* tmq, int64_t blocking_time) {
}
}
#endif
#endif
tmq_message_t
*
tmq_consumer_poll
(
tmq_t
*
tmq
,
int64_t
blocking_time
)
{
TAOS_RES
*
tmq_consumer_poll
(
tmq_t
*
tmq
,
int64_t
blocking_time
)
{
tmq_message_t
*
rspMsg
;
SMqRspObj
*
rspObj
;
int64_t
startTime
=
taosGetTimestampMs
();
int64_t
startTime
=
taosGetTimestampMs
();
// TODO: put into another thread or delayed queue
// TODO: put into another thread or delayed queue
int64_t
status
=
atomic_load_64
(
&
tmq
->
status
);
int64_t
status
=
atomic_load_64
(
&
tmq
->
status
);
tmqAskEp
(
tmq
,
status
==
TMQ_CONSUMER_STATUS__INIT
);
tmqAskEp
(
tmq
,
status
==
TMQ_CONSUMER_STATUS__INIT
);
rsp
Msg
=
tmqHandleAllRsp
(
tmq
,
blocking_time
,
false
);
rsp
Obj
=
tmqHandleAllRsp
(
tmq
,
blocking_time
,
false
);
if
(
rsp
Msg
)
{
if
(
rsp
Obj
)
{
return
rspMsg
;
return
(
TAOS_RES
*
)
rspObj
;
}
}
while
(
1
)
{
while
(
1
)
{
...
@@ -1402,9 +1455,9 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
...
@@ -1402,9 +1455,9 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
/*tsem_wait(&tmq->rspSem);*/
/*tsem_wait(&tmq->rspSem);*/
rsp
Msg
=
tmqHandleAllRsp
(
tmq
,
blocking_time
,
false
);
rsp
Obj
=
tmqHandleAllRsp
(
tmq
,
blocking_time
,
false
);
if
(
rsp
Msg
)
{
if
(
rsp
Obj
)
{
return
rspMsg
;
return
(
TAOS_RES
*
)
rspObj
;
}
}
if
(
blocking_time
!=
0
)
{
if
(
blocking_time
!=
0
)
{
int64_t
endTime
=
taosGetTimestampMs
();
int64_t
endTime
=
taosGetTimestampMs
();
...
@@ -1546,6 +1599,7 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* tmq_topic_v
...
@@ -1546,6 +1599,7 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* tmq_topic_v
}
}
#endif
#endif
#if 0
void tmq_message_destroy(tmq_message_t* tmq_message) {
void tmq_message_destroy(tmq_message_t* tmq_message) {
if (tmq_message == NULL) return;
if (tmq_message == NULL) return;
SMqPollRsp* pRsp = &tmq_message->msg;
SMqPollRsp* pRsp = &tmq_message->msg;
...
@@ -1553,6 +1607,7 @@ void tmq_message_destroy(tmq_message_t* tmq_message) {
...
@@ -1553,6 +1607,7 @@ void tmq_message_destroy(tmq_message_t* tmq_message) {
/*taosMemoryFree(tmq_message);*/
/*taosMemoryFree(tmq_message);*/
taosFreeQitem(tmq_message);
taosFreeQitem(tmq_message);
}
}
#endif
tmq_resp_err_t
tmq_consumer_close
(
tmq_t
*
tmq
)
{
return
TMQ_RESP_ERR__SUCCESS
;
}
tmq_resp_err_t
tmq_consumer_close
(
tmq_t
*
tmq
)
{
return
TMQ_RESP_ERR__SUCCESS
;
}
...
@@ -1563,4 +1618,27 @@ const char* tmq_err2str(tmq_resp_err_t err) {
...
@@ -1563,4 +1618,27 @@ const char* tmq_err2str(tmq_resp_err_t err) {
return
"fail"
;
return
"fail"
;
}
}
char
*
tmq_get_topic_name
(
tmq_message_t
*
message
)
{
return
"not implemented yet"
;
}
char
*
tmq_get_topic_name
(
TAOS_RES
*
res
)
{
if
(
TD_RES_TMQ
(
res
))
{
SMqRspObj
*
pRspObj
=
(
SMqRspObj
*
)
res
;
return
pRspObj
->
topic
;
}
else
{
return
NULL
;
}
}
int32_t
tmq_get_vgroup_id
(
TAOS_RES
*
res
)
{
if
(
TD_RES_TMQ
(
res
))
{
SMqRspObj
*
pRspObj
=
(
SMqRspObj
*
)
res
;
return
pRspObj
->
vgId
;
}
else
{
return
-
1
;
}
}
void
tmq_message_destroy
(
TAOS_RES
*
res
)
{
if
(
res
==
NULL
)
return
;
if
(
TD_RES_TMQ
(
res
))
{
SMqRspObj
*
pRspObj
=
(
SMqRspObj
*
)
res
;
}
}
source/dnode/mgmt/exe/dmMain.c
浏览文件 @
3a26ec4e
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "dmImp.h"
#include "dmImp.h"
#include "tconfig.h"
#include "tconfig.h"
#include "
tg
rant.h"
#include "
mndG
rant.h"
static
struct
{
static
struct
{
bool
dumpConfig
;
bool
dumpConfig
;
...
@@ -90,7 +90,7 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
...
@@ -90,7 +90,7 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
return
0
;
return
0
;
}
}
static
void
dmGenerateGrant
()
{
grantParse
Parameter
();
}
static
void
dmGenerateGrant
()
{
parseGrant
Parameter
();
}
static
void
dmPrintVersion
()
{
static
void
dmPrintVersion
()
{
#ifdef TD_ENTERPRISE
#ifdef TD_ENTERPRISE
...
...
source/dnode/mnode/impl/CMakeLists.txt
浏览文件 @
3a26ec4e
...
@@ -9,6 +9,13 @@ target_link_libraries(
...
@@ -9,6 +9,13 @@ target_link_libraries(
mnode scheduler sdb wal transport cjson sync monitor executor qworker stream parser
mnode scheduler sdb wal transport cjson sync monitor executor qworker stream parser
)
)
IF
(
TD_GRANT
)
TARGET_LINK_LIBRARIES
(
mnode grant
)
ENDIF
()
IF
(
TD_USB_DONGLE
)
TARGET_LINK_LIBRARIES
(
mnode usb_dongle
)
ENDIF
()
if
(
${
BUILD_TEST
}
)
if
(
${
BUILD_TEST
}
)
add_subdirectory
(
test
)
add_subdirectory
(
test
)
endif
(
${
BUILD_TEST
}
)
endif
(
${
BUILD_TEST
}
)
include/common/tg
rant.h
→
source/dnode/mnode/impl/inc/mndG
rant.h
浏览文件 @
3a26ec4e
...
@@ -36,14 +36,15 @@ typedef enum {
...
@@ -36,14 +36,15 @@ typedef enum {
TSDB_GRANT_CPU_CORES
,
TSDB_GRANT_CPU_CORES
,
}
EGrantType
;
}
EGrantType
;
int32_t
grantIni
t
();
int32_t
mndInitGran
t
();
void
grantCleanUp
();
void
mndCleanupGrant
();
void
grantParseParameter
();
void
grantParseParameter
();
int32_t
grantCheck
(
EGrantType
grant
);
int32_t
grantCheck
(
EGrantType
grant
);
void
grantReset
(
EGrantType
grant
,
uint64_t
value
);
void
grantReset
(
EGrantType
grant
,
uint64_t
value
);
void
grantAdd
(
EGrantType
grant
,
uint64_t
value
);
void
grantAdd
(
EGrantType
grant
,
uint64_t
value
);
void
grantRestore
(
EGrantType
grant
,
uint64_t
value
);
void
grantRestore
(
EGrantType
grant
,
uint64_t
value
);
void
parseGrantParameter
();
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/dnode/mnode/impl/src/mndGrant.c
浏览文件 @
3a26ec4e
...
@@ -17,11 +17,11 @@
...
@@ -17,11 +17,11 @@
#ifndef _GRANT
#ifndef _GRANT
#include "os.h"
#include "os.h"
#include "taoserror.h"
#include "taoserror.h"
#include "
tg
rant.h"
#include "
mndG
rant.h"
#include "mndInt.h"
#include "mndInt.h"
int32_t
grantInit
(
)
{
return
TSDB_CODE_SUCCESS
;
}
int32_t
mndInitGrant
(
SMnode
*
pMnode
)
{
return
TSDB_CODE_SUCCESS
;
}
void
grantCleanUp
()
{}
void
mndCleanupGrant
()
{}
void
grantParseParameter
()
{
mError
(
"can't parsed parameter k"
);
}
void
grantParseParameter
()
{
mError
(
"can't parsed parameter k"
);
}
int32_t
grantCheck
(
EGrantType
grant
)
{
return
TSDB_CODE_SUCCESS
;
}
int32_t
grantCheck
(
EGrantType
grant
)
{
return
TSDB_CODE_SUCCESS
;
}
void
grantReset
(
EGrantType
grant
,
uint64_t
value
)
{}
void
grantReset
(
EGrantType
grant
,
uint64_t
value
)
{}
...
@@ -29,3 +29,5 @@ void grantAdd(EGrantType grant, uint64_t value) {}
...
@@ -29,3 +29,5 @@ void grantAdd(EGrantType grant, uint64_t value) {}
void
grantRestore
(
EGrantType
grant
,
uint64_t
value
)
{}
void
grantRestore
(
EGrantType
grant
,
uint64_t
value
)
{}
#endif
#endif
void
parseGrantParameter
()
{
parseGrantParameter
();
}
\ No newline at end of file
source/dnode/mnode/impl/src/mndInfoSchema.c
浏览文件 @
3a26ec4e
...
@@ -151,6 +151,22 @@ static const SInfosTableSchema userUsersSchema[] = {
...
@@ -151,6 +151,22 @@ static const SInfosTableSchema userUsersSchema[] = {
{.
name
=
"create_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
{.
name
=
"create_time"
,
.
bytes
=
8
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
},
{.
name
=
"account"
,
.
bytes
=
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"account"
,
.
bytes
=
TSDB_USER_LEN
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
};
};
static
const
SInfosTableSchema
grantsSchema
[]
=
{
{.
name
=
"version"
,
.
bytes
=
8
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"expire time"
,
.
bytes
=
19
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"expired"
,
.
bytes
=
5
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"storage(GB)"
,
.
bytes
=
21
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"timeseries"
,
.
bytes
=
21
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"databases"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"users"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"accounts"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"dnodes"
,
.
bytes
=
10
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"connections"
,
.
bytes
=
11
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"streams"
,
.
bytes
=
9
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"cpu cores"
,
.
bytes
=
9
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"speed(PPS)"
,
.
bytes
=
9
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"querytime"
,
.
bytes
=
9
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
};
static
const
SInfosTableSchema
vgroupsSchema
[]
=
{
static
const
SInfosTableSchema
vgroupsSchema
[]
=
{
{.
name
=
"vgroup_id"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"vgroup_id"
,
.
bytes
=
4
,
.
type
=
TSDB_DATA_TYPE_INT
},
{.
name
=
"db_name"
,
.
bytes
=
SYSTABLE_SCH_DB_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
{.
name
=
"db_name"
,
.
bytes
=
SYSTABLE_SCH_DB_NAME_LEN
,
.
type
=
TSDB_DATA_TYPE_BINARY
},
...
@@ -211,6 +227,7 @@ static const SInfosTableMeta infosMeta[] = {
...
@@ -211,6 +227,7 @@ static const SInfosTableMeta infosMeta[] = {
{
TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED
,
userTblDistSchema
,
tListLen
(
userTblDistSchema
)},
{
TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED
,
userTblDistSchema
,
tListLen
(
userTblDistSchema
)},
{
TSDB_INS_TABLE_USER_USERS
,
userUsersSchema
,
tListLen
(
userUsersSchema
)},
{
TSDB_INS_TABLE_USER_USERS
,
userUsersSchema
,
tListLen
(
userUsersSchema
)},
{
TSDB_INS_TABLE_VGROUPS
,
vgroupsSchema
,
tListLen
(
vgroupsSchema
)},
{
TSDB_INS_TABLE_VGROUPS
,
vgroupsSchema
,
tListLen
(
vgroupsSchema
)},
{
TSDB_INS_TABLE_LICENCES
,
grantsSchema
,
tListLen
(
grantsSchema
)},
};
};
// connection/application/
// connection/application/
...
...
source/dnode/mnode/impl/src/mndSubscribe.c
浏览文件 @
3a26ec4e
...
@@ -60,8 +60,10 @@ static int32_t mndProcessResetOffsetReq(SNodeMsg *pMsg);
...
@@ -60,8 +60,10 @@ static int32_t mndProcessResetOffsetReq(SNodeMsg *pMsg);
static
int32_t
mndPersistMqSetConnReq
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
const
SMqTopicObj
*
pTopic
,
const
char
*
cgroup
,
static
int32_t
mndPersistMqSetConnReq
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
const
SMqTopicObj
*
pTopic
,
const
char
*
cgroup
,
const
SMqConsumerEp
*
pConsumerEp
);
const
SMqConsumerEp
*
pConsumerEp
);
static
int32_t
mndPersistRebalanceMsg
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
const
SMqConsumerEp
*
pConsumerEp
,
const
char
*
topicName
);
static
int32_t
mndPersistRebalanceMsg
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
const
SMqConsumerEp
*
pConsumerEp
,
static
int32_t
mndPersistCancelConnReq
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
const
SMqConsumerEp
*
pConsumerEp
,
const
char
*
oldTopicName
);
const
char
*
topicName
);
static
int32_t
mndPersistCancelConnReq
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
const
SMqConsumerEp
*
pConsumerEp
,
const
char
*
oldTopicName
);
int32_t
mndInitSubscribe
(
SMnode
*
pMnode
)
{
int32_t
mndInitSubscribe
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_SUBSCRIBE
,
SSdbTable
table
=
{.
sdbType
=
SDB_SUBSCRIBE
,
...
@@ -102,7 +104,8 @@ static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj
...
@@ -102,7 +104,8 @@ static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj
return
pSub
;
return
pSub
;
}
}
static
int32_t
mndBuildRebalanceMsg
(
void
**
pBuf
,
int32_t
*
pLen
,
const
SMqConsumerEp
*
pConsumerEp
,
const
char
*
topicName
)
{
static
int32_t
mndBuildRebalanceMsg
(
void
**
pBuf
,
int32_t
*
pLen
,
const
SMqConsumerEp
*
pConsumerEp
,
const
char
*
topicName
)
{
SMqMVRebReq
req
=
{
SMqMVRebReq
req
=
{
.
vgId
=
pConsumerEp
->
vgId
,
.
vgId
=
pConsumerEp
->
vgId
,
.
oldConsumerId
=
pConsumerEp
->
oldConsumerId
,
.
oldConsumerId
=
pConsumerEp
->
oldConsumerId
,
...
@@ -131,7 +134,8 @@ static int32_t mndBuildRebalanceMsg(void **pBuf, int32_t *pLen, const SMqConsume
...
@@ -131,7 +134,8 @@ static int32_t mndBuildRebalanceMsg(void **pBuf, int32_t *pLen, const SMqConsume
return
0
;
return
0
;
}
}
static
int32_t
mndPersistRebalanceMsg
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
const
SMqConsumerEp
*
pConsumerEp
,
const
char
*
topicName
)
{
static
int32_t
mndPersistRebalanceMsg
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
const
SMqConsumerEp
*
pConsumerEp
,
const
char
*
topicName
)
{
ASSERT
(
pConsumerEp
->
oldConsumerId
!=
-
1
);
ASSERT
(
pConsumerEp
->
oldConsumerId
!=
-
1
);
void
*
buf
;
void
*
buf
;
...
@@ -158,7 +162,8 @@ static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqC
...
@@ -158,7 +162,8 @@ static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqC
return
0
;
return
0
;
}
}
static
int32_t
mndBuildCancelConnReq
(
void
**
pBuf
,
int32_t
*
pLen
,
const
SMqConsumerEp
*
pConsumerEp
,
const
char
*
oldTopicName
)
{
static
int32_t
mndBuildCancelConnReq
(
void
**
pBuf
,
int32_t
*
pLen
,
const
SMqConsumerEp
*
pConsumerEp
,
const
char
*
oldTopicName
)
{
SMqCancelConnReq
req
=
{
0
};
SMqCancelConnReq
req
=
{
0
};
req
.
consumerId
=
pConsumerEp
->
consumerId
;
req
.
consumerId
=
pConsumerEp
->
consumerId
;
req
.
vgId
=
pConsumerEp
->
vgId
;
req
.
vgId
=
pConsumerEp
->
vgId
;
...
@@ -182,7 +187,8 @@ static int32_t mndBuildCancelConnReq(void **pBuf, int32_t *pLen, const SMqConsum
...
@@ -182,7 +187,8 @@ static int32_t mndBuildCancelConnReq(void **pBuf, int32_t *pLen, const SMqConsum
return
0
;
return
0
;
}
}
static
int32_t
mndPersistCancelConnReq
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
const
SMqConsumerEp
*
pConsumerEp
,
const
char
*
oldTopicName
)
{
static
int32_t
mndPersistCancelConnReq
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
const
SMqConsumerEp
*
pConsumerEp
,
const
char
*
oldTopicName
)
{
void
*
buf
;
void
*
buf
;
int32_t
tlen
;
int32_t
tlen
;
if
(
mndBuildCancelConnReq
(
&
buf
,
&
tlen
,
pConsumerEp
,
oldTopicName
)
<
0
)
{
if
(
mndBuildCancelConnReq
(
&
buf
,
&
tlen
,
pConsumerEp
,
oldTopicName
)
<
0
)
{
...
@@ -219,13 +225,14 @@ static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) {
...
@@ -219,13 +225,14 @@ static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) {
terrno
=
TSDB_CODE_MND_CONSUMER_NOT_EXIST
;
terrno
=
TSDB_CODE_MND_CONSUMER_NOT_EXIST
;
return
-
1
;
return
-
1
;
}
}
//TODO add lock
//
TODO add lock
ASSERT
(
strcmp
(
pReq
->
cgroup
,
pConsumer
->
cgroup
)
==
0
);
ASSERT
(
strcmp
(
pReq
->
cgroup
,
pConsumer
->
cgroup
)
==
0
);
int32_t
serverEpoch
=
pConsumer
->
epoch
;
int32_t
serverEpoch
=
pConsumer
->
epoch
;
// TODO
// TODO
int32_t
hbStatus
=
atomic_load_32
(
&
pConsumer
->
hbStatus
);
int32_t
hbStatus
=
atomic_load_32
(
&
pConsumer
->
hbStatus
);
mDebug
(
"consumer %ld epoch(%d) try to get sub ep, server epoch %d, old val: %d"
,
consumerId
,
epoch
,
serverEpoch
,
hbStatus
);
mDebug
(
"consumer %ld epoch(%d) try to get sub ep, server epoch %d, old val: %d"
,
consumerId
,
epoch
,
serverEpoch
,
hbStatus
);
atomic_store_32
(
&
pConsumer
->
hbStatus
,
0
);
atomic_store_32
(
&
pConsumer
->
hbStatus
,
0
);
/*SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pConsumer);*/
/*SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pConsumer);*/
/*sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY);*/
/*sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY);*/
...
@@ -233,7 +240,8 @@ static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) {
...
@@ -233,7 +240,8 @@ static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) {
strcpy
(
rsp
.
cgroup
,
pReq
->
cgroup
);
strcpy
(
rsp
.
cgroup
,
pReq
->
cgroup
);
if
(
epoch
!=
serverEpoch
)
{
if
(
epoch
!=
serverEpoch
)
{
mInfo
(
"send new assignment to consumer %ld, consumer epoch %d, server epoch %d"
,
pConsumer
->
consumerId
,
epoch
,
serverEpoch
);
mInfo
(
"send new assignment to consumer %ld, consumer epoch %d, server epoch %d"
,
pConsumer
->
consumerId
,
epoch
,
serverEpoch
);
mDebug
(
"consumer %ld try r lock"
,
consumerId
);
mDebug
(
"consumer %ld try r lock"
,
consumerId
);
taosRLockLatch
(
&
pConsumer
->
lock
);
taosRLockLatch
(
&
pConsumer
->
lock
);
mDebug
(
"consumer %ld r locked"
,
consumerId
);
mDebug
(
"consumer %ld r locked"
,
consumerId
);
...
@@ -251,8 +259,15 @@ static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) {
...
@@ -251,8 +259,15 @@ static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) {
if
(
consumerId
==
pSubConsumer
->
consumerId
)
{
if
(
consumerId
==
pSubConsumer
->
consumerId
)
{
int32_t
vgsz
=
taosArrayGetSize
(
pSubConsumer
->
vgInfo
);
int32_t
vgsz
=
taosArrayGetSize
(
pSubConsumer
->
vgInfo
);
mInfo
(
"topic %s has %d vg"
,
topicName
,
serverEpoch
);
mInfo
(
"topic %s has %d vg"
,
topicName
,
serverEpoch
);
SMqSubTopicEp
topicEp
;
SMqSubTopicEp
topicEp
;
strcpy
(
topicEp
.
topic
,
topicName
);
strcpy
(
topicEp
.
topic
,
topicName
);
SMqTopicObj
*
pTopic
=
mndAcquireTopic
(
pMnode
,
topicName
);
ASSERT
(
pTopic
!=
NULL
);
topicEp
.
schema
=
pTopic
->
schema
;
mndReleaseTopic
(
pMnode
,
pTopic
);
topicEp
.
vgs
=
taosArrayInit
(
vgsz
,
sizeof
(
SMqSubVgEp
));
topicEp
.
vgs
=
taosArrayInit
(
vgsz
,
sizeof
(
SMqSubVgEp
));
for
(
int32_t
k
=
0
;
k
<
vgsz
;
k
++
)
{
for
(
int32_t
k
=
0
;
k
<
vgsz
;
k
++
)
{
char
offsetKey
[
TSDB_PARTITION_KEY_LEN
];
char
offsetKey
[
TSDB_PARTITION_KEY_LEN
];
...
@@ -409,7 +424,8 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) {
...
@@ -409,7 +424,8 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) {
SMqSubscribeObj
*
pSub
=
mndAcquireSubscribeByKey
(
pMnode
,
pRebSub
->
key
);
SMqSubscribeObj
*
pSub
=
mndAcquireSubscribeByKey
(
pMnode
,
pRebSub
->
key
);
taosMemoryFreeClear
(
pRebSub
->
key
);
taosMemoryFreeClear
(
pRebSub
->
key
);
mInfo
(
"mq rebalance subscription: %s, vgNum: %d, unassignedVg: %d"
,
pSub
->
key
,
pSub
->
vgNum
,
(
int32_t
)
taosArrayGetSize
(
pSub
->
unassignedVg
));
mInfo
(
"mq rebalance subscription: %s, vgNum: %d, unassignedVg: %d"
,
pSub
->
key
,
pSub
->
vgNum
,
(
int32_t
)
taosArrayGetSize
(
pSub
->
unassignedVg
));
// remove lost consumer
// remove lost consumer
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pRebSub
->
lostConsumers
);
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pRebSub
->
lostConsumers
);
i
++
)
{
...
@@ -500,7 +516,7 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) {
...
@@ -500,7 +516,7 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) {
pConsumerEp
->
oldConsumerId
=
pConsumerEp
->
consumerId
;
pConsumerEp
->
oldConsumerId
=
pConsumerEp
->
consumerId
;
pConsumerEp
->
consumerId
=
pSubConsumer
->
consumerId
;
pConsumerEp
->
consumerId
=
pSubConsumer
->
consumerId
;
//TODO
//
TODO
pConsumerEp
->
epoch
=
0
;
pConsumerEp
->
epoch
=
0
;
taosArrayPush
(
pSubConsumer
->
vgInfo
,
pConsumerEp
);
taosArrayPush
(
pSubConsumer
->
vgInfo
,
pConsumerEp
);
...
...
source/dnode/mnode/impl/src/mndUser.c
浏览文件 @
3a26ec4e
...
@@ -687,6 +687,8 @@ static int32_t mndGetUserMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pM
...
@@ -687,6 +687,8 @@ static int32_t mndGetUserMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pM
}
}
static
int32_t
mndRetrieveUsers
(
SNodeMsg
*
pReq
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
static
int32_t
mndRetrieveUsers
(
SNodeMsg
*
pReq
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
printf
(
"%s(%d) %s rows=%d
\n
"
,
__FILE__
,
__LINE__
,
__func__
,
rows
);
printf
(
"%s(%d) %s pShow->numOfReads=%d
\n
"
,
__FILE__
,
__LINE__
,
__func__
,
pShow
->
numOfReads
);
SMnode
*
pMnode
=
pReq
->
pNode
;
SMnode
*
pMnode
=
pReq
->
pNode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
int32_t
numOfRows
=
0
;
...
@@ -701,10 +703,12 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, char *data, int
...
@@ -701,10 +703,12 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, char *data, int
cols
=
0
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
printf
(
"%s(%d) %s pWrite=%p
\n
"
,
__FILE__
,
__LINE__
,
__func__
,
pWrite
);
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pUser
->
user
,
pShow
->
bytes
[
cols
]);
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pUser
->
user
,
pShow
->
bytes
[
cols
]);
cols
++
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
printf
(
"%s(%d) %s pWrite=%p
\n
"
,
__FILE__
,
__LINE__
,
__func__
,
pWrite
);
if
(
pUser
->
superUser
)
{
if
(
pUser
->
superUser
)
{
const
char
*
src
=
"super"
;
const
char
*
src
=
"super"
;
STR_WITH_SIZE_TO_VARSTR
(
pWrite
,
src
,
strlen
(
src
));
STR_WITH_SIZE_TO_VARSTR
(
pWrite
,
src
,
strlen
(
src
));
...
@@ -715,10 +719,12 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, char *data, int
...
@@ -715,10 +719,12 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, char *data, int
cols
++
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
printf
(
"%s(%d) %s pWrite=%p
\n
"
,
__FILE__
,
__LINE__
,
__func__
,
pWrite
);
*
(
int64_t
*
)
pWrite
=
pUser
->
createdTime
;
*
(
int64_t
*
)
pWrite
=
pUser
->
createdTime
;
cols
++
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
printf
(
"%s(%d) %s pWrite=%p
\n
"
,
__FILE__
,
__LINE__
,
__func__
,
pWrite
);
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pUser
->
acct
,
pShow
->
bytes
[
cols
]);
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pUser
->
acct
,
pShow
->
bytes
[
cols
]);
cols
++
;
cols
++
;
...
@@ -728,6 +734,7 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, char *data, int
...
@@ -728,6 +734,7 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, char *data, int
mndVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
mndVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
pShow
->
numOfReads
+=
numOfRows
;
printf
(
"%s(%d) %s numOfRows=%d
\n
"
,
__FILE__
,
__LINE__
,
__func__
,
numOfRows
);
return
numOfRows
;
return
numOfRows
;
}
}
...
...
source/dnode/mnode/impl/src/mnode.c
浏览文件 @
3a26ec4e
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
#include "mndUser.h"
#include "mndUser.h"
#include "mndVgroup.h"
#include "mndVgroup.h"
#include "mndQuery.h"
#include "mndQuery.h"
#include "mndGrant.h"
#define MQ_TIMER_MS 3000
#define MQ_TIMER_MS 3000
#define TRNAS_TIMER_MS 6000
#define TRNAS_TIMER_MS 6000
...
@@ -197,6 +198,7 @@ static int32_t mndInitSteps(SMnode *pMnode, bool deploy) {
...
@@ -197,6 +198,7 @@ static int32_t mndInitSteps(SMnode *pMnode, bool deploy) {
if
(
mndAllocStep
(
pMnode
,
"mnode-qnode"
,
mndInitBnode
,
mndCleanupBnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-qnode"
,
mndInitBnode
,
mndCleanupBnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-dnode"
,
mndInitDnode
,
mndCleanupDnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-dnode"
,
mndInitDnode
,
mndCleanupDnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-user"
,
mndInitUser
,
mndCleanupUser
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-user"
,
mndInitUser
,
mndCleanupUser
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-grant"
,
mndInitGrant
,
mndCleanupGrant
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-auth"
,
mndInitAuth
,
mndCleanupAuth
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-auth"
,
mndInitAuth
,
mndCleanupAuth
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-acct"
,
mndInitAcct
,
mndCleanupAcct
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-acct"
,
mndInitAcct
,
mndCleanupAcct
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-stream"
,
mndInitStream
,
mndCleanupStream
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-stream"
,
mndInitStream
,
mndCleanupStream
)
!=
0
)
return
-
1
;
...
...
source/dnode/vnode/CMakeLists.txt
浏览文件 @
3a26ec4e
...
@@ -30,6 +30,7 @@ target_sources(
...
@@ -30,6 +30,7 @@ target_sources(
# tsdb
# tsdb
# "src/tsdb/tsdbBDBImpl.c"
# "src/tsdb/tsdbBDBImpl.c"
"src/tsdb/tsdbTDBImpl.c"
"src/tsdb/tsdbCommit.c"
"src/tsdb/tsdbCommit.c"
"src/tsdb/tsdbCompact.c"
"src/tsdb/tsdbCompact.c"
"src/tsdb/tsdbFile.c"
"src/tsdb/tsdbFile.c"
...
@@ -40,7 +41,7 @@ target_sources(
...
@@ -40,7 +41,7 @@ target_sources(
"src/tsdb/tsdbRead.c"
"src/tsdb/tsdbRead.c"
"src/tsdb/tsdbReadImpl.c"
"src/tsdb/tsdbReadImpl.c"
"src/tsdb/tsdbScan.c"
"src/tsdb/tsdbScan.c"
#
"src/tsdb/tsdbSma.c"
"src/tsdb/tsdbSma.c"
"src/tsdb/tsdbWrite.c"
"src/tsdb/tsdbWrite.c"
# tq
# tq
...
...
source/dnode/vnode/inc/vnode.h
浏览文件 @
3a26ec4e
此差异已折叠。
点击以展开。
source/dnode/vnode/src/inc/meta.h
浏览文件 @
3a26ec4e
...
@@ -24,6 +24,17 @@ typedef struct SMetaCache SMetaCache;
...
@@ -24,6 +24,17 @@ typedef struct SMetaCache SMetaCache;
typedef
struct
SMetaIdx
SMetaIdx
;
typedef
struct
SMetaIdx
SMetaIdx
;
typedef
struct
SMetaDB
SMetaDB
;
typedef
struct
SMetaDB
SMetaDB
;
SMeta
*
metaOpen
(
const
char
*
path
,
const
SMetaCfg
*
pMetaCfg
,
SMemAllocatorFactory
*
pMAF
);
void
metaClose
(
SMeta
*
pMeta
);
void
metaRemove
(
const
char
*
path
);
int
metaCreateTable
(
SMeta
*
pMeta
,
STbCfg
*
pTbCfg
);
int
metaDropTable
(
SMeta
*
pMeta
,
tb_uid_t
uid
);
int
metaCommit
(
SMeta
*
pMeta
);
int32_t
metaCreateTSma
(
SMeta
*
pMeta
,
SSmaCfg
*
pCfg
);
int32_t
metaDropTSma
(
SMeta
*
pMeta
,
int64_t
indexUid
);
STbCfg
*
metaGetTbInfoByUid
(
SMeta
*
pMeta
,
tb_uid_t
uid
);
STbCfg
*
metaGetTbInfoByName
(
SMeta
*
pMeta
,
char
*
tbname
,
tb_uid_t
*
uid
);
// SMetaDB
// SMetaDB
int
metaOpenDB
(
SMeta
*
pMeta
);
int
metaOpenDB
(
SMeta
*
pMeta
);
void
metaCloseDB
(
SMeta
*
pMeta
);
void
metaCloseDB
(
SMeta
*
pMeta
);
...
...
source/dnode/vnode/src/inc/tsdbSma.h
0 → 100644
浏览文件 @
3a26ec4e
/*
* 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_TSDB_SMA_H_
#define _TD_VNODE_TSDB_SMA_H_
#include "tdbInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
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
;
}
#ifdef __cplusplus
}
#endif
#endif
/*_TD_VNODE_TSDB_SMA_H_*/
\ No newline at end of file
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
3a26ec4e
...
@@ -17,6 +17,9 @@
...
@@ -17,6 +17,9 @@
#define _TD_VNODE_DEF_H_
#define _TD_VNODE_DEF_H_
#include "executor.h"
#include "executor.h"
#include "filter.h"
#include "qworker.h"
#include "sync.h"
#include "tchecksum.h"
#include "tchecksum.h"
#include "tcoding.h"
#include "tcoding.h"
#include "tcompression.h"
#include "tcompression.h"
...
@@ -25,14 +28,15 @@
...
@@ -25,14 +28,15 @@
#include "tglobal.h"
#include "tglobal.h"
#include "tlist.h"
#include "tlist.h"
#include "tlockfree.h"
#include "tlockfree.h"
#include "tlosertree.h"
#include "tmacro.h"
#include "tmacro.h"
#include "tmallocator.h"
#include "tmallocator.h"
#include "tskiplist.h"
#include "tskiplist.h"
#include "tstream.h"
#include "ttime.h"
#include "ttime.h"
#include "ttimer.h"
#include "ttimer.h"
#include "vnode.h"
#include "vnode.h"
#include "wal.h"
#include "wal.h"
#include "qworker.h"
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -220,6 +224,8 @@ void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data);
...
@@ -220,6 +224,8 @@ void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data);
#include "tq.h"
#include "tq.h"
#include "tsdbSma.h"
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/dnode/vnode/src/meta/metaBDBImpl.c
浏览文件 @
3a26ec4e
...
@@ -16,10 +16,7 @@
...
@@ -16,10 +16,7 @@
#define ALLOW_FORBID_FUNC
#define ALLOW_FORBID_FUNC
#include "db.h"
#include "db.h"
#include "metaDef.h"
#include "vnodeInt.h"
#include "tcoding.h"
#include "thash.h"
#define IMPL_WITH_LOCK 1
#define IMPL_WITH_LOCK 1
// #if IMPL_WITH_LOCK
// #if IMPL_WITH_LOCK
...
@@ -667,8 +664,8 @@ STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) {
...
@@ -667,8 +664,8 @@ STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) {
return
pTbCfg
;
return
pTbCfg
;
}
}
STSma
*
metaGetSmaInfoByIndex
(
SMeta
*
pMeta
,
int64_t
indexUid
)
{
void
*
metaGetSmaInfoByIndex
(
SMeta
*
pMeta
,
int64_t
indexUid
,
bool
isDecode
)
{
STSma
*
pCfg
=
NULL
;
STSma
*
pCfg
=
NULL
;
SMetaDB
*
pDB
=
pMeta
->
pDB
;
SMetaDB
*
pDB
=
pMeta
->
pDB
;
DBT
key
=
{
0
};
DBT
key
=
{
0
};
DBT
value
=
{
0
};
DBT
value
=
{
0
};
...
@@ -920,7 +917,7 @@ SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) {
...
@@ -920,7 +917,7 @@ SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) {
return
pCur
;
return
pCur
;
}
}
void
metaCloseSmaCur
os
r
(
SMSmaCursor
*
pCur
)
{
void
metaCloseSmaCur
so
r
(
SMSmaCursor
*
pCur
)
{
if
(
pCur
)
{
if
(
pCur
)
{
if
(
pCur
->
pCur
)
{
if
(
pCur
->
pCur
)
{
pCur
->
pCur
->
close
(
pCur
->
pCur
);
pCur
->
pCur
->
close
(
pCur
->
pCur
);
...
@@ -930,7 +927,8 @@ void metaCloseSmaCurosr(SMSmaCursor *pCur) {
...
@@ -930,7 +927,8 @@ void metaCloseSmaCurosr(SMSmaCursor *pCur) {
}
}
}
}
const
char
*
metaSmaCursorNext
(
SMSmaCursor
*
pCur
)
{
int64_t
metaSmaCursorNext
(
SMSmaCursor
*
pCur
)
{
#if 0
DBT skey = {0};
DBT skey = {0};
DBT pkey = {0};
DBT pkey = {0};
DBT pval = {0};
DBT pval = {0};
...
@@ -946,6 +944,8 @@ const char *metaSmaCursorNext(SMSmaCursor *pCur) {
...
@@ -946,6 +944,8 @@ const char *metaSmaCursorNext(SMSmaCursor *pCur) {
} else {
} else {
return NULL;
return NULL;
}
}
#endif
return
0
;
}
}
STSmaWrapper
*
metaGetSmaInfoByTable
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
STSmaWrapper
*
metaGetSmaInfoByTable
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
...
@@ -972,7 +972,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
...
@@ -972,7 +972,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
++
pSW
->
number
;
++
pSW
->
number
;
STSma
*
tptr
=
(
STSma
*
)
taosMemoryRealloc
(
pSW
->
tSma
,
pSW
->
number
*
sizeof
(
STSma
));
STSma
*
tptr
=
(
STSma
*
)
taosMemoryRealloc
(
pSW
->
tSma
,
pSW
->
number
*
sizeof
(
STSma
));
if
(
tptr
==
NULL
)
{
if
(
tptr
==
NULL
)
{
metaCloseSmaCur
os
r
(
pCur
);
metaCloseSmaCur
so
r
(
pCur
);
tdDestroyTSmaWrapper
(
pSW
);
tdDestroyTSmaWrapper
(
pSW
);
taosMemoryFreeClear
(
pSW
);
taosMemoryFreeClear
(
pSW
);
return
NULL
;
return
NULL
;
...
@@ -980,7 +980,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
...
@@ -980,7 +980,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
pSW
->
tSma
=
tptr
;
pSW
->
tSma
=
tptr
;
pBuf
=
pval
.
data
;
pBuf
=
pval
.
data
;
if
(
tDecodeTSma
(
pBuf
,
pSW
->
tSma
+
pSW
->
number
-
1
)
==
NULL
)
{
if
(
tDecodeTSma
(
pBuf
,
pSW
->
tSma
+
pSW
->
number
-
1
)
==
NULL
)
{
metaCloseSmaCur
os
r
(
pCur
);
metaCloseSmaCur
so
r
(
pCur
);
tdDestroyTSmaWrapper
(
pSW
);
tdDestroyTSmaWrapper
(
pSW
);
taosMemoryFreeClear
(
pSW
);
taosMemoryFreeClear
(
pSW
);
return
NULL
;
return
NULL
;
...
@@ -990,7 +990,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
...
@@ -990,7 +990,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
break
;
break
;
}
}
metaCloseSmaCur
os
r
(
pCur
);
metaCloseSmaCur
so
r
(
pCur
);
return
pSW
;
return
pSW
;
}
}
...
@@ -1004,7 +1004,7 @@ SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) {
...
@@ -1004,7 +1004,7 @@ SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) {
int
ret
;
int
ret
;
// TODO: lock?
// TODO: lock?
ret
=
pDB
->
p
Ctb
Idx
->
cursor
(
pDB
->
pSmaIdx
,
NULL
,
&
pCur
,
0
);
ret
=
pDB
->
p
Sma
Idx
->
cursor
(
pDB
->
pSmaIdx
,
NULL
,
&
pCur
,
0
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
return
NULL
;
return
NULL
;
}
}
...
...
source/dnode/vnode/src/meta/metaCfg.c
浏览文件 @
3a26ec4e
...
@@ -18,11 +18,6 @@
...
@@ -18,11 +18,6 @@
const
SMetaCfg
defaultMetaOptions
=
{.
lruSize
=
0
};
const
SMetaCfg
defaultMetaOptions
=
{.
lruSize
=
0
};
/* ------------------------ EXPOSED METHODS ------------------------ */
/* ------------------------ EXPOSED METHODS ------------------------ */
void
metaOptionsInit
(
SMetaCfg
*
pMetaOptions
)
{
metaOptionsCopy
(
pMetaOptions
,
&
defaultMetaOptions
);
}
void
metaOptionsClear
(
SMetaCfg
*
pMetaOptions
)
{
// TODO
}
int
metaValidateOptions
(
const
SMetaCfg
*
pMetaOptions
)
{
int
metaValidateOptions
(
const
SMetaCfg
*
pMetaOptions
)
{
// TODO
// TODO
...
...
source/dnode/vnode/src/meta/metaQuery.c
浏览文件 @
3a26ec4e
...
@@ -12,3 +12,5 @@
...
@@ -12,3 +12,5 @@
* You should have received a copy of the GNU Affero General Public License
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "vnodeInt.h"
\ No newline at end of file
source/dnode/vnode/src/meta/metaTDBImpl.c
浏览文件 @
3a26ec4e
...
@@ -15,29 +15,34 @@
...
@@ -15,29 +15,34 @@
#include "vnodeInt.h"
#include "vnodeInt.h"
#include "tdbInt.h"
typedef
struct
SPoolMem
{
typedef
struct
SPoolMem
{
int64_t
size
;
int64_t
size
;
struct
SPoolMem
*
prev
;
struct
SPoolMem
*
prev
;
struct
SPoolMem
*
next
;
struct
SPoolMem
*
next
;
}
SPoolMem
;
}
SPoolMem
;
#define META_TDB_SMA_TEST
static
SPoolMem
*
openPool
();
static
SPoolMem
*
openPool
();
static
void
clearPool
(
SPoolMem
*
pPool
);
static
void
clearPool
(
SPoolMem
*
pPool
);
static
void
closePool
(
SPoolMem
*
pPool
);
static
void
closePool
(
SPoolMem
*
pPool
);
static
void
*
poolMalloc
(
void
*
arg
,
size_t
size
);
static
void
*
poolMalloc
(
void
*
arg
,
size_t
size
);
static
void
poolFree
(
void
*
arg
,
void
*
ptr
);
static
void
poolFree
(
void
*
arg
,
void
*
ptr
);
struct
SMetaDB
{
struct
SMetaDB
{
TXN
txn
;
TXN
txn
;
TENV
*
pEnv
;
TENV
*
pEnv
;
TDB
*
pTbDB
;
TDB
*
pTbDB
;
TDB
*
pSchemaDB
;
TDB
*
pSchemaDB
;
TDB
*
pNameIdx
;
TDB
*
pNameIdx
;
TDB
*
pStbIdx
;
TDB
*
pStbIdx
;
TDB
*
pNtbIdx
;
TDB
*
pNtbIdx
;
TDB
*
pCtbIdx
;
TDB
*
pCtbIdx
;
SPoolMem
*
pPool
;
SPoolMem
*
pPool
;
#ifdef META_TDB_SMA_TEST
TDB
*
pSmaDB
;
TDB
*
pSmaIdx
;
#endif
};
};
typedef
struct
__attribute__
((
__packed__
))
{
typedef
struct
__attribute__
((
__packed__
))
{
...
@@ -46,7 +51,7 @@ typedef struct __attribute__((__packed__)) {
...
@@ -46,7 +51,7 @@ typedef struct __attribute__((__packed__)) {
}
SSchemaDbKey
;
}
SSchemaDbKey
;
typedef
struct
{
typedef
struct
{
char
*
name
;
char
*
name
;
tb_uid_t
uid
;
tb_uid_t
uid
;
}
SNameIdxKey
;
}
SNameIdxKey
;
...
@@ -55,6 +60,11 @@ typedef struct {
...
@@ -55,6 +60,11 @@ typedef struct {
tb_uid_t
uid
;
tb_uid_t
uid
;
}
SCtbIdxKey
;
}
SCtbIdxKey
;
typedef
struct
{
tb_uid_t
uid
;
int64_t
smaUid
;
}
SSmaIdxKey
;
static
int
metaEncodeTbInfo
(
void
**
buf
,
STbCfg
*
pTbCfg
);
static
int
metaEncodeTbInfo
(
void
**
buf
,
STbCfg
*
pTbCfg
);
static
void
*
metaDecodeTbInfo
(
void
*
buf
,
STbCfg
*
pTbCfg
);
static
void
*
metaDecodeTbInfo
(
void
*
buf
,
STbCfg
*
pTbCfg
);
static
int
metaEncodeSchema
(
void
**
buf
,
SSchemaWrapper
*
pSW
);
static
int
metaEncodeSchema
(
void
**
buf
,
SSchemaWrapper
*
pSW
);
...
@@ -115,6 +125,17 @@ static inline int metaCtbIdxCmpr(const void *arg1, int len1, const void *arg2, i
...
@@ -115,6 +125,17 @@ static inline int metaCtbIdxCmpr(const void *arg1, int len1, const void *arg2, i
return
metaUidCmpr
(
&
pKey1
->
uid
,
sizeof
(
tb_uid_t
),
&
pKey2
->
uid
,
sizeof
(
tb_uid_t
));
return
metaUidCmpr
(
&
pKey1
->
uid
,
sizeof
(
tb_uid_t
),
&
pKey2
->
uid
,
sizeof
(
tb_uid_t
));
}
}
static
inline
int
metaSmaIdxCmpr
(
const
void
*
arg1
,
int
len1
,
const
void
*
arg2
,
int
len2
)
{
int
c
;
SSmaIdxKey
*
pKey1
=
(
SSmaIdxKey
*
)
arg1
;
SSmaIdxKey
*
pKey2
=
(
SSmaIdxKey
*
)
arg2
;
c
=
metaUidCmpr
(
arg1
,
sizeof
(
tb_uid_t
),
arg2
,
sizeof
(
tb_uid_t
));
if
(
c
)
return
c
;
return
metaUidCmpr
(
&
pKey1
->
smaUid
,
sizeof
(
int64_t
),
&
pKey2
->
smaUid
,
sizeof
(
int64_t
));
}
int
metaOpenDB
(
SMeta
*
pMeta
)
{
int
metaOpenDB
(
SMeta
*
pMeta
)
{
SMetaDB
*
pMetaDb
;
SMetaDB
*
pMetaDb
;
int
ret
;
int
ret
;
...
@@ -143,6 +164,15 @@ int metaOpenDB(SMeta *pMeta) {
...
@@ -143,6 +164,15 @@ int metaOpenDB(SMeta *pMeta) {
return
-
1
;
return
-
1
;
}
}
#ifdef META_TDB_SMA_TEST
ret
=
tdbDbOpen
(
"sma.db"
,
sizeof
(
int64_t
),
TDB_VARIANT_LEN
,
metaUidCmpr
,
pMetaDb
->
pEnv
,
&
(
pMetaDb
->
pSmaDB
));
if
(
ret
<
0
)
{
// TODO
ASSERT
(
0
);
return
-
1
;
}
#endif
// open schema DB
// open schema DB
ret
=
tdbDbOpen
(
"schema.db"
,
sizeof
(
SSchemaDbKey
),
TDB_VARIANT_LEN
,
metaSchemaKeyCmpr
,
pMetaDb
->
pEnv
,
ret
=
tdbDbOpen
(
"schema.db"
,
sizeof
(
SSchemaDbKey
),
TDB_VARIANT_LEN
,
metaSchemaKeyCmpr
,
pMetaDb
->
pEnv
,
&
(
pMetaDb
->
pSchemaDB
));
&
(
pMetaDb
->
pSchemaDB
));
...
@@ -180,6 +210,15 @@ int metaOpenDB(SMeta *pMeta) {
...
@@ -180,6 +210,15 @@ int metaOpenDB(SMeta *pMeta) {
return
-
1
;
return
-
1
;
}
}
#ifdef META_TDB_SMA_TEST
ret
=
tdbDbOpen
(
"sma.idx"
,
sizeof
(
SSmaIdxKey
),
0
,
metaSmaIdxCmpr
,
pMetaDb
->
pEnv
,
&
(
pMetaDb
->
pSmaIdx
));
if
(
ret
<
0
)
{
// TODO
ASSERT
(
0
);
return
-
1
;
}
#endif
pMetaDb
->
pPool
=
openPool
();
pMetaDb
->
pPool
=
openPool
();
tdbTxnOpen
(
&
pMetaDb
->
txn
,
0
,
poolMalloc
,
poolFree
,
pMetaDb
->
pPool
,
TDB_TXN_WRITE
|
TDB_TXN_READ_UNCOMMITTED
);
tdbTxnOpen
(
&
pMetaDb
->
txn
,
0
,
poolMalloc
,
poolFree
,
pMetaDb
->
pPool
,
TDB_TXN_WRITE
|
TDB_TXN_READ_UNCOMMITTED
);
tdbBegin
(
pMetaDb
->
pEnv
,
NULL
);
tdbBegin
(
pMetaDb
->
pEnv
,
NULL
);
...
@@ -193,10 +232,16 @@ void metaCloseDB(SMeta *pMeta) {
...
@@ -193,10 +232,16 @@ void metaCloseDB(SMeta *pMeta) {
tdbCommit
(
pMeta
->
pDB
->
pEnv
,
&
pMeta
->
pDB
->
txn
);
tdbCommit
(
pMeta
->
pDB
->
pEnv
,
&
pMeta
->
pDB
->
txn
);
tdbTxnClose
(
&
pMeta
->
pDB
->
txn
);
tdbTxnClose
(
&
pMeta
->
pDB
->
txn
);
clearPool
(
pMeta
->
pDB
->
pPool
);
clearPool
(
pMeta
->
pDB
->
pPool
);
#ifdef META_TDB_SMA_TEST
tdbDbClose
(
pMeta
->
pDB
->
pSmaIdx
);
#endif
tdbDbClose
(
pMeta
->
pDB
->
pCtbIdx
);
tdbDbClose
(
pMeta
->
pDB
->
pCtbIdx
);
tdbDbClose
(
pMeta
->
pDB
->
pNtbIdx
);
tdbDbClose
(
pMeta
->
pDB
->
pNtbIdx
);
tdbDbClose
(
pMeta
->
pDB
->
pStbIdx
);
tdbDbClose
(
pMeta
->
pDB
->
pStbIdx
);
tdbDbClose
(
pMeta
->
pDB
->
pNameIdx
);
tdbDbClose
(
pMeta
->
pDB
->
pNameIdx
);
#ifdef META_TDB_SMA_TEST
tdbDbClose
(
pMeta
->
pDB
->
pSmaDB
);
#endif
tdbDbClose
(
pMeta
->
pDB
->
pSchemaDB
);
tdbDbClose
(
pMeta
->
pDB
->
pSchemaDB
);
tdbDbClose
(
pMeta
->
pDB
->
pTbDB
);
tdbDbClose
(
pMeta
->
pDB
->
pTbDB
);
taosMemoryFree
(
pMeta
->
pDB
);
taosMemoryFree
(
pMeta
->
pDB
);
...
@@ -205,14 +250,14 @@ void metaCloseDB(SMeta *pMeta) {
...
@@ -205,14 +250,14 @@ void metaCloseDB(SMeta *pMeta) {
int
metaSaveTableToDB
(
SMeta
*
pMeta
,
STbCfg
*
pTbCfg
)
{
int
metaSaveTableToDB
(
SMeta
*
pMeta
,
STbCfg
*
pTbCfg
)
{
tb_uid_t
uid
;
tb_uid_t
uid
;
SMetaDB
*
pMetaDb
;
SMetaDB
*
pMetaDb
;
void
*
pKey
;
void
*
pKey
;
void
*
pVal
;
void
*
pVal
;
int
kLen
;
int
kLen
;
int
vLen
;
int
vLen
;
int
ret
;
int
ret
;
char
buf
[
512
];
char
buf
[
512
];
void
*
pBuf
;
void
*
pBuf
;
SCtbIdxKey
ctbIdxKey
;
SCtbIdxKey
ctbIdxKey
;
SSchemaDbKey
schemaDbKey
;
SSchemaDbKey
schemaDbKey
;
SSchemaWrapper
schemaWrapper
;
SSchemaWrapper
schemaWrapper
;
...
@@ -329,11 +374,11 @@ int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
...
@@ -329,11 +374,11 @@ int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) {
STbCfg
*
metaGetTbInfoByUid
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
STbCfg
*
metaGetTbInfoByUid
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
int
ret
;
int
ret
;
SMetaDB
*
pMetaDb
=
pMeta
->
pDB
;
SMetaDB
*
pMetaDb
=
pMeta
->
pDB
;
void
*
pKey
;
void
*
pKey
;
void
*
pVal
;
void
*
pVal
;
int
kLen
;
int
kLen
;
int
vLen
;
int
vLen
;
STbCfg
*
pTbCfg
;
STbCfg
*
pTbCfg
;
// Fetch
// Fetch
pKey
=
&
uid
;
pKey
=
&
uid
;
...
@@ -385,14 +430,14 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo
...
@@ -385,14 +430,14 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo
}
}
static
SSchemaWrapper
*
metaGetTableSchemaImpl
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int32_t
sver
,
bool
isinline
,
bool
isGetEx
)
{
static
SSchemaWrapper
*
metaGetTableSchemaImpl
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int32_t
sver
,
bool
isinline
,
bool
isGetEx
)
{
void
*
pKey
;
void
*
pKey
;
void
*
pVal
;
void
*
pVal
;
int
kLen
;
int
kLen
;
int
vLen
;
int
vLen
;
int
ret
;
int
ret
;
SSchemaDbKey
schemaDbKey
;
SSchemaDbKey
schemaDbKey
;
SSchemaWrapper
*
pSchemaWrapper
;
SSchemaWrapper
*
pSchemaWrapper
;
void
*
pBuf
;
void
*
pBuf
;
// fetch
// fetch
schemaDbKey
.
uid
=
uid
;
schemaDbKey
.
uid
=
uid
;
...
@@ -419,9 +464,9 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) {
...
@@ -419,9 +464,9 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) {
tb_uid_t
quid
;
tb_uid_t
quid
;
SSchemaWrapper
*
pSW
;
SSchemaWrapper
*
pSW
;
STSchemaBuilder
sb
;
STSchemaBuilder
sb
;
SSchemaEx
*
pSchema
;
SSchemaEx
*
pSchema
;
STSchema
*
pTSchema
;
STSchema
*
pTSchema
;
STbCfg
*
pTbCfg
;
STbCfg
*
pTbCfg
;
pTbCfg
=
metaGetTbInfoByUid
(
pMeta
,
uid
);
pTbCfg
=
metaGetTbInfoByUid
(
pMeta
,
uid
);
if
(
pTbCfg
->
type
==
META_CHILD_TABLE
)
{
if
(
pTbCfg
->
type
==
META_CHILD_TABLE
)
{
...
@@ -452,7 +497,7 @@ struct SMTbCursor {
...
@@ -452,7 +497,7 @@ struct SMTbCursor {
SMTbCursor
*
metaOpenTbCursor
(
SMeta
*
pMeta
)
{
SMTbCursor
*
metaOpenTbCursor
(
SMeta
*
pMeta
)
{
SMTbCursor
*
pTbCur
=
NULL
;
SMTbCursor
*
pTbCur
=
NULL
;
SMetaDB
*
pDB
=
pMeta
->
pDB
;
SMetaDB
*
pDB
=
pMeta
->
pDB
;
pTbCur
=
(
SMTbCursor
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pTbCur
));
pTbCur
=
(
SMTbCursor
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pTbCur
));
if
(
pTbCur
==
NULL
)
{
if
(
pTbCur
==
NULL
)
{
...
@@ -474,12 +519,12 @@ void metaCloseTbCursor(SMTbCursor *pTbCur) {
...
@@ -474,12 +519,12 @@ void metaCloseTbCursor(SMTbCursor *pTbCur) {
}
}
char
*
metaTbCursorNext
(
SMTbCursor
*
pTbCur
)
{
char
*
metaTbCursorNext
(
SMTbCursor
*
pTbCur
)
{
void
*
pKey
=
NULL
;
void
*
pKey
=
NULL
;
void
*
pVal
=
NULL
;
void
*
pVal
=
NULL
;
int
kLen
;
int
kLen
;
int
vLen
;
int
vLen
;
int
ret
;
int
ret
;
void
*
pBuf
;
void
*
pBuf
;
STbCfg
tbCfg
;
STbCfg
tbCfg
;
for
(;;)
{
for
(;;)
{
...
@@ -491,7 +536,6 @@ char *metaTbCursorNext(SMTbCursor *pTbCur) {
...
@@ -491,7 +536,6 @@ char *metaTbCursorNext(SMTbCursor *pTbCur) {
taosMemoryFree
(
tbCfg
.
name
);
taosMemoryFree
(
tbCfg
.
name
);
taosMemoryFree
(
tbCfg
.
stbCfg
.
pTagSchema
);
taosMemoryFree
(
tbCfg
.
stbCfg
.
pTagSchema
);
continue
;
continue
;
;
}
else
if
(
tbCfg
.
type
==
META_CHILD_TABLE
)
{
}
else
if
(
tbCfg
.
type
==
META_CHILD_TABLE
)
{
kvRowFree
(
tbCfg
.
ctbCfg
.
pTag
);
kvRowFree
(
tbCfg
.
ctbCfg
.
pTag
);
}
}
...
@@ -503,17 +547,17 @@ char *metaTbCursorNext(SMTbCursor *pTbCur) {
...
@@ -503,17 +547,17 @@ char *metaTbCursorNext(SMTbCursor *pTbCur) {
}
}
struct
SMCtbCursor
{
struct
SMCtbCursor
{
TDBC
*
pCur
;
TDBC
*
pCur
;
tb_uid_t
suid
;
tb_uid_t
suid
;
void
*
pKey
;
void
*
pKey
;
void
*
pVal
;
void
*
pVal
;
int
kLen
;
int
kLen
;
int
vLen
;
int
vLen
;
};
};
SMCtbCursor
*
metaOpenCtbCursor
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
SMCtbCursor
*
metaOpenCtbCursor
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
SMCtbCursor
*
pCtbCur
=
NULL
;
SMCtbCursor
*
pCtbCur
=
NULL
;
SMetaDB
*
pDB
=
pMeta
->
pDB
;
SMetaDB
*
pDB
=
pMeta
->
pDB
;
int
ret
;
int
ret
;
pCtbCur
=
(
SMCtbCursor
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pCtbCur
));
pCtbCur
=
(
SMCtbCursor
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pCtbCur
));
...
@@ -566,51 +610,325 @@ int metaGetTbNum(SMeta *pMeta) {
...
@@ -566,51 +610,325 @@ int metaGetTbNum(SMeta *pMeta) {
return
0
;
return
0
;
}
}
struct
SMSmaCursor
{
TDBC
*
pCur
;
tb_uid_t
uid
;
void
*
pKey
;
void
*
pVal
;
int
kLen
;
int
vLen
;
};
STSmaWrapper
*
metaGetSmaInfoByTable
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
STSmaWrapper
*
metaGetSmaInfoByTable
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
// TODO
// TODO
ASSERT
(
0
);
// ASSERT(0);
// return NULL;
#ifdef META_TDB_SMA_TEST
STSmaWrapper
*
pSW
=
NULL
;
pSW
=
taosMemoryCalloc
(
1
,
sizeof
(
*
pSW
));
if
(
pSW
==
NULL
)
{
return
NULL
;
}
SMSmaCursor
*
pCur
=
metaOpenSmaCursor
(
pMeta
,
uid
);
if
(
pCur
==
NULL
)
{
taosMemoryFree
(
pSW
);
return
NULL
;
}
void
*
pBuf
=
NULL
;
SSmaIdxKey
*
pSmaIdxKey
=
NULL
;
while
(
true
)
{
// TODO: lock during iterate?
if
(
tdbDbNext
(
pCur
->
pCur
,
&
pCur
->
pKey
,
&
pCur
->
kLen
,
NULL
,
&
pCur
->
vLen
)
==
0
)
{
pSmaIdxKey
=
pCur
->
pKey
;
ASSERT
(
pSmaIdxKey
!=
NULL
);
void
*
pSmaVal
=
metaGetSmaInfoByIndex
(
pMeta
,
pSmaIdxKey
->
smaUid
,
false
);
if
(
pSmaVal
==
NULL
)
{
tsdbWarn
(
"no tsma exists for indexUid: %"
PRIi64
,
pSmaIdxKey
->
smaUid
);
continue
;
}
++
pSW
->
number
;
STSma
*
tptr
=
(
STSma
*
)
taosMemoryRealloc
(
pSW
->
tSma
,
pSW
->
number
*
sizeof
(
STSma
));
if
(
tptr
==
NULL
)
{
TDB_FREE
(
pSmaVal
);
metaCloseSmaCursor
(
pCur
);
tdDestroyTSmaWrapper
(
pSW
);
taosMemoryFreeClear
(
pSW
);
return
NULL
;
}
pSW
->
tSma
=
tptr
;
pBuf
=
pSmaVal
;
if
(
tDecodeTSma
(
pBuf
,
pSW
->
tSma
+
pSW
->
number
-
1
)
==
NULL
)
{
TDB_FREE
(
pSmaVal
);
metaCloseSmaCursor
(
pCur
);
tdDestroyTSmaWrapper
(
pSW
);
taosMemoryFreeClear
(
pSW
);
return
NULL
;
return
NULL
;
}
TDB_FREE
(
pSmaVal
);
continue
;
}
break
;
}
metaCloseSmaCursor
(
pCur
);
return
pSW
;
#endif
}
}
int
metaRemoveSmaFromDb
(
SMeta
*
pMeta
,
int64_t
indexUid
)
{
int
metaRemoveSmaFromDb
(
SMeta
*
pMeta
,
int64_t
indexUid
)
{
// TODO
// TODO
ASSERT
(
0
);
ASSERT
(
0
);
#ifndef META_TDB_SMA_TEST
DBT
key
=
{
0
};
key
.
data
=
(
void
*
)
indexName
;
key
.
size
=
strlen
(
indexName
);
metaDBWLock
(
pMeta
->
pDB
);
// TODO: No guarantee of consistence.
// Use transaction or DB->sync() for some guarantee.
pMeta
->
pDB
->
pSmaDB
->
del
(
pMeta
->
pDB
->
pSmaDB
,
NULL
,
&
key
,
0
);
metaDBULock
(
pMeta
->
pDB
);
#endif
return
0
;
return
0
;
}
}
int
metaSaveSmaToDB
(
SMeta
*
pMeta
,
STSma
*
pSmaCfg
)
{
int
metaSaveSmaToDB
(
SMeta
*
pMeta
,
STSma
*
pSmaCfg
)
{
// TODO
// TODO
ASSERT
(
0
);
// ASSERT(0);
#ifdef META_TDB_SMA_TEST
int32_t
ret
=
0
;
SMetaDB
*
pMetaDb
=
pMeta
->
pDB
;
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
->
pDB
->
pSmaDB
,
key
,
kLen
,
val
,
vLen
,
&
pMetaDb
->
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
->
pDB
->
pSmaIdx
,
key
,
kLen
,
val
,
vLen
,
&
pMetaDb
->
txn
);
if
(
ret
<
0
)
{
taosMemoryFreeClear
(
pBuf
);
return
-
1
;
}
// release
taosMemoryFreeClear
(
pBuf
);
if
(
pMeta
->
pDB
->
pPool
->
size
>
0
)
{
metaCommit
(
pMeta
);
}
#endif
return
0
;
return
0
;
}
}
STSma
*
metaGetSmaInfoByIndex
(
SMeta
*
pMeta
,
int64_t
indexUid
)
{
void
*
metaGetSmaInfoByIndex
(
SMeta
*
pMeta
,
int64_t
indexUid
,
bool
isDecode
)
{
// TODO
// TODO
ASSERT
(
0
);
// ASSERT(0);
// return NULL;
#ifdef META_TDB_SMA_TEST
SMetaDB
*
pDB
=
pMeta
->
pDB
;
void
*
pKey
=
NULL
;
void
*
pVal
=
NULL
;
int
kLen
=
0
;
int
vLen
=
0
;
int
ret
=
-
1
;
// Set key
pKey
=
(
void
*
)
&
indexUid
;
kLen
=
sizeof
(
indexUid
);
// Query
ret
=
tdbDbGet
(
pDB
->
pSmaDB
,
pKey
,
kLen
,
&
pVal
,
&
vLen
);
if
(
ret
!=
0
||
!
pVal
)
{
return
NULL
;
}
if
(
!
isDecode
)
{
// return raw value
return
pVal
;
}
// Decode
STSma
*
pCfg
=
(
STSma
*
)
taosMemoryCalloc
(
1
,
sizeof
(
STSma
));
if
(
pCfg
==
NULL
)
{
taosMemoryFree
(
pVal
);
return
NULL
;
return
NULL
;
}
void
*
pBuf
=
pVal
;
if
(
tDecodeTSma
(
pBuf
,
pCfg
)
==
NULL
)
{
tdDestroyTSma
(
pCfg
);
taosMemoryFree
(
pCfg
);
TDB_FREE
(
pVal
);
return
NULL
;
}
TDB_FREE
(
pVal
);
return
pCfg
;
#endif
}
}
const
char
*
metaSmaCursorNext
(
SMSmaCursor
*
pCur
)
{
/**
* @brief
*
* @param pMeta
* @param uid 0 means iterate all uids.
* @return SMSmaCursor*
*/
SMSmaCursor
*
metaOpenSmaCursor
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
// TODO
// TODO
ASSERT
(
0
);
// ASSERT(0);
// return NULL;
#ifdef META_TDB_SMA_TEST
SMSmaCursor
*
pCur
=
NULL
;
SMetaDB
*
pDB
=
pMeta
->
pDB
;
int
ret
;
pCur
=
(
SMSmaCursor
*
)
taosMemoryCalloc
(
1
,
sizeof
(
*
pCur
));
if
(
pCur
==
NULL
)
{
return
NULL
;
return
NULL
;
}
pCur
->
uid
=
uid
;
ret
=
tdbDbcOpen
(
pDB
->
pSmaIdx
,
&
(
pCur
->
pCur
));
if
((
ret
!=
0
)
||
(
pCur
->
pCur
==
NULL
))
{
taosMemoryFree
(
pCur
);
return
NULL
;
}
if
(
uid
!=
0
)
{
// TODO: move to the specific uid
}
return
pCur
;
#endif
}
}
void
metaCloseSmaCurosr
(
SMSmaCursor
*
pCur
)
{
/**
* @brief
*
* @param pCur
* @return int64_t smaIndexUid
*/
int64_t
metaSmaCursorNext
(
SMSmaCursor
*
pCur
)
{
// TODO
// TODO
ASSERT
(
0
);
// ASSERT(0);
// return NULL;
#ifdef META_TDB_SMA_TEST
int
ret
;
void
*
pBuf
;
SSmaIdxKey
*
smaIdxKey
;
ret
=
tdbDbNext
(
pCur
->
pCur
,
&
pCur
->
pKey
,
&
pCur
->
kLen
,
&
pCur
->
pVal
,
&
pCur
->
vLen
);
if
(
ret
<
0
)
{
return
0
;
}
smaIdxKey
=
pCur
->
pKey
;
return
smaIdxKey
->
smaUid
;
#endif
}
void
metaCloseSmaCursor
(
SMSmaCursor
*
pCur
)
{
// TODO
// ASSERT(0);
#ifdef META_TDB_SMA_TEST
if
(
pCur
)
{
if
(
pCur
->
pCur
)
{
tdbDbcClose
(
pCur
->
pCur
);
}
taosMemoryFree
(
pCur
);
}
#endif
}
}
SArray
*
metaGetSmaTbUids
(
SMeta
*
pMeta
,
bool
isDup
)
{
SArray
*
metaGetSmaTbUids
(
SMeta
*
pMeta
,
bool
isDup
)
{
// TODO
// TODO
// ASSERT(0); // comment this line to pass CI
// ASSERT(0); // comment this line to pass CI
// return NULL:
#ifdef META_TDB_SMA_TEST
SArray
*
pUids
=
NULL
;
SMetaDB
*
pDB
=
pMeta
->
pDB
;
void
*
pKey
;
// TODO: lock?
SMSmaCursor
*
pCur
=
metaOpenSmaCursor
(
pMeta
,
0
);
if
(
pCur
==
NULL
)
{
return
NULL
;
return
NULL
;
}
}
// TODO: lock?
SMSmaCursor
*
metaOpenSmaCursor
(
SMeta
*
pMeta
,
tb_uid_t
uid
)
{
SSmaIdxKey
*
pSmaIdxKey
=
NULL
;
// TODO
tb_uid_t
uid
=
0
;
ASSERT
(
0
);
while
(
true
)
{
// TODO: lock during iterate?
if
(
tdbDbNext
(
pCur
->
pCur
,
&
pCur
->
pKey
,
&
pCur
->
kLen
,
NULL
,
&
pCur
->
vLen
)
==
0
)
{
ASSERT
(
pSmaIdxKey
!=
NULL
);
pSmaIdxKey
=
pCur
->
pKey
;
if
(
pSmaIdxKey
->
uid
==
0
||
pSmaIdxKey
->
uid
==
uid
)
{
continue
;
}
uid
=
pSmaIdxKey
->
uid
;
if
(
!
pUids
)
{
pUids
=
taosArrayInit
(
16
,
sizeof
(
tb_uid_t
));
if
(
!
pUids
)
{
metaCloseSmaCursor
(
pCur
);
return
NULL
;
return
NULL
;
}
}
taosArrayPush
(
pUids
,
&
uid
);
continue
;
}
break
;
}
metaCloseSmaCursor
(
pCur
);
return
pUids
;
#endif
}
}
static
int
metaEncodeSchema
(
void
**
buf
,
SSchemaWrapper
*
pSW
)
{
static
int
metaEncodeSchema
(
void
**
buf
,
SSchemaWrapper
*
pSW
)
{
...
@@ -783,7 +1101,7 @@ static void closePool(SPoolMem *pPool) {
...
@@ -783,7 +1101,7 @@ static void closePool(SPoolMem *pPool) {
}
}
static
void
*
poolMalloc
(
void
*
arg
,
size_t
size
)
{
static
void
*
poolMalloc
(
void
*
arg
,
size_t
size
)
{
void
*
ptr
=
NULL
;
void
*
ptr
=
NULL
;
SPoolMem
*
pPool
=
(
SPoolMem
*
)
arg
;
SPoolMem
*
pPool
=
(
SPoolMem
*
)
arg
;
SPoolMem
*
pMem
;
SPoolMem
*
pMem
;
...
...
source/dnode/vnode/src/meta/metaTbCfg.c
浏览文件 @
3a26ec4e
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
*/
*/
#include "vnodeInt.h"
#include "vnodeInt.h"
#include "tcoding.h"
int
metaValidateTbCfg
(
SMeta
*
pMeta
,
const
STbCfg
*
pTbOptions
)
{
int
metaValidateTbCfg
(
SMeta
*
pMeta
,
const
STbCfg
*
pTbOptions
)
{
// TODO
// TODO
...
...
source/dnode/vnode/src/meta/metaTbTag.c
浏览文件 @
3a26ec4e
...
@@ -12,3 +12,5 @@
...
@@ -12,3 +12,5 @@
* You should have received a copy of the GNU Affero General Public License
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "vnodeInt.h"
\ No newline at end of file
source/dnode/vnode/src/tq/tq.c
浏览文件 @
3a26ec4e
...
@@ -13,9 +13,6 @@
...
@@ -13,9 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "tcompare.h"
#include "tdatablock.h"
#include "tstream.h"
#include "vnodeInt.h"
#include "vnodeInt.h"
int32_t
tqInit
()
{
return
tqPushMgrInit
();
}
int32_t
tqInit
()
{
return
tqPushMgrInit
();
}
...
@@ -82,9 +79,9 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t versi
...
@@ -82,9 +79,9 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t versi
memcpy
(
data
,
msg
,
msgLen
);
memcpy
(
data
,
msg
,
msgLen
);
if
(
msgType
==
TDMT_VND_SUBMIT
)
{
if
(
msgType
==
TDMT_VND_SUBMIT
)
{
// if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg
) != 0) {
if
(
tsdbUpdateSmaWindow
(
pTq
->
pVnode
->
pTsdb
,
msg
,
version
)
!=
0
)
{
//
return -1;
return
-
1
;
//
}
}
}
}
SRpcMsg
req
=
{
SRpcMsg
req
=
{
...
@@ -255,7 +252,7 @@ int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsu
...
@@ -255,7 +252,7 @@ int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsu
return
0
;
return
0
;
}
}
#if 0
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
SMqPollReq* pReq = pMsg->pCont;
SMqPollReq* pReq = pMsg->pCont;
int64_t consumerId = pReq->consumerId;
int64_t consumerId = pReq->consumerId;
...
@@ -433,6 +430,215 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
...
@@ -433,6 +430,215 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
return 0;
return 0;
}
}
#endif
int32_t
tqProcessPollReq
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
,
int32_t
workerId
)
{
SMqPollReq
*
pReq
=
pMsg
->
pCont
;
int64_t
consumerId
=
pReq
->
consumerId
;
int64_t
fetchOffset
;
int64_t
blockingTime
=
pReq
->
blockingTime
;
int32_t
reqEpoch
=
pReq
->
epoch
;
if
(
pReq
->
currentOffset
==
TMQ_CONF__RESET_OFFSET__EARLIEAST
)
{
fetchOffset
=
0
;
}
else
if
(
pReq
->
currentOffset
==
TMQ_CONF__RESET_OFFSET__LATEST
)
{
fetchOffset
=
walGetLastVer
(
pTq
->
pWal
);
}
else
{
fetchOffset
=
pReq
->
currentOffset
+
1
;
}
vDebug
(
"tmq poll: consumer %ld (epoch %d) recv poll req in vg %d, req %ld %ld"
,
consumerId
,
pReq
->
epoch
,
pTq
->
pVnode
->
vgId
,
pReq
->
currentOffset
,
fetchOffset
);
SMqPollRspV2
rspV2
=
{
0
};
rspV2
.
dataLen
=
0
;
STqConsumer
*
pConsumer
=
tqHandleGet
(
pTq
->
tqMeta
,
consumerId
);
if
(
pConsumer
==
NULL
)
{
vWarn
(
"tmq poll: consumer %ld (epoch %d) not found in vg %d"
,
consumerId
,
pReq
->
epoch
,
pTq
->
pVnode
->
vgId
);
pMsg
->
pCont
=
NULL
;
pMsg
->
contLen
=
0
;
pMsg
->
code
=
-
1
;
tmsgSendRsp
(
pMsg
);
return
0
;
}
int32_t
consumerEpoch
=
atomic_load_32
(
&
pConsumer
->
epoch
);
while
(
consumerEpoch
<
reqEpoch
)
{
consumerEpoch
=
atomic_val_compare_exchange_32
(
&
pConsumer
->
epoch
,
consumerEpoch
,
reqEpoch
);
}
STqTopic
*
pTopic
=
NULL
;
int32_t
topicSz
=
taosArrayGetSize
(
pConsumer
->
topics
);
for
(
int32_t
i
=
0
;
i
<
topicSz
;
i
++
)
{
STqTopic
*
topic
=
taosArrayGet
(
pConsumer
->
topics
,
i
);
// TODO race condition
ASSERT
(
pConsumer
->
consumerId
==
consumerId
);
if
(
strcmp
(
topic
->
topicName
,
pReq
->
topic
)
==
0
)
{
pTopic
=
topic
;
break
;
}
}
if
(
pTopic
==
NULL
)
{
vWarn
(
"tmq poll: consumer %ld (epoch %d) topic %s not found in vg %d"
,
consumerId
,
pReq
->
epoch
,
pReq
->
topic
,
pTq
->
pVnode
->
vgId
);
pMsg
->
pCont
=
NULL
;
pMsg
->
contLen
=
0
;
pMsg
->
code
=
-
1
;
tmsgSendRsp
(
pMsg
);
return
0
;
}
vDebug
(
"poll topic %s from consumer %ld (epoch %d) vg %d"
,
pTopic
->
topicName
,
consumerId
,
pReq
->
epoch
,
pTq
->
pVnode
->
vgId
);
rspV2
.
reqOffset
=
pReq
->
currentOffset
;
rspV2
.
skipLogNum
=
0
;
while
(
1
)
{
/*if (fetchOffset > walGetLastVer(pTq->pWal) || walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {*/
// TODO
consumerEpoch
=
atomic_load_32
(
&
pConsumer
->
epoch
);
if
(
consumerEpoch
>
reqEpoch
)
{
vDebug
(
"tmq poll: consumer %ld (epoch %d) vg %d offset %ld, found new consumer epoch %d discard req epoch %d"
,
consumerId
,
pReq
->
epoch
,
pTq
->
pVnode
->
vgId
,
fetchOffset
,
consumerEpoch
,
reqEpoch
);
break
;
}
SWalReadHead
*
pHead
;
if
(
walReadWithHandle_s
(
pTopic
->
pReadhandle
,
fetchOffset
,
&
pHead
)
<
0
)
{
// TODO: no more log, set timer to wait blocking time
// if data inserted during waiting, launch query and
// response to user
vDebug
(
"tmq poll: consumer %ld (epoch %d) vg %d offset %ld, no more log to return"
,
consumerId
,
pReq
->
epoch
,
pTq
->
pVnode
->
vgId
,
fetchOffset
);
break
;
}
vDebug
(
"tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d"
,
consumerId
,
pReq
->
epoch
,
pTq
->
pVnode
->
vgId
,
fetchOffset
,
pHead
->
msgType
);
/*int8_t pos = fetchOffset % TQ_BUFFER_SIZE;*/
/*pHead = pTopic->pReadhandle->pHead;*/
if
(
pHead
->
msgType
==
TDMT_VND_SUBMIT
)
{
SSubmitReq
*
pCont
=
(
SSubmitReq
*
)
&
pHead
->
body
;
qTaskInfo_t
task
=
pTopic
->
buffer
.
output
[
workerId
].
task
;
ASSERT
(
task
);
qSetStreamInput
(
task
,
pCont
,
STREAM_DATA_TYPE_SUBMIT_BLOCK
);
SArray
*
pRes
=
taosArrayInit
(
0
,
sizeof
(
SSDataBlock
));
while
(
1
)
{
SSDataBlock
*
pDataBlock
=
NULL
;
uint64_t
ts
;
if
(
qExecTask
(
task
,
&
pDataBlock
,
&
ts
)
<
0
)
{
ASSERT
(
false
);
}
if
(
pDataBlock
==
NULL
)
{
/*pos = fetchOffset % TQ_BUFFER_SIZE;*/
break
;
}
taosArrayPush
(
pRes
,
pDataBlock
);
}
if
(
taosArrayGetSize
(
pRes
)
==
0
)
{
vDebug
(
"tmq poll: consumer %ld (epoch %d) iter log, vg %d skip log %ld since not wanted"
,
consumerId
,
pReq
->
epoch
,
pTq
->
pVnode
->
vgId
,
fetchOffset
);
fetchOffset
++
;
rspV2
.
skipLogNum
++
;
taosArrayDestroy
(
pRes
);
continue
;
}
rspV2
.
rspOffset
=
fetchOffset
;
int32_t
blockSz
=
taosArrayGetSize
(
pRes
);
int32_t
dataBlockStrLen
=
0
;
for
(
int32_t
i
=
0
;
i
<
blockSz
;
i
++
)
{
SSDataBlock
*
pBlock
=
taosArrayGet
(
pRes
,
i
);
dataBlockStrLen
+=
sizeof
(
SRetrieveTableRsp
)
+
blockGetEncodeSize
(
pBlock
);
}
void
*
dataBlockBuf
=
taosMemoryMalloc
(
dataBlockStrLen
);
if
(
dataBlockBuf
==
NULL
)
{
pMsg
->
code
=
-
1
;
taosMemoryFree
(
pHead
);
}
rspV2
.
blockData
=
dataBlockBuf
;
int32_t
pos
;
rspV2
.
blockPos
=
taosArrayInit
(
blockSz
,
sizeof
(
int32_t
));
for
(
int32_t
i
=
0
;
i
<
blockSz
;
i
++
)
{
pos
=
0
;
SSDataBlock
*
pBlock
=
taosArrayGet
(
pRes
,
i
);
SRetrieveTableRsp
*
pRetrieve
=
(
SRetrieveTableRsp
*
)
dataBlockBuf
;
pRetrieve
->
useconds
=
0
;
pRetrieve
->
precision
=
0
;
pRetrieve
->
compressed
=
0
;
pRetrieve
->
completed
=
1
;
pRetrieve
->
numOfRows
=
htonl
(
pBlock
->
info
.
rows
);
blockCompressEncode
(
pBlock
,
pRetrieve
->
data
,
&
pos
,
pBlock
->
info
.
numOfCols
,
false
);
taosArrayPush
(
rspV2
.
blockPos
,
&
rspV2
.
dataLen
);
int32_t
totLen
=
sizeof
(
SRetrieveTableRsp
)
+
pos
;
pRetrieve
->
compLen
=
htonl
(
totLen
);
rspV2
.
dataLen
+=
totLen
;
dataBlockBuf
=
POINTER_SHIFT
(
dataBlockBuf
,
totLen
);
}
ASSERT
(
POINTER_DISTANCE
(
dataBlockBuf
,
rspV2
.
blockData
)
<=
dataBlockStrLen
);
int32_t
msgLen
=
sizeof
(
SMqRspHead
)
+
tEncodeSMqPollRspV2
(
NULL
,
&
rspV2
);
void
*
buf
=
rpcMallocCont
(
msgLen
);
((
SMqRspHead
*
)
buf
)
->
mqMsgType
=
TMQ_MSG_TYPE__POLL_RSP
;
((
SMqRspHead
*
)
buf
)
->
epoch
=
pReq
->
epoch
;
((
SMqRspHead
*
)
buf
)
->
consumerId
=
consumerId
;
void
*
msgBodyBuf
=
POINTER_SHIFT
(
buf
,
sizeof
(
SMqRspHead
));
tEncodeSMqPollRspV2
(
&
msgBodyBuf
,
&
rspV2
);
/*rsp.pBlockData = pRes;*/
/*taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);*/
pMsg
->
pCont
=
buf
;
pMsg
->
contLen
=
msgLen
;
pMsg
->
code
=
0
;
vDebug
(
"vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp"
,
pTq
->
pVnode
->
vgId
,
fetchOffset
,
pHead
->
msgType
,
consumerId
,
pReq
->
epoch
);
tmsgSendRsp
(
pMsg
);
taosMemoryFree
(
pHead
);
return
0
;
}
else
{
taosMemoryFree
(
pHead
);
fetchOffset
++
;
rspV2
.
skipLogNum
++
;
}
}
/*if (blockingTime != 0) {*/
/*tqAddClientPusher(pTq->tqPushMgr, pMsg, consumerId, blockingTime);*/
/*} else {*/
rspV2
.
rspOffset
=
fetchOffset
-
1
;
int32_t
tlen
=
sizeof
(
SMqRspHead
)
+
tEncodeSMqPollRspV2
(
NULL
,
&
rspV2
);
void
*
buf
=
rpcMallocCont
(
tlen
);
if
(
buf
==
NULL
)
{
pMsg
->
code
=
-
1
;
return
-
1
;
}
((
SMqRspHead
*
)
buf
)
->
mqMsgType
=
TMQ_MSG_TYPE__POLL_RSP
;
((
SMqRspHead
*
)
buf
)
->
epoch
=
pReq
->
epoch
;
((
SMqRspHead
*
)
buf
)
->
consumerId
=
consumerId
;
void
*
abuf
=
POINTER_SHIFT
(
buf
,
sizeof
(
SMqRspHead
));
tEncodeSMqPollRspV2
(
&
abuf
,
&
rspV2
);
pMsg
->
pCont
=
buf
;
pMsg
->
contLen
=
tlen
;
pMsg
->
code
=
0
;
tmsgSendRsp
(
pMsg
);
vDebug
(
"vg %d offset %ld from consumer %ld (epoch %d) not rsp"
,
pTq
->
pVnode
->
vgId
,
fetchOffset
,
consumerId
,
pReq
->
epoch
);
/*}*/
return
0
;
}
int32_t
tqProcessRebReq
(
STQ
*
pTq
,
char
*
msg
)
{
int32_t
tqProcessRebReq
(
STQ
*
pTq
,
char
*
msg
)
{
SMqMVRebReq
req
=
{
0
};
SMqMVRebReq
req
=
{
0
};
...
...
source/dnode/vnode/src/tq/tqCommit.c
浏览文件 @
3a26ec4e
...
@@ -12,3 +12,5 @@
...
@@ -12,3 +12,5 @@
* You should have received a copy of the GNU Affero General Public License
* 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/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "vnodeInt.h"
source/dnode/vnode/src/tq/tqMetaStore.c
浏览文件 @
3a26ec4e
...
@@ -14,10 +14,10 @@
...
@@ -14,10 +14,10 @@
*/
*/
#include "vnodeInt.h"
#include "vnodeInt.h"
// TODO:replace by an abstract file layer
// TODO:replace by an abstract file layer
#include <fcntl.h>
//
#include <fcntl.h>
#include <string.h>
//
#include <string.h>
#include <unistd.h>
//
#include <unistd.h>
#include "osDir.h"
//
#include "osDir.h"
#define TQ_META_NAME "tq.meta"
#define TQ_META_NAME "tq.meta"
#define TQ_IDX_NAME "tq.idx"
#define TQ_IDX_NAME "tq.idx"
...
...
source/dnode/vnode/src/tq/tqRead.c
浏览文件 @
3a26ec4e
...
@@ -13,8 +13,7 @@
...
@@ -13,8 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "tdatablock.h"
#include "vnodeInt.h"
#include "vnode.h"
STqReadHandle
*
tqInitSubmitMsgScanner
(
SMeta
*
pMeta
)
{
STqReadHandle
*
tqInitSubmitMsgScanner
(
SMeta
*
pMeta
)
{
STqReadHandle
*
pReadHandle
=
taosMemoryMalloc
(
sizeof
(
STqReadHandle
));
STqReadHandle
*
pReadHandle
=
taosMemoryMalloc
(
sizeof
(
STqReadHandle
));
...
@@ -88,7 +87,7 @@ int tqRetrieveDataBlockInfo(STqReadHandle* pHandle, SDataBlockInfo* pBlockInfo)
...
@@ -88,7 +87,7 @@ int tqRetrieveDataBlockInfo(STqReadHandle* pHandle, SDataBlockInfo* pBlockInfo)
pBlockInfo
->
numOfCols
=
taosArrayGetSize
(
pHandle
->
pColIdList
);
pBlockInfo
->
numOfCols
=
taosArrayGetSize
(
pHandle
->
pColIdList
);
pBlockInfo
->
rows
=
pHandle
->
pBlock
->
numOfRows
;
pBlockInfo
->
rows
=
pHandle
->
pBlock
->
numOfRows
;
// pBlockInfo->uid = pHandle->pBlock->uid; // the uid can not be assigned to pBlockData.
// pBlockInfo->uid = pHandle->pBlock->uid; // the uid can not be assigned to pBlockData.
return
0
;
return
0
;
}
}
...
@@ -177,3 +176,41 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
...
@@ -177,3 +176,41 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
}
}
return
pArray
;
return
pArray
;
}
}
void
tqReadHandleSetColIdList
(
STqReadHandle
*
pReadHandle
,
SArray
*
pColIdList
)
{
pReadHandle
->
pColIdList
=
pColIdList
;
}
int
tqReadHandleSetTbUidList
(
STqReadHandle
*
pHandle
,
const
SArray
*
tbUidList
)
{
if
(
pHandle
->
tbIdHash
)
{
taosHashClear
(
pHandle
->
tbIdHash
);
}
pHandle
->
tbIdHash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
HASH_NO_LOCK
);
if
(
pHandle
->
tbIdHash
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
tbUidList
);
i
++
)
{
int64_t
*
pKey
=
(
int64_t
*
)
taosArrayGet
(
tbUidList
,
i
);
taosHashPut
(
pHandle
->
tbIdHash
,
pKey
,
sizeof
(
int64_t
),
NULL
,
0
);
}
return
0
;
}
int
tqReadHandleAddTbUidList
(
STqReadHandle
*
pHandle
,
const
SArray
*
tbUidList
)
{
if
(
pHandle
->
tbIdHash
==
NULL
)
{
pHandle
->
tbIdHash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
HASH_NO_LOCK
);
if
(
pHandle
->
tbIdHash
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
}
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
tbUidList
);
i
++
)
{
int64_t
*
pKey
=
(
int64_t
*
)
taosArrayGet
(
tbUidList
,
i
);
taosHashPut
(
pHandle
->
tbIdHash
,
pKey
,
sizeof
(
int64_t
),
NULL
,
0
);
}
return
0
;
}
source/dnode/vnode/src/tsdb/tsdbBDBImpl.c
浏览文件 @
3a26ec4e
...
@@ -16,9 +16,7 @@
...
@@ -16,9 +16,7 @@
#define ALLOW_FORBID_FUNC
#define ALLOW_FORBID_FUNC
#include "db.h"
#include "db.h"
#include "taoserror.h"
#include "vnodeInt.h"
#include "tcoding.h"
#include "thash.h"
#define IMPL_WITH_LOCK 1
#define IMPL_WITH_LOCK 1
...
@@ -139,7 +137,7 @@ int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *key, uint32_t keySize, void *data,
...
@@ -139,7 +137,7 @@ int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *key, uint32_t keySize, void *data,
return
0
;
return
0
;
}
}
void
*
tsdbGetSmaDataByKey
(
SDBFile
*
pDBF
,
void
*
key
,
uint32_t
keySize
,
uint32_t
*
valueSize
)
{
void
*
tsdbGetSmaDataByKey
(
SDBFile
*
pDBF
,
void
*
key
,
uint32_t
keySize
,
uint32_t
*
valueSize
)
{
void
*
result
=
NULL
;
void
*
result
=
NULL
;
DBT
key1
=
{
0
};
DBT
key1
=
{
0
};
DBT
value1
=
{
0
};
DBT
value1
=
{
0
};
...
...
source/dnode/vnode/src/tsdb/tsdbFS.c
浏览文件 @
3a26ec4e
...
@@ -13,9 +13,7 @@
...
@@ -13,9 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include <regex.h>
#include "vnodeInt.h"
#include "vnodeInt.h"
#include "os.h"
typedef
enum
{
TSDB_TXN_TEMP_FILE
=
0
,
TSDB_TXN_CURR_FILE
}
TSDB_TXN_FILE_T
;
typedef
enum
{
TSDB_TXN_TEMP_FILE
=
0
,
TSDB_TXN_CURR_FILE
}
TSDB_TXN_FILE_T
;
static
const
char
*
tsdbTxnFname
[]
=
{
"current.t"
,
"current"
};
static
const
char
*
tsdbTxnFname
[]
=
{
"current.t"
,
"current"
};
...
@@ -97,7 +95,7 @@ static int tsdbEncodeDFileSetArray(void **buf, SArray *pArray) {
...
@@ -97,7 +95,7 @@ static int tsdbEncodeDFileSetArray(void **buf, SArray *pArray) {
return
tlen
;
return
tlen
;
}
}
static
void
*
tsdbDecodeDFileSetArray
(
STsdb
*
pRepo
,
void
*
buf
,
SArray
*
pArray
)
{
static
void
*
tsdbDecodeDFileSetArray
(
STsdb
*
pRepo
,
void
*
buf
,
SArray
*
pArray
)
{
uint64_t
nset
=
0
;
uint64_t
nset
=
0
;
taosArrayClear
(
pArray
);
taosArrayClear
(
pArray
);
...
@@ -122,7 +120,7 @@ static int tsdbEncodeFSStatus(void **buf, SFSStatus *pStatus) {
...
@@ -122,7 +120,7 @@ static int tsdbEncodeFSStatus(void **buf, SFSStatus *pStatus) {
return
tlen
;
return
tlen
;
}
}
static
void
*
tsdbDecodeFSStatus
(
STsdb
*
pRepo
,
void
*
buf
,
SFSStatus
*
pStatus
)
{
static
void
*
tsdbDecodeFSStatus
(
STsdb
*
pRepo
,
void
*
buf
,
SFSStatus
*
pStatus
)
{
tsdbResetFSStatus
(
pStatus
);
tsdbResetFSStatus
(
pStatus
);
// pStatus->pmf = &(pStatus->mf);
// pStatus->pmf = &(pStatus->mf);
...
@@ -407,8 +405,8 @@ int tsdbUpdateDFileSet(STsdbFS *pfs, const SDFileSet *pSet) { return tsdbAddDFil
...
@@ -407,8 +405,8 @@ int tsdbUpdateDFileSet(STsdbFS *pfs, const SDFileSet *pSet) { return tsdbAddDFil
static
int
tsdbSaveFSStatus
(
STsdb
*
pRepo
,
SFSStatus
*
pStatus
)
{
static
int
tsdbSaveFSStatus
(
STsdb
*
pRepo
,
SFSStatus
*
pStatus
)
{
SFSHeader
fsheader
;
SFSHeader
fsheader
;
void
*
pBuf
=
NULL
;
void
*
pBuf
=
NULL
;
void
*
ptr
;
void
*
ptr
;
char
hbuf
[
TSDB_FILE_HEAD_SIZE
]
=
"
\0
"
;
char
hbuf
[
TSDB_FILE_HEAD_SIZE
]
=
"
\0
"
;
char
tfname
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
char
tfname
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
char
cfname
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
char
cfname
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
...
@@ -592,7 +590,7 @@ void tsdbFSIterSeek(SFSIter *pIter, int fid) {
...
@@ -592,7 +590,7 @@ void tsdbFSIterSeek(SFSIter *pIter, int fid) {
}
}
SDFileSet
*
tsdbFSIterNext
(
SFSIter
*
pIter
)
{
SDFileSet
*
tsdbFSIterNext
(
SFSIter
*
pIter
)
{
STsdbFS
*
pfs
=
pIter
->
pfs
;
STsdbFS
*
pfs
=
pIter
->
pfs
;
SDFileSet
*
pSet
;
SDFileSet
*
pSet
;
if
(
pIter
->
index
<
0
)
{
if
(
pIter
->
index
<
0
)
{
...
@@ -651,12 +649,12 @@ static void tsdbGetTxnFname(STsdb *pRepo, TSDB_TXN_FILE_T ftype, char fname[]) {
...
@@ -651,12 +649,12 @@ static void tsdbGetTxnFname(STsdb *pRepo, TSDB_TXN_FILE_T ftype, char fname[]) {
}
}
static
int
tsdbOpenFSFromCurrent
(
STsdb
*
pRepo
)
{
static
int
tsdbOpenFSFromCurrent
(
STsdb
*
pRepo
)
{
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
TdFilePtr
pFile
=
NULL
;
TdFilePtr
pFile
=
NULL
;
void
*
buffer
=
NULL
;
void
*
buffer
=
NULL
;
SFSHeader
fsheader
;
SFSHeader
fsheader
;
char
current
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
char
current
[
TSDB_FILENAME_LEN
]
=
"
\0
"
;
void
*
ptr
;
void
*
ptr
;
tsdbGetTxnFname
(
pRepo
,
TSDB_TXN_CURR_FILE
,
current
);
tsdbGetTxnFname
(
pRepo
,
TSDB_TXN_CURR_FILE
,
current
);
...
@@ -746,7 +744,7 @@ _err:
...
@@ -746,7 +744,7 @@ _err:
// Scan and try to fix incorrect files
// Scan and try to fix incorrect files
static
int
tsdbScanAndTryFixFS
(
STsdb
*
pRepo
)
{
static
int
tsdbScanAndTryFixFS
(
STsdb
*
pRepo
)
{
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
SFSStatus
*
pStatus
=
pfs
->
cstatus
;
SFSStatus
*
pStatus
=
pfs
->
cstatus
;
// if (tsdbScanAndTryFixMFile(pRepo) < 0) {
// if (tsdbScanAndTryFixMFile(pRepo) < 0) {
...
@@ -910,7 +908,7 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) {
...
@@ -910,7 +908,7 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) {
static
int
tsdbScanRootDir
(
STsdb
*
pRepo
)
{
static
int
tsdbScanRootDir
(
STsdb
*
pRepo
)
{
char
rootDir
[
TSDB_FILENAME_LEN
];
char
rootDir
[
TSDB_FILENAME_LEN
];
char
bname
[
TSDB_FILENAME_LEN
];
char
bname
[
TSDB_FILENAME_LEN
];
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
const
STfsFile
*
pf
;
const
STfsFile
*
pf
;
tsdbGetRootDir
(
REPO_ID
(
pRepo
),
rootDir
);
tsdbGetRootDir
(
REPO_ID
(
pRepo
),
rootDir
);
...
@@ -944,7 +942,7 @@ static int tsdbScanRootDir(STsdb *pRepo) {
...
@@ -944,7 +942,7 @@ static int tsdbScanRootDir(STsdb *pRepo) {
static
int
tsdbScanDataDir
(
STsdb
*
pRepo
)
{
static
int
tsdbScanDataDir
(
STsdb
*
pRepo
)
{
char
dataDir
[
TSDB_FILENAME_LEN
];
char
dataDir
[
TSDB_FILENAME_LEN
];
char
bname
[
TSDB_FILENAME_LEN
];
char
bname
[
TSDB_FILENAME_LEN
];
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
const
STfsFile
*
pf
;
const
STfsFile
*
pf
;
tsdbGetDataDir
(
REPO_ID
(
pRepo
),
dataDir
);
tsdbGetDataDir
(
REPO_ID
(
pRepo
),
dataDir
);
...
@@ -1109,12 +1107,12 @@ static bool tsdbIsTFileInFS(STsdbFS *pfs, const STfsFile *pf) {
...
@@ -1109,12 +1107,12 @@ static bool tsdbIsTFileInFS(STsdbFS *pfs, const STfsFile *pf) {
static
int
tsdbRestoreDFileSet
(
STsdb
*
pRepo
)
{
static
int
tsdbRestoreDFileSet
(
STsdb
*
pRepo
)
{
char
dataDir
[
TSDB_FILENAME_LEN
];
char
dataDir
[
TSDB_FILENAME_LEN
];
char
bname
[
TSDB_FILENAME_LEN
];
char
bname
[
TSDB_FILENAME_LEN
];
STfsDir
*
tdir
=
NULL
;
STfsDir
*
tdir
=
NULL
;
const
STfsFile
*
pf
=
NULL
;
const
STfsFile
*
pf
=
NULL
;
const
char
*
pattern
=
"^v[0-9]+f[0-9]+
\\
.(head|data|last|smad|smal)(-ver[0-9]+)?$"
;
const
char
*
pattern
=
"^v[0-9]+f[0-9]+
\\
.(head|data|last|smad|smal)(-ver[0-9]+)?$"
;
SArray
*
fArray
=
NULL
;
SArray
*
fArray
=
NULL
;
regex_t
regex
;
regex_t
regex
;
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
tsdbGetDataDir
(
REPO_ID
(
pRepo
),
dataDir
);
tsdbGetDataDir
(
REPO_ID
(
pRepo
),
dataDir
);
...
@@ -1327,7 +1325,7 @@ static int tsdbComparTFILE(const void *arg1, const void *arg2) {
...
@@ -1327,7 +1325,7 @@ static int tsdbComparTFILE(const void *arg1, const void *arg2) {
}
}
static
void
tsdbScanAndTryFixDFilesHeader
(
STsdb
*
pRepo
,
int32_t
*
nExpired
)
{
static
void
tsdbScanAndTryFixDFilesHeader
(
STsdb
*
pRepo
,
int32_t
*
nExpired
)
{
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
STsdbFS
*
pfs
=
REPO_FS
(
pRepo
);
SFSStatus
*
pStatus
=
pfs
->
cstatus
;
SFSStatus
*
pStatus
=
pfs
->
cstatus
;
SDFInfo
info
;
SDFInfo
info
;
...
...
source/dnode/vnode/src/tsdb/tsdbOptions.c
浏览文件 @
3a26ec4e
...
@@ -26,15 +26,6 @@ const STsdbCfg defautlTsdbOptions = {.precision = 0,
...
@@ -26,15 +26,6 @@ const STsdbCfg defautlTsdbOptions = {.precision = 0,
.
update
=
0
,
.
update
=
0
,
.
compression
=
TWO_STAGE_COMP
};
.
compression
=
TWO_STAGE_COMP
};
int
tsdbOptionsInit
(
STsdbCfg
*
pTsdbOptions
)
{
// TODO
return
0
;
}
void
tsdbOptionsClear
(
STsdbCfg
*
pTsdbOptions
)
{
// TODO
}
int
tsdbValidateOptions
(
const
STsdbCfg
*
pTsdbOptions
)
{
int
tsdbValidateOptions
(
const
STsdbCfg
*
pTsdbOptions
)
{
// TODO
// TODO
return
0
;
return
0
;
...
...
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
3a26ec4e
...
@@ -13,18 +13,6 @@
...
@@ -13,18 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "os.h"
#include "talgo.h"
#include "tcompare.h"
#include "tdatablock.h"
#include "tdataformat.h"
#include "texception.h"
#include "vnodeInt.h"
#include "filter.h"
#include "taosdef.h"
#include "tlosertree.h"
#include "tmsg.h"
#include "vnodeInt.h"
#include "vnodeInt.h"
#define EXTRA_BYTES 2
#define EXTRA_BYTES 2
...
...
source/dnode/vnode/src/tsdb/tsdbSma.c
浏览文件 @
3a26ec4e
...
@@ -38,6 +38,29 @@ typedef enum {
...
@@ -38,6 +38,29 @@ typedef enum {
SMA_STORAGE_LEVEL_DFILESET
=
1
// use days of TS data e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f1906.tsma
SMA_STORAGE_LEVEL_DFILESET
=
1
// use days of TS data e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f1906.tsma
}
ESmaStorageLevel
;
}
ESmaStorageLevel
;
typedef
struct
SPoolMem
{
int64_t
size
;
struct
SPoolMem
*
prev
;
struct
SPoolMem
*
next
;
}
SPoolMem
;
struct
SSmaEnv
{
TdThreadRwlock
lock
;
TXN
txn
;
SPoolMem
*
pPool
;
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_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)
typedef
struct
{
typedef
struct
{
STsdb
*
pTsdb
;
STsdb
*
pTsdb
;
SDBFile
dFile
;
SDBFile
dFile
;
...
@@ -82,8 +105,8 @@ struct SSmaStat {
...
@@ -82,8 +105,8 @@ struct SSmaStat {
// declaration of static functions
// declaration of static functions
// expired window
// expired window
static
int32_t
tsdbUpdateExpiredWindowImpl
(
STsdb
*
pTsdb
,
SSubmitReq
*
pMsg
);
static
int32_t
tsdbUpdateExpiredWindowImpl
(
STsdb
*
pTsdb
,
SSubmitReq
*
pMsg
,
int64_t
version
);
static
int32_t
tsdbSetExpiredWindow
(
STsdb
*
pTsdb
,
SHashObj
*
pItemsHash
,
int64_t
indexUid
,
int64_t
winSKey
);
static
int32_t
tsdbSetExpiredWindow
(
STsdb
*
pTsdb
,
SHashObj
*
pItemsHash
,
int64_t
indexUid
,
int64_t
winSKey
,
int64_t
version
);
static
int32_t
tsdbInitSmaStat
(
SSmaStat
**
pSmaStat
);
static
int32_t
tsdbInitSmaStat
(
SSmaStat
**
pSmaStat
);
static
void
*
tsdbFreeSmaStatItem
(
SSmaStatItem
*
pSmaStatItem
);
static
void
*
tsdbFreeSmaStatItem
(
SSmaStatItem
*
pSmaStatItem
);
static
int32_t
tsdbDestroySmaState
(
SSmaStat
*
pSmaStat
);
static
int32_t
tsdbDestroySmaState
(
SSmaStat
*
pSmaStat
);
...
@@ -104,7 +127,8 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH);
...
@@ -104,7 +127,8 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH);
static
int32_t
tsdbInitTSmaReadH
(
STSmaReadH
*
pSmaH
,
STsdb
*
pTsdb
,
int64_t
interval
,
int8_t
intervalUnit
);
static
int32_t
tsdbInitTSmaReadH
(
STSmaReadH
*
pSmaH
,
STsdb
*
pTsdb
,
int64_t
interval
,
int8_t
intervalUnit
);
static
int32_t
tsdbGetSmaStorageLevel
(
int64_t
interval
,
int8_t
intervalUnit
);
static
int32_t
tsdbGetSmaStorageLevel
(
int64_t
interval
,
int8_t
intervalUnit
);
static
int32_t
tsdbSetRSmaDataFile
(
STSmaWriteH
*
pSmaH
,
int32_t
fid
);
static
int32_t
tsdbSetRSmaDataFile
(
STSmaWriteH
*
pSmaH
,
int32_t
fid
);
static
int32_t
tsdbInsertTSmaBlocks
(
STSmaWriteH
*
pSmaH
,
void
*
smaKey
,
uint32_t
keyLen
,
void
*
pData
,
uint32_t
dataLen
);
static
int32_t
tsdbInsertTSmaBlocks
(
STSmaWriteH
*
pSmaH
,
void
*
smaKey
,
int32_t
keyLen
,
void
*
pData
,
int32_t
dataLen
,
TXN
*
txn
);
static
int64_t
tsdbGetIntervalByPrecision
(
int64_t
interval
,
uint8_t
intervalUnit
,
int8_t
precision
,
bool
adjusted
);
static
int64_t
tsdbGetIntervalByPrecision
(
int64_t
interval
,
uint8_t
intervalUnit
,
int8_t
precision
,
bool
adjusted
);
static
int32_t
tsdbGetTSmaDays
(
STsdb
*
pTsdb
,
int64_t
interval
,
int32_t
storageLevel
);
static
int32_t
tsdbGetTSmaDays
(
STsdb
*
pTsdb
,
int64_t
interval
,
int32_t
storageLevel
);
static
int32_t
tsdbSetTSmaDataFile
(
STSmaWriteH
*
pSmaH
,
int64_t
indexUid
,
int32_t
fid
);
static
int32_t
tsdbSetTSmaDataFile
(
STSmaWriteH
*
pSmaH
,
int64_t
indexUid
,
int32_t
fid
);
...
@@ -117,9 +141,121 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg);
...
@@ -117,9 +141,121 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg);
// mgmt interface
// mgmt interface
static
int32_t
tsdbDropTSmaDataImpl
(
STsdb
*
pTsdb
,
int64_t
indexUid
);
static
int32_t
tsdbDropTSmaDataImpl
(
STsdb
*
pTsdb
,
int64_t
indexUid
);
// 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
);
static
int
tsdbSmaBeginCommit
(
SSmaEnv
*
pEnv
);
static
int
tsdbSmaEndCommit
(
SSmaEnv
*
pEnv
);
// implementation
// implementation
static
FORCE_INLINE
int16_t
tsdbTSmaAdd
(
STsdb
*
pTsdb
,
int16_t
n
)
{
return
atomic_add_fetch_16
(
&
REPO_TSMA_NUM
(
pTsdb
),
n
);
}
static
FORCE_INLINE
int16_t
tsdbTSmaAdd
(
STsdb
*
pTsdb
,
int16_t
n
)
{
static
FORCE_INLINE
int16_t
tsdbTSmaSub
(
STsdb
*
pTsdb
,
int16_t
n
)
{
return
atomic_sub_fetch_16
(
&
REPO_TSMA_NUM
(
pTsdb
),
n
);
}
return
atomic_add_fetch_16
(
&
REPO_TSMA_NUM
(
pTsdb
),
n
);
}
static
FORCE_INLINE
int16_t
tsdbTSmaSub
(
STsdb
*
pTsdb
,
int16_t
n
)
{
return
atomic_sub_fetch_16
(
&
REPO_TSMA_NUM
(
pTsdb
),
n
);
}
static
FORCE_INLINE
int32_t
tsdbRLockSma
(
SSmaEnv
*
pEnv
)
{
int
code
=
taosThreadRwlockRdlock
(
&
(
pEnv
->
lock
));
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
return
0
;
}
static
FORCE_INLINE
int32_t
tsdbWLockSma
(
SSmaEnv
*
pEnv
)
{
int
code
=
taosThreadRwlockWrlock
(
&
(
pEnv
->
lock
));
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
return
0
;
}
static
FORCE_INLINE
int32_t
tsdbUnLockSma
(
SSmaEnv
*
pEnv
)
{
int
code
=
taosThreadRwlockUnlock
(
&
(
pEnv
->
lock
));
if
(
code
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
code
);
return
-
1
;
}
return
0
;
}
static
SPoolMem
*
openPool
()
{
SPoolMem
*
pPool
=
(
SPoolMem
*
)
tdbOsMalloc
(
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
;
tdbOsFree
(
pMem
);
}
while
(
1
);
assert
(
pPool
->
size
==
0
);
}
static
void
closePool
(
SPoolMem
*
pPool
)
{
if
(
pPool
)
{
clearPool
(
pPool
);
tdbOsFree
(
pPool
);
}
}
static
void
*
poolMalloc
(
void
*
arg
,
size_t
size
)
{
void
*
ptr
=
NULL
;
SPoolMem
*
pPool
=
(
SPoolMem
*
)
arg
;
SPoolMem
*
pMem
;
pMem
=
(
SPoolMem
*
)
tdbOsMalloc
(
sizeof
(
*
pMem
)
+
size
);
if
(
pMem
==
NULL
)
{
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
;
tdbOsFree
(
pMem
);
}
int32_t
tsdbInitSma
(
STsdb
*
pTsdb
)
{
int32_t
tsdbInitSma
(
STsdb
*
pTsdb
)
{
// tSma
// tSma
...
@@ -213,7 +349,12 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
...
@@ -213,7 +349,12 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
char
aname
[
TSDB_FILENAME_LEN
]
=
{
0
};
char
aname
[
TSDB_FILENAME_LEN
]
=
{
0
};
tfsAbsoluteName
(
pTsdb
->
pTfs
,
did
,
path
,
aname
);
tfsAbsoluteName
(
pTsdb
->
pTfs
,
did
,
path
,
aname
);
if
(
tsdbOpenBDBEnv
(
&
pEnv
->
dbEnv
,
aname
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tsdbOpenDBEnv
(
&
pEnv
->
dbEnv
,
aname
)
!=
TSDB_CODE_SUCCESS
)
{
tsdbFreeSmaEnv
(
pEnv
);
return
NULL
;
}
if
((
pEnv
->
pPool
=
openPool
())
==
NULL
)
{
tsdbFreeSmaEnv
(
pEnv
);
tsdbFreeSmaEnv
(
pEnv
);
return
NULL
;
return
NULL
;
}
}
...
@@ -248,7 +389,8 @@ void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) {
...
@@ -248,7 +389,8 @@ void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) {
taosMemoryFreeClear
(
pSmaEnv
->
pStat
);
taosMemoryFreeClear
(
pSmaEnv
->
pStat
);
taosMemoryFreeClear
(
pSmaEnv
->
path
);
taosMemoryFreeClear
(
pSmaEnv
->
path
);
taosThreadRwlockDestroy
(
&
(
pSmaEnv
->
lock
));
taosThreadRwlockDestroy
(
&
(
pSmaEnv
->
lock
));
tsdbCloseBDBEnv
(
pSmaEnv
->
dbEnv
);
tsdbCloseDBEnv
(
pSmaEnv
->
dbEnv
);
closePool
(
pSmaEnv
->
pPool
);
}
}
}
}
...
@@ -402,7 +544,7 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
...
@@ -402,7 +544,7 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
};
};
static
int32_t
tsdbSetExpiredWindow
(
STsdb
*
pTsdb
,
SHashObj
*
pItemsHash
,
int64_t
indexUid
,
int64_t
winSKey
)
{
static
int32_t
tsdbSetExpiredWindow
(
STsdb
*
pTsdb
,
SHashObj
*
pItemsHash
,
int64_t
indexUid
,
int64_t
winSKey
,
int64_t
version
)
{
SSmaStatItem
*
pItem
=
taosHashGet
(
pItemsHash
,
&
indexUid
,
sizeof
(
indexUid
));
SSmaStatItem
*
pItem
=
taosHashGet
(
pItemsHash
,
&
indexUid
,
sizeof
(
indexUid
));
if
(
pItem
==
NULL
)
{
if
(
pItem
==
NULL
)
{
// TODO: use TSDB_SMA_STAT_EXPIRED and update by stream computing later
// TODO: use TSDB_SMA_STAT_EXPIRED and update by stream computing later
...
@@ -414,7 +556,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
...
@@ -414,7 +556,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
}
}
// cache smaMeta
// cache smaMeta
STSma
*
pSma
=
metaGetSmaInfoByIndex
(
pTsdb
->
pMeta
,
indexUid
);
STSma
*
pSma
=
metaGetSmaInfoByIndex
(
pTsdb
->
pMeta
,
indexUid
,
true
);
if
(
pSma
==
NULL
)
{
if
(
pSma
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_NO_SMA_INDEX_IN_META
;
terrno
=
TSDB_CODE_TDB_NO_SMA_INDEX_IN_META
;
taosHashCleanup
(
pItem
->
expiredWindows
);
taosHashCleanup
(
pItem
->
expiredWindows
);
...
@@ -436,8 +578,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
...
@@ -436,8 +578,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
int8_t
state
=
TSDB_SMA_STAT_EXPIRED
;
if
(
taosHashPut
(
pItem
->
expiredWindows
,
&
winSKey
,
sizeof
(
TSKEY
),
&
version
,
sizeof
(
version
))
!=
0
)
{
if
(
taosHashPut
(
pItem
->
expiredWindows
,
&
winSKey
,
sizeof
(
TSKEY
),
&
state
,
sizeof
(
state
))
!=
0
)
{
// If error occurs during taosHashPut expired windows, remove the smaIndex from pTsdb->pSmaStat, thus TSDB would
// If error occurs during taosHashPut expired windows, remove the smaIndex from pTsdb->pSmaStat, thus TSDB would
// tell query module to query raw TS data.
// tell query module to query raw TS data.
// N.B.
// N.B.
...
@@ -464,7 +605,8 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
...
@@ -464,7 +605,8 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
* @param msg SSubmitReq
* @param msg SSubmitReq
* @return int32_t
* @return int32_t
*/
*/
int32_t
tsdbUpdateExpiredWindowImpl
(
STsdb
*
pTsdb
,
SSubmitReq
*
pMsg
)
{
int32_t
tsdbUpdateExpiredWindowImpl
(
STsdb
*
pTsdb
,
SSubmitReq
*
pMsg
,
int64_t
version
)
{
// no time-range-sma, just return success
if
(
atomic_load_16
(
&
REPO_TSMA_NUM
(
pTsdb
))
<=
0
)
{
if
(
atomic_load_16
(
&
REPO_TSMA_NUM
(
pTsdb
))
<=
0
)
{
tsdbTrace
(
"vgId:%d not update expire window since no tSma"
,
REPO_ID
(
pTsdb
));
tsdbTrace
(
"vgId:%d not update expire window since no tSma"
,
REPO_ID
(
pTsdb
));
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -479,29 +621,11 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg) {
...
@@ -479,29 +621,11 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg) {
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
// TODO: decode the msg from Stream Computing module => start
#ifdef TSDB_SMA_TESTx
int64_t
indexUid
=
SMA_TEST_INDEX_UID
;
const
int32_t
SMA_TEST_EXPIRED_WINDOW_SIZE
=
10
;
TSKEY
expiredWindows
[
SMA_TEST_EXPIRED_WINDOW_SIZE
];
TSKEY
skey1
=
1646987196
*
1e3
;
for
(
int32_t
i
=
0
;
i
<
SMA_TEST_EXPIRED_WINDOW_SIZE
;
++
i
)
{
expiredWindows
[
i
]
=
skey1
+
i
;
}
#else
#endif
// TODO: decode the msg <= end
if
(
tsdbCheckAndInitSmaEnv
(
pTsdb
,
TSDB_SMA_TYPE_TIME_RANGE
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tsdbCheckAndInitSmaEnv
(
pTsdb
,
TSDB_SMA_TYPE_TIME_RANGE
)
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
TSDB_CODE_TDB_INIT_FAILED
;
terrno
=
TSDB_CODE_TDB_INIT_FAILED
;
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
#ifndef TSDB_SMA_TEST
TSKEY
expiredWindows
[
SMA_TEST_EXPIRED_WINDOW_SIZE
];
#endif
// Firstly, assume that tSma can only be created on super table/normal table.
// Firstly, assume that tSma can only be created on super table/normal table.
// getActiveTimeWindow
// getActiveTimeWindow
...
@@ -562,7 +686,11 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg) {
...
@@ -562,7 +686,11 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg) {
TSKEY
winSKey
=
taosTimeTruncate
(
TD_ROW_KEY
(
row
),
&
interval
,
interval
.
precision
);
TSKEY
winSKey
=
taosTimeTruncate
(
TD_ROW_KEY
(
row
),
&
interval
,
interval
.
precision
);
tsdbSetExpiredWindow
(
pTsdb
,
pItemsHash
,
pTSma
->
indexUid
,
winSKey
);
tsdbSetExpiredWindow
(
pTsdb
,
pItemsHash
,
pTSma
->
indexUid
,
winSKey
,
version
);
// TODO: release only when suid changes.
tdDestroyTSmaWrapper
(
pSW
);
taosMemoryFreeClear
(
pSW
);
}
}
}
}
...
@@ -676,10 +804,12 @@ static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
...
@@ -676,10 +804,12 @@ static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
* @param dataLen
* @param dataLen
* @return int32_t
* @return int32_t
*/
*/
static
int32_t
tsdbInsertTSmaBlocks
(
STSmaWriteH
*
pSmaH
,
void
*
smaKey
,
uint32_t
keyLen
,
void
*
pData
,
uint32_t
dataLen
)
{
static
int32_t
tsdbInsertTSmaBlocks
(
STSmaWriteH
*
pSmaH
,
void
*
smaKey
,
int32_t
keyLen
,
void
*
pData
,
int32_t
dataLen
,
TXN
*
txn
)
{
SDBFile
*
pDBFile
=
&
pSmaH
->
dFile
;
SDBFile
*
pDBFile
=
&
pSmaH
->
dFile
;
// TODO: insert sma data blocks into B+Tree(TDB)
// TODO: insert sma data blocks into B+Tree(TDB)
if
(
tsdbSaveSmaToDB
(
pDBFile
,
smaKey
,
keyLen
,
pData
,
dataLen
)
!=
0
)
{
if
(
tsdbSaveSmaToDB
(
pDBFile
,
smaKey
,
keyLen
,
pData
,
dataLen
,
txn
)
!=
0
)
{
tsdbWarn
(
"vgId:%d insert sma data blocks into %s: smaKey %"
PRIx64
"-%"
PRIx64
", dataLen %"
PRIu32
" fail"
,
tsdbWarn
(
"vgId:%d insert sma data blocks into %s: smaKey %"
PRIx64
"-%"
PRIx64
", dataLen %"
PRIu32
" fail"
,
REPO_ID
(
pSmaH
->
pTsdb
),
pDBFile
->
path
,
*
(
int64_t
*
)
smaKey
,
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
dataLen
);
REPO_ID
(
pSmaH
->
pTsdb
),
pDBFile
->
path
,
*
(
int64_t
*
)
smaKey
,
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
dataLen
);
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
...
@@ -826,6 +956,30 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe
...
@@ -826,6 +956,30 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe
return
daysPerFile
;
return
daysPerFile
;
}
}
static
int
tsdbSmaBeginCommit
(
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
)
{
tsdbWarn
(
"tsdbSma tdb begin commit fail"
);
return
-
1
;
}
return
0
;
}
static
int
tsdbSmaEndCommit
(
SSmaEnv
*
pEnv
)
{
TXN
*
pTxn
=
&
pEnv
->
txn
;
// Commit current txn
if
(
tdbCommit
(
pEnv
->
dbEnv
,
pTxn
)
!=
0
)
{
tsdbWarn
(
"tsdbSma tdb end commit fail"
);
return
-
1
;
}
tdbTxnClose
(
pTxn
);
clearPool
(
pEnv
->
pPool
);
return
0
;
}
/**
/**
* @brief Insert/Update Time-range-wise SMA data.
* @brief Insert/Update Time-range-wise SMA data.
* - If interval < SMA_STORAGE_SPLIT_HOURS(e.g. 24), save the SMA data as a part of DFileSet to e.g.
* - If interval < SMA_STORAGE_SPLIT_HOURS(e.g. 24), save the SMA data as a part of DFileSet to e.g.
...
@@ -841,12 +995,12 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe
...
@@ -841,12 +995,12 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe
static
int32_t
tsdbInsertTSmaDataImpl
(
STsdb
*
pTsdb
,
int64_t
indexUid
,
const
char
*
msg
)
{
static
int32_t
tsdbInsertTSmaDataImpl
(
STsdb
*
pTsdb
,
int64_t
indexUid
,
const
char
*
msg
)
{
STsdbCfg
*
pCfg
=
REPO_CFG
(
pTsdb
);
STsdbCfg
*
pCfg
=
REPO_CFG
(
pTsdb
);
const
SArray
*
pDataBlocks
=
(
const
SArray
*
)
msg
;
const
SArray
*
pDataBlocks
=
(
const
SArray
*
)
msg
;
SSmaEnv
*
pEnv
=
atomic_load_ptr
(
&
REPO_TSMA_ENV
(
pTsdb
));
if
(
pEnv
==
NULL
)
{
// For super table aggregation, the sma data is stored in vgroup calculated from the hash value of stable name. Thus
terrno
=
TSDB_CODE_INVALID_PTR
;
// the sma data would arrive ahead of the update-expired-window msg.
tsdbWarn
(
"vgId:%d insert tSma data failed since pTSmaEnv is NULL"
,
REPO_ID
(
pTsdb
));
if
(
tsdbCheckAndInitSmaEnv
(
pTsdb
,
TSDB_SMA_TYPE_TIME_RANGE
)
!=
TSDB_CODE_SUCCESS
)
{
return
terrno
;
terrno
=
TSDB_CODE_TDB_INIT_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
if
(
pDataBlocks
==
NULL
)
{
if
(
pDataBlocks
==
NULL
)
{
...
@@ -861,6 +1015,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
...
@@ -861,6 +1015,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
SSmaEnv
*
pEnv
=
REPO_TSMA_ENV
(
pTsdb
);
SSmaStat
*
pStat
=
SMA_ENV_STAT
(
pEnv
);
SSmaStat
*
pStat
=
SMA_ENV_STAT
(
pEnv
);
SSmaStatItem
*
pItem
=
NULL
;
SSmaStatItem
*
pItem
=
NULL
;
...
@@ -911,14 +1066,10 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
...
@@ -911,14 +1066,10 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
int64_t
groupId
=
pDataBlock
->
info
.
groupId
;
int64_t
groupId
=
pDataBlock
->
info
.
groupId
;
for
(
int32_t
j
=
0
;
j
<
rows
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
rows
;
++
j
)
{
printf
(
"|"
);
printf
(
"|"
);
TSKEY
skey
=
1649295200000
;
// TSKEY_INITIAL_VAL; //
the start key of TS window by interval
TSKEY
skey
=
TSKEY_INITIAL_VAL
;
//
the start key of TS window by interval
void
*
pSmaKey
=
&
smaKey
;
void
*
pSmaKey
=
&
smaKey
;
bool
isStartKey
=
false
;
bool
isStartKey
=
false
;
{
// just for debugging
isStartKey
=
true
;
tsdbEncodeTSmaKey
(
groupId
,
skey
,
&
pSmaKey
);
}
int32_t
tlen
=
0
;
// reset the len
int32_t
tlen
=
0
;
// reset the len
pDataBuf
=
&
dataBuf
;
// reset the buf
pDataBuf
=
&
dataBuf
;
// reset the buf
for
(
int32_t
k
=
0
;
k
<
colNum
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
colNum
;
++
k
)
{
...
@@ -929,7 +1080,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
...
@@ -929,7 +1080,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
if
(
!
isStartKey
)
{
if
(
!
isStartKey
)
{
isStartKey
=
true
;
isStartKey
=
true
;
skey
=
*
(
TSKEY
*
)
var
;
skey
=
*
(
TSKEY
*
)
var
;
printf
(
"=
=> skey =
%"
PRIi64
" groupId = %"
PRIi64
"|"
,
skey
,
groupId
);
printf
(
"=
skey
%"
PRIi64
" groupId = %"
PRIi64
"|"
,
skey
,
groupId
);
tsdbEncodeTSmaKey
(
groupId
,
skey
,
&
pSmaKey
);
tsdbEncodeTSmaKey
(
groupId
,
skey
,
&
pSmaKey
);
}
else
{
}
else
{
printf
(
" %"
PRIi64
" |"
,
*
(
int64_t
*
)
var
);
printf
(
" %"
PRIi64
" |"
,
*
(
int64_t
*
)
var
);
...
@@ -1010,6 +1161,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
...
@@ -1010,6 +1161,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
// TODO: tsdbStartTSmaCommit();
// TODO: tsdbStartTSmaCommit();
if
(
fid
!=
tSmaH
.
dFile
.
fid
)
{
if
(
fid
!=
tSmaH
.
dFile
.
fid
)
{
if
(
tSmaH
.
dFile
.
fid
!=
TSDB_IVLD_FID
)
{
if
(
tSmaH
.
dFile
.
fid
!=
TSDB_IVLD_FID
)
{
tsdbSmaEndCommit
(
pEnv
);
tsdbCloseDBF
(
&
tSmaH
.
dFile
);
tsdbCloseDBF
(
&
tSmaH
.
dFile
);
}
}
tsdbSetTSmaDataFile
(
&
tSmaH
,
indexUid
,
fid
);
tsdbSetTSmaDataFile
(
&
tSmaH
,
indexUid
,
fid
);
...
@@ -1020,12 +1172,14 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
...
@@ -1020,12 +1172,14 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
tsdbUnRefSmaStat
(
pTsdb
,
pStat
);
tsdbUnRefSmaStat
(
pTsdb
,
pStat
);
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
tsdbSmaBeginCommit
(
pEnv
);
}
}
if
(
tsdbInsertTSmaBlocks
(
&
tSmaH
,
&
smaKey
,
SMA_KEY_LEN
,
dataBuf
,
tlen
)
!=
0
)
{
if
(
tsdbInsertTSmaBlocks
(
&
tSmaH
,
&
smaKey
,
SMA_KEY_LEN
,
dataBuf
,
tlen
,
&
pEnv
->
txn
)
!=
0
)
{
tsdbWarn
(
"vgId:%d insert tSma data blocks fail for index %"
PRIi64
", skey %"
PRIi64
", groupId %"
PRIi64
tsdbWarn
(
"vgId:%d insert tSma data blocks fail for index %"
PRIi64
", skey %"
PRIi64
", groupId %"
PRIi64
" since %s"
,
" since %s"
,
REPO_ID
(
pTsdb
),
indexUid
,
skey
,
groupId
,
tstrerror
(
terrno
));
REPO_ID
(
pTsdb
),
indexUid
,
skey
,
groupId
,
tstrerror
(
terrno
));
tsdbSmaEndCommit
(
pEnv
);
tsdbDestroyTSmaWriteH
(
&
tSmaH
);
tsdbDestroyTSmaWriteH
(
&
tSmaH
);
tsdbUnRefSmaStat
(
pTsdb
,
pStat
);
tsdbUnRefSmaStat
(
pTsdb
,
pStat
);
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
...
@@ -1044,9 +1198,10 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
...
@@ -1044,9 +1198,10 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
}
}
tsdbSmaEndCommit
(
pEnv
);
// TODO: not commit for every insert
tsdbDestroyTSmaWriteH
(
&
tSmaH
);
tsdbDestroyTSmaWriteH
(
&
tSmaH
);
tsdbUnRefSmaStat
(
pTsdb
,
pStat
);
tsdbUnRefSmaStat
(
pTsdb
,
pStat
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -1371,7 +1526,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
...
@@ -1371,7 +1526,7 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid,
tReadH
.
dFile
.
path
,
*
(
int64_t
*
)
smaKey
,
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
SMA_KEY_LEN
);
tReadH
.
dFile
.
path
,
*
(
int64_t
*
)
smaKey
,
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
SMA_KEY_LEN
);
void
*
result
=
NULL
;
void
*
result
=
NULL
;
u
int32_t
valueSize
=
0
;
int32_t
valueSize
=
0
;
if
((
result
=
tsdbGetSmaDataByKey
(
&
tReadH
.
dFile
,
smaKey
,
SMA_KEY_LEN
,
&
valueSize
))
==
NULL
)
{
if
((
result
=
tsdbGetSmaDataByKey
(
&
tReadH
.
dFile
,
smaKey
,
SMA_KEY_LEN
,
&
valueSize
))
==
NULL
)
{
tsdbWarn
(
"vgId:%d get sma data failed from smaIndex %"
PRIi64
", smaKey %"
PRIx64
"-%"
PRIx64
" since %s"
,
tsdbWarn
(
"vgId:%d get sma data failed from smaIndex %"
PRIi64
", smaKey %"
PRIx64
"-%"
PRIx64
" since %s"
,
REPO_ID
(
pTsdb
),
indexUid
,
*
(
int64_t
*
)
smaKey
,
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
tstrerror
(
terrno
));
REPO_ID
(
pTsdb
),
indexUid
,
*
(
int64_t
*
)
smaKey
,
*
(
int64_t
*
)
POINTER_SHIFT
(
smaKey
,
8
),
tstrerror
(
terrno
));
...
@@ -1515,9 +1670,9 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg) {
...
@@ -1515,9 +1670,9 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg) {
return
code
;
return
code
;
}
}
int32_t
tsdbUpdateSmaWindow
(
STsdb
*
pTsdb
,
SSubmitReq
*
pMsg
)
{
int32_t
tsdbUpdateSmaWindow
(
STsdb
*
pTsdb
,
SSubmitReq
*
pMsg
,
int64_t
version
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
((
code
=
tsdbUpdateExpiredWindowImpl
(
pTsdb
,
pMsg
))
<
0
)
{
if
((
code
=
tsdbUpdateExpiredWindowImpl
(
pTsdb
,
pMsg
,
version
))
<
0
)
{
tsdbWarn
(
"vgId:%d update expired sma window failed since %s"
,
REPO_ID
(
pTsdb
),
tstrerror
(
terrno
));
tsdbWarn
(
"vgId:%d update expired sma window failed since %s"
,
REPO_ID
(
pTsdb
),
tstrerror
(
terrno
));
}
}
return
code
;
return
code
;
...
...
source/dnode/vnode/src/tsdb/tsdbTDBImpl.c
0 → 100644
浏览文件 @
3a26ec4e
/*
* 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 "vnodeInt.h"
int32_t
tsdbOpenDBEnv
(
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
)
{
tsdbError
(
"Failed to create tsdb db env, ret = %d"
,
ret
);
return
-
1
;
}
return
0
;
}
int32_t
tsdbCloseDBEnv
(
TENV
*
pEnv
)
{
return
tdbEnvClose
(
pEnv
);
}
static
inline
int
tsdbSmaKeyCmpr
(
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
tsdbOpenDBDb
(
TDB
**
ppDB
,
TENV
*
pEnv
,
const
char
*
pFName
)
{
int
ret
;
FKeyComparator
compFunc
;
// Create a database
compFunc
=
tsdbSmaKeyCmpr
;
ret
=
tdbDbOpen
(
pFName
,
TDB_VARIANT_LEN
,
TDB_VARIANT_LEN
,
compFunc
,
pEnv
,
ppDB
);
return
0
;
}
static
int32_t
tsdbCloseDBDb
(
TDB
*
pDB
)
{
return
tdbDbClose
(
pDB
);
}
int32_t
tsdbOpenDBF
(
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
(
tsdbOpenDBDb
(
&
(
pDBF
->
pDB
),
pEnv
,
pDBF
->
path
)
<
0
)
{
terrno
=
TSDB_CODE_TDB_INIT_FAILED
;
tsdbCloseDBDb
(
pDBF
->
pDB
);
return
-
1
;
}
return
0
;
}
int32_t
tsdbCloseDBF
(
SDBFile
*
pDBF
)
{
int32_t
ret
=
0
;
if
(
pDBF
->
pDB
)
{
ret
=
tsdbCloseDBDb
(
pDBF
->
pDB
);
pDBF
->
pDB
=
NULL
;
}
taosMemoryFreeClear
(
pDBF
->
path
);
return
ret
;
}
int32_t
tsdbSaveSmaToDB
(
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
)
{
tsdbError
(
"Failed to create insert sma data into db, ret = %d"
,
ret
);
return
-
1
;
}
return
0
;
}
void
*
tsdbGetSmaDataByKey
(
SDBFile
*
pDBF
,
const
void
*
pKey
,
int32_t
keyLen
,
int32_t
*
valLen
)
{
void
*
result
;
void
*
pVal
;
int
ret
;
ret
=
tdbDbGet
(
pDBF
->
pDB
,
pKey
,
keyLen
,
&
pVal
,
valLen
);
if
(
ret
<
0
)
{
tsdbError
(
"Failed to get sma data from db, ret = %d"
,
ret
);
return
NULL
;
}
ASSERT
(
*
valLen
>=
0
);
result
=
taosMemoryMalloc
(
*
valLen
);
if
(
result
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
// 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?
memcpy
(
result
,
pVal
,
*
valLen
);
return
result
;
}
\ No newline at end of file
source/dnode/vnode/src/vnd/vnodeCfg.c
浏览文件 @
3a26ec4e
...
@@ -18,13 +18,6 @@
...
@@ -18,13 +18,6 @@
const
SVnodeCfg
defaultVnodeOptions
=
{
const
SVnodeCfg
defaultVnodeOptions
=
{
.
wsize
=
96
*
1024
*
1024
,
.
ssize
=
1
*
1024
*
1024
,
.
lsize
=
1024
,
.
walCfg
=
{.
level
=
TAOS_WAL_WRITE
}};
/* TODO */
.
wsize
=
96
*
1024
*
1024
,
.
ssize
=
1
*
1024
*
1024
,
.
lsize
=
1024
,
.
walCfg
=
{.
level
=
TAOS_WAL_WRITE
}};
/* TODO */
void
vnodeOptionsInit
(
SVnodeCfg
*
pVnodeOptions
)
{
/* TODO */
vnodeOptionsCopy
(
pVnodeOptions
,
&
defaultVnodeOptions
);
}
void
vnodeOptionsClear
(
SVnodeCfg
*
pVnodeOptions
)
{
/* TODO */
}
int
vnodeValidateOptions
(
const
SVnodeCfg
*
pVnodeOptions
)
{
int
vnodeValidateOptions
(
const
SVnodeCfg
*
pVnodeOptions
)
{
// TODO
// TODO
return
0
;
return
0
;
...
@@ -53,5 +46,3 @@ int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) {
...
@@ -53,5 +46,3 @@ int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
source/dnode/vnode/src/vnd/vnodeInt.c
浏览文件 @
3a26ec4e
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
*/
*/
#define _DEFAULT_SOURCE
#define _DEFAULT_SOURCE
#include "sync.h"
#include "vnodeInt.h"
#include "vnodeInt.h"
// #include "vnodeInt.h"
// #include "vnodeInt.h"
...
...
source/dnode/vnode/src/vnd/vnodeMgr.c
浏览文件 @
3a26ec4e
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
*/
*/
#include "vnodeInt.h"
#include "vnodeInt.h"
#include "tglobal.h"
SVnodeMgr
vnodeMgr
=
{.
vnodeInitFlag
=
TD_MOD_UNINITIALIZED
};
SVnodeMgr
vnodeMgr
=
{.
vnodeInitFlag
=
TD_MOD_UNINITIALIZED
};
...
...
source/dnode/vnode/src/vnd/vnodeQuery.c
浏览文件 @
3a26ec4e
...
@@ -13,7 +13,6 @@
...
@@ -13,7 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "executor.h"
#include "vnodeInt.h"
#include "vnodeInt.h"
static
int32_t
vnodeGetTableList
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
static
int32_t
vnodeGetTableList
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
...
...
source/dnode/vnode/src/vnd/vnodeWrite.c
浏览文件 @
3a26ec4e
...
@@ -19,7 +19,7 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
...
@@ -19,7 +19,7 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
// TODO
// TODO
// blockDebugShowData(data);
// blockDebugShowData(data);
//
tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data);
tsdbInsertTSmaData
(((
SVnode
*
)
pVnode
)
->
pTsdb
,
smaId
,
(
const
char
*
)
data
);
}
}
void
vnodeProcessWMsgs
(
SVnode
*
pVnode
,
SArray
*
pMsgs
)
{
void
vnodeProcessWMsgs
(
SVnode
*
pVnode
,
SArray
*
pMsgs
)
{
...
@@ -81,7 +81,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
...
@@ -81,7 +81,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
// TODO: to encapsule a free API
// TODO: to encapsule a free API
taosMemoryFree
(
vCreateTbReq
.
stbCfg
.
pSchema
);
taosMemoryFree
(
vCreateTbReq
.
stbCfg
.
pSchema
);
taosMemoryFree
(
vCreateTbReq
.
stbCfg
.
pTagSchema
);
taosMemoryFree
(
vCreateTbReq
.
stbCfg
.
pTagSchema
);
if
(
vCreateTbReq
.
stbCfg
.
pRSmaParam
)
{
if
(
vCreateTbReq
.
stbCfg
.
pRSmaParam
)
{
taosMemoryFree
(
vCreateTbReq
.
stbCfg
.
pRSmaParam
->
pFuncIds
);
taosMemoryFree
(
vCreateTbReq
.
stbCfg
.
pRSmaParam
->
pFuncIds
);
taosMemoryFree
(
vCreateTbReq
.
stbCfg
.
pRSmaParam
);
taosMemoryFree
(
vCreateTbReq
.
stbCfg
.
pRSmaParam
);
}
}
...
@@ -232,9 +232,9 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
...
@@ -232,9 +232,9 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
tdDestroyTSma(&vCreateSmaReq.tSma);
tdDestroyTSma(&vCreateSmaReq.tSma);
// TODO: return directly or go on follow steps?
// TODO: return directly or go on follow steps?
#endif
#endif
//
if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) {
if
(
tsdbCreateTSma
(
pVnode
->
pTsdb
,
POINTER_SHIFT
(
pMsg
->
pCont
,
sizeof
(
SMsgHead
)))
<
0
)
{
//
// TODO
// TODO
//
}
}
// } break;
// } break;
// case TDMT_VND_CANCEL_SMA: { // timeRangeSMA
// case TDMT_VND_CANCEL_SMA: { // timeRangeSMA
// } break;
// } break;
...
...
source/dnode/vnode/test/tsdbSmaTest.cpp
浏览文件 @
3a26ec4e
...
@@ -210,7 +210,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
...
@@ -210,7 +210,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
// get value by indexName
// get value by indexName
STSma
*
qSmaCfg
=
NULL
;
STSma
*
qSmaCfg
=
NULL
;
qSmaCfg
=
metaGetSmaInfoByIndex
(
pMeta
,
indexUid1
);
qSmaCfg
=
metaGetSmaInfoByIndex
(
pMeta
,
indexUid1
,
true
);
assert
(
qSmaCfg
!=
NULL
);
assert
(
qSmaCfg
!=
NULL
);
printf
(
"name1 = %s
\n
"
,
qSmaCfg
->
indexName
);
printf
(
"name1 = %s
\n
"
,
qSmaCfg
->
indexName
);
printf
(
"timezone1 = %"
PRIi8
"
\n
"
,
qSmaCfg
->
timezoneInt
);
printf
(
"timezone1 = %"
PRIi8
"
\n
"
,
qSmaCfg
->
timezoneInt
);
...
@@ -221,7 +221,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
...
@@ -221,7 +221,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
tdDestroyTSma
(
qSmaCfg
);
tdDestroyTSma
(
qSmaCfg
);
taosMemoryFreeClear
(
qSmaCfg
);
taosMemoryFreeClear
(
qSmaCfg
);
qSmaCfg
=
metaGetSmaInfoByIndex
(
pMeta
,
indexUid2
);
qSmaCfg
=
metaGetSmaInfoByIndex
(
pMeta
,
indexUid2
,
true
);
assert
(
qSmaCfg
!=
NULL
);
assert
(
qSmaCfg
!=
NULL
);
printf
(
"name2 = %s
\n
"
,
qSmaCfg
->
indexName
);
printf
(
"name2 = %s
\n
"
,
qSmaCfg
->
indexName
);
printf
(
"timezone2 = %"
PRIi8
"
\n
"
,
qSmaCfg
->
timezoneInt
);
printf
(
"timezone2 = %"
PRIi8
"
\n
"
,
qSmaCfg
->
timezoneInt
);
...
@@ -233,11 +233,12 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
...
@@ -233,11 +233,12 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
taosMemoryFreeClear
(
qSmaCfg
);
taosMemoryFreeClear
(
qSmaCfg
);
// get index name by table uid
// get index name by table uid
#if 0
SMSmaCursor *pSmaCur = metaOpenSmaCursor(pMeta, tbUid);
SMSmaCursor *pSmaCur = metaOpenSmaCursor(pMeta, tbUid);
assert(pSmaCur != NULL);
assert(pSmaCur != NULL);
uint32_t indexCnt = 0;
uint32_t indexCnt = 0;
while (1) {
while (1) {
const
char
*
indexName
=
metaSmaCursorNext
(
pSmaCur
);
const char *indexName =
(const char *)
metaSmaCursorNext(pSmaCur);
if (indexName == NULL) {
if (indexName == NULL) {
break;
break;
}
}
...
@@ -245,8 +246,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
...
@@ -245,8 +246,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
++indexCnt;
++indexCnt;
}
}
EXPECT_EQ(indexCnt, nCntTSma);
EXPECT_EQ(indexCnt, nCntTSma);
metaCloseSmaCur
os
r
(
pSmaCur
);
metaCloseSmaCur
so
r(pSmaCur);
#endif
// get wrapper by table uid
// get wrapper by table uid
STSmaWrapper
*
pSW
=
metaGetSmaInfoByTable
(
pMeta
,
tbUid
);
STSmaWrapper
*
pSW
=
metaGetSmaInfoByTable
(
pMeta
,
tbUid
);
assert
(
pSW
!=
NULL
);
assert
(
pSW
!=
NULL
);
...
@@ -408,7 +409,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
...
@@ -408,7 +409,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
EXPECT_EQ
(
tdScanAndConvertSubmitMsg
(
pMsg
),
TSDB_CODE_SUCCESS
);
EXPECT_EQ
(
tdScanAndConvertSubmitMsg
(
pMsg
),
TSDB_CODE_SUCCESS
);
EXPECT_EQ
(
tsdbUpdateSmaWindow
(
pTsdb
,
pMsg
),
0
);
EXPECT_EQ
(
tsdbUpdateSmaWindow
(
pTsdb
,
pMsg
,
0
),
0
);
// init
// init
const
int32_t
tSmaGroupSize
=
4
;
const
int32_t
tSmaGroupSize
=
4
;
...
...
source/libs/executor/src/dataDispatcher.c
浏览文件 @
3a26ec4e
...
@@ -92,7 +92,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput,
...
@@ -92,7 +92,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput,
return
false
;
return
false
;
}
}
pBuf
->
allocSize
=
sizeof
(
SRetrieveTableRsp
)
+
block
Estimate
EncodeSize
(
pInput
->
pData
);
pBuf
->
allocSize
=
sizeof
(
SRetrieveTableRsp
)
+
block
Get
EncodeSize
(
pInput
->
pData
);
pBuf
->
pData
=
taosMemoryMalloc
(
pBuf
->
allocSize
);
pBuf
->
pData
=
taosMemoryMalloc
(
pBuf
->
allocSize
);
if
(
pBuf
->
pData
==
NULL
)
{
if
(
pBuf
->
pData
==
NULL
)
{
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
3a26ec4e
...
@@ -543,7 +543,7 @@ EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) {
...
@@ -543,7 +543,7 @@ EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) {
char
*
dbName
=
nodesGetValueFromNode
(
node
);
char
*
dbName
=
nodesGetValueFromNode
(
node
);
strncpy
(
pContext
,
varDataVal
(
dbName
),
varDataLen
(
dbName
));
strncpy
(
pContext
,
varDataVal
(
dbName
),
varDataLen
(
dbName
));
*
((
char
*
)
pContext
+
varDataLen
(
dbName
))
=
0
;
*
((
char
*
)
pContext
+
varDataLen
(
dbName
))
=
0
;
return
DEAL_RES_E
RROR
;
// stop walk
return
DEAL_RES_E
ND
;
// stop walk
}
}
default:
default:
break
;
break
;
...
@@ -772,6 +772,8 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB
...
@@ -772,6 +772,8 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB
tableType
=
TSDB_MGMT_TABLE_USER
;
tableType
=
TSDB_MGMT_TABLE_USER
;
}
else
if
(
strncasecmp
(
name
,
TSDB_INS_TABLE_DNODES
,
tListLen
(
pName
->
tname
))
==
0
)
{
}
else
if
(
strncasecmp
(
name
,
TSDB_INS_TABLE_DNODES
,
tListLen
(
pName
->
tname
))
==
0
)
{
tableType
=
TSDB_MGMT_TABLE_DNODE
;
tableType
=
TSDB_MGMT_TABLE_DNODE
;
}
else
if
(
strncasecmp
(
name
,
TSDB_INS_TABLE_LICENCES
,
tListLen
(
pName
->
tname
))
==
0
)
{
tableType
=
TSDB_MGMT_TABLE_GRANTS
;
}
else
if
(
strncasecmp
(
name
,
TSDB_INS_TABLE_MNODES
,
tListLen
(
pName
->
tname
))
==
0
)
{
}
else
if
(
strncasecmp
(
name
,
TSDB_INS_TABLE_MNODES
,
tListLen
(
pName
->
tname
))
==
0
)
{
tableType
=
TSDB_MGMT_TABLE_MNODE
;
tableType
=
TSDB_MGMT_TABLE_MNODE
;
}
else
if
(
strncasecmp
(
name
,
TSDB_INS_TABLE_MODULES
,
tListLen
(
pName
->
tname
))
==
0
)
{
}
else
if
(
strncasecmp
(
name
,
TSDB_INS_TABLE_MODULES
,
tListLen
(
pName
->
tname
))
==
0
)
{
...
...
source/libs/function/src/builtins.c
浏览文件 @
3a26ec4e
...
@@ -423,6 +423,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -423,6 +423,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
sprocessFunc
=
timeTruncateFunction
,
.
sprocessFunc
=
timeTruncateFunction
,
.
finalizeFunc
=
NULL
.
finalizeFunc
=
NULL
},
},
{
.
name
=
"timediff"
,
.
type
=
FUNCTION_TYPE_TIMEDIFF
,
.
classification
=
FUNC_MGT_SCALAR_FUNC
,
.
checkFunc
=
checkAndGetResultType
,
.
getEnvFunc
=
NULL
,
.
initFunc
=
NULL
,
.
sprocessFunc
=
timeDiffFunction
,
.
finalizeFunc
=
NULL
},
{
{
.
name
=
"_rowts"
,
.
name
=
"_rowts"
,
.
type
=
FUNCTION_TYPE_ROWTS
,
.
type
=
FUNCTION_TYPE_ROWTS
,
...
@@ -651,6 +661,10 @@ int32_t checkAndGetResultType(SFunctionNode* pFunc) {
...
@@ -651,6 +661,10 @@ int32_t checkAndGetResultType(SFunctionNode* pFunc) {
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_TIMESTAMP
].
bytes
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
};
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_TIMESTAMP
].
bytes
,
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
};
break
;
break
;
}
}
case
FUNCTION_TYPE_TIMEDIFF
:
{
pFunc
->
node
.
resType
=
(
SDataType
)
{
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_BIGINT
].
bytes
,
.
type
=
TSDB_DATA_TYPE_BIGINT
};
break
;
}
case
FUNCTION_TYPE_TBNAME
:
{
case
FUNCTION_TYPE_TBNAME
:
{
// todo
// todo
...
...
source/libs/nodes/src/nodesTraverseFuncs.c
浏览文件 @
3a26ec4e
...
@@ -46,7 +46,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
...
@@ -46,7 +46,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
case
QUERY_NODE_OPERATOR
:
{
case
QUERY_NODE_OPERATOR
:
{
SOperatorNode
*
pOpNode
=
(
SOperatorNode
*
)
pNode
;
SOperatorNode
*
pOpNode
=
(
SOperatorNode
*
)
pNode
;
res
=
walkNode
(
pOpNode
->
pLeft
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pOpNode
->
pLeft
,
order
,
walker
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
walkNode
(
pOpNode
->
pRight
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pOpNode
->
pRight
,
order
,
walker
,
pContext
);
}
}
break
;
break
;
...
@@ -63,10 +63,10 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
...
@@ -63,10 +63,10 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
case
QUERY_NODE_JOIN_TABLE
:
{
case
QUERY_NODE_JOIN_TABLE
:
{
SJoinTableNode
*
pJoinTableNode
=
(
SJoinTableNode
*
)
pNode
;
SJoinTableNode
*
pJoinTableNode
=
(
SJoinTableNode
*
)
pNode
;
res
=
walkNode
(
pJoinTableNode
->
pLeft
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pJoinTableNode
->
pLeft
,
order
,
walker
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
walkNode
(
pJoinTableNode
->
pRight
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pJoinTableNode
->
pRight
,
order
,
walker
,
pContext
);
}
}
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
walkNode
(
pJoinTableNode
->
pOnCond
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pJoinTableNode
->
pOnCond
,
order
,
walker
,
pContext
);
}
}
break
;
break
;
...
@@ -80,7 +80,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
...
@@ -80,7 +80,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
case
QUERY_NODE_STATE_WINDOW
:
{
case
QUERY_NODE_STATE_WINDOW
:
{
SStateWindowNode
*
pState
=
(
SStateWindowNode
*
)
pNode
;
SStateWindowNode
*
pState
=
(
SStateWindowNode
*
)
pNode
;
res
=
walkNode
(
pState
->
pExpr
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pState
->
pExpr
,
order
,
walker
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
walkNode
(
pState
->
pCol
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pState
->
pCol
,
order
,
walker
,
pContext
);
}
}
break
;
break
;
...
@@ -88,7 +88,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
...
@@ -88,7 +88,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
case
QUERY_NODE_SESSION_WINDOW
:
{
case
QUERY_NODE_SESSION_WINDOW
:
{
SSessionWindowNode
*
pSession
=
(
SSessionWindowNode
*
)
pNode
;
SSessionWindowNode
*
pSession
=
(
SSessionWindowNode
*
)
pNode
;
res
=
walkNode
(
pSession
->
pCol
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pSession
->
pCol
,
order
,
walker
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
walkNode
(
pSession
->
pGap
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pSession
->
pGap
,
order
,
walker
,
pContext
);
}
}
break
;
break
;
...
@@ -96,16 +96,16 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
...
@@ -96,16 +96,16 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
case
QUERY_NODE_INTERVAL_WINDOW
:
{
case
QUERY_NODE_INTERVAL_WINDOW
:
{
SIntervalWindowNode
*
pInterval
=
(
SIntervalWindowNode
*
)
pNode
;
SIntervalWindowNode
*
pInterval
=
(
SIntervalWindowNode
*
)
pNode
;
res
=
walkNode
(
pInterval
->
pInterval
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pInterval
->
pInterval
,
order
,
walker
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
walkNode
(
pInterval
->
pOffset
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pInterval
->
pOffset
,
order
,
walker
,
pContext
);
}
}
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
walkNode
(
pInterval
->
pSliding
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pInterval
->
pSliding
,
order
,
walker
,
pContext
);
}
}
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
walkNode
(
pInterval
->
pFill
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pInterval
->
pFill
,
order
,
walker
,
pContext
);
}
}
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
walkNode
(
pInterval
->
pCol
,
order
,
walker
,
pContext
);
res
=
walkNode
(
pInterval
->
pCol
,
order
,
walker
,
pContext
);
}
}
break
;
break
;
...
@@ -126,7 +126,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
...
@@ -126,7 +126,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
break
;
break
;
}
}
if
(
DEAL_RES_ERROR
!=
res
&&
TRAVERSAL_POSTORDER
==
order
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
&&
TRAVERSAL_POSTORDER
==
order
)
{
res
=
walker
(
pNode
,
pContext
);
res
=
walker
(
pNode
,
pContext
);
}
}
...
@@ -136,8 +136,9 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
...
@@ -136,8 +136,9 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
static
EDealRes
walkList
(
SNodeList
*
pNodeList
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
)
{
static
EDealRes
walkList
(
SNodeList
*
pNodeList
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
)
{
SNode
*
node
;
SNode
*
node
;
FOREACH
(
node
,
pNodeList
)
{
FOREACH
(
node
,
pNodeList
)
{
if
(
DEAL_RES_ERROR
==
walkNode
(
node
,
order
,
walker
,
pContext
))
{
EDealRes
res
=
walkNode
(
node
,
order
,
walker
,
pContext
);
return
DEAL_RES_ERROR
;
if
(
DEAL_RES_ERROR
==
res
||
DEAL_RES_END
==
res
)
{
return
res
;
}
}
}
}
return
DEAL_RES_CONTINUE
;
return
DEAL_RES_CONTINUE
;
...
@@ -185,7 +186,7 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
...
@@ -185,7 +186,7 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
case
QUERY_NODE_OPERATOR
:
{
case
QUERY_NODE_OPERATOR
:
{
SOperatorNode
*
pOpNode
=
(
SOperatorNode
*
)
pNode
;
SOperatorNode
*
pOpNode
=
(
SOperatorNode
*
)
pNode
;
res
=
rewriteNode
(
&
(
pOpNode
->
pLeft
),
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
(
pOpNode
->
pLeft
),
order
,
rewriter
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
rewriteNode
(
&
(
pOpNode
->
pRight
),
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
(
pOpNode
->
pRight
),
order
,
rewriter
,
pContext
);
}
}
break
;
break
;
...
@@ -202,10 +203,10 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
...
@@ -202,10 +203,10 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
case
QUERY_NODE_JOIN_TABLE
:
{
case
QUERY_NODE_JOIN_TABLE
:
{
SJoinTableNode
*
pJoinTableNode
=
(
SJoinTableNode
*
)
pNode
;
SJoinTableNode
*
pJoinTableNode
=
(
SJoinTableNode
*
)
pNode
;
res
=
rewriteNode
(
&
(
pJoinTableNode
->
pLeft
),
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
(
pJoinTableNode
->
pLeft
),
order
,
rewriter
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
rewriteNode
(
&
(
pJoinTableNode
->
pRight
),
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
(
pJoinTableNode
->
pRight
),
order
,
rewriter
,
pContext
);
}
}
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
rewriteNode
(
&
(
pJoinTableNode
->
pOnCond
),
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
(
pJoinTableNode
->
pOnCond
),
order
,
rewriter
,
pContext
);
}
}
break
;
break
;
...
@@ -219,7 +220,7 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
...
@@ -219,7 +220,7 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
case
QUERY_NODE_STATE_WINDOW
:
{
case
QUERY_NODE_STATE_WINDOW
:
{
SStateWindowNode
*
pState
=
(
SStateWindowNode
*
)
pNode
;
SStateWindowNode
*
pState
=
(
SStateWindowNode
*
)
pNode
;
res
=
rewriteNode
(
&
pState
->
pExpr
,
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
pState
->
pExpr
,
order
,
rewriter
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
rewriteNode
(
&
pState
->
pCol
,
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
pState
->
pCol
,
order
,
rewriter
,
pContext
);
}
}
break
;
break
;
...
@@ -227,7 +228,7 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
...
@@ -227,7 +228,7 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
case
QUERY_NODE_SESSION_WINDOW
:
{
case
QUERY_NODE_SESSION_WINDOW
:
{
SSessionWindowNode
*
pSession
=
(
SSessionWindowNode
*
)
pNode
;
SSessionWindowNode
*
pSession
=
(
SSessionWindowNode
*
)
pNode
;
res
=
rewriteNode
(
&
pSession
->
pCol
,
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
pSession
->
pCol
,
order
,
rewriter
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
rewriteNode
(
&
pSession
->
pGap
,
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
pSession
->
pGap
,
order
,
rewriter
,
pContext
);
}
}
break
;
break
;
...
@@ -235,16 +236,16 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
...
@@ -235,16 +236,16 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
case
QUERY_NODE_INTERVAL_WINDOW
:
{
case
QUERY_NODE_INTERVAL_WINDOW
:
{
SIntervalWindowNode
*
pInterval
=
(
SIntervalWindowNode
*
)
pNode
;
SIntervalWindowNode
*
pInterval
=
(
SIntervalWindowNode
*
)
pNode
;
res
=
rewriteNode
(
&
(
pInterval
->
pInterval
),
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
(
pInterval
->
pInterval
),
order
,
rewriter
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
rewriteNode
(
&
(
pInterval
->
pOffset
),
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
(
pInterval
->
pOffset
),
order
,
rewriter
,
pContext
);
}
}
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
rewriteNode
(
&
(
pInterval
->
pSliding
),
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
(
pInterval
->
pSliding
),
order
,
rewriter
,
pContext
);
}
}
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
rewriteNode
(
&
(
pInterval
->
pFill
),
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
(
pInterval
->
pFill
),
order
,
rewriter
,
pContext
);
}
}
if
(
DEAL_RES_ERROR
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
rewriteNode
(
&
(
pInterval
->
pCol
),
order
,
rewriter
,
pContext
);
res
=
rewriteNode
(
&
(
pInterval
->
pCol
),
order
,
rewriter
,
pContext
);
}
}
break
;
break
;
...
@@ -265,7 +266,7 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
...
@@ -265,7 +266,7 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
break
;
break
;
}
}
if
(
DEAL_RES_ERROR
!=
res
&&
TRAVERSAL_POSTORDER
==
order
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
&&
TRAVERSAL_POSTORDER
==
order
)
{
res
=
rewriter
(
pRawNode
,
pContext
);
res
=
rewriter
(
pRawNode
,
pContext
);
}
}
...
@@ -275,8 +276,9 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
...
@@ -275,8 +276,9 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
static
EDealRes
rewriteList
(
SNodeList
*
pNodeList
,
ETraversalOrder
order
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
static
EDealRes
rewriteList
(
SNodeList
*
pNodeList
,
ETraversalOrder
order
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
SNode
**
pNode
;
SNode
**
pNode
;
FOREACH_FOR_REWRITE
(
pNode
,
pNodeList
)
{
FOREACH_FOR_REWRITE
(
pNode
,
pNodeList
)
{
if
(
DEAL_RES_ERROR
==
rewriteNode
(
pNode
,
order
,
rewriter
,
pContext
))
{
EDealRes
res
=
rewriteNode
(
pNode
,
order
,
rewriter
,
pContext
);
return
DEAL_RES_ERROR
;
if
(
DEAL_RES_ERROR
==
res
||
DEAL_RES_END
==
res
)
{
return
res
;
}
}
}
}
return
DEAL_RES_CONTINUE
;
return
DEAL_RES_CONTINUE
;
...
...
source/libs/parser/inc/sql.y
浏览文件 @
3a26ec4e
...
@@ -588,6 +588,7 @@ column_reference(A) ::= column_name(B).
...
@@ -588,6 +588,7 @@ column_reference(A) ::= column_name(B).
column_reference(A) ::= table_name(B) NK_DOT column_name(C). { A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); }
column_reference(A) ::= table_name(B) NK_DOT column_name(C). { A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); }
pseudo_column(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
pseudo_column(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
pseudo_column(A) ::= TODAY(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
pseudo_column(A) ::= ROWTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
pseudo_column(A) ::= ROWTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
pseudo_column(A) ::= TBNAME(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
pseudo_column(A) ::= TBNAME(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
pseudo_column(A) ::= QSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
pseudo_column(A) ::= QSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
3a26ec4e
...
@@ -335,8 +335,26 @@ SNode* createLogicConditionNode(SAstCreateContext* pCxt, ELogicConditionType typ
...
@@ -335,8 +335,26 @@ SNode* createLogicConditionNode(SAstCreateContext* pCxt, ELogicConditionType typ
CHECK_OUT_OF_MEM
(
cond
);
CHECK_OUT_OF_MEM
(
cond
);
cond
->
condType
=
type
;
cond
->
condType
=
type
;
cond
->
pParameterList
=
nodesMakeList
();
cond
->
pParameterList
=
nodesMakeList
();
if
((
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pParam1
)
&&
type
!=
((
SLogicConditionNode
*
)
pParam1
)
->
condType
)
||
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pParam2
)
&&
type
!=
((
SLogicConditionNode
*
)
pParam2
)
->
condType
))
{
nodesListAppend
(
cond
->
pParameterList
,
pParam1
);
nodesListAppend
(
cond
->
pParameterList
,
pParam1
);
nodesListAppend
(
cond
->
pParameterList
,
pParam2
);
nodesListAppend
(
cond
->
pParameterList
,
pParam2
);
}
else
{
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pParam1
))
{
nodesListAppendList
(
cond
->
pParameterList
,
((
SLogicConditionNode
*
)
pParam1
)
->
pParameterList
);
((
SLogicConditionNode
*
)
pParam1
)
->
pParameterList
=
NULL
;
nodesDestroyNode
(
pParam1
);
}
else
{
nodesListAppend
(
cond
->
pParameterList
,
pParam1
);
}
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pParam2
))
{
nodesListAppendList
(
cond
->
pParameterList
,
((
SLogicConditionNode
*
)
pParam2
)
->
pParameterList
);
((
SLogicConditionNode
*
)
pParam2
)
->
pParameterList
=
NULL
;
nodesDestroyNode
(
pParam2
);
}
else
{
nodesListAppend
(
cond
->
pParameterList
,
pParam2
);
}
}
return
(
SNode
*
)
cond
;
return
(
SNode
*
)
cond
;
}
}
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
3a26ec4e
...
@@ -325,6 +325,11 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time
...
@@ -325,6 +325,11 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time
for
(
int
k
=
pToken
->
n
;
pToken
->
z
[
k
]
!=
'\0'
;
k
++
)
{
for
(
int
k
=
pToken
->
n
;
pToken
->
z
[
k
]
!=
'\0'
;
k
++
)
{
if
(
pToken
->
z
[
k
]
==
' '
||
pToken
->
z
[
k
]
==
'\t'
)
continue
;
if
(
pToken
->
z
[
k
]
==
' '
||
pToken
->
z
[
k
]
==
'\t'
)
continue
;
if
(
pToken
->
z
[
k
]
==
'('
&&
pToken
->
z
[
k
+
1
]
==
')'
)
{
//for insert NOW()/TODAY()
*
end
=
pTokenEnd
=
&
pToken
->
z
[
k
+
2
];
k
++
;
continue
;
}
if
(
pToken
->
z
[
k
]
==
','
)
{
if
(
pToken
->
z
[
k
]
==
','
)
{
*
end
=
pTokenEnd
;
*
end
=
pTokenEnd
;
*
time
=
ts
;
*
time
=
ts
;
...
...
source/libs/parser/src/parTokenizer.c
浏览文件 @
3a26ec4e
...
@@ -175,6 +175,7 @@ static SKeyword keywordTable[] = {
...
@@ -175,6 +175,7 @@ static SKeyword keywordTable[] = {
{
"TBNAME"
,
TK_TBNAME
},
{
"TBNAME"
,
TK_TBNAME
},
{
"TIMESTAMP"
,
TK_TIMESTAMP
},
{
"TIMESTAMP"
,
TK_TIMESTAMP
},
{
"TINYINT"
,
TK_TINYINT
},
{
"TINYINT"
,
TK_TINYINT
},
{
"TODAY"
,
TK_TODAY
},
{
"TOPIC"
,
TK_TOPIC
},
{
"TOPIC"
,
TK_TOPIC
},
{
"TOPICS"
,
TK_TOPICS
},
{
"TOPICS"
,
TK_TOPICS
},
{
"TSERIES"
,
TK_TSERIES
},
{
"TSERIES"
,
TK_TSERIES
},
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
3a26ec4e
...
@@ -2363,7 +2363,6 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
...
@@ -2363,7 +2363,6 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
break
;
break
;
case
QUERY_NODE_SHOW_APPS_STMT
:
case
QUERY_NODE_SHOW_APPS_STMT
:
case
QUERY_NODE_SHOW_CONNECTIONS_STMT
:
case
QUERY_NODE_SHOW_CONNECTIONS_STMT
:
case
QUERY_NODE_SHOW_LICENCE_STMT
:
case
QUERY_NODE_SHOW_QUERIES_STMT
:
case
QUERY_NODE_SHOW_QUERIES_STMT
:
case
QUERY_NODE_SHOW_SCORES_STMT
:
case
QUERY_NODE_SHOW_SCORES_STMT
:
case
QUERY_NODE_SHOW_TOPICS_STMT
:
case
QUERY_NODE_SHOW_TOPICS_STMT
:
...
@@ -2551,6 +2550,8 @@ static const char* getSysTableName(ENodeType type) {
...
@@ -2551,6 +2550,8 @@ static const char* getSysTableName(ENodeType type) {
return
TSDB_INS_TABLE_BNODES
;
return
TSDB_INS_TABLE_BNODES
;
case
QUERY_NODE_SHOW_SNODES_STMT
:
case
QUERY_NODE_SHOW_SNODES_STMT
:
return
TSDB_INS_TABLE_SNODES
;
return
TSDB_INS_TABLE_SNODES
;
case
QUERY_NODE_SHOW_LICENCE_STMT
:
return
TSDB_INS_TABLE_LICENCES
;
default:
default:
break
;
break
;
}
}
...
@@ -3058,6 +3059,7 @@ static int32_t rewriteAlterTable(STranslateContext* pCxt, SQuery* pQuery) {
...
@@ -3058,6 +3059,7 @@ static int32_t rewriteAlterTable(STranslateContext* pCxt, SQuery* pQuery) {
static
int32_t
rewriteQuery
(
STranslateContext
*
pCxt
,
SQuery
*
pQuery
)
{
static
int32_t
rewriteQuery
(
STranslateContext
*
pCxt
,
SQuery
*
pQuery
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
nodeType
(
pQuery
->
pRoot
))
{
switch
(
nodeType
(
pQuery
->
pRoot
))
{
case
QUERY_NODE_SHOW_LICENCE_STMT
:
case
QUERY_NODE_SHOW_DATABASES_STMT
:
case
QUERY_NODE_SHOW_DATABASES_STMT
:
case
QUERY_NODE_SHOW_TABLES_STMT
:
case
QUERY_NODE_SHOW_TABLES_STMT
:
case
QUERY_NODE_SHOW_STABLES_STMT
:
case
QUERY_NODE_SHOW_STABLES_STMT
:
...
...
source/libs/parser/src/sql.c
浏览文件 @
3a26ec4e
此差异已折叠。
点击以展开。
source/libs/parser/test/mockCatalogService.cpp
浏览文件 @
3a26ec4e
...
@@ -146,6 +146,7 @@ public:
...
@@ -146,6 +146,7 @@ public:
meta_
[
db
][
tbname
].
reset
(
new
MockTableMeta
());
meta_
[
db
][
tbname
].
reset
(
new
MockTableMeta
());
meta_
[
db
][
tbname
]
->
schema
=
table
.
release
();
meta_
[
db
][
tbname
]
->
schema
=
table
.
release
();
meta_
[
db
][
tbname
]
->
schema
->
uid
=
id_
++
;
meta_
[
db
][
tbname
]
->
schema
->
uid
=
id_
++
;
meta_
[
db
][
tbname
]
->
schema
->
tableType
=
TSDB_CHILD_TABLE
;
SVgroupInfo
vgroup
=
{.
vgId
=
vgid
,
.
hashBegin
=
0
,
.
hashEnd
=
0
,};
SVgroupInfo
vgroup
=
{.
vgId
=
vgid
,
.
hashBegin
=
0
,
.
hashEnd
=
0
,};
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_1"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_1"
,
6030
);
...
@@ -197,11 +198,11 @@ public:
...
@@ -197,11 +198,11 @@ public:
std
::
cout
<<
"Table:"
<<
table
.
first
<<
std
::
endl
;
std
::
cout
<<
"Table:"
<<
table
.
first
<<
std
::
endl
;
std
::
cout
<<
SH
(
"Field"
)
<<
SH
(
"Type"
)
<<
SH
(
"DataType"
)
<<
IH
(
"Bytes"
)
<<
std
::
endl
;
std
::
cout
<<
SH
(
"Field"
)
<<
SH
(
"Type"
)
<<
SH
(
"DataType"
)
<<
IH
(
"Bytes"
)
<<
std
::
endl
;
std
::
cout
<<
SL
(
3
,
1
)
<<
std
::
endl
;
std
::
cout
<<
SL
(
3
,
1
)
<<
std
::
endl
;
int16_t
numOf
Tags
=
schema
->
tableInfo
.
numOfTag
s
;
int16_t
numOf
Columns
=
schema
->
tableInfo
.
numOfColumn
s
;
int16_t
numOfFields
=
numOf
Tags
+
schema
->
tableInfo
.
numOfColumn
s
;
int16_t
numOfFields
=
numOf
Columns
+
schema
->
tableInfo
.
numOfTag
s
;
for
(
int16_t
i
=
0
;
i
<
numOfFields
;
++
i
)
{
for
(
int16_t
i
=
0
;
i
<
numOfFields
;
++
i
)
{
const
SSchema
*
col
=
schema
->
schema
+
i
;
const
SSchema
*
col
=
schema
->
schema
+
i
;
std
::
cout
<<
SF
(
std
::
string
(
col
->
name
))
<<
SH
(
ftToString
(
i
,
numOf
Tag
s
))
<<
SH
(
dtToString
(
col
->
type
))
<<
IF
(
col
->
bytes
)
<<
std
::
endl
;
std
::
cout
<<
SF
(
std
::
string
(
col
->
name
))
<<
SH
(
ftToString
(
i
,
numOf
Column
s
))
<<
SH
(
dtToString
(
col
->
type
))
<<
IF
(
col
->
bytes
)
<<
std
::
endl
;
}
}
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
}
}
...
@@ -262,8 +263,8 @@ private:
...
@@ -262,8 +263,8 @@ private:
return
tDataTypes
[
type
].
name
;
return
tDataTypes
[
type
].
name
;
}
}
std
::
string
ftToString
(
int16_t
colid
,
int16_t
numOf
Tag
s
)
const
{
std
::
string
ftToString
(
int16_t
colid
,
int16_t
numOf
Column
s
)
const
{
return
(
0
==
colid
?
"column"
:
(
colid
<=
numOf
Tag
s
?
"tag"
:
"column"
));
return
(
0
==
colid
?
"column"
:
(
colid
<=
numOf
Column
s
?
"tag"
:
"column"
));
}
}
STableMeta
*
getTableSchemaMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
)
const
{
STableMeta
*
getTableSchemaMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
)
const
{
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
3a26ec4e
...
@@ -694,7 +694,6 @@ static int32_t createPartitionLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pS
...
@@ -694,7 +694,6 @@ static int32_t createPartitionLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pS
}
}
return
code
;
return
code
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
createDistinctLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SLogicNode
**
pLogicNode
)
{
static
int32_t
createDistinctLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SLogicNode
**
pLogicNode
)
{
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
3a26ec4e
...
@@ -41,6 +41,21 @@ typedef struct SOsdInfo {
...
@@ -41,6 +41,21 @@ typedef struct SOsdInfo {
SNodeList
*
pDsoFuncs
;
SNodeList
*
pDsoFuncs
;
}
SOsdInfo
;
}
SOsdInfo
;
typedef
struct
SCpdIsMultiTableCondCxt
{
SNodeList
*
pLeftCols
;
SNodeList
*
pRightCols
;
bool
havaLeftCol
;
bool
haveRightCol
;
}
SCpdIsMultiTableCondCxt
;
typedef
enum
ECondAction
{
COND_ACTION_STAY
=
1
,
COND_ACTION_PUSH_JOIN
,
COND_ACTION_PUSH_LEFT_CHILD
,
COND_ACTION_PUSH_RIGHT_CHILD
// after supporting outer join, there are other possibilities
}
ECondAction
;
static
bool
osdMayBeOptimized
(
SLogicNode
*
pNode
)
{
static
bool
osdMayBeOptimized
(
SLogicNode
*
pNode
)
{
if
(
OPTIMIZE_FLAG_TEST_MASK
(
pNode
->
optimizedFlag
,
OPTIMIZE_FLAG_OSD
))
{
if
(
OPTIMIZE_FLAG_TEST_MASK
(
pNode
->
optimizedFlag
,
OPTIMIZE_FLAG_OSD
))
{
return
false
;
return
false
;
...
@@ -152,34 +167,227 @@ static int32_t cpdOptimizeScanCondition(SOptimizeContext* pCxt, SScanLogicNode*
...
@@ -152,34 +167,227 @@ static int32_t cpdOptimizeScanCondition(SOptimizeContext* pCxt, SScanLogicNode*
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
cpdPartitionCondition
(
SJoinLogicNode
*
pJoin
,
SNodeList
**
pMultiTableCond
,
SNodeList
**
pSingleTableCond
)
{
static
bool
belongThisTable
(
SNode
*
pCondCol
,
SNodeList
*
pTableCols
)
{
// todo
SNode
*
pTableCol
=
NULL
;
FOREACH
(
pTableCol
,
pTableCols
)
{
if
(
nodesEqualNode
(
pCondCol
,
pTableCol
))
{
return
true
;
}
}
return
false
;
}
static
EDealRes
cpdIsMultiTableCondImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
SCpdIsMultiTableCondCxt
*
pCxt
=
pContext
;
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
if
(
belongThisTable
(
pNode
,
pCxt
->
pLeftCols
))
{
pCxt
->
havaLeftCol
=
true
;
}
else
if
(
belongThisTable
(
pNode
,
pCxt
->
pRightCols
))
{
pCxt
->
haveRightCol
=
true
;
}
return
pCxt
->
havaLeftCol
&&
pCxt
->
haveRightCol
?
DEAL_RES_END
:
DEAL_RES_CONTINUE
;
}
return
DEAL_RES_CONTINUE
;
}
static
ECondAction
cpdCondAction
(
EJoinType
joinType
,
SNodeList
*
pLeftCols
,
SNodeList
*
pRightCols
,
SNode
*
pNode
)
{
SCpdIsMultiTableCondCxt
cxt
=
{
.
pLeftCols
=
pLeftCols
,
.
pRightCols
=
pRightCols
,
.
havaLeftCol
=
false
,
.
haveRightCol
=
false
};
nodesWalkExpr
(
pNode
,
cpdIsMultiTableCondImpl
,
&
cxt
);
return
(
JOIN_TYPE_INNER
!=
joinType
?
COND_ACTION_STAY
:
(
cxt
.
havaLeftCol
&&
cxt
.
haveRightCol
?
COND_ACTION_PUSH_JOIN
:
(
cxt
.
havaLeftCol
?
COND_ACTION_PUSH_LEFT_CHILD
:
COND_ACTION_PUSH_RIGHT_CHILD
)));
}
static
int32_t
cpdMakeCond
(
SNodeList
**
pConds
,
SNode
**
pCond
)
{
if
(
NULL
==
*
pConds
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
1
==
LIST_LENGTH
(
*
pConds
))
{
*
pCond
=
nodesListGetNode
(
*
pConds
,
0
);
nodesClearList
(
*
pConds
);
}
else
{
SLogicConditionNode
*
pLogicCond
=
nodesMakeNode
(
QUERY_NODE_LOGIC_CONDITION
);
if
(
NULL
==
pLogicCond
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pLogicCond
->
condType
=
LOGIC_COND_TYPE_AND
;
pLogicCond
->
pParameterList
=
*
pConds
;
*
pCond
=
(
SNode
*
)
pLogicCond
;
}
*
pConds
=
NULL
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
cpdPushJoinCondToOnCond
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
,
SNodeList
*
pMultiTableCond
)
{
static
int32_t
cpdPartitionLogicCond
(
SJoinLogicNode
*
pJoin
,
SNode
**
pOnCond
,
SNode
**
pLeftChildCond
,
SNode
**
pRightChildCond
)
{
// todo
SLogicConditionNode
*
pLogicCond
=
(
SLogicConditionNode
*
)
pJoin
->
node
.
pConditions
;
if
(
LOGIC_COND_TYPE_AND
!=
pLogicCond
->
condType
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
SNodeList
*
pLeftCols
=
((
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
0
))
->
pTargets
;
SNodeList
*
pRightCols
=
((
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
1
))
->
pTargets
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
SNodeList
*
pOnConds
=
NULL
;
SNodeList
*
pLeftChildConds
=
NULL
;
SNodeList
*
pRightChildConds
=
NULL
;
SNodeList
*
pRemainConds
=
NULL
;
SNode
*
pCond
=
NULL
;
FOREACH
(
pCond
,
pLogicCond
->
pParameterList
)
{
ECondAction
condAction
=
cpdCondAction
(
pJoin
->
joinType
,
pLeftCols
,
pRightCols
,
pCond
);
if
(
COND_ACTION_PUSH_JOIN
==
condAction
)
{
code
=
nodesListMakeAppend
(
&
pOnConds
,
nodesCloneNode
(
pCond
));
}
else
if
(
COND_ACTION_PUSH_LEFT_CHILD
==
condAction
)
{
code
=
nodesListMakeAppend
(
&
pLeftChildConds
,
nodesCloneNode
(
pCond
));
}
else
if
(
COND_ACTION_PUSH_RIGHT_CHILD
==
condAction
)
{
code
=
nodesListMakeAppend
(
&
pRightChildConds
,
nodesCloneNode
(
pCond
));
}
else
{
code
=
nodesListMakeAppend
(
&
pRemainConds
,
nodesCloneNode
(
pCond
));
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
break
;
}
}
SNode
*
pTempOnCond
=
NULL
;
SNode
*
pTempLeftChildCond
=
NULL
;
SNode
*
pTempRightChildCond
=
NULL
;
SNode
*
pTempRemainCond
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
cpdMakeCond
(
&
pOnConds
,
&
pTempOnCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
cpdMakeCond
(
&
pLeftChildConds
,
&
pTempLeftChildCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
cpdMakeCond
(
&
pRightChildConds
,
&
pTempRightChildCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
cpdMakeCond
(
&
pRemainConds
,
&
pTempRemainCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pOnCond
=
pTempOnCond
;
*
pLeftChildCond
=
pTempLeftChildCond
;
*
pRightChildCond
=
pTempRightChildCond
;
nodesDestroyNode
(
pJoin
->
node
.
pConditions
);
pJoin
->
node
.
pConditions
=
pTempRemainCond
;
}
else
{
nodesDestroyList
(
pOnConds
);
nodesDestroyList
(
pLeftChildConds
);
nodesDestroyList
(
pRightChildConds
);
nodesDestroyList
(
pRemainConds
);
nodesDestroyNode
(
pTempOnCond
);
nodesDestroyNode
(
pTempLeftChildCond
);
nodesDestroyNode
(
pTempRightChildCond
);
nodesDestroyNode
(
pTempRemainCond
);
}
return
code
;
}
}
static
int32_t
cpdPushJoinCondToChildren
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
,
SNodeList
*
pSingleTableCond
)
{
static
int32_t
cpdPartitionOpCond
(
SJoinLogicNode
*
pJoin
,
SNode
**
pOnCond
,
SNode
**
pLeftChildCond
,
SNode
**
pRightChildCond
)
{
// todo
SNodeList
*
pLeftCols
=
((
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
0
))
->
pTargets
;
SNodeList
*
pRightCols
=
((
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
1
))
->
pTargets
;
ECondAction
condAction
=
cpdCondAction
(
pJoin
->
joinType
,
pLeftCols
,
pRightCols
,
pJoin
->
node
.
pConditions
);
if
(
COND_ACTION_STAY
==
condAction
)
{
return
TSDB_CODE_SUCCESS
;
}
else
if
(
COND_ACTION_PUSH_JOIN
==
condAction
)
{
*
pOnCond
=
pJoin
->
node
.
pConditions
;
}
else
if
(
COND_ACTION_PUSH_LEFT_CHILD
==
condAction
)
{
*
pLeftChildCond
=
pJoin
->
node
.
pConditions
;
}
else
if
(
COND_ACTION_PUSH_RIGHT_CHILD
==
condAction
)
{
*
pRightChildCond
=
pJoin
->
node
.
pConditions
;
}
pJoin
->
node
.
pConditions
=
NULL
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
cpdPushJoinCondition
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
)
{
static
int32_t
cpdPartitionCond
(
SJoinLogicNode
*
pJoin
,
SNode
**
pOnCond
,
SNode
**
pLeftChildCond
,
SNode
**
pRightChildCond
)
{
if
(
NULL
!=
pJoin
->
node
.
pConditions
)
{
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pJoin
->
node
.
pConditions
))
{
SNodeList
*
pMultiTableCond
=
NULL
;
return
cpdPartitionLogicCond
(
pJoin
,
pOnCond
,
pLeftChildCond
,
pRightChildCond
);
SNodeList
*
pSingleTableCond
=
NULL
;
}
else
{
int32_t
code
=
cpdPartitionCondition
(
pJoin
,
&
pMultiTableCond
,
&
pSingleTableCond
);
return
cpdPartitionOpCond
(
pJoin
,
pOnCond
,
pLeftChildCond
,
pRightChildCond
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pMultiTableCond
)
{
code
=
cpdPushJoinCondToOnCond
(
pCxt
,
pJoin
,
pMultiTableCond
);
}
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pSingleTableCond
)
{
}
code
=
cpdPushJoinCondToChildren
(
pCxt
,
pJoin
,
pSingleTableCond
);
static
int32_t
cpdCondAppend
(
SOptimizeContext
*
pCxt
,
SNode
**
pCond
,
SNode
**
pAdditionalCond
)
{
if
(
NULL
==
*
pCond
)
{
TSWAP
(
*
pCond
,
*
pAdditionalCond
,
SNode
*
);
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
*
pCond
))
{
code
=
nodesListAppend
(((
SLogicConditionNode
*
)
*
pCond
)
->
pParameterList
,
*
pAdditionalCond
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pAdditionalCond
=
NULL
;
}
}
else
{
SLogicConditionNode
*
pLogicCond
=
nodesMakeNode
(
QUERY_NODE_LOGIC_CONDITION
);
if
(
NULL
==
pLogicCond
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pLogicCond
->
condType
=
LOGIC_COND_TYPE_AND
;
code
=
nodesListMakeAppend
(
&
pLogicCond
->
pParameterList
,
*
pAdditionalCond
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pAdditionalCond
=
NULL
;
code
=
nodesListMakeAppend
(
&
pLogicCond
->
pParameterList
,
*
pCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pCond
=
(
SNode
*
)
pLogicCond
;
}
else
{
nodesDestroyNode
(
pLogicCond
);
}
}
return
code
;
}
static
int32_t
cpdPushCondToOnCond
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
,
SNode
**
pCond
)
{
return
cpdCondAppend
(
pCxt
,
&
pJoin
->
pOnConditions
,
pCond
);
}
static
int32_t
cpdPushCondToScan
(
SOptimizeContext
*
pCxt
,
SScanLogicNode
*
pScan
,
SNode
**
pCond
)
{
return
cpdCondAppend
(
pCxt
,
&
pScan
->
node
.
pConditions
,
pCond
);
}
static
int32_t
cpdPushCondToChild
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pChild
,
SNode
**
pCond
)
{
switch
(
nodeType
(
pChild
))
{
case
QUERY_NODE_LOGIC_PLAN_SCAN
:
return
cpdPushCondToScan
(
pCxt
,
(
SScanLogicNode
*
)
pChild
,
pCond
);
default:
break
;
}
}
return
TSDB_CODE_PLAN_INTERNAL_ERROR
;
}
static
int32_t
cpdPushJoinCondition
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
)
{
if
(
NULL
==
pJoin
->
node
.
pConditions
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
SNode
*
pOnCond
=
NULL
;
SNode
*
pLeftChildCond
=
NULL
;
SNode
*
pRightChildCond
=
NULL
;
int32_t
code
=
cpdPartitionCond
(
pJoin
,
&
pOnCond
,
&
pLeftChildCond
,
&
pRightChildCond
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pOnCond
)
{
code
=
cpdPushCondToOnCond
(
pCxt
,
pJoin
,
&
pOnCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pLeftChildCond
)
{
code
=
cpdPushCondToChild
(
pCxt
,
(
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
0
),
&
pLeftChildCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pRightChildCond
)
{
code
=
cpdPushCondToChild
(
pCxt
,
(
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
1
),
&
pRightChildCond
);
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
nodesDestroyNode
(
pOnCond
);
nodesDestroyNode
(
pLeftChildCond
);
nodesDestroyNode
(
pRightChildCond
);
}
return
code
;
}
}
static
int32_t
cpdPushAggCondition
(
SOptimizeContext
*
pCxt
,
SAggLogicNode
*
pAgg
)
{
static
int32_t
cpdPushAggCondition
(
SOptimizeContext
*
pCxt
,
SAggLogicNode
*
pAgg
)
{
...
...
source/libs/planner/src/planSpliter.c
浏览文件 @
3a26ec4e
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#define SPLIT_FLAG_MASK(n) (1 << n)
#define SPLIT_FLAG_MASK(n) (1 << n)
#define SPLIT_FLAG_STS SPLIT_FLAG_MASK(0)
#define SPLIT_FLAG_STS SPLIT_FLAG_MASK(0)
#define SPLIT_FLAG_CTJ SPLIT_FLAG_MASK(1)
#define SPLIT_FLAG_SET_MASK(val, mask) (val) |= (mask)
#define SPLIT_FLAG_SET_MASK(val, mask) (val) |= (mask)
#define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
#define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
...
@@ -39,43 +40,14 @@ typedef struct SStsInfo {
...
@@ -39,43 +40,14 @@ typedef struct SStsInfo {
SLogicSubplan
*
pSubplan
;
SLogicSubplan
*
pSubplan
;
}
SStsInfo
;
}
SStsInfo
;
static
SLogicNode
*
stsMatchByNode
(
SLogicNode
*
pNode
)
{
typedef
struct
SCtjInfo
{
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pNode
)
&&
SScanLogicNode
*
pScan
;
NULL
!=
((
SScanLogicNode
*
)
pNode
)
->
pVgroupList
&&
((
SScanLogicNode
*
)
pNode
)
->
pVgroupList
->
numOfVgroups
>
1
)
{
SLogicSubplan
*
pSubplan
;
return
pNode
;
}
SCtjInfo
;
}
SNode
*
pChild
;
FOREACH
(
pChild
,
pNode
->
pChildren
)
{
SLogicNode
*
pSplitNode
=
stsMatchByNode
((
SLogicNode
*
)
pChild
);
if
(
NULL
!=
pSplitNode
)
{
return
pSplitNode
;
}
}
return
NULL
;
}
static
void
stsFindSplitNode
(
SLogicSubplan
*
pSubplan
,
SStsInfo
*
pInfo
)
{
typedef
bool
(
*
FSplFindSplitNode
)(
SLogicSubplan
*
pSubplan
,
SStsInfo
*
pInfo
);
SLogicNode
*
pSplitNode
=
stsMatchByNode
(
pSubplan
->
pNode
);
if
(
NULL
!=
pSplitNode
)
{
pInfo
->
pScan
=
(
SScanLogicNode
*
)
pSplitNode
;
pInfo
->
pSubplan
=
pSubplan
;
}
}
static
void
stsMatch
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
SStsInfo
*
pInfo
)
{
if
(
!
SPLIT_FLAG_TEST_MASK
(
pSubplan
->
splitFlag
,
SPLIT_FLAG_STS
))
{
stsFindSplitNode
(
pSubplan
,
pInfo
);
}
SNode
*
pChild
;
FOREACH
(
pChild
,
pSubplan
->
pChildren
)
{
stsMatch
(
pCxt
,
(
SLogicSubplan
*
)
pChild
,
pInfo
);
if
(
NULL
!=
pInfo
->
pScan
)
{
break
;
}
}
return
;
}
static
SLogicSubplan
*
s
tsCreateScanSubplan
(
SSplitContext
*
pCxt
,
SScanLogicNode
*
pScan
)
{
static
SLogicSubplan
*
s
plCreateScanSubplan
(
SSplitContext
*
pCxt
,
SScanLogicNode
*
pScan
,
int32_t
flag
)
{
SLogicSubplan
*
pSubplan
=
nodesMakeNode
(
QUERY_NODE_LOGIC_SUBPLAN
);
SLogicSubplan
*
pSubplan
=
nodesMakeNode
(
QUERY_NODE_LOGIC_SUBPLAN
);
if
(
NULL
==
pSubplan
)
{
if
(
NULL
==
pSubplan
)
{
return
NULL
;
return
NULL
;
...
@@ -84,11 +56,11 @@ static SLogicSubplan* stsCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode*
...
@@ -84,11 +56,11 @@ static SLogicSubplan* stsCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode*
pSubplan
->
subplanType
=
SUBPLAN_TYPE_SCAN
;
pSubplan
->
subplanType
=
SUBPLAN_TYPE_SCAN
;
pSubplan
->
pNode
=
(
SLogicNode
*
)
nodesCloneNode
(
pScan
);
pSubplan
->
pNode
=
(
SLogicNode
*
)
nodesCloneNode
(
pScan
);
TSWAP
(
pSubplan
->
pVgroupList
,
((
SScanLogicNode
*
)
pSubplan
->
pNode
)
->
pVgroupList
,
SVgroupsInfo
*
);
TSWAP
(
pSubplan
->
pVgroupList
,
((
SScanLogicNode
*
)
pSubplan
->
pNode
)
->
pVgroupList
,
SVgroupsInfo
*
);
SPLIT_FLAG_SET_MASK
(
pSubplan
->
splitFlag
,
SPLIT_FLAG_STS
);
SPLIT_FLAG_SET_MASK
(
pSubplan
->
splitFlag
,
flag
);
return
pSubplan
;
return
pSubplan
;
}
}
static
int32_t
s
tsCreateExchangeNode
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
SScanLogicNode
*
pScan
)
{
static
int32_t
s
plCreateExchangeNode
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
SScanLogicNode
*
pScan
,
ESubplanType
subplanType
)
{
SExchangeLogicNode
*
pExchange
=
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_EXCHANGE
);
SExchangeLogicNode
*
pExchange
=
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_EXCHANGE
);
if
(
NULL
==
pExchange
)
{
if
(
NULL
==
pExchange
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
...
@@ -119,10 +91,100 @@ static int32_t stsCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla
...
@@ -119,10 +91,100 @@ static int32_t stsCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla
return
TSDB_CODE_FAILED
;
return
TSDB_CODE_FAILED
;
}
}
static
bool
splMatch
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
int32_t
flag
,
FSplFindSplitNode
func
,
void
*
pInfo
)
{
if
(
!
SPLIT_FLAG_TEST_MASK
(
pSubplan
->
splitFlag
,
flag
))
{
if
(
func
(
pSubplan
,
pInfo
))
{
return
true
;
}
}
SNode
*
pChild
;
FOREACH
(
pChild
,
pSubplan
->
pChildren
)
{
if
(
splMatch
(
pCxt
,
(
SLogicSubplan
*
)
pChild
,
flag
,
func
,
pInfo
))
{
return
true
;
}
}
return
false
;
}
static
SLogicNode
*
stsMatchByNode
(
SLogicNode
*
pNode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pNode
)
&&
NULL
!=
((
SScanLogicNode
*
)
pNode
)
->
pVgroupList
&&
((
SScanLogicNode
*
)
pNode
)
->
pVgroupList
->
numOfVgroups
>
1
)
{
return
pNode
;
}
SNode
*
pChild
;
FOREACH
(
pChild
,
pNode
->
pChildren
)
{
SLogicNode
*
pSplitNode
=
stsMatchByNode
((
SLogicNode
*
)
pChild
);
if
(
NULL
!=
pSplitNode
)
{
return
pSplitNode
;
}
}
return
NULL
;
}
static
bool
stsFindSplitNode
(
SLogicSubplan
*
pSubplan
,
SStsInfo
*
pInfo
)
{
SLogicNode
*
pSplitNode
=
stsMatchByNode
(
pSubplan
->
pNode
);
if
(
NULL
!=
pSplitNode
)
{
pInfo
->
pScan
=
(
SScanLogicNode
*
)
pSplitNode
;
pInfo
->
pSubplan
=
pSubplan
;
}
return
NULL
!=
pSplitNode
;
}
static
int32_t
stsSplit
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
)
{
static
int32_t
stsSplit
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
)
{
SStsInfo
info
=
{
0
};
SStsInfo
info
=
{
0
};
stsMatch
(
pCxt
,
pSubplan
,
&
info
);
if
(
!
splMatch
(
pCxt
,
pSubplan
,
SPLIT_FLAG_STS
,
stsFindSplitNode
,
&
info
))
{
if
(
NULL
==
info
.
pScan
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
NULL
==
info
.
pSubplan
->
pChildren
)
{
info
.
pSubplan
->
pChildren
=
nodesMakeList
();
if
(
NULL
==
info
.
pSubplan
->
pChildren
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
int32_t
code
=
nodesListStrictAppend
(
info
.
pSubplan
->
pChildren
,
splCreateScanSubplan
(
pCxt
,
info
.
pScan
,
SPLIT_FLAG_STS
));
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
splCreateExchangeNode
(
pCxt
,
info
.
pSubplan
,
info
.
pScan
,
SUBPLAN_TYPE_MERGE
);
}
++
(
pCxt
->
groupId
);
pCxt
->
split
=
true
;
return
code
;
}
static
bool
ctjIsSingleTable
(
int8_t
tableType
)
{
return
(
TSDB_CHILD_TABLE
==
tableType
||
TSDB_NORMAL_TABLE
==
tableType
);
}
static
SLogicNode
*
ctjMatchByNode
(
SLogicNode
*
pNode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_JOIN
==
nodeType
(
pNode
))
{
SLogicNode
*
pLeft
=
(
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
);
SLogicNode
*
pRight
=
(
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
1
);
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pLeft
)
&&
ctjIsSingleTable
(((
SScanLogicNode
*
)
pLeft
)
->
pMeta
->
tableType
)
&&
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pRight
)
&&
ctjIsSingleTable
(((
SScanLogicNode
*
)
pRight
)
->
pMeta
->
tableType
))
{
return
pRight
;
}
}
SNode
*
pChild
;
FOREACH
(
pChild
,
pNode
->
pChildren
)
{
SLogicNode
*
pSplitNode
=
ctjMatchByNode
((
SLogicNode
*
)
pChild
);
if
(
NULL
!=
pSplitNode
)
{
return
pSplitNode
;
}
}
return
NULL
;
}
static
bool
ctjFindSplitNode
(
SLogicSubplan
*
pSubplan
,
SStsInfo
*
pInfo
)
{
SLogicNode
*
pSplitNode
=
ctjMatchByNode
(
pSubplan
->
pNode
);
if
(
NULL
!=
pSplitNode
)
{
pInfo
->
pScan
=
(
SScanLogicNode
*
)
pSplitNode
;
pInfo
->
pSubplan
=
pSubplan
;
}
return
NULL
!=
pSplitNode
;
}
static
int32_t
ctjSplit
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
)
{
SCtjInfo
info
=
{
0
};
if
(
!
splMatch
(
pCxt
,
pSubplan
,
SPLIT_FLAG_CTJ
,
ctjFindSplitNode
,
&
info
))
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
NULL
==
info
.
pSubplan
->
pChildren
)
{
if
(
NULL
==
info
.
pSubplan
->
pChildren
)
{
...
@@ -131,9 +193,9 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
...
@@ -131,9 +193,9 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
}
}
int32_t
code
=
nodesListStrictAppend
(
info
.
pSubplan
->
pChildren
,
s
tsCreateScanSubplan
(
pCxt
,
info
.
pScan
));
int32_t
code
=
nodesListStrictAppend
(
info
.
pSubplan
->
pChildren
,
s
plCreateScanSubplan
(
pCxt
,
info
.
pScan
,
SPLIT_FLAG_CTJ
));
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
s
tsCreateExchangeNode
(
pCxt
,
info
.
pSubplan
,
info
.
pScan
);
code
=
s
plCreateExchangeNode
(
pCxt
,
info
.
pSubplan
,
info
.
pScan
,
info
.
pSubplan
->
subplanType
);
}
}
++
(
pCxt
->
groupId
);
++
(
pCxt
->
groupId
);
pCxt
->
split
=
true
;
pCxt
->
split
=
true
;
...
@@ -141,7 +203,8 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
...
@@ -141,7 +203,8 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
}
}
static
const
SSplitRule
splitRuleSet
[]
=
{
static
const
SSplitRule
splitRuleSet
[]
=
{
{
.
pName
=
"SuperTableScan"
,
.
splitFunc
=
stsSplit
}
{
.
pName
=
"SuperTableScan"
,
.
splitFunc
=
stsSplit
},
{
.
pName
=
"ChildTableJoin"
,
.
splitFunc
=
ctjSplit
},
};
};
static
const
int32_t
splitRuleNum
=
(
sizeof
(
splitRuleSet
)
/
sizeof
(
SSplitRule
));
static
const
int32_t
splitRuleNum
=
(
sizeof
(
splitRuleSet
)
/
sizeof
(
SSplitRule
));
...
...
source/libs/planner/test/plannerTest.cpp
浏览文件 @
3a26ec4e
...
@@ -70,6 +70,12 @@ protected:
...
@@ -70,6 +70,12 @@ protected:
cout
<<
"unformatted logic plan : "
<<
endl
;
cout
<<
"unformatted logic plan : "
<<
endl
;
cout
<<
toString
((
const
SNode
*
)
pLogicNode
,
false
)
<<
endl
;
cout
<<
toString
((
const
SNode
*
)
pLogicNode
,
false
)
<<
endl
;
code
=
optimizeLogicPlan
(
&
cxt
,
pLogicNode
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
cout
<<
"sql:["
<<
cxt_
.
pSql
<<
"] optimizeLogicPlan code:"
<<
code
<<
", strerror:"
<<
tstrerror
(
code
)
<<
endl
;
return
false
;
}
SLogicSubplan
*
pLogicSubplan
=
nullptr
;
SLogicSubplan
*
pLogicSubplan
=
nullptr
;
code
=
splitLogicPlan
(
&
cxt
,
pLogicNode
,
&
pLogicSubplan
);
code
=
splitLogicPlan
(
&
cxt
,
pLogicNode
,
&
pLogicSubplan
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
@@ -174,13 +180,13 @@ TEST_F(PlannerTest, selectStableBasic) {
...
@@ -174,13 +180,13 @@ TEST_F(PlannerTest, selectStableBasic) {
TEST_F
(
PlannerTest
,
selectJoin
)
{
TEST_F
(
PlannerTest
,
selectJoin
)
{
setDatabase
(
"root"
,
"test"
);
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT *
FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"
);
// bind("SELECT t1.c1, t2.c2
FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts");
ASSERT_TRUE
(
run
());
//
ASSERT_TRUE(run());
bind
(
"SELECT * FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1
"
);
// bind("SELECT t1.*, t2.* FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts
");
ASSERT_TRUE
(
run
());
//
ASSERT_TRUE(run());
bind
(
"SELECT t1.
* FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1
"
);
bind
(
"SELECT t1.
c1, t2.c1 FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1 and t1.c2 = 'abc' and t2.c2 = 'qwe'
"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
}
}
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
3a26ec4e
...
@@ -1104,6 +1104,144 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
...
@@ -1104,6 +1104,144 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
timeDiffFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
if
(
inputNum
!=
2
&&
inputNum
!=
3
)
{
return
TSDB_CODE_FAILED
;
}
int32_t
timePrec
=
GET_PARAM_PRECISON
(
&
pInput
[
0
]);
int64_t
timeUnit
=
-
1
,
timeVal
[
2
]
=
{
0
};
if
(
inputNum
==
3
)
{
if
(
GET_PARAM_TYPE
(
&
pInput
[
2
])
!=
TSDB_DATA_TYPE_BIGINT
)
{
return
TSDB_CODE_FAILED
;
}
GET_TYPED_DATA
(
timeUnit
,
int64_t
,
GET_PARAM_TYPE
(
&
pInput
[
2
]),
pInput
[
2
].
columnData
->
pData
);
}
char
*
input
[
2
];
for
(
int32_t
k
=
0
;
k
<
2
;
++
k
)
{
int32_t
type
=
GET_PARAM_TYPE
(
&
pInput
[
k
]);
if
(
type
!=
TSDB_DATA_TYPE_BIGINT
&&
type
!=
TSDB_DATA_TYPE_TIMESTAMP
&&
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
)
{
return
TSDB_CODE_FAILED
;
}
if
(
IS_VAR_DATA_TYPE
(
type
))
{
input
[
k
]
=
pInput
[
k
].
columnData
->
pData
+
pInput
[
k
].
columnData
->
varmeta
.
offset
[
0
];
}
else
{
input
[
k
]
=
pInput
[
k
].
columnData
->
pData
;
}
}
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
for
(
int32_t
k
=
0
;
k
<
2
;
++
k
)
{
if
(
colDataIsNull_s
(
pInput
[
0
].
columnData
,
i
))
{
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
int32_t
type
=
GET_PARAM_TYPE
(
&
pInput
[
k
]);
if
(
IS_VAR_DATA_TYPE
(
type
))
{
/* datetime format strings */
convertStringToTimestamp
(
type
,
input
[
k
],
TSDB_TIME_PRECISION_NANO
,
&
timeVal
[
k
]);
}
else
if
(
type
==
TSDB_DATA_TYPE_BIGINT
||
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
/* unix timestamp or ts column*/
GET_TYPED_DATA
(
timeVal
[
k
],
int64_t
,
type
,
input
[
k
]);
if
(
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
int64_t
timeValSec
=
timeVal
[
k
]
/
factor
;
if
(
timeValSec
<
1000000000
)
{
timeVal
[
k
]
=
timeValSec
;
}
}
char
buf
[
20
]
=
{
0
};
NUM_TO_STRING
(
TSDB_DATA_TYPE_BIGINT
,
&
timeVal
[
k
],
sizeof
(
buf
),
buf
);
int32_t
tsDigits
=
(
int32_t
)
strlen
(
buf
);
if
(
tsDigits
<=
TSDB_TIME_PRECISION_SEC_DIGITS
)
{
timeVal
[
k
]
=
timeVal
[
k
]
*
1000000000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_MILLI_DIGITS
)
{
timeVal
[
k
]
=
timeVal
[
k
]
*
1000000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_MICRO_DIGITS
)
{
timeVal
[
k
]
=
timeVal
[
k
]
*
1000
;
}
else
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
timeVal
[
k
]
=
timeVal
[
k
];
}
}
if
(
pInput
[
k
].
numOfRows
!=
1
)
{
if
(
IS_VAR_DATA_TYPE
(
type
))
{
input
[
k
]
+=
varDataTLen
(
input
[
k
]);
}
else
{
input
[
k
]
+=
tDataTypes
[
type
].
bytes
;
}
}
}
int64_t
result
=
(
timeVal
[
0
]
>=
timeVal
[
1
])
?
(
timeVal
[
0
]
-
timeVal
[
1
])
:
(
timeVal
[
1
]
-
timeVal
[
0
]);
if
(
timeUnit
<
0
)
{
// if no time unit given use db precision
switch
(
timePrec
)
{
case
TSDB_TIME_PRECISION_MILLI
:
{
result
=
result
/
1000000
;
break
;
}
case
TSDB_TIME_PRECISION_MICRO
:
{
result
=
result
/
1000
;
break
;
}
case
TSDB_TIME_PRECISION_NANO
:
{
result
=
result
/
1
;
break
;
}
}
}
else
{
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
timeUnit
=
timeUnit
*
1000
/
factor
;
switch
(
timeUnit
)
{
case
0
:
{
/* 1u */
result
=
result
/
1000
;
break
;
}
case
1
:
{
/* 1a */
result
=
result
/
1000000
;
break
;
}
case
1000
:
{
/* 1s */
result
=
result
/
1000000000
;
break
;
}
case
60000
:
{
/* 1m */
result
=
result
/
1000000000
/
60
;
break
;
}
case
3600000
:
{
/* 1h */
result
=
result
/
1000000000
/
3600
;
break
;
}
case
86400000
:
{
/* 1d */
result
=
result
/
1000000000
/
86400
;
break
;
}
case
604800000
:
{
/* 1w */
result
=
result
/
1000000000
/
604800
;
break
;
}
default:
{
break
;
}
}
}
colDataAppend
(
pOutput
->
columnData
,
i
,
(
char
*
)
&
result
,
false
);
}
pOutput
->
numOfRows
=
pInput
->
numOfRows
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
atanFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
atanFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
return
doScalarFunctionUnique
(
pInput
,
inputNum
,
pOutput
,
atan
);
return
doScalarFunctionUnique
(
pInput
,
inputNum
,
pOutput
,
atan
);
}
}
...
...
source/libs/tdb/src/db/tdbBtree.c
浏览文件 @
3a26ec4e
...
@@ -1196,6 +1196,11 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
...
@@ -1196,6 +1196,11 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
return
-
1
;
return
-
1
;
}
}
*
ppKey
=
pKey
;
*
kLen
=
cd
.
kLen
;
memcpy
(
pKey
,
cd
.
pKey
,
cd
.
kLen
);
if
(
ppVal
)
{
// TODO: vLen may be zero
// TODO: vLen may be zero
pVal
=
TDB_REALLOC
(
*
ppVal
,
cd
.
vLen
);
pVal
=
TDB_REALLOC
(
*
ppVal
,
cd
.
vLen
);
if
(
pVal
==
NULL
)
{
if
(
pVal
==
NULL
)
{
...
@@ -1203,14 +1208,10 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
...
@@ -1203,14 +1208,10 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
return
-
1
;
return
-
1
;
}
}
*
ppKey
=
pKey
;
*
ppVal
=
pVal
;
*
ppVal
=
pVal
;
*
kLen
=
cd
.
kLen
;
*
vLen
=
cd
.
vLen
;
*
vLen
=
cd
.
vLen
;
memcpy
(
pKey
,
cd
.
pKey
,
cd
.
kLen
);
memcpy
(
pVal
,
cd
.
pVal
,
cd
.
vLen
);
memcpy
(
pVal
,
cd
.
pVal
,
cd
.
vLen
);
}
ret
=
tdbBtcMoveToNext
(
pBtc
);
ret
=
tdbBtcMoveToNext
(
pBtc
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
...
...
source/os/src/osFile.c
浏览文件 @
3a26ec4e
...
@@ -768,7 +768,7 @@ int32_t taosUmaskFile(int32_t maskVal) {
...
@@ -768,7 +768,7 @@ int32_t taosUmaskFile(int32_t maskVal) {
}
}
int32_t
taosGetErrorFile
(
TdFilePtr
pFile
)
{
return
errno
;
}
int32_t
taosGetErrorFile
(
TdFilePtr
pFile
)
{
return
errno
;
}
int64_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict
__
ptrBuf
)
{
int64_t
taosGetLineFile
(
TdFilePtr
pFile
,
char
**
__restrict
ptrBuf
)
{
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
{
return
-
1
;
return
-
1
;
}
}
...
...
source/os/src/osSystem.c
浏览文件 @
3a26ec4e
...
@@ -29,6 +29,8 @@
...
@@ -29,6 +29,8 @@
struct
termios
oldtio
;
struct
termios
oldtio
;
#endif
#endif
typedef
struct
FILE
TdCmd
;
void
*
taosLoadDll
(
const
char
*
filename
)
{
void
*
taosLoadDll
(
const
char
*
filename
)
{
#if defined(WINDOWS)
#if defined(WINDOWS)
return
NULL
;
return
NULL
;
...
@@ -178,3 +180,33 @@ void resetTerminalMode() {
...
@@ -178,3 +180,33 @@ void resetTerminalMode() {
}
}
#endif
#endif
}
}
TdCmdPtr
taosOpenCmd
(
const
char
*
cmd
)
{
if
(
cmd
==
NULL
)
return
NULL
;
return
(
TdCmdPtr
)
popen
(
cmd
,
"r"
);
}
int64_t
taosGetLineCmd
(
TdCmdPtr
pCmd
,
char
**
__restrict
ptrBuf
)
{
if
(
pCmd
==
NULL
)
{
return
-
1
;
}
size_t
len
=
0
;
return
getline
(
ptrBuf
,
&
len
,
(
FILE
*
)
pCmd
);
}
int32_t
taosEOFCmd
(
TdCmdPtr
pCmd
)
{
if
(
pCmd
==
NULL
)
{
return
0
;
}
return
feof
((
FILE
*
)
pCmd
);
}
int64_t
taosCloseCmd
(
TdCmdPtr
*
ppCmd
)
{
if
(
ppCmd
==
NULL
||
*
ppCmd
==
NULL
)
{
return
0
;
}
pclose
((
FILE
*
)(
*
ppCmd
));
*
ppCmd
=
NULL
;
return
0
;
}
tests/pytest/insert/binary.py
浏览文件 @
3a26ec4e
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
platform
import
sys
import
sys
from
util.log
import
*
from
util.log
import
*
from
util.cases
import
*
from
util.cases
import
*
...
@@ -13,6 +14,23 @@ class TDTestCase:
...
@@ -13,6 +14,23 @@ class TDTestCase:
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
getPath
(
self
,
tool
=
"taos"
):
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
projPath
=
selfPath
[:
selfPath
.
find
(
"community"
)]
else
:
projPath
=
selfPath
[:
selfPath
.
find
(
"tests"
)]
paths
=
[]
for
root
,
dirs
,
files
in
os
.
walk
(
projPath
):
if
((
tool
)
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
paths
.
append
(
os
.
path
.
join
(
root
,
tool
))
break
return
paths
[
0
]
def
run
(
self
):
def
run
(
self
):
tdSql
.
prepare
()
tdSql
.
prepare
()
...
@@ -53,16 +71,27 @@ class TDTestCase:
...
@@ -53,16 +71,27 @@ class TDTestCase:
tdLog
.
info
(
"tdSql.checkData(0, 0, '34567')"
)
tdLog
.
info
(
"tdSql.checkData(0, 0, '34567')"
)
tdSql
.
checkData
(
0
,
0
,
'34567'
)
tdSql
.
checkData
(
0
,
0
,
'34567'
)
tdLog
.
info
(
"insert into tb values (now+4a,
\"
'';
\"
)"
)
tdLog
.
info
(
"insert into tb values (now+4a,
\"
'';
\"
)"
)
config_dir
=
subprocess
.
check_output
(
str
(
"ps -ef |grep dnode1|grep -v grep |awk '{print $NF}'"
),
stderr
=
subprocess
.
STDOUT
,
shell
=
True
).
decode
(
'utf-8'
).
replace
(
'
\n
'
,
''
)
result
=
''
.
join
(
os
.
popen
(
r
"""taos -s "insert into db.tb values (now+4a, \"'';\")" -c %s"""
%
(
config_dir
)).
readlines
())
if
platform
.
system
()
==
"Linux"
:
if
"Query OK"
not
in
result
:
tdLog
.
exit
(
"err:insert '';"
)
config_dir
=
subprocess
.
check_output
(
tdLog
.
info
(
'drop database db'
)
str
(
"ps -ef |grep dnode1|grep -v grep |awk '{print $NF}'"
),
tdSql
.
execute
(
'drop database db'
)
stderr
=
subprocess
.
STDOUT
,
tdLog
.
info
(
'show databases'
)
shell
=
True
).
decode
(
'utf-8'
).
replace
(
tdSql
.
query
(
'show databases'
)
'
\n
'
,
tdLog
.
info
(
'tdSql.checkRow(0)'
)
''
)
tdSql
.
checkRows
(
0
)
# convert end
binPath
=
self
.
getPath
(
"taos"
)
if
(
binPath
==
""
):
tdLog
.
exit
(
"taos not found!"
)
else
:
tdLog
.
info
(
"taos found: %s"
%
binPath
)
result
=
''
.
join
(
os
.
popen
(
r
"""%s -s "insert into db.tb values (now+4a, \"'';\")" -c %s"""
%
(
binPath
,
(
config_dir
))).
readlines
())
if
"Query OK"
not
in
result
:
tdLog
.
exit
(
"err:insert '';"
)
def
stop
(
self
):
def
stop
(
self
):
tdSql
.
close
()
tdSql
.
close
()
...
...
tests/script/jenkins/basic.txt
浏览文件 @
3a26ec4e
...
@@ -59,6 +59,15 @@
...
@@ -59,6 +59,15 @@
./test.sh -f tsim/tmq/oneTopic.sim
./test.sh -f tsim/tmq/oneTopic.sim
./test.sh -f tsim/tmq/multiTopic.sim
./test.sh -f tsim/tmq/multiTopic.sim
#./test.sh -f tsim/tmq/mainConsumerInMultiTopic.sim
#./test.sh -f tsim/tmq/mainConsumerInOneTopic.sim
#fail ./test.sh -f tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim
#fail ./test.sh -f tsim/tmq/main2Con1Cgrp1TopicFrStb.sim
#./test.sh -f tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim
#./test.sh -f tsim/tmq/main2Con1Cgrp2TopicFrStb.sim
# --- stable
# --- stable
./test.sh -f tsim/stable/disk.sim
./test.sh -f tsim/stable/disk.sim
./test.sh -f tsim/stable/dnode3.sim
./test.sh -f tsim/stable/dnode3.sim
...
@@ -80,4 +89,7 @@
...
@@ -80,4 +89,7 @@
./test.sh -f tsim/qnode/basic1.sim -m
./test.sh -f tsim/qnode/basic1.sim -m
./test.sh -f tsim/mnode/basic1.sim -m
./test.sh -f tsim/mnode/basic1.sim -m
# --- sma
./test.sh -f tsim/sma/tsmaCreateInsertData.sim
#======================b1-end===============
#======================b1-end===============
tests/script/tsim/sma/tsmaCreateInsertData.sim
0 → 100644
浏览文件 @
3a26ec4e
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sleep 50
sql connect
print =============== create database
sql create database d1
sql show databases
if $rows != 2 then
return -1
endi
print $data00 $data01 $data02
sql use d1
print =============== create super table, include column type for count/sum/min/max/first
sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int unsigned)
sql show stables
if $rows != 1 then
return -1
endi
print =============== create child table
sql create table ct1 using stb tags(1000)
sql show tables
if $rows != 1 then
return -1
endi
print =============== insert data, mode1: one row one table in sql
sql insert into ct1 values(now+0s, 10, 2.0, 3.0)
sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3)
print =============== create sma index from super table
sql create sma index sma_index_name1 on stb function(max(c1),max(c2),min(c1)) interval(5m,10s) sliding(2m)
print $data00 $data01 $data02 $data03
print =============== trigger stream to execute sma aggr task and insert sma data into sma store
sql insert into ct1 values(now+5s, 20, 20.0, 30.0)
#===================================================================
system sh/exec.sh -n dnode1 -s stop -x SIGINT
tests/script/tsim/tmq/insertDataV1.sim
浏览文件 @
3a26ec4e
...
@@ -22,23 +22,19 @@ while $i < $tbNum
...
@@ -22,23 +22,19 @@ while $i < $tbNum
$x = 0
$x = 0
while $x < $rowNum
while $x < $rowNum
$c = $x / 10
$c = $c * 10
$c = $x - $c
$binary = ' . binary
$binary = ' . binary
$binary = $binary . $
c
$binary = $binary . $
i
$binary = $binary . '
$binary = $binary . '
#print ====> insert into $tb values ($tstart , $
c
, $x , $binary )
#print ====> insert into $tb values ($tstart , $
i
, $x , $binary )
#print ====> insert into ntb values ($tstart , $
c
, $x , $binary )
#print ====> insert into ntb values ($tstart , $
i
, $x , $binary )
sql insert into $tb values ($tstart , $
c
, $x , $binary )
sql insert into $tb values ($tstart , $
i
, $x , $binary )
sql insert into ntb values ($tstart ,
$c , $x , $binary
)
sql insert into ntb values ($tstart ,
999 , 999 , 'binary-ntb'
)
$tstart = $tstart + 1
$tstart = $tstart + 1
$x = $x + 1
$x = $x + 1
endw
endw
#
print ====> insert rows: $rowNum into $tb and ntb
print ====> insert rows: $rowNum into $tb and ntb
$i = $i + 1
$i = $i + 1
# $tstart = 1640966400000
# $tstart = 1640966400000
...
...
tests/script/tsim/tmq/insertDataV4.sim
浏览文件 @
3a26ec4e
...
@@ -22,18 +22,14 @@ while $i < $tbNum
...
@@ -22,18 +22,14 @@ while $i < $tbNum
$x = 0
$x = 0
while $x < $rowNum
while $x < $rowNum
$c = $x / 10
$c = $c * 10
$c = $x - $c
$binary = ' . binary
$binary = ' . binary
$binary = $binary . $
c
$binary = $binary . $
i
$binary = $binary . '
$binary = $binary . '
#print ====> insert into $tb values ($tstart , $
c
, $x , $binary )
#print ====> insert into $tb values ($tstart , $
i
, $x , $binary )
#print ====> insert into ntb values ($tstart , $
c
, $x , $binary )
#print ====> insert into ntb values ($tstart , $
i
, $x , $binary )
sql insert into $tb values ($tstart , $
c
, $x , $binary )
sql insert into $tb values ($tstart , $
i
, $x , $binary )
sql insert into ntb values ($tstart ,
$c , $x , $binary
)
sql insert into ntb values ($tstart ,
999 , 999 , 'binary-ntb'
)
$tstart = $tstart + 1
$tstart = $tstart + 1
$x = $x + 1
$x = $x + 1
endw
endw
...
...
tests/script/tsim/tmq/insertFixedDataV2.sim
0 → 100644
浏览文件 @
3a26ec4e
sql connect
print ================ insert data
$dbNamme = d0
$tbPrefix = ct
$tbNum = 10
$rowNum = 100
$tstart = 1640966400000 # 2022-01-01 00:00:00.000
$loopInsertNum = 10
sql use $dbNamme
$loopIndex = 0
loop_insert:
print ====> loop $loopIndex insert
$loopIndex = $loopIndex + 1
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
$x = 0
while $x < $rowNum
$binary = ' . binary
$binary = $binary . $i
$binary = $binary . '
#print ====> insert into $tb values ($tstart , $i , $x , $binary )
#print ====> insert into ntb values ($tstart , $i , $x , $binary )
sql insert into $tb values ($tstart , $i , $x , $binary )
sql insert into ntb values ($tstart , 999 , 999 , 'binary-ntb' )
$tstart = $tstart + 1
$x = $x + 1
endw
#print ====> insert rows: $rowNum into $tb and ntb
$i = $i + 1
# $tstart = 1640966400000
endw
if $loopIndex < $loopInsertNum then
goto loop_insert
endi
print ====> insert data end ===========
tests/script/tsim/tmq/insertFixedDataV4.sim
0 → 100644
浏览文件 @
3a26ec4e
sql connect
print ================ insert data
$dbNamme = d1
$tbPrefix = ct
$tbNum = 10
$rowNum = 100
$tstart = 1640966400000 # 2022-01-01 00:00:00.000
$loopInsertNum = 10
sql use $dbNamme
$loopIndex = 0
loop_insert:
print ====> loop $loopIndex insert
$loopIndex = $loopIndex + 1
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
$x = 0
while $x < $rowNum
$binary = ' . binary
$binary = $binary . $i
$binary = $binary . '
#print ====> insert into $tb values ($tstart , $i , $x , $binary )
#print ====> insert into ntb values ($tstart , $i , $x , $binary )
sql insert into $tb values ($tstart , $i , $x , $binary )
sql insert into ntb values ($tstart , 999 , 999 , 'binary-ntb' )
$tstart = $tstart + 1
$x = $x + 1
endw
#print ====> insert rows: $rowNum into $tb and ntb
$i = $i + 1
# $tstart = 1640966400000
endw
if $loopIndex < $loopInsertNum then
goto loop_insert
endi
print ====> insert data end ===========
tests/script/tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim
0 → 100644
浏览文件 @
3a26ec4e
此差异已折叠。
点击以展开。
tests/script/tsim/tmq/main2Con1Cgrp1TopicFrStb.sim
0 → 100644
浏览文件 @
3a26ec4e
此差异已折叠。
点击以展开。
tests/script/tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim
0 → 100644
浏览文件 @
3a26ec4e
此差异已折叠。
点击以展开。
tests/script/tsim/tmq/main2Con1Cgrp2TopicFrStb.sim
0 → 100644
浏览文件 @
3a26ec4e
此差异已折叠。
点击以展开。
tests/script/tsim/tmq/mainConsumerInMultiTopic.sim
浏览文件 @
3a26ec4e
此差异已折叠。
点击以展开。
tests/script/tsim/tmq/mainConsumerInOneTopic.sim
浏览文件 @
3a26ec4e
此差异已折叠。
点击以展开。
tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim
0 → 100644
浏览文件 @
3a26ec4e
此差异已折叠。
点击以展开。
tests/test/c/tmqDemo.c
浏览文件 @
3a26ec4e
...
@@ -195,7 +195,7 @@ void parseArgument(int32_t argc, char *argv[]) {
...
@@ -195,7 +195,7 @@ void parseArgument(int32_t argc, char *argv[]) {
}
}
static
int
running
=
1
;
static
int
running
=
1
;
static
void
msg_process
(
tmq_message_t
*
message
)
{
tmqShowMsg
(
message
);
}
/*static void msg_process(tmq_message_t* message) { tmqShowMsg(message); }*/
// calc dir size (not include itself 4096Byte)
// calc dir size (not include itself 4096Byte)
int64_t
getDirectorySize
(
char
*
dir
)
int64_t
getDirectorySize
(
char
*
dir
)
...
@@ -363,9 +363,9 @@ void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) {
...
@@ -363,9 +363,9 @@ void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) {
}
}
while
(
running
)
{
while
(
running
)
{
tmq_message_t
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
1
);
TAOS_RES
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
1
);
if
(
tmqmessage
)
{
if
(
tmqmessage
)
{
msg_process
(
tmqmessage
);
/*msg_process(tmqmessage);*/
tmq_message_destroy
(
tmqmessage
);
tmq_message_destroy
(
tmqmessage
);
if
((
++
msg_count
%
MIN_COMMIT_COUNT
)
==
0
)
tmq_commit
(
tmq
,
NULL
,
0
);
if
((
++
msg_count
%
MIN_COMMIT_COUNT
)
==
0
)
tmq_commit
(
tmq
,
NULL
,
0
);
...
@@ -392,12 +392,12 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog
...
@@ -392,12 +392,12 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog
int32_t
skipLogNum
=
0
;
int32_t
skipLogNum
=
0
;
int64_t
startTime
=
taosGetTimestampUs
();
int64_t
startTime
=
taosGetTimestampUs
();
while
(
running
)
{
while
(
running
)
{
tmq_message_t
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
3000
);
TAOS_RES
*
tmqmessage
=
tmq_consumer_poll
(
tmq
,
3000
);
if
(
tmqmessage
)
{
if
(
tmqmessage
)
{
batchCnt
++
;
batchCnt
++
;
skipLogNum
+=
tmqGetSkipLogNum
(
tmqmessage
);
/*skipLogNum += tmqGetSkipLogNum(tmqmessage);*/
if
(
0
!=
g_stConfInfo
.
showMsgFlag
)
{
if
(
0
!=
g_stConfInfo
.
showMsgFlag
)
{
msg_process
(
tmqmessage
);
/*msg_process(tmqmessage);*/
}
}
tmq_message_destroy
(
tmqmessage
);
tmq_message_destroy
(
tmqmessage
);
}
else
{
}
else
{
...
...
tests/test/c/tmqSim.c
浏览文件 @
3a26ec4e
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录