Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
As shown in FIG. 1, in one embodiment, a data migration system is provided that includes a plurality ofterminals 102 and aserver 104. Theterminal 102 may be a mobile phone, a personal notebook, a tablet computer, a desktop computer, or the like; theserver 104 may be one or more servers. Theuser terminal 102 runs a request application program, and at least provides a request sending function. Theserver 104 is used to provide service support for requesting applications running on theterminal 102. The user may send various read and write requests to theserver 104 through theterminal 102, and theserver 104 processes the various read and write requests through its internal database. Data corresponding to the read request and the write request sent by the user is stored in a database of theserver 104, and the data can be migrated between different databases.
In one embodiment, the internal structure of theserver 104 in fig. 1 is schematically illustrated in fig. 2. The server comprises a processor, a memory, a storage medium and a network interface which are connected through a system bus. Theserver 104 receives read requests and write requests from theuser terminal 102 through the network interface. The storage medium of the server stores an operating system, a database and a data migration device, wherein the database can be one or more than two databases. The data migration device is used for realizing a data migration method. The processor of the server is configured to perform a data migration method.
As shown in fig. 3, in an embodiment, a data migration method is provided, and this embodiment is illustrated by applying the method to the server in fig. 1. The data migration method specifically comprises the following steps:
step S302: data in the first database is migrated to the second database.
Specifically, a DB (database) refers to a collection of data that is stored together in a manner that can be shared by multiple users, has as little redundancy as possible, and is independent of applications. The database belongs to an application system and can be installed on a server.
The first database and the second database may be installed on the same server or may be installed on different servers. In this embodiment, the first database and the second database are installed on the same server.
Step S304: a read request and a write request are received from a user terminal.
Specifically, a requesting application is run on the user terminal, and a request trigger control, such as a button or a hyperlink, is set in a page of the requesting application. The user inputs a trigger instruction through an input device such as a touch screen, a button or a track ball of the user terminal, so that the user terminal sends a read request or a write request to the server. Read requests do not require data to be modified, such as security knowledge browsing requests, while write requests require data to be modified, such as password modification requests.
In this embodiment, the server may receive one or more requests from one user terminal, or may receive requests from two or more user terminals.
Step S306: the migration state of the data is detected.
Specifically, after data starts to be migrated from one database to another database, the migration state at least includes the migration in progress and the migration completed.
In this embodiment, step S306 specifically includes: and detecting whether all the data in the first database are migrated into the second database, if so, determining that the migration of the data is completed, and if not, determining that the migration of the data is in progress.
And step S308, processing the read request and the write request according to the migration state of the data.
Specifically, if the migration state of the data is migration, the write request is allocated to the second database for processing, and the read request is allocated to the first database or the second database for processing; and if the migration state of the data is migration completion, distributing the read request and the write request to the second database for processing.
For example, if the migration state of the data is migration, after receiving the read request, the server searches the second database for the data corresponding to the read request. If the second database has data corresponding to the read request, the server will distribute the read request to the second database for processing through a logic process (i.e. a server process) in the program running process, i.e. the second database provides service for the user. If the second database is found to have no data corresponding to the read request in the searching process, the corresponding data is not migrated to the second database, and the logic process redistributes the read request to the first database for processing.
According to the data migration method, in the process of migrating data from the first database to the second database, after the server receives the read request and the write request from the user terminal, the migration state of the data is detected, and the read request and the write request are processed according to the migration state, so that the read-write service can be provided for a user in the process of data migration, and unnecessary loss is not brought to the user due to stopping the service of the database.
Fig. 4 is a flowchart illustrating a process of allocating a read request to a first database or a second database according to an embodiment.
In this embodiment, the allocating the read request to the first database or the second database specifically includes:
step S402: and searching whether the second database has data corresponding to the reading request, if so, executing step S404, and if not, executing step S406.
Step S402: the read request is assigned to a second database transaction.
Step S406: the read request is assigned to a first database transaction.
For example, if a user sends a read request through the terminal to read data a, data a corresponding to the read request is searched in the second database. If the second database has data a, the read request is assigned to the second database for processing, i.e. data a is returned to the user terminal via the second database. If the second database does not have the data a corresponding to the read request, it indicates that the data a has not been migrated from the first database to the second database, and therefore, the read request needs to be allocated to the first database for processing, and the first database returns the data a to the user terminal.
Fig. 5 is a flowchart illustrating migration of data in a first database to a second database according to an embodiment.
Step S502: data in the first database is replicated.
Step S504: detecting whether the data already exists in the second database or whether the second database receives a deletion request corresponding to the data, if so, executing step S506; if not, go to step S508.
Step S506: the data is directly discarded.
Step S508: pasting the data into a second database.
In particular, the write request comprises a delete request. In this embodiment, if the data corresponding to the deletion request has not been migrated to the second database, the deletion request may be recorded in the second database in a tag manner after being processed, and when the data is migrated to the second database, if it is detected that the second database receives the deletion request corresponding to the data, it is detected that a corresponding tag is recorded in the second database, so that the data may be directly lost.
For example, when the second database processes the delete request, a column is added in the data table as a reserved field of the data, and if the data corresponding to the delete request has not been migrated to the second database, the data corresponding to the delete request will be marked at the reserved field after being processed, indicating that the data corresponding to the delete request has been deleted.
The principle of the data migration method is described below by using a specific application scenario, which takes a desktop computer as a terminal, installs a first database and a second database on the same server, and sends a security knowledge browsing request and a password modification request to the server through the desktop computer by a user as an example.
Referring to fig. 6, before data is not migrated, a user sends a security knowledge browsing request and a password modification request to aserver 620 corresponding to an account security center through adesktop computer 610. Because the relevant data corresponding to these requests are stored in thefirst database 622 before migration, theserver 620 distributes the security knowledge browsing request and the password modification request to thefirst database 622 for processing through a logic process during the program running process after receiving the requests, that is, thefirst database 622 provides services for the user.
The account security center is account protection software, can provide one-stop software security service for users, and comprises functions of password protection, account protection, security physical examination, password modification, account complaint and the like, so that the account is safer and more reliable.
Nowadays, various accounts registered by a user through a network need to fill in some personal information, and the security of the accounts is very important for the user. When a user wants to know some security knowledge related to account protection, a security knowledge browsing request can be sent to the server. After receiving the request, the server processes the safety knowledge browsing request by running a series of programs, and feeds back related data stored in the database to the user terminal in a certain mode.
Each account is provided with a corresponding password, and the data corresponding to the password is stored in a database for providing services. If the user feels that the security of the previously set password is not high enough, the password needs to be modified. At this point, the user may send a password modification request to the server. After receiving the request, the server processes the password modification request by running a series of programs, and at this time, the user is required to write a new password to be stored in the database to replace the previous password, that is, the data corresponding to the previous password is deleted.
Referring to fig. 7, due to some unpredictable failures, the data in thefirst database 622 needs to be urgently migrated to thesecond database 624. During the data migration process, a user sends a safety knowledge browsing request to aserver 620 corresponding to the account safety center through adesktop computer 610. Because it is detected that all the data in thefirst database 622 has not been migrated to thesecond database 624, the migration status of the data is migration, and the data corresponding to the request may have been migrated to thesecond database 624 or may not have been migrated to thesecond database 624. Thus, upon receiving the request, theserver 620 will look up thesecond database 624 for the data corresponding to the security knowledge browsing request. If thesecond database 624 has data corresponding to the security knowledge browsing request, theserver 620 will distribute the security knowledge browsing request to thesecond database 624 for processing through a logic process during the program running process, i.e. thesecond database 624 provides services for the user. If during the search process, it is found that thesecond database 624 does not have the data corresponding to the security knowledge browse request, which indicates that the corresponding data has not been migrated to thesecond database 624, the logic process will redistribute the security knowledge browse request to thefirst database 622 for processing.
During the data migration process, suppose that the user sends a password modification request to theserver 620 corresponding to the account security center through thedesktop computer 610. Because the password modification request belongs to the write request, theserver 620 needs to delete the data corresponding to the previous password after storing the data corresponding to the new password input by the user. At this time, if the data corresponding to the previous password has not been migrated to thesecond database 624, the data corresponding to the previous password is recorded in thesecond database 624 in a flag manner, and when the data corresponding to the previous password is migrated to thesecond database 624, if it is detected that the corresponding flag is recorded in thesecond database 624, the data corresponding to the previous password is directly discarded.
Referring to fig. 8, after all data in thefirst database 622 is migrated to thesecond database 624, the user sends a security knowledge browsing request and a password modification request to theserver 620 corresponding to the account security center through thedesktop computer 610, respectively, because it is detected that all data in thefirst database 622 is migrated to thesecond database 624, the migration state of the data is migration completion, and after receiving the request, theserver 620 distributes both the security knowledge browsing request and the password modification request to thesecond database 624 through a logic process in the program running process, that is, thesecond database 624 provides services for the user.
As shown in fig. 9, in one embodiment, adata migration apparatus 900 having functions of implementing the data migration methods of the above embodiments is provided. Thedata migration apparatus 900 includes amigration module 902, arequest receiving module 904, adetection module 906, and aprocessing module 908.
Themigration module 902 is configured to migrate data in the first database to the second database.
Therequest receiving module 904 is configured to receive a read request and a write request from a user terminal.
Thedetection module 906 is configured to detect a migration status of data.
Specifically, the detectingmodule 906 is configured to detect whether all data in the first database is migrated to the second database, if so, the migration state of the data is migration completion, and if not, the migration state of the data is migration in progress.
Theprocessing module 908 is configured to process the read request and the write request according to the migration status of the data.
Specifically, theprocessing module 908 includes an allocating unit, and if the migration state of the data is migration, the allocating unit is configured to allocate the write request to the second database process, and allocate the read request to the first database or the second database process; and if the migration state of the data is migration completion, the allocation unit is used for allocating the read request and the write request to the second database for processing.
If the migration state of the data is migration, the allocating unit allocates the read request to the first database or the second database for processing specifically as follows: if the migration state of the data is migration, the allocation unit is used for searching whether the second database has data corresponding to the read request, and if so, the read request is allocated to the second database for processing; and if not, distributing the read request to the first database for processing.
As shown in fig. 10, in one embodiment, amigration module 1000 is provided, themigration module 1000 including acopy unit 1002, adetection unit 1004, adelete unit 1006, and apaste unit 1008.
The copyingunit 1002 is used for copying data in the first database.
The detectingunit 1004 is configured to detect whether the data already exists in the second database or whether a deletion request corresponding to the data is received by the second database.
The deletingunit 1006 is used to directly discard the data.
Thepasting unit 1008 is used to paste the data into the second database.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disk, a Read-Only Memory (ROM), or a Random Access Memory (RAM).
The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.