Comments (5)
Logistically it would make more sense to override the Model methods 'create'/'save' to temporarily change the read connection service for these methods.
Altering the code base to account for anyone running a master-slave database infrastructure by 'reading' from the 'write' DB service doesn't make the most sense out of all possible solutions, in my opinion.
Based on the code at https://github.com/phalcon/cphalcon/blob/c8d4916bbfd0cb18395fe25d8c5a663fc5077d8f/phalcon/mvc/model.zep#L2959
You could do something like
namespace Custom;
class Model extends \Phalcon\Mvc\Model {
public function create($data = NULL, $whiteList = NULL)
{
$originalReadService = $this->getReadConnectionService();
$this->setReadConnectionService($this->getWriteConnectionService());
$result = parent::create($data, $whiteList);
$this->setReadConnectionService($originalReadService);
return $result;
}
}
from phalcon.
@sergeyklay Can we add this to the 4.0 milestone? We can evaluate it later for its validity. It seems though that it could eliminate some rare gnarly impossible to reproduce race conditions.
from phalcon.
Maybe we should not check if record exists, it's not just a master-slave latency problem. Even using the same connection here, unless you use select...for update
under a transaction,or else you can not avoid this 'cause of concurrency. @ifsnow @Mechzeit
Sent from my OnePlus ONEPLUS A5000 using FastHub
from phalcon.
Master-slave setup does not work with transactions either. If a transaction is active, all reads should be kept in master regardless the read connection. Doctrine has some cool rules to handle all these scenarios mentioned in this issue. I marked in bold the most important one that will covered the latency and the transaction issue.
Slave if master was never picked before and ONLY if 'getWrappedConnection' or 'executeQuery' is used.
Master picked when 'exec', 'executeUpdate', 'insert', 'delete', 'update', 'createSavepoint', 'releaseSavepoint', 'beginTransaction', 'rollback', 'commit', 'query' or 'prepare' is called.
If master was picked once during the lifetime of the connection it will always get picked afterwards.
One slave connection is randomly picked ONCE during a request.
from phalcon.
@acmenna Agree. But I don't think this could help exists()
before doLowUpdate
.
from phalcon.
Related Issues (20)
- [NFR]: Replace regexp in the router with arrays for extra performance
- Can't access page, 404 FORBIDDEN
- Can I use `$this->getRelated` on already cached data?
- [BUG]: Scrutinizer Fixes HOT 1
- [NFR]: ADD sticky for read write connection
- [NFR]: removeBehavior method in Model
- [NFR]:returnedValue not updated after dispatcher->forward
- [NFR]: No way to add html attributes to Select Tag. documentation inadequate HOT 1
- [BUG]: The "setDefault" method does not work for forms of type "text" with name "value" HOT 5
- update src folder links
- How to use cookie in phalcon 4.x ? HOT 1
- update tests folder links
- [NFR]: Complete rework of ORM HOT 3
- [BUG]: \Phalcon\Encryption\Crypt + named parameters/arguments throw fatal error. HOT 1
- [NFR]: Refactor Phalcon\Mvc\Router/Route HOT 1
- [NFR]: Refactor Phalcon\Mvc\Model\MetaData
- phalcon 3,4 webhook problem HOT 2
- [NFR]: What is the purpose of this library? HOT 3
- [NFR]: Add a getResult() or fetchAll() method to Resultset\Simple
- [BUG]: when i use JWT Builder , api returns blank HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phalcon.