Advanced replication in Firebird 4 and beyond Dmitry Yemanov [email protected] Firebird Project www.firebirdsql.org
Jun 16, 2020
Advanced replicationAdvanced replicationin Firebird 4 and beyondin Firebird 4 and beyond
Dmitry [email protected]
Firebird Projectwww.firebirdsql.org
2
2FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Firebird Conference 2019Berlin, 17-19 October
3
3FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Replication cost
Data load, seconds (less = better)0
100
200
300
400
500
600
700
FW=OFFFW=ONFW=ON + SYNCFW=ON + ASYNCFW=OFF + SYNCFW=OFF + ASYNC
4
4FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Replication cost
Data load, seconds (less = better)0
100
200
300
400
500
600
700
800
900
1000
FW=OFFFW=ONFW=ON + SYNCFW=ON + ASYNCFW=OFF + SYNCFW=OFF + ASYNC
5
5FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Replication cost
Data load, seconds (less = better)0
100
200
300
400
500
600
700
800
900
1000
FW=OFFFW=ONFW=ON + SYNCFW=ON + ASYNCFW=OFF + SYNCFW=OFF + ASYNC
6
6FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Replication cost
Data load, seconds (less = better)0
100
200
300
400
500
600
700
800
900
1000
FW=OFFFW=ONFW=ON + SYNCFW=ON + ASYNCFW=OFF + SYNCFW=OFF + ASYNC
7
7FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Replication cost
OLTP, transactions/minute (more = better)0
5000
10000
15000
20000
25000
FW=OFFFW=ONFW=ON + SYNCFW=ON + ASYNCFW=OFF + SYNCFW=OFF + ASYNC
8
8FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Replication cost
OLTP, transactions/minute (more = better)0
5000
10000
15000
20000
25000
FW=OFFFW=ONFW=ON + SYNCFW=ON + ASYNCFW=OFF + SYNCFW=OFF + ASYNC
9
9FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Replication cost
OLTP, transactions/minute (more = better)0
5000
10000
15000
20000
25000
FW=OFFFW=ONFW=ON + SYNCFW=ON + ASYNCFW=OFF + SYNCFW=OFF + ASYNC
10
10FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Speeding up performance
Old trick with shadows FW = ON on the shadow side is enough
11
11FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Speeding up performance
Old trick with shadows FW = ON on the shadow side is enough
The same trick with replication FW = OFF on the primary side FW = ON on the replica side Set up sync / async replication Double your disk space ;-)
12
12FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Read-only replica
Applications Just a failover (very limited RO activity) Long-running reports Backup
13
13FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Read-write replica
Applications Reports that modify data
(emulated temporary tables) Merge changes from the other database
(head office → branch or vice versa)
14
14FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Read-write replica
Applications Reports that modify data
(emulated temporary tables) Merge changes from the other database
(head office → branch or vice versa)
How to avoid conflicts Exclude «temporary» tables from replication set Make changes non-intersecting Ensure global ID scheme
15
15FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Mixed sync / async replication
Multi-level recovery guarantee Sync replica(s) are for immediate recovery Async journal as a backup recovery option Minimized downtime
16
16FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Mixed sync / async replication
Multi-level recovery guarantee Sync replica(s) are for immediate recovery Async journal as a backup recovery option Minimized downtime
Other applications Use journal for PITR Use journal for audit
17
17FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Semi-sync replication
Concept Relax synchronization requirements
and thus improve performance Still be able to recover
18
18FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Semi-sync replication
Concept Relax synchronization requirements
and thus improve performance Still be able to recover
Possible options Changes are received by the replica host Changes are received by the replica host and applied Changes are received by the replica host and applied
and committed Quorum threshold
19
19FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Multi-source replication
Concept Replica may receive changes from multiple primary databases Database UUID to separate sources Limit the replica to deal with particular sources
Application Merge branches to the head office
20
20FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Multi-source replication
Usage Set up multiple source directories Set up source filters for the replica Ensure non-intersecting operations or unique ID scheme
21
21FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Cascaded replication
Concept Replica can also act as primary Applied changes are replicated further May also work for read-write replica Can be set up with a single entry in replication.conf
22
22FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Cascaded replication
Concept Replica can also act as primary Applied changes are replicated further May also work for read-write replica Can be set up with a single entry in replication.conf
Tricks What about loops? A → B → C → A A → B → A
23
23FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Bi-directional replication
Concept Not the same as «looped» cascaded replication Use read-write mode for replica Global record identification
(UUID key, range-based key, composite key) Rules for conflict resolution
24
24FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Bi-directional replication
Concept Not the same as «looped» cascaded replication Use read-write mode for replica Global record identification
(UUID key, range-based key, composite key) Rules for conflict resolution
Problems What to do with sequences Delayed conflicts and manual resolutions
25
25FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Simplifying migration
Upgrading Use production FB / database as primary Set up async replication Backup and restore on new FB version Set up restored database as replica Wait until it catches up the primary Test the replica Once ready, promote replica to primary
26
26FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Simplifying migration
Downgrading Use upgraded FB / database as primary,
older FB / database as replica Set up async OR sync replication Switch to the older FB / database
if something goes seriously wrong
27
27FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Creating custom replicators
Concept Public CDC interface Plugin-based architecture Built-in replication is just a built-in plugin Public API to apply replication packets
28
28FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Creating custom replicators
Concept Public CDC interface Plugin-based architecture Built-in replication is just a built-in plugin Public API to apply replication packets
Applications Alternative journalling or transport options Publishing data to other products (e.g. OLAP) Row-level audit
29
29FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN
Questions?Questions?