SlideShare a Scribd company logo
www.vmcd.org 
ROMA MySQL ASYNC MESSAGE SYSTEM ANALYSIS 
Our MySQL async message system Roma has already online. Here I want to talk about the process and explain the advantage of this system. 
Roma is based on Canal system which is used in Alibaba Inc. for different platform data flow translations. Canal acts as a slave of master and send quest to it, then master database will dump binlog event to Canal server. 
Canal will miner MySQL binlogs and translate them into messages, clients can subscribe these messages and do some other work later. Roma was marked as a subscriber behind Canal system. 
The architecture of Canal
www.vmcd.org 
Dump binlog 
Dump binlog 
I am slave! 
client 
Master 
Canal 
Process of Canal work: 
1. Canal tells MySQL Master (hey ,I’m Slave pleases sent binlog event to me) 
2. Master gets this message and finds that ‘real’ Slave (ok! dump binlog event to this Slave ) 
3. Canal gets the binlog event and calls the event parser to miner event into the formatted message 
4. Roma subscribes these messages then stores them in it ’s own store 
5. Everyone who wants to subscribe these message can ask Roma system
www.vmcd.org 
Why not use Canal as the final provider for customers? In other words why add Roma server behind Canal? The most important reason is that Canal can’t store messages in a solid state for its memory is used as RingBuffer, a ring circle based on arrays, that when you insert a new record, the old one will be overwritten then some message will be lost. Since we must keep everything in our system, we wrote Roma which uses rocketmq as a data storage (we can keep on MetaQ for a long time). In that way, Roma acts as a subscriber behind Canal and a provider for customers. 
Architecture of Roma: 
1. Based on Canal’s messages 
2. Roma subscribes Canal message 
3. Roma puts its message in MetaQ 
4. Canal opens ddl isolation, Roma subscribes ddl record
www.vmcd.org 
metamgr binlogETLmanager 
consumer 
MMyySSQQLL MMyySSQQLL 
canalserver canalserver 
dbnamemaper topicmaper binlogETL4MQ binlogETL4Chg 
diamond 
Romaclient 
RocketMQ 
DDL audit 
roma
www.vmcd.org 
Roma server subscribes what Canal server has provided, let us talk about the details 
First, MySQL database, we always do high availability for MySQL database, Canal can use these features to provide its own HA algorithm, Canal will do these steps when MySQL failover happens: 
Canal server configurations 
1. First look at Canal server configuration for MySQL database Master -> standby 
# position info Canal.instance.Master.address = 10.20.144.25:3306 Canal.instance.Master.journal.name = Canal.instance.Master.position = Canal.instance.Master.timestamp = 
Canal.instance.standby.address = 10.20.144.29:3306 Canal.instance.standby.journal.name = Canal.instance.standby.position = Canal.instance.standby.timestamp = 
2. When heartbeatHaEnable = true and also Canal got threshold of retry time 
3. When interval time * retry has been reached, Canal will switch to standby 
4. Canal finds new binlog position from new MySQL database using (timestamp minus fallbackIntervalInSeconds)
www.vmcd.org 
5. Canal will receive new binlog events from MySQL database 
What is fallbackIntervalInSeconds:when MySQL failover starts,Canal will find timestamp to identify which is the binlog position in new MySQL database. This timestamp should be earlier than which Canal has already determined (we consider this new timestamp should be (last timestamp – fallbackintervalseconds)). But if these steps have been done, Canal will produce some repeat records that have already been parsed. 
Slave database always stay behind master (we usually say there is a lag between them) so we need go back to old position due the “lag”. For some other reasons we also need to do so -- system time difference or IDC zone etc. It needs to roll back fallbackIntervalInSeconds to guarantee no data loss. 
But nothing is absolute. If Slave loses data in replication process, no matter how wonderful Canal is, the data will be lost。 
In this process ,Canal finds the final position based on timestamp -- using timestamp minus fallbackIntervalInSeconds to find new binlog position – below is the code : 
if (StringUtils.isEmpty(entryPosition.getJournalName())) { // 如果没有指定binlogName,尝试按照timestamp进行查找 if (entryPosition.getTimestamp() != null && > 0L) { return findByStartTimeStamp(MySQLConnection, entryPosition.getTimestamp()); } else { return findEndPosition(MySQLConnection); // 默认从当前最后一个位置进行消费 } } else { if (entryPosition.getPosition() != null && > 0L) { // 如果指定binlogName + offest,直接返回
www.vmcd.org 
return entryPosition; } else { EntryPosition specificLogFilePosition = null; if (entryPosition.getTimestamp() != null && entryPosition.getTimestamp() > 0L) { // 如果指定binlogName + timestamp,但没有指定对应的offest,尝试根据时间找一下offest EntryPosition endPosition = findEndPosition(MySQLConnection); if (endPosition != null) { specificLogFilePosition = findAsPerTimestampInSpecificLogFile( MySQLConnection, entryPosition.getTimestamp(), endPosition, entryPosition.getJournalName()); } } if (specificLogFilePosition == null) { // position不存在,从文件头开始 entryPosition.setPosition(BINLOG_START_OFFEST); return entryPosition; } else { return specificLogFilePosition; } } }
www.vmcd.org 
} else { if (logPosition.getIdentity().getSourceAddress().equals(MySQLConnection.getConnector().getAddress())) { return logPosition.getPostion(); } else { // 针对切换的情况,考虑回退时间 long newStartTimestamp = logPosition.getPostion().getTimestamp() - fallbackIntervalInSeconds * 1000; return findByStartTimeStamp(MySQLConnection, newStartTimestamp); } } } 
But problem persists, although Canal calculates a new timestamp, it may still could not find the right position (slave lags too much). So image that Canal minuses timestamp with fallbackIntervalInSeconds data and gets a new timestamp 12:00:00, but slave does not reach this timestamp at the moment, then data will be lost. New master’s(original slave) binlog position is the key point in this process, Canal will find new binlog position automatically ,then start parsing binlog from the new master database. 
This algorithm will produce duplicate messages. Canal can solve it by itself with filtering duplicate message on server & client site (we can also do idempotent protection in the end of services). 
Generally, Canal cannot guarantee data is correct whenever MySQL database failover happens (if data loss happens in MySQL replication layer, no one will save these)
www.vmcd.org 
In our MHA environment, we still set maser&standby parameters. MHA VIPs are not useful to Canal servers (different from business services) 
## MySQL serverId Canal.instance.MySQL.SlaveId9 = 1234 
# position info Canal.instance.Master.address9 = xxx.xxx:3306 Canal.instance.Master.journal.name9 = Canal.instance.Master.position9 = Canal.instance.Master.timestamp9 = 
Canal.instance.standby.address9 = xxx.xxx:3306 Canal.instance.standby.journal.name9 = Canal.instance.standby.position9 = Canal.instance.standby.timestamp9 =
www.vmcd.org 
# username/password Canal.instance.dbUsername9 = binlog Canal.instance.dbPassword9 = xxxxxxxxx Canal.instance.defaultDatabaseName9 = Canal.instance.connectionCharset9 = UTF-8 
# table regex Canal.instance.filter.regex9 = .* ..* # table black regex Canal.instance.filter.black.regex9 = pajk_monitor ..* ################################################# 
Canal server self HA 
Reference documents: 
Two parts of Canal HA, Canal client and Canal server 
Canal server: Instances in different servers must keep one running at the same time, others are keeping standby state to reduce requests from MySQL dump. 
Canal client: For one instance, just only Canal client can do get/ack/rollback commands at the same time to keep message in order.
www.vmcd.org 
Whole HA depends on zookeeper, watcher and EPHEMERAL nodes session lifecycle binding. 
Canal server 
Following are the steps: 
1. Canal server sends zookeeper a request to start one instance (create EPHEMERAL node, who successes first will get the privileges) 
2. After creating zk node successfully, the Canal server will create instance and other servers will be in standby state.
www.vmcd.org 
3. If zookeeper finds Canal server A has disappeared, it will inform other Canal servers to repeat step 1 immediately to elect a new candidate to create instance. 
4. Whenever Canal client tries to connect, it will ask zookeeper who has already created instance. Clients will keep trying to reconnect to servers if connection failure happens. 
Canal client is similar to Canal server, both of them intent to grab EPHEMERAL node 
Tips: 
1. If you choose memory mode for Canal event store, no position will be kept. Next time when Canal starts,it will read the last position which has been subscribed successfully(last ‘ack’ submit point) 
Canal.id= 1 Canal.ip= Canal.port= 11111 Canal.zkServers = xxx.xxx.xxx:2181,xxx.xxx.xxx.xxx:2181,xxx.xxx.xxx.xxx:2181 # flush data to zk Canal.zookeeper.flush.period = 1000 # flush meta cursor/parse position to file Canal.file.data.dir = ${Canal.conf.dir} Canal.file.flush.period = 1000 ## memory store RingBuffer size, should be Math.pow(2,n) Canal.instance.memory.buffer.size = 16384 ## memory store RingBuffer used unit size , default 1kb
www.vmcd.org 
Canal.instance.memory.buffer.memunit = 1024 ## meory store gets mode used MEMSIZE or ITEMSIZE Canal.instance.memory.batch.mode = MEMSIZE 
GroupEventParser and GroupEventSink 
It is popular among internet companies to split database into many physical instances. In this situation, if you want to combine them into one logical instance, Group parameter will be helpful. Using these two parameters will help you to create new logical instance for subscribing. 
If database has been split into four shards, every shard one instance. If you don’t make up a group, you will have to create four clients to subscribe each shard rather than one client to access all of them. 
GroupEventParser: multi threads event parser, parallel parse. 
GroupEventSink: Corresponding to groupeventparser ,global timestamp sort 
Main for global group ,according to this architecture ,if you split database db into db1:db2:db3:db4 split table user into user1:user2:user3:user4: 
Db1 -> user1+user2+user3+user4 
You can use Roma create logical topic + tag => logical:db user as table merge
www.vmcd.org 
Modify logical db mapping com.pajk.Roma.dbs/ROMA_GROUP(dataId/组名). [{"logicDb":"logicDb1","realDbs":"realDb11,realDb12"},{"logicDb2","realDb21,realDb22"}] 
Modify logical table mapping com.pajk.Roma.tbs/ROMA_GROUP(dataId/组名). [{"logicTb":"logicTb1","realTbs":"realTb11,realTb12"},{"logicTb":"logicTb2","realTbs":"realTb21,realTb22"}] 
Modify logical db mapping to topic com.pajk.Roma.topics/ROMA_GROUP(dataId/组名). [{"logicDb":"logicDb1","topic":"topic1"},{"logicDb2","topic2"}] 。 Modidfy logical table mapping to tag com.pajk.Roma.tags/ROMA_GROUP(dataId/组名). [{"logicTb":"logicTb1,field1","tag":"tag1,f1"},{"logicTb2","tag2"}] 
Client will subscribe topic in logic:db+table format direct. 
Advantages of Canal: 
1. Parallel parses, especially when we use group event parse. (refers Logical instance parallel parses.) 
2. Support different platforms. 
Canal cannot apply parallelly (message subscribe should in order) which is the same as MySQL slave recover. Canal and MySQL
www.vmcd.org 
can learn from oracle logical standby database. 
Advantages of Roma: 
1. Storage is permanent which is good for subscribing. 
2. Support logical topic which is good for combining operation (similar to partition merge in Kafka)

More Related Content

What's hot

MySQL replication & cluster
MySQL replication & clusterMySQL replication & cluster
MySQL replication & cluster
elliando dias
 

What's hot (20)

PostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication CheatsheetPostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication Cheatsheet
 
Backup automation in KAKAO
Backup automation in KAKAO Backup automation in KAKAO
Backup automation in KAKAO
 
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
Масштабируемая конфигурация Nginx, Игорь Сысоев (Nginx)
 
MongoDB – Sharded cluster tutorial - Percona Europe 2017
MongoDB – Sharded cluster tutorial - Percona Europe 2017MongoDB – Sharded cluster tutorial - Percona Europe 2017
MongoDB – Sharded cluster tutorial - Percona Europe 2017
 
Introduction to MySQL InnoDB Cluster
Introduction to MySQL InnoDB ClusterIntroduction to MySQL InnoDB Cluster
Introduction to MySQL InnoDB Cluster
 
WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-Tree
 
GOTO 2013: Why Zalando trusts in PostgreSQL
GOTO 2013: Why Zalando trusts in PostgreSQLGOTO 2013: Why Zalando trusts in PostgreSQL
GOTO 2013: Why Zalando trusts in PostgreSQL
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced Replication
 
Apache con na_2013_updated_2016
Apache con na_2013_updated_2016Apache con na_2013_updated_2016
Apache con na_2013_updated_2016
 
My sql failover test using orchestrator
My sql failover test  using orchestratorMy sql failover test  using orchestrator
My sql failover test using orchestrator
 
How to upgrade to MongoDB 4.0 - Percona Europe 2018
How to upgrade to MongoDB 4.0 - Percona Europe 2018How to upgrade to MongoDB 4.0 - Percona Europe 2018
How to upgrade to MongoDB 4.0 - Percona Europe 2018
 
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
Как понять, что происходит на сервере? / Александр Крижановский (NatSys Lab.,...
 
Apache con na_2013_updated_2016
Apache con na_2013_updated_2016Apache con na_2013_updated_2016
Apache con na_2013_updated_2016
 
Add a bit of ACID to Cassandra. Cassandra Summit EU 2014
Add a bit of ACID to Cassandra. Cassandra Summit EU 2014Add a bit of ACID to Cassandra. Cassandra Summit EU 2014
Add a bit of ACID to Cassandra. Cassandra Summit EU 2014
 
Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우Mvcc in postgreSQL 권건우
Mvcc in postgreSQL 권건우
 
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
Peeking into the Black Hole Called PL/PGSQL - the New PL Profiler / Jan Wieck...
 
GitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons LearnedGitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons Learned
 
MySQL replication & cluster
MySQL replication & clusterMySQL replication & cluster
MySQL replication & cluster
 
Ceph issue 해결 사례
Ceph issue 해결 사례Ceph issue 해결 사례
Ceph issue 해결 사례
 
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
Being closer to Cassandra by Oleg Anastasyev. Talk at Cassandra Summit EU 2013
 

Similar to MySQL async message subscription platform

Alibaba patches in MariaDB
Alibaba patches in MariaDBAlibaba patches in MariaDB
Alibaba patches in MariaDB
Lixun Peng
 
Dw tpain - Gordon Klok
Dw tpain - Gordon KlokDw tpain - Gordon Klok
Dw tpain - Gordon Klok
Devopsdays
 

Similar to MySQL async message subscription platform (20)

TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011
 
Building a High-Performance Database with Scala, Akka, and Spark
Building a High-Performance Database with Scala, Akka, and SparkBuilding a High-Performance Database with Scala, Akka, and Spark
Building a High-Performance Database with Scala, Akka, and Spark
 
Apache Cassandra in Bangalore - Cassandra Internals and Performance
Apache Cassandra in Bangalore - Cassandra Internals and PerformanceApache Cassandra in Bangalore - Cassandra Internals and Performance
Apache Cassandra in Bangalore - Cassandra Internals and Performance
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
Apache Con NA 2013 - Cassandra Internals
Apache Con NA 2013 - Cassandra InternalsApache Con NA 2013 - Cassandra Internals
Apache Con NA 2013 - Cassandra Internals
 
Consul - service discovery and others
Consul - service discovery and othersConsul - service discovery and others
Consul - service discovery and others
 
How Prometheus Store the Data
How Prometheus Store the DataHow Prometheus Store the Data
How Prometheus Store the Data
 
Alibaba patches in MariaDB
Alibaba patches in MariaDBAlibaba patches in MariaDB
Alibaba patches in MariaDB
 
weblogic perfomence tuning
weblogic perfomence tuningweblogic perfomence tuning
weblogic perfomence tuning
 
Apache Camel K - Fredericia
Apache Camel K - FredericiaApache Camel K - Fredericia
Apache Camel K - Fredericia
 
Active mq Installation and Master Slave setup
Active mq Installation and Master Slave setupActive mq Installation and Master Slave setup
Active mq Installation and Master Slave setup
 
C* Summit EU 2013: Cassandra Internals
C* Summit EU 2013: Cassandra Internals C* Summit EU 2013: Cassandra Internals
C* Summit EU 2013: Cassandra Internals
 
Apache samza past, present and future
Apache samza  past, present and futureApache samza  past, present and future
Apache samza past, present and future
 
Kafka streams decoupling with stores
Kafka streams decoupling with storesKafka streams decoupling with stores
Kafka streams decoupling with stores
 
A Detailed Look At cassandra.yaml (Edward Capriolo, The Last Pickle) | Cassan...
A Detailed Look At cassandra.yaml (Edward Capriolo, The Last Pickle) | Cassan...A Detailed Look At cassandra.yaml (Edward Capriolo, The Last Pickle) | Cassan...
A Detailed Look At cassandra.yaml (Edward Capriolo, The Last Pickle) | Cassan...
 
Concurrency at the Database Layer
Concurrency at the Database Layer Concurrency at the Database Layer
Concurrency at the Database Layer
 
Dw tpain - Gordon Klok
Dw tpain - Gordon KlokDw tpain - Gordon Klok
Dw tpain - Gordon Klok
 
Kamailio with Docker and Kubernetes
Kamailio with Docker and KubernetesKamailio with Docker and Kubernetes
Kamailio with Docker and Kubernetes
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - Deployment
 

More from Louis liu

基于Mongodb的压力评测工具 ycsb的一些概括
基于Mongodb的压力评测工具 ycsb的一些概括基于Mongodb的压力评测工具 ycsb的一些概括
基于Mongodb的压力评测工具 ycsb的一些概括
Louis liu
 
NetApp ef540 SSD Storage Test
NetApp ef540 SSD Storage TestNetApp ef540 SSD Storage Test
NetApp ef540 SSD Storage Test
Louis liu
 
MySQL 5.5&5.6 new features summary
MySQL 5.5&5.6 new features summaryMySQL 5.5&5.6 new features summary
MySQL 5.5&5.6 new features summary
Louis liu
 
Ssd gc review
Ssd gc reviewSsd gc review
Ssd gc review
Louis liu
 
1号店数据库架构
1号店数据库架构1号店数据库架构
1号店数据库架构
Louis liu
 
Architecture of YHD
Architecture of YHDArchitecture of YHD
Architecture of YHD
Louis liu
 
Think of oracle and mysql bind value
Think of oracle and mysql bind value Think of oracle and mysql bind value
Think of oracle and mysql bind value
Louis liu
 
ION performance brief hp dl980-8b
ION performance brief   hp dl980-8bION performance brief   hp dl980-8b
ION performance brief hp dl980-8b
Louis liu
 

More from Louis liu (20)

Tcpcopy benchmark
Tcpcopy benchmarkTcpcopy benchmark
Tcpcopy benchmark
 
JK Log-Center architect
JK Log-Center architectJK Log-Center architect
JK Log-Center architect
 
Wdt Test
Wdt TestWdt Test
Wdt Test
 
JKDB BACKUP Introduction
JKDB BACKUP IntroductionJKDB BACKUP Introduction
JKDB BACKUP Introduction
 
Infiniflash benchmark
Infiniflash benchmarkInfiniflash benchmark
Infiniflash benchmark
 
MySQL 5.7 milestone
MySQL 5.7 milestoneMySQL 5.7 milestone
MySQL 5.7 milestone
 
MySQL Oslayer performace optimization
MySQL  Oslayer performace optimizationMySQL  Oslayer performace optimization
MySQL Oslayer performace optimization
 
HBASE Performane Test
HBASE Performane TestHBASE Performane Test
HBASE Performane Test
 
Jkcn MySQLDB 架构
Jkcn MySQLDB 架构Jkcn MySQLDB 架构
Jkcn MySQLDB 架构
 
基于Mongodb的压力评测工具 ycsb的一些概括
基于Mongodb的压力评测工具 ycsb的一些概括基于Mongodb的压力评测工具 ycsb的一些概括
基于Mongodb的压力评测工具 ycsb的一些概括
 
NetApp ef540 SSD Storage Test
NetApp ef540 SSD Storage TestNetApp ef540 SSD Storage Test
NetApp ef540 SSD Storage Test
 
Exadata best practice on E-commerce area
Exadata best practice on E-commerce area Exadata best practice on E-commerce area
Exadata best practice on E-commerce area
 
MySQL 5.5&5.6 new features summary
MySQL 5.5&5.6 new features summaryMySQL 5.5&5.6 new features summary
MySQL 5.5&5.6 new features summary
 
Ssd gc review
Ssd gc reviewSsd gc review
Ssd gc review
 
1号店数据库架构
1号店数据库架构1号店数据库架构
1号店数据库架构
 
Architecture of YHD
Architecture of YHDArchitecture of YHD
Architecture of YHD
 
Oracle dgha
Oracle dghaOracle dgha
Oracle dgha
 
Think of oracle and mysql bind value
Think of oracle and mysql bind value Think of oracle and mysql bind value
Think of oracle and mysql bind value
 
ION performance brief hp dl980-8b
ION performance brief   hp dl980-8bION performance brief   hp dl980-8b
ION performance brief hp dl980-8b
 
How to study oracle by louis liu
How to study oracle by louis liu How to study oracle by louis liu
How to study oracle by louis liu
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 

MySQL async message subscription platform

  • 1. www.vmcd.org ROMA MySQL ASYNC MESSAGE SYSTEM ANALYSIS Our MySQL async message system Roma has already online. Here I want to talk about the process and explain the advantage of this system. Roma is based on Canal system which is used in Alibaba Inc. for different platform data flow translations. Canal acts as a slave of master and send quest to it, then master database will dump binlog event to Canal server. Canal will miner MySQL binlogs and translate them into messages, clients can subscribe these messages and do some other work later. Roma was marked as a subscriber behind Canal system. The architecture of Canal
  • 2. www.vmcd.org Dump binlog Dump binlog I am slave! client Master Canal Process of Canal work: 1. Canal tells MySQL Master (hey ,I’m Slave pleases sent binlog event to me) 2. Master gets this message and finds that ‘real’ Slave (ok! dump binlog event to this Slave ) 3. Canal gets the binlog event and calls the event parser to miner event into the formatted message 4. Roma subscribes these messages then stores them in it ’s own store 5. Everyone who wants to subscribe these message can ask Roma system
  • 3. www.vmcd.org Why not use Canal as the final provider for customers? In other words why add Roma server behind Canal? The most important reason is that Canal can’t store messages in a solid state for its memory is used as RingBuffer, a ring circle based on arrays, that when you insert a new record, the old one will be overwritten then some message will be lost. Since we must keep everything in our system, we wrote Roma which uses rocketmq as a data storage (we can keep on MetaQ for a long time). In that way, Roma acts as a subscriber behind Canal and a provider for customers. Architecture of Roma: 1. Based on Canal’s messages 2. Roma subscribes Canal message 3. Roma puts its message in MetaQ 4. Canal opens ddl isolation, Roma subscribes ddl record
  • 4. www.vmcd.org metamgr binlogETLmanager consumer MMyySSQQLL MMyySSQQLL canalserver canalserver dbnamemaper topicmaper binlogETL4MQ binlogETL4Chg diamond Romaclient RocketMQ DDL audit roma
  • 5. www.vmcd.org Roma server subscribes what Canal server has provided, let us talk about the details First, MySQL database, we always do high availability for MySQL database, Canal can use these features to provide its own HA algorithm, Canal will do these steps when MySQL failover happens: Canal server configurations 1. First look at Canal server configuration for MySQL database Master -> standby # position info Canal.instance.Master.address = 10.20.144.25:3306 Canal.instance.Master.journal.name = Canal.instance.Master.position = Canal.instance.Master.timestamp = Canal.instance.standby.address = 10.20.144.29:3306 Canal.instance.standby.journal.name = Canal.instance.standby.position = Canal.instance.standby.timestamp = 2. When heartbeatHaEnable = true and also Canal got threshold of retry time 3. When interval time * retry has been reached, Canal will switch to standby 4. Canal finds new binlog position from new MySQL database using (timestamp minus fallbackIntervalInSeconds)
  • 6. www.vmcd.org 5. Canal will receive new binlog events from MySQL database What is fallbackIntervalInSeconds:when MySQL failover starts,Canal will find timestamp to identify which is the binlog position in new MySQL database. This timestamp should be earlier than which Canal has already determined (we consider this new timestamp should be (last timestamp – fallbackintervalseconds)). But if these steps have been done, Canal will produce some repeat records that have already been parsed. Slave database always stay behind master (we usually say there is a lag between them) so we need go back to old position due the “lag”. For some other reasons we also need to do so -- system time difference or IDC zone etc. It needs to roll back fallbackIntervalInSeconds to guarantee no data loss. But nothing is absolute. If Slave loses data in replication process, no matter how wonderful Canal is, the data will be lost。 In this process ,Canal finds the final position based on timestamp -- using timestamp minus fallbackIntervalInSeconds to find new binlog position – below is the code : if (StringUtils.isEmpty(entryPosition.getJournalName())) { // 如果没有指定binlogName,尝试按照timestamp进行查找 if (entryPosition.getTimestamp() != null && > 0L) { return findByStartTimeStamp(MySQLConnection, entryPosition.getTimestamp()); } else { return findEndPosition(MySQLConnection); // 默认从当前最后一个位置进行消费 } } else { if (entryPosition.getPosition() != null && > 0L) { // 如果指定binlogName + offest,直接返回
  • 7. www.vmcd.org return entryPosition; } else { EntryPosition specificLogFilePosition = null; if (entryPosition.getTimestamp() != null && entryPosition.getTimestamp() > 0L) { // 如果指定binlogName + timestamp,但没有指定对应的offest,尝试根据时间找一下offest EntryPosition endPosition = findEndPosition(MySQLConnection); if (endPosition != null) { specificLogFilePosition = findAsPerTimestampInSpecificLogFile( MySQLConnection, entryPosition.getTimestamp(), endPosition, entryPosition.getJournalName()); } } if (specificLogFilePosition == null) { // position不存在,从文件头开始 entryPosition.setPosition(BINLOG_START_OFFEST); return entryPosition; } else { return specificLogFilePosition; } } }
  • 8. www.vmcd.org } else { if (logPosition.getIdentity().getSourceAddress().equals(MySQLConnection.getConnector().getAddress())) { return logPosition.getPostion(); } else { // 针对切换的情况,考虑回退时间 long newStartTimestamp = logPosition.getPostion().getTimestamp() - fallbackIntervalInSeconds * 1000; return findByStartTimeStamp(MySQLConnection, newStartTimestamp); } } } But problem persists, although Canal calculates a new timestamp, it may still could not find the right position (slave lags too much). So image that Canal minuses timestamp with fallbackIntervalInSeconds data and gets a new timestamp 12:00:00, but slave does not reach this timestamp at the moment, then data will be lost. New master’s(original slave) binlog position is the key point in this process, Canal will find new binlog position automatically ,then start parsing binlog from the new master database. This algorithm will produce duplicate messages. Canal can solve it by itself with filtering duplicate message on server & client site (we can also do idempotent protection in the end of services). Generally, Canal cannot guarantee data is correct whenever MySQL database failover happens (if data loss happens in MySQL replication layer, no one will save these)
  • 9. www.vmcd.org In our MHA environment, we still set maser&standby parameters. MHA VIPs are not useful to Canal servers (different from business services) ## MySQL serverId Canal.instance.MySQL.SlaveId9 = 1234 # position info Canal.instance.Master.address9 = xxx.xxx:3306 Canal.instance.Master.journal.name9 = Canal.instance.Master.position9 = Canal.instance.Master.timestamp9 = Canal.instance.standby.address9 = xxx.xxx:3306 Canal.instance.standby.journal.name9 = Canal.instance.standby.position9 = Canal.instance.standby.timestamp9 =
  • 10. www.vmcd.org # username/password Canal.instance.dbUsername9 = binlog Canal.instance.dbPassword9 = xxxxxxxxx Canal.instance.defaultDatabaseName9 = Canal.instance.connectionCharset9 = UTF-8 # table regex Canal.instance.filter.regex9 = .* ..* # table black regex Canal.instance.filter.black.regex9 = pajk_monitor ..* ################################################# Canal server self HA Reference documents: Two parts of Canal HA, Canal client and Canal server Canal server: Instances in different servers must keep one running at the same time, others are keeping standby state to reduce requests from MySQL dump. Canal client: For one instance, just only Canal client can do get/ack/rollback commands at the same time to keep message in order.
  • 11. www.vmcd.org Whole HA depends on zookeeper, watcher and EPHEMERAL nodes session lifecycle binding. Canal server Following are the steps: 1. Canal server sends zookeeper a request to start one instance (create EPHEMERAL node, who successes first will get the privileges) 2. After creating zk node successfully, the Canal server will create instance and other servers will be in standby state.
  • 12. www.vmcd.org 3. If zookeeper finds Canal server A has disappeared, it will inform other Canal servers to repeat step 1 immediately to elect a new candidate to create instance. 4. Whenever Canal client tries to connect, it will ask zookeeper who has already created instance. Clients will keep trying to reconnect to servers if connection failure happens. Canal client is similar to Canal server, both of them intent to grab EPHEMERAL node Tips: 1. If you choose memory mode for Canal event store, no position will be kept. Next time when Canal starts,it will read the last position which has been subscribed successfully(last ‘ack’ submit point) Canal.id= 1 Canal.ip= Canal.port= 11111 Canal.zkServers = xxx.xxx.xxx:2181,xxx.xxx.xxx.xxx:2181,xxx.xxx.xxx.xxx:2181 # flush data to zk Canal.zookeeper.flush.period = 1000 # flush meta cursor/parse position to file Canal.file.data.dir = ${Canal.conf.dir} Canal.file.flush.period = 1000 ## memory store RingBuffer size, should be Math.pow(2,n) Canal.instance.memory.buffer.size = 16384 ## memory store RingBuffer used unit size , default 1kb
  • 13. www.vmcd.org Canal.instance.memory.buffer.memunit = 1024 ## meory store gets mode used MEMSIZE or ITEMSIZE Canal.instance.memory.batch.mode = MEMSIZE GroupEventParser and GroupEventSink It is popular among internet companies to split database into many physical instances. In this situation, if you want to combine them into one logical instance, Group parameter will be helpful. Using these two parameters will help you to create new logical instance for subscribing. If database has been split into four shards, every shard one instance. If you don’t make up a group, you will have to create four clients to subscribe each shard rather than one client to access all of them. GroupEventParser: multi threads event parser, parallel parse. GroupEventSink: Corresponding to groupeventparser ,global timestamp sort Main for global group ,according to this architecture ,if you split database db into db1:db2:db3:db4 split table user into user1:user2:user3:user4: Db1 -> user1+user2+user3+user4 You can use Roma create logical topic + tag => logical:db user as table merge
  • 14. www.vmcd.org Modify logical db mapping com.pajk.Roma.dbs/ROMA_GROUP(dataId/组名). [{"logicDb":"logicDb1","realDbs":"realDb11,realDb12"},{"logicDb2","realDb21,realDb22"}] Modify logical table mapping com.pajk.Roma.tbs/ROMA_GROUP(dataId/组名). [{"logicTb":"logicTb1","realTbs":"realTb11,realTb12"},{"logicTb":"logicTb2","realTbs":"realTb21,realTb22"}] Modify logical db mapping to topic com.pajk.Roma.topics/ROMA_GROUP(dataId/组名). [{"logicDb":"logicDb1","topic":"topic1"},{"logicDb2","topic2"}] 。 Modidfy logical table mapping to tag com.pajk.Roma.tags/ROMA_GROUP(dataId/组名). [{"logicTb":"logicTb1,field1","tag":"tag1,f1"},{"logicTb2","tag2"}] Client will subscribe topic in logic:db+table format direct. Advantages of Canal: 1. Parallel parses, especially when we use group event parse. (refers Logical instance parallel parses.) 2. Support different platforms. Canal cannot apply parallelly (message subscribe should in order) which is the same as MySQL slave recover. Canal and MySQL
  • 15. www.vmcd.org can learn from oracle logical standby database. Advantages of Roma: 1. Storage is permanent which is good for subscribing. 2. Support logical topic which is good for combining operation (similar to partition merge in Kafka)