Skip to content
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

Active Record Master / Slave latency and update #4799

Closed
Ragazzo opened this issue Aug 23, 2014 · 6 comments
Closed

Active Record Master / Slave latency and update #4799

Ragazzo opened this issue Aug 23, 2014 · 6 comments

Comments

@Ragazzo
Copy link
Contributor

Ragazzo commented Aug 23, 2014

Would be great to know how to limit effect of slave update with Yii2. The problem is that when we perform some update on user data we do it on master and to avoid eventual consistency and data latency update we should read from the master actual data that needed for current request (data that was updated). If it is for UI then it is fine since we actually can make simple query with DAO, but when it is about AR and application logic then it is becoming a little bit hard. How to reroute query to master for the AR ? Currently the only solution is passing db instance in all($db) or one($db) and other methods.

@qiangxue can you maybe suggest some solution or brief overview of how it can be solved ? Also can you maybe add in docs how master balancing is supported ? I have not found it in code , would be great if you will point out it

@qiangxue
Copy link
Member

You can use

Yii::$db->useMaster(function () {
    // perform AR query here
});

You don't need to pass $db to all() or one(). This is documented in the tutorial already.

@samdark samdark closed this as completed Aug 23, 2014
@Ragazzo
Copy link
Contributor Author

Ragazzo commented Aug 24, 2014

Can you show hod load balancing for masters is done ?

@samdark
Copy link
Member

samdark commented Aug 24, 2014

@Ragazzo
Copy link
Contributor Author

Ragazzo commented Aug 24, 2014

@samdark too abstract i dont see where actually master is opened, this pool is used for slaves, can you maybe track some logic ? Would be great

@samdark
Copy link
Member

samdark commented Aug 24, 2014

@Ragazzo
Copy link
Contributor Author

Ragazzo commented Aug 24, 2014

I see , thanks , maybe it is better to create ReplicationConnection instead of mixup this functionality ? Same as done in Symfony 2 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants