Documentation
¶
Index ¶
- Constants
- func ConfigureConnReadDeadline(poolConfig *pgxpool.Config)
- func DataSourceName(d DataSourceNameParams) (string, error)
- func FmtNsID(sqlTemplate, namespaceID string) string
- func GetTablePreSplitTablets(ctx context.Context, pg *pgxpool.Pool, config *Config) (int, error)
- func IsYugabyteDB(ctx context.Context, pool *pgxpool.Pool) (bool, error)
- func MakeNsTablesQuery(nsID string, tablets int) string
- func NewPool(ctx context.Context, config *Config) (*pgxpool.Pool, error)
- func SetupSystemTablesAndNamespaces(ctx context.Context, config *Config) error
- func TableName(nsID string) string
- type Config
- type DataSourceNameParams
- type TLSConfig
Constants ¶
const (
// TxStatusTableName is the name of the system table holding per-transaction status.
TxStatusTableName = "tx_status"
)
Variables ¶
This section is empty.
Functions ¶
func ConfigureConnReadDeadline ¶
ConfigureConnReadDeadline configures pool connections with a per-read deadline so that reads on dead connections fail instead of hanging indefinitely.
We use a custom DialFunc that wraps every net.Conn with deadlineConn, which calls SetReadDeadline before each Read. Pool callbacks like AfterConnect or BeforeAcquire only fire once, so they can only set a single absolute deadline that expires even if the connection is healthy. Wrapping net.Conn lets us reset the deadline on every Read call.
The read timeout is set to 60 seconds, which is more than enough for read-set validation and commit operations. This can be made configurable if needed.
On macOS, Docker Desktop runs a userspace TCP proxy inside a Linux VM. When a container dies the proxy does not immediately close forwarded connections, so reads hang indefinitely. The deadlineConn wrapper ensures stuck reads fail within the timeout, allowing the pool to replace them. On Linux, reads already fail immediately via TCP RST when a node dies, so the wrapper is harmless.
func DataSourceName ¶
func DataSourceName(d DataSourceNameParams) (string, error)
DataSourceName returns the data source name of the database.
func FmtNsID ¶
FmtNsID replaces the namespace placeholder with the namespace ID in an SQL template string.
func GetTablePreSplitTablets ¶
GetTablePreSplitTablets determines the number of tablets to use for table pre-splitting. Returns 0 for PostgreSQL or when TablePreSplitTablets is not configured. Returns the configured value for YugabyteDB.
func IsYugabyteDB ¶
IsYugabyteDB queries the database version string to determine whether the backend is YugabyteDB. YugabyteDB's version() output contains "-YB-" (e.g., "PostgreSQL 11.2-YB-2.20.1.0 ..."), which distinguishes it from standard PostgreSQL.
func MakeNsTablesQuery ¶
MakeNsTablesQuery returns the query to create the table and functions for a namespace.
func SetupSystemTablesAndNamespaces ¶
SetupSystemTablesAndNamespaces creates the required system tables and namespaces in the database. This function should be called before operating against the database. It is safe to run multiple times.
Types ¶
type Config ¶
type Config struct {
Endpoints []*connection.Endpoint `mapstructure:"endpoints" default:"localhost:5433"`
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
Database string `mapstructure:"database" default:"yugabyte"`
MaxConnections int32 `mapstructure:"max-connections" default:"20" validate:"gt=0"`
MinConnections int32 `mapstructure:"min-connections" default:"1" validate:"gte=0"`
LoadBalance bool `mapstructure:"load-balance"`
Retry *retry.Profile `mapstructure:"retry" default:"max-elapsed-time=10m"`
TLS TLSConfig `mapstructure:"tls"`
TablePreSplitTablets int `mapstructure:"table-pre-split-tablets"`
}
Config is the configuration for database initialization and connection. This configuration is shared across multiple services (VC, Query) and the init-db CLI command.
func (*Config) DataSourceName ¶
DataSourceName returns the data source name of the database.
func (*Config) EndpointsString ¶
EndpointsString returns the address:port as a string with comma as a separator between endpoints.