Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
d6a65c5e
Commit
d6a65c5e
authored
May 18, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove active env cache
parent
4b6df298
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
34 deletions
+8
-34
PortalSettings.java
...src/main/java/com/ctrip/apollo/portal/PortalSettings.java
+8
-34
No files found.
apollo-portal/src/main/java/com/ctrip/apollo/portal/PortalSettings.java
View file @
d6a65c5e
...
...
@@ -40,18 +40,13 @@ public class PortalSettings {
private
List
<
Env
>
allEnvs
=
new
ArrayList
<
Env
>();
private
volatile
boolean
updatedFromLastHealthCheck
=
true
;
//for cache
private
List
<
Env
>
activeEnvs
=
new
LinkedList
<>();
private
List
<
Env
>
activeEnvs
;
//mark env up or down
private
Map
<
Env
,
Boolean
>
envStatusMark
=
new
ConcurrentHashMap
<>();
private
ScheduledExecutorService
healthCheckService
;
private
Lock
lock
=
new
ReentrantLock
();
@PostConstruct
private
void
postConstruct
()
{
//init origin config envs
...
...
@@ -63,9 +58,6 @@ public class PortalSettings {
envStatusMark
.
put
(
env
,
true
);
}
//init active envs
activeEnvs
=
refreshActiveEnvs
();
healthCheckService
=
Executors
.
newScheduledThreadPool
(
1
);
healthCheckService
...
...
@@ -75,24 +67,14 @@ public class PortalSettings {
}
public
List
<
Env
>
getActiveEnvs
()
{
if
(
updatedFromLastHealthCheck
)
{
lock
.
lock
();
//maybe refresh many times but not create a bad impression.
activeEnvs
=
refreshActiveEnvs
();
lock
.
unlock
();
}
return
activeEnvs
;
}
private
List
<
Env
>
refreshActiveEnvs
()
{
List
<
Env
>
envs
=
new
LinkedList
<>();
List
<
Env
>
activeEnvs
=
new
LinkedList
<>();
for
(
Env
env
:
allEnvs
)
{
if
(
envStatusMark
.
get
(
env
))
{
e
nvs
.
add
(
env
);
activeE
nvs
.
add
(
env
);
}
}
logger
.
info
(
"refresh active envs"
)
;
return
e
nvs
;
this
.
activeEnvs
=
activeEnvs
;
return
activeE
nvs
;
}
public
Env
getFirstAliveEnv
()
{
...
...
@@ -117,7 +99,6 @@ public class PortalSettings {
public
void
run
()
{
logger
.
info
(
"admin server health check start..."
);
boolean
hasUpdateStatus
=
false
;
for
(
Env
env
:
allEnvs
)
{
try
{
...
...
@@ -126,25 +107,20 @@ public class PortalSettings {
if
(!
envStatusMark
.
get
(
env
))
{
envStatusMark
.
put
(
env
,
true
);
healthCheckFailCnt
.
put
(
env
,
0
l
);
hasUpdateStatus
=
true
;
logger
.
info
(
"env up again [env:{}]"
,
env
);
}
}
else
{
//maybe meta server up but admin server down
ha
sUpdateStatus
=
ha
ndleEnvDown
(
env
);
handleEnvDown
(
env
);
}
}
catch
(
Exception
e
)
{
//maybe meta server down
logger
.
warn
(
"health check fail. [env:{}]"
,
env
,
e
.
getMessage
());
ha
sUpdateStatus
=
ha
ndleEnvDown
(
env
);
handleEnvDown
(
env
);
}
}
if
(!
hasUpdateStatus
)
{
logger
.
info
(
"admin server health check OK"
);
}
updatedFromLastHealthCheck
=
hasUpdateStatus
;
}
private
boolean
isUp
(
Env
env
)
{
...
...
@@ -152,17 +128,15 @@ public class PortalSettings {
return
"UP"
.
equals
(
health
.
getStatus
().
getCode
());
}
private
boolean
handleEnvDown
(
Env
env
)
{
private
void
handleEnvDown
(
Env
env
)
{
long
failCnt
=
healthCheckFailCnt
.
get
(
env
);
healthCheckFailCnt
.
put
(
env
,
++
failCnt
);
if
(
envStatusMark
.
get
(
env
)
&&
failCnt
>=
ENV_DIED_THREADHOLD
){
envStatusMark
.
put
(
env
,
false
);
logger
.
error
(
"env turn to down [env:{}]"
,
env
);
return
true
;
}
else
{
logger
.
warn
(
"[env:{}] down yet."
,
env
);
return
false
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment