-
Notifications
You must be signed in to change notification settings - Fork 510
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
[Spot] Make spot_state use safe_cursor(). #2102
Conversation
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.
Thanks for identifying this issue @concretevitamin! Left a question about the consistency across the modules. : )
sky/spot/spot_state.py
Outdated
@contextlib.contextmanager | ||
def _safe_cursor(): |
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.
It seems we have this in the sky.skylet.configs
as well. Do we want to refactor it as a common utility function in sky.utils.db_utils
?
Also, we have a db_utils.SQLiteConn
which creates a thread-level connection for the database and serves for the same purpose in job_lib
and global_user_state
. Can we have choose one of them for all the modules using sqlite?
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.
Good point - moved it into db_utils.safe_cursor()
. SQLiteConn
doesn't come with auto-commit as a context manager so I didn't use it.
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.
Thanks @concretevitamin! LGTM.
One general question: will adding the commit
after read-only queries degrade the performance, as we have quite many SELECT
queries that do no modify the database?
On a controller,
which is fast enough. |
* [Spot] Make spot_state use safe_cursor(). * db_utils.safe_cursor()
When developing a basic Flask app that eventually calls into
spot_state.get_spot_jobs()
, SQLite complained about threading errors. Withsafe_cursor()
this error was fixed. This PR changes the entire spot_state module to use it.Tested (run the relevant ones):
bash format.sh
pytest tests/test_smoke.py --managed-spot
pytest tests/test_smoke.py::test_fill_in_the_name
bash tests/backward_comaptibility_tests.sh