Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only some of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The data processing process provided in the embodiment of the present application is a process of "migrating", to a second database, business data generated when a business request is executed in a period of time after a predetermined time point by a first database when the first database used by an application needs to be replaced by the second database. The first database is an original database used by the application program, and the second database is a replacement database replacing the original database.
In general, the predetermined time point may be a time point determined by a worker, and a time duration corresponding to a period of time after the predetermined time point may also be determined by the worker, that is, the end time of the "migration" process may also be determined by the worker. Moreover, since the predetermined time point and the duration of the period of time have no relation with the data processing process of the present application, the present application is not limited to this specifically. That is, the data processing process described in this application is a data processing method when the application executes the service request after the predetermined time point until the end of the period of time, and does not refer to when the data processing method starts and when the data processing method ends.
The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
Fig. 1 is a data processing process provided in an embodiment of the present application, which specifically includes the following steps:
s101: a service request is received for a relational database.
In the prior art, during the execution of a service, an application server may generally receive a service request corresponding to the service, and the application server determines the operation of the subsequent step according to the service request.
Similarly, in the embodiment of the present application, the application server may also receive the service request, where the service request may also be a service request for a relational database because the application corresponds to a process of how to perform data processing on data in the database. Since the data processing process is a process of "migrating" data in the first database to the second database, the application server may correspond to the first database and the second database, the first database is an original database used by the application server, the second database is a replacement database that is expected to be used by the application server to replace the first database after the "migration" process is completed, and both the first database and the second database may be relational databases, as shown in fig. 2.
Fig. 2 is a schematic structural relationship diagram of an application server, the first database, and the second database according to an embodiment of the present application. It can be seen that the application server corresponds to the first database and the second database.
The application server may be an individual device, or may be a system (i.e., a distributed application server) composed of a plurality of devices, and the first database and the second database may be an individual device, or may be a system (i.e., a distributed database) composed of a plurality of devices, which is not limited in this application.
In addition, since the application program usually executes an Object-oriented Language (such as java Language), the service request received by the application server is usually generated by the Object-oriented Language, but if the service request relates to an add, Query, modify, Delete (Create, Retrieve, Update, Delete, CRUD) operation on data in a database corresponding to the application server, because the Language for operating the relational database is Structured Query Language (SQL), which is not consistent with the Object-oriented Language, in this embodiment of the application, when the application server receives the service request for the relational database, the application server may further convert the service request into an SQL statement capable of operating the relational database through a pre-configured Object Relation Mapping (ORM) framework so as to subsequently operate the relational database, the application server may operate the relational database using the ORM framework, which may be ibatis specifically, using data layer middleware.
Fig. 2 may continue to be refined to fig. 3. Fig. 3 is a schematic diagram illustrating a detailed structural relationship among the application server, the first database, and the second database according to an embodiment of the present disclosure. It can be seen that the application server generates SQL statements through the ORM framework, and operates the first and second databases using data layer middleware.
And, since the application server corresponds to the first database and the second database, and the database types and the database sizes of the first and second databases may be different, a first conversion rule for converting the service request into an SQL statement operable on the first database and a second conversion rule for converting the service request into an SQL statement operable on the second database may be configured in advance in the application server, where the first conversion rule is also generally referred to as a sqmap and the second conversion rule is referred to as a second sqmap in the following description because the conversion rule is also generally referred to as a sqmap.
For example, assuming that an application server a corresponds to a first database B and a second database C, where the first database B and the second database C are both relational databases, the application program corresponding to the application server a uses a Java language, further assuming that the first database B is mysql and the second database C is oracle, the application server a is also preconfigured with a first slmap that converts the Java language into a first SQL statement corresponding to the mysql database, so as to convert the Java language into a second slmap that corresponds to the second SQL statement corresponding to the oracle database, and the first slmap and the second slmap are both configured in an ORM framework of the application server, and the application server a receives a service request D for the relational database.
S102: and generating a first SQL statement corresponding to the service request according to the service request and a first conversion rule configured in advance, and generating a second SQL statement according to the service request and a second conversion rule configured in advance.
In the embodiment of the present application, after the application server receives a service request for a relational database, an idle thread may be determined, and the service request may be executed through the thread, where the thread may first convert the service request into a first SQL statement for executing a corresponding operation on the first database, and then convert the first SQL statement into a second SQL statement for executing a corresponding operation on the second database.
Specifically, the application server may determine an idle thread, and enable the thread to generate the first SQL statement according to the service request through the first sqmap preconfigured in the ORM framework of the application server, and because the ORM framework is also preconfigured with the second sqmap, the thread may also generate the second SQL statement according to the service request, so that the application server may execute corresponding operations on the first database and the second data through the first SQL statement and the second SQL statement, respectively.
In addition, in the embodiment of the present application, since the second database is used as a replacement database, the amount of data stored is smaller than the amount of data stored in the first database, and the probability of supporting the normal operation of the application server is lower, if any service request to the relational database generates the first SQL statement and the second SQL statement respectively, the probability of the execution failure of the second SQL statement may be increased. In addition, in the data processing process described in the present application, it is only necessary to make the data change in the first database caused by the service request appear in the second server as well, that is, it is only necessary to ensure that after the preset time point, the value of the data in the second database is consistent with the value of the data after the data change occurs in the first database, so in this embodiment of the present application, the data processing process may only be directed to the operations of adding, deleting, and changing the data, and does not need to perform the data processing process described in the present application on the query operation (the query operation does not change the value of the data stored in the first database).
Since the operator can determine what kind of service request of the application program needs to add, delete, and modify the data in the first database, in the application, a service identifier list determined by the operator may be stored in the application server in advance, where each service identifier in the service identifier list is a service identifier of a service request that needs to add, delete, and modify the first database, and the application server may also determine whether to generate the second SQL statement according to the service identifier corresponding to the service request.
Specifically, in step S101, the service request received by the application server may carry a service identifier corresponding to the service request, so that, first, when the application server calls an idle thread according to the service request, the service identifier may be written into a thread variable of the thread. Secondly, after the thread generates the first SQL statement according to the first sqmap, the data layer middleware may execute the first SQL statement to operate on the first database, and then the data layer middleware may determine the service identifier through a thread variable of the thread. Then, the data layer middleware may determine, according to the pre-stored service identifier list, whether the service identifier is the same as any service identifier in the service identifier list, if so, determine that the second SQL statement needs to be generated, the thread may also generate the second SQL statement through the second sqmap, subsequently execute the first and second SQL statements, if not, determine that the second SQL statement does not need to be generated, and the thread may continue to execute subsequent operations (e.g., execute corresponding operations on the first database according to the first SQL statement).
Continuing with the above example, assume that the application server a determines that thread x that is idle is executing the service request, the application server may write the service identification y of the service request into the thread variable of the thread x, after the thread x generates the first SQL statement through the first sqmap pre-configured in the ORM framework, when the first SQL statement is executed by using the data layer middleware, the service identifier y can be determined by the thread variable of the thread x, further assuming that the service identifier y is included in the service identifier list pre-stored in the application server a, the data tier middleware, upon executing the first SQL statement, may further determine that a second SQL statement needs to be generated, the thread x may also generate a second SQL statement via the second sqmap, and the thread x may execute the first SQL statement and the second SQL statement using the data layer middleware.
S103: and executing corresponding operation on the first relational database through the first SQL statement, and executing corresponding operation on the second relational database through the second SQL statement.
In this embodiment, after the first and second SQL statements are generated, the application server may perform corresponding operations on the first database and the second database by using the data layer middleware through the thread.
Moreover, because the first database and the second database are two independent databases, corresponding transactions can be respectively established for the first SQL statement and the second SQL statement, and further, in order to ensure that the data in the second database can be consistent with the modified data in the first database, the transactions corresponding to the first SQL statement and the second SQL statement respectively can be submitted only when the first SQL statement and the second SQL statement are executed successfully in the present application.
Specifically, the thread uses the data layer middleware to firstly establish a first transaction for executing the first SQL statement in the first database, secondly establish a second transaction for executing the second SQL statement in the second database, thirdly execute an operation corresponding to the first SQL statement in the first database according to the first SQL statement, fourthly execute an operation corresponding to the second SQL statement in the second database according to the second SQL statement, and submit the first transaction and the second transaction when the first SQL statement and the second SQL statement respectively execute successfully, and if the first transaction fails to establish or the second transaction fails to establish or the first SQL statement fails to execute or the second SQL statement fails to execute, the thread returns an error message (also called a throw error) and executes a rollback operation to restore the data in the first database and the second database to the state before executing step S103, as shown in fig. 4.
Fig. 4 is a schematic diagram illustrating a process of executing the first SQL statement and the second SQL statement in the first database and the second database, respectively, according to an embodiment of the present application.
It can be seen that, in the process of executing the corresponding operation on the first database by the first SQL statement and executing the corresponding operation on the second database by the second SQL statement, as long as any step has an error or a failure, the thread will throw the error and execute the rollback operation, and when both the first transaction and the second transaction are successfully submitted, the operation corresponding to the service request is executed.
Through the steps shown in fig. 4, it can be ensured that for the operation corresponding to the service request, the change of the data in the first database and the second database is the same, and the situation that one database is executed successfully and the other database is executed unsuccessfully, resulting in inconsistent data, does not occur.
It should be noted that, as described above, the application server may be a single device or a system composed of multiple devices, so that all execution subjects of the steps of the method provided in the embodiment of the present application shown in fig. 1 may be the same device, or different devices may be used as execution subjects of the method. For example, the execution subject of step S101 and step S102 may be device 1, and the execution subject of step S103 may be device 2; for another example, the execution subject of step S101 may be device 1, and the execution subjects of step S102 and step S103 may be device 2; and so on.
By the data processing method shown in fig. 1, the first and second SQL statements of the operations executed on the first database and the second database respectively can be generated according to the business request received by the application service for the relational database, so that the business request can execute the corresponding operation in the second database through the second SQL statement, so that the data in the second database is not obtained only through the data processing procedure of "asynchronous double write" at the database level, but obtained through the business request of the application, and in the present application, only when the first SQL statement and the second SQL statement are executed successfully, the corresponding first transaction and second transaction will be submitted, so that the first database and second database generate actual data changes, so through the data processing procedure provided by the present application, not only can the actual relation be generated between the operation of the second database and the application, but also the consistency of the data in the first database and the second database (specifically, the change of the data after the preset time point is consistent) can be ensured, so that the second database can directly support the operation of the application when the duration of the period of time is over, the subsequent process of verifying the data in the second database is avoided, and the cost of database replacement is reduced.
In addition, in the present application, since the first SQL statement is already generated in the application server before the second SQL statement is generated, the second sqmap may also be a rule for generating a second SQL statement for operating the second database according to the first SQL statement, and when the thread determines that the second SQL statement needs to be generated, the thread may generate the second SQL statement according to the first SQL statement and the second sqmap.
Further, since it is not necessary for the application program to care whether the application server needs to perform corresponding operations on the first database and the second database according to the service request, the content of the service request may be only for the first database, and the application server may implement the operations of subsequent steps S102 and S103 according to the application request.
In the above description of the embodiment of the present application, the application server is used as the execution subject, that is, the application program running on the application server includes the data layer middleware, but the data layer middleware may exist as a single program or system, so that in the embodiment of the present application, the data layer middleware may execute a part of step S102 and step S103.
Specifically, when the data layer middleware is a single program, the application server may further run an application program (referred to as a surface layer application, for example, for distinction), which faces a user, where the surface layer is applied to receive an operation of the user, determine a service request, generate the first SQL statement according to the preconfigured first sqmap, and send the first SQL statement to the data layer middleware, so that the data layer middleware performs a subsequent operation.
In this embodiment of the application, the application server determines, according to a pre-stored service identifier list and the service identifier carried in the service request, that the second SQL statement that is required to be generated to operate the second relational database is generated, which may specifically be:
after receiving the service request, the surface layer application can generate the first SQL statement according to the first sqmap, write a service identifier corresponding to the service request into a thread for executing the first SQL statement, and send the service identifier to the data layer middleware. The data layer middleware may determine, by running the thread, the service identifier written in the thread variable, and determine, by using a service identifier list stored in advance, whether to generate a second SQL statement, and if necessary, generate the second SQL statement according to the second pre-configured sqmap. Then, the data layer middleware may execute all the processes of step S103, and may specifically be consistent with the processes shown in fig. 4.
Further, since the application server can be divided into the surface application and the data layer middleware, and the two programs can be independent of each other, the pre-configured first and second sqmaps can be accessible to both the surface application and the data layer middleware.
Furthermore, since the surface layer Application and the data layer middleware can be independent from each other, the surface layer Application and the data layer middleware can perform data interaction through an Application Programming Interface (API), when the surface layer Application is connected with the data layer middleware for the first time, the first and the second databases corresponding to the surface layer Application can be declared to the data layer middleware through a declaration file configured in advance in the surface layer Application by a worker, wherein the declaration file includes database information such as database addresses and database configurations respectively corresponding to the first and the second databases.
Of course, the surface layer application and the data layer middleware may also be located in the same application program, which is not particularly limited in this application, and when the data layer middleware is an independent program, the data layer middleware may also be located in one or more independent devices, and the data layer middleware may also be connected to a plurality of surface layer applications and operate a plurality of databases, respectively. Moreover, since the present application relates to a "migration" process of data in a database, only the case where the first and second databases exist has been described, but the method described in the present application is not limited to corresponding to only two databases with the application server, and the application server may also correspond to a plurality of databases as long as the application server is configured with a corresponding sqmap in advance.
In addition, since the data layer middleware can directly call the first and second SQLMAPs configured in advance, in the present application, therefore, the data layer middleware can also request services of the relational database, and generates the first and second SQL statements, and finally executes the first and second SQL statements, it should be noted that, the service request received by the data layer middleware may be different from the aforementioned service request, (for example, for distinction, the following is referred to as a data request) specifically, the service request is sent to the data layer middleware after being processed by the skin application, specifically, the surface application may determine the operations to be performed on the data based on the received service request and based on the service logic, and sending the operation as a data request to the data-layer middleware to cause the data-layer middleware to perform a subsequent operation.
It should be noted that the language used by the application program may be C language, C + + language, etc. other than Java language described in fig. 1, the ORM framework may be Entity EJB, Hibernate, TopLink, OJB, etc. other than ibatis, the types of the first database and the second database may be Oracle, DB2, Microsoft SQL Server, etc., and the application is not limited in particular to the language used by the application program, the ORM framework used by the application Server, and the types of the first and second databases.
Based on the data processing process shown in fig. 1, an embodiment of the present application further provides a data processing apparatus, as shown in fig. 5.
Fig. 5 is a schematic structural diagram of a data processing apparatus according to an embodiment of the present application, including:
a receiving module 201, which receives a service request to a relational database;
the generating module 202 is configured to generate a first SQL statement corresponding to the service request according to the service request and a first conversion rule configured in advance, and generate a second SQL statement according to the service request and a second conversion rule configured in advance;
the execution module 203 executes a corresponding operation on the first relational database through the first SQL statement, and executes a corresponding operation on the second relational database through the second SQL statement.
The service request carries a service identifier;
the generating module 202 determines, according to a pre-stored service identifier list and the service identifier carried in the service request, that the second SQL statement that operates on the second relational database needs to be generated.
The receiving module 201 writes the service identifier into a thread variable of a thread executing the first SQL statement;
the generating module 202, when the first SQL statement is executed by the thread, determines the service identifier according to the thread variable, and determines, according to a pre-stored service identifier list and the service identifier, the second SQL statement that needs to be generated to operate the second relational database.
The execution module 203 establishes a first transaction for executing the first SQL statement in the first relational database, establishes a second transaction for executing the second SQL statement in the second relational database, executes a corresponding operation in the first relational database according to the first SQL statement, executes a corresponding operation in the second relational database according to the second SQL statement, submits the first transaction and the second transaction when the first SQL statement and the second SQL statement are both successfully executed, and returns error information and executes a rollback operation when the first SQL statement and/or the second SQL statement are failed to be executed.
The first relational database is an original database, the second relational database is a replacement database, and the corresponding operation comprises at least one of addition, deletion and change.
Specifically, the data processing apparatus shown in fig. 4 may be located in an application server, and the application server may be one device or a system composed of multiple devices.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.