yiisoft / db

Yii Database Library
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
131 stars 35 forks source link

[Refactoring todo] Master/Slave implementation of ConnectionInterface #260

Open darkdef opened 2 years ago

darkdef commented 2 years ago

Need create separate implementation of Master/Slave connection and remove this magic from current realisation. CQRS - responsibility of user

samdark commented 2 years ago

Do you still want slave connection to be a pool of database connections? i.e. if there's multiple slave instances, would it still look like a single one to developer?

darkdef commented 2 years ago

I think need simple implementation of single connection. And creating Multiconnection (also implementation of ConnectionInterface, but with pool of connections. Inherit or decorator) with inner using instances of singleconnection

samdark commented 2 years ago

Decorator sounds great but the thing is that selecting master or slave depends on the query being made i.e. read queries go to slave, write queries go to master so it's not possible to achieve using just decorator over connection. It should be decorator over query builder.

darkdef commented 2 years ago

Yes, there may be problems with the current implementation. But similar functions must be removed from the connection: getMasterPdo, getSlave

darkdef commented 2 years ago

Not actual. Interfaces are separated

alamagus commented 1 year ago

@darkdef don't you think that current design of ConnectionPoolInterface doesn't quite get along with Single Responsibility Principle? Say, if I want to use ConnectionPoolInterface with RR/Swoole, and I have only one database, why would I bother with Master/Slave settings And what's the advantage of $dbPool->useMaster(callable $callback) over $callback($dbPool->getMaster()) ?

darkdef commented 1 year ago

Why do you need a connection pool for a single database?

alamagus commented 1 year ago

At least in Swoole it's used to reuse connections, so there's no waste of time on establishing connections to db during every new request(you can't use single connection from different coroutines; each new request is handled in new coroutine(well, depends on settings, but it's popular setting) ) Mb I got wrong perception of Connection Pool :thinking: UPD. example of ConnectionPool class in Swoole https://github.com/swoole/library/blob/master/src/core/ConnectionPool.php

darkdef commented 1 year ago

You understand the concept correctly.
At the moment, we have tried to keep the functions in the pool interface.
During implementation, there will be refactoring and we will take into account your comment.