Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
DolphinScheduler
提交
ab8f8786
DolphinScheduler
项目概览
apache
/
DolphinScheduler
上一次同步 1 年多
通知
705
Star
9572
Fork
3514
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
ab8f8786
编写于
9月 18, 2022
作者:
J
JinYong Li
提交者:
GitHub
9月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix heartBeatTaskCount bug (#12024)
上级
bc629f8f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
100 addition
and
60 deletion
+100
-60
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/registry/MasterHeartBeatTask.java
...scheduler/server/master/registry/MasterHeartBeatTask.java
+73
-0
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/registry/MasterRegistryClient.java
...cheduler/server/master/registry/MasterRegistryClient.java
+8
-11
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/registry/WorkerHeartBeatTask.java
...scheduler/server/worker/registry/WorkerHeartBeatTask.java
+10
-37
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistryClient.java
...cheduler/server/worker/registry/WorkerRegistryClient.java
+9
-12
未找到文件。
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/registry/MasterHeartBeatTask.java
0 → 100644
浏览文件 @
ab8f8786
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.server.master.registry
;
import
org.apache.dolphinscheduler.common.Constants
;
import
org.apache.dolphinscheduler.common.utils.HeartBeat
;
import
org.apache.dolphinscheduler.service.registry.RegistryClient
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* Master heart beat task
*/
public
class
MasterHeartBeatTask
implements
Runnable
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
MasterHeartBeatTask
.
class
);
private
final
Set
<
String
>
heartBeatPaths
;
private
final
RegistryClient
registryClient
;
private
final
HeartBeat
heartBeat
;
private
final
AtomicInteger
heartBeatErrorTimes
=
new
AtomicInteger
();
public
MasterHeartBeatTask
(
long
startupTime
,
double
maxCpuloadAvg
,
double
reservedMemory
,
Set
<
String
>
heartBeatPaths
,
RegistryClient
registryClient
)
{
this
.
heartBeatPaths
=
heartBeatPaths
;
this
.
registryClient
=
registryClient
;
this
.
heartBeat
=
new
HeartBeat
(
startupTime
,
maxCpuloadAvg
,
reservedMemory
);
}
public
String
getHeartBeatInfo
()
{
return
this
.
heartBeat
.
encodeHeartBeat
();
}
@Override
public
void
run
()
{
try
{
for
(
String
heartBeatPath
:
heartBeatPaths
)
{
if
(
registryClient
.
checkIsDeadServer
(
heartBeatPath
,
Constants
.
MASTER_TYPE
))
{
registryClient
.
getStoppable
().
stop
(
"i was judged to death, release resources and stop myself"
);
return
;
}
}
for
(
String
heartBeatPath
:
heartBeatPaths
)
{
registryClient
.
persistEphemeral
(
heartBeatPath
,
heartBeat
.
encodeHeartBeat
());
}
heartBeatErrorTimes
.
set
(
0
);
}
catch
(
Throwable
ex
)
{
logger
.
error
(
"HeartBeat task execute failed, errorTimes: {}"
,
heartBeatErrorTimes
.
get
(),
ex
);
}
}
}
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/registry/MasterRegistryClient.java
浏览文件 @
ab8f8786
...
...
@@ -30,7 +30,6 @@ import org.apache.dolphinscheduler.registry.api.RegistryException;
import
org.apache.dolphinscheduler.remote.utils.NamedThreadFactory
;
import
org.apache.dolphinscheduler.server.master.config.MasterConfig
;
import
org.apache.dolphinscheduler.server.master.service.FailoverService
;
import
org.apache.dolphinscheduler.server.registry.HeartBeatTask
;
import
org.apache.dolphinscheduler.service.registry.RegistryClient
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -50,7 +49,7 @@ import com.google.common.collect.Sets;
/**
* <p>DolphinScheduler master register client, used to connect to registry and hand the registry events.
* <p>When the Master node startup, it will register in registry center. And schedule a {@link HeartBeatTask} to update its metadata in registry.
* <p>When the Master node startup, it will register in registry center. And schedule a {@link
Master
HeartBeatTask} to update its metadata in registry.
*/
@Component
public
class
MasterRegistryClient
implements
AutoCloseable
{
...
...
@@ -97,7 +96,7 @@ public class MasterRegistryClient implements AutoCloseable {
// master registry
registry
();
registryClient
.
addConnectionStateListener
(
new
MasterConnectionStateListener
(
getCurrentNodePath
(),
registryClient
));
registryClient
));
registryClient
.
subscribe
(
REGISTRY_DOLPHINSCHEDULER_NODE
,
new
MasterRegistryDataListener
());
}
catch
(
Exception
e
)
{
throw
new
RegistryException
(
"Master registry client start up error"
,
e
);
...
...
@@ -190,13 +189,11 @@ public class MasterRegistryClient implements AutoCloseable {
logger
.
info
(
"Master node : {} registering to registry center"
,
masterAddress
);
String
localNodePath
=
getCurrentNodePath
();
Duration
masterHeartbeatInterval
=
masterConfig
.
getHeartbeatInterval
();
HeartBeatTask
heartBeatTask
=
new
HeartBeatTask
(
startupTime
,
masterConfig
.
getMaxCpuLoadAvg
(),
masterConfig
.
getReservedMemory
(),
Sets
.
newHashSet
(
localNodePath
),
Constants
.
MASTER_TYPE
,
registryClient
,
masterConfig
.
getHeartbeatErrorThreshold
());
MasterHeartBeatTask
heartBeatTask
=
new
MasterHeartBeatTask
(
startupTime
,
masterConfig
.
getMaxCpuLoadAvg
(),
masterConfig
.
getReservedMemory
(),
Sets
.
newHashSet
(
localNodePath
),
registryClient
);
// remove before persist
registryClient
.
remove
(
localNodePath
);
...
...
@@ -247,4 +244,4 @@ public class MasterRegistryClient implements AutoCloseable {
return
NetUtils
.
getAddr
(
masterConfig
.
getListenPort
());
}
}
}
\ No newline at end of file
dolphinscheduler-
server/src/main/java/org/apache/dolphinscheduler/server/registry/
HeartBeatTask.java
→
dolphinscheduler-
worker/src/main/java/org/apache/dolphinscheduler/server/worker/registry/Worker
HeartBeatTask.java
浏览文件 @
ab8f8786
...
...
@@ -15,64 +15,43 @@
* limitations under the License.
*/
package
org.apache.dolphinscheduler.server.registry
;
package
org.apache.dolphinscheduler.server.
worker.
registry
;
import
org.apache.dolphinscheduler.common.Constants
;
import
org.apache.dolphinscheduler.common.utils.HeartBeat
;
import
org.apache.dolphinscheduler.service.registry.RegistryClient
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* Heart beat task
*/
public
class
HeartBeatTask
implements
Runnable
{
public
class
Worker
HeartBeatTask
implements
Runnable
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
HeartBeatTask
.
class
);
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Worker
HeartBeatTask
.
class
);
private
final
Set
<
String
>
heartBeatPaths
;
private
final
RegistryClient
registryClient
;
private
int
workerWaitingTaskCount
;
private
final
String
serverType
;
private
final
HeartBeat
heartBeat
;
private
final
int
heartBeatErrorThreshold
;
private
final
AtomicInteger
heartBeatErrorTimes
=
new
AtomicInteger
();
public
HeartBeatTask
(
long
startupTime
,
double
maxCpuloadAvg
,
double
reservedMemory
,
Set
<
String
>
heartBeatPaths
,
String
serverType
,
RegistryClient
registryClient
,
int
heartBeatErrorThreshold
)
{
this
.
heartBeatPaths
=
heartBeatPaths
;
this
.
registryClient
=
registryClient
;
this
.
serverType
=
serverType
;
this
.
heartBeat
=
new
HeartBeat
(
startupTime
,
maxCpuloadAvg
,
reservedMemory
);
this
.
heartBeatErrorThreshold
=
heartBeatErrorThreshold
;
}
public
HeartBeatTask
(
long
startupTime
,
public
WorkerHeartBeatTask
(
long
startupTime
,
double
maxCpuloadAvg
,
double
reservedMemory
,
int
hostWeight
,
Set
<
String
>
heartBeatPaths
,
String
serverType
,
RegistryClient
registryClient
,
int
workerThreadCount
,
int
workerWaitingTaskCount
,
int
heartBeatErrorThreshold
)
{
int
workerWaitingTaskCount
)
{
this
.
heartBeatPaths
=
heartBeatPaths
;
this
.
registryClient
=
registryClient
;
this
.
workerWaitingTaskCount
=
workerWaitingTaskCount
;
this
.
serverType
=
serverType
;
this
.
heartBeat
=
new
HeartBeat
(
startupTime
,
maxCpuloadAvg
,
reservedMemory
,
hostWeight
,
workerThreadCount
);
this
.
heartBeatErrorThreshold
=
heartBeatErrorThreshold
;
}
public
String
getHeartBeatInfo
()
{
...
...
@@ -82,14 +61,12 @@ public class HeartBeatTask implements Runnable {
@Override
public
void
run
()
{
try
{
// check dead or not in zookeeper
for
(
String
heartBeatPath
:
heartBeatPaths
)
{
if
(
registryClient
.
checkIsDeadServer
(
heartBeatPath
,
serverType
))
{
if
(
registryClient
.
checkIsDeadServer
(
heartBeatPath
,
Constants
.
WORKER_TYPE
))
{
registryClient
.
getStoppable
().
stop
(
"i was judged to death, release resources and stop myself"
);
return
;
}
}
// update waiting task count
heartBeat
.
setWorkerWaitingTaskCount
(
workerWaitingTaskCount
);
...
...
@@ -98,11 +75,7 @@ public class HeartBeatTask implements Runnable {
}
heartBeatErrorTimes
.
set
(
0
);
}
catch
(
Throwable
ex
)
{
logger
.
error
(
"HeartBeat task execute failed"
,
ex
);
if
(
heartBeatErrorTimes
.
incrementAndGet
()
>=
heartBeatErrorThreshold
)
{
registryClient
.
getStoppable
()
.
stop
(
"HeartBeat task connect to zk failed too much times: "
+
heartBeatErrorTimes
);
}
logger
.
error
(
"HeartBeat task execute failed, errorTimes: {}"
,
heartBeatErrorTimes
.
get
(),
ex
);
}
}
}
dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/registry/WorkerRegistryClient.java
浏览文件 @
ab8f8786
...
...
@@ -28,7 +28,6 @@ import org.apache.dolphinscheduler.common.enums.NodeType;
import
org.apache.dolphinscheduler.common.thread.ThreadUtils
;
import
org.apache.dolphinscheduler.common.utils.NetUtils
;
import
org.apache.dolphinscheduler.remote.utils.NamedThreadFactory
;
import
org.apache.dolphinscheduler.server.registry.HeartBeatTask
;
import
org.apache.dolphinscheduler.server.worker.config.WorkerConfig
;
import
org.apache.dolphinscheduler.server.worker.runner.WorkerManagerThread
;
import
org.apache.dolphinscheduler.service.registry.RegistryClient
;
...
...
@@ -101,16 +100,14 @@ public class WorkerRegistryClient implements AutoCloseable {
Set
<
String
>
workerZkPaths
=
getWorkerZkPaths
();
long
workerHeartbeatInterval
=
workerConfig
.
getHeartbeatInterval
().
getSeconds
();
HeartBeatTask
heartBeatTask
=
new
HeartBeatTask
(
startupTime
,
workerConfig
.
getMaxCpuLoadAvg
(),
workerConfig
.
getReservedMemory
(),
workerConfig
.
getHostWeight
(),
workerZkPaths
,
Constants
.
WORKER_TYPE
,
registryClient
,
workerConfig
.
getExecThreads
(),
workerManagerThread
.
getThreadPoolQueueSize
(),
workerConfig
.
getHeartbeatErrorThreshold
());
WorkerHeartBeatTask
heartBeatTask
=
new
WorkerHeartBeatTask
(
startupTime
,
workerConfig
.
getMaxCpuLoadAvg
(),
workerConfig
.
getReservedMemory
(),
workerConfig
.
getHostWeight
(),
workerZkPaths
,
registryClient
,
workerConfig
.
getExecThreads
(),
workerManagerThread
.
getThreadPoolQueueSize
());
for
(
String
workerZKPath
:
workerZkPaths
)
{
// remove before persist
...
...
@@ -199,4 +196,4 @@ public class WorkerRegistryClient implements AutoCloseable {
unRegistry
();
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录