Method and device for constructing data and system for synchronizing data between databases

文档序号:7621 发布日期:2021-09-17 浏览:38次 中文

1. A method of constructing data, comprising:

after a failure of a target log system of a database: when the operation of the database is monitored, acquiring the associated data of the operation acting on the database; the target log system stores target log data used for executing data synchronization or data recovery;

and constructing simulation log data by using the acquired associated data and according to the format of the target log data, and storing the constructed simulation log data.

2. The method of constructing data as claimed in claim 1, further comprising: before the obtaining of the associated data of the operation action on the database, associating the operation method of the database with a preset section code; and when the operation on the database is monitored, acquiring the associated data of the operation acting on the database, wherein the method comprises the following steps:

when it is monitored that a corresponding operation method is called for the operation of the database so as to trigger the section code associated with the operation method, the associated data of the operation acting on the database is obtained by utilizing the section code triggered to be executed.

3. The method of building data according to claim 2, wherein the associated data includes an operation type; and the method of constructing data further comprises:

determining a preset template corresponding to the operation type before constructing simulation log data according to the format of the target log data by using the obtained associated data; the template comprises a construction logic of simulation log data corresponding to the operation type and maintains a context object;

constructing analog log data by using the acquired associated data and according to the format of the target log data, wherein the method comprises the following steps:

and storing the acquired associated data in a context object of the determined template, and constructing simulation log data according to the construction logic in the template.

4. The method of constructing data as claimed in claim 1, further comprising:

after a failure of a target log system of the database: receiving a query statement aiming at the database, and determining target data corresponding to the query statement in the database;

and constructing simulation log data by using the target data and according to the format of the target log data, and storing the constructed simulation log data.

5. The method of building data according to claim 3, wherein the database is a source database providing support for a target database, and the method of building data further comprises:

after the simulation log data are constructed, sending the simulation log data to a data synchronization system of a target database; the data synchronization system is used for performing data synchronization from a source database to a target database by taking the simulation log data as target log data.

6. The method of constructing data according to claim 5,

the source database comprises Mysql, and the target database comprises Redis and/or Elastic Search;

the target log data is binary log binlog data, and the target log system is a binlog system;

the operation types comprise addition, deletion and/or updating, and the operation methods comprise addition methods, deletion methods and/or updating methods;

the associated data also comprises an identifier of a data table aimed at by operation in the source database, and pre-operation data and post-operation data of records aimed at by operation in the data table;

the section code is enhancement code based on section-oriented programming AOP.

7. An apparatus for constructing data, comprising:

an associated data acquisition unit configured to: after a failure of a target log system of a database: when the operation of the database is monitored, acquiring the associated data of the operation acting on the database; the target log system stores target log data used for executing data synchronization or data recovery;

the simulation log data construction unit: and the simulation log data is constructed by using the acquired associated data and according to the format of the target log data, and the constructed simulation log data is stored.

8. A system for synchronizing data between databases, comprising: the system comprises a source database, an access system provided with a source database external access interface, a target database provided with data support by the source database, and a data synchronization system for performing data synchronization on the target database according to target log data generated by the source database; a degradation tool is included in the access system; wherein the content of the first and second substances,

after a failure of a target log system storing the target log data: when the operation of the source database is monitored by the degradation tool, the associated data of the operation acting on the source database is obtained, the obtained associated data is used for constructing the simulation log data according to the format of the target log data, and the constructed simulation log data is sent to the data synchronization system.

9. 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-6.

10. A computer-readable storage 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-6.

Background

In the existing Mysql database, data backup and data replication between databases are supported through binlog (binary log), but if a binlog system fails, data cannot be backed up or data among databases are inconsistent, and actual services are further affected. The prior art attempts to repair binlog systems only when faced with this problem, but this repair process can be time consuming and even repair can lose data change information during the failure.

Disclosure of Invention

In view of this, embodiments of the present invention provide a method and an apparatus for constructing data, and a system for synchronizing data between databases, which are capable of automatically acquiring data associated with database operations when a target log system fails and constructing simulated log data having the same format as the target log data, where the simulated log data may replace the target log data to perform data recovery or data replication, so that the database can better cope with the situation where the target log system fails.

To achieve the above object, according to one aspect of the present invention, there is provided a method of constructing data.

The method for constructing data comprises the following steps: after a failure of a target log system of a database: when the operation of the database is monitored, acquiring the associated data of the operation acting on the database; the target log system stores target log data used for executing data synchronization or data recovery; and constructing simulation log data by using the acquired associated data and according to the format of the target log data, and storing the constructed simulation log data.

Optionally, the method for constructing data further includes: before the obtaining of the associated data of the operation action on the database, associating the operation method of the database with a preset section code; and when the operation on the database is monitored, acquiring the associated data of the operation acting on the database, wherein the method comprises the following steps: when it is monitored that a corresponding operation method is called for the operation of the database so as to trigger the section code associated with the operation method, the associated data of the operation acting on the database is obtained by utilizing the section code triggered to be executed.

Optionally, the associated data includes an operation type; and the method of constructing data further comprises: determining a preset template corresponding to the operation type before constructing simulation log data according to the format of the target log data by using the obtained associated data; the template comprises a construction logic of simulation log data corresponding to the operation type and maintains a context object; constructing analog log data by using the acquired associated data and according to the format of the target log data, wherein the method comprises the following steps: and storing the acquired associated data in a context object of the determined template, and constructing simulation log data according to the construction logic in the template.

Optionally, the method for constructing data further includes: after a failure of a target log system of the database: receiving a query statement aiming at the database, and determining target data corresponding to the query statement in the database; and constructing simulation log data by using the target data and according to the format of the target log data, and storing the constructed simulation log data.

Optionally, the database is a source database providing support for a target database, and the method for constructing data further includes: after the simulation log data are constructed, sending the simulation log data to a data synchronization system of a target database; the data synchronization system is used for performing data synchronization from a source database to a target database by taking the simulation log data as target log data.

Optionally, the source database comprises Mysql, the target database comprises Redis and/or Elastic Search; the target log data is binary log binlog data, and the target log system is a binlog system; the operation types comprise addition, deletion and/or updating, and the operation methods comprise addition methods, deletion methods and/or updating methods; the associated data also comprises an identifier of a data table aimed at by operation in the source database, and pre-operation data and post-operation data of records aimed at by operation in the data table; the section code is enhancement code based on section-oriented programming AOP.

To achieve the above object, according to another aspect of the present invention, there is provided an apparatus for constructing data.

The device for constructing data of the embodiment of the invention can comprise: an associated data acquisition unit configured to: after a failure of a target log system of a database: when the operation of the database is monitored, acquiring the associated data of the operation acting on the database; the target log system stores target log data used for executing data synchronization or data recovery; the simulation log data construction unit: and the simulation log data is constructed by using the acquired associated data and according to the format of the target log data, and the constructed simulation log data is stored.

To achieve the above object, according to still another aspect of the present invention, there is provided a system for synchronizing data between databases.

The system for synchronizing data between databases of the embodiment of the present invention may include: the system comprises a source database, an access system provided with a source database external access interface, a target database provided with data support by the source database, and a data synchronization system for performing data synchronization on the target database according to target log data generated by the source database; a degradation tool is included in the access system; wherein, after a failure of a target log system storing the target log data: when the operation of the source database is monitored by the degradation tool, the associated data of the operation acting on the source database is obtained, the obtained associated data is used for constructing the simulation log data according to the format of the target log data, and the constructed simulation log data is sent to the data synchronization system.

