500 likes | 725 Views
Chat with the Lab Replication in the IBM Informix Dynamic Server. Agenda. What is Enterprise Replication How is Enterprise Replication different from HDR Internal Overview of HDR/ER Recent Improvements in Enterprise Replication (10.x) Troubleshooting Enterprise Replication.
E N D
Chat with the LabReplication in the IBM Informix Dynamic Server
Agenda • What is Enterprise Replication • How is Enterprise Replication different from HDR • Internal Overview of HDR/ER • Recent Improvements in Enterprise Replication (10.x) • Troubleshooting Enterprise Replication
IDS Enterprise Replication (ER) • Log based, Transaction oriented replication • Asynchronous, Homogeneous (IDS 7.22+ only) • Primary/Target + Update anywhere • Consolidation, Dissemination, Workload partitioning • Tightly coupled with the server • Web and command line administration
ER History • Initial Release: 7.22 in 12/1996 • Version I - 7.22 - 7.30 releases • Version II (7.31 & 9.2x) • Queue and NIF redesign, Hierarchical Routing • Version III (9.3) • Extensibility, Increased parallelism, Smart blob queuing, In-place alter to add/drop CRCOLS, Serial Col Primary Key Support, … • Version IV (9.4) • ER/HDR support, Large transaction support, Complex Type support, Performance enhancements, Network Encryption • Version V (10.x) • Templates, Alter Support, Resync Support, Mastered Replicates, Shadow Replicates
How HDR and ER differ? Provides single primary and single secondary Allows configurable source(s)/target(s) Primary and secondary must run thesame executables and have similardisk layout Source/target do not have to be thesame Secondary restricted to report processing Allows full usage of both source/target Simple to set up and administer Setup and administration more complex Primary and secondary are mirror images Source and target can be totally different Does not support blobspace blobs Supports blobspace blobs Replication can be synchronous Replication is asynchronous Primary purpose is for highavailability Primary purpose is for data distribution HDR ER
HDR – How it works LogRecvr AcctTable AcctTable Logical Log Buffer Recovery Buffer drsecapply Reception Buffer HDR Buffer Logical Logs Written to Disk Logical Logs Written to Disk DRINTERVAL Sets maximum time lag in seconds for HDR buffer transmission Set to ‘-1’ for synchronous. Primary Secondary
ER – how it works Global Catalog syscdr Database Regroups transaction and performs evaluation Database Target apply threads Grouper Data Synch Snoopy AckQueue Logical Log NIF Send Queue ReceiveQueue Spool Transmits Txn to targets Source Target Transmits Txn to targets
ER Setup Issues • Row is identified by its primary key • SQLHOSTS issues • LogSize issue • Conflict Resolution issues • Topology • Scope issues • Stable Queue
SQL host changes for ER Group Name Label Type Server Service Options CDRID – any number between1 and 32768 Must be unique withinreplication domain. srv1tcp1 ontlitcp dallas port1 srv1tcp2 ontlitcp dallas port2 srv1shm onipcshm dallas srv1shm1 srv2tcp1 ontlitcp houston cdr2 srv2shm onipcshm houston srv2shm srv1_g group - - i=1 srv1tcp1 ontlitcp dallas port1 g=srv1_g srv1shm onipcshm dallas srv1shm1 srv2_g group - - i=2 srv2tcp1 ontlitcp houston cdr2 g=srv2_g srv2shm onipcshm houston srv2shm g=srv2_g NO!!!ER groups should only containTCP connections.
SQL host changes for ER with HDR (9.4) Configure HDR pair as members Of the same ER group Label Type Server Service Options srv1tcp1 ontlitcp dallas port1 srv1tcp2 ontlitcp dallas port2 srv1shm onipcshm dallas srv1shm1 srv2tcp1 ontlitcp houston cdr2 srv2shm onipcshm houston srv2shm srv1_g group - - i=1 hdrPrim ontlitcp dallas port1 g=srv1_g dhrSec ontlitcp ftworth port1 g=srv1_g srv1shm onipcshm dallas srv1shm1 srv2_g group - - i=2 srv2tcp1 ontlitcp houston cdr2 g=srv2_g
Snoopy/Replay/DDRBLOCK Log Number 1 2 3 4 5 6 7 8 Unique id 1214 1215 1216 1217 1210 1211 1212 1213 Replay position Snoopy position Current position Log needs position Replay position DDR BLOCK zone Advancing Log Positions Snoopy position Log needs position Current position
Work Done to Avoid DDRBLOCK state • Spooling Threads • Starts spooling much earlier • CDR_MAX_DYNAMIC_LOGS (9.4) • Allows ER to dynamically add a log rather than enter a DRBLOCK state • -1 Add logs infinitely • 0 Turn off • >0 Number of logs ER is allowed to dynamically create
What is Conflict Resolution? A B Very Fast Network Sally enters a new order on ‘A’ Fast Fingered Fredcan update an orderfaster than can bedelivered to ‘C’ on the ‘Buggy Network’ Slow Network C What to do when the originalorder finally arrives from A after Fred’s update has been applied?Who Wins???
Conflict Resolution • Method to determine if the current version or a just received version of the row should ‘win’ • Ignore • Row must be applied as is • Timestamp • Most recent update wins • Upsert processing • Stored Procedure • User written stored procedure is invoked • Always Apply (10.0) • Like Ignore but performs upserts • Requires CRCOLS (shadow columns) • CDRTIME, CDRSERVER • Create table ... With CRCOLS
What if Fred Deleted the order??? A B Very Fast Network Fast Fingered Fredcan also delete an orderfaster than can bedelivered to ‘C’ on the ‘Buggy Network’ Slow Network C OppsWhat to do when the originalorder finally arrives from A?? Deleted Row Tables
Routing - All Roots B A C
Routing - Hierarchial A (root) B (non-root) C (non-root) B2 (leaf) C1 (leaf) B1 (leaf) C2 (leaf)
Routing - Hub/Spoke B (leaf) E (leaf) A (root) D (leaf) C (leaf)
Routing vrs Replication • The Server Definitions define the topology and routing of the ER domain • The Replicate Definitions define which tables are replicated and where the targets are located • Any table can be replicated to any other server within the replication domain
Things to think about Scope • Transaction scope is really “All or Nothing” • If one row fails within the transaction and you are in transaction scope, then all of the rows fail. • The transaction is always applied as a transaction. • The transaction is NOT rolled-back on the source • Triggers are normally not fired on the target • Firing triggers can be a way to replicate a procedure rather than replicate a table change • Timed Based replication is not a good thing
Smart Blob Queue Setup (9.3+) • Stable storage moved table space blobs to smart blob space • Defined by CDR_QDATA_SBSPACE in onconfig • Can be logged or non-logged • 9.4 can have multiple entries forCDR_QDATA_SBSPACE • Can have both logged and unlogged smartblob queue • Small transactions use logged smartblob space • Large transactions use unlogged smartblob space • If using with HDR, then only logged smartblob space used
ER Encryption Configuration • ENCRYPT_CDR • 0 Encryption Turned Off • 1 Encrypt if peer can decrypt • 2 Encryption must be used • ENCRYPT_CIPHERS • List of to use or to reject • Default is all without using ECB mode • ENCRYPT_SWITCH <CipherTime>,<KeyTime> • Time between renegotiations
New Features in 10.x • Mastered Replicates • Shadow Replicates • Template Support • Allows multi-table deployment with minimal adminstration • Table Alter Support • Support add/modify/drop of column, attach/detach of fragment • Sync Support • Supports multi-node – update anywhere syncronization • Infrastructure • Mastered Replicates • Shadow Replicates • Other • Always Apply, Ignore Deletes
Mastered Replicate • A new replicate type in IDS 10.00 • Traditional replicate are called classic replicate now • A master replicate is a replicate that stores dictionary information in CDR database • Guarantees data integrity • check column type • Can be used to verify column name (--name=y) • Enables table generation on participants • Also allow user to perform alter operations on replicated tables • “Select *” is converted into “select col1, col2, col3…”
Master Replicate (example….) cdr define repl SharkRepl \–S row –C always –M Miami_g –name=y \ “DB@Miami_g:userid.Sharks” “select * from Sharks” \“DB@Charleston_g:userid.Sharks” “select * from Sharks”
Shadow Replicate A B C
Shadow Replicate • Functions as a ‘special case’ replicate • Used in alter to seamlessly swap one replicate definition for another (remastering) • Used in Sync to provide targeted replication cdr define replicate shadowReplicate -M masterNode –m primaryReplicate –S row –C always …
Re-mastering • Seamlessly swaps one replicate definition for another • Uses shadow replicates internally • cdr remaster –M Miami_g SharkRepl “select * from Sharks” • A replicate should be re-master after a replicated table is altered on all nodes
Template in Enterprise Replication • Ease of ER administration and setup • ER Template feature is an extension to the replication set concept • Mass deployment with multiple tables • Easy to define and deploy replicate • Can create tables and deploy on new node • Can provide initial data Sync • Easy command line interface • Eliminates many schema related errors
Enterprise Replication Template • The ER Template feature has two main commands and two other supporting commands. • Define template • Realize template • List template • Delete templete
Define Template • Define a template on participants (tables) • Creates the empty master replicates internally and also a replset on the specified tables • Master replicate is based on tables definition taken from master node cdr define template SharkReplTemp –S row –C timestamp –M NewYork_g –d DB --all
Realize Template • Realize operation Instantiate a template on one or many server • Table on each server matches master definition • Additional columns at any participants are ignored • Realize operation can create tables • Tables can be synced at realize time cdr realize template SharkReplTemp Miami_g Charleston_g NewYork_g • Replication is started by default
Things to Consider With Templates • A template needs to be defined from the non-leaf server just as a replicate set and replicates • Always we need to have direct connectivity between –c server and the Master node • Always we need to specify a group name i.e. g_<server name> as the master node. • Initial Sync using a template requires that all servers should be always directly connected during sync.
Alter table/fragment support on ER table • This feature provides alter support for tables being replicated (10.00) • add/drop default values • add/drop SQL checks • add/drop fragments • attach/detach fragments • add/drop columns • recluster indexes • alter non replicated columns • modify replicated column
Alter on Replication Table • Table defined using master replicate can be altered • During alter • ER is notified of alter of a replicated table • ER spools the queue to avoid having to snoop any old log records • ER blocks any ER activity on the table (CDR Alter Mode) • Normal alter logic performed • ER is notified that the alter is complete and rebuilds dictionary information • Table is verified to ensure that replication can resume • If replication column is altered, it is verified • Alter mode can be set/unset manually through CDR CLI or implicitly through SQL alter statement itself. cdr alter [-c server] –o|-f <tables>
Alter table/fragment Restrictions • ER must be in active state for altering a replicated table except in scenarios where adding/dropping check constraints and default values. • Alter operations are supported only on tables defined with mastered replicates. • Rename table operation is not supported • Rename column operation is not supported • Drop table operation is not supported
Resync feature in 10.00 • To bring a newly participating table up-to-date with the ongoing replication. • Repair a replicated table if replication was stopped or failed for some reason.
Using sync option • Sync tables when starting replicate cdr start replicate repl1 –S NewYork_g • Sync tables when template is realized cdr realize template –c Dallas_g SharkReplTemp –S NewYork_g “DB@Charleston_g” “DB@NewYork_g”
Repair using sync option • By defining and running a ‘repair job’ • Repair is defined on active replicate • Repair entire table • Repair part of a table
Repairing a replicate • Repair a replicate $ cdr define repair <jobname> -r <replicate name> -b <blocksize> -e <extra target row option> -S <source server name> < target server name> extratargetrow option can be one of : delete, keep, merge (default is delete)
Repairing a set • Repair a replicate set $ cdr define repair [ -c <connect server > ] <jobname> -R <replicate set name> -b <blocksize> -e <extra target row option> -S <source server name> < target server name> CDR determines the order of replicate jobs internally based on the referential constraints between the tables in the replset on the target server. NOTE: If the source or leaf of a repair job is a leaf server then ‘connect server’ has to be a non-leaf server
Running a Repair job • Starting a Repair job $ cdr start repair [ -c <connect server> ] jobname The ‘connect server’ has to be the source server of the job. • Stopping a Repair job $ cdr stop repair [ -c <connect server> ] jobname This will stop the scanning of source table for the repair job. But forwarding of data to the target server will continue. ‘start repair’ command on the same job will resume scanning.
How repair job work … • Generates stored procedures and triggers to: • Scan the source data • Handle the extra target row options – including cascade deletes if the option is delete • Cleanup the rows in the internal tables and populate the violations table for errors. • Do dummy updates on the source data to replicate to the target.
ATS & RIS Repair Command syntax: $ cdr repair ats <ats_filename> [-C] $ cdr repair ris <ris_filename> [-C] -C option does only check for the existence of failed rows on target and source.
ATS & RIS Repair How It Works: • If the failed operation is ‘delete’ then do a ‘local’ delete of those row(s) on the target server. • If the failed operation is ‘insert’ or ‘update’ • If the row(s) are found on the ‘source server’ of the failed transaction then do a ‘dummy update’ on those row(s) • If the row(s) are NOT found then do a ‘local’ delete on the target server.