-
-
Notifications
You must be signed in to change notification settings - Fork 919
[WIP] using db-pool library to create a pool of databases #5846
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
base: main
Are you sure you want to change the base?
Conversation
.await; | ||
|
||
// TODO make compatible with ActualDbPool | ||
db_pool.pull_immutable().await |
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 created this WIP PR to share the progress and the issue I'm stuck with currently. The crate I use operates with its own structure wrapping connection pools: code
And we have our own ActualDbPool. They are kinda same, but it's not obvious for me how to correctly convert one to another.
I had an idea to make ActualDbPool
a enum with two possible values: RegularPool and ReusablePool, but stuck on trying to adapt stuff like LemmyContext, which also requires pool struct to be clone-able (and ReusablePool is not). And it seems a lot of changes to the main codebase for purely test changes.
Do you folks have any ideas how to manage that? Or should I stick to the initial plan without using this library?
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.
Our ActualDbPool
is just a type alias for deadpool Pool<AsyncPgConnection>
.
Their crate should be able to work with deadpool pools, but I'm not familiar with how to plug that into their crate... you'll have to ask them.
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.
Yeah, I see. I returned to this issue today after a week of a break. I'm in contact with the db-pool author and they're helping to understand a lot of moments and really willing to collaborate, so i think we'll make this work.
I'd like to clarify one moment: do we want build_db_pool_for_tests
to return still ActualDbPool
? db-pool
has its own wrapper ReusableConnectionPool
which works like a deadpool Pool
, but a bit different and needs adaptation. And it might be easier to adapt tests for working with ReusableConnectionPool
than converting ReusableConnectionPool
to ActualDbPool
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.
The return type of build_db_pool_for_tests
may be changed. Also, a DbPool
variant may be added if needed.
crates/api/api_utils/src/context.rs
Outdated
|
||
#[derive(Clone)] | ||
pub struct LemmyContext { | ||
pool: ActualDbPool, | ||
pool: ContextPool, |
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.
This is the moment which currently blocks me, and i think it's better to consult with you again. LemmyContext
structure must be cloneable, therefore all the fields, therefore the pool. But unfortunately, reusable pool from db-pool
crate is not, and i don't have access to its fields to implement the trait here.
But before asking db-pool
developer, i'd like to be sure we really need this pool cloning stuff, especially for the tests. Cloning the pool seems a bit strange to me, but i may miss something. I'm looking at the code now, but maybe you folks already have some insights on this
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.
Wrap it in Arc
for now.
Update: I'm working on the topic; cannot devote much time for it, but it slowly going forward, and i keep the code in the branch up-to-date. I connected |
Hey! I've a question about the replaceable schema — found out it's the reason tests are failing in the branch: the tests are being run in restricted privilege mode, and have no access to the |
Yes I believe the main reason is so that they're easier to clean up.
Everything in the
Is this a limitation of the db-pool library? Because regular cargo tests can already run the |
Yep, it's designed the way you have privileged connection pool to prepare dbs and do migrations, and restricted connection pool to run tests. And the latest can only access |
Maybe its just a matter of running https://stackoverflow.com/questions/17338621/what-does-grant-usage-on-schema-do-exactly cc @dullbananas |
that's an option i'm thinking about. but unfortunately it has certain caveats.
however, i can change it in a fork, so it will use the same role for all the restricted connections (e.g. |
Maybe. The problem is almost certainly caused by something being different between the "public" schema and the "r" schema. Otherwise migrations would have failed before replaceable_schema runs. |
There's logic in the db-pool library which grants permission to restricted user fro public schema assuming it's the only one tests will deal with. |
Addresses: #4979