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

Add `beforeApplyChanges` Project Changes event #5802

Closed
nateiler opened this issue Mar 17, 2020 · 3 comments
Closed

Add `beforeApplyChanges` Project Changes event #5802

nateiler opened this issue Mar 17, 2020 · 3 comments

Comments

@nateiler
Copy link
Contributor

@nateiler nateiler commented Mar 17, 2020

We experienced some issues applying project config changes in our master/slave database configuration (AWS RDS). It appears there is a small lag between the read and write instance propagation which results in various errors (field column not found, etc).

If a beforeApplyChanges event were available to us, we could disable the read-only database while performing the project config changes.

Ref:

const EVENT_AFTER_APPLY_CHANGES = 'afterApplyChanges';

@brandonkelly

This comment has been minimized.

Copy link
Member

@brandonkelly brandonkelly commented Apr 1, 2020

I wonder if this is something we can solve directly in core, rather than making everyone that uses read/write splitting have to implement their own workaround.

Seems like it wouldn’t be quite as simple as disabling the slave connections for the duration of the sync request though, because even once that’s done, there will still be a lag before all changes have been fully copied over, where subsequent requests could still get SQL errors. So maybe it would be best to restore the slave connections via a delayed queue job, perhaps delayed by 60 seconds by default.

Thoughts? What were you planning on doing, given this event?

@nateiler

This comment has been minimized.

Copy link
Contributor Author

@nateiler nateiler commented Apr 2, 2020

In our case (AWS RDS) I'm thinking we're talking in milliseconds and seems to be tied to schema changes (add/rename columns/tables).

Our approach would be to use the before and after events to toggle the 'enableSlaves' connection value. https://www.yiiframework.com/doc/api/2.0/yii-db-connection#$enableSlaves-detail

@brandonkelly

This comment has been minimized.

Copy link
Member

@brandonkelly brandonkelly commented Apr 4, 2020

Alright, in that case, just went with the ultra simple option here. As of Craft 3.4.14, applyYamlChanges() will disable read/write splitting for the remainder of the request.

To get the fix early, change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#bf9ff1eab9dfd8d50a9b22c6be5e32513dfe5924 as 3.4.13",
  "...": "..."
}

Then run composer update.

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.