美文网首页
SymmetricDS 实时数据库同步工具总结

SymmetricDS 实时数据库同步工具总结

作者: ZNK | 来源:发表于2016-03-29 18:47 被阅读0次

SymmetricDS 总结

[TOC]

基本知识

configure Sync

node

nodes defined in sym_node

trigger

router

trigger router

conflict

相关的classes

symmetrict-io: org.jumpmind.io.data.writer
AbstractDatabaseWriter.java
AbstractDataBaseWrtierConflictResolver.java
AbstractDatabaseWriter.java
DefaultDatabaseWriter.java

transform

常用配置

配置client

创建node_group

创建node_group_link

常见问题

1. 如果需要同步的Table的结构更改, 需要重新启动 SymmServer

2. 如果报JDBC Driver问题, 要保证停掉了所有的Server, 查看是否有Server的进程没有被停掉.

3. fallback using PK_data

问题来源于ee_pawnitems表, 在ddt里的pk是entityid, 而在platform里的pk是 billid + itemnum.
如果platform里也定义成 EntityID, 则会导致重复数据的问题

在insert时出现失败, 就会触发conflict 处理

  • conflict detection:
    如果conflict detection 选择 USE_PK_DATA
    如果a row already exists during an insert then conflict has been detected.

  • resolve type
    Fallback: if the source operation was an insert, then an update will be attempted.

 Preparing dml: insert into `pawn_plat_all`.`ee_pawnitems` (`ENTITYID`, `BILLID`, `ITEMNUM`, `CATEGORYID`, `ITEMNAME`, `SPECIFICATION`, `QUANTITY`, `EVALUATEPRICE`, `PAWNMONEY`, `CONTINUEID`, `note`, `corporationId`, `sumCharge`, `realPay`, `monthRate`, `interestRate`, `businessStatus`, `linkBill`, `sumInterest`, `stockStatus`, `fineness`, `weight`, `unitPrice`) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
2016-01-21 13:46:40,096 DEBUG [corp-000] [DefaultDatabaseWriter] [http-bio-8580-exec-9] Submitting data [8a22527852364c4f0152623201fd15a5, 00067866201508190001, 1, 4092, 小汽车, 粤AS281W, 1.00, 630000.00, 630000.00, 00067866201511170001, , 67866, 6300, 623700, 0.01, 0, 2, null, null, 0, 0, 0.000, 0.00] with types [12, 12, 4, 4, 12, 12, 3, 3, 3, 12, 12, -5, 3, 3, 3, 3, 4, 12, 3, 4, 4, 3, 3]

// conflict detected
2016-01-21 13:46:40,097 DEBUG [corp-000] [AbstractDatabaseWriterConflictResolver] [http-bio-8580-exec-9] Conflict detected: conflict_ee_pawnitems02 in batch 531124 at line 193 for table pawn_plat_all.ee_pawnitems
2016-01-21 13:46:40,097 DEBUG [corp-000] [AbstractDatabaseWriterConflictResolver] [http-bio-8580-exec-9] Row data: "8a22527852364c4f0152623201fd15a5","00067866201508190001","1","4092","小汽车
","粤AS281W","1.00","630000.00","630000.00","00067866201511170001","","67866","6300","623700","0.01","0","2",,,"0","0","0.000","0.00"

// resolve conflict
2016-01-21 13:46:40,099 DEBUG [corp-000] [DefaultDatabaseWriter] [http-bio-8580-exec-9] Preparing dml: update `pawn_plat_all`.`ee_pawnitems` set `BILLID` = ?, `ITEMNUM` = ?, `CATEGORYID` = ?, `ITEMNAME` = ?, `SPECIFICATION` = ?, `QUANTITY` = ?, `EVALUATEPRICE` = ?, `PAWNMONEY` = ?, `CONTINUEID` = ?, `note` = ?, `corporationId` = ?, `sumCharge` = ?, `realPay` = ?, `monthRate` = ?, `interestRate` = ?, `businessStatus` = ?, `linkBill` = ?, `sumInterest` = ?, `stockStatus` = ?, `fineness` = ?, `weight` = ?, `unitPrice` = ? where `ENTITYID` = ?
2016-01-21 13:46:40,099 DEBUG [corp-000] [DefaultDatabaseWriter] [http-bio-8580-exec-9] Submitting data [00067866201508190001, 1, 4092, 小汽车, 粤AS281W, 1.00, 630000.00, 630000.00, 00067866201511170001, , 67866, 6300, 623700, 0.01, 0, 2, null, null, 0, 0, 0.000, 0.00, 8a22527852364c4f0152623201fd15a5] with types [12, 4, 4, 12, 12, 3, 3, 3, 12, 12, -5, 3, 3, 3, 3, 4, 12, 3, 4, 4, 3, 3, 12]

2016-01-21 13:46:40,102 INFO [corp-000] [DefaultDatabaseWriter] [http-bio-8580-exec-9] Failed to process a insert event in batch 531124.
Failed row data was: "8a22527852364c4f0152623201fd15a5","00067866201508190001","1","4092","小汽车","粤AS281W","1.00","630000.00","630000.00","00067866201511170001","","67866","6300","623700","0.01","0","2",,,"0","0","0.000","0.00"

4. 同步数据传递时遇到的问题

