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

Missing sj heartbeat #2583

Merged
merged 7 commits into from
May 28, 2024
Merged
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
26 changes: 26 additions & 0 deletions nvflare/private/fed/server/fed_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
ServerCommandKey,
ServerCommandNames,
SnapshotKey,
SystemComponents,
WorkspaceConstants,
)
from nvflare.apis.fl_context import FLContext
from nvflare.apis.fl_exception import NotAuthenticated
from nvflare.apis.job_def import JobMetaKey, RunStatus
from nvflare.apis.workspace import Workspace
from nvflare.fuel.common.exit_codes import ProcessExitCode
from nvflare.fuel.f3.cellnet.cell import Cell
Expand Down Expand Up @@ -374,10 +376,23 @@ def _listen_command(self, request: Message) -> Message:
reply = make_cellnet_reply(F3ReturnCode.OK, "", None)
return reply
elif command == ServerCommandNames.HEARTBEAT:
if job_id not in self.engine.run_processes:
yhwen marked this conversation as resolved.
Show resolved Hide resolved
self.engine.abort_app_on_server(job_id)
self._set_job_aborted(job_id)
self.logger.info(
f"Job: {job_id} should not be running, but still sending the heartbeat calls. Abort the job."
)
return make_cellnet_reply(F3ReturnCode.OK, "", None)
else:
return make_cellnet_reply(F3ReturnCode.INVALID_REQUEST, "", None)

def _set_job_aborted(self, job_id):
job_manager = self.engine.get_component(SystemComponents.JOB_MANAGER)
with self.engine.new_context() as fl_ctx:
job = job_manager.get_job(job_id, fl_ctx)
if job.meta.get(JobMetaKey.STATUS) == RunStatus.RUNNING:
job_manager.set_status(job_id, RunStatus.FINISHED_ABORTED, fl_ctx)

def _create_server_engine(self, args, snapshot_persistor):
return ServerEngine(
server=self, args=args, client_manager=self.client_manager, snapshot_persistor=snapshot_persistor
Expand Down Expand Up @@ -687,12 +702,23 @@ def start_run(self, job_id, run_root, conf, args, snapshot):
if self.engine.asked_to_stop:
self.engine.engine_info.status = MachineStatus.STOPPED

self._send_parent_heartbeat(job_id)
time.sleep(self.check_engine_frequency)

finally:
self.engine.engine_info.status = MachineStatus.STOPPED
self.run_manager = None

def _send_parent_heartbeat(self, job_id):
if self.cell:
request = new_cell_message({CellMessageHeaderKeys.JOB_ID: job_id}, {})
self.cell.fire_and_forget(
targets=FQCN.ROOT_SERVER,
channel=CellChannel.SERVER_PARENT_LISTENER,
topic=ServerCommandNames.HEARTBEAT,
message=request,
)

def create_run_manager(self, workspace, job_id):
return RunManager(
server_name=self.project_name,
Expand Down
2 changes: 0 additions & 2 deletions nvflare/private/fed/server/server_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ def abort_app_on_clients(self, clients: List[str]) -> str:
return ""

def abort_app_on_server(self, job_id: str, turn_to_cold: bool = False) -> str:
if job_id not in self.run_processes.keys():
yhwen marked this conversation as resolved.
Show resolved Hide resolved
return "Server app has not started."

self.logger.info("Abort the server app run.")
command_data = Shareable()
Expand Down
Loading