WO2020147392A1 - 数据库之间的数据同步方法和系统 - Google Patents

数据库之间的数据同步方法和系统 Download PDF

Info

Publication number
WO2020147392A1
WO2020147392A1 PCT/CN2019/116998 CN2019116998W WO2020147392A1 WO 2020147392 A1 WO2020147392 A1 WO 2020147392A1 CN 2019116998 W CN2019116998 W CN 2019116998W WO 2020147392 A1 WO2020147392 A1 WO 2020147392A1
Authority
WO
WIPO (PCT)
Prior art keywords
database
standard
source
statement
server
Prior art date
Application number
PCT/CN2019/116998
Other languages
English (en)
French (fr)
Inventor
刘顺
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2020147392A1 publication Critical patent/WO2020147392A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Definitions

  • This application relates to a method and system for data synchronization between databases.
  • data synchronization In order to ensure the normal operation of enterprise business, data synchronization needs to be achieved between the core database and the target database in each region to ensure the integrity and unity of data requirements.
  • data synchronization is mainly to synchronize data between master and slave servers in the same database cluster.
  • the inventor has realized that when data is synchronized in different database clusters, the normal operation of the business of the enterprise cannot be achieved because the data cannot be synchronized in real time.
  • a method for data synchronization between databases includes:
  • the source server reads the log file of the source database, and parses the log file into recognizable text
  • the source server filters SQL statements from the identifiable text, and converts the obtained SQL statements into standard SQL statements; the filtered SQL statements are used to operate on changed data in the database;
  • the source server encapsulates the standard SQL statement into a subscription message and sends it to the Kafka cluster;
  • the Kafka cluster broadcasts to each target server after receiving the subscription message.
  • the target server After obtaining the subscription message, the target server decapsulates the subscription message to obtain the standard SQL statement, and executes the standard SQL statement to synchronize the changed data sent in the source database to the target database.
  • a data synchronization system between databases includes:
  • the source server is used to read the log file of the source database and parse the log file into recognizable text
  • the source server is also used to filter SQL statements from the identifiable text and convert the obtained SQL statements into standard SQL statements; the filtered SQL statements are used to operate on data that has changed in the database;
  • the source server is also used to encapsulate the standard SQL statement into a subscription message and send it to the Kafka cluster;
  • the Kafka cluster is configured to broadcast to each target server after receiving the subscription message
  • the target server is configured to decapsulate the subscription message to obtain the standard SQL statement after obtaining the subscription message, and execute the standard SQL statement to synchronize the changed data sent in the source database to The target database.
  • Fig. 1 is an application scenario diagram of a data synchronization method between databases according to one or more embodiments
  • FIG. 2 is a schematic flowchart of a data synchronization method between databases according to one or more embodiments
  • Figure 3 is a schematic diagram of partitioned storage in a Kafka cluster according to one or more embodiments
  • Figure 4 is a structural block diagram of a data synchronization system between databases according to one or more embodiments
  • Fig. 5 is a structural block diagram of a data synchronization system between databases according to another or more embodiments.
  • the data synchronization method between databases provided in this application can be applied to the application environment as shown in FIG. 1.
  • the source server 110, the kafka cluster 120, the target server 130, the first terminal 140, and the second terminal 150 can communicate through a network.
  • the source server 110 reads the log file of the source database and parses the log file into recognizable text; the source server 110 filters SQL statements from the recognizable text and converts the obtained SQL statements into standard SQL statements; the source server 110 converts the standard
  • the SQL statement is encapsulated into a subscription message and sent to the kafka cluster; after receiving the subscription message, the kafka cluster 120 broadcasts to each target server 130; after obtaining the subscription message, the target server 130 decapsulates the subscription message to obtain a standard SQL statement.
  • the first terminal 140 and the second terminal 150 may obtain data from the source server 110 and the target server 130, respectively, to perform corresponding business interactions, such as acquiring insurance business data to handle insurance business.
  • the first terminal 140 and the second terminal 150 may be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, and the like.
  • the source server 110, the kafka cluster 120, and the target server 130 may be implemented by independent servers or a server cluster composed of multiple servers, respectively.
  • a method for data synchronization between databases which includes the following steps:
  • the source server reads the log file of the source database, and parses the log file into recognizable text.
  • the aforementioned source database can be a database such as mySQL, Oracle, or postgreSQL.
  • the log file can be a binary binlog log file. All operations on the database are saved in the binlog log file, such as query, update, insert, add and delete data tables and other database-related operations. In addition, the binlog log file will record the operation data and data type.
  • the source server can read the log file of the source database through canal.
  • canal can simulate the slave interaction protocol of the database, pretend to be a slave of the database, and then read the log file of the source database.
  • the source server can parse the binary log file into a user-recognizable file, so that a user-recognizable SQL (Structured Query Language, structured query language) can be obtained about database operations. Query language) statement.
  • SQL Structured Query Language, structured query language
  • the source server includes a translator, where the translator is divided into two parts: an analyzer and a converter.
  • the source server can parse the binlog log file into recognizable text through the analyzer.
  • S202 may specifically include: when the data in the source database changes or meets a preset synchronization time requirement, the source server reads the log file of the source database through the canal.
  • the preset synchronization time can be every few seconds, minutes or other intervals.
  • the source server can synchronize data that has changed in the source database, and can also synchronize all data in the source database.
  • the source server makes canal read the binlog from the starting point according to the configuration information in the configuration file.
  • the source server makes canal read the binlog log according to the storage time of the data according to the configuration information in the configuration file to obtain the binlog log file. Then, the source server parses the read binary binlog log file into user-recognizable text through the analyzer.
  • the source server filters SQL statements from the identifiable text, and converts the obtained SQL statements into standard SQL statements; the filtered SQL statements are used to operate on the changed data in the database.
  • Standard SQL statements include at least one of the following: standard new statements, standard insert statements, and standard delete statements.
  • the filtered SQL statements may be: SQL statements that change the data in the database, for example, including at least one of the following: new statements, insert statements, and delete statements; S204 may specifically include: source server acquisition Keywords corresponding to new sentences, insert sentences, and/or delete sentences; the source server filters SQL sentences matching the keywords from the recognizable text, or filters SQL sentences in the recognizable text that do not match the keywords , Get the filtered SQL statement, and convert the obtained SQL statement into a standard SQL statement.
  • the above-mentioned newly added sentence may be a sentence for adding data, a sentence for modifying data, etc.
  • add, alter, drop, modify and other keywords used to manipulate the database are included in the new, insert, and delete statements.
  • the source server filters the SQL statements that match add, alter, drop, modify and other keywords in the recognizable text, and operate on the changed data in the database; or, in the recognizable text, the source server will match add, SQL statements with unmatched keywords such as alter, drop, modify, etc. are filtered to obtain SQL statements that operate on the changed data in the database.
  • the select query statement since the select query statement will not change the data in the database, the select query statement can be filtered out during the data synchronization process.
  • the source server can also filter data that is not an operational business table, such as non-SQL statements, through an analyzer.
  • the source server translates the SQL statements of the source database into standard SQL statements through a converter.
  • standard SQL statements can be executed in other different types of databases, which is the key to the system's ability to synchronize data between different databases.
  • the source server encapsulates the standard SQL statement into a subscription message and sends it to the Kafka cluster.
  • the source server can encapsulate standard SQL statements into subscription messages through SQL_producer and send them to the Kafka cluster. Due to the publish and subscribe mechanism of Kafka, the target server will immediately perceive the subscription message in the Kafka cluster, and immediately use SQL_consumer (kafka consumer) to connect to the database to execute SQL, so it is real-time.
  • SQL_consumer kafka consumer
  • SQL_producer can be a producer of a Kafka cluster developed by Java.
  • the source server can assemble SQL statements into a subscription message of the Kafka cluster through SQL_producer, and then send the assembled subscription message to the Kafka cluster.
  • the source server sends the subscription message to the designated partition in the kafka cluster by specifying the partition; or the source server sends the subscription message to the corresponding different partition in the kafka cluster through the balancing strategy.
  • the source server when sending a subscription message, determines to adopt a designated partitioning method or a balancing strategy, or a random balancing method. Then, the source server sends the subscription message to the designated partition in the Kafka cluster according to the designated partition; or, according to the balancing strategy, sends the subscription message to the corresponding different partitions in the Kafka cluster; or, according to the random balance The way, the subscription message is randomly sent to the partition in the kafka cluster.
  • the target server After obtaining the subscription message, the target server decapsulates the subscription message to obtain a standard SQL statement, and executes the standard SQL statement to synchronize the changed data sent in the source database to the target database.
  • the target server consumes the subscription message through SQL_consumer, after consuming the subscription message, establishes a connection with the target database, unpackages the subscription message to obtain a standard SQL statement, and executes the standard SQL statement , To synchronize the changed data sent in the source database to the target database.
  • the target server establishes a long connection between SQL_consumer and the Kafka cluster, and continuously pulls subscription messages from the Kafka cluster through the established long connection, and then consumes these subscription messages.
  • Kafka will also record the current consumption location through offset.
  • the consumption record location offset does not interfere with each other.
  • the standard SQL statement includes at least one of the following: a standard new statement, a standard insert statement, and a standard delete statement; the standard SQL statement is executed in S210 to synchronize the business data from the source database to the target
  • the database includes: the target server executes a standard new statement to synchronize the updated business data in the source database to the target database; and/or the target server executes a standard insert statement to simultaneously insert the business data inserted in the source database To the target database; and/or, the target server executes a standard delete statement to delete data in the target database corresponding to the deleted business data in the source database.
  • Incremental data is synchronized to the corresponding field of the target database; if the deleted data in the source database is synchronized, when standard SQL statements are executed, the second field identifier in the target database is determined according to the deleted data field, and the second field identifier is deleted according to the second field identifier The data of the corresponding field in the target database to achieve data synchronization.
  • the zookeeper system monitors the working status of the source server, the kafka cluster, and the target server, and generates a status list based on the working status, so as to find abnormal devices from the source server, the kafka cluster, and the target server according to the status list.
  • the zookeeper system is a tool for managing the cluster, which can be used to manage the kafka cluster, SQL_producer and SQL_consumer, monitor the working status of the kafka cluster, SQL_producer and SQL_consumer, and determine whether the working status is normal.
  • the working status can be the status information of whether the source server, the Kafka cluster, and the target server are working normally, such as the length of time for processing the task (for example, the time for processing the task is greater than a preset threshold), or downtime.
  • the zookeeper system monitors the working status of the source server. According to the working status, it determines that the source server takes a long time to process tasks or if there is downtime, then it is determined that the source server is abnormal. In the same way, it can also be determined whether the Kafka cluster and the target server are abnormal.
  • the log file records all data operations on the source database.
  • the source server parses the log file into recognizable text, filters the filtered SQL statements from the recognizable text, and converts the SQL statements into standard SQL statements , Since standard SQL statements can support data operations of multiple types of databases, real-time data synchronization between different database clusters can be realized.
  • the custom SQL_producer, canal, SQL_consumer and converter are systems developed by pure java, which are easy to operate and maintain.
  • the corresponding physical equipment (such as source server, kafka cluster) and service operation status can be monitored by zookeeper.
  • Synchronization of remote computer rooms Compared with the replication efficiency of long-distance computer rooms such as mySQL or Oracle, using the embodiment of this application, data playback is broken up into log analysis, log analysis, SQL statement generation, encapsulation of messages, transmission of messages, and consumption Messages and other steps, each step can deploy multiple machines to improve performance, thereby improving the performance of the entire system.
  • steps in the flowchart of FIG. 2 are displayed in sequence as indicated by the arrows, these steps are not necessarily performed in sequence in the order indicated by the arrows. Unless clearly stated in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least part of the steps in FIG. 2 may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution of these sub-steps or stages The sequence is not necessarily performed sequentially, but may be performed alternately or alternately with other steps or at least a part of sub-steps or stages of other steps.
  • a data synchronization system between databases including: a source server 402, a kafka cluster 404, and a target server 406, where:
  • the source server 402 is used to read the log file of the source database and parse the log file into recognizable text.
  • the aforementioned source database can be a database such as mySQL, Oracle, or postgreSQL.
  • the log file can be a binary binlog log file. All operations on the database are saved in the binlog log file, such as query, update, insert, add and delete data tables and other database-related operations. In addition, the binlog log file will record the operation data and data type.
  • the source server 402 is also used to read the log file of the source database through canal.
  • canal can simulate the slave interaction protocol of the database, pretend to be a slave of the database, and then read the log file.
  • the source server 402 is also used to parse the binary log file into a user-recognizable file, so that user-recognizable SQL (Structured SQL) related to database operations can be obtained.
  • SQL Structured SQL
  • Query Language structured query language
  • the source server 402 includes a translator, and the translator is divided into two parts: an analyzer and a converter; wherein, the filtered SQL statements include at least one of the following: new statements, insert statements, and delete statements;
  • the analyzer is used to obtain keywords corresponding to newly added sentences, insert sentences, and/or delete sentences; filter SQL sentences that match the keywords from the recognizable text, or the recognizable text does not match the keywords Filter the SQL statement to get the filtered SQL statement;
  • the converter is used to convert the obtained SQL statement into a standard SQL statement.
  • the source server 402 when the data in the source database changes, or when the preset synchronization time is reached, the source server 402 is also used to read the log file of the source database through the canal.
  • the source server 402 can also be used to synchronize data that has changed in the source database, and can also synchronize all data in the source database.
  • the source server 402 is also used to make canal read the binlog from the starting point according to the configuration information in the configuration file.
  • the source server 402 is also used to make canal read the binlog log according to the storage time of the data according to the configuration information in the configuration file to obtain the binlog log file. Then, the source server 402 is also used to parse the read binary binlog log file into user-recognizable text through an analyzer.
  • the source server 402 is also used to filter SQL statements from the identifiable text and convert the obtained SQL statements into standard SQL statements; the filtered SQL statements are used to operate on the changed data in the database.
  • standard SQL statements include at least one of the following: standard new statements, standard insert statements, and standard delete statements.
  • the filtered SQL statements may be: SQL statements that cause data in the database to change, for example, including at least one of the following: new statements, insert statements, and delete statements; the source server 402 is specifically used to: Keywords corresponding to new sentences, insert sentences and/or delete sentences; filter SQL sentences matching the keywords from the recognizable text, or filter the SQL sentences that do not match the keywords in the recognizable text, get Filter the SQL statements, and convert the obtained SQL statements into standard SQL statements.
  • the above-mentioned newly added sentence may be a sentence for adding data, a sentence for modifying data, etc.
  • add, alter, drop, modify and other keywords used to manipulate the database are included in the new, insert, and delete statements.
  • the source server 402 is also used to filter SQL statements matching add, alter, drop, modify and other keywords in the recognizable text and operate on the changed data in the database; or, the source server 402 is also used to In the recognized text, filter SQL statements that do not match keywords such as add, alter, drop, modify, etc., to obtain SQL statements that operate on the changed data in the database.
  • the select query statement since the select query statement will not change the data in the database, the select query statement can be filtered out during the data synchronization process.
  • the source server 402 is also used to filter data that is not an operation business table, such as a non-SQL statement, through an analyzer.
  • the source server 402 is also used to translate SQL statements of the source database into standard SQL statements through a converter.
  • standard SQL statements can be executed in other different types of databases, which is the key to the system's ability to synchronize data between different databases.
  • the source server 402 is also used to encapsulate standard SQL statements into subscription messages and send them to the Kafka cluster 404.
  • the source server 402 is also used to encapsulate standard SQL statements into subscription messages through SQL_producer and send them to the kafka cluster 404. Due to the publish and subscribe mechanism of Kafka, the target server will immediately perceive a subscription message in the Kafka cluster 404, and immediately use SQL_consumer (kafka consumer) to connect to the database to execute SQL, so it is real-time.
  • SQL_consumer kafka consumer
  • SQL_producer may be the producer of the Kafka cluster 404 developed by Java, the source server 402, and is also used to assemble SQL statements into the subscription message of the Kafka cluster 404 through SQL_producer, and then send the assembled subscription message to the Kafka cluster 404.
  • the source server 402 is also used to send the subscription message to the designated partition in the kafka cluster 404 by means of designated partition; or, through the balancing strategy, send the subscription message to the kafka cluster 404 Corresponding to different partitions.
  • the source server 402 when sending a subscription message, determines to adopt a designated partition method or a balancing strategy, or a random balancing method. Then, the source server 402 sends the subscription message to the designated partition in the Kafka cluster 404 in the manner of the designated partition; or, in accordance with the balancing strategy, sends the subscription message to the corresponding different partition in the Kafka cluster 404; or, In a random and balanced manner, the subscription message is randomly sent to the partition in the kafka cluster 404.
  • the kafka cluster 404 is configured to broadcast to each target server 406 after receiving the subscription message.
  • the target server 406 is configured to decapsulate the subscription message to obtain a standard SQL statement after obtaining the subscription message, and execute the standard SQL statement to synchronize the changed data sent in the source database to the target database.
  • the target server 406 is also used to consume the subscription message through SQL_consumer after receiving the broadcast, establish a connection with the target database after the subscription message is consumed, and unpack the subscription message to obtain a standard SQL statement , Execute standard SQL statements to synchronize the changed data sent in the source database to the target database.
  • the target server 406 is also used to establish a persistent connection between the SQL_consumer and the Kafka cluster 404, continuously pull subscription messages from the Kafka cluster 404 through the established persistent connection, and then consume these subscription messages.
  • Kafka will also record the current consumption location through offset.
  • the consumption record location offset does not interfere with each other.
  • the standard SQL statement includes at least one of the following: a standard new statement, a standard insert statement, and a standard delete statement;
  • the target server 406 is specifically used to execute the standard new statement to transfer the source database Synchronously update the business data updated in the target database; and/or execute a standard insert statement to insert the business data inserted in the source database into the target database; and/or execute a standard delete statement to delete the target database Data corresponding to the deleted business data in the source database.
  • Incremental data is synchronized to the corresponding field of the target database; if the deleted data in the source database is synchronized, when standard SQL statements are executed, the second field identifier in the target database is determined according to the deleted data field, and the second field identifier is deleted according to the second field identifier The data of the corresponding field in the target database to achieve data synchronization.
  • the data synchronization system further includes a zookeeper system 408; among them: the zookeeper system 408 is used to monitor the working status of the source server 402, the kafka cluster 404 and the target server 406, and generate the status according to the working status List to find abnormal devices from the source server, kafka cluster and target server according to the status list.
  • the zookeeper system 408 is used to monitor the working status of the source server 402, the kafka cluster 404 and the target server 406, and generate the status according to the working status List to find abnormal devices from the source server, kafka cluster and target server according to the status list.
  • the zookeeper system 408 is a cluster management tool, which can be used to manage the kafka cluster 404, SQL_producer and SQL_consumer, monitor the working status of the kafka cluster 404, SQL_producer and SQL_consumer, and determine whether the working status is normal.
  • the working status can be the status information of whether the source server, the Kafka cluster, and the target server are working normally, such as the length of time for processing the task (for example, the time for processing the task is greater than a preset threshold), or downtime.
  • the zookeeper system monitors the working status of the source server. According to the working status, it determines that the source server takes a long time to process tasks or if there is downtime, then it is determined that the source server is abnormal. In the same way, it can be determined whether the Kafka cluster and the target server are abnormal.
  • the log file records all data operations on the source database.
  • the source server parses the log file into recognizable text, filters the filtered SQL statements from the recognizable text, and converts the SQL statements into standard SQL statements . Since standard SQL statements can support data operations of multiple types of databases, real-time data synchronization between different database clusters can be realized, thereby ensuring the normal operation of business.
  • the custom SQL_producer, canal, SQL_consumer and converter are systems developed by pure java, which are easy to operate and maintain.
  • the corresponding physical equipment (such as source server, kafka cluster) and service operation status can be monitored by zookeeper.
  • Synchronization of remote computer rooms Compared with the replication efficiency of long-distance computer rooms such as mySQL or Oracle, using the embodiment of this application, data playback is broken up into log analysis, log analysis, SQL statement generation, encapsulation of messages, transmission of messages, and consumption Messages and other steps, each step can deploy multiple machines to improve performance, thereby improving the performance of the entire system.
  • Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory.
  • Volatile memory can include random access memory (RAM) or external cache memory.
  • RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous chain (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
  • SRAM static RAM
  • DRAM dynamic RAM
  • SDRAM synchronous DRAM
  • DDRSDRAM double data rate SDRAM
  • ESDRAM enhanced SDRAM
  • SLDRAM synchronous chain (Synchlink) DRAM
  • SLDRAM synchronous chain (Synchlink) DRAM
  • Rambus direct RAM
  • DRAM direct memory bus dynamic RAM
  • RDRAM memory bus dynamic RAM

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种数据库之间的数据同步方法,包括:源服务器读取源数据库的日志文件,并将所述日志文件解析成可识别文本;所述源服务器从所述可识别文本中筛选SQL语句,并将获得的SQL语句转换成标准SQL语句;所述源服务器将所述标准SQL语句封装成订阅消息并发送至kafka集群;所述kafka集群在接收到所述订阅消息后,向各目标服务器进行广播;所述目标服务器在获得所述订阅消息后,对所述订阅消息进行解封装得到所述标准SQL语句,执行标准SQL语句,以将源数据库中发送变化的数据同步至目标数据库。

Description

数据库之间的数据同步方法和系统
本申请要求于2019年01月16日提交中国专利局,申请号为2019100403611,申请名称为“数据库之间的数据同步方法和系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及一种数据库之间的数据同步方法和系统。
背景技术
在当前的互联网时代,许多企业在网上为广大用户提供数字服务,使得数据访问需求量呈井喷式增长,核心数据库往往无法支撑如此大的并发操作,为此许多互联网和金融等企业建立多个跨区域的目标数据库,将大量业务数据从核心数据库转移到相应区域的目标数据库中。
为确保企业业务的正常运转,核心数据库与各区域的目标数据库之间需要实现数据同步,保证数据需的完整性和统一性。传统的数据同步方案中,数据同步主要是同一个数据库集群内的主从服务器之间互相进行数据同步。然而,发明人意识到,在不同数据库集群中进行数据同步时,由于无法达到数据实时同步而影响企业业务的正常运转。
发明内容
根据本申请公开的各种实施例,提供一种数据库之间的数据同步方法和系统。
一种数据库之间的数据同步方法,所述方法包括:
源服务器读取源数据库的日志文件,并将所述日志文件解析成可识别文本;
所述源服务器从所述可识别文本中筛选SQL语句,并将获得的SQL语句转换成标准SQL语句;筛选的所述SQL语句用于对数据库中发生变化的数据进行操作;
所述源服务器将所述标准SQL语句封装成订阅消息并发送至kafka集群;
所述kafka集群在接收到所述订阅消息后,向各目标服务器进行广播;及
所述目标服务器在获得所述订阅消息后,对所述订阅消息进行解封装得到所述标准SQL语句,执行所述标准SQL语句,以将所述源数据库中发送变化的数据同步至目标数据库。
一种数据库之间的数据同步系统,所述系统包括:
源服务器,用于读取源数据库的日志文件,并将所述日志文件解析成可识别文本;
所述源服务器,还用于从所述可识别文本中筛选SQL语句,并将获得的SQL语句转换成标准SQL语句;筛选的所述SQL语句用于对数据库中发生变化的数据进行操作;
所述源服务器,还用于将所述标准SQL语句封装成订阅消息并发送至kafka集群;
所述kafka集群,用于在接收到所述订阅消息后,向各目标服务器进行广播;及
所述目标服务器,用于在获得所述订阅消息后,对所述订阅消息进行解封装得到所述标准SQL语句,执行所述标准SQL语句,以将所述源数据库中发送变化的数据同步至目标数据库。
本申请的一个或多个实施例的细节在下面的附图和描述中提出。本申请的其它特征和优点将从说明书、附图以及权利要求书变得明显。
附图说明
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。
图1为根据一个或多个实施例中数据库之间的数据同步方法的应用场景图;
图2为根据一个或多个实施例中数据库之间的数据同步方法的流程示意图;
图3为根据一个或多个实施例中kafka集群分区存储的示意图;
图4为根据一个或多个实施例中数据库之间的数据同步系统的结构框图;
图5为根据另一个或多个实施例中数据库之间的数据同步系统的结构框图。
具体实施方式
为了使本申请的技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。
本申请提供的数据库之间的数据同步方法,可以应用于如图1所示的应用环境中。其中,源服务器110、kafka集群120、目标服务器130、第一终端140和第二终端150之间可以通过网络进行通信。源服务器110读取源数据库的日志文件,并将日志文件解析成可识别文本;源服务器110从可识别文本中筛选SQL语句,并将获得的SQL语句转换成标准SQL语句;源服务器110将标准SQL语句封装成订阅消息并发送至kafka集群;kafka集群120在接收到订阅消息后,向各目标服务器130进行广播;目标服务器130在获得订阅消息后,对订阅消息进行解封装得到标准SQL语句,执行标准SQL语句,以将源数据库中发送变化的数据同步至目标数据库。此外,第一终端140和第二终端150可以分别从源服务器110和目标服务器130获取数据,以进行相应的业务交互,如获取保险业务数据以办理保险业务等。其中,第一终端140和第二终端150可以但不限于是各种个人计算机、笔记本电脑、智能手机和平板电脑等。源服务器110、kafka集群120和目标服务器130分别可以用独立的服务器或者是多个服务器组成的服务器集群来实现。
在其中一个实施例中,如图2所示,提供了一种数据库之间的数据同步方法,该包括以下步骤:
S202,源服务器读取源数据库的日志文件,并将日志文件解析成可识别文本。
上述源数据库可以是mySQL、Oracle或postgreSQL等数据库。日志文件可以是二进制的binlog日志文件。在binlog日志文件中保存了所有的对数据库的 操作,如查询、更新、插入、增加和删除数据表等与数据库相关的操作。此外,binlog日志文件中还会记录操作的数据和数据的类型。
在其中一个实施例中,源服务器可以通过canal读取源数据库的日志文件。其中,canal可以模拟数据库的slave交互协议,伪装为数据库的一个slaver,然后便可读取源数据库的日志文件。
在其中一个实施例中,由于日志文件是二进制的,源服务器可以将二进制的日志文件解析成用户可识别的文件,从而可以得到用户可识别的、关于数据库操作的SQL(Structured Query Language,结构化查询语言)语句。
在其中一个实施例中,源服务器中包括有翻译器,其中,翻译器分为分析器(analyzer)和转换器(convertor)两个部分。源服务器可以通过analyzer将binlog日志文件解析成可识别文本。
在其中一个实施例中,S202具体可以包括:当源数据库中的数据发生变化,或满足预设的同步时间要求时,源服务器通过canal读取源数据库的日志文件。其中,预设的同步时间可以是每隔几秒钟、几分钟或其它间隔时间。
在其中一个实施例中,源服务器可以同步源数据库中发生变化的数据,也可以同步源数据库中的所有数据。当同步源数据库中所有的数据时,源服务器按照配置文件中的配置信息,使canal从起始点开始读取binlog日志。当只同步源数据库中发生变化的数据时,源服务器按照配置文件中的配置信息,使canal按照数据的保存时间读取binlog日志,得到binlog日志文件。然后,源服务器通过analyzer把读取到的二进制binlog日志文件解析成用户可识别文本。
S204,源服务器从可识别文本中筛选SQL语句,并将获得的SQL语句转换成标准SQL语句;筛选的SQL语句用于对数据库中发生变化的数据进行操作。
标准SQL语句至少包括以下之一:标准的新增语句、标准的插入语句和标准的删除语句。
在其中一个实施例中,筛选的SQL语句可以是:令数据库中的数据发生变化的SQL语句,例如至少包括以下之一:新增语句、插入语句和删除语句;S204具体可以包括:源服务器获取与新增语句、插入语句和/或删除语句对应的关键词;源服务器从可识别文本中筛选与关键词匹配的SQL语句,或者,将可识别 文本中与关键词不匹配的SQL语句进行过滤,得到筛选的SQL语句,并将获得的SQL语句转换成标准SQL语句。
上述新增语句可以是增添数据的语句和修改数据的语句等。
例如,新增语句、插入语句和删除语句中包括add、alter、drop、modify等用于操作数据库的关键词。源服务器在可识别文本中筛选与add、alter、drop、modify等关键词匹配的、且对数据库中发生变化的数据进行操作的SQL语句;或者,源服务器在可识别文本中,将与add、alter、drop、modify等关键词不匹配的SQL语句进行过滤,得到对数据库中发生变化的数据进行操作的SQL语句。
又例如,由于select查询语句不会使数据库中的数据发生变化,在进行数据同步的过程中,可以将select查询语句过滤掉。
在其中一个实施例中,源服务器还可以通过analyzer过滤其中不是操作业务表的数据,如非SQL语句。
在其中一个实施例中,源服务器通过convertor将源数据库的SQL语句翻译成标准的SQL语句。其中,标准的SQL语句可以在其它不同类型的数据库中执行,这是本系统可以在不同数据库之间同步数据的关键。
S206,源服务器将标准SQL语句封装成订阅消息并发送至kafka集群。
在其中一个实施例中,源服务器可以通过SQL_producer,将标准SQL语句封装成订阅消息并发送至kafka集群。由于kafka的发布订阅机制,使得kafka集群中一有订阅消息马上就会被目标服务器感知到,即刻用SQL_consumer(kafka的消费者)连接数据库执行SQL,所以是实时的。
SQL_producer可以是由java开发的kafka集群的生产者,源服务器可以通过SQL_producer将SQL语句组装成kafka集群的订阅消息,然后将组装的订阅消息并发送至kafka集群。
在其中一个实施例中,源服务器通过指定分区的方式,将订阅消息发送至kafka集群中所指定的分区;或者,源服务器通过均衡策略的方式,将订阅消息发送至kafka集群中对应不同的分区。
例如,如图3所示,在发送订阅消息时,源服务器确定采用指定分区的方式或均衡策略的方式,又或者是随机均衡的方式。然后,源服务器按照指定分 区的方式,将订阅消息发送至kafka集群中所指定的分区;或者,按照均衡策略的方式,将订阅消息发送至kafka集群中对应不同的分区;又或者,按照随机均衡的方式,将订阅消息随机发送至kafka集群中的分区。
S208,kafka集群在接收到订阅消息后,向各目标服务器进行广播。
S210,目标服务器在获得订阅消息后,对订阅消息进行解封装得到标准SQL语句,执行标准SQL语句,以将源数据库中发送变化的数据同步至目标数据库。
在其中一个实施例中,目标服务器在在接收到广播后,通过SQL_consumer消费订阅消息,在消费到订阅消息后,与目标数据库建立连接,对订阅消息进行解封装得到标准SQL语句,执行标准SQL语句,以将源数据库中发送变化的数据同步至目标数据库。
在其中一个实施例中,目标服务器将SQL_consumer与kafka集群建立长连接,通过所建立的长连接不断地从kafka集群中拉取订阅消息,然后对这些订阅消息进行消费。SQL_consumer在消费者消费订阅消息时,kafka也会通过offset来记录当前消费的位置,两个不同的SQL_consumer同时消费订阅消息是,消费的记录位置offset互不干扰。
在其中一个实施例中,对于SQL_consumer而言,它需要保存所消费的订阅消息的偏移量(offset),当consumer正常消费订阅消息时,offset将会"线性"的向前驱动,即订阅消息将依顺序被消费。
在其中一个实施例中,标准SQL语句,至少包括以下之一:标准的新增语句、标准的插入语句和标准的删除语句;S210中执行标准SQL语句,以使业务数据从源数据库同步至目标数据库包括:目标服务器执行标准的新增语句,以将源数据库中更新的业务数据同步更新至目标数据库;和/或,目标服务器执行标准的插入语句,以将源数据库中插入的业务数据同步插入至目标数据库;和/或,目标服务器执行标准的删除语句,以删除目标数据库中与源数据库中被删除的业务数据相对应的数据。
例如,若同步源数据库中发生变化的数据(即增量数据),在执行标准SQL语句时,获取增量数据以及该增量数据在目标数据库中的第一字段标识,按照第一字段标识将增量数据同步至目标数据库的相应字段内;若同步源数据库中 的删除数据,在执行标准SQL语句时,根据所删除数据的字段确定目标数据库中的第二字段标识,按照第二字段标识删除目标数据库中相应字段的数据,从而实现数据同步。
在其中一个实施例中,zookeeper系统监控源服务器、kafka集群和目标服务器的工作状态,根据工作状态生成状态列表,以便根据状态列表从源服务器、kafka集群和目标服务器中查找出现异常的设备。
其中,zookeeper系统是管理集群的工具,可用于管理kafka集群、SQL_producer和SQL_consumer,监控kafka集群、SQL_producer和SQL_consumer的工作状态,确定工作状态是否正常。工作状态可以是源服务器、kafka集群和目标服务器是否正常工作的状态信息,如处理任务的耗时长(如处理任务的耗时大于预设阈值)、或者宕机等。
例如,zookeeper系统监控源服务器的工作状态,根据该工作状态确定源服务器处理任务的耗时长或出现宕机的情况时,则确定源服务器出现异常。同理也可确定kafka集群和目标服务器是否出现异常。
上述实施例中,日志文件中记载了关于源数据库的所有数据操作,源服务器将日志文件解析为可识别文本,从可识别文本中筛选筛选的SQL语句,并将该SQL语句转换成标准SQL语句,由于标准SQL语句可以支持多种类型数据库的数据操作,从而实现在不同数据库集群之间进行数据实时同步。
此外,通过上述实施例,还可以具有以下有益效果:
管理运维方便:自定义的SQL_producer、canal、SQL_consumer和convertor为纯java开发的系统,运维方便,对应的实体设备(如源服务器、kafka集群)及服务的运行状况都可以由zookeeper来监控。
异地机房同步:相比于mySQL或者Oracle等异地长距离机房的复制效率,采用本申请的实施例,将数据的回放拆散成了日志解析、分析日志、生成SQL语句、封装消息、传输消息和消费消息等步骤,每个步骤都可以部署多台机器提升性能,进而提升整个系统的性能。
跨不同数据库之间:由于将数据库操作通过转换器转换成了标准的SQL语言,从而可以实现在不同数据库之间进行数据的同步。
应该理解的是,虽然图2的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,这些步骤可以以其它的顺序执行。而且,图2中的至少一部分步骤可以包括多个子步骤或者多个阶段,这些子步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,这些子步骤或者阶段的执行顺序也不必然是依次进行,而是可以与其它步骤或者其它步骤的子步骤或者阶段的至少一部分轮流或者交替地执行。
在其中一个实施例中,如图4所示,提供了一种数据库之间的数据同步系统,包括:源服务器402、kafka集群404和目标服务器406,其中:
源服务器402,用于读取源数据库的日志文件,并将日志文件解析成可识别文本。
上述源数据库可以是mySQL、Oracle或postgreSQL等数据库。日志文件可以是二进制的binlog日志文件。在binlog日志文件中保存了所有的对数据库的操作,如查询、更新、插入、增加和删除数据表等与数据库相关的操作。此外,binlog日志文件中还会记录操作的数据和数据的类型。
在其中一个实施例中,源服务器402,还用于可以通过canal读取源数据库的日志文件。其中,canal可以模拟数据库的slave交互协议,伪装为数据库的一个slaver,然后便可读取日志文件。
在其中一个实施例中,由于日志文件是二进制的,源服务器402,还用于可以将二进制的日志文件解析成用户可识别的文件,从而可以得到用户可识别的、关于数据库操作的SQL(Structured Query Language,结构化查询语言)语句。
在其中一个实施例中,源服务器402包括翻译器,翻译器分为分析器和转换器两部分;其中,筛选的SQL语句,至少包括以下之一:新增语句、插入语句和删除语句;
分析器,用于分别获取与新增语句、插入语句和/或删除语句对应的关键词;从可识别文本中筛选与关键词匹配的SQL语句,或者,将可识别文本中与关键词不匹配的SQL语句进行过滤,得到筛选的SQL语句;
转换器,用于将获得的SQL语句转换成标准SQL语句。
在其中一个实施例中,当源数据库中的数据发生变化时,或者,在达到预设的同步时间时,源服务器402,还用于通过canal读取源数据库的日志文件。
在其中一个实施例中,源服务器402,还用于可以同步源数据库中发生变化的数据,也可以同步源数据库中的所有数据。当同步源数据库中所有的数据时,源服务器402还用于按照配置文件中的配置信息,使canal从起始点开始读取binlog日志。当只同步源数据库中发生变化的数据时,源服务器402还用于按照配置文件中的配置信息,使canal按照数据的保存时间读取binlog日志,得到binlog日志文件。然后,源服务器402,还用于通过analyzer把读取到的二进制binlog日志文件解析成用户可识别文本。
源服务器402,还用于从可识别文本中筛选SQL语句,并将获得的SQL语句转换成标准SQL语句;筛选的SQL语句用于对数据库中发生变化的数据进行操作。
其中,标准SQL语句,至少包括以下之一:标准的新增语句、标准的插入语句和标准的删除语句。
在其中一个实施例中,筛选的SQL语句可以是:令数据库中的数据发生变化的SQL语句,例如至少包括以下之一:新增语句、插入语句和删除语句;源服务器402具体用于:获取与新增语句、插入语句和/或删除语句对应的关键词;从可识别文本中筛选与关键词匹配的SQL语句,或者,将可识别文本中与关键词不匹配的SQL语句进行过滤,得到筛选的SQL语句,并将获得的SQL语句转换成标准SQL语句。
上述新增语句可以是增添数据的语句和修改数据的语句等。
例如,新增语句、插入语句和删除语句中包括add、alter、drop、modify等用于操作数据库的关键词。源服务器402还用于在可识别文本中筛选与add、alter、drop、modify等关键词匹配的、且对数据库中发生变化的数据进行操作的SQL语句;或者,源服务器402还用于在可识别文本中,将与add、alter、drop、modify等关键词不匹配的SQL语句进行过滤,得到对数据库中发生变化的数据进行操作的SQL语句。
又例如,由于select查询语句不会使数据库中的数据发生变化,在进行数据同步的过程中,可以将select查询语句过滤掉。
在其中一个实施例中,源服务器402,还用于通过analyzer过滤其中不是操作业务表的数据,如非SQL语句。
在其中一个实施例中,源服务器402,还用于通过convertor将源数据库的SQL语句翻译成标准的SQL语句。其中,标准的SQL语句可以在其它不同类型的数据库中执行,这是本系统可以在不同数据库之间同步数据的关键。
源服务器402,还用于将标准SQL语句封装成订阅消息并发送至kafka集群404。
在其中一个实施例中,源服务器402还用于通过SQL_producer,将标准SQL语句封装成订阅消息并发送至kafka集群404。由于kafka的发布订阅机制,使得kafka集群404中一有订阅消息马上就会被目标服务器感知到,即刻用SQL_consumer(kafka的消费者)连接数据库执行SQL,所以是实时的。
其中,SQL_producer可以是由java开发的kafka集群404的生产者,源服务器402,还用于通过SQL_producer将SQL语句组装成kafka集群404的订阅消息,然后将组装的订阅消息并发送至kafka集群404。
在其中一个实施例中,源服务器402,还用于通过指定分区的方式,将订阅消息发送至kafka集群404中所指定的分区;或者,通过均衡策略的方式,将订阅消息发送至kafka集群404中对应不同的分区。
例如,如图3所示,在发送订阅消息时,源服务器402确定采用指定分区的方式或均衡策略的方式,又或者是随机均衡的方式。然后,源服务器402按照指定分区的方式,将订阅消息发送至kafka集群404中所指定的分区;或者,按照均衡策略的方式,将订阅消息发送至kafka集群404中对应不同的分区;又或者,按照随机均衡的方式,将订阅消息随机发送至kafka集群404中的分区。
kafka集群404,用于在接收到订阅消息后,向各目标服务器406进行广播。
目标服务器406,用于在获得订阅消息后,对订阅消息进行解封装得到标准SQL语句,执行标准SQL语句,以将源数据库中发送变化的数据同步至目标数据库。
在其中一个实施例中,目标服务器406,还用于在在接收到广播后,通过SQL_consumer消费订阅消息,在消费到订阅消息后,与目标数据库建立连接,对订阅消息进行解封装得到标准SQL语句,执行标准SQL语句,以将源数据库中发送变化的数据同步至目标数据库。
在其中一个实施例中,目标服务器406还用于将SQL_consumer与kafka集群404建立长连接,通过所建立的长连接不断地从kafka集群404中拉取订阅消息,然后对这些订阅消息进行消费。SQL_consumer在消费者消费订阅消息时,kafka也会通过offset来记录当前消费的位置,两个不同的SQL_consumer同时消费订阅消息是,消费的记录位置offset互不干扰。
在其中一个实施例中,对于SQL_consumer而言,它需要保存所消费的订阅消息的偏移量(offset),当consumer正常消费订阅消息时,offset将会"线性"的向前驱动,即订阅消息将依顺序被消费。
在其中一个实施例中,标准SQL语句至少包括以下之一:标准的新增语句、标准的插入语句和标准的删除语句;目标服务器406,具体用于执行标准的新增语句,以将源数据库中更新的业务数据同步更新至目标数据库;和/或,执行标准的插入语句,以将源数据库中插入的业务数据同步插入至目标数据库;和/或,执行标准的删除语句,以删除目标数据库中与源数据库中被删除的业务数据相对应的数据。
例如,若同步源数据库中发生变化的数据(即增量数据),在执行标准SQL语句时,获取增量数据以及该增量数据在目标数据库中的第一字段标识,按照第一字段标识将增量数据同步至目标数据库的相应字段内;若同步源数据库中的删除数据,在执行标准SQL语句时,根据所删除数据的字段确定目标数据库中的第二字段标识,按照第二字段标识删除目标数据库中相应字段的数据,从而实现数据同步。
在其中一个实施例中,如图5所示,数据同步系统还包括zookeeper系统408;其中:zookeeper系统408用于监控源服务器402、kafka集群404和目标服务器406的工作状态,根据工作状态生成状态列表,以便根据状态列表从源服务器、kafka集群和目标服务器中查找出现异常的设备。
其中,zookeeper系统408是管理集群的工具,可用于管理kafka集群404、SQL_producer和SQL_consumer,监控kafka集群404、SQL_producer和SQL_consumer的工作状态,确定工作状态是否正常。工作状态可以是源服务器、kafka集群和目标服务器是否正常工作的状态信息,如处理任务的耗时长(如处理任务的耗时大于预设阈值)、或者宕机等。
例如,zookeeper系统监控源服务器的工作状态,根据该工作状态确定源服务器处理任务的耗时长或出现宕机的情况时,则确定源服务器出现异常。同理也可确定kafka集群和目标服务器是否出现异常。
上述实施例中,日志文件中记载了关于源数据库的所有数据操作,源服务器将日志文件解析为可识别文本,从可识别文本中筛选筛选的SQL语句,并将该SQL语句转换成标准SQL语句,由于标准SQL语句可以支持多种类型数据库的数据操作,从而实现在不同数据库集群之间进行数据实时同步,进而可以确保业务的正常运行。
此外,通过上述实施例,还可以具有以下有益效果:
管理运维方便:自定义的SQL_producer、canal、SQL_consumer和convertor为纯java开发的系统,运维方便,对应的实体设备(如源服务器、kafka集群)及服务的运行状况都可以由zookeeper来监控。
异地机房同步:相比于mySQL或者Oracle等异地长距离机房的复制效率,采用本申请的实施例,将数据的回放拆散成了日志解析、分析日志、生成SQL语句、封装消息、传输消息和消费消息等步骤,每个步骤都可以部署多台机器提升性能,进而提升整个系统的性能。
跨不同数据库之间:由于将数据库操作通过转换器转换成了标准的SQL语言,从而可以实现在不同数据库之间进行数据的同步。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一非易失性计算机可读取存储介质中,该计算机程序在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、 存储、数据库或其它介质的任何引用,均可包括非易失性和/或易失性存储器。非易失性存储器可包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双数据率SDRAM(DDRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)等。
以上实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。
以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请专利的保护范围应以所附权利要求为准。

Claims (20)

  1. 一种数据库之间的数据同步方法,所述方法包括:
    源服务器读取源数据库的日志文件,并将所述日志文件解析成可识别文本;
    所述源服务器从所述可识别文本中筛选SQL语句,并将获得的SQL语句转换成标准SQL语句;筛选的所述SQL语句用于对数据库中发生变化的数据进行操作;
    所述源服务器将所述标准SQL语句封装成订阅消息并发送至kafka集群;
    所述kafka集群在接收到所述订阅消息后,向各目标服务器进行广播;及
    所述目标服务器在获得所述订阅消息后,对所述订阅消息进行解封装得到所述标准SQL语句,执行所述标准SQL语句,以将所述源数据库中发送变化的数据同步至目标数据库。
  2. 根据权利要求1所述的方法,其特征在于,所述SQL语句至少包括以下之一:新增语句、插入语句和删除语句;所述从所述可识别文本中筛选SQL语句,并将获得的SQL语句转换成标准SQL语句包括:
    所述源服务器获取与所述新增语句、插入语句和删除语句中至少一种语句对应的关键词;及
    所述源服务器从所述可识别文本中筛选与所述关键词匹配的SQL语句,或者,将所述可识别文本中与所述关键词不匹配的SQL语句进行过滤,得到筛选的SQL语句,并将获得的SQL语句转换成标准SQL语句。
  3. 根据权利要求1所述的方法,其特征在于,所述标准SQL语句包括标准的新增语句;
    所述执行所述标准SQL语句,以使所述业务数据从所述源数据库同步至目标数据库包括:
    所述目标服务器执行所述标准的新增语句,以将所述源数据库中更新的业务数据同步更新至目标数据库。
  4. 根据权利要求1所述的方法,其特征在于,所述标准SQL语句包括标准的插入语句;
    所述执行所述标准SQL语句,以使所述业务数据从所述源数据库同步至目 标数据库包括:
    所述目标服务器执行所述标准的插入语句,以将所述源数据库中插入的业务数据同步插入至目标数据库。
  5. 根据权利要求1所述的方法,其特征在于,所述标准SQL语句包括标准的删除语句;
    所述执行所述标准SQL语句,以使所述业务数据从所述源数据库同步至目标数据库包括:
    所述目标服务器执行所述标准的删除语句,以删除目标数据库中与所述源数据库中被删除的业务数据相对应的数据。
  6. 根据权利要求1至5任一项所述的方法,其特征在于,还包括:
    所述源服务器通过指定分区的方式,将所述订阅消息发送至所述kafka集群中所指定的分区。
  7. 根据权利要求1至5任一项所述的方法,其特征在于,还包括:
    所述源服务器通过均衡策略的方式,将所述订阅消息发送至所述kafka集群中对应不同的分区。
  8. 根据权利要求1至5任一项所述的方法,其特征在于,还包括:
    zookeeper系统监控所述源服务器、所述kafka集群和所述目标服务器的工作状态,根据所述工作状态生成状态列表,以便根据所述状态列表从所述源服务器、所述kafka集群和所述目标服务器中查找出现异常的设备。
  9. 根据权利要求1至5任一项所述的方法,其特征在于,所述源服务器读取源数据库的日志文件包括:
    当源数据库中的数据发生变化,或满足预设的同步时间要求时,所述源服务器通过canal模拟所述数据库的slave交互协议,按照所述slave交互协议读取源数据库的日志文件。
  10. 根据权利要求1至5任一项所述的方法,其特征在于,所述日志文件为binlog日志文件;
    所述将所述日志文件解析成可识别文本包括:
    所述源服务器通过analyzer将所述binlog日志文件解析成可识别文本。
  11. 一种数据库之间的数据同步系统,所述系统包括:
    源服务器,用于读取源数据库的日志文件,并将所述日志文件解析成可识别文本;
    所述源服务器,还用于从所述可识别文本中筛选SQL语句,并将获得的SQL语句转换成标准SQL语句;筛选的所述SQL语句用于对数据库中发生变化的数据进行操作;
    所述源服务器,还用于将所述标准SQL语句封装成订阅消息并发送至kafka集群;
    所述kafka集群,用于在接收到所述订阅消息后,向各目标服务器进行广播;及
    所述目标服务器,用于在获得所述订阅消息后,对所述订阅消息进行解封装得到所述标准SQL语句,执行所述标准SQL语句,以将所述源数据库中发送变化的数据同步至目标数据库。
  12. 根据权利要求11所述的系统,其特征在于,所述源服务器包括分析器和转换器;所述SQL语句至少包括以下之一:新增语句、插入语句和删除语句;
    所述分析器,用于分别获取与所述新增语句、插入语句和删除语句中至少一种语句对应的关键词;及
    从所述可识别文本中筛选与所述关键词匹配的SQL语句,或者,将可识别文本中与所述关键词不匹配的SQL语句进行过滤,得到筛选的SQL语句;
    所述转换器,用于将获得的SQL语句转换成标准SQL语句。
  13. 根据权利要求11所述的系统,其特征在于,所述标准SQL语句包括标准的新增语句;
    所述目标服务器还用于执行所述标准的新增语句,以将所述源数据库中更新的业务数据同步更新至目标数据库。
  14. 根据权利要求11所述的系统,其特征在于,所述标准SQL语句包括标准的插入语句;
    所述目标服务器还用于执行所述标准的插入语句,以将所述源数据库中插入的业务数据同步插入至目标数据库。
  15. 根据权利要求11所述的系统,其特征在于,所述标准SQL语句包括标准的删除语句;
    所述目标服务器还用于执行所述标准的删除语句,以删除目标数据库中与所述源数据库中被删除的业务数据相对应的数据。
  16. 根据权利要求11至15任一项所述的系统,其特征在于,所述目标服务器还用于:
    通过指定分区的方式,将所述订阅消息发送至所述kafka集群中所指定的分区。
  17. 根据权利要求11至15任一项所述的系统,其特征在于,所述目标服务器还用于:
    通过均衡策略的方式,将所述订阅消息发送至所述kafka集群中对应不同的分区。
  18. 根据权利要求11至15任一项所述的系统,其特征在于,还包括:
    zookeeper系统,用于监控所述源服务器、所述kafka集群和所述目标服务器的工作状态,根据所述工作状态生成状态列表,以便根据所述状态列表从所述源服务器、所述kafka集群和所述目标服务器中查找出现异常的设备。
  19. 根据权利要求11至15任一项所述的系统,其特征在于,
    所述源服务器,还用于当源数据库中的数据发生变化,或满足预设的同步时间要求时,通过canal模拟所述数据库的slave交互协议,按照所述slave交互协议读取源数据库的日志文件。
  20. 根据权利要求11至15任一项所述的系统,其特征在于,所述日志文件为binlog日志文件;
    所述源服务器,还用于通过analyzer将所述binlog日志文件解析成可识别文本。
PCT/CN2019/116998 2019-01-16 2019-11-11 数据库之间的数据同步方法和系统 WO2020147392A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910040361.1 2019-01-16
CN201910040361.1A CN109960710B (zh) 2019-01-16 2019-01-16 数据库之间的数据同步方法和系统

Publications (1)

Publication Number Publication Date
WO2020147392A1 true WO2020147392A1 (zh) 2020-07-23

Family

ID=67023551

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/116998 WO2020147392A1 (zh) 2019-01-16 2019-11-11 数据库之间的数据同步方法和系统

Country Status (2)

Country Link
CN (1) CN109960710B (zh)
WO (1) WO2020147392A1 (zh)

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111913853A (zh) * 2020-08-14 2020-11-10 中消云(北京)物联网科技研究院有限公司 基于Canal的数据处理方法及装置
CN112416710A (zh) * 2020-11-19 2021-02-26 京东数字科技控股股份有限公司 用户操作的记录方法、装置、电子设备及存储介质
CN112416944A (zh) * 2020-12-03 2021-02-26 云知声智能科技股份有限公司 一种同步业务数据的方法和设备
CN112948491A (zh) * 2021-02-26 2021-06-11 平安普惠企业管理有限公司 数据同步的方法、装置、终端设备及计算机可读存储介质
CN113407638A (zh) * 2021-07-16 2021-09-17 上海通联金融服务有限公司 实现实时关系型数据库数据同步的方法
CN113505173A (zh) * 2021-07-08 2021-10-15 上海卓钢链科技有限公司 一种数据采集同步系统与同步方法
CN113590639A (zh) * 2021-07-30 2021-11-02 浙江中控技术股份有限公司 一种网闸隔离的数据库之间数据同步方法
CN113810456A (zh) * 2021-02-09 2021-12-17 京东科技信息技术有限公司 数据获取方法、装置、系统、计算机设备及存储介质
CN113849351A (zh) * 2021-09-30 2021-12-28 紫光云技术有限公司 一种MySQL高可用性的实现方法
CN115391361A (zh) * 2022-08-24 2022-11-25 国任财产保险股份有限公司 一种基于分布式数据库的实时数据处理方法及其装置
CN116032849A (zh) * 2022-12-22 2023-04-28 中国电信股份有限公司 数据交换的方法、装置、系统及电子设备
CN117171268A (zh) * 2023-08-31 2023-12-05 深圳麦风科技有限公司 新老系统的数据同步方法、设备及存储介质

Families Citing this family (23)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109960710B (zh) * 2019-01-16 2023-04-11 平安科技(深圳)有限公司 数据库之间的数据同步方法和系统
CN110334156A (zh) * 2019-07-10 2019-10-15 北京启迪区块链科技发展有限公司 一种数据库同步方法、装置、服务器和存储介质
CN110392104B (zh) * 2019-07-18 2022-06-10 腾讯科技(深圳)有限公司 数据同步方法、系统、服务器及存储介质
CN110532275A (zh) * 2019-08-09 2019-12-03 国云科技股份有限公司 一种跨域数据和文件更新同步的实现方法
CN110569142A (zh) * 2019-08-29 2019-12-13 天津大学 一种oracle数据增量同步系统及方法
CN110865974B (zh) * 2019-09-27 2023-01-10 苏州浪潮智能科技有限公司 一种基于kafka智能加载离线SQL表数据的方法
CN111125214B (zh) * 2019-12-02 2023-08-25 武汉虹信技术服务有限责任公司 一种轻量级增量数据同步方法、装置及计算机可读介质
CN111177254B (zh) * 2019-12-05 2021-08-17 武汉达梦数据库股份有限公司 一种异构关系型数据库之间数据同步的方法和装置
CN111049898A (zh) * 2019-12-10 2020-04-21 杭州东方通信软件技术有限公司 一种实现计算集群资源跨域架构的方法及系统
CN111125065B (zh) * 2019-12-24 2023-09-12 阳光人寿保险股份有限公司 可视化数据同步方法、系统、终端和计算机可读存储介质
US11461315B2 (en) 2020-12-03 2022-10-04 International Business Machines Corporation Batch job performance improvement in active-active architecture
CN112632183B (zh) * 2020-12-11 2023-07-11 广东电力通信科技有限公司 一种基于电网网络分区数据表准实时同步方法及系统
CN112988897A (zh) * 2021-03-30 2021-06-18 工银科技有限公司 系统升级场景下的数据双向同步方法及装置
CN113468170B (zh) * 2021-06-02 2024-06-14 上海赛可出行科技服务有限公司 一种自动化实现数据实时同步的系统
CN113709250B (zh) * 2021-08-31 2023-09-15 中国电子科技集团公司第二十八研究所 一种基于订阅发送模式的跨域用户数据同步方法
CN113656427B (zh) * 2021-10-20 2022-02-08 腾讯科技(深圳)有限公司 数据同步方法及相关设备
CN113656511B (zh) * 2021-10-20 2022-02-18 天津南大通用数据技术股份有限公司 一种基于源库不停机的异构数据库增量同步方法及系统
CN113934744A (zh) * 2021-12-17 2022-01-14 南京云联数科科技有限公司 一种数据共享的方法及设备
CN114385737A (zh) * 2022-03-24 2022-04-22 国能大渡河流域水电开发有限公司 基于变化数据捕捉的电力监控数据监控方法及平台
CN114579671A (zh) * 2022-05-09 2022-06-03 高伟达软件股份有限公司 集群间数据同步方法及装置
CN117312353A (zh) * 2022-06-22 2023-12-29 华为云计算技术有限公司 数据管理的方法、装置、系统及存储介质
CN115391457B (zh) * 2022-08-23 2023-09-12 昆仑数智科技有限责任公司 跨数据库的数据同步方法、装置及存储介质
CN115470302B (zh) * 2022-10-25 2023-05-09 以萨技术股份有限公司 一种基于canal的数据库双向同步方法、介质及设备

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180017345A1 (en) * 2016-07-12 2018-01-18 Fractal Heatsink Technologies, LLC System and method for maintaining efficiency of a heat sink
CN108228621A (zh) * 2016-12-15 2018-06-29 上海祈贝健康管理咨询有限公司 一种异地实时同步sql数据的方法
CN109063196A (zh) * 2018-09-03 2018-12-21 拉扎斯网络科技(上海)有限公司 数据处理方法、装置、电子设备及计算机可读存储介质
CN109960710A (zh) * 2019-01-16 2019-07-02 平安科技(深圳)有限公司 数据库之间的数据同步方法和系统

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103761318B (zh) * 2014-01-27 2017-08-18 中国工商银行股份有限公司 一种关系型异构数据库数据同步的方法及系统

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20180017345A1 (en) * 2016-07-12 2018-01-18 Fractal Heatsink Technologies, LLC System and method for maintaining efficiency of a heat sink
CN108228621A (zh) * 2016-12-15 2018-06-29 上海祈贝健康管理咨询有限公司 一种异地实时同步sql数据的方法
CN109063196A (zh) * 2018-09-03 2018-12-21 拉扎斯网络科技(上海)有限公司 数据处理方法、装置、电子设备及计算机可读存储介质
CN109960710A (zh) * 2019-01-16 2019-07-02 平安科技(深圳)有限公司 数据库之间的数据同步方法和系统

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111913853A (zh) * 2020-08-14 2020-11-10 中消云(北京)物联网科技研究院有限公司 基于Canal的数据处理方法及装置
CN112416710A (zh) * 2020-11-19 2021-02-26 京东数字科技控股股份有限公司 用户操作的记录方法、装置、电子设备及存储介质
CN112416944A (zh) * 2020-12-03 2021-02-26 云知声智能科技股份有限公司 一种同步业务数据的方法和设备
CN113810456A (zh) * 2021-02-09 2021-12-17 京东科技信息技术有限公司 数据获取方法、装置、系统、计算机设备及存储介质
CN112948491B (zh) * 2021-02-26 2023-09-22 湖北华中电力科技开发有限责任公司 数据同步的方法、装置、终端设备及计算机可读存储介质
CN112948491A (zh) * 2021-02-26 2021-06-11 平安普惠企业管理有限公司 数据同步的方法、装置、终端设备及计算机可读存储介质
CN113505173A (zh) * 2021-07-08 2021-10-15 上海卓钢链科技有限公司 一种数据采集同步系统与同步方法
CN113505173B (zh) * 2021-07-08 2024-03-19 上海卓钢链科技有限公司 一种数据采集同步系统与同步方法
CN113407638A (zh) * 2021-07-16 2021-09-17 上海通联金融服务有限公司 实现实时关系型数据库数据同步的方法
CN113590639A (zh) * 2021-07-30 2021-11-02 浙江中控技术股份有限公司 一种网闸隔离的数据库之间数据同步方法
CN113849351A (zh) * 2021-09-30 2021-12-28 紫光云技术有限公司 一种MySQL高可用性的实现方法
CN115391361A (zh) * 2022-08-24 2022-11-25 国任财产保险股份有限公司 一种基于分布式数据库的实时数据处理方法及其装置
CN116032849A (zh) * 2022-12-22 2023-04-28 中国电信股份有限公司 数据交换的方法、装置、系统及电子设备
CN116032849B (zh) * 2022-12-22 2024-05-24 中国电信股份有限公司 数据交换的方法、装置、系统及电子设备
CN117171268A (zh) * 2023-08-31 2023-12-05 深圳麦风科技有限公司 新老系统的数据同步方法、设备及存储介质

Also Published As

Publication number Publication date
CN109960710A (zh) 2019-07-02
CN109960710B (zh) 2023-04-11

Similar Documents

Publication Publication Date Title
WO2020147392A1 (zh) 数据库之间的数据同步方法和系统
CN108536761B (zh) 报表数据查询方法及服务器
TWI628551B (zh) Data library copying method and device based on log parsing
CN109063196B (zh) 数据处理方法、装置、电子设备及计算机可读存储介质
US9875311B2 (en) Collaborative CAx updates
CN109325077A (zh) 一种基于canal和kafka实现实时数仓的系统
CN111831748A (zh) 数据同步方法、装置及存储介质
CN111432025A (zh) 一种面向云边协同的分布式服务目录管理方法及系统
WO2019076236A1 (zh) 数据同步方法、装置、超级控制器、域控制器及存储介质
CN112351068A (zh) 信息同步方法、系统、装置、计算机设备和存储介质
CN112685499A (zh) 一种工作业务流的流程数据同步方法、装置及设备
CN103414762A (zh) 云备份方法和装置
CN103685485A (zh) 移动终端VoIP通讯音频管理系统
CN114996361B (zh) 数据处理方法及系统
CN116846729A (zh) 一种基于云容器下多租户模式管理监控告警通知的方法
CN116467336A (zh) 数据处理方法及装置、电子设备、存储介质
CN115629909A (zh) 业务数据处理的方法、装置、电子设备和存储介质
CN116186053A (zh) 一种数据处理方法、装置及存储介质
CN115757642A (zh) 一种基于归档日志文件的数据同步方法及装置
CN115982133A (zh) 数据处理方法及装置
CN112115206A (zh) 一种处理对象存储元数据的方法和装置
CN113378219B (zh) 一种非结构化数据的处理方法和系统
CN114911872A (zh) 内外网数据同步方法、装置、系统、外网服务器及存储介质
CN114398333A (zh) 一种增量数据实时同步方法、装置、电子设备及存储介质
US20210141791A1 (en) Method and system for generating a hybrid data model

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19910744

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19910744

Country of ref document: EP

Kind code of ref document: A1