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

Persistent session storage #614

Merged
merged 6 commits into from
Dec 6, 2021

Conversation

Zsailer
Copy link
Member

@Zsailer Zsailer commented Nov 18, 2021

Fixes #611

Makes the session database path a configurable trait and avoids overwriting the database if it exists.

Also, sets the database's isolation level to None so that it autocommits all changes after every change.

Copy link
Member

@kevin-bates kevin-bates 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 creating this PR Zach. This seems like a good evolutionary step in the server.

jupyter_server/services/sessions/sessionmanager.py Outdated Show resolved Hide resolved
@blink1073 blink1073 added this to the 1.12 milestone Nov 23, 2021
@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2021

Codecov Report

Merging #614 (fe3658d) into master (a1b013e) will increase coverage by 0.37%.
The diff coverage is 96.42%.

❗ Current head fe3658d differs from pull request most recent head fb4f33c. Consider uploading reports for the commit fb4f33c to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #614      +/-   ##
==========================================
+ Coverage   77.41%   77.79%   +0.37%     
==========================================
  Files         110      110              
  Lines       10252    10448     +196     
  Branches     1259     1416     +157     
==========================================
+ Hits         7937     8128     +191     
- Misses       1918     1921       +3     
- Partials      397      399       +2     
Impacted Files Coverage Δ
jupyter_server/services/sessions/sessionmanager.py 87.50% <91.30%> (+0.61%) ⬆️
...ter_server/tests/services/sessions/test_manager.py 100.00% <100.00%> (ø)
jupyter_server/pytest_plugin.py 84.97% <0.00%> (-3.10%) ⬇️
jupyter_server/tests/services/kernels/test_api.py 97.60% <0.00%> (-1.41%) ⬇️
jupyter_server/base/zmqhandlers.py 59.09% <0.00%> (-1.18%) ⬇️
jupyter_server/tests/services/sessions/test_api.py 98.16% <0.00%> (-0.75%) ⬇️
jupyter_server/serverapp.py 65.35% <0.00%> (-0.13%) ⬇️
jupyter_server/tests/services/kernels/test_cull.py 100.00% <0.00%> (ø)
jupyter_server/tests/services/contents/test_api.py 99.76% <0.00%> (+<0.01%) ⬆️
jupyter_server/services/kernels/handlers.py 61.92% <0.00%> (+1.10%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1b013e...fb4f33c. Read the comment docs.

@Zsailer
Copy link
Member Author

Zsailer commented Dec 6, 2021

Ok, I've added validator to database_filepath trait in SessionManager that verifies:

  • path is not a directory
  • file on disk is a valid SQLite 3 file (empty files are also allowed).

I've added some unit tests to (1) confirm database_filepath validation is working properly and (2) the session persistence is working when across session manager instances.

Ping @kevin-bates, @mwakaba2 and @Wh1isper for a second round of reviews. Thanks, y'all!

"`database_filepath` expected a file path, but the given path is a directory."
)
# If the file exists, but it's empty, its a valid entry.
if os.stat(path).st_size == 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say just try to connect to the file here and let the error propagate. I verified that you can connect to an empty file.

@@ -47,14 +46,12 @@ def _validate_database_filepath(self, proposal):
raise TraitError(
"`database_filepath` expected a file path, but the given path is a directory."
)
# If the file exists, but it's empty, its a valid entry.
if os.stat(path).st_size == 0:
return value
# Verify that database path is an SQLite 3 Database by checking its header.
with open(value, "rb") as f:
Copy link
Contributor

Choose a reason for hiding this comment

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

I meant also for the contents validation piece, rather than inspecting the file

Copy link
Member Author

Choose a reason for hiding this comment

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

I think sqlite3 overwrites the file if it's not a valid database format, rather than raising an exception if the file has contents that are not sqlite data.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yup, confirmed.

Copy link
Contributor

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@Zsailer
Copy link
Member Author

Zsailer commented Dec 6, 2021

Thank you! Merging!

@Zsailer Zsailer merged commit b51969f into jupyter-server:master Dec 6, 2021
@Zsailer Zsailer deleted the persistent-sessionmanager branch January 16, 2024 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Persistent Session Storage
6 participants