目标:
同步数据从SWB数据库到plat数据库, 再同步到ddt数据库:

swb client => plat_all => ddt db

  • 发现的问题: 在从SWB 同步数据到plat_all后, 并不能激发同步数据到ddt.
  • 如何处理这个问题, 需要定时触发reload data from plat_all to ddt_db

在crontab 中加入定期激发重新load数据的任务

###### reload area table data from plat_all to ddt_db dairly ############
05 23  * * * /usr/bin/mysql -h rdsnfiaaqnfiaaq.mysql.rds.aliyuncs.com -u pawn_client_user -pSoudang_518 --database pawn_plat_all < /opt/sql_scripts/reload_area.sql
-- reload_area.sql 内容:
INSERT INTO sym_data (table_name, event_type, row_data, pk_data, old_data, trigger_hist_id, channel_id, transaction_id, source_node_id, external_data, create_time)
SELECT  t.source_table_name ,        'R',     '1=1',   NULL,   NULL,  h.trigger_hist_id , t.channel_id , '1',    NULL,    NULL,    CURRENT_TIMESTAMP
  FROM sym_trigger t
 INNER JOIN sym_trigger_router tr  ON  t.trigger_id = tr .trigger_id
 INNER JOIN sym_trigger_hist h   ON   h.trigger_hist_id = (
  SELECT
       MAX(trigger_hist_id)
   FROM
       sym_trigger_hist
   WHERE
       trigger_id= t .trigger_id
 )
WHERE
  channel_id = 'plat_2_ddt' AND  tr.router_id  LIKE  'corp_2_client02_ddt'  AND (t.source_table_name = 'area')
ORDER BY tr.initial_load_order ASC;

5. 如何重新load 数据

如果数据改变没有被捕获, 可能有时需要重新发送或重新同步数据. 这种情况

执行下列SQL 在数据来源库(例如 DDTService DB).

需要替换channel_id, router_id 和 数据来源表名称

INSERT INTO sym_data (table_name, event_type, row_data, pk_data, old_data, trigger_hist_id, channel_id, transaction_id, source_node_id, external_data, create_time)
SELECT  t.source_table_name ,        'R',     '1=1',   NULL,   NULL,  h.trigger_hist_id , t.channel_id , '1',    NULL,    NULL,    CURRENT_TIMESTAMP
  FROM sym_trigger t
  INNER JOIN sym_trigger_router tr  ON  t.trigger_id = tr .trigger_id
  INNER JOIN sym_trigger_hist h   ON   h.trigger_hist_id = (
    SELECT
          MAX(trigger_hist_id)
    FROM
         sym_trigger_hist
    WHERE
         trigger_id= t .trigger_id
   )
WHERE
   channel_id = 'business_ddt' AND  tr.router_id  LIKE  'client02_2_corp_ddt'  AND (t.source_table_name = 'mb_paymentinfo')
ORDER BY tr.initial_load_order ASC;

-- 查找 data_id
select data_id, event_type, table_name, channel_id from sym_data where event_type = 'R' order by create_time desc limit 1;

-- 根据data_id查找执行状态
select o.batch_id, o.status, o.data_event_count, d.data_id, d.table_name, d.event_type from sym_data d 
join sym_data_event de 
on d.data_id = de.data_id  
join sym_outgoing_batch o 
on de.batch_id = o.batch_id 
where d.data_id = 16197111;

相关文章

  • SymmetricDS 实时数据库同步工具总结

    SymmetricDS 总结 [TOC] 基本知识 configure Sync node nodes defin...

  • Linux sersync day35

    什么是实时同步为什么要实时同步实时同步的原理实时同步的场景实时同步工具选择实时同步案例演示 一、什么是实时同步 实...

  • 实现实时同步备份总结

    实现实时同步备份总结 \ 一. 实时同步备份原理1.inotify实时监控2.rsync实时传输3.sersy...

  • day 35综合架构实时同步

    课程介绍部分 (补充扩展) 课程总结 一:网站实时同步服务 二.数据监控软件 inotify 三.实现实时同步数据...

  • 缓存一致性解决方案

    1.实时同步更新 特点:更新数据库的同时,更新缓存,使用缓存工具类或者AOP实现 优点:数据一致性强,不会出现缓存...

  • 备份服务之实时同步备份(sersync)

    实时同步备份方法1)利用脚本实现实时同步2)利用软件实现实时同步 实时同步备份原理 存储服务器 --...

  • Java缓存优化3 - 缓存同步、缓存穿透、缓存击穿、缓存雪崩的

    一、缓存同步问题 1. 缓存同步解决方案 1.1 数据实时同步 这种数据同步是增量、主动、强一致性 对数据库数据进...

  • 数据技术篇

    大数据阶段 数据采集层(1)数据库同步(DataX/同步中心)(2)消息中间件(离线、实时) 数据计算层 数据服务...

  • 架构之美

    企业项目案例 共享存储实时备份的原理: inotify(实时同步工具) 异步文件系统事件监控机制,可以监控文件系统...

  • 综合架构实时同步详解

    day35 综合架构实时同步 课程介绍: 1.实时同步原理概念2.实现实时同步方式3.实现实时同步方式1)利用脚本...

网友评论

      本文标题:SymmetricDS 实时数据库同步工具总结

      本文链接:https://www.haomeiwen.com/subject/wmyslttx.html