-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(server): support single computer do schedule task #2676
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,8 +172,18 @@ public NodeRole selfNodeRole() { | |
return this.globalNodeInfo.nodeRole(); | ||
} | ||
|
||
public boolean selfIsMaster() { | ||
return this.selfNodeRole() != null && this.selfNodeRole().master(); | ||
public boolean selfIsMasterOrSingleComputer() { | ||
boolean isMaster=this.selfNodeRole() != null && this.selfNodeRole().master(); | ||
boolean isSingleComputer=isStandAloneComputer(); | ||
return isMaster||isSingleComputer; | ||
} | ||
|
||
public boolean selfIsComputer() { | ||
return this.selfNodeRole() != null && this.selfNodeRole().computer(); | ||
} | ||
|
||
public boolean isStandAloneComputer(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused method? |
||
return this.onlySingleNode() && this.selfIsComputer(); | ||
} | ||
|
||
public boolean onlySingleNode() { | ||
|
@@ -198,7 +208,7 @@ public synchronized void heartbeat() { | |
LOG.info("ServerInfo is missing: {}, may not be initialized yet", this.selfNodeId()); | ||
return; | ||
} | ||
if (this.selfIsMaster()) { | ||
if (this.selfIsMasterOrSingleComputer()) { | ||
// On the master node, just wait for ServerInfo re-init | ||
LOG.warn("ServerInfo is missing: {}, may be cleared before", this.selfNodeId()); | ||
return; | ||
|
@@ -228,6 +238,32 @@ protected boolean graphIsReady() { | |
return !this.closed && this.graph.started() && this.graph.initialized(); | ||
} | ||
|
||
protected synchronized void updateIsSingleNode(){ | ||
Collection<HugeServerInfo> servers=this.allServerInfos(); | ||
boolean hasWorkerNode = false; | ||
long now = DateUtil.now().getTime(); | ||
int computerNodeCount=0; | ||
|
||
// Iterate servers to find suitable one | ||
for (HugeServerInfo server : servers) { | ||
if (!server.alive()) { | ||
continue; | ||
} | ||
if (server.role().master()) { | ||
continue; | ||
}else if (server.role().computer()){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a space after '}', or remove 'else' |
||
computerNodeCount++; | ||
} | ||
hasWorkerNode = true; | ||
} | ||
|
||
boolean singleNode = !hasWorkerNode||computerNodeCount==1; | ||
if (singleNode != this.onlySingleNode) { | ||
LOG.info("Switch only_single_node 02 to {}", singleNode); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure |
||
this.onlySingleNode = singleNode; | ||
} | ||
} | ||
|
||
protected synchronized HugeServerInfo pickWorkerNode(Collection<HugeServerInfo> servers, | ||
HugeTask<?> task) { | ||
HugeServerInfo master = null; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect spaces " = "