Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ca870415
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ca870415
编写于
12月 03, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-2270
上级
551827eb
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
612 addition
and
496 deletion
+612
-496
src/balance/inc/bnMain.h
src/balance/inc/bnMain.h
+56
-0
src/balance/inc/bnScore.h
src/balance/inc/bnScore.h
+34
-0
src/balance/inc/bnThread.h
src/balance/inc/bnThread.h
+7
-6
src/balance/src/balanceMain.c
src/balance/src/balanceMain.c
+110
-449
src/balance/src/bnScore.c
src/balance/src/bnScore.c
+328
-0
src/balance/src/bnThread.c
src/balance/src/bnThread.c
+53
-17
src/inc/tbalance.h
src/inc/tbalance.h
+8
-8
src/mnode/src/mnodeDb.c
src/mnode/src/mnodeDb.c
+1
-1
src/mnode/src/mnodeDnode.c
src/mnode/src/mnodeDnode.c
+12
-12
src/mnode/src/mnodeMain.c
src/mnode/src/mnodeMain.c
+1
-1
src/mnode/src/mnodeSdb.c
src/mnode/src/mnodeSdb.c
+1
-1
src/mnode/src/mnodeVgroup.c
src/mnode/src/mnodeVgroup.c
+1
-1
未找到文件。
src/balance/inc/bnMain.h
0 → 100644
浏览文件 @
ca870415
/*
* 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_BALANCE_MAIN_H
#define TDENGINE_BALANCE_MAIN_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "mnodeInt.h"
#include "mnodeDnode.h"
typedef
struct
{
int32_t
size
;
int32_t
maxSize
;
SDnodeObj
**
list
;
}
SBnDnodes
;
typedef
struct
{
void
*
timer
;
bool
stop
;
pthread_mutex_t
mutex
;
pthread_cond_t
cond
;
pthread_t
thread
;
}
SBnThread
;
typedef
struct
{
pthread_mutex_t
mutex
;
}
SBnMgmt
;
int32_t
bnInit
();
void
bnCleanUp
();
bool
bnStart
();
void
bnCheckStatus
();
void
bnCheckModules
();
extern
SBnDnodes
tsBnDnodes
;
extern
void
*
tsMnodeTmr
;
#ifdef __cplusplus
}
#endif
#endif
src/balance/inc/bnScore.h
0 → 100644
浏览文件 @
ca870415
/*
* 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_BALANCE_SCORE_H
#define TDENGINE_BALANCE_SCORE_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "bnMain.h"
void
bnInitDnodes
();
void
bnCleanupDnodes
();
void
bnAccquireDnodes
();
void
bnReleaseDnodes
();
float
bnTryCalcDnodeScore
(
SDnodeObj
*
pDnode
,
int32_t
extraVnode
);
#ifdef __cplusplus
}
#endif
#endif
src/balance/inc/bnThread.h
浏览文件 @
ca870415
...
@@ -13,17 +13,18 @@
...
@@ -13,17 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#ifndef TDENGINE_BALANCE_H
#ifndef TDENGINE_BALANCE_
THREAD_
H
#define TDENGINE_BALANCE_H
#define TDENGINE_BALANCE_
THREAD_
H
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
#endif
#endif
#include "bnMain.h"
int32_t
bn
ThreadInit
();
int32_t
bn
InitThread
();
void
bn
ThreadCleanup
();
void
bn
CleanupThread
();
void
bn
ThreadSync
Notify
();
void
bnNotify
();
void
bn
ThreadAsyncNotify
(
);
void
bn
StartTimer
(
int64_t
mseconds
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/balance/src/balanceMain.c
浏览文件 @
ca870415
...
@@ -33,36 +33,23 @@
...
@@ -33,36 +33,23 @@
#include "mnodeUser.h"
#include "mnodeUser.h"
#include "mnodeVgroup.h"
#include "mnodeVgroup.h"
/*
#include "bnMain.h"
* once sdb work as mater, then tsAccessSquence reset to zero
#include "bnScore.h"
* increase tsAccessSquence every balance interval
#include "bnThread.h"
*/
extern
void
*
tsMnodeTmr
;
static
SBnMgmt
tsBnMgmt
;;
static
void
*
tsBalanceTimer
=
NULL
;
static
int32_t
tsBalanceDnodeListSize
=
0
;
static
void
bnMonitorDnodeModule
();
static
SDnodeObj
**
tsBalanceDnodeList
=
NULL
;
static
int32_t
tsBalanceDnodeListMallocSize
=
16
;
static
void
bnLock
()
{
static
pthread_mutex_t
tsBalanceMutex
;
pthread_mutex_lock
(
&
tsBnMgmt
.
mutex
);
static
void
balanceStartTimer
(
int64_t
mseconds
);
static
void
balanceInitDnodeList
();
static
void
balanceCleanupDnodeList
();
static
void
balanceAccquireDnodeList
();
static
void
balanceReleaseDnodeList
();
static
void
balanceMonitorDnodeModule
();
static
float
balanceTryCalcDnodeScore
(
SDnodeObj
*
pDnode
,
int32_t
extraVnode
);
static
int32_t
balanceGetScoresMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
balanceRetrieveScores
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
void
balanceLock
()
{
pthread_mutex_lock
(
&
tsBalanceMutex
);
}
}
static
void
b
alance
UnLock
()
{
static
void
b
n
UnLock
()
{
pthread_mutex_unlock
(
&
tsB
alanceM
utex
);
pthread_mutex_unlock
(
&
tsB
nMgmt
.
m
utex
);
}
}
static
bool
b
alance
CheckFree
(
SDnodeObj
*
pDnode
)
{
static
bool
b
n
CheckFree
(
SDnodeObj
*
pDnode
)
{
if
(
pDnode
->
status
==
TAOS_DN_STATUS_DROPPING
||
pDnode
->
status
==
TAOS_DN_STATUS_OFFLINE
)
{
if
(
pDnode
->
status
==
TAOS_DN_STATUS_DROPPING
||
pDnode
->
status
==
TAOS_DN_STATUS_OFFLINE
)
{
mError
(
"dnode:%d, status:%s not available"
,
pDnode
->
dnodeId
,
mnodeGetDnodeStatusStr
(
pDnode
->
status
));
mError
(
"dnode:%d, status:%s not available"
,
pDnode
->
dnodeId
,
mnodeGetDnodeStatusStr
(
pDnode
->
status
));
return
false
;
return
false
;
...
@@ -86,7 +73,7 @@ static bool balanceCheckFree(SDnodeObj *pDnode) {
...
@@ -86,7 +73,7 @@ static bool balanceCheckFree(SDnodeObj *pDnode) {
return
true
;
return
true
;
}
}
static
void
b
alance
DiscardVnode
(
SVgObj
*
pVgroup
,
SVnodeGid
*
pVnodeGid
)
{
static
void
b
n
DiscardVnode
(
SVgObj
*
pVgroup
,
SVnodeGid
*
pVnodeGid
)
{
mDebug
(
"vgId:%d, dnode:%d is dropping"
,
pVgroup
->
vgId
,
pVnodeGid
->
dnodeId
);
mDebug
(
"vgId:%d, dnode:%d is dropping"
,
pVgroup
->
vgId
,
pVnodeGid
->
dnodeId
);
SDnodeObj
*
pDnode
=
mnodeGetDnode
(
pVnodeGid
->
dnodeId
);
SDnodeObj
*
pDnode
=
mnodeGetDnode
(
pVnodeGid
->
dnodeId
);
...
@@ -111,27 +98,26 @@ static void balanceDiscardVnode(SVgObj *pVgroup, SVnodeGid *pVnodeGid) {
...
@@ -111,27 +98,26 @@ static void balanceDiscardVnode(SVgObj *pVgroup, SVnodeGid *pVnodeGid) {
mnodeUpdateVgroup
(
pVgroup
);
mnodeUpdateVgroup
(
pVgroup
);
}
}
static
void
b
alance
SwapVnodeGid
(
SVnodeGid
*
pVnodeGid1
,
SVnodeGid
*
pVnodeGid2
)
{
static
void
b
n
SwapVnodeGid
(
SVnodeGid
*
pVnodeGid1
,
SVnodeGid
*
pVnodeGid2
)
{
// SVnodeGid tmp = *pVnodeGid1;
// SVnodeGid tmp = *pVnodeGid1;
// *pVnodeGid1 = *pVnodeGid2;
// *pVnodeGid1 = *pVnodeGid2;
// *pVnodeGid2 = tmp;
// *pVnodeGid2 = tmp;
}
}
int32_t
b
alance
AllocVnodes
(
SVgObj
*
pVgroup
)
{
int32_t
b
n
AllocVnodes
(
SVgObj
*
pVgroup
)
{
static
int32_t
randIndex
=
0
;
static
int32_t
randIndex
=
0
;
int32_t
dnode
=
0
;
int32_t
dnode
=
0
;
int32_t
vnodes
=
0
;
int32_t
vnodes
=
0
;
balanceLock
();
bnLock
();
bnAccquireDnodes
();
balanceAccquireDnodeList
();
mDebug
(
"db:%s, try alloc %d vnodes to vgroup, dnodes total:%d, avail:%d"
,
pVgroup
->
dbName
,
pVgroup
->
numOfVnodes
,
mDebug
(
"db:%s, try alloc %d vnodes to vgroup, dnodes total:%d, avail:%d"
,
pVgroup
->
dbName
,
pVgroup
->
numOfVnodes
,
mnodeGetDnodesNum
(),
tsB
alanceDnodeListS
ize
);
mnodeGetDnodesNum
(),
tsB
nDnodes
.
s
ize
);
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
for
(;
dnode
<
tsB
alanceDnodeListS
ize
;
++
dnode
)
{
for
(;
dnode
<
tsB
nDnodes
.
s
ize
;
++
dnode
)
{
SDnodeObj
*
pDnode
=
tsB
alanceDnodeL
ist
[
dnode
];
SDnodeObj
*
pDnode
=
tsB
nDnodes
.
l
ist
[
dnode
];
if
(
b
alance
CheckFree
(
pDnode
))
{
if
(
b
n
CheckFree
(
pDnode
))
{
SVnodeGid
*
pVnodeGid
=
pVgroup
->
vnodeGid
+
i
;
SVnodeGid
*
pVnodeGid
=
pVgroup
->
vnodeGid
+
i
;
pVnodeGid
->
dnodeId
=
pDnode
->
dnodeId
;
pVnodeGid
->
dnodeId
=
pDnode
->
dnodeId
;
pVnodeGid
->
pDnode
=
pDnode
;
pVnodeGid
->
pDnode
=
pDnode
;
...
@@ -148,8 +134,8 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
...
@@ -148,8 +134,8 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
}
}
if
(
vnodes
!=
pVgroup
->
numOfVnodes
)
{
if
(
vnodes
!=
pVgroup
->
numOfVnodes
)
{
b
alanceReleaseDnodeList
();
b
nReleaseDnodes
();
b
alance
UnLock
();
b
n
UnLock
();
mDebug
(
"db:%s, need vnodes:%d, but alloc:%d"
,
pVgroup
->
dbName
,
pVgroup
->
numOfVnodes
,
vnodes
);
mDebug
(
"db:%s, need vnodes:%d, but alloc:%d"
,
pVgroup
->
dbName
,
pVgroup
->
numOfVnodes
,
vnodes
);
...
@@ -179,33 +165,33 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
...
@@ -179,33 +165,33 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
if
(
pVgroup
->
numOfVnodes
==
1
)
{
if
(
pVgroup
->
numOfVnodes
==
1
)
{
}
else
if
(
pVgroup
->
numOfVnodes
==
2
)
{
}
else
if
(
pVgroup
->
numOfVnodes
==
2
)
{
if
(
randIndex
++
%
2
==
0
)
{
if
(
randIndex
++
%
2
==
0
)
{
b
alance
SwapVnodeGid
(
pVgroup
->
vnodeGid
,
pVgroup
->
vnodeGid
+
1
);
b
n
SwapVnodeGid
(
pVgroup
->
vnodeGid
,
pVgroup
->
vnodeGid
+
1
);
}
}
}
else
{
}
else
{
int32_t
randVal
=
randIndex
++
%
6
;
int32_t
randVal
=
randIndex
++
%
6
;
if
(
randVal
==
1
)
{
// 1, 0, 2
if
(
randVal
==
1
)
{
// 1, 0, 2
b
alance
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
0
,
pVgroup
->
vnodeGid
+
1
);
b
n
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
0
,
pVgroup
->
vnodeGid
+
1
);
}
else
if
(
randVal
==
2
)
{
// 1, 2, 0
}
else
if
(
randVal
==
2
)
{
// 1, 2, 0
b
alance
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
0
,
pVgroup
->
vnodeGid
+
1
);
b
n
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
0
,
pVgroup
->
vnodeGid
+
1
);
b
alance
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
1
,
pVgroup
->
vnodeGid
+
2
);
b
n
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
1
,
pVgroup
->
vnodeGid
+
2
);
}
else
if
(
randVal
==
3
)
{
// 2, 1, 0
}
else
if
(
randVal
==
3
)
{
// 2, 1, 0
b
alance
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
0
,
pVgroup
->
vnodeGid
+
2
);
b
n
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
0
,
pVgroup
->
vnodeGid
+
2
);
}
else
if
(
randVal
==
4
)
{
// 2, 0, 1
}
else
if
(
randVal
==
4
)
{
// 2, 0, 1
b
alance
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
0
,
pVgroup
->
vnodeGid
+
2
);
b
n
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
0
,
pVgroup
->
vnodeGid
+
2
);
b
alance
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
1
,
pVgroup
->
vnodeGid
+
2
);
b
n
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
1
,
pVgroup
->
vnodeGid
+
2
);
}
}
if
(
randVal
==
5
)
{
// 0, 2, 1
if
(
randVal
==
5
)
{
// 0, 2, 1
b
alance
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
1
,
pVgroup
->
vnodeGid
+
2
);
b
n
SwapVnodeGid
(
pVgroup
->
vnodeGid
+
1
,
pVgroup
->
vnodeGid
+
2
);
}
else
{
}
else
{
}
// 0, 1, 2
}
// 0, 1, 2
}
}
b
alanceReleaseDnodeList
();
b
nReleaseDnodes
();
b
alance
UnLock
();
b
n
UnLock
();
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
bool
b
alance
CheckVgroupReady
(
SVgObj
*
pVgroup
,
SVnodeGid
*
pRmVnode
)
{
static
bool
b
n
CheckVgroupReady
(
SVgObj
*
pVgroup
,
SVnodeGid
*
pRmVnode
)
{
if
(
pVgroup
->
lbTime
+
5
*
tsStatusInterval
>
tsAccessSquence
)
{
if
(
pVgroup
->
lbTime
+
5
*
tsStatusInterval
>
tsAccessSquence
)
{
return
false
;
return
false
;
}
}
...
@@ -232,7 +218,7 @@ static bool balanceCheckVgroupReady(SVgObj *pVgroup, SVnodeGid *pRmVnode) {
...
@@ -232,7 +218,7 @@ static bool balanceCheckVgroupReady(SVgObj *pVgroup, SVnodeGid *pRmVnode) {
* desc: remove one vnode from vgroup
* desc: remove one vnode from vgroup
* all vnodes in vgroup should in ready state, except the balancing one
* all vnodes in vgroup should in ready state, except the balancing one
**/
**/
static
int32_t
b
alance
RemoveVnode
(
SVgObj
*
pVgroup
)
{
static
int32_t
b
n
RemoveVnode
(
SVgObj
*
pVgroup
)
{
if
(
pVgroup
->
numOfVnodes
<=
1
)
return
-
1
;
if
(
pVgroup
->
numOfVnodes
<=
1
)
return
-
1
;
SVnodeGid
*
pRmVnode
=
NULL
;
SVnodeGid
*
pRmVnode
=
NULL
;
...
@@ -274,17 +260,17 @@ static int32_t balanceRemoveVnode(SVgObj *pVgroup) {
...
@@ -274,17 +260,17 @@ static int32_t balanceRemoveVnode(SVgObj *pVgroup) {
pSelVnode
=
pRmVnode
;
pSelVnode
=
pRmVnode
;
}
}
if
(
!
b
alance
CheckVgroupReady
(
pVgroup
,
pSelVnode
))
{
if
(
!
b
n
CheckVgroupReady
(
pVgroup
,
pSelVnode
))
{
mDebug
(
"vgId:%d, is not ready"
,
pVgroup
->
vgId
);
mDebug
(
"vgId:%d, is not ready"
,
pVgroup
->
vgId
);
return
-
1
;
return
-
1
;
}
else
{
}
else
{
mDebug
(
"vgId:%d, is ready, discard dnode:%d"
,
pVgroup
->
vgId
,
pSelVnode
->
dnodeId
);
mDebug
(
"vgId:%d, is ready, discard dnode:%d"
,
pVgroup
->
vgId
,
pSelVnode
->
dnodeId
);
b
alance
DiscardVnode
(
pVgroup
,
pSelVnode
);
b
n
DiscardVnode
(
pVgroup
,
pSelVnode
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
}
}
static
bool
b
alance
CheckDnodeInVgroup
(
SDnodeObj
*
pDnode
,
SVgObj
*
pVgroup
)
{
static
bool
b
n
CheckDnodeInVgroup
(
SDnodeObj
*
pDnode
,
SVgObj
*
pVgroup
)
{
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pVgroup
->
numOfVnodes
;
++
i
)
{
SVnodeGid
*
pGid
=
&
pVgroup
->
vnodeGid
[
i
];
SVnodeGid
*
pGid
=
&
pVgroup
->
vnodeGid
[
i
];
if
(
pGid
->
dnodeId
==
0
)
break
;
if
(
pGid
->
dnodeId
==
0
)
break
;
...
@@ -299,13 +285,13 @@ static bool balanceCheckDnodeInVgroup(SDnodeObj *pDnode, SVgObj *pVgroup) {
...
@@ -299,13 +285,13 @@ static bool balanceCheckDnodeInVgroup(SDnodeObj *pDnode, SVgObj *pVgroup) {
/**
/**
* desc: add vnode to vgroup, find a new one if dest dnode is null
* desc: add vnode to vgroup, find a new one if dest dnode is null
**/
**/
static
int32_t
b
alance
AddVnode
(
SVgObj
*
pVgroup
,
SDnodeObj
*
pSrcDnode
,
SDnodeObj
*
pDestDnode
)
{
static
int32_t
b
n
AddVnode
(
SVgObj
*
pVgroup
,
SDnodeObj
*
pSrcDnode
,
SDnodeObj
*
pDestDnode
)
{
if
(
pDestDnode
==
NULL
)
{
if
(
pDestDnode
==
NULL
)
{
for
(
int32_t
i
=
0
;
i
<
tsB
alanceDnodeListS
ize
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
tsB
nDnodes
.
s
ize
;
++
i
)
{
SDnodeObj
*
pDnode
=
tsB
alanceDnodeL
ist
[
i
];
SDnodeObj
*
pDnode
=
tsB
nDnodes
.
l
ist
[
i
];
if
(
pDnode
==
pSrcDnode
)
continue
;
if
(
pDnode
==
pSrcDnode
)
continue
;
if
(
b
alance
CheckDnodeInVgroup
(
pDnode
,
pVgroup
))
continue
;
if
(
b
n
CheckDnodeInVgroup
(
pDnode
,
pVgroup
))
continue
;
if
(
!
b
alance
CheckFree
(
pDnode
))
continue
;
if
(
!
b
n
CheckFree
(
pDnode
))
continue
;
pDestDnode
=
pDnode
;
pDestDnode
=
pDnode
;
mDebug
(
"vgId:%d, add vnode to dnode:%d"
,
pVgroup
->
vgId
,
pDnode
->
dnodeId
);
mDebug
(
"vgId:%d, add vnode to dnode:%d"
,
pVgroup
->
vgId
,
pDnode
->
dnodeId
);
...
@@ -333,25 +319,25 @@ static int32_t balanceAddVnode(SVgObj *pVgroup, SDnodeObj *pSrcDnode, SDnodeObj
...
@@ -333,25 +319,25 @@ static int32_t balanceAddVnode(SVgObj *pVgroup, SDnodeObj *pSrcDnode, SDnodeObj
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
bool
b
alance
MonitorBalance
()
{
static
bool
b
n
MonitorBalance
()
{
if
(
tsB
alanceDnodeListS
ize
<
2
)
return
false
;
if
(
tsB
nDnodes
.
s
ize
<
2
)
return
false
;
for
(
int32_t
src
=
tsB
alanceDnodeListS
ize
-
1
;
src
>=
0
;
--
src
)
{
for
(
int32_t
src
=
tsB
nDnodes
.
s
ize
-
1
;
src
>=
0
;
--
src
)
{
SDnodeObj
*
pDnode
=
tsB
alanceDnodeL
ist
[
src
];
SDnodeObj
*
pDnode
=
tsB
nDnodes
.
l
ist
[
src
];
mDebug
(
"%d-dnode:%d, state:%s, score:%.1f, numOfCores:%d, openVnodes:%d"
,
tsB
alanceDnodeListS
ize
-
src
-
1
,
mDebug
(
"%d-dnode:%d, state:%s, score:%.1f, numOfCores:%d, openVnodes:%d"
,
tsB
nDnodes
.
s
ize
-
src
-
1
,
pDnode
->
dnodeId
,
mnodeGetDnodeStatusStr
(
pDnode
->
status
),
pDnode
->
score
,
pDnode
->
numOfCores
,
pDnode
->
dnodeId
,
mnodeGetDnodeStatusStr
(
pDnode
->
status
),
pDnode
->
score
,
pDnode
->
numOfCores
,
pDnode
->
openVnodes
);
pDnode
->
openVnodes
);
}
}
float
scoresDiff
=
tsB
alanceDnodeList
[
tsBalanceDnodeListSize
-
1
]
->
score
-
tsBalanceDnodeL
ist
[
0
]
->
score
;
float
scoresDiff
=
tsB
nDnodes
.
list
[
tsBnDnodes
.
size
-
1
]
->
score
-
tsBnDnodes
.
l
ist
[
0
]
->
score
;
if
(
scoresDiff
<
0
.
01
)
{
if
(
scoresDiff
<
0
.
01
)
{
mDebug
(
"all dnodes:%d is already balanced, scoresDiff:%f"
,
tsB
alanceDnodeListS
ize
,
scoresDiff
);
mDebug
(
"all dnodes:%d is already balanced, scoresDiff:%f"
,
tsB
nDnodes
.
s
ize
,
scoresDiff
);
return
false
;
return
false
;
}
}
for
(
int32_t
src
=
tsB
alanceDnodeListS
ize
-
1
;
src
>
0
;
--
src
)
{
for
(
int32_t
src
=
tsB
nDnodes
.
s
ize
-
1
;
src
>
0
;
--
src
)
{
SDnodeObj
*
pSrcDnode
=
tsB
alanceDnodeL
ist
[
src
];
SDnodeObj
*
pSrcDnode
=
tsB
nDnodes
.
l
ist
[
src
];
float
srcScore
=
b
alance
TryCalcDnodeScore
(
pSrcDnode
,
-
1
);
float
srcScore
=
b
n
TryCalcDnodeScore
(
pSrcDnode
,
-
1
);
if
(
tsEnableBalance
==
0
&&
pSrcDnode
->
status
!=
TAOS_DN_STATUS_DROPPING
)
{
if
(
tsEnableBalance
==
0
&&
pSrcDnode
->
status
!=
TAOS_DN_STATUS_DROPPING
)
{
continue
;
continue
;
}
}
...
@@ -362,19 +348,19 @@ static bool balanceMonitorBalance() {
...
@@ -362,19 +348,19 @@ static bool balanceMonitorBalance() {
pIter
=
mnodeGetNextVgroup
(
pIter
,
&
pVgroup
);
pIter
=
mnodeGetNextVgroup
(
pIter
,
&
pVgroup
);
if
(
pVgroup
==
NULL
)
break
;
if
(
pVgroup
==
NULL
)
break
;
if
(
b
alance
CheckDnodeInVgroup
(
pSrcDnode
,
pVgroup
))
{
if
(
b
n
CheckDnodeInVgroup
(
pSrcDnode
,
pVgroup
))
{
for
(
int32_t
dest
=
0
;
dest
<
src
;
dest
++
)
{
for
(
int32_t
dest
=
0
;
dest
<
src
;
dest
++
)
{
SDnodeObj
*
pDestDnode
=
tsB
alanceDnodeL
ist
[
dest
];
SDnodeObj
*
pDestDnode
=
tsB
nDnodes
.
l
ist
[
dest
];
if
(
b
alance
CheckDnodeInVgroup
(
pDestDnode
,
pVgroup
))
continue
;
if
(
b
n
CheckDnodeInVgroup
(
pDestDnode
,
pVgroup
))
continue
;
float
destScore
=
b
alance
TryCalcDnodeScore
(
pDestDnode
,
1
);
float
destScore
=
b
n
TryCalcDnodeScore
(
pDestDnode
,
1
);
if
(
srcScore
+
0
.
0001
<
destScore
)
continue
;
if
(
srcScore
+
0
.
0001
<
destScore
)
continue
;
if
(
!
b
alance
CheckFree
(
pDestDnode
))
continue
;
if
(
!
b
n
CheckFree
(
pDestDnode
))
continue
;
mDebug
(
"vgId:%d, balance from dnode:%d to dnode:%d, srcScore:%.1f:%.1f, destScore:%.1f:%.1f"
,
mDebug
(
"vgId:%d, balance from dnode:%d to dnode:%d, srcScore:%.1f:%.1f, destScore:%.1f:%.1f"
,
pVgroup
->
vgId
,
pSrcDnode
->
dnodeId
,
pDestDnode
->
dnodeId
,
pSrcDnode
->
score
,
pVgroup
->
vgId
,
pSrcDnode
->
dnodeId
,
pDestDnode
->
dnodeId
,
pSrcDnode
->
score
,
srcScore
,
pDestDnode
->
score
,
destScore
);
srcScore
,
pDestDnode
->
score
,
destScore
);
b
alance
AddVnode
(
pVgroup
,
pSrcDnode
,
pDestDnode
);
b
n
AddVnode
(
pVgroup
,
pSrcDnode
,
pDestDnode
);
mnodeDecVgroupRef
(
pVgroup
);
mnodeDecVgroupRef
(
pVgroup
);
mnodeCancelGetNextVgroup
(
pIter
);
mnodeCancelGetNextVgroup
(
pIter
);
return
true
;
return
true
;
...
@@ -392,7 +378,7 @@ static bool balanceMonitorBalance() {
...
@@ -392,7 +378,7 @@ static bool balanceMonitorBalance() {
// 1. reset balanceAccessSquence to zero
// 1. reset balanceAccessSquence to zero
// 2. reset state of dnodes to offline
// 2. reset state of dnodes to offline
// 3. reset lastAccess of dnodes to zero
// 3. reset lastAccess of dnodes to zero
void
b
alance
Reset
()
{
void
b
n
Reset
()
{
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
SDnodeObj
*
pDnode
=
NULL
;
SDnodeObj
*
pDnode
=
NULL
;
while
(
1
)
{
while
(
1
)
{
...
@@ -413,7 +399,7 @@ void balanceReset() {
...
@@ -413,7 +399,7 @@ void balanceReset() {
tsAccessSquence
=
0
;
tsAccessSquence
=
0
;
}
}
static
int32_t
b
alance
MonitorVgroups
()
{
static
int32_t
b
n
MonitorVgroups
()
{
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
SVgObj
*
pVgroup
=
NULL
;
SVgObj
*
pVgroup
=
NULL
;
bool
hasUpdatingVgroup
=
false
;
bool
hasUpdatingVgroup
=
false
;
...
@@ -429,11 +415,11 @@ static int32_t balanceMonitorVgroups() {
...
@@ -429,11 +415,11 @@ static int32_t balanceMonitorVgroups() {
if
(
vgReplica
>
dbReplica
)
{
if
(
vgReplica
>
dbReplica
)
{
mInfo
(
"vgId:%d, replica:%d numOfVnodes:%d, try remove one vnode"
,
pVgroup
->
vgId
,
dbReplica
,
vgReplica
);
mInfo
(
"vgId:%d, replica:%d numOfVnodes:%d, try remove one vnode"
,
pVgroup
->
vgId
,
dbReplica
,
vgReplica
);
hasUpdatingVgroup
=
true
;
hasUpdatingVgroup
=
true
;
code
=
b
alance
RemoveVnode
(
pVgroup
);
code
=
b
n
RemoveVnode
(
pVgroup
);
}
else
if
(
vgReplica
<
dbReplica
)
{
}
else
if
(
vgReplica
<
dbReplica
)
{
mInfo
(
"vgId:%d, replica:%d numOfVnodes:%d, try add one vnode"
,
pVgroup
->
vgId
,
dbReplica
,
vgReplica
);
mInfo
(
"vgId:%d, replica:%d numOfVnodes:%d, try add one vnode"
,
pVgroup
->
vgId
,
dbReplica
,
vgReplica
);
hasUpdatingVgroup
=
true
;
hasUpdatingVgroup
=
true
;
code
=
b
alance
AddVnode
(
pVgroup
,
NULL
,
NULL
);
code
=
b
n
AddVnode
(
pVgroup
,
NULL
,
NULL
);
}
}
mnodeDecVgroupRef
(
pVgroup
);
mnodeDecVgroupRef
(
pVgroup
);
...
@@ -446,7 +432,7 @@ static int32_t balanceMonitorVgroups() {
...
@@ -446,7 +432,7 @@ static int32_t balanceMonitorVgroups() {
return
hasUpdatingVgroup
;
return
hasUpdatingVgroup
;
}
}
static
bool
b
alance
MonitorDnodeDropping
(
SDnodeObj
*
pDnode
)
{
static
bool
b
n
MonitorDnodeDropping
(
SDnodeObj
*
pDnode
)
{
mDebug
(
"dnode:%d, in dropping state"
,
pDnode
->
dnodeId
);
mDebug
(
"dnode:%d, in dropping state"
,
pDnode
->
dnodeId
);
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
...
@@ -456,7 +442,7 @@ static bool balanceMonitorDnodeDropping(SDnodeObj *pDnode) {
...
@@ -456,7 +442,7 @@ static bool balanceMonitorDnodeDropping(SDnodeObj *pDnode) {
pIter
=
mnodeGetNextVgroup
(
pIter
,
&
pVgroup
);
pIter
=
mnodeGetNextVgroup
(
pIter
,
&
pVgroup
);
if
(
pVgroup
==
NULL
)
break
;
if
(
pVgroup
==
NULL
)
break
;
hasThisDnode
=
b
alance
CheckDnodeInVgroup
(
pDnode
,
pVgroup
);
hasThisDnode
=
b
n
CheckDnodeInVgroup
(
pDnode
,
pVgroup
);
mnodeDecVgroupRef
(
pVgroup
);
mnodeDecVgroupRef
(
pVgroup
);
if
(
hasThisDnode
)
{
if
(
hasThisDnode
)
{
...
@@ -474,7 +460,7 @@ static bool balanceMonitorDnodeDropping(SDnodeObj *pDnode) {
...
@@ -474,7 +460,7 @@ static bool balanceMonitorDnodeDropping(SDnodeObj *pDnode) {
return
false
;
return
false
;
}
}
static
bool
b
alance
MontiorDropping
()
{
static
bool
b
n
MontiorDropping
()
{
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
SDnodeObj
*
pDnode
=
NULL
;
SDnodeObj
*
pDnode
=
NULL
;
...
@@ -499,7 +485,7 @@ static bool balanceMontiorDropping() {
...
@@ -499,7 +485,7 @@ static bool balanceMontiorDropping() {
}
}
if
(
pDnode
->
status
==
TAOS_DN_STATUS_DROPPING
)
{
if
(
pDnode
->
status
==
TAOS_DN_STATUS_DROPPING
)
{
bool
ret
=
b
alance
MonitorDnodeDropping
(
pDnode
);
bool
ret
=
b
n
MonitorDnodeDropping
(
pDnode
);
mnodeDecDnodeRef
(
pDnode
);
mnodeDecDnodeRef
(
pDnode
);
mnodeCancelGetNextDnode
(
pIter
);
mnodeCancelGetNextDnode
(
pIter
);
return
ret
;
return
ret
;
...
@@ -509,33 +495,32 @@ static bool balanceMontiorDropping() {
...
@@ -509,33 +495,32 @@ static bool balanceMontiorDropping() {
return
false
;
return
false
;
}
}
static
bool
balance
Start
()
{
bool
bn
Start
()
{
if
(
!
sdbIsMaster
())
return
false
;
if
(
!
sdbIsMaster
())
return
false
;
balanceLock
();
bnLock
();
bnAccquireDnodes
();
balanceAccquireDnodeList
();
b
alance
MonitorDnodeModule
();
b
n
MonitorDnodeModule
();
bool
updateSoon
=
b
alance
MontiorDropping
();
bool
updateSoon
=
b
n
MontiorDropping
();
if
(
!
updateSoon
)
{
if
(
!
updateSoon
)
{
updateSoon
=
b
alance
MonitorVgroups
();
updateSoon
=
b
n
MonitorVgroups
();
}
}
if
(
!
updateSoon
)
{
if
(
!
updateSoon
)
{
updateSoon
=
b
alance
MonitorBalance
();
updateSoon
=
b
n
MonitorBalance
();
}
}
b
alanceReleaseDnodeList
();
b
nReleaseDnodes
();
b
alance
UnLock
();
b
n
UnLock
();
return
updateSoon
;
return
updateSoon
;
}
}
static
void
b
alance
SetVgroupOffline
(
SDnodeObj
*
pDnode
)
{
static
void
b
n
SetVgroupOffline
(
SDnodeObj
*
pDnode
)
{
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
while
(
1
)
{
while
(
1
)
{
SVgObj
*
pVgroup
;
SVgObj
*
pVgroup
;
...
@@ -551,7 +536,7 @@ static void balanceSetVgroupOffline(SDnodeObj* pDnode) {
...
@@ -551,7 +536,7 @@ static void balanceSetVgroupOffline(SDnodeObj* pDnode) {
}
}
}
}
static
void
balanceCheckDnodeAcces
s
()
{
void
bnCheckStatu
s
()
{
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
SDnodeObj
*
pDnode
=
NULL
;
SDnodeObj
*
pDnode
=
NULL
;
...
@@ -564,84 +549,39 @@ static void balanceCheckDnodeAccess() {
...
@@ -564,84 +549,39 @@ static void balanceCheckDnodeAccess() {
pDnode
->
offlineReason
=
TAOS_DN_OFF_STATUS_MSG_TIMEOUT
;
pDnode
->
offlineReason
=
TAOS_DN_OFF_STATUS_MSG_TIMEOUT
;
mInfo
(
"dnode:%d, set to offline state, access seq:%d last seq:%d laststat:%d"
,
pDnode
->
dnodeId
,
tsAccessSquence
,
mInfo
(
"dnode:%d, set to offline state, access seq:%d last seq:%d laststat:%d"
,
pDnode
->
dnodeId
,
tsAccessSquence
,
pDnode
->
lastAccess
,
pDnode
->
status
);
pDnode
->
lastAccess
,
pDnode
->
status
);
b
alance
SetVgroupOffline
(
pDnode
);
b
n
SetVgroupOffline
(
pDnode
);
}
}
}
}
mnodeDecDnodeRef
(
pDnode
);
mnodeDecDnodeRef
(
pDnode
);
}
}
}
}
static
void
balanceProcessBalanceTimer
(
void
*
handle
,
void
*
tmrId
)
{
void
bnCheckModules
()
{
if
(
!
sdbIsMaster
())
return
;
tsBalanceTimer
=
NULL
;
tsAccessSquence
++
;
balanceCheckDnodeAccess
();
bool
updateSoon
=
false
;
if
(
handle
==
NULL
)
{
if
(
tsAccessSquence
%
tsBalanceInterval
==
0
)
{
mDebug
(
"balance function is scheduled by timer"
);
updateSoon
=
balanceStart
();
}
}
else
{
int64_t
mseconds
=
(
int64_t
)
handle
;
mDebug
(
"balance function is scheduled by event for %"
PRId64
" mseconds arrived"
,
mseconds
);
updateSoon
=
balanceStart
();
}
if
(
updateSoon
)
{
balanceStartTimer
(
1000
);
}
else
{
taosTmrReset
(
balanceProcessBalanceTimer
,
tsStatusInterval
*
1000
,
NULL
,
tsMnodeTmr
,
&
tsBalanceTimer
);
}
}
static
void
balanceStartTimer
(
int64_t
mseconds
)
{
taosTmrReset
(
balanceProcessBalanceTimer
,
mseconds
,
(
void
*
)
mseconds
,
tsMnodeTmr
,
&
tsBalanceTimer
);
}
void
balanceSyncNotify
()
{
if
(
sdbIsMaster
())
{
if
(
sdbIsMaster
())
{
b
alance
Lock
();
b
n
Lock
();
b
alanceAccquireDnodeList
();
b
nAccquireDnodes
();
b
alance
MonitorDnodeModule
();
b
n
MonitorDnodeModule
();
b
alanceReleaseDnodeList
();
b
nReleaseDnodes
();
b
alance
UnLock
();
b
n
UnLock
();
}
}
}
}
void
balanceAsyncNotify
()
{
int32_t
bnInit
()
{
balanceStartTimer
(
500
);
pthread_mutex_init
(
&
tsBnMgmt
.
mutex
,
NULL
);
}
bnInitDnodes
();
bnInitThread
();
int32_t
balanceInit
()
{
bnReset
();
mnodeAddShowMetaHandle
(
TSDB_MGMT_TABLE_SCORES
,
balanceGetScoresMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_MGMT_TABLE_SCORES
,
balanceRetrieveScores
);
mnodeAddShowFreeIterHandle
(
TSDB_MGMT_TABLE_SCORES
,
mnodeCancelGetNextDnode
);
pthread_mutex_init
(
&
tsBalanceMutex
,
NULL
);
balanceInitDnodeList
();
balanceStartTimer
(
2000
);
mDebug
(
"balance start fp:%p initialized"
,
balanceProcessBalanceTimer
);
balanceReset
();
return
0
;
return
0
;
}
}
void
balanceCleanUp
()
{
void
bnCleanUp
()
{
if
(
tsBalanceTimer
!=
NULL
)
{
bnCleanupThread
();
taosTmrStopA
(
&
tsBalanceTimer
);
pthread_mutex_destroy
(
&
tsBnMgmt
.
mutex
);
pthread_mutex_destroy
(
&
tsBalanceMutex
);
bnCleanupDnodes
();
tsBalanceTimer
=
NULL
;
mDebug
(
"stop balance timer"
);
}
balanceCleanupDnodeList
();
}
}
int32_t
b
alance
DropDnode
(
SDnodeObj
*
pDnode
)
{
int32_t
b
n
DropDnode
(
SDnodeObj
*
pDnode
)
{
int32_t
totalFreeVnodes
=
0
;
int32_t
totalFreeVnodes
=
0
;
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
SDnodeObj
*
pTempDnode
=
NULL
;
SDnodeObj
*
pTempDnode
=
NULL
;
...
@@ -650,7 +590,7 @@ int32_t balanceDropDnode(SDnodeObj *pDnode) {
...
@@ -650,7 +590,7 @@ int32_t balanceDropDnode(SDnodeObj *pDnode) {
pIter
=
mnodeGetNextDnode
(
pIter
,
&
pTempDnode
);
pIter
=
mnodeGetNextDnode
(
pIter
,
&
pTempDnode
);
if
(
pTempDnode
==
NULL
)
break
;
if
(
pTempDnode
==
NULL
)
break
;
if
(
pTempDnode
!=
pDnode
&&
b
alance
CheckFree
(
pTempDnode
))
{
if
(
pTempDnode
!=
pDnode
&&
b
n
CheckFree
(
pTempDnode
))
{
totalFreeVnodes
+=
(
TSDB_MAX_VNODES
-
pTempDnode
->
openVnodes
);
totalFreeVnodes
+=
(
TSDB_MAX_VNODES
-
pTempDnode
->
openVnodes
);
}
}
...
@@ -665,298 +605,19 @@ int32_t balanceDropDnode(SDnodeObj *pDnode) {
...
@@ -665,298 +605,19 @@ int32_t balanceDropDnode(SDnodeObj *pDnode) {
pDnode
->
status
=
TAOS_DN_STATUS_DROPPING
;
pDnode
->
status
=
TAOS_DN_STATUS_DROPPING
;
mnodeUpdateDnode
(
pDnode
);
mnodeUpdateDnode
(
pDnode
);
b
alance
StartTimer
(
1100
);
b
n
StartTimer
(
1100
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
balanceCalcCpuScore
(
SDnodeObj
*
pDnode
)
{
if
(
pDnode
->
cpuAvgUsage
<
80
)
return
0
;
else
if
(
pDnode
->
cpuAvgUsage
<
90
)
return
10
;
else
return
50
;
}
static
int32_t
balanceCalcMemoryScore
(
SDnodeObj
*
pDnode
)
{
if
(
pDnode
->
memoryAvgUsage
<
80
)
return
0
;
else
if
(
pDnode
->
memoryAvgUsage
<
90
)
return
10
;
else
return
50
;
}
static
int32_t
balanceCalcDiskScore
(
SDnodeObj
*
pDnode
)
{
if
(
pDnode
->
diskAvgUsage
<
80
)
return
0
;
else
if
(
pDnode
->
diskAvgUsage
<
90
)
return
10
;
else
return
50
;
}
static
int32_t
balanceCalcBandwidthScore
(
SDnodeObj
*
pDnode
)
{
if
(
pDnode
->
bandwidthUsage
<
30
)
return
0
;
else
if
(
pDnode
->
bandwidthUsage
<
80
)
return
10
;
else
return
50
;
}
static
float
balanceCalcModuleScore
(
SDnodeObj
*
pDnode
)
{
if
(
pDnode
->
numOfCores
<=
0
)
return
0
;
if
(
pDnode
->
isMgmt
)
{
return
(
float
)
tsMnodeEqualVnodeNum
/
pDnode
->
numOfCores
;
}
return
0
;
}
static
float
balanceCalcVnodeScore
(
SDnodeObj
*
pDnode
,
int32_t
extra
)
{
if
(
pDnode
->
status
==
TAOS_DN_STATUS_DROPPING
||
pDnode
->
status
==
TAOS_DN_STATUS_OFFLINE
)
return
100000000
;
if
(
pDnode
->
numOfCores
<=
0
)
return
0
;
return
(
float
)(
pDnode
->
openVnodes
+
extra
)
/
pDnode
->
numOfCores
;
}
/**
* calc singe score, such as cpu/memory/disk/bandwitdh/vnode
* 1. get the score config
* 2. if the value is out of range, use border data
* 3. otherwise use interpolation method
**/
void
balanceCalcDnodeScore
(
SDnodeObj
*
pDnode
)
{
pDnode
->
score
=
balanceCalcCpuScore
(
pDnode
)
+
balanceCalcMemoryScore
(
pDnode
)
+
balanceCalcDiskScore
(
pDnode
)
+
balanceCalcBandwidthScore
(
pDnode
)
+
balanceCalcModuleScore
(
pDnode
)
+
balanceCalcVnodeScore
(
pDnode
,
0
)
+
pDnode
->
customScore
;
}
float
balanceTryCalcDnodeScore
(
SDnodeObj
*
pDnode
,
int32_t
extra
)
{
int32_t
systemScore
=
balanceCalcCpuScore
(
pDnode
)
+
balanceCalcMemoryScore
(
pDnode
)
+
balanceCalcDiskScore
(
pDnode
)
+
balanceCalcBandwidthScore
(
pDnode
);
float
moduleScore
=
balanceCalcModuleScore
(
pDnode
);
float
vnodeScore
=
balanceCalcVnodeScore
(
pDnode
,
extra
);
float
score
=
systemScore
+
moduleScore
+
vnodeScore
+
pDnode
->
customScore
;
return
score
;
}
static
void
balanceInitDnodeList
()
{
tsBalanceDnodeList
=
calloc
(
tsBalanceDnodeListMallocSize
,
sizeof
(
SDnodeObj
*
));
}
static
void
balanceCleanupDnodeList
()
{
if
(
tsBalanceDnodeList
!=
NULL
)
{
free
(
tsBalanceDnodeList
);
tsBalanceDnodeList
=
NULL
;
}
}
static
void
balanceCheckDnodeListSize
(
int32_t
dnodesNum
)
{
if
(
tsBalanceDnodeListMallocSize
<=
dnodesNum
)
{
tsBalanceDnodeListMallocSize
=
dnodesNum
*
2
;
tsBalanceDnodeList
=
realloc
(
tsBalanceDnodeList
,
tsBalanceDnodeListMallocSize
*
sizeof
(
SDnodeObj
*
));
}
}
void
balanceAccquireDnodeList
()
{
int32_t
dnodesNum
=
mnodeGetDnodesNum
();
balanceCheckDnodeListSize
(
dnodesNum
);
void
*
pIter
=
NULL
;
SDnodeObj
*
pDnode
=
NULL
;
int32_t
dnodeIndex
=
0
;
while
(
1
)
{
if
(
dnodeIndex
>=
dnodesNum
)
{
mnodeCancelGetNextDnode
(
pIter
);
break
;
}
pIter
=
mnodeGetNextDnode
(
pIter
,
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
if
(
pDnode
->
status
==
TAOS_DN_STATUS_OFFLINE
)
{
mnodeDecDnodeRef
(
pDnode
);
continue
;
}
balanceCalcDnodeScore
(
pDnode
);
int32_t
orderIndex
=
dnodeIndex
;
for
(;
orderIndex
>
0
;
--
orderIndex
)
{
if
(
pDnode
->
score
>
tsBalanceDnodeList
[
orderIndex
-
1
]
->
score
)
{
break
;
}
tsBalanceDnodeList
[
orderIndex
]
=
tsBalanceDnodeList
[
orderIndex
-
1
];
}
tsBalanceDnodeList
[
orderIndex
]
=
pDnode
;
dnodeIndex
++
;
}
tsBalanceDnodeListSize
=
dnodeIndex
;
}
void
balanceReleaseDnodeList
()
{
for
(
int32_t
i
=
0
;
i
<
tsBalanceDnodeListSize
;
++
i
)
{
SDnodeObj
*
pDnode
=
tsBalanceDnodeList
[
i
];
if
(
pDnode
!=
NULL
)
{
mnodeDecDnodeRef
(
pDnode
);
}
}
}
static
int32_t
balanceGetScoresMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SUserObj
*
pUser
=
mnodeGetUserFromConn
(
pConn
);
if
(
pUser
==
NULL
)
return
0
;
if
(
strcmp
(
pUser
->
pAcct
->
user
,
"root"
)
!=
0
)
{
mnodeDecUserRef
(
pUser
);
return
TSDB_CODE_MND_NO_RIGHTS
;
}
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
schema
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"id"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_FLOAT
;
strcpy
(
pSchema
[
cols
].
name
,
"system scores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_FLOAT
;
strcpy
(
pSchema
[
cols
].
name
,
"custom scores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_FLOAT
;
strcpy
(
pSchema
[
cols
].
name
,
"module scores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_FLOAT
;
strcpy
(
pSchema
[
cols
].
name
,
"vnode scores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_FLOAT
;
strcpy
(
pSchema
[
cols
].
name
,
"total scores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"open vnodes"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"cpu cores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
18
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"balance state"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
mnodeGetDnodesNum
();
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
pShow
->
pIter
=
NULL
;
mnodeDecUserRef
(
pUser
);
return
0
;
}
static
int32_t
balanceRetrieveScores
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
SDnodeObj
*
pDnode
=
NULL
;
char
*
pWrite
;
int32_t
cols
=
0
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
mnodeGetNextDnode
(
pShow
->
pIter
,
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
int32_t
systemScore
=
balanceCalcCpuScore
(
pDnode
)
+
balanceCalcMemoryScore
(
pDnode
)
+
balanceCalcDiskScore
(
pDnode
)
+
balanceCalcBandwidthScore
(
pDnode
);
float
moduleScore
=
balanceCalcModuleScore
(
pDnode
);
float
vnodeScore
=
balanceCalcVnodeScore
(
pDnode
,
0
);
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDnode
->
dnodeId
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
float
*
)
pWrite
=
systemScore
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
float
*
)
pWrite
=
pDnode
->
customScore
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
float
*
)
pWrite
=
(
int32_t
)
moduleScore
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
float
*
)
pWrite
=
(
int32_t
)
vnodeScore
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
float
*
)
pWrite
=
(
int32_t
)(
vnodeScore
+
moduleScore
+
pDnode
->
customScore
+
systemScore
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pDnode
->
openVnodes
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pDnode
->
numOfCores
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_TO_VARSTR
(
pWrite
,
mnodeGetDnodeStatusStr
(
pDnode
->
status
));
cols
++
;
numOfRows
++
;
mnodeDecDnodeRef
(
pDnode
);
}
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
void
b
alance
MonitorDnodeModule
()
{
static
void
b
n
MonitorDnodeModule
()
{
int32_t
numOfMnodes
=
mnodeGetMnodesNum
();
int32_t
numOfMnodes
=
mnodeGetMnodesNum
();
if
(
numOfMnodes
>=
tsNumOfMnodes
)
return
;
if
(
numOfMnodes
>=
tsNumOfMnodes
)
return
;
for
(
int32_t
i
=
0
;
i
<
tsB
alanceDnodeListS
ize
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
tsB
nDnodes
.
s
ize
;
++
i
)
{
SDnodeObj
*
pDnode
=
tsB
alanceDnodeL
ist
[
i
];
SDnodeObj
*
pDnode
=
tsB
nDnodes
.
l
ist
[
i
];
if
(
pDnode
==
NULL
)
break
;
if
(
pDnode
==
NULL
)
break
;
if
(
pDnode
->
isMgmt
||
pDnode
->
status
==
TAOS_DN_STATUS_DROPPING
||
pDnode
->
status
==
TAOS_DN_STATUS_OFFLINE
)
{
if
(
pDnode
->
isMgmt
||
pDnode
->
status
==
TAOS_DN_STATUS_DROPPING
||
pDnode
->
status
==
TAOS_DN_STATUS_OFFLINE
)
{
...
@@ -980,7 +641,7 @@ static void balanceMonitorDnodeModule() {
...
@@ -980,7 +641,7 @@ static void balanceMonitorDnodeModule() {
}
}
}
}
int32_t
b
alance
AlterDnode
(
struct
SDnodeObj
*
pSrcDnode
,
int32_t
vnodeId
,
int32_t
dnodeId
)
{
int32_t
b
n
AlterDnode
(
struct
SDnodeObj
*
pSrcDnode
,
int32_t
vnodeId
,
int32_t
dnodeId
)
{
if
(
!
sdbIsMaster
())
{
if
(
!
sdbIsMaster
())
{
mError
(
"dnode:%d, failed to alter vgId:%d to dnode:%d, for self not master"
,
pSrcDnode
->
dnodeId
,
vnodeId
,
dnodeId
);
mError
(
"dnode:%d, failed to alter vgId:%d to dnode:%d, for self not master"
,
pSrcDnode
->
dnodeId
,
vnodeId
,
dnodeId
);
return
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
TSDB_CODE_MND_DNODE_NOT_EXIST
;
...
@@ -1004,29 +665,29 @@ int32_t balanceAlterDnode(struct SDnodeObj *pSrcDnode, int32_t vnodeId, int32_t
...
@@ -1004,29 +665,29 @@ int32_t balanceAlterDnode(struct SDnodeObj *pSrcDnode, int32_t vnodeId, int32_t
return
TSDB_CODE_MND_DNODE_NOT_EXIST
;
return
TSDB_CODE_MND_DNODE_NOT_EXIST
;
}
}
b
alance
Lock
();
b
n
Lock
();
b
alanceAccquireDnodeList
();
b
nAccquireDnodes
();
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
!
b
alance
CheckDnodeInVgroup
(
pSrcDnode
,
pVgroup
))
{
if
(
!
b
n
CheckDnodeInVgroup
(
pSrcDnode
,
pVgroup
))
{
mError
(
"dnode:%d, failed to alter vgId:%d to dnode:%d, vgroup not in dnode:%d"
,
pSrcDnode
->
dnodeId
,
vnodeId
,
mError
(
"dnode:%d, failed to alter vgId:%d to dnode:%d, vgroup not in dnode:%d"
,
pSrcDnode
->
dnodeId
,
vnodeId
,
dnodeId
,
pSrcDnode
->
dnodeId
);
dnodeId
,
pSrcDnode
->
dnodeId
);
code
=
TSDB_CODE_MND_VGROUP_NOT_IN_DNODE
;
code
=
TSDB_CODE_MND_VGROUP_NOT_IN_DNODE
;
}
else
if
(
b
alance
CheckDnodeInVgroup
(
pDestDnode
,
pVgroup
))
{
}
else
if
(
b
n
CheckDnodeInVgroup
(
pDestDnode
,
pVgroup
))
{
mError
(
"dnode:%d, failed to alter vgId:%d to dnode:%d, vgroup already in dnode:%d"
,
pSrcDnode
->
dnodeId
,
vnodeId
,
mError
(
"dnode:%d, failed to alter vgId:%d to dnode:%d, vgroup already in dnode:%d"
,
pSrcDnode
->
dnodeId
,
vnodeId
,
dnodeId
,
dnodeId
);
dnodeId
,
dnodeId
);
code
=
TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE
;
code
=
TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE
;
}
else
if
(
!
b
alance
CheckFree
(
pDestDnode
))
{
}
else
if
(
!
b
n
CheckFree
(
pDestDnode
))
{
mError
(
"dnode:%d, failed to alter vgId:%d to dnode:%d, for dnode:%d not free"
,
pSrcDnode
->
dnodeId
,
vnodeId
,
dnodeId
,
mError
(
"dnode:%d, failed to alter vgId:%d to dnode:%d, for dnode:%d not free"
,
pSrcDnode
->
dnodeId
,
vnodeId
,
dnodeId
,
dnodeId
);
dnodeId
);
code
=
TSDB_CODE_MND_DNODE_NOT_FREE
;
code
=
TSDB_CODE_MND_DNODE_NOT_FREE
;
}
else
{
}
else
{
code
=
b
alance
AddVnode
(
pVgroup
,
pSrcDnode
,
pDestDnode
);
code
=
b
n
AddVnode
(
pVgroup
,
pSrcDnode
,
pDestDnode
);
mInfo
(
"dnode:%d, alter vgId:%d to dnode:%d, result:%s"
,
pSrcDnode
->
dnodeId
,
vnodeId
,
dnodeId
,
tstrerror
(
code
));
mInfo
(
"dnode:%d, alter vgId:%d to dnode:%d, result:%s"
,
pSrcDnode
->
dnodeId
,
vnodeId
,
dnodeId
,
tstrerror
(
code
));
}
}
b
alanceReleaseDnodeList
();
b
nReleaseDnodes
();
b
alance
UnLock
();
b
n
UnLock
();
mnodeDecVgroupRef
(
pVgroup
);
mnodeDecVgroupRef
(
pVgroup
);
mnodeDecDnodeRef
(
pDestDnode
);
mnodeDecDnodeRef
(
pDestDnode
);
...
...
src/balance/src/bnScore.c
0 → 100644
浏览文件 @
ca870415
/*
* 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 "tutil.h"
#include "tbalance.h"
#include "tsync.h"
#include "tsync.h"
#include "ttimer.h"
#include "tglobal.h"
#include "tdataformat.h"
#include "dnode.h"
#include "mnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeDnode.h"
#include "mnodeDb.h"
#include "mnodeMnode.h"
#include "mnodeSdb.h"
#include "mnodeShow.h"
#include "mnodeUser.h"
#include "mnodeVgroup.h"
#include "bnScore.h"
SBnDnodes
tsBnDnodes
;
static
int32_t
bnGetScoresMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
bnRetrieveScores
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
bnCalcCpuScore
(
SDnodeObj
*
pDnode
)
{
if
(
pDnode
->
cpuAvgUsage
<
80
)
return
0
;
else
if
(
pDnode
->
cpuAvgUsage
<
90
)
return
10
;
else
return
50
;
}
static
int32_t
bnCalcMemoryScore
(
SDnodeObj
*
pDnode
)
{
if
(
pDnode
->
memoryAvgUsage
<
80
)
return
0
;
else
if
(
pDnode
->
memoryAvgUsage
<
90
)
return
10
;
else
return
50
;
}
static
int32_t
bnCalcDiskScore
(
SDnodeObj
*
pDnode
)
{
if
(
pDnode
->
diskAvgUsage
<
80
)
return
0
;
else
if
(
pDnode
->
diskAvgUsage
<
90
)
return
10
;
else
return
50
;
}
static
int32_t
bnCalcBandScore
(
SDnodeObj
*
pDnode
)
{
if
(
pDnode
->
bandwidthUsage
<
30
)
return
0
;
else
if
(
pDnode
->
bandwidthUsage
<
80
)
return
10
;
else
return
50
;
}
static
float
bnCalcModuleScore
(
SDnodeObj
*
pDnode
)
{
if
(
pDnode
->
numOfCores
<=
0
)
return
0
;
if
(
pDnode
->
isMgmt
)
{
return
(
float
)
tsMnodeEqualVnodeNum
/
pDnode
->
numOfCores
;
}
return
0
;
}
static
float
bnCalcVnodeScore
(
SDnodeObj
*
pDnode
,
int32_t
extra
)
{
if
(
pDnode
->
status
==
TAOS_DN_STATUS_DROPPING
||
pDnode
->
status
==
TAOS_DN_STATUS_OFFLINE
)
return
100000000
;
if
(
pDnode
->
numOfCores
<=
0
)
return
0
;
return
(
float
)(
pDnode
->
openVnodes
+
extra
)
/
pDnode
->
numOfCores
;
}
/**
* calc singe score, such as cpu/memory/disk/bandwitdh/vnode
* 1. get the score config
* 2. if the value is out of range, use border data
* 3. otherwise use interpolation method
**/
static
void
bnCalcDnodeScore
(
SDnodeObj
*
pDnode
)
{
pDnode
->
score
=
bnCalcCpuScore
(
pDnode
)
+
bnCalcMemoryScore
(
pDnode
)
+
bnCalcDiskScore
(
pDnode
)
+
bnCalcBandScore
(
pDnode
)
+
bnCalcModuleScore
(
pDnode
)
+
bnCalcVnodeScore
(
pDnode
,
0
)
+
pDnode
->
customScore
;
}
float
bnTryCalcDnodeScore
(
SDnodeObj
*
pDnode
,
int32_t
extra
)
{
int32_t
systemScore
=
bnCalcCpuScore
(
pDnode
)
+
bnCalcMemoryScore
(
pDnode
)
+
bnCalcDiskScore
(
pDnode
)
+
bnCalcBandScore
(
pDnode
);
float
moduleScore
=
bnCalcModuleScore
(
pDnode
);
float
vnodeScore
=
bnCalcVnodeScore
(
pDnode
,
extra
);
float
score
=
systemScore
+
moduleScore
+
vnodeScore
+
pDnode
->
customScore
;
return
score
;
}
void
bnInitDnodes
()
{
mnodeAddShowMetaHandle
(
TSDB_MGMT_TABLE_SCORES
,
bnGetScoresMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_MGMT_TABLE_SCORES
,
bnRetrieveScores
);
mnodeAddShowFreeIterHandle
(
TSDB_MGMT_TABLE_SCORES
,
mnodeCancelGetNextDnode
);
memset
(
&
tsBnDnodes
,
0
,
sizeof
(
SBnDnodes
));
tsBnDnodes
.
maxSize
=
16
;
tsBnDnodes
.
list
=
calloc
(
tsBnDnodes
.
maxSize
,
sizeof
(
SDnodeObj
*
));
}
void
bnCleanupDnodes
()
{
if
(
tsBnDnodes
.
list
!=
NULL
)
{
free
(
tsBnDnodes
.
list
);
tsBnDnodes
.
list
=
NULL
;
}
}
static
void
bnCheckDnodesSize
(
int32_t
dnodesNum
)
{
if
(
tsBnDnodes
.
maxSize
<=
dnodesNum
)
{
tsBnDnodes
.
maxSize
=
dnodesNum
*
2
;
tsBnDnodes
.
list
=
realloc
(
tsBnDnodes
.
list
,
tsBnDnodes
.
maxSize
*
sizeof
(
SDnodeObj
*
));
}
}
void
bnAccquireDnodes
()
{
int32_t
dnodesNum
=
mnodeGetDnodesNum
();
bnCheckDnodesSize
(
dnodesNum
);
void
*
pIter
=
NULL
;
SDnodeObj
*
pDnode
=
NULL
;
int32_t
dnodeIndex
=
0
;
while
(
1
)
{
if
(
dnodeIndex
>=
dnodesNum
)
{
mnodeCancelGetNextDnode
(
pIter
);
break
;
}
pIter
=
mnodeGetNextDnode
(
pIter
,
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
if
(
pDnode
->
status
==
TAOS_DN_STATUS_OFFLINE
)
{
mnodeDecDnodeRef
(
pDnode
);
continue
;
}
bnCalcDnodeScore
(
pDnode
);
int32_t
orderIndex
=
dnodeIndex
;
for
(;
orderIndex
>
0
;
--
orderIndex
)
{
if
(
pDnode
->
score
>
tsBnDnodes
.
list
[
orderIndex
-
1
]
->
score
)
{
break
;
}
tsBnDnodes
.
list
[
orderIndex
]
=
tsBnDnodes
.
list
[
orderIndex
-
1
];
}
tsBnDnodes
.
list
[
orderIndex
]
=
pDnode
;
dnodeIndex
++
;
}
tsBnDnodes
.
size
=
dnodeIndex
;
}
void
bnReleaseDnodes
()
{
for
(
int32_t
i
=
0
;
i
<
tsBnDnodes
.
size
;
++
i
)
{
SDnodeObj
*
pDnode
=
tsBnDnodes
.
list
[
i
];
if
(
pDnode
!=
NULL
)
{
mnodeDecDnodeRef
(
pDnode
);
}
}
}
static
int32_t
bnGetScoresMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SUserObj
*
pUser
=
mnodeGetUserFromConn
(
pConn
);
if
(
pUser
==
NULL
)
return
0
;
if
(
strcmp
(
pUser
->
pAcct
->
user
,
"root"
)
!=
0
)
{
mnodeDecUserRef
(
pUser
);
return
TSDB_CODE_MND_NO_RIGHTS
;
}
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
schema
;
pShow
->
bytes
[
cols
]
=
2
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_SMALLINT
;
strcpy
(
pSchema
[
cols
].
name
,
"id"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_FLOAT
;
strcpy
(
pSchema
[
cols
].
name
,
"system scores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_FLOAT
;
strcpy
(
pSchema
[
cols
].
name
,
"custom scores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_FLOAT
;
strcpy
(
pSchema
[
cols
].
name
,
"module scores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_FLOAT
;
strcpy
(
pSchema
[
cols
].
name
,
"vnode scores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_FLOAT
;
strcpy
(
pSchema
[
cols
].
name
,
"total scores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"open vnodes"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"cpu cores"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
18
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"balance state"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
mnodeGetDnodesNum
();
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
pShow
->
pIter
=
NULL
;
mnodeDecUserRef
(
pUser
);
return
0
;
}
static
int32_t
bnRetrieveScores
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
SDnodeObj
*
pDnode
=
NULL
;
char
*
pWrite
;
int32_t
cols
=
0
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
mnodeGetNextDnode
(
pShow
->
pIter
,
&
pDnode
);
if
(
pDnode
==
NULL
)
break
;
int32_t
systemScore
=
bnCalcCpuScore
(
pDnode
)
+
bnCalcMemoryScore
(
pDnode
)
+
bnCalcDiskScore
(
pDnode
)
+
bnCalcBandScore
(
pDnode
);
float
moduleScore
=
bnCalcModuleScore
(
pDnode
);
float
vnodeScore
=
bnCalcVnodeScore
(
pDnode
,
0
);
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDnode
->
dnodeId
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
float
*
)
pWrite
=
systemScore
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
float
*
)
pWrite
=
pDnode
->
customScore
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
float
*
)
pWrite
=
(
int32_t
)
moduleScore
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
float
*
)
pWrite
=
(
int32_t
)
vnodeScore
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
float
*
)
pWrite
=
(
int32_t
)(
vnodeScore
+
moduleScore
+
pDnode
->
customScore
+
systemScore
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pDnode
->
openVnodes
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pDnode
->
numOfCores
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_TO_VARSTR
(
pWrite
,
mnodeGetDnodeStatusStr
(
pDnode
->
status
));
cols
++
;
numOfRows
++
;
mnodeDecDnodeRef
(
pDnode
);
}
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
src/balance/src/bnThread.c
浏览文件 @
ca870415
...
@@ -34,14 +34,10 @@
...
@@ -34,14 +34,10 @@
#include "mnodeUser.h"
#include "mnodeUser.h"
#include "mnodeVgroup.h"
#include "mnodeVgroup.h"
typedef
struct
{
bool
stop
;
pthread_mutex_t
mutex
;
pthread_cond_t
cond
;
pthread_t
thread
;
}
SBalanceThread
;
static
SBalanceThread
tsBnThread
;
#include "bnThread.h"
static
SBnThread
tsBnThread
;
static
void
*
bnThreadFunc
(
void
*
arg
)
{
static
void
*
bnThreadFunc
(
void
*
arg
)
{
while
(
1
)
{
while
(
1
)
{
...
@@ -52,14 +48,16 @@ static void *bnThreadFunc(void *arg) {
...
@@ -52,14 +48,16 @@ static void *bnThreadFunc(void *arg) {
}
}
pthread_cond_wait
(
&
tsBnThread
.
cond
,
&
tsBnThread
.
mutex
);
pthread_cond_wait
(
&
tsBnThread
.
cond
,
&
tsBnThread
.
mutex
);
bool
updateSoon
=
bnStart
();
bnStartTimer
(
updateSoon
?
1000
:
-
1
);
pthread_mutex_unlock
(
&
(
tsBnThread
.
mutex
));
pthread_mutex_unlock
(
&
(
tsBnThread
.
mutex
));
}
}
return
NULL
;
return
NULL
;
}
}
int32_t
bnThreadInit
()
{
int32_t
bnInitThread
()
{
memset
(
&
tsBnThread
,
0
,
sizeof
(
SBnThread
));
tsBnThread
.
stop
=
false
;
tsBnThread
.
stop
=
false
;
pthread_mutex_init
(
&
tsBnThread
.
mutex
,
NULL
);
pthread_mutex_init
(
&
tsBnThread
.
mutex
,
NULL
);
pthread_cond_init
(
&
tsBnThread
.
cond
,
NULL
);
pthread_cond_init
(
&
tsBnThread
.
cond
,
NULL
);
...
@@ -75,13 +73,20 @@ int32_t bnThreadInit() {
...
@@ -75,13 +73,20 @@ int32_t bnThreadInit() {
return
-
1
;
return
-
1
;
}
}
bnStartTimer
(
2000
);
mDebug
(
"balance thread is created"
);
mDebug
(
"balance thread is created"
);
return
0
;
return
0
;
}
}
void
bn
ThreadCleanup
()
{
void
bn
CleanupThread
()
{
mDebug
(
"balance thread will be cleanup"
);
mDebug
(
"balance thread will be cleanup"
);
if
(
tsBnThread
.
timer
!=
NULL
)
{
taosTmrStopA
(
&
tsBnThread
.
timer
);
tsBnThread
.
timer
=
NULL
;
mDebug
(
"stop balance timer"
);
}
pthread_mutex_lock
(
&
tsBnThread
.
mutex
);
pthread_mutex_lock
(
&
tsBnThread
.
mutex
);
tsBnThread
.
stop
=
true
;
tsBnThread
.
stop
=
true
;
pthread_cond_signal
(
&
tsBnThread
.
cond
);
pthread_cond_signal
(
&
tsBnThread
.
cond
);
...
@@ -92,16 +97,47 @@ void bnThreadCleanup() {
...
@@ -92,16 +97,47 @@ void bnThreadCleanup() {
pthread_mutex_destroy
(
&
tsBnThread
.
mutex
);
pthread_mutex_destroy
(
&
tsBnThread
.
mutex
);
}
}
void
bnThreadSyncNotify
()
{
static
void
bnPostSignal
()
{
mDebug
(
"balance thread sync notify"
);
mDebug
(
"balance thread
a
sync notify"
);
pthread_mutex_lock
(
&
tsBnThread
.
mutex
);
pthread_mutex_lock
(
&
tsBnThread
.
mutex
);
pthread_cond_signal
(
&
tsBnThread
.
cond
);
pthread_cond_signal
(
&
tsBnThread
.
cond
);
pthread_mutex_unlock
(
&
(
tsBnThread
.
mutex
));
pthread_mutex_unlock
(
&
(
tsBnThread
.
mutex
));
}
}
void
bnThreadAsyncNotify
()
{
/*
mDebug
(
"balance thread async notify"
);
* once sdb work as mater, then tsAccessSquence reset to zero
pthread_mutex_lock
(
&
tsBnThread
.
mutex
);
* increase tsAccessSquence every balance interval
pthread_cond_signal
(
&
tsBnThread
.
cond
);
*/
pthread_mutex_unlock
(
&
(
tsBnThread
.
mutex
));
static
void
bnProcessTimer
(
void
*
handle
,
void
*
tmrId
)
{
if
(
!
sdbIsMaster
())
return
;
tsBnThread
.
timer
=
NULL
;
tsAccessSquence
++
;
bnCheckStatus
();
if
(
handle
==
NULL
)
{
if
(
tsAccessSquence
%
tsBalanceInterval
==
0
)
{
mDebug
(
"balance function is scheduled by timer"
);
bnPostSignal
();
}
}
else
{
int64_t
mseconds
=
(
int64_t
)
handle
;
mDebug
(
"balance function is scheduled by event for %"
PRId64
" mseconds arrived"
,
mseconds
);
bnPostSignal
();
}
}
void
bnStartTimer
(
int64_t
mseconds
)
{
bool
updateSoon
=
(
mseconds
!=
-
1
);
if
(
updateSoon
)
{
taosTmrReset
(
bnProcessTimer
,
mseconds
,
(
void
*
)
mseconds
,
tsMnodeTmr
,
&
tsBnThread
.
timer
);
}
else
{
taosTmrReset
(
bnProcessTimer
,
tsStatusInterval
*
1000
,
NULL
,
tsMnodeTmr
,
&
tsBnThread
.
timer
);
}
}
void
bnNotify
()
{
bnStartTimer
(
500
);
}
}
src/inc/tbalance.h
浏览文件 @
ca870415
...
@@ -23,14 +23,14 @@ extern "C" {
...
@@ -23,14 +23,14 @@ extern "C" {
struct
SVgObj
;
struct
SVgObj
;
struct
SDnodeObj
;
struct
SDnodeObj
;
int32_t
b
alance
Init
();
int32_t
b
n
Init
();
void
b
alance
CleanUp
();
void
b
n
CleanUp
();
void
b
alanceAsync
Notify
();
void
b
n
Notify
();
void
b
alanceSyncNotify
();
void
b
nCheckModules
();
void
b
alance
Reset
();
void
b
n
Reset
();
int32_t
b
alance
AllocVnodes
(
struct
SVgObj
*
pVgroup
);
int32_t
b
n
AllocVnodes
(
struct
SVgObj
*
pVgroup
);
int32_t
b
alance
AlterDnode
(
struct
SDnodeObj
*
pDnode
,
int32_t
vnodeId
,
int32_t
dnodeId
);
int32_t
b
n
AlterDnode
(
struct
SDnodeObj
*
pDnode
,
int32_t
vnodeId
,
int32_t
dnodeId
);
int32_t
b
alance
DropDnode
(
struct
SDnodeObj
*
pDnode
);
int32_t
b
n
DropDnode
(
struct
SDnodeObj
*
pDnode
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/mnode/src/mnodeDb.c
浏览文件 @
ca870415
...
@@ -1004,7 +1004,7 @@ static int32_t mnodeAlterDbCb(SMnodeMsg *pMsg, int32_t code) {
...
@@ -1004,7 +1004,7 @@ static int32_t mnodeAlterDbCb(SMnodeMsg *pMsg, int32_t code) {
mDebug
(
"db:%s, all vgroups is altered"
,
pDb
->
name
);
mDebug
(
"db:%s, all vgroups is altered"
,
pDb
->
name
);
mLInfo
(
"db:%s, is alterd by %s"
,
pDb
->
name
,
mnodeGetUserFromMsg
(
pMsg
));
mLInfo
(
"db:%s, is alterd by %s"
,
pDb
->
name
,
mnodeGetUserFromMsg
(
pMsg
));
b
alanceAsync
Notify
();
b
n
Notify
();
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
...
src/mnode/src/mnodeDnode.c
浏览文件 @
ca870415
...
@@ -115,7 +115,7 @@ static int32_t mnodeDnodeActionDelete(SSdbRow *pRow) {
...
@@ -115,7 +115,7 @@ static int32_t mnodeDnodeActionDelete(SSdbRow *pRow) {
mnodeDropAllDnodeVgroups
(
pDnode
);
mnodeDropAllDnodeVgroups
(
pDnode
);
#endif
#endif
mnodeDropMnodeLocal
(
pDnode
->
dnodeId
);
mnodeDropMnodeLocal
(
pDnode
->
dnodeId
);
b
alanceAsync
Notify
();
b
n
Notify
();
mnodeUpdateDnodeEps
();
mnodeUpdateDnodeEps
();
mDebug
(
"dnode:%d, all vgroups is dropped from sdb"
,
pDnode
->
dnodeId
);
mDebug
(
"dnode:%d, all vgroups is dropped from sdb"
,
pDnode
->
dnodeId
);
...
@@ -347,7 +347,7 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
...
@@ -347,7 +347,7 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) {
return
TSDB_CODE_MND_INVALID_DNODE_CFG_OPTION
;
return
TSDB_CODE_MND_INVALID_DNODE_CFG_OPTION
;
}
}
int32_t
code
=
b
alance
AlterDnode
(
pDnode
,
vnodeId
,
dnodeId
);
int32_t
code
=
b
n
AlterDnode
(
pDnode
,
vnodeId
,
dnodeId
);
mnodeDecDnodeRef
(
pDnode
);
mnodeDecDnodeRef
(
pDnode
);
return
code
;
return
code
;
}
else
{
}
else
{
...
@@ -591,8 +591,8 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
...
@@ -591,8 +591,8 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
mInfo
(
"dnode:%d, from offline to online"
,
pDnode
->
dnodeId
);
mInfo
(
"dnode:%d, from offline to online"
,
pDnode
->
dnodeId
);
pDnode
->
status
=
TAOS_DN_STATUS_READY
;
pDnode
->
status
=
TAOS_DN_STATUS_READY
;
pDnode
->
offlineReason
=
TAOS_DN_OFF_ONLINE
;
pDnode
->
offlineReason
=
TAOS_DN_OFF_ONLINE
;
b
alanceSyncNotify
();
b
nCheckModules
();
b
alanceAsync
Notify
();
b
n
Notify
();
}
}
if
(
openVnodes
!=
pDnode
->
openVnodes
)
{
if
(
openVnodes
!=
pDnode
->
openVnodes
)
{
...
@@ -708,7 +708,7 @@ static int32_t mnodeDropDnodeByEp(char *ep, SMnodeMsg *pMsg) {
...
@@ -708,7 +708,7 @@ static int32_t mnodeDropDnodeByEp(char *ep, SMnodeMsg *pMsg) {
#ifndef _SYNC
#ifndef _SYNC
int32_t
code
=
mnodeDropDnode
(
pDnode
,
pMsg
);
int32_t
code
=
mnodeDropDnode
(
pDnode
,
pMsg
);
#else
#else
int32_t
code
=
b
alance
DropDnode
(
pDnode
);
int32_t
code
=
b
n
DropDnode
(
pDnode
);
#endif
#endif
mnodeDecDnodeRef
(
pDnode
);
mnodeDecDnodeRef
(
pDnode
);
return
code
;
return
code
;
...
@@ -1182,12 +1182,12 @@ static char* mnodeGetDnodeAlternativeRoleStr(int32_t alternativeRole) {
...
@@ -1182,12 +1182,12 @@ static char* mnodeGetDnodeAlternativeRoleStr(int32_t alternativeRole) {
#ifndef _SYNC
#ifndef _SYNC
int32_t
b
alance
Init
()
{
return
TSDB_CODE_SUCCESS
;
}
int32_t
b
n
Init
()
{
return
TSDB_CODE_SUCCESS
;
}
void
b
alance
CleanUp
()
{}
void
b
n
CleanUp
()
{}
void
b
alanceAsync
Notify
()
{}
void
b
n
Notify
()
{}
void
b
alanceSyncNotify
()
{}
void
b
nCheckModules
()
{}
void
b
alance
Reset
()
{}
void
b
n
Reset
()
{}
int32_t
b
alance
AlterDnode
(
struct
SDnodeObj
*
pDnode
,
int32_t
vnodeId
,
int32_t
dnodeId
)
{
return
TSDB_CODE_SYN_NOT_ENABLED
;
}
int32_t
b
n
AlterDnode
(
struct
SDnodeObj
*
pDnode
,
int32_t
vnodeId
,
int32_t
dnodeId
)
{
return
TSDB_CODE_SYN_NOT_ENABLED
;
}
char
*
syncRole
[]
=
{
char
*
syncRole
[]
=
{
"offline"
,
"offline"
,
...
@@ -1197,7 +1197,7 @@ char* syncRole[] = {
...
@@ -1197,7 +1197,7 @@ char* syncRole[] = {
"master"
"master"
};
};
int32_t
b
alance
AllocVnodes
(
SVgObj
*
pVgroup
)
{
int32_t
b
n
AllocVnodes
(
SVgObj
*
pVgroup
)
{
void
*
pIter
=
NULL
;
void
*
pIter
=
NULL
;
SDnodeObj
*
pDnode
=
NULL
;
SDnodeObj
*
pDnode
=
NULL
;
SDnodeObj
*
pSelDnode
=
NULL
;
SDnodeObj
*
pSelDnode
=
NULL
;
...
...
src/mnode/src/mnodeMain.c
浏览文件 @
ca870415
...
@@ -58,7 +58,7 @@ static const SMnodeComponent tsMnodeComponents[] = {
...
@@ -58,7 +58,7 @@ static const SMnodeComponent tsMnodeComponents[] = {
{
"tables"
,
mnodeInitTables
,
mnodeCleanupTables
},
{
"tables"
,
mnodeInitTables
,
mnodeCleanupTables
},
{
"mnodes"
,
mnodeInitMnodes
,
mnodeCleanupMnodes
},
{
"mnodes"
,
mnodeInitMnodes
,
mnodeCleanupMnodes
},
{
"sdb"
,
sdbInit
,
sdbCleanUp
},
{
"sdb"
,
sdbInit
,
sdbCleanUp
},
{
"balance"
,
b
alanceInit
,
balance
CleanUp
},
{
"balance"
,
b
nInit
,
bn
CleanUp
},
{
"grant"
,
grantInit
,
grantCleanUp
},
{
"grant"
,
grantInit
,
grantCleanUp
},
{
"show"
,
mnodeInitShow
,
mnodeCleanUpShow
}
{
"show"
,
mnodeInitShow
,
mnodeCleanUpShow
}
};
};
...
...
src/mnode/src/mnodeSdb.c
浏览文件 @
ca870415
...
@@ -244,7 +244,7 @@ static void sdbNotifyRole(int32_t vgId, int8_t role) {
...
@@ -244,7 +244,7 @@ static void sdbNotifyRole(int32_t vgId, int8_t role) {
sdbInfo
(
"vgId:1, mnode role changed from %s to %s"
,
syncRole
[
tsSdbMgmt
.
role
],
syncRole
[
role
]);
sdbInfo
(
"vgId:1, mnode role changed from %s to %s"
,
syncRole
[
tsSdbMgmt
.
role
],
syncRole
[
role
]);
if
(
role
==
TAOS_SYNC_ROLE_MASTER
&&
tsSdbMgmt
.
role
!=
TAOS_SYNC_ROLE_MASTER
)
{
if
(
role
==
TAOS_SYNC_ROLE_MASTER
&&
tsSdbMgmt
.
role
!=
TAOS_SYNC_ROLE_MASTER
)
{
b
alance
Reset
();
b
n
Reset
();
}
}
tsSdbMgmt
.
role
=
role
;
tsSdbMgmt
.
role
=
role
;
...
...
src/mnode/src/mnodeVgroup.c
浏览文件 @
ca870415
...
@@ -563,7 +563,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) {
...
@@ -563,7 +563,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) {
pVgroup
->
numOfVnodes
=
pDb
->
cfg
.
replications
;
pVgroup
->
numOfVnodes
=
pDb
->
cfg
.
replications
;
pVgroup
->
createdTime
=
taosGetTimestampMs
();
pVgroup
->
createdTime
=
taosGetTimestampMs
();
pVgroup
->
accessState
=
TSDB_VN_ALL_ACCCESS
;
pVgroup
->
accessState
=
TSDB_VN_ALL_ACCCESS
;
int32_t
code
=
b
alance
AllocVnodes
(
pVgroup
);
int32_t
code
=
b
n
AllocVnodes
(
pVgroup
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"db:%s, no enough dnode to alloc %d vnodes to vgroup, reason:%s"
,
pDb
->
name
,
pVgroup
->
numOfVnodes
,
mError
(
"db:%s, no enough dnode to alloc %d vnodes to vgroup, reason:%s"
,
pDb
->
name
,
pVgroup
->
numOfVnodes
,
tstrerror
(
code
));
tstrerror
(
code
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录