Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
loser646
TDengine
提交
3006a756
T
TDengine
项目概览
loser646
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3006a756
编写于
3月 11, 2020
作者:
S
slguan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor dnode module code
上级
46c31a24
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
377 addition
and
456 deletion
+377
-456
src/dnode/inc/dnodeModule.h
src/dnode/inc/dnodeModule.h
+2
-2
src/dnode/inc/dnodeRead.h
src/dnode/inc/dnodeRead.h
+1
-1
src/dnode/inc/dnodeSystem.h
src/dnode/inc/dnodeSystem.h
+0
-37
src/dnode/inc/dnodeWrite.h
src/dnode/inc/dnodeWrite.h
+1
-1
src/dnode/src/dnodeMClient.c
src/dnode/src/dnodeMClient.c
+1
-1
src/dnode/src/dnodeMain.c
src/dnode/src/dnodeMain.c
+260
-0
src/dnode/src/dnodeMgmt.c
src/dnode/src/dnodeMgmt.c
+95
-94
src/dnode/src/dnodeMnode.c
src/dnode/src/dnodeMnode.c
+1
-1
src/dnode/src/dnodeModule.c
src/dnode/src/dnodeModule.c
+5
-5
src/dnode/src/dnodeRead.c
src/dnode/src/dnodeRead.c
+1
-3
src/dnode/src/dnodeShell.c
src/dnode/src/dnodeShell.c
+1
-1
src/dnode/src/dnodeSystem.c
src/dnode/src/dnodeSystem.c
+0
-280
src/dnode/src/dnodeWrite.c
src/dnode/src/dnodeWrite.c
+1
-3
src/inc/dnode.h
src/inc/dnode.h
+7
-26
src/mnode/src/mgmtShell.c
src/mnode/src/mgmtShell.c
+1
-1
未找到文件。
src/dnode/inc/dnodeModule.h
浏览文件 @
3006a756
...
...
@@ -20,9 +20,9 @@
extern
"C"
{
#endif
void
dnodeAllocModules
();
int32_t
dnodeInitModules
();
void
dnodeCleanUpModules
();
void
dnodeStartModules
();
#ifdef __cplusplus
}
...
...
src/dnode/inc/dnodeRead.h
浏览文件 @
3006a756
...
...
@@ -22,7 +22,7 @@ extern "C" {
int32_t
dnodeInitRead
();
void
dnodeCleanupRead
();
void
dnodeRead
(
void
*
pMsg
);
void
dnodeRead
(
SRpcMsg
*
pMsg
);
void
*
dnodeAllocateReadWorker
();
void
dnodeFreeReadWorker
(
void
*
rqueue
);
...
...
src/dnode/inc/dnodeSystem.h
已删除
100644 → 0
浏览文件 @
46c31a24
/*
* 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 TDENGINE_DNODE_SYSTEM_H
#define TDENGINE_DNODE_SYSTEM_H
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
enum
{
TSDB_DNODE_RUN_STATUS_INITIALIZE
,
TSDB_DNODE_RUN_STATUS_RUNING
,
TSDB_DNODE_RUN_STATUS_STOPPED
}
SDnodeRunStatus
;
int32_t
dnodeInitSystem
();
void
dnodeCleanUpSystem
();
SDnodeRunStatus
dnodeGetRunStatus
();
#ifdef __cplusplus
}
#endif
#endif
src/dnode/inc/dnodeWrite.h
浏览文件 @
3006a756
...
...
@@ -22,7 +22,7 @@ extern "C" {
int32_t
dnodeInitWrite
();
void
dnodeCleanupWrite
();
void
dnodeWrite
(
void
*
pMsg
);
void
dnodeWrite
(
SRpcMsg
*
pMsg
);
void
*
dnodeAllocateWriteWorker
();
void
dnodeFreeWriteWorker
(
void
*
worker
);
...
...
src/dnode/src/dnodeMClient.c
浏览文件 @
3006a756
...
...
@@ -18,7 +18,7 @@
#include "taosmsg.h"
#include "tlog.h"
#include "trpc.h"
#include "dnode
System
.h"
#include "dnode.h"
static
void
(
*
dnodeProcessMgmtRspFp
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
);
static
void
dnodeProcessRspFromMnode
(
SRpcMsg
*
pMsg
);
...
...
src/dnode/src/dnode
Service
.c
→
src/dnode/src/dnode
Main
.c
浏览文件 @
3006a756
...
...
@@ -15,41 +15,46 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "tlog.h"
#include "tglobalcfg.h"
#include "dnodeSystem.h"
#include "tlog.h"
#include "tmodule.h"
#include "trpc.h"
#include "tutil.h"
#include "dnode.h"
#include "dnodeMClient.h"
#include "dnodeMgmt.h"
#include "dnodeMnode.h"
#include "dnodeModule.h"
#include "dnodeRead.h"
#include "dnodeShell.h"
#include "dnodeWrite.h"
#ifdef CLUSTER
#include "account.h"
#include "admin.h"
#include "balance.h"
#include "cluster.h"
#include "grant.h"
#include "mpeer.h"
#include "storage.h"
#include "vpeer.h"
#endif
static
int32_t
dnodeInitSystem
();
static
int32_t
dnodeInitStorage
();
static
void
dnodeInitPlugins
();
static
void
dnodeCleanupStorage
();
static
void
dnodeCleanUpSystem
();
static
void
dnodeSetRunStatus
(
SDnodeRunStatus
status
);
static
void
signal_handler
(
int32_t
signum
,
siginfo_t
*
sigInfo
,
void
*
context
);
static
void
dnodeCheckDataDirOpenned
(
char
*
dir
);
static
SDnodeRunStatus
tsDnodeRunStatus
=
TSDB_DNODE_RUN_STATUS_STOPPED
;
void
(
*
dnodeParseParameterKFp
)()
=
NULL
;
/*
* Termination handler
*/
void
signal_handler
(
int
signum
,
siginfo_t
*
sigInfo
,
void
*
context
)
{
if
(
signum
==
SIGUSR1
)
{
tsCfgDynamicOptions
(
"debugFlag 135"
);
return
;
}
if
(
signum
==
SIGUSR2
)
{
tsCfgDynamicOptions
(
"resetlog"
);
return
;
}
syslog
(
LOG_INFO
,
"Shut down signal is %d"
,
signum
);
syslog
(
LOG_INFO
,
"Shutting down TDengine service..."
);
// clean the system.
dPrint
(
"shut down signal is %d, sender PID:%d"
,
signum
,
sigInfo
->
si_pid
);
dnodeCleanUpSystem
();
// close the syslog
syslog
(
LOG_INFO
,
"Shut down TDengine service successfully"
);
dPrint
(
"TDengine is shut down!"
);
closelog
();
exit
(
EXIT_SUCCESS
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int32_t
main
(
int32_t
argc
,
char
*
argv
[])
{
dnodeInitPlugins
();
// Set global configuration file
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
for
(
int
32_t
i
=
1
;
i
<
argc
;
++
i
)
{
if
(
strcmp
(
argv
[
i
],
"-c"
)
==
0
)
{
if
(
i
<
argc
-
1
)
{
strcpy
(
configDir
,
argv
[
++
i
]);
...
...
@@ -63,10 +68,11 @@ int main(int argc, char *argv[]) {
printf
(
"gitinfo: %s
\n
"
,
gitinfo
);
printf
(
"gitinfoI: %s
\n
"
,
gitinfoOfInternal
);
printf
(
"buildinfo: %s
\n
"
,
buildinfo
);
return
0
;
exit
(
EXIT_SUCCESS
)
;
}
else
if
(
strcmp
(
argv
[
i
],
"-k"
)
==
0
)
{
if
(
dnodeParseParameterKFp
)
{
dnodeParseParameterKFp
();
exit
(
EXIT_SUCCESS
);
}
#ifdef TAOS_MEM_CHECK
}
else
if
(
strcmp
(
argv
[
i
],
"--alloc-random-fail"
)
==
0
)
{
...
...
@@ -94,7 +100,6 @@ int main(int argc, char *argv[]) {
sigaction
(
SIGINT
,
&
act
,
NULL
);
sigaction
(
SIGUSR1
,
&
act
,
NULL
);
sigaction
(
SIGUSR2
,
&
act
,
NULL
);
// sigaction(SIGABRT, &act, NULL);
// Open /var/log/syslog file to record information.
openlog
(
"TDengine:"
,
LOG_PID
|
LOG_CONS
|
LOG_NDELAY
,
LOG_LOCAL1
);
...
...
@@ -116,4 +121,140 @@ int main(int argc, char *argv[]) {
}
}
static
void
signal_handler
(
int32_t
signum
,
siginfo_t
*
sigInfo
,
void
*
context
)
{
if
(
signum
==
SIGUSR1
)
{
tsCfgDynamicOptions
(
"debugFlag 135"
);
return
;
}
if
(
signum
==
SIGUSR2
)
{
tsCfgDynamicOptions
(
"resetlog"
);
return
;
}
syslog
(
LOG_INFO
,
"Shut down signal is %d"
,
signum
);
syslog
(
LOG_INFO
,
"Shutting down TDengine service..."
);
// clean the system.
dPrint
(
"shut down signal is %d, sender PID:%d"
,
signum
,
sigInfo
->
si_pid
);
dnodeCleanUpSystem
();
// close the syslog
syslog
(
LOG_INFO
,
"Shut down TDengine service successfully"
);
dPrint
(
"TDengine is shut down!"
);
closelog
();
exit
(
EXIT_SUCCESS
);
}
static
int32_t
dnodeInitSystem
()
{
dnodeSetRunStatus
(
TSDB_DNODE_RUN_STATUS_INITIALIZE
);
tscEmbedded
=
1
;
taosResolveCRC
();
tsReadGlobalLogConfig
();
taosSetCoreDump
();
signal
(
SIGPIPE
,
SIG_IGN
);
struct
stat
dirstat
;
if
(
stat
(
logDir
,
&
dirstat
)
<
0
)
{
mkdir
(
logDir
,
0755
);
}
char
temp
[
TSDB_FILENAME_LEN
];
sprintf
(
temp
,
"%s/taosdlog"
,
logDir
);
if
(
taosInitLog
(
temp
,
tsNumOfLogLines
,
1
)
<
0
)
{
printf
(
"failed to init log file
\n
"
);
}
if
(
!
tsReadGlobalConfig
())
{
tsPrintGlobalConfig
();
dError
(
"TDengine read global config failed"
);
return
-
1
;
}
tsPrintGlobalConfig
();
dPrint
(
"Server IP address is:%s"
,
tsPrivateIp
);
dPrint
(
"starting to initialize TDengine ..."
);
if
(
dnodeInitStorage
()
!=
0
)
return
-
1
;
if
(
dnodeInitModules
()
!=
0
)
return
-
1
;
if
(
dnodeInitRead
()
!=
0
)
return
-
1
;
if
(
dnodeInitWrite
()
!=
0
)
return
-
1
;
if
(
dnodeInitMgmt
()
!=
0
)
return
-
1
;
if
(
dnodeInitMnode
()
!=
0
)
return
-
1
;
if
(
dnodeInitMClient
()
!=
0
)
return
-
1
;
if
(
dnodeInitShell
()
!=
0
)
return
-
1
;
dnodeStartModules
();
dnodeSetRunStatus
(
TSDB_DNODE_RUN_STATUS_RUNING
);
dPrint
(
"TDengine is initialized successfully"
);
return
0
;
}
static
void
dnodeCleanUpSystem
()
{
if
(
dnodeGetRunStatus
()
!=
TSDB_DNODE_RUN_STATUS_STOPPED
)
{
tclearModuleStatus
(
TSDB_MOD_MGMT
);
dnodeSetRunStatus
(
TSDB_DNODE_RUN_STATUS_STOPPED
);
dnodeCleanupShell
();
dnodeCleanupMClient
();
dnodeCleanupMnode
();
dnodeCleanupMgmt
();
dnodeCleanupWrite
();
dnodeCleanupRead
();
dnodeCleanUpModules
();
dnodeCleanupStorage
();
taosCloseLogger
();
}
}
SDnodeRunStatus
dnodeGetRunStatus
()
{
return
tsDnodeRunStatus
;
}
static
void
dnodeSetRunStatus
(
SDnodeRunStatus
status
)
{
tsDnodeRunStatus
=
status
;
}
static
void
dnodeCheckDataDirOpenned
(
char
*
dir
)
{
char
filepath
[
256
]
=
{
0
};
sprintf
(
filepath
,
"%s/.running"
,
dir
);
int32_t
fd
=
open
(
filepath
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
int32_t
ret
=
flock
(
fd
,
LOCK_EX
|
LOCK_NB
);
if
(
ret
!=
0
)
{
dError
(
"failed to lock file:%s ret:%d, database may be running, quit"
,
filepath
,
ret
);
exit
(
0
);
}
}
static
int32_t
dnodeInitStorage
()
{
struct
stat
dirstat
;
strcpy
(
tsDirectory
,
dataDir
);
if
(
stat
(
dataDir
,
&
dirstat
)
<
0
)
{
mkdir
(
dataDir
,
0755
);
}
char
fileName
[
128
];
sprintf
(
fileName
,
"%s/tsdb"
,
tsDirectory
);
mkdir
(
fileName
,
0755
);
sprintf
(
fileName
,
"%s/data"
,
tsDirectory
);
mkdir
(
fileName
,
0755
);
sprintf
(
tsMgmtDirectory
,
"%s/mgmt"
,
tsDirectory
);
sprintf
(
tsDirectory
,
"%s/tsdb"
,
dataDir
);
dnodeCheckDataDirOpenned
(
dataDir
);
dPrint
(
"storage directory is initialized"
);
return
0
;
}
static
void
dnodeCleanupStorage
()
{}
static
void
dnodeInitPlugins
()
{
#ifdef CLUSTER
// acctInit();
// adminInit();
// balanceInit();
// clusterInit();
// grantInit();
// mpeerInit();
// storageInit();
#endif
}
src/dnode/src/dnodeMgmt.c
浏览文件 @
3006a756
...
...
@@ -21,7 +21,7 @@
#include "tlog.h"
#include "trpc.h"
#include "tstatus.h"
#include "tsdb.h"
//
#include "tsdb.h"
#include "dnodeMgmt.h"
#include "dnodeRead.h"
#include "dnodeWrite.h"
...
...
@@ -60,7 +60,8 @@ int32_t dnodeInitMgmt() {
tsDnodeVnodesHash
=
taosInitIntHash
(
TSDB_MAX_VNODES
,
sizeof
(
SVnodeObj
),
taosHashInt
);
if
(
tsDnodeVnodesHash
==
NULL
)
{
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
dError
(
"failed to init vnode list"
);
return
-
1
;
}
return
dnodeOpenVnodes
();
...
...
@@ -139,111 +140,111 @@ static void dnodeCleanupVnodes() {
}
static
int32_t
dnodeOpenVnode
(
int32_t
vgId
)
{
char
rootDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
sprintf
(
rootDir
,
"%s/vnode%d"
,
tsDirectory
,
vgId
);
void
*
pTsdb
=
tsdbOpenRepo
(
rootDir
);
if
(
pTsdb
!=
NULL
)
{
return
terrno
;
}
SVnodeObj
vnodeObj
;
vnodeObj
.
vgId
=
vgId
;
vnodeObj
.
status
=
TSDB_VN_STATUS_NOT_READY
;
vnodeObj
.
refCount
=
1
;
vnodeObj
.
version
=
0
;
vnodeObj
.
wworker
=
dnodeAllocateWriteWorker
();
vnodeObj
.
rworker
=
dnodeAllocateReadWorker
();
vnodeObj
.
wal
=
NULL
;
vnodeObj
.
tsdb
=
pTsdb
;
vnodeObj
.
replica
=
NULL
;
vnodeObj
.
events
=
NULL
;
vnodeObj
.
cq
=
NULL
;
taosAddIntHash
(
tsDnodeVnodesHash
,
vnodeObj
.
vgId
,
&
vnodeObj
);
//
char rootDir[TSDB_FILENAME_LEN] = {0};
//
sprintf(rootDir, "%s/vnode%d", tsDirectory, vgId);
//
//
void *pTsdb = tsdbOpenRepo(rootDir);
//
if (pTsdb != NULL) {
//
return terrno;
//
}
//
//
SVnodeObj vnodeObj;
//
vnodeObj.vgId = vgId;
//
vnodeObj.status = TSDB_VN_STATUS_NOT_READY;
//
vnodeObj.refCount = 1;
//
vnodeObj.version = 0;
//
vnodeObj.wworker = dnodeAllocateWriteWorker();
//
vnodeObj.rworker = dnodeAllocateReadWorker();
//
vnodeObj.wal = NULL;
//
vnodeObj.tsdb = pTsdb;
//
vnodeObj.replica = NULL;
//
vnodeObj.events = NULL;
//
vnodeObj.cq = NULL;
//
//
taosAddIntHash(tsDnodeVnodesHash, vnodeObj.vgId, &vnodeObj);
return
TSDB_CODE_SUCCESS
;
}
static
void
dnodeCleanupVnode
(
SVnodeObj
*
pVnode
)
{
pVnode
->
status
=
TSDB_VN_STATUS_NOT_READY
;
int32_t
count
=
atomic_sub_fetch_32
(
&
pVnode
->
refCount
,
1
);
if
(
count
>
0
)
{
// wait refcount
}
// remove replica
// remove read queue
dnodeFreeReadWorker
(
pVnode
->
rworker
);
pVnode
->
rworker
=
NULL
;
// remove write queue
dnodeFreeWriteWorker
(
pVnode
->
wworker
);
pVnode
->
wworker
=
NULL
;
// remove wal
// remove tsdb
if
(
pVnode
->
tsdb
)
{
tsdbCloseRepo
(
pVnode
->
tsdb
);
pVnode
->
tsdb
=
NULL
;
}
taosDeleteIntHash
(
tsDnodeVnodesHash
,
pVnode
->
vgId
);
//
pVnode->status = TSDB_VN_STATUS_NOT_READY;
//
int32_t count = atomic_sub_fetch_32(&pVnode->refCount, 1);
//
if (count > 0) {
//
// wait refcount
//
}
//
//
// remove replica
//
//
// remove read queue
//
dnodeFreeReadWorker(pVnode->rworker);
//
pVnode->rworker = NULL;
//
//
// remove write queue
//
dnodeFreeWriteWorker(pVnode->wworker);
//
pVnode->wworker = NULL;
//
//
// remove wal
//
//
// remove tsdb
//
if (pVnode->tsdb) {
//
tsdbCloseRepo(pVnode->tsdb);
//
pVnode->tsdb = NULL;
//
}
//
//
taosDeleteIntHash(tsDnodeVnodesHash, pVnode->vgId);
}
static
int32_t
dnodeCreateVnode
(
SMDCreateVnodeMsg
*
pVnodeCfg
)
{
STsdbCfg
tsdbCfg
;
tsdbCfg
.
precision
=
pVnodeCfg
->
cfg
.
precision
;
tsdbCfg
.
tsdbId
=
pVnodeCfg
->
vnode
;
tsdbCfg
.
maxTables
=
pVnodeCfg
->
cfg
.
maxSessions
;
tsdbCfg
.
daysPerFile
=
pVnodeCfg
->
cfg
.
daysPerFile
;
tsdbCfg
.
minRowsPerFileBlock
=
-
1
;
tsdbCfg
.
maxRowsPerFileBlock
=
-
1
;
tsdbCfg
.
keep
=
-
1
;
tsdbCfg
.
maxCacheSize
=
-
1
;
char
rootDir
[
TSDB_FILENAME_LEN
]
=
{
0
};
sprintf
(
rootDir
,
"%s/vnode%d"
,
tsDirectory
,
pVnodeCfg
->
cfg
.
vgId
);
void
*
pTsdb
=
tsdbCreateRepo
(
rootDir
,
&
tsdbCfg
,
NULL
);
if
(
pTsdb
!=
NULL
)
{
return
terrno
;
}
SVnodeObj
vnodeObj
;
vnodeObj
.
vgId
=
pVnodeCfg
->
cfg
.
vgId
;
vnodeObj
.
status
=
TSDB_VN_STATUS_NOT_READY
;
vnodeObj
.
refCount
=
1
;
vnodeObj
.
version
=
0
;
vnodeObj
.
wworker
=
dnodeAllocateWriteWorker
();
vnodeObj
.
rworker
=
dnodeAllocateReadWorker
();
vnodeObj
.
wal
=
NULL
;
vnodeObj
.
tsdb
=
pTsdb
;
vnodeObj
.
replica
=
NULL
;
vnodeObj
.
events
=
NULL
;
vnodeObj
.
cq
=
NULL
;
taosAddIntHash
(
tsDnodeVnodesHash
,
vnodeObj
.
vgId
,
&
vnodeObj
);
//
STsdbCfg tsdbCfg;
//
tsdbCfg.precision = pVnodeCfg->cfg.precision;
//
tsdbCfg.tsdbId = pVnodeCfg->vnode;
//
tsdbCfg.maxTables = pVnodeCfg->cfg.maxSessions;
//
tsdbCfg.daysPerFile = pVnodeCfg->cfg.daysPerFile;
//
tsdbCfg.minRowsPerFileBlock = -1;
//
tsdbCfg.maxRowsPerFileBlock = -1;
//
tsdbCfg.keep = -1;
//
tsdbCfg.maxCacheSize = -1;
//
char rootDir[TSDB_FILENAME_LEN] = {0};
//
sprintf(rootDir, "%s/vnode%d", tsDirectory, pVnodeCfg->cfg.vgId);
//
//
void *pTsdb = tsdbCreateRepo(rootDir, &tsdbCfg, NULL);
//
if (pTsdb != NULL) {
//
return terrno;
//
}
//
//
SVnodeObj vnodeObj;
//
vnodeObj.vgId = pVnodeCfg->cfg.vgId;
//
vnodeObj.status = TSDB_VN_STATUS_NOT_READY;
//
vnodeObj.refCount = 1;
//
vnodeObj.version = 0;
//
vnodeObj.wworker = dnodeAllocateWriteWorker();
//
vnodeObj.rworker = dnodeAllocateReadWorker();
//
vnodeObj.wal = NULL;
//
vnodeObj.tsdb = pTsdb;
//
vnodeObj.replica = NULL;
//
vnodeObj.events = NULL;
//
vnodeObj.cq = NULL;
//
//
taosAddIntHash(tsDnodeVnodesHash, vnodeObj.vgId, &vnodeObj);
return
TSDB_CODE_SUCCESS
;
}
static
void
dnodeDropVnode
(
SVnodeObj
*
pVnode
)
{
pVnode
->
status
=
TSDB_VN_STATUS_NOT_READY
;
int32_t
count
=
atomic_sub_fetch_32
(
&
pVnode
->
refCount
,
1
);
if
(
count
>
0
)
{
// wait refcount
}
if
(
pVnode
->
tsdb
)
{
tsdbDropRepo
(
pVnode
->
tsdb
);
pVnode
->
tsdb
=
NULL
;
}
dnodeCleanupVnode
(
pVnode
);
//
pVnode->status = TSDB_VN_STATUS_NOT_READY;
//
//
int32_t count = atomic_sub_fetch_32(&pVnode->refCount, 1);
//
if (count > 0) {
//
// wait refcount
//
}
//
//
if (pVnode->tsdb) {
//
tsdbDropRepo(pVnode->tsdb);
//
pVnode->tsdb = NULL;
//
}
//
//
dnodeCleanupVnode(pVnode);
}
static
void
dnodeProcesSMDCreateVnodeMsg
(
SRpcMsg
*
rpcMsg
)
{
...
...
src/dnode/src/dnodeMnode.c
浏览文件 @
3006a756
...
...
@@ -17,7 +17,7 @@
#include "taosmsg.h"
#include "tlog.h"
#include "trpc.h"
#include "dnode
System
.h"
#include "dnode.h"
#include "dnodeMgmt.h"
#include "dnodeWrite.h"
...
...
src/dnode/src/dnodeModule.c
浏览文件 @
3006a756
...
...
@@ -22,9 +22,9 @@
#include "http.h"
#include "monitor.h"
#include "dnodeModule.h"
#include "dnode
System
.h"
#include "dnode.h"
void
dnodeAllocModules
()
{
static
void
dnodeAllocModules
()
{
tsModule
[
TSDB_MOD_MGMT
].
name
=
"mgmt"
;
tsModule
[
TSDB_MOD_MGMT
].
initFp
=
mgmtInitSystem
;
tsModule
[
TSDB_MOD_MGMT
].
cleanUpFp
=
mgmtCleanUpSystem
;
...
...
@@ -69,6 +69,8 @@ void dnodeCleanUpModules() {
}
int32_t
dnodeInitModules
()
{
dnodeAllocModules
();
for
(
int
mod
=
0
;
mod
<
TSDB_MOD_MAX
;
++
mod
)
{
if
(
tsModule
[
mod
].
num
!=
0
&&
tsModule
[
mod
].
initFp
)
{
if
((
*
tsModule
[
mod
].
initFp
)()
!=
0
)
{
...
...
@@ -81,7 +83,7 @@ int32_t dnodeInitModules() {
return
TSDB_CODE_SUCCESS
;
}
void
dnodeStartModules
Imp
()
{
void
dnodeStartModules
()
{
for
(
int
mod
=
1
;
mod
<
TSDB_MOD_MAX
;
++
mod
)
{
if
(
tsModule
[
mod
].
num
!=
0
&&
tsModule
[
mod
].
startFp
)
{
if
((
*
tsModule
[
mod
].
startFp
)()
!=
0
)
{
...
...
@@ -90,5 +92,3 @@ void dnodeStartModulesImp() {
}
}
}
void
(
*
dnodeStartModules
)()
=
dnodeStartModulesImp
;
src/dnode/src/dnodeRead.c
浏览文件 @
3006a756
...
...
@@ -67,9 +67,7 @@ void dnodeCleanupRead() {
taosCloseQset
(
readQset
);
}
void
dnodeRead
(
void
*
rpcMsg
)
{
SRpcMsg
*
pMsg
=
rpcMsg
;
void
dnodeRead
(
SRpcMsg
*
pMsg
)
{
int32_t
leftLen
=
pMsg
->
contLen
;
char
*
pCont
=
(
char
*
)
pMsg
->
pCont
;
int32_t
contLen
=
0
;
...
...
src/dnode/src/dnodeShell.c
浏览文件 @
3006a756
...
...
@@ -20,7 +20,7 @@
#include "taosmsg.h"
#include "tlog.h"
#include "trpc.h"
#include "dnode
System
.h"
#include "dnode.h"
#include "dnodeRead.h"
#include "dnodeWrite.h"
#include "dnodeShell.h"
...
...
src/dnode/src/dnodeSystem.c
已删除
100644 → 0
浏览文件 @
46c31a24
/*
* 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 "taosdef.h"
#include "taoserror.h"
#include "tcrc32c.h"
#include "tlog.h"
#include "tmodule.h"
#include "tsched.h"
#include "ttime.h"
#include "ttimer.h"
#include "tutil.h"
#include "http.h"
#include "trpc.h"
#include "dnode.h"
#include "dnodeMgmt.h"
#include "dnodeModule.h"
#include "dnodeShell.h"
#include "dnodeSystem.h"
#ifdef CLUSTER
#include "account.h"
#include "admin.h"
#include "balance.h"
#include "cluster.h"
#include "grant.h"
#include "mpeer.h"
#include "storage.h"
#include "vpeer.h"
#endif
static
pthread_mutex_t
tsDnodeMutex
;
static
SDnodeRunStatus
tsDnodeRunStatus
=
TSDB_DNODE_RUN_STATUS_STOPPED
;
static
int32_t
dnodeInitRpcQHandle
();
static
int32_t
dnodeInitTmrCtl
();
int32_t
(
*
dnodeInitStorage
)()
=
NULL
;
void
(
*
dnodeCleanupStorage
)()
=
NULL
;
int32_t
(
*
dnodeInitPeers
)(
int32_t
numOfThreads
)
=
NULL
;
void
*
tsDnodeTmr
;
void
**
tsRpcQhandle
;
int32_t
tsVnodePeers
=
TSDB_VNODES_SUPPORT
-
1
;
int32_t
tsMaxQueues
;
uint32_t
tsRebootTime
;
static
void
dnodeInitVnodesLock
()
{
pthread_mutex_init
(
&
tsDnodeMutex
,
NULL
);
}
void
dnodeLockVnodes
()
{
pthread_mutex_lock
(
&
tsDnodeMutex
);
}
void
dnodeUnLockVnodes
()
{
pthread_mutex_unlock
(
&
tsDnodeMutex
);
}
static
void
dnodeCleanVnodesLock
()
{
pthread_mutex_destroy
(
&
tsDnodeMutex
);
}
SDnodeRunStatus
dnodeGetRunStatus
()
{
return
tsDnodeRunStatus
;
}
void
dnodeSetRunStatus
(
SDnodeRunStatus
status
)
{
tsDnodeRunStatus
=
status
;
}
void
dnodeCleanUpSystem
()
{
tclearModuleStatus
(
TSDB_MOD_MGMT
);
if
(
dnodeGetRunStatus
()
==
TSDB_DNODE_RUN_STATUS_STOPPED
)
{
return
;
}
else
{
dnodeSetRunStatus
(
TSDB_DNODE_RUN_STATUS_STOPPED
);
}
dnodeCleanupShell
();
dnodeCleanUpModules
();
dnodeCleanupMgmt
();
taosCloseLogger
();
dnodeCleanupStorage
();
dnodeCleanVnodesLock
();
}
void
dnodeCheckDataDirOpenned
(
const
char
*
dir
)
{
char
filepath
[
256
]
=
{
0
};
sprintf
(
filepath
,
"%s/.running"
,
dir
);
int32_t
fd
=
open
(
filepath
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
S_IRWXU
|
S_IRWXG
|
S_IRWXO
);
int32_t
ret
=
flock
(
fd
,
LOCK_EX
|
LOCK_NB
);
if
(
ret
!=
0
)
{
dError
(
"failed to lock file:%s ret:%d, database may be running, quit"
,
filepath
,
ret
);
exit
(
0
);
}
}
void
dnodeInitPlugins
()
{
#ifdef CLUSTER
// acctInit();
// adminInit();
// balanceInit();
// clusterInit();
// grantInit();
// mpeerInit();
// storageInit();
#endif
}
int32_t
dnodeInitSystem
()
{
tsRebootTime
=
taosGetTimestampSec
();
tscEmbedded
=
1
;
dnodeSetRunStatus
(
TSDB_DNODE_RUN_STATUS_INITIALIZE
);
taosResolveCRC
();
// Read global configuration.
tsReadGlobalLogConfig
();
struct
stat
dirstat
;
if
(
stat
(
logDir
,
&
dirstat
)
<
0
)
{
mkdir
(
logDir
,
0755
);
}
char
temp
[
128
];
sprintf
(
temp
,
"%s/taosdlog"
,
logDir
);
if
(
taosInitLog
(
temp
,
tsNumOfLogLines
,
1
)
<
0
)
{
printf
(
"failed to init log file
\n
"
);
}
if
(
!
tsReadGlobalConfig
())
{
tsPrintGlobalConfig
();
dError
(
"TDengine read global config failed"
);
return
-
1
;
}
if
(
dnodeInitStorage
()
!=
0
)
{
dError
(
"TDengine init tier directory failed"
);
return
-
1
;
}
// dnodeInitMgmtIp();
tsPrintGlobalConfig
();
dPrint
(
"Server IP address is:%s"
,
tsPrivateIp
);
taosSetCoreDump
();
signal
(
SIGPIPE
,
SIG_IGN
);
dnodeAllocModules
();
dnodeInitVnodesLock
();
dPrint
(
"starting to initialize TDengine ..."
);
if
(
dnodeInitRpcQHandle
()
<
0
)
{
dError
(
"failed to init query qhandle, exit"
);
return
-
1
;
}
if
(
dnodeCheckSystem
()
<
0
)
{
return
-
1
;
}
if
(
dnodeInitModules
()
<
0
)
{
return
-
1
;
}
if
(
dnodeInitTmrCtl
()
<
0
)
{
dError
(
"failed to init timer, exit"
);
return
-
1
;
}
if
(
dnodeInitMgmt
()
<
0
)
{
dError
(
"failed to init vnode storage"
);
return
-
1
;
}
int32_t
numOfThreads
=
(
1
.
0
-
tsRatioOfQueryThreads
)
*
tsNumOfCores
*
tsNumOfThreadsPerCore
/
2
.
0
;
if
(
numOfThreads
<
1
)
numOfThreads
=
1
;
if
(
dnodeInitPeers
(
numOfThreads
)
<
0
)
{
dError
(
"failed to init vnode peer communication"
);
return
-
1
;
}
if
(
dnodeInitMgmt
()
<
0
)
{
dError
(
"failed to init communication to mgmt"
);
return
-
1
;
}
if
(
dnodeInitShell
()
<
0
)
{
dError
(
"failed to init communication to shell"
);
return
-
1
;
}
dnodeStartModules
();
dnodeSetRunStatus
(
TSDB_DNODE_RUN_STATUS_RUNING
);
dPrint
(
"TDengine is initialized successfully"
);
return
0
;
}
int32_t
dnodeInitStorageImp
()
{
struct
stat
dirstat
;
strcpy
(
tsDirectory
,
dataDir
);
if
(
stat
(
dataDir
,
&
dirstat
)
<
0
)
{
mkdir
(
dataDir
,
0755
);
}
char
fileName
[
128
];
sprintf
(
fileName
,
"%s/tsdb"
,
tsDirectory
);
mkdir
(
fileName
,
0755
);
sprintf
(
fileName
,
"%s/data"
,
tsDirectory
);
mkdir
(
fileName
,
0755
);
sprintf
(
tsMgmtDirectory
,
"%s/mgmt"
,
tsDirectory
);
sprintf
(
tsDirectory
,
"%s/tsdb"
,
dataDir
);
dnodeCheckDataDirOpenned
(
dataDir
);
return
0
;
}
static
int32_t
dnodeInitTmrCtl
()
{
tsDnodeTmr
=
taosTmrInit
(
TSDB_MAX_VNODES
*
(
tsVnodePeers
+
10
)
+
tsSessionsPerVnode
+
1000
,
200
,
60000
,
"DND-vnode"
);
if
(
tsDnodeTmr
==
NULL
)
{
dError
(
"failed to init timer, exit"
);
return
-
1
;
}
return
0
;
}
static
int32_t
dnodeInitRpcQHandle
()
{
tsMaxQueues
=
(
1
.
0
-
tsRatioOfQueryThreads
)
*
tsNumOfCores
*
tsNumOfThreadsPerCore
/
2
.
0
;
if
(
tsMaxQueues
<
1
)
{
tsMaxQueues
=
1
;
}
tsRpcQhandle
=
malloc
(
tsMaxQueues
*
sizeof
(
void
*
));
for
(
int32_t
i
=
0
;
i
<
tsMaxQueues
;
++
i
)
{
tsRpcQhandle
[
i
]
=
taosInitScheduler
(
tsSessionsPerVnode
,
1
,
"dnode"
);
}
return
0
;
}
int32_t
dnodeCheckSystemImp
()
{
return
0
;
}
int32_t
(
*
dnodeCheckSystem
)()
=
dnodeCheckSystemImp
;
int32_t
dnodeInitPeersImp
(
int32_t
numOfThreads
)
{
return
0
;
}
src/dnode/src/dnodeWrite.c
浏览文件 @
3006a756
...
...
@@ -79,9 +79,7 @@ void dnodeCleanupWrite() {
free
(
wWorkerPool
.
writeWorker
);
}
void
dnodeWrite
(
void
*
rpcMsg
)
{
SRpcMsg
*
pMsg
=
rpcMsg
;
void
dnodeWrite
(
SRpcMsg
*
pMsg
)
{
int32_t
leftLen
=
pMsg
->
contLen
;
char
*
pCont
=
(
char
*
)
pMsg
->
pCont
;
int32_t
contLen
=
0
;
...
...
src/inc/dnode.h
浏览文件 @
3006a756
...
...
@@ -21,7 +21,7 @@ extern "C" {
#endif
#include <stdint.h>
#include <
pthread
.h>
#include <
stdbool
.h>
typedef
struct
{
int32_t
queryReqNum
;
...
...
@@ -29,32 +29,13 @@ typedef struct {
int32_t
httpReqNum
;
}
SDnodeStatisInfo
;
typedef
struct
{
char
id
[
20
];
char
sid
;
void
*
thandle
;
int
mgmtIndex
;
char
status
;
// 0:offline, 1:online
}
SMgmtObj
;
// global variables
extern
uint32_t
tsRebootTime
;
// dnodeCluster
extern
void
(
*
dnodeStartModules
)();
extern
int32_t
(
*
dnodeCheckSystem
)();
// dnodeSystem
void
dnodeCheckDataDirOpenned
(
const
char
*
dir
);
// dnodeModule
extern
void
(
*
dnodeStartModules
)();
typedef
enum
{
TSDB_DNODE_RUN_STATUS_INITIALIZE
,
TSDB_DNODE_RUN_STATUS_RUNING
,
TSDB_DNODE_RUN_STATUS_STOPPED
}
SDnodeRunStatus
;
void
dnodeLockVnodes
();
void
dnodeUnLockVnodes
();
SDnodeRunStatus
dnodeGetRunStatus
();
SDnodeStatisInfo
dnodeGetStatisInfo
();
#ifdef __cplusplus
...
...
src/mnode/src/mgmtShell.c
浏览文件 @
3006a756
...
...
@@ -21,7 +21,7 @@
#include "trpc.h"
#include "tstatus.h"
#include "tsched.h"
#include "dnode
System
.h"
#include "dnode.h"
#include "mnode.h"
#include "mgmtAcct.h"
#include "mgmtBalance.h"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录