Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ae182cd7
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看板
提交
ae182cd7
编写于
3月 30, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
shm
上级
6ece0d9a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
76 addition
and
49 deletion
+76
-49
include/os/osShm.h
include/os/osShm.h
+2
-2
source/dnode/mgmt/main/inc/dnd.h
source/dnode/mgmt/main/inc/dnd.h
+1
-1
source/dnode/mgmt/main/inc/dndInt.h
source/dnode/mgmt/main/inc/dndInt.h
+3
-3
source/dnode/mgmt/main/src/dndExec.c
source/dnode/mgmt/main/src/dndExec.c
+12
-2
source/dnode/mgmt/main/src/dndFile.c
source/dnode/mgmt/main/src/dndFile.c
+43
-36
source/dnode/mgmt/main/src/dndObj.c
source/dnode/mgmt/main/src/dndObj.c
+13
-3
source/os/src/osShm.c
source/os/src/osShm.c
+2
-2
未找到文件。
include/os/osShm.h
浏览文件 @
ae182cd7
...
...
@@ -22,11 +22,11 @@ extern "C" {
typedef
struct
{
int32_t
id
;
int
32
_t
size
;
int
64
_t
size
;
void
*
ptr
;
}
SShm
;
int32_t
taosCreateShm
(
SShm
*
pShm
,
int
32
_t
shmsize
)
;
int32_t
taosCreateShm
(
SShm
*
pShm
,
int
64
_t
shmsize
)
;
void
taosDropShm
(
SShm
*
pShm
);
int32_t
taosAttachShm
(
SShm
*
pShm
);
void
taosDetachShm
(
SShm
*
pShm
);
...
...
source/dnode/mgmt/main/inc/dnd.h
浏览文件 @
ae182cd7
...
...
@@ -128,7 +128,7 @@ typedef struct SDnode {
EDndStatus
status
;
EDndEvent
event
;
SStartupReq
startup
;
TdFilePtr
runtimeF
ile
;
TdFilePtr
lockf
ile
;
STransMgmt
trans
;
SMgmtWrapper
wrappers
[
NODE_MAX
];
}
SDnode
;
...
...
source/dnode/mgmt/main/inc/dndInt.h
浏览文件 @
ae182cd7
...
...
@@ -54,9 +54,9 @@ int32_t dndInitMsgHandle(SDnode *pDnode);
void
dndSendRpcRsp
(
SMgmtWrapper
*
pWrapper
,
const
SRpcMsg
*
pRsp
);
// dndFile.c
int32_t
dndOpenRuntimeFile
(
SDnode
*
pDnode
);
int32_t
dndWriteRuntime
File
(
SDnode
*
pDnode
);
void
dndCloseRuntime
File
(
SDnode
*
pDnode
);
TdFilePtr
dndCheckRunning
(
const
char
*
dataDir
);
int32_t
dndReadShm
File
(
SDnode
*
pDnode
);
int32_t
dndWriteShm
File
(
SDnode
*
pDnode
);
#ifdef __cplusplus
}
...
...
source/dnode/mgmt/main/src/dndExec.c
浏览文件 @
ae182cd7
...
...
@@ -160,7 +160,12 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) {
return
-
1
;
}
SProcCfg
cfg
=
{.
parentConsumeFp
=
(
ProcConsumeFp
)
dndConsumeParentQueue
,
SProcCfg
cfg
=
{.
childConsumeFp
=
(
ProcConsumeFp
)
dndConsumeChildQueue
,
.
childMallocHeadFp
=
(
ProcMallocFp
)
taosAllocateQitem
,
.
childFreeHeadFp
=
(
ProcFreeFp
)
taosFreeQitem
,
.
childMallocBodyFp
=
(
ProcMallocFp
)
rpcMallocCont
,
.
childFreeBodyFp
=
(
ProcFreeFp
)
rpcFreeCont
,
.
parentConsumeFp
=
(
ProcConsumeFp
)
dndConsumeParentQueue
,
.
parentdMallocHeadFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
parentFreeHeadFp
=
(
ProcFreeFp
)
taosMemoryFree
,
.
parentMallocBodyFp
=
(
ProcMallocFp
)
rpcMallocCont
,
...
...
@@ -176,7 +181,7 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) {
}
}
if
(
dndWrite
Runtime
File
(
pDnode
)
!=
0
)
{
if
(
dndWrite
Shm
File
(
pDnode
)
!=
0
)
{
dError
(
"failed to write runtime file since %s"
,
terrstr
());
return
-
1
;
}
...
...
@@ -220,6 +225,11 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) {
.
childFreeHeadFp
=
(
ProcFreeFp
)
taosFreeQitem
,
.
childMallocBodyFp
=
(
ProcMallocFp
)
rpcMallocCont
,
.
childFreeBodyFp
=
(
ProcFreeFp
)
rpcFreeCont
,
.
parentConsumeFp
=
(
ProcConsumeFp
)
dndConsumeParentQueue
,
.
parentdMallocHeadFp
=
(
ProcMallocFp
)
taosMemoryMalloc
,
.
parentFreeHeadFp
=
(
ProcFreeFp
)
taosMemoryFree
,
.
parentMallocBodyFp
=
(
ProcMallocFp
)
rpcMallocCont
,
.
parentFreeBodyFp
=
(
ProcFreeFp
)
rpcFreeCont
,
.
shm
=
pWrapper
->
shm
,
.
pParent
=
pWrapper
,
.
name
=
pWrapper
->
name
};
...
...
source/dnode/mgmt/main/src/dndFile.c
浏览文件 @
ae182cd7
...
...
@@ -117,7 +117,30 @@ _OVER:
return
code
;
}
int32_t
dndOpenRuntimeFile
(
SDnode
*
pDnode
)
{
TdFilePtr
dndCheckRunning
(
const
char
*
dataDir
)
{
char
filepath
[
PATH_MAX
]
=
{
0
};
snprintf
(
filepath
,
sizeof
(
filepath
),
"%s%s.running"
,
dataDir
,
TD_DIRSEP
);
TdFilePtr
pFile
=
taosOpenFile
(
filepath
,
TD_FILE_CTEATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to lock file:%s since %s"
,
filepath
,
terrstr
());
return
NULL
;
}
int32_t
ret
=
taosLockFile
(
pFile
);
if
(
ret
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to lock file:%s since %s"
,
filepath
,
terrstr
());
taosCloseFile
(
&
pFile
);
return
NULL
;
}
dDebug
(
"file:%s is locked"
,
filepath
);
return
pFile
;
}
int32_t
dndReadShmFile
(
SDnode
*
pDnode
)
{
int32_t
code
=
-
1
;
char
itemName
[
24
]
=
{
0
};
char
content
[
MAXLEN
+
1
]
=
{
0
};
...
...
@@ -125,17 +148,11 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) {
cJSON
*
root
=
NULL
;
TdFilePtr
pFile
=
NULL
;
snprintf
(
file
,
sizeof
(
file
),
"%s%s.
running
"
,
pDnode
->
dataDir
,
TD_DIRSEP
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_
CTEATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
snprintf
(
file
,
sizeof
(
file
),
"%s%s.
shmfile
"
,
pDnode
->
dataDir
,
TD_DIRSEP
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_
READ
);
if
(
pFile
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to open file:%s since %s"
,
file
,
terrstr
());
goto
_OVER
;
}
if
(
taosLockFile
(
pFile
)
!=
0
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
dError
(
"failed to lock file:%s since %s"
,
file
,
terrstr
());
dDebug
(
"file %s not exist"
,
file
);
code
=
0
;
goto
_OVER
;
}
...
...
@@ -150,14 +167,14 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) {
for
(
ENodeType
ntype
=
DNODE
+
1
;
ntype
<
NODE_MAX
;
++
ntype
)
{
snprintf
(
itemName
,
sizeof
(
itemName
),
"%s_shmid"
,
dndNodeProcStr
(
ntype
));
cJSON
*
shmid
=
cJSON_GetObjectItem
(
root
,
itemName
);
if
(
shmid
&&
shmid
->
type
==
cJSON_
Number
)
{
pDnode
->
wrappers
[
ntype
].
shm
.
id
=
shmid
->
valueint
;
if
(
shmid
&&
shmid
->
type
==
cJSON_
String
)
{
pDnode
->
wrappers
[
ntype
].
shm
.
id
=
atoi
(
shmid
->
valuestring
)
;
}
snprintf
(
itemName
,
sizeof
(
itemName
),
"%s_shmsize"
,
dndNodeProcStr
(
ntype
));
cJSON
*
shmsize
=
cJSON_GetObjectItem
(
root
,
itemName
);
if
(
shmsize
&&
shmsize
->
type
==
cJSON_
Number
)
{
pDnode
->
wrappers
[
ntype
].
shm
.
size
=
shmsize
->
valueint
;
if
(
shmsize
&&
shmsize
->
type
==
cJSON_
String
)
{
pDnode
->
wrappers
[
ntype
].
shm
.
size
=
atoll
(
shmsize
->
valuestring
)
;
}
}
}
...
...
@@ -166,7 +183,7 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) {
for
(
ENodeType
ntype
=
DNODE
;
ntype
<
NODE_MAX
;
++
ntype
)
{
SMgmtWrapper
*
pWrapper
=
&
pDnode
->
wrappers
[
pDnode
->
ntype
];
if
(
pWrapper
->
shm
.
id
>
0
)
{
dDebug
(
"shmid:%d, is closed, size:%
d"
,
pWrapper
->
shm
.
id
,
pWrapper
->
shm
.
size
);
dDebug
(
"shmid:%d, is closed, size:%
"
PRId64
,
pWrapper
->
shm
.
id
,
pWrapper
->
shm
.
size
);
taosDropShm
(
&
pWrapper
->
shm
);
}
}
...
...
@@ -177,7 +194,7 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) {
dError
(
"shmid:%d, failed to attach since %s"
,
pWrapper
->
shm
.
id
,
terrstr
());
goto
_OVER
;
}
dDebug
(
"shmid:%d, is attached, size:%
d"
,
pWrapper
->
shm
.
id
,
pWrapper
->
shm
.
size
);
dDebug
(
"shmid:%d, is attached, size:%
"
PRId64
,
pWrapper
->
shm
.
id
,
pWrapper
->
shm
.
size
);
}
dDebug
(
"successed to open %s"
,
file
);
...
...
@@ -185,16 +202,12 @@ int32_t dndOpenRuntimeFile(SDnode *pDnode) {
_OVER:
if
(
root
!=
NULL
)
cJSON_Delete
(
root
);
if
(
code
!=
0
)
{
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
}
else
{
pDnode
->
runtimeFile
=
pFile
;
}
if
(
pFile
!=
NULL
)
taosCloseFile
(
&
pFile
);
return
code
;
}
int32_t
dndWrite
Runtime
File
(
SDnode
*
pDnode
)
{
int32_t
dndWrite
Shm
File
(
SDnode
*
pDnode
)
{
int32_t
code
=
-
1
;
int32_t
len
=
0
;
char
content
[
MAXLEN
+
1
]
=
{
0
};
...
...
@@ -202,8 +215,8 @@ int32_t dndWriteRuntimeFile(SDnode *pDnode) {
char
realfile
[
PATH_MAX
]
=
{
0
};
TdFilePtr
pFile
=
NULL
;
snprintf
(
file
,
sizeof
(
file
),
"%s%s.
running
.bak"
,
pDnode
->
dataDir
,
TD_DIRSEP
);
snprintf
(
realfile
,
sizeof
(
realfile
),
"%s%s.
running
"
,
pDnode
->
dataDir
,
TD_DIRSEP
);
snprintf
(
file
,
sizeof
(
file
),
"%s%s.
shmfile
.bak"
,
pDnode
->
dataDir
,
TD_DIRSEP
);
snprintf
(
realfile
,
sizeof
(
realfile
),
"%s%s.
shmfile
"
,
pDnode
->
dataDir
,
TD_DIRSEP
);
pFile
=
taosOpenFile
(
file
,
TD_FILE_CTEATE
|
TD_FILE_WRITE
|
TD_FILE_TRUNC
);
if
(
pFile
==
NULL
)
{
...
...
@@ -215,11 +228,13 @@ int32_t dndWriteRuntimeFile(SDnode *pDnode) {
len
+=
snprintf
(
content
+
len
,
MAXLEN
-
len
,
"{
\n
"
);
for
(
ENodeType
ntype
=
DNODE
+
1
;
ntype
<
NODE_MAX
;
++
ntype
)
{
SMgmtWrapper
*
pWrapper
=
&
pDnode
->
wrappers
[
pDnode
->
ntype
];
len
+=
snprintf
(
content
+
len
,
MAXLEN
-
len
,
"
\"
%s_shmid
\"
:
%d
,
\n
"
,
dndNodeProcStr
(
ntype
),
pWrapper
->
shm
.
id
);
len
+=
snprintf
(
content
+
len
,
MAXLEN
-
len
,
"
\"
%s_shmid
\"
:
\"
%d
\"
,
\n
"
,
dndNodeProcStr
(
ntype
),
pWrapper
->
shm
.
id
);
if
(
ntype
==
NODE_MAX
-
1
)
{
len
+=
snprintf
(
content
+
len
,
MAXLEN
-
len
,
"
\"
%s_shmsize
\"
: %d
\n
"
,
dndNodeProcStr
(
ntype
),
pWrapper
->
shm
.
size
);
len
+=
snprintf
(
content
+
len
,
MAXLEN
-
len
,
"
\"
%s_shmsize
\"
:
\"
%"
PRId64
"
\"\n
"
,
dndNodeProcStr
(
ntype
),
pWrapper
->
shm
.
size
);
}
else
{
len
+=
snprintf
(
content
+
len
,
MAXLEN
-
len
,
"
\"
%s_shmsize
\"
: %d,
\n
"
,
dndNodeProcStr
(
ntype
),
pWrapper
->
shm
.
size
);
len
+=
snprintf
(
content
+
len
,
MAXLEN
-
len
,
"
\"
%s_shmsize
\"
:
\"
%"
PRId64
"
\"
,
\n
"
,
dndNodeProcStr
(
ntype
),
pWrapper
->
shm
.
size
);
}
}
len
+=
snprintf
(
content
+
len
,
MAXLEN
-
len
,
"}
\n
"
);
...
...
@@ -254,11 +269,3 @@ _OVER:
return
code
;
}
void
dndCloseRuntimeFile
(
SDnode
*
pDnode
)
{
if
(
pDnode
->
runtimeFile
)
{
taosUnLockFile
(
pDnode
->
runtimeFile
);
taosCloseFile
(
&
pDnode
->
runtimeFile
);
pDnode
->
runtimeFile
=
NULL
;
}
}
\ No newline at end of file
source/dnode/mgmt/main/src/dndObj.c
浏览文件 @
ae182cd7
...
...
@@ -34,6 +34,12 @@ static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) {
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
pDnode
->
lockfile
=
dndCheckRunning
(
pDnode
->
dataDir
);
if
(
pDnode
->
lockfile
==
NULL
)
{
return
-
1
;
}
return
0
;
}
...
...
@@ -42,7 +48,11 @@ static void dndClearVars(SDnode *pDnode) {
SMgmtWrapper
*
pMgmt
=
&
pDnode
->
wrappers
[
n
];
taosMemoryFreeClear
(
pMgmt
->
path
);
}
dndCloseRuntimeFile
(
pDnode
);
if
(
pDnode
->
lockfile
!=
NULL
)
{
taosUnLockFile
(
pDnode
->
lockfile
);
taosCloseFile
(
&
pDnode
->
lockfile
);
pDnode
->
lockfile
=
NULL
;
}
taosMemoryFreeClear
(
pDnode
->
localEp
);
taosMemoryFreeClear
(
pDnode
->
localFqdn
);
taosMemoryFreeClear
(
pDnode
->
firstEp
);
...
...
@@ -96,8 +106,8 @@ SDnode *dndCreate(const SDnodeOpt *pOption) {
goto
_OVER
;
}
if
(
dnd
OpenRuntime
File
(
pDnode
)
!=
0
)
{
dError
(
"failed to
open runtime
file since %s"
,
terrstr
());
if
(
dnd
ReadShm
File
(
pDnode
)
!=
0
)
{
dError
(
"failed to
read shm
file since %s"
,
terrstr
());
goto
_OVER
;
}
...
...
source/os/src/osShm.c
浏览文件 @
ae182cd7
...
...
@@ -17,8 +17,8 @@
#define _DEFAULT_SOURCE
#include "os.h"
int32_t
taosCreateShm
(
SShm
*
pShm
,
int
32
_t
shmsize
)
{
int32_t
shmid
=
shmget
(
IPC_PRIVATE
,
shmsize
,
IPC_CREAT
|
0600
);
int32_t
taosCreateShm
(
SShm
*
pShm
,
int
64
_t
shmsize
)
{
int32_t
shmid
=
shmget
(
IPC_PRIVATE
,
(
size_t
)
shmsize
,
IPC_CREAT
|
0600
);
if
(
shmid
<
0
)
{
return
-
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录