Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond...

29
Advanced replication in Firebird 4 and beyond Dmitry Yemanov [email protected] Firebird Project www.firebirdsql.org

Transcript of Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond...

Page 1: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

Advanced replicationAdvanced replicationin Firebird 4 and beyondin Firebird 4 and beyond

Dmitry [email protected]

Firebird Projectwww.firebirdsql.org

Page 2: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

2

2FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN

Firebird Conference 2019Berlin, 17-19 October

Page 3: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 4: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 5: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 6: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 7: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 8: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 9: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 10: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

10

10FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN

Speeding up performance

Old trick with shadows FW = ON on the shadow side is enough

Page 11: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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 ;-)

Page 12: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

12

12FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN

Read-only replica

Applications Just a failover (very limited RO activity) Long-running reports Backup

Page 13: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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)

Page 14: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 15: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 16: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 17: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

17

17FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN

Semi-sync replication

Concept Relax synchronization requirements

and thus improve performance Still be able to recover

Page 18: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 19: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 20: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 21: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 22: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 23: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 24: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 25: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 26: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 27: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 28: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

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

Page 29: Advanced replication in Firebird 4 and beyond · Advanced replication in Firebird 4 and beyond Dmitry Yemanov dimitr@firebirdsql.org Firebird Project . 2 FIREBIRD INTERNATIONAL CONFERENCE

29

29FIREBIRD INTERNATIONAL CONFERENCE '2019 - BERLIN

Questions?Questions?