Data snapshot method, device, equipment and storage medium
The database log files are converted into subscription messages through the Canal component and Kafka, and the snapshot component performs data snapshot processing, which solves the problems in the existing technology of data snapshots affecting business operations and poor disaster tolerance, and achieves efficient data snapshots and recovery.
Patent Information
- Application Number
- CN202010850323.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-21
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2040-08-21
AI Technical Summary
Existing data snapshot technology will affect the normal operation of the business during the snapshot generation process, and the generated snapshots have poor disaster tolerance and cannot be effectively restored.
The database log file is sent to the distributed publish-subscribe messaging system Kafka through the Canal component. Kafka writes the log file to the message partition and generates the subscription message. The snapshot component performs snapshot processing based on the subscription message to achieve data snapshots and perform data recovery when needed. .
It generates data snapshots without affecting the normal operation of the business, and has strong disaster tolerance. It can quickly restore data slices at any point in time, improving scalability and data recovery capabilities.
Smart Images

Figure CN114077518B_ABST
Abstract
Description
Technical Field
[0001] The present invention generally relates to the field of data processing technology, and in particular to a data snapshot method, device, equipment and storage medium. Background Art
[0002] With the continuous development of information technology, the amount of data generated is increasing and the update is getting faster and faster. This also puts high demands on data processing and storage technology. Data snapshot processing is needed to achieve data backup at a certain time point. Data snapshot is a technology that retains the image of data at a certain moment. The retained image is called a snapshot.
[0003] Currently, data snapshots can back up all data in a specified table to another table by executing SQL statements, so that data backup is formed in the new table when SQL commands are executed. Data snapshot backup of a single database and a single table / a single database and multiple tables / multiple databases and multiple tables can also be achieved through the backup file system dump tool that comes with the MySQL database.
[0004] However, when the relevant snapshot processing solution generates a data snapshot, other business operations cannot be carried out normally, which will have a business impact on the full-time non-stop business. If the generated snapshot is damaged, it will be impossible to recover, making the disaster tolerance of snapshot processing poor. Summary of the invention
[0005] In view of the above-mentioned defects or deficiencies in the prior art, it is desirable to provide a data snapshot method, apparatus, device and storage medium.
[0006] In a first aspect, the present application provides a data snapshot method, the method comprising:
[0007] The Canal component sends the log files read from the database to the distributed publish-subscribe messaging system Kafka;
[0008] Kafka writes the log file to the corresponding message partition, generates a subscription message and sends it to the snapshot component;
[0009] When the snapshot triggering condition is met, the snapshot component performs snapshot processing on the log file based on the subscription message to obtain a data snapshot.
[0010] In one embodiment, Kafka writes the log file to the corresponding message partition, generates a subscription message and sends it to the snapshot component, including:
[0011] Kafka hashes the log file according to the pre-configured sharding rules to obtain a hash value;
[0012] Kafka partitions log files according to hash values and stores them in corresponding message partitions;
[0013] Kafka reads the log file corresponding to the message partition and generates subscription messages;
[0014] Kafka sends the subscription message to the snapshot component.
[0015] In one embodiment, the snapshot component performs snapshot processing on the log file based on the subscription message to obtain a data snapshot, including:
[0016] The snapshot component parses and processes the subscription message to obtain a log file corresponding to the subscription message;
[0017] The snapshot component performs snapshot processing on the log file based on the preset configuration file to obtain a data snapshot.
[0018] In one embodiment, the snapshot component includes at least one business processing component and at least one business storage component. The snapshot component performs snapshot processing on the log file based on a preset configuration file to obtain a data snapshot, including:
[0019] The snapshot component determines whether the log file needs to be processed based on a preset configuration file, which includes configuration parameters set under different business processing conditions for the same log file;
[0020] When the log file needs to be processed, obtain the business type corresponding to each business processing component in at least one business processing component;
[0021] The log files are processed based on the business type to obtain a data snapshot corresponding to each business processing component.
[0022] In one embodiment, after the snapshot component determines whether the log file needs to be processed based on a preset configuration file, the method further includes:
[0023] When the log file does not need to be processed, obtaining a storage format corresponding to each business storage component in at least one business storage component;
[0024] The log file is processed according to the storage format to obtain a data snapshot corresponding to each business storage component.
[0025] In one embodiment, the snapshot component further includes a master node component. After Kafka sends a subscription message to the snapshot component, the method further includes:
[0026] Based on the subscription message, the log file corresponding to the subscription message is stored in the master node component to perform data backup on the log file.
[0027] In one of the embodiments, after backing up the log file, the method further includes:
[0028] The business component receives a data recovery request, the data recovery request includes a data recovery time point and a snapshot data identifier, and the business component is a business processing component or a business storage component;
[0029] The business component obtains snapshot data from the master node component based on the snapshot data identifier. The snapshot data includes the data set and the position offset corresponding to each message partition.
[0030] The business component loads the data set into the work table and resets the position offset corresponding to each message partition;
[0031] The business component sets the snapshot trigger time as the data recovery time point and consumes message data from Kafka;
[0032] When the snapshot trigger time is reached, the business component stops consuming Kafka message data to obtain the data snapshot corresponding to the data recovery time point.
[0033] In a second aspect, the present application provides a data snapshot device, the device comprising:
[0034] The sending module is used by the Canal component to send the log files read from the database to the distributed publish-subscribe messaging system Kafka;
[0035] The partition module is used for the kafka to write the log file into the corresponding partition message partition, generate a subscription message and send it to the snapshot component;
[0036] The snapshot generation module is used for obtaining a data snapshot by the snapshot component performing snapshot processing on the log file based on the subscription message when the snapshot trigger time is reached.
[0037] In a third aspect, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the data snapshot method of the first aspect is implemented.
[0038] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program is used to implement the data snapshot method of the first aspect.
[0039] The data snapshot method, device, equipment and storage medium provided in the embodiment of the present application send the log file read from the database to the distributed publish-subscribe message system kafka through the Canal component, and kafka writes the log file to the corresponding message partition, generates a subscription message and sends it to the snapshot component. When the snapshot trigger condition is met, the snapshot component performs snapshot processing on the log file based on the subscription message to generate a data snapshot. In this technical solution, the snapshot component can directly perform snapshot processing based on the subscription message sent by kafka, so that the normal operation of the business is not affected during the generation of the data snapshot, and it has strong disaster tolerance, and can quickly restore the backup data during the snapshot processing by the snapshot component to obtain the data section data at any time point. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0041] Figure 1 A schematic diagram of the system architecture of a data snapshot provided in an embodiment of the present application;
[0042] Figure 2 A schematic diagram of a data snapshot method provided in an embodiment of the present application;
[0043] Figure 3 A flowchart of a data snapshot method provided by another embodiment of the present application;
[0044] Figure 4 A schematic diagram of the structure of a data snapshot provided in an embodiment of the present application;
[0045] Figure 5 A flowchart of a data recovery method provided in an embodiment of the present application;
[0046] Figure 6 A schematic diagram of the structure of the data recovery method provided in the embodiment of the present application;
[0047] Figure 7 A schematic diagram of the structure of a data snapshot device provided in an embodiment of the present application;
[0048] Figure 8 A schematic diagram of the structure of a data snapshot device provided in an embodiment of the present application;
[0049] Fig. 9 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0050] The present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the invention are shown in the accompanying drawings.
[0051] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0052] It can be understood that a data snapshot is a record of the state of data storage at a certain moment. Depending on the business scenario, the demand for data snapshots is also different. For example, a copy of the latest production data is needed to test a new system or provide decision support and data analysis. In some scenarios, a certain business will have a fixed business "rest period", such as the closing of a supermarket or the closing of a stock market, so there is enough free time to process data snapshots. However, for some non-stop businesses, such as e-commerce businesses, business is happening at any time and data is changing at any time. It is necessary to achieve accurate cross-sectional data snapshots without affecting normal business, such as daily account settlement.
[0053] At present, in the related technology, all data in the specified table can be backed up to another table by executing SQL statements, so that the data backup when the SQL command is executed is formed in the new table. The backup file system dump tool that comes with the MySQL database can also be used to implement data snapshot backup of a single database and a single table / a single database and multiple tables / multiple databases and multiple tables. However, in the process of generating snapshots in the related technology, the modification of data by the business will be blocked, which will have a business impact on the business that does not stop at all times. If the generated snapshot is damaged, it will be unrecoverable, and only simple data backup can be performed. Customized data processing cannot be performed for different businesses, and the scalability is poor.
[0054] Based on the above-mentioned defects, the present application provides a data snapshot method. Compared with the related technology, the snapshot component can directly perform snapshot processing based on the subscription message sent by Kafka, so that the normal operation of the business is not affected during the generation of the data snapshot, and it has strong disaster recovery. The backup data during snapshot processing by the snapshot component can be quickly restored to obtain data section data at any time point, and during data snapshot processing, data can be processed according to the needs of the business party to obtain the corresponding data snapshot, which greatly improves the scalability.
[0055] Figure 1 This is a diagram of the implementation environment of the data snapshot method provided in the embodiment of the present application. Figure 1 As shown, the implementation environment architecture includes: a terminal 100 and a server 200.
[0056] The terminal 100 may be a smart phone, a laptop computer, or a tablet computer, etc. The present application does not limit the type of operating system, for example, it may include an Android operating system, an iOS operating system, or a Windows operating system, etc. A client runs on the terminal 100, and a user may perform any business operation on the client of the terminal 100, thereby generating business data, and storing the business data in a database.
[0057] The server 200 can be a single server, a server cluster consisting of multiple servers, or a cloud computing service center. The server 200 has a data processing function, which is used to read log files from the database through the Canal component and send them to Kafka, write the log files to the corresponding message partitions through Kafka, generate subscription messages and send them to the snapshot component, and when the snapshot trigger condition is met, the snapshot component performs snapshot processing on the log files based on the subscription message to obtain a data snapshot.
[0058] The terminal 100 and the server 200 establish a communication connection via a wired or wireless network.
[0059] For ease of understanding and explanation, the following Figures 2 to 9 The data snapshot method, device, equipment and storage medium provided in the embodiments of the present application are described in detail.
[0060] Figure 2 FIG. 1 is a flow chart of a data snapshot processing method provided in an embodiment of the present application. The method is applied to a data snapshot device, which may be a server or a terminal. Figure 2 As shown, the method includes:
[0061] S101. The Canal component sends the log files read from the database to the distributed publish-subscribe messaging system Kafka.
[0062] Specifically, the above log file can be a binary format log file, which is used to record the sql statement information of the user's data operation. For example, the sql statement of changing the database table and changing the content will be recorded in the log file. The mysqlbin command can be used to view the content of the binary log. The log file can be binlog.
[0063] When processing business, business data can be stored in the mysql database. The log file binlog is read from the database through the Canal component. After reading the log file binlog, the log file binlog is parsed and processed by the Canal component, for example, protocol conversion can be performed to parse the log file binlog into a log file binlog that conforms to a preset format, for example, it can be parsed and processed into a json format. Then the log file binlog that conforms to the preset format is sent to the distributed publish-subscribe messaging system kafka.
[0064] When reading log files, the Canal component can simulate the interactive protocol of MySQL slave and disguise itself as the slave of the database MySQL to read the binlog log files. Optionally, the corresponding read permissions can be configured for the Canal component to read the log files corresponding to the configured read permissions. Generally, read permissions are configured for all files, that is, all log files can be read.
[0065] S102, Kafka writes the log file to the corresponding message partition, generates a subscription message and sends it to the snapshot component.
[0066] The above-mentioned Kafka is a high-throughput distributed publish-subscribe messaging system that supports partitioning messages through Kafka servers or consumer machine clusters. It can process all action flow data of consumers on the website. These data are usually solved by processing logs and log aggregation due to throughput requirements. The purpose of Kafka is to unify online and offline message processing through Hadoop's parallel loading mechanism in order to provide real-time messages through clusters. Kafka open source components can be used for multi-threaded concurrency to achieve high-performance processing. The log file sent by the Canal component to Kafka can include multiple message data, each of which has a category, which is called a topic. Users can store messages of different business categories in different topics according to their own business forms, and physically store messages of different topics separately. Kafka manages messages by topic, and each topic contains one or more message partitions, which can be partition message partitions. Kafka can pre-configure the number of message partitions according to performance requirements, where the higher the number of partitions, the higher the degree of concurrency.
[0067] The log files sent by the Canal component to Kafka are distributed to multiple partition message partitions corresponding to a topic through messages. Each partition message partition is an ordered, immutable queue that stores each message in the order of production. Each message in the partition is assigned a 64-bit position offset, which is a self-increasing ordered offset. This offset is equivalent to the message id and is used to uniquely determine the position of each message in the partition message partition.
[0068] After the Canal component parses the log file into a binlog log file that conforms to the preset format and transmits it to Kafka, Kafka hashes the log file according to the sharding rules pre-configured by the Canal component to obtain the corresponding hash value, where the sharding rule can be, for example, sharding according to the user. The same shard can guarantee the order of message processing, and the order cannot be strictly guaranteed between different partitions, that is, the sharding rule requires that the dimensions that do not affect each other be selected according to the business. Then the log file is partitioned according to the hash value, the log file is stored in the corresponding partition message partition, and the log file corresponding to the partition message partition is read. The log file corresponding to one partition message partition or multiple partition message partitions can be processed through the preset protocol, and a subscription message is generated, and the subscription message is sent to the snapshot component. Optionally, the number of message partitions configured according to performance requirements can be detected, and based on the hash value and the number of message partitions, the log file can be partitioned using a preset algorithm so that it is stored in the corresponding partition message partition. Among them, the number of partitions can be modulo based on the hash value to determine which partition the message is distributed to. For example, the partition message partition to be submitted to is calculated by the algorithm: partition = hash (group_id) % 50, where group_id is the subscription message identifier, for example: group_id = test_group_1, then partition = hash (test_group_1) % 50 = 28, that is, the log file corresponding to the subscription message is stored in the partition message partition identified as 28.
[0069] In this embodiment, the log files read from the database by the Canal component are sent to Kafka, and the log files are distributed through Kafka. Since the binlog synchronization mode is used to obtain the log files, the snapshot processing and data snapshot generation behavior are completely imperceptible and have no impact on the MySQL data storage, so that the normal operation of the business is not affected during the data snapshot generation process.
[0070] S103: When the snapshot triggering condition is met, the snapshot component performs snapshot processing on the log file based on the subscription message to obtain a data snapshot.
[0071] Specifically, when performing data snapshot processing, the snapshot trigger conditions can be configured according to needs. When there is a snapshot demand at a preset time point, the snapshot trigger condition can be configured as a preset time point. When the preset time point is reached, the snapshot component is automatically triggered to perform snapshot processing based on the subscription message to obtain the corresponding data snapshot; the snapshot trigger condition can also be actively triggered through an external interface, and data is consumed and a data snapshot is generated through the external interface, and the generated data snapshot can be stored.
[0072] The generated data snapshot may be stored in a database, such as a MongoDB database.
[0073] It should be noted that MongoDB is a non-relational database, also called a document database. It is a NoSQL database that can store data of XML, JSON, and BSON types in a JSON-like document format and uses MongoDB query statements. It is a database that supports both community and enterprise versions.
[0074] Optionally, as another possible implementation method, Figure 3 The flowchart of the method for obtaining a data snapshot by performing snapshot processing on log files based on subscription messages provided in this embodiment is as follows. Figure 3 As shown, the above step S103 may include the following steps:
[0075] S201. The snapshot component parses the subscription message to obtain a log file corresponding to the subscription message.
[0076] S202: The snapshot component performs snapshot processing on the log file based on a preset configuration file to obtain a data snapshot.
[0077] Specifically, when performing snapshot services, the snapshot component can register a corresponding number of message consumers according to the number of partition message partitions in Kafka. The message consumers can be multiple business components in the snapshot component that read messages from Kafka. The multiple business components include at least one business processing component and at least one business storage component. Each business processing component is configured with a different business type, and each business storage component is configured with a different storage format. The message consumer consumes subscription messages from Kafka, parses the subscription messages, obtains the log files corresponding to the subscription messages, and determines whether the log files need to be processed based on a pre-set configuration file, wherein the pre-set configuration file may include configuration parameters set under different business processing conditions for the same log file.
[0078] When it is necessary to process the log file, the business type corresponding to each business processing component in at least one business processing component is obtained from the configuration sub-file preset by each business processing component, and the log file is processed based on the business type to obtain a data snapshot corresponding to each business processing component, wherein the configuration sub-file preset by the business processing component may include configuration parameters such as the business type and business rules; when it is not necessary to process the log file, the storage format corresponding to each business storage component in at least one business storage component may be obtained from the configuration sub-file preset by each business storage component, and then the log file is processed according to the storage format to obtain a data snapshot corresponding to each business storage component, wherein the configuration sub-file preset by the business storage component may include configuration parameters such as the data storage format and storage rules.
[0079] The processing operation of the log file according to the business type and business rules may be to filter and process the log file to obtain a data snapshot. For example, if the business type is to obtain data and the business rule is to obtain the order data at 12 o'clock, the business processing component in the snapshot component consumes the subscription message from Kafka, parses the subscription message, and obtains, for example, the order data of each day, and filters the order data of each day to obtain the order data at 12 o'clock.
[0080] Furthermore, when the snapshot component performs data snapshot services, the snapshot component may include the above-mentioned business component and the master node component. The master node component may be called Checkpoint branch, and the business component may also be called business branch. The snapshot component has a master node component Checkpoint branch by default to monitor and save all data in real time, that is, it will consume the data of each partition message partition from kafka, and store the log file of each partition message partition in the master node component, thereby realizing the basic backup of the full data such as log files. The business branch is used to obtain a data snapshot after snapshot processing of the log file of a partition message partition in kafka. The business branch can also customize the snapshot trigger time. For example, if the snapshot trigger time is five o'clock, the snapshot operation will be triggered at five o'clock.
[0081] In addition, the snapshot component can also add business components according to business needs, namely business branches. The data of the master node component Checkpoint branch is the superset of each business branch, and each business branch has independent configuration, customization, and processing unit.
[0082] Among them, the data snapshot table is stored in the Checkpoint branch of the master node component and the business branch. The data snapshot table includes data section information such as snapshot identifier, storage address, snapshot generation time, data set, and offset corresponding to each partition in Kafka.
[0083] It should be noted that the master node component Checkpoint branch and the business component Biz branch have the following differences: the data of Biz branch is a subset of Checkpoint branch, including data volume dimension and / or attribute volume dimension; the time reference of snapshot trigger of business component Biz branch is divided into two levels, the first level is kafka timestamp Kfktimestamp, and the second level is real time; CheckPoint branch does not care about kafka timestamp Kfk timestamp, and only generates snapshots at certain times (not requiring exact time points) for disaster recovery and replay; the image of master node component CheckPoint branch is theoretically retained for a long time, while the image of business component Biz branch only retains the previous time point.
[0084] In this embodiment, multiple business components are provided so that each business component can independently customize required data, and the data between each business is isolated and does not affect each other, thereby further improving the scalability of business data processing.
[0085] For example, Figure 4 As shown, business data is generated during business operations and is stored in the MySQL database in the form of binlog log files. The Canal component reads the binlog log files from the MySQL that stores the business data, parses the binlog log files into binlog log files that conform to a preset format, and transmits the binlog log files that conform to the preset format to Kafka. Kafka hashes the log files according to the pre-configured sharding rules to obtain the corresponding hash values, and then partitions the log files according to the hash values and stores them in the corresponding multiple partition message partitions in Kafka. Kafka reads the corresponding log files in the partition message partitions, processes the log files in one or more partition message partitions based on the preset protocol to generate subscription messages, and sends the subscription messages to the snapshot component Polaroid.
[0086] The Polaroid snapshot component consumes subscription messages from Kafka. When the snapshot trigger condition is met, it stops consuming subscription messages from Kafka and parses the subscription messages to obtain the corresponding log files. Then, it determines whether the log files need to be stored synchronously based on the preset configuration files. When it is determined that the log files need to be stored synchronously, it obtains the corresponding storage format from the configuration subfile preset by the business storage component, and processes the log files according to the storage format corresponding to the business storage component to obtain the corresponding data snapshot. When the log files do not need to be stored synchronously, it obtains the business type from the configuration subfile preset by the business processing component, and processes the log files based on the business type to obtain a data snapshot, and stores the generated data snapshot in the MongoDB database.
[0087] In this embodiment, the snapshot component can directly perform snapshot processing based on the subscription message sent by Kafka, so that the normal operation of the business is not affected during the generation of the data snapshot. By setting up multiple business components in the snapshot component, each business component can independently customize the required data, and the data between each business is isolated and does not affect each other, thereby obtaining a data snapshot that meets business needs.
[0088] Furthermore, the snapshot component has strong disaster recovery capabilities. As long as there is an undamaged image and the Kafka message is stored intact, all images after the image can be redone and the data can be restored. This redo / recovery process is called Replay.
[0089] Figure 5 The following is a flow chart of the data recovery method provided in this embodiment. Figure 5As shown, the method includes:
[0090] S301: A business component receives a data recovery request, where the data recovery request includes a data recovery time point and a snapshot data identifier. The business component is a business processing component or a business storage component.
[0091] Specifically, when it is necessary to restore data at a certain point in time, a data recovery request is received through the business component, and the data recovery request includes the data recovery time and the snapshot data identifier. The data recovery time can be any time point, such as 0 o'clock. The snapshot data identifier is the corresponding identifier in the snapshot data worksheet backed up by the master node component Checkpoint branch, which is used to uniquely identify the data of a certain snapshot slice.
[0092] S302: The business component obtains snapshot data from the master node component based on the snapshot data identifier, where the snapshot data includes a data set and a position offset corresponding to each message partition.
[0093] In response to the data recovery request, the business component obtains snapshot data from the master node component based on the snapshot data identifier, wherein the snapshot data may include a data set and the offset corresponding to each message partition in Kafka. The data set stores the log files consumed from Kafka.
[0094] S303: The business component loads the data set into the work table and resets the position offset corresponding to each message partition.
[0095] S304: The business component sets the snapshot trigger time as the data recovery time point and consumes message data from Kafka.
[0096] S305: When the snapshot trigger time is reached, the business component stops consuming message data from Kafka to obtain a data snapshot corresponding to the data recovery time point.
[0097] The business component loads the data set into its own work table, resets the offset corresponding to each message partition, sets the snapshot trigger time to the data recovery time point, and consumes message data from Kafka. When the snapshot trigger time is reached, it stops consuming message data from Kafka to obtain the data snapshot corresponding to the data recovery time point.
[0098] For example, Figure 6As shown, for example, business component Branch A receives a data recovery request, which requires the recovery of the data snapshot corresponding to 0:00 on March 3, and the currently available data snapshot is the checkpoint mirror data of March 1 backed up by the master node component Checkpoint branch. The checkpoint mirror data includes the data set image collection and the offset corresponding to each partition message partition, such as P1: offset, P2: offset, P3: offset.
[0099] Assume that the data snapshot of BranchA is triggered at 0:00 every day. During the data recovery process, the data set in the checkpoint mirror data on March 1 is loaded into the work table in the business component BranchA, and the position offset corresponding to each partition message partition is adjusted according to Kafka's own capabilities, that is, the position offset is reset. The time point of the next snapshot trigger is set to 0:00 on March 2. When the business component branchA consumes data from Kafka, it compares the snapshot trigger time with the timestamp of each message in Kafka.
[0100] When the Kafka timestamp of each message in Kafka reaches after March 2 (after midnight), that is, the timestamp of the consumed Kafka message is after 0:00 on March 2, and all the partition message partitions reach this time node, the business component branchA stops consuming messages and prints the data snapshot at 0:00 on March 2. Similarly, continue to set the next snapshot trigger time to 0:00 on March 3, consume Kafka messages until the Kafka timestamp is 0:00 on March 3, and after reaching 0:00 on March 3, print the data snapshot at 0:00 on March 3, thereby completing the data recovery at 0:00 on March 3. Furthermore, you can also set the next snapshot trigger time to 0:00 on March 4, and then restore the data snapshot at 0:00 on March 4. After the data recovery is completed, you can continue normal business data synchronization.
[0101] In this embodiment, since the master node component Checkpoint branch is used to perform basic backup, data can be quickly restored through the complete basic backup data, which has extremely strong data disaster tolerance and can restore data at any time point.
[0102] It should be noted that although the operations of the method of the present invention are described in a particular order in the accompanying drawings, this does not require or imply that the operations must be performed in this particular order, or that all the operations shown must be performed to achieve the desired results. On the contrary, the steps depicted in the flow chart can be performed in a different order. Additionally or alternatively, some steps can be omitted, multiple steps can be combined into one step, and / or one step can be decomposed into multiple steps.
[0103] on the other hand, Figure 7 The structure diagram of a data snapshot device provided in an embodiment of the present application is shown in FIG. The device may be a device in a terminal device, such as Figure 7 As shown, the device 700 includes:
[0104] The sending module 710 is used for the Canal component to send the log files read from the database to the distributed publish-subscribe messaging system kafka;
[0105] Partition module 720, used for Kafka to write log files into corresponding message partitions, generate subscription messages and send them to snapshot components;
[0106] The snapshot generation module 730 is used for obtaining a data snapshot by the snapshot component performing snapshot processing on the log file based on the subscription message when the snapshot trigger time is reached.
[0107] Optional, see Figure 8 The partition module 720 includes:
[0108] Processing unit 721, used for Kafka to perform hash processing on the log file according to the pre-configured sharding rule to obtain a hash value;
[0109] Storage unit 722, used for Kafka to partition the log file according to the hash value and store it in the corresponding message partition;
[0110] A generating unit 723 is used for Kafka to read the log file corresponding to the message partition and generate a subscription message;
[0111] The sending unit 724 is used for Kafka to send the subscription message to the snapshot component.
[0112] Optionally, the snapshot generation module 730 includes:
[0113] The parsing unit 731 is used for the snapshot component to parse the subscription message and obtain the log file corresponding to the subscription message;
[0114] The snapshot unit 732 is used for the snapshot component to perform snapshot processing on the log file based on a preset configuration file to obtain a data snapshot.
[0115] Optionally, the snapshot unit 732 is specifically configured to:
[0116] The snapshot component determines whether the log file needs to be processed based on a preset configuration file, which includes configuration parameters set under different business processing conditions for the same log file;
[0117] When the log file needs to be processed, obtain the business type corresponding to each business processing component in at least one business processing component;
[0118] The log file is processed based on the business type to obtain a data snapshot corresponding to each of the business processing components.
[0119] Optionally, the snapshot unit 732 is specifically configured to:
[0120] When the log file does not need to be processed, obtaining a storage format corresponding to each business storage component in at least one business storage component;
[0121] The log files are processed according to the storage format to obtain the data snapshot corresponding to each business storage component.
[0122] Optionally, the above device is also used for:
[0123] Based on the subscription message, the log file corresponding to the subscription message is stored in the master node component to perform data backup on the log file.
[0124] Optionally, the above device is also used for:
[0125] The business component receives a data recovery request, the data recovery request includes a data recovery time point and a snapshot data identifier, and the business component is a business processing component or a business storage component;
[0126] The business component obtains snapshot data from the master node component based on the snapshot data identifier. The snapshot data includes the data set and the position offset corresponding to each message partition.
[0127] The business component loads the data set into the work table and resets the position offset corresponding to each message partition;
[0128] The business component sets the snapshot trigger time as the data recovery time point and consumes message data from Kafka;
[0129] When the snapshot trigger time is reached, the business component stops consuming message data from Kafka to obtain the data snapshot corresponding to the data recovery time point.
[0130] The data snapshot device provided in the embodiment of the present application sends the log file read from the database to the distributed publish-subscribe message system kafka through the Canal component. Kafka writes the log file to the corresponding message partition, generates a subscription message and sends it to the snapshot component. When the snapshot trigger condition is met, the snapshot component performs snapshot processing on the log file based on the subscription message to generate a data snapshot. In this technical solution, the snapshot component can directly perform snapshot processing based on the subscription message sent by kafka, so that the normal operation of the business is not affected during the generation of the data snapshot, and it has strong disaster tolerance, and can quickly restore the backup data during the snapshot processing by the snapshot component to obtain the data section data at any time point.
[0131] Reference below Fig. 9 , Fig. 9 A schematic diagram of the structure of a computer system of a terminal device or server according to an embodiment of the present application.
[0132] like Fig. 9 As shown, the computer system 1000 includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage part 1008 into a random access memory (RAM) 1003. In the RAM 1003, various programs and data required for the operation of the system 1000 are also stored. The CPU 1001, the ROM 1002, and the RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1006 is also connected to the bus 1004.
[0133] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, etc.; an output section 1007 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1008 including a hard disk, etc.; and a communication section 1009 including a network interface card such as a LAN card, a modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1006 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1010 as needed, so that a computer program read therefrom is installed into the storage section 1008 as needed.
[0134] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a machine-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication part 1003, and / or installed from a removable medium 1011. When the computer program is executed by a central processing unit (CPU) 1001, the above-mentioned functions defined in the system of the present application are executed.
[0135] It should be noted that the computer-readable medium shown in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0136] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of the code, and the aforementioned module, program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0137] The units or modules involved in the embodiments of the present application may be implemented in software or hardware. The units or modules described may also be provided in a processor, for example, may be described as: a processor comprising: a sending module, a partitioning module and a snapshot generation module. Among them, the names of these units or modules do not constitute a limitation on the units or modules themselves in certain cases, for example, the sending module may also be described as "for the Canal component to send the log files read from the database to the distributed publish-subscribe messaging system kafka".
[0138] As another aspect, the present application further provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiment; or may exist independently and not be assembled into the electronic device. The above computer-readable storage medium stores one or more programs, and when the above programs are used by one or more processors to execute the data snapshot method described in the present application:
[0139] The Canal component sends the log files read from the database to the distributed publish-subscribe messaging system Kafka;
[0140] The kafka writes the log file into the corresponding message partition, generates a subscription message and sends it to the snapshot component;
[0141] When the snapshot triggering condition is met, the snapshot component performs snapshot processing on the log file based on the subscription message to obtain a data snapshot.
[0142] In summary, the data snapshot method, device, equipment and storage medium provided by the embodiments of the present application send the log file read from the database to the distributed publish-subscribe message system kafka through the Canal component, and kafka writes the log file to the corresponding message partition, generates a subscription message and sends it to the snapshot component. When the snapshot trigger condition is met, the snapshot component performs snapshot processing on the log file based on the subscription message to generate a data snapshot. In this technical solution, the snapshot component can directly perform snapshot processing based on the subscription message sent by kafka, so that the normal operation of the business is not affected during the generation of the data snapshot, and it has strong disaster tolerance, and can quickly restore the backup data during the snapshot processing by the snapshot component to obtain the data section data at any time point.
[0143] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the inventive concept. For example, the above features are replaced with (but not limited to) technical features with similar functions disclosed in the present application.
Claims
1. A data snapshot method, characterized in that: include: The Canal component sends the log files read from the database to the distributed publish-subscribe messaging system Kafka; The kafka writes the log file into the corresponding message partition, generates a subscription message and sends it to the snapshot component; When the snapshot triggering condition is met, the snapshot component performs snapshot processing on the log file based on the subscription message to obtain a data snapshot, specifically including: the snapshot component performs parsing processing on the subscription message to obtain a log file corresponding to the subscription message; The snapshot component performs snapshot processing on the log file based on a preset configuration file to obtain a data snapshot; The snapshot component includes at least one business processing component and at least one business storage component. The snapshot component performs snapshot processing on the log file based on a preset configuration file to obtain a data snapshot, including: The snapshot component determines whether the log file needs to be processed based on a preset configuration file, wherein the configuration file includes configuration parameters set under different business processing conditions for the same log file; When the log file needs to be processed, obtaining a service type corresponding to each service processing component in the at least one service processing component; The log file is processed based on the business type to obtain a data snapshot corresponding to each of the business processing components.
2. The method according to claim 1, characterized in that: The kafka writes the log file into the corresponding message partition, generates a subscription message and sends it to the snapshot component, including: The kafka performs hash processing on the log file according to the pre-configured sharding rules to obtain a hash value; The kafka partitions the log file according to the hash value and stores it in the corresponding message partition; The kafka reads the log file corresponding to the message partition and generates a subscription message; The kafka sends the subscription message to the snapshot component.
3. The method according to claim 1, characterized in that After the snapshot component determines whether the log file needs to be processed based on a preset configuration file, the method further includes: When the log file does not need to be processed, obtaining a storage format corresponding to each business storage component in the at least one business storage component; The log file is processed according to the storage format to obtain a data snapshot corresponding to each business storage component.
4. The method according to claim 1, characterized in that: The snapshot component also includes a master node component. After the kafka sends a subscription message to the snapshot component, the method further includes: Based on the subscription message, the log file corresponding to the subscription message is stored in the master node component to perform data backup on the log file.
5. The method according to claim 4, characterized in that After backing up the log file, the method further includes: The business component receives a data recovery request, the data recovery request includes a data recovery time point and a snapshot data identifier, and the business component is a business processing component or a business storage component; The business component obtains snapshot data from the master node component based on the snapshot data identifier, wherein the snapshot data includes a data set and a position offset corresponding to each message partition; The business component loads the data set into a work table and resets the position offset corresponding to each message partition; The business component sets the snapshot trigger time as the data recovery time point and consumes message data from the kafka; When the snapshot trigger time is reached, the business component stops consuming message data from the kafka to obtain a data snapshot corresponding to the data recovery time point.
6. A data snapshot device, characterized in that: The device is used to execute the method according to any one of claims 1 to 5, and the device comprises: The sending module is used by the Canal component to send the log files read from the database to the distributed publish-subscribe messaging system Kafka; A partition module is used for the kafka to write the log file into the corresponding message partition, generate a subscription message and send it to the snapshot component; The snapshot generation module is used for obtaining a data snapshot by the snapshot component performing snapshot processing on the log file based on the subscription message when the snapshot trigger time is reached.
7. A computer device, characterized in that: The computer device comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor is configured to implement the method according to any one of claims 1 to 5 when executing the program.
8. A computer-readable storage medium having a computer program stored thereon, wherein the computer program is used to implement the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Data synchronization method and device, medium and electronic equipment
CN110083660A
Data display method and device
CN110555028A
Message processing method and device
CN110659124A
Log storage method, device and system, electronic equipment and computer readable medium
CN111046010A
Implementation method and device of data middle station and electronic equipment
CN111143465A