Optionally, a management interface is arranged in the access system; and, the degradation tool is further for: when it is monitored that a corresponding operation method is called for the operation of a source database so as to trigger a section code which is pre-associated with the operation method, acquiring associated data of the operation action on the source database by using the section code, storing the acquired associated data in a context object of a predetermined template, and constructing simulation log data according to construction logic in the template; when receiving a query statement which is input by a management interface and aims at the database, determining target data corresponding to the query statement in a source database, constructing simulated log data by using the target data and according to the format of the target log data, and sending the constructed simulated log data to a data synchronization system.

Optionally, the demotion tool sends the simulated log data to the data synchronization system through a message queue; the source database comprises Mysql, and the target database comprises Redis and/or Elastic Search; the target log data is binary log binlog data, and the target log system is a binlog system; the operation types comprise addition, deletion and/or updating, and the operation methods comprise addition methods, deletion methods and/or updating methods; the associated data also comprises an identifier of a data table aimed at by operation in the source database, and pre-operation data and post-operation data of records aimed at by operation in the data table; the section code is enhancement code based on section-oriented programming AOP.

To achieve the above object, according to still another aspect of the present invention, there is provided an electronic apparatus.

An electronic device of the present invention includes: 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 constructing data provided by the present invention.

To achieve the above object, according to still another aspect of the present invention, there is provided a computer-readable storage medium.

A computer-readable storage medium of the present invention has stored thereon a computer program which, when executed by a processor, implements the method of constructing data provided by the present invention.

According to the technical scheme of the invention, one embodiment of the invention has the following advantages or beneficial effects: when the target log system fails, the associated data of the database operation, such as the operation type, the data table identifier, the data before the operation, the data after the operation and the like, can be acquired according to the section code associated with the database operation method in advance, and the simulated log data with the same format as the target log data can be constructed according to the construction logic in the preset template, and can be used for data recovery or data synchronization between databases instead of the target log data during the failure of the target log system. Through the setting, the situation that the target log system fails can be well dealt with, and reliable data recovery or data consistency among databases is guaranteed. The method is simple to operate and high in reliability, the advantages of strong data synchronization consistency of the target log system, simplicity in exception handling and the like are reserved, original codes can be reused to the greatest extent, and the problem of distributed objects cannot be caused. In addition, the administrator can query the database for the required data and perform corresponding actions, and can also construct simulation log data to perform subsequent data recovery or data replication.

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 prior art system for synchronizing data between databases;

FIG. 2 is a schematic diagram of the main steps of a method of constructing data according to an embodiment of the present invention;

FIG. 3 is a diagram illustrating specific steps performed by a method for constructing data according to an embodiment of the present invention;

FIG. 4 is a schematic diagram of the components of an apparatus for constructing data in an embodiment of the present invention;

FIG. 5 is a block diagram of a system for synchronizing data between databases according to an embodiment of the present invention;

fig. 6 is a schematic structural diagram of an electronic device for implementing the method for constructing data in the embodiment of the present 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.

In a large-scale internet application system today, because an access amount is large, and a query performance of a traditional database cannot provide stable support, a support query such as Redis (a key value pair database), ES (Elastic Search engine), and the like needs to be introduced, that is, database operations such as addition (namely create), deletion (namely delete), update (namely update) and the like are performed by taking a database of Mysql and the like as a source database, and data reading and query facing a user are realized by taking the database of Redis, ES and the like as a target database, so that read-write separation is achieved. It should be noted that the operations in the present invention include addition, deletion, and update, and do not include query. Each of the above operations may call a corresponding operation method of a database write interface, for example, a DAO (Data Access Object) write interface, for example, an add operation may call an add method (i.e., insert inter method), a delete operation may call a delete method (i.e., delete method), and an update operation may call an update method (i.e., update method).

