3. Replication in ManageIQ
Multiple databases can be used for far away environments
Database replication allows for easy reporting and visibility
Database 1 Database 2
Global Database
Replication!
5. rubyrep
Ruby + ActiveRecord
Triggers = Developer headaches
SQL
Configuration is … hardelsif commands.include? command
status = commands[command][:command].run(args.slice(1, 1_000_000))
6. rubyrep in ManageIQ
We use our own fork
https://github.com/ManageIQ/rubyrep
Mainly support for new versions of ActiveRecord
7. rubyrep in ManageIQ
PR to add support for Rails 4.2
March 27, 2015
“Yup. It's basically dead. Our changes are also SOOO crazy
different, that this is like a Frankenstein project now. I wonder
if we should just write something different from scratch given
our experience...or perhaps we should rethink replication
altogether and come up with a plan.”
-
@Fryguy
8. rubyrep in ManageIQ
Worker process
Database Synchronization role
Worker will run on the server with the role
Passive global database
12. pglogical in ManageIQ
AR connection adapter extension
Exposes a ruby method per pglogical stored procedure
Configure “subscriptions” to remote regions through global
region UI
Exclude table configuration unchanged
“Advanced Settings” tab in remote region UI
14. Performance testing
How long does it take to replicate a “backlog” of data?
Vary amount of data and artificial network latency
Measure time until “backlog” is zero
rubyrep - number of rows in rr_pending_changes table
pglogical - transaction log location compared to flush location
SELECT pg_xlog_location_diff(pg_current_xlog_location(), flush_location) AS lag_bytes
FROM pg_stat_replication;
Replication as a feature, not for failover - that’s Brett’s talk next
Better local performance (using the product normally) by keeping the database close to the provider / other infrastructure it is managing
No one wants multiple reports because of performance concerns
Replicate the data to the “global” database and report there
The ruby rep website is even older - 2009
Typically just doing more than it probably needs to.
Used active record so it could support more than just postgresql
Renamed tables cause issues with triggers
We don’t have a standard interface to adding / removing them when we change things
Not everyone that is making a database change is also thinking about replication
Talk about even streams table -
Table was renamed
Had to remember that replication was a thing,
Had to rename all the existing rows in the pending changes and the state table
Forgot about the triggers
The old trigger stayed around and we got a change entry for both table names every time something happened
SQL as opposed to …
Was trying to track down how the configuration worked
Our config file was a two line ruby script that was passed as an argument to a rubyrep gem method (run)
That config file called out to a class which set config options from within the gem
Found the PR to our fork for adding support for Rails 4.2 while looking back in the repo
Found a comment
We also added support for rails 5
Don’t want worker running on a server that has a bad connection to both databases.
Extra worker takes up memory on the appliance
We have to monitor when replication is running (heartbeat)
Additional process outside of our worker actually runs the replication
Upside - passive global
Replication is just another database connection writing data
9.7 estimate from a contributor on the project I spoke with
Still not looking likely, but the extension is fine
Starts and stops with the database once it is configured
No worrying about roles
Will always run on the database server
Stored procs are a lot nicer to deal with than a separate process or changing that config
Logical decoding is a way to capture more detailed data from the WAL logs
Needs an output plugin to present the data
Replication slots track when changes have been consumed and retain WAL logs accordingly
Before replication slots users had to come up with a WAL archiving strategy to make sure the
logs were still there when they needed to be replicated.
The user now configures the credentials in one place (global)
Latency achieved with `tc` command to inject a delay before network traffic is queued
(standard deviation)
Triggers have some overhead on insert