Data redistribution method, device and system

By directly migrating the node set of the data table in the distributed database, using hash distribution rules and serial distributed transactions, the problem of high complexity of online data redistribution in the existing technology is solved, and efficient data migration and fault tolerance are achieved. sex.

CN112789606BActive Publication Date: 2024-10-11HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201980005457.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-09-11
Publication Date
2024-10-11
Estimated Expiration
2039-09-11

AI Technical Summary

Technical Problem

The existing technology is highly complex in the process of online data redistribution in relational databases and requires the establishment of temporary tables, resulting in high data consistency assurance and resource consumption, which affects user businesses.

Method used

By determining the node set associated with the data table in the distributed database, the data is directly migrated without the need to create a temporary table. Hash distribution rules are used for data distribution, multiple distributed transactions are serially executed for data migration, and invalid migration data is filtered to reduce the cost of data migration. Migration complexity and resource consumption.

Benefits of technology

It reduces the complexity of online data redistribution, improves migration efficiency and database fault tolerance, and reduces resource consumption and user business impact.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112789606B_ABST
    Figure CN112789606B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a data redistribution method, device and system, which are applied to the database field. The method includes: determining a first node set and a second node set respectively associated with a first data table in a distributed database, the first node set including data nodes used to store data in the first data table before the data in the first data table is redistributed, and the second node set including data nodes used to store data in the first data table from the beginning of the data redistribution of the data in the first data table; migrating the data of the first data table from the first node set to the second node set; in the process of migrating the data of the first data table, when a target business request for the first data table is received, determining a third node set for responding to the target business request in the first node set and the second node set; sending the target business request to the data nodes in the third node set. The present application can reduce the complexity of online data redistribution. The present application is used for data storage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of databases, and in particular to a data redistribution method, device and system. Background Art

[0002] Online data redistribution refers to the redistribution of data without interrupting user services. Currently, more and more databases are using this technology.

[0003] In a relational database, data of one or more data tables are maintained in multiple nodes of the database. Usually, a temporary table is created to achieve online data redistribution. For example, for the first data table that needs data redistribution, a temporary table is first created for the table. Then, all the data of the first data table deployed on the node corresponding to the first data table is copied to the node corresponding to the temporary table. After the data is copied, the data of the temporary table and the data of the first data table are exchanged (this process is called data switching). After the exchange is completed, the temporary table and the data of the temporary table are deleted, and the data redistribution is completed.

[0004] In the above data redistribution process, it is necessary to ensure the data consistency of the source table (ie, the first data table) and the temporary table, and it is also necessary to perform a data switching process. Therefore, the complexity of online data redistribution is relatively high. Summary of the invention

[0005] The embodiments of the present application provide a data redistribution method, device and system, which can reduce the complexity of online data redistribution.

[0006] In a first aspect, a data redistribution method is provided, comprising:

[0007] Determine a first node set and a second node set respectively associated with the first data table in the distributed database, the first node set including data nodes used to store data in the first data table before data redistribution of the data in the first data table, and the second node set including data nodes used to store data in the first data table starting from data redistribution of the data in the first data table;

[0008] Migrating data of the first data table from the first node set to the second node set;

[0009] In the process of migrating the data of the first data table, when a target service request for the first data table is received, a third node set for responding to the target service request is determined from the first node set and the second node set;

[0010] The target service request is sent to the data node in the third node set, and the target service request is used for each node in the third node set to perform service processing based on the target service request.

[0011] The data redistribution method provided in the embodiment of the present application can execute the target task without establishing a temporary table, thereby realizing online data redistribution. In this way, there is no need to migrate data between tables, and only data migration within the table is required, thereby reducing the complexity of online data redistribution.

[0012] In a possible implementation, determining a third node set for responding to a target service request in the first node set and the second node set includes: when the target service request is a data adding request, determining the third node set for responding to the data adding request in the second node set.

[0013] Writing new data directly to the redistributed nodes can effectively reduce the complexity of redistribution and improve data migration efficiency.

[0014] For example, determining a third node set in the second node set for responding to the data adding request includes: calculating a hash value based on the key value of the newly added data carried in the data adding request; determining a data node corresponding to the hash value in the second node set, and the determined data node belongs to the third node set.

[0015] Using hash distribution rules to distribute data can achieve load balancing.

[0016] In a possible implementation, determining a third node set for responding to a target service request from the first node set and the second node set includes:

[0017] When the target business request is a data deletion request, a data modification request, or a data query request associated with the first data table, a data node for responding to the target business request is determined in the first node set, and a data node for responding to the target business request is determined in the second node set, and the third node set is composed of the data nodes determined from the first node set and the data nodes determined from the second node set.

[0018] In one possible implementation, migrating data of a first data table from a first node set to a second node set includes: filtering data to be migrated from the data of the first data table stored in the first node set, the data to be migrated being data of the first data table that is not stored in the second node set before migration; and migrating the data to be migrated from the first node set to the second node set.

[0019] In some scenarios, such as capacity expansion scenarios, some data may not need to be migrated, and these data can be called invalid migration data. For example, data whose positions are unchanged in the data nodes before and after the migration and / or data that has been deleted before the migration action, performing migration actions on these data will not only occupy data resources, but also affect the efficiency of the migration. Therefore, invalid migration data can be eliminated through screening operations, and data migration can be performed using the data that actually needs to be migrated as the data to be migrated. That is, the data to be migrated includes the data in the first data table except for the invalid migration data. In this way, partial migration of table data can be achieved, the amount of data to be migrated can be reduced, the occupation of data resources can be reduced, and the migration efficiency can be improved.

[0020] For example, filtering the data to be migrated from the data in the first data table stored in the first node set includes: obtaining a first mapping relationship between the data in the first data table and the data nodes of the first node set; obtaining a second mapping relationship between the data in the first data table and the data nodes of the second node set; for the target data in the first data table, when the data node corresponding to the target data determined based on the first mapping relationship is different from the data node corresponding to the target data determined based on the second mapping relationship, the target data is determined as the data to be migrated in the data nodes corresponding to the target data determined based on the first mapping relationship.

[0021] In a possible implementation, different data of the first data table are migrated from the first node set to the second node set respectively through multiple distributed transactions executed in series.

[0022] Since multiple distributed transactions are executed serially for data migration, although the total time required to migrate the first data table may not be shortened, each distributed transaction consumes less resources and the single migration time is short. Since the data of transactions that have been successfully migrated does not need to be re-migrated, if a migration fails, the cost of re-migrating the data is low, resource consumption is small, and the impact on other user jobs executed simultaneously is reduced.

[0023] In a possible implementation, the migrating different data of the first data table from the first node set to the second node set respectively through multiple distributed transactions executed in series includes:

[0024] When the multiple distributed transactions are executed in series, data to be migrated that meets the migration condition is selected from the unmigrated data of the first data table in the first node set through the currently executed distributed transaction, and the selected data to be migrated is migrated from the first node set to the second node set, and the selected data to be migrated is locked during the migration process;

[0025] Among them, the migration conditions include: the data volume of the data to be migrated through the currently executed distributed transaction migration is less than or equal to the specified data volume threshold, and / or the migration duration of the currently executed distributed transaction migration is less than or equal to the specified duration threshold.

[0026] In a possible implementation, when the multiple distributed transactions are executed serially, selecting data to be migrated that meets a migration condition from unmigrated data of the first data table in the first node set through the currently executed distributed transaction, and migrating the selected data to be migrated from the first node set to the second node set includes:

[0027] Based on the currently executed distributed transaction, n distributed plans are generated for n data nodes respectively, the first node set includes the n data nodes, the n data nodes correspond to the n distributed plans one by one, and n is a positive integer;

[0028] Instruct the n data nodes to respectively execute the n distributed plans to select in parallel the data to be migrated that meets the sub-migration condition from the unmigrated data of the first data table in the n data nodes, and send the selected data to be migrated that meets the sub-migration condition from the n data nodes to the second node set, wherein the sub-migration condition is determined based on the migration condition.

[0029] In a possible implementation, the method further includes: during the process of migrating the data of the first data table, if a rollback trigger event is detected, rolling back the data that has been migrated through the multiple distributed transactions.

[0030] In a possible implementation, the method further includes: during the process of migrating the data of the first data table, if a rollback trigger event is detected, rolling back the data that has been migrated by the currently executed distributed transaction.

[0031] The rollback triggering event may be a data node failure (such as a crash) associated with the first data table, a data transmission error, a network error, or receiving a rollback instruction.

[0032] In the embodiment of the present application, the aforementioned distributed transaction ensures the data consistency and persistence of the migration process. When there are multiple distributed transactions, the overall data migration process for the first data table is split into the migration process through multiple distributed transactions. If a rollback trigger event is detected, it is only necessary to roll back all operations of the currently working distributed transaction. After the migration conditions are met again, a new distributed transaction can be initiated to migrate data. Therefore, the data granularity and amount of rollback data are reduced, the amount of data to be repeatedly migrated is reduced, the overall impact of rollback on the data migration process is reduced, resource waste is avoided, and the fault tolerance of the database is improved.

[0033] In a possible implementation, the method includes: setting a deletion flag for the migrated data in the first data table on the first node set.

[0034] That is, after the migrated data is deleted, it is actually recorded as a historical version on the corresponding data node. When subsequent distributed transactions perform data scanning, the data of the historical version can be skipped (that is, the data marked with deletion is skipped). In this way, it can be ensured that during the data migration process, the user's data query operation on the historical version of the data is effectively executed.

[0035] In a second aspect, a data redistribution device is provided, which may include at least one module, and the at least one module may be used to implement the data redistribution method provided by the first aspect or various possible implementations of the first aspect.

[0036] In a third aspect, the present application provides a computing device, the computing device comprising a processor and a memory. The memory stores computer instructions; the processor executes the computer instructions stored in the memory, so that the computing device performs the method provided by the first aspect or various possible implementations of the first aspect, so that the computing device deploys the data redistribution device provided by the second aspect or various possible implementations of the second aspect.

[0037] In a fourth aspect, the present application provides a computer-readable storage medium, which stores computer instructions, and the computer instructions instruct the computing device to execute the method provided by the above-mentioned first aspect or various possible implementations of the first aspect, or the computer instructions instruct the computing device to deploy the data redistribution device provided by the above-mentioned second aspect or various possible implementations of the second aspect.

[0038] In a fifth aspect, the present application provides a computer program product, the computer program product comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computing device may read the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computing device executes the method provided by the first aspect or various possible implementations of the first aspect, and the computing device deploys the data redistribution apparatus provided by the second aspect or various possible implementations of the second aspect.

[0039] In a sixth aspect, a distributed database system is provided, comprising: a management node and a data node, wherein the management node comprises the data redistribution device described in the second aspect or various possible implementations of the second aspect or the computing device described in the third aspect.

[0040] In a seventh aspect, a chip is provided, which may include a programmable logic circuit and / or program instructions, and when the chip is running, it is used to implement the data redistribution method as described in any one of the first aspects. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 It is a schematic diagram of a data redistribution method provided by the related art;

[0042] Figure 2 It is a schematic diagram of an application scenario involved in a data redistribution method provided in an embodiment of the present application;

[0043] Figure 3 It is a flowchart of a data redistribution method provided in an embodiment of the present application;

[0044] Figure 4 is a schematic diagram of data nodes involved in a data redistribution method provided in an embodiment of the present application;

[0045] Figure 5 It is a flowchart of a method for screening data to be migrated provided in an embodiment of the present application;

[0046] Figure 6 It is a schematic diagram of a mapping relationship provided in an embodiment of the present application;

[0047] Figure 7 It is a schematic diagram of a data migration process provided by an embodiment of the present application;

[0048] Figure 8 It is a schematic diagram of an execution scenario of data migration provided in an embodiment of the present application;

[0049] Fig. 9 This is a user business scenario diagram of data migration provided by an embodiment of the present application;

[0050] Fig.10 is a block diagram of a data redistribution device provided in an embodiment of the present application;

[0051] Fig.11 is a block diagram of a second determination module provided in an embodiment of the present application;

[0052] Fig.12 is a block diagram of a migration module provided in an embodiment of the present application;

[0053] Fig.13 is a block diagram of another data redistribution device provided in an embodiment of the present application;

[0054] Fig.14 is a block diagram of another data redistribution device provided in an embodiment of the present application;

[0055] Fig.15 It is a structural diagram of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0056] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0057] Many distributed databases (DDBs) support data redistribution technology, which can be applied in scenarios such as system expansion, reduction, or data migration. Online data redistribution means completing data redistribution without interrupting user services.

[0058] Distributed databases may include relational databases. Relational databases refer to databases that use a relational model to organize data. They store data in the form of rows and columns. Usually, a row of data is the smallest unit of data reading and writing, also known as a record. In a relational database, a series of rows and columns is called a data table, and a data table can be regarded as a two-dimensional table. The relational model can be simply understood as a two-dimensional table model. A relational database includes one or more data tables and relationship description information between data tables. Each data table includes table data and table information. Table data is data deployed in the data node in the data table, that is, the aforementioned data stored in the form of rows and columns. Table information is information describing the data table, such as information describing the definition and architecture of the data table. The table information of the data table can be stored in each data node where the table data is deployed, or it can be saved by a separate node.

[0059] In a relational database, data is stored in a structured manner. Each field in each data table is defined according to pre-set rules (that is, the structure of the table is pre-defined), and then data is stored according to the structure of the data table. In this way, since the form and content of the data have been defined before being stored in the data table, the reliability and stability of the entire data table are relatively high.

[0060] In a relational database, data from one or more tables is deployed in multiple data nodes of the database. Usually, temporary tables are created to achieve online data redistribution. For example, please refer to Figure 1 For the first data table T1 (which can be called the source table) that needs data redistribution, a temporary table T2 is first created for the table. Then the first data table T1 is mapped to the data node ( Figure 1 Take 3 data nodes: nodes 1 to 3 as an example) for the first data table deployed on all data: data 1 to 9, copy to the corresponding data node of the temporary table ( Figure 1Taking 4 data nodes: nodes 1 to 4 as an example, the method of copying all the data in the data table at one time is called full data migration. After the data copy process is completed, the data of the temporary table T2 and the data of the first data table are exchanged. After the exchange is completed, the data of the temporary table and the data of the first data table are deleted, and the complete process of data redistribution is completed. For example, the relational database can be a greenplum database (Database, DB) or GaussDB. Among them, greenplum DB is referred to as gpdb.

[0061] During the process of copying data from the node where the source table is located to the node where the temporary table is located (also known as data redistribution), if data update operations such as adding, deleting and / or modifying data are performed, the data in the temporary table and the source table may be inconsistent. Therefore, an exclusive lock is added to the source table to temporarily prohibit data updates, and the lock is unlocked after the data switching process is completed.

[0062] For example, in gpdb, in order to avoid data update operations such as adding, deleting, and / or modifying data during the data redistribution process, the table being replicated will be locked, and data addition operations (also known as data insertion operations), data deletion operations, and data modification operations are not allowed on the data in the table. Only data query operations are allowed on the data in the table.

[0063] In GaussDB, assuming that the first data table needs to be redistributed, after the temporary table is established, in order to allow data updates, such as data addition, deletion and / or modification, during the data redistribution process, GaussDB uses a designated file to record updated data after receiving a data update request (such as a data addition request or a data deletion request), so that after completing a full data migration, the updated data during the full data migration process can be found, and incremental data migration is performed based on the updated data. The incremental data migration process refers to checking whether the designated file has updated records (including deleted records, modified records, and inserted records during the full data migration process, etc.), and if there are updated records, the updated data is copied again based on the updated records. Since the update operation may always exist, if there are updated records in the designated file after executing several incremental data migration processes, the first data table should be locked (such as an exclusive lock) for the last time, and data replication should be performed. After the data is copied, the exchange process of the first data table and the temporary table is executed, and finally the lock is released.

[0064] In the above data redistribution process, the data consistency of the source table and the temporary table needs to be guaranteed, and the data switching process needs to be performed. Therefore, the complexity of online data redistribution is relatively high. In addition, the full migration of the data table takes a long time and consumes a lot of resources (including the central processing unit (CPU), memory, input / output (IO) resources, etc.), and other user jobs executed at the same time may be affected due to insufficient resources.

[0065] Please refer to Figure 2 , Figure 2 It is a schematic diagram of the application environment of a distributed database system (DDBS) involved in a data redistribution method provided in an embodiment of the present application. The DDBS can be a server or a server cluster composed of multiple servers, and the DDBS includes a distributed database management system (DDBMS) and a DDB. In a distributed database system, an application can transparently operate the DDB through the DDBS, and the data in the DDB is stored in different local databases, managed by one or more DDBMS, run on different machines, supported by different operating systems, and connected by different communication networks. Among them, DDBS10 includes: a management node (also called a database engine, a coordination data node, coordinator) 101 and a data node 102. The DDBMS can be deployed on the management node 101, and the DDB can be deployed on multiple data nodes (datanode) 102. The distributed database can be established based on a share-nothing architecture, that is, all the data of the database are distributed on the data nodes, and the data between the data nodes is not shared.

[0066] The management node 101 is used to manage the corresponding data node 102 and implement the operation of the application 20 on the data node 102, such as executing a data adding operation, a data deleting operation, a data modifying operation or a data query operation.

[0067] In an embodiment of the present application, the management node 101 can be a single node, or a designated data node or an elected data node among multiple data nodes 102, which can be a server or a server cluster composed of multiple servers. Each data node represents a set minimum processing unit of the DDBS. For example, each data node can be an application instance or a database execution process for managing and / or storing data. The DDBS can be deployed on a server or a server cluster composed of multiple servers. A distributed database can have multiple data tables, and the data records of each data table are distributed to each data node according to a user-defined distribution rule, and the data distribution rule is usually a hash distribution, i.e., a key-value distribution.

[0068] To facilitate the reader's understanding, the embodiment of the present application briefly introduces the principle of hash distribution. Hash distribution is a data distribution method based on a hash function, which can also be called a hash function. A hash function is a function that obtains a value (also called a hash value) based on the key (key, also known as a key value, also known as a distribution key value in a distributed system) of the data. That is, value = f (key), and function f is the hash function. Taking Table 1 as an example, assuming that the hash function is f (key) = key mod5, "mod" means modulus, that is, the hash function is a module operation function. Assuming that the keys are 1, 2, 3, 4, 5, 6, 7, 8 and 9 respectively, the corresponding values ​​are 1, 2, 3, 4, 0, 1, 2, 3 and 4 respectively.

[0069] Table 1

[0070] key 1 2 3 4 5 6 7 8 9 value 1 2 3 4 0 1 2 3 4

[0071] As can be seen from the above, when the key is 1 and 6, the value is 1. Therefore, when using a hash function to determine the value, there may be different keys corresponding to the same value. This situation is called a hash conflict. The hash bucket algorithm is a special hash algorithm that can resolve hash conflicts. A hash bucket is a container for placing different key lists (also called hash tables). The hash bucket is also called an f(key) set, or a value set. The values ​​corresponding to the same hash bucket are the same. Referring to the previous example, the number of hash buckets can be set to the value of the modulus (also called modulus), that is, 5. Multiple value values ​​correspond to multiple hash buckets one by one. For example, the value value can be used as the index or number of the hash bucket. Each hash bucket stores keys with the same value. The conflicting keys in the same hash bucket are stored in a one-way linked list, which solves the hash conflict. When searching for data corresponding to a key, you only need to use the key to index the hash bucket corresponding to the value, and then start searching from the node corresponding to the first address of the hash bucket, that is, search in the order of the linked list, compare the key value, until the corresponding key is found, and then index the corresponding data based on the found key. As shown in Table 1, when the key is 1 and 6, it is stored in hash bucket 1, when the key is 2 and 7, it is stored in hash bucket 2; when the key is 3 and 8, it is stored in hash bucket 3; when the key is 4 and 9, it is stored in hash bucket 4; when the key is 5, it is stored in hash bucket 0.

[0072] It should be noted that the aforementioned embodiment only uses the hash function as a modulus function as an example for explanation. In fact, the hash function can also be a remainder function (in this case, the hash function is a complementation function, and the number of hash buckets is the value of the modulus), or other functions. The embodiments of the present application do not limit this.

[0073] The present invention provides a data redistribution method which can be applied to Figure 2 The distributed database in the application environment shown can simplify the complexity of online data redistribution, and all or part of the method can be executed by the aforementioned management node. Figure 3 As shown, in the embodiment of the present application, it is assumed that the first data table is a data table to be migrated, that is, a data table to be redistributed. The method includes:

[0074] Step 301: A management node determines a first node set and a second node set respectively associated with a first data table in a distributed database.

[0075] The operation and maintenance personnel of the distributed database will adjust the data nodes according to the load of the database and other information. When the distributed database adds new data nodes (capacity expansion scenario) or needs to delete some data nodes (capacity reduction scenario) or needs to adjust the storage data of some data nodes (data migration scenario), or needs to adjust the data tables between groups of data nodes (inter-group data table adjustment scenario), the operation and maintenance personnel can input data redistribution instructions to the management node. The management node receives the data redistribution instructions and controls the data nodes to redistribute data based on the data redistribution instructions. The data redistribution instructions are structured query languages ​​(SQL) used to instruct data redistribution, which include one or more SQL statements. Among them, in the inter-group data table adjustment scenario, the data nodes in the distributed database are divided into different data node groups, each data node group contains the same or different number of data nodes. When the user wants to migrate the table created on a data node group to other data node groups, the table data needs to be redistributed on the new data node group, thereby generating this scenario.

[0076] In different data redistribution scenarios, the content of data redistribution is different. For example, in the expansion scenario, the data nodes after redistribution will include all the data nodes before redistribution, and the data redistribution instruction is an expansion instruction, which is used to indicate the data table involved in the expansion operation (the first data table in this embodiment), and is also used to indicate the data nodes added by the expansion operation; in the reduction scenario, the data nodes before redistribution will include all the data nodes after redistribution, and the data redistribution instruction is a reduction instruction, which is used to indicate the data table involved in the reduction operation (the first data table in this embodiment), and is also used to indicate the data nodes reduced by the reduction operation; in the data migration scenario, there may or may not be data node overlap between the data nodes after redistribution and the data nodes before redistribution; the data redistribution instruction is a data migration instruction, which is used to indicate the data table involved in the data migration operation (the first data table in this embodiment), and is also used to indicate the target data node migrated by the data migration operation. In the inter-group data table adjustment scenario, there is usually no data node overlap between the data nodes after redistribution and the data nodes before redistribution; the data redistribution instruction is a data migration instruction, which is used to indicate the data table involved in the data migration operation (the first data table in this embodiment), and is also used to indicate the target data node group to which the data migration operation is to be migrated.

[0077] It is worth noting that data redistribution may also have other scenarios, and the embodiments of the present application are only schematic illustrations and are not limited to this. After the data redistribution instruction triggers the data redistribution process, in order to effectively identify whether the first data table is currently in the data redistribution process, the management node may add a redistribution flag to the first data table, and the redistribution flag is used to identify that the first data table is in the data redistribution process. Subsequently, after receiving the user's business request, the management node can perform the corresponding action by querying whether the data table involved in the business request has been added with a redistribution flag.

[0078] The management node can obtain the first node set and the second node set based on the data redistribution instruction (i.e., parsing the SQL statement in the data redistribution instruction). The first node set includes data nodes used to store data in the first data table before the data in the first data table is redistributed, that is, the first node set is the set of data nodes deployed for the data in the first data table currently (i.e., when step 301 is executed and before step 302); the second node set includes data nodes used to store data in the first data table from the time the data in the first data table is redistributed, that is, the second node set is the set of data nodes deployed for the data in the first data table after subsequent data migration (i.e., after step 302). In an embodiment of the present application, the first node set and the second node set both include one or more data nodes.

[0079] There are many ways to obtain the first node set. In one optional way, the data nodes where the data in the current first data table is deployed can be directly queried to obtain the first node set. In another optional way, the distributed database can maintain a mapping relationship between the data of each current data table and the data nodes of the node set it deploys, and each mapping relationship can be updated in real time based on the deployment location of the data in the corresponding data table, so that the first node set corresponding to the first data table can be obtained by querying the mapping relationship; for example, the mapping relationship between the data in the first data table and the data nodes of the first node set is called the first mapping relationship, and the first node set can be determined by querying the first mapping relationship. In yet another optional way, the data redistribution instruction can carry the identifier of the first node set, and the first node set is obtained based on the identifier.

[0080] There are also multiple ways to obtain the second node set. The second node set can be directly obtained through a data redistribution instruction; for example, in a capacity expansion scenario, the first node set and the data nodes added by the capacity expansion operation are determined as the data nodes included in the second node set. Figure 2 As shown, Figure 2Taking the expansion scenario as an example, the first node set has a total of 4 data nodes, and the second node set has a total of 6 data nodes; in the reduction scenario, the data nodes in the first node set except the data nodes reduced by the reduction operation are determined as the second node set; in the data migration scenario, the target data nodes migrated by the data migration operation are determined as the second node set; in the inter-group data table adjustment scenario, the target data node group migrated by the data migration operation is determined as the second node set.

[0081] It is worth noting that the first node set and the second node set may be determined in other ways, and the embodiments of the present application are only illustrative and not limiting.

[0082] like Figure 4 As shown, Figure 4 Assuming that the first node set includes data nodes N1 to N6, and the second node set includes data nodes N2 to N5, and N7 to N9, the data nodes involved in this data redistribution include data nodes N1 to N9.

[0083] Before the data migration process of the first data table in step 302, the data nodes involved in the data redistribution can be uniformly numbered and sorted in advance, and the first mapping relationship between the data of the first data table and the data nodes of the first node set, and the second mapping relationship between the data of the first data table and the data nodes of the second node set are determined by using the hash distribution rule. The first mapping relationship and the second node mapping relationship can be determined based on the principle of minimum movement quantity (also called the data minimum movement principle). If the distributed system pre-stores the first mapping relationship between the data of the first data table and the data nodes of the first node set, the mapping relationship can be directly obtained without re-calculating the hash. By obtaining the first mapping relationship and the second mapping relationship, the mapping relationship of the table data distribution can be organized. This makes it easy to find the direction of data movement in the subsequent data migration process. At the same time, it is also convenient to prepare for generating a distributed plan (also called a distributed execution plan) during the process of migrating the data of the first data table.

[0084] In short, the aforementioned process of determining the first node set and the second node set is the process of determining which data nodes are involved before and after data redistribution, and the process of determining the mapping relationship is the process of determining on which data node each data is specifically distributed before and after data redistribution.

[0085] Step 302: The management node migrates the data of the first data table from the first node set to the second node set.

[0086] In the embodiment of the present application, the principle of the migration action is similar to data shearing, which refers to the action of moving a piece of data from one node to another node. The process of migrating the data of the first data table from the first node set to the second node set is the process of moving the data of the first data table from the first node set to the second node set. Optionally, the data moved from the first node set is no longer stored in the first node set.

[0087] The data migration process of the first data table, that is, the data redistribution process, can be implemented in a variety of ways. In the embodiments of the present application, the following optional implementations are used as examples for illustration, but are not limited to these:

[0088] The first optional implementation method is to migrate all the data in the first data table directly from the first node set to the second node set. That is, all the data in the first data table is used as the data to be migrated. Such a migration process is a full migration process.

[0089] A second optional implementation manner is to filter the data to be migrated from the data in the first data table stored in the first node set, where the data to be migrated is the data in the first data table that is not stored in the second node set before migration; and migrate the data to be migrated from the first node set to the second node set.

[0090] In some scenarios, such as capacity expansion scenarios, some data may not need to be migrated, and these data can be called invalid migration data. For example, data whose positions are unchanged in the data nodes before and after the migration and / or data that has been deleted before the migration action, performing migration actions on these data will not only occupy data resources, but also affect the efficiency of the migration. Therefore, invalid migration data can be eliminated through screening operations, and the data that actually needs to be migrated can be used as the data to be migrated. That is, the data to be migrated includes the data in the first data table except for the invalid migration data. In this way, partial migration of table data can be achieved, the amount of data to be migrated can be reduced, the occupation of data resources can be reduced, and the migration efficiency can be improved.

[0091] It is worth noting that only when the same data nodes exist in the first node set and the second node set (that is, there is an intersection between the data nodes of the first node set and the second node set) may there be a situation where the data deployed in the data node before and after the migration remains unchanged. If the data nodes in the first node set and the second node set are completely different (this may happen in the data migration scenario), there will usually not be a situation where the data deployed in the data node before and after the migration remains unchanged; in this case, the data of the first data table deployed by the data nodes in the first node set needs to be migrated to the data nodes in the second node set, that is, the data to be migrated is all the data of the first data table deployed by the data nodes in the first node set. Therefore, in an embodiment of the present application, before filtering the data to be migrated in the data of the first data table stored in the first node set, it is also possible to detect whether the same data nodes exist in the first node set and the second node set; when the same data nodes exist in the first node set and the second node set, the data to be migrated is filtered in the data of the first data table stored in the first node set; when the same data nodes do not exist in the first node set and the second node set, the filtering action is not performed. Since the amount of computation required for the screening process of the data to be migrated is greater than that of the aforementioned detection process, this can avoid additional screening of the data to be migrated, thereby reducing computational complexity and improving the efficiency of data migration.

[0092] For example, Figure 5 As shown, the process of screening the data to be migrated from the data of the first data table stored in the first node set may include:

[0093] Step 3021: The management node obtains a first mapping relationship between data in a first data table and data nodes of a first node set.

[0094] In a distributed database, the distribution of data follows the load balancing principle. Referring to the above introduction, in order to ensure the uniform distribution of data and achieve load balancing, the hash distribution rule is usually adopted to distribute data on each data node. Furthermore, in order to avoid hash conflicts, data can also be distributed by introducing a hash bucket algorithm. In a distributed database that introduces a hash bucket algorithm, data is usually distributed on each data node in units of hash buckets to achieve load balancing. Usually, a data node can deploy data corresponding to one or more hash buckets.

[0095] When the hash distribution rule is used for data distribution, the first mapping relationship can be represented by a mapping relationship between a hash value and an identifier of a data node in the first node set. Furthermore, in a distributed database that uses a hash bucket algorithm, since in the hash bucket algorithm, the hash value corresponds one-to-one to the hash bucket identifier, the first mapping relationship can also be represented by a mapping relationship between the hash bucket identifier and the identifier of the data node in the first node set. Among them, the identifier of the data node can be composed of one or more characters (such as numbers) to identify the data node; the identifier of the data node can be a data node name (such as N1 or N2) or a data node number. The hash bucket identifier can be composed of one or more characters (such as numbers) to identify the hash bucket; the hash bucket identifier can be the numerical value of the calculated hash value, or it can be a hash bucket number, such as 1 or 2.

[0096] The first mapping relationship can be calculated in real time. If the distributed database has the first mapping relationship pre-recorded, the pre-recorded first mapping relationship can also be directly obtained. The first mapping relationship can be represented in the form of a relationship graph, a relationship table or a relationship index. For example, the first mapping relationship can be as follows: Figure 6 In the relationship diagram shown in FIG. 1 , it is assumed that the first mapping relationship can be represented by a mapping relationship between a hash bucket number and a name of a data node in the first node set. Figure 6 As shown, based on the first mapping relationship, it can be known that the data with hash bucket numbers 1 to 6 correspond to the data nodes with data node names N1 to N6 respectively, the data with hash bucket numbers 7 to 12 correspond to the data nodes with data node names N1 to N6 respectively, and the data with hash bucket numbers 13 to 17 correspond to the data nodes with data node names N1 to N5 respectively. It can be seen that in the first mapping relationship, data node N1 corresponds to hash buckets with hash bucket numbers 1, 7 and 13; data node N2 corresponds to hash buckets with hash bucket numbers 2, 8 and 14; data node N3 corresponds to hash buckets with hash bucket numbers 3, 9 and 15; data node N4 corresponds to hash buckets with hash bucket numbers 4, 10 and 16; data node N5 corresponds to hash buckets with hash bucket numbers 5, 11 and 17; data node N6 corresponds to hash buckets with hash bucket numbers 6 and 12. Figure 6 In the first mapping relationship shown, the name of the data node and the hash bucket number are in a one-to-many relationship.

[0097] Step 3022: The management node obtains a second mapping relationship between the data in the first data table and the data nodes of the second node set.

[0098] Similar to the first mapping relationship, the second mapping relationship can be represented in a variety of ways and forms. When the hash distribution rule is used for data distribution, the second mapping relationship can be represented by a mapping relationship between a hash value and an identifier of a data node in the second node set. Further, in a distributed database to which a hash bucket algorithm is applied, the second mapping relationship can be represented by a mapping relationship between a hash bucket identifier and an identifier of a data node in the second node set. Among them, the identifier of the data node can be composed of one or more characters (such as numbers) for identifying the data node; the identifier of the data node can be a data node name (such as N1 or N2) or a data node number. The hash bucket identifier can be composed of one or more characters (such as numbers) for identifying the hash bucket; the hash bucket identifier can be the value of the calculated hash value, or it can be a hash bucket number, such as 1 or 2. The second mapping relationship can be calculated in real time, for example, based on the first mapping relationship and the principle of the minimum number of moves. If the distributed database pre-records the second mapping relationship, the pre-recorded second mapping relationship can also be directly obtained. The second mapping relationship can be represented in the form of a relationship graph, a relationship table, or a relationship index.

[0099] For example, the second mapping relationship may be as follows: Figure 6 As shown in the relationship diagram, in the relationship diagram, assuming that the second mapping relationship can be represented by a mapping relationship between a hash bucket number and a name of a data node in the second node set, then Figure 6 As shown, based on the second mapping relationship, the data with hash bucket numbers 1 to 6 correspond to the data nodes with data node names N7, N2, N3, N4, N5 and N8 respectively, the data with hash bucket numbers 7 to 12 correspond to the data nodes with data node names N9, N2, N3, N4, N7 and N8 respectively, and the data with hash bucket numbers 13 to 17 correspond to the data nodes with data node names N9, N2, N3, N7 and N5 respectively. It can be seen that in the second mapping relationship, data node N2 corresponds to hash buckets with hash bucket numbers 2, 8 and 14; data node N3 corresponds to hash buckets with hash bucket numbers 3, 9 and 15; data node N4 corresponds to hash buckets with hash bucket numbers 4 and 10; data node N5 corresponds to hash buckets with hash bucket numbers 5 and 17; data node N7 corresponds to hash buckets with hash bucket numbers 1, 11 and 16; data node N8 corresponds to hash buckets with hash bucket numbers 6 and 12; data node N9 corresponds to hash buckets with hash bucket numbers 7 and 13. Figure 6 In the second mapping relationship shown, the name of the data node and the hash bucket number are in a one-to-many relationship.

[0100] It is worth noting that the first mapping relationship and the second mapping relationship may be represented by the same relationship graph, relationship table or relationship index, or may be represented by their own relationship graphs, relationship tables or relationship indexes. Figure 6The first mapping relationship and the second mapping relationship may be represented by the same relationship graph as an example for illustration, but this is not a limitation.

[0101] Step 3023: The management node screens the data to be migrated from the data in the first data table stored in the first node set based on the first mapping relationship and the second mapping relationship.

[0102] Referring to the foregoing content, it can be known that the data to be migrated is the data whose deployment location in the data node has changed before and after migration (i.e., data redistribution), i.e., effective migration data. The data to be migrated is the data of the first data table that was not stored in the second node set before migration.

[0103] In an optional example, each data in the first data table may be traversed, and the data to be migrated may be screened from the data in the first data table stored in the first node set by comparing the first mapping relationship and the second mapping relationship. Specifically, for target data in the first data table, when the data node corresponding to the target data determined based on the first mapping relationship is different from the data node corresponding to the target data determined based on the second mapping relationship, the target data is determined as the data to be migrated in the data node corresponding to the target data determined based on the first mapping relationship.

[0104] by Figure 6 For example, assuming that the hash value is the same as the hash bucket number, for the target data X in the first data table, calculate its hash value, assuming that the calculated hash value is 1, then the hash value of the target data X is stored in hash bucket 1, and the target data X is the data with hash bucket number 1. Based on the first mapping relationship, it can be known that the data node corresponding to the target data X is N1; based on the second mapping relationship, it can be known that the data node corresponding to the target data X is N7. It can be seen that the data nodes of the target data X are different before and after data migration, so the target data X in the data node N1 is determined to be the data to be migrated.

[0105] In another optional example, by comparing the first mapping relationship and the second mapping relationship, the different data nodes stored in the two mapping relationships are used as data to be migrated. Specifically, the comparison process includes: for each data node in the first node set, query the first mapping relationship to obtain the first data set corresponding to the data node; query the second mapping relationship to obtain the second data set corresponding to the data node; use the data in the first data set that is different from the data in the second data set as the data to be migrated corresponding to the data node. The acquired data to be migrated corresponding to each data node in the first node set constitute the final data to be migrated. It is worth noting that for a certain data node in the first node set, the data node may not exist in the second node set. If the certain data node does not exist in the second node set, the second data set corresponding to the certain data node is empty.

[0106] by Figure 6 For example, for data node N1 in the first node set, query the first mapping relationship, obtain the first data set corresponding to the data node, including data with hash bucket numbers 1, 7, and 13; query the second mapping relationship, obtain the second data set corresponding to the data node N1 is empty; then the data to be migrated corresponding to data node N1 is the data with hash bucket numbers 1, 7, and 13. For data node N2 in the first node set, query the first mapping relationship, obtain the first data set corresponding to the data node is the data with hash bucket numbers 2, 8, and 14; query the second mapping relationship, obtain the second data set corresponding to the data node includes data with hash bucket numbers 2, 8, and 14; then the data to be migrated corresponding to data node N2 is empty. The method for obtaining the data to be migrated for other data nodes is similar, and will not be repeated in the embodiments of the present application. The data to be migrated corresponding to the final first node set includes data with hash bucket numbers 1, 11 and 16 (subsequently migrated from data nodes N1, N5 and N4 to data node N7 respectively), data with hash bucket numbers 6 and 12 (subsequently migrated from data node N6 to data node N8), and data with hash bucket numbers 7 and 13 (subsequently migrated from data node N1 to data node N9).

[0107] In the traditional data redistribution process, when data is migrated from the source table to the temporary table, an exclusive lock is added to the source table to temporarily prohibit data updates. In gpdb, due to the use of full data migration, the source table needs to be locked during the entire migration process. If the amount of data to be migrated is large, such as tens of gigabytes (G) or terabytes (T), it will cause user business congestion for tens of minutes or even hours. In GaussDB, the overall migration process is divided into full migration and multiple incremental migrations. If the amount of data to be migrated is large, such as tens of G or terabytes, it will cause user business congestion for tens of minutes.

[0108] In the embodiment of the present application, although full data migration is still adopted, in scenarios such as expansion or reduction, the screening process of the data to be migrated in the aforementioned step 3023 can reduce the migration of a large amount of invalid migration data, thereby reducing the service blocking time and improving the migration efficiency.

[0109] In an optional embodiment, the aforementioned process of migrating the data of the first data table from the first node set to the second node set may be executed through one or more distributed transactions.

[0110] Transactions in a distributed database can all be referred to as distributed transactions. The distributed transactions in the embodiments of the present application involve a management node and multiple data nodes. Distributed transactions generally include three stages: a transaction start stage, a transaction execution stage, and a transaction commit stage. Among them, in the process of executing the distributed transaction, at the transaction start stage, the management node needs to prepare certain statements for the subsequent transaction execution stage; in the transaction execution stage, the management node executes one or more actions involved in the distributed transaction, and the multiple actions can be executed in parallel. In the embodiments of the present application, the actions included in the distributed transaction can be scanning actions or migration actions. Among them, the migration action can involve one or more SQL statements, and the actions included in the distributed transaction can also be generating a distributed plan and sending a distributed plan; in the transaction commit stage, the 2-Phase Commit (2PC) protocol or the 3-Phase Commit (3PC) protocol is followed to maintain the consistency of the execution of the transaction in the management node and the multiple data nodes.

[0111] In another optional embodiment, the aforementioned process of migrating the data of the first data table from the first node set to the second node set can be implemented by multiple distributed transactions executed in series. In the embodiment of the present application, the management node can execute the multiple distributed transactions in series to control the data nodes in the first node set and the second node set to implement data migration.

[0112] Specifically, when executing the multiple distributed transactions in series, the management node selects the data to be migrated that meets the migration condition from the unmigrated data of the first data table in the first node set through the currently executed distributed transaction (the determination method of the data to be migrated can refer to the aforementioned steps 3021 to 3023), and migrates the selected data to be migrated from the first node set to the second node set. The selected data to be migrated is locked during the migration process, and is usually unlocked when the distributed transaction for migrating the data to be migrated is successfully submitted.

[0113] The migration condition includes: the amount of data to be migrated through the currently executed distributed transaction migration is less than or equal to a specified data amount threshold, and / or the migration duration of the currently executed distributed transaction migration is less than or equal to a specified duration threshold.

[0114] The amount of data to be migrated can be represented by the number of records. A record is a row of data in a data table, which is the smallest unit of data migration. Accordingly, the specified data amount threshold can be represented by the specified number threshold.

[0115] The aforementioned data volume threshold and designated duration threshold may be fixed values, or dynamically changing values, respectively. For example, before step 302, the data volume threshold may be determined based on the data volume of the first data table, and / or the current load information of the distributed database; and / or, the designated duration threshold may be determined based on the data volume of the first data table, and / or the load information of the current resources (such as one or more resources of CPU, memory or IO resources) used by the distributed database. Among them, the data volume of the first data table is positively correlated with the data volume threshold, and positively correlated with the designated duration threshold, and the current load information of the distributed database is negatively correlated with the data volume threshold, and negatively correlated with the designated duration threshold. That is, the larger the data volume of the first data table, the larger the data volume threshold, and the longer the duration threshold; the larger the current load of the distributed database, the smaller the data volume threshold, and the smaller the duration threshold.

[0116] After migrating the corresponding data to be migrated through each distributed transaction currently executed, the management node can delete the migrated data of the first data table stored in the data node of the first node set, so as to distinguish which data has been migrated and which data has not been migrated when scanning the data later.

[0117] It is worth noting that the duration of user business blocking is actually the duration of data being locked. Since the data migrated by each distributed transaction is different, the duration of each migrated data being locked is the duration of the migration process of the corresponding distributed transaction. In the embodiment of the present application, table data migration is executed in batches of multiple serial transactions. By limiting the amount of data migrated and / or the migration duration of each distributed transaction, excessive resource consumption is avoided when executing each distributed transaction, and the locking duration corresponding to each distributed transaction is reduced.

[0118] In the traditional data redistribution process, in gpdb, due to the use of full data migration, the length of time that each migrated data is locked is equal to the migration duration of the entire incremental migration process; in GaussDB, although the overall migration process is divided into full migration and multiple incremental migrations, the length of time that each migrated data is locked is relatively shortened, but the overall business blocking time is still relatively long.

[0119] In the embodiment of the present application, by limiting the amount of data migrated and / or the migration duration of each distributed transaction, the time that each migrated data is locked is much shorter than the locking time in the traditional data redistribution process. The overall service blocking time can be reduced to about 1 minute, and users are usually unaware of it. Therefore, compared with the traditional data redistribution method, it can effectively reduce the service blocking time, ensure smooth service, and improve user experience. In addition, the lock added to the migrated data is a write lock to prevent changes and deletions to the data during its migration process, but query operations on the data can still be performed.

[0120] In an embodiment of the present application, the management node may initiate multiple distributed transactions in series based on the determined first node set and the second node set, generate one or more distributed plans when executing each distributed transaction, and instruct the data nodes in the first node set and / or the second node set to execute the generated distributed plans, thereby realizing the data migration in the aforementioned first data table. Wherein, each distributed plan corresponds to one or more data nodes. The distributed plan includes one or more SQL statements, which are used to indicate the actions executed by the corresponding data nodes, and the order of execution of the actions, etc. For example, the executed action may be a scanning action or a migration action. The distributed plan may carry the aforementioned migration condition, or a sub-migration condition determined based on the migration condition. Optionally, each time a distributed transaction is initiated, the management node may also adjust the content of the distributed plan in combination with the current system resource situation, such as adjusting the migration condition or the sub-migration condition. The distributed plan may be implemented by executing a transaction or task in the corresponding data node. For example, when a data node receives the distributed plan, it may initiate a transaction (also called a local transaction) or a task to execute the actions indicated in the distributed plan in the order indicated in the distributed plan.

[0121] In the first optional mode, the management node generates multiple distributed plans based on the currently executed distributed transaction to instruct multiple data nodes to migrate data in the first data table. Assume that the first node set includes n data nodes, n is a positive integer; the second node set includes m data nodes, m is a positive integer. Figure 7 As shown, the migration process includes:

[0122] Step 3024: The management node generates n distributed plans for the n data nodes respectively based on the currently executed distributed transaction, and the n data nodes correspond to the n distributed plans one by one; the management node instructs the n data nodes to respectively execute the n distributed plans to select in parallel the data to be migrated that meets the sub-migration conditions from the unmigrated data of the first data table in the n data nodes, and send the selected data to be migrated that meets the sub-migration conditions from the n data nodes to the second node set.

[0123] Specifically, for the currently executed distributed transaction, the management node sends each of the n distributed plans generated based on the distributed transaction to the corresponding data node. The corresponding data node executes the distributed plan. When each data node completes the execution of the corresponding distributed plan, the management node executes the next distributed transaction, generates n new distributed plans, and sends them to the corresponding data nodes respectively, and so on. If all the data in the first data table has been migrated, the management node cancels the table redistribution flag and prepares for data migration of the next data table.

[0124] The aforementioned sub-migration condition is determined according to the migration condition. Optionally, the distributed plan may also carry the aforementioned migration sub-condition. For example, when the migration condition is that the data volume of the data to be migrated through the currently executed distributed transaction migration is less than or equal to the specified data volume threshold, the corresponding sub-migration condition is that the data volume of the data to be migrated through the execution of the corresponding distributed plan migration is less than or equal to the sub-data volume threshold. The sub-quantity threshold is less than the specified quantity threshold. The sub-quantity thresholds corresponding to n distributed plans may be equal or unequal. For example, the sub-quantity thresholds corresponding to n distributed plans may be equal to one-nth of the specified quantity threshold. When the migration condition is that the migration duration of the currently executed distributed transaction migration is less than or equal to the specified duration threshold, the corresponding sub-migration condition is that the migration duration of the currently executed distributed transaction migration is less than or equal to the sub-duration threshold. The sub-duration threshold is less than or equal to the specified duration threshold, and the maximum value of the sub-duration thresholds corresponding to the n distributed plans is the aforementioned specified duration threshold. The sub-duration thresholds corresponding to the n distributed plans may be equal or unequal. Typically, the sub-duration thresholds corresponding to the n distributed plans are all equal to the specified duration threshold.

[0125] For each of the n data nodes, the obtained distributed plan can be implemented by executing a transaction or task in the data node. Assume that the first data node is any of the n data nodes, and take the first data node executing a local transaction to implement the distributed plan as an example. For example, the distributed plan generated for the first data node may include one or more SQL statements, which are used to instruct the first data node to perform a scanning action and a migration action, and the scanning action and the migration action are performed in parallel, the target data node for data migration is the second data node (i.e., the data node in the second node set), and the distributed plan carries a sub-migration condition. Based on the distributed plan, the first data node can scan the unmigrated data of the first data table stored in the first data node through a local transaction (also called a table scan) to select the data to be migrated that meets the sub-migration condition, and send the selected data to be migrated that meets the sub-migration condition from the first data node to the second data node in the second node set.

[0126] For example, when the first optional implementation method described above is adopted and all unmigrated data in the first data table is used as data to be migrated, the first data node can traverse the unmigrated data of the first data table stored in the first data node through a local transaction and use the traversed data as data to be migrated.

[0127] When the second optional implementation is adopted, the data to be migrated is obtained by screening the data in the first data table, and the first data node traverses the unmigrated data in the first data table in the first data node through a local transaction to screen the data to be migrated that meets the migration sub-condition. The screening process can refer to the aforementioned step 3023.

[0128] When a distributed transaction is the first distributed transaction initiated during the data redistribution process, the unmigrated data obtained by scanning the n data nodes is all the data of the first data table. When a distributed transaction is not the first distributed transaction initiated during the data redistribution process, the unmigrated data obtained by scanning the n data nodes is the data of the first data table that has not been migrated by the previous distributed transaction.

[0129] In a first optional implementation, the first data node can scan all records of the first data table stored in the first data node through a local transaction to obtain the unmigrated data, that is, scan from the beginning of the first data table stored in the first data node from top to bottom. By adopting the scanning method provided by the first optional implementation, when each distributed transaction is executed by the management node, the first data node is instructed to scan all records of the first data table stored in the first data node, which can avoid omission of the data to be migrated.

[0130] Optionally, if the second optional implementation is adopted to scan the unmigrated data, the first data node can record the end position of this scan through a local transaction, and when the management node executes the next distributed transaction, instruct the first data node to scan backward from the most recently ended position of the records of the first data table stored in the first data node based on the corresponding distributed plan to obtain the unmigrated data. In this way, the records that have been scanned previously in the first data node can be prevented from being scanned again.

[0131] Optionally, if the second optional implementation method is used to scan the unmigrated data, in order to avoid the updated data being stored in the data records scanned by the distributed transaction control data node before the current distributed transaction, the management node can generate n distributed plans through the last distributed transaction executed, each distributed plan instructs the corresponding data node to scan the data of the first data table stored on the data node at one time, thereby avoiding data omissions, or control n data nodes through multiple distributed transactions to scan different data of the first data table respectively at the same time.

[0132] In an embodiment of the present application, when the management node executes the current distributed transaction, the aforementioned steps 3023 and 3024 may be executed in a nested manner, that is, the specific action of the aforementioned step 3023 is executed by the management node instructing the data node to execute through a distributed plan.

[0133] Step 3025: The management node generates m distributed plans for the m data nodes respectively based on the currently executed distributed transaction, and the m data nodes correspond one to one to the m distributed plans; the management node instructs the m data nodes to respectively execute the m distributed plans to receive and store the data of the first data table sent from the first node set in parallel.

[0134] For each of the m data nodes, the obtained distributed plan can be implemented by executing a transaction or task in the data node. Assuming that the second data node is any one of the m data nodes, the second data node executes a local transaction to implement the distributed plan as an example. For example, the distributed plan generated for the second data node may include one or more SQL statements, which are used to instruct the second data node to perform a receiving action and a storing action, and the receiving action and the storing action are executed in parallel, and the source data node of the data is the first data node. Based on the distributed plan, the second data node can receive and store the data of the first data table sent from the first node set through a local transaction.

[0135] Optionally, for each data node in the first node set, the data node deploys a local transaction for executing the distributed plan issued by the management node. Specifically, the local transaction executed by the data node may include two threads, and the two threads are used to respectively execute the aforementioned scanning action and migration action. For example, each local transaction includes a scanning thread and a sending thread, and the scanning thread is used to scan the unmigrated data of the first data table in the data node corresponding to the first node set (that is, when scanning the data of the first data table, skip the deleted data) to obtain the data to be migrated. The process of determining the data to be migrated can refer to the aforementioned step 3023; the sending thread is used to send the data to be migrated to the target data node in the second node set. The two threads can be executed in parallel to improve the efficiency of data redistribution. For each data node in the second node set, the data node deploys a local transaction for executing the distributed plan issued by the management node. Specifically, the local transaction executed by the data node may include a receiving thread for receiving data sent by other data nodes and writing the received data to the local data node. Since the data nodes in the first node set may also receive data from other nodes, the local transaction executed by each data node in the first node set may also include a receiving thread. Similarly, since the data nodes in the second node set may also send data to other nodes, the local transaction executed by each data node in the second node set may also include a sending thread. Optionally, when a data node needs to initiate a sending thread and a receiving thread at the same time, in order to save thread occupancy, the data node may initiate a sending and receiving thread (i.e., the local transaction includes a sending and receiving thread) by executing a local transaction to complete the functions of the aforementioned sending thread and receiving thread, such as receiving and sending data.

[0136] It is worth noting that after the data node in the first node set completes the migration of the data to be migrated in the first data table stored on the local data node, it can send a migration completion notification (also called an end mark) to the target data node in the second node set to which the data to be migrated is migrated; for any data node in the second node set, when the data node receives the migration completion notification from the corresponding source data nodes (the source data nodes corresponding to the data node can be recorded in the distributed plan), it determines that the execution of the corresponding distributed plan is completed and stops executing the corresponding distributed plan.

[0137] By generating multiple distributed plans based on distributed transactions, multiple data nodes can be instructed to execute multiple distributed plans in parallel to perform data migration in parallel, which can effectively save the execution time of each distributed transaction and improve the efficiency of executing distributed transactions.

[0138] like Figure 8As shown, assuming that the first node set includes data nodes N1 to N3, and the second node set includes data node N4, the management node migrates the data to be migrated through two distributed transactions executed in series. Among them, assuming that the two distributed transactions include a first distributed transaction and a second distributed transaction, the three distributed plans generated based on the first distributed transaction are respectively implemented by transactions 1a to 1c of the three data nodes in the first node set, and the three distributed plans generated based on the second distributed transaction are respectively implemented by transactions 2a to 2c of the three data nodes in the first node set. Assuming that the number of records is used to represent the amount of migrated data, and the corresponding specified data volume threshold in each distributed plan is 1, then each transaction in transactions 1a to 1c is executed to scan the data of multiple records that have not been migrated by the corresponding data node, and then complete the migration of the data of 1 record. Taking the execution of the first distributed transaction by the management node as an example, each data node executes the corresponding distributed plan, so that each data node performs data scanning on the local data node through its transaction, finds the data to be migrated, and sends the data to be migrated to the target data node ( Figure 8 is data node N4), and at the same time deletes the migrated data of the local data node that has been migrated by the transaction. Scanning and migration actions are performed in parallel by executing transactions 1a to 1c until the aforementioned migration conditions are met, or each data node meets the corresponding sub-conditions. The management node then commits the first distributed transaction to complete the migration of this batch of data. Among them, the process of finding the data to be migrated can refer to the corresponding process in the aforementioned step 302. The execution process of transactions 2a to 2c refers to the execution process of transactions 1a to 1c, and the embodiments of the present application will not be repeated. Furthermore, based on the first distributed transaction, a distributed plan corresponding to data node N4 can also be generated. Data node N4 executes transaction ( Figure 8 (not shown) to implement the distributed plan, thereby receiving the data sent by the data nodes N1 to N3 and storing the received data in the data node N4.

[0139] In a second optional method, the management node generates a distributed plan based on the currently executed distributed transaction, and instructs the data nodes in the first node set and the data nodes in the second node set to execute the distributed plan to select the data to be migrated that meets the migration conditions from the unmigrated data in the first data table in the first node set, and migrate the selected data to be migrated from the first node set to the second node set.

[0140] The distributed plan corresponds to multiple data nodes in the first node set and the second node set, and can be regarded as an integrated plan of n distributed plans and m distributed plans in the first optional method mentioned above. The distributed plan includes one or more SQL statements, which are used to indicate the actions performed by each data node in the first node set and the second node set, as well as the order in which the actions are performed. For example, the executed actions may include scanning actions, migration actions, receiving actions and / or storage actions. Optionally, the distributed plan may also carry the aforementioned migration conditions. After each data node receives the distributed plan, it can determine the actions it needs to perform, and can also determine the sub-migration conditions corresponding to itself based on the migration conditions. The migration condition determination process can refer to the aforementioned first optional method.

[0141] The distributed plan can be implemented by executing transactions or tasks in the data nodes. The process of each data node in the first node set and the second node set executing the actions required to be executed in the distributed plan can refer to the process of the data node executing the corresponding distributed plan in the first optional method mentioned above, and the embodiments of the present application will not be repeated here.

[0142] In an embodiment of the present application, the distributed database uses a multiversion concurrency control mechanism (Multiversion concurrency control, MVCC) for data storage. In the multiversion concurrency mechanism, the data deleted from a data node is not physically removed from the data node, but is also stored on the data node as a historical version. For example, after executing the aforementioned step 3025, the management node sets a deletion mark for the migrated data in the first data table on the first node set (or sets a deletion mark through a distributed plan to control the data node), and the deletion mark indicates that the migrated data is converted into a historical version of the data. Then the migrated data described in the aforementioned step 3025 is deleted, which essentially records the data as a historical version on the corresponding data node. Subsequently, by executing a distributed transaction to perform data scanning, the data of the historical version can be skipped (that is, the data with a deletion mark set is skipped). In this way, it can be ensured that during the data migration process, the user's data query operation for the historical version of the data is effectively executed.

[0143] It is worth noting that during the data migration process, since the data being migrated is locked, only data query operations can be performed on the migrated data, and data modification and deletion operations cannot be performed. Once the migration of the data is completed, the data on the first node set will be set with a deletion flag, and the data will become historical version data (in fact, it is not really deleted in the first node set), and the latest version of the data has been migrated to the new node in the second node set. These historical versions of data only support data query operations. After the distributed transaction used to migrate the data is committed, new user transactions will no longer query these historical versions of data. When all concurrent transactions for the historical version of the data in the first node set (such as data query operations for querying the historical version of the data) are completed, these historical versions of the data will no longer be accessed and can be physically deleted. The distributed database will remove these historical versions of the data from the data in the first data table based on the data cleaning mechanism of its running cycle, that is, physically remove them from the distributed database (this process is the data expiration cleaning process).

[0144] Step 303: When receiving a target service request for the first data table during the process of migrating data of the first data table, the management node determines a third node set from the first node set and the second node set to respond to the target service request.

[0145] During the data migration process, various types of user services may be generated due to different user needs.

[0146] There are many types of user services in different scenarios, such as data query services, data adding services (also called data insertion services), data deletion services and data modification services, and the corresponding service requests are data query requests, data adding requests (also called data insertion requests), data deletion requests and data modification requests. Among them, the data query request is used to request a data query operation on data, the data adding request is used to request a data adding operation, the data deletion request is used to request a data deletion operation, and the data modification request is used to request a data modification operation. Among them, the data query service is further divided into data query services associated with one data table and data query services associated with multiple data tables based on its association with the data table. The data query operation indicated by the data query request corresponding to the data query service associated with one data table only needs to query the data in one data table, and the data query operation indicated by the data query request corresponding to the data query service associated with multiple data tables needs to query the data in multiple data tables. For example, a data query request is: "Query the information of female employees in Company X". Assuming that the information of female employees of Company X is recorded in the first data table, the query operation only involves one data table, and the data query request is a data query request corresponding to a data query service associated with one data table. For another example, a data query request is: "Query the information of female employees of client companies of Company X". Assuming that the client companies of Company X are recorded in the second data table, and the information of female employees of different client companies is recorded in different data tables, the query operation indicates to first query the second data table to obtain the identifier of the client company of Company X, and then query the data table of the corresponding company based on the obtained identifier to obtain the information of female employees of the client company of Company X. The data query request involves multiple data tables, and the data query request is a data query request corresponding to a data query service associated with multiple data tables.

[0147] In the embodiment of the present application, the data redistribution method can be applied to a variety of scenarios, and the target service request can be a data query request, a data addition request (also called an insertion request), a data deletion request or a data modification request, and the target service request can be for one or more records of data. Fig. 9As shown, during the data migration process, the business data targeted by the same target business may involve data nodes before data redistribution and / or data nodes after data redistribution. For example, when data is hashed and distributed in the form of hash buckets, the data of the same hash bucket will be moved through multiple distributed transactions executed in series. Therefore, during the migration process, the data of the same hash bucket will be distributed on two data nodes at the same time (the data that has been migrated is distributed on the data nodes of the second node set, and the data that has not been migrated is distributed on the data nodes of the first node set, and all the new data corresponding to the hash bucket is directly written to the data nodes of the second node set). Therefore, for different target businesses, the final determined third node set is different, and the third node set includes one or more data nodes. The embodiment of the present application takes the following implementation scenarios as examples to illustrate the process of determining the third node set:

[0148] In a first implementation scenario, when the target service request is a data adding request, a third node set for responding to the data adding request is determined in the second node set.

[0149] For example, a hash value is calculated according to the key value of the newly added data carried by the data addition request; and a third node set for responding to the data addition request is determined in the second node set according to the hash value. For example, the data node in the second node set corresponding to the hash value is determined as the data node of the third node set. For example, the hash bucket corresponding to the hash value can be determined, and the data node corresponding to the hash bucket in the second node set is determined as the data node in the third node set. For example, the data node obtained by the query can be determined as the data node in the third node set by querying the aforementioned second mapping relationship table.

[0150] like Fig. 9 As shown, assuming that a data adding request is received, the request indicates that the data adding operation corresponds to the newly added data D, then the third node set storing the newly added data D is determined to be data node N4 through the hash distribution rule, and the newly added data D is stored in data node N4.

[0151] For traditional data redistribution methods, considering the consistency of the source table and the temporary table, if the rate of new data in the source table is greater than the data migration rate, the data migration will not be completed. If the table is locked forcibly for migration, the table lock time may be relatively long and affect user services. In the embodiment of the present application, since there is no need to establish a temporary table, the new data is directly added to the data nodes of the second node set (i.e., the third node set). Therefore, during the data migration process, there is no need to migrate these new data, nor is there any need to record these new data. The storage of new data can be quickly realized, effectively reducing the number of data migrations, simplifying the data migration process, improving data migration efficiency, and reducing the impact on user services.

[0152] In the second implementation scenario, when the target business request is a data deletion request or a data modification request or a data query request associated with the first data table, a data node for responding to the target business request is determined in the first node set, and a data node for responding to the target business request is determined in the second node set, and the third node set is composed of the data nodes determined from the first node set and the data nodes determined from the second node set.

[0153] In an optional manner, when the target service request includes a data deletion request, the data node for responding to the data deletion request (i.e., the data node where the data requested to be deleted by the data deletion request is located) is queried in the first node set, and the data node for responding to the data deletion request is queried in the second node set, and the data nodes obtained by the respective queries are merged to form a third node set. Fig. 9 As shown, the data node where the data B requested to be deleted by the data deletion request is located is queried in the first node set (including data nodes N1 to N3), and data node N2 is obtained; the data node where the data B is located is queried in the second node set (including data node N4), and data node N4 is obtained; the third node set composed of the data nodes obtained by the query includes data nodes N2 and N4.

[0154] For example, for a data deletion request, if the deletion can be performed based on the key value, after calculating the hash value based on the key value, the fourth node set is determined in the first node set based on the aforementioned first mapping relationship table, and the fifth node set is determined in the second node set based on the aforementioned second mapping relationship table. The deleted data may exist in both node sets, so the union of the fourth node set and the fifth node set is determined as the third node set, that is, the third node set includes the fourth node set and the fifth node set. The fourth node set and the fifth node set each include one or more data nodes.

[0155] In another optional manner, when the target service request includes a data modification request, the data node for responding to the data modification request (i.e., the data node where the data requested to be modified by the data modification request is located) is queried in the first node set, and the data node for responding to the data modification request is queried in the second node set, and the data nodes obtained by the respective queries are merged to form a third node set. Fig. 9 As shown, the data node where the data C requested to be modified by the data modification request is located is queried in the first node set (including data nodes N1 to N3), and the data node N3 is obtained; and the data node where the data C is located is queried in the second node set (including data node N4), and the data node N4 is obtained; the third node set composed of the data nodes obtained by the query includes data nodes N3 and N4.

[0156] For example, for a data modification request, if the modification can be performed based on the key value, after calculating the hash value based on the key value, the sixth node set is determined in the first node set based on the aforementioned first mapping relationship table, and the seventh node set is determined in the second node set based on the aforementioned second mapping relationship table. The modified data may exist in both node sets, so the union of the sixth node set and the seventh node set is determined as the third node set. The sixth node set and the seventh node set both include one or more data nodes.

[0157] In another optional manner, when the data query request includes a data query request associated with the first data table, the data node for responding to the data query request (i.e., the data node where the data requested by the data query request is located) is queried in the first node set, and the data node for responding to the data query request is queried in the second node set, and the data nodes obtained by the respective queries are merged to form a third node set. Fig. 9 As shown, the data node where the data A requested to be modified by the data modification request is located is queried in the first node set (including data nodes N1 to N3), and data node N1 is obtained, and the data node where the data A is located is queried in the second node set (including data node N4), and data node N4 is obtained. The third node set composed of the data nodes obtained by the query includes data nodes N1 and N4.

[0158] For example, for a data query request, if the query can be performed based on the key value, after calculating the hash value based on the key value, the eighth node set is determined in the first node set based on the aforementioned first mapping relationship table, and the ninth node set is determined in the second node set based on the aforementioned second mapping relationship table. The queried data may exist in both node sets, so the union of the eighth node set and the ninth node set is determined as the third node set. The eighth node set and the ninth node set both include one or more data nodes.

[0159] It should be noted that the data query request associated with the first data table can be a data query request associated only with the first data table, or can be a data query request associated with multiple data tables including the first data table. If the query request is a data query request associated with multiple data tables including the first data table, for each data table associated with the query request, the method for obtaining the third node set corresponding to the data table that responds to the query request refers to the method for obtaining the third node set corresponding to the first data table when the data query request is a data query request associated only with the first data table, and this embodiment of the application will not be described in detail. Subsequently, the data query request needs to be sent to the third node set corresponding to the multiple data tables. The sending process can refer to the subsequent step 304.

[0160] In the second implementation scenario, by executing the aforementioned operation of querying data nodes, the number of data nodes in the third node set can be reduced, the amount of information subsequently interacted with the third node set can be reduced, and communication overhead can be saved.

[0161] As mentioned above, the data targeted by the target business request can be the data of one or more records. When it targets the data of a record, since the data of a record cannot exist on two data nodes at the same time, the same record can only be processed successfully on one of the data nodes. If the third node set is not determined based on the key value, the target business request needs to be sent to all data nodes involved before and after the data redistribution. Because during the data migration process, all data nodes may have records that meet the conditions requested by the target business request. It can be seen that in the aforementioned second implementation scenario, the operation of querying the data node can also be omitted, and the union of the first node set and the second node set can be directly determined as the third node set. For example, the target business request is a data query request, which is used to request to query the data in the specified data range or specified time range in the first data table. The specified data range can be the range of data that meets the specified conditions, and the specified time range can be the time range that is earlier than or later than the specified time point. Since the data targeted by the data query request may be located in the data nodes before data redistribution and in the data nodes after data redistribution during the data migration process of the first data table, it is usually necessary to traverse the data nodes before data redistribution and the data nodes after data redistribution to avoid missing the queried data. Therefore, the union of the first node set and the second node set can be directly determined as the third node set. In addition, directly determining the union of the first node set and the second node set as the third node set can also reduce the delay of querying data nodes and improve business execution efficiency.

[0162] Step 304: The management node sends the target service request to the data nodes in the third node set.

[0163] The target service request is used for each data node in the third node set to perform service processing based on the target service request. After receiving the target service request, each data node in the third node set performs corresponding service processing. For example, assuming that the first data node is any data node in the third node set, the first data node performs the following process:

[0164] When the first data node receives a data query request, it detects whether the data node stores the data requested by the data query request. If the data node stores the data requested by the data query request, it obtains information about the data and sends a data query response to the management node, where the data query response includes the queried data. If the data node does not store the data requested by the data query request, it stops the action or sends a data query response to the management node, where the data query response indicates that the requested data has not been found.

[0165] When the first data node receives the data adding request, the newly added data is directly added to the data node. Optionally, the first data node may send an adding success response to the management node.

[0166] When the first data node receives the data modification request, it detects whether the data node stores the data requested to be modified by the data modification request. If the data node stores the data requested to be modified by the data modification request, it modifies the data according to the data modification request. Optionally, it sends a data modification response to the management node, the data modification response includes the modified data, or indicates that the modification is successful; if the data node does not store the data requested to be modified by the data modification request, it stops the action, or sends a data modification response to the management node, the data modification response indicates that the requested data does not exist.

[0167] When the first data node receives the data deletion request, it detects whether the data node stores the data requested to be deleted by the data deletion request. If the data node stores the data requested to be deleted by the data deletion request, it deletes the data according to the data deletion request. Optionally, it sends a data deletion response to the management node, and the data deletion response indicates that the deletion is successful; if the data node does not store the data requested to be deleted by the data deletion request, it stops the action, or sends a data deletion response to the management node, and the data deletion response indicates that the requested data does not exist.

[0168] As mentioned above, since in the aforementioned data redistribution process of the embodiment of the present application, the data is no longer stored in the data node before the migration after the migration, it is ensured that the data of the same record will only be stored on one data node of the distributed database, and will not be stored on two data nodes, thereby ensuring that the aforementioned target business request will not have a conflicting response.

[0169] Step 305: During the process of migrating the data of the first data table, if the management node detects a rollback triggering event, the data that has been migrated through multiple distributed transactions will be rolled back.

[0170] The rollback trigger event may be a failure (such as a crash) of a data node associated with the first data table in the second node set, or a data transmission error occurring in the data node associated with the first data table in the second node set, or a network error occurring in the data node associated with the first data table in the second node set, or the data node associated with the first data table in the second node set receiving a rollback instruction, or a distributed transaction associated with the first data table failing to commit, etc.

[0171] In one possible implementation, after a rollback trigger event is detected in the distributed database, the data that has been migrated through multiple distributed transactions will be rolled back, and the distributed database can be restored to a previous state where it can operate normally, so that after the end condition of the rollback trigger event is met in the subsequent process, the distributed database can still execute online services and data redistribution services normally.

[0172] In a possible implementation, the aforementioned step 305 may be replaced by: during the process of migrating the data of the first data table, if a rollback triggering event is detected, the data that has been migrated by the currently executed distributed transaction is rolled back.

[0173] In traditional distributed databases, when a distributed transaction is used to migrate data in a data table, if a rollback trigger event is detected, all the currently migrated data will be rolled back, that is, all the executed actions corresponding to the distributed transaction will be canceled. The amount of data rolled back is large, and all the migrated data will become invalid. When the conditions for re-migration are met, it needs to be migrated again, resulting in repeated data migration, waste of resources, and poor fault tolerance of the database.

[0174] In the embodiment of the present application, the aforementioned distributed transaction ensures the data consistency and persistence of the migration process. When there are multiple distributed transactions, the overall data migration process is split into the migration process of multiple distributed transactions executed in series. If a rollback trigger event is detected, it is only necessary to roll back all operations corresponding to the currently executed distributed transaction. After the migration conditions are met again, a new distributed transaction can be initiated to migrate data. Therefore, the data granularity and amount of rollback data are reduced, the amount of data that is repeatedly migrated is reduced, the overall impact of rollback on the data migration process is reduced, resource waste is avoided, and the fault tolerance of the database is improved.

[0175] It is worth noting that in the process of migrating the data of the first data table, in addition to the aforementioned data query service, data addition service and other data manipulation language (DML) services, other types of user services may also be generated, such as data definition language (DDL) services, which include services such as creating table information, modifying table information and deleting table information, and the object of the operation requested by the DDL service is the table information, that is, the definition and architecture of the table.

[0176] In the traditional data redistribution method, since the data consistency of the source table and the temporary table needs to be guaranteed, DDL operations are not allowed to be executed during the data migration process.

[0177] In the embodiment of the present application, since there is no need to create a temporary table, the data migration process occurs within the data table, rather than between the source table and the temporary table. Therefore, during the data migration process, the aforementioned DDL services are supported, such as supporting the modification of table meta information, allowing the modification of table names, adding or deleting fields in the data table, and so on.

[0178] It is worth noting that the aforementioned embodiment is described by taking a data table that needs to perform data redistribution as an example. When the embodiment of the present application is actually implemented, multiple data tables can execute the above-mentioned data redistribution process at the same time, thereby improving the efficiency of data redistribution and increasing concurrency.

[0179] To sum up, the data redistribution method provided in the embodiment of the present application can execute the target task without establishing a temporary table and realize online data redistribution. In this way, there is no need to migrate data between tables, only data migration within the table is required, thereby reducing the complexity of online data redistribution.

[0180] In addition, since data migration is performed using multiple distributed transactions executed serially, a single migration takes less time and consumes less resources, reducing the impact on other user jobs executed simultaneously.

[0181] Furthermore, since the newly added data is directly written to the data nodes after data redistribution, the amount of data to be migrated is effectively reduced, thereby reducing resource consumption and reducing the impact on other user jobs executed simultaneously.

[0182] For example, the above Figure 6For example, if the traditional data redistribution method is used, the data with hash bucket numbers 1 to 17 need to be migrated from the first node set to the second node set; in the embodiment of the present application, the data with hash bucket number 1 needs to be moved from data node N1 to data node N7, the data with hash bucket number 2 does not need to be moved, the data with hash bucket number 7 needs to be moved from data node N1 to data node N9, and so on. Overall, only the data with hash bucket numbers 1, 6, 7, 11, 12, 13, and 16 need to be migrated ( Figure 6 In the second node set, data nodes N7, N8 and N9 that need to receive the aforementioned migrated data are shaded, which effectively reduces the amount of data migration.

[0183] In the embodiment of the present application, in the scenario with concurrent user jobs, data migration is implemented by using in-table data migration and distributed multi-version concurrency control technology. There is no need to consider the data appending caused by the insertion and deletion operations of concurrent jobs, and migration is allowed to be performed in batches multiple times according to the amount of data and execution time, ensuring that the consumption of system resources by data redistribution is controllable, and the resource consumption and lock conflict impact of migration can be effectively controlled, and the impact on user jobs is greatly reduced. By using the embodiment of the present application to implement online capacity expansion of distributed databases, long-term business blockage caused by downtime for capacity expansion can be avoided, and the impact on online jobs is very small. Even in the case of data node failure and network failure, the redistribution operation can be easily restored, and the impact on data migration is also very small.

[0184] The present application embodiment provides a data redistribution device 40, which can be deployed on a management node. Fig.10 As shown, the data redistribution device 40 includes:

[0185] A first determining module 401, configured to execute the aforementioned step 301;

[0186] Migration module 402, used to execute the aforementioned step 302;

[0187] A second determining module 403, configured to execute the aforementioned step 303;

[0188] The sending module 404 is used to execute the aforementioned step 304.

[0189] To sum up, the data redistribution device provided in the embodiment of the present application can execute the target task without establishing a temporary table and realize online data redistribution. In this way, there is no need to migrate data between tables, only data migration within the table is required, thereby reducing the complexity of online data redistribution.

[0190] Alternatively, if Fig.11 As shown, the second determining module 403 includes:

[0191] The determination submodule 4031 is configured to determine, in the second node set, the third node set for responding to the data adding request when the target service request is a data adding request.

[0192] Optionally, the determining submodule 4031 is used to:

[0193] Calculate a hash value according to the key value of the newly added data carried in the data adding request;

[0194] A data node corresponding to the hash value is determined in the second node set, and the determined data node belongs to the third node set.

[0195] Optionally, the second determining module 403 is configured to:

[0196] When the target business request is a data deletion request, a data modification request, or a data query request associated with the first data table, a data node for responding to the target business request is determined in the first node set, and a data node for responding to the target business request is determined in the second node set, and the third node set is composed of the data nodes determined from the first node set and the data nodes determined from the second node set.

[0197] Alternatively, if Fig.12 As shown, the migration module 402 includes:

[0198] A screening submodule 4021 is used to screen the data in the first data table stored in the first node set for data to be migrated, wherein the data to be migrated is data in the first data table that is not stored in the second node set before migration;

[0199] The migration submodule 4022 is used to migrate the data to be migrated from the first node set to the second node set.

[0200] Optionally, the screening submodule 4021 is used to:

[0201] Acquire a first mapping relationship between the data in the first data table and the data nodes of the first node set;

[0202] Acquire a second mapping relationship between the data in the first data table and the data nodes of the second node set;

[0203] For the target data in the first data table, when the data node corresponding to the target data determined based on the first mapping relationship is different from the data node corresponding to the target data determined based on the second mapping relationship, the target data is determined as the data to be migrated in the data node corresponding to the target data determined based on the first mapping relationship.

[0204] Optionally, the migration submodule 4022 is used to:

[0205] Different data of the first data table are migrated from the first node set to the second node set respectively through a plurality of distributed transactions executed in series.

[0206] Optionally, the migration submodule 4022 is used to:

[0207] When the multiple distributed transactions are executed in series, data to be migrated that meets the migration condition is selected from the unmigrated data of the first data table in the first node set through the currently executed distributed transaction, and the selected data to be migrated is migrated from the first node set to the second node set, and the selected data to be migrated is locked during the migration process;

[0208] Among them, the migration conditions include: the data volume of the data to be migrated through the currently executed distributed transaction migration is less than or equal to the specified data volume threshold, and / or the migration duration of the currently executed distributed transaction migration is less than or equal to the specified duration threshold.

[0209] Optionally, the migration submodule 4022 is used to:

[0210] Based on the currently executed distributed transaction, n distributed plans are generated for n data nodes respectively, the first node set includes the n data nodes, the n data nodes correspond to the n distributed plans one by one, and n is a positive integer;

[0211] Instruct the n data nodes to respectively execute the n distributed plans to select in parallel the data to be migrated that meets the sub-migration condition from the unmigrated data of the first data table in the n data nodes, and send the selected data to be migrated that meets the sub-migration condition from the n data nodes to the second node set, wherein the sub-migration condition is determined based on the migration condition.

[0212] Alternatively, if Fig.13 As shown, the device 40 also includes:

[0213] The rollback module 405 is used to roll back the data migrated by the currently working distributed transaction if it is detected that the distributed database reaches a rollback trigger event during the process of migrating the data of the first data table.

[0214] Alternatively, the rollback module 405 is used to roll back the data that has been migrated by the currently executed distributed transaction if a rollback trigger event is detected during the process of migrating the data of the first data table.

[0215] Alternatively, if Fig.14 As shown, the device 40 also includes:

[0216] The setting module 406 is configured to set a deletion flag for the migrated data in the first data table on the first node set.

[0217] Optionally, Fig.15 A possible basic hardware architecture of the computing device described in this application is schematically provided.

[0218] See also Fig.15 , computing device 500 includes a processor 501 , a memory 502 , a communication interface 503 and a bus 504 .

[0219] In the computing device 500, the number of processors 501 may be one or more. Fig.15 Only one of the processors 501 is shown. Optionally, the processor 501 may be a central processing unit (CPU). If the computing device 500 has multiple processors 501, the types of the multiple processors 501 may be different or the same. Optionally, the multiple processors 501 of the computing device 500 may also be integrated into a multi-core processor.

[0220] The memory 502 stores computer instructions and data; the memory 502 may store computer instructions and data required to implement the data redistribution method provided in the present application, for example, the memory 502 stores instructions for implementing the steps of the data redistribution method. The memory 502 may be any one or any combination of the following storage media: non-volatile memory (e.g., read-only memory (ROM), solid-state drive (SSD), hard disk (HDD), optical disk), volatile memory.

[0221] The communication interface 503 may be any one or any combination of the following devices: a network interface (eg, an Ethernet interface), a wireless network card, or other device with a network access function.

[0222] The communication interface 503 is used for the computing device 500 to perform data communication with other computing devices or terminals.

[0223] The bus 504 can connect the processor 501 to the memory 502 and the communication interface 503. Thus, through the bus 504, the processor 501 can access the memory 502, and can also use the communication interface 503 to exchange data with other computing devices or terminals.

[0224] In the present application, the computing device 500 executes computer instructions in the memory 502, so that the computing device 500 implements the data redistribution method provided in the present application, or enables the computing device 500 to deploy a data redistribution apparatus.

[0225] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory including instructions, and the above instructions can be executed by a processor of a server to complete the emoticon picture recommendation method shown in various embodiments of the present invention. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device, etc.

[0226] An embodiment of the present application provides a distributed database system, including: a management node and a data node, wherein the management node includes any of the aforementioned data redistribution devices 40 or the aforementioned computing devices 500.

[0227] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product, which includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, data center, etc. that contains one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium, or a semiconductor medium (e.g., a solid-state hard disk), etc.

[0228] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.

[0229] In this application, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance. The term "plurality" refers to two or more, unless otherwise expressly defined. A refers to B, which means that A is the same as B or A is a simple variation of B.

[0230] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0231] The above description is only an exemplary embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.

Claims

1. A data redistribution method, characterized in that: include: Determine a first node set and a second node set respectively associated with a first data table in a distributed database, wherein the first node set includes data nodes used to store data in the first data table before data in the first data table is redistributed, and the second node set includes data nodes used to store data in the first data table starting from the data in the first data table being redistributed; In the case where the first node set and the second node set have the same data nodes, according to a first mapping relationship between data in the first data table and the data nodes of the first node set and a second mapping relationship between data in the first data table and the data nodes of the second node set, the data to be migrated are screened from the data of the first data table stored in the first node set, and the data to be migrated of the first data table are migrated from the first node set to the second node set, the data to be migrated of the first data table are the data of the first data table that are not stored in the second node set before the migration, and the first mapping relationship and the second mapping relationship are determined by adopting a hash distribution rule and according to a principle of minimum movement quantity; In the process of migrating the data of the first data table, when a target service request for the first data table is received, a third node set for responding to the target service request is determined from the first node set and the second node set; The target service request is sent to a data node in the third node set.

2. The method according to claim 1, characterized in that The determining of a third node set for responding to the target service request from the first node set and the second node set includes: When the target service request is a data adding request, the third node set for responding to the data adding request is determined in the second node set.

3. The method according to claim 2, characterized in that The determining of the third node set for responding to the data adding request in the second node set comprises: Calculate a hash value according to the key value of the newly added data carried in the data adding request; A data node corresponding to the hash value is determined in the second node set, and the determined data node belongs to the third node set.

4. The method according to claim 1, characterized in that: The determining of a third node set for responding to the target service request from the first node set and the second node set includes: When the target business request is a data deletion request, a data modification request, or a data query request associated with the first data table, a data node for responding to the target business request is determined in the first node set, and a data node for responding to the target business request is determined in the second node set, and the third node set is composed of the data nodes determined from the first node set and the data nodes determined from the second node set.

5. The method according to claim 1, characterized in that The filtering of the data to be migrated from the data in the first data table stored in the first node set according to the first mapping relationship between the data in the first data table and the data nodes of the first node set and the second mapping relationship between the data in the first data table and the data nodes of the second node set includes: Acquire the first mapping relationship; Acquire the second mapping relationship; For the target data in the first data table, when the data node corresponding to the target data determined based on the first mapping relationship is different from the data node corresponding to the target data determined based on the second mapping relationship, the target data is determined as the data to be migrated in the data node corresponding to the target data determined based on the first mapping relationship.

6. The method according to any one of claims 1 to 5, characterized in that: The step of migrating the to-be-migrated data of the first data table from the first node set to the second node set includes: Different to-be-migrated data of the first data table are migrated from the first node set to the second node set respectively through a plurality of distributed transactions executed in series.

7. The method according to claim 6, characterized in that The step of migrating different to-be-migrated data of the first data table from the first node set to the second node set respectively by executing a plurality of distributed transactions in series includes: When the multiple distributed transactions are executed in series, data to be migrated that meets the migration condition is selected from the unmigrated data to be migrated of the first data table in the first node set through the currently executed distributed transaction, and the selected data to be migrated is migrated from the first node set to the second node set, and the selected data to be migrated is locked during the migration process; Among them, the migration conditions include: the data volume of the data to be migrated through the currently executed distributed transaction migration is less than or equal to the specified data volume threshold, and / or the migration duration of the currently executed distributed transaction migration is less than or equal to the specified duration threshold.

8. The method according to claim 7, characterized in that The method of selecting, when executing the plurality of distributed transactions in series, data to be migrated that meets a migration condition from unmigrated data to be migrated of the first data table in the first node set through the currently executed distributed transaction, and migrating the selected data to be migrated from the first node set to the second node set, comprises: Based on the currently executed distributed transaction, n distributed plans are generated for n data nodes respectively, the first node set includes the n data nodes, the n data nodes correspond to the n distributed plans one by one, and n is a positive integer; Instruct the n data nodes to respectively execute the n distributed plans to select in parallel the data to be migrated that meets the sub-migration condition from the unmigrated data to be migrated in the first data table in the n data nodes, and send the selected data to be migrated that meets the sub-migration condition from the n data nodes to the second node set, wherein the sub-migration condition is determined based on the migration condition.

9. The method according to claim 7 or 8, characterized in that: The method further comprises: During the process of migrating the data of the first data table, if a rollback triggering event is detected, the data that has been migrated through the multiple distributed transactions will be rolled back.

10. The method according to claim 7 or 8, characterized in that: The method further comprises: During the process of migrating the data of the first data table, if a rollback trigger event is detected, the data that has been migrated by the currently executed distributed transaction will be rolled back.

11. The method according to any one of claims 1 to 5, 7 and 8, characterized in that: The method comprises: A deletion flag is set for the migrated data in the first data table on the first node set.

12. A data redistribution device, characterized in that: include: A first determination module is used to determine a first node set and a second node set respectively associated with a first data table in a distributed database, wherein the first node set includes data nodes used to store data in the first data table before data in the first data table is redistributed, and the second node set includes data nodes used to store data in the first data table starting from the data in the first data table being redistributed; Migration module, including screening submodule and migration submodule; The screening submodule is used for screening the data to be migrated from the data of the first data table stored in the first node set according to a first mapping relationship between the data in the first data table and the data nodes of the first node set and a second mapping relationship between the data in the first data table and the data nodes of the second node set when the first node set and the second node set have the same data nodes, wherein the data to be migrated in the first data table are the data in the first data table that are not stored in the second node set before the migration, and the first mapping relationship and the second mapping relationship are determined by adopting a hash distribution rule and according to a principle of minimum movement quantity; the migration submodule is used for migrating the data to be migrated in the first data table from the first node set to the second node set; a second determining module, configured to determine, in the process of migrating the data of the first data table, when receiving a target service request for the first data table, a third node set from the first node set and the second node set for responding to the target service request; A sending module is used to send the target service request to the data node in the third node set.

13. The device according to claim 12, characterized in that The second determining module includes: The determination submodule is used to determine the third node set in the second node set for responding to the data adding request when the target service request is a data adding request.

14. The device according to claim 13, characterized in that The determining submodule is used to: Calculate a hash value according to the key value of the newly added data carried in the data adding request; A data node corresponding to the hash value is determined in the second node set, and the determined data node belongs to the third node set.

15. The device according to claim 12, characterized in that The second determining module is used to: When the target business request is a data deletion request, a data modification request, or a data query request associated with the first data table, a data node for responding to the target business request is determined in the first node set, and a data node for responding to the target business request is determined in the second node set, and the third node set is composed of the data nodes determined from the first node set and the data nodes determined from the second node set.

16. The device according to claim 12, characterized in that The screening submodule is used for: Acquire the first mapping relationship; Acquire the second mapping relationship; For the target data in the first data table, when the data node corresponding to the target data determined based on the first mapping relationship is different from the data node corresponding to the target data determined based on the second mapping relationship, the target data is determined as the data to be migrated in the data node corresponding to the target data determined based on the first mapping relationship.

17. The device according to any one of claims 12 to 16, characterized in that The migration submodule is used to: Different to-be-migrated data of the first data table are migrated from the first node set to the second node set respectively through a plurality of distributed transactions executed in series.

18. The device according to claim 17, characterized in that The migration submodule is used to: When the multiple distributed transactions are executed in series, data to be migrated that meets the migration condition is selected from the unmigrated data to be migrated of the first data table in the first node set through the currently executed distributed transaction, and the selected data to be migrated is migrated from the first node set to the second node set, and the selected data to be migrated is locked during the migration process; Among them, the migration conditions include: the data volume of the data to be migrated through the currently executed distributed transaction migration is less than or equal to the specified data volume threshold, and / or the migration duration of the currently executed distributed transaction migration is less than or equal to the specified duration threshold.

19. The device according to claim 18, characterized in that The migration submodule is used to: Based on the currently executed distributed transaction, n distributed plans are generated for n data nodes respectively, the first node set includes the n data nodes, the n data nodes correspond to the n distributed plans one by one, and n is a positive integer; Instruct the n data nodes to respectively execute the n distributed plans to select in parallel the data to be migrated that meets the sub-migration condition from the unmigrated data to be migrated in the first data table in the n data nodes, and send the selected data to be migrated that meets the sub-migration condition from the n data nodes to the second node set, wherein the sub-migration condition is determined based on the migration condition.

20. The device according to claim 18 or 19, characterized in that The device also includes: The rollback module is used to roll back the data migrated by the currently working distributed transaction if it is detected that the distributed database reaches a rollback trigger event during the process of migrating the data of the first data table.

21. The device according to claim 18 or 19, characterized in that The device also includes: The rollback module is used to roll back the data that has been migrated by the currently executed distributed transaction if a rollback trigger event is detected during the process of migrating the data of the first data table.

22. The device according to any one of claims 12 to 16, 18 and 19, characterized in that: The device also includes: A setting module is used to set a deletion mark for the migrated data in the first data table on the first node set.

23. A computer device, characterized in that: include: Processor and memory; The memory is used to store computer instructions; The processor is used to execute computer instructions stored in the memory, so that the computing device executes the data redistribution method according to any one of claims 1 to 11.

24. A distributed database system, characterized in that: include: A management node and a data node, wherein the management node comprises the data redistribution device according to any one of claims 12 to 22.

25. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes computer instructions, and the computer instructions instruct a computing device to execute the data redistribution method according to any one of claims 1 to 11.