Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d4734eb1
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d4734eb1
编写于
4月 21, 2022
作者:
S
slzhou
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of github.com:taosdata/TDengine into 3.0_udfd
上级
b4d3008d
babef48c
变更
68
展开全部
隐藏空白更改
内联
并排
Showing
68 changed file
with
3447 addition
and
898 deletion
+3447
-898
example/src/demoapi.c
example/src/demoapi.c
+1
-1
example/src/tmq.c
example/src/tmq.c
+2
-1
include/common/tdatablock.h
include/common/tdatablock.h
+28
-12
include/common/tdataformat.h
include/common/tdataformat.h
+2
-3
include/common/tmsg.h
include/common/tmsg.h
+129
-10
include/common/tmsgdef.h
include/common/tmsgdef.h
+2
-0
include/common/ttypes.h
include/common/ttypes.h
+2
-2
include/dnode/mnode/sdb/sdb.h
include/dnode/mnode/sdb/sdb.h
+7
-1
include/libs/scalar/scalar.h
include/libs/scalar/scalar.h
+1
-0
include/util/talgo.h
include/util/talgo.h
+5
-0
include/util/taoserror.h
include/util/taoserror.h
+2
-0
include/util/tarray.h
include/util/tarray.h
+14
-14
include/util/tcompare.h
include/util/tcompare.h
+2
-0
include/util/tdef.h
include/util/tdef.h
+2
-0
include/util/tjson.h
include/util/tjson.h
+1
-0
include/util/tutil.h
include/util/tutil.h
+0
-2
source/client/inc/clientInt.h
source/client/inc/clientInt.h
+32
-28
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+70
-0
source/client/src/clientMain.c
source/client/src/clientMain.c
+16
-19
source/client/src/tmq.c
source/client/src/tmq.c
+73
-142
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+17
-4
source/common/src/tmsg.c
source/common/src/tmsg.c
+2
-4
source/common/src/ttypes.c
source/common/src/ttypes.c
+2
-1
source/common/src/tvariant.c
source/common/src/tvariant.c
+1
-1
source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
+1
-0
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
+6
-5
source/dnode/mnode/impl/inc/mndConsumer.h
source/dnode/mnode/impl/inc/mndConsumer.h
+10
-7
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+132
-2
source/dnode/mnode/impl/inc/mndOffset.h
source/dnode/mnode/impl/inc/mndOffset.h
+1
-1
source/dnode/mnode/impl/inc/mndSubscribe.h
source/dnode/mnode/impl/inc/mndSubscribe.h
+3
-1
source/dnode/mnode/impl/src/mndConsumer.c
source/dnode/mnode/impl/src/mndConsumer.c
+523
-14
source/dnode/mnode/impl/src/mndDef.c
source/dnode/mnode/impl/src/mndDef.c
+397
-0
source/dnode/mnode/impl/src/mndOffset.c
source/dnode/mnode/impl/src/mndOffset.c
+13
-5
source/dnode/mnode/impl/src/mndScheduler.c
source/dnode/mnode/impl/src/mndScheduler.c
+30
-5
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+1
-1
source/dnode/mnode/impl/src/mndSubscribe.c
source/dnode/mnode/impl/src/mndSubscribe.c
+510
-24
source/dnode/mnode/impl/src/mnode.c
source/dnode/mnode/impl/src/mnode.c
+3
-3
source/dnode/vnode/src/inc/tq.h
source/dnode/vnode/src/inc/tq.h
+26
-23
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+117
-133
source/dnode/vnode/src/tq/tqMetaStore.c
source/dnode/vnode/src/tq/tqMetaStore.c
+0
-1
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+9
-1
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+1
-1
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+1
-1
source/libs/parser/inc/parUtil.h
source/libs/parser/inc/parUtil.h
+1
-0
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+1
-0
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+25
-28
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+36
-10
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+162
-5
source/libs/scalar/inc/filterInt.h
source/libs/scalar/inc/filterInt.h
+0
-2
source/libs/scalar/inc/sclvector.h
source/libs/scalar/inc/sclvector.h
+4
-0
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+39
-59
source/libs/scalar/src/scalar.c
source/libs/scalar/src/scalar.c
+24
-12
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+54
-0
source/libs/scalar/src/sclvector.c
source/libs/scalar/src/sclvector.c
+369
-158
source/libs/scalar/test/scalar/CMakeLists.txt
source/libs/scalar/test/scalar/CMakeLists.txt
+2
-1
source/libs/scalar/test/scalar/scalarTests.cpp
source/libs/scalar/test/scalar/scalarTests.cpp
+262
-1
source/os/src/osFile.c
source/os/src/osFile.c
+20
-20
source/util/src/tarray.c
source/util/src/tarray.c
+43
-3
source/util/src/tcompare.c
source/util/src/tcompare.c
+5
-0
source/util/src/tjson.c
source/util/src/tjson.c
+34
-0
source/util/src/tutil.c
source/util/src/tutil.c
+0
-59
tests/pytest/insert/binary.py
tests/pytest/insert/binary.py
+15
-13
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+3
-0
tests/script/sh/checkValgrind.sh
tests/script/sh/checkValgrind.sh
+38
-0
tests/script/tsim/tmq/basic1.sim
tests/script/tsim/tmq/basic1.sim
+2
-2
tests/script/tsim/valgrind/checkError.sim
tests/script/tsim/valgrind/checkError.sim
+83
-0
tests/tsim/src/simExe.c
tests/tsim/src/simExe.c
+6
-0
tools/shell/src/shellEngine.c
tools/shell/src/shellEngine.c
+22
-52
未找到文件。
example/src/demoapi.c
浏览文件 @
d4734eb1
...
...
@@ -176,7 +176,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) {
}
if
(
block
)
{
warnPrint
(
"%s"
,
"call taos_fetch_block()
\n
"
);
warnPrint
(
"%s"
,
"call taos_fetch_block()
, don't call taos_fetch_lengths()
\n
"
);
int
rows
=
0
;
while
((
rows
=
taos_fetch_block
(
res
,
&
row
)))
{
int
*
lengths
=
taos_fetch_lengths
(
res
);
...
...
example/src/tmq.c
浏览文件 @
d4734eb1
...
...
@@ -22,6 +22,7 @@
static
int
running
=
1
;
static
void
msg_process
(
TAOS_RES
*
msg
)
{
char
buf
[
1024
];
memset
(
buf
,
0
,
1024
);
printf
(
"topic: %s
\n
"
,
tmq_get_topic_name
(
msg
));
printf
(
"vg:%d
\n
"
,
tmq_get_vgroup_id
(
msg
));
while
(
1
)
{
...
...
@@ -220,7 +221,7 @@ void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) {
msg_process
(
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);*/
}
}
...
...
include/common/tdatablock.h
浏览文件 @
d4734eb1
...
...
@@ -54,12 +54,34 @@ SEpSet getEpSet_s(SCorEpSet* pEpSet);
BMCharPos(bm_, r_) |= (1u << (7u - BitPos(r_))); \
} while (0)
#define colDataIsNull_var(pColumnInfoData, row) (pColumnInfoData->varmeta.offset[row] == -1)
#define colDataSetNull_var(pColumnInfoData, row) (pColumnInfoData->varmeta.offset[row] = -1)
#define BitmapLen(_n) (((_n) + ((1 << NBIT) - 1)) >> NBIT)
#define colDataGetVarData(p1_, r_) ((p1_)->pData + (p1_)->varmeta.offset[(r_)])
#define colDataGetNumData(p1_, r_) ((p1_)->pData + ((r_) * (p1_)->info.bytes))
// SColumnInfoData, rowNumber
#define colDataGetData(p1_, r_) \
((IS_VAR_DATA_TYPE((p1_)->info.type)) ? colDataGetVarData(p1_, r_) \
: colDataGetNumData(p1_, r_))
static
FORCE_INLINE
bool
colDataIsNull_s
(
const
SColumnInfoData
*
pColumnInfoData
,
uint32_t
row
)
{
if
(
pColumnInfoData
->
info
.
type
==
TSDB_DATA_TYPE_JSON
){
if
(
colDataIsNull_var
(
pColumnInfoData
,
row
)){
return
true
;
}
char
*
data
=
colDataGetVarData
(
pColumnInfoData
,
row
);
return
(
*
data
==
TSDB_DATA_TYPE_NULL
);
}
if
(
!
pColumnInfoData
->
hasNull
)
{
return
false
;
}
if
(
IS_VAR_DATA_TYPE
(
pColumnInfoData
->
info
.
type
))
{
return
pColumnInfoData
->
varmeta
.
offset
[
row
]
==
-
1
;
if
(
pColumnInfoData
->
info
.
type
==
TSDB_DATA_TYPE_VARCHAR
||
pColumnInfoData
->
info
.
type
==
TSDB_DATA_TYPE_NCHAR
)
{
return
colDataIsNull_var
(
pColumnInfoData
,
row
);
}
else
{
if
(
pColumnInfoData
->
nullbitmap
==
NULL
)
{
return
false
;
...
...
@@ -86,7 +108,7 @@ static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, u
}
if
(
IS_VAR_DATA_TYPE
(
pColumnInfoData
->
info
.
type
))
{
return
pColumnInfoData
->
varmeta
.
offset
[
row
]
==
-
1
;
return
colDataIsNull_var
(
pColumnInfoData
,
row
)
;
}
else
{
if
(
pColumnInfoData
->
nullbitmap
==
NULL
)
{
return
false
;
...
...
@@ -96,17 +118,10 @@ static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, u
}
}
#define BitmapLen(_n) (((_n) + ((1 << NBIT) - 1)) >> NBIT)
// SColumnInfoData, rowNumber
#define colDataGetData(p1_, r_) \
((IS_VAR_DATA_TYPE((p1_)->info.type)) ? ((p1_)->pData + (p1_)->varmeta.offset[(r_)]) \
: ((p1_)->pData + ((r_) * (p1_)->info.bytes)))
static
FORCE_INLINE
void
colDataAppendNULL
(
SColumnInfoData
*
pColumnInfoData
,
uint32_t
currentRow
)
{
// There is a placehold for each NULL value of binary or nchar type.
if
(
IS_VAR_DATA_TYPE
(
pColumnInfoData
->
info
.
type
))
{
pColumnInfoData
->
varmeta
.
offset
[
currentRow
]
=
-
1
;
// it is a null value of VAR type.
colDataSetNull_var
(
pColumnInfoData
,
currentRow
)
;
// it is a null value of VAR type.
}
else
{
colDataSetNull_f
(
pColumnInfoData
->
nullbitmap
,
currentRow
);
}
...
...
@@ -117,7 +132,7 @@ static FORCE_INLINE void colDataAppendNULL(SColumnInfoData* pColumnInfoData, uin
static
FORCE_INLINE
void
colDataAppendNNULL
(
SColumnInfoData
*
pColumnInfoData
,
uint32_t
start
,
size_t
nRows
)
{
if
(
IS_VAR_DATA_TYPE
(
pColumnInfoData
->
info
.
type
))
{
for
(
int32_t
i
=
start
;
i
<
start
+
nRows
;
++
i
)
{
pColumnInfoData
->
varmeta
.
offset
[
i
]
=
-
1
;
// it is a null value of VAR type.
colDataSetNull_var
(
pColumnInfoData
,
i
)
;
// it is a null value of VAR type.
}
}
else
{
for
(
int32_t
i
=
start
;
i
<
start
+
nRows
;
++
i
)
{
...
...
@@ -265,3 +280,4 @@ static FORCE_INLINE void blockCompressEncode(const SSDataBlock* pBlock, char* da
#endif
#endif
/*_TD_COMMON_EP_H_*/
include/common/tdataformat.h
浏览文件 @
d4734eb1
...
...
@@ -502,7 +502,7 @@ typedef struct {
#define TD_KV_ROW_HEAD_SIZE (sizeof(uint16_t) + sizeof(int16_t))
#define kvRowLen(r) (*(
TDRowLenT
*)(r))
#define kvRowLen(r) (*(
uint16_t
*)(r))
#define kvRowNCols(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(uint16_t)))
#define kvRowSetLen(r, len) kvRowLen(r) = (len)
#define kvRowSetNCols(r, n) kvRowNCols(r) = (n)
...
...
@@ -608,7 +608,7 @@ void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder);
void
tdResetKVRowBuilder
(
SKVRowBuilder
*
pBuilder
);
SKVRow
tdGetKVRowFromBuilder
(
SKVRowBuilder
*
pBuilder
);
static
FORCE_INLINE
int32_t
tdAddColToKVRow
(
SKVRowBuilder
*
pBuilder
,
col_id_t
colId
,
int8_t
type
,
const
void
*
value
)
{
static
FORCE_INLINE
int32_t
tdAddColToKVRow
(
SKVRowBuilder
*
pBuilder
,
col_id_t
colId
,
const
void
*
value
,
int32_t
tlen
)
{
if
(
pBuilder
->
nCols
>=
pBuilder
->
tCols
)
{
pBuilder
->
tCols
*=
2
;
SColIdx
*
pColIdx
=
(
SColIdx
*
)
taosMemoryRealloc
((
void
*
)(
pBuilder
->
pColIdx
),
sizeof
(
SColIdx
)
*
pBuilder
->
tCols
);
...
...
@@ -621,7 +621,6 @@ static FORCE_INLINE int32_t tdAddColToKVRow(SKVRowBuilder *pBuilder, col_id_t co
pBuilder
->
nCols
++
;
int32_t
tlen
=
IS_VAR_DATA_TYPE
(
type
)
?
varDataTLen
(
value
)
:
TYPE_BYTES
[
type
];
if
(
tlen
>
pBuilder
->
alloc
-
pBuilder
->
size
)
{
while
(
tlen
>
pBuilder
->
alloc
-
pBuilder
->
size
)
{
pBuilder
->
alloc
*=
2
;
...
...
include/common/tmsg.h
浏览文件 @
d4734eb1
...
...
@@ -324,7 +324,7 @@ typedef struct SEpSet {
int32_t
tEncodeSEpSet
(
SCoder
*
pEncoder
,
const
SEpSet
*
pEp
);
int32_t
tDecodeSEpSet
(
SCoder
*
pDecoder
,
SEpSet
*
pEp
);
int32_t
taosEncodeSEpSet
(
void
**
buf
,
const
SEpSet
*
pEp
);
void
*
taosDecodeSEpSet
(
void
*
buf
,
SEpSet
*
pEp
);
void
*
taosDecodeSEpSet
(
const
void
*
buf
,
SEpSet
*
pEp
);
typedef
struct
{
int8_t
connType
;
...
...
@@ -1291,10 +1291,14 @@ typedef struct {
int32_t
tSerializeSCMCreateTopicRsp
(
void
*
buf
,
int32_t
bufLen
,
const
SCMCreateTopicRsp
*
pRsp
);
int32_t
tDeserializeSCMCreateTopicRsp
(
void
*
buf
,
int32_t
bufLen
,
SCMCreateTopicRsp
*
pRsp
);
typedef
struct
{
int64_t
consumerId
;
}
SMqConsumerLostMsg
;
typedef
struct
{
int32_t
topicNum
;
int64_t
consumerId
;
char
*
consumerGroup
;
char
cgroup
[
TSDB_CGROUP_LEN
]
;
SArray
*
topicNames
;
// SArray<char*>
}
SCMSubscribeReq
;
...
...
@@ -1302,7 +1306,7 @@ static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubsc
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI32
(
buf
,
pReq
->
topicNum
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pReq
->
consumerId
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
c
onsumerG
roup
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
c
g
roup
);
for
(
int32_t
i
=
0
;
i
<
pReq
->
topicNum
;
i
++
)
{
tlen
+=
taosEncodeString
(
buf
,
(
char
*
)
taosArrayGetP
(
pReq
->
topicNames
,
i
));
...
...
@@ -1313,7 +1317,7 @@ static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubsc
static
FORCE_INLINE
void
*
tDeserializeSCMSubscribeReq
(
void
*
buf
,
SCMSubscribeReq
*
pReq
)
{
buf
=
taosDecodeFixedI32
(
buf
,
&
pReq
->
topicNum
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pReq
->
consumerId
);
buf
=
taosDecodeString
(
buf
,
&
pReq
->
consumerG
roup
);
buf
=
taosDecodeString
To
(
buf
,
pReq
->
cg
roup
);
pReq
->
topicNames
=
taosArrayInit
(
pReq
->
topicNum
,
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
pReq
->
topicNum
;
i
++
)
{
char
*
name
;
...
...
@@ -1389,10 +1393,10 @@ static FORCE_INLINE void* tDeserializeSMVSubscribeReq(void* buf, SMVSubscribeReq
}
typedef
struct
{
c
onst
char
*
key
;
SArray
*
lostConsumers
;
// SArray<int64_t>
SArray
*
removedConsumers
;
// SArray<int64_t>
SArray
*
newConsumers
;
// SArray<int64_t>
c
har
key
[
TSDB_SUBSCRIBE_KEY_LEN
]
;
SArray
*
lostConsumers
;
// SArray<int64_t>
SArray
*
removedConsumers
;
// SArray<int64_t>
SArray
*
newConsumers
;
// SArray<int64_t>
}
SMqRebSubscribe
;
static
FORCE_INLINE
SMqRebSubscribe
*
tNewSMqRebSubscribe
(
const
char
*
key
)
{
...
...
@@ -1400,7 +1404,7 @@ static FORCE_INLINE SMqRebSubscribe* tNewSMqRebSubscribe(const char* key) {
if
(
pRebSub
==
NULL
)
{
goto
_err
;
}
pRebSub
->
key
=
strdup
(
key
);
strcpy
(
pRebSub
->
key
,
key
);
pRebSub
->
lostConsumers
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
if
(
pRebSub
->
lostConsumers
==
NULL
)
{
goto
_err
;
...
...
@@ -1425,6 +1429,7 @@ _err:
// this message is sent from mnode to mnode(read thread to write thread), so there is no need for serialization or
// deserialization
typedef
struct
{
int8_t
*
mqInReb
;
SHashObj
*
rebSubHash
;
// SHashObj<key, SMqRebSubscribe>
}
SMqDoRebalanceMsg
;
...
...
@@ -1927,6 +1932,40 @@ static FORCE_INLINE void* taosDecodeSMqMsg(void* buf, SMqHbMsg* pMsg) {
return
buf
;
}
typedef
struct
{
int64_t
leftForVer
;
int32_t
vgId
;
int64_t
oldConsumerId
;
int64_t
newConsumerId
;
char
subKey
[
TSDB_SUBSCRIBE_KEY_LEN
];
char
*
qmsg
;
}
SMqRebVgReq
;
static
FORCE_INLINE
int32_t
tEncodeSMqRebVgReq
(
void
**
buf
,
const
SMqRebVgReq
*
pReq
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pReq
->
leftForVer
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pReq
->
vgId
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pReq
->
oldConsumerId
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pReq
->
newConsumerId
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
subKey
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
qmsg
);
return
tlen
;
}
static
FORCE_INLINE
void
*
tDecodeSMqRebVgReq
(
const
void
*
buf
,
SMqRebVgReq
*
pReq
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
pReq
->
leftForVer
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pReq
->
vgId
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pReq
->
oldConsumerId
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pReq
->
newConsumerId
);
buf
=
taosDecodeStringTo
(
buf
,
pReq
->
subKey
);
buf
=
taosDecodeString
(
buf
,
&
pReq
->
qmsg
);
return
(
void
*
)
buf
;
}
typedef
struct
{
int8_t
reserved
;
}
SMqRebVgRsp
;
typedef
struct
{
int64_t
leftForVer
;
int32_t
vgId
;
...
...
@@ -2397,6 +2436,7 @@ typedef struct {
int64_t
consumerId
;
}
SMqRspHead
;
#if 0
typedef struct {
SMsgHead head;
...
...
@@ -2410,6 +2450,17 @@ typedef struct {
uint64_t reqId;
char topic[TSDB_TOPIC_FNAME_LEN];
} SMqPollReq;
#endif
typedef
struct
{
SMsgHead
head
;
char
subKey
[
TSDB_SUBSCRIBE_KEY_LEN
];
int32_t
epoch
;
uint64_t
reqId
;
int64_t
consumerId
;
int64_t
blockingTime
;
int64_t
currentOffset
;
}
SMqPollReqV2
;
typedef
struct
{
int32_t
vgId
;
...
...
@@ -2483,13 +2534,81 @@ static FORCE_INLINE void* tDecodeSMqPollRspV2(const void* buf, SMqPollRspV2* pRs
return
(
void
*
)
buf
;
}
typedef
struct
{
SMqRspHead
head
;
int64_t
reqOffset
;
int64_t
rspOffset
;
int32_t
skipLogNum
;
int32_t
blockNum
;
int8_t
withTbName
;
int8_t
withSchema
;
int8_t
withTag
;
int8_t
withTagSchema
;
SArray
*
blockDataLen
;
// SArray<int32_t>
SArray
*
blockData
;
// SArray<SRetrieveTableRsp*>
SArray
*
blockTbName
;
// SArray<char*>
SArray
*
blockSchema
;
// SArray<SSchemaWrapper>
SArray
*
blockTags
;
// SArray<kvrow>
SArray
*
blockTagSchema
;
// SArray<kvrow>
}
SMqDataBlkRsp
;
static
FORCE_INLINE
int32_t
tEncodeSMqDataBlkRsp
(
void
**
buf
,
const
SMqDataBlkRsp
*
pRsp
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pRsp
->
reqOffset
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pRsp
->
rspOffset
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pRsp
->
skipLogNum
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pRsp
->
blockNum
);
if
(
pRsp
->
blockNum
!=
0
)
{
tlen
+=
taosEncodeFixedI8
(
buf
,
pRsp
->
withTbName
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pRsp
->
withSchema
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pRsp
->
withTag
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pRsp
->
withTagSchema
);
for
(
int32_t
i
=
0
;
i
<
pRsp
->
blockNum
;
i
++
)
{
int32_t
bLen
=
*
(
int32_t
*
)
taosArrayGet
(
pRsp
->
blockDataLen
,
i
);
void
*
data
=
taosArrayGetP
(
pRsp
->
blockData
,
i
);
tlen
+=
taosEncodeFixedI32
(
buf
,
bLen
);
tlen
+=
taosEncodeBinary
(
buf
,
data
,
bLen
);
}
}
return
tlen
;
}
static
FORCE_INLINE
void
*
tDecodeSMqDataBlkRsp
(
const
void
*
buf
,
SMqDataBlkRsp
*
pRsp
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
pRsp
->
reqOffset
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pRsp
->
rspOffset
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pRsp
->
skipLogNum
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pRsp
->
blockNum
);
pRsp
->
blockData
=
taosArrayInit
(
pRsp
->
blockNum
,
sizeof
(
void
*
));
pRsp
->
blockDataLen
=
taosArrayInit
(
pRsp
->
blockNum
,
sizeof
(
void
*
));
if
(
pRsp
->
blockNum
!=
0
)
{
buf
=
taosDecodeFixedI8
(
buf
,
&
pRsp
->
withTbName
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pRsp
->
withSchema
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pRsp
->
withTag
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pRsp
->
withTagSchema
);
for
(
int32_t
i
=
0
;
i
<
pRsp
->
blockNum
;
i
++
)
{
int32_t
bLen
=
0
;
void
*
data
=
NULL
;
buf
=
taosDecodeFixedI32
(
buf
,
&
bLen
);
buf
=
taosDecodeBinary
(
buf
,
&
data
,
bLen
);
taosArrayPush
(
pRsp
->
blockDataLen
,
&
bLen
);
taosArrayPush
(
pRsp
->
blockData
,
&
data
);
}
}
return
(
void
*
)
buf
;
}
typedef
struct
{
SMqRspHead
head
;
char
cgroup
[
TSDB_CGROUP_LEN
];
SArray
*
topics
;
// SArray<SMqSubTopicEp>
}
SMqCMGetSubEpRsp
;
static
FORCE_INLINE
void
tDeleteSMqSubTopicEp
(
SMqSubTopicEp
*
pSubTopicEp
)
{
taosArrayDestroy
(
pSubTopicEp
->
vgs
);
}
static
FORCE_INLINE
void
tDeleteSMqSubTopicEp
(
SMqSubTopicEp
*
pSubTopicEp
)
{
// taosMemoryFree(pSubTopicEp->schema.pSchema);
taosArrayDestroy
(
pSubTopicEp
->
vgs
);
}
static
FORCE_INLINE
int32_t
tEncodeSMqSubVgEp
(
void
**
buf
,
const
SMqSubVgEp
*
pVgEp
)
{
int32_t
tlen
=
0
;
...
...
include/common/tmsgdef.h
浏览文件 @
d4734eb1
...
...
@@ -146,6 +146,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_MND_SUBSCRIBE
,
"mnode-subscribe"
,
SCMSubscribeReq
,
SCMSubscribeRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_GET_SUB_EP
,
"mnode-get-sub-ep"
,
SMqCMGetSubEpReq
,
SMqCMGetSubEpRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_TIMER
,
"mnode-mq-tmr"
,
SMTimerReq
,
SMTimerReq
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_CONSUMER_LOST
,
"mnode-mq-consumer-lost"
,
SMTimerReq
,
SMTimerReq
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_DO_REBALANCE
,
"mnode-mq-do-rebalance"
,
SMqDoRebalanceMsg
,
SMqDoRebalanceMsg
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MQ_COMMIT_OFFSET
,
"mnode-mq-commit-offset"
,
SMqCMCommitOffsetReq
,
SMqCMCommitOffsetRsp
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_STREAM
,
"mnode-create-stream"
,
SCMCreateStreamReq
,
SCMCreateStreamRsp
)
...
...
@@ -177,6 +178,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_VND_MQ_SET_CONN
,
"vnode-mq-set-conn"
,
SMqSetCVgReq
,
SMqSetCVgRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_MQ_REB
,
"vnode-mq-mv-rebalance"
,
SMqMVRebReq
,
SMqMVRebRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_MQ_CANCEL_CONN
,
"vnode-mq-mv-cancel-conn"
,
SMqCancelConnReq
,
SMqCancelConnRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_MQ_VG_CHANGE
,
"vnode-mq-vg-change"
,
SMqRebVgReq
,
SMqRebVgRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_MQ_SET_CUR
,
"vnode-mq-set-cur"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_RES_READY
,
"vnode-res-ready"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_TASKS_STATUS
,
"vnode-tasks-status"
,
NULL
,
NULL
)
...
...
include/common/ttypes.h
浏览文件 @
d4734eb1
...
...
@@ -49,7 +49,7 @@ typedef struct {
#define varDataCopy(dst, v) memcpy((dst), (void *)(v), varDataTLen(v))
#define varDataLenByData(v) (*(VarDataLenT *)(((char *)(v)) - VARSTR_HEADER_SIZE))
#define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT)(_len))
#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_NCHAR))
#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_NCHAR)
|| ((t) == TSDB_DATA_TYPE_JSON)
)
#define varDataNetLen(v) (htons(((VarDataLenT *)(v))[0]))
#define varDataNetTLen(v) (sizeof(VarDataLenT) + varDataNetLen(v))
...
...
@@ -252,7 +252,7 @@ typedef struct tDataTypeDescriptor {
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minindex
,
int16_t
*
maxindex
,
int16_t
*
numofnull
);
}
tDataTypeDescriptor
;
extern
tDataTypeDescriptor
tDataTypes
[
15
];
extern
tDataTypeDescriptor
tDataTypes
[
TSDB_DATA_TYPE_MAX
];
bool
isValidDataType
(
int32_t
type
);
...
...
include/dnode/mnode/sdb/sdb.h
浏览文件 @
d4734eb1
...
...
@@ -92,7 +92,13 @@ extern "C" {
typedef
struct
SMnode
SMnode
;
typedef
struct
SSdbRaw
SSdbRaw
;
typedef
struct
SSdbRow
SSdbRow
;
typedef
enum
{
SDB_KEY_BINARY
=
1
,
SDB_KEY_INT32
=
2
,
SDB_KEY_INT64
=
3
}
EKeyType
;
typedef
enum
{
SDB_KEY_BINARY
=
1
,
SDB_KEY_INT32
=
2
,
SDB_KEY_INT64
=
3
,
}
EKeyType
;
typedef
enum
{
SDB_STATUS_INIT
=
0
,
SDB_STATUS_CREATING
=
1
,
...
...
include/libs/scalar/scalar.h
浏览文件 @
d4734eb1
...
...
@@ -76,6 +76,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
/* Time related functions */
int32_t
toISO8601Function
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
toUnixtimestampFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
int32_t
toJsonFunction
(
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
);
int32_t
nowFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
);
...
...
include/util/talgo.h
浏览文件 @
d4734eb1
...
...
@@ -27,6 +27,11 @@ extern "C" {
typedef
int32_t
(
*
__compar_fn_t
)(
const
void
*
,
const
void
*
);
#endif
typedef
void
*
(
*
FCopy
)(
void
*
);
typedef
void
(
*
FDelete
)(
void
*
);
typedef
int32_t
(
*
FEncode
)(
void
**
buf
,
const
void
*
dst
);
typedef
void
*
(
*
FDecode
)(
const
void
*
buf
,
void
*
dst
);
#define TD_EQ 0x1
#define TD_GT 0x2
#define TD_LT 0x4
...
...
include/util/taoserror.h
浏览文件 @
d4734eb1
...
...
@@ -279,6 +279,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_UNSUPPORTED_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03E8)
#define TSDB_CODE_MND_SUBSCRIBE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E9)
#define TSDB_CODE_MND_OFFSET_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03EA)
#define TSDB_CODE_MND_CONSUMER_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x03EB)
// mnode-stream
#define TSDB_CODE_MND_STREAM_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03F0)
...
...
@@ -609,6 +610,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_INTER_SLIDING_UNIT TAOS_DEF_ERROR_CODE(0, 0x2630)
#define TSDB_CODE_PAR_INTER_SLIDING_TOO_BIG TAOS_DEF_ERROR_CODE(0, 0x2631)
#define TSDB_CODE_PAR_INTER_SLIDING_TOO_SMALL TAOS_DEF_ERROR_CODE(0, 0x2632)
#define TSDB_CODE_PAR_ONLY_ONE_JSON_TAG TAOS_DEF_ERROR_CODE(0, 0x2633)
//planner
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
...
...
include/util/tarray.h
浏览文件 @
d4734eb1
...
...
@@ -41,10 +41,10 @@ extern "C" {
#define TARRAY_GET_START(array) ((array)->pData)
typedef
struct
SArray
{
size_t
size
;
size_t
size
;
uint32_t
capacity
;
uint32_t
elemSize
;
void
*
pData
;
void
*
pData
;
}
SArray
;
/**
...
...
@@ -199,6 +199,13 @@ SArray* taosArrayFromList(const void* src, size_t size, size_t elemSize);
*/
SArray
*
taosArrayDup
(
const
SArray
*
pSrc
);
/**
* deep copy a new array
* @param pSrc
*/
SArray
*
taosArrayDeepCopy
(
const
SArray
*
pSrc
,
FCopy
deepCopy
);
/**
* clear the array (remove all element)
* @param pArray
...
...
@@ -212,19 +219,9 @@ void taosArrayClear(SArray* pArray);
*/
void
taosArrayClearEx
(
SArray
*
pArray
,
void
(
*
fp
)(
void
*
));
/**
* destroy array list
* @param pArray
*/
void
*
taosArrayDestroy
(
SArray
*
pArray
);
/**
*
* @param pArray
* @param fp
*/
void
taosArrayDestroyEx
(
SArray
*
pArray
,
void
(
*
fp
)(
void
*
));
void
taosArrayDestroyP
(
SArray
*
pArray
,
FDelete
fp
);
void
taosArrayDestroyEx
(
SArray
*
pArray
,
FDelete
fp
);
/**
* sort the array
...
...
@@ -272,6 +269,9 @@ char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t
void
taosArraySortPWithExt
(
SArray
*
pArray
,
__ext_compar_fn_t
fn
,
const
void
*
param
);
int32_t
taosEncodeArray
(
void
**
buf
,
const
SArray
*
pArray
,
FEncode
encode
);
void
*
taosDecodeArray
(
const
void
*
buf
,
SArray
**
pArray
,
FDecode
decode
,
int32_t
dataSz
);
#ifdef __cplusplus
}
#endif
...
...
include/util/tcompare.h
浏览文件 @
d4734eb1
...
...
@@ -105,6 +105,8 @@ int32_t compareStrPatternNotMatch(const void *pLeft, const void *pRight);
int32_t
compareWStrPatternMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareWStrPatternNotMatch
(
const
void
*
pLeft
,
const
void
*
pRight
);
int32_t
compareJsonContainsKey
(
const
void
*
pLeft
,
const
void
*
pRight
);
__compar_fn_t
getComparFunc
(
int32_t
type
,
int32_t
optr
);
__compar_fn_t
getKeyComparFunc
(
int32_t
keyType
,
int32_t
order
);
int32_t
doCompare
(
const
char
*
a
,
const
char
*
b
,
int32_t
type
,
size_t
size
);
...
...
include/util/tdef.h
浏览文件 @
d4734eb1
...
...
@@ -273,6 +273,8 @@ typedef enum ELogicConditionType {
#define TSDB_MAX_TAGS 128
#define TSDB_MAX_TAG_CONDITIONS 1024
#define TSDB_MAX_JSON_TAG_LEN 16384
#define TSDB_AUTH_LEN 16
#define TSDB_PASSWORD_LEN 32
#define TSDB_USET_PASSWORD_LEN 129
...
...
include/util/tjson.h
浏览文件 @
d4734eb1
...
...
@@ -76,6 +76,7 @@ char* tjsonToString(const SJson* pJson);
char
*
tjsonToUnformattedString
(
const
SJson
*
pJson
);
SJson
*
tjsonParse
(
const
char
*
pStr
);
bool
tjsonValidateJson
(
const
char
*
pJson
);
#ifdef __cplusplus
}
...
...
include/util/tutil.h
浏览文件 @
d4734eb1
...
...
@@ -26,8 +26,6 @@ extern "C" {
#endif
int32_t
strdequote
(
char
*
src
);
int32_t
strndequote
(
char
*
dst
,
const
char
*
z
,
int32_t
len
);
int32_t
strRmquote
(
char
*
z
,
int32_t
len
);
size_t
strtrim
(
char
*
src
);
char
*
strnchr
(
const
char
*
haystack
,
char
needle
,
int32_t
len
,
bool
skipquote
);
char
**
strsplit
(
char
*
src
,
const
char
*
delim
,
int32_t
*
num
);
...
...
source/client/inc/clientInt.h
浏览文件 @
d4734eb1
...
...
@@ -44,7 +44,7 @@ extern "C" {
} while (0)
#define ERROR_MSG_BUF_DEFAULT_SIZE 512
#define HEARTBEAT_INTERVAL 1500 // ms
#define HEARTBEAT_INTERVAL
1500 // ms
enum
{
RES_TYPE__QUERY
=
1
,
...
...
@@ -187,11 +187,13 @@ typedef struct SRequestSendRecvBody {
}
SRequestSendRecvBody
;
typedef
struct
{
int8_t
resType
;
char
*
topic
;
SArray
*
res
;
// SArray<SReqResultInfo>
int32_t
resIter
;
int32_t
vgId
;
int8_t
resType
;
char
topic
[
TSDB_TOPIC_FNAME_LEN
];
int32_t
vgId
;
SSchemaWrapper
schema
;
int32_t
resIter
;
SMqDataBlkRsp
rsp
;
SReqResultInfo
resInfo
;
}
SMqRspObj
;
typedef
struct
SRequestObj
{
...
...
@@ -211,16 +213,24 @@ typedef struct SRequestObj {
SRequestSendRecvBody
body
;
}
SRequestObj
;
void
*
doFetchRows
(
SRequestObj
*
pRequest
,
bool
setupOneRowPtr
,
bool
convertUcs4
);
void
doSetOneRowPtr
(
SReqResultInfo
*
pResultInfo
);
void
setResPrecision
(
SReqResultInfo
*
pResInfo
,
int32_t
precision
);
int32_t
setQueryResultFromRsp
(
SReqResultInfo
*
pResultInfo
,
const
SRetrieveTableRsp
*
pRsp
,
bool
convertUcs4
);
void
setResSchemaInfo
(
SReqResultInfo
*
pResInfo
,
const
SSchema
*
pSchema
,
int32_t
numOfCols
);
static
FORCE_INLINE
SReqResultInfo
*
tmqGetCurResInfo
(
TAOS_RES
*
res
)
{
SMqRspObj
*
msg
=
(
SMqRspObj
*
)
res
;
int32_t
resIter
=
msg
->
resIter
==
-
1
?
0
:
msg
->
resIter
;
return
(
SReqResultInfo
*
)
taosArrayGet
(
msg
->
res
,
resIter
);
return
(
SReqResultInfo
*
)
&
msg
->
resInfo
;
}
static
FORCE_INLINE
SReqResultInfo
*
tmqGetNextResInfo
(
TAOS_RES
*
res
)
{
static
FORCE_INLINE
SReqResultInfo
*
tmqGetNextResInfo
(
TAOS_RES
*
res
,
bool
convertUcs4
)
{
SMqRspObj
*
msg
=
(
SMqRspObj
*
)
res
;
if
(
++
msg
->
resIter
<
taosArrayGetSize
(
msg
->
res
))
{
return
(
SReqResultInfo
*
)
taosArrayGet
(
msg
->
res
,
msg
->
resIter
);
msg
->
resIter
++
;
if
(
msg
->
resIter
<
msg
->
rsp
.
blockNum
)
{
SRetrieveTableRsp
*
pRetrieve
=
(
SRetrieveTableRsp
*
)
taosArrayGetP
(
msg
->
rsp
.
blockData
,
msg
->
resIter
);
setQueryResultFromRsp
(
&
msg
->
resInfo
,
pRetrieve
,
convertUcs4
);
return
&
msg
->
resInfo
;
}
return
NULL
;
}
...
...
@@ -238,25 +248,25 @@ extern int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t
int
genericRspCallback
(
void
*
param
,
const
SDataBuf
*
pMsg
,
int32_t
code
);
SMsgSendInfo
*
buildMsgInfoImpl
(
SRequestObj
*
pReqObj
);
int
taos_init
();
int
taos_init
();
void
*
createTscObj
(
const
char
*
user
,
const
char
*
auth
,
const
char
*
db
,
SAppInstInfo
*
pAppInfo
);
void
destroyTscObj
(
void
*
pObj
);
STscObj
*
acquireTscObj
(
int64_t
rid
);
int32_t
releaseTscObj
(
int64_t
rid
);
void
*
createTscObj
(
const
char
*
user
,
const
char
*
auth
,
const
char
*
db
,
SAppInstInfo
*
pAppInfo
);
void
destroyTscObj
(
void
*
pObj
);
STscObj
*
acquireTscObj
(
int64_t
rid
);
int32_t
releaseTscObj
(
int64_t
rid
);
uint64_t
generateRequestId
();
void
*
createRequest
(
STscObj
*
pObj
,
__taos_async_fn_t
fp
,
void
*
param
,
int32_t
type
);
void
destroyRequest
(
SRequestObj
*
pRequest
);
SRequestObj
*
acquireRequest
(
int64_t
rid
);
int32_t
releaseRequest
(
int64_t
rid
);
void
*
createRequest
(
STscObj
*
pObj
,
__taos_async_fn_t
fp
,
void
*
param
,
int32_t
type
);
void
destroyRequest
(
SRequestObj
*
pRequest
);
SRequestObj
*
acquireRequest
(
int64_t
rid
);
int32_t
releaseRequest
(
int64_t
rid
);
char
*
getDbOfConnection
(
STscObj
*
pObj
);
void
setConnectionDB
(
STscObj
*
pTscObj
,
const
char
*
db
);
void
resetConnectDB
(
STscObj
*
pTscObj
);
int
taos_options_imp
(
TSDB_OPTION
option
,
const
char
*
str
);
int
taos_options_imp
(
TSDB_OPTION
option
,
const
char
*
str
);
void
*
openTransporter
(
const
char
*
user
,
const
char
*
auth
,
int32_t
numOfThreads
);
...
...
@@ -273,12 +283,6 @@ int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArra
int32_t
buildRequest
(
STscObj
*
pTscObj
,
const
char
*
sql
,
int
sqlLen
,
SRequestObj
**
pRequest
);
void
*
doFetchRows
(
SRequestObj
*
pRequest
,
bool
setupOneRowPtr
,
bool
convertUcs4
);
void
doSetOneRowPtr
(
SReqResultInfo
*
pResultInfo
);
void
setResSchemaInfo
(
SReqResultInfo
*
pResInfo
,
const
SSchema
*
pSchema
,
int32_t
numOfCols
);
void
setResPrecision
(
SReqResultInfo
*
pResInfo
,
int32_t
precision
);
int32_t
setQueryResultFromRsp
(
SReqResultInfo
*
pResultInfo
,
const
SRetrieveTableRsp
*
pRsp
,
bool
convertUcs4
);
// --- heartbeat
// global, called by mgmt
int
hbMgrInit
();
...
...
@@ -290,7 +294,7 @@ SAppHbMgr* appHbMgrInit(SAppInstInfo* pAppInstInfo, char* key);
void
appHbMgrCleanup
(
void
);
// conn level
int
hbRegisterConn
(
SAppHbMgr
*
pAppHbMgr
,
int64_t
tscRefId
,
int64_t
clusterId
,
int8_t
connType
);
int
hbRegisterConn
(
SAppHbMgr
*
pAppHbMgr
,
int64_t
tscRefId
,
int64_t
clusterId
,
int8_t
connType
);
void
hbDeregisterConn
(
SAppHbMgr
*
pAppHbMgr
,
SClientHbKey
connKey
);
int
hbAddConnInfo
(
SAppHbMgr
*
pAppHbMgr
,
SClientHbKey
connKey
,
void
*
key
,
void
*
value
,
int32_t
keyLen
,
int32_t
valueLen
);
...
...
source/client/src/clientImpl.c
浏览文件 @
d4734eb1
...
...
@@ -725,6 +725,76 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int
pResultInfo
->
pCol
[
i
].
pData
=
pResultInfo
->
convertBuf
[
i
];
pResultInfo
->
row
[
i
]
=
pResultInfo
->
pCol
[
i
].
pData
;
}
if
(
type
==
TSDB_DATA_TYPE_JSON
)
{
char
*
p
=
taosMemoryRealloc
(
pResultInfo
->
convertBuf
[
i
],
colLength
[
i
]);
if
(
p
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pResultInfo
->
convertBuf
[
i
]
=
p
;
int32_t
len
=
0
;
SResultColumn
*
pCol
=
&
pResultInfo
->
pCol
[
i
];
for
(
int32_t
j
=
0
;
j
<
numOfRows
;
++
j
)
{
if
(
pCol
->
offset
[
j
]
!=
-
1
)
{
char
*
pStart
=
pCol
->
offset
[
j
]
+
pCol
->
pData
;
int32_t
jsonInnerType
=
*
pStart
;
char
*
jsonInnerData
=
pStart
+
CHAR_BYTES
;
char
dst
[
TSDB_MAX_JSON_TAG_LEN
]
=
{
0
};
if
(
jsonInnerType
==
TSDB_DATA_TYPE_NULL
){
sprintf
(
varDataVal
(
dst
),
"%s"
,
TSDB_DATA_NULL_STR_L
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_JSON
){
int32_t
length
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
jsonInnerData
),
varDataLen
(
jsonInnerData
),
varDataVal
(
dst
));
if
(
length
<=
0
)
{
tscError
(
"charset:%s to %s. val:%s convert failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
varDataVal
(
jsonInnerData
));
length
=
0
;
}
varDataSetLen
(
dst
,
length
);
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_NCHAR
)
{
// value -> "value"
*
(
char
*
)
varDataVal
(
dst
)
=
'\"'
;
int32_t
length
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
jsonInnerData
),
varDataLen
(
jsonInnerData
),
varDataVal
(
dst
)
+
CHAR_BYTES
);
if
(
length
<=
0
)
{
tscError
(
"charset:%s to %s. val:%s convert failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
varDataVal
(
jsonInnerData
));
length
=
0
;
}
varDataSetLen
(
dst
,
length
+
CHAR_BYTES
*
2
);
*
(
char
*
)(
varDataVal
(
dst
),
length
+
CHAR_BYTES
)
=
'\"'
;
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_DOUBLE
){
double
jsonVd
=
*
(
double
*
)(
jsonInnerData
);
sprintf
(
varDataVal
(
dst
),
"%.9lf"
,
jsonVd
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_BIGINT
){
int64_t
jsonVd
=
*
(
int64_t
*
)(
jsonInnerData
);
sprintf
(
varDataVal
(
dst
),
"%"
PRId64
,
jsonVd
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_BOOL
){
sprintf
(
varDataVal
(
dst
),
"%s"
,
(
*
((
char
*
)
jsonInnerData
)
==
1
)
?
"true"
:
"false"
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
{
ASSERT
(
0
);
}
if
(
len
+
varDataTLen
(
dst
)
>
colLength
[
i
]){
p
=
taosMemoryRealloc
(
pResultInfo
->
convertBuf
[
i
],
len
+
varDataTLen
(
dst
));
if
(
p
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pResultInfo
->
convertBuf
[
i
]
=
p
;
}
p
=
pResultInfo
->
convertBuf
[
i
]
+
len
;
memcpy
(
p
,
dst
,
varDataTLen
(
dst
));
pCol
->
offset
[
j
]
=
len
;
len
+=
varDataTLen
(
dst
);
}
}
pResultInfo
->
pCol
[
i
].
pData
=
pResultInfo
->
convertBuf
[
i
];
pResultInfo
->
row
[
i
]
=
pResultInfo
->
pCol
[
i
].
pData
;
}
}
return
TSDB_CODE_SUCCESS
;
...
...
source/client/src/clientMain.c
浏览文件 @
d4734eb1
...
...
@@ -14,12 +14,12 @@
*/
#include "catalog.h"
#include "scheduler.h"
#include "clientInt.h"
#include "clientStmt.h"
#include "clientLog.h"
#include "clientStmt.h"
#include "os.h"
#include "query.h"
#include "scheduler.h"
#include "tglobal.h"
#include "tmsg.h"
#include "tref.h"
...
...
@@ -177,25 +177,24 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
return
doFetchRows
(
pRequest
,
true
,
true
);
}
else
if
(
TD_RES_TMQ
(
res
))
{
SMqRspObj
*
msg
=
((
SMqRspObj
*
)
res
);
if
(
msg
->
resIter
==
-
1
)
msg
->
resIter
++
;
SReqResultInfo
*
pResultInfo
=
taosArrayGet
(
msg
->
res
,
msg
->
resIter
);
SMqRspObj
*
msg
=
((
SMqRspObj
*
)
res
);
SReqResultInfo
*
pResultInfo
;
if
(
msg
->
resIter
==
-
1
)
{
pResultInfo
=
tmqGetNextResInfo
(
res
,
true
);
}
else
{
pResultInfo
=
tmqGetCurResInfo
(
res
);
}
if
(
pResultInfo
->
current
<
pResultInfo
->
numOfRows
)
{
doSetOneRowPtr
(
pResultInfo
);
pResultInfo
->
current
+=
1
;
return
pResultInfo
->
row
;
}
else
{
msg
->
resIter
++
;
if
(
msg
->
resIter
<
taosArrayGetSize
(
msg
->
res
))
{
pResultInfo
=
taosArrayGet
(
msg
->
res
,
msg
->
resIter
);
doSetOneRowPtr
(
pResultInfo
);
pResultInfo
->
current
+=
1
;
return
pResultInfo
->
row
;
}
else
{
return
NULL
;
}
pResultInfo
=
tmqGetNextResInfo
(
res
,
true
);
if
(
pResultInfo
==
NULL
)
return
NULL
;
doSetOneRowPtr
(
pResultInfo
);
pResultInfo
->
current
+=
1
;
return
pResultInfo
->
row
;
}
}
else
{
// assert to avoid un-initialization error
ASSERT
(
0
);
...
...
@@ -455,7 +454,7 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) {
(
*
numOfRows
)
=
pResultInfo
->
numOfRows
;
return
pRequest
->
code
;
}
else
if
(
TD_RES_TMQ
(
res
))
{
SReqResultInfo
*
pResultInfo
=
tmqGetNextResInfo
(
res
);
SReqResultInfo
*
pResultInfo
=
tmqGetNextResInfo
(
res
,
true
);
if
(
pResultInfo
==
NULL
)
return
-
1
;
pResultInfo
->
current
=
pResultInfo
->
numOfRows
;
...
...
@@ -474,7 +473,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
}
if
(
TD_RES_TMQ
(
res
))
{
SReqResultInfo
*
pResultInfo
=
tmqGetNextResInfo
(
res
);
SReqResultInfo
*
pResultInfo
=
tmqGetNextResInfo
(
res
,
false
);
if
(
pResultInfo
==
NULL
)
{
(
*
numOfRows
)
=
0
;
return
0
;
...
...
@@ -710,10 +709,8 @@ int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
return
stmtBindBatch
(
stmt
,
bind
);
}
TAOS_RES
*
taos_schemaless_insert
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
,
int
protocol
,
int
precision
)
{
// TODO
return
NULL
;
}
source/client/src/tmq.c
浏览文件 @
d4734eb1
...
...
@@ -72,25 +72,25 @@ struct tmq_conf_t {
struct
tmq_t
{
// conf
char
groupId
[
TSDB_CGROUP_LEN
];
char
clientId
[
256
];
int8_t
autoCommit
;
int8_t
inWaiting
;
char
groupId
[
TSDB_CGROUP_LEN
];
char
clientId
[
256
];
int8_t
autoCommit
;
/*int8_t inWaiting;*/
int64_t
consumerId
;
int32_t
epoch
;
int32_t
resetOffsetCfg
;
int64_t
status
;
STscObj
*
pTscObj
;
tmq_commit_cb
*
commit_cb
;
int32_t
nextTopicIdx
;
int8_t
epStatus
;
int32_t
epSkipCnt
;
int32_t
waitingRequest
;
int32_t
readyRequest
;
SArray
*
clientTopics
;
// SArray<SMqClientTopic>
STaosQueue
*
mqueue
;
// queue of tmq_message_t
STaosQall
*
qall
;
tsem_t
rspSem
;
/*int32_t nextTopicIdx;*/
int8_t
epStatus
;
int32_t
epSkipCnt
;
/*int32_t waitingRequest;*/
/*int32_t readyRequest;*/
SArray
*
clientTopics
;
// SArray<SMqClientTopic>
STaosQueue
*
mqueue
;
// queue of tmq_message_t
STaosQall
*
qall
;
tsem_t
rspSem
;
// stat
int64_t
pollCnt
;
};
...
...
@@ -134,7 +134,7 @@ typedef struct {
int32_t
epoch
;
SMqClientVg
*
vgHandle
;
SMqClientTopic
*
topicHandle
;
SMq
PollRspV2
msg
;
SMq
DataBlkRsp
msg
;
}
SMqPollRspWrapper
;
typedef
struct
{
...
...
@@ -145,6 +145,7 @@ typedef struct {
typedef
struct
{
tmq_t
*
tmq
;
int32_t
code
;
int32_t
sync
;
tsem_t
rspSem
;
}
SMqAskEpCbParam
;
...
...
@@ -255,7 +256,12 @@ int32_t tmq_list_append(tmq_list_t* list, const char* src) {
void
tmq_list_destroy
(
tmq_list_t
*
list
)
{
SArray
*
container
=
&
list
->
container
;
/*taosArrayDestroy(container);*/
taosArrayDestroyEx
(
container
,
(
void
(
*
)(
void
*
))
taosMemoryFree
);
int32_t
sz
=
taosArrayGetSize
(
container
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
str
=
taosArrayGetP
(
container
,
i
);
taosMemoryFree
(
str
);
}
taosArrayDestroy
(
container
);
}
static
int32_t
tmqMakeTopicVgKey
(
char
*
dst
,
const
char
*
topicName
,
int32_t
vg
)
{
...
...
@@ -322,12 +328,12 @@ tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errs
return
NULL
;
}
pTmq
->
pTscObj
=
(
STscObj
*
)
conn
;
pTmq
->
inWaiting
=
0
;
/*pTmq->inWaiting = 0;*/
pTmq
->
status
=
0
;
pTmq
->
pollCnt
=
0
;
pTmq
->
epoch
=
0
;
pTmq
->
waitingRequest
=
0
;
pTmq
->
readyRequest
=
0
;
/*pTmq->waitingRequest = 0;*/
/*pTmq->readyRequest = 0;*/
pTmq
->
epStatus
=
0
;
pTmq
->
epSkipCnt
=
0
;
// set conf
...
...
@@ -367,12 +373,12 @@ tmq_t* tmq_consumer_new1(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
pTmq
->
pTscObj
=
taos_connect_internal
(
conf
->
ip
,
user
,
pass
,
NULL
,
conf
->
db
,
conf
->
port
,
CONN_TYPE__TMQ
);
if
(
pTmq
->
pTscObj
==
NULL
)
return
NULL
;
pTmq
->
inWaiting
=
0
;
/*pTmq->inWaiting = 0;*/
pTmq
->
status
=
0
;
pTmq
->
pollCnt
=
0
;
pTmq
->
epoch
=
0
;
pTmq
->
waitingRequest
=
0
;
pTmq
->
readyRequest
=
0
;
/*pTmq->waitingRequest = 0;*/
/*pTmq->readyRequest = 0;*/
pTmq
->
epStatus
=
0
;
pTmq
->
epSkipCnt
=
0
;
// set conf
...
...
@@ -496,7 +502,7 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) {
SCMSubscribeReq
req
;
req
.
topicNum
=
sz
;
req
.
consumerId
=
tmq
->
consumerId
;
req
.
consumerGroup
=
strdup
(
tmq
->
groupId
);
strcpy
(
req
.
cgroup
,
tmq
->
groupId
);
req
.
topicNames
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
...
...
@@ -857,7 +863,6 @@ void tmqShowMsg(tmq_message_t* tmq_message) {
#endif
int32_t
tmqPollCb
(
void
*
param
,
const
SDataBuf
*
pMsg
,
int32_t
code
)
{
/*printf("recv poll\n");*/
SMqPollCbParam
*
pParam
=
(
SMqPollCbParam
*
)
param
;
SMqClientVg
*
pVg
=
pParam
->
pVg
;
SMqClientTopic
*
pTopic
=
pParam
->
pTopic
;
...
...
@@ -870,17 +875,15 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
int32_t
msgEpoch
=
((
SMqRspHead
*
)
pMsg
->
pData
)
->
epoch
;
int32_t
tmqEpoch
=
atomic_load_32
(
&
tmq
->
epoch
);
if
(
msgEpoch
<
tmqEpoch
)
{
/*printf("discard rsp epoch %d, current epoch %d\n", msgEpoch, tmqEpoch);*/
/*tsem_post(&tmq->rspSem);*/
// do not write into queue since updating epoch reset
tscWarn
(
"msg discard from vg %d since from earlier epoch, rsp epoch %d, current epoch %d"
,
pParam
->
vgId
,
msgEpoch
,
tmqEpoch
);
/*tsem_post(&tmq->rspSem);*/
return
0
;
}
if
(
msgEpoch
!=
tmqEpoch
)
{
tscWarn
(
"mismatch rsp from vg %d, epoch %d, current epoch %d"
,
pParam
->
vgId
,
msgEpoch
,
tmqEpoch
);
}
else
{
atomic_sub_fetch_32
(
&
tmq
->
waitingRequest
,
1
);
}
#if 0
...
...
@@ -902,45 +905,33 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
}
#endif
/*SMqConsumeRsp* pRsp = taosMemoryCalloc(1, sizeof(SMqConsumeRsp));*/
/*tmq_message_t* pRsp = taosAllocateQitem(sizeof(tmq_message_t));*/
SMqPollRspWrapper
*
pRspWrapper
=
taosAllocateQitem
(
sizeof
(
SMqPollRspWrapper
));
if
(
pRspWrapper
==
NULL
)
{
tscWarn
(
"msg discard from vg %d, epoch %d since out of memory"
,
pParam
->
vgId
,
pParam
->
epoch
);
goto
CREATE_MSG_FAIL
;
}
pRspWrapper
->
tmqRspType
=
TMQ_MSG_TYPE__POLL_RSP
;
pRspWrapper
->
vgHandle
=
pVg
;
pRspWrapper
->
topicHandle
=
pTopic
;
/*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
/*pRsp->*/
/*printf("rsp commit off:%ld rsp off:%ld has data:%d\n", pRsp->committedOffset, pRsp->rspOffset, pRsp->numOfTopics);*/
#if 0
if (pRsp->msg.numOfTopics == 0) {
/*printf("no data\n");*/
taosFreeQitem(pRsp);
goto CREATE_MSG_FAIL;
}
#endif
tDecodeSMqDataBlkRsp
(
POINTER_SHIFT
(
pMsg
->
pData
,
sizeof
(
SMqRspHead
)),
&
pRspWrapper
->
msg
);
tscDebug
(
"consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld"
,
tmq
->
consumerId
,
pVg
->
vgId
,
pRspWrapper
->
msg
.
reqOffset
,
pRspWrapper
->
msg
.
rspOffset
);
taosWriteQitem
(
tmq
->
mqueue
,
pRspWrapper
);
atomic_add_fetch_32
(
&
tmq
->
readyRequest
,
1
);
/*tsem_post(&tmq->rspSem);*/
return
0
;
return
0
;
CREATE_MSG_FAIL:
if
(
pParam
->
epoch
==
tmq
->
epoch
)
{
atomic_store_32
(
&
pVg
->
vgStatus
,
TMQ_VG_STATUS__IDLE
);
}
/*tsem_post(&tmq->rspSem);*/
return
code
;
return
-
1
;
}
bool
tmqUpdateEp
(
tmq_t
*
tmq
,
int32_t
epoch
,
SMqCMGetSubEpRsp
*
pRsp
)
{
...
...
@@ -1023,6 +1014,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
int32_t
tmqAskEpCb
(
void
*
param
,
const
SDataBuf
*
pMsg
,
int32_t
code
)
{
SMqAskEpCbParam
*
pParam
=
(
SMqAskEpCbParam
*
)
param
;
tmq_t
*
tmq
=
pParam
->
tmq
;
pParam
->
code
=
code
;
if
(
code
!=
0
)
{
tscError
(
"consumer %ld get topic endpoint error, not ready, wait:%d"
,
tmq
->
consumerId
,
pParam
->
sync
);
goto
END
;
...
...
@@ -1062,6 +1054,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) {
taosWriteQitem
(
tmq
->
mqueue
,
pWrapper
);
/*tsem_post(&tmq->rspSem);*/
taosMemoryFree
(
pParam
);
}
END:
...
...
@@ -1073,7 +1066,8 @@ END:
}
int32_t
tmqAskEp
(
tmq_t
*
tmq
,
bool
sync
)
{
int8_t
epStatus
=
atomic_val_compare_exchange_8
(
&
tmq
->
epStatus
,
0
,
1
);
int32_t
code
=
0
;
int8_t
epStatus
=
atomic_val_compare_exchange_8
(
&
tmq
->
epStatus
,
0
,
1
);
if
(
epStatus
==
1
)
{
int32_t
epSkipCnt
=
atomic_add_fetch_32
(
&
tmq
->
epSkipCnt
,
1
);
tscTrace
(
"consumer %ld skip ask ep cnt %d"
,
tmq
->
consumerId
,
epSkipCnt
);
...
...
@@ -1130,8 +1124,12 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) {
int64_t
transporterId
=
0
;
asyncSendMsgToServer
(
tmq
->
pTscObj
->
pAppInfo
->
pTransporter
,
&
epSet
,
&
transporterId
,
sendInfo
);
if
(
sync
)
tsem_wait
(
&
pParam
->
rspSem
);
return
0
;
if
(
sync
)
{
tsem_wait
(
&
pParam
->
rspSem
);
code
=
pParam
->
code
;
taosMemoryFree
(
pParam
);
}
return
code
;
}
tmq_resp_err_t
tmq_seek
(
tmq_t
*
tmq
,
const
tmq_topic_vgroup_t
*
offset
)
{
...
...
@@ -1157,7 +1155,7 @@ tmq_resp_err_t tmq_seek(tmq_t* tmq, const tmq_topic_vgroup_t* offset) {
return
TMQ_RESP_ERR__FAIL
;
}
SMqPollReq
*
tmqBuildConsumeReqImpl
(
tmq_t
*
tmq
,
int64_t
blockingTime
,
SMqClientTopic
*
pTopic
,
SMqClientVg
*
pVg
)
{
SMqPollReq
V2
*
tmqBuildConsumeReqImpl
(
tmq_t
*
tmq
,
int64_t
blockingTime
,
SMqClientTopic
*
pTopic
,
SMqClientVg
*
pVg
)
{
int64_t
reqOffset
;
if
(
pVg
->
currentOffset
>=
0
)
{
reqOffset
=
pVg
->
currentOffset
;
...
...
@@ -1169,13 +1167,18 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTo
reqOffset
=
tmq
->
resetOffsetCfg
;
}
SMqPollReq
*
pReq
=
taosMemoryMalloc
(
sizeof
(
SMqPollReq
));
SMqPollReq
V2
*
pReq
=
taosMemoryMalloc
(
sizeof
(
SMqPollReqV2
));
if
(
pReq
==
NULL
)
{
return
NULL
;
}
strcpy
(
pReq
->
topic
,
pTopic
->
topicName
);
strcpy
(
pReq
->
cgroup
,
tmq
->
groupId
);
/*strcpy(pReq->topic, pTopic->topicName);*/
/*strcpy(pReq->cgroup, tmq->groupId);*/
int32_t
tlen
=
strlen
(
tmq
->
groupId
);
memcpy
(
pReq
->
subKey
,
tmq
->
groupId
,
tlen
);
pReq
->
subKey
[
tlen
]
=
TMQ_SEPARATOR
;
strcpy
(
pReq
->
subKey
+
tlen
+
1
,
pTopic
->
topicName
);
pReq
->
blockingTime
=
blockingTime
;
pReq
->
consumerId
=
tmq
->
consumerId
;
...
...
@@ -1184,101 +1187,26 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTo
pReq
->
reqId
=
generateRequestId
();
pReq
->
head
.
vgId
=
htonl
(
pVg
->
vgId
);
pReq
->
head
.
contLen
=
htonl
(
sizeof
(
SMqPollReq
));
pReq
->
head
.
contLen
=
htonl
(
sizeof
(
SMqPollReq
V2
));
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
;
strncpy
(
pRspObj
->
topic
,
pWrapper
->
topicHandle
->
topicName
,
TSDB_TOPIC_FNAME_LEN
);
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
tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) {
tmq_message_t* msg = NULL;
for (int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) {
SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i);
for (int j = 0; j < taosArrayGetSize(pTopic->vgs); j++) {
SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j);
int32_t vgStatus = atomic_val_compare_exchange_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE, TMQ_VG_STATUS__WAIT);
/*if (vgStatus != TMQ_VG_STATUS__IDLE) {*/
/*continue;*/
/*}*/
SMqPollReq* pReq = tmqBuildConsumeReqImpl(tmq, blockingTime, pTopic, pVg);
if (pReq == NULL) {
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
// TODO: out of mem
return NULL;
}
SMqPollCbParam* pParam = taosMemoryMalloc(sizeof(SMqPollCbParam));
if (pParam == NULL) {
atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
// TODO: out of mem
return NULL;
}
pParam->tmq = tmq;
pParam->pVg = pVg;
pParam->epoch = tmq->epoch;
pParam->sync = 1;
pParam->msg = &msg;
tsem_init(&pParam->rspSem, 0, 0);
SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo));
if (sendInfo == NULL) {
return NULL;
}
sendInfo->msgInfo = (SDataBuf){
.pData = pReq,
.len = sizeof(SMqPollReq),
.handle = NULL,
};
sendInfo->requestId = generateRequestId();
sendInfo->requestObjRefId = 0;
sendInfo->param = pParam;
sendInfo->fp = tmqPollCb;
sendInfo->msgType = TDMT_VND_CONSUME;
pRspObj
->
resIter
=
-
1
;
memcpy
(
&
pRspObj
->
rsp
,
&
pWrapper
->
msg
,
sizeof
(
SMqDataBlkRsp
));
int64_t transporterId = 0;
/*printf("send poll\n");*/
atomic_add_fetch_32(&tmq->waitingRequest, 1);
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, &transporterId, sendInfo);
pVg->pollCnt++;
tmq->pollCnt++;
/*SRetrieveTableRsp* pRetrieve = taosArrayGetP(pWrapper->msg.blockData, 0);*/
pRspObj
->
resInfo
.
totalRows
=
0
;
pRspObj
->
resInfo
.
precision
=
TSDB_TIME_PRECISION_MILLI
;
setResSchemaInfo
(
&
pRspObj
->
resInfo
,
pWrapper
->
topicHandle
->
schema
.
pSchema
,
pWrapper
->
topicHandle
->
schema
.
nCols
);
tsem_wait(&pParam->rspSem);
tmq_message_t* nmsg = NULL;
while (1) {
taosReadQitem(tmq->mqueue, (void**)&nmsg);
if (nmsg == NULL) continue;
while (nmsg->head.mqMsgType != TMQ_MSG_TYPE__POLL_RSP) {
taosReadQitem(tmq->mqueue, (void**)&nmsg);
}
return nmsg;
}
}
}
return NULL;
taosFreeQitem
(
pWrapper
);
return
pRspObj
;
}
#endif
int32_t
tmqPollImpl
(
tmq_t
*
tmq
,
int64_t
blockingTime
)
{
/*printf("call poll\n");*/
...
...
@@ -1301,7 +1229,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
#endif
}
atomic_store_32
(
&
pVg
->
vgSkipCnt
,
0
);
SMqPollReq
*
pReq
=
tmqBuildConsumeReqImpl
(
tmq
,
blockingTime
,
pTopic
,
pVg
);
SMqPollReq
V2
*
pReq
=
tmqBuildConsumeReqImpl
(
tmq
,
blockingTime
,
pTopic
,
pVg
);
if
(
pReq
==
NULL
)
{
atomic_store_32
(
&
pVg
->
vgStatus
,
TMQ_VG_STATUS__IDLE
);
/*tsem_post(&tmq->rspSem);*/
...
...
@@ -1332,7 +1260,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
sendInfo
->
msgInfo
=
(
SDataBuf
){
.
pData
=
pReq
,
.
len
=
sizeof
(
SMqPollReq
),
.
len
=
sizeof
(
SMqPollReq
V2
),
.
handle
=
NULL
,
};
sendInfo
->
requestId
=
pReq
->
reqId
;
...
...
@@ -1343,7 +1271,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
int64_t
transporterId
=
0
;
/*printf("send poll\n");*/
atomic_add_fetch_32
(
&
tmq
->
waitingRequest
,
1
);
/*atomic_add_fetch_32(&tmq->waitingRequest, 1);*/
tscDebug
(
"consumer %ld send poll to %s : vg %d, epoch %d, req offset %ld, reqId %lu"
,
tmq
->
consumerId
,
pTopic
->
topicName
,
pVg
->
vgId
,
tmq
->
epoch
,
pVg
->
currentOffset
,
pReq
->
reqId
);
/*printf("send vg %d %ld\n", pVg->vgId, pVg->currentOffset);*/
...
...
@@ -1385,7 +1313,7 @@ SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfReset) {
if
(
rspWrapper
->
tmqRspType
==
TMQ_MSG_TYPE__POLL_RSP
)
{
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);*/
if
(
pollRspWrapper
->
msg
.
head
.
epoch
==
atomic_load_32
(
&
tmq
->
epoch
))
{
/*printf("epoch match\n");*/
...
...
@@ -1393,7 +1321,7 @@ SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfReset) {
/*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/
pVg
->
currentOffset
=
pollRspWrapper
->
msg
.
rspOffset
;
atomic_store_32
(
&
pVg
->
vgStatus
,
TMQ_VG_STATUS__IDLE
);
if
(
pollRspWrapper
->
msg
.
dataLen
==
0
)
{
if
(
pollRspWrapper
->
msg
.
blockNum
==
0
)
{
taosFreeQitem
(
pollRspWrapper
);
rspWrapper
=
NULL
;
continue
;
...
...
@@ -1449,7 +1377,10 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) {
// TODO: put into another thread or delayed queue
int64_t
status
=
atomic_load_64
(
&
tmq
->
status
);
tmqAskEp
(
tmq
,
status
==
TMQ_CONSUMER_STATUS__INIT
);
while
(
0
!=
tmqAskEp
(
tmq
,
status
==
TMQ_CONSUMER_STATUS__INIT
))
{
tscDebug
(
"not ready, retry
\n
"
);
taosSsleep
(
1
);
}
rspObj
=
tmqHandleAllRsp
(
tmq
,
blocking_time
,
false
);
if
(
rspObj
)
{
...
...
source/common/src/tdatablock.c
浏览文件 @
d4734eb1
...
...
@@ -113,14 +113,27 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
int32_t
type
=
pColumnInfoData
->
info
.
type
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
int32_t
dataLen
=
varDataTLen
(
pData
);
if
(
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
*
pData
==
TSDB_DATA_TYPE_NULL
)
{
dataLen
=
0
;
}
else
if
(
*
pData
==
TSDB_DATA_TYPE_NCHAR
)
{
dataLen
=
varDataTLen
(
pData
+
CHAR_BYTES
);
}
else
if
(
*
pData
==
TSDB_DATA_TYPE_BIGINT
||
*
pData
==
TSDB_DATA_TYPE_DOUBLE
)
{
dataLen
=
LONG_BYTES
;
}
else
if
(
*
pData
==
TSDB_DATA_TYPE_BOOL
)
{
dataLen
=
CHAR_BYTES
;
}
dataLen
+=
CHAR_BYTES
;
}
SVarColAttr
*
pAttr
=
&
pColumnInfoData
->
varmeta
;
if
(
pAttr
->
allocLen
<
pAttr
->
length
+
varDataTLen
(
pData
)
)
{
if
(
pAttr
->
allocLen
<
pAttr
->
length
+
dataLen
)
{
uint32_t
newSize
=
pAttr
->
allocLen
;
if
(
newSize
==
0
)
{
newSize
=
8
;
}
while
(
newSize
<
pAttr
->
length
+
varDataTLen
(
pData
)
)
{
while
(
newSize
<
pAttr
->
length
+
dataLen
)
{
newSize
=
newSize
*
1
.
5
;
}
...
...
@@ -136,8 +149,8 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
uint32_t
len
=
pColumnInfoData
->
varmeta
.
length
;
pColumnInfoData
->
varmeta
.
offset
[
currentRow
]
=
len
;
memcpy
(
pColumnInfoData
->
pData
+
len
,
pData
,
varDataTLen
(
pData
)
);
pColumnInfoData
->
varmeta
.
length
+=
varDataTLen
(
pData
)
;
memcpy
(
pColumnInfoData
->
pData
+
len
,
pData
,
dataLen
);
pColumnInfoData
->
varmeta
.
length
+=
dataLen
;
}
else
{
memcpy
(
pColumnInfoData
->
pData
+
pColumnInfoData
->
info
.
bytes
*
currentRow
,
pData
,
pColumnInfoData
->
info
.
bytes
);
}
...
...
source/common/src/tmsg.c
浏览文件 @
d4734eb1
...
...
@@ -125,14 +125,14 @@ int32_t taosEncodeSEpSet(void **buf, const SEpSet *pEp) {
return
tlen
;
}
void
*
taosDecodeSEpSet
(
void
*
buf
,
SEpSet
*
pEp
)
{
void
*
taosDecodeSEpSet
(
const
void
*
buf
,
SEpSet
*
pEp
)
{
buf
=
taosDecodeFixedI8
(
buf
,
&
pEp
->
inUse
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pEp
->
numOfEps
);
for
(
int32_t
i
=
0
;
i
<
TSDB_MAX_REPLICA
;
i
++
)
{
buf
=
taosDecodeFixedU16
(
buf
,
&
pEp
->
eps
[
i
].
port
);
buf
=
taosDecodeStringTo
(
buf
,
pEp
->
eps
[
i
].
fqdn
);
}
return
buf
;
return
(
void
*
)
buf
;
}
static
int32_t
tSerializeSClientHbReq
(
SCoder
*
pEncoder
,
const
SClientHbReq
*
pReq
)
{
...
...
@@ -3599,8 +3599,6 @@ int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateS
if
(
tEncodeI8
(
&
encoder
,
pReq
->
igExists
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
sqlLen
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
astLen
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
&
encoder
,
pReq
->
triggerType
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
&
encoder
,
pReq
->
watermark
)
<
0
)
return
-
1
;
if
(
sqlLen
>
0
&&
tEncodeCStr
(
&
encoder
,
pReq
->
sql
)
<
0
)
return
-
1
;
if
(
astLen
>
0
&&
tEncodeCStr
(
&
encoder
,
pReq
->
ast
)
<
0
)
return
-
1
;
...
...
source/common/src/ttypes.c
浏览文件 @
d4734eb1
...
...
@@ -379,7 +379,7 @@ static void getStatics_nchr(int8_t bitmapMode, const void *pBitmap, const void *
*
maxIndex
=
0
;
}
tDataTypeDescriptor
tDataTypes
[
15
]
=
{
tDataTypeDescriptor
tDataTypes
[
TSDB_DATA_TYPE_MAX
]
=
{
{
TSDB_DATA_TYPE_NULL
,
6
,
1
,
"NOTYPE"
,
0
,
0
,
NULL
,
NULL
,
NULL
},
{
TSDB_DATA_TYPE_BOOL
,
4
,
CHAR_BYTES
,
"BOOL"
,
false
,
true
,
tsCompressBool
,
tsDecompressBool
,
getStatics_bool
},
{
TSDB_DATA_TYPE_TINYINT
,
7
,
CHAR_BYTES
,
"TINYINT"
,
INT8_MIN
,
INT8_MAX
,
tsCompressTinyint
,
tsDecompressTinyint
,
...
...
@@ -402,6 +402,7 @@ tDataTypeDescriptor tDataTypes[15] = {
{
TSDB_DATA_TYPE_UINT
,
12
,
INT_BYTES
,
"INT UNSIGNED"
,
0
,
UINT32_MAX
,
tsCompressInt
,
tsDecompressInt
,
getStatics_u32
},
{
TSDB_DATA_TYPE_UBIGINT
,
15
,
LONG_BYTES
,
"BIGINT UNSIGNED"
,
0
,
UINT64_MAX
,
tsCompressBigint
,
tsDecompressBigint
,
getStatics_u64
},
{
TSDB_DATA_TYPE_JSON
,
4
,
TSDB_MAX_JSON_TAG_LEN
,
"JSON"
,
0
,
0
,
tsCompressString
,
tsDecompressString
,
getStatics_nchr
},
};
char
tTokenTypeSwitcher
[
13
]
=
{
...
...
source/common/src/tvariant.c
浏览文件 @
d4734eb1
...
...
@@ -118,7 +118,7 @@ void taosVariantCreate(SVariant *pVar, const char *z, int32_t n, int32_t type) {
}
case
TSDB_DATA_TYPE_BINARY
:
{
pVar
->
pz
=
strndup
(
z
,
n
);
pVar
->
nLen
=
strRmquote
(
pVar
->
pz
,
n
);
//
pVar->nLen = strRmquote(pVar->pz, n);
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
...
...
source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
浏览文件 @
d4734eb1
...
...
@@ -211,6 +211,7 @@ void mmInitMsgHandle(SMgmtWrapper *pWrapper) {
dmSetMsgHandle
(
pWrapper
,
TDMT_MND_SUBSCRIBE
,
mmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_MND_MQ_COMMIT_OFFSET
,
mmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_MND_GET_SUB_EP
,
mmProcessReadMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_MQ_VG_CHANGE_RSP
,
mmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_MND_CREATE_STREAM
,
mmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_TASK_DEPLOY_RSP
,
mmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_MND_GET_DB_CFG
,
mmProcessReadMsg
,
DEFAULT_HANDLE
);
...
...
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
浏览文件 @
d4734eb1
...
...
@@ -252,7 +252,7 @@ void vmInitMsgHandle(SMgmtWrapper *pWrapper) {
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_MQ_QUERY
,
vmProcessQueryMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_MQ_CONNECT
,
vmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_MQ_DISCONNECT
,
vmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_MQ_SET_CUR
,
vmProcessWriteMsg
,
DEFAULT_HANDLE
);
//
dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, vmProcessWriteMsg, DEFAULT_HANDLE);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_RES_READY
,
vmProcessFetchMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_TASKS_STATUS
,
vmProcessFetchMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_CANCEL_TASK
,
vmProcessFetchMsg
,
DEFAULT_HANDLE
);
...
...
@@ -265,10 +265,11 @@ void vmInitMsgHandle(SMgmtWrapper *pWrapper) {
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_CREATE_SMA
,
vmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_CANCEL_SMA
,
vmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_DROP_SMA
,
vmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_MQ_SET_CONN
,
vmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_MQ_REB
,
vmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_MQ_CANCEL_CONN
,
vmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_MQ_SET_CUR
,
vmProcessFetchMsg
,
DEFAULT_HANDLE
);
//dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, vmProcessWriteMsg, DEFAULT_HANDLE);
//dmSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, vmProcessWriteMsg, DEFAULT_HANDLE);
//dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN, vmProcessWriteMsg, DEFAULT_HANDLE);
//dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, vmProcessFetchMsg, DEFAULT_HANDLE);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_MQ_VG_CHANGE
,
(
NodeMsgFp
)
vmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_CONSUME
,
vmProcessFetchMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_TASK_DEPLOY
,
vmProcessWriteMsg
,
DEFAULT_HANDLE
);
dmSetMsgHandle
(
pWrapper
,
TDMT_VND_QUERY_HEARTBEAT
,
vmProcessFetchMsg
,
DEFAULT_HANDLE
);
...
...
source/dnode/mnode/impl/inc/mndConsumer.h
浏览文件 @
d4734eb1
...
...
@@ -22,27 +22,30 @@
extern
"C"
{
#endif
enum
{
MQ_CONSUMER_STATUS__INIT
=
1
,
MQ_CONSUMER_STATUS__IDLE
,
MQ_CONSUMER_STATUS__ACTIVE
,
// MQ_CONSUMER_STATUS__INIT = 1,
MQ_CONSUMER_STATUS__MODIFY
=
1
,
MQ_CONSUMER_STATUS__MODIFY_IN_REB
,
// MQ_CONSUMER_STATUS__IDLE,
MQ_CONSUMER_STATUS__READY
,
MQ_CONSUMER_STATUS__LOST
,
MQ_CONSUMER_STATUS__MODIFY
MQ_CONSUMER_STATUS__LOST_IN_REB
,
MQ_CONSUMER_STATUS__LOST_REBD
,
};
int32_t
mndInitConsumer
(
SMnode
*
pMnode
);
void
mndCleanupConsumer
(
SMnode
*
pMnode
);
SMqConsumerObj
*
mndAcquireConsumer
(
SMnode
*
pMnode
,
int64_t
consumerId
);
void
mndReleaseConsumer
(
SMnode
*
pMnode
,
SMqConsumerObj
*
pConsumer
);
SMqConsumerObj
*
mndCreateConsumer
(
int64_t
consumerId
,
const
char
*
cgroup
);
SMqConsumerObj
*
mndCreateConsumer
(
int64_t
consumerId
,
const
char
*
cgroup
);
SSdbRaw
*
mndConsumerActionEncode
(
SMqConsumerObj
*
pConsumer
);
SSdbRow
*
mndConsumerActionDecode
(
SSdbRaw
*
pRaw
);
int32_t
mndSetConsumerCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SMqConsumerObj
*
pConsumer
);
#ifdef __cplusplus
}
#endif
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
d4734eb1
...
...
@@ -88,6 +88,7 @@ typedef enum {
TRN_TYPE_CREATE_STREAM
=
1019
,
TRN_TYPE_DROP_STREAM
=
1020
,
TRN_TYPE_ALTER_STREAM
=
1021
,
TRN_TYPE_CONSUMER_LOST
=
1022
,
TRN_TYPE_BASIC_SCOPE_END
,
TRN_TYPE_GLOBAL_SCOPE
=
2000
,
TRN_TYPE_CREATE_DNODE
=
2001
,
...
...
@@ -511,6 +512,7 @@ static FORCE_INLINE void* tDecodeSMqOffsetObj(void* buf, SMqOffsetObj* pOffset)
return
buf
;
}
#if 0
typedef struct {
char key[TSDB_SUBSCRIBE_KEY_LEN];
int32_t status;
...
...
@@ -641,6 +643,7 @@ static FORCE_INLINE void tDeleteSMqSubscribeObj(SMqSubscribeObj* pSub) {
pSub->unassignedVg = NULL;
}
}
#endif
typedef
struct
{
char
name
[
TSDB_TOPIC_FNAME_LEN
];
...
...
@@ -659,6 +662,7 @@ typedef struct {
SSchemaWrapper
schema
;
}
SMqTopicObj
;
#if 0
typedef struct {
int64_t consumerId;
int64_t connId;
...
...
@@ -713,7 +717,7 @@ static FORCE_INLINE void* tDecodeSMqConsumerObj(void* buf, SMqConsumerObj* pCons
buf = taosDecodeStringTo(buf, pConsumer->cgroup);
buf = taosDecodeFixedI32(buf, &sz);
pConsumer
->
currentTopics
=
taosArrayInit
(
sz
,
sizeof
(
SMqConsumerObj
));
pConsumer->currentTopics = taosArrayInit(sz, sizeof(
void*
));
for (int32_t i = 0; i < sz; i++) {
char* topic;
buf = taosDecodeString(buf, &topic);
...
...
@@ -721,7 +725,7 @@ static FORCE_INLINE void* tDecodeSMqConsumerObj(void* buf, SMqConsumerObj* pCons
}
buf = taosDecodeFixedI32(buf, &sz);
pConsumer
->
recentRemovedTopics
=
taosArrayInit
(
sz
,
sizeof
(
SMqConsumerObj
));
pConsumer->recentRemovedTopics = taosArrayInit(sz, sizeof(
void*
));
for (int32_t i = 0; i < sz; i++) {
char* topic;
buf = taosDecodeString(buf, &topic);
...
...
@@ -729,6 +733,132 @@ static FORCE_INLINE void* tDecodeSMqConsumerObj(void* buf, SMqConsumerObj* pCons
}
return buf;
}
#endif
enum
{
CONSUMER_UPDATE__TOUCH
=
1
,
CONSUMER_UPDATE__ADD
,
CONSUMER_UPDATE__REMOVE
,
CONSUMER_UPDATE__LOST
,
CONSUMER_UPDATE__MODIFY
,
};
typedef
struct
{
int64_t
consumerId
;
char
cgroup
[
TSDB_CGROUP_LEN
];
int8_t
updateType
;
// used only for update
int32_t
epoch
;
int32_t
status
;
// hbStatus is not applicable to serialization
int32_t
hbStatus
;
// lock is used for topics update
SRWLatch
lock
;
SArray
*
currentTopics
;
// SArray<char*>
#if 0
SArray* waitingRebTopics; // SArray<char*>
#endif
SArray
*
rebNewTopics
;
// SArray<char*>
SArray
*
rebRemovedTopics
;
// SArray<char*>
}
SMqConsumerObj
;
SMqConsumerObj
*
tNewSMqConsumerObj
(
int64_t
consumerId
,
char
cgroup
[
TSDB_CGROUP_LEN
]);
void
tDeleteSMqConsumerObj
(
SMqConsumerObj
*
pConsumer
);
int32_t
tEncodeSMqConsumerObj
(
void
**
buf
,
const
SMqConsumerObj
*
pConsumer
);
void
*
tDecodeSMqConsumerObj
(
const
void
*
buf
,
SMqConsumerObj
*
pConsumer
);
typedef
struct
{
int32_t
vgId
;
char
*
qmsg
;
// char topic[TSDB_TOPIC_FNAME_LEN];
SEpSet
epSet
;
}
SMqVgEp
;
SMqVgEp
*
tCloneSMqVgEp
(
const
SMqVgEp
*
pVgEp
);
void
tDeleteSMqVgEp
(
SMqVgEp
*
pVgEp
);
int32_t
tEncodeSMqVgEp
(
void
**
buf
,
const
SMqVgEp
*
pVgEp
);
void
*
tDecodeSMqVgEp
(
const
void
*
buf
,
SMqVgEp
*
pVgEp
);
typedef
struct
{
int64_t
consumerId
;
// -1 for unassigned
SArray
*
vgs
;
// SArray<SMqVgEp*>
}
SMqConsumerEpInSub
;
SMqConsumerEpInSub
*
tCloneSMqConsumerEpInSub
(
const
SMqConsumerEpInSub
*
pEpInSub
);
void
tDeleteSMqConsumerEpInSub
(
SMqConsumerEpInSub
*
pEpInSub
);
int32_t
tEncodeSMqConsumerEpInSub
(
void
**
buf
,
const
SMqConsumerEpInSub
*
pEpInSub
);
void
*
tDecodeSMqConsumerEpInSub
(
const
void
*
buf
,
SMqConsumerEpInSub
*
pEpInSub
);
typedef
struct
{
char
key
[
TSDB_SUBSCRIBE_KEY_LEN
];
SRWLatch
lock
;
int32_t
vgNum
;
SHashObj
*
consumerHash
;
// consumerId -> SMqConsumerEpInSub
}
SMqSubscribeObj
;
SMqSubscribeObj
*
tNewSubscribeObj
(
const
char
key
[
TSDB_SUBSCRIBE_KEY_LEN
]);
SMqSubscribeObj
*
tCloneSubscribeObj
(
const
SMqSubscribeObj
*
pSub
);
void
tDeleteSubscribeObj
(
SMqSubscribeObj
*
pSub
);
int32_t
tEncodeSubscribeObj
(
void
**
buf
,
const
SMqSubscribeObj
*
pSub
);
void
*
tDecodeSubscribeObj
(
const
void
*
buf
,
SMqSubscribeObj
*
pSub
);
typedef
struct
{
int32_t
epoch
;
SArray
*
consumers
;
// SArray<SMqConsumerEpInSub*>
}
SMqSubActionLogEntry
;
SMqSubActionLogEntry
*
tCloneSMqSubActionLogEntry
(
SMqSubActionLogEntry
*
pEntry
);
void
tDeleteSMqSubActionLogEntry
(
SMqSubActionLogEntry
*
pEntry
);
int32_t
tEncodeSMqSubActionLogEntry
(
void
**
buf
,
const
SMqSubActionLogEntry
*
pEntry
);
void
*
tDecodeSMqSubActionLogEntry
(
const
void
*
buf
,
SMqSubActionLogEntry
*
pEntry
);
typedef
struct
{
char
key
[
TSDB_SUBSCRIBE_KEY_LEN
];
SArray
*
logs
;
// SArray<SMqSubActionLogEntry*>
}
SMqSubActionLogObj
;
SMqSubActionLogObj
*
tCloneSMqSubActionLogObj
(
SMqSubActionLogObj
*
pLog
);
void
tDeleteSMqSubActionLogObj
(
SMqSubActionLogObj
*
pLog
);
int32_t
tEncodeSMqSubActionLogObj
(
void
**
buf
,
const
SMqSubActionLogObj
*
pLog
);
void
*
tDecodeSMqSubActionLogObj
(
const
void
*
buf
,
SMqSubActionLogObj
*
pLog
);
typedef
struct
{
int64_t
consumerId
;
char
cgroup
[
TSDB_CGROUP_LEN
];
SRWLatch
lock
;
SArray
*
vgs
;
// SArray<SMqVgEp*>
}
SMqConsumerEpObj
;
SMqConsumerEpObj
*
tCloneSMqConsumerEpObj
(
const
SMqConsumerEpObj
*
pConsumerEp
);
void
tDeleteSMqConsumerEpObj
(
SMqConsumerEpObj
*
pConsumerEp
);
int32_t
tEncodeSMqConsumerEpObj
(
void
**
buf
,
const
SMqConsumerEpObj
*
pConsumerEp
);
void
*
tDecodeSMqConsumerEpObj
(
const
void
*
buf
,
SMqConsumerEpObj
*
pConsumerEp
);
typedef
struct
{
const
SMqSubscribeObj
*
pOldSub
;
const
SMqTopicObj
*
pTopic
;
const
SMqRebSubscribe
*
pRebInfo
;
}
SMqRebInputObj
;
typedef
struct
{
int64_t
oldConsumerId
;
int64_t
newConsumerId
;
SMqVgEp
*
pVgEp
;
}
SMqRebOutputVg
;
#if 0
typedef struct {
int64_t consumerId;
} SMqRebOutputConsumer;
#endif
typedef
struct
{
SArray
*
rebVgs
;
// SArray<SMqRebOutputVg>
SArray
*
newConsumers
;
// SArray<int64_t>
SArray
*
removedConsumers
;
// SArray<int64_t>
SArray
*
touchedConsumers
;
// SArray<int64_t>
SMqSubscribeObj
*
pSub
;
SMqSubActionLogEntry
*
pLogEntry
;
}
SMqRebOutputObj
;
typedef
struct
{
char
name
[
TSDB_TOPIC_FNAME_LEN
];
...
...
source/dnode/mnode/impl/inc/mndOffset.h
浏览文件 @
d4734eb1
...
...
@@ -31,7 +31,7 @@ void mndReleaseOffset(SMnode *pMnode, SMqOffsetObj *pOffset);
SSdbRaw
*
mndOffsetActionEncode
(
SMqOffsetObj
*
pOffset
);
SSdbRow
*
mndOffsetActionDecode
(
SSdbRaw
*
pRaw
);
int32_t
mndCreateOffset
(
STrans
*
pTrans
,
const
char
*
cgroup
,
const
char
*
topicName
,
const
SArray
*
vgs
);
int32_t
mndCreateOffset
s
(
STrans
*
pTrans
,
const
char
*
cgroup
,
const
char
*
topicName
,
const
SArray
*
vgs
);
static
FORCE_INLINE
int32_t
mndMakePartitionKey
(
char
*
key
,
const
char
*
cgroup
,
const
char
*
topicName
,
int32_t
vgId
)
{
return
snprintf
(
key
,
TSDB_PARTITION_KEY_LEN
,
"%d:%s:%s"
,
vgId
,
cgroup
,
topicName
);
...
...
source/dnode/mnode/impl/inc/mndSubscribe.h
浏览文件 @
d4734eb1
...
...
@@ -26,9 +26,11 @@ int32_t mndInitSubscribe(SMnode *pMnode);
void
mndCleanupSubscribe
(
SMnode
*
pMnode
);
SMqSubscribeObj
*
mndAcquireSubscribe
(
SMnode
*
pMnode
,
const
char
*
CGroup
,
const
char
*
topicName
);
SMqSubscribeObj
*
mndAcquireSubscribeByKey
(
SMnode
*
pMnode
,
const
char
*
key
);
SMqSubscribeObj
*
mndAcquireSubscribeByKey
(
SMnode
*
pMnode
,
const
char
*
key
);
void
mndReleaseSubscribe
(
SMnode
*
pMnode
,
SMqSubscribeObj
*
pSub
);
int32_t
mndMakeSubscribeKey
(
char
*
key
,
const
char
*
cgroup
,
const
char
*
topicName
);
#ifdef __cplusplus
}
#endif
...
...
source/dnode/mnode/impl/src/mndConsumer.c
浏览文件 @
d4734eb1
此差异已折叠。
点击以展开。
source/dnode/mnode/impl/src/mndDef.c
浏览文件 @
d4734eb1
...
...
@@ -14,6 +14,403 @@
*/
#include "mndDef.h"
#include "mndConsumer.h"
SMqConsumerObj
*
tNewSMqConsumerObj
(
int64_t
consumerId
,
char
cgroup
[
TSDB_CGROUP_LEN
])
{
SMqConsumerObj
*
pConsumer
=
taosMemoryCalloc
(
1
,
sizeof
(
SMqConsumerObj
));
if
(
pConsumer
==
NULL
)
{
return
NULL
;
}
pConsumer
->
consumerId
=
consumerId
;
memcpy
(
pConsumer
->
cgroup
,
cgroup
,
TSDB_CGROUP_LEN
);
pConsumer
->
epoch
=
0
;
pConsumer
->
status
=
MQ_CONSUMER_STATUS__MODIFY
;
pConsumer
->
hbStatus
=
0
;
taosInitRWLatch
(
&
pConsumer
->
lock
);
pConsumer
->
currentTopics
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
#if 0
pConsumer->waitingRebTopics = NULL;
#endif
pConsumer
->
rebNewTopics
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
pConsumer
->
rebRemovedTopics
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
if
(
pConsumer
->
currentTopics
==
NULL
||
pConsumer
->
rebNewTopics
==
NULL
||
pConsumer
->
rebRemovedTopics
==
NULL
)
{
taosArrayDestroy
(
pConsumer
->
currentTopics
);
taosArrayDestroy
(
pConsumer
->
rebNewTopics
);
taosArrayDestroy
(
pConsumer
->
rebRemovedTopics
);
taosMemoryFree
(
pConsumer
);
return
NULL
;
}
return
pConsumer
;
}
void
tDeleteSMqConsumerObj
(
SMqConsumerObj
*
pConsumer
)
{
if
(
pConsumer
->
currentTopics
)
{
taosArrayDestroyP
(
pConsumer
->
currentTopics
,
(
FDelete
)
taosMemoryFree
);
}
#if 0
if (pConsumer->waitingRebTopics) {
taosArrayDestroyP(pConsumer->waitingRebTopics, taosMemoryFree);
}
#endif
if
(
pConsumer
->
rebNewTopics
)
{
taosArrayDestroyP
(
pConsumer
->
rebNewTopics
,
(
FDelete
)
taosMemoryFree
);
}
if
(
pConsumer
->
rebRemovedTopics
)
{
taosArrayDestroyP
(
pConsumer
->
rebRemovedTopics
,
(
FDelete
)
taosMemoryFree
);
}
}
int32_t
tEncodeSMqConsumerObj
(
void
**
buf
,
const
SMqConsumerObj
*
pConsumer
)
{
int32_t
tlen
=
0
;
int32_t
sz
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumer
->
consumerId
);
tlen
+=
taosEncodeString
(
buf
,
pConsumer
->
cgroup
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pConsumer
->
updateType
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pConsumer
->
epoch
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pConsumer
->
status
);
// current topics
if
(
pConsumer
->
currentTopics
)
{
sz
=
taosArrayGetSize
(
pConsumer
->
currentTopics
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
=
taosArrayGetP
(
pConsumer
->
currentTopics
,
i
);
tlen
+=
taosEncodeString
(
buf
,
topic
);
}
}
else
{
tlen
+=
taosEncodeFixedI32
(
buf
,
0
);
}
#if 0
// waiting reb topics
if (pConsumer->waitingRebTopics) {
sz = taosArrayGetSize(pConsumer->waitingRebTopics);
tlen += taosEncodeFixedI32(buf, sz);
for (int32_t i = 0; i < sz; i++) {
char *topic = taosArrayGetP(pConsumer->waitingRebTopics, i);
tlen += taosEncodeString(buf, topic);
}
} else {
tlen += taosEncodeFixedI32(buf, 0);
}
#endif
// reb new topics
if
(
pConsumer
->
rebNewTopics
)
{
sz
=
taosArrayGetSize
(
pConsumer
->
rebNewTopics
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
=
taosArrayGetP
(
pConsumer
->
rebNewTopics
,
i
);
tlen
+=
taosEncodeString
(
buf
,
topic
);
}
}
else
{
tlen
+=
taosEncodeFixedI32
(
buf
,
0
);
}
// reb removed topics
if
(
pConsumer
->
rebRemovedTopics
)
{
sz
=
taosArrayGetSize
(
pConsumer
->
rebRemovedTopics
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
=
taosArrayGetP
(
pConsumer
->
rebRemovedTopics
,
i
);
tlen
+=
taosEncodeString
(
buf
,
topic
);
}
}
else
{
tlen
+=
taosEncodeFixedI32
(
buf
,
0
);
}
return
tlen
;
}
void
*
tDecodeSMqConsumerObj
(
const
void
*
buf
,
SMqConsumerObj
*
pConsumer
)
{
int32_t
sz
;
buf
=
taosDecodeFixedI64
(
buf
,
&
pConsumer
->
consumerId
);
buf
=
taosDecodeStringTo
(
buf
,
pConsumer
->
cgroup
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pConsumer
->
updateType
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pConsumer
->
epoch
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pConsumer
->
status
);
// current topics
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pConsumer
->
currentTopics
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
;
buf
=
taosDecodeString
(
buf
,
&
topic
);
taosArrayPush
(
pConsumer
->
currentTopics
,
&
topic
);
}
#if 0
// waiting reb topics
buf = taosDecodeFixedI32(buf, &sz);
pConsumer->waitingRebTopics = taosArrayInit(sz, sizeof(void *));
for (int32_t i = 0; i < sz; i++) {
char *topic;
buf = taosDecodeString(buf, &topic);
taosArrayPush(pConsumer->waitingRebTopics, &topic);
}
#endif
// reb new topics
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pConsumer
->
rebNewTopics
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
;
buf
=
taosDecodeString
(
buf
,
&
topic
);
taosArrayPush
(
pConsumer
->
rebNewTopics
,
&
topic
);
}
// reb removed topics
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pConsumer
->
rebRemovedTopics
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topic
;
buf
=
taosDecodeString
(
buf
,
&
topic
);
taosArrayPush
(
pConsumer
->
rebRemovedTopics
,
&
topic
);
}
return
(
void
*
)
buf
;
}
SMqVgEp
*
tCloneSMqVgEp
(
const
SMqVgEp
*
pVgEp
)
{
SMqVgEp
*
pVgEpNew
=
taosMemoryMalloc
(
sizeof
(
SMqVgEp
));
if
(
pVgEpNew
==
NULL
)
return
NULL
;
pVgEpNew
->
vgId
=
pVgEp
->
vgId
;
pVgEpNew
->
qmsg
=
strdup
(
pVgEp
->
qmsg
);
/*memcpy(pVgEpNew->topic, pVgEp->topic, TSDB_TOPIC_FNAME_LEN);*/
pVgEpNew
->
epSet
=
pVgEp
->
epSet
;
return
pVgEpNew
;
}
void
tDeleteSMqVgEp
(
SMqVgEp
*
pVgEp
)
{
taosMemoryFree
(
pVgEp
->
qmsg
);
}
int32_t
tEncodeSMqVgEp
(
void
**
buf
,
const
SMqVgEp
*
pVgEp
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI32
(
buf
,
pVgEp
->
vgId
);
tlen
+=
taosEncodeString
(
buf
,
pVgEp
->
qmsg
);
/*tlen += taosEncodeString(buf, pVgEp->topic);*/
tlen
+=
taosEncodeSEpSet
(
buf
,
&
pVgEp
->
epSet
);
return
tlen
;
}
void
*
tDecodeSMqVgEp
(
const
void
*
buf
,
SMqVgEp
*
pVgEp
)
{
buf
=
taosDecodeFixedI32
(
buf
,
&
pVgEp
->
vgId
);
buf
=
taosDecodeString
(
buf
,
&
pVgEp
->
qmsg
);
/*buf = taosDecodeStringTo(buf, pVgEp->topic);*/
buf
=
taosDecodeSEpSet
(
buf
,
&
pVgEp
->
epSet
);
return
(
void
*
)
buf
;
}
SMqConsumerEpObj
*
tCloneSMqConsumerEpObj
(
const
SMqConsumerEpObj
*
pConsumerEp
)
{
SMqConsumerEpObj
*
pConsumerEpNew
=
taosMemoryMalloc
(
sizeof
(
SMqConsumerEpObj
));
if
(
pConsumerEpNew
==
NULL
)
return
NULL
;
pConsumerEpNew
->
consumerId
=
pConsumerEp
->
consumerId
;
memcpy
(
pConsumerEpNew
->
cgroup
,
pConsumerEp
->
cgroup
,
TSDB_CGROUP_LEN
);
taosInitRWLatch
(
&
pConsumerEpNew
->
lock
);
pConsumerEpNew
->
vgs
=
taosArrayDeepCopy
(
pConsumerEpNew
->
vgs
,
(
FCopy
)
tCloneSMqVgEp
);
return
pConsumerEpNew
;
}
void
tDeleteSMqConsumerEpObj
(
SMqConsumerEpObj
*
pConsumerEp
)
{
taosArrayDestroyEx
(
pConsumerEp
->
vgs
,
(
FDelete
)
tDeleteSMqVgEp
);
}
int32_t
tEncodeSMqConsumerEpObj
(
void
**
buf
,
const
SMqConsumerEpObj
*
pConsumerEp
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumerEp
->
consumerId
);
tlen
+=
taosEncodeString
(
buf
,
pConsumerEp
->
cgroup
);
tlen
+=
taosEncodeArray
(
buf
,
pConsumerEp
->
vgs
,
(
FEncode
)
tEncodeSMqVgEp
);
return
tlen
;
}
void
*
tDecodeSMqConsumerEpObj
(
const
void
*
buf
,
SMqConsumerEpObj
*
pConsumerEp
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
pConsumerEp
->
consumerId
);
buf
=
taosDecodeStringTo
(
buf
,
pConsumerEp
->
cgroup
);
buf
=
taosDecodeArray
(
buf
,
&
pConsumerEp
->
vgs
,
(
FDecode
)
tDecodeSMqVgEp
,
sizeof
(
SMqSubVgEp
));
return
(
void
*
)
buf
;
}
SMqConsumerEpInSub
*
tCloneSMqConsumerEpInSub
(
const
SMqConsumerEpInSub
*
pEpInSub
)
{
SMqConsumerEpInSub
*
pEpInSubNew
=
taosMemoryMalloc
(
sizeof
(
SMqConsumerEpInSub
));
if
(
pEpInSubNew
==
NULL
)
return
NULL
;
pEpInSubNew
->
consumerId
=
pEpInSub
->
consumerId
;
pEpInSubNew
->
vgs
=
taosArrayDeepCopy
(
pEpInSub
->
vgs
,
(
FCopy
)
tCloneSMqVgEp
);
return
pEpInSubNew
;
}
void
tDeleteSMqConsumerEpInSub
(
SMqConsumerEpInSub
*
pEpInSub
)
{
taosArrayDestroyEx
(
pEpInSub
->
vgs
,
(
FDelete
)
tDeleteSMqVgEp
);
}
int32_t
tEncodeSMqConsumerEpInSub
(
void
**
buf
,
const
SMqConsumerEpInSub
*
pEpInSub
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pEpInSub
->
consumerId
);
int32_t
sz
=
taosArrayGetSize
(
pEpInSub
->
vgs
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqVgEp
*
pVgEp
=
taosArrayGetP
(
pEpInSub
->
vgs
,
i
);
tlen
+=
tEncodeSMqVgEp
(
buf
,
pVgEp
);
}
/*tlen += taosEncodeArray(buf, pEpInSub->vgs, (FEncode)tEncodeSMqVgEp);*/
return
tlen
;
}
void
*
tDecodeSMqConsumerEpInSub
(
const
void
*
buf
,
SMqConsumerEpInSub
*
pEpInSub
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
pEpInSub
->
consumerId
);
/*buf = taosDecodeArray(buf, &pEpInSub->vgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqSubVgEp));*/
int32_t
sz
;
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pEpInSub
->
vgs
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqVgEp
*
pVgEp
=
taosMemoryMalloc
(
sizeof
(
SMqVgEp
));
buf
=
tDecodeSMqVgEp
(
buf
,
pVgEp
);
taosArrayPush
(
pEpInSub
->
vgs
,
&
pVgEp
);
}
return
(
void
*
)
buf
;
}
SMqSubscribeObj
*
tNewSubscribeObj
(
const
char
key
[
TSDB_SUBSCRIBE_KEY_LEN
])
{
SMqSubscribeObj
*
pSubNew
=
taosMemoryMalloc
(
sizeof
(
SMqSubscribeObj
));
if
(
pSubNew
==
NULL
)
return
NULL
;
memcpy
(
pSubNew
->
key
,
key
,
TSDB_SUBSCRIBE_KEY_LEN
);
taosInitRWLatch
(
&
pSubNew
->
lock
);
pSubNew
->
vgNum
=
-
1
;
pSubNew
->
consumerHash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
// TODO set free fp
SMqConsumerEpInSub
epInSub
=
{
.
consumerId
=
-
1
,
.
vgs
=
taosArrayInit
(
0
,
sizeof
(
void
*
)),
};
int64_t
unexistKey
=
-
1
;
taosHashPut
(
pSubNew
->
consumerHash
,
&
unexistKey
,
sizeof
(
int64_t
),
&
epInSub
,
sizeof
(
SMqConsumerEpInSub
));
return
pSubNew
;
}
SMqSubscribeObj
*
tCloneSubscribeObj
(
const
SMqSubscribeObj
*
pSub
)
{
SMqSubscribeObj
*
pSubNew
=
taosMemoryMalloc
(
sizeof
(
SMqSubscribeObj
));
if
(
pSubNew
==
NULL
)
return
NULL
;
memcpy
(
pSubNew
->
key
,
pSub
->
key
,
TSDB_SUBSCRIBE_KEY_LEN
);
taosInitRWLatch
(
&
pSubNew
->
lock
);
pSubNew
->
vgNum
=
pSub
->
vgNum
;
/*pSubNew->consumerEps = taosArrayDeepCopy(pSub->consumerEps, (FCopy)tCloneSMqConsumerEpInSub);*/
pSubNew
->
consumerHash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
/*taosHashSetFreeFp(pSubNew->consumerHash, taosArrayDestroy);*/
void
*
pIter
=
NULL
;
SMqConsumerEpInSub
*
pEpInSub
=
NULL
;
while
(
1
)
{
pIter
=
taosHashIterate
(
pSub
->
consumerHash
,
pIter
);
if
(
pIter
==
NULL
)
break
;
pEpInSub
=
(
SMqConsumerEpInSub
*
)
pIter
;
SMqConsumerEpInSub
newEp
=
{
.
consumerId
=
pEpInSub
->
consumerId
,
.
vgs
=
taosArrayDeepCopy
(
pEpInSub
->
vgs
,
(
FCopy
)
tCloneSMqVgEp
),
};
taosHashPut
(
pSubNew
->
consumerHash
,
&
newEp
.
consumerId
,
sizeof
(
int64_t
),
&
newEp
,
sizeof
(
SMqConsumerEpInSub
));
}
return
pSubNew
;
}
void
tDeleteSubscribeObj
(
SMqSubscribeObj
*
pSub
)
{
/*taosArrayDestroyEx(pSub->consumerEps, (FDelete)tDeleteSMqConsumerEpInSub);*/
taosHashCleanup
(
pSub
->
consumerHash
);
}
int32_t
tEncodeSubscribeObj
(
void
**
buf
,
const
SMqSubscribeObj
*
pSub
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeString
(
buf
,
pSub
->
key
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pSub
->
vgNum
);
void
*
pIter
=
NULL
;
int32_t
sz
=
taosHashGetSize
(
pSub
->
consumerHash
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
int32_t
cnt
=
0
;
while
(
1
)
{
pIter
=
taosHashIterate
(
pSub
->
consumerHash
,
pIter
);
if
(
pIter
==
NULL
)
break
;
SMqConsumerEpInSub
*
pEpInSub
=
(
SMqConsumerEpInSub
*
)
pIter
;
tlen
+=
tEncodeSMqConsumerEpInSub
(
buf
,
pEpInSub
);
cnt
++
;
}
ASSERT
(
cnt
==
sz
);
/*tlen += taosEncodeArray(buf, pSub->consumerEps, (FEncode)tEncodeSMqConsumerEpInSub);*/
return
tlen
;
}
void
*
tDecodeSubscribeObj
(
const
void
*
buf
,
SMqSubscribeObj
*
pSub
)
{
//
buf
=
taosDecodeStringTo
(
buf
,
pSub
->
key
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pSub
->
vgNum
);
int32_t
sz
;
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pSub
->
consumerHash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
HASH_NO_LOCK
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
/*SMqConsumerEpInSub* pEpInSub = taosMemoryMalloc(sizeof(SMqConsumerEpInSub));*/
SMqConsumerEpInSub
epInSub
=
{
0
};
buf
=
tDecodeSMqConsumerEpInSub
(
buf
,
&
epInSub
);
taosHashPut
(
pSub
->
consumerHash
,
&
epInSub
.
consumerId
,
sizeof
(
int64_t
),
&
epInSub
,
sizeof
(
SMqConsumerEpInSub
));
}
/*buf = taosDecodeArray(buf, &pSub->consumerEps, (FDecode)tDecodeSMqConsumerEpInSub, sizeof(SMqConsumerEpInSub));*/
return
(
void
*
)
buf
;
}
SMqSubActionLogEntry
*
tCloneSMqSubActionLogEntry
(
SMqSubActionLogEntry
*
pEntry
)
{
SMqSubActionLogEntry
*
pEntryNew
=
taosMemoryMalloc
(
sizeof
(
SMqSubActionLogEntry
));
if
(
pEntryNew
==
NULL
)
return
NULL
;
pEntryNew
->
epoch
=
pEntry
->
epoch
;
pEntryNew
->
consumers
=
taosArrayDeepCopy
(
pEntry
->
consumers
,
(
FCopy
)
tCloneSMqConsumerEpInSub
);
return
pEntryNew
;
}
void
tDeleteSMqSubActionLogEntry
(
SMqSubActionLogEntry
*
pEntry
)
{
taosArrayDestroyEx
(
pEntry
->
consumers
,
(
FDelete
)
tDeleteSMqConsumerEpInSub
);
}
int32_t
tEncodeSMqSubActionLogEntry
(
void
**
buf
,
const
SMqSubActionLogEntry
*
pEntry
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI32
(
buf
,
pEntry
->
epoch
);
tlen
+=
taosEncodeArray
(
buf
,
pEntry
->
consumers
,
(
FEncode
)
tEncodeSMqSubActionLogEntry
);
return
tlen
;
}
void
*
tDecodeSMqSubActionLogEntry
(
const
void
*
buf
,
SMqSubActionLogEntry
*
pEntry
)
{
buf
=
taosDecodeFixedI32
(
buf
,
&
pEntry
->
epoch
);
buf
=
taosDecodeArray
(
buf
,
&
pEntry
->
consumers
,
(
FDecode
)
tDecodeSMqSubActionLogEntry
,
sizeof
(
SMqSubActionLogEntry
));
return
(
void
*
)
buf
;
}
SMqSubActionLogObj
*
tCloneSMqSubActionLogObj
(
SMqSubActionLogObj
*
pLog
)
{
SMqSubActionLogObj
*
pLogNew
=
taosMemoryMalloc
(
sizeof
(
SMqSubActionLogObj
));
if
(
pLogNew
==
NULL
)
return
pLogNew
;
memcpy
(
pLogNew
->
key
,
pLog
->
key
,
TSDB_SUBSCRIBE_KEY_LEN
);
pLogNew
->
logs
=
taosArrayDeepCopy
(
pLog
->
logs
,
(
FCopy
)
tCloneSMqConsumerEpInSub
);
return
pLogNew
;
}
void
tDeleteSMqSubActionLogObj
(
SMqSubActionLogObj
*
pLog
)
{
taosArrayDestroyEx
(
pLog
->
logs
,
(
FDelete
)
tDeleteSMqConsumerEpInSub
);
}
int32_t
tEncodeSMqSubActionLogObj
(
void
**
buf
,
const
SMqSubActionLogObj
*
pLog
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeString
(
buf
,
pLog
->
key
);
tlen
+=
taosEncodeArray
(
buf
,
pLog
->
logs
,
(
FEncode
)
tEncodeSMqSubActionLogEntry
);
return
tlen
;
}
void
*
tDecodeSMqSubActionLogObj
(
const
void
*
buf
,
SMqSubActionLogObj
*
pLog
)
{
buf
=
taosDecodeStringTo
(
buf
,
pLog
->
key
);
buf
=
taosDecodeArray
(
buf
,
&
pLog
->
logs
,
(
FDecode
)
tDecodeSMqSubActionLogEntry
,
sizeof
(
SMqSubActionLogEntry
));
return
(
void
*
)
buf
;
}
int32_t
tEncodeSStreamObj
(
SCoder
*
pEncoder
,
const
SStreamObj
*
pObj
)
{
int32_t
sz
=
0
;
...
...
source/dnode/mnode/impl/src/mndOffset.c
浏览文件 @
d4734eb1
...
...
@@ -130,8 +130,7 @@ OFFSET_DECODE_OVER:
return
pRow
;
}
int32_t
mndCreateOffset
(
STrans
*
pTrans
,
const
char
*
cgroup
,
const
char
*
topicName
,
const
SArray
*
vgs
)
{
int32_t
code
=
0
;
int32_t
mndCreateOffsets
(
STrans
*
pTrans
,
const
char
*
cgroup
,
const
char
*
topicName
,
const
SArray
*
vgs
)
{
int32_t
sz
=
taosArrayGetSize
(
vgs
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqConsumerEp
*
pConsumerEp
=
taosArrayGet
(
vgs
,
i
);
...
...
@@ -170,13 +169,22 @@ static int32_t mndProcessCommitOffsetReq(SNodeMsg *pMsg) {
if
(
mndMakePartitionKey
(
key
,
pOffset
->
cgroup
,
pOffset
->
topicName
,
pOffset
->
vgId
)
<
0
)
{
return
-
1
;
}
bool
create
=
false
;
SMqOffsetObj
*
pOffsetObj
=
mndAcquireOffset
(
pMnode
,
key
);
ASSERT
(
pOffsetObj
);
if
(
pOffsetObj
==
NULL
)
{
pOffsetObj
=
taosMemoryMalloc
(
sizeof
(
SMqOffset
));
memcpy
(
pOffsetObj
->
key
,
key
,
TSDB_PARTITION_KEY_LEN
);
create
=
true
;
}
pOffsetObj
->
offset
=
pOffset
->
offset
;
SSdbRaw
*
pOffsetRaw
=
mndOffsetActionEncode
(
pOffsetObj
);
sdbSetRawStatus
(
pOffsetRaw
,
SDB_STATUS_READY
);
mndTransAppendRedolog
(
pTrans
,
pOffsetRaw
);
mndReleaseOffset
(
pMnode
,
pOffsetObj
);
if
(
create
)
{
taosMemoryFree
(
pOffsetObj
);
}
else
{
mndReleaseOffset
(
pMnode
,
pOffsetObj
);
}
}
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
...
...
@@ -201,7 +209,7 @@ static int32_t mndOffsetActionDelete(SSdb *pSdb, SMqOffsetObj *pOffset) {
static
int32_t
mndOffsetActionUpdate
(
SSdb
*
pSdb
,
SMqOffsetObj
*
pOldOffset
,
SMqOffsetObj
*
pNewOffset
)
{
mTrace
(
"offset:%s, perform update action"
,
pOldOffset
->
key
);
pOldOffset
->
offset
=
pNewOffset
->
offset
;
atomic_store_64
(
&
pOldOffset
->
offset
,
pNewOffset
->
offset
)
;
return
0
;
}
...
...
source/dnode/mnode/impl/src/mndScheduler.c
浏览文件 @
d4734eb1
...
...
@@ -434,7 +434,9 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
return
-
1
;
}
ASSERT
(
pSub
->
vgNum
==
0
);
ASSERT
(
pSub
->
vgNum
==
-
1
);
pSub
->
vgNum
=
0
;
int32_t
levelNum
=
LIST_LENGTH
(
pPlan
->
pSubplans
);
if
(
levelNum
!=
1
)
{
...
...
@@ -453,6 +455,12 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
}
SSubplan
*
plan
=
nodesListGetNode
(
inner
->
pNodeList
,
0
);
int64_t
unexistKey
=
-
1
;
SMqConsumerEpInSub
*
pEpInSub
=
taosHashGet
(
pSub
->
consumerHash
,
&
unexistKey
,
sizeof
(
int64_t
));
ASSERT
(
pEpInSub
);
ASSERT
(
taosHashGetSize
(
pSub
->
consumerHash
)
==
1
);
void
*
pIter
=
NULL
;
while
(
1
)
{
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pIter
,
(
void
**
)
&
pVgroup
);
...
...
@@ -466,24 +474,41 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib
plan
->
execNode
.
nodeId
=
pVgroup
->
vgId
;
plan
->
execNode
.
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
SMqVgEp
*
pVgEp
=
taosMemoryMalloc
(
sizeof
(
SMqVgEp
));
pVgEp
->
epSet
=
plan
->
execNode
.
epSet
;
pVgEp
->
vgId
=
plan
->
execNode
.
nodeId
;
#if 0
SMqConsumerEp consumerEp = {0};
consumerEp.status = 0;
consumerEp.consumerId = -1;
consumerEp.epSet = plan->execNode.epSet;
consumerEp.vgId = plan->execNode.nodeId;
mDebug
(
"init subscribption %s, assign vg: %d"
,
pSub
->
key
,
consumerEp
.
vgId
);
#endif
mDebug
(
"init subscribption %s, assign vg: %d"
,
pSub
->
key
,
pVgEp
->
vgId
);
int32_t
msgLen
;
if
(
qSubPlanToString
(
plan
,
&
consumerEp
.
qmsg
,
&
msgLen
)
<
0
)
{
if
(
qSubPlanToString
(
plan
,
&
pVgEp
->
qmsg
,
&
msgLen
)
<
0
)
{
sdbRelease
(
pSdb
,
pVgroup
);
qDestroyQueryPlan
(
pPlan
);
terrno
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
-
1
;
}
taosArrayPush
(
pSub
->
unassignedVg
,
&
consumerEp
);
taosArrayPush
(
pEpInSub
->
vgs
,
&
pVgEp
);
ASSERT
(
taosHashGetSize
(
pSub
->
consumerHash
)
==
1
);
/*taosArrayPush(pSub->unassignedVg, &consumerEp);*/
}
ASSERT
(
pEpInSub
->
vgs
->
size
>
0
);
pEpInSub
=
taosHashGet
(
pSub
->
consumerHash
,
&
unexistKey
,
sizeof
(
int64_t
));
ASSERT
(
pEpInSub
->
vgs
->
size
>
0
);
ASSERT
(
taosHashGetSize
(
pSub
->
consumerHash
)
==
1
);
qDestroyQueryPlan
(
pPlan
);
return
0
;
...
...
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
d4734eb1
...
...
@@ -348,7 +348,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
memcpy
(
pOld
->
pColumns
,
pNew
->
pColumns
,
pOld
->
numOfColumns
*
sizeof
(
SSchema
));
memcpy
(
pOld
->
pTags
,
pNew
->
pTags
,
pOld
->
numOfTags
*
sizeof
(
SSchema
));
if
(
pNew
->
commentLen
!=
0
)
{
memcpy
(
pOld
->
comment
,
pNew
->
comment
,
TSDB_STB_COMMENT_LEN
);
memcpy
(
pOld
->
comment
,
pNew
->
comment
,
pNew
->
commentLen
);
}
if
(
pNew
->
ast1Len
!=
0
)
{
memcpy
(
pOld
->
pAst1
,
pNew
->
pAst1
,
pNew
->
ast1Len
);
...
...
source/dnode/mnode/impl/src/mndSubscribe.c
浏览文件 @
d4734eb1
此差异已折叠。
点击以展开。
source/dnode/mnode/impl/src/mnode.c
浏览文件 @
d4734eb1
...
...
@@ -22,12 +22,14 @@
#include "mndDb.h"
#include "mndDnode.h"
#include "mndFunc.h"
#include "mndGrant.h"
#include "mndInfoSchema.h"
#include "mndPerfSchema.h"
#include "mndMnode.h"
#include "mndOffset.h"
#include "mndPerfSchema.h"
#include "mndProfile.h"
#include "mndQnode.h"
#include "mndQuery.h"
#include "mndShow.h"
#include "mndSma.h"
#include "mndSnode.h"
...
...
@@ -40,8 +42,6 @@
#include "mndTrans.h"
#include "mndUser.h"
#include "mndVgroup.h"
#include "mndQuery.h"
#include "mndGrant.h"
#define MQ_TIMER_MS 3000
#define TRNAS_TIMER_MS 6000
...
...
source/dnode/vnode/src/inc/tq.h
浏览文件 @
d4734eb1
...
...
@@ -16,6 +16,13 @@
#ifndef _TD_VNODE_TQ_H_
#define _TD_VNODE_TQ_H_
#include "executor.h"
#include "os.h"
#include "thash.h"
#include "tmsg.h"
#include "ttimer.h"
#include "wal.h"
#ifdef __cplusplus
extern
"C"
{
#endif
...
...
@@ -30,12 +37,6 @@ extern "C" {
#define tqTrace(...) do { if (tqDebugFlag & DEBUG_TRACE) { taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); }} while(0)
// clang-format on
enum
{
TQ_STREAM_TOKEN__DATA
=
1
,
TQ_STREAM_TOKEN__WATERMARK
,
TQ_STREAM_TOKEN__CHECKPOINT
,
};
#define TQ_BUFFER_SIZE 4
#define TQ_BUCKET_MASK 0xFF
...
...
@@ -151,22 +152,27 @@ typedef struct {
}
STqMetaStore
;
typedef
struct
{
SMemAllocatorFactory
*
pAllocatorFactory
;
SMemAllocator
*
pAllocator
;
}
STqMemRef
;
char
subKey
[
TSDB_SUBSCRIBE_KEY_LEN
];
int64_t
consumerId
;
int32_t
epoch
;
char
*
qmsg
;
// SRWLatch lock;
SWalReadHandle
*
pReadHandle
;
// number should be identical to fetch thread num
qTaskInfo_t
task
[
4
];
}
STqExec
;
struct
STQ
{
// the collection of groups
// the handle of meta kvstore
bool
writeTrigger
;
char
*
path
;
STqMemRef
tqMemRef
;
STqMetaStore
*
tqMeta
;
// STqPushMgr* tqPushMgr;
SHashObj
*
pStreamTasks
;
SVnode
*
pVnode
;
SWal
*
pWal
;
SMeta
*
pVnodeMeta
;
SHashObj
*
tqMetaNew
;
// subKey -> tqExec
SHashObj
*
pStreamTasks
;
SVnode
*
pVnode
;
SWal
*
pWal
;
SMeta
*
pVnodeMeta
;
};
typedef
struct
{
...
...
@@ -230,10 +236,6 @@ typedef struct {
// TODO sync function
}
STqStreamPusher
;
typedef
struct
{
int8_t
type
;
// mq or stream
}
STqPusher
;
typedef
struct
{
SHashObj
*
pHash
;
// <id, STqPush*>
}
STqPushMgr
;
...
...
@@ -257,9 +259,10 @@ int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t version);
int
tqCommit
(
STQ
*
);
int32_t
tqProcessPollReq
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
,
int32_t
workerId
);
int32_t
tqProcessSetConnReq
(
STQ
*
pTq
,
char
*
msg
);
int32_t
tqProcessRebReq
(
STQ
*
pTq
,
char
*
msg
);
int32_t
tqProcessCancelConnReq
(
STQ
*
pTq
,
char
*
msg
);
int32_t
tqProcessVgChangeReq
(
STQ
*
pTq
,
char
*
msg
,
int32_t
msgLen
);
// int32_t tqProcessSetConnReq(STQ* pTq, char* msg);
// int32_t tqProcessRebReq(STQ* pTq, char* msg);
// int32_t tqProcessCancelConnReq(STQ* pTq, char* msg);
int32_t
tqProcessTaskExec
(
STQ
*
pTq
,
char
*
msg
,
int32_t
msgLen
,
int32_t
workerId
);
int32_t
tqProcessTaskDeploy
(
STQ
*
pTq
,
char
*
msg
,
int32_t
msgLen
);
int32_t
tqProcessStreamTrigger
(
STQ
*
pTq
,
void
*
data
,
int32_t
dataLen
,
int32_t
workerId
);
...
...
@@ -314,4 +317,4 @@ STqStreamPusher* tqAddStreamPusher(STqPushMgr* pushMgr, int64_t streamId, SEpSet
}
#endif
#endif
/*_TD_VNODE_TQ_H_*/
\ No newline at end of file
#endif
/*_TD_VNODE_TQ_H_*/
source/dnode/vnode/src/tq/tq.c
浏览文件 @
d4734eb1
...
...
@@ -29,31 +29,14 @@ STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pVnodeMeta, SMe
pTq
->
pVnode
=
pVnode
;
pTq
->
pWal
=
pWal
;
pTq
->
pVnodeMeta
=
pVnodeMeta
;
#if 0
pTq->tqMemRef.pAllocatorFactory = allocFac;
pTq->tqMemRef.pAllocator = allocFac->create(allocFac);
if (pTq->tqMemRef.pAllocator == NULL) {
// TODO: error code of buffer pool
}
#endif
pTq
->
tqMeta
=
tqStoreOpen
(
pTq
,
path
,
(
FTqSerialize
)
tqSerializeConsumer
,
(
FTqDeserialize
)
tqDeserializeConsumer
,
(
FTqDelete
)
taosMemoryFree
,
0
);
if
(
pTq
->
tqMeta
==
NULL
)
{
taosMemoryFree
(
pTq
);
#if 0
allocFac->destroy(allocFac, pTq->tqMemRef.pAllocator);
#endif
return
NULL
;
}
#if 0
pTq->tqPushMgr = tqPushMgrOpen();
if (pTq->tqPushMgr == NULL) {
// free store
taosMemoryFree(pTq);
return NULL;
}
#endif
pTq
->
tqMetaNew
=
taosHashInit
(
64
,
MurmurHash3_32
,
true
,
HASH_ENTRY_LOCK
);
pTq
->
pStreamTasks
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_NO_LOCK
);
...
...
@@ -248,16 +231,15 @@ int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsu
return
0
;
}
#if 0
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;
SMqPollReqV2
*
pReq
=
pMsg
->
pCont
;
int64_t
consumerId
=
pReq
->
consumerId
;
int32_t
reqEpoch
=
pReq
->
epoch
;
int64_t
fetchOffset
;
if
(
pReq
->
currentOffset
==
TMQ_CONF__RESET_OFFSET__EARLIEAST
)
{
fetchOffset =
0
;
fetchOffset
=
walGetFirstVer
(
pTq
->
pWal
)
;
}
else
if
(
pReq
->
currentOffset
==
TMQ_CONF__RESET_OFFSET__LATEST
)
{
fetchOffset
=
walGetLastVer
(
pTq
->
pWal
);
}
else
{
...
...
@@ -267,65 +249,29 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
vDebug
(
"tmq poll: consumer %ld (epoch %d) recv poll req in vg %d, req %ld %ld"
,
consumerId
,
pReq
->
epoch
,
TD_VID
(
pTq
->
pVnode
),
pReq
->
currentOffset
,
fetchOffset
);
SMqPollRsp rsp = {
/*.consumerId = consumerId,*/
.numOfTopics = 0,
.pBlockData = NULL,
};
STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, consumerId);
if (pConsumer == NULL) {
vWarn("tmq poll: consumer %ld (epoch %d) not found in vg %d", consumerId, pReq->epoch, TD_VID(pTq->pVnode));
pMsg->pCont = NULL;
pMsg->contLen = 0;
pMsg->code = -1;
tmsgSendRsp(pMsg);
return 0;
}
STqExec
*
pExec
=
taosHashGet
(
pTq
->
tqMetaNew
,
pReq
->
subKey
,
strlen
(
pReq
->
subKey
));
ASSERT
(
pExec
);
int32_t consumerEpoch = atomic_load_32(&p
Consumer
->epoch);
int32_t
consumerEpoch
=
atomic_load_32
(
&
p
Exec
->
epoch
);
while
(
consumerEpoch
<
reqEpoch
)
{
consumerEpoch = atomic_val_compare_exchange_32(&p
Consumer
->epoch, consumerEpoch, reqEpoch);
consumerEpoch
=
atomic_val_compare_exchange_32
(
&
p
Exec
->
epoch
,
consumerEpoch
,
reqEpoch
);
}
STqTopic* pTopic = NULL;
int32_t sz = taosArrayGetSize(pConsumer->topics);
for (int32_t i = 0; i < sz; 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,
TD_VID(pTq->pVnode));
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,
TD_VID(pTq->pVnode));
SMqDataBlkRsp
rsp
=
{
0
};
rsp
.
reqOffset
=
pReq
->
currentOffset
;
rsp.skipLogNum = 0;
rsp
.
blockDataLen
=
taosArrayInit
(
0
,
sizeof
(
int32_t
));
rsp
.
blockData
=
taosArrayInit
(
0
,
sizeof
(
void
*
));
while
(
1
)
{
/*if (fetchOffset > walGetLastVer(pTq->pWal) || walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {*/
// TODO
consumerEpoch = atomic_load_32(&pConsumer->epoch);
consumerEpoch
=
atomic_load_32
(
&
pExec
->
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
,
TD_VID
(
pTq
->
pVnode
),
fetchOffset
,
consumerEpoch
,
reqEpoch
);
break
;
}
SWalReadHead
*
pHead
;
if (walReadWithHandle_s(p
Topic->pReadh
andle, fetchOffset, &pHead) < 0) {
if
(
walReadWithHandle_s
(
p
Exec
->
pReadH
andle
,
fetchOffset
,
&
pHead
)
<
0
)
{
// TODO: no more log, set timer to wait blocking time
// if data inserted during waiting, launch query and
// response to user
...
...
@@ -333,101 +279,88 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
TD_VID
(
pTq
->
pVnode
),
fetchOffset
);
break
;
}
vDebug
(
"tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d"
,
consumerId
,
pReq
->
epoch
,
TD_VID
(
pTq
->
pVnode
),
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 = p
Topic->buffer.output[workerId].task
;
qTaskInfo_t
task
=
p
Exec
->
task
[
workerId
]
;
ASSERT
(
task
);
qSetStreamInput
(
task
,
pCont
,
STREAM_DATA_TYPE_SUBMIT_BLOCK
);
SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock));
while
(
1
)
{
SSDataBlock
*
pDataBlock
=
NULL
;
uint64_t ts;
uint64_t
ts
=
0
;
if
(
qExecTask
(
task
,
&
pDataBlock
,
&
ts
)
<
0
)
{
ASSERT(false);
}
if (pDataBlock == NULL) {
/*pos = fetchOffset % TQ_BUFFER_SIZE;*/
break;
ASSERT
(
0
);
}
if
(
pDataBlock
==
NULL
)
break
;
taosArrayPush(pRes, pDataBlock
);
}
ASSERT
(
pDataBlock
->
info
.
rows
!=
0
);
ASSERT
(
pDataBlock
->
info
.
numOfCols
!=
0
);
if (taosArrayGetSize(pRes) == 0) {
vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d skip log %ld since not wanted", consumerId,
pReq->epoch, TD_VID(pTq->pVnode), fetchOffset);
fetchOffset++;
rsp.skipLogNum++;
taosArrayDestroy(pRes);
continue;
int32_t
dataStrLen
=
sizeof
(
SRetrieveTableRsp
)
+
blockGetEncodeSize
(
pDataBlock
);
void
*
buf
=
taosMemoryCalloc
(
1
,
dataStrLen
);
SRetrieveTableRsp
*
pRetrieve
=
(
SRetrieveTableRsp
*
)
buf
;
pRetrieve
->
useconds
=
ts
;
pRetrieve
->
precision
=
TSDB_DEFAULT_PRECISION
;
pRetrieve
->
compressed
=
0
;
pRetrieve
->
completed
=
1
;
pRetrieve
->
numOfRows
=
htonl
(
pDataBlock
->
info
.
rows
);
// TODO enable compress
int32_t
actualLen
=
0
;
blockCompressEncode
(
pDataBlock
,
pRetrieve
->
data
,
&
actualLen
,
pDataBlock
->
info
.
numOfCols
,
false
);
actualLen
+=
sizeof
(
SRetrieveTableRsp
);
ASSERT
(
actualLen
<=
dataStrLen
);
taosArrayPush
(
rsp
.
blockDataLen
,
&
actualLen
);
taosArrayPush
(
rsp
.
blockData
,
&
buf
);
rsp
.
blockNum
++
;
}
rsp.schema = pTopic->buffer.output[workerId].pReadHandle->pSchemaWrapper;
rsp.rspOffset = fetchOffset;
}
rsp.numOfTopics = 1;
rsp.pBlockData = pRes;
// TODO batch optimization
if
(
rsp
.
blockNum
!=
0
)
break
;
rsp
.
skipLogNum
++
;
fetchOffset
++
;
}
int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRsp(NULL, &rsp);
void* buf = rpcMallocCont(tlen);
if (buf == NULL) {
pMsg->code = -1;
taosMemoryFree(pHead);
return -1;
}
((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
((SMqRspHead*)buf)->epoch = pReq->epoch;
((SMqRspHead*)buf)->consumerId = consumerId;
ASSERT
(
taosArrayGetSize
(
rsp
.
blockData
)
==
rsp
.
blockNum
);
ASSERT
(
taosArrayGetSize
(
rsp
.
blockDataLen
)
==
rsp
.
blockNum
);
void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
tEncodeSMqPollRsp(&abuf, &rsp);
/*taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);*/
pMsg->pCont = buf;
pMsg->contLen = tlen;
pMsg->code = 0;
vDebug("vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp", TD_VID(pTq->pVnode), fetchOffset,
pHead->msgType, consumerId, pReq->epoch);
tmsgSendRsp(pMsg);
taosMemoryFree(pHead);
return 0;
} else {
taosMemoryFree(pHead);
fetchOffset++;
rsp.skipLogNum++;
}
}
if
(
rsp
.
blockNum
!=
0
)
rsp
.
rspOffset
=
fetchOffset
;
else
rsp
.
rspOffset
=
fetchOffset
-
1
;
/*if (blockingTime != 0) {*/
/*tqAddClientPusher(pTq->tqPushMgr, pMsg, consumerId, blockingTime);*/
/*} else {*/
int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRsp(NULL, &rsp);
int32_t
tlen
=
sizeof
(
SMqRspHead
)
+
tEncodeSMqDataBlkRsp
(
NULL
,
&
rsp
);
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
;
rsp.rspOffset = fetchOffset - 1
;
((
SMqRspHead
*
)
buf
)
->
consumerId
=
consumerId
;
void
*
abuf
=
POINTER_SHIFT
(
buf
,
sizeof
(
SMqRspHead
));
tEncodeSMqPollRsp(&abuf, &rsp);
rsp.pBlockData = NULL;
tEncodeSMqDataBlkRsp
(
&
abuf
,
&
rsp
);
pMsg
->
pCont
=
buf
;
pMsg
->
contLen
=
tlen
;
pMsg
->
code
=
0
;
tmsgSendRsp
(
pMsg
);
vDebug("vg %d offset %ld from consumer %ld (epoch %d) not rsp", TD_VID(pTq->pVnode), fetchOffset, consumerId,
pReq->epoch);
/*}*/
vDebug
(
"vg %d offset %ld from consumer %ld (epoch %d) send rsp, block num: %d, reqOffset: %ld, rspOffset: %ld"
,
TD_VID
(
pTq
->
pVnode
),
fetchOffset
,
consumerId
,
pReq
->
epoch
,
rsp
.
blockNum
,
rsp
.
reqOffset
,
rsp
.
rspOffset
);
// TODO destroy
taosArrayDestroy
(
rsp
.
blockData
);
taosArrayDestroy
(
rsp
.
blockDataLen
);
return
0
;
}
#endif
#if 0
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
SMqPollReq* pReq = pMsg->pCont;
int64_t consumerId = pReq->consumerId;
...
...
@@ -436,7 +369,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
int32_t reqEpoch = pReq->epoch;
if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__EARLIEAST) {
fetchOffset
=
0
;
fetchOffset =
walGetFirstVer(pTq->pWal)
;
} else if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__LATEST) {
fetchOffset = walGetLastVer(pTq->pWal);
} else {
...
...
@@ -635,7 +568,57 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
return 0;
}
#endif
// TODO: persist meta into tdb
int32_t
tqProcessVgChangeReq
(
STQ
*
pTq
,
char
*
msg
,
int32_t
msgLen
)
{
SMqRebVgReq
req
;
tDecodeSMqRebVgReq
(
msg
,
&
req
);
// todo lock
STqExec
*
pExec
=
taosHashGet
(
pTq
->
tqMetaNew
,
req
.
subKey
,
strlen
(
req
.
subKey
));
if
(
pExec
==
NULL
)
{
ASSERT
(
req
.
oldConsumerId
==
-
1
);
ASSERT
(
req
.
newConsumerId
!=
-
1
);
STqExec
exec
=
{
0
};
pExec
=
&
exec
;
/*taosInitRWLatch(&pExec->lock);*/
memcpy
(
pExec
->
subKey
,
req
.
subKey
,
TSDB_SUBSCRIBE_KEY_LEN
);
pExec
->
consumerId
=
req
.
newConsumerId
;
pExec
->
epoch
=
-
1
;
pExec
->
qmsg
=
req
.
qmsg
;
req
.
qmsg
=
NULL
;
pExec
->
pReadHandle
=
walOpenReadHandle
(
pTq
->
pVnode
->
pWal
);
for
(
int32_t
i
=
0
;
i
<
4
;
i
++
)
{
STqReadHandle
*
pReadHandle
=
tqInitSubmitMsgScanner
(
pTq
->
pVnodeMeta
);
SReadHandle
handle
=
{
.
reader
=
pReadHandle
,
.
meta
=
pTq
->
pVnodeMeta
,
};
pExec
->
task
[
i
]
=
qCreateStreamExecTaskInfo
(
pExec
->
qmsg
,
&
handle
);
ASSERT
(
pExec
->
task
[
i
]);
}
taosHashPut
(
pTq
->
tqMetaNew
,
req
.
subKey
,
strlen
(
req
.
subKey
),
pExec
,
sizeof
(
STqExec
));
return
0
;
}
else
{
/*if (req.newConsumerId != -1) {*/
/*taosWLockLatch(&pExec->lock);*/
ASSERT
(
pExec
->
consumerId
==
req
.
oldConsumerId
);
// TODO handle qmsg and exec modification
atomic_store_32
(
&
pExec
->
epoch
,
-
1
);
atomic_store_64
(
&
pExec
->
consumerId
,
req
.
newConsumerId
);
atomic_add_fetch_32
(
&
pExec
->
epoch
,
1
);
/*taosWUnLockLatch(&pExec->lock);*/
return
0
;
/*} else {*/
// TODO
/*taosHashRemove(pTq->tqMetaNew, req.subKey, strlen(req.subKey));*/
/*return 0;*/
/*}*/
}
}
#if 0
int32_t tqProcessRebReq(STQ* pTq, char* msg) {
SMqMVRebReq req = {0};
terrno = TSDB_CODE_SUCCESS;
...
...
@@ -754,6 +737,7 @@ int32_t tqProcessCancelConnReq(STQ* pTq, char* msg) {
terrno = TSDB_CODE_SUCCESS;
return 0;
}
#endif
int32_t
tqExpandTask
(
STQ
*
pTq
,
SStreamTask
*
pTask
,
int32_t
parallel
)
{
if
(
pTask
->
execType
==
TASK_EXEC__NONE
)
return
0
;
...
...
source/dnode/vnode/src/tq/tqMetaStore.c
浏览文件 @
d4734eb1
...
...
@@ -13,7 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "vnodeInt.h"
// TODO:replace by an abstract file layer
// #include <fcntl.h>
// #include <string.h>
// #include <unistd.h>
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
d4734eb1
...
...
@@ -80,6 +80,13 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
pRsp
->
msgType
=
TDMT_VND_SUBMIT_RSP
;
vnodeProcessSubmitReq
(
pVnode
,
ptr
,
pRsp
);
break
;
case
TDMT_VND_MQ_VG_CHANGE
:
if
(
tqProcessVgChangeReq
(
pVnode
->
pTq
,
POINTER_SHIFT
(
pMsg
->
pCont
,
sizeof
(
SMsgHead
)),
pMsg
->
contLen
-
sizeof
(
SMsgHead
))
<
0
)
{
// TODO: handle error
}
break
;
#if 0
case TDMT_VND_MQ_SET_CONN: {
if (tqProcessSetConnReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) {
// TODO: handle error
...
...
@@ -93,6 +100,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
if (tqProcessCancelConnReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) {
}
} break;
#endif
case
TDMT_VND_TASK_DEPLOY
:
{
if
(
tqProcessTaskDeploy
(
pVnode
->
pTq
,
POINTER_SHIFT
(
pMsg
->
pCont
,
sizeof
(
SMsgHead
)),
pMsg
->
contLen
-
sizeof
(
SMsgHead
))
<
0
)
{
...
...
@@ -309,4 +317,4 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, SSubmitReq *pSubmitReq, SRpcMsg
pRsp
->
contLen
=
sizeof
(
SSubmitRsp
);
return
0
;
}
\ No newline at end of file
}
source/libs/function/src/builtins.c
浏览文件 @
d4734eb1
...
...
@@ -939,7 +939,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
translateFunc
=
translateToJson
,
.
getEnvFunc
=
NULL
,
.
initFunc
=
NULL
,
.
sprocessFunc
=
NULL
,
.
sprocessFunc
=
toJsonFunction
,
.
finalizeFunc
=
NULL
}
};
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
d4734eb1
...
...
@@ -1009,6 +1009,7 @@ bool nodesIsComparisonOp(const SOperatorNode* pOp) {
case
OP_TYPE_NOT_LIKE
:
case
OP_TYPE_MATCH
:
case
OP_TYPE_NMATCH
:
case
OP_TYPE_JSON_CONTAINS
:
case
OP_TYPE_IS_NULL
:
case
OP_TYPE_IS_NOT_NULL
:
case
OP_TYPE_IS_TRUE
:
...
...
@@ -1027,7 +1028,6 @@ bool nodesIsComparisonOp(const SOperatorNode* pOp) {
bool
nodesIsJsonOp
(
const
SOperatorNode
*
pOp
)
{
switch
(
pOp
->
opType
)
{
case
OP_TYPE_JSON_GET_VALUE
:
case
OP_TYPE_JSON_CONTAINS
:
return
true
;
default:
break
;
...
...
source/libs/parser/inc/parUtil.h
浏览文件 @
d4734eb1
...
...
@@ -47,6 +47,7 @@ SSchema *getTableTagSchema(const STableMeta* pTableMeta);
int32_t
getNumOfColumns
(
const
STableMeta
*
pTableMeta
);
int32_t
getNumOfTags
(
const
STableMeta
*
pTableMeta
);
STableComInfo
getTableInfo
(
const
STableMeta
*
pTableMeta
);
int
parseJsontoTagData
(
const
char
*
json
,
SKVRowBuilder
*
kvRowBuilder
,
SMsgBuf
*
errMsg
,
int16_t
startColId
);
int32_t
trimString
(
const
char
*
src
,
int32_t
len
,
char
*
dst
,
int32_t
dlen
);
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
d4734eb1
...
...
@@ -48,6 +48,7 @@ void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) {
}
static
void
trimEscape
(
SToken
*
pName
)
{
// todo need to deal with `ioo``ii` -> ioo`ii
if
(
NULL
!=
pName
&&
pName
->
n
>
1
&&
'`'
==
pName
->
z
[
0
])
{
pName
->
z
+=
1
;
pName
->
n
-=
2
;
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
d4734eb1
...
...
@@ -397,35 +397,15 @@ static FORCE_INLINE int32_t checkAndTrimValue(SToken* pToken, uint32_t type, cha
return
buildSyntaxErrMsg
(
pMsgBuf
,
"invalid data or symbol"
,
pToken
->
z
);
}
if
(
IS_NUMERIC_TYPE
(
type
)
&&
pToken
->
n
==
0
)
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"invalid numeric data"
,
pToken
->
z
);
}
// Remove quotation marks
if
(
TK_NK_STRING
==
pToken
->
type
)
{
if
(
pToken
->
n
>=
TSDB_MAX_BYTES_PER_ROW
)
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"too long string"
,
pToken
->
z
);
}
// delete escape character: \\, \', \"
char
delim
=
pToken
->
z
[
0
];
int32_t
cnt
=
0
;
int32_t
j
=
0
;
for
(
uint32_t
k
=
1
;
k
<
pToken
->
n
-
1
;
++
k
)
{
if
(
pToken
->
z
[
k
]
==
'\\'
||
(
pToken
->
z
[
k
]
==
delim
&&
pToken
->
z
[
k
+
1
]
==
delim
))
{
tmpTokenBuf
[
j
]
=
pToken
->
z
[
k
+
1
];
cnt
++
;
j
++
;
k
++
;
continue
;
}
tmpTokenBuf
[
j
]
=
pToken
->
z
[
k
];
j
++
;
}
tmpTokenBuf
[
j
]
=
0
;
int32_t
len
=
trimString
(
pToken
->
z
,
pToken
->
n
,
tmpTokenBuf
,
TSDB_MAX_BYTES_PER_ROW
);
pToken
->
z
=
tmpTokenBuf
;
pToken
->
n
-=
2
+
cnt
;
pToken
->
n
=
len
;
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -603,6 +583,13 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int
return
func
(
pMsgBuf
,
pToken
->
z
,
pToken
->
n
,
param
);
}
case
TSDB_DATA_TYPE_JSON
:
{
if
(
pToken
->
n
>
(
TSDB_MAX_JSON_TAG_LEN
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
){
return
buildSyntaxErrMsg
(
pMsgBuf
,
"json string too long than 4095"
,
pToken
->
z
);
}
return
func
(
pMsgBuf
,
pToken
->
z
,
pToken
->
n
,
param
);
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
int64_t
tmpVal
;
if
(
parseTime
(
end
,
pToken
,
timePrec
,
&
tmpVal
,
pMsgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -723,8 +710,10 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo*
qsort
(
pColIdx
,
pColList
->
numOfBound
,
sizeof
(
SBoundIdxInfo
),
boundIdxCompar
);
}
memset
(
&
pColList
->
boundColumns
[
pColList
->
numOfBound
],
0
,
sizeof
(
col_id_t
)
*
(
pColList
->
numOfCols
-
pColList
->
numOfBound
));
if
(
pColList
->
numOfCols
>
pColList
->
numOfBound
){
memset
(
&
pColList
->
boundColumns
[
pColList
->
numOfBound
],
0
,
sizeof
(
col_id_t
)
*
(
pColList
->
numOfCols
-
pColList
->
numOfBound
));
}
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -741,9 +730,18 @@ static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, voi
int8_t
type
=
pa
->
schema
->
type
;
int16_t
colId
=
pa
->
schema
->
colId
;
if
(
TSDB_DATA_TYPE_JSON
==
type
){
return
parseJsontoTagData
(
value
,
pa
->
builder
,
pMsgBuf
,
colId
);
}
if
(
value
==
NULL
)
{
// it is a null data
// tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, pa->colIdx);
return
TSDB_CODE_SUCCESS
;
}
if
(
TSDB_DATA_TYPE_BINARY
==
type
)
{
STR_WITH_SIZE_TO_VARSTR
(
pa
->
buf
,
value
,
len
);
tdAddColToKVRow
(
pa
->
builder
,
colId
,
type
,
pa
->
buf
);
tdAddColToKVRow
(
pa
->
builder
,
colId
,
pa
->
buf
,
varDataTLen
(
pa
->
buf
)
);
}
else
if
(
TSDB_DATA_TYPE_NCHAR
==
type
)
{
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
int32_t
output
=
0
;
...
...
@@ -751,13 +749,12 @@ static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, voi
char
buf
[
512
]
=
{
0
};
snprintf
(
buf
,
tListLen
(
buf
),
"%s"
,
strerror
(
errno
));
return
buildSyntaxErrMsg
(
pMsgBuf
,
buf
,
value
);
;
}
varDataSetLen
(
pa
->
buf
,
output
);
tdAddColToKVRow
(
pa
->
builder
,
colId
,
type
,
pa
->
buf
);
tdAddColToKVRow
(
pa
->
builder
,
colId
,
pa
->
buf
,
varDataTLen
(
pa
->
buf
)
);
}
else
{
tdAddColToKVRow
(
pa
->
builder
,
colId
,
type
,
value
);
tdAddColToKVRow
(
pa
->
builder
,
colId
,
value
,
TYPE_BYTES
[
type
]
);
}
return
TSDB_CODE_SUCCESS
;
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
d4734eb1
...
...
@@ -543,14 +543,18 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
pOp
->
node
.
resType
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_DOUBLE
].
bytes
;
}
}
else
if
(
nodesIsComparisonOp
(
pOp
))
{
if
(
TSDB_DATA_TYPE_
JSON
==
ldt
.
type
||
TSDB_DATA_TYPE_
BLOB
==
ldt
.
type
||
TSDB_DATA_TYPE_JSON
==
rdt
.
type
||
if
(
TSDB_DATA_TYPE_BLOB
==
ldt
.
type
||
TSDB_DATA_TYPE_JSON
==
rdt
.
type
||
TSDB_DATA_TYPE_BLOB
==
rdt
.
type
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
((
SExprNode
*
)(
pOp
->
pRight
))
->
aliasName
);
}
pOp
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_BOOL
;
pOp
->
node
.
resType
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_BOOL
].
bytes
;
}
else
{
// todo json operator
}
else
if
(
nodesIsJsonOp
(
pOp
)){
if
(
TSDB_DATA_TYPE_JSON
!=
ldt
.
type
||
TSDB_DATA_TYPE_BINARY
!=
rdt
.
type
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
((
SExprNode
*
)(
pOp
->
pRight
))
->
aliasName
);
}
pOp
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_JSON
;
pOp
->
node
.
resType
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_JSON
].
bytes
;
}
return
DEAL_RES_CONTINUE
;
}
...
...
@@ -1813,6 +1817,17 @@ static int32_t checkTableSmaOption(STranslateContext* pCxt, SCreateTableStmt* pS
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
checkTableTags
(
STranslateContext
*
pCxt
,
SCreateTableStmt
*
pStmt
)
{
SNode
*
pNode
;
FOREACH
(
pNode
,
pStmt
->
pTags
)
{
SColumnDefNode
*
pCol
=
(
SColumnDefNode
*
)
pNode
;
if
(
pCol
->
dataType
.
type
==
TSDB_DATA_TYPE_JSON
&&
LIST_LENGTH
(
pStmt
->
pTags
)
>
1
){
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_ONLY_ONE_JSON_TAG
);
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
checkTableRollupOption
(
STranslateContext
*
pCxt
,
SNodeList
*
pFuncs
)
{
if
(
NULL
==
pFuncs
)
{
return
TSDB_CODE_SUCCESS
;
...
...
@@ -1848,6 +1863,9 @@ static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkRangeOption
(
pCxt
,
"delay"
,
pStmt
->
pOptions
->
pDelay
,
TSDB_MIN_DB_DELAY
,
TSDB_MAX_DB_DELAY
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkTableTags
(
pCxt
,
pStmt
);
}
return
code
;
}
...
...
@@ -3247,17 +3265,25 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, c
static
int32_t
addValToKVRow
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
,
const
SSchema
*
pSchema
,
SKVRowBuilder
*
pBuilder
)
{
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_JSON
){
if
(
pVal
->
literal
&&
strlen
(
pVal
->
literal
)
>
(
TSDB_MAX_JSON_TAG_LEN
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
){
return
buildSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
"json string too long than 4095"
,
pVal
->
literal
);
}
return
parseJsontoTagData
(
pVal
->
literal
,
pBuilder
,
&
pCxt
->
msgBuf
,
pSchema
->
colId
);
}
if
(
DEAL_RES_ERROR
==
translateValue
(
pCxt
,
pVal
))
{
return
pCxt
->
errCode
;
}
SVariant
var
;
valueNodeToVariant
(
pVal
,
&
var
);
char
tagVal
[
TSDB_MAX_TAGS_LEN
]
=
{
0
};
int32_t
code
=
taosVariantDump
(
&
var
,
tagVal
,
pSchema
->
type
,
true
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tdAddColToKVRow
(
pBuilder
,
pSchema
->
colId
,
pSchema
->
type
,
tagVal
);
if
(
pVal
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_NULL
){
// todo
}
else
{
tdAddColToKVRow
(
pBuilder
,
pSchema
->
colId
,
&
(
pVal
->
datum
.
p
),
IS_VAR_DATA_TYPE
(
pSchema
->
type
)
?
varDataTLen
(
pVal
->
datum
.
p
)
:
TYPE_BYTES
[
pSchema
->
type
]);
}
return
code
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
buildKVRowForBindTags
(
STranslateContext
*
pCxt
,
SCreateSubTableClause
*
pStmt
,
STableMeta
*
pSuperTableMeta
,
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
d4734eb1
...
...
@@ -14,6 +14,7 @@
*/
#include "parUtil.h"
#include "cJSON.h"
static
char
*
getSyntaxErrFormat
(
int32_t
errCode
)
{
switch
(
errCode
)
{
...
...
@@ -115,6 +116,8 @@ static char* getSyntaxErrFormat(int32_t errCode) {
return
"sliding value no larger than the interval value"
;
case
TSDB_CODE_PAR_INTER_SLIDING_TOO_SMALL
:
return
"sliding value can not less than 1% of interval value"
;
case
TSDB_CODE_PAR_ONLY_ONE_JSON_TAG
:
return
"Only one tag if there is a json tag"
;
case
TSDB_CODE_OUT_OF_MEMORY
:
return
"Out of memory"
;
default:
...
...
@@ -215,24 +218,178 @@ STableComInfo getTableInfo(const STableMeta* pTableMeta) {
}
int32_t
trimString
(
const
char
*
src
,
int32_t
len
,
char
*
dst
,
int32_t
dlen
)
{
// delete escape character: \\, \', \"
if
(
len
<=
0
||
dlen
<=
0
)
return
0
;
char
delim
=
src
[
0
];
int32_t
cnt
=
0
;
int32_t
j
=
0
;
for
(
uint32_t
k
=
1
;
k
<
len
-
1
;
++
k
)
{
if
(
j
>=
dlen
)
{
break
;
dst
[
j
-
1
]
=
'\0'
;
return
j
;
}
if
(
src
[
k
]
==
'\\'
||
(
src
[
k
]
==
delim
&&
src
[
k
+
1
]
==
delim
))
{
if
(
src
[
k
]
==
delim
&&
src
[
k
+
1
]
==
delim
)
{
// deal with "", ''
dst
[
j
]
=
src
[
k
+
1
];
cnt
++
;
j
++
;
k
++
;
continue
;
}
if
(
src
[
k
]
==
'\\'
)
{
// deal with escape character
if
(
src
[
k
+
1
]
==
'n'
){
dst
[
j
]
=
'\n'
;
}
else
if
(
src
[
k
+
1
]
==
'r'
){
dst
[
j
]
=
'\r'
;
}
else
if
(
src
[
k
+
1
]
==
't'
){
dst
[
j
]
=
'\t'
;
}
else
if
(
src
[
k
+
1
]
==
'\\'
){
dst
[
j
]
=
'\\'
;
}
else
if
(
src
[
k
+
1
]
==
'\''
){
dst
[
j
]
=
'\''
;
}
else
if
(
src
[
k
+
1
]
==
'"'
){
dst
[
j
]
=
'"'
;
}
else
if
(
src
[
k
+
1
]
==
'%'
||
src
[
k
+
1
]
==
'_'
){
dst
[
j
++
]
=
src
[
k
];
dst
[
j
]
=
src
[
k
+
1
];
}
else
{
dst
[
j
]
=
src
[
k
+
1
];
}
j
++
;
k
++
;
continue
;
}
dst
[
j
]
=
src
[
k
];
j
++
;
}
dst
[
j
]
=
'\0'
;
return
j
;
}
static
bool
isValidateTag
(
char
*
input
)
{
if
(
!
input
)
return
false
;
for
(
size_t
i
=
0
;
i
<
strlen
(
input
);
++
i
)
{
if
(
isprint
(
input
[
i
])
==
0
)
return
false
;
}
return
true
;
}
int
parseJsontoTagData
(
const
char
*
json
,
SKVRowBuilder
*
kvRowBuilder
,
SMsgBuf
*
pMsgBuf
,
int16_t
startColId
){
// set json NULL data
uint8_t
jsonNULL
=
TSDB_DATA_TYPE_NULL
;
int
jsonIndex
=
startColId
+
1
;
if
(
!
json
||
strcasecmp
(
json
,
TSDB_DATA_NULL_STR_L
)
==
0
){
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
,
&
jsonNULL
,
CHAR_BYTES
);
return
TSDB_CODE_SUCCESS
;
}
// set json real data
cJSON
*
root
=
cJSON_Parse
(
json
);
if
(
root
==
NULL
){
return
buildSyntaxErrMsg
(
pMsgBuf
,
"json parse error"
,
json
);
}
int
size
=
cJSON_GetArraySize
(
root
);
if
(
!
cJSON_IsObject
(
root
)){
return
buildSyntaxErrMsg
(
pMsgBuf
,
"json error invalide value"
,
json
);
}
int
retCode
=
0
;
char
*
tagKV
=
NULL
;
SHashObj
*
keyHash
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
false
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
root
,
i
);
if
(
!
item
)
{
qError
(
"json inner error:%d"
,
i
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json inner error"
,
json
);
goto
end
;
}
char
*
jsonKey
=
item
->
string
;
if
(
!
isValidateTag
(
jsonKey
)){
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json key not validate"
,
jsonKey
);
goto
end
;
}
// if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){
// tscError("json key too long error");
// retCode = tscSQLSyntaxErrMsg(errMsg, "json key too long, more than 256", NULL);
// goto end;
// }
size_t
keyLen
=
strlen
(
jsonKey
);
if
(
keyLen
==
0
||
taosHashGet
(
keyHash
,
jsonKey
,
keyLen
)
!=
NULL
){
continue
;
}
// key: keyLen + VARSTR_HEADER_SIZE, value type: CHAR_BYTES, value reserved: LONG_BYTES
tagKV
=
taosMemoryCalloc
(
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
LONG_BYTES
,
1
);
if
(
!
tagKV
)
{
retCode
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
strncpy
(
varDataVal
(
tagKV
),
jsonKey
,
keyLen
);
varDataSetLen
(
tagKV
,
keyLen
);
if
(
taosHashGetSize
(
keyHash
)
==
0
){
uint8_t
jsonNotNULL
=
TSDB_DATA_TYPE_JSON
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
&
jsonNotNULL
,
CHAR_BYTES
);
// add json type
}
taosHashPut
(
keyHash
,
jsonKey
,
keyLen
,
&
keyLen
,
CHAR_BYTES
);
// add key to hash to remove dumplicate, value is useless
if
(
item
->
type
==
cJSON_String
){
// add json value format: type|data
char
*
jsonValue
=
item
->
valuestring
;
int32_t
valLen
=
(
int32_t
)
strlen
(
jsonValue
);
int32_t
totalLen
=
keyLen
+
VARSTR_HEADER_SIZE
+
valLen
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
;
char
*
tmp
=
taosMemoryRealloc
(
tagKV
,
totalLen
);
if
(
!
tmp
)
{
retCode
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
tagKV
=
tmp
;
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
*
valueType
=
TSDB_DATA_TYPE_NCHAR
;
if
(
valLen
>
0
&&
!
taosMbsToUcs4
(
jsonValue
,
valLen
,
(
TdUcs4
*
)
varDataVal
(
valueData
),
(
int32_t
)(
valLen
*
TSDB_NCHAR_SIZE
),
&
valLen
))
{
qError
(
"charset:%s to %s. val:%s, errno:%s, convert failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
jsonValue
,
strerror
(
errno
));
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"charset convert json error"
,
jsonValue
);
goto
end
;
}
varDataSetLen
(
valueData
,
valLen
);
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
totalLen
);
}
else
if
(
item
->
type
==
cJSON_Number
){
if
(
!
isfinite
(
item
->
valuedouble
)){
qError
(
"json value is invalidate"
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json value number is illegal"
,
json
);
goto
end
;
}
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
*
valueType
=
(
item
->
valuedouble
-
(
int64_t
)(
item
->
valuedouble
)
==
0
)
?
TSDB_DATA_TYPE_BIGINT
:
TSDB_DATA_TYPE_DOUBLE
;
if
(
*
valueType
==
TSDB_DATA_TYPE_DOUBLE
)
*
((
double
*
)
valueData
)
=
item
->
valuedouble
;
else
if
(
*
valueType
==
TSDB_DATA_TYPE_BIGINT
)
*
((
int64_t
*
)
valueData
)
=
item
->
valueint
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
LONG_BYTES
);
}
else
if
(
item
->
type
==
cJSON_True
||
item
->
type
==
cJSON_False
){
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
*
valueType
=
TSDB_DATA_TYPE_BOOL
;
*
valueData
=
(
char
)(
item
->
valueint
);
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
CHAR_BYTES
);
}
else
if
(
item
->
type
==
cJSON_NULL
){
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
*
valueType
=
TSDB_DATA_TYPE_NULL
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
}
else
{
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"invalidate json value"
,
json
);
goto
end
;
}
}
if
(
taosHashGetSize
(
keyHash
)
==
0
){
// set json NULL true
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
,
&
jsonNULL
,
CHAR_BYTES
);
}
end:
taosMemoryFree
(
tagKV
);
taosHashCleanup
(
keyHash
);
cJSON_Delete
(
root
);
return
retCode
;
}
\ No newline at end of file
source/libs/scalar/inc/filterInt.h
浏览文件 @
d4734eb1
...
...
@@ -308,7 +308,6 @@ struct SFilterInfo {
#define FILTER_GET_COL_FIELD_DATA(fi, ri) (colDataGetData(((SColumnInfoData *)(fi)->data), (ri)))
#define FILTER_GET_VAL_FIELD_TYPE(fi) (((SValueNode *)((fi)->desc))->node.resType.type)
#define FILTER_GET_VAL_FIELD_DATA(fi) ((char *)(fi)->data)
#define FILTER_GET_JSON_VAL_FIELD_DATA(fi) ((char *)(fi)->desc)
#define FILTER_GET_TYPE(fl) ((fl) & FLD_TYPE_MAX)
#define FILTER_GROUP_UNIT(i, g, uid) ((i)->units + (g)->unitIdxs[uid])
...
...
@@ -321,7 +320,6 @@ struct SFilterInfo {
#define FILTER_UNIT_COL_SIZE(i, u) FILTER_GET_COL_FIELD_SIZE(FILTER_UNIT_LEFT_FIELD(i, u))
#define FILTER_UNIT_COL_ID(i, u) FILTER_GET_COL_FIELD_ID(FILTER_UNIT_LEFT_FIELD(i, u))
#define FILTER_UNIT_VAL_DATA(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u))
#define FILTER_UNIT_JSON_VAL_DATA(i, u) FILTER_GET_JSON_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u))
#define FILTER_UNIT_COL_IDX(u) ((u)->left.idx)
#define FILTER_UNIT_OPTR(u) ((u)->compare.optr)
#define FILTER_UNIT_COMP_FUNC(u) ((u)->compare.func)
...
...
source/libs/scalar/inc/sclvector.h
浏览文件 @
d4734eb1
...
...
@@ -56,6 +56,8 @@ static FORCE_INLINE double getVectorDoubleValue_BOOL(void *src, int32_t index) {
return
(
double
)
*
((
bool
*
)
src
+
index
);
}
double
getVectorDoubleValue_JSON
(
void
*
src
,
int32_t
index
);
static
FORCE_INLINE
_getDoubleValue_fn_t
getVectorDoubleValueFn
(
int32_t
srcType
)
{
_getDoubleValue_fn_t
p
=
NULL
;
if
(
srcType
==
TSDB_DATA_TYPE_TINYINT
)
{
...
...
@@ -80,6 +82,8 @@ static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType)
p
=
getVectorDoubleValue_DOUBLE
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
p
=
getVectorDoubleValue_BIGINT
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_JSON
)
{
p
=
getVectorDoubleValue_JSON
;
}
else
if
(
srcType
==
TSDB_DATA_TYPE_BOOL
)
{
p
=
getVectorDoubleValue_BOOL
;
}
else
{
...
...
source/libs/scalar/src/filter.c
浏览文件 @
d4734eb1
...
...
@@ -57,28 +57,24 @@ OptrStr gOptrStr[] = {
{
OP_TYPE_IS_NOT_UNKNOWN
,
"not unknown"
},
// json operator
{
OP_TYPE_JSON_GET_VALUE
,
"
json get
"
},
{
OP_TYPE_JSON_GET_VALUE
,
"
->
"
},
{
OP_TYPE_JSON_CONTAINS
,
"json contains"
}
};
bool
filterRangeCompGi
(
const
void
*
minv
,
const
void
*
maxv
,
const
void
*
minr
,
const
void
*
maxr
,
__compar_fn_t
cfunc
)
{
int32_t
result
=
cfunc
(
maxv
,
minr
);
//if (result == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false;
return
result
>=
0
;
}
bool
filterRangeCompGe
(
const
void
*
minv
,
const
void
*
maxv
,
const
void
*
minr
,
const
void
*
maxr
,
__compar_fn_t
cfunc
)
{
int32_t
result
=
cfunc
(
maxv
,
minr
);
//if (result == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false;
return
result
>
0
;
}
bool
filterRangeCompLi
(
const
void
*
minv
,
const
void
*
maxv
,
const
void
*
minr
,
const
void
*
maxr
,
__compar_fn_t
cfunc
)
{
int32_t
result
=
cfunc
(
minv
,
maxr
);
//if (result == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false;
return
result
<=
0
;
}
bool
filterRangeCompLe
(
const
void
*
minv
,
const
void
*
maxv
,
const
void
*
minr
,
const
void
*
maxr
,
__compar_fn_t
cfunc
)
{
int32_t
result
=
cfunc
(
minv
,
maxr
);
//if (result == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false;
return
result
<
0
;
}
bool
filterRangeCompii
(
const
void
*
minv
,
const
void
*
maxv
,
const
void
*
minr
,
const
void
*
maxr
,
__compar_fn_t
cfunc
)
{
...
...
@@ -170,7 +166,7 @@ __compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val
compareLenPrefixedWStr
,
compareUint8Val
,
compareUint16Val
,
compareUint32Val
,
compareUint64Val
,
setChkInBytes1
,
setChkInBytes2
,
setChkInBytes4
,
setChkInBytes8
,
compareStrRegexCompMatch
,
compareStrRegexCompNMatch
,
setChkNotInBytes1
,
setChkNotInBytes2
,
setChkNotInBytes4
,
setChkNotInBytes8
,
compareChkNotInString
,
compareStrPatternNotMatch
,
compareWStrPatternNotMatch
compareChkNotInString
,
compareStrPatternNotMatch
,
compareWStrPatternNotMatch
,
compareJsonContainsKey
};
int8_t
filterGetCompFuncIdx
(
int32_t
type
,
int32_t
optr
)
{
...
...
@@ -221,7 +217,12 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
assert
(
0
);
}
}
if
(
optr
==
OP_TYPE_JSON_CONTAINS
&&
type
==
TSDB_DATA_TYPE_JSON
)
{
return
28
;
}
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
comparFn
=
1
;
break
;
...
...
@@ -1049,6 +1050,8 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) {
cell
=
cell
->
pNext
;
}
colDataDestroy
(
out
.
columnData
);
taosMemoryFree
(
out
.
columnData
);
}
else
{
filterAddFieldFromNode
(
info
,
node
->
pRight
,
&
right
);
...
...
@@ -1778,9 +1781,9 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
bytes
=
(
len
+
1
)
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
;
fi
->
data
=
taosMemoryCalloc
(
1
,
bytes
);
}
else
if
(
type
!=
TSDB_DATA_TYPE_JSON
)
{
}
else
{
if
(
dType
->
type
==
TSDB_DATA_TYPE_VALUE_ARRAY
)
{
//TIME RANGE
/*
/*
fi->data = taosMemoryCalloc(dType->bytes, tDataTypes[type].bytes);
for (int32_t a = 0; a < dType->bytes; ++a) {
int64_t *v = taosArrayGet(var->arr, a);
...
...
@@ -1791,31 +1794,29 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
}
else
{
fi
->
data
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
));
}
}
else
{
// type == TSDB_DATA_TYPE_JSON
// fi->data = null; use fi->desc as data, because json value is variable, so use tVariant (fi->desc)
}
if
(
type
!=
TSDB_DATA_TYPE_JSON
)
{
if
(
dType
->
type
==
type
)
{
assignVal
(
fi
->
data
,
nodesGetValueFromNode
(
var
),
dType
->
bytes
,
type
);
if
(
dType
->
type
==
type
)
{
assignVal
(
fi
->
data
,
nodesGetValueFromNode
(
var
),
dType
->
bytes
,
type
);
}
else
{
SScalarParam
out
=
{.
columnData
=
taosMemoryCalloc
(
1
,
sizeof
(
SColumnInfoData
))};
out
.
columnData
->
info
.
type
=
type
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
out
.
columnData
->
info
.
bytes
=
bytes
;
}
else
{
SScalarParam
out
=
{.
columnData
=
taosMemoryCalloc
(
1
,
sizeof
(
SColumnInfoData
))};
out
.
columnData
->
info
.
type
=
type
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
out
.
columnData
->
info
.
bytes
=
bytes
;
}
else
{
out
.
columnData
->
info
.
bytes
=
tDataTypes
[
type
].
bytes
;
}
// todo refactor the convert
int32_t
code
=
doConvertDataType
(
var
,
&
out
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"convert value to type[%d] failed"
,
type
);
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
out
.
columnData
->
info
.
bytes
=
tDataTypes
[
type
].
bytes
;
}
memcpy
(
fi
->
data
,
out
.
columnData
->
pData
,
out
.
columnData
->
info
.
bytes
);
// todo refactor the convert
int32_t
code
=
doConvertDataType
(
var
,
&
out
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"convert value to type[%d] failed"
,
type
);
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
memcpy
(
fi
->
data
,
out
.
columnData
->
pData
,
out
.
columnData
->
info
.
bytes
);
colDataDestroy
(
out
.
columnData
);
taosMemoryFree
(
out
.
columnData
);
}
// match/nmatch for nchar type need convert from ucs4 to mbs
...
...
@@ -2556,11 +2557,7 @@ int32_t filterGenerateComInfo(SFilterInfo *info) {
info
->
cunits
[
i
].
colId
=
FILTER_UNIT_COL_ID
(
info
,
unit
);
if
(
unit
->
right
.
type
==
FLD_TYPE_VALUE
)
{
if
(
FILTER_UNIT_DATA_TYPE
(
unit
)
==
TSDB_DATA_TYPE_JSON
){
// json value is tVariant
info
->
cunits
[
i
].
valData
=
FILTER_UNIT_JSON_VAL_DATA
(
info
,
unit
);
}
else
{
info
->
cunits
[
i
].
valData
=
FILTER_UNIT_VAL_DATA
(
info
,
unit
);
}
info
->
cunits
[
i
].
valData
=
FILTER_UNIT_VAL_DATA
(
info
,
unit
);
}
else
{
info
->
cunits
[
i
].
valData
=
NULL
;
}
...
...
@@ -2886,18 +2883,8 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows,
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
uint32_t
uidx
=
info
->
groups
[
0
].
unitIdxs
[
0
];
void
*
colData
=
colDataGetData
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
i
);
if
(
info
->
cunits
[
uidx
].
dataType
==
TSDB_DATA_TYPE_JSON
){
if
(
!
colData
){
// for json->'key' is null
(
*
p
)[
i
]
=
1
;
}
else
if
(
*
(
char
*
)
colData
==
TSDB_DATA_TYPE_JSON
){
// for json is null
colData
=
POINTER_SHIFT
(
colData
,
CHAR_BYTES
);
(
*
p
)[
i
]
=
colDataIsNull
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
0
,
i
,
NULL
);
}
else
{
(
*
p
)[
i
]
=
0
;
}
}
else
{
(
*
p
)[
i
]
=
((
colData
==
NULL
)
||
colDataIsNull
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
0
,
i
,
NULL
));
}
(
*
p
)[
i
]
=
((
colData
==
NULL
)
||
colDataIsNull
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
0
,
i
,
NULL
));
if
((
*
p
)[
i
]
==
0
)
{
all
=
false
;
}
...
...
@@ -2921,19 +2908,7 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows
uint32_t
uidx
=
info
->
groups
[
0
].
unitIdxs
[
0
];
void
*
colData
=
colDataGetData
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
i
);
if
(
info
->
cunits
[
uidx
].
dataType
==
TSDB_DATA_TYPE_JSON
){
if
(
!
colData
)
{
// for json->'key' is not null
(
*
p
)[
i
]
=
0
;
}
else
if
(
*
(
char
*
)
colData
==
TSDB_DATA_TYPE_JSON
){
// for json is not null
colData
=
POINTER_SHIFT
(
colData
,
CHAR_BYTES
);
(
*
p
)[
i
]
=
!
colDataIsNull
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
0
,
i
,
NULL
);
}
else
{
// for json->'key' is not null
(
*
p
)[
i
]
=
1
;
}
}
else
{
(
*
p
)[
i
]
=
((
colData
!=
NULL
)
&&
!
colDataIsNull
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
0
,
i
,
NULL
));
}
(
*
p
)[
i
]
=
((
colData
!=
NULL
)
&&
!
colDataIsNull
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
0
,
i
,
NULL
));
if
((
*
p
)[
i
]
==
0
)
{
all
=
false
;
}
...
...
@@ -3566,6 +3541,11 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
return
DEAL_RES_CONTINUE
;
}
if
(
OP_TYPE_JSON_CONTAINS
==
node
->
opType
)
{
stat
->
scalarMode
=
true
;
return
DEAL_RES_CONTINUE
;
}
if
(
QUERY_NODE_COLUMN
!=
nodeType
(
node
->
pLeft
))
{
SNode
*
t
=
node
->
pLeft
;
node
->
pLeft
=
node
->
pRight
;
...
...
source/libs/scalar/src/scalar.c
浏览文件 @
d4734eb1
...
...
@@ -132,6 +132,7 @@ void sclFreeRes(SHashObj *res) {
void
sclFreeParam
(
SScalarParam
*
param
)
{
if
(
param
->
columnData
!=
NULL
)
{
colDataDestroy
(
param
->
columnData
);
taosMemoryFree
(
param
->
columnData
);
}
if
(
param
->
pHashFilter
!=
NULL
)
{
...
...
@@ -605,37 +606,48 @@ EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) {
EDealRes
sclWalkTarget
(
SNode
*
pNode
,
SScalarCtx
*
ctx
)
{
STargetNode
*
target
=
(
STargetNode
*
)
pNode
;
if
(
target
->
dataBlockId
>=
taosArrayGetSize
(
ctx
->
pBlockList
))
{
sclError
(
"target tupleId is too big, tupleId:%d, dataBlockNum:%d"
,
target
->
dataBlockId
,
(
int32_t
)
taosArrayGetSize
(
ctx
->
pBlockList
));
ctx
->
code
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
DEAL_RES_ERROR
;
}
SSDataBlock
*
block
=
*
(
SSDataBlock
**
)
taosArrayGet
(
ctx
->
pBlockList
,
target
->
dataBlockId
);
int32_t
index
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
ctx
->
pBlockList
);
++
i
)
{
SSDataBlock
*
pb
=
taosArrayGetP
(
ctx
->
pBlockList
,
i
);
if
(
pb
->
info
.
blockId
==
target
->
dataBlockId
)
{
index
=
i
;
break
;
}
}
if
(
index
==
-
1
)
{
sclError
(
"column tupleId is too big, tupleId:%d, dataBlockNum:%d"
,
target
->
dataBlockId
,
(
int32_t
)
taosArrayGetSize
(
ctx
->
pBlockList
));
ctx
->
code
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
DEAL_RES_ERROR
;
}
SSDataBlock
*
block
=
*
(
SSDataBlock
**
)
taosArrayGet
(
ctx
->
pBlockList
,
index
);
if
(
target
->
slotId
>=
taosArrayGetSize
(
block
->
pDataBlock
))
{
sclError
(
"target slot not exist, dataBlockId:%d, slotId:%d, dataBlockNum:%d"
,
target
->
dataBlockId
,
target
->
slotId
,
(
int32_t
)
taosArrayGetSize
(
block
->
pDataBlock
));
ctx
->
code
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
DEAL_RES_ERROR
;
}
// if block->pDataBlock is not enough, there are problems if target->slotId bigger than the size of block->pDataBlock,
SColumnInfoData
*
col
=
taosArrayGet
(
block
->
pDataBlock
,
target
->
slotId
);
SScalarParam
*
res
=
(
SScalarParam
*
)
taosHashGet
(
ctx
->
pRes
,
(
void
*
)
&
target
->
pExpr
,
POINTER_BYTES
);
if
(
NULL
==
res
)
{
sclError
(
"no valid res in hash, node:%p, type:%d"
,
target
->
pExpr
,
nodeType
(
target
->
pExpr
));
ctx
->
code
=
TSDB_CODE_QRY_APP_ERROR
;
return
DEAL_RES_ERROR
;
}
for
(
int32_t
i
=
0
;
i
<
res
->
numOfRows
;
++
i
)
{
if
(
colDataIsNull
(
res
->
columnData
,
res
->
numOfRows
,
i
,
NULL
))
{
colDataAppend
(
col
,
i
,
NULL
,
true
);
}
else
{
char
*
p
=
colDataGetData
(
res
->
columnData
,
i
);
colDataAppend
(
col
,
i
,
p
,
false
);
}
}
colDataAssign
(
col
,
res
->
columnData
,
res
->
numOfRows
);
block
->
info
.
rows
=
res
->
numOfRows
;
sclFreeParam
(
res
);
taosHashRemove
(
ctx
->
pRes
,
(
void
*
)
&
target
->
pExpr
,
POINTER_BYTES
);
...
...
source/libs/scalar/src/sclfunc.c
浏览文件 @
d4734eb1
...
...
@@ -4,6 +4,7 @@
#include "ttime.h"
#include "sclInt.h"
#include "sclvector.h"
#include "tjson.h"
typedef
float
(
*
_float_fn
)(
float
);
typedef
double
(
*
_double_fn
)(
double
);
...
...
@@ -872,6 +873,59 @@ int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
return
TSDB_CODE_SUCCESS
;
}
int32_t
toJsonFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
type
=
GET_PARAM_TYPE
(
pInput
);
if
(
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
)
{
return
TSDB_CODE_FAILED
;
}
if
(
inputNum
!=
1
)
{
return
TSDB_CODE_FAILED
;
}
char
*
input
=
pInput
[
0
].
columnData
->
pData
+
pInput
[
0
].
columnData
->
varmeta
.
offset
[
0
];
char
*
tmp
=
taosMemoryCalloc
(
pInput
[
0
].
columnData
->
info
.
bytes
+
1
,
1
);
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInput
[
0
].
columnData
,
i
))
{
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
if
(
type
==
TSDB_DATA_TYPE_NCHAR
){
if
(
varDataTLen
(
input
)
>
TSDB_MAX_JSON_TAG_LEN
){
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
int32_t
len
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
input
),
varDataLen
(
input
),
tmp
);
if
(
len
<
0
)
{
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
tmp
[
len
]
=
0
;
}
else
{
if
(
varDataLen
(
input
)
>
(
TSDB_MAX_JSON_TAG_LEN
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
){
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
memcpy
(
tmp
,
varDataVal
(
input
),
varDataLen
(
input
));
tmp
[
varDataTLen
(
input
)]
=
0
;
}
if
(
!
tjsonValidateJson
(
tmp
)){
colDataAppendNULL
(
pOutput
->
columnData
,
i
);
continue
;
}
colDataAppend
(
pOutput
->
columnData
,
i
,
input
,
false
);
input
+=
varDataTLen
(
input
);
}
taosMemoryFree
(
tmp
);
pOutput
->
numOfRows
=
pInput
->
numOfRows
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
timeTruncateFunction
(
SScalarParam
*
pInput
,
int32_t
inputNum
,
SScalarParam
*
pOutput
)
{
int32_t
type
=
GET_PARAM_TYPE
(
&
pInput
[
0
]);
int32_t
timePrec
=
GET_PARAM_PRECISON
(
&
pInput
[
0
]);
...
...
source/libs/scalar/src/sclvector.c
浏览文件 @
d4734eb1
此差异已折叠。
点击以展开。
source/libs/scalar/test/scalar/CMakeLists.txt
浏览文件 @
d4734eb1
...
...
@@ -8,11 +8,12 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
ADD_EXECUTABLE
(
scalarTest
${
SOURCE_LIST
}
)
TARGET_LINK_LIBRARIES
(
scalarTest
PUBLIC os util common gtest qcom function nodes scalar
PUBLIC os util common gtest qcom function nodes scalar
parser
)
TARGET_INCLUDE_DIRECTORIES
(
scalarTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/scalar/"
PUBLIC
"
${
TD_SOURCE_DIR
}
/source/libs/parser/inc"
PRIVATE
"
${
TD_SOURCE_DIR
}
/source/libs/scalar/inc"
)
source/libs/scalar/test/scalar/scalarTests.cpp
浏览文件 @
d4734eb1
...
...
@@ -38,6 +38,7 @@
#include "scalar.h"
#include "nodes.h"
#include "tlog.h"
#include "parUtil.h"
#define _DEBUG_PRINT_ 0
...
...
@@ -92,6 +93,7 @@ void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *s
blockDataEnsureCapacity
(
res
,
rows
);
*
dataBlockId
=
taosArrayGetSize
(
pBlockList
)
-
1
;
res
->
info
.
blockId
=
*
dataBlockId
;
*
slotId
=
0
;
}
else
{
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
pBlockList
);
...
...
@@ -909,6 +911,264 @@ TEST(constantTest, greater_and_lower) {
nodesDestroyNode
(
res
);
}
void
makeJsonArrow
(
SSDataBlock
**
src
,
SNode
**
opNode
,
void
*
json
,
char
*
key
){
char
keyVar
[
32
]
=
{
0
};
memcpy
(
varDataVal
(
keyVar
),
key
,
strlen
(
key
));
varDataLen
(
keyVar
)
=
strlen
(
key
);
SNode
*
pLeft
=
NULL
,
*
pRight
=
NULL
;
scltMakeValueNode
(
&
pRight
,
TSDB_DATA_TYPE_BINARY
,
keyVar
);
scltMakeColumnNode
(
&
pLeft
,
src
,
TSDB_DATA_TYPE_JSON
,
varDataLen
(
json
),
1
,
json
);
scltMakeOpNode
(
opNode
,
OP_TYPE_JSON_GET_VALUE
,
TSDB_DATA_TYPE_JSON
,
pLeft
,
pRight
);
}
void
makeOperator
(
SNode
**
opNode
,
SArray
*
blockList
,
EOperatorType
opType
,
int32_t
rightType
,
void
*
rightData
){
int32_t
resType
=
TSDB_DATA_TYPE_NULL
;
if
(
opType
==
OP_TYPE_ADD
||
opType
==
OP_TYPE_SUB
||
opType
==
OP_TYPE_MULTI
||
opType
==
OP_TYPE_DIV
||
opType
==
OP_TYPE_MOD
||
opType
==
OP_TYPE_MINUS
){
resType
=
TSDB_DATA_TYPE_DOUBLE
;
}
else
if
(
opType
==
OP_TYPE_BIT_AND
||
opType
==
OP_TYPE_BIT_OR
){
resType
=
TSDB_DATA_TYPE_BIGINT
;
}
else
if
(
opType
==
OP_TYPE_GREATER_THAN
||
opType
==
OP_TYPE_GREATER_EQUAL
||
opType
==
OP_TYPE_LOWER_THAN
||
opType
==
OP_TYPE_LOWER_EQUAL
||
opType
==
OP_TYPE_EQUAL
||
opType
==
OP_TYPE_NOT_EQUAL
||
opType
==
OP_TYPE_IS_NULL
||
opType
==
OP_TYPE_IS_NOT_NULL
||
opType
==
OP_TYPE_IS_TRUE
||
opType
==
OP_TYPE_LIKE
||
opType
==
OP_TYPE_NOT_LIKE
||
opType
==
OP_TYPE_MATCH
||
opType
==
OP_TYPE_NMATCH
){
resType
=
TSDB_DATA_TYPE_BOOL
;
}
SNode
*
right
=
NULL
;
scltMakeValueNode
(
&
right
,
rightType
,
rightData
);
scltMakeOpNode
(
opNode
,
opType
,
resType
,
*
opNode
,
right
);
SColumnInfo
colInfo
=
createColumnInfo
(
1
,
resType
,
tDataTypes
[
resType
].
bytes
);
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
true
,
1
,
&
colInfo
);
scltMakeTargetNode
(
opNode
,
dataBlockId
,
slotId
,
*
opNode
);
}
void
makeCalculate
(
void
*
json
,
void
*
key
,
int32_t
rightType
,
void
*
rightData
,
double
exceptValue
,
EOperatorType
opType
){
SArray
*
blockList
=
taosArrayInit
(
2
,
POINTER_BYTES
);
SSDataBlock
*
src
=
NULL
;
SNode
*
opNode
=
NULL
;
makeJsonArrow
(
&
src
,
&
opNode
,
json
,
(
char
*
)
key
);
taosArrayPush
(
blockList
,
&
src
);
makeOperator
(
&
opNode
,
blockList
,
opType
,
rightType
,
rightData
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
ASSERT_EQ
(
code
,
0
);
SSDataBlock
*
res
=
*
(
SSDataBlock
**
)
taosArrayGetLast
(
blockList
);
ASSERT_EQ
(
res
->
info
.
rows
,
1
);
SColumnInfoData
*
column
=
(
SColumnInfoData
*
)
taosArrayGetLast
(
res
->
pDataBlock
);
if
(
colDataIsNull_f
(
column
->
nullbitmap
,
0
)){
ASSERT_EQ
(
DBL_MAX
,
exceptValue
);
printf
(
"result:NULL
\n
"
);
}
else
if
(
opType
==
OP_TYPE_ADD
||
opType
==
OP_TYPE_SUB
||
opType
==
OP_TYPE_MULTI
||
opType
==
OP_TYPE_DIV
||
opType
==
OP_TYPE_MOD
||
opType
==
OP_TYPE_MINUS
){
double
tmp
=
*
((
double
*
)
colDataGetData
(
column
,
0
));
ASSERT_TRUE
(
tmp
==
exceptValue
);
printf
(
"result:%lf
\n
"
,
tmp
);
}
else
if
(
opType
==
OP_TYPE_BIT_AND
||
opType
==
OP_TYPE_BIT_OR
){
ASSERT_EQ
(
*
((
int64_t
*
)
colDataGetData
(
column
,
0
)),
exceptValue
);
printf
(
"result:%ld
\n
"
,
*
((
int64_t
*
)
colDataGetData
(
column
,
0
)));
}
else
if
(
opType
==
OP_TYPE_GREATER_THAN
||
opType
==
OP_TYPE_GREATER_EQUAL
||
opType
==
OP_TYPE_LOWER_THAN
||
opType
==
OP_TYPE_LOWER_EQUAL
||
opType
==
OP_TYPE_EQUAL
||
opType
==
OP_TYPE_NOT_EQUAL
||
opType
==
OP_TYPE_IS_NULL
||
opType
==
OP_TYPE_IS_NOT_NULL
||
opType
==
OP_TYPE_IS_TRUE
||
opType
==
OP_TYPE_LIKE
||
opType
==
OP_TYPE_NOT_LIKE
||
opType
==
OP_TYPE_MATCH
||
opType
==
OP_TYPE_NMATCH
){
ASSERT_EQ
(
*
((
bool
*
)
colDataGetData
(
column
,
0
)),
exceptValue
);
printf
(
"result:%d
\n
"
,
*
((
bool
*
)
colDataGetData
(
column
,
0
)));
}
taosArrayDestroyEx
(
blockList
,
scltFreeDataBlock
);
nodesDestroyNode
(
opNode
);
}
TEST
(
columnTest
,
json_column_arith_op
)
{
scltInitLogFile
();
char
*
rightv
=
"{
\"
k1
\"
:4,
\"
k2
\"
:
\"
hello
\"
,
\"
k3
\"
:null,
\"
k4
\"
:true,
\"
k5
\"
:5.44}"
;
SKVRowBuilder
kvRowBuilder
;
tdInitKVRowBuilder
(
&
kvRowBuilder
);
parseJsontoTagData
(
rightv
,
&
kvRowBuilder
,
NULL
,
0
);
SKVRow
row
=
tdGetKVRowFromBuilder
(
&
kvRowBuilder
);
const
int32_t
len
=
8
;
EOperatorType
op
[
len
]
=
{
OP_TYPE_ADD
,
OP_TYPE_SUB
,
OP_TYPE_MULTI
,
OP_TYPE_DIV
,
OP_TYPE_MOD
,
OP_TYPE_MINUS
,
OP_TYPE_BIT_AND
,
OP_TYPE_BIT_OR
};
int32_t
input
[
len
]
=
{
1
,
8
,
2
,
2
,
3
,
0
,
-
4
,
9
};
printf
(
"--------------------json int---------------------
\n
"
);
char
*
key
=
"k1"
;
double
eRes
[
len
]
=
{
5.0
,
-
4
,
8.0
,
2.0
,
1.0
,
-
4
,
4
&-
4
,
4
|
9
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes
[
i
],
op
[
i
]);
}
printf
(
"--------------------json string---------------------
\n
"
);
key
=
"k2"
;
double
eRes1
[
len
]
=
{
1.0
,
-
8
,
0
,
0
,
0
,
0
,
0
,
9
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes1
[
i
],
op
[
i
]);
}
printf
(
"---------------------json null--------------------
\n
"
);
key
=
"k3"
;
double
eRes2
[
len
]
=
{
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes2
[
i
],
op
[
i
]);
}
printf
(
"---------------------json bool--------------------
\n
"
);
key
=
"k4"
;
double
eRes3
[
len
]
=
{
2.0
,
-
7
,
2
,
0.5
,
1
,
-
1
,
1
&-
4
,
1
|
9
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes3
[
i
],
op
[
i
]);
}
printf
(
"----------------------json double-------------------
\n
"
);
key
=
"k5"
;
double
eRes4
[
len
]
=
{
6.44
,
-
2.56
,
10.88
,
2.72
,
2.44
,
-
5.44
,
5
&-
4
,
5
|
9
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes4
[
i
],
op
[
i
]);
}
printf
(
"---------------------json not exist--------------------
\n
"
);
key
=
"k10"
;
double
eRes5
[
len
]
=
{
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes5
[
i
],
op
[
i
]);
}
}
void
*
prepareNchar
(
char
*
rightData
){
int32_t
len
=
0
;
int32_t
inputLen
=
strlen
(
rightData
);
char
*
t
=
(
char
*
)
taosMemoryCalloc
(
1
,(
inputLen
+
1
)
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
);
taosMbsToUcs4
(
rightData
,
inputLen
,
(
TdUcs4
*
)
varDataVal
(
t
),
inputLen
*
TSDB_NCHAR_SIZE
,
&
len
);
varDataSetLen
(
t
,
len
);
return
t
;
}
TEST
(
columnTest
,
json_column_logic_op
)
{
scltInitLogFile
();
char
*
rightv
=
"{
\"
k1
\"
:4,
\"
k2
\"
:
\"
hello
\"
,
\"
k3
\"
:null,
\"
k4
\"
:true,
\"
k5
\"
:5.44,
\"
k6
\"
:
\"
6.6hello
\"
}"
;
SKVRowBuilder
kvRowBuilder
;
tdInitKVRowBuilder
(
&
kvRowBuilder
);
parseJsontoTagData
(
rightv
,
&
kvRowBuilder
,
NULL
,
0
);
SKVRow
row
=
tdGetKVRowFromBuilder
(
&
kvRowBuilder
);
const
int32_t
len
=
9
;
const
int32_t
len1
=
4
;
EOperatorType
op
[
len
+
len1
]
=
{
OP_TYPE_GREATER_THAN
,
OP_TYPE_GREATER_EQUAL
,
OP_TYPE_LOWER_THAN
,
OP_TYPE_LOWER_EQUAL
,
OP_TYPE_EQUAL
,
OP_TYPE_NOT_EQUAL
,
OP_TYPE_IS_NULL
,
OP_TYPE_IS_NOT_NULL
,
OP_TYPE_IS_TRUE
,
OP_TYPE_LIKE
,
OP_TYPE_NOT_LIKE
,
OP_TYPE_MATCH
,
OP_TYPE_NMATCH
};
int32_t
input
[
len
]
=
{
1
,
8
,
2
,
2
,
3
,
0
,
0
,
0
,
0
};
char
*
inputNchar
[
len1
]
=
{
"hell_"
,
"hel%"
,
"hell"
,
"llll"
};
printf
(
"--------------------json int---------------------
\n
"
);
char
*
key
=
"k1"
;
bool
eRes
[
len
+
len1
]
=
{
true
,
false
,
false
,
false
,
false
,
true
,
false
,
true
,
true
,
false
,
false
,
false
,
false
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes
[
i
],
op
[
i
]);
}
for
(
int
i
=
len
;
i
<
len
+
len1
;
i
++
){
void
*
rightData
=
prepareNchar
(
inputNchar
[
i
-
len
]);
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_NCHAR
,
rightData
,
eRes
[
i
],
op
[
i
]);
taosMemoryFree
(
rightData
);
}
printf
(
"--------------------json string---------------------
\n
"
);
key
=
"k2"
;
bool
eRes1
[
len
+
len1
]
=
{
false
,
false
,
true
,
true
,
false
,
false
,
false
,
true
,
false
,
true
,
false
,
true
,
true
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes1
[
i
],
op
[
i
]);
}
for
(
int
i
=
len
;
i
<
len
+
len1
;
i
++
){
void
*
rightData
=
prepareNchar
(
inputNchar
[
i
-
len
]);
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_NCHAR
,
rightData
,
eRes1
[
i
],
op
[
i
]);
taosMemoryFree
(
rightData
);
}
printf
(
"--------------------json null---------------------
\n
"
);
key
=
"k3"
;
double
eRes2
[
len
+
len1
]
=
{
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
true
,
false
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes2
[
i
],
op
[
i
]);
}
for
(
int
i
=
len
;
i
<
len
+
len1
;
i
++
){
void
*
rightData
=
prepareNchar
(
inputNchar
[
i
-
len
]);
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_NCHAR
,
rightData
,
eRes2
[
i
],
op
[
i
]);
taosMemoryFree
(
rightData
);
}
printf
(
"--------------------json bool---------------------
\n
"
);
key
=
"k4"
;
bool
eRes3
[
len
+
len1
]
=
{
false
,
false
,
true
,
true
,
false
,
true
,
false
,
true
,
true
,
false
,
false
,
false
,
false
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes3
[
i
],
op
[
i
]);
}
for
(
int
i
=
len
;
i
<
len
+
len1
;
i
++
){
void
*
rightData
=
prepareNchar
(
inputNchar
[
i
-
len
]);
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_NCHAR
,
rightData
,
eRes3
[
i
],
op
[
i
]);
taosMemoryFree
(
rightData
);
}
printf
(
"--------------------json double---------------------
\n
"
);
key
=
"k5"
;
bool
eRes4
[
len
+
len1
]
=
{
true
,
false
,
false
,
false
,
false
,
true
,
false
,
true
,
true
,
false
,
false
,
false
,
false
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes4
[
i
],
op
[
i
]);
}
for
(
int
i
=
len
;
i
<
len
+
len1
;
i
++
){
void
*
rightData
=
prepareNchar
(
inputNchar
[
i
-
len
]);
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_NCHAR
,
rightData
,
eRes4
[
i
],
op
[
i
]);
taosMemoryFree
(
rightData
);
}
printf
(
"--------------------json double---------------------
\n
"
);
key
=
"k6"
;
bool
eRes5
[
len
+
len1
]
=
{
true
,
false
,
false
,
false
,
false
,
true
,
false
,
true
,
true
,
false
,
false
,
false
,
true
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes5
[
i
],
op
[
i
]);
}
for
(
int
i
=
len
;
i
<
len
+
len1
;
i
++
){
void
*
rightData
=
prepareNchar
(
inputNchar
[
i
-
len
]);
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_NCHAR
,
rightData
,
eRes5
[
i
],
op
[
i
]);
taosMemoryFree
(
rightData
);
}
printf
(
"---------------------json not exist--------------------
\n
"
);
key
=
"k10"
;
double
eRes10
[
len
+
len1
]
=
{
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
true
,
false
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
,
DBL_MAX
};
for
(
int
i
=
0
;
i
<
len
;
i
++
){
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_INT
,
&
input
[
i
],
eRes10
[
i
],
op
[
i
]);
}
for
(
int
i
=
len
;
i
<
len
+
len1
;
i
++
){
void
*
rightData
=
prepareNchar
(
inputNchar
[
i
-
len
]);
makeCalculate
(
row
,
key
,
TSDB_DATA_TYPE_NCHAR
,
rightData
,
eRes10
[
i
],
op
[
i
]);
taosMemoryFree
(
rightData
);
}
}
TEST
(
columnTest
,
smallint_value_add_int_column
)
{
scltInitLogFile
();
...
...
@@ -928,7 +1188,7 @@ TEST(columnTest, smallint_value_add_int_column) {
int16_t
dataBlockId
=
0
,
slotId
=
0
;
scltAppendReservedSlot
(
blockList
,
&
dataBlockId
,
&
slotId
,
true
,
rowNum
,
&
colInfo
);
scltMakeTargetNode
(
&
opNode
,
dataBlockId
,
slotId
,
opNode
);
int32_t
code
=
scalarCalculate
(
opNode
,
blockList
,
NULL
);
ASSERT_EQ
(
code
,
0
);
...
...
@@ -3097,3 +3357,4 @@ int main(int argc, char** argv) {
}
#pragma GCC diagnostic pop
source/os/src/osFile.c
浏览文件 @
d4734eb1
...
...
@@ -38,7 +38,7 @@ extern int openU(const char *, int, ...); /* MsvcLibX UTF-8 version of open */
#include <sys/file.h>
#if !defined(_TD_DARWIN_64)
#include <sys/sendfile.h>
#include <sys/sendfile.h>
#endif
#include <sys/stat.h>
#include <unistd.h>
...
...
@@ -58,9 +58,9 @@ typedef int32_t FileFd;
typedef
struct
TdFile
{
TdThreadRwlock
rwlock
;
int
refId
;
FileFd
fd
;
FILE
*
fp
;
int
refId
;
FileFd
fd
;
FILE
*
fp
;
}
*
TdFilePtr
,
TdFile
;
#define FILE_WITH_LOCK 1
...
...
@@ -182,7 +182,7 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
return
0
;
#else
struct
stat
fileStat
;
int32_t
code
=
stat
(
path
,
&
fileStat
);
int32_t
code
=
stat
(
path
,
&
fileStat
);
if
(
code
<
0
)
{
return
code
;
}
...
...
@@ -203,7 +203,7 @@ int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno) {
return
0
;
#else
struct
stat
fileStat
;
int32_t
code
=
stat
(
path
,
&
fileStat
);
int32_t
code
=
stat
(
path
,
&
fileStat
);
if
(
code
<
0
)
{
return
code
;
}
...
...
@@ -226,7 +226,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
NULL
;
#else
int
fd
=
-
1
;
int
fd
=
-
1
;
FILE
*
fp
=
NULL
;
if
(
tdFileOptions
&
TD_FILE_STREAM
)
{
char
*
mode
=
NULL
;
...
...
@@ -325,7 +325,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
#if FILE_WITH_LOCK
taosThreadRwlockRdlock
(
&
(
pFile
->
rwlock
));
#endif
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
int64_t
leftbytes
=
count
;
int64_t
readbytes
;
char
*
tbuf
=
(
char
*
)
buf
;
...
...
@@ -365,7 +365,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
#if FILE_WITH_LOCK
taosThreadRwlockRdlock
(
&
(
pFile
->
rwlock
));
#endif
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
int64_t
ret
=
pread
(
pFile
->
fd
,
buf
,
count
,
offset
);
#if FILE_WITH_LOCK
taosThreadRwlockUnlock
(
&
(
pFile
->
rwlock
));
...
...
@@ -380,7 +380,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
#if FILE_WITH_LOCK
taosThreadRwlockWrlock
(
&
(
pFile
->
rwlock
));
#endif
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
/*assert(pFile->fd >= 0); // Please check if you have closed the file.*/
int64_t
nleft
=
count
;
int64_t
nwritten
=
0
;
...
...
@@ -414,7 +414,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
#if FILE_WITH_LOCK
taosThreadRwlockRdlock
(
&
(
pFile
->
rwlock
));
#endif
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
int64_t
ret
=
lseek
(
pFile
->
fd
,
(
long
)
offset
,
whence
);
#if FILE_WITH_LOCK
taosThreadRwlockUnlock
(
&
(
pFile
->
rwlock
));
...
...
@@ -429,10 +429,10 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
if
(
pFile
==
NULL
)
{
return
0
;
}
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
struct
stat
fileStat
;
int32_t
code
=
fstat
(
pFile
->
fd
,
&
fileStat
);
int32_t
code
=
fstat
(
pFile
->
fd
,
&
fileStat
);
if
(
code
<
0
)
{
return
code
;
}
...
...
@@ -456,7 +456,7 @@ int32_t taosLockFile(TdFilePtr pFile) {
if
(
pFile
==
NULL
)
{
return
0
;
}
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
return
(
int32_t
)
flock
(
pFile
->
fd
,
LOCK_EX
|
LOCK_NB
);
#endif
...
...
@@ -469,7 +469,7 @@ int32_t taosUnLockFile(TdFilePtr pFile) {
if
(
pFile
==
NULL
)
{
return
0
;
}
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
return
(
int32_t
)
flock
(
pFile
->
fd
,
LOCK_UN
|
LOCK_NB
);
#endif
...
...
@@ -529,7 +529,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
if
(
pFile
==
NULL
)
{
return
0
;
}
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
return
ftruncate
(
pFile
->
fd
,
l_size
);
#endif
...
...
@@ -637,7 +637,7 @@ int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t co
}
off_t
len
=
count
;
while
(
len
>
0
)
{
char
buf
[
1024
*
16
];
char
buf
[
1024
*
16
];
off_t
n
=
sizeof
(
buf
);
if
(
len
<
n
)
n
=
len
;
size_t
m
=
fread
(
buf
,
1
,
n
,
in_file
);
...
...
@@ -662,7 +662,7 @@ int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t count) {
}
off_t
len
=
count
;
while
(
len
>
0
)
{
char
buf
[
1024
*
16
];
char
buf
[
1024
*
16
];
off_t
n
=
sizeof
(
buf
);
if
(
len
<
n
)
n
=
len
;
size_t
m
=
read
(
sfd
,
buf
,
n
);
...
...
@@ -750,7 +750,7 @@ void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) {
if
(
pFile
==
NULL
)
{
return
NULL
;
}
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
assert
(
pFile
->
fd
>=
0
);
// Please check if you have closed the file.
void
*
ptr
=
mmap
(
NULL
,
length
,
PROT_READ
,
MAP_SHARED
,
pFile
->
fd
,
0
);
return
ptr
;
...
...
@@ -811,4 +811,4 @@ bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) {
bool
taosCheckExistFile
(
const
char
*
pathname
)
{
return
taosCheckAccessFile
(
pathname
,
TD_FILE_ACCESS_EXIST_OK
);
};
#endif // WINDOWS
#endif
// WINDOWS
source/util/src/tarray.c
浏览文件 @
d4734eb1
此差异已折叠。
点击以展开。
source/util/src/tcompare.c
浏览文件 @
d4734eb1
...
...
@@ -222,6 +222,11 @@ int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight) {
return
compareLenPrefixedWStr
(
pRight
,
pLeft
);
}
int32_t
compareJsonContainsKey
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
if
(
pLeft
)
return
0
;
return
1
;
}
/*
* Compare two strings
* TSDB_MATCH: Match
...
...
source/util/src/tjson.c
浏览文件 @
d4734eb1
...
...
@@ -276,3 +276,37 @@ int32_t tjsonToArray(const SJson* pJson, const char* pName, FToObject func, void
}
SJson
*
tjsonParse
(
const
char
*
pStr
)
{
return
cJSON_Parse
(
pStr
);
}
bool
tjsonValidateJson
(
const
char
*
jIn
)
{
if
(
!
jIn
){
return
false
;
}
// set json real data
cJSON
*
root
=
cJSON_Parse
(
jIn
);
if
(
root
==
NULL
){
return
false
;
}
if
(
!
cJSON_IsObject
(
root
)){
return
false
;
}
int
size
=
cJSON_GetArraySize
(
root
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
root
,
i
);
if
(
!
item
)
{
return
false
;
}
char
*
jsonKey
=
item
->
string
;
if
(
!
jsonKey
)
return
false
;
for
(
size_t
j
=
0
;
j
<
strlen
(
jsonKey
);
++
i
)
{
if
(
isprint
(
jsonKey
[
i
])
==
0
)
return
false
;
}
if
(
item
->
type
==
cJSON_Object
||
item
->
type
==
cJSON_Array
)
{
return
false
;
}
}
return
true
;
}
\ No newline at end of file
source/util/src/tutil.c
浏览文件 @
d4734eb1
此差异已折叠。
点击以展开。
tests/pytest/insert/binary.py
浏览文件 @
d4734eb1
此差异已折叠。
点击以展开。
tests/script/jenkins/basic.txt
浏览文件 @
d4734eb1
...
...
@@ -93,4 +93,7 @@
# --- sma
./test.sh -f tsim/sma/tsmaCreateInsertData.sim
# --- valgrind
./test.sh -f tsim/valgrind/checkError.sim -v
#======================b1-end===============
tests/script/sh/checkValgrind.sh
0 → 100755
浏览文件 @
d4734eb1
此差异已折叠。
点击以展开。
tests/script/tsim/tmq/basic1.sim
浏览文件 @
d4734eb1
此差异已折叠。
点击以展开。
tests/script/tsim/valgrind/checkError.sim
0 → 100644
浏览文件 @
d4734eb1
此差异已折叠。
点击以展开。
tests/tsim/src/simExe.c
浏览文件 @
d4734eb1
此差异已折叠。
点击以展开。
tools/shell/src/shellEngine.c
浏览文件 @
d4734eb1
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录