-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Delay Adapter#check_version to #configure_connection #49378
Conversation
There's some intricate build failures to investigate. I'll have another look tomorrow. |
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.
👍🏻 Making this change was on my list of things to do. GitHub has a lingering Trilogy adapter patch that does basically the same thing, and it'll be nice for us to get that cleaned up.
3e566f6
to
50e337f
Compare
I only have one failure left in Action Cable, but I'm having trouble reproducing it locally :/ |
I haven't had the time to figure out the Action Cable issue today, but I don't expect it to need much more change. @matthewd any opinions here? |
90b60f8
to
55f5f4e
Compare
55f5f4e
to
f538068
Compare
Ok, so actually it seems they are currently broken on main. All the PostgresqlAdapter tests are skipped because we fail to connect to postgresql. The PG server is started but I think we fail to create the database or something. |
actioncable/lib/action_cable/subscription_adapter/postgresql.rb
Outdated
Show resolved
Hide resolved
@@ -233,7 +233,7 @@ def with_connection | |||
|
|||
# Returns true if a connection has already been opened. | |||
def connected? | |||
synchronize { @connections.any? } | |||
synchronize { @connections.any?(&:connected?) } |
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.
Gently hesitant here on whether callers are most likely to expect this to mean "are there physical sockets established" or "does this pool have conns in 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.
Well, the doc says "connection has been opened".
before my change this was true as soon as there one one adapter instance in the pool, now that the connection is properly lazy, it's no longer true. I had to change this to fix a good number of tests.
activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
Outdated
Show resolved
Hide resolved
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
Outdated
Show resolved
Hide resolved
warn "Ignoring #{filename} because it has expired. The current schema version is #{current_version}, but the one in the schema cache file is #{cache.schema_version}." | ||
connection_pool.schema_reflection.clear! |
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 sounds reasonable but only semi-related... assuming it is separate (the instigating change?), might be better split out, it only because of how confusing it is that this is also about a different version check? 😅
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.
Moved to #49415
979373d
to
e03f24f
Compare
e9fee38
to
2bca6fe
Compare
2bca6fe
to
1479702
Compare
1479702
to
e1612a1
Compare
e1612a1
to
0a688a7
Compare
I rebased on top of #49415, this solves the circular issue in PostgresAdapter. |
0a688a7
to
90e5d1c
Compare
Ref: rails#49378 As discussed with Matthew Draper, we have a bit of a chicken and egg problem with the schema cache and the database version. The database version is stored in the cache to avoid a query, but the schema cache need to query the schema version in the database to be revalidated. So `check_version` depends on `schema_cache`, which depends on `Migrator.current_version`, which depends on `configure_connection` which depends on `check_version`. But ultimately, we think storing the server version in the cache is incorrect, because upgrading a DB server is orthogonal from regenerating the schema cache. So not persisting the version in cache is better. Instead we store it in the pool config, so that we only check it once per process and per database.
c3c3854
to
8f2f25d
Compare
activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
Outdated
Show resolved
Hide resolved
8f2f25d
to
b67a9c7
Compare
Ideally we should be able to checkout an Adapter instance without triggering a connection to the server. For some adapters like Trilogy that is the case today, but only if you have a schema cache loaded, otherwise `check_version` will trigger a query. I think this check can be delayed to when we actually use the connection.
b67a9c7
to
2da1852
Compare
Ideally we should be able to checkout an Adapter instance without triggering a connection to the server.
For some adapters like Trilogy that is the case today, but only if you have a schema cache loaded, otherwise
check_version
will trigger a query.I think this check can be delayed to when we actually use the connection.