Repository navigation
Move pool and friends out of DatabaseConfig - #37408
eileencodes wants to merge 1 commit into
Conversation
This PR moves `pool`, `disconnect_pools!`, `discard_pool!`, `disconnect_pool!`, etc out of the `DatabaseConfig` and into a new `PoolManager` class. The `DatabaseConfig` is for storing how databases connect and shouldn't have any knowledge of their pool. We also removed the WeakMap since discard (which it calls) already removes entries from the config_to_pool Hash - and no tests failed. We should get the same behavior as WeakMap by deleting from the map. Co-authored-by: John Crepezzi <[email protected]>
08103a6 to
0a1ea4b
Compare
Yeah but that's not what it was for. In this PR you have The |
Cool, we can add it back - I'm not sure how to test it. Any ideas? |
I'd say create a new def test_gc
db_config = DatabaseConfig.new(blah)
pool_ref = WeakRef.new(PoolManager.instance.pool_for(db_config))
assert_predicate pool_ref, :weakref_alive?
4.times { GC.start } # 4 times is mandatory for making sure old gen is GCed as well.
refute_predicate pool_ref, :weakref_alive?
endThe problem is that since this hash is now the only reference to the No sure how we could go about that. 🤔 |
|
Is there any reason why we need to remove the poll from DatabaseConfig right now? I do believe the actual DatabaseConfig should be renamed to something else and a new DatabaseConfig should be created with the only responsibility of holding the config. I do think we need a object that holds the pool, schema cache and the config. We would call this object If we need to remove the poll from DatabaseConfig I'd prefer to go to that direction instead of adding a new singleton since this only add complexity to the codebase. It is already very hard to understand how the singleton ConnectionHandler work. |
Yes because work that @seejohnrun and I are trying to do to DatabaseConfig is blocked by this due to the DatabaseConfig needing to know about the state of the pool.
I don't think we need to rename We moved this to a PoolManager class for now because we needed to get it out of |
|
FWIW we were going to move schema cache after this PR, we just were doing it in multiples instead of all at once. We can move everything all at once instead and make a new class to handle this. |
There was a problem hiding this comment.
My main concern if with the fact PoolManager is a singleton. I don't think it needs to be.
When I say rename the class I actually mean doing:
class DatabaseConfig -> class Role
And
class Role
def initialize(database_config)
end
end
Role.new(DatabaseConfig.new)
In the end we will have a DatabaseConfig with the previous responsibility, but we will not have a singleton. We need again to have that internal hash config_to_pool similar to the owner_to_config. Having those two identical constructors is a clear small that those two concepts should be the same.
If this unblocks you I'm fine with it, but I don't think we should keep this implementation around.
|
Actually, after second thought. I'd prefer to just revert the previous PR than moving to this direction. I think those two singletons should be the same and there is no advantage on splitting them. I prefer we redo the previous PR already implementing the |
|
Previous to #37296 the implementation works like this: We can add a Role class that encapsulates pool, db_config, and schema cache but aren't sure what we're hoping to get from that change given that we could already get from owner to pool and from there reach the db_config and schema_cache in the original implementation. I really appreciate the work you're doing to add sharding and I don't want to block that work. However we're stuck on our upgrade internally and on the features we need to implement going forward. I want to also make sure we're making things simpler and better and don't add unnecessary complexity. Maybe we need to revert the #37296 until we have a clearer design of the future state? Can you show us in a graph what you're going for - that might make it easier to get on the same page. I think John and I can also add a lot more tests to better demonstrate our usage requirements. |
I think that is better in my opinion. It unblocks you and we can work skipping the current intermediate step that we introduced. I'll let @byroot explain the object model that he had in mind and why it is not possible to implement what we want with the current one. |
|
Revert opened in #37444 |
This reverts commit 4ea7769, reversing changes made to 2ef9eca. I'm reverting this PR for now at Rafael's recommendation because some of the changes have caused our Rails upgrade at GitHub to be blocked (we use some private API's) as well as other work to use the db_config to establish a connection. See PR and comments here rails#37408 for more detail.
|
👋 trying to catch up here. I'll be mostly off line this week end and the coming week, but I'll try to find some time to see if instead of reverting that PR we could just do a quick introduction of the envisioned In short:
Would that work for you @eileencodes ? I can't guarantee it will work until I try, but shouldn't be too hard (#famouslastwords) |
|
@byroot I might be missing something but can you go into a bit more detail on what we get by replacing |
|
@seejohnrun you are right that at the moment, we could move most of However my long term goal is to be able to load the database topology without having to load models or connect to any database. So in this context using Also in the future I want to move the Let me know if that still isn't clear. |


Note: this PR removes WeakRef and no tests failed. If we need it we can add tests to make sure it sticks around in future refactorings.
cc/ @casperisfine @rafaelfranca @matthewd @seejohnrun @tenderlove @jhawthorn
This PR moves
pool,disconnect_pools!,discard_pool!,disconnect_pool!, etc out of theDatabaseConfigand into a newPoolManagerclass.The
DatabaseConfigis for storing how databases connect and shouldn'thave any knowledge of their pool.
We also removed the WeakMap since discard (which it calls) already
removes entries from the config_to_pool Hash - and no tests failed.
We should get the same behavior as WeakMap by deleting from the map.