CN112181937A - Data transmission method and device - Google Patents

Data transmission method and device Download PDF

Info

Publication number
CN112181937A
CN112181937A CN201910599964.5A CN201910599964A CN112181937A CN 112181937 A CN112181937 A CN 112181937A CN 201910599964 A CN201910599964 A CN 201910599964A CN 112181937 A CN112181937 A CN 112181937A
Authority
CN
China
Prior art keywords
data
file
target
storage device
database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201910599964.5A
Other languages
Chinese (zh)
Other versions
CN112181937B (en
Inventor
周振华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Zhenshi Information Technology Co Ltd
Original Assignee
Beijing Jingdong Zhenshi Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Zhenshi Information Technology Co Ltd filed Critical Beijing Jingdong Zhenshi Information Technology Co Ltd
Priority to CN201910599964.5A priority Critical patent/CN112181937B/en
Publication of CN112181937A publication Critical patent/CN112181937A/en
Application granted granted Critical
Publication of CN112181937B publication Critical patent/CN112181937B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/214Database migration support
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

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

Abstract

The invention discloses a method and a device for carrying out data transmission, and relates to the technical field of computers. One embodiment of the method comprises: acquiring a log file of a source database, analyzing the log file, and determining a data slave table associated with a data master table to be carried out transfer and an association relation between the data master table and the data slave table; configuring data carry-over information according to the incidence relation; inquiring data to be subjected to carry out carry-over according to the data carry-over information and storing the data to be carried over into a storage device; and writing the data to be carried forward in the storage device into the target database. According to the embodiment, the log files of the source database are analyzed, the data tables which are correlated with each other are determined, the correlation relationship among the data tables can be further determined, and the data forwarding information is configured based on the correlation relationship to perform data forwarding, so that the data subordinate tables correlated with the data main table can be avoided from being omitted, the data relationship between the forwarded source database and the target database is complete, data maintenance is facilitated, and the labor cost is reduced.

Description

Data transmission method and device
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for carrying out data transmission.
Background
With the continuous development of computer application systems, the amount of data in a database is continuously increasing, and when the amount of data in the database reaches a certain magnitude, the speed of data operation is inevitably affected, most of data is data long before the database is, and the liveness of the data is lost, so that the data needs to be transferred to other databases, such as a historical database, so that the volume of the current database is reduced, and the influence of a large amount of invalid data on the data operation is reduced. The data transfer mainly refers to transferring part or all of data in one database to another database.
At present, the common data carrying-over method includes: manual carry-over and with the help of carry-over tools. However, in the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art: the manual tie-up needs research personnel and a Database Administrator (DBA for short) to complete together, but the Database Administrator cannot know actual business, and has high communication cost and high labor cost. Moreover, for a database administrator unfamiliar with business data, when data is carried out, the data tables related to each other are easily missed or the association relationship between the data tables is easily confused, so that the data relationship is incomplete, or even the data is disorderly lost. Most of the forwarding tools are single-table forwarding, a forwarding task needs to be created for each table, the forwarding task is executed one by one, the time consumption is long, the single-table forwarding is generally performed according to time, and data time points of data associated from the tables are not necessarily the same, so that the forwarding is uniformly performed according to a certain time point, the relationship of forwarding data is incomplete, and some data cannot be associated due to query of a historical database or a current database.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for data forwarding, which determine data tables associated with each other by analyzing log files of a source database, and further may determine an association relationship between the data tables, and configure data forwarding information to perform data forwarding based on the association relationship, so as to avoid missing a data secondary table associated with a data primary table, ensure that a data relationship between a forwarded source database and a target database is complete, facilitate data maintenance, and further reduce labor cost.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a method of forwarding data, including:
acquiring a log file of a source database, analyzing the log file, and determining a data slave table associated with a data master table to be carried out transfer and an association relation between the data master table and the data slave table;
configuring data transfer information based on the incidence relation, wherein the data transfer information at least comprises configuration transfer conditions and incidence fields;
inquiring data to be subjected to forward from a source database according to the forward condition and the associated field, and storing the inquired data to be subjected to forward into a storage device;
and reading the data to be transferred from the storage device and writing the data to the target database.
Optionally, determining a target master table and a target slave table corresponding to the data master table and the data slave table in a target database according to the table names; detecting whether the structure of the target master table is consistent with that of the data master table and whether the structure of the target slave table is consistent with that of the data slave table; and if the data are inconsistent, the structures of the target master table and the target slave table are changed by taking the data master table and the data as standards.
Optionally, after storing the queried data to be carried forward in the storage unit, the method further includes: generating a write notification; reading data to be carried forward from the storage device and writing to the target database comprises: and responding to the write notification, reading the data to be transferred from the storage device, and writing the data to a target database.
Optionally, the step of storing the queried data to be carried forward to the storage device includes: generating a data file according to the inquired data to be subjected to carry-over, wherein the data file is used for recording the data to be subjected to carry-over; segmenting the data file to obtain a plurality of subdata files and attribute information of each subdata file; generating corresponding file path information according to the attribute information of each sub data file; storing the plurality of subdata files and corresponding file path information to a storage device;
reading data to be carried forward from the storage device and writing to a target database comprises: and inquiring the subdata files according to the file path information, reading data to be converted from the inquired subdata files, and writing the data into a target database.
Optionally, the step of storing the queried data to be carried forward to the storage device includes: generating a primary key file according to the inquired data to be subjected to carry out carry-over, wherein the primary key file is used for recording primary key information of the data to be subjected to carry-over and storing the primary key file to a storage device;
after writing to the target database, the method further comprises: verifying the data to be carried forward in the target database according to a preset rule; if the verification is successful, deleting the data to be transferred in the source database according to the primary key file; and if the verification fails, rolling back to the data to be rolled in the target database.
To achieve the above object, according to another aspect of an embodiment of the present invention, there is provided an apparatus for forwarding data, including: the determining module is used for acquiring a log file of a source database, analyzing the log file, and determining a data slave table associated with a data master table to be carried forward and an association relation between the data master table and the data slave table; the information configuration module is used for configuring data transfer-forward information based on the incidence relation, and at least comprises configuration transfer-forward conditions and incidence fields; the data preparation module is used for inquiring data to be subjected to forward from a source database according to the forward condition and the associated field and storing the inquired data to be subjected to forward into the storage device; and the data transfer module is used for reading the data to be transferred from the storage device and writing the data into a target database.
Optionally, the apparatus further comprises a detection module configured to: determining a target master table and a target slave table corresponding to the data master table and the data slave table in a target database according to the table names; detecting whether the structure of the target master table is consistent with that of the data master table and whether the structure of the target slave table is consistent with that of the data slave table; and if the data are inconsistent, the structures of the target master table and the target slave table are changed by taking the data master table and the data as standards.
Optionally, the data preparation module is further configured to: generating a write notification after storing the inquired data to be transferred into a storage unit;
the data carry forward module is further configured to: and responding to the write notification, reading the data to be transferred from the storage device, and writing the data to a target database.
Optionally, the data forwarding module is further configured to: generating a data file according to the inquired data to be subjected to carry-over, wherein the data file is used for recording the data to be subjected to carry-over; saving the data file to a storage device; segmenting the data file to obtain a plurality of subdata files and attribute information of each subdata file; generating corresponding file path information according to the attribute information of each sub data file; storing the plurality of subdata files and corresponding file path information to a storage device;
the data carry forward module is further configured to: and inquiring the subdata files according to the file path information, reading data to be converted from the inquired subdata files, and writing the data into a target database.
Optionally, the data preparation module is further configured to: generating a primary key file according to the inquired data to be subjected to carry out carry-over, wherein the primary key file is used for recording primary key information of the data to be subjected to carry-over and storing the primary key file to a storage device;
the data carry forward module is further configured to: after the data is written into the target database, verifying the data to be transferred into the target database according to a preset rule; if the verification is successful, deleting the data to be transferred in the source database according to the primary key file; and if the verification fails, rolling back to the data to be rolled in the target database.
To achieve the above object, according to still another aspect of an embodiment of the present invention, there is provided an electronic apparatus including: one or more processors; a storage device for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement the method of carrying forward data of an embodiment of the present invention.
To achieve the above object, according to an aspect of the embodiments of the present invention, there is provided a computer readable medium having stored thereon a computer program which, when executed by a processor, implements a method of carrying out the data of the embodiments of the present invention.
One embodiment of the above invention has the following advantages or benefits: the data balance method comprises the steps of determining data tables which are correlated with each other by analyzing log files of a source database, further determining the correlation between the data tables, configuring data balance information based on the correlation, wherein the data balance information at least comprises balance conditions and correlation fields, inquiring data to be balanced in the source database according to the balance conditions and the correlation fields, storing the inquired data to be balanced in a storage device, reading the data to be balanced from the storage device, and writing the data to a target database, thereby completing data balance, so that a secondary data table which is correlated with a primary data table can be avoided from being omitted, the complete data relation between the source database and the target database after balance is ensured, data maintenance is facilitated, and labor cost is reduced; the data to be converted in the source database is stored in the storage device, and then the data to be converted is read from the storage device and written into the target database, so that asynchronous conversion can be realized, and the conversion efficiency is improved.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of a main flow of a method of forwarding data according to an embodiment of the present invention;
FIG. 2-1 is data carry forward information configured in accordance with a method of carrying forward data according to an embodiment of the present invention;
FIG. 2-2 is data carry forward information configured in accordance with a method of carrying forward data according to another embodiment of the present invention;
FIGS. 2-3 are schematic diagrams of a main flow of a method of forwarding data according to another embodiment of the present invention;
FIG. 3 is a schematic diagram of a main flow of a method of forwarding data according to yet another embodiment of the present invention;
FIG. 4 is a schematic diagram of the main blocks of an apparatus for forwarding data according to an embodiment of the present invention;
FIG. 5 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 6 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic flow chart of main steps of a method for forwarding data according to an embodiment of the present invention, as shown in fig. 1, the method includes:
step S101: the method comprises the steps of obtaining a log file of a source database, analyzing the log file, and determining a data slave table associated with a data master table to be carried forward and an association relation between the data master table and the data slave table. In this embodiment, the slave data table may also be referred to as an association table.
In this step, the log file may be a binlog log. The binlog log is a binary log of the database, and is used for recording SQL statements (Structured Query Language, which is a kind of database Query and programming Language) operated on the database by a user.
Specifically, the log file of the source database may be obtained in the following two ways:
(1) and connecting the source database, opening the log acquisition permission of the source database, and directly acquiring the log file from the source database.
(2) A dump request (dump is a backup command, a directory or the whole file system can be backed up) is sent from a database (MySQL slave) to a source database by using an open source tool (for example, canal) simulation to acquire real-time log information, and the acquired log information is generated into a log file.
After the log file is obtained, the log file is analyzed to obtain SQL statements, and a data slave table related to a data master table to be converted and the association relation between the data master table and the data slave table can be determined according to the SQL statements related to the table name query of the data table to be converted. For example, the table name of the main data table to be carried forward is Tm, and the parsed SQL statement is: name, m.id, r.mark from Tm m left join Tr on r.tm _ id ═ m.id where m.create _ time < ═ 2019-04-15'. According to the SQL statement, the data slave table associated with the data master table Tm to be transferred is determined to be Tr, and the association relationship between the data master table Tm to be transferred and the data slave table Tr is as follows: the data master table is associated with the data slave table through id.
In the step, all the data slave tables associated with the data master table to be converted and the association relationship between each data slave table and the data master table can be automatically acquired by analyzing the log file of the source database, so that the data slave tables associated with the data master table can be prevented from being omitted, and prompt information can be sent to personnel unfamiliar with service data.
In an optional embodiment, the data forwarding method further includes:
determining a target master table and a target slave table corresponding to the data master table and the data slave table in a target database according to the table names;
detecting whether the structure of the target master table is consistent with that of the data master table and whether the structure of the target slave table is consistent with that of the data slave table;
and if the data are inconsistent, the structures of the target master table and the target slave table are changed by taking the data master table and the data as standards.
Specifically, different table structure query statements are executed according to different database types to respectively obtain the table structures of the source database and the target database, for example, the MySQL database may execute the statement acquisition of the show create table … …, desc, and the like. And then comparing the table structures of the data tables of the source database and the target database to obtain a difference, and eliminating the structural difference of the target database by taking the source database as a standard.
Step S102: and configuring data transfer information based on the association relationship, wherein the data transfer information at least comprises configuration transfer conditions and association fields.
In the previous step, all the data slave tables associated with the data master table to be subjected to the forwarding balancing and the association relationship between each data slave table and the data master table are determined, and in this step, a forwarding balancing condition of the data master table can be set according to a service requirement or a forwarding balancing requirement, and the forwarding balancing condition is used for screening out the data to be subjected to the forwarding balancing in the data master table. As a specific example, a certain time node (e.g., completion time) may be used as the carry-over condition, and data before or after the time node may be used as data to be carried over, such as "where _ time >' yyyyyy-mm-dd". The data slave table then sets the data slave table needing to be carried forward and the corresponding associated field of the data slave table.
The association field may be used to limit the scope of the data associated with the data master table, and the association field may be determined according to the association relationship. As an example, the data master table is an order table, the data slave table is an order detail table, and when the order data in the order table is finished, the detail information of the related order can be transferred from the order detail table according to the related field. If there are multiple data slave tables associated with the data master table, an association field needs to be configured for each data slave table. If there is a data table associated with the data slave table, the data table may be configured with a corresponding association field.
As an example, as shown in fig. 2-1, if the master table Tm is a master table of data to be transferred, a transfer condition of the master table Tm is configured, and if tables Tr1 and Tr2 are slave tables of data associated with the master table Tm, association fields of tables Tr1 and Tr2 are configured, respectively, and tables Tr1 and Tr2 may be used as primary slave tables of data. Table Tr3 is the data slave table associated with table Tr1, then the associated fields of table Tr3 are configured and table Tr3 can be the secondary data slave table.
In an alternative embodiment, the data forwarding condition of the slave table may also be configured when the data forwarding information is configured. In this embodiment, the range of the data to be transferred from the table with the data can be determined by the associated field of the configuration data slave table, and the data to be transferred can be further screened from the range by the transfer condition of the configuration data slave table. As an example, as shown in fig. 2-2, the junction conditions are configured for the data from tables Tr1, Tr2, and Tr3 in this fig. 2-2, respectively.
Step S103: and inquiring data to be subjected to forward from the source database according to the forward condition and the associated field, and storing the inquired data to be subjected to forward to a storage device.
In this embodiment, after the configuration of the data forwarding information is completed, forwarding check may be performed, specifically, the data main table may be checked preferentially, that is, data to be forwarded by the data main table is queried in the source database according to the forwarding condition. If the data can not be inquired, prompt information can be output, for example, the data to be forwarded of the data main table can not be inquired according to the forwarding condition, and the data can not be forwarded. If the data master table passes the verification, each data slave table may be verified respectively, and specifically, the data to be transferred in the data slave table may be queried in the source database according to the level of the data slave table. If one of the data is not queried from the table, a prompt message, such as "data is not queried from table xx to data to be forwarded", may be output.
After the verification of the data master table and the data slave table is passed, the data to be transferred in the source database is stored in a storage device, for example, in a cloud, and then the data to be transferred is read from the data file of the storage device and written into a target database. The embodiment can carry out data transfer asynchronously, namely, the step of reading the data to be transferred from the source database and saving the data to be transferred into the storage device, and the step of reading the data to be transferred from the storage device and writing the data to be transferred into the target database can be executed asynchronously, thereby improving the data transfer efficiency. In addition, for the case of an excessively large amount of data, a transfer space may exist in which the intermediate database or the intermediate data table is used as transfer data, and the intermediate database or the intermediate data table stores the transfer data for a long time, which may consume a large amount of space to cause resource waste and may reduce the efficiency of subsequent transfer tasks.
In practical applications, a source database may include two databases: a master database and a slave database, the slave database being a backup of the master database. In order to reduce the impact on the master database, the slave database is queried when querying data to be carried forward.
Step S104: and reading the data to be transferred from the storage device and writing the data to the target database.
In an optional embodiment, after the data to be carried forward is stored in the storage unit, the data carrying method further includes: generating a write notification; and responding to the write notification, reading data to be transferred from the storage device, and writing the data to the target database.
In the embodiment, the process of writing the data to be transferred into the storage device and the process of writing the data to be transferred into the target database from the storage device can be layered in a notification manner, that is, the data transfer is asynchronously realized. Specifically, MQ or RPC may be employed to implement asynchronous forwarding data. The MQ (Message Queue) is a tool for communication between middleware and application programs, supports asynchronous communication, and realizes decoupling of the application programs. RPC (Remote Procedure Call) is a protocol for requesting services from a Remote computer program over a network without knowledge of underlying network technologies, and is a means for applications to implement communication after a layered architecture.
The data forwarding method of the embodiment of the invention determines the data tables which are correlated with each other by analyzing the log file of the source database, and further can determine the correlation between the data tables, configures data forwarding information based on the correlation, wherein the data forwarding information at least comprises forwarding conditions and correlation fields, queries the data to be forwarded in the source database according to the forwarding conditions and the correlation fields, stores the queried data to be forwarded into the storage device, reads the data to be forwarded from the storage device, and writes the data to be forwarded into the target database, thereby completing data forwarding.
As shown in fig. 2-3, in an alternative embodiment, the step S104 of reading the data to be transferred from the storage device and writing the data to the target database further includes:
respectively creating data transfer threads for the data master table and the data slave table to obtain a plurality of data transfer threads;
executing the multiple data carry-over threads based on a locking mechanism, and storing the inquired data to be carried over to a storage device;
and when the execution of the plurality of data transfer threads is finished, reading the data to be transferred from the storage device and writing the data to be transferred into the target database (namely the historical database).
In this embodiment, a data transfer thread may be created for each table by using the java multithreading mechanism, and the task of each data transfer thread is: and generating a data file according to the inquired data to be carried forward, wherein the data file is used for recording the data to be carried forward. The data file may be saved in a storage device, such as in the cloud, and then the data to be transferred is read from the data file in the storage device and written into the target database. The embodiment can carry out data transfer asynchronously, namely, the step of reading the data to be transferred from the source database and saving the data to be transferred into the storage device, and the step of reading the data to be transferred from the storage device and writing the data to be transferred into the target database can be executed asynchronously, thereby improving the data transfer efficiency.
When the plurality of data carry-over threads are executed, a java locking mechanism can be adopted, and after all the data carry-over threads are executed, the data to be carried over can be read from the storage device and written into the target database. Where java is a door-to-object programming language, latch is a synchronous tool class that can delay the progress of a thread until the latch reaches a termination state, and the latch can be used to ensure that some activities do not continue until other activities are completed.
In an alternative embodiment, when the generated data file is large, the following steps may be performed:
generating a data file according to the inquired data to be subjected to carry-over, wherein the data file is used for recording the data to be subjected to carry-over;
segmenting the data file to obtain a plurality of subdata files and attribute information of each subdata file;
generating corresponding file path information according to the attribute information of each sub data file;
storing the plurality of subdata files and corresponding file path information to a storage device;
and inquiring the subdata files according to the file path information, reading data to be converted from the inquired subdata files, and writing the data into the target database.
The attribute information of the sub data file may include a data table name, a data main key interval, and a time for creating the piece of data. According to the attribute information, file path information (KEY or URL) can be generated, the storage position of the sub-data files can be determined through the file path information, the splicing relation among the sub-data files can also be determined, and then the data to be converted in the sub-data files can be written into a target database in sequence.
In an alternative embodiment, executing the multiple data forwarding threads, and storing the queried data to be forwarded to the storage device includes: and generating a primary key file according to the inquired data to be subjected to carry out carry-over, wherein the primary key file is used for recording primary key information of the data to be subjected to carry-over and storing the primary key file in a storage device. The primary key file can be used as a basis for deleting the data to be transferred in the source database after the data transfer is completed.
After the inquired data to be carried forward is carried forward to a target database, verifying the data to be carried forward in the target database according to a preset rule; if the verification is successful, deleting the data to be transferred in the source database according to the primary key file; and if the verification fails, rolling back to the data to be rolled in the target database. The preset rule may be to check whether the data amount is consistent, and specifically includes one or more of the following: checking whether the data volume of the data master table and all the data slave tables in the target database is consistent with the data volume of the data master table at the cloud end and the data volume of the corresponding data slave tables; checking whether the data volumes of the data main table in the target database and the data main table in the cloud end are consistent or not; and checking whether the data volumes of the data tables appointed in the target database and the data tables corresponding to the cloud end are consistent or not. When the verification is passed, deleting the data to be transferred in the source database according to the primary key file; and when the verification fails, rolling back the data to be transferred to the target database, namely deleting the data to be transferred written into the target database.
Fig. 3 is a schematic diagram illustrating a main flow of a data forwarding method according to another embodiment of the present invention. With reference to fig. 2-3 and 3, the method comprises:
step S301: the method comprises the steps of obtaining a log file of a source database, analyzing the log file, and determining a data slave table associated with a data master table to be carried forward and an association relation between the data master table and the data slave table.
Step S302: setting a carry-over task: setting the carry-over condition of a data master table to be carried over and the associated field of a data slave table associated with the data master table, and setting the state of the carry-over task as initial.
Step S303: data query: and inquiring data to be carried forward from a database according to the carrying forward condition and the associated field. The source database may include two databases: a master database and a slave database, the slave database being a backup of the master database. In order to reduce the impact on the master database, the slave database is queried when querying data to be carried forward.
When the data to be carried forward cannot be inquired according to the carry forward condition, the state of the carry forward task is updated to be abnormal, and prompt information is output; and for the secondary data table to be carried out the transfer, when the secondary data table to be carried out the transfer cannot be inquired according to the associated field, updating the state of the transfer task to be a pause state, and outputting prompt information.
Step S304: acquiring data: and respectively establishing data transfer threads for the data master table and the data slave table to obtain a plurality of data transfer threads.
For each data carry-over thread, generating a data file and a main key file according to the inquired data to be carried over, wherein the data file is used for recording the data to be carried over, and the main key file is used for recording the main key information of the data to be carried over; and saving the data file and the primary key file to a storage device. And after all the data transfer threads finish working, updating the state of the transfer tasks to be ready data.
Step S305: writing into a target database: and when the execution of the plurality of data transfer threads is finished, reading the data to be transferred from the storage device and writing the data into the target database. And updating the state of the transfer-forward task to be in execution when the data to be transferred forward is written into the target database.
In an alternative embodiment, to improve the efficiency of the forward link, step S304 and step S305 may be performed asynchronously using MQ or RPC implementations. The MQ (Message Queue) is a tool for communication between middleware and application programs, supports asynchronous communication, and realizes decoupling of the application programs. RPC (Remote Procedure Call) is a protocol for requesting services from a Remote computer program over a network without knowledge of underlying network technologies, and is a means for applications to implement communication after a layered architecture.
Step S306: and verifying the data to be carried forward in the target database according to a preset rule.
Step S307: and if the verification is successful, deleting the data to be carried forward in the source database according to the primary key file, and updating the state of the carry forward task to be finished.
Step S308: and if the verification fails, rolling back the data to be carried forward in the target database, and updating the state of the carry forward task to be failed.
For step S306, the preset rule may be to check whether the data amount is consistent, and specifically includes one or more of the following: checking whether the data volume of the data master table and all the data slave tables in the target database is consistent with the data volume of the data master table at the cloud end and the data volume of the corresponding data slave tables; checking whether the data volumes of the data main table in the target database and the data main table in the cloud end are consistent or not; and checking whether the data volumes of the data tables appointed in the target database and the data tables corresponding to the cloud end are consistent or not. When the verification is passed, deleting the data to be transferred in the source database according to the primary key file; and when the verification fails, rolling back the data to be transferred to the target database, namely deleting the data to be transferred written into the target database.
The data slave table data transfer method of this embodiment determines the data tables associated with each other by analyzing the log file of the source database, and further may determine the association relationship between the data tables, and configures data transfer information based on the association relationship, where the data transfer information at least includes a transfer condition and an association field, queries the data to be transferred in the source database according to the transfer condition and the association field, stores the queried data to be transferred into the storage device, and then reads the data to be transferred from the storage device and writes the data to the target database, thereby completing the data transfer.
FIG. 4 is a schematic diagram of the main blocks of an apparatus 400 for forwarding data according to an embodiment of the present invention; as shown in fig. 4, the apparatus 400 includes:
a determining module 401, configured to obtain a log file of a source database, analyze the log file, and determine a data slave table associated with a data master table to be transferred and an association relationship between the data master table and the data slave table;
an information configuration module 402, configured to configure data transfer-forward information, including at least a configuration transfer-forward condition and an associated field;
a data preparation module 403, configured to query, according to the carry-over condition and the associated field, data to be carried over from a source database, and store the queried data to be carried over to a storage device;
and a data forwarding module 404, configured to read data to be forwarded from the storage device and write the data to the target database.
Optionally, the apparatus 400 further comprises a detection module configured to: determining a target master table and a target slave table corresponding to the data master table and the data slave table in a target database according to the table names; detecting whether the structure of the target master table is consistent with that of the data master table and whether the structure of the target slave table is consistent with that of the data slave table; and if the data are inconsistent, the structures of the target master table and the target slave table are changed by taking the data master table and the data as standards.
Optionally, the data preparation module 403 is further configured to: generating a write notification after storing the inquired data to be transferred into a storage unit;
the data forwarding module 404 is further configured to: and responding to the write notification, reading the data to be transferred from the storage device, and writing the data to a target database.
Optionally, the data preparation module 403 is further configured to: generating a data file according to the inquired data to be subjected to carry-over, wherein the data file is used for recording the data to be subjected to carry-over; saving the data file to a storage device; segmenting the data file to obtain a plurality of subdata files and attribute information of each subdata file; generating corresponding file path information according to the attribute information of each sub data file; storing the plurality of subdata files and corresponding file path information to a storage device;
the data forwarding module 404 is further configured to: and inquiring the subdata files according to the file path information, reading data to be converted from the inquired subdata files, and writing the data into the target database.
Optionally, the data preparation module 403 is further configured to: generating a primary key file according to the inquired data to be subjected to carry out carry-over, wherein the primary key file is used for recording primary key information of the data to be subjected to carry-over and storing the primary key file to a storage device;
the data forwarding module 404 is further configured to: after the inquired data to be carried forward is carried forward to a target database, verifying the data to be carried forward in the target database according to a preset rule; if the verification is successful, deleting the data to be transferred in the source database according to the primary key file; and if the verification fails, rolling back to the data to be rolled in the target database.
The device can execute the method provided by the embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
Fig. 5 illustrates an exemplary system architecture 500 to which a method of forwarding data or an apparatus for forwarding data of an embodiment of the present invention may be applied.
As shown in fig. 5, the system architecture 500 may include terminal devices 501, 502, 503, a network 504, and a server 505. The network 504 serves to provide a medium for communication links between the terminal devices 501, 502, 503 and the server 505. Network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 501, 502, 503 to interact with a server 505 over a network 504 to receive or send messages or the like. The terminal devices 501, 502, 503 may have various communication client applications installed thereon, such as a shopping application, a web browser application, a search application, an instant messaging tool, a mailbox client, social platform software, and the like.
The terminal devices 501, 502, 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 505 may be a server that provides various services, such as a background management server that supports shopping websites browsed by users using the terminal devices 501, 502, 503. The background management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (e.g., target push information and product information) to the terminal device.
It should be noted that the method for forwarding data provided by the embodiment of the present invention is generally executed by the server 505, and accordingly, the apparatus for forwarding data is generally disposed in the server 505.
It should be understood that the number of terminal devices, networks, and servers in fig. 5 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 6, a block diagram of a computer system 600 suitable for use with a terminal device implementing an embodiment of the invention is shown. The terminal device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU)601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output portion 607 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 605 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 601.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a sending module, an obtaining module, a determining module, and a first processing module. The names of these modules do not in some cases constitute a limitation on the unit itself, and for example, the sending module may also be described as a "module that sends a picture acquisition request to a connected server".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise:
acquiring a log file of a source database, analyzing the log file, and determining a data slave table associated with a data master table to be carried out transfer and an association relation between the data master table and the data slave table;
configuring data transfer information based on the incidence relation, wherein the data transfer information at least comprises configuration transfer conditions and incidence fields;
inquiring data to be subjected to forward from a source database according to the forward condition and the associated field, and storing the inquired data to be subjected to forward into a storage device;
and reading the data to be transferred from the storage device and writing the data to the target database.
According to the technical scheme of the embodiment of the invention, the data tables which are mutually associated are determined by analyzing the log file of the source database, the association relationship between the data tables can be further determined, the data transfer information is configured based on the association relationship, the data transfer information at least comprises the transfer condition and the association field, the data to be transferred in the source database is inquired according to the transfer condition and the association field, the inquired data to be transferred is stored in the storage device, then the data to be transferred is read from the storage device and written into the target database, so that the data transfer is completed, the data slave table which is associated with the data master table can be prevented from being omitted, the complete data relationship between the transferred source database and the target database is ensured, the data maintenance is convenient, and the labor cost is reduced.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (12)