In the system, data synchronization between the source database and the target database needs to be performed through the target log data. Generally, the target log data contains data changes before and after the database operation is executed, and the target database can keep data synchronization with the source database according to the target log data. Fig. 1 is a schematic diagram of a system for synchronizing data between databases in the prior art, and as shown in fig. 1, a target log system is configured to store target log data generated by a source database and provide the target log data to a data synchronization system, and the data synchronization system is configured to perform an operation on the target database according to the target log data so as to implement data synchronization with the source database. Fig. 1 also shows an access system provided with an external interface (i.e., an external access interface) of the source database and a query system based on the target database and facing to the user, where the access system is further provided with a DAO write interface and a DAO read interface for the source database.

In the system shown in fig. 1, the data synchronization system continuously receives target log data, the target log data are respectively locked in various service scenes and the version numbers are compared to ensure that the target database writes the latest data, if a certain link has a problem, an exception can be thrown out and retried to ensure that the problem of distributed transactions cannot be generated between the databases, and when a data table is added, only a corresponding processing template needs to be added, the original code can be prevented from being invaded, so that the system safety is ensured. It can be seen that the above data synchronization method forms a strong dependency on the target log system, and if the target log system fails, data inconsistency between databases may be caused, thereby affecting service operation. In practical application, the target log data can also be used for data recovery of the source database, and the target log system also has influence on the data recovery when a fault occurs. The method provided by the invention can be used for dealing with the condition that the target log system fails, and can reduce or avoid the influence of the failure of the target log system on scenes such as data synchronization, data recovery and the like.

It should be noted that the source database and the target database in the embodiment of the present invention may be various databases, and the target log data may also be log data having the above data synchronization and/or data recovery functions, for example, the source database may be Mysql or Oracle, the target database may be ES and/or Redis, and the target log data may be binlog in Mysql or redo log data in Oracle. The following description will mainly take the source database as Mysql, the target database as ES and Redis, and the target log data as binlog as examples. Furthermore, the embodiments of the present invention and the technical features in the embodiments may be combined with each other without conflict.

Fig. 2 is a schematic diagram of main steps of a method for constructing data according to an embodiment of the present invention, and as shown in fig. 2, the method for constructing data according to an embodiment of the present invention may be specifically executed according to the following steps:

step S201: after a failure of a target log system of a database: when the operation aiming at the database is monitored, acquiring the associated data of the operation acting on the database; the target log system stores therein target log data for performing data synchronization or data recovery.

The database in this step may be the source database in fig. 1, and the failure of the target log system may be that the target log system cannot generate the target log data or cannot provide the target log data to the data synchronization system. To monitor database operations, the method of operation for the source database may be enhanced with AOP (Aspect organized Programming) techniques before performing this step. Specifically, an addition method, a deletion method, and an update method for the source database may be associated with a preset section code as a tangent point (i.e., Pointcut). The tangent plane code is an enhanced code (i.e., Advice) in the AOP, which can read the associated data acting on the source database by calling the DAO read interface of the source database. In practical application, a downgrade switch for controlling the execution of section codes (downgrading refers to switching from using a target log system to using the method for data synchronization or data recovery) can be further arranged in the AOP, the downgrade switch can be switched in an automatic or manual mode, and when the downgrade switch is turned on, the enhancement codes can be executed; when the downgrade switch is closed, the enhancement code cannot execute. In practical application, if the administrator detects that the target log system has a fault, the dynamic switch can be immediately turned on.

The associated data may include an identification of the data table targeted by the operation (e.g., a data table name), an operation type (i.e., whether the operation is to be added, deleted, or updated), an operation time, pre-operation data and post-operation data of a corresponding record in the data table (i.e., a record targeted by the operation). If the source database is a plurality of databases, the associated data may further include an identifier of the source database for which the operation is directed. It is understood that for the add operation, the pre-operation data of the corresponding field (i.e., the field for which the operation is directed) in the record is null; for deletion operation, the data of the corresponding field in the record after operation is null; for the update operation, neither the pre-operation data nor the post-operation data of the corresponding field in the above record is null, and the update operation will be mainly described as an example below.

In the embodiment of the present invention, the enhancement type for the operation method may be set as pre-enhancement, so that when the external call operation method executes a corresponding operation on the source database, the corresponding section code is triggered to execute before the operation method executes, and thus, corresponding associated data can be obtained. Preferably, the present invention may create a template for each database operation type in advance, where the template defines logic for acquiring associated data and logic for constructing the log data to be described below (hereinafter referred to as construction logic), and a context object may be maintained in the template for temporarily storing various associated data. In addition, the invention can also set a processor for each data table in the source database, and the processor has the functions of data query, analog log data construction and message assembly (the message is used for transmitting analog log data), and can also have other self-defining functions.

The specific process of obtaining the associated data based on the template is as follows: when it is monitored that an operation method is called, a section code associated with the operation method is triggered to execute first, then an operation type (the operation type corresponds to the type of the operation method) and a data table identifier are obtained through the section code, then a template corresponding to the operation type can be determined, and then associated data can be obtained according to corresponding logic in the template. Taking an update operation as an example, a context object maintained by the template may be initialized first, a processor corresponding to the data table is determined, then the DAO read interface is called to query the pre-operation data of the corresponding record to be put into the context object, and after the operation is executed, the DAO read interface is called again to query the post-operation data of the corresponding record to be put into the context object.

Step S202: and constructing simulation log data by using the acquired associated data and according to the format of the target log data, and storing the constructed simulation log data.

In this step, the associated data in the context object may be used to construct the simulation log data. In an embodiment of the present invention, the simulation log data is used to simulate the target log data, which may not be the log data itself. Preferably, the mock log data may have the same format as the target log data, and thus may be constructed in the format of the target log data when the mock log data is constructed. Generally, the format of the target log data can be set according to actual needs. For example, if a piece of target log data corresponding to an update operation is composed of a check code of 4 bytes, a start event of a first type, an event corresponding to the update operation, and an end event of a second type in this order, the analog log data corresponding to the update operation may also include a check code of 4 bytes, a start event of the first type, an event of the update operation, and an end event of the second type in this order. In a specific application, the above-mentioned construction process may be executed by a processor, and the processor may process the associated data in the context object according to the construction logic in the template, so as to obtain the simulation log data. The mock log data constructed in the above-described manner has the same format as the target log data, and thus can perform various functions of the target log data instead of the target log data. And finally, the constructed simulation log data can be stored for subsequent data recovery, or the simulation log data can be assembled into messages and sent to a data synchronization system through a message queue, so that data synchronization is realized. It can be understood that after the construction of the simulation log data is completed, the simulation log data can also be directly sent to the data synchronization system, and the stored simulation log data can also be used in other scenarios besides data recovery and data synchronization.

In some embodiments, data recovery and data synchronization based on the source database management interface are further supported. For example, when a small amount of data needs to be restored or synchronized, an administrator may input a query statement (e.g., a Structured Query Language (SQL) statement) on the management interface, and then the system first calls the DAO read interface of the source database to determine destination data corresponding to the query statement, then uses the destination data and constructs the log data according to the format of the destination log data, and finally stores or sends the constructed log data to the destination database. The method for constructing the simulation log data by using the target data is similar to the method for constructing the simulation log data by using the associated data, except that the target data acquisition and the simulation log data construction are performed by using the template corresponding to the scene in the scene.

Fig. 3 is a schematic diagram illustrating specific implementation steps of a method for constructing data according to an embodiment of the present invention, and as shown in fig. 3, when target log data fails, an administrator turns on a downgrade switch in an AOP. When a certain update operation calls an operation method to trigger an associated section code, the name of the operation method can be obtained by using the section code so as to determine the operation type and obtain the identifier of the data table, and then a corresponding template can be obtained according to the operation type and the following steps are executed according to the logic in the template: initializing a context object and acquiring a corresponding processor according to a data table identifier, then inquiring pre-operation data recorded in a data table correspondingly and putting the pre-operation data into the context object, inquiring the recorded post-operation data after the operation is executed and putting the post-operation data into the context object, and finally constructing and assembling simulation log data by using the processor into a message and sending the message to a data synchronization system, thereby completing data synchronization from a source database to a target database.

According to the technical scheme of the embodiment of the invention, when the target log system fails, the associated data of the database operation, such as the operation type, the data table identification, the data before the operation, the data after the operation and the like, can be obtained according to the section code associated with the database operation method in advance, the simulated log data with the same format as the target log data can be constructed according to the construction logic in the preset template, and the simulated log data can be used for data recovery or data synchronization between databases instead of the target log data during the failure of the target log system. Through the setting, the situation that the target log system fails can be well dealt with, and reliable data recovery or data consistency among databases is guaranteed. The method is simple to operate and high in reliability, the advantages of strong data synchronization consistency of the target log system, simplicity in exception handling and the like are reserved, original codes can be reused to the greatest extent, and the problem of distributed objects cannot be caused. In addition, the administrator can query the database for the required data and perform corresponding actions, and can also construct simulation log data to perform subsequent data recovery or data replication.

It should be noted that, for the convenience of description, the foregoing method embodiments are described as a series of acts, but those skilled in the art will appreciate that the present invention is not limited by the order of acts described, and that some steps may in fact be performed in other orders or concurrently. Moreover, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no acts or modules are necessarily required to implement the invention.

To facilitate a better implementation of the above-described aspects of embodiments of the present invention, the following also provides relevant means for implementing the above-described aspects.

Referring to fig. 4, an apparatus for constructing data according to an embodiment of the present invention may include: an associated data acquisition unit 401 and a simulation log data construction unit 402.

The associated data acquiring unit 401 may be configured to: after a failure of a target log system of a database: when the operation of the database is monitored, acquiring the associated data of the operation acting on the database; the target log system stores target log data used for executing data synchronization or data recovery; the simulation log data construction unit 402 may be configured to construct simulation log data according to a format of target log data by using the obtained associated data, and store the constructed simulation log data.

In an embodiment of the present invention, the apparatus 400 further comprises a section-oriented programming unit, configured to: and before the operation is acquired to act on the associated data of the database, associating the operation method of the database with a preset section code. The associated data obtaining unit 401 may further be configured to: when it is monitored that a corresponding operation method is called for the operation of the database so as to trigger the section code associated with the operation method, the associated data of the operation acting on the database is obtained by utilizing the section code triggered to be executed.

In practical applications, the associated data may include an operation type. The apparatus 400 may further comprise a template acquisition unit for: determining a preset template corresponding to the operation type before constructing simulation log data according to the format of the target log data by using the obtained associated data; wherein, the template comprises the construction logic of the simulation log data corresponding to the operation type and maintains the context object. The simulation log data construction unit 402 is further operable to: and storing the acquired associated data in a context object of the determined template, and constructing simulation log data according to the construction logic in the template.

As a preferred solution, the apparatus 400 may further include a background processing unit, configured to: after a target log system of the database fails, receiving a query statement aiming at the database, and determining target data corresponding to the query statement in the database; and constructing simulation log data by using the target data and according to the format of the target log data, and storing the constructed simulation log data.

Preferably, the database is a source database that provides support for a target database. The apparatus may further comprise a synchronization unit operable to: after the simulation log data are constructed, sending the simulation log data to a data synchronization system of a target database; the data synchronization system is used for performing data synchronization from a source database to a target database by taking the simulation log data as target log data.

Furthermore, in embodiments of the present invention, the source database comprises Mysql, and the target database comprises Redis and/or Elastic Search; the target log data is binary log binlog data, and the target log system is a binlog system; the operation types comprise addition, deletion and/or updating, and the operation methods comprise addition methods, deletion methods and/or updating methods; the associated data also comprises an identifier of a data table aimed at by operation in the source database, and pre-operation data and post-operation data of records aimed at by operation in the data table; the section code is enhancement code based on section-oriented programming AOP.

According to the technical scheme of the embodiment of the invention, when the target log system fails, the associated data of the database operation, such as the operation type, the data table identification, the data before the operation, the data after the operation and the like, can be obtained according to the section code associated with the database operation method in advance, the simulated log data with the same format as the target log data can be constructed according to the construction logic in the preset template, and the simulated log data can be used for data recovery or data synchronization between databases instead of the target log data during the failure of the target log system. Through the setting, the situation that the target log system fails can be well dealt with, and reliable data recovery or data consistency among databases is guaranteed. The method is simple to operate and high in reliability, the advantages of strong data synchronization consistency of the target log system, simplicity in exception handling and the like are reserved, original codes can be reused to the greatest extent, and the problem of distributed objects cannot be caused. In addition, the administrator can query the database for the required data and perform corresponding actions, and can also construct simulation log data to perform subsequent data recovery or data replication.

Fig. 5 is a schematic architecture diagram of a system for synchronizing data between databases according to an embodiment of the present invention, and as shown in fig. 5, the system for synchronizing data between databases according to an embodiment of the present invention may include: source database, target database, access system, data synchronization system.

The source database provides data support for the target database, the data synchronization system can perform data synchronization on the target database according to target log data generated by the source database, and the access system is provided with an external access interface of the source database and a read interface and a write interface (i.e., a DAO read interface and a DAO write interface in fig. 5) for the source database. In particular, a downgrading tool for executing the method for constructing the data is further arranged in the access system, the downgrading tool can be used as a main body for acquiring the associated data or the destination data, constructing the simulation log data and assembling and sending the message to the data synchronization system, and a management interface for inputting the query statement can be further arranged in the access system. Preferably, in the embodiment of the present invention, the downgrading tool may include a template factory and a processor factory, where the template factory includes a template corresponding to each operation method and a template corresponding to a background processing scenario (the background processing scenario will be described below), and the processor factory includes a processor corresponding to each data table, and the processor has functions of data query, log data construction simulation, message assembly, and the like, and may also implement various custom functions as needed. The specific functions of the template and the processor are described above and will not be repeated here. Also shown in FIG. 5 is a query system based on a target database and oriented to a user.

In practical application, each method of the DAO write interface may be enhanced in advance by using the AOP technology, that is, each method of the DAO write interface is associated with a preset section code, and a downgrade switch is set in the AOP to control execution of the section code. After the target log system fails, the administrator can manually turn on the downgrade switch to perform the aforementioned method of building data. When a certain operation of the source database is executed, the degradation tool can acquire the associated data acted on the source database by the operation through the triggered section code, construct the simulation log data according to the format of the target log data by using the acquired associated data, and finally send the constructed simulation log data to the data synchronization system. Specifically, when monitoring that a corresponding operation method is called for an operation of a source database and a section code associated with the operation method is triggered, a degradation tool first acquires an operation type and a data table identifier by using the section code and further acquires a template corresponding to the operation type, then executes corresponding logic in the template to acquire various associated data and stores the acquired associated data in a context object maintained by the template, and finally constructs simulation log data according to the constructed logic in the template and sends corresponding messages to a data synchronization system through a message queue. It should be noted that the template is designed in a chain of responsibility design mode, and can be split into a plurality of independent and reusable code blocks, thereby improving the development efficiency. Meanwhile, as design modes such as factories and responsibility chains are used in the degradation tool, the code structure is clear and meets the switching principle (namely objects such as classes, modules and functions in software are open for extension and closed for modification), when a new scene or a new data table is accessed, only a new template and a new processor need to be developed independently, the original code is not polluted, and the stability of the system is guaranteed.

