Data migration method, device, electronic device and computer storage medium
By adopting the data migration method of routing access strategy and grayscale switching table and switch strategy in bank electronic channels, the performance bottleneck and downtime problems in traditional database migration are solved, and efficient, imperceptible data migration and data security are achieved.
Patent Information
- Application Number
- CN202110333945.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-29
- Publication Date
- 2024-10-08
- Estimated Expiration
- 2041-03-29
AI Technical Summary
Traditional centralized databases have performance bottlenecks in the process of high concurrency and data migration in bank electronic channels, resulting in impaired user experience, and the downtime migration strategy may cause irreversible data damage and user complaints.
Adopt a data migration method based on routing access strategy and grayscale switching table and switching strategy. By controlling the routing access of data tables at the application layer, data migration is achieved smoothly and downtime is avoided. Redis is used for real-time data update and verification to ensure data consistency. and security.
It achieves data migration that is imperceptible to customers, reduces the risk of production interruptions, reduces the occurrence of production events, and improves user experience and system reliability.
Smart Images

Figure CN112860670B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of database technology. Specifically, the present application relates to a data migration method, device, electronic device and computer storage medium. Background Art
[0002] In recent years, the online channels of retail banks have developed rapidly, the number of users has continued to grow at a high speed, and the replacement rate of the number and amount of electronic banking transactions has exceeded 94%. Electronic channels have become the main channels for retail customer transactions. At the same time, the contradiction between rapid business development and insufficient technical support has become increasingly acute. The traditional centralized databases used by many banks have low throughput, high machine load, insufficient high-concurrency business carrying capacity, and serious reliance on single-point databases. Problems such as these have gradually been exposed. The performance bottleneck of the traditional centralized database that data storage relies on has become a key factor restricting the sustainable development of electronic channels.
[0003] In order to support a large number of users, improve the carrying capacity of high-concurrency and flash sales services, and quickly respond to market demand, many banks have explored distributed database migration. When migrating distributed databases, in order to maintain the consistency of data before and after data migration and prevent dirty data, transactions that update database data need to be blocked during the data migration process. This is because the user data of bank electronic channels has the characteristics of large data volume, high complexity, data sensitivity and high accuracy requirements. At the same time, given the huge functions of business systems and the numerous and complex business scenarios, the industry currently generally adopts a shutdown strategy, that is, to prevent users from trading by shutting down the application server. The existing practice is to shut down the application server of the system to be migrated before the distributed database is migrated, and the application system stops providing services to customers. After the database migration is completed, the application server is restarted.
[0004] However, the inventor of this application found in the specific implementation process that the solution of completely shutting down until the database migration is completed and then restarting the application server is simple in logic, low in operating cost, and not prone to errors. However, the bank's electronic channel business system belongs to the middle-office business system in the bank's IT system. The availability of the system and the accuracy of user data will be directly related to the use of the user's electronic channel function. Long-term downtime will cause users to be unable to use any function of the electronic channel during this period, seriously affecting the user experience and causing great damage to the bank's reputation and reputation. In addition, the bank's electronic channel system has a large amount of user data and has high requirements for data security and accuracy. It cannot be rolled back after switching. Once a production accident occurs after going online, data recovery is difficult, which may cause irreversible damage to users and may even cause user complaints, which is a high risk. Summary of the invention
[0005] The purpose of the embodiments of the present application is to solve at least one of the above technical defects, and the following technical solutions are proposed:
[0006] In one aspect, a data migration method is provided, comprising:
[0007] Determine the user data tables to be migrated from the original database, where the user data tables to be migrated are all or part of the user data tables in the original database;
[0008] Based on the preset routing access strategy, grayscale switching table and switch strategy, the user data table to be migrated is migrated from the original database to the target database, and data access to the user data table to be migrated in the target database is controlled.
[0009] In a possible implementation, the grayscale switching table and the switch strategy include a grayscale switching table, a user switching table, a table switching information table, and a transaction code and table correspondence table; wherein,
[0010] The grayscale switch table is used to control data access and data migration of the entire application;
[0011] The user switching table stores the identifiers of the user to be switched to access the original database and the target database, and is used to control the database access at the user level;
[0012] The table switching information table stores the ready state, table type and table access route of the table to be switched, and is used to control database access at the data table level. The ready state includes the unready state and the ready state. The table type includes the user table and the parameter table. The table access route includes the original database and the target database.
[0013] The transaction code and table correspondence table is used to store table switching or to prevent writing of transaction lists during user switching.
[0014] In a possible implementation, the grayscale switch table includes a master control switch, a switching switch, and a new user access switch;
[0015] The master switch is used to control data access of the entire application. The master switch includes the initial state, grayscale state, and external release state.
[0016] The switch is used to control the migration of users or data tables from the original database to the target database. The switch includes the states of not started switching, switching in progress, and switching completed.
[0017] The new user access switch is used to control whether the new user accesses the original database or the target database.
[0018] In one possible implementation, the data in the grayscale switch table, user switching table, table switching information table, and transaction code and table correspondence table are all set by a scheduled task to the remote dictionary service Redis, so that the application can read data from Redis and write the updated data to Redis in real time when the data is updated.
[0019] In a possible implementation, when any one of the grayscale switch table, the user switch table, the table switch information table, and the transaction code and table correspondence table includes key user information, an attribute representing the user switch state is added to any table to control database access to a single piece of user data;
[0020] Among them, key user information includes at least one of the following:
[0021] User ID, email address, ID number, security authentication mobile number, login mobile number, contract account, core customer number, machine code, identity verification system OpenID;
[0022] The user switching status includes not switched, switching, and switched.
[0023] In a possible implementation, before migrating the user data table to be migrated from the original database to the target database based on the preset routing access strategy, the grayscale switching table and the switch strategy, the method further includes:
[0024] The user data table to be migrated is divided into a user table and a parameter table according to whether the user data table to be migrated includes key user information and an application scenario of the user data table to be migrated.
[0025] In a possible implementation, the routing access policy includes a user table access policy and a parameter table access policy;
[0026] The user table access policy is used to control whether the user accesses the original database or the target database. If the master control switch is grayed out and the user ID is switched, or the master control switch is released to the outside, the user is controlled to access the target database; otherwise, the user is controlled to access the original database.
[0027] The parameter table access policy is used to control whether the user accesses the original database or the target database. If the parameter table status is externally released or the grayscale access identifier is the target database, the user is controlled to access the target database; otherwise, the user is controlled to access the original database.
[0028] In a possible implementation, the routing access policy also includes a newly added user access policy;
[0029] The new user access policy is used to determine whether the data of the new user is saved in the target database or the original database by configuring the status of the switch for the registered user in the database system parameter table.
[0030] In one aspect, a data migration device is provided, comprising:
[0031] A determination module, used to determine the user data tables to be migrated from the original database, where the user data tables to be migrated are all or part of the user data tables in the original database;
[0032] The processing module is used to migrate the user data table to be migrated from the original database to the target database based on the preset routing access strategy, grayscale switching table and switch strategy, and control data access to the user data table to be migrated in the target database.
[0033] In a possible implementation, the grayscale switching table and the switch strategy include a grayscale switching table, a user switching table, a table switching information table, and a transaction code and table correspondence table; wherein,
[0034] The grayscale switch table is used to control data access and data migration of the entire application;
[0035] The user switching table stores the identifiers of the user to be switched to access the original database and the target database, and is used to control the database access at the user level;
[0036] The table switching information table stores the ready state, table type and table access route of the table to be switched, and is used to control database access at the data table level. The ready state includes the unready state and the ready state. The table type includes the user table and the parameter table. The table access route includes the original database and the target database.
[0037] The transaction code and table correspondence table is used to store table switching or to prevent writing of transaction lists during user switching.
[0038] In a possible implementation, the grayscale switch table includes a master control switch, a switching switch, and a new user access switch;
[0039] The master switch is used to control data access of the entire application. The master switch includes the initial state, grayscale state, and external release state.
[0040] The switch is used to control the migration of users or data tables from the original database to the target database. The switch includes the states of not started switching, switching in progress, and switching completed.
[0041] The new user access switch is used to control whether the new user accesses the original database or the target database.
[0042] In one possible implementation, the data in the grayscale switch table, user switching table, table switching information table, and transaction code and table correspondence table are all set by a scheduled task to the remote dictionary service Redis, so that the application can read data from Redis and write the updated data to Redis in real time when the data is updated.
[0043] In a possible implementation, when any one of the grayscale switch table, the user switch table, the table switch information table, and the transaction code and table correspondence table includes key user information, an attribute representing the user switch state is added to any table to control database access to a single piece of user data;
[0044] Among them, key user information includes at least one of the following:
[0045] User ID, email address, ID number, security authentication mobile number, login mobile number, contract account, core customer number, machine code, identity verification system OpenID;
[0046] The user switching status includes not switched, switching, and switched.
[0047] In a possible implementation, a classification module is further included; the classification module is used to:
[0048] The user data table to be migrated is divided into a user table and a parameter table according to whether the user data table to be migrated includes key user information and an application scenario of the user data table to be migrated.
[0049] In a possible implementation, the routing access policy includes a user table access policy and a parameter table access policy;
[0050] The user table access policy is used to control whether the user accesses the original database or the target database. If the master control switch is grayed out and the user ID is switched, or the master control switch is released to the outside, the user is controlled to access the target database; otherwise, the user is controlled to access the original database.
[0051] The parameter table access policy is used to control whether the user accesses the original database or the target database. If the parameter table status is externally released or the grayscale access identifier is the target database, the user is controlled to access the target database; otherwise, the user is controlled to access the original database.
[0052] In a possible implementation, the routing access policy also includes a newly added user access policy;
[0053] The new user access policy is used to determine whether the data of the new user is saved in the target database or the original database by configuring the status of the switch for the registered user in the database system parameter table.
[0054] On the one hand, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the above-mentioned data migration method is implemented when the processor executes the program.
[0055] On the one hand, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the above-mentioned data migration method is implemented.
[0056] The data migration method provided in the embodiment of the present application, through the routing access strategy and the grayscale switching table and the switch strategy, can complete the smooth migration of data by controlling the routing access strategy of the data table at the application layer during the database data migration, and the external service will not be stopped during the migration, thereby reducing the impact of the data migration in the database on customers in production, avoiding the situation where long-term transaction blocking occurs due to the downtime of the application server, and realizing data migration without customer perception; through the grayscale release mechanism of the grayscale switching table and the switch strategy, sufficient internal verification is carried out before external promotion, which greatly reduces the occurrence of production events.
[0057] Additional aspects and advantages of the embodiments of the present application will be partially given in the description below, which will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] The above and / or additional aspects and advantages of the embodiments of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0059] Figure 1 A schematic diagram of a data migration method according to an embodiment of the present application;
[0060] Figure 2 A schematic diagram of the overall process of data migration in an embodiment of the present application;
[0061] Figure 3 A schematic diagram of a user routing strategy process according to an embodiment of the present application;
[0062] Figure 4 A schematic diagram of a process of accessing a user table database according to an embodiment of the present application;
[0063] Figure 5 A flow chart of a parameter table writing operation according to an embodiment of the present application;
[0064] Figure 6 A schematic diagram of the process of adding a new user access policy in an embodiment of the present application;
[0065] Figure 7 A schematic diagram of the transaction layer control flow of an embodiment of the present application;
[0066] Figure 8 This is an example process of the data migration process of the embodiment of the present application;
[0067] Fig. 9 A schematic diagram of the basic structure of a data migration device according to an embodiment of the present application;
[0068] Fig.10 A schematic diagram of the structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0069] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present application.
[0070] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be intermediate elements. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.
[0071] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.
[0072] The following specific embodiments are used to describe in detail the technical solutions of the embodiments of the present application and how the technical solutions of the embodiments of the present application solve the above-mentioned technical problems. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0073] An embodiment of the present application provides a data migration method, which is executed by a computer device, which is a server. The server can be an independent physical server, a physical server cluster, or a virtual server. Figure 1 As shown, the method includes:
[0074] Step S110, determining the user data tables to be migrated from the original database, where the user data tables to be migrated are all or part of the user data tables in the original database; Step S120, migrating the user data tables to be migrated from the original database to the target database based on a pre-set routing access strategy and grayscale switching table and switch strategy, and controlling data access to the user data tables to be migrated in the target database.
[0075] The data migration method provided in the embodiment of the present application, through the routing access strategy and the grayscale switching table and the switch strategy, can complete the smooth migration of data by controlling the routing access strategy of the data table at the application layer during the database data migration, and the external service will not be stopped during the migration, thereby reducing the impact of the data migration in the database on customers in production, avoiding the situation where long-term transaction blocking occurs due to the downtime of the application server, and realizing data migration without customer perception; through the grayscale release mechanism of the grayscale switching table and the switch strategy, sufficient internal verification is carried out before external promotion, which greatly reduces the occurrence of production events.
[0076] The embodiments of the present application, starting from the perspective of customer experience priority, reduce the impact of database migration on customers in production, and avoid long-term transaction blocking caused by application server downtime. At the same time, from the perspective of risk management, if there is a problem in the switching process, there must be a fallback strategy that can respond in time to ensure that production problems are solved as soon as possible. In view of the complexity and security of database migration in banking application systems, an application layer traffic control strategy for distributed database migration without downtime is finally proposed. The following takes the data migration of databases in banking systems as an example to specifically introduce the embodiments of the present application. It should be noted that in this example, the above-mentioned original database is the distributed database DB2, and the above-mentioned target database is the MySQL database.
[0077] Among them, DB2 is a relational database management system, and its main operating environment is UNIX, Linux and Windows servers. DB2 is mainly used in large-scale application systems, with good scalability, and can support from mainframe to single-user environment, and is applied to all common server operating system platforms. DB2 provides high-level data utilization, integrity, security, recoverability, and the execution capability of small-scale to large-scale applications, with basic functions and SQL commands that are independent of the platform. DB2 uses data classification technology, which can make it easy to download mainframe data to the LAN database server, so that client / server users and LAN-based applications can access mainframe data, and make database localization and remote connection transparent. DB2 is known for having a very complete query optimizer, and its external connection improves query performance and supports multi-task parallel query. DB2 has good network support capabilities. Each subsystem can connect to hundreds of thousands of distributed users and can activate thousands of active threads at the same time. It is particularly suitable for large-scale distributed application systems.
[0078] MySQL database service is a fully managed database service. It is an open source relational database management system that uses the most commonly used database management language - Structured Query Language (SQL) for database management.
[0079] During the data migration process, in order to ensure smooth data migration in production and prevent production incidents, this distributed database migration adopts a gray release strategy when it is put into production. The production is divided into three stages: pre-switching, gray release, and formal external release. In the gray release stage, the users to be switched (these users are called whitelist users) are verified. After the verification is passed, the traffic is gradually switched and officially released to the outside world.
[0080] Figure 2 The overall process of data migration based on the grayscale release strategy is given. Figure 2In the figure, ① is the pre-production stage, during which the distributed database only accesses DB2, ②-⑤ is the grayscale release stage, during which the application is transformed and put into production. In this stage, access to MySQL and DB2 coexist, and data migration begins gradually. Among them, for user data tables with a scale of tens of millions, full migration is performed in advance, and then incremental migration is performed daily; for business parameter type tables with a slightly smaller data scale, full migration is performed daily. It should be noted that user migration adopts the strategy of grayscale migration of a small number of users first, then small batch migration, then large batch migration, and finally full user migration to MySQL database. After the migration is completed, the database fully accesses the MySQL database, and after waiting for stable operation, the original DB2 access branch is offline. If a serious production problem occurs, the database access rollback for all data tables, a single data table, and a single user can be achieved by switching the master control switch, table-level switch, and user-level switch.
[0081] When the distributed database is migrated and put into production, the application adopts the grayscale release plan, and after verification, it is switched to formal external release. When grayscale is put into production, the grayscale switch table, user switch table, table switch information table, and transaction code and table correspondence table are configured respectively, that is, the grayscale switch table and switch strategy are adopted, and the grayscale switch table and switch strategy include the grayscale switch table, user switch table, table switch information table, and transaction code and table correspondence table.
[0082] In a possible implementation, the gray switch table is used to control data access and data migration of the entire application; the user switch table stores the identifier of the user to be switched to access the original database and the target database, and is used to control user-level database access; the table switch information table stores the ready state, table type and table access route of the table to be switched, and is used to control database access at the data table level. The ready state includes the unready state and the ready state. The table type includes the user table and the parameter table. The table access route includes the original database and the target database; the transaction code and table correspondence table is used to store table switching or to block the writing of the transaction list during the user switching process. The gray switch table includes a master control switch, a switching switch and a new user access switch; the master control switch is used to control the data access of the entire application, and the master control switch includes the initial state, the gray state and the external release state; the switching switch is used to control the migration of users or data tables from the original database to the target database, and the switching switch includes the unstarted switching state, the switching state and the switching completed state; the new user access switch is used to control whether the new user accesses the original database or the target database.
[0083] In actual applications, (1) the data in the grayscale switch table include: a. master control switch, including initial state, grayscale state, and external release state, which controls the data access of the entire application; b. switching switch, including three states: not started, switching in progress, and switching completed, which controls the migration of users or tables from DB2 to MySQL; c. new user access switch, including two states: new user access to DB2 or MySQL. The grayscale period controls the addition of new users to DB2 or MySQL. (2) User switching table: stores the access to DB2 and MySQL identifiers of the user to be switched, which is used to control user-level database access. (3) Table switching information table: stores the ready identifier (not ready or ready) of the table to be switched, the table type (user table or parameter table), and the table access route (DB2 or MySQL), which is used to control database access at the data table level. By switching the state of the switch, access control of the entire table can be achieved, where DB2 is accessed when not ready and MySQL is accessed when ready; (4) Transaction code and table correspondence table: stores the transaction list that is blocked during table switching or user switching.
[0084] It should be noted that the above four tables are only related to grayscale verification and are only configured in the DB2 database. They will not be migrated to the MySQL database in the future. After the application switch is officially released to the outside world and runs smoothly, it can be directly taken offline.
[0085] In a possible implementation, in order to ensure the real-time effectiveness of grayscale switching or whitelist information changes and the normal operation of applications, and to reduce the frequency of database access during application runtime, the data of these four tables are written to Redis by a scheduled task. When the application reads data, it reads Redis, and when the data is updated, the application writes to Redis in real time. Such updates are not frequent. In other words, the data in the grayscale switch table, user switching table, table switching information table, and transaction code and table correspondence table are all scheduled by a scheduled task into the remote dictionary service Redis, so that the application reads data from Redis and writes the updated data to Redis in real time when the data is updated. Among them, Redis (Remote Dictionary Server), that is, the remote dictionary service, is an open source log-type, Key-Value database written in ANSI C language, supports the network, can be based on memory or persistence, and provides APIs (application programming interfaces) in multiple languages; Redis is a high-performance key-value database.
[0086] In a possible implementation, when any one of the grayscale switch table, user switching table, table switching information table, and transaction code and table correspondence table includes key user information, an attribute representing the user switching status is added to any table to control database access to a single user data; wherein the key user information includes at least one of the following: user number, email address, ID number, security authentication mobile phone number, login mobile phone number, contract account, core customer number, machine code, identity authentication system OpenID; user switching status includes not switched, switching in progress, and switched.
[0087] In other words, in the data table involving key user information (i.e. 11 elements of information, 11 elements of information include user information and user information type, among which user information includes user number, login mobile number, card number, etc.; user information type includes user number, core customer number, certificate number, login mobile number, email, security authentication mobile number, DN, DN_CN, CN number, machine code, OpenID, contract account, etc.), a new attribute of user switching status is added to control database access for a single user data. Among them, there are three states of user switching status: unswitched state (which can be represented by the number 0), switching state (which can be represented by the number 1) and switched state (which can be represented by the number 2). During the grayscale period, the user switching state is used in conjunction with the switch to determine whether the user performs transaction blocking and database access DB2 or MySQL during transactions. Among them, OpenID is a user-centric digital identity recognition framework that is open and decentralized.
[0088] Regarding the routing access strategy of the embodiment of the present application, this migration divides the high-frequency data tables to be migrated into two categories, user tables and parameter tables, according to whether they contain key user information and application scenarios. In the public component, three routing access methods are provided according to different operations of adding, deleting, modifying and checking the two types of data tables, namely user table access strategy, parameter table access strategy and new user access strategy. According to the different application scenarios of adding, deleting, modifying and checking different data tables, different routing methods are called before the DAO layer database access statement method body for adaptive transformation, so as to realize the control of user access to DB2 or MySQL through routing, while reducing the impact on the upper-level business processing components. In addition, for transactions, complex database access, etc., the business components will be transformed and encapsulated.
[0089] 1. User table access strategy
[0090] Add a user access routing method in the public component: whiteChangeRoute (table name, whitelist user information, user information type), where the whitelist user (i.e. user table) information includes user number, login mobile number, card number, etc. User information types include user number, core customer number, ID number, login mobile number, email, security authentication mobile number, DN, DN_CN, CN number, machine code, OpenID, and contracted account. This method controls user access to DB2 or MySQL. When the master control switch is grayed out, the user ID is switched, or the master control switch is released to the outside, MySQL is accessed, and DB2 is accessed in other cases. The process of the routing strategy for whitelist users is as follows: Figure 3 As shown; the access process of the user table database is as follows Figure 4 shown.
[0091] It should be noted that the user table performs unilateral read and write operations during the grayscale period. Before the grayscale starts, the existing user table is fully migrated, and then during the grayscale period, the DB2 incremental data is migrated to MySQL every day.
[0092] 2. Parameter table access strategy
[0093] Add the parameter table access routing method parTable(table name) in the public component. When the parameter table status is external release or the grayscale access identifier is MySQL, MySQL will be accessed, and DB2 will be accessed in other cases.
[0094] For parameter table write operations, the parameter table performs bilateral write operations during the grayscale period, that is, DB2 and MySQL are updated synchronously. DB2 is accessed during the rollback period, and MySQL is accessed during the external release phase. The parameter table is fully migrated every day during the grayscale period. The write operation process of the parameter table is as follows: Figure 5 shown.
[0095] For the parameter table read operation, the user is judged to access MySQL or DB2 according to the result of the whitelist user routing policy. The parameter table read operation process is as follows: Figure 4 shown.
[0096] 3. Add user access policy
[0097] In the public component, a new user information saving routing method isInsertDb2() is added. In it, by configuring the status of the registered user switch in the database system parameter table, it is determined whether the new user data is saved in MySQL or DB2, and the process of adding a new user access policy Figure 6 shown.
[0098] In one possible implementation, an embodiment of the present application also involves a transaction layer control strategy, in which a grayscale switching table is used in conjunction with a switch and routing strategy to perform access control at the transaction layer, so that when switching data tables, users are prevented from accessing transactions corresponding to data table write operations. The access control can be accurate to the table-level dimension and user-level dimension control, that is, the switching of the entire table can be blocked, and the migration of a single user data can be blocked, thereby achieving distributed database migration without downtime.
[0099] For the transaction layer control strategy, before data migration, the master control switch is in fallback state, the switching switch is not started, and the database access is DB2; in the grayscale stage, the master control switch is changed to grayscale; during data migration, the switching switch is switching, and the table switching information table is not ready, the user identification is switching, and the parameter table and user table (i.e. whitelist users) will block transactions at the transaction layer when conducting transactions. At this time, data is not allowed to be written to the database, and only database data migration is performed; when the database migration is completed, the table switching information is ready, the user identification is switched, and the switching switch is changed to switching completed. At this time, the transaction layer no longer blocks writing, and the whitelist user data access route is changed from DB2 to MySQL. In the formal external stage, the master control switch is changed to external release. The entire process can realize distributed database migration without downtime. Only during the data migration process, some transactions are temporarily blocked. After the data migration is completed, services are provided to users normally, which greatly reduces the impact on users and greatly improves the customer experience. Among them, the transaction layer control process is as follows Figure 7 shown.
[0100] In the embodiment of the present application, through the application layer process control strategy, the distributed database migration application transformation and conventional business needs are carried out in parallel, and the strategy of rapid iteration, parallel version tracking and non-business demand control is adopted. Through 20 iterations, the pre-order governance, application commissioning and database switching are completed, and the construction of key projects such as daily business projects is achieved without affecting the construction of key projects. At the same time, the smooth migration of 60 million users and 1.4 billion existing data of the electronic channel is completed. During the migration, external services are not stopped, and customers are not aware of it. At the same time, because of the gray release mechanism of the strategy of sufficient internal verification before external promotion, zero production events are achieved after the official external release. The application layer flow control strategy of distributed database migration without downtime makes this database migration project the first case in the industry where a bank successfully migrates a distributed database without downtime. This strategy has certain guiding value for the distributed database migration of peer systems.
[0101] The embodiments of the present application have the following advantages:
[0102] 1) No downtime, no customer awareness
[0103] A non-stop data migration strategy of grayscale -> small batch -> large batch -> full batch is adopted. During database data migration, data table routing policy control is performed at the application layer to complete smooth data migration. External services are not stopped during the migration, and customers are not aware of it.
[0104] 2) Demand is not controlled and has no impact on business
[0105] Distributed database migration application transformation and regular business demand projects are carried out in parallel, using a strategy of rapid iteration, parallel version tracking, and no control over business needs. Through multiple iterations, pre-process governance, application commissioning, and database switching are completed, achieving no impact on the construction of key projects such as daily business projects.
[0106] 3) Grayscale release to reduce production incidents
[0107] The grayscale release mechanism adopts the strategy of first fully verifying the product internally and then promoting it externally, which can achieve zero incidents in production.
[0108] A practical application example of the embodiment of the present application is given below, specifically:
[0109] In 2019, the software development center of Bank A applied the electronic channel private business processing platform system to improve system performance and reduce the bottleneck of single-point database dependence. It planned to migrate the database from DB2 to MySQL. In order to improve user experience, ensure data reliability and control risks, the electronic channel private business processing platform system used the application layer process control strategy to transform the application and carried out multiple application commissioning and database migration from September to December. The commissioning plan is as follows: Figure 8 shown.
[0110] 1. Description of the production phase
[0111] (1) Rollback phase: Only access to DB2 before November 3, 2019.
[0112] (2) Phase 1: November 3, 2019 to December 1, 2019. Migrate tables to DB2 and MySQL for parallel access.
[0113] (3) Formal external release: After December 1, 2019, the migration table will only access MySQL.
[0114] Among them, the two-way support for DB2 database and MySQL database will last until January 2020.
[0115] 2. Data table access instructions
[0116] (1) User table: Before November 3, 2019, only DB2 was accessed. Whitelist switching and traffic switching began on November 3, 2019. Whitelist switching users and traffic switching users accessed MySQL, and other users accessed DB2. During the gray period, whitelist users who were newly registered registered in MySQL, and other users registered in DB2. All newly registered users began to switch to MySQL.
[0117] (2) Parameter tables: Before November 10, 2019, only DB2 is accessed. Starting from November 10, 2019, parameter tables of the parameter type are written to both DB2 and MySQL, and MySQL is queried. User parameter tables only operate on MySQL. After the two types of parameter tables are officially released to the public, only MySQL is operated.
[0118] 3. Production effect
[0119] Through this, 60 million users and 1.4 billion pieces of stock data of the electronic channel were smoothly migrated. External services were not stopped during the migration period, and customers were not aware of it. At the same time, due to the adoption of a gray release mechanism of sufficient internal verification before external promotion, zero events were produced after the official release to the outside world. The application layer traffic control strategy of non-stop distributed database migration made this database migration project the first case in the industry where a bank successfully migrated a distributed database without downtime. This strategy has certain guiding value for the distributed database migration of peer systems.
[0120] Fig. 9 A structural diagram of a data migration device provided in another embodiment of the present application is shown as follows: Fig. 9 As shown, the device 900 may include: a determination module 901 and a processing module 902, wherein:
[0121] A determination module 901 is used to determine the user data tables to be migrated from the original database, where the user data tables to be migrated are all or part of the user data tables in the original database;
[0122] The processing module 902 is used to migrate the user data table to be migrated from the original database to the target database based on the preset routing access strategy, grayscale switching table and switch strategy, and control data access to the user data table to be migrated in the target database.
[0123] In a possible implementation, the grayscale switching table and the switch strategy include a grayscale switching table, a user switching table, a table switching information table, and a transaction code and table correspondence table; wherein,
[0124] The grayscale switch table is used to control data access and data migration of the entire application;
[0125] The user switching table stores the identifiers of the user to be switched to access the original database and the target database, and is used to control the database access at the user level;
[0126] The table switching information table stores the ready state, table type and table access route of the table to be switched, and is used to control database access at the data table level. The ready state includes the unready state and the ready state. The table type includes the user table and the parameter table. The table access route includes the original database and the target database.
[0127] The transaction code and table correspondence table is used to store table switching or to prevent writing of transaction lists during user switching.
[0128] In a possible implementation, the grayscale switch table includes a master control switch, a switching switch, and a new user access switch;
[0129] The master switch is used to control data access of the entire application. The master switch includes the initial state, grayscale state, and external release state.
[0130] The switch is used to control the migration of users or data tables from the original database to the target database. The switch includes the states of not started switching, switching in progress, and switching completed.
[0131] The new user access switch is used to control whether the new user accesses the original database or the target database.
[0132] In one possible implementation, the data in the grayscale switch table, user switching table, table switching information table, and transaction code and table correspondence table are all set by a scheduled task to the remote dictionary service Redis, so that the application can read data from Redis and write the updated data to Redis in real time when the data is updated.
[0133] In a possible implementation, when any one of the grayscale switch table, the user switch table, the table switch information table, and the transaction code and table correspondence table includes key user information, an attribute representing the user switch state is added to any table to control database access to a single piece of user data;
[0134] Among them, key user information includes at least one of the following:
[0135] User ID, email address, ID number, security authentication mobile number, login mobile number, contract account, core customer number, machine code, identity verification system OpenID;
[0136] The user switching status includes not switched, switching, and switched.
[0137] In a possible implementation, a classification module is further included; the classification module is used to:
[0138] The user data table to be migrated is divided into a user table and a parameter table according to whether the user data table to be migrated includes key user information and an application scenario of the user data table to be migrated.
[0139] In a possible implementation, the routing access policy includes a user table access policy and a parameter table access policy;
[0140] The user table access policy is used to control whether the user accesses the original database or the target database. If the master control switch is grayed out and the user ID is switched, or the master control switch is released to the outside, the user is controlled to access the target database; otherwise, the user is controlled to access the original database.
[0141] The parameter table access policy is used to control whether the user accesses the original database or the target database. If the parameter table status is externally released or the grayscale access identifier is the target database, the user is controlled to access the target database; otherwise, the user is controlled to access the original database.
[0142] In a possible implementation, the routing access policy also includes a newly added user access policy;
[0143] The new user access policy is used to determine whether the data of the new user is saved in the target database or the original database by configuring the status of the switch for the registered user in the database system parameter table.
[0144] The device provided in the embodiment of the present application, through the routing access strategy and the grayscale switching table and the switch strategy, can complete the smooth migration of data by controlling the routing access strategy of the data table at the application layer during the database data migration, and the external service will not be stopped during the migration, thereby reducing the impact of the data migration in the database on customers in production, avoiding the situation where long-term transaction blocking occurs due to the downtime of the application server, and realizing data migration without customer perception; through the grayscale release mechanism of the grayscale switching table and the switch strategy, sufficient internal verification is carried out before external promotion, which greatly reduces the occurrence of production events.
[0145] It should be noted that this embodiment is an apparatus embodiment corresponding to the above-mentioned method embodiment, and this embodiment can be implemented in conjunction with the above-mentioned method embodiment. The relevant technical details mentioned in the above-mentioned method embodiment are still valid in this embodiment, and in order to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in this embodiment can also be applied in the above-mentioned method embodiment.
[0146] Another embodiment of the present application provides an electronic device, such as Fig.10 As shown, Fig.10The electronic device 1000 shown includes: a processor 1001 and a memory 1003. The processor 1001 and the memory 1003 are connected, such as through a bus 1002. Further, the electronic device 1000 may also include a transceiver 1004. It should be noted that in actual applications, the transceiver 1004 is not limited to one, and the structure of the electronic device 1000 does not constitute a limitation on the embodiments of the present application.
[0147] The processor 1001 is used in the embodiment of the present application to implement Fig. 9 The functions of the determination module and the processing module are shown. The transceiver 1004 includes a receiver and a transmitter.
[0148] Processor 1001 may be a CPU, a general-purpose processor, a DSP, an ASIC, an FPGA or other programmable logic device, a transistor logic device, a hardware component or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. Processor 1001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0149] The bus 1002 may include a path to transmit information between the above components. The bus 1002 may be a PCI bus or an EISA bus, etc. The bus 1002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.10 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0150] The memory 1003 may be a ROM or other type of static storage device that can store static information and instructions, a RAM or other type of dynamic storage device that can store information and instructions, or an EEPROM, a CD-ROM or other optical disk storage, an optical disk storage (including a compressed optical disk, a laser disk, an optical disk, a digital versatile disk, a Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to these.
[0151] The memory 1003 is used to store the application code for executing the solution of the present application, and the execution is controlled by the processor 1001. The processor 1001 is used to execute the application code stored in the memory 1003 to implement Fig. 9 The illustrated embodiment provides actions of the data migration device.
[0152] The electronic device provided by the embodiment of the present application includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the following can be achieved: determining a user data table to be migrated from an original database, where the user data table to be migrated is all or part of the user data tables in the original database; then, based on a pre-set routing access strategy and a grayscale switching table and a switch strategy, migrating the user data table to be migrated from the original database to a target database, and controlling data access to the user data table to be migrated in the target database.
[0153] The embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the method shown in the above embodiment is implemented. Among them, through the routing access strategy and the grayscale switching table and the switch strategy, by controlling the routing access strategy of the data table at the application layer during the database data migration, not only can the data be smoothly migrated, but also the external service is not stopped during the migration, reducing the impact of the data migration in the database on the customer in production, avoiding the situation of long-term transaction blocking caused by the downtime of the application server, and realizing data migration without customer perception; through the grayscale release mechanism of the grayscale switching table and the switch strategy, it is fully verified internally before external promotion, which greatly reduces the occurrence of production events.
[0154] The computer-readable storage medium provided in the embodiments of the present application is applicable to any embodiment of the above method.
[0155] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0156] The above is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A data migration method, It is characterized in that include: Determine the user data tables to be migrated from the original database, wherein the user data tables to be migrated are all or part of the user data tables in the original database; Based on a preset routing access strategy, a grayscale switching table, and a switch strategy, the user data table to be migrated is migrated from the original database to the target database, and data access to the user data table to be migrated is controlled in the target database; The grayscale switching table and switch strategy include a grayscale switching table, a user switching table, a table switching information table, and a transaction code and table correspondence table; wherein: The grayscale switch table is used to control data access and data migration of the entire application; The user switching table stores identifiers of the original database and the target database accessed by the user to be switched, and is used to control user-level database access; The table switching information table stores the ready state, table type and table access route of the user table to be switched, and is used to control database access at the data table level. The ready state includes a not ready state and a ready state. The table type includes a user table and a parameter table. The table access route includes an original database and a target database. The transaction code and table correspondence table is used for storing table switching or for blocking the writing of transaction lists during user switching; The grayscale switch table includes a master control switch, a switching switch, and a new user access switch; The master control switch is used to control data access of the entire application, and the master control switch includes an initial state, a gray state, and an external release state; The switch is used to control the migration of users or data tables from the original database to the target database, and the switch includes a switching state not started, a switching state, and a switching completed state; The newly added user access switch is used to control whether the newly added user accesses the original database or the target database.
2. The method according to claim 1, It is characterized in that The data in the grayscale switch table, the user switch table, the table switch information table and the transaction code and table correspondence table are all set by the scheduled task to the remote dictionary service Redis, so that the application reads data from the Redis and writes the updated data to Redis in real time when the data is updated.
3. The method according to claim 1, It is characterized in that When any one of the grayscale switch table, the user switch table, the table switch information table, and the transaction code and table correspondence table includes key user information, an attribute representing the user switch state is added to any one of the tables to control database access to a single piece of user data; The key user information includes at least one of the following: User ID, email address, ID number, security authentication mobile number, login mobile number, contract account, core customer number, machine code, identity verification system OpenID; The user switching status includes not switched, switching and switched.
4. The method according to any one of claims 1 to 3, It is characterized in that Before migrating the user data table to be migrated from the original database to the target database based on the preset routing access strategy, grayscale switching table and switch strategy, the method further includes: The user data table to be migrated is divided into a user table and a parameter table according to whether the user data table to be migrated includes key user information and an application scenario of the user data table to be migrated.
5. The method according to claim 4, It is characterized in that The routing access policy includes a user table access policy, a parameter table access policy and a new user access policy; The user table access policy is used to control whether the user accesses the original database or the target database, wherein if the master control switch is grayed out and the user identifier is switched, or the master control switch is released to the outside, the user is controlled to access the target database, otherwise the user is controlled to access the original database; The parameter table access policy is used to control whether the user accesses the original database or the target database, wherein if the parameter table status is external release or the grayscale access identifier is the target database, the user is controlled to access the target database, otherwise the user is controlled to access the original database; The newly added user access policy is used to determine whether the data of the newly added user is stored in the target database or the original database by configuring the status of the switch of the registered user in the database system parameter table.
6. A data migration device, It is characterized in that include: A determination module, used to determine the user data tables to be migrated from the original database, wherein the user data tables to be migrated are all or part of the user data tables in the original database; A processing module, configured to migrate the user data table to be migrated from the original database to the target database based on a preset routing access strategy, a grayscale switching table and a switch strategy, and to control data access to the user data table to be migrated in the target database; The grayscale switching table and switch strategy include a grayscale switching table, a user switching table, a table switching information table, and a transaction code and table correspondence table; wherein: The grayscale switch table is used to control data access and data migration of the entire application; The user switching table stores identifiers of the original database and the target database accessed by the user to be switched, and is used to control user-level database access; The table switching information table stores the ready state, table type and table access route of the user table to be switched, and is used to control database access at the data table level. The ready state includes a not ready state and a ready state. The table type includes a user table and a parameter table. The table access route includes an original database and a target database. The transaction code and table correspondence table is used for storing table switching or for blocking the writing of transaction lists during user switching; The grayscale switch table includes a master control switch, a switching switch, and a new user access switch; The master control switch is used to control data access of the entire application, and the master control switch includes an initial state, a gray state, and an external release state; The switch is used to control the migration of users or data tables from the original database to the target database, and the switch includes a switching state not started, a switching state, and a switching completed state; The newly added user access switch is used to control whether the newly added user accesses the original database or the target database.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the method according to any one of claims 1 to 5 is implemented.
8. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 5.
