Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
22305b01
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
22305b01
编写于
3月 30, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
3月 30, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11147 from taosdata/feature/shm
shm
上级
dcfd63a2
9a4eb5ff
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
111 addition
and
130 deletion
+111
-130
include/os/os.h
include/os/os.h
+1
-0
include/os/osProc.h
include/os/osProc.h
+33
-0
include/os/osSignal.h
include/os/osSignal.h
+2
-0
include/util/taoserror.h
include/util/taoserror.h
+1
-0
source/dnode/mgmt/main/exe/dndMain.c
source/dnode/mgmt/main/exe/dndMain.c
+2
-5
source/dnode/mgmt/main/inc/dnd.h
source/dnode/mgmt/main/inc/dnd.h
+3
-2
source/dnode/mgmt/main/src/dndExec.c
source/dnode/mgmt/main/src/dndExec.c
+26
-5
source/dnode/mgmt/main/src/dndFile.c
source/dnode/mgmt/main/src/dndFile.c
+2
-2
source/dnode/mgmt/main/src/dndObj.c
source/dnode/mgmt/main/src/dndObj.c
+5
-3
source/os/src/osProc.c
source/os/src/osProc.c
+27
-0
source/os/src/osShm.c
source/os/src/osShm.c
+6
-7
source/os/src/osSignal.c
source/os/src/osSignal.c
+2
-0
source/util/src/terror.c
source/util/src/terror.c
+1
-1
source/util/test/queueTest.cpp
source/util/test/queueTest.cpp
+0
-105
未找到文件。
include/os/os.h
浏览文件 @
22305b01
...
...
@@ -82,6 +82,7 @@ extern "C" {
#include "osLz4.h"
#include "osMath.h"
#include "osMemory.h"
#include "osProc.h"
#include "osRand.h"
#include "osThread.h"
#include "osSemaphore.h"
...
...
include/os/osProc.h
0 → 100644
浏览文件 @
22305b01
/*
* 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_OS_PROC_H_
#define _TD_OS_PROC_H_
#ifdef __cplusplus
extern
"C"
{
#endif
// start a copy of itself
int32_t
taosNewProc
(
const
char
*
args
);
// the length of the new name must be less than the original name to take effect
void
taosSetProcName
(
char
**
argv
,
const
char
*
name
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_OS_PROC_H_*/
include/os/osSignal.h
浏览文件 @
22305b01
...
...
@@ -49,6 +49,8 @@ void taosSetSignal(int32_t signum, FSignalHandler sigfp);
void
taosIgnSignal
(
int32_t
signum
);
void
taosDflSignal
(
int32_t
signum
);
void
taosKillChildOnSelfStopped
();
#ifdef __cplusplus
}
#endif
...
...
include/util/taoserror.h
浏览文件 @
22305b01
...
...
@@ -78,6 +78,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_CFG_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x010C)
#define TSDB_CODE_INVALID_CFG TAOS_DEF_ERROR_CODE(0, 0x010D)
#define TSDB_CODE_OUT_OF_SHM_MEM TAOS_DEF_ERROR_CODE(0, 0x010E)
#define TSDB_CODE_INVALID_SHM_ID TAOS_DEF_ERROR_CODE(0, 0x010F)
#define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0110)
#define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0111)
#define TSDB_CODE_REF_ID_REMOVED TAOS_DEF_ERROR_CODE(0, 0x0112)
...
...
source/dnode/mgmt/main/exe/dndMain.c
浏览文件 @
22305b01
...
...
@@ -52,13 +52,11 @@ static void dndSetSignalHandle() {
if
(
!
tsMultiProcess
)
{
// Set the single process signal
}
else
if
(
global
.
ntype
==
DNODE
)
{
// Set the parent process signal
// When the child process exits, the parent process receives a signal
taosSetSignal
(
SIGCHLD
,
dndHandleChild
);
}
else
{
// Set child process signal
// When the parent process exits, the child process will receive the SIGKILL signal
prctl
(
PR_SET_PDEATHSIG
,
SIGKILL
);
taosKillChildOnSelfStopped
(
);
}
}
...
...
@@ -145,8 +143,7 @@ static int32_t dndInitLog() {
static
void
dndSetProcName
(
char
**
argv
)
{
if
(
global
.
ntype
!=
DNODE
)
{
const
char
*
name
=
dndNodeProcStr
(
global
.
ntype
);
prctl
(
PR_SET_NAME
,
name
);
strcpy
(
argv
[
0
],
name
);
taosSetProcName
(
argv
,
name
);
}
}
...
...
source/dnode/mgmt/main/inc/dnd.h
浏览文件 @
22305b01
...
...
@@ -95,13 +95,14 @@ typedef struct SMgmtWrapper {
bool
deployed
;
bool
required
;
EProcType
procType
;
int32_t
procId
;
SProcObj
*
pProc
;
SShm
shm
;
void
*
pMgmt
;
SDnode
*
pDnode
;
NodeMsgFp
msgFps
[
TDMT_MAX
];
int8_t
msgVgIds
[
TDMT_MAX
];
// Handle the case where the same message type is distributed to qnode or vnode
SMgmtFp
fp
;
int8_t
msgVgIds
[
TDMT_MAX
];
// Handle the case where the same message type is distributed to qnode or vnode
NodeMsgFp
msgFps
[
TDMT_MAX
];
}
SMgmtWrapper
;
typedef
struct
{
...
...
source/dnode/mgmt/main/src/dndExec.c
浏览文件 @
22305b01
...
...
@@ -192,8 +192,19 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) {
SMgmtWrapper
*
pWrapper
=
&
pDnode
->
wrappers
[
n
];
if
(
!
pWrapper
->
required
)
continue
;
dInfo
(
"node:%s, will not start in parent process"
,
pWrapper
->
name
);
// exec new node
if
(
pDnode
->
ntype
==
NODE_MAX
)
{
dInfo
(
"node:%s, should be started manually"
,
pWrapper
->
name
);
}
else
{
char
args
[
PATH_MAX
];
int32_t
pid
=
taosNewProc
(
args
);
if
(
pid
<=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"node:%s, failed to exec in new process since %s"
,
pWrapper
->
name
,
terrstr
());
return
-
1
;
}
pWrapper
->
procId
=
pid
;
dInfo
(
"node:%s, run in new process, pid:%d"
,
pWrapper
->
name
,
pid
);
}
if
(
taosProcRun
(
pWrapper
->
pProc
)
!=
0
)
{
dError
(
"node:%s, failed to run proc since %s"
,
pWrapper
->
name
,
terrstr
());
...
...
@@ -214,8 +225,12 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) {
static
int32_t
dndRunInChildProcess
(
SDnode
*
pDnode
)
{
dInfo
(
"dnode start to run in child process"
);
SMgmtWrapper
*
pWrapper
=
&
pDnode
->
wrappers
[
pDnode
->
ntype
];
SMsgCb
msgCb
=
dndCreateMsgcb
(
pWrapper
);
tmsgSetDefaultMsgCb
(
&
msgCb
);
pWrapper
->
procType
=
PROC_CHILD
;
if
(
dndOpenNode
(
pWrapper
)
!=
0
)
{
dError
(
"node:%s, failed to start since %s"
,
pWrapper
->
name
,
terrstr
());
return
-
1
;
...
...
@@ -236,13 +251,19 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) {
.
isChild
=
true
,
.
name
=
pWrapper
->
name
};
pWrapper
->
procType
=
PROC_CHILD
;
pWrapper
->
pProc
=
taosProcInit
(
&
cfg
);
if
(
pWrapper
->
pProc
==
NULL
)
{
dError
(
"node:%s, failed to create proc since %s"
,
pWrapper
->
name
,
terrstr
());
return
-
1
;
}
if
(
pWrapper
->
fp
.
startFp
!=
NULL
)
{
if
((
*
pWrapper
->
fp
.
startFp
)(
pWrapper
)
!=
0
)
{
dError
(
"node:%s, failed to start since %s"
,
pWrapper
->
name
,
terrstr
());
return
-
1
;
}
}
if
(
taosProcRun
(
pWrapper
->
pProc
)
!=
0
)
{
dError
(
"node:%s, failed to run proc since %s"
,
pWrapper
->
name
,
terrstr
());
return
-
1
;
...
...
@@ -258,7 +279,7 @@ int32_t dndRun(SDnode * pDnode) {
dError
(
"failed to run dnode since %s"
,
terrstr
());
return
-
1
;
}
}
else
if
(
pDnode
->
ntype
==
DNODE
)
{
}
else
if
(
pDnode
->
ntype
==
DNODE
||
pDnode
->
ntype
==
NODE_MAX
)
{
if
(
dndRunInParentProcess
(
pDnode
)
!=
0
)
{
dError
(
"failed to run dnode in parent process since %s"
,
terrstr
());
return
-
1
;
...
...
source/dnode/mgmt/main/src/dndFile.c
浏览文件 @
22305b01
...
...
@@ -179,7 +179,7 @@ int32_t dndReadShmFile(SDnode *pDnode) {
}
}
if
(
!
tsMultiProcess
||
pDnode
->
ntype
==
DNODE
)
{
if
(
!
tsMultiProcess
||
pDnode
->
ntype
==
DNODE
||
pDnode
->
ntype
==
DNODE
)
{
for
(
ENodeType
ntype
=
DNODE
;
ntype
<
NODE_MAX
;
++
ntype
)
{
SMgmtWrapper
*
pWrapper
=
&
pDnode
->
wrappers
[
ntype
];
if
(
pWrapper
->
shm
.
id
>=
0
)
{
...
...
@@ -191,7 +191,7 @@ int32_t dndReadShmFile(SDnode *pDnode) {
SMgmtWrapper
*
pWrapper
=
&
pDnode
->
wrappers
[
pDnode
->
ntype
];
if
(
taosAttachShm
(
&
pWrapper
->
shm
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"shmid:%d, failed to attach since %s"
,
pWrapper
->
shm
.
id
,
terrstr
());
dError
(
"shmid:%d, failed to attach s
hm s
ince %s"
,
pWrapper
->
shm
.
id
,
terrstr
());
goto
_OVER
;
}
dDebug
(
"shmid:%d, is attached, size:%d"
,
pWrapper
->
shm
.
id
,
pWrapper
->
shm
.
size
);
...
...
source/dnode/mgmt/main/src/dndObj.c
浏览文件 @
22305b01
...
...
@@ -35,9 +35,11 @@ static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) {
return
-
1
;
}
pDnode
->
lockfile
=
dndCheckRunning
(
pDnode
->
dataDir
);
if
(
pDnode
->
lockfile
==
NULL
)
{
return
-
1
;
if
(
!
tsMultiProcess
||
pDnode
->
ntype
==
DNODE
||
pDnode
->
ntype
==
NODE_MAX
)
{
pDnode
->
lockfile
=
dndCheckRunning
(
pDnode
->
dataDir
);
if
(
pDnode
->
lockfile
==
NULL
)
{
return
-
1
;
}
}
return
0
;
...
...
source/os/src/osProc.c
0 → 100644
浏览文件 @
22305b01
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE
#include "os.h"
int32_t
taosNewProc
(
const
char
*
args
)
{
return
0
;
}
void
taosSetProcName
(
char
**
argv
,
const
char
*
name
)
{
prctl
(
PR_SET_NAME
,
name
);
strcpy
(
argv
[
0
],
name
);
}
\ No newline at end of file
source/os/src/osShm.c
浏览文件 @
22305b01
...
...
@@ -49,12 +49,11 @@ void taosDropShm(SShm* pShm) {
}
int32_t
taosAttachShm
(
SShm
*
pShm
)
{
if
(
pShm
->
id
>=
0
)
{
pShm
->
ptr
=
shmat
(
pShm
->
id
,
NULL
,
0
);
if
(
pShm
->
ptr
!=
NULL
)
{
return
0
;
}
}
errno
=
0
;
return
-
1
;
void
*
ptr
=
shmat
(
pShm
->
id
,
NULL
,
0
);
if
(
errno
==
0
)
{
pShm
->
ptr
=
ptr
;
}
return
errno
;
}
source/os/src/osSignal.c
浏览文件 @
22305b01
...
...
@@ -71,4 +71,6 @@ void taosIgnSignal(int32_t signum) { signal(signum, SIG_IGN); }
void
taosDflSignal
(
int32_t
signum
)
{
signal
(
signum
,
SIG_DFL
);
}
void
taosKillChildOnSelfStopped
()
{
prctl
(
PR_SET_PDEATHSIG
,
SIGKILL
);
}
#endif
source/util/src/terror.c
浏览文件 @
22305b01
...
...
@@ -85,7 +85,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_REPEAT_INIT, "Repeat initialization
TAOS_DEFINE_ERROR
(
TSDB_CODE_CFG_NOT_FOUND
,
"Config not found"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_INVALID_CFG
,
"Invalid config option"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_OUT_OF_SHM_MEM
,
"Out of Share memory"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_INVALID_SHM_ID
,
"Invalid SHM ID"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_REF_NO_MEMORY
,
"Ref out of memory"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_REF_FULL
,
"too many Ref Objs"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_REF_ID_REMOVED
,
"Ref ID is removed"
)
...
...
source/util/test/queueTest.cpp
浏览文件 @
22305b01
...
...
@@ -26,108 +26,3 @@ class UtilTestQueue : public ::testing::Test {
static
void
SetUpTestSuite
()
{}
static
void
TearDownTestSuite
()
{}
};
#if 0
TEST_F(UtilTestQueue, 01_fork) {
pid_t pid;
int shmid;
int* shmptr;
int* tmp;
int err;
pthread_mutexattr_t mattr;
if ((err = taosThreadMutexAttrInit(&mattr)) < 0) {
printf("mutex addr init error:%s\n", strerror(err));
exit(1);
}
if ((err = taosThreadMutexAttrSetPshared(&mattr, PTHREAD_PROCESS_SHARED)) < 0) {
printf("mutex addr get shared error:%s\n", strerror(err));
exit(1);
}
pthread_mutex_t* m;
int mid = shmget(IPC_PRIVATE, sizeof(pthread_mutex_t), 0600);
m = (pthread_mutex_t*)shmat(mid, NULL, 0);
if ((err = taosThreadMutexInit(m, &mattr)) < 0) {
printf("mutex mutex init error:%s\n", strerror(err));
exit(1);
}
if ((shmid = shmget(IPC_PRIVATE, 1000, IPC_CREAT | 0600)) < 0) {
perror("shmget error");
exit(1);
}
if ((shmptr = (int*)shmat(shmid, 0, 0)) == (void*)-1) {
perror("shmat error");
exit(1);
}
tmp = shmptr;
int shmid2;
int** shmptr2;
if ((shmid2 = shmget(IPC_PRIVATE, 20, IPC_CREAT | 0600)) < 0) {
perror("shmget2 error");
exit(1);
}
if ((shmptr2 = (int**)shmat(shmid2, 0, 0)) == (void*)-1) {
perror("shmat2 error");
exit(1);
}
*shmptr2 = shmptr;
if ((pid = fork()) < 0) {
perror("fork error");
exit(1);
} else if (pid == 0) {
if ((err = taosThreadMutexLock(m)) < 0) {
printf("lock error:%s\n", strerror(err));
exit(1);
}
for (int i = 0; i < 30; ++i) {
**shmptr2 = i;
(*shmptr2)++;
}
if ((err = taosThreadMutexUnlock(m)) < 0) {
printf("unlock error:%s\n", strerror(err));
exit(1);
}
exit(0);
} else {
if ((err = taosThreadMutexLock(m)) < 0) {
printf("lock error:%s\n", strerror(err));
exit(1);
}
for (int i = 10; i < 42; ++i) {
**shmptr2 = i;
(*shmptr2)++;
}
if ((err = taosThreadMutexUnlock(m)) < 0) {
printf("unlock error:%s\n", strerror(err));
exit(1);
}
}
wait(NULL);
for (int i = 0; i < 70; ++i) {
printf("%d ", tmp[i]);
}
printf("\n");
taosThreadAttrDestroy(&mattr);
//销毁mutex
taosThreadMutexDestroy(m);
exit(0);
}
#endif
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录