Module eysql_conn

The default driver: epgsql, with the sharp edges filed off.

Behaviours: eysql_driver.

Description

The default driver: epgsql, with the sharp edges filed off.

epgsql:connect/1 links the socket process to the caller before connecting, and that process exits abnormally when the connect fails, so a failed connect can kill the caller. open/3 starts the socket process unlinked and links it only once the connection is up.

An epgsql call on a connection whose process has died exits the caller. squery/2 and equery/3 turn that into {error, {connection_lost, Reason}}.

epgsql waits for the server for as long as it takes, and a server that has died silently or hangs never answers. On a connection checked out of a pool with a socket_timeout, in the process that checked it out, squery/2 and equery/3 wait that long at most: the pool then kills the connection, and they return {error, {connection_lost, socket_timeout}} (see eysql_pool:watch/1). So code inside eysql:with_connection/3 or eysql:transaction/3 gets bounded queries by calling them in place of epgsql:squery/2 and epgsql:equery/3. Anywhere else they behave as those do, with no bound.

epgsql has no call that tells whether a connection is inside a transaction. transaction_status/1 reads it inside the connection process.

Data Types

transaction_status()

transaction_status() = idle | in_transaction | failed | unknown

Function Index

close/1
committed/1
discover/1Read yb_servers().
equery/3epgsql:equery/3, as squery/2 is epgsql:squery/2.
is_primary/1
open/3Connect to one host.
squery/2epgsql:squery/2, returning an error rather than exiting when the connection has died, and bounded by the pool's socket_timeout when this process checked Conn out of a pool.
transaction_status/1Whether the server has a transaction open on the connection, from the status byte of its last ReadyForQuery: idle (I), in_transaction (T) or failed (E, a statement failed and only ROLLBACK is accepted).

Function Details

close/1

close(Conn::pid()) -> ok

committed/1

committed(Conn::pid()) -> boolean()

discover/1

discover(Conn::pid()) -> {ok, [eysql_topology:server()]} | {error, term()}

Read yb_servers(). On PostgreSQL this fails with SQLSTATE 42883 (undefined function), which the cluster takes to mean "not YugabyteDB". public_ip is empty for a server that has none.

equery/3

equery(Conn::pid(), Sql::iodata(), Params::[term()]) -> term()

epgsql:equery/3, as squery/2 is epgsql:squery/2.

is_primary/1

is_primary(Conn::pid()) -> {ok, boolean()} | {error, term()}

open/3

open(Host::binary(), Port::inet:port_number(), Settings::map()) -> {ok, pid()} | {error, term()}

Connect to one host. The connection is linked to the caller, as with epgsql:connect/1.

squery/2

squery(Conn::pid(), Sql::iodata()) -> term()

epgsql:squery/2, returning an error rather than exiting when the connection has died, and bounded by the pool's socket_timeout when this process checked Conn out of a pool.

transaction_status/1

transaction_status(Conn::pid()) -> transaction_status()

Whether the server has a transaction open on the connection, from the status byte of its last ReadyForQuery: idle (I), in_transaction (T) or failed (E, a statement failed and only ROLLBACK is accepted). No round trip to the server.

unknown when the byte does not tell: the process is gone or took longer than a second to answer, a command is still running, epgsql waits for a sync after an extended-query error, the connection is in COPY mode, or the state is not one this function knows.

After epgsql:parse, epgsql:bind or epgsql:execute with no epgsql:sync/1 after them, the byte is stale: the server sends ReadyForQuery only on sync.

The connection process reads the byte itself and sends back only the answer, so the call does not copy the connection's state.


Generated by EDoc