Documentation ¶
Overview ¶
Package rdsmysql provides load balancing of read-only queries across multiple database instances. Designed to work with AWS RDS Aurora read slaves auto-scaling.
Details ¶
- queries information_schema.replica_host_status table discovering new or removing no longer available replicas
- supports replica restarts and deletes, retries connections failed this way against a different instance
- does not retry queries that failed in progress (due to hard server shutdowns, network interruptions)
Index ¶
Constants ¶
const DriverName = "rdsmysql"
DriverName is the public name of the driver
const MaxConnectAttempts = 5
MaxConnectAttempts is the max number of tries to connect to a server
const MaxServersTriedForQuery = 3
MaxServersTriedForQuery is the max number of servers tried for a query. The actual number of retries is +1 since it tries to connect to initial instance twice.
Variables ¶
var DefaultDriverOpts = url.Values{
"collation": {"utf8mb4_unicode_ci"},
"parseTime": {"true"},
"autocommit": {"true"},
"timeout": {defaultConnectTimeout.String()},
"readTimeout": {defaultReadimeout.String()},
}
DefaultDriverOpts are the default driver values if not provided in the DSN
var ErrConnectMaxRetriesExceeded = errors.New("tried MaxServersTriedForQuery servers to connect, all failed")
ErrConnectMaxRetriesExceeded is returned from Query when query tried more than MaxServersTriedForQuery servers, and all of them failed. There could be more available instances.
var ErrExecMaxRetriesExceeded = errors.New("max retries exceeded for retryable error")
ErrExecMaxRetriesExceeded is returned after exhausting a retryable query
var ErrNoServersAvailable = errors.New("no servers available")
ErrNoServersAvailable is returned from Query when no servers are available. All servers returned from information_schema.replica_host_status failed.
var ErrUnsupportedMethod = errors.New("unsupported method")
ErrUnsupportedMethod is returned for an unsupported method that is invoked against the underlying driver
var MaxRetries = 3
MaxRetries is the max number of times that a deadlock query will be retried
Functions ¶
Types ¶
type Logger ¶
type Logger interface {
Log(keyvals ...interface{}) error
}
Logger is the fundamental interface for all log operations. Log creates a log event from keyvals, a variadic sequence of alternating keys and values. Implementations must be safe for concurrent use by multiple goroutines. In particular, any implementation of Logger that appends to keyvals or modifies or retains any of its elements must make a copy first.
var L Logger = &defaultLogger{}
L is the logger to use internally by the package, defaults to a logger which is no op
type TrackedConn ¶
type TrackedConn interface {
// Terminate will forceably shutdown the connection and close all db
Terminate()
}
TrackedConn is an interface that the conn implementation returned from the Open returns to allow it to be terminated