An optimization method for implementing CDC based on distributed database
By starting the asynchronous CDC processor in the distributed database and directly outputting the change data to the data pool, it solves the problems of low efficiency and high resource consumption in the existing technology, achieves more efficient change data capture and real-time performance, and improves the system performance.
Patent Information
- Application Number
- CN202010618749.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-01
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-07-01
AI Technical Summary
The existing database CDC implementation in distributed databases has low efficiency and insufficient real-time performance. It also increases the consumption of computing, storage and network resources and reduces system performance.
In the distributed database, by starting the asynchronous CDC processor after the transaction is submitted, the changed data is directly output to the data pool, avoiding temporary table storage and log parsing, and using the data format of JSON or AVRO format to output the changed data point-to-point.
It reduces the occupation of storage space and computing resources, reduces network load, improves the efficiency and real-time performance of change data capture, and improves system performance.
Smart Images

Figure CN111782671B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, in particular to an optimization method for implementing CDC based on a distributed database. Background Art
[0002] CDC (Change Data Capture) is a change data processing technology that can identify changes in data after the last modification, such as addition, update, and deletion. Currently known database CDC implementations mainly use three technologies:
[0003] 1) Capture change data based on triggers and stored procedures:
[0004] This solution creates a trigger on the source table and calls a stored procedure or function to store the change data in a temporary change data table so that other applications can query the captured change data through the CDC query function.
[0005] 2) The background capture process periodically captures and parses incremental transaction logs to capture change data:
[0006] This solution starts a capture process on the database server, regularly captures incremental transaction logs, and stores data related to the incremental logs in a temporary change data table so that other applications can query the captured change data through CDC query functions.
[0007] 3) Analyze the snapshot of the database and find the difference between the old and new snapshots:
[0008] The background capture process creates database snapshots at regular intervals and compares them with the previous old snapshot to find the difference. This method requires large amounts of calculations, is complex to implement, and lacks real-time performance. In addition, it requires saving a large number of snapshots, which consumes a large amount of storage space. For distributed databases and massive data, the efficiency of comparing the old and new snapshots to find the difference is even lower.
[0009] Solutions (1), (2) and (3) all require additional temporary tables to store changed data, which consumes more storage resources and increases IO pressure. In addition, solution (1) uses stored procedures and triggers, which will reduce system performance and is rarely used; solution (2) will also have a permanent capture process in the background to read and parse transaction logs, which requires more computing resources; incremental transaction logs are read and parsed regularly, and real-time performance is not guaranteed. Solution (3) is similar to solution (2), and is even less efficient in the case of distributed databases and massive data. The above three solutions increase the IO pressure of the database server and the consumption of computing resources in the case of a single machine. In a distributed database, network resources are also consumed due to the transmission of data and log files. The above three solutions are mainly used in single-machine databases and are not applicable in distributed databases. Therefore, these three traditional CDC implementations will increase the consumption of computing, storage and network resources, and will also reduce system performance when resources are constant. Especially in the storage of distributed databases and massive data, these three solutions will further reduce system performance, increase resource consumption and reduce real-time performance. Summary of the invention
[0010] In order to improve the efficiency and real-time performance of the existing database CDC and reduce the consumption of computing, storage, network and other resources, the present invention provides an optimization method for implementing CDC based on a distributed database, so that the optimized CDC implementation is more suitable for the distributed database and improves the performance of the database system service.
[0011] The present invention provides an optimization method for implementing CDC based on a distributed database, and the technical solution adopted to solve the above technical problems is as follows:
[0012] An optimization method for implementing CDC based on a distributed database, the execution process of the optimization method includes:
[0013] Step 1: Create a CDC in a distributed database or a table in a distributed database;
[0014] Step 2: The user performs a DML operation and executes the SQL that changes the data. The database service parses the SQL to generate a syntax tree, and then generates an execution plan based on the syntax tree.
[0015] Step 3: The database service sends the execution plan to each execution node for execution;
[0016] Step 4: Each database service node receives the execution plan and executes it. After the plan is executed, the transaction is committed and the changed data is sent to the data pool.
[0017] Furthermore, the specific operations of creating a CDC in step 1 include:
[0018] Step 1.1, first create a CDC statement;
[0019] Step 1.2, then register the CDC's job information to METADATA. The registration information includes the library information, table information, status, and data pool connection information corresponding to the CDC.
[0020] Furthermore, after the execution plan is generated in step 2, the CDC registration information of the operation object should be queried first to determine whether the CDC has been created:
[0021] a) If CDC is not created, a normal execution plan is generated.
[0022] b) If it is found that the CDC has been created, a CDC processor is generated according to the CDC registration information, and the execution plan and the CDC processor are encapsulated as a derived object of the execution plan.
[0023] Then proceed to step 3 to send the normal execution plan or the derived object of the execution plan to each execution node for execution.
[0024] Furthermore, during step 4, after the transaction is committed:
[0025] If a CDC processor exists, start the asynchronous CDC processor and send the data to the data pool.
[0026] If no CDC processor exists, the data is sent directly to the data sink.
[0027] Furthermore, the asynchronous CDC processor is started to send the data to the data pool. The specific operations of this process are:
[0028] 1) Capture change data,
[0029] 2) Generate data in a certain format according to the DML operation type.
[0030] 3) Connect to the external data pool and output the changed data to the external data pool.
[0031] Preferably, the data pool may be a file server, a file or other message queue type middleware.
[0032] Preferably, the format of the data can be JSON or AVRO.
[0033] Furthermore, when the data is in JSON format and the DML operation type executed is add or update, the output data is the entire row of data after the addition or update. The data format captured and output to the data pool by CDC is as follows:
[0034] {
[0035] "updated": <data row update timestamp>,
[0036] “pk”: <field name 1: the value of field name 1, field name 2: the value of field name 2, …, field name k: the value of field name k>,
[0037] "data":{
[0038] "<field 1 name>":<field 1 data value>,"<field 2 name>":<field 2 data value>,"...,"<field n name>":<field n data value>"
[0039] }
[0040] }.
[0041] Furthermore, when the data is in JSON format and the DML operation type executed is delete, the data format captured and output to the data pool by CDC is as follows:
[0042] {
[0043] "updated": <data row update timestamp>,
[0044] “pk”: <field name 1: the value of field name 1, field name 2: the value of field name 2, …, field name k: the value of field name k>,
[0045] "data":null
[0046] }.
[0047] The optimization method for implementing CDC based on a distributed database of the present invention has the following beneficial effects compared with the prior art:
[0048] 1) The optimization method of the present invention is applicable to distributed databases. After the transaction is committed, the CDC JOB is directly started to asynchronously output the change data to the data pool, thereby reducing the storage space occupied, reducing the computing and IO resource occupation, reducing the network load, improving the change data capture efficiency and real-time performance, and improving the system performance;
[0049] 2) The optimization method of the present invention does not need to create a capture process, does not need to parse logs, does not need to store the captured change data in a temporary table, and does not need interoperation between nodes. Instead, the change data is output to the data pool point-to-point. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Attached Figure 1 It is a schematic flow chart of step 1 in the optimization method of the present invention;
[0051] Attached Figure 2It is a schematic flow chart of step 2 to step 4 in the optimization method of the present invention;
[0052] Attached Figure 3 It is a flow chart of executing an asynchronous CDC processor in the optimization method of the present invention. DETAILED DESCRIPTION
[0053] In order to make the technical solution, the technical problem solved and the technical effect of the present invention more clearly understood, the technical solution of the present invention is clearly and completely described below in conjunction with specific embodiments.
[0054] First, let’s explain the nouns involved:
[0055] CDC: Change Data Capture is a change data processing technology for databases that can identify change data after the last modification, such as addition, update, and deletion.
[0056] METADATA: Also known as metadata. It is data that describes other data. Its use is to identify resources, to achieve simple and efficient management of large amounts of networked data, and to achieve effective discovery and search of information resources. Once metadata is established, it can be shared.
[0057] JOB: Asynchronous task. Used to obtain the changed data, assemble it, and send it to the external data pool.
[0058] DML: Data Manipulation Language (DML), through which users can perform basic operations on data in the database, including adding, updating, and deleting operations.
[0059] SQL: Structured Query Language is a special programming language used to access data and query, update and manage relational database systems.
[0060] Embodiment 1:
[0061] This embodiment proposes an optimization method for implementing CDC based on a distributed database. The execution process of the optimization method includes:
[0062] Step 1: Create a CDC in a distributed database or a table in a distributed database. Figure 1 , the specific operations to create a CDC include:
[0063] Step 1.1, first create a CDC statement;
[0064] Step 1.2, then register the CDC's job information to METADATA. The registration information includes the library information, table information, status, and data pool connection information corresponding to the CDC.
[0065] Step 2: The user performs DML operations and executes SQL statements that change data. The database service parses the SQL statements to generate a syntax tree, and then generates an execution plan based on the syntax tree. Figure 2 ,
[0066] After generating the execution plan, you should first query the CDC registration information of the operation object to determine whether the CDC has been created:
[0067] a) If CDC is not created, a normal execution plan is generated.
[0068] b) If it is found that the CDC has been created, a CDC processor is generated according to the CDC registration information, and the execution plan and the CDC processor are encapsulated as a derived object of the execution plan.
[0069] Step 3: Send the normal execution plan or the derived object of the execution plan to each execution node for execution.
[0070] Step 4: Each database service node receives the execution plan and executes it. After the plan is executed, the transaction is committed and then it is determined whether there is a CDC processor.
[0071] If a CDC processor exists, start the asynchronous CDC processor and combine it with the attached Figure 3 , capture the changed data, generate data in a certain format according to the DML operation type, connect to the external data pool, and output the changed data to the external data pool,
[0072] If no CDC processor exists, the data is sent directly to the data sink.
[0073] In this embodiment, the data pool mentioned may be a file server, a file, or other message queue-type middleware.
[0074] In this embodiment, the format of the data may be JSON format or AVRO format.
[0075] Generally speaking, DML operation types include add, update, and delete.
[0076] Specifically,
[0077] I) When the data is in JSON format and the DML operation type is add or update, the output data is the entire row of data after the addition or update. The data format captured and output to the data pool by CDC is as follows:
[0078] {
[0079] "updated": <data row update timestamp>,
[0080] “pk”: <field name 1: the value of field name 1, field name 2: the value of field name 2, …, field name k: the value of field name k>,
[0081] "data":{
[0082] "<field 1 name>":<field 1 data value>,"<field 2 name>":<field 2 data value>,"...,"<field n name>":<field n data value>"
[0083] }
[0084] }.
[0085] II) When the data is in JSON format and the DML operation type is delete, the data format captured and output to the data pool by CDC is as follows:
[0086] {
[0087] "updated": <data row update timestamp>,
[0088] “pk”: <field name 1: the value of field name 1, field name 2: the value of field name 2, …, field name k: the value of field name k>,
[0089] "data":null
[0090] }.
[0091] In summary, the optimization method for implementing CDC based on a distributed database according to the present invention can reduce the occupancy of storage space, reduce the occupancy of computing and IO resources, reduce network load, improve the efficiency and real-time performance of change data capture, and improve system performance.
[0092] The above specific examples are used to explain the principles and implementation methods of the present invention in detail. These examples are only used to help understand the core technical content of the present invention. Based on the above specific embodiments of the present invention, any improvements and modifications made by technicians in this technical field without departing from the principles of the present invention should fall within the scope of patent protection of the present invention.
Claims
1. An optimization method for implementing CDC based on a distributed database, characterized in that ,The execution process of the optimization method includes: Step 1: Create a CDC in a distributed database or a table in a distributed database. The specific operations include: Step 1.1, first create a CDC statement; Step 1.2, then register the CDC's job information to METADATA. The registration information includes the library information, table information, status, and data pool connection information corresponding to the CDC; Step 2: The user performs a DML operation and executes the SQL that changes the data. The database service parses the SQL to generate a syntax tree, and then generates an execution plan based on the syntax tree. It then queries the CDC registration information of the operation object to determine whether the CDC has been created: a) If CDC is not created, a normal execution plan is generated. b) If it is found that the CDC has been created, a CDC processor is generated according to the CDC registration information, and the execution plan and the CDC processor are encapsulated as a derived object of the execution plan, and then step 3 is continued; Step 3: The database service sends the normal execution plan or the derived object of the execution plan to each execution node for execution; Step 4: Each database service node receives the execution plan and executes it. After the plan is executed, the transaction is committed to determine whether there is a CDC processor: If a CDC processor exists, the asynchronous CDC processor is started to send the data to the data pool. The specific operations of this process are: 1) capturing the changed data, 2) generating data in a certain format according to the DML operation type, 3) connecting to the external data pool and outputting the changed data to the external data pool; If no CDC processor exists, the data is sent directly to the data sink.
2. According to the optimization method for implementing CDC based on a distributed database according to claim 1, it is characterized in that: The data pool can be a file server, a file, or other message queue-like middleware.
3. The optimization method for implementing CDC based on a distributed database according to claim 1, characterized in that: The data format can be JSON or AVRO.
4. The optimization method for implementing CDC based on a distributed database according to claim 3, characterized in that: When the data is in JSON format and the DML operation type is add or update, the output data is the entire row of data after the addition or update. The data format captured and output to the data pool by CDC is as follows: { "updated": <data row update timestamp>, "pk": <field name 1: the value of field name 1, field name 2: the value of field name 2, ..., field name k: the value of field name k>, "data":{ "<field 1 name>":<field 1 data value>,"<field 2 name>":<field 2 data value>,"...,"<field n name>":<field n data value>" } }。 5. The optimization method for implementing CDC based on a distributed database according to claim 3, characterized in that: When the data is in JSON format and the DML operation type is delete, the data format captured and output to the data pool by CDC is as follows: { "updated": <data row update timestamp>, "pk": <field name 1: the value of field name 1, field name 2: the value of field name 2, ..., field name k: the value of field name k>, "data":null }。
Citation Information
Patent Citations
Method for storing massive structural data based on relational database
CN104133891A
Block chain data storage and query method, device and equipment and storage medium
CN110309196A
