-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add helpful error when pool size is too small #2259
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
Conversation
What would be the best way to test this? The transaction checkout in the migration task would raise the exception that this is providing a more descriptive error for. |
Unfortunately this would only work with Ecto.Adapters.SQL.Sandbox and not the other pools. Also we don't want to be pattern matching on the string |
It is probably better to check the pool size on Ecto.Migrator or on the "ecto.migrate" task.
|
Are we not able to make it work with single connection by default? |
@fishcakez copying from the other comment in case some folks find this question first:
|
@blatyo I think instead of trying to wrap the error message, we should proactively check the pool_size in those two places:
What do you think? |
@josevalim I was trying to only show an error when there was actually an issue. The SQLite adapter could run with pool_size 1 and be fine. Although, since it's being defaulted to 2 and very few people would configure their repo with less than two, I guess it's not too bad to error on 1. I'll put something up later tonight. |
@fishcakez Like José said, but put a different way, it could be made to work with a single connection as long as you never disabled transactions on a migration. |
@blatyo so maybe we could check for the pool size on lock_for_migration? If set, the pool size is in |
@josevalim Is it possible at that point to just ask the pool how many connections it has rather than looking at the options? |
@blatyo I don't think we can ask the pool, there is no such API in DBConnection, but they should all respect the pool_size option. |
@josevalim we have a pool that is always size 1 ( |
@fishcakez that's a great. Since the goal of the error is to provide a better error message, we don't need to be 100% accurate though. So I would move on with an opts check for now and replace with a status check later on. What do you think? |
This sounds good. I expect very few people use this pool because they would need to dive into DBConnection and also not need more than 1 connection so I am not worried about it for a major version change in Ecto. It might be easier if we warn or crash on the single connection pool if pool_size is set other than 1 in DBConnection.Connection itself, and of course do the warning here too. |
I've pushed a new commit that should address everything discussed. I'm unsure where to add a test, as it seems not much in the adapter sql is directly tested. |
We can probably test it on integration_test/sql/migration.exs. Note we will need to start a pool exclusively for this test and then trigger the migration command. |
integration_test/cases/migrator.exs
Outdated
@@ -6,11 +6,12 @@ defmodule Ecto.Integration.MigratorTest do | |||
import Support.FileHelpers | |||
import Ecto.Migrator, only: [migrated_versions: 1] | |||
|
|||
alias Ecto.Integration.PoolRepo | |||
alias Ecto.Integration.{PoolRepo, SingleConnectionRepo} |
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.
Most of the time you are using the multiple single line alias/require/import/use directives but here you are using the multi-alias/require/import/use syntax
f28b522
to
9bdc70b
Compare
I've added a test case. AFAIK, the failing test is not related to the changes I've made. |
❤️ 💚 💙 💛 💜 |
No description provided.