Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
老大叔也想要天天的爱情
DolphinScheduler
提交
b0533224
DolphinScheduler
项目概览
老大叔也想要天天的爱情
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
3
Star
0
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
b0533224
编写于
12月 29, 2019
作者:
T
Technoboy-
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor AbstractZKClient
上级
98a7daa6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
36 addition
and
60 deletion
+36
-60
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/zk/AbstractZKClient.java
...g/apache/dolphinscheduler/common/zk/AbstractZKClient.java
+36
-60
未找到文件。
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/zk/AbstractZKClient.java
浏览文件 @
b0533224
...
...
@@ -16,6 +16,22 @@
*/
package
org.apache.dolphinscheduler.common.zk
;
import
static
org
.
apache
.
dolphinscheduler
.
common
.
Constants
.
ADD_ZK_OP
;
import
static
org
.
apache
.
dolphinscheduler
.
common
.
Constants
.
DELETE_ZK_OP
;
import
static
org
.
apache
.
dolphinscheduler
.
common
.
Constants
.
MASTER_PREFIX
;
import
static
org
.
apache
.
dolphinscheduler
.
common
.
Constants
.
SINGLE_SLASH
;
import
static
org
.
apache
.
dolphinscheduler
.
common
.
Constants
.
UNDERLINE
;
import
static
org
.
apache
.
dolphinscheduler
.
common
.
Constants
.
WORKER_PREFIX
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.curator.framework.CuratorFramework
;
import
org.apache.curator.framework.imps.CuratorFrameworkState
;
import
org.apache.curator.framework.recipes.locks.InterProcessMutex
;
import
org.apache.dolphinscheduler.common.Constants
;
import
org.apache.dolphinscheduler.common.IStoppable
;
import
org.apache.dolphinscheduler.common.enums.ZKNodeType
;
...
...
@@ -23,26 +39,9 @@ import org.apache.dolphinscheduler.common.model.Server;
import
org.apache.dolphinscheduler.common.utils.DateUtils
;
import
org.apache.dolphinscheduler.common.utils.OSUtils
;
import
org.apache.dolphinscheduler.common.utils.ResInfo
;
import
org.apache.commons.configuration.Configuration
;
import
org.apache.commons.configuration.ConfigurationException
;
import
org.apache.commons.configuration.PropertiesConfiguration
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.curator.RetryPolicy
;
import
org.apache.curator.framework.CuratorFramework
;
import
org.apache.curator.framework.CuratorFrameworkFactory
;
import
org.apache.curator.framework.imps.CuratorFrameworkState
;
import
org.apache.curator.framework.recipes.locks.InterProcessMutex
;
import
org.apache.curator.framework.state.ConnectionState
;
import
org.apache.curator.framework.state.ConnectionStateListener
;
import
org.apache.curator.retry.ExponentialBackoffRetry
;
import
org.apache.zookeeper.CreateMode
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.*
;
import
static
org
.
apache
.
dolphinscheduler
.
common
.
Constants
.*;
/**
* abstract zookeeper client
...
...
@@ -70,8 +69,7 @@ public abstract class AbstractZKClient extends ZookeeperCachedOperator{
return
;
}
byte
[]
bytes
=
zkClient
.
getData
().
forPath
(
znode
);
String
resInfoStr
=
new
String
(
bytes
);
String
resInfoStr
=
super
.
get
(
znode
);
String
[]
splits
=
resInfoStr
.
split
(
Constants
.
COMMA
);
if
(
splits
.
length
!=
Constants
.
HEARTBEAT_FOR_ZOOKEEPER_INFO_LENGTH
){
return
;
...
...
@@ -107,8 +105,7 @@ public abstract class AbstractZKClient extends ZookeeperCachedOperator{
String
type
=
serverType
.
equals
(
MASTER_PREFIX
)
?
MASTER_PREFIX
:
WORKER_PREFIX
;
String
deadServerPath
=
getDeadZNodeParentPath
()
+
SINGLE_SLASH
+
type
+
UNDERLINE
+
ipSeqNo
;
if
(
zkClient
.
checkExists
().
forPath
(
zNode
)
==
null
||
zkClient
.
checkExists
().
forPath
(
deadServerPath
)
!=
null
){
if
(!
isExisted
(
zNode
)
||
isExisted
(
deadServerPath
)){
return
true
;
}
...
...
@@ -118,14 +115,12 @@ public abstract class AbstractZKClient extends ZookeeperCachedOperator{
public
void
removeDeadServerByHost
(
String
host
,
String
serverType
)
throws
Exception
{
List
<
String
>
deadServers
=
zkClient
.
getChildren
().
forPath
(
getDeadZNodeParentPath
());
List
<
String
>
deadServers
=
super
.
getChildrenKeys
(
getDeadZNodeParentPath
());
for
(
String
serverPath
:
deadServers
){
if
(
serverPath
.
startsWith
(
serverType
+
UNDERLINE
+
host
)){
String
server
=
getDeadZNodeParentPath
()
+
SINGLE_SLASH
+
serverPath
;
if
(
zkClient
.
checkExists
().
forPath
(
server
)
!=
null
){
zkClient
.
delete
().
forPath
(
server
);
logger
.
info
(
"{} server {} deleted from zk dead server path success"
,
serverType
,
host
);
}
String
server
=
getDeadZNodeParentPath
()
+
SINGLE_SLASH
+
serverPath
;
super
.
remove
(
server
);
logger
.
info
(
"{} server {} deleted from zk dead server path success"
,
serverType
,
host
);
}
}
}
...
...
@@ -143,8 +138,8 @@ public abstract class AbstractZKClient extends ZookeeperCachedOperator{
// create temporary sequence nodes for master znode
String
parentPath
=
getZNodeParentPath
(
zkNodeType
);
String
serverPathPrefix
=
parentPath
+
"/"
+
OSUtils
.
getHost
();
String
registerPath
=
zkClient
.
create
().
withMode
(
CreateMode
.
EPHEMERAL_SEQUENTIAL
).
forPath
(
serverPathPrefix
+
UNDERLINE
,
heartbeatZKInfo
.
getBytes
()
);
String
registerPath
=
serverPathPrefix
+
UNDERLINE
;
super
.
persistEphemeral
(
registerPath
,
heartbeatZKInfo
);
logger
.
info
(
"register {} node {} success"
,
zkNodeType
.
toString
(),
registerPath
);
return
registerPath
;
}
...
...
@@ -165,7 +160,7 @@ public abstract class AbstractZKClient extends ZookeeperCachedOperator{
}
registerPath
=
createZNodePath
(
zkNodeType
);
// handle dead server
// handle dead server
handleDeadServer
(
registerPath
,
zkNodeType
,
Constants
.
DELETE_ZK_OP
);
return
registerPath
;
...
...
@@ -196,10 +191,10 @@ public abstract class AbstractZKClient extends ZookeeperCachedOperator{
}
else
if
(
opType
.
equals
(
ADD_ZK_OP
)){
String
deadServerPath
=
getDeadZNodeParentPath
()
+
SINGLE_SLASH
+
type
+
UNDERLINE
+
ipSeqNo
;
if
(
zkClient
.
checkExists
().
forPath
(
deadServerPath
)
==
null
){
if
(
!
super
.
isExisted
(
deadServerPath
)
){
//add dead server info to zk dead server path : /dead-servers/
zkClient
.
create
().
forPath
(
deadServerPath
,(
type
+
UNDERLINE
+
ipSeqNo
).
getBytes
(
));
super
.
persist
(
deadServerPath
,(
type
+
UNDERLINE
+
ipSeqNo
));
logger
.
info
(
"{} server dead , and {} added to zk dead server path success"
,
zkNodeType
.
toString
(),
zNode
);
...
...
@@ -226,19 +221,13 @@ public abstract class AbstractZKClient extends ZookeeperCachedOperator{
List
<
String
>
childrenList
=
new
ArrayList
<>();
try
{
// read master node parent path from conf
if
(
zkClient
.
checkExists
().
forPath
(
getZNodeParentPath
(
ZKNodeType
.
MASTER
))
!=
null
){
childrenList
=
zkClient
.
getChildren
().
forPath
(
getZNodeParentPath
(
ZKNodeType
.
MASTER
));
if
(
super
.
isExisted
(
getZNodeParentPath
(
ZKNodeType
.
MASTER
))
){
childrenList
=
super
.
getChildrenKeys
(
getZNodeParentPath
(
ZKNodeType
.
MASTER
));
}
}
catch
(
Exception
e
)
{
if
(
e
.
getMessage
().
contains
(
"java.lang.IllegalStateException: instance must be started"
)){
logger
.
error
(
"zookeeper service not started"
,
e
);
}
else
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
finally
{
return
childrenList
.
size
();
logger
.
error
(
"getActiveMasterNum error"
,
e
);
}
return
childrenList
.
size
();
}
/**
...
...
@@ -280,10 +269,9 @@ public abstract class AbstractZKClient extends ZookeeperCachedOperator{
Map
<
String
,
String
>
masterMap
=
new
HashMap
<>();
try
{
String
path
=
getZNodeParentPath
(
zkNodeType
);
List
<
String
>
serverList
=
getZkClient
().
getChildren
().
forPath
(
path
);
List
<
String
>
serverList
=
super
.
getChildrenKeys
(
path
);
for
(
String
server
:
serverList
){
byte
[]
bytes
=
getZkClient
().
getData
().
forPath
(
path
+
"/"
+
server
);
masterMap
.
putIfAbsent
(
server
,
new
String
(
bytes
));
masterMap
.
putIfAbsent
(
server
,
super
.
get
(
path
+
"/"
+
server
));
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"get server list failed : "
+
e
.
getMessage
(),
e
);
...
...
@@ -430,27 +418,15 @@ public abstract class AbstractZKClient extends ZookeeperCachedOperator{
*/
protected
void
initSystemZNode
(){
try
{
createNodePath
(
getMasterZNodeParentPath
()
);
createNodePath
(
getWorkerZNodeParentPath
()
);
createNodePath
(
getDeadZNodeParentPath
()
);
persist
(
getMasterZNodeParentPath
(),
""
);
persist
(
getWorkerZNodeParentPath
(),
""
);
persist
(
getDeadZNodeParentPath
(),
""
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"init system znode failed : "
+
e
.
getMessage
(),
e
);
}
}
/**
* create zookeeper node path if not exists
* @param zNodeParentPath zookeeper parent path
* @throws Exception errors
*/
private
void
createNodePath
(
String
zNodeParentPath
)
throws
Exception
{
if
(
null
==
zkClient
.
checkExists
().
forPath
(
zNodeParentPath
)){
zkClient
.
create
().
creatingParentContainersIfNeeded
()
.
withMode
(
CreateMode
.
PERSISTENT
).
forPath
(
zNodeParentPath
);
}
}
/**
* server self dead, stop all threads
* @param serverHost server host
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录