-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fix/default to maindb if read replica errs #1221
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## develop #1221 +/- ##
===========================================
- Coverage 78.18% 77.95% -0.24%
===========================================
Files 48 48
Lines 1985 1996 +11
Branches 314 315 +1
===========================================
+ Hits 1552 1556 +4
- Misses 433 440 +7 ☔ View full report in Codecov by Sentry. |
let found = await this.replicationRequestRepository.findByCid(cid) | ||
let found | ||
try { | ||
found = await this.replicationRequestRepository.findByCid(cid) |
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.
My preference would be to expect the replica to work if it exists, but default the config to main if there is none defined. I think we should expect it to work if it's defined, but it should be optional.
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.
In terms of implementation, I'd expect we either set up a RO connection pool, or we just use the main pool and the app still calls replicationRequestRepository
for all reads because it doesn't require the writer, without needing to know anything about the actual DB used.
This also avoids doing double reads for things that don't actually exist and potentially getting hung trying to talk to a non-exists RO instance.
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.
yeah, it all around a better design to make the read replication optional. FYI, currently all our reads do not got to the replica. If the configuration for the read replica is not specified or if any of the config params are missing, we default to the maindb. Will add a commit for this and tag you, let me know if this might fix it or there might be something else I missed
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.
I like the changes you made, do we still need this fallback? if it fails now, it seems like it's failing for a reason so there's not sure we need to try another database.
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.
yup, in the case of the read replica not having the request. If sync b/w the db's is slow
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.
Yeah, what I was trying to say is that if the RR doesn't have the request, it's unlikely the main DB does so there's no reason to ask. If for some reason we're far enough behind on replicating (i.e. minutes), we probably don't want to load the main database more and should investigate. Otherwise, we can tolerate the client retrying again in a few seconds and the RR will respond with data.
@@ -71,7 +71,7 @@ export async function createDbConnection(dbConfig: Db = config.db): Promise<Knex | |||
|
|||
export async function createReplicaDbConnection( | |||
replica_db_config: Replicadb = config.replica_db | |||
): Promise<Knex> { | |||
): Promise<{ connection: Knex; type: string }> { |
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.
@dav1do this change makes the readReplica optional and by introducing a connectionType we have captured the two modes it can work in.
The type is also useful to avoid misleading logs in the connection failure mode giving devs more insight into what is happening in the background
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.
Looks good. One more comment since I'm not sure we need to fallback now but approving.
let found = await this.replicationRequestRepository.findByCid(cid) | ||
let found | ||
try { | ||
found = await this.replicationRequestRepository.findByCid(cid) |
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.
I like the changes you made, do we still need this fallback? if it fails now, it seems like it's failing for a reason so there's not sure we need to try another database.
[Replace Me With Meaningful Name] - #[Issue]
Description
Include a summary of the change and which issue it addresses in the title of the PR.
Include relevant motivation, context, brief description and impact of the change(s). List follow-up tasks here.
How Has This Been Tested?
Describe the tests that you ran to verify your changes. Provide instructions for reproduction.
Definition of Done
Before submitting this PR, please make sure:
References:
Please list relevant documentation (e.g. tech specs, articles, related work etc.) relevant to this change, and note if the documentation has been updated.