Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a881adcf
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看板
提交
a881adcf
编写于
12月 29, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
alloc vgroups
上级
c9f8a110
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
84 addition
and
28 deletion
+84
-28
source/dnode/mgmt/daemon/src/daemon.c
source/dnode/mgmt/daemon/src/daemon.c
+1
-1
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+1
-0
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+2
-2
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+80
-25
未找到文件。
source/dnode/mgmt/daemon/src/daemon.c
浏览文件 @
a881adcf
...
...
@@ -139,7 +139,7 @@ void dmnWaitSignal() {
void
dmnInitOption
(
SDnodeOpt
*
pOption
)
{
pOption
->
sver
=
30000000
;
//3.0.0.0
pOption
->
numOfCores
=
tsNumOfCores
;
pOption
->
numOfSupportVnodes
=
1
;
pOption
->
numOfSupportVnodes
=
1
6
;
pOption
->
numOfCommitThreads
=
1
;
pOption
->
statusInterval
=
tsStatusInterval
;
pOption
->
numOfThreadsPerCore
=
tsNumOfThreadsPerCore
;
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
a881adcf
...
...
@@ -124,6 +124,7 @@ typedef struct {
int64_t
rebootTime
;
int64_t
lastAccessTime
;
int32_t
accessTimes
;
int16_t
numOfVnodes
;
int16_t
numOfSupportVnodes
;
int16_t
numOfCores
;
EDndStatus
status
;
...
...
source/dnode/mnode/impl/src/mndTrans.c
浏览文件 @
a881adcf
...
...
@@ -442,7 +442,7 @@ static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
}
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
m
Trace
(
"trans:%d, sync to other nodes"
,
pTrans
->
id
);
m
Debug
(
"trans:%d, sync to other nodes"
,
pTrans
->
id
);
int32_t
code
=
mndSyncPropose
(
pMnode
,
pRaw
);
if
(
code
!=
0
)
{
mError
(
"trans:%d, failed to sync since %s"
,
pTrans
->
id
,
terrstr
());
...
...
@@ -450,7 +450,7 @@ static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
return
-
1
;
}
m
Trace
(
"trans:%d, sync finished"
,
pTrans
->
id
);
m
Debug
(
"trans:%d, sync finished"
,
pTrans
->
id
);
code
=
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
if
(
code
!=
0
)
{
...
...
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
a881adcf
...
...
@@ -86,7 +86,6 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
for
(
int8_t
i
=
0
;
i
<
pVgroup
->
replica
;
++
i
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
SDB_SET_INT32
(
pRaw
,
dataPos
,
pVgid
->
dnodeId
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pVgid
->
role
)
}
SDB_SET_RESERVE
(
pRaw
,
dataPos
,
TSDB_VGROUP_RESERVE_SIZE
)
SDB_SET_DATALEN
(
pRaw
,
dataPos
);
...
...
@@ -121,7 +120,6 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
for
(
int8_t
i
=
0
;
i
<
pVgroup
->
replica
;
++
i
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
i
];
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pVgid
->
dnodeId
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
(
int8_t
*
)
&
pVgid
->
role
)
}
SDB_GET_RESERVE
(
pRaw
,
pRow
,
dataPos
,
TSDB_VGROUP_RESERVE_SIZE
)
...
...
@@ -237,44 +235,95 @@ SDropVnodeMsg *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *p
return
pDrop
;
}
static
int32_t
mndGetAvailableDnode
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
)
{
static
SArray
*
mndBuildDnodesArray
(
SMnode
*
pMnode
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
allocedVnodes
=
0
;
void
*
pIter
=
NULL
;
int32_t
numOfDnodes
=
mndGetDnodeSize
(
pMnode
);
SArray
*
pArray
=
taosArrayInit
(
numOfDnodes
,
sizeof
(
SDnodeObj
));
if
(
pArray
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
while
(
allocedVnodes
<
pVgroup
->
replica
)
{
void
*
pIter
=
NULL
;
while
(
1
)
{
SDnodeObj
*
pDnode
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_DNODE
,
pIter
,
(
void
**
)
&
pDnode
);
if
(
pIter
==
NULL
)
break
;
// todo
if
(
mndIsDnodeInReadyStatus
(
pMnode
,
pDnode
))
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
allocedVnodes
]
;
pVgid
->
dnodeId
=
pDnode
->
id
;
if
(
pVgroup
->
replica
==
1
)
{
pVgid
->
role
=
TAOS_SYNC_STATE_LEADER
;
}
else
{
pVgid
->
role
=
TAOS_SYNC_STATE_FOLLOWER
;
}
allocedVnodes
++
;
int32_t
numOfVnodes
=
mndGetVnodesNum
(
pMnode
,
pDnode
->
id
);
bool
isMnode
=
mndIsMnode
(
pMnode
,
pDnode
->
id
)
;
if
(
isMnode
)
{
pDnode
->
numOfVnodes
++
;
}
bool
isReady
=
mndIsDnodeInReadyStatus
(
pMnode
,
pDnode
)
;
if
(
isReady
)
{
taosArrayPush
(
pArray
,
pDnode
)
;
}
mDebug
(
"dnode:%d, numOfVnodes:%d numOfSupportVnodes:%d isMnode:%d ready:%d"
,
pDnode
->
id
,
numOfVnodes
,
pDnode
->
numOfSupportVnodes
,
isMnode
,
isReady
);
sdbRelease
(
pSdb
,
pDnode
);
}
if
(
allocedVnodes
!=
pVgroup
->
replica
)
{
terrno
=
TSDB_CODE_MND_NO_ENOUGH_DNODES
;
return
-
1
;
return
pArray
;
}
static
int32_t
mndCompareDnodeVnodes
(
SDnodeObj
*
pDnode1
,
SDnodeObj
*
pDnode2
)
{
float
d1Score
=
(
float
)
pDnode1
->
numOfVnodes
/
pDnode1
->
numOfSupportVnodes
;
float
d2Score
=
(
float
)
pDnode2
->
numOfVnodes
/
pDnode2
->
numOfSupportVnodes
;
return
d1Score
>
d2Score
?
0
:
1
;
}
static
int32_t
mndGetAvailableDnode
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
,
SArray
*
pArray
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
allocedVnodes
=
0
;
void
*
pIter
=
NULL
;
taosArraySort
(
pArray
,
(
__compar_fn_t
)
mndCompareDnodeVnodes
);
for
(
int32_t
v
=
0
;
v
<
pVgroup
->
replica
;
++
v
)
{
SVnodeGid
*
pVgid
=
&
pVgroup
->
vnodeGid
[
v
];
SDnodeObj
*
pDnode
=
taosArrayGet
(
pArray
,
v
);
if
(
pDnode
==
NULL
||
pDnode
->
numOfVnodes
>
pDnode
->
numOfSupportVnodes
)
{
terrno
=
TSDB_CODE_MND_NO_ENOUGH_DNODES
;
return
-
1
;
}
pVgid
->
dnodeId
=
pDnode
->
id
;
if
(
pVgroup
->
replica
==
1
)
{
pVgid
->
role
=
TAOS_SYNC_STATE_LEADER
;
}
else
{
pVgid
->
role
=
TAOS_SYNC_STATE_FOLLOWER
;
}
mDebug
(
"db:%s, vgId:%d, vindex:%d dnodeId:%d is alloced"
,
pVgroup
->
dbName
,
pVgroup
->
vgId
,
v
,
pVgid
->
dnodeId
);
pDnode
->
numOfVnodes
++
;
}
return
0
;
}
int32_t
mndAllocVgroup
(
SMnode
*
pMnode
,
SDbObj
*
pDb
,
SVgObj
**
ppVgroups
)
{
SVgObj
*
pVgroups
=
calloc
(
pDb
->
cfg
.
numOfVgroups
,
sizeof
(
SVgObj
));
int32_t
code
=
-
1
;
SArray
*
pArray
=
NULL
;
SVgObj
*
pVgroups
=
NULL
;
pVgroups
=
calloc
(
pDb
->
cfg
.
numOfVgroups
,
sizeof
(
SVgObj
));
if
(
pVgroups
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
goto
ALLOC_VGROUP_OVER
;
}
pArray
=
mndBuildDnodesArray
(
pMnode
);
if
(
pArray
==
NULL
)
{
goto
ALLOC_VGROUP_OVER
;
}
mDebug
(
"db:%s, total %d dnodes used to create %d vgroups (%d vnodes)"
,
pDb
->
name
,
(
int32_t
)
taosArrayGetSize
(
pArray
),
pDb
->
cfg
.
numOfVgroups
,
pDb
->
cfg
.
numOfVgroups
*
pDb
->
cfg
.
replications
);
int32_t
allocedVgroups
=
0
;
int32_t
maxVgId
=
sdbGetMaxId
(
pMnode
->
pSdb
,
SDB_VGROUP
);
uint32_t
hashMin
=
0
;
...
...
@@ -298,17 +347,23 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
pVgroup
->
dbUid
=
pDb
->
uid
;
pVgroup
->
replica
=
pDb
->
cfg
.
replications
;
if
(
mndGetAvailableDnode
(
pMnode
,
pVgroup
)
!=
0
)
{
if
(
mndGetAvailableDnode
(
pMnode
,
pVgroup
,
pArray
)
!=
0
)
{
terrno
=
TSDB_CODE_MND_NO_ENOUGH_DNODES
;
free
(
pVgroups
);
return
-
1
;
goto
ALLOC_VGROUP_OVER
;
}
allocedVgroups
++
;
}
*
ppVgroups
=
pVgroups
;
return
0
;
code
=
0
;
mDebug
(
"db:%s, %d vgroups is alloced, replica:%d"
,
pDb
->
name
,
pDb
->
cfg
.
numOfVgroups
,
pDb
->
cfg
.
replications
);
ALLOC_VGROUP_OVER:
if
(
code
!=
0
)
free
(
pVgroups
);
taosArrayDestroy
(
pArray
);
return
code
;
}
SEpSet
mndGetVgroupEpset
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录