db icon indicating copy to clipboard operation
db copied to clipboard

[Refactoring todo] Master/Slave implementation of ConnectionInterface

Open darkdef opened this issue 3 years ago • 9 comments

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

darkdef avatar Jan 23 '22 16:01 darkdef

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?

samdark avatar Jan 23 '22 20:01 samdark

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

darkdef avatar Jan 24 '22 05:01 darkdef

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.

samdark avatar Jan 24 '22 13:01 samdark

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

darkdef avatar Jan 24 '22 17:01 darkdef

Not actual. Interfaces are separated

darkdef avatar Jun 19 '22 17:06 darkdef

@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()) ?

alamagus avatar Jul 28 '22 14:07 alamagus

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

darkdef avatar Jul 28 '22 14:07 darkdef

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

alamagus avatar Jul 28 '22 14:07 alamagus

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.

darkdef avatar Jul 28 '22 14:07 darkdef