-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
sqlite: add support for SQLite Session Extension #54181
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
Wouldn't this be solved if users could use their own SQLite build? That's already being considered according to the original issue. |
@karimfromjordan Nope, because you need access to the C API to access this feature. |
Can you add the appropriate documentation as well? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #54181 +/- ##
========================================
Coverage 87.32% 87.33%
========================================
Files 649 649
Lines 182618 182808 +190
Branches 35033 35083 +50
========================================
+ Hits 159475 159653 +178
- Misses 16407 16409 +2
- Partials 6736 6746 +10
|
I need to make sure sessions are deleted before the database they are attached to is closed. I think I need the When a |
9fe44b8
to
36e1920
Compare
@anonrig I have added documentation, most of the functionality and fixed the lint issues. Could you trigger another CI run? I want to add support for generating a patchset and then this PR is ready for review. I have some ideas for future improvements, e.g. more fine-grained conflict handling or exposing the utilities SQLite provides for inspecting and merging changesets, but they can be added in a backward-compatible manner. |
768d950
to
1948ee0
Compare
8fc1cf0
to
aaf0928
Compare
08b3562
to
b544d2f
Compare
This is excellent work that many projects will surely be based on. I am curious about the eventual wrapping of the entire Sessions C API (mixed & mashed into higher-level Node functions). Does this PR leave space for that? There are a few more Sessions API functions that would be of great use in Node. |
return tmpl; | ||
} | ||
|
||
void Session::MemoryInfo(MemoryTracker* tracker) const {} |
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.
I am not sure how to implement these.
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.
@jasnell Do you know if anything needs to happen here?
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.
For now I'd say it is ok to leave this as is.
@TheOneTheOnlyJJ Thanks! I agree that exposing more functionality of the Session Extension in Node.js would be great. Here are some ideas:
Here is the full API for future reference: https://www.sqlite.org/session/funclist.html Right now I first want to gather some feedback, but I'd be interested continue working on this, either in a follow-up PR or in this one. Since the SQLite integration is still under active development I think working incrementally is the preferred approach. |
Good point, here's my view on them:
Yes, I was about to suggest these. There's also
This should be a high priority right now, as long-running Node processes (like server back-ends) that would use Sessions will have their memory slowly but surely filled up with no way of freeing it without closing the database connection. Applications could run for months or even longer without closing a database connection, so not being able to close Sessions and free their memory would deter developers from using them. The database should, of course, still keep a list of all active sessions and delete them when it is closed, just in case not all Sessions were manually closed. From my point of view, this function should be wrapped as soon as possible and be included in this PR. Not having it surely decreases the chances of getting this merged, and it would be a shame to lose out on this.
Very important functionalities, but again, they're not vital for achieving functional basic interaction with the extension. These 3 points could be bundled in a follow-up PR that handles the finer-grained data management side of the API. The
I've noticed this in the documentation and it's definitely a part of the API that would be crucial in large apps with large databases. But again, for the current goal of incrementally proposing a stable API that exposes the API of the extension, this is not required right now. It would also require wrapping Also, before I wrap up... I noticed that you proposed the |
Agreed. I will still add this one as part of this PR.
I don't see any benefits. Furthermore, I like the philosophy of better-sqlite3:
In this vein I also oped to default to aborting on conflict, instead of requiring an explicit conflict handler to be passed like in the API of SQLite. |
Yes, this would be ideal. For further updates other than this, I believe it's best to wait for the final form of the
I was checking if any additional functionality could be squeezed out by separating the functions. Given that there is none, your decision is a sensible one and I support it.
This is also the best sane default option, as every developer should customize this behavior according to their use case. I'm not experienced in the internals of Node, so my contribution here can only amount to discussing the API design and smaller implementation details. I guess the next step now (after implementing the Session |
Co-authored-by: James M Snell <jasnell@gmail.com>
Co-authored-by: Aviv Keller <redyetidev@gmail.com>
Co-authored-by: Aviv Keller <redyetidev@gmail.com>
Co-authored-by: Aviv Keller <redyetidev@gmail.com>
Co-authored-by: Aviv Keller <redyetidev@gmail.com>
Co-authored-by: Colin Ihrig <cjihrig@gmail.com>
Thanks for your reviews! Took me a while to get back to this. I have addressed most comments and left a few questions. Please have another look if you have the chance. If someone could kick off CI that would be great. |
We were talking about adding support for the Session Extension of SQLite in #53752. This is not a run-time extension but rather a feature built in to the SQLite amalgamation. It can be enabled with a compile flag and is enabled by default on some platforms.
I have never contributed to Node.js before so I will probably need some help to bring this to a conclusion.
TODO:
Throw with specific (documented) exception in case of conflict when applying changesetsince SQLite doesn't consider this to be an error I returnfalse
when applying the changeset is aborted due to a conflictExample usage: