good morning!!!!

Skip to content
Snippets Groups Projects
Commit f76e7734 authored by Garet Halliday's avatar Garet Halliday
Browse files

allow multiple replicas

parent 78cc2f41
No related branches found
No related tags found
No related merge requests found
......@@ -21,8 +21,8 @@ PostgreSQL pooler (like PgBouncer) with sharding, load balancing and failover su
| Transaction pooling | :white_check_mark: | :white_check_mark: | Identical to PgBouncer. |
| Session pooling | :white_check_mark: | :white_check_mark: | Identical to PgBouncer. |
| `COPY` support | :white_check_mark: | :white_check_mark: | Both `COPY TO` and `COPY FROM` are supported. |
| Query cancellation | :white_check_mark: | no | Supported both in transaction and session pooling modes. |
| Load balancing of read queries | :white_check_mark: | no | Using random between replicas. Primary is included when `primary_reads_enabled` is enabled (default). |
| Query cancellation | :white_check_mark: | :white_check_mark: | Supported both in transaction and session pooling modes. |
| Load balancing of read queries | :white_check_mark: | :white_check_mark: | Using random between replicas. Primary is included when `primary_reads_enabled` is enabled (default). |
| Sharding | :white_check_mark: | no | Transactions are sharded using `SET SHARD TO` and `SET SHARDING KEY TO` syntax extensions; see examples below. |
| Failover | :white_check_mark: | no | Replicas are tested with a health check. If a health check fails, remaining replicas are attempted; see below for algorithm description and examples. |
| Statistics | :white_check_mark: | no | Statistics available in the admin database (`pgcat` and `pgbouncer`) with `SHOW STATS`, `SHOW POOLS` and others. |
......
......@@ -16,8 +16,8 @@ import (
)
type connections struct {
primary *server.Server
replica *server.Server
primary *server.Server
replicas []*server.Server
mu sync.Mutex
}
......@@ -27,11 +27,11 @@ func (s *connections) choose(role config.ServerRole) *server.Server {
case config.SERVERROLE_PRIMARY:
return s.primary
case config.SERVERROLE_REPLICA:
if s.replica == nil {
if len(s.replicas) == 0 {
// fallback to primary
return s.primary
}
return s.replica
return s.replicas[rand.Intn(len(s.replicas))]
default:
return nil
}
......@@ -141,7 +141,7 @@ func (c *ConnectionPool) chooseConnections() *connections {
case config.SERVERROLE_PRIMARY:
srvs.primary = srv
case config.SERVERROLE_REPLICA:
srvs.replica = srv
srvs.replicas = append(srvs.replicas, srv)
}
}
if srvs.primary == nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment