Method, device and electronic device for database migration
By obtaining the distribution strategy of database usage data tags and combination tables, the problem of database migration relying on manual subjective consciousness is solved, automated migration and load balancing are achieved, and migration efficiency and accuracy are improved.
Patent Information
- Application Number
- CN202010232141.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-03-27
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2040-03-27
AI Technical Summary
Database migration in the existing technology mainly relies on manual subjective consciousness and lacks data support, resulting in inaccurate migration in complex and huge data scenarios, consuming a lot of manpower and financial resources, and making it difficult to balance the load and storage pressure of each node in the distributed environment.
By obtaining the usage data of the database, marking the data table, generating a combined table with associated query relationships, and migrating it to each node in the distributed environment according to the predetermined distribution strategy, reducing cross-node query operations, balancing node load and alleviating storage pressure.
It realizes the automation of database migration, improves the accuracy and efficiency of migration, reduces the consumption of human and financial resources, and balances the load and storage pressure of each node in the distributed environment.
Smart Images

Figure CN113448941B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to the field of cloud computing technology, and more particularly to a method and device for database migration. Background Art
[0002] Database is a warehouse that organizes, stores and manages data according to data structure. It was created more than 60 years ago. With the development of information technology and market, especially after the 1990s, data management is no longer just about storing and managing data, but has turned into various data management methods required by users. However, with the explosive growth of data scale, using a single database for data storage management will lead to capacity bottlenecks and performance bottlenecks, which will affect the improvement of application system processing capabilities and thus affect the faster development of business. In order to solve this problem, the database migration method can be used, that is, the massive data storage management is split from one database into multiple database storage management, and different databases are distributed on different machines to form a distributed relational database to reduce the single-machine pressure of TPS (Transaction Processing Systems), I / O (Input / Output) and storage. In general, when enterprises face the need for database sub-library, they are already in the stage of processing system evolution, and most of them have accumulated a large number of SQL (structured query statements) usage logs. The massive SQL logs contain the logical relationship between tens of millions of tables in the business system, which can play an important guiding role in the distributed partitioning of databases.
[0003] Currently, the distributed partitioning scheme for databases mainly relies on manual execution. Specifically, based on a detailed interpretation of the SQL (structured query statement) usage log, a subjective migration scheme is formed according to the individual's own experience and understanding of the business. By analyzing the business logic and the relationship between database tables, the database tables with closer relationships are divided into a distributed environment node according to the analysis results.
[0004] The above method completely relies on human subjective consciousness, lacks data support, and the relationship between database tables is relatively complex. When performing manual migration, it is difficult to accurately analyze the relationship between a large number of database tables, and it is even more difficult to accurately determine the closeness of the relationship, which leads to inaccurate migration plans. It cannot reduce the operation of querying data tables across distributed environment nodes, balance the load of each node in the distributed environment, and balance the storage pressure of each node in the distributed environment. In addition, manual migration of complex and large systems will consume a lot of manpower and financial resources. Summary of the invention
[0005] The purpose of the present disclosure is to provide a database migration method, device, electronic device and computer-readable storage medium to solve the problem faced by centralized databases in large-scale data scenarios that database migration can only be performed through subjective consciousness, lacks data support, and manual database migration of complex and large data consumes a lot of manpower and financial resources.
[0006] According to a first aspect of the present disclosure, a method for database migration is provided, comprising:
[0007] Obtaining usage data of the database;
[0008] marking data tables queried simultaneously in the database according to usage data of the database;
[0009] Combining the data tables with the same mark to generate a combined table with an associated query relationship;
[0010] The combination table is migrated to each node in the distributed environment according to a predetermined allocation strategy.
[0011] According to a second aspect of the present disclosure, a database migration device is provided, including:
[0012] An acquisition module, used for acquiring usage data of the database;
[0013] a marking module, configured to mark data tables queried simultaneously in the database according to the usage data of the database acquired by the acquisition module;
[0014] A generating module, used for combining the data tables with the same mark marked by the marking module to generate a combined table with an associated query relationship;
[0015] The migration module is used to migrate the combination table generated by the generation module to each node in the distributed environment according to a predetermined allocation strategy.
[0016] According to a third aspect of the present disclosure, an electronic device is provided, the electronic device comprising:
[0017] The database migration device according to the second aspect of the present disclosure; or,
[0018] A processor and a memory, the memory is used to store executable instructions, and the instructions are used to control the processor to execute the database migration method according to the first aspect of the present disclosure.
[0019] According to a fourth aspect of an embodiment of the present disclosure, there is provided a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the database migration method according to the first aspect of the present disclosure is implemented.
[0020] According to the disclosed embodiment, a method for database migration is provided, which marks the data tables that are queried simultaneously in the database by acquiring the usage data including the database, and the purpose of marking is to combine the data tables with the same mark to generate a combination table with an associated query relationship, and finally migrate the combination table to each node in the distributed environment according to the predetermined allocation strategy, and the migration of the entire database does not need to rely on manual work, which solves the problem that the centralized database in the large-scale data scenario can only be migrated through subjective consciousness, lacks data support, and consumes a lot of manpower and financial resources for manual migration of complex and large data. And by setting the combination table to realize the query of the data table with an associated relationship on the same node, the operation of querying the data table across nodes is reduced, and at the same time, the combination table is distributed to each node in the distributed environment according to the query number, data capacity or scale of the combination table, which can achieve the effect of balancing the load of each node and alleviating the storage pressure of each node in the distributed environment.
[0021] Other features and advantages of the present disclosure will become apparent from the following detailed description of exemplary embodiments of the present disclosure with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the embodiments of the present disclosure.
[0023] Figure 1 The present invention is a block diagram of a hardware configuration structure of an electronic device that can be used to implement an embodiment of the present disclosure.
[0024] Figure 2 The following is a flowchart of the steps of the database migration method according to an embodiment of the present disclosure.
[0025] Figure 3 The structure block diagram of the database migration device according to the embodiment of the present disclosure.
[0026] Figure 4 A schematic diagram of a combination table allocation strategy according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0027] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that unless otherwise specifically stated, the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the embodiments of the present disclosure.
[0028] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the embodiments of the present disclosure and its application or uses.
[0029] Technologies, methods, and apparatuses known to persons of ordinary skill in the relevant art may not be discussed in detail, but where appropriate, such technologies, methods, and apparatuses should be considered part of the specification.
[0030] In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not limiting. Therefore, other examples of the exemplary embodiments may have different values.
[0031] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0032] <Hardware Configuration>
[0033] Figure 1 1 is a structural block diagram showing a hardware configuration of an electronic device 1000 that can implement an embodiment of the present disclosure.
[0034] In one example, electronic device 1000 may be a computer.
[0035] In another example, the electronic device 1000 may also be a server, etc. The server may be in the form of a blade server, a rack server, etc., or a server cluster deployed in the cloud. In some embodiments, each server may include hardware, software, or an embedded logic component or a combination of two or more such components for executing the appropriate functions supported or implemented by the server.
[0036] like Figure 1 As shown, the electronic device 1000 may include a processor 1100, a memory 1200, an interface device 1300, a communication device 1400, a display device 1500, an input device 1600, a speaker 1700, a microphone 1800, and the like. Among them, the processor 1100 may be a central processing unit CPU, a microprocessor MCU, and the like. The memory 1200 includes, for example, a ROM (read-only memory), a RAM (random access memory), a non-volatile memory such as a hard disk, and the like. The interface device 1300 includes, for example, a USB interface, a headphone interface, and the like. The communication device 1400 is, for example, capable of communicating with or without presence, and may specifically include WiFi communication, Bluetooth communication, 2G / 3G / 4G / 5G communication, and the like. The display device 1500 is, for example, a liquid crystal display screen, a touch display screen, and the like. The input device 1600 may include, for example, a touch screen, a keyboard, a somatosensory input, and the like. The user may input / output voice information through the speaker 1700 and the microphone 1800.
[0037] Figure 1The electronic device shown is merely illustrative and does not in any way imply any limitation on the embodiments of the present disclosure, its application or use. In the embodiment applied to the embodiments of the present disclosure, the memory 1200 of the electronic device 1000 is used to store instructions, and the instructions are used to control the processor 1100 to operate to perform any one of the database migration methods provided in the embodiments of the present disclosure. It should be understood by those skilled in the art that although Figure 1 In the electronic device 1000, multiple devices are shown, but the embodiment of the present disclosure may only involve some of the devices, for example, the electronic device 1000 may only involve the processor 1100 and the storage device 1200. The technicians can design instructions according to the scheme disclosed in the embodiment of the present disclosure. How instructions control the processor to operate is well known in the art, so it will not be described in detail here.
[0038] <Method Example>
[0039] With the explosive growth of data size in the database, data storage pressure has been brought to a single node in the distributed environment. In addition, there are more and more cross-node query operations, which makes the load of each node in the distributed environment unbalanced. In order to solve these problems caused by the database, there is a need to migrate the database.
[0040] In view of the above problems, the database migration in the prior art mainly relies on engineers to form a subjective database migration plan based on their own experience and understanding of the business, which lacks data support, and the manual sub-library of complex and large systems will also consume a lot of manpower and financial resources. The database migration method provided in the embodiment of the present disclosure obtains the usage data of the database, divides the data table in the database into a combination table with an associated query relationship, and then establishes a mapping relationship between the combination table and each node of the distributed environment to migrate the corresponding data table to the corresponding distributed environment node, and the migration of the entire database does not need to rely on manual labor. And by setting up a combined table to realize the query of the data table with an associated relationship on the same node, the operation of querying the data table across nodes is reduced. At the same time, according to the query number, data capacity or scale of the combined table, a mapping relationship between the combined table and each node of the distributed environment is established to migrate the corresponding data table to the corresponding distributed environment node, which can achieve the effect of balancing the load of each node and alleviating the storage pressure of each node in the distributed environment. The specific implementation method is as follows:
[0041] Please refer to Figure 2 , which is a flowchart of the steps of the database migration method according to an embodiment of the present disclosure. The database migration method can be implemented by an electronic device, and the electronic device can be, for example, Figure 1 An electronic device 1000 is shown.
[0042] like Figure 2As shown, the database migration method of the embodiment of the present disclosure includes the following steps:
[0043] In step 201, the usage data of the database is obtained. Specifically, the migration of the database depends on the historical usage data of the database, which is obtained from the log of the database. The log of the database records various types of data of the database during use, and the data required for the database migration is selected to provide data support for the database migration. It should be noted that the historical usage data of the database can be data within a preset time period or all the historical usage data of the database, and the preset time period can be a week, a month or a quarter.
[0044] Optionally, the usage data is a database log, and the log records query data of a data table in the database. After obtaining the usage data of the database, the method may further include:
[0045] The database log is preprocessed to filter out data in the log except the query data of the data table.
[0046] Specifically, the migration of data tables in the database requires the query data of the data tables in the database usage data. The usage data is the database log, which is used to record the query data of the data tables in the database. The association between the data tables is obtained based on the query data, and the data tables are divided based on the association. Therefore, the data in the log that is not related to the query data of the data table can be filtered out to obtain the query data faster. Examples of logs that are not related to query data include: data updated by the database, data debugged by the database, and data reported by the database during use.
[0047] In step 202, the data tables to be queried simultaneously in the database are marked according to the usage data of the database. Specifically, the marking step includes:
[0048] Extracting query statements from the usage data of the database to obtain table names of data tables queried within the same time period;
[0049] The table names of data tables that are queried simultaneously within the same time period are marked with the same identifier.
[0050] The query statement is used to record the specific content of the query request at a certain moment, including the table name of the data table and the name of the database corresponding to the data table. By obtaining the query statement at different moments, the table names of the data tables queried at the same moment in the database and the database names corresponding to the data tables can be screened out, and the table names of the data tables queried at the same moment are marked with the same symbol to classify the data tables, so as to provide data support for the subsequent migration of the database according to the classification of the data tables.
[0051] For example, in a database with two names H1 and H2, H1 has three data tables, the names of which are Table 1, Table 2, and Table 3; H2 has three data tables, the names of which are Table 4, Table 5, and Table 6. When Table 1 in H1 and Table 5 in H2 are queried together at a certain moment, Table 1 in H1 and Table 5 in H2 are marked with the same symbol.
[0052] In step 203, the data tables with the same mark are combined to generate a combination table with an associated query relationship. Specifically, in step 204, the query relationship between each data table and other data tables is obtained. The query relationship is judged by whether there is a mark with the same symbol. When a data table has a mark with the same symbol as other data tables, it means that the data table and other data tables are queried at the same time when querying, that is, the data table has an associated query relationship with other data tables. The data table and other data tables come from different databases. In order to quickly obtain other data tables associated with it when querying the data table later, this operation does not require cross-node operation at the same time. The data table and the data table with an associated query relationship with the data table are combined together, that is, the data tables with the same symbol mark are combined together to generate a combination table. Finally, the combination table is stored on a distributed node, so that the fast associated query of the data table can be realized, which improves the user experience.
[0053] For example, in four databases named H1, H2, H3, and H4, there are three tables in H1, and the names of the data tables are Table 1, Table 2, and Table 3; there are three tables in H2, and the names of the data tables are Table 4, Table 5, and Table 6; there are three tables in H3, and the names of the data tables are Table 7, Table 8, and Table 9; there are three tables in H4, and the names of the data tables are Table 10, Table 11, and Table 12. When Table 1 in H1 and Table 5 in H2 are queried together at a certain moment, Table 1 in H1 and Table 5 in H2 are marked with the same symbol; when Table 2 in H1, Table 9 in H3, and Table 10 in H4 are queried together at a certain moment, Table 2 in H1, Table 9 in H3, and Table 10 in H4 are marked with the same symbol; then Table 1 in H1 and Table 5 in H2 are put together to generate a new combined table A, and Table 2 in H1, Table 9 in H3, and Table 10 in H4 are put together to generate a new combined table B.
[0054] It should be noted that if Table 1 in H1 and Table 5 in H2 appear at the same time at the first moment, Table 1 in H1, Table 5 in H2 and Table 9 in H3 appear at the same time at the second moment, and Table 1 in H1, Table 5 in H2 and Table 10 in H3 appear at the same time at the third moment, Table 1, Table 5, Table 9 and Table 10 can be combined into a combined table according to the maximum set principle.
[0055] In step 204, the combined table is migrated to each node of the distributed environment according to a predetermined allocation strategy. Specifically, multiple combined tables are generated according to the method of step 206. The combined table is a logical division. The data tables contained in the combined table can be data tables stored in different databases, or data tables stored in different storage addresses of the same database at different storage addresses of the same database. In order to complete the database migration in a physical sense, it is necessary to migrate the data tables in the combined table from the original database to a node in the distributed environment so that the data tables with associated relationships have the same storage address, thereby reducing the operation of querying data tables across nodes. At the same time, in order to solve the storage pressure of the nodes in the distributed environment and balance the load of each node, the following allocation strategy is established:
[0056] Obtaining the query times of the combination table according to the usage data of the database;
[0057] Establishing a mapping relationship between the combination table and the distributed environment node according to the query times of the combination table so that the combination tables with a query times greater than or equal to a predetermined number are not allocated to the same distributed environment node;
[0058] The data table in the database is migrated to the corresponding distributed environment node according to the mapping relationship.
[0059] Specifically, this allocation strategy is formulated by establishing a mapping relationship between the number of times the combination table is queried within a predetermined time period and the nodes in the distributed environment. A large number of queries on a combination table indicates that the node storing the combination table has a large load. In order to balance the load of each node, the combination table with a large number of queries should not be allocated to the same distributed environment node. Then, according to this allocation strategy, the data tables in the database are migrated to each node in the distributed environment.
[0060] For example, in an embodiment with 4 combined tables and 2 distributed nodes. The 4 combined tables are denoted as Table A, Table B, Table C, and Table D; and the 2 distributed nodes are denoted as Node 1 and Node 2. According to the usage data statistics of the database, the query times of the combined tables are 12 times for Table A, 11 times for Table B, 10 times for Table C, and 9 times for Table D. In order to allocate combined tables with a predetermined query time of 11 or more to different nodes to balance the load of each node, the following mapping relationship between combined tables and distributed environment nodes can be established: migrate Table A and Table C to Node 1, and migrate Table B and Table D to Node 2; or migrate Table A and Table C to Node 2, and migrate Table B and Table D to Node 1; or migrate Table A and Table D to Node 1, and migrate Table B and Table C to Node 2; or migrate Table A and Table D to Node 2, and migrate Table B and Table C to Node 1. According to the mapping relationship between the above four combined tables and the two distributed nodes, according to the table name of the data table extracted from the usage data of the database and the database name corresponding to the data table, the corresponding data table is searched from the corresponding database for migration.
[0061] Optionally, the step of migrating the combination table to each node in the distributed environment according to a predetermined allocation strategy includes:
[0062] Establishing a mapping relationship between the combined table and the distributed environment node according to the data capacity of the combined table so that the combined tables with a data capacity greater than or equal to a predetermined data capacity are not allocated to the same distributed environment node;
[0063] The data table in the database is migrated to the corresponding distributed environment node according to the mapping relationship.
[0064] Specifically, a mapping relationship is established according to the relationship between the data capacity of the combined table and the storage capacity of each node in the distributed environment to formulate an allocation strategy, so that the combined table that occupies a large storage capacity is not allocated to the nodes in the same distributed environment, thereby alleviating the storage pressure of each node in the distributed environment.
[0065] For example, there are 4 combined tables and 2 distributed nodes. The 4 combined tables are denoted as Table A, Table B, Table C, and Table D; the 2 distributed nodes are denoted as Node 1 and Node 2. The data capacity of Table A, Table B, Table C, and Table D is 12G, 10G, 9G, and 6.5G respectively; the storage capacity of Node 1 and Node 2 is 80G and 50G respectively. In order to allocate combined tables with a predetermined data capacity of 10G or more to different nodes to alleviate the storage pressure of each node in the distributed environment, the following mapping relationship between combined tables and distributed environment nodes is established: migrate Table A and Table C to Node 1, and migrate Table B and Table D to Node 2; or migrate Table A and Table C to Node 2, and migrate Table B and Table D to Node 1; or migrate Table A and Table D to Node 1, and migrate Table B and Table C to Node 2; or migrate Table A and Table D to Node 2, and migrate Table B and Table C to Node 1. According to the mapping relationship between the above four combined tables and the two distributed nodes, according to the table name of the data table extracted from the usage data of the database and the database name corresponding to the data table, the corresponding data table is searched from the corresponding database for migration.
[0066] Optionally, the step of migrating the combination table to each node in the distributed environment according to a predetermined allocation strategy includes:
[0067] Establishing a mapping relationship between the combined table and the distributed environment node according to the scale of the combined table;
[0068] The data table in the database is migrated to the corresponding distributed environment node according to the mapping relationship.
[0069] Specifically, a mapping relationship is established according to the scale of the combined table, that is, the number of combined tables and the number of nodes in the distributed environment to formulate an allocation strategy and achieve average allocation of the combined table. In practical applications, the data capacity of the combined table is not much different, and the storage capacity of the nodes in the distributed environment is relatively large. Allocating the combined table according to the quantity relationship can also achieve the effect of alleviating the storage pressure of each node in the distributed environment.
[0070] For example, there are 4 combined tables and 2 distributed nodes. The 4 combined tables are denoted as Table A, Table B, Table C, and Table D; the 2 distributed nodes are denoted as Node 1 and Node 2. In order to alleviate the storage pressure of each node in the distributed environment, the following mapping relationship between combined tables and distributed environment nodes is established: migrate Table A and Table B to Node 1, and migrate Table C and Table D to Node 2; or migrate Table A and Table C to Node 1, and migrate Table B and Table D to Node 2; or migrate Table A and Table D to Node 1, and migrate Table B and Table C to Node 2; or migrate Table A and Table B to Node 2, and migrate Table C and Table D to Node 1; or migrate Table A and Table C to Node 2, and migrate Table B and Table D to Node 1; or migrate Table A and Table D to Node 2, and migrate Table B and Table C to Node 1. According to the mapping relationship between the above four combined tables and the two distributed nodes, according to the table name of the data table extracted from the usage data of the database and the database name corresponding to the data table, the corresponding data table is searched from the corresponding database for migration.
[0071] Optionally, there are M combination tables, and there are N distributed environment nodes, where M and N are positive integers greater than or equal to 1, and migrating the combination table to each node of the distributed environment according to a predetermined allocation strategy includes:
[0072] Obtaining the query times of the combination table according to the usage data of the database;
[0073] Sort the M combination tables according to the number of queries to obtain serial numbers of the combination tables, where the serial numbers of the combination tables are 0, 1, 2, 3, ..., M-1;
[0074] Allocate the combination tables whose serial numbers are in the range of [2n*N, (2n+1)*N-1] to the distributed nodes with serial numbers m%N in sequence, where the serial numbers of the distributed nodes are 0, 1, 2, 3, ..., N-1;
[0075] The combination tables whose serial numbers are in the range of [(2n+1)*N, (2n+2)*N-1] are sequentially distributed to the distributed nodes whose serial numbers are N-1-m%N, wherein n is a non-negative integer, % is a remainder symbol, and m is the serial number of the combination table;
[0076] Migrating the data table in the database to the corresponding distributed environment node;
[0077] or,
[0078] Sorting the M combination tables according to data capacity to obtain serial numbers of the combination tables, wherein the serial numbers of the combination tables are 0, 1, 2, 3, ..., M-1;
[0079] Allocate the combination tables whose serial numbers are in the range of [2n*N, (2n+1)*N-1] to the distributed nodes with serial numbers m%N in sequence, where the serial numbers of the distributed nodes are 0, 1, 2, 3, ..., N-1;
[0080] The combination tables whose serial numbers are in the range of [(2n+1)*N, (2n+2)*N-1] are sequentially distributed to the distributed nodes whose serial numbers are N-1-m%N, wherein n is a non-negative integer, % is a remainder symbol, and m is the serial number of the combination table;
[0081] Migrating the data table in the database to the corresponding distributed environment node;
[0082] or,
[0083] Sorting the M combination tables according to their sizes to obtain serial numbers of the combination tables, wherein the serial numbers of the combination tables are 0, 1, 2, 3, ..., M-1;
[0084] Allocate the combination tables whose serial numbers are in the range of [2n*N, (2n+1)*N-1] to the distributed nodes with serial numbers m%N in sequence, where the serial numbers of the distributed nodes are 0, 1, 2, 3, ..., N-1;
[0085] The combination tables whose serial numbers are in the range of [(2n+1)*N, (2n+2)*N-1] are sequentially distributed to the distributed nodes whose serial numbers are N-1-m%N, wherein n is a non-negative integer, % is a remainder symbol, and m is the serial number of the combination table;
[0086] Migrate the data table in the database to the corresponding node in the distributed environment.
[0087] Specifically, before migrating the combined table, a mapping relationship between the combined table and each node of the distributed environment must be established. The purpose of establishing the mapping relationship is to balance the load or storage pressure of each distributed environment node. For example, when there are M combined tables and N distributed environment nodes, first, all combined tables are sorted according to the number of queries, data capacity or scale to obtain the sequence number of the combined table, and then N distributed environment nodes are used as a round, for example, the first distributed environment node, the second distributed environment node, ..., the Nth distributed environment node is used as a round, for example, the Nth distributed environment node, the second distributed environment node, ..., the first distributed environment node is used as a round: in the first round, the combined tables are allocated to the corresponding distributed environment nodes in ascending order of the node number, in the second round, the remaining combined tables are allocated to the corresponding distributed environment nodes in descending order of the node number, and in the third round, the remaining combined tables are allocated to the corresponding distributed environment nodes in ascending order of the node number... Alternate allocation is performed until the M combined tables are allocated. By allocating M combined tables to N distributed environment nodes according to the above allocation method, the combined tables can be evenly distributed to each node in the distributed environment, ensuring that there is not a large difference in the storage data capacity of each node in the distributed environment, achieving not only balancing the load of each node but also balancing the data storage pressure of each node, while improving the efficiency of database migration.
[0088] For example, if Figure 4As shown, there are 12 combination tables and 4 distributed nodes. The combination tables are sorted according to the number of queries, data capacity or scale, and the serial numbers of the 12 combination tables are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and 11 respectively; the serial numbers of the distributed nodes are 0, 1, 2, and 3; according to the allocation strategy of distributing the combination tables to the distributed nodes with serial numbers m%N in sequence when the serial numbers of the combination tables are in the range of [2n*N, (2n+1)*N-1], the following mapping relationship is established: the combination tables with serial numbers 0 and 8 are migrated to the node with serial number 0, the combination tables with serial numbers 1 and 9 are migrated to the node with serial number 1, the combination tables with serial numbers 2 and 10 are migrated to the node with serial number 2, and the combination tables with serial numbers 3 and 11 are migrated to the node with serial number 3. According to the allocation strategy of sequentially allocating the combination tables to the distributed nodes with the sequence numbers N-1-m%N when the sequence numbers of the combination tables are within the range of [(2n+1)*N, (2n+2)*N-1], the following mapping relationships are established: the combination table with the sequence number 4 is migrated to the node with the sequence number 3, the combination table with the sequence number 5 is migrated to the node with the sequence number 2, the combination table with the sequence number 6 is migrated to the node with the sequence number 1, and the combination table with the sequence number 7 is migrated to the node with the sequence number 0. According to the mapping relationship between the above 12 combination tables and the 4 distributed nodes, the corresponding data tables are searched from the corresponding databases for migration by using the table names of the data tables extracted from the usage data of the database and the database names corresponding to the data tables.
[0089] In addition to the above-listed allocation strategies, there may be other allocation strategies based on the principle of alleviating storage pressure and balancing the load of each node, which are not limited here.
[0090] Optionally, the database further includes an isolated table, which is a data table for separate query;
[0091] The method further includes: migrating the isolated table to each node in the distributed environment according to a predetermined allocation strategy.
[0092] Specifically, when classifying the data tables in the database according to the association relationship between the data tables, there is also a type of table that does not have an associated query relationship, that is, this type of table appears alone when requesting a query, and does not appear at the same time as other data tables. In the disclosed embodiment, this type of table is called an isolated table. After combining multiple data tables in multiple databases through the above method, multiple combined tables and multiple isolated tables are generated. The isolated tables also need to be migrated according to the predetermined allocation strategy to further balance the load and storage pressure of each distributed node. Among them, the predetermined allocation strategies include the following:
[0093] Establishing a mapping relationship between the isolated table and the distributed environment node according to the query times of the isolated table so that the isolated tables with a query times greater than or equal to a predetermined number are allocated to different distributed environment nodes;
[0094] The data table in the database is migrated to the corresponding distributed environment node according to the mapping relationship.
[0095] Specifically, establishing a mapping relationship between isolated tables and distributed environment nodes according to the number of queries means sorting isolated tables according to the number of queries extracted in the query statement, and not allocating isolated tables with a query number greater than or equal to a predetermined number to the same distributed environment node, so as to balance the load of each distributed node. For example, there are 8 isolated tables: Table A, Table B, Table C, Table D, Table E, Table F, Table G, Table H; 4 distributed environment nodes: Node 1, Node 2, Node 3, Node 4. In the table, the query times of table A is 100 times, the query times of table B is 80 times, the query times of table C is 70 times, the query times of table D is 50 times, the query times of table E is 20 times, the query times of table F is 10 times, the query times of table G is 5 times, and the query times of table H is 3 times; then according to the allocation strategy of not distributing the queries greater than or equal to 50 times to the same distributed environment node, the mapping relationship between the isolated table and each distributed node is established as follows: allocate table A and table E to node 1, allocate table B and table F to node 2, allocate table C and table G to node 3, and allocate table D and table H to node 4; or, allocate table A and table H to node 1, allocate table B and table G to node 2, allocate table C and table F to node 3, and allocate table D and table E to node 4; as long as the allocation strategy of not distributing the queries greater than or equal to 50 times to the same distributed node is met, the combination of isolated tables is not restricted. According to the mapping relationship between the above 8 isolated tables and 4 distributed nodes, the corresponding data table is found from the corresponding database for migration through the table name of the data table extracted from the usage data of the database and the database name corresponding to the data table.
[0096] Optionally, the step of migrating the isolated table to each node in the distributed environment according to a predetermined allocation strategy includes:
[0097] Establishing a mapping relationship between the orphan table and the distributed environment node according to the data capacity of the orphan table so that the orphan table with a data capacity greater than or equal to a predetermined data capacity is allocated to different distributed environment nodes;
[0098] The data table in the database is migrated to the corresponding distributed environment node according to the mapping relationship.
[0099] Specifically, the database is migrated according to the relationship between the data size of the isolated table and the storage capacity of each distributed node, in order to balance the storage pressure of each node. The specific allocation strategy is the same as the allocation strategy of the combined table according to the storage capacity, which will not be repeated here.
[0100] Optionally, the step of migrating the isolated table to each node in the distributed environment according to a predetermined allocation strategy includes:
[0101] Establishing a mapping relationship between the orphan table and the distributed environment node according to the scale of the orphan table;
[0102] The data table in the database is migrated to the corresponding distributed environment node according to the mapping relationship.
[0103] Specifically, migrating the database according to the scale of the isolated table, that is, the relationship between the number of isolated tables and the number of distributed nodes, can also balance the storage pressure of each node. The specific allocation strategy is the same as the allocation strategy of the combined table according to the scale, which will not be repeated here.
[0104] <Device Example>
[0105] In another embodiment of the present disclosure, a database migration device 300 is provided. The database migration device 300 includes:
[0106] An acquisition module 301 , a marking module 302 , a generation module 303 and a migration module 304 .
[0107] The acquisition module 301 is used to acquire usage data of the database;
[0108] The marking module 302 is used to mark the data tables queried simultaneously in the database according to the usage data of the database acquired by the acquisition module 301;
[0109] The generating module 303 is used to combine the data tables with the same mark marked by the marking module 302 to generate a combined table with an associated query relationship;
[0110] The migration module 304 is used to migrate the combination table generated by the generation module 303 to each node in the distributed environment according to a predetermined allocation strategy.
[0111] The device further comprises a preprocessing module 305, and the preprocessing module 305 is used to preprocess the usage data of the database, and the preprocessing comprises: filtering out data other than the query data of the data table in the database.
[0112] <Computer Readable Storage Medium>
[0113] Finally, according to another embodiment of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the database migration method described in any embodiment of the present disclosure is implemented.
[0114] The embodiments of the present disclosure may be systems, methods and / or computer program products. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the embodiments of the present disclosure.
[0115] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.
[0116] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0117] The computer program instructions for performing the operation of the embodiments of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of a computer-readable program instruction, and the electronic circuit may execute a computer-readable program instruction, thereby realizing various aspects of the embodiments of the present disclosure.
[0118] Various aspects of the embodiments of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0119] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0120] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0121] The flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to the multiple embodiments of the embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of an instruction, and the module, a program segment or a part of an instruction contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or the flowchart, and the combination of the boxes in the block diagram and / or the flowchart can be implemented by a dedicated hardware-based system that performs the specified function or action, or can be implemented by a combination of dedicated hardware and computer instructions. It is well known to those skilled in the art that it is equivalent to implement it by hardware, implement it by software, and implement it by a combination of software and hardware.
[0122] The various embodiments of the embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the marketplace, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein. The scope of the embodiments of the present disclosure is defined by the appended claims.
Claims
1. A method for database migration, characterized in that: include: Obtaining usage data of the database; marking data tables queried simultaneously in the database according to usage data of the database; Combining the data tables with the same mark to generate a combined table with an associated query relationship; Migrating the combination table to each node of the distributed environment according to a predetermined allocation strategy; wherein the number of the combination tables is M, the number of the distributed environment nodes is N, M and N are positive integers greater than or equal to 1, and migrating the combination table to each node of the distributed environment according to the predetermined allocation strategy includes: Obtaining the query times of the combination table according to the usage data of the database; Sort the M combination tables according to the number of queries to obtain serial numbers of the combination tables, where the serial numbers of the combination tables are 0, 1, 2, 3, ..., M-1; Allocating the combination tables whose serial numbers are in the range of [2n*N, (2n+1)*N-1] to distributed environment nodes with serial numbers of m%N in sequence, where the serial numbers of the distributed environment nodes are 0, 1, 2, 3, ..., N-1; Allocate the combination tables whose serial numbers are in the range of [(2n+1)*N, (2n+2)*N-1] to the distributed environment nodes with serial numbers N-1-m%N in sequence, where n is a non-negative integer, % is a remainder symbol, and m is the serial number of the combination table; Migrating the data table in the database to the corresponding distributed environment node; or, Sorting the M combination tables according to data capacity to obtain serial numbers of the combination tables, wherein the serial numbers of the combination tables are 0, 1, 2, 3, ..., M-1; Allocating the combination tables whose serial numbers are in the range of [2n*N, (2n+1)*N-1] to distributed environment nodes with serial numbers of m%N in sequence, where the serial numbers of the distributed environment nodes are 0, 1, 2, 3, ..., N-1; Allocate the combination tables whose serial numbers are in the range of [(2n+1)*N, (2n+2)*N-1] to the distributed environment nodes with serial numbers N-1-m%N in sequence, where n is a non-negative integer, % is a remainder symbol, and m is the serial number of the combination table; Migrating the data table in the database to the corresponding distributed environment node; or, Sorting the M combination tables according to their sizes to obtain serial numbers of the combination tables, wherein the serial numbers of the combination tables are 0, 1, 2, 3, ..., M-1; Allocating the combination tables whose serial numbers are in the range of [2n*N, (2n+1)*N-1] to distributed environment nodes with serial numbers of m%N in sequence, where the serial numbers of the distributed environment nodes are 0, 1, 2, 3, ..., N-1; Allocate the combination tables whose serial numbers are in the range of [(2n+1)*N, (2n+2)*N-1] to the distributed environment nodes with serial numbers N-1-m%N in sequence, where n is a non-negative integer, % is a remainder symbol, and m is the serial number of the combination table; Migrate the data table in the database to the corresponding node in the distributed environment.
2. The method according to claim 1, wherein: The step of marking the data tables queried simultaneously in the database according to the usage data of the database comprises: Extracting query statements from the usage data of the database to obtain table names of data tables queried within the same time period; The table names of data tables that are queried simultaneously within the same time period are marked with the same identifier.
3. The method according to claim 1, wherein: The step of migrating the combination table to each node in the distributed environment according to a predetermined allocation strategy includes: Obtaining the query times of the combination table according to the usage data of the database; Establishing a mapping relationship between the combination table and the distributed environment node according to the query times of the combination table so that the combination tables with a query times greater than or equal to a predetermined number are not allocated to the same distributed environment node; The data table in the database is migrated to the corresponding distributed environment node according to the mapping relationship.
4. The method according to claim 1, wherein: The step of migrating the combination table to each node in the distributed environment according to a predetermined allocation strategy includes: Establishing a mapping relationship between the combined table and the distributed environment node according to the data capacity of the combined table so that the combined tables with a data capacity greater than or equal to a predetermined data capacity are not allocated to the same distributed environment node; The data table in the database is migrated to the corresponding distributed environment node according to the mapping relationship.
5. The method according to claim 1, wherein: The step of migrating the combination table to each node in the distributed environment according to a predetermined allocation strategy includes: Establishing a mapping relationship between the combined table and the distributed environment node according to the scale of the combined table; The data table in the database is migrated to the corresponding distributed environment node according to the mapping relationship.
6. The method according to claim 1, wherein: The database also includes an isolated table, which is a data table for separate query; The method further includes: migrating the isolated table to each node in the distributed environment according to a predetermined allocation strategy.
7. The method according to claim 6, wherein: The step of migrating the isolated table to each node in the distributed environment according to a predetermined allocation strategy includes: Establishing a mapping relationship between the isolated table and the distributed environment node according to the query times of the isolated table so that the isolated tables with query times greater than or equal to a predetermined number are not allocated to the same distributed environment node; The data table in the database is migrated to the corresponding distributed environment node according to the mapping relationship.
8. The method according to claim 6, wherein: The step of migrating the isolated table to each node in the distributed environment according to a predetermined allocation strategy includes: Establishing a mapping relationship between the isolated table and the distributed environment node according to the data capacity of the isolated table so that isolated tables with a data capacity greater than or equal to a predetermined data capacity are not allocated to the same distributed environment node; The data table in the database is migrated to the corresponding distributed environment node according to the mapping relationship.
9. The method according to claim 6, wherein: The step of migrating the isolated table to each node in the distributed environment according to a predetermined allocation strategy includes: Establishing a mapping relationship between the orphan table and the distributed environment node according to the scale of the orphan table; The data table in the database is migrated to the corresponding distributed environment node according to the mapping relationship.
10. The method according to claim 1, wherein: The usage data is a database log, and the log records query data of a data table in the database. After obtaining the usage data of the database, the method further includes: The database log is preprocessed to filter out data in the log except the query data of the data table.
11. A device for database migration, characterized in that: include: An acquisition module, used for acquiring the database usage data; a marking module, used for marking the data tables queried simultaneously in the database according to the usage data of the database acquired by the acquisition module; A generating module, used for combining the data tables with the same mark marked by the marking module to generate a combined table with an associated query relationship; A migration module is used to migrate the combination table generated by the generation module to each node in the distributed environment according to a predetermined allocation strategy, wherein: The number of the combination tables is M, the number of the distributed environment nodes is N, M and N are positive integers greater than or equal to 1, and the migration module is used for: Obtaining the query times of the combination table according to the usage data of the database; Sort the M combination tables according to the number of queries to obtain serial numbers of the combination tables, where the serial numbers of the combination tables are 0, 1, 2, 3, ..., M-1; Allocating the combination tables whose serial numbers are in the range of [2n*N, (2n+1)*N-1] to distributed environment nodes with serial numbers of m%N in sequence, where the serial numbers of the distributed environment nodes are 0, 1, 2, 3, ..., N-1; Allocate the combination tables whose serial numbers are in the range of [(2n+1)*N, (2n+2)*N-1] to the distributed environment nodes with serial numbers N-1-m%N in sequence, where n is a non-negative integer, % is a remainder symbol, and m is the serial number of the combination table; Migrating the data table in the database to the corresponding distributed environment node; or, Sorting the M combination tables according to data capacity to obtain serial numbers of the combination tables, wherein the serial numbers of the combination tables are 0, 1, 2, 3, ..., M-1; Allocating the combination tables whose serial numbers are in the range of [2n*N, (2n+1)*N-1] to distributed environment nodes with serial numbers of m%N in sequence, where the serial numbers of the distributed environment nodes are 0, 1, 2, 3, ..., N-1; Allocate the combination tables whose serial numbers are in the range of [(2n+1)*N, (2n+2)*N-1] to the distributed environment nodes with serial numbers N-1-m%N in sequence, where n is a non-negative integer, % is a remainder symbol, and m is the serial number of the combination table; Migrating the data table in the database to the corresponding distributed environment node; or, Sorting the M combination tables according to their sizes to obtain serial numbers of the combination tables, wherein the serial numbers of the combination tables are 0, 1, 2, 3, ..., M-1; Allocating the combination tables whose serial numbers are in the range of [2n*N, (2n+1)*N-1] to distributed environment nodes with serial numbers of m%N in sequence, where the serial numbers of the distributed environment nodes are 0, 1, 2, 3, ..., N-1; Allocate the combination tables whose serial numbers are in the range of [(2n+1)*N, (2n+2)*N-1] to the distributed environment nodes with serial numbers N-1-m%N in sequence, where n is a non-negative integer, % is a remainder symbol, and m is the serial number of the combination table; Migrate the data table in the database to the corresponding node in the distributed environment.
12. An electronic device, characterized in that: include: The device for database migration according to claim 11; or, A processor and a memory, wherein the memory is used to store executable instructions, and the instructions are used to control the processor to execute the database migration method according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the database migration method according to any one of claims 1 to 10 is implemented.
