-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
feat: allow to specify read-only replica for SELECTs #1085
Conversation
edf633e
to
6bf1e97
Compare
6bf1e97
to
702e525
Compare
Awesome. I think variadic function is a good way to allow multiple replicas to be set at once. db := bun.NewDB(sqldb, dialect,
bun.WithReadOnlyReplicas(sqldb2),
bun.WithReadOnlyReplicas(sqldb3, sqldb4),
bun.WithReadOnlyReplicas(replicas...)) |
When we want to use the master for a specific query to avoid master-slave replication delay, how should we proceed? |
There is a db.NewSelect().Conn(db) |
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this pr will be closed. Please feel free to give a status update now, ping for review, when it's ready. Thank you for your contributions! |
This is ready for review. Please speak up if there are any concerns. |
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) | ||
defer cancel() | ||
|
||
healthy := make([]*sql.DB, 0, len(r.replicas)) |
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.
Is it necessary to declare two slices and always use the one not utilized by r.healthyReplicas
to avoid memory allocation?
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.
It sounds like you suggest to declare 2 slices and re-cycle them in the monitor
.
It is not totally safe since we don't exactly know when the slice becomes free, but more importantly I believe it is not worth it since a slice allocation every 3-5 seconds is not going to change much.
Co-authored-by: Aoang <[email protected]>
Co-authored-by: Aoang <[email protected]>
…ica' into feat/read-only-replica
There are some minor API changes. Most notable of them is the removal of
GetConn() IConn
method, because the internal queryconn IConn
must be initialized tonil
so Bun can resolve to a random read-only connect.Overwriting the connection using
query.Conn(conn)
still works.The usage should be like this:
Closes #1037