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

[Serve] Fix adding initial version and cleanup service versions #3804

Merged
merged 4 commits into from
Aug 7, 2024

Conversation

cblmemo
Copy link
Collaborator

@cblmemo cblmemo commented Aug 1, 2024

Originally, in our serve state,

  • We create the initial insertion to version_specs in the __init__ function of ReplicaManager, which is not attached to insertion to the services table. This could sometimes lead to a misalign of the two tables;
  • We do not cleanup the version information after its termination. Although we clean all outdated version in our controller process, this will left one final valid version at termination.

This PR fixed the two problems.

TODO: test.

Tested (run the relevant ones):

  • Code formatting: bash format.sh
  • Any manual or new tests for this PR (please specify below)
  • All smoke tests: pytest tests/test_smoke.py
  • Relevant individual smoke tests: pytest tests/test_smoke.py::test_fill_in_the_name
  • Backward compatibility tests: conda deactivate; bash -i tests/backward_compatibility_tests.sh

Copy link
Collaborator

@Michaelvll Michaelvll left a comment

Choose a reason for hiding this comment

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

Thanks for the fix @cblmemo! Left two quesetions.

Comment on lines +422 to +423
# If the `services` and `version_specs` table are not aligned, it might
# result in a None service status. In this case, the controller process
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we write down in what case the two tables will be misaligned if we have always handled the two database at the same time?

Copy link
Collaborator Author

@cblmemo cblmemo Aug 6, 2024

Choose a reason for hiding this comment

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

Previously, the system added an initial version in the __init__ function of replica managers and added the service record here

success = serve_state.add_service(
service_name,
controller_job_id=job_id,
policy=service_spec.autoscaling_policy_str(),
requested_resources_str=backend_utils.get_task_resources_str(task),
status=serve_state.ServiceStatus.CONTROLLER_INIT)

If the code is aborted before adding the version and after adding the service, it will cause a misalignment. In this PR we move the adding of initial version closer to the service table, to reduce the possibility of causing such misalignment, though arguably it is still 'possible' to happed, so I added a safe guard here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An example of abortion would be shutil lib call to fail, e.g. permission issues

Copy link
Collaborator

Choose a reason for hiding this comment

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

Was the previous issue mainly because the clean up not deleting the final version from the version_spec table, which is fixed by the delete_all_versions now?

If this safe guard is only for rare case, it would be great to mention that this is rare in the comment here to make sure we still know whether this is a common case in the future. : )

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, sorry for not making it clear. The previous issue is the misalignment of service and version_spec, which causes the _get_service_status to return a None (due to the joining of the two tables), and causes the assertion to abort the deletion of the service.

service_status = _get_service_status(service_name,
with_replica_info=False)
assert service_status is not None, service_name

I found that we did not clean up the remaining version when I debugged the original issue, and fix that in the same PR along the way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If this safe guard is only for rare case, it would be great to mention that this is rare in the comment here to make sure we still know whether this is a common case in the future. : )

Good point! Added a comment for this. Thanks!

Comment on lines +159 to +161
# Add initial version information to the service state.
serve_state.add_or_update_version(service_name, constants.INITIAL_VERSION,
service_spec)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious, is this movement related to the bug?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, please see the comment above 🫡

Copy link
Collaborator

@Michaelvll Michaelvll left a comment

Choose a reason for hiding this comment

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

Thanks for the fix @cblmemo! LGTM.

@cblmemo cblmemo added this pull request to the merge queue Aug 7, 2024
Merged via the queue into master with commit 51f1f78 Aug 7, 2024
20 checks passed
@cblmemo cblmemo deleted the serve-fix-version branch August 7, 2024 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants