Database migration system, data migration method and apparatus
By using a method based on business operation logs and asynchronous processing threads in heterogeneous database migration, the problems of coarse switching granularity and poor real-time performance of dual-write compensation are solved, achieving a smooth, reliable, and efficient database migration process.
Patent Information
- Application Number
- CN202611458627.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-18
- Publication Date
- 2026-11-24
AI Technical Summary
Existing technologies for online migration of heterogeneous databases are prone to business interruption, data inconsistency, and lack of flexible rollback due to coarse switching granularity and poor real-time performance of dual-write compensation.
After migrating the source database data to the target database in the first instance, incremental data is synchronized based on business operation logs. The dual-write mechanism is verified to be correct using asynchronous processing threads. Transaction data is queried step by step according to the preset importance level. Finally, the source database is taken offline after all user data has been switched.
It achieves business continuity, strong data consistency, and flexible rollback during heterogeneous database migration, ensuring smooth migration, high reliability of the main transaction link, and second-level bidirectional synchronization of incremental data, while isolating fine-grained risks.
Smart Images

Figure CN123157692A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database migration technology, and more specifically, to a database migration system, data migration method, and apparatus. Background Technology
[0002] As enterprises deepen their digital transformation and their business scale grows exponentially, the performance bottlenecks of traditional database architectures are becoming increasingly prominent, necessitating an evolution towards high-performance heterogeneous databases to support sustainable business development. However, some industries have stringent requirements for system high availability, and traditional downtime-based migration solutions, due to significant service interruption risks, can no longer meet these industries' rigid demands for business continuity. This makes database migration a core pain point restricting system architecture upgrades.
[0003] To address these issues, existing technologies have proposed online migration solutions, typically employing a combination of full and incremental synchronization to achieve seamless business operation during the migration process. While some existing technologies incorporate dual-write mechanisms to ensure data consistency, significant shortcomings remain in practical applications: First, the switching granularity is too coarse, typically proceeding as a whole, failing to support phased migration by customer or transaction type, leading to highly concentrated risks. Second, dual-write compensation mechanisms are mostly reactive, lacking real-time capability, and directly blocking the main transaction link in the event of dual-write failure severely reduces system availability, making it difficult to achieve second-level data synchronization and eventual consistency guarantees.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] This invention provides a database migration system, data migration method, and apparatus to at least solve the technical problems in related technologies where online migration of heterogeneous databases is prone to business interruption, data inconsistency, and inflexible rollback due to coarse switching granularity and poor real-time performance of dual-write compensation.
[0006] According to one aspect of the present invention, a data migration method is provided, comprising: after migrating data from a source database to a target database at a first moment, synchronizing maintenance incremental data of the first phase from the source database to the target database at a second moment based on business operation logs, wherein the first phase refers to a time window tracing back 24 hours from the second moment; after determining that the maintenance incremental data in the source database will be synchronized to the target database, at a third moment, synchronizing maintenance change data of the second phase written to the source database to the target database through an asynchronous processing thread and verifying that the dual-write mechanism is correct, synchronizing the maintenance change data to the source database and the target database through a business processing thread, wherein the second phase refers to the time window from 0:00 on the third moment to the third moment; after determining that the maintenance change data will be synchronized to the source database and the target database, gradually switching query transaction data from the source database to the target database according to a preset importance level; switching business access requests to the target database according to the user data migration status, and taking the source database offline after all user data switching is completed to complete the migration.
[0007] Optionally, migrating data from the source database to the target database at the first moment includes: reading the data from the source database up to the first moment; writing the data into the target database to establish the initial state of the target database.
[0008] Optionally, based on the business operation log, the maintenance incremental data of the first stage in the source database is synchronized to the target database at a second time, including: extracting the maintenance transaction log of the first stage at the second time; searching for the data record corresponding to each maintenance transaction log in the source database, and comparing the data record with the corresponding record in the target database to obtain a comparison result; when the comparison result shows an inconsistency, the data record in the source database is overwritten into the record in the target database.
[0009] Optionally, after determining to synchronize the incremental maintenance data in the source database to the target database, at a third moment, the maintenance change data of the second phase written to the source database is synchronized to the target database through an asynchronous processing thread, and the dual-write mechanism is verified to be correct. This includes: after receiving a maintenance transaction request at the third moment, using the main business processing thread to write the maintenance transaction request to the source database and feeding back the writing result to the client; when the writing result shows success, capturing the maintenance change data corresponding to the maintenance transaction request and writing the maintenance change data to the target database; if the maintenance change data is successfully written to the target database and the data verification passes, the dual-write mechanism is determined to be correct.
[0010] Optionally, the maintenance change data is synchronously written to the source database and the target database through a business processing thread, including: using the business processing thread to synchronously write the maintenance change data to the source database and the target database to obtain a response result; when the response result shows that the writing to the source database was successful and the writing to the target database failed, the failure log containing the maintenance transaction request is pushed to a message queue; and the failure log is read through a compensation program and the corresponding latest data is obtained from the source database to compensate the target database.
[0011] Optionally, after determining that the maintenance change data will be synchronously written to the source database and the target database, the query transaction data is gradually switched from the source database to the target database according to a preset importance level. This includes: establishing a priority list based on the preset importance level, wherein the query transaction data in the priority list are arranged in order of increasing importance; switching the query transaction data with the lowest importance in the priority list to the target database and monitoring the operating performance indicators of the target database; and after confirming that the operating performance indicators of the target database are within a preset range, sequentially switching the subsequent query transaction data in the priority list to the target database.
[0012] Optionally, the service access requests are switched to the target database according to the user data migration status, and the source database is taken offline after all user data is switched to complete the migration. This includes: obtaining a target user list, wherein the target user list contains users to be migrated and users who have been migrated; when the user is the user who has been migrated, maintenance change data is written to both the source database and the target database simultaneously through the dual-write mechanism, and the write result of the target database is used as the basis for determining the success of the transaction, and the target database is queried to respond to query-type transactions; when the user is the user to be migrated, maintenance change data is written to the source database, and the target database is queried to respond to query-type transactions.
[0013] According to another aspect of the present invention, a data migration apparatus is also provided, comprising: a synchronization unit, configured to, after migrating data from a source database to a target database at a first moment, synchronize maintenance incremental data of the first phase in the source database to the target database at a second moment based on business operation logs, wherein the first phase refers to a time window tracing back 24 hours from the second moment as the end point; a writing unit, configured to, after determining that the maintenance incremental data in the source database will be synchronized to the target database, synchronize maintenance change data of the second phase written to the source database to the target database through an asynchronous processing thread at a third moment, and after verifying that the dual-write mechanism is correct, synchronize the maintenance change data to both the source database and the target database through a business processing thread, wherein the second phase refers to the time window from 0:00 on the day of the third moment to the third moment; a first switching unit, configured to, after determining that the maintenance change data will be synchronized to both the source database and the target database, gradually switch query transaction data from the source database to the target database according to a preset importance level; and a second switching unit, configured to switch business access requests to the target database according to the user data migration status, and take the source database offline after all user data switching is completed to complete the migration.
[0014] Optionally, the synchronization unit includes: a first reading module for reading the data in the source database up to the first time point; and a second writing module for writing the data into the target database to establish the initial state of the target database.
[0015] Optionally, the synchronization unit includes: an extraction module, used to extract the maintenance transaction flow of the first stage at the second time; a search module, used to search for the data record corresponding to each maintenance transaction flow in the source database, and compare the data record with the corresponding record in the target database to obtain a comparison result; and a third writing module, used to overwrite the data record in the source database with the record in the target database when the comparison result shows inconsistency.
[0016] Optionally, the writing unit includes: a fourth writing module, configured to, after receiving the maintenance transaction request at the third time, use the main business processing thread to write the maintenance transaction request into the source database and feed back the writing result to the client; a first acquisition module, configured to, after the writing result shows success, capture the maintenance change data corresponding to the maintenance transaction request and write the maintenance change data into the target database; and a determination module, configured to, if the maintenance change data is successfully written into the target database and the data verification passes, determine that the dual-write mechanism is correct.
[0017] Optionally, the writing unit includes: a fifth writing module, used to synchronously write the maintenance change data to the source database and the target database using the business processing thread to obtain a response result; a push module, used to push the failure log containing the maintenance transaction request to a message queue when the response result shows that the writing to the source database was successful and the writing to the target database failed; and a compensation module, used to read the failure log and obtain the corresponding latest data from the source database through a compensation program to compensate the target database.
[0018] Optionally, the first switching unit includes: a table creation module, configured to create a priority list based on the preset importance level, wherein the query transaction data in the priority list are arranged in order of increasing importance; a first switching module, configured to switch the query transaction data with the lowest importance in the priority list to the target database and monitor the operating performance indicators of the target database; and a second switching module, configured to, after confirming that the operating performance indicators of the target database are within a preset range, sequentially switch the subsequent query transaction data in the priority list to the target database.
[0019] Optionally, the second switching unit includes: a second acquisition module, configured to acquire a target user list, wherein the target user list includes users to be migrated and users already migrated; a sixth writing module, configured to, when the user is the already migrated user, simultaneously write maintenance change data to the source database and the target database through the dual-write mechanism, and use the write result of the target database as the basis for determining the success of the transaction, and query the target database to respond to query-type transactions; and a seventh writing module, configured to, when the user is the user to be migrated, write maintenance change data to the source database, and query the target database to respond to query-type transactions.
[0020] According to one aspect of the present invention, a database migration system is provided, the database migration system using the data migration method described in any one of the above embodiments.
[0021] According to one aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium including a stored program, wherein the program performs the data migration method described in any one of the foregoing embodiments.
[0022] According to one aspect of the present invention, a processor is provided for running a program, wherein the program executes the data migration method described in any one of the foregoing embodiments.
[0023] According to one aspect of the present invention, a computer program product is provided, including computer instructions that, when executed by a processor, perform the data migration method described in any one of the above embodiments.
[0024] Applying the technical solution of this application, in the above data migration method, after migrating the data from the source database to the target database at the first moment, based on the business operation log, the maintenance incremental data of the first stage in the source database is synchronized to the target database at the second moment. Here, the first stage refers to a time window tracing back 24 hours from the second moment. After determining that the maintenance incremental data in the source database has been synchronized to the target database, at the third moment, the maintenance change data of the second stage written to the source database is synchronized to the target database through an asynchronous processing thread. After verifying that the dual-write mechanism is correct, the maintenance change data is synchronously written to both the source and target databases through a business processing thread. Here, the second stage refers to the time window from 0:00 on the third moment to the third moment. After determining that the maintenance incremental data in the source database has been synchronized to the target database, the maintenance change data of the second stage written to the source and target databases through an asynchronous processing thread. After maintenance changes are synchronously written to the source and target databases, the query transaction data is gradually switched from the source database to the target database according to the preset importance level. Business access requests are switched to the target database according to the user data migration status. After all user data is switched, the source database is taken offline to complete the migration. This achieves the goal of ensuring business continuity, strong data consistency, and flexible rollback during the heterogeneous database migration process. It achieves the technical effects of smooth migration, high reliability of the main transaction link, second-level bidirectional synchronization of incremental data, and fine-grained risk isolation for each customer. This solves the technical problems in related technologies where online migration of heterogeneous databases is prone to business interruption, data inconsistency, and inflexible rollback due to coarse switching granularity and poor real-time performance of dual-write compensation. Attached Figure Description
[0025] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0026] Figure 1 This is a hardware structure block diagram of a mobile terminal for a control method of an air conditioner according to an embodiment of the present invention.
[0027] Figure 2 This is a flowchart of a data migration method according to an embodiment of the present invention;
[0028] Figure 3 This is a flowchart illustrating the overall data migration process according to an embodiment of the present invention;
[0029] Figure 4 This is a flowchart of incremental data synchronization according to an embodiment of the present invention;
[0030] Figure 5 This is a flowchart of the double-write compensation process according to an embodiment of the present invention;
[0031] Figure 6 This is a flowchart of the flow cutting and eviction migration according to an embodiment of the present invention;
[0032] Figure 7 This is a schematic diagram of a data migration apparatus according to an embodiment of the present invention.
[0033] The above figures include the following reference numerals:
[0034] 102. Processor; 104. Memory; 106. Transmission device; 108. Input / output device. Detailed Implementation
[0035] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0036] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0037] As described in the background section, online migration of heterogeneous databases in related technologies suffers from drawbacks such as coarse-grained switching and poor real-time performance of dual-write compensation, which can easily lead to business interruptions, data inconsistencies, and a lack of flexible rollback. The embodiments of this invention provide a data migration method and apparatus, a database migration system, a computer-readable storage medium, a processor, and a computer program product.
[0038] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0039] The methods and embodiments provided in this invention can be executed on a mobile terminal, a computer terminal, or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal for a data migration method according to an embodiment of the present invention. Figure 1 As shown, a mobile terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0040] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the data migration method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thus implementing the above-described method. The memory 104 may include high-speed random access memory and non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the aforementioned networks may include wireless networks provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0041] Example 1
[0042] According to an embodiment of the present invention, a method embodiment of a data migration method is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0043] Figure 2 This is a flowchart of a data migration method according to an embodiment of the present invention, such as... Figure 2 As shown, the method includes the following steps:
[0044] Step S202: After migrating the data from the source database to the target database at the first moment, based on the business operation log, the maintenance incremental data of the first phase in the source database is synchronized to the target database at the second moment. The first phase refers to a time window that traces back 24 hours from the second moment.
[0045] It should be noted that, Figure 3 This is a flowchart of the overall data migration process according to an embodiment of the present invention, such as... Figure 3 As shown, a four-stage progressive migration architecture combining existing data migration, incremental synchronization, dual-write compensation, and customer-by-customer switching is adopted. Specifically, the following steps are included: First, a full migration of existing data from the source database to the target database is completed using data migration tools, establishing a basic data copy; second, an incremental synchronization batch program is started to continuously capture and synchronize incremental changes during the existing data migration process, ensuring that the data in the source and target databases are in a near real-time consistent state; third, after existing and incremental synchronization are ready, a bidirectional dual-write compensation mechanism is introduced: the application sends business write requests to both the source and target databases simultaneously, and ensures data consistency at both ends through second-level latency data verification and compensation tasks, providing a safe buffer for switching; then, through the gateway... Query transactions are gradually switched from ordinary to important, and traffic is gradually increased, with the target database as the primary database. This process allows for thorough verification of the target database's performance. Finally, a customer-by-customer migration is performed, with each customer as the smallest unit of switching. This supports the batch-by-batch switching of business traffic from the source database to the target database for specific customer groups and customers. During the switching process for each customer, final consistency checks are performed on the data to ensure data integrity before and after the switch. Rollback points are set at each stage of the migration process, including existing data migration, incremental synchronization, dual-write operation, and customer-by-customer switching. This allows for a switchback to the source database at any time without interrupting business or downtime, achieving the technical effect of zero business interruption, zero data loss, and full rollback capability during the migration process.
[0046] In this embodiment, the first moment refers to the time point at which the full data migration is performed, i.e., the TA moment, which is usually chosen during off-peak business hours (such as at night). At this time, the data migration tool completely copies all existing business data in the source database up to this moment to the target database, establishing a basic data copy. The source database refers to the source database instance that carries the original business data before the migration. It continues to provide read and write services to the outside world before the migration is completed, and stores the latest business data. The target database refers to the new or high-performance database instance that carries the business data after the migration. It is in a silent or quasi-synchronous state before the migration is completed and is used to receive the existing data migrated from the source database and the incremental data that is subsequently synchronized. The business operation log refers to the business layer log that records the flow of various maintenance transactions (such as add, delete, and modify operations) in the source database. Data changes are identified by parsing such logs. The second moment refers to the start time point of the incremental synchronization program, i.e., the TB moment. The first stage is a time window that traces back 24 hours from the second moment. The maintenance incremental data in the first stage specifically refers to all business change data generated between the first moment and the second moment, i.e., during the existing data migration.
[0047] It should be noted that, Figure 4 This is a flowchart of incremental data synchronization according to an embodiment of the present invention, such as... Figure 4 As shown, production traffic is routed through the proxy layer to the original application (hereinafter referred to as the original application), which provides services to the outside world and records the operation logs of all maintenance transactions during this period. At time TA (the system is in a low-business period at night), the existing business data in the source database is migrated to the target database using a data migration tool. At this time, the data in the target database is a copy of the source database at time TA. The data migration tool refers to the software or service that migrates data from the source database to the target database. It usually supports full data migration and incremental data synchronization, and supports data consistency comparison before and after migration. Existing data migration refers to the process of migrating all the data in the source database to the target database. This data is usually all the business data before a certain point in time. Incremental data synchronization refers to the process of synchronizing the updated data in the source database to the target database after the existing data migration is completed.
[0048] Optionally, an incremental data synchronization batch can be initiated at TB time. By using maintenance transaction log information, the records in the target database can be brought up to the records in the source database TB minus 1 day. Subsequently, an incremental data synchronization batch can be initiated at midnight every day to synchronize the data of the previous day. That is, the records in the target database are delayed by a maximum of 1 day compared with the records in the source database. The specific rules for the incremental data synchronization batch are as follows: read the maintenance transaction log of the previous day and synchronize the data in the order of timestamps; compare the data in the source database and the target database table by table to see if they are consistent. If they are inconsistent, the data in the source database will be forcibly overwritten in the target database.
[0049] This method manages incremental data through a time window mechanism. After the first time zone (TA) completes the full data migration, the source database continues to generate new maintenance transactions during peak business periods. The operation logs of these transactions are recorded by the proxy layer or application layer. When the second time zone (TB) starts incremental synchronization, a first-stage time window is defined, which ends at TB and traces back 24 hours. The system reads the business operation logs within this window, parses out all data change instructions in the order of timestamps, and replays these changes in the target database.
[0050] By implementing this control method, compatibility, strong consistency, and predictable data latency control between databases are achieved. By using a synchronization method based on business operation logs, it eliminates the dependence on specific database underlying log formats, enabling the method to be applied to database migration scenarios involving different brands, versions, and even architectures (such as from relational to large-scale models). Simultaneously, the strategy of daily scheduled start-up at midnight and a 24-hour time window transforms the high-intensity real-time synchronization pressure into low-frequency, batch offline processing tasks, significantly reducing the performance interference of the migration process on production business systems. Furthermore, through a consistency verification mechanism that compares tables one by one and forces overwrite, it ensures that the target database data always maintains eventual consistency with the source database, and data latency is strictly controlled within 24 hours.
[0051] Step S204: After determining that the maintenance incremental data in the source database will be synchronized to the target database, at the third time, the maintenance change data of the second phase written to the source database will be synchronized to the target database through the asynchronous processing thread and the dual-write mechanism will be verified to be correct. Then, the maintenance change data will be synchronously written to the source database and the target database through the business processing thread. The second phase refers to the time window from 0:00 on the third time of the day to the third time.
[0052] In this embodiment, the third time point refers to the formal start time of enabling the dual-write mechanism, i.e., the TC time point; the asynchronous processing thread refers to a background thread independent of the main business transaction thread, used to perform preliminary verification of the dual-write function without affecting the main business process; the second stage is specifically defined as the time window from 0:00 on the day of the third time point (TC time point) to the third time point, which is mainly used to process a small amount of incremental data generated from 0:00 on the day to the start time of dual-write; the maintenance change data in the second stage specifically refers to the business change data generated in the short period of time before the start of dual-write, between 0:00 on the day of the third time point (TC time point); the business processing thread refers to the main business thread that directly processes user transaction requests.
[0053] It should be noted that, Figure 5 This is a flowchart of the double-write compensation process according to an embodiment of the present invention, such as... Figure 5As shown, a dual-write mechanism is implemented at TC (True / False) time. At this point, the deviation between the target database and the original database is the record from 00:00 on the TC day to the TC time. Dual-write anomalies for some customers are normal. The dual-write compensation mechanism is a means to ensure data consistency during database migration. The application writes data to both the original and target databases simultaneously. If one write fails, a compensation mechanism ensures eventual data consistency. The core logic prioritizes successful writes to the original database to maintain the normal operation of the main business chain. If the target database write fails, an asynchronous compensation program is triggered via a message queue to correct the data. Specifically, after production traffic accesses the front-end proxy, the front-end proxy sends all maintenance operations to the original application first, then to the target application, and uses the return result from the original application as the standard. If a transaction in the original application fails, the transaction fails directly, and the target application is not called again. If a transaction in the original application succeeds but the transaction in the target application fails, the failure log is pushed to the message queue, and the dual-write compensation performs batch real-time reading of the failures. The system records and synchronizes data between the original and target databases in real time, with synchronization rules consistent with incremental data synchronization batches. The dual-write mechanism enables bidirectional synchronization between the target and original databases, with a data synchronization delay in the order of seconds. The dual-write mechanism is applied in two phases: when it is launched at TC (Trading Center) time, an asynchronous dual-write mode is used to verify the functionality without affecting trading. This mode utilizes an additional thread (non-trading thread) to perform the dual writes. Once the dual-write functionality is verified, it is switched to synchronous dual-write mode, directly using trading threads to complete the dual writes, increasing reliability. On TC+1 day, the incremental synchronization batch is invoked for the last time. Data that failed to be written after 00:00 on TC+1 day is compensated through a dual-write compensation batch to ensure bidirectional data consistency.
[0054] This method utilizes independent asynchronous processing threads to write existing maintenance and change data from 00:00 to the third hour of the day (TC) to the source and target databases in parallel. This serves as a pre-verification phase for the dual-write function, ensuring the logical correctness and anomalies of the data received by the target database. After successful asynchronous verification, the system switches to a synchronous dual-write mode executed by the main business thread. In this mode, all maintenance transactions simultaneously write data to both the source and target databases. If both writes are successful, the transaction is marked as successful. If the write to the source database succeeds but the write to the target database fails, the main transaction is still marked as successful, and the failed transaction is pushed to a message queue. The background compensation program asynchronously reads the transaction and retrieves the latest data from the source database for repair, thereby ensuring eventual data consistency.
[0055] By implementing this control method, the system prioritizes write responses to the source database (main link), isolating write failures in the target database during the asynchronous compensation phase. This achieves real-time bidirectional data synchronization between the source and target databases, preventing transaction interruptions due to target database anomalies and significantly reducing migration risks. Through the asynchronous verification phase, the system can fully expose potential defects in the dual-write function without affecting production transactions, ensuring the reliability of subsequent synchronous dual-writes. The combination of synchronous dual-writes and the message queue asynchronous compensation mechanism gives the main transaction link strong fault tolerance to target database failures. Even if a write to the target database fails, the user end can still receive a successful response. After the compensation program asynchronously repairs the data, the data at both ends eventually becomes consistent, meeting the stringent real-time requirements of the business, ensuring high availability of the main business, and avoiding the availability degradation problem caused by direct rollback due to target database failures in traditional dual-write solutions.
[0056] Step S206: After determining that the maintenance change data will be synchronously written to the source database and the target database, the query transaction data will be gradually switched from the source database to the target database according to the preset importance level.
[0057] In this embodiment, the preset importance level refers to the hierarchical sorting of query transactions based on the scope of business impact or the degree of risk. Typically, query transactions with low risk or non-core business are listed as low priority, while core or high-risk queries are listed as high priority. Query transaction data refers to business requests that only involve data reading and not data modification.
[0058] It should be noted that, Figure 6 This is a flowchart of the flow cutting and eviction migration according to an embodiment of the present invention, such as... Figure 6 As shown, query transactions are prioritized and traffic is gradually migrated from low to high through the gateway to the current database. This process of switching traffic allows for thorough verification of the target database's performance.
[0059] This method constructs a tiered traffic switching strategy based on business risk sensitivity. It dynamically adjusts routing rules at the gateway layer to achieve gradual traffic migration. Query transactions are sorted according to a preset importance level, forming a priority sequence from low to low risk. During the traffic switching process, the gateway first directs the lowest importance and least risky query traffic to the target database, while keeping high-importance queries routed to the source database, thus serving as a probe to verify the target database's performance. As the stability of the target database under low-priority traffic is verified, the system gradually increases the switching threshold, sequentially switching higher-importance query transactions to the target database until all query traffic has been migrated, completing the stress test and functional verification of the target database's capacity.
[0060] By implementing this control method, the risks of query traffic switching are made controllable, and performance verification is proactively implemented. Through a gradual switch from low to high importance, the system can promptly identify potential issues with the target database in terms of performance bottlenecks, compatibility, or data consistency at an early stage. Furthermore, since low-importance queries typically have low traffic or low real-time requirements, even if anomalies occur during the switch, the impact on overall business is limited to a minimum, avoiding the risk of core business paralysis caused by a direct full switch. In addition, this strategy decouples performance verification from traffic switching, allowing for a thorough evaluation of the target database's true performance without the user being aware of the migration process, ensuring a smooth, orderly, and reversible migration process.
[0061] Step S208: Switch business access requests to the target database according to the user data migration status, and take the source database offline after all user data has been switched to complete the migration.
[0062] In this embodiment, user data migration status refers to the status information recorded through the customer list or migration identifier as to whether the customer has been included in the target database service scope, used to distinguish between customers who have not been migrated and customers who have been migrated; business access requests refer to various database read and write requests initiated by the client; taking the source database offline means that after confirming that all customer traffic has been smoothly transitioned to the target database without any abnormalities, the business services of the source database are stopped and the relevant configurations are removed, marking the formal end of the entire heterogeneous database online migration process.
[0063] Optionally, such as Figure 6 As shown, customer-by-customer migration is a database migration strategy that gradually switches traffic. During the migration process, a small number of customers are first switched to the target database to observe the system's operation. If there are no problems, the scale of customers being migrated is gradually increased until all customers are migrated. Specifically, data migration is performed according to the customer dimension, and all customers are maintained in a customer list table. At this time, the agent layer schedules transactions based on whether the customer has completed the migration. If the customer has not yet migrated, query transactions are based on the target application, while maintenance transactions are still based on the original application. For customers who have already migrated, query transactions are based on the target application, and maintenance transactions still maintain dual writes, but at this time the dual write mechanism is based on the target application. After all customers have been migrated, the original application and database are taken offline.
[0064] This method employs a dynamic routing strategy to achieve a gradual switch from the source database to the target database. By maintaining a customer list containing the migration status of all customers, when the proxy layer receives a business access request, it first identifies the migration identifier of the customer to which the request belongs. For customers who have not migrated, query requests are routed to the target database to verify data consistency, while maintenance transactions are still written to the source database to maintain the original business logic. For customers who have migrated, a full switch to the target database is performed, and their maintenance transactions are synchronized to the source database through a dual-write mechanism. The write results in the target database are used as the criterion for transaction success, ensuring eventual data consistency. This mechanism allows the system to gradually strip traffic while retaining some customers in the source database until all customers have been migrated.
[0065] By implementing this control method, the migration process was made controllable and rollbackable. Through a customer-by-customer migration strategy, migration anomalies or performance issues of a single customer only affect that specific customer, and risks are isolated at the smallest granularity, avoiding global failures. This allows operations and maintenance personnel to monitor in real time and quickly roll back specific customer groups, greatly reducing migration risks. As customers of different importance levels are gradually switched, the system can fully verify the performance of the target database under real business loads, ensuring its stability when carrying core customer data. When all customer migrations are completed and confirmed to be error-free, taking the source database offline marks the complete end of the data migration work, achieving a smooth transition from the old architecture to the new architecture, ensuring business continuity while completing the upgrade and evolution of the technical architecture.
[0066] As described above, through the technical solution provided by the above embodiments of the present invention, after migrating the data from the source database to the target database at the first moment, based on the business operation log, the maintenance incremental data of the first stage in the source database is synchronized to the target database at the second moment. Here, the first stage refers to a time window tracing back 24 hours from the second moment as the end point. After determining that the maintenance incremental data in the source database is synchronized to the target database, at the third moment, the maintenance change data of the second stage written to the source database is synchronized to the target database through an asynchronous processing thread. After verifying that the dual-write mechanism is correct, the maintenance change data is synchronously written to both the source database and the target database through a business processing thread. Here, the second stage refers to the... The three-time window extends from 00:00 to the third time of the day. After determining that maintenance change data will be synchronously written to the source database and the target database, the query transaction data is gradually switched from the source database to the target database according to the preset importance level. The business access requests are switched to the target database according to the user data migration status, and the source database is taken offline after all user data is switched to complete the migration. This achieves the goal of building a proactive data consistency verification and compensation closed loop based on business flow, and realizing the physical isolation of the main transaction link from dual-write failure. It also achieves the technical effects of eliminating historical data differences through table-by-table forced overwrite, ensuring high availability of the main link through asynchronous verification, and minimizing the impact of failures based on the user dimension.
[0067] Therefore, the technical solution provided by the above embodiments of the present invention solves the technical problems in the related art where online migration of heterogeneous databases is prone to business interruption, data inconsistency and inflexible rollback due to coarse switching granularity and poor real-time performance of dual-write compensation.
[0068] According to the above embodiments of the present invention, migrating data from the source database to the target database at a first moment includes: reading data from the source database up to the first moment; writing the data into the target database to establish the initial state of the target database.
[0069] In this embodiment, the initial state of the target database refers to the state in which the data content stored in the target database is completely consistent with the data content of the source database at the specific point in time, after the migration of the existing data is completed. At this time, the target database contains all business data up to the first moment, but does not yet contain any new or changed data generated after the first moment.
[0070] This method locks the state of the source database at a specific point in time at the first moment of TA, reads all existing business data that has been committed before that moment, and persists it completely to the target database. This process does not involve any incremental changes or parsing of real-time transaction logs, but rather copies data blocks or records, instantly aligning the target database from a zero state or old state to the complete historical data view of the source database at the TA moment.
[0071] By implementing this control method, rapid initialization and consistency anchoring of existing data between databases were achieved, laying a solid data foundation for subsequent online migration. Through a one-time full migration, the system can efficiently complete the migration of massive amounts of historical data during off-peak business periods, avoiding the performance overhead and long waiting time caused by synchronization one by one. The established initial state ensures that the target database has a historical data view that is completely consistent with the source database before incremental synchronization starts, eliminating the risk of data loss or version misalignment. This decouples the full and incremental phases of the migration process, reduces system complexity, and ensures that the data at both ends is at a highly consistent baseline level when the dual-write mechanism is started, thereby significantly reducing the data verification pressure and potential consistency issues in the early stages of migration.
[0072] According to the above embodiments of the present invention, based on the business operation log, the maintenance incremental data of the first stage in the source database is synchronized to the target database at the second time, including: extracting the maintenance transaction flow of the first stage at the second time; searching for the data record corresponding to each maintenance transaction flow in the source database, and comparing the data record with the corresponding record in the target database to obtain the comparison result; when the comparison result shows inconsistency, the data record in the source database is overwritten into the record in the target database.
[0073] In this embodiment, the business operation log refers to the operation flow information of all maintenance transactions (i.e., operations involving data writing, updating, or deletion) recorded in the source database. This log contains key information such as the transaction timestamp, operation type, and affected data records. It is used to track and locate all data changes generated after the completion of the existing data migration during the incremental synchronization phase, serving as the basis for data synchronization and consistency verification. The maintenance transaction flow of the first stage refers to the operation log or flow record recorded in the source database, used to track all maintenance business operations in the first stage (i.e., from the time of existing data migration to the time of dual-write startup). It contains the time, type, and content information of data changes. The comparison result refers to the judgment conclusion obtained after comparing the latest data record in the source database with the old data record in the corresponding position in the target database table by table and field by field, showing whether the two are consistent. Overwrite refers to the forced writing of data records in the source database to the target database when data inconsistency is found, based on the data in the source database, thereby replacing the old and inconsistent data records in the target database to achieve data consistency.
[0074] In the second time step (TB), the system first extracts the maintenance transaction logs generated within the first time window. These logs record all data change operations that occurred in the source database. Subsequently, the system retrieves the latest complete data record in the source database based on the log information and performs a fine-grained comparison between the record and the corresponding position in the target database, table by table and field by field. By forcibly refreshing the difference data, the system ensures that the data in the target database always remains absolutely consistent with the source database.
[0075] By implementing this control method, the dependency on specific database storage engines and log formats is eliminated, enabling the migration process to seamlessly support heterogeneous databases of different brands and versions. At the same time, the mechanism of comparing tables one by one and forcibly overwriting actively discovers and repairs data differences, avoiding silent data errors caused by network jitter or application anomalies, and ensuring data consistency. In addition, this process runs as a background batch task, which is unaware of production business traffic, ensuring the accuracy of data synchronization and maintaining the high-performance operation of the system.
[0076] According to the above embodiments of the present invention, after determining that the maintenance incremental data in the source database will be synchronized to the target database, the maintenance change data of the second stage written to the source database will be synchronized to the target database through an asynchronous processing thread at a third time and the dual-write mechanism will be verified to be correct. This includes: after receiving the maintenance transaction request at the third time, the maintenance transaction request will be written to the source database using the main business processing thread, and the writing result will be fed back to the client; when the writing result shows success, the maintenance change data corresponding to the maintenance transaction request will be captured and written to the target database; if the maintenance change data is successfully written to the target database and the data verification passes, the dual-write mechanism will be determined to be correct.
[0077] In this embodiment, the asynchronous processing thread refers to a non-transaction thread specifically designed to perform dual-write tasks. It is independent of the main business thread that responds to client requests and is used to synchronize changed data from the source database to the target database in the background to avoid blocking the main transaction chain. The main business processing thread is the core thread that is directly responsible for receiving client requests, executing business logic, and writing data to the source database. Its execution result directly determines the success or failure of the transaction and is fed back to the client. The write result refers to the status information (such as success or failure) returned by the main business processing thread after writing the maintenance transaction request to the source database, which is used to confirm whether the content in the source database has been saved. Data verification refers to the process of comparing whether the written data in the source database is consistent with the data received in the target database, which is used to confirm the integrity and correctness of the dual-write data.
[0078] This method writes maintenance transaction requests to the source database through the main business processing thread and immediately returns the write results to the client, thereby ensuring low latency and fast response of the main transaction chain. Successful writing to the source database means successful transaction. Subsequently, the system captures changed data from successful transactions, uses an independent asynchronous processing thread to write it to the target database in parallel, and performs data consistency verification. Through decoupling design, write failure or delay in the target database will not block the main transaction. At the same time, the verification process of the asynchronous thread is used to confirm the correctness of the dual-write logic. Only when the verification is correct does the system consider the dual-write mechanism to be in a usable state, laying the foundation for subsequent switching to synchronous dual-write mode.
[0079] By implementing this control method, zero business interruption and minimization of migration risks were achieved. It avoided blocking or failure of front-end business caused by target database performance fluctuations or network anomalies, ensuring high availability of the core transaction link. The asynchronous verification mechanism enabled the testing of the dual-write function to be carried out in non-production load or low-interference environments, which could fully expose potential data format conversion errors or connection problems without directly affecting ongoing business transactions. In addition, it ensured that before switching to the more performance-demanding synchronous dual-write mode, the system had confirmed that the target database could correctly receive and store changed data, thereby significantly reducing the risk of data inconsistency in the early stages of migration and improving the controllability and reliability of the overall migration solution.
[0080] According to the above embodiments of the present invention, the maintenance change data is synchronously written to the source database and the target database through the business processing thread, including: using the business processing thread to synchronously write the maintenance change data to the source database and the target database to obtain a response result; when the response result shows that the source database was successfully written and the target database was failed to be written, the failure log containing the maintenance transaction request is pushed to the message queue; and the failure log is read through the compensation program and the corresponding latest data is obtained from the source database to compensate the target database.
[0081] In this embodiment, the response result refers to the status information returned by the source database and the target database respectively after receiving the write instruction, indicating whether the write operation was successful or failed; the failure log refers to the error log record recorded by the system when the write to the source database is successful but the write to the target database fails, containing key information of the maintenance transaction request (such as transaction ID, timestamp, etc.), used for tracking and compensation; the message queue refers to an asynchronous message passing mechanism used to temporarily store the failure log, ensuring that the failure log data is not lost even if the compensation program is temporarily unavailable, and awaits subsequent processing; the compensation program refers to an automated program running in the background, responsible for reading the failure log from the message queue, performing data repair operations, and ensuring that the data in the source database and the target database are eventually consistent; the latest data refers to the complete data record in the source database reflecting the latest business status after the write operation, used to correct missing or erroneous data in the target database.
[0082] When the business processing thread performs a dual write, if the write to the source database succeeds but the write to the target database fails, the system does not directly roll back the main transaction. Instead, it pushes the failed maintenance transaction log to the message queue for persistent storage to ensure that error information is not lost. Subsequently, the background compensation program asynchronously reads these failed logs, retrieves the latest complete data record after the successful write from the source database, and rewrites it to the target database to correct the differences.
[0083] By implementing this control method, zero-blocking and highly reliable data consistency assurance were achieved in the main transaction chain. By isolating write failures in the target database in the asynchronous compensation stage, the main business transactions do not need to wait for the target database to respond or handle exceptions, significantly reducing transaction latency, avoiding large-scale transaction failures caused by target database failures, and improving system availability. At the same time, by using message queues as a buffer, it is ensured that compensation tasks can be reliably executed even during peak front-end traffic or when the compensation program is temporarily unavailable, achieving automatic fault recovery and providing a solid data security barrier for online migration.
[0084] According to the above embodiments of the present invention, after determining that maintenance change data will be synchronously written to the source database and the target database, query transaction data is gradually switched from the source database to the target database according to a preset importance level, including: establishing a priority list based on the preset importance level, wherein the query transaction data in the priority list are arranged in order of increasing importance; switching the query transaction data with the lowest importance in the priority list to the target database and monitoring the operating performance indicators of the target database; and after confirming that the operating performance indicators of the target database are within a preset range, sequentially switching the subsequent query transaction data in the priority list to the target database.
[0085] In this embodiment, the preset importance level refers to a predefined grading standard used to measure the impact of query transactions on business and the amount of system resource consumption. It is usually divided into low, medium, and high levels and is used to determine the order of switching. The priority list is an ordered set generated by sorting query transaction data according to the preset importance level. The elements in the list are arranged in order of importance from low to high, and serve as the basis for the execution of the flow switching operation. Query transaction data refers to business requests initiated by the client that only involve reading data from the database without modifying the data and their return results, which are different from maintenance transactions that involve writing data. The performance indicators refer to key parameters that reflect the current operating status of the target database, including but not limited to response latency, transaction processing per second, CPU utilization, memory usage, and number of connections. The preset range refers to a pre-set threshold range used to judge whether the performance of the target database is normal. When the performance indicators are within this range, the database is considered to be operating stably.
[0086] This method constructs a tiered traffic switching strategy based on risk sensitivity, dynamically adjusting routing rules at the gateway layer to achieve gradual traffic migration. The system sorts query transactions according to a preset importance level, forming a priority sequence from low to high risk. During the traffic switching process, the gateway first directs the query traffic with the lowest importance level and least risk to the target database, while keeping high-importance queries processed by the source database. This serves as an initial performance verification of the target database. The core logic is: query traffic is switched to the target database only when the risk level of a query transaction is below a set threshold and the target database's performance indicators are within a preset normal range. As the stability of the target database under low-priority traffic is verified, the system gradually increases the switching threshold, sequentially switching higher-importance query transactions to the target database until all query traffic has been migrated. This completes a comprehensive stress test and functional verification of the target database's capacity without interfering with core business operations.
[0087] By implementing this control method, the risks of query traffic switching are made controllable, and performance verification is proactively implemented. This allows the system to identify potential issues with the target database in terms of performance bottlenecks, compatibility, or data consistency at an early stage, avoiding the risk of core business paralysis caused by a direct full switch. Furthermore, this strategy decouples performance verification from traffic switching, enabling the operations team to fully assess the target database's actual performance without being aware of it.
[0088] According to the above embodiments of the present invention, the process of switching business access requests to the target database according to the user data migration status and taking the source database offline after all user data switching is completed to complete the migration includes: obtaining a target user list, wherein the target user list includes users to be migrated and users who have been migrated; when the user is a user who has been migrated, maintenance change data is written to both the source database and the target database simultaneously through a dual-write mechanism, and the write result of the target database is used as the basis for determining the success of the transaction, and the target database is queried to respond to query-type transactions; when the user is a user to be migrated, maintenance change data is written to the source database, and the target database is queried to respond to query-type transactions.
[0089] In this embodiment, the target user list refers to a data structure maintained internally by the system that records the current migration status of each customer, used to distinguish whether a user is in a pending migration or already migrated state. Pending migration users are those whose business traffic has not yet been fully switched to the target database, and their data is mainly stored in the source database. Migrated users are those who have completed the business traffic switch, and whose main business data reads and writes are directed to the target database. The dual-write mechanism refers to the technical means of sending write requests to both the source and target databases simultaneously during the migration transition to ensure data consistency between the two ends. The criteria for determining transaction success specifically refer to using successful writes to the target database as the marker of transaction success. Query transactions refer to business requests initiated by the client that only read data from the database without modifying it. Response query transactions refer to the process where the system receives a query request, retrieves data from the specified database, and returns it to the client. Taking the source database offline means stopping the source database service and disconnecting it after confirming that all user data migration is complete and the target database is running stably, marking the complete end of the migration work.
[0090] This method is based on a bidirectional routing switching and data consistency guarantee mechanism at the user granularity level. The system maintains a target user list containing the status of users to be migrated and users who have already been migrated. The proxy layer performs differentiated routing of business requests based on this list. For users who have already been migrated, the system adopts a dual-write and target database priority strategy, writing maintenance transactions to both the source database and the target database simultaneously, but using the successful write to the target database as the final criterion for transaction determination, while query transactions directly point to the target database. For users to be migrated, maintenance transactions are only written to the source database, while query transactions point to the target database to verify data consistency. Through fine-grained scheduling, the system gradually strips traffic from the source database until all users have completed the migration.
[0091] By implementing this control method, a smooth transition, risk isolation, and seamless business cutover were achieved during the migration process. Through a customer-by-customer migration strategy, migration anomalies or performance issues affecting a single user only impact that specific user, strictly limiting risk to the smallest granularity and avoiding global failures. It also supports rapid rollback to specific customer groups. By gradually switching users in different states, the system can fully verify the stability of the target database under business loads. Once all users have migrated and the source database is offline, the online database migration is complete, achieving a seamless migration from the old architecture to the new architecture and ensuring business continuity and data security.
[0092] As described above, through the technical solution provided by the above embodiments of the present invention, after migrating the data from the source database to the target database at the first moment, based on the business operation log, the maintenance incremental data of the first stage in the source database is synchronized to the target database at the second moment. Here, the first stage refers to a time window tracing back 24 hours from the second moment as the end point. After determining that the maintenance incremental data in the source database is synchronized to the target database, at the third moment, the maintenance change data of the second stage written to the source database is synchronized to the target database through an asynchronous processing thread. After verifying that the dual-write mechanism is correct, the maintenance change data is synchronously written to both the source database and the target database through a business processing thread. Here, the second stage refers to the third... The time window is from 00:00 to the third hour of the day; after determining that the maintenance change data will be synchronously written to the source database and the target database, the query transaction data is gradually switched from the source database to the target database according to the preset importance level; the business access requests are switched to the target database according to the user data migration status, and the source database is taken offline after all user data is switched to complete the migration. This achieves the goal of building a closed loop of full-link data consistency verification based on business flow and realizing the dynamic decoupling of read and write traffic and migration progress. This achieves the technical effects of zero-difference data alignment based on the active compensation mechanism, logical isolation of the main business link from dual write failures, and smooth evolution based on user-dimensional risk minimization.
[0093] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0094] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0095] Example 2
[0096] According to embodiments of the present invention, a data migration apparatus for implementing the above-described data migration method is also provided. Figure 7 This is a schematic diagram of a data migration apparatus according to an embodiment of the present invention, such as... Figure 7 As shown, the device includes: a synchronization unit 701, a writing unit 703, a first switching unit 705, and a second switching unit 707. The device will now be described in detail.
[0097] Synchronization unit 701 is used to migrate the data from the source database to the target database at the first moment, and then, based on the business operation log, synchronize the maintenance incremental data of the first phase from the source database to the target database at the second moment. The first phase refers to a time window that traces back 24 hours from the second moment.
[0098] The writing unit 703 is used to synchronize the maintenance incremental data in the source database to the target database through an asynchronous processing thread at the third time after determining that the maintenance change data in the source database is synchronized to the target database and the dual-write mechanism is correct. Then, the maintenance change data is synchronously written to the source database and the target database through the business processing thread. The second stage refers to the time window from 0:00 on the third time to the third time.
[0099] The first switching unit 705 is used to gradually switch the query transaction data from the source database to the target database according to the preset importance level after determining that the maintenance change data will be synchronously written to the source database and the target database.
[0100] The second switching unit 707 is used to switch business access requests to the target database according to the user data migration status, and take the source database offline after all user data is switched to complete the migration.
[0101] It should be noted that the above-mentioned synchronization unit 701, writing unit 703, first switching unit 705, and second switching unit 707 correspond to steps S202 to S208 in the above embodiments. The four units and the corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in the above embodiments.
[0102] As can be seen from the above, in the solution described in the above embodiments of the present invention, the synchronization unit 701 can be used to migrate the data in the source database to the target database at the first moment, and then, based on the business operation log, synchronize the maintenance incremental data of the first stage in the source database to the target database at the second moment, wherein the first stage refers to a time window tracing back 24 hours from the second moment as the end point; the writing unit 703 can be used to, after determining that the maintenance incremental data in the source database is synchronized to the target database, synchronize the maintenance change data of the second stage written to the source database to the target database through an asynchronous processing thread at the third moment, and after verifying that the dual-write mechanism is correct, synchronize the maintenance change data to both the source database and the target database through a business processing thread, wherein the second stage refers to the third moment of the day The time window is from 0:00 to the third moment. The first switching unit 705 is used to gradually switch the query transaction data from the source database to the target database according to the preset importance level after determining that the maintenance change data will be synchronously written to the source database and the target database. The second switching unit 707 is used to switch the business access request to the target database according to the user data migration status, and take the source database offline after all user data is switched to complete the migration. Through the above technical solution, the complex processes such as data synchronization, dual-write verification, read-write flow switching and customer-by-customer migration are modularized and decoupled, and the status of the entire migration process is observable and the steps are controllable. The technical effects of independent reuse of functions in each migration stage, front-end interception of dual-write risks, and gradual smooth transition based on traffic classification are achieved.
[0103] Therefore, the technical solution provided by the above embodiments of the present invention solves the technical problems in the related art where online migration of heterogeneous databases is prone to business interruption, data inconsistency and inflexible rollback due to coarse switching granularity and poor real-time performance of dual-write compensation.
[0104] Optionally, the synchronization unit includes: a first reading module for reading data from the source database up to the first moment; and a second writing module for writing the data into the target database to establish the initial state of the target database.
[0105] Optionally, the synchronization unit further includes: an extraction module for extracting the maintenance transaction log of the first stage at the second moment; a search module for searching for the data record corresponding to each maintenance transaction log in the source database and comparing the data record with the corresponding record in the target database to obtain the comparison result; and a third writing module for overwriting the data record in the target database with the data record in the source database when the comparison result shows inconsistency.
[0106] Optionally, the writing unit includes: a fourth writing module, used to write the maintenance transaction request to the source database using the main business processing thread after receiving the maintenance transaction request at the third moment, and to feed back the writing result to the client; a first acquisition module, used to capture the maintenance change data corresponding to the maintenance transaction request and write the maintenance change data to the target database after the writing result shows success; and a determination module, used to determine that the dual-write mechanism is correct if the maintenance change data is successfully written to the target database and the data verification passes.
[0107] Optionally, the writing unit further includes: a fifth writing module, used to synchronously write maintenance change data to the source database and the target database using the business processing thread to obtain a response result; a push module, used to push the failure log containing the maintenance transaction request to the message queue when the response result shows that the source database writing was successful and the target database writing failed; and a compensation module, used to read the failure log through the compensation program and obtain the corresponding latest data from the source database to compensate the target database.
[0108] Optionally, the first switching unit includes: a table creation module, used to create a priority list based on a preset importance level, wherein the query transaction data in the priority list are arranged in order of increasing importance; a first switching module, used to switch the query transaction data with the lowest importance in the priority list to the target database and monitor the operating performance indicators of the target database; and a second switching module, used to switch the subsequent query transaction data in the priority list to the target database in sequence after confirming that the operating performance indicators of the target database are within a preset range.
[0109] Optionally, the second switching unit includes: a second acquisition module, used to acquire a target user list, wherein the target user list includes users to be migrated and users who have already been migrated; a sixth writing module, used to write maintenance change data to both the source database and the target database simultaneously through a dual-write mechanism when the user is a migrated user, and to use the write result of the target database as the basis for determining the success of the transaction, and to query the target database to respond to query-type transactions; and a seventh writing module, used to write maintenance change data to the source database when the user is a user to be migrated, and to query the target database to respond to query-type transactions.
[0110] According to another aspect of the present invention, a database migration system is also provided, which uses any of the data migration methods described above.
[0111] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored program, wherein the program performs the data migration method described above.
[0112] According to another aspect of the present invention, a processor is also provided, which is used to run a program, wherein the program executes any of the above-described data migration methods during runtime.
[0113] According to one aspect of the present invention, a computer program product is provided, including computer instructions, which, when executed by a processor, perform any of the above-described data migration methods.
[0114] Optionally, in this embodiment, the computer-readable storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any communication device in a group of communication devices.
[0115] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: After migrating data from the source database to the target database at a first moment, based on the business operation log, the maintenance incremental data of the first phase in the source database is synchronized to the target database at a second moment, wherein the first phase refers to a time window tracing back 24 hours from the second moment; after determining that the maintenance incremental data in the source database is synchronized to the target database, at a third moment, the maintenance change data of the second phase written to the source database is synchronized to the target database through an asynchronous processing thread, and after verifying that the dual-write mechanism is correct, the maintenance change data is synchronously written to the source database and the target database through a business processing thread, wherein the second phase refers to the time window from 0:00 on the third moment to the third moment; after determining that the maintenance change data is synchronously written to the source database and the target database, the query transaction data is gradually switched from the source database to the target database according to a preset importance level; the business access requests are switched to the target database according to the user data migration status, and the source database is taken offline after all user data is switched to complete the migration.
[0116] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: migrating data from the source database to the target database at a first moment, including: reading data from the source database up to the first moment; writing the data into the target database, and establishing the initial state of the target database.
[0117] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: based on the business operation log, synchronizing the maintenance incremental data of the first stage in the source database to the target database at a second time, including: extracting the maintenance transaction log of the first stage at the second time; searching for the data record corresponding to each maintenance transaction log in the source database, and comparing the data record with the corresponding record in the target database to obtain a comparison result; when the comparison result shows inconsistency, overwriting the record in the target database with the data record in the source database.
[0118] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: after determining that the maintenance incremental data in the source database will be synchronized to the target database, at a third moment, the maintenance change data of the second stage written to the source database will be synchronized to the target database through an asynchronous processing thread and the dual-write mechanism will be verified to be correct. This includes: after receiving the maintenance transaction request at the third moment, the maintenance transaction request will be written to the source database using the main business processing thread, and the writing result will be fed back to the client; when the writing result shows success, the maintenance change data corresponding to the maintenance transaction request will be captured and the maintenance change data will be written to the target database; if the maintenance change data is successfully written to the target database and the data verification passes, the dual-write mechanism will be determined to be correct.
[0119] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: synchronously writing maintenance change data to the source database and the target database through a business processing thread, including: using the business processing thread to synchronously write maintenance change data to the source database and the target database, and obtaining a response result; when the response result shows that the source database was successfully written and the target database was written unsuccessfully, pushing the failure log containing the maintenance transaction request to the message queue; and reading the failure log and obtaining the corresponding latest data from the source database through a compensation program to compensate the target database.
[0120] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: after determining that maintenance change data will be synchronously written to the source database and the target database, query transaction data is gradually switched from the source database to the target database according to a preset importance level, including: establishing a priority list based on the preset importance level, wherein the query transaction data in the priority list are arranged in order of increasing importance; switching the query transaction data with the lowest importance in the priority list to the target database and monitoring the operating performance indicators of the target database; after confirming that the operating performance indicators of the target database are within a preset range, sequentially switching the subsequent query transaction data in the priority list to the target database.
[0121] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: switching business access requests to the target database according to the user data migration status, and taking the source database offline to complete the migration after all user data has been switched, including: obtaining a target user list, wherein the target user list contains users to be migrated and users who have been migrated; when the user is a user who has been migrated, writing maintenance change data to both the source database and the target database simultaneously through a dual-write mechanism, and using the write result of the target database as the basis for determining the success of the transaction, and querying the target database to respond to query-type transactions; when the user is a user to be migrated, writing maintenance change data to the source database, and querying the target database to respond to query-type transactions.
[0122] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0123] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0124] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0125] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0126] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0127] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0128] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0129] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A data migration method, characterized by, include: After migrating the data from the source database to the target database at the first moment, based on the business operation log, the maintenance incremental data of the first phase in the source database is synchronized to the target database at the second moment. The first phase refers to a time window that traces back 24 hours from the second moment as the end point. After determining that the maintenance incremental data in the source database will be synchronized to the target database, at the third time, the maintenance change data of the second stage written to the source database will be synchronized to the target database through an asynchronous processing thread and the dual-write mechanism will be verified to be correct. Then, the maintenance change data will be synchronously written to the source database and the target database through a business processing thread. The second stage refers to the time window from 0:00 on the third time day to the third time. After determining that the maintenance change data will be synchronously written to the source database and the target database, the query transaction data will be gradually switched from the source database to the target database according to the preset importance level. According to the user data migration status, the business access requests are switched to the target database, and the source database is taken offline after all user data has been switched to complete the migration.
2. The data migration method of claim 1, wherein, Migrate data from the source database to the target database immediately, including: Read the data from the source database up to the first time point; The data is written into the target database to establish the initial state of the target database.
3. The data migration method of claim 2, wherein, Based on the business operation logs, the incremental maintenance data from the first phase in the source database is synchronized to the target database at the second moment, including: Extract the maintenance transaction log from the first phase at the second time point; Find the data record corresponding to each maintenance transaction in the source database, and compare the data record with the corresponding record in the target database to obtain the comparison result; When the comparison results show inconsistency, the data record in the source database is overwritten into the record in the target database.
4. The data migration method of claim 1, wherein, After determining that the maintenance incremental data in the source database will be synchronized to the target database, at a third moment, the maintenance change data of the second phase written to the source database will be synchronized to the target database through an asynchronous processing thread, and the dual-write mechanism will be verified to be correct, including: After receiving the maintenance transaction request at the third moment, the main business processing thread writes the maintenance transaction request into the source database and sends the writing result back to the client. Once the write result is displayed as successful, the maintenance change data corresponding to the maintenance transaction request is captured, and the maintenance change data is written to the target database; If the maintenance change data is successfully written to the target database and the data verification passes, the dual-write mechanism is confirmed to be correct.
5. The data migration method according to claim 4, characterized in that, The maintenance change data is synchronously written to the source database and the target database through the business processing thread, including: The maintenance change data is synchronously written to the source database and the target database using the business processing thread to obtain a response result; When the response result shows that the source database was successfully written and the target database was not written, the failure log containing the maintenance transaction request will be pushed to the message queue. The compensation procedure reads the failed transaction logs and retrieves the corresponding latest data from the source database to compensate the target database.
6. The data migration method according to claim 1, characterized in that, After determining that the maintenance change data will be synchronously written to the source database and the target database, the query transaction data is gradually switched from the source database to the target database according to a preset importance level, including: Based on the preset importance level, a priority list is established, wherein the query transaction data in the priority list are arranged in order of increasing importance; Switch the lowest priority query transaction data in the priority list to the target database, and monitor the performance metrics of the target database; After confirming that the performance metrics of the target database are within a preset range, the subsequent query transaction data in the priority list are sequentially switched to the target database.
7. The data migration method according to claim 1, characterized in that, According to the user data migration status, business access requests are switched to the target database, and the source database is taken offline after all user data has been switched to complete the migration, including: Obtain a target user list, which includes users to be migrated and users who have already been migrated; When the user is the migrated user, the maintenance change data is written to both the source database and the target database simultaneously through the dual-write mechanism. The write result of the target database is used as the basis for determining the success of the transaction, and the target database is queried to respond to query-type transactions. When the user is the user to be migrated, the maintenance change data is written to the source database, and the target database is queried in response to query-type transactions.
8. A data migration device, characterized in that, include: The synchronization unit is used to migrate the data from the source database to the target database at the first moment, and then, based on the business operation log, synchronize the maintenance incremental data of the first phase in the source database to the target database at the second moment. The first phase refers to a time window that traces back 24 hours from the second moment as the end point. The writing unit is used to, after determining that the maintenance incremental data in the source database will be synchronized to the target database, synchronize the maintenance change data of the second stage written to the source database to the target database through an asynchronous processing thread at a third time and verify that the dual-write mechanism is correct, and then synchronize the maintenance change data to the source database and the target database through a business processing thread. The second stage refers to the time window from 0:00 on the third time to the third time. The first switching unit is used to, after determining that the maintenance change data will be synchronously written to the source database and the target database, gradually switch the query transaction data from the source database to the target database according to a preset importance level. The second switching unit is used to switch business access requests to the target database according to the user data migration status, and to take the source database offline after all user data has been switched to complete the migration.
9. A database migration system, characterized in that, The database migration system uses the data migration method described in any one of claims 1 to 7.
10. A computer program product comprising computer instructions, characterized in that, When the computer instructions are executed by the processor, the data migration method according to any one of claims 1 to 7 is performed.
