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
Remove cache flushing on startup #18238
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we instead flush the caches in api/src/database/migrations/run.ts in case a migration has actually been performed? Theoretically a migration can lead to any changes in the database.
Yes we should. 👍 However, when a new migration is added or when the schema is changed, the same issue occurs. I wonder if we should add a |
Right, this sounds like a good plan 👍 |
I don't think that'll solve it either. On migrate, you'll still have active containers on the old version, while the new one is upgrading. I think the only real fix is to make sure we add the current api version as part of the redis key |
Wouldn't the other instances get notified by the messenger about the schema change? Together with @licitdev's idea of locking the schema fetch I think that should work 🤔 Edit:
Oh yeah, and for the instances still running on older versions this would be required too 👍 |
For now I think we could simply move the |
@paescuj I don't think that'll work. Lets say you have 4 instances on v1. When updating, you'd move one instance to v2, wait for it to be done, and then move 2/4 to v2, 3/4 to v2, 4/4 to v2. When the first v2 comes online, migrations run and caches are flushed, however, because those other 3/4 are still on v1, the caches are recreated as fast as they're flushed. If there's a breaking change in that migration, it'll start crashing on both sides |
Yeah, I understand. (So that would have already been the case up to now...? 👀😅) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
* Remove cache flushing on startup * Flush caches on migrate * Add current API version to cache key * Fix expect hashes in test
This was added way back when to make sure that projects that upgrade don't run into bugs due to changes in the structure of the cache. However, this comes with the (huge) side-effect that all caches are flushed whenever a horizontal scaling event happens (eg when the project is scaling up, the caches are flushed, putting needless strain on the database while all containers try to regenerate the schema cache simultaneously).
Fixes #18245