Skip to content

Asynchronous, HA (master-master) PostgreSQL driver on top of libpq.

License

Notifications You must be signed in to change notification settings

ArtemGr/pg_async.rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pg_async.rs

Asynchronous, HA (master-master) PostgreSQL driver on top of libpq.

crate docs patreon

Vision

  • Designed to work with a master-master replicated database, such as BDR (but standalone databases are supported too).
  • Uses libpq, leveraging it's asynchronous support.
  • Maintains an asynchronous connection to every node of the replicated cluster.
  • Pings the nodes (with SELECT 1) to see who's closer/faster.
  • Every operation is a separate transaction.
  • If a node fails, the operation is transparently retried on another node.
  • Operations are exposed as futures.
  • futures are backed by a thread or two and can be used without a tokio reactor (because KISS).
  • Fast mode: send the operation to every node and return the first answer.
  • Pin mode: send the operation to one of the nodes only (useful to avoid some of the master-master conflicts).
  • There is a JSON helper converting table rows to serde_json objects.
  • If the operation wasn't pipelined already, dropping a Future allows the driver to cancel it.
  • Database-level timeouts can be used to terminate slow operations early.

Notes

The combination of libpq and OpenSSL doesn't work very well during PostgreSQL server restarts. I've seen libpq SEGV-crash reliably when the OpenSSL layer is enabled. For the driver to properly work around PostgreSQL server unavailability and restarts I recommend adding the "sslmode=disable" disabler to the connection strings.

Releases

No releases published

Packages

No packages published

Languages