1. A method of carrying forward data, comprising:
acquiring a log file of a source database, analyzing the log file, and determining a data slave table associated with a data master table to be carried out transfer and an association relation between the data master table and the data slave table;
configuring data transfer information based on the incidence relation, wherein the data transfer information at least comprises configuration transfer conditions and incidence fields;
inquiring data to be subjected to forward from a source database according to the forward condition and the associated field, and storing the inquired data to be subjected to forward into a storage device;
and reading the data to be transferred from the storage device and writing the data to the target database.
2. The method of claim 1, further comprising:
determining a target master table and a target slave table corresponding to the data master table and the data slave table in a target database according to the table names;
detecting whether the structure of the target master table is consistent with that of the data master table and whether the structure of the target slave table is consistent with that of the data slave table;
and if the data are inconsistent, the structures of the target master table and the target slave table are changed by taking the data master table and the data as standards.
3. The method of claim 1, wherein after storing the queried data to be carried forward in the storage unit, the method further comprises: generating a write notification;
reading data to be carried forward from the storage device and writing to the target database comprises: and responding to the write notification, reading the data to be transferred from the storage device, and writing the data to a target database.
4. The method of claim 1, wherein storing the queried data to be carried forward in a storage device comprises:
generating a data file according to the inquired data to be subjected to carry-over, wherein the data file is used for recording the data to be subjected to carry-over;
segmenting the data file to obtain a plurality of subdata files and attribute information of each subdata file;
generating corresponding file path information according to the attribute information of each sub data file;
storing the plurality of subdata files and corresponding file path information to a storage device;
reading data to be carried forward from the storage device and writing to a target database comprises: and inquiring the subdata files according to the file path information, reading data to be converted from the inquired subdata files, and writing the data into a target database.
5. The method according to any one of claims 1-4, wherein storing the queried data to be carried forward to a storage device comprises: generating a primary key file according to the inquired data to be subjected to carry out carry-over, wherein the primary key file is used for recording primary key information of the data to be subjected to carry-over and storing the primary key file in a storage device;
after writing to the target database, the method further comprises:
verifying the data to be carried forward in the target database according to a preset rule;
if the verification is successful, deleting the data to be transferred in the source database according to the primary key file;
and if the verification fails, rolling back to the data to be rolled in the target database.
6. An apparatus for carrying forward data, comprising:
the determining module is used for acquiring a log file of a source database, analyzing the log file, and determining a data slave table associated with a data master table to be carried forward and an association relation between the data master table and the data slave table;
the information configuration module is used for configuring data transfer-forward information based on the incidence relation, and at least comprises configuration transfer-forward conditions and incidence fields;
the data preparation module is used for inquiring data to be subjected to forward from a source database according to the forward condition and the associated field and storing the inquired data to be subjected to forward into the storage device;
and the data transfer module is used for reading the data to be transferred from the storage device and writing the data into a target database.
7. The apparatus of claim 6, further comprising a detection module to:
determining a target master table and a target slave table corresponding to the data master table and the data slave table in a target database according to the table names;
detecting whether the structure of the target master table is consistent with that of the data master table and whether the structure of the target slave table is consistent with that of the data slave table;
and if the data are inconsistent, the structures of the target master table and the target slave table are changed by taking the data master table and the data as standards.
8. The apparatus of claim 6, wherein the data preparation module is further configured to: generating a write notification after storing the inquired data to be transferred into a storage unit;
the data carry forward module is further configured to: and responding to the write notification, reading the data to be transferred from the storage device, and writing the data to a target database.
9. The apparatus of claim 6, wherein the data preparation module is further configured to:
generating a data file according to the inquired data to be subjected to carry-over, wherein the data file is used for recording the data to be subjected to carry-over;
segmenting the data file to obtain a plurality of subdata files and attribute information of each subdata file;
generating corresponding file path information according to the attribute information of each sub data file;
storing the plurality of subdata files and corresponding file path information to a storage device;
the data carry forward module is further configured to: and inquiring the subdata files according to the file path information, reading data to be converted from the inquired subdata files, and writing the data into a target database.
10. The apparatus of any of claims 6-9, wherein the data preparation module is further configured to:
generating a primary key file according to the inquired data to be subjected to carry out carry-over, wherein the primary key file is used for recording primary key information of the data to be subjected to carry-over and storing the primary key file to a storage device;
the data carry forward module is further configured to: after the data is written into the target database, verifying the data to be transferred into the target database according to a preset rule;
if the verification is successful, deleting the data to be transferred in the source database according to the primary key file;
and if the verification fails, rolling back to the data to be rolled in the target database.
11. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-5.
12. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-5.
CN201910599964.5A 2019-07-04 2019-07-04 Method and device for transferring data Active CN112181937B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910599964.5A CN112181937B (en) 2019-07-04 2019-07-04 Method and device for transferring data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910599964.5A CN112181937B (en) 2019-07-04 2019-07-04 Method and device for transferring data

