Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public void waitUntilAllTasksCompleted(long seconds)

@Override
public void checkRequirement(String op) {
if (!this.serverManager().selfIsMaster()) {
if (!this.serverManager().selfIsMasterOrSingleComputer()) {
throw new HugeException("Can't %s task on non-master server", op);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect spaces " = "

return isMaster||isSingleComputer;
}

public boolean selfIsComputer() {
return this.selfNodeRole() != null && this.selfNodeRole().computer();
}

public boolean isStandAloneComputer(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused method?

return this.onlySingleNode() && this.selfIsComputer();
}

public boolean onlySingleNode() {
Expand All @@ -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;
Expand Down Expand Up @@ -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()){
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure 02 means what

this.onlySingleNode = singleNode;
}
}

protected synchronized HugeServerInfo pickWorkerNode(Collection<HugeServerInfo> servers,
HugeTask<?> task) {
HugeServerInfo master = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public synchronized <V> void cancel(HugeTask<V> task) {
// The task scheduled to workers, let the worker node to cancel
this.save(task);
assert task.server() != null : task;
assert this.serverManager().selfIsMaster();
assert this.serverManager().selfIsMasterOrSingleComputer();
if (!task.server().equals(this.serverManager().selfNodeId())) {
/*
* Remove the task from memory if it's running on worker node,
Expand Down Expand Up @@ -312,7 +312,7 @@ protected synchronized void scheduleTasksOnMaster() {
continue;
}

if (!this.serverManager.selfIsMaster()) {
if (!this.serverManager.selfIsMasterOrSingleComputer()) {
return;
}

Expand Down Expand Up @@ -720,7 +720,7 @@ public <V> V call(Callable<V> callable) {
}

private void checkOnMasterNode(String op) {
if (!this.serverManager().selfIsMaster()) {
if (!this.serverManager().selfIsMasterOrSingleComputer()) {
throw new HugeException("Can't %s task on non-master server", op);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,15 @@ private void scheduleOrExecuteJobForGraph(TaskScheduler scheduler) {
// Update server heartbeat
serverManager.heartbeat();

serverManager.updateIsSingleNode();
/*
* Master will schedule tasks to suitable servers.
* Note a Worker may become to a Master, so elected-Master also needs to
* execute tasks assigned by previous Master when enableRoleElected=true.
* However, when enableRoleElected=false, a Master is only set by the
* config assignment, assigned-Master always stays the same state.
*/
if (serverManager.selfIsMaster()) {
if (serverManager.selfIsMasterOrSingleComputer()) {
standardTaskScheduler.scheduleTasksOnMaster();
if (!this.enableRoleElected && !serverManager.onlySingleNode()) {
// assigned-Master + non-single-node don't need to execute tasks
Expand Down
Loading