Data synchronization method and device
By adding a data synchronization platform outside the data warehouse to automatically obtain and synchronize data, the problems of long data synchronization cycle and poor timeliness in the existing technology are solved, and efficient data synchronization operations are realized.
Patent Information
- Application Number
- CN202210452630.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-27
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2042-04-27
AI Technical Summary
The existing solution for synchronizing data to the data warehouse has a long cycle and poor timeliness. It can only synchronize the data of the previous day every day, and the cost of manual docking is high.
Add a data synchronization platform outside the data warehouse, obtain the source address and destination address through the synchronization requirements of the target data, obtain the target data from the data middleware, and synchronize it to the matching hive table to achieve automated operations.
The data synchronization cycle is shortened, manual docking costs are reduced, data synchronization efficiency is improved, and real-time data synchronization is achieved.
Smart Images

Figure CN114860826B
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data synchronization method and device. Background Art
[0002] At present, synchronizing the data of the business system to the data warehouse usually requires the following process: first, the business personnel propose the data synchronization requirements; then the product manager evaluates the rationality of the data synchronization requirements; if the data synchronization requirements are evaluated, the product personnel and the data warehouse management personnel coordinate the data synchronization requirements scheduling; then, the data warehouse management personnel connect the data that needs to be synchronized in the business system to the data warehouse according to the data synchronization requirements within the schedule; finally, after the data synchronization, the business personnel verify the synchronized data. If any problems are found during the access process, the data warehouse management personnel need to communicate with the business personnel to correct the requirements. In addition, the existing data synchronization to the data warehouse solution needs to be triggered by the scheduling system every day to synchronize the data generated in the business system the previous day to the data warehouse. At the same time, when the initial import (that is, when the requirements are connected), the data warehouse management personnel need to manually trigger the task execution to synchronize the data generated by the business system to the data warehouse.
[0003] Obviously, the existing solution for synchronizing data to the data warehouse has a long cycle from data synchronization demand to data synchronization completion, and can only synchronize data generated in the business system on the previous day every day, so the timeliness is also poor. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a data synchronization method and device for improving the efficiency of synchronizing data into a data warehouse.
[0005] In a first aspect, a data synchronization method is provided, the method being applied to a data synchronization platform, comprising:
[0006] Based on the synchronization requirements of the target data, obtaining the source address and the synchronization destination address in the synchronization configuration information of the target data;
[0007] Based on the source address, obtaining the target data from the data middleware;
[0008] The target data is synchronized to a hive table in the data warehouse that matches the synchronization destination address.
[0009] In a second aspect, a data synchronization platform is provided, including:
[0010] An address acquisition unit, configured to acquire a source address and a synchronization destination address in the synchronization configuration information of the target data based on a synchronization requirement of the target data;
[0011] A data acquisition unit, configured to acquire the target data from the data middleware based on the source address;
[0012] A data synchronization unit is used to synchronize the target data to a hive table in the data warehouse that matches the synchronization destination address.
[0013] In a third aspect, an electronic device is provided, which includes a processor, a memory, and a computer program stored in the memory and executable on the processor, and when the computer program is executed by the processor, the steps of the data synchronization method of the first aspect are implemented.
[0014] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the data synchronization method of the first aspect are implemented.
[0015] By adopting the solution of the embodiment of the present application, a data synchronization platform is additionally added in addition to the data warehouse, and the data synchronization operation is performed by the data synchronization platform. After the target data is generated, if there is a synchronization requirement for the target data, the synchronization requirement of the target data can be sent to the data synchronization platform, and the data synchronization platform obtains the source address and the synchronization destination address in the synchronization configuration information of the target data based on the synchronization requirement of the target data, so that the target data can be obtained from the data middleware based on the source address, and the obtained target data can be synchronized to the hive table in the data warehouse that matches the synchronization destination address, thereby realizing the automated operation of synchronizing the target data to the data warehouse, reducing the manual docking cost in the data synchronization process, shortening the data synchronization cycle, and effectively improving the data synchronization efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0017] Figure 1 It is a flowchart of a data synchronization method provided by an embodiment of the present application.
[0018] Figure 2 This is an example diagram of an actual scenario of the application of the data synchronization method provided by an embodiment of the present application.
[0019] Figure 3 This is an example diagram of an actual scenario of the application of the data synchronization method provided by an embodiment of the present application.
[0020] Figure 4 It is a structural diagram of a data synchronization device provided by an embodiment of the present application.
[0021] Figure 5 It is a structural schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0022] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application. The numbering of the drawings in this application is only used to distinguish the various steps in the scheme, and is not used to limit the execution order of the various steps. The specific execution order is subject to the description in the specification.
[0023] As described in the background technology, the existing data synchronization scheme requires the cooperation of personnel from all parties from the proposal of data synchronization requirements to the completion of data synchronization, which will result in a long data synchronization cycle and poor data synchronization timeliness. In view of this, the embodiment of the present application provides a data synchronization method for improving data synchronization efficiency. The method is applied to a data synchronization platform, that is, an additional data synchronization platform is added outside the data warehouse, and the data synchronization platform performs data synchronization operations. After the target data is generated, if there is a synchronization requirement for the target data, the synchronization requirement of the target data can be sent to the data synchronization platform, and the data synchronization platform obtains the source address and synchronization destination address in the synchronization configuration information of the target data based on the synchronization requirement of the target data. The data synchronization platform is enabled to obtain the target data to be synchronized from the data middleware based on the source address, and synchronize the obtained target data to the hive table matching the synchronization destination address in the data warehouse. The automatic operation of synchronizing the target data to the data warehouse is realized, that is, after the synchronization requirement of the target data is proposed, the synchronization requirement is submitted to the data synchronization platform to realize the synchronization of the target data to the data warehouse, without the need for personnel from all parties to continuously perform manual docking during the synchronization process, thereby greatly shortening the synchronization cycle of the target data and effectively improving the synchronization efficiency of the target data.
[0024] First, let's introduce the concepts of message queue, Kafka, Topic, hive, hudi, schema registry, automatic parsing, no perception, and data synchronization platform:
[0025] Message queue: Message queue is an important component in distributed systems, mainly solving problems such as application coupling, asynchronous messages, and traffic clipping. It is an architecture that achieves high performance, high availability, scalability, and eventual consistency, and is also an indispensable middleware for large distributed systems. The first data middleware Kafka in the embodiment of the present application is an implementation form of a message queue.
[0026] Kafka: Kafka is a distributed streaming platform with three key functions: publishing and subscribing to record streams, storing streams in a fault-tolerant and durable way, and processing streams as records occur. Kafka is typically used in two major categories of applications, including building real-time streaming data pipelines that can reliably obtain data between systems or applications, and building real-time streaming applications that transform or respond to data streams. Kafka runs as a cluster on one or more servers that can span multiple data centers. The Kafka cluster stores record streams in categories called xxtopics topics. Each record in the Kafka cluster contains a key, a value, and a timestamp.
[0027] Topic: Topic is a subject in Kafka. A Topic can be considered as a type of message. Each Topic will be divided into multiple partitions. Each partition is an append log file at the storage level. Topic is the category or subscription source name of the published record. Kafka's Topic is always multi-user, that is, a Topic can have zero, one or more consumers subscribing to write its data. In the embodiment of the present application, a Topic corresponds to a sender of target data.
[0028] Hive: A data warehouse that encapsulates HADOOP parallel computing tasks at the bottom layer. It is mainly used to process structured data on HADOOP. Hive provides a SQL-like language to implement data query and converts SQL statements into parallel computing tasks to run on HADOOP.
[0029] Hudi: Also known as a data lake, it synchronizes upstream data to the RawTables of the data lake in real time through Spark / Flink, and can add, delete, modify and query Raw Tables.
[0030] Schema Registry: It is a tool developed by Confluent to store historical versions of Avro Schema and also includes compatibility checking functions. When deployed, it is not part of the Kafka cluster but is deployed independently outside the Kafka cluster. Schema Registry creates a Schema ID for each Schema, and SchemaAPI provides add, query, and delete operations through Schema ID.
[0031] Automatic parsing: Pass in information according to the agreed specifications, and the program will automatically parse out the content.
[0032] Imperceptible: This method is transparent and imperceptible to users, and does not require configuration in code or interface.
[0033] Data synchronization platform: The embodiment of the present application uses spark streaming to build a data synchronization platform. The data synchronization platform is configured with a management terminal to manage the source of the data to be synchronized and the data synchronization tasks.
[0034] like Figure 1 As shown, the data synchronization method provided in the embodiment of the present application includes:
[0035] S110, based on the synchronization requirement of the target data, obtaining a source address and a synchronization destination address in the synchronization configuration information of the target data.
[0036] After the target data is generated, if there is a synchronization requirement for the target data, the sender of the target data (the business party that generates the target data, such as the target application) can send the synchronization requirement for the target data to the data synchronization platform, and the data synchronization platform will execute the operation of synchronizing the target data to the data warehouse.
[0037] Among them, the data synchronization platform can be built based on Spark Streaming, which is an extension of Spark's core API and can achieve high-throughput, real-time streaming data processing with fault-tolerant mechanisms. Spark Streaming can receive real-time input data from various sources such as Kafka, Flume, and HDFS, and save the received data in various places such as HDFS and DataBase after processing. Spark Streaming has a graphical monitoring interface that can be output to the front-end monitoring page. Spark Streaming actually does not process data one by one like Strom, but after connecting to the external data stream, it splits it according to time and batches the split files one by one, which is the same as Spark's processing logic. Spark Streaming splits the received real-time streaming data at a certain time interval and hands it to the Spark Engine to finally obtain batches of results.
[0038] It should be understood that in order to facilitate the data synchronization platform to synchronize the target data to the data warehouse, the synchronization requirements of the target data should carry the synchronization configuration information of the target data. The synchronization configuration information may be configured with the source address of the target data, that is, the address where the target data is stored in the data middleware, the synchronization destination address of the target data, that is, the cluster name, library name, table name and other address information where the target data is synchronized to the data warehouse.
[0039] In order to facilitate the data synchronization platform to perform data synchronization operations on the target data, the business party that generates the target data, such as the target application, can construct a message key name (messagekey) based on the library name, table name, rowkey field name, partition field name, and partition value field in the data warehouse, that is, the metadata identifier described below. Among them, the library name and table name are defined according to the specifications of the data warehouse, the rowkey field name is similar to the MySQL primary key, and the partition field name can be defined according to the partition in the hive table in the data warehouse. In general, the creation time can be used as a partition, and the partition value field can use the creation time as the partition value field. The message key name can be understood as the metadata identifier described below, which is to describe the real data information of the corresponding message key value. The target data can specifically consist of multiple key-value pairs consisting of multiple message key names and corresponding message key values.
[0040] S120, obtaining target data from the data middleware based on the source address.
[0041] The data middleware is used to receive and store target data sent from a sender of the target data, such as a target application.
[0042] It should be understood that the original data file generated by the sender of the target data, such as the target application, may contain other redundant data in addition to the target data. In order to facilitate the data synchronization platform to parse the target data in the original data file generated by the target application, the data middleware in the embodiment of the present application may include a first data middleware and a second data middleware. Among them, the first data middleware is used to receive and store the original data file from the target application, and the second data middleware is used to receive and store the metadata description information of the target data from the target application. The metadata description information of the target data is used to define the metadata in the target data. The data synchronization platform can identify the metadata in the original data file based on the metadata description information of the target data.
[0043] Specifically, the data middleware includes a first data middleware and a second data middleware, and based on the source address, obtaining target data from the data middleware includes:
[0044] Based on the source address, determining a designated subject corresponding to the target data from the first data middleware, and obtaining a data file corresponding to the target data from the designated subject;
[0045] Based on the source address, obtain metadata description information of the target data from the second data middleware;
[0046] Based on the metadata description information of the target data, the data file is parsed to obtain the target data, wherein the target data includes a metadata identifier and corresponding data content.
[0047] Among them, the first data middleware can be implemented in actual applications through the distributed streaming platform Kafka. Kafka maintains multiple topics, and one topic corresponds to a target application. Based on the source address of the target data, it can be determined in which Topic in Kafka the target data is stored. The second data middleware can be implemented in actual applications through Schema Registry, which is used to receive and store metadata description information corresponding to each metadata identifier from the target application. The metadata description information can be registered in Schema Registry, and after the metadata description information corresponding to each metadata identifier is registered in Schema Registry, Schema Registry will also assign a Schema ID to the metadata description information corresponding to the metadata identifier, so that when the metadata identifier and its corresponding data content are parsed, the corresponding metadata description information can be quickly obtained based on the Schema ID, thereby realizing the rapid parsing of the metadata identifier and its corresponding data content.
[0048] When the same kafkatopic corresponds to multiple tables in the data warehouse, the following problems will arise when registering the above metadata description information in the schema registry: Usually, when registering metadata description information in the schema registry, the subject is named as topic name-key (the key here is the message key name, which is the metadata identifier), topic-value (the value here is the message key value, which is the data content corresponding to the metadata identifier).
[0049] In this naming method, if a kafkatopic corresponds to multiple tables in the data warehouse, it is impossible to obtain the latest metadata definition of each table, nor to view the change records of the metadata definition corresponding to the table. In order to solve this problem, the embodiment of the present application can change the naming method of the subject in the class so that it is defined according to the rules of topic-library name-table name-key, topic-library name-table name-value. Since the subject naming contains the change records of each table in the data warehouse, it is also possible to obtain the latest metadata definition and metadata definition change records of each table in the data warehouse.
[0050] Optionally, in order to improve the data parsing efficiency of the data platform, the data file corresponding to the target data may further include a metadata description identifier. Based on the metadata description information of the target data, the data file is parsed to obtain the target data, and the target data includes the metadata identifier and the corresponding data content, including:
[0051] Acquire target metadata description information corresponding to the metadata description identifier from the metadata description information of the target data;
[0052] Based on the metadata description information, the data file is parsed to obtain target data, wherein the target data includes a metadata identifier and corresponding data content.
[0053] Among them, the second data middleware Schema Registry creates a Schema ID, i.e., a metadata description identifier, for each Schema, and each Schema ID corresponds to a metadata description information. The target data is usually composed of multiple key-value pairs consisting of multiple message key names and corresponding message key values, that is, multiple metadata identifiers and corresponding data contents. In order to improve the data parsing efficiency of the target data, the embodiment of the present application can quickly and accurately obtain multiple target metadata description information for parsing the data file corresponding to the target data from the metadata description information of the target data based on the metadata description identifier contained in the data file corresponding to the target data. This enables the data synchronization platform to accurately parse the data files based on these multiple target metadata description information.
[0054] S130, synchronizing the target data to a hive table in the data warehouse that matches the synchronization destination address.
[0055] It should be understood that there are multiple hive tables in the data warehouse, and the specified hive table can be located through the synchronization target address, and the synchronization target address includes address information indicating the specific library name and table name in the data warehouse.
[0056] Optionally, synchronize the target data to a hive table in the data warehouse that matches the synchronization destination address, including:
[0057] Performing format verification on the target data, and if the target data passes the format verification, performing type mapping on the metadata identifier in the target data, and replacing the metadata identifier in the target data with the metadata identifier in the data warehouse;
[0058] Call the data lake interface to synchronize the target data to the hive table in the data warehouse that matches the synchronization destination address.
[0059] Specifically, the target data can be format-checked according to the agreed format, such as determining whether the target data contains agreed field names such as primary key fields and partition fields, whether the library name and table name cannot be empty, and whether it contains designated fields that indicate the synchronous processing method of each key-value pair in the target data (such as addition, deletion, modification and query).
[0060] It should be understood that there are many types of target data data, i.e., metadata identifiers, and there are also many types of data types, i.e., metadata identifiers, in the data warehouse, but there may be certain differences in the definitions of the data types of the two parties, i.e., metadata identifiers. In order to accommodate this difference, before the target data is synchronized to the data warehouse, the metadata identifier in the target data can be mapped to the corresponding metadata identifier in the data warehouse by type mapping. That is, the metadata identifier in the target data is matched with the metadata identifier in the data warehouse in advance, a mapping relationship table between the metadata identifier in the target data and the metadata identifier in the data warehouse is established, and based on the mapping relationship table, the metadata identifier in the target data is converted to the metadata identifier in the data warehouse.
[0061] As an example, the metadata identifiers in the target data may include aa, bb, cc, and dd, and the metadata identifiers in the data warehouse may include Aa, Bb, Cc, and Dd. The mapping relationship table between the metadata identifiers in the target data and the metadata identifiers in the data warehouse is shown in Table 1. Based on the mapping relationship table of metadata identifiers shown in Table 1, the metadata identifiers in the target data may be replaced with the metadata identifiers in the data warehouse, that is, based on the mapping relationship table, the metadata identifier aa may be converted into Aa, the metadata identifier bb may be converted into Bb, the metadata identifier cc may be converted into Cc, and the metadata identifier dd may be converted into Dd.
[0062] Table 1 Metadata identifier mapping relationship
[0063]
[0064]
[0065] The English name of the data lake is hudi. The data lake supports addition, deletion, modification and query, and can synchronize addition, deletion and modification data operations in real time, that is, it can realize real-time data writing and support addition, deletion, modification and query data operations. Based on this point, the embodiment of the present application calls the data lake interface to synchronize the target data in real time to the hive table in the data warehouse that matches the synchronization destination address.
[0066] It should be understood that when synchronizing the target data to the hive table in the data warehouse that matches the synchronization destination address, the following two situations may occur: In the first situation, there is no hive table matching the synchronization destination address in the data warehouse. In this case, it is necessary to first create a hive table matching the synchronization destination address, and then write the target data into the hive table; In the second situation, there is already a hive table matching the synchronization destination address in the data warehouse. In this case, you can directly find and determine the hive table matching the synchronization destination address based on the synchronization destination address to write the target data into the hive table.
[0067] Specifically, when the above situation occurs, that is, there is no hive table matching the synchronization destination address in the data warehouse, synchronizing the target data to the hive table matching the synchronization destination address in the data warehouse includes:
[0068] Call the data lake interface to write the target data into the distributed file system HDFS file;
[0069] If there is no hive table matching the synchronization destination address in the data warehouse, the data lake interface is called to create a hive table in the data warehouse based on the HDFS file, and synchronize the target data in the HDFS file to the hive table, where the hive table matches the synchronization destination address of the target data.
[0070] Among them, calling the data lake interface to write the target data into the HDFS file is only one implementation method. You can also call the data lake interface to write the target data into the directional storage system, and then call the data lake interface to create a hive table based on the data in the directional storage system.
[0071] Among them, the data lake interface is called to create a table in the data warehouse based on the HDFS file. Specifically, a hive table can be created in the data warehouse based on the HDFS file, and the HDFS file is connected and integrated with the metadata of the hive table in the data warehouse in the form of a table structure. That is, a hive table is created in the form of the metadata of the hive table in the data warehouse, and the data writing path of the HDFS file synchronized to the hive table in the data warehouse is recorded, so that the synchronized target data can be found based on the writing path later.
[0072] It should be understood that the data warehouse consists of two parts: the table structure and the data used to fill the table structure. The data warehouse can be divided into internal tables and external tables. The internal table means that after the data is written into the table structure, the data in the internal table has only a unique storage path, and the data and the table structure are an integral relationship. For the external table, the data and the table structure are separated. The data and the table structure of the external table are associated through the location in the table structure that points to the location of the data. The advantage of the external table is that it can be established in real time as needed, and even if the established external table is deleted in the data warehouse, for example, if some errors occur, only the table structure of the external table is deleted, and the data stored in the external table is not deleted.
[0073] Based on this advantage of external tables, the embodiment of the present application stores the target data to be synchronized to the data warehouse in the HDFS file. The HDFS file stores the real content of the target data, and then calls the data lake interface to create a hive table in the data warehouse based on the HDFS file. That is, based on the location of the HDFS file, the data content in the HDFS file is associated with the table structure of the hive table in the data warehouse, thereby realizing the creation of the hive table in the data warehouse.
[0074] In addition, when calling the data lake interface to write data to the HDFS file, many small files with a file size of 256M (such as files of several k or several M) may be generated. Once the number of such small files increases to a certain order of magnitude, it will affect the query performance of the data warehouse and the instability of the cluster. In order to solve this problem, the embodiment of the present application will also use the feature of the data lake to automatically manage small files when writing data to the HDFS file. Once a small file is generated when the data lake writes data, the next time the data is written, it will continue to write data based on the small file, that is, it can realize the merge operation of multiple small files. Moreover, the data lake interface can also provide snapshot isolation for reads and writes, that is, to ensure that the target data is not changed during the process of writing to the HDFS file.
[0075] Specifically, when the above situation 2 occurs, that is, there is a hive table in the data warehouse that matches the synchronization destination address, the target data in the HDFS file can be directly synchronized to the hive table. Specifically, the method provided in the embodiment of the present application also includes:
[0076] If there is a hive table in the data warehouse that matches the synchronization destination address, synchronize the target data in the HDFS file to the hive table.
[0077] Optionally, to facilitate the determination of the synchronization processing method of the target data, the sender of the target data, such as the target application, can pre-agreed with the data synchronization platform on the definition of some specified fields, which are used to indicate the synchronization processing method of adding / deleting / modifying the target data. Specifically, synchronizing the target data in the HDFS file to the hive table includes:
[0078] Determine the specified field name contained in the target data;
[0079] Based on the specified field name, determine the synchronization processing mode of the target data, which synchronization processing mode includes one of adding, deleting, and modifying;
[0080] Based on the synchronization processing method of the target data, call the data lake interface to synchronize the target data to the hive table.
[0081] When the synchronization processing mode of the target data is determined to be add based on the specified field name, the data lake interface can be called to write the target data into the hive table that matches the synchronization destination address; when the synchronization processing mode of the target data is determined to be delete based on the specified field name, the data lake interface can be called to delete the target data in the hive table that matches the synchronization destination address; when the synchronization processing mode of the target data is determined to be modify based on the specified field name, the data lake interface can be called to modify the data at the specified location in the hive table that matches the synchronization destination address to the target data.
[0082] Optionally, in the process of synchronizing the target data to the data warehouse, it is very likely that the data synchronization fails due to the program setting problem of the synchronization platform. In order to promptly discover the data that failed to synchronize, the embodiment of the present application can count whether the number of target data is consistent with the number of data in the hive table synchronized to the data warehouse. Specifically, after synchronizing the target data to the hive table in the data warehouse that matches the synchronization destination address, the method further includes:
[0083] Determine the first data quantity of the target data to be written into the hive table;
[0084] determining a second data quantity of the target data;
[0085] If the second data quantity is greater than the first data quantity, the data that failed to be synchronized is obtained to resynchronize the data that failed to be synchronized to the data warehouse.
[0086] The first data quantity of the target data written into the hive table can be sent by the data synchronization platform to the monitoring kafka, and the second data quantity of the target data can be sent by the target application to the monitoring kafka. The monitoring kafka sends the two data to MySQL for association, and issues an alarm message when the second data quantity is greater than the first data quantity, so that the synchronization platform obtains the data that failed to be synchronized, and resynchronizes the data that failed to be synchronized to the data warehouse.
[0087] It should be noted that, since the first data middleware Kafka cannot directly query the data volume like a traditional database, the second data quantity of the target data can be determined by counting the second data quantity of the target data by dotting at the target data sending end (such as the target application), and the first data quantity of the target data written to the hive table can be determined by dotting on the data synchronization platform. Then, the first data quantity obtained by dotting at the target data sending end and the second data quantity obtained by dotting on the data synchronization platform are compared to determine whether the first data quantity and the second data quantity are consistent, and then determine whether there is data in the target data that fails to synchronize.
[0088] After obtaining the data that failed to be synchronized, you can re-execute the data synchronization process, that is, perform format verification on the data that failed to be synchronized. If the format verification of the data that failed to be synchronized passes, perform type mapping on the data that failed to be synchronized to obtain data that matches the data type in the data warehouse. Finally, call the data lake interface to synchronize the type-mapped data to the data warehouse.
[0089] Optionally, in order to avoid the situation where the data synchronization process still fails after multiple data synchronization failures, resulting in waste of resources caused by repeated execution of the data synchronization process, a threshold can be set for the number of times the data synchronization process is repeated for data synchronization failures. If the preset threshold is reached, an alarm message can be issued so that the maintenance personnel of the data synchronization platform can promptly discover problems in the data synchronization process. Specifically, the method also includes:
[0090] If the number of synchronization loss of the synchronized data reaches a preset threshold, an alarm message is issued.
[0091] As an example, the preset threshold can be set to three times, that is, each time data that fails to synchronize occurs, the data synchronization process is re-executed. If the data that failed to synchronize still fails to synchronize successfully after repeating the data synchronization process three times, an alarm message is issued to allow the maintenance personnel of the data synchronization platform to perform loss analysis on the data that was lost.
[0092] Combine the following Figure 2 and Figure 3 An example diagram describing a practical scenario of the application of the data synchronization method is shown in Figure 2 In the data synchronization method, the system includes the target application of the sender of the target data, Kafka, schema registry, data synchronization platform, data lake and data warehouse. The interaction process between these modules includes:
[0093] S31, constructing a metadata identifier.
[0094] Specifically, the target application may construct the metadata identifier according to the library name, table name, rowkey field name, partition field name, and partition value field in the data warehouse.
[0095] S32: construct metadata description information based on the metadata identifier.
[0096] Specifically, the target application can construct metadata description information based on the metadata identifier, that is, describe the metadata identifier and define the data type, data declaration, attributes and other information of the data content corresponding to the metadata identifier.
[0097] S33, calling the SDK provided by the data synchronization platform to send the target data generated by the target application.
[0098] Specifically, the target application can call the SDK provided by the data synchronization platform to send the target data, where the SDK provided by the data synchronization platform is used to standardize the target data sent by the target application, that is, the data sent by the target application is required to contain a metadata identifier (MessageKey) and the corresponding data content (kafka value).
[0099] More specifically, the target application sends the target data generated by it to the first data middleware kafka, and sends the metadata description information constructed by it to the second data middleware schema registry.
[0100] S34, calling the SDK provided by the data synchronization platform to send the second data quantity of the target data.
[0101] Specifically, the target application may call the SDK provided by the data synchronization platform to send the second data quantity of the key-value pair data of the target application to the monitoring kafka.
[0102] S35, based on the synchronization requirement of the target data, obtaining synchronization configuration information of the target data.
[0103] Specifically, the data synchronization platform can obtain the synchronization configuration information of the target data based on the synchronization requirements of the target data, wherein the synchronization configuration information of the target data includes the source address of the target data and the synchronization destination address of the target data.
[0104] S36, acquiring target data based on the source address of the target data.
[0105] Specifically, the data synchronization platform can first obtain the data file corresponding to the target data from the first data middleware kafka based on the source address of the target data, and obtain the metadata description information of the target data from the second data middleware schemaregistry based on the source address of the target data; then the data synchronization platform parses the data file corresponding to the target data based on the metadata description information of the target data to obtain the target data.
[0106] S37, verify whether the format of the target data complies with the specification.
[0107] Specifically, the data synchronization platform can verify whether the format of the target data complies with the specification based on the agreed data format, such as whether it contains the specified field names such as the primary key field and partition field. If the format of the target data does not comply with the rules, an alarm message will be issued.
[0108] S38, performing type mapping on the target data.
[0109] Specifically, the data synchronization platform can perform type mapping on the target data to obtain data that matches the data type in the data warehouse.
[0110] S39, write the type-mapped data into the HDFS file.
[0111] Specifically, the data synchronization platform can call the data lake interface to write the target data after type mapping into the HDFS file.
[0112] S310, creating a hive table in the data warehouse based on the HDFS file.
[0113] Specifically, the data synchronization platform can call the data lake interface to create a hive table in the data warehouse based on the HDFS file.
[0114] S311, sending the first data quantity of the target data written into the hive table.
[0115] Specifically, the data synchronization platform may send the first data quantity of the target data written into the hive table to the monitoring kafka.
[0116] S312: When the first data quantity is inconsistent with the second data quantity, an alarm message is issued.
[0117] The monitoring kafka sends the first data quantity and the second data quantity to MySQL for association, and when it is determined in MySQL that the first data quantity and the second data quantity are inconsistent, an alarm message is issued.
[0118] By adopting the data synchronization method provided in the embodiment of the present application, a data synchronization platform is additionally added outside the data warehouse, and the data synchronization operation is performed by the data synchronization platform. After the target data is generated, if there is a synchronization requirement for the target data, the synchronization requirement of the target data can be sent to the data synchronization platform. The data synchronization platform obtains the source address and the synchronization destination address in the synchronization configuration information of the target data based on the synchronization requirement of the target data, so that the target data can be obtained from the data middleware based on the source address, and the obtained target data can be synchronized to the hive table in the data warehouse that matches the synchronization destination address, thereby realizing the automatic operation of synchronizing the target data to the data warehouse, reducing the manual docking cost in the data synchronization process, shortening the data synchronization cycle, and effectively improving the data synchronization efficiency.
[0119] In order to solve the problems existing in the prior art, such as Figure 4 As shown, the embodiment of the present application further provides a data synchronization platform 400, including:
[0120] An address acquisition unit 401 is used to acquire a source address and a synchronization destination address in the synchronization configuration information of the target data based on the synchronization requirement of the target data;
[0121] A data acquisition unit 402, configured to acquire the target data from the data middleware based on the source address;
[0122] The data synchronization unit 403 is used to synchronize the target data to a hive table in the data warehouse that matches the synchronization destination address.
[0123] In an embodiment of the present application, a data synchronization platform is additionally added in addition to the data warehouse, and the data synchronization operation is performed by the data synchronization platform. After the target data is generated, if there is a synchronization requirement for the target data, the synchronization requirement for the target data can be sent to the data synchronization platform. The data synchronization platform obtains the source address and the synchronization destination address in the synchronization configuration information of the target data based on the synchronization requirement of the target data, so that the target data can be obtained from the data middleware based on the source address, and the obtained target data can be synchronized to the hive table in the data warehouse that matches the synchronization destination address, thereby realizing the automated operation of synchronizing the target data to the data warehouse, reducing the manual docking cost in the data synchronization process, shortening the data synchronization cycle, and effectively improving the data synchronization efficiency.
[0124] Optionally, in an implementation manner, the data middleware includes a first data middleware and a second data middleware, and the data acquisition unit 402 is used to:
[0125] Based on the source address, determining a designated subject corresponding to the target data from the first data middleware, and acquiring a data file corresponding to the target data from the designated subject;
[0126] Based on the source address, obtaining metadata description information of the target data from the second data middleware;
[0127] Based on the metadata description information, the data file is parsed to obtain the target data, which includes a metadata identifier and corresponding data content.
[0128] Optionally, in one implementation, the data synchronization unit 403 is configured to:
[0129] Performing format verification on the target data, and if the target data passes the format verification, performing type mapping on the metadata identifier in the target data, and converting the metadata identifier in the target data into the metadata identifier in the data warehouse;
[0130] The data lake interface is called to synchronize the target data to the hive table in the data warehouse that matches the synchronization destination address.
[0131] Optionally, in one implementation, the data synchronization unit 403 is configured to:
[0132] Call the data lake interface to write the target data into a distributed file system HDFS file;
[0133] If there is no hive table matching the synchronization destination address in the data warehouse, the data lake interface is called to create a hive table in the data warehouse based on the HDFS file, and the target data in the HDFS file is synchronized to the hive table, wherein the hive table matches the synchronization destination address in the data warehouse.
[0134] Optionally, in one implementation, the data synchronization unit 403 is further configured to:
[0135] If there is a hive table matching the synchronization destination address in the data warehouse, the target data in the HDFS file is synchronized to the hive table.
[0136] Optionally, in one implementation, the data synchronization unit 403 is configured to:
[0137] Determine the specified field name contained in the target data;
[0138] Based on the specified field name, determining a synchronization processing mode of the target data, wherein the synchronization processing mode includes one of adding, deleting, and modifying;
[0139] Based on the synchronization processing method of the target data, the data lake interface is called to synchronize the target data into the hive table.
[0140] Optionally, in one implementation, after the data synchronization unit 403 synchronizes the target data to a hive table in the data warehouse that matches the synchronization destination address, the data synchronization platform further includes:
[0141] A first determining unit, configured to determine a first data quantity of target data to be written into the hive table;
[0142] A second determining unit, configured to determine a second data quantity of the target data;
[0143] A resynchronization unit is used to obtain the data that failed to be synchronized if the second data quantity is greater than the first data quantity, so as to resynchronize the data that failed to be synchronized to the data warehouse.
[0144] Optionally, in one implementation, the data synchronization platform further includes:
[0145] The alarm unit is used to issue an alarm message if the number of synchronization failures of the data that failed to synchronize reaches a preset threshold.
[0146] Among them, the above modules in the data synchronization device provided by the embodiment of the present application can also implement the data synchronization method steps provided by the above data synchronization method embodiment. Alternatively, the device provided by the embodiment of the present application can also include other modules in addition to the above modules to implement the data synchronization method steps provided by the above method embodiment. And the device provided by the embodiment of the present application can achieve the technical effects that can be achieved by the above data synchronization method embodiment.
[0147] Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of this specification. Figure 5 At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. The memory may include a memory, such as a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage. Of course, the electronic device may also include hardware required for other services.
[0148] The processor, network interface and memory can be interconnected through an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0149] The memory is used to store the program. Specifically, the program may include a program code, and the program code includes a computer operation instruction. The memory may include a memory and a non-volatile memory, and provides instructions and data to the processor.
[0150] The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it, forming a data synchronization device at the logical level. The processor executes the program stored in the memory and is specifically used to perform the following operations:
[0151] Based on the synchronization requirements of the target data, obtaining the source address and the synchronization destination address in the synchronization configuration information of the target data;
[0152] Based on the source address of the target data, obtaining the target data from the data middleware;
[0153] The target data is synchronized to a hive table in the data warehouse that matches the synchronization destination address.
[0154] The electronic device provided in the embodiment of the present application adds an additional data synchronization platform in addition to the data warehouse, and the data synchronization platform performs data synchronization operations. After the target data is generated, if there is a synchronization requirement for the target data, the synchronization requirement for the target data can be sent to the data synchronization platform, and the data synchronization platform obtains the source address and the synchronization destination address in the synchronization configuration information of the target data based on the synchronization requirement of the target data, so that the target data can be obtained from the data middleware based on the source address, and the obtained target data can be synchronized to the hive table in the data warehouse that matches the synchronization destination address, thereby realizing the automatic operation of synchronizing the target data to the data warehouse, reducing the manual docking cost in the data synchronization process, shortening the data synchronization cycle, and effectively improving the data synchronization efficiency.
[0155] The above is as in this manual Figure 1 to Figure 3The method performed by the data synchronization device disclosed in the illustrated embodiment can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor or an instruction in the form of software. The above processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of this specification can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of this specification can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module can be located in a mature storage medium in the field such as random access memory, flash memory, read-only memory, programmable read-only memory or electrically erasable programmable memory, register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.
[0156] The electronic device may also perform Figure 1 to Figure 3 The method and the data synchronization device are implemented in Figure 1 to Figure 3 The functions of the illustrated embodiments will not be described in detail in the embodiments of this specification.
[0157] The embodiment of the present specification also provides a computer-readable storage medium, which stores one or more programs, wherein the one or more programs include instructions, which, when executed by a portable electronic device including a plurality of application programs, enable the portable electronic device to execute Figure 1 to Figure 3 The method of the embodiment shown is specifically used to perform the following operations:
[0158] Based on the synchronization requirements of the target data, obtaining the source address and the synchronization destination address in the synchronization configuration information of the target data;
[0159] Based on the source address of the target data, obtaining the target data from the data middleware;
[0160] The target data is synchronized to a hive table in the data warehouse that matches the synchronization destination address.
[0161] The computer-readable storage medium provided in the embodiment of the present application adds an additional data synchronization platform outside the data warehouse, and the data synchronization operation is performed by the data synchronization platform. After the target data is generated, if there is a synchronization requirement for the target data, the synchronization requirement of the target data can be sent to the data synchronization platform, and the data synchronization platform obtains the source address and the synchronization destination address in the synchronization configuration information of the target data based on the synchronization requirement of the target data, so that the target data can be obtained from the data middleware based on the source address, and the obtained target data can be synchronized to the hive table in the data warehouse that matches the synchronization destination address, thereby realizing the automatic operation of synchronizing the target data to the data warehouse, reducing the manual docking cost in the data synchronization process, shortening the data synchronization cycle, and effectively improving the data synchronization efficiency.
[0162] Of course, in addition to software implementation, the electronic device of this specification does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0163] The above is a description of a specific embodiment of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0164] In short, the above description is only a preferred embodiment of this specification and is not intended to limit the protection scope of this specification. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification shall be included in the protection scope of this specification.
[0165] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0166] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0167] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0168] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
Claims
1. A data synchronization method, It is characterized in that The method is applied to a data synchronization platform, and includes: Based on the synchronization requirements of the target data, obtaining the source address and the synchronization destination address in the synchronization configuration information of the target data; Based on the source address, obtaining the target data from the data middleware; Synchronize the target data to a hive table in the data warehouse that matches the synchronization destination address; The data middleware includes a first data middleware and a second data middleware, and obtaining the target data from the data middleware based on the source address includes: Based on the source address, determining a designated subject corresponding to the target data from the first data middleware, and acquiring a data file corresponding to the target data from the designated subject; Based on the source address, obtaining metadata description information of the target data from the second data middleware; Based on the metadata description information, the data file is parsed to obtain the target data, which includes a metadata identifier and corresponding data content; the metadata identifier is constructed based on the library name, table name, rowkey field name, partition field name, and partition value field in the data warehouse.
2. The method according to claim 1, It is characterized in that Synchronizing the target data to a hive table in the data warehouse that matches the synchronization destination address includes: Performing format verification on the target data, and if the target data passes the format verification, performing type mapping on the metadata identifier in the target data, and replacing the metadata identifier in the target data with the metadata identifier in the data warehouse; The data lake interface is called to synchronize the target data to the hive table in the data warehouse that matches the synchronization destination address.
3. The method as claimed in claim 2, It is characterized in that Synchronizing the target data to a hive table in the data warehouse that matches the synchronization destination address includes: Call the data lake interface to write the target data into a distributed file system HDFS file; If there is no hive table matching the synchronization destination address in the data warehouse, the data lake interface is called to create a hive table in the data warehouse based on the HDFS file, and the target data in the HDFS file is synchronized to the hive table, wherein the hive table matches the synchronization destination address of the target data.
4. The method according to claim 3, It is characterized in that The method further comprises: If there is a hive table matching the synchronization destination address in the data warehouse, the target data in the HDFS file is synchronized to the hive table.
5. The method according to claim 3 or 4, It is characterized in that The step of synchronizing the target data in the HDFS file to the hive table includes: Determine the specified field name contained in the target data; Based on the specified field name, determining a synchronization processing mode of the target data, wherein the synchronization processing mode includes one of adding, deleting, and modifying; Based on the synchronization processing method of the target data, the data lake interface is called to synchronize the target data into the hive table.
6. The method according to claim 1, It is characterized in that After synchronizing the target data to a hive table in the data warehouse that matches the synchronization destination address, the method further includes: Determine a first data quantity of target data to be written into the hive table; Determining a second data quantity of the target data; If the second data quantity is greater than the first data quantity, the data that failed to be synchronized is obtained to resynchronize the data that failed to be synchronized to the data warehouse.
7. The method according to claim 6, It is characterized in that The method further comprises: If the number of synchronization failures of the data that failed to be synchronized reaches a preset threshold, an alarm message is issued.
8. A data synchronization platform, It is characterized in that include: An address acquisition unit, configured to acquire a source address and a synchronization destination address in the synchronization configuration information of the target data based on a synchronization requirement of the target data; A data acquisition unit, configured to acquire the target data from the data middleware based on the source address; A data synchronization unit, used to synchronize the target data to a hive table in the data warehouse that matches the synchronization destination address; The data acquisition unit is specifically used for: Based on the source address, determining a designated subject corresponding to the target data from the first data middleware, and acquiring a data file corresponding to the target data from the designated subject; Based on the source address, obtaining metadata description information of the target data from the second data middleware; Based on the metadata description information, the data file is parsed to obtain the target data, wherein the target data includes a metadata identifier and corresponding data content; The metadata identifier is constructed based on the library name, table name, rowkey field name, partition field name, and partition value field in the data warehouse.
9. An electronic device, It is characterized in that include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the data synchronization method according to any one of claims 1 to 7.
10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data synchronization method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Method for processing message based on kafka
CN106487891A
Data synchronization method and device
CN110851511A
Big data processing method for realizing mixed transaction analysis
CN112711593A
System for automatically realizing data real-time synchronization
CN113468170A
Data acquisition method for multi-source science and technology innovation resources
CN113918793A