In a background processing scenario (for example, a scenario requiring synchronization of a small amount of data using a management interface), an administrator may input a query statement on the management interface, and then a downgrading tool first calls a DAO read interface of a source database to determine destination data corresponding to the query statement, then uses the destination data and constructs log data according to a format of the destination log data, and finally sends the constructed log data to a target database.

In an alternative implementation, the source database includes Mysql, and the target database includes Redis and/or Elastic Search; the target log data is binary log binlog data, and the target log system is a binlog system; the operation types comprise addition, deletion and/or updating, and the operation methods comprise addition methods, deletion methods and/or updating methods; the associated data also comprises an identifier of a data table aimed at by operation in the source database, and pre-operation data and post-operation data of records aimed at by operation in the data table; the section code is enhancement code based on section-oriented programming AOP.

In the technical scheme of the embodiment of the invention, when the target log system fails, relevant data of database operation, such as operation type, data table identification, data before operation, data after operation and the like, can be obtained according to a tangent plane code which is pre-associated with a database operation method, and simulated log data with the same format as that of the target log data can be constructed according to construction logic in a preset template, and the simulated log data can replace the target log data for data synchronization between databases during the failure of the target log system. Through the setting, the situation that the target log system fails can be well dealt with, and reliable data recovery or data consistency among databases is guaranteed. The method is simple to operate and high in reliability, the advantages of strong data synchronization consistency of the target log system, simplicity in exception handling and the like are reserved, original codes can be reused to the greatest extent, and the problem of distributed objects cannot be caused. In addition, the administrator can search the database for the required data and execute corresponding actions to construct simulation log data to realize data replication.

The invention also provides the electronic equipment. The electronic device of the embodiment of the invention comprises: 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 constructing data provided by the present invention.

Referring now to FIG. 6, shown is a block diagram of a computer system 600 suitable for use with the electronic device implementing an embodiment of the present invention. The electronic 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 RAM603, various programs and data necessary for the operation of the computer system 600 are also stored. The CPU601, ROM 602, and RAM603 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, the processes described in the main step diagrams above may be implemented as computer software programs, according to embodiments of the present disclosure. For example, embodiments of the invention 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 main step diagram. In the above-described embodiment, the computer program can be downloaded and installed from the 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 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, 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 units described in the embodiments of the present invention may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes an associated data acquisition unit and a simulation log data construction unit. Here, the names of these units do not constitute a limitation to the unit itself in some cases, and for example, the associated data obtaining unit may also be described as a "unit that provides associated data to the simulation log data constructing unit".

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 the apparatus, cause the apparatus to perform steps comprising: after a failure of a target log system of a database: when the operation of the database is monitored, acquiring the associated data of the operation acting on the database; the target log system stores target log data used for executing data synchronization or data recovery; and constructing simulation log data by using the acquired associated data and according to the format of the target log data, and storing the constructed simulation log data.

According to the technical scheme of the embodiment of the invention, when the target log system fails, the associated data of the database operation, such as the operation type, the data table identification, the data before the operation, the data after the operation and the like, can be obtained according to the section code associated with the database operation method in advance, the simulated log data with the same format as the target log data can be constructed according to the construction logic in the preset template, and the simulated log data can be used for data recovery or data synchronization between databases instead of the target log data during the failure of the target log system. Through the setting, the situation that the target log system fails can be well dealt with, and reliable data recovery or data consistency among databases is guaranteed. The method is simple to operate and high in reliability, the advantages of strong data synchronization consistency of the target log system, simplicity in exception handling and the like are reserved, original codes can be reused to the greatest extent, and the problem of distributed objects cannot be caused. In addition, the administrator can query the database for the required data and perform corresponding actions, and can also construct simulation log data to perform subsequent data recovery or data replication.

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.

完整详细技术资料下载
上一篇:石墨接头机器人自动装卡簧、装栓机
下一篇:基于异构Hadoop集群环境的数据块放置方法及系统

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!