Publications (2)

Publication Number Publication Date
CN112181937A true CN112181937A (en) 2021-01-05
CN112181937B CN112181937B (en) 2023-11-03

Family

ID=73915136

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910599964.5A Active CN112181937B (en) 2019-07-04 2019-07-04 Method and device for transferring data

Country Status (1)

Country Link
CN (1) CN112181937B (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030046310A1 (en) * 2001-08-28 2003-03-06 Polytechnic University Tracking files of storage media and enabling users to quickly associate such files with the storage media on which they are stored
CN101067863A (en) * 2007-06-14 2007-11-07 华为技术有限公司 Accounts managing system apparatus and method
CN102637214A (en) * 2012-04-28 2012-08-15 中国工商银行股份有限公司 Method and system for synchronizing general data among database services
CN103020315A (en) * 2013-01-10 2013-04-03 中国人民解放军国防科学技术大学 Method for storing mass of small files on basis of master-slave distributed file system
US20140372383A1 (en) * 2013-06-18 2014-12-18 Barracuda Networks, Inc. Log Access Method Storage Control Apparatus, Archive System, and Method of Operation
CN105095425A (en) * 2015-07-17 2015-11-25 北京京东尚科信息技术有限公司 Cross-database transfer method and device for databases
CN107357883A (en) * 2017-06-30 2017-11-17 北京奇虎科技有限公司 Data migration method and device
WO2018093094A1 (en) * 2016-11-16 2018-05-24 주식회사 실크로드소프트 Data replacation technique in database management system
CN108932313A (en) * 2018-06-20 2018-12-04 斑马网络技术有限公司 Data processing method, device, electronic equipment and storage medium

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030046310A1 (en) * 2001-08-28 2003-03-06 Polytechnic University Tracking files of storage media and enabling users to quickly associate such files with the storage media on which they are stored
CN101067863A (en) * 2007-06-14 2007-11-07 华为技术有限公司 Accounts managing system apparatus and method
CN102637214A (en) * 2012-04-28 2012-08-15 中国工商银行股份有限公司 Method and system for synchronizing general data among database services
CN103020315A (en) * 2013-01-10 2013-04-03 中国人民解放军国防科学技术大学 Method for storing mass of small files on basis of master-slave distributed file system
US20140372383A1 (en) * 2013-06-18 2014-12-18 Barracuda Networks, Inc. Log Access Method Storage Control Apparatus, Archive System, and Method of Operation
CN105095425A (en) * 2015-07-17 2015-11-25 北京京东尚科信息技术有限公司 Cross-database transfer method and device for databases
WO2018093094A1 (en) * 2016-11-16 2018-05-24 주식회사 실크로드소프트 Data replacation technique in database management system
CN107357883A (en) * 2017-06-30 2017-11-17 北京奇虎科技有限公司 Data migration method and device
CN108932313A (en) * 2018-06-20 2018-12-04 斑马网络技术有限公司 Data processing method, device, electronic equipment and storage medium

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
LEONARDO ANIELLO: "A Prototype Evaluation of a Tamper-Resistant High Performance Blockchain-Based Transaction Log for a Distributed Database", 2017 13TH EUROPEAN DEPENDABLE COMPUTING CONFERENCE (EDCC) *
刘柱, 任声援: "基于综合柜员制及C/S结构的储蓄通存通兑系统", 中国金融电脑, no. 08 *
王文君;: "综合分项逐步结转分步法", 中国乡镇企业会计, no. 02 *
黄晓微;陈玲;魏玮;徐世莲;: "基于快照日志分析的数据同步方法", 后勤工程学院学报, no. 02 *

Also Published As

Publication number Publication date
CN112181937B (en) 2023-11-03

Similar Documents

Publication Publication Date Title
CN106649630A (en) Data query method and device
CN110019350A (en) Data query method and apparatus based on configuration information
CN112445626B (en) Data processing method and device based on message middleware
KR20210005043A (en) Input and output schema mapping
CN110851468A (en) Method and device for making simulation response to test request of client
CN111126948A (en) Processing method and device for approval process
CN111038906A (en) Order sorting method and device
WO2024124789A1 (en) File processing method and apparatus, server, and medium
CN113190517B (en) Data integration method and device, electronic equipment and computer readable medium
CN117950850A (en) Data transmission method, device, electronic equipment and computer readable medium
CN113127335B (en) System testing method and device
CN112948494A (en) Data synchronization method and device, electronic equipment and computer readable medium
CN113672671A (en) Method and device for realizing data processing
CN112948138A (en) Method and device for processing message
CN108833147B (en) Configuration information updating method and device
CN111698109A (en) Method and device for monitoring log
CN111367500A (en) Data processing method and device
CN111008202A (en) Distributed transaction processing method and framework
CN110806967A (en) Unit testing method and device
CN113515285B (en) Method and device for generating real-time calculation logic data
CN112181937A (en) Data transmission method and device
CN110909269B (en) Log reporting method and device
US8527580B2 (en) Saving multiple data items using partial-order planning
JP5351746B2 (en) Data processing apparatus and method
CN113268417B (en) Task execution method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant