Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
81ebcd8b
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
81ebcd8b
编写于
11月 30, 2021
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' into feature/vnode
上级
df9ba31d
56e643ba
变更
74
隐藏空白更改
内联
并排
Showing
74 changed file
with
2003 addition
and
1455 deletion
+2003
-1455
include/dnode/mnode/mnode.h
include/dnode/mnode/mnode.h
+165
-65
include/dnode/mnode/sdb/sdb.h
include/dnode/mnode/sdb/sdb.h
+150
-25
source/dnode/mgmt/impl/CMakeLists.txt
source/dnode/mgmt/impl/CMakeLists.txt
+1
-1
source/dnode/mgmt/impl/src/dndDnode.c
source/dnode/mgmt/impl/src/dndDnode.c
+46
-40
source/dnode/mgmt/impl/src/dndMnode.c
source/dnode/mgmt/impl/src/dndMnode.c
+48
-39
source/dnode/mgmt/impl/src/dndTransport.c
source/dnode/mgmt/impl/src/dndTransport.c
+5
-3
source/dnode/mgmt/impl/src/dnode.c
source/dnode/mgmt/impl/src/dnode.c
+2
-3
source/dnode/mnode/impl/CMakeLists.txt
source/dnode/mnode/impl/CMakeLists.txt
+3
-3
source/dnode/mnode/impl/inc/mndAcct.h
source/dnode/mnode/impl/inc/mndAcct.h
+6
-6
source/dnode/mnode/impl/inc/mndAuth.h
source/dnode/mnode/impl/inc/mndAuth.h
+6
-6
source/dnode/mnode/impl/inc/mndBalance.h
source/dnode/mnode/impl/inc/mndBalance.h
+32
-0
source/dnode/mnode/impl/inc/mndCluster.h
source/dnode/mnode/impl/inc/mndCluster.h
+32
-0
source/dnode/mnode/impl/inc/mndDb.h
source/dnode/mnode/impl/inc/mndDb.h
+32
-0
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+48
-55
source/dnode/mnode/impl/inc/mndDnode.h
source/dnode/mnode/impl/inc/mndDnode.h
+32
-0
source/dnode/mnode/impl/inc/mndFunc.h
source/dnode/mnode/impl/inc/mndFunc.h
+6
-6
source/dnode/mnode/impl/inc/mndInt.h
source/dnode/mnode/impl/inc/mndInt.h
+26
-29
source/dnode/mnode/impl/inc/mndMnode.h
source/dnode/mnode/impl/inc/mndMnode.h
+34
-0
source/dnode/mnode/impl/inc/mndOper.h
source/dnode/mnode/impl/inc/mndOper.h
+5
-5
source/dnode/mnode/impl/inc/mndProfile.h
source/dnode/mnode/impl/inc/mndProfile.h
+32
-0
source/dnode/mnode/impl/inc/mndShow.h
source/dnode/mnode/impl/inc/mndShow.h
+6
-6
source/dnode/mnode/impl/inc/mndStable.h
source/dnode/mnode/impl/inc/mndStable.h
+32
-0
source/dnode/mnode/impl/inc/mndSync.h
source/dnode/mnode/impl/inc/mndSync.h
+34
-0
source/dnode/mnode/impl/inc/mndTelem.h
source/dnode/mnode/impl/inc/mndTelem.h
+6
-6
source/dnode/mnode/impl/inc/mndTrans.h
source/dnode/mnode/impl/inc/mndTrans.h
+47
-0
source/dnode/mnode/impl/inc/mndUser.h
source/dnode/mnode/impl/inc/mndUser.h
+32
-0
source/dnode/mnode/impl/inc/mndVgroup.h
source/dnode/mnode/impl/inc/mndVgroup.h
+32
-0
source/dnode/mnode/impl/inc/mnodeDb.h
source/dnode/mnode/impl/inc/mnodeDb.h
+0
-32
source/dnode/mnode/impl/inc/mnodeDnode.h
source/dnode/mnode/impl/inc/mnodeDnode.h
+0
-32
source/dnode/mnode/impl/inc/mnodeFunc.h
source/dnode/mnode/impl/inc/mnodeFunc.h
+0
-32
source/dnode/mnode/impl/inc/mnodeMnode.h
source/dnode/mnode/impl/inc/mnodeMnode.h
+0
-34
source/dnode/mnode/impl/inc/mnodeProfile.h
source/dnode/mnode/impl/inc/mnodeProfile.h
+0
-32
source/dnode/mnode/impl/inc/mnodeShow.h
source/dnode/mnode/impl/inc/mnodeShow.h
+0
-32
source/dnode/mnode/impl/inc/mnodeStable.h
source/dnode/mnode/impl/inc/mnodeStable.h
+0
-32
source/dnode/mnode/impl/inc/mnodeSync.h
source/dnode/mnode/impl/inc/mnodeSync.h
+0
-35
source/dnode/mnode/impl/inc/mnodeUser.h
source/dnode/mnode/impl/inc/mnodeUser.h
+0
-32
source/dnode/mnode/impl/inc/mnodeVgroup.h
source/dnode/mnode/impl/inc/mnodeVgroup.h
+0
-32
source/dnode/mnode/impl/src/mndAcct.c
source/dnode/mnode/impl/src/mndAcct.c
+12
-13
source/dnode/mnode/impl/src/mndAuth.c
source/dnode/mnode/impl/src/mndAuth.c
+4
-4
source/dnode/mnode/impl/src/mndBalance.c
source/dnode/mnode/impl/src/mndBalance.c
+21
-0
source/dnode/mnode/impl/src/mndCluster.c
source/dnode/mnode/impl/src/mndCluster.c
+21
-0
source/dnode/mnode/impl/src/mndDb.c
source/dnode/mnode/impl/src/mndDb.c
+3
-3
source/dnode/mnode/impl/src/mndDnode.c
source/dnode/mnode/impl/src/mndDnode.c
+21
-0
source/dnode/mnode/impl/src/mndFunc.c
source/dnode/mnode/impl/src/mndFunc.c
+3
-3
source/dnode/mnode/impl/src/mndMnode.c
source/dnode/mnode/impl/src/mndMnode.c
+5
-5
source/dnode/mnode/impl/src/mndOper.c
source/dnode/mnode/impl/src/mndOper.c
+3
-3
source/dnode/mnode/impl/src/mndProfile.c
source/dnode/mnode/impl/src/mndProfile.c
+21
-0
source/dnode/mnode/impl/src/mndShow.c
source/dnode/mnode/impl/src/mndShow.c
+3
-3
source/dnode/mnode/impl/src/mndStable.c
source/dnode/mnode/impl/src/mndStable.c
+21
-0
source/dnode/mnode/impl/src/mndSync.c
source/dnode/mnode/impl/src/mndSync.c
+7
-7
source/dnode/mnode/impl/src/mndTelem.c
source/dnode/mnode/impl/src/mndTelem.c
+55
-55
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+76
-79
source/dnode/mnode/impl/src/mndUser.c
source/dnode/mnode/impl/src/mndUser.c
+45
-52
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+21
-0
source/dnode/mnode/impl/src/mnode.c
source/dnode/mnode/impl/src/mnode.c
+297
-254
source/dnode/mnode/impl/src/mnodeFunc.c
source/dnode/mnode/impl/src/mnodeFunc.c
+0
-21
source/dnode/mnode/impl/src/mnodeOper.c
source/dnode/mnode/impl/src/mnodeOper.c
+0
-21
source/dnode/mnode/impl/src/mnodeProfile.c
source/dnode/mnode/impl/src/mnodeProfile.c
+0
-21
source/dnode/mnode/impl/src/mnodeShow.c
source/dnode/mnode/impl/src/mnodeShow.c
+0
-21
source/dnode/mnode/impl/src/mnodeStable.c
source/dnode/mnode/impl/src/mnodeStable.c
+0
-21
source/dnode/mnode/impl/src/mnodeVgroup.c
source/dnode/mnode/impl/src/mnodeVgroup.c
+0
-21
source/dnode/mnode/sdb/CMakeLists.txt
source/dnode/mnode/sdb/CMakeLists.txt
+1
-1
source/dnode/mnode/sdb/inc/sdbInt.h
source/dnode/mnode/sdb/inc/sdbInt.h
+4
-5
source/dnode/mnode/sdb/src/sdb.c
source/dnode/mnode/sdb/src/sdb.c
+72
-49
source/dnode/mnode/sdb/src/sdbFile.c
source/dnode/mnode/sdb/src/sdbFile.c
+49
-70
source/dnode/mnode/sdb/src/sdbHash.c
source/dnode/mnode/sdb/src/sdbHash.c
+62
-63
source/dnode/mnode/sdb/src/sdbRaw.c
source/dnode/mnode/sdb/src/sdbRaw.c
+2
-2
source/dnode/mnode/sdb/src/sdbRow.c
source/dnode/mnode/sdb/src/sdbRow.c
+1
-1
source/libs/index/inc/index_fst.h
source/libs/index/inc/index_fst.h
+51
-1
source/libs/index/inc/index_fst_automation.h
source/libs/index/inc/index_fst_automation.h
+13
-8
source/libs/index/inc/index_fst_node.h
source/libs/index/inc/index_fst_node.h
+1
-1
source/libs/index/src/index_fst.c
source/libs/index/src/index_fst.c
+185
-3
source/libs/index/src/index_fst_node.c
source/libs/index/src/index_fst_node.c
+22
-21
source/libs/index/src/index_fst_util.c
source/libs/index/src/index_fst_util.c
+1
-0
未找到文件。
include/dnode/mnode/mnode.h
浏览文件 @
81ebcd8b
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MN
ODE
_H_
#define _TD_MN
ODE
_H_
#ifndef _TD_MN
D
_H_
#define _TD_MN
D
_H_
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -30,28 +30,132 @@ typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
typedef
int32_t
(
*
PutMsgToMnodeQFp
)(
SDnode
*
pDnode
,
SMnodeMsg
*
pMsg
);
typedef
struct
SMnodeLoad
{
/**
* @brief the number of dnodes in cluster.
*
*/
int64_t
numOfDnode
;
/**
* @brief the number of mnodes in cluster.
*
*/
int64_t
numOfMnode
;
/**
* @brief the number of vgroups in cluster.
*
*/
int64_t
numOfVgroup
;
/**
* @brief the number of databases in cluster.
*
*/
int64_t
numOfDatabase
;
/**
* @brief the number of super tables in cluster.
*
*/
int64_t
numOfSuperTable
;
/**
* @brief the number of child tables in cluster.
*
*/
int64_t
numOfChildTable
;
/**
* @brief the number of normal tables in cluster.
*
*/
int64_t
numOfNormalTable
;
/**
* @brief the number of numOfTimeseries in cluster.
*
*/
int64_t
numOfColumn
;
/**
* @brief total points written in cluster.
*
*/
int64_t
totalPoints
;
/**
* @brief total storage in cluster.
*
*/
int64_t
totalStorage
;
/**
* @brief total compressed storage in cluster.
*
*/
int64_t
compStorage
;
}
SMnodeLoad
;
typedef
struct
{
int32_t
dnodeId
;
int64_t
clusterId
;
int8_t
replica
;
int8_t
selfIndex
;
SReplica
replicas
[
TSDB_MAX_REPLICA
];
struct
SDnode
*
pDnode
;
PutMsgToMnodeQFp
putMsgToApplyMsgFp
;
SendMsgToDnodeFp
sendMsgToDnodeFp
;
SendMsgToMnodeFp
sendMsgToMnodeFp
;
/**
* @brief dnodeId of this mnode.
*
*/
int32_t
dnodeId
;
/**
* @brief clusterId of this mnode.
*
*/
int64_t
clusterId
;
/**
* @brief replica num of this mnode.
*
*/
int8_t
replica
;
/**
* @brief self index in the array of replicas.
*
*/
int8_t
selfIndex
;
/**
* @brief detail replica information of this mnode.
*
*/
SReplica
replicas
[
TSDB_MAX_REPLICA
];
/**
* @brief the parent dnode of this mnode.
*
*/
SDnode
*
pDnode
;
/**
* @brief put apply msg to the write queue in dnode.
*
*/
PutMsgToMnodeQFp
putMsgToApplyMsgFp
;
/**
* @brief the callback function while send msg to dnode.
*
*/
SendMsgToDnodeFp
sendMsgToDnodeFp
;
/**
* @brief the callback function while send msg to mnode.
*
*/
SendMsgToMnodeFp
sendMsgToMnodeFp
;
/**
* @brief the callback function while send redirect msg to clients or peers.
*
*/
SendRedirectMsgFp
sendRedirectMsgFp
;
}
SMnodeOpt
;
...
...
@@ -59,119 +163,115 @@ typedef struct {
/**
* @brief Open a mnode.
*
* @param path Path of the mnode
* @param pOption Option of the mnode
* @return SMnode* The mnode object
* @param path Path of the mnode
.
* @param pOption Option of the mnode
.
* @return SMnode* The mnode object
.
*/
SMnode
*
mn
ode
Open
(
const
char
*
path
,
const
SMnodeOpt
*
pOption
);
SMnode
*
mn
d
Open
(
const
char
*
path
,
const
SMnodeOpt
*
pOption
);
/**
* @brief Close a mnode
* @brief Close a mnode
.
*
* @param pMnode The mnode object to close
* @param pMnode The mnode object to close
.
*/
void
mn
ode
Close
(
SMnode
*
pMnode
);
void
mn
d
Close
(
SMnode
*
pMnode
);
/**
* @brief Close a mnode
* @brief Close a mnode
.
*
* @param pMnode The mnode object to close
* @param pOption Options of the mnode
* @return int32_t 0 for success, -1 for failure
* @param pMnode The mnode object to close
.
* @param pOption Options of the mnode
.
* @return int32_t 0 for success, -1 for failure
.
*/
int32_t
mn
ode
Alter
(
SMnode
*
pMnode
,
const
SMnodeOpt
*
pOption
);
int32_t
mn
d
Alter
(
SMnode
*
pMnode
,
const
SMnodeOpt
*
pOption
);
/**
* @brief Drop a mnode.
*
* @param path Path of the mnode.
*/
void
mn
ode
Destroy
(
const
char
*
path
);
void
mn
d
Destroy
(
const
char
*
path
);
/**
* @brief Get mnode statistics info
* @brief Get mnode statistics info
.
*
* @param pMnode The mnode object
* @param pMnode The mnode object
.
* @param pLoad Statistics of the mnode.
* @return int32_t 0 for success, -1 for failure
* @return int32_t 0 for success, -1 for failure
.
*/
int32_t
mn
ode
GetLoad
(
SMnode
*
pMnode
,
SMnodeLoad
*
pLoad
);
int32_t
mn
d
GetLoad
(
SMnode
*
pMnode
,
SMnodeLoad
*
pLoad
);
/**
* @brief Get user authentication info
* @brief Get user authentication info
.
*
* @param pMnode The mnode object
* @param pMnode The mnode object
.
* @param user
* @param spi
* @param encrypt
* @param secret
* @param ckey
* @return int32_t 0 for success, -1 for failure
* @return int32_t 0 for success, -1 for failure
.
*/
int32_t
mn
ode
RetriveAuth
(
SMnode
*
pMnode
,
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
int32_t
mn
d
RetriveAuth
(
SMnode
*
pMnode
,
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
/**
* @brief Initialize mnode msg
* @brief Initialize mnode msg
.
*
* @param pMnode The mnode object
* @param pMsg The request rpc msg
* @return int32_t The created mnode msg
* @param pMnode The mnode object
.
* @param pMsg The request rpc msg
.
* @return int32_t The created mnode msg
.
*/
SMnodeMsg
*
mn
ode
InitMsg
(
SMnode
*
pMnode
,
SRpcMsg
*
pRpcMsg
);
SMnodeMsg
*
mn
d
InitMsg
(
SMnode
*
pMnode
,
SRpcMsg
*
pRpcMsg
);
/**
* @brief Cleanup mnode msg
* @brief Cleanup mnode msg
.
*
* @param pMsg The request msg
* @param pMsg The request msg
.
*/
void
mn
ode
CleanupMsg
(
SMnodeMsg
*
pMsg
);
void
mn
d
CleanupMsg
(
SMnodeMsg
*
pMsg
);
/**
* @brief Cleanup mnode msg
* @brief Cleanup mnode msg
.
*
* @param pMsg The request msg
* @param code The error code
* @param pMsg The request msg
.
* @param code The error code
.
*/
void
mn
ode
SendRsp
(
SMnodeMsg
*
pMsg
,
int32_t
code
);
void
mn
d
SendRsp
(
SMnodeMsg
*
pMsg
,
int32_t
code
);
/**
* @brief Process the read request
* @brief Process the read request
.
*
* @param pMnode The mnode object
* @param pMsg The request msg
* @return int32_t 0 for success, -1 for failure
* @param pMsg The request msg.
* @return int32_t 0 for success, -1 for failure.
*/
void
mn
odeProcessReadMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
);
void
mn
dProcessReadMsg
(
SMnodeMsg
*
pMsg
);
/**
* @brief Process the write request
* @brief Process the write request
.
*
* @param pMnode The mnode object
* @param pMsg The request msg
* @return int32_t 0 for success, -1 for failure
* @param pMsg The request msg.
* @return int32_t 0 for success, -1 for failure.
*/
void
mn
odeProcessWriteMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
);
void
mn
dProcessWriteMsg
(
SMnodeMsg
*
pMsg
);
/**
* @brief Process the sync request
* @brief Process the sync request
.
*
* @param pMnode The mnode object
* @param pMsg The request msg
* @return int32_t 0 for success, -1 for failure
* @param pMsg The request msg.
* @return int32_t 0 for success, -1 for failure.
*/
void
mn
odeProcessSyncMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
);
void
mn
dProcessSyncMsg
(
SMnodeMsg
*
pMsg
);
/**
* @brief Process the apply request
* @brief Process the apply request
.
*
* @param pMnode The mnode object
* @param pMsg The request msg
* @return int32_t 0 for success, -1 for failure
* @param pMsg The request msg.
* @return int32_t 0 for success, -1 for failure.
*/
void
mn
odeProcessApplyMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
);
void
mn
dProcessApplyMsg
(
SMnodeMsg
*
pMsg
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MN
ODE
_H_*/
#endif
/*_TD_MN
D
_H_*/
include/dnode/mnode/sdb/sdb.h
浏览文件 @
81ebcd8b
...
...
@@ -114,56 +114,181 @@ typedef enum {
SDB_START
=
0
,
SDB_TRANS
=
1
,
SDB_CLUSTER
=
2
,
SDB_
D
NODE
=
3
,
SDB_
M
NODE
=
4
,
SDB_
M
NODE
=
3
,
SDB_
D
NODE
=
4
,
SDB_USER
=
5
,
SDB_AUTH
=
6
,
SDB_ACCT
=
7
,
SDB_DB
=
8
,
SDB_VGROUP
=
9
,
SDB_STABLE
=
10
,
SDB_STABLE
=
9
,
SDB_DB
=
10
,
SDB_FUNC
=
11
,
SDB_MAX
=
12
}
ESdbType
;
typedef
int32_t
(
*
SdbInsertFp
)(
void
*
pObj
);
typedef
int32_t
(
*
SdbUpdateFp
)(
void
*
pSrcObj
,
void
*
pDstObj
);
typedef
int32_t
(
*
SdbDeleteFp
)(
void
*
pObj
);
typedef
int32_t
(
*
SdbDeployFp
)();
typedef
struct
SSdb
SSdb
;
typedef
int32_t
(
*
SdbInsertFp
)(
SSdb
*
pSdb
,
void
*
pObj
);
typedef
int32_t
(
*
SdbUpdateFp
)(
SSdb
*
pSdb
,
void
*
pSrcObj
,
void
*
pDstObj
);
typedef
int32_t
(
*
SdbDeleteFp
)(
SSdb
*
pSdb
,
void
*
pObj
);
typedef
int32_t
(
*
SdbDeployFp
)(
SSdb
*
pSdb
);
typedef
SSdbRow
*
(
*
SdbDecodeFp
)(
SSdbRaw
*
pRaw
);
typedef
SSdbRaw
*
(
*
SdbEncodeFp
)(
void
*
pObj
);
typedef
struct
{
ESdbType
sdbType
;
EKeyType
keyType
;
/**
* @brief The sdb type of the table.
*
*/
ESdbType
sdbType
;
/**
* @brief The key type of the table.
*
*/
EKeyType
keyType
;
/**
* @brief The callback function when the table is first deployed.
*
*/
SdbDeployFp
deployFp
;
/**
* @brief Encode one row of the table into rawdata.
*
*/
SdbEncodeFp
encodeFp
;
/**
* @brief Decode one row of the table from rawdata.
*
*/
SdbDecodeFp
decodeFp
;
/**
* @brief The callback function when insert a row to sdb.
*
*/
SdbInsertFp
insertFp
;
/**
* @brief The callback function when undate a row in sdb.
*
*/
SdbUpdateFp
updateFp
;
/**
* @brief The callback function when delete a row from sdb.
*
*/
SdbDeleteFp
deleteFp
;
}
SSdbTable
;
typedef
struct
SSdb
SSdb
;
typedef
struct
SSdbOpt
{
/**
* @brief The path of the sdb file.
*
*/
const
char
*
path
;
}
SSdbOpt
;
/**
* @brief Initialize and start the sdb.
*
* @param pOption Option of the sdb.
* @return SSdb* The sdb object.
*/
SSdb
*
sdbInit
(
SSdbOpt
*
pOption
);
/**
* @brief Stop and cleanup the sdb.
*
* @param pSdb The sdb object to close.
*/
void
sdbCleanup
(
SSdb
*
pSdb
);
/**
* @brief Set the properties of sdb table.
*
* @param pSdb The sdb object.
* @param table The properties of the table.
* @return int32_t 0 for success, -1 for failure.
*/
int32_t
sdbSetTable
(
SSdb
*
pSdb
,
SSdbTable
table
);
/**
* @brief Set the initial rows of sdb.
*
* @param pSdb The sdb object.
* @return int32_t 0 for success, -1 for failure.
*/
int32_t
sdbDeploy
(
SSdb
*
pSdb
);
int32_t
sdbInit
();
void
sdbCleanup
();
void
sdbSetTable
(
SSdbTable
table
);
/**
* @brief Load sdb from file.
*
* @param pSdb The sdb object.
* @return int32_t 0 for success, -1 for failure.
*/
int32_t
sdbReadFile
(
SSdb
*
pSdb
);
int32_t
sdbOpen
();
void
sdbClose
();
int32_t
sdbWrite
(
SSdbRaw
*
pRaw
);
/**
* @brief Parse and write raw data to sdb.
*
* @param pSdb The sdb object.
* @param pRaw The raw data.
* @return int32_t 0 for success, -1 for failure.
*/
int32_t
sdbWrite
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
);
int32_t
sdbDeploy
();
void
sdbUnDeploy
();
/**
* @brief Acquire a row from sdb
*
* @param pSdb The sdb object.
* @param type The type of the row.
* @param pKey The key value of the row.
* @return void* The object of the row.
*/
void
*
sdbAcquire
(
SSdb
*
pSdb
,
ESdbType
type
,
void
*
pKey
);
void
*
sdbAcquire
(
ESdbType
sdb
,
void
*
pKey
);
void
sdbRelease
(
void
*
pObj
);
void
*
sdbFetch
(
ESdbType
sdb
,
void
*
pIter
,
void
**
ppObj
);
void
sdbCancelFetch
(
void
*
pIter
);
int32_t
sdbGetSize
(
ESdbType
sdb
);
/**
* @brief Release a row from sdb.
*
* @param pSdb The sdb object.
* @param pObj The object of the row.
*/
void
sdbRelease
(
SSdb
*
pSdb
,
void
*
pObj
);
/**
* @brief Traverse a sdb table
*
* @param pSdb The sdb object.
* @param type The type of the table.
* @param type The initial iterator of the table.
* @param pObj The object of the row just fetched.
* @return void* The next iterator of the table.
*/
void
*
sdbFetch
(
SSdb
*
pSdb
,
ESdbType
type
,
void
*
pIter
,
void
**
ppObj
);
/**
* @brief Cancel a traversal
*
* @param pSdb The sdb object.
* @param pIter The iterator of the table.
* @param type The initial iterator of table.
*/
void
sdbCancelFetch
(
SSdb
*
pSdb
,
void
*
pIter
);
/**
* @brief Get the number of rows in the table
*
* @param pSdb The sdb object.
* @param pIter The type of the table.
* @record int32_t The number of rows in the table
*/
int32_t
sdbGetSize
(
SSdb
*
pSdb
,
ESdbType
type
);
SSdbRaw
*
sdbAllocRaw
(
ESdbType
sdb
,
int8_t
sver
,
int32_t
dataLen
);
SSdbRaw
*
sdbAllocRaw
(
ESdbType
type
,
int8_t
sver
,
int32_t
dataLen
);
void
sdbFreeRaw
(
SSdbRaw
*
pRaw
);
int32_t
sdbSetRawInt8
(
SSdbRaw
*
pRaw
,
int32_t
dataPos
,
int8_t
val
);
int32_t
sdbSetRawInt32
(
SSdbRaw
*
pRaw
,
int32_t
dataPos
,
int32_t
val
);
...
...
source/dnode/mgmt/impl/CMakeLists.txt
浏览文件 @
81ebcd8b
...
...
@@ -12,5 +12,5 @@ target_link_libraries(
target_include_directories
(
dnode
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/dnode/mgmt"
private
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
source/dnode/mgmt/impl/src/dndDnode.c
浏览文件 @
81ebcd8b
...
...
@@ -18,32 +18,27 @@
#include "dndTransport.h"
#include "dndVnodes.h"
static
inline
void
dndRLockDnode
(
SDnode
*
pDnode
)
{
taosRLockLatch
(
&
pDnode
->
dmgmt
.
latch
);
}
static
inline
void
dndRUnLockDnode
(
SDnode
*
pDnode
)
{
taosRUnLockLatch
(
&
pDnode
->
dmgmt
.
latch
);
}
static
inline
void
dndWLockDnode
(
SDnode
*
pDnode
)
{
taosWLockLatch
(
&
pDnode
->
dmgmt
.
latch
);
}
static
inline
void
dndWUnLockDnode
(
SDnode
*
pDnode
)
{
taosWUnLockLatch
(
&
pDnode
->
dmgmt
.
latch
);
}
int32_t
dndGetDnodeId
(
SDnode
*
pDnode
)
{
dndRLockDnode
(
pDnode
);
int32_t
dnodeId
=
pDnode
->
dmgmt
.
dnodeId
;
dndRUnLockDnode
(
pDnode
);
SDnodeMgmt
*
pMgmt
=
&
pDnode
->
dmgmt
;
taosRLockLatch
(
&
pMgmt
->
latch
);
int32_t
dnodeId
=
pMgmt
->
dnodeId
;
taosRUnLockLatch
(
&
pMgmt
->
latch
);
return
dnodeId
;
}
int64_t
dndGetClusterId
(
SDnode
*
pDnode
)
{
dndRLockDnode
(
pDnode
);
int64_t
clusterId
=
pDnode
->
dmgmt
.
clusterId
;
dndRUnLockDnode
(
pDnode
);
SDnodeMgmt
*
pMgmt
=
&
pDnode
->
dmgmt
;
taosRLockLatch
(
&
pMgmt
->
latch
);
int64_t
clusterId
=
pMgmt
->
clusterId
;
taosRUnLockLatch
(
&
pMgmt
->
latch
);
return
clusterId
;
}
void
dndGetDnodeEp
(
SDnode
*
pDnode
,
int32_t
dnodeId
,
char
*
pEp
,
char
*
pFqdn
,
uint16_t
*
pPort
)
{
dndRLockDnode
(
pDnode
);
SDnodeMgmt
*
pMgmt
=
&
pDnode
->
dmgmt
;
taosRLockLatch
(
&
pMgmt
->
latch
);
SDnodeEp
*
pDnodeEp
=
taosHashGet
(
p
Dnode
->
dmgmt
.
dnodeHash
,
&
dnodeId
,
sizeof
(
int32_t
));
SDnodeEp
*
pDnodeEp
=
taosHashGet
(
p
Mgmt
->
dnodeHash
,
&
dnodeId
,
sizeof
(
int32_t
));
if
(
pDnodeEp
!=
NULL
)
{
if
(
pPort
!=
NULL
)
{
*
pPort
=
pDnodeEp
->
port
;
...
...
@@ -56,13 +51,14 @@ void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint
}
}
dndRUnLockDnode
(
pDnode
);
taosRUnLockLatch
(
&
pMgmt
->
latch
);
}
void
dndGetMnodeEpSet
(
SDnode
*
pDnode
,
SEpSet
*
pEpSet
)
{
dndRLockDnode
(
pDnode
);
*
pEpSet
=
pDnode
->
dmgmt
.
mnodeEpSet
;
dndRUnLockDnode
(
pDnode
);
SDnodeMgmt
*
pMgmt
=
&
pDnode
->
dmgmt
;
taosRLockLatch
(
&
pMgmt
->
latch
);
*
pEpSet
=
pMgmt
->
mnodeEpSet
;
taosRUnLockLatch
(
&
pMgmt
->
latch
);
}
void
dndSendRedirectMsg
(
SDnode
*
pDnode
,
SRpcMsg
*
pMsg
)
{
...
...
@@ -87,14 +83,15 @@ void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) {
static
void
dndUpdateMnodeEpSet
(
SDnode
*
pDnode
,
SEpSet
*
pEpSet
)
{
dInfo
(
"mnode is changed, num:%d inUse:%d"
,
pEpSet
->
numOfEps
,
pEpSet
->
inUse
);
dndWLockDnode
(
pDnode
);
SDnodeMgmt
*
pMgmt
=
&
pDnode
->
dmgmt
;
taosWLockLatch
(
&
pMgmt
->
latch
);
p
Dnode
->
dmgmt
.
mnodeEpSet
=
*
pEpSet
;
p
Mgmt
->
mnodeEpSet
=
*
pEpSet
;
for
(
int32_t
i
=
0
;
i
<
pEpSet
->
numOfEps
;
++
i
)
{
dInfo
(
"mnode index:%d %s:%u"
,
i
,
pEpSet
->
fqdn
[
i
],
pEpSet
->
port
[
i
]);
}
dndWUnLockDnode
(
pDnode
);
taosWUnLockLatch
(
&
pMgmt
->
latch
);
}
static
void
dndPrintDnodes
(
SDnode
*
pDnode
)
{
...
...
@@ -124,12 +121,14 @@ static void dndResetDnodes(SDnode *pDnode, SDnodeEps *pDnodeEps) {
}
pMgmt
->
mnodeEpSet
.
inUse
=
0
;
pMgmt
->
mnodeEpSet
.
numOfEps
=
0
;
int32_t
mIndex
=
0
;
for
(
int32_t
i
=
0
;
i
<
pMgmt
->
dnodeEps
->
num
;
i
++
)
{
SDnodeEp
*
pDnodeEp
=
&
pMgmt
->
dnodeEps
->
eps
[
i
];
if
(
!
pDnodeEp
->
isMnode
)
continue
;
if
(
mIndex
>=
TSDB_MAX_REPLICA
)
continue
;
pMgmt
->
mnodeEpSet
.
numOfEps
++
;
strcpy
(
pMgmt
->
mnodeEpSet
.
fqdn
[
mIndex
],
pDnodeEp
->
fqdn
);
pMgmt
->
mnodeEpSet
.
port
[
mIndex
]
=
pDnodeEp
->
port
;
mIndex
++
;
...
...
@@ -145,16 +144,18 @@ static void dndResetDnodes(SDnode *pDnode, SDnodeEps *pDnodeEps) {
static
bool
dndIsEpChanged
(
SDnode
*
pDnode
,
int32_t
dnodeId
,
char
*
pEp
)
{
bool
changed
=
false
;
dndRLockDnode
(
pDnode
);
SDnodeEp
*
pDnodeEp
=
taosHashGet
(
pDnode
->
dmgmt
.
dnodeHash
,
&
dnodeId
,
sizeof
(
int32_t
));
SDnodeMgmt
*
pMgmt
=
&
pDnode
->
dmgmt
;
taosRLockLatch
(
&
pMgmt
->
latch
);
SDnodeEp
*
pDnodeEp
=
taosHashGet
(
pMgmt
->
dnodeHash
,
&
dnodeId
,
sizeof
(
int32_t
));
if
(
pDnodeEp
!=
NULL
)
{
char
epstr
[
TSDB_EP_LEN
+
1
];
snprintf
(
epstr
,
TSDB_EP_LEN
,
"%s:%u"
,
pDnodeEp
->
fqdn
,
pDnodeEp
->
port
);
changed
=
strcmp
(
pEp
,
epstr
)
!=
0
;
}
dndRUnLockDnode
(
pDnode
);
taosRUnLockLatch
(
&
pMgmt
->
latch
);
return
changed
;
}
...
...
@@ -280,6 +281,7 @@ PRASE_DNODE_OVER:
if
(
pMgmt
->
dnodeEps
==
NULL
)
{
pMgmt
->
dnodeEps
=
calloc
(
1
,
sizeof
(
SDnodeEps
)
+
sizeof
(
SDnodeEp
));
pMgmt
->
dnodeEps
->
num
=
1
;
pMgmt
->
dnodeEps
->
eps
[
0
].
isMnode
=
1
;
pMgmt
->
dnodeEps
->
eps
[
0
].
port
=
pDnode
->
opt
.
serverPort
;
tstrncpy
(
pMgmt
->
dnodeEps
->
eps
[
0
].
fqdn
,
pDnode
->
opt
.
localFqdn
,
TSDB_FQDN_LEN
);
}
...
...
@@ -342,11 +344,14 @@ static void dndSendStatusMsg(SDnode *pDnode) {
return
;
}
dndRLockDnode
(
pDnode
);
bool
changed
=
false
;
SDnodeMgmt
*
pMgmt
=
&
pDnode
->
dmgmt
;
taosRLockLatch
(
&
pMgmt
->
latch
);
pStatus
->
sversion
=
htonl
(
pDnode
->
opt
.
sver
);
pStatus
->
dnodeId
=
htonl
(
p
Dnode
->
dmgmt
.
dnodeId
);
pStatus
->
clusterId
=
htobe64
(
p
Dnode
->
dmgmt
.
clusterId
);
pStatus
->
rebootTime
=
htonl
(
p
Dnode
->
dmgmt
.
rebootTime
);
pStatus
->
dnodeId
=
htonl
(
p
Mgmt
->
dnodeId
);
pStatus
->
clusterId
=
htobe64
(
p
Mgmt
->
clusterId
);
pStatus
->
rebootTime
=
htonl
(
p
Mgmt
->
rebootTime
);
pStatus
->
numOfCores
=
htonl
(
pDnode
->
opt
.
numOfCores
);
tstrncpy
(
pStatus
->
dnodeEp
,
pDnode
->
opt
.
localEp
,
TSDB_EP_LEN
);
pStatus
->
clusterCfg
.
statusInterval
=
htonl
(
pDnode
->
opt
.
statusInterval
);
...
...
@@ -356,7 +361,7 @@ static void dndSendStatusMsg(SDnode *pDnode) {
pStatus
->
clusterCfg
.
checkTime
=
0
;
char
timestr
[
32
]
=
"1970-01-01 00:00:00.00"
;
(
void
)
taosParseTime
(
timestr
,
&
pStatus
->
clusterCfg
.
checkTime
,
(
int32_t
)
strlen
(
timestr
),
TSDB_TIME_PRECISION_MILLI
,
0
);
dndRUnLockDnode
(
pDnode
);
taosRUnLockLatch
(
&
pMgmt
->
latch
);
dndGetVnodeLoads
(
pDnode
,
&
pStatus
->
vnodeLoads
);
contLen
=
sizeof
(
SStatusMsg
)
+
pStatus
->
vnodeLoads
.
num
*
sizeof
(
SVnodeLoad
);
...
...
@@ -370,32 +375,33 @@ static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) {
if
(
pMgmt
->
dnodeId
==
0
||
pMgmt
->
dropped
!=
pCfg
->
dropped
)
{
dInfo
(
"set dnodeId:%d clusterId:%"
PRId64
" dropped:%d"
,
pCfg
->
dnodeId
,
pCfg
->
clusterId
,
pCfg
->
dropped
);
dndWLockDnode
(
pDnode
);
taosWLockLatch
(
&
pMgmt
->
latch
);
pMgmt
->
dnodeId
=
pCfg
->
dnodeId
;
pMgmt
->
clusterId
=
pCfg
->
clusterId
;
pMgmt
->
dropped
=
pCfg
->
dropped
;
(
void
)
dndWriteDnodes
(
pDnode
);
dndWUnLockDnode
(
pDnode
);
taosWUnLockLatch
(
&
pMgmt
->
latch
);
}
}
static
void
dndUpdateDnodeEps
(
SDnode
*
pDnode
,
SDnodeEps
*
pDnodeEps
)
{
if
(
pDnodeEps
==
NULL
||
pDnodeEps
->
num
<=
0
)
return
;
dndWLockDnode
(
pDnode
);
SDnodeMgmt
*
pMgmt
=
&
pDnode
->
dmgmt
;
taosWLockLatch
(
&
pMgmt
->
latch
);
if
(
pDnodeEps
->
num
!=
p
Dnode
->
dmgmt
.
dnodeEps
->
num
)
{
if
(
pDnodeEps
->
num
!=
p
Mgmt
->
dnodeEps
->
num
)
{
dndResetDnodes
(
pDnode
,
pDnodeEps
);
dndWriteDnodes
(
pDnode
);
}
else
{
int32_t
size
=
pDnodeEps
->
num
*
sizeof
(
SDnodeEp
)
+
sizeof
(
SDnodeEps
);
if
(
memcmp
(
p
Dnode
->
dmgmt
.
dnodeEps
,
pDnodeEps
,
size
)
!=
0
)
{
if
(
memcmp
(
p
Mgmt
->
dnodeEps
,
pDnodeEps
,
size
)
!=
0
)
{
dndResetDnodes
(
pDnode
,
pDnodeEps
);
dndWriteDnodes
(
pDnode
);
}
}
dndWUnLockDnode
(
pDnode
);
taosWUnLockLatch
(
&
pMgmt
->
latch
);
}
static
void
dndProcessStatusRsp
(
SDnode
*
pDnode
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
...
...
@@ -458,7 +464,7 @@ static void *dnodeThreadRoutine(void *param) {
pthread_testcancel
();
if
(
dndGetStat
(
pDnode
)
==
DND_STAT_RUNNING
)
{
dndSendStatusMsg
(
pDnode
);
//
dndSendStatusMsg(pDnode);
}
}
}
...
...
@@ -512,7 +518,7 @@ void dndCleanupDnode(SDnode *pDnode) {
pMgmt
->
threadId
=
NULL
;
}
dndWLockDnode
(
pDnode
);
taosWLockLatch
(
&
pMgmt
->
latch
);
if
(
pMgmt
->
dnodeEps
!=
NULL
)
{
free
(
pMgmt
->
dnodeEps
);
...
...
@@ -529,7 +535,7 @@ void dndCleanupDnode(SDnode *pDnode) {
pMgmt
->
file
=
NULL
;
}
dndWUnLockDnode
(
pDnode
);
taosWUnLockLatch
(
&
pMgmt
->
latch
);
dInfo
(
"dnode-dnode is cleaned up"
);
}
...
...
source/dnode/mgmt/impl/src/dndMnode.c
浏览文件 @
81ebcd8b
...
...
@@ -80,7 +80,9 @@ static SMnode *dndAcquireMnode(SDnode *pDnode) {
}
taosRUnLockLatch
(
&
pMgmt
->
latch
);
dTrace
(
"acquire mnode, refCount:%d"
,
refCount
);
if
(
pMnode
!=
NULL
)
{
dTrace
(
"acquire mnode, refCount:%d"
,
refCount
);
}
return
pMnode
;
}
...
...
@@ -94,7 +96,9 @@ static void dndReleaseMnode(SDnode *pDnode, SMnode *pMnode) {
}
taosRUnLockLatch
(
&
pMgmt
->
latch
);
dTrace
(
"release mnode, refCount:%d"
,
refCount
);
if
(
pMnode
!=
NULL
)
{
dTrace
(
"release mnode, refCount:%d"
,
refCount
);
}
}
static
int32_t
dndReadMnodeFile
(
SDnode
*
pDnode
)
{
...
...
@@ -360,13 +364,13 @@ static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SC
pOption
->
replica
=
pMsg
->
replica
;
pOption
->
selfIndex
=
-
1
;
for
(
int32_t
i
ndex
=
0
;
index
<
pMsg
->
replica
;
++
index
)
{
SReplica
*
pReplica
=
&
pOption
->
replicas
[
i
ndex
];
pReplica
->
id
=
pMsg
->
replicas
[
i
ndex
].
id
;
pReplica
->
port
=
pMsg
->
replicas
[
i
ndex
].
port
;
tstrncpy
(
pReplica
->
fqdn
,
pMsg
->
replicas
[
i
ndex
].
fqdn
,
TSDB_FQDN_LEN
);
for
(
int32_t
i
=
0
;
i
<
pMsg
->
replica
;
++
i
)
{
SReplica
*
pReplica
=
&
pOption
->
replicas
[
i
];
pReplica
->
id
=
pMsg
->
replicas
[
i
].
id
;
pReplica
->
port
=
pMsg
->
replicas
[
i
].
port
;
tstrncpy
(
pReplica
->
fqdn
,
pMsg
->
replicas
[
i
].
fqdn
,
TSDB_FQDN_LEN
);
if
(
pReplica
->
id
==
pOption
->
dnodeId
)
{
pOption
->
selfIndex
=
i
ndex
;
pOption
->
selfIndex
=
i
;
}
}
...
...
@@ -392,7 +396,7 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) {
return
code
;
}
SMnode
*
pMnode
=
mn
ode
Open
(
pDnode
->
dir
.
mnode
,
pOption
);
SMnode
*
pMnode
=
mn
d
Open
(
pDnode
->
dir
.
mnode
,
pOption
);
if
(
pMnode
==
NULL
)
{
dError
(
"failed to open mnode since %s"
,
terrstr
());
code
=
terrno
;
...
...
@@ -405,8 +409,8 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) {
dError
(
"failed to write mnode file since %s"
,
terrstr
());
code
=
terrno
;
dndStopMnodeWorker
(
pDnode
);
mn
ode
Close
(
pMnode
);
mn
ode
Destroy
(
pDnode
->
dir
.
mnode
);
mn
d
Close
(
pMnode
);
mn
d
Destroy
(
pDnode
->
dir
.
mnode
);
terrno
=
code
;
return
code
;
}
...
...
@@ -428,7 +432,7 @@ static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOpt *pOption) {
return
-
1
;
}
if
(
mn
ode
Alter
(
pMnode
,
pOption
)
!=
0
)
{
if
(
mn
d
Alter
(
pMnode
,
pOption
)
!=
0
)
{
dError
(
"failed to alter mnode since %s"
,
terrstr
());
dndReleaseMnode
(
pDnode
,
pMnode
);
return
-
1
;
...
...
@@ -463,8 +467,8 @@ static int32_t dndDropMnode(SDnode *pDnode) {
dndStopMnodeWorker
(
pDnode
);
dndWriteMnodeFile
(
pDnode
);
mn
ode
Close
(
pMnode
);
mn
ode
Destroy
(
pDnode
->
dir
.
mnode
);
mn
d
Close
(
pMnode
);
mn
d
Destroy
(
pDnode
->
dir
.
mnode
);
return
0
;
}
...
...
@@ -491,6 +495,7 @@ static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
if
(
dndBuildMnodeOptionFromMsg
(
pDnode
,
&
option
,
pMsg
)
!=
0
)
{
return
-
1
;
}
return
dndOpenMnode
(
pDnode
,
&
option
);
}
}
...
...
@@ -550,13 +555,13 @@ static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
SMnode
*
pMnode
=
dndAcquireMnode
(
pDnode
);
if
(
pMnode
!=
NULL
)
{
mn
odeProcessReadMsg
(
pMnode
,
pMsg
);
mn
dProcessReadMsg
(
pMsg
);
dndReleaseMnode
(
pDnode
,
pMnode
);
}
else
{
mn
ode
SendRsp
(
pMsg
,
terrno
);
mn
d
SendRsp
(
pMsg
,
terrno
);
}
mn
ode
CleanupMsg
(
pMsg
);
mn
d
CleanupMsg
(
pMsg
);
}
static
void
dndProcessMnodeWriteQueue
(
SDnode
*
pDnode
,
SMnodeMsg
*
pMsg
)
{
...
...
@@ -564,13 +569,13 @@ static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
SMnode
*
pMnode
=
dndAcquireMnode
(
pDnode
);
if
(
pMnode
!=
NULL
)
{
mn
odeProcessWriteMsg
(
pMnode
,
pMsg
);
mn
dProcessWriteMsg
(
pMsg
);
dndReleaseMnode
(
pDnode
,
pMnode
);
}
else
{
mn
ode
SendRsp
(
pMsg
,
terrno
);
mn
d
SendRsp
(
pMsg
,
terrno
);
}
mn
ode
CleanupMsg
(
pMsg
);
mn
d
CleanupMsg
(
pMsg
);
}
static
void
dndProcessMnodeApplyQueue
(
SDnode
*
pDnode
,
SMnodeMsg
*
pMsg
)
{
...
...
@@ -578,13 +583,13 @@ static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
SMnode
*
pMnode
=
dndAcquireMnode
(
pDnode
);
if
(
pMnode
!=
NULL
)
{
mn
odeProcessApplyMsg
(
pMnode
,
pMsg
);
mn
dProcessApplyMsg
(
pMsg
);
dndReleaseMnode
(
pDnode
,
pMnode
);
}
else
{
mn
ode
SendRsp
(
pMsg
,
terrno
);
mn
d
SendRsp
(
pMsg
,
terrno
);
}
mn
ode
CleanupMsg
(
pMsg
);
mn
d
CleanupMsg
(
pMsg
);
}
static
void
dndProcessMnodeSyncQueue
(
SDnode
*
pDnode
,
SMnodeMsg
*
pMsg
)
{
...
...
@@ -592,26 +597,26 @@ static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
SMnode
*
pMnode
=
dndAcquireMnode
(
pDnode
);
if
(
pMnode
!=
NULL
)
{
mn
odeProcessSyncMsg
(
pMnode
,
pMsg
);
mn
dProcessSyncMsg
(
pMsg
);
dndReleaseMnode
(
pDnode
,
pMnode
);
}
else
{
mn
ode
SendRsp
(
pMsg
,
terrno
);
mn
d
SendRsp
(
pMsg
,
terrno
);
}
mn
ode
CleanupMsg
(
pMsg
);
mn
d
CleanupMsg
(
pMsg
);
}
static
int32_t
dndWriteMnodeMsgToQueue
(
SMnode
*
pMnode
,
taos_queue
pQueue
,
SRpcMsg
*
pRpcMsg
)
{
assert
(
pQueue
);
SMnodeMsg
*
pMsg
=
mn
ode
InitMsg
(
pMnode
,
pRpcMsg
);
SMnodeMsg
*
pMsg
=
mn
d
InitMsg
(
pMnode
,
pRpcMsg
);
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
if
(
taosWriteQitem
(
pQueue
,
pMsg
)
!=
0
)
{
mn
ode
CleanupMsg
(
pMsg
);
mn
d
CleanupMsg
(
pMsg
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
...
...
@@ -683,7 +688,7 @@ static int32_t dndPutMsgIntoMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) {
static
int32_t
dndAllocMnodeMgmtQueue
(
SDnode
*
pDnode
)
{
SMnodeMgmt
*
pMgmt
=
&
pDnode
->
mmgmt
;
pMgmt
->
pMgmtQ
=
tWorkerAllocQueue
(
&
pMgmt
->
mgmtPool
,
NULL
,
(
FProcessItem
)
dndProcessMnodeMgmtQueue
);
pMgmt
->
pMgmtQ
=
tWorkerAllocQueue
(
&
pMgmt
->
mgmtPool
,
pDnode
,
(
FProcessItem
)
dndProcessMnodeMgmtQueue
);
if
(
pMgmt
->
pMgmtQ
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
...
...
@@ -708,18 +713,19 @@ static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode) {
return
-
1
;
}
dDebug
(
"mnode mgmt worker is initialized"
);
return
0
;
}
static
void
dndCleanupMnodeMgmtWorker
(
SDnode
*
pDnode
)
{
SMnodeMgmt
*
pMgmt
=
&
pDnode
->
mmgmt
;
tWorkerCleanup
(
&
pMgmt
->
mgmtPool
);
dDebug
(
"mnode mgmt worker is
stopp
ed"
);
dDebug
(
"mnode mgmt worker is
clos
ed"
);
}
static
int32_t
dndAllocMnodeReadQueue
(
SDnode
*
pDnode
)
{
SMnodeMgmt
*
pMgmt
=
&
pDnode
->
mmgmt
;
pMgmt
->
pReadQ
=
tWorkerAllocQueue
(
&
pMgmt
->
readPool
,
NULL
,
(
FProcessItem
)
dndProcessMnodeReadQueue
);
pMgmt
->
pReadQ
=
tWorkerAllocQueue
(
&
pMgmt
->
readPool
,
pDnode
,
(
FProcessItem
)
dndProcessMnodeReadQueue
);
if
(
pMgmt
->
pReadQ
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
...
...
@@ -745,18 +751,19 @@ static int32_t dndInitMnodeReadWorker(SDnode *pDnode) {
return
-
1
;
}
dDebug
(
"mnode read worker is initialized"
);
return
0
;
}
static
void
dndCleanupMnodeReadWorker
(
SDnode
*
pDnode
)
{
SMnodeMgmt
*
pMgmt
=
&
pDnode
->
mmgmt
;
tWorkerCleanup
(
&
pMgmt
->
readPool
);
dDebug
(
"mnode read worker is
stopp
ed"
);
dDebug
(
"mnode read worker is
clos
ed"
);
}
static
int32_t
dndAllocMnodeWriteQueue
(
SDnode
*
pDnode
)
{
SMnodeMgmt
*
pMgmt
=
&
pDnode
->
mmgmt
;
pMgmt
->
pWriteQ
=
tWorkerAllocQueue
(
&
pMgmt
->
writePool
,
NULL
,
(
FProcessItem
)
dndProcessMnodeWriteQueue
);
pMgmt
->
pWriteQ
=
tWorkerAllocQueue
(
&
pMgmt
->
writePool
,
pDnode
,
(
FProcessItem
)
dndProcessMnodeWriteQueue
);
if
(
pMgmt
->
pWriteQ
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
...
...
@@ -773,7 +780,7 @@ static void dndFreeMnodeWriteQueue(SDnode *pDnode) {
static
int32_t
dndAllocMnodeApplyQueue
(
SDnode
*
pDnode
)
{
SMnodeMgmt
*
pMgmt
=
&
pDnode
->
mmgmt
;
pMgmt
->
pApplyQ
=
tWorkerAllocQueue
(
&
pMgmt
->
writePool
,
NULL
,
(
FProcessItem
)
dndProcessMnodeApplyQueue
);
pMgmt
->
pApplyQ
=
tWorkerAllocQueue
(
&
pMgmt
->
writePool
,
pDnode
,
(
FProcessItem
)
dndProcessMnodeApplyQueue
);
if
(
pMgmt
->
pApplyQ
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
...
...
@@ -799,18 +806,19 @@ static int32_t dndInitMnodeWriteWorker(SDnode *pDnode) {
return
-
1
;
}
dDebug
(
"mnode write worker is initialized"
);
return
0
;
}
static
void
dndCleanupMnodeWriteWorker
(
SDnode
*
pDnode
)
{
SMnodeMgmt
*
pMgmt
=
&
pDnode
->
mmgmt
;
tWorkerCleanup
(
&
pMgmt
->
writePool
);
dDebug
(
"mnode write worker is
stopp
ed"
);
dDebug
(
"mnode write worker is
clos
ed"
);
}
static
int32_t
dndAllocMnodeSyncQueue
(
SDnode
*
pDnode
)
{
SMnodeMgmt
*
pMgmt
=
&
pDnode
->
mmgmt
;
pMgmt
->
pSyncQ
=
tWorkerAllocQueue
(
&
pMgmt
->
syncPool
,
NULL
,
(
FProcessItem
)
dndProcessMnodeSyncQueue
);
pMgmt
->
pSyncQ
=
tWorkerAllocQueue
(
&
pMgmt
->
syncPool
,
pDnode
,
(
FProcessItem
)
dndProcessMnodeSyncQueue
);
if
(
pMgmt
->
pSyncQ
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
...
...
@@ -836,13 +844,14 @@ static int32_t dndInitMnodeSyncWorker(SDnode *pDnode) {
return
-
1
;
}
dDebug
(
"mnode sync worker is initialized"
);
return
0
;
}
static
void
dndCleanupMnodeSyncWorker
(
SDnode
*
pDnode
)
{
SMnodeMgmt
*
pMgmt
=
&
pDnode
->
mmgmt
;
tWorkerCleanup
(
&
pMgmt
->
syncPool
);
dDebug
(
"mnode sync worker is
stopp
ed"
);
dDebug
(
"mnode sync worker is
clos
ed"
);
}
int32_t
dndInitMnode
(
SDnode
*
pDnode
)
{
...
...
@@ -869,7 +878,7 @@ int32_t dndInitMnode(SDnode *pDnode) {
if
(
pMgmt
->
dropped
)
{
dInfo
(
"mnode has been deployed and needs to be deleted"
);
mn
ode
Destroy
(
pDnode
->
dir
.
mnode
);
mn
d
Destroy
(
pDnode
->
dir
.
mnode
);
return
0
;
}
...
...
@@ -912,7 +921,7 @@ int32_t dndGetUserAuthFromMnode(SDnode *pDnode, char *user, char *spi, char *enc
return
-
1
;
}
int32_t
code
=
mn
ode
RetriveAuth
(
pMnode
,
user
,
spi
,
encrypt
,
secret
,
ckey
);
int32_t
code
=
mn
d
RetriveAuth
(
pMnode
,
user
,
spi
,
encrypt
,
secret
,
ckey
);
dndReleaseMnode
(
pDnode
,
pMnode
);
return
code
;
}
source/dnode/mgmt/impl/src/dndTransport.c
浏览文件 @
81ebcd8b
...
...
@@ -187,6 +187,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
int32_t
msgType
=
pMsg
->
msgType
;
if
(
msgType
==
TSDB_MSG_TYPE_NETWORK_TEST
)
{
dTrace
(
"RPC %p, network test req will be processed"
,
pMsg
->
handle
);
dndProcessDnodeReq
(
pDnode
,
pMsg
,
pEpSet
);
return
;
}
...
...
@@ -206,6 +207,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
}
if
(
pMsg
->
pCont
==
NULL
)
{
dTrace
(
"RPC %p, req:%s not processed since content is null"
,
pMsg
->
handle
,
taosMsg
[
msgType
]);
SRpcMsg
rspMsg
=
{.
handle
=
pMsg
->
handle
,
.
code
=
TSDB_CODE_DND_INVALID_MSG_LEN
};
rpcSendResponse
(
&
rspMsg
);
return
;
...
...
@@ -259,12 +261,12 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
SDnode
*
pDnode
=
parent
;
if
(
dndAuthInternalMsg
(
parent
,
user
,
spi
,
encrypt
,
secret
,
ckey
)
==
0
)
{
dTrace
(
"get internal auth success"
);
//
dTrace("get internal auth success");
return
0
;
}
if
(
dndGetUserAuthFromMnode
(
pDnode
,
user
,
spi
,
encrypt
,
secret
,
ckey
)
==
0
)
{
dTrace
(
"get auth from internal mnode"
);
//
dTrace("get auth from internal mnode");
return
0
;
}
...
...
@@ -273,7 +275,7 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
return
-
1
;
}
dDebug
(
"user:%s, send auth msg to other mnodes"
,
user
);
//
dDebug("user:%s, send auth msg to other mnodes", user);
SAuthMsg
*
pMsg
=
rpcMallocCont
(
sizeof
(
SAuthMsg
));
tstrncpy
(
pMsg
->
user
,
user
,
TSDB_USER_LEN
);
...
...
source/dnode/mgmt/impl/src/dnode.c
浏览文件 @
81ebcd8b
...
...
@@ -26,7 +26,7 @@
EStat
dndGetStat
(
SDnode
*
pDnode
)
{
return
pDnode
->
stat
;
}
void
dndSetStat
(
SDnode
*
pDnode
,
EStat
stat
)
{
dDebug
(
"dnode stat set from %s to %s"
,
dndStatStr
(
pDnode
->
stat
),
dndStatStr
(
stat
));
dDebug
(
"dnode stat
us
set from %s to %s"
,
dndStatStr
(
pDnode
->
stat
),
dndStatStr
(
stat
));
pDnode
->
stat
=
stat
;
}
...
...
@@ -214,8 +214,7 @@ void dndCleanup(SDnode *pDnode) {
dndCleanupDnode
(
pDnode
);
walCleanUp
();
rpcCleanup
();
dInfo
(
"TDengine is cleaned up successfully"
);
dndCleanupEnv
(
pDnode
);
free
(
pDnode
);
dInfo
(
"TDengine is cleaned up successfully"
);
}
source/dnode/mnode/impl/CMakeLists.txt
浏览文件 @
81ebcd8b
...
...
@@ -3,11 +3,11 @@ add_library(mnode ${MNODE_SRC})
target_include_directories
(
mnode
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/dnode/mnode"
private
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
target_link_libraries
(
mnode
PRIVATE sdb
P
UBLIC
transport
P
UBLIC
cjson
P
RIVATE
transport
P
RIVATE
cjson
)
\ No newline at end of file
source/dnode/mnode/impl/inc/mn
ode
Acct.h
→
source/dnode/mnode/impl/inc/mn
d
Acct.h
浏览文件 @
81ebcd8b
...
...
@@ -13,20 +13,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MN
ODE
_ACCT_H_
#define _TD_MN
ODE
_ACCT_H_
#ifndef _TD_MN
D
_ACCT_H_
#define _TD_MN
D
_ACCT_H_
#include "mn
ode
Int.h"
#include "mn
d
Int.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mn
odeInitAcct
(
);
void
mn
odeCleanupAcct
(
);
int32_t
mn
dInitAcct
(
SMnode
*
pMnode
);
void
mn
dCleanupAcct
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MN
ODE
_ACCT_H_*/
#endif
/*_TD_MN
D
_ACCT_H_*/
source/dnode/mnode/impl/inc/mn
ode
Auth.h
→
source/dnode/mnode/impl/inc/mn
d
Auth.h
浏览文件 @
81ebcd8b
...
...
@@ -13,20 +13,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MN
ODE
_AUTH_H_
#define _TD_MN
ODE
_AUTH_H_
#ifndef _TD_MN
D
_AUTH_H_
#define _TD_MN
D
_AUTH_H_
#include "mn
ode
Int.h"
#include "mn
d
Int.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mn
odeInitAuth
(
);
void
mn
odeCleanupAuth
(
);
int32_t
mn
dInitAuth
(
SMnode
*
pMnode
);
void
mn
dCleanupAuth
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MN
ODE
_AUTH_H_*/
#endif
/*_TD_MN
D
_AUTH_H_*/
source/dnode/mnode/impl/inc/mndBalance.h
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MND_BALANCE_H_
#define _TD_MND_BALANCE_H_
#include "mndInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitBalance
(
SMnode
*
pMnode
);
void
mndCleanupBalance
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_BALANCE_H_*/
source/dnode/mnode/impl/inc/mndCluster.h
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MND_CLUSTER_H_
#define _TD_MND_CLUSTER_H_
#include "mndInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitCluster
(
SMnode
*
pMnode
);
void
mndCleanupCluster
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_CLUSTER_H_*/
source/dnode/mnode/impl/inc/mndDb.h
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MND_DATABASE_H_
#define _TD_MND_DATABASE_H_
#include "mndInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitDb
(
SMnode
*
pMnode
);
void
mndCleanupDb
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_DATABASE_H_*/
source/dnode/mnode/impl/inc/mn
ode
Def.h
→
source/dnode/mnode/impl/inc/mn
d
Def.h
浏览文件 @
81ebcd8b
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MN
ODE
_DEF_H_
#define _TD_MN
ODE
_DEF_H_
#ifndef _TD_MN
D
_DEF_H_
#define _TD_MN
D
_DEF_H_
#include "os.h"
#include "taosmsg.h"
...
...
@@ -39,42 +39,34 @@ extern int32_t mDebugFlag;
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
// #define mLError(...) { monSaveLog(2, __VA_ARGS__); mError(__VA_ARGS__) }
// #define mLWarn(...) { monSaveLog(1, __VA_ARGS__); mWarn(__VA_ARGS__) }
// #define mLInfo(...) { monSaveLog(0, __VA_ARGS__); mInfo(__VA_ARGS__) }
#define mLError(...) {mError(__VA_ARGS__) }
#define mLWarn(...) {mWarn(__VA_ARGS__) }
#define mLInfo(...) {mInfo(__VA_ARGS__) }
typedef
struct
SClusterObj
SClusterObj
;
typedef
struct
SDnodeObj
SDnodeObj
;
typedef
struct
SMnodeObj
SMnodeObj
;
typedef
struct
SAcctObj
SAcctObj
;
typedef
struct
SUserObj
SUserObj
;
typedef
struct
SDbObj
SDbObj
;
typedef
struct
SVgObj
SVgObj
;
typedef
struct
SSTableObj
SSTableObj
;
typedef
struct
SFuncObj
SFuncObj
;
typedef
struct
SOperObj
SOperObj
;
typedef
struct
SClusterObj
SClusterObj
;
typedef
struct
SDnodeObj
SDnodeObj
;
typedef
struct
SMnodeObj
SMnodeObj
;
typedef
struct
SAcctObj
SAcctObj
;
typedef
struct
SUserObj
SUserObj
;
typedef
struct
SDbObj
SDbObj
;
typedef
struct
SVgObj
SVgObj
;
typedef
struct
SSTableObj
SSTableObj
;
typedef
struct
SFuncObj
SFuncObj
;
typedef
struct
SOperObj
SOperObj
;
typedef
enum
{
MN_AUTH_ACCT_START
=
0
,
MN_AUTH_ACCT_USER
,
MN_AUTH_ACCT_DNODE
,
MN_AUTH_ACCT_MNODE
,
MN_AUTH_ACCT_DB
,
MN_AUTH_ACCT_TABLE
,
MN_AUTH_ACCT_MAX
}
E
Mn
AuthAcct
;
MN
D
_AUTH_ACCT_START
=
0
,
MN
D
_AUTH_ACCT_USER
,
MN
D
_AUTH_ACCT_DNODE
,
MN
D
_AUTH_ACCT_MNODE
,
MN
D
_AUTH_ACCT_DB
,
MN
D
_AUTH_ACCT_TABLE
,
MN
D
_AUTH_ACCT_MAX
}
EAuthAcct
;
typedef
enum
{
MN_AUTH_OP_START
=
0
,
MN_AUTH_OP_CREATE_USER
,
MN_AUTH_OP_ALTER_USER
,
MN_AUTH_OP_DROP_USER
,
MN_AUTH_MAX
}
E
Mn
AuthOp
;
MN
D
_AUTH_OP_START
=
0
,
MN
D
_AUTH_OP_CREATE_USER
,
MN
D
_AUTH_OP_ALTER_USER
,
MN
D
_AUTH_OP_DROP_USER
,
MN
D
_AUTH_MAX
}
EAuthOp
;
typedef
enum
{
TRN_STAGE_PREPARE
=
1
,
...
...
@@ -86,11 +78,11 @@ typedef enum {
typedef
enum
{
TRN_POLICY_ROLLBACK
=
1
,
TRN_POLICY_RETRY
=
2
}
ETrnPolicy
;
typedef
struct
STrans
{
int32_t
id
;
ETrnStage
stage
;
ETrnPolicy
policy
;
SMnode
*
pMnode
;
void
*
rpcHandle
;
SArray
*
redoLogs
;
SArray
*
undoLogs
;
...
...
@@ -99,7 +91,6 @@ typedef struct STrans {
SArray
*
undoActions
;
}
STrans
;
typedef
struct
SClusterObj
{
int64_t
id
;
char
uid
[
TSDB_CLUSTER_ID_LEN
];
...
...
@@ -202,6 +193,7 @@ typedef struct SDbObj {
int64_t
createdTime
;
int64_t
updateTime
;
SDbCfg
cfg
;
int64_t
uid
;
int8_t
status
;
int32_t
numOfVgroups
;
int32_t
numOfTables
;
...
...
@@ -240,13 +232,13 @@ typedef struct SVgObj {
}
SVgObj
;
typedef
struct
SSTableObj
{
char
tableId
[
TSDB_TABLE_NAME_LEN
];
uint64_t
uid
;
int64_t
createdTime
;
int64_t
updateTime
;
int32_t
numOfColumns
;
// used by normal table
int32_t
numOfTags
;
SSchema
*
schema
;
char
tableId
[
TSDB_TABLE_NAME_LEN
];
uint64_t
uid
;
int64_t
createdTime
;
int64_t
updateTime
;
int32_t
numOfColumns
;
// used by normal table
int32_t
numOfTags
;
SSchema
*
schema
;
}
SSTableObj
;
typedef
struct
SFuncObj
{
...
...
@@ -284,25 +276,26 @@ typedef struct {
typedef
struct
{
int32_t
len
;
void
*
rsp
;
}
SMnRsp
;
}
SMn
ode
Rsp
;
typedef
struct
SMnodeMsg
{
SMnode
*
pMnode
;
void
(
*
fp
)(
SMnodeMsg
*
pMsg
,
int32_t
code
);
SRpcConnInfo
conn
;
SUserObj
*
pUser
;
int16_t
received
;
int16_t
successed
;
int16_t
expected
;
int16_t
retry
;
int32_t
code
;
int64_t
createdTime
;
SMn
Rsp
rpcRsp
;
SRpcMsg
rpcMsg
;
char
pCont
[];
SUserObj
*
pUser
;
int16_t
received
;
int16_t
successed
;
int16_t
expected
;
int16_t
retry
;
int32_t
code
;
int64_t
createdTime
;
SMn
odeRsp
rpcRsp
;
SRpcMsg
rpcMsg
;
char
pCont
[];
}
SMnodeMsg
;
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MN
ODE
_DEF_H_*/
#endif
/*_TD_MN
D
_DEF_H_*/
source/dnode/mnode/impl/inc/mndDnode.h
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MND_DNODE_H_
#define _TD_MND_DNODE_H_
#include "mndInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitDnode
(
SMnode
*
pMnode
);
void
mndCleanupDnode
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_DNODE_H_*/
source/dnode/mnode/impl/inc/mn
odeBalance
.h
→
source/dnode/mnode/impl/inc/mn
dFunc
.h
浏览文件 @
81ebcd8b
...
...
@@ -13,20 +13,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MN
ODE_BALANCE
_H_
#define _TD_MN
ODE_BALANCE
_H_
#ifndef _TD_MN
D_FUNC
_H_
#define _TD_MN
D_FUNC
_H_
#include "mn
ode
Int.h"
#include "mn
d
Int.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mn
odeInitBalance
(
);
void
mn
odeCleanupBalance
(
);
int32_t
mn
dInitFunc
(
SMnode
*
pMnode
);
void
mn
dCleanupFunc
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MN
ODE_BALANCE
_H_*/
#endif
/*_TD_MN
D_FUNC
_H_*/
source/dnode/mnode/impl/inc/mn
ode
Int.h
→
source/dnode/mnode/impl/inc/mn
d
Int.h
浏览文件 @
81ebcd8b
...
...
@@ -13,28 +13,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MN
ODE
_INT_H_
#define _TD_MN
ODE
_INT_H_
#ifndef _TD_MN
D
_INT_H_
#define _TD_MN
D
_INT_H_
#include "mn
ode
Def.h"
#include "mn
d
Def.h"
#include "sdb.h"
#include "t
step
.h"
#include "t
queue
.h"
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
int32_t
(
*
MnodeRpcFp
)(
SMnodeMsg
*
pMsg
);
typedef
int32_t
(
*
MndMsgFp
)(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
);
typedef
int32_t
(
*
MndInitFp
)(
SMnode
*
pMnode
);
typedef
void
(
*
MndCleanupFp
)(
SMnode
*
pMnode
);
typedef
struct
SMnodeBak
{
int32_t
dnodeId
;
int64_t
clusterId
;
tmr_h
timer
;
SSteps
*
pInitSteps
;
SSteps
*
pStartSteps
;
SMnodeOpt
para
;
MnodeRpcFp
msgFp
[
TSDB_MSG_TYPE_MAX
];
}
SMnodeBak
;
typedef
struct
{
const
char
*
name
;
MndInitFp
initFp
;
MndCleanupFp
cleanupFp
;
}
SMnodeStep
;
typedef
struct
SMnode
{
int32_t
dnodeId
;
...
...
@@ -43,29 +41,28 @@ typedef struct SMnode {
int8_t
selfIndex
;
SReplica
replicas
[
TSDB_MAX_REPLICA
];
tmr_h
timer
;
SSteps
*
pInitSteps
;
SSteps
*
pStartSteps
;
struct
SSdb
*
pSdb
;
struct
SDnode
*
pServer
;
MnodeRpcFp
msgFp
[
TSDB_MSG_TYPE_MAX
];
PutMsgToMnodeQFp
putMsgToApplyMsgFp
;
char
*
path
;
SSdb
*
pSdb
;
SDnode
*
pDnode
;
SArray
*
pSteps
;
MndMsgFp
msgFp
[
TSDB_MSG_TYPE_MAX
];
SendMsgToDnodeFp
sendMsgToDnodeFp
;
SendMsgToMnodeFp
sendMsgToMnodeFp
;
SendRedirectMsgFp
sendRedirectMsgFp
;
PutMsgToMnodeQFp
putMsgToApplyMsgFp
;
}
SMnode
;
tmr_h
mnodeGetTimer
();
int32_t
mnodeGetDnodeId
();
int64_t
mnodeGetClusterId
();
void
mnodeSendMsgToDnode
(
SMnode
*
pMnode
,
struct
SEpSet
*
epSet
,
struct
SRpcMsg
*
rpcMsg
);
void
mnodeSendMsgToMnode
(
SMnode
*
pMnode
,
struct
SRpcMsg
*
rpcMsg
);
void
mnodeSendRedirectMsg
(
SMnode
*
pMnode
,
struct
SRpcMsg
*
rpcMsg
,
bool
forShell
);
tmr_h
mndGetTimer
(
SMnode
*
pMnode
);
int32_t
mndGetDnodeId
(
SMnode
*
pMnode
);
int64_t
mndGetClusterId
(
SMnode
*
pMnode
);
void
mnodeSetMsgFp
(
int32_t
msgType
,
MnodeRpcFp
fp
);
void
mndSendMsgToDnode
(
SMnode
*
pMnode
,
SEpSet
*
pEpSet
,
SRpcMsg
*
rpcMsg
);
void
mndSendMsgToMnode
(
SMnode
*
pMnode
,
SRpcMsg
*
pMsg
);
void
mndSendRedirectMsg
(
SMnode
*
pMnode
,
SRpcMsg
*
pMsg
);
void
mndSetMsgHandle
(
SMnode
*
pMnode
,
int32_t
msgType
,
MndMsgFp
fp
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MN
ODE
_INT_H_*/
#endif
/*_TD_MN
D
_INT_H_*/
source/dnode/mnode/impl/inc/mndMnode.h
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MND_MNODE_H_
#define _TD_MND_MNODE_H_
#include "mndInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitMnode
(
SMnode
*
pMnode
);
void
mndCleanupMnode
(
SMnode
*
pMnode
);
void
mndGetMnodeEpSetForPeer
(
SEpSet
*
epSet
,
bool
redirect
);
void
mndGetMnodeEpSetForShell
(
SEpSet
*
epSet
,
bool
redirect
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_MNODE_H_*/
source/dnode/mnode/impl/inc/mn
ode
Oper.h
→
source/dnode/mnode/impl/inc/mn
d
Oper.h
浏览文件 @
81ebcd8b
...
...
@@ -13,18 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MN
ODE
_OPER_H_
#define _TD_MN
ODE
_OPER_H_
#ifndef _TD_MN
D
_OPER_H_
#define _TD_MN
D
_OPER_H_
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mn
odeInitOper
(
);
void
mn
odeCleanupOper
(
);
int32_t
mn
dInitOper
(
SMnode
*
pMnode
);
void
mn
dCleanupOper
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MN
ODE
_OPER_H_*/
#endif
/*_TD_MN
D
_OPER_H_*/
source/dnode/mnode/impl/inc/mndProfile.h
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MND_PROFILE_H_
#define _TD_MND_PROFILE_H_
#include "mndInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitProfile
(
SMnode
*
pMnode
);
void
mndCleanupProfile
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_PROFILE_H_*/
source/dnode/mnode/impl/inc/mn
odeCluster
.h
→
source/dnode/mnode/impl/inc/mn
dShow
.h
浏览文件 @
81ebcd8b
...
...
@@ -13,20 +13,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MN
ODE_CLUSTER
_H_
#define _TD_MN
ODE_CLUSTER
_H_
#ifndef _TD_MN
D_SHOW
_H_
#define _TD_MN
D_SHOW
_H_
#include "mn
ode
Int.h"
#include "mn
d
Int.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mn
odeInitCluster
(
);
void
mn
odeCleanupCluster
(
);
int32_t
mn
dInitShow
(
SMnode
*
pMnode
);
void
mn
dCleanupShow
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MN
ODE_CLUSTER
_H_*/
#endif
/*_TD_MN
D_SHOW
_H_*/
source/dnode/mnode/impl/inc/mndStable.h
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MND_STABLE_H_
#define _TD_MND_STABLE_H_
#include "mndInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitStable
(
SMnode
*
pMnode
);
void
mndCleanupStable
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_STABLE_H_*/
source/dnode/mnode/impl/inc/mndSync.h
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MND_SYNC_H_
#define _TD_MND_SYNC_H_
#include "mndInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitSync
(
SMnode
*
pMnode
);
void
mndCleanupSync
(
SMnode
*
pMnode
);
bool
mndIsMaster
(
SMnode
*
pMnode
);
int32_t
mndSyncPropose
(
SSdbRaw
*
pRaw
,
void
*
pData
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_SYNC_H_*/
source/dnode/mnode/impl/inc/mn
ode
Telem.h
→
source/dnode/mnode/impl/inc/mn
d
Telem.h
浏览文件 @
81ebcd8b
...
...
@@ -13,19 +13,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MN
ODE
_TELEMETRY_H_
#define _TD_MN
ODE
_TELEMETRY_H_
#ifndef _TD_MN
D
_TELEMETRY_H_
#define _TD_MN
D
_TELEMETRY_H_
#ifdef __cplusplus
extern
"C"
{
#endif
#include "mn
ode
Int.h"
#include "mn
d
Int.h"
int32_t
mn
odeInitTelem
(
);
void
mn
odeCleanupTelem
(
);
int32_t
mn
dInitTelem
(
SMnode
*
pMnode
);
void
mn
dCleanupTelem
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MN
ODE
_TELEMETRY_H_*/
#endif
/*_TD_MN
D
_TELEMETRY_H_*/
source/dnode/mnode/impl/inc/mn
ode
Trans.h
→
source/dnode/mnode/impl/inc/mn
d
Trans.h
浏览文件 @
81ebcd8b
...
...
@@ -16,29 +16,29 @@
#ifndef _TD_TRANSACTION_INT_H_
#define _TD_TRANSACTION_INT_H_
#include "mn
ode
Int.h"
#include "mn
d
Int.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mn
odeInitTrans
(
);
void
mn
odeCleanupTrans
(
);
int32_t
mn
dInitTrans
(
SMnode
*
pMnode
);
void
mn
dCleanupTrans
(
SMnode
*
pMnode
);
STrans
*
trnCreate
(
ETrnPolicy
policy
,
void
*
rpcHandle
);
void
trn
Drop
(
STrans
*
pTrans
);
int32_t
trnAppendRedoL
og
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
);
int32_t
trnAppendUndoL
og
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
);
int32_t
trnAppendCommitL
og
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
);
int32_t
trn
AppendRedoAction
(
STrans
*
pTrans
,
SEpSet
*
,
void
*
pMsg
);
int32_t
trn
AppendUndoAction
(
STrans
*
pTrans
,
SEpSet
*
,
void
*
pMsg
);
STrans
*
mndTransCreate
(
SMnode
*
pMnode
,
ETrnPolicy
policy
,
void
*
rpcHandle
);
void
mndTrans
Drop
(
STrans
*
pTrans
);
int32_t
mndTransAppendRedol
og
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
);
int32_t
mndTransAppendUndol
og
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
);
int32_t
mndTransAppendCommitl
og
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
);
int32_t
mndTrans
AppendRedoAction
(
STrans
*
pTrans
,
SEpSet
*
,
void
*
pMsg
);
int32_t
mndTrans
AppendUndoAction
(
STrans
*
pTrans
,
SEpSet
*
,
void
*
pMsg
);
int32_t
trn
Prepare
(
STrans
*
pTrans
,
int32_t
(
*
syncfp
)(
SSdbRaw
*
pRaw
,
void
*
pData
));
int32_t
trnApply
(
SSdbRaw
*
pRaw
,
void
*
pData
,
int32_t
code
);
int32_t
trnExecute
(
int32_t
tranId
);
int32_t
mndTrans
Prepare
(
STrans
*
pTrans
,
int32_t
(
*
syncfp
)(
SSdbRaw
*
pRaw
,
void
*
pData
));
int32_t
mndTransApply
(
SMnode
*
pMnode
,
SSdbRaw
*
pRaw
,
void
*
pData
,
int32_t
code
);
int32_t
mndTransExecute
(
SSdb
*
pSdb
,
int32_t
tranId
);
SSdbRaw
*
trn
ActionEncode
(
STrans
*
pTrans
);
SSdbRow
*
trn
ActionDecode
(
SSdbRaw
*
pRaw
);
SSdbRaw
*
mndTrans
ActionEncode
(
STrans
*
pTrans
);
SSdbRow
*
mndTrans
ActionDecode
(
SSdbRaw
*
pRaw
);
#ifdef __cplusplus
}
...
...
source/dnode/mnode/impl/inc/mndUser.h
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MND_USER_H_
#define _TD_MND_USER_H_
#include "mndInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitUser
(
SMnode
*
pMnode
);
void
mndCleanupUser
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_USER_H_*/
source/dnode/mnode/impl/inc/mndVgroup.h
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MND_VGROUP_H_
#define _TD_MND_VGROUP_H_
#include "mndInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mndInitVgroup
(
SMnode
*
pMnode
);
void
mndCleanupVgroup
(
SMnode
*
pMnode
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MND_VGROUP_H_*/
source/dnode/mnode/impl/inc/mnodeDb.h
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MNODE_DATABASE_H_
#define _TD_MNODE_DATABASE_H_
#include "mnodeInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mnodeInitDb
();
void
mnodeCleanupDb
();
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MNODE_DATABASE_H_*/
source/dnode/mnode/impl/inc/mnodeDnode.h
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MNODE_DNODE_H_
#define _TD_MNODE_DNODE_H_
#include "mnodeInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mnodeInitDnode
();
void
mnodeCleanupDnode
();
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MNODE_DNODE_H_*/
source/dnode/mnode/impl/inc/mnodeFunc.h
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MNODE_FUNC_H_
#define _TD_MNODE_FUNC_H_
#include "mnodeInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mnodeInitFunc
();
void
mnodeCleanupFunc
();
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MNODE_FUNC_H_*/
source/dnode/mnode/impl/inc/mnodeMnode.h
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MNODE_MNODE_H_
#define _TD_MNODE_MNODE_H_
#include "mnodeInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mnodeInitMnode
();
void
mnodeCleanupMnode
();
void
mnodeGetMnodeEpSetForPeer
(
SEpSet
*
epSet
,
bool
redirect
);
void
mnodeGetMnodeEpSetForShell
(
SEpSet
*
epSet
,
bool
redirect
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MNODE_MNODE_H_*/
source/dnode/mnode/impl/inc/mnodeProfile.h
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MNODE_PROFILE_H_
#define _TD_MNODE_PROFILE_H_
#include "mnodeInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mnodeInitProfile
();
void
mnodeCleanupProfile
();
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MNODE_PROFILE_H_*/
source/dnode/mnode/impl/inc/mnodeShow.h
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MNODE_SHOW_H_
#define _TD_MNODE_SHOW_H_
#include "mnodeInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mnodeInitShow
();
void
mnodeCleanUpShow
();
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MNODE_SHOW_H_*/
source/dnode/mnode/impl/inc/mnodeStable.h
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MNODE_STABLE_H_
#define _TD_MNODE_STABLE_H_
#include "mnodeInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mnodeInitStable
();
void
mnodeCleanupStable
();
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MNODE_STABLE_H_*/
source/dnode/mnode/impl/inc/mnodeSync.h
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MNODE_SYNC_H_
#define _TD_MNODE_SYNC_H_
#include "mnodeInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mnodeInitSync
();
void
mnodeCleanUpSync
();
int32_t
mnodeSyncPropose
(
SSdbRaw
*
pRaw
,
void
*
pData
);
bool
mnodeIsMaster
();
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MNODE_SYNC_H_*/
source/dnode/mnode/impl/inc/mnodeUser.h
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MNODE_USER_H_
#define _TD_MNODE_USER_H_
#include "mnodeInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mnodeInitUser
();
void
mnodeCleanupUser
();
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MNODE_USER_H_*/
source/dnode/mnode/impl/inc/mnodeVgroup.h
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_MNODE_VGROUP_H_
#define _TD_MNODE_VGROUP_H_
#include "mnodeInt.h"
#ifdef __cplusplus
extern
"C"
{
#endif
int32_t
mnodeInitVgroup
();
void
mnodeCleanupVgroup
();
#ifdef __cplusplus
}
#endif
#endif
/*_TD_MNODE_VGROUP_H_*/
source/dnode/mnode/impl/src/mn
ode
Acct.c
→
source/dnode/mnode/impl/src/mn
d
Acct.c
浏览文件 @
81ebcd8b
...
...
@@ -14,7 +14,7 @@
*/
#define _DEFAULT_SOURCE
#include "mn
ode
Int.h"
#include "mn
d
Int.h"
#define SDB_ACCT_VER 1
...
...
@@ -48,10 +48,10 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
return
NULL
;
}
SSdbRow
*
pRow
=
sdbAllocRow
(
sizeof
(
SAcctObj
));
SSdbRow
*
pRow
=
sdbAllocRow
(
sizeof
(
SAcctObj
));
SAcctObj
*
pAcct
=
sdbGetRowObj
(
pRow
);
if
(
pAcct
==
NULL
)
return
NULL
;
int32_t
dataPos
=
0
;
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pAcct
->
acct
,
TSDB_USER_LEN
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pAcct
->
createdTime
)
...
...
@@ -68,18 +68,18 @@ static SSdbRow *mnodeAcctActionDecode(SSdbRaw *pRaw) {
return
pRow
;
}
static
int32_t
mnodeAcctActionInsert
(
SAcctObj
*
pAcct
)
{
return
0
;
}
static
int32_t
mnodeAcctActionInsert
(
S
Sdb
*
pSdb
,
S
AcctObj
*
pAcct
)
{
return
0
;
}
static
int32_t
mnodeAcctActionDelete
(
SAcctObj
*
pAcct
)
{
return
0
;
}
static
int32_t
mnodeAcctActionDelete
(
S
Sdb
*
pSdb
,
S
AcctObj
*
pAcct
)
{
return
0
;
}
static
int32_t
mnodeAcctActionUpdate
(
SAcctObj
*
pSrcAcct
,
SAcctObj
*
pDstAcct
)
{
static
int32_t
mnodeAcctActionUpdate
(
S
Sdb
*
pSdb
,
S
AcctObj
*
pSrcAcct
,
SAcctObj
*
pDstAcct
)
{
SAcctObj
tObj
;
int32_t
len
=
(
int32_t
)((
int8_t
*
)
&
tObj
.
info
-
(
int8_t
*
)
&
tObj
);
memcpy
(
pDstAcct
,
pSrcAcct
,
len
);
return
0
;
}
static
int32_t
mnodeCreateDefaultAcct
()
{
static
int32_t
mnodeCreateDefaultAcct
(
SSdb
*
pSdb
)
{
int32_t
code
=
0
;
SAcctObj
acctObj
=
{
0
};
...
...
@@ -98,21 +98,20 @@ static int32_t mnodeCreateDefaultAcct() {
if
(
pRaw
==
NULL
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
return
sdbWrite
(
pRaw
);
return
sdbWrite
(
p
Sdb
,
p
Raw
);
}
int32_t
mn
odeInitAcct
(
)
{
int32_t
mn
dInitAcct
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_ACCT
,
.
keyType
=
SDB_KEY_BINARY
,
.
deployFp
=
(
SdbDeployFp
)
mnodeCreateDefaultAcct
,
.
deployFp
=
mnodeCreateDefaultAcct
,
.
encodeFp
=
(
SdbEncodeFp
)
mnodeAcctActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mnodeAcctActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mnodeAcctActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mnodeAcctActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mnodeAcctActionDelete
};
sdbSetTable
(
table
);
return
0
;
return
sdbSetTable
(
pMnode
->
pSdb
,
table
)
;
}
void
mn
odeCleanupAcct
(
)
{}
void
mn
dCleanupAcct
(
SMnode
*
pMnode
)
{}
source/dnode/mnode/impl/src/mn
ode
Auth.c
→
source/dnode/mnode/impl/src/mn
d
Auth.c
浏览文件 @
81ebcd8b
...
...
@@ -15,11 +15,11 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "mn
ode
Auth.h"
#include "mn
d
Auth.h"
int32_t
mn
odeInitAuth
(
)
{
return
0
;
}
void
mn
odeCleanupAuth
(
)
{}
int32_t
mn
dInitAuth
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mn
dCleanupAuth
(
SMnode
*
pMnode
)
{}
int32_t
mn
ode
RetriveAuth
(
SMnode
*
pMnode
,
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
int32_t
mn
d
RetriveAuth
(
SMnode
*
pMnode
,
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
return
0
;
}
\ No newline at end of file
source/dnode/mnode/impl/src/mndBalance.c
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mndInt.h"
int32_t
mndInitBalance
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mndCleanupBalance
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mndCluster.c
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mndInt.h"
int32_t
mndInitCluster
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mndCleanupCluster
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mn
odeDnode
.c
→
source/dnode/mnode/impl/src/mn
dDb
.c
浏览文件 @
81ebcd8b
...
...
@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "mn
ode
Int.h"
#include "mn
d
Int.h"
int32_t
mnodeInitDnode
()
{
return
0
;
}
void
mnodeCleanupDnode
()
{}
\ No newline at end of file
int32_t
mndInitDb
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mndCleanupDb
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mndDnode.c
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mndInt.h"
int32_t
mndInitDnode
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mndCleanupDnode
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mn
odeBalance
.c
→
source/dnode/mnode/impl/src/mn
dFunc
.c
浏览文件 @
81ebcd8b
...
...
@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "mn
ode
Int.h"
#include "mn
d
Int.h"
int32_t
mnodeInitBalance
()
{
return
0
;
}
void
mnodeCleanupBalance
()
{}
\ No newline at end of file
int32_t
mndInitFunc
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mndCleanupFunc
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mn
ode
Mnode.c
→
source/dnode/mnode/impl/src/mn
d
Mnode.c
浏览文件 @
81ebcd8b
...
...
@@ -15,10 +15,10 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "mn
ode
Int.h"
#include "mn
d
Int.h"
int32_t
mn
odeInitMnode
(
)
{
return
0
;
}
void
mn
odeCleanupMnode
(
)
{}
int32_t
mn
dInitMnode
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mn
dCleanupMnode
(
SMnode
*
pMnode
)
{}
void
mnodeGetMnodeEpSetForPeer
(
SEpSet
*
epSet
,
bool
redirect
)
{}
void
mnodeGetMnodeEpSetForShell
(
SEpSet
*
epSet
,
bool
redirect
)
{}
\ No newline at end of file
void
mndGetMnodeEpSetForPeer
(
SEpSet
*
epSet
,
bool
redirect
)
{}
void
mndGetMnodeEpSetForShell
(
SEpSet
*
epSet
,
bool
redirect
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mn
odeClust
er.c
→
source/dnode/mnode/impl/src/mn
dOp
er.c
浏览文件 @
81ebcd8b
...
...
@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "mn
ode
Int.h"
#include "mn
d
Int.h"
int32_t
mnodeInitCluster
()
{
return
0
;
}
void
mnodeCleanupCluster
()
{}
\ No newline at end of file
int32_t
mndInitOper
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mndCleanupOper
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mndProfile.c
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mndInt.h"
int32_t
mndInitProfile
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mndCleanupProfile
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mn
odeDb
.c
→
source/dnode/mnode/impl/src/mn
dShow
.c
浏览文件 @
81ebcd8b
...
...
@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "mn
ode
Int.h"
#include "mn
d
Int.h"
int32_t
mnodeInitDb
()
{
return
0
;
}
void
mnodeCleanupDb
()
{}
\ No newline at end of file
int32_t
mndInitShow
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mndCleanupShow
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mndStable.c
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mndInt.h"
int32_t
mndInitStable
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mndCleanupStable
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mn
ode
Sync.c
→
source/dnode/mnode/impl/src/mn
d
Sync.c
浏览文件 @
81ebcd8b
...
...
@@ -15,16 +15,16 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "mn
ode
Int.h"
#include "mn
ode
Trans.h"
#include "mn
d
Int.h"
#include "mn
d
Trans.h"
int32_t
mn
odeInitSync
(
)
{
return
0
;
}
void
mn
odeCleanUpSync
(
)
{}
int32_t
mn
dInitSync
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mn
dCleanupSync
(
SMnode
*
pMnode
)
{}
int32_t
mn
odeSyncPropose
(
SSdbRaw
*
pRaw
,
void
*
pData
)
{
trnApply
(
pData
,
pData
,
0
);
int32_t
mn
dSyncPropose
(
SMnode
*
pMnode
,
SSdbRaw
*
pRaw
,
void
*
pData
)
{
mndTransApply
(
pMnode
,
pData
,
pData
,
0
);
free
(
pData
);
return
0
;
}
bool
mnodeIsMaster
()
{
return
true
;
}
\ No newline at end of file
bool
mndIsMaster
(
SMnode
*
pMnode
)
{
return
true
;
}
\ No newline at end of file
source/dnode/mnode/impl/src/mn
ode
Telem.c
→
source/dnode/mnode/impl/src/mn
d
Telem.c
浏览文件 @
81ebcd8b
...
...
@@ -14,10 +14,10 @@
*/
#define _DEFAULT_SOURCE
#include "mn
ode
Telem.h"
#include "mn
d
Telem.h"
#include "tbuffer.h"
#include "tglobal.h"
#include "mn
ode
Sync.h"
#include "mn
d
Sync.h"
#define TELEMETRY_SERVER "telemetry.taosdata.com"
#define TELEMETRY_PORT 80
...
...
@@ -36,9 +36,9 @@ static struct {
char
email
[
TSDB_FQDN_LEN
];
}
tsTelem
;
static
void
mn
ode
BeginObject
(
SBufferWriter
*
bw
)
{
tbufWriteChar
(
bw
,
'{'
);
}
static
void
mn
d
BeginObject
(
SBufferWriter
*
bw
)
{
tbufWriteChar
(
bw
,
'{'
);
}
static
void
mn
ode
CloseObject
(
SBufferWriter
*
bw
)
{
static
void
mn
d
CloseObject
(
SBufferWriter
*
bw
)
{
size_t
len
=
tbufTell
(
bw
);
if
(
tbufGetData
(
bw
,
false
)[
len
-
1
]
==
','
)
{
tbufWriteCharAt
(
bw
,
len
-
1
,
'}'
);
...
...
@@ -64,14 +64,14 @@ static void closeArray(SBufferWriter* bw) {
}
#endif
static
void
mn
ode
WriteString
(
SBufferWriter
*
bw
,
const
char
*
str
)
{
static
void
mn
d
WriteString
(
SBufferWriter
*
bw
,
const
char
*
str
)
{
tbufWriteChar
(
bw
,
'"'
);
tbufWrite
(
bw
,
str
,
strlen
(
str
));
tbufWriteChar
(
bw
,
'"'
);
}
static
void
mn
ode
AddIntField
(
SBufferWriter
*
bw
,
const
char
*
k
,
int64_t
v
)
{
mn
ode
WriteString
(
bw
,
k
);
static
void
mn
d
AddIntField
(
SBufferWriter
*
bw
,
const
char
*
k
,
int64_t
v
)
{
mn
d
WriteString
(
bw
,
k
);
tbufWriteChar
(
bw
,
':'
);
char
buf
[
32
];
sprintf
(
buf
,
"%"
PRId64
,
v
);
...
...
@@ -79,14 +79,14 @@ static void mnodeAddIntField(SBufferWriter* bw, const char* k, int64_t v) {
tbufWriteChar
(
bw
,
','
);
}
static
void
mn
ode
AddStringField
(
SBufferWriter
*
bw
,
const
char
*
k
,
const
char
*
v
)
{
mn
ode
WriteString
(
bw
,
k
);
static
void
mn
d
AddStringField
(
SBufferWriter
*
bw
,
const
char
*
k
,
const
char
*
v
)
{
mn
d
WriteString
(
bw
,
k
);
tbufWriteChar
(
bw
,
':'
);
mn
ode
WriteString
(
bw
,
v
);
mn
d
WriteString
(
bw
,
v
);
tbufWriteChar
(
bw
,
','
);
}
static
void
mn
ode
AddCpuInfo
(
SBufferWriter
*
bw
)
{
static
void
mn
d
AddCpuInfo
(
SBufferWriter
*
bw
)
{
char
*
line
=
NULL
;
size_t
size
=
0
;
int32_t
done
=
0
;
...
...
@@ -100,11 +100,11 @@ static void mnodeAddCpuInfo(SBufferWriter* bw) {
line
[
size
-
1
]
=
'\0'
;
if
(((
done
&
1
)
==
0
)
&&
strncmp
(
line
,
"model name"
,
10
)
==
0
)
{
const
char
*
v
=
strchr
(
line
,
':'
)
+
2
;
mn
ode
AddStringField
(
bw
,
"cpuModel"
,
v
);
mn
d
AddStringField
(
bw
,
"cpuModel"
,
v
);
done
|=
1
;
}
else
if
(((
done
&
2
)
==
0
)
&&
strncmp
(
line
,
"cpu cores"
,
9
)
==
0
)
{
const
char
*
v
=
strchr
(
line
,
':'
)
+
2
;
mn
ode
WriteString
(
bw
,
"numOfCpu"
);
mn
d
WriteString
(
bw
,
"numOfCpu"
);
tbufWriteChar
(
bw
,
':'
);
tbufWrite
(
bw
,
v
,
strlen
(
v
));
tbufWriteChar
(
bw
,
','
);
...
...
@@ -116,7 +116,7 @@ static void mnodeAddCpuInfo(SBufferWriter* bw) {
fclose
(
fp
);
}
static
void
mn
ode
AddOsInfo
(
SBufferWriter
*
bw
)
{
static
void
mn
d
AddOsInfo
(
SBufferWriter
*
bw
)
{
char
*
line
=
NULL
;
size_t
size
=
0
;
...
...
@@ -133,7 +133,7 @@ static void mnodeAddOsInfo(SBufferWriter* bw) {
p
++
;
line
[
size
-
2
]
=
0
;
}
mn
ode
AddStringField
(
bw
,
"os"
,
p
);
mn
d
AddStringField
(
bw
,
"os"
,
p
);
break
;
}
}
...
...
@@ -142,7 +142,7 @@ static void mnodeAddOsInfo(SBufferWriter* bw) {
fclose
(
fp
);
}
static
void
mn
ode
AddMemoryInfo
(
SBufferWriter
*
bw
)
{
static
void
mn
d
AddMemoryInfo
(
SBufferWriter
*
bw
)
{
char
*
line
=
NULL
;
size_t
size
=
0
;
...
...
@@ -156,7 +156,7 @@ static void mnodeAddMemoryInfo(SBufferWriter* bw) {
if
(
strncmp
(
line
,
"MemTotal"
,
8
)
==
0
)
{
const
char
*
p
=
strchr
(
line
,
':'
)
+
1
;
while
(
*
p
==
' '
)
p
++
;
mn
ode
AddStringField
(
bw
,
"memory"
,
p
);
mn
d
AddStringField
(
bw
,
"memory"
,
p
);
break
;
}
}
...
...
@@ -165,32 +165,32 @@ static void mnodeAddMemoryInfo(SBufferWriter* bw) {
fclose
(
fp
);
}
static
void
mn
ode
AddVersionInfo
(
SBufferWriter
*
bw
)
{
mn
ode
AddStringField
(
bw
,
"version"
,
version
);
mn
ode
AddStringField
(
bw
,
"buildInfo"
,
buildinfo
);
mn
ode
AddStringField
(
bw
,
"gitInfo"
,
gitinfo
);
mn
ode
AddStringField
(
bw
,
"email"
,
tsTelem
.
email
);
static
void
mn
d
AddVersionInfo
(
SBufferWriter
*
bw
)
{
mn
d
AddStringField
(
bw
,
"version"
,
version
);
mn
d
AddStringField
(
bw
,
"buildInfo"
,
buildinfo
);
mn
d
AddStringField
(
bw
,
"gitInfo"
,
gitinfo
);
mn
d
AddStringField
(
bw
,
"email"
,
tsTelem
.
email
);
}
static
void
mn
ode
AddRuntimeInfo
(
SBufferWriter
*
bw
)
{
static
void
mn
d
AddRuntimeInfo
(
SBufferWriter
*
bw
)
{
SMnodeLoad
load
=
{
0
};
if
(
mn
ode
GetLoad
(
NULL
,
&
load
)
!=
0
)
{
if
(
mn
d
GetLoad
(
NULL
,
&
load
)
!=
0
)
{
return
;
}
mn
ode
AddIntField
(
bw
,
"numOfDnode"
,
load
.
numOfDnode
);
mn
ode
AddIntField
(
bw
,
"numOfMnode"
,
load
.
numOfMnode
);
mn
ode
AddIntField
(
bw
,
"numOfVgroup"
,
load
.
numOfVgroup
);
mn
ode
AddIntField
(
bw
,
"numOfDatabase"
,
load
.
numOfDatabase
);
mn
ode
AddIntField
(
bw
,
"numOfSuperTable"
,
load
.
numOfSuperTable
);
mn
ode
AddIntField
(
bw
,
"numOfChildTable"
,
load
.
numOfChildTable
);
mn
ode
AddIntField
(
bw
,
"numOfColumn"
,
load
.
numOfColumn
);
mn
ode
AddIntField
(
bw
,
"numOfPoint"
,
load
.
totalPoints
);
mn
ode
AddIntField
(
bw
,
"totalStorage"
,
load
.
totalStorage
);
mn
ode
AddIntField
(
bw
,
"compStorage"
,
load
.
compStorage
);
mn
d
AddIntField
(
bw
,
"numOfDnode"
,
load
.
numOfDnode
);
mn
d
AddIntField
(
bw
,
"numOfMnode"
,
load
.
numOfMnode
);
mn
d
AddIntField
(
bw
,
"numOfVgroup"
,
load
.
numOfVgroup
);
mn
d
AddIntField
(
bw
,
"numOfDatabase"
,
load
.
numOfDatabase
);
mn
d
AddIntField
(
bw
,
"numOfSuperTable"
,
load
.
numOfSuperTable
);
mn
d
AddIntField
(
bw
,
"numOfChildTable"
,
load
.
numOfChildTable
);
mn
d
AddIntField
(
bw
,
"numOfColumn"
,
load
.
numOfColumn
);
mn
d
AddIntField
(
bw
,
"numOfPoint"
,
load
.
totalPoints
);
mn
d
AddIntField
(
bw
,
"totalStorage"
,
load
.
totalStorage
);
mn
d
AddIntField
(
bw
,
"compStorage"
,
load
.
compStorage
);
}
static
void
mn
ode
SendTelemetryReport
()
{
static
void
mn
d
SendTelemetryReport
()
{
char
buf
[
128
]
=
{
0
};
uint32_t
ip
=
taosGetIpv4FromFqdn
(
TELEMETRY_SERVER
);
if
(
ip
==
0xffffffff
)
{
...
...
@@ -203,20 +203,20 @@ static void mnodeSendTelemetryReport() {
return
;
}
int64_t
clusterId
=
mn
odeGetClusterId
(
);
int64_t
clusterId
=
mn
dGetClusterId
(
NULL
);
char
clusterIdStr
[
20
]
=
{
0
};
snprintf
(
clusterIdStr
,
sizeof
(
clusterIdStr
),
"%"
PRId64
,
clusterId
);
SBufferWriter
bw
=
tbufInitWriter
(
NULL
,
false
);
mn
ode
BeginObject
(
&
bw
);
mn
ode
AddStringField
(
&
bw
,
"instanceId"
,
clusterIdStr
);
mn
ode
AddIntField
(
&
bw
,
"reportVersion"
,
1
);
mn
ode
AddOsInfo
(
&
bw
);
mn
ode
AddCpuInfo
(
&
bw
);
mn
ode
AddMemoryInfo
(
&
bw
);
mn
ode
AddVersionInfo
(
&
bw
);
mn
ode
AddRuntimeInfo
(
&
bw
);
mn
ode
CloseObject
(
&
bw
);
mn
d
BeginObject
(
&
bw
);
mn
d
AddStringField
(
&
bw
,
"instanceId"
,
clusterIdStr
);
mn
d
AddIntField
(
&
bw
,
"reportVersion"
,
1
);
mn
d
AddOsInfo
(
&
bw
);
mn
d
AddCpuInfo
(
&
bw
);
mn
d
AddMemoryInfo
(
&
bw
);
mn
d
AddVersionInfo
(
&
bw
);
mn
d
AddRuntimeInfo
(
&
bw
);
mn
d
CloseObject
(
&
bw
);
const
char
*
header
=
"POST /report HTTP/1.1
\n
"
...
...
@@ -240,12 +240,12 @@ static void mnodeSendTelemetryReport() {
taosCloseSocket
(
fd
);
}
static
void
*
mn
ode
TelemThreadFp
(
void
*
param
)
{
static
void
*
mn
d
TelemThreadFp
(
void
*
param
)
{
struct
timespec
end
=
{
0
};
clock_gettime
(
CLOCK_REALTIME
,
&
end
);
end
.
tv_sec
+=
300
;
// wait 5 minutes before send first report
setThreadName
(
"mn
ode
-telem"
);
setThreadName
(
"mn
d
-telem"
);
while
(
!
tsTelem
.
exit
)
{
int32_t
r
=
0
;
...
...
@@ -256,8 +256,8 @@ static void* mnodeTelemThreadFp(void* param) {
if
(
r
==
0
)
break
;
if
(
r
!=
ETIMEDOUT
)
continue
;
if
(
mn
odeIsMaster
(
))
{
mn
ode
SendTelemetryReport
();
if
(
mn
dIsMaster
(
NULL
))
{
mn
d
SendTelemetryReport
();
}
end
.
tv_sec
+=
REPORT_INTERVAL
;
}
...
...
@@ -265,7 +265,7 @@ static void* mnodeTelemThreadFp(void* param) {
return
NULL
;
}
static
void
mn
ode
GetEmail
(
char
*
filepath
)
{
static
void
mn
d
GetEmail
(
char
*
filepath
)
{
int32_t
fd
=
taosOpenFileRead
(
filepath
);
if
(
fd
<
0
)
{
return
;
...
...
@@ -278,7 +278,7 @@ static void mnodeGetEmail(char* filepath) {
taosCloseFile
(
fd
);
}
int32_t
mn
odeInitTelem
(
)
{
int32_t
mn
dInitTelem
(
SMnode
*
pMnode
)
{
tsTelem
.
enable
=
tsEnableTelemetryReporting
;
if
(
!
tsTelem
.
enable
)
return
0
;
...
...
@@ -287,23 +287,23 @@ int32_t mnodeInitTelem() {
pthread_cond_init
(
&
tsTelem
.
cond
,
NULL
);
tsTelem
.
email
[
0
]
=
0
;
mn
ode
GetEmail
(
"/usr/local/taos/email"
);
mn
d
GetEmail
(
"/usr/local/taos/email"
);
pthread_attr_t
attr
;
pthread_attr_init
(
&
attr
);
pthread_attr_setdetachstate
(
&
attr
,
PTHREAD_CREATE_JOINABLE
);
int32_t
code
=
pthread_create
(
&
tsTelem
.
thread
,
&
attr
,
mn
ode
TelemThreadFp
,
NULL
);
int32_t
code
=
pthread_create
(
&
tsTelem
.
thread
,
&
attr
,
mn
d
TelemThreadFp
,
NULL
);
pthread_attr_destroy
(
&
attr
);
if
(
code
!=
0
)
{
mTrace
(
"failed to create telemetry thread since :%s"
,
strerror
(
code
));
}
mInfo
(
"mn
ode
telemetry is initialized"
);
mInfo
(
"mn
d
telemetry is initialized"
);
return
0
;
}
void
mn
odeCleanupTelem
(
)
{
void
mn
dCleanupTelem
(
SMnode
*
pMnode
)
{
if
(
!
tsTelem
.
enable
)
return
;
if
(
taosCheckPthreadValid
(
tsTelem
.
thread
))
{
...
...
source/dnode/mnode/impl/src/mn
ode
Trans.c
→
source/dnode/mnode/impl/src/mn
d
Trans.c
浏览文件 @
81ebcd8b
...
...
@@ -14,13 +14,13 @@
*/
#define _DEFAULT_SOURCE
#include "mn
ode
Trans.h"
#include "mn
d
Trans.h"
#include "trpc.h"
#define SDB_TRANS_VER 1
#define TRN_DEFAULT_ARRAY_SIZE 8
SSdbRaw
*
trn
ActionEncode
(
STrans
*
pTrans
)
{
SSdbRaw
*
mndTrans
ActionEncode
(
STrans
*
pTrans
)
{
int32_t
rawDataLen
=
10
*
sizeof
(
int32_t
);
int32_t
redoLogNum
=
taosArrayGetSize
(
pTrans
->
redoLogs
);
int32_t
undoLogNum
=
taosArrayGetSize
(
pTrans
->
undoLogs
);
...
...
@@ -28,18 +28,18 @@ SSdbRaw *trnActionEncode(STrans *pTrans) {
int32_t
redoActionNum
=
taosArrayGetSize
(
pTrans
->
redoActions
);
int32_t
undoActionNum
=
taosArrayGetSize
(
pTrans
->
undoActions
);
for
(
int32_t
i
ndex
=
0
;
index
<
redoLogNum
;
++
index
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
redoLogs
,
i
ndex
);
for
(
int32_t
i
=
0
;
i
<
redoLogNum
;
++
i
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
redoLogs
,
i
);
rawDataLen
+=
sdbGetRawTotalSize
(
pTmp
);
}
for
(
int32_t
i
ndex
=
0
;
index
<
undoLogNum
;
++
index
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
undoLogs
,
i
ndex
);
for
(
int32_t
i
=
0
;
i
<
undoLogNum
;
++
i
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
undoLogs
,
i
);
rawDataLen
+=
sdbGetRawTotalSize
(
pTmp
);
}
for
(
int32_t
i
ndex
=
0
;
index
<
commitLogNum
;
++
index
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
commitLogs
,
i
ndex
);
for
(
int32_t
i
=
0
;
i
<
commitLogNum
;
++
i
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
commitLogs
,
i
);
rawDataLen
+=
sdbGetRawTotalSize
(
pTmp
);
}
...
...
@@ -59,22 +59,22 @@ SSdbRaw *trnActionEncode(STrans *pTrans) {
SDB_SET_INT32
(
pRaw
,
dataPos
,
redoActionNum
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
undoActionNum
)
for
(
int32_t
i
ndex
=
0
;
index
<
redoLogNum
;
++
index
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
redoLogs
,
i
ndex
);
for
(
int32_t
i
=
0
;
i
<
redoLogNum
;
++
i
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
redoLogs
,
i
);
int32_t
len
=
sdbGetRawTotalSize
(
pTmp
);
SDB_SET_INT32
(
pRaw
,
dataPos
,
len
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
pTmp
,
len
)
}
for
(
int32_t
i
ndex
=
0
;
index
<
undoLogNum
;
++
index
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
undoLogs
,
i
ndex
);
for
(
int32_t
i
=
0
;
i
<
undoLogNum
;
++
i
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
undoLogs
,
i
);
int32_t
len
=
sdbGetRawTotalSize
(
pTmp
);
SDB_SET_INT32
(
pRaw
,
dataPos
,
len
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
pTmp
,
len
)
}
for
(
int32_t
i
ndex
=
0
;
index
<
commitLogNum
;
++
index
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
commitLogs
,
i
ndex
);
for
(
int32_t
i
=
0
;
i
<
commitLogNum
;
++
i
)
{
SSdbRaw
*
pTmp
=
taosArrayGet
(
pTrans
->
commitLogs
,
i
);
int32_t
len
=
sdbGetRawTotalSize
(
pTmp
);
SDB_SET_INT32
(
pRaw
,
dataPos
,
len
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
(
void
*
)
pTmp
,
len
)
...
...
@@ -84,7 +84,7 @@ SSdbRaw *trnActionEncode(STrans *pTrans) {
return
pRaw
;
}
SSdbRow
*
trn
ActionDecode
(
SSdbRaw
*
pRaw
)
{
SSdbRow
*
mndTrans
ActionDecode
(
SSdbRaw
*
pRaw
)
{
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
{
mError
(
"failed to get soft ver from raw:%p since %s"
,
pRaw
,
terrstr
());
...
...
@@ -134,7 +134,7 @@ SSdbRow *trnActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
undoActionNum
)
int32_t
code
=
0
;
for
(
int32_t
i
ndex
=
0
;
index
<
redoLogNum
;
++
index
)
{
for
(
int32_t
i
=
0
;
i
<
redoLogNum
;
++
i
)
{
int32_t
dataLen
=
0
;
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
dataLen
)
...
...
@@ -150,7 +150,7 @@ SSdbRow *trnActionDecode(SSdbRaw *pRaw) {
if
(
code
!=
0
)
{
terrno
=
code
;
mError
(
"trn:%d, failed to parse from raw:%p since %s"
,
pTrans
->
id
,
pRaw
,
terrstr
());
trn
Drop
(
pTrans
);
mndTrans
Drop
(
pTrans
);
return
NULL
;
}
...
...
@@ -158,13 +158,13 @@ SSdbRow *trnActionDecode(SSdbRaw *pRaw) {
return
pRow
;
}
static
int32_t
trnActionInsert
(
STrans
*
pTrans
)
{
static
int32_t
mndTransActionInsert
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
SArray
*
pArray
=
pTrans
->
redoLogs
;
int32_t
arraySize
=
taosArrayGetSize
(
pArray
);
for
(
int32_t
i
ndex
=
0
;
index
<
arraySize
;
++
index
)
{
SSdbRaw
*
pRaw
=
taosArrayGet
(
pArray
,
i
ndex
);
int32_t
code
=
sdbWrite
(
pRaw
);
for
(
int32_t
i
=
0
;
i
<
arraySize
;
++
i
)
{
SSdbRaw
*
pRaw
=
taosArrayGet
(
pArray
,
i
);
int32_t
code
=
sdbWrite
(
p
Sdb
,
p
Raw
);
if
(
code
!=
0
)
{
mError
(
"trn:%d, failed to write raw:%p to sdb since %s"
,
pTrans
->
id
,
pRaw
,
terrstr
());
return
code
;
...
...
@@ -175,13 +175,13 @@ static int32_t trnActionInsert(STrans *pTrans) {
return
0
;
}
static
int32_t
trnActionDelete
(
STrans
*
pTrans
)
{
static
int32_t
mndTransActionDelete
(
SSdb
*
pSdb
,
STrans
*
pTrans
)
{
SArray
*
pArray
=
pTrans
->
redoLogs
;
int32_t
arraySize
=
taosArrayGetSize
(
pArray
);
for
(
int32_t
i
ndex
=
0
;
index
<
arraySize
;
++
index
)
{
SSdbRaw
*
pRaw
=
taosArrayGet
(
pArray
,
i
ndex
);
int32_t
code
=
sdbWrite
(
pRaw
);
for
(
int32_t
i
=
0
;
i
<
arraySize
;
++
i
)
{
SSdbRaw
*
pRaw
=
taosArrayGet
(
pArray
,
i
);
int32_t
code
=
sdbWrite
(
p
Sdb
,
p
Raw
);
if
(
code
!=
0
)
{
mError
(
"trn:%d, failed to write raw:%p to sdb since %s"
,
pTrans
->
id
,
pRaw
,
terrstr
());
return
code
;
...
...
@@ -192,14 +192,14 @@ static int32_t trnActionDelete(STrans *pTrans) {
return
0
;
}
static
int32_t
trnActionUpdate
(
STrans
*
pTrans
,
STrans
*
pDstTrans
)
{
static
int32_t
mndTransActionUpdate
(
SSdb
*
pSdb
,
STrans
*
pTrans
,
STrans
*
pDstTrans
)
{
assert
(
true
);
SArray
*
pArray
=
pTrans
->
redoLogs
;
int32_t
arraySize
=
taosArrayGetSize
(
pArray
);
for
(
int32_t
i
ndex
=
0
;
index
<
arraySize
;
++
index
)
{
SSdbRaw
*
pRaw
=
taosArrayGet
(
pArray
,
i
ndex
);
int32_t
code
=
sdbWrite
(
pRaw
);
for
(
int32_t
i
=
0
;
i
<
arraySize
;
++
i
)
{
SSdbRaw
*
pRaw
=
taosArrayGet
(
pArray
,
i
);
int32_t
code
=
sdbWrite
(
p
Sdb
,
p
Raw
);
if
(
code
!=
0
)
{
mError
(
"trn:%d, failed to write raw:%p to sdb since %s"
,
pTrans
->
id
,
pRaw
,
terrstr
());
return
code
;
...
...
@@ -213,7 +213,7 @@ static int32_t trnActionUpdate(STrans *pTrans, STrans *pDstTrans) {
static
int32_t
trnGenerateTransId
()
{
return
1
;
}
STrans
*
trnCreate
(
ETrnPolicy
policy
,
void
*
rpcHandle
)
{
STrans
*
mndTransCreate
(
SMnode
*
pMnode
,
ETrnPolicy
policy
,
void
*
rpcHandle
)
{
STrans
*
pTrans
=
calloc
(
1
,
sizeof
(
STrans
));
if
(
pTrans
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -243,15 +243,15 @@ STrans *trnCreate(ETrnPolicy policy, void *rpcHandle) {
}
static
void
trnDropArray
(
SArray
*
pArray
)
{
for
(
int32_t
i
ndex
=
0
;
index
<
pArray
->
size
;
++
index
)
{
SSdbRaw
*
pRaw
=
taosArrayGet
(
pArray
,
i
ndex
);
for
(
int32_t
i
=
0
;
i
<
pArray
->
size
;
++
i
)
{
SSdbRaw
*
pRaw
=
taosArrayGet
(
pArray
,
i
);
tfree
(
pRaw
);
}
taosArrayDestroy
(
pArray
);
}
void
trn
Drop
(
STrans
*
pTrans
)
{
void
mndTrans
Drop
(
STrans
*
pTrans
)
{
trnDropArray
(
pTrans
->
redoLogs
);
trnDropArray
(
pTrans
->
undoLogs
);
trnDropArray
(
pTrans
->
commitLogs
);
...
...
@@ -262,12 +262,12 @@ void trnDrop(STrans *pTrans) {
tfree
(
pTrans
);
}
void
trn
SetRpcHandle
(
STrans
*
pTrans
,
void
*
rpcHandle
)
{
void
mndTrans
SetRpcHandle
(
STrans
*
pTrans
,
void
*
rpcHandle
)
{
pTrans
->
rpcHandle
=
rpcHandle
;
mTrace
(
"trn:%d, set rpc handle:%p"
,
pTrans
->
id
,
rpcHandle
);
}
static
int32_t
trn
AppendArray
(
SArray
*
pArray
,
SSdbRaw
*
pRaw
)
{
static
int32_t
mndTrans
AppendArray
(
SArray
*
pArray
,
SSdbRaw
*
pRaw
)
{
if
(
pArray
==
NULL
||
pRaw
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
...
...
@@ -282,64 +282,61 @@ static int32_t trnAppendArray(SArray *pArray, SSdbRaw *pRaw) {
return
0
;
}
int32_t
trnAppendRedoL
og
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
)
{
int32_t
code
=
trn
AppendArray
(
pTrans
->
redoLogs
,
pRaw
);
int32_t
mndTransAppendRedol
og
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
)
{
int32_t
code
=
mndTrans
AppendArray
(
pTrans
->
redoLogs
,
pRaw
);
mTrace
(
"trn:%d, raw:%p append to redo logs, code:%d"
,
pTrans
->
id
,
pRaw
,
code
);
return
code
;
}
int32_t
trnAppendUndoL
og
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
)
{
int32_t
code
=
trn
AppendArray
(
pTrans
->
undoLogs
,
pRaw
);
int32_t
mndTransAppendUndol
og
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
)
{
int32_t
code
=
mndTrans
AppendArray
(
pTrans
->
undoLogs
,
pRaw
);
mTrace
(
"trn:%d, raw:%p append to undo logs, code:%d"
,
pTrans
->
id
,
pRaw
,
code
);
return
code
;
}
int32_t
trnAppendCommitL
og
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
)
{
int32_t
code
=
trn
AppendArray
(
pTrans
->
commitLogs
,
pRaw
);
int32_t
mndTransAppendCommitl
og
(
STrans
*
pTrans
,
SSdbRaw
*
pRaw
)
{
int32_t
code
=
mndTrans
AppendArray
(
pTrans
->
commitLogs
,
pRaw
);
mTrace
(
"trn:%d, raw:%p append to commit logs, code:%d"
,
pTrans
->
id
,
pRaw
,
code
);
return
code
;
}
int32_t
trn
AppendRedoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
void
*
pMsg
)
{
int32_t
code
=
trn
AppendArray
(
pTrans
->
redoActions
,
pMsg
);
int32_t
mndTrans
AppendRedoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
void
*
pMsg
)
{
int32_t
code
=
mndTrans
AppendArray
(
pTrans
->
redoActions
,
pMsg
);
mTrace
(
"trn:%d, msg:%p append to redo actions"
,
pTrans
->
id
,
pMsg
);
return
code
;
}
int32_t
trn
AppendUndoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
void
*
pMsg
)
{
int32_t
code
=
trn
AppendArray
(
pTrans
->
undoActions
,
pMsg
);
int32_t
mndTrans
AppendUndoAction
(
STrans
*
pTrans
,
SEpSet
*
pEpSet
,
void
*
pMsg
)
{
int32_t
code
=
mndTrans
AppendArray
(
pTrans
->
undoActions
,
pMsg
);
mTrace
(
"trn:%d, msg:%p append to undo actions"
,
pTrans
->
id
,
pMsg
);
return
code
;
}
int32_t
mn
odeInitTrans
(
)
{
int32_t
mn
dInitTrans
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_TRANS
,
.
keyType
=
SDB_KEY_INT32
,
.
encodeFp
=
(
SdbEncodeFp
)
trnActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
trnActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
trnActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
trnActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
trnActionDelete
};
sdbSetTable
(
table
);
mInfo
(
"trn module is initialized"
);
return
0
;
}
.
encodeFp
=
(
SdbEncodeFp
)
mndTransActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndTransActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndTransActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndTransActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndTransActionDelete
};
void
mnodeCleanupTrans
()
{
mInfo
(
"trn module is cleaned up"
);
}
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupTrans
(
SMnode
*
pMnode
)
{}
int32_t
trn
Prepare
(
STrans
*
pTrans
,
int32_t
(
*
syncfp
)(
SSdbRaw
*
pRaw
,
void
*
pData
))
{
int32_t
mndTrans
Prepare
(
STrans
*
pTrans
,
int32_t
(
*
syncfp
)(
SSdbRaw
*
pRaw
,
void
*
pData
))
{
if
(
syncfp
==
NULL
)
return
-
1
;
SSdbRaw
*
pRaw
=
trn
ActionEncode
(
pTrans
);
SSdbRaw
*
pRaw
=
mndTrans
ActionEncode
(
pTrans
);
if
(
pRaw
==
NULL
)
{
mError
(
"trn:%d, failed to decode trans since %s"
,
pTrans
->
id
,
terrstr
());
return
-
1
;
}
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_CREATING
);
if
(
sdbWrite
(
pRaw
)
!=
0
)
{
if
(
sdbWrite
(
p
Trans
->
pMnode
->
pSdb
,
p
Raw
)
!=
0
)
{
mError
(
"trn:%d, failed to write trans since %s"
,
pTrans
->
id
,
terrstr
());
return
-
1
;
}
...
...
@@ -359,13 +356,13 @@ static void trnSendRpcRsp(void *rpcHandle, int32_t code) {
}
}
int32_t
trnApply
(
SSdbRaw
*
pRaw
,
void
*
pData
,
int32_t
code
)
{
int32_t
mndTransApply
(
SMnode
*
pMnode
,
SSdbRaw
*
pRaw
,
void
*
pData
,
int32_t
code
)
{
if
(
code
!=
0
)
{
trnSendRpcRsp
(
pData
,
terrno
);
return
0
;
}
if
(
sdbWrite
(
pData
)
!=
0
)
{
if
(
sdbWrite
(
p
Mnode
->
pSdb
,
p
Data
)
!=
0
)
{
code
=
terrno
;
trnSendRpcRsp
(
pData
,
code
);
terrno
=
code
;
...
...
@@ -375,10 +372,10 @@ int32_t trnApply(SSdbRaw *pRaw, void *pData, int32_t code) {
return
0
;
}
static
int32_t
trnExecuteArray
(
SArray
*
pArray
)
{
for
(
int32_t
i
ndex
=
0
;
index
<
pArray
->
size
;
++
index
)
{
SSdbRaw
*
pRaw
=
taosArrayGetP
(
pArray
,
i
ndex
);
if
(
sdbWrite
(
pRaw
)
!=
0
)
{
static
int32_t
trnExecuteArray
(
S
Mnode
*
pMnode
,
S
Array
*
pArray
)
{
for
(
int32_t
i
=
0
;
i
<
pArray
->
size
;
++
i
)
{
SSdbRaw
*
pRaw
=
taosArrayGetP
(
pArray
,
i
);
if
(
sdbWrite
(
p
Mnode
->
pSdb
,
p
Raw
)
!=
0
)
{
return
-
1
;
}
}
...
...
@@ -386,15 +383,15 @@ static int32_t trnExecuteArray(SArray *pArray) {
return
0
;
}
static
int32_t
trnExecuteRedoLogs
(
STrans
*
pTrans
)
{
return
trnExecuteArray
(
pTrans
->
redoLogs
);
}
static
int32_t
trnExecuteRedoLogs
(
STrans
*
pTrans
)
{
return
trnExecuteArray
(
pTrans
->
pMnode
,
pTrans
->
redoLogs
);
}
static
int32_t
trnExecuteUndoLogs
(
STrans
*
pTrans
)
{
return
trnExecuteArray
(
pTrans
->
undoLogs
);
}
static
int32_t
trnExecuteUndoLogs
(
STrans
*
pTrans
)
{
return
trnExecuteArray
(
pTrans
->
pMnode
,
pTrans
->
undoLogs
);
}
static
int32_t
trnExecuteCommitLogs
(
STrans
*
pTrans
)
{
return
trnExecuteArray
(
pTrans
->
commitLogs
);
}
static
int32_t
trnExecuteCommitLogs
(
STrans
*
pTrans
)
{
return
trnExecuteArray
(
pTrans
->
pMnode
,
pTrans
->
commitLogs
);
}
static
int32_t
trnExecuteRedoActions
(
STrans
*
pTrans
)
{
return
trnExecuteArray
(
pTrans
->
redoActions
);
}
static
int32_t
trnExecuteRedoActions
(
STrans
*
pTrans
)
{
return
trnExecuteArray
(
pTrans
->
pMnode
,
pTrans
->
redoActions
);
}
static
int32_t
trnExecuteUndoActions
(
STrans
*
pTrans
)
{
return
trnExecuteArray
(
pTrans
->
undoActions
);
}
static
int32_t
trnExecuteUndoActions
(
STrans
*
pTrans
)
{
return
trnExecuteArray
(
pTrans
->
pMnode
,
pTrans
->
undoActions
);
}
static
int32_t
trnPerformPrepareStage
(
STrans
*
pTrans
)
{
if
(
trnExecuteRedoLogs
(
pTrans
)
==
0
)
{
...
...
@@ -454,49 +451,49 @@ static int32_t trnPerformRetryStage(STrans *pTrans) {
}
}
int32_t
trnExecute
(
int32_t
tranId
)
{
int32_t
mndTransExecute
(
SSdb
*
pSdb
,
int32_t
tranId
)
{
int32_t
code
=
0
;
STrans
*
pTrans
=
sdbAcquire
(
SDB_TRANS
,
&
tranId
);
STrans
*
pTrans
=
sdbAcquire
(
pSdb
,
SDB_TRANS
,
&
tranId
);
if
(
pTrans
==
NULL
)
{
return
-
1
;
}
if
(
pTrans
->
stage
==
TRN_STAGE_PREPARE
)
{
if
(
trnPerformPrepareStage
(
pTrans
)
!=
0
)
{
sdbRelease
(
pTrans
);
sdbRelease
(
p
Sdb
,
p
Trans
);
return
-
1
;
}
}
if
(
pTrans
->
stage
==
TRN_STAGE_EXECUTE
)
{
if
(
trnPerformExecuteStage
(
pTrans
)
!=
0
)
{
sdbRelease
(
pTrans
);
sdbRelease
(
p
Sdb
,
p
Trans
);
return
-
1
;
}
}
if
(
pTrans
->
stage
==
TRN_STAGE_COMMIT
)
{
if
(
trnPerformCommitStage
(
pTrans
)
!=
0
)
{
sdbRelease
(
pTrans
);
sdbRelease
(
p
Sdb
,
p
Trans
);
return
-
1
;
}
}
if
(
pTrans
->
stage
==
TRN_STAGE_ROLLBACK
)
{
if
(
trnPerformRollbackStage
(
pTrans
)
!=
0
)
{
sdbRelease
(
pTrans
);
sdbRelease
(
p
Sdb
,
p
Trans
);
return
-
1
;
}
}
if
(
pTrans
->
stage
==
TRN_STAGE_RETRY
)
{
if
(
trnPerformRetryStage
(
pTrans
)
!=
0
)
{
sdbRelease
(
pTrans
);
sdbRelease
(
p
Sdb
,
p
Trans
);
return
-
1
;
}
}
sdbRelease
(
pTrans
);
sdbRelease
(
p
Sdb
,
p
Trans
);
return
0
;
}
\ No newline at end of file
source/dnode/mnode/impl/src/mn
ode
User.c
→
source/dnode/mnode/impl/src/mn
d
User.c
浏览文件 @
81ebcd8b
...
...
@@ -14,15 +14,13 @@
*/
#define _DEFAULT_SOURCE
#include "mnodeSync.h"
#include "os.h"
#include "tglobal.h"
#include "mndSync.h"
#include "tkey.h"
#include "mn
ode
Trans.h"
#include "mn
d
Trans.h"
#define SDB_USER_VER 1
static
SSdbRaw
*
mn
ode
UserActionEncode
(
SUserObj
*
pUser
)
{
static
SSdbRaw
*
mn
d
UserActionEncode
(
SUserObj
*
pUser
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_USER
,
SDB_USER_VER
,
sizeof
(
SAcctObj
));
if
(
pRaw
==
NULL
)
return
NULL
;
...
...
@@ -38,7 +36,7 @@ static SSdbRaw *mnodeUserActionEncode(SUserObj *pUser) {
return
pRaw
;
}
static
SSdbRow
*
mn
ode
UserActionDecode
(
SSdbRaw
*
pRaw
)
{
static
SSdbRow
*
mn
d
UserActionDecode
(
SSdbRaw
*
pRaw
)
{
int8_t
sver
=
0
;
if
(
sdbGetRawSoftVer
(
pRaw
,
&
sver
)
!=
0
)
return
NULL
;
...
...
@@ -62,14 +60,14 @@ static SSdbRow *mnodeUserActionDecode(SSdbRaw *pRaw) {
return
pRow
;
}
static
int32_t
mn
odeUserActionInsert
(
SUserObj
*
pUser
)
{
static
int32_t
mn
dUserActionInsert
(
SSdb
*
pSdb
,
SUserObj
*
pUser
)
{
pUser
->
prohibitDbHash
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_ENTRY_LOCK
);
if
(
pUser
->
prohibitDbHash
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pUser
->
pAcct
=
sdbAcquire
(
SDB_ACCT
,
pUser
->
acct
);
pUser
->
pAcct
=
sdbAcquire
(
pSdb
,
SDB_ACCT
,
pUser
->
acct
);
if
(
pUser
->
pAcct
==
NULL
)
{
terrno
=
TSDB_CODE_MND_ACCT_NOT_EXIST
;
return
-
1
;
...
...
@@ -78,28 +76,28 @@ static int32_t mnodeUserActionInsert(SUserObj *pUser) {
return
0
;
}
static
int32_t
mn
odeUserActionDelete
(
SUserObj
*
pUser
)
{
static
int32_t
mn
dUserActionDelete
(
SSdb
*
pSdb
,
SUserObj
*
pUser
)
{
if
(
pUser
->
prohibitDbHash
)
{
taosHashCleanup
(
pUser
->
prohibitDbHash
);
pUser
->
prohibitDbHash
=
NULL
;
}
if
(
pUser
->
acct
!=
NULL
)
{
sdbRelease
(
pUser
->
pAcct
);
sdbRelease
(
p
Sdb
,
p
User
->
pAcct
);
pUser
->
pAcct
=
NULL
;
}
return
0
;
}
static
int32_t
mn
odeUserActionUpdate
(
SUserObj
*
pSrcUser
,
SUserObj
*
pDstUser
)
{
static
int32_t
mn
dUserActionUpdate
(
SSdb
*
pSdb
,
SUserObj
*
pSrcUser
,
SUserObj
*
pDstUser
)
{
SUserObj
tObj
;
int32_t
len
=
(
int32_t
)((
int8_t
*
)
tObj
.
prohibitDbHash
-
(
int8_t
*
)
&
tObj
);
memcpy
(
pDstUser
,
pSrcUser
,
len
);
return
0
;
}
static
int32_t
mn
odeCreateDefaultUser
(
char
*
acct
,
char
*
user
,
char
*
pass
)
{
static
int32_t
mn
dCreateDefaultUser
(
SSdb
*
pSdb
,
char
*
acct
,
char
*
user
,
char
*
pass
)
{
SUserObj
userObj
=
{
0
};
tstrncpy
(
userObj
.
user
,
user
,
TSDB_USER_LEN
);
tstrncpy
(
userObj
.
acct
,
acct
,
TSDB_USER_LEN
);
...
...
@@ -111,30 +109,26 @@ static int32_t mnodeCreateDefaultUser(char *acct, char *user, char *pass) {
userObj
.
rootAuth
=
1
;
}
SSdbRaw
*
pRaw
=
mn
ode
UserActionEncode
(
&
userObj
);
SSdbRaw
*
pRaw
=
mn
d
UserActionEncode
(
&
userObj
);
if
(
pRaw
==
NULL
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
return
sdbWrite
(
pRaw
);
return
sdbWrite
(
p
Sdb
,
p
Raw
);
}
static
int32_t
mn
odeCreateDefaultUsers
(
)
{
if
(
mn
odeCreateDefaultUser
(
TSDB_DEFAULT_USER
,
TSDB_DEFAULT_USER
,
TSDB_DEFAULT_PASS
)
!=
0
)
{
static
int32_t
mn
dCreateDefaultUsers
(
SSdb
*
pSdb
)
{
if
(
mn
dCreateDefaultUser
(
pSdb
,
TSDB_DEFAULT_USER
,
TSDB_DEFAULT_USER
,
TSDB_DEFAULT_PASS
)
!=
0
)
{
return
-
1
;
}
if
(
mnodeCreateDefaultUser
(
TSDB_DEFAULT_USER
,
"monitor"
,
tsInternalPass
)
!=
0
)
{
return
-
1
;
}
if
(
mnodeCreateDefaultUser
(
TSDB_DEFAULT_USER
,
"_"
TSDB_DEFAULT_USER
,
tsInternalPass
)
!=
0
)
{
if
(
mndCreateDefaultUser
(
pSdb
,
TSDB_DEFAULT_USER
,
"_"
TSDB_DEFAULT_USER
,
TSDB_DEFAULT_PASS
)
!=
0
)
{
return
-
1
;
}
return
0
;
}
static
int32_t
mn
odeCreateUser
(
char
*
acct
,
char
*
user
,
char
*
pass
,
SMnodeMsg
*
pMsg
)
{
static
int32_t
mn
dCreateUser
(
SMnode
*
pMnode
,
char
*
acct
,
char
*
user
,
char
*
pass
,
SMnodeMsg
*
pMsg
)
{
SUserObj
userObj
=
{
0
};
tstrncpy
(
userObj
.
user
,
user
,
TSDB_USER_LEN
);
tstrncpy
(
userObj
.
acct
,
acct
,
TSDB_USER_LEN
);
...
...
@@ -143,43 +137,43 @@ static int32_t mnodeCreateUser(char *acct, char *user, char *pass, SMnodeMsg *pM
userObj
.
updateTime
=
userObj
.
createdTime
;
userObj
.
rootAuth
=
0
;
STrans
*
pTrans
=
trnCreate
(
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
STrans
*
pTrans
=
mndTransCreate
(
pMnode
,
TRN_POLICY_ROLLBACK
,
pMsg
->
rpcMsg
.
handle
);
if
(
pTrans
==
NULL
)
return
-
1
;
SSdbRaw
*
pRedoRaw
=
mn
ode
UserActionEncode
(
&
userObj
);
if
(
pRedoRaw
==
NULL
||
trnAppendRedoL
og
(
pTrans
,
pRedoRaw
)
!=
0
)
{
SSdbRaw
*
pRedoRaw
=
mn
d
UserActionEncode
(
&
userObj
);
if
(
pRedoRaw
==
NULL
||
mndTransAppendRedol
og
(
pTrans
,
pRedoRaw
)
!=
0
)
{
mError
(
"failed to append redo log since %s"
,
terrstr
());
trn
Drop
(
pTrans
);
mndTrans
Drop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pRedoRaw
,
SDB_STATUS_CREATING
);
SSdbRaw
*
pUndoRaw
=
mn
ode
UserActionEncode
(
&
userObj
);
if
(
pUndoRaw
==
NULL
||
trnAppendUndoL
og
(
pTrans
,
pUndoRaw
)
!=
0
)
{
SSdbRaw
*
pUndoRaw
=
mn
d
UserActionEncode
(
&
userObj
);
if
(
pUndoRaw
==
NULL
||
mndTransAppendUndol
og
(
pTrans
,
pUndoRaw
)
!=
0
)
{
mError
(
"failed to append undo log since %s"
,
terrstr
());
trn
Drop
(
pTrans
);
mndTrans
Drop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pUndoRaw
,
SDB_STATUS_DROPPED
);
SSdbRaw
*
pCommitRaw
=
mn
ode
UserActionEncode
(
&
userObj
);
if
(
pCommitRaw
==
NULL
||
trnAppendCommitL
og
(
pTrans
,
pCommitRaw
)
!=
0
)
{
SSdbRaw
*
pCommitRaw
=
mn
d
UserActionEncode
(
&
userObj
);
if
(
pCommitRaw
==
NULL
||
mndTransAppendCommitl
og
(
pTrans
,
pCommitRaw
)
!=
0
)
{
mError
(
"failed to append commit log since %s"
,
terrstr
());
trn
Drop
(
pTrans
);
mndTrans
Drop
(
pTrans
);
return
-
1
;
}
sdbSetRawStatus
(
pCommitRaw
,
SDB_STATUS_READY
);
if
(
trnPrepare
(
pTrans
,
mnode
SyncPropose
)
!=
0
)
{
trn
Drop
(
pTrans
);
if
(
mndTransPrepare
(
pTrans
,
mnd
SyncPropose
)
!=
0
)
{
mndTrans
Drop
(
pTrans
);
return
-
1
;
}
trn
Drop
(
pTrans
);
mndTrans
Drop
(
pTrans
);
return
0
;
}
static
int32_t
mn
odeProcessCreateUserMsg
(
SMnodeMsg
*
pMsg
)
{
static
int32_t
mn
dProcessCreateUserMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{
SCreateUserMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
if
(
pCreate
->
user
[
0
]
==
0
)
{
...
...
@@ -194,23 +188,23 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
return
-
1
;
}
SUserObj
*
pUser
=
sdbAcquire
(
SDB_USER
,
pCreate
->
user
);
SUserObj
*
pUser
=
sdbAcquire
(
pMnode
->
pSdb
,
SDB_USER
,
pCreate
->
user
);
if
(
pUser
!=
NULL
)
{
sdbRelease
(
pUser
);
sdbRelease
(
p
Mnode
->
pSdb
,
p
User
);
terrno
=
TSDB_CODE_MND_USER_ALREADY_EXIST
;
mError
(
"user:%s, failed to create since %s"
,
pCreate
->
user
,
terrstr
());
return
-
1
;
}
SUserObj
*
pOperUser
=
sdbAcquire
(
SDB_USER
,
pMsg
->
conn
.
user
);
SUserObj
*
pOperUser
=
sdbAcquire
(
pMnode
->
pSdb
,
SDB_USER
,
pMsg
->
conn
.
user
);
if
(
pOperUser
==
NULL
)
{
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
mError
(
"user:%s, failed to create since %s"
,
pCreate
->
user
,
terrstr
());
return
-
1
;
}
int32_t
code
=
mn
odeCreateUser
(
pOperUser
->
acct
,
pCreate
->
user
,
pCreate
->
pass
,
pMsg
);
sdbRelease
(
pOperUser
);
int32_t
code
=
mn
dCreateUser
(
pMnode
,
pOperUser
->
acct
,
pCreate
->
user
,
pCreate
->
pass
,
pMsg
);
sdbRelease
(
p
Mnode
->
pSdb
,
p
OperUser
);
if
(
code
!=
0
)
{
mError
(
"user:%s, failed to create since %s"
,
pCreate
->
user
,
terrstr
());
...
...
@@ -220,20 +214,19 @@ static int32_t mnodeProcessCreateUserMsg(SMnodeMsg *pMsg) {
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
int32_t
mn
odeInitUser
(
)
{
int32_t
mn
dInitUser
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_USER
,
.
keyType
=
SDB_KEY_BINARY
,
.
deployFp
=
(
SdbDeployFp
)
mnodeCreateDefaultUsers
,
.
encodeFp
=
(
SdbEncodeFp
)
mnodeUserActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mnodeUserActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mnodeUserActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mnodeUserActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mnodeUserActionDelete
};
sdbSetTable
(
table
);
.
deployFp
=
(
SdbDeployFp
)
mndCreateDefaultUsers
,
.
encodeFp
=
(
SdbEncodeFp
)
mndUserActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndUserActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndUserActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndUserActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndUserActionDelete
};
mn
odeSetMsgFp
(
TSDB_MSG_TYPE_CREATE_USER
,
mnode
ProcessCreateUserMsg
);
mn
dSetMsgHandle
(
pMnode
,
TSDB_MSG_TYPE_CREATE_USER
,
mnd
ProcessCreateUserMsg
);
return
0
;
return
sdbSetTable
(
pMnode
->
pSdb
,
table
)
;
}
void
mnodeCleanupUser
()
{}
\ No newline at end of file
void
mndCleanupUser
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mndVgroup.c
0 → 100644
浏览文件 @
81ebcd8b
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mndInt.h"
int32_t
mndInitVgroup
(
SMnode
*
pMnode
)
{
return
0
;
}
void
mndCleanupVgroup
(
SMnode
*
pMnode
)
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mnode.c
浏览文件 @
81ebcd8b
...
...
@@ -14,172 +14,324 @@
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "tglobal.h"
#include "tqueue.h"
#include "mnodeAcct.h"
#include "mnodeAuth.h"
#include "mnodeBalance.h"
#include "mnodeCluster.h"
#include "mnodeDb.h"
#include "mnodeDnode.h"
#include "mnodeFunc.h"
#include "mnodeMnode.h"
#include "mnodeOper.h"
#include "mnodeProfile.h"
#include "mnodeShow.h"
#include "mnodeStable.h"
#include "mnodeSync.h"
#include "mnodeTelem.h"
#include "mnodeTrans.h"
#include "mnodeUser.h"
#include "mnodeVgroup.h"
SMnodeBak
tsMint
=
{
0
};
int32_t
mnodeGetDnodeId
()
{
return
tsMint
.
para
.
dnodeId
;
}
int64_t
mnodeGetClusterId
()
{
return
tsMint
.
para
.
clusterId
;
}
void
mnodeSendMsgToDnode
(
SMnode
*
pMnode
,
struct
SEpSet
*
epSet
,
struct
SRpcMsg
*
rpcMsg
)
{
assert
(
pMnode
);
(
*
pMnode
->
sendMsgToDnodeFp
)(
pMnode
->
pServer
,
epSet
,
rpcMsg
);
#include "mndAcct.h"
#include "mndAuth.h"
#include "mndBalance.h"
#include "mndCluster.h"
#include "mndDb.h"
#include "mndDnode.h"
#include "mndFunc.h"
#include "mndMnode.h"
#include "mndOper.h"
#include "mndProfile.h"
#include "mndShow.h"
#include "mndStable.h"
#include "mndSync.h"
#include "mndTelem.h"
#include "mndTrans.h"
#include "mndUser.h"
#include "mndVgroup.h"
int32_t
mndGetDnodeId
(
SMnode
*
pMnode
)
{
if
(
pMnode
!=
NULL
)
{
return
pMnode
->
dnodeId
;
}
return
-
1
;
}
int64_t
mndGetClusterId
(
SMnode
*
pMnode
)
{
if
(
pMnode
!=
NULL
)
{
return
pMnode
->
clusterId
;
}
return
-
1
;
}
tmr_h
mndGetTimer
(
SMnode
*
pMnode
)
{
if
(
pMnode
!=
NULL
)
{
return
pMnode
->
timer
;
}
return
NULL
;
}
void
mnodeSendMsgToMnode
(
SMnode
*
pMnode
,
struct
SRpcMsg
*
rpcMsg
)
{
assert
(
pMnode
);
(
*
pMnode
->
sendMsgToMnodeFp
)(
pMnode
->
pServer
,
rpcMsg
);
void
mndSendMsgToDnode
(
SMnode
*
pMnode
,
SEpSet
*
pEpSet
,
SRpcMsg
*
pMsg
)
{
if
(
pMnode
!=
NULL
&&
pMnode
->
sendMsgToDnodeFp
!=
NULL
)
{
(
*
pMnode
->
sendMsgToDnodeFp
)(
pMnode
->
pDnode
,
pEpSet
,
pMsg
);
}
}
void
mnodeSendRedirectMsg
(
SMnode
*
pMnode
,
struct
SRpcMsg
*
rpcMsg
,
bool
forShell
)
{
assert
(
pMnode
);
(
*
pMnode
->
sendRedirectMsgFp
)(
pMnode
->
pServer
,
rpcMsg
);
void
mndSendMsgToMnode
(
SMnode
*
pMnode
,
SRpcMsg
*
pMsg
)
{
if
(
pMnode
!=
NULL
&&
pMnode
->
sendMsgToMnodeFp
!=
NULL
)
{
(
*
pMnode
->
sendMsgToMnodeFp
)(
pMnode
->
pDnode
,
pMsg
);
}
}
void
mndSendRedirectMsg
(
SMnode
*
pMnode
,
SRpcMsg
*
pMsg
)
{
if
(
pMnode
!=
NULL
&&
pMnode
->
sendRedirectMsgFp
!=
NULL
)
{
(
*
pMnode
->
sendRedirectMsgFp
)(
pMnode
->
pDnode
,
pMsg
);
}
}
static
int32_t
mn
odeInitTimer
(
)
{
if
(
tsMint
.
timer
==
NULL
)
{
tsMint
.
timer
=
taosTmrInit
(
tsMaxShellConns
,
200
,
3600000
,
"MND"
);
static
int32_t
mn
dInitTimer
(
SMnode
*
pMnode
)
{
if
(
pMnode
->
timer
==
NULL
)
{
pMnode
->
timer
=
taosTmrInit
(
5000
,
200
,
3600000
,
"MND"
);
}
if
(
tsMint
.
timer
==
NULL
)
{
if
(
pMnode
->
timer
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
return
0
;
}
static
void
mn
odeCleanupTimer
(
)
{
if
(
tsMint
.
timer
!=
NULL
)
{
taosTmrCleanUp
(
tsMint
.
timer
);
tsMint
.
timer
=
NULL
;
static
void
mn
dCleanupTimer
(
SMnode
*
pMnode
)
{
if
(
pMnode
->
timer
!=
NULL
)
{
taosTmrCleanUp
(
pMnode
->
timer
);
pMnode
->
timer
=
NULL
;
}
}
tmr_h
mnodeGetTimer
()
{
return
tsMint
.
timer
;
}
static
int32_t
mnodeCreateDir
(
SMnode
*
pMnode
,
const
char
*
path
)
{
pMnode
->
path
=
strdup
(
path
);
if
(
pMnode
->
path
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
static
int32_t
mnodeSetOptions
(
SMnode
*
pMnode
,
const
SMnodeOpt
*
pOption
)
{
if
(
taosMkDir
(
pMnode
->
path
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
-
1
;
}
return
0
;
}
static
int32_t
mndInitSdb
(
SMnode
*
pMnode
)
{
SSdbOpt
opt
=
{
0
};
opt
.
path
=
pMnode
->
path
;
pMnode
->
pSdb
=
sdbInit
(
&
opt
);
if
(
pMnode
->
pSdb
==
NULL
)
{
return
-
1
;
}
return
0
;
}
static
int32_t
mndDeploySdb
(
SMnode
*
pMnode
)
{
return
sdbDeploy
(
pMnode
->
pSdb
);
}
static
int32_t
mndReadSdb
(
SMnode
*
pMnode
)
{
return
sdbReadFile
(
pMnode
->
pSdb
);
}
static
void
mndCleanupSdb
(
SMnode
*
pMnode
)
{
if
(
pMnode
->
pSdb
)
{
sdbCleanup
(
pMnode
->
pSdb
);
pMnode
->
pSdb
=
NULL
;
}
}
static
int32_t
mndAllocStep
(
SMnode
*
pMnode
,
char
*
name
,
MndInitFp
initFp
,
MndCleanupFp
cleanupFp
)
{
SMnodeStep
step
=
{
0
};
step
.
name
=
name
;
step
.
initFp
=
initFp
;
step
.
cleanupFp
=
cleanupFp
;
if
(
taosArrayPush
(
pMnode
->
pSteps
,
&
step
)
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
return
0
;
}
static
int32_t
mndInitSteps
(
SMnode
*
pMnode
)
{
if
(
mndAllocStep
(
pMnode
,
"mnode-sdb"
,
mndInitSdb
,
mndCleanupSdb
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-trans"
,
mndInitTrans
,
mndCleanupTrans
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-cluster"
,
mndInitCluster
,
mndCleanupCluster
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-dnode"
,
mndInitDnode
,
mndCleanupDnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-mnode"
,
mndInitMnode
,
mndCleanupMnode
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-acct"
,
mndInitAcct
,
mndCleanupAcct
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-auth"
,
mndInitAuth
,
mndCleanupAuth
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-user"
,
mndInitUser
,
mndCleanupUser
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-db"
,
mndInitDb
,
mndCleanupDb
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-vgroup"
,
mndInitVgroup
,
mndCleanupVgroup
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-stable"
,
mndInitStable
,
mndCleanupStable
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-func"
,
mndInitFunc
,
mndCleanupFunc
)
!=
0
)
return
-
1
;
if
(
pMnode
->
clusterId
<=
0
)
{
if
(
mndAllocStep
(
pMnode
,
"mnode-sdb-deploy"
,
mndDeploySdb
,
NULL
)
!=
0
)
return
-
1
;
}
else
{
if
(
mndAllocStep
(
pMnode
,
"mnode-sdb-read"
,
mndReadSdb
,
NULL
)
!=
0
)
return
-
1
;
}
if
(
mndAllocStep
(
pMnode
,
"mnode-timer"
,
mndInitTimer
,
NULL
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-balance"
,
mndInitBalance
,
mndCleanupBalance
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-profile"
,
mndInitProfile
,
mndCleanupProfile
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-show"
,
mndInitShow
,
mndCleanupShow
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-sync"
,
mndInitSync
,
mndCleanupSync
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-telem"
,
mndInitTelem
,
mndCleanupTelem
)
!=
0
)
return
-
1
;
if
(
mndAllocStep
(
pMnode
,
"mnode-timer"
,
NULL
,
mndCleanupTimer
)
!=
0
)
return
-
1
;
return
0
;
}
static
void
mndCleanupSteps
(
SMnode
*
pMnode
,
int32_t
pos
)
{
if
(
pMnode
->
pSteps
==
NULL
)
return
;
if
(
pos
==
-
1
)
{
pos
=
taosArrayGetSize
(
pMnode
->
pSteps
);
}
for
(
int32_t
s
=
pos
;
s
>=
0
;
s
--
)
{
SMnodeStep
*
pStep
=
taosArrayGet
(
pMnode
->
pSteps
,
pos
);
mDebug
(
"step:%s will cleanup"
,
pStep
->
name
);
if
(
pStep
->
cleanupFp
!=
NULL
)
{
(
*
pStep
->
cleanupFp
)(
pMnode
);
}
}
taosArrayClear
(
pMnode
->
pSteps
);
pMnode
->
pSteps
=
NULL
;
}
static
int32_t
mndExecSteps
(
SMnode
*
pMnode
)
{
int32_t
size
=
taosArrayGetSize
(
pMnode
->
pSteps
);
for
(
int32_t
pos
=
0
;
pos
<
size
;
pos
++
)
{
SMnodeStep
*
pStep
=
taosArrayGet
(
pMnode
->
pSteps
,
pos
);
if
(
pStep
->
initFp
==
NULL
)
continue
;
// (*pMnode->reportProgress)(pStep->name, "start initialize");
if
((
*
pStep
->
initFp
)(
pMnode
)
!=
0
)
{
mError
(
"step:%s exec failed since %s, start to cleanup"
,
pStep
->
name
,
terrstr
());
mndCleanupSteps
(
pMnode
,
pos
);
return
-
1
;
}
else
{
mDebug
(
"step:%s is initialized"
,
pStep
->
name
);
}
// (*pMnode->reportProgress)(pStep->name, "initialize completed");
}
return
0
;
}
static
int32_t
mndSetOptions
(
SMnode
*
pMnode
,
const
SMnodeOpt
*
pOption
)
{
pMnode
->
dnodeId
=
pOption
->
dnodeId
;
pMnode
->
clusterId
=
pOption
->
clusterId
;
pMnode
->
replica
=
pOption
->
replica
;
pMnode
->
selfIndex
=
pOption
->
selfIndex
;
memcpy
(
&
pMnode
->
replicas
,
pOption
->
replicas
,
sizeof
(
SReplica
)
*
TSDB_MAX_REPLICA
);
pMnode
->
p
Server
=
pOption
->
pDnode
;
pMnode
->
p
Dnode
=
pOption
->
pDnode
;
pMnode
->
putMsgToApplyMsgFp
=
pOption
->
putMsgToApplyMsgFp
;
pMnode
->
sendMsgToDnodeFp
=
pOption
->
sendMsgToDnodeFp
;
pMnode
->
sendMsgToMnodeFp
=
pOption
->
sendMsgToMnodeFp
;
pMnode
->
sendRedirectMsgFp
=
pOption
->
sendRedirectMsgFp
;
if
(
pMnode
->
sendMsgToDnodeFp
==
NULL
||
pMnode
->
sendMsgToMnodeFp
==
NULL
||
pMnode
->
sendRedirectMsgFp
==
NULL
||
pMnode
->
putMsgToApplyMsgFp
==
NULL
||
pMnode
->
dnodeId
<
0
||
pMnode
->
clusterId
<
0
)
{
pMnode
->
putMsgToApplyMsgFp
==
NULL
)
{
terrno
=
TSDB_CODE_MND_APP_ERROR
;
return
-
1
;
}
return
0
;
}
if
(
pMnode
->
dnodeId
<
0
||
pMnode
->
clusterId
<
0
)
{
terrno
=
TSDB_CODE_MND_APP_ERROR
;
return
-
1
;
}
static
int32_t
mnodeAllocInitSteps
()
{
struct
SSteps
*
steps
=
taosStepInit
(
16
,
NULL
);
if
(
steps
==
NULL
)
return
-
1
;
if
(
taosStepAdd
(
steps
,
"mnode-trans"
,
mnodeInitTrans
,
mnodeCleanupTrans
)
!=
0
)
return
-
1
;
if
(
taosStepAdd
(
steps
,
"mnode-cluster"
,
mnodeInitCluster
,
mnodeCleanupCluster
)
!=
0
)
return
-
1
;
if
(
taosStepAdd
(
steps
,
"mnode-dnode"
,
mnodeInitDnode
,
mnodeCleanupDnode
)
!=
0
)
return
-
1
;
if
(
taosStepAdd
(
steps
,
"mnode-mnode"
,
mnodeInitMnode
,
mnodeCleanupMnode
)
!=
0
)
return
-
1
;
if
(
taosStepAdd
(
steps
,
"mnode-acct"
,
mnodeInitAcct
,
mnodeCleanupAcct
)
!=
0
)
return
-
1
;
if
(
taosStepAdd
(
steps
,
"mnode-auth"
,
mnodeInitAuth
,
mnodeCleanupAuth
)
!=
0
)
return
-
1
;
if
(
taosStepAdd
(
steps
,
"mnode-user"
,
mnodeInitUser
,
mnodeCleanupUser
)
!=
0
)
return
-
1
;
if
(
taosStepAdd
(
steps
,
"mnode-db"
,
mnodeInitDb
,
mnodeCleanupDb
)
!=
0
)
return
-
1
;
if
(
taosStepAdd
(
steps
,
"mnode-vgroup"
,
mnodeInitVgroup
,
mnodeCleanupVgroup
)
!=
0
)
return
-
1
;
if
(
taosStepAdd
(
steps
,
"mnode-stable"
,
mnodeInitStable
,
mnodeCleanupStable
)
!=
0
)
return
-
1
;
if
(
taosStepAdd
(
steps
,
"mnode-func"
,
mnodeInitFunc
,
mnodeCleanupFunc
)
!=
0
)
return
-
1
;
if
(
taosStepAdd
(
steps
,
"mnode-sdb"
,
sdbInit
,
sdbCleanup
)
!=
0
)
return
-
1
;
tsMint
.
pInitSteps
=
steps
;
return
0
;
}
static
int32_t
mnodeAllocStartSteps
()
{
struct
SSteps
*
steps
=
taosStepInit
(
8
,
NULL
);
if
(
steps
==
NULL
)
return
-
1
;
taosStepAdd
(
steps
,
"mnode-timer"
,
mnodeInitTimer
,
NULL
);
taosStepAdd
(
steps
,
"mnode-sdb-file"
,
sdbOpen
,
sdbClose
);
taosStepAdd
(
steps
,
"mnode-balance"
,
mnodeInitBalance
,
mnodeCleanupBalance
);
taosStepAdd
(
steps
,
"mnode-profile"
,
mnodeInitProfile
,
mnodeCleanupProfile
);
taosStepAdd
(
steps
,
"mnode-show"
,
mnodeInitShow
,
mnodeCleanUpShow
);
taosStepAdd
(
steps
,
"mnode-sync"
,
mnodeInitSync
,
mnodeCleanUpSync
);
taosStepAdd
(
steps
,
"mnode-telem"
,
mnodeInitTelem
,
mnodeCleanupTelem
);
taosStepAdd
(
steps
,
"mnode-timer"
,
NULL
,
mnodeCleanupTimer
);
SMnode
*
mndOpen
(
const
char
*
path
,
const
SMnodeOpt
*
pOption
)
{
mDebug
(
"start to open mnode in %s"
,
path
);
tsMint
.
pStartSteps
=
steps
;
return
0
;
}
SMnode
*
mnodeOpen
(
const
char
*
path
,
const
SMnodeOpt
*
pOption
)
{
SMnode
*
pMnode
=
calloc
(
1
,
sizeof
(
SMnode
));
if
(
pMnode
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"failed to open mnode since %s"
,
terrstr
());
return
NULL
;
}
if
(
mnodeSetOptions
(
pMnode
,
pOption
)
!=
0
)
{
pMnode
->
pSteps
=
taosArrayInit
(
24
,
sizeof
(
SMnodeStep
));
if
(
pMnode
->
pSteps
==
NULL
)
{
free
(
pMnode
);
mError
(
"failed to init mnode options since %s"
,
terrstr
());
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"failed to open mnode since %s"
,
terrstr
());
return
NULL
;
}
if
(
mnodeAllocInitSteps
()
!=
0
)
{
mError
(
"failed to alloc init steps since %s"
,
terrstr
());
int32_t
code
=
mnodeCreateDir
(
pMnode
,
path
);
if
(
mnodeCreateDir
(
pMnode
,
path
)
!=
0
)
{
mError
(
"failed to open mnode since %s"
,
tstrerror
(
code
));
mndClose
(
pMnode
);
terrno
=
code
;
return
NULL
;
}
if
(
mnodeAllocStartSteps
()
!=
0
)
{
mError
(
"failed to alloc start steps since %s"
,
terrstr
());
code
=
mndSetOptions
(
pMnode
,
pOption
);
if
(
code
!=
0
)
{
mError
(
"failed to open mnode since %s"
,
tstrerror
(
code
));
mndClose
(
pMnode
);
terrno
=
code
;
return
NULL
;
}
taosStepExec
(
tsMint
.
pInitSteps
);
if
(
tsMint
.
para
.
dnodeId
<=
0
&&
tsMint
.
para
.
clusterId
<=
0
)
{
if
(
sdbDeploy
()
!=
0
)
{
mError
(
"failed to deploy sdb since %s"
,
terrstr
());
return
NULL
;
}
else
{
mInfo
(
"mnode is deployed"
);
}
code
=
mndInitSteps
(
pMnode
);
if
(
code
!=
0
)
{
mError
(
"failed to open mnode since %s"
,
tstrerror
(
code
));
mndClose
(
pMnode
);
terrno
=
code
;
return
NULL
;
}
taosStepExec
(
tsMint
.
pStartSteps
);
code
=
mndExecSteps
(
pMnode
);
if
(
code
!=
0
)
{
mError
(
"failed to open mnode since %s"
,
tstrerror
(
code
));
mndClose
(
pMnode
);
terrno
=
code
;
return
NULL
;
}
mDebug
(
"mnode open successfully "
);
return
pMnode
;
}
void
mnodeClose
(
SMnode
*
pMnode
)
{
free
(
pMnode
);
}
void
mndClose
(
SMnode
*
pMnode
)
{
if
(
pMnode
!=
NULL
)
{
mDebug
(
"start to close mnode"
);
mndCleanupSteps
(
pMnode
,
-
1
);
tfree
(
pMnode
->
path
);
tfree
(
pMnode
);
mDebug
(
"mnode is closed"
);
}
}
int32_t
mndAlter
(
SMnode
*
pMnode
,
const
SMnodeOpt
*
pOption
)
{
mDebug
(
"start to alter mnode"
);
mDebug
(
"mnode is altered"
);
return
0
;
}
int32_t
mnodeAlter
(
SMnode
*
pMnode
,
const
SMnodeOpt
*
pOption
)
{
return
0
;
}
void
mndDestroy
(
const
char
*
path
)
{
mDebug
(
"start to destroy mnode at %s"
,
path
);
taosRemoveDir
(
path
);
mDebug
(
"mnode is destroyed"
);
}
void
mnodeDestroy
(
const
char
*
path
)
{
sdbUnDeploy
();
}
int32_t
mndGetLoad
(
SMnode
*
pMnode
,
SMnodeLoad
*
pLoad
)
{
pLoad
->
numOfDnode
=
0
;
pLoad
->
numOfMnode
=
0
;
pLoad
->
numOfVgroup
=
0
;
pLoad
->
numOfDatabase
=
0
;
pLoad
->
numOfSuperTable
=
0
;
pLoad
->
numOfChildTable
=
0
;
pLoad
->
numOfColumn
=
0
;
pLoad
->
totalPoints
=
0
;
pLoad
->
totalStorage
=
0
;
pLoad
->
compStorage
=
0
;
int32_t
mnodeGetLoad
(
SMnode
*
pMnode
,
SMnodeLoad
*
pLoad
)
{
return
0
;
}
return
0
;
}
SMnodeMsg
*
mn
ode
InitMsg
(
SMnode
*
pMnode
,
SRpcMsg
*
pRpcMsg
)
{
SMnodeMsg
*
mn
d
InitMsg
(
SMnode
*
pMnode
,
SRpcMsg
*
pRpcMsg
)
{
SMnodeMsg
*
pMsg
=
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
if
(
pMsg
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -187,7 +339,7 @@ SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
}
if
(
rpcGetConnInfo
(
pRpcMsg
->
handle
,
&
pMsg
->
conn
)
!=
0
)
{
mn
ode
CleanupMsg
(
pMsg
);
mn
d
CleanupMsg
(
pMsg
);
mError
(
"can not get user from conn:%p"
,
pMsg
->
rpcMsg
.
handle
);
terrno
=
TSDB_CODE_MND_NO_USER_FROM_CONN
;
return
NULL
;
...
...
@@ -199,181 +351,72 @@ SMnodeMsg *mnodeInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
return
pMsg
;
}
void
mn
ode
CleanupMsg
(
SMnodeMsg
*
pMsg
)
{
void
mn
d
CleanupMsg
(
SMnodeMsg
*
pMsg
)
{
if
(
pMsg
->
pUser
!=
NULL
)
{
sdbRelease
(
pMsg
->
pUser
);
sdbRelease
(
pMsg
->
p
Mnode
->
pSdb
,
pMsg
->
p
User
);
}
taosFreeQitem
(
pMsg
);
}
void
mnodeSendRsp
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{}
static
void
mnodeProcessRpcMsg
(
SMnodeMsg
*
pMsg
)
{
if
(
!
mnodeIsMaster
())
{
mnodeSendRedirectMsg
(
NULL
,
&
pMsg
->
rpcMsg
,
true
);
mnodeCleanupMsg
(
pMsg
);
return
;
}
void
mndSendRsp
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{}
static
void
mndProcessRpcMsg
(
SMnodeMsg
*
pMsg
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
int32_t
code
=
0
;
int32_t
msgType
=
pMsg
->
rpcMsg
.
msgType
;
void
*
ahandle
=
pMsg
->
rpcMsg
.
ahandle
;
bool
isReq
=
(
msgType
%
2
==
1
);
MnodeRpcFp
fp
=
tsMint
.
msgFp
[
msgType
];
if
(
fp
==
NULL
)
{
}
int32_t
code
=
(
fp
)(
pMsg
);
if
(
code
!=
0
)
{
assert
(
code
);
}
}
void
mnodeSetMsgFp
(
int32_t
msgType
,
MnodeRpcFp
fp
)
{
if
(
msgType
>
0
||
msgType
<
TSDB_MSG_TYPE_MAX
)
{
tsMint
.
msgFp
[
msgType
]
=
fp
;
if
(
isReq
&&
!
mndIsMaster
(
pMnode
))
{
code
=
TSDB_CODE_APP_NOT_READY
;
goto
PROCESS_RPC_END
;
}
}
void
mnodeProcessReadMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{
mnodeProcessRpcMsg
(
pMsg
);
}
void
mnodeProcessWriteMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{
mnodeProcessRpcMsg
(
pMsg
);
}
void
mnodeProcessSyncMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{
mnodeProcessRpcMsg
(
pMsg
);
}
void
mnodeProcessApplyMsg
(
SMnode
*
pMnode
,
SMnodeMsg
*
pMsg
)
{}
#if 0
static void mnodeProcessWriteReq(SMnodeMsg *pMsg, void *unused) {
int32_t msgType = pMsg->rpcMsg.msgType;
void *ahandle = pMsg->rpcMsg.ahandle;
int32_t code = 0;
if (pMsg->rpcMsg.pCont == NULL) {
if
(
isReq
&&
pMsg
->
rpcMsg
.
pCont
==
NULL
)
{
mError
(
"msg:%p, app:%p type:%s content is null"
,
pMsg
,
ahandle
,
taosMsg
[
msgType
]);
code
=
TSDB_CODE_MND_INVALID_MSG_LEN
;
goto PROCESS_WRITE_REQ_END;
}
if (!mnodeIsMaster()) {
SMnRsp *rpcRsp = &pMsg->rpcRsp;
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
mnodeGetMnodeEpSetForShell(epSet, true);
rpcRsp->rsp = epSet;
rpcRsp->len = sizeof(SEpSet);
mDebug("msg:%p, app:%p type:%s in write queue, is redirected, numOfEps:%d inUse:%d", pMsg, ahandle,
taosMsg[msgType], epSet->numOfEps, epSet->inUse);
code = TSDB_CODE_RPC_REDIRECT;
goto PROCESS_WRITE_REQ_END;
goto
PROCESS_RPC_END
;
}
if (tsMworker.writeMsgFp[msgType] == NULL) {
MndMsgFp
fp
=
pMnode
->
msgFp
[
msgType
];
if
(
fp
==
NULL
)
{
mError
(
"msg:%p, app:%p type:%s not processed"
,
pMsg
,
ahandle
,
taosMsg
[
msgType
]);
code = TSDB_CODE_M
ND_M
SG_NOT_PROCESSED;
goto PROCESS_
WRITE_REQ
_END;
code
=
TSDB_CODE_MSG_NOT_PROCESSED
;
goto
PROCESS_
RPC
_END
;
}
code = (*tsMworker.writeMsgFp[msgType])(pMsg);
PROCESS_WRITE_REQ_END:
mnodeSendRsp(pMsg, code);
}
static void mnodeProcessReadReq(SMnodeMsg *pMsg, void *unused) {
int32_t msgType = pMsg->rpcMsg.msgType;
void *ahandle = pMsg->rpcMsg.ahandle;
int32_t code = 0;
if (pMsg->rpcMsg.pCont == NULL) {
mError("msg:%p, app:%p type:%s in mread queue, content is null", pMsg, ahandle, taosMsg[msgType]);
code = TSDB_CODE_MND_INVALID_MSG_LEN;
goto PROCESS_READ_REQ_END;
code
=
(
*
fp
)(
pMnode
,
pMsg
);
if
(
code
!=
0
)
{
code
=
terrno
;
mError
(
"msg:%p, app:%p type:%s failed to process since %s"
,
pMsg
,
ahandle
,
taosMsg
[
msgType
],
terrstr
());
goto
PROCESS_RPC_END
;
}
if (!mnodeIsMaster()) {
SMnRsp *rpcRsp = &pMsg->rpcRsp;
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
if (!epSet) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto PROCESS_READ_REQ_END;
PROCESS_RPC_END:
if
(
isReq
)
{
if
(
code
==
TSDB_CODE_APP_NOT_READY
)
{
mndSendRedirectMsg
(
pMnode
,
&
pMsg
->
rpcMsg
);
}
else
if
(
code
!=
0
)
{
SRpcMsg
rspMsg
=
{.
handle
=
pMsg
->
rpcMsg
.
handle
,
.
code
=
code
};
rpcSendResponse
(
&
rspMsg
);
}
else
{
}
mnodeGetMnodeEpSetForShell(epSet, true);
rpcRsp->rsp = epSet;
rpcRsp->len = sizeof(SEpSet);
mDebug("msg:%p, app:%p type:%s in mread queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle, taosMsg[msgType],
epSet->numOfEps, epSet->inUse);
code = TSDB_CODE_RPC_REDIRECT;
goto PROCESS_READ_REQ_END;
}
if (tsMworker.readMsgFp[msgType] == NULL) {
mError("msg:%p, app:%p type:%s in mread queue, not processed", pMsg, ahandle, taosMsg[msgType]);
code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
goto PROCESS_READ_REQ_END;
}
mTrace("msg:%p, app:%p type:%s will be processed in mread queue", pMsg, ahandle, taosMsg[msgType]);
code = (*tsMworker.readMsgFp[msgType])(pMsg);
PROCESS_READ_REQ_END:
mnodeSendRsp(pMsg, code);
mndCleanupMsg
(
pMsg
);
}
static void mnodeProcessPeerReq(SMnodeMsg *pMsg, void *unused) {
int32_t msgType = pMsg->rpcMsg.msgType;
void *ahandle = pMsg->rpcMsg.ahandle;
int32_t code = 0;
if (pMsg->rpcMsg.pCont == NULL) {
mError("msg:%p, ahandle:%p type:%s in mpeer queue, content is null", pMsg, ahandle, taosMsg[msgType]);
code = TSDB_CODE_MND_INVALID_MSG_LEN;
goto PROCESS_PEER_REQ_END;
void
mndSetMsgHandle
(
SMnode
*
pMnode
,
int32_t
msgType
,
MndMsgFp
fp
)
{
if
(
msgType
>=
0
&&
msgType
<
TSDB_MSG_TYPE_MAX
)
{
pMnode
->
msgFp
[
msgType
]
=
fp
;
}
if (!mnodeIsMaster()) {
SMnRsp *rpcRsp = &pMsg->rpcRsp;
SEpSet *epSet = rpcMallocCont(sizeof(SEpSet));
mnodeGetMnodeEpSetForPeer(epSet, true);
rpcRsp->rsp = epSet;
rpcRsp->len = sizeof(SEpSet);
mDebug("msg:%p, ahandle:%p type:%s in mpeer queue is redirected, numOfEps:%d inUse:%d", pMsg, ahandle,
taosMsg[msgType], epSet->numOfEps, epSet->inUse);
code = TSDB_CODE_RPC_REDIRECT;
goto PROCESS_PEER_REQ_END;
}
if (tsMworker.peerReqFp[msgType] == NULL) {
mError("msg:%p, ahandle:%p type:%s in mpeer queue, not processed", pMsg, ahandle, taosMsg[msgType]);
code = TSDB_CODE_MND_MSG_NOT_PROCESSED;
goto PROCESS_PEER_REQ_END;
}
code = (*tsMworker.peerReqFp[msgType])(pMsg);
PROCESS_PEER_REQ_END:
mnodeSendRsp(pMsg, code);
}
static void mnodeProcessPeerRsp(SMnodeMsg *pMsg, void *unused) {
int32_t msgType = pMsg->rpcMsg.msgType;
SRpcMsg *pRpcMsg = &pMsg->rpcMsg;
void
mndProcessReadMsg
(
SMnodeMsg
*
pMsg
)
{
mndProcessRpcMsg
(
pMsg
);
}
if (!mnodeIsMaster()) {
mError("msg:%p, ahandle:%p type:%s not processed for not master", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
mnodeCleanupMsg2(pMsg);
}
void
mndProcessWriteMsg
(
SMnodeMsg
*
pMsg
)
{
mndProcessRpcMsg
(
pMsg
);
}
if (tsMworker.peerRspFp[msgType]) {
(*tsMworker.peerRspFp[msgType])(pRpcMsg);
} else {
mError("msg:%p, ahandle:%p type:%s is not processed", pRpcMsg, pRpcMsg->ahandle, taosMsg[msgType]);
}
void
mndProcessSyncMsg
(
SMnodeMsg
*
pMsg
)
{
mndProcessRpcMsg
(
pMsg
);
}
mnodeCleanupMsg2(pMsg);
}
#endif
\ No newline at end of file
void
mndProcessApplyMsg
(
SMnodeMsg
*
pMsg
)
{}
source/dnode/mnode/impl/src/mnodeFunc.c
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mnodeInt.h"
int32_t
mnodeInitFunc
()
{
return
0
;
}
void
mnodeCleanupFunc
()
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mnodeOper.c
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mnodeInt.h"
int32_t
mnodeInitOper
()
{
return
0
;
}
void
mnodeCleanupOper
()
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mnodeProfile.c
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mnodeInt.h"
int32_t
mnodeInitProfile
()
{
return
0
;
}
void
mnodeCleanupProfile
()
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mnodeShow.c
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mnodeInt.h"
int32_t
mnodeInitShow
()
{
return
0
;
}
void
mnodeCleanUpShow
()
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mnodeStable.c
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mnodeInt.h"
int32_t
mnodeInitStable
()
{
return
0
;
}
void
mnodeCleanupStable
()
{}
\ No newline at end of file
source/dnode/mnode/impl/src/mnodeVgroup.c
已删除
100644 → 0
浏览文件 @
df9ba31d
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "mnodeInt.h"
int32_t
mnodeInitVgroup
()
{
return
0
;
}
void
mnodeCleanupVgroup
()
{}
\ No newline at end of file
source/dnode/mnode/sdb/CMakeLists.txt
浏览文件 @
81ebcd8b
...
...
@@ -3,7 +3,7 @@ add_library(sdb ${MNODE_SRC})
target_include_directories
(
sdb
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/dnode/mnode/sdb"
private
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
target_link_libraries
(
sdb
...
...
source/dnode/mnode/sdb/inc/sdbInt.h
浏览文件 @
81ebcd8b
...
...
@@ -37,7 +37,7 @@ extern "C" {
#define SDB_MAX_SIZE (32 * 1024)
typedef
struct
SSdbRaw
{
int8_t
sdb
;
int8_t
type
;
int8_t
sver
;
int8_t
status
;
int8_t
reserved
;
...
...
@@ -46,7 +46,7 @@ typedef struct SSdbRaw {
}
SSdbRaw
;
typedef
struct
SSdbRow
{
ESdbType
sdb
;
ESdbType
type
;
ESdbStatus
status
;
int32_t
refCount
;
char
pObj
[];
...
...
@@ -69,9 +69,8 @@ typedef struct SSdb {
SdbDecodeFp
decodeFps
[
SDB_MAX
];
}
SSdb
;
extern
SSdb
tsSdb
;
int32_t
sdbWriteImp
(
SSdbRaw
*
pRaw
);
int32_t
sdbWriteFile
(
SSdb
*
pSdb
);
int32_t
sdbWriteRaw
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
);
#ifdef __cplusplus
}
...
...
source/dnode/mnode/sdb/src/sdb.c
浏览文件 @
81ebcd8b
...
...
@@ -15,77 +15,100 @@
#define _DEFAULT_SOURCE
#include "sdbInt.h"
#include "tglobal.h"
SSdb
tsSdb
=
{
0
};
SSdb
*
sdbInit
(
SSdbOpt
*
pOption
)
{
mDebug
(
"start to init sdb in %s"
,
pOption
->
path
);
int32_t
sdbInit
()
{
char
path
[
PATH_MAX
+
100
];
snprintf
(
path
,
PATH_MAX
+
100
,
"%s%scur%s"
,
tsMnodeDir
,
TD_DIRSEP
,
TD_DIRSEP
);
tsSdb
.
currDir
=
strdup
(
path
);
snprintf
(
path
,
PATH_MAX
+
100
,
"%s%ssync%s"
,
tsMnodeDir
,
TD_DIRSEP
,
TD_DIRSEP
);
tsSdb
.
syncDir
=
strdup
(
path
);
snprintf
(
path
,
PATH_MAX
+
100
,
"%s%stmp%s"
,
tsMnodeDir
,
TD_DIRSEP
,
TD_DIRSEP
);
tsSdb
.
tmpDir
=
strdup
(
path
);
SSdb
*
pSdb
=
calloc
(
1
,
sizeof
(
SSdb
));
if
(
pSdb
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"failed to init sdb since %s"
,
terrstr
());
return
NULL
;
}
if
(
tsSdb
.
currDir
==
NULL
||
tsSdb
.
currDir
==
NULL
||
tsSdb
.
currDir
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
char
path
[
PATH_MAX
+
100
];
snprintf
(
path
,
PATH_MAX
+
100
,
"%s"
,
pOption
->
path
);
pSdb
->
currDir
=
strdup
(
path
);
snprintf
(
path
,
PATH_MAX
+
100
,
"%s%ssync"
,
pOption
->
path
,
TD_DIRSEP
);
pSdb
->
syncDir
=
strdup
(
path
);
snprintf
(
path
,
PATH_MAX
+
100
,
"%s%stmp"
,
pOption
->
path
,
TD_DIRSEP
);
pSdb
->
tmpDir
=
strdup
(
path
);
if
(
pSdb
->
currDir
==
NULL
||
pSdb
->
currDir
==
NULL
||
pSdb
->
currDir
==
NULL
)
{
sdbCleanup
(
pSdb
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"failed to init sdb since %s"
,
terrstr
());
return
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
SDB_MAX
;
++
i
)
{
int32_t
type
;
if
(
tsSdb
.
keyTypes
[
i
]
==
SDB_KEY_INT32
)
{
type
=
TSDB_DATA_TYPE_INT
;
}
else
if
(
tsSdb
.
keyTypes
[
i
]
==
SDB_KEY_INT64
)
{
type
=
TSDB_DATA_TYPE_BIGINT
;
}
else
{
type
=
TSDB_DATA_TYPE_BINARY
;
}
SHashObj
*
hash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
type
),
true
,
HASH_NO_LOCK
);
if
(
hash
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
tsSdb
.
hashObjs
[
i
]
=
hash
;
taosInitRWLatch
(
&
tsSdb
.
locks
[
i
]);
taosInitRWLatch
(
&
pSdb
->
locks
[
i
]);
}
return
0
;
mDebug
(
"sdb init successfully"
);
return
pSdb
;
}
void
sdbCleanup
()
{
if
(
tsSdb
.
currDir
!=
NULL
)
{
tfree
(
tsSdb
.
currDir
);
void
sdbCleanup
(
SSdb
*
pSdb
)
{
mDebug
(
"start to cleanup sdb"
);
if
(
pSdb
->
curVer
!=
pSdb
->
lastCommitVer
)
{
mDebug
(
"write sdb file for curVer:% "
PRId64
" and lastVer:%"
PRId64
,
pSdb
->
curVer
,
pSdb
->
lastCommitVer
);
sdbWriteFile
(
pSdb
);
}
if
(
tsSdb
.
sync
Dir
!=
NULL
)
{
tfree
(
tsSdb
.
sync
Dir
);
if
(
pSdb
->
curr
Dir
!=
NULL
)
{
tfree
(
pSdb
->
curr
Dir
);
}
if
(
tsSdb
.
tmpDir
!=
NULL
)
{
tfree
(
tsSdb
.
tmpDir
);
if
(
pSdb
->
syncDir
!=
NULL
)
{
tfree
(
pSdb
->
syncDir
);
}
if
(
pSdb
->
tmpDir
!=
NULL
)
{
tfree
(
pSdb
->
tmpDir
);
}
for
(
int32_t
i
=
0
;
i
<
SDB_MAX
;
++
i
)
{
SHashObj
*
hash
=
tsSdb
.
hashObjs
[
i
];
SHashObj
*
hash
=
pSdb
->
hashObjs
[
i
];
if
(
hash
!=
NULL
)
{
taosHashClear
(
hash
);
taosHashCleanup
(
hash
);
}
tsSdb
.
hashObjs
[
i
]
=
NULL
;
pSdb
->
hashObjs
[
i
]
=
NULL
;
}
mDebug
(
"sdb is cleaned up"
);
}
void
sdbSetTable
(
SSdbTable
table
)
{
int32_t
sdbSetTable
(
SSdb
*
pSdb
,
SSdbTable
table
)
{
ESdbType
sdb
=
table
.
sdbType
;
tsSdb
.
keyTypes
[
sdb
]
=
table
.
keyType
;
tsSdb
.
insertFps
[
sdb
]
=
table
.
insertFp
;
tsSdb
.
updateFps
[
sdb
]
=
table
.
updateFp
;
tsSdb
.
deleteFps
[
sdb
]
=
table
.
deleteFp
;
tsSdb
.
deployFps
[
sdb
]
=
table
.
deployFp
;
tsSdb
.
encodeFps
[
sdb
]
=
table
.
encodeFp
;
tsSdb
.
decodeFps
[
sdb
]
=
table
.
decodeFp
;
pSdb
->
keyTypes
[
sdb
]
=
table
.
keyType
;
pSdb
->
insertFps
[
sdb
]
=
table
.
insertFp
;
pSdb
->
updateFps
[
sdb
]
=
table
.
updateFp
;
pSdb
->
deleteFps
[
sdb
]
=
table
.
deleteFp
;
pSdb
->
deployFps
[
sdb
]
=
table
.
deployFp
;
pSdb
->
encodeFps
[
sdb
]
=
table
.
encodeFp
;
pSdb
->
decodeFps
[
sdb
]
=
table
.
decodeFp
;
for
(
int32_t
i
=
0
;
i
<
SDB_MAX
;
++
i
)
{
int32_t
type
;
if
(
pSdb
->
keyTypes
[
i
]
==
SDB_KEY_INT32
)
{
type
=
TSDB_DATA_TYPE_INT
;
}
else
if
(
pSdb
->
keyTypes
[
i
]
==
SDB_KEY_INT64
)
{
type
=
TSDB_DATA_TYPE_BIGINT
;
}
else
{
type
=
TSDB_DATA_TYPE_BINARY
;
}
SHashObj
*
hash
=
taosHashInit
(
64
,
taosGetDefaultHashFunction
(
type
),
true
,
HASH_NO_LOCK
);
if
(
hash
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pSdb
->
hashObjs
[
i
]
=
hash
;
taosInitRWLatch
(
&
pSdb
->
locks
[
i
]);
}
return
0
;
}
\ No newline at end of file
source/dnode/mnode/sdb/src/sdbFile.c
浏览文件 @
81ebcd8b
...
...
@@ -15,71 +15,71 @@
#define _DEFAULT_SOURCE
#include "sdbInt.h"
#include "tglobal.h"
#include "tchecksum.h"
static
int32_t
sdbCreateDir
()
{
mDebug
(
"start to create mnode at %s"
,
tsMnodeDir
);
if
(
taosMkDir
(
tsSdb
.
currDir
)
!=
0
)
{
static
int32_t
sdbCreateDir
(
SSdb
*
pSdb
)
{
if
(
taosMkDir
(
pSdb
->
currDir
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"failed to create dir:%s since %s"
,
tsSdb
.
currDir
,
terrstr
());
mError
(
"failed to create dir:%s since %s"
,
pSdb
->
currDir
,
terrstr
());
return
-
1
;
}
if
(
taosMkDir
(
tsSdb
.
syncDir
)
!=
0
)
{
if
(
taosMkDir
(
pSdb
->
syncDir
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"failed to create dir:%s since %s"
,
tsSdb
.
syncDir
,
terrstr
());
mError
(
"failed to create dir:%s since %s"
,
pSdb
->
syncDir
,
terrstr
());
return
-
1
;
}
if
(
taosMkDir
(
tsSdb
.
tmpDir
)
!=
0
)
{
if
(
taosMkDir
(
pSdb
->
tmpDir
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"failed to create dir:%s since %s"
,
tsSdb
.
tmpDir
,
terrstr
());
mError
(
"failed to create dir:%s since %s"
,
pSdb
->
tmpDir
,
terrstr
());
return
-
1
;
}
return
0
;
}
static
int32_t
sdbRunDeployFp
()
{
mDebug
(
"start to
run deploy functions
"
);
static
int32_t
sdbRunDeployFp
(
SSdb
*
pSdb
)
{
mDebug
(
"start to
deploy sdb
"
);
for
(
int32_t
i
=
SDB_MAX
-
1
;
i
>
SDB_START
;
--
i
)
{
SdbDeployFp
fp
=
tsSdb
.
deployFps
[
i
];
SdbDeployFp
fp
=
pSdb
->
deployFps
[
i
];
if
(
fp
==
NULL
)
continue
;
if
((
*
fp
)()
!=
0
)
{
if
((
*
fp
)(
pSdb
)
!=
0
)
{
mError
(
"failed to deploy sdb:%d since %s"
,
i
,
terrstr
());
return
-
1
;
}
}
mDebug
(
"
end of run deploy functions
"
);
mDebug
(
"
sdb deploy successfully
"
);
return
0
;
}
static
int32_t
sdbReadDataFile
()
{
int32_t
sdbReadFile
(
SSdb
*
pSdb
)
{
int64_t
offset
=
0
;
int32_t
code
=
0
;
int32_t
readLen
=
0
;
int64_t
ret
=
0
;
SSdbRaw
*
pRaw
=
malloc
(
SDB_MAX_SIZE
);
if
(
pRaw
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
mError
(
"failed read file since %s"
,
terrstr
());
return
-
1
;
}
char
file
[
PATH_MAX
]
=
{
0
};
snprintf
(
file
,
sizeof
(
file
),
"%ssdb.data"
,
tsSdb
.
currDir
);
snprintf
(
file
,
sizeof
(
file
),
"%s%ssdb.data"
,
pSdb
->
currDir
,
TD_DIRSEP
);
FileFd
fd
=
taosOpenFileRead
(
file
);
if
(
fd
<=
0
)
{
free
(
pRaw
);
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"failed to
open file:%s for read
since %s"
,
file
,
terrstr
());
mError
(
"failed to
read file:%s
since %s"
,
file
,
terrstr
());
return
-
1
;
}
int64_t
offset
=
0
;
int32_t
code
=
0
;
int32_t
readLen
=
0
;
int64_t
ret
=
0
;
while
(
1
)
{
readLen
=
sizeof
(
SSdbRaw
);
ret
=
taosReadFile
(
fd
,
pRaw
,
readLen
);
...
...
@@ -118,7 +118,7 @@ static int32_t sdbReadDataFile() {
break
;
}
code
=
sdbWrite
Imp
(
pRaw
);
code
=
sdbWrite
Raw
(
pSdb
,
pRaw
);
if
(
code
!=
0
)
{
mError
(
"failed to read file:%s since %s"
,
file
,
terrstr
());
goto
PARSE_SDB_DATA_ERROR
;
...
...
@@ -130,13 +130,18 @@ static int32_t sdbReadDataFile() {
PARSE_SDB_DATA_ERROR:
taosCloseFile
(
fd
);
sdbFreeRaw
(
pRaw
);
terrno
=
code
;
return
code
;
}
static
int32_t
sdbWriteDataFile
()
{
int32_t
sdbWriteFile
(
SSdb
*
pSdb
)
{
int32_t
code
=
0
;
char
tmpfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
tmpfile
,
sizeof
(
tmpfile
),
"%ssdb.data"
,
tsSdb
.
tmpDir
);
snprintf
(
tmpfile
,
sizeof
(
tmpfile
),
"%s%ssdb.data"
,
pSdb
->
tmpDir
,
TD_DIRSEP
);
char
curfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
curfile
,
sizeof
(
curfile
),
"%s%ssdb.data"
,
pSdb
->
currDir
,
TD_DIRSEP
);
FileFd
fd
=
taosOpenFileCreateWrite
(
tmpfile
);
if
(
fd
<=
0
)
{
...
...
@@ -145,14 +150,12 @@ static int32_t sdbWriteDataFile() {
return
-
1
;
}
int32_t
code
=
0
;
for
(
int32_t
i
=
SDB_MAX
-
1
;
i
>
SDB_START
;
--
i
)
{
SdbEncodeFp
encodeFp
=
tsSdb
.
encodeFps
[
i
];
SdbEncodeFp
encodeFp
=
pSdb
->
encodeFps
[
i
];
if
(
encodeFp
==
NULL
)
continue
;
SHashObj
*
hash
=
tsSdb
.
hashObjs
[
i
];
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
i
];
SHashObj
*
hash
=
pSdb
->
hashObjs
[
i
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
i
];
taosWLockLatch
(
pLock
);
SSdbRow
**
ppRow
=
taosHashIterate
(
hash
,
NULL
);
...
...
@@ -192,68 +195,44 @@ static int32_t sdbWriteDataFile() {
if
(
code
==
0
)
{
code
=
taosFsyncFile
(
fd
);
if
(
code
!=
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"failed to write file:%s since %s"
,
tmpfile
,
tstrerror
(
code
));
}
}
taosCloseFile
(
fd
);
if
(
code
==
0
)
{
char
curfile
[
PATH_MAX
]
=
{
0
};
snprintf
(
curfile
,
sizeof
(
curfile
),
"%ssdb.data"
,
tsSdb
.
currDir
);
code
=
taosRenameFile
(
tmpfile
,
curfile
);
if
(
code
!=
0
)
{
code
=
TAOS_SYSTEM_ERROR
(
errno
);
mError
(
"failed to write file:%s since %s"
,
curfile
,
tstrerror
(
code
));
}
}
if
(
code
!=
0
)
{
terrno
=
code
;
mError
(
"failed to write sdb file since %s"
,
terrstr
());
mError
(
"failed to write file:%s since %s"
,
curfile
,
tstrerror
(
code
));
}
else
{
mDebug
(
"write
sdb file successfully"
);
mDebug
(
"write
file:%s successfully"
,
curfile
);
}
terrno
=
code
;
return
code
;
}
int32_t
sdbOpen
()
{
mDebug
(
"start to read mnode file"
);
if
(
sdbReadDataFile
()
!=
0
)
{
int32_t
sdbDeploy
(
SSdb
*
pSdb
)
{
if
(
sdbCreateDir
(
pSdb
)
!=
0
)
{
return
-
1
;
}
return
0
;
}
void
sdbClose
()
{
if
(
tsSdb
.
curVer
!=
tsSdb
.
lastCommitVer
)
{
mDebug
(
"start to write mnode file"
);
sdbWriteDataFile
();
}
for
(
int32_t
i
=
0
;
i
<
SDB_MAX
;
++
i
)
{
SHashObj
*
hash
=
tsSdb
.
hashObjs
[
i
];
if
(
hash
!=
NULL
)
{
taosHashClear
(
hash
);
}
}
}
int32_t
sdbDeploy
()
{
if
(
sdbCreateDir
()
!=
0
)
{
if
(
sdbRunDeployFp
(
pSdb
)
!=
0
)
{
return
-
1
;
}
if
(
sdb
RunDeployFp
(
)
!=
0
)
{
if
(
sdb
WriteFile
(
pSdb
)
!=
0
)
{
return
-
1
;
}
if
(
sdbWriteDataFile
()
!=
0
)
{
return
-
1
;
}
sdbClose
();
return
0
;
}
void
sdbUnDeploy
()
{
mDebug
(
"start to undeploy mnode"
);
taosRemoveDir
(
tsMnodeDir
);
}
source/dnode/mnode/sdb/src/sdbHash.c
浏览文件 @
81ebcd8b
...
...
@@ -15,15 +15,14 @@
#define _DEFAULT_SOURCE
#include "sdbInt.h"
#include "tglobal.h"
static
SHashObj
*
sdbGetHash
(
int32_t
sdb
)
{
if
(
sdb
>=
SDB_MAX
||
sdb
<=
SDB_START
)
{
static
SHashObj
*
sdbGetHash
(
SSdb
*
pSdb
,
int32_t
type
)
{
if
(
type
>=
SDB_MAX
||
type
<=
SDB_START
)
{
terrno
=
TSDB_CODE_SDB_INVALID_TABLE_TYPE
;
return
NULL
;
}
SHashObj
*
hash
=
tsSdb
.
hashObjs
[
sdb
];
SHashObj
*
hash
=
pSdb
->
hashObjs
[
type
];
if
(
hash
==
NULL
)
{
terrno
=
TSDB_CODE_SDB_APP_ERROR
;
return
NULL
;
...
...
@@ -32,9 +31,9 @@ static SHashObj *sdbGetHash(int32_t sdb) {
return
hash
;
}
static
int32_t
sdbGetkeySize
(
ESdbType
sdb
,
void
*
pKey
)
{
static
int32_t
sdbGetkeySize
(
SSdb
*
pSdb
,
ESdbType
type
,
void
*
pKey
)
{
int32_t
keySize
;
EKeyType
keyType
=
tsSdb
.
keyTypes
[
sdb
];
EKeyType
keyType
=
pSdb
->
keyTypes
[
type
];
if
(
keyType
==
SDB_KEY_INT32
)
{
keySize
=
sizeof
(
int32_t
);
...
...
@@ -47,77 +46,81 @@ static int32_t sdbGetkeySize(ESdbType sdb, void *pKey) {
return
keySize
;
}
static
int32_t
sdbInsertRow
(
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
pRow
->
sdb
];
static
int32_t
sdbInsertRow
(
SSdb
*
pSdb
,
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
int32_t
code
=
0
;
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
taosWLockLatch
(
pLock
);
SSdbRow
*
pDstRow
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
if
(
pDstRow
!=
NULL
)
{
terrno
=
TSDB_CODE_SDB_OBJ_ALREADY_THERE
;
taosWUnLockLatch
(
pLock
);
sdbFreeRow
(
pRow
);
return
-
1
;
return
TSDB_CODE_SDB_OBJ_ALREADY_THERE
;
}
pRow
->
refCount
=
1
;
pRow
->
status
=
pRaw
->
status
;
if
(
taosHashPut
(
hash
,
pRow
->
pObj
,
keySize
,
&
pRow
,
sizeof
(
void
*
))
!=
0
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
taosWUnLockLatch
(
pLock
);
sdbFreeRow
(
pRow
);
return
-
1
;
return
TSDB_CODE_SDB_OBJ_ALREADY_THERE
;
}
taosWUnLockLatch
(
pLock
);
SdbInsertFp
insertFp
=
tsSdb
.
insertFps
[
pRow
->
sdb
];
SdbInsertFp
insertFp
=
pSdb
->
insertFps
[
pRow
->
type
];
if
(
insertFp
!=
NULL
)
{
if
((
*
insertFp
)(
pRow
->
pObj
)
!=
0
)
{
code
=
(
*
insertFp
)(
pSdb
,
pRow
->
pObj
);
if
(
code
!=
0
)
{
taosWLockLatch
(
pLock
);
taosHashRemove
(
hash
,
pRow
->
pObj
,
keySize
);
taosWUnLockLatch
(
pLock
);
sdbFreeRow
(
pRow
);
return
-
1
;
return
code
;
}
}
return
0
;
}
static
int32_t
sdbUpdateRow
(
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
pRow
->
sdb
];
static
int32_t
sdbUpdateRow
(
SSdb
*
pSdb
,
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
int32_t
code
=
0
;
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
taosRLockLatch
(
pLock
);
SSdbRow
**
ppDstRow
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
if
(
ppDstRow
==
NULL
||
*
ppDstRow
==
NULL
)
{
taosRUnLockLatch
(
pLock
);
return
sdbInsertRow
(
hash
,
pRaw
,
pRow
,
keySize
);
return
sdbInsertRow
(
pSdb
,
hash
,
pRaw
,
pRow
,
keySize
);
}
SSdbRow
*
pDstRow
=
*
ppDstRow
;
pRow
->
status
=
pRaw
->
status
;
taosRUnLockLatch
(
pLock
);
SdbUpdateFp
updateFp
=
tsSdb
.
updateFps
[
pRow
->
sdb
];
SdbUpdateFp
updateFp
=
pSdb
->
updateFps
[
pRow
->
type
];
if
(
updateFp
!=
NULL
)
{
(
*
updateFp
)(
pRow
->
pObj
,
pDstRow
->
pObj
);
code
=
(
*
updateFp
)(
pSdb
,
pRow
->
pObj
,
pDstRow
->
pObj
);
}
sdbFreeRow
(
pRow
);
return
0
;
return
code
;
}
static
int32_t
sdbDeleteRow
(
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
pRow
->
sdb
];
static
int32_t
sdbDeleteRow
(
SSdb
*
pSdb
,
SHashObj
*
hash
,
SSdbRaw
*
pRaw
,
SSdbRow
*
pRow
,
int32_t
keySize
)
{
int32_t
code
=
0
;
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
taosWLockLatch
(
pLock
);
SSdbRow
**
ppDstRow
=
taosHashGet
(
hash
,
pRow
->
pObj
,
keySize
);
if
(
ppDstRow
==
NULL
||
*
ppDstRow
==
NULL
)
{
terrno
=
TSDB_CODE_SDB_OBJ_NOT_THERE
;
taosWUnLockLatch
(
pLock
);
sdbFreeRow
(
pRow
);
return
-
1
;
return
TSDB_CODE_SDB_OBJ_NOT_THERE
;
}
SSdbRow
*
pDstRow
=
*
ppDstRow
;
...
...
@@ -125,71 +128,67 @@ static int32_t sdbDeleteRow(SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_
taosHashRemove
(
hash
,
pDstRow
->
pObj
,
keySize
);
taosWUnLockLatch
(
pLock
);
SdbDeleteFp
deleteFp
=
tsSdb
.
deleteFps
[
pDstRow
->
sdb
];
SdbDeleteFp
deleteFp
=
pSdb
->
deleteFps
[
pDstRow
->
type
];
if
(
deleteFp
!=
NULL
)
{
(
void
)(
*
deleteFp
)(
pDstRow
->
pObj
);
code
=
(
*
deleteFp
)(
pSdb
,
pDstRow
->
pObj
);
}
sdbRelease
(
pDstRow
->
pObj
);
sdbRelease
(
p
Sdb
,
p
DstRow
->
pObj
);
sdbFreeRow
(
pRow
);
return
0
;
return
code
;
}
int32_t
sdbWrite
Imp
(
SSdbRaw
*
pRaw
)
{
SHashObj
*
hash
=
sdbGetHash
(
p
Raw
->
sdb
);
if
(
hash
==
NULL
)
return
-
1
;
int32_t
sdbWrite
Raw
(
SSdb
*
pSdb
,
SSdbRaw
*
pRaw
)
{
SHashObj
*
hash
=
sdbGetHash
(
p
Sdb
,
pRaw
->
type
);
if
(
hash
==
NULL
)
return
terrno
;
SdbDecodeFp
decodeFp
=
tsSdb
.
decodeFps
[
pRaw
->
sdb
];
SdbDecodeFp
decodeFp
=
pSdb
->
decodeFps
[
pRaw
->
type
];
SSdbRow
*
pRow
=
(
*
decodeFp
)(
pRaw
);
if
(
pRow
==
NULL
)
{
terrno
=
TSDB_CODE_SDB_INVALID_DATA_CONTENT
;
return
-
1
;
return
terrno
;
}
pRow
->
sdb
=
pRaw
->
sdb
;
pRow
->
type
=
pRaw
->
type
;
int32_t
keySize
=
sdbGetkeySize
(
p
Row
->
sdb
,
pRow
->
pObj
);
int32_t
code
=
-
1
;
int32_t
keySize
=
sdbGetkeySize
(
p
Sdb
,
pRow
->
type
,
pRow
->
pObj
);
int32_t
code
=
TSDB_CODE_SDB_INVALID_ACTION_TYPE
;
switch
(
pRaw
->
status
)
{
case
SDB_STATUS_CREATING
:
code
=
sdbInsertRow
(
hash
,
pRaw
,
pRow
,
keySize
);
code
=
sdbInsertRow
(
pSdb
,
hash
,
pRaw
,
pRow
,
keySize
);
break
;
case
SDB_STATUS_READY
:
case
SDB_STATUS_DROPPING
:
code
=
sdbUpdateRow
(
hash
,
pRaw
,
pRow
,
keySize
);
code
=
sdbUpdateRow
(
pSdb
,
hash
,
pRaw
,
pRow
,
keySize
);
break
;
case
SDB_STATUS_DROPPED
:
code
=
sdbDeleteRow
(
hash
,
pRaw
,
pRow
,
keySize
);
break
;
default:
terrno
=
TSDB_CODE_SDB_INVALID_ACTION_TYPE
;
code
=
sdbDeleteRow
(
pSdb
,
hash
,
pRaw
,
pRow
,
keySize
);
break
;
}
return
code
;
}
int32_t
sdbWrite
(
SSdbRaw
*
pRaw
)
{
int32_t
code
=
sdbWrite
Imp
(
pRaw
);
int32_t
sdbWrite
(
SSdb
*
pSdb
,
SSdb
Raw
*
pRaw
)
{
int32_t
code
=
sdbWrite
Raw
(
pSdb
,
pRaw
);
sdbFreeRaw
(
pRaw
);
return
code
;
}
void
*
sdbAcquire
(
ESdbType
sdb
,
void
*
pKey
)
{
SHashObj
*
hash
=
sdbGetHash
(
sdb
);
void
*
sdbAcquire
(
SSdb
*
pSdb
,
ESdbType
type
,
void
*
pKey
)
{
SHashObj
*
hash
=
sdbGetHash
(
pSdb
,
type
);
if
(
hash
==
NULL
)
return
NULL
;
void
*
pRet
=
NULL
;
int32_t
keySize
=
sdbGetkeySize
(
sdb
,
pKey
);
int32_t
keySize
=
sdbGetkeySize
(
pSdb
,
type
,
pKey
);
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
sdb
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
type
];
taosRLockLatch
(
pLock
);
SSdbRow
**
ppRow
=
taosHashGet
(
hash
,
pKey
,
keySize
);
if
(
ppRow
==
NULL
||
*
ppRow
==
NULL
)
{
terrno
=
TSDB_CODE_SDB_OBJ_NOT_THERE
;
taosRUnLockLatch
(
pLock
);
terrno
=
TSDB_CODE_SDB_OBJ_NOT_THERE
;
return
NULL
;
}
...
...
@@ -214,13 +213,13 @@ void *sdbAcquire(ESdbType sdb, void *pKey) {
return
pRet
;
}
void
sdbRelease
(
void
*
pObj
)
{
void
sdbRelease
(
SSdb
*
pSdb
,
void
*
pObj
)
{
if
(
pObj
==
NULL
)
return
;
SSdbRow
*
pRow
=
(
SSdbRow
*
)((
char
*
)
pObj
-
sizeof
(
SSdbRow
));
if
(
pRow
->
sdb
>=
SDB_MAX
||
pRow
->
sdb
<=
SDB_START
)
return
;
if
(
pRow
->
type
>=
SDB_MAX
||
pRow
->
type
<=
SDB_START
)
return
;
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
pRow
->
sdb
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
taosRLockLatch
(
pLock
);
int32_t
ref
=
atomic_sub_fetch_32
(
&
pRow
->
refCount
,
1
);
...
...
@@ -231,11 +230,11 @@ void sdbRelease(void *pObj) {
taosRUnLockLatch
(
pLock
);
}
void
*
sdbFetch
(
ESdbType
sdb
,
void
*
pIter
,
void
**
ppObj
)
{
SHashObj
*
hash
=
sdbGetHash
(
sdb
);
void
*
sdbFetch
(
SSdb
*
pSdb
,
ESdbType
type
,
void
*
pIter
,
void
**
ppObj
)
{
SHashObj
*
hash
=
sdbGetHash
(
pSdb
,
type
);
if
(
hash
==
NULL
)
return
NULL
;
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
sdb
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
type
];
taosRLockLatch
(
pLock
);
SSdbRow
**
ppRow
=
taosHashIterate
(
hash
,
ppRow
);
...
...
@@ -255,23 +254,23 @@ void *sdbFetch(ESdbType sdb, void *pIter, void **ppObj) {
return
ppRow
;
}
void
sdbCancelFetch
(
void
*
pIter
)
{
void
sdbCancelFetch
(
SSdb
*
pSdb
,
void
*
pIter
)
{
if
(
pIter
==
NULL
)
return
;
SSdbRow
*
pRow
=
*
(
SSdbRow
**
)
pIter
;
SHashObj
*
hash
=
sdbGetHash
(
p
Row
->
sdb
);
SHashObj
*
hash
=
sdbGetHash
(
p
Sdb
,
pRow
->
type
);
if
(
hash
==
NULL
)
return
;
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
pRow
->
sdb
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
pRow
->
type
];
taosRLockLatch
(
pLock
);
taosHashCancelIterate
(
hash
,
pIter
);
taosRUnLockLatch
(
pLock
);
}
int32_t
sdbGetSize
(
ESdbType
sdb
)
{
SHashObj
*
hash
=
sdbGetHash
(
sdb
);
int32_t
sdbGetSize
(
SSdb
*
pSdb
,
ESdbType
type
)
{
SHashObj
*
hash
=
sdbGetHash
(
pSdb
,
type
);
if
(
hash
==
NULL
)
return
0
;
SRWLatch
*
pLock
=
&
tsSdb
.
locks
[
sdb
];
SRWLatch
*
pLock
=
&
pSdb
->
locks
[
type
];
taosRLockLatch
(
pLock
);
int32_t
size
=
taosHashGetSize
(
hash
);
taosRUnLockLatch
(
pLock
);
...
...
source/dnode/mnode/sdb/src/sdbRaw.c
浏览文件 @
81ebcd8b
...
...
@@ -16,14 +16,14 @@
#define _DEFAULT_SOURCE
#include "sdbInt.h"
SSdbRaw
*
sdbAllocRaw
(
ESdbType
sdb
,
int8_t
sver
,
int32_t
dataLen
)
{
SSdbRaw
*
sdbAllocRaw
(
ESdbType
type
,
int8_t
sver
,
int32_t
dataLen
)
{
SSdbRaw
*
pRaw
=
calloc
(
1
,
dataLen
+
sizeof
(
SSdbRaw
));
if
(
pRaw
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
pRaw
->
sdb
=
sdb
;
pRaw
->
type
=
type
;
pRaw
->
sver
=
sver
;
pRaw
->
dataLen
=
dataLen
;
return
pRaw
;
...
...
source/dnode/mnode/sdb/src/sdbRow.c
浏览文件 @
81ebcd8b
...
...
@@ -35,4 +35,4 @@ void *sdbGetRowObj(SSdbRow *pRow) {
return
pRow
->
pObj
;
}
void
sdbFreeRow
(
SSdbRow
*
pRow
)
{
free
(
pRow
);
}
void
sdbFreeRow
(
SSdbRow
*
pRow
)
{
t
free
(
pRow
);
}
source/libs/index/inc/index_fst.h
浏览文件 @
81ebcd8b
...
...
@@ -21,6 +21,7 @@
#include "index_fst_util.h"
#include "index_fst_registry.h"
#include "index_fst_counting_writer.h"
#include "index_fst_automation.h"
typedef
struct
FstNode
FstNode
;
...
...
@@ -34,11 +35,28 @@ typedef struct FstRange {
typedef
enum
{
OneTransNext
,
OneTrans
,
AnyTrans
,
EmptyFinal
}
State
;
typedef
enum
{
Included
,
Excluded
,
Unbounded
}
FstBound
;
typedef
enum
{
Ordered
,
OutOfOrdered
,
DuplicateKey
}
OrderType
;
typedef
enum
{
Included
,
Excluded
,
Unbounded
}
FstBound
;
typedef
struct
FstBoundWithData
{
FstSlice
data
;
FstBound
type
;
}
FstBoundWithData
;
FstBoundWithData
*
fstBoundStateCreate
(
FstBound
type
,
FstSlice
*
data
);
bool
fstBoundWithDataExceededBy
(
FstBoundWithData
*
bound
,
FstSlice
*
slice
);
bool
fstBoundWithDataIsEmpty
(
FstBoundWithData
*
bound
);
bool
fstBoundWithDataIsIncluded
(
FstBoundWithData
*
bound
);
typedef
struct
FstOutput
{
bool
null
;
Output
out
;
}
FstOutput
;
/*
*
...
...
@@ -251,8 +269,40 @@ void fstDestroy(Fst *fst);
bool
fstGet
(
Fst
*
fst
,
FstSlice
*
b
,
Output
*
out
);
FstNode
*
fstGetNode
(
Fst
*
fst
,
CompiledAddr
);
FstNode
*
fstGetRoot
(
Fst
*
fst
);
FstType
fstGetType
(
Fst
*
fst
);
CompiledAddr
fstGetRootAddr
(
Fst
*
fst
);
Output
fstEmptyFinalOutput
(
Fst
*
fst
,
bool
*
null
);
bool
fstVerify
(
Fst
*
fst
);
//refactor this function
bool
fstBuilderNodeCompileTo
(
FstBuilderNode
*
b
,
FstCountingWriter
*
wrt
,
CompiledAddr
lastAddr
,
CompiledAddr
startAddr
);
typedef
struct
StreamState
{
FstNode
*
node
;
uint64_t
trans
;
FstOutput
out
;
void
*
autState
;
}
StreamState
;
typedef
struct
StreamWithState
{
Fst
*
fst
;
Automation
*
aut
;
SArray
*
inp
;
FstOutput
emptyOutput
;
SArray
*
stack
;
// <StreamState>
FstBoundWithData
*
endAt
;
}
StreamWithState
;
typedef
void
*
(
*
StreamCallback
)(
void
*
);
StreamWithState
*
streamWithStateCreate
(
Fst
*
fst
,
Automation
*
automation
,
FstBoundWithData
*
min
,
FstBoundWithData
*
max
)
;
void
streamWithStateDestroy
(
StreamWithState
*
sws
);
bool
streamWithStateSeekMin
(
StreamWithState
*
sws
,
FstBoundWithData
*
min
);
void
*
streamWithStateNextWith
(
StreamWithState
*
sws
,
StreamCallback
callback
);
#endif
source/libs/index/inc/index_fst_automation.h
浏览文件 @
81ebcd8b
...
...
@@ -15,7 +15,7 @@
#ifndef __INDEX_FST_AUTAOMATION_H__
#define __INDEX_FST_AUTAOMATION_H__
struct
AutomationCtx
;
typedef
struct
AutomationCtx
AutomationCtx
;
typedef
struct
StartWith
{
AutomationCtx
*
autoSelf
;
...
...
@@ -23,20 +23,25 @@ typedef struct StartWith {
typedef
struct
Complement
{
AutomationCtx
*
autoSelf
;
}
Complement
;
// automation
typedef
struct
AutomationCtx
{
// automation interface
void
*
data
;
}
AutomationCtx
;
// automation interface
void
(
*
start
)(
AutomationCtx
*
ctx
);
bool
(
*
isMatch
)(
AutomationCtx
*
ctx
);
bool
(
*
canMatch
)(
AutomationCtx
*
ctx
,
void
*
data
);
bool
(
*
willAlwaysMatch
)(
AutomationCtx
*
ctx
,
void
*
state
);
void
*
(
*
accpet
)(
AutomationCtx
*
ctx
,
void
*
state
,
uint8_t
byte
);
void
*
(
*
accpetEof
)(
AutomationCtx
*
ctx
,
*
state
);
typedef
struct
Automation
{
void
*
(
*
start
)()
;
bool
(
*
isMatch
)();
bool
(
*
canMatch
)(
void
*
data
);
bool
(
*
willAlwaysMatch
)(
void
*
state
);
void
*
(
*
accpet
)(
void
*
state
,
uint8_t
byte
);
void
*
(
*
accpetEof
)(
void
*
state
);
void
*
data
;
}
Automation
;
#endif
source/libs/index/inc/index_fst_node.h
浏览文件 @
81ebcd8b
...
...
@@ -41,7 +41,7 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src);
void
fstBuilderNodeCloneFrom
(
FstBuilderNode
*
dst
,
FstBuilderNode
*
src
);
bool
fstBuilderNodeCompileTo
(
FstBuilderNode
*
b
,
FstCountingWriter
*
wrt
,
CompiledAddr
lastAddr
,
CompiledAddr
startAddr
);
//
bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr);
void
fstBuilderNodeDestroy
(
FstBuilderNode
*
node
);
...
...
source/libs/index/src/index_fst.c
浏览文件 @
81ebcd8b
...
...
@@ -733,6 +733,11 @@ bool fstNodeCompile(FstNode *node, void *w, CompiledAddr lastAddr, CompiledAddr
return
true
;
}
bool
fstBuilderNodeCompileTo
(
FstBuilderNode
*
b
,
FstCountingWriter
*
wrt
,
CompiledAddr
lastAddr
,
CompiledAddr
startAddr
)
{
return
fstNodeCompile
(
NULL
,
wrt
,
lastAddr
,
startAddr
,
b
);
}
FstBuilder
*
fstBuilderCreate
(
void
*
w
,
FstType
ty
)
{
FstBuilder
*
b
=
malloc
(
sizeof
(
FstBuilder
));
...
...
@@ -985,15 +990,39 @@ void fstDestroy(Fst *fst) {
}
bool
fstGet
(
Fst
*
fst
,
FstSlice
*
b
,
Output
*
out
)
{
FstNode
*
root
=
fstGetRoot
(
fst
);
Output
tOut
=
0
;
for
(
uint32_t
i
=
0
;
i
<
b
->
dLen
;
i
++
)
{
uint8_t
inp
=
b
->
data
[
i
];
Output
res
=
0
;
bool
null
=
fstNodeFindInput
(
root
,
inp
,
&
res
);
if
(
null
)
{
return
false
;
}
FstTransition
trn
;
fstNodeGetTransitionAt
(
root
,
res
,
&
trn
);
tOut
+=
trn
.
out
;
root
=
fstGetNode
(
fst
,
trn
.
addr
);
}
if
(
!
FST_NODE_IS_FINAL
(
root
))
{
return
false
;
}
else
{
tOut
=
tOut
+
FST_NODE_FINAL_OUTPUT
(
root
);
}
*
out
=
tOut
;
return
false
;
}
FstNode
*
fstGetRoot
(
Fst
*
fst
)
{
CompiledAddr
root
=
fstGetRootAddr
(
fst
);
return
fstGetNode
(
fst
,
root
);
}
FstNode
*
fstGetNode
(
Fst
*
fst
,
CompiledAddr
addr
)
{
if
(
fst
->
root
!=
NULL
)
{
return
fst
->
root
;
}
fst
->
root
=
fstNodeCreate
(
fst
->
meta
->
version
,
addr
,
fst
->
data
);
return
fst
->
root
;
}
...
...
@@ -1016,15 +1045,168 @@ Output fstEmptyFinalOutput(Fst *fst, bool *null) {
return
res
;
}
bool
fstVerify
(
Fst
*
fst
)
{
uint32_t
checkSum
=
fst
->
meta
->
checkSum
;
FstSlice
*
data
=
fst
->
data
;
TSCKSUM
initSum
=
0
;
if
(
taosCheckChecksumWhole
(
data
->
data
,
data
->
dLen
))
{
if
(
!
taosCheckChecksumWhole
(
data
->
data
,
data
->
dLen
))
{
return
false
;
}
return
true
;
}
// data bound function
FstBoundWithData
*
fstBoundStateCreate
(
FstBound
type
,
FstSlice
*
data
)
{
FstBoundWithData
*
b
=
calloc
(
1
,
sizeof
(
FstBoundWithData
));
if
(
b
==
NULL
)
{
return
NULL
;
}
b
->
type
=
type
;
b
->
data
=
fstSliceCopy
(
data
,
data
->
start
,
data
->
end
);
return
b
;
}
bool
fstBoundWithDataExceededBy
(
FstBoundWithData
*
bound
,
FstSlice
*
slice
)
{
int
comp
=
fstSliceCompare
(
slice
,
&
bound
->
data
);
if
(
bound
->
type
==
Included
)
{
return
comp
>
0
?
true
:
false
;
}
else
if
(
bound
->
type
==
Excluded
)
{
return
comp
>=
0
?
true
:
false
;
}
else
{
return
true
;
}
}
bool
fstBoundWithDataIsEmpty
(
FstBoundWithData
*
bound
)
{
if
(
bound
->
type
==
Unbounded
)
{
return
true
;
}
else
{
return
fstSliceEmpty
(
&
bound
->
data
);
}
}
bool
fstBoundWithDataIsIncluded
(
FstBoundWithData
*
bound
)
{
return
bound
->
type
==
Included
?
true
:
false
;
}
void
fstBoundDestroy
(
FstBoundWithData
*
bound
)
{
free
(
bound
);
}
StreamWithState
*
streamWithStateCreate
(
Fst
*
fst
,
Automation
*
automation
,
FstBoundWithData
*
min
,
FstBoundWithData
*
max
)
{
StreamWithState
*
sws
=
calloc
(
1
,
sizeof
(
StreamWithState
));
if
(
sws
==
NULL
)
{
return
NULL
;
}
sws
->
fst
=
fst
;
sws
->
aut
=
automation
;
sws
->
inp
=
(
SArray
*
)
taosArrayInit
(
256
,
sizeof
(
uint8_t
));
sws
->
emptyOutput
.
null
=
false
;
sws
->
emptyOutput
.
out
=
0
;
sws
->
stack
=
(
SArray
*
)
taosArrayInit
(
256
,
sizeof
(
StreamState
));
sws
->
endAt
=
max
;
streamWithStateSeekMin
(
sws
,
min
);
return
sws
;
}
void
streamWithStateDestroy
(
StreamWithState
*
sws
)
{
if
(
sws
==
NULL
)
{
return
;
}
taosArrayDestroy
(
sws
->
inp
);
taosArrayDestroy
(
sws
->
stack
);
free
(
sws
);
}
bool
streamWithStateSeekMin
(
StreamWithState
*
sws
,
FstBoundWithData
*
min
)
{
if
(
fstBoundWithDataIsEmpty
(
min
))
{
if
(
fstBoundWithDataIsIncluded
(
min
))
{
sws
->
emptyOutput
.
out
=
fstEmptyFinalOutput
(
sws
->
fst
,
&
(
sws
->
emptyOutput
.
null
));
}
StreamState
s
=
{.
node
=
fstGetRoot
(
sws
->
fst
),
.
trans
=
0
,
.
out
=
{.
null
=
false
,
.
out
=
0
},
.
autState
=
sws
->
aut
->
start
()};
// auto.start callback
taosArrayPush
(
sws
->
stack
,
&
s
);
return
true
;
}
FstSlice
*
key
=
NULL
;
bool
inclusize
=
false
;;
if
(
min
->
type
==
Included
)
{
key
=
&
min
->
data
;
inclusize
=
true
;
}
else
if
(
min
->
type
==
Excluded
)
{
key
=
&
min
->
data
;
}
else
{
return
false
;
}
FstNode
*
node
=
fstGetRoot
(
sws
->
fst
);
Output
out
=
0
;
void
*
autState
=
sws
->
aut
->
start
();
for
(
uint32_t
i
=
0
;
i
<
key
->
dLen
;
i
++
)
{
uint8_t
b
=
key
->
data
[
i
];
uint64_t
res
=
0
;
bool
null
=
fstNodeFindInput
(
node
,
b
,
&
res
);
if
(
null
==
false
)
{
FstTransition
trn
;
fstNodeGetTransitionAt
(
node
,
res
,
&
trn
);
void
*
preState
=
autState
;
autState
=
sws
->
aut
->
accpet
(
preState
,
b
);
taosArrayPush
(
sws
->
inp
,
&
b
);
StreamState
s
=
{.
node
=
node
,
.
trans
=
res
+
1
,
.
out
=
{.
null
=
false
,
.
out
=
out
},
.
autState
=
preState
};
taosArrayPush
(
sws
->
stack
,
&
s
);
out
+=
trn
.
out
;
node
=
fstGetNode
(
sws
->
fst
,
trn
.
addr
);
}
else
{
// This is a little tricky. We're in this case if the
// given bound is not a prefix of any key in the FST.
// Since this is a minimum bound, we need to find the
// first transition in this node that proceeds the current
// input byte.
FstTransitions
*
trans
=
fstNodeTransitions
(
node
);
uint64_t
i
=
0
;
for
(
i
=
trans
->
range
.
start
;
i
<
trans
->
range
.
end
;
i
++
)
{
FstTransition
trn
;
if
(
fstNodeGetTransitionAt
(
node
,
i
,
&
trn
)
&&
trn
.
inp
>
b
)
{
break
;
}
}
StreamState
s
=
{.
node
=
node
,
.
trans
=
i
,
.
out
=
{.
null
=
false
,
.
out
=
out
},
.
autState
=
autState
};
taosArrayPush
(
sws
->
stack
,
&
s
);
return
true
;
}
}
uint32_t
sz
=
taosArrayGetSize
(
sws
->
stack
);
if
(
sz
!=
0
)
{
StreamState
*
s
=
taosArrayGet
(
sws
->
stack
,
sz
-
1
);
if
(
inclusize
)
{
s
->
trans
-=
1
;
taosArrayPop
(
sws
->
inp
);
}
else
{
FstNode
*
n
=
s
->
node
;
uint64_t
trans
=
s
->
trans
;
FstTransition
trn
;
fstNodeGetTransitionAt
(
n
,
trans
-
1
,
&
trn
);
StreamState
s
=
{.
node
=
fstGetNode
(
sws
->
fst
,
trn
.
addr
),
.
trans
=
0
,
.
out
=
{.
null
=
false
,
.
out
=
out
},
.
autState
=
autState
};
taosArrayPush
(
sws
->
stack
,
&
s
);
return
true
;
}
return
false
;
}
}
source/libs/index/src/index_fst_node.c
浏览文件 @
81ebcd8b
...
...
@@ -59,26 +59,27 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src) {
src
->
trans
=
NULL
;
}
bool
fstBuilderNodeCompileTo
(
FstBuilderNode
*
b
,
FstCountingWriter
*
wrt
,
CompiledAddr
lastAddr
,
CompiledAddr
startAddr
)
{
size_t
sz
=
taosArrayGetSize
(
b
->
trans
);
assert
(
sz
<
256
);
if
(
FST_BUILDER_NODE_IS_FINAL
(
b
)
&&
FST_BUILDER_NODE_TRANS_ISEMPTY
(
b
)
&&
FST_BUILDER_NODE_FINALOUTPUT_ISZERO
(
b
))
{
return
true
;
}
else
if
(
sz
!=
1
||
b
->
isFinal
)
{
// AnyTrans->Compile(w, addr, node);
}
else
{
FstTransition
*
tran
=
taosArrayGet
(
b
->
trans
,
0
);
if
(
tran
->
addr
==
lastAddr
&&
tran
->
out
==
0
)
{
//OneTransNext::compile(w, lastAddr, tran->inp);
return
true
;
}
else
{
//OneTrans::Compile(w, lastAddr, *tran);
return
true
;
}
}
return
true
;
}
//bool fstBuilderNodeCompileTo(FstBuilderNode *b, FstCountingWriter *wrt, CompiledAddr lastAddr, CompiledAddr startAddr) {
//size_t sz = taosArrayGetSize(b->trans);
//assert(sz < 256);
//if (FST_BUILDER_NODE_IS_FINAL(b)
// && FST_BUILDER_NODE_TRANS_ISEMPTY(b)
// && FST_BUILDER_NODE_FINALOUTPUT_ISZERO(b)) {
// return true;
//} else if (sz != 1 || b->isFinal) {
// // AnyTrans->Compile(w, addr, node);
//} else {
// FstTransition *tran = taosArrayGet(b->trans, 0);
// if (tran->addr == lastAddr && tran->out == 0) {
// //OneTransNext::compile(w, lastAddr, tran->inp);
// return true;
// } else {
// //OneTrans::Compile(w, lastAddr, *tran);
// return true;
// }
//}
//return true;
//}
source/libs/index/src/index_fst_util.c
浏览文件 @
81ebcd8b
...
...
@@ -95,6 +95,7 @@ FstSlice fstSliceCreate(uint8_t *data, uint64_t dLen) {
FstSlice
slice
=
{.
data
=
data
,
.
dLen
=
dLen
,
.
start
=
0
,
.
end
=
dLen
-
1
};
return
slice
;
}
// just shallow copy
FstSlice
fstSliceCopy
(
FstSlice
*
slice
,
int32_t
start
,
int32_t
end
)
{
FstSlice
t
;
if
(
start
>=
slice
->
dLen
||
end
>=
slice
->
dLen
||
start
>
end
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录