Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2d315222
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2d315222
编写于
12月 21, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' into feature/vnode
上级
816a9d93
4e390996
变更
65
展开全部
隐藏空白更改
内联
并排
Showing
65 changed file
with
1736 addition
and
1062 deletion
+1736
-1062
Jenkinsfile
Jenkinsfile
+1
-4
include/common/taosmsg.h
include/common/taosmsg.h
+17
-8
include/common/tmsgtype.h
include/common/tmsgtype.h
+2
-2
include/dnode/vnode/tq/tq.h
include/dnode/vnode/tq/tq.h
+97
-97
include/dnode/vnode/vnode.h
include/dnode/vnode/vnode.h
+2
-2
include/libs/scheduler/scheduler.h
include/libs/scheduler/scheduler.h
+6
-2
include/util/taoserror.h
include/util/taoserror.h
+14
-0
include/util/tlog.h
include/util/tlog.h
+1
-1
include/util/tthread.h
include/util/tthread.h
+2
-2
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+1
-1
source/client/src/clientMsgHandler.c
source/client/src/clientMsgHandler.c
+15
-2
source/client/src/tscEnv.c
source/client/src/tscEnv.c
+0
-1
source/client/test/clientTests.cpp
source/client/test/clientTests.cpp
+43
-17
source/dnode/mgmt/daemon/src/daemon.c
source/dnode/mgmt/daemon/src/daemon.c
+1
-1
source/dnode/mgmt/impl/src/dndTransport.c
source/dnode/mgmt/impl/src/dndTransport.c
+1
-1
source/dnode/mgmt/impl/src/dndVnodes.c
source/dnode/mgmt/impl/src/dndVnodes.c
+210
-154
source/dnode/mgmt/impl/src/dnode.c
source/dnode/mgmt/impl/src/dnode.c
+8
-0
source/dnode/mgmt/impl/test/db/db.cpp
source/dnode/mgmt/impl/test/db/db.cpp
+4
-4
source/dnode/mgmt/impl/test/stb/stb.cpp
source/dnode/mgmt/impl/test/stb/stb.cpp
+2
-2
source/dnode/mgmt/impl/test/sut/deploy.cpp
source/dnode/mgmt/impl/test/sut/deploy.cpp
+1
-1
source/dnode/mgmt/impl/test/vgroup/vgroup.cpp
source/dnode/mgmt/impl/test/vgroup/vgroup.cpp
+102
-39
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+5
-6
source/dnode/mnode/impl/inc/mndInt.h
source/dnode/mnode/impl/inc/mndInt.h
+1
-0
source/dnode/mnode/impl/inc/mndTrans.h
source/dnode/mnode/impl/inc/mndTrans.h
+17
-4
source/dnode/mnode/impl/src/mndAcct.c
source/dnode/mnode/impl/src/mndAcct.c
+7
-8
source/dnode/mnode/impl/src/mndCluster.c
source/dnode/mnode/impl/src/mndCluster.c
+7
-3
source/dnode/mnode/impl/src/mndDb.c
source/dnode/mnode/impl/src/mndDb.c
+198
-123
source/dnode/mnode/impl/src/mndDnode.c
source/dnode/mnode/impl/src/mndDnode.c
+8
-24
source/dnode/mnode/impl/src/mndMnode.c
source/dnode/mnode/impl/src/mndMnode.c
+6
-3
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+115
-93
source/dnode/mnode/impl/src/mndUser.c
source/dnode/mnode/impl/src/mndUser.c
+3
-3
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+42
-19
source/dnode/mnode/impl/src/mnode.c
source/dnode/mnode/impl/src/mnode.c
+4
-1
source/dnode/mnode/sdb/src/sdbRaw.c
source/dnode/mnode/sdb/src/sdbRaw.c
+2
-2
source/dnode/vnode/impl/src/vnodeWrite.c
source/dnode/vnode/impl/src/vnodeWrite.c
+1
-5
source/dnode/vnode/tq/CMakeLists.txt
source/dnode/vnode/tq/CMakeLists.txt
+1
-0
source/dnode/vnode/tq/inc/tqInt.h
source/dnode/vnode/tq/inc/tqInt.h
+10
-1
source/dnode/vnode/tq/inc/tqMetaStore.h
source/dnode/vnode/tq/inc/tqMetaStore.h
+1
-1
source/dnode/vnode/tq/src/tq.c
source/dnode/vnode/tq/src/tq.c
+200
-123
source/dnode/vnode/tq/src/tqMetaStore.c
source/dnode/vnode/tq/src/tqMetaStore.c
+33
-25
source/dnode/vnode/tq/test/tqMetaTest.cpp
source/dnode/vnode/tq/test/tqMetaTest.cpp
+48
-77
source/libs/catalog/test/catalogTests.cpp
source/libs/catalog/test/catalogTests.cpp
+2
-2
source/libs/index/inc/indexInt.h
source/libs/index/inc/indexInt.h
+1
-1
source/libs/index/inc/index_fst_counting_writer.h
source/libs/index/inc/index_fst_counting_writer.h
+10
-4
source/libs/index/inc/index_tfile.h
source/libs/index/inc/index_tfile.h
+60
-2
source/libs/index/inc/index_util.h
source/libs/index/inc/index_util.h
+53
-0
source/libs/index/src/index_cache.c
source/libs/index/src/index_cache.c
+9
-21
source/libs/index/src/index_fst.c
source/libs/index/src/index_fst.c
+1
-1
source/libs/index/src/index_fst_counting_writer.c
source/libs/index/src/index_fst_counting_writer.c
+20
-18
source/libs/index/src/index_tfile.c
source/libs/index/src/index_tfile.c
+58
-0
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+1
-1
source/libs/parser/inc/astToMsg.h
source/libs/parser/inc/astToMsg.h
+2
-1
source/libs/parser/src/astToMsg.c
source/libs/parser/src/astToMsg.c
+22
-5
source/libs/parser/src/astValidate.c
source/libs/parser/src/astValidate.c
+7
-1
source/libs/parser/src/queryInfoUtil.c
source/libs/parser/src/queryInfoUtil.c
+1
-4
source/libs/parser/test/mockCatalogService.cpp
source/libs/parser/test/mockCatalogService.cpp
+3
-3
source/libs/qcom/src/querymsg.c
source/libs/qcom/src/querymsg.c
+1
-1
source/libs/scheduler/CMakeLists.txt
source/libs/scheduler/CMakeLists.txt
+2
-0
source/libs/scheduler/inc/schedulerInt.h
source/libs/scheduler/inc/schedulerInt.h
+2
-3
source/libs/scheduler/src/scheduler.c
source/libs/scheduler/src/scheduler.c
+44
-23
source/libs/scheduler/test/CMakeLists.txt
source/libs/scheduler/test/CMakeLists.txt
+18
-0
source/libs/scheduler/test/schedulerTests.cpp
source/libs/scheduler/test/schedulerTests.cpp
+104
-0
source/util/src/tlog.c
source/util/src/tlog.c
+65
-64
source/util/src/tthread.c
source/util/src/tthread.c
+11
-13
tests/script/general/user/monitor.sim
tests/script/general/user/monitor.sim
+0
-32
未找到文件。
Jenkinsfile
浏览文件 @
2d315222
...
...
@@ -42,7 +42,6 @@ def pre_test(){
killall -9 gdb || echo "no gdb running"
killall -9 python3.8 || echo "no python program running"
cd ${WKC}
git reset --hard HEAD~10 >/dev/null
'''
script
{
if
(
env
.
CHANGE_TARGET
==
'master'
)
{
...
...
@@ -75,11 +74,9 @@ def pre_test(){
git pull >/dev/null
git fetch origin +refs/pull/${CHANGE_ID}/merge
git checkout -qf FETCH_HEAD
git clean -dfx
git clean -dfx
export TZ=Asia/Harbin
date
rm -rf debug
mkdir debug
cd debug
cmake .. > /dev/null
...
...
include/common/taosmsg.h
浏览文件 @
2d315222
...
...
@@ -50,9 +50,8 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONSUME, "mq-consume" )
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_QUERY
,
"mq-query"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_CONNECT
,
"mq-connect"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_DISCONNECT
,
"mq-disconnect"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_SET
,
"mq-set
"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_MQ_SET
_CUR
,
"mq-set-cur
"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_RSP_READY
,
"rsp-ready"
)
// message from client to mnode
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_CONNECT
,
"connect"
)
TAOS_DEFINE_MESSAGE_TYPE
(
TSDB_MSG_TYPE_CREATE_ACCT
,
"create-acct"
)
...
...
@@ -225,6 +224,7 @@ typedef struct SBuildUseDBInput {
int32_t
vgVersion
;
}
SBuildUseDBInput
;
#pragma pack(push, 1)
// null-terminated string instead of char array to avoid too many memory consumption in case of more than 1M tableMeta
...
...
@@ -343,7 +343,7 @@ typedef struct {
typedef
struct
{
char
tableFname
[
TSDB_TABLE_FNAME_LEN
];
char
db
[
TSDB_FULL_DB_NAME_LEN
];
int16_t
type
;
/* operation type */
int16_t
type
;
/* operation type */
int16_t
numOfCols
;
/* number of schema */
int32_t
tagValLen
;
SSchema
schema
[];
...
...
@@ -545,8 +545,8 @@ typedef struct {
int32_t
sqlstrLen
;
// sql query string
int32_t
prevResultLen
;
// previous result length
int32_t
numOfOperator
;
int32_t
tableScanOperator
;
// table scan operator. -1 means no scan operator
int32_t
udfNum
;
// number of udf function
int32_t
tableScanOperator
;
// table scan operator. -1 means no scan operator
int32_t
udfNum
;
// number of udf function
int32_t
udfContentOffset
;
int32_t
udfContentLen
;
SColumnInfo
tableCols
[];
...
...
@@ -591,8 +591,8 @@ typedef struct {
int32_t
daysToKeep0
;
int32_t
daysToKeep1
;
int32_t
daysToKeep2
;
int32_t
minRows
PerFileBlock
;
int32_t
maxRows
PerFileBlock
;
int32_t
minRows
;
int32_t
maxRows
;
int32_t
commitTime
;
int32_t
fsyncPeriod
;
int8_t
walLevel
;
...
...
@@ -706,7 +706,7 @@ typedef struct {
SVnodeLoad
data
[];
}
SVnodeLoads
;
typedef
struct
SStatusMsg
{
typedef
struct
{
int32_t
sver
;
int32_t
dnodeId
;
int32_t
clusterId
;
...
...
@@ -756,6 +756,7 @@ typedef struct {
int32_t
dnodeId
;
char
db
[
TSDB_FULL_DB_NAME_LEN
];
uint64_t
dbUid
;
int32_t
vgVersion
;
int32_t
cacheBlockSize
;
int32_t
totalBlocks
;
int32_t
daysPerFile
;
...
...
@@ -1005,27 +1006,35 @@ typedef struct {
// mq related
typedef
struct
{
}
SMqConnectReq
;
typedef
struct
{
}
SMqConnectRsp
;
typedef
struct
{
}
SMqDisconnectReq
;
typedef
struct
{
}
SMqDisconnectRsp
;
typedef
struct
{
}
SMqAckReq
;
typedef
struct
{
}
SMqAckRsp
;
typedef
struct
{
}
SMqResetReq
;
typedef
struct
{
}
SMqResetRsp
;
// mq related end
...
...
include/common/tmsgtype.h
浏览文件 @
2d315222
...
...
@@ -35,7 +35,7 @@ enum {
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_SELECT
,
"select"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_FETCH
,
"fetch"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_INSERT
,
"insert"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_UPDATE_TAG
S
_VAL
,
"update-tag-val"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_UPDATE_TAG_VAL
,
"update-tag-val"
)
// the SQL below is for mgmt node
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_MGMT
,
"mgmt"
)
...
...
@@ -54,7 +54,7 @@ enum {
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_ALTER_TABLE
,
"alter-table"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_ALTER_DB
,
"alter-db"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_SYNC_DB_REPLICA
,
"sync db-replica"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_SYNC_DB_REPLICA
,
"sync db-replica"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_CREATE_MNODE
,
"create-mnode"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_DROP_MNODE
,
"drop-mnode"
)
TSDB_DEFINE_SQL_TYPE
(
TSDB_SQL_CREATE_DNODE
,
"create-dnode"
)
...
...
include/dnode/vnode/tq/tq.h
浏览文件 @
2d315222
...
...
@@ -16,86 +16,76 @@
#ifndef _TD_TQ_H_
#define _TD_TQ_H_
#include "common.h"
#include "mallocator.h"
#include "os.h"
#include "taoserror.h"
#include "taosmsg.h"
#include "tlist.h"
#include "tutil.h"
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
Tm
qMsgHead
{
typedef
struct
ST
qMsgHead
{
int32_t
protoVer
;
int32_t
msgType
;
int64_t
cgId
;
int64_t
clientId
;
}
Tm
qMsgHead
;
}
ST
qMsgHead
;
typedef
struct
Tm
qOneAck
{
typedef
struct
ST
qOneAck
{
int64_t
topicId
;
int64_t
consumeOffset
;
}
Tm
qOneAck
;
}
ST
qOneAck
;
typedef
struct
Tm
qAcks
{
typedef
struct
ST
qAcks
{
int32_t
ackNum
;
// should be sorted
Tm
qOneAck
acks
[];
}
Tm
qAcks
;
ST
qOneAck
acks
[];
}
ST
qAcks
;
// TODO: put msgs into common
typedef
struct
TmqConnectReq
{
TmqMsgHead
head
;
TmqAcks
acks
;
}
TmqConnectReq
;
typedef
struct
TmqConnectRsp
{
TmqMsgHead
head
;
int8_t
status
;
}
TmqConnectRsp
;
typedef
struct
TmqDisconnectReq
{
TmqMsgHead
head
;
}
TmqDiscconectReq
;
typedef
struct
TmqDisconnectRsp
{
TmqMsgHead
head
;
int8_t
status
;
}
TmqDisconnectRsp
;
typedef
struct
STqSetCurReq
{
STqMsgHead
head
;
int64_t
topicId
;
int64_t
offset
;
}
STqSetCurReq
;
typedef
struct
STqConsumeReq
{
Tm
qMsgHead
head
;
Tm
qAcks
acks
;
ST
qMsgHead
head
;
ST
qAcks
acks
;
}
STqConsumeReq
;
typedef
struct
Tm
qMsgContent
{
typedef
struct
ST
qMsgContent
{
int64_t
topicId
;
int64_t
msgLen
;
char
msg
[];
}
Tm
qMsgContent
;
}
ST
qMsgContent
;
typedef
struct
STqConsumeRsp
{
Tm
qMsgHead
head
;
ST
qMsgHead
head
;
int64_t
bodySize
;
Tm
qMsgContent
msgs
[];
ST
qMsgContent
msgs
[];
}
STqConsumeRsp
;
typedef
struct
Tm
qSubscribeReq
{
Tm
qMsgHead
head
;
typedef
struct
ST
qSubscribeReq
{
ST
qMsgHead
head
;
int32_t
topicNum
;
int64_t
topic
[];
}
Tm
qSubscribeReq
;
}
ST
qSubscribeReq
;
typedef
struct
tm
qSubscribeRsp
{
Tm
qMsgHead
head
;
typedef
struct
ST
qSubscribeRsp
{
ST
qMsgHead
head
;
int64_t
vgId
;
char
ep
[
TSDB_EP_LEN
];
// TSDB_EP_LEN
}
Tm
qSubscribeRsp
;
}
ST
qSubscribeRsp
;
typedef
struct
Tm
qHeartbeatReq
{
}
Tm
qHeartbeatReq
;
typedef
struct
ST
qHeartbeatReq
{
}
ST
qHeartbeatReq
;
typedef
struct
Tm
qHeartbeatRsp
{
}
Tm
qHeartbeatRsp
;
typedef
struct
ST
qHeartbeatRsp
{
}
ST
qHeartbeatRsp
;
typedef
struct
STqTopicVhandle
{
int64_t
topicId
;
...
...
@@ -108,48 +98,54 @@ typedef struct STqTopicVhandle {
#define TQ_BUFFER_SIZE 8
typedef
struct
STqExec
{
void
*
runtimeEnv
;
SSDataBlock
*
(
*
exec
)(
void
*
runtimeEnv
);
void
*
(
*
assign
)(
void
*
runtimeEnv
,
SSubmitBlk
*
inputData
);
void
(
*
clear
)(
void
*
runtimeEnv
);
char
*
(
*
serialize
)(
struct
STqExec
*
);
struct
STqExec
*
(
*
deserialize
)(
char
*
);
}
STqExec
;
typedef
struct
STqBufferItem
{
int64_t
offset
;
// executors are identical but not concurrent
// so there must be a copy in each item
void
*
executor
;
int64_t
size
;
void
*
content
;
}
STqBufferItem
;
STqExec
*
executor
;
int32_t
status
;
int64_t
size
;
void
*
content
;
}
STqMsgItem
;
typedef
struct
STq
BufferHandle
{
typedef
struct
STq
Topic
{
// char* topic; //c style, end with '\0'
// int64_t cgId;
// void* ahandle;
int64_t
nextConsumeOffset
;
int64_t
floatingCursor
;
int64_t
topicId
;
int32_t
head
;
int32_t
tail
;
STq
Buffer
Item
buffer
[
TQ_BUFFER_SIZE
];
}
STq
BufferHandle
;
int64_t
nextConsumeOffset
;
int64_t
floatingCursor
;
int64_t
topicId
;
int32_t
head
;
int32_t
tail
;
STq
Msg
Item
buffer
[
TQ_BUFFER_SIZE
];
}
STq
Topic
;
typedef
struct
STqListHandle
{
STq
BufferHandle
bufHandle
;
STq
Topic
topic
;
struct
STqListHandle
*
next
;
}
STqListHandle
;
typedef
struct
STqGroupHandle
{
int64_t
cId
;
int64_t
cgId
;
void
*
ahandle
;
int32_t
topicNum
;
STqListHandle
*
head
;
}
STqGroupHandle
;
typedef
struct
STqQueryExec
{
void
*
src
;
STqBufferItem
*
dest
;
void
*
executor
;
}
STqQueryExec
;
}
STqList
;
typedef
struct
STqGroup
{
int64_t
clientId
;
int64_t
cgId
;
void
*
ahandle
;
int32_t
topicNum
;
STqList
*
head
;
SList
*
topicList
;
// SList<STqTopic>
void
*
returnMsg
;
// SVReadMsg
}
STqGroup
;
typedef
struct
STqQueryMsg
{
STq
QueryExec
*
exec
;
STq
MsgItem
*
item
;
struct
STqQueryMsg
*
next
;
}
STqQueryMsg
;
...
...
@@ -209,15 +205,15 @@ typedef void (*FTqDelete)(void*);
#define TQ_DUP_INTXN_REWRITE 0
#define TQ_DUP_INTXN_REJECT 2
static
inline
bool
T
qUpdateAppend
(
int32_t
tqConfigFlag
)
{
return
tqConfigFlag
&
TQ_UPDATE_APPEND
;
}
static
inline
bool
t
qUpdateAppend
(
int32_t
tqConfigFlag
)
{
return
tqConfigFlag
&
TQ_UPDATE_APPEND
;
}
static
inline
bool
T
qDupIntxnReject
(
int32_t
tqConfigFlag
)
{
return
tqConfigFlag
&
TQ_DUP_INTXN_REJECT
;
}
static
inline
bool
t
qDupIntxnReject
(
int32_t
tqConfigFlag
)
{
return
tqConfigFlag
&
TQ_DUP_INTXN_REJECT
;
}
static
const
int8_t
TQ_CONST_DELETE
=
TQ_ACTION_CONST
;
#define TQ_DELETE_TOKEN (void*)&TQ_CONST_DELETE
typedef
struct
TqMetaHandle
{
typedef
struct
S
TqMetaHandle
{
int64_t
key
;
int64_t
offset
;
int64_t
serializedSize
;
...
...
@@ -225,23 +221,25 @@ typedef struct TqMetaHandle {
void
*
valueInTxn
;
}
STqMetaHandle
;
typedef
struct
TqMetaList
{
STqMetaHandle
handle
;
struct
TqMetaList
*
next
;
// struct TqMetaList* inTxnPrev;
// struct TqMetaList* inTxnNext;
struct
TqMetaList
*
unpersistPrev
;
struct
TqMetaList
*
unpersistNext
;
typedef
struct
S
TqMetaList
{
STqMetaHandle
handle
;
struct
S
TqMetaList
*
next
;
// struct
S
TqMetaList* inTxnPrev;
// struct
S
TqMetaList* inTxnNext;
struct
S
TqMetaList
*
unpersistPrev
;
struct
S
TqMetaList
*
unpersistNext
;
}
STqMetaList
;
typedef
struct
TqMetaStore
{
typedef
struct
S
TqMetaStore
{
STqMetaList
*
bucket
[
TQ_BUCKET_SIZE
];
// a table head
STqMetaList
*
unpersistHead
;
// TODO:temporaral use, to be replaced by unified tfile
int
fileFd
;
// TODO:temporaral use, to be replaced by unified tfile
int
idxFd
;
int
idxFd
;
char
*
dirPath
;
int32_t
tqConfigFlag
;
FTqSerialize
pSerializer
;
...
...
@@ -250,8 +248,8 @@ typedef struct TqMetaStore {
}
STqMetaStore
;
typedef
struct
STQ
{
// the collection of group
handle
// the handle of kvstore
// the collection of group
s
// the handle of
meta
kvstore
char
*
path
;
STqCfg
*
tqConfig
;
STqLogReader
*
tqLogReader
;
...
...
@@ -266,23 +264,25 @@ void tqClose(STQ*);
// void* will be replace by a msg type
int
tqPushMsg
(
STQ
*
,
void
*
msg
,
int64_t
version
);
int
tqCommit
(
STQ
*
);
int
tqSetCursor
(
STQ
*
,
void
*
msg
);
int
tqConsume
(
STQ
*
,
STqConsumeReq
*
);
STqGroupHandle
*
tqGetGroupHandle
(
STQ
*
,
int64_t
cId
);
int
tqSetCursor
(
STQ
*
,
STqSetCurReq
*
pMsg
);
int
tqBufferSetOffset
(
STqTopic
*
,
int64_t
offset
);
STqTopic
*
tqFindTopic
(
STqGroup
*
,
int64_t
topicId
);
STqGroup
*
tqGetGroup
(
STQ
*
,
int64_t
clientId
);
STqGroup
*
tqOpenGroup
(
STQ
*
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
);
int
tqCloseGroup
(
STQ
*
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
);
int
tqRegisterContext
(
STqGroup
*
,
void
*
ahandle
);
int
tqSendLaunchQuery
(
STqMsgItem
*
,
int64_t
offset
);
STqGroupHandle
*
tqOpenTCGroup
(
STQ
*
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
);
int
tqCloseTCGroup
(
STQ
*
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
);
int
tqMoveOffsetToNext
(
STqGroupHandle
*
);
int
tqResetOffset
(
STQ
*
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
offset
);
int
tqRegisterContext
(
STqGroupHandle
*
,
void
*
ahandle
);
int
tqLaunchQuery
(
STqGroupHandle
*
);
int
tqSendLaunchQuery
(
STqGroupHandle
*
);
int
tqSerializeGroup
(
const
STqGroup
*
,
STqSerializedHead
**
);
int
tqSerializeGroupHandle
(
const
STqGroupHandle
*
gHandle
,
STqSerializedHead
**
ppHead
);
const
void
*
tqDeserializeGroup
(
const
STqSerializedHead
*
,
STqGroup
**
);
const
void
*
tqDeserializeGroupHandle
(
const
STqSerializedHead
*
pHead
,
STqGroupHandle
**
gHandle
);
static
int
tqQueryExecuting
(
int32_t
status
)
{
return
status
;
}
#ifdef __cplusplus
}
...
...
include/dnode/vnode/vnode.h
浏览文件 @
2d315222
...
...
@@ -197,8 +197,8 @@ void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type);
// int32_t daysToKeep0;
// int32_t daysToKeep1;
// int32_t daysToKeep2;
// int32_t minRows
PerFileBlock
;
// int32_t maxRows
PerFileBlock
;
// int32_t minRows;
// int32_t maxRows;
// int8_t precision; // time resolution
// int8_t compression;
// int8_t cacheLastRow;
...
...
include/libs/scheduler/scheduler.h
浏览文件 @
2d315222
...
...
@@ -50,13 +50,15 @@ typedef struct SQueryProfileSummary {
uint64_t
resultSize
;
// generated result size in Kb.
}
SQueryProfileSummary
;
int32_t
schedulerInit
(
SSchedulerCfg
*
cfg
);
/**
* Process the query job, generated according to the query physical plan.
* This is a synchronized API, and is also thread-safety.
* @param
pJob
* @param
qnodeList Qnode address list, element is SEpAddr
* @return
*/
int32_t
schedule
QueryJob
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
SQueryDag
*
pDag
,
void
**
pJob
);
int32_t
schedule
ExecJob
(
void
*
transport
,
SArray
*
qnodeList
,
SQueryDag
*
pDag
,
void
**
pJob
);
int32_t
scheduleFetchRows
(
void
*
pJob
,
void
**
data
);
...
...
@@ -70,6 +72,8 @@ int32_t scheduleCancelJob(void *pJob);
void
scheduleFreeJob
(
void
*
pJob
);
void
schedulerDestroy
(
void
);
#ifdef __cplusplus
}
#endif
...
...
include/util/taoserror.h
浏览文件 @
2d315222
...
...
@@ -339,6 +339,20 @@ int32_t* taosGetErrno();
#define TSDB_CODE_SYN_INVALID_MSGLEN TAOS_DEF_ERROR_CODE(0, 0x0909) //"Invalid msg length")
#define TSDB_CODE_SYN_INVALID_MSGTYPE TAOS_DEF_ERROR_CODE(0, 0x090A) //"Invalid msg type")
// tq
#define TSDB_CODE_TQ_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0A00) //"Invalid configuration")
#define TSDB_CODE_TQ_INIT_FAILED TAOS_DEF_ERROR_CODE(0, 0x0A01) //"Tq init failed")
#define TSDB_CODE_TQ_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x0A02) //"No diskspace for tq")
#define TSDB_CODE_TQ_NO_DISK_PERMISSIONS TAOS_DEF_ERROR_CODE(0, 0x0A03) //"No permission for disk files")
#define TSDB_CODE_TQ_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0A04) //"Data file(s) corrupted")
#define TSDB_CODE_TQ_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0A05) //"Out of memory")
#define TSDB_CODE_TQ_FILE_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0A06) //"File already exists")
#define TSDB_CODE_TQ_FAILED_TO_CREATE_DIR TAOS_DEF_ERROR_CODE(0, 0x0A07) //"Failed to create dir")
#define TSDB_CODE_TQ_META_NO_SUCH_KEY TAOS_DEF_ERROR_CODE(0, 0x0A08) //"Target key not found")
#define TSDB_CODE_TQ_META_KEY_NOT_IN_TXN TAOS_DEF_ERROR_CODE(0, 0x0A09) //"Target key not in transaction")
#define TSDB_CODE_TQ_META_KEY_DUP_IN_TXN TAOS_DEF_ERROR_CODE(0, 0x0A0A) //"Target key duplicated in transaction")
#define TSDB_CODE_TQ_GROUP_NOT_SET TAOS_DEF_ERROR_CODE(0, 0x0A0B) //"Group of corresponding client is not set by mnode")
// wal
#define TSDB_CODE_WAL_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x1000) //"Unexpected generic error in wal")
#define TSDB_CODE_WAL_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x1001) //"WAL file is corrupted")
...
...
include/util/tlog.h
浏览文件 @
2d315222
...
...
@@ -42,11 +42,11 @@ extern int32_t qDebugFlag;
extern
int32_t
wDebugFlag
;
extern
int32_t
sDebugFlag
;
extern
int32_t
tsdbDebugFlag
;
extern
int32_t
tqDebugFlag
;
extern
int32_t
cqDebugFlag
;
extern
int32_t
debugFlag
;
extern
int32_t
ctgDebugFlag
;
#define DEBUG_FATAL 1U
#define DEBUG_ERROR DEBUG_FATAL
#define DEBUG_WARN 2U
...
...
include/util/tthread.h
浏览文件 @
2d315222
...
...
@@ -24,8 +24,8 @@ extern "C" {
#include "tdef.h"
// create new thread
pthread_t
*
taosCreateThread
(
void
*
(
*
__start_routine
)
(
void
*
),
void
*
param
);
// destory thread
pthread_t
*
taosCreateThread
(
void
*
(
*
__start_routine
)(
void
*
),
void
*
param
);
// destory thread
bool
taosDestoryThread
(
pthread_t
*
pthread
);
// thread running return true
bool
taosThreadRunning
(
pthread_t
*
pthread
);
...
...
source/client/src/clientImpl.c
浏览文件 @
2d315222
...
...
@@ -153,7 +153,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
void
*
output
=
NULL
;
int32_t
outputLen
=
0
;
code
=
qParseQuerySql
(
pRequest
->
sqlstr
,
sqlLen
,
pRequest
->
requestId
,
&
type
,
&
output
,
&
outputLen
,
pRequest
->
msgBuf
,
ERROR_MSG_BUF_DEFAULT_SIZE
);
if
(
type
==
TSDB_SQL_CREATE_USER
||
type
==
TSDB_SQL_SHOW
||
type
==
TSDB_SQL_DROP_USER
||
type
==
TSDB_SQL_
CREATE_DB
)
{
if
(
type
==
TSDB_SQL_CREATE_USER
||
type
==
TSDB_SQL_SHOW
||
type
==
TSDB_SQL_DROP_USER
||
type
==
TSDB_SQL_
DROP_ACCT
||
type
==
TSDB_SQL_CREATE_DB
||
type
==
TSDB_SQL_CREATE_ACCT
)
{
pRequest
->
type
=
type
;
pRequest
->
body
.
param
=
output
;
pRequest
->
body
.
paramLen
=
outputLen
;
...
...
source/client/src/clientMsgHandler.c
浏览文件 @
2d315222
...
...
@@ -407,7 +407,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
}
// single table query error need to be handled here.
if ((cmd == TSDB_SQL_SELECT || cmd == TSDB_SQL_UPDATE_TAG
S
_VAL) &&
if ((cmd == TSDB_SQL_SELECT || cmd == TSDB_SQL_UPDATE_TAG_VAL) &&
(((rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID)) ||
rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || rpcMsg->code == TSDB_CODE_APP_NOT_READY)) {
...
...
@@ -3176,6 +3176,15 @@ int32_t doBuildMsgSupp(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) {
case
TSDB_SQL_CREATE_USER
:
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_CREATE_USER
;
break
;
case
TSDB_SQL_DROP_USER
:
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_DROP_USER
;
break
;
case
TSDB_SQL_CREATE_ACCT
:
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_CREATE_ACCT
;
break
;
case
TSDB_SQL_DROP_ACCT
:
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_DROP_ACCT
;
break
;
case
TSDB_SQL_CREATE_DB
:
{
pMsgBody
->
msgType
=
TSDB_MSG_TYPE_CREATE_DB
;
...
...
@@ -3328,7 +3337,7 @@ void initMsgHandleFp() {
tscBuildMsg[TSDB_SQL_DROP_DNODE] = tscBuildDropDnodeMsg;
tscBuildMsg[TSDB_SQL_CFG_DNODE] = tscBuildCfgDnodeMsg;
tscBuildMsg[TSDB_SQL_ALTER_TABLE] = tscBuildAlterTableMsg;
tscBuildMsg[TSDB_SQL_UPDATE_TAG
S
_VAL] = tscBuildUpdateTagMsg;
tscBuildMsg[TSDB_SQL_UPDATE_TAG_VAL] = tscBuildUpdateTagMsg;
tscBuildMsg[TSDB_SQL_ALTER_DB] = tscAlterDbMsg;
tscBuildMsg[TSDB_SQL_COMPACT_VNODE] = tscBuildCompactMsg;
...
...
@@ -3383,6 +3392,10 @@ void initMsgHandleFp() {
handleRequestRspFp
[
TSDB_SQL_CONNECT
]
=
processConnectRsp
;
buildRequestMsgFp
[
TSDB_SQL_CREATE_USER
]
=
doBuildMsgSupp
;
buildRequestMsgFp
[
TSDB_SQL_DROP_USER
]
=
doBuildMsgSupp
;
buildRequestMsgFp
[
TSDB_SQL_CREATE_ACCT
]
=
doBuildMsgSupp
;
buildRequestMsgFp
[
TSDB_SQL_DROP_ACCT
]
=
doBuildMsgSupp
;
buildRequestMsgFp
[
TSDB_SQL_SHOW
]
=
doBuildMsgSupp
;
handleRequestRspFp
[
TSDB_SQL_SHOW
]
=
processShowRsp
;
...
...
source/client/src/tscEnv.c
浏览文件 @
2d315222
...
...
@@ -189,7 +189,6 @@ static void doDestroyRequest(void* p) {
tfree
(
pRequest
->
pInfo
);
if
(
pRequest
->
body
.
pResInfo
!=
NULL
)
{
tfree
(
pRequest
->
body
.
pResInfo
->
pData
);
tfree
(
pRequest
->
body
.
pResInfo
->
pMsg
);
tfree
(
pRequest
->
body
.
pResInfo
);
}
...
...
source/client/test/clientTests.cpp
浏览文件 @
2d315222
...
...
@@ -40,13 +40,13 @@ TEST(testCase, driverInit_Test) {
TEST
(
testCase
,
connect_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
//
assert(pConn != NULL);
taos_close
(
pConn
);
}
TEST
(
testCase
,
create_user_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
//
assert(pConn != NULL);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"create user abc pass 'abc'"
);
if
(
taos_errno
(
pRes
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -57,23 +57,36 @@ TEST(testCase, create_user_Test) {
taos_close
(
pConn
);
}
//TEST(testCase, drop_user_Test) {
// TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
//
// TAOS_RES* pRes = taos_query(pConn, "drop user abc");
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
// }
//
// taos_free_result(pRes);
// taos_close(pConn);
//}
TEST
(
testCase
,
create_account_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TEST
(
testCase
,
show_user_Test
)
{
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"create account aabc pass 'abc'"
);
if
(
taos_errno
(
pRes
)
!=
TSDB_CODE_SUCCESS
)
{
printf
(
"failed to create user, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
taos_free_result
(
pRes
);
taos_close
(
pConn
);
}
TEST
(
testCase
,
drop_account_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"drop account aabc"
);
if
(
taos_errno
(
pRes
)
!=
TSDB_CODE_SUCCESS
)
{
printf
(
"failed to create user, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
taos_free_result
(
pRes
);
taos_close
(
pConn
);
}
TEST
(
testCase
,
show_user_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
// assert(pConn != NULL);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"show users"
);
TAOS_ROW
pRow
=
NULL
;
...
...
@@ -89,10 +102,23 @@ TEST(testCase, show_user_Test) {
taos_close
(
pConn
);
}
TEST
(
testCase
,
show_db
_Test
)
{
TEST
(
testCase
,
drop_user
_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"drop user abc"
);
if
(
taos_errno
(
pRes
)
!=
TSDB_CODE_SUCCESS
)
{
printf
(
"failed to create user, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
taos_free_result
(
pRes
);
taos_close
(
pConn
);
}
TEST
(
testCase
,
show_db_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
// assert(pConn != NULL);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"show databases"
);
TAOS_ROW
pRow
=
NULL
;
...
...
@@ -112,7 +138,7 @@ TEST(testCase, create_db_Test) {
TAOS
*
pConn
=
taos_connect
(
"ubuntu"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"create database abc"
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"create database abc
1
"
);
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pRes
);
ASSERT_TRUE
(
pFields
==
NULL
);
...
...
source/dnode/mgmt/daemon/src/daemon.c
浏览文件 @
2d315222
...
...
@@ -31,7 +31,7 @@ static struct {
}
global
=
{
0
};
void
dmnSigintHandle
(
int
signum
,
void
*
info
,
void
*
ctx
)
{
u
Error
(
"singal:%d is received"
,
signum
);
u
Info
(
"singal:%d is received"
,
signum
);
global
.
stop
=
true
;
}
...
...
source/dnode/mgmt/impl/src/dndTransport.c
浏览文件 @
2d315222
...
...
@@ -44,7 +44,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_CONSUME
]
=
dndProcessVnodeQueryMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_CONNECT
]
=
dndProcessVnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_DISCONNECT
]
=
dndProcessVnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_SET
]
=
dndProcessVnodeWriteMsg
;
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_MQ_SET
_CUR
]
=
dndProcessVnodeWriteMsg
;
// msg from client to mnode
pMgmt
->
msgFp
[
TSDB_MSG_TYPE_CONNECT
]
=
dndProcessMnodeReadMsg
;
...
...
source/dnode/mgmt/impl/src/dndVnodes.c
浏览文件 @
2d315222
此差异已折叠。
点击以展开。
source/dnode/mgmt/impl/src/dnode.c
浏览文件 @
2d315222
...
...
@@ -176,6 +176,12 @@ SDnode *dndInit(SDnodeOpt *pOption) {
return
NULL
;
}
if
(
vnodeInit
(
1
)
!=
0
)
{
dError
(
"failed to init vnode env"
);
dndCleanup
(
pDnode
);
return
NULL
;
}
if
(
dndInitDnode
(
pDnode
)
!=
0
)
{
dError
(
"failed to init dnode"
);
dndCleanup
(
pDnode
);
...
...
@@ -222,8 +228,10 @@ void dndCleanup(SDnode *pDnode) {
dndCleanupMnode
(
pDnode
);
dndCleanupVnodes
(
pDnode
);
dndCleanupDnode
(
pDnode
);
vnodeClear
();
walCleanUp
();
rpcCleanup
();
dndCleanupEnv
(
pDnode
);
free
(
pDnode
);
dInfo
(
"TDengine is cleaned up successfully"
);
...
...
source/dnode/mgmt/impl/test/db/db.cpp
浏览文件 @
2d315222
...
...
@@ -210,8 +210,8 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
pReq
->
daysToKeep0
=
htonl
(
3650
);
pReq
->
daysToKeep1
=
htonl
(
3650
);
pReq
->
daysToKeep2
=
htonl
(
3650
);
pReq
->
minRows
PerFileBlock
=
htonl
(
100
);
pReq
->
maxRows
PerFileBlock
=
htonl
(
4096
);
pReq
->
minRows
=
htonl
(
100
);
pReq
->
maxRows
=
htonl
(
4096
);
pReq
->
commitTime
=
htonl
(
3600
);
pReq
->
fsyncPeriod
=
htonl
(
3000
);
pReq
->
walLevel
=
1
;
...
...
@@ -375,8 +375,8 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) {
pReq
->
daysToKeep0
=
htonl
(
3650
);
pReq
->
daysToKeep1
=
htonl
(
3650
);
pReq
->
daysToKeep2
=
htonl
(
3650
);
pReq
->
minRows
PerFileBlock
=
htonl
(
100
);
pReq
->
maxRows
PerFileBlock
=
htonl
(
4096
);
pReq
->
minRows
=
htonl
(
100
);
pReq
->
maxRows
=
htonl
(
4096
);
pReq
->
commitTime
=
htonl
(
3600
);
pReq
->
fsyncPeriod
=
htonl
(
3000
);
pReq
->
walLevel
=
1
;
...
...
source/dnode/mgmt/impl/test/stb/stb.cpp
浏览文件 @
2d315222
...
...
@@ -187,8 +187,8 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
pReq
->
daysToKeep0
=
htonl
(
3650
);
pReq
->
daysToKeep1
=
htonl
(
3650
);
pReq
->
daysToKeep2
=
htonl
(
3650
);
pReq
->
minRows
PerFileBlock
=
htonl
(
100
);
pReq
->
maxRows
PerFileBlock
=
htonl
(
4096
);
pReq
->
minRows
=
htonl
(
100
);
pReq
->
maxRows
=
htonl
(
4096
);
pReq
->
commitTime
=
htonl
(
3600
);
pReq
->
fsyncPeriod
=
htonl
(
3000
);
pReq
->
walLevel
=
1
;
...
...
source/dnode/mgmt/impl/test/sut/deploy.cpp
浏览文件 @
2d315222
...
...
@@ -16,7 +16,7 @@
#include "deploy.h"
void
initLog
(
const
char
*
path
)
{
dDebugFlag
=
143
;
dDebugFlag
=
207
;
vDebugFlag
=
0
;
mDebugFlag
=
207
;
cDebugFlag
=
0
;
...
...
source/dnode/mgmt/impl/test/vgroup/vgroup.cpp
浏览文件 @
2d315222
...
...
@@ -176,49 +176,112 @@ SServer* DndTestVgroup::pServer;
SClient
*
DndTestVgroup
::
pClient
;
int32_t
DndTestVgroup
::
connId
;
TEST_F
(
DndTestVgroup
,
01
_Create_Restart_Drop_Vnode
)
{
{
SCreateVnodeMsg
*
pReq
=
(
SCreateVnodeMsg
*
)
rpcMallocCont
(
sizeof
(
SCreateVnodeMsg
));
pReq
->
vgId
=
htonl
(
2
);
pReq
->
dnodeId
=
htonl
(
1
);
strcpy
(
pReq
->
db
,
"1.d1"
);
pReq
->
dbUid
=
htobe64
(
9527
);
pReq
->
cacheBlockSize
=
htonl
(
16
);
pReq
->
totalBlocks
=
htonl
(
10
);
pReq
->
daysPerFile
=
htonl
(
10
);
pReq
->
daysToKeep0
=
htonl
(
3650
);
pReq
->
daysToKeep1
=
htonl
(
3650
);
pReq
->
daysToKeep2
=
htonl
(
3650
);
pReq
->
minRows
=
htonl
(
100
);
pReq
->
minRows
=
htonl
(
4096
);
pReq
->
commitTime
=
htonl
(
3600
);
pReq
->
fsyncPeriod
=
htonl
(
3000
);
pReq
->
walLevel
=
1
;
pReq
->
precision
=
0
;
pReq
->
compression
=
2
;
pReq
->
replica
=
1
;
pReq
->
quorum
=
1
;
pReq
->
update
=
0
;
pReq
->
cacheLastRow
=
0
;
pReq
->
selfIndex
=
0
;
for
(
int
r
=
0
;
r
<
pReq
->
replica
;
++
r
)
{
SReplica
*
pReplica
=
&
pReq
->
replicas
[
r
];
pReplica
->
id
=
htonl
(
1
);
pReplica
->
port
=
htons
(
9150
);
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
SCreateVnodeMsg
*
pReq
=
(
SCreateVnodeMsg
*
)
rpcMallocCont
(
sizeof
(
SCreateVnodeMsg
));
pReq
->
vgId
=
htonl
(
2
);
pReq
->
dnodeId
=
htonl
(
1
);
strcpy
(
pReq
->
db
,
"1.d1"
);
pReq
->
dbUid
=
htobe64
(
9527
);
pReq
->
vgVersion
=
htonl
(
1
);
pReq
->
cacheBlockSize
=
htonl
(
16
);
pReq
->
totalBlocks
=
htonl
(
10
);
pReq
->
daysPerFile
=
htonl
(
10
);
pReq
->
daysToKeep0
=
htonl
(
3650
);
pReq
->
daysToKeep1
=
htonl
(
3650
);
pReq
->
daysToKeep2
=
htonl
(
3650
);
pReq
->
minRows
=
htonl
(
100
);
pReq
->
minRows
=
htonl
(
4096
);
pReq
->
commitTime
=
htonl
(
3600
);
pReq
->
fsyncPeriod
=
htonl
(
3000
);
pReq
->
walLevel
=
1
;
pReq
->
precision
=
0
;
pReq
->
compression
=
2
;
pReq
->
replica
=
1
;
pReq
->
quorum
=
1
;
pReq
->
update
=
0
;
pReq
->
cacheLastRow
=
0
;
pReq
->
selfIndex
=
0
;
for
(
int
r
=
0
;
r
<
pReq
->
replica
;
++
r
)
{
SReplica
*
pReplica
=
&
pReq
->
replicas
[
r
];
pReplica
->
id
=
htonl
(
1
);
pReplica
->
port
=
htons
(
9150
);
}
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SCreateVnodeMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_CREATE_VNODE_IN
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
}
}
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SCreateVnodeMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_CREATE_VNODE_IN
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
taosMsleep
(
1000000
);
{
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
SAlterVnodeMsg
*
pReq
=
(
SAlterVnodeMsg
*
)
rpcMallocCont
(
sizeof
(
SAlterVnodeMsg
));
pReq
->
vgId
=
htonl
(
2
);
pReq
->
dnodeId
=
htonl
(
1
);
strcpy
(
pReq
->
db
,
"1.d1"
);
pReq
->
dbUid
=
htobe64
(
9527
);
pReq
->
vgVersion
=
htonl
(
2
);
pReq
->
cacheBlockSize
=
htonl
(
16
);
pReq
->
totalBlocks
=
htonl
(
10
);
pReq
->
daysPerFile
=
htonl
(
10
);
pReq
->
daysToKeep0
=
htonl
(
3650
);
pReq
->
daysToKeep1
=
htonl
(
3650
);
pReq
->
daysToKeep2
=
htonl
(
3650
);
pReq
->
minRows
=
htonl
(
100
);
pReq
->
minRows
=
htonl
(
4096
);
pReq
->
commitTime
=
htonl
(
3600
);
pReq
->
fsyncPeriod
=
htonl
(
3000
);
pReq
->
walLevel
=
1
;
pReq
->
precision
=
0
;
pReq
->
compression
=
2
;
pReq
->
replica
=
1
;
pReq
->
quorum
=
1
;
pReq
->
update
=
0
;
pReq
->
cacheLastRow
=
0
;
pReq
->
selfIndex
=
0
;
for
(
int
r
=
0
;
r
<
pReq
->
replica
;
++
r
)
{
SReplica
*
pReplica
=
&
pReq
->
replicas
[
r
];
pReplica
->
id
=
htonl
(
1
);
pReplica
->
port
=
htons
(
9150
);
}
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SAlterVnodeMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_ALTER_VNODE_IN
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
}
}
{
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
SDropVnodeMsg
*
pReq
=
(
SDropVnodeMsg
*
)
rpcMallocCont
(
sizeof
(
SDropVnodeMsg
));
pReq
->
vgId
=
htonl
(
2
);
pReq
->
dnodeId
=
htonl
(
1
);
strcpy
(
pReq
->
db
,
"1.d1"
);
pReq
->
dbUid
=
htobe64
(
9527
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SDropVnodeMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_DROP_VNODE_IN
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
}
}
}
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
2d315222
...
...
@@ -61,15 +61,14 @@ typedef enum {
}
EAuthOp
;
typedef
enum
{
TRN_STAGE_PREPARE
=
1
,
TRN_STAGE_EXECUTE
=
2
,
TRN_STAGE_PREPARE
=
0
,
TRN_STAGE_EXECUTE
=
1
,
TRN_STAGE_ROLLBACK
=
2
,
TRN_STAGE_COMMIT
=
3
,
TRN_STAGE_ROLLBACK
=
4
,
TRN_STAGE_RETRY
=
5
,
TRN_STAGE_OVER
=
6
,
TRN_STAGE_OVER
=
4
,
}
ETrnStage
;
typedef
enum
{
TRN_POLICY_ROLLBACK
=
1
,
TRN_POLICY_RETRY
=
2
}
ETrnPolicy
;
typedef
enum
{
TRN_POLICY_ROLLBACK
=
0
,
TRN_POLICY_RETRY
=
1
}
ETrnPolicy
;
typedef
enum
{
DND_STATUS_OFFLINE
=
0
,
...
...
source/dnode/mnode/impl/inc/mndInt.h
浏览文件 @
2d315222
...
...
@@ -70,6 +70,7 @@ typedef struct SMnode {
tmr_h
timer
;
char
*
path
;
SMnodeCfg
cfg
;
int64_t
checkTime
;
SSdb
*
pSdb
;
SDnode
*
pDnode
;
SArray
*
pSteps
;
...
...
source/dnode/mnode/impl/inc/mndTrans.h
浏览文件 @
2d315222
...
...
@@ -22,6 +22,16 @@
extern
"C"
{
#endif
typedef
struct
{
SEpSet
epSet
;
int8_t
msgType
;
int8_t
msgSent
;
int8_t
msgReceived
;
int32_t
errCode
;
int32_t
contLen
;
void
*
pCont
;
}
STransAction
;
int32_t
mndInitTrans
(
SMnode
*
pMnode
);
void
mndCleanupTrans
(
SMnode
*
pMnode
);
...
...
@@ -30,12 +40,15 @@ void mndTransDrop(STrans *pTrans);
int32_t
mndTransAppendRedolog
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
);
int32_t
mndTransAppendUndolog
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
);
int32_t
mndTransAppendCommitlog
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
);
int32_t
mndTransAppendRedoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
int8_t
msgType
,
int32_t
contLen
,
void
*
pCont
);
int32_t
mndTransAppendUndoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
int8_t
msgType
,
int32_t
contLen
,
void
*
pCont
);
int32_t
mndTransAppendRedoAction
(
STrans
*
pTrans
,
STransAction
*
pAction
);
int32_t
mndTransAppendUndoAction
(
STrans
*
pTrans
,
STransAction
*
pAction
);
int32_t
mndTransPrepare
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
void
mndTransApply
(
SMnode
*
pMnode
,
SSdbRaw
*
pRaw
,
STransMsg
*
pMsg
,
int32_t
code
);
char
*
mndTransStageStr
(
ETrnStage
stage
);
char
*
mndTransPolicyStr
(
ETrnPolicy
policy
);
void
mndTransHandleActionRsp
(
SMnodeMsg
*
pMsg
);
char
*
mndTransStageStr
(
ETrnStage
stage
);
char
*
mndTransPolicyStr
(
ETrnPolicy
policy
);
#ifdef __cplusplus
}
...
...
source/dnode/mnode/impl/src/mndAcct.c
浏览文件 @
2d315222
...
...
@@ -17,7 +17,8 @@
#include "mndAcct.h"
#include "mndShow.h"
#define SDB_ACCT_VER 1
#define TSDB_ACCT_VER_NUMBER 1
#define TSDB_ACCT_RESERVE_SIZE 64
static
int32_t
mndCreateDefaultAcct
(
SMnode
*
pMnode
);
static
SSdbRaw
*
mndAcctActionEncode
(
SAcctObj
*
pAcct
);
...
...
@@ -70,7 +71,7 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
}
static
SSdbRaw
*
mndAcctActionEncode
(
SAcctObj
*
pAcct
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_ACCT
,
SDB_ACCT_V
ER
,
sizeof
(
SAcctObj
));
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_ACCT
,
TSDB_ACCT_VER_NUMB
ER
,
sizeof
(
SAcctObj
));
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
...
...
@@ -85,6 +86,7 @@ static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAcct
->
cfg
.
maxStreams
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pAcct
->
cfg
.
maxStorage
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAcct
->
cfg
.
accessState
)
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_ACCT_RESERVE_SIZE
)
SDB_SET_DATALEN
(
pRaw
,
dataPos
);
return
pRaw
;
...
...
@@ -94,7 +96,7 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
SDB_ACCT_V
ER
)
{
if
(
sver
!=
TSDB_ACCT_VER_NUMB
ER
)
{
mError
(
"failed to decode acct since %s"
,
terrstr
());
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
return
NULL
;
...
...
@@ -116,13 +118,13 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pAcct
->
cfg
.
maxStreams
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pAcct
->
cfg
.
maxStorage
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pAcct
->
cfg
.
accessState
)
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
TSDB_ACCT_RESERVE_SIZE
)
return
pRow
;
}
static
int32_t
mndAcctActionInsert
(
SSdb
*
pSdb
,
SAcctObj
*
pAcct
)
{
mTrace
(
"acct:%s, perform insert action"
,
pAcct
->
acct
);
memset
(
&
pAcct
->
info
,
0
,
sizeof
(
SAcctInfo
));
return
0
;
}
...
...
@@ -134,12 +136,9 @@ static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
static
int32_t
mndAcctActionUpdate
(
SSdb
*
pSdb
,
SAcctObj
*
pOldAcct
,
SAcctObj
*
pNewAcct
)
{
mTrace
(
"acct:%s, perform update action"
,
pOldAcct
->
acct
);
memcpy
(
pOldAcct
->
acct
,
pNewAcct
->
acct
,
TSDB_USER_LEN
);
pOldAcct
->
createdTime
=
pNewAcct
->
createdTime
;
pOldAcct
->
updateTime
=
pNewAcct
->
updateTime
;
pOldAcct
->
acctId
=
pNewAcct
->
acctId
;
pOldAcct
->
status
=
pNewAcct
->
status
;
pOldAcct
->
cfg
=
pNewAcct
->
cfg
;
memcpy
(
&
pOldAcct
->
cfg
,
&
pNewAcct
->
cfg
,
sizeof
(
SAcctInfo
))
;
return
0
;
}
...
...
source/dnode/mnode/impl/src/mndCluster.c
浏览文件 @
2d315222
...
...
@@ -18,7 +18,8 @@
#include "mndShow.h"
#include "mndTrans.h"
#define SDB_CLUSTER_VER 1
#define TSDB_CLUSTER_VER_NUMBE 1
#define TSDB_CLUSTER_RESERVE_SIZE 64
static
SSdbRaw
*
mndClusterActionEncode
(
SClusterObj
*
pCluster
);
static
SSdbRow
*
mndClusterActionDecode
(
SSdbRaw
*
pRaw
);
...
...
@@ -62,7 +63,7 @@ int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) {
}
static
SSdbRaw
*
mndClusterActionEncode
(
SClusterObj
*
pCluster
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_CLUSTER
,
SDB_CLUSTER_VER
,
sizeof
(
SClusterObj
));
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_CLUSTER
,
TSDB_CLUSTER_VER_NUMBE
,
sizeof
(
SClusterObj
));
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
...
...
@@ -70,6 +71,7 @@ static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
SDB_SET_INT64
(
pRaw
,
dataPos
,
pCluster
->
createdTime
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pCluster
->
updateTime
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pCluster
->
name
,
TSDB_CLUSTER_ID_LEN
)
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_CLUSTER_RESERVE_SIZE
)
return
pRaw
;
}
...
...
@@ -78,7 +80,7 @@ static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
SDB_CLUSTER_VER
)
{
if
(
sver
!=
TSDB_CLUSTER_VER_NUMBE
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
mError
(
"failed to decode cluster since %s"
,
terrstr
());
return
NULL
;
...
...
@@ -93,6 +95,7 @@ static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pCluster
->
createdTime
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pCluster
->
updateTime
)
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pCluster
->
name
,
TSDB_CLUSTER_ID_LEN
)
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
TSDB_CLUSTER_RESERVE_SIZE
)
return
pRow
;
}
...
...
@@ -169,6 +172,7 @@ static int32_t mndGetClusterMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
pShow
->
numOfRows
=
1
;
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
strcpy
(
pMeta
->
tbFname
,
mndShowStr
(
pShow
->
type
));
return
0
;
}
...
...
source/dnode/mnode/impl/src/mndDb.c
浏览文件 @
2d315222
此差异已折叠。
点击以展开。
source/dnode/mnode/impl/src/mndDnode.c
浏览文件 @
2d315222
...
...
@@ -18,10 +18,10 @@
#include "mndMnode.h"
#include "mndShow.h"
#include "mndTrans.h"
#include "ttime.h"
#include "tep.h"
#include "ttime.h"
#define TSDB_DNODE_VER 1
#define TSDB_DNODE_VER
_NUMBER
1
#define TSDB_DNODE_RESERVE_SIZE 64
#define TSDB_CONFIG_OPTION_LEN 16
#define TSDB_CONIIG_VALUE_LEN 48
...
...
@@ -101,14 +101,14 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) {
SSdbRaw
*
pRaw
=
mndDnodeActionEncode
(
&
dnodeObj
);
if
(
pRaw
==
NULL
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
)
;
if
(
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
)
!=
0
)
return
-
1
;
mDebug
(
"dnode:%d, will be created while deploy sdb"
,
dnodeObj
.
id
);
return
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
}
static
SSdbRaw
*
mndDnodeActionEncode
(
SDnodeObj
*
pDnode
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_DNODE
,
TSDB_DNODE_VER
,
sizeof
(
SDnodeObj
)
+
TSDB_DNODE_RESERVE_SIZE
);
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_DNODE
,
TSDB_DNODE_VER
_NUMBER
,
sizeof
(
SDnodeObj
)
+
TSDB_DNODE_RESERVE_SIZE
);
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
...
...
@@ -127,7 +127,7 @@ static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
TSDB_DNODE_VER
)
{
if
(
sver
!=
TSDB_DNODE_VER
_NUMBER
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
mError
(
"failed to decode dnode since %s"
,
terrstr
());
return
NULL
;
...
...
@@ -150,21 +150,8 @@ static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
static
int32_t
mndDnodeActionInsert
(
SSdb
*
pSdb
,
SDnodeObj
*
pDnode
)
{
mTrace
(
"dnode:%d, perform insert action"
,
pDnode
->
id
);
pDnode
->
rebootTime
=
0
;
pDnode
->
lastAccessTime
=
0
;
pDnode
->
accessTimes
=
0
;
pDnode
->
numOfMnodes
=
0
;
pDnode
->
numOfVnodes
=
0
;
pDnode
->
numOfQnodes
=
0
;
pDnode
->
numOfSupportMnodes
=
0
;
pDnode
->
numOfSupportVnodes
=
0
;
pDnode
->
numOfSupportQnodes
=
0
;
pDnode
->
numOfCores
=
0
;
pDnode
->
status
=
DND_STATUS_OFFLINE
;
pDnode
->
offlineReason
=
DND_REASON_STATUS_NOT_RECEIVED
;
snprintf
(
pDnode
->
ep
,
TSDB_EP_LEN
,
"%s:%u"
,
pDnode
->
fqdn
,
pDnode
->
port
);
return
0
;
}
...
...
@@ -225,7 +212,7 @@ int32_t mndGetDnodeSize(SMnode *pMnode) {
bool
mndIsDnodeInReadyStatus
(
SMnode
*
pMnode
,
SDnodeObj
*
pDnode
)
{
int64_t
ms
=
taosGetTimestampMs
();
int64_t
interval
=
ABS
(
pDnode
->
lastAccessTime
-
ms
);
if
(
interval
>
3
0
00
*
pMnode
->
cfg
.
statusInterval
)
{
if
(
interval
>
3
5
00
*
pMnode
->
cfg
.
statusInterval
)
{
return
false
;
}
return
true
;
...
...
@@ -267,12 +254,9 @@ static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) {
return
DND_REASON_STATUS_INTERVAL_NOT_MATCH
;
}
int64_t
checkTime
=
0
;
char
timestr
[
32
]
=
"1970-01-01 00:00:00.00"
;
(
void
)
taosParseTime
(
timestr
,
&
checkTime
,
(
int32_t
)
strlen
(
timestr
),
TSDB_TIME_PRECISION_MILLI
,
0
);
if
((
0
!=
strcasecmp
(
pCfg
->
timezone
,
pMnode
->
cfg
.
timezone
))
&&
(
checkTime
!=
pCfg
->
checkTime
))
{
if
((
0
!=
strcasecmp
(
pCfg
->
timezone
,
pMnode
->
cfg
.
timezone
))
&&
(
pMnode
->
checkTime
!=
pCfg
->
checkTime
))
{
mError
(
"timezone [%s - %s] [%"
PRId64
" - %"
PRId64
"] cfg inconsistent"
,
pCfg
->
timezone
,
pMnode
->
cfg
.
timezone
,
pCfg
->
checkTime
,
checkTime
);
pCfg
->
checkTime
,
pMnode
->
checkTime
);
return
DND_REASON_TIME_ZONE_NOT_MATCH
;
}
...
...
source/dnode/mnode/impl/src/mndMnode.c
浏览文件 @
2d315222
...
...
@@ -19,7 +19,8 @@
#include "mndShow.h"
#include "mndTrans.h"
#define SDB_MNODE_VER 1
#define TSDB_MNODE_VER_NUMBER 1
#define TSDB_MNODE_RESERVE_SIZE 64
static
int32_t
mndCreateDefaultMnode
(
SMnode
*
pMnode
);
static
SSdbRaw
*
mndMnodeActionEncode
(
SMnodeObj
*
pMnodeObj
);
...
...
@@ -97,13 +98,14 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) {
}
static
SSdbRaw
*
mndMnodeActionEncode
(
SMnodeObj
*
pMnodeObj
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_MNODE
,
SDB_MNODE_V
ER
,
sizeof
(
SMnodeObj
));
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_MNODE
,
TSDB_MNODE_VER_NUMB
ER
,
sizeof
(
SMnodeObj
));
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_SET_INT32
(
pRaw
,
dataPos
,
pMnodeObj
->
id
);
SDB_SET_INT64
(
pRaw
,
dataPos
,
pMnodeObj
->
createdTime
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pMnodeObj
->
updateTime
)
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_MNODE_RESERVE_SIZE
)
return
pRaw
;
}
...
...
@@ -112,7 +114,7 @@ static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) {
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
SDB_MNODE_V
ER
)
{
if
(
sver
!=
TSDB_MNODE_VER_NUMB
ER
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
mError
(
"failed to decode mnode since %s"
,
terrstr
());
return
NULL
;
...
...
@@ -126,6 +128,7 @@ static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pMnodeObj
->
id
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pMnodeObj
->
createdTime
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pMnodeObj
->
updateTime
)
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
TSDB_MNODE_RESERVE_SIZE
)
return
pRow
;
}
...
...
source/dnode/mnode/impl/src/mndTrans.c
浏览文件 @
2d315222
...
...
@@ -17,17 +17,10 @@
#include "mndTrans.h"
#include "mndSync.h"
#define TSDB_TRANS_VER 1
#define TSDB_TRANS_VER
_NUMBER
1
#define TSDB_TRN_ARRAY_SIZE 8
#define TSDB_TRN_RESERVE_SIZE 64
typedef
struct
{
SEpSet
epSet
;
int8_t
msgType
;
int32_t
contLen
;
void
*
pCont
;
}
STransAction
;
static
SSdbRaw
*
mndTransActionEncode
(
STrans
*
pTrans
);
static
SSdbRow
*
mndTransActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndTransActionInsert
(
SSdb
*
pSdb
,
STrans
*
pTrans
);
...
...
@@ -37,11 +30,11 @@ static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans);
static
void
mndTransSetRpcHandle
(
STrans
*
pTrans
,
void
*
rpcHandle
);
static
void
mndTransSendRpcRsp
(
STrans
*
pTrans
,
int32_t
code
);
static
int32_t
mndTransAppendLog
(
SArray
*
pArray
,
SSdbRaw
*
pRaw
);
static
int32_t
mndTransAppendAction
(
SArray
*
pArray
,
S
EpSet
*
pEpSet
,
int8_t
msgType
,
int32_t
contLen
,
void
*
pCont
);
static
int32_t
mndTransAppendAction
(
SArray
*
pArray
,
S
TransAction
*
pAction
);
static
void
mndTransDropLogs
(
SArray
*
pArray
);
static
void
mndTransDropActions
(
SArray
*
pArray
);
static
int32_t
mndTransExecuteLogs
(
SMnode
*
pMnode
,
SArray
*
pArray
);
static
int32_t
mndTransExecuteActions
(
SMnode
*
pMnode
,
SArray
*
pArray
);
static
int32_t
mndTransExecuteActions
(
SMnode
*
pMnode
,
S
Trans
*
pTrans
,
S
Array
*
pArray
);
static
int32_t
mndTransExecuteRedoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
static
int32_t
mndTransExecuteUndoLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
static
int32_t
mndTransExecuteCommitLogs
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
...
...
@@ -100,7 +93,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
rawDataLen
+=
(
sizeof
(
STransAction
)
+
pAction
->
contLen
);
}
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_TRANS
,
TSDB_TRANS_VER
,
rawDataLen
);
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_TRANS
,
TSDB_TRANS_VER
_NUMBER
,
rawDataLen
);
if
(
pRaw
==
NULL
)
{
mError
(
"trans:%d, failed to alloc raw since %s"
,
pTrans
->
id
,
terrstr
());
return
NULL
;
...
...
@@ -167,7 +160,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
return
NULL
;
}
if
(
sver
!=
TSDB_TRANS_VER
)
{
if
(
sver
!=
TSDB_TRANS_VER
_NUMBER
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
mError
(
"failed to get check soft ver from raw:%p since %s"
,
pRaw
,
terrstr
());
return
NULL
;
...
...
@@ -343,10 +336,8 @@ char *mndTransStageStr(ETrnStage stage) {
return
"commit"
;
case
TRN_STAGE_ROLLBACK
:
return
"rollback"
;
case
TRN_STAGE_RETRY
:
return
"retry"
;
case
TRN_STAGE_OVER
:
return
"
stop
"
;
return
"
over
"
;
default:
return
"undefined"
;
}
...
...
@@ -388,7 +379,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
return
NULL
;
}
mDebug
(
"trans:%d,
data:%p is created"
,
pTrans
->
id
,
pTrans
);
mDebug
(
"trans:%d,
is created"
,
pTrans
->
id
);
return
pTrans
;
}
...
...
@@ -417,7 +408,7 @@ void mndTransDrop(STrans *pTrans) {
mndTransDropActions
(
pTrans
->
redoActions
);
mndTransDropActions
(
pTrans
->
undoActions
);
mDebug
(
"trans:%d, data:%p is dropped
"
,
pTrans
->
id
,
pTrans
);
// mDebug("trans:%d, is dropped, data:%p
", pTrans->id, pTrans);
tfree
(
pTrans
);
}
...
...
@@ -459,10 +450,8 @@ int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw) {
return
code
;
}
static
int32_t
mndTransAppendAction
(
SArray
*
pArray
,
SEpSet
*
pEpSet
,
int8_t
msgType
,
int32_t
contLen
,
void
*
pCont
)
{
STransAction
action
=
{.
epSet
=
*
pEpSet
,
.
msgType
=
msgType
,
.
contLen
=
contLen
,
.
pCont
=
pCont
};
void
*
ptr
=
taosArrayPush
(
pArray
,
&
action
);
static
int32_t
mndTransAppendAction
(
SArray
*
pArray
,
STransAction
*
pAction
)
{
void
*
ptr
=
taosArrayPush
(
pArray
,
pAction
);
if
(
ptr
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
...
...
@@ -471,16 +460,12 @@ static int32_t mndTransAppendAction(SArray *pArray, SEpSet *pEpSet, int8_t msgTy
return
0
;
}
int32_t
mndTransAppendRedoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
int8_t
msgType
,
int32_t
contLen
,
void
*
pCont
)
{
int32_t
code
=
mndTransAppendAction
(
pTrans
->
redoActions
,
pEpSet
,
msgType
,
contLen
,
pCont
);
mTrace
(
"trans:%d, msg:%s len:%d append to redo actions"
,
pTrans
->
id
,
taosMsg
[
msgType
],
contLen
);
return
code
;
int32_t
mndTransAppendRedoAction
(
STrans
*
pTrans
,
STransAction
*
pAction
)
{
return
mndTransAppendAction
(
pTrans
->
redoActions
,
pAction
);
}
int32_t
mndTransAppendUndoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
int8_t
msgType
,
int32_t
contLen
,
void
*
pCont
)
{
int32_t
code
=
mndTransAppendAction
(
pTrans
->
undoActions
,
pEpSet
,
msgType
,
contLen
,
pCont
);
mTrace
(
"trans:%d, msg:%s len:%d append to undo actions"
,
pTrans
->
id
,
taosMsg
[
msgType
],
contLen
);
return
code
;
int32_t
mndTransAppendUndoAction
(
STrans
*
pTrans
,
STransAction
*
pAction
)
{
return
mndTransAppendAction
(
pTrans
->
undoActions
,
pAction
);
}
int32_t
mndTransPrepare
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
...
...
@@ -493,7 +478,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
}
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
mTrace
(
"trans:%d, s
tart sync
"
,
pTrans
->
id
);
mTrace
(
"trans:%d, s
ync to other nodes
"
,
pTrans
->
id
);
int32_t
code
=
mndSyncPropose
(
pMnode
,
pRaw
);
if
(
code
!=
0
)
{
mError
(
"trans:%d, failed to sync since %s"
,
pTrans
->
id
,
terrstr
());
...
...
@@ -533,7 +518,7 @@ int32_t mndTransCommit(SMnode *pMnode, STrans *pTrans) {
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_DROPPED
);
if
(
taosArrayGetSize
(
pTrans
->
commitLogs
)
!=
0
)
{
mTrace
(
"trans:%d, s
tart sync
"
,
pTrans
->
id
);
mTrace
(
"trans:%d, s
ync to other nodes
"
,
pTrans
->
id
);
int32_t
code
=
mndSyncPropose
(
pMnode
,
pRaw
);
if
(
code
!=
0
)
{
mError
(
"trans:%d, failed to sync since %s"
,
pTrans
->
id
,
terrstr
());
...
...
@@ -563,7 +548,7 @@ int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) {
}
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_DROPPED
);
mTrace
(
"trans:%d, s
tart sync
"
,
pTrans
->
id
);
mTrace
(
"trans:%d, s
ync to other nodes
"
,
pTrans
->
id
);
int32_t
code
=
mndSyncPropose
(
pMnode
,
pRaw
);
if
(
code
!=
0
)
{
mError
(
"trans:%d, failed to sync since %s"
,
pTrans
->
id
,
terrstr
());
...
...
@@ -596,6 +581,50 @@ void mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, STransMsg *pMsg, int32_t code)
// todo
}
void
mndTransHandleActionRsp
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
int64_t
sig
=
(
int64_t
)(
pMsg
->
rpcMsg
.
ahandle
);
int32_t
transId
=
(
int32_t
)(
sig
>>
32
);
int32_t
action
=
(
int32_t
)((
sig
<<
32
)
>>
32
);
STrans
*
pTrans
=
mndAcquireTrans
(
pMnode
,
transId
);
if
(
pTrans
==
NULL
)
{
mError
(
"trans:%d, failed to get transId from vnode rsp since %s"
,
transId
,
terrstr
());
goto
HANDLE_ACTION_RSP_OVER
;
}
SArray
*
pArray
=
NULL
;
if
(
pTrans
->
stage
==
TRN_STAGE_EXECUTE
)
{
pArray
=
pTrans
->
redoActions
;
}
else
if
(
pTrans
->
stage
==
TRN_STAGE_ROLLBACK
)
{
pArray
=
pTrans
->
undoActions
;
}
else
{
}
if
(
pArray
==
NULL
)
{
mError
(
"trans:%d, invalid trans stage:%s"
,
transId
,
mndTransStageStr
(
pTrans
->
stage
));
goto
HANDLE_ACTION_RSP_OVER
;
}
int32_t
actionNum
=
taosArrayGetSize
(
pTrans
->
redoActions
);
if
(
action
<
0
||
action
>
actionNum
)
{
mError
(
"trans:%d, invalid action:%d"
,
transId
,
action
);
goto
HANDLE_ACTION_RSP_OVER
;
}
STransAction
*
pAction
=
taosArrayGet
(
pArray
,
action
);
if
(
pAction
!=
NULL
)
{
pAction
->
msgReceived
=
1
;
pAction
->
errCode
=
pMsg
->
code
;
}
mDebug
(
"trans:%d, action:%d response is received, code:0x%x"
,
transId
,
action
,
pMsg
->
code
);
mndTransExecute
(
pMnode
,
pTrans
);
HANDLE_ACTION_RSP_OVER:
mndReleaseTrans
(
pMnode
,
pTrans
);
}
static
int32_t
mndTransExecuteLogs
(
SMnode
*
pMnode
,
SArray
*
pArray
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
arraySize
=
taosArrayGetSize
(
pArray
);
...
...
@@ -618,7 +647,7 @@ static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans) {
if
(
code
!=
0
)
{
mError
(
"trans:%d, failed to execute redo logs since %s"
,
pTrans
->
id
,
terrstr
())
}
else
{
m
Trace
(
"trans:%d, execute redo logs finished"
,
pTrans
->
id
)
m
Debug
(
"trans:%d, execute redo logs finished"
,
pTrans
->
id
)
}
}
...
...
@@ -632,7 +661,7 @@ static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans) {
if
(
code
!=
0
)
{
mError
(
"trans:%d, failed to execute undo logs since %s"
,
pTrans
->
id
,
terrstr
())
}
else
{
m
Trace
(
"trans:%d, execute undo logs finished"
,
pTrans
->
id
)
m
Debug
(
"trans:%d, execute undo logs finished"
,
pTrans
->
id
)
}
}
...
...
@@ -646,47 +675,70 @@ static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans) {
if
(
code
!=
0
)
{
mError
(
"trans:%d, failed to execute commit logs since %s"
,
pTrans
->
id
,
terrstr
())
}
else
{
m
Trace
(
"trans:%d, execute commit logs finished"
,
pTrans
->
id
)
m
Debug
(
"trans:%d, execute commit logs finished"
,
pTrans
->
id
)
}
}
return
code
;
}
static
int32_t
mndTransExecuteActions
(
SMnode
*
pMnode
,
SArray
*
pArray
)
{
#if 0
int32_t arraySize = taosArrayGetSize(pArray);
for (int32_t i = 0; i < arraySize; ++i) {
STransAction *pAction = taosArrayGet(pArray, i);
static
int32_t
mndTransExecuteActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SArray
*
pArray
)
{
int32_t
numOfActions
=
taosArrayGetSize
(
pArray
);
if
(
numOfActions
==
0
)
return
0
;
for
(
int32_t
action
=
0
;
action
<
numOfActions
;
++
action
)
{
STransAction
*
pAction
=
taosArrayGet
(
pArray
,
action
);
if
(
pAction
==
NULL
)
continue
;
if
(
pAction
->
msgSent
)
continue
;
int64_t
signature
=
pTrans
->
id
;
signature
=
(
signature
<<
32
);
signature
+=
action
;
SRpcMsg rpcMsg = {.msgType = pAction->msgType, .contLen = pAction->contLen};
SRpcMsg
rpcMsg
=
{.
msgType
=
pAction
->
msgType
,
.
contLen
=
pAction
->
contLen
,
.
ahandle
=
(
void
*
)
signature
};
rpcMsg
.
pCont
=
rpcMallocCont
(
pAction
->
contLen
);
if
(
rpcMsg
.
pCont
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
memcpy
(
rpcMsg
.
pCont
,
pAction
->
pCont
,
pAction
->
contLen
);
pAction
->
msgSent
=
1
;
pAction
->
msgReceived
=
0
;
pAction
->
errCode
=
0
;
mDebug
(
"trans:%d, action:%d is sent"
,
pTrans
->
id
,
action
);
mndSendMsgToDnode
(
pMnode
,
&
pAction
->
epSet
,
&
rpcMsg
);
}
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
#else
return
0
;
#endif
int32_t
numOfReceivedMsgs
=
0
;
int32_t
errorCode
=
0
;
for
(
int32_t
action
=
0
;
action
<
numOfActions
;
++
action
)
{
STransAction
*
pAction
=
taosArrayGet
(
pArray
,
action
);
if
(
pAction
==
NULL
)
continue
;
if
(
pAction
->
msgSent
&&
pAction
->
msgReceived
)
{
numOfReceivedMsgs
++
;
if
(
pAction
->
errCode
!=
0
)
{
errorCode
=
pAction
->
errCode
;
}
}
}
if
(
numOfReceivedMsgs
==
numOfActions
)
{
mDebug
(
"trans:%d, all %d actions executed, code:0x%x"
,
pTrans
->
id
,
numOfActions
,
errorCode
);
terrno
=
errorCode
;
return
errorCode
;
}
else
{
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
}
static
int32_t
mndTransExecuteRedoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
if
(
taosArrayGetSize
(
pTrans
->
redoActions
)
<=
0
)
return
0
;
mTrace
(
"trans:%d, start to execute redo actions"
,
pTrans
->
id
);
return
mndTransExecuteActions
(
pMnode
,
pTrans
->
redoActions
);
return
mndTransExecuteActions
(
pMnode
,
pTrans
,
pTrans
->
redoActions
);
}
static
int32_t
mndTransExecuteUndoActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
if
(
taosArrayGetSize
(
pTrans
->
undoActions
)
<=
0
)
return
0
;
mTrace
(
"trans:%d, start to execute undo actions"
,
pTrans
->
id
);
return
mndTransExecuteActions
(
pMnode
,
pTrans
->
undoActions
);
return
mndTransExecuteActions
(
pMnode
,
pTrans
,
pTrans
->
undoActions
);
}
static
int32_t
mndTransPerformPrepareStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
...
...
@@ -694,7 +746,7 @@ static int32_t mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) {
if
(
code
==
0
)
{
pTrans
->
stage
=
TRN_STAGE_EXECUTE
;
m
Trace
(
"trans:%d, stage from prepare to execute"
,
pTrans
->
id
);
m
Debug
(
"trans:%d, stage from prepare to execute"
,
pTrans
->
id
);
}
else
{
pTrans
->
stage
=
TRN_STAGE_ROLLBACK
;
mError
(
"trans:%d, stage from prepare to rollback since %s"
,
pTrans
->
id
,
terrstr
());
...
...
@@ -708,17 +760,17 @@ static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans) {
if
(
code
==
0
)
{
pTrans
->
stage
=
TRN_STAGE_COMMIT
;
m
Trace
(
"trans:%d, stage from execute to commit"
,
pTrans
->
id
);
m
Debug
(
"trans:%d, stage from execute to commit"
,
pTrans
->
id
);
}
else
if
(
code
==
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
m
Trace
(
"trans:%d, stage keep on execute since %s"
,
pTrans
->
id
,
terrst
r
(
code
));
m
Debug
(
"trans:%d, stage keep on execute since %s"
,
pTrans
->
id
,
tstrerro
r
(
code
));
return
code
;
}
else
{
if
(
pTrans
->
policy
==
TRN_POLICY_ROLLBACK
)
{
pTrans
->
stage
=
TRN_STAGE_ROLLBACK
;
mError
(
"trans:%d, stage from execute to rollback since %s"
,
pTrans
->
id
,
terrstr
());
}
else
{
pTrans
->
stage
=
TRN_STAGE_
RETRY
;
mError
(
"trans:%d, stage
from execute to retry
since %s"
,
pTrans
->
id
,
terrstr
());
pTrans
->
stage
=
TRN_STAGE_
EXECUTE
;
mError
(
"trans:%d, stage
keep on execute
since %s"
,
pTrans
->
id
,
terrstr
());
}
}
...
...
@@ -726,29 +778,16 @@ static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans) {
}
static
int32_t
mndTransPerformCommitStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
int32_t
code
=
mndTransExecuteCommitLogs
(
pMnode
,
pTrans
);
if
(
code
==
0
)
{
pTrans
->
stage
=
TRN_STAGE_OVER
;
mTrace
(
"trans:%d, commit stage finished"
,
pTrans
->
id
);
}
else
{
if
(
pTrans
->
policy
==
TRN_POLICY_ROLLBACK
)
{
pTrans
->
stage
=
TRN_STAGE_ROLLBACK
;
mError
(
"trans:%d, stage from commit to rollback since %s"
,
pTrans
->
id
,
terrstr
());
}
else
{
pTrans
->
stage
=
TRN_STAGE_RETRY
;
mError
(
"trans:%d, stage from commit to retry since %s"
,
pTrans
->
id
,
terrstr
());
}
}
return
code
;
mndTransExecuteCommitLogs
(
pMnode
,
pTrans
);
pTrans
->
stage
=
TRN_STAGE_OVER
;
return
0
;
}
static
int32_t
mndTransPerformRollbackStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
int32_t
code
=
mndTransExecuteUndoActions
(
pMnode
,
pTrans
);
if
(
code
==
0
)
{
m
Trace
(
"trans:%d, rollbacked"
,
pTrans
->
id
);
m
Debug
(
"trans:%d, rollbacked"
,
pTrans
->
id
);
}
else
{
pTrans
->
stage
=
TRN_STAGE_ROLLBACK
;
mError
(
"trans:%d, stage keep on rollback since %s"
,
pTrans
->
id
,
terrstr
());
...
...
@@ -757,20 +796,6 @@ static int32_t mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans) {
return
code
;
}
static
int32_t
mndTransPerformRetryStage
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
int32_t
code
=
mndTransExecuteRedoActions
(
pMnode
,
pTrans
);
if
(
code
==
0
)
{
pTrans
->
stage
=
TRN_STAGE_COMMIT
;
mTrace
(
"trans:%d, stage from retry to commit"
,
pTrans
->
id
);
}
else
{
pTrans
->
stage
=
TRN_STAGE_RETRY
;
mError
(
"trans:%d, stage keep on retry since %s"
,
pTrans
->
id
,
terrstr
());
}
return
code
;
}
static
void
mndTransExecute
(
SMnode
*
pMnode
,
STrans
*
pTrans
)
{
int32_t
code
=
0
;
...
...
@@ -785,7 +810,7 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) {
case
TRN_STAGE_COMMIT
:
code
=
mndTransCommit
(
pMnode
,
pTrans
);
if
(
code
==
0
)
{
code
=
mndTransPerformCommitStage
(
pMnode
,
pTrans
);
mndTransPerformCommitStage
(
pMnode
,
pTrans
);
}
break
;
case
TRN_STAGE_ROLLBACK
:
...
...
@@ -794,9 +819,6 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) {
code
=
mndTransRollback
(
pMnode
,
pTrans
);
}
break
;
case
TRN_STAGE_RETRY
:
code
=
mndTransPerformRetryStage
(
pMnode
,
pTrans
);
break
;
default:
mndTransSendRpcRsp
(
pTrans
,
0
);
return
;
...
...
source/dnode/mnode/impl/src/mndUser.c
浏览文件 @
2d315222
...
...
@@ -20,7 +20,7 @@
#include "mndTrans.h"
#include "tkey.h"
#define TSDB_USER_VER 1
#define TSDB_USER_VER
_NUMBER
1
#define TSDB_USER_RESERVE_SIZE 64
static
int32_t
mndCreateDefaultUsers
(
SMnode
*
pMnode
);
...
...
@@ -94,7 +94,7 @@ static int32_t mndCreateDefaultUsers(SMnode *pMnode) {
}
static
SSdbRaw
*
mndUserActionEncode
(
SUserObj
*
pUser
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_USER
,
TSDB_USER_VER
,
sizeof
(
SUserObj
)
+
TSDB_USER_RESERVE_SIZE
);
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_USER
,
TSDB_USER_VER
_NUMBER
,
sizeof
(
SUserObj
)
+
TSDB_USER_RESERVE_SIZE
);
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
...
...
@@ -114,7 +114,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
TSDB_USER_VER
)
{
if
(
sver
!=
TSDB_USER_VER
_NUMBER
)
{
mError
(
"failed to decode user since %s"
,
terrstr
());
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
return
NULL
;
...
...
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
2d315222
...
...
@@ -21,7 +21,7 @@
#include "mndShow.h"
#include "mndTrans.h"
#define TSDB_VGROUP_VER_NUM 1
#define TSDB_VGROUP_VER_NUM
BER
1
#define TSDB_VGROUP_RESERVE_SIZE 64
static
SSdbRow
*
mndVgroupActionDecode
(
SSdbRaw
*
pRaw
);
...
...
@@ -70,7 +70,7 @@ int32_t mndInitVgroup(SMnode *pMnode) {
void
mndCleanupVgroup
(
SMnode
*
pMnode
)
{}
SSdbRaw
*
mndVgroupActionEncode
(
SVgObj
*
pVgroup
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_VGROUP
,
TSDB_VGROUP_VER_NUM
,
sizeof
(
SVgObj
)
+
TSDB_VGROUP_RESERVE_SIZE
);
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_VGROUP
,
TSDB_VGROUP_VER_NUM
BER
,
sizeof
(
SVgObj
)
+
TSDB_VGROUP_RESERVE_SIZE
);
if
(
pRaw
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
...
...
@@ -98,7 +98,7 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
if
(
sver
!=
TSDB_VGROUP_VER_NUM
)
{
if
(
sver
!=
TSDB_VGROUP_VER_NUM
BER
)
{
mError
(
"failed to decode vgroup since %s"
,
terrstr
());
terrno
=
TSDB_CODE_SDB_INVALID_DATA_VER
;
return
NULL
;
...
...
@@ -142,14 +142,20 @@ static int32_t mndVgroupActionUpdate(SSdb *pSdb, SVgObj *pOldVgroup, SVgObj *pNe
mTrace
(
"vgId:%d, perform update action"
,
pOldVgroup
->
vgId
);
pOldVgroup
->
updateTime
=
pNewVgroup
->
updateTime
;
pOldVgroup
->
version
=
pNewVgroup
->
version
;
pOldVgroup
->
hashBegin
=
pNewVgroup
->
hashBegin
;
pOldVgroup
->
hashEnd
=
pNewVgroup
->
hashEnd
;
pOldVgroup
->
replica
=
pNewVgroup
->
replica
;
memcpy
(
pOldVgroup
->
vnodeGid
,
pNewVgroup
->
vnodeGid
,
TSDB_MAX_REPLICA
*
sizeof
(
SVnodeGid
));
return
0
;
}
SVgObj
*
mndAcquireVgroup
(
SMnode
*
pMnode
,
int32_t
vgId
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
return
sdbAcquire
(
pSdb
,
SDB_VGROUP
,
&
vgId
);
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SVgObj
*
pVgroup
=
sdbAcquire
(
pSdb
,
SDB_VGROUP
,
&
vgId
);
if
(
pVgroup
==
NULL
)
{
terrno
=
TSDB_CODE_MND_VGROUP_NOT_EXIST
;
}
return
pVgroup
;
}
void
mndReleaseVgroup
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
)
{
...
...
@@ -158,16 +164,17 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup) {
}
SCreateVnodeMsg
*
mndBuildCreateVnodeMsg
(
SMnode
*
pMnode
,
SDnodeObj
*
pDnode
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
)
{
SCreateVnodeMsg
*
pCreate
=
malloc
(
sizeof
(
SCreateVnodeMsg
));
SCreateVnodeMsg
*
pCreate
=
calloc
(
1
,
sizeof
(
SCreateVnodeMsg
));
if
(
pCreate
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
pCreate
->
dnodeId
=
htonl
(
pDnode
->
id
);
pCreate
->
vgId
=
htonl
(
pVgroup
->
vgId
);
pCreate
->
dnodeId
=
htonl
(
pDnode
->
id
);
memcpy
(
pCreate
->
db
,
pDb
->
name
,
TSDB_FULL_DB_NAME_LEN
);
pCreate
->
dbUid
=
htobe64
(
pDb
->
uid
);
pCreate
->
vgVersion
=
htonl
(
pVgroup
->
version
);
pCreate
->
cacheBlockSize
=
htonl
(
pDb
->
cfg
.
cacheBlockSize
);
pCreate
->
totalBlocks
=
htonl
(
pDb
->
cfg
.
totalBlocks
);
pCreate
->
daysPerFile
=
htonl
(
pDb
->
cfg
.
daysPerFile
);
...
...
@@ -193,7 +200,6 @@ SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbOb
SDnodeObj
*
pVgidDnode
=
mndAcquireDnode
(
pMnode
,
pVgid
->
dnodeId
);
if
(
pVgidDnode
==
NULL
)
{
free
(
pCreate
);
terrno
=
TSDB_CODE_MND_APP_ERROR
;
return
NULL
;
}
...
...
@@ -217,7 +223,7 @@ SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbOb
}
SDropVnodeMsg
*
mndBuildDropVnodeMsg
(
SMnode
*
pMnode
,
SDnodeObj
*
pDnode
,
SDbObj
*
pDb
,
SVgObj
*
pVgroup
)
{
SDropVnodeMsg
*
pDrop
=
malloc
(
sizeof
(
SDropVnodeMsg
));
SDropVnodeMsg
*
pDrop
=
calloc
(
1
,
sizeof
(
SDropVnodeMsg
));
if
(
pDrop
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
...
...
@@ -269,7 +275,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
return
-
1
;
}
int32_t
alloceVgroups
=
0
;
int32_t
alloce
d
Vgroups
=
0
;
int32_t
maxVgId
=
sdbGetMaxId
(
pMnode
->
pSdb
,
SDB_VGROUP
);
uint32_t
hashMin
=
0
;
uint32_t
hashMax
=
UINT32_MAX
;
...
...
@@ -281,7 +287,6 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
pVgroup
->
createdTime
=
taosGetTimestampMs
();
pVgroup
->
updateTime
=
pVgroups
->
createdTime
;
pVgroup
->
version
=
1
;
pVgroup
->
dbUid
=
pDb
->
uid
;
pVgroup
->
hashBegin
=
hashMin
+
hashInterval
*
v
;
if
(
v
==
pDb
->
cfg
.
numOfVgroups
-
1
)
{
pVgroup
->
hashEnd
=
hashMax
;
...
...
@@ -290,6 +295,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
}
memcpy
(
pVgroup
->
dbName
,
pDb
->
name
,
TSDB_FULL_DB_NAME_LEN
);
pVgroup
->
dbUid
=
pDb
->
uid
;
pVgroup
->
replica
=
pDb
->
cfg
.
replications
;
if
(
mndGetAvailableDnode
(
pMnode
,
pVgroup
)
!=
0
)
{
...
...
@@ -298,22 +304,25 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
return
-
1
;
}
alloceVgroups
++
;
alloce
d
Vgroups
++
;
}
*
ppVgroups
=
pVgroups
;
return
0
;
}
static
int32_t
mndProcessCreateVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessCreateVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
mndTransHandleActionRsp
(
pMsg
);
return
0
;
}
static
int32_t
mndProcessAlterVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessDropVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessSyncVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndProcessCompactVnodeRsp
(
SMnodeMsg
*
pMsg
)
{
return
0
;
}
static
int32_t
mndGetVgroupMaxReplica
(
SMnode
*
pMnode
,
char
*
dbName
,
int8_t
*
pReplica
,
int32_t
*
pNumOfVgroups
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SDbObj
*
pDb
=
mndAcquireDb
(
pMnode
,
dbName
);
if
(
pDb
==
NULL
)
{
terrno
=
TSDB_CODE_MND_DB_NOT_SELECTED
;
...
...
@@ -329,7 +338,7 @@ static int32_t mndGetVgroupMaxReplica(SMnode *pMnode, char *dbName, int8_t *pRep
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pIter
,
(
void
**
)
&
pVgroup
);
if
(
pIter
==
NULL
)
break
;
if
(
strcmp
(
pVgroup
->
dbName
,
dbName
)
==
0
)
{
if
(
pVgroup
->
dbUid
==
pDb
->
uid
)
{
replica
=
MAX
(
replica
,
pVgroup
->
replica
);
numOfVgroups
++
;
}
...
...
@@ -441,11 +450,25 @@ static void mndCancelGetNextVgroup(SMnode *pMnode, void *pIter) {
}
static
int32_t
mndGetVnodesNum
(
SMnode
*
pMnode
,
int32_t
dnodeId
)
{
if
(
dnodeId
==
0
)
{
return
0
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfVnodes
=
0
;
void
*
pIter
=
NULL
;
while
(
1
)
{
SVgObj
*
pVgroup
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pIter
,
(
void
**
)
&
pVgroup
);
if
(
pIter
==
NULL
)
break
;
for
(
int32_t
v
=
0
;
v
<
pVgroup
->
replica
;
++
v
)
{
if
(
pVgroup
->
vnodeGid
[
v
].
dnodeId
==
dnodeId
)
{
numOfVnodes
++
;
}
}
sdbRelease
(
pSdb
,
pVgroup
);
}
return
0
;
return
numOfVnodes
;
}
static
int32_t
mndGetVnodeMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
...
...
source/dnode/mnode/impl/src/mnode.c
浏览文件 @
2d315222
...
...
@@ -225,7 +225,7 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
}
return
0
;
}
}
SMnode
*
mndOpen
(
const
char
*
path
,
const
SMnodeOpt
*
pOption
)
{
mDebug
(
"start to open mnode in %s"
,
path
);
...
...
@@ -237,6 +237,9 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
return
NULL
;
}
char
timestr
[
24
]
=
"1970-01-01 00:00:00.00"
;
(
void
)
taosParseTime
(
timestr
,
&
pMnode
->
checkTime
,
(
int32_t
)
strlen
(
timestr
),
TSDB_TIME_PRECISION_MILLI
,
0
);
pMnode
->
pSteps
=
taosArrayInit
(
24
,
sizeof
(
SMnodeStep
));
if
(
pMnode
->
pSteps
==
NULL
)
{
free
(
pMnode
);
...
...
source/dnode/mnode/sdb/src/sdbRaw.c
浏览文件 @
2d315222
...
...
@@ -27,12 +27,12 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
pRaw
->
sver
=
sver
;
pRaw
->
dataLen
=
dataLen
;
mTrace
(
"raw:%p, is created, len:%d"
,
pRaw
,
dataLen
);
//
mTrace("raw:%p, is created, len:%d", pRaw, dataLen);
return
pRaw
;
}
void
sdbFreeRaw
(
SSdbRaw
*
pRaw
)
{
mTrace
(
"raw:%p, is freed"
,
pRaw
);
//
mTrace("raw:%p, is freed", pRaw);
free
(
pRaw
);
}
...
...
source/dnode/vnode/impl/src/vnodeWrite.c
浏览文件 @
2d315222
...
...
@@ -16,17 +16,13 @@
#include "vnodeDef.h"
int
vnodeProcessNoWalWMsgs
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
)
{
SVnodeReq
*
pVnodeReq
;
switch
(
pMsg
->
msgType
)
{
case
TSDB_MSG_TYPE_MQ_SET
:
case
TSDB_MSG_TYPE_MQ_SET
_CUR
:
if
(
tqSetCursor
(
pVnode
->
pTq
,
pMsg
->
pCont
)
<
0
)
{
// TODO: handle error
}
break
;
}
void
*
pBuf
=
pMsg
->
pCont
;
return
0
;
}
...
...
source/dnode/vnode/tq/CMakeLists.txt
浏览文件 @
2d315222
...
...
@@ -11,6 +11,7 @@ target_link_libraries(
PUBLIC wal
PUBLIC os
PUBLIC util
PUBLIC common
)
if
(
${
BUILD_TEST
}
)
...
...
source/dnode/vnode/tq/inc/tqInt.h
浏览文件 @
2d315222
...
...
@@ -17,11 +17,20 @@
#define _TD_TQ_INT_H_
#include "tq.h"
#include "tlog.h"
#ifdef __cplusplus
extern
"C"
{
#endif
extern
int32_t
tqDebugFlag
;
#define tqFatal(...) { if (tqDebugFlag & DEBUG_FATAL) { taosPrintLog("TQ FATAL ", 255, __VA_ARGS__); }}
#define tqError(...) { if (tqDebugFlag & DEBUG_ERROR) { taosPrintLog("TQ ERROR ", 255, __VA_ARGS__); }}
#define tqWarn(...) { if (tqDebugFlag & DEBUG_WARN) { taosPrintLog("TQ WARN ", 255, __VA_ARGS__); }}
#define tqInfo(...) { if (tqDebugFlag & DEBUG_INFO) { taosPrintLog("TQ ", 255, __VA_ARGS__); }}
#define tqDebug(...) { if (tqDebugFlag & DEBUG_DEBUG) { taosPrintLog("TQ ", tqDebugFlag, __VA_ARGS__); }}
#define tqTrace(...) { if (tqDebugFlag & DEBUG_TRACE) { taosPrintLog("TQ ", tqDebugFlag, __VA_ARGS__); }}
// create persistent storage for meta info such as consuming offset
// return value > 0: cgId
// return value <= 0: error code
...
...
source/dnode/vnode/tq/inc/tqMetaStore.h
浏览文件 @
2d315222
...
...
@@ -17,7 +17,7 @@
#define _TQ_META_STORE_H_
#include "os.h"
#include "tq.h"
#include "tq
Int
.h"
#ifdef __cplusplus
extern
"C"
{
...
...
source/dnode/vnode/tq/src/tq.c
浏览文件 @
2d315222
...
...
@@ -24,89 +24,80 @@
// handle management message
//
int
tqG
etgHandleSSize
(
const
STqGroupHandle
*
gHandle
);
int
tq
BufHandle
SSize
();
int
tq
Buf
ItemSSize
();
int
tqG
roupSSize
(
const
STqGroup
*
pGroup
);
int
tq
Topic
SSize
();
int
tqItemSSize
();
STqGroupHandle
*
tqFindHandle
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
STqGroupHandle
*
gHandle
;
return
NULL
;
}
void
*
tqSerializeListHandle
(
STqList
*
listHandle
,
void
*
ptr
);
void
*
tqSerializeTopic
(
STqTopic
*
pTopic
,
void
*
ptr
);
void
*
tqSerializeItem
(
STqMsgItem
*
pItem
,
void
*
ptr
);
void
*
tqSerializeListHandle
(
STqListHandle
*
listHandle
,
void
*
ptr
);
void
*
tqSerializeBufHandle
(
STqBufferHandle
*
bufHandle
,
void
*
ptr
);
void
*
tqSerializeBufItem
(
STqBufferItem
*
bufItem
,
void
*
ptr
);
const
void
*
tqDeserializeBufHandle
(
const
void
*
pBytes
,
STqBufferHandle
*
bufHandle
);
const
void
*
tqDeserializeBufItem
(
const
void
*
pBytes
,
STqBufferItem
*
bufItem
);
const
void
*
tqDeserializeTopic
(
const
void
*
pBytes
,
STqTopic
*
pTopic
);
const
void
*
tqDeserializeItem
(
const
void
*
pBytes
,
STqMsgItem
*
pItem
);
STQ
*
tqOpen
(
const
char
*
path
,
STqCfg
*
tqConfig
,
STqLogReader
*
tqLogReader
,
SMemAllocatorFactory
*
allocFac
)
{
STQ
*
pTq
=
malloc
(
sizeof
(
STQ
));
if
(
pTq
==
NULL
)
{
// TODO: memory error
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
return
NULL
;
}
pTq
->
path
=
strdup
(
path
);
pTq
->
tqConfig
=
tqConfig
;
pTq
->
tqLogReader
=
tqLogReader
;
pTq
->
tqMemRef
.
pAlloctorFactory
=
allocFac
;
//
pTq->tqMemRef.pAllocator = allocFac->create(allocFac);
pTq
->
tqMemRef
.
pAllocator
=
allocFac
->
create
(
allocFac
);
if
(
pTq
->
tqMemRef
.
pAllocator
==
NULL
)
{
// TODO
// TODO
: error code of buffer pool
}
pTq
->
tqMeta
=
tqStoreOpen
(
path
,
(
FTqSerialize
)
tqSerializeGroupHandle
,
(
FTqDeserialize
)
tqDeserializeGroupHandle
,
free
,
0
);
pTq
->
tqMeta
=
tqStoreOpen
(
path
,
(
FTqSerialize
)
tqSerializeGroup
,
(
FTqDeserialize
)
tqDeserializeGroup
,
free
,
0
);
if
(
pTq
->
tqMeta
==
NULL
)
{
// TODO: free STQ
return
NULL
;
}
return
pTq
;
}
void
tqClose
(
STQ
*
pTq
)
{
void
tqClose
(
STQ
*
pTq
)
{
// TODO
}
static
int
tqProtoCheck
(
TmqMsgHead
*
pMsg
)
{
return
pMsg
->
protoVer
==
0
;
}
static
int
tqProtoCheck
(
STqMsgHead
*
pMsg
)
{
return
pMsg
->
protoVer
==
0
;
}
static
int
tqAckOneTopic
(
STq
BufferHandle
*
bHandle
,
Tm
qOneAck
*
pAck
,
STqQueryMsg
**
ppQuery
)
{
static
int
tqAckOneTopic
(
STq
Topic
*
pTopic
,
ST
qOneAck
*
pAck
,
STqQueryMsg
**
ppQuery
)
{
// clean old item and move forward
int32_t
consumeOffset
=
pAck
->
consumeOffset
;
int
idx
=
consumeOffset
%
TQ_BUFFER_SIZE
;
ASSERT
(
bHandle
->
buffer
[
idx
].
content
&&
bHandle
->
buffer
[
idx
].
executor
);
tfree
(
bHandle
->
buffer
[
idx
].
content
);
ASSERT
(
pTopic
->
buffer
[
idx
].
content
&&
pTopic
->
buffer
[
idx
].
executor
);
tfree
(
pTopic
->
buffer
[
idx
].
content
);
if
(
1
/* TODO: need to launch new query */
)
{
STqQueryMsg
*
pNewQuery
=
malloc
(
sizeof
(
STqQueryMsg
));
if
(
pNewQuery
==
NULL
)
{
// TODO: memory insufficient
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
return
-
1
;
}
// TODO: lock executor
pNewQuery
->
exec
->
executor
=
bHandle
->
buffer
[
idx
].
executor
;
// TODO: read from wal and assign to src
pNewQuery
->
exec
->
src
=
0
;
pNewQuery
->
exec
->
dest
=
&
bHandle
->
buffer
[
idx
];
pNewQuery
->
next
=
*
ppQuery
;
*
ppQuery
=
pNewQuery
;
/*pNewQuery->exec->executor = pTopic->buffer[idx].executor;*/
/*pNewQuery->exec->src = 0;*/
/*pNewQuery->exec->dest = &pTopic->buffer[idx];*/
/*pNewQuery->next = *ppQuery;*/
/**ppQuery = pNewQuery;*/
}
return
0
;
}
static
int
tqAck
(
STqGroup
Handle
*
gHandle
,
Tm
qAcks
*
pAcks
)
{
static
int
tqAck
(
STqGroup
*
pGroup
,
ST
qAcks
*
pAcks
)
{
int32_t
ackNum
=
pAcks
->
ackNum
;
Tm
qOneAck
*
acks
=
pAcks
->
acks
;
ST
qOneAck
*
acks
=
pAcks
->
acks
;
// double ptr for acks and list
int
i
=
0
;
STqList
Handle
*
node
=
gHandle
->
head
;
int
ackCnt
=
0
;
STqQueryMsg
*
pQuery
=
NULL
;
int
i
=
0
;
STqList
*
node
=
pGroup
->
head
;
int
ackCnt
=
0
;
STqQueryMsg
*
pQuery
=
NULL
;
while
(
i
<
ackNum
&&
node
->
next
)
{
if
(
acks
[
i
].
topicId
==
node
->
next
->
bufHandle
.
topicId
)
{
if
(
acks
[
i
].
topicId
==
node
->
next
->
topic
.
topicId
)
{
ackCnt
++
;
tqAckOneTopic
(
&
node
->
next
->
bufHandle
,
&
acks
[
i
],
&
pQuery
);
}
else
if
(
acks
[
i
].
topicId
<
node
->
next
->
bufHandle
.
topicId
)
{
tqAckOneTopic
(
&
node
->
next
->
topic
,
&
acks
[
i
],
&
pQuery
);
}
else
if
(
acks
[
i
].
topicId
<
node
->
next
->
topic
.
topicId
)
{
i
++
;
}
else
{
node
=
node
->
next
;
...
...
@@ -118,52 +109,56 @@ static int tqAck(STqGroupHandle* gHandle, TmqAcks* pAcks) {
return
ackCnt
;
}
static
int
tqCommit
TCGroup
(
STqGroupHandle
*
handle
)
{
static
int
tqCommit
Group
(
STqGroup
*
pGroup
)
{
// persist modification into disk
return
0
;
}
int
tqCreate
TCGroup
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
,
STqGroupHandle
**
handle
)
{
int
tqCreate
Group
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
,
STqGroup
**
ppGroup
)
{
// create in disk
STqGroup
Handle
*
gHandle
=
(
STqGroupHandle
*
)
malloc
(
sizeof
(
STqGroupHandle
));
if
(
gHandle
==
NULL
)
{
STqGroup
*
pGroup
=
(
STqGroup
*
)
malloc
(
sizeof
(
STqGroup
));
if
(
pGroup
==
NULL
)
{
// TODO
return
-
1
;
}
memset
(
gHandle
,
0
,
sizeof
(
STqGroupHandle
));
*
ppGroup
=
pGroup
;
memset
(
pGroup
,
0
,
sizeof
(
STqGroup
));
return
0
;
}
STqGroup
Handle
*
tqOpenTC
Group
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
STqGroup
Handle
*
gHandle
=
tqHandleGet
(
pTq
->
tqMeta
,
cId
);
if
(
gHandle
==
NULL
)
{
int
code
=
tqCreate
TCGroup
(
pTq
,
topicId
,
cgId
,
cId
,
&
gHandle
);
if
(
code
!=
0
)
{
STqGroup
*
tqOpen
Group
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
STqGroup
*
pGroup
=
tqHandleGet
(
pTq
->
tqMeta
,
cId
);
if
(
pGroup
==
NULL
)
{
int
code
=
tqCreate
Group
(
pTq
,
topicId
,
cgId
,
cId
,
&
pGroup
);
if
(
code
<
0
)
{
// TODO
return
NULL
;
}
tqHandleMovePut
(
pTq
->
tqMeta
,
cId
,
pGroup
);
}
ASSERT
(
pGroup
);
// create
// open
return
gHandle
;
return
pGroup
;
}
int
tqCloseTCGroup
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
return
0
;
}
int
tqCloseGroup
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
// TODO
return
0
;
}
int
tqDrop
TC
Group
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
int
tqDropGroup
(
STQ
*
pTq
,
int64_t
topicId
,
int64_t
cgId
,
int64_t
cId
)
{
// delete from disk
return
0
;
}
static
int
tqFetch
(
STqGroup
Handle
*
gHandle
,
void
**
msg
)
{
STqList
Handle
*
head
=
gHandle
->
head
;
STqList
Handle
*
node
=
head
;
int
totSize
=
0
;
static
int
tqFetch
(
STqGroup
*
pGroup
,
void
**
msg
)
{
STqList
*
head
=
pGroup
->
head
;
STqList
*
node
=
head
;
int
totSize
=
0
;
// TODO: make it a macro
int
sizeLimit
=
4
*
1024
;
Tm
qMsgContent
*
buffer
=
malloc
(
sizeLimit
);
ST
qMsgContent
*
buffer
=
malloc
(
sizeLimit
);
if
(
buffer
==
NULL
)
{
// TODO:memory insufficient
return
-
1
;
...
...
@@ -172,25 +167,25 @@ static int tqFetch(STqGroupHandle* gHandle, void** msg) {
// until all topic iterated or msgs over sizeLimit
while
(
node
->
next
)
{
node
=
node
->
next
;
STq
BufferHandle
*
bufHandle
=
&
node
->
bufHandle
;
int
idx
=
buf
Handle
->
nextConsumeOffset
%
TQ_BUFFER_SIZE
;
if
(
bufHandle
->
buffer
[
idx
].
content
!=
NULL
&&
bufHandle
->
buffer
[
idx
].
offset
==
buf
Handle
->
nextConsumeOffset
)
{
totSize
+=
buf
Handle
->
buffer
[
idx
].
size
;
STq
Topic
*
topicHandle
=
&
node
->
topic
;
int
idx
=
topic
Handle
->
nextConsumeOffset
%
TQ_BUFFER_SIZE
;
if
(
topicHandle
->
buffer
[
idx
].
content
!=
NULL
&&
topicHandle
->
buffer
[
idx
].
offset
==
topic
Handle
->
nextConsumeOffset
)
{
totSize
+=
topic
Handle
->
buffer
[
idx
].
size
;
if
(
totSize
>
sizeLimit
)
{
void
*
ptr
=
realloc
(
buffer
,
totSize
);
if
(
ptr
==
NULL
)
{
totSize
-=
buf
Handle
->
buffer
[
idx
].
size
;
totSize
-=
topic
Handle
->
buffer
[
idx
].
size
;
// TODO:memory insufficient
// return msgs already copied
break
;
}
}
*
((
int64_t
*
)
buffer
)
=
buf
Handle
->
topicId
;
*
((
int64_t
*
)
buffer
)
=
topic
Handle
->
topicId
;
buffer
=
POINTER_SHIFT
(
buffer
,
sizeof
(
int64_t
));
*
((
int64_t
*
)
buffer
)
=
buf
Handle
->
buffer
[
idx
].
size
;
*
((
int64_t
*
)
buffer
)
=
topic
Handle
->
buffer
[
idx
].
size
;
buffer
=
POINTER_SHIFT
(
buffer
,
sizeof
(
int64_t
));
memcpy
(
buffer
,
bufHandle
->
buffer
[
idx
].
content
,
buf
Handle
->
buffer
[
idx
].
size
);
buffer
=
POINTER_SHIFT
(
buffer
,
buf
Handle
->
buffer
[
idx
].
size
);
memcpy
(
buffer
,
topicHandle
->
buffer
[
idx
].
content
,
topic
Handle
->
buffer
[
idx
].
size
);
buffer
=
POINTER_SHIFT
(
buffer
,
topic
Handle
->
buffer
[
idx
].
size
);
if
(
totSize
>
sizeLimit
)
{
break
;
}
...
...
@@ -199,11 +194,19 @@ static int tqFetch(STqGroupHandle* gHandle, void** msg) {
return
totSize
;
}
STqGroupHandle
*
tqGetGroupHandle
(
STQ
*
pTq
,
int64_t
cId
)
{
return
NULL
;
}
int
tqLaunchQuery
(
STqGroupHandle
*
gHandle
)
{
return
0
;
}
STqGroup
*
tqGetGroup
(
STQ
*
pTq
,
int64_t
clientId
)
{
return
tqHandleGet
(
pTq
->
tqMeta
,
clientId
);
}
int
tqSendLaunchQuery
(
STqGroupHandle
*
gHandle
)
{
return
0
;
}
int
tqSendLaunchQuery
(
STqMsgItem
*
bufItem
,
int64_t
offset
)
{
if
(
tqQueryExecuting
(
bufItem
->
status
))
{
return
0
;
}
bufItem
->
status
=
1
;
// load data from wal or buffer pool
// put into exec
// send exec into non blocking queue
// when query finished, put into buffer pool
return
0
;
}
/*int tqMoveOffsetToNext(TqGroupHandle* gHandle) {*/
/*return 0;*/
...
...
@@ -220,23 +223,96 @@ int tqCommit(STQ* pTq) {
return
0
;
}
int
tqSetCursor
(
STQ
*
pTq
,
void
*
msg
)
{
int
tqBufferSetOffset
(
STqTopic
*
pTopic
,
int64_t
offset
)
{
int
code
;
memset
(
pTopic
->
buffer
,
0
,
sizeof
(
pTopic
->
buffer
));
// launch query
for
(
int
i
=
offset
;
i
<
offset
+
TQ_BUFFER_SIZE
;
i
++
)
{
int
pos
=
i
%
TQ_BUFFER_SIZE
;
code
=
tqSendLaunchQuery
(
&
pTopic
->
buffer
[
pos
],
offset
);
if
(
code
<
0
)
{
// TODO: error handling
}
}
// set offset
pTopic
->
nextConsumeOffset
=
offset
;
pTopic
->
floatingCursor
=
offset
;
return
0
;
}
STqTopic
*
tqFindTopic
(
STqGroup
*
pGroup
,
int64_t
topicId
)
{
// TODO
return
NULL
;
}
int
tqSetCursor
(
STQ
*
pTq
,
STqSetCurReq
*
pMsg
)
{
int
code
;
int64_t
clientId
=
pMsg
->
head
.
clientId
;
int64_t
topicId
=
pMsg
->
topicId
;
int64_t
offset
=
pMsg
->
offset
;
STqGroup
*
gHandle
=
tqGetGroup
(
pTq
,
clientId
);
if
(
gHandle
==
NULL
)
{
// client not connect
return
-
1
;
}
STqTopic
*
topicHandle
=
tqFindTopic
(
gHandle
,
topicId
);
if
(
topicHandle
==
NULL
)
{
return
-
1
;
}
if
(
pMsg
->
offset
==
topicHandle
->
nextConsumeOffset
)
{
return
0
;
}
// TODO: check log last version
code
=
tqBufferSetOffset
(
topicHandle
,
offset
);
if
(
code
<
0
)
{
// set error code
return
-
1
;
}
return
0
;
}
int
tqConsume
(
STQ
*
pTq
,
STqConsumeReq
*
pMsg
)
{
int64_t
clientId
=
pMsg
->
head
.
clientId
;
STqGroup
*
pGroup
=
tqGetGroup
(
pTq
,
clientId
);
if
(
pGroup
==
NULL
)
{
terrno
=
TSDB_CODE_TQ_GROUP_NOT_SET
;
return
-
1
;
}
STqConsumeRsp
*
pRsp
=
(
STqConsumeRsp
*
)
pMsg
;
int
numOfMsgs
=
tqFetch
(
pGroup
,
(
void
**
)
&
pRsp
->
msgs
);
if
(
numOfMsgs
<
0
)
{
return
-
1
;
}
if
(
numOfMsgs
==
0
)
{
// most recent data has been fetched
// enable timer for blocking wait
// once new data written during wait time
// launch query and response
}
// fetched a num of msgs, rpc response
return
0
;
}
#if 0
int tqConsume(STQ* pTq, STqConsumeReq* pMsg) {
if
(
!
tqProtoCheck
((
Tm
qMsgHead
*
)
pMsg
))
{
if (!tqProtoCheck((
ST
qMsgHead*)pMsg)) {
// proto version invalid
return -1;
}
int64_t
clientId
=
pMsg
->
head
.
clientId
;
STqGroup
Handle
*
gHandle
=
tqGetGroupHandle
(
pTq
,
clientId
);
if
(
gHandle
==
NULL
)
{
int64_t clientId = pMsg->head.clientId;
STqGroup
* pGroup = tqGetGroup
(pTq, clientId);
if (
pGroup
== NULL) {
// client not connect
return -1;
}
if (pMsg->acks.ackNum != 0) {
if
(
tqAck
(
gHandle
,
&
pMsg
->
acks
)
!=
0
)
{
if (tqAck(
pGroup
, &pMsg->acks) != 0) {
// ack not success
return -1;
}
...
...
@@ -244,22 +320,23 @@ int tqConsume(STQ* pTq, STqConsumeReq* pMsg) {
STqConsumeRsp* pRsp = (STqConsumeRsp*)pMsg;
if
(
tqFetch
(
gHandle
,
(
void
**
)
&
pRsp
->
msgs
)
<=
0
)
{
if (tqFetch(
pGroup
, (void**)&pRsp->msgs) <= 0) {
// fetch error
return -1;
}
// judge and launch new query
if
(
tqLaunchQuery
(
gHandle
))
{
// launch query error
return
-
1
;
}
/*if (tqSendLaunchQuery(gHandle)) {*/
// launch query error
/*return -1;*/
/*}*/
return 0;
}
#endif
int
tqSerializeGroup
Handle
(
const
STqGroupHandle
*
gHandle
,
STqSerializedHead
**
ppHead
)
{
int
tqSerializeGroup
(
const
STqGroup
*
pGroup
,
STqSerializedHead
**
ppHead
)
{
// calculate size
int
sz
=
tqG
etgHandleSSize
(
gHandle
)
+
sizeof
(
STqSerializedHead
);
int
sz
=
tqG
roupSSize
(
pGroup
)
+
sizeof
(
STqSerializedHead
);
if
(
sz
>
(
*
ppHead
)
->
ssize
)
{
void
*
tmpPtr
=
realloc
(
*
ppHead
,
sz
);
if
(
tmpPtr
==
NULL
)
{
...
...
@@ -272,53 +349,53 @@ int tqSerializeGroupHandle(const STqGroupHandle* gHandle, STqSerializedHead** pp
}
void
*
ptr
=
(
*
ppHead
)
->
content
;
// do serialization
*
(
int64_t
*
)
ptr
=
gHandle
->
c
Id
;
*
(
int64_t
*
)
ptr
=
pGroup
->
client
Id
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
*
(
int64_t
*
)
ptr
=
gHandle
->
cgId
;
*
(
int64_t
*
)
ptr
=
pGroup
->
cgId
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
*
(
int32_t
*
)
ptr
=
gHandle
->
topicNum
;
*
(
int32_t
*
)
ptr
=
pGroup
->
topicNum
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
if
(
gHandle
->
topicNum
>
0
)
{
tqSerializeListHandle
(
gHandle
->
head
,
ptr
);
if
(
pGroup
->
topicNum
>
0
)
{
tqSerializeListHandle
(
pGroup
->
head
,
ptr
);
}
return
0
;
}
void
*
tqSerializeListHandle
(
STqList
Handle
*
listHandle
,
void
*
ptr
)
{
STqList
Handle
*
node
=
listHandle
;
void
*
tqSerializeListHandle
(
STqList
*
listHandle
,
void
*
ptr
)
{
STqList
*
node
=
listHandle
;
ASSERT
(
node
!=
NULL
);
while
(
node
)
{
ptr
=
tqSerialize
BufHandle
(
&
node
->
bufHandle
,
ptr
);
ptr
=
tqSerialize
Topic
(
&
node
->
topic
,
ptr
);
node
=
node
->
next
;
}
return
ptr
;
}
void
*
tqSerialize
BufHandle
(
STqBufferHandle
*
bufHandle
,
void
*
ptr
)
{
*
(
int64_t
*
)
ptr
=
bufHandle
->
nextConsumeOffset
;
void
*
tqSerialize
Topic
(
STqTopic
*
pTopic
,
void
*
ptr
)
{
*
(
int64_t
*
)
ptr
=
pTopic
->
nextConsumeOffset
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
*
(
int64_t
*
)
ptr
=
bufHandle
->
topicId
;
*
(
int64_t
*
)
ptr
=
pTopic
->
topicId
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
*
(
int32_t
*
)
ptr
=
bufHandle
->
head
;
*
(
int32_t
*
)
ptr
=
pTopic
->
head
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
*
(
int32_t
*
)
ptr
=
bufHandle
->
tail
;
*
(
int32_t
*
)
ptr
=
pTopic
->
tail
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
for
(
int
i
=
0
;
i
<
TQ_BUFFER_SIZE
;
i
++
)
{
ptr
=
tqSerialize
BufItem
(
&
bufHandle
->
buffer
[
i
],
ptr
);
ptr
=
tqSerialize
Item
(
&
pTopic
->
buffer
[
i
],
ptr
);
}
return
ptr
;
}
void
*
tqSerialize
BufItem
(
STqBuffer
Item
*
bufItem
,
void
*
ptr
)
{
void
*
tqSerialize
Item
(
STqMsg
Item
*
bufItem
,
void
*
ptr
)
{
// TODO: do we need serialize this?
// mainly for executor
return
ptr
;
}
const
void
*
tqDeserializeGroup
Handle
(
const
STqSerializedHead
*
pHead
,
STqGroupHandle
**
ppGHandle
)
{
STqGroup
Handle
*
gHandle
=
*
ppGHandle
;
const
void
*
ptr
=
pHead
->
content
;
gHandle
->
cId
=
*
(
int64_t
*
)
ptr
;
const
void
*
tqDeserializeGroup
(
const
STqSerializedHead
*
pHead
,
STqGroup
**
ppGroup
)
{
STqGroup
*
gHandle
=
*
ppGroup
;
const
void
*
ptr
=
pHead
->
content
;
gHandle
->
c
lient
Id
=
*
(
int64_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
gHandle
->
cgId
=
*
(
int64_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
...
...
@@ -326,63 +403,63 @@ const void* tqDeserializeGroupHandle(const STqSerializedHead* pHead, STqGroupHan
gHandle
->
topicNum
=
*
(
int32_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
gHandle
->
head
=
NULL
;
STqList
Handle
*
node
=
gHandle
->
head
;
STqList
*
node
=
gHandle
->
head
;
for
(
int
i
=
0
;
i
<
gHandle
->
topicNum
;
i
++
)
{
if
(
gHandle
->
head
==
NULL
)
{
if
((
node
=
malloc
(
sizeof
(
STqList
Handle
)))
==
NULL
)
{
if
((
node
=
malloc
(
sizeof
(
STqList
)))
==
NULL
)
{
// TODO: error
return
NULL
;
}
node
->
next
=
NULL
;
ptr
=
tqDeserialize
BufHandle
(
ptr
,
&
node
->
bufHandle
);
ptr
=
tqDeserialize
Topic
(
ptr
,
&
node
->
topic
);
gHandle
->
head
=
node
;
}
else
{
node
->
next
=
malloc
(
sizeof
(
STqList
Handle
));
node
->
next
=
malloc
(
sizeof
(
STqList
));
if
(
node
->
next
==
NULL
)
{
// TODO: error
return
NULL
;
}
node
->
next
->
next
=
NULL
;
ptr
=
tqDeserialize
BufHandle
(
ptr
,
&
node
->
next
->
bufHandle
);
ptr
=
tqDeserialize
Topic
(
ptr
,
&
node
->
next
->
topic
);
node
=
node
->
next
;
}
}
return
ptr
;
}
const
void
*
tqDeserialize
BufHandle
(
const
void
*
pBytes
,
STqBufferHandle
*
bufHandle
)
{
const
void
*
tqDeserialize
Topic
(
const
void
*
pBytes
,
STqTopic
*
topic
)
{
const
void
*
ptr
=
pBytes
;
bufHandle
->
nextConsumeOffset
=
*
(
int64_t
*
)
ptr
;
topic
->
nextConsumeOffset
=
*
(
int64_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
bufHandle
->
topicId
=
*
(
int64_t
*
)
ptr
;
topic
->
topicId
=
*
(
int64_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
bufHandle
->
head
=
*
(
int32_t
*
)
ptr
;
topic
->
head
=
*
(
int32_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
bufHandle
->
tail
=
*
(
int32_t
*
)
ptr
;
topic
->
tail
=
*
(
int32_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
for
(
int
i
=
0
;
i
<
TQ_BUFFER_SIZE
;
i
++
)
{
ptr
=
tqDeserialize
BufItem
(
ptr
,
&
bufHandle
->
buffer
[
i
]);
ptr
=
tqDeserialize
Item
(
ptr
,
&
topic
->
buffer
[
i
]);
}
return
ptr
;
}
const
void
*
tqDeserialize
BufItem
(
const
void
*
pBytes
,
STqBuffer
Item
*
bufItem
)
{
return
pBytes
;
}
const
void
*
tqDeserialize
Item
(
const
void
*
pBytes
,
STqMsg
Item
*
bufItem
)
{
return
pBytes
;
}
// TODO: make this a macro
int
tqG
etgHandleSSize
(
const
STqGroupHandle
*
gHandle
)
{
int
tqG
roupSSize
(
const
STqGroup
*
gHandle
)
{
return
sizeof
(
int64_t
)
*
2
// cId + cgId
+
sizeof
(
int32_t
)
// topicNum
+
gHandle
->
topicNum
*
tq
BufHandle
SSize
();
+
gHandle
->
topicNum
*
tq
Topic
SSize
();
}
// TODO: make this a macro
int
tq
BufHandle
SSize
()
{
int
tq
Topic
SSize
()
{
return
sizeof
(
int64_t
)
*
2
// nextConsumeOffset + topicId
+
sizeof
(
int32_t
)
*
2
// head + tail
+
TQ_BUFFER_SIZE
*
tq
Buf
ItemSSize
();
+
TQ_BUFFER_SIZE
*
tqItemSSize
();
}
int
tq
Buf
ItemSSize
()
{
int
tqItemSSize
()
{
// TODO: do this need serialization?
// mainly for executor
return
0
;
...
...
source/dnode/vnode/tq/src/tqMetaStore.c
浏览文件 @
2d315222
...
...
@@ -56,6 +56,7 @@ static inline int tqReadLastPage(int fd, STqIdxPageBuf* pBuf) {
int
offset
=
tqSeekLastPage
(
fd
);
int
nBytes
;
if
((
nBytes
=
read
(
fd
,
pBuf
,
TQ_PAGE_SIZE
))
==
-
1
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
if
(
nBytes
==
0
)
{
...
...
@@ -71,7 +72,7 @@ STqMetaStore* tqStoreOpen(const char* path, FTqSerialize serializer, FTqDeserial
int32_t
tqConfigFlag
)
{
STqMetaStore
*
pMeta
=
malloc
(
sizeof
(
STqMetaStore
));
if
(
pMeta
==
NULL
)
{
// close
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
return
NULL
;
}
memset
(
pMeta
,
0
,
sizeof
(
STqMetaStore
));
...
...
@@ -79,8 +80,9 @@ STqMetaStore* tqStoreOpen(const char* path, FTqSerialize serializer, FTqDeserial
// concat data file name and index file name
size_t
pathLen
=
strlen
(
path
);
pMeta
->
dirPath
=
malloc
(
pathLen
+
1
);
if
(
pMeta
->
dirPath
!=
NULL
)
{
// TODO: memory insufficient
if
(
pMeta
->
dirPath
==
NULL
)
{
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
return
NULL
;
}
strcpy
(
pMeta
->
dirPath
,
path
);
...
...
@@ -88,13 +90,14 @@ STqMetaStore* tqStoreOpen(const char* path, FTqSerialize serializer, FTqDeserial
strcpy
(
name
,
path
);
if
(
taosDirExist
(
name
)
!=
0
&&
taosMkDir
(
name
)
!=
0
)
{
ASSERT
(
false
);
terrno
=
TSDB_CODE_TQ_FAILED_TO_CREATE_DIR
;
tqError
(
"failed to create dir:%s since %s "
,
name
,
terrstr
());
}
strcat
(
name
,
"/"
TQ_IDX_NAME
);
int
idxFd
=
open
(
name
,
O_RDWR
|
O_CREAT
,
0755
);
if
(
idxFd
<
0
)
{
ASSERT
(
false
);
// close file
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
tqError
(
"failed to open file:%s since %s "
,
name
,
terrstr
());
// free memory
return
NULL
;
}
...
...
@@ -102,9 +105,7 @@ STqMetaStore* tqStoreOpen(const char* path, FTqSerialize serializer, FTqDeserial
pMeta
->
idxFd
=
idxFd
;
pMeta
->
unpersistHead
=
malloc
(
sizeof
(
STqMetaList
));
if
(
pMeta
->
unpersistHead
==
NULL
)
{
ASSERT
(
false
);
// close file
// free memory
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
return
NULL
;
}
memset
(
pMeta
->
unpersistHead
,
0
,
sizeof
(
STqMetaList
));
...
...
@@ -114,7 +115,8 @@ STqMetaStore* tqStoreOpen(const char* path, FTqSerialize serializer, FTqDeserial
strcat
(
name
,
"/"
TQ_META_NAME
);
int
fileFd
=
open
(
name
,
O_RDWR
|
O_CREAT
,
0755
);
if
(
fileFd
<
0
)
{
ASSERT
(
false
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
tqError
(
"failed to open file:%s since %s"
,
name
,
terrstr
());
return
NULL
;
}
...
...
@@ -129,7 +131,7 @@ STqMetaStore* tqStoreOpen(const char* path, FTqSerialize serializer, FTqDeserial
STqIdxPageBuf
idxBuf
;
STqSerializedHead
*
serializedObj
=
malloc
(
TQ_PAGE_SIZE
);
if
(
serializedObj
==
NULL
)
{
// TODO:memory insufficient
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
}
int
idxRead
;
int
allocated
=
TQ_PAGE_SIZE
;
...
...
@@ -137,14 +139,16 @@ STqMetaStore* tqStoreOpen(const char* path, FTqSerialize serializer, FTqDeserial
while
((
idxRead
=
read
(
idxFd
,
&
idxBuf
,
TQ_PAGE_SIZE
)))
{
if
(
idxRead
==
-
1
)
{
// TODO: handle error
ASSERT
(
false
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
tqError
(
"failed to read tq index file since %s"
,
terrstr
());
}
ASSERT
(
idxBuf
.
head
.
writeOffset
==
idxRead
);
// loop read every entry
for
(
int
i
=
0
;
i
<
idxBuf
.
head
.
writeOffset
-
TQ_IDX_PAGE_HEAD_SIZE
;
i
+=
TQ_IDX_SIZE
)
{
STqMetaList
*
pNode
=
malloc
(
sizeof
(
STqMetaList
));
if
(
pNode
==
NULL
)
{
// TODO: free memory and return error
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
// TODO: free memory
}
memset
(
pNode
,
0
,
sizeof
(
STqMetaList
));
memcpy
(
&
pNode
->
handle
,
&
idxBuf
.
buffer
[
i
],
TQ_IDX_SIZE
);
...
...
@@ -153,7 +157,8 @@ STqMetaStore* tqStoreOpen(const char* path, FTqSerialize serializer, FTqDeserial
if
(
allocated
<
pNode
->
handle
.
serializedSize
)
{
void
*
ptr
=
realloc
(
serializedObj
,
pNode
->
handle
.
serializedSize
);
if
(
ptr
==
NULL
)
{
// TODO: memory insufficient
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
// TODO: free memory
}
serializedObj
=
ptr
;
allocated
=
pNode
->
handle
.
serializedSize
;
...
...
@@ -292,7 +297,7 @@ int32_t tqStorePersist(STqMetaStore* pMeta) {
STqMetaList
*
pNode
=
pHead
->
unpersistNext
;
STqSerializedHead
*
pSHead
=
malloc
(
sizeof
(
STqSerializedHead
));
if
(
pSHead
==
NULL
)
{
// TODO: memory error
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
return
-
1
;
}
pSHead
->
ver
=
TQ_SVER
;
...
...
@@ -403,7 +408,6 @@ static int32_t tqHandlePutCommitted(STqMetaStore* pMeta, int64_t key, void* valu
STqMetaList
*
pNode
=
pMeta
->
bucket
[
bucketKey
];
while
(
pNode
)
{
if
(
pNode
->
handle
.
key
==
key
)
{
// TODO: think about thread safety
if
(
pNode
->
handle
.
valueInUse
&&
pNode
->
handle
.
valueInUse
!=
TQ_DELETE_TOKEN
)
{
pMeta
->
pDeleter
(
pNode
->
handle
.
valueInUse
);
}
...
...
@@ -416,7 +420,7 @@ static int32_t tqHandlePutCommitted(STqMetaStore* pMeta, int64_t key, void* valu
}
STqMetaList
*
pNewNode
=
malloc
(
sizeof
(
STqMetaList
));
if
(
pNewNode
==
NULL
)
{
// TODO: memory error
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
return
-
1
;
}
memset
(
pNewNode
,
0
,
sizeof
(
STqMetaList
));
...
...
@@ -470,10 +474,10 @@ static inline int32_t tqHandlePutImpl(STqMetaStore* pMeta, int64_t key, void* va
STqMetaList
*
pNode
=
pMeta
->
bucket
[
bucketKey
];
while
(
pNode
)
{
if
(
pNode
->
handle
.
key
==
key
)
{
// TODO: think about thread safety
if
(
pNode
->
handle
.
valueInTxn
)
{
if
(
TqDupIntxnReject
(
pMeta
->
tqConfigFlag
))
{
return
-
2
;
if
(
tqDupIntxnReject
(
pMeta
->
tqConfigFlag
))
{
terrno
=
TSDB_CODE_TQ_META_KEY_DUP_IN_TXN
;
return
-
1
;
}
if
(
pNode
->
handle
.
valueInTxn
!=
TQ_DELETE_TOKEN
)
{
pMeta
->
pDeleter
(
pNode
->
handle
.
valueInTxn
);
...
...
@@ -488,7 +492,7 @@ static inline int32_t tqHandlePutImpl(STqMetaStore* pMeta, int64_t key, void* va
}
STqMetaList
*
pNewNode
=
malloc
(
sizeof
(
STqMetaList
));
if
(
pNewNode
==
NULL
)
{
// TODO: memory error
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
return
-
1
;
}
memset
(
pNewNode
,
0
,
sizeof
(
STqMetaList
));
...
...
@@ -505,7 +509,7 @@ int32_t tqHandleMovePut(STqMetaStore* pMeta, int64_t key, void* value) { return
int32_t
tqHandleCopyPut
(
STqMetaStore
*
pMeta
,
int64_t
key
,
void
*
value
,
size_t
vsize
)
{
void
*
vmem
=
malloc
(
vsize
);
if
(
vmem
==
NULL
)
{
// TODO: memory error
terrno
=
TSDB_CODE_TQ_OUT_OF_MEMORY
;
return
-
1
;
}
memcpy
(
vmem
,
value
,
vsize
);
...
...
@@ -535,6 +539,7 @@ int32_t tqHandleCommit(STqMetaStore* pMeta, int64_t key) {
while
(
pNode
)
{
if
(
pNode
->
handle
.
key
==
key
)
{
if
(
pNode
->
handle
.
valueInTxn
==
NULL
)
{
terrno
=
TSDB_CODE_TQ_META_KEY_NOT_IN_TXN
;
return
-
1
;
}
if
(
pNode
->
handle
.
valueInUse
&&
pNode
->
handle
.
valueInUse
!=
TQ_DELETE_TOKEN
)
{
...
...
@@ -548,7 +553,8 @@ int32_t tqHandleCommit(STqMetaStore* pMeta, int64_t key) {
pNode
=
pNode
->
next
;
}
}
return
-
2
;
terrno
=
TSDB_CODE_TQ_META_NO_SUCH_KEY
;
return
-
1
;
}
int32_t
tqHandleAbort
(
STqMetaStore
*
pMeta
,
int64_t
key
)
{
...
...
@@ -564,12 +570,14 @@ int32_t tqHandleAbort(STqMetaStore* pMeta, int64_t key) {
tqLinkUnpersist
(
pMeta
,
pNode
);
return
0
;
}
terrno
=
TSDB_CODE_TQ_META_KEY_NOT_IN_TXN
;
return
-
1
;
}
else
{
pNode
=
pNode
->
next
;
}
}
return
-
2
;
terrno
=
TSDB_CODE_TQ_META_NO_SUCH_KEY
;
return
-
1
;
}
int32_t
tqHandleDel
(
STqMetaStore
*
pMeta
,
int64_t
key
)
{
...
...
@@ -588,7 +596,7 @@ int32_t tqHandleDel(STqMetaStore* pMeta, int64_t key) {
pNode
=
pNode
->
next
;
}
}
// no such key
terrno
=
TSDB_CODE_TQ_META_NO_SUCH_KEY
;
return
-
1
;
}
...
...
source/dnode/vnode/tq/test/tqMetaTest.cpp
浏览文件 @
2d315222
...
...
@@ -10,8 +10,8 @@ struct Foo {
};
int
FooSerializer
(
const
void
*
pObj
,
STqSerializedHead
**
ppHead
)
{
Foo
*
foo
=
(
Foo
*
)
pObj
;
if
((
*
ppHead
)
==
NULL
||
(
*
ppHead
)
->
ssize
<
sizeof
(
STqSerializedHead
)
+
sizeof
(
int32_t
))
{
Foo
*
foo
=
(
Foo
*
)
pObj
;
if
((
*
ppHead
)
==
NULL
||
(
*
ppHead
)
->
ssize
<
sizeof
(
STqSerializedHead
)
+
sizeof
(
int32_t
))
{
*
ppHead
=
(
STqSerializedHead
*
)
realloc
(
*
ppHead
,
sizeof
(
STqSerializedHead
)
+
sizeof
(
int32_t
));
(
*
ppHead
)
->
ssize
=
sizeof
(
STqSerializedHead
)
+
sizeof
(
int32_t
);
}
...
...
@@ -20,36 +20,28 @@ int FooSerializer(const void* pObj, STqSerializedHead** ppHead) {
}
const
void
*
FooDeserializer
(
const
STqSerializedHead
*
pHead
,
void
**
ppObj
)
{
if
(
*
ppObj
==
NULL
)
{
if
(
*
ppObj
==
NULL
)
{
*
ppObj
=
realloc
(
*
ppObj
,
sizeof
(
int32_t
));
}
Foo
*
pFoo
=
*
(
Foo
**
)
ppObj
;
pFoo
->
a
=
*
(
int32_t
*
)
pHead
->
content
;
pFoo
->
a
=
*
(
int32_t
*
)
pHead
->
content
;
return
NULL
;
}
void
FooDeleter
(
void
*
pObj
)
{
free
(
pObj
);
}
void
FooDeleter
(
void
*
pObj
)
{
free
(
pObj
);
}
class
TqMetaUpdateAppendTest
:
public
::
testing
::
Test
{
protected:
void
SetUp
()
override
{
taosRemoveDir
(
pathName
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
}
void
TearDown
()
override
{
tqStoreClose
(
pMeta
);
}
TqMetaStore
*
pMeta
;
const
char
*
pathName
=
"/tmp/tq_test"
;
protected:
void
SetUp
()
override
{
taosRemoveDir
(
pathName
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
}
void
TearDown
()
override
{
tqStoreClose
(
pMeta
);
}
STqMetaStore
*
pMeta
;
const
char
*
pathName
=
"/tmp/tq_test"
;
};
TEST_F
(
TqMetaUpdateAppendTest
,
copyPutTest
)
{
...
...
@@ -57,11 +49,11 @@ TEST_F(TqMetaUpdateAppendTest, copyPutTest) {
foo
.
a
=
3
;
tqHandleCopyPut
(
pMeta
,
1
,
&
foo
,
sizeof
(
Foo
));
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
tqHandleCommit
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
->
a
,
3
);
}
...
...
@@ -78,10 +70,7 @@ TEST_F(TqMetaUpdateAppendTest, persistTest) {
EXPECT_EQ
(
pBar
==
NULL
,
true
);
tqStoreClose
(
pMeta
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
pBar
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
...
...
@@ -97,7 +86,7 @@ TEST_F(TqMetaUpdateAppendTest, uncommittedTest) {
pFoo
->
a
=
3
;
tqHandleMovePut
(
pMeta
,
1
,
pFoo
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
}
...
...
@@ -106,11 +95,11 @@ TEST_F(TqMetaUpdateAppendTest, abortTest) {
pFoo
->
a
=
3
;
tqHandleMovePut
(
pMeta
,
1
,
pFoo
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
tqHandleAbort
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
}
...
...
@@ -119,32 +108,29 @@ TEST_F(TqMetaUpdateAppendTest, deleteTest) {
pFoo
->
a
=
3
;
tqHandleMovePut
(
pMeta
,
1
,
pFoo
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
tqHandleCommit
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
);
EXPECT_EQ
(
pFoo
->
a
,
3
);
tqHandleDel
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
);
EXPECT_EQ
(
pFoo
->
a
,
3
);
tqHandleCommit
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
tqStoreClose
(
pMeta
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
EXPECT_EQ
(
pFoo
==
NULL
,
true
);
}
...
...
@@ -162,10 +148,7 @@ TEST_F(TqMetaUpdateAppendTest, intxnPersist) {
EXPECT_EQ
(
pFoo1
->
a
,
3
);
tqStoreClose
(
pMeta
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
pFoo1
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
...
...
@@ -177,10 +160,7 @@ TEST_F(TqMetaUpdateAppendTest, intxnPersist) {
EXPECT_EQ
(
pFoo1
->
a
,
4
);
tqStoreClose
(
pMeta
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
pFoo1
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
1
);
...
...
@@ -190,13 +170,13 @@ TEST_F(TqMetaUpdateAppendTest, intxnPersist) {
TEST_F
(
TqMetaUpdateAppendTest
,
multiplePage
)
{
srand
(
0
);
std
::
vector
<
int
>
v
;
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
v
.
push_back
(
rand
());
Foo
foo
;
foo
.
a
=
v
[
i
];
tqHandleCopyPut
(
pMeta
,
i
,
&
foo
,
sizeof
(
Foo
));
}
for
(
int
i
=
0
;
i
<
500
;
i
++
)
{
for
(
int
i
=
0
;
i
<
500
;
i
++
)
{
tqHandleCommit
(
pMeta
,
i
);
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
i
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
)
<<
" at idx "
<<
i
<<
"
\n
"
;
...
...
@@ -204,38 +184,34 @@ TEST_F(TqMetaUpdateAppendTest, multiplePage) {
}
tqStoreClose
(
pMeta
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
for
(
int
i
=
500
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
500
;
i
<
1000
;
i
++
)
{
tqHandleCommit
(
pMeta
,
i
);
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
i
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
)
<<
" at idx "
<<
i
<<
"
\n
"
;
EXPECT_EQ
(
pFoo
->
a
,
v
[
i
]);
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
i
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
)
<<
" at idx "
<<
i
<<
"
\n
"
;
EXPECT_EQ
(
pFoo
->
a
,
v
[
i
]);
}
}
TEST_F
(
TqMetaUpdateAppendTest
,
multipleRewrite
)
{
srand
(
0
);
std
::
vector
<
int
>
v
;
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
v
.
push_back
(
rand
());
Foo
foo
;
foo
.
a
=
v
[
i
];
tqHandleCopyPut
(
pMeta
,
i
,
&
foo
,
sizeof
(
Foo
));
}
for
(
int
i
=
0
;
i
<
500
;
i
++
)
{
for
(
int
i
=
0
;
i
<
500
;
i
++
)
{
tqHandleCommit
(
pMeta
,
i
);
v
[
i
]
=
rand
();
Foo
foo
;
...
...
@@ -243,25 +219,22 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
tqHandleCopyPut
(
pMeta
,
i
,
&
foo
,
sizeof
(
Foo
));
}
for
(
int
i
=
500
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
500
;
i
<
1000
;
i
++
)
{
v
[
i
]
=
rand
();
Foo
foo
;
foo
.
a
=
v
[
i
];
tqHandleCopyPut
(
pMeta
,
i
,
&
foo
,
sizeof
(
Foo
));
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
tqHandleCommit
(
pMeta
,
i
);
}
tqStoreClose
(
pMeta
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
pMeta
=
tqStoreOpen
(
pathName
,
FooSerializer
,
FooDeserializer
,
FooDeleter
,
TQ_UPDATE_APPEND
);
ASSERT
(
pMeta
);
for
(
int
i
=
500
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
500
;
i
<
1000
;
i
++
)
{
v
[
i
]
=
rand
();
Foo
foo
;
foo
.
a
=
v
[
i
];
...
...
@@ -269,40 +242,38 @@ TEST_F(TqMetaUpdateAppendTest, multipleRewrite) {
tqHandleCommit
(
pMeta
,
i
);
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
i
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
)
<<
" at idx "
<<
i
<<
"
\n
"
;
EXPECT_EQ
(
pFoo
->
a
,
v
[
i
]);
}
}
TEST_F
(
TqMetaUpdateAppendTest
,
dupCommit
)
{
srand
(
0
);
std
::
vector
<
int
>
v
;
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
v
.
push_back
(
rand
());
Foo
foo
;
foo
.
a
=
v
[
i
];
tqHandleCopyPut
(
pMeta
,
i
,
&
foo
,
sizeof
(
Foo
));
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
int
ret
=
tqHandleCommit
(
pMeta
,
i
);
EXPECT_EQ
(
ret
,
0
);
ret
=
tqHandleCommit
(
pMeta
,
i
);
EXPECT_EQ
(
ret
,
-
1
);
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
int
ret
=
tqHandleCommit
(
pMeta
,
i
);
EXPECT_EQ
(
ret
,
-
1
);
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
Foo
*
pFoo
=
(
Foo
*
)
tqHandleGet
(
pMeta
,
i
);
ASSERT_EQ
(
pFoo
!=
NULL
,
true
)
<<
" at idx "
<<
i
<<
"
\n
"
;
EXPECT_EQ
(
pFoo
->
a
,
v
[
i
]);
}
}
source/libs/catalog/test/catalogTests.cpp
浏览文件 @
2d315222
...
...
@@ -61,8 +61,8 @@ void sendCreateDbMsg(void *shandle, SEpSet *pEpSet) {
pReq
->
daysToKeep0
=
htonl
(
3650
);
pReq
->
daysToKeep1
=
htonl
(
3650
);
pReq
->
daysToKeep2
=
htonl
(
3650
);
pReq
->
minRows
PerFileBlock
=
htonl
(
100
);
pReq
->
maxRows
PerFileBlock
=
htonl
(
4096
);
pReq
->
minRows
=
htonl
(
100
);
pReq
->
maxRows
=
htonl
(
4096
);
pReq
->
commitTime
=
htonl
(
3600
);
pReq
->
fsyncPeriod
=
htonl
(
3000
);
pReq
->
walLevel
=
1
;
...
...
source/libs/index/inc/indexInt.h
浏览文件 @
2d315222
...
...
@@ -76,7 +76,7 @@ struct SIndexMultiTermQuery {
// field and key;
typedef
struct
SIndexTerm
{
int64_t
suid
;
int64_t
suid
;
SIndexOperOnColumn
operType
;
// oper type, add/del/update
uint8_t
colType
;
// term data type, str/interger/json
char
*
colName
;
...
...
source/libs/index/inc/index_fst_counting_writer.h
浏览文件 @
2d315222
...
...
@@ -34,8 +34,14 @@ typedef struct WriterCtx {
int
(
*
flush
)(
struct
WriterCtx
*
ctx
);
WriterType
type
;
union
{
int
fd
;
void
*
mem
;
struct
{
int
fd
;
bool
readOnly
;
}
file
;
struct
{
int32_t
capa
;
char
*
buf
;
}
mem
;
};
int32_t
offset
;
int32_t
limit
;
...
...
@@ -45,7 +51,7 @@ static int writeCtxDoWrite(WriterCtx *ctx, uint8_t *buf, int len);
static
int
writeCtxDoRead
(
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
);
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
);
WriterCtx
*
writerCtxCreate
(
WriterType
type
,
bool
readOnl
y
);
WriterCtx
*
writerCtxCreate
(
WriterType
type
,
const
char
*
path
,
bool
readOnly
,
int32_t
capacit
y
);
void
writerCtxDestroy
(
WriterCtx
*
w
);
typedef
uint32_t
CheckSummer
;
...
...
@@ -66,7 +72,7 @@ int fstCountingWriterFlush(FstCountingWriter *write);
uint32_t
fstCountingWriterMaskedCheckSum
(
FstCountingWriter
*
write
);
FstCountingWriter
*
fstCountingWriterCreate
(
void
*
wtr
,
bool
readOnly
);
FstCountingWriter
*
fstCountingWriterCreate
(
void
*
wtr
);
void
fstCountingWriterDestroy
(
FstCountingWriter
*
w
);
...
...
source/libs/index/inc/index_tfile.h
浏览文件 @
2d315222
...
...
@@ -18,23 +18,81 @@
#include "index.h"
#include "indexInt.h"
#include "tlockfree.h"
#include "tskiplist.h"
#include "index_tfile.h"
#include "index_fst_counting_writer.h"
#include "index_fst.h"
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
struct
IndexTFile
{
typedef
struct
TFileCacheKey
{
uint64_t
suid
;
uint8_t
colType
;
int32_t
version
;
const
char
*
colName
;
int32_t
nColName
;
}
TFileCacheKey
;
// table cache
// refactor to LRU cache later
typedef
struct
TFileCache
{
SHashObj
*
tableCache
;
int16_t
capacity
;
// add more param
}
TFileCache
;
typedef
struct
TFileWriter
{
FstBuilder
*
fb
;
WriterCtx
*
wc
;
}
TFileWriter
;
typedef
struct
TFileReader
{
T_REF_DECLARE
()
Fst
*
fst
;
}
TFileReader
;
typedef
struct
IndexTFile
{
char
*
path
;
TFileReader
*
tb
;
TFileWriter
*
tw
;
}
IndexTFile
;
typedef
struct
TFileWriterOpt
{
uint64_t
suid
;
int8_t
colType
;
char
*
colName
;
int32_t
nColName
;
int32_t
version
;
}
TFileWriterOpt
;
typedef
struct
TFileReaderOpt
{
uint64_t
suid
;
char
*
colName
;
int32_t
nColName
;
}
TFileReaderOpt
;
// tfile cache
TFileCache
*
tfileCacheCreate
();
void
tfileCacheDestroy
(
TFileCache
*
tcache
);
TFileReader
*
tfileCacheGet
(
TFileCache
*
tcache
,
TFileCacheKey
*
key
);
void
tfileCachePut
(
TFileCache
*
tcache
,
TFileCacheKey
*
key
,
TFileReader
*
reader
);
TFileWriter
*
tfileWriterCreate
(
const
char
*
suid
,
const
char
*
colName
);
IndexTFile
*
indexTFileCreate
();
int
indexTFilePut
(
void
*
tfile
,
SIndexTerm
*
term
,
uint64_t
uid
);
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SArray
*
result
);
#ifdef __cplusplus
}
...
...
source/libs/index/inc/index_util.h
0 → 100644
浏览文件 @
2d315222
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __INDEX_UTIL_H__
#define __INDEX_UTIL_H__
#ifdef __cplusplus
extern
"C"
{
#endif
#define SERIALIZE_MEM_TO_BUF(buf, key, mem) \
do { \
memcpy((void *)buf, (void *)(&key->mem), sizeof(key->mem)); \
buf += sizeof(key->mem); \
} while (0)
#define SERIALIZE_STR_MEM_TO_BUF(buf, key, mem, len) \
do { \
memcpy((void *)buf, (void *)key->mem, len); \
buf += len; \
} while (0)
#define SERIALIZE_VAR_TO_BUF(buf, var, type) \
do { \
type c = var; \
assert(sizeof(var) == sizeof(type));\
memcpy((void *)buf, (void *)&c, sizeof(c)); \
buf += sizeof(c); \
} while (0)
#define SERIALIZE_STR_VAR_TO_BUF(buf, var, len) \
do { \
memcpy((void *)buf, (void *)var, len); \
buf += len;\
} while (0)
#ifdef __cplusplus
}
#endif
#endif
source/libs/index/src/index_cache.c
浏览文件 @
2d315222
...
...
@@ -15,6 +15,7 @@
#include "index_cache.h"
#include "tcompare.h"
#include "index_util.h"
#define MAX_INDEX_KEY_LEN 256// test only, change later
...
...
@@ -110,35 +111,22 @@ int indexCachePut(void *cache, SIndexTerm *term, int16_t colId, int32_t version,
if
(
cache
==
NULL
)
{
return
-
1
;}
IndexCache
*
pCache
=
cache
;
// encode data
int32_t
total
=
CACHE_KEY_LEN
(
term
);
char
*
buf
=
calloc
(
1
,
total
);
char
*
p
=
buf
;
memcpy
(
p
,
&
total
,
sizeof
(
total
));
p
+=
sizeof
(
total
);
memcpy
(
p
,
&
colId
,
sizeof
(
colId
));
p
+=
sizeof
(
colId
);
SERIALIZE_VAR_TO_BUF
(
p
,
total
,
int32_t
);
SERIALIZE_VAR_TO_BUF
(
p
,
colId
,
int16_t
);
memcpy
(
p
,
&
term
->
colType
,
sizeof
(
term
->
colType
));
p
+=
sizeof
(
term
->
colType
);
SERIALIZE_MEM_TO_BUF
(
p
,
term
,
colType
);
SERIALIZE_MEM_TO_BUF
(
p
,
term
,
nColVal
);
SERIALIZE_STR_MEM_TO_BUF
(
p
,
term
,
colVal
,
term
->
nColVal
);
memcpy
(
p
,
&
term
->
nColVal
,
sizeof
(
term
->
nColVal
));
p
+=
sizeof
(
term
->
nColVal
);
memcpy
(
p
,
term
->
colVal
,
term
->
nColVal
);
p
+=
term
->
nColVal
;
memcpy
(
p
,
&
version
,
sizeof
(
version
));
p
+=
sizeof
(
version
);
memcpy
(
p
,
&
uid
,
sizeof
(
uid
));
p
+=
sizeof
(
uid
);
SERIALIZE_VAR_TO_BUF
(
p
,
version
,
int32_t
);
SERIALIZE_VAR_TO_BUF
(
p
,
uid
,
uint64_t
);
memcpy
(
p
,
&
term
->
operType
,
sizeof
(
term
->
operType
));
p
+=
sizeof
(
term
->
operType
);
SERIALIZE_MEM_TO_BUF
(
p
,
term
,
operType
);
tSkipListPut
(
pCache
->
skiplist
,
(
void
*
)
buf
);
return
0
;
...
...
source/libs/index/src/index_fst.c
浏览文件 @
2d315222
...
...
@@ -779,7 +779,7 @@ FstBuilder *fstBuilderCreate(void *w, FstType ty) {
if
(
NULL
==
b
)
{
return
b
;
}
b
->
wrt
=
fstCountingWriterCreate
(
w
,
false
);
b
->
wrt
=
fstCountingWriterCreate
(
w
);
b
->
unfinished
=
fstUnFinishedNodesCreate
();
b
->
registry
=
fstRegistryCreate
(
10000
,
2
)
;
b
->
last
=
fstSliceCreate
(
NULL
,
0
);
...
...
source/libs/index/src/index_fst_counting_writer.c
浏览文件 @
2d315222
...
...
@@ -23,9 +23,9 @@ static int writeCtxDoWrite(WriterCtx *ctx, uint8_t *buf, int len) {
}
if
(
ctx
->
type
==
TFile
)
{
assert
(
len
==
tfWrite
(
ctx
->
fd
,
buf
,
len
));
assert
(
len
==
tfWrite
(
ctx
->
f
ile
.
f
d
,
buf
,
len
));
}
else
{
memcpy
(
ctx
->
mem
+
ctx
->
offset
,
buf
,
len
);
memcpy
(
ctx
->
mem
.
buf
+
ctx
->
offset
,
buf
,
len
);
}
ctx
->
offset
+=
len
;
return
len
;
...
...
@@ -33,9 +33,9 @@ static int writeCtxDoWrite(WriterCtx *ctx, uint8_t *buf, int len) {
static
int
writeCtxDoRead
(
WriterCtx
*
ctx
,
uint8_t
*
buf
,
int
len
)
{
int
nRead
=
0
;
if
(
ctx
->
type
==
TFile
)
{
nRead
=
tfRead
(
ctx
->
fd
,
buf
,
len
);
nRead
=
tfRead
(
ctx
->
f
ile
.
f
d
,
buf
,
len
);
}
else
{
memcpy
(
buf
,
ctx
->
mem
+
ctx
->
offset
,
len
);
memcpy
(
buf
,
ctx
->
mem
.
buf
+
ctx
->
offset
,
len
);
}
ctx
->
offset
+=
nRead
;
...
...
@@ -44,63 +44,64 @@ static int writeCtxDoRead(WriterCtx *ctx, uint8_t *buf, int len) {
static
int
writeCtxDoFlush
(
WriterCtx
*
ctx
)
{
if
(
ctx
->
type
==
TFile
)
{
//tfFsync(ctx->fd);
//tfFlush(ctx->fd);
//tfFlush(ctx->f
ile.f
d);
}
else
{
// do nothing
}
return
1
;
}
WriterCtx
*
writerCtxCreate
(
WriterType
type
,
bool
readOnl
y
)
{
WriterCtx
*
writerCtxCreate
(
WriterType
type
,
const
char
*
path
,
bool
readOnly
,
int32_t
capacit
y
)
{
WriterCtx
*
ctx
=
calloc
(
1
,
sizeof
(
WriterCtx
));
if
(
ctx
==
NULL
)
{
return
NULL
;
}
ctx
->
type
=
type
;
if
(
ctx
->
type
==
TFile
)
{
tfInit
();
// ugly code, refactor later
ctx
->
file
.
readOnly
=
readOnly
;
if
(
readOnly
==
false
)
{
ctx
->
fd
=
tfOpenCreateWriteAppend
(
tmpFile
);
ctx
->
f
ile
.
f
d
=
tfOpenCreateWriteAppend
(
tmpFile
);
}
else
{
ctx
->
fd
=
tfOpenReadWrite
(
tmpFile
);
ctx
->
f
ile
.
f
d
=
tfOpenReadWrite
(
tmpFile
);
}
if
(
ctx
->
fd
<
0
)
{
if
(
ctx
->
f
ile
.
f
d
<
0
)
{
indexError
(
"open file error %d"
,
errno
);
}
}
else
if
(
ctx
->
type
==
TMemory
)
{
ctx
->
mem
=
calloc
(
1
,
DefaultMem
*
sizeof
(
uint8_t
));
ctx
->
mem
.
buf
=
calloc
(
1
,
sizeof
(
char
)
*
capacity
);
ctx
->
mem
.
capa
=
capacity
;
}
ctx
->
write
=
writeCtxDoWrite
;
ctx
->
read
=
writeCtxDoRead
;
ctx
->
flush
=
writeCtxDoFlush
;
ctx
->
offset
=
0
;
ctx
->
limit
=
DefaultMem
;
ctx
->
limit
=
capacity
;
return
ctx
;
}
void
writerCtxDestroy
(
WriterCtx
*
ctx
)
{
if
(
ctx
->
type
==
TMemory
)
{
free
(
ctx
->
mem
);
free
(
ctx
->
mem
.
buf
);
}
else
{
tfClose
(
ctx
->
fd
);
tfCleanup
();
tfClose
(
ctx
->
file
.
fd
);
}
free
(
ctx
);
}
FstCountingWriter
*
fstCountingWriterCreate
(
void
*
wrt
,
bool
readOnly
)
{
FstCountingWriter
*
fstCountingWriterCreate
(
void
*
wrt
)
{
FstCountingWriter
*
cw
=
calloc
(
1
,
sizeof
(
FstCountingWriter
));
if
(
cw
==
NULL
)
{
return
NULL
;
}
cw
->
wrt
=
(
void
*
)(
writerCtxCreate
(
TFile
,
readOnly
));
cw
->
wrt
=
wrt
;
//(void *)(writerCtxCreate(TFile, readOnly));
return
cw
;
}
void
fstCountingWriterDestroy
(
FstCountingWriter
*
cw
)
{
// free wrt object: close fd or free mem
fstCountingWriterFlush
(
cw
);
writerCtxDestroy
((
WriterCtx
*
)(
cw
->
wrt
));
//
writerCtxDestroy((WriterCtx *)(cw->wrt));
free
(
cw
);
}
...
...
@@ -124,6 +125,7 @@ int fstCountingWriterRead(FstCountingWriter *write, uint8_t *buf, uint32_t len)
}
uint32_t
fstCountingWriterMaskedCheckSum
(
FstCountingWriter
*
write
)
{
return
0
;
}
int
fstCountingWriterFlush
(
FstCountingWriter
*
write
)
{
...
...
source/libs/index/src/index_tfile.c
浏览文件 @
2d315222
...
...
@@ -14,6 +14,50 @@
*/
#include "index_tfile.h"
#include "index_fst.h"
#include "index_util.h"
static
void
tfileSerialCacheKey
(
TFileCacheKey
*
key
,
char
*
buf
)
{
SERIALIZE_MEM_TO_BUF
(
buf
,
key
,
suid
);
SERIALIZE_VAR_TO_BUF
(
buf
,
'_'
,
char
);
SERIALIZE_MEM_TO_BUF
(
buf
,
key
,
colType
);
SERIALIZE_VAR_TO_BUF
(
buf
,
'_'
,
char
);
SERIALIZE_MEM_TO_BUF
(
buf
,
key
,
version
);
SERIALIZE_VAR_TO_BUF
(
buf
,
'_'
,
char
);
SERIALIZE_STR_MEM_TO_BUF
(
buf
,
key
,
colName
,
key
->
nColName
);
}
TFileCache
*
tfileCacheCreate
()
{
TFileCache
*
tcache
=
calloc
(
1
,
sizeof
(
TFileCache
));
if
(
tcache
==
NULL
)
{
return
NULL
;
}
tcache
->
tableCache
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
tcache
->
capacity
=
64
;
return
tcache
;
}
void
tfileCacheDestroy
(
TFileCache
*
tcache
)
{
free
(
tcache
);
}
TFileReader
*
tfileCacheGet
(
TFileCache
*
tcache
,
TFileCacheKey
*
key
)
{
char
buf
[
128
]
=
{
0
};
tfileSerialCacheKey
(
key
,
buf
);
TFileReader
*
reader
=
taosHashGet
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
));
return
reader
;
}
void
tfileCachePut
(
TFileCache
*
tcache
,
TFileCacheKey
*
key
,
TFileReader
*
reader
)
{
char
buf
[
128
]
=
{
0
};
tfileSerialCacheKey
(
key
,
buf
);
taosHashPut
(
tcache
->
tableCache
,
buf
,
strlen
(
buf
),
&
reader
,
sizeof
(
void
*
));
return
;
}
IndexTFile
*
indexTFileCreate
()
{
IndexTFile
*
tfile
=
calloc
(
1
,
sizeof
(
IndexTFile
));
...
...
@@ -22,10 +66,24 @@ IndexTFile *indexTFileCreate() {
void
IndexTFileDestroy
(
IndexTFile
*
tfile
)
{
free
(
tfile
);
}
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SArray
*
result
)
{
IndexTFile
*
ptfile
=
(
IndexTFile
*
)
tfile
;
return
0
;
}
int
indexTFilePut
(
void
*
tfile
,
SIndexTerm
*
term
,
uint64_t
uid
)
{
TFileWriterOpt
wOpt
=
{.
suid
=
term
->
suid
,
.
colType
=
term
->
colType
,
.
colName
=
term
->
colName
,
.
nColName
=
term
->
nColName
,
.
version
=
1
};
return
0
;
}
source/libs/index/test/indexTests.cc
浏览文件 @
2d315222
...
...
@@ -45,7 +45,7 @@ class FstWriter {
class
FstReadMemory
{
public:
FstReadMemory
(
size_t
size
)
{
_w
=
fstCountingWriterCreate
(
NULL
,
true
);
_w
=
fstCountingWriterCreate
(
NULL
);
_size
=
size
;
memset
((
void
*
)
&
_s
,
0
,
sizeof
(
_s
));
}
...
...
source/libs/parser/inc/astToMsg.h
浏览文件 @
2d315222
...
...
@@ -4,7 +4,8 @@
#include "parserInt.h"
#include "taosmsg.h"
SCreateUserMsg
*
buildUserManipulationMsg
(
SSqlInfo
*
pInfo
,
int64_t
id
,
char
*
msgBuf
,
int32_t
msgLen
);
SCreateUserMsg
*
buildUserManipulationMsg
(
SSqlInfo
*
pInfo
,
int32_t
*
outputLen
,
int64_t
id
,
char
*
msgBuf
,
int32_t
msgLen
);
SDropUserMsg
*
buildDropUserMsg
(
SSqlInfo
*
pInfo
,
int32_t
*
outputLen
,
int64_t
id
,
char
*
msgBuf
,
int32_t
msgLen
);
SShowMsg
*
buildShowMsg
(
SShowInfo
*
pShowInfo
,
int64_t
id
,
char
*
msgBuf
,
int32_t
msgLen
);
SCreateDbMsg
*
buildCreateDbMsg
(
SCreateDbInfo
*
pCreateDbInfo
,
char
*
msgBuf
,
int32_t
msgLen
);
...
...
source/libs/parser/src/astToMsg.c
浏览文件 @
2d315222
#include "parserInt.h"
#include "parserUtil.h"
SCreateUserMsg
*
buildUserManipulationMsg
(
SSqlInfo
*
pInfo
,
int64_t
id
,
char
*
msgBuf
,
int32_t
msgLen
)
{
SCreateUserMsg
*
buildUserManipulationMsg
(
SSqlInfo
*
pInfo
,
int
32_t
*
outputLen
,
int
64_t
id
,
char
*
msgBuf
,
int32_t
msgLen
)
{
SCreateUserMsg
*
pMsg
=
(
SCreateUserMsg
*
)
calloc
(
1
,
sizeof
(
SCreateUserMsg
));
if
(
pMsg
==
NULL
)
{
// tscError("0x%" PRIx64 " failed to malloc for query msg", id);
...
...
@@ -20,6 +20,24 @@ SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int64_t id, char* msgB
strncpy
(
pMsg
->
pass
,
pUser
->
passwd
.
z
,
pUser
->
passwd
.
n
);
}
*
outputLen
=
sizeof
(
SUserInfo
);
return
pMsg
;
}
SDropUserMsg
*
buildDropUserMsg
(
SSqlInfo
*
pInfo
,
int32_t
*
msgLen
,
int64_t
id
,
char
*
msgBuf
,
int32_t
msgBufLen
)
{
SToken
*
pName
=
taosArrayGet
(
pInfo
->
pMiscInfo
->
a
,
0
);
if
(
pName
->
n
>=
TSDB_USER_LEN
)
{
return
NULL
;
}
SDropUserMsg
*
pMsg
=
calloc
(
1
,
sizeof
(
SDropUserMsg
));
if
(
pMsg
==
NULL
)
{
return
NULL
;
}
strncpy
(
pMsg
->
user
,
pName
->
z
,
pName
->
n
);
*
msgLen
=
sizeof
(
SDropUserMsg
);
return
pMsg
;
}
...
...
@@ -89,7 +107,7 @@ static int32_t setTimePrecision(SCreateDbMsg* pMsg, const SCreateDbInfo* pCreate
pMsg
->
precision
=
TSDB_TIME_PRECISION_MILLI
;
// millisecond by default
SToken
*
pToken
=
&
pCreateDbInfo
->
precision
;
SToken
*
pToken
=
(
SToken
*
)
&
pCreateDbInfo
->
precision
;
if
(
pToken
->
n
>
0
)
{
pToken
->
n
=
strdequote
(
pToken
->
z
);
...
...
@@ -116,8 +134,8 @@ static void doSetDbOptions(SCreateDbMsg* pMsg, const SCreateDbInfo* pCreateDb) {
pMsg
->
totalBlocks
=
htonl
(
pCreateDb
->
numOfBlocks
);
pMsg
->
daysPerFile
=
htonl
(
pCreateDb
->
daysPerFile
);
pMsg
->
commitTime
=
htonl
((
int32_t
)
pCreateDb
->
commitTime
);
pMsg
->
minRows
PerFileBlock
=
htonl
(
pCreateDb
->
minRowsPerBlock
);
pMsg
->
maxRows
PerFileBlock
=
htonl
(
pCreateDb
->
maxRowsPerBlock
);
pMsg
->
minRows
=
htonl
(
pCreateDb
->
minRowsPerBlock
);
pMsg
->
maxRows
=
htonl
(
pCreateDb
->
maxRowsPerBlock
);
pMsg
->
fsyncPeriod
=
htonl
(
pCreateDb
->
fsyncPeriod
);
pMsg
->
compression
=
pCreateDb
->
compressionLevel
;
pMsg
->
walLevel
=
(
char
)
pCreateDb
->
walLevel
;
...
...
@@ -141,7 +159,6 @@ int32_t setDbOptions(SCreateDbMsg* pCreateDbMsg, const SCreateDbInfo* pCreateDbS
// todo configurable
pCreateDbMsg
->
numOfVgroups
=
htonl
(
2
);
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/parser/src/astValidate.c
浏览文件 @
2d315222
...
...
@@ -4224,7 +4224,13 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, int64_t id, void** output, in
}
}
*
output
=
buildUserManipulationMsg
(
pInfo
,
id
,
msgBuf
,
msgBufLen
);
*
output
=
buildUserManipulationMsg
(
pInfo
,
outputLen
,
id
,
msgBuf
,
msgBufLen
);
break
;
}
case
TSDB_SQL_DROP_ACCT
:
case
TSDB_SQL_DROP_USER
:
{
*
output
=
buildDropUserMsg
(
pInfo
,
outputLen
,
id
,
msgBuf
,
msgBufLen
);
break
;
}
...
...
source/libs/parser/src/queryInfoUtil.c
浏览文件 @
2d315222
#include "os.h"
#include "queryInfoUtil.h"
#include <function.h>
#include "astGenerator.h"
#include "function.h"
#include "os.h"
#include "parser.h"
#include "parserInt.h"
#include "parserUtil.h"
static
struct
SSchema
_s
=
{
...
...
source/libs/parser/test/mockCatalogService.cpp
浏览文件 @
2d315222
...
...
@@ -38,7 +38,7 @@ public:
virtual
TableBuilder
&
setVgid
(
int16_t
vgid
)
{
schema
()
->
vgId
=
vgid
;
meta_
->
vgs
.
emplace_back
(
SVgroupInfo
{.
vgId
=
vgid
,
.
numOfEps
=
3
,
.
epAddr
=
{{
"dnode_1"
,
6030
},
{
"dnode_2"
,
6030
},
{
"dnode_3"
,
6030
}}});
meta_
->
vgs
.
emplace_back
(
SVgroupInfo
{.
vgId
=
vgid
,
.
hashBegin
=
0
,
.
hashEnd
=
0
,
.
inUse
=
0
,
.
numOfEps
=
3
,
.
epAddr
=
{{
"dnode_1"
,
6030
},
{
"dnode_2"
,
6030
},
{
"dnode_3"
,
6030
}}});
return
*
this
;
}
...
...
@@ -118,9 +118,9 @@ public:
meta_
[
db
][
tbname
].
reset
(
new
MockTableMeta
());
meta_
[
db
][
tbname
]
->
schema
.
reset
(
table
.
release
());
meta_
[
db
][
tbname
]
->
schema
->
uid
=
id_
++
;
meta_
[
db
][
tbname
]
->
vgs
.
emplace_back
(
SVgroupInfo
{.
vgId
=
vgid
,
.
numOfEps
=
3
,
.
epAddr
=
{{
"dnode_1"
,
6030
},
{
"dnode_2"
,
6030
},
{
"dnode_3"
,
6030
}}});
meta_
[
db
][
tbname
]
->
vgs
.
emplace_back
(
(
SVgroupInfo
){.
vgId
=
vgid
,
.
hashBegin
=
0
,
.
hashEnd
=
0
,
.
inUse
=
0
,
.
numOfEps
=
3
,
.
epAddr
=
{{
"dnode_1"
,
6030
},
{
"dnode_2"
,
6030
},
{
"dnode_3"
,
6030
}}});
// super table
meta_
[
db
][
stbname
]
->
vgs
.
emplace_back
(
SVgroupInfo
{.
vgId
=
vgid
,
.
numOfEps
=
3
,
.
epAddr
=
{{
"dnode_1"
,
6030
},
{
"dnode_2"
,
6030
},
{
"dnode_3"
,
6030
}}});
meta_
[
db
][
stbname
]
->
vgs
.
emplace_back
(
(
SVgroupInfo
){.
vgId
=
vgid
,
.
hashBegin
=
0
,
.
hashEnd
=
0
,
.
inUse
=
0
,
.
numOfEps
=
3
,
.
epAddr
=
{{
"dnode_1"
,
6030
},
{
"dnode_2"
,
6030
},
{
"dnode_3"
,
6030
}}});
}
void
showTables
()
const
{
...
...
source/libs/qcom/src/querymsg.c
浏览文件 @
2d315222
...
...
@@ -294,7 +294,7 @@ void msgInit() {
tscBuildMsg[TSDB_SQL_DROP_DNODE] = tscBuildDropDnodeMsg;
tscBuildMsg[TSDB_SQL_CFG_DNODE] = tscBuildCfgDnodeMsg;
tscBuildMsg[TSDB_SQL_ALTER_TABLE] = tscBuildAlterTableMsg;
tscBuildMsg[TSDB_SQL_UPDATE_TAG
S
_VAL] = tscBuildUpdateTagMsg;
tscBuildMsg[TSDB_SQL_UPDATE_TAG_VAL] = tscBuildUpdateTagMsg;
tscBuildMsg[TSDB_SQL_ALTER_DB] = tscAlterDbMsg;
tscBuildMsg[TSDB_SQL_COMPACT_VNODE] = tscBuildCompactMsg;
...
...
source/libs/scheduler/CMakeLists.txt
浏览文件 @
2d315222
...
...
@@ -11,3 +11,5 @@ target_link_libraries(
scheduler
PRIVATE os util planner qcom common catalog transport
)
ADD_SUBDIRECTORY
(
test
)
\ No newline at end of file
source/libs/scheduler/inc/schedulerInt.h
浏览文件 @
2d315222
...
...
@@ -73,9 +73,8 @@ typedef struct SQueryJob {
SQueryProfileSummary
summary
;
SEpSet
dataSrcEps
;
SEpAddr
resEp
;
struct
SCatalog
*
catalog
;
void
*
rpc
;
SEpSet
*
mgmtEpSet
;
void
*
transport
;
SArray
*
qnodeList
;
tsem_t
rspSem
;
int32_t
userFetch
;
int32_t
remoteFetch
;
...
...
source/libs/scheduler/src/scheduler.c
浏览文件 @
2d315222
...
...
@@ -58,8 +58,8 @@ int32_t schBuildTaskRalation(SQueryJob *job, SHashObj *planToTask) {
for
(
int32_t
m
=
0
;
m
<
level
->
taskNum
;
++
m
)
{
SQueryTask
*
task
=
taosArrayGet
(
level
->
subTasks
,
m
);
SSubplan
*
plan
=
task
->
plan
;
int32_t
childNum
=
(
int32_t
)
taosArrayGetSize
(
plan
->
pChildern
)
;
int32_t
parentNum
=
(
int32_t
)
taosArrayGetSize
(
plan
->
pParents
)
;
int32_t
childNum
=
plan
->
pChildern
?
(
int32_t
)
taosArrayGetSize
(
plan
->
pChildern
)
:
0
;
int32_t
parentNum
=
plan
->
pParents
?
(
int32_t
)
taosArrayGetSize
(
plan
->
pParents
)
:
0
;
if
(
childNum
>
0
)
{
task
->
children
=
taosArrayInit
(
childNum
,
POINTER_BYTES
);
...
...
@@ -187,13 +187,19 @@ int32_t schValidateAndBuildJob(SQueryDag *dag, SQueryJob *job) {
for
(
int32_t
n
=
0
;
n
<
levelPlanNum
;
++
n
)
{
SSubplan
*
plan
=
taosArrayGet
(
levelPlans
,
n
);
SQueryTask
*
task
=
taosArrayGet
(
level
.
subTasks
,
n
)
;
SQueryTask
task
=
{
0
}
;
task
->
taskId
=
atomic_add_fetch_64
(
&
schMgmt
.
taskId
,
1
);
task
->
plan
=
plan
;
task
->
status
=
SCH_STATUS_NOT_START
;
task
.
taskId
=
atomic_add_fetch_64
(
&
schMgmt
.
taskId
,
1
);
task
.
plan
=
plan
;
task
.
status
=
SCH_STATUS_NOT_START
;
if
(
0
!=
taosHashPut
(
planToTask
,
&
plan
,
POINTER_BYTES
,
&
task
,
POINTER_BYTES
))
{
void
*
p
=
taosArrayPush
(
level
.
subTasks
,
&
task
);
if
(
NULL
==
p
)
{
qError
(
"taosArrayPush failed"
);
SCH_ERR_JRET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
if
(
0
!=
taosHashPut
(
planToTask
,
&
plan
,
POINTER_BYTES
,
&
p
,
POINTER_BYTES
))
{
qError
(
"taosHashPut failed"
);
SCH_ERR_JRET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
...
...
@@ -225,20 +231,27 @@ _return:
SCH_RET
(
code
);
}
int32_t
sch
Available
EpSet
(
SQueryJob
*
job
,
SEpSet
*
epSet
)
{
int32_t
sch
SetTaskExec
EpSet
(
SQueryJob
*
job
,
SEpSet
*
epSet
)
{
if
(
epSet
->
numOfEps
>=
SCH_MAX_CONDIDATE_EP_NUM
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
SCH_HAS_QNODE_IN_CLUSTER
(
schMgmt
.
cfg
.
clusterType
))
{
SCH_ERR_RET
(
catalogGetQnodeList
(
job
->
catalog
,
job
->
rpc
,
job
->
mgmtEpSet
,
epSet
));
}
else
{
for
(
int32_t
i
=
0
;
i
<
job
->
dataSrcEps
.
numOfEps
;
++
i
)
{
strncpy
(
epSet
->
fqdn
[
epSet
->
numOfEps
],
job
->
dataSrcEps
.
fqdn
[
i
],
sizeof
(
job
->
dataSrcEps
.
fqdn
[
i
]));
epSet
->
port
[
epSet
->
numOfEps
]
=
job
->
dataSrcEps
.
port
[
i
];
++
epSet
->
numOfEps
;
}
int32_t
qnodeNum
=
taosArrayGetSize
(
job
->
qnodeList
);
for
(
int32_t
i
=
0
;
i
<
qnodeNum
&&
epSet
->
numOfEps
<
tListLen
(
epSet
->
port
);
++
i
)
{
SEpAddr
*
addr
=
taosArrayGet
(
job
->
qnodeList
,
i
);
strncpy
(
epSet
->
fqdn
[
epSet
->
numOfEps
],
addr
->
fqdn
,
sizeof
(
addr
->
fqdn
));
epSet
->
port
[
epSet
->
numOfEps
]
=
addr
->
port
;
++
epSet
->
numOfEps
;
}
for
(
int32_t
i
=
0
;
i
<
job
->
dataSrcEps
.
numOfEps
&&
epSet
->
numOfEps
<
tListLen
(
epSet
->
port
);
++
i
)
{
strncpy
(
epSet
->
fqdn
[
epSet
->
numOfEps
],
job
->
dataSrcEps
.
fqdn
[
i
],
sizeof
(
job
->
dataSrcEps
.
fqdn
[
i
]));
epSet
->
port
[
epSet
->
numOfEps
]
=
job
->
dataSrcEps
.
port
[
i
];
++
epSet
->
numOfEps
;
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -509,7 +522,12 @@ int32_t schLaunchTask(SQueryJob *job, SQueryTask *task) {
SCH_ERR_RET
(
qSubPlanToString
(
plan
,
&
task
->
msg
));
if
(
plan
->
execEpSet
.
numOfEps
<=
0
)
{
SCH_ERR_RET
(
schAvailableEpSet
(
job
,
&
plan
->
execEpSet
));
SCH_ERR_RET
(
schSetTaskExecEpSet
(
job
,
&
plan
->
execEpSet
));
}
if
(
plan
->
execEpSet
.
numOfEps
<=
0
)
{
SCH_TASK_ERR_LOG
(
"invalid execEpSet num:%d"
,
plan
->
execEpSet
.
numOfEps
);
SCH_ERR_RET
(
TSDB_CODE_SCH_INTERNAL_ERROR
);
}
SCH_ERR_RET
(
schAsyncSendMsg
(
job
,
task
,
TSDB_MSG_TYPE_QUERY
));
...
...
@@ -548,20 +566,23 @@ int32_t schedulerInit(SSchedulerCfg *cfg) {
}
int32_t
schedule
QueryJob
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
SQueryDag
*
pDag
,
void
**
pJob
)
{
if
(
NULL
==
pCatalog
||
NULL
==
pRpc
||
NULL
==
pMgmtEps
||
NULL
==
pDag
||
NULL
==
pDag
->
pSubplans
||
NULL
==
pJob
)
{
int32_t
schedule
ExecJob
(
void
*
transport
,
SArray
*
qnodeList
,
SQueryDag
*
pDag
,
void
**
pJob
)
{
if
(
NULL
==
transport
||
NULL
==
transport
||
NULL
==
pDag
||
NULL
==
pDag
->
pSubplans
||
NULL
==
pJob
)
{
SCH_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
if
(
taosArrayGetSize
(
qnodeList
)
<=
0
)
{
qInfo
(
"qnodeList is empty"
);
}
int32_t
code
=
0
;
SQueryJob
*
job
=
calloc
(
1
,
sizeof
(
SQueryJob
));
if
(
NULL
==
job
)
{
SCH_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
job
->
catalog
=
pCatalog
;
job
->
rpc
=
pRpc
;
job
->
mgmtEpSet
=
(
SEpSet
*
)
pMgmtEps
;
job
->
transport
=
transport
;
job
->
qnodeList
=
qnodeList
;
SCH_ERR_JRET
(
schValidateAndBuildJob
(
pDag
,
job
));
...
...
source/libs/scheduler/test/CMakeLists.txt
0 → 100644
浏览文件 @
2d315222
MESSAGE
(
STATUS
"build scheduler unit test"
)
# GoogleTest requires at least C++11
SET
(
CMAKE_CXX_STANDARD 11
)
AUX_SOURCE_DIRECTORY
(
${
CMAKE_CURRENT_SOURCE_DIR
}
SOURCE_LIST
)
ADD_EXECUTABLE
(
schedulerTest
${
SOURCE_LIST
}
)
TARGET_LINK_LIBRARIES
(
schedulerTest
PUBLIC os util common catalog transport gtest qcom taos planner scheduler
)
TARGET_INCLUDE_DIRECTORIES
(
schedulerTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/scheduler/"
PRIVATE
"
${
CMAKE_SOURCE_DIR
}
/source/libs/scheduler/inc"
)
source/libs/scheduler/test/schedulerTests.cpp
浏览文件 @
2d315222
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include <tglobal.h>
#include <iostream>
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#include "os.h"
#include "taos.h"
#include "tdef.h"
#include "tvariant.h"
#include "catalog.h"
#include "scheduler.h"
#include "tep.h"
#include "trpc.h"
namespace
{
void
mockBuildDag
(
SQueryDag
*
dag
)
{
uint64_t
qId
=
0x111111111111
;
dag
->
queryId
=
qId
;
dag
->
numOfSubplans
=
2
;
dag
->
pSubplans
=
taosArrayInit
(
dag
->
numOfSubplans
,
POINTER_BYTES
);
SArray
*
scan
=
taosArrayInit
(
1
,
sizeof
(
SSubplan
));
SArray
*
merge
=
taosArrayInit
(
1
,
sizeof
(
SSubplan
));
SSubplan
scanPlan
=
{
0
};
SSubplan
mergePlan
=
{
0
};
scanPlan
.
id
.
queryId
=
qId
;
scanPlan
.
id
.
templateId
=
0x2222222222
;
scanPlan
.
id
.
subplanId
=
0x3333333333
;
scanPlan
.
type
=
QUERY_TYPE_SCAN
;
scanPlan
.
level
=
1
;
scanPlan
.
execEpSet
.
numOfEps
=
1
;
scanPlan
.
pChildern
=
NULL
;
scanPlan
.
pParents
=
taosArrayInit
(
1
,
POINTER_BYTES
);
mergePlan
.
id
.
queryId
=
qId
;
mergePlan
.
id
.
templateId
=
0x4444444444
;
mergePlan
.
id
.
subplanId
=
0x5555555555
;
mergePlan
.
type
=
QUERY_TYPE_MERGE
;
mergePlan
.
level
=
0
;
mergePlan
.
execEpSet
.
numOfEps
=
1
;
mergePlan
.
pChildern
=
taosArrayInit
(
1
,
POINTER_BYTES
);
mergePlan
.
pParents
=
NULL
;
SSubplan
*
mergePointer
=
(
SSubplan
*
)
taosArrayPush
(
merge
,
&
mergePlan
);
SSubplan
*
scanPointer
=
(
SSubplan
*
)
taosArrayPush
(
scan
,
&
scanPlan
);
taosArrayPush
(
mergePointer
->
pChildern
,
&
scanPointer
);
taosArrayPush
(
scanPointer
->
pParents
,
&
mergePointer
);
taosArrayPush
(
dag
->
pSubplans
,
&
merge
);
taosArrayPush
(
dag
->
pSubplans
,
&
scan
);
}
}
TEST
(
testCase
,
normalCase
)
{
void
*
mockPointer
=
(
void
*
)
0x1
;
char
*
clusterId
=
"cluster1"
;
char
*
dbname
=
"1.db1"
;
char
*
tablename
=
"table1"
;
SVgroupInfo
vgInfo
=
{
0
};
void
*
pJob
=
NULL
;
SQueryDag
dag
=
{
0
};
SArray
*
qnodeList
=
taosArrayInit
(
1
,
sizeof
(
SEpAddr
));
int32_t
code
=
schedulerInit
(
NULL
);
ASSERT_EQ
(
code
,
0
);
mockBuildDag
(
&
dag
);
code
=
scheduleExecJob
(
mockPointer
,
qnodeList
,
&
dag
,
&
pJob
);
ASSERT_EQ
(
code
,
0
);
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
source/util/src/tlog.c
浏览文件 @
2d315222
此差异已折叠。
点击以展开。
source/util/src/tthread.c
浏览文件 @
2d315222
...
...
@@ -13,16 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "tthread.h"
#include "os.h"
#include "taoserror.h"
#include "tdef.h"
#include "tutil.h"
#include "ulog.h"
#include "taoserror.h"
// create new thread
pthread_t
*
taosCreateThread
(
void
*
(
*
__start_routine
)
(
void
*
),
void
*
param
)
{
pthread_t
*
pthread
=
(
pthread_t
*
)
malloc
(
sizeof
(
pthread_t
));
pthread_t
*
taosCreateThread
(
void
*
(
*
__start_routine
)(
void
*
),
void
*
param
)
{
pthread_t
*
pthread
=
(
pthread_t
*
)
malloc
(
sizeof
(
pthread_t
));
pthread_attr_t
thattr
;
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
...
...
@@ -36,26 +36,24 @@ pthread_t* taosCreateThread( void *(*__start_routine) (void *), void* param) {
return
pthread
;
}
// destory thread
// destory thread
bool
taosDestoryThread
(
pthread_t
*
pthread
)
{
if
(
pthread
==
NULL
)
return
false
;
if
(
taosThreadRunning
(
pthread
))
{
if
(
pthread
==
NULL
)
return
false
;
if
(
taosThreadRunning
(
pthread
))
{
pthread_cancel
(
*
pthread
);
pthread_join
(
*
pthread
,
NULL
);
}
free
(
pthread
);
return
true
;
}
// thread running return true
bool
taosThreadRunning
(
pthread_t
*
pthread
)
{
if
(
pthread
==
NULL
)
return
false
;
if
(
pthread
==
NULL
)
return
false
;
int
ret
=
pthread_kill
(
*
pthread
,
0
);
if
(
ret
==
ESRCH
)
return
false
;
if
(
ret
==
EINVAL
)
return
false
;
if
(
ret
==
ESRCH
)
return
false
;
if
(
ret
==
EINVAL
)
return
false
;
// alive
return
true
;
}
tests/script/general/user/monitor.sim
已删除
100644 → 0
浏览文件 @
816a9d93
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
print ========== step1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/cfg.sh -n dnode1 -c monitor -v 1
system sh/cfg.sh -n dnode1 -c monitorInterval -v 1
system sh/exec.sh -n dnode1 -s start
sleep 2000
sql connect
print ========== step2
#sql drop database log -x step21
# return -1
#step21:
sql drop table log.dn -x step22
# return -1
step22:
sql drop user log -x step23
# return -1
step23:
print ========== step3
sleep 2000
#sql select * from log.dn
#if $rows == 0 then
# return -1
#